text
stringlengths 0
3.34M
|
---|
function [ id, type, rep, field, symm ] = mm_header_read ( input_unit )
%*****************************************************************************80
%
%% MM_HEADER_READ reads the header line from a Matrix Market file.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 28 April 2004
%
% Author:
%
% John Burkardt
%
% Parameters:
%
% Input, integer INPUT_UNIT, the input unit identifier.
%
% Output, character ( len = 14 ) ID, the Matrix Market identifier.
% This value must be '%%MatrixMarket'.
%
% Output, character ( len = 6 ) TYPE, the Matrix Market type.
% This value must be 'matrix'.
%
% Output, character ( len = 10 ) REP, the Matrix Market 'representation'
% indicator. Possible values include:
% 'coordinate' (for sparse data)
% 'array' (for dense data)
% 'elemental' (to be added)
%
% Output, character ( len = 7 ) FIELD, the Matrix Market 'field'.
% Possible values include:
% 'real'
% 'double'
% 'complex'
% 'integer'
% 'pattern'
%
% Output, character ( len = 19 ) SYMM, the Matrix Market symmetry.
% Possible values include:
% 'symmetric'
% 'hermitian'
% 'skew-symmetric'
% 'general'
%
header = fgets ( input_unit );
if ( header == -1 )
fprintf ( 1, '\n' );
fprintf ( 1, 'MM_HEADER_READ - Fatal error!\n' );
fprintf ( 1, ' An empty header line was read.\n' );
error ( 'MM_HEADER_READ - Fatal error!' )
end
[ id, header ] = strtok ( header );
[ type, header ] = strtok ( header );
[ rep, header ] = strtok ( header );
[ field, header ] = strtok ( header );
[ symm, header ] = strtok ( header );
return
end
|
SUBROUTINE wmoout(BULHEAD, KW, yy, mm, dd, hh,
1 lwork, linelen, nlines, grib, lgrib, wmounit)
C Robert Grumbine 1998
IMPLICIT none
CHARACTER(6) BULHEAD
CHARACTER(4) KW
INTEGER yy, mm, dd, hh
INTEGER linelen, nlines, lwork(linelen, nlines)
INTEGER lgrib, wmounit
CHARACTER(1) grib(lgrib)
INTEGER IDS(6)
CHARACTER(1) HEADER(21)
CHARACTER(1) QUEUE(80)
INTEGER mlen, mfin
IDS(1) = yy
IDS(2) = mm
IDS(3) = dd
IDS(4) = hh
IDS(5) = 0
IDS(6) = 0
mlen = lgrib
CALL MAKWMO(BULHEAD, IDS, HEADER, KW)
CALL QUEDES(QUEUE, BULHEAD, mlen, KW)
CALL TRANST(wmounit, grib, HEADER, QUEUE, mlen, mfin,
1 lwork, linelen, nlines)
RETURN
END
|
# ---
# title: 595. Big Countries
# id: problem595
# author: Tian Jun
# date: 2020-10-31
# difficulty: Easy
# categories:
# link: <https://leetcode.com/problems/big-countries/description/>
# hidden: true
# ---
#
# There is a table `World`
#
#
#
# +-----------------+------------+------------+--------------+---------------+
# | name | continent | area | population | gdp |
# +-----------------+------------+------------+--------------+---------------+
# | Afghanistan | Asia | 652230 | 25500100 | 20343000 |
# | Albania | Europe | 28748 | 2831741 | 12960000 |
# | Algeria | Africa | 2381741 | 37100000 | 188681000 |
# | Andorra | Europe | 468 | 78115 | 3712000 |
# | Angola | Africa | 1246700 | 20609294 | 100990000 |
# +-----------------+------------+------------+--------------+---------------+
#
#
# A country is big if it has an area of bigger than 3 million square km or a
# population of more than 25 million.
#
# Write a SQL solution to output big countries' name, population and area.
#
# For example, according to the above table, we should output:
#
#
#
# +--------------+-------------+--------------+
# | name | population | area |
# +--------------+-------------+--------------+
# | Afghanistan | 25500100 | 652230 |
# | Algeria | 37100000 | 2381741 |
# +--------------+-------------+--------------+
#
#
#
#
#
## @lc code=start
using LeetCode
## add your code here:
## @lc code=end
|
plotstuff_pendcart(args...) = println("Install package Plots.jl (and call using Plots) to plot results in the end of demo_pendcart")
function care(A, B, Q, R)
G = try
B*inv(R)*B'
catch
error("R must be non-singular.")
end
Z = [A -G;
-Q -A']
S = schur(Z)
S = ordschur(S, real(S.values).<0)
U = S.Z
(m, n) = size(U)
U11 = U[1:div(m, 2), 1:div(n,2)]
U21 = U[div(m,2)+1:m, 1:div(n,2)]
return U21/U11
end
function lqr(A, B, Q, R)
S = care(A, B, Q, R)
K = R\B'*S
return K
end
"""
demo_pendcart(;kwargs...)
Run the iLQG Function to find an optimal trajectory For the "pendulum on a cart system". Requires package ControlSystems.jl
# Arguments
`x0 = [π-0.6,0,0,0]`
`goal = [π,0,0,0]`
`Q = Diagonal([10,1,2,1])` : State weight matrix
`R = 1` : Control weight matrix
`lims = 5.0*[-1 1]` : control limits,
`T = 600` : Number of time steps
`doplot = true` : Plot results
"""
function demo_pendcart(;x0 = [π-0.6,0,0,0], goal = [π,0,0,0],
Q = Diagonal([10.,1,2,1]), # State weight matrix
R = 1., # Control weight matrix
lims = 5.0*[-1 1], # control limits,
T = 600, # Number of time steps
doplot = true # Plot results
)
N = T+1
g = 9.82
l = 0.35 # Length of pendulum
h = 0.01 # Sample time
d = 0.99
A = [0 1 0 0; # Linearlized system dynamics matrix, continuous time
g/l -d 0 0;
0 0 0 1;
0 0 0 0]
B = [0, -1/l, 0, 1]
C = eye(4) # Assume all states are measurable
D = 4
L = lqr(A,B,Q,R) # Calculate the optimal state feedback
I = T
function fsys_closedloop(t,x,L,xd)
dx = copy(x)
dx[1] -= pi
u = -(L*dx)[1]
xd[1] = x[2]
xd[2] = -g/l * sin(x[1]) + u/l * cos(x[1]) - d*x[2]
xd[3] = x[4]
xd[4] = u
end
function fsys(t,x,u,xd)
xd[1] = x[2]
xd[2] = -g/l * sin(x[1]) + u/l * cos(x[1]) - d*x[2]
xd[3] = x[4]
xd[4] = u
end
dfvec = zeros(4)
function dfsys(x,u)
dfvec[1] = x[1]+h*x[2]
dfvec[2] = x[2]+h*(-g/l*sin(x[1])+u[1]/l*cos(x[1])- d*x[2])
dfvec[3] = x[3]+h*x[4]
dfvec[4] = x[4]+h*u[1]
dfvec
end
function cost_quadratic(x,u)
local d = (x.-goal)
0.5(d'*Q*d + u'R*u)[1]
end
function cost_quadratic(x::Matrix,u)
local d = (x.-goal)
T = size(u,2)
c = Vector{Float64}(undef,T+1)
for t = 1:T
c[t] = 0.5(d[:,t]'*Q*d[:,t] + u[:,t]'R*u[:,t])[1]
end
c[end] = cost_quadratic(x[:,end][:],[0.0])
return c
end
cx = zeros(4,T)
cu = zeros(1,T)
cxu = zeros(D,1)
function dcost_quadratic(x,u)
cx .= Q*(x.-goal)
cu .= R.*u
return cx,cu,cxu
end
function lin_dyn_f(x,u,i)
u[isnan.(u)] .= 0
f = dfsys(x,u)
end
fxc = Array{Float64}(undef,D,D,I)
fuc = Array{Float64}(undef,D,1,I)
fxd = Array{Float64}(undef,D,D,I)
fud = Array{Float64}(undef,D,1,I)
for ii = 1:I
fxc[:,:,ii] = [0 1 0 0;
0 0 0 0;
0 0 0 1;
0 0 0 0]
fuc[:,:,ii] = [0, 0, 0, 1]
end
function lin_dyn_df(x,u)
u[isnan.(u)] .= 0
D = size(x,1)
nu,I = size(u)
cx,cu,cxu = dcost_quadratic(x,u)
cxx = Q
cuu = [R]
for ii = 1:I
fxc[2,1,ii] = -g/l*cos(x[1,ii])-u[ii]/l*sin(x[1,ii])
fxc[2,2,ii] = -d
fuc[2,1,ii] = cos(x[1,ii])/l
ABd = exp([fxc[:,:,ii]*h fuc[:,:,ii]*h; zeros(nu, D + nu)])# ZoH sampling
fxd[:,:,ii] = ABd[1:D,1:D]
fud[:,:,ii] = ABd[1:D,D+1:D+nu]
end
fxx=fxu=fuu = []
return fxd,fud,fxx,fxu,fuu,cx,cu,cxx,cxu,cuu
end
x = zeros(4,N)
u = zeros(1,T)
"""
Simulate a pendulum on a cart using the non-linear equations
"""
function simulate_pendcart(x0,L, dfsys, cost)
x[:,1] = x0
u[1] = 0
for t = 2:T
dx = copy(x[:,t-1])
dx[1] -= pi
u[t] = -(L*dx)[1]
if !isempty(lims)
u[t] = clamp(u[t],lims[1],lims[2])
end
x[:,t] = dfsys(x[:,t-1],u[t])
end
dx = copy(x[:,T])
dx[1] -= pi
uT = -(L*dx)[1]
if !isempty(lims)
uT = clamp(uT,lims[1],lims[2])
end
x[:,T+1] = dfsys(x[:,T],uT)
c = cost(x,u)
return x, u, c
end
# Simulate the closed loop system with regular LQG control and watch it fail due to control limits
x00, u00, cost00 = simulate_pendcart(x0, L, dfsys, cost_quadratic)
f(x,u,i) = lin_dyn_f(x,u,i)
df(x,u) = lin_dyn_df(x,u)
# plotFn(x) = plot(squeeze(x,2)')
println("Entering iLQG function")
# subplot(n=4,nc=2)
x, u, L, Vx, Vxx, cost, trace = iLQG(f,cost_quadratic, df, x0, 0*u00,
lims = lims,
# plotFn = x -> Plots.subplot!(x'),
regType = 2,
α = exp10.(range(0.2, stop=-3, length=6)),
λmax = 1e15,
verbosity = 3,
tol_fun = 1e-8,
tol_grad = 1e-8,
max_iter = 1000);
doplot && plotstuff_pendcart(x00, u00, x,u,cost00,cost,trace)
println("Done")
return x, u, L, Vx, Vxx, cost, trace
end
|
// =============================================================================
// == niw_sampled.h
// == --------------------------------------------------------------------------
// == A class for a Normal Inverse-Wishart distribution
// == --------------------------------------------------------------------------
// == Copyright 2013. MIT. All Rights Reserved.
// == Written by Jason Chang 11-03-2013
// == --------------------------------------------------------------------------
// == If this code is used, the following should be cited:
// ==
// == [1] J. Chang and J. W. Fisher II, "Parallel Sampling of DP Mixtures
// == Models using Sub-Cluster Splits". Neural Information Processing
// == Systems (NIPS 2013), Lake Tahoe, NV, USA, Dec 2013.
// =============================================================================
#ifndef _NIW_SAMPLED_H_INCLUDED_
#define _NIW_SAMPLED_H_INCLUDED_
//#include "matrix.h"
//#include "mex.h"
#include <math.h>
//#include "array.h"
//#include "helperMEX.h"
//#include "debugMEX.h"
#include "dpmmSubclusters/normal.h"
#include "dpmmSubclusters/linear_algebra.h"
#include "dpmmSubclusters/myfuncs.h"
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <Eigen/Cholesky>
#include <vector>
using std::vector;
#ifndef pi
#define pi 3.14159265
#endif
#ifndef logpi
#define logpi 1.144729885849
#endif
class niw_sampled
{
gsl_rng *r;
public:
// prior hyperparameters
double kappah;
double nuh;
arr(double) thetah;
arr(double) Deltah;
int D;
int D2;
// sufficient statistics of the observed data
arr(double) t;
arr(double) T;
int N;
// posterior hyperparameters
double kappa;
double nu;
arr(double) theta;
arr(double) Delta;
arr(double) tempVec;
arr(double) tempMtx;
// instantiated gaussian parameters
normal param;
double logpmu_prior, logpmu_posterior;
public:
// --------------------------------------------------------------------------
// -- niw_sampled
// -- constructor; initializes to empty
// --------------------------------------------------------------------------
niw_sampled();
// --------------------------------------------------------------------------
// -- niw_sampled
// -- copy constructor;
// --------------------------------------------------------------------------
niw_sampled(const niw_sampled& that);
// --------------------------------------------------------------------------
// -- operator=
// -- assignment operator
// --------------------------------------------------------------------------
niw_sampled& operator=(const niw_sampled& that);
// --------------------------------------------------------------------------
// -- copy
// -- returns a copy of this
// --------------------------------------------------------------------------
void copy(const niw_sampled& that);
// --------------------------------------------------------------------------
// -- niw_sampled
// -- constructor; intializes to all the values given
// --------------------------------------------------------------------------
niw_sampled(int _D, double _kappah, double _nuh, arr(double) _thetah, arr(double) _Deltah);
// --------------------------------------------------------------------------
// -- ~niw_sampled
// -- destructor
// --------------------------------------------------------------------------
virtual ~niw_sampled();
// --------------------------------------------------------------------------
// -- ~cleanup
// -- deletes all the memory allocated by this
// --------------------------------------------------------------------------
virtual void cleanup();
public:
// --------------------------------------------------------------------------
// -- empty
// -- Empties out the statistics of the niw_sampled (i.e. no data).
// --------------------------------------------------------------------------
void clear();
void empty();
bool isempty() const;
int getN() const;
int getD() const;
arr(double) get_mean() const;
arr(double) get_cov() const;
arr(double) get_prec() const;
gsl_rng* get_r();
void set_normal(normal &other);
void set_normal(arr(double) _mean, arr(double) _cov);
normal* get_normal();
// --------------------------------------------------------------------------
// -- update_posteriors
// -- Updates the posterior hyperparameters
// --------------------------------------------------------------------------
void update_posteriors();
void update_posteriors_sample();
// --------------------------------------------------------------------------
// -- add_data
// -- functions to add an observation to the niw_sampled. Updates the sufficient
// -- statistics, posterior hyperparameters, and predictive parameters
// --
// -- parameters:
// -- - data : the new observed data point of size [1 D]
// --------------------------------------------------------------------------
void add_data_init(arr(double) data);
void add_data(arr(double) data);
void merge_with(niw_sampled* &other, bool doSample);
void merge_with(niw_sampled* &other1, niw_sampled* &other2, bool doSample);
void merge_with(niw_sampled &other, bool doSample);
void merge_with(niw_sampled &other1, niw_sampled &other2, bool doSample);
void set_stats(int _N, arr(double) _t, arr(double) _T);
double Jdivergence(const niw_sampled &other);
double predictive_loglikelihood(arr(double) data) const;
double predictive_loglikelihood_mode(arr(double) data) const;
double data_loglikelihood() const;
double data_loglikelihood_marginalized() const;
double data_loglikelihood_marginalized_testmerge(niw_sampled *other) const;
void sample(normal &_param);
void sample_scale(normal &_param);
void sample();
void find_mode();
double logmu_posterior(const normal &_param) const;
double logmu_posterior() const;
double logmu_prior(const normal &_param) const;
double logmu_prior() const;
};
inline double niw_sampled::predictive_loglikelihood(arr(double) data) const
{
return param.predictive_loglikelihood(data);
}
#endif
|
State Before: ι : Type u_3
α : Type u_4
β : Type u_1
γ : Type u_2
inst✝² : CommMonoid α
s✝ t : Multiset α
a : α
m : Multiset ι
f✝ g : ι → α
inst✝¹ : CommMonoid β
inst✝ : CommMonoid γ
s : Multiset ι
f : α → β → γ
hf : ∀ (a b : α) (c d : β), f (a * b) (c * d) = f a c * f b d
hf' : f 1 1 = 1
f₁ : ι → α
f₂ : ι → β
l : List ι
⊢ prod (map (fun i => f (f₁ i) (f₂ i)) (Quotient.mk (List.isSetoid ι) l)) =
f (prod (map f₁ (Quotient.mk (List.isSetoid ι) l))) (prod (map f₂ (Quotient.mk (List.isSetoid ι) l))) State After: no goals Tactic: simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod] |
-- Module shadowing using generated modules for records and datatypes
module Issue260a where
module D where
data D : Set where
|
Formal statement is: lemma pole_theorem_analytic_0: assumes g: "g analytic_on S" and eq: "\<And>z. z \<in> S \<Longrightarrow> \<exists>d. 0 < d \<and> (\<forall>w \<in> ball z d - {a}. g w = (w - a) * f w)" and [simp]: "f a = deriv g a" "g a = 0" shows "f analytic_on S" Informal statement is: If $g$ is analytic on $S$ and for all $z \in S$, there exists a $d > 0$ such that for all $w \in B(z, d) - \{a\}$, $g(w) = (w - a)f(w)$, then $f$ is analytic on $S$. |
[STATEMENT]
lemma numeral_assoc_simps:
"((a::real) + numeral b) + numeral c = a + numeral (b + c)"
"(a + numeral b) - numeral c = a + neg_numeral_class.sub b c"
"(a - numeral b) + numeral c = a + neg_numeral_class.sub c b"
"(a - numeral b) - numeral c = a - numeral (b + c)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (a + numeral b + numeral c = a + numeral (b + c) &&& a + numeral b - numeral c = a + neg_numeral_class.sub b c) &&& a - numeral b + numeral c = a + neg_numeral_class.sub c b &&& a - numeral b - numeral c = a - numeral (b + c)
[PROOF STEP]
by simp_all |
-- binary search trees (not balanced)
open import bool
open import bool-thms2
open import eq
open import maybe
open import product
open import product-thms
open import bool-relations using (transitive ; total)
module bst (A : Set) (_≤A_ : A → A → 𝔹)
(≤A-trans : transitive _≤A_)
(≤A-total : total _≤A_) where
open import bool-relations _≤A_ hiding (transitive ; total)
open import minmax _≤A_ ≤A-trans ≤A-total
data bst : A → A → Set where
bst-leaf : ∀ {l u : A} → l ≤A u ≡ tt → bst l u
bst-node : ∀ {l l' u' u : A}(d : A) →
bst l' d → bst d u' →
l ≤A l' ≡ tt → u' ≤A u ≡ tt →
bst l u
-- find a node which is isomorphic (_=A_) to d and return it; or else return nothing
bst-search : ∀{l u : A}(d : A) → bst l u → maybe (Σ A (λ d' → d iso𝔹 d' ≡ tt))
bst-search d (bst-leaf _) = nothing
bst-search d (bst-node d' L R _ _) with keep (d ≤A d')
bst-search d (bst-node d' L R _ _) | tt , p1 with keep (d' ≤A d)
bst-search d (bst-node d' L R _ _) | tt , p1 | tt , p2 = just (d' , iso𝔹-intro p1 p2)
bst-search d (bst-node d' L R _ _) | tt , p1 | ff , p2 = bst-search d L
bst-search d (bst-node d' L R _ _) | ff , p1 = bst-search d R
bst-dec-lb : ∀ {l l' u' : A} → bst l' u' → l ≤A l' ≡ tt → bst l u'
bst-dec-lb (bst-leaf p) q = bst-leaf (≤A-trans q p)
bst-dec-lb (bst-node d L R p1 p2) q = bst-node d L R (≤A-trans q p1) p2
bst-inc-ub : ∀ {l' u' u : A} → bst l' u' → u' ≤A u ≡ tt → bst l' u
bst-inc-ub (bst-leaf p) q = bst-leaf (≤A-trans p q)
bst-inc-ub (bst-node d L R p1 p2) q = bst-node d L R p1 (≤A-trans p2 q)
bst-insert : ∀{l u : A}(d : A) → bst l u → bst (min d l) (max d u)
bst-insert d (bst-leaf p) = bst-node d (bst-leaf ≤A-refl) (bst-leaf ≤A-refl) min-≤1 max-≤1
bst-insert d (bst-node d' L R p1 p2) with keep (d ≤A d')
bst-insert d (bst-node d' L R p1 p2) | tt , p with bst-insert d L
bst-insert d (bst-node d' L R p1 p2) | tt , p | L' rewrite p =
bst-node d' L' (bst-inc-ub R (≤A-trans p2 max-≤2)) (min2-mono p1) ≤A-refl
bst-insert d (bst-node d' L R p1 p2) | ff , p with bst-insert d R
bst-insert d (bst-node d' L R p1 p2) | ff , p | R' rewrite p =
bst-node d' (bst-dec-lb L p1) R' min-≤2 (max2-mono p2)
|
From mathcomp.ssreflect
Require Import ssreflect ssrbool.
Set Implicit Arguments.
(* Example 4 from "Unifiers as Equivalences" *)
Inductive Im (A B : Type) (f : A -> B) (y : B) : Type :=
image x of y = f x.
(* when would we need the following lemma? Perhaps if the above image proofs are used inside the encoding of a different relation? *)
Lemma im_prop : forall (A B : Type) (f : A -> B) (x x' : A) (e : f x = f x'), eq_rect (f x) (fun y => Im f y) (image f x eq_refl) (f x') e = image f x' eq_refl -> x = x'.
Proof.
move=> A B f x x' e eqims.
(* cannot use e, cannot use eqims...*)
Admitted.
|
[STATEMENT]
lemma parts_subset_iff [simp]: "(parts G \<subseteq> parts H) = (G \<subseteq> parts H)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (parts G \<subseteq> parts H) = (G \<subseteq> parts H)
[PROOF STEP]
apply (rule iffI)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
1. parts G \<subseteq> parts H \<Longrightarrow> G \<subseteq> parts H
2. G \<subseteq> parts H \<Longrightarrow> parts G \<subseteq> parts H
[PROOF STEP]
apply (iprover intro: subset_trans parts_increasing)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. G \<subseteq> parts H \<Longrightarrow> parts G \<subseteq> parts H
[PROOF STEP]
apply (frule parts_mono, simp)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done |
\section{Nine years of FAIMS Mobile}
\begin{sectionframe} % Custom environment required for section slides
\frametitle{Nine years of FAIMS Mobile}
%\framesubtitle{Subtitle}
% Some section slide content
% This is on another line
\end{sectionframe}
%----------------------------------------------------------------------------------------
\begin{frame}{Research Specific}
\begin{figure}[H]
\centering
\vspace{-0.5cm}
\includegraphics[height=.75\textheight]{figures/FAIMS-screenshots.png}
\caption{FAIMS Mobile: GIS and `picture dictionaries'}
\label{fig:FAIMS-mobile-screenshots}
\end{figure}
\end{frame}
% %----------------------------------------------------------------------------------------
\begin{frame}{Key research-specific features}
\begin{columns}[T]
\begin{column}{0.45\textwidth}
\begin{itemize}
\item Customisable workflows.
\item Offline capable.
\item Complete data provenance / version history.
\item Binds text, structured, geospatial, multimedia data.
\item Mobile GIS with layers, raster and vector display, shape creation.
\item Uses device and external sensors.
\item Multimedia file and metadata management.
\end{itemize}
\end{column}
\begin{column}{0.45\textwidth}
\begin{itemize}
\item Validation and automation on device or server.
\item Multilingual user-interface.
\item Granular metadata: Notes and certainty for each field.
\item Contextual help with images.
\item Structured data can implement vocabularies / ontologies, LOD approaches.
\item Data can be exported in a variety of formats, including custom exports.
\end{itemize}
\end{column}
\end{columns}
\end{frame}
%----------------------------------------------------------------------------------------
\begin{frame}{Generalised}
\begin{figure}[H]
\centering
\vspace{-0.5cm}
\includegraphics[height=.75\textheight]{figures/FAIMS-generalised.png}
\caption{FAIMS Mobile customisations on GitHub}
\label{fig:FAIMS-github}
\end{figure}
\end{frame}
%----------------------------------------------------------------------------------------
\begin{frame}{Modular and federated}
\begin{figure}[H]
\centering
\vspace{-0.5cm}
\includegraphics[height=.75\textheight]{figures/FAIMS-federation}
\caption{FAIMS Mobile federation}
\label{fig:FAIMS-federation}
\end{figure}
\end{frame}
%----------------------------------------------------------------------------------------
\begin{frame}{Open Source}
\begin{figure}[H]
\centering
\includegraphics[width=.65\textwidth]{figures/asf_logo_url.png}
\label{fig:FAIMS-github-OSS}
\end{figure}
FAIMS Mobile v0.1-2.6 `core' code is licensed GPLv3; FAIMS 3.0 is licensed Apache 2.0; definition files are openly licensed (CC-BY); everything is on GitHub
\end{frame}
%----------------------------------------------------------------------------------------
\begin{frame}{FAIMS by the numbers}
\begin{itemize}
\item \textbf{64 field data capture workflows customised}.
\item \textbf{48 workflows confirmed deployed} to field at over \textbf{40 projects}.
\item \textbf{100s of users} logged \textbf{10,000s hours} on the platform.
\item Deployments took place in disciplines including \textbf{archaeology, geoscience, ecology, oral history, ecology, }and \textbf{linguistics}.
\end{itemize}
\end{frame}
%----------------------------------------------------------------------------------------
\begin{frame}{Example deployments}
\begin{itemize}
\item Indigenous Foodways in the Cape York Peninsula (UNE, archaeology)
\item Khirbet el-Rai Excavations, Israel (Macquarie, archaeology).
\item Landscape Archaeology at Lake Mungo (LTU, archaeology)
\item Excavation at the Boncuklu Höyük, Turkey (UQ, archaeology).
\item Tao River Archaeological Project, China (Harvard, archaeology).
\item Proyecto Arqueològico Zaña Colonial, Peru (Brown, archaeology).
\item The Malawi Earlier-Middle Stone Age Project (Yale, archaeology).
\item Avian Ecology in NSW (Macquarie, ecology)
\item The Greek-Australian Historical Archive (UNSW, oral history).
\item Key Pluridisciplinary Advances on African Multilingualism, Cameroon (SUNY Buffalo, linguistics).
\item Capricorn Distal Footprints Project (CSIRO, geological sampling).
\end{itemize}
\end{frame} |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kevin Buzzard
-/
import algebra.big_operators.nat_antidiagonal
import algebra.geom_sum
import data.fintype.card
import ring_theory.power_series.well_known
import tactic.field_simp
/-!
# Bernoulli numbers
The Bernoulli numbers are a sequence of rational numbers that frequently show up in
number theory.
## Mathematical overview
The Bernoulli numbers $(B_0, B_1, B_2, \ldots)=(1, -1/2, 1/6, 0, -1/30, \ldots)$ are
a sequence of rational numbers. They show up in the formula for the sums of $k$th
powers. They are related to the Taylor series expansions of $x/\tan(x)$ and
of $\coth(x)$, and also show up in the values that the Riemann Zeta function
takes both at both negative and positive integers (and hence in the
theory of modular forms). For example, if $1 \leq n$ is even then
$$\zeta(2n)=\sum_{t\geq1}t^{-2n}=(-1)^{n+1}\frac{(2\pi)^{2n}B_{2n}}{2(2n)!}.$$
Note however that this result is not yet formalised in Lean.
The Bernoulli numbers can be formally defined using the power series
$$\sum B_n\frac{t^n}{n!}=\frac{t}{1-e^{-t}}$$
although that happens to not be the definition in mathlib (this is an *implementation
detail* and need not concern the mathematician).
Note that $B_1=-1/2$, meaning that we are using the $B_n^-$ of
[from Wikipedia](https://en.wikipedia.org/wiki/Bernoulli_number).
## Implementation detail
The Bernoulli numbers are defined using well-founded induction, by the formula
$$B_n=1-\sum_{k\lt n}\frac{\binom{n}{k}}{n-k+1}B_k.$$
This formula is true for all $n$ and in particular $B_0=1$. Note that this is the definition
for positive Bernoulli numbers, which we call `bernoulli'`. The negative Bernoulli numbers are
then defined as `bernoulli := (-1)^n * bernoulli'`.
## Main theorems
`sum_bernoulli : ∑ k in finset.range n, (n.choose k : ℚ) * bernoulli k = 0`
-/
open_locale nat big_operators
open finset nat finset.nat power_series
variables (A : Type*) [comm_ring A] [algebra ℚ A]
/-! ### Definitions -/
/-- The Bernoulli numbers:
the $n$-th Bernoulli number $B_n$ is defined recursively via
$$B_n = 1 - \sum_{k < n} \binom{n}{k}\frac{B_k}{n+1-k}$$ -/
def bernoulli' : ℕ → ℚ :=
well_founded.fix lt_wf $
λ n bernoulli', 1 - ∑ k : fin n, n.choose k / (n - k + 1) * bernoulli' k k.2
lemma bernoulli'_def' (n : ℕ) :
bernoulli' n = 1 - ∑ k : fin n, n.choose k / (n - k + 1) * bernoulli' k :=
well_founded.fix_eq _ _ _
lemma bernoulli'_def (n : ℕ) :
bernoulli' n = 1 - ∑ k in range n, n.choose k / (n - k + 1) * bernoulli' k :=
by { rw [bernoulli'_def', ← fin.sum_univ_eq_sum_range], refl }
lemma bernoulli'_spec (n : ℕ) :
∑ k in range n.succ, (n.choose (n - k) : ℚ) / (n - k + 1) * bernoulli' k = 1 :=
begin
rw [sum_range_succ_comm, bernoulli'_def n, tsub_self],
conv in (n.choose (_ - _)) { rw choose_symm (mem_range.1 H).le },
simp only [one_mul, cast_one, sub_self, sub_add_cancel, choose_zero_right, zero_add, div_one],
end
lemma bernoulli'_spec' (n : ℕ) :
∑ k in antidiagonal n, ((k.1 + k.2).choose k.2 : ℚ) / (k.2 + 1) * bernoulli' k.1 = 1 :=
begin
refine ((sum_antidiagonal_eq_sum_range_succ_mk _ n).trans _).trans (bernoulli'_spec n),
refine sum_congr rfl (λ x hx, _),
simp only [add_tsub_cancel_of_le, mem_range_succ_iff.mp hx, cast_sub],
end
/-! ### Examples -/
section examples
@[simp] lemma bernoulli'_zero : bernoulli' 0 = 1 :=
by { rw bernoulli'_def, norm_num }
@[simp] lemma bernoulli'_one : bernoulli' 1 = 1/2 :=
by { rw bernoulli'_def, norm_num }
@[simp] lemma bernoulli'_two : bernoulli' 2 = 1/6 :=
by { rw bernoulli'_def, norm_num [sum_range_succ] }
@[simp] lemma bernoulli'_three : bernoulli' 3 = 0 :=
by { rw bernoulli'_def, norm_num [sum_range_succ] }
@[simp] lemma bernoulli'_four : bernoulli' 4 = -1/30 :=
have nat.choose 4 2 = 6 := dec_trivial, -- shrug
by { rw bernoulli'_def, norm_num [sum_range_succ, this] }
end examples
@[simp] lemma sum_bernoulli' (n : ℕ) :
∑ k in range n, (n.choose k : ℚ) * bernoulli' k = n :=
begin
cases n, { simp },
suffices : (n + 1 : ℚ) * ∑ k in range n, ↑(n.choose k) / (n - k + 1) * bernoulli' k =
∑ x in range n, ↑(n.succ.choose x) * bernoulli' x,
{ rw_mod_cast [sum_range_succ, bernoulli'_def, ← this, choose_succ_self_right], ring },
simp_rw [mul_sum, ← mul_assoc],
refine sum_congr rfl (λ k hk, _),
congr',
have : ((n - k : ℕ) : ℚ) + 1 ≠ 0 := by apply_mod_cast succ_ne_zero,
field_simp [← cast_sub (mem_range.1 hk).le, mul_comm],
rw_mod_cast [tsub_add_eq_add_tsub (mem_range.1 hk).le, choose_mul_succ_eq],
end
/-- The exponential generating function for the Bernoulli numbers `bernoulli' n`. -/
def bernoulli'_power_series := mk $ λ n, algebra_map ℚ A (bernoulli' n / n!)
theorem bernoulli'_power_series_mul_exp_sub_one :
bernoulli'_power_series A * (exp A - 1) = X * exp A :=
begin
ext n,
-- constant coefficient is a special case
cases n, { simp },
rw [bernoulli'_power_series, coeff_mul, mul_comm X, sum_antidiagonal_succ'],
suffices : ∑ p in antidiagonal n, (bernoulli' p.1 / p.1!) * ((p.2 + 1) * p.2!)⁻¹ = n!⁻¹,
{ simpa [ring_hom.map_sum] using congr_arg (algebra_map ℚ A) this },
apply eq_inv_of_mul_left_eq_one,
rw sum_mul,
convert bernoulli'_spec' n using 1,
apply sum_congr rfl,
simp_rw [mem_antidiagonal],
rintro ⟨i, j⟩ rfl,
have : (j + 1 : ℚ) ≠ 0 := by exact_mod_cast succ_ne_zero j,
have : (j + 1 : ℚ) * j! * i! ≠ 0 := by simpa [factorial_ne_zero],
have := factorial_mul_factorial_dvd_factorial_add i j,
field_simp [mul_comm _ (bernoulli' i), mul_assoc, add_choose],
rw_mod_cast [mul_comm (j + 1), mul_div_assoc, ← mul_assoc],
rw [cast_mul, cast_mul, mul_div_mul_right, cast_dvd_char_zero, cast_mul],
assumption',
end
/-- Odd Bernoulli numbers (greater than 1) are zero. -/
theorem bernoulli'_odd_eq_zero {n : ℕ} (h_odd : odd n) (hlt : 1 < n) : bernoulli' n = 0 :=
begin
let B := mk (λ n, bernoulli' n / n!),
suffices : (B - eval_neg_hom B) * (exp ℚ - 1) = X * (exp ℚ - 1),
{ cases mul_eq_mul_right_iff.mp this;
simp only [power_series.ext_iff, eval_neg_hom, coeff_X] at h,
{ apply eq_zero_of_neg_eq,
specialize h n,
split_ifs at h;
simp [neg_one_pow_of_odd h_odd, factorial_ne_zero, *] at * },
{ simpa using h 1 } },
have h : B * (exp ℚ - 1) = X * exp ℚ,
{ simpa [bernoulli'_power_series] using bernoulli'_power_series_mul_exp_sub_one ℚ },
rw [sub_mul, h, mul_sub X, sub_right_inj, ← neg_sub, ← neg_mul_eq_mul_neg, neg_eq_iff_neg_eq],
suffices : eval_neg_hom (B * (exp ℚ - 1)) * exp ℚ = eval_neg_hom (X * exp ℚ) * exp ℚ,
{ simpa [mul_assoc, sub_mul, mul_comm (eval_neg_hom (exp ℚ)), exp_mul_exp_neg_eq_one, eq_comm] },
congr',
end
/-- The Bernoulli numbers are defined to be `bernoulli'` with a parity sign. -/
def bernoulli (n : ℕ) : ℚ := (-1)^n * bernoulli' n
lemma bernoulli'_eq_bernoulli (n : ℕ) : bernoulli' n = (-1)^n * bernoulli n :=
by simp [bernoulli, ← mul_assoc, ← sq, ← pow_mul, mul_comm n 2, pow_mul]
@[simp] lemma bernoulli_zero : bernoulli 0 = 1 := by simp [bernoulli]
@[simp] lemma bernoulli_one : bernoulli 1 = -1/2 :=
by norm_num [bernoulli]
theorem bernoulli_eq_bernoulli'_of_ne_one {n : ℕ} (hn : n ≠ 1) : bernoulli n = bernoulli' n :=
begin
by_cases h0 : n = 0, { simp [h0] },
rw [bernoulli, neg_one_pow_eq_pow_mod_two],
cases mod_two_eq_zero_or_one n, { simp [h] },
simp [bernoulli'_odd_eq_zero (odd_iff.mpr h) (one_lt_iff_ne_zero_and_ne_one.mpr ⟨h0, hn⟩)],
end
@[simp] theorem sum_bernoulli (n : ℕ):
∑ k in range n, (n.choose k : ℚ) * bernoulli k = if n = 1 then 1 else 0 :=
begin
cases n, { simp },
cases n, { simp },
suffices : ∑ i in range n, ↑((n + 2).choose (i + 2)) * bernoulli (i + 2) = n / 2,
{ simp only [this, sum_range_succ', cast_succ, bernoulli_one, bernoulli_zero, choose_one_right,
mul_one, choose_zero_right, cast_zero, if_false, zero_add, succ_succ_ne_one], ring },
have f := sum_bernoulli' n.succ.succ,
simp_rw [sum_range_succ', bernoulli'_one, choose_one_right, cast_succ, ← eq_sub_iff_add_eq] at f,
convert f,
{ ext x, rw bernoulli_eq_bernoulli'_of_ne_one (succ_ne_zero x ∘ succ.inj) },
{ simp only [one_div, mul_one, bernoulli'_zero, cast_one, choose_zero_right, add_sub_cancel],
ring },
end
lemma bernoulli_spec' (n : ℕ) :
∑ k in antidiagonal n, ((k.1 + k.2).choose k.2 : ℚ) / (k.2 + 1) * bernoulli k.1 =
if n = 0 then 1 else 0 :=
begin
cases n, { simp },
rw if_neg (succ_ne_zero _),
-- algebra facts
have h₁ : (1, n) ∈ antidiagonal n.succ := by simp [mem_antidiagonal, add_comm],
have h₂ : (n : ℚ) + 1 ≠ 0 := by apply_mod_cast succ_ne_zero,
have h₃ : (1 + n).choose n = n + 1 := by simp [add_comm],
-- key equation: the corresponding fact for `bernoulli'`
have H := bernoulli'_spec' n.succ,
-- massage it to match the structure of the goal, then convert piece by piece
rw sum_eq_add_sum_diff_singleton h₁ at H ⊢,
apply add_eq_of_eq_sub',
convert eq_sub_of_add_eq' H using 1,
{ refine sum_congr rfl (λ p h, _),
obtain ⟨h', h''⟩ : p ∈ _ ∧ p ≠ _ := by rwa [mem_sdiff, mem_singleton] at h,
simp [bernoulli_eq_bernoulli'_of_ne_one ((not_congr (antidiagonal_congr h' h₁)).mp h'')] },
{ field_simp [h₃],
norm_num },
end
/-- The exponential generating function for the Bernoulli numbers `bernoulli n`. -/
def bernoulli_power_series := mk $ λ n, algebra_map ℚ A (bernoulli n / n!)
theorem bernoulli_power_series_mul_exp_sub_one :
bernoulli_power_series A * (exp A - 1) = X :=
begin
ext n,
-- constant coefficient is a special case
cases n, { simp },
simp only [bernoulli_power_series, coeff_mul, coeff_X, sum_antidiagonal_succ', one_div, coeff_mk,
coeff_one, coeff_exp, linear_map.map_sub, factorial, if_pos, cast_succ, cast_one, cast_mul,
sub_zero, ring_hom.map_one, add_eq_zero_iff, if_false, inv_one, zero_add, one_ne_zero, mul_zero,
and_false, sub_self, ← ring_hom.map_mul, ← ring_hom.map_sum],
suffices : ∑ x in antidiagonal n, bernoulli x.1 / x.1! * ((x.2 + 1) * x.2!)⁻¹
= if n.succ = 1 then 1 else 0, { split_ifs; simp [h, this] },
cases n, { simp },
have hfact : ∀ m, (m! : ℚ) ≠ 0 := λ m, by exact_mod_cast factorial_ne_zero m,
have hite1 : ite (n.succ.succ = 1) 1 0 = (0 / n.succ! : ℚ) := by simp,
have hite2 : ite (n.succ = 0) 1 0 = (0 : ℚ) := by simp [succ_ne_zero],
rw [hite1, eq_div_iff (hfact n.succ), ← hite2, ← bernoulli_spec', sum_mul],
apply sum_congr rfl,
rintro ⟨i, j⟩ h,
rw mem_antidiagonal at h,
have hj : (j.succ : ℚ) ≠ 0 := by exact_mod_cast succ_ne_zero j,
field_simp [← h, mul_ne_zero hj (hfact j), hfact i, mul_comm _ (bernoulli i), mul_assoc],
rw_mod_cast [mul_comm (j + 1), mul_div_assoc, ← mul_assoc],
rw [cast_mul, cast_mul, mul_div_mul_right _ _ hj, add_choose, cast_dvd_char_zero],
apply factorial_mul_factorial_dvd_factorial_add,
end
section faulhaber
/-- **Faulhaber's theorem** relating the **sum of of p-th powers** to the Bernoulli numbers:
$$\sum_{k=0}^{n-1} k^p = \sum_{i=0}^p B_i\binom{p+1}{i}\frac{n^{p+1-i}}{p+1}.$$
See https://proofwiki.org/wiki/Faulhaber%27s_Formula and [orosi2018faulhaber] for
the proof provided here. -/
theorem sum_range_pow (n p : ℕ) :
∑ k in range n, (k : ℚ) ^ p =
∑ i in range (p + 1), bernoulli i * (p + 1).choose i * n ^ (p + 1 - i) / (p + 1) :=
begin
have hne : ∀ m : ℕ, (m! : ℚ) ≠ 0 := λ m, by exact_mod_cast factorial_ne_zero m,
-- compute the Cauchy product of two power series
have h_cauchy : mk (λ p, bernoulli p / p!) * mk (λ q, coeff ℚ (q + 1) (exp ℚ ^ n))
= mk (λ p, ∑ i in range (p + 1),
bernoulli i * (p + 1).choose i * n ^ (p + 1 - i) / (p + 1)!),
{ ext q,
let f := λ a b, bernoulli a / a! * coeff ℚ (b + 1) (exp ℚ ^ n),
-- key step: use `power_series.coeff_mul` and then rewrite sums
simp only [coeff_mul, coeff_mk, cast_mul, sum_antidiagonal_eq_sum_range_succ f],
apply sum_congr rfl,
simp_intros m h only [finset.mem_range],
simp only [f, exp_pow_eq_rescale_exp, rescale, one_div, coeff_mk, ring_hom.coe_mk, coeff_exp,
ring_hom.id_apply, cast_mul, rat.algebra_map_rat_rat],
-- manipulate factorials and binomial coefficients
rw [choose_eq_factorial_div_factorial h.le, eq_comm, div_eq_iff (hne q.succ), succ_eq_add_one,
mul_assoc _ _ ↑q.succ!, mul_comm _ ↑q.succ!, ← mul_assoc, div_mul_eq_mul_div,
mul_comm (↑n ^ (q - m + 1)), ← mul_assoc _ _ (↑n ^ (q - m + 1)), ← one_div, mul_one_div,
div_div_eq_div_mul, tsub_add_eq_add_tsub (le_of_lt_succ h), cast_dvd, cast_mul],
{ ring },
{ exact factorial_mul_factorial_dvd_factorial h.le },
{ simp [hne] } },
-- same as our goal except we pull out `p!` for convenience
have hps : ∑ k in range n, ↑k ^ p
= (∑ i in range (p + 1), bernoulli i * (p + 1).choose i * n ^ (p + 1 - i) / (p + 1)!)
* p!,
{ suffices : mk (λ p, ∑ k in range n, ↑k ^ p * algebra_map ℚ ℚ p!⁻¹)
= mk (λ p, ∑ i in range (p + 1),
bernoulli i * (p + 1).choose i * n ^ (p + 1 - i) / (p + 1)!),
{ rw [← div_eq_iff (hne p), div_eq_mul_inv, sum_mul],
rw power_series.ext_iff at this,
simpa using this p },
-- the power series `exp ℚ - 1` is non-zero, a fact we need in order to use `mul_right_inj'`
have hexp : exp ℚ - 1 ≠ 0,
{ simp only [exp, power_series.ext_iff, ne, not_forall],
use 1,
simp },
have h_r : exp ℚ ^ n - 1 = X * mk (λ p, coeff ℚ (p + 1) (exp ℚ ^ n)),
{ have h_const : C ℚ (constant_coeff ℚ (exp ℚ ^ n)) = 1 := by simp,
rw [← h_const, sub_const_eq_X_mul_shift] },
-- key step: a chain of equalities of power series
rw [← mul_right_inj' hexp, mul_comm, ← exp_pow_sum, ← geom_sum_def, geom_sum_mul, h_r,
← bernoulli_power_series_mul_exp_sub_one, bernoulli_power_series, mul_right_comm],
simp [h_cauchy, mul_comm] },
-- massage `hps` into our goal
rw [hps, sum_mul],
refine sum_congr rfl (λ x hx, _),
field_simp [mul_right_comm _ ↑p!, ← mul_assoc _ _ ↑p!, cast_add_one_ne_zero, hne],
end
/-- Alternate form of **Faulhaber's theorem**, relating the sum of p-th powers to the Bernoulli
numbers: $$\sum_{k=1}^{n} k^p = \sum_{i=0}^p (-1)^iB_i\binom{p+1}{i}\frac{n^{p+1-i}}{p+1}.$$
Deduced from `sum_range_pow`. -/
theorem sum_Ico_pow (n p : ℕ) :
∑ k in Ico 1 (n + 1), (k : ℚ) ^ p =
∑ i in range (p + 1), bernoulli' i * (p + 1).choose i * n ^ (p + 1 - i) / (p + 1) :=
begin
-- dispose of the trivial case
cases p, { simp },
let f := λ i, bernoulli i * p.succ.succ.choose i * n ^ (p.succ.succ - i) / p.succ.succ,
let f' := λ i, bernoulli' i * p.succ.succ.choose i * n ^ (p.succ.succ - i) / p.succ.succ,
suffices : ∑ k in Ico 1 n.succ, ↑k ^ p.succ = ∑ i in range p.succ.succ, f' i, { convert this },
-- prove some algebraic facts that will make things easier for us later on
have hle := nat.le_add_left 1 n,
have hne : (p + 1 + 1 : ℚ) ≠ 0 := by exact_mod_cast succ_ne_zero p.succ,
have h1 : ∀ r : ℚ, r * (p + 1 + 1) * n ^ p.succ / (p + 1 + 1 : ℚ) = r * n ^ p.succ :=
λ r, by rw [mul_div_right_comm, mul_div_cancel _ hne],
have h2 : f 1 + n ^ p.succ = 1 / 2 * n ^ p.succ,
{ simp_rw [f, bernoulli_one, choose_one_right, succ_sub_succ_eq_sub, cast_succ, tsub_zero, h1],
ring },
have : ∑ i in range p, bernoulli (i + 2) * (p + 2).choose (i + 2) * n ^ (p - i) / ↑(p + 2)
= ∑ i in range p, bernoulli' (i + 2) * (p + 2).choose (i + 2) * n ^ (p - i) / ↑(p + 2) :=
sum_congr rfl (λ i h, by rw bernoulli_eq_bernoulli'_of_ne_one (succ_succ_ne_one i)),
calc ∑ k in Ico 1 n.succ, ↑k ^ p.succ
-- replace sum over `Ico` with sum over `range` and simplify
= ∑ k in range n.succ, ↑k ^ p.succ : by simp [sum_Ico_eq_sub _ hle, succ_ne_zero]
-- extract the last term of the sum
... = ∑ k in range n, (k : ℚ) ^ p.succ + n ^ p.succ : by rw sum_range_succ
-- apply the key lemma, `sum_range_pow`
... = ∑ i in range p.succ.succ, f i + n ^ p.succ : by simp [f, sum_range_pow]
-- extract the first two terms of the sum
... = ∑ i in range p, f i.succ.succ + f 1 + f 0 + n ^ p.succ : by simp_rw [sum_range_succ']
... = ∑ i in range p, f i.succ.succ + (f 1 + n ^ p.succ) + f 0 : by ring
... = ∑ i in range p, f i.succ.succ + 1 / 2 * n ^ p.succ + f 0 : by rw h2
-- convert from `bernoulli` to `bernoulli'`
... = ∑ i in range p, f' i.succ.succ + f' 1 + f' 0 : by { simp only [f, f'], simpa [h1] }
-- rejoin the first two terms of the sum
... = ∑ i in range p.succ.succ, f' i : by simp_rw [sum_range_succ'],
end
end faulhaber
|
/-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Sean Leather
List folds generalized to `traversable`. Informally, we can think of
`foldl` as a special case of `traverse` where we do not care about the
reconstructed data structure and, in a state monad, we care about the
final state.
The obvious way to define `foldl` would be to use the state monad but it
is nicer to reason about a more abstract interface with `fold_map` as a
primitive and `fold_map_hom` as a defining property.
def fold_map {α ω} [has_one ω] [has_mul ω] (f : α → ω) : t α → ω := ...
lemma fold_map_hom (α β)
[monoid α] [monoid β] (f : α → β) [is_monoid_hom f]
(g : γ → α) (x : t γ) :
f (fold_map g x) = fold_map (f ∘ g) x :=
...
`fold_map` uses a monoid ω to accumulate a value for every element of
a data structure and `fold_map_hom` uses a monoid homomorphism to
substitute the monoid used by `fold_map`. The two are sufficient to
define `foldl`, `foldr` and `to_list`. `to_list` permits the
formulation of specifications in terms of operations on lists.
Each fold function can be defined using a specialized
monoid. `to_list` uses a free monoid represented as a list with
concatenation while `foldl` uses endofunctions together with function
composition.
The definition through monoids uses `traverse` together with the
applicative functor `const m` (where `m` is the monoid). As an
implementation, `const` guarantees that no resource is spent on
reconstructing the structure during traversal.
A special class could be defined for `foldable`, similarly to Haskell,
but the author cannot think of instances of `foldable` that are not also
`traversable`.
-/
import tactic.squeeze
import algebra.group
import data.list.basic
import category.traversable.instances category.traversable.lemmas
import category_theory.category category_theory.types category_theory.opposites category_theory.instances.kleisli
import category.applicative
universes u v
open ulift category_theory
namespace monoid
variables {m : Type u → Type u} [monad m]
variables {α β : Type u}
/--
For a list, foldl f x [y₀,y₁] reduces as follows
calc foldl f x [y₀,y₁]
= foldl f (f x y₀) [y₁] : rfl
... = foldl f (f (f x y₀) y₁) [] : rfl
... = f (f x y₀) y₁ : rfl
with f : α → β → α
x : α
[y₀,y₁] : list β
We can view the above as a composition of functions:
... = f (f x y₀) y₁ : rfl
... = flip f y₁ (flip f y₀ x) : rfl
... = (flip f y₁ ∘ flip f y₀) x : rfl
We can use traverse and const to construct this composition:
calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x
= const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x
... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x
... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x
... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x
... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x
... = const.run ( flip f y₁ ∘ flip f y₀ ) x
... = f (f x y₀) y₁
And this is how `const` turns a monoid into an applicative functor and
how the monoid of endofunctions define `foldl`.
-/
@[reducible] def foldl (α : Type u) : Type u := End α
def foldl.mk (f : α → α) : foldl α := f
def foldl.of_free_monoid (f : β → α → β) (xs : free_monoid α) : monoid.foldl β :=
flip (list.foldl f) xs
@[reducible] def foldr (α : Type u) : Type u := (End α)ᵒᵖ
def foldr.mk (f : α → α) : foldr α := op f
def foldr.get (x : foldr α) : α → α := unop x
def foldr.of_free_monoid (f : α → β → β) (xs : free_monoid α) : monoid.foldr β :=
op $ flip (list.foldr f) xs
@[reducible] def mfoldl (m : Type u → Type u) [monad m] (α : Type u) : Type u := End $ Kleisli.mk m α
def mfoldl.mk (f : α → m α) : mfoldl m α := f
def mfoldl.of_free_monoid (f : β → α → m β) (xs : free_monoid α) : monoid.mfoldl m β :=
flip (list.mfoldl f) xs
@[reducible] def mfoldr (m : Type u → Type u) [monad m] (α : Type u) : Type u := (End $ Kleisli.mk m α)ᵒᵖ
def mfoldr.mk (f : α → m α) : mfoldr m α := op f
def mfoldr.get (x : mfoldr m α) : α → m α := unop x
def mfoldr.of_free_monoid (f : α → β → m β) (xs : free_monoid α) : monoid.mfoldr m β :=
op $ flip (list.mfoldr f) xs
end monoid
namespace traversable
open monoid functor
section defs
variables {α β : Type u} {t : Type u → Type u} [traversable t]
def fold_map {α ω} [has_one ω] [has_mul ω] (f : α → ω) : t α → ω :=
traverse (const.mk' ∘ f)
def foldl (f : α → β → α) (x : α) (xs : t β) : α :=
fold_map (foldl.mk ∘ flip f) xs x
def foldr (f : α → β → β) (x : β) (xs : t α) : β :=
unop (fold_map (foldr.mk ∘ f) xs) x
/--
Conceptually, `to_list` collects all the elements of a collection
in a list. This idea is formalized by
`lemma to_list_spec (x : t α) : to_list x = fold_map free_monoid.mk x`.
The definition of `to_list` is based on `foldl` and `list.cons` for
speed. It is faster than using `fold_map free_monoid.mk` because, by
using `foldl` and `list.cons`, each insertion is done in constant
time. As a consequence, `to_list` performs in linear.
On the other hand, `fold_map free_monoid.mk` creates a singleton list
around each element and concatenates all the resulting lists. In
`xs ++ ys`, concatenation takes a time proportional to `length xs`. Since
the order in which concatenation is evaluated is unspecified, nothing
prevents each element of the traversable to be appended at the end
`xs ++ [x]` which would yield a `O(n²)` run time. -/
def to_list : t α → list α :=
list.reverse ∘ foldl (flip list.cons) []
def length (xs : t α) : ℕ :=
down $ foldl (λ l _, up $ l.down + 1) (up 0) xs
variables {m : Type u → Type u} [monad m]
def mfoldl (f : α → β → m α) (x : α) (xs : t β) : m α :=
fold_map (mfoldl.mk ∘ flip f) xs x
def mfoldr (f : α → β → m β) (x : β) (xs : t α) : m β :=
unop (fold_map (mfoldr.mk ∘ f) xs) x
end defs
section applicative_transformation
variables {α β γ : Type u}
open function (hiding const) is_monoid_hom
def map_fold [monoid α] [monoid β] (f : α → β) [is_monoid_hom f] :
applicative_transformation (const α) (const β) :=
{ app := λ x, f,
preserves_seq' := by { intros, simp only [map_mul f], },
preserves_pure' := by { intros, simp only [map_one f] } }
def free.mk : α → free_monoid α := list.ret
def free.map (f : α → β) : free_monoid α → free_monoid β := list.map f
lemma free.map_eq_map (f : α → β) (xs : list α) :
f <$> xs = free.map f xs := rfl
instance (f : α → β) : is_monoid_hom (free.map f) :=
by constructor; simp only [free.map, list.map_append, forall_2_true_iff, free_add_monoid.add_def, list.map, free_add_monoid.zero_def, list.map, eq_self_iff_true]
instance fold_foldl (f : β → α → β) :
is_monoid_hom (foldl.of_free_monoid f) :=
{ map_one := rfl,
map_mul := by { intros, unfold_projs, simp only [foldl.of_free_monoid, flip, list.foldl_append], } }
lemma foldr.unop_of_free_monoid (f : α → β → β) (xs : free_monoid α) (a : β) :
unop (foldr.of_free_monoid f xs) a = list.foldr f a xs := rfl
instance fold_foldr (f : α → β → β) :
is_monoid_hom (foldr.of_free_monoid f) :=
{ map_one := rfl,
map_mul := by { intros, apply unop_inj, ext, simp only [foldr.of_free_monoid,flip,free_add_monoid.add_def, list.foldr_append], refl } }
variables (m : Type u → Type u) [monad m] [is_lawful_monad m]
instance fold_mfoldl (f : β → α → m β) :
is_monoid_hom (mfoldl.of_free_monoid f) :=
{ map_one := rfl,
map_mul := by { intros, unfold_projs, simp only [mfoldl.of_free_monoid,flip, list.mfoldl_append] } }
@[simp]
lemma mfoldr.unop_of_free_monoid (f : α → β → m β) (xs : free_monoid α) (a : β) :
unop (mfoldr.of_free_monoid f xs) a = list.mfoldr f a xs := rfl
instance fold_mfoldr (f : α → β → m β) :
is_monoid_hom (mfoldr.of_free_monoid f) :=
{ map_one := rfl,
map_mul := by { intros, apply unop_inj, ext, simp only [list.mfoldr_append, mfoldr.unop_of_free_monoid, free_add_monoid.add_def],
apply bind_ext_congr, simp only [mfoldr.unop_of_free_monoid, eq_self_iff_true, forall_true_iff], } }
variables {t : Type u → Type u} [traversable t] [is_lawful_traversable t]
open is_lawful_traversable
lemma fold_map_hom
[monoid α] [monoid β] (f : α → β) [is_monoid_hom f]
(g : γ → α) (x : t γ) :
f (fold_map g x) = fold_map (f ∘ g) x :=
calc f (fold_map g x)
= f (traverse (const.mk' ∘ g) x) : rfl
... = (map_fold f).app _ (traverse (const.mk' ∘ g) x) : rfl
... = traverse ((map_fold f).app _ ∘ (const.mk' ∘ g)) x : naturality (map_fold f) _ _
... = fold_map (f ∘ g) x : rfl
lemma fold_map_hom_free
[monoid β] (f : free_monoid α → β) [is_monoid_hom f] (x : t α) :
f (fold_map free.mk x) = fold_map (f ∘ free.mk) x :=
fold_map_hom _ _ x
variable {m}
lemma fold_mfoldl_cons (f : α → β → m α) (x : β) (y : α) :
list.mfoldl f y (free.mk x) = f y x :=
by simp only [free.mk, list.ret, list.mfoldl, bind_pure]
lemma fold_mfoldr_cons (f : β → α → m α) (x : β) (y : α) :
list.mfoldr f y (free.mk x) = f x y :=
by simp only [free.mk, list.ret, list.mfoldr, pure_bind]
end applicative_transformation
section equalities
open is_lawful_traversable list (cons)
variables {α β γ : Type u}
variables {t : Type u → Type u} [traversable t] [is_lawful_traversable t]
@[simp]
lemma foldl.of_free_monoid_comp_free_mk (f : α → β → α) : foldl.of_free_monoid f ∘ free.mk = foldl.mk ∘ flip f := rfl
@[simp]
lemma foldr.of_free_monoid_comp_free_mk (f : β → α → α) : foldr.of_free_monoid f ∘ free.mk = foldr.mk ∘ f := rfl
@[simp]
lemma mfoldl.of_free_monoid_comp_free_mk {m} [monad m] [is_lawful_monad m] (f : α → β → m α) : mfoldl.of_free_monoid f ∘ free.mk = mfoldl.mk ∘ flip f :=
by { ext, simp only [(∘), mfoldl.of_free_monoid, mfoldl.mk, flip, fold_mfoldl_cons] }
@[simp]
lemma mfoldr.of_free_monoid_comp_free_mk {m} [monad m] [is_lawful_monad m] (f : β → α → m α) : mfoldr.of_free_monoid f ∘ free.mk = mfoldr.mk ∘ f :=
by { ext, apply unop_inj, ext, simp only [(∘),mfoldr.of_free_monoid,mfoldr.mk,flip,fold_mfoldr_cons] }
lemma to_list_spec (xs : t α) :
to_list xs = (fold_map free.mk xs : free_monoid _) :=
eq.symm $
calc fold_map free.mk xs
= (fold_map free.mk xs).reverse.reverse : by simp only [list.reverse_reverse]
... = (list.foldr cons [] (fold_map free.mk xs).reverse).reverse
: by simp only [list.foldr_eta]
... = (foldl.of_free_monoid (flip cons) (fold_map free.mk xs) []).reverse
: by simp only [flip,list.foldr_reverse,foldl.of_free_monoid]
... = to_list xs : by { rw fold_map_hom_free (foldl.of_free_monoid (flip cons)),
simp only [to_list, foldl, list.reverse_inj, foldl.of_free_monoid_comp_free_mk],
all_goals { apply_instance } }
lemma fold_map_map [monoid γ] (f : α → β) (g : β → γ) (xs : t α) :
fold_map g (f <$> xs) = fold_map (g ∘ f) xs :=
by simp only [fold_map,traverse_map]
lemma foldl_to_list (f : α → β → α) (xs : t β) (x : α) :
foldl f x xs = list.foldl f x (to_list xs) :=
by { change _ = foldl.of_free_monoid _ _ _,
simp only [foldl, to_list_spec, fold_map_hom_free (foldl.of_free_monoid f), foldl.of_free_monoid_comp_free_mk] }
lemma foldr_to_list (f : α → β → β) (xs : t α) (x : β) :
foldr f x xs = list.foldr f x (to_list xs) :=
by { rw ← foldr.unop_of_free_monoid,
simp only [foldr, to_list_spec, fold_map_hom_free (foldr.of_free_monoid f), foldr.of_free_monoid_comp_free_mk] }
lemma to_list_map (f : α → β) (xs : t α) :
to_list (f <$> xs) = f <$> to_list xs :=
by simp only [to_list_spec,free.map_eq_map,fold_map_hom (free.map f), fold_map_map]; refl
@[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) :
foldl f a (g <$> l) = foldl (λ x y, f x (g y)) a l :=
by simp only [foldl, fold_map_map, (∘), flip]
@[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) :
foldr f a (g <$> l) = foldr (f ∘ g) a l :=
by simp only [foldr, fold_map_map, (∘), flip]
@[simp] theorem to_list_eq_self {xs : list α} : to_list xs = xs :=
begin
simp only [to_list_spec, fold_map, traverse],
induction xs,
case list.nil { refl },
case list.cons : _ _ ih { unfold list.traverse list.ret, rw ih, refl }
end
theorem length_to_list {xs : t α} : length xs = list.length (to_list xs) :=
begin
unfold length,
rw foldl_to_list,
generalize : to_list xs = ys,
let f := λ (n : ℕ) (a : α), n + 1,
transitivity list.foldl f 0 ys,
{ generalize : 0 = n,
induction ys with _ _ ih generalizing n,
{ simp only [list.foldl_nil] },
{ simp only [list.foldl, ih (n+1)] } },
{ induction ys with _ tl ih,
{ simp only [list.length, list.foldl_nil] },
{ simp only [list.foldl, list.length],
transitivity list.foldl f 0 tl + 1,
{ exact eq.symm (list.foldl_hom (+1) f f 0 (λ _ _, rfl) _) },
{ rw ih } } }
end
variables {m : Type u → Type u} [monad m] [is_lawful_monad m]
lemma mfoldl_to_list {f : α → β → m α} {x : α} {xs : t β} :
mfoldl f x xs = list.mfoldl f x (to_list xs) :=
by { change _ = mfoldl.of_free_monoid f (to_list xs) x,
simp only [mfoldl, to_list_spec, fold_map_hom_free (mfoldl.of_free_monoid f),mfoldl.of_free_monoid_comp_free_mk] }
lemma mfoldr_to_list (f : α → β → m β) (x : β) (xs : t α) :
mfoldr f x xs = list.mfoldr f x (to_list xs) :=
by { change _ = unop (mfoldr.of_free_monoid f (to_list xs)) x,
simp only [mfoldr, to_list_spec, fold_map_hom_free (mfoldr.of_free_monoid f),mfoldr.of_free_monoid_comp_free_mk] }
@[simp] theorem mfoldl_map (g : β → γ) (f : α → γ → m α) (a : α) (l : t β) :
mfoldl f a (g <$> l) = mfoldl (λ x y, f x (g y)) a l :=
by simp only [mfoldl, fold_map_map, (∘), flip]
@[simp] theorem mfoldr_map (g : β → γ) (f : γ → α → m α) (a : α) (l : t β) :
mfoldr f a (g <$> l) = mfoldr (f ∘ g) a l :=
by simp only [mfoldr, fold_map_map, (∘), flip]
end equalities
end traversable
|
module Main
( main
) where
-------------------------------------------------------------------------------
import Criterion
import Criterion.Main
import Data.Foldable
-------------------------------------------------------------------------------
import Statistics.RollingAverage
-------------------------------------------------------------------------------
main :: IO ()
main = defaultMain [
bgroup "ravgAdd" $ flip map [1, 100, 1000] $ \n ->
bgroup (show n) [
bench "Int" $ whnf (avgList n) ([1..fromIntegral n] :: [Int])
, bench "Integer" $ whnf (avgList n) ([1..fromIntegral n] :: [Integer])
]
, bgroup "ravg" $ flip map [1, 100, 1000] $ \n ->
bgroup (show n) [
bench "Int" $ whnf ravg' (avgList n ([1..fromIntegral n] :: [Int]))
, bench "Integer" $ whnf ravg' (avgList n ([1..fromIntegral n] :: [Integer]))
]
]
-------------------------------------------------------------------------------
avgList :: Num a => Int -> [a] -> RollingAvg a
avgList lim = foldl' ravgAdd (mkRavg lim)
-------------------------------------------------------------------------------
ravg' :: (Integral a) => RollingAvg a -> Double
ravg' = ravg
|
> module Nat.Positive
> import Syntax.PreorderReasoning
> import Unique.Predicates
> import Subset.Properties
> %default total
> %access public export
> %auto_implicits on
> |||
> data Positive : Nat -> Type where
> MkPositive : {n : Nat} -> Positive (S n)
> |||
> PositiveUnique : {n : Nat} -> Unique (Positive n)
> PositiveUnique MkPositive MkPositive = Refl
> |||
> fromSucc : (m : Nat) -> (n : Nat) -> S m = n -> Positive n
> fromSucc m n prf = s2 where
> s1 : Positive (S m)
> s1 = MkPositive
> s2 : Positive n
> s2 = replace prf s1
> |||
> implementation Uninhabited (Positive Z) where
> uninhabited (MkPositive {n}) impossible
> |||
> positiveNotZ : {n : Nat} -> Positive n -> Not (n = Z)
> positiveNotZ {n = Z} p = absurd p
> positiveNotZ {n = S m} _ = SIsNotZ
> |||
> plusPreservesPositivity : Positive m -> Positive n -> Positive (m + n)
> plusPreservesPositivity {m = Z } {n } MkPositive _ impossible
> plusPreservesPositivity {m } {n = Z } _ MkPositive impossible
> plusPreservesPositivity {m = S m} {n = S n} _ _ = MkPositive
> |||
> multPreservesPositivity : Positive m -> Positive n -> Positive (m * n)
> multPreservesPositivity {m = Z } {n } MkPositive _ impossible
> multPreservesPositivity {m } {n = Z } _ MkPositive impossible
> multPreservesPositivity {m = S m} {n = S n} _ _ = MkPositive
|
[STATEMENT]
lemma mset_lt_single_iff[iff]: "{#x#} < {#y#} \<longleftrightarrow> x < y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. ({#x#} < {#y#}) = (x < y)
[PROOF STEP]
unfolding less_multiset\<^sub>H\<^sub>O
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. ({#x#} \<noteq> {#y#} \<and> (\<forall>ya. count {#y#} ya < count {#x#} ya \<longrightarrow> (\<exists>xa>ya. count {#x#} xa < count {#y#} xa))) = (x < y)
[PROOF STEP]
by simp |
/**
*
* @file qwrapper_slaset.c
*
* PLASMA core_blas quark wrapper
* PLASMA is a software package provided by Univ. of Tennessee,
* Univ. of California Berkeley and Univ. of Colorado Denver
*
* @version 2.6.0
* @author Hatem Ltaief
* @date 2010-11-15
* @generated s Tue Jan 7 11:44:58 2014
*
**/
#include <lapacke.h>
#include "common.h"
/***************************************************************************//**
*
**/
void QUARK_CORE_slaset(Quark *quark, Quark_Task_Flags *task_flags,
PLASMA_enum uplo, int M, int N,
float alpha, float beta,
float *A, int LDA)
{
DAG_CORE_LASET;
QUARK_Insert_Task(quark, CORE_slaset_quark, task_flags,
sizeof(PLASMA_enum), &uplo, VALUE,
sizeof(int), &M, VALUE,
sizeof(int), &N, VALUE,
sizeof(float), &alpha, VALUE,
sizeof(float), &beta, VALUE,
sizeof(float)*LDA*N, A, OUTPUT,
sizeof(int), &LDA, VALUE,
0);
}
/***************************************************************************//**
*
**/
#if defined(PLASMA_HAVE_WEAK)
#pragma weak CORE_slaset_quark = PCORE_slaset_quark
#define CORE_slaset_quark PCORE_slaset_quark
#endif
void CORE_slaset_quark(Quark *quark)
{
PLASMA_enum uplo;
int M;
int N;
float alpha;
float beta;
float *A;
int LDA;
quark_unpack_args_7(quark, uplo, M, N, alpha, beta, A, LDA);
LAPACKE_slaset_work(
LAPACK_COL_MAJOR,
lapack_const(uplo),
M, N, alpha, beta, A, LDA);
}
|
(* ** AES-NI *)
(* From eclib/AES.ec *)
(* ** Imports and settings *)
From mathcomp Require Import all_ssreflect all_algebra.
From mathcomp Require Import word_ssrZ word.
Require Import word.
Require Import Psatz ZArith utils.
Import Utf8.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import ssrnat.
Local Open Scope Z_scope.
(* -------------------------------------------------------------- *)
Definition Sbox (v1 : u8) : u8 :=
wrepr U8 match toword v1 with
| 0 => 99 | 1 => 124 | 2 => 119 | 3 => 123 | 4 => 242
| 5 => 107 | 6 => 111 | 7 => 197 | 8 => 48 | 9 => 1
| 10 => 103 | 11 => 43 | 12 => 254 | 13 => 215 | 14 => 171
| 15 => 118 | 16 => 202 | 17 => 130 | 18 => 201 | 19 => 125
| 20 => 250 | 21 => 89 | 22 => 71 | 23 => 240 | 24 => 173
| 25 => 212 | 26 => 162 | 27 => 175 | 28 => 156 | 29 => 164
| 30 => 114 | 31 => 192 | 32 => 183 | 33 => 253 | 34 => 147
| 35 => 38 | 36 => 54 | 37 => 63 | 38 => 247 | 39 => 204
| 40 => 52 | 41 => 165 | 42 => 229 | 43 => 241 | 44 => 113
| 45 => 216 | 46 => 49 | 47 => 21 | 48 => 4 | 49 => 199
| 50 => 35 | 51 => 195 | 52 => 24 | 53 => 150 | 54 => 5
| 55 => 154 | 56 => 7 | 57 => 18 | 58 => 128 | 59 => 226
| 60 => 235 | 61 => 39 | 62 => 178 | 63 => 117 | 64 => 9
| 65 => 131 | 66 => 44 | 67 => 26 | 68 => 27 | 69 => 110
| 70 => 90 | 71 => 160 | 72 => 82 | 73 => 59 | 74 => 214
| 75 => 179 | 76 => 41 | 77 => 227 | 78 => 47 | 79 => 132
| 80 => 83 | 81 => 209 | 82 => 0 | 83 => 237 | 84 => 32
| 85 => 252 | 86 => 177 | 87 => 91 | 88 => 106 | 89 => 203
| 90 => 190 | 91 => 57 | 92 => 74 | 93 => 76 | 94 => 88
| 95 => 207 | 96 => 208 | 97 => 239 | 98 => 170 | 99 => 251
| 100 => 67 | 101 => 77 | 102 => 51 | 103 => 133 | 104 => 69
| 105 => 249 | 106 => 2 | 107 => 127 | 108 => 80 | 109 => 60
| 110 => 159 | 111 => 168 | 112 => 81 | 113 => 163 | 114 => 64
| 115 => 143 | 116 => 146 | 117 => 157 | 118 => 56 | 119 => 245
| 120 => 188 | 121 => 182 | 122 => 218 | 123 => 33 | 124 => 16
| 125 => 255 | 126 => 243 | 127 => 210 | 128 => 205 | 129 => 12
| 130 => 19 | 131 => 236 | 132 => 95 | 133 => 151 | 134 => 68
| 135 => 23 | 136 => 196 | 137 => 167 | 138 => 126 | 139 => 61
| 140 => 100 | 141 => 93 | 142 => 25 | 143 => 115 | 144 => 96
| 145 => 129 | 146 => 79 | 147 => 220 | 148 => 34 | 149 => 42
| 150 => 144 | 151 => 136 | 152 => 70 | 153 => 238 | 154 => 184
| 155 => 20 | 156 => 222 | 157 => 94 | 158 => 11 | 159 => 219
| 160 => 224 | 161 => 50 | 162 => 58 | 163 => 10 | 164 => 73
| 165 => 6 | 166 => 36 | 167 => 92 | 168 => 194 | 169 => 211
| 170 => 172 | 171 => 98 | 172 => 145 | 173 => 149 | 174 => 228
| 175 => 121 | 176 => 231 | 177 => 200 | 178 => 55 | 179 => 109
| 180 => 141 | 181 => 213 | 182 => 78 | 183 => 169 | 184 => 108
| 185 => 86 | 186 => 244 | 187 => 234 | 188 => 101 | 189 => 122
| 190 => 174 | 191 => 8 | 192 => 186 | 193 => 120 | 194 => 37
| 195 => 46 | 196 => 28 | 197 => 166 | 198 => 180 | 199 => 198
| 200 => 232 | 201 => 221 | 202 => 116 | 203 => 31 | 204 => 75
| 205 => 189 | 206 => 139 | 207 => 138 | 208 => 112 | 209 => 62
| 210 => 181 | 211 => 102 | 212 => 72 | 213 => 3 | 214 => 246
| 215 => 14 | 216 => 97 | 217 => 53 | 218 => 87 | 219 => 185
| 220 => 134 | 221 => 193 | 222 => 29 | 223 => 158 | 224 => 225
| 225 => 248 | 226 => 152 | 227 => 17 | 228 => 105 | 229 => 217
| 230 => 142 | 231 => 148 | 232 => 155 | 233 => 30 | 234 => 135
| 235 => 233 | 236 => 206 | 237 => 85 | 238 => 40 | 239 => 223
| 240 => 140 | 241 => 161 | 242 => 137 | 243 => 13 | 244 => 191
| 245 => 230 | 246 => 66 | 247 => 104 | 248 => 65 | 249 => 153
| 250 => 45 | 251 => 15 | 252 => 176 | 253 => 84 | 254 => 187
| 255 => 22 | _ => 0
end.
Definition InvSbox (v1 : u8) :=
wrepr U8 match toword v1 with
| 0 => 82 | 1 => 9 | 2 => 106 | 3 => 213 | 4 => 48
| 5 => 54 | 6 => 165 | 7 => 56 | 8 => 191 | 9 => 64
| 10 => 163 | 11 => 158 | 12 => 129 | 13 => 243 | 14 => 215
| 15 => 251 | 16 => 124 | 17 => 227 | 18 => 57 | 19 => 130
| 20 => 155 | 21 => 47 | 22 => 255 | 23 => 135 | 24 => 52
| 25 => 142 | 26 => 67 | 27 => 68 | 28 => 196 | 29 => 222
| 30 => 233 | 31 => 203 | 32 => 84 | 33 => 123 | 34 => 148
| 35 => 50 | 36 => 166 | 37 => 194 | 38 => 35 | 39 => 61
| 40 => 238 | 41 => 76 | 42 => 149 | 43 => 11 | 44 => 66
| 45 => 250 | 46 => 195 | 47 => 78 | 48 => 8 | 49 => 46
| 50 => 161 | 51 => 102 | 52 => 40 | 53 => 217 | 54 => 36
| 55 => 178 | 56 => 118 | 57 => 91 | 58 => 162 | 59 => 73
| 60 => 109 | 61 => 139 | 62 => 209 | 63 => 37 | 64 => 114
| 65 => 248 | 66 => 246 | 67 => 100 | 68 => 134 | 69 => 104
| 70 => 152 | 71 => 22 | 72 => 212 | 73 => 164 | 74 => 92
| 75 => 204 | 76 => 93 | 77 => 101 | 78 => 182 | 79 => 146
| 80 => 108 | 81 => 112 | 82 => 72 | 83 => 80 | 84 => 253
| 85 => 237 | 86 => 185 | 87 => 218 | 88 => 94 | 89 => 21
| 90 => 70 | 91 => 87 | 92 => 167 | 93 => 141 | 94 => 157
| 95 => 132 | 96 => 144 | 97 => 216 | 98 => 171 | 99 => 0
| 100 => 140 | 101 => 188 | 102 => 211 | 103 => 10 | 104 => 247
| 105 => 228 | 106 => 88 | 107 => 5 | 108 => 184 | 109 => 179
| 110 => 69 | 111 => 6 | 112 => 208 | 113 => 44 | 114 => 30
| 115 => 143 | 116 => 202 | 117 => 63 | 118 => 15 | 119 => 2
| 120 => 193 | 121 => 175 | 122 => 189 | 123 => 3 | 124 => 1
| 125 => 19 | 126 => 138 | 127 => 107 | 128 => 58 | 129 => 145
| 130 => 17 | 131 => 65 | 132 => 79 | 133 => 103 | 134 => 220
| 135 => 234 | 136 => 151 | 137 => 242 | 138 => 207 | 139 => 206
| 140 => 240 | 141 => 180 | 142 => 230 | 143 => 115 | 144 => 150
| 145 => 172 | 146 => 116 | 147 => 34 | 148 => 231 | 149 => 173
| 150 => 53 | 151 => 133 | 152 => 226 | 153 => 249 | 154 => 55
| 155 => 232 | 156 => 28 | 157 => 117 | 158 => 223 | 159 => 110
| 160 => 71 | 161 => 241 | 162 => 26 | 163 => 113 | 164 => 29
| 165 => 41 | 166 => 197 | 167 => 137 | 168 => 111 | 169 => 183
| 170 => 98 | 171 => 14 | 172 => 170 | 173 => 24 | 174 => 190
| 175 => 27 | 176 => 252 | 177 => 86 | 178 => 62 | 179 => 75
| 180 => 198 | 181 => 210 | 182 => 121 | 183 => 32 | 184 => 154
| 185 => 219 | 186 => 192 | 187 => 254 | 188 => 120 | 189 => 205
| 190 => 90 | 191 => 244 | 192 => 31 | 193 => 221 | 194 => 168
| 195 => 51 | 196 => 136 | 197 => 7 | 198 => 199 | 199 => 49
| 200 => 177 | 201 => 18 | 202 => 16 | 203 => 89 | 204 => 39
| 205 => 128 | 206 => 236 | 207 => 95 | 208 => 96 | 209 => 81
| 210 => 127 | 211 => 169 | 212 => 25 | 213 => 181 | 214 => 74
| 215 => 13 | 216 => 45 | 217 => 229 | 218 => 122 | 219 => 159
| 220 => 147 | 221 => 201 | 222 => 156 | 223 => 239 | 224 => 160
| 225 => 224 | 226 => 59 | 227 => 77 | 228 => 174 | 229 => 42
| 230 => 245 | 231 => 176 | 232 => 200 | 233 => 235 | 234 => 187
| 235 => 60 | 236 => 131 | 237 => 83 | 238 => 153 | 239 => 97
| 240 => 23 | 241 => 43 | 242 => 4 | 243 => 126 | 244 => 186
| 245 => 119 | 246 => 214 | 247 => 38 | 248 => 225 | 249 => 105
| 250 => 20 | 251 => 99 | 252 => 85 | 253 => 33 | 254 => 12
| 255 => 125 | _ => 0
end.
(* NOTE: SubWord clashes with subword *)
Definition SubWord (v1 : u32) :=
make_vec U32 (map Sbox (split_vec U8 v1)).
Definition InvSubWord (v1 : u32) :=
make_vec U32 (map InvSbox (split_vec U8 v1)).
Definition RotWord (v1 : u32) :=
make_vec U32 [:: (subword (1 * U8) U8 v1); subword (2 * U8) U8 v1; subword (3 * U8) U8 v1; subword (0 * U8) U8 v1].
Definition to_matrix (s : u128) :=
let s_ := fun i j => (subword (i * U8) U8 (subword (j * U32) U32 s)) in
(s_ 0 0, s_ 0 1, s_ 0 2, s_ 0 3,
s_ 1 0, s_ 1 1, s_ 1 2, s_ 1 3,
s_ 2 0, s_ 2 1, s_ 2 2, s_ 2 2,
s_ 3 0, s_ 3 1, s_ 3 2, s_ 3 3)%nat.
Definition to_state (m : u8 * u8 * u8 * u8 * u8 * u8 * u8 * u8 * u8 * u8 * u8 * u8 * u8 * u8 * u8 * u8) :=
let '(s00, s01, s02, s03,
s10, s11, s12, s13,
s20, s21, s22, s23,
s30, s31, s32, s33) := m in
let c0 := make_vec U32 [:: s00; s10; s20; s30] in
let c1 := make_vec U32 [:: s01; s11; s21; s31] in
let c2 := make_vec U32 [:: s02; s12; s22; s32] in
let c3 := make_vec U32 [:: s03; s13; s23; s33] in
make_vec U128 [:: c0; c1; c2; c3].
Definition SubBytes (s : u128) :=
make_vec U128 (map SubWord (split_vec U32 s)).
Definition InvSubBytes (s : u128) :=
make_vec U128 (map InvSubWord (split_vec U32 s)).
Definition ShiftRows (s : u128) :=
let '(s00, s01, s02, s03,
s10, s11, s12, s13,
s20, s21, s22, s23,
s30, s31, s32, s33) := to_matrix s in
to_state (s00, s01, s02, s03,
s11, s12, s13, s10,
s22, s23, s20, s21,
s33, s30, s31, s32).
Definition InvShiftRows (s : u128) :=
let '(s00, s01, s02, s03,
s11, s12, s13, s10,
s22, s23, s20, s21,
s33, s30, s31, s32) := to_matrix s in
to_state
(s00, s01, s02, s03,
s10, s11, s12, s13,
s20, s21, s22, s23,
s30, s31, s32, s33).
(* TODO: Implement these *)
Parameter MixColumns : u128 -> u128.
Parameter InvMixColumns : u128 -> u128.
Definition wAESDEC (state rkey : u128) :=
let state := InvShiftRows state in
let state := InvSubBytes state in
let state := InvMixColumns state in
wxor state rkey.
Definition wAESDECLAST (state rkey : u128) :=
let state := InvShiftRows state in
let state := InvSubBytes state in
wxor state rkey.
Definition wAESENC (state rkey : u128) :=
let state := ShiftRows state in
let state := SubBytes state in
let state := MixColumns state in
wxor state rkey.
Definition wAESENCLAST (state rkey : u128) :=
let state := ShiftRows state in
let state := SubBytes state in
wxor state rkey.
Notation wAESIMC := InvMixColumns.
Definition wAESKEYGENASSIST (v1 : u128) (v2 : u8) :=
let rcon := zero_extend U32 v2 in
let x1 := subword (1 * U32) U32 v1 in
let x3 := subword (3 * U32) U32 v1 in
let y0 := SubWord x1 in
let y1 := wxor (RotWord (SubWord x1)) rcon in
let y2 := SubWord x3 in
let y3 := wxor (RotWord (SubWord x3)) rcon in
make_vec U128 [:: y0; y1; y2; y3].
Definition wAESENC_ (state rkey: u128) :=
let state := SubBytes state in
let state := ShiftRows state in
let state := MixColumns state in
wxor state rkey.
Definition wAESENCLAST_ (state rkey: u128) :=
let state := SubBytes state in
let state := ShiftRows state in
wxor state rkey.
Definition wAESDEC_ (state rkey: u128) :=
let state := InvShiftRows state in
let state := InvSubBytes state in
let state := wxor state rkey in
InvMixColumns state.
|
function geometry_test013 ( )
%*****************************************************************************80
%
%% TEST013 tests CIRCLE_LUNE_CENTROID_2D, CIRCLE_SECTOR_CENTROID_2D.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 14 February 2003
%
% Author:
%
% John Burkardt
%
n_test = 12;
r = 2.0;
center(1:2,1) = [ 5.0; 3.0 ];
theta1 = 0.0;
fprintf ( 1, '\n' );
fprintf ( 1, 'TEST013\n' );
fprintf ( 1, ' CIRCLE_LUNE_CENTROID_2D computes the centroid of a\n' );
fprintf ( 1, ' circular lune, defined by joining the endpoints\n' );
fprintf ( 1, ' of a circular arc.\n' );
fprintf ( 1, ' CIRCLE_SECTOR_CENTROID_2D computes the centroid of a\n' );
fprintf ( 1, ' circular sector, defined by joining the endpoints\n' );
fprintf ( 1, ' of a circular arc to the center.\n' );
circle_imp_print_2d ( r, center, ' The implicit circle:' );
fprintf ( 1, '\n' );
fprintf ( 1, ' The first angle of our lune and sector is always 0.\n' );
fprintf ( 1, '\n' );
fprintf ( 1, ' Lune Sector\n' );
fprintf ( 1, ' THETA2 X Y X Y\n' );
fprintf ( 1, '\n' );
for i = 0 : n_test
theta2 = i * 2.0 * pi / n_test;
centroid1(1:2,1) = circle_lune_centroid_2d ( r, center, theta1, theta2 );
centroid2(1:2,1) = circle_sector_centroid_2d ( r, center, theta1, theta2 );
fprintf ( 1, ' %12f %12f %12f %12f %12f\n', ...
theta2, centroid1(1:2,1), centroid2(1:2,1) );
end
return
end
|
lemma complex_cnj_fact [simp]: "cnj (fact n) = fact n" |
#i64o-bitpatterns.jl
#bitpattern detection of unum integer numbers. Certain patterns of numbers are
#well suited for detection for certain fraction tasks. In particular, all-zeros
#is necessary for deciding if number is an exact power of two or zero. And
#is_top helps detect the subnormal one.
doc"""
`is_all_zero` outputs whether or not all of the bits in an UInt64 or an `ArrayNum`
are zero. Used for checking zero at the Unum level.
"""
is_all_zero(n::UInt64) = (n == 0)
function is_all_zero{FSS}(n::ArrayNum{FSS})
for idx = 1:__cell_length(FSS)
@inbounds (n.a[idx] != 0) && return false #accumulate bits.
end
return true
end
doc"""
`is_not_zero` outputs whether or not any of the bits in an UInt64 or an `ArrayNum`
are one. Used for checking not_zero at the Unum level.
"""
is_not_zero(n::UInt64) = (n != 0)
function is_not_zero{FSS}(n::ArrayNum{FSS})
for idx = 1:__cell_length(FSS)
@inbounds (n.a[idx] != 0) && return true
end
return false
end
doc"""
`is_all_ones(n)` outputs whether or not all of the bits in an UInt64 or an `ArrayNum`
are one.
`is_all_ones(n, fsize)` does the same, but constrained to a certain fsize.
"""
function is_all_ones{FSS}(n::ArrayNum{FSS})
for idx = 1:__cell_length(FSS)
@inbounds (n.a[idx] != f64) && return false
end
return true
end
function is_all_ones(n::UInt64, fsize::UInt16)
n == mask_top(fsize)
end
function is_all_ones{FSS}(n::ArrayNum{FSS}, fsize::UInt16)
cell_index = (fsize ÷ 0x0040) + o16
bit_index = fsize % 0x0040
for idx = 1:cell_index - 1
@inbounds (n.a[idx] != f64) && return false
end
@inbounds return is_all_ones(n.a[cell_index], bit_index)
end
doc"""
`is_not_ones` outputs whether or not any of the bits in an UInt64 or an `ArrayNum`
is zero
"""
function is_not_ones{FSS}(n::ArrayNum{FSS})
for idx = 1:__cell_length(FSS)
@inbounds (n.a[idx] != f64) && return true
end
return false
end
doc"""
`is_top` outputs whether or not the most significant bit of an UInt64 or an
`ArrayNum` is a one, while the rest are zero. Used for checking the subnormal
one at the Unum level.
"""
is_top(a::UInt64) = (a == t64)
function is_top{FSS}(n::ArrayNum{FSS})
(n.a[1] != t64) && return false
for idx = 2:__cell_length(FSS)
@inbounds (n.a[idx] != 0) && return false
end
return true
end
doc"""
`top_bit` outputs whether or not the top bit is one.
"""
top_bit(a::UInt64) = (a & t64) != z64
top_bit{FSS}(a::ArrayNum{FSS}) = @inbounds top_bit(a.a[1])
@universal frac_top_bit(a::Unum) = top_bit(a.fraction)
doc"""
`is_not_top` outputs if the most significant bit of an UInt64 or an
`ArrayNum` isn't one, or if any of the other bits are one. Used for checking
the subnormal one at the Unum level.
"""
is_not_top(a::UInt64) = (a != t64)
function is_not_top{FSS}(n::ArrayNum{FSS})
(n.a[1] != t64) && return true
for idx = 2:__cell_length(FSS)
@inbounds (n.a[idx] != 0) && return true
end
return false
end
doc"""
`is_mmr_frac(::ArrayNum)` checks if the fraction looks like mmr.
`is_mmr_frac(::UInt64, ::Type{Val{FSS}})` also checks if the fraction looks like mmr.
"""
function is_mmr_frac{FSS}(n::UInt64, ::Type{Val{FSS}})
if FSS == 0
n == z64
else
n == mask_top(max_fsize(FSS) - 0x0001)
end
end
function is_mmr_frac{FSS}(n::ArrayNum{FSS})
l = __cell_length(FSS)
for idx = 1:(l - 1)
@inbounds (n.a[idx] != f64) && return false
end
@inbounds return (n.a[l] == 0xFFFF_FFFF_FFFF_FFFE)
end
bool_bottom_bit{FSS}(fraction::UInt64, ::Type{Val{FSS}}) = (bottom_bit(FSS) & fraction) != 0
bool_bottom_bit{FSS}(n::ArrayNum{FSS}) = (n.a[__cell_length(FSS)] & o64) != 0
bool_bottom_bit{ESS,FSS}(x::UnumSmall{ESS,FSS}) = bool_bottom_bit(x.fraction, Val{FSS})
bool_bottom_bit{ESS,FSS}(x::UnumLarge{ESS,FSS}) = bool_bottom_bit(x.fraction)
doc"""
`Unums.bool_indexed_bit(fraction, index)`
"""
bool_indexed_bit(fraction::UInt64, index::UInt16) = ((t64 >> index) & fraction) != 0
function bool_indexed_bit{FSS}(fraction::ArrayNum{FSS}, index::UInt16)
cell_index = (index ÷ 0x0040) + o16
index = index % 0x0040
bool_indexed_bit(fraction.a[cell_index], index)
end
|
import Mathlib.Data.Real.Basic
def log (x : ℝ) := x - 1
-- #check
theorem log_mul_eq_add : log (a * b) = log a + log b := sorry
theorem log_add_eq_mul : log a + log b = log (a * b) := Iff.mp eq_comm log_mul_eq_add
-- theorem log_pm (a n : ℝ) : log (a ^ n) = n * log a := sorry
theorem log_le_zero_iff : log a ≤ 0 ↔ a ≤ 1 := sorry
lemma log_linear (x : ℝ) : log x ≤ x - 1 := by rfl
theorem log_ineq_iff (a b : ℝ) (hb : b > 0) : log (a / b) ≤ 0 ↔ b ≥ a :=
calc
_ ↔ a / b ≤ 1 := log_le_zero_iff
_ ↔ _ := div_le_one hb
-- theorem log_
lemma sqrt_self (a : ℝ) : a = a^(1/2) * a^(1/2) := sorry
lemma sqrt_decompose (a b : ℝ) : (a*b)^(1/2) = a^(1/2) * b^(1/2) := sorry
lemma log_sqrt (a : ℝ) : log (a^(1/2)) = (1/2) * log a := sorry
lemma add_map (a b : ℝ) (f : ℝ -> ℝ) : a + b = f a + f b := sorry
lemma log_add_sqrt (a b : ℝ): log (a^(1/2)) + log (b^(1/2)) = (1/2) * log a + (1/2) * log b
:= sorry
theorem log_bi_arith_geom_ineq (a b : ℝ) (ha : a > 0) (hb : b > 0) :
log ( (a*b)^(1/2) / ((a+b)/2) ) ≤ 0 :=
have hale : _ := log_linear (2 * a/(a+b))
have hble : _ := log_linear (2 * b/(a+b))
have hline : log (2 * a/(a+b)) + log (2 * b/(a+b)) ≤ (2 * a/(a+b) - 1) + (2 * b/(a+b) - 1)
:= add_le_add hale hble
have hsum : a + b ≠ 0 := sorry
have hp : _ := sorry
have hp' : _ := sorry
calc
_ = _ := sorry
_ = log ((2 * a/(a+b))^(1/2)) + log ((2*b/(a+b))^(1/2)) := log_mul_eq_add
_ = (1/2) * log (2 * a/(a+b)) + (1/2) * log (2*b/(a+b)) := log_add_sqrt _ _
_ = (1/2) * ( log (2 * a/(a+b)) + log (2 * b/(a+b)) ) := by ring
_ ≤ (1/2) * (2 * a/(a+b) - 1 + (2 * b/(a+b) - 1)) := mul_le_mul le_rfl hline hp hp'
_ = (a + b) / (a + b) - 1 := by ring
_ = 1 - 1 := by rw [div_self hsum]
_ = 0 := by simp
theorem bi_arith_geom_ineq (a b : ℝ)
(ha : a > 0) (hb : b > 0) : (a + b) / 2 ≥ (a*b)^(1/2) :=
have hsum : a + b > 0 := add_pos ha hb
have h2 : 2 > 0 := by simp
have hbot : (a + b) / 2 > 0 := Iff.mp gt_iff_lt (div_pos hsum h2)
have hlog : _ := log_bi_arith_geom_ineq a b ha hb
show _ from Iff.mp (log_ineq_iff _ _ hbot) hlog
-- calc
-- have heq1 : _ := sqrt_decompose a b
-- have heq2 : (a * b)^(1/2) / ((a+b)/2) = a^(1/2)*b^(1/2) / ((a+b)/2) := sorry
-- have heq3 : a^(1/2) * b^(1/2) / ((a+b)/2) = ((2 * a/(a+b))^(1/2)) * ((2*b/(a+b))^(1/2)) := sorry
-- have hle1 _ := log_linear (2*a/(a+b))
-- -- have hle2 : (1/2) * log (2*a/(a+b)) ≤ (1/2) * (2 * a / (a + b) - 1) := mul_le_mul (le_refl _) hle1
-- calc
-- _ = log _ := congrArg log heq3
-- _ = log ((2 * a/(a+b))^(1/2)) + log ((2*a/(a+b))^(1/2)) := log_mul_eq_add
-- _ = (1/2) * log (2 * a/(a+b)) + (1/2) * log (2*b/(a+b)) := sorry
-- _ ≤ 0 := sorry
|
# K Means Clustering
library(cluster)
data(iris)
iris$Species <- as.numeric(iris$Species)
kmeans <- kmeans(x = iris, centers = 5)
clusplot(
iris,
kmeans$cluster,
color = TRUE,
shade = TRUE,
labels = 13,
lines = 0
)
# Elbow Method
library(cluster)
library(ggplot2)
data(iris)
iris$Species <- as.numeric(iris$Species)
cost_df <- data.frame()
for (i in 1:100) {
kmeans <- kmeans(x = iris, centers = i, iter.max = 50)
cost_df <- rbind(cost_df, cbind(i, kmeans$tot.withinss))
}
names(cost_df) <- c("cluster", "cost")
cost_df
ggplot(data = cost_df, aes(x = cluster, y = cost, group = 1)) +
theme_bw(base_family = "D2Coding") +
geom_line(colour = "darkgreen") +
theme(text = element_text(size = 10)) +
ggtitle("Reduction in cost for values of 'k'\n") +
xlab("Clusters") +
ylab("Within-Cluster Sum of Sqarea\n")
|
function model = ResNet50_for_DetectTrack_ILSVRCvid(model)
% ResNet 50 layers D&T with OHEM training (finetuned from res3a)
model.solver_def_file = fullfile(pwd, 'models', 'rfcn_prototxts', 'ResNet-50L_ILSVRCvid_corr', 'solver_160k240k_lr1_4.prototxt');
model.test_net_def_file = fullfile(pwd, 'models', 'rfcn_prototxts', 'ResNet-50L_ILSVRCvid_corr', 'test_track.prototxt');
model.net_file = fullfile(pwd, 'models', 'pre_trained_models', 'ResNet-50L', 'ResNet-50-D-ilsvrc-vid.caffemodel');
model.mean_image = fullfile(pwd, 'models', 'pre_trained_models', 'ResNet-50L', 'mean_image');
end |
Gwendolen and her formidable mother Lady Bracknell now call on Algernon who distracts Lady Bracknell in another room while Jack proposes to Gwendolen . She accepts , but seems to love him very largely for his professed name of Ernest . Jack accordingly resolves to himself to be rechristened " Ernest " . Discovering them in this intimate exchange , Lady Bracknell interviews Jack as a prospective suitor . Horrified to learn that he was adopted after being discovered as a baby in a handbag at Victoria Station , she refuses him and forbids further contact with her daughter . Gwendolen , though , manages covertly to promise to him her undying love . As Jack gives her his address in the country , Algernon surreptitiously notes it on the cuff of his sleeve : Jack 's revelation of his pretty and wealthy young ward has motivated his friend to meet her .
|
/*
* Copyright (c) 2007, Michael Lehn
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1) Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2) Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3) Neither the name of the FLENS development group nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef FLENS_FLENS_H
#define FLENS_FLENS_H 1
#define ADDRESS(x) reinterpret_cast<const void *>(&x)
#ifndef ASSERT
#define ASSERT(x) assert(x)
#endif //ASSERT
#include <array.h>
#include <bandstorage.h>
#include <blas.h>
#include <blas_flens.h>
#include <cg.h>
#include <complex_helper.h>
#include <crs.h>
#include <densevector.h>
#include <evalclosure.h>
#include <fullstorage.h>
#include <generalmatrix.h>
#include <generic_blas.h>
#include <refcounter.h>
#include <lapack.h>
#include <lapack_flens.h>
#include <listinitializer.h>
#include <matvec.h>
#include <matvecclosures.h>
#include <matvecio.h>
#include <matvecoperations.h>
#include <multigrid.h>
#include <packedstorage.h>
#include <range.h>
#include <snapshot.h>
#include <storage.h>
#include <sparsematrix.h>
#include <sparse_blas.h>
#include <sparse_blas_flens.h>
#include <symmetricmatrix.h>
#include <traits.h>
#include <triangularmatrix.h>
#include <underscore.h>
#include <uplo.h>
#endif // FLENS_FLENS_H
|
postulate
foo = Foo
-- Error message is:
-- A postulate block can only contain type signatures or instance blocks
|
[GOAL]
R : Type u_1
M : Type u_2
P : Type u_3
N : Type u_4
inst✝⁸ : Ring R
inst✝⁷ : AddCommGroup M
inst✝⁶ : AddCommGroup P
inst✝⁵ : AddCommGroup N
inst✝⁴ : Module R M
inst✝³ : Module R P
inst✝² : Module R N
inst✝¹ : IsArtinian R M
inst✝ : IsArtinian R P
f : M →ₗ[R] N
g : N →ₗ[R] P
hf : Function.Injective ↑f
hg : Function.Surjective ↑g
h : LinearMap.range f = LinearMap.ker g
⊢ ∀ (a : Submodule R N), Submodule.map f (Submodule.comap f a) = a ⊓ LinearMap.range f
[PROOFSTEP]
simp [Submodule.map_comap_eq, inf_comm]
[GOAL]
R : Type u_1
M : Type u_2
P : Type u_3
N : Type u_4
inst✝⁸ : Ring R
inst✝⁷ : AddCommGroup M
inst✝⁶ : AddCommGroup P
inst✝⁵ : AddCommGroup N
inst✝⁴ : Module R M
inst✝³ : Module R P
inst✝² : Module R N
inst✝¹ : IsArtinian R M
inst✝ : IsArtinian R P
f : M →ₗ[R] N
g : N →ₗ[R] P
hf : Function.Injective ↑f
hg : Function.Surjective ↑g
h : LinearMap.range f = LinearMap.ker g
⊢ ∀ (a : Submodule R N), Submodule.comap g (Submodule.map g a) = a ⊔ LinearMap.range f
[PROOFSTEP]
simp [Submodule.comap_map_eq, h]
[GOAL]
R✝ : Type u_1
M : Type u_2
P : Type u_3
N : Type u_4
inst✝⁷ : Ring R✝
inst✝⁶ : AddCommGroup M
inst✝⁵ : AddCommGroup P
inst✝⁴ : AddCommGroup N
inst✝³ : Module R✝ M
inst✝² : Module R✝ P
inst✝¹ : Module R✝ N
R : Type u_5
ι : Type u_6
inst✝ : Finite ι
⊢ ∀ {M : ι → Type u_7} [inst : Ring R] [inst_1 : (i : ι) → AddCommGroup (M i)] [inst_2 : (i : ι) → Module R (M i)]
[inst_3 : ∀ (i : ι), IsArtinian R (M i)], IsArtinian R ((i : ι) → M i)
[PROOFSTEP]
apply Finite.induction_empty_option _ _ _ ι
[GOAL]
R✝ : Type u_1
M : Type u_2
P : Type u_3
N : Type u_4
inst✝⁷ : Ring R✝
inst✝⁶ : AddCommGroup M
inst✝⁵ : AddCommGroup P
inst✝⁴ : AddCommGroup N
inst✝³ : Module R✝ M
inst✝² : Module R✝ P
inst✝¹ : Module R✝ N
R : Type u_5
ι : Type u_6
inst✝ : Finite ι
⊢ ∀ {α β : Type u_6},
α ≃ β →
(∀ {M : α → Type u_7} [inst : Ring R] [inst_1 : (i : α) → AddCommGroup (M i)] [inst_2 : (i : α) → Module R (M i)]
[inst_3 : ∀ (i : α), IsArtinian R (M i)], IsArtinian R ((i : α) → M i)) →
∀ {M : β → Type u_7} [inst : Ring R] [inst_1 : (i : β) → AddCommGroup (M i)] [inst_2 : (i : β) → Module R (M i)]
[inst_3 : ∀ (i : β), IsArtinian R (M i)], IsArtinian R ((i : β) → M i)
[PROOFSTEP]
intro α β e hα M _ _ _ _
[GOAL]
R✝ : Type u_1
M✝ : Type u_2
P : Type u_3
N : Type u_4
inst✝¹¹ : Ring R✝
inst✝¹⁰ : AddCommGroup M✝
inst✝⁹ : AddCommGroup P
inst✝⁸ : AddCommGroup N
inst✝⁷ : Module R✝ M✝
inst✝⁶ : Module R✝ P
inst✝⁵ : Module R✝ N
R : Type u_5
ι : Type u_6
inst✝⁴ : Finite ι
α β : Type u_6
e : α ≃ β
hα :
∀ {M : α → Type u_7} [inst : Ring R] [inst_1 : (i : α) → AddCommGroup (M i)] [inst_2 : (i : α) → Module R (M i)]
[inst_3 : ∀ (i : α), IsArtinian R (M i)], IsArtinian R ((i : α) → M i)
M : β → Type u_7
inst✝³ : Ring R
inst✝² : (i : β) → AddCommGroup (M i)
inst✝¹ : (i : β) → Module R (M i)
inst✝ : ∀ (i : β), IsArtinian R (M i)
⊢ IsArtinian R ((i : β) → M i)
[PROOFSTEP]
have := @hα
[GOAL]
R✝ : Type u_1
M✝ : Type u_2
P : Type u_3
N : Type u_4
inst✝¹¹ : Ring R✝
inst✝¹⁰ : AddCommGroup M✝
inst✝⁹ : AddCommGroup P
inst✝⁸ : AddCommGroup N
inst✝⁷ : Module R✝ M✝
inst✝⁶ : Module R✝ P
inst✝⁵ : Module R✝ N
R : Type u_5
ι : Type u_6
inst✝⁴ : Finite ι
α β : Type u_6
e : α ≃ β
hα :
∀ {M : α → Type u_7} [inst : Ring R] [inst_1 : (i : α) → AddCommGroup (M i)] [inst_2 : (i : α) → Module R (M i)]
[inst_3 : ∀ (i : α), IsArtinian R (M i)], IsArtinian R ((i : α) → M i)
M : β → Type u_7
inst✝³ : Ring R
inst✝² : (i : β) → AddCommGroup (M i)
inst✝¹ : (i : β) → Module R (M i)
inst✝ : ∀ (i : β), IsArtinian R (M i)
this :
∀ {M : α → Type u_7} [inst : Ring R] [inst_1 : (i : α) → AddCommGroup (M i)] [inst_2 : (i : α) → Module R (M i)]
[inst_3 : ∀ (i : α), IsArtinian R (M i)], IsArtinian R ((i : α) → M i)
⊢ IsArtinian R ((i : β) → M i)
[PROOFSTEP]
exact isArtinian_of_linearEquiv (LinearEquiv.piCongrLeft R M e)
[GOAL]
R✝ : Type u_1
M : Type u_2
P : Type u_3
N : Type u_4
inst✝⁷ : Ring R✝
inst✝⁶ : AddCommGroup M
inst✝⁵ : AddCommGroup P
inst✝⁴ : AddCommGroup N
inst✝³ : Module R✝ M
inst✝² : Module R✝ P
inst✝¹ : Module R✝ N
R : Type u_5
ι : Type u_6
inst✝ : Finite ι
⊢ ∀ {M : PEmpty → Type u_7} [inst : Ring R] [inst_1 : (i : PEmpty) → AddCommGroup (M i)]
[inst_2 : (i : PEmpty) → Module R (M i)] [inst_3 : ∀ (i : PEmpty), IsArtinian R (M i)],
IsArtinian R ((i : PEmpty) → M i)
[PROOFSTEP]
intro M _ _ _ _
[GOAL]
R✝ : Type u_1
M✝ : Type u_2
P : Type u_3
N : Type u_4
inst✝¹¹ : Ring R✝
inst✝¹⁰ : AddCommGroup M✝
inst✝⁹ : AddCommGroup P
inst✝⁸ : AddCommGroup N
inst✝⁷ : Module R✝ M✝
inst✝⁶ : Module R✝ P
inst✝⁵ : Module R✝ N
R : Type u_5
ι : Type u_6
inst✝⁴ : Finite ι
M : PEmpty → Type u_7
inst✝³ : Ring R
inst✝² : (i : PEmpty) → AddCommGroup (M i)
inst✝¹ : (i : PEmpty) → Module R (M i)
inst✝ : ∀ (i : PEmpty), IsArtinian R (M i)
⊢ IsArtinian R ((i : PEmpty) → M i)
[PROOFSTEP]
infer_instance
[GOAL]
R✝ : Type u_1
M : Type u_2
P : Type u_3
N : Type u_4
inst✝⁷ : Ring R✝
inst✝⁶ : AddCommGroup M
inst✝⁵ : AddCommGroup P
inst✝⁴ : AddCommGroup N
inst✝³ : Module R✝ M
inst✝² : Module R✝ P
inst✝¹ : Module R✝ N
R : Type u_5
ι : Type u_6
inst✝ : Finite ι
⊢ ∀ {α : Type u_6} [inst : Fintype α],
(∀ {M : α → Type u_7} [inst : Ring R] [inst_1 : (i : α) → AddCommGroup (M i)] [inst_2 : (i : α) → Module R (M i)]
[inst_3 : ∀ (i : α), IsArtinian R (M i)], IsArtinian R ((i : α) → M i)) →
∀ {M : Option α → Type u_7} [inst : Ring R] [inst_1 : (i : Option α) → AddCommGroup (M i)]
[inst_2 : (i : Option α) → Module R (M i)] [inst_3 : ∀ (i : Option α), IsArtinian R (M i)],
IsArtinian R ((i : Option α) → M i)
[PROOFSTEP]
intro α _ ih M _ _ _ _
[GOAL]
R✝ : Type u_1
M✝ : Type u_2
P : Type u_3
N : Type u_4
inst✝¹² : Ring R✝
inst✝¹¹ : AddCommGroup M✝
inst✝¹⁰ : AddCommGroup P
inst✝⁹ : AddCommGroup N
inst✝⁸ : Module R✝ M✝
inst✝⁷ : Module R✝ P
inst✝⁶ : Module R✝ N
R : Type u_5
ι : Type u_6
inst✝⁵ : Finite ι
α : Type u_6
inst✝⁴ : Fintype α
ih :
∀ {M : α → Type u_7} [inst : Ring R] [inst_1 : (i : α) → AddCommGroup (M i)] [inst_2 : (i : α) → Module R (M i)]
[inst_3 : ∀ (i : α), IsArtinian R (M i)], IsArtinian R ((i : α) → M i)
M : Option α → Type u_7
inst✝³ : Ring R
inst✝² : (i : Option α) → AddCommGroup (M i)
inst✝¹ : (i : Option α) → Module R (M i)
inst✝ : ∀ (i : Option α), IsArtinian R (M i)
⊢ IsArtinian R ((i : Option α) → M i)
[PROOFSTEP]
have := @ih
[GOAL]
R✝ : Type u_1
M✝ : Type u_2
P : Type u_3
N : Type u_4
inst✝¹² : Ring R✝
inst✝¹¹ : AddCommGroup M✝
inst✝¹⁰ : AddCommGroup P
inst✝⁹ : AddCommGroup N
inst✝⁸ : Module R✝ M✝
inst✝⁷ : Module R✝ P
inst✝⁶ : Module R✝ N
R : Type u_5
ι : Type u_6
inst✝⁵ : Finite ι
α : Type u_6
inst✝⁴ : Fintype α
ih :
∀ {M : α → Type u_7} [inst : Ring R] [inst_1 : (i : α) → AddCommGroup (M i)] [inst_2 : (i : α) → Module R (M i)]
[inst_3 : ∀ (i : α), IsArtinian R (M i)], IsArtinian R ((i : α) → M i)
M : Option α → Type u_7
inst✝³ : Ring R
inst✝² : (i : Option α) → AddCommGroup (M i)
inst✝¹ : (i : Option α) → Module R (M i)
inst✝ : ∀ (i : Option α), IsArtinian R (M i)
this :
∀ {M : α → Type u_7} [inst : Ring R] [inst_1 : (i : α) → AddCommGroup (M i)] [inst_2 : (i : α) → Module R (M i)]
[inst_3 : ∀ (i : α), IsArtinian R (M i)], IsArtinian R ((i : α) → M i)
⊢ IsArtinian R ((i : Option α) → M i)
[PROOFSTEP]
exact isArtinian_of_linearEquiv (LinearEquiv.piOptionEquivProd R).symm
[GOAL]
R : Type u_1
M : Type u_2
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : Nontrivial R
inst✝ : IsArtinian R M
s : Set M
hs : LinearIndependent R Subtype.val
⊢ Set.Finite s
[PROOFSTEP]
refine'
by_contradiction fun hf =>
(RelEmbedding.wellFounded_iff_no_descending_seq.1 (wellFounded_submodule_lt (R := R) (M := M))).elim' _
[GOAL]
R : Type u_1
M : Type u_2
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : Nontrivial R
inst✝ : IsArtinian R M
s : Set M
hs : LinearIndependent R Subtype.val
hf : ¬Set.Finite s
⊢ (fun x x_1 => x > x_1) ↪r fun x x_1 => x < x_1
[PROOFSTEP]
have f : ℕ ↪ s := Set.Infinite.natEmbedding s hf
[GOAL]
R : Type u_1
M : Type u_2
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : Nontrivial R
inst✝ : IsArtinian R M
s : Set M
hs : LinearIndependent R Subtype.val
hf : ¬Set.Finite s
f : ℕ ↪ ↑s
⊢ (fun x x_1 => x > x_1) ↪r fun x x_1 => x < x_1
[PROOFSTEP]
have : ∀ n, (↑) ∘ f '' {m | n ≤ m} ⊆ s := by
rintro n x ⟨y, _, rfl⟩
exact (f y).2
[GOAL]
R : Type u_1
M : Type u_2
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : Nontrivial R
inst✝ : IsArtinian R M
s : Set M
hs : LinearIndependent R Subtype.val
hf : ¬Set.Finite s
f : ℕ ↪ ↑s
⊢ ∀ (n : ℕ), Subtype.val ∘ ↑f '' {m | n ≤ m} ⊆ s
[PROOFSTEP]
rintro n x ⟨y, _, rfl⟩
[GOAL]
case intro.intro
R : Type u_1
M : Type u_2
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : Nontrivial R
inst✝ : IsArtinian R M
s : Set M
hs : LinearIndependent R Subtype.val
hf : ¬Set.Finite s
f : ℕ ↪ ↑s
n y : ℕ
left✝ : y ∈ {m | n ≤ m}
⊢ (Subtype.val ∘ ↑f) y ∈ s
[PROOFSTEP]
exact (f y).2
[GOAL]
R : Type u_1
M : Type u_2
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : Nontrivial R
inst✝ : IsArtinian R M
s : Set M
hs : LinearIndependent R Subtype.val
hf : ¬Set.Finite s
f : ℕ ↪ ↑s
this : ∀ (n : ℕ), Subtype.val ∘ ↑f '' {m | n ≤ m} ⊆ s
⊢ (fun x x_1 => x > x_1) ↪r fun x x_1 => x < x_1
[PROOFSTEP]
have : ∀ a b : ℕ, a ≤ b ↔ span R (Subtype.val ∘ f '' {m | b ≤ m}) ≤ span R (Subtype.val ∘ f '' {m | a ≤ m}) :=
by
intro a b
rw [span_le_span_iff hs (this b) (this a), Set.image_subset_image_iff (Subtype.coe_injective.comp f.injective),
Set.subset_def]
simp only [Set.mem_setOf_eq]
exact ⟨fun hab x => le_trans hab, fun h => h _ le_rfl⟩
[GOAL]
R : Type u_1
M : Type u_2
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : Nontrivial R
inst✝ : IsArtinian R M
s : Set M
hs : LinearIndependent R Subtype.val
hf : ¬Set.Finite s
f : ℕ ↪ ↑s
this : ∀ (n : ℕ), Subtype.val ∘ ↑f '' {m | n ≤ m} ⊆ s
⊢ ∀ (a b : ℕ), a ≤ b ↔ span R (Subtype.val ∘ ↑f '' {m | b ≤ m}) ≤ span R (Subtype.val ∘ ↑f '' {m | a ≤ m})
[PROOFSTEP]
intro a b
[GOAL]
R : Type u_1
M : Type u_2
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : Nontrivial R
inst✝ : IsArtinian R M
s : Set M
hs : LinearIndependent R Subtype.val
hf : ¬Set.Finite s
f : ℕ ↪ ↑s
this : ∀ (n : ℕ), Subtype.val ∘ ↑f '' {m | n ≤ m} ⊆ s
a b : ℕ
⊢ a ≤ b ↔ span R (Subtype.val ∘ ↑f '' {m | b ≤ m}) ≤ span R (Subtype.val ∘ ↑f '' {m | a ≤ m})
[PROOFSTEP]
rw [span_le_span_iff hs (this b) (this a), Set.image_subset_image_iff (Subtype.coe_injective.comp f.injective),
Set.subset_def]
[GOAL]
R : Type u_1
M : Type u_2
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : Nontrivial R
inst✝ : IsArtinian R M
s : Set M
hs : LinearIndependent R Subtype.val
hf : ¬Set.Finite s
f : ℕ ↪ ↑s
this : ∀ (n : ℕ), Subtype.val ∘ ↑f '' {m | n ≤ m} ⊆ s
a b : ℕ
⊢ a ≤ b ↔ ∀ (x : ℕ), x ∈ {m | b ≤ m} → x ∈ {m | a ≤ m}
[PROOFSTEP]
simp only [Set.mem_setOf_eq]
[GOAL]
R : Type u_1
M : Type u_2
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : Nontrivial R
inst✝ : IsArtinian R M
s : Set M
hs : LinearIndependent R Subtype.val
hf : ¬Set.Finite s
f : ℕ ↪ ↑s
this : ∀ (n : ℕ), Subtype.val ∘ ↑f '' {m | n ≤ m} ⊆ s
a b : ℕ
⊢ a ≤ b ↔ ∀ (x : ℕ), b ≤ x → a ≤ x
[PROOFSTEP]
exact ⟨fun hab x => le_trans hab, fun h => h _ le_rfl⟩
[GOAL]
R : Type u_1
M : Type u_2
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : Nontrivial R
inst✝ : IsArtinian R M
s : Set M
hs : LinearIndependent R Subtype.val
hf : ¬Set.Finite s
f : ℕ ↪ ↑s
this✝ : ∀ (n : ℕ), Subtype.val ∘ ↑f '' {m | n ≤ m} ⊆ s
this : ∀ (a b : ℕ), a ≤ b ↔ span R (Subtype.val ∘ ↑f '' {m | b ≤ m}) ≤ span R (Subtype.val ∘ ↑f '' {m | a ≤ m})
⊢ (fun x x_1 => x > x_1) ↪r fun x x_1 => x < x_1
[PROOFSTEP]
exact
⟨⟨fun n => span R (Subtype.val ∘ f '' {m | n ≤ m}), fun x y =>
by
rw [le_antisymm_iff, ← this y x, ← this x y]
exact fun ⟨h₁, h₂⟩ => le_antisymm_iff.2 ⟨h₂, h₁⟩⟩,
by
intro a b
conv_rhs => rw [GT.gt, lt_iff_le_not_le, this, this, ← lt_iff_le_not_le]⟩
[GOAL]
R : Type u_1
M : Type u_2
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : Nontrivial R
inst✝ : IsArtinian R M
s : Set M
hs : LinearIndependent R Subtype.val
hf : ¬Set.Finite s
f : ℕ ↪ ↑s
this✝ : ∀ (n : ℕ), Subtype.val ∘ ↑f '' {m | n ≤ m} ⊆ s
this : ∀ (a b : ℕ), a ≤ b ↔ span R (Subtype.val ∘ ↑f '' {m | b ≤ m}) ≤ span R (Subtype.val ∘ ↑f '' {m | a ≤ m})
x y : ℕ
⊢ (fun n => span R (Subtype.val ∘ ↑f '' {m | n ≤ m})) x = (fun n => span R (Subtype.val ∘ ↑f '' {m | n ≤ m})) y → x = y
[PROOFSTEP]
rw [le_antisymm_iff, ← this y x, ← this x y]
[GOAL]
R : Type u_1
M : Type u_2
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : Nontrivial R
inst✝ : IsArtinian R M
s : Set M
hs : LinearIndependent R Subtype.val
hf : ¬Set.Finite s
f : ℕ ↪ ↑s
this✝ : ∀ (n : ℕ), Subtype.val ∘ ↑f '' {m | n ≤ m} ⊆ s
this : ∀ (a b : ℕ), a ≤ b ↔ span R (Subtype.val ∘ ↑f '' {m | b ≤ m}) ≤ span R (Subtype.val ∘ ↑f '' {m | a ≤ m})
x y : ℕ
⊢ y ≤ x ∧ x ≤ y → x = y
[PROOFSTEP]
exact fun ⟨h₁, h₂⟩ => le_antisymm_iff.2 ⟨h₂, h₁⟩
[GOAL]
R : Type u_1
M : Type u_2
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : Nontrivial R
inst✝ : IsArtinian R M
s : Set M
hs : LinearIndependent R Subtype.val
hf : ¬Set.Finite s
f : ℕ ↪ ↑s
this✝ : ∀ (n : ℕ), Subtype.val ∘ ↑f '' {m | n ≤ m} ⊆ s
this : ∀ (a b : ℕ), a ≤ b ↔ span R (Subtype.val ∘ ↑f '' {m | b ≤ m}) ≤ span R (Subtype.val ∘ ↑f '' {m | a ≤ m})
⊢ ∀ {a b : ℕ},
↑{ toFun := fun n => span R (Subtype.val ∘ ↑f '' {m | n ≤ m}),
inj' :=
(_ :
∀ (x y : ℕ),
(fun n => span R (Subtype.val ∘ ↑f '' {m | n ≤ m})) x =
(fun n => span R (Subtype.val ∘ ↑f '' {m | n ≤ m})) y →
x = y) }
a <
↑{ toFun := fun n => span R (Subtype.val ∘ ↑f '' {m | n ≤ m}),
inj' :=
(_ :
∀ (x y : ℕ),
(fun n => span R (Subtype.val ∘ ↑f '' {m | n ≤ m})) x =
(fun n => span R (Subtype.val ∘ ↑f '' {m | n ≤ m})) y →
x = y) }
b ↔
a > b
[PROOFSTEP]
intro a b
[GOAL]
R : Type u_1
M : Type u_2
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : Nontrivial R
inst✝ : IsArtinian R M
s : Set M
hs : LinearIndependent R Subtype.val
hf : ¬Set.Finite s
f : ℕ ↪ ↑s
this✝ : ∀ (n : ℕ), Subtype.val ∘ ↑f '' {m | n ≤ m} ⊆ s
this : ∀ (a b : ℕ), a ≤ b ↔ span R (Subtype.val ∘ ↑f '' {m | b ≤ m}) ≤ span R (Subtype.val ∘ ↑f '' {m | a ≤ m})
a b : ℕ
⊢ ↑{ toFun := fun n => span R (Subtype.val ∘ ↑f '' {m | n ≤ m}),
inj' :=
(_ :
∀ (x y : ℕ),
(fun n => span R (Subtype.val ∘ ↑f '' {m | n ≤ m})) x =
(fun n => span R (Subtype.val ∘ ↑f '' {m | n ≤ m})) y →
x = y) }
a <
↑{ toFun := fun n => span R (Subtype.val ∘ ↑f '' {m | n ≤ m}),
inj' :=
(_ :
∀ (x y : ℕ),
(fun n => span R (Subtype.val ∘ ↑f '' {m | n ≤ m})) x =
(fun n => span R (Subtype.val ∘ ↑f '' {m | n ≤ m})) y →
x = y) }
b ↔
a > b
[PROOFSTEP]
conv_rhs => rw [GT.gt, lt_iff_le_not_le, this, this, ← lt_iff_le_not_le]
[GOAL]
R : Type u_1
M : Type u_2
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : Nontrivial R
inst✝ : IsArtinian R M
s : Set M
hs : LinearIndependent R Subtype.val
hf : ¬Set.Finite s
f : ℕ ↪ ↑s
this✝ : ∀ (n : ℕ), Subtype.val ∘ ↑f '' {m | n ≤ m} ⊆ s
this : ∀ (a b : ℕ), a ≤ b ↔ span R (Subtype.val ∘ ↑f '' {m | b ≤ m}) ≤ span R (Subtype.val ∘ ↑f '' {m | a ≤ m})
a b : ℕ
| a > b
[PROOFSTEP]
rw [GT.gt, lt_iff_le_not_le, this, this, ← lt_iff_le_not_le]
[GOAL]
R : Type u_1
M : Type u_2
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : Nontrivial R
inst✝ : IsArtinian R M
s : Set M
hs : LinearIndependent R Subtype.val
hf : ¬Set.Finite s
f : ℕ ↪ ↑s
this✝ : ∀ (n : ℕ), Subtype.val ∘ ↑f '' {m | n ≤ m} ⊆ s
this : ∀ (a b : ℕ), a ≤ b ↔ span R (Subtype.val ∘ ↑f '' {m | b ≤ m}) ≤ span R (Subtype.val ∘ ↑f '' {m | a ≤ m})
a b : ℕ
| a > b
[PROOFSTEP]
rw [GT.gt, lt_iff_le_not_le, this, this, ← lt_iff_le_not_le]
[GOAL]
R : Type u_1
M : Type u_2
inst✝⁴ : Ring R
inst✝³ : AddCommGroup M
inst✝² : Module R M
inst✝¹ : Nontrivial R
inst✝ : IsArtinian R M
s : Set M
hs : LinearIndependent R Subtype.val
hf : ¬Set.Finite s
f : ℕ ↪ ↑s
this✝ : ∀ (n : ℕ), Subtype.val ∘ ↑f '' {m | n ≤ m} ⊆ s
this : ∀ (a b : ℕ), a ≤ b ↔ span R (Subtype.val ∘ ↑f '' {m | b ≤ m}) ≤ span R (Subtype.val ∘ ↑f '' {m | a ≤ m})
a b : ℕ
| a > b
[PROOFSTEP]
rw [GT.gt, lt_iff_le_not_le, this, this, ← lt_iff_le_not_le]
[GOAL]
R : Type u_1
M : Type u_2
inst✝² : Ring R
inst✝¹ : AddCommGroup M
inst✝ : Module R M
⊢ (∀ (a : Set (Submodule R M)), Set.Nonempty a → ∃ M', M' ∈ a ∧ ∀ (I : Submodule R M), I ∈ a → ¬I < M') ↔ IsArtinian R M
[PROOFSTEP]
rw [isArtinian_iff_wellFounded, WellFounded.wellFounded_iff_has_min]
[GOAL]
R : Type u_1
M : Type u_2
inst✝² : Ring R
inst✝¹ : AddCommGroup M
inst✝ : Module R M
⊢ (∀ (f : ℕ →o (Submodule R M)ᵒᵈ), ∃ n, ∀ (m : ℕ), n ≤ m → ↑f n = ↑f m) ↔ IsArtinian R M
[PROOFSTEP]
rw [isArtinian_iff_wellFounded]
[GOAL]
R : Type u_1
M : Type u_2
inst✝² : Ring R
inst✝¹ : AddCommGroup M
inst✝ : Module R M
⊢ (∀ (f : ℕ →o (Submodule R M)ᵒᵈ), ∃ n, ∀ (m : ℕ), n ≤ m → ↑f n = ↑f m) ↔ WellFounded fun x x_1 => x < x_1
[PROOFSTEP]
exact WellFounded.monotone_chain_condition.symm
[GOAL]
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
⊢ ∃ n, n ≠ 0 ∧ LinearMap.ker (f ^ n) ⊔ LinearMap.range (f ^ n) = ⊤
[PROOFSTEP]
obtain ⟨n, w⟩ := monotone_stabilizes (f.iterateRange.comp ⟨fun n => n + 1, fun n m w => by linarith⟩)
[GOAL]
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
n m : ℕ
w : n ≤ m
⊢ (fun n => n + 1) n ≤ (fun n => n + 1) m
[PROOFSTEP]
linarith
[GOAL]
case intro
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
n : ℕ
w :
∀ (m : ℕ),
n ≤ m →
↑(OrderHom.comp (LinearMap.iterateRange f)
{ toFun := fun n => n + 1,
monotone' := (_ : ∀ (n m : ℕ), n ≤ m → (fun n => n + 1) n ≤ (fun n => n + 1) m) })
n =
↑(OrderHom.comp (LinearMap.iterateRange f)
{ toFun := fun n => n + 1,
monotone' := (_ : ∀ (n m : ℕ), n ≤ m → (fun n => n + 1) n ≤ (fun n => n + 1) m) })
m
⊢ ∃ n, n ≠ 0 ∧ LinearMap.ker (f ^ n) ⊔ LinearMap.range (f ^ n) = ⊤
[PROOFSTEP]
specialize w (n + 1 + n) (by linarith)
[GOAL]
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
n : ℕ
w :
∀ (m : ℕ),
n ≤ m →
↑(OrderHom.comp (LinearMap.iterateRange f)
{ toFun := fun n => n + 1,
monotone' := (_ : ∀ (n m : ℕ), n ≤ m → (fun n => n + 1) n ≤ (fun n => n + 1) m) })
n =
↑(OrderHom.comp (LinearMap.iterateRange f)
{ toFun := fun n => n + 1,
monotone' := (_ : ∀ (n m : ℕ), n ≤ m → (fun n => n + 1) n ≤ (fun n => n + 1) m) })
m
⊢ n ≤ n + 1 + n
[PROOFSTEP]
linarith
[GOAL]
case intro
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
n : ℕ
w :
↑(OrderHom.comp (LinearMap.iterateRange f)
{ toFun := fun n => n + 1, monotone' := (_ : ∀ (n m : ℕ), n ≤ m → (fun n => n + 1) n ≤ (fun n => n + 1) m) })
n =
↑(OrderHom.comp (LinearMap.iterateRange f)
{ toFun := fun n => n + 1, monotone' := (_ : ∀ (n m : ℕ), n ≤ m → (fun n => n + 1) n ≤ (fun n => n + 1) m) })
(n + 1 + n)
⊢ ∃ n, n ≠ 0 ∧ LinearMap.ker (f ^ n) ⊔ LinearMap.range (f ^ n) = ⊤
[PROOFSTEP]
dsimp at w
[GOAL]
case intro
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
n : ℕ
w : LinearMap.range (f ^ (n + 1)) = LinearMap.range (f ^ (n + 1 + n + 1))
⊢ ∃ n, n ≠ 0 ∧ LinearMap.ker (f ^ n) ⊔ LinearMap.range (f ^ n) = ⊤
[PROOFSTEP]
refine' ⟨n + 1, Nat.succ_ne_zero _, _⟩
[GOAL]
case intro
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
n : ℕ
w : LinearMap.range (f ^ (n + 1)) = LinearMap.range (f ^ (n + 1 + n + 1))
⊢ LinearMap.ker (f ^ (n + 1)) ⊔ LinearMap.range (f ^ (n + 1)) = ⊤
[PROOFSTEP]
simp_rw [eq_top_iff', mem_sup]
[GOAL]
case intro
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
n : ℕ
w : LinearMap.range (f ^ (n + 1)) = LinearMap.range (f ^ (n + 1 + n + 1))
⊢ ∀ (x : M), ∃ y, y ∈ LinearMap.ker (f ^ (n + 1)) ∧ ∃ z, z ∈ LinearMap.range (f ^ (n + 1)) ∧ y + z = x
[PROOFSTEP]
intro x
[GOAL]
case intro
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
n : ℕ
w : LinearMap.range (f ^ (n + 1)) = LinearMap.range (f ^ (n + 1 + n + 1))
x : M
⊢ ∃ y, y ∈ LinearMap.ker (f ^ (n + 1)) ∧ ∃ z, z ∈ LinearMap.range (f ^ (n + 1)) ∧ y + z = x
[PROOFSTEP]
have : (f ^ (n + 1)) x ∈ LinearMap.range (f ^ (n + 1 + n + 1)) :=
by
rw [← w]
exact mem_range_self _
[GOAL]
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
n : ℕ
w : LinearMap.range (f ^ (n + 1)) = LinearMap.range (f ^ (n + 1 + n + 1))
x : M
⊢ ↑(f ^ (n + 1)) x ∈ LinearMap.range (f ^ (n + 1 + n + 1))
[PROOFSTEP]
rw [← w]
[GOAL]
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
n : ℕ
w : LinearMap.range (f ^ (n + 1)) = LinearMap.range (f ^ (n + 1 + n + 1))
x : M
⊢ ↑(f ^ (n + 1)) x ∈ LinearMap.range (f ^ (n + 1))
[PROOFSTEP]
exact mem_range_self _
[GOAL]
case intro
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
n : ℕ
w : LinearMap.range (f ^ (n + 1)) = LinearMap.range (f ^ (n + 1 + n + 1))
x : M
this : ↑(f ^ (n + 1)) x ∈ LinearMap.range (f ^ (n + 1 + n + 1))
⊢ ∃ y, y ∈ LinearMap.ker (f ^ (n + 1)) ∧ ∃ z, z ∈ LinearMap.range (f ^ (n + 1)) ∧ y + z = x
[PROOFSTEP]
rcases this with ⟨y, hy⟩
[GOAL]
case intro.intro
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
n : ℕ
w : LinearMap.range (f ^ (n + 1)) = LinearMap.range (f ^ (n + 1 + n + 1))
x y : M
hy : ↑(f ^ (n + 1 + n + 1)) y = ↑(f ^ (n + 1)) x
⊢ ∃ y, y ∈ LinearMap.ker (f ^ (n + 1)) ∧ ∃ z, z ∈ LinearMap.range (f ^ (n + 1)) ∧ y + z = x
[PROOFSTEP]
use x - (f ^ (n + 1)) y
[GOAL]
case h
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
n : ℕ
w : LinearMap.range (f ^ (n + 1)) = LinearMap.range (f ^ (n + 1 + n + 1))
x y : M
hy : ↑(f ^ (n + 1 + n + 1)) y = ↑(f ^ (n + 1)) x
⊢ x - ↑(f ^ (n + 1)) y ∈ LinearMap.ker (f ^ (n + 1)) ∧
∃ z, z ∈ LinearMap.range (f ^ (n + 1)) ∧ x - ↑(f ^ (n + 1)) y + z = x
[PROOFSTEP]
constructor
[GOAL]
case h.left
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
n : ℕ
w : LinearMap.range (f ^ (n + 1)) = LinearMap.range (f ^ (n + 1 + n + 1))
x y : M
hy : ↑(f ^ (n + 1 + n + 1)) y = ↑(f ^ (n + 1)) x
⊢ x - ↑(f ^ (n + 1)) y ∈ LinearMap.ker (f ^ (n + 1))
[PROOFSTEP]
rw [LinearMap.mem_ker, LinearMap.map_sub, ← hy, sub_eq_zero, pow_add]
[GOAL]
case h.left
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
n : ℕ
w : LinearMap.range (f ^ (n + 1)) = LinearMap.range (f ^ (n + 1 + n + 1))
x y : M
hy : ↑(f ^ (n + 1 + n + 1)) y = ↑(f ^ (n + 1)) x
⊢ ↑(f ^ (n + 1 + n + 1)) y = ↑(f ^ n * f ^ 1) (↑(f ^ n * f ^ 1) y)
[PROOFSTEP]
simp [pow_add]
[GOAL]
case h.right
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
n : ℕ
w : LinearMap.range (f ^ (n + 1)) = LinearMap.range (f ^ (n + 1 + n + 1))
x y : M
hy : ↑(f ^ (n + 1 + n + 1)) y = ↑(f ^ (n + 1)) x
⊢ ∃ z, z ∈ LinearMap.range (f ^ (n + 1)) ∧ x - ↑(f ^ (n + 1)) y + z = x
[PROOFSTEP]
use(f ^ (n + 1)) y
[GOAL]
case h
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
n : ℕ
w : LinearMap.range (f ^ (n + 1)) = LinearMap.range (f ^ (n + 1 + n + 1))
x y : M
hy : ↑(f ^ (n + 1 + n + 1)) y = ↑(f ^ (n + 1)) x
⊢ ↑(f ^ (n + 1)) y ∈ LinearMap.range (f ^ (n + 1)) ∧ x - ↑(f ^ (n + 1)) y + ↑(f ^ (n + 1)) y = x
[PROOFSTEP]
simp
[GOAL]
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
s : Injective ↑f
⊢ Surjective ↑f
[PROOFSTEP]
obtain ⟨n, ne, w⟩ := exists_endomorphism_iterate_ker_sup_range_eq_top f
[GOAL]
case intro.intro
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
s : Injective ↑f
n : ℕ
ne : n ≠ 0
w : LinearMap.ker (f ^ n) ⊔ LinearMap.range (f ^ n) = ⊤
⊢ Surjective ↑f
[PROOFSTEP]
rw [LinearMap.ker_eq_bot.mpr (LinearMap.iterate_injective s n), bot_sup_eq, LinearMap.range_eq_top] at w
[GOAL]
case intro.intro
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : M →ₗ[R] M
s : Injective ↑f
n : ℕ
ne : n ≠ 0
w : Surjective ↑(f ^ n)
⊢ Surjective ↑f
[PROOFSTEP]
exact LinearMap.surjective_of_iterate_surjective ne w
[GOAL]
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : ℕ → Submodule R M
h : ∀ (n : ℕ), Disjoint (↑(partialSups (↑OrderDual.toDual ∘ f)) n) (↑OrderDual.toDual (f (n + 1)))
⊢ ∃ n, ∀ (m : ℕ), n ≤ m → f m = ⊤
[PROOFSTEP]
rsuffices ⟨n, w⟩ : ∃ n : ℕ, ∀ m, n ≤ m → OrderDual.toDual f (m + 1) = ⊤
[GOAL]
case intro
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : ℕ → Submodule R M
h : ∀ (n : ℕ), Disjoint (↑(partialSups (↑OrderDual.toDual ∘ f)) n) (↑OrderDual.toDual (f (n + 1)))
n : ℕ
w : ∀ (m : ℕ), n ≤ m → ↑OrderDual.toDual f (m + 1) = ⊤
⊢ ∃ n, ∀ (m : ℕ), n ≤ m → f m = ⊤
[PROOFSTEP]
use n + 1
[GOAL]
case h
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : ℕ → Submodule R M
h : ∀ (n : ℕ), Disjoint (↑(partialSups (↑OrderDual.toDual ∘ f)) n) (↑OrderDual.toDual (f (n + 1)))
n : ℕ
w : ∀ (m : ℕ), n ≤ m → ↑OrderDual.toDual f (m + 1) = ⊤
⊢ ∀ (m : ℕ), n + 1 ≤ m → f m = ⊤
[PROOFSTEP]
rintro (_ | m) p
[GOAL]
case h.zero
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : ℕ → Submodule R M
h : ∀ (n : ℕ), Disjoint (↑(partialSups (↑OrderDual.toDual ∘ f)) n) (↑OrderDual.toDual (f (n + 1)))
n : ℕ
w : ∀ (m : ℕ), n ≤ m → ↑OrderDual.toDual f (m + 1) = ⊤
p : n + 1 ≤ Nat.zero
⊢ f Nat.zero = ⊤
[PROOFSTEP]
cases p
[GOAL]
case h.succ
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : ℕ → Submodule R M
h : ∀ (n : ℕ), Disjoint (↑(partialSups (↑OrderDual.toDual ∘ f)) n) (↑OrderDual.toDual (f (n + 1)))
n : ℕ
w : ∀ (m : ℕ), n ≤ m → ↑OrderDual.toDual f (m + 1) = ⊤
m : ℕ
p : n + 1 ≤ Nat.succ m
⊢ f (Nat.succ m) = ⊤
[PROOFSTEP]
apply w
[GOAL]
case h.succ.a
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : ℕ → Submodule R M
h : ∀ (n : ℕ), Disjoint (↑(partialSups (↑OrderDual.toDual ∘ f)) n) (↑OrderDual.toDual (f (n + 1)))
n : ℕ
w : ∀ (m : ℕ), n ≤ m → ↑OrderDual.toDual f (m + 1) = ⊤
m : ℕ
p : n + 1 ≤ Nat.succ m
⊢ n ≤ m
[PROOFSTEP]
exact Nat.succ_le_succ_iff.mp p
[GOAL]
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : ℕ → Submodule R M
h : ∀ (n : ℕ), Disjoint (↑(partialSups (↑OrderDual.toDual ∘ f)) n) (↑OrderDual.toDual (f (n + 1)))
⊢ ∃ n, ∀ (m : ℕ), n ≤ m → ↑OrderDual.toDual f (m + 1) = ⊤
[PROOFSTEP]
obtain ⟨n, w⟩ := monotone_stabilizes (partialSups (OrderDual.toDual ∘ f))
[GOAL]
case intro
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : ℕ → Submodule R M
h : ∀ (n : ℕ), Disjoint (↑(partialSups (↑OrderDual.toDual ∘ f)) n) (↑OrderDual.toDual (f (n + 1)))
n : ℕ
w : ∀ (m : ℕ), n ≤ m → ↑(partialSups (↑OrderDual.toDual ∘ f)) n = ↑(partialSups (↑OrderDual.toDual ∘ f)) m
⊢ ∃ n, ∀ (m : ℕ), n ≤ m → ↑OrderDual.toDual f (m + 1) = ⊤
[PROOFSTEP]
refine' ⟨n, fun m p => _⟩
[GOAL]
case intro
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
f : ℕ → Submodule R M
h : ∀ (n : ℕ), Disjoint (↑(partialSups (↑OrderDual.toDual ∘ f)) n) (↑OrderDual.toDual (f (n + 1)))
n : ℕ
w : ∀ (m : ℕ), n ≤ m → ↑(partialSups (↑OrderDual.toDual ∘ f)) n = ↑(partialSups (↑OrderDual.toDual ∘ f)) m
m : ℕ
p : n ≤ m
⊢ ↑OrderDual.toDual f (m + 1) = ⊤
[PROOFSTEP]
exact (h m).eq_bot_of_ge (sup_eq_left.1 <| (w (m + 1) <| le_add_right p).symm.trans <| w m p)
[GOAL]
R : Type u_1
M : Type u_2
inst✝³ : CommRing R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
r : R
n m : ℕ
h : n ≤ m
x : M
x✝ : x ∈ (fun n => LinearMap.range (r ^ n • LinearMap.id)) m
y : M
hy : ↑(r ^ m • LinearMap.id) y = x
⊢ ↑(r ^ n • LinearMap.id) (r ^ (m - n) • y) = x
[PROOFSTEP]
dsimp at hy ⊢
[GOAL]
R : Type u_1
M : Type u_2
inst✝³ : CommRing R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
r : R
n m : ℕ
h : n ≤ m
x : M
x✝ : x ∈ (fun n => LinearMap.range (r ^ n • LinearMap.id)) m
y : M
hy : r ^ m • y = x
⊢ r ^ n • r ^ (m - n) • y = x
[PROOFSTEP]
rw [← smul_assoc, smul_eq_mul, ← pow_add, ← hy, add_tsub_cancel_of_le h]
[GOAL]
R : Type u_1
M : Type u_2
inst✝³ : CommRing R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
r : R
x : M
⊢ ∃ n y, r ^ Nat.succ n • y = r ^ n • x
[PROOFSTEP]
obtain ⟨n, hn⟩ := IsArtinian.range_smul_pow_stabilizes M r
[GOAL]
case intro
R : Type u_1
M : Type u_2
inst✝³ : CommRing R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
r : R
x : M
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → LinearMap.range (r ^ n • LinearMap.id) = LinearMap.range (r ^ m • LinearMap.id)
⊢ ∃ n y, r ^ Nat.succ n • y = r ^ n • x
[PROOFSTEP]
simp_rw [SetLike.ext_iff] at hn
[GOAL]
case intro
R : Type u_1
M : Type u_2
inst✝³ : CommRing R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
r : R
x : M
n : ℕ
hn :
∀ (m : ℕ), n ≤ m → ∀ (x : M), x ∈ LinearMap.range (r ^ n • LinearMap.id) ↔ x ∈ LinearMap.range (r ^ m • LinearMap.id)
⊢ ∃ n y, r ^ Nat.succ n • y = r ^ n • x
[PROOFSTEP]
exact ⟨n, by simpa using hn n.succ n.le_succ (r ^ n • x)⟩
[GOAL]
R : Type u_1
M : Type u_2
inst✝³ : CommRing R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinian R M
r : R
x : M
n : ℕ
hn :
∀ (m : ℕ), n ≤ m → ∀ (x : M), x ∈ LinearMap.range (r ^ n • LinearMap.id) ↔ x ∈ LinearMap.range (r ^ m • LinearMap.id)
⊢ ∃ y, r ^ Nat.succ n • y = r ^ n • x
[PROOFSTEP]
simpa using hn n.succ n.le_succ (r ^ n • x)
[GOAL]
R : Type u_1
S : Type u_2
M : Type u_3
inst✝⁶ : CommRing R
inst✝⁵ : Ring S
inst✝⁴ : AddCommGroup M
inst✝³ : Algebra R S
inst✝² : Module S M
inst✝¹ : Module R M
inst✝ : IsScalarTower R S M
h : IsArtinian R M
⊢ IsArtinian S M
[PROOFSTEP]
rw [isArtinian_iff_wellFounded] at h ⊢
[GOAL]
R : Type u_1
S : Type u_2
M : Type u_3
inst✝⁶ : CommRing R
inst✝⁵ : Ring S
inst✝⁴ : AddCommGroup M
inst✝³ : Algebra R S
inst✝² : Module S M
inst✝¹ : Module R M
inst✝ : IsScalarTower R S M
h : WellFounded fun x x_1 => x < x_1
⊢ WellFounded fun x x_1 => x < x_1
[PROOFSTEP]
refine' (Submodule.restrictScalarsEmbedding R S M).wellFounded h
[GOAL]
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
N : Submodule R M
inst✝ : IsArtinianRing R
hN : FG N
⊢ IsArtinian R { x // x ∈ N }
[PROOFSTEP]
let ⟨s, hs⟩ := hN
[GOAL]
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
N : Submodule R M
inst✝ : IsArtinianRing R
hN : FG N
s : Finset M
hs : span R ↑s = N
⊢ IsArtinian R { x // x ∈ N }
[PROOFSTEP]
haveI := Classical.decEq M
[GOAL]
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
N : Submodule R M
inst✝ : IsArtinianRing R
hN : FG N
s : Finset M
hs : span R ↑s = N
this : DecidableEq M
⊢ IsArtinian R { x // x ∈ N }
[PROOFSTEP]
haveI := Classical.decEq R
[GOAL]
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
N : Submodule R M
inst✝ : IsArtinianRing R
hN : FG N
s : Finset M
hs : span R ↑s = N
this✝ : DecidableEq M
this : DecidableEq R
⊢ IsArtinian R { x // x ∈ N }
[PROOFSTEP]
have : ∀ x ∈ s, x ∈ N := fun x hx => hs ▸ Submodule.subset_span hx
[GOAL]
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
N : Submodule R M
inst✝ : IsArtinianRing R
hN : FG N
s : Finset M
hs : span R ↑s = N
this✝¹ : DecidableEq M
this✝ : DecidableEq R
this : ∀ (x : M), x ∈ s → x ∈ N
⊢ IsArtinian R { x // x ∈ N }
[PROOFSTEP]
refine' @isArtinian_of_surjective _ ((↑s : Set M) →₀ R) N _ _ _ _ _ _ _ isArtinian_finsupp
[GOAL]
case refine'_1
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
N : Submodule R M
inst✝ : IsArtinianRing R
hN : FG N
s : Finset M
hs : span R ↑s = N
this✝¹ : DecidableEq M
this✝ : DecidableEq R
this : ∀ (x : M), x ∈ s → x ∈ N
⊢ (↑↑s →₀ R) →ₗ[R] { x // x ∈ N }
[PROOFSTEP]
exact Finsupp.total (↑s : Set M) N R (fun i => ⟨i, hs ▸ subset_span i.2⟩)
[GOAL]
case refine'_2
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
N : Submodule R M
inst✝ : IsArtinianRing R
hN : FG N
s : Finset M
hs : span R ↑s = N
this✝¹ : DecidableEq M
this✝ : DecidableEq R
this : ∀ (x : M), x ∈ s → x ∈ N
⊢ Surjective ↑(Finsupp.total ↑↑s { x // x ∈ N } R fun i => { val := ↑i, property := (_ : ↑i ∈ N) })
[PROOFSTEP]
rw [← LinearMap.range_eq_top, eq_top_iff, ←
map_le_map_iff_of_injective (show Injective (Submodule.subtype N) from Subtype.val_injective), Submodule.map_top,
range_subtype, ← Submodule.map_top, ← Submodule.map_comp, Submodule.map_top]
[GOAL]
case refine'_2
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
N : Submodule R M
inst✝ : IsArtinianRing R
hN : FG N
s : Finset M
hs : span R ↑s = N
this✝¹ : DecidableEq M
this✝ : DecidableEq R
this : ∀ (x : M), x ∈ s → x ∈ N
⊢ N ≤
LinearMap.range
(LinearMap.comp (Submodule.subtype N)
(Finsupp.total ↑↑s { x // x ∈ N } R fun i => { val := ↑i, property := (_ : ↑i ∈ N) }))
[PROOFSTEP]
subst N
[GOAL]
case refine'_2
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinianRing R
s : Finset M
this✝¹ : DecidableEq M
this✝ : DecidableEq R
hN : FG (span R ↑s)
this : ∀ (x : M), x ∈ s → x ∈ span R ↑s
⊢ span R ↑s ≤
LinearMap.range
(LinearMap.comp (Submodule.subtype (span R ↑s))
(Finsupp.total ↑↑s { x // x ∈ span R ↑s } R fun i => { val := ↑i, property := (_ : ↑i ∈ span R ↑s) }))
[PROOFSTEP]
refine span_le.2 (fun i hi => ?_)
[GOAL]
case refine'_2
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinianRing R
s : Finset M
this✝¹ : DecidableEq M
this✝ : DecidableEq R
hN : FG (span R ↑s)
this : ∀ (x : M), x ∈ s → x ∈ span R ↑s
i : M
hi : i ∈ ↑s
⊢ i ∈
↑(LinearMap.range
(LinearMap.comp (Submodule.subtype (span R ↑s))
(Finsupp.total ↑↑s { x // x ∈ span R ↑s } R fun i => { val := ↑i, property := (_ : ↑i ∈ span R ↑s) })))
[PROOFSTEP]
use Finsupp.single ⟨i, hi⟩ 1
[GOAL]
case h
R : Type u_1
M : Type u_2
inst✝³ : Ring R
inst✝² : AddCommGroup M
inst✝¹ : Module R M
inst✝ : IsArtinianRing R
s : Finset M
this✝¹ : DecidableEq M
this✝ : DecidableEq R
hN : FG (span R ↑s)
this : ∀ (x : M), x ∈ s → x ∈ span R ↑s
i : M
hi : i ∈ ↑s
⊢ ↑(LinearMap.comp (Submodule.subtype (span R ↑s))
(Finsupp.total ↑↑s { x // x ∈ span R ↑s } R fun i => { val := ↑i, property := (_ : ↑i ∈ span R ↑s) }))
(Finsupp.single { val := i, property := hi } 1) =
i
[PROOFSTEP]
simp
[GOAL]
R : Type u_1
inst✝² : Ring R
S : Type u_2
inst✝¹ : Ring S
F : Type u_3
inst✝ : RingHomClass F R S
f : F
hf : Surjective ↑f
H : IsArtinianRing R
⊢ IsArtinianRing S
[PROOFSTEP]
rw [isArtinianRing_iff, isArtinian_iff_wellFounded] at H ⊢
[GOAL]
R : Type u_1
inst✝² : Ring R
S : Type u_2
inst✝¹ : Ring S
F : Type u_3
inst✝ : RingHomClass F R S
f : F
hf : Surjective ↑f
H : WellFounded fun x x_1 => x < x_1
⊢ WellFounded fun x x_1 => x < x_1
[PROOFSTEP]
exact (Ideal.orderEmbeddingOfSurjective f hf).wellFounded H
[GOAL]
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
⊢ IsNilpotent (Ideal.jacobson ⊥)
[PROOFSTEP]
let Jac := Ideal.jacobson (⊥ : Ideal R)
[GOAL]
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
⊢ IsNilpotent (Ideal.jacobson ⊥)
[PROOFSTEP]
let f : ℕ →o (Ideal R)ᵒᵈ := ⟨fun n => Jac ^ n, fun _ _ h => Ideal.pow_le_pow h⟩
[GOAL]
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
⊢ IsNilpotent (Ideal.jacobson ⊥)
[PROOFSTEP]
obtain ⟨n, hn⟩ : ∃ n, ∀ m, n ≤ m → Jac ^ n = Jac ^ m := IsArtinian.monotone_stabilizes f
[GOAL]
case intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
⊢ IsNilpotent (Ideal.jacobson ⊥)
[PROOFSTEP]
refine' ⟨n, _⟩
[GOAL]
case intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
⊢ Ideal.jacobson ⊥ ^ n = 0
[PROOFSTEP]
let J : Ideal R := annihilator (Jac ^ n)
[GOAL]
case intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
⊢ Ideal.jacobson ⊥ ^ n = 0
[PROOFSTEP]
suffices J = ⊤ by
have hJ : J • Jac ^ n = ⊥ := annihilator_smul (Jac ^ n)
simpa only [this, top_smul, Ideal.zero_eq_bot] using hJ
[GOAL]
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
this : J = ⊤
⊢ Ideal.jacobson ⊥ ^ n = 0
[PROOFSTEP]
have hJ : J • Jac ^ n = ⊥ := annihilator_smul (Jac ^ n)
[GOAL]
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
this : J = ⊤
hJ : J • Jac ^ n = ⊥
⊢ Ideal.jacobson ⊥ ^ n = 0
[PROOFSTEP]
simpa only [this, top_smul, Ideal.zero_eq_bot] using hJ
[GOAL]
case intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
⊢ J = ⊤
[PROOFSTEP]
by_contra hJ
[GOAL]
case intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : ¬J = ⊤
⊢ False
[PROOFSTEP]
change J ≠ ⊤ at hJ
[GOAL]
case intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
⊢ False
[PROOFSTEP]
rcases IsArtinian.set_has_minimal {J' : Ideal R | J < J'} ⟨⊤, hJ.lt_top⟩ with
⟨J', hJJ' : J < J', hJ' : ∀ I, J < I → ¬I < J'⟩
[GOAL]
case intro.intro.intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
J' : Submodule R R
hJJ' : J < J'
hJ' : ∀ (I : Ideal R), J < I → ¬I < J'
⊢ False
[PROOFSTEP]
rcases SetLike.exists_of_lt hJJ' with ⟨x, hxJ', hxJ⟩
[GOAL]
case intro.intro.intro.intro.intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
J' : Submodule R R
hJJ' : J < J'
hJ' : ∀ (I : Ideal R), J < I → ¬I < J'
x : R
hxJ' : x ∈ J'
hxJ : ¬x ∈ J
⊢ False
[PROOFSTEP]
obtain rfl : J ⊔ Ideal.span { x } = J' :=
by
apply eq_of_le_of_not_lt _ (hJ' (J ⊔ Ideal.span { x }) _)
· exact sup_le hJJ'.le (span_le.2 (singleton_subset_iff.2 hxJ'))
· rw [SetLike.lt_iff_le_and_exists]
exact ⟨le_sup_left, ⟨x, mem_sup_right (mem_span_singleton_self x), hxJ⟩⟩
[GOAL]
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
J' : Submodule R R
hJJ' : J < J'
hJ' : ∀ (I : Ideal R), J < I → ¬I < J'
x : R
hxJ' : x ∈ J'
hxJ : ¬x ∈ J
⊢ J ⊔ Ideal.span {x} = J'
[PROOFSTEP]
apply eq_of_le_of_not_lt _ (hJ' (J ⊔ Ideal.span { x }) _)
[GOAL]
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
J' : Submodule R R
hJJ' : J < J'
hJ' : ∀ (I : Ideal R), J < I → ¬I < J'
x : R
hxJ' : x ∈ J'
hxJ : ¬x ∈ J
⊢ J ⊔ Ideal.span {x} ≤ J'
[PROOFSTEP]
exact sup_le hJJ'.le (span_le.2 (singleton_subset_iff.2 hxJ'))
[GOAL]
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
J' : Submodule R R
hJJ' : J < J'
hJ' : ∀ (I : Ideal R), J < I → ¬I < J'
x : R
hxJ' : x ∈ J'
hxJ : ¬x ∈ J
⊢ J < J ⊔ Ideal.span {x}
[PROOFSTEP]
rw [SetLike.lt_iff_le_and_exists]
[GOAL]
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
J' : Submodule R R
hJJ' : J < J'
hJ' : ∀ (I : Ideal R), J < I → ¬I < J'
x : R
hxJ' : x ∈ J'
hxJ : ¬x ∈ J
⊢ J ≤ J ⊔ Ideal.span {x} ∧ ∃ x_1, x_1 ∈ J ⊔ Ideal.span {x} ∧ ¬x_1 ∈ J
[PROOFSTEP]
exact ⟨le_sup_left, ⟨x, mem_sup_right (mem_span_singleton_self x), hxJ⟩⟩
[GOAL]
case intro.intro.intro.intro.intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
x : R
hxJ : ¬x ∈ J
hJJ' : J < J ⊔ Ideal.span {x}
hJ' : ∀ (I : Ideal R), J < I → ¬I < J ⊔ Ideal.span {x}
hxJ' : x ∈ J ⊔ Ideal.span {x}
⊢ False
[PROOFSTEP]
have : J ⊔ Jac • Ideal.span { x } ≤ J ⊔ Ideal.span { x } :=
sup_le_sup_left (smul_le.2 fun _ _ _ => Submodule.smul_mem _ _) _
[GOAL]
case intro.intro.intro.intro.intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
x : R
hxJ : ¬x ∈ J
hJJ' : J < J ⊔ Ideal.span {x}
hJ' : ∀ (I : Ideal R), J < I → ¬I < J ⊔ Ideal.span {x}
hxJ' : x ∈ J ⊔ Ideal.span {x}
this : J ⊔ Jac • Ideal.span {x} ≤ J ⊔ Ideal.span {x}
⊢ False
[PROOFSTEP]
have : Jac * Ideal.span { x } ≤ J := by
-- Need version 4 of Nakayama's lemma on Stacks
by_contra H
refine' H (smul_sup_le_of_le_smul_of_le_jacobson_bot (fg_span_singleton _) le_rfl (this.eq_of_not_lt (hJ' _ _)).ge)
exact lt_of_le_of_ne le_sup_left fun h => H <| h.symm ▸ le_sup_right
[GOAL]
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
x : R
hxJ : ¬x ∈ J
hJJ' : J < J ⊔ Ideal.span {x}
hJ' : ∀ (I : Ideal R), J < I → ¬I < J ⊔ Ideal.span {x}
hxJ' : x ∈ J ⊔ Ideal.span {x}
this : J ⊔ Jac • Ideal.span {x} ≤ J ⊔ Ideal.span {x}
⊢ Jac * Ideal.span {x} ≤ J
[PROOFSTEP]
by_contra H
[GOAL]
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
x : R
hxJ : ¬x ∈ J
hJJ' : J < J ⊔ Ideal.span {x}
hJ' : ∀ (I : Ideal R), J < I → ¬I < J ⊔ Ideal.span {x}
hxJ' : x ∈ J ⊔ Ideal.span {x}
this : J ⊔ Jac • Ideal.span {x} ≤ J ⊔ Ideal.span {x}
H : ¬Jac * Ideal.span {x} ≤ J
⊢ False
[PROOFSTEP]
refine' H (smul_sup_le_of_le_smul_of_le_jacobson_bot (fg_span_singleton _) le_rfl (this.eq_of_not_lt (hJ' _ _)).ge)
[GOAL]
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
x : R
hxJ : ¬x ∈ J
hJJ' : J < J ⊔ Ideal.span {x}
hJ' : ∀ (I : Ideal R), J < I → ¬I < J ⊔ Ideal.span {x}
hxJ' : x ∈ J ⊔ Ideal.span {x}
this : J ⊔ Jac • Ideal.span {x} ≤ J ⊔ Ideal.span {x}
H : ¬Jac * Ideal.span {x} ≤ J
⊢ J < J ⊔ Jac • Ideal.span {x}
[PROOFSTEP]
exact lt_of_le_of_ne le_sup_left fun h => H <| h.symm ▸ le_sup_right
[GOAL]
case intro.intro.intro.intro.intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
x : R
hxJ : ¬x ∈ J
hJJ' : J < J ⊔ Ideal.span {x}
hJ' : ∀ (I : Ideal R), J < I → ¬I < J ⊔ Ideal.span {x}
hxJ' : x ∈ J ⊔ Ideal.span {x}
this✝ : J ⊔ Jac • Ideal.span {x} ≤ J ⊔ Ideal.span {x}
this : Jac * Ideal.span {x} ≤ J
⊢ False
[PROOFSTEP]
have : Ideal.span { x } * Jac ^ (n + 1) ≤ ⊥
[GOAL]
case this
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
x : R
hxJ : ¬x ∈ J
hJJ' : J < J ⊔ Ideal.span {x}
hJ' : ∀ (I : Ideal R), J < I → ¬I < J ⊔ Ideal.span {x}
hxJ' : x ∈ J ⊔ Ideal.span {x}
this✝ : J ⊔ Jac • Ideal.span {x} ≤ J ⊔ Ideal.span {x}
this : Jac * Ideal.span {x} ≤ J
⊢ Ideal.span {x} * Jac ^ (n + 1) ≤ ⊥
case intro.intro.intro.intro.intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
x : R
hxJ : ¬x ∈ J
hJJ' : J < J ⊔ Ideal.span {x}
hJ' : ∀ (I : Ideal R), J < I → ¬I < J ⊔ Ideal.span {x}
hxJ' : x ∈ J ⊔ Ideal.span {x}
this✝¹ : J ⊔ Jac • Ideal.span {x} ≤ J ⊔ Ideal.span {x}
this✝ : Jac * Ideal.span {x} ≤ J
this : Ideal.span {x} * Jac ^ (n + 1) ≤ ⊥
⊢ False
[PROOFSTEP]
calc
Ideal.span { x } * Jac ^ (n + 1) = Ideal.span { x } * Jac * Jac ^ n := by rw [pow_succ, ← mul_assoc]
_ ≤ J * Jac ^ n := (mul_le_mul (by rwa [mul_comm]) le_rfl)
_ = ⊥ := by simp
[GOAL]
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
x : R
hxJ : ¬x ∈ J
hJJ' : J < J ⊔ Ideal.span {x}
hJ' : ∀ (I : Ideal R), J < I → ¬I < J ⊔ Ideal.span {x}
hxJ' : x ∈ J ⊔ Ideal.span {x}
this✝ : J ⊔ Jac • Ideal.span {x} ≤ J ⊔ Ideal.span {x}
this : Jac * Ideal.span {x} ≤ J
⊢ Ideal.span {x} * Jac ^ (n + 1) = Ideal.span {x} * Jac * Jac ^ n
[PROOFSTEP]
rw [pow_succ, ← mul_assoc]
[GOAL]
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
x : R
hxJ : ¬x ∈ J
hJJ' : J < J ⊔ Ideal.span {x}
hJ' : ∀ (I : Ideal R), J < I → ¬I < J ⊔ Ideal.span {x}
hxJ' : x ∈ J ⊔ Ideal.span {x}
this✝ : J ⊔ Jac • Ideal.span {x} ≤ J ⊔ Ideal.span {x}
this : Jac * Ideal.span {x} ≤ J
⊢ Ideal.span {x} * Jac ≤ J
[PROOFSTEP]
rwa [mul_comm]
[GOAL]
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
x : R
hxJ : ¬x ∈ J
hJJ' : J < J ⊔ Ideal.span {x}
hJ' : ∀ (I : Ideal R), J < I → ¬I < J ⊔ Ideal.span {x}
hxJ' : x ∈ J ⊔ Ideal.span {x}
this✝ : J ⊔ Jac • Ideal.span {x} ≤ J ⊔ Ideal.span {x}
this : Jac * Ideal.span {x} ≤ J
⊢ J * Jac ^ n = ⊥
[PROOFSTEP]
simp
[GOAL]
case intro.intro.intro.intro.intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
x : R
hxJ : ¬x ∈ J
hJJ' : J < J ⊔ Ideal.span {x}
hJ' : ∀ (I : Ideal R), J < I → ¬I < J ⊔ Ideal.span {x}
hxJ' : x ∈ J ⊔ Ideal.span {x}
this✝¹ : J ⊔ Jac • Ideal.span {x} ≤ J ⊔ Ideal.span {x}
this✝ : Jac * Ideal.span {x} ≤ J
this : Ideal.span {x} * Jac ^ (n + 1) ≤ ⊥
⊢ False
[PROOFSTEP]
refine' hxJ (mem_annihilator.2 fun y hy => (mem_bot R).1 _)
[GOAL]
case intro.intro.intro.intro.intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
x : R
hxJ : ¬x ∈ J
hJJ' : J < J ⊔ Ideal.span {x}
hJ' : ∀ (I : Ideal R), J < I → ¬I < J ⊔ Ideal.span {x}
hxJ' : x ∈ J ⊔ Ideal.span {x}
this✝¹ : J ⊔ Jac • Ideal.span {x} ≤ J ⊔ Ideal.span {x}
this✝ : Jac * Ideal.span {x} ≤ J
this : Ideal.span {x} * Jac ^ (n + 1) ≤ ⊥
y : R
hy : y ∈ Jac ^ n
⊢ x • y ∈ ⊥
[PROOFSTEP]
refine' this (mul_mem_mul (mem_span_singleton_self x) _)
[GOAL]
case intro.intro.intro.intro.intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsArtinianRing R
Jac : Ideal R := Ideal.jacobson ⊥
f : ℕ →o (Ideal R)ᵒᵈ := { toFun := fun n => Jac ^ n, monotone' := (_ : ∀ (x x_1 : ℕ), x ≤ x_1 → Jac ^ x_1 ≤ Jac ^ x) }
n : ℕ
hn : ∀ (m : ℕ), n ≤ m → Jac ^ n = Jac ^ m
J : Ideal R := annihilator (Jac ^ n)
hJ : J ≠ ⊤
x : R
hxJ : ¬x ∈ J
hJJ' : J < J ⊔ Ideal.span {x}
hJ' : ∀ (I : Ideal R), J < I → ¬I < J ⊔ Ideal.span {x}
hxJ' : x ∈ J ⊔ Ideal.span {x}
this✝¹ : J ⊔ Jac • Ideal.span {x} ≤ J ⊔ Ideal.span {x}
this✝ : Jac * Ideal.span {x} ≤ J
this : Ideal.span {x} * Jac ^ (n + 1) ≤ ⊥
y : R
hy : y ∈ Jac ^ n
⊢ y ∈ Jac ^ (n + 1)
[PROOFSTEP]
rwa [← hn (n + 1) (Nat.le_succ _)]
[GOAL]
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
⊢ ∃ b, x * b = 1
[PROOFSTEP]
have : IsArtinianRing (R ⧸ p) := (@Ideal.Quotient.mk_surjective R _ p).isArtinianRing
[GOAL]
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
this : IsArtinianRing (R ⧸ p)
⊢ ∃ b, x * b = 1
[PROOFSTEP]
obtain ⟨n, hn⟩ : ∃ (n : ℕ), Ideal.span {x ^ n} = Ideal.span {x ^ (n + 1)}
[GOAL]
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
this : IsArtinianRing (R ⧸ p)
⊢ ∃ n, Ideal.span {x ^ n} = Ideal.span {x ^ (n + 1)}
[PROOFSTEP]
obtain ⟨n, h⟩ :=
IsArtinian.monotone_stabilizes (R := R ⧸ p) (M := R ⧸ p)
⟨fun m => OrderDual.toDual (Ideal.span {x ^ m}), fun m n h y hy =>
by
dsimp [OrderDual.toDual] at *
rw [Ideal.mem_span_singleton] at hy ⊢
obtain ⟨z, rfl⟩ := hy
exact dvd_mul_of_dvd_left (pow_dvd_pow _ h) _⟩
[GOAL]
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
this : IsArtinianRing (R ⧸ p)
m n : ℕ
h : m ≤ n
y : R ⧸ p
hy : y ∈ (fun m => ↑OrderDual.toDual (Ideal.span {x ^ m})) n
⊢ y ∈ (fun m => ↑OrderDual.toDual (Ideal.span {x ^ m})) m
[PROOFSTEP]
dsimp [OrderDual.toDual] at *
[GOAL]
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : ¬x = 0
this : IsArtinianRing (R ⧸ p)
m n : ℕ
h : m ≤ n
y : R ⧸ p
hy : y ∈ Ideal.span {x ^ n}
⊢ y ∈ Ideal.span {x ^ m}
[PROOFSTEP]
rw [Ideal.mem_span_singleton] at hy ⊢
[GOAL]
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : ¬x = 0
this : IsArtinianRing (R ⧸ p)
m n : ℕ
h : m ≤ n
y : R ⧸ p
hy : x ^ n ∣ y
⊢ x ^ m ∣ y
[PROOFSTEP]
obtain ⟨z, rfl⟩ := hy
[GOAL]
case intro
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : ¬x = 0
this : IsArtinianRing (R ⧸ p)
m n : ℕ
h : m ≤ n
z : R ⧸ p
⊢ x ^ m ∣ x ^ n * z
[PROOFSTEP]
exact dvd_mul_of_dvd_left (pow_dvd_pow _ h) _
[GOAL]
case intro
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
this : IsArtinianRing (R ⧸ p)
n : ℕ
h :
∀ (m : ℕ),
n ≤ m →
↑{ toFun := fun m => ↑OrderDual.toDual (Ideal.span {x ^ m}),
monotone' :=
(_ :
∀ (m n : ℕ),
m ≤ n →
∀ (y : R ⧸ p),
y ∈ (fun m => ↑OrderDual.toDual (Ideal.span {x ^ m})) n →
y ∈ (fun m => ↑OrderDual.toDual (Ideal.span {x ^ m})) m) }
n =
↑{ toFun := fun m => ↑OrderDual.toDual (Ideal.span {x ^ m}),
monotone' :=
(_ :
∀ (m n : ℕ),
m ≤ n →
∀ (y : R ⧸ p),
y ∈ (fun m => ↑OrderDual.toDual (Ideal.span {x ^ m})) n →
y ∈ (fun m => ↑OrderDual.toDual (Ideal.span {x ^ m})) m) }
m
⊢ ∃ n, Ideal.span {x ^ n} = Ideal.span {x ^ (n + 1)}
[PROOFSTEP]
exact ⟨n, h (n + 1) <| by norm_num⟩
[GOAL]
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
this : IsArtinianRing (R ⧸ p)
n : ℕ
h :
∀ (m : ℕ),
n ≤ m →
↑{ toFun := fun m => ↑OrderDual.toDual (Ideal.span {x ^ m}),
monotone' :=
(_ :
∀ (m n : ℕ),
m ≤ n →
∀ (y : R ⧸ p),
y ∈ (fun m => ↑OrderDual.toDual (Ideal.span {x ^ m})) n →
y ∈ (fun m => ↑OrderDual.toDual (Ideal.span {x ^ m})) m) }
n =
↑{ toFun := fun m => ↑OrderDual.toDual (Ideal.span {x ^ m}),
monotone' :=
(_ :
∀ (m n : ℕ),
m ≤ n →
∀ (y : R ⧸ p),
y ∈ (fun m => ↑OrderDual.toDual (Ideal.span {x ^ m})) n →
y ∈ (fun m => ↑OrderDual.toDual (Ideal.span {x ^ m})) m) }
m
⊢ n ≤ n + 1
[PROOFSTEP]
norm_num
[GOAL]
case intro
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
this : IsArtinianRing (R ⧸ p)
n : ℕ
hn : Ideal.span {x ^ n} = Ideal.span {x ^ (n + 1)}
⊢ ∃ b, x * b = 1
[PROOFSTEP]
have H : x ^ n ∈ Ideal.span {x ^ (n + 1)}
[GOAL]
case H
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
this : IsArtinianRing (R ⧸ p)
n : ℕ
hn : Ideal.span {x ^ n} = Ideal.span {x ^ (n + 1)}
⊢ x ^ n ∈ Ideal.span {x ^ (n + 1)}
case intro
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
this : IsArtinianRing (R ⧸ p)
n : ℕ
hn : Ideal.span {x ^ n} = Ideal.span {x ^ (n + 1)}
H : x ^ n ∈ Ideal.span {x ^ (n + 1)}
⊢ ∃ b, x * b = 1
[PROOFSTEP]
{rw [← hn]; refine Submodule.subset_span (Set.mem_singleton _)
}
[GOAL]
case H
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
this : IsArtinianRing (R ⧸ p)
n : ℕ
hn : Ideal.span {x ^ n} = Ideal.span {x ^ (n + 1)}
⊢ x ^ n ∈ Ideal.span {x ^ (n + 1)}
[PROOFSTEP]
rw [← hn]
[GOAL]
case H
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
this : IsArtinianRing (R ⧸ p)
n : ℕ
hn : Ideal.span {x ^ n} = Ideal.span {x ^ (n + 1)}
⊢ x ^ n ∈ Ideal.span {x ^ n}
[PROOFSTEP]
refine Submodule.subset_span (Set.mem_singleton _)
[GOAL]
case intro
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
this : IsArtinianRing (R ⧸ p)
n : ℕ
hn : Ideal.span {x ^ n} = Ideal.span {x ^ (n + 1)}
H : x ^ n ∈ Ideal.span {x ^ (n + 1)}
⊢ ∃ b, x * b = 1
[PROOFSTEP]
rw [Ideal.mem_span_singleton] at H
[GOAL]
case intro
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
this : IsArtinianRing (R ⧸ p)
n : ℕ
hn : Ideal.span {x ^ n} = Ideal.span {x ^ (n + 1)}
H : x ^ (n + 1) ∣ x ^ n
⊢ ∃ b, x * b = 1
[PROOFSTEP]
obtain ⟨y, hy⟩ := H
[GOAL]
case intro.intro
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
this : IsArtinianRing (R ⧸ p)
n : ℕ
hn : Ideal.span {x ^ n} = Ideal.span {x ^ (n + 1)}
y : R ⧸ p
hy : x ^ n = x ^ (n + 1) * y
⊢ ∃ b, x * b = 1
[PROOFSTEP]
rw [pow_add, mul_assoc, pow_one] at hy
[GOAL]
case intro.intro
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
this : IsArtinianRing (R ⧸ p)
n : ℕ
hn : Ideal.span {x ^ n} = Ideal.span {x ^ (n + 1)}
y : R ⧸ p
hy : x ^ n = x ^ n * (x * y)
⊢ ∃ b, x * b = 1
[PROOFSTEP]
conv_lhs at hy => rw [← mul_one (x ^ n)]
[GOAL]
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
this : IsArtinianRing (R ⧸ p)
n : ℕ
hn : Ideal.span {x ^ n} = Ideal.span {x ^ (n + 1)}
y : R ⧸ p
hy : x ^ n = x ^ n * (x * y)
| x ^ n
[PROOFSTEP]
rw [← mul_one (x ^ n)]
[GOAL]
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
this : IsArtinianRing (R ⧸ p)
n : ℕ
hn : Ideal.span {x ^ n} = Ideal.span {x ^ (n + 1)}
y : R ⧸ p
hy : x ^ n = x ^ n * (x * y)
| x ^ n
[PROOFSTEP]
rw [← mul_one (x ^ n)]
[GOAL]
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
this : IsArtinianRing (R ⧸ p)
n : ℕ
hn : Ideal.span {x ^ n} = Ideal.span {x ^ (n + 1)}
y : R ⧸ p
hy : x ^ n = x ^ n * (x * y)
| x ^ n
[PROOFSTEP]
rw [← mul_one (x ^ n)]
[GOAL]
case intro.intro
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsArtinianRing R
p : Ideal R
inst✝ : Ideal.IsPrime p
x : R ⧸ p
hx : x ≠ 0
this : IsArtinianRing (R ⧸ p)
n : ℕ
hn : Ideal.span {x ^ n} = Ideal.span {x ^ (n + 1)}
y : R ⧸ p
hy : x ^ n * 1 = x ^ n * (x * y)
⊢ ∃ b, x * b = 1
[PROOFSTEP]
exact ⟨y, mul_left_cancel₀ (pow_ne_zero _ hx) hy.symm⟩
[GOAL]
R : Type u_1
inst✝⁴ : CommRing R
inst✝³ : IsArtinianRing R
S : Submonoid R
L : Type u_2
inst✝² : CommRing L
inst✝¹ : Algebra R L
inst✝ : IsLocalization S L
⊢ Surjective ↑(algebraMap R L)
[PROOFSTEP]
intro r'
[GOAL]
R : Type u_1
inst✝⁴ : CommRing R
inst✝³ : IsArtinianRing R
S : Submonoid R
L : Type u_2
inst✝² : CommRing L
inst✝¹ : Algebra R L
inst✝ : IsLocalization S L
r' : L
⊢ ∃ a, ↑(algebraMap R L) a = r'
[PROOFSTEP]
obtain ⟨r₁, s, rfl⟩ := IsLocalization.mk'_surjective S r'
[GOAL]
case intro.intro
R : Type u_1
inst✝⁴ : CommRing R
inst✝³ : IsArtinianRing R
S : Submonoid R
L : Type u_2
inst✝² : CommRing L
inst✝¹ : Algebra R L
inst✝ : IsLocalization S L
r₁ : R
s : { x // x ∈ S }
⊢ ∃ a, ↑(algebraMap R L) a = IsLocalization.mk' L r₁ s
[PROOFSTEP]
obtain ⟨r₂, h⟩ : ∃ r : R, IsLocalization.mk' L 1 s = algebraMap R L r
[GOAL]
R : Type u_1
inst✝⁴ : CommRing R
inst✝³ : IsArtinianRing R
S : Submonoid R
L : Type u_2
inst✝² : CommRing L
inst✝¹ : Algebra R L
inst✝ : IsLocalization S L
r₁ : R
s : { x // x ∈ S }
⊢ ∃ r, IsLocalization.mk' L 1 s = ↑(algebraMap R L) r
case intro.intro.intro
R : Type u_1
inst✝⁴ : CommRing R
inst✝³ : IsArtinianRing R
S : Submonoid R
L : Type u_2
inst✝² : CommRing L
inst✝¹ : Algebra R L
inst✝ : IsLocalization S L
r₁ : R
s : { x // x ∈ S }
r₂ : R
h : IsLocalization.mk' L 1 s = ↑(algebraMap R L) r₂
⊢ ∃ a, ↑(algebraMap R L) a = IsLocalization.mk' L r₁ s
[PROOFSTEP]
swap
[GOAL]
case intro.intro.intro
R : Type u_1
inst✝⁴ : CommRing R
inst✝³ : IsArtinianRing R
S : Submonoid R
L : Type u_2
inst✝² : CommRing L
inst✝¹ : Algebra R L
inst✝ : IsLocalization S L
r₁ : R
s : { x // x ∈ S }
r₂ : R
h : IsLocalization.mk' L 1 s = ↑(algebraMap R L) r₂
⊢ ∃ a, ↑(algebraMap R L) a = IsLocalization.mk' L r₁ s
[PROOFSTEP]
exact ⟨r₁ * r₂, by rw [IsLocalization.mk'_eq_mul_mk'_one, map_mul, h]⟩
[GOAL]
R : Type u_1
inst✝⁴ : CommRing R
inst✝³ : IsArtinianRing R
S : Submonoid R
L : Type u_2
inst✝² : CommRing L
inst✝¹ : Algebra R L
inst✝ : IsLocalization S L
r₁ : R
s : { x // x ∈ S }
r₂ : R
h : IsLocalization.mk' L 1 s = ↑(algebraMap R L) r₂
⊢ ↑(algebraMap R L) (r₁ * r₂) = IsLocalization.mk' L r₁ s
[PROOFSTEP]
rw [IsLocalization.mk'_eq_mul_mk'_one, map_mul, h]
[GOAL]
R : Type u_1
inst✝⁴ : CommRing R
inst✝³ : IsArtinianRing R
S : Submonoid R
L : Type u_2
inst✝² : CommRing L
inst✝¹ : Algebra R L
inst✝ : IsLocalization S L
r₁ : R
s : { x // x ∈ S }
⊢ ∃ r, IsLocalization.mk' L 1 s = ↑(algebraMap R L) r
[PROOFSTEP]
obtain ⟨n, r, hr⟩ := IsArtinian.exists_pow_succ_smul_dvd (s : R) (1 : R)
[GOAL]
case intro.intro
R : Type u_1
inst✝⁴ : CommRing R
inst✝³ : IsArtinianRing R
S : Submonoid R
L : Type u_2
inst✝² : CommRing L
inst✝¹ : Algebra R L
inst✝ : IsLocalization S L
r₁ : R
s : { x // x ∈ S }
n : ℕ
r : R
hr : ↑s ^ Nat.succ n • r = ↑s ^ n • 1
⊢ ∃ r, IsLocalization.mk' L 1 s = ↑(algebraMap R L) r
[PROOFSTEP]
use r
[GOAL]
case h
R : Type u_1
inst✝⁴ : CommRing R
inst✝³ : IsArtinianRing R
S : Submonoid R
L : Type u_2
inst✝² : CommRing L
inst✝¹ : Algebra R L
inst✝ : IsLocalization S L
r₁ : R
s : { x // x ∈ S }
n : ℕ
r : R
hr : ↑s ^ Nat.succ n • r = ↑s ^ n • 1
⊢ IsLocalization.mk' L 1 s = ↑(algebraMap R L) r
[PROOFSTEP]
rw [smul_eq_mul, smul_eq_mul, pow_succ', mul_assoc] at hr
[GOAL]
case h
R : Type u_1
inst✝⁴ : CommRing R
inst✝³ : IsArtinianRing R
S : Submonoid R
L : Type u_2
inst✝² : CommRing L
inst✝¹ : Algebra R L
inst✝ : IsLocalization S L
r₁ : R
s : { x // x ∈ S }
n : ℕ
r : R
hr : ↑s ^ n * (↑s * r) = ↑s ^ n * 1
⊢ IsLocalization.mk' L 1 s = ↑(algebraMap R L) r
[PROOFSTEP]
apply_fun algebraMap R L at hr
[GOAL]
case h
R : Type u_1
inst✝⁴ : CommRing R
inst✝³ : IsArtinianRing R
S : Submonoid R
L : Type u_2
inst✝² : CommRing L
inst✝¹ : Algebra R L
inst✝ : IsLocalization S L
r₁ : R
s : { x // x ∈ S }
n : ℕ
r : R
hr : ↑(algebraMap R L) (↑s ^ n * (↑s * r)) = ↑(algebraMap R L) (↑s ^ n * 1)
⊢ IsLocalization.mk' L 1 s = ↑(algebraMap R L) r
[PROOFSTEP]
simp only [map_mul] at hr
[GOAL]
case h
R : Type u_1
inst✝⁴ : CommRing R
inst✝³ : IsArtinianRing R
S : Submonoid R
L : Type u_2
inst✝² : CommRing L
inst✝¹ : Algebra R L
inst✝ : IsLocalization S L
r₁ : R
s : { x // x ∈ S }
n : ℕ
r : R
hr :
↑(algebraMap R L) (↑s ^ n) * (↑(algebraMap R L) ↑s * ↑(algebraMap R L) r) =
↑(algebraMap R L) (↑s ^ n) * ↑(algebraMap R L) 1
⊢ IsLocalization.mk' L 1 s = ↑(algebraMap R L) r
[PROOFSTEP]
rw [← IsLocalization.mk'_one (M := S) L, IsLocalization.mk'_eq_iff_eq, mul_one, Submonoid.coe_one, ←
(IsLocalization.map_units L (s ^ n)).mul_left_cancel hr, map_mul]
|
(* Title: HOL/Auth/n_german_lemma_invs_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_german Protocol Case Study*}*)
theory n_german_lemma_invs_on_rules imports n_german_lemma_inv__1_on_rules n_german_lemma_inv__2_on_rules n_german_lemma_inv__3_on_rules n_german_lemma_inv__4_on_rules n_german_lemma_inv__5_on_rules n_german_lemma_inv__6_on_rules n_german_lemma_inv__7_on_rules n_german_lemma_inv__8_on_rules n_german_lemma_inv__9_on_rules n_german_lemma_inv__10_on_rules n_german_lemma_inv__11_on_rules n_german_lemma_inv__12_on_rules n_german_lemma_inv__13_on_rules n_german_lemma_inv__14_on_rules n_german_lemma_inv__15_on_rules n_german_lemma_inv__16_on_rules n_german_lemma_inv__17_on_rules n_german_lemma_inv__18_on_rules n_german_lemma_inv__19_on_rules n_german_lemma_inv__20_on_rules n_german_lemma_inv__21_on_rules n_german_lemma_inv__22_on_rules n_german_lemma_inv__23_on_rules n_german_lemma_inv__24_on_rules n_german_lemma_inv__25_on_rules n_german_lemma_inv__26_on_rules n_german_lemma_inv__27_on_rules n_german_lemma_inv__28_on_rules n_german_lemma_inv__29_on_rules n_german_lemma_inv__30_on_rules n_german_lemma_inv__31_on_rules n_german_lemma_inv__32_on_rules n_german_lemma_inv__33_on_rules n_german_lemma_inv__34_on_rules n_german_lemma_inv__35_on_rules n_german_lemma_inv__36_on_rules n_german_lemma_inv__37_on_rules n_german_lemma_inv__38_on_rules n_german_lemma_inv__39_on_rules n_german_lemma_inv__40_on_rules n_german_lemma_inv__41_on_rules n_german_lemma_inv__42_on_rules n_german_lemma_inv__43_on_rules n_german_lemma_inv__44_on_rules n_german_lemma_inv__45_on_rules n_german_lemma_inv__46_on_rules n_german_lemma_inv__47_on_rules n_german_lemma_inv__48_on_rules n_german_lemma_inv__49_on_rules n_german_lemma_inv__50_on_rules n_german_lemma_inv__51_on_rules n_german_lemma_inv__52_on_rules n_german_lemma_inv__53_on_rules n_german_lemma_inv__54_on_rules n_german_lemma_inv__55_on_rules n_german_lemma_inv__56_on_rules n_german_lemma_inv__57_on_rules n_german_lemma_inv__58_on_rules
begin
lemma invs_on_rules:
assumes a1: "f \<in> invariants N" and a2: "r \<in> rules N"
shows "invHoldForRule s f r (invariants N)"
proof -
have b1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__1 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__2 p__Inv0 p__Inv2)\<or>
(f=inv__3 )\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__4 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__5 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__6 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__7 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__8 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__9 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__10 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__11 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__12 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__13 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__14 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__15 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__16 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__17 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__18 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__19 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__20 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__21 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__22 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv1 p__Inv2. p__Inv0\<le>N\<and>p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv1\<and>p__Inv0~=p__Inv2\<and>p__Inv1~=p__Inv2\<and>f=inv__23 p__Inv0 p__Inv1 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__24 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__25 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__26 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__27 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__28 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__29 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__30 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__31 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__32 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__33 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__34 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__35 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__36 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__37 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__38 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__39 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__40 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__41 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__42 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__43 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__44 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__45 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__46 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__47 p__Inv2)\<or>
(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__48 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__49 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__50 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__52 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__53 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__54 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__55 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__56 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__57 p__Inv0 p__Inv2)\<or>
(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__58 p__Inv0 p__Inv2)"
apply (cut_tac a1, auto) done
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__1 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__1_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__2 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__2_on_rules) done
}
moreover {
assume c1: "(f=inv__3 )"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__3_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__4 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__4_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__5 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__5_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__6 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__6_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__7 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__7_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__8 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__8_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__9 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__9_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__10 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__10_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__11 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__11_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__12 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__12_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__13 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__13_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__14 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__14_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__15 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__15_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__16 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__16_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__17 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__17_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__18 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__18_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__19 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__19_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__20 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__20_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__21 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__21_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__22 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__22_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv1 p__Inv2. p__Inv0\<le>N\<and>p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv1\<and>p__Inv0~=p__Inv2\<and>p__Inv1~=p__Inv2\<and>f=inv__23 p__Inv0 p__Inv1 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__23_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__24 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__24_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__25 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__25_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__26 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__26_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__27 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__27_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__28 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__28_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__29 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__29_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__30 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__30_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__31 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__31_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__32 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__32_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__33 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__33_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__34 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__34_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__35 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__35_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__36 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__36_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__37 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__37_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__38 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__38_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__39 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__39_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__40 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__40_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__41 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__41_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__42 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__42_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__43 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__43_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__44 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__44_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__45 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__45_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__46 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__46_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__47 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__47_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__48 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__48_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__49 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__49_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__50 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__50_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__51_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__52 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__52_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__53 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__53_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__54 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__54_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__55 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__55_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__56 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__56_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__57 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__57_on_rules) done
}
moreover {
assume c1: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__58 p__Inv0 p__Inv2)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac a2 c1, metis lemma_inv__58_on_rules) done
}
ultimately show "invHoldForRule s f r (invariants N)"
by satx
qed
end
|
Basement Waterproofing Guys will be there for all of your needs concerning Waterproofing in Weston, FL. You want the most sophisticated modern technology in the field, and our crew of skilled professionals will offer that. We make sure that you receive the most excellent services, the most suitable selling price, and the finest materials. Call us today by dialing 800-244-0167 to start out.
At Basement Waterproofing Guys, we are aware that you have to stay in budget and lower your costs anywhere it's possible to. You'll still need to have top quality results on Waterproofing in Weston, FL, and you can depend on our staff to help you save money while still offering the finest quality work. We be sure our cash saving initiatives don't ever translate to a lesser standard of quality. Our ambition is to ensure you experience the finest products and a result that will last throughout the years. For example, we are watchful to steer clear of expensive complications, work quickly to conserve time, and make sure that you will get the top prices on products and labor. Connect with Basement Waterproofing Guys when you need the best solutions at the best price. You'll be able to connect with our business at 800-244-0167 to get started.
When it comes to Waterproofing in Weston, FL, you need to be knowledgeable to make the very best decisions. We won't encourage you to make ill advised choices, because we know what we're working at, and we ensure you know exactly what to expect from the task. This is exactly why we try to make every effort to make sure you learn the plan and are not confronted by any sort of unexpected surprises. The first step is to give us a call at 800-244-0167 to begin your job. We are going to reply to your questions and concerns and schedule your first appointment. Our staff can arrive at the arranged time with the required materials, and can work closely with you throughout the project.
Whenever you are setting up a task for Waterproofing in Weston, FL, you will find great reasons to work with Basement Waterproofing Guys. Our equipment are of the very best quality, our money saving techniques are helpful and powerful, and our customer care scores cannot be topped. We understand your expectations and objectives, and we're ready to assist you with our practical experience. When you require Waterproofing in Weston, get in touch with Basement Waterproofing Guys by dialing 800-244-0167, and we will be beyond pleased to help. |
I was in NYC last week and had THE BEST time. I had the rarity of lots of free time to myself, and I took advantage of it to explore everything. I'd start at 7AM with my Blue Bottle coffee and wear myself out walking (10-15 miles a day, one of my favorite things about New York) in preparation for my daily Shake Shack lunch. :) Blake met me for the weekend and we had a whirlwind 36 hours running around with friends, picking out wedding bands (!), drinking from flaming pineapples, eating pizza in the street at 2AM, and discovering the most insanely beautiful Japanese speakeasy. So much fun.
A few highlights above from moments when I remembered to take my camera out: the observatory at the "Top of the Rock" (such a touristy thing to do but one of my favorites, I love getting aerial views of cities, and the air was so crisp up there), mornings on the High Line, walking the Brooklyn Bridge, the new Whitney Museum, and of course lots of delicious tiki drinks at Maison Premiere. I'm already looking forward to my next trip! |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kevin Buzzard
-/
import data.rat
import data.fintype.card
import algebra.big_operators.nat_antidiagonal
import ring_theory.power_series.well_known
/-!
# Bernoulli numbers
The Bernoulli numbers are a sequence of rational numbers that frequently show up in
number theory.
## Mathematical overview
The Bernoulli numbers $(B_0, B_1, B_2, \ldots)=(1, -1/2, 1/6, 0, -1/30, \ldots)$ are
a sequence of rational numbers. They show up in the formula for the sums of $k$th
powers. They are related to the Taylor series expansions of $x/\tan(x)$ and
of $\coth(x)$, and also show up in the values that the Riemann Zeta function
takes both at both negative and positive integers (and hence in the
theory of modular forms). For example, if $1 \leq n$ is even then
$$\zeta(2n)=\sum_{t\geq1}t^{-2n}=(-1)^{n+1}\frac{(2\pi)^{2n}B_{2n}}{2(2n)!}.$$
Note however that this result is not yet formalised in Lean.
The Bernoulli numbers can be formally defined using the power series
$$\sum B_n\frac{t^n}{n!}=\frac{t}{1-e^{-t}}$$
although that happens to not be the definition in mathlib (this is an *implementation
detail* and need not concern the mathematician).
Note that $B_1=-1/2$, meaning that we are using the $B_n^-$ of
[from Wikipedia](https://en.wikipedia.org/wiki/Bernoulli_number).
## Implementation detail
The Bernoulli numbers are defined using well-founded induction, by the formula
$$B_n=1-\sum_{k\lt n}\frac{\binom{n}{k}}{n-k+1}B_k.$$
This formula is true for all $n$ and in particular $B_0=1$. Note that this is the definition
for positive Bernoulli numbers, which we call `bernoulli'`. The negative Bernoulli numbers are
then defined as `bernoulli := (-1)^n * bernoulli'`.
## Main theorems
`sum_bernoulli : ∑ k in finset.range n, (n.choose k : ℚ) * bernoulli k = 0`
-/
open_locale nat big_operators
open finset nat finset.nat power_series
variables (A : Type*) [comm_ring A] [algebra ℚ A]
/-! ### Definitions -/
/-- The Bernoulli numbers:
the $n$-th Bernoulli number $B_n$ is defined recursively via
$$B_n = 1 - \sum_{k < n} \binom{n}{k}\frac{B_k}{n+1-k}$$ -/
def bernoulli' : ℕ → ℚ :=
well_founded.fix lt_wf $
λ n bernoulli', 1 - ∑ k : fin n, n.choose k / (n - k + 1) * bernoulli' k k.2
lemma bernoulli'_def' (n : ℕ) :
bernoulli' n = 1 - ∑ k : fin n, n.choose k / (n - k + 1) * bernoulli' k :=
well_founded.fix_eq _ _ _
lemma bernoulli'_def (n : ℕ) :
bernoulli' n = 1 - ∑ k in range n, n.choose k / (n - k + 1) * bernoulli' k :=
by { rw [bernoulli'_def', ← fin.sum_univ_eq_sum_range], refl }
lemma bernoulli'_spec (n : ℕ) :
∑ k in range n.succ, (n.choose (n - k) : ℚ) / (n - k + 1) * bernoulli' k = 1 :=
begin
rw [sum_range_succ_comm, bernoulli'_def n, nat.sub_self],
conv in (n.choose (_ - _)) { rw choose_symm (mem_range.1 H).le },
simp only [one_mul, cast_one, sub_self, sub_add_cancel, choose_zero_right, zero_add, div_one],
end
lemma bernoulli'_spec' (n : ℕ) :
∑ k in antidiagonal n, ((k.1 + k.2).choose k.2 : ℚ) / (k.2 + 1) * bernoulli' k.1 = 1 :=
begin
refine ((sum_antidiagonal_eq_sum_range_succ_mk _ n).trans _).trans (bernoulli'_spec n),
refine sum_congr rfl (λ x hx, _),
simp only [nat.add_sub_cancel', mem_range_succ_iff.mp hx, cast_sub],
end
/-! ### Examples -/
section examples
@[simp] lemma bernoulli'_zero : bernoulli' 0 = 1 :=
by { rw bernoulli'_def, norm_num }
@[simp] lemma bernoulli'_one : bernoulli' 1 = 1/2 :=
by { rw bernoulli'_def, norm_num }
@[simp] lemma bernoulli'_two : bernoulli' 2 = 1/6 :=
by { rw bernoulli'_def, norm_num [sum_range_succ] }
@[simp] lemma bernoulli'_three : bernoulli' 3 = 0 :=
by { rw bernoulli'_def, norm_num [sum_range_succ] }
@[simp] lemma bernoulli'_four : bernoulli' 4 = -1/30 :=
have nat.choose 4 2 = 6 := dec_trivial, -- shrug
by { rw bernoulli'_def, norm_num [sum_range_succ, this] }
end examples
@[simp] lemma sum_bernoulli' (n : ℕ) :
∑ k in range n, (n.choose k : ℚ) * bernoulli' k = n :=
begin
cases n, { simp },
suffices : (n + 1 : ℚ) * ∑ k in range n, ↑(n.choose k) / (n - k + 1) * bernoulli' k =
∑ x in range n, ↑(n.succ.choose x) * bernoulli' x,
{ rw_mod_cast [sum_range_succ, bernoulli'_def, ← this, choose_succ_self_right], ring },
simp_rw [mul_sum, ← mul_assoc],
refine sum_congr rfl (λ k hk, _),
congr',
have : ((n - k : ℕ) : ℚ) + 1 ≠ 0 := by apply_mod_cast succ_ne_zero,
field_simp [← cast_sub (mem_range.1 hk).le, mul_comm],
rw_mod_cast [nat.sub_add_eq_add_sub (mem_range.1 hk).le, choose_mul_succ_eq],
end
/-- The exponential generating function for the Bernoulli numbers `bernoulli' n`. -/
def bernoulli'_power_series := mk $ λ n, algebra_map ℚ A (bernoulli' n / n!)
theorem bernoulli'_power_series_mul_exp_sub_one :
bernoulli'_power_series A * (exp A - 1) = X * exp A :=
begin
ext n,
-- constant coefficient is a special case
cases n, { simp },
rw [bernoulli'_power_series, coeff_mul, mul_comm X, sum_antidiagonal_succ'],
suffices : ∑ p in antidiagonal n, (bernoulli' p.1 / p.1!) * ((p.2 + 1) * p.2!)⁻¹ = n!⁻¹,
{ simpa [ring_hom.map_sum] using congr_arg (algebra_map ℚ A) this },
apply eq_inv_of_mul_left_eq_one,
rw sum_mul,
convert bernoulli'_spec' n using 1,
apply sum_congr rfl,
simp_rw [mem_antidiagonal],
rintro ⟨i, j⟩ rfl,
have : (j + 1 : ℚ) ≠ 0 := by exact_mod_cast succ_ne_zero j,
have : (j + 1 : ℚ) * j! * i! ≠ 0 := by simpa [factorial_ne_zero],
have := factorial_mul_factorial_dvd_factorial_add i j,
field_simp [mul_comm _ (bernoulli' i), mul_assoc, add_choose],
rw_mod_cast [mul_comm (j + 1), mul_div_assoc, ← mul_assoc],
rw [cast_mul, cast_mul, mul_div_mul_right, cast_dvd_char_zero, cast_mul],
assumption',
end
/-- Odd Bernoulli numbers (greater than 1) are zero. -/
theorem bernoulli'_odd_eq_zero {n : ℕ} (h_odd : odd n) (hlt : 1 < n) : bernoulli' n = 0 :=
begin
let B := mk (λ n, bernoulli' n / n!),
suffices : (B - eval_neg_hom B) * (exp ℚ - 1) = X * (exp ℚ - 1),
{ cases mul_eq_mul_right_iff.mp this;
simp only [power_series.ext_iff, eval_neg_hom, coeff_X] at h,
{ apply eq_zero_of_neg_eq,
specialize h n,
split_ifs at h;
simp [neg_one_pow_of_odd h_odd, factorial_ne_zero, *] at * },
{ simpa using h 1 } },
have h : B * (exp ℚ - 1) = X * exp ℚ,
{ simpa [bernoulli'_power_series] using bernoulli'_power_series_mul_exp_sub_one ℚ },
rw [sub_mul, h, mul_sub X, sub_right_inj, ← neg_sub, ← neg_mul_eq_mul_neg, neg_eq_iff_neg_eq],
suffices : eval_neg_hom (B * (exp ℚ - 1)) * exp ℚ = eval_neg_hom (X * exp ℚ) * exp ℚ,
{ simpa [mul_assoc, sub_mul, mul_comm (eval_neg_hom (exp ℚ)), exp_mul_exp_neg_eq_one, eq_comm] },
congr',
end
/-- The Bernoulli numbers are defined to be `bernoulli'` with a parity sign. -/
def bernoulli (n : ℕ) : ℚ := (-1)^n * bernoulli' n
lemma bernoulli'_eq_bernoulli (n : ℕ) : bernoulli' n = (-1)^n * bernoulli n :=
by simp [bernoulli, ← mul_assoc, ← sq, ← pow_mul, mul_comm n 2, pow_mul]
@[simp] lemma bernoulli_zero : bernoulli 0 = 1 := by simp [bernoulli]
@[simp] lemma bernoulli_one : bernoulli 1 = -1/2 :=
by norm_num [bernoulli]
theorem bernoulli_eq_bernoulli'_of_ne_one {n : ℕ} (hn : n ≠ 1) : bernoulli n = bernoulli' n :=
begin
by_cases h0 : n = 0, { simp [h0] },
rw [bernoulli, neg_one_pow_eq_pow_mod_two],
cases mod_two_eq_zero_or_one n, { simp [h] },
simp [bernoulli'_odd_eq_zero (odd_iff.mpr h) (one_lt_iff_ne_zero_and_ne_one.mpr ⟨h0, hn⟩)],
end
@[simp] theorem sum_bernoulli (n : ℕ):
∑ k in range n, (n.choose k : ℚ) * bernoulli k = if n = 1 then 1 else 0 :=
begin
cases n, { simp },
cases n, { simp },
suffices : ∑ i in range n, ↑((n + 2).choose (i + 2)) * bernoulli (i + 2) = n / 2,
{ simp only [this, sum_range_succ', cast_succ, bernoulli_one, bernoulli_zero, choose_one_right,
mul_one, choose_zero_right, cast_zero, if_false, zero_add, succ_succ_ne_one], ring },
have f := sum_bernoulli' n.succ.succ,
simp_rw [sum_range_succ', bernoulli'_one, choose_one_right, cast_succ, ← eq_sub_iff_add_eq] at f,
convert f,
{ ext x, rw bernoulli_eq_bernoulli'_of_ne_one (succ_ne_zero x ∘ succ.inj) },
{ simp only [one_div, mul_one, bernoulli'_zero, cast_one, choose_zero_right, add_sub_cancel],
ring },
end
lemma bernoulli_spec' (n : ℕ) :
∑ k in antidiagonal n, ((k.1 + k.2).choose k.2 : ℚ) / (k.2 + 1) * bernoulli k.1 =
if n = 0 then 1 else 0 :=
begin
cases n, { simp },
rw if_neg (succ_ne_zero _),
-- algebra facts
have h₁ : (1, n) ∈ antidiagonal n.succ := by simp [mem_antidiagonal, add_comm],
have h₂ : (n : ℚ) + 1 ≠ 0 := by apply_mod_cast succ_ne_zero,
have h₃ : (1 + n).choose n = n + 1 := by simp [add_comm],
-- key equation: the corresponding fact for `bernoulli'`
have H := bernoulli'_spec' n.succ,
-- massage it to match the structure of the goal, then convert piece by piece
rw sum_eq_add_sum_diff_singleton h₁ at H ⊢,
apply add_eq_of_eq_sub',
convert eq_sub_of_add_eq' H using 1,
{ refine sum_congr rfl (λ p h, _),
obtain ⟨h', h''⟩ : p ∈ _ ∧ p ≠ _ := by rwa [mem_sdiff, mem_singleton] at h,
simp [bernoulli_eq_bernoulli'_of_ne_one ((not_congr (antidiagonal_congr h' h₁)).mp h'')] },
{ field_simp [h₃],
norm_num },
end
/-- The exponential generating function for the Bernoulli numbers `bernoulli n`. -/
def bernoulli_power_series := mk $ λ n, algebra_map ℚ A (bernoulli n / n!)
theorem bernoulli_power_series_mul_exp_sub_one :
bernoulli_power_series A * (exp A - 1) = X :=
begin
ext n,
-- constant coefficient is a special case
cases n, { simp },
simp only [bernoulli_power_series, coeff_mul, coeff_X, sum_antidiagonal_succ', one_div, coeff_mk,
coeff_one, coeff_exp, linear_map.map_sub, factorial, if_pos, cast_succ, cast_one, cast_mul,
sub_zero, ring_hom.map_one, add_eq_zero_iff, if_false, inv_one, zero_add, one_ne_zero, mul_zero,
and_false, sub_self, ← ring_hom.map_mul, ← ring_hom.map_sum],
suffices : ∑ x in antidiagonal n, bernoulli x.1 / x.1! * ((x.2 + 1) * x.2!)⁻¹
= if n.succ = 1 then 1 else 0, { split_ifs; simp [h, this] },
cases n, { simp },
have hfact : ∀ m, (m! : ℚ) ≠ 0 := λ m, by exact_mod_cast factorial_ne_zero m,
have hite1 : ite (n.succ.succ = 1) 1 0 = (0 / n.succ! : ℚ) := by simp,
have hite2 : ite (n.succ = 0) 1 0 = (0 : ℚ) := by simp [succ_ne_zero],
rw [hite1, eq_div_iff (hfact n.succ), ← hite2, ← bernoulli_spec', sum_mul],
apply sum_congr rfl,
rintro ⟨i, j⟩ h,
rw mem_antidiagonal at h,
have hj : (j.succ : ℚ) ≠ 0 := by exact_mod_cast succ_ne_zero j,
field_simp [← h, mul_ne_zero hj (hfact j), hfact i, mul_comm _ (bernoulli i), mul_assoc],
rw_mod_cast [mul_comm (j + 1), mul_div_assoc, ← mul_assoc],
rw [cast_mul, cast_mul, mul_div_mul_right _ _ hj, add_choose, cast_dvd_char_zero],
apply factorial_mul_factorial_dvd_factorial_add,
end
section faulhaber
/-- Faulhaber's theorem relating the sum of of p-th powers to the Bernoulli numbers.
See https://proofwiki.org/wiki/Faulhaber%27s_Formula and [orosi2018faulhaber] for
the proof provided here. -/
theorem sum_range_pow (n p : ℕ) :
∑ k in range n, (k : ℚ) ^ p =
∑ i in range (p + 1), bernoulli i * (p + 1).choose i * n ^ (p + 1 - i) / (p + 1) :=
begin
have hne : ∀ m : ℕ, (m! : ℚ) ≠ 0 := λ m, by exact_mod_cast factorial_ne_zero m,
-- compute the Cauchy product of two power series
have h_cauchy : mk (λ p, bernoulli p / p!) * mk (λ q, coeff ℚ (q + 1) (exp ℚ ^ n))
= mk (λ p, ∑ i in range (p + 1),
bernoulli i * (p + 1).choose i * n ^ (p + 1 - i) / (p + 1)!),
{ ext q,
let f := λ a b, bernoulli a / a! * coeff ℚ (b + 1) (exp ℚ ^ n),
-- key step: use `power_series.coeff_mul` and then rewrite sums
simp only [coeff_mul, coeff_mk, cast_mul, sum_antidiagonal_eq_sum_range_succ f],
apply sum_congr rfl,
simp_intros m h only [finset.mem_range],
simp only [f, exp_pow_eq_rescale_exp, rescale, one_div, coeff_mk, ring_hom.coe_mk, coeff_exp,
ring_hom.id_apply, cast_mul, rat.algebra_map_rat_rat],
-- manipulate factorials and binomial coefficients
rw [choose_eq_factorial_div_factorial h.le, eq_comm, div_eq_iff (hne q.succ), succ_eq_add_one,
mul_assoc _ _ ↑q.succ!, mul_comm _ ↑q.succ!, ← mul_assoc, div_mul_eq_mul_div,
mul_comm (↑n ^ (q - m + 1)), ← mul_assoc _ _ (↑n ^ (q - m + 1)), ← one_div, mul_one_div,
div_div_eq_div_mul, ← nat.sub_add_comm (le_of_lt_succ h), cast_dvd, cast_mul],
{ ring },
{ exact factorial_mul_factorial_dvd_factorial h.le },
{ simp [hne] } },
-- same as our goal except we pull out `p!` for convenience
have hps : ∑ k in range n, ↑k ^ p
= (∑ i in range (p + 1), bernoulli i * (p + 1).choose i * n ^ (p + 1 - i) / (p + 1)!)
* p!,
{ suffices : mk (λ p, ∑ k in range n, ↑k ^ p * algebra_map ℚ ℚ p!⁻¹)
= mk (λ p, ∑ i in range (p + 1),
bernoulli i * (p + 1).choose i * n ^ (p + 1 - i) / (p + 1)!),
{ rw [← div_eq_iff (hne p), div_eq_mul_inv, sum_mul],
rw power_series.ext_iff at this,
simpa using this p },
-- the power series `exp ℚ - 1` is non-zero, a fact we need in order to use `mul_right_inj'`
have hexp : exp ℚ - 1 ≠ 0,
{ simp only [exp, power_series.ext_iff, ne, not_forall],
use 1,
simp },
have h_r : exp ℚ ^ n - 1 = X * mk (λ p, coeff ℚ (p + 1) (exp ℚ ^ n)),
{ have h_const : C ℚ (constant_coeff ℚ (exp ℚ ^ n)) = 1 := by simp,
rw [← h_const, sub_const_eq_X_mul_shift] },
-- key step: a chain of equalities of power series
rw [← mul_right_inj' hexp, mul_comm, ← exp_pow_sum, ← geom_sum_def, geom_sum_mul, h_r,
← bernoulli_power_series_mul_exp_sub_one, bernoulli_power_series, mul_right_comm],
simp [h_cauchy, mul_comm] },
-- massage `hps` into our goal
rw [hps, sum_mul],
refine sum_congr rfl (λ x hx, _),
field_simp [mul_right_comm _ ↑p!, ← mul_assoc _ _ ↑p!, cast_add_one_ne_zero, hne],
end
/-- Alternate form of Faulhaber's theorem, relating the sum of p-th powers to the Bernoulli numbers.
Deduced from `sum_range_pow`. -/
theorem sum_range_pow' (n p : ℕ) :
∑ k in Ico 1 (n + 1), (k : ℚ) ^ p =
∑ i in range (p + 1), bernoulli' i * (p + 1).choose i * n ^ (p + 1 - i) / (p + 1) :=
begin
-- dispose of the trivial case
cases p, { simp },
let f := λ i, bernoulli i * p.succ.succ.choose i * n ^ (p.succ.succ - i) / p.succ.succ,
let f' := λ i, bernoulli' i * p.succ.succ.choose i * n ^ (p.succ.succ - i) / p.succ.succ,
suffices : ∑ k in Ico 1 n.succ, ↑k ^ p.succ = ∑ i in range p.succ.succ, f' i, { convert this },
-- prove some algebraic facts that will make things easier for us later on
have hle := le_add_left 1 n,
have hne : (p + 1 + 1 : ℚ) ≠ 0 := by exact_mod_cast succ_ne_zero p.succ,
have h1 : ∀ r : ℚ, r * (p + 1 + 1) * n ^ p.succ / (p + 1 + 1 : ℚ) = r * n ^ p.succ :=
λ r, by rw [mul_div_right_comm, mul_div_cancel _ hne],
have h2 : f 1 + n ^ p.succ = 1 / 2 * n ^ p.succ,
{ simp_rw [f, bernoulli_one, choose_one_right, succ_sub_succ_eq_sub, cast_succ, nat.sub_zero, h1],
ring },
have : ∑ i in range p, bernoulli (i + 2) * (p + 2).choose (i + 2) * n ^ (p - i) / ↑(p + 2)
= ∑ i in range p, bernoulli' (i + 2) * (p + 2).choose (i + 2) * n ^ (p - i) / ↑(p + 2) :=
sum_congr rfl (λ i h, by rw bernoulli_eq_bernoulli'_of_ne_one (succ_succ_ne_one i)),
calc ∑ k in Ico 1 n.succ, ↑k ^ p.succ
-- replace sum over `Ico` with sum over `range` and simplify
= ∑ k in range n.succ, ↑k ^ p.succ : by simp [sum_Ico_eq_sub _ hle, succ_ne_zero]
-- extract the last term of the sum
... = ∑ k in range n, (k : ℚ) ^ p.succ + n ^ p.succ : by rw sum_range_succ
-- apply the key lemma, `sum_range_pow`
... = ∑ i in range p.succ.succ, f i + n ^ p.succ : by simp [f, sum_range_pow]
-- extract the first two terms of the sum
... = ∑ i in range p, f i.succ.succ + f 1 + f 0 + n ^ p.succ : by simp_rw [sum_range_succ']
... = ∑ i in range p, f i.succ.succ + (f 1 + n ^ p.succ) + f 0 : by ring
... = ∑ i in range p, f i.succ.succ + 1 / 2 * n ^ p.succ + f 0 : by rw h2
-- convert from `bernoulli` to `bernoulli'`
... = ∑ i in range p, f' i.succ.succ + f' 1 + f' 0 : by { simp only [f, f'], simpa [h1] }
-- rejoin the first two terms of the sum
... = ∑ i in range p.succ.succ, f' i : by simp_rw [sum_range_succ'],
end
end faulhaber
|
import time
import os
import numpy as np
import pandas as pd
from tqdm import tqdm
from datetime import datetime as dt
from py4jps.resources import JpsBaseLib
# Local KG location (fallback)
FALLBACK_KG = "http://localhost:9999/blazegraph/"
# Output location
OUTPUT_FOLDER = "/var/www/html/gas-grid"
# Maximum batch size for results
BATCH_SIZE = 50_000
# SPARQL query string
QUERY = """PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ns1: <http://www.theworldavatar.com/ontology/ontocape/upper_level/system.owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX gasgrid: <http://www.theworldavatar.com/ontology/ontogasgrid/gas_network_system.owl#>
PREFIX loc: <http://www.bigdata.com/rdf/geospatial/literals/v1#>
PREFIX geo: <http://www.bigdata.com/rdf/geospatial#>
PREFIX comp: <http://www.theworldavatar.com/ontology/ontogasgrid/gas_network_components.owl#>
SELECT ?location ?order ?label
WHERE
{
?pipe rdf:type gasgrid:GridPipeline.
?pipe rdfs:label ?label.
?pipe ns1:hasSubsystem ?segment.
?segment gasgrid:hasEndPart ?end.
?end gasgrid:entersPipeConnection ?connection.
?connection loc:lat-lon ?location.
?connection gasgrid:hasOrder ?order.
}"""
def initialiseGateway():
"""
Initialise the JPS Base Library
"""
jpsBaseLibGW = JpsBaseLib()
jpsBaseLibGW.launchGateway()
jpsBaseLibView = jpsBaseLibGW.createModuleView()
jpsBaseLibGW.importPackages(jpsBaseLibView, "uk.ac.cam.cares.jps.base.query.*")
return jpsBaseLibView.RemoteStoreClient(getKGLocation("ontogasgrid"))
def getKGLocation(namespace):
"""
Determines the correct URL for the KG's SPARQL endpoint.
Arguments:
namespace - KG namespace.
Returns:
Full URL for the KG.
"""
# Check for the KG_LOCATION environment variable, using local fallback
kgRoot = os.getenv('KG_LOCATION', FALLBACK_KG)
if kgRoot.endswith("/"):
return kgRoot + "namespace/" + namespace + "/sparql"
else:
return kgRoot + "/namespace/" + namespace + "/sparql"
def outputPipes():
"""
Queries the KG for data on pipes then outputs it
to a GeoJSON file.
"""
kgClient = initialiseGateway()
print("Using KG endpoint:", getKGLocation("ontogasgrid"))
gotAllResults = False
offset = 1
iteration = 1
totalResults = 0
result = []
# Run query in batches
while not gotAllResults:
print("INFO: Submitting request #" + str(iteration) + " at", dt.now())
print("INFO: Limit is " + str(BATCH_SIZE) + ", offset is " + str(offset))
finalQuery = QUERY + " LIMIT " + str(BATCH_SIZE) + " OFFSET " + str(offset)
batchResult = kgClient.executeQuery(finalQuery)
batchResult = batchResult.toList()
for singleResult in batchResult:
result.append(singleResult)
# Check if we have all results
if len(batchResult) < BATCH_SIZE:
gotAllResults = True
else:
if totalResults == 0:
offset += (BATCH_SIZE - 1)
else:
offset += BATCH_SIZE
iteration += 1
totalResults += len(batchResult)
num_ret = len(result)
ret_array = np.zeros((num_ret,4),dtype='object')
header = ['lat','lon','order','name']
for i in tqdm(range(num_ret)):
lat,lon = result[i]['location'].split('#')
ret_array[i,:] = [lat, lon, float(result[i]['order']), result[i]['label']]
result = pd.DataFrame(ret_array, columns=header)
unique_names = result['name'].unique() # name of all individual pipes
# Start of geoJSON file
geojson_file = """{
"type": "FeatureCollection",
"name": "pipe_network",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features":["""
for i in range(len(unique_names)):
# getting all coordinates for each unique pipe name
name = unique_names[i]
pipe = result.loc[result['name']==unique_names[i]].values
# sort pipe order
sort_index = np.argsort(pipe[:,2])
sorted_pipe = pipe[sort_index,:]
if len(sorted_pipe) != 1:
# start of geoJSON line
feature_start = """{ "type": "Feature", "properties": {"name": "%s" ,"stroke":"#000000"}, "geometry": { "type": "MultiLineString", "coordinates": [ [""" % name
# appending coordinates
for j in range(len(sort_index)):
feature_start += "["+sorted_pipe[j,1]+","+sorted_pipe[j,0]+"],"
# finishing line
feature_start = feature_start[:-1]
feature_start += "]]}},"
geojson_file += '\n'+feature_start
# Removing last comma in last line
geojson_file = geojson_file[:-1]
# EOF
end_geojson = """
]
}
"""
geojson_file += end_geojson
# Saving as geoJSON
try:
global OUTPUT_FOLDER
os.mkdir(OUTPUT_FOLDER)
except FileExistsError:
print('Directory already exists')
except:
OUTPUT_FOLDER = "."
print("Writing GeoJSON file...")
geojson_written = open(OUTPUT_FOLDER + '/pipe_network.geojson','w')
geojson_written.write(geojson_file)
geojson_written.close()
print("GeoJSON file written to:", OUTPUT_FOLDER + '/pipe_network.geojson')
# Entry point
outputPipes() |
! Get the code from [Bremer 2016] and run the following commands:
! make
! gfortran -O3 -c laguerre_quad_Adj.f90
! gfortran -O3 -o comparison explExpa.f90 utils.o chebyshev.o odesolve.o kummer.o laguerre_quad_Adj.o
! To run the timings into Timings.out: ./comparison
! To run the memory tests into the other *.out: ./comparison asdf
program explExpa
use kummer_laguerre_routines
double precision, parameter :: pi = acos(-1.d0)
double precision, allocatable :: x(:), w(:), xt(:), wt(:)
double precision :: alpha = 0.0
integer :: n = 100, mode = 1, ni
character(len=80) :: tmp
mode = command_argument_count()
if (mode == 0) then
! kummer only seems correct for alpha = 0
call testAll(0.0d0);
return
elseif (mode == 1) then
open(7, file='Ns.out')
call SYSTEM('echo " " > NbAlloc.out')
call SYSTEM('echo " " > BytesAlloc.out')
call SYSTEM('echo " " > MrssTime.out')
do ni = 1, 15
n = nint(exp( log(100*1.0)*(15 -ni)/(15 -1.0) + (ni-1.0)*log(10**9*1.0)/(15-1.0) ) )
do mode = 1,4
write (tmp, '(a, i10, a, i1, a)'), 'valgrind ./comparison ', n, ' 0.0 ', mode, ' 2> valg'
call SYSTEM(tmp)
call SYSTEM('grep -o -P "(?<=heap usage:).*(?=allocs,)" valg | tr -d ''\n'' | tr -d '','' >> NbAlloc.out')
call SYSTEM('grep -o -P "(?<=frees,).*(?=bytes al)" valg | tr -d ''\n'' | tr -d '','' >> BytesAlloc.out')
write (tmp, '(a, i10, a, i1, a)'), '/usr/bin/time -v ./comparison ', n, ' 0.0 ', mode, ' 2> ubtime'
call SYSTEM(tmp)
call SYSTEM('grep -Po "(?<=Maximum resident set size \(kbytes\):).*(?=)" ubtime | tr -d ''\n'' >> MrssTime.out')
enddo
call SYSTEM('echo " " >> NbAlloc.out')
call SYSTEM('echo " " >> BytesAlloc.out')
call SYSTEM('echo " " >> MrssTime.out')
write(7,*) n
enddo
close(7)
return
endif
call get_command_argument(1,tmp)
read(tmp, '(i10)' ) n
call get_command_argument(2,tmp)
read(tmp, '(f15.10)' ) alpha
call get_command_argument(3,tmp)
read(tmp, '(i10)' ) mode
if (mode == 1) then ! Compressed representation with bes(zer)
call laguerreExp(n, alpha, x, w, .true., .true., .true.)
else
allocate(x(n), w(n))
endif
if (mode == 2) then ! Uncompressed representation without bes(zer)
call laguerreExp(n, alpha, x, w, .false., .false., .false.)
elseif (mode == 3) then ! Uncompressed representation with bes(zer)
call laguerreExp(n, alpha, x, w, .true., .true., .false.)
elseif (mode == 4) then ! Nonoscillatory phase
call kummer_laguerre(n, alpha, x, w)
endif
! Use the result such that the compiler does not optimize out the computation
if (abs(sum(w)/GAMMA(alpha+1) -1) > 1e-8) then
print *, sum(w), "error", GAMMA(alpha+1), w(1:10)
endif
deallocate(x,w)
contains
subroutine testAll(alpha)
use kummer_laguerre_routines
implicit none
integer, parameter :: minN = 100, maxN = 10**9, nbRep = 5, lN = 15
integer :: ni, n, nTest, t1, t2, clm, dNt(8), rate, ns(lN), mode, row, whTim
double precision, allocatable :: xn(:), wn(:), xe(:), we(:), xcpr(:), wcpr(:)
double precision :: alpha, ers(lN,12)
real :: ts, tm, te, td, tarr(2), elTimes(lN,nbRep,4,4), start, prevToc = 0.0
elTimes = -1.d0
ers = -1.d0
ns = (/ (nint(exp( log(minN*1.0d0)*((lN -ni)/(lN -1.0d0)) + &
log(maxN*1.0d0)*((ni-1.0d0)/(lN-1.0d0)) ) ), ni=1,lN) /)
do ni =1,lN
n = ns(ni)
allocate(xn(n), wn(n), xe(n), we(n))
do mode = 1, 4
do nTest = 1, nbRep
call etime(tarr, ts)
call cpu_time(td)
call date_and_time(values=dNt)
start = 0.001d0*dNt(8) + dNt(7) + 60*(dNt(6) + 60*(dNt(5) + 24*dNt(3) ))
call system_clock(t1, rate, clm)
if (mode == 1) then ! Compressed representation with bes(zer)
call laguerreExp(n, alpha, xcpr, wcpr, .true., .true., .true.)
deallocate(xcpr, wcpr)
end if
if (mode == 2) then ! Uncompressed representation without bes(zer)
call laguerreExp(n, alpha, xe, we, .false., .false., .false.)
elseif (mode == 3) then ! Uncompressed representation with bes(zer)
call laguerreExp(n, alpha, xe, we, .true., .true., .false.)
elseif (mode == 4) then ! Nonoscillatory phase
call kummer_laguerre(n, alpha, xn, wn)
endif
call etime(tarr, tm)
elTimes(ni,nTest,1, mode) = tm-ts
call date_and_time(values=dNt)
elTimes(ni,nTest,2, mode) = 0.001d0*dNt(8) + dNt(7) + 60*(dNt(6) + 60*(dNt(5) + 24*dNt(3) )) - start
call cpu_time(te)
elTimes(ni,nTest,3, mode) = te-td
call system_clock(t2, rate, clm)
elTimes(ni,nTest,4, mode) = (t2 -t1 +0.0)/rate
if (tm - prevToc > 3.0) then ! print progress info every three seconds
print '(i2,a,i1,a, i2, a, es12.3, a, es12.3, a)', ni, "=ni, mode=", mode, ", nTest=", nTest, ", etime=", tm, &
", ", tm*(sum(ns)*4.0*nbRep/( sum(ns(1:ni-1))*4.0*nbRep +n*(mode-1.0)*nbRep +n*nTest) -1.0)/3600.0, " hr left."
prevToc = tm
endif
enddo
enddo
! xe and we are now the last simulations (ntest=nbRep) with the uncompressed representation with computation of Bessel function and zeros (mode = 3)
nTest = floor(0.9*n)-1
ers(ni,1) = norm2(xn -xe)/norm2(xn)
ers(ni,2) = norm2(wn -we)/norm2(wn)
ers(ni,3) = norm2((xn -xe)/xn)
ers(ni,4) = norm2((wn -we)/wn)
ers(ni,5) = norm2(xn -xe)
ers(ni,6) = norm2(wn -we)
ers(ni,7) = norm2(xn(1:nTest) -xe(1:nTest))/norm2(xn(1:nTest))
ers(ni,8) = norm2(wn(1:nTest) -we(1:nTest))/norm2(wn(1:nTest))
ers(ni,9) = norm2((xn(1:nTest) -xe(1:nTest))/xn(1:nTest))
ers(ni,10) = norm2((wn(1:nTest) -we(1:nTest))/wn(1:nTest))
ers(ni,11) = norm2(xn(1:nTest) -xe(1:nTest))
ers(ni,12) = norm2(wn(1:nTest) -we(1:nTest))
deallocate(xn, wn, xe, we)
open(8, file="Timings.out")
write(8, *), ns, "=ns, elTimes = "
do mode =1,size(elTimes,4)
do whTim =1,size(elTimes,3)
write(8,*), "Mode", mode, " time nr ", whTim, " = "
do row = 1,size(elTimes,1)
write (8,*), elTimes(row,:,whTim,mode)
enddo
enddo
enddo
write (8, *), ", ers = "
do row = 1,size(ers,1)
write (8,*), ers(row,:)
enddo
close(8)
end do
end subroutine
subroutine laguerreExp(n, alpha, x, w, compZer, compBes, compRepr)
implicit none
integer :: n, T, ibes, iair, it, k, mn, mxb
double precision :: alpha, d, pt, term, co, so, cf, zeta, prev, jta
double precision, parameter :: ak(11) = (/ -13.69148903521072d0, &
-12.828776752865757d0, -11.93601556323626d0, -11.00852430373326d0, &
-10.04017434155809d0, -9.02265085340981d0, -7.944133587120853d0, &
-6.786708090071759d0, -5.520559828095551d0, -4.08794944413097d0, &
-2.338107410459767d0 /) ! First 11 roots of the Airy function in reverse order
double precision, parameter :: dak(10) = (/ &
-1.0677938592d0, 1.0487206486d0, -1.0277386888d0, &
1.0043701227d0, -0.9779228086d0, 0.9473357094d0, &
-0.9108507370d0, 0.8652040259d0, -0.8031113697d0, &
0.7012108227d0 /) ! Derivatives at first 11 roots of the Airy function in reverse order [DLMF tab 9.9.1]
double precision, allocatable :: x(:), w(:)
logical compZer, compBes, compRepr
double precision mu, b, a1, a3, a5, a7, a9, a11, a13, TT(30)
double precision, parameter :: tab(20) = (/ 2.4048255576957728d0, &
5.5200781102863106d0, 8.6537279129110122d0, 11.791534439014281d0, &
14.930917708487785d0, 18.071063967910922d0, 21.211636629879258d0, &
24.352471530749302d0, 27.493479132040254d0, 30.634606468431975d0, &
33.775820213573568d0, 36.917098353664044d0, 40.058425764628239d0, &
43.199791713176730d0, 46.341188371661814d0, 49.482609897397817d0, &
52.624051841114996d0, 55.765510755019979d0, 58.906983926080942d0, &
62.048469190227170d0 /) ! First 20 roots of J0(x) are precomputed (using Wolfram Alpha)
double precision, parameter :: C(6,30) = reshape( &
(/2.883975316228d0, 8.263194332307d0, 11.493871452173d0, 14.689036505931d0, &
17.866882871378d0, 21.034784308088d0, &
0.767665211539d0, 4.209200330779d0, 4.317988625384d0, 4.387437455306d0, &
4.435717974422d0, 4.471319438161d0, &
-0.086538804759d0, -0.164644722483d0, -0.130667664397d0, -0.109469595763d0, &
-0.094492317231d0, -0.083234240394d0, &
0.020433979038d0, 0.039764618826d0, 0.023009510531d0, 0.015359574754d0, &
0.011070071951d0, 0.008388073020d0, &
-0.006103761347d0, -0.011799527177d0, -0.004987164201d0, -0.002655024938d0, &
-0.001598668225d0, -0.001042443435d0, &
0.002046841322d0, 0.003893555229d0, 0.001204453026d0, 0.000511852711d0, &
0.000257620149d0, 0.000144611721d0, &
-0.000734476579d0, -0.001369989689d0, -0.000310786051d0, -0.000105522473d0, &
-0.000044416219d0, -0.000021469973d0, &
0.000275336751d0, 0.000503054700d0, 0.000083834770d0, 0.000022761626d0, &
0.000008016197d0, 0.000003337753d0, &
-0.000106375704d0, -0.000190381770d0, -0.000023343325d0, -0.000005071979d0, &
-0.000001495224d0, -0.000000536428d0, &
0.000042003336d0, 0.000073681222d0, 0.000006655551d0, 0.000001158094d0, &
0.000000285903d0, 0.000000088402d0, &
-0.000016858623d0, -0.000029010830d0, -0.000001932603d0, -0.000000269480d0, &
-0.000000055734d0, -0.000000014856d0, &
0.000006852440d0, 0.000011579131d0, 0.000000569367d0, 0.000000063657d0, &
0.000000011033d0, 0.000000002536d0, &
-0.000002813300d0, -0.000004672877d0, -0.000000169722d0, -0.000000015222d0, &
-0.000000002212d0, -0.000000000438d0, &
0.000001164419d0, 0.000001903082d0, 0.000000051084d0, 0.000000003677d0, &
0.000000000448d0, 0.000000000077d0, &
-0.000000485189d0, -0.000000781030d0, -0.000000015501d0, -0.000000000896d0, &
-0.000000000092d0, -0.000000000014d0, &
0.000000203309d0, 0.000000322648d0, 0.000000004736d0, 0.000000000220d0, &
0.000000000019d0, 0.000000000002d0, &
-0.000000085602d0, -0.000000134047d0, -0.000000001456d0, -0.000000000054d0, &
-0.000000000004d0, 0.d0, &
0.000000036192d0, 0.000000055969d0, 0.000000000450d0, 0.000000000013d0, &
0.d0, 0.d0, &
-0.000000015357d0, -0.000000023472d0, -0.000000000140d0, -0.000000000003d0, &
0.d0, 0.d0, &
0.000000006537d0, 0.000000009882d0, 0.000000000043d0, 0.000000000001d0, &
0.d0, 0.d0, &
-0.000000002791d0, -0.000000004175d0, -0.000000000014d0, 0.d0, 0.d0, 0.d0, &
0.000000001194d0, 0.000000001770d0, 0.000000000004d0, 0.d0, 0.d0, 0.d0, &
-0.000000000512d0, -0.000000000752d0, 0.d0, 0.d0, 0.d0, 0.d0, &
0.000000000220d0, 0.000000000321d0, 0.d0, 0.d0, 0.d0, 0.d0, &
-0.000000000095d0, -0.000000000137d0, 0.d0, 0.d0, 0.d0, 0.d0, &
0.000000000041d0, 0.000000000059d0, 0.d0, 0.d0, 0.d0, 0.d0, &
-0.000000000018d0, -0.000000000025d0, 0.d0, 0.d0, 0.d0, 0.d0, &
0.000000000008d0, 0.000000000011d0, 0.d0, 0.d0, 0.d0, 0.d0, &
-0.000000000003d0, -0.000000000005d0, 0.d0, 0.d0, 0.d0, 0.d0, &
0.000000000001d0, 0.000000000002d0, 0.d0, 0.d0, 0.d0, 0.d0 /), &
(/ 6, 30 /) )
! McMahon's expansion. This expansion gives very accurate approximation
! for the k-th zero (k >= 7) for extreme nu, and moderate approximation
! in other cases for low k or medium-sized Bessel parameters.
mu = 4*alpha**2
a1 = 1.d0/8
a3 = (7*mu-31)/384
a5 = 4*(3779 +mu*(-982 +83*mu))/61440
a7 = 6*(-6277237 +mu*(1585743 +mu*(-153855 +6949*mu)))/20643840;
a9 = 144*(2092163573 +mu*(-512062548 +mu*(48010494 +mu*(-2479316 + &
70197*mu)) )) / 11890851840.d0
a11 = 720.d0*(-8249725736393.d0 +mu*(1982611456181.d0 +mu*(-179289628602.d0 &
+mu*(8903961290.d0 +mu*(-287149133.d0 +5592657.d0*mu) ) ) ) ) / 10463949619200.d0
a13 = (576.d0*(423748443625564327.d0 + mu*(-100847472093088506.d0 &
+mu*(8929489333108377.d0 + mu*(-426353946885548.d0 +mu*(13172003634537.d0 &
+mu*(-291245357370.d0 + mu*4148944183.d0))) ))) / 13059009124761600.d0)
if (compRepr) then
mn = min(nint(17*sqrt(n*1.0d0)), n)
allocate(x(mn), w(mn))
else
mn = n
endif
! This is a heuristic for the number of terms in the expansions that follow.
T = ceiling(34/log(n+0.0) )
d = 1/(4*n+2*alpha+2)
ibes = max(ceiling(sqrt(n*1.0) ), 7)
! Heuristics to switch between Bessel, bulk and Airy initial.
iair = floor(0.9*n)
mxb = min(mn, iair-1)
!print *, ibes, iair, "=iair, mxb=", mxb
if (compBes) then
b = (alpha-2)/3
TT(1) = 1.d0
TT(2) = b
do k = 2,29
TT(k+1) = 2*b*TT(k) - TT(k-1)
enddo
endif
jta = 1.0d0
x = 0.d0
w = 0.d0
do k=1,ibes !Bessel region
! Roots of the function J_v(x) from chebfun by L. L. Peixoto, 2015, later modified by A. Townsend to work in Julia
if ((compBes) .and. (alpha .eq. 0.d0) .and. (k < 21)) then
jta = tab(k)
elseif ((compBes) .and. (alpha < 5) .and. (k < 7)) then
! Piessens's Chebyshev series approximations (1984). Calculates the 6 first
! zeros to at least 12 decimal figures in region -1 <= V <= 5:
jta = dot_product(C(k,:),TT)
if (k == 1) then
jta = jta*sqrt(alpha+1) ! Scale the first root.
endif
elseif (compBes) then
b = 0.25d0*(2*alpha+4*k-1)*pi
! Evaluate using Horner's scheme: Possibly inaccurate results
jta = (((a13/b**2 + a11)/b**2 + a9)/b**2 + a7)/b**2 + a5
jta = b - (mu-1)*( ((jta/b**2 + a3)/b**2 + a1)/b)
endif
!Computed j_{alpha,k}, now add higher order terms
if (T >= 7) then
! These higher order terms in the left and bulk region are derived in [Huybrechs and Opsomer 2018, in preparation]
x(k) = x(k) + (657*jta**6 +36*jta**4*( &
73*alpha**2-181) +2*jta**2*(2459*alpha**4 -10750*alpha**2 &
+14051) + 4*(1493*alpha**6 -9303*alpha**4 +19887*alpha**2 - 12077))*d**6/2835
w(k) = w(k) + (11944*alpha**6 + 5256*jta**6 &
- (5061*alpha**5 + 5085*alpha**4 + 4830*alpha**3 -22724*alpha**2 -22932*alpha &
+ 39164)*jta**4 - 74424*alpha**4 + 8*(2459*alpha**4 -10750*alpha**2 &
+ 14051)*jta**2 + 159096*alpha**2 - 96616)/2835/2*d**6
endif
if (T >= 5) then
x(k) = x(k) + (11*jta**4 +3*jta**2*( &
11*alpha**2-19) +46*alpha**4 -140*alpha**2 +94)*d**4/45
w(k) = w(k) + (46*alpha**4 + 33*jta**4 &
+6*jta**2*(11*alpha**2 -19) -140*alpha**2 +94)/45*d**4
endif
if (T >= 3) then
x(k) = x(k) + (jta**2 + 2*alpha**2 - 2)*d**2/3
w(k) = w(k) + (alpha**2 + jta**2 -1)*2/3*d**2
endif
x(k) = jta**2*d*(1 + x(k))
if ((compBes) .and. (k < 6+10*alpha**2/pi)) then
! j_{alpha,k} \sim k*pi + O(k^0) with j_{alpha,k} > (alpha+1)^2
pt = 1/GAMMA(alpha+2)
term = pt
prev = pt*jta**2/(alpha+2)
do it = 1, 100
term = -term*jta**2/4/it/(alpha+it+1)
if (abs(term) < abs(pt)*10.d0**(-12) ) then
! Stop when no significant increase any more
exit
endif
pt = term + pt
prev = term
enddo
! Computed J_{alpha+1}(j_{alpha,k}) but = -J_{alpha-1} and square
w(k)=4*d*x(k)**alpha*exp(-x(k))/(pt*(jta/2)**(alpha+1))**2*(1+w(k))
elseif (compBes) then
! Approximate J_{\alpha-1}(j_{\alpha,k}) for large arguments
pt = 0.d0
co = cos(jta -(alpha-1)*pi/2 -pi/4)
so = sin(jta -(alpha-1)*pi/2 -pi/4)
cf = 1.d0
prev = 2.0d0
do it = 0, 50
term = co*(-1)**it*cf
cf = cf*(4*(alpha-1)**2 -(4*it +1)**2)/(2*it +1)/8/jta
term = term - so*(-1)**it*cf
if ((abs(term) + abs(prev) < abs(pt)*10.d0**(-12) ) .or. &
(abs(term) > abs(prev))) then
! Stop when no significant increase any more taking into account [1; 0; 0.5; 0; 0.25 ...], or when the series starts diverging
exit
endif
pt = term + pt
prev = term
cf = cf*(4*(alpha-1)**2 -(4*it +3)**2)/(2*it+2)/8/jta
enddo
w(k) = 2*d*x(k)**alpha*exp(-x(k))/pt**2*jta*pi*(1+w(k))
else
w(k) = 4*d*x(k)**alpha*exp(-x(k))*(1+w(k))
endif
enddo ! End loop bessel region
do k=ibes+1,mxb !Loop lens
if (compBes) then
pt = (4*n -4*k +3)*d
jta = pi**2/16*(pt -1)**2 ! This t is not a very good initial approximation of the inverse function of f(y) = (4*n -4*k +3)*d*pi +2*sqrt(y)*sqrt(1-y) -acos(2*y-1); but better approximations are much more time-consuming
do it = 1,6
jta = jta - (pt*pi +2*sqrt(jta -jta**2) -acos(2*jta -1) )*sqrt(jta/(1-jta))/2
end do
endif
if (T >= 7) then
! These higher order terms in the left and bulk region are derived in [Huybrechs and Opsomer 2018, in preparation]
x(k) = x(k) -d**5/181440*(9216*(21*alpha**6 &
- 105*alpha**4 + 147*alpha**2 - 31)*jta**10 &
-69120*(21*alpha**6 - 105*alpha**4 + 147*alpha**2 - 31)*jta**9 &
+384*(12285*alpha**6 -61320*alpha**4 +85785*alpha**2 &
-18086)*jta**8 - 64*(136080*alpha**6 - 675675*alpha**4 &
+943110*alpha**2 - 198743)*jta**7 &
+ 144*(70560*alpha**6 - 345765*alpha**4 +479850*alpha**2 &
- 101293)*jta**6 + 72576*alpha**6 - (8128512*alpha**6 &
- 38656800*alpha**4+ 52928064*alpha**2 - 13067711)*jta**5 &
+ 5*(1016064*alpha**6 - 4581360*alpha**4 +6114528*alpha**2 &
+ 113401)*jta**4 - 317520*alpha**4 - 10*(290304*alpha**6 &
-1245888*alpha**4 + 1620864*alpha**2 - 528065)*jta**3 &
+ 5*(290304*alpha**6 -1234800*alpha**4 + 1598688*alpha**2 &
- 327031)*jta**2 + 417312*alpha**2 -5*(96768*alpha**6 &
- 417312*alpha**4 + 544320*alpha**2 - 111509)*jta &
-85616)/(jta-1)**8/jta**2
w(k) = w(k) + d**6/362880*(9216*(21*alpha**6 &
- 105*alpha**4 + 147*alpha**2 - 31)*jta**10 &
-1536*(945*alpha**6-4830*alpha**4 +6825*alpha**2 -1444)*jta**9 &
+ 384*(11340*alpha**6 -60165*alpha**4 + 86310*alpha**2 &
- 18289)*jta**8 - 2*(2903040*alpha**6 - 17055360*alpha**4 &
+ 25401600*alpha**2 - 5*alpha - 5252997)*jta**7 &
- (11753280*alpha**4 - 23506560*alpha**2+ 67*alpha &
- 13987519)*jta**6 - 290304*alpha**6 + 12*(1016064*alpha**6 &
-3578400*alpha**4 +4108608*alpha**2 +16*alpha +7100871)*jta**5 &
- 5*(4064256*alpha**6 -16559424*alpha**4 + 20926080*alpha**2 + 61*alpha &
- 15239393)*jta**4 + 1270080*alpha**4 +10*(1741824*alpha**6 &
-7386624*alpha**4 +9547776*alpha**2 +29*alpha -1560107)*jta**3 &
- 15*(580608*alpha**6 - 2503872*alpha**4 + 3265920*alpha**2 + 11*alpha &
- 669051)*jta**2- 1669248*alpha**2 + 4*(604800*alpha**6 &
- 2630880*alpha**4 + 3447360*alpha**2 + 13*alpha- 706850)*jta &
- 7*alpha + 342463)/(jta -1)**9/jta**3
endif
if (T >= 5) then
x(k) = x(k) - d**3/720*(32*(15*alpha**4 &
- 30*alpha**2 + 7)*jta**6 -144*(15*alpha**4 - 30*alpha**2 &
+ 7)*jta**5 + 16*(225*alpha**4 - 450*alpha**2 &
+104)*jta**4 - 240*alpha**4 - 480*(5*alpha**4 - 10*alpha**2 &
+ 1)*jta**3 + 480*alpha**2 +45*(16*alpha**4 - 32*alpha**2 &
+ 7)*jta +990*jta**2 -105)/(jta &
-1)**5/jta
w(k) = w(k) + d**4/720*(16*(15*alpha**4 &
- 30*alpha**2 + 7)*jta**6 - 32*(45*alpha**4 - 90*alpha**2 &
+22)*jta**5 + 48*(75*alpha**4 - 150*alpha**2 + &
74)*jta**4 + 240*alpha**4 - 600*(8*alpha**4- 16*alpha**2 &
- 5)*jta**3 + 45*(80*alpha**4 - 160*alpha**2 + &
57)*jta**2 - 480*alpha**2 -90*(16*alpha**4 - 32*alpha**2 &
+ 7)*jta + 105)/(jta -1)**6/jta**2
endif
if (T >= 3) then
x(k) = x(k) - d/12*(4*(3*alpha**2 &
-1)*jta**2 +12*alpha**2 -12*(2*alpha**2 -1)*jta - 3)/(jta-1)**2
w(k) = w(k) + d**2/6*(2*jta + 3)/(jta-1)**3
endif
x(k) = x(k) + jta/d;
w(k) = x(k)**alpha*exp(-x(k) )*2*pi*sqrt(jta/(1-jta))*(1 +w(k))
enddo !Loop lens
do k =iair,mn !Loop Airy
if ((compBes) .and. (k < n - 10)) then
pt = 3*pi/2*( n -k +0.75d0) ! [DLMF (9.9.6)]
jta = -pt**(2.d0/3)*(1 + 5/48.d0/pt**2 - 5/36.d0/pt**4 + &
77125/82944.d0/pt**6 -10856875/6967296.d0/pt**8)
elseif (compBes) then
jta = ak(k -n +11)
endif
! For the Airy region, only O(n**{-4}) relative error for x and O(n**{-2/3}) for w as the latter are extremely small or even underflow
if (T >= 5) then
x(k) = x(k) -(15152.d0/3031875*jta**5 &
+1088.d0/121275*jta**2)*2**(1.d0/3)*d**(7.0d0/3) ! [Gatteshi 2002 (4.9)], Gives an O(n**{-4}) relative error
endif
if (T >= 3) then
x(k) = x(k) + jta**2*(d*16)**(1.d0/3)/5 &
+ (11.d0/35 -alpha**2 -12.d0/175*jta**3)*d + (16.d0/1575*jta &
+ 92.d0/7875*jta**4)*2**(2.d0/3)*d**(5.0d0/3)
endif
x(k) = x(k) + 1/d +jta*(d/4)**(-1.d0/3)
if ((compBes) .and. (k <= n-10)) then
zeta = -2*jta*sqrt(-jta)/3 ! = zeta in [DLMF 9.7.10]
co = cos(zeta -pi/4)
so = sin(zeta -pi/4)
! Asymptotic expansion of Airy(z) = exp(-zeta)/2/sqrt(pi)/z^(1/4) sum_{n=0}^\infty (-1)^n Gamma(n+5/6) Gamma(n+1/6) (3/4)^n /2/pi/ n!/z^(3n/2) but for pos z and
! (6*k+1)/(1-6*k)/216^k/factorial(k)*product (2*j+1) for j in range(k,3*k-1) = -(2^(-5 k) 27^(-k) (6 k + 1) Γ(6 k - 1))/(Γ(2 k) Γ(k + 1))
pt = 0.d0
cf = 1.d0 ! = GAMMA(5.d0/6)*GAMMA(7.d0/6)*3/pi
prev = 2.0d0
do it = 0, 50
term = so*cf/(1-12*it)*(-1)**it
cf = cf*(2*it +5.d0/6)*(2*it+7.d0/6)/2/(2*it+1)/zeta
term = term - co*cf/(1-6*(2*it+1))*(-1)**it
cf = cf*(2*it +11.d0/6)*(2*it+13.d0/6)/2/(2*it+2)/zeta
if ((abs(term) + abs(prev) < abs(pt)*10.d0**(-12) ) .or. (abs(term) > abs(prev))) then
! Stop when no significant increase any more taking into account [1; 0; 0.5; 0; 0.25 ...], or when the series starts diverging
exit
endif
pt = pt + term
prev = term
enddo
w(k) = 4**(1.d0/3)*x(k)**(alpha +1.d0/3)*exp(-x(k) )/( pt**2*sqrt(-jta)/pi )
elseif (compBes) then
! Could also use a series expansion of the Airy function as Ai"(z)=z Ai(z)
w(k) = 4**(1.d0/3)*x(k)**(alpha+1.d0/3)*exp(-x(k))/(dak(k-n+10))**2
else
w(k) = 4**(1.d0/3)*x(k)**(alpha+1.d0/3)*exp(-x(k))
endif
enddo !Loop Airy
if (((minval(x) < 0.d0) .or. (maxval(x) > 4*n +2*alpha +2) .or. &
(minval(w) < 0.d0)) .and. compBes) then
print *, "Wrong node or weight."
endif
end subroutine
end program
|
Formal statement is: lemma tendsto_at_iff_sequentially: "(f \<longlongrightarrow> a) (at x within s) \<longleftrightarrow> (\<forall>X. (\<forall>i. X i \<in> s - {x}) \<longrightarrow> X \<longlonglongrightarrow> x \<longrightarrow> ((f \<circ> X) \<longlonglongrightarrow> a))" for f :: "'a::first_countable_topology \<Rightarrow> _" Informal statement is: A function $f$ tends to $a$ at $x$ within $s$ if and only if for every sequence $X$ that converges to $x$ and is contained in $s - \{x\}$, the sequence $f \circ X$ converges to $a$. |
p_1 = createmodel(:CapitalAdjustModel; nK = 40, nz = 11, γ = 2., intdim = :Separable)
sol_1_prebuild = solve(p_1; rewardcall=:pre)
sol_1_prebuild_partial = solve(p_1; rewardcall=:pre_partial)
sol_1_nobuild = solve(p_1; rewardcall=:jit)
p_2 = createmodel(:CapitalAdjustModel2; nK = 15, nN = 10, nz = 3, intdim=:Separable_ExogStates,)
diopt = Dict(:concavity => [true,true], :monotonicity => [true,true])
sol_2_prebuild = solve(p_2; diopt..., rewardcall=:pre)
sol_2_prebuild_partial = solve(p_2; diopt..., rewardcall=:pre_partial)
sol_2_nobuild = solve(p_2; diopt..., rewardcall=:jit)
sol_1_nobuild
@testset "reward matrix options" begin
@testset "SingleChoiceVar" begin
@test isapprox(sol_1_nobuild, sol_1_prebuild_partial, rtol=mytol)
@test isapprox(sol_1_nobuild, sol_1_prebuild, rtol=mytol)
@test isapprox(sol_1_prebuild, sol_1_prebuild_partial, rtol=mytol)
end
@testset "TwoChoiceVar" begin
@test isapprox(sol_2_nobuild, sol_2_prebuild_partial, rtol=mytol)
@test isapprox(sol_2_nobuild, sol_2_prebuild, rtol=mytol)
@test isapprox(sol_2_prebuild, sol_2_prebuild_partial, rtol=mytol)
end
end
|
#include <boost/dll.hpp>
#include <filesystem>
#include <sstream>
#include "fundot/fundot.h"
namespace fundot {
class Evaluator::Impl {
public:
template<class T>
Object* getFromPair(T& owner, const Object& index);
Object* get(Vector& owner, const Integer& integer);
Object* get(Vector& owner, const Object& index);
Object* get(UnorderedSet& owner, const Object& index);
Object* get(List& owner, const Integer& integer);
Object* get(List& owner, const Object& index);
Object* get(Object& owner, const Getter& getter);
Object* get(Object& owner, const Object& index);
template<class T>
void setPair(T& owner, const Object& index, const Object& value);
void set(Vector& owner, const Integer& integer, const Object& value);
void set(Vector& owner, const Object& index, const Object& value);
void set(UnorderedSet& owner, const Object& index, const Object& value);
void set(List& owner, const Integer& index, const Object& value);
void set(List& owner, const Object& index, const Object& value);
void set(Object& owner, const Getter& index, const Object& value);
void set(Object& owner, const Object& index, const Object& value);
Object cond_(const List& list);
Object eval_(const List& list);
Object global_();
Object if_(const List& list);
Object import_(const List& list);
Object let_(const List& list);
Object local_();
Object locate_(const List& list);
Object while_(const List& list);
Object evalFunction(const List& list);
Object evalMacro(const List& list);
Object eval(const Adder& adder);
Object eval(const Subtractor& subtractor);
Object eval(const Multiplier& multiplier);
Object eval(const Divisor& divisor);
Object eval(const Modular& modular);
Object eval(const Negator& negator);
Object eval(const Less& less);
Object eval(const Greater& greater);
Object eval(const LessEqual& less_equal);
Object eval(const GreaterEqual& greater_equal);
Object eval(const EqualTo& equal_to);
Object eval(const NotEqualTo& not_equal_to);
Object eval(const And& logical_and);
Object eval(const Or& logical_or);
Object eval(const Not& logical_not);
Object eval(const BitwiseAnd& bitwise_and);
Object eval(const BitwiseOr& bitwise_or);
Object eval(const BitwiseXor& bitwise_xor);
Object eval(const BitwiseNot& bitwise_not);
Object eval(const LeftShift& left_shift);
Object eval(const RightShift& right_shift);
Object eval(const Symbol& symbol);
Object eval(const Getter& getter);
Object eval(const Setter& setter);
Object eval(const Assignment& assignment);
Object eval(const List& list);
Object eval(const Quote& quote);
Object eval(const SharedObject& shared_object);
Object eval(const Object& object);
Object eval(const std::string& script);
private:
Object shared_objects_ = {UnorderedSet()};
Object global_scope_ = {UnorderedSet()};
Object local_scope_ = {UnorderedSet()};
};
void parse(std::list<Object>& list);
template<class T>
Object* Evaluator::Impl::getFromPair(T& owner, const Object& index)
{
if (index == Object({Symbol({"first"})})) {
return &owner.value.first;
}
if (index == Object({Symbol({"second"})})) {
return &owner.value.second;
}
throw std::invalid_argument("Unexpected index.");
}
Object* Evaluator::Impl::get(Vector& owner, const Integer& integer)
{
if (static_cast<std::size_t>(integer.value) < owner.value.size()) {
return &owner.value[integer.value];
}
throw std::out_of_range("Index out of range.");
}
Object* Evaluator::Impl::get(Vector& owner, const Object& index)
{
if (index.value.type() == typeid(Integer)) {
return get(owner, std::any_cast<const Integer&>(index.value));
}
throw std::invalid_argument("Unexpected index type.");
}
Object* Evaluator::Impl::get(UnorderedSet& owner, const Object& index)
{
auto iter = owner.value.find(index);
if (iter != owner.value.end()) {
if (iter->value.type() == typeid(Setter)) {
return &const_cast<Object&>(
std::any_cast<const Setter&>(iter->value).value.second);
}
return &const_cast<Object&>(*iter);
}
return nullptr;
}
Object* Evaluator::Impl::get(List& owner, const Integer& integer)
{
if (static_cast<std::size_t>(integer.value) < owner.value.size()) {
auto iter = owner.value.begin();
std::advance(iter, integer.value);
return &*iter;
}
throw std::out_of_range("Index out of range.");
}
Object* Evaluator::Impl::get(List& owner, const Object& index)
{
if (index.value.type() == typeid(Integer)) {
return get(owner, std::any_cast<const Integer&>(index.value));
}
throw std::invalid_argument("Unexpected index type.");
}
Object* Evaluator::Impl::get(Object& owner, const Getter& getter)
{
Object* obj_ptr = get(owner, getter.value.first);
if (obj_ptr != nullptr) {
return get(*obj_ptr, eval(getter.value.second));
}
return nullptr;
}
Object* Evaluator::Impl::get(Object& owner, const Object& index)
{
if (index.value.type() == typeid(Getter)) {
return get(owner, std::any_cast<const Getter&>(index.value));
}
if (owner.value.type() == typeid(Setter)) {
return getFromPair(std::any_cast<Setter&>(owner.value), index);
}
if (owner.value.type() == typeid(Getter)) {
return getFromPair(std::any_cast<Getter&>(owner.value), index);
}
if (owner.value.type() == typeid(Adder)) {
return getFromPair(std::any_cast<Adder&>(owner.value), index);
}
if (owner.value.type() == typeid(Subtractor)) {
return getFromPair(std::any_cast<Subtractor&>(owner.value), index);
}
if (owner.value.type() == typeid(Multiplier)) {
return getFromPair(std::any_cast<Multiplier&>(owner.value), index);
}
if (owner.value.type() == typeid(Divisor)) {
return getFromPair(std::any_cast<Divisor&>(owner.value), index);
}
if (owner.value.type() == typeid(Modular)) {
return getFromPair(std::any_cast<Modular&>(owner.value), index);
}
if (owner.value.type() == typeid(Less)) {
return getFromPair(std::any_cast<Less&>(owner.value), index);
}
if (owner.value.type() == typeid(Greater)) {
return getFromPair(std::any_cast<Greater&>(owner.value), index);
}
if (owner.value.type() == typeid(LessEqual)) {
return getFromPair(std::any_cast<LessEqual&>(owner.value), index);
}
if (owner.value.type() == typeid(GreaterEqual)) {
return getFromPair(std::any_cast<GreaterEqual&>(owner.value), index);
}
if (owner.value.type() == typeid(EqualTo)) {
return getFromPair(std::any_cast<EqualTo&>(owner.value), index);
}
if (owner.value.type() == typeid(NotEqualTo)) {
return getFromPair(std::any_cast<NotEqualTo&>(owner.value), index);
}
if (owner.value.type() == typeid(And)) {
return getFromPair(std::any_cast<And&>(owner.value), index);
}
if (owner.value.type() == typeid(Or)) {
return getFromPair(std::any_cast<Or&>(owner.value), index);
}
if (owner.value.type() == typeid(BitwiseAnd)) {
return getFromPair(std::any_cast<BitwiseAnd&>(owner.value), index);
}
if (owner.value.type() == typeid(BitwiseOr)) {
return getFromPair(std::any_cast<BitwiseOr&>(owner.value), index);
}
if (owner.value.type() == typeid(BitwiseXor)) {
return getFromPair(std::any_cast<BitwiseXor&>(owner.value), index);
}
if (owner.value.type() == typeid(LeftShift)) {
return getFromPair(std::any_cast<LeftShift&>(owner.value), index);
}
if (owner.value.type() == typeid(RightShift)) {
return getFromPair(std::any_cast<RightShift&>(owner.value), index);
}
if (owner.value.type() == typeid(UnorderedSet)) {
return get(std::any_cast<UnorderedSet&>(owner.value), index);
}
if (owner.value.type() == typeid(Vector)) {
return get(std::any_cast<Vector&>(owner.value), index);
}
if (owner.value.type() == typeid(List)) {
return get(std::any_cast<List&>(owner.value), index);
}
throw std::invalid_argument("Unexpected owner type.");
}
template<class T>
void Evaluator::Impl::setPair(T& owner, const Object& index,
const Object& value)
{
if (index == Object({Symbol({"first"})})) {
owner.value.first = value;
return;
}
if (index == Object({Symbol({"second"})})) {
owner.value.second = value;
return;
}
throw std::invalid_argument("Unexpected index.");
}
void Evaluator::Impl::set(Vector& owner, const Integer& integer,
const Object& value)
{
if (static_cast<std::size_t>(integer.value) < owner.value.size()) {
owner.value[integer.value] = value;
return;
}
throw std::out_of_range("Index out of range.");
}
void Evaluator::Impl::set(Vector& owner, const Object& index,
const Object& value)
{
if (index.value.type() == typeid(Integer)) {
return set(owner, std::any_cast<const Integer&>(index.value), value);
}
throw std::invalid_argument("Unexpected index type.");
}
void Evaluator::Impl::set(UnorderedSet& owner, const Object& index,
const Object& value)
{
owner.value.erase({Setter({{index, value}})});
owner.value.insert({Setter({{index, value}})});
}
void Evaluator::Impl::set(List& owner, const Integer& index,
const Object& value)
{
if (static_cast<std::size_t>(index.value) < owner.value.size()) {
auto iter = owner.value.begin();
std::advance(iter, index.value);
*iter = value;
return;
}
throw std::out_of_range("Index out of range.");
}
void Evaluator::Impl::set(List& owner, const Object& index, const Object& value)
{
if (index.value.type() == typeid(Integer)) {
return set(owner, std::any_cast<const Integer&>(index.value), value);
}
throw std::invalid_argument("Unexpected index type.");
}
void Evaluator::Impl::set(Object& owner, const Getter& index,
const Object& value)
{
Object* owner_ptr = get(owner, index.value.first);
if (owner_ptr == nullptr) {
throw std::runtime_error("Owner not found.");
}
set(*owner_ptr, eval(index.value.second), value);
}
void Evaluator::Impl::set(Object& owner, const Object& index,
const Object& value)
{
if (index.value.type() == typeid(Getter)) {
return set(owner, std::any_cast<const Getter&>(index.value), value);
}
if (owner.value.type() == typeid(Setter)) {
return setPair(std::any_cast<Setter&>(owner.value), index, value);
}
if (owner.value.type() == typeid(Getter)) {
return setPair(std::any_cast<Getter&>(owner.value), index, value);
}
if (owner.value.type() == typeid(Adder)) {
return setPair(std::any_cast<Adder&>(owner.value), index, value);
}
if (owner.value.type() == typeid(Subtractor)) {
return setPair(std::any_cast<Subtractor&>(owner.value), index, value);
}
if (owner.value.type() == typeid(Multiplier)) {
return setPair(std::any_cast<Multiplier&>(owner.value), index, value);
}
if (owner.value.type() == typeid(Divisor)) {
return setPair(std::any_cast<Divisor&>(owner.value), index, value);
}
if (owner.value.type() == typeid(Modular)) {
return setPair(std::any_cast<Modular&>(owner.value), index, value);
}
if (owner.value.type() == typeid(Less)) {
return setPair(std::any_cast<Less&>(owner.value), index, value);
}
if (owner.value.type() == typeid(Greater)) {
return setPair(std::any_cast<Greater&>(owner.value), index, value);
}
if (owner.value.type() == typeid(LessEqual)) {
return setPair(std::any_cast<LessEqual&>(owner.value), index, value);
}
if (owner.value.type() == typeid(GreaterEqual)) {
return setPair(std::any_cast<GreaterEqual&>(owner.value), index, value);
}
if (owner.value.type() == typeid(EqualTo)) {
return setPair(std::any_cast<EqualTo&>(owner.value), index, value);
}
if (owner.value.type() == typeid(NotEqualTo)) {
return setPair(std::any_cast<NotEqualTo&>(owner.value), index, value);
}
if (owner.value.type() == typeid(And)) {
return setPair(std::any_cast<And&>(owner.value), index, value);
}
if (owner.value.type() == typeid(Or)) {
return setPair(std::any_cast<Or&>(owner.value), index, value);
}
if (owner.value.type() == typeid(BitwiseAnd)) {
return setPair(std::any_cast<BitwiseAnd&>(owner.value), index, value);
}
if (owner.value.type() == typeid(BitwiseOr)) {
return setPair(std::any_cast<BitwiseOr&>(owner.value), index, value);
}
if (owner.value.type() == typeid(BitwiseXor)) {
return setPair(std::any_cast<BitwiseXor&>(owner.value), index, value);
}
if (owner.value.type() == typeid(LeftShift)) {
return setPair(std::any_cast<LeftShift&>(owner.value), index, value);
}
if (owner.value.type() == typeid(RightShift)) {
return setPair(std::any_cast<RightShift&>(owner.value), index, value);
}
if (owner.value.type() == typeid(UnorderedSet)) {
return set(std::any_cast<UnorderedSet&>(owner.value), index, value);
}
if (owner.value.type() == typeid(Vector)) {
return set(std::any_cast<Vector&>(owner.value), index, value);
}
if (owner.value.type() == typeid(List)) {
return set(std::any_cast<List&>(owner.value), index, value);
}
throw std::invalid_argument("Unexpected owner type.");
}
Object Evaluator::Impl::cond_(const List& list)
{
auto iter = list.value.begin();
while (++iter != list.value.end()) {
Object result = eval(*iter);
++iter;
if (result.value.type() != typeid(Null)
&& result != Object({Boolean({false})})) {
return eval(*iter);
}
}
return {Null()};
}
Object Evaluator::Impl::eval_(const List& list)
{
if (list.value.size() < 2) {
return {Null()};
}
return eval(*++list.value.begin());
}
Object Evaluator::Impl::global_()
{
return global_scope_;
}
Object Evaluator::Impl::if_(const List& list)
{
auto iter = ++list.value.begin();
Object result = eval(*iter);
if (result.value.type() == typeid(Null)
|| result == Object({Boolean({false})})) {
if (++iter != list.value.end() && ++iter != list.value.end()) {
return eval(*iter);
}
return {Null()};
}
if (++iter != list.value.end()) {
return eval(*iter);
}
return {Null()};
}
Object Evaluator::Impl::import_(const List& list)
{
auto iter = ++list.value.begin();
if (iter == list.value.end()) {
return {Null()};
}
PrimitiveFunction function;
if (iter->value.type() != typeid(String)) {
return {Null()};
}
std::filesystem::path path =
std::any_cast<const String&>(iter->value).value;
if (std::filesystem::exists(path) == false) {
return {Null()};
}
if (++iter == list.value.end()) {
std::fstream file(path.string());
Object to_eval;
Reader read;
while (file) {
read(to_eval, file);
eval(to_eval);
}
return global_();
}
if (iter->value.type() != typeid(String)) {
return {Null()};
}
std::string name = std::any_cast<const String&>(iter->value).value;
boost::dll::shared_library lib(path.string());
if (lib.has(name) == false) {
return {Null()};
}
boost::shared_ptr<Object> obj_ptr =
boost::dll::import<Object>(path.string(), name);
SharedObject shared_object = {std::shared_ptr<Object>(
obj_ptr.get(), [obj_ptr](Object*) mutable { obj_ptr.reset(); })};
Object first = {Symbol({name})};
Object second = {shared_object};
set(shared_objects_, first, second);
return eval(shared_object);
}
Object Evaluator::Impl::let_(const List& list)
{
if (list.value.size() < 2) {
return {Null()};
}
auto iter = ++list.value.begin();
if (iter->value.type() != typeid(Setter)) {
return {Null()};
}
const Setter& setter = std::any_cast<const Setter&>(iter->value);
Object after_eval = eval(setter.value.second);
set(local_scope_, setter.value.first, after_eval);
return after_eval;
}
Object Evaluator::Impl::local_()
{
return local_scope_;
}
Object Evaluator::Impl::locate_(const List& list)
{
auto iter = ++list.value.begin();
if (iter == list.value.end()) {
return {String({std::filesystem::current_path().string()})};
}
boost::dll::fs::path path = boost::dll::program_location().parent_path();
if (*iter == Object({Symbol({"bin"})})) {
return {String({path.string()})};
}
path = path.parent_path();
if (*iter == Object({Symbol({"fundot"})})) {
return {String({path.string()})};
}
if (*iter == Object({Symbol({"lib"})})) {
return {String({(path / "lib").string()})};
}
return {Null()};
}
Object Evaluator::Impl::while_(const List& list)
{
auto iter = ++list.value.begin();
Object predicate = *iter;
Object to_eval = *++iter;
Object result = eval(predicate);
Object ret({Null()});
while (result.value.type() != typeid(Null)
&& result != Object({Boolean({false})})) {
ret = eval(to_eval);
result = eval(predicate);
}
return ret;
}
Object Evaluator::Impl::evalFunction(const List& list)
{
const Object& front = list.value.front();
if (front.value.type() == typeid(UnorderedSet)) {
auto info = std::any_cast<const UnorderedSet&>(front.value);
Object* type = get(info, {Symbol({"type"})});
if (type == nullptr) {
return {Null()};
}
if (*type == Object({Symbol({"function"})})) {
Object* params = get(info, {Symbol({"params"})});
if (params == nullptr || params->value.type() != typeid(Vector)) {
return {Null()};
}
Object* body = get(info, {Symbol({"body"})});
if (body == nullptr) {
return {Null()};
}
Object local = local_scope_;
const auto& vector =
std::any_cast<const Vector&>(params->value).value;
auto it = list.value.begin();
for (const auto& arg : vector) {
if (++it == list.value.end()) {
break;
}
set(local_scope_, arg, *it);
}
Object after = eval(*body);
local_scope_ = local;
return after;
}
}
return {Void()};
}
Object Evaluator::Impl::evalMacro(const List& list)
{
const Object& front = list.value.front();
if (front.value.type() == typeid(UnorderedSet)) {
auto info = std::any_cast<const UnorderedSet&>(front.value);
Object* type = get(info, {Symbol({"type"})});
if (type == nullptr) {
return {Null()};
}
if (*type == Object({Symbol({"macro"})})) {
Object* params = get(info, {Symbol({"params"})});
if (params == nullptr || params->value.type() != typeid(Vector)) {
return {Null()};
}
Object* body = get(info, {Symbol({"body"})});
if (body == nullptr) {
return {Null()};
}
Object local = local_scope_;
const auto& vector =
std::any_cast<const Vector&>(params->value).value;
auto it = list.value.begin();
for (const auto& arg : vector) {
if (++it == list.value.end()) {
break;
}
set(local_scope_, arg, *it);
}
Object after = eval(*body);
local_scope_ = local;
return after;
}
}
return {Void()};
}
Object Evaluator::Impl::eval(const Adder& adder)
{
return eval(adder.value.first) + eval(adder.value.second);
}
Object Evaluator::Impl::eval(const Subtractor& subtractor)
{
return eval(subtractor.value.first) - eval(subtractor.value.second);
}
Object Evaluator::Impl::eval(const Multiplier& multiplier)
{
return eval(multiplier.value.first) * eval(multiplier.value.second);
}
Object Evaluator::Impl::eval(const Divisor& divisor)
{
return eval(divisor.value.first) / eval(divisor.value.second);
}
Object Evaluator::Impl::eval(const Modular& modular)
{
return eval(modular.value.first) % eval(modular.value.second);
}
Object Evaluator::Impl::eval(const Negator& negator)
{
return -eval(negator.value);
}
Object Evaluator::Impl::eval(const Less& less)
{
return {Boolean({eval(less.value.first) < eval(less.value.second)})};
}
Object Evaluator::Impl::eval(const Greater& greater)
{
return {Boolean({eval(greater.value.first) > eval(greater.value.second)})};
}
Object Evaluator::Impl::eval(const LessEqual& less_equal)
{
return {Boolean(
{eval(less_equal.value.first) <= eval(less_equal.value.second)})};
}
Object Evaluator::Impl::eval(const GreaterEqual& greater_equal)
{
return {Boolean(
{eval(greater_equal.value.first) >= eval(greater_equal.value.second)})};
}
Object Evaluator::Impl::eval(const EqualTo& equal_to)
{
return {
Boolean({eval(equal_to.value.first) == eval(equal_to.value.second)})};
}
Object Evaluator::Impl::eval(const NotEqualTo& not_equal_to)
{
return {Boolean(
{eval(not_equal_to.value.first) != eval(not_equal_to.value.second)})};
}
Object Evaluator::Impl::eval(const And& logical_and)
{
return eval(logical_and.value.first) && eval(logical_and.value.second);
}
Object Evaluator::Impl::eval(const Or& logical_or)
{
return eval(logical_or.value.first) || eval(logical_or.value.second);
}
Object Evaluator::Impl::eval(const Not& logical_not)
{
return !eval(logical_not.value);
}
Object Evaluator::Impl::eval(const BitwiseAnd& bitwise_and)
{
return eval(bitwise_and.value.first) & eval(bitwise_and.value.second);
}
Object Evaluator::Impl::eval(const BitwiseOr& bitwise_or)
{
return eval(bitwise_or.value.first) | eval(bitwise_or.value.second);
}
Object Evaluator::Impl::eval(const BitwiseXor& bitwise_xor)
{
return eval(bitwise_xor.value.first) ^ eval(bitwise_xor.value.second);
}
Object Evaluator::Impl::eval(const BitwiseNot& bitwise_not)
{
return ~eval(bitwise_not.value);
}
Object Evaluator::Impl::eval(const LeftShift& left_shift)
{
return eval(left_shift.value.first) << eval(left_shift.value.second);
}
Object Evaluator::Impl::eval(const RightShift& right_shift)
{
return eval(right_shift.value.first) >> eval(right_shift.value.second);
}
Object Evaluator::Impl::eval(const Symbol& symbol)
{
Object* obj_ptr = get(local_scope_, {symbol});
if (obj_ptr != nullptr) {
return *obj_ptr;
}
obj_ptr = get(global_scope_, {symbol});
if (obj_ptr != nullptr) {
return *obj_ptr;
}
return {symbol};
}
Object Evaluator::Impl::eval(const Getter& getter)
{
Object* obj_ptr = get(local_scope_, {getter});
if (obj_ptr != nullptr) {
return *obj_ptr;
}
obj_ptr = get(global_scope_, {getter});
if (obj_ptr != nullptr) {
return *obj_ptr;
}
throw std::runtime_error("Variable not found.");
}
Object Evaluator::Impl::eval(const Setter& setter)
{
Object after_eval = eval(setter.value.second);
set(global_scope_, setter.value.first, after_eval);
return after_eval;
}
Object Evaluator::Impl::eval(const Assignment& assignment)
{
return eval(
{Setter({{eval(assignment.value.first), assignment.value.second}})});
}
Object Evaluator::Impl::eval(const List& list)
{
if (list.value.empty()) {
return {Null()};
}
List list_copy = list;
parse(list_copy.value);
auto iter = list_copy.value.begin();
*iter = eval(*iter);
const Object& front = list_copy.value.front();
if (front.value.type() == typeid(SpecialForm)) {
const SpecialForm& special_form =
std::any_cast<const SpecialForm&>(front.value);
return special_form.value(list_copy);
}
Object after_eval = evalMacro(list_copy);
if (after_eval.value.type() != typeid(Void)) {
return eval(after_eval);
}
while (++iter != list_copy.value.end()) {
*iter = eval(*iter);
}
if (front.value.type() == typeid(PrimitiveFunction)) {
const PrimitiveFunction& function =
std::any_cast<const PrimitiveFunction&>(front.value);
return function.value(list_copy);
}
after_eval = evalFunction(list_copy);
if (after_eval.value.type() != typeid(Void)) {
return after_eval;
}
if (list_copy.value.size() == 1) {
return list_copy.value.back();
}
return {list_copy};
}
Object Evaluator::Impl::eval(const Quote& quote)
{
return quote.value;
}
Object Evaluator::Impl::eval(const SharedObject& shared_object)
{
return eval(*shared_object.value);
}
Object Evaluator::Impl::eval(const Object& object)
{
if (object.value.type() == typeid(Adder)) {
return eval(std::any_cast<const Adder&>(object.value));
}
if (object.value.type() == typeid(Subtractor)) {
return eval(std::any_cast<const Subtractor&>(object.value));
}
if (object.value.type() == typeid(Multiplier)) {
return eval(std::any_cast<const Multiplier&>(object.value));
}
if (object.value.type() == typeid(Divisor)) {
return eval(std::any_cast<const Divisor&>(object.value));
}
if (object.value.type() == typeid(Modular)) {
return eval(std::any_cast<const Modular&>(object.value));
}
if (object.value.type() == typeid(Negator)) {
return eval(std::any_cast<const Negator&>(object.value));
}
if (object.value.type() == typeid(Less)) {
return eval(std::any_cast<const Less&>(object.value));
}
if (object.value.type() == typeid(Greater)) {
return eval(std::any_cast<const Greater&>(object.value));
}
if (object.value.type() == typeid(LessEqual)) {
return eval(std::any_cast<const LessEqual&>(object.value));
}
if (object.value.type() == typeid(GreaterEqual)) {
return eval(std::any_cast<const GreaterEqual&>(object.value));
}
if (object.value.type() == typeid(EqualTo)) {
return eval(std::any_cast<const EqualTo&>(object.value));
}
if (object.value.type() == typeid(NotEqualTo)) {
return eval(std::any_cast<const NotEqualTo&>(object.value));
}
if (object.value.type() == typeid(And)) {
return eval(std::any_cast<const And&>(object.value));
}
if (object.value.type() == typeid(Or)) {
return eval(std::any_cast<const Or&>(object.value));
}
if (object.value.type() == typeid(Not)) {
return eval(std::any_cast<const Not&>(object.value));
}
if (object.value.type() == typeid(BitwiseAnd)) {
return eval(std::any_cast<const BitwiseAnd&>(object.value));
}
if (object.value.type() == typeid(BitwiseOr)) {
return eval(std::any_cast<const BitwiseOr&>(object.value));
}
if (object.value.type() == typeid(BitwiseXor)) {
return eval(std::any_cast<const BitwiseXor&>(object.value));
}
if (object.value.type() == typeid(BitwiseNot)) {
return eval(std::any_cast<const BitwiseNot&>(object.value));
}
if (object.value.type() == typeid(LeftShift)) {
return eval(std::any_cast<const LeftShift&>(object.value));
}
if (object.value.type() == typeid(RightShift)) {
return eval(std::any_cast<const RightShift&>(object.value));
}
if (object.value.type() == typeid(Symbol)) {
return eval(std::any_cast<const Symbol&>(object.value));
}
if (object.value.type() == typeid(Getter)) {
return eval(std::any_cast<const Getter&>(object.value));
}
if (object.value.type() == typeid(Setter)) {
return eval(std::any_cast<const Setter&>(object.value));
}
if (object.value.type() == typeid(Assignment)) {
return eval(std::any_cast<const Assignment&>(object.value));
}
if (object.value.type() == typeid(List)) {
return eval(std::any_cast<const List&>(object.value));
}
if (object.value.type() == typeid(Quote)) {
return eval(std::any_cast<const Quote&>(object.value));
}
if (object.value.type() == typeid(SharedObject)) {
return eval(std::any_cast<const SharedObject&>(object.value));
}
return object;
}
Object Evaluator::Impl::eval(const std::string& script)
{
std::stringstream script_stream(script);
Object to_eval;
Reader read;
read(to_eval, script_stream);
return eval(to_eval);
}
Object Evaluator::operator()(const Object& object)
{
return pimpl_->eval(object);
}
Object Evaluator::operator()(const std::string& script)
{
return pimpl_->eval(script);
}
Evaluator::Evaluator() : pimpl_(new Evaluator::Impl)
{
Symbol name;
PrimitiveFunction function;
name.value = "eval";
function.value = [this](const List& list) {
return pimpl_->eval_(list);
};
pimpl_->eval(Setter({{{name}, {function}}}));
name.value = "global";
function.value = [this](const List&) {
return pimpl_->global_();
};
pimpl_->eval(Setter({{{name}, {function}}}));
name.value = "import";
function.value = [this](const List& list) {
return pimpl_->import_(list);
};
pimpl_->eval(Setter({{{name}, {function}}}));
name.value = "local";
function.value = [this](const List&) {
return pimpl_->local_();
};
pimpl_->eval(Setter({{{name}, {function}}}));
name.value = "locate";
function.value = [this](const List& list) {
return pimpl_->locate_(list);
};
pimpl_->eval(Setter({{{name}, {function}}}));
SpecialForm special_from;
name.value = "cond";
special_from.value = [this](const List& list) {
return pimpl_->cond_(list);
};
pimpl_->eval(Setter({{{name}, {special_from}}}));
name.value = "if";
special_from.value = [this](const List& list) {
return pimpl_->if_(list);
};
pimpl_->eval(Setter({{{name}, {special_from}}}));
name.value = "let";
special_from.value = [this](const List& list) {
return pimpl_->let_(list);
};
pimpl_->eval(Setter({{{name}, {special_from}}}));
name.value = "while";
special_from.value = [this](const List& list) {
return pimpl_->while_(list);
};
pimpl_->eval(Setter({{{name}, {special_from}}}));
}
Evaluator::~Evaluator() = default;
} // namespace fundot
|
/******************************************************************************
*
* INTEL CONFIDENTIAL
*
* Copyright 2015 Intel Corporation All Rights Reserved.
*
* The source code contained or described herein and all documents related
* to the source code (Material) are owned by Intel Corporation or its
* suppliers or licensors. Title to the Material remains with
* Intel Corporation or its suppliers and licensors. The Material contains
* trade secrets and proprietary and confidential information of Intel or
* its suppliers and licensors. The Material is protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Material may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without Intel's
* prior express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or
* delivery of the Materials, either expressly, by implication, inducement,
* estoppel or otherwise. Any license under such intellectual property rights
* must be express and approved by Intel in writing.
*
*
* Workfile: FwUpdateDebug.c
*
* Abstract: macros to wrap dbglog for simple FwUpdate debugging
*
******************************************************************************/
#ifndef __FW_UPDATE_DEBUG_H__
#define __FW_UPDATE_DEBUG_H__
#include <gsl/span>
#include <iostream>
typedef enum
{
PRINT_NONE = 0,
PRINT_CRITICAL = 1,
PRINT_ERROR,
PRINT_WARNING,
PRINT_INFO,
PRINT_DEBUG,
PRINT_DEBUG2,
PRINT_ALL,
} dbg_level;
#define FWCRITICAL(MSG) PRINT(PRINT_CRITICAL, MSG)
#define FWERROR(MSG) PRINT(PRINT_ERROR, MSG)
#define FWWARN(MSG) PRINT(PRINT_WARNING, MSG)
#define FWINFO(MSG) PRINT(PRINT_INFO, MSG)
#define FWDEBUG(MSG) PRINT(PRINT_DEBUG, MSG)
#define FWDEBUG2(MSG) PRINT(PRINT_DEBUG2, MSG)
#define FWDUMP(D, L) DUMP(PRINT_DEBUG, D, L)
#define FW_UPDATE_DEBUG 1
#ifdef FW_UPDATE_DEBUG
extern dbg_level fw_update_get_dbg_level(void);
extern void fw_update_set_dbg_level(dbg_level l);
#define PRINT(LEVEL, MSG) \
do \
{ \
if ((LEVEL) <= fw_update_get_dbg_level()) \
{ \
std::stringstream ss; \
ss << '<' << LEVEL << '>' << __FUNCTION__ << ":" << __LINE__ \
<< ": " << MSG; \
std::cerr << ss.str() << std::endl; \
} \
} while (0)
void _dump(dbg_level lvl, const char* fn, int lineno, const char* bname,
const gsl::span<const uint8_t>& buf);
void _dump(dbg_level lvl, const char* fn, int lineno, const char* bname,
const void* buf, size_t len);
#define DUMP(LEVEL, BUF, ...) \
do \
{ \
if ((LEVEL) <= fw_update_get_dbg_level()) \
{ \
_dump(LEVEL, __FUNCTION__, __LINE__, #BUF, BUF, ##__VA_ARGS__); \
} \
} while (0)
#else /* !FW_UPDATE_DEBUG */
#define PRINT(...)
#define DUMP(...)
#endif /* FW_UPDATE_DEBUG */
#endif /* __FW_UPDATE_DEBUG_H__ */
|
solution <- sort |
# -*- coding: utf-8 -*-
""" Stacked plot
In data science, often one wants to compare two different sets of data, like signal/background or prediction and
actual data.
In this very brief script we create two sets of data and compare them in one plot.
"""
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import b2plot as bp
try:
plt.style.use('belle2')
except OSError:
print("Please install belle2 matplotlib style")
bp.hist(np.random.normal(0, 0.5, 1000), label="Pseudo Simulation")
bp.errorhist(np.random.normal(0, 0.5, 1000), label="Pseudo Data", color='black')
bp.labels("O", "Entries", "Unit")
plt.legend()
# bp.xlim()
# bp.labels('$\Delta M$', "Events", "GeV", 0)
bp.save("histogram2.png")
|
import linear_algebra.dimension
import missing_mathlib.set_theory.cardinal
universe variables u u' u'' v v' w w'
variables {α : Type u} {β γ δ ε : Type v}
variables {ι : Type w} {ι' : Type w'} {η : Type u''} {φ : η → Type u'}
section vector_space
variables [decidable_eq ι] [decidable_eq ι'] [field α] [decidable_eq α] [add_comm_group β] [vector_space α β]
include α
open submodule lattice function set
open vector_space
lemma submodule.bot_of_dim_zero (p : submodule α β) (h_dim : dim α p = 0) : p = ⊥ :=
begin
haveI : decidable_eq β := classical.dec_eq β,
obtain ⟨b, hb⟩ : ∃b : set p, is_basis α (λ i : b, i.val) := @exists_is_basis α p _ _ _,
rw ←le_bot_iff,
intros x hx,
have : (⟨x, (submodule.mem_coe p).1 hx⟩ : p) = (0 : p),
{ rw ←@mem_bot α p _ _ _,
rw [← @span_empty α p _ _ _, ←(@set.range_eq_empty p b (λ (i : b), i.val)).2, hb.2],
apply mem_top,
unfold_coes,
rw [nonempty_subtype],
push_neg,
rw [←set.eq_empty_iff_forall_not_mem, ←cardinal.mk_zero_iff_empty_set],
rwa cardinal.lift_inj.1 hb.mk_eq_dim },
rw [mem_bot],
rw <-coe_eq_zero at this,
apply this,
end
lemma linear_independent.le_lift_dim [decidable_eq β] {v : ι → β} (hv : linear_independent α v) :
cardinal.lift.{w v} (cardinal.mk ι) ≤ cardinal.lift.{v w} (dim α β) :=
calc
cardinal.lift.{w v} (cardinal.mk ι)
= cardinal.lift.{v w} (cardinal.mk (range v)) :
by rw ←cardinal.mk_range_eq_of_injective (linear_independent.injective hv)
... = cardinal.lift.{v w} (dim α (span α (range v))) :
by rw ←dim_span hv
... ≤ cardinal.lift.{v w} (dim α (⊤ : submodule α β)) :
cardinal.lift_le.2 (dim_le_of_submodule (submodule.span α (set.range v)) ⊤ le_top)
... ≤ cardinal.lift.{v w} (dim α β) :
by rw dim_top
lemma linear_independent_le_dim {α : Type u} {β : Type v} {ι : Type w}
[field α] [decidable_eq β] [add_comm_group β] [vector_space α β] [decidable_eq ι]
{v : ι → β} (hv : @linear_independent _ α _ v (@comm_ring.to_ring _ (field.to_comm_ring _)) _ _) :
cardinal.lift.{w v} (cardinal.mk ι) ≤ cardinal.lift.{v w} (dim α β) :=
calc
cardinal.lift.{w v} (cardinal.mk ι) = cardinal.lift.{v w} (cardinal.mk (set.range v)) :
(cardinal.mk_range_eq_of_injective (linear_independent.injective hv)).symm
... = cardinal.lift.{v w} (dim α (submodule.span α (set.range v))) : by rw (dim_span hv).symm
... ≤ cardinal.lift.{v w} (dim α β) : cardinal.lift_le.2 (dim_submodule_le (submodule.span α _))
lemma powers_linear_dependent_of_dim_finite (α : Type v) (β : Type w)
[field α] [decidable_eq β] [add_comm_group β] [vector_space α β]
(f : β →ₗ[α] β) (h_dim : dim α β < cardinal.omega) (v : β) :
¬ linear_independent α (λ n : ℕ, (f ^ n) v) :=
begin
intro hw,
apply not_lt_of_le _ h_dim,
rw [← cardinal.lift_id (dim α β), cardinal.lift_umax.{w 0}],
apply linear_independent_le_dim hw
end
lemma exists_mem_ne_zero_of_dim_pos' {α : Type v} {β : Type w}
[field α] [add_comm_group β] [vector_space α β]
(h_dim : 0 < dim α β) : ∃ x : β, x ≠ 0 :=
begin
obtain ⟨b, _, _⟩ : (∃ b : β, b ∈ (⊤ : submodule α β) ∧ b ≠ 0),
{ apply exists_mem_ne_zero_of_dim_pos,
rw dim_top,
apply h_dim },
use b
end
lemma dim_pos_of_mem_ne_zero {α : Type v} {β : Type w}
[field α] [add_comm_group β] [vector_space α β]
(x : β) (h : x ≠ 0) : 0 < dim α β :=
begin
classical,
by_contra hc,
rw [not_lt, cardinal.le_zero, ←dim_top] at hc,
have x_mem_bot : x ∈ ⊥,
{ rw ← submodule.bot_of_dim_zero ⊤ hc,
apply mem_top },
exact h ((mem_bot α).1 x_mem_bot)
end
end vector_space |
-- Teorema_de_Cantor.lean
-- Teorema de Cantor.
-- José A. Alonso Jiménez <https://jaalonso.github.io>
-- Sevilla, 6-mayo-2022
-- ---------------------------------------------------------------------
-- ---------------------------------------------------------------------
-- Demostrar el teorema de Cantor:
-- ∀ f : α → set α, ¬ surjective f
-- ----------------------------------------------------------------------
import data.set.basic
open function
variables {α : Type}
-- 1ª demostración
-- ===============
example : ∀ f : α → set α, ¬ surjective f :=
begin
intros f hf,
let S := {i | i ∉ f i},
unfold surjective at hf,
cases hf S with j hj,
by_cases j ∈ S,
{ dsimp at h,
apply h,
rw hj,
exact h, },
{ apply h,
rw ← hj at h,
exact h, },
end
-- 2ª demostración
-- ===============
example : ∀ f : α → set α, ¬ surjective f :=
begin
intros f hf,
let S := {i | i ∉ f i},
cases hf S with j hj,
by_cases j ∈ S,
{ apply h,
rwa hj, },
{ apply h,
rwa ← hj at h, },
end
-- 3ª demostración
-- ===============
example : ∀ f : α → set α, ¬ surjective f :=
begin
intros f hf,
let S := {i | i ∉ f i},
cases hf S with j hj,
have h : (j ∈ S) = (j ∉ S), from
calc (j ∈ S)
= (j ∉ f j) : set.mem_set_of_eq
... = (j ∉ S) : congr_arg not (congr_arg (has_mem.mem j) hj),
exact false_of_a_eq_not_a h,
end
-- 4ª demostración
-- ===============
example : ∀ f : α → set α, ¬ surjective f :=
begin
intros f hf,
let S := {i | i ∉ f i},
cases hf S with j hj,
have h : (j ∈ S) = (j ∉ S),
{ dsimp,
exact congr_arg not (congr_arg (has_mem.mem j) hj), },
{ exact false_of_a_eq_not_a (congr_arg not (congr_arg not h)), },
end
-- 5ª demostración
-- ===============
example : ∀ f : α → set α, ¬ surjective f :=
cantor_surjective
|
InputTextFile("input.txt");
s := ReadAll(f);; # two semicolons to hide the result, which may be long
CloseStream(f);
|
{- Copyright © 2015 Benjamin Barenblat
Licensed under the Apache License, Version 2.0 (the ‘License’); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an ‘AS IS’ BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License. -}
module B.Prelude.Bool where
open import B.Prelude.BooleanAlgebra using (BooleanAlgebra)
import Data.Bool
import Data.Bool.Properties
open Data.Bool
using (Bool; if_then_else_; T)
public
instance
BooleanAlgebra-Bool : BooleanAlgebra _ _
BooleanAlgebra-Bool = Data.Bool.Properties.booleanAlgebra
module Bool where
open Data.Bool
using (_xor_)
public
|
section \<open> Relational Operational Semantics \<close>
theory utp_rel_opsem
imports
utp_rel_laws
utp_hoare
begin
text \<open> This theory uses the laws of relational calculus to create a basic operational semantics.
It is based on Chapter 10 of the UTP book~\cite{Hoare&98}. \<close>
fun trel :: "'\<alpha> usubst \<times> '\<alpha> hrel \<Rightarrow> '\<alpha> usubst \<times> '\<alpha> hrel \<Rightarrow> bool" (infix "\<rightarrow>\<^sub>u" 85) where
"(\<sigma>, P) \<rightarrow>\<^sub>u (\<rho>, Q) \<longleftrightarrow> (\<langle>\<sigma>\<rangle>\<^sub>a ;; P) \<sqsubseteq> (\<langle>\<rho>\<rangle>\<^sub>a ;; Q)"
lemma trans_trel:
"\<lbrakk> (\<sigma>, P) \<rightarrow>\<^sub>u (\<rho>, Q); (\<rho>, Q) \<rightarrow>\<^sub>u (\<phi>, R) \<rbrakk> \<Longrightarrow> (\<sigma>, P) \<rightarrow>\<^sub>u (\<phi>, R)"
by auto
lemma skip_trel: "(\<sigma>, II) \<rightarrow>\<^sub>u (\<sigma>, II)"
by simp
lemma assigns_trel: "(\<sigma>, \<langle>\<rho>\<rangle>\<^sub>a) \<rightarrow>\<^sub>u (\<rho> \<circ>\<^sub>s \<sigma>, II)"
by (simp add: assigns_comp)
lemma assign_trel:
"(\<sigma>, x := v) \<rightarrow>\<^sub>u (\<sigma>(&x \<mapsto>\<^sub>s \<sigma> \<dagger> v), II)"
by (simp add: assigns_comp usubst)
lemma seq_trel:
assumes "(\<sigma>, P) \<rightarrow>\<^sub>u (\<rho>, Q)"
shows "(\<sigma>, P ;; R) \<rightarrow>\<^sub>u (\<rho>, Q ;; R)"
by (metis (no_types, lifting) assms order_refl seqr_assoc seqr_mono trel.simps)
lemma seq_skip_trel:
"(\<sigma>, II ;; P) \<rightarrow>\<^sub>u (\<sigma>, P)"
by simp
lemma nondet_left_trel:
"(\<sigma>, P \<sqinter> Q) \<rightarrow>\<^sub>u (\<sigma>, P)"
by (metis (no_types, opaque_lifting) disj_comm disj_upred_def semilattice_sup_class.sup.absorb_iff1 semilattice_sup_class.sup.left_idem seqr_or_distr trel.simps)
lemma nondet_right_trel:
"(\<sigma>, P \<sqinter> Q) \<rightarrow>\<^sub>u (\<sigma>, Q)"
by (simp add: seqr_mono)
lemma rcond_true_trel:
assumes "\<sigma> \<dagger> b = true"
shows "(\<sigma>, P \<triangleleft> b \<triangleright>\<^sub>r Q) \<rightarrow>\<^sub>u (\<sigma>, P)"
using assms
by (simp add: assigns_r_comp usubst alpha)
lemma rcond_false_trel:
assumes "\<sigma> \<dagger> b = false"
shows "(\<sigma>, P \<triangleleft> b \<triangleright>\<^sub>r Q) \<rightarrow>\<^sub>u (\<sigma>, Q)"
using assms
by (simp add: assigns_r_comp usubst alpha)
lemma while_true_trel:
assumes "\<sigma> \<dagger> b = true"
shows "(\<sigma>, while b do P od) \<rightarrow>\<^sub>u (\<sigma>, P ;; while b do P od)"
by (metis assms rcond_true_trel while_unfold)
lemma while_false_trel:
assumes "\<sigma> \<dagger> b = false"
shows "(\<sigma>, while b do P od) \<rightarrow>\<^sub>u (\<sigma>, II)"
by (metis assms rcond_false_trel while_unfold)
text \<open> Theorem linking Hoare calculus and operational semantics. If we start $Q$ in a state $\sigma_0$
satisfying $p$, and $Q$ reaches final state $\sigma_1$ then $r$ holds in this final state. \<close>
theorem hoare_opsem_link:
"\<lbrace>p\<rbrace>Q\<lbrace>r\<rbrace>\<^sub>u = (\<forall> \<sigma>\<^sub>0 \<sigma>\<^sub>1. `\<sigma>\<^sub>0 \<dagger> p` \<and> (\<sigma>\<^sub>0, Q) \<rightarrow>\<^sub>u (\<sigma>\<^sub>1, II) \<longrightarrow> `\<sigma>\<^sub>1 \<dagger> r`)"
apply (rel_auto)
apply (rename_tac a b)
apply (metis (full_types) lit.rep_eq)
done
declare trel.simps [simp del]
end |
lemma mult_poly_add_left: "(p + q) * r = p * r + q * r" for p q r :: "'a poly" |
[STATEMENT]
lemma hv_eq_zero [simp]: "Hv v = 0 \<longleftrightarrow> v = 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (Hv v = 0) = (v = 0)
[PROOF STEP]
by (simp add: octo_eq_iff vec_eq_iff) (metis exhaust_7) |
clear all
close all
disp('Synthetic data from nonlinear ODE model');
disp('defined in Ramsay et al. (2007)');
disp('based on Van der Pol oscillator and which');
disp('reduces to Fitzhugh-Nagumo for certain parameters');
sigma_e=0.01;
[M,U] = mci_ramsay_struct(sigma_e);
% Use higher integration tolerances than by default
M.reltol=1e-3;
M.abstol=1e-5;
rand_init=0;
if rand_init
P=spm_normrnd(M.vpE,M.pC,1);
else
P=[log(0.2) log(0.2)]';
end
tic;
Y = mci_ramsay_gen(P,M,U);
toc
mci_plot_outputs(M,Y);
%mcmc.inference='vl';
%mcmc.inference='langevin';
%mcmc.maxits=16;
%mcmc.verbose=1;
mcmc.inference='ais';
mcmc.anneal='geometric';
mcmc.prop='lmc';
mcmc.nprop=1;
mcmc.J=16;
mcmc.maxits=8;
mcmc.rec_traj=1;
post = spm_mci_post (mcmc,M,U,Y,P);
if ~strcmp(mcmc.inference,'vl')
spm_mci_diag(post);
stats = spm_mci_mvnpost (post,'ESS')
stats = spm_mci_mvnpost (post,'thinning')
for j=1:length(P),
spm_mci_quantiles (post,j,0);
end
end
load ramsay-surface
figure
surf(S.x,S.y,L);
xlabel(S.name{1});
ylabel(S.name{2});
figure;
imagesc(S.pxy(1,:),S.pxy(2,:),L);
axis xy
hold on
xlabel(S.name{1});
ylabel(S.name{2});
hold on
ms=10;
plot(M.pE(1),M.pE(2),'wo','MarkerSize',ms);
plot(P(1),P(2),'w+','MarkerSize',ms);
if ~strcmp(mcmc.inference,'vl')
j=post.ind;
plot(post.P(1,j),post.P(2,j),'w.');
end
plot(post.Ep(1),post.Ep(2),'kx','MarkerSize',ms);
if strcmp(mcmc.inference,'ais')
% plot individual trajectories
figure
xlim([-2 0]);
ylim([-2 0]);
hold on
for i=1:mcmc.maxits,
xx=squeeze(post.traj(i,1,:));
yy=squeeze(post.traj(i,2,:));
plot(xx,yy,'k-');
plot(xx(end),yy(end),'kx','MarkerSize',ms);
xlabel(S.name{1});
ylabel(S.name{2});
disp('Press space to see more trajectories');
pause
end
end
|
The set of absolute values of the inner products of a vector $x$ with the basis vectors is equal to the image of the basis vectors under the function that maps a basis vector to its absolute inner product with $x$. |
import tactic
namespace myeven
def is_even (n : ℕ) := ∃ p : ℕ, n = 2*p
theorem inf_many_evens : ∀ n:ℕ, ∃ k : ℕ, (k > n) ∧ (is_even k) :=
begin
assume n, -- assume an arbitrary n
use (2*(n+1)),
split,
{
linarith,
},
{
unfold is_even,
use (n+1),
}
end
end myeven |
import M4R.Algebra.Ring.Semiring
namespace M4R
namespace NCRing
open Group NCSemiring
protected instance Product (α₁ : Type _) (α₂ : Type _) [NCRing α₁] [NCRing α₂] : NCRing (α₁ × α₂) where
toNeg := (Group.Product α₁ α₂).toNeg
add_neg := (Group.Product α₁ α₂).add_neg
protected instance multi_product {ι : Type _} (fι : ι → Type _) [∀ i, NCRing (fι i)] : NCRing (MultiProd fι) where
toNeg := (Group.multi_product fι).toNeg
add_neg := (Group.multi_product fι).add_neg
theorem neg_mul [NCRing α] (a b : α) : -a * b = -(a * b) := by
rw [←add_right_cancel _ _ (a * b), neg_add, ←mul_distrib_right, neg_add, zero_mul]
theorem mul_neg [NCRing α] (a b : α) : a * -b = -(a * b) := by
rw [←add_right_cancel _ _ (a * b), neg_add, ←mul_distrib_left, neg_add, mul_zero]
theorem mul_neg_swap [NCRing α] (a b : α) : a * -b = -a * b := by
rw [mul_neg, neg_mul]
theorem neg_one_mul [NCRing α] (a : α) : -1 * a = -a := by
rw [neg_mul, one_mul]
theorem neg_one_mul_add [NCRing α] (a b : α) : -1 * (a + b) = -a + -b := by
rw [mul_distrib_left, neg_one_mul, neg_one_mul]
theorem neg_one_mul_add' [NCRing α] (a b : α) : -1 * (a + b) = -b + -a := by
rw [neg_one_mul, neg_add_distrib]
theorem sub_mul_distrib_left [NCRing α] (a b c : α) : a * (b - c) = a * b - a * c := by
rw [sub_def, mul_distrib_left, mul_neg]; rfl
theorem sub_mul_distrib_right [NCRing α] (a b c : α) : (a - b) * c = a * c - b * c := by
rw [sub_def, mul_distrib_right, neg_mul]; rfl
protected class constructor_ncr (α : Type _) extends Group.constructor_g α, One α, Mul α where
mul_one : ∀ a : α, a * 1 = a
one_mul : ∀ a : α, 1 * a = a
mul_assoc : ∀ a b c : α, (a * b) * c = a * (b * c)
mul_distrib_left : ∀ a b c : α, a * (b + c) = a * b + a * c
mul_distrib_right : ∀ a b c : α, (a + b) * c = a * c + b * c
protected def construct {α : Type _} (c : NCRing.constructor_ncr α) : NCRing α where
toNCSemiring := NCSemiring.construct
{
toconstructor_cm := {
add_zero := c.add_zero
add_assoc := c.add_assoc
add_comm := fun a b => (Group.construct c.toconstructor_g).neg_inj (by
rw [(Group.construct c.toconstructor_g).neg_add_distrib]
have : ∀ a : α, -a = -1 * a := fun a => by
rw [←(Group.construct c.toconstructor_g).add_right_cancel _ _ a,
(Group.construct c.toconstructor_g).neg_add]
conv => rhs rhs rw [←c.one_mul a]
rw [←c.mul_distrib_right, (Group.construct c.toconstructor_g).neg_add,
←(Group.construct c.toconstructor_g).add_right_cancel _ _ (0 * a),
←c.mul_distrib_right, c.add_zero, (Group.construct c.toconstructor_g).zero_add]
rw [this (b + a), c.mul_distrib_left, ←this, ←this])
}
mul_one := c.mul_one
one_mul := c.one_mul
mul_assoc := c.mul_assoc
mul_distrib_left := c.mul_distrib_left
mul_distrib_right := c.mul_distrib_right
mul_zero := fun a => by
rw [←(Group.construct c.toconstructor_g).add_right_cancel _ _ (a * 0),
←c.mul_distrib_left]
conv => rhs rw [(Group.construct c.toconstructor_g).zero_add]
rw [c.add_zero]
zero_mul := fun a => by
rw [←(Group.construct c.toconstructor_g).add_right_cancel _ _ (0 * a),
←c.mul_distrib_right]
conv => rhs rw [(Group.construct c.toconstructor_g).zero_add]
rw [c.add_zero]
}
toNeg := (Group.construct c.toconstructor_g).toNeg
add_neg := (Group.construct c.toconstructor_g).add_neg
protected def to_constructor (α : Type _) [NCRing α] : NCRing.constructor_ncr α where
toconstructor_g := Group.to_constructor α
mul_one := NCSemiring.mul_one
one_mul := NCSemiring.one_mul
mul_assoc := NCSemiring.mul_assoc
mul_distrib_left := NCSemiring.mul_distrib_left
mul_distrib_right := NCSemiring.mul_distrib_right
end NCRing
namespace Ring
open NCSemiring
protected instance Product (α₁ : Type _) (α₂ : Type _) [Ring α₁] [Ring α₂] : Ring (α₁ × α₂) where
toNCRing := NCRing.Product α₁ α₂
mul_comm := (Semiring.Product α₁ α₂).mul_comm
protected instance multi_product {ι : Type _} (fι : ι → Type _) [∀ i, Ring (fι i)] : Ring (MultiProd fι) where
mul_comm := (Semiring.multi_product fι).mul_comm
def is_NonTrivial (α : Type _) [Ring α] : Prop := (1 : α) ≠ 0
def is_NonTrivial.toNonTrivialRing [Ring α] (h : is_NonTrivial α) : NonTrivialRing α where
toNonTrivial.one_neq_zero := h
protected class constructor_r (α : Type _) extends AbelianGroup.constructor_ab α, One α, Mul α where
mul_one : ∀ a : α, a * 1 = a
mul_assoc : ∀ a b c : α, (a * b) * c = a * (b * c)
mul_distrib_left : ∀ a b c : α, a * (b + c) = a * b + a * c
mul_comm : ∀ a b : α, a * b = b * a
protected def construct {α : Type _} (c : Ring.constructor_r α) : Ring α where
toNCRing := NCRing.construct
{
mul_one := c.mul_one
one_mul := fun a => by rw [c.mul_comm]; exact c.mul_one a
mul_assoc := c.mul_assoc
mul_distrib_left := c.mul_distrib_left
mul_distrib_right := fun a b _ => by rw [c.mul_comm, c.mul_comm a, c.mul_comm b]; exact c.mul_distrib_left _ _ _
}
mul_comm := c.mul_comm
protected def to_constructor (α : Type _) [Ring α] : Ring.constructor_r α where
toconstructor_ab := AbelianGroup.to_constructor α
mul_one := NCSemiring.mul_one
mul_assoc := NCSemiring.mul_assoc
mul_distrib_left := NCSemiring.mul_distrib_left
mul_comm := Semiring.mul_comm
end Ring
theorem NonTrivialRing.to_is_NonTrivial [NonTrivialRing α] : Ring.is_NonTrivial α := NonTrivial.one_neq_zero
instance IntRing : NonTrivialRing Int where
toRing := Ring.construct
{
toconstructor_ab := IntGroup.to_constructor
mul_one := Int.mul_one
mul_assoc := Int.mul_assoc
mul_distrib_left := Int.mul_distrib_left
mul_comm := Int.mul_comm
}
toNonTrivial := IntNonTrivial
end M4R
|
lemma setdist_eq_0_closed: "closed S \<Longrightarrow> (setdist {x} S = 0 \<longleftrightarrow> S = {} \<or> x \<in> S)" |
Formal statement is: lemma has_complex_derivative_locally_invertible: assumes holf: "f holomorphic_on S" and S: "\<xi> \<in> S" "open S" and dnz: "deriv f \<xi> \<noteq> 0" obtains r where "r > 0" "ball \<xi> r \<subseteq> S" "open (f ` (ball \<xi> r))" "inj_on f (ball \<xi> r)" Informal statement is: If $f$ is holomorphic on a neighborhood of $\xi$ and $f'(\xi) \neq 0$, then there exists a neighborhood $U$ of $\xi$ such that $f(U)$ is open and $f$ is injective on $U$. |
[STATEMENT]
lemma check_while:
shows "\<Theta>; \<Phi>; {||}; GNil; \<Delta> \<turnstile> WHILE s1 DO { s2 } \<Leftarrow> \<tau> \<Longrightarrow> atom x \<sharp> (s1, s2) \<Longrightarrow> atom z' \<sharp> x \<Longrightarrow>
\<Theta>; \<Phi>; {||}; GNil; \<Delta> \<turnstile> LET x : (\<lbrace> z' : B_bool | TRUE \<rbrace>) = s1 IN (IF (V_var x) THEN (s2 ;; (WHILE s1 DO {s2}))
ELSE ([ V_lit L_unit]\<^sup>s)) \<Leftarrow> \<tau>" and
"check_branch_s \<Theta> \<Phi> {||} GNil \<Delta> tid dc const v cs \<tau> \<Longrightarrow> True" and
"check_branch_list \<Theta> \<Phi> {||} \<Gamma> \<Delta> tid dclist v css \<tau> \<Longrightarrow> True"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (\<lbrakk> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> WHILE s1 DO { s2 } \<Leftarrow> \<tau>; atom x \<sharp> (s1, s2); atom z' \<sharp> x\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET x : \<lbrace> z' : B_bool | TRUE \<rbrace> = s1 IN IF [ x ]\<^sup>v THEN s2 ;; WHILE s1 DO { s2 } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>) &&& ( \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> ; tid ; dc ; const ; v \<turnstile> cs \<Leftarrow> \<tau> \<Longrightarrow> True) &&& ( \<Theta> ; \<Phi> ; {||} ; \<Gamma> ; \<Delta> ; tid ; dclist ; v \<turnstile> css \<Leftarrow> \<tau> \<Longrightarrow> True)
[PROOF STEP]
proof(nominal_induct "{||}::bv fset" GNil \<Delta> "AS_while s1 s2" \<tau> and \<tau> and \<tau> avoiding: s1 s2 x z' rule: check_s_check_branch_s_check_branch_list.strong_induct)
[PROOF STATE]
proof (state)
goal (4 subgoals):
1. \<And>\<Theta> \<B> \<Gamma> \<Delta> \<tau> const x \<Phi> tid cons v s s1 s2 xa z'. \<lbrakk>atom x \<sharp> s1; atom x \<sharp> s2; atom x \<sharp> xa; atom x \<sharp> z'; \<Theta> ; \<B> ; \<Gamma> \<turnstile>\<^sub>w\<^sub>f \<Delta> ; \<turnstile>\<^sub>w\<^sub>f \<Theta> ; \<Theta> ; \<B> ; \<Gamma> \<turnstile>\<^sub>w\<^sub>f \<tau> ; \<Theta> ; {||} ; GNil \<turnstile>\<^sub>w\<^sub>f const ; atom x \<sharp> \<Theta>; atom x \<sharp> \<Phi>; atom x \<sharp> \<B>; atom x \<sharp> \<Gamma>; atom x \<sharp> \<Delta>; atom x \<sharp> tid; atom x \<sharp> cons; atom x \<sharp> const; atom x \<sharp> v; atom x \<sharp> \<tau>; \<Theta> ; \<Phi> ; \<B> ; (x, b_of const, [ v ]\<^sup>c\<^sup>e == [ V_cons tid cons [ x ]\<^sup>v ]\<^sup>c\<^sup>e AND c_of const x ) #\<^sub>\<Gamma> \<Gamma> ; \<Delta> \<turnstile> s \<Leftarrow> \<tau>\<rbrakk> \<Longrightarrow> True
2. \<And>\<Theta> \<Phi> \<B> \<Gamma> \<Delta> tid cons const v cs \<tau> dclist css s1 s2 x z'. \<lbrakk> \<Theta> ; \<Phi> ; \<B> ; \<Gamma> ; \<Delta> ; tid ; cons ; const ; v \<turnstile> cs \<Leftarrow> \<tau>; \<And>b ba bb bc. True; \<Theta> ; \<Phi> ; \<B> ; \<Gamma> ; \<Delta> ; tid ; dclist ; v \<turnstile> css \<Leftarrow> \<tau>; \<And>b ba bb bc. True\<rbrakk> \<Longrightarrow> True
3. \<And>\<Theta> \<Phi> \<B> \<Gamma> \<Delta> tid cons const v cs \<tau> s1 s2 x z'. \<lbrakk> \<Theta> ; \<Phi> ; \<B> ; \<Gamma> ; \<Delta> ; tid ; cons ; const ; v \<turnstile> cs \<Leftarrow> \<tau>; \<And>b ba bb bc. True\<rbrakk> \<Longrightarrow> True
4. \<And>\<Theta> \<Phi> \<Delta> s1 z s2 \<tau>' x z'. \<lbrakk> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>; \<And>b ba bb bc. \<lbrakk>s1 = WHILE b DO { ba } ; atom bb \<sharp> (b, ba); atom bc \<sharp> bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET bb : \<lbrace> bc : B_bool | TRUE \<rbrace> = b IN IF [ bb ]\<^sup>v THEN ba ;; WHILE b DO { ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>; \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>; \<And>b ba bb bc. \<lbrakk>s2 = WHILE b DO { ba } ; atom bb \<sharp> (b, ba); atom bc \<sharp> bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET bb : \<lbrace> bc : B_bool | TRUE \<rbrace> = b IN IF [ bb ]\<^sup>v THEN ba ;; WHILE b DO { ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>; \<Theta> ; {||} ; GNil \<turnstile> \<lbrace> z : B_unit | TRUE \<rbrace> \<lesssim> \<tau>'; atom x \<sharp> (s1, s2); atom z' \<sharp> x\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET x : \<lbrace> z' : B_bool | TRUE \<rbrace> = s1 IN IF [ x ]\<^sup>v THEN s2 ;; WHILE s1 DO { s2 } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
[PROOF STEP]
case (check_whileI \<Theta> \<Phi> \<Delta> s1 z s2 \<tau>')
[PROOF STATE]
proof (state)
this:
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>
\<lbrakk>s1 = WHILE ?b DO { ?ba } ; atom ?bb \<sharp> (?b, ?ba); atom ?bc \<sharp> ?bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET ?bb : \<lbrace> ?bc : B_bool | TRUE \<rbrace> = ?b IN IF [ ?bb ]\<^sup>v THEN ?ba ;; WHILE ?b DO { ?ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
\<lbrakk>s2 = WHILE ?b DO { ?ba } ; atom ?bb \<sharp> (?b, ?ba); atom ?bc \<sharp> ?bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET ?bb : \<lbrace> ?bc : B_bool | TRUE \<rbrace> = ?b IN IF [ ?bb ]\<^sup>v THEN ?ba ;; WHILE ?b DO { ?ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
\<Theta> ; {||} ; GNil \<turnstile> \<lbrace> z : B_unit | TRUE \<rbrace> \<lesssim> \<tau>'
atom x \<sharp> (s1, s2)
atom z' \<sharp> x
goal (4 subgoals):
1. \<And>\<Theta> \<B> \<Gamma> \<Delta> \<tau> const x \<Phi> tid cons v s s1 s2 xa z'. \<lbrakk>atom x \<sharp> s1; atom x \<sharp> s2; atom x \<sharp> xa; atom x \<sharp> z'; \<Theta> ; \<B> ; \<Gamma> \<turnstile>\<^sub>w\<^sub>f \<Delta> ; \<turnstile>\<^sub>w\<^sub>f \<Theta> ; \<Theta> ; \<B> ; \<Gamma> \<turnstile>\<^sub>w\<^sub>f \<tau> ; \<Theta> ; {||} ; GNil \<turnstile>\<^sub>w\<^sub>f const ; atom x \<sharp> \<Theta>; atom x \<sharp> \<Phi>; atom x \<sharp> \<B>; atom x \<sharp> \<Gamma>; atom x \<sharp> \<Delta>; atom x \<sharp> tid; atom x \<sharp> cons; atom x \<sharp> const; atom x \<sharp> v; atom x \<sharp> \<tau>; \<Theta> ; \<Phi> ; \<B> ; (x, b_of const, [ v ]\<^sup>c\<^sup>e == [ V_cons tid cons [ x ]\<^sup>v ]\<^sup>c\<^sup>e AND c_of const x ) #\<^sub>\<Gamma> \<Gamma> ; \<Delta> \<turnstile> s \<Leftarrow> \<tau>\<rbrakk> \<Longrightarrow> True
2. \<And>\<Theta> \<Phi> \<B> \<Gamma> \<Delta> tid cons const v cs \<tau> dclist css s1 s2 x z'. \<lbrakk> \<Theta> ; \<Phi> ; \<B> ; \<Gamma> ; \<Delta> ; tid ; cons ; const ; v \<turnstile> cs \<Leftarrow> \<tau>; \<And>b ba bb bc. True; \<Theta> ; \<Phi> ; \<B> ; \<Gamma> ; \<Delta> ; tid ; dclist ; v \<turnstile> css \<Leftarrow> \<tau>; \<And>b ba bb bc. True\<rbrakk> \<Longrightarrow> True
3. \<And>\<Theta> \<Phi> \<B> \<Gamma> \<Delta> tid cons const v cs \<tau> s1 s2 x z'. \<lbrakk> \<Theta> ; \<Phi> ; \<B> ; \<Gamma> ; \<Delta> ; tid ; cons ; const ; v \<turnstile> cs \<Leftarrow> \<tau>; \<And>b ba bb bc. True\<rbrakk> \<Longrightarrow> True
4. \<And>\<Theta> \<Phi> \<Delta> s1 z s2 \<tau>' x z'. \<lbrakk> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>; \<And>b ba bb bc. \<lbrakk>s1 = WHILE b DO { ba } ; atom bb \<sharp> (b, ba); atom bc \<sharp> bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET bb : \<lbrace> bc : B_bool | TRUE \<rbrace> = b IN IF [ bb ]\<^sup>v THEN ba ;; WHILE b DO { ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>; \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>; \<And>b ba bb bc. \<lbrakk>s2 = WHILE b DO { ba } ; atom bb \<sharp> (b, ba); atom bc \<sharp> bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET bb : \<lbrace> bc : B_bool | TRUE \<rbrace> = b IN IF [ bb ]\<^sup>v THEN ba ;; WHILE b DO { ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>; \<Theta> ; {||} ; GNil \<turnstile> \<lbrace> z : B_unit | TRUE \<rbrace> \<lesssim> \<tau>'; atom x \<sharp> (s1, s2); atom z' \<sharp> x\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET x : \<lbrace> z' : B_bool | TRUE \<rbrace> = s1 IN IF [ x ]\<^sup>v THEN s2 ;; WHILE s1 DO { s2 } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
[PROOF STEP]
have teq:"\<lbrace> z' : B_bool | TRUE \<rbrace> = \<lbrace> z : B_bool | TRUE \<rbrace>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<lbrace> z' : B_bool | TRUE \<rbrace> = \<lbrace> z : B_bool | TRUE \<rbrace>
[PROOF STEP]
using \<tau>.eq_iff
[PROOF STATE]
proof (prove)
using this:
(\<lbrace> ?x : ?b | ?c \<rbrace> = \<lbrace> ?xa : ?ba | ?ca \<rbrace>) = ([[atom ?x]]lst. ?c = [[atom ?xa]]lst. ?ca \<and> ?b = ?ba)
goal (1 subgoal):
1. \<lbrace> z' : B_bool | TRUE \<rbrace> = \<lbrace> z : B_bool | TRUE \<rbrace>
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<lbrace> z' : B_bool | TRUE \<rbrace> = \<lbrace> z : B_bool | TRUE \<rbrace>
goal (4 subgoals):
1. \<And>\<Theta> \<B> \<Gamma> \<Delta> \<tau> const x \<Phi> tid cons v s s1 s2 xa z'. \<lbrakk>atom x \<sharp> s1; atom x \<sharp> s2; atom x \<sharp> xa; atom x \<sharp> z'; \<Theta> ; \<B> ; \<Gamma> \<turnstile>\<^sub>w\<^sub>f \<Delta> ; \<turnstile>\<^sub>w\<^sub>f \<Theta> ; \<Theta> ; \<B> ; \<Gamma> \<turnstile>\<^sub>w\<^sub>f \<tau> ; \<Theta> ; {||} ; GNil \<turnstile>\<^sub>w\<^sub>f const ; atom x \<sharp> \<Theta>; atom x \<sharp> \<Phi>; atom x \<sharp> \<B>; atom x \<sharp> \<Gamma>; atom x \<sharp> \<Delta>; atom x \<sharp> tid; atom x \<sharp> cons; atom x \<sharp> const; atom x \<sharp> v; atom x \<sharp> \<tau>; \<Theta> ; \<Phi> ; \<B> ; (x, b_of const, [ v ]\<^sup>c\<^sup>e == [ V_cons tid cons [ x ]\<^sup>v ]\<^sup>c\<^sup>e AND c_of const x ) #\<^sub>\<Gamma> \<Gamma> ; \<Delta> \<turnstile> s \<Leftarrow> \<tau>\<rbrakk> \<Longrightarrow> True
2. \<And>\<Theta> \<Phi> \<B> \<Gamma> \<Delta> tid cons const v cs \<tau> dclist css s1 s2 x z'. \<lbrakk> \<Theta> ; \<Phi> ; \<B> ; \<Gamma> ; \<Delta> ; tid ; cons ; const ; v \<turnstile> cs \<Leftarrow> \<tau>; \<And>b ba bb bc. True; \<Theta> ; \<Phi> ; \<B> ; \<Gamma> ; \<Delta> ; tid ; dclist ; v \<turnstile> css \<Leftarrow> \<tau>; \<And>b ba bb bc. True\<rbrakk> \<Longrightarrow> True
3. \<And>\<Theta> \<Phi> \<B> \<Gamma> \<Delta> tid cons const v cs \<tau> s1 s2 x z'. \<lbrakk> \<Theta> ; \<Phi> ; \<B> ; \<Gamma> ; \<Delta> ; tid ; cons ; const ; v \<turnstile> cs \<Leftarrow> \<tau>; \<And>b ba bb bc. True\<rbrakk> \<Longrightarrow> True
4. \<And>\<Theta> \<Phi> \<Delta> s1 z s2 \<tau>' x z'. \<lbrakk> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>; \<And>b ba bb bc. \<lbrakk>s1 = WHILE b DO { ba } ; atom bb \<sharp> (b, ba); atom bc \<sharp> bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET bb : \<lbrace> bc : B_bool | TRUE \<rbrace> = b IN IF [ bb ]\<^sup>v THEN ba ;; WHILE b DO { ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>; \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>; \<And>b ba bb bc. \<lbrakk>s2 = WHILE b DO { ba } ; atom bb \<sharp> (b, ba); atom bc \<sharp> bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET bb : \<lbrace> bc : B_bool | TRUE \<rbrace> = b IN IF [ bb ]\<^sup>v THEN ba ;; WHILE b DO { ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>; \<Theta> ; {||} ; GNil \<turnstile> \<lbrace> z : B_unit | TRUE \<rbrace> \<lesssim> \<tau>'; atom x \<sharp> (s1, s2); atom z' \<sharp> x\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET x : \<lbrace> z' : B_bool | TRUE \<rbrace> = s1 IN IF [ x ]\<^sup>v THEN s2 ;; WHILE s1 DO { s2 } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET x : \<lbrace> z' : B_bool | TRUE \<rbrace> = s1 IN IF [ x ]\<^sup>v THEN s2 ;; WHILE s1 DO { s2 } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (3 subgoals):
1. atom x \<sharp> (\<Theta>, \<Phi>, {||}, GNil, \<Delta>, \<lbrace> z' : B_bool | TRUE \<rbrace>, s1, \<tau>')
2. \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z' : B_bool | TRUE \<rbrace>
3. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> IF [ x ]\<^sup>v THEN s2 ;; WHILE s1 DO { s2 } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
[PROOF STEP]
have " atom x \<sharp> \<tau>' "
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. atom x \<sharp> \<tau>'
[PROOF STEP]
using wfT_nil_supp fresh_def subtype_wfT check_whileI(5)
[PROOF STATE]
proof (prove)
using this:
?\<Theta> ; {||} ; GNil \<turnstile>\<^sub>w\<^sub>f ?t \<Longrightarrow> supp ?t = {}
?a \<sharp> ?x \<equiv> ?a \<notin> supp ?x
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile> ?t1.0 \<lesssim> ?t2.0 \<Longrightarrow> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?t1.0 \<and> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?t2.0
\<Theta> ; {||} ; GNil \<turnstile> \<lbrace> z : B_unit | TRUE \<rbrace> \<lesssim> \<tau>'
goal (1 subgoal):
1. atom x \<sharp> \<tau>'
[PROOF STEP]
by fast
[PROOF STATE]
proof (state)
this:
atom x \<sharp> \<tau>'
goal (3 subgoals):
1. atom x \<sharp> (\<Theta>, \<Phi>, {||}, GNil, \<Delta>, \<lbrace> z' : B_bool | TRUE \<rbrace>, s1, \<tau>')
2. \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z' : B_bool | TRUE \<rbrace>
3. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> IF [ x ]\<^sup>v THEN s2 ;; WHILE s1 DO { s2 } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
atom x \<sharp> \<tau>'
goal (3 subgoals):
1. atom x \<sharp> (\<Theta>, \<Phi>, {||}, GNil, \<Delta>, \<lbrace> z' : B_bool | TRUE \<rbrace>, s1, \<tau>')
2. \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z' : B_bool | TRUE \<rbrace>
3. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> IF [ x ]\<^sup>v THEN s2 ;; WHILE s1 DO { s2 } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
[PROOF STEP]
have "atom x \<sharp> \<lbrace> z' : B_bool | TRUE \<rbrace> "
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. atom x \<sharp> \<lbrace> z' : B_bool | TRUE \<rbrace>
[PROOF STEP]
using \<tau>.fresh c.fresh b.fresh
[PROOF STATE]
proof (prove)
using this:
?a \<sharp> \<lbrace> ?x : ?b | ?c \<rbrace> = ((?a \<sharp> ?c \<or> ?a \<in> set [atom ?x]) \<and> ?a \<sharp> ?b)
?a \<sharp> (TRUE)
?a \<sharp> (FALSE)
?a \<sharp> (?c1.0 AND ?c2.0 ) = (?a \<sharp> ?c1.0 \<and> ?a \<sharp> ?c2.0)
?a \<sharp> (?c1.0 OR ?c2.0 ) = (?a \<sharp> ?c1.0 \<and> ?a \<sharp> ?c2.0)
?a \<sharp> (\<not> ?c ) = ?a \<sharp> ?c
?a \<sharp> (?c1.0 IMP ?c2.0 ) = (?a \<sharp> ?c1.0 \<and> ?a \<sharp> ?c2.0)
?a \<sharp> (?ce1.0 == ?ce2.0 ) = (?a \<sharp> ?ce1.0 \<and> ?a \<sharp> ?ce2.0)
?a \<sharp> B_int
?a \<sharp> B_bool
?a \<sharp> B_id ?list = ?a \<sharp> ?list
?a \<sharp> [ ?b1.0 , ?b2.0 ]\<^sup>b = (?a \<sharp> ?b1.0 \<and> ?a \<sharp> ?b2.0)
?a \<sharp> B_unit
?a \<sharp> B_bitvec
?a \<sharp> B_var ?bv = ?a \<sharp> ?bv
?a \<sharp> B_app ?list ?b = (?a \<sharp> ?list \<and> ?a \<sharp> ?b)
goal (1 subgoal):
1. atom x \<sharp> \<lbrace> z' : B_bool | TRUE \<rbrace>
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
atom x \<sharp> \<lbrace> z' : B_bool | TRUE \<rbrace>
goal (3 subgoals):
1. atom x \<sharp> (\<Theta>, \<Phi>, {||}, GNil, \<Delta>, \<lbrace> z' : B_bool | TRUE \<rbrace>, s1, \<tau>')
2. \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z' : B_bool | TRUE \<rbrace>
3. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> IF [ x ]\<^sup>v THEN s2 ;; WHILE s1 DO { s2 } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
atom x \<sharp> \<tau>'
atom x \<sharp> \<lbrace> z' : B_bool | TRUE \<rbrace>
[PROOF STEP]
show \<open>atom x \<sharp> (\<Theta>, \<Phi>, {||}, GNil, \<Delta>, \<lbrace> z' : B_bool | TRUE \<rbrace>, s1, \<tau>')\<close>
[PROOF STATE]
proof (prove)
using this:
atom x \<sharp> \<tau>'
atom x \<sharp> \<lbrace> z' : B_bool | TRUE \<rbrace>
goal (1 subgoal):
1. atom x \<sharp> (\<Theta>, \<Phi>, {||}, GNil, \<Delta>, \<lbrace> z' : B_bool | TRUE \<rbrace>, s1, \<tau>')
[PROOF STEP]
apply(unfold fresh_prodN)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<lbrakk>atom x \<sharp> \<tau>'; atom x \<sharp> \<lbrace> z' : B_bool | TRUE \<rbrace>\<rbrakk> \<Longrightarrow> atom x \<sharp> \<Theta> \<and> atom x \<sharp> \<Phi> \<and> atom x \<sharp> {||} \<and> atom x \<sharp> GNil \<and> atom x \<sharp> \<Delta> \<and> atom x \<sharp> \<lbrace> z' : B_bool | TRUE \<rbrace> \<and> atom x \<sharp> s1 \<and> atom x \<sharp> \<tau>'
[PROOF STEP]
using check_whileI wb_x_fresh check_s_wf wfD_x_fresh fresh_empty_fset fresh_GNil fresh_Pair \<open>atom x \<sharp> \<tau>'\<close>
[PROOF STATE]
proof (prove)
using this:
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>
\<lbrakk>s1 = WHILE ?b DO { ?ba } ; atom ?bb \<sharp> (?b, ?ba); atom ?bc \<sharp> ?bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET ?bb : \<lbrace> ?bc : B_bool | TRUE \<rbrace> = ?b IN IF [ ?bb ]\<^sup>v THEN ?ba ;; WHILE ?b DO { ?ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
\<lbrakk>s2 = WHILE ?b DO { ?ba } ; atom ?bb \<sharp> (?b, ?ba); atom ?bc \<sharp> ?bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET ?bb : \<lbrace> ?bc : B_bool | TRUE \<rbrace> = ?b IN IF [ ?bb ]\<^sup>v THEN ?ba ;; WHILE ?b DO { ?ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
\<Theta> ; {||} ; GNil \<turnstile> \<lbrace> z : B_unit | TRUE \<rbrace> \<lesssim> \<tau>'
atom x \<sharp> (s1, s2)
atom z' \<sharp> x
\<turnstile>\<^sub>w\<^sub>f ?T \<Longrightarrow> atom ?x \<sharp> ?T
?T \<turnstile>\<^sub>w\<^sub>f ?P \<Longrightarrow> atom ?x \<sharp> ?P
\<lbrakk>atom ?x \<sharp> ?\<Gamma>; ?P ; ?B ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<rbrakk> \<Longrightarrow> atom ?x \<sharp> ?\<Delta>
\<lbrakk> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<tau> ; atom ?x \<sharp> ?\<Gamma>\<rbrakk> \<Longrightarrow> atom ?x \<sharp> ?\<tau>
\<lbrakk> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?v : ?b ; atom ?x \<sharp> ?\<Gamma>\<rbrakk> \<Longrightarrow> atom ?x \<sharp> ?v
?\<Theta> ; ?\<Phi> ; ?B ; ?\<Gamma> ; ?\<Delta> \<turnstile> ?s \<Leftarrow> ?\<tau> \<Longrightarrow> ?\<Theta> ; ?B \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> ?\<Theta> ; ?B ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<tau> \<and> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> ; ?B ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<and> ?\<Theta> ; ?\<Phi> ; ?B ; ?\<Gamma> ; ?\<Delta> \<turnstile>\<^sub>w\<^sub>f ?s : b_of ?\<tau>
\<lbrakk>atom ?x \<sharp> ?\<Gamma>; ?P ; ?B ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<rbrakk> \<Longrightarrow> atom ?x \<sharp> ?\<Delta>
?a \<sharp> {||}
?a \<sharp> GNil
?a \<sharp> (?x, ?y) = (?a \<sharp> ?x \<and> ?a \<sharp> ?y)
atom x \<sharp> \<tau>'
goal (1 subgoal):
1. \<lbrakk>atom x \<sharp> \<tau>'; atom x \<sharp> \<lbrace> z' : B_bool | TRUE \<rbrace>\<rbrakk> \<Longrightarrow> atom x \<sharp> \<Theta> \<and> atom x \<sharp> \<Phi> \<and> atom x \<sharp> {||} \<and> atom x \<sharp> GNil \<and> atom x \<sharp> \<Delta> \<and> atom x \<sharp> \<lbrace> z' : B_bool | TRUE \<rbrace> \<and> atom x \<sharp> s1 \<and> atom x \<sharp> \<tau>'
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
atom x \<sharp> (\<Theta>, \<Phi>, {||}, GNil, \<Delta>, \<lbrace> z' : B_bool | TRUE \<rbrace>, s1, \<tau>')
goal (2 subgoals):
1. \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z' : B_bool | TRUE \<rbrace>
2. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> IF [ x ]\<^sup>v THEN s2 ;; WHILE s1 DO { s2 } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
[PROOF STEP]
show \<open> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z' : B_bool | TRUE \<rbrace>\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z' : B_bool | TRUE \<rbrace>
[PROOF STEP]
using check_whileI teq
[PROOF STATE]
proof (prove)
using this:
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>
\<lbrakk>s1 = WHILE ?b DO { ?ba } ; atom ?bb \<sharp> (?b, ?ba); atom ?bc \<sharp> ?bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET ?bb : \<lbrace> ?bc : B_bool | TRUE \<rbrace> = ?b IN IF [ ?bb ]\<^sup>v THEN ?ba ;; WHILE ?b DO { ?ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
\<lbrakk>s2 = WHILE ?b DO { ?ba } ; atom ?bb \<sharp> (?b, ?ba); atom ?bc \<sharp> ?bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET ?bb : \<lbrace> ?bc : B_bool | TRUE \<rbrace> = ?b IN IF [ ?bb ]\<^sup>v THEN ?ba ;; WHILE ?b DO { ?ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
\<Theta> ; {||} ; GNil \<turnstile> \<lbrace> z : B_unit | TRUE \<rbrace> \<lesssim> \<tau>'
atom x \<sharp> (s1, s2)
atom z' \<sharp> x
\<lbrace> z' : B_bool | TRUE \<rbrace> = \<lbrace> z : B_bool | TRUE \<rbrace>
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z' : B_bool | TRUE \<rbrace>
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z' : B_bool | TRUE \<rbrace>
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> IF [ x ]\<^sup>v THEN s2 ;; WHILE s1 DO { s2 } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
[PROOF STEP]
let ?G = "(x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil"
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> IF [ x ]\<^sup>v THEN s2 ;; WHILE s1 DO { s2 } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
[PROOF STEP]
have cof:"(c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) = C_true"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x = (TRUE)
[PROOF STEP]
using c_of.simps check_whileI subst_cv.simps
[PROOF STATE]
proof (prove)
using this:
atom ?z \<sharp> ?x \<Longrightarrow> c_of \<lbrace> ?z : ?b | ?c \<rbrace> ?x = ?c[?z::=[ ?x ]\<^sup>v]\<^sub>c\<^sub>v
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>
\<lbrakk>s1 = WHILE ?b DO { ?ba } ; atom ?bb \<sharp> (?b, ?ba); atom ?bc \<sharp> ?bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET ?bb : \<lbrace> ?bc : B_bool | TRUE \<rbrace> = ?b IN IF [ ?bb ]\<^sup>v THEN ?ba ;; WHILE ?b DO { ?ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
\<lbrakk>s2 = WHILE ?b DO { ?ba } ; atom ?bb \<sharp> (?b, ?ba); atom ?bc \<sharp> ?bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET ?bb : \<lbrace> ?bc : B_bool | TRUE \<rbrace> = ?b IN IF [ ?bb ]\<^sup>v THEN ?ba ;; WHILE ?b DO { ?ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
\<Theta> ; {||} ; GNil \<turnstile> \<lbrace> z : B_unit | TRUE \<rbrace> \<lesssim> \<tau>'
atom x \<sharp> (s1, s2)
atom z' \<sharp> x
(TRUE)[?x::=?v]\<^sub>c\<^sub>v = (TRUE)
(FALSE)[?x::=?v]\<^sub>c\<^sub>v = (FALSE)
(?c1.0 AND ?c2.0 )[?x::=?v]\<^sub>c\<^sub>v = (?c1.0[?x::=?v]\<^sub>c\<^sub>v AND ?c2.0[?x::=?v]\<^sub>c\<^sub>v )
(?c1.0 OR ?c2.0 )[?x::=?v]\<^sub>c\<^sub>v = (?c1.0[?x::=?v]\<^sub>c\<^sub>v OR ?c2.0[?x::=?v]\<^sub>c\<^sub>v )
(?c1.0 IMP ?c2.0 )[?x::=?v]\<^sub>c\<^sub>v = (?c1.0[?x::=?v]\<^sub>c\<^sub>v IMP ?c2.0[?x::=?v]\<^sub>c\<^sub>v )
(?e1.0 == ?e2.0 )[?x::=?v]\<^sub>c\<^sub>v = (?e1.0[?x::=?v]\<^sub>c\<^sub>e\<^sub>v == ?e2.0[?x::=?v]\<^sub>c\<^sub>e\<^sub>v )
(\<not> ?c )[?x::=?v]\<^sub>c\<^sub>v = (\<not> ?c[?x::=?v]\<^sub>c\<^sub>v )
goal (1 subgoal):
1. c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x = (TRUE)
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x = (TRUE)
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> IF [ x ]\<^sup>v THEN s2 ;; WHILE s1 DO { s2 } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
[PROOF STEP]
have wfg: "\<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f ?G"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (4 subgoals):
1. c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x \<in> {TRUE, FALSE}
2. \<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f GNil
3. atom x \<sharp> GNil
4. \<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f b_of \<lbrace> z' : B_bool | TRUE \<rbrace>
[PROOF STEP]
show "c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x \<in> {TRUE, FALSE}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x \<in> {TRUE, FALSE}
[PROOF STEP]
using subst_cv.simps cof
[PROOF STATE]
proof (prove)
using this:
(TRUE)[?x::=?v]\<^sub>c\<^sub>v = (TRUE)
(FALSE)[?x::=?v]\<^sub>c\<^sub>v = (FALSE)
(?c1.0 AND ?c2.0 )[?x::=?v]\<^sub>c\<^sub>v = (?c1.0[?x::=?v]\<^sub>c\<^sub>v AND ?c2.0[?x::=?v]\<^sub>c\<^sub>v )
(?c1.0 OR ?c2.0 )[?x::=?v]\<^sub>c\<^sub>v = (?c1.0[?x::=?v]\<^sub>c\<^sub>v OR ?c2.0[?x::=?v]\<^sub>c\<^sub>v )
(?c1.0 IMP ?c2.0 )[?x::=?v]\<^sub>c\<^sub>v = (?c1.0[?x::=?v]\<^sub>c\<^sub>v IMP ?c2.0[?x::=?v]\<^sub>c\<^sub>v )
(?e1.0 == ?e2.0 )[?x::=?v]\<^sub>c\<^sub>v = (?e1.0[?x::=?v]\<^sub>c\<^sub>e\<^sub>v == ?e2.0[?x::=?v]\<^sub>c\<^sub>e\<^sub>v )
(\<not> ?c )[?x::=?v]\<^sub>c\<^sub>v = (\<not> ?c[?x::=?v]\<^sub>c\<^sub>v )
c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x = (TRUE)
goal (1 subgoal):
1. c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x \<in> {TRUE, FALSE}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x \<in> {TRUE, FALSE}
goal (3 subgoals):
1. \<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f GNil
2. atom x \<sharp> GNil
3. \<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f b_of \<lbrace> z' : B_bool | TRUE \<rbrace>
[PROOF STEP]
show "\<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f GNil "
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f GNil
[PROOF STEP]
using wfG_nilI check_whileI wfX_wfY check_s_wf
[PROOF STATE]
proof (prove)
using this:
\<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f GNil
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>
\<lbrakk>s1 = WHILE ?b DO { ?ba } ; atom ?bb \<sharp> (?b, ?ba); atom ?bc \<sharp> ?bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET ?bb : \<lbrace> ?bc : B_bool | TRUE \<rbrace> = ?b IN IF [ ?bb ]\<^sup>v THEN ?ba ;; WHILE ?b DO { ?ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
\<lbrakk>s2 = WHILE ?b DO { ?ba } ; atom ?bb \<sharp> (?b, ?ba); atom ?bc \<sharp> ?bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET ?bb : \<lbrace> ?bc : B_bool | TRUE \<rbrace> = ?b IN IF [ ?bb ]\<^sup>v THEN ?ba ;; WHILE ?b DO { ?ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
\<Theta> ; {||} ; GNil \<turnstile> \<lbrace> z : B_unit | TRUE \<rbrace> \<lesssim> \<tau>'
atom x \<sharp> (s1, s2)
atom z' \<sharp> x
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?v : ?b \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?c \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<Longrightarrow> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<tau> \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f b_of ?\<tau>
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?ts \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
\<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<Longrightarrow> True
?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?b \<Longrightarrow> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?ce : ?b \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?td \<Longrightarrow> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<Phi> ; ?\<B> ; ?\<Gamma> ; ?\<Delta> \<turnstile>\<^sub>w\<^sub>f ?e : ?b \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi>
?\<Theta> ; ?\<Phi> ; ?\<B> ; ?\<Gamma> ; ?\<Delta> \<turnstile>\<^sub>w\<^sub>f ?s : ?b \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi>
?\<Theta> ; ?\<Phi> ; ?\<B> ; ?\<Gamma> ; ?\<Delta> ; ?tid ; ?dc ; ?t \<turnstile>\<^sub>w\<^sub>f ?cs : ?b \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi>
?\<Theta> ; ?\<Phi> ; ?\<B> ; ?\<Gamma> ; ?\<Delta> ; ?tid ; ?dclist \<turnstile>\<^sub>w\<^sub>f ?css : ?b \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi>
?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi> \<Longrightarrow> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<Phi> \<turnstile>\<^sub>w\<^sub>f ?ftq \<Longrightarrow> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<Phi> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?ft \<Longrightarrow> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<Phi> ; ?B ; ?\<Gamma> ; ?\<Delta> \<turnstile> ?s \<Leftarrow> ?\<tau> \<Longrightarrow> ?\<Theta> ; ?B \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> ?\<Theta> ; ?B ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<tau> \<and> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> ; ?B ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<and> ?\<Theta> ; ?\<Phi> ; ?B ; ?\<Gamma> ; ?\<Delta> \<turnstile>\<^sub>w\<^sub>f ?s : b_of ?\<tau>
goal (1 subgoal):
1. \<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f GNil
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
\<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f GNil
goal (2 subgoals):
1. atom x \<sharp> GNil
2. \<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f b_of \<lbrace> z' : B_bool | TRUE \<rbrace>
[PROOF STEP]
show "atom x \<sharp> GNil"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. atom x \<sharp> GNil
[PROOF STEP]
using fresh_GNil
[PROOF STATE]
proof (prove)
using this:
?a \<sharp> GNil
goal (1 subgoal):
1. atom x \<sharp> GNil
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
atom x \<sharp> GNil
goal (1 subgoal):
1. \<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f b_of \<lbrace> z' : B_bool | TRUE \<rbrace>
[PROOF STEP]
show "\<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f b_of \<lbrace> z' : B_bool | TRUE \<rbrace> "
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f b_of \<lbrace> z' : B_bool | TRUE \<rbrace>
[PROOF STEP]
using wfB_boolI wfX_wfY check_s_wf b_of.simps
[PROOF STATE]
proof (prove)
using this:
\<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f B_bool
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?v : ?b \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?c \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<Longrightarrow> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<tau> \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f b_of ?\<tau>
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?ts \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
\<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<Longrightarrow> True
?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?b \<Longrightarrow> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?ce : ?b \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?td \<Longrightarrow> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<Phi> ; ?\<B> ; ?\<Gamma> ; ?\<Delta> \<turnstile>\<^sub>w\<^sub>f ?e : ?b \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi>
?\<Theta> ; ?\<Phi> ; ?\<B> ; ?\<Gamma> ; ?\<Delta> \<turnstile>\<^sub>w\<^sub>f ?s : ?b \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi>
?\<Theta> ; ?\<Phi> ; ?\<B> ; ?\<Gamma> ; ?\<Delta> ; ?tid ; ?dc ; ?t \<turnstile>\<^sub>w\<^sub>f ?cs : ?b \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi>
?\<Theta> ; ?\<Phi> ; ?\<B> ; ?\<Gamma> ; ?\<Delta> ; ?tid ; ?dclist \<turnstile>\<^sub>w\<^sub>f ?css : ?b \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi>
?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi> \<Longrightarrow> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<Phi> \<turnstile>\<^sub>w\<^sub>f ?ftq \<Longrightarrow> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<Phi> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?ft \<Longrightarrow> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<Phi> ; ?B ; ?\<Gamma> ; ?\<Delta> \<turnstile> ?s \<Leftarrow> ?\<tau> \<Longrightarrow> ?\<Theta> ; ?B \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> ?\<Theta> ; ?B ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<tau> \<and> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> ; ?B ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<and> ?\<Theta> ; ?\<Phi> ; ?B ; ?\<Gamma> ; ?\<Delta> \<turnstile>\<^sub>w\<^sub>f ?s : b_of ?\<tau>
b_of \<lbrace> ?z : ?b | ?c \<rbrace> = ?b
goal (1 subgoal):
1. \<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f b_of \<lbrace> z' : B_bool | TRUE \<rbrace>
[PROOF STEP]
by (metis \<open>\<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f GNil\<close>)
[PROOF STATE]
proof (state)
this:
\<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f b_of \<lbrace> z' : B_bool | TRUE \<rbrace>
goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> IF [ x ]\<^sup>v THEN s2 ;; WHILE s1 DO { s2 } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
[PROOF STEP]
obtain zz::x where zf:\<open>atom zz \<sharp> ((\<Theta>, \<Phi>, {||}::bv fset, ?G , \<Delta>, [ x ]\<^sup>v,
AS_seq s2 (AS_while s1 s2), AS_val [ L_unit ]\<^sup>v, \<tau>'),x,?G)\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (\<And>zz. atom zz \<sharp> ((\<Theta>, \<Phi>, {||}, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil, \<Delta>, [ x ]\<^sup>v, s2 ;; WHILE s1 DO { s2 } , [[ L_unit ]\<^sup>v]\<^sup>s, \<tau>'), x, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil) \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using obtain_fresh
[PROOF STATE]
proof (prove)
using this:
(\<And>a. atom a \<sharp> ?x \<Longrightarrow> ?thesis) \<Longrightarrow> ?thesis
goal (1 subgoal):
1. (\<And>zz. atom zz \<sharp> ((\<Theta>, \<Phi>, {||}, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil, \<Delta>, [ x ]\<^sup>v, s2 ;; WHILE s1 DO { s2 } , [[ L_unit ]\<^sup>v]\<^sup>s, \<tau>'), x, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil) \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
atom zz \<sharp> ((\<Theta>, \<Phi>, {||}, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil, \<Delta>, [ x ]\<^sup>v, s2 ;; WHILE s1 DO { s2 } , [[ L_unit ]\<^sup>v]\<^sup>s, \<tau>'), x, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil)
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> IF [ x ]\<^sup>v THEN s2 ;; WHILE s1 DO { s2 } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
[PROOF STEP]
show \<open> \<Theta> ; \<Phi> ; {||} ; ?G ; \<Delta> \<turnstile>
AS_if [ x ]\<^sup>v (AS_seq s2 (AS_while s1 s2)) (AS_val [ L_unit ]\<^sup>v) \<Leftarrow> \<tau>'\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> IF [ x ]\<^sup>v THEN s2 ;; WHILE s1 DO { s2 } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (4 subgoals):
1. atom ?z \<sharp> (\<Theta>, \<Phi>, {||}, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil, \<Delta>, [ x ]\<^sup>v, s2 ;; WHILE s1 DO { s2 } , [[ L_unit ]\<^sup>v]\<^sup>s, \<tau>')
2. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> [ x ]\<^sup>v \<Leftarrow> \<lbrace> ?z : B_bool | TRUE \<rbrace>
3. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> s2 ;; WHILE s1 DO { s2 } \<Leftarrow> \<lbrace> ?z : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' ?z \<rbrace>
4. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> ?z : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_false ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' ?z \<rbrace>
[PROOF STEP]
show "atom zz \<sharp> (\<Theta>, \<Phi>, {||}::bv fset, ?G , \<Delta>, [ x ]\<^sup>v, AS_seq s2 (AS_while s1 s2), AS_val [ L_unit ]\<^sup>v, \<tau>')"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. atom zz \<sharp> (\<Theta>, \<Phi>, {||}, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil, \<Delta>, [ x ]\<^sup>v, s2 ;; WHILE s1 DO { s2 } , [[ L_unit ]\<^sup>v]\<^sup>s, \<tau>')
[PROOF STEP]
using zf
[PROOF STATE]
proof (prove)
using this:
atom zz \<sharp> ((\<Theta>, \<Phi>, {||}, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil, \<Delta>, [ x ]\<^sup>v, s2 ;; WHILE s1 DO { s2 } , [[ L_unit ]\<^sup>v]\<^sup>s, \<tau>'), x, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil)
goal (1 subgoal):
1. atom zz \<sharp> (\<Theta>, \<Phi>, {||}, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil, \<Delta>, [ x ]\<^sup>v, s2 ;; WHILE s1 DO { s2 } , [[ L_unit ]\<^sup>v]\<^sup>s, \<tau>')
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
atom zz \<sharp> (\<Theta>, \<Phi>, {||}, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil, \<Delta>, [ x ]\<^sup>v, s2 ;; WHILE s1 DO { s2 } , [[ L_unit ]\<^sup>v]\<^sup>s, \<tau>')
goal (3 subgoals):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> [ x ]\<^sup>v \<Leftarrow> \<lbrace> zz : B_bool | TRUE \<rbrace>
2. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> s2 ;; WHILE s1 DO { s2 } \<Leftarrow> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
3. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_false ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
[PROOF STEP]
show \<open>\<Theta> ; {||} ; ?G \<turnstile> [ x ]\<^sup>v \<Leftarrow> \<lbrace> zz : B_bool | TRUE \<rbrace>\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> [ x ]\<^sup>v \<Leftarrow> \<lbrace> zz : B_bool | TRUE \<rbrace>
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (2 subgoals):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> ?\<tau>1.0 \<lesssim> \<lbrace> zz : B_bool | TRUE \<rbrace>
2. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> [ x ]\<^sup>v \<Rightarrow> ?\<tau>1.0
[PROOF STEP]
have "atom zz \<sharp> x \<and> atom zz \<sharp> (\<Theta>, {||}::bv fset, ?G)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. atom zz \<sharp> x \<and> atom zz \<sharp> (\<Theta>, {||}, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil)
[PROOF STEP]
using zf fresh_prodN
[PROOF STATE]
proof (prove)
using this:
atom zz \<sharp> ((\<Theta>, \<Phi>, {||}, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil, \<Delta>, [ x ]\<^sup>v, s2 ;; WHILE s1 DO { s2 } , [[ L_unit ]\<^sup>v]\<^sup>s, \<tau>'), x, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil)
?a \<sharp> (?x, ?y) = (?a \<sharp> ?x \<and> ?a \<sharp> ?y)
?x \<sharp> (?a, ?b, ?c) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c)
?x \<sharp> (?a, ?b, ?c, ?d) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d)
?x \<sharp> (?a, ?b, ?c, ?d, ?e) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h, ?i) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h \<and> ?x \<sharp> ?i)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h, ?i, ?j) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h \<and> ?x \<sharp> ?i \<and> ?x \<sharp> ?j)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h, ?i, ?j, ?k, ?l) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h \<and> ?x \<sharp> ?i \<and> ?x \<sharp> ?j \<and> ?x \<sharp> ?k \<and> ?x \<sharp> ?l)
goal (1 subgoal):
1. atom zz \<sharp> x \<and> atom zz \<sharp> (\<Theta>, {||}, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil)
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
atom zz \<sharp> x \<and> atom zz \<sharp> (\<Theta>, {||}, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil)
goal (2 subgoals):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> ?\<tau>1.0 \<lesssim> \<lbrace> zz : B_bool | TRUE \<rbrace>
2. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> [ x ]\<^sup>v \<Rightarrow> ?\<tau>1.0
[PROOF STEP]
thus \<open> \<Theta> ; {||} ; ?G \<turnstile> [ x ]\<^sup>v \<Rightarrow>\<lbrace> zz : B_bool | [[zz]\<^sup>v]\<^sup>c\<^sup>e == [[ x ]\<^sup>v]\<^sup>c\<^sup>e \<rbrace>\<close>
[PROOF STATE]
proof (prove)
using this:
atom zz \<sharp> x \<and> atom zz \<sharp> (\<Theta>, {||}, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil)
goal (1 subgoal):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> [ x ]\<^sup>v \<Rightarrow> \<lbrace> zz : B_bool | [ [ zz ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e \<rbrace>
[PROOF STEP]
using infer_v_varI lookup.simps wfg b_of.simps
[PROOF STATE]
proof (prove)
using this:
atom zz \<sharp> x \<and> atom zz \<sharp> (\<Theta>, {||}, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil)
\<lbrakk> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> ; Some (?b, ?c) = lookup ?\<Gamma> ?x; atom ?z \<sharp> ?x; atom ?z \<sharp> (?\<Theta>, ?\<B>, ?\<Gamma>)\<rbrakk> \<Longrightarrow> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile> [ ?x ]\<^sup>v \<Rightarrow> \<lbrace> ?z : ?b | [ [ ?z ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ ?x ]\<^sup>v ]\<^sup>c\<^sup>e \<rbrace>
lookup GNil ?x = None
lookup ((?x, ?b, ?c) #\<^sub>\<Gamma> ?G) ?y = (if ?x = ?y then Some (?b, ?c) else lookup ?G ?y)
\<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil
b_of \<lbrace> ?z : ?b | ?c \<rbrace> = ?b
goal (1 subgoal):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> [ x ]\<^sup>v \<Rightarrow> \<lbrace> zz : B_bool | [ [ zz ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e \<rbrace>
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
\<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> [ x ]\<^sup>v \<Rightarrow> \<lbrace> zz : B_bool | [ [ zz ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e \<rbrace>
goal (1 subgoal):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> \<lbrace> zz : B_bool | [ [ zz ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e \<rbrace> \<lesssim> \<lbrace> zz : B_bool | TRUE \<rbrace>
[PROOF STEP]
thus \<open>\<Theta> ; {||} ; ?G \<turnstile> \<lbrace> zz : B_bool | [[ zz ]\<^sup>v]\<^sup>c\<^sup>e == [[ x ]\<^sup>v]\<^sup>c\<^sup>e \<rbrace> \<lesssim> \<lbrace> zz : B_bool | TRUE \<rbrace>\<close>
[PROOF STATE]
proof (prove)
using this:
\<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> [ x ]\<^sup>v \<Rightarrow> \<lbrace> zz : B_bool | [ [ zz ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e \<rbrace>
goal (1 subgoal):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> \<lbrace> zz : B_bool | [ [ zz ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e \<rbrace> \<lesssim> \<lbrace> zz : B_bool | TRUE \<rbrace>
[PROOF STEP]
using subtype_top infer_v_wf
[PROOF STATE]
proof (prove)
using this:
\<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> [ x ]\<^sup>v \<Rightarrow> \<lbrace> zz : B_bool | [ [ zz ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e \<rbrace>
?\<Theta> ; ?\<B> ; ?G \<turnstile>\<^sub>w\<^sub>f \<lbrace> ?z : ?b | ?c \<rbrace> \<Longrightarrow> ?\<Theta> ; ?\<B> ; ?G \<turnstile> \<lbrace> ?z : ?b | ?c \<rbrace> \<lesssim> \<lbrace> ?z : ?b | TRUE \<rbrace>
?\<Theta> ; ?\<B> ; ?G \<turnstile> ?v \<Rightarrow> ?\<tau> \<Longrightarrow> ?\<Theta> ; ?\<B> ; ?G \<turnstile>\<^sub>w\<^sub>f ?v : b_of ?\<tau>
?\<Theta> ; ?\<B> ; ?G \<turnstile> ?v \<Rightarrow> ?\<tau> \<Longrightarrow> ?\<Theta> ; ?\<B> ; ?G \<turnstile>\<^sub>w\<^sub>f ?\<tau>
?\<Theta> ; ?\<B> ; ?G \<turnstile> ?v \<Rightarrow> ?\<tau> \<Longrightarrow> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<B> ; ?G \<turnstile> ?v \<Rightarrow> ?\<tau> \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?G
goal (1 subgoal):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> \<lbrace> zz : B_bool | [ [ zz ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e \<rbrace> \<lesssim> \<lbrace> zz : B_bool | TRUE \<rbrace>
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
\<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> \<lbrace> zz : B_bool | [ [ zz ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e \<rbrace> \<lesssim> \<lbrace> zz : B_bool | TRUE \<rbrace>
goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> [ x ]\<^sup>v \<Leftarrow> \<lbrace> zz : B_bool | TRUE \<rbrace>
goal (2 subgoals):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> s2 ;; WHILE s1 DO { s2 } \<Leftarrow> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
2. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_false ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
[PROOF STEP]
show \<open> \<Theta> ; \<Phi> ; {||} ; ?G ; \<Delta> \<turnstile> AS_seq s2 (AS_while s1 s2) \<Leftarrow> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> s2 ;; WHILE s1 DO { s2 } \<Leftarrow> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (2 subgoals):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> ?z : B_unit | TRUE \<rbrace>
2. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> WHILE s1 DO { s2 } \<Leftarrow> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
[PROOF STEP]
have "\<lbrace> zz : B_unit | TRUE \<rbrace> = \<lbrace> z : B_unit | TRUE \<rbrace>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<lbrace> zz : B_unit | TRUE \<rbrace> = \<lbrace> z : B_unit | TRUE \<rbrace>
[PROOF STEP]
using \<tau>.eq_iff
[PROOF STATE]
proof (prove)
using this:
(\<lbrace> ?x : ?b | ?c \<rbrace> = \<lbrace> ?xa : ?ba | ?ca \<rbrace>) = ([[atom ?x]]lst. ?c = [[atom ?xa]]lst. ?ca \<and> ?b = ?ba)
goal (1 subgoal):
1. \<lbrace> zz : B_unit | TRUE \<rbrace> = \<lbrace> z : B_unit | TRUE \<rbrace>
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<lbrace> zz : B_unit | TRUE \<rbrace> = \<lbrace> z : B_unit | TRUE \<rbrace>
goal (2 subgoals):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> ?z : B_unit | TRUE \<rbrace>
2. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> WHILE s1 DO { s2 } \<Leftarrow> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
[PROOF STEP]
thus \<open> \<Theta> ; \<Phi> ; {||} ; ?G ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> zz : B_unit | TRUE \<rbrace>\<close>
[PROOF STATE]
proof (prove)
using this:
\<lbrace> zz : B_unit | TRUE \<rbrace> = \<lbrace> z : B_unit | TRUE \<rbrace>
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> zz : B_unit | TRUE \<rbrace>
[PROOF STEP]
using check_s_g_weakening(1) [OF check_whileI(3) _ wfg] toSet.simps
[PROOF STATE]
proof (prove)
using this:
\<lbrace> zz : B_unit | TRUE \<rbrace> = \<lbrace> z : B_unit | TRUE \<rbrace>
toSet GNil \<subseteq> toSet ((x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil) \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
toSet GNil = {}
toSet (?xbc #\<^sub>\<Gamma> ?G) = {?xbc} \<union> toSet ?G
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> zz : B_unit | TRUE \<rbrace>
[PROOF STEP]
by (simp add: \<open>\<lbrace> zz : B_unit | TRUE \<rbrace> = \<lbrace> z : B_unit | TRUE \<rbrace>\<close>)
[PROOF STATE]
proof (state)
this:
\<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> zz : B_unit | TRUE \<rbrace>
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> WHILE s1 DO { s2 } \<Leftarrow> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
[PROOF STEP]
show \<open> \<Theta> ; \<Phi> ; {||} ; ?G ; \<Delta> \<turnstile> AS_while s1 s2 \<Leftarrow> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> WHILE s1 DO { s2 } \<Leftarrow> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
[PROOF STEP]
proof(rule check_s_supertype(1))
[PROOF STATE]
proof (state)
goal (2 subgoals):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> WHILE s1 DO { s2 } \<Leftarrow> ?t1.0
2. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> ?t1.0 \<lesssim> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
[PROOF STEP]
have \<open> \<Theta>; \<Phi>; {||}; GNil; \<Delta> \<turnstile> AS_while s1 s2 \<Leftarrow> \<tau>'\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> WHILE s1 DO { s2 } \<Leftarrow> \<tau>'
[PROOF STEP]
using check_whileI
[PROOF STATE]
proof (prove)
using this:
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>
\<lbrakk>s1 = WHILE ?b DO { ?ba } ; atom ?bb \<sharp> (?b, ?ba); atom ?bc \<sharp> ?bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET ?bb : \<lbrace> ?bc : B_bool | TRUE \<rbrace> = ?b IN IF [ ?bb ]\<^sup>v THEN ?ba ;; WHILE ?b DO { ?ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
\<lbrakk>s2 = WHILE ?b DO { ?ba } ; atom ?bb \<sharp> (?b, ?ba); atom ?bc \<sharp> ?bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET ?bb : \<lbrace> ?bc : B_bool | TRUE \<rbrace> = ?b IN IF [ ?bb ]\<^sup>v THEN ?ba ;; WHILE ?b DO { ?ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
\<Theta> ; {||} ; GNil \<turnstile> \<lbrace> z : B_unit | TRUE \<rbrace> \<lesssim> \<tau>'
atom x \<sharp> (s1, s2)
atom z' \<sharp> x
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> WHILE s1 DO { s2 } \<Leftarrow> \<tau>'
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> WHILE s1 DO { s2 } \<Leftarrow> \<tau>'
goal (2 subgoals):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> WHILE s1 DO { s2 } \<Leftarrow> ?t1.0
2. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> ?t1.0 \<lesssim> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
[PROOF STEP]
thus *:\<open> \<Theta> ; \<Phi> ; {||} ; ?G ; \<Delta> \<turnstile> AS_while s1 s2 \<Leftarrow> \<tau>' \<close>
[PROOF STATE]
proof (prove)
using this:
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> WHILE s1 DO { s2 } \<Leftarrow> \<tau>'
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> WHILE s1 DO { s2 } \<Leftarrow> \<tau>'
[PROOF STEP]
using check_s_g_weakening(1)[OF _ _ wfg] toSet.simps
[PROOF STATE]
proof (prove)
using this:
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> WHILE s1 DO { s2 } \<Leftarrow> \<tau>'
\<lbrakk> \<Theta> ; ?\<Phi> ; {||} ; ?\<Gamma> ; ?\<Delta> \<turnstile> ?s \<Leftarrow> ?t; toSet ?\<Gamma> \<subseteq> toSet ((x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil)\<rbrakk> \<Longrightarrow> \<Theta> ; ?\<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; ?\<Delta> \<turnstile> ?s \<Leftarrow> ?t
toSet GNil = {}
toSet (?xbc #\<^sub>\<Gamma> ?G) = {?xbc} \<union> toSet ?G
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> WHILE s1 DO { s2 } \<Leftarrow> \<tau>'
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> WHILE s1 DO { s2 } \<Leftarrow> \<tau>'
goal (1 subgoal):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> \<tau>' \<lesssim> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
[PROOF STEP]
show \<open>\<Theta> ; {||} ; ?G \<turnstile> \<tau>' \<lesssim> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> \<tau>' \<lesssim> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
[PROOF STEP]
proof(rule subtype_eq_if_\<tau>)
[PROOF STATE]
proof (state)
goal (3 subgoals):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile>\<^sub>w\<^sub>f \<tau>'
2. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile>\<^sub>w\<^sub>f \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
3. atom zz \<sharp> \<tau>'
[PROOF STEP]
show \<open> \<Theta> ; {||} ; ?G \<turnstile>\<^sub>w\<^sub>f \<tau>' \<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile>\<^sub>w\<^sub>f \<tau>'
[PROOF STEP]
using * check_s_wf
[PROOF STATE]
proof (prove)
using this:
\<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> WHILE s1 DO { s2 } \<Leftarrow> \<tau>'
?\<Theta> ; ?\<Phi> ; ?B ; ?\<Gamma> ; ?\<Delta> \<turnstile> ?s \<Leftarrow> ?\<tau> \<Longrightarrow> ?\<Theta> ; ?B \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> ?\<Theta> ; ?B ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<tau> \<and> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> ; ?B ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<and> ?\<Theta> ; ?\<Phi> ; ?B ; ?\<Gamma> ; ?\<Delta> \<turnstile>\<^sub>w\<^sub>f ?s : b_of ?\<tau>
goal (1 subgoal):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile>\<^sub>w\<^sub>f \<tau>'
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile>\<^sub>w\<^sub>f \<tau>'
goal (2 subgoals):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile>\<^sub>w\<^sub>f \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
2. atom zz \<sharp> \<tau>'
[PROOF STEP]
show \<open> \<Theta> ; {||} ; ?G \<turnstile>\<^sub>w\<^sub>f \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace> \<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile>\<^sub>w\<^sub>f \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
[PROOF STEP]
apply(rule wfT_eq_imp, simp add: base_for_lit.simps)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
1. \<Theta> ; {||} ; GNil \<turnstile>\<^sub>w\<^sub>f \<tau>'
2. \<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil
3. atom zz \<sharp> x
[PROOF STEP]
using subtype_wf check_whileI wfg zf fresh_prodN
[PROOF STATE]
proof (prove)
using this:
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile> ?\<tau>1.0 \<lesssim> ?\<tau>2.0 \<Longrightarrow> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<tau>1.0 \<and> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<tau>2.0
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>
\<lbrakk>s1 = WHILE ?b DO { ?ba } ; atom ?bb \<sharp> (?b, ?ba); atom ?bc \<sharp> ?bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET ?bb : \<lbrace> ?bc : B_bool | TRUE \<rbrace> = ?b IN IF [ ?bb ]\<^sup>v THEN ?ba ;; WHILE ?b DO { ?ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
\<lbrakk>s2 = WHILE ?b DO { ?ba } ; atom ?bb \<sharp> (?b, ?ba); atom ?bc \<sharp> ?bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET ?bb : \<lbrace> ?bc : B_bool | TRUE \<rbrace> = ?b IN IF [ ?bb ]\<^sup>v THEN ?ba ;; WHILE ?b DO { ?ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
\<Theta> ; {||} ; GNil \<turnstile> \<lbrace> z : B_unit | TRUE \<rbrace> \<lesssim> \<tau>'
atom x \<sharp> (s1, s2)
atom z' \<sharp> x
\<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil
atom zz \<sharp> ((\<Theta>, \<Phi>, {||}, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil, \<Delta>, [ x ]\<^sup>v, s2 ;; WHILE s1 DO { s2 } , [[ L_unit ]\<^sup>v]\<^sup>s, \<tau>'), x, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil)
?a \<sharp> (?x, ?y) = (?a \<sharp> ?x \<and> ?a \<sharp> ?y)
?x \<sharp> (?a, ?b, ?c) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c)
?x \<sharp> (?a, ?b, ?c, ?d) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d)
?x \<sharp> (?a, ?b, ?c, ?d, ?e) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h, ?i) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h \<and> ?x \<sharp> ?i)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h, ?i, ?j) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h \<and> ?x \<sharp> ?i \<and> ?x \<sharp> ?j)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h, ?i, ?j, ?k, ?l) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h \<and> ?x \<sharp> ?i \<and> ?x \<sharp> ?j \<and> ?x \<sharp> ?k \<and> ?x \<sharp> ?l)
goal (3 subgoals):
1. \<Theta> ; {||} ; GNil \<turnstile>\<^sub>w\<^sub>f \<tau>'
2. \<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil
3. atom zz \<sharp> x
[PROOF STEP]
by metis+
[PROOF STATE]
proof (state)
this:
\<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile>\<^sub>w\<^sub>f \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
goal (1 subgoal):
1. atom zz \<sharp> \<tau>'
[PROOF STEP]
show \<open>atom zz \<sharp> \<tau>'\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. atom zz \<sharp> \<tau>'
[PROOF STEP]
using zf fresh_prodN
[PROOF STATE]
proof (prove)
using this:
atom zz \<sharp> ((\<Theta>, \<Phi>, {||}, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil, \<Delta>, [ x ]\<^sup>v, s2 ;; WHILE s1 DO { s2 } , [[ L_unit ]\<^sup>v]\<^sup>s, \<tau>'), x, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil)
?a \<sharp> (?x, ?y) = (?a \<sharp> ?x \<and> ?a \<sharp> ?y)
?x \<sharp> (?a, ?b, ?c) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c)
?x \<sharp> (?a, ?b, ?c, ?d) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d)
?x \<sharp> (?a, ?b, ?c, ?d, ?e) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h, ?i) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h \<and> ?x \<sharp> ?i)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h, ?i, ?j) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h \<and> ?x \<sharp> ?i \<and> ?x \<sharp> ?j)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h, ?i, ?j, ?k, ?l) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h \<and> ?x \<sharp> ?i \<and> ?x \<sharp> ?j \<and> ?x \<sharp> ?k \<and> ?x \<sharp> ?l)
goal (1 subgoal):
1. atom zz \<sharp> \<tau>'
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
atom zz \<sharp> \<tau>'
goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> \<tau>' \<lesssim> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> WHILE s1 DO { s2 } \<Leftarrow> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> s2 ;; WHILE s1 DO { s2 } \<Leftarrow> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_true ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_false ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
[PROOF STEP]
show \<open> \<Theta> ; \<Phi> ; {||} ; ?G ; \<Delta> \<turnstile> AS_val [ L_unit ]\<^sup>v \<Leftarrow> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_false ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_false ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
[PROOF STEP]
proof(rule check_s_supertype(1))
[PROOF STATE]
proof (state)
goal (2 subgoals):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> ?t1.0
2. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> ?t1.0 \<lesssim> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_false ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
[PROOF STEP]
show *:\<open> \<Theta> ; \<Phi> ; {||} ; ?G ; \<Delta> \<turnstile> AS_val [ L_unit ]\<^sup>v \<Leftarrow> \<tau>'\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
[PROOF STEP]
using check_unit[OF check_whileI(5) _ _ wfg]
[PROOF STATE]
proof (prove)
using this:
\<lbrakk> \<Theta> ; {||} ; GNil \<turnstile>\<^sub>w\<^sub>f ?\<Delta> ; \<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi> \<rbrakk> \<Longrightarrow> \<Theta> ; ?\<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; ?\<Delta> \<turnstile> [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
[PROOF STEP]
using check_whileI wfg wfX_wfY check_s_wf
[PROOF STATE]
proof (prove)
using this:
\<lbrakk> \<Theta> ; {||} ; GNil \<turnstile>\<^sub>w\<^sub>f ?\<Delta> ; \<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi> \<rbrakk> \<Longrightarrow> \<Theta> ; ?\<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; ?\<Delta> \<turnstile> [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>
\<lbrakk>s1 = WHILE ?b DO { ?ba } ; atom ?bb \<sharp> (?b, ?ba); atom ?bc \<sharp> ?bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET ?bb : \<lbrace> ?bc : B_bool | TRUE \<rbrace> = ?b IN IF [ ?bb ]\<^sup>v THEN ?ba ;; WHILE ?b DO { ?ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
\<lbrakk>s2 = WHILE ?b DO { ?ba } ; atom ?bb \<sharp> (?b, ?ba); atom ?bc \<sharp> ?bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET ?bb : \<lbrace> ?bc : B_bool | TRUE \<rbrace> = ?b IN IF [ ?bb ]\<^sup>v THEN ?ba ;; WHILE ?b DO { ?ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
\<Theta> ; {||} ; GNil \<turnstile> \<lbrace> z : B_unit | TRUE \<rbrace> \<lesssim> \<tau>'
atom x \<sharp> (s1, s2)
atom z' \<sharp> x
\<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?v : ?b \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?c \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<Longrightarrow> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<tau> \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f b_of ?\<tau>
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?ts \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
\<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<Longrightarrow> True
?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?b \<Longrightarrow> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?ce : ?b \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?td \<Longrightarrow> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<Phi> ; ?\<B> ; ?\<Gamma> ; ?\<Delta> \<turnstile>\<^sub>w\<^sub>f ?e : ?b \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi>
?\<Theta> ; ?\<Phi> ; ?\<B> ; ?\<Gamma> ; ?\<Delta> \<turnstile>\<^sub>w\<^sub>f ?s : ?b \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi>
?\<Theta> ; ?\<Phi> ; ?\<B> ; ?\<Gamma> ; ?\<Delta> ; ?tid ; ?dc ; ?t \<turnstile>\<^sub>w\<^sub>f ?cs : ?b \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi>
?\<Theta> ; ?\<Phi> ; ?\<B> ; ?\<Gamma> ; ?\<Delta> ; ?tid ; ?dclist \<turnstile>\<^sub>w\<^sub>f ?css : ?b \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi>
?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi> \<Longrightarrow> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<Longrightarrow> ?\<Theta> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<Phi> \<turnstile>\<^sub>w\<^sub>f ?ftq \<Longrightarrow> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<Phi> ; ?\<B> \<turnstile>\<^sub>w\<^sub>f ?ft \<Longrightarrow> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta>
?\<Theta> ; ?\<Phi> ; ?B ; ?\<Gamma> ; ?\<Delta> \<turnstile> ?s \<Leftarrow> ?\<tau> \<Longrightarrow> ?\<Theta> ; ?B \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> ?\<Theta> ; ?B ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<tau> \<and> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> ; ?B ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<and> ?\<Theta> ; ?\<Phi> ; ?B ; ?\<Gamma> ; ?\<Delta> \<turnstile>\<^sub>w\<^sub>f ?s : b_of ?\<tau>
goal (1 subgoal):
1. \<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
\<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
goal (1 subgoal):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> \<tau>' \<lesssim> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_false ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
[PROOF STEP]
show \<open>\<Theta> ; {||} ; ?G \<turnstile> \<tau>' \<lesssim> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_false ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> \<tau>' \<lesssim> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_false ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
[PROOF STEP]
proof(rule subtype_eq_if_\<tau>)
[PROOF STATE]
proof (state)
goal (3 subgoals):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile>\<^sub>w\<^sub>f \<tau>'
2. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile>\<^sub>w\<^sub>f \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_false ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
3. atom zz \<sharp> \<tau>'
[PROOF STEP]
show \<open> \<Theta> ; {||} ; ?G \<turnstile>\<^sub>w\<^sub>f \<tau>' \<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile>\<^sub>w\<^sub>f \<tau>'
[PROOF STEP]
using * check_s_wf
[PROOF STATE]
proof (prove)
using this:
\<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
?\<Theta> ; ?\<Phi> ; ?B ; ?\<Gamma> ; ?\<Delta> \<turnstile> ?s \<Leftarrow> ?\<tau> \<Longrightarrow> ?\<Theta> ; ?B \<turnstile>\<^sub>w\<^sub>f ?\<Gamma> \<and> ?\<Theta> ; ?B ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<tau> \<and> ?\<Theta> \<turnstile>\<^sub>w\<^sub>f ?\<Phi> \<and> \<turnstile>\<^sub>w\<^sub>f ?\<Theta> \<and> ?\<Theta> ; ?B ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<Delta> \<and> ?\<Theta> ; ?\<Phi> ; ?B ; ?\<Gamma> ; ?\<Delta> \<turnstile>\<^sub>w\<^sub>f ?s : b_of ?\<tau>
goal (1 subgoal):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile>\<^sub>w\<^sub>f \<tau>'
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
\<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile>\<^sub>w\<^sub>f \<tau>'
goal (2 subgoals):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile>\<^sub>w\<^sub>f \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_false ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
2. atom zz \<sharp> \<tau>'
[PROOF STEP]
show \<open> \<Theta> ; {||} ; ?G \<turnstile>\<^sub>w\<^sub>f \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_false ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace> \<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile>\<^sub>w\<^sub>f \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_false ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
[PROOF STEP]
apply(rule wfT_eq_imp, simp add: base_for_lit.simps)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
1. \<Theta> ; {||} ; GNil \<turnstile>\<^sub>w\<^sub>f \<tau>'
2. \<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil
3. atom zz \<sharp> x
[PROOF STEP]
using subtype_wf check_whileI wfg zf fresh_prodN
[PROOF STATE]
proof (prove)
using this:
?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile> ?\<tau>1.0 \<lesssim> ?\<tau>2.0 \<Longrightarrow> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<tau>1.0 \<and> ?\<Theta> ; ?\<B> ; ?\<Gamma> \<turnstile>\<^sub>w\<^sub>f ?\<tau>2.0
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s1 \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>
\<lbrakk>s1 = WHILE ?b DO { ?ba } ; atom ?bb \<sharp> (?b, ?ba); atom ?bc \<sharp> ?bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET ?bb : \<lbrace> ?bc : B_bool | TRUE \<rbrace> = ?b IN IF [ ?bb ]\<^sup>v THEN ?ba ;; WHILE ?b DO { ?ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_bool | TRUE \<rbrace>
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> s2 \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
\<lbrakk>s2 = WHILE ?b DO { ?ba } ; atom ?bb \<sharp> (?b, ?ba); atom ?bc \<sharp> ?bb\<rbrakk> \<Longrightarrow> \<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET ?bb : \<lbrace> ?bc : B_bool | TRUE \<rbrace> = ?b IN IF [ ?bb ]\<^sup>v THEN ?ba ;; WHILE ?b DO { ?ba } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> z : B_unit | TRUE \<rbrace>
\<Theta> ; {||} ; GNil \<turnstile> \<lbrace> z : B_unit | TRUE \<rbrace> \<lesssim> \<tau>'
atom x \<sharp> (s1, s2)
atom z' \<sharp> x
\<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil
atom zz \<sharp> ((\<Theta>, \<Phi>, {||}, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil, \<Delta>, [ x ]\<^sup>v, s2 ;; WHILE s1 DO { s2 } , [[ L_unit ]\<^sup>v]\<^sup>s, \<tau>'), x, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil)
?a \<sharp> (?x, ?y) = (?a \<sharp> ?x \<and> ?a \<sharp> ?y)
?x \<sharp> (?a, ?b, ?c) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c)
?x \<sharp> (?a, ?b, ?c, ?d) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d)
?x \<sharp> (?a, ?b, ?c, ?d, ?e) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h, ?i) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h \<and> ?x \<sharp> ?i)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h, ?i, ?j) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h \<and> ?x \<sharp> ?i \<and> ?x \<sharp> ?j)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h, ?i, ?j, ?k, ?l) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h \<and> ?x \<sharp> ?i \<and> ?x \<sharp> ?j \<and> ?x \<sharp> ?k \<and> ?x \<sharp> ?l)
goal (3 subgoals):
1. \<Theta> ; {||} ; GNil \<turnstile>\<^sub>w\<^sub>f \<tau>'
2. \<Theta> ; {||} \<turnstile>\<^sub>w\<^sub>f (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil
3. atom zz \<sharp> x
[PROOF STEP]
by metis+
[PROOF STATE]
proof (state)
this:
\<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile>\<^sub>w\<^sub>f \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_false ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
goal (1 subgoal):
1. atom zz \<sharp> \<tau>'
[PROOF STEP]
show \<open>atom zz \<sharp> \<tau>'\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. atom zz \<sharp> \<tau>'
[PROOF STEP]
using zf fresh_prodN
[PROOF STATE]
proof (prove)
using this:
atom zz \<sharp> ((\<Theta>, \<Phi>, {||}, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil, \<Delta>, [ x ]\<^sup>v, s2 ;; WHILE s1 DO { s2 } , [[ L_unit ]\<^sup>v]\<^sup>s, \<tau>'), x, (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil)
?a \<sharp> (?x, ?y) = (?a \<sharp> ?x \<and> ?a \<sharp> ?y)
?x \<sharp> (?a, ?b, ?c) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c)
?x \<sharp> (?a, ?b, ?c, ?d) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d)
?x \<sharp> (?a, ?b, ?c, ?d, ?e) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h, ?i) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h \<and> ?x \<sharp> ?i)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h, ?i, ?j) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h \<and> ?x \<sharp> ?i \<and> ?x \<sharp> ?j)
?x \<sharp> (?a, ?b, ?c, ?d, ?e, ?f, ?g, ?h, ?i, ?j, ?k, ?l) = (?x \<sharp> ?a \<and> ?x \<sharp> ?b \<and> ?x \<sharp> ?c \<and> ?x \<sharp> ?d \<and> ?x \<sharp> ?e \<and> ?x \<sharp> ?f \<and> ?x \<sharp> ?g \<and> ?x \<sharp> ?h \<and> ?x \<sharp> ?i \<and> ?x \<sharp> ?j \<and> ?x \<sharp> ?k \<and> ?x \<sharp> ?l)
goal (1 subgoal):
1. atom zz \<sharp> \<tau>'
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
atom zz \<sharp> \<tau>'
goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<Theta> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil \<turnstile> \<tau>' \<lesssim> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_false ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<lbrace> zz : b_of \<tau>' | [ [ x ]\<^sup>v ]\<^sup>c\<^sup>e == [ [ L_false ]\<^sup>v ]\<^sup>c\<^sup>e IMP c_of \<tau>' zz \<rbrace>
goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<Theta> ; \<Phi> ; {||} ; (x, b_of \<lbrace> z' : B_bool | TRUE \<rbrace>, c_of \<lbrace> z' : B_bool | TRUE \<rbrace> x) #\<^sub>\<Gamma> GNil ; \<Delta> \<turnstile> IF [ x ]\<^sup>v THEN s2 ;; WHILE s1 DO { s2 } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<Theta> ; \<Phi> ; {||} ; GNil ; \<Delta> \<turnstile> LET x : \<lbrace> z' : B_bool | TRUE \<rbrace> = s1 IN IF [ x ]\<^sup>v THEN s2 ;; WHILE s1 DO { s2 } ELSE [[ L_unit ]\<^sup>v]\<^sup>s \<Leftarrow> \<tau>'
goal (3 subgoals):
1. \<And>\<Theta> \<B> \<Gamma> \<Delta> \<tau> const x \<Phi> tid cons v s s1 s2 xa z'. \<lbrakk>atom x \<sharp> s1; atom x \<sharp> s2; atom x \<sharp> xa; atom x \<sharp> z'; \<Theta> ; \<B> ; \<Gamma> \<turnstile>\<^sub>w\<^sub>f \<Delta> ; \<turnstile>\<^sub>w\<^sub>f \<Theta> ; \<Theta> ; \<B> ; \<Gamma> \<turnstile>\<^sub>w\<^sub>f \<tau> ; \<Theta> ; {||} ; GNil \<turnstile>\<^sub>w\<^sub>f const ; atom x \<sharp> \<Theta>; atom x \<sharp> \<Phi>; atom x \<sharp> \<B>; atom x \<sharp> \<Gamma>; atom x \<sharp> \<Delta>; atom x \<sharp> tid; atom x \<sharp> cons; atom x \<sharp> const; atom x \<sharp> v; atom x \<sharp> \<tau>; \<Theta> ; \<Phi> ; \<B> ; (x, b_of const, [ v ]\<^sup>c\<^sup>e == [ V_cons tid cons [ x ]\<^sup>v ]\<^sup>c\<^sup>e AND c_of const x ) #\<^sub>\<Gamma> \<Gamma> ; \<Delta> \<turnstile> s \<Leftarrow> \<tau>\<rbrakk> \<Longrightarrow> True
2. \<And>\<Theta> \<Phi> \<B> \<Gamma> \<Delta> tid cons const v cs \<tau> dclist css s1 s2 x z'. \<lbrakk> \<Theta> ; \<Phi> ; \<B> ; \<Gamma> ; \<Delta> ; tid ; cons ; const ; v \<turnstile> cs \<Leftarrow> \<tau>; \<And>b ba bb bc. True; \<Theta> ; \<Phi> ; \<B> ; \<Gamma> ; \<Delta> ; tid ; dclist ; v \<turnstile> css \<Leftarrow> \<tau>; \<And>b ba bb bc. True\<rbrakk> \<Longrightarrow> True
3. \<And>\<Theta> \<Phi> \<B> \<Gamma> \<Delta> tid cons const v cs \<tau> s1 s2 x z'. \<lbrakk> \<Theta> ; \<Phi> ; \<B> ; \<Gamma> ; \<Delta> ; tid ; cons ; const ; v \<turnstile> cs \<Leftarrow> \<tau>; \<And>b ba bb bc. True\<rbrakk> \<Longrightarrow> True
[PROOF STEP]
qed(auto+) |
(* Title: HOL/UNITY/Simple/NSP_Bad.thy
Author: Lawrence C Paulson, Cambridge University Computer Laboratory
Copyright 1996 University of Cambridge
Original file is ../Auth/NS_Public_Bad
*)
section{*Analyzing the Needham-Schroeder Public-Key Protocol in UNITY*}
theory NSP_Bad imports "../../Auth/Public" "../UNITY_Main" begin
text{*This is the flawed version, vulnerable to Lowe's attack.
From page 260 of
Burrows, Abadi and Needham. A Logic of Authentication.
Proc. Royal Soc. 426 (1989).
*}
type_synonym state = "event list"
(*The spy MAY say anything he CAN say. We do not expect him to
invent new nonces here, but he can also use NS1. Common to
all similar protocols.*)
definition
Fake :: "(state*state) set"
where "Fake = {(s,s').
\<exists>B X. s' = Says Spy B X # s
& X \<in> synth (analz (spies s))}"
(*The numeric suffixes on A identify the rule*)
(*Alice initiates a protocol run, sending a nonce to Bob*)
definition
NS1 :: "(state*state) set"
where "NS1 = {(s1,s').
\<exists>A1 B NA.
s' = Says A1 B (Crypt (pubK B) {|Nonce NA, Agent A1|}) # s1
& Nonce NA \<notin> used s1}"
(*Bob responds to Alice's message with a further nonce*)
definition
NS2 :: "(state*state) set"
where "NS2 = {(s2,s').
\<exists>A' A2 B NA NB.
s' = Says B A2 (Crypt (pubK A2) {|Nonce NA, Nonce NB|}) # s2
& Says A' B (Crypt (pubK B) {|Nonce NA, Agent A2|}) \<in> set s2
& Nonce NB \<notin> used s2}"
(*Alice proves her existence by sending NB back to Bob.*)
definition
NS3 :: "(state*state) set"
where "NS3 = {(s3,s').
\<exists>A3 B' B NA NB.
s' = Says A3 B (Crypt (pubK B) (Nonce NB)) # s3
& Says A3 B (Crypt (pubK B) {|Nonce NA, Agent A3|}) \<in> set s3
& Says B' A3 (Crypt (pubK A3) {|Nonce NA, Nonce NB|}) \<in> set s3}"
definition Nprg :: "state program" where
(*Initial trace is empty*)
"Nprg = mk_total_program({[]}, {Fake, NS1, NS2, NS3}, UNIV)"
declare spies_partsEs [elim]
declare analz_into_parts [dest]
declare Fake_parts_insert_in_Un [dest]
text{*For other theories, e.g. Mutex and Lift, using [iff] slows proofs down.
Here, it facilitates re-use of the Auth proofs.*}
declare Fake_def [THEN def_act_simp, iff]
declare NS1_def [THEN def_act_simp, iff]
declare NS2_def [THEN def_act_simp, iff]
declare NS3_def [THEN def_act_simp, iff]
declare Nprg_def [THEN def_prg_Init, simp]
text{*A "possibility property": there are traces that reach the end.
Replace by LEADSTO proof!*}
lemma "A \<noteq> B ==>
\<exists>NB. \<exists>s \<in> reachable Nprg. Says A B (Crypt (pubK B) (Nonce NB)) \<in> set s"
apply (intro exI bexI)
apply (rule_tac [2] act = "totalize_act NS3" in reachable.Acts)
apply (rule_tac [3] act = "totalize_act NS2" in reachable.Acts)
apply (rule_tac [4] act = "totalize_act NS1" in reachable.Acts)
apply (rule_tac [5] reachable.Init)
apply (simp_all (no_asm_simp) add: Nprg_def totalize_act_def)
apply auto
done
subsection{*Inductive Proofs about @{term ns_public}*}
lemma ns_constrainsI:
"(!!act s s'. [| act \<in> {Id, Fake, NS1, NS2, NS3};
(s,s') \<in> act; s \<in> A |] ==> s' \<in> A')
==> Nprg \<in> A co A'"
apply (simp add: Nprg_def mk_total_program_def)
apply (rule constrainsI, auto)
done
text{*This ML code does the inductions directly.*}
ML{*
fun ns_constrains_tac ctxt i =
SELECT_GOAL
(EVERY
[REPEAT (etac @{thm Always_ConstrainsI} 1),
REPEAT (resolve_tac [@{thm StableI}, @{thm stableI}, @{thm constrains_imp_Constrains}] 1),
rtac @{thm ns_constrainsI} 1,
full_simp_tac ctxt 1,
REPEAT (FIRSTGOAL (etac disjE)),
ALLGOALS (clarify_tac (ctxt delrules [impI, @{thm impCE}])),
REPEAT (FIRSTGOAL (analz_mono_contra_tac ctxt)),
ALLGOALS (asm_simp_tac ctxt)]) i;
(*Tactic for proving secrecy theorems*)
fun ns_induct_tac ctxt =
(SELECT_GOAL o EVERY)
[rtac @{thm AlwaysI} 1,
force_tac ctxt 1,
(*"reachable" gets in here*)
rtac (@{thm Always_reachable} RS @{thm Always_ConstrainsI} RS @{thm StableI}) 1,
ns_constrains_tac ctxt 1];
*}
method_setup ns_induct = {*
Scan.succeed (SIMPLE_METHOD' o ns_induct_tac) *}
"for inductive reasoning about the Needham-Schroeder protocol"
text{*Converts invariants into statements about reachable states*}
lemmas Always_Collect_reachableD =
Always_includes_reachable [THEN subsetD, THEN CollectD]
text{*Spy never sees another agent's private key! (unless it's bad at start)*}
lemma Spy_see_priK:
"Nprg \<in> Always {s. (Key (priK A) \<in> parts (spies s)) = (A \<in> bad)}"
apply ns_induct
apply blast
done
declare Spy_see_priK [THEN Always_Collect_reachableD, simp]
lemma Spy_analz_priK:
"Nprg \<in> Always {s. (Key (priK A) \<in> analz (spies s)) = (A \<in> bad)}"
by (rule Always_reachable [THEN Always_weaken], auto)
declare Spy_analz_priK [THEN Always_Collect_reachableD, simp]
subsection{*Authenticity properties obtained from NS2*}
text{*It is impossible to re-use a nonce in both NS1 and NS2 provided the
nonce is secret. (Honest users generate fresh nonces.)*}
lemma no_nonce_NS1_NS2:
"Nprg
\<in> Always {s. Crypt (pubK C) {|NA', Nonce NA|} \<in> parts (spies s) -->
Crypt (pubK B) {|Nonce NA, Agent A|} \<in> parts (spies s) -->
Nonce NA \<in> analz (spies s)}"
apply ns_induct
apply (blast intro: analz_insertI)+
done
text{*Adding it to the claset slows down proofs...*}
lemmas no_nonce_NS1_NS2_reachable =
no_nonce_NS1_NS2 [THEN Always_Collect_reachableD, rule_format]
text{*Unicity for NS1: nonce NA identifies agents A and B*}
lemma unique_NA_lemma:
"Nprg
\<in> Always {s. Nonce NA \<notin> analz (spies s) -->
Crypt(pubK B) {|Nonce NA, Agent A|} \<in> parts(spies s) -->
Crypt(pubK B') {|Nonce NA, Agent A'|} \<in> parts(spies s) -->
A=A' & B=B'}"
apply ns_induct
apply auto
txt{*Fake, NS1 are non-trivial*}
done
text{*Unicity for NS1: nonce NA identifies agents A and B*}
lemma unique_NA:
"[| Crypt(pubK B) {|Nonce NA, Agent A|} \<in> parts(spies s);
Crypt(pubK B') {|Nonce NA, Agent A'|} \<in> parts(spies s);
Nonce NA \<notin> analz (spies s);
s \<in> reachable Nprg |]
==> A=A' & B=B'"
by (blast dest: unique_NA_lemma [THEN Always_Collect_reachableD])
text{*Secrecy: Spy does not see the nonce sent in msg NS1 if A and B are secure*}
lemma Spy_not_see_NA:
"[| A \<notin> bad; B \<notin> bad |]
==> Nprg \<in> Always
{s. Says A B (Crypt(pubK B) {|Nonce NA, Agent A|}) \<in> set s
--> Nonce NA \<notin> analz (spies s)}"
apply ns_induct
txt{*NS3*}
prefer 4 apply (blast intro: no_nonce_NS1_NS2_reachable)
txt{*NS2*}
prefer 3 apply (blast dest: unique_NA)
txt{*NS1*}
prefer 2 apply blast
txt{*Fake*}
apply spy_analz
done
text{*Authentication for A: if she receives message 2 and has used NA
to start a run, then B has sent message 2.*}
lemma A_trusts_NS2:
"[| A \<notin> bad; B \<notin> bad |]
==> Nprg \<in> Always
{s. Says A B (Crypt(pubK B) {|Nonce NA, Agent A|}) \<in> set s &
Crypt(pubK A) {|Nonce NA, Nonce NB|} \<in> parts (knows Spy s)
--> Says B A (Crypt(pubK A) {|Nonce NA, Nonce NB|}) \<in> set s}"
(*insert an invariant for use in some of the subgoals*)
apply (insert Spy_not_see_NA [of A B NA], simp, ns_induct)
apply (auto dest: unique_NA)
done
text{*If the encrypted message appears then it originated with Alice in NS1*}
lemma B_trusts_NS1:
"Nprg \<in> Always
{s. Nonce NA \<notin> analz (spies s) -->
Crypt (pubK B) {|Nonce NA, Agent A|} \<in> parts (spies s)
--> Says A B (Crypt (pubK B) {|Nonce NA, Agent A|}) \<in> set s}"
apply ns_induct
apply blast
done
subsection{*Authenticity properties obtained from NS2*}
text{*Unicity for NS2: nonce NB identifies nonce NA and agent A.
Proof closely follows that of @{text unique_NA}.*}
lemma unique_NB_lemma:
"Nprg
\<in> Always {s. Nonce NB \<notin> analz (spies s) -->
Crypt (pubK A) {|Nonce NA, Nonce NB|} \<in> parts (spies s) -->
Crypt(pubK A'){|Nonce NA', Nonce NB|} \<in> parts(spies s) -->
A=A' & NA=NA'}"
apply ns_induct
apply auto
txt{*Fake, NS2 are non-trivial*}
done
lemma unique_NB:
"[| Crypt(pubK A) {|Nonce NA, Nonce NB|} \<in> parts(spies s);
Crypt(pubK A'){|Nonce NA', Nonce NB|} \<in> parts(spies s);
Nonce NB \<notin> analz (spies s);
s \<in> reachable Nprg |]
==> A=A' & NA=NA'"
apply (blast dest: unique_NB_lemma [THEN Always_Collect_reachableD])
done
text{*NB remains secret PROVIDED Alice never responds with round 3*}
lemma Spy_not_see_NB:
"[| A \<notin> bad; B \<notin> bad |]
==> Nprg \<in> Always
{s. Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) \<in> set s &
(ALL C. Says A C (Crypt (pubK C) (Nonce NB)) \<notin> set s)
--> Nonce NB \<notin> analz (spies s)}"
apply ns_induct
apply (simp_all (no_asm_simp) add: all_conj_distrib)
txt{*NS3: because NB determines A*}
prefer 4 apply (blast dest: unique_NB)
txt{*NS2: by freshness and unicity of NB*}
prefer 3 apply (blast intro: no_nonce_NS1_NS2_reachable)
txt{*NS1: by freshness*}
prefer 2 apply blast
txt{*Fake*}
apply spy_analz
done
text{*Authentication for B: if he receives message 3 and has used NB
in message 2, then A has sent message 3--to somebody....*}
lemma B_trusts_NS3:
"[| A \<notin> bad; B \<notin> bad |]
==> Nprg \<in> Always
{s. Crypt (pubK B) (Nonce NB) \<in> parts (spies s) &
Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) \<in> set s
--> (\<exists>C. Says A C (Crypt (pubK C) (Nonce NB)) \<in> set s)}"
(*insert an invariant for use in some of the subgoals*)
apply (insert Spy_not_see_NB [of A B NA NB], simp, ns_induct)
apply (simp_all (no_asm_simp) add: ex_disj_distrib)
apply auto
txt{*NS3: because NB determines A. This use of @{text unique_NB} is robust.*}
apply (blast intro: unique_NB [THEN conjunct1])
done
text{*Can we strengthen the secrecy theorem? NO*}
lemma "[| A \<notin> bad; B \<notin> bad |]
==> Nprg \<in> Always
{s. Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) \<in> set s
--> Nonce NB \<notin> analz (spies s)}"
apply ns_induct
apply auto
txt{*Fake*}
apply spy_analz
txt{*NS2: by freshness and unicity of NB*}
apply (blast intro: no_nonce_NS1_NS2_reachable)
txt{*NS3: unicity of NB identifies A and NA, but not B*}
apply (frule_tac A'=A in Says_imp_spies [THEN parts.Inj, THEN unique_NB])
apply (erule Says_imp_spies [THEN parts.Inj], auto)
apply (rename_tac s B' C)
txt{*This is the attack!
@{subgoals[display,indent=0,margin=65]}
*}
oops
(*
THIS IS THE ATTACK!
[| A \<notin> bad; B \<notin> bad |]
==> Nprg
\<in> Always
{s. Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) \<in> set s -->
Nonce NB \<notin> analz (knows Spy s)}
1. !!s B' C.
[| A \<notin> bad; B \<notin> bad; s \<in> reachable Nprg
Says A C (Crypt (pubK C) {|Nonce NA, Agent A|}) \<in> set s;
Says B' A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) \<in> set s;
C \<in> bad; Says B A (Crypt (pubK A) {|Nonce NA, Nonce NB|}) \<in> set s;
Nonce NB \<notin> analz (knows Spy s) |]
==> False
*)
end
|
Next message: Cohen and "jazz"
This joke just came to mind and I'd better record it for Posterity. I believe I saw it in some 19th century magazine. Maybe it's not that funny after all.
After the Confederate surrender at Appomattox Court House, Southern soldiers were given parole on the sole condition that they endorse a paper pledging their permanent allegiance to the duly elected Government of the United States.
During one of these signings, after many and many a erbel soldier had accepted his pardon from the government of Uncle Sam, an old grizzled veteran of Joe Johnston's army appeared before the Yankee officer to be paroled. After reading the document, the old veteran looked the hated Yankee in the eye, and said with bitterness, "Well, we guv you *H--l* at Chickamaugy!"
"Just sign the paper," exclaimed the Union man. "And no more of your sauce!"
"I *said*, 'We guv you *H--l* at Chickamaugy!'"
"Come, come!" expostulated the officer, whose patience with the old fellow was now wearing thin. "Come sign immediately or I'll have you arrested and imprisoned as the traitor that you have been and are !"
The old man shifted his tobacco, and realizing his dire circumstances, quickly affixed his signature to the official document sanctioning his freedom.
"There, my good man," said his interlocutor. "Now you are once again a citizen of this Great Republic, as good as any man you see here."
"The clever old man replied, 'You mean I'm a Yankee now?'"
"Yes, of course!" came the reply.
"Yes, yes, I have siad it is so."
"Wall, in that case I just have one thing left to say."
"And that thing is --- ?
"They guv us *H--l* at Chickamaugy!" |
lemmas LIMSEQ_def = lim_sequentially |
function linpack_c_test14 ( )
%*****************************************************************************80
%
%% TEST14 tests CHPCO.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 25 June 2009
%
% Author:
%
% John Burkardt
%
n = 3;
fprintf ( 1, '\n' );
fprintf ( 1, 'TEST14\n' );
fprintf ( 1, ' For a single precision complex (C)\n' );
fprintf ( 1, ' Hermitian matrix using packed storage (HP),\n' );
fprintf ( 1, ' CHPCO factors the matrix and estimates\n' );
fprintf ( 1, ' the reciprocal condition number.\n' );
fprintf ( 1, '\n' );
fprintf ( 1, ' The matrix order is N = %d\n', n );
%
% Set the values of the matrix A.
%
k = 0;
seed = 123456789;
for j = 1 : n
for i = 1 : j-1
k = k + 1;
[ a(k), seed ] = c4_uniform_01 ( seed );
a_save(i,j) = a(k);
a_save(j,i) = conj ( a(k) );
end
k = k + 1;
[ a(k), seed ] = r4_uniform_01 ( seed );
a_save(j,j) = a(k);
end
fprintf ( 1, '\n' );
fprintf ( 1, ' The matrix A:\n' );
fprintf ( 1, '\n' );
for i = 1 : n
for j = 1 : n
fprintf ( 1, ' (%8f %8f)', real ( a_save(i,j) ), imag ( a_save(i,j) ) );
end
fprintf ( 1, '\n' );
end
%
% Factor the matrix A.
%
[ a, ipvt, rcond ] = chpco ( a, n );
fprintf ( 1, '\n' );
fprintf ( 1, ' Estimated reciprocal condition RCOND = %f\n', rcond );
return
end
|
I would like to post a thread with some images in it but I don't know how to attach them.
Can anybody help me with this thing?
I will appreciate your HEEEEEELLLLP!!!
At the bottom of the screen where you create a post is the option shown below. I usually use the [alt]-[prnt scrn] buttons on the computer to capture a screenshot, then take that into Paint and cut it down to what I want, then save it as a PNG file since they are small and made to be transferred over networks. Use the Browse button to go find the picture on your computer and double click on it to get it to load into the window. |
= = Canadian division across the Moro = =
|
[STATEMENT]
lemma mset_lt_single_iff[iff]: "{#x#} < {#y#} \<longleftrightarrow> x < y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. ({#x#} < {#y#}) = (x < y)
[PROOF STEP]
unfolding less_multiset\<^sub>H\<^sub>O
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. ({#x#} \<noteq> {#y#} \<and> (\<forall>ya. count {#y#} ya < count {#x#} ya \<longrightarrow> (\<exists>xa>ya. count {#x#} xa < count {#y#} xa))) = (x < y)
[PROOF STEP]
by simp |
import LeanUtils.Div
import Mathlib.Tactic.Ring
/- Parity : functions and theorems related to parity -/
namespace Nat
def even (a : Nat) : Prop := a % 2 = 0
def odd (a : Nat) : Prop := a % 2 = 1
theorem even_rewrite {a : Nat} : even a ↔ ∃ (n : Nat), a = 2 * n :=
Iff.intro
(by
intro h
rw [even, mod_rewrite] at h
simp_all)
(by
intro h
have ⟨n, hn⟩ := h
rw [hn, even, mod_rewrite]
exact ⟨_, by rfl⟩)
theorem odd_rewrite {a : Nat} : odd a ↔ ∃ (n : Nat), a = 2 * n + 1 :=
Iff.intro
(by
intro h
rw [odd, mod_rewrite] at h
simp_all)
(by
intro h
have ⟨n, hn⟩ := h
rw [hn, odd, mod_rewrite]
exact ⟨_, by rfl⟩)
theorem even_plus_even {a b : Nat} : even a → even b → even (a + b) := by
intros h₁ h₂
rw [even_rewrite] at h₁ h₂
have ⟨n, hn⟩ := h₁
have ⟨m, hm⟩ := h₂
rw [hn, hm]
apply even_rewrite.mpr
exact ⟨n+m, by ring⟩
theorem even_plus_odd {a b : Nat} : even a → odd b → odd (a + b) := by
intros h₁ h₂
rw [even_rewrite] at h₁
rw [odd_rewrite] at h₂
have ⟨n, hn⟩ := h₁
have ⟨m, hm⟩ := h₂
rw [hn, hm]
apply odd_rewrite.mpr
exact ⟨n+m, by ring⟩
theorem odd_plus_odd {a b : Nat} : odd a → odd b → even (a + b) := by
intros h₁ h₂
rw [odd_rewrite] at h₁ h₂
have ⟨n, hn⟩ := h₁
have ⟨m, hm⟩ := h₂
rw [hn, hm]
apply even_rewrite.mpr
exact ⟨n+m+1, by ring⟩
end Nat
|
The function $y \mapsto \text{dist}(\{y\}, S)$ is continuous at $x$. |
```python
from sympy import *
init_printing(use_unicode=True)
```
<p></p>
```python
Matrix([[1,-1],[3,4],[0,2]])
Matrix([1,2,3])
```
$$\left[\begin{matrix}1 & -1\\3 & 4\\0 & 2\end{matrix}\right]$$
$$\left[\begin{matrix}1\\2\\3\end{matrix}\right]$$
```python
M = Matrix([[1,2,3],[3,2,1]])
N = Matrix([0,1,1])
M
M.shape
```
|
State Before: α : Type u
inst✝ : DivInvMonoid α
x y : α
⊢ op (x / y) = (op y)⁻¹ * op x State After: no goals Tactic: simp [div_eq_mul_inv] |
//
// Created by daeyun on 4/11/17.
//
#pragma once
#ifndef NDEBUG
#define USE_OMP false
#else
#define USE_OMP true
#endif
#include <iostream>
#include <limits>
#include <cstdlib>
#include <vector>
#include <array>
#include <string>
#include <map>
#include <set>
#include <memory>
#include <gsl/gsl_assert>
#include <Eigen/Dense>
#include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_color_sinks.h"
using Eigen::Matrix;
using Eigen::MatrixXd;
using Eigen::Dynamic;
using Vec = Eigen::VectorXd;
using Vec2 = Eigen::Vector2d;
using Vec2i = Eigen::Matrix<int, 2, 1>;
using Vec3 = Eigen::Vector3d;
using Vec4 = Eigen::Vector4d;
using Mat44 = Eigen::Matrix<double, 4, 4>;
using Mat34 = Eigen::Matrix<double, 3, 4>;
using Mat33 = Eigen::Matrix<double, 3, 3>;
using MatrixX = Eigen::MatrixXd;
using Points4d = Eigen::Matrix<double, 4, Eigen::Dynamic>;
using Points3d = Eigen::Matrix<double, 3, Eigen::Dynamic>;
using Points2d = Eigen::Matrix<double, 2, Eigen::Dynamic>;
using Points2i = Eigen::Matrix<int, 2, Eigen::Dynamic>;
using Points1d = Eigen::Matrix<double, 1, Eigen::Dynamic>;
using std::vector;
using std::array;
using std::string;
using std::unique_ptr;
using std::shared_ptr;
using std::make_unique;
using std::make_shared;
using std::move;
using std::tuple;
using std::pair;
using std::map;
using std::set;
using std::get;
constexpr double kInfinity = std::numeric_limits<double>::infinity();
constexpr double kOneOverTwoPi = M_1_PI * 0.5;
constexpr double kEpsilon = 1e-9;
constexpr double kDeg2Rad = M_PI / 180.0;
// Make sure to have the following in the executable: spdlog::stdout_color_mt("console");
#define LOGGER spdlog::get("console")
|
#include <boost/spirit/home/support/nonterminal/extract_param.hpp>
|
/-
Copyright (c) 2022 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
! This file was ported from Lean 3 source module analysis.calculus.diff_cont_on_cl
! leanprover-community/mathlib commit f2ce6086713c78a7f880485f7917ea547a215982
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathbin.Analysis.Calculus.Deriv
/-!
# Functions differentiable on a domain and continuous on its closure
Many theorems in complex analysis assume that a function is complex differentiable on a domain and
is continuous on its closure. In this file we define a predicate `diff_cont_on_cl` that expresses
this property and prove basic facts about this predicate.
-/
open Set Filter Metric
open Topology
variable (𝕜 : Type _) {E F G : Type _} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E]
[NormedAddCommGroup F] [NormedSpace 𝕜 E] [NormedSpace 𝕜 F] [NormedAddCommGroup G]
[NormedSpace 𝕜 G] {f g : E → F} {s t : Set E} {x : E}
/-- A predicate saying that a function is differentiable on a set and is continuous on its
closure. This is a common assumption in complex analysis. -/
@[protect_proj]
structure DiffContOnCl (f : E → F) (s : Set E) : Prop where
DifferentiableOn : DifferentiableOn 𝕜 f s
ContinuousOn : ContinuousOn f (closure s)
#align diff_cont_on_cl DiffContOnCl
variable {𝕜}
theorem DifferentiableOn.diffContOnCl (h : DifferentiableOn 𝕜 f (closure s)) : DiffContOnCl 𝕜 f s :=
⟨h.mono subset_closure, h.ContinuousOn⟩
#align differentiable_on.diff_cont_on_cl DifferentiableOn.diffContOnCl
theorem Differentiable.diffContOnCl (h : Differentiable 𝕜 f) : DiffContOnCl 𝕜 f s :=
⟨h.DifferentiableOn, h.Continuous.ContinuousOn⟩
#align differentiable.diff_cont_on_cl Differentiable.diffContOnCl
theorem IsClosed.diffContOnCl_iff (hs : IsClosed s) : DiffContOnCl 𝕜 f s ↔ DifferentiableOn 𝕜 f s :=
⟨fun h => h.DifferentiableOn, fun h => ⟨h, hs.closure_eq.symm ▸ h.ContinuousOn⟩⟩
#align is_closed.diff_cont_on_cl_iff IsClosed.diffContOnCl_iff
theorem diffContOnCl_univ : DiffContOnCl 𝕜 f univ ↔ Differentiable 𝕜 f :=
isClosed_univ.diffContOnCl_iff.trans differentiableOn_univ
#align diff_cont_on_cl_univ diffContOnCl_univ
theorem diffContOnCl_const {c : F} : DiffContOnCl 𝕜 (fun x : E => c) s :=
⟨differentiableOn_const c, continuousOn_const⟩
#align diff_cont_on_cl_const diffContOnCl_const
namespace DiffContOnCl
theorem comp {g : G → E} {t : Set G} (hf : DiffContOnCl 𝕜 f s) (hg : DiffContOnCl 𝕜 g t)
(h : MapsTo g t s) : DiffContOnCl 𝕜 (f ∘ g) t :=
⟨hf.1.comp hg.1 h, hf.2.comp hg.2 <| h.closure_of_continuousOn hg.2⟩
#align diff_cont_on_cl.comp DiffContOnCl.comp
theorem continuousOn_ball [NormedSpace ℝ E] {x : E} {r : ℝ} (h : DiffContOnCl 𝕜 f (ball x r)) :
ContinuousOn f (closedBall x r) :=
by
rcases eq_or_ne r 0 with (rfl | hr)
· rw [closed_ball_zero]
exact continuousOn_singleton f x
· rw [← closure_ball x hr]
exact h.continuous_on
#align diff_cont_on_cl.continuous_on_ball DiffContOnCl.continuousOn_ball
theorem mk_ball {x : E} {r : ℝ} (hd : DifferentiableOn 𝕜 f (ball x r))
(hc : ContinuousOn f (closedBall x r)) : DiffContOnCl 𝕜 f (ball x r) :=
⟨hd, hc.mono <| closure_ball_subset_closedBall⟩
#align diff_cont_on_cl.mk_ball DiffContOnCl.mk_ball
protected theorem differentiableAt (h : DiffContOnCl 𝕜 f s) (hs : IsOpen s) (hx : x ∈ s) :
DifferentiableAt 𝕜 f x :=
h.DifferentiableOn.DifferentiableAt <| hs.mem_nhds hx
#align diff_cont_on_cl.differentiable_at DiffContOnCl.differentiableAt
theorem differentiable_at' (h : DiffContOnCl 𝕜 f s) (hx : s ∈ 𝓝 x) : DifferentiableAt 𝕜 f x :=
h.DifferentiableOn.DifferentiableAt hx
#align diff_cont_on_cl.differentiable_at' DiffContOnCl.differentiable_at'
protected theorem mono (h : DiffContOnCl 𝕜 f s) (ht : t ⊆ s) : DiffContOnCl 𝕜 f t :=
⟨h.DifferentiableOn.mono ht, h.ContinuousOn.mono (closure_mono ht)⟩
#align diff_cont_on_cl.mono DiffContOnCl.mono
theorem add (hf : DiffContOnCl 𝕜 f s) (hg : DiffContOnCl 𝕜 g s) : DiffContOnCl 𝕜 (f + g) s :=
⟨hf.1.add hg.1, hf.2.add hg.2⟩
#align diff_cont_on_cl.add DiffContOnCl.add
theorem add_const (hf : DiffContOnCl 𝕜 f s) (c : F) : DiffContOnCl 𝕜 (fun x => f x + c) s :=
hf.add diffContOnCl_const
#align diff_cont_on_cl.add_const DiffContOnCl.add_const
theorem const_add (hf : DiffContOnCl 𝕜 f s) (c : F) : DiffContOnCl 𝕜 (fun x => c + f x) s :=
diffContOnCl_const.add hf
#align diff_cont_on_cl.const_add DiffContOnCl.const_add
theorem neg (hf : DiffContOnCl 𝕜 f s) : DiffContOnCl 𝕜 (-f) s :=
⟨hf.1.neg, hf.2.neg⟩
#align diff_cont_on_cl.neg DiffContOnCl.neg
theorem sub (hf : DiffContOnCl 𝕜 f s) (hg : DiffContOnCl 𝕜 g s) : DiffContOnCl 𝕜 (f - g) s :=
⟨hf.1.sub hg.1, hf.2.sub hg.2⟩
#align diff_cont_on_cl.sub DiffContOnCl.sub
theorem sub_const (hf : DiffContOnCl 𝕜 f s) (c : F) : DiffContOnCl 𝕜 (fun x => f x - c) s :=
hf.sub diffContOnCl_const
#align diff_cont_on_cl.sub_const DiffContOnCl.sub_const
theorem const_sub (hf : DiffContOnCl 𝕜 f s) (c : F) : DiffContOnCl 𝕜 (fun x => c - f x) s :=
diffContOnCl_const.sub hf
#align diff_cont_on_cl.const_sub DiffContOnCl.const_sub
theorem const_smul {R : Type _} [Semiring R] [Module R F] [SMulCommClass 𝕜 R F]
[ContinuousConstSMul R F] (hf : DiffContOnCl 𝕜 f s) (c : R) : DiffContOnCl 𝕜 (c • f) s :=
⟨hf.1.const_smul c, hf.2.const_smul c⟩
#align diff_cont_on_cl.const_smul DiffContOnCl.const_smul
theorem smul {𝕜' : Type _} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' F]
[IsScalarTower 𝕜 𝕜' F] {c : E → 𝕜'} {f : E → F} {s : Set E} (hc : DiffContOnCl 𝕜 c s)
(hf : DiffContOnCl 𝕜 f s) : DiffContOnCl 𝕜 (fun x => c x • f x) s :=
⟨hc.1.smul hf.1, hc.2.smul hf.2⟩
#align diff_cont_on_cl.smul DiffContOnCl.smul
theorem smul_const {𝕜' : Type _} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜']
[NormedSpace 𝕜' F] [IsScalarTower 𝕜 𝕜' F] {c : E → 𝕜'} {s : Set E} (hc : DiffContOnCl 𝕜 c s)
(y : F) : DiffContOnCl 𝕜 (fun x => c x • y) s :=
hc.smul diffContOnCl_const
#align diff_cont_on_cl.smul_const DiffContOnCl.smul_const
theorem inv {f : E → 𝕜} (hf : DiffContOnCl 𝕜 f s) (h₀ : ∀ x ∈ closure s, f x ≠ 0) :
DiffContOnCl 𝕜 f⁻¹ s :=
⟨differentiableOn_inv.comp hf.1 fun x hx => h₀ _ (subset_closure hx), hf.2.inv₀ h₀⟩
#align diff_cont_on_cl.inv DiffContOnCl.inv
end DiffContOnCl
theorem Differentiable.comp_diffContOnCl {g : G → E} {t : Set G} (hf : Differentiable 𝕜 f)
(hg : DiffContOnCl 𝕜 g t) : DiffContOnCl 𝕜 (f ∘ g) t :=
hf.DiffContOnCl.comp hg (mapsTo_image _ _)
#align differentiable.comp_diff_cont_on_cl Differentiable.comp_diffContOnCl
theorem DifferentiableOn.diffContOnCl_ball {U : Set E} {c : E} {R : ℝ} (hf : DifferentiableOn 𝕜 f U)
(hc : closedBall c R ⊆ U) : DiffContOnCl 𝕜 f (ball c R) :=
DiffContOnCl.mk_ball (hf.mono (ball_subset_closedBall.trans hc)) (hf.ContinuousOn.mono hc)
#align differentiable_on.diff_cont_on_cl_ball DifferentiableOn.diffContOnCl_ball
|
lemmas scaleR_minus_right = real_vector.scale_minus_right |
(* Title: InternalAdjunction
Author: Eugene W. Stark <[email protected]>, 2019
Maintainer: Eugene W. Stark <[email protected]>
*)
section "Adjunctions in a Bicategory"
theory InternalAdjunction
imports CanonicalIsos Strictness
begin
text \<open>
An \emph{internal adjunction} in a bicategory is a four-tuple \<open>(f, g, \<eta>, \<epsilon>)\<close>,
where \<open>f\<close> and \<open>g\<close> are antiparallel 1-cells and \<open>\<guillemotleft>\<eta> : src f \<Rightarrow> g \<star> f\<guillemotright>\<close> and
\<open>\<guillemotleft>\<epsilon> : f \<star> g \<Rightarrow> src g\<guillemotright>\<close> are 2-cells, such that the familiar ``triangle''
(or ``zig-zag'') identities are satisfied. We state the triangle identities
in two equivalent forms, each of which is convenient in certain situations.
\<close>
locale adjunction_in_bicategory =
adjunction_data_in_bicategory +
assumes triangle_left: "(\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>) = \<l>\<^sup>-\<^sup>1[f] \<cdot> \<r>[f]"
and triangle_right: "(g \<star> \<epsilon>) \<cdot> \<a>[g, f, g] \<cdot> (\<eta> \<star> g) = \<r>\<^sup>-\<^sup>1[g] \<cdot> \<l>[g]"
begin
lemma triangle_left':
shows "\<l>[f] \<cdot> (\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>) \<cdot> \<r>\<^sup>-\<^sup>1[f] = f"
using triangle_left triangle_equiv_form by simp
lemma triangle_right':
shows "\<r>[g] \<cdot> (g \<star> \<epsilon>) \<cdot> \<a>[g, f, g] \<cdot> (\<eta> \<star> g) \<cdot> \<l>\<^sup>-\<^sup>1[g] = g"
using triangle_right triangle_equiv_form by simp
end
text \<open>
Internal adjunctions have a number of properties, which we now develop,
that generalize those of ordinary adjunctions involving functors and
natural transformations.
\<close>
context bicategory
begin
lemma adjunction_unit_determines_counit:
assumes "adjunction_in_bicategory (\<cdot>) (\<star>) \<a> \<i> src trg f g \<eta> \<epsilon>"
and "adjunction_in_bicategory (\<cdot>) (\<star>) \<a> \<i> src trg f g \<eta> \<epsilon>'"
shows "\<epsilon> = \<epsilon>'"
proof -
interpret E: adjunction_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>
using assms(1) by auto
interpret E': adjunction_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>'
using assms(2) by auto
text \<open>
Note that since we want to prove the the result for an arbitrary bicategory,
not just in for a strict bicategory, the calculation is a little more involved
than one might expect from a treatment that suppresses canonical isomorphisms.
\<close>
have "\<epsilon> \<cdot> \<r>[f \<star> g] = \<r>[trg f] \<cdot> (\<epsilon> \<star> trg f)"
using runit_naturality [of \<epsilon>] by simp
have 1: "\<r>[f \<star> g] = (f \<star> \<r>[g]) \<cdot> \<a>[f, g, src g]"
using E.antipar runit_hcomp by simp
have "\<epsilon> = \<epsilon> \<cdot> (f \<star> \<r>[g] \<cdot> (g \<star> \<epsilon>') \<cdot> \<a>[g, f, g] \<cdot> (\<eta> \<star> g) \<cdot> \<l>\<^sup>-\<^sup>1[g])"
using E'.triangle_right' comp_arr_dom by simp
also have "... = \<epsilon> \<cdot> (f \<star> \<r>[g]) \<cdot> (f \<star> g \<star> \<epsilon>') \<cdot> (f \<star> \<a>[g, f, g]) \<cdot> (f \<star> \<eta> \<star> g) \<cdot> (f \<star> \<l>\<^sup>-\<^sup>1[g])"
using E.antipar whisker_left by simp
also have "... = \<epsilon> \<cdot> ((f \<star> \<r>[g]) \<cdot> (f \<star> g \<star> \<epsilon>')) \<cdot> (f \<star> \<a>[g, f, g]) \<cdot> (f \<star> \<eta> \<star> g) \<cdot> (f \<star> \<l>\<^sup>-\<^sup>1[g])"
using comp_assoc by simp
also have "... = \<epsilon> \<cdot> \<r>[f \<star> g] \<cdot> (\<a>\<^sup>-\<^sup>1[f, g, src g] \<cdot> (f \<star> g \<star> \<epsilon>')) \<cdot>
(f \<star> \<a>[g, f, g]) \<cdot> (f \<star> \<eta> \<star> g) \<cdot> (f \<star> \<l>\<^sup>-\<^sup>1[g])"
proof -
have "f \<star> \<r>[g] = \<r>[f \<star> g] \<cdot> \<a>\<^sup>-\<^sup>1[f, g, src g]"
using E.antipar(1) runit_hcomp(3) by auto
thus ?thesis
using comp_assoc by simp
qed
also have "... = (\<epsilon> \<cdot> \<r>[f \<star> g]) \<cdot> ((f \<star> g) \<star> \<epsilon>') \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f \<star> g] \<cdot>
(f \<star> \<a>[g, f, g]) \<cdot> (f \<star> \<eta> \<star> g) \<cdot> (f \<star> \<l>\<^sup>-\<^sup>1[g])"
using E.antipar E'.counit_in_hom assoc'_naturality [of f g \<epsilon>'] comp_assoc by simp
also have "... = \<r>[trg f] \<cdot> ((\<epsilon> \<star> trg f) \<cdot> ((f \<star> g) \<star> \<epsilon>')) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f \<star> g] \<cdot>
(f \<star> \<a>[g, f, g]) \<cdot> (f \<star> \<eta> \<star> g) \<cdot> (f \<star> \<l>\<^sup>-\<^sup>1[g])"
using E.antipar E.counit_in_hom runit_naturality [of \<epsilon>] comp_assoc by simp
also have "... = (\<l>[src g] \<cdot> (src g \<star> \<epsilon>')) \<cdot> (\<epsilon> \<star> f \<star> g) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f \<star> g] \<cdot>
(f \<star> \<a>[g, f, g]) \<cdot> (f \<star> \<eta> \<star> g) \<cdot> (f \<star> \<l>\<^sup>-\<^sup>1[g])"
proof -
have "(\<epsilon> \<star> trg f) \<cdot> ((f \<star> g) \<star> \<epsilon>') = (src g \<star> \<epsilon>') \<cdot> (\<epsilon> \<star> f \<star> g)"
using E.antipar interchange E.counit_in_hom comp_arr_dom comp_cod_arr
by (metis E'.counit_simps(1-3) E.counit_simps(1-3))
thus ?thesis
using E.antipar comp_assoc unitor_coincidence by simp
qed
also have "... = \<epsilon>' \<cdot> \<l>[f \<star> g] \<cdot> (\<epsilon> \<star> f \<star> g) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f \<star> g] \<cdot>
(f \<star> \<a>[g, f, g]) \<cdot> (f \<star> \<eta> \<star> g) \<cdot> (f \<star> \<l>\<^sup>-\<^sup>1[g])"
proof -
have "\<l>[src g] \<cdot> (src g \<star> \<epsilon>') = \<epsilon>' \<cdot> \<l>[f \<star> g]"
using E.antipar lunit_naturality [of \<epsilon>'] by simp
thus ?thesis
using comp_assoc by simp
qed
also have "... = \<epsilon>' \<cdot> (\<l>[f] \<star> g) \<cdot> (\<a>\<^sup>-\<^sup>1[trg f, f, g] \<cdot> (\<epsilon> \<star> f \<star> g)) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f \<star> g] \<cdot>
(f \<star> \<a>[g, f, g]) \<cdot> (f \<star> \<eta> \<star> g) \<cdot> (f \<star> \<l>\<^sup>-\<^sup>1[g])"
using E.antipar lunit_hcomp comp_assoc by simp
also have "... = \<epsilon>' \<cdot> (\<l>[f] \<star> g) \<cdot> ((\<epsilon> \<star> f) \<star> g) \<cdot> (\<a>\<^sup>-\<^sup>1[f \<star> g, f, g] \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f \<star> g] \<cdot>
(f \<star> \<a>[g, f, g])) \<cdot> (f \<star> \<eta> \<star> g) \<cdot> (f \<star> \<l>\<^sup>-\<^sup>1[g])"
using E.antipar assoc'_naturality [of \<epsilon> f g] comp_assoc by simp
also have "... = \<epsilon>' \<cdot> (\<l>[f] \<star> g) \<cdot> ((\<epsilon> \<star> f) \<star> g) \<cdot> (\<a>\<^sup>-\<^sup>1[f, g, f] \<star> g) \<cdot>
(\<a>\<^sup>-\<^sup>1[f, g \<star> f, g] \<cdot> (f \<star> \<eta> \<star> g)) \<cdot> (f \<star> \<l>\<^sup>-\<^sup>1[g])"
proof -
have "\<a>\<^sup>-\<^sup>1[f \<star> g, f, g] \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f \<star> g] \<cdot> (f \<star> \<a>[g, f, g]) =
(\<a>\<^sup>-\<^sup>1[f, g, f] \<star> g) \<cdot> \<a>\<^sup>-\<^sup>1[f, g \<star> f, g]"
using 1 E.antipar iso_assoc' iso_inv_iso pentagon' comp_assoc
invert_side_of_triangle(2)
[of "\<a>\<^sup>-\<^sup>1[f \<star> g, f, g] \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f \<star> g]"
"(\<a>\<^sup>-\<^sup>1[f, g, f] \<star> g) \<cdot> \<a>\<^sup>-\<^sup>1[f, g \<star> f, g]" "f \<star> \<a>\<^sup>-\<^sup>1[g, f, g]"]
by simp
thus ?thesis
using comp_assoc by simp
qed
also have "... = \<epsilon>' \<cdot> (\<l>[f] \<star> g) \<cdot> ((\<epsilon> \<star> f) \<star> g) \<cdot> (\<a>\<^sup>-\<^sup>1[f, g, f] \<star> g) \<cdot>
((f \<star> \<eta>) \<star> g) \<cdot> \<a>\<^sup>-\<^sup>1[f, trg g, g] \<cdot> (f \<star> \<l>\<^sup>-\<^sup>1[g])"
using E.antipar assoc'_naturality [of f \<eta> g] comp_assoc by simp
also have "... = \<epsilon>' \<cdot> (\<l>[f] \<star> g) \<cdot> ((\<epsilon> \<star> f) \<star> g) \<cdot> (\<a>\<^sup>-\<^sup>1[f, g, f] \<star> g) \<cdot>
((f \<star> \<eta>) \<star> g) \<cdot> (\<r>\<^sup>-\<^sup>1[f] \<star> g)"
proof -
have "\<a>\<^sup>-\<^sup>1[f, trg g, g] \<cdot> (f \<star> \<l>\<^sup>-\<^sup>1[g]) = \<r>\<^sup>-\<^sup>1[f] \<star> g"
proof -
have "\<r>\<^sup>-\<^sup>1[f] \<star> g = inv (\<r>[f] \<star> g)"
using E.antipar by simp
also have "... = inv ((f \<star> \<l>[g]) \<cdot> \<a>[f, trg g, g])"
using E.antipar by (simp add: triangle)
also have "... = \<a>\<^sup>-\<^sup>1[f, trg g, g] \<cdot> (f \<star> \<l>\<^sup>-\<^sup>1[g])"
using E.antipar inv_comp by simp
finally show ?thesis by simp
qed
thus ?thesis by simp
qed
also have "... = \<epsilon>' \<cdot> (\<l>[f] \<cdot> (\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>) \<cdot> \<r>\<^sup>-\<^sup>1[f] \<star> g)"
using E.antipar whisker_right by simp
also have "... = \<epsilon>'"
using E.triangle_left' comp_arr_dom by simp
finally show ?thesis by simp
qed
end
subsection "Adjoint Transpose"
context adjunction_in_bicategory
begin
interpretation E: self_evaluation_map V H \<a> \<i> src trg ..
notation E.eval ("\<lbrace>_\<rbrace>")
text \<open>
Just as for an ordinary adjunction between categories, an adjunction in a bicategory
determines bijections between hom-sets. There are two versions of this relationship:
depending on whether the transposition is occurring on the left (\emph{i.e.}~``output'')
side or the right (\emph{i.e.}~``input'') side.
\<close>
definition trnl\<^sub>\<eta>
where "trnl\<^sub>\<eta> v \<mu> \<equiv> (g \<star> \<mu>) \<cdot> \<a>[g, f, v] \<cdot> (\<eta> \<star> v) \<cdot> \<l>\<^sup>-\<^sup>1[v]"
definition trnl\<^sub>\<epsilon>
where "trnl\<^sub>\<epsilon> u \<nu> \<equiv> \<l>[u] \<cdot> (\<epsilon> \<star> u) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, u] \<cdot> (f \<star> \<nu>)"
lemma adjoint_transpose_left:
assumes "ide u" and "ide v" and "src f = trg v" and "src g = trg u"
shows "trnl\<^sub>\<eta> v \<in> hom (f \<star> v) u \<rightarrow> hom v (g \<star> u)"
and "trnl\<^sub>\<epsilon> u \<in> hom v (g \<star> u) \<rightarrow> hom (f \<star> v) u"
and "\<guillemotleft>\<mu> : f \<star> v \<Rightarrow> u\<guillemotright> \<Longrightarrow> trnl\<^sub>\<epsilon> u (trnl\<^sub>\<eta> v \<mu>) = \<mu>"
and "\<guillemotleft>\<nu> : v \<Rightarrow> g \<star> u\<guillemotright> \<Longrightarrow> trnl\<^sub>\<eta> v (trnl\<^sub>\<epsilon> u \<nu>) = \<nu>"
and "bij_betw (trnl\<^sub>\<eta> v) (hom (f \<star> v) u) (hom v (g \<star> u))"
and "bij_betw (trnl\<^sub>\<epsilon> u) (hom v (g \<star> u)) (hom (f \<star> v) u)"
proof -
show A: "trnl\<^sub>\<eta> v \<in> hom (f \<star> v) u \<rightarrow> hom v (g \<star> u)"
using assms antipar trnl\<^sub>\<eta>_def by fastforce
show B: "trnl\<^sub>\<epsilon> u \<in> hom v (g \<star> u) \<rightarrow> hom (f \<star> v) u"
using assms antipar trnl\<^sub>\<epsilon>_def by fastforce
show C: "\<And>\<mu>. \<guillemotleft>\<mu> : f \<star> v \<Rightarrow> u\<guillemotright> \<Longrightarrow> trnl\<^sub>\<epsilon> u (trnl\<^sub>\<eta> v \<mu>) = \<mu>"
proof -
fix \<mu>
assume \<mu>: "\<guillemotleft>\<mu> : f \<star> v \<Rightarrow> u\<guillemotright>"
have "trnl\<^sub>\<epsilon> u (trnl\<^sub>\<eta> v \<mu>) =
\<l>[u] \<cdot> (\<epsilon> \<star> u) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, u] \<cdot> (f \<star> (g \<star> \<mu>) \<cdot> \<a>[g, f, v] \<cdot> (\<eta> \<star> v) \<cdot> \<l>\<^sup>-\<^sup>1[v])"
using trnl\<^sub>\<eta>_def trnl\<^sub>\<epsilon>_def by simp
also have "... = \<l>[u] \<cdot> (\<epsilon> \<star> u) \<cdot> (\<a>\<^sup>-\<^sup>1[f, g, u] \<cdot> (f \<star> g \<star> \<mu>)) \<cdot> (f \<star> \<a>[g, f, v]) \<cdot>
(f \<star> \<eta> \<star> v) \<cdot> (f \<star> \<l>\<^sup>-\<^sup>1[v])"
using assms \<mu> antipar whisker_left comp_assoc by auto
also have "... = \<l>[u] \<cdot> ((\<epsilon> \<star> u) \<cdot> ((f \<star> g) \<star> \<mu>)) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f \<star> v] \<cdot> (f \<star> \<a>[g, f, v]) \<cdot>
(f \<star> \<eta> \<star> v) \<cdot> (f \<star> \<l>\<^sup>-\<^sup>1[v])"
using assms \<mu> antipar assoc'_naturality [of f g \<mu>] comp_assoc by fastforce
also have "... = \<l>[u] \<cdot> (trg u \<star> \<mu>) \<cdot>
(\<epsilon> \<star> f \<star> v) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f \<star> v] \<cdot> (f \<star> \<a>[g, f, v]) \<cdot>
(f \<star> \<eta> \<star> v) \<cdot> (f \<star> \<l>\<^sup>-\<^sup>1[v])"
proof -
have "(\<epsilon> \<star> u) \<cdot> ((f \<star> g) \<star> \<mu>) = (trg u \<star> \<mu>) \<cdot> (\<epsilon> \<star> f \<star> v)"
using assms \<mu> antipar comp_cod_arr comp_arr_dom
interchange [of "trg u" \<epsilon> \<mu> "f \<star> v"] interchange [of \<epsilon> "f \<star> g" u \<mu>]
by auto
thus ?thesis
using comp_assoc by simp
qed
also have "... = \<l>[u] \<cdot> (trg u \<star> \<mu>) \<cdot> \<a>[trg f, f, v] \<cdot>
((\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>) \<star> v) \<cdot>
\<a>\<^sup>-\<^sup>1[f, trg v, v] \<cdot> (f \<star> \<l>\<^sup>-\<^sup>1[v])"
proof -
have 1: "(\<epsilon> \<star> f \<star> v) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f \<star> v] \<cdot> (f \<star> \<a>[g, f, v]) \<cdot> (f \<star> \<eta> \<star> v) =
\<a>[trg f, f, v] \<cdot> ((\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>) \<star> v) \<cdot> \<a>\<^sup>-\<^sup>1[f, trg v, v]"
proof -
have "(\<epsilon> \<star> f \<star> v) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f \<star> v] \<cdot> (f \<star> \<a>[g, f, v]) \<cdot> (f \<star> \<eta> \<star> v) =
(\<epsilon> \<star> f \<star> v) \<cdot>
\<a>[f \<star> g, f, v] \<cdot> (\<a>\<^sup>-\<^sup>1[f, g, f] \<star> v) \<cdot> \<a>\<^sup>-\<^sup>1[f, g \<star> f, v] \<cdot>
(f \<star> \<eta> \<star> v)"
proof -
have "(\<epsilon> \<star> f \<star> v) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f \<star> v] \<cdot> (f \<star> \<a>[g, f, v]) \<cdot> (f \<star> \<eta> \<star> v) =
(\<epsilon> \<star> f \<star> v) \<cdot> (\<a>\<^sup>-\<^sup>1[f, g, f \<star> v] \<cdot> (f \<star> \<a>[g, f, v])) \<cdot> (f \<star> \<eta> \<star> v)"
using comp_assoc by simp
also have "... = (\<epsilon> \<star> f \<star> v) \<cdot>
\<a>[f \<star> g, f, v] \<cdot> (\<a>\<^sup>-\<^sup>1[f, g, f] \<star> v) \<cdot> \<a>\<^sup>-\<^sup>1[f, g \<star> f, v] \<cdot>
(f \<star> \<eta> \<star> v)"
proof -
have "\<a>\<^sup>-\<^sup>1[f, g, f \<star> v] \<cdot> (f \<star> \<a>[g, f, v]) =
\<a>[f \<star> g, f, v] \<cdot> (\<a>\<^sup>-\<^sup>1[f, g, f] \<star> v) \<cdot> \<a>\<^sup>-\<^sup>1[f, g \<star> f, v]"
using assms antipar canI_associator_0 whisker_can_left_0 whisker_can_right_0
canI_associator_hcomp(1-3)
by simp
thus ?thesis
using comp_assoc by simp
qed
finally show ?thesis by blast
qed
also have "... = ((\<epsilon> \<star> f \<star> v) \<cdot> \<a>[f \<star> g, f, v]) \<cdot>
(\<a>\<^sup>-\<^sup>1[f, g, f] \<star> v) \<cdot> ((f \<star> \<eta>) \<star> v) \<cdot>
\<a>\<^sup>-\<^sup>1[f, trg v, v]"
using assms \<mu> antipar assoc'_naturality [of f \<eta> v] comp_assoc by simp
also have "... = (\<a>[trg f, f, v] \<cdot> ((\<epsilon> \<star> f) \<star> v)) \<cdot> (\<a>\<^sup>-\<^sup>1[f, g, f] \<star> v) \<cdot> ((f \<star> \<eta>) \<star> v) \<cdot>
\<a>\<^sup>-\<^sup>1[f, trg v, v]"
using assms \<mu> antipar assoc_naturality [of \<epsilon> f v] by simp
also have "... = \<a>[trg f, f, v] \<cdot>
(((\<epsilon> \<star> f) \<star> v) \<cdot> (\<a>\<^sup>-\<^sup>1[f, g, f] \<star> v) \<cdot> ((f \<star> \<eta>) \<star> v)) \<cdot>
\<a>\<^sup>-\<^sup>1[f, trg v, v]"
using comp_assoc by simp
also have "... = \<a>[trg f, f, v] \<cdot> ((\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>) \<star> v) \<cdot> \<a>\<^sup>-\<^sup>1[f, trg v, v]"
using assms \<mu> antipar whisker_right by simp
finally show ?thesis by simp
qed
show ?thesis
using 1 comp_assoc by metis
qed
also have "... = \<l>[u] \<cdot> (trg u \<star> \<mu>) \<cdot>
\<a>[trg f, f, v] \<cdot> (\<l>\<^sup>-\<^sup>1[f] \<cdot> \<r>[f] \<star> v) \<cdot> \<a>\<^sup>-\<^sup>1[f, trg v, v] \<cdot> (f \<star> \<l>\<^sup>-\<^sup>1[v])"
using assms \<mu> antipar triangle_left by simp
also have "... = \<l>[u] \<cdot> (trg u \<star> \<mu>) \<cdot> can (\<^bold>\<langle>trg u\<^bold>\<rangle>\<^sub>0 \<^bold>\<star> \<^bold>\<langle>f\<^bold>\<rangle> \<^bold>\<star> \<^bold>\<langle>v\<^bold>\<rangle>) (\<^bold>\<langle>f\<^bold>\<rangle> \<^bold>\<star> \<^bold>\<langle>v\<^bold>\<rangle>)"
using assms \<mu> antipar canI_unitor_0 canI_associator_1
canI_associator_1(1-2) [of f v] whisker_can_right_0 whisker_can_left_0
by simp
also have "... = \<l>[u] \<cdot> (trg u \<star> \<mu>) \<cdot> \<l>\<^sup>-\<^sup>1[f \<star> v]"
unfolding can_def using assms antipar comp_arr_dom comp_cod_arr \<ll>_ide_simp
by simp
also have "... = (\<l>[u] \<cdot> \<l>\<^sup>-\<^sup>1[u]) \<cdot> \<mu>"
using assms \<mu> lunit'_naturality [of \<mu>] comp_assoc by auto
also have "... = \<mu>"
using assms \<mu> comp_cod_arr iso_lunit comp_arr_inv inv_is_inverse by auto
finally show "trnl\<^sub>\<epsilon> u (trnl\<^sub>\<eta> v \<mu>) = \<mu>" by simp
qed
show D: "\<And>\<nu>. \<guillemotleft>\<nu> : v \<Rightarrow> g \<star> u\<guillemotright> \<Longrightarrow> trnl\<^sub>\<eta> v (trnl\<^sub>\<epsilon> u \<nu>) = \<nu>"
proof -
fix \<nu>
assume \<nu>: "\<guillemotleft>\<nu> : v \<Rightarrow> g \<star> u\<guillemotright>"
have "trnl\<^sub>\<eta> v (trnl\<^sub>\<epsilon> u \<nu>) =
(g \<star> \<l>[u] \<cdot> (\<epsilon> \<star> u) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, u] \<cdot> (f \<star> \<nu>)) \<cdot> \<a>[g, f, v] \<cdot> (\<eta> \<star> v) \<cdot> \<l>\<^sup>-\<^sup>1[v]"
using trnl\<^sub>\<eta>_def trnl\<^sub>\<epsilon>_def by simp
also have "... = (g \<star> \<l>[u]) \<cdot> (g \<star> \<epsilon> \<star> u) \<cdot> (g \<star> \<a>\<^sup>-\<^sup>1[f, g, u]) \<cdot> (g \<star> f \<star> \<nu>) \<cdot>
\<a>[g, f, v] \<cdot> (\<eta> \<star> v) \<cdot> \<l>\<^sup>-\<^sup>1[v]"
using assms \<nu> antipar interchange [of g "g \<cdot> g \<cdot> g"] comp_assoc by auto
also have "... = ((g \<star> \<l>[u]) \<cdot> (g \<star> \<epsilon> \<star> u) \<cdot> (g \<star> \<a>\<^sup>-\<^sup>1[f, g, u]) \<cdot>
\<a>[g, f, g \<star> u] \<cdot> (\<eta> \<star> g \<star> u)) \<cdot> (trg v \<star> \<nu>) \<cdot> \<l>\<^sup>-\<^sup>1[v]"
proof -
have "(g \<star> f \<star> \<nu>) \<cdot> \<a>[g, f, v] \<cdot> (\<eta> \<star> v) \<cdot> \<l>\<^sup>-\<^sup>1[v] =
\<a>[g, f, g \<star> u] \<cdot> (\<eta> \<star> g \<star> u) \<cdot> (trg v \<star> \<nu>) \<cdot> \<l>\<^sup>-\<^sup>1[v]"
proof -
have "(g \<star> f \<star> \<nu>) \<cdot> \<a>[g, f, v] \<cdot> (\<eta> \<star> v) \<cdot> \<l>\<^sup>-\<^sup>1[v] =
\<a>[g, f, g \<star> u] \<cdot> ((g \<star> f) \<star> \<nu>) \<cdot> (\<eta> \<star> v) \<cdot> \<l>\<^sup>-\<^sup>1[v]"
proof -
have "(g \<star> f \<star> \<nu>) \<cdot> \<a>[g, f, v] = \<a>[g, f, g \<star> u] \<cdot> ((g \<star> f) \<star> \<nu>)"
using assms \<nu> antipar assoc_naturality [of g f \<nu>] by auto
thus ?thesis
using assms comp_assoc by metis
qed
also have "... = \<a>[g, f, g \<star> u] \<cdot> (\<eta> \<star> g \<star> u) \<cdot> (trg v \<star> \<nu>) \<cdot> \<l>\<^sup>-\<^sup>1[v]"
proof -
have "((g \<star> f) \<star> \<nu>) \<cdot> (\<eta> \<star> v) = (\<eta> \<star> g \<star> u) \<cdot> (trg v \<star> \<nu>)"
using assms \<nu> antipar comp_arr_dom comp_cod_arr
interchange [of "g \<star> f" \<eta> \<nu> v] interchange [of \<eta> "trg v" "g \<star> u" \<nu>]
by auto
thus ?thesis
using comp_assoc by metis
qed
finally show ?thesis by blast
qed
thus ?thesis using comp_assoc by simp
qed
also have "... = \<l>[g \<star> u] \<cdot> (trg v \<star> \<nu>) \<cdot> \<l>\<^sup>-\<^sup>1[v]"
proof -
have "(g \<star> \<l>[u]) \<cdot> (g \<star> \<epsilon> \<star> u) \<cdot> (g \<star> \<a>\<^sup>-\<^sup>1[f, g, u]) \<cdot> \<a>[g, f, g \<star> u] \<cdot> (\<eta> \<star> g \<star> u) =
\<l>[g \<star> u]"
proof -
have "(g \<star> \<l>[u]) \<cdot> (g \<star> \<epsilon> \<star> u) \<cdot> (g \<star> \<a>\<^sup>-\<^sup>1[f, g, u]) \<cdot> \<a>[g, f, g \<star> u] \<cdot> (\<eta> \<star> g \<star> u) =
(g \<star> \<l>[u]) \<cdot> \<a>[g, trg u, u] \<cdot>
((g \<star> \<epsilon>) \<cdot> \<a>[g, f, g] \<cdot> (\<eta> \<star> g) \<star> u) \<cdot>
\<a>\<^sup>-\<^sup>1[trg v, g, u]"
proof -
have "(g \<star> \<l>[u]) \<cdot> (g \<star> \<epsilon> \<star> u) \<cdot> (g \<star> \<a>\<^sup>-\<^sup>1[f, g, u]) \<cdot> \<a>[g, f, g \<star> u] \<cdot> (\<eta> \<star> g \<star> u) =
(g \<star> \<l>[u]) \<cdot> (g \<star> \<epsilon> \<star> u) \<cdot> (g \<star> \<a>\<^sup>-\<^sup>1[f, g, u]) \<cdot> \<a>[g, f, g \<star> u] \<cdot>
((\<eta> \<star> g \<star> u) \<cdot> \<a>[trg v, g, u]) \<cdot> \<a>\<^sup>-\<^sup>1[trg v, g, u]"
using assms antipar comp_arr_dom comp_assoc comp_assoc_assoc'(1) by simp
also have "... = (g \<star> \<l>[u]) \<cdot> (g \<star> \<epsilon> \<star> u) \<cdot> (g \<star> \<a>\<^sup>-\<^sup>1[f, g, u]) \<cdot> \<a>[g, f, g \<star> u] \<cdot>
(\<a>[g \<star> f, g, u] \<cdot> ((\<eta> \<star> g) \<star> u)) \<cdot> \<a>\<^sup>-\<^sup>1[trg v, g, u]"
using assms antipar assoc_naturality [of \<eta> g u] by simp
also have "... = (g \<star> \<l>[u]) \<cdot> (g \<star> \<epsilon> \<star> u) \<cdot>
((g \<star> \<a>\<^sup>-\<^sup>1[f, g, u]) \<cdot> \<a>[g, f, g \<star> u] \<cdot> \<a>[g \<star> f, g, u]) \<cdot>
((\<eta> \<star> g) \<star> u) \<cdot> \<a>\<^sup>-\<^sup>1[trg v, g, u]"
using comp_assoc by simp
also have "... = (g \<star> \<l>[u]) \<cdot> ((\<a>[g, trg u, u] \<cdot> \<a>\<^sup>-\<^sup>1[g, trg u, u]) \<cdot> (g \<star> \<epsilon> \<star> u)) \<cdot>
((g \<star> \<a>\<^sup>-\<^sup>1[f, g, u]) \<cdot> \<a>[g, f, g \<star> u] \<cdot> \<a>[g \<star> f, g, u]) \<cdot>
((\<eta> \<star> g) \<star> u) \<cdot> \<a>\<^sup>-\<^sup>1[trg v, g, u]"
proof -
have "(\<a>[g, trg u, u] \<cdot> \<a>\<^sup>-\<^sup>1[g, trg u, u]) \<cdot> (g \<star> \<epsilon> \<star> u) = g \<star> \<epsilon> \<star> u"
using assms antipar comp_cod_arr comp_assoc_assoc'(1) by simp
thus ?thesis
using comp_assoc by simp
qed
also have "... = (g \<star> \<l>[u]) \<cdot> \<a>[g, trg u, u] \<cdot> (\<a>\<^sup>-\<^sup>1[g, trg u, u] \<cdot> (g \<star> \<epsilon> \<star> u)) \<cdot>
(g \<star> \<a>\<^sup>-\<^sup>1[f, g, u]) \<cdot> \<a>[g, f, g \<star> u] \<cdot> \<a>[g \<star> f, g, u] \<cdot>
((\<eta> \<star> g) \<star> u) \<cdot> \<a>\<^sup>-\<^sup>1[trg v, g, u]"
using comp_assoc by simp
also have "... = (g \<star> \<l>[u]) \<cdot> \<a>[g, trg u, u] \<cdot> (((g \<star> \<epsilon>) \<star> u) \<cdot> (\<a>\<^sup>-\<^sup>1[g, f \<star> g, u] \<cdot>
(g \<star> \<a>\<^sup>-\<^sup>1[f, g, u]) \<cdot> \<a>[g, f, g \<star> u] \<cdot> \<a>[g \<star> f, g, u]) \<cdot>
((\<eta> \<star> g) \<star> u)) \<cdot> \<a>\<^sup>-\<^sup>1[trg v, g, u]"
using assms antipar assoc'_naturality [of g \<epsilon> u] comp_assoc by simp
also have "... = (g \<star> \<l>[u]) \<cdot> \<a>[g, trg u, u] \<cdot>
((g \<star> \<epsilon>) \<cdot> \<a>[g, f, g] \<cdot> (\<eta> \<star> g) \<star> u) \<cdot>
\<a>\<^sup>-\<^sup>1[trg v, g, u]"
proof -
have "\<a>\<^sup>-\<^sup>1[g, f \<star> g, u] \<cdot> (g \<star> \<a>\<^sup>-\<^sup>1[f, g, u]) \<cdot> \<a>[g, f, g \<star> u] \<cdot> \<a>[g \<star> f, g, u] =
\<a>[g, f, g] \<star> u"
using assms antipar canI_associator_0 whisker_can_left_0 whisker_can_right_0
canI_associator_hcomp
by simp
hence "((g \<star> \<epsilon>) \<star> u) \<cdot>
(\<a>\<^sup>-\<^sup>1[g, f \<star> g, u] \<cdot> (g \<star> \<a>\<^sup>-\<^sup>1[f, g, u]) \<cdot> \<a>[g, f, g \<star> u] \<cdot> \<a>[g \<star> f, g, u]) \<cdot>
((\<eta> \<star> g) \<star> u) =
(g \<star> \<epsilon>) \<cdot> \<a>[g, f, g] \<cdot> (\<eta> \<star> g) \<star> u"
using assms antipar whisker_right by simp
thus ?thesis by simp
qed
finally show ?thesis by blast
qed
also have "... = (g \<star> \<l>[u]) \<cdot> \<a>[g, trg u, u] \<cdot> (\<r>\<^sup>-\<^sup>1[g] \<cdot> \<l>[g] \<star> u) \<cdot> \<a>\<^sup>-\<^sup>1[trg g, g, u]"
using assms antipar triangle_right by simp
also have "... = can (\<^bold>\<langle>g\<^bold>\<rangle> \<^bold>\<star> \<^bold>\<langle>u\<^bold>\<rangle>) (\<^bold>\<langle>trg g\<^bold>\<rangle>\<^sub>0 \<^bold>\<star> \<^bold>\<langle>g\<^bold>\<rangle> \<^bold>\<star> \<^bold>\<langle>u\<^bold>\<rangle>)"
proof -
have "(g \<star> \<l>[u]) \<cdot> \<a>[g, trg u, u] \<cdot> (\<r>\<^sup>-\<^sup>1[g] \<cdot> \<l>[g] \<star> u) \<cdot> \<a>\<^sup>-\<^sup>1[trg g, g, u] =
((g \<star> \<l>[u]) \<cdot> \<a>[g, trg u, u] \<cdot> (\<r>\<^sup>-\<^sup>1[g] \<cdot> \<l>[g] \<star> u) \<cdot> \<a>\<^sup>-\<^sup>1[trg g, g, u])"
using comp_assoc by simp
moreover have "... = can (\<^bold>\<langle>g\<^bold>\<rangle> \<^bold>\<star> \<^bold>\<langle>u\<^bold>\<rangle>) (\<^bold>\<langle>trg g\<^bold>\<rangle>\<^sub>0 \<^bold>\<star> \<^bold>\<langle>g\<^bold>\<rangle> \<^bold>\<star> \<^bold>\<langle>u\<^bold>\<rangle>)"
using assms antipar canI_unitor_0 canI_associator_1 [of g u] inv_can
whisker_can_left_0 whisker_can_right_0
by simp
ultimately show ?thesis by simp
qed
also have "... = \<l>[g \<star> u]"
unfolding can_def using assms comp_arr_dom comp_cod_arr \<ll>_ide_simp by simp
finally show ?thesis by simp
qed
thus ?thesis by simp
qed
also have "... = (\<l>[g \<star> u] \<cdot> \<l>\<^sup>-\<^sup>1[g \<star> u]) \<cdot> \<nu>"
using assms \<nu> lunit'_naturality comp_assoc by auto
also have "... = \<nu>"
using assms \<nu> comp_cod_arr iso_lunit comp_arr_inv inv_is_inverse by auto
finally show "trnl\<^sub>\<eta> v (trnl\<^sub>\<epsilon> u \<nu>) = \<nu>" by simp
qed
show "bij_betw (trnl\<^sub>\<eta> v) (hom (f \<star> v) u) (hom v (g \<star> u))"
using A B C D by (intro bij_betwI, auto)
show "bij_betw (trnl\<^sub>\<epsilon> u) (hom v (g \<star> u)) (hom (f \<star> v) u)"
using A B C D by (intro bij_betwI, auto)
qed
lemma trnl\<^sub>\<epsilon>_comp:
assumes "ide u" and "seq \<mu> \<nu>" and "src f = trg \<mu>"
shows "trnl\<^sub>\<epsilon> u (\<mu> \<cdot> \<nu>) = trnl\<^sub>\<epsilon> u \<mu> \<cdot> (f \<star> \<nu>)"
using assms trnl\<^sub>\<epsilon>_def whisker_left [of f \<mu> \<nu>] comp_assoc by auto
definition trnr\<^sub>\<eta>
where "trnr\<^sub>\<eta> v \<mu> \<equiv> (\<mu> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[v, g, f] \<cdot> (v \<star> \<eta>) \<cdot> \<r>\<^sup>-\<^sup>1[v]"
definition trnr\<^sub>\<epsilon>
where "trnr\<^sub>\<epsilon> u \<nu> \<equiv> \<r>[u] \<cdot> (u \<star> \<epsilon>) \<cdot> \<a>[u, f, g] \<cdot> (\<nu> \<star> g)"
lemma adjoint_transpose_right:
assumes "ide u" and "ide v" and "src v = trg g" and "src u = trg f"
shows "trnr\<^sub>\<eta> v \<in> hom (v \<star> g) u \<rightarrow> hom v (u \<star> f)"
and "trnr\<^sub>\<epsilon> u \<in> hom v (u \<star> f) \<rightarrow> hom (v \<star> g) u"
and "\<guillemotleft>\<mu> : v \<star> g \<Rightarrow> u\<guillemotright> \<Longrightarrow> trnr\<^sub>\<epsilon> u (trnr\<^sub>\<eta> v \<mu>) = \<mu>"
and "\<guillemotleft>\<nu> : v \<Rightarrow> u \<star> f\<guillemotright> \<Longrightarrow> trnr\<^sub>\<eta> v (trnr\<^sub>\<epsilon> u \<nu>) = \<nu>"
and "bij_betw (trnr\<^sub>\<eta> v) (hom (v \<star> g) u) (hom v (u \<star> f))"
and "bij_betw (trnr\<^sub>\<epsilon> u) (hom v (u \<star> f)) (hom (v \<star> g) u)"
proof -
show A: "trnr\<^sub>\<eta> v \<in> hom (v \<star> g) u \<rightarrow> hom v (u \<star> f)"
using assms antipar trnr\<^sub>\<eta>_def by fastforce
show B: "trnr\<^sub>\<epsilon> u \<in> hom v (u \<star> f) \<rightarrow> hom (v \<star> g) u"
using assms antipar trnr\<^sub>\<epsilon>_def by fastforce
show C: "\<And>\<mu>. \<guillemotleft>\<mu> : v \<star> g \<Rightarrow> u\<guillemotright> \<Longrightarrow> trnr\<^sub>\<epsilon> u (trnr\<^sub>\<eta> v \<mu>) = \<mu>"
proof -
fix \<mu>
assume \<mu>: "\<guillemotleft>\<mu> : v \<star> g \<Rightarrow> u\<guillemotright>"
have "trnr\<^sub>\<epsilon> u (trnr\<^sub>\<eta> v \<mu>) =
\<r>[u] \<cdot> (u \<star> \<epsilon>) \<cdot> \<a>[u, f, g] \<cdot> ((\<mu> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[v, g, f] \<cdot> (v \<star> \<eta>) \<cdot> \<r>\<^sup>-\<^sup>1[v] \<star> g)"
unfolding trnr\<^sub>\<epsilon>_def trnr\<^sub>\<eta>_def by simp
also have "... = \<r>[u] \<cdot> (u \<star> \<epsilon>) \<cdot> (\<a>[u, f, g] \<cdot> ((\<mu> \<star> f) \<star> g)) \<cdot>
(\<a>\<^sup>-\<^sup>1[v, g, f] \<star> g) \<cdot> ((v \<star> \<eta>) \<star> g) \<cdot> (\<r>\<^sup>-\<^sup>1[v] \<star> g)"
using assms \<mu> antipar whisker_right comp_assoc by auto
also have "... = \<r>[u] \<cdot> (u \<star> \<epsilon>) \<cdot> ((\<mu> \<star> f \<star> g) \<cdot> \<a>[v \<star> g, f, g]) \<cdot>
(\<a>\<^sup>-\<^sup>1[v, g, f] \<star> g) \<cdot> ((v \<star> \<eta>) \<star> g) \<cdot> (\<r>\<^sup>-\<^sup>1[v] \<star> g)"
using assms \<mu> antipar assoc_naturality [of \<mu> f g] by auto
also have "... = \<r>[u] \<cdot> ((u \<star> \<epsilon>) \<cdot> (\<mu> \<star> f \<star> g)) \<cdot> \<a>[v \<star> g, f, g] \<cdot>
(\<a>\<^sup>-\<^sup>1[v, g, f] \<star> g) \<cdot> ((v \<star> \<eta>) \<star> g) \<cdot> (\<r>\<^sup>-\<^sup>1[v] \<star> g)"
using comp_assoc by auto
also have "... = \<r>[u] \<cdot> (\<mu> \<star> src u) \<cdot> ((v \<star> g) \<star> \<epsilon>) \<cdot> \<a>[v \<star> g, f, g] \<cdot>
(\<a>\<^sup>-\<^sup>1[v, g, f] \<star> g) \<cdot> ((v \<star> \<eta>) \<star> g) \<cdot> (\<r>\<^sup>-\<^sup>1[v] \<star> g)"
proof -
have "(u \<star> \<epsilon>) \<cdot> (\<mu> \<star> f \<star> g) = (\<mu> \<star> src u) \<cdot> ((v \<star> g) \<star> \<epsilon>)"
using assms \<mu> antipar comp_arr_dom comp_cod_arr
interchange [of \<mu> "v \<star> g" "src u" \<epsilon>] interchange [of u \<mu> \<epsilon> "f \<star> g"]
by auto
thus ?thesis
using comp_assoc by simp
qed
also have "... = \<r>[u] \<cdot> (\<mu> \<star> src u) \<cdot>
(((v \<star> g) \<star> \<epsilon>) \<cdot> \<a>[v \<star> g, f, g] \<cdot> (\<a>\<^sup>-\<^sup>1[v, g, f] \<star> g) \<cdot> ((v \<star> \<eta>) \<star> g)) \<cdot>
(\<r>\<^sup>-\<^sup>1[v] \<star> g)"
using comp_assoc by simp
also have "... = \<r>[u] \<cdot> (\<mu> \<star> src u) \<cdot>
(\<a>\<^sup>-\<^sup>1[v, g, src u] \<cdot> (v \<star> (g \<star> \<epsilon>) \<cdot> \<a>[g, f, g] \<cdot> (\<eta> \<star> g)) \<cdot>
\<a>[v, src v, g]) \<cdot> (\<r>\<^sup>-\<^sup>1[v] \<star> g)"
proof -
have "((v \<star> g) \<star> \<epsilon>) \<cdot> \<a>[v \<star> g, f, g] \<cdot> (\<a>\<^sup>-\<^sup>1[v, g, f] \<star> g) \<cdot> ((v \<star> \<eta>) \<star> g) =
\<a>\<^sup>-\<^sup>1[v, g, src u] \<cdot> (v \<star> (g \<star> \<epsilon>) \<cdot> \<a>[g, f, g] \<cdot> (\<eta> \<star> g)) \<cdot> \<a>[v, src v, g]"
proof -
have "((v \<star> g) \<star> \<epsilon>) \<cdot> \<a>[v \<star> g, f, g] \<cdot> (\<a>\<^sup>-\<^sup>1[v, g, f] \<star> g) \<cdot> ((v \<star> \<eta>) \<star> g) =
((\<a>\<^sup>-\<^sup>1[v, g, src u] \<cdot> \<a>[v, g, src u]) \<cdot> ((v \<star> g) \<star> \<epsilon>)) \<cdot>
\<a>[v \<star> g, f, g] \<cdot> (\<a>\<^sup>-\<^sup>1[v, g, f] \<star> g) \<cdot> ((v \<star> \<eta>) \<star> g)"
proof -
have "arr v \<and> dom v = v \<and> cod v = v"
using assms(2) ide_char by blast
moreover have "arr g \<and> dom g = g \<and> cod g = g"
using ide_right ide_char by blast
ultimately show ?thesis
by (metis (no_types) antipar(2) assms(3-4) assoc_naturality
counit_simps(1,3,5) hcomp_reassoc(1) comp_assoc)
qed
also have "... = \<a>\<^sup>-\<^sup>1[v, g, src u] \<cdot> (\<a>[v, g, src u] \<cdot> ((v \<star> g) \<star> \<epsilon>)) \<cdot>
\<a>[v \<star> g, f, g] \<cdot> (\<a>\<^sup>-\<^sup>1[v, g, f] \<star> g) \<cdot> ((v \<star> \<eta>) \<star> g)"
using comp_assoc by simp
also have "... = \<a>\<^sup>-\<^sup>1[v, g, src u] \<cdot> ((v \<star> g \<star> \<epsilon>) \<cdot> \<a>[v, g, f \<star> g]) \<cdot>
\<a>[v \<star> g, f, g] \<cdot> (\<a>\<^sup>-\<^sup>1[v, g, f] \<star> g) \<cdot>
(\<a>\<^sup>-\<^sup>1[v, g \<star> f, g] \<cdot> \<a>[v, g \<star> f, g]) \<cdot> ((v \<star> \<eta>) \<star> g)"
proof -
have "\<a>[v, g, src u] \<cdot> ((v \<star> g) \<star> \<epsilon>) = (v \<star> g \<star> \<epsilon>) \<cdot> \<a>[v, g, f \<star> g]"
using assms antipar assoc_naturality [of v g \<epsilon>] by simp
moreover have "(\<a>\<^sup>-\<^sup>1[v, g \<star> f, g] \<cdot> \<a>[v, g \<star> f, g]) \<cdot> ((v \<star> \<eta>) \<star> g) = (v \<star> \<eta>) \<star> g"
using assms antipar comp_cod_arr comp_assoc_assoc'(2) by simp
ultimately show ?thesis by simp
qed
also have "... = \<a>\<^sup>-\<^sup>1[v, g, src u] \<cdot> (v \<star> g \<star> \<epsilon>) \<cdot>
\<a>[v, g, f \<star> g] \<cdot> \<a>[v \<star> g, f, g] \<cdot> (\<a>\<^sup>-\<^sup>1[v, g, f] \<star> g) \<cdot>
\<a>\<^sup>-\<^sup>1[v, g \<star> f, g] \<cdot> \<a>[v, g \<star> f, g] \<cdot> ((v \<star> \<eta>) \<star> g)"
using comp_assoc by simp
also have "... = \<a>\<^sup>-\<^sup>1[v, g, src u] \<cdot> ((v \<star> g \<star> \<epsilon>) \<cdot>
(\<a>[v, g, f \<star> g] \<cdot> \<a>[v \<star> g, f, g] \<cdot> (\<a>\<^sup>-\<^sup>1[v, g, f] \<star> g) \<cdot>
\<a>\<^sup>-\<^sup>1[v, g \<star> f, g]) \<cdot> (v \<star> \<eta> \<star> g)) \<cdot> \<a>[v, src v, g]"
using assms antipar assoc_naturality [of v \<eta> g] comp_assoc by simp
also have "... = \<a>\<^sup>-\<^sup>1[v, g, src u] \<cdot>
((v \<star> g \<star> \<epsilon>) \<cdot> (v \<star> \<a>[g, f, g]) \<cdot> (v \<star> \<eta> \<star> g)) \<cdot>
\<a>[v, src v, g]"
proof -
have "\<a>[v, g, f \<star> g] \<cdot> \<a>[v \<star> g, f, g] \<cdot> (\<a>\<^sup>-\<^sup>1[v, g, f] \<star> g) \<cdot> \<a>\<^sup>-\<^sup>1[v, g \<star> f, g] =
v \<star> \<a>[g, f, g]"
using assms antipar canI_associator_0 canI_associator_hcomp
whisker_can_left_0 whisker_can_right_0
by simp
thus ?thesis
using assms antipar whisker_left by simp
qed
also have "... = \<a>\<^sup>-\<^sup>1[v, g, src u] \<cdot>
(v \<star> (g \<star> \<epsilon>) \<cdot> \<a>[g, f, g] \<cdot> (\<eta> \<star> g)) \<cdot>
\<a>[v, src v, g]"
using assms antipar whisker_left by simp
finally show ?thesis by simp
qed
thus ?thesis by auto
qed
also have "... = \<r>[u] \<cdot> (\<mu> \<star> src u) \<cdot>
\<a>\<^sup>-\<^sup>1[v, g, src u] \<cdot> (v \<star> \<r>\<^sup>-\<^sup>1[g] \<cdot> \<l>[g]) \<cdot>
\<a>[v, src v, g] \<cdot> (\<r>\<^sup>-\<^sup>1[v] \<star> g)"
using triangle_right comp_assoc by simp
also have "... = \<r>[u] \<cdot> (\<mu> \<star> src u) \<cdot> \<r>\<^sup>-\<^sup>1[v \<star> g]"
proof -
have "\<a>\<^sup>-\<^sup>1[v, g, src u] \<cdot> (v \<star> \<r>\<^sup>-\<^sup>1[g] \<cdot> \<l>[g]) \<cdot> \<a>[v, src v, g] \<cdot> (\<r>\<^sup>-\<^sup>1[v] \<star> g) = \<r>\<^sup>-\<^sup>1[v \<star> g]"
proof -
have "\<a>\<^sup>-\<^sup>1[v, g, src u] \<cdot> (v \<star> \<r>\<^sup>-\<^sup>1[g] \<cdot> \<l>[g]) \<cdot> \<a>[v, src v, g] \<cdot> (\<r>\<^sup>-\<^sup>1[v] \<star> g) =
\<a>\<^sup>-\<^sup>1[v, g, trg f] \<cdot> can (\<^bold>\<langle>v\<^bold>\<rangle> \<^bold>\<star> \<^bold>\<langle>g\<^bold>\<rangle> \<^bold>\<star> \<^bold>\<langle>src g\<^bold>\<rangle>\<^sub>0) (\<^bold>\<langle>v\<^bold>\<rangle> \<^bold>\<star> \<^bold>\<langle>g\<^bold>\<rangle>)"
using assms canI_unitor_0 canI_associator_1(2-3) whisker_can_left_0(1)
whisker_can_right_0
by simp
also have "... = \<a>\<^sup>-\<^sup>1[v, g, src g] \<cdot> can (\<^bold>\<langle>v\<^bold>\<rangle> \<^bold>\<star> \<^bold>\<langle>g\<^bold>\<rangle> \<^bold>\<star> \<^bold>\<langle>src g\<^bold>\<rangle>\<^sub>0) (\<^bold>\<langle>v\<^bold>\<rangle> \<^bold>\<star> \<^bold>\<langle>g\<^bold>\<rangle>)"
using antipar by simp
(* TODO: There should be an alternate version of whisker_can_left for this. *)
also have "... = \<a>\<^sup>-\<^sup>1[v, g, src g] \<cdot> (v \<star> can (\<^bold>\<langle>g\<^bold>\<rangle> \<^bold>\<star> \<^bold>\<langle>src g\<^bold>\<rangle>\<^sub>0) \<^bold>\<langle>g\<^bold>\<rangle>)"
using assms canI_unitor_0(2) whisker_can_left_0 by simp
also have "... = \<a>\<^sup>-\<^sup>1[v, g, src g] \<cdot> (v \<star> \<r>\<^sup>-\<^sup>1[g])"
using assms canI_unitor_0(2) by simp
also have "... = \<r>\<^sup>-\<^sup>1[v \<star> g]"
using assms runit_hcomp(2) by simp
finally have "\<a>\<^sup>-\<^sup>1[v, g, src u] \<cdot> (v \<star> \<r>\<^sup>-\<^sup>1[g] \<cdot> \<l>[g]) \<cdot> \<a>[v, src v, g] \<cdot> (\<r>\<^sup>-\<^sup>1[v] \<star> g) =
\<r>\<^sup>-\<^sup>1[v \<star> g]"
by simp
thus ?thesis by simp
qed
thus ?thesis by simp
qed
also have "... = (\<r>[u] \<cdot> \<r>\<^sup>-\<^sup>1[u]) \<cdot> \<mu>"
using assms \<mu> runit'_naturality [of \<mu>] comp_assoc by auto
also have "... = \<mu>"
using \<mu> comp_cod_arr iso_runit inv_is_inverse comp_arr_inv by auto
finally show "trnr\<^sub>\<epsilon> u (trnr\<^sub>\<eta> v \<mu>) = \<mu>" by simp
qed
show D: "\<And>\<nu>. \<guillemotleft>\<nu> : v \<Rightarrow> u \<star> f\<guillemotright> \<Longrightarrow> trnr\<^sub>\<eta> v (trnr\<^sub>\<epsilon> u \<nu>) = \<nu>"
proof -
fix \<nu>
assume \<nu>: "\<guillemotleft>\<nu> : v \<Rightarrow> u \<star> f\<guillemotright>"
have "trnr\<^sub>\<eta> v (trnr\<^sub>\<epsilon> u \<nu>) =
(\<r>[u] \<cdot> (u \<star> \<epsilon>) \<cdot> \<a>[u, f, g] \<cdot> (\<nu> \<star> g) \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[v, g, f] \<cdot> (v \<star> \<eta>) \<cdot> \<r>\<^sup>-\<^sup>1[v]"
unfolding trnr\<^sub>\<eta>_def trnr\<^sub>\<epsilon>_def by simp
also have "... = (\<r>[u] \<star> f) \<cdot> ((u \<star> \<epsilon>) \<star> f) \<cdot> (\<a>[u, f, g] \<star> f) \<cdot>
(((\<nu> \<star> g) \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[v, g, f]) \<cdot> (v \<star> \<eta>) \<cdot> \<r>\<^sup>-\<^sup>1[v]"
using assms \<nu> antipar whisker_right comp_assoc by auto
also have "... = (\<r>[u] \<star> f) \<cdot> ((u \<star> \<epsilon>) \<star> f) \<cdot> (\<a>[u, f, g] \<star> f) \<cdot>
(\<a>\<^sup>-\<^sup>1[u \<star> f, g, f] \<cdot> (\<nu> \<star> g \<star> f)) \<cdot> (v \<star> \<eta>) \<cdot> \<r>\<^sup>-\<^sup>1[v]"
using assms \<nu> antipar assoc'_naturality [of \<nu> g f] by auto
also have "... = (\<r>[u] \<star> f) \<cdot> ((u \<star> \<epsilon>) \<star> f) \<cdot> (\<a>[u, f, g] \<star> f) \<cdot>
\<a>\<^sup>-\<^sup>1[u \<star> f, g, f] \<cdot> ((\<nu> \<star> g \<star> f) \<cdot> (v \<star> \<eta>)) \<cdot> \<r>\<^sup>-\<^sup>1[v]"
using comp_assoc by simp
also have "... = (\<r>[u] \<star> f) \<cdot> ((u \<star> \<epsilon>) \<star> f) \<cdot> (\<a>[u, f, g] \<star> f) \<cdot>
\<a>\<^sup>-\<^sup>1[u \<star> f, g, f] \<cdot> (((u \<star> f) \<star> \<eta>) \<cdot> (\<nu> \<star> src v)) \<cdot> \<r>\<^sup>-\<^sup>1[v]"
proof -
have "(\<nu> \<star> g \<star> f) \<cdot> (v \<star> \<eta>) = ((u \<star> f) \<star> \<eta>) \<cdot> (\<nu> \<star> src v)"
using assms \<nu> antipar interchange [of "u \<star> f" \<nu> \<eta> "src v"]
interchange [of \<nu> v "g \<star> f" \<eta>] comp_arr_dom comp_cod_arr
by auto
thus ?thesis by simp
qed
also have "... = ((\<r>[u] \<star> f) \<cdot> ((u \<star> \<epsilon>) \<star> f) \<cdot>
((\<a>[u, f, g] \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[u \<star> f, g, f]) \<cdot>
((u \<star> f) \<star> \<eta>)) \<cdot> (\<nu> \<star> src v) \<cdot> \<r>\<^sup>-\<^sup>1[v]"
using comp_assoc by simp
also have "... = ((\<r>[u] \<star> f) \<cdot> ((u \<star> \<epsilon>) \<star> f) \<cdot>
(\<a>\<^sup>-\<^sup>1[u, f \<star> g, f] \<cdot> (u \<star> \<a>\<^sup>-\<^sup>1[f, g, f]) \<cdot> \<a>[u, f, g \<star> f]) \<cdot>
((u \<star> f) \<star> \<eta>)) \<cdot> (\<nu> \<star> src v) \<cdot> \<r>\<^sup>-\<^sup>1[v]"
using assms antipar canI_associator_hcomp canI_associator_0 whisker_can_left_0
whisker_can_right_0
by simp
also have "... = ((\<r>[u] \<star> f) \<cdot> (((u \<star> \<epsilon>) \<star> f) \<cdot>
\<a>\<^sup>-\<^sup>1[u, f \<star> g, f]) \<cdot> (u \<star> \<a>\<^sup>-\<^sup>1[f, g, f]) \<cdot> (\<a>[u, f, g \<star> f]) \<cdot>
((u \<star> f) \<star> \<eta>)) \<cdot> (\<nu> \<star> src v) \<cdot> \<r>\<^sup>-\<^sup>1[v]"
using comp_assoc by simp
also have "... = ((\<r>[u] \<star> f) \<cdot> (\<a>\<^sup>-\<^sup>1[u, src u, f] \<cdot> (u \<star> \<epsilon> \<star> f)) \<cdot>
(u \<star> \<a>\<^sup>-\<^sup>1[f, g, f]) \<cdot> ((u \<star> f \<star> \<eta>) \<cdot> \<a>[u, f, src f])) \<cdot>
(\<nu> \<star> src v) \<cdot> \<r>\<^sup>-\<^sup>1[v]"
using assms antipar assoc'_naturality [of u \<epsilon> f] assoc_naturality [of u f \<eta>]
by auto
also have "... = (\<r>[u] \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[u, src u, f] \<cdot>
((u \<star> \<epsilon> \<star> f) \<cdot> (u \<star> \<a>\<^sup>-\<^sup>1[f, g, f]) \<cdot> (u \<star> f \<star> \<eta>)) \<cdot> \<a>[u, f, src f] \<cdot>
(\<nu> \<star> src v) \<cdot> \<r>\<^sup>-\<^sup>1[v]"
using comp_assoc by simp
also have "... = (\<r>[u] \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[u, src u, f] \<cdot>
(u \<star> (\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>)) \<cdot> \<a>[u, f, src f] \<cdot>
(\<nu> \<star> src v) \<cdot> \<r>\<^sup>-\<^sup>1[v]"
using assms antipar whisker_left by auto
also have "... = ((\<r>[u] \<star> f) \<cdot> (\<a>\<^sup>-\<^sup>1[u, src u, f] \<cdot> (u \<star> \<l>\<^sup>-\<^sup>1[f] \<cdot> \<r>[f]) \<cdot> \<a>[u, f, src f])) \<cdot>
(\<nu> \<star> src v) \<cdot> \<r>\<^sup>-\<^sup>1[v]"
using assms antipar triangle_left comp_assoc by simp
also have "... = \<r>[u \<star> f] \<cdot> (\<nu> \<star> src v) \<cdot> \<r>\<^sup>-\<^sup>1[v]"
proof -
have "(\<r>[u] \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[u, src u, f] \<cdot> (u \<star> \<l>\<^sup>-\<^sup>1[f] \<cdot> \<r>[f]) \<cdot> \<a>[u, f, src f] =
((u \<star> \<l>[f]) \<cdot> (\<a>[u, src u, f] \<cdot> \<a>\<^sup>-\<^sup>1[u, src u, f])) \<cdot>
(u \<star> \<l>\<^sup>-\<^sup>1[f] \<cdot> \<r>[f]) \<cdot> \<a>[u, f, src f]"
using assms ide_left ide_right antipar triangle comp_assoc by metis
also have "... = (u \<star> \<r>[f]) \<cdot> \<a>[u, f, src f]"
using assms antipar canI_associator_1 canI_unitor_0 whisker_can_left_0
whisker_can_right_0 canI_associator_1
by simp
also have "... = \<r>[u \<star> f]"
using assms antipar runit_hcomp by simp
finally show ?thesis by simp
qed
also have "... = (\<r>[u \<star> f] \<cdot> \<r>\<^sup>-\<^sup>1[u \<star> f]) \<cdot> \<nu>"
using assms \<nu> runit'_naturality [of \<nu>] comp_assoc by auto
also have "... = \<nu>"
using assms \<nu> comp_cod_arr comp_arr_inv inv_is_inverse iso_runit by auto
finally show "trnr\<^sub>\<eta> v (trnr\<^sub>\<epsilon> u \<nu>) = \<nu>" by auto
qed
show "bij_betw (trnr\<^sub>\<eta> v) (hom (v \<star> g) u) (hom v (u \<star> f))"
using A B C D by (intro bij_betwI, auto)
show "bij_betw (trnr\<^sub>\<epsilon> u) (hom v (u \<star> f)) (hom (v \<star> g) u)"
using A B C D by (intro bij_betwI, auto)
qed
lemma trnr\<^sub>\<eta>_comp:
assumes "ide v" and "seq \<mu> \<nu>" and "src \<mu> = trg f"
shows "trnr\<^sub>\<eta> v (\<mu> \<cdot> \<nu>) = (\<mu> \<star> f) \<cdot> trnr\<^sub>\<eta> v \<nu>"
using assms trnr\<^sub>\<eta>_def whisker_right comp_assoc by auto
end
text \<open>
It is useful to have at hand the simpler versions of the preceding results that
hold in a normal bicategory and in a strict bicategory.
\<close>
locale adjunction_in_normal_bicategory =
normal_bicategory +
adjunction_in_bicategory
begin
lemma triangle_left:
shows "(\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>) = f"
using triangle_left strict_lunit strict_runit by simp
lemma triangle_right:
shows "(g \<star> \<epsilon>) \<cdot> \<a>[g, f, g] \<cdot> (\<eta> \<star> g) = g"
using triangle_right strict_lunit strict_runit by simp
lemma trnr\<^sub>\<eta>_eq:
assumes "ide u" and "ide v"
and "src v = trg g" and "src u = trg f"
and "\<mu> \<in> hom (v \<star> g) u"
shows "trnr\<^sub>\<eta> v \<mu> = (\<mu> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[v, g, f] \<cdot> (v \<star> \<eta>)"
unfolding trnr\<^sub>\<eta>_def
using assms antipar strict_runit' comp_arr_ide [of "\<r>\<^sup>-\<^sup>1[v]" "v \<star> \<eta>"] hcomp_arr_obj
by auto
lemma trnr\<^sub>\<epsilon>_eq:
assumes "ide u" and "ide v"
and "src v = trg g" and "src u = trg f"
and "\<nu> \<in> hom v (u \<star> f)"
shows "trnr\<^sub>\<epsilon> u \<nu> = (u \<star> \<epsilon>) \<cdot> \<a>[u, f, g] \<cdot> (\<nu> \<star> g)"
unfolding trnr\<^sub>\<epsilon>_def
using assms antipar strict_runit comp_ide_arr hcomp_arr_obj by auto
lemma trnl\<^sub>\<eta>_eq:
assumes "ide u" and "ide v"
and "src f = trg v" and "src g = trg u"
and "\<mu> \<in> hom (f \<star> v) u"
shows "trnl\<^sub>\<eta> v \<mu> = (g \<star> \<mu>) \<cdot> \<a>[g, f, v] \<cdot> (\<eta> \<star> v)"
using assms trnl\<^sub>\<eta>_def antipar strict_lunit comp_arr_dom hcomp_obj_arr by auto
lemma trnl\<^sub>\<epsilon>_eq:
assumes "ide u" and "ide v"
and "src f = trg v" and "src g = trg u"
and "\<nu> \<in> hom v (g \<star> u)"
shows "trnl\<^sub>\<epsilon> u \<nu> = (\<epsilon> \<star> u) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, u] \<cdot> (f \<star> \<nu>)"
using assms trnl\<^sub>\<epsilon>_def antipar strict_lunit comp_cod_arr hcomp_obj_arr by auto
end
locale adjunction_in_strict_bicategory =
strict_bicategory +
adjunction_in_normal_bicategory
begin
lemma triangle_left:
shows "(\<epsilon> \<star> f) \<cdot> (f \<star> \<eta>) = f"
using ide_left ide_right antipar triangle_left strict_assoc' comp_cod_arr
by (metis dom_eqI ideD(1) seqE)
lemma triangle_right:
shows "(g \<star> \<epsilon>) \<cdot> (\<eta> \<star> g) = g"
using ide_left ide_right antipar triangle_right strict_assoc comp_cod_arr
by (metis ideD(1) ideD(2) seqE)
lemma trnr\<^sub>\<eta>_eq:
assumes "ide u" and "ide v"
and "src v = trg g" and "src u = trg f"
and "\<mu> \<in> hom (v \<star> g) u"
shows "trnr\<^sub>\<eta> v \<mu> = (\<mu> \<star> f) \<cdot> (v \<star> \<eta>)"
proof -
have "trnr\<^sub>\<eta> v \<mu> = (\<mu> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[v, g, f] \<cdot> (v \<star> \<eta>)"
using assms trnr\<^sub>\<eta>_eq [of u v \<mu>] by simp
also have "... = (\<mu> \<star> f) \<cdot> (v \<star> \<eta>)"
proof -
have "\<a>\<^sup>-\<^sup>1[v, g, f] \<cdot> (v \<star> \<eta>) = (v \<star> \<eta>)"
proof -
have "ide \<a>\<^sup>-\<^sup>1[v, g, f]"
using assms antipar strict_assoc' by simp
moreover have "seq \<a>\<^sup>-\<^sup>1[v, g, f] (v \<star> \<eta>)"
using assms antipar by simp
ultimately show ?thesis
using comp_ide_arr by simp
qed
thus ?thesis by simp
qed
finally show ?thesis by simp
qed
lemma trnr\<^sub>\<epsilon>_eq:
assumes "ide u" and "ide v"
and "src v = trg g" and "src u = trg f"
and "\<nu> \<in> hom v (u \<star> f)"
shows "trnr\<^sub>\<epsilon> u \<nu> = (u \<star> \<epsilon>) \<cdot> (\<nu> \<star> g)"
proof -
have "trnr\<^sub>\<epsilon> u \<nu> = (u \<star> \<epsilon>) \<cdot> \<a>[u, f, g] \<cdot> (\<nu> \<star> g)"
using assms trnr\<^sub>\<epsilon>_eq [of u v \<nu>] by simp
also have "... = (u \<star> \<epsilon>) \<cdot> (\<nu> \<star> g)"
proof -
have "\<a>[u, f, g] \<cdot> (\<nu> \<star> g) = (\<nu> \<star> g)"
proof -
have "ide \<a>[u, f, g]"
using assms antipar strict_assoc by simp
moreover have "seq \<a>[u, f, g] (\<nu> \<star> g)"
using assms antipar by force
ultimately show ?thesis
using comp_ide_arr by simp
qed
thus ?thesis by simp
qed
finally show ?thesis by simp
qed
lemma trnl\<^sub>\<eta>_eq:
assumes "ide u" and "ide v"
and "src f = trg v" and "src g = trg u"
and "\<mu> \<in> hom (f \<star> v) u"
shows "trnl\<^sub>\<eta> v \<mu> = (g \<star> \<mu>) \<cdot> (\<eta> \<star> v)"
proof -
have "trnl\<^sub>\<eta> v \<mu> = (g \<star> \<mu>) \<cdot> \<a>[g, f, v] \<cdot> (\<eta> \<star> v)"
using assms trnl\<^sub>\<eta>_eq [of u v \<mu>] by simp
also have "... = (g \<star> \<mu>) \<cdot> (\<eta> \<star> v)"
proof -
have "seq \<a>[g, f, v] (\<eta> \<star> v)"
using assms antipar unit_in_hom by simp
thus ?thesis
using assms antipar trnl\<^sub>\<eta>_eq strict_assoc comp_ide_arr [of "\<a>[g, f, v]" "\<eta> \<star> v"]
by simp
qed
finally show ?thesis by blast
qed
lemma trnl\<^sub>\<epsilon>_eq:
assumes "ide u" and "ide v"
and "src f = trg v" and "src g = trg u"
and "\<nu> \<in> hom v (g \<star> u)"
shows "trnl\<^sub>\<epsilon> u \<nu> = (\<epsilon> \<star> u) \<cdot> (f \<star> \<nu>)"
proof -
have "trnl\<^sub>\<epsilon> u \<nu> = (\<epsilon> \<star> u) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, u] \<cdot> (f \<star> \<nu>)"
using assms trnl\<^sub>\<epsilon>_eq [of u v \<nu>] by simp
also have "... = ((\<epsilon> \<star> u) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, u]) \<cdot> (f \<star> \<nu>)"
using comp_assoc by simp
also have "... = (\<epsilon> \<star> u) \<cdot> (f \<star> \<nu>)"
proof -
have "seq (\<epsilon> \<star> u) \<a>\<^sup>-\<^sup>1[f, g, u]"
using assms antipar unit_in_hom by simp
thus ?thesis
using assms antipar trnl\<^sub>\<epsilon>_eq strict_assoc' comp_arr_ide ide_left ide_right
by metis
qed
finally show ?thesis by simp
qed
end
subsection "Preservation Properties for Adjunctions"
text \<open>
Here we show that adjunctions are preserved under isomorphisms of the
left and right adjoints.
\<close>
context bicategory
begin
interpretation E: self_evaluation_map V H \<a> \<i> src trg ..
notation E.eval ("\<lbrace>_\<rbrace>")
definition adjoint_pair
where "adjoint_pair f g \<equiv> \<exists>\<eta> \<epsilon>. adjunction_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>"
(* These would normally be called "maps", but that name is too heavily used already. *)
abbreviation is_left_adjoint
where "is_left_adjoint f \<equiv> \<exists>g. adjoint_pair f g"
abbreviation is_right_adjoint
where "is_right_adjoint g \<equiv> \<exists>f. adjoint_pair f g"
lemma adjoint_pair_antipar:
assumes "adjoint_pair f g"
shows "ide f" and "ide g" and "src f = trg g" and "src g = trg f"
proof -
obtain \<eta> \<epsilon> where A: "adjunction_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>"
using assms adjoint_pair_def by auto
interpret A: adjunction_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>
using A by auto
show "ide f" by simp
show "ide g" by simp
show "src f = trg g" using A.antipar by simp
show "src g = trg f" using A.antipar by simp
qed
lemma left_adjoint_is_ide:
assumes "is_left_adjoint f"
shows "ide f"
using assms adjoint_pair_antipar by auto
lemma right_adjoint_is_ide:
assumes "is_right_adjoint f"
shows "ide f"
using assms adjoint_pair_antipar by auto
lemma adjunction_preserved_by_iso_right:
assumes "adjunction_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>"
and "\<guillemotleft>\<phi> : g \<Rightarrow> g'\<guillemotright>" and "iso \<phi>"
shows "adjunction_in_bicategory V H \<a> \<i> src trg f g' ((\<phi> \<star> f) \<cdot> \<eta>) (\<epsilon> \<cdot> (f \<star> inv \<phi>))"
proof
interpret A: adjunction_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>
using assms by auto
show "ide f" by simp
show "ide g'"
using assms(2) isomorphic_def by auto
show "\<guillemotleft>(\<phi> \<star> f) \<cdot> \<eta> : src f \<Rightarrow> g' \<star> f\<guillemotright>"
using assms A.antipar by fastforce
show "\<guillemotleft>\<epsilon> \<cdot> (f \<star> inv \<phi>) : f \<star> g' \<Rightarrow> src g'\<guillemotright>"
proof
show "\<guillemotleft>f \<star> inv \<phi> : f \<star> g' \<Rightarrow> f \<star> g\<guillemotright>"
using assms A.antipar by (intro hcomp_in_vhom, auto)
show "\<guillemotleft>\<epsilon> : f \<star> g \<Rightarrow> src g'\<guillemotright>"
using assms A.counit_in_hom A.antipar by auto
qed
show "(\<epsilon> \<cdot> (f \<star> inv \<phi>) \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g', f] \<cdot> (f \<star> (\<phi> \<star> f) \<cdot> \<eta>) = \<l>\<^sup>-\<^sup>1[f] \<cdot> \<r>[f]"
proof -
have "(\<epsilon> \<cdot> (f \<star> inv \<phi>) \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g', f] \<cdot> (f \<star> (\<phi> \<star> f) \<cdot> \<eta>) =
(\<epsilon> \<star> f) \<cdot> (((f \<star> inv \<phi>) \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g', f]) \<cdot> (f \<star> \<phi> \<star> f) \<cdot> (f \<star> \<eta>)"
using assms A.antipar whisker_right whisker_left comp_assoc by auto
also have "... = (\<epsilon> \<star> f) \<cdot> (\<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> inv \<phi> \<star> f)) \<cdot> (f \<star> \<phi> \<star> f) \<cdot> (f \<star> \<eta>)"
using assms A.antipar assoc'_naturality [of f "inv \<phi>" f] by auto
also have "... = (\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> ((f \<star> inv \<phi> \<star> f) \<cdot> (f \<star> \<phi> \<star> f)) \<cdot> (f \<star> \<eta>)"
using comp_assoc by simp
also have "... = (\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> g \<star> f) \<cdot> (f \<star> \<eta>)"
using assms A.antipar comp_inv_arr inv_is_inverse whisker_left
whisker_right [of f "inv \<phi>" \<phi>]
by auto
also have "... = (\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>)"
using assms A.antipar comp_cod_arr by simp
also have "... = \<l>\<^sup>-\<^sup>1[f] \<cdot> \<r>[f]"
using A.triangle_left by simp
finally show ?thesis by simp
qed
show "(g' \<star> \<epsilon> \<cdot> (f \<star> inv \<phi>)) \<cdot> \<a>[g', f, g'] \<cdot> ((\<phi> \<star> f) \<cdot> \<eta> \<star> g') = \<r>\<^sup>-\<^sup>1[g'] \<cdot> \<l>[g']"
proof -
have "(g' \<star> \<epsilon> \<cdot> (f \<star> inv \<phi>)) \<cdot> \<a>[g', f, g'] \<cdot> ((\<phi> \<star> f) \<cdot> \<eta> \<star> g') =
(g' \<star> \<epsilon>) \<cdot> ((g' \<star> f \<star> inv \<phi>) \<cdot> \<a>[g', f, g']) \<cdot> ((\<phi> \<star> f) \<star> g') \<cdot> (\<eta> \<star> g')"
using assms A.antipar whisker_left whisker_right comp_assoc by auto
also have "... = (g' \<star> \<epsilon>) \<cdot> (\<a>[g', f, g] \<cdot> ((g' \<star> f) \<star> inv \<phi>)) \<cdot> ((\<phi> \<star> f) \<star> g') \<cdot> (\<eta> \<star> g')"
using assms A.antipar assoc_naturality [of g' f "inv \<phi>"] by auto
also have "... = (g' \<star> \<epsilon>) \<cdot> \<a>[g', f, g] \<cdot> (((g' \<star> f) \<star> inv \<phi>) \<cdot> ((\<phi> \<star> f) \<star> g')) \<cdot> (\<eta> \<star> g')"
using comp_assoc by simp
also have "... = (g' \<star> \<epsilon>) \<cdot> (\<a>[g', f, g] \<cdot> ((\<phi> \<star> f) \<star> g)) \<cdot> ((g \<star> f) \<star> inv \<phi>) \<cdot> (\<eta> \<star> g')"
proof -
have "((g' \<star> f) \<star> inv \<phi>) \<cdot> ((\<phi> \<star> f) \<star> g') = (\<phi> \<star> f) \<star> inv \<phi>"
using assms A.antipar comp_arr_dom comp_cod_arr
interchange [of "g' \<star> f" "\<phi> \<star> f" "inv \<phi>" g']
by auto
also have "... = ((\<phi> \<star> f) \<star> g) \<cdot> ((g \<star> f) \<star> inv \<phi>)"
using assms A.antipar comp_arr_dom comp_cod_arr
interchange [of "\<phi> \<star> f" "g \<star> f" g "inv \<phi>"]
by auto
finally show ?thesis
using comp_assoc by simp
qed
also have "... = ((g' \<star> \<epsilon>) \<cdot> (\<phi> \<star> f \<star> g)) \<cdot> \<a>[g, f, g] \<cdot> (\<eta> \<star> g) \<cdot> (trg g \<star> inv \<phi>)"
proof -
have "\<a>[g', f, g] \<cdot> ((\<phi> \<star> f) \<star> g) = (\<phi> \<star> f \<star> g) \<cdot> \<a>[g, f, g]"
using assms A.antipar assoc_naturality [of \<phi> f g] by auto
moreover have "((g \<star> f) \<star> inv \<phi>) \<cdot> (\<eta> \<star> g') = (\<eta> \<star> g) \<cdot> (trg g \<star> inv \<phi>)"
using assms A.antipar comp_arr_dom comp_cod_arr
interchange [of "g \<star> f" \<eta> "inv \<phi>" g'] interchange [of \<eta> "trg g" g "inv \<phi>"]
by auto
ultimately show ?thesis
using comp_assoc by simp
qed
also have "... = ((\<phi> \<star> src g) \<cdot> (g \<star> \<epsilon>)) \<cdot> \<a>[g, f, g] \<cdot> (\<eta> \<star> g) \<cdot> (trg g \<star> inv \<phi>)"
using assms A.antipar comp_arr_dom comp_cod_arr
interchange [of g' \<phi> \<epsilon> "f \<star> g"] interchange [of \<phi> g "src g" \<epsilon>]
by auto
also have "... = (\<phi> \<star> src g) \<cdot> ((g \<star> \<epsilon>) \<cdot> \<a>[g, f, g] \<cdot> (\<eta> \<star> g)) \<cdot> (trg g \<star> inv \<phi>)"
using comp_assoc by simp
also have "... = ((\<phi> \<star> src g) \<cdot> \<r>\<^sup>-\<^sup>1[g]) \<cdot> \<l>[g] \<cdot> (trg g \<star> inv \<phi>)"
using assms A.antipar A.triangle_right comp_cod_arr comp_assoc
by simp
also have "... = (\<r>\<^sup>-\<^sup>1[g'] \<cdot> \<phi>) \<cdot> inv \<phi> \<cdot> \<l>[g']"
using assms A.antipar runit'_naturality [of \<phi>] lunit_naturality [of "inv \<phi>"]
by auto
also have "... = \<r>\<^sup>-\<^sup>1[g'] \<cdot> (\<phi> \<cdot> inv \<phi>) \<cdot> \<l>[g']"
using comp_assoc by simp
also have "... = \<r>\<^sup>-\<^sup>1[g'] \<cdot> \<l>[g']"
using assms comp_cod_arr comp_arr_inv' by auto
finally show ?thesis by simp
qed
qed
lemma adjunction_preserved_by_iso_left:
assumes "adjunction_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>"
and "\<guillemotleft>\<phi> : f \<Rightarrow> f'\<guillemotright>" and "iso \<phi>"
shows "adjunction_in_bicategory V H \<a> \<i> src trg f' g ((g \<star> \<phi>) \<cdot> \<eta>) (\<epsilon> \<cdot> (inv \<phi> \<star> g))"
proof
interpret A: adjunction_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>
using assms by auto
show "ide g" by simp
show "ide f'"
using assms(2) isomorphic_def by auto
show "\<guillemotleft>(g \<star> \<phi>) \<cdot> \<eta> : src f' \<Rightarrow> g \<star> f'\<guillemotright>"
proof
show "\<guillemotleft>\<eta> : src f' \<Rightarrow> g \<star> f\<guillemotright>"
using assms A.unit_in_hom by auto
show "\<guillemotleft>g \<star> \<phi> : g \<star> f \<Rightarrow> g \<star> f'\<guillemotright>"
using assms A.antipar by fastforce
qed
show "\<guillemotleft>\<epsilon> \<cdot> (inv \<phi> \<star> g) : f' \<star> g \<Rightarrow> src g\<guillemotright>"
proof
show "\<guillemotleft>inv \<phi> \<star> g : f' \<star> g \<Rightarrow> f \<star> g\<guillemotright>"
using assms A.antipar by (intro hcomp_in_vhom, auto)
show "\<guillemotleft>\<epsilon> : f \<star> g \<Rightarrow> src g\<guillemotright>"
using assms A.antipar by auto
qed
show "(g \<star> \<epsilon> \<cdot> (inv \<phi> \<star> g)) \<cdot> \<a>[g, f', g] \<cdot> ((g \<star> \<phi>) \<cdot> \<eta> \<star> g) = \<r>\<^sup>-\<^sup>1[g] \<cdot> \<l>[g]"
proof -
have "(g \<star> \<epsilon> \<cdot> (inv \<phi> \<star> g)) \<cdot> \<a>[g, f', g] \<cdot> ((g \<star> \<phi>) \<cdot> \<eta> \<star> g) =
(g \<star> \<epsilon>) \<cdot> ((g \<star> inv \<phi> \<star> g) \<cdot> \<a>[g, f', g]) \<cdot> ((g \<star> \<phi>) \<star> g) \<cdot> (\<eta> \<star> g)"
using assms A.antipar whisker_left whisker_right comp_assoc by auto
also have "... = (g \<star> \<epsilon>) \<cdot> (\<a>[g, f, g] \<cdot> ((g \<star> inv \<phi>) \<star> g)) \<cdot> ((g \<star> \<phi>) \<star> g) \<cdot> (\<eta> \<star> g)"
using assms A.antipar assoc_naturality [of g "inv \<phi>" g] by auto
also have "... = (g \<star> \<epsilon>) \<cdot> \<a>[g, f, g] \<cdot> (((g \<star> inv \<phi>) \<star> g) \<cdot> ((g \<star> \<phi>) \<star> g)) \<cdot> (\<eta> \<star> g)"
using comp_assoc by simp
also have "... = (g \<star> \<epsilon>) \<cdot> \<a>[g, f, g] \<cdot> ((g \<star> f) \<star> g) \<cdot> (\<eta> \<star> g)"
using assms A.antipar comp_inv_arr inv_is_inverse whisker_right
whisker_left [of g "inv \<phi>" \<phi>]
by auto
also have "... = (g \<star> \<epsilon>) \<cdot> \<a>[g, f, g] \<cdot> (\<eta> \<star> g)"
using assms A.antipar comp_cod_arr by simp
also have "... = \<r>\<^sup>-\<^sup>1[g] \<cdot> \<l>[g]"
using A.triangle_right by simp
finally show ?thesis by simp
qed
show "(\<epsilon> \<cdot> (inv \<phi> \<star> g) \<star> f') \<cdot> \<a>\<^sup>-\<^sup>1[f', g, f'] \<cdot> (f' \<star> (g \<star> \<phi>) \<cdot> \<eta>) = \<l>\<^sup>-\<^sup>1[f'] \<cdot> \<r>[f']"
proof -
have "(\<epsilon> \<cdot> (inv \<phi> \<star> g) \<star> f') \<cdot> \<a>\<^sup>-\<^sup>1[f', g, f'] \<cdot> (f' \<star> (g \<star> \<phi>) \<cdot> \<eta>) =
(\<epsilon> \<star> f') \<cdot> (((inv \<phi> \<star> g) \<star> f') \<cdot> \<a>\<^sup>-\<^sup>1[f', g, f']) \<cdot> (f' \<star> g \<star> \<phi>) \<cdot> (f' \<star> \<eta>)"
using assms A.antipar whisker_right whisker_left comp_assoc
by auto
also have "... = (\<epsilon> \<star> f') \<cdot> (\<a>\<^sup>-\<^sup>1[f, g, f'] \<cdot> (inv \<phi> \<star> g \<star> f')) \<cdot> (f' \<star> g \<star> \<phi>) \<cdot> (f' \<star> \<eta>)"
using assms A.antipar assoc'_naturality [of "inv \<phi>" g f'] by auto
also have "... = (\<epsilon> \<star> f') \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f'] \<cdot> ((inv \<phi> \<star> g \<star> f') \<cdot> (f' \<star> g \<star> \<phi>)) \<cdot> (f' \<star> \<eta>)"
using comp_assoc by simp
also have "... = (\<epsilon> \<star> f') \<cdot> (\<a>\<^sup>-\<^sup>1[f, g, f'] \<cdot> (f \<star> g \<star> \<phi>)) \<cdot> (inv \<phi> \<star> g \<star> f) \<cdot> (f' \<star> \<eta>)"
proof -
have "(inv \<phi> \<star> g \<star> f') \<cdot> (f' \<star> g \<star> \<phi>) = (f \<star> g \<star> \<phi>) \<cdot> (inv \<phi> \<star> g \<star> f)"
using assms(2-3) A.antipar comp_arr_dom comp_cod_arr
interchange [of "inv \<phi>" f' "g \<star> f'" "g \<star> \<phi>"]
interchange [of f "inv \<phi>" "g \<star> \<phi>" "g \<star> f"]
by auto
thus ?thesis
using comp_assoc by simp
qed
also have "... = ((\<epsilon> \<star> f') \<cdot> ((f \<star> g) \<star> \<phi>)) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>) \<cdot> (inv \<phi> \<star> src f)"
proof -
have "\<a>\<^sup>-\<^sup>1[f, g, f'] \<cdot> (f \<star> g \<star> \<phi>) = ((f \<star> g) \<star> \<phi>) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f]"
using assms A.antipar assoc'_naturality [of f g \<phi>] by auto
moreover have "(inv \<phi> \<star> g \<star> f) \<cdot> (f' \<star> \<eta>) = (f \<star> \<eta>) \<cdot> (inv \<phi> \<star> src f)"
using assms A.antipar comp_arr_dom comp_cod_arr
interchange [of "inv \<phi>" f' "g \<star> f" \<eta>] interchange [of f "inv \<phi>" \<eta> "src f"]
by auto
ultimately show ?thesis
using comp_assoc by simp
qed
also have "... = ((trg f \<star> \<phi>) \<cdot> (\<epsilon> \<star> f)) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>) \<cdot> (inv \<phi> \<star> src f)"
using assms A.antipar comp_arr_dom comp_cod_arr
interchange [of \<epsilon> "f \<star> g" f' \<phi>] interchange [of "trg f" \<epsilon> \<phi> f]
by (metis A.counit_simps(1) A.counit_simps(2) A.counit_simps(3) in_homE)
also have "... = (trg f \<star> \<phi>) \<cdot> ((\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>)) \<cdot> (inv \<phi> \<star> src f)"
using comp_assoc by simp
also have "... = ((trg f \<star> \<phi>) \<cdot> \<l>\<^sup>-\<^sup>1[f]) \<cdot> \<r>[f] \<cdot> (inv \<phi> \<star> src f)"
using assms A.antipar A.triangle_left comp_cod_arr comp_assoc
by simp
also have "... = (\<l>\<^sup>-\<^sup>1[f'] \<cdot> \<phi>) \<cdot> inv \<phi> \<cdot> \<r>[f']"
using assms A.antipar lunit'_naturality runit_naturality [of "inv \<phi>"] by auto
also have "... = \<l>\<^sup>-\<^sup>1[f'] \<cdot> (\<phi> \<cdot> inv \<phi>) \<cdot> \<r>[f']"
using comp_assoc by simp
also have "... = \<l>\<^sup>-\<^sup>1[f'] \<cdot> \<r>[f']"
using assms comp_cod_arr comp_arr_inv inv_is_inverse by auto
finally show ?thesis by simp
qed
qed
lemma adjoint_pair_preserved_by_iso:
assumes "adjoint_pair f g"
and "\<guillemotleft>\<phi> : f \<Rightarrow> f'\<guillemotright>" and "iso \<phi>"
and "\<guillemotleft>\<psi> : g \<Rightarrow> g'\<guillemotright>" and "iso \<psi>"
shows "adjoint_pair f' g'"
proof -
obtain \<eta> \<epsilon> where A: "adjunction_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>"
using assms adjoint_pair_def by auto
have "adjunction_in_bicategory V H \<a> \<i> src trg f g' ((\<psi> \<star> f) \<cdot> \<eta>) (\<epsilon> \<cdot> (f \<star> inv \<psi>))"
using assms A adjunction_preserved_by_iso_right by blast
hence "adjunction_in_bicategory V H \<a> \<i> src trg f' g'
((g' \<star> \<phi>) \<cdot> (\<psi> \<star> f) \<cdot> \<eta>) ((\<epsilon> \<cdot> (f \<star> inv \<psi>)) \<cdot> (inv \<phi> \<star> g'))"
using assms adjunction_preserved_by_iso_left by blast
thus ?thesis using adjoint_pair_def by auto
qed
lemma left_adjoint_preserved_by_iso:
assumes "is_left_adjoint f"
and "\<guillemotleft>\<phi> : f \<Rightarrow> f'\<guillemotright>" and "iso \<phi>"
shows "is_left_adjoint f'"
proof -
obtain g where g: "adjoint_pair f g"
using assms by auto
have "adjoint_pair f' g"
using assms g adjoint_pair_preserved_by_iso [of f g \<phi> f' g g]
adjoint_pair_antipar [of f g]
by auto
thus ?thesis by auto
qed
lemma right_adjoint_preserved_by_iso:
assumes "is_right_adjoint g"
and "\<guillemotleft>\<phi> : g \<Rightarrow> g'\<guillemotright>" and "iso \<phi>"
shows "is_right_adjoint g'"
proof -
obtain f where f: "adjoint_pair f g"
using assms by auto
have "adjoint_pair f g'"
using assms f adjoint_pair_preserved_by_iso [of f g f f \<phi> g']
adjoint_pair_antipar [of f g]
by auto
thus ?thesis by auto
qed
lemma left_adjoint_preserved_by_iso':
assumes "is_left_adjoint f" and "f \<cong> f'"
shows "is_left_adjoint f'"
using assms isomorphic_def left_adjoint_preserved_by_iso by blast
lemma right_adjoint_preserved_by_iso':
assumes "is_right_adjoint g" and "g \<cong> g'"
shows "is_right_adjoint g'"
using assms isomorphic_def right_adjoint_preserved_by_iso by blast
lemma obj_self_adjunction:
assumes "obj a"
shows "adjunction_in_bicategory V H \<a> \<i> src trg a a \<l>\<^sup>-\<^sup>1[a] \<r>[a]"
proof
show 1: "ide a"
using assms by auto
show "\<guillemotleft>\<l>\<^sup>-\<^sup>1[a] : src a \<Rightarrow> a \<star> a\<guillemotright>"
using assms 1 by auto
show "\<guillemotleft>\<r>[a] : a \<star> a \<Rightarrow> src a\<guillemotright>"
using assms 1 by fastforce
show "(\<r>[a] \<star> a) \<cdot> \<a>\<^sup>-\<^sup>1[a, a, a] \<cdot> (a \<star> \<l>\<^sup>-\<^sup>1[a]) = \<l>\<^sup>-\<^sup>1[a] \<cdot> \<r>[a]"
using assms 1 canI_unitor_1 canI_associator_1(2) canI_associator_3
whisker_can_right_1 whisker_can_left_1 can_Ide_self obj_simps
by simp
show "(a \<star> \<r>[a]) \<cdot> \<a>[a, a, a] \<cdot> (\<l>\<^sup>-\<^sup>1[a] \<star> a) = \<r>\<^sup>-\<^sup>1[a] \<cdot> \<l>[a]"
using assms 1 canI_unitor_1 canI_associator_1(2) canI_associator_3
whisker_can_right_1 whisker_can_left_1 can_Ide_self
by simp
qed
lemma obj_is_self_adjoint:
assumes "obj a"
shows "adjoint_pair a a" and "is_left_adjoint a" and "is_right_adjoint a"
using assms obj_self_adjunction adjoint_pair_def by auto
end
subsection "Pseudofunctors and Adjunctions"
context pseudofunctor
begin
lemma preserves_adjunction:
assumes "adjunction_in_bicategory V\<^sub>C H\<^sub>C \<a>\<^sub>C \<i>\<^sub>C src\<^sub>C trg\<^sub>C f g \<eta> \<epsilon>"
shows "adjunction_in_bicategory V\<^sub>D H\<^sub>D \<a>\<^sub>D \<i>\<^sub>D src\<^sub>D trg\<^sub>D (F f) (F g)
(D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f))
(D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<cdot>\<^sub>D \<Phi> (f, g))"
proof -
interpret adjunction_in_bicategory V\<^sub>C H\<^sub>C \<a>\<^sub>C \<i>\<^sub>C src\<^sub>C trg\<^sub>C f g \<eta> \<epsilon>
using assms by auto
interpret A: adjunction_data_in_bicategory V\<^sub>D H\<^sub>D \<a>\<^sub>D \<i>\<^sub>D src\<^sub>D trg\<^sub>D
\<open>F f\<close> \<open>F g\<close> \<open>D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f)\<close>
\<open>D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<cdot>\<^sub>D \<Phi> (f, g)\<close>
using adjunction_data_in_bicategory_axioms preserves_adjunction_data by auto
show "adjunction_in_bicategory V\<^sub>D H\<^sub>D \<a>\<^sub>D \<i>\<^sub>D src\<^sub>D trg\<^sub>D (F f) (F g)
(D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f))
(D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<cdot>\<^sub>D \<Phi> (f, g))"
proof
show "(D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<cdot>\<^sub>D \<Phi> (f, g) \<star>\<^sub>D F f) \<cdot>\<^sub>D \<a>\<^sub>D\<^sup>-\<^sup>1[F f, F g, F f] \<cdot>\<^sub>D
(F f \<star>\<^sub>D D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f)) =
D.lunit' (F f) \<cdot>\<^sub>D \<r>\<^sub>D[F f]"
proof -
have 1: "D.iso (\<Phi> (f, g \<star>\<^sub>C f) \<cdot>\<^sub>D (F f \<star>\<^sub>D \<Phi> (g, f)))"
using antipar C.VV.ide_char C.VV.arr_char D.iso_is_arr FF_def
by (intro D.isos_compose D.seqI, simp_all)
have "(D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<cdot>\<^sub>D \<Phi> (f, g) \<star>\<^sub>D F f) \<cdot>\<^sub>D \<a>\<^sub>D\<^sup>-\<^sup>1[F f, F g, F f] \<cdot>\<^sub>D
(F f \<star>\<^sub>D D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f)) =
(D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<cdot>\<^sub>D \<Phi> (f, g) \<star>\<^sub>D F f) \<cdot>\<^sub>D
(D.inv (\<Phi> (f, g)) \<star>\<^sub>D F f) \<cdot>\<^sub>D D.inv (\<Phi> (f \<star>\<^sub>C g, f)) \<cdot>\<^sub>D
F \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f] \<cdot>\<^sub>D
\<Phi> (f, g \<star>\<^sub>C f) \<cdot>\<^sub>D (F f \<star>\<^sub>D \<Phi> (g, f)) \<cdot>\<^sub>D
(F f \<star>\<^sub>D D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f))"
proof -
have "\<a>\<^sub>D\<^sup>-\<^sup>1[F f, F g, F f] =
(D.inv (\<Phi> (f, g)) \<star>\<^sub>D F f) \<cdot>\<^sub>D D.inv (\<Phi> (f \<star>\<^sub>C g, f)) \<cdot>\<^sub>D F \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f] \<cdot>\<^sub>D
\<Phi> (f, g \<star>\<^sub>C f) \<cdot>\<^sub>D (F f \<star>\<^sub>D \<Phi> (g, f))"
proof -
have "\<a>\<^sub>D\<^sup>-\<^sup>1[F f, F g, F f] \<cdot>\<^sub>D D.inv (\<Phi> (f, g \<star>\<^sub>C f) \<cdot>\<^sub>D (F f \<star>\<^sub>D \<Phi> (g, f))) =
D.inv (F \<a>\<^sub>C[f, g, f] \<cdot>\<^sub>D \<Phi> (f \<star>\<^sub>C g, f) \<cdot>\<^sub>D (\<Phi> (f, g) \<star>\<^sub>D F f))"
proof -
have "D.inv (\<Phi> (f, g \<star>\<^sub>C f) \<cdot>\<^sub>D (F f \<star>\<^sub>D \<Phi> (g, f)) \<cdot>\<^sub>D \<a>\<^sub>D[F f, F g, F f]) =
D.inv (F \<a>\<^sub>C[f, g, f] \<cdot>\<^sub>D \<Phi> (f \<star>\<^sub>C g, f) \<cdot>\<^sub>D (\<Phi> (f, g) \<star>\<^sub>D F f))"
using antipar assoc_coherence by simp
moreover
have "D.inv (\<Phi> (f, g \<star>\<^sub>C f) \<cdot>\<^sub>D (F f \<star>\<^sub>D \<Phi> (g, f)) \<cdot>\<^sub>D \<a>\<^sub>D[F f, F g, F f]) =
\<a>\<^sub>D\<^sup>-\<^sup>1[F f, F g, F f] \<cdot>\<^sub>D D.inv (\<Phi> (f, g \<star>\<^sub>C f) \<cdot>\<^sub>D (F f \<star>\<^sub>D \<Phi> (g, f)))"
proof -
have "D.seq (\<Phi> (f, g \<star>\<^sub>C f) \<cdot>\<^sub>D (F f \<star>\<^sub>D \<Phi> (g, f))) \<a>\<^sub>D[F f, F g, F f]"
using antipar by fastforce
thus ?thesis
using 1 antipar D.comp_assoc
D.inv_comp [of "\<a>\<^sub>D[F f, F g, F f]" "\<Phi> (f, g \<star>\<^sub>C f) \<cdot>\<^sub>D (F f \<star>\<^sub>D \<Phi> (g, f))"]
by auto
qed
ultimately show ?thesis by simp
qed
moreover have 2: "D.iso (F \<a>\<^sub>C[f, g, f] \<cdot>\<^sub>D \<Phi> (f \<star>\<^sub>C g, f) \<cdot>\<^sub>D (\<Phi> (f, g) \<star>\<^sub>D F f))"
using antipar D.isos_compose C.VV.ide_char C.VV.arr_char \<Phi>_simps(4)
by simp
ultimately have "\<a>\<^sub>D\<^sup>-\<^sup>1[F f, F g, F f] =
D.inv (F \<a>\<^sub>C[f, g, f] \<cdot>\<^sub>D \<Phi> (f \<star>\<^sub>C g, f) \<cdot>\<^sub>D (\<Phi> (f, g) \<star>\<^sub>D F f)) \<cdot>\<^sub>D
(\<Phi> (f, g \<star>\<^sub>C f) \<cdot>\<^sub>D (F f \<star>\<^sub>D \<Phi> (g, f)))"
using 1 2 antipar D.invert_side_of_triangle(2) D.inv_inv D.iso_inv_iso D.arr_inv
by metis
moreover have "D.inv (F \<a>\<^sub>C[f, g, f] \<cdot>\<^sub>D \<Phi> (f \<star>\<^sub>C g, f) \<cdot>\<^sub>D (\<Phi> (f, g) \<star>\<^sub>D F f)) =
(D.inv (\<Phi> (f, g)) \<star>\<^sub>D F f) \<cdot>\<^sub>D D.inv (\<Phi> (f \<star>\<^sub>C g, f)) \<cdot>\<^sub>D F \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f]"
proof -
have "D.inv (F \<a>\<^sub>C[f, g, f] \<cdot>\<^sub>D \<Phi> (f \<star>\<^sub>C g, f) \<cdot>\<^sub>D (\<Phi> (f, g) \<star>\<^sub>D F f)) =
D.inv (\<Phi> (f \<star>\<^sub>C g, f) \<cdot>\<^sub>D (\<Phi> (f, g) \<star>\<^sub>D F f)) \<cdot>\<^sub>D F \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f]"
using antipar D.isos_compose C.VV.arr_char \<Phi>_simps(4)
preserves_inv D.inv_comp
by simp
also have "... = (D.inv (\<Phi> (f, g) \<star>\<^sub>D F f) \<cdot>\<^sub>D D.inv (\<Phi> (f \<star>\<^sub>C g, f))) \<cdot>\<^sub>D
F \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f]"
using antipar D.inv_comp C.VV.ide_char C.VV.arr_char \<Phi>_simps(4)
by simp
also have "... = ((D.inv (\<Phi> (f, g)) \<star>\<^sub>D F f) \<cdot>\<^sub>D D.inv (\<Phi> (f \<star>\<^sub>C g, f))) \<cdot>\<^sub>D
F \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f]"
using antipar C.VV.ide_char C.VV.arr_char by simp
also have "... = (D.inv (\<Phi> (f, g)) \<star>\<^sub>D F f) \<cdot>\<^sub>D D.inv (\<Phi> (f \<star>\<^sub>C g, f)) \<cdot>\<^sub>D
F \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f]"
using D.comp_assoc by simp
finally show ?thesis by simp
qed
ultimately show ?thesis
using D.comp_assoc by simp
qed
thus ?thesis
using D.comp_assoc by simp
qed
also have "... = (D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<star>\<^sub>D F f) \<cdot>\<^sub>D
D.inv (\<Phi> (f \<star>\<^sub>C g, f)) \<cdot>\<^sub>D
F \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f] \<cdot>\<^sub>D
\<Phi> (f, g \<star>\<^sub>C f) \<cdot>\<^sub>D
(F f \<star>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f))"
proof -
have "... = ((D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<star>\<^sub>D F f) \<cdot>\<^sub>D (\<Phi> (f, g) \<star>\<^sub>D F f)) \<cdot>\<^sub>D
(D.inv (\<Phi> (f, g)) \<star>\<^sub>D F f) \<cdot>\<^sub>D D.inv (\<Phi> (f \<star>\<^sub>C g, f)) \<cdot>\<^sub>D
F \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f] \<cdot>\<^sub>D
\<Phi> (f, g \<star>\<^sub>C f) \<cdot>\<^sub>D (F f \<star>\<^sub>D \<Phi> (g, f)) \<cdot>\<^sub>D
((F f \<star>\<^sub>D D.inv (\<Phi> (g, f))) \<cdot>\<^sub>D (F f \<star>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f)))"
proof -
have "D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<cdot>\<^sub>D \<Phi> (f, g) \<star>\<^sub>D F f =
(D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<star>\<^sub>D F f) \<cdot>\<^sub>D (\<Phi> (f, g) \<star>\<^sub>D F f)"
using ide_left ide_right antipar D.whisker_right \<Psi>_char(2)
by (metis A.counit_simps(1) A.ide_left D.comp_assoc)
moreover have "F f \<star>\<^sub>D D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f) =
(F f \<star>\<^sub>D D.inv (\<Phi> (g, f))) \<cdot>\<^sub>D (F f \<star>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f))"
using antipar \<Psi>_char(2) D.whisker_left by simp
ultimately show ?thesis by simp
qed
also have "... = (D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<star>\<^sub>D F f) \<cdot>\<^sub>D
(((\<Phi> (f, g) \<star>\<^sub>D F f) \<cdot>\<^sub>D (D.inv (\<Phi> (f, g)) \<star>\<^sub>D F f)) \<cdot>\<^sub>D
D.inv (\<Phi> (f \<star>\<^sub>C g, f))) \<cdot>\<^sub>D F \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f] \<cdot>\<^sub>D \<Phi> (f, g \<star>\<^sub>C f) \<cdot>\<^sub>D
(((F f \<star>\<^sub>D \<Phi> (g, f)) \<cdot>\<^sub>D (F f \<star>\<^sub>D D.inv (\<Phi> (g, f)))) \<cdot>\<^sub>D
(F f \<star>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f)))"
using D.comp_assoc by simp
also have "... = (D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<star>\<^sub>D F f) \<cdot>\<^sub>D
D.inv (\<Phi> (f \<star>\<^sub>C g, f)) \<cdot>\<^sub>D
F \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f] \<cdot>\<^sub>D
\<Phi> (f, g \<star>\<^sub>C f) \<cdot>\<^sub>D
(F f \<star>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f))"
proof -
have "((F f \<star>\<^sub>D \<Phi> (g, f)) \<cdot>\<^sub>D (F f \<star>\<^sub>D D.inv (\<Phi> (g, f)))) \<cdot>\<^sub>D
(F f \<star>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f)) =
F f \<star>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f)"
proof -
have "(F f \<star>\<^sub>D \<Phi> (g, f)) \<cdot>\<^sub>D (F f \<star>\<^sub>D D.inv (\<Phi> (g, f))) = F f \<star>\<^sub>D F (g \<star>\<^sub>C f)"
using antipar \<Psi>_char(2) D.comp_arr_inv D.inv_is_inverse
D.whisker_left [of "F f" "\<Phi> (g, f)" "D.inv (\<Phi> (g, f))"]
by simp
moreover have "D.seq (F f \<star>\<^sub>D F (g \<star>\<^sub>C f)) (F f \<star>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f))"
using antipar by fastforce
ultimately show ?thesis
using D.comp_cod_arr by auto
qed
moreover have "((\<Phi> (f, g) \<star>\<^sub>D F f) \<cdot>\<^sub>D (D.inv (\<Phi> (f, g)) \<star>\<^sub>D F f)) \<cdot>\<^sub>D
D.inv (\<Phi> (f \<star>\<^sub>C g, f)) =
D.inv (\<Phi> (f \<star>\<^sub>C g, f))"
using antipar D.comp_arr_inv D.inv_is_inverse D.comp_cod_arr
D.whisker_right [of "F f" "\<Phi> (f, g)" "D.inv (\<Phi> (f, g))"]
by simp
ultimately show ?thesis by simp
qed
finally show ?thesis by simp
qed
also have "... = (D.inv (\<Psi> (trg\<^sub>C f)) \<star>\<^sub>D F f) \<cdot>\<^sub>D
D.inv (\<Phi> (trg\<^sub>C f, f)) \<cdot>\<^sub>D F (\<epsilon> \<star>\<^sub>C f) \<cdot>\<^sub>D
((\<Phi> (f \<star>\<^sub>C g, f) \<cdot>\<^sub>D D.inv (\<Phi> (f \<star>\<^sub>C g, f))) \<cdot>\<^sub>D
F \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f]) \<cdot>\<^sub>D
((\<Phi> (f, g \<star>\<^sub>C f) \<cdot>\<^sub>D D.inv (\<Phi> (f, g \<star>\<^sub>C f))) \<cdot>\<^sub>D F (f \<star>\<^sub>C \<eta>)) \<cdot>\<^sub>D
\<Phi> (f, src\<^sub>C f) \<cdot>\<^sub>D (F f \<star>\<^sub>D \<Psi> (src\<^sub>C f))"
proof -
have "(D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<star>\<^sub>D F f) \<cdot>\<^sub>D
D.inv (\<Phi> (f \<star>\<^sub>C g, f)) \<cdot>\<^sub>D
F \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f] \<cdot>\<^sub>D
\<Phi> (f, g \<star>\<^sub>C f) \<cdot>\<^sub>D
(F f \<star>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f)) =
((D.inv (\<Psi> (trg\<^sub>C f)) \<star>\<^sub>D F f) \<cdot>\<^sub>D (F \<epsilon> \<star>\<^sub>D F f)) \<cdot>\<^sub>D
D.inv (\<Phi> (f \<star>\<^sub>C g, f)) \<cdot>\<^sub>D
F \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f] \<cdot>\<^sub>D
\<Phi> (f, g \<star>\<^sub>C f) \<cdot>\<^sub>D
((F f \<star>\<^sub>D F \<eta>) \<cdot>\<^sub>D (F f \<star>\<^sub>D \<Psi> (src\<^sub>C f)))"
using antipar D.comp_assoc D.whisker_left D.whisker_right \<Psi>_char(2)
by simp
moreover have "F \<epsilon> \<star>\<^sub>D F f = D.inv (\<Phi> (trg\<^sub>C f, f)) \<cdot>\<^sub>D F (\<epsilon> \<star>\<^sub>C f) \<cdot>\<^sub>D \<Phi> (f \<star>\<^sub>C g, f)"
using antipar \<Phi>.naturality [of "(\<epsilon>, f)"] C.VV.arr_char FF_def
D.invert_side_of_triangle(1)
by simp
moreover have "F f \<star>\<^sub>D F \<eta> = D.inv (\<Phi> (f, g \<star>\<^sub>C f)) \<cdot>\<^sub>D F (f \<star>\<^sub>C \<eta>) \<cdot>\<^sub>D \<Phi> (f, src\<^sub>C f)"
using antipar \<Phi>.naturality [of "(f, \<eta>)"] C.VV.arr_char FF_def
D.invert_side_of_triangle(1)
by simp
ultimately show ?thesis
using D.comp_assoc by simp
qed
also have "... = ((D.inv (\<Psi> (trg\<^sub>C f)) \<star>\<^sub>D F f) \<cdot>\<^sub>D D.inv (\<Phi> (trg\<^sub>C f, f))) \<cdot>\<^sub>D
(F (\<epsilon> \<star>\<^sub>C f) \<cdot>\<^sub>D F \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f] \<cdot>\<^sub>D F (f \<star>\<^sub>C \<eta>)) \<cdot>\<^sub>D
\<Phi> (f, src\<^sub>C f) \<cdot>\<^sub>D (F f \<star>\<^sub>D \<Psi> (src\<^sub>C f))"
using antipar D.comp_arr_inv' D.comp_cod_arr D.comp_assoc by simp
also have "... = D.inv (\<Phi> (trg\<^sub>C f, f) \<cdot>\<^sub>D (\<Psi> (trg\<^sub>C f) \<star>\<^sub>D F f)) \<cdot>\<^sub>D
F ((\<epsilon> \<star>\<^sub>C f) \<cdot>\<^sub>C \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f] \<cdot>\<^sub>C (f \<star>\<^sub>C \<eta>)) \<cdot>\<^sub>D
\<Phi> (f, src\<^sub>C f) \<cdot>\<^sub>D (F f \<star>\<^sub>D \<Psi> (src\<^sub>C f))"
proof -
have "(D.inv (\<Psi> (trg\<^sub>C f)) \<star>\<^sub>D F f) \<cdot>\<^sub>D D.inv (\<Phi> (trg\<^sub>C f, f)) =
D.inv (\<Phi> (trg\<^sub>C f, f) \<cdot>\<^sub>D (\<Psi> (trg\<^sub>C f) \<star>\<^sub>D F f))"
proof -
have "D.iso (\<Phi> (trg\<^sub>C f, f))"
using antipar by simp
moreover have "D.iso (\<Psi> (trg\<^sub>C f) \<star>\<^sub>D F f)"
using antipar \<Psi>_char(2) by simp
moreover have "D.seq (\<Phi> (trg\<^sub>C f, f)) (\<Psi> (trg\<^sub>C f) \<star>\<^sub>D F f)"
using antipar D.iso_is_arr calculation(2)
apply (intro D.seqI D.hseqI) by auto
ultimately show ?thesis
using antipar D.inv_comp \<Psi>_char(2) by simp
qed
moreover have "F (\<epsilon> \<star>\<^sub>C f) \<cdot>\<^sub>D F \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f] \<cdot>\<^sub>D F (f \<star>\<^sub>C \<eta>) =
F ((\<epsilon> \<star>\<^sub>C f) \<cdot>\<^sub>C \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f] \<cdot>\<^sub>C (f \<star>\<^sub>C \<eta>))"
using antipar by simp
ultimately show ?thesis by simp
qed
also have "... = (D.lunit' (F f) \<cdot>\<^sub>D F \<l>\<^sub>C[f]) \<cdot>\<^sub>D
F (C.lunit' f \<cdot>\<^sub>C \<r>\<^sub>C[f]) \<cdot>\<^sub>D
(D.inv (F \<r>\<^sub>C[f]) \<cdot>\<^sub>D \<r>\<^sub>D[F f])"
proof -
have "F ((\<epsilon> \<star>\<^sub>C f) \<cdot>\<^sub>C \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f] \<cdot>\<^sub>C (f \<star>\<^sub>C \<eta>)) = F (C.lunit' f \<cdot>\<^sub>C \<r>\<^sub>C[f])"
using triangle_left by simp
moreover have "D.inv (\<Phi> (trg\<^sub>C f, f) \<cdot>\<^sub>D (\<Psi> (trg\<^sub>C f) \<star>\<^sub>D F f)) =
D.lunit' (F f) \<cdot>\<^sub>D F \<l>\<^sub>C[f]"
proof -
have 0: "D.iso (\<Phi> (trg\<^sub>C f, f) \<cdot>\<^sub>D (\<Psi> (trg\<^sub>C f) \<star>\<^sub>D F f))"
using \<Psi>_char(2)
apply (intro D.isos_compose D.seqI) by auto
show ?thesis
proof -
have 1: "D.iso (F \<l>\<^sub>C[f])"
using C.iso_lunit preserves_iso by auto
moreover have "D.iso (F \<l>\<^sub>C[f] \<cdot>\<^sub>D \<Phi> (trg\<^sub>C f, f) \<cdot>\<^sub>D (\<Psi> (trg\<^sub>C f) \<star>\<^sub>D F f))"
by (metis (no_types) A.ide_left D.iso_lunit ide_left lunit_coherence)
moreover have "D.inv (D.inv (F \<l>\<^sub>C[f])) = F \<l>\<^sub>C[f]"
using 1 D.inv_inv by blast
ultimately show ?thesis
by (metis 0 D.inv_comp D.invert_side_of_triangle(2) D.iso_inv_iso
D.iso_is_arr ide_left lunit_coherence)
qed
qed
moreover have "\<Phi> (f, src\<^sub>C f) \<cdot>\<^sub>D (F f \<star>\<^sub>D \<Psi> (src\<^sub>C f)) = D.inv (F \<r>\<^sub>C[f]) \<cdot>\<^sub>D \<r>\<^sub>D[F f]"
using ide_left runit_coherence preserves_iso C.iso_runit D.invert_side_of_triangle(1)
by (metis A.ide_left D.runit_simps(1))
ultimately show ?thesis by simp
qed
also have "... = D.lunit' (F f) \<cdot>\<^sub>D
((F \<l>\<^sub>C[f] \<cdot>\<^sub>D F (C.lunit' f)) \<cdot>\<^sub>D (F \<r>\<^sub>C[f] \<cdot>\<^sub>D D.inv (F \<r>\<^sub>C[f]))) \<cdot>\<^sub>D
\<r>\<^sub>D[F f]"
using D.comp_assoc by simp
also have "... = D.lunit' (F f) \<cdot>\<^sub>D \<r>\<^sub>D[F f]"
using D.comp_cod_arr C.iso_runit C.iso_lunit preserves_iso D.comp_arr_inv'
preserves_inv
by force
finally show ?thesis by blast
qed
show "(F g \<star>\<^sub>D D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<cdot>\<^sub>D \<Phi> (f, g)) \<cdot>\<^sub>D
\<a>\<^sub>D[F g, F f, F g] \<cdot>\<^sub>D (D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f) \<star>\<^sub>D F g) =
D.runit' (F g) \<cdot>\<^sub>D \<l>\<^sub>D[F g]"
proof -
have "\<a>\<^sub>D[F g, F f, F g] =
D.inv (\<Phi> (g, f \<star>\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Phi> (f, g))) \<cdot>\<^sub>D
F \<a>\<^sub>C[g, f, g] \<cdot>\<^sub>D \<Phi> (g \<star>\<^sub>C f, g) \<cdot>\<^sub>D (\<Phi> (g, f) \<star>\<^sub>D F g)"
proof -
have "D.iso (\<Phi> (g, f \<star>\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Phi> (f, g)))"
using antipar D.iso_is_arr
apply (intro D.isos_compose, auto)
by (metis C.iso_assoc D.comp_assoc D.seqE ide_left ide_right
preserves_assoc(1) preserves_iso)
have "F \<a>\<^sub>C[g, f, g] \<cdot>\<^sub>D \<Phi> (g \<star>\<^sub>C f, g) \<cdot>\<^sub>D (\<Phi> (g, f) \<star>\<^sub>D F g) =
\<Phi> (g, f \<star>\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Phi> (f, g)) \<cdot>\<^sub>D \<a>\<^sub>D[F g, F f, F g]"
using antipar assoc_coherence by simp
moreover have "D.seq (F \<a>\<^sub>C[g, f, g]) (\<Phi> (g \<star>\<^sub>C f, g) \<cdot>\<^sub>D (\<Phi> (g, f) \<star>\<^sub>D F g))"
proof (intro D.seqI)
show 1: "D.hseq (\<Phi> (g, f)) (F g)"
using antipar C.VV.arr_char by simp
show "D.arr (\<Phi> (g \<star>\<^sub>C f, g))"
using antipar C.VV.arr_char by simp
show "D.dom (\<Phi> (g \<star>\<^sub>C f, g)) = D.cod (\<Phi> (g, f) \<star>\<^sub>D F g)"
proof -
have "D.iso (\<Phi> (g, f) \<star>\<^sub>D F g)"
using antipar by simp
moreover have "D.iso (\<Phi> (g \<star>\<^sub>C f, g))"
using antipar by simp
ultimately show ?thesis
by (metis C.iso_assoc D.comp_assoc D.iso_is_arr D.seqE
\<open>F \<a>\<^sub>C[g, f, g] \<cdot>\<^sub>D \<Phi> (g \<star>\<^sub>C f, g) \<cdot>\<^sub>D (\<Phi> (g, f) \<star>\<^sub>D F g) =
\<Phi> (g, f \<star>\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Phi> (f, g)) \<cdot>\<^sub>D \<a>\<^sub>D[F g, F f, F g]\<close>
antipar(1) antipar(2) ide_left ide_right preserves_assoc(1) preserves_iso)
qed
show "D.arr (F \<a>\<^sub>C[g, f, g])"
using antipar by simp
show "D.dom (F \<a>\<^sub>C[g, f, g]) = D.cod (\<Phi> (g \<star>\<^sub>C f, g) \<cdot>\<^sub>D (\<Phi> (g, f) \<star>\<^sub>D F g))"
proof -
have "D.iso (\<Phi> (g, f) \<star>\<^sub>D F g)"
using antipar by simp
moreover have "D.seq (\<Phi> (g \<star>\<^sub>C f, g)) (\<Phi> (g, f) \<star>\<^sub>D F g)"
using antipar D.iso_is_arr
apply (intro D.seqI) by auto
ultimately show ?thesis
using antipar by simp
qed
qed
ultimately show ?thesis
using \<open>D.iso (\<Phi> (g, f \<star>\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Phi> (f, g)))\<close> D.invert_side_of_triangle(1)
D.comp_assoc
by auto
qed
hence "(F g \<star>\<^sub>D D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<cdot>\<^sub>D \<Phi> (f, g)) \<cdot>\<^sub>D
\<a>\<^sub>D[F g, F f, F g] \<cdot>\<^sub>D
(D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f) \<star>\<^sub>D F g) =
(F g \<star>\<^sub>D (D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon>) \<cdot>\<^sub>D \<Phi> (f, g)) \<cdot>\<^sub>D
D.inv (\<Phi> (g, f \<star>\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Phi> (f, g))) \<cdot>\<^sub>D
F \<a>\<^sub>C[g, f, g] \<cdot>\<^sub>D
\<Phi> (g \<star>\<^sub>C f, g) \<cdot>\<^sub>D (\<Phi> (g, f) \<star>\<^sub>D F g) \<cdot>\<^sub>D
(D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f) \<star>\<^sub>D F g)"
using D.comp_assoc by simp
also have "... = ((F g \<star>\<^sub>D D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon>) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Phi> (f, g))) \<cdot>\<^sub>D
D.inv (\<Phi> (g, f \<star>\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Phi> (f, g))) \<cdot>\<^sub>D
F \<a>\<^sub>C[g, f, g] \<cdot>\<^sub>D \<Phi> (g \<star>\<^sub>C f, g) \<cdot>\<^sub>D
(\<Phi> (g, f) \<star>\<^sub>D F g) \<cdot>\<^sub>D ((D.inv (\<Phi> (g, f)) \<star>\<^sub>D F g) \<cdot>\<^sub>D
(F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f) \<star>\<^sub>D F g))"
proof -
have "F g \<star>\<^sub>D (D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon>) \<cdot>\<^sub>D \<Phi> (f, g) =
(F g \<star>\<^sub>D D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon>) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Phi> (f, g))"
proof -
have "D.seq (D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon>) (\<Phi> (f, g))"
using antipar D.comp_assoc by simp
thus ?thesis
using antipar D.whisker_left by simp
qed
moreover have "D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f) \<star>\<^sub>D F g =
(D.inv (\<Phi> (g, f)) \<star>\<^sub>D F g) \<cdot>\<^sub>D (F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f) \<star>\<^sub>D F g)"
using antipar D.whisker_right by simp
ultimately show ?thesis
using D.comp_assoc by simp
qed
also have "... = (F g \<star>\<^sub>D D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon>) \<cdot>\<^sub>D
(((F g \<star>\<^sub>D \<Phi> (f, g)) \<cdot>\<^sub>D D.inv (F g \<star>\<^sub>D \<Phi> (f, g))) \<cdot>\<^sub>D
D.inv (\<Phi> (g, f \<star>\<^sub>C g))) \<cdot>\<^sub>D F \<a>\<^sub>C[g, f, g] \<cdot>\<^sub>D \<Phi> (g \<star>\<^sub>C f, g) \<cdot>\<^sub>D
((\<Phi> (g, f) \<star>\<^sub>D F g) \<cdot>\<^sub>D (D.inv (\<Phi> (g, f)) \<star>\<^sub>D F g)) \<cdot>\<^sub>D
(F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f) \<star>\<^sub>D F g)"
proof -
have "D.inv (\<Phi> (g, f \<star>\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Phi> (f, g))) =
D.inv (F g \<star>\<^sub>D \<Phi> (f, g)) \<cdot>\<^sub>D D.inv (\<Phi> (g, f \<star>\<^sub>C g))"
proof -
have "D.iso (\<Phi> (g, f \<star>\<^sub>C g))"
using antipar by simp
moreover have "D.iso (F g \<star>\<^sub>D \<Phi> (f, g))"
using antipar by simp
moreover have "D.seq (\<Phi> (g, f \<star>\<^sub>C g)) (F g \<star>\<^sub>D \<Phi> (f, g))"
using antipar \<Phi>_in_hom A.ide_right D.iso_is_arr
apply (intro D.seqI D.hseqI) by auto
ultimately show ?thesis
using antipar D.inv_comp by simp
qed
thus ?thesis
using D.comp_assoc by simp
qed
also have "... = (F g \<star>\<^sub>D D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon>) \<cdot>\<^sub>D
D.inv (\<Phi> (g, f \<star>\<^sub>C g)) \<cdot>\<^sub>D F \<a>\<^sub>C[g, f, g] \<cdot>\<^sub>D \<Phi> (g \<star>\<^sub>C f, g) \<cdot>\<^sub>D
(F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f) \<star>\<^sub>D F g)"
proof -
have "((\<Phi> (g, f) \<star>\<^sub>D F g) \<cdot>\<^sub>D (D.inv (\<Phi> (g, f)) \<star>\<^sub>D F g)) \<cdot>\<^sub>D
(F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f) \<star>\<^sub>D F g) =
(F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f) \<star>\<^sub>D F g)"
proof -
have "(\<Phi> (g, f) \<star>\<^sub>D F g) \<cdot>\<^sub>D (D.inv (\<Phi> (g, f)) \<star>\<^sub>D F g) = F (g \<star>\<^sub>C f) \<star>\<^sub>D F g"
using antipar D.comp_arr_inv'
D.whisker_right [of "F g" "\<Phi> (g, f)" "D.inv (\<Phi> (g, f))"]
by simp
thus ?thesis
using antipar D.comp_cod_arr D.whisker_right by simp
qed
moreover have "((F g \<star>\<^sub>D \<Phi> (f, g)) \<cdot>\<^sub>D D.inv (F g \<star>\<^sub>D \<Phi> (f, g))) \<cdot>\<^sub>D
D.inv (\<Phi> (g, f \<star>\<^sub>C g)) =
D.inv (\<Phi> (g, f \<star>\<^sub>C g))"
using antipar D.comp_arr_inv' D.comp_cod_arr
D.whisker_left [of "F g" "\<Phi> (f, g)" "D.inv (\<Phi> (f, g))"]
by simp
ultimately show ?thesis by simp
qed
also have "... = (F g \<star>\<^sub>D D.inv (\<Psi> (trg\<^sub>C f))) \<cdot>\<^sub>D
((F g \<star>\<^sub>D F \<epsilon>) \<cdot>\<^sub>D D.inv (\<Phi> (g, f \<star>\<^sub>C g))) \<cdot>\<^sub>D
F \<a>\<^sub>C[g, f, g] \<cdot>\<^sub>D
(\<Phi> (g \<star>\<^sub>C f, g) \<cdot>\<^sub>D (F \<eta> \<star>\<^sub>D F g)) \<cdot>\<^sub>D
(\<Psi> (src\<^sub>C f) \<star>\<^sub>D F g)"
using antipar D.whisker_left D.whisker_right \<Psi>_char(2) D.comp_assoc by simp
also have "... = (F g \<star>\<^sub>D D.inv (\<Psi> (trg\<^sub>C f))) \<cdot>\<^sub>D D.inv (\<Phi> (g, src\<^sub>C g)) \<cdot>\<^sub>D
(F (g \<star>\<^sub>C \<epsilon>) \<cdot>\<^sub>D F \<a>\<^sub>C[g, f, g] \<cdot>\<^sub>D F (\<eta> \<star>\<^sub>C g)) \<cdot>\<^sub>D
\<Phi> (trg\<^sub>C g, g) \<cdot>\<^sub>D (\<Psi> (src\<^sub>C f) \<star>\<^sub>D F g)"
proof -
have "(F g \<star>\<^sub>D F \<epsilon>) \<cdot>\<^sub>D D.inv (\<Phi> (g, f \<star>\<^sub>C g)) = D.inv (\<Phi> (g, src\<^sub>C g)) \<cdot>\<^sub>D F (g \<star>\<^sub>C \<epsilon>)"
using antipar C.VV.arr_char \<Phi>.naturality [of "(g, \<epsilon>)"] FF_def
D.invert_opposite_sides_of_square
by simp
moreover have "\<Phi> (g \<star>\<^sub>C f, g) \<cdot>\<^sub>D (F \<eta> \<star>\<^sub>D F g) = F (\<eta> \<star>\<^sub>C g) \<cdot>\<^sub>D \<Phi> (trg\<^sub>C g, g)"
using antipar C.VV.arr_char \<Phi>.naturality [of "(\<eta>, g)"] FF_def by simp
ultimately show ?thesis
using D.comp_assoc by simp
qed
also have "... = ((F g \<star>\<^sub>D D.inv (\<Psi> (trg\<^sub>C f))) \<cdot>\<^sub>D D.inv (\<Phi> (g, src\<^sub>C g)) \<cdot>\<^sub>D
F (C.runit' g)) \<cdot>\<^sub>D (F \<l>\<^sub>C[g] \<cdot>\<^sub>D \<Phi> (trg\<^sub>C g, g) \<cdot>\<^sub>D (\<Psi> (src\<^sub>C f) \<star>\<^sub>D F g))"
proof -
have "F (g \<star>\<^sub>C \<epsilon>) \<cdot>\<^sub>D F \<a>\<^sub>C[g, f, g] \<cdot>\<^sub>D F (\<eta> \<star>\<^sub>C g) = F (C.runit' g) \<cdot>\<^sub>D F \<l>\<^sub>C[g]"
using ide_left ide_right antipar triangle_right
by (metis C.comp_in_homE C.seqI' preserves_comp triangle_in_hom(2))
thus ?thesis
using D.comp_assoc by simp
qed
also have "... = D.runit' (F g) \<cdot>\<^sub>D \<l>\<^sub>D[F g]"
proof -
have "D.inv \<r>\<^sub>D[F g] =
(F g \<star>\<^sub>D D.inv (\<Psi> (trg\<^sub>C f))) \<cdot>\<^sub>D D.inv (\<Phi> (g, src\<^sub>C g)) \<cdot>\<^sub>D F (C.runit' g)"
proof -
have "D.runit' (F g) = D.inv (F \<r>\<^sub>C[g] \<cdot>\<^sub>D \<Phi> (g, src\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Psi> (src\<^sub>C g)))"
using runit_coherence by simp
also have
"... = (F g \<star>\<^sub>D D.inv (\<Psi> (trg\<^sub>C f))) \<cdot>\<^sub>D D.inv (\<Phi> (g, src\<^sub>C g)) \<cdot>\<^sub>D F (C.runit' g)"
proof -
have "D.inv (F \<r>\<^sub>C[g] \<cdot>\<^sub>D \<Phi> (g, src\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Psi> (src\<^sub>C g))) =
D.inv (F g \<star>\<^sub>D \<Psi> (src\<^sub>C g)) \<cdot>\<^sub>D D.inv (\<Phi> (g, src\<^sub>C g)) \<cdot>\<^sub>D F (C.runit' g)"
proof -
have "D.iso (F \<r>\<^sub>C[g])"
using preserves_iso by simp
moreover have 1: "D.iso (\<Phi> (g, src\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Psi> (src\<^sub>C g)))"
using preserves_iso \<Psi>_char(2) D.arrI D.seqE ide_right runit_coherence
by (intro D.isos_compose D.seqI, auto)
moreover have "D.seq (F \<r>\<^sub>C[g]) (\<Phi> (g, src\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Psi> (src\<^sub>C g)))"
using ide_right A.ide_right D.runit_simps(1) runit_coherence by metis
ultimately have "D.inv (F \<r>\<^sub>C[g] \<cdot>\<^sub>D \<Phi> (g, src\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Psi> (src\<^sub>C g))) =
D.inv (\<Phi> (g, src\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Psi> (src\<^sub>C g))) \<cdot>\<^sub>D F (C.runit' g)"
using C.iso_runit preserves_inv D.inv_comp by simp
moreover have "D.inv (\<Phi> (g, src\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Psi> (src\<^sub>C g))) =
D.inv (F g \<star>\<^sub>D \<Psi> (src\<^sub>C g)) \<cdot>\<^sub>D D.inv (\<Phi> (g, src\<^sub>C g))"
proof -
have "D.seq (\<Phi> (g, src\<^sub>C g)) (F g \<star>\<^sub>D \<Psi> (src\<^sub>C g))"
using 1 antipar preserves_iso \<Psi>_char(2) by fast
(*
* TODO: The fact that auto cannot do this step is probably what is blocking
* the whole thing from being done by auto.
*)
thus ?thesis
using 1 antipar preserves_iso \<Psi>_char(2) D.inv_comp by auto
qed
ultimately show ?thesis
using D.comp_assoc by simp
qed
thus ?thesis
using antipar \<Psi>_char(2) preserves_iso by simp
qed
finally show ?thesis by simp
qed
thus ?thesis
using antipar lunit_coherence by simp
qed
finally show ?thesis by simp
qed
qed
qed
lemma preserves_adjoint_pair:
assumes "C.adjoint_pair f g"
shows "D.adjoint_pair (F f) (F g)"
using assms C.adjoint_pair_def D.adjoint_pair_def preserves_adjunction by blast
lemma preserves_left_adjoint:
assumes "C.is_left_adjoint f"
shows "D.is_left_adjoint (F f)"
using assms preserves_adjoint_pair by auto
lemma preserves_right_adjoint:
assumes "C.is_right_adjoint g"
shows "D.is_right_adjoint (F g)"
using assms preserves_adjoint_pair by auto
end
context equivalence_pseudofunctor
begin
lemma reflects_adjunction:
assumes "C.ide f" and "C.ide g"
and "\<guillemotleft>\<eta> : src\<^sub>C f \<Rightarrow>\<^sub>C g \<star>\<^sub>C f\<guillemotright>" and "\<guillemotleft>\<epsilon> : f \<star>\<^sub>C g \<Rightarrow>\<^sub>C src\<^sub>C g\<guillemotright>"
and "adjunction_in_bicategory V\<^sub>D H\<^sub>D \<a>\<^sub>D \<i>\<^sub>D src\<^sub>D trg\<^sub>D (F f) (F g)
(D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f))
(D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<cdot>\<^sub>D \<Phi> (f, g))"
shows "adjunction_in_bicategory V\<^sub>C H\<^sub>C \<a>\<^sub>C \<i>\<^sub>C src\<^sub>C trg\<^sub>C f g \<eta> \<epsilon>"
proof -
let ?\<eta>' = "D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f)"
let ?\<epsilon>' = "D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<cdot>\<^sub>D \<Phi> (f, g)"
interpret A': adjunction_in_bicategory V\<^sub>D H\<^sub>D \<a>\<^sub>D \<i>\<^sub>D src\<^sub>D trg\<^sub>D \<open>F f\<close> \<open>F g\<close> ?\<eta>' ?\<epsilon>'
using assms(5) by auto
interpret A: adjunction_data_in_bicategory V\<^sub>C H\<^sub>C \<a>\<^sub>C \<i>\<^sub>C src\<^sub>C trg\<^sub>C f g \<eta> \<epsilon>
using assms(1-4) by (unfold_locales, auto)
show ?thesis
proof
show "(\<epsilon> \<star>\<^sub>C f) \<cdot>\<^sub>C \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f] \<cdot>\<^sub>C (f \<star>\<^sub>C \<eta>) = \<l>\<^sub>C\<^sup>-\<^sup>1[f] \<cdot>\<^sub>C \<r>\<^sub>C[f]"
proof -
have 1: "C.par ((\<epsilon> \<star>\<^sub>C f) \<cdot>\<^sub>C \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f] \<cdot>\<^sub>C (f \<star>\<^sub>C \<eta>)) (\<l>\<^sub>C\<^sup>-\<^sup>1[f] \<cdot>\<^sub>C \<r>\<^sub>C[f])"
using assms A.antipar by simp
moreover have "F ((\<epsilon> \<star>\<^sub>C f) \<cdot>\<^sub>C \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f] \<cdot>\<^sub>C (f \<star>\<^sub>C \<eta>)) = F (\<l>\<^sub>C\<^sup>-\<^sup>1[f] \<cdot>\<^sub>C \<r>\<^sub>C[f])"
proof -
have "F ((\<epsilon> \<star>\<^sub>C f) \<cdot>\<^sub>C \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f] \<cdot>\<^sub>C (f \<star>\<^sub>C \<eta>)) =
F (\<epsilon> \<star>\<^sub>C f) \<cdot>\<^sub>D F \<a>\<^sub>C\<^sup>-\<^sup>1[f, g, f] \<cdot>\<^sub>D F (f \<star>\<^sub>C \<eta>)"
using 1 by auto
also have "... =
(F (\<epsilon> \<star>\<^sub>C f) \<cdot>\<^sub>D \<Phi> (f \<star>\<^sub>C g, f)) \<cdot>\<^sub>D
(\<Phi> (f, g) \<star>\<^sub>D F f) \<cdot>\<^sub>D \<a>\<^sub>D\<^sup>-\<^sup>1[F f, F g, F f] \<cdot>\<^sub>D (F f \<star>\<^sub>D D.inv (\<Phi> (g, f))) \<cdot>\<^sub>D
(D.inv (\<Phi> (f, g \<star>\<^sub>C f)) \<cdot>\<^sub>D F (f \<star>\<^sub>C \<eta>))"
using assms A.antipar preserves_assoc(2) D.comp_assoc by auto
also have "... = \<Phi> (trg\<^sub>C f, f) \<cdot>\<^sub>D ((F \<epsilon> \<star>\<^sub>D F f) \<cdot>\<^sub>D (\<Phi> (f, g) \<star>\<^sub>D F f)) \<cdot>\<^sub>D
\<a>\<^sub>D\<^sup>-\<^sup>1[F f, F g, F f] \<cdot>\<^sub>D
((F f \<star>\<^sub>D D.inv (\<Phi> (g, f))) \<cdot>\<^sub>D (F f \<star>\<^sub>D F \<eta>)) \<cdot>\<^sub>D
D.inv (\<Phi> (f, src\<^sub>C f))"
proof -
have "F (\<epsilon> \<star>\<^sub>C f) \<cdot>\<^sub>D \<Phi> (f \<star>\<^sub>C g, f) = \<Phi> (trg\<^sub>C f, f) \<cdot>\<^sub>D (F \<epsilon> \<star>\<^sub>D F f)"
using assms \<Phi>.naturality [of "(\<epsilon>, f)"] FF_def C.VV.arr_char by simp
moreover have "D.inv (\<Phi> (f, g \<star>\<^sub>C f)) \<cdot>\<^sub>D F (f \<star>\<^sub>C \<eta>) =
(F f \<star>\<^sub>D F \<eta>) \<cdot>\<^sub>D D.inv (\<Phi> (f, src\<^sub>C f))"
proof -
have "F (f \<star>\<^sub>C \<eta>) \<cdot>\<^sub>D \<Phi> (f, src\<^sub>C f) = \<Phi> (f, g \<star>\<^sub>C f) \<cdot>\<^sub>D (F f \<star>\<^sub>D F \<eta>)"
using assms \<Phi>.naturality [of "(f, \<eta>)"] FF_def C.VV.arr_char A.antipar
by simp
thus ?thesis
using assms A.antipar \<Phi>_components_are_iso C.VV.arr_char \<Phi>_in_hom
FF_def
D.invert_opposite_sides_of_square
[of "\<Phi> (f, g \<star>\<^sub>C f)" "F f \<star>\<^sub>D F \<eta>" "F (f \<star>\<^sub>C \<eta>)" "\<Phi> (f, src\<^sub>C f)"]
by fastforce
qed
ultimately show ?thesis
using D.comp_assoc by simp
qed
also have "... = \<Phi> (trg\<^sub>C f, f) \<cdot>\<^sub>D (F \<epsilon> \<cdot>\<^sub>D \<Phi> (f, g) \<star>\<^sub>D F f) \<cdot>\<^sub>D
\<a>\<^sub>D\<^sup>-\<^sup>1[F f, F g, F f] \<cdot>\<^sub>D
(F f \<star>\<^sub>D D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta>) \<cdot>\<^sub>D D.inv (\<Phi> (f, src\<^sub>C f))"
using assms A.antipar \<Phi>_in_hom A.ide_left A.ide_right A'.ide_left A'.ide_right
D.whisker_left [of "F f" "D.inv (\<Phi> (g, f))" "F \<eta>"]
D.whisker_right [of "F f" "F \<epsilon>" "\<Phi> (f, g)"]
by (metis A'.counit_in_vhom A'.unit_simps(1)D.arrI D.comp_assoc
D.src.preserves_reflects_arr D.src_vcomp D.vseq_implies_hpar(1) \<Phi>_simps(2))
also have "... = \<Phi> (trg\<^sub>C f, f) \<cdot>\<^sub>D (\<Psi> (trg\<^sub>C f) \<cdot>\<^sub>D ?\<epsilon>' \<star>\<^sub>D F f) \<cdot>\<^sub>D
\<a>\<^sub>D\<^sup>-\<^sup>1[F f, F g, F f] \<cdot>\<^sub>D
(F f \<star>\<^sub>D ?\<eta>' \<cdot>\<^sub>D D.inv (\<Psi> (src\<^sub>C f))) \<cdot>\<^sub>D D.inv (\<Phi> (f, src\<^sub>C f))"
proof -
have "F \<epsilon> \<cdot>\<^sub>D \<Phi> (f, g) = \<Psi> (trg\<^sub>C f) \<cdot>\<^sub>D ?\<epsilon>'"
proof -
have "D.iso (\<Psi> (trg\<^sub>C f))"
using A.ide_left C.ideD(1) \<Psi>_char(2) by blast
thus ?thesis
by (metis A'.counit_simps(1) D.comp_assoc D.comp_cod_arr D.inv_is_inverse
D.seqE D.comp_arr_inv)
qed
moreover have "D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> = ?\<eta>' \<cdot>\<^sub>D D.inv (\<Psi> (src\<^sub>C f))"
using assms(2) \<Psi>_char D.comp_arr_inv D.inv_is_inverse D.comp_assoc D.comp_cod_arr
by (metis A'.unit_simps(1) A.antipar(1) C.ideD(1) C.obj_trg
D.invert_side_of_triangle(2))
ultimately show ?thesis by simp
qed
also have "... = \<Phi> (trg\<^sub>C f, f) \<cdot>\<^sub>D ((\<Psi> (trg\<^sub>C f) \<star>\<^sub>D F f) \<cdot>\<^sub>D
(?\<epsilon>' \<star>\<^sub>D F f)) \<cdot>\<^sub>D \<a>\<^sub>D\<^sup>-\<^sup>1[F f, F g, F f] \<cdot>\<^sub>D ((F f \<star>\<^sub>D ?\<eta>') \<cdot>\<^sub>D
(F f \<star>\<^sub>D D.inv (\<Psi> (src\<^sub>C f)))) \<cdot>\<^sub>D D.inv (\<Phi> (f, src\<^sub>C f))"
using assms A.antipar A'.antipar \<Psi>_char D.whisker_left D.whisker_right
by simp
also have "... = \<Phi> (trg\<^sub>C f, f) \<cdot>\<^sub>D (\<Psi> (trg\<^sub>C f) \<star>\<^sub>D F f) \<cdot>\<^sub>D
((?\<epsilon>' \<star>\<^sub>D F f) \<cdot>\<^sub>D \<a>\<^sub>D\<^sup>-\<^sup>1[F f, F g, F f] \<cdot>\<^sub>D (F f \<star>\<^sub>D ?\<eta>')) \<cdot>\<^sub>D
(F f \<star>\<^sub>D D.inv (\<Psi> (src\<^sub>C f))) \<cdot>\<^sub>D D.inv (\<Phi> (f, src\<^sub>C f))"
using D.comp_assoc by simp
also have "... = (\<Phi> (trg\<^sub>C f, f) \<cdot>\<^sub>D (\<Psi> (trg\<^sub>C f) \<star>\<^sub>D F f) \<cdot>\<^sub>D \<l>\<^sub>D\<^sup>-\<^sup>1[F f]) \<cdot>\<^sub>D
\<r>\<^sub>D[F f] \<cdot>\<^sub>D (F f \<star>\<^sub>D D.inv (\<Psi> (src\<^sub>C f))) \<cdot>\<^sub>D D.inv (\<Phi> (f, src\<^sub>C f))"
using A'.triangle_left D.comp_assoc by simp
also have "... = F \<l>\<^sub>C\<^sup>-\<^sup>1[f] \<cdot>\<^sub>D F \<r>\<^sub>C[f]"
using assms A.antipar preserves_lunit(2) preserves_runit(1) by simp
also have "... = F (\<l>\<^sub>C\<^sup>-\<^sup>1[f] \<cdot>\<^sub>C \<r>\<^sub>C[f])"
using assms by simp
finally show ?thesis by simp
qed
ultimately show ?thesis
using is_faithful by blast
qed
show "(g \<star>\<^sub>C \<epsilon>) \<cdot>\<^sub>C \<a>\<^sub>C[g, f, g] \<cdot>\<^sub>C (\<eta> \<star>\<^sub>C g) = \<r>\<^sub>C\<^sup>-\<^sup>1[g] \<cdot>\<^sub>C \<l>\<^sub>C[g]"
proof -
have 1: "C.par ((g \<star>\<^sub>C \<epsilon>) \<cdot>\<^sub>C \<a>\<^sub>C g f g \<cdot>\<^sub>C (\<eta> \<star>\<^sub>C g)) (\<r>\<^sub>C\<^sup>-\<^sup>1[g] \<cdot>\<^sub>C \<l>\<^sub>C[g])"
using assms A.antipar by auto
moreover have "F ((g \<star>\<^sub>C \<epsilon>) \<cdot>\<^sub>C \<a>\<^sub>C[g, f, g] \<cdot>\<^sub>C (\<eta> \<star>\<^sub>C g)) = F (\<r>\<^sub>C\<^sup>-\<^sup>1[g] \<cdot>\<^sub>C \<l>\<^sub>C[g])"
proof -
have "F ((g \<star>\<^sub>C \<epsilon>) \<cdot>\<^sub>C \<a>\<^sub>C g f g \<cdot>\<^sub>C (\<eta> \<star>\<^sub>C g)) =
F (g \<star>\<^sub>C \<epsilon>) \<cdot>\<^sub>D F \<a>\<^sub>C[g, f, g] \<cdot>\<^sub>D F (\<eta> \<star>\<^sub>C g)"
using 1 by auto
also have "... = (F (g \<star>\<^sub>C \<epsilon>) \<cdot>\<^sub>D \<Phi> (g, f \<star>\<^sub>C g)) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Phi> (f, g)) \<cdot>\<^sub>D
\<a>\<^sub>D[F g, F f, F g] \<cdot>\<^sub>D
(D.inv (\<Phi> (g, f)) \<star>\<^sub>D F g) \<cdot>\<^sub>D (D.inv (\<Phi> (g \<star>\<^sub>C f, g)) \<cdot>\<^sub>D F (\<eta> \<star>\<^sub>C g))"
using assms A.antipar preserves_assoc(1) [of g f g] D.comp_assoc by auto
also have "... = \<Phi> (g, src\<^sub>C g) \<cdot>\<^sub>D ((F g \<star>\<^sub>D F \<epsilon>) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Phi> (f, g))) \<cdot>\<^sub>D
\<a>\<^sub>D[F g, F f, F g] \<cdot>\<^sub>D
((D.inv (\<Phi> (g, f)) \<star>\<^sub>D F g) \<cdot>\<^sub>D (F \<eta> \<star>\<^sub>D F g)) \<cdot>\<^sub>D D.inv (\<Phi> (trg\<^sub>C g, g))"
proof -
have "F (g \<star>\<^sub>C \<epsilon>) \<cdot>\<^sub>D \<Phi> (g, f \<star>\<^sub>C g) = \<Phi> (g, src\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D F \<epsilon>)"
using assms \<Phi>.naturality [of "(g, \<epsilon>)"] FF_def C.VV.arr_char by auto
moreover have "D.inv (\<Phi> (g \<star>\<^sub>C f, g)) \<cdot>\<^sub>D F (\<eta> \<star>\<^sub>C g) =
(F \<eta> \<star>\<^sub>D F g) \<cdot>\<^sub>D D.inv (\<Phi> (trg\<^sub>C g, g))"
proof -
have "F (\<eta> \<star>\<^sub>C g) \<cdot>\<^sub>D \<Phi> (trg\<^sub>C g, g) = \<Phi> (g \<star>\<^sub>C f, g) \<cdot>\<^sub>D (F \<eta> \<star>\<^sub>D F g)"
using assms \<Phi>.naturality [of "(\<eta>, g)"] FF_def C.VV.arr_char A.antipar
by auto
thus ?thesis
using assms A.antipar \<Phi>_components_are_iso C.VV.arr_char FF_def
D.invert_opposite_sides_of_square
[of "\<Phi> (g \<star>\<^sub>C f, g)" "F \<eta> \<star>\<^sub>D F g" "F (\<eta> \<star>\<^sub>C g)" "\<Phi> (trg\<^sub>C g, g)"]
by fastforce
qed
ultimately show ?thesis
using D.comp_assoc by simp
qed
also have " ... = \<Phi> (g, src\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D F \<epsilon> \<cdot>\<^sub>D \<Phi> (f, g)) \<cdot>\<^sub>D
\<a>\<^sub>D[F g, F f, F g] \<cdot>\<^sub>D
(D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> \<star>\<^sub>D F g) \<cdot>\<^sub>D D.inv (\<Phi> (trg\<^sub>C g, g))"
proof -
have "(F g \<star>\<^sub>D F \<epsilon>) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Phi> (f, g)) = F g \<star>\<^sub>D F \<epsilon> \<cdot>\<^sub>D \<Phi> (f, g)"
using assms A.antipar D.whisker_left
by (metis A'.counit_simps(1) A'.ide_right D.seqE)
moreover have "(D.inv (\<Phi> (g, f)) \<star>\<^sub>D F g) \<cdot>\<^sub>D (F \<eta> \<star>\<^sub>D F g) =
D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> \<star>\<^sub>D F g"
using assms A.antipar D.whisker_right by simp
ultimately show ?thesis by simp
qed
also have "... = \<Phi> (g, src\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Psi> (trg\<^sub>C f) \<cdot>\<^sub>D ?\<epsilon>') \<cdot>\<^sub>D
\<a>\<^sub>D[F g, F f, F g] \<cdot>\<^sub>D
(?\<eta>' \<cdot>\<^sub>D D.inv (\<Psi> (src\<^sub>C f)) \<star>\<^sub>D F g) \<cdot>\<^sub>D D.inv (\<Phi> (trg\<^sub>C g, g))"
proof -
have "F \<epsilon> \<cdot>\<^sub>D \<Phi> (f, g) = \<Psi> (trg\<^sub>C f) \<cdot>\<^sub>D ?\<epsilon>'"
using \<Psi>_char D.comp_arr_inv D.inv_is_inverse D.comp_assoc D.comp_cod_arr
by (metis A'.counit_simps(1) C.ideD(1) C.obj_trg D.seqE assms(1))
moreover have "D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> = ?\<eta>' \<cdot>\<^sub>D D.inv (\<Psi> (src\<^sub>C f))"
using \<Psi>_char D.comp_arr_inv D.inv_is_inverse D.comp_assoc D.comp_cod_arr
by (metis A'.unit_simps(1) A.unit_simps(1) A.unit_simps(5)
C.obj_trg D.invert_side_of_triangle(2))
ultimately show ?thesis by simp
qed
also have "... = \<Phi> (g, src\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D
((F g \<star>\<^sub>D ?\<epsilon>') \<cdot>\<^sub>D \<a>\<^sub>D[F g, F f, F g] \<cdot>\<^sub>D (?\<eta>' \<star>\<^sub>D F g)) \<cdot>\<^sub>D
(D.inv (\<Psi> (src\<^sub>C f)) \<star>\<^sub>D F g) \<cdot>\<^sub>D D.inv (\<Phi> (trg\<^sub>C g, g))"
using assms A.antipar \<Psi>_char D.whisker_left D.whisker_right D.comp_assoc
by simp
also have "... = \<Phi> (g, src\<^sub>C g) \<cdot>\<^sub>D (F g \<star>\<^sub>D \<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D \<r>\<^sub>D\<^sup>-\<^sup>1[F g] \<cdot>\<^sub>D
\<l>\<^sub>D[F g] \<cdot>\<^sub>D (D.inv (\<Psi> (src\<^sub>C f)) \<star>\<^sub>D F g) \<cdot>\<^sub>D D.inv (\<Phi> (trg\<^sub>C g, g))"
using A'.triangle_right D.comp_assoc by simp
also have "... = F \<r>\<^sub>C\<^sup>-\<^sup>1[g] \<cdot>\<^sub>D F \<l>\<^sub>C[g]"
using assms A.antipar preserves_lunit(1) preserves_runit(2) D.comp_assoc
by simp
also have "... = F (\<r>\<^sub>C\<^sup>-\<^sup>1[g] \<cdot>\<^sub>C \<l>\<^sub>C[g])"
using assms by simp
finally show ?thesis by simp
qed
ultimately show ?thesis
using is_faithful by blast
qed
qed
qed
lemma reflects_adjoint_pair:
assumes "C.ide f" and "C.ide g"
and "src\<^sub>C f = trg\<^sub>C g" and "src\<^sub>C g = trg\<^sub>C f"
and "D.adjoint_pair (F f) (F g)"
shows "C.adjoint_pair f g"
proof -
obtain \<eta>' \<epsilon>' where A': "adjunction_in_bicategory V\<^sub>D H\<^sub>D \<a>\<^sub>D \<i>\<^sub>D src\<^sub>D trg\<^sub>D (F f) (F g) \<eta>' \<epsilon>'"
using assms D.adjoint_pair_def by auto
interpret A': adjunction_in_bicategory V\<^sub>D H\<^sub>D \<a>\<^sub>D \<i>\<^sub>D src\<^sub>D trg\<^sub>D \<open>F f\<close> \<open>F g\<close> \<eta>' \<epsilon>'
using A' by auto
have 1: "\<guillemotleft>\<Phi> (g, f) \<cdot>\<^sub>D \<eta>' \<cdot>\<^sub>D D.inv (\<Psi> (src\<^sub>C f)) : F (src\<^sub>C f) \<Rightarrow>\<^sub>D F (g \<star>\<^sub>C f)\<guillemotright>"
using assms \<Psi>_char [of "src\<^sub>C f"] A'.unit_in_hom
by (intro D.comp_in_homI, auto)
have 2: "\<guillemotleft>\<Psi> (trg\<^sub>C f) \<cdot>\<^sub>D \<epsilon>' \<cdot>\<^sub>D D.inv (\<Phi> (f, g)): F (f \<star>\<^sub>C g) \<Rightarrow>\<^sub>D F (trg\<^sub>C f)\<guillemotright>"
using assms \<Phi>_in_hom [of f g] \<Psi>_char [of "trg\<^sub>C f"] A'.counit_in_hom
by (intro D.comp_in_homI, auto)
obtain \<eta> where \<eta>: "\<guillemotleft>\<eta> : src\<^sub>C f \<Rightarrow>\<^sub>C g \<star>\<^sub>C f\<guillemotright> \<and>
F \<eta> = \<Phi> (g, f) \<cdot>\<^sub>D \<eta>' \<cdot>\<^sub>D D.inv (\<Psi> (src\<^sub>C f))"
using assms 1 A'.unit_in_hom \<Phi>_in_hom locally_full by fastforce
have \<eta>': "\<eta>' = D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f)"
using assms 1 \<eta> \<Phi>_in_hom \<Phi>.components_are_iso C.VV.ide_char C.VV.arr_char D.iso_inv_iso
\<Phi>_components_are_iso \<Psi>_char(2)
D.invert_side_of_triangle(1) [of "F \<eta>" "\<Phi> (g, f)" "\<eta>' \<cdot>\<^sub>D D.inv (\<Psi> (src\<^sub>C f))"]
D.invert_side_of_triangle(2) [of "D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta>" \<eta>' "D.inv (\<Psi> (src\<^sub>C f))"]
by (metis (no_types, lifting) C.ideD(1) C.obj_trg D.arrI D.comp_assoc D.inv_inv)
obtain \<epsilon> where \<epsilon>: "\<guillemotleft>\<epsilon> : f \<star>\<^sub>C g \<Rightarrow>\<^sub>C trg\<^sub>C f\<guillemotright> \<and>
F \<epsilon> = \<Psi> (trg\<^sub>C f) \<cdot>\<^sub>D \<epsilon>' \<cdot>\<^sub>D D.inv (\<Phi> (f, g))"
using assms 2 A'.counit_in_hom \<Phi>_in_hom locally_full by fastforce
have \<epsilon>': "\<epsilon>' = D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<cdot>\<^sub>D \<Phi> (f, g)"
using assms 2 \<epsilon> \<Phi>_in_hom \<Phi>.components_are_iso C.VV.ide_char C.VV.arr_char D.iso_inv_iso
\<Psi>_char(2) D.comp_assoc
D.invert_side_of_triangle(1) [of "F \<epsilon>" "\<Psi> (trg\<^sub>C f)" "\<epsilon>' \<cdot>\<^sub>D D.inv (\<Phi> (f, g))"]
D.invert_side_of_triangle(2) [of "D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon>" \<epsilon>' "D.inv (\<Phi> (f, g))"]
by (metis (no_types, lifting) C.arrI C.ideD(1) C.obj_trg D.inv_inv \<Phi>_components_are_iso
preserves_arr)
have "adjunction_in_bicategory V\<^sub>D H\<^sub>D \<a>\<^sub>D \<i>\<^sub>D src\<^sub>D trg\<^sub>D (F f) (F g)
(D.inv (\<Phi> (g, f)) \<cdot>\<^sub>D F \<eta> \<cdot>\<^sub>D \<Psi> (src\<^sub>C f))
(D.inv (\<Psi> (trg\<^sub>C f)) \<cdot>\<^sub>D F \<epsilon> \<cdot>\<^sub>D \<Phi> (f, g))"
using A'.adjunction_in_bicategory_axioms \<eta>' \<epsilon>' by simp
hence "adjunction_in_bicategory V\<^sub>C H\<^sub>C \<a>\<^sub>C \<i>\<^sub>C src\<^sub>C trg\<^sub>C f g \<eta> \<epsilon>"
using assms \<eta> \<epsilon> reflects_adjunction by simp
thus ?thesis
using C.adjoint_pair_def by auto
qed
lemma reflects_left_adjoint:
assumes "C.ide f" and "D.is_left_adjoint (F f)"
shows "C.is_left_adjoint f"
proof -
obtain g' where g': "D.adjoint_pair (F f) g'"
using assms D.adjoint_pair_def by auto
obtain g where g: "\<guillemotleft>g : trg\<^sub>C f \<rightarrow>\<^sub>C src\<^sub>C f\<guillemotright> \<and> C.ide g \<and> D.isomorphic (F g) g'"
using assms g' locally_essentially_surjective [of "trg\<^sub>C f" "src\<^sub>C f" g']
D.adjoint_pair_antipar [of "F f" g']
by auto
obtain \<phi> where \<phi>: "\<guillemotleft>\<phi> : g' \<Rightarrow>\<^sub>D F g\<guillemotright> \<and> D.iso \<phi>"
using g D.isomorphic_def D.isomorphic_symmetric by metis
have "D.adjoint_pair (F f) (F g)"
using assms g g' \<phi> D.adjoint_pair_preserved_by_iso [of "F f" g' "F f" "F f" \<phi> "F g"]
by auto
thus ?thesis
using assms g reflects_adjoint_pair [of f g] D.adjoint_pair_antipar C.in_hhom_def
by auto
qed
lemma reflects_right_adjoint:
assumes "C.ide g" and "D.is_right_adjoint (F g)"
shows "C.is_right_adjoint g"
proof -
obtain f' where f': "D.adjoint_pair f' (F g)"
using assms D.adjoint_pair_def by auto
obtain f where f: "\<guillemotleft>f : trg\<^sub>C g \<rightarrow>\<^sub>C src\<^sub>C g\<guillemotright> \<and> C.ide f \<and> D.isomorphic (F f) f'"
using assms f' locally_essentially_surjective [of "trg\<^sub>C g" "src\<^sub>C g" f']
D.adjoint_pair_antipar [of f' "F g"]
by auto
obtain \<phi> where \<phi>: "\<guillemotleft>\<phi> : f' \<Rightarrow>\<^sub>D F f\<guillemotright> \<and> D.iso \<phi>"
using f D.isomorphic_def D.isomorphic_symmetric by metis
have "D.adjoint_pair (F f) (F g)"
using assms f f' \<phi> D.adjoint_pair_preserved_by_iso [of f' "F g" \<phi> "F f" "F g" "F g"]
by auto
thus ?thesis
using assms f reflects_adjoint_pair [of f g] D.adjoint_pair_antipar C.in_hhom_def
by auto
qed
end
subsection "Composition of Adjunctions"
text \<open>
We first consider the strict case, then extend to all bicategories using strictification.
\<close>
locale composite_adjunction_in_strict_bicategory =
strict_bicategory V H \<a> \<i> src trg +
fg: adjunction_in_strict_bicategory V H \<a> \<i> src trg f g \<zeta> \<xi> +
hk: adjunction_in_strict_bicategory V H \<a> \<i> src trg h k \<sigma> \<tau>
for V :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "\<cdot>" 55)
and H :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "\<star>" 53)
and \<a> :: "'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a" ("\<a>[_, _, _]")
and \<i> :: "'a \<Rightarrow> 'a" ("\<i>[_]")
and src :: "'a \<Rightarrow> 'a"
and trg :: "'a \<Rightarrow> 'a"
and f :: "'a"
and g :: "'a"
and \<zeta> :: "'a"
and \<xi> :: "'a"
and h :: "'a"
and k :: "'a"
and \<sigma> :: "'a"
and \<tau> :: "'a" +
assumes composable: "src h = trg f"
begin
abbreviation \<eta>
where "\<eta> \<equiv> (g \<star> \<sigma> \<star> f) \<cdot> \<zeta>"
abbreviation \<epsilon>
where "\<epsilon> \<equiv> \<tau> \<cdot> (h \<star> \<xi> \<star> k)"
interpretation adjunction_data_in_bicategory V H \<a> \<i> src trg \<open>h \<star> f\<close> \<open>g \<star> k\<close> \<eta> \<epsilon>
proof
show "ide (h \<star> f)"
using composable by simp
show "ide (g \<star> k)"
using fg.antipar hk.antipar composable by simp
show "\<guillemotleft>\<eta> : src (h \<star> f) \<Rightarrow> (g \<star> k) \<star> h \<star> f\<guillemotright>"
proof
show "\<guillemotleft>\<zeta> : src (h \<star> f) \<Rightarrow> g \<star> f\<guillemotright>"
using fg.antipar hk.antipar composable \<open>ide (h \<star> f)\<close> by auto
show "\<guillemotleft>g \<star> \<sigma> \<star> f : g \<star> f \<Rightarrow> (g \<star> k) \<star> h \<star> f\<guillemotright>"
proof -
have "\<guillemotleft>g \<star> \<sigma> \<star> f : g \<star> trg f \<star> f \<Rightarrow> g \<star> (k \<star> h) \<star> f\<guillemotright>"
using fg.antipar hk.antipar composable hk.unit_in_hom
apply (intro hcomp_in_vhom) by auto
thus ?thesis
using hcomp_obj_arr hcomp_assoc by fastforce
qed
qed
show "\<guillemotleft>\<epsilon> : (h \<star> f) \<star> g \<star> k \<Rightarrow> src (g \<star> k)\<guillemotright>"
proof
show "\<guillemotleft>h \<star> \<xi> \<star> k : (h \<star> f) \<star> g \<star> k \<Rightarrow> h \<star> k\<guillemotright>"
proof -
have "\<guillemotleft>h \<star> \<xi> \<star> k : h \<star> (f \<star> g) \<star> k \<Rightarrow> h \<star> trg f \<star> k\<guillemotright>"
using composable fg.antipar(1-2) hk.antipar(1) by fastforce
thus ?thesis
using fg.antipar hk.antipar composable hk.unit_in_hom hcomp_obj_arr hcomp_assoc
by simp
qed
show "\<guillemotleft>\<tau> : h \<star> k \<Rightarrow> src (g \<star> k)\<guillemotright>"
using fg.antipar hk.antipar composable hk.unit_in_hom by auto
qed
qed
sublocale adjunction_in_strict_bicategory V H \<a> \<i> src trg \<open>h \<star> f\<close> \<open>g \<star> k\<close> \<eta> \<epsilon>
proof
show "(\<epsilon> \<star> h \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[h \<star> f, g \<star> k, h \<star> f] \<cdot> ((h \<star> f) \<star> \<eta>) = \<l>\<^sup>-\<^sup>1[h \<star> f] \<cdot> \<r>[h \<star> f]"
proof -
have "(\<epsilon> \<star> h \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[h \<star> f, g \<star> k, h \<star> f] \<cdot> ((h \<star> f) \<star> \<eta>) =
(\<tau> \<cdot> (h \<star> \<xi> \<star> k) \<star> h \<star> f) \<cdot> ((h \<star> f) \<star> (g \<star> \<sigma> \<star> f) \<cdot> \<zeta>)"
using fg.antipar hk.antipar composable strict_assoc comp_ide_arr
ide_left ide_right antipar(1) antipar(2)
by (metis arrI seqE strict_assoc' triangle_in_hom(1))
also have "... = (\<tau> \<star> h \<star> f) \<cdot> ((h \<star> \<xi> \<star> (k \<star> h) \<star> f) \<cdot> (h \<star> (f \<star> g) \<star> \<sigma> \<star> f)) \<cdot> (h \<star> f \<star> \<zeta>)"
using fg.antipar hk.antipar composable whisker_left [of "h \<star> f"] whisker_right
comp_assoc hcomp_assoc
by simp
also have "... = (\<tau> \<star> h \<star> f) \<cdot> (h \<star> (\<xi> \<star> (k \<star> h)) \<cdot> ((f \<star> g) \<star> \<sigma>) \<star> f) \<cdot> (h \<star> f \<star> \<zeta>)"
using fg.antipar hk.antipar composable whisker_left whisker_right hcomp_assoc
by simp
also have "... = (\<tau> \<star> h \<star> f) \<cdot> (h \<star> (trg f \<star> \<sigma>) \<cdot> (\<xi> \<star> trg f) \<star> f) \<cdot> (h \<star> f \<star> \<zeta>)"
using fg.antipar hk.antipar composable comp_arr_dom comp_cod_arr
interchange [of \<xi> "f \<star> g" "k \<star> h" \<sigma>] interchange [of "trg f" \<xi> \<sigma> "trg f"]
by (metis fg.counit_simps(1) fg.counit_simps(2) fg.counit_simps(3)
hk.unit_simps(1) hk.unit_simps(2) hk.unit_simps(3))
also have "... = (\<tau> \<star> h \<star> f) \<cdot> (h \<star> \<sigma> \<cdot> \<xi> \<star> f) \<cdot> (h \<star> f \<star> \<zeta>)"
using fg.antipar hk.antipar composable hcomp_obj_arr hcomp_arr_obj
by (metis fg.counit_simps(1) fg.counit_simps(4) hk.unit_simps(1) hk.unit_simps(5)
obj_src)
also have "... = ((\<tau> \<star> h \<star> f) \<cdot> (h \<star> \<sigma> \<star> f)) \<cdot> ((h \<star> \<xi> \<star> f) \<cdot> (h \<star> f \<star> \<zeta>))"
using fg.antipar hk.antipar composable whisker_left whisker_right comp_assoc
by simp
also have "... = ((\<tau> \<star> h) \<cdot> (h \<star> \<sigma>) \<star> f) \<cdot> (h \<star> (\<xi> \<star> f) \<cdot> (f \<star> \<zeta>))"
using fg.antipar hk.antipar composable whisker_left whisker_right hcomp_assoc
by simp
also have "... = h \<star> f"
using fg.antipar hk.antipar composable fg.triangle_left hk.triangle_left
by simp
also have "... = \<l>\<^sup>-\<^sup>1[h \<star> f] \<cdot> \<r>[h \<star> f]"
using fg.antipar hk.antipar composable strict_lunit' strict_runit by simp
finally show ?thesis by simp
qed
show "((g \<star> k) \<star> \<epsilon>) \<cdot> \<a>[g \<star> k, h \<star> f, g \<star> k] \<cdot> (\<eta> \<star> g \<star> k) = \<r>\<^sup>-\<^sup>1[g \<star> k] \<cdot> \<l>[g \<star> k]"
proof -
have "((g \<star> k) \<star> \<epsilon>) \<cdot> \<a>[g \<star> k, h \<star> f, g \<star> k] \<cdot> (\<eta> \<star> g \<star> k) =
((g \<star> k) \<star> \<tau> \<cdot> (h \<star> \<xi> \<star> k)) \<cdot> ((g \<star> \<sigma> \<star> f) \<cdot> \<zeta> \<star> g \<star> k)"
using fg.antipar hk.antipar composable strict_assoc comp_ide_arr
ide_left ide_right
by (metis antipar(1) antipar(2) arrI seqE triangle_in_hom(2))
also have "... = (g \<star> k \<star> \<tau>) \<cdot> ((g \<star> (k \<star> h) \<star> \<xi> \<star> k) \<cdot> (g \<star> \<sigma> \<star> (f \<star> g) \<star> k)) \<cdot> (\<zeta> \<star> g \<star> k)"
using fg.antipar hk.antipar composable whisker_left [of "g \<star> k"] whisker_right
comp_assoc hcomp_assoc
by simp
also have "... = (g \<star> k \<star> \<tau>) \<cdot> (g \<star> ((k \<star> h) \<star> \<xi>) \<cdot> (\<sigma> \<star> f \<star> g) \<star> k) \<cdot> (\<zeta> \<star> g \<star> k)"
using fg.antipar hk.antipar composable whisker_left whisker_right hcomp_assoc
by simp
also have "... = (g \<star> k \<star> \<tau>) \<cdot> (g \<star> (\<sigma> \<star> src g) \<cdot> (src g \<star> \<xi>) \<star> k) \<cdot> (\<zeta> \<star> g \<star> k)"
using fg.antipar hk.antipar composable interchange [of "k \<star> h" \<sigma> \<xi> "f \<star> g"]
interchange [of \<sigma> "src g" "src g" \<xi>] comp_arr_dom comp_cod_arr
by (metis fg.counit_simps(1) fg.counit_simps(2) fg.counit_simps(3)
hk.unit_simps(1) hk.unit_simps(2) hk.unit_simps(3))
also have "... = (g \<star> k \<star> \<tau>) \<cdot> (g \<star> \<sigma> \<cdot> \<xi> \<star> k) \<cdot> (\<zeta> \<star> g \<star> k)"
using fg.antipar hk.antipar composable hcomp_obj_arr [of "src g" \<xi>]
hcomp_arr_obj [of \<sigma> "src g"]
by simp
also have "... = ((g \<star> k \<star> \<tau>) \<cdot> (g \<star> \<sigma> \<star> k)) \<cdot> (g \<star> \<xi> \<star> k) \<cdot> (\<zeta> \<star> g \<star> k)"
using fg.antipar hk.antipar composable whisker_left whisker_right comp_assoc
by simp
also have "... = (g \<star> (k \<star> \<tau>) \<cdot> (\<sigma> \<star> k)) \<cdot> ((g \<star> \<xi>) \<cdot> (\<zeta> \<star> g) \<star> k)"
using fg.antipar hk.antipar composable whisker_left whisker_right hcomp_assoc
by simp
also have "... = g \<star> k"
using fg.antipar hk.antipar composable fg.triangle_right hk.triangle_right
by simp
also have "... = \<r>\<^sup>-\<^sup>1[g \<star> k] \<cdot> \<l>[g \<star> k]"
using fg.antipar hk.antipar composable strict_lunit strict_runit' by simp
finally show ?thesis by simp
qed
qed
lemma is_adjunction_in_strict_bicategory:
shows "adjunction_in_strict_bicategory V H \<a> \<i> src trg (h \<star> f) (g \<star> k) \<eta> \<epsilon>"
..
end
context strict_bicategory
begin
lemma left_adjoints_compose:
assumes "is_left_adjoint f" and "is_left_adjoint f'" and "src f' = trg f"
shows "is_left_adjoint (f' \<star> f)"
proof -
obtain g \<eta> \<epsilon> where fg: "adjunction_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>"
using assms adjoint_pair_def by auto
interpret fg: adjunction_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>
using fg by auto
obtain g' \<eta>' \<epsilon>' where f'g': "adjunction_in_bicategory V H \<a> \<i> src trg f' g' \<eta>' \<epsilon>'"
using assms adjoint_pair_def by auto
interpret f'g': adjunction_in_bicategory V H \<a> \<i> src trg f' g' \<eta>' \<epsilon>'
using f'g' by auto
interpret f'fgg': composite_adjunction_in_strict_bicategory V H \<a> \<i> src trg
f g \<eta> \<epsilon> f' g' \<eta>' \<epsilon>'
using assms apply unfold_locales by simp
have "adjoint_pair (f' \<star> f) (g \<star> g')"
using adjoint_pair_def f'fgg'.adjunction_in_bicategory_axioms by auto
thus ?thesis by auto
qed
lemma right_adjoints_compose:
assumes "is_right_adjoint g" and "is_right_adjoint g'" and "src g = trg g'"
shows "is_right_adjoint (g \<star> g')"
proof -
obtain f \<eta> \<epsilon> where fg: "adjunction_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>"
using assms adjoint_pair_def by auto
interpret fg: adjunction_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>
using fg by auto
obtain f' \<eta>' \<epsilon>' where f'g': "adjunction_in_bicategory V H \<a> \<i> src trg f' g' \<eta>' \<epsilon>'"
using assms adjoint_pair_def by auto
interpret f'g': adjunction_in_bicategory V H \<a> \<i> src trg f' g' \<eta>' \<epsilon>'
using f'g' by auto
interpret f'fgg': composite_adjunction_in_strict_bicategory V H \<a> \<i> src trg
f g \<eta> \<epsilon> f' g' \<eta>' \<epsilon>'
using assms fg.antipar f'g'.antipar apply unfold_locales by simp
have "adjoint_pair (f' \<star> f) (g \<star> g')"
using adjoint_pair_def f'fgg'.adjunction_in_bicategory_axioms by auto
thus ?thesis by auto
qed
end
text \<open>
We now use strictification to extend the preceding results to an arbitrary bicategory.
We only prove that ``left adjoints compose'' and ``right adjoints compose'';
I did not work out formulas for the unit and counit of the composite adjunction in the
non-strict case.
\<close>
context bicategory
begin
interpretation S: strictified_bicategory V H \<a> \<i> src trg ..
notation S.vcomp (infixr "\<cdot>\<^sub>S" 55)
notation S.hcomp (infixr "\<star>\<^sub>S" 53)
notation S.in_hom ("\<guillemotleft>_ : _ \<Rightarrow>\<^sub>S _\<guillemotright>")
notation S.in_hhom ("\<guillemotleft>_ : _ \<rightarrow>\<^sub>S _\<guillemotright>")
interpretation UP: fully_faithful_functor V S.vcomp S.UP
using S.UP_is_fully_faithful_functor by auto
interpretation UP: equivalence_pseudofunctor V H \<a> \<i> src trg
S.vcomp S.hcomp S.\<a> S.\<i> S.src S.trg S.UP S.\<Phi>
using S.UP_is_equivalence_pseudofunctor by auto
lemma left_adjoints_compose:
assumes "is_left_adjoint f" and "is_left_adjoint f'" and "src f = trg f'"
shows "is_left_adjoint (f \<star> f')"
proof -
have "S.is_left_adjoint (S.UP f) \<and> S.is_left_adjoint (S.UP f')"
using assms UP.preserves_left_adjoint by simp
moreover have "S.src (S.UP f) = S.trg (S.UP f')"
using assms left_adjoint_is_ide by simp
ultimately have "S.is_left_adjoint (S.hcomp (S.UP f) (S.UP f'))"
using S.left_adjoints_compose by simp
moreover have "S.isomorphic (S.hcomp (S.UP f) (S.UP f')) (S.UP (f \<star> f'))"
proof -
have "\<guillemotleft>S.\<Phi> (f, f') : S.hcomp (S.UP f) (S.UP f') \<Rightarrow>\<^sub>S S.UP (f \<star> f')\<guillemotright>"
using assms left_adjoint_is_ide UP.\<Phi>_in_hom by simp
moreover have "S.iso (S.\<Phi> (f, f'))"
using assms left_adjoint_is_ide by simp
ultimately show ?thesis
using S.isomorphic_def by blast
qed
ultimately have "S.is_left_adjoint (S.UP (f \<star> f'))"
using S.left_adjoint_preserved_by_iso S.isomorphic_def by blast
thus "is_left_adjoint (f \<star> f')"
using assms left_adjoint_is_ide UP.reflects_left_adjoint by simp
qed
lemma right_adjoints_compose:
assumes "is_right_adjoint g" and "is_right_adjoint g'" and "src g' = trg g"
shows "is_right_adjoint (g' \<star> g)"
proof -
have "S.is_right_adjoint (S.UP g) \<and> S.is_right_adjoint (S.UP g')"
using assms UP.preserves_right_adjoint by simp
moreover have "S.src (S.UP g') = S.trg (S.UP g)"
using assms right_adjoint_is_ide by simp
ultimately have "S.is_right_adjoint (S.hcomp (S.UP g') (S.UP g))"
using S.right_adjoints_compose by simp
moreover have "S.isomorphic (S.hcomp (S.UP g') (S.UP g)) (S.UP (g' \<star> g))"
proof -
have "\<guillemotleft>S.\<Phi> (g', g) : S.hcomp (S.UP g') (S.UP g) \<Rightarrow>\<^sub>S S.UP (g' \<star> g)\<guillemotright>"
using assms right_adjoint_is_ide UP.\<Phi>_in_hom by simp
moreover have "S.iso (S.\<Phi> (g', g))"
using assms right_adjoint_is_ide by simp
ultimately show ?thesis
using S.isomorphic_def by blast
qed
ultimately have "S.is_right_adjoint (S.UP (g' \<star> g))"
using S.right_adjoint_preserved_by_iso S.isomorphic_def by blast
thus "is_right_adjoint (g' \<star> g)"
using assms right_adjoint_is_ide UP.reflects_right_adjoint by simp
qed
end
subsection "Choosing Right Adjoints"
text \<open>
It will be useful in various situations to suppose that we have made a choice of
right adjoint for each left adjoint ({\it i.e.} each ``map'') in a bicategory.
\<close>
locale chosen_right_adjoints =
bicategory
begin
(* Global notation is evil! *)
no_notation Transitive_Closure.rtrancl ("(_\<^sup>*)" [1000] 999)
definition some_right_adjoint ("_\<^sup>*" [1000] 1000)
where "f\<^sup>* \<equiv> SOME g. adjoint_pair f g"
definition some_unit
where "some_unit f \<equiv> SOME \<eta>. \<exists>\<epsilon>. adjunction_in_bicategory V H \<a> \<i> src trg f f\<^sup>* \<eta> \<epsilon>"
definition some_counit
where "some_counit f \<equiv>
SOME \<epsilon>. adjunction_in_bicategory V H \<a> \<i> src trg f f\<^sup>* (some_unit f) \<epsilon>"
lemma left_adjoint_extends_to_adjunction:
assumes "is_left_adjoint f"
shows "adjunction_in_bicategory V H \<a> \<i> src trg f f\<^sup>* (some_unit f) (some_counit f)"
using assms some_right_adjoint_def adjoint_pair_def some_unit_def some_counit_def
someI_ex [of "\<lambda>g. adjoint_pair f g"]
someI_ex [of "\<lambda>\<eta>. \<exists>\<epsilon>. adjunction_in_bicategory V H \<a> \<i> src trg f f\<^sup>* \<eta> \<epsilon>"]
someI_ex [of "\<lambda>\<epsilon>. adjunction_in_bicategory V H \<a> \<i> src trg f f\<^sup>* (some_unit f) \<epsilon>"]
by auto
lemma left_adjoint_extends_to_adjoint_pair:
assumes "is_left_adjoint f"
shows "adjoint_pair f f\<^sup>*"
using assms adjoint_pair_def left_adjoint_extends_to_adjunction by blast
lemma right_adjoint_in_hom [intro]:
assumes "is_left_adjoint f"
shows "\<guillemotleft>f\<^sup>* : trg f \<rightarrow> src f\<guillemotright>"
and "\<guillemotleft>f\<^sup>* : f\<^sup>* \<Rightarrow> f\<^sup>*\<guillemotright>"
using assms left_adjoint_extends_to_adjoint_pair adjoint_pair_antipar [of f "f\<^sup>*"]
by auto
lemma right_adjoint_simps [simp]:
assumes "is_left_adjoint f"
shows "ide f\<^sup>*"
and "src f\<^sup>* = trg f" and "trg f\<^sup>* = src f"
and "dom f\<^sup>* = f\<^sup>*" and "cod f\<^sup>* = f\<^sup>*"
using assms right_adjoint_in_hom left_adjoint_extends_to_adjoint_pair apply auto
using assms right_adjoint_is_ide [of "f\<^sup>*"] by blast
end
locale map_in_bicategory =
bicategory + chosen_right_adjoints +
fixes f :: 'a
assumes is_map: "is_left_adjoint f"
begin
abbreviation \<eta>
where "\<eta> \<equiv> some_unit f"
abbreviation \<epsilon>
where "\<epsilon> \<equiv> some_counit f"
sublocale adjunction_in_bicategory V H \<a> \<i> src trg f \<open>f\<^sup>*\<close> \<eta> \<epsilon>
using is_map left_adjoint_extends_to_adjunction by simp
end
subsection "Equivalences Refine to Adjoint Equivalences"
text \<open>
In this section, we show that, just as an equivalence between categories can always
be refined to an adjoint equivalence, an internal equivalence in a bicategory can also
always be so refined.
The proof, which follows that of Theorem 3.3 from \cite{nlab-adjoint-equivalence},
makes use of the fact that if an internal equivalence satisfies one of the triangle
identities, then it also satisfies the other.
\<close>
locale adjoint_equivalence_in_bicategory =
equivalence_in_bicategory +
adjunction_in_bicategory
begin
lemma dual_adjoint_equivalence:
shows "adjoint_equivalence_in_bicategory V H \<a> \<i> src trg g f (inv \<epsilon>) (inv \<eta>)"
proof -
interpret gf: equivalence_in_bicategory V H \<a> \<i> src trg g f \<open>inv \<epsilon>\<close> \<open>inv \<eta>\<close>
using dual_equivalence by simp
show ?thesis
proof
show "(inv \<eta> \<star> g) \<cdot> \<a>\<^sup>-\<^sup>1[g, f, g] \<cdot> (g \<star> inv \<epsilon>) = \<l>\<^sup>-\<^sup>1[g] \<cdot> \<r>[g]"
proof -
have "(inv \<eta> \<star> g) \<cdot> \<a>\<^sup>-\<^sup>1[g, f, g] \<cdot> (g \<star> inv \<epsilon>) =
inv ((g \<star> \<epsilon>) \<cdot> \<a>[g, f, g] \<cdot> (\<eta> \<star> g))"
using antipar inv_comp iso_inv_iso isos_compose comp_assoc by simp
also have "... = inv (\<r>\<^sup>-\<^sup>1[g] \<cdot> \<l>[g])"
using triangle_right by simp
also have "... = \<l>\<^sup>-\<^sup>1[g] \<cdot> \<r>[g]"
using iso_inv_iso inv_comp by simp
finally show ?thesis
by blast
qed
show "(f \<star> inv \<eta>) \<cdot> \<a>[f, g, f] \<cdot> (inv \<epsilon> \<star> f) = \<r>\<^sup>-\<^sup>1[f] \<cdot> \<l>[f]"
proof -
have "(f \<star> inv \<eta>) \<cdot> \<a>[f, g, f] \<cdot> (inv \<epsilon> \<star> f) =
inv ((\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>))"
using antipar inv_comp iso_inv_iso isos_compose comp_assoc by simp
also have "... = inv (\<l>\<^sup>-\<^sup>1[f] \<cdot> \<r>[f])"
using triangle_left by simp
also have "... = \<r>\<^sup>-\<^sup>1[f] \<cdot> \<l>[f]"
using iso_inv_iso inv_comp by simp
finally show ?thesis by blast
qed
qed
qed
end
context strict_bicategory
begin
lemma equivalence_refines_to_adjoint_equivalence:
assumes "equivalence_map f" and "\<guillemotleft>g : trg f \<rightarrow> src f\<guillemotright>" and "ide g"
and "\<guillemotleft>\<eta> : src f \<Rightarrow> g \<star> f\<guillemotright>" and "iso \<eta>"
shows "\<exists>!\<epsilon>. adjoint_equivalence_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>"
proof -
obtain g' \<eta>' \<epsilon>' where E': "equivalence_in_bicategory V H \<a> \<i> src trg f g' \<eta>' \<epsilon>'"
using assms equivalence_map_def by auto
interpret E': equivalence_in_bicategory V H \<a> \<i> src trg f g' \<eta>' \<epsilon>'
using E' by auto
let ?a = "src f" and ?b = "trg f"
(* TODO: in_homE cannot be applied automatically to a conjunction. Must break down! *)
have f_in_hhom: "\<guillemotleft>f : ?a \<rightarrow> ?b\<guillemotright>" and ide_f: "ide f"
using assms equivalence_map_def by auto
have g_in_hhom: "\<guillemotleft>g : ?b \<rightarrow> ?a\<guillemotright>" and ide_g: "ide g"
using assms by auto
have g'_in_hhom: "\<guillemotleft>g' : ?b \<rightarrow> ?a\<guillemotright>" and ide_g': "ide g'"
using assms f_in_hhom E'.antipar by auto
have \<eta>_in_hom: "\<guillemotleft>\<eta> : ?a \<Rightarrow> g \<star> f\<guillemotright>" and iso_\<eta>: "iso \<eta>"
using assms by auto
have a: "obj ?a" and b: "obj ?b"
using f_in_hhom by auto
have \<eta>_in_hhom: "\<guillemotleft>\<eta> : ?a \<rightarrow> ?a\<guillemotright>"
using a src_dom trg_dom \<eta>_in_hom by fastforce
text \<open>
The following is quoted from \cite{nlab-adjoint-equivalence}:
\begin{quotation}
``Since \<open>g \<cong> gfg' \<cong> g'\<close>, the isomorphism \<open>fg' \<cong> 1\<close> also induces an isomorphism \<open>fg \<cong> 1\<close>,
which we denote \<open>\<xi>\<close>. Now \<open>\<eta>\<close> and \<open>\<xi>\<close> may not satisfy the zigzag identities, but if we
define \<open>\<epsilon>\<close> by \<open>\<xi> \<cdot> (f \<star> \<eta>\<^sup>-\<^sup>1) \<cdot> (f \<star> g \<star> \<xi>\<^sup>-\<^sup>1) : f \<star> g \<Rightarrow> 1\<close>, then we can verify,
using string diagram notation as above,
that \<open>\<epsilon>\<close> satisfies one zigzag identity, and hence (by the previous lemma) also the other.
Finally, if \<open>\<epsilon>': fg \<Rightarrow> 1\<close> is any other isomorphism satisfying the zigzag identities
with \<open>\<eta>\<close>, then we have:
\[
\<open>\<epsilon>' = \<epsilon>' \<cdot> (\<epsilon> f g) \<cdot> (f \<eta> g) = \<epsilon> \<cdot> (f g \<epsilon>') \<cdot> (f \<eta> g) = \<epsilon>\<close>
\]
using the interchange law and two zigzag identities. This shows uniqueness.''
\end{quotation}
\<close>
have 1: "isomorphic g g'"
proof -
have "isomorphic g (g \<star> ?b)"
using assms hcomp_arr_obj isomorphic_reflexive by auto
also have "isomorphic ... (g \<star> f \<star> g')"
using assms f_in_hhom g_in_hhom g'_in_hhom E'.counit_in_vhom E'.counit_is_iso
isomorphic_def hcomp_ide_isomorphic isomorphic_symmetric
by (metis E'.counit_simps(5) in_hhomE trg_trg)
also have "isomorphic ... (?a \<star> g')"
using assms f_in_hhom g_in_hhom g'_in_hhom ide_g' E'.unit_in_vhom E'.unit_is_iso
isomorphic_def hcomp_isomorphic_ide isomorphic_symmetric
by (metis hcomp_assoc hcomp_isomorphic_ide in_hhomE src_src)
also have "isomorphic ... g'"
using assms
by (simp add: E'.antipar(1) hcomp_obj_arr isomorphic_reflexive)
finally show ?thesis by blast
qed
moreover have "isomorphic (f \<star> g') ?b"
using E'.counit_is_iso isomorphicI [of \<epsilon>'] by auto
hence 2: "isomorphic (f \<star> g) ?b"
using assms 1 ide_f hcomp_ide_isomorphic [of f g g'] isomorphic_transitive
isomorphic_symmetric
by (metis in_hhomE)
obtain \<xi> where \<xi>: "\<guillemotleft>\<xi> : f \<star> g \<Rightarrow> ?b\<guillemotright> \<and> iso \<xi>"
using 2 by auto
have \<xi>_in_hom: "\<guillemotleft>\<xi> : f \<star> g \<Rightarrow> ?b\<guillemotright>" and iso_\<xi>: "iso \<xi>"
using \<xi> by auto
have \<xi>_in_hhom: "\<guillemotleft>\<xi> : ?b \<rightarrow> ?b\<guillemotright>"
using b src_cod trg_cod \<xi>_in_hom by fastforce
text \<open>
At the time of this writing, the definition of \<open>\<epsilon>\<close> given on nLab
\cite{nlab-adjoint-equivalence} had an apparent typo:
the expression \<open>f \<star> g \<star> \<xi>\<^sup>-\<^sup>1\<close> should read \<open>\<xi>\<^sup>-\<^sup>1 \<star> f \<star> g\<close>, as we have used here.
\<close>
let ?\<epsilon> = "\<xi> \<cdot> (f \<star> inv \<eta> \<star> g) \<cdot> (inv \<xi> \<star> f \<star> g)"
have \<epsilon>_in_hom: "\<guillemotleft>?\<epsilon> : f \<star> g \<Rightarrow> ?b\<guillemotright>"
proof -
have "\<guillemotleft>f \<star> inv \<eta> \<star> g : f \<star> g \<star> f \<star> g \<Rightarrow> f \<star> g\<guillemotright>"
proof -
have "\<guillemotleft>inv \<eta> : g \<star> f \<Rightarrow> ?a\<guillemotright>"
using \<eta>_in_hom iso_\<eta> by auto
hence "\<guillemotleft>f \<star> inv \<eta> \<star> g : f \<star> (g \<star> f) \<star> g \<Rightarrow> f \<star> ?a \<star> g\<guillemotright>"
using assms by (intro hcomp_in_vhom, auto)
hence "\<guillemotleft>f \<star> inv \<eta> \<star> g : f \<star> (g \<star> f) \<star> g \<Rightarrow> f \<star> g\<guillemotright>"
using assms f_in_hhom hcomp_obj_arr by (metis in_hhomE)
moreover have "f \<star> (g \<star> f) \<star> g = f \<star> g \<star> f \<star> g"
using hcomp_assoc by simp
ultimately show ?thesis by simp
qed
moreover have "\<guillemotleft>inv \<xi> \<star> f \<star> g : f \<star> g \<Rightarrow> f \<star> g \<star> f \<star> g\<guillemotright>"
proof -
have "\<guillemotleft>inv \<xi> \<star> f \<star> g : ?b \<star> f \<star> g \<Rightarrow> (f \<star> g) \<star> f \<star> g\<guillemotright>"
using assms \<xi>_in_hom iso_\<xi> by (intro hcomp_in_vhom, auto)
moreover have "(f \<star> g) \<star> f \<star> g = f \<star> g \<star> f \<star> g"
using hcomp_assoc by simp
moreover have "?b \<star> f \<star> g = f \<star> g"
using f_in_hhom g_in_hhom b hcomp_obj_arr [of ?b "f \<star> g"] by fastforce
ultimately show ?thesis by simp
qed
ultimately show "\<guillemotleft>?\<epsilon> : f \<star> g \<Rightarrow> ?b\<guillemotright>"
using \<xi>_in_hom by blast
qed
have "iso ?\<epsilon>"
using f_in_hhom g_in_hhom \<eta>_in_hhom ide_f ide_g \<eta>_in_hom iso_\<eta> \<xi>_in_hhom \<xi>_in_hom iso_\<xi>
iso_inv_iso isos_compose
by (metis \<epsilon>_in_hom arrI hseqE ide_is_iso iso_hcomp seqE)
have 4: "\<guillemotleft>inv \<xi> \<star> f : ?b \<star> f \<Rightarrow> f \<star> g \<star> f\<guillemotright>"
proof -
have "\<guillemotleft>inv \<xi> \<star> f : ?b \<star> f \<Rightarrow> (f \<star> g) \<star> f\<guillemotright>"
using \<xi>_in_hom iso_\<xi> f_in_hhom
by (intro hcomp_in_vhom, auto)
thus ?thesis
using hcomp_assoc by simp
qed
text \<open>
First show \<open>?\<epsilon>\<close> and \<open>\<eta>\<close> satisfy the ``left'' triangle identity.
\<close>
have triangle_left: "(?\<epsilon> \<star> f) \<cdot> (f \<star> \<eta>) = f"
proof -
have "(?\<epsilon> \<star> f) \<cdot> (f \<star> \<eta>) = (\<xi> \<star> f) \<cdot> (f \<star> inv \<eta> \<star> g \<star> f) \<cdot> (inv \<xi> \<star> f \<star> g \<star> f) \<cdot> (?b \<star> f \<star> \<eta>)"
proof -
have "f \<star> \<eta> = ?b \<star> f \<star> \<eta>"
using b \<eta>_in_hhom hcomp_obj_arr [of ?b "f \<star> \<eta>"] by fastforce
moreover have "\<xi> \<cdot> (f \<star> inv \<eta> \<star> g) \<cdot> (inv \<xi> \<star> f \<star> g) \<star> f =
(\<xi> \<star> f) \<cdot> ((f \<star> inv \<eta> \<star> g) \<star> f) \<cdot> ((inv \<xi> \<star> f \<star> g) \<star> f)"
using ide_f ide_g \<xi>_in_hhom \<xi>_in_hom iso_\<xi> \<eta>_in_hhom \<eta>_in_hom iso_\<eta> whisker_right
by (metis \<epsilon>_in_hom arrI in_hhomE seqE)
moreover have "... = (\<xi> \<star> f) \<cdot> (f \<star> inv \<eta> \<star> g \<star> f) \<cdot> (inv \<xi> \<star> f \<star> g \<star> f)"
using hcomp_assoc by simp
ultimately show ?thesis
using comp_assoc by simp
qed
also have "... = (\<xi> \<star> f) \<cdot> ((f \<star> inv \<eta> \<star> g \<star> f) \<cdot> (f \<star> g \<star> f \<star> \<eta>)) \<cdot> (inv \<xi> \<star> f)"
proof -
have "((inv \<xi> \<star> f) \<star> (g \<star> f)) \<cdot> ((?b \<star> f) \<star> \<eta>) = (inv \<xi> \<star> f) \<cdot> (?b \<star> f) \<star> (g \<star> f) \<cdot> \<eta>"
proof -
have "seq (inv \<xi> \<star> f) (?b \<star> f)"
using a b 4 ide_f ide_g \<xi>_in_hhom \<xi>_in_hom iso_\<xi> \<eta>_in_hhom \<eta>_in_hom iso_\<eta>
by blast
moreover have "seq (g \<star> f) \<eta>"
using f_in_hhom g_in_hhom ide_g ide_f \<eta>_in_hom by fast
ultimately show ?thesis
using interchange [of "inv \<xi> \<star> f" "?b \<star> f" "g \<star> f" \<eta>] by simp
qed
also have "... = inv \<xi> \<star> f \<star> \<eta>"
proof -
have "(inv \<xi> \<star> f) \<cdot> (?b \<star> f) = inv \<xi> \<star> f"
using 4 comp_arr_dom by auto
moreover have "(g \<star> f) \<cdot> \<eta> = \<eta>"
using \<eta>_in_hom comp_cod_arr by auto
ultimately show ?thesis
using hcomp_assoc by simp
qed
also have "... = (f \<star> g) \<cdot> inv \<xi> \<star> (f \<star> \<eta>) \<cdot> (f \<star> ?a)"
proof -
have "(f \<star> g) \<cdot> inv \<xi> = inv \<xi>"
using \<xi>_in_hom iso_\<xi> comp_cod_arr by auto
moreover have "(f \<star> \<eta>) \<cdot> (f \<star> ?a) = f \<star> \<eta>"
proof -
have "\<guillemotleft>f \<star> \<eta> : f \<star> ?a \<Rightarrow> f \<star> g \<star> f\<guillemotright>"
using \<eta>_in_hom by fastforce
thus ?thesis
using comp_arr_dom by blast
qed
ultimately show ?thesis by argo
qed
also have "... = ((f \<star> g) \<star> (f \<star> \<eta>)) \<cdot> (inv \<xi> \<star> (f \<star> ?a))"
proof -
have "seq (f \<star> g) (inv \<xi>)"
using \<xi>_in_hom iso_\<xi> comp_cod_arr by auto
moreover have "seq (f \<star> \<eta>) (f \<star> ?a)"
using f_in_hhom \<eta>_in_hom by force
ultimately show ?thesis
using interchange by simp
qed
also have "... = (f \<star> g \<star> f \<star> \<eta>) \<cdot> (inv \<xi> \<star> f)"
using hcomp_arr_obj hcomp_assoc by auto
finally have "((inv \<xi> \<star> f) \<star> (g \<star> f)) \<cdot> ((?b \<star> f) \<star> \<eta>) = (f \<star> g \<star> f \<star> \<eta>) \<cdot> (inv \<xi> \<star> f)"
by simp
thus ?thesis
using comp_assoc hcomp_assoc by simp
qed
also have "... = (\<xi> \<star> f) \<cdot> ((f \<star> ?a \<star> \<eta>) \<cdot> (f \<star> inv \<eta> \<star> ?a)) \<cdot> (inv \<xi> \<star> f)"
proof -
have "(f \<star> inv \<eta> \<star> g \<star> f) \<cdot> (f \<star> (g \<star> f) \<star> \<eta>) = f \<star> (inv \<eta> \<star> g \<star> f) \<cdot> ((g \<star> f) \<star> \<eta>)"
proof -
have "seq ((inv \<eta> \<star> g) \<star> f) ((g \<star> f) \<star> \<eta>)"
proof -
have "seq (inv \<eta> \<star> g \<star> f) ((g \<star> f) \<star> \<eta>)"
using f_in_hhom ide_f g_in_hhom ide_g \<eta>_in_hhom \<eta>_in_hom iso_\<eta>
apply (intro seqI)
apply blast
apply blast
by fastforce
thus ?thesis
using hcomp_assoc by simp
qed
hence "(f \<star> (inv \<eta> \<star> g) \<star> f) \<cdot> (f \<star> (g \<star> f) \<star> \<eta>) =
f \<star> ((inv \<eta> \<star> g) \<star> f) \<cdot> ((g \<star> f) \<star> \<eta>)"
using whisker_left by simp
thus ?thesis
using hcomp_assoc by simp
qed
also have "... = f \<star> (?a \<star> \<eta>) \<cdot> (inv \<eta> \<star> ?a)"
proof -
have "(inv \<eta> \<star> g \<star> f) \<cdot> ((g \<star> f) \<star> \<eta>) = (?a \<star> \<eta>) \<cdot> (inv \<eta> \<star> ?a)"
proof -
have "(inv \<eta> \<star> g \<star> f) \<cdot> ((g \<star> f) \<star> \<eta>) = inv \<eta> \<cdot> (g \<star> f) \<star> (g \<star> f) \<cdot> \<eta>"
proof -
have "seq (inv \<eta>) (g \<star> f)"
using g_in_hhom ide_g \<eta>_in_hom iso_\<eta> by force
moreover have "seq (g \<star> f) \<eta>"
using g_in_hhom ide_g \<eta>_in_hom by fastforce
ultimately show ?thesis
using interchange by fastforce
qed
also have "... = inv \<eta> \<star> \<eta>"
using \<eta>_in_hom iso_\<eta> comp_arr_dom comp_cod_arr by auto
also have "... = ?a \<cdot> inv \<eta> \<star> \<eta> \<cdot> ?a"
using \<eta>_in_hom iso_\<eta> comp_arr_dom comp_cod_arr by auto
also have "... = (?a \<star> \<eta>) \<cdot> (inv \<eta> \<star> ?a)"
proof -
have "seq ?a (inv \<eta>)"
using a \<eta>_in_hom iso_\<eta> ideD [of ?a] by (elim objE, auto)
moreover have "seq \<eta> ?a"
using a \<eta>_in_hom by fastforce
ultimately show ?thesis
using interchange by blast
qed
finally show ?thesis by simp
qed
thus ?thesis by argo
qed
also have "... = (f \<star> ?a \<star> \<eta>) \<cdot> (f \<star> inv \<eta> \<star> ?a)"
proof -
have "seq (?a \<star> \<eta>) (inv \<eta> \<star> ?a)"
proof (intro seqI')
show "\<guillemotleft>inv \<eta> \<star> ?a : (g \<star> f) \<star> ?a \<Rightarrow> ?a \<star> ?a\<guillemotright>"
using a g_in_hhom \<eta>_in_hom iso_\<eta> hseqI ide_f ide_g
apply (elim in_homE in_hhomE, intro hcomp_in_vhom)
by auto
show "\<guillemotleft>?a \<star> \<eta> : ?a \<star> ?a \<Rightarrow> ?a \<star> g \<star> f\<guillemotright>"
using a \<eta>_in_hom hseqI by (intro hcomp_in_vhom, auto)
qed
thus ?thesis
using whisker_left by simp
qed
finally show ?thesis
using hcomp_assoc by simp
qed
also have "... = (\<xi> \<star> f) \<cdot> ((f \<star> \<eta>) \<cdot> (f \<star> inv \<eta>)) \<cdot> (inv \<xi> \<star> f)"
using a \<eta>_in_hhom iso_\<eta> hcomp_obj_arr [of ?a \<eta>] hcomp_arr_obj [of "inv \<eta>" ?a] by auto
also have "... = (\<xi> \<star> f) \<cdot> (inv \<xi> \<star> f)"
proof -
have "(f \<star> \<eta>) \<cdot> (f \<star> inv \<eta>) = f \<star> \<eta> \<cdot> inv \<eta>"
using \<eta>_in_hhom iso_\<eta> whisker_left inv_in_hom by auto
moreover have "f \<star> \<eta> \<cdot> inv \<eta> = f \<star> g \<star> f"
using \<eta>_in_hom iso_\<eta> comp_arr_inv inv_is_inverse by auto
moreover have "(f \<star> g \<star> f) \<cdot> (inv \<xi> \<star> f) = inv \<xi> \<star> f"
proof -
have "\<guillemotleft>inv \<xi> \<star> f : ?b \<star> f \<Rightarrow> f \<star> g \<star> f\<guillemotright>"
proof -
have "\<guillemotleft>inv \<xi> \<star> f : ?b \<star> f \<Rightarrow> (f \<star> g) \<star> f\<guillemotright>"
using \<xi>_in_hom iso_\<xi> by (intro hcomp_in_vhom, auto)
thus ?thesis
using hcomp_assoc by simp
qed
moreover have "f \<star> g \<star> f = cod (inv \<xi> \<star> f)"
using \<xi>_in_hhom iso_\<xi> hcomp_assoc calculation by auto
ultimately show ?thesis
using comp_cod_arr by auto
qed
ultimately show ?thesis by simp
qed
also have "... = ?b \<star> f"
proof -
have "(\<xi> \<star> f) \<cdot> (inv \<xi> \<star> f) = \<xi> \<cdot> inv \<xi> \<star> f"
using \<xi>_in_hhom iso_\<xi> whisker_right by auto
moreover have "\<xi> \<cdot> inv \<xi> = ?b"
using \<xi>_in_hom iso_\<xi> comp_arr_inv inv_is_inverse by auto
ultimately show ?thesis by simp
qed
also have "... = f"
using hcomp_obj_arr by auto
finally show ?thesis by blast
qed
(* TODO: Putting this earlier breaks some steps in the proof. *)
interpret E: equivalence_in_strict_bicategory V H \<a> \<i> src trg f g \<eta> ?\<epsilon>
using ide_g \<eta>_in_hom \<epsilon>_in_hom g_in_hhom `iso \<eta>` `iso ?\<epsilon>`
by (unfold_locales, auto)
text \<open>
Apply ``triangle left if and only iff right'' to show the ``right'' triangle identity.
\<close>
have triangle_right: "((g \<star> \<xi> \<cdot> (f \<star> inv \<eta> \<star> g) \<cdot> (inv \<xi> \<star> f \<star> g)) \<cdot> (\<eta> \<star> g) = g)"
using triangle_left E.triangle_left_iff_right by simp
text \<open>
Use the two triangle identities to establish an adjoint equivalence and show that
there is only one choice for the counit.
\<close>
show "\<exists>!\<epsilon>. adjoint_equivalence_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>"
proof -
have "adjoint_equivalence_in_bicategory V H \<a> \<i> src trg f g \<eta> ?\<epsilon>"
proof
show "(?\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>) = \<l>\<^sup>-\<^sup>1[f] \<cdot> \<r>[f]"
proof -
have "(?\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>) = (?\<epsilon> \<star> f) \<cdot> (f \<star> \<eta>)"
proof -
have "seq \<a>\<^sup>-\<^sup>1[f, g, f] (f \<star> \<eta>)"
using E.antipar
by (intro seqI, auto)
hence "\<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>) = f \<star> \<eta>"
using ide_f ide_g E.antipar triangle_right strict_assoc' comp_ide_arr
by presburger
thus ?thesis by simp
qed
also have "... = f"
using triangle_left by simp
also have "... = \<l>\<^sup>-\<^sup>1[f] \<cdot> \<r>[f]"
using strict_lunit strict_runit by simp
finally show ?thesis by simp
qed
show "(g \<star> ?\<epsilon>) \<cdot> \<a>[g, f, g] \<cdot> (\<eta> \<star> g) = \<r>\<^sup>-\<^sup>1[g] \<cdot> \<l>[g]"
proof -
have "(g \<star> ?\<epsilon>) \<cdot> \<a>[g, f, g] \<cdot> (\<eta> \<star> g) = (g \<star> ?\<epsilon>) \<cdot> (\<eta> \<star> g)"
proof -
have "seq \<a>[g, f, g] (\<eta> \<star> g)"
using E.antipar
by (intro seqI, auto)
hence "\<a>[g, f, g] \<cdot> (\<eta> \<star> g) = \<eta> \<star> g"
using ide_f ide_g E.antipar triangle_right strict_assoc comp_ide_arr
by presburger
thus ?thesis by simp
qed
also have "... = g"
using triangle_right by simp
also have "... = \<r>\<^sup>-\<^sup>1[g] \<cdot> \<l>[g]"
using strict_lunit strict_runit by simp
finally show ?thesis by blast
qed
qed
moreover have "\<And>\<epsilon> \<epsilon>'. \<lbrakk> adjoint_equivalence_in_bicategory (\<cdot>) (\<star>) \<a> \<i> src trg f g \<eta> \<epsilon>;
adjoint_equivalence_in_bicategory (\<cdot>) (\<star>) \<a> \<i> src trg f g \<eta> \<epsilon>' \<rbrakk>
\<Longrightarrow> \<epsilon> = \<epsilon>'"
using adjunction_unit_determines_counit
by (meson adjoint_equivalence_in_bicategory.axioms(2))
ultimately show ?thesis by auto
qed
qed
end
text \<open>
We now apply strictification to generalize the preceding result to an arbitrary bicategory.
\<close>
context bicategory
begin
interpretation S: strictified_bicategory V H \<a> \<i> src trg ..
notation S.vcomp (infixr "\<cdot>\<^sub>S" 55)
notation S.hcomp (infixr "\<star>\<^sub>S" 53)
notation S.in_hom ("\<guillemotleft>_ : _ \<Rightarrow>\<^sub>S _\<guillemotright>")
notation S.in_hhom ("\<guillemotleft>_ : _ \<rightarrow>\<^sub>S _\<guillemotright>")
interpretation UP: fully_faithful_functor V S.vcomp S.UP
using S.UP_is_fully_faithful_functor by auto
interpretation UP: equivalence_pseudofunctor V H \<a> \<i> src trg
S.vcomp S.hcomp S.\<a> S.\<i> S.src S.trg S.UP S.\<Phi>
using S.UP_is_equivalence_pseudofunctor by auto
interpretation UP: pseudofunctor_into_strict_bicategory V H \<a> \<i> src trg
S.vcomp S.hcomp S.\<a> S.\<i> S.src S.trg S.UP S.\<Phi>
..
lemma equivalence_refines_to_adjoint_equivalence:
assumes "equivalence_map f" and "\<guillemotleft>g : trg f \<rightarrow> src f\<guillemotright>" and "ide g"
and "\<guillemotleft>\<eta> : src f \<Rightarrow> g \<star> f\<guillemotright>" and "iso \<eta>"
shows "\<exists>!\<epsilon>. adjoint_equivalence_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>"
proof -
text \<open>
To unpack the consequences of the assumptions, we need to obtain an
interpretation of @{locale equivalence_in_bicategory}, even though we don't
need the associated data other than \<open>f\<close>, \<open>a\<close>, and \<open>b\<close>.
\<close>
obtain g' \<phi> \<psi> where E: "equivalence_in_bicategory V H \<a> \<i> src trg f g' \<phi> \<psi>"
using assms equivalence_map_def by auto
interpret E: equivalence_in_bicategory V H \<a> \<i> src trg f g' \<phi> \<psi>
using E by auto
let ?a = "src f" and ?b = "trg f"
have ide_f: "ide f" by simp
have f_in_hhom: "\<guillemotleft>f : ?a \<rightarrow> ?b\<guillemotright>" by simp
have a: "obj ?a" and b: "obj ?b" by auto
have 1: "S.equivalence_map (S.UP f)"
using assms UP.preserves_equivalence_maps by simp
let ?\<eta>' = "S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta> \<cdot>\<^sub>S UP.\<Psi> ?a"
have 2: "\<guillemotleft>S.UP \<eta> : S.UP ?a \<Rightarrow>\<^sub>S S.UP (g \<star> f)\<guillemotright>"
using assms UP.preserves_hom [of \<eta> "src f" "g \<star> f"] by auto
have 4: "\<guillemotleft>?\<eta>' : UP.map\<^sub>0 ?a \<Rightarrow>\<^sub>S S.UP g \<star>\<^sub>S S.UP f\<guillemotright> \<and> S.iso ?\<eta>'"
proof (intro S.comp_in_homI conjI)
have 3: "S.iso (S.\<Phi> (g, f))"
using assms UP.\<Phi>_components_are_iso by auto
show "\<guillemotleft>S.inv (S.\<Phi> (g, f)) : S.UP (g \<star> f) \<Rightarrow>\<^sub>S S.UP g \<star>\<^sub>S S.UP f\<guillemotright>"
using assms 3 UP.\<Phi>_in_hom(2) [of g f] UP.FF_def by auto
moreover show "\<guillemotleft>UP.\<Psi> ?a : UP.map\<^sub>0 ?a \<Rightarrow>\<^sub>S S.UP ?a\<guillemotright>" by auto
moreover show "\<guillemotleft>S.UP \<eta> : S.UP ?a \<Rightarrow>\<^sub>S S.UP (g \<star> f)\<guillemotright>"
using 2 by simp
ultimately show "S.iso (S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta> \<cdot>\<^sub>S UP.\<Psi> ?a)"
using assms 3 a UP.\<Psi>_char(2) S.iso_inv_iso
apply (intro S.isos_compose) by auto
qed
have ex_un_\<xi>': "\<exists>!\<xi>'. adjoint_equivalence_in_bicategory S.vcomp S.hcomp S.\<a> S.\<i> S.src S.trg
(S.UP f) (S.UP g) ?\<eta>' \<xi>'"
proof -
have "\<guillemotleft>S.UP g : S.trg (S.UP f) \<rightarrow>\<^sub>S S.src (S.UP f)\<guillemotright>"
using assms(2) by auto
moreover have "S.ide (S.UP g)"
by (simp add: assms(3))
ultimately show ?thesis
using 1 4 S.equivalence_refines_to_adjoint_equivalence S.UP_map\<^sub>0_obj by simp
qed
obtain \<xi>' where \<xi>': "adjoint_equivalence_in_bicategory S.vcomp S.hcomp S.\<a> S.\<i> S.src S.trg
(S.UP f) (S.UP g) ?\<eta>' \<xi>'"
using ex_un_\<xi>' by auto
interpret E': adjoint_equivalence_in_bicategory S.vcomp S.hcomp S.\<a> S.\<i> S.src S.trg
\<open>S.UP f\<close> \<open>S.UP g\<close> ?\<eta>' \<xi>'
using \<xi>' by auto
let ?\<epsilon>' = "UP.\<Psi> ?b \<cdot>\<^sub>S \<xi>' \<cdot>\<^sub>S S.inv (S.\<Phi> (f, g))"
have \<epsilon>': "\<guillemotleft>?\<epsilon>' : S.UP (f \<star> g) \<Rightarrow>\<^sub>S S.UP ?b\<guillemotright>"
using assms(2-3) S.UP_map\<^sub>0_obj apply (intro S.in_homI) by auto
have ex_un_\<epsilon>: "\<exists>!\<epsilon>. \<guillemotleft>\<epsilon> : f \<star> g \<Rightarrow> ?b\<guillemotright> \<and> S.UP \<epsilon> = ?\<epsilon>'"
proof -
have "\<exists>\<epsilon>. \<guillemotleft>\<epsilon> : f \<star> g \<Rightarrow> ?b\<guillemotright> \<and> S.UP \<epsilon> = ?\<epsilon>'"
proof -
have "src (f \<star> g) = src ?b \<and> trg (f \<star> g) = trg ?b"
proof -
have "arr (f \<star> g)"
using assms(2) f_in_hhom by blast
thus ?thesis
using assms(2) f_in_hhom by (elim hseqE, auto)
qed
moreover have "ide (f \<star> g)"
using assms(2-3) by auto
ultimately show ?thesis
using \<epsilon>' UP.locally_full by auto
qed
moreover have
"\<And>\<mu> \<nu>. \<lbrakk> \<guillemotleft>\<mu> : f \<star> g \<Rightarrow> ?b\<guillemotright>; S.UP \<mu> = ?\<epsilon>'; \<guillemotleft>\<nu> : f \<star> g \<Rightarrow> ?b\<guillemotright>; S.UP \<nu> = ?\<epsilon>' \<rbrakk>
\<Longrightarrow> \<mu> = \<nu>"
proof -
fix \<mu> \<nu>
assume \<mu>: "\<guillemotleft>\<mu> : f \<star> g \<Rightarrow> ?b\<guillemotright>" and \<nu>: "\<guillemotleft>\<nu> : f \<star> g \<Rightarrow> ?b\<guillemotright>"
and 1: "S.UP \<mu> = ?\<epsilon>'" and 2: "S.UP \<nu> = ?\<epsilon>'"
have "par \<mu> \<nu>"
using \<mu> \<nu> by fastforce
thus "\<mu> = \<nu>"
using 1 2 UP.is_faithful [of \<mu> \<nu>] by simp
qed
ultimately show ?thesis by auto
qed
have iso_\<epsilon>': "S.iso ?\<epsilon>'"
proof (intro S.isos_compose)
show "S.iso (S.inv (S.\<Phi> (f, g)))"
using assms UP.\<Phi>_components_are_iso S.iso_inv_iso by auto
show "S.iso \<xi>'"
using E'.counit_is_iso by blast
show "S.iso (UP.\<Psi> ?b)"
using b UP.\<Psi>_char(2) by simp
show "S.seq (UP.\<Psi> ?b) (\<xi>' \<cdot>\<^sub>S S.inv (S.\<Phi> (f, g)))"
proof (intro S.seqI')
show "\<guillemotleft>UP.\<Psi> ?b : UP.map\<^sub>0 ?b \<Rightarrow>\<^sub>S S.UP ?b\<guillemotright>"
using b UP.\<Psi>_char by simp
show "\<guillemotleft>\<xi>' \<cdot>\<^sub>S S.inv (S.\<Phi> (f, g)) : S.UP (f \<star> g) \<Rightarrow>\<^sub>S UP.map\<^sub>0 ?b\<guillemotright>"
using assms UP.\<Phi>_components_are_iso VV.arr_char S.\<Phi>_in_hom [of "(f, g)"]
E'.counit_in_hom S.UP_map\<^sub>0_obj
apply (intro S.comp_in_homI) by auto
qed
thus "S.seq \<xi>' (S.inv (S.\<Phi> (f, g)))" by auto
qed
obtain \<epsilon> where \<epsilon>: "\<guillemotleft>\<epsilon> : f \<star> g \<Rightarrow> ?b\<guillemotright> \<and> S.UP \<epsilon> = ?\<epsilon>'"
using ex_un_\<epsilon> by auto
interpret E'': equivalence_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>
using assms(1,3-5)
apply unfold_locales
apply simp_all
using assms(2) \<epsilon>
apply auto[1]
using \<epsilon> iso_\<epsilon>' UP.reflects_iso [of \<epsilon>]
by auto
interpret E'': adjoint_equivalence_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>
proof
show "(\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>) = \<l>\<^sup>-\<^sup>1[f] \<cdot> \<r>[f]"
proof -
have "S.UP ((\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>)) =
S.\<Phi> (trg f, f) \<cdot>\<^sub>S (S.UP \<epsilon> \<cdot>\<^sub>S S.\<Phi> (f, g) \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S
(S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta>) \<cdot>\<^sub>S S.inv (S.\<Phi> (f, src f))"
using E''.UP_triangle(3) by simp
also have
"... = S.\<Phi> (trg f, f) \<cdot>\<^sub>S (UP.\<Psi> ?b \<cdot>\<^sub>S \<xi>' \<cdot>\<^sub>S S.inv (S.\<Phi> (f, g)) \<cdot>\<^sub>S S.\<Phi> (f, g) \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S
(S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta>) \<cdot>\<^sub>S S.inv (S.\<Phi> (f, src f))"
using \<epsilon> S.comp_assoc by simp
also have "... = S.\<Phi> (trg f, f) \<cdot>\<^sub>S (UP.\<Psi> ?b \<cdot>\<^sub>S \<xi>' \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S
(S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta>) \<cdot>\<^sub>S S.inv (S.\<Phi> (f, src f))"
proof -
have "\<xi>' \<cdot>\<^sub>S S.inv (S.\<Phi> (f, g)) \<cdot>\<^sub>S S.\<Phi> (f, g) = \<xi>'"
proof -
have "S.iso (S.\<Phi> (f, g))"
using assms by auto
moreover have "S.dom (S.\<Phi> (f, g)) = S.UP f \<star>\<^sub>S S.UP g"
using assms by auto
ultimately have "S.inv (S.\<Phi> (f, g)) \<cdot>\<^sub>S S.\<Phi> (f, g) = S.UP f \<star>\<^sub>S S.UP g"
using S.comp_inv_arr' by simp
thus ?thesis
using S.comp_arr_dom E'.counit_in_hom(2) by simp
qed
thus ?thesis by argo
qed
also have
"... = S.\<Phi> (trg f, f) \<cdot>\<^sub>S (UP.\<Psi> ?b \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S
((\<xi>' \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S (S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f))) \<cdot>\<^sub>S (S.UP f \<star>\<^sub>S S.UP \<eta>)) \<cdot>\<^sub>S
S.inv (S.\<Phi> (f, src f))"
proof -
have "UP.\<Psi> ?b \<cdot>\<^sub>S \<xi>' \<star>\<^sub>S S.UP f = (UP.\<Psi> ?b \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S (\<xi>' \<star>\<^sub>S S.UP f)"
using assms b UP.\<Psi>_char S.whisker_right S.UP_map\<^sub>0_obj by auto
moreover have "S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta> =
(S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f))) \<cdot>\<^sub>S (S.UP f \<star>\<^sub>S S.UP \<eta>)"
using assms S.whisker_left S.comp_assoc by auto
ultimately show ?thesis
using S.comp_assoc by simp
qed
also have "... = (S.\<Phi> (trg f, f) \<cdot>\<^sub>S (UP.\<Psi> ?b \<star>\<^sub>S S.UP f)) \<cdot>\<^sub>S
(S.UP f \<star>\<^sub>S S.inv (UP.\<Psi> (src f))) \<cdot>\<^sub>S S.inv (S.\<Phi> (f, src f))"
proof -
have "(\<xi>' \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S (S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f))) \<cdot>\<^sub>S (S.UP f \<star>\<^sub>S S.UP \<eta>) =
(S.UP f \<star>\<^sub>S S.inv (UP.\<Psi> (src f)))"
proof -
have "(S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f))) \<cdot>\<^sub>S (S.UP f \<star>\<^sub>S S.UP \<eta>) =
S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta>"
using assms S.whisker_left by auto
hence "((\<xi>' \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S (S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f))) \<cdot>\<^sub>S (S.UP f \<star>\<^sub>S S.UP \<eta>)) =
((\<xi>' \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S (S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta>))"
by simp
also have "... = ((\<xi>' \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S S.\<a>' (S.UP f) (S.UP g) (S.UP f)) \<cdot>\<^sub>S
(S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta>)"
proof -
have "(\<xi>' \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S S.\<a>' (S.UP f) (S.UP g) (S.UP f) = \<xi>' \<star>\<^sub>S S.UP f"
proof -
have "\<guillemotleft>\<xi>' \<star>\<^sub>S S.UP f :
(S.UP f \<star>\<^sub>S S.UP g) \<star>\<^sub>S S.UP f \<Rightarrow>\<^sub>S S.trg (S.UP f) \<star>\<^sub>S S.UP f\<guillemotright>"
using assms by (intro S.hcomp_in_vhom, auto)
moreover have "\<guillemotleft>S.\<a>' (S.UP f) (S.UP g) (S.UP f) :
S.UP f \<star>\<^sub>S S.UP g \<star>\<^sub>S S.UP f \<Rightarrow>\<^sub>S (S.UP f \<star>\<^sub>S S.UP g) \<star>\<^sub>S S.UP f\<guillemotright>"
using assms S.assoc'_in_hom by auto
ultimately show ?thesis
using assms S.strict_assoc' S.iso_assoc S.hcomp_assoc E'.antipar
S.comp_arr_ide S.seqI'
by (metis (no_types, lifting) E'.ide_left E'.ide_right)
qed
thus ?thesis
using S.comp_assoc by simp
qed
also have "... = ((\<xi>' \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S S.\<a>' (S.UP f) (S.UP g) (S.UP f) \<cdot>\<^sub>S
(S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta>))"
using S.comp_assoc by simp
also have "... = (S.UP f \<star>\<^sub>S S.inv (UP.\<Psi> (src f)))"
proof -
have "(\<xi>' \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S S.\<a>' (S.UP f) (S.UP g) (S.UP f) \<cdot>\<^sub>S
(S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta>) =
(S.UP f \<star>\<^sub>S S.inv (UP.\<Psi> (src f)))"
proof -
have "(\<xi>' \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S S.\<a>' (S.UP f) (S.UP g) (S.UP f) \<cdot>\<^sub>S
(S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta>) \<cdot>\<^sub>S
(S.UP f \<star>\<^sub>S UP.\<Psi> ?a) =
S.lunit' (S.UP f) \<cdot>\<^sub>S S.runit (S.UP f)"
proof -
have "(\<xi>' \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S S.\<a>' (S.UP f) (S.UP g) (S.UP f) \<cdot>\<^sub>S
(S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta>) \<cdot>\<^sub>S
(S.UP f \<star>\<^sub>S UP.\<Psi> ?a) =
(\<xi>' \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S S.\<a>' (S.UP f) (S.UP g) (S.UP f) \<cdot>\<^sub>S
(S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta> \<cdot>\<^sub>S UP.\<Psi> ?a)"
proof -
have "S.seq (S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta>) (UP.\<Psi> ?a)"
using assms UP.\<Psi>_char UP.\<Phi>_components_are_iso
E'.unit_simps(1) S.comp_assoc
by presburger
hence "(S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta>) \<cdot>\<^sub>S (S.UP f \<star>\<^sub>S UP.\<Psi> ?a) =
S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta> \<cdot>\<^sub>S UP.\<Psi> ?a"
using assms UP.\<Psi>_char UP.\<Phi>_components_are_iso S.comp_assoc
S.whisker_left [of "S.UP f" "S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta>" "UP.\<Psi> ?a"]
by simp
thus ?thesis by simp
qed
thus ?thesis
using assms E'.triangle_left UP.\<Phi>_components_are_iso UP.\<Psi>_char
by argo
qed
also have "... = S.UP f"
using S.strict_lunit' S.strict_runit by simp
finally have 1: "((\<xi>' \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S S.\<a>' (S.UP f) (S.UP g) (S.UP f) \<cdot>\<^sub>S
(S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta>)) \<cdot>\<^sub>S
(S.UP f \<star>\<^sub>S UP.\<Psi> ?a) = S.UP f"
using S.comp_assoc by simp
have "(\<xi>' \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S S.\<a>' (S.UP f) (S.UP g) (S.UP f) \<cdot>\<^sub>S
(S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta>) =
S.UP f \<cdot>\<^sub>S (S.UP f \<star>\<^sub>S S.inv (UP.\<Psi> ?a))"
proof -
have "S.arr (S.UP f)"
using assms by simp
moreover have "S.iso (S.UP f \<star>\<^sub>S UP.\<Psi> ?a)"
using assms UP.\<Psi>_char S.UP_map\<^sub>0_obj by auto
moreover have "S.inv (S.UP f \<star>\<^sub>S UP.\<Psi> ?a) = S.UP f \<star>\<^sub>S S.inv (UP.\<Psi> ?a)"
using assms a UP.\<Psi>_char S.UP_map\<^sub>0_obj by auto
ultimately show ?thesis
using assms 1 UP.\<Psi>_char UP.\<Phi>_components_are_iso
S.invert_side_of_triangle(2)
[of "S.UP f" "(\<xi>' \<star>\<^sub>S S.UP f) \<cdot>\<^sub>S S.\<a>' (S.UP f) (S.UP g) (S.UP f) \<cdot>\<^sub>S
(S.UP f \<star>\<^sub>S S.inv (S.\<Phi> (g, f)) \<cdot>\<^sub>S S.UP \<eta>)"
"S.UP f \<star>\<^sub>S UP.\<Psi> ?a"]
by presburger
qed
also have "... = S.UP f \<star>\<^sub>S S.inv (UP.\<Psi> ?a)"
proof -
have "\<guillemotleft>S.UP f \<star>\<^sub>S S.inv (UP.\<Psi> ?a) :
S.UP f \<star>\<^sub>S S.UP ?a \<Rightarrow>\<^sub>S S.UP f \<star>\<^sub>S UP.map\<^sub>0 ?a\<guillemotright>"
using assms ide_f f_in_hhom UP.\<Psi>_char [of ?a] S.inv_in_hom
apply (intro S.hcomp_in_vhom)
apply auto[1]
apply blast
by auto
moreover have "S.UP f \<star>\<^sub>S UP.map\<^sub>0 ?a = S.UP f"
using a S.hcomp_arr_obj S.UP_map\<^sub>0_obj by auto
finally show ?thesis
using S.comp_cod_arr by blast
qed
finally show ?thesis by auto
qed
thus ?thesis
using S.comp_assoc by simp
qed
finally show ?thesis by simp
qed
thus ?thesis
using S.comp_assoc by simp
qed
also have "... = S.UP \<l>\<^sup>-\<^sup>1[f] \<cdot>\<^sub>S S.UP \<r>[f]"
proof -
have "S.\<Phi> (trg f, f) \<cdot>\<^sub>S (UP.\<Psi> ?b \<star>\<^sub>S S.UP f) = S.UP \<l>\<^sup>-\<^sup>1[f]"
proof -
have "S.UP f = S.UP \<l>[f] \<cdot>\<^sub>S S.\<Phi> (trg f, f) \<cdot>\<^sub>S (UP.\<Psi> (trg f) \<star>\<^sub>S S.UP f)"
using UP.lunit_coherence iso_lunit S.strict_lunit by simp
thus ?thesis
using UP.image_of_unitor(3) ide_f by presburger
qed
moreover have "(S.UP f \<star>\<^sub>S S.inv (UP.\<Psi> (src f))) \<cdot>\<^sub>S S.inv (S.\<Phi> (f, src f)) =
S.UP \<r>[f]"
proof -
have "S.UP \<r>[f] \<cdot>\<^sub>S S.\<Phi> (f, src f) \<cdot>\<^sub>S (S.UP f \<star>\<^sub>S UP.\<Psi> (src f)) = S.UP f"
using UP.runit_coherence [of f] S.strict_runit by simp
moreover have "S.iso (S.\<Phi> (f, src f) \<cdot>\<^sub>S (S.UP f \<star>\<^sub>S UP.\<Psi> (src f)))"
using UP.\<Psi>_char UP.\<Phi>_components_are_iso VV.arr_char S.UP_map\<^sub>0_obj
apply (intro S.isos_compose S.seqI)
by simp_all
ultimately have
"S.UP \<r>[f] = S.UP f \<cdot>\<^sub>S S.inv (S.\<Phi> (f, src f) \<cdot>\<^sub>S (S.UP f \<star>\<^sub>S UP.\<Psi> (src f)))"
using S.invert_side_of_triangle(2)
[of "S.UP f" "S.UP \<r>[f]" "S.\<Phi> (f, src f) \<cdot>\<^sub>S (S.UP f \<star>\<^sub>S UP.\<Psi> (src f))"]
ideD(1) ide_f by blast
thus ?thesis
using ide_f UP.image_of_unitor(2) [of f] by argo
qed
ultimately show ?thesis
using S.comp_assoc by simp
qed
also have "... = S.UP (\<l>\<^sup>-\<^sup>1[f] \<cdot> \<r>[f])"
by simp
finally have "S.UP ((\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>)) = S.UP (\<l>\<^sup>-\<^sup>1[f] \<cdot> \<r>[f])"
by simp
moreover have "par ((\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>)) (\<l>\<^sup>-\<^sup>1[f] \<cdot> \<r>[f])"
proof -
have "\<guillemotleft>(\<epsilon> \<star> f) \<cdot> \<a>\<^sup>-\<^sup>1[f, g, f] \<cdot> (f \<star> \<eta>) : f \<star> src f \<Rightarrow> trg f \<star> f\<guillemotright>"
using E''.triangle_in_hom(1) by simp
moreover have "\<guillemotleft>\<l>\<^sup>-\<^sup>1[f] \<cdot> \<r>[f] : f \<star> src f \<Rightarrow> trg f \<star> f\<guillemotright>" by auto
ultimately show ?thesis
by (metis in_homE)
qed
ultimately show ?thesis
using UP.is_faithful by blast
qed
thus "(g \<star> \<epsilon>) \<cdot> \<a>[g, f, g] \<cdot> (\<eta> \<star> g) = \<r>\<^sup>-\<^sup>1[g] \<cdot> \<l>[g]"
using E''.triangle_left_implies_right by simp
qed
show ?thesis
using E''.adjoint_equivalence_in_bicategory_axioms E''.adjunction_in_bicategory_axioms
adjunction_unit_determines_counit adjoint_equivalence_in_bicategory_def
by metis
qed
lemma equivalence_map_extends_to_adjoint_equivalence:
assumes "equivalence_map f"
shows "\<exists>g \<eta> \<epsilon>. adjoint_equivalence_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>"
proof -
obtain g \<eta> \<epsilon>' where E: "equivalence_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>'"
using assms equivalence_map_def by auto
interpret E: equivalence_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>'
using E by auto
obtain \<epsilon> where A: "adjoint_equivalence_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>"
using assms equivalence_refines_to_adjoint_equivalence [of f g \<eta>]
E.antipar E.unit_is_iso E.unit_in_hom by auto
show ?thesis
using E A by blast
qed
end
subsection "Uniqueness of Adjoints"
text \<open>
Left and right adjoints determine each other up to isomorphism.
\<close>
context strict_bicategory
begin
lemma left_adjoint_determines_right_up_to_iso:
assumes "adjoint_pair f g" and "adjoint_pair f g'"
shows "g \<cong> g'"
proof -
obtain \<eta> \<epsilon> where A: "adjunction_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>"
using assms adjoint_pair_def by auto
interpret A: adjunction_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>
using A by auto
interpret A: adjunction_in_strict_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon> ..
obtain \<eta>' \<epsilon>' where A': "adjunction_in_bicategory V H \<a> \<i> src trg f g' \<eta>' \<epsilon>'"
using assms adjoint_pair_def by auto
interpret A': adjunction_in_bicategory V H \<a> \<i> src trg f g' \<eta>' \<epsilon>'
using A' by auto
interpret A': adjunction_in_strict_bicategory V H \<a> \<i> src trg f g' \<eta>' \<epsilon>' ..
let ?\<phi> = "A'.trnl\<^sub>\<eta> g \<epsilon>"
have "\<guillemotleft>?\<phi>: g \<Rightarrow> g'\<guillemotright>"
using A'.trnl\<^sub>\<eta>_eq A'.adjoint_transpose_left(1) [of "trg f" g] A.antipar A'.antipar
hcomp_arr_obj
by auto
moreover have "iso ?\<phi>"
proof (intro isoI)
let ?\<psi> = "A.trnl\<^sub>\<eta> g' \<epsilon>'"
show "inverse_arrows ?\<phi> ?\<psi>"
proof
show "ide (?\<phi> \<cdot> ?\<psi>)"
proof -
have 1: "ide (trg f) \<and> trg (trg f) = trg f"
by simp
have "?\<phi> \<cdot> ?\<psi> = (g' \<star> \<epsilon>) \<cdot> ((\<eta>' \<star> g) \<cdot> (g \<star> \<epsilon>')) \<cdot> (\<eta> \<star> g')"
using 1 A.antipar A'.antipar A.trnl\<^sub>\<eta>_eq [of "trg f" g' \<epsilon>']
A'.trnl\<^sub>\<eta>_eq [of "trg f" g \<epsilon>] comp_assoc A.counit_in_hom A'.counit_in_hom
by simp
also have "... = ((g' \<star> \<epsilon>) \<cdot> (g' \<star> f \<star> g \<star> \<epsilon>')) \<cdot> ((\<eta>' \<star> g \<star> f \<star> g') \<cdot> (\<eta> \<star> g'))"
proof -
have "(\<eta>' \<star> g) \<cdot> (g \<star> \<epsilon>') = (\<eta>' \<star> g \<star> trg f) \<cdot> (src f \<star> g \<star> \<epsilon>')"
using A.antipar A'.antipar hcomp_arr_obj hcomp_obj_arr [of "src f" "g \<star> \<epsilon>'"]
hseqI'
by (metis A'.counit_simps(1) A'.counit_simps(5) A.ide_right ideD(1)
obj_trg trg_hcomp)
also have "... = \<eta>' \<star> g \<star> \<epsilon>'"
using A.antipar A'.antipar interchange [of \<eta>' "src f" "g \<star> trg f" "g \<star> \<epsilon>'"]
whisker_left comp_arr_dom comp_cod_arr
by simp
also have "... = ((g' \<star> f) \<star> g \<star> \<epsilon>') \<cdot> (\<eta>' \<star> g \<star> (f \<star> g'))"
using A.ide_left A.ide_right A'.ide_right A.antipar A'.antipar
A'.unit_in_hom A'.counit_in_hom interchange whisker_left
comp_arr_dom comp_cod_arr
by (metis A'.counit_simps(1-2,5) A'.unit_simps(1,3) hseqI' ide_char)
also have "... = (g' \<star> f \<star> g \<star> \<epsilon>') \<cdot> (\<eta>' \<star> g \<star> f \<star> g')"
using hcomp_assoc by simp
finally show ?thesis
using comp_assoc by simp
qed
also have "... = (g' \<star> \<epsilon>') \<cdot> ((g' \<star> (\<epsilon> \<star> f) \<star> g') \<cdot> (g' \<star> (f \<star> \<eta>) \<star> g')) \<cdot> (\<eta>' \<star> g')"
proof -
have "(g' \<star> \<epsilon>) \<cdot> (g' \<star> f \<star> g \<star> \<epsilon>') = (g' \<star> \<epsilon>') \<cdot> (g' \<star> \<epsilon> \<star> f \<star> g')"
proof -
have "(g' \<star> \<epsilon>) \<cdot> (g' \<star> f \<star> g \<star> \<epsilon>') = g' \<star> \<epsilon> \<star> \<epsilon>'"
proof -
have "\<epsilon> \<cdot> (f \<star> g \<star> \<epsilon>') = \<epsilon> \<star> \<epsilon>'"
using A.ide_left A.ide_right A.antipar A'.antipar hcomp_arr_obj comp_arr_dom
comp_cod_arr interchange obj_src trg_src
by (metis A'.counit_simps(1,3) A.counit_simps(1-2,4) hcomp_assoc)
thus ?thesis
using A.antipar A'.antipar whisker_left [of g' \<epsilon> "f \<star> g \<star> \<epsilon>'"]
by (simp add: hcomp_assoc)
qed
also have "... = (g' \<star> \<epsilon>') \<cdot> (g' \<star> \<epsilon> \<star> f \<star> g')"
proof -
have "\<epsilon> \<star> \<epsilon>' = \<epsilon>' \<cdot> (\<epsilon> \<star> f \<star> g')"
using A.ide_left A.ide_right A'.ide_right A.antipar A'.antipar
hcomp_obj_arr hcomp_arr_obj comp_arr_dom comp_cod_arr interchange
obj_src trg_src
by (metis A'.counit_simps(1-2,5) A.counit_simps(1,3-4) arr_cod
not_arr_null seq_if_composable)
thus ?thesis
using A.ide_left A.ide_right A'.ide_right A.antipar A'.antipar
whisker_left
by (metis A'.counit_simps(1,5) A.counit_simps(1,4) hseqI')
qed
finally show ?thesis by simp
qed
moreover have "(\<eta>' \<star> g \<star> f \<star> g') \<cdot> (\<eta> \<star> g') = (g' \<star> f \<star> \<eta> \<star> g') \<cdot> (\<eta>' \<star> g')"
proof -
have "(\<eta>' \<star> g \<star> f \<star> g') \<cdot> (\<eta> \<star> g') = \<eta>' \<star> \<eta> \<star> g'"
proof -
have "(\<eta>' \<star> g \<star> f) \<cdot> \<eta> = \<eta>' \<star> \<eta>"
using A.ide_left A.ide_right A.antipar A'.antipar A'.unit_in_hom hcomp_arr_obj
interchange comp_arr_dom comp_cod_arr
by (metis A'.unit_simps(1-2,4) A.unit_simps(1,3,5) hcomp_obj_arr obj_trg)
thus ?thesis
using A.antipar A'.antipar whisker_right [of g' "\<eta>' \<star> g \<star> f" \<eta>]
by (simp add: hcomp_assoc)
qed
also have "... = (g' \<star> f \<star> \<eta> \<star> g') \<cdot> (\<eta>' \<star> g')"
proof -
have "\<eta>' \<star> \<eta> = (g' \<star> f \<star> \<eta>) \<cdot> \<eta>'"
using A.ide_left A.ide_right A.antipar A'.antipar A'.unit_in_hom hcomp_arr_obj
comp_arr_dom comp_cod_arr hcomp_assoc interchange
by (metis A'.unit_simps(1,3-4) A.unit_simps(1-2) obj_src)
thus ?thesis
using A.ide_left A.ide_right A.antipar A'.antipar A'.unit_in_hom hcomp_arr_obj
whisker_right [of g' "g' \<star> f \<star> \<eta>" \<eta>']
by (metis A'.ide_right A'.unit_simps(1,4) A.unit_simps(1,5)
hseqI' hcomp_assoc)
qed
finally show ?thesis by simp
qed
ultimately show ?thesis
using comp_assoc hcomp_assoc by simp
qed
also have "... = (g' \<star> \<epsilon>') \<cdot> ((g' \<star> f) \<star> g') \<cdot> (\<eta>' \<star> g')"
proof -
have "(g' \<star> (\<epsilon> \<star> f) \<star> g') \<cdot> (g' \<star> (f \<star> \<eta>) \<star> g') = g' \<star> f \<star> g'"
proof -
have "(g' \<star> (\<epsilon> \<star> f) \<star> g') \<cdot> (g' \<star> (f \<star> \<eta>) \<star> g') =
g' \<star> ((\<epsilon> \<star> f) \<star> g') \<cdot> ((f \<star> \<eta>) \<star> g')"
using A.ide_left A.ide_right A.antipar A'.antipar A'.unit_in_hom
A'.counit_in_hom whisker_left [of g' "(\<epsilon> \<star> f) \<star> g'" "(f \<star> \<eta>) \<star> g'"]
by (metis A'.ide_right A.triangle_left hseqI' ideD(1) whisker_right)
also have "... = g' \<star> (\<epsilon> \<star> f) \<cdot> (f \<star> \<eta>) \<star> g'"
using A.antipar A'.antipar whisker_right [of g' "\<epsilon> \<star> f" "f \<star> \<eta>"]
by (simp add: A.triangle_left)
also have "... = g' \<star> f \<star> g'"
using A.triangle_left by simp
finally show ?thesis by simp
qed
thus ?thesis
using hcomp_assoc by simp
qed
also have "... = (g' \<star> \<epsilon>') \<cdot> (\<eta>' \<star> g')"
using A.antipar A'.antipar A'.unit_in_hom A'.counit_in_hom comp_cod_arr
by (metis A'.ide_right A'.triangle_in_hom(2) A.ide_left arrI assoc_is_natural_2
ide_char seqE strict_assoc)
also have "... = g'"
using A'.triangle_right by simp
finally have "?\<phi> \<cdot> ?\<psi> = g'" by simp
thus ?thesis by simp
qed
show "ide (?\<psi> \<cdot> ?\<phi>)"
proof -
have 1: "ide (trg f) \<and> trg (trg f) = trg f"
by simp
have "?\<psi> \<cdot> ?\<phi> = (g \<star> \<epsilon>') \<cdot> ((\<eta> \<star> g') \<cdot> (g' \<star> \<epsilon>)) \<cdot> (\<eta>' \<star> g)"
using A.antipar A'.antipar A'.trnl\<^sub>\<eta>_eq [of "trg f" g \<epsilon>]
A.trnl\<^sub>\<eta>_eq [of "trg f" g' \<epsilon>'] comp_assoc A.counit_in_hom A'.counit_in_hom
by simp
also have "... = ((g \<star> \<epsilon>') \<cdot> (g \<star> f \<star> g' \<star> \<epsilon>)) \<cdot> ((\<eta> \<star> g' \<star> f \<star> g) \<cdot> (\<eta>' \<star> g))"
proof -
have "(\<eta> \<star> g') \<cdot> (g' \<star> \<epsilon>) = (\<eta> \<star> g' \<star> trg f) \<cdot> (src f \<star> g' \<star> \<epsilon>)"
using A.antipar A'.antipar hcomp_arr_obj hcomp_obj_arr hseqI'
by (metis A'.ide_right A.unit_simps(1,4) hcomp_assoc hcomp_obj_arr
ideD(1) obj_src)
also have "... = \<eta> \<star> g' \<star> \<epsilon>"
using A.ide_left A.ide_right A'.ide_right A.antipar A'.antipar A.unit_in_hom
A.counit_in_hom interchange
by (metis "1" A.counit_simps(5) A.unit_simps(4) hseqI' ide_def ide_in_hom(2)
not_arr_null seqI' src.preserves_ide)
also have "... = ((g \<star> f) \<star> g' \<star> \<epsilon>) \<cdot> (\<eta> \<star> g' \<star> (f \<star> g))"
using A'.ide_right A'.antipar interchange ide_char comp_arr_dom comp_cod_arr hseqI'
by (metis A.counit_simps(1-2,5) A.unit_simps(1,3))
also have "... = (g \<star> f \<star> g' \<star> \<epsilon>) \<cdot> (\<eta> \<star> g' \<star> f \<star> g)"
using hcomp_assoc by simp
finally show ?thesis
using comp_assoc by simp
qed
also have "... = (g \<star> \<epsilon>) \<cdot> ((g \<star> (\<epsilon>' \<star> f) \<star> g) \<cdot> (g \<star> (f \<star> \<eta>') \<star> g)) \<cdot> (\<eta> \<star> g)"
proof -
have "(g \<star> \<epsilon>') \<cdot> (g \<star> f \<star> g' \<star> \<epsilon>) = (g \<star> \<epsilon>) \<cdot> (g \<star> \<epsilon>' \<star> f \<star> g)"
proof -
have "(g \<star> \<epsilon>') \<cdot> (g \<star> f \<star> g' \<star> \<epsilon>) = g \<star> \<epsilon>' \<star> \<epsilon>"
proof -
have "\<epsilon>' \<cdot> (f \<star> g' \<star> \<epsilon>) = \<epsilon>' \<star> \<epsilon>"
using A.ide_left A.ide_right A'.ide_right A.antipar A'.antipar hcomp_arr_obj
comp_arr_dom comp_cod_arr interchange obj_src trg_src hcomp_assoc
by (metis A.counit_simps(1,3) A'.counit_simps(1-2,4))
thus ?thesis
using A.antipar A'.antipar whisker_left [of g \<epsilon>' "f \<star> g' \<star> \<epsilon>"]
by (simp add: hcomp_assoc)
qed
also have "... = (g \<star> \<epsilon>) \<cdot> (g \<star> \<epsilon>' \<star> f \<star> g)"
proof -
have "\<epsilon>' \<star> \<epsilon> = \<epsilon> \<cdot> (\<epsilon>' \<star> f \<star> g)"
using A.ide_left A.ide_right A'.ide_right A.antipar A'.antipar hcomp_obj_arr
hcomp_arr_obj comp_arr_dom comp_cod_arr interchange obj_src trg_src
by (metis A.counit_simps(1-2,5) A'.counit_simps(1,3-4)
arr_cod not_arr_null seq_if_composable)
thus ?thesis
using A.ide_left A.ide_right A'.ide_right A.antipar A'.antipar
whisker_left
by (metis A.counit_simps(1,5) A'.counit_simps(1,4) hseqI')
qed
finally show ?thesis by simp
qed
moreover have "(\<eta> \<star> g' \<star> f \<star> g) \<cdot> (\<eta>' \<star> g) = (g \<star> f \<star> \<eta>' \<star> g) \<cdot> (\<eta> \<star> g)"
proof -
have "(\<eta> \<star> g' \<star> f \<star> g) \<cdot> (\<eta>' \<star> g) = \<eta> \<star> \<eta>' \<star> g"
proof -
have "(\<eta> \<star> g' \<star> f) \<cdot> \<eta>' = \<eta> \<star> \<eta>'"
using A.antipar A'.antipar A.unit_in_hom hcomp_arr_obj
comp_arr_dom comp_cod_arr hcomp_obj_arr interchange
by (metis A'.unit_simps(1,3,5) A.unit_simps(1-2,4) obj_trg)
thus ?thesis
using A.antipar A'.antipar whisker_right [of g "\<eta> \<star> g' \<star> f" \<eta>']
by (simp add: hcomp_assoc)
qed
also have "... = ((g \<star> f) \<star> \<eta>' \<star> g) \<cdot> (\<eta> \<star> src f \<star> g)"
using A.ide_left A.ide_right A'.ide_right A.antipar A'.antipar A.unit_in_hom
A'.unit_in_hom comp_arr_dom comp_cod_arr interchange
by (metis A'.unit_simps(1-2,4) A.unit_simps(1,3) hseqI' ide_char)
also have "... = (g \<star> f \<star> \<eta>' \<star> g) \<cdot> (\<eta> \<star> g)"
using A.antipar A'.antipar hcomp_assoc
by (simp add: hcomp_obj_arr)
finally show ?thesis by simp
qed
ultimately show ?thesis
using comp_assoc hcomp_assoc by simp
qed
also have "... = (g \<star> \<epsilon>) \<cdot> ((g \<star> f) \<star> g) \<cdot> (\<eta> \<star> g)"
proof -
have "(g \<star> (\<epsilon>' \<star> f) \<star> g) \<cdot> (g \<star> (f \<star> \<eta>') \<star> g) = g \<star> f \<star> g"
proof -
have "(g \<star> (\<epsilon>' \<star> f) \<star> g) \<cdot> (g \<star> (f \<star> \<eta>') \<star> g) =
g \<star> ((\<epsilon>' \<star> f) \<star> g) \<cdot> ((f \<star> \<eta>') \<star> g)"
using A.ide_left A.ide_right A'.ide_right A.antipar A'.antipar A.unit_in_hom
A.counit_in_hom whisker_left
by (metis A'.triangle_left hseqI' ideD(1) whisker_right)
also have "... = g \<star> (\<epsilon>' \<star> f) \<cdot> (f \<star> \<eta>') \<star> g"
using A.antipar A'.antipar whisker_right [of g "\<epsilon>' \<star> f" "f \<star> \<eta>'"]
by (simp add: A'.triangle_left)
also have "... = g \<star> f \<star> g"
using A'.triangle_left by simp
finally show ?thesis by simp
qed
thus ?thesis
using hcomp_assoc by simp
qed
also have "... = (g \<star> \<epsilon>) \<cdot> (\<eta> \<star> g)"
using A.antipar A'.antipar A.unit_in_hom A.counit_in_hom comp_cod_arr
by (metis A.ide_left A.ide_right A.triangle_in_hom(2) arrI assoc_is_natural_2
ide_char seqE strict_assoc)
also have "... = g"
using A.triangle_right by simp
finally have "?\<psi> \<cdot> ?\<phi> = g" by simp
moreover have "ide g"
by simp
ultimately show ?thesis by simp
qed
qed
qed
ultimately show ?thesis
using isomorphic_def by auto
qed
end
text \<open>
We now use strictification to extend to arbitrary bicategories.
\<close>
context bicategory
begin
interpretation S: strictified_bicategory V H \<a> \<i> src trg ..
notation S.vcomp (infixr "\<cdot>\<^sub>S" 55)
notation S.hcomp (infixr "\<star>\<^sub>S" 53)
notation S.in_hom ("\<guillemotleft>_ : _ \<Rightarrow>\<^sub>S _\<guillemotright>")
notation S.in_hhom ("\<guillemotleft>_ : _ \<rightarrow>\<^sub>S _\<guillemotright>")
interpretation UP: equivalence_pseudofunctor V H \<a> \<i> src trg
S.vcomp S.hcomp S.\<a> S.\<i> S.src S.trg S.UP S.\<Phi>
using S.UP_is_equivalence_pseudofunctor by auto
interpretation UP: pseudofunctor_into_strict_bicategory V H \<a> \<i> src trg
S.vcomp S.hcomp S.\<a> S.\<i> S.src S.trg S.UP S.\<Phi>
..
interpretation UP: fully_faithful_functor V S.vcomp S.UP
using S.UP_is_fully_faithful_functor by auto
lemma left_adjoint_determines_right_up_to_iso:
assumes "adjoint_pair f g" and "adjoint_pair f g'"
shows "g \<cong> g'"
proof -
have 0: "ide g \<and> ide g'"
using assms adjoint_pair_def adjunction_in_bicategory_def
adjunction_data_in_bicategory_def adjunction_data_in_bicategory_axioms_def
by metis
have 1: "S.adjoint_pair (S.UP f) (S.UP g) \<and> S.adjoint_pair (S.UP f) (S.UP g')"
using assms UP.preserves_adjoint_pair by simp
obtain \<nu> where \<nu>: "\<guillemotleft>\<nu> : S.UP g \<Rightarrow>\<^sub>S S.UP g'\<guillemotright> \<and> S.iso \<nu>"
using 1 S.left_adjoint_determines_right_up_to_iso S.isomorphic_def by blast
obtain \<mu> where \<mu>: "\<guillemotleft>\<mu> : g \<Rightarrow> g'\<guillemotright> \<and> S.UP \<mu> = \<nu>"
using 0 \<nu> UP.is_full [of g' g \<nu>] by auto
have "\<guillemotleft>\<mu> : g \<Rightarrow> g'\<guillemotright> \<and> iso \<mu>"
using \<mu> \<nu> UP.reflects_iso by auto
thus ?thesis
using isomorphic_def by auto
qed
lemma right_adjoint_determines_left_up_to_iso:
assumes "adjoint_pair f g" and "adjoint_pair f' g"
shows "f \<cong> f'"
proof -
obtain \<eta> \<epsilon> where A: "adjunction_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>"
using assms adjoint_pair_def by auto
interpret A: adjunction_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>
using A by auto
obtain \<eta>' \<epsilon>' where A': "adjunction_in_bicategory V H \<a> \<i> src trg f' g \<eta>' \<epsilon>'"
using assms adjoint_pair_def by auto
interpret A': adjunction_in_bicategory V H \<a> \<i> src trg f' g \<eta>' \<epsilon>'
using A' by auto
interpret Cop: op_bicategory V H \<a> \<i> src trg ..
interpret Aop: adjunction_in_bicategory V Cop.H Cop.\<a> \<i> Cop.src Cop.trg g f \<eta> \<epsilon>
using A.antipar A.triangle_left A.triangle_right Cop.assoc_ide_simp
Cop.lunit_ide_simp Cop.runit_ide_simp
by (unfold_locales, auto)
interpret Aop': adjunction_in_bicategory V Cop.H Cop.\<a> \<i> Cop.src Cop.trg g f' \<eta>' \<epsilon>'
using A'.antipar A'.triangle_left A'.triangle_right Cop.assoc_ide_simp
Cop.lunit_ide_simp Cop.runit_ide_simp
by (unfold_locales, auto)
show ?thesis
using Aop.adjunction_in_bicategory_axioms Aop'.adjunction_in_bicategory_axioms
Cop.left_adjoint_determines_right_up_to_iso Cop.adjoint_pair_def
by blast
qed
end
context chosen_right_adjoints
begin
lemma isomorphic_to_left_adjoint_implies_isomorphic_right_adjoint:
assumes "is_left_adjoint f" and "f \<cong> h"
shows "f\<^sup>* \<cong> h\<^sup>*"
proof -
have 1: "adjoint_pair f f\<^sup>*"
using assms left_adjoint_extends_to_adjoint_pair by blast
moreover have "adjoint_pair h f\<^sup>*"
using assms 1 adjoint_pair_preserved_by_iso isomorphic_symmetric isomorphic_reflexive
by (meson isomorphic_def right_adjoint_simps(1))
thus ?thesis
using left_adjoint_determines_right_up_to_iso left_adjoint_extends_to_adjoint_pair
by blast
qed
end
context bicategory
begin
lemma equivalence_is_adjoint:
assumes "equivalence_map f"
shows equivalence_is_left_adjoint: "is_left_adjoint f"
and equivalence_is_right_adjoint: "is_right_adjoint f"
proof -
obtain g \<eta> \<epsilon> where fg: "adjoint_equivalence_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>"
using assms equivalence_map_extends_to_adjoint_equivalence by blast
interpret fg: adjoint_equivalence_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>
using fg by simp
interpret gf: adjoint_equivalence_in_bicategory V H \<a> \<i> src trg g f \<open>inv \<epsilon>\<close> \<open>inv \<eta>\<close>
using fg.dual_adjoint_equivalence by simp
show "is_left_adjoint f"
using fg.adjunction_in_bicategory_axioms adjoint_pair_def by auto
show "is_right_adjoint f"
using gf.adjunction_in_bicategory_axioms adjoint_pair_def by auto
qed
lemma right_adjoint_to_equivalence_is_equivalence:
assumes "equivalence_map f" and "adjoint_pair f g"
shows "equivalence_map g"
proof -
obtain \<eta> \<epsilon> where fg: "adjunction_in_bicategory (\<cdot>) (\<star>) \<a> \<i> src trg f g \<eta> \<epsilon>"
using assms adjoint_pair_def by auto
interpret fg: adjunction_in_bicategory \<open>(\<cdot>)\<close> \<open>(\<star>)\<close> \<a> \<i> src trg f g \<eta> \<epsilon>
using fg by simp
obtain g' \<phi> \<psi> where fg': "equivalence_in_bicategory (\<cdot>) (\<star>) \<a> \<i> src trg f g' \<phi> \<psi>"
using assms equivalence_map_def by auto
interpret fg': equivalence_in_bicategory \<open>(\<cdot>)\<close> \<open>(\<star>)\<close> \<a> \<i> src trg f g' \<phi> \<psi>
using fg' by auto
obtain \<psi>' where \<psi>': "adjoint_equivalence_in_bicategory (\<cdot>) (\<star>) \<a> \<i> src trg f g' \<phi> \<psi>'"
using assms equivalence_refines_to_adjoint_equivalence [of f g' \<phi>]
fg'.antipar fg'.unit_in_hom fg'.unit_is_iso
by auto
interpret \<psi>': adjoint_equivalence_in_bicategory \<open>(\<cdot>)\<close> \<open>(\<star>)\<close> \<a> \<i> src trg f g' \<phi> \<psi>'
using \<psi>' by simp
have 1: "g \<cong> g'"
using fg.adjunction_in_bicategory_axioms \<psi>'.adjunction_in_bicategory_axioms
left_adjoint_determines_right_up_to_iso adjoint_pair_def
by blast
obtain \<gamma> where \<gamma>: "\<guillemotleft>\<gamma> : g' \<Rightarrow> g\<guillemotright> \<and> iso \<gamma>"
using 1 isomorphic_def isomorphic_symmetric by metis
have "equivalence_in_bicategory (\<cdot>) (\<star>) \<a> \<i> src trg f g ((\<gamma> \<star> f) \<cdot> \<phi>) (\<psi>' \<cdot> (f \<star> inv \<gamma>))"
using \<gamma> equivalence_preserved_by_iso_right \<psi>'.equivalence_in_bicategory_axioms by simp
hence "equivalence_pair f g"
using equivalence_pair_def by auto
thus ?thesis
using equivalence_pair_symmetric equivalence_pair_def equivalence_map_def by blast
qed
lemma left_adjoint_to_equivalence_is_equivalence:
assumes "equivalence_map f" and "adjoint_pair g f"
shows "equivalence_map g"
proof -
obtain \<eta> \<epsilon> where gf: "adjunction_in_bicategory (\<cdot>) (\<star>) \<a> \<i> src trg g f \<eta> \<epsilon>"
using assms adjoint_pair_def by auto
interpret gf: adjunction_in_bicategory \<open>(\<cdot>)\<close> \<open>(\<star>)\<close> \<a> \<i> src trg g f \<eta> \<epsilon>
using gf by simp
obtain g' where 1: "equivalence_pair g' f"
using assms equivalence_map_def equivalence_pair_def equivalence_pair_symmetric
by blast
obtain \<phi> \<psi> where g'f: "equivalence_in_bicategory (\<cdot>) (\<star>) \<a> \<i> src trg g' f \<phi> \<psi>"
using assms 1 equivalence_pair_def by auto
interpret g'f: equivalence_in_bicategory \<open>(\<cdot>)\<close> \<open>(\<star>)\<close> \<a> \<i> src trg g' f \<phi> \<psi>
using g'f by auto
obtain \<psi>' where \<psi>': "adjoint_equivalence_in_bicategory (\<cdot>) (\<star>) \<a> \<i> src trg g' f \<phi> \<psi>'"
using assms 1 equivalence_refines_to_adjoint_equivalence [of g' f \<phi>]
g'f.antipar g'f.unit_in_hom g'f.unit_is_iso equivalence_pair_def
equivalence_map_def
by auto
interpret \<psi>': adjoint_equivalence_in_bicategory \<open>(\<cdot>)\<close> \<open>(\<star>)\<close> \<a> \<i> src trg g' f \<phi> \<psi>'
using \<psi>' by simp
have 1: "g \<cong> g'"
using gf.adjunction_in_bicategory_axioms \<psi>'.adjunction_in_bicategory_axioms
right_adjoint_determines_left_up_to_iso adjoint_pair_def
by blast
obtain \<gamma> where \<gamma>: "\<guillemotleft>\<gamma> : g' \<Rightarrow> g\<guillemotright> \<and> iso \<gamma>"
using 1 isomorphic_def isomorphic_symmetric by metis
have "equivalence_in_bicategory (\<cdot>) (\<star>) \<a> \<i> src trg g f ((f \<star> \<gamma>) \<cdot> \<phi>) (\<psi>' \<cdot> (inv \<gamma> \<star> f))"
using \<gamma> equivalence_preserved_by_iso_left \<psi>'.equivalence_in_bicategory_axioms by simp
hence "equivalence_pair g f"
using equivalence_pair_def by auto
thus ?thesis
using equivalence_pair_symmetric equivalence_pair_def equivalence_map_def by blast
qed
lemma equivalence_pair_is_adjoint_pair:
assumes "equivalence_pair f g"
shows "adjoint_pair f g"
proof -
obtain \<eta> \<epsilon> where \<eta>\<epsilon>: "equivalence_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>"
using assms equivalence_pair_def by auto
interpret \<eta>\<epsilon>: equivalence_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>
using \<eta>\<epsilon> by auto
obtain \<epsilon>' where \<eta>\<epsilon>': "adjoint_equivalence_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>'"
using \<eta>\<epsilon> equivalence_map_def \<eta>\<epsilon>.antipar \<eta>\<epsilon>.unit_in_hom \<eta>\<epsilon>.unit_is_iso
\<eta>\<epsilon>.ide_right equivalence_refines_to_adjoint_equivalence [of f g \<eta>]
by force
interpret \<eta>\<epsilon>': adjoint_equivalence_in_bicategory V H \<a> \<i> src trg f g \<eta> \<epsilon>'
using \<eta>\<epsilon>' by auto
show ?thesis
using \<eta>\<epsilon>' adjoint_pair_def \<eta>\<epsilon>'.adjunction_in_bicategory_axioms by auto
qed
lemma equivalence_pair_isomorphic_right:
assumes "equivalence_pair f g"
shows "equivalence_pair f g' \<longleftrightarrow> g \<cong> g'"
proof
show "g \<cong> g' \<Longrightarrow> equivalence_pair f g'"
using assms equivalence_pair_def isomorphic_def equivalence_preserved_by_iso_right
by metis
assume g': "equivalence_pair f g'"
show "g \<cong> g'"
using assms g' equivalence_pair_is_adjoint_pair left_adjoint_determines_right_up_to_iso
by blast
qed
lemma equivalence_pair_isomorphic_left:
assumes "equivalence_pair f g"
shows "equivalence_pair f' g \<longleftrightarrow> f \<cong> f'"
proof
show "f \<cong> f' \<Longrightarrow> equivalence_pair f' g"
using assms equivalence_pair_def isomorphic_def equivalence_preserved_by_iso_left
by metis
assume f': "equivalence_pair f' g"
show "f \<cong> f'"
using assms f' equivalence_pair_is_adjoint_pair right_adjoint_determines_left_up_to_iso
by blast
qed
end
end
|
Formal statement is: lemma cmult_in_bigo_iff [simp]: "(\<lambda>x. c * f x) \<in> O[F](g) \<longleftrightarrow> c = 0 \<or> f \<in> O[F](g)" and cmult_in_bigo_iff' [simp]: "(\<lambda>x. f x * c) \<in> O[F](g) \<longleftrightarrow> c = 0 \<or> f \<in> O[F](g)" and cmult_in_smallo_iff [simp]: "(\<lambda>x. c * f x) \<in> o[F](g) \<longleftrightarrow> c = 0 \<or> f \<in> o[F](g)" and cmult_in_smallo_iff' [simp]: "(\<lambda>x. f x * c) \<in> o[F](g) \<longleftrightarrow> c = 0 \<or> f \<in> o[F](g)" Informal statement is: If $f(x) = cg(x)$ for some constant $c$, then $f(x)$ is $O(g(x))$ if and only if $c = 0$ or $f(x)$ is $O(g(x))$. |
using GAP_pkg_datastructures
using Test
import GAP_pkg_datastructures
println("TODO")
|
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
module FokkerPlanck.FourierSeriesGPU where
import Control.Monad as M
import Control.Monad.Parallel as MP
import qualified Data.Array.Accelerate as A
import qualified Data.Array.Accelerate.Data.Complex as A
import Data.Array.Accelerate.LLVM.PTX
import Data.Complex as C
import Data.DList as DL
import Data.List as L
import Data.Vector.Unboxed as VU
import FokkerPlanck.Analytic
import FokkerPlanck.BrownianMotion (Particle (..),
generateRandomNumber,
moveParticle, scalePlus,
thetaPlus)
import FokkerPlanck.FourierSeries
import FokkerPlanck.GPUKernel
import FokkerPlanck.Histogram
import GHC.Float
import Statistics.Distribution
import Statistics.Distribution.Normal
import System.Random.MWC
import Utils.Parallel
import Debug.Trace
import Utils.List
{-# INLINE computeFourierCoefficientsGPU #-}
computeFourierCoefficientsGPU ::
[Double]
-> [Double]
-> [Double]
-> [Double]
-> Acc (A.Vector (Float, Float, Float, Float))
-> A.Exp Float
-> A.Exp Float
-> PTX
-> [DList Particle]
-> Histogram (C.Complex Double)
computeFourierCoefficientsGPU !phiFreqs !rhoFreqs !thetaFreqs !rFreqs !freqArr !sigmaExp !logPeriodExp !ptx !xs =
let particles =
L.map
(\(Particle phi rho theta r w) ->
( double2Float phi
, double2Float (log rho)
, double2Float theta
, double2Float (log r)
, double2Float w)) .
DL.toList . DL.concat $
xs
!len = L.length particles
in Histogram
[ L.length phiFreqs
, L.length rhoFreqs
, L.length thetaFreqs
, L.length rFreqs
]
len .
VU.map (\(a :+ b) -> float2Double a :+ float2Double b) .
VU.fromList .
A.toList .
runNWith ptx (gpuKernel'' sigmaExp logPeriodExp freqArr) .
A.fromList (A.Z A.:. len) $
particles
{-# INLINE computeFrequencyArray #-}
computeFrequencyArray ::
(A.Elt a) => [a] -> [a] -> [a] -> [a] -> A.Vector (a, a, a, a)
computeFrequencyArray !phiFreqs !rhoFreqs !thetaFreqs !rFreqs =
A.fromList
(A.Z A.:.
((L.length rFreqs) * (L.length thetaFreqs) * (L.length rhoFreqs) *
L.length phiFreqs))
[ (rFreq', thetaFreq', rhoFreq', phiFreq')
| rFreq' <- rFreqs
, thetaFreq' <- thetaFreqs
, rhoFreq' <- rhoFreqs
, phiFreq' <- phiFreqs
]
-- {-# INLINE computeFourierCoefficientsGPU #-}
-- computeFourierCoefficientsGPU ::
-- Acc (A.Vector (Double, Double, Double, Double))
-- -> [Double]
-- -> [Double]
-- -> [Double]
-- -> [Double]
-- -> Double
-- -> Double
-- -> Exp Double
-- -> Exp Double
-- -> Exp (AC.Complex Double)
-- -> PTX
-- -> [DList Particle]
-- -> Histogram (C.Complex Double)
-- computeFourierCoefficientsGPU !freqArr !phiFreqs !rhoFreqs !thetaFreqs !rFreqs !halfLogPeriod !deltaLogRho !maxScaleExp !halfLogPeriodExp !deltaLogRhoComplexExp !ptx !xs =
-- let !particles = DL.toList . DL.concat $ xs
-- !len = L.length particles
-- !scaleSampledParticles =
-- L.concat .
-- parMap
-- rdeepseq
-- (\particle@(Particle phi rho theta r) ->
-- let !n = Prelude.floor $ (log r + halfLogPeriod) / deltaLogRho
-- in (phi, rho, theta, r) :
-- [ ( phi
-- , rho
-- , theta
-- , (exp $
-- (Prelude.fromIntegral i * deltaLogRho - halfLogPeriod)))
-- | i <- [0 .. n - 1]
-- ]) $
-- particles
-- !movedParticleArr =
-- compute .
-- afst .
-- A.filter
-- (\particle ->
-- let (_, rho, _, _) =
-- unlift particle :: ( Exp Double
-- , Exp Double
-- , Exp Double
-- , Exp Double)
-- in rho A./= 0) .
-- A.map (moveParticle maxScaleExp) .
-- use . A.fromList (Z :. (L.length scaleSampledParticles)) $
-- scaleSampledParticles
-- in Histogram
-- [ L.length phiFreqs
-- , L.length rhoFreqs
-- , L.length thetaFreqs
-- , L.length rFreqs
-- ]
-- len .
-- VU.fromList . A.toList $
-- runWith ptx .
-- A.map
-- (\(unlift -> (rFreq, thetaFreq, rhoFreq, phiFreq)) ->
-- sfoldl
-- (\s particle ->
-- s +
-- deltaLogRhoComplexExp *
-- (coefficient
-- halfLogPeriodExp
-- rFreq
-- thetaFreq
-- rhoFreq
-- phiFreq
-- particle))
-- 0
-- (constant Z)
-- movedParticleArr) $
-- freqArr
computeFourierCoefficientsGPU' ::
Double
-> Double
-> [Double]
-> [Double]
-> [Double]
-> [Double]
-> PTX
-> [(Double, Double, Double, Double, Double)]
-> Histogram (Complex Double)
computeFourierCoefficientsGPU' !sigma !period !phiFreqs !rhoFreqs !thetaFreqs !rFreqs !ptx !xs =
let -- !freqArr =
-- A.use $
-- computeFrequencyArray
-- (L.map double2Float phiFreqs)
-- (L.map double2Float rhoFreqs)
-- (L.map double2Float thetaFreqs)
-- (L.map double2Float rFreqs)
!freqArr =
A.use $
computeFrequencyArray
( phiFreqs)
( rhoFreqs)
( thetaFreqs)
( rFreqs)
in Histogram
[ L.length phiFreqs
, L.length rhoFreqs
, L.length thetaFreqs
, L.length rFreqs
]
1 .
VU.fromList .
-- L.map (\(a :+ b) -> (float2Double a) :+ (float2Double b)) .
A.toList .
runNWith
ptx
(gpuKernel''
(A.constant ( sigma))
(A.constant ( (log period)))
freqArr) .
A.fromList (A.Z A.:. (L.length xs)) -- .
-- L.map
-- (\(a, b, c, d, e) ->
-- ( double2Float a
-- , double2Float b
-- , double2Float c
-- , double2Float d
-- , double2Float e))
$
xs
{-# INLINE computePinwheelCoefficients #-}
computePinwheelCoefficients ::
Int
-> Int
-> Int
-> Int
-> PTX
-> [(Double, Double, Double, Double, Complex Double)]
-> Histogram (Complex Double)
computePinwheelCoefficients !maxPhiFreq !maxRhoFreq !maxThetaFreq !maxRFreq !ptx !xs =
let freqFunc maxFreq = [-(fromIntegral maxFreq) .. (fromIntegral maxFreq)]
phiFreqs = freqFunc maxPhiFreq
rhoFreqs = freqFunc maxRhoFreq
thetaFreqs = freqFunc maxThetaFreq
rFreqs = freqFunc maxRFreq
!freqArr =
A.use $ computeFrequencyArray phiFreqs rhoFreqs thetaFreqs rFreqs
in Histogram
[ L.length phiFreqs
, L.length rhoFreqs
, L.length thetaFreqs
, L.length rFreqs
]
1 .
VU.fromList .
A.toList .
runNWith ptx (pinwheelCoefficientsAcc freqArr) .
A.fromList (A.Z A.:. (L.length xs)) $
xs
|
/*!
@file
Defines `boost::hana::Orderable`.
@copyright Louis Dionne 2015
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_HANA_CONCEPT_ORDERABLE_HPP
#define BOOST_HANA_CONCEPT_ORDERABLE_HPP
#include <boost/hana/fwd/concept/orderable.hpp>
#include <boost/hana/core/default.hpp>
#include <boost/hana/core/tag_of.hpp>
#include <boost/hana/less.hpp>
namespace boost { namespace hana {
template <typename Ord>
struct Orderable {
using Tag = typename tag_of<Ord>::type;
static constexpr bool value = !is_default<less_impl<Tag, Tag>>::value;
};
}} // end namespace boost::hana
#endif // !BOOST_HANA_CONCEPT_ORDERABLE_HPP
|
lemma bigoI_tendsto_norm: fixes f g assumes "((\<lambda>x. norm (f x / g x)) \<longlongrightarrow> c) F" assumes "eventually (\<lambda>x. g x \<noteq> 0) F" shows "f \<in> O[F](g)" |
[STATEMENT]
lemma nat_exists_least_iff': "(\<exists>(n::nat). P n) \<longleftrightarrow> P (Least P) \<and> (\<forall>m < (Least P). \<not> P m)"
(is "?lhs \<longleftrightarrow> ?rhs")
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (\<exists>n. P n) = (P (Least P) \<and> (\<forall>m<Least P. \<not> P m))
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (2 subgoals):
1. \<exists>n. P n \<Longrightarrow> P (Least P) \<and> (\<forall>m<Least P. \<not> P m)
2. P (Least P) \<and> (\<forall>m<Least P. \<not> P m) \<Longrightarrow> \<exists>n. P n
[PROOF STEP]
show ?lhs if ?rhs
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<exists>n. P n
[PROOF STEP]
using that
[PROOF STATE]
proof (prove)
using this:
P (Least P) \<and> (\<forall>m<Least P. \<not> P m)
goal (1 subgoal):
1. \<exists>n. P n
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
P (Least P) \<and> (\<forall>m<Least P. \<not> P m) \<Longrightarrow> \<exists>n. P n
goal (1 subgoal):
1. \<exists>n. P n \<Longrightarrow> P (Least P) \<and> (\<forall>m<Least P. \<not> P m)
[PROOF STEP]
show ?rhs if ?lhs
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. P (Least P) \<and> (\<forall>m<Least P. \<not> P m)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. P (Least P) \<and> (\<forall>m<Least P. \<not> P m)
[PROOF STEP]
from \<open>?lhs\<close>
[PROOF STATE]
proof (chain)
picking this:
\<exists>n. P n
[PROOF STEP]
obtain n where n: "P n"
[PROOF STATE]
proof (prove)
using this:
\<exists>n. P n
goal (1 subgoal):
1. (\<And>n. P n \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
P n
goal (1 subgoal):
1. P (Least P) \<and> (\<forall>m<Least P. \<not> P m)
[PROOF STEP]
let ?x = "Least P"
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. P (Least P) \<and> (\<forall>m<Least P. \<not> P m)
[PROOF STEP]
have "\<not> P m" if "m < ?x" for m
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<not> P m
[PROOF STEP]
by (rule not_less_Least[OF that])
[PROOF STATE]
proof (state)
this:
?m < Least P \<Longrightarrow> \<not> P ?m
goal (1 subgoal):
1. P (Least P) \<and> (\<forall>m<Least P. \<not> P m)
[PROOF STEP]
with LeastI_ex[OF \<open>?lhs\<close>]
[PROOF STATE]
proof (chain)
picking this:
P (LEAST n. P n)
?m < Least P \<Longrightarrow> \<not> P ?m
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
P (LEAST n. P n)
?m < Least P \<Longrightarrow> \<not> P ?m
goal (1 subgoal):
1. P (Least P) \<and> (\<forall>m<Least P. \<not> P m)
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
P (Least P) \<and> (\<forall>m<Least P. \<not> P m)
goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<exists>n. P n \<Longrightarrow> P (Least P) \<and> (\<forall>m<Least P. \<not> P m)
goal:
No subgoals!
[PROOF STEP]
qed |
(*
Inductive ex (a:Type) (P:a -> Prop) : Prop :=
| ex_intro : forall (x:a), P x -> ex a P
.
Arguments ex {a} _.
Arguments ex_intro {a} _ _ _.
*)
|
(* Title: ProductCategory
Author: Eugene W. Stark <[email protected]>, 2016
Maintainer: Eugene W. Stark <[email protected]>
*)
chapter ProductCategory
theory ProductCategory
imports Category EpiMonoIso
begin
text\<open>
This theory defines the product of two categories @{term C1} and @{term C2},
which is the category @{term C} whose arrows are ordered pairs consisting of an
arrow of @{term C1} and an arrow of @{term C2}, with composition defined
componentwise. As the ordered pair \<open>(C1.null, C2.null)\<close> is available
to serve as \<open>C.null\<close>, we may directly identify the arrows of the product
category @{term C} with ordered pairs, leaving the type of arrows of @{term C}
transparent.
\<close>
locale product_category =
C1: category C1 +
C2: category C2
for C1 :: "'a1 comp" (infixr "\<cdot>\<^sub>1" 55)
and C2 :: "'a2 comp" (infixr "\<cdot>\<^sub>2" 55)
begin
type_synonym ('aa1, 'aa2) arr = "'aa1 * 'aa2"
notation C1.in_hom ("\<guillemotleft>_ : _ \<rightarrow>\<^sub>1 _\<guillemotright>")
notation C2.in_hom ("\<guillemotleft>_ : _ \<rightarrow>\<^sub>2 _\<guillemotright>")
abbreviation (input) Null :: "('a1, 'a2) arr"
where "Null \<equiv> (C1.null, C2.null)"
abbreviation (input) Arr :: "('a1, 'a2) arr \<Rightarrow> bool"
where "Arr f \<equiv> C1.arr (fst f) \<and> C2.arr (snd f)"
abbreviation (input) Ide :: "('a1, 'a2) arr \<Rightarrow> bool"
where "Ide f \<equiv> C1.ide (fst f) \<and> C2.ide (snd f)"
abbreviation (input) Dom :: "('a1, 'a2) arr \<Rightarrow> ('a1, 'a2) arr"
where "Dom f \<equiv> (if Arr f then (C1.dom (fst f), C2.dom (snd f)) else Null)"
abbreviation (input) Cod :: "('a1, 'a2) arr \<Rightarrow> ('a1, 'a2) arr"
where "Cod f \<equiv> (if Arr f then (C1.cod (fst f), C2.cod (snd f)) else Null)"
definition comp :: "('a1, 'a2) arr \<Rightarrow> ('a1, 'a2) arr \<Rightarrow> ('a1, 'a2) arr"
where "comp g f = (if Arr f \<and> Arr g \<and> Cod f = Dom g then
(C1 (fst g) (fst f), C2 (snd g) (snd f))
else Null)"
notation comp (infixr "\<cdot>" 55)
lemma not_Arr_Null:
shows "\<not>Arr Null"
by simp
interpretation partial_magma comp
proof
show "\<exists>!n. \<forall>f. n \<cdot> f = n \<and> f \<cdot> n = n"
proof
let ?P = "\<lambda>n. \<forall>f. n \<cdot> f = n \<and> f \<cdot> n = n"
show 1: "?P Null" using comp_def not_Arr_Null by metis
thus "\<And>n. \<forall>f. n \<cdot> f = n \<and> f \<cdot> n = n \<Longrightarrow> n = Null" by metis
qed
qed
notation in_hom ("\<guillemotleft>_ : _ \<rightarrow> _\<guillemotright>")
lemma null_char [simp]:
shows "null = Null"
proof -
let ?P = "\<lambda>n. \<forall>f. n \<cdot> f = n \<and> f \<cdot> n = n"
have "?P Null" using comp_def not_Arr_Null by metis
thus ?thesis
unfolding null_def using the1_equality [of ?P Null] ex_un_null by blast
qed
lemma ide_Ide:
assumes "Ide a"
shows "ide a"
unfolding ide_def comp_def null_char
using assms C1.not_arr_null C1.ide_in_hom C1.comp_arr_dom C1.comp_cod_arr
C2.comp_arr_dom C2.comp_cod_arr
by auto
lemma has_domain_char:
shows "domains f \<noteq> {} \<longleftrightarrow> Arr f"
proof
show "domains f \<noteq> {} \<Longrightarrow> Arr f"
unfolding domains_def comp_def null_char by (auto; metis)
assume f: "Arr f"
show "domains f \<noteq> {}"
proof -
have "ide (Dom f) \<and> comp f (Dom f) \<noteq> null"
using f comp_def ide_Ide C1.comp_arr_dom C1.arr_dom_iff_arr C2.arr_dom_iff_arr
by auto
thus ?thesis using domains_def by blast
qed
qed
lemma has_codomain_char:
shows "codomains f \<noteq> {} \<longleftrightarrow> Arr f"
proof
show "codomains f \<noteq> {} \<Longrightarrow> Arr f"
unfolding codomains_def comp_def null_char by (auto; metis)
assume f: "Arr f"
show "codomains f \<noteq> {}"
proof -
have "ide (Cod f) \<and> comp (Cod f) f \<noteq> null"
using f comp_def ide_Ide C1.comp_cod_arr C1.arr_cod_iff_arr C2.arr_cod_iff_arr
by auto
thus ?thesis using codomains_def by blast
qed
qed
lemma arr_char [iff]:
shows "arr f \<longleftrightarrow> Arr f"
using has_domain_char has_codomain_char arr_def by simp
lemma arrI [intro]:
assumes "C1.arr f1" and "C2.arr f2"
shows "arr (f1, f2)"
using assms by simp
lemma arrE:
assumes "arr f"
and "C1.arr (fst f) \<and> C2.arr (snd f) \<Longrightarrow> T"
shows "T"
using assms by auto
lemma seqI [intro]:
assumes "C1.seq g1 f1 \<and> C2.seq g2 f2"
shows "seq (g1, g2) (f1, f2)"
using assms comp_def by auto
lemma seqE [elim]:
assumes "seq g f"
and "C1.seq (fst g) (fst f) \<Longrightarrow> C2.seq (snd g) (snd f) \<Longrightarrow> T"
shows "T"
using assms comp_def
by (metis (no_types, lifting) C1.seqI C2.seqI Pair_inject not_arr_null null_char)
lemma seq_char [iff]:
shows "seq g f \<longleftrightarrow> C1.seq (fst g) (fst f) \<and> C2.seq (snd g) (snd f)"
using comp_def by auto
lemma Dom_comp:
assumes "seq g f"
shows "Dom (g \<cdot> f) = Dom f"
using assms comp_def
apply (cases "C1.arr (fst g)"; cases "C1.arr (fst f)";
cases "C2.arr (snd f)"; cases "C2.arr (snd g)"; simp_all)
by auto
lemma Cod_comp:
assumes "seq g f"
shows "Cod (g \<cdot> f) = Cod g"
using assms comp_def
apply (cases "C1.arr (fst f)"; cases "C2.arr (snd f)";
cases "C1.arr (fst g)"; cases "C2.arr (snd g)"; simp_all)
by auto
theorem is_category:
shows "category comp"
proof
fix f
show "(domains f \<noteq> {}) = (codomains f \<noteq> {})"
using has_domain_char has_codomain_char by simp
fix g
show "g \<cdot> f \<noteq> null \<Longrightarrow> seq g f"
using comp_def seq_char by (metis C1.seqI C2.seqI Pair_inject null_char)
fix h
show "seq h g \<Longrightarrow> seq (h \<cdot> g) f \<Longrightarrow> seq g f"
using comp_def null_char seq_char by (elim seqE C1.seqE C2.seqE, simp)
show "seq h (g \<cdot> f) \<Longrightarrow> seq g f \<Longrightarrow> seq h g"
using comp_def null_char seq_char by (elim seqE C1.seqE C2.seqE, simp)
show "seq g f \<Longrightarrow> seq h g \<Longrightarrow> seq (h \<cdot> g) f"
using comp_def null_char seq_char by (elim seqE C1.seqE C2.seqE, simp)
show "seq g f \<Longrightarrow> seq h g \<Longrightarrow> (h \<cdot> g) \<cdot> f = h \<cdot> g \<cdot> f"
using comp_def null_char seq_char C1.comp_assoc C2.comp_assoc
by (elim seqE C1.seqE C2.seqE, simp)
qed
end
sublocale product_category \<subseteq> category comp
using is_category comp_def by auto
context product_category
begin
lemma dom_simp [simp]:
assumes "arr f"
shows "dom f = (C1.dom (fst f), C2.dom (snd f))"
using assms dom_char by auto
lemma cod_char:
shows "cod f = Cod f"
proof (cases "Arr f")
show "\<not>Arr f \<Longrightarrow> cod f = Cod f"
unfolding cod_def using has_codomain_char by auto
show "Arr f \<Longrightarrow> cod f = Cod f"
using ide_Ide seqI apply (intro cod_eqI, simp)
using seq_char comp_def C1.arr_cod_iff_arr C2.arr_cod_iff_arr by auto
qed
lemma cod_simp [simp]:
assumes "arr f"
shows "cod f = (C1.cod (fst f), C2.cod (snd f))"
using assms cod_char by auto
lemma in_homI [intro, simp]:
assumes "\<guillemotleft>fst f: fst a \<rightarrow>\<^sub>1 fst b\<guillemotright>" and "\<guillemotleft>snd f: snd a \<rightarrow>\<^sub>2 snd b\<guillemotright>"
shows "\<guillemotleft>f: a \<rightarrow> b\<guillemotright>"
using assms by fastforce
lemma in_homE [elim]:
assumes "\<guillemotleft>f: a \<rightarrow> b\<guillemotright>"
and "\<guillemotleft>fst f: fst a \<rightarrow>\<^sub>1 fst b\<guillemotright> \<Longrightarrow> \<guillemotleft>snd f: snd a \<rightarrow>\<^sub>2 snd b\<guillemotright> \<Longrightarrow> T"
shows "T"
using assms
by (metis C1.in_homI C2.in_homI arr_char cod_simp dom_simp fst_conv in_homE snd_conv)
lemma ide_char [iff]:
shows "ide f \<longleftrightarrow> Ide f"
using ide_in_hom C1.ide_in_hom C2.ide_in_hom by blast
lemma comp_char:
shows "g \<cdot> f = (if C1.arr (C1 (fst g) (fst f)) \<and> C2.arr (C2 (snd g) (snd f)) then
(C1 (fst g) (fst f), C2 (snd g) (snd f))
else Null)"
using comp_def by auto
lemma comp_simp [simp]:
assumes "C1.seq (fst g) (fst f)" and "C2.seq (snd g) (snd f)"
shows "g \<cdot> f = (fst g \<cdot>\<^sub>1 fst f, snd g \<cdot>\<^sub>2 snd f)"
using assms comp_char by simp
lemma iso_char [iff]:
shows "iso f \<longleftrightarrow> C1.iso (fst f) \<and> C2.iso (snd f)"
proof
assume f: "iso f"
obtain g where g: "inverse_arrows f g" using f by auto
have 1: "ide (g \<cdot> f) \<and> ide (f \<cdot> g)"
using f g by (simp add: inverse_arrows_def)
have "g \<cdot> f = (fst g \<cdot>\<^sub>1 fst f, snd g \<cdot>\<^sub>2 snd f) \<and> f \<cdot> g = (fst f \<cdot>\<^sub>1 fst g, snd f \<cdot>\<^sub>2 snd g)"
using 1 comp_char arr_char by (meson ideD(1) seq_char)
hence "C1.ide (fst g \<cdot>\<^sub>1 fst f) \<and> C2.ide (snd g \<cdot>\<^sub>2 snd f) \<and>
C1.ide (fst f \<cdot>\<^sub>1 fst g) \<and> C2.ide (snd f \<cdot>\<^sub>2 snd g)"
using 1 ide_char by simp
hence "C1.inverse_arrows (fst f) (fst g) \<and> C2.inverse_arrows (snd f) (snd g)"
by auto
thus "C1.iso (fst f) \<and> C2.iso (snd f)" by auto
next
assume f: "C1.iso (fst f) \<and> C2.iso (snd f)"
obtain g1 where g1: "C1.inverse_arrows (fst f) g1" using f by blast
obtain g2 where g2: "C2.inverse_arrows (snd f) g2" using f by blast
have "C1.ide (g1 \<cdot>\<^sub>1 fst f) \<and> C2.ide (g2 \<cdot>\<^sub>2 snd f) \<and>
C1.ide (fst f \<cdot>\<^sub>1 g1) \<and> C2.ide (snd f \<cdot>\<^sub>2 g2)"
using g1 g2 ide_char by force
hence "inverse_arrows f (g1, g2)"
using f g1 g2 ide_char comp_char by (intro inverse_arrowsI, auto)
thus "iso f" by auto
qed
lemma isoI [intro, simp]:
assumes "C1.iso (fst f)" and "C2.iso (snd f)"
shows "iso f"
using assms by simp
lemma isoD:
assumes "iso f"
shows "C1.iso (fst f)" and "C2.iso (snd f)"
using assms by auto
lemma inv_simp [simp]:
assumes "iso f"
shows "inv f = (C1.inv (fst f), C2.inv (snd f))"
proof -
have "inverse_arrows f (C1.inv (fst f), C2.inv (snd f))"
proof
have 1: "C1.inverse_arrows (fst f) (C1.inv (fst f))"
using assms iso_char C1.inv_is_inverse by simp
have 2: "C2.inverse_arrows (snd f) (C2.inv (snd f))"
using assms iso_char C2.inv_is_inverse by simp
show "ide ((C1.inv (fst f), C2.inv (snd f)) \<cdot> f)"
using 1 2 ide_char comp_char by auto
show "ide (f \<cdot> (C1.inv (fst f), C2.inv (snd f)))"
using 1 2 ide_char comp_char by auto
qed
thus ?thesis using inverse_unique by auto
qed
end
end
|
/-
Notes
-----
A set seems to be the lambda λα : Type → Prop
`mem` takes a set and another input and simply applies the set to the other.
protected def mem (a : α) (s : set α) :=
s a
∈ is defined in library/init.core.lean.
infix ∈ := has_mem.mem
with has_mem.mem having the definition:
class has_mem (α : out_param $ Type u) (y : Type v) := (mem : α→y→Prop)
$ usage. Quoted from "Programming in Lean":
Note the use of the dollar-sign for function application. In general,
an expression f $ a denotes nothing more than f a, but the binding strength
is such that you do not need to use extra parentheses when a is a long
expression. This provides a convenient idiom in situations exactly like
the one in the example.
The statement:
∃x ∈ X
is shorthand for:
∃ (x : _) (h : x ∈ X)
which is shorthand for:
∃ (x : _), ∃ (h : x ∈ X),
-/
/-
Contents and exercises for Chapter 9 of Tao's Analysis.
-/
-- We want real numbers and their basic properties
import data.real.basic
import data.set
import logic.basic
import tao_ch5
set_option pp.implicit true
-- Make simp display the steps used.
set_option trace.simplify.rewrite true
-- We want to be able to define functions using the law of excluded middle
noncomputable theory
open_locale classical
-- Use a namespace so that we can copy some of the matlib naming.
namespace tao_analysis
-- Notation for absolute. Is this in Lean somewhere?
local notation `|`x`|` := abs x
/- Section 9.1
Many of these results can be found in matlib. For example, definitions and
properties of closures can be found here:
https://leanprover-community.github.io/mathlib_docs/topology/basic.html
-/
/- Definition 9.1.1 (Intervals)
Intervals are available in matlib.
https://leanprover-community.github.io/mathlib_docs/data/set/intervals/basic.html
-/
namespace demo
def x₁ : ℝ := 1
def x₂ : ℝ := 4
constant open_interval : set.Ioo x₁ x₂
constant closed_open_interval : set.Ico x₁ x₂
constant open_closed_interval : set.Ioc x₁ x₂
constant closed_interval : set.Icc x₁ x₂
end demo
/-
Exercises
---------
9.1.1
9.1.2 (Lemma 9.1.11)
9.1.3 TODO
9.1.1 again, this time using Lemma 9.1.11, and Exercise 9.1.6.
-/
-- Definition 9.1.7
-- I'm skipping this and going directly to 9.1.8
-- Definition 9.1.8
def is_adherent (x : ℝ) (X : set ℝ) : Prop :=
∀ ε > 0, ∃y ∈ X, |x - y| < ε
infix `is_adherent_to` :55 := is_adherent
-- Definition 9.1.10
def closure (X : set ℝ) : set ℝ :=
{x : ℝ | x is_adherent_to X }
-- Definition 9.1.15
def is_closed (X : set ℝ) :Prop :=
closure X = X
-- Definition 9.1.18 a)
def is_limit_point (x : ℝ) (X : set ℝ) : Prop :=
is_adherent x (X \ {x})
def is_isolated_point (x : ℝ) (X : set ℝ) : Prop :=
x ∈ X ∧ ∃ ε > 0, ∀y ∈ (X \ {x}), |x - y| > ε
-- Definition 9.1.22
def is_bounded (X : set ℝ) : Prop :=
∃ M > 0, X ⊆ set.Icc (-M) M
/- Exercise 9.1.1
If X ⊆ Y ⊆ closure(X), then closure(Y) = closure(X)
This attempt is a hacky δ—ε proof; it doesn't use any properties from Lemma
9.1.11. I repeat the proof again below using Lemma 9.1.11.
-/
lemma closure_squeeze
(X Y : set ℝ)
(h₁ : X ⊆ Y)
(h₂ : Y ⊆ closure(X)) :
closure(X) = closure(Y) :=
begin
apply set.eq_of_subset_of_subset,
{
intros x h₃ ε hε,
have h₄ : x is_adherent_to X, from h₃,
have h₅ : ∃x' ∈ X, |x - x'| < ε, from h₃ ε hε,
rcases h₅ with ⟨x', h₆, h₇⟩,
have h₈ : x' ∈ Y, from h₁ h₆,
use x',
exact and.intro h₈ h₇
},
{
intros y h₃ ε hε,
set δ := ε/3 with hδ,
have h₅ : δ > 0, by linarith,
have h₆ : ∃y' ∈ Y, |y - y'| < δ, from h₃ δ h₅,
rcases h₆ with ⟨y', hy', h₇⟩,
have h₈ : y' ∈ closure(X), from h₂ hy',
have h₉ : ∃x ∈ X, |y' - x| < δ, from h₈ δ h₅,
rcases h₉ with ⟨x, hx, h₁₀⟩,
use x,
have h₁₀ : |(y - y') + (y' - x)| ≤ |y - y'| + |y' - x|, from abs_add _ _,
have h₁₁ : |y - x| < 2*δ,
rw (show (y - x) = (y - y') + (y' - x), by ring),
linarith,
have h₁₂ : |y - x| < ε, by linarith,
exact and.intro hx h₁₂
}
end
/- Exercise 9.1.2 (Lemma 9.1.11)
There are 4 separate propositions here:
1. X ⊆ closure(X)
The 4th part is done next so that it can be used in 2 and 3.
4. X ⊆ Y → closure(X) ⊆ closure(Y)
2. closure(X ∪ Y) = closure(X) ∪ closure(Y)
3. closure(X ∩ Y) ⊆ closure(X) ∩ closure(Y)
-/
-- 1. X ⊆ closure(X)
lemma subset_closure (X : set ℝ ) : X ⊆ closure(X) :=
begin
intros x h₁ ε h₂,
apply exists.intro x,
apply exists.intro h₁,
rw [sub_self, abs_zero],
exact h₂,
end
-- Trying to achieve the same thing using a term-based proof.
lemma subset_closure_term (X : set ℝ ) : X ⊆ closure(X) :=
assume x,
assume h₁ : x ∈ X,
have adh: x is_adherent_to X, from
assume ε,
assume h₂ : ε > 0,
have h₃ : |x - x| < ε, from
have h₄ : x - x = 0, from sub_self x,
sorry, -- not sure how to proceed here.
exists.intro x (exists.intro h₁ h₃),
show x ∈ closure(X), from adh
-- 4. X ⊆ Y → closure(X) ⊆ closure(Y)
lemma closure_mono {X Y :set ℝ} (hXY : X ⊆ Y) : closure(X) ⊆ closure(Y) :=
begin
intros x hx ε hε,
have : ∃x' ∈ X, |x - x'| < ε, from hx ε hε,
rcases this with ⟨x', hx', h₂⟩,
use x',
split,
exact hXY hx',
exact h₂, -- could use `assumption` here instead.
end
-- 2. closure(X ∪ Y) = closure(X) ∪ closure(Y)
lemma closure_union
{X Y : set ℝ} :
closure (X ∪ Y) = closure (X) ∪ closure (Y) :=
begin
apply set.subset.antisymm,
{
-- not sure how to do this part in Lean.
admit
},
{
intros a haXY,
cases haXY,
apply closure_mono (set.subset_union_left X Y) haXY,
apply closure_mono (set.subset_union_right X Y) haXY
}
end
/- 3. closure(X ∩ Y) ⊆ closure(X) ∩ closure(Y)
Version 1, my original ε attempt.
Below, using closure_mono, is a nicer proof.
-/
lemma closure_inter_subset_inter_closure (X Y : set ℝ) :
closure (X ∩ Y) ⊆ closure X ∩ closure Y :=
begin
intros a ha,
split,
repeat {
intros ε hε,
rcases ha ε hε with ⟨xy, hxy, h₁⟩,
use xy,
cases hxy with l r,
split; assumption
}
end
/- 3. closure(X ∩ Y) ⊆ closure(X) ∩ closure(Y)
Version 2, by Kenny Lau.
https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/cleaning.20up.20this.20tactic.20proof.20%28regarding.20closures%29/near/192625784
-/
lemma closure_inter_subset_inter_closure' (X Y : set ℝ) :
closure (X ∩ Y) ⊆ closure X ∩ closure Y :=
have h₁ : closure (X ∩ Y) ⊆ closure X,
from closure_mono (set.inter_subset_left X Y),
have h₂ : closure (X ∩ Y) ⊆ closure Y,
from closure_mono (set.inter_subset_right X Y),
set.subset_inter h₁ h₂
-- Lemma 9.1.12
-- There are 4 parts.
-- 1. Closure of interval (a, b) is [a, b].
lemma closure_Ioo_Icc
(a b : ℝ)
(hab : a < b) :
closure (set.Ioo a b) = (set.Icc a b) :=
begin
apply set.subset.antisymm,
{
intros x hx,
by_contradiction H,
unfold set.Icc at H,
simp at H,
have hxa : x < a ∨ a ≤ x, by exact @lt_or_ge ℝ real.linear_order x a,
cases hxa with hlt hge,
{
have h₁ : ∃ β > 0, x + β = a, from sorry,
--have h₆ : x = a - β, by linarith,--exact @eq_sub_of_add_eq ℝ real.add_group x a β h₂,
rcases h₁ with ⟨β, hβ, h₂⟩,
rcases hx β hβ with ⟨y, hy, hxy⟩,
have h₃ : a < y, from hy.left,
have h₄ : ∃ α > 0, a + α = y, from sorry,
rcases h₄ with ⟨α, hα, h₅⟩,
have h₆ : a = y - α, by linarith,
rw h₆ at h₂,
have h₇ := y - x = β + α, from sorry,--by linarith, -- really linarith!
},
{
admit
},
},
{
admit
},
end
-- 2. Closure of interval (a, b] is [a, b].
-- 3. Closure of interval [a, b) is [a, b].
-- 4. Closure of interval [a, b] is [a, b].
-- [TODO: convert to lean]
-- Exercise 9.1.3
-- This needs to be improved! How to properly prove being equal to the
-- empty set?
lemma is_empty_closed : is_closed ∅ :=
begin
unfold is_closed,
unfold closure,
apply set.subset.antisymm,
{
intros x hx,
have h₁ : ∀ ε > 0, ∃x' ∈ ∅, |x - x'| < ε, from hx,
set a : ℝ := 1 with h₂,
have h₃ : a > 0, by linarith,
rcases h₁ a h₃ with ⟨x', h0, h0a⟩,
exact h0
},
{simp,}
end
-- Exercise 9.1.4
-- Exercise 9.1.5
/-
Exercise 9.1.6
-/
lemma closure_closure (X : set ℝ) : closure (closure X) = closure X :=
begin
apply set.subset.antisymm,
{
intros a haX ε hε,
set δ := ε/3 with h3δ,
have hδ : δ > 0, by linarith,
rcases haX δ hδ with ⟨xc, hxc, h₁⟩,
rcases hxc δ hδ with ⟨x, hx, h₂⟩,
use x,
split,
exact hx,
calc |a - x| = |(a - xc) + (xc - x)| : by ring
... ≤ |a - xc| + |xc - x| : by apply abs_add
... < 2 * δ : by linarith
... < ε : by linarith
},
{
apply subset_closure (closure X)
}
end
/- Exercise 9.1.6 (version 2)
If you decide to follow the book and prove exercise 9.1.1 first, then you can
use that result to prove 9.1.6 easily. Above, 9.1.6 is done without 9.1.1
so as to be available for earlier proofs.
-/
example {X : set ℝ} : closure (closure X) = closure X :=
begin
-- Use closure(X) as the middle term in 9.1.1's lemma.
let Y := closure X,
have h₁ : X ⊆ Y, from subset_closure X,
have h₂ : Y ⊆ closure X, from set.subset.refl Y,
have h₃ : closure X = closure (closure X), from closure_squeeze X Y h₁ h₂,
apply eq.symm, -- Should `simp,` work here instead?
exact h₃,
end
/- Exercise 9.1.7
A the union of a finite number of closed sets is closed.
It seems possible to either:
a) take a function, f: ℕ → set ℝ, as input and induce on ℕ, or
b) take a finset ℝ as input and induce using the provided mechanism of finset.
Let's try a)
The captial 'U' refers to the union of the family of sets.
Note: should the `n` be removed?
mathlib uses 'is_closed_bUnion' to name their method. I'm not sure what
the b prefix means here.
-/
/-lemma is_closed_Union
{ss : finset set ℝ}
(h₁ : ∀s ∈ ss, is_closed (s)) :
is_closed (set.Union (finset.to_set ss)) :=
sorry
-/
/- TODO
Struggling to induce over finite sets, so I'll try a more general approach of
using index sets and come back later to address it. We can define f to be
a function that simply maps all i>n to n to achieve the same thing as intented,
it's just not really honoring the intent of the original statement.
-/
lemma is_closed_Union_n
{n : ℕ}
{f : ℕ → set ℝ}
(h₁ : ∀i < n, is_closed (f i)) :
is_closed ⋃ i < n, f i :=
sorry
lemma not_le_of_ge (a b : ℝ) (h : ¬ a < b) : a ≥ b :=
begin
-- ge_iff_le isn't actually needed.
rw [@not_lt ℝ real.linear_order a b, ←ge_iff_le] at h,
exact h
end
[email protected] (¬a < b) (b ≤ a) (@not_lt ℝ real.linear_order a b) h
variables P : ℝ → Prop
example (a : ℝ) (h : ∀ y : ℝ, P y → ¬ a < y) : ∀ y : ℝ, P y → a ≥ y :=
begin
simp_rw @not_lt ℝ real.linear_order a at h,
exact h
end
/-- Exercise 9.1.9
I took two approaches to solving this.
1. Tao's order
I approached it in the sequence presented in the problem (starting with adherent
points being limit points xor isolated points). The first part of this turned
into a monolithic tactic proof.
2. First introduce to iff statements
In an attempt to make the above proof less of a monolith, I proved the
bijections:
is_limit_point x X ↔ x ∈ closure (X \ {x})
is_isolated_point x X ↔ is_adherent x X ∧ x ∉ closure (X \ {x})
However, the second of these proofs turned out to be even more involved than the
original monolith, so nothing was really gained here.
-/
-- 1. Tao's order.
/- 1.1
An adherent point to set of reals is exactly one of the following:
* a limit point or
* an isolated point
-/
lemma limit_xor_isolated
(X : set ℝ)
(x : ℝ)
(hx : is_adherent x X) :
is_isolated_point x X ↔ ¬ is_limit_point x X :=
begin
split,
{
intros hix hlx,
rcases hix with ⟨hxX, ε, hε, hy⟩,
rcases hlx ε hε with ⟨y, hyX, hxy⟩,
have h₁ := hy y hyX,
linarith,
},
{
intros nhlx,
-- unfold so that simp will be able to work.
unfold is_limit_point is_adherent at nhlx,
-- Push the negative all the way to the < relation.
simp_rw [not_forall, not_exists, @not_lt ℝ real.linear_order] at nhlx,
-- Writing it out here will nicer variables.
have h₁ : ∃ (ε : ℝ) (hε : ε > 0), ∀ (y : ℝ), y ∈ X \ {x} → |x - y| ≥ ε, from nhlx,
-- Q: Is there an easy way to replace all ≥ with > knowing that we can find
-- a smaller real?
-- I just want to replace ≥ with >. It look simple, but it takes me...
have h₂ : ∃ (ε : ℝ) (hε : ε > 0), ∀ (y : ℝ), y ∈ X \ {x} → |x - y| > ε,
rcases h₁ with ⟨ε, hε, hy⟩,
use ε/2,
split,
{
exact (by linarith),
},
{
intros y hyX,
have h:= hy y hyX,
linarith,
},
-- ... 8 lines.
split,
{
rcases h₁ with ⟨ε, hε, hy⟩,
rcases hx ε hε with ⟨y, hyX, hxy⟩,
by_contradiction,
rw ←(set.diff_singleton_eq_self a) at hyX,
have nhxy := hy y hyX,
linarith,
},
{
exact h₂
}
}
end
-- 1.2 a limit point is an adherent point.
lemma adherent_of_limit
{X : set ℝ}
{x : ℝ}
(h : is_limit_point x X) :
is_adherent x X :=
begin
set X_diff_x := X \ {x},
have h₁ : is_adherent x X_diff_x, from h,
have h₂ : X_diff_x ⊆ X, from set.diff_subset X {x},
exact closure_mono h₂ h₁,
end
-- 1.3 a isolated point is an adherent point.
lemma adherent_of_isolated
{X : set ℝ}
{x : ℝ}
(h : is_isolated_point x X) :
is_adherent x X :=
begin
intros ε hε,
use x,
rw [sub_self, abs_zero],
exact ⟨h.left, hε⟩,
end
-- 2. Custom order.
lemma limit_iff_mem_closure_minus
{X : set ℝ}
{x : ℝ} :
is_limit_point x X ↔ x ∈ closure (X \ {x}) :=
begin
unfold is_limit_point closure,
simp
end
lemma isolated_iff_adherent_not_mem_closure_minus
{X : set ℝ}
{x : ℝ} :
is_isolated_point x X ↔ is_adherent x X ∧ x ∉ closure (X \ {x}) :=
begin
split,
{
intro h,
split,
{
intros ε hε,
use x,
rw [sub_self, abs_zero],
exact ⟨h.left,hε⟩,
},
{
-- I wanted to push the negative to the left and produce:
-- ∃ ε > 0, ¬∃ y ∈ X\{x}, |x - y| ≤ ε
-- ∃ ε/2 > 0, ¬∃ y ∈ X\{x}, |x - y| < ε/2
-- ¬ ∀ ε/2 > 0, ∃ y ∈ X\{x}, |x - y| < ε/2
-- which is our goal.
-- But, as seen below, it's tedius, so I'll just bounce between the ∃ and ∀.
intros hn,
rcases h.right with ⟨ε, hε, h₁⟩,
simp at hn h₁,
rcases hn ε hε with ⟨y, hy, hxy⟩,
simp at hy,
have h := h₁ y hy.left hy.right,
linarith,
}
},
{
assume h,
have h₁ : x ∈ closure X, from h.left,
split,
{
by_contradiction,
have h₂ : X = X \ {x}, from eq.symm (set.diff_singleton_eq_self a),
rw h₂ at h₁,
exact h.right h₁,
},
{
have hr := h.right,
unfold closure is_adherent at hr,
rw set.mem_set_of_eq at hr,
-- Push the negative all the way to the < relation.
simp_rw [not_forall, not_exists, @not_lt ℝ real.linear_order,
iff.symm ge_iff_le] at hr,
-- I just want to replace ≥ with >. It look simple, but it takes me...
have ans : ∃ (ε : ℝ) (hε : ε > 0), ∀ (y : ℝ), y ∈ X \ {x} → |x - y| > ε,
rcases hr with ⟨ε, hε, hy⟩,
use ε/2,
split,
exact (by linarith),
intros y hyX,
have h:= hy y hyX,
linarith,
-- ... 8 lines.-/
exact ans
}
}
end
lemma limit_xor_isolated'
(X : set ℝ)
(x : ℝ)
(hx : is_adherent x X) :
is_isolated_point x X ↔ ¬ is_limit_point x X :=
begin
split,
{
intros hix hlx,
exact (iff.elim_left isolated_iff_adherent_not_mem_closure_minus hix).right hlx,
},
{
intros nhlx,
rw limit_iff_mem_closure_minus at nhlx,
have h₁ := and.intro hx nhlx,
exact (iff.elim_right isolated_iff_adherent_not_mem_closure_minus h₁)
}
end
-- Exercise 9.1.10
-- This is an trivial proof on paper, but I ended up with a mess in Lean.
example (X : set ℝ) (h : X.nonempty) :
is_bounded X ↔ has_finite_sup X ∧ has_finite_inf X :=
begin
split,
{
-- The forward proof isn't too bad—it's the reverse that is the main issue.
intro hb,
rcases hb with ⟨u, hu, h₁⟩,
let l := -u,
have hub : u ∈ upper_bounds X,
intros x hx,
exact (h₁ hx).right,
have hlb : l ∈ lower_bounds X,
intros x hx,
exact (h₁ hx).left,
have hfs : has_finite_sup X, from ⟨h, set.nonempty_of_mem hub⟩,
have hfi : has_finite_inf X, from ⟨h, set.nonempty_of_mem hlb⟩,
exact ⟨hfs, hfi⟩,
},
{
-- This part is a mess, mainly becase:
-- 1. I don't find a simple way of going from `u l : ℝ` to `∃ m > 0, m ≥ u ∧ m ≥ l`
-- 2. I don't know of a tactic like `linarith` that will work with abs inequalities.
intro h,
rcases h.left.right with ⟨u, hu⟩,
rcases h.right.right with ⟨l, hl⟩,
-- Try create m by setting it equal to `|upper bound| + |lower bound| + 1`
let m0 := |u| + |l|,
have h₁ : m0 ≥ |u| ∧ m0 ≥ |l|,
split; {norm_num, apply abs_nonneg},
let m1 : ℝ := m0 + 1,
have h₂ : m0 ≤ m1, by norm_num,
have h₄ : m1 ≥ |u| ∧ m1 ≥ |l|,
-- Short but opaque alternative for h₄ proof:
-- split; cases h₁; apply le_trans; assumption,
split,
{
apply le_trans h₁.left h₂,
},
{
apply le_trans h₁.right h₂,
},
use m1,
split,
{
-- Can't find any automation for here.
have m0_nonneg : 0 ≤ m0, from add_nonneg (abs_nonneg u) (abs_nonneg l),
have h₃ : 0 < m1, from add_pos_of_nonneg_of_pos m0_nonneg (by norm_num),
exact h₃,
},
{
intros x hx,
-- Can't find any automation for here.
have hxm : x ≤ m1, from le_trans (hu hx) (le_trans (le_abs_self u) h₄.left),
have hml : -l ≤ m1, from le_trans (neg_le_abs_self l) h₄.right,
rw neg_le at hml,
have hmx := le_trans hml (hl hx),
exact ⟨hmx, hxm⟩,
},
},
end
example (X : set ℝ) (h : X.nonempty) :
is_bounded X ↔ has_finite_sup X ∧ has_finite_inf X :=
begin
split,
{ rintro ⟨M, M0, hM⟩,
exact ⟨⟨h, M, λ x h, (hM h).2⟩, ⟨h, -M, λ x h, (hM h).1⟩⟩ },
{ rintro ⟨⟨_, u, hu⟩, ⟨_, v, hv⟩⟩,
use max 1 (max u (-v)), split,
{ apply lt_of_lt_of_le zero_lt_one,
apply le_max_left },
{ intros x hx, split,
{ apply neg_le.1,
apply le_trans _ (le_max_right _ _),
apply le_trans _ (le_max_right _ _),
apply neg_le_neg,
exact hv hx },
{ apply le_trans _ (le_max_right _ _),
apply le_trans _ (le_max_left _ _),
exact hu hx } } }
end
/-
intros hlx,
--have h₁ := not_forall hlx,
have h₁ := iff.elim_left not_forall hlx,
-- Why can't I apply rw not_imp here? simp goes too far.
-- rw not_imp,
cases h₁ with ε h₂,
have h₃ := iff.elim_left not_imp h₂,
cases h₃,
rw not_exists at h₃_right,
-- Why can't I write: rw ←not_le at h₃_right,
split,
{
rcases hx ε h₃_left with ⟨y, hy, hxy⟩,
have h₄ := h₃_right y,
rw not_exists at h₄,
by_contradiction,
have h₅ := and.intro hy a,
rw [set.sub_eq_diff, set.mem_diff] at h₄,
have h₆ : y ≠ x,
by_contradiction,
simp at a_1,
have h₇ := h₄ ⟨h₅.left, _⟩,
simp at h₄,
},
{
set δ := ε/2 with h3δ,
have hδ : δ > 0, by linarith,
use δ,
split,
exact hδ,
intros y hy,
have h₄ := h₃_right y,
rw not_exists at h₄,
have h₅ := h₄ hy,
linarith,
}
--rcases hx ε h₃.left with ⟨y, hy, hxy⟩,
}
end-/
/-have h₁ : ¬(is_isolated_point x X ∧ is_limit_point x X),
intro h₂,
rcases h₂.left with ⟨hxX, ε, hε, hy⟩,
have h₃ := h₂.right ε hε,
rcases h₃ with ⟨y, hyX, hxy⟩,
have h₄ := hy y hyX,
linarith,-/
/-{
intros hix hlx,
rcases hix with ⟨hxX, ε, hε, hy⟩,
rcases hlx ε hε with ⟨y, hyX, hxy⟩,
have h₁ := hy y hyX,
linarith,
},
{
intros hlx hix,
}
end-/
lemma limit_point_is_adherent
(X : set ℝ)
(x : ℝ)
(h₁ : is_limit_point x X):
is_adherent x X :=
sorry
lemma isolated_point_is_adherent
(X : set ℝ)
(x : ℝ)
(h₁ : is_isolated_point x X):
is_adherent x X :=
sorry
/-- Exercise 9.1.10
-/
lemma closure_bounded_if_bounded :
(X :)
end tao_analysis |
theory ContinuousInv
imports BigStepContinuous
begin
lemma chainrule:
assumes "\<forall>x. ((\<lambda>v. g (vec2state v)) has_derivative g' (vec2state x)) (at x within UNIV)"
and "ODEsol ode p d"
and "t \<in> {0 .. d}"
shows "((\<lambda>t. g (p t)) has_derivative (\<lambda>s. g' (p t) (s *\<^sub>R ODE2Vec ode (p t)))) (at t within {0 .. d})"
proof -
have 1: "(\<And>x. x \<in> UNIV \<Longrightarrow> ((\<lambda>v. g (vec2state v)) has_derivative g' (vec2state x)) (at x))"
using assms(1) by auto
have 2: "0 \<le> t \<and> t \<le> d"
using assms(3) by auto
have 3: "((\<lambda>t. state2vec(p t)) has_derivative (\<lambda>s. s *\<^sub>R ODE2Vec ode (p t))) (at t within {0..d})"
using 2 assms(2) using ODEsol_old[OF assms(2)]unfolding ODEsol_def has_vderiv_on_def has_vector_derivative_def by auto
show ?thesis
using 1 2 3 has_derivative_in_compose2[of UNIV "(\<lambda>v. g (vec2state v))" "(\<lambda>v. g' (vec2state v))" "(\<lambda>t. state2vec (p t))" "{0 .. d}" t "(\<lambda>s. s *\<^sub>R ODE2Vec ode (p t))"]
by auto
qed
lemma chainrule':
assumes "\<forall>x. ((\<lambda>v. g (vec2state v)) has_derivative g' (vec2state x)) (at x within UNIV)"
and "((\<lambda>t. state2vec (p t)) has_vderiv_on (\<lambda>t. ODE2Vec ode (p t))) {-e .. d+e}"
and "e>0"
and "t \<in> {-e .. d+e}"
shows "((\<lambda>t. g (p t)) has_derivative (\<lambda>s. g' (p t) (s *\<^sub>R ODE2Vec ode (p t)))) (at t within {-e .. d+e})"
proof -
have 1: "(\<And>x. x \<in> UNIV \<Longrightarrow> ((\<lambda>v. g (vec2state v)) has_derivative g' (vec2state x)) (at x))"
using assms(1) by auto
have 2: "-e \<le> t \<and> t \<le> d+e"
using assms(3) assms(4) by auto
have 3: "((\<lambda>t. state2vec(p t)) has_derivative (\<lambda>s. s *\<^sub>R ODE2Vec ode (p t))) (at t within {-e .. d+e})"
using 2 assms(2) unfolding ODEsol_def has_vderiv_on_def has_vector_derivative_def by auto
show ?thesis
using 1 2 3 has_derivative_in_compose2[of UNIV "(\<lambda>v. g (vec2state v))" "(\<lambda>v. g' (vec2state v))" "(\<lambda>t. state2vec (p t))" "{-e .. d+e}" t "(\<lambda>s. s *\<^sub>R ODE2Vec ode (p t))"]
by auto
qed
theorem Valid_inv:
fixes inv :: "state \<Rightarrow> real"
assumes "\<forall>x. ((\<lambda>v. inv (vec2state v)) has_derivative g' x) (at x within UNIV)"
and "\<forall>S. b S \<longrightarrow> g' (state2vec S) (ODE2Vec ode S) = 0"
shows "\<Turnstile> {\<lambda>s tr. inv s = r \<and> tr = tra \<and> b s}
Cont ode b
{\<lambda>s tr. (\<exists>p d. tr = tra @ [WaitBlk d (\<lambda>\<tau>. State (p \<tau>)) ({}, {})] \<and> (\<forall>t\<in>{0..d}. inv (p t) = r))}"
unfolding Valid_def
apply (auto elim!: contE)
subgoal for d p
apply (rule exI[where x=p])
apply (rule exI[where x=d])
apply auto
subgoal premises pre for \<tau>
proof-
have 1: "\<forall>t\<in>{0 .. d}. ((\<lambda>t. inv(p t)) has_derivative (\<lambda>s. g' (state2vec(p t)) (s *\<^sub>R ODE2Vec ode (p t)))) (at t within {0 .. d})"
using pre assms
using chainrule[of inv "\<lambda>x. g'(state2vec x)" ode p d]
by auto
have 2: "\<forall>s. g' (state2vec(p t)) ((s *\<^sub>R 1) *\<^sub>R ODE2Vec ode (p t)) = s *\<^sub>R g' (state2vec(p t)) (1 *\<^sub>R ODE2Vec ode (p t))" if "t\<in>{0 .. d}" for t
using 1 unfolding has_derivative_def bounded_linear_def
using that linear_iff[of "(\<lambda>s. g' (state2vec(p t)) (s *\<^sub>R ODE2Vec ode (p t)))"]
by blast
have 3: "\<forall>s. (s *\<^sub>R 1) = s" by simp
have 4: "\<forall>s. g' (state2vec(p t)) (s *\<^sub>R ODE2Vec ode (p t)) = s *\<^sub>R g' (state2vec(p t)) (ODE2Vec ode (p t))" if "t\<in>{0 .. d}" for t
using 2 3 that by auto
have 5: "\<forall>s. g' (state2vec(p t)) (s *\<^sub>R ODE2Vec ode (p t))= 0" if "t\<in>{0 ..<d}" for t
using 4 assms(2) that pre by auto
show ?thesis
using mvt_real_eq[of d "(\<lambda>t. inv(p t))""\<lambda>t. (\<lambda>s. g' (state2vec(p t)) (s *\<^sub>R ODE2Vec ode (p t)))" \<tau>]
using 1 5 pre by auto
qed
done
done
text \<open>ODE with invariant\<close>
inductive ode_inv_assn :: "(state \<Rightarrow> bool) \<Rightarrow> tassn" where
"\<forall>t\<in>{0..d::real}. f (p t) \<Longrightarrow> ode_inv_assn f [WaitBlk d (\<lambda>\<tau>. State (p \<tau>)) ({}, {})]"
inductive_cases ode_inv_assn_elim: "ode_inv_assn f tr"
theorem Valid_inv':
fixes inv :: "state \<Rightarrow> real"
assumes "\<forall>x. ((\<lambda>v. inv (vec2state v)) has_derivative g' (x)) (at x within UNIV)"
and "\<forall>S. b S \<longrightarrow> g' (state2vec S) (ODE2Vec ode S) = 0"
shows "\<Turnstile> {\<lambda>s tr. inv s = r \<and> P tr \<and> b s}
Cont ode b
{\<lambda>s tr. (P @\<^sub>t ode_inv_assn (\<lambda>s. inv s = r)) tr}"
unfolding Valid_def
apply (auto elim!: contE)
subgoal for tr1 d p
apply(simp add: join_assn_def)
apply(rule exI [where x="tr1"])
apply auto
apply (auto intro!: ode_inv_assn.intros)
subgoal premises pre for \<tau>
proof-
have 1: "\<forall>t\<in>{0 .. d}. ((\<lambda>t. inv(p t)) has_derivative (\<lambda>s. g' (state2vec(p t)) (s *\<^sub>R ODE2Vec ode (p t)))) (at t within {0 .. d})"
using pre assms
using chainrule[of inv "\<lambda>x. g'(state2vec x)" ode p d]
by auto
have 2: "\<forall>s. g' (state2vec(p t)) ((s *\<^sub>R 1) *\<^sub>R ODE2Vec ode (p t)) = s *\<^sub>R g' (state2vec(p t)) (1 *\<^sub>R ODE2Vec ode (p t))" if "t\<in>{0 .. d}" for t
using 1 unfolding has_derivative_def bounded_linear_def
using that linear_iff[of "(\<lambda>s. g' (state2vec(p t)) (s *\<^sub>R ODE2Vec ode (p t)))"]
by blast
have 3: "\<forall>s. (s *\<^sub>R 1) = s" by simp
have 4: "\<forall>s. g' (state2vec(p t)) (s *\<^sub>R ODE2Vec ode (p t)) = s *\<^sub>R g' (state2vec(p t)) (ODE2Vec ode (p t))" if "t\<in>{0 .. d}" for t
using 2 3 that by auto
have 5: "\<forall>s. g' (state2vec(p t)) (s *\<^sub>R ODE2Vec ode (p t))= 0" if "t\<in>{0 ..<d}" for t
using 4 assms(2) that pre by auto
show ?thesis
using mvt_real_eq[of d "(\<lambda>t. inv(p t))""\<lambda>t. (\<lambda>s. g' (state2vec(p t)) (s *\<^sub>R ODE2Vec ode (p t)))" \<tau>]
using 1 5 pre by auto
qed
done
done
theorem Valid_ode_supp:
assumes "ode_supp (ODE ode) \<subseteq> VS"
shows "\<Turnstile> {\<lambda>s tr. supp s \<subseteq> VS}
Cont (ODE ode) b
{\<lambda>s tr. supp s \<subseteq> VS}"
unfolding Valid_def
apply (auto elim!: contE)
subgoal for v d p
unfolding supp_def apply auto
subgoal premises pre
proof(rule ccontr)
assume cond:"v \<notin> VS"
have 1:"p 0 v = 0" using pre cond by auto
have 2:"ode v = (\<lambda>_. 0)"
using assms cond by auto
have 3:"((\<lambda>t. p t v) has_vderiv_on (\<lambda>t. 0)) {0 .. d}"
using ODEsol_old[OF pre(4)]
using has_vderiv_on_proj[of "(\<lambda>t. state2vec (p t))" "(\<lambda>t. ODE2Vec (ODE ode) (p t))" "{0 .. d}" v]
apply auto
unfolding state2vec_def apply auto
using 2 by auto
then have 4:"p 0 v = p d v"
unfolding has_vderiv_on_def has_vector_derivative_def
using mvt_real_eq[of d "(\<lambda>t. p t v)" "\<lambda>t. (\<lambda>x. x *\<^sub>R 0)" d]
using pre by auto
then show False using 1 pre by auto
qed
done
done
theorem Valid_inv_barrier_s_tr_le:
fixes inv :: "state \<Rightarrow> real"
assumes "\<forall>x. ((\<lambda>v. inv (vec2state v)) has_derivative g' (x)) (at x within UNIV)"
and "\<forall>S. (b S)\<longrightarrow> ((inv S = 0) \<longrightarrow> g' (state2vec S) (ODE2Vec (ODE ode) S) < 0)"
shows "\<Turnstile> {\<lambda>s tr. inv s \<le> 0 \<and> b s \<and> P tr}
Cont (ODE ode) b
{\<lambda>s tr. inv s \<le> 0 \<and> (P @\<^sub>t ode_inv_assn (\<lambda>s. inv s \<le> 0)) tr}"
unfolding Valid_def
apply (auto elim!: contE)
subgoal premises pre for tr1 d p
proof-
obtain e where e: "e > 0" "((\<lambda>t. state2vec (p t)) has_vderiv_on (\<lambda>t. ODE2Vec (ODE ode) (p t))) {-e .. d+e}"
using pre unfolding ODEsol_def by auto
have 1: "\<forall>t\<in>{-e .. d+e}. ((\<lambda>t. inv(p t)) has_derivative (\<lambda>s. g' (state2vec(p t)) (s *\<^sub>R ODE2Vec (ODE ode) (p t)))) (at t within {-e .. d+e})"
using pre assms e
using chainrule'[of inv "\<lambda>x. g'(state2vec x)" p "(ODE ode)" e d]
by auto
have 2: "\<forall>s. g' (state2vec(p t)) ((s *\<^sub>R 1) *\<^sub>R ODE2Vec (ODE ode) (p t)) = s *\<^sub>R g' (state2vec(p t)) (1 *\<^sub>R ODE2Vec (ODE ode) (p t))" if "t\<in>{-e .. d+e}" for t
using 1 unfolding has_derivative_def bounded_linear_def
using that linear_iff[of "(\<lambda>s. g' (state2vec(p t)) (s *\<^sub>R ODE2Vec (ODE ode) (p t)))"]
by blast
have 3: "(s *\<^sub>R 1) = s" and "(1 *\<^sub>R s) = s"
apply simp by simp
have 4: "\<forall>s. g' (state2vec(p t)) (s *\<^sub>R ODE2Vec (ODE ode) (p t)) = s *\<^sub>R g' (state2vec(p t)) (ODE2Vec (ODE ode) (p t))" if "t\<in>{-e .. d+e}" for t
using 2 3 that by auto
have 5: "\<forall>t\<in>{0..<d}. inv(p t) = 0 \<longrightarrow> g' (state2vec(p t)) (ODE2Vec (ODE ode) (p t))< 0" if "t\<in>{0 ..<d}" for t
using 4 assms(2) that pre by auto
show ?thesis
using real_inv_le[OF 1, of 0]
using pre 5 e 3 by auto
qed
subgoal for tr1 d p
apply(simp add: join_assn_def)
apply(rule exI [where x="tr1"])
apply auto
apply (auto intro!: ode_inv_assn.intros)
subgoal premises pre for \<tau>
proof-
obtain e where e: "e > 0" "((\<lambda>t. state2vec (p t)) has_vderiv_on (\<lambda>t. ODE2Vec (ODE ode) (p t))) {-e .. d+e}"
using pre unfolding ODEsol_def by auto
have 1: "\<forall>t\<in>{-e .. d+e}. ((\<lambda>t. inv(p t)) has_derivative (\<lambda>s. g' (state2vec(p t)) (s *\<^sub>R ODE2Vec (ODE ode) (p t)))) (at t within {-e .. d+e})"
using pre assms e
using chainrule'[of inv "\<lambda>x. g'(state2vec x)" p "(ODE ode)" e d]
by auto
have 2: "\<forall>s. g' (state2vec(p t)) ((s *\<^sub>R 1) *\<^sub>R ODE2Vec (ODE ode) (p t)) = s *\<^sub>R g' (state2vec(p t)) (1 *\<^sub>R ODE2Vec (ODE ode) (p t))" if "t\<in>{-e .. d+e}" for t
using 1 unfolding has_derivative_def bounded_linear_def
using that linear_iff[of "(\<lambda>s. g' (state2vec(p t)) (s *\<^sub>R ODE2Vec (ODE ode) (p t)))"]
by blast
have 3: "(s *\<^sub>R 1) = s" and "(1 *\<^sub>R s) = s"
apply simp by simp
have 4: "\<forall>s. g' (state2vec(p t)) (s *\<^sub>R ODE2Vec (ODE ode) (p t)) = s *\<^sub>R g' (state2vec(p t)) (ODE2Vec (ODE ode) (p t))" if "t\<in>{-e .. d+e}" for t
using 2 3 that by auto
have 5: "inv(p t) = 0 \<longrightarrow> g' (state2vec(p t)) (ODE2Vec (ODE ode) (p t))< 0" if "t\<in>{0 ..<d}" for t
using 4 assms(2) that pre by auto
show ?thesis
using real_inv_le[OF 1, of 0]
using pre 5 e 3 by auto
qed
done
done
theorem DC:
assumes "\<Turnstile> {\<lambda>s tr. init s \<and> P tr \<and> b s}
Cont ode b
{\<lambda>s tr. (P @\<^sub>t ode_inv_assn c) tr}"
and "\<Turnstile> {\<lambda>s tr. init s \<and> P tr \<and> (\<lambda>s. b s \<and> c s) s}
Cont ode (\<lambda>s. b s \<and> c s)
{\<lambda>s tr. (P @\<^sub>t ode_inv_assn d) tr}"
shows "\<Turnstile> {\<lambda>s tr. init s \<and> P tr \<and> b s}
Cont ode b
{\<lambda>s tr. (P @\<^sub>t ode_inv_assn d) tr}"
unfolding Valid_def
apply (auto elim!: contE)
subgoal premises pre for tr T p
proof-
have 1:"big_step (Cont ode b) (p 0) [WaitBlk (ereal T) (\<lambda>\<tau>. State (p \<tau>)) ({}, {})] (p T)"
apply (rule big_step.intros)
using pre by auto
have 2:"(P @\<^sub>t ode_inv_assn c) (tr @ [WaitBlk (ereal T) (\<lambda>\<tau>. State (p \<tau>)) ({}, {})])"
using assms(1) 1
unfolding Valid_def using pre by auto
obtain tra1 tra2 where tra1:"P tra1" and tra2:"ode_inv_assn c tra2" and tra3:"tra1 @ tra2 = (tr @ [WaitBlk (ereal T) (\<lambda>\<tau>. State (p \<tau>)) ({}, {})])"
using 2 unfolding join_assn_def by auto
obtain T' p' where Tp:"tra2 = [WaitBlk (ereal T') (\<lambda>\<tau>. State (p' \<tau>)) ({}, {})]"
using tra2 apply (induct rule: ode_inv_assn.induct)
by auto
have 3:"ode_inv_assn c [WaitBlk (ereal T) (\<lambda>\<tau>. State (p \<tau>)) ({}, {})]"
using Tp tra3 tra2 by auto
have 4: "\<forall>t\<in>{0..T}. c (p t)"
using 3 apply (elim ode_inv_assn_elim)
apply auto
subgoal for d p' t
apply (frule WaitBlk_cong)
apply (frule WaitBlk_cong2)
by auto
done
have 5:"big_step (Cont ode (\<lambda>s. b s \<and> c s)) (p 0) [WaitBlk (ereal T) (\<lambda>\<tau>. State (p \<tau>)) ({}, {})] (p T)"
apply (rule big_step.intros)
using pre 4 by auto
show ?thesis
using assms(2)
unfolding Valid_def
using pre 4 5
by (smt atLeastAtMost_iff)
qed
done
end
|
Aston Villa have a large fanbase and draw support from all over the Midlands and beyond , with supporters ' clubs all across the world . Former Villa chief executive Richard Fitzgerald has stated that the ethnicity of the supporters is currently 98 % white . When Randy Lerner 's regime took over at Villa Park , they aimed to improve their support from ethnic minorities . A number of organisations have been set up to support the local community including Aston Pride . A Villa in the Community programme has also been set up to encourage support among young people in the region . The new owners have also initiated several surveys aimed at gaining the opinions of Villa fans and to involve them in the decision making process . Meetings also occur every three months where supporters are invited by ballot and are invited to ask questions to the Board . In 2011 , the club supported a supporter @-@ based initiative for an official anthem to boost the atmosphere at Villa Park . The song " The Bells Are Ringing " is to be played before games .
|
theory Benchmark_Set_LC
imports
Benchmark_Set
Containers.Set_Impl
"HOL-Library.Code_Target_Nat"
begin
lemma [code_unfold del]: "card \<equiv> Cardinality.card'" by(simp)
instantiation word :: (len0) ceq begin
definition "CEQ('a word) = Some (=)"
instance by(intro_classes)(simp add: ceq_word_def)
end
instantiation word :: (len0) compare begin
definition "compare_word = (comparator_of :: 'a word comparator)"
instance by(intro_classes)(simp add: compare_word_def comparator_of)
end
instantiation word :: (len0) ccompare begin
definition "CCOMPARE('a word) = Some compare"
instance by(intro_classes)(simp add: ccompare_word_def comparator_compare)
end
instantiation word :: (len0) set_impl begin
definition "SET_IMPL('a word) = Phantom('a word) set_RBT"
instance ..
end
instantiation word :: (len) proper_interval begin
fun proper_interval_word :: "'a word option \<Rightarrow> 'a word option \<Rightarrow> bool"
where
"proper_interval_word None None = True"
| "proper_interval_word None (Some y) = (y \<noteq> 0)"
| "proper_interval_word (Some x) None = (x \<noteq> max_word)"
| "proper_interval_word (Some x) (Some y) = (x < y \<and> x \<noteq> y - 1)"
instance
proof
let ?pi = "proper_interval :: 'a word proper_interval"
show "?pi None None = True" by simp
fix y
show "?pi None (Some y) = (\<exists>z. z < y)"
by simp (metis word_gt_0 word_not_simps(1))
fix x
show "?pi (Some x) None = (\<exists>z. x < z)"
by simp (metis eq_iff max_word_max not_le)
have "(x < y \<and> x \<noteq> y - 1) = (\<exists>z>x. z < y)" (is "?lhs \<longleftrightarrow> ?rhs")
proof
assume ?lhs
then obtain "x < y" "x \<noteq> y - 1" ..
have "0 \<le> uint x" by simp
also have "\<dots> < uint y" using \<open>x < y\<close> by(simp add: word_less_def)
finally have "0 < uint y" .
then have "y - 1 < y" by(simp add: word_less_def uint_sub_if' not_le)
moreover from \<open>0 < uint y\<close> \<open>x < y\<close> \<open>x \<noteq> y - 1\<close>
have "x < y - 1" by(simp add: word_less_def uint_sub_if' uint_arith_simps(3))
ultimately show ?rhs by blast
next
assume ?rhs
then obtain z where z: "x < z" "z < y" by blast
have "0 \<le> uint z" by simp
also have "\<dots> < uint y" using \<open>z < y\<close> by(simp add: word_less_def)
finally show ?lhs using z by(auto simp add: word_less_def uint_sub_if')
qed
thus "?pi (Some x) (Some y) = (\<exists>z>x. z < y)" by simp
qed
end
instantiation word :: (len) cproper_interval begin
definition "cproper_interval = (proper_interval :: 'a word proper_interval)"
instance by( intro_classes, simp add: cproper_interval_word_def ccompare_word_def
compare_word_def le_lt_comparator_of ID_Some proper_interval_class.axioms)
end
instantiation word :: (len0) cenum begin
definition "CENUM('a word) = None"
instance by(intro_classes)(simp_all add: cEnum_word_def)
end
notepad begin
have "Benchmark_Set.complete 30 40 (12345, 67899) = (32, 4294967296)" by eval
end
end
|
{-# OPTIONS --without-K #-}
open import Base
open import Homotopy.Connected
module Homotopy.Extensions.ProductPushoutToProductToConnected
{i j} {A A′ B B′ : Set i} (f : A → A′) (g : B → B′) (P : A′ → B′ → Set j)
{n₁ n₂} ⦃ P-is-trunc : ∀ a′ b′ → is-truncated (n₁ +2+ n₂) (P a′ b′) ⦄
(f-is-conn : has-connected-fibers n₁ f)
(g-is-conn : has-connected-fibers n₂ g)
(left* : ∀ a′ b → P a′ (g b))
(right* : ∀ a b′ → P (f a) b′)
(glue* : ∀ a b → left* (f a) b ≡ right* a (g b))
where
open import Homotopy.Truncation
open import Homotopy.Extensions.ProductPushoutToProductToConnected.Magic
{-
-- The pushout diagram you should have in your mind.
connected-extend-diag : pushout-diag i
connected-extend-diag = record
{ A = A′ × B
; B = A × B′
; C = A × B
; f = λ{(a , b) → f a , b}
; g = λ{(a , b) → a , g b}
}
-}
private
-- The first part: The extension for a fixed [a] is n₁-truncated.
extension₁ : ∀ a′ → Set (max i j)
extension₁ a′ = extension g (P a′) (left* a′)
extend-magic₁ : ∀ a′ → is-truncated n₁ (extension₁ a′)
extend-magic₁ a′ = extension-is-truncated
g g-is-conn (P a′) ⦃ P-is-trunc a′ ⦄ (left* a′)
-- The second part: The extension of extensions is contractible.
extension₂ : Set (max i j)
extension₂ = extension f extension₁ (λ a → right* a , glue* a)
abstract
extend-magic₂ : is-truncated ⟨-2⟩ extension₂
extend-magic₂ = extension-is-truncated
f f-is-conn extension₁ ⦃ extend-magic₁ ⦄ (λ a → right* a , glue* a)
extend-magic₃ : extension₂
extend-magic₃ = π₁ extend-magic₂
abstract
-- Get the buried function.
connected-extend : ∀ a′ b′ → P a′ b′
connected-extend a′ b′ = π₁ (π₁ extend-magic₃ a′) b′
-- β rules
connected-extend-β-left : ∀ a′ b → connected-extend a′ (g b) ≡ left* a′ b
connected-extend-β-left a′ b = ! $ π₂ (π₁ extend-magic₃ a′) b
connected-extend-β-right : ∀ a b′ → connected-extend (f a) b′ ≡ right* a b′
connected-extend-β-right a b′ = ! $ happly (base-path (π₂ extend-magic₃ a)) b′
private
-- This is a combination of 2~3 basic rules.
lemma₁ : ∀ a (k : ∀ b → P (f a) (g b))
{l₁ l₂ : ∀ b′ → P (f a) b′} (p : l₁ ≡ l₂) (q : ∀ b → k b ≡ l₁ (g b)) c
→ transport (λ l → ∀ b → k b ≡ l (g b)) p q c
≡ q c ∘ happly p (g c)
lemma₁ a k refl q c = ! $ refl-right-unit _
connected-extend-triangle : ∀ a b
→ connected-extend-β-left (f a) b ∘ glue* a b
≡ connected-extend-β-right a (g b)
connected-extend-triangle a b =
! (π₂ (π₁ extend-magic₃ (f a)) b) ∘ glue* a b
≡⟨ ap (λ p → ! p ∘ glue* a b) $ ! $ happly (fiber-path (π₂ extend-magic₃ a)) b ⟩
! (transport (λ l → ∀ b → left* (f a) b ≡ l (g b)) (base-path (π₂ extend-magic₃ a)) (glue* a) b) ∘ glue* a b
≡⟨ ap (λ p → ! p ∘ glue* a b)
$ lemma₁ a (left* (f a)) (base-path (π₂ extend-magic₃ a)) (glue* a) b ⟩
! (glue* a b ∘ happly (base-path (π₂ extend-magic₃ a)) (g b)) ∘ glue* a b
≡⟨ ap (λ p → p ∘ glue* a b) $ opposite-concat (glue* a b) (happly (base-path (π₂ extend-magic₃ a)) (g b)) ⟩
(connected-extend-β-right a (g b) ∘ ! (glue* a b)) ∘ glue* a b
≡⟨ concat-assoc (connected-extend-β-right a (g b)) (! (glue* a b)) (glue* a b) ⟩
connected-extend-β-right a (g b) ∘ ! (glue* a b) ∘ glue* a b
≡⟨ ap (λ p → connected-extend-β-right a (g b) ∘ p) $ opposite-left-inverse (glue* a b) ⟩
connected-extend-β-right a (g b) ∘ refl
≡⟨ refl-right-unit _ ⟩∎
connected-extend-β-right a (g b)
∎
|
section "Multivariate Polynomials Extension"
theory MPolyExtension
imports Polynomials.Polynomials (*MPoly_Type_Efficient_Code*) Polynomials.MPoly_Type_Class_FMap
begin
subsection "Definition Lifting"
lift_definition coeff_code::"'a::zero mpoly \<Rightarrow> (nat \<Rightarrow>\<^sub>0 nat) \<Rightarrow> 'a" is
"lookup" .
lemma coeff_code[code]: "coeff = coeff_code"
unfolding coeff_def apply(transfer) by auto
lemma coeff_transfer[transfer_rule]:\<comment> \<open>TODO: coeff should be defined via
lifting, this gives us the illusion\<close>
"rel_fun cr_mpoly (=) lookup coeff" using coeff_code.transfer[folded
coeff_code] .
lemmas coeff_add = coeff_add[symmetric]
lemma plus_monom_zero[simp]: "p + MPoly_Type.monom m 0 = p"
by transfer auto
lift_definition monomials::"'a::zero mpoly \<Rightarrow> (nat \<Rightarrow>\<^sub>0 nat) set" is
"Poly_Mapping.keys::((nat\<Rightarrow>\<^sub>0nat) \<Rightarrow>\<^sub>0 'a) \<Rightarrow> _ set" .
lemma mpoly_induct [case_names monom sum]:\<comment> \<open>TODO: overwrites @{thm
mpoly_induct}\<close>
assumes monom:"\<And>m a. P (MPoly_Type.monom m a)"
and sum:"(\<And>p1 p2 m a. P p1 \<Longrightarrow> P p2 \<Longrightarrow> p2 = (MPoly_Type.monom m a) \<Longrightarrow> m \<notin> monomials p1
\<Longrightarrow> a \<noteq> 0 \<Longrightarrow> P (p1+p2))"
shows "P p" using assms
proof (induction p rule: mpoly_induct)
case (sum p1 p2 m a)
then show ?case
by (cases "a = 0") (auto simp: monomials.rep_eq)
qed simp
value "monomials ((Var 0 + Const (3::int) * Var 1)^2)"
lemma Sum_any_lookup_times_eq:
"(\<Sum>k. ((lookup (x::'a\<Rightarrow>\<^sub>0('b::comm_semiring_1)) (k::'a)) * ((f:: 'a\<Rightarrow>('b::comm_semiring_1)) k))) = (\<Sum>k\<in>keys
x. (lookup x (k::'a)) * (f k))"
by (subst Sum_any.conditionalize) (auto simp: in_keys_iff intro!:
Sum_any.cong)
lemma Prod_any_power_lookup_eq:
"(\<Prod>k::'a. f k ^ lookup (x::'a\<Rightarrow>\<^sub>0nat) k) = (\<Prod>k\<in>keys x. f k ^ lookup x k)"
by (subst Prod_any.conditionalize) (auto simp: in_keys_iff intro!:
Prod_any.cong)
lemma insertion_monom: "insertion i (monom m a) = a * (\<Prod>k\<in>keys m. i k ^
lookup m k)"
by transfer (auto simp: insertion_aux_def insertion_fun_def
Sum_any_lookup_times_eq Prod_any_power_lookup_eq)
lemma monomials_monom[simp]: "monomials (monom m a) = (if a = 0 then {}
else {m})"
by transfer auto
lemma finite_monomials[simp]: "finite (monomials m)"
by transfer auto
lemma monomials_add_disjoint:
"monomials (a + b) = monomials a \<union> monomials b" if "monomials a \<inter>
monomials b = {}"
using that
by transfer (auto simp add: keys_plus_eqI)
lemma coeff_monom[simp]: "coeff (monom m a) m = a"
by transfer simp
lemma coeff_not_in_monomials[simp]: "coeff m x = 0" if "x \<notin> monomials m"
using that
by transfer (simp add: in_keys_iff)
code_thms insertion
lemma insertion_code[code]: "insertion i mp =
(\<Sum>m\<in>monomials mp. (coeff mp m) * (\<Prod>k\<in>keys m. i k ^ lookup m k))"
proof (induction mp rule: mpoly_induct)
case (monom m a)
show ?case
by (simp add: insertion_monom)
next
case (sum p1 p2 m a)
have monomials_add: "monomials (p1 + p2) = insert m (monomials p1)"
using sum.hyps
by (auto simp: monomials_add_disjoint)
have *: "coeff (monom m a) x = 0" if "x \<in> monomials p1" for x
using sum.hyps that
by (subst coeff_not_in_monomials) auto
show ?case
unfolding insertion_add monomials_add sum.IH
using sum.hyps
by (auto simp: coeff_add * algebra_simps)
qed
(* insertion f p
takes in a mapping from natural numbers to the type of the polynomial and substitutes in
the constant (f var) for each var variable in polynomial p
*)
code_thms insertion
value "insertion (nth [1, 2.3]) ((Var 0 + Const (3::int) * Var 1)^2)"
(* isolate_variable_sparse p var degree
returns the coefficient of the term a*var^degree in polynomial p
*)
lift_definition isolate_variable_sparse::"'a::comm_monoid_add mpoly \<Rightarrow>
nat \<Rightarrow> nat \<Rightarrow> 'a mpoly" is
"\<lambda>(mp::'a mpoly) x d. sum
(\<lambda>m. monomial (coeff mp m) (Poly_Mapping.update x 0 m))
{m \<in> monomials mp. lookup m x = d}" .
lemma Poly_Mapping_update_code[code]: "Poly_Mapping.update a b (Pm_fmap
fm) = Pm_fmap (fmupd a b fm)"
by (auto intro!: poly_mapping_eqI simp: update.rep_eq
fmlookup_default_def)
lemma monom_zero [simp] : "monom m 0 = 0"
by (simp add: coeff_all_0)
lemma remove_key_code[code]: "remove_key v (Pm_fmap fm) = Pm_fmap
(fmdrop v fm)"
by (auto simp: remove_key_lookup fmlookup_default_def intro!:
poly_mapping_eqI)
lemma extract_var_code[code]:
"extract_var p v =
(\<Sum>m\<in>monomials p. monom (remove_key v m) (monom (Poly_Mapping.single
v (lookup m v)) (coeff p m)))"
apply (rule extract_var_finite_set[where S="monomials p"])
using coeff_not_in_monomials by auto
value "extract_var ((Var 0 + Const (3::real) * Var 1)^2) 0"
(* degree p var
takes in polynomial p and a variable var and finds the degree of that variable in the polynomial
missing code theorems? still manages to evaluate
*)
code_thms degree
value "degree ((Var 0 + Const (3::real) * Var 1)^2) 0"
(* this function gives a set of all the variables in the polynomial
*)
lemma vars_code[code]: "vars p = \<Union> (keys ` monomials p)"
unfolding monomials.rep_eq vars_def ..
value "vars ((Var 0 + Const (3::real) * Var 1)^2)"
(* return true if the polynomial contains no variables
*)
fun is_constant :: "'a::zero mpoly \<Rightarrow> bool" where
"is_constant p = Set.is_empty (vars p)"
value "is_constant (Const (0::int))"
(*
if the polynomial is constant, returns the real value associated with the polynomial,
otherwise returns none
*)
fun get_if_const :: "real mpoly \<Rightarrow> real option" where
"get_if_const p = (if is_constant p then Some (coeff p 0) else None)"
term "coeff p 0"
lemma insertionNegative : "insertion f p = - insertion f (-p)" try
by (metis add.right_inverse eq_neg_iff_add_eq_0 insertion_add insertion_zero)
definition derivative :: "nat \<Rightarrow> real mpoly \<Rightarrow> real mpoly" where
"derivative x p = (\<Sum>i\<in>{0..degree p x-1}. isolate_variable_sparse p x (i+1) * (Var x)^i * (Const (i+1)))"
text "get\\_coeffs $x$ $p$
gets the tuple of coefficients $a$ $b$ $c$ of the term $a*x^2+b*x+c$ in polynomial $p$"
fun get_coeffs :: "nat \<Rightarrow> real mpoly \<Rightarrow> real mpoly * real mpoly * real mpoly" where
"get_coeffs var x = (
isolate_variable_sparse x var 2,
isolate_variable_sparse x var 1,
isolate_variable_sparse x var 0)
"
end
|
/**
*
* @file qwrapper_zgemv.c
*
* PLASMA core_blas quark wrapper
* PLASMA is a software package provided by Univ. of Tennessee,
* Univ. of California Berkeley and Univ. of Colorado Denver
*
* @version 2.6.0
* @author Mark Gates
* @author Mathieu Faverge
* @date 2010-11-15
* @precisions normal z -> c d s
*
**/
#include <cblas.h>
#include "common.h"
/***************************************************************************//**
*
**/
void QUARK_CORE_zgemv(Quark *quark, Quark_Task_Flags *task_flags,
PLASMA_enum trans, int m, int n,
PLASMA_Complex64_t alpha, const PLASMA_Complex64_t *A, int lda,
const PLASMA_Complex64_t *x, int incx,
PLASMA_Complex64_t beta, PLASMA_Complex64_t *y, int incy)
{
DAG_CORE_GEMV;
QUARK_Insert_Task(quark, CORE_zgemv_quark, task_flags,
sizeof(PLASMA_enum), &trans, VALUE,
sizeof(int), &m, VALUE,
sizeof(int), &n, VALUE,
sizeof(PLASMA_Complex64_t), &alpha, VALUE,
sizeof(PLASMA_Complex64_t)*m*n, A, INPUT,
sizeof(int), &lda, VALUE,
sizeof(PLASMA_Complex64_t)*n, x, INPUT,
sizeof(int), &incx, VALUE,
sizeof(PLASMA_Complex64_t), &beta, VALUE,
sizeof(PLASMA_Complex64_t)*m, y, INOUT,
sizeof(int), &incy, VALUE,
0);
}
/***************************************************************************//**
*
**/
#if defined(PLASMA_HAVE_WEAK)
#pragma weak CORE_zgemv_quark = PCORE_zgemv_quark
#define CORE_zgemv_quark PCORE_zgemv_quark
#endif
void CORE_zgemv_quark(Quark *quark)
{
PLASMA_enum trans;
int m, n, lda, incx, incy;
PLASMA_Complex64_t alpha, beta;
const PLASMA_Complex64_t *A, *x;
PLASMA_Complex64_t *y;
quark_unpack_args_11( quark, trans, m, n, alpha, A, lda, x, incx, beta, y, incy );
cblas_zgemv(
CblasColMajor,
(CBLAS_TRANSPOSE)trans,
m, n,
CBLAS_SADDR(alpha), A, lda,
x, incx,
CBLAS_SADDR(beta), y, incy);
}
|
library(shiny)
library(rsconnect)
library(RMySQL)
shinyUI(
fluidPage(
# Input: Select a file ----
fluidRow(column(2, fileInput("file", "Upload excel file", multiple = FALSE, accept = c(".xlsx")), downloadButton('download', 'Download')),
# Input: Enter the lead-time -----
column(2, sliderInput("leadtme", "Leadtime:", 7, min = 1, max =12, step=1)),
# Input : Enter the product index ------
column(1, numericInput("index", "Product Index:", 1, min = 1)),
# Input : Enter the minimum order quantity ------
column(1, numericInput("MOQ", "MOQ:", 100, min = 1)),
# Input : Enter the set-up/fixed cost ------
column(1, numericInput("fixedcost", "Set-up/fixed cost:", 2000, min = 1)),
# Input : Enter the carrying/storate cost ------
column(1, numericInput("carryingcost", "Storage/carrying cost(%):", 20, min = 1)),
# Input : Enter the service level ------
column(2, sliderInput("servicelevel", "Service level in %:", 95, min = 80, max=100, step = 1))
),
fluidRow(column(3, plotOutput("plot1")),
column(4, tableOutput("table1")),
column(3, plotOutput("plot2"))
),
fluidRow(column(10, dataTableOutput("table"))
)
)
)
|
#include <EigenFaceMaskedArray.h>
#include <EigenFace.h>
#include <EigenFaceData.h>
#include <QColor>
#include <QImage>
#include <QString>
#include <QVector>
#include <GreyImage.h>
#include <Return.h>
#include <math.h>
QImage EigenFaceMaskedArray::toImage(QImage::Format Format, bool fullMask) const
{
if ( ! isValid())
return QImage();
QSize sz(efData->mask().size());
QImage image(sz, QImage::Format_Indexed8);
image.setNumColors(256);
image.setColorTable(GreyImage::greyColorTable());
image.fill(128);
int x = 0;
for (int row = 0; row < sz.width() ; ++row)
for (int col = 0; col < sz.height(); ++col)
if (efData->mask().at(col, row))
{
if (fullMask || efData->outputMask().at(col, row))
{
qreal f = data.at(x);
if (f < 0.0)
image.setPixel(col, row, (int)128 - (128.0 * f / minData));
else
image.setPixel(col, row, (int)127 + (128.0 * f / maxData));
}
++x;
}
image = image.convertToFormat(Format);
return image;
} // toImage()
Return EigenFaceMaskedArray::fromImage(const QImage & image)
{
if ( ! efData || ! efData->isValid())
return Return(EigenFace::ReturnInvalidStructure, "FaceData");
if ( ! efData->mask().isValid())
return Return(EigenFace::ReturnInvalidStructure, "BitMask");
if ( ! efData->weights().isValid())
return Return(EigenFace::ReturnInvalidStructure, "WeightMask");
int rows = efData->eigenSize().height();
int cols = efData->eigenSize().width();
clear();
data.reserve(efData->activePixels());
qreal totalGrey = 0.0;
for (int y = 0; y < rows; ++y)
for (int x = 0; x < cols; ++x)
if (efData->mask().at(x,y))
{
qreal grey;
if (QImage::Format_Indexed8 == image.format())
{
int pixel = image.pixel(x, y);
grey = (qreal)pixel / 255.0;
}
else
{
QRgb pixel = image.pixel(x, y);
// accumulateColor(pixel);
grey = (qreal)qGray(pixel) / 255.0;
}
grey *= efData->weights().at(data.size());
totalGrey += grey;
if (grey < minData) minData = grey;
if (grey > maxData) maxData = grey;
data.append(grey);
} // if, for, for
if ( ! isValid())
return Return(EigenFace::ReturnInvalidStructure, "Invalid Count");
qreal averageGrey = totalGrey / (qreal)data.size();
qreal sumSquares = subtract(averageGrey);
qreal variance = sqrt(sumSquares);
divideBy(variance);
// IEIGENFACE_PRELIMINARY
/*
QImage varImage = toImage(QImage::Format_Indexed8, false);
varImage.save("varImage.jpg");
*/
return Return();
} // fromImage()
Return EigenFaceMaskedArray::generateEigenImage(const QImage & image, Eyes eyes)
{
if (image.isNull())
return Return(EigenFace::ReturnNullImage, "InputImage");
if ( ! efData)
return Return(EigenFace::ReturnNoData);
Eyes eigenEyes = efData->eigenEyes();
if (eigenEyes.isNull())
return Return(EigenFace::ReturnInvalidStructure, "eigenEyes");
QSize eigenSize = efData->eigenSize();
if ( ! eigenSize.isValid())
return Return(EigenFace::ReturnInvalidStructure, "eigenSize");
if (eyes.isNull())
return Return(EigenFace::ReturnNoEyes);
eigenImage = EigenFace::normalize(image, eyes, eigenSize, eigenEyes);
if (eigenImage.isNull())
return Return(EigenFace::ReturnNullImage, "EigenFace");
return Return();
} // generateEigenImage()
Return EigenFaceMaskedArray::generateEigenImage(const GreyImage & gi, Eyes eyes)
{
if (gi.isNull())
return Return(EigenFace::ReturnNullImage, "InputImage");
if ( ! efData)
return Return(EigenFace::ReturnNoData);
Eyes eigenEyes = efData->eigenEyes();
if (eigenEyes.isNull())
return Return(EigenFace::ReturnInvalidStructure, "eigenEyes");
QSize eigenSize = efData->eigenSize();
if ( ! eigenSize.isValid())
return Return(EigenFace::ReturnInvalidStructure, "eigenSize");
if (eyes.isNull())
return Return(EigenFace::ReturnNoEyes);
eigenImage = EigenFace::normalize(gi, eyes, eigenSize, eigenEyes);
if (eigenImage.isNull())
return Return(EigenFace::ReturnNullImage, "EigenFace");
return Return();
} // generateEigenImage()
Return EigenFaceMaskedArray::generate(const QImage & image,
const Eyes eyes,
const EigenFaceVectorKey vecKey)
{
Return rtn;
if ( ! efData)
return Return(EigenFace::ReturnNoData);
if ( ! efData->meanFace(vecKey.meanId()).isValid())
return Return(EigenFace::ReturnInvalidStructure, "MeanFace");
rtn = generateEigenImage(image, eyes);
if (rtn.isError())
return rtn;
rtn = fromImage(eigenImage);
if (rtn.isError())
return rtn;
Residual = subtract(efData->meanFace(vecKey.meanId()));
setVectorKey(vecKey);
return rtn;
} // generate()
Return EigenFaceMaskedArray::generate(const GreyImage & gi,
const Eyes eyes,
const EigenFaceVectorKey vecKey)
{
Return rtn;
if ( ! efData)
return Return(EigenFace::ReturnNoData);
if ( ! efData->meanFace(vecKey.meanId()).isValid())
return Return(EigenFace::ReturnInvalidStructure, "MeanFace");
rtn = generateEigenImage(gi, eyes);
if (rtn.isError())
return rtn;
rtn = fromImage(eigenImage);
if (rtn.isError())
return rtn;
Residual = subtract(efData->meanFace(vecKey.meanId()));
setVectorKey(vecKey);
return rtn;
} // generate()
|
/-
0. Read the class notes through Section
3.7, Implication. It is important that
you do this before classes next week, as
we will move somewhat quickly through a
few of these chapters.
To complete the rest of this homework,
solve the problems given as specified,
then save and submit this file.
-/
/-
1.
Show that if you're given proofs
of a = b and c = b you can construct
a proof of a = c. Do it by completing
the following function.
-/
def eq_snart { T : Type}
{ a b c: T }
(ab: a = b)
(cb: c = b) :
a = c :=
eq.trans
ab
(eq.symm cb)
/-
Now given the following assumptions, apply
your newly proved inference rule, eq.snart,
(!) to show that Harry = Bob.
-/
axiom Person : Type
axioms Harry Bob Jose: Person
axioms (hj : Harry = Bob) (jb : Jose = Bob)
example : Harry = Jose := eq_snart hj jb
/-
Note: This problem featured the use of a
logically correct but humanly midleading
identifier, hj, for a proof of Harry=Bob.
It would have been better style to call it
hb. That said, the proof goes through just
fine. Ultimately the main rules that one
must follow when it comes to identifiers
is to avoid using conflicting identifiers.
There is a more subtle rule when it comes
to the elimination for for existentially
quantified propositions. We'll get there.
For now, it's a good practice to avoid
using misleading idenifiers, even if they
are logically ok.
-/
/-
2. Use example to assert and then prove that
if T is any type, and if a, b, c, and d, are
values of that type, and if you have proofs of
a = b, b = c, and c = d, you can construct a
proof of a = d. Put the proposition in the first
placeholder below, and the proof in the second.
Hint: Aquality propositions are types. Think of
the problem here as one of producing a function
of the specific type. Use lambdas. We've gotten
you started. The first lambda "assumes" that a,
b, c, and d are natural numbers. What's left to
do is to prove a function (yes, start with lambda)
that takes three arguments of the specified kinds
(use lambda to give them names) and that finally
produces a result of the type at the end of the
chain.
-/
theorem transit :
∀ a b c d : ℕ,
(a = b) → (b = c) → (c = d) → (a = d)
:=
λ a b c d,
λ ab bc cd,
eq.trans (eq.trans ab bc) cd
/-
3. In the context of the axioms in the following
namespace, write an exact proof term to prove
that Yuanfang is friendly. Hint #1: Just apply
the relevant inference rule as a function to the
right arguments. Hint #2: The direction in which
an equality is written matters. If, for example,
you have a proof of x = y and you want to apply
an inference rule that requires a proof of y = x,
then you need to find a way to get what you need
from what you have to work with in your context.
-/
axioms Mary Yuanfang : Person
axiom Friendly : Person → Prop
axiom mf : Friendly Mary
axiom yeqm : Yuanfang = Mary
example : Friendly Yuanfang :=
eq.subst (eq.symm yeqm) mf
/-
4. The subtitution rule for equality lets
you rewrite proof goals by substituting one
term for another, in a goal, as long as you
already have a proof that the two terms
are equal. The reasoning is that replacing
one term with another makes no difference to
the truth of a proposition if the two terms
are equal.
Suppose for example that you have a proof,
h, of y = x (yes we can and do give names
to proofs, as we consider them to be values),
and a proof, y1, of y = 1, and that your
goal is to prove (x = 1). You can justify
rewriting this goal as (y = 1), for which
you already have a proof, because you know
that y = x; so making this substitution
doesn't change the truth of the proposition.
In the tactic scripting libraries that Lean
provides, there is a tactic for rewriting a
goal in this way. If h is a proof of x = y,
then the tactic, "rw h" ("rw" is short for
"rewrite") replaces all occurrences of x (the
left side of h) with y (it's right side).
Here's an example.
-/
def foo (x y : ℕ) (y1 : y = 1) (h: x = y) : (x = 1) :=
begin
rewrite h,
exact y1,
end
/-
Use what you just learned to state and prove
the proposition that for any type, T, and for
any objects, a, b, and c, of this type, if
(a = b) and (b = c) then (c = a). Do this by
finishing off the tactic script that follows.
Note that to apply an inference rule within a
tactic script you use the "apply" tactic. Read
the further explanation and hint that follow
before attempting to solve this problem.
-/
def ac (T : Type) (a b c : T)
(ab : a = b) (bc : b = c)
: (c = a) :=
begin
apply eq.symm (eq.trans ab bc)
end
/-
Note that the "foralls" in the natural language
statement are represented in this code *not* by
using ∀ but by declaring them to be arguments
to our function. If you can write a function of
the specified type then you have in effect proven
that for *any* T and any a, b, c, of type T, if
if you also have a proof of a=b and a proof of
b=c, then a value of type c=a can be constructed
and returned. The reason this is true is that in
Lean all functions are total, as you now recall!
Key hint: The tactic application "rw h" changes
all occurrences of the left side of the equality
h, in the goal, into what's on its right side.
If you want the rewriting to go from right to
left, use "rw<-h". When you're just about done,
don't be surprised if the rewrite tactic applies
rfl automatically.
-/ |
This site is the official home page of Iwakuni is a municipality of Japan.
This site, to have you know the Iwakuni also foreign visitors, we have introduced a translation service for the entire site.
이 사이트는, 일본의 자치단체인 이와쿠니시의 공식 홈페이지입니다.
당 사이트에서는, 외국 분에게도 이와쿠니시를 알아 받기 위해서, 사이트 전체의 번역 서비스를 도입하고 있습니다.
Translate by using the free translation service of an external site, the home page Iwakuni.
Because it is translated mechanically, if it is not already in the correct translation is also available. Even if there is a mistake due accuracy of the translation, we can not be held responsible for all in Iwakuni, Please note.
이와쿠니시 홈페이지를 외부 사이트 무료 번역 서비스를 이용하여 번역합니다.
기계적으로 번역되어 있기 때문에 올바른 번역이되어 있지 않은 경우도 있습니다. 번역의 정확도 의한 실수 등이 있었다고해도,이와쿠니시에서는 책임을 질 수 없기 때문에, 미리 양해 바랍니다.
By using the translation services of Google, English, Chinese, and can be translated into the Korean Iwakuni website.
Google의 번역 서비스를 이용하고, 이와쿠니시 홈페이지를 영어, 중국어,및 한글로 번역할 수 있습니다.
Copyright (C) Iwakuni City All rights reserved. |
/-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Daniel Selsam, Leonardo de Moura
Type class instance synthesizer using tabled resolution.
-/
import Lean.Meta.Basic
import Lean.Meta.Instances
import Lean.Meta.AbstractMVars
import Lean.Meta.WHNF
import Lean.Meta.Check
import Lean.Util.Profile
namespace Lean.Meta
register_builtin_option synthInstance.maxHeartbeats : Nat := {
defValue := 20000
descr := "maximum amount of heartbeats per typeclass resolution problem. A heartbeat is number of (small) memory allocations (in thousands), 0 means no limit"
}
register_builtin_option synthInstance.maxSize : Nat := {
defValue := 128
descr := "maximum number of instances used to construct a solution in the type class instance synthesis procedure"
}
register_builtin_option synthInstance.etaExperiment : Bool := {
defValue := false
descr := "[DO NOT USE EXCEPT FOR TESTING] enable structure eta for type-classes during type-class search"
}
namespace SynthInstance
def getMaxHeartbeats (opts : Options) : Nat :=
synthInstance.maxHeartbeats.get opts * 1000
builtin_initialize inferTCGoalsRLAttr : TagAttribute ←
registerTagAttribute `infer_tc_goals_rl "instruct type class resolution procedure to solve goals from right to left for this instance"
def hasInferTCGoalsRLAttribute (env : Environment) (constName : Name) : Bool :=
inferTCGoalsRLAttr.hasTag env constName
structure GeneratorNode where
mvar : Expr
key : Expr
mctx : MetavarContext
instances : Array Expr
currInstanceIdx : Nat
deriving Inhabited
structure ConsumerNode where
mvar : Expr
key : Expr
mctx : MetavarContext
subgoals : List Expr
size : Nat -- instance size so far
deriving Inhabited
inductive Waiter where
| consumerNode : ConsumerNode → Waiter
| root : Waiter
def Waiter.isRoot : Waiter → Bool
| Waiter.consumerNode _ => false
| Waiter.root => true
/-!
In tabled resolution, we creating a mapping from goals (e.g., `Coe Nat ?x`) to
answers and waiters. Waiters are consumer nodes that are waiting for answers for a
particular node.
We implement this mapping using a `HashMap` where the keys are
normalized expressions. That is, we replace assignable metavariables
with auxiliary free variables of the form `_tc.<idx>`. We do
not declare these free variables in any local context, and we should
view them as "normalized names" for metavariables. For example, the
term `f ?m ?m ?n` is normalized as
`f _tc.0 _tc.0 _tc.1`.
This approach is structural, and we may visit the same goal more
than once if the different occurrences are just definitionally
equal, but not structurally equal.
Remark: a metavariable is assignable only if its depth is equal to
the metavar context depth.
-/
namespace MkTableKey
structure State where
nextIdx : Nat := 0
lmap : HashMap LMVarId Level := {}
emap : HashMap MVarId Expr := {}
mctx : MetavarContext
abbrev M := StateM State
@[always_inline]
instance : MonadMCtx M where
getMCtx := return (← get).mctx
modifyMCtx f := modify fun s => { s with mctx := f s.mctx }
partial def normLevel (u : Level) : M Level := do
if !u.hasMVar then
return u
else match u with
| Level.succ v => return u.updateSucc! (← normLevel v)
| Level.max v w => return u.updateMax! (← normLevel v) (← normLevel w)
| Level.imax v w => return u.updateIMax! (← normLevel v) (← normLevel w)
| Level.mvar mvarId =>
if (← getMCtx).getLevelDepth mvarId != (← getMCtx).depth then
return u
else
let s ← get
match (← get).lmap.find? mvarId with
| some u' => pure u'
| none =>
let u' := mkLevelParam <| Name.mkNum `_tc s.nextIdx
modify fun s => { s with nextIdx := s.nextIdx + 1, lmap := s.lmap.insert mvarId u' }
return u'
| u => return u
partial def normExpr (e : Expr) : M Expr := do
if !e.hasMVar then
pure e
else match e with
| Expr.const _ us => return e.updateConst! (← us.mapM normLevel)
| Expr.sort u => return e.updateSort! (← normLevel u)
| Expr.app f a => return e.updateApp! (← normExpr f) (← normExpr a)
| Expr.letE _ t v b _ => return e.updateLet! (← normExpr t) (← normExpr v) (← normExpr b)
| Expr.forallE _ d b _ => return e.updateForallE! (← normExpr d) (← normExpr b)
| Expr.lam _ d b _ => return e.updateLambdaE! (← normExpr d) (← normExpr b)
| Expr.mdata _ b => return e.updateMData! (← normExpr b)
| Expr.proj _ _ b => return e.updateProj! (← normExpr b)
| Expr.mvar mvarId =>
if !(← mvarId.isAssignable) then
return e
else
let s ← get
match s.emap.find? mvarId with
| some e' => pure e'
| none => do
let e' := mkFVar { name := Name.mkNum `_tc s.nextIdx }
modify fun s => { s with nextIdx := s.nextIdx + 1, emap := s.emap.insert mvarId e' }
return e'
| _ => return e
end MkTableKey
/-- Remark: `mkTableKey` assumes `e` does not contain assigned metavariables. -/
def mkTableKey [Monad m] [MonadMCtx m] (e : Expr) : m Expr := do
let (r, s) := MkTableKey.normExpr e |>.run { mctx := (← getMCtx) }
setMCtx s.mctx
return r
structure Answer where
result : AbstractMVarsResult
resultType : Expr
size : Nat
deriving Inhabited
structure TableEntry where
waiters : Array Waiter
answers : Array Answer := #[]
structure Context where
maxResultSize : Nat
maxHeartbeats : Nat
/--
Remark: the SynthInstance.State is not really an extension of `Meta.State`.
The field `postponed` is not needed, and the field `mctx` is misleading since
`synthInstance` methods operate over different `MetavarContext`s simultaneously.
That being said, we still use `extends` because it makes it simpler to move from
`M` to `MetaM`.
-/
structure State where
result? : Option AbstractMVarsResult := none
generatorStack : Array GeneratorNode := #[]
resumeStack : Array (ConsumerNode × Answer) := #[]
tableEntries : HashMap Expr TableEntry := {}
abbrev SynthM := ReaderT Context $ StateRefT State MetaM
def checkMaxHeartbeats : SynthM Unit := do
Core.checkMaxHeartbeatsCore "typeclass" `synthInstance.maxHeartbeats (← read).maxHeartbeats
@[inline] def mapMetaM (f : forall {α}, MetaM α → MetaM α) {α} : SynthM α → SynthM α :=
monadMap @f
instance : Inhabited (SynthM α) where
default := fun _ _ => default
/-- Return globals and locals instances that may unify with `type` -/
def getInstances (type : Expr) : MetaM (Array Expr) := do
-- We must retrieve `localInstances` before we use `forallTelescopeReducing` because it will update the set of local instances
let localInstances ← getLocalInstances
forallTelescopeReducing type fun _ type => do
let className? ← isClass? type
match className? with
| none => throwError "type class instance expected{indentExpr type}"
| some className =>
let globalInstances ← getGlobalInstancesIndex
let result ← globalInstances.getUnify type
-- Using insertion sort because it is stable and the array `result` should be mostly sorted.
-- Most instances have default priority.
let result := result.insertionSort fun e₁ e₂ => e₁.priority < e₂.priority
let erasedInstances ← getErasedInstances
let result ← result.filterMapM fun e => match e.val with
| Expr.const constName us =>
if erasedInstances.contains constName then
return none
else
return some <| e.val.updateConst! (← us.mapM (fun _ => mkFreshLevelMVar))
| _ => panic! "global instance is not a constant"
let result := localInstances.foldl (init := result) fun (result : Array Expr) linst =>
if linst.className == className then result.push linst.fvar else result
trace[Meta.synthInstance.instances] result
return result
def mkGeneratorNode? (key mvar : Expr) : MetaM (Option GeneratorNode) := do
let mvarType ← inferType mvar
let mvarType ← instantiateMVars mvarType
let instances ← getInstances mvarType
if instances.isEmpty then
return none
else
let mctx ← getMCtx
return some {
mvar, key, mctx, instances
currInstanceIdx := instances.size
}
/--
Create a new generator node for `mvar` and add `waiter` as its waiter.
`key` must be `mkTableKey mctx mvarType`. -/
def newSubgoal (mctx : MetavarContext) (key : Expr) (mvar : Expr) (waiter : Waiter) : SynthM Unit :=
withMCtx mctx do withTraceNode' `Meta.synthInstance do
match (← mkGeneratorNode? key mvar) with
| none => pure ((), m!"no instances for {key}")
| some node =>
let entry : TableEntry := { waiters := #[waiter] }
modify fun s =>
{ s with
generatorStack := s.generatorStack.push node
tableEntries := s.tableEntries.insert key entry }
pure ((), m!"new goal {key}")
def findEntry? (key : Expr) : SynthM (Option TableEntry) := do
return (← get).tableEntries.find? key
def getEntry (key : Expr) : SynthM TableEntry := do
match (← findEntry? key) with
| none => panic! "invalid key at synthInstance"
| some entry => pure entry
/--
Create a `key` for the goal associated with the given metavariable.
That is, we create a key for the type of the metavariable.
We must instantiate assigned metavariables before we invoke `mkTableKey`. -/
def mkTableKeyFor (mctx : MetavarContext) (mvar : Expr) : SynthM Expr :=
withMCtx mctx do
let mvarType ← inferType mvar
let mvarType ← instantiateMVars mvarType
mkTableKey mvarType
/-- See `getSubgoals` and `getSubgoalsAux`
We use the parameter `j` to reduce the number of `instantiate*` invocations.
It is the same approach we use at `forallTelescope` and `lambdaTelescope`.
Given `getSubgoalsAux args j subgoals instVal type`,
we have that `type.instantiateRevRange j args.size args` does not have loose bound variables. -/
structure SubgoalsResult where
subgoals : List Expr
instVal : Expr
instTypeBody : Expr
private partial def getSubgoalsAux (lctx : LocalContext) (localInsts : LocalInstances) (xs : Array Expr)
: Array Expr → Nat → List Expr → Expr → Expr → MetaM SubgoalsResult
| args, j, subgoals, instVal, Expr.forallE _ d b bi => do
let d := d.instantiateRevRange j args.size args
let mvarType ← mkForallFVars xs d
let mvar ← mkFreshExprMVarAt lctx localInsts mvarType
let arg := mkAppN mvar xs
let instVal := mkApp instVal arg
let subgoals := if bi.isInstImplicit then mvar::subgoals else subgoals
let args := args.push (mkAppN mvar xs)
getSubgoalsAux lctx localInsts xs args j subgoals instVal b
| args, j, subgoals, instVal, type => do
let type := type.instantiateRevRange j args.size args
let type ← whnf type
if type.isForall then
getSubgoalsAux lctx localInsts xs args args.size subgoals instVal type
else
return ⟨subgoals, instVal, type⟩
/--
`getSubgoals lctx localInsts xs inst` creates the subgoals for the instance `inst`.
The subgoals are in the context of the free variables `xs`, and
`(lctx, localInsts)` is the local context and instances before we added the free variables to it.
This extra complication is required because
1- We want all metavariables created by `synthInstance` to share the same local context.
2- We want to ensure that applications such as `mvar xs` are higher order patterns.
The method `getGoals` create a new metavariable for each parameter of `inst`.
For example, suppose the type of `inst` is `forall (x_1 : A_1) ... (x_n : A_n), B x_1 ... x_n`.
Then, we create the metavariables `?m_i : forall xs, A_i`, and return the subset of these
metavariables that are instance implicit arguments, and the expressions:
- `inst (?m_1 xs) ... (?m_n xs)` (aka `instVal`)
- `B (?m_1 xs) ... (?m_n xs)` -/
def getSubgoals (lctx : LocalContext) (localInsts : LocalInstances) (xs : Array Expr) (inst : Expr) : MetaM SubgoalsResult := do
let instType ← inferType inst
let result ← getSubgoalsAux lctx localInsts xs #[] 0 [] inst instType
if let .const constName _ := inst.getAppFn then
let env ← getEnv
if hasInferTCGoalsRLAttribute env constName then
return result
return { result with subgoals := result.subgoals.reverse }
/--
Try to synthesize metavariable `mvar` using the instance `inst`.
Remark: `mctx` is set using `withMCtx`.
If it succeeds, the result is a new updated metavariable context and a new list of subgoals.
A subgoal is created for each instance implicit parameter of `inst`. -/
def tryResolve (mvar : Expr) (inst : Expr) : MetaM (Option (MetavarContext × List Expr)) := do
let mvarType ← inferType mvar
let lctx ← getLCtx
let localInsts ← getLocalInstances
forallTelescopeReducing mvarType fun xs mvarTypeBody => do
let ⟨subgoals, instVal, instTypeBody⟩ ← getSubgoals lctx localInsts xs inst
withTraceNode `Meta.synthInstance.tryResolve (withMCtx (← getMCtx) do
return m!"{exceptOptionEmoji ·} {← instantiateMVars mvarTypeBody} ≟ {← instantiateMVars instTypeBody}") do
if (← isDefEq mvarTypeBody instTypeBody) then
let instVal ← mkLambdaFVars xs instVal
if (← isDefEq mvar instVal) then
return some ((← getMCtx), subgoals)
return none
/--
Assign a precomputed answer to `mvar`.
If it succeeds, the result is a new updated metavariable context and a new list of subgoals. -/
def tryAnswer (mctx : MetavarContext) (mvar : Expr) (answer : Answer) : SynthM (Option MetavarContext) :=
withMCtx mctx do
let (_, _, val) ← openAbstractMVarsResult answer.result
if (← isDefEq mvar val) then
return some (← getMCtx)
else
return none
/-- Move waiters that are waiting for the given answer to the resume stack. -/
def wakeUp (answer : Answer) : Waiter → SynthM Unit
| Waiter.root => do
/- Recall that we now use `ignoreLevelMVarDepth := true`. Thus, we should allow solutions
containing universe metavariables, and not check `answer.result.paramNames.isEmpty`.
We use `openAbstractMVarsResult` to construct the universe metavariables
at the correct depth. -/
if answer.result.numMVars == 0 then
modify fun s => { s with result? := answer.result }
else
let (_, _, answerExpr) ← openAbstractMVarsResult answer.result
trace[Meta.synthInstance] "skip answer containing metavariables {answerExpr}"
| Waiter.consumerNode cNode =>
modify fun s => { s with resumeStack := s.resumeStack.push (cNode, answer) }
def isNewAnswer (oldAnswers : Array Answer) (answer : Answer) : Bool :=
oldAnswers.all fun oldAnswer =>
-- Remark: isDefEq here is too expensive. TODO: if `==` is too imprecise, add some light normalization to `resultType` at `addAnswer`
-- iseq ← isDefEq oldAnswer.resultType answer.resultType; pure (!iseq)
oldAnswer.resultType != answer.resultType
private def mkAnswer (cNode : ConsumerNode) : MetaM Answer :=
withMCtx cNode.mctx do
let val ← instantiateMVars cNode.mvar
trace[Meta.synthInstance.newAnswer] "size: {cNode.size}, val: {val}"
let result ← abstractMVars val -- assignable metavariables become parameters
let resultType ← inferType result.expr
return { result, resultType, size := cNode.size + 1 }
/--
Create a new answer after `cNode` resolved all subgoals.
That is, `cNode.subgoals == []`.
And then, store it in the tabled entries map, and wakeup waiters. -/
def addAnswer (cNode : ConsumerNode) : SynthM Unit := do
withMCtx cNode.mctx do
if cNode.size ≥ (← read).maxResultSize then
trace[Meta.synthInstance.answer] "{crossEmoji} {← instantiateMVars (← inferType cNode.mvar)}{Format.line}(size: {cNode.size} ≥ {(← read).maxResultSize})"
else
withTraceNode `Meta.synthInstance.answer
(fun _ => return m!"{checkEmoji} {← instantiateMVars (← inferType cNode.mvar)}") do
let answer ← mkAnswer cNode
-- Remark: `answer` does not contain assignable or assigned metavariables.
let key := cNode.key
let entry ← getEntry key
if isNewAnswer entry.answers answer then
let newEntry := { entry with answers := entry.answers.push answer }
modify fun s => { s with tableEntries := s.tableEntries.insert key newEntry }
entry.waiters.forM (wakeUp answer)
/--
Return `true` if a type of the form `(a_1 : A_1) → ... → (a_n : A_n) → B` has an unused argument `a_i`.
Remark: This is syntactic check and no reduction is performed.
-/
private def hasUnusedArguments : Expr → Bool
| Expr.forallE _ _ b _ => !b.hasLooseBVar 0 || hasUnusedArguments b
| _ => false
/--
If the type of the metavariable `mvar` has unused argument, return a pair `(α, transformer)`
where `α` is a new type without the unused arguments and the `transformer` is a function for coverting a
solution with type `α` into a value that can be assigned to `mvar`.
Example: suppose `mvar` has type `(a : A) → (b : B a) → (c : C a) → D a c`, the result is the pair
```
((a : A) → (c : C a) → D a c,
fun (f : (a : A) → (c : C a) → D a c) (a : A) (b : B a) (c : C a) => f a c
)
```
This method is used to improve the effectiveness of the TC resolution procedure. It was suggested and prototyped by
Tomas Skrivan. It improves the support for instances of type `a : A → C` where `a` does not appear in class `C`.
When we look for such an instance it is enough to look for an instance `c : C` and then return `fun _ => c`.
Tomas' approach makes sure that instance of a type like `a : A → C` never gets tabled/cached. More on that later.
At the core is this method. it takes an expression E and does two things:
The modification to TC resolution works this way: We are looking for an instance of `E`, if it is tabled
just get it as normal, but if not first remove all unused arguments producing `E'`. Now we look up the table again but
for `E'`. If it exists, use the transformer to create E. If it does not exists, create a new goal `E'`.
-/
private def removeUnusedArguments? (mctx : MetavarContext) (mvar : Expr) : MetaM (Option (Expr × Expr)) :=
withMCtx mctx do
let mvarType ← instantiateMVars (← inferType mvar)
if !hasUnusedArguments mvarType then
return none
else
forallTelescope mvarType fun xs body => do
let ys ← xs.foldrM (init := []) fun x ys => do
if body.containsFVar x.fvarId! then
return x :: ys
else if (← ys.anyM fun y => return (← inferType y).containsFVar x.fvarId!) then
return x :: ys
else
return ys
let ys := ys.toArray
let mvarType' ← mkForallFVars ys body
withLocalDeclD `redf mvarType' fun f => do
let transformer ← mkLambdaFVars #[f] (← mkLambdaFVars xs (mkAppN f ys))
trace[Meta.synthInstance.unusedArgs] "{mvarType}\nhas unused arguments, reduced type{indentExpr mvarType'}\nTransformer{indentExpr transformer}"
return some (mvarType', transformer)
/-- Process the next subgoal in the given consumer node. -/
def consume (cNode : ConsumerNode) : SynthM Unit := do
/- Filter out subgoals that have already been assigned when solving typing constraints.
This may happen when a local instance type depends on other local instances.
For example, in Mathlib, we have
```
@Submodule.setLike : {R : Type u_1} → {M : Type u_2} →
[_inst_1 : Semiring R] →
[_inst_2 : AddCommMonoid M] →
[_inst_3 : @ModuleS R M _inst_1 _inst_2] →
SetLike (@Submodule R M _inst_1 _inst_2 _inst_3) M
```
-/
let cNode := { cNode with
subgoals := ← withMCtx cNode.mctx do
cNode.subgoals.filterM (not <$> ·.mvarId!.isAssigned)
}
match cNode.subgoals with
| [] => addAnswer cNode
| mvar::_ =>
let waiter := Waiter.consumerNode cNode
let key ← mkTableKeyFor cNode.mctx mvar
let entry? ← findEntry? key
match entry? with
| none =>
-- Remove unused arguments and try again, see comment at `removeUnusedArguments?`
match (← removeUnusedArguments? cNode.mctx mvar) with
| none => newSubgoal cNode.mctx key mvar waiter
| some (mvarType', transformer) =>
let key' ← withMCtx cNode.mctx <| mkTableKey mvarType'
match (← findEntry? key') with
| none =>
let (mctx', mvar') ← withMCtx cNode.mctx do
let mvar' ← mkFreshExprMVar mvarType'
return (← getMCtx, mvar')
newSubgoal mctx' key' mvar' (Waiter.consumerNode { cNode with mctx := mctx', subgoals := mvar'::cNode.subgoals })
| some entry' =>
let answers' ← entry'.answers.mapM fun a => withMCtx cNode.mctx do
let trAnswr := Expr.betaRev transformer #[← instantiateMVars a.result.expr]
let trAnswrType ← inferType trAnswr
pure { a with result.expr := trAnswr, resultType := trAnswrType }
modify fun s =>
{ s with
resumeStack := answers'.foldl (fun s answer => s.push (cNode, answer)) s.resumeStack,
tableEntries := s.tableEntries.insert key' { entry' with waiters := entry'.waiters.push waiter } }
| some entry => modify fun s =>
{ s with
resumeStack := entry.answers.foldl (fun s answer => s.push (cNode, answer)) s.resumeStack,
tableEntries := s.tableEntries.insert key { entry with waiters := entry.waiters.push waiter } }
def getTop : SynthM GeneratorNode :=
return (← get).generatorStack.back
@[inline] def modifyTop (f : GeneratorNode → GeneratorNode) : SynthM Unit :=
modify fun s => { s with generatorStack := s.generatorStack.modify (s.generatorStack.size - 1) f }
/-- Try the next instance in the node on the top of the generator stack. -/
def generate : SynthM Unit := do
let gNode ← getTop
if gNode.currInstanceIdx == 0 then
modify fun s => { s with generatorStack := s.generatorStack.pop }
else
let key := gNode.key
let idx := gNode.currInstanceIdx - 1
let inst := gNode.instances.get! idx
let mctx := gNode.mctx
let mvar := gNode.mvar
discard do withMCtx mctx do
withTraceNode `Meta.synthInstance
(return m!"{exceptOptionEmoji ·} apply {inst} to {← instantiateMVars (← inferType mvar)}") do
modifyTop fun gNode => { gNode with currInstanceIdx := idx }
if let some (mctx, subgoals) ← tryResolve mvar inst then
consume { key, mvar, subgoals, mctx, size := 0 }
return some ()
return none
def getNextToResume : SynthM (ConsumerNode × Answer) := do
let r := (← get).resumeStack.back
modify fun s => { s with resumeStack := s.resumeStack.pop }
return r
/--
Given `(cNode, answer)` on the top of the resume stack, continue execution by using `answer` to solve the
next subgoal. -/
def resume : SynthM Unit := do
let (cNode, answer) ← getNextToResume
match cNode.subgoals with
| [] => panic! "resume found no remaining subgoals"
| mvar::rest =>
match (← tryAnswer cNode.mctx mvar answer) with
| none => return ()
| some mctx =>
withMCtx mctx do
let goal ← inferType cNode.mvar
let subgoal ← inferType mvar
withTraceNode `Meta.synthInstance.resume
(fun _ => withMCtx cNode.mctx do
return m!"propagating {← instantiateMVars answer.resultType} to subgoal {← instantiateMVars subgoal} of {← instantiateMVars goal}") do
trace[Meta.synthInstance.resume] "size: {cNode.size + answer.size}"
consume { key := cNode.key, mvar := cNode.mvar, subgoals := rest, mctx, size := cNode.size + answer.size }
def step : SynthM Bool := do
checkMaxHeartbeats
let s ← get
if !s.resumeStack.isEmpty then
resume
return true
else if !s.generatorStack.isEmpty then
generate
return true
else
return false
def getResult : SynthM (Option AbstractMVarsResult) :=
return (← get).result?
partial def synth : SynthM (Option AbstractMVarsResult) := do
if (← step) then
match (← getResult) with
| none => synth
| some result => return result
else
return none
def main (type : Expr) (maxResultSize : Nat) : MetaM (Option AbstractMVarsResult) :=
withCurrHeartbeats do
let mvar ← mkFreshExprMVar type
let key ← mkTableKey type
let action : SynthM (Option AbstractMVarsResult) := do
newSubgoal (← getMCtx) key mvar Waiter.root
synth
try
action.run { maxResultSize := maxResultSize, maxHeartbeats := getMaxHeartbeats (← getOptions) } |>.run' {}
catch ex =>
if ex.isMaxHeartbeat then
throwError "failed to synthesize{indentExpr type}\n{ex.toMessageData}"
else
throw ex
end SynthInstance
/-!
Type class parameters can be annotated with `outParam` annotations.
Given `C a_1 ... a_n`, we replace `a_i` with a fresh metavariable `?m_i` IF
`a_i` is an `outParam`.
The result is type correct because we reject type class declarations IF
it contains a regular parameter X that depends on an `out` parameter Y.
Then, we execute type class resolution as usual.
If it succeeds, and metavariables ?m_i have been assigned, we try to unify
the original type `C a_1 ... a_n` witht the normalized one.
-/
private def preprocess (type : Expr) : MetaM Expr :=
forallTelescopeReducing type fun xs type => do
let type ← whnf type
mkForallFVars xs type
private def preprocessLevels (us : List Level) : MetaM (List Level × Bool) := do
let mut r := #[]
let mut modified := false
for u in us do
let u ← instantiateLevelMVars u
if u.hasMVar then
r := r.push (← mkFreshLevelMVar)
modified := true
else
r := r.push u
return (r.toList, modified)
private partial def preprocessArgs (type : Expr) (i : Nat) (args : Array Expr) (outParamsPos : Array Nat) : MetaM (Array Expr) := do
if h : i < args.size then
let type ← whnf type
match type with
| .forallE _ d b _ => do
let arg := args.get ⟨i, h⟩
/-
We should not simply check `d.isOutParam`. See `checkOutParam` and issue #1852.
If an instance implicit argument depends on an `outParam`, it is treated as an `outParam` too.
-/
let arg ← if outParamsPos.contains i then mkFreshExprMVar d else pure arg
let args := args.set ⟨i, h⟩ arg
preprocessArgs (b.instantiate1 arg) (i+1) args outParamsPos
| _ =>
throwError "type class resolution failed, insufficient number of arguments" -- TODO improve error message
else
return args
private def preprocessOutParam (type : Expr) : MetaM Expr :=
forallTelescope type fun xs typeBody => do
match typeBody.getAppFn with
| c@(Expr.const declName _) =>
let env ← getEnv
if let some outParamsPos := getOutParamPositions? env declName then
unless outParamsPos.isEmpty do
let args := typeBody.getAppArgs
let cType ← inferType c
let args ← preprocessArgs cType 0 args outParamsPos
return (← mkForallFVars xs (mkAppN c args))
return type
| _ =>
return type
/-!
Remark: when `maxResultSize? == none`, the configuration option `synthInstance.maxResultSize` is used.
Remark: we use a different option for controlling the maximum result size for coercions.
-/
def synthInstance? (type : Expr) (maxResultSize? : Option Nat := none) : MetaM (Option Expr) := do profileitM Exception "typeclass inference" (← getOptions) (decl := type.getAppFn.constName?.getD .anonymous) do
let opts ← getOptions
let maxResultSize := maxResultSize?.getD (synthInstance.maxSize.get opts)
withTraceNode `Meta.synthInstance
(return m!"{exceptOptionEmoji ·} {← instantiateMVars type}") do
/-
We disable eta for structures that are not classes during TC resolution because it allows us to find unintended solutions.
See discussion at
https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/.60constructor.60.20and.20.60Applicative.60/near/279984801
-/
let etaStruct := if synthInstance.etaExperiment.get (← getOptions) then .all else .notClasses
withConfig (fun config => { config with isDefEqStuckEx := true, transparency := TransparencyMode.instances,
foApprox := true, ctxApprox := true, constApprox := false,
etaStruct }) do
let localInsts ← getLocalInstances
let type ← instantiateMVars type
let type ← preprocess type
let s ← get
let rec assignOutParams (result : Expr) : MetaM Bool := do
let resultType ← inferType result
/- Output parameters of local instances may be marked as `syntheticOpaque` by the application-elaborator.
We use `withAssignableSyntheticOpaque` to make sure this kind of parameter can be assigned by the following `isDefEq`.
TODO: rewrite this check to avoid `withAssignableSyntheticOpaque`. -/
let defEq ← withDefault <| withAssignableSyntheticOpaque <| isDefEq type resultType
unless defEq do
trace[Meta.synthInstance] "{crossEmoji} result type{indentExpr resultType}\nis not definitionally equal to{indentExpr type}"
return defEq
match s.cache.synthInstance.find? (localInsts, type) with
| some result =>
trace[Meta.synthInstance] "result {result} (cached)"
if let some inst := result then
unless (← assignOutParams inst) do
return none
pure result
| none =>
let result? ← withNewMCtxDepth (allowLevelAssignments := true) do
let normType ← preprocessOutParam type
SynthInstance.main normType maxResultSize
let result? ← match result? with
| none => pure none
| some result => do
let (_, _, result) ← openAbstractMVarsResult result
trace[Meta.synthInstance] "result {result}"
if (← assignOutParams result) then
let result ← instantiateMVars result
/- We use `check` to propogate universe constraints implied by the `result`.
Recall that we use `allowLevelAssignments := true` which allows universe metavariables in the current depth to be assigned,
but these assignments are discarded by `withNewMCtxDepth`.
TODO: If this `check` is a performance bottleneck, we can improve performance by tracking whether
a universe metavariable from previous universe levels have been assigned or not during TC resolution.
We only need to perform the `check` if this kind of assignment have been performed.
The example in the issue #796 exposed this issue.
```
structure A
class B (a : outParam A) (α : Sort u)
class C {a : A} (α : Sort u) [B a α]
class D {a : A} (α : Sort u) [B a α] [c : C α]
class E (a : A) where [c (α : Sort u) [B a α] : C α]
instance c {a : A} [e : E a] (α : Sort u) [B a α] : C α := e.c α
def d {a : A} [e : E a] (α : Sort u) [b : B a α] : D α := ⟨⟩
```
The term `D α` has two instance implicit arguments. The second one has type `C α`, and TC
resolution produces the result `@c.{u} a e α b`.
Note that the `e` has type `E.{?v} a`, and `E` is universe polymorphic,
but the universe does not occur in the parameter `a`. We have that `?v := u` is implied by `@c.{u} a e α b`,
but this assignment is lost.
-/
check result
pure (some result)
else
pure none
modify fun s => { s with cache.synthInstance := s.cache.synthInstance.insert (localInsts, type) result? }
pure result?
/--
Return `LOption.some r` if succeeded, `LOption.none` if it failed, and `LOption.undef` if
instance cannot be synthesized right now because `type` contains metavariables. -/
def trySynthInstance (type : Expr) (maxResultSize? : Option Nat := none) : MetaM (LOption Expr) := do
catchInternalId isDefEqStuckExceptionId
(toLOptionM <| synthInstance? type maxResultSize?)
(fun _ => pure LOption.undef)
def synthInstance (type : Expr) (maxResultSize? : Option Nat := none) : MetaM Expr :=
catchInternalId isDefEqStuckExceptionId
(do
let result? ← synthInstance? type maxResultSize?
match result? with
| some result => pure result
| none => throwError "failed to synthesize{indentExpr type}")
(fun _ => throwError "failed to synthesize{indentExpr type}")
@[export lean_synth_pending]
private def synthPendingImp (mvarId : MVarId) : MetaM Bool := withIncRecDepth <| mvarId.withContext do
let mvarDecl ← mvarId.getDecl
match mvarDecl.kind with
| MetavarKind.syntheticOpaque =>
return false
| _ =>
/- Check whether the type of the given metavariable is a class or not. If yes, then try to synthesize
it using type class resolution. We only do it for `synthetic` and `natural` metavariables. -/
match (← isClass? mvarDecl.type) with
| none =>
return false
| some _ =>
/- TODO: use a configuration option instead of the hard-coded limit `1`. -/
if (← read).synthPendingDepth > 1 then
trace[Meta.synthPending] "too many nested synthPending invocations"
return false
else
withReader (fun ctx => { ctx with synthPendingDepth := ctx.synthPendingDepth + 1 }) do
trace[Meta.synthPending] "synthPending {mkMVar mvarId}"
let val? ← catchInternalId isDefEqStuckExceptionId (synthInstance? mvarDecl.type (maxResultSize? := none)) (fun _ => pure none)
match val? with
| none =>
return false
| some val =>
if (← mvarId.isAssigned) then
return false
else
mvarId.assign val
return true
builtin_initialize
registerTraceClass `Meta.synthPending
registerTraceClass `Meta.synthInstance
registerTraceClass `Meta.synthInstance.instances (inherited := true)
registerTraceClass `Meta.synthInstance.tryResolve (inherited := true)
registerTraceClass `Meta.synthInstance.resume (inherited := true)
registerTraceClass `Meta.synthInstance.unusedArgs
registerTraceClass `Meta.synthInstance.newAnswer
end Lean.Meta
|
# This example shows you how to use the R6 class ParameterFile. That being said, it is quite simple to just copy-paste the parameter you want from the logfile type 2 rather than using my ParameterFile interface if you prefer.
# Note that the graph will likely not be good looking. You will need to play around with the ggnet function to get exactly the graph you want. The purpose of this script is just to show you a small example of what you could do to graph parameters that are being printed on the logfile type 2
###########################
##### Instal packages #####
###########################
needed_packages <- c("network", "ggplot2", "GGally")
need_to_install_packages = setdiff(needed_packages, rownames(installed.packages()))
if (length(need_to_install_packages) > 0) {
cat(paste("I will try to install the following package(s):", paste(need_to_install_packages, collapse=", ")))
install.packages(need_to_install_packages)
}
for (needed_package in needed_packages)
{
require(needed_package, character.only=TRUE)
}
###################################
##### Load log file of type 2 #####
###################################
paramFile = ParameterFile$new("/Users/remi/Documents/Biologie/programming/PopGenSimulator/SimBit/log.log")
##########################
##### Get parameters #####
##########################
generations = paramFile$readParameter("__GenerationChange") # Contains a vector of the generations at which there were temporal changes (with the @G marker)
dispMatrices = paramFile$readDispersalMatrixOverTime() # Contains a list of dispersal matrix. Each element of the list is for a different @G marker
patchCapacities = paramFile$readParameter("__patchCapacity") # Contains a list of vector of patch capacity. Each element of the list is for a different @G marker
######################################################################################
##### Loop over the generations at which there were changes for those parameters #####
######################################################################################
pdf("DemographyGraphs.pdf")
for (generation_index in 1:length(generations))
{
dispMatrix = dispMatrices[[generation_index]]
patchCapacity = patchCapacities[[generation_index]]
generation = generations[generation_index]
#################
##### Graph #####
#################
net = network(dispMatrix, directed = TRUE)
#net %v% "patchID" = paste("patch ", 1:nrow(dispMatrix))
print(ggnet(net, node.alpha=0.5, label = 1:nrow(dispMatrix), weight = patchCapacity, arrow.size = 8, arrow.gap = 0) + ggtitle(paste("From generation", generation)))
}
dev.off()
|
[STATEMENT]
lemma N_top [simp]:
"N top = 1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. N top = (1::'a)
[PROOF STEP]
by simp |
State Before: α : Type u_1
𝕜 : Type u_2
inst✝² : LinearOrderedField 𝕜
inst✝¹ : DecidableEq α
A : Finset α
P : Finpartition A
G : SimpleGraph α
inst✝ : DecidableRel G.Adj
ε✝ ε ε' : 𝕜
hP : IsUniform P G ε
h : ε ≤ ε'
⊢ ↑(card P.parts * (card P.parts - 1)) * ε ≤ ↑(card P.parts * (card P.parts - 1)) * ε' State After: no goals Tactic: gcongr |
%%
% \documentclass[12pt]{article}
%
% \title{ODEbox: A Toolbox for Ordinary Differential Equations\\
% Example 1}
%
% \author{Matthew Harker and Paul O'Leary\\
% Institute for Automation\\
% University of Leoben\\
% A-8700 Leoben,
% Austria\\
% URL: automation.unileoben.ac.at\\
% \\
% Original: January 9, 2013\\
% $\copyright$ 2013\\
% \\
% Last Modified: \today}
%%
%\section{Initial Value Problem}
%
% This file demonstrated the solution of initial value problems using the
% DOPBox and ODEBox toolbaxes. The example being considered here is:
%
% \begin{equation}
% \ddot{y} + 6\,\dot{y} + 9 y = 0
% \hspace{5mm}
% \text{with}
% \hspace{5mm}
% y(0) = 10
% \hspace{5mm}
% \text{and}
% \hspace{5mm}
% \dot{y}(0) = -75
% \end{equation}
%
% The analytical solution to this problem is:
%
% \begin{equation}
% y(x) = 10 \, e^{-3\,x} - 45 \,x {e^{-3\,x}}.
% \end{equation}
%
% This example has been taken from~\cite{adams}.
%
% This M-file demonstrated the new approach to solving this problem and
% compared the result with a classical runga-kutta solution as provided by
% MATLAB.
%
%%
% \section{Prepare the workspace}
%
close all;
clear all;
setUpGraphics(12) ;
%%
% Define the equation and solution as a strings for documentation
%
Eq = '$$\ddot{y} - 6\,\dot{y} - 9 y = 0$$, with, $$y(0) = 10$$ and $$\dot{y}(1) = -75$$' ;
Sol = '$$y(x) = 10 \, e^{-3\,x} - 45 \,x {e^{-3\,x}}$$';
%
%------------------------------------------------------------------
%%
% \section{Define the Matrix Linear Differential Operator}
%
% Define the number of points used in the solution
%
noPts = 85 ;
%
% Define the interval in which the problem is to be solved
%
xMin = 0 ;
xMax = 3 ;
%
% Use a nonlinear node placement. This ensures a higher density of nodes
% where the solution has a highed derivative.
%
x = linspace(0,1,noPts)';
x = 5 * x.^2;
%
% Setup the differentiating matrix, with support length 13.
%
ls = 13;
D = dopDiffLocal( x, ls, ls );
%
% Define the matrix C of constraints, i.e. the initial conditions
%
C = zeros(noPts,2) ;
%
C(1,1) = 1 ;
C(:,2) = D(1,:)' ;
%
d = [ 10 ; -75] ;
%
% Compute the linear differential operator.
%
L = D*D + 6*D + 9*eye(noPts) ;
%%
%\section{Compute the Solutions}
%
% Solve the algebraic system of equations as a least squares problem. This
% is the actual computation of the solution of the differential equation.
%
y = odeLSE( L, [] , C, d );
%%
% For comparison solve using the MATLAB ode45 method.
% Runge-Kutta Solution:
%
[xm,Y] = ode45(@eulerODE01,[xMin xMax],d');
%
ym = Y(:,1);
%%
% Compute the Analytic Solution as an inline to compare the results
%
f = inline('10*exp(-3*t) - 45*t.*exp(-3*t)') ;
%
ya = f(x);
%%
% \section{Plot the Results}
%
% for plot purposes solve beyond the ends
%
xp = linspace(xMin-1/4,xMax+1/4,1000) ;
yp = f(xp);
%
% Present the solutions
%
setUpGraphics(12)
FigureSize=[1 1 10 6];
set(0,'DefaultFigureUnits','centimeters');
set(0,'DefaultFigurePosition',FigureSize);
set(0,'DefaultFigurePaperUnits','centimeters');
set(0,'DefaultFigurePaperPosition',FigureSize);
MyAxesPosition=[0.13 0.15 0.86 0.82];
set(0,'DefaultaxesPosition',MyAxesPosition);
%
fig1 = figure;
plot( xp, yp, 'k' ) ;
hold on
plot( x, y, 'ko', 'MarkerFaceColor', 'w' ) ;
%
plot( xm, ym,'kv');
legend('Analytical','New','Runge-Kutta','Location','NorthEast');
xlabel('$$x$$');
ylabel('$$y$$');
grid on;
range = axis;
plot( range(1:2), [0,0],'k');
axis([-0.5,3.5,-5,15]);
plot( x, -4.5*ones(size(x)), 'k.');
%
%\caption{Comparison of the analytical solution, the new numberical
% method and the Runga-Kutta solution.}
%%
%
setUpGraphics(12)
FigureSize=[1 1 10 6];
set(0,'DefaultFigureUnits','centimeters');
set(0,'DefaultFigurePosition',FigureSize);
set(0,'DefaultFigurePaperUnits','centimeters');
set(0,'DefaultFigurePaperPosition',FigureSize);
MyAxesPosition=[0.13 0.13 0.86 0.82];
set(0,'DefaultaxesPosition',MyAxesPosition);
%
fig2 = figure;
subplot(2,1,1)
plot( x, y - ya, 'k', 'MarkerFaceColor', 'w' ) ;
hold on
plot( x, y - ya, 'k.', 'MarkerFaceColor', 'w' ) ;
range = axis;
plot( range(1:2), [0,0],'k');
ylabel('$$e_{L}$$');
grid on;
%title(Sol);
%
subplot(2,1,2)
plot( xm, ym - f(xm), 'k', 'MarkerFaceColor', 'w' ) ;
hold on
plot( xm, ym - f(xm), 'k.', 'MarkerFaceColor', 'w' ) ;
hold on;
range = axis;
plot( range(1:2), [0,0],'k');
xlabel('$$x$$');
ylabel('$$e_{RK}$$');
grid on;
%
% \caption{Comparison the residual error for the new method (top) (Bottom)and
% for the Runga-Kutta method. Note the residual is orders of magnitude smaller for the new method.}
%
%%
%\section{Save the figures to disk.}
%
fileType = 'eps';
printFigure( fig1, 'ivpExp3Sol', fileType);
printFigure( fig2, 'ivpExp3Err', fileType);
%
%% Define the Bibliography
%
% \bibliographystyle{IEEETran}
% \bibliography{odebib}
|
#check (.=.)
-- #print (.=.)
-- #print (.=.)
#check (.==.)
#check Eq.refl
#check @Eq.refl
#check Eq.refl 5
#check @Eq.symm
#check @Eq.trans
#check @Eq.subst
#print Eq
def mod7Rel (x y : Nat) : Prop :=
x % 7 = y % 7
#check mod7Rel
theorem thm_1: mod7Rel 3 10 := rfl
#print thm_1
theorem thm_2: mod7Rel 3 10 := by
simp [mod7Rel]
/- Example of an equality proof -/
-- example: 5=3+2 := Eq.refl -- error: missing argument a for "a = a"
example: 5=3+2 := Eq.refl 5 -- concrete value for a
example: 5=3+2 := Eq.refl _ -- auto unification for a; in order to prove 5=5, a should be obviously 5.
example: 5=3+2 := rfl -- notification
#check rfl
#print rfl
section
variable (α : Type)
variable (a b : α)
variable (f g : α → Nat)
variable (h₁ : a = b)
variable (h₂ : f = g)
example : f a = f b := congrArg f h₁
example : f a = g a := congrFun h₂ a
example : f a = g b := congr h₂ h₁
end
#print id
#check Nat
#check @congr
#check @congrArg
#check congrArg id (Eq.refl 5)
#check @congrFun
#check @Equivalence
#print Equivalence
theorem thm_3 : Equivalence mod7Rel :=
by
constructor
intros; rfl
intro x y p1
simp [ mod7Rel ] at *
rw [ p1 ]
intro x y z hxy hyz
simp [mod7Rel] at *
apply Eq.trans hxy hyz
|
(* Title: Lazy_Intruder.thy
Author: Andreas Viktor Hess, DTU
SPDX-License-Identifier: BSD-3-Clause
*)
section \<open>The Lazy Intruder\<close>
theory Lazy_Intruder
imports Strands_and_Constraints Intruder_Deduction
begin
context intruder_model
begin
subsection \<open>Definition of the Lazy Intruder\<close>
text \<open>The lazy intruder constraint reduction system, defined as a relation on constraint states\<close>
inductive_set LI_rel::
"((('fun,'var) strand \<times> (('fun,'var) subst)) \<times>
('fun,'var) strand \<times> (('fun,'var) subst)) set"
and LI_rel' (infix "\<leadsto>" 50)
and LI_rel_trancl (infix "\<leadsto>\<^sup>+" 50)
and LI_rel_rtrancl (infix "\<leadsto>\<^sup>*" 50)
where
"A \<leadsto> B \<equiv> (A,B) \<in> LI_rel"
| "A \<leadsto>\<^sup>+ B \<equiv> (A,B) \<in> LI_rel\<^sup>+"
| "A \<leadsto>\<^sup>* B \<equiv> (A,B) \<in> LI_rel\<^sup>*"
| Compose: "\<lbrakk>simple S; length T = arity f; public f\<rbrakk>
\<Longrightarrow> (S@Send [Fun f T]#S',\<theta>) \<leadsto> (S@(map Send1 T)@S',\<theta>)"
| Unify: "\<lbrakk>simple S; Fun f T' \<in> ik\<^sub>s\<^sub>t S; Some \<delta> = mgu (Fun f T) (Fun f T')\<rbrakk>
\<Longrightarrow> (S@Send [Fun f T]#S',\<theta>) \<leadsto> ((S@S') \<cdot>\<^sub>s\<^sub>t \<delta>,\<theta> \<circ>\<^sub>s \<delta>)"
| Equality: "\<lbrakk>simple S; Some \<delta> = mgu t t'\<rbrakk>
\<Longrightarrow> (S@Equality _ t t'#S',\<theta>) \<leadsto> ((S@S') \<cdot>\<^sub>s\<^sub>t \<delta>,\<theta> \<circ>\<^sub>s \<delta>)"
text \<open>A "pre-processing step" to be applied before constraint reduction. It transforms constraints
such that exactly one message is transmitted in each message transmission step. It is sound and
complete and preserves the various well-formedness properties required by the lazy intruder.\<close>
fun LI_preproc where
"LI_preproc [] = []"
| "LI_preproc (Send ts#S) = map Send1 ts@LI_preproc S"
| "LI_preproc (Receive ts#S) = map Receive1 ts@LI_preproc S"
| "LI_preproc (x#S) = x#LI_preproc S"
definition LI_preproc_prop where
"LI_preproc_prop S \<equiv> \<forall>ts. Send ts \<in> set S \<or> Receive ts \<in> set S \<longrightarrow> (\<exists>t. ts = [t])"
subsection \<open>Lemmata: Preprocessing \<close>
lemma LI_preproc_preproc_prop:
"LI_preproc_prop (LI_preproc S)"
by (induct S rule: LI_preproc.induct) (auto simp add: LI_preproc_prop_def)
lemma LI_preproc_sem_eq:
"\<lbrakk>M; S\<rbrakk>\<^sub>c \<I> \<longleftrightarrow> \<lbrakk>M; LI_preproc S\<rbrakk>\<^sub>c \<I>" (is "?A \<longleftrightarrow> ?B")
proof
show "?A \<Longrightarrow> ?B"
proof (induction S rule: strand_sem_induct)
case (ConsSnd M ts S)
hence "\<lbrakk>M; LI_preproc S\<rbrakk>\<^sub>c \<I>" "\<lbrakk>M; map Send1 ts\<rbrakk>\<^sub>c \<I>" using strand_sem_Send_map(5) by auto
moreover have "ik\<^sub>s\<^sub>t (map Send1 ts) \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I> = {}" unfolding ik\<^sub>s\<^sub>t_is_rcv_set by fastforce
ultimately show ?case using strand_sem_append(1) by simp
next
case (ConsRcv M ts S)
hence "\<lbrakk>(set ts \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>) \<union> M; LI_preproc S\<rbrakk>\<^sub>c \<I>" "\<lbrakk>M; map Receive1 ts\<rbrakk>\<^sub>c \<I>"
using strand_sem_Receive_map(3) by auto
moreover have "ik\<^sub>s\<^sub>t (map Receive1 ts) \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I> = set ts \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>" unfolding ik\<^sub>s\<^sub>t_is_rcv_set by force
ultimately show ?case using strand_sem_append(1) by (simp add: Un_commute)
qed simp_all
show "?B \<Longrightarrow> ?A"
proof (induction S arbitrary: M rule: LI_preproc.induct)
case (2 ts S)
have "ik\<^sub>s\<^sub>t (map Send1 ts) \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I> = {}" unfolding ik\<^sub>s\<^sub>t_is_rcv_set by fastforce
hence "\<lbrakk>M; S\<rbrakk>\<^sub>c \<I>" "\<lbrakk>M; map Send1 ts\<rbrakk>\<^sub>c \<I>" using 2 strand_sem_append(1) by auto
thus ?case using strand_sem_Send_map(5) by simp
next
case (3 ts S)
have "ik\<^sub>s\<^sub>t (map Receive1 ts) \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I> = set ts \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>" unfolding ik\<^sub>s\<^sub>t_is_rcv_set by force
hence "\<lbrakk>M \<union> (set ts \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>); S\<rbrakk>\<^sub>c \<I>" "\<lbrakk>M; map Receive1 ts\<rbrakk>\<^sub>c \<I>"
using 3 strand_sem_append(1) by auto
thus ?case using strand_sem_Receive_map(3) by (simp add: Un_commute)
qed simp_all
qed
lemma LI_preproc_sem_eq':
"(\<I> \<Turnstile>\<^sub>c \<langle>S, \<theta>\<rangle>) \<longleftrightarrow> (\<I> \<Turnstile>\<^sub>c \<langle>LI_preproc S, \<theta>\<rangle>)"
using LI_preproc_sem_eq unfolding constr_sem_c_def by simp
lemma LI_preproc_vars_eq:
"fv\<^sub>s\<^sub>t (LI_preproc S) = fv\<^sub>s\<^sub>t S"
"bvars\<^sub>s\<^sub>t (LI_preproc S) = bvars\<^sub>s\<^sub>t S"
"vars\<^sub>s\<^sub>t (LI_preproc S) = vars\<^sub>s\<^sub>t S"
by (induct S rule: LI_preproc.induct) auto
lemma LI_preproc_trms_eq:
"trms\<^sub>s\<^sub>t (LI_preproc S) = trms\<^sub>s\<^sub>t S"
by (induct S rule: LI_preproc.induct) auto
lemma LI_preproc_wf\<^sub>s\<^sub>t:
assumes "wf\<^sub>s\<^sub>t X S"
shows "wf\<^sub>s\<^sub>t X (LI_preproc S)"
using assms
proof (induction S arbitrary: X rule: wf\<^sub>s\<^sub>t_induct)
case (ConsRcv X ts S)
hence "fv\<^sub>s\<^sub>e\<^sub>t (set ts) \<subseteq> X" "wf\<^sub>s\<^sub>t X (LI_preproc S)" by auto
thus ?case using wf_Receive1_prefix by simp
next
case (ConsSnd X ts S)
hence "wf\<^sub>s\<^sub>t (X \<union> fv\<^sub>s\<^sub>e\<^sub>t (set ts)) (LI_preproc S)" by simp
thus ?case using wf_Send1_prefix by simp
qed simp_all
lemma LI_preproc_preserves_wellformedness:
assumes "wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r S \<theta>"
shows "wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r (LI_preproc S) \<theta>"
using assms LI_preproc_vars_eq[of S] LI_preproc_wf\<^sub>s\<^sub>t[of "{}" S] unfolding wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r_def by argo
lemma LI_preproc_prop_SendE:
assumes "LI_preproc_prop S"
and "Send ts \<in> set S"
shows "(\<exists>x. ts = [Var x]) \<or> (\<exists>f T. ts = [Fun f T])"
proof -
obtain t where "ts = [t]" using assms unfolding LI_preproc_prop_def by auto
thus ?thesis by (cases t) auto
qed
lemma LI_preproc_prop_split:
"LI_preproc_prop (S@S') \<longleftrightarrow> LI_preproc_prop S \<and> LI_preproc_prop S'" (is "?A \<longleftrightarrow> ?B")
proof
show "?A \<Longrightarrow> ?B"
proof (induction S)
case (Cons x S) thus ?case unfolding LI_preproc_prop_def by (cases x) auto
qed (simp add: LI_preproc_prop_def)
show "?B \<Longrightarrow> ?A"
proof (induction S)
case (Cons x S) thus ?case unfolding LI_preproc_prop_def by (cases x) auto
qed (simp add: LI_preproc_prop_def)
qed
subsection \<open>Lemma: The Lazy Intruder is Well-founded\<close>
context
begin
private lemma LI_compose_measure_lt:
"((S@(map Send1 T)@S',\<theta>\<^sub>1), (S@Send [Fun f T]#S',\<theta>\<^sub>2)) \<in> measure\<^sub>s\<^sub>t"
using strand_fv_card_map_fun_eq[of S f T S'] strand_size_map_fun_lt[of T f]
by (simp add: measure\<^sub>s\<^sub>t_def size\<^sub>s\<^sub>t_def)
private lemma LI_unify_measure_lt:
assumes "Some \<delta> = mgu (Fun f T) t" "fv t \<subseteq> fv\<^sub>s\<^sub>t S"
shows "(((S@S') \<cdot>\<^sub>s\<^sub>t \<delta>,\<theta>\<^sub>1), (S@Send [Fun f T]#S',\<theta>\<^sub>2)) \<in> measure\<^sub>s\<^sub>t"
proof (cases "\<delta> = Var")
assume "\<delta> = Var"
hence "(S@S') \<cdot>\<^sub>s\<^sub>t \<delta> = S@S'" by blast
thus ?thesis
using strand_fv_card_rm_fun_le[of S S' f T]
by (auto simp add: measure\<^sub>s\<^sub>t_def size\<^sub>s\<^sub>t_def)
next
assume "\<delta> \<noteq> Var"
then obtain v where "v \<in> fv (Fun f T) \<union> fv t" "subst_elim \<delta> v"
using mgu_eliminates[OF assms(1)[symmetric]] by metis
hence v_in: "v \<in> fv\<^sub>s\<^sub>t (S@Send [Fun f T]#S')"
using assms(2) by (auto simp add: measure\<^sub>s\<^sub>t_def size\<^sub>s\<^sub>t_def)
have "range_vars \<delta> \<subseteq> fv (Fun f T) \<union> fv\<^sub>s\<^sub>t S"
using assms(2) mgu_vars_bounded[OF assms(1)[symmetric]] by auto
hence img_bound: "range_vars \<delta> \<subseteq> fv\<^sub>s\<^sub>t (S@Send [Fun f T]#S')" by auto
have finite_fv: "finite (fv\<^sub>s\<^sub>t (S@Send [Fun f T]#S'))" by auto
have "v \<notin> fv\<^sub>s\<^sub>t ((S@Send [Fun f T]#S') \<cdot>\<^sub>s\<^sub>t \<delta>)"
using strand_fv_subst_subset_if_subst_elim[OF \<open>subst_elim \<delta> v\<close>] v_in by metis
hence v_not_in: "v \<notin> fv\<^sub>s\<^sub>t ((S@S') \<cdot>\<^sub>s\<^sub>t \<delta>)" by auto
have "fv\<^sub>s\<^sub>t ((S@S') \<cdot>\<^sub>s\<^sub>t \<delta>) \<subseteq> fv\<^sub>s\<^sub>t (S@Send [Fun f T]#S')"
using strand_subst_fv_bounded_if_img_bounded[OF img_bound] by simp
hence "fv\<^sub>s\<^sub>t ((S@S') \<cdot>\<^sub>s\<^sub>t \<delta>) \<subset> fv\<^sub>s\<^sub>t (S@Send [Fun f T]#S')" using v_in v_not_in by blast
hence "card (fv\<^sub>s\<^sub>t ((S@S') \<cdot>\<^sub>s\<^sub>t \<delta>)) < card (fv\<^sub>s\<^sub>t (S@Send [Fun f T]#S'))"
using psubset_card_mono[OF finite_fv] by simp
thus ?thesis by (auto simp add: measure\<^sub>s\<^sub>t_def size\<^sub>s\<^sub>t_def)
qed
private lemma LI_equality_measure_lt:
assumes "Some \<delta> = mgu t t'"
shows "(((S@S') \<cdot>\<^sub>s\<^sub>t \<delta>,\<theta>\<^sub>1), (S@Equality a t t'#S',\<theta>\<^sub>2)) \<in> measure\<^sub>s\<^sub>t"
proof (cases "\<delta> = Var")
assume "\<delta> = Var"
hence "(S@S') \<cdot>\<^sub>s\<^sub>t \<delta> = S@S'" by blast
thus ?thesis
using strand_fv_card_rm_eq_le[of S S' a t t']
by (auto simp add: measure\<^sub>s\<^sub>t_def size\<^sub>s\<^sub>t_def)
next
assume "\<delta> \<noteq> Var"
then obtain v where "v \<in> fv t \<union> fv t'" "subst_elim \<delta> v"
using mgu_eliminates[OF assms(1)[symmetric]] by metis
hence v_in: "v \<in> fv\<^sub>s\<^sub>t (S@Equality a t t'#S')" using assms by auto
have "range_vars \<delta> \<subseteq> fv t \<union> fv t' \<union> fv\<^sub>s\<^sub>t S"
using assms mgu_vars_bounded[OF assms(1)[symmetric]] by auto
hence img_bound: "range_vars \<delta> \<subseteq> fv\<^sub>s\<^sub>t (S@Equality a t t'#S')" by auto
have finite_fv: "finite (fv\<^sub>s\<^sub>t (S@Equality a t t'#S'))" by auto
have "v \<notin> fv\<^sub>s\<^sub>t ((S@Equality a t t'#S') \<cdot>\<^sub>s\<^sub>t \<delta>)"
using strand_fv_subst_subset_if_subst_elim[OF \<open>subst_elim \<delta> v\<close>] v_in by metis
hence v_not_in: "v \<notin> fv\<^sub>s\<^sub>t ((S@S') \<cdot>\<^sub>s\<^sub>t \<delta>)" by auto
have "fv\<^sub>s\<^sub>t ((S@S') \<cdot>\<^sub>s\<^sub>t \<delta>) \<subseteq> fv\<^sub>s\<^sub>t (S@Equality a t t'#S')"
using strand_subst_fv_bounded_if_img_bounded[OF img_bound] by simp
hence "fv\<^sub>s\<^sub>t ((S@S') \<cdot>\<^sub>s\<^sub>t \<delta>) \<subset> fv\<^sub>s\<^sub>t (S@Equality a t t'#S')" using v_in v_not_in by blast
hence "card (fv\<^sub>s\<^sub>t ((S@S') \<cdot>\<^sub>s\<^sub>t \<delta>)) < card (fv\<^sub>s\<^sub>t (S@Equality a t t'#S'))"
using psubset_card_mono[OF finite_fv] by simp
thus ?thesis by (auto simp add: measure\<^sub>s\<^sub>t_def size\<^sub>s\<^sub>t_def)
qed
private lemma LI_in_measure: "(S\<^sub>1,\<theta>\<^sub>1) \<leadsto> (S\<^sub>2,\<theta>\<^sub>2) \<Longrightarrow> ((S\<^sub>2,\<theta>\<^sub>2),(S\<^sub>1,\<theta>\<^sub>1)) \<in> measure\<^sub>s\<^sub>t"
proof (induction rule: LI_rel.induct)
case (Compose S T f S' \<theta>) thus ?case using LI_compose_measure_lt[of S T S'] by metis
next
case (Unify S f U \<delta> T S' \<theta>)
hence "fv (Fun f U) \<subseteq> fv\<^sub>s\<^sub>t S"
using fv_snd_rcv_strand_subset(2)[of S] by force
thus ?case using LI_unify_measure_lt[OF Unify.hyps(3), of S S'] by metis
qed (metis LI_equality_measure_lt)
private lemma LI_in_measure_trans: "(S\<^sub>1,\<theta>\<^sub>1) \<leadsto>\<^sup>+ (S\<^sub>2,\<theta>\<^sub>2) \<Longrightarrow> ((S\<^sub>2,\<theta>\<^sub>2),(S\<^sub>1,\<theta>\<^sub>1)) \<in> measure\<^sub>s\<^sub>t"
by (induction rule: trancl.induct, metis surjective_pairing LI_in_measure)
(metis (no_types, lifting) surjective_pairing LI_in_measure measure\<^sub>s\<^sub>t_trans trans_def)
private lemma LI_converse_wellfounded_trans: "wf ((LI_rel\<^sup>+)\<inverse>)"
proof -
have "(LI_rel\<^sup>+)\<inverse> \<subseteq> measure\<^sub>s\<^sub>t" using LI_in_measure_trans by auto
thus ?thesis using measure\<^sub>s\<^sub>t_wellfounded wf_subset by metis
qed
private lemma LI_acyclic_trans: "acyclic (LI_rel\<^sup>+)"
using wf_acyclic[OF LI_converse_wellfounded_trans] acyclic_converse by metis
private lemma LI_acyclic: "acyclic LI_rel"
using LI_acyclic_trans acyclic_subset by (simp add: acyclic_def)
lemma LI_no_infinite_chain: "\<not>(\<exists>f. \<forall>i. f i \<leadsto>\<^sup>+ f (Suc i))"
proof -
have "\<not>(\<exists>f. \<forall>i. (f (Suc i), f i) \<in> (LI_rel\<^sup>+)\<inverse>)"
using wf_iff_no_infinite_down_chain LI_converse_wellfounded_trans by metis
thus ?thesis by simp
qed
private lemma LI_unify_finite:
assumes "finite M"
shows "finite {((S@Send [Fun f T]#S',\<theta>), ((S@S') \<cdot>\<^sub>s\<^sub>t \<delta>,\<theta> \<circ>\<^sub>s \<delta>)) | \<delta> T'.
simple S \<and> Fun f T' \<in> M \<and> Some \<delta> = mgu (Fun f T) (Fun f T')}"
using assms
proof (induction M rule: finite_induct)
case (insert m M) thus ?case
proof (cases m)
case (Fun g U)
let ?a = "\<lambda>\<delta>. ((S@Send [Fun f T]#S',\<theta>), ((S@S') \<cdot>\<^sub>s\<^sub>t \<delta>,\<theta> \<circ>\<^sub>s \<delta>))"
let ?A = "\<lambda>B. {?a \<delta> | \<delta> T'. simple S \<and> Fun f T' \<in> B \<and> Some \<delta> = mgu (Fun f T) (Fun f T')}"
have "?A (insert m M) = (?A M) \<union> (?A {m})" by auto
moreover have "finite (?A {m})"
proof (cases "\<exists>\<delta>. Some \<delta> = mgu (Fun f T) (Fun g U)")
case True
then obtain \<delta> where \<delta>: "Some \<delta> = mgu (Fun f T) (Fun g U)" by blast
have A_m_eq: "\<And>\<delta>'. ?a \<delta>' \<in> ?A {m} \<Longrightarrow> ?a \<delta> = ?a \<delta>'"
proof -
fix \<delta>' assume "?a \<delta>' \<in> ?A {m}"
hence "\<exists>\<sigma>. Some \<sigma> = mgu (Fun f T) (Fun g U) \<and> ?a \<sigma> = ?a \<delta>'"
using \<open>m = Fun g U\<close> by auto
thus "?a \<delta> = ?a \<delta>'" by (metis \<delta> option.inject)
qed
have "?A {m} = {} \<or> ?A {m} = {?a \<delta>}"
proof (cases "simple S \<and> ?A {m} \<noteq> {}")
case True
hence "simple S" "?A {m} \<noteq> {}" by meson+
hence "?A {m} = {?a \<delta> | \<delta>. Some \<delta> = mgu (Fun f T) (Fun g U)}" using \<open>m = Fun g U\<close> by auto
hence "?a \<delta> \<in> ?A {m}" using \<delta> by auto
show ?thesis
proof (rule ccontr)
assume "\<not>(?A {m} = {} \<or> ?A {m} = {?a \<delta>})"
then obtain B where B: "?A {m} = insert (?a \<delta>) B" "?a \<delta> \<notin> B" "B \<noteq> {}"
using \<open>?A {m} \<noteq> {}\<close> \<open>?a \<delta> \<in> ?A {m}\<close> by (metis (no_types, lifting) Set.set_insert)
then obtain b where b: "?a \<delta> \<noteq> b" "b \<in> B" by (metis (no_types, lifting) ex_in_conv)
then obtain \<delta>' where \<delta>': "b = ?a \<delta>'" using B(1) by blast
moreover have "?a \<delta>' \<in> ?A {m}" using B(1) b(2) \<delta>' by auto
hence "?a \<delta> = ?a \<delta>'" by (blast dest!: A_m_eq)
ultimately show False using b(1) by simp
qed
qed auto
thus ?thesis by (metis (no_types, lifting) finite.emptyI finite_insert)
next
case False
hence "?A {m} = {}" using \<open>m = Fun g U\<close> by blast
thus ?thesis by (metis finite.emptyI)
qed
ultimately show ?thesis using insert.IH by auto
qed simp
qed fastforce
end
subsection \<open>Lemma: The Lazy Intruder Preserves Well-formedness\<close>
context
begin
private lemma LI_preserves_subst_wf_single:
assumes "(S\<^sub>1,\<theta>\<^sub>1) \<leadsto> (S\<^sub>2,\<theta>\<^sub>2)" "fv\<^sub>s\<^sub>t S\<^sub>1 \<inter> bvars\<^sub>s\<^sub>t S\<^sub>1 = {}" "wf\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<theta>\<^sub>1"
and "subst_domain \<theta>\<^sub>1 \<inter> vars\<^sub>s\<^sub>t S\<^sub>1 = {}" "range_vars \<theta>\<^sub>1 \<inter> bvars\<^sub>s\<^sub>t S\<^sub>1 = {}"
shows "fv\<^sub>s\<^sub>t S\<^sub>2 \<inter> bvars\<^sub>s\<^sub>t S\<^sub>2 = {}" "wf\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<theta>\<^sub>2"
and "subst_domain \<theta>\<^sub>2 \<inter> vars\<^sub>s\<^sub>t S\<^sub>2 = {}" "range_vars \<theta>\<^sub>2 \<inter> bvars\<^sub>s\<^sub>t S\<^sub>2 = {}"
using assms
proof (induction rule: LI_rel.induct)
case (Compose S X f S' \<theta>)
{ case 1 thus ?case using vars_st_snd_map by auto }
{ case 2 thus ?case using vars_st_snd_map by auto }
{ case 3 thus ?case using vars_st_snd_map by force }
{ case 4 thus ?case using vars_st_snd_map by auto }
next
case (Unify S f U \<delta> T S' \<theta>)
hence "fv (Fun f U) \<subseteq> fv\<^sub>s\<^sub>t S" using fv_subset_if_in_strand_ik' by blast
hence *: "subst_domain \<delta> \<union> range_vars \<delta> \<subseteq> fv\<^sub>s\<^sub>t (S@Send [Fun f T]#S')"
using mgu_vars_bounded[OF Unify.hyps(3)[symmetric]]
unfolding range_vars_alt_def by (fastforce simp del: subst_range.simps)
have "fv\<^sub>s\<^sub>t (S@S') \<subseteq> fv\<^sub>s\<^sub>t (S@Send [Fun f T]#S')" "vars\<^sub>s\<^sub>t (S@S') \<subseteq> vars\<^sub>s\<^sub>t (S@Send [Fun f T]#S')"
by auto
hence **: "fv\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) \<subseteq> fv\<^sub>s\<^sub>t (S@Send [Fun f T]#S')"
"vars\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) \<subseteq> vars\<^sub>s\<^sub>t (S@Send [Fun f T]#S')"
using subst_sends_strand_fv_to_img[of "S@S'" \<delta>]
strand_subst_vars_union_bound[of "S@S'" \<delta>] *
by blast+
have "wf\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<delta>" by (fact mgu_gives_wellformed_subst[OF Unify.hyps(3)[symmetric]])
{ case 1
have "bvars\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) = bvars\<^sub>s\<^sub>t (S@Send [Fun f T]#S')"
using bvars_subst_ident[of "S@S'" \<delta>] by auto
thus ?case using 1 ** by blast
}
{ case 2
hence "subst_domain \<theta> \<inter> subst_domain \<delta> = {}" "subst_domain \<theta> \<inter> range_vars \<delta> = {}"
using * by blast+
thus ?case by (metis wf_subst_compose[OF \<open>wf\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<theta>\<close> \<open>wf\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<delta>\<close>])
}
{ case 3
hence "subst_domain \<theta> \<inter> vars\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) = {}" using ** by blast
moreover have "v \<in> fv\<^sub>s\<^sub>t (S@Send [Fun f T]#S')" when "v \<in> subst_domain \<delta>" for v
using * that by blast
hence "subst_domain \<delta> \<inter> fv\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) = {}"
using mgu_eliminates_dom[OF Unify.hyps(3)[symmetric],
THEN strand_fv_subst_subset_if_subst_elim, of _ "S@Send [Fun f T]#S'"]
unfolding subst_elim_def by auto
moreover have "bvars\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) = bvars\<^sub>s\<^sub>t (S@Send [Fun f T]#S')"
using bvars_subst_ident[of "S@S'" \<delta>] by auto
hence "subst_domain \<delta> \<inter> bvars\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) = {}" using 3(1) * by blast
ultimately show ?case
using ** * subst_domain_compose[of \<theta> \<delta>] vars\<^sub>s\<^sub>t_is_fv\<^sub>s\<^sub>t_bvars\<^sub>s\<^sub>t[of "S@S' \<cdot>\<^sub>s\<^sub>t \<delta>"]
by blast
}
{ case 4
have ***: "bvars\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) = bvars\<^sub>s\<^sub>t (S@Send [Fun f T]#S')"
using bvars_subst_ident[of "S@S'" \<delta>] by auto
hence "range_vars \<delta> \<inter> bvars\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) = {}" using 4(1) * by blast
thus ?case using subst_img_comp_subset[of \<theta> \<delta>] 4(4) *** by blast
}
next
case (Equality S \<delta> t t' a S' \<theta>)
hence *: "subst_domain \<delta> \<union> range_vars \<delta> \<subseteq> fv\<^sub>s\<^sub>t (S@Equality a t t'#S')"
using mgu_vars_bounded[OF Equality.hyps(2)[symmetric]]
unfolding range_vars_alt_def by fastforce
have "fv\<^sub>s\<^sub>t (S@S') \<subseteq> fv\<^sub>s\<^sub>t (S@Equality a t t'#S')" "vars\<^sub>s\<^sub>t (S@S') \<subseteq> vars\<^sub>s\<^sub>t (S@Equality a t t'#S')"
by auto
hence **: "fv\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) \<subseteq> fv\<^sub>s\<^sub>t (S@Equality a t t'#S')"
"vars\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) \<subseteq> vars\<^sub>s\<^sub>t (S@Equality a t t'#S')"
using subst_sends_strand_fv_to_img[of "S@S'" \<delta>]
strand_subst_vars_union_bound[of "S@S'" \<delta>] *
by blast+
have "wf\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<delta>" by (fact mgu_gives_wellformed_subst[OF Equality.hyps(2)[symmetric]])
{ case 1
have "bvars\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) = bvars\<^sub>s\<^sub>t (S@Equality a t t'#S')"
using bvars_subst_ident[of "S@S'" \<delta>] by auto
thus ?case using 1 ** by blast
}
{ case 2
hence "subst_domain \<theta> \<inter> subst_domain \<delta> = {}" "subst_domain \<theta> \<inter> range_vars \<delta> = {}"
using * by blast+
thus ?case by (metis wf_subst_compose[OF \<open>wf\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<theta>\<close> \<open>wf\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<delta>\<close>])
}
{ case 3
hence "subst_domain \<theta> \<inter> vars\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) = {}" using ** by blast
moreover have "v \<in> fv\<^sub>s\<^sub>t (S@Equality a t t'#S')" when "v \<in> subst_domain \<delta>" for v
using * that by blast
hence "subst_domain \<delta> \<inter> fv\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) = {}"
using mgu_eliminates_dom[OF Equality.hyps(2)[symmetric],
THEN strand_fv_subst_subset_if_subst_elim, of _ "S@Equality a t t'#S'"]
unfolding subst_elim_def by auto
moreover have "bvars\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) = bvars\<^sub>s\<^sub>t (S@Equality a t t'#S')"
using bvars_subst_ident[of "S@S'" \<delta>] by auto
hence "subst_domain \<delta> \<inter> bvars\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) = {}" using 3(1) * by blast
ultimately show ?case
using ** * subst_domain_compose[of \<theta> \<delta>] vars\<^sub>s\<^sub>t_is_fv\<^sub>s\<^sub>t_bvars\<^sub>s\<^sub>t[of "S@S' \<cdot>\<^sub>s\<^sub>t \<delta>"]
by blast
}
{ case 4
have ***: "bvars\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) = bvars\<^sub>s\<^sub>t (S@Equality a t t'#S')"
using bvars_subst_ident[of "S@S'" \<delta>] by auto
hence "range_vars \<delta> \<inter> bvars\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) = {}" using 4(1) * by blast
thus ?case using subst_img_comp_subset[of \<theta> \<delta>] 4(4) *** by blast
}
qed
private lemma LI_preserves_subst_wf:
assumes "(S\<^sub>1,\<theta>\<^sub>1) \<leadsto>\<^sup>* (S\<^sub>2,\<theta>\<^sub>2)" "fv\<^sub>s\<^sub>t S\<^sub>1 \<inter> bvars\<^sub>s\<^sub>t S\<^sub>1 = {}" "wf\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<theta>\<^sub>1"
and "subst_domain \<theta>\<^sub>1 \<inter> vars\<^sub>s\<^sub>t S\<^sub>1 = {}" "range_vars \<theta>\<^sub>1 \<inter> bvars\<^sub>s\<^sub>t S\<^sub>1 = {}"
shows "fv\<^sub>s\<^sub>t S\<^sub>2 \<inter> bvars\<^sub>s\<^sub>t S\<^sub>2 = {}" "wf\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<theta>\<^sub>2"
and "subst_domain \<theta>\<^sub>2 \<inter> vars\<^sub>s\<^sub>t S\<^sub>2 = {}" "range_vars \<theta>\<^sub>2 \<inter> bvars\<^sub>s\<^sub>t S\<^sub>2 = {}"
using assms
proof (induction S\<^sub>2 \<theta>\<^sub>2 rule: rtrancl_induct2)
case (step S\<^sub>i \<theta>\<^sub>i S\<^sub>j \<theta>\<^sub>j)
{ case 1 thus ?case using LI_preserves_subst_wf_single[OF \<open>(S\<^sub>i,\<theta>\<^sub>i) \<leadsto> (S\<^sub>j,\<theta>\<^sub>j)\<close>] step.IH by metis }
{ case 2 thus ?case using LI_preserves_subst_wf_single[OF \<open>(S\<^sub>i,\<theta>\<^sub>i) \<leadsto> (S\<^sub>j,\<theta>\<^sub>j)\<close>] step.IH by metis }
{ case 3 thus ?case using LI_preserves_subst_wf_single[OF \<open>(S\<^sub>i,\<theta>\<^sub>i) \<leadsto> (S\<^sub>j,\<theta>\<^sub>j)\<close>] step.IH by metis }
{ case 4 thus ?case using LI_preserves_subst_wf_single[OF \<open>(S\<^sub>i,\<theta>\<^sub>i) \<leadsto> (S\<^sub>j,\<theta>\<^sub>j)\<close>] step.IH by metis }
qed metis
lemma LI_preserves_wellformedness:
assumes "(S\<^sub>1,\<theta>\<^sub>1) \<leadsto>\<^sup>* (S\<^sub>2,\<theta>\<^sub>2)" "wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r S\<^sub>1 \<theta>\<^sub>1"
shows "wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r S\<^sub>2 \<theta>\<^sub>2"
proof -
have *: "wf\<^sub>s\<^sub>t {} S\<^sub>j"
when "(S\<^sub>i, \<theta>\<^sub>i) \<leadsto> (S\<^sub>j, \<theta>\<^sub>j)" "wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r S\<^sub>i \<theta>\<^sub>i" for S\<^sub>i \<theta>\<^sub>i S\<^sub>j \<theta>\<^sub>j
using that
proof (induction rule: LI_rel.induct)
case (Compose S T f S' \<theta>) thus ?case by (metis wf_send_compose wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r_def)
next
case (Unify S f U \<delta> T S' \<theta>)
have "fv (Fun f T) \<union> fv (Fun f U) \<subseteq> fv\<^sub>s\<^sub>t (S@Send [Fun f T]#S')" using Unify.hyps(2) by force
hence "subst_domain \<delta> \<union> range_vars \<delta> \<subseteq> fv\<^sub>s\<^sub>t (S@Send [Fun f T]#S')"
using mgu_vars_bounded[OF Unify.hyps(3)[symmetric]] by (metis subset_trans)
hence "(subst_domain \<delta> \<union> range_vars \<delta>) \<inter> bvars\<^sub>s\<^sub>t (S@Send [Fun f T]#S') = {}"
using Unify.prems unfolding wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r_def by blast
thus ?case
using wf_unify[OF _ Unify.hyps(2) MGU_is_Unifier[OF mgu_gives_MGU], of "{}",
OF _ Unify.hyps(3)[symmetric], of S'] Unify.prems(1)
by (auto simp add: wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r_def)
next
case (Equality S \<delta> t t' a S' \<theta>)
have "fv t \<union> fv t' \<subseteq> fv\<^sub>s\<^sub>t (S@Equality a t t'#S')" using Equality.hyps(2) by force
hence "subst_domain \<delta> \<union> range_vars \<delta> \<subseteq> fv\<^sub>s\<^sub>t (S@Equality a t t'#S')"
using mgu_vars_bounded[OF Equality.hyps(2)[symmetric]] by (metis subset_trans)
hence "(subst_domain \<delta> \<union> range_vars \<delta>) \<inter> bvars\<^sub>s\<^sub>t (S@Equality a t t'#S') = {}"
using Equality.prems unfolding wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r_def by blast
thus ?case
using wf_equality[OF _ Equality.hyps(2)[symmetric], of "{}" S a S'] Equality.prems(1)
by (auto simp add: wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r_def)
qed
show ?thesis using assms
proof (induction rule: rtrancl_induct2)
case (step S\<^sub>i \<theta>\<^sub>i S\<^sub>j \<theta>\<^sub>j) thus ?case
using LI_preserves_subst_wf_single[OF \<open>(S\<^sub>i,\<theta>\<^sub>i) \<leadsto> (S\<^sub>j,\<theta>\<^sub>j)\<close>] *[OF \<open>(S\<^sub>i,\<theta>\<^sub>i) \<leadsto> (S\<^sub>j,\<theta>\<^sub>j)\<close>]
by (metis wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r_def)
qed simp
qed
{ fix s assume "s \<in> set (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>)"
hence "\<exists>s' \<in> set (S@S'). s = s' \<cdot>\<^sub>s\<^sub>t\<^sub>p \<delta> \<and> wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>t\<^sub>p s')"
using Unify.prems(1) by (auto simp add: subst_apply_strand_def)
moreover {
fix s' assume s': "s = s' \<cdot>\<^sub>s\<^sub>t\<^sub>p \<delta>" "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>t\<^sub>p s')" "s' \<in> set (S@S')"
from s'(2) have "trms\<^sub>s\<^sub>t\<^sub>p (s' \<cdot>\<^sub>s\<^sub>t\<^sub>p \<delta>) = trms\<^sub>s\<^sub>t\<^sub>p s' \<cdot>\<^sub>s\<^sub>e\<^sub>t (rm_vars (set (bvars\<^sub>s\<^sub>t\<^sub>p s')) \<delta>)"
proof (induction s')
case (Inequality X F) thus ?case by (induct F) (auto simp add: subst_apply_pairs_def)
qed auto
hence "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>t\<^sub>p s)"
using wf_trm_subst[OF wf_trms_subst_rm_vars'[OF range_wf]] \<open>wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>t\<^sub>p s')\<close> s'(1)
by simp
}
ultimately have "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>t\<^sub>p s)" by auto
}
thus ?case by auto
next
case (Equality S \<delta> t t' a S' \<theta>)
hence "wf\<^sub>t\<^sub>r\<^sub>m t" "wf\<^sub>t\<^sub>r\<^sub>m t'" by simp_all
hence range_wf: "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range \<delta>)"
using mgu_wf_trm[OF Equality.hyps(2)[symmetric]] by simp
{ fix s assume "s \<in> set (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>)"
hence "\<exists>s' \<in> set (S@S'). s = s' \<cdot>\<^sub>s\<^sub>t\<^sub>p \<delta> \<and> wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>t\<^sub>p s')"
using Equality.prems(1) by (auto simp add: subst_apply_strand_def)
moreover {
fix s' assume s': "s = s' \<cdot>\<^sub>s\<^sub>t\<^sub>p \<delta>" "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>t\<^sub>p s')" "s' \<in> set (S@S')"
from s'(2) have "trms\<^sub>s\<^sub>t\<^sub>p (s' \<cdot>\<^sub>s\<^sub>t\<^sub>p \<delta>) = trms\<^sub>s\<^sub>t\<^sub>p s' \<cdot>\<^sub>s\<^sub>e\<^sub>t (rm_vars (set (bvars\<^sub>s\<^sub>t\<^sub>p s')) \<delta>)"
proof (induction s')
case (Inequality X F) thus ?case by (induct F) (auto simp add: subst_apply_pairs_def)
qed auto
hence "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>t\<^sub>p s)"
using wf_trm_subst[OF wf_trms_subst_rm_vars'[OF range_wf]] \<open>wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>t\<^sub>p s')\<close> s'(1)
by simp
}
ultimately have "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>t\<^sub>p s)" by auto
}
thus ?case by auto
qed
}
with assms show ?thesis by (induction rule: rtrancl_induct2) metis+
qed
lemma LI_preproc_prop_subst:
"LI_preproc_prop S \<longleftrightarrow> LI_preproc_prop (S \<cdot>\<^sub>s\<^sub>t \<delta>)"
proof (induction S)
case (Cons x S) thus ?case unfolding LI_preproc_prop_def by (cases x) auto
qed (simp add: LI_preproc_prop_def)
lemma LI_preserves_LI_preproc_prop:
assumes "(S\<^sub>1,\<theta>\<^sub>1) \<leadsto>\<^sup>* (S\<^sub>2,\<theta>\<^sub>2)" "LI_preproc_prop S\<^sub>1"
shows "LI_preproc_prop S\<^sub>2"
using assms
proof (induction rule: rtrancl_induct2)
case (step S\<^sub>i \<theta>\<^sub>i S\<^sub>j \<theta>\<^sub>j)
hence "LI_preproc_prop S\<^sub>i" by metis
with step.hyps(2) show ?case
proof (induction rule: LI_rel.induct)
case (Unify S f T' \<delta> T S' \<theta>) thus ?case
using LI_preproc_prop_subst LI_preproc_prop_split
by (metis append.left_neutral append_Cons)
next
case (Equality S \<delta> t t' uu S' \<theta>) thus ?case
using LI_preproc_prop_subst LI_preproc_prop_split
by (metis append.left_neutral append_Cons)
qed (auto simp add: LI_preproc_prop_def)
qed simp
end
subsection \<open>Theorem: Soundness of the Lazy Intruder\<close>
context
begin
private lemma LI_soundness_single:
assumes "wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r S\<^sub>1 \<theta>\<^sub>1" "(S\<^sub>1,\<theta>\<^sub>1) \<leadsto> (S\<^sub>2,\<theta>\<^sub>2)" "\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>2,\<theta>\<^sub>2\<rangle>"
shows "\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>1,\<theta>\<^sub>1\<rangle>"
using assms(2,1,3)
proof (induction rule: LI_rel.induct)
case (Compose S T f S' \<theta>)
have "ik\<^sub>s\<^sub>t (map Send1 T) \<cdot>\<^sub>s\<^sub>e\<^sub>t \<theta> = {}" by fastforce
hence *: "\<lbrakk>{}; S\<rbrakk>\<^sub>c \<I>" "\<lbrakk>ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>; map Send1 T\<rbrakk>\<^sub>c \<I>" "\<lbrakk>ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>; S'\<rbrakk>\<^sub>c \<I>"
using Compose unfolding constr_sem_c_def
by (force, force, fastforce)
have "ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I> \<turnstile>\<^sub>c Fun f T \<cdot> \<I>"
using *(2) Compose.hyps(2) ComposeC[OF _ Compose.hyps(3), of "map (\<lambda>x. x \<cdot> \<I>) T"]
unfolding subst_compose_def by force
thus "\<I> \<Turnstile>\<^sub>c \<langle>S@Send [Fun f T]#S',\<theta>\<rangle>"
using *(1,3) \<open>\<I> \<Turnstile>\<^sub>c \<langle>S@map Send1 T@S',\<theta>\<rangle>\<close>
by (auto simp add: constr_sem_c_def)
next
case (Unify S f U \<delta> T S' \<theta>)
have "(\<theta> \<circ>\<^sub>s \<delta>) supports \<I>" "\<lbrakk>{}; S@S' \<cdot>\<^sub>s\<^sub>t \<delta>\<rbrakk>\<^sub>c \<I>"
using Unify.prems(2) unfolding constr_sem_c_def by metis+
then obtain \<sigma> where \<sigma>: "\<theta> \<circ>\<^sub>s \<delta> \<circ>\<^sub>s \<sigma> = \<I>" unfolding subst_compose_def by auto
have \<theta>fun_id: "Fun f U \<cdot> \<theta> = Fun f U" "Fun f T \<cdot> \<theta> = Fun f T"
using Unify.prems(1) trm_subst_ident[of "Fun f U" \<theta>]
fv_subset_if_in_strand_ik[of "Fun f U" S] Unify.hyps(2)
fv_snd_rcv_strand_subset(2)[of S]
strand_vars_split(1)[of S "Send [Fun f T]#S'"]
unfolding wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r_def apply blast
using Unify.prems(1) trm_subst_ident[of "Fun f T" \<theta>]
unfolding wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r_def by fastforce
hence \<theta>\<delta>_disj:
"subst_domain \<theta> \<inter> subst_domain \<delta> = {}"
"subst_domain \<theta> \<inter> range_vars \<delta> = {}"
"subst_domain \<theta> \<inter> range_vars \<theta> = {}"
using trm_subst_disj mgu_vars_bounded[OF Unify.hyps(3)[symmetric]] apply (blast,blast)
using Unify.prems(1) unfolding wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r_def wf\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t_def by blast
hence \<theta>\<delta>_support: "\<theta> supports \<I>" "\<delta> supports \<I>"
by (simp_all add: subst_support_comp_split[OF \<open>(\<theta> \<circ>\<^sub>s \<delta>) supports \<I>\<close>])
have "fv (Fun f T) \<subseteq> fv\<^sub>s\<^sub>t (S@Send [Fun f T]#S')" "fv (Fun f U) \<subseteq> fv\<^sub>s\<^sub>t (S@Send [Fun f T]#S')"
using Unify.hyps(2) by force+
hence \<delta>_vars_bound: "subst_domain \<delta> \<union> range_vars \<delta> \<subseteq> fv\<^sub>s\<^sub>t (S@Send [Fun f T]#S')"
using mgu_vars_bounded[OF Unify.hyps(3)[symmetric]] by blast
have "\<lbrakk>ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>; [Send [Fun f T]]\<rbrakk>\<^sub>c \<I>"
proof -
from Unify.hyps(2) have "Fun f U \<cdot> \<I> \<in> ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>" by blast
hence "Fun f U \<cdot> \<I> \<in> ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>" by blast
moreover have "Unifier \<delta> (Fun f T) (Fun f U)"
by (fact MGU_is_Unifier[OF mgu_gives_MGU[OF Unify.hyps(3)[symmetric]]])
ultimately have "Fun f T \<cdot> \<I> \<in> ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>"
using \<sigma> by (metis \<theta>fun_id subst_subst_compose)
thus ?thesis by simp
qed
have "\<lbrakk>{}; S\<rbrakk>\<^sub>c \<I>" "\<lbrakk>ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>; S'\<rbrakk>\<^sub>c \<I>"
proof -
have "(S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) \<cdot>\<^sub>s\<^sub>t \<theta> = S@S' \<cdot>\<^sub>s\<^sub>t \<delta>" "(S@S') \<cdot>\<^sub>s\<^sub>t \<theta> = S@S'"
proof -
have "subst_domain \<theta> \<inter> vars\<^sub>s\<^sub>t (S@S') = {}"
using Unify.prems(1) by (auto simp add: wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r_def)
hence "subst_domain \<theta> \<inter> vars\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) = {}"
using \<theta>\<delta>_disj(2) strand_subst_vars_union_bound[of "S@S'" \<delta>] by blast
thus "(S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) \<cdot>\<^sub>s\<^sub>t \<theta> = S@S' \<cdot>\<^sub>s\<^sub>t \<delta>" "(S@S') \<cdot>\<^sub>s\<^sub>t \<theta> = S@S'"
using strand_subst_comp \<open>subst_domain \<theta> \<inter> vars\<^sub>s\<^sub>t (S@S') = {}\<close> by (blast,blast)
qed
moreover have "subst_idem \<delta>" by (fact mgu_gives_subst_idem[OF Unify.hyps(3)[symmetric]])
moreover have
"(subst_domain \<theta> \<union> range_vars \<theta>) \<inter> bvars\<^sub>s\<^sub>t (S@S') = {}"
"(subst_domain \<theta> \<union> range_vars \<theta>) \<inter> bvars\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) = {}"
"(subst_domain \<delta> \<union> range_vars \<delta>) \<inter> bvars\<^sub>s\<^sub>t (S@S') = {}"
using wf_constr_bvars_disj[OF Unify.prems(1)]
wf_constr_bvars_disj'[OF Unify.prems(1) \<delta>_vars_bound]
by auto
ultimately have "\<lbrakk>{}; S@S'\<rbrakk>\<^sub>c \<I>"
using \<open>\<lbrakk>{}; S@S' \<cdot>\<^sub>s\<^sub>t \<delta>\<rbrakk>\<^sub>c \<I>\<close> \<sigma>
strand_sem_subst(1)[of \<theta> "S@S' \<cdot>\<^sub>s\<^sub>t \<delta>" "{}" "\<delta> \<circ>\<^sub>s \<sigma>"]
strand_sem_subst(2)[of \<theta> "S@S'" "{}" "\<delta> \<circ>\<^sub>s \<sigma>"]
strand_sem_subst_subst_idem[of \<delta> "S@S'" "{}" \<sigma>]
unfolding constr_sem_c_def
by (metis subst_compose_assoc)
thus "\<lbrakk>{}; S\<rbrakk>\<^sub>c \<I>" "\<lbrakk>ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>; S'\<rbrakk>\<^sub>c \<I>" by auto
qed
show "\<I> \<Turnstile>\<^sub>c \<langle>S@Send [Fun f T]#S',\<theta>\<rangle>"
using \<theta>\<delta>_support(1) \<open>\<lbrakk>ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>; [Send [Fun f T]]\<rbrakk>\<^sub>c \<I>\<close> \<open>\<lbrakk>{}; S\<rbrakk>\<^sub>c \<I>\<close> \<open>\<lbrakk>ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>; S'\<rbrakk>\<^sub>c \<I>\<close>
by (auto simp add: constr_sem_c_def)
next
case (Equality S \<delta> t t' a S' \<theta>)
have "(\<theta> \<circ>\<^sub>s \<delta>) supports \<I>" "\<lbrakk>{}; S@S' \<cdot>\<^sub>s\<^sub>t \<delta>\<rbrakk>\<^sub>c \<I>"
using Equality.prems(2) unfolding constr_sem_c_def by metis+
then obtain \<sigma> where \<sigma>: "\<theta> \<circ>\<^sub>s \<delta> \<circ>\<^sub>s \<sigma> = \<I>" unfolding subst_compose_def by auto
have "fv t \<subseteq> vars\<^sub>s\<^sub>t (S@Equality a t t'#S')" "fv t' \<subseteq> vars\<^sub>s\<^sub>t (S@Equality a t t'#S')"
by auto
moreover have "subst_domain \<theta> \<inter> vars\<^sub>s\<^sub>t (S@Equality a t t'#S') = {}"
using Equality.prems(1) unfolding wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r_def by auto
ultimately have \<theta>fun_id: "t \<cdot> \<theta> = t" "t' \<cdot> \<theta> = t'"
using trm_subst_ident[of t \<theta>] trm_subst_ident[of t' \<theta>]
by auto
hence \<theta>\<delta>_disj:
"subst_domain \<theta> \<inter> subst_domain \<delta> = {}"
"subst_domain \<theta> \<inter> range_vars \<delta> = {}"
"subst_domain \<theta> \<inter> range_vars \<theta> = {}"
using trm_subst_disj mgu_vars_bounded[OF Equality.hyps(2)[symmetric]] apply (blast,blast)
using Equality.prems(1) unfolding wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r_def wf\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t_def by blast
hence \<theta>\<delta>_support: "\<theta> supports \<I>" "\<delta> supports \<I>"
by (simp_all add: subst_support_comp_split[OF \<open>(\<theta> \<circ>\<^sub>s \<delta>) supports \<I>\<close>])
have "fv t \<subseteq> fv\<^sub>s\<^sub>t (S@Equality a t t'#S')" "fv t' \<subseteq> fv\<^sub>s\<^sub>t (S@Equality a t t'#S')" by auto
hence \<delta>_vars_bound: "subst_domain \<delta> \<union> range_vars \<delta> \<subseteq> fv\<^sub>s\<^sub>t (S@Equality a t t'#S')"
using mgu_vars_bounded[OF Equality.hyps(2)[symmetric]] by blast
have "\<lbrakk>ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>; [Equality a t t']\<rbrakk>\<^sub>c \<I>"
proof -
have "t \<cdot> \<delta> = t' \<cdot> \<delta>"
using MGU_is_Unifier[OF mgu_gives_MGU[OF Equality.hyps(2)[symmetric]]]
by metis
hence "t \<cdot> (\<theta> \<circ>\<^sub>s \<delta>) = t' \<cdot> (\<theta> \<circ>\<^sub>s \<delta>)" by (metis \<theta>fun_id subst_subst_compose)
hence "t \<cdot> \<I> = t' \<cdot> \<I>" by (metis \<sigma> subst_subst_compose)
thus ?thesis by simp
qed
have "\<lbrakk>{}; S\<rbrakk>\<^sub>c \<I>" "\<lbrakk>ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>; S'\<rbrakk>\<^sub>c \<I>"
proof -
have "(S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) \<cdot>\<^sub>s\<^sub>t \<theta> = S@S' \<cdot>\<^sub>s\<^sub>t \<delta>" "(S@S') \<cdot>\<^sub>s\<^sub>t \<theta> = S@S'"
proof -
have "subst_domain \<theta> \<inter> vars\<^sub>s\<^sub>t (S@S') = {}"
using Equality.prems(1)
by (fastforce simp add: wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r_def simp del: subst_range.simps)
hence "subst_domain \<theta> \<inter> fv\<^sub>s\<^sub>t (S@S') = {}" by blast
hence "subst_domain \<theta> \<inter> fv\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) = {}"
using \<theta>\<delta>_disj(2) subst_sends_strand_fv_to_img[of "S@S'" \<delta>] by blast
thus "(S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) \<cdot>\<^sub>s\<^sub>t \<theta> = S@S' \<cdot>\<^sub>s\<^sub>t \<delta>" "(S@S') \<cdot>\<^sub>s\<^sub>t \<theta> = S@S'"
using strand_subst_comp \<open>subst_domain \<theta> \<inter> vars\<^sub>s\<^sub>t (S@S') = {}\<close> by (blast,blast)
qed
moreover have
"(subst_domain \<theta> \<union> range_vars \<theta>) \<inter> bvars\<^sub>s\<^sub>t (S@S') = {}"
"(subst_domain \<theta> \<union> range_vars \<theta>) \<inter> bvars\<^sub>s\<^sub>t (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>) = {}"
"(subst_domain \<delta> \<union> range_vars \<delta>) \<inter> bvars\<^sub>s\<^sub>t (S@S') = {}"
using wf_constr_bvars_disj[OF Equality.prems(1)]
wf_constr_bvars_disj'[OF Equality.prems(1) \<delta>_vars_bound]
by auto
ultimately have "\<lbrakk>{}; S@S'\<rbrakk>\<^sub>c \<I>"
using \<open>\<lbrakk>{}; S@S' \<cdot>\<^sub>s\<^sub>t \<delta>\<rbrakk>\<^sub>c \<I>\<close> \<sigma>
strand_sem_subst(1)[of \<theta> "S@S' \<cdot>\<^sub>s\<^sub>t \<delta>" "{}" "\<delta> \<circ>\<^sub>s \<sigma>"]
strand_sem_subst(2)[of \<theta> "S@S'" "{}" "\<delta> \<circ>\<^sub>s \<sigma>"]
strand_sem_subst_subst_idem[of \<delta> "S@S'" "{}" \<sigma>]
mgu_gives_subst_idem[OF Equality.hyps(2)[symmetric]]
unfolding constr_sem_c_def
by (metis subst_compose_assoc)
thus "\<lbrakk>{}; S\<rbrakk>\<^sub>c \<I>" "\<lbrakk>ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>; S'\<rbrakk>\<^sub>c \<I>" by auto
qed
show "\<I> \<Turnstile>\<^sub>c \<langle>S@Equality a t t'#S',\<theta>\<rangle>"
using \<theta>\<delta>_support(1) \<open>\<lbrakk>ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>; [Equality a t t']\<rbrakk>\<^sub>c \<I>\<close> \<open>\<lbrakk>{}; S\<rbrakk>\<^sub>c \<I>\<close> \<open>\<lbrakk>ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>; S'\<rbrakk>\<^sub>c \<I>\<close>
by (auto simp add: constr_sem_c_def)
qed
theorem LI_soundness:
assumes "wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r S\<^sub>1 \<theta>\<^sub>1" "(LI_preproc S\<^sub>1,\<theta>\<^sub>1) \<leadsto>\<^sup>* (S\<^sub>2,\<theta>\<^sub>2)" "\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>2, \<theta>\<^sub>2\<rangle>"
shows "\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>1, \<theta>\<^sub>1\<rangle>"
using assms(2,1,3)
proof (induction S\<^sub>2 \<theta>\<^sub>2 rule: rtrancl_induct2)
case (step S\<^sub>i \<theta>\<^sub>i S\<^sub>j \<theta>\<^sub>j) thus ?case
using LI_preproc_preserves_wellformedness[OF \<open>wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r S\<^sub>1 \<theta>\<^sub>1\<close>]
LI_preserves_wellformedness[OF \<open>(LI_preproc S\<^sub>1, \<theta>\<^sub>1) \<leadsto>\<^sup>* (S\<^sub>i, \<theta>\<^sub>i)\<close>]
LI_soundness_single[OF _ \<open>(S\<^sub>i, \<theta>\<^sub>i) \<leadsto> (S\<^sub>j, \<theta>\<^sub>j)\<close> \<open>\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>j, \<theta>\<^sub>j\<rangle>\<close>]
by metis
qed (metis LI_preproc_sem_eq')
end
subsection \<open>Theorem: Completeness of the Lazy Intruder\<close>
context
begin
private lemma LI_completeness_single:
assumes "wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r S\<^sub>1 \<theta>\<^sub>1" "\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>1, \<theta>\<^sub>1\<rangle>" "\<not>simple S\<^sub>1" "LI_preproc_prop S\<^sub>1"
shows "\<exists>S\<^sub>2 \<theta>\<^sub>2. (S\<^sub>1,\<theta>\<^sub>1) \<leadsto> (S\<^sub>2,\<theta>\<^sub>2) \<and> (\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>2, \<theta>\<^sub>2\<rangle>)"
using not_simple_elim[OF \<open>\<not>simple S\<^sub>1\<close>]
proof -
{ \<comment> \<open>In this case \<open>S\<^sub>1\<close> isn't simple because it contains an equality constraint,
so we can simply proceed with the reduction by computing the MGU for the equation\<close>
assume "\<exists>S' S'' a t t'. S\<^sub>1 = S'@Equality a t t'#S'' \<and> simple S'"
then obtain S a t t' S' where S\<^sub>1: "S\<^sub>1 = S@Equality a t t'#S'" "simple S" by moura
hence *: "wf\<^sub>s\<^sub>t {} S" "\<I> \<Turnstile>\<^sub>c \<langle>S, \<theta>\<^sub>1\<rangle>" "\<theta>\<^sub>1 supports \<I>" "t \<cdot> \<I> = t' \<cdot> \<I>"
using \<open>\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>1, \<theta>\<^sub>1\<rangle>\<close> \<open>wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r S\<^sub>1 \<theta>\<^sub>1\<close> wf_eq_fv[of "{}" S t t' S']
fv_snd_rcv_strand_subset(5)[of S]
by (auto simp add: constr_sem_c_def wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r_def)
from * have "Unifier \<I> t t'" by simp
then obtain \<delta> where \<delta>:
"Some \<delta> = mgu t t'" "subst_idem \<delta>" "subst_domain \<delta> \<union> range_vars \<delta> \<subseteq> fv t \<union> fv t'"
using mgu_always_unifies mgu_gives_subst_idem mgu_vars_bounded by metis+
have "\<delta> \<preceq>\<^sub>\<circ> \<I>"
using mgu_gives_MGU[OF \<delta>(1)[symmetric]]
by (metis \<open>Unifier \<I> t t'\<close>)
hence "\<delta> supports \<I>" using subst_support_if_mgt_subst_idem[OF _ \<delta>(2)] by metis
hence "(\<theta>\<^sub>1 \<circ>\<^sub>s \<delta>) supports \<I>" using subst_support_comp \<open>\<theta>\<^sub>1 supports \<I>\<close> by metis
have "\<lbrakk>{}; S@S' \<cdot>\<^sub>s\<^sub>t \<delta>\<rbrakk>\<^sub>c \<I>"
proof -
have "subst_domain \<delta> \<union> range_vars \<delta> \<subseteq> fv\<^sub>s\<^sub>t S\<^sub>1" using \<delta>(3) S\<^sub>1(1) by auto
hence "\<lbrakk>{}; S\<^sub>1 \<cdot>\<^sub>s\<^sub>t \<delta>\<rbrakk>\<^sub>c \<I>"
using \<open>subst_idem \<delta>\<close> \<open>\<delta> \<preceq>\<^sub>\<circ> \<I>\<close> \<open>\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>1, \<theta>\<^sub>1\<rangle>\<close> strand_sem_subst
wf_constr_bvars_disj'(1)[OF assms(1)]
unfolding subst_idem_def constr_sem_c_def
by (metis (no_types) subst_compose_assoc)
thus "\<lbrakk>{}; S@S' \<cdot>\<^sub>s\<^sub>t \<delta>\<rbrakk>\<^sub>c \<I>" using S\<^sub>1(1) by force
qed
moreover have "(S@Equality a t t'#S', \<theta>\<^sub>1) \<leadsto> (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>, \<theta>\<^sub>1 \<circ>\<^sub>s \<delta>)"
using LI_rel.Equality[OF \<open>simple S\<close> \<delta>(1)] S\<^sub>1 by metis
ultimately have ?thesis
using S\<^sub>1(1) \<open>(\<theta>\<^sub>1 \<circ>\<^sub>s \<delta>) supports \<I>\<close>
by (auto simp add: constr_sem_c_def)
} moreover {
\<comment> \<open>In this case \<open>S\<^sub>1\<close> isn't simple because it contains a deduction constraint for a composed
term, so we must look at how this composed term is derived under the interpretation \<open>\<I>\<close>\<close>
assume "\<exists>S' S'' ts. S\<^sub>1 = S'@Send ts#S'' \<and> (\<nexists>x. ts = [Var x]) \<and> simple S'"
hence "\<exists>S' S'' f T. S\<^sub>1 = S'@Send [Fun f T]#S'' \<and> simple S'"
using LI_preproc_prop_SendE[OF \<open>LI_preproc_prop S\<^sub>1\<close>]
by fastforce
with assms obtain S f T S' where S\<^sub>1: "S\<^sub>1 = S@Send [Fun f T]#S'" "simple S" by moura
hence "wf\<^sub>s\<^sub>t {} S" "\<I> \<Turnstile>\<^sub>c \<langle>S, \<theta>\<^sub>1\<rangle>" "\<theta>\<^sub>1 supports \<I>"
using \<open>\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>1, \<theta>\<^sub>1\<rangle>\<close> \<open>wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r S\<^sub>1 \<theta>\<^sub>1\<close>
by (auto simp add: constr_sem_c_def wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r_def)
\<comment> \<open>Lemma for a common subcase\<close>
have fun_sat: "\<I> \<Turnstile>\<^sub>c \<langle>S@(map Send1 T)@S', \<theta>\<^sub>1\<rangle>"
when T: "\<And>t. t \<in> set T \<Longrightarrow> ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I> \<turnstile>\<^sub>c t \<cdot> \<I>"
proof -
have "\<And>t. t \<in> set T \<Longrightarrow> \<lbrakk>ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>; [Send1 t]\<rbrakk>\<^sub>c \<I>" using T by simp
hence "\<lbrakk>ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>; map Send1 T\<rbrakk>\<^sub>c \<I>"
using \<open>\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>1, \<theta>\<^sub>1\<rangle>\<close> strand_sem_Send_map by blast
moreover have "ik\<^sub>s\<^sub>t (S@[Send1 (Fun f T)]) \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I> = ik\<^sub>s\<^sub>t (S@(map Send1 T)) \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>" by auto
hence "\<lbrakk>ik\<^sub>s\<^sub>t (S@(map Send1 T)) \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>; S'\<rbrakk>\<^sub>c \<I>"
using \<open>\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>1, \<theta>\<^sub>1\<rangle>\<close> unfolding S\<^sub>1(1) constr_sem_c_def by force
ultimately show ?thesis
using \<open>\<I> \<Turnstile>\<^sub>c \<langle>S, \<theta>\<^sub>1\<rangle>\<close> strand_sem_append(1)[of "{}" S \<I> "map Send1 T"]
strand_sem_append(1)[of "{}" "S@map Send1 T" \<I> S']
unfolding constr_sem_c_def by simp
qed
from S\<^sub>1 \<open>\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>1, \<theta>\<^sub>1\<rangle>\<close> have "ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I> \<turnstile>\<^sub>c Fun f T \<cdot> \<I>" by (auto simp add: constr_sem_c_def)
hence ?thesis
proof cases
\<comment> \<open>Case 1: \<open>\<I>(f(T))\<close> has been derived using the \<open>AxiomC\<close> rule.\<close>
case AxiomC
hence ex_t: "\<exists>t. t \<in> ik\<^sub>s\<^sub>t S \<and> Fun f T \<cdot> \<I> = t \<cdot> \<I>" by auto
show ?thesis
proof (cases "\<forall>T'. Fun f T' \<in> ik\<^sub>s\<^sub>t S \<longrightarrow> Fun f T \<cdot> \<I> \<noteq> Fun f T' \<cdot> \<I>")
\<comment> \<open>Case 1.1: \<open>f(T)\<close> is equal to a variable in the intruder knowledge under \<open>\<I>\<close>.
Hence there must exists a deduction constraint in the simple prefix of the constraint
in which this variable occurs/"is sent" for the first time. Since this variable itself
cannot have been derived from the \<open>AxiomC\<close> rule (because it must be equal under the
interpretation to \<open>f(T)\<close>, which is by assumption not in the intruder knowledge under
\<open>\<I>\<close>) it must be the case that we can derive it using the \<open>ComposeC\<close> rule. Hence we can
apply the \<open>Compose\<close> rule of the lazy intruder to \<open>f(T)\<close>.\<close>
case True
have "\<exists>v. Var v \<in> ik\<^sub>s\<^sub>t S \<and> Fun f T \<cdot> \<I> = \<I> v"
proof -
obtain t where "t \<in> ik\<^sub>s\<^sub>t S" "Fun f T \<cdot> \<I> = t \<cdot> \<I>" using ex_t by moura
thus ?thesis
using \<open>\<forall>T'. Fun f T' \<in> ik\<^sub>s\<^sub>t S \<longrightarrow> Fun f T \<cdot> \<I> \<noteq> Fun f T' \<cdot> \<I>\<close>
by (cases t) auto
qed
hence "\<exists>v \<in> wfrestrictedvars\<^sub>s\<^sub>t S. Fun f T \<cdot> \<I> = \<I> v"
using vars_subset_if_in_strand_ik2[of _ S] by fastforce
then obtain v S\<^sub>p\<^sub>r\<^sub>e S\<^sub>s\<^sub>u\<^sub>f
where S: "S = S\<^sub>p\<^sub>r\<^sub>e@Send [Var v]#S\<^sub>s\<^sub>u\<^sub>f" "Fun f T \<cdot> \<I> = \<I> v"
"\<not>(\<exists>w \<in> wfrestrictedvars\<^sub>s\<^sub>t S\<^sub>p\<^sub>r\<^sub>e. Fun f T \<cdot> \<I> = \<I> w)"
using \<open>wf\<^sub>s\<^sub>t {} S\<close> wf_simple_strand_first_Send_var_split[OF _ \<open>simple S\<close>, of "Fun f T" \<I>]
by auto
hence "\<forall>w. Var w \<in> ik\<^sub>s\<^sub>t S\<^sub>p\<^sub>r\<^sub>e \<longrightarrow> \<I> v \<noteq> Var w \<cdot> \<I>" by force
moreover have "\<forall>T'. Fun f T' \<in> ik\<^sub>s\<^sub>t S\<^sub>p\<^sub>r\<^sub>e \<longrightarrow> Fun f T \<cdot> \<I> \<noteq> Fun f T' \<cdot> \<I>"
using \<open>\<forall>T'. Fun f T' \<in> ik\<^sub>s\<^sub>t S \<longrightarrow> Fun f T \<cdot> \<I> \<noteq> Fun f T' \<cdot> \<I>\<close> S(1)
by (meson contra_subsetD ik_append_subset(1))
hence "\<forall>g T'. Fun g T' \<in> ik\<^sub>s\<^sub>t S\<^sub>p\<^sub>r\<^sub>e \<longrightarrow> \<I> v \<noteq> Fun g T' \<cdot> \<I>" using S(2) by simp
ultimately have "\<forall>t \<in> ik\<^sub>s\<^sub>t S\<^sub>p\<^sub>r\<^sub>e. \<I> v \<noteq> t \<cdot> \<I>" by (metis term.exhaust)
hence "\<I> v \<notin> (ik\<^sub>s\<^sub>t S\<^sub>p\<^sub>r\<^sub>e) \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>" by auto
have "ik\<^sub>s\<^sub>t S\<^sub>p\<^sub>r\<^sub>e \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I> \<turnstile>\<^sub>c \<I> v"
using S\<^sub>1(1) S(1) \<open>\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>1, \<theta>\<^sub>1\<rangle>\<close>
by (auto simp add: constr_sem_c_def)
hence "ik\<^sub>s\<^sub>t S\<^sub>p\<^sub>r\<^sub>e \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I> \<turnstile>\<^sub>c Fun f T \<cdot> \<I>" using \<open>Fun f T \<cdot> \<I> = \<I> v\<close> by metis
hence "length T = arity f" "public f" "\<And>t. t \<in> set T \<Longrightarrow> ik\<^sub>s\<^sub>t S\<^sub>p\<^sub>r\<^sub>e \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I> \<turnstile>\<^sub>c t \<cdot> \<I>"
using \<open>Fun f T \<cdot> \<I> = \<I> v\<close> \<open>\<I> v \<notin> ik\<^sub>s\<^sub>t S\<^sub>p\<^sub>r\<^sub>e \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>\<close>
intruder_synth.simps[of "ik\<^sub>s\<^sub>t S\<^sub>p\<^sub>r\<^sub>e \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>" "\<I> v"]
by auto
hence *: "\<And>t. t \<in> set T \<Longrightarrow> ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I> \<turnstile>\<^sub>c t \<cdot> \<I>"
using S(1) by (auto intro: ideduct_synth_mono)
hence "\<I> \<Turnstile>\<^sub>c \<langle>S@(map Send1 T)@S', \<theta>\<^sub>1\<rangle>" by (metis fun_sat)
moreover have "(S@Send [Fun f T]#S', \<theta>\<^sub>1) \<leadsto> (S@map Send1 T@S', \<theta>\<^sub>1)"
by (metis LI_rel.Compose[OF \<open>simple S\<close> \<open>length T = arity f\<close> \<open>public f\<close>])
ultimately show ?thesis using S\<^sub>1 by auto
next
\<comment> \<open>Case 1.2: \<open>\<I>(f(T))\<close> can be derived from an interpreted composed term in the intruder
knowledge. Use the \<open>Unify\<close> rule on this composed term to further reduce the constraint.\<close>
case False
then obtain T' where t: "Fun f T' \<in> ik\<^sub>s\<^sub>t S" "Fun f T \<cdot> \<I> = Fun f T' \<cdot> \<I>"
by auto
hence "fv (Fun f T') \<subseteq> fv\<^sub>s\<^sub>t S\<^sub>1"
using S\<^sub>1(1) fv_subset_if_in_strand_ik'[OF t(1)]
fv_snd_rcv_strand_subset(2)[of S]
by auto
from t have "Unifier \<I> (Fun f T) (Fun f T')" by simp
then obtain \<delta> where \<delta>:
"Some \<delta> = mgu (Fun f T) (Fun f T')" "subst_idem \<delta>"
"subst_domain \<delta> \<union> range_vars \<delta> \<subseteq> fv (Fun f T) \<union> fv (Fun f T')"
using mgu_always_unifies mgu_gives_subst_idem mgu_vars_bounded by metis+
have "\<delta> \<preceq>\<^sub>\<circ> \<I>"
using mgu_gives_MGU[OF \<delta>(1)[symmetric]]
by (metis \<open>Unifier \<I> (Fun f T) (Fun f T')\<close>)
hence "\<delta> supports \<I>" using subst_support_if_mgt_subst_idem[OF _ \<delta>(2)] by metis
hence "(\<theta>\<^sub>1 \<circ>\<^sub>s \<delta>) supports \<I>" using subst_support_comp \<open>\<theta>\<^sub>1 supports \<I>\<close> by metis
have "\<lbrakk>{}; S@S' \<cdot>\<^sub>s\<^sub>t \<delta>\<rbrakk>\<^sub>c \<I>"
proof -
have "subst_domain \<delta> \<union> range_vars \<delta> \<subseteq> fv\<^sub>s\<^sub>t S\<^sub>1"
using \<delta>(3) S\<^sub>1(1) \<open>fv (Fun f T') \<subseteq> fv\<^sub>s\<^sub>t S\<^sub>1\<close>
unfolding range_vars_alt_def by (fastforce simp del: subst_range.simps)
hence "\<lbrakk>{}; S\<^sub>1 \<cdot>\<^sub>s\<^sub>t \<delta>\<rbrakk>\<^sub>c \<I>"
using \<open>subst_idem \<delta>\<close> \<open>\<delta> \<preceq>\<^sub>\<circ> \<I>\<close> \<open>\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>1, \<theta>\<^sub>1\<rangle>\<close> strand_sem_subst
wf_constr_bvars_disj'(1)[OF assms(1)]
unfolding subst_idem_def constr_sem_c_def
by (metis (no_types) subst_compose_assoc)
thus "\<lbrakk>{}; S@S' \<cdot>\<^sub>s\<^sub>t \<delta>\<rbrakk>\<^sub>c \<I>" using S\<^sub>1(1) by force
qed
moreover have "(S@Send [Fun f T]#S', \<theta>\<^sub>1) \<leadsto> (S@S' \<cdot>\<^sub>s\<^sub>t \<delta>, \<theta>\<^sub>1 \<circ>\<^sub>s \<delta>)"
using LI_rel.Unify[OF \<open>simple S\<close> t(1) \<delta>(1)] S\<^sub>1 by metis
ultimately show ?thesis
using S\<^sub>1(1) \<open>(\<theta>\<^sub>1 \<circ>\<^sub>s \<delta>) supports \<I>\<close>
by (auto simp add: constr_sem_c_def)
qed
next
\<comment> \<open>Case 2: \<open>\<I>(f(T))\<close> has been derived using the \<open>ComposeC\<close> rule.
Simply use the \<open>Compose\<close> rule of the lazy intruder to proceed with the reduction.\<close>
case (ComposeC T' g)
hence "f = g" "length T = arity f" "public f"
and "\<And>x. x \<in> set T \<Longrightarrow> ik\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I> \<turnstile>\<^sub>c x \<cdot> \<I>"
by auto
hence "\<I> \<Turnstile>\<^sub>c \<langle>S@(map Send1 T)@S', \<theta>\<^sub>1\<rangle>" using fun_sat by metis
moreover have "(S\<^sub>1, \<theta>\<^sub>1) \<leadsto> (S@(map Send1 T)@S', \<theta>\<^sub>1)"
using S\<^sub>1 LI_rel.Compose[OF \<open>simple S\<close> \<open>length T = arity f\<close> \<open>public f\<close>]
by metis
ultimately show ?thesis by metis
qed
} moreover have "\<And>A B X F. S\<^sub>1 = A@Inequality X F#B \<Longrightarrow> ineq_model \<I> X F"
using assms(2) by (auto simp add: constr_sem_c_def)
ultimately show ?thesis using not_simple_elim[OF \<open>\<not>simple S\<^sub>1\<close>] by metis
qed
theorem LI_completeness:
assumes "wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r S\<^sub>1 \<theta>\<^sub>1" "\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>1, \<theta>\<^sub>1\<rangle>"
shows "\<exists>S\<^sub>2 \<theta>\<^sub>2. (LI_preproc S\<^sub>1,\<theta>\<^sub>1) \<leadsto>\<^sup>* (S\<^sub>2,\<theta>\<^sub>2) \<and> simple S\<^sub>2 \<and> (\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>2, \<theta>\<^sub>2\<rangle>)"
proof (cases "simple (LI_preproc S\<^sub>1)")
case False
let ?Stuck = "\<lambda>S\<^sub>2 \<theta>\<^sub>2. \<not>(\<exists>S\<^sub>3 \<theta>\<^sub>3. (S\<^sub>2,\<theta>\<^sub>2) \<leadsto> (S\<^sub>3,\<theta>\<^sub>3) \<and> (\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>3, \<theta>\<^sub>3\<rangle>))"
let ?Sats = "{((S,\<theta>),(S',\<theta>')). (S,\<theta>) \<leadsto> (S',\<theta>') \<and> (\<I> \<Turnstile>\<^sub>c \<langle>S, \<theta>\<rangle>) \<and> (\<I> \<Turnstile>\<^sub>c \<langle>S', \<theta>'\<rangle>)}"
have simple_if_stuck:
"\<And>S\<^sub>2 \<theta>\<^sub>2. \<lbrakk>(LI_preproc S\<^sub>1,\<theta>\<^sub>1) \<leadsto>\<^sup>+ (S\<^sub>2,\<theta>\<^sub>2); \<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>2, \<theta>\<^sub>2\<rangle>; ?Stuck S\<^sub>2 \<theta>\<^sub>2\<rbrakk> \<Longrightarrow> simple S\<^sub>2"
using LI_preproc_preserves_wellformedness[OF \<open>wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r S\<^sub>1 \<theta>\<^sub>1\<close>]
LI_preserves_LI_preproc_prop[OF _ LI_preproc_preproc_prop]
LI_completeness_single[OF LI_preserves_wellformedness]
trancl_into_rtrancl
by metis
have base: "\<exists>b. ((LI_preproc S\<^sub>1,\<theta>\<^sub>1),b) \<in> ?Sats"
using LI_preproc_preserves_wellformedness[OF \<open>wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r S\<^sub>1 \<theta>\<^sub>1\<close>]
LI_completeness_single[OF _ _ False LI_preproc_preproc_prop]
LI_preproc_sem_eq' \<open>\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>1, \<theta>\<^sub>1\<rangle>\<close>
by auto
have *: "\<And>S \<theta> S' \<theta>'. ((S,\<theta>),(S',\<theta>')) \<in> ?Sats\<^sup>+ \<Longrightarrow> (S,\<theta>) \<leadsto>\<^sup>+ (S',\<theta>') \<and> (\<I> \<Turnstile>\<^sub>c \<langle>S', \<theta>'\<rangle>)"
proof -
fix S \<theta> S' \<theta>'
assume "((S,\<theta>),(S',\<theta>')) \<in> ?Sats\<^sup>+"
thus "(S,\<theta>) \<leadsto>\<^sup>+ (S',\<theta>') \<and> (\<I> \<Turnstile>\<^sub>c \<langle>S', \<theta>'\<rangle>)"
by (induct rule: trancl_induct2) auto
qed
have "\<exists>S\<^sub>2 \<theta>\<^sub>2. ((LI_preproc S\<^sub>1,\<theta>\<^sub>1),(S\<^sub>2,\<theta>\<^sub>2)) \<in> ?Sats\<^sup>+ \<and> ?Stuck S\<^sub>2 \<theta>\<^sub>2"
proof (rule ccontr)
assume "\<not>(\<exists>S\<^sub>2 \<theta>\<^sub>2. ((LI_preproc S\<^sub>1,\<theta>\<^sub>1),(S\<^sub>2,\<theta>\<^sub>2)) \<in> ?Sats\<^sup>+ \<and> ?Stuck S\<^sub>2 \<theta>\<^sub>2)"
hence sat_not_stuck: "\<And>S\<^sub>2 \<theta>\<^sub>2. ((LI_preproc S\<^sub>1,\<theta>\<^sub>1),(S\<^sub>2,\<theta>\<^sub>2)) \<in> ?Sats\<^sup>+ \<Longrightarrow> \<not>?Stuck S\<^sub>2 \<theta>\<^sub>2" by blast
have "\<forall>S \<theta>. ((LI_preproc S\<^sub>1,\<theta>\<^sub>1),(S,\<theta>)) \<in> ?Sats\<^sup>+ \<longrightarrow> (\<exists>b. ((S,\<theta>),b) \<in> ?Sats)"
proof (intro allI impI)
fix S \<theta> assume a: "((LI_preproc S\<^sub>1,\<theta>\<^sub>1),(S,\<theta>)) \<in> ?Sats\<^sup>+"
have "\<And>b. ((LI_preproc S\<^sub>1,\<theta>\<^sub>1),b) \<in> ?Sats\<^sup>+ \<Longrightarrow> \<exists>c. b \<leadsto> c \<and> ((LI_preproc S\<^sub>1,\<theta>\<^sub>1),c) \<in> ?Sats\<^sup>+"
proof -
fix b assume in_sat: "((LI_preproc S\<^sub>1,\<theta>\<^sub>1),b) \<in> ?Sats\<^sup>+"
hence "\<exists>c. (b,c) \<in> ?Sats" using * sat_not_stuck by (cases b) blast
thus "\<exists>c. b \<leadsto> c \<and> ((LI_preproc S\<^sub>1,\<theta>\<^sub>1),c) \<in> ?Sats\<^sup>+"
using trancl_into_trancl[OF in_sat] by blast
qed
hence "\<exists>S' \<theta>'. (S,\<theta>) \<leadsto> (S',\<theta>') \<and> ((LI_preproc S\<^sub>1,\<theta>\<^sub>1),(S',\<theta>')) \<in> ?Sats\<^sup>+" using a by auto
then obtain S' \<theta>' where S'\<theta>': "(S,\<theta>) \<leadsto> (S',\<theta>')" "((LI_preproc S\<^sub>1,\<theta>\<^sub>1),(S',\<theta>')) \<in> ?Sats\<^sup>+" by auto
hence "\<I> \<Turnstile>\<^sub>c \<langle>S', \<theta>'\<rangle>" using * by blast
moreover have "(LI_preproc S\<^sub>1, \<theta>\<^sub>1) \<leadsto>\<^sup>+ (S,\<theta>)" using a trancl_mono by blast
ultimately have "((S,\<theta>),(S',\<theta>')) \<in> ?Sats" using S'\<theta>'(1) * a by blast
thus "\<exists>b. ((S,\<theta>),b) \<in> ?Sats" using S'\<theta>'(2) by blast
qed
hence "\<exists>f. \<forall>i::nat. (f i, f (Suc i)) \<in> ?Sats"
using infinite_chain_intro'[OF base] by blast
moreover have "?Sats \<subseteq> LI_rel\<^sup>+" by auto
hence "\<not>(\<exists>f. \<forall>i::nat. (f i, f (Suc i)) \<in> ?Sats)"
using LI_no_infinite_chain infinite_chain_mono by blast
ultimately show False by auto
qed
hence "\<exists>S\<^sub>2 \<theta>\<^sub>2. (LI_preproc S\<^sub>1, \<theta>\<^sub>1) \<leadsto>\<^sup>+ (S\<^sub>2, \<theta>\<^sub>2) \<and> simple S\<^sub>2 \<and> (\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>2, \<theta>\<^sub>2\<rangle>)"
using simple_if_stuck * by blast
thus ?thesis by (meson trancl_into_rtrancl)
qed (use LI_preproc_sem_eq' \<open>\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>1, \<theta>\<^sub>1\<rangle>\<close> in blast)
end
subsection \<open>Corollary: Soundness and Completeness as a Single Theorem\<close>
corollary LI_soundness_and_completeness:
assumes "wf\<^sub>c\<^sub>o\<^sub>n\<^sub>s\<^sub>t\<^sub>r S\<^sub>1 \<theta>\<^sub>1"
shows "\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>1, \<theta>\<^sub>1\<rangle> \<longleftrightarrow> (\<exists>S\<^sub>2 \<theta>\<^sub>2. (LI_preproc S\<^sub>1,\<theta>\<^sub>1) \<leadsto>\<^sup>* (S\<^sub>2,\<theta>\<^sub>2) \<and> simple S\<^sub>2 \<and> (\<I> \<Turnstile>\<^sub>c \<langle>S\<^sub>2, \<theta>\<^sub>2\<rangle>))"
by (metis LI_soundness[OF assms] LI_completeness[OF assms])
end
end
|
import FemtoCleaner
using Base.Test
println("Dry running DataFrames")
@test FemtoCleaner.cleanrepo("https://github.com/JuliaData/DataFrames.jl"; show_diff = false)
println("Dry running Gadfly")
@test FemtoCleaner.cleanrepo("https://github.com/GiovineItalia/Gadfly.jl"; show_diff = false)
println("Dry running JuMP")
@test FemtoCleaner.cleanrepo("https://github.com/JuliaOpt/JuMP.jl"; show_diff = false)
println("Dry running Plots")
@test FemtoCleaner.cleanrepo("https://github.com/JuliaPlots/Plots.jl"; show_diff = false)
|
(*:maxLineLen=78:*)
chapter \<open>Dutch Book Theorem \label{chap:dutch-book-theorem}\<close>
text \<open> The first completeness theorem for inequalities for probability logic
to be investigated is due to Patrick Suppes.\<close>
theory Dutch_Book
imports
"../../Logic/Classical/Classical_Connectives"
"Probability_Logic_Inequality_Completeness"
"HOL.Real"
begin
section \<open> Fixed Odds Markets \label{sec:fixed-odds-markets} \<close>
record 'p bet_offer =
bet :: 'p
amount :: real
record 'p book =
buys :: "('p bet_offer) list"
sells :: "('p bet_offer) list"
definition payoff :: "('p \<Rightarrow> bool) \<Rightarrow> 'p book \<Rightarrow> real" ("\<pi>") where
[simp]: "\<pi> s b \<equiv> (\<Sum> i \<leftarrow> sells b. (if s (bet i) then 1 else 0) - amount i)
+ (\<Sum> i \<leftarrow> buys b. amount i - (if s (bet i) then 1 else 0))"
definition settle_bet :: "('p \<Rightarrow> bool) \<Rightarrow> 'p \<Rightarrow> real" where
"settle_bet s \<phi> \<equiv> if (s \<phi>) then 1 else 0"
lemma payoff_alt_def1:
"\<pi> s book = (\<Sum> i \<leftarrow> sells book. settle_bet s (bet i) - amount i)
+ (\<Sum> i \<leftarrow> buys book. amount i - settle_bet s (bet i))"
unfolding settle_bet_def
by simp
definition settle :: "('p \<Rightarrow> bool) \<Rightarrow> 'p bet_offer list \<Rightarrow> real" where
"settle s bets \<equiv> \<Sum> b \<leftarrow> bets. settle_bet s (bet b)"
definition total_amount :: "('p bet_offer) list \<Rightarrow> real" where
"total_amount offers \<equiv> \<Sum> i \<leftarrow> offers. amount i"
lemma payoff_alt_def2:
"\<pi> s book = settle s (sells book)
- settle s (buys book)
+ total_amount (buys book)
- total_amount (sells book)"
unfolding payoff_alt_def1 total_amount_def settle_def
by (simp add: sum_list_subtractf)
(* TODO: Cite Lehman *)
definition (in classical_logic) possibility :: "('a \<Rightarrow> bool) \<Rightarrow> bool" where
[simp]: "possibility p \<equiv>
\<not> (p \<bottom>)
\<and> (\<forall> \<phi>. \<turnstile> \<phi> \<longrightarrow> p \<phi>)
\<and> (\<forall> \<phi> \<psi> . p (\<phi> \<rightarrow> \<psi>) \<longrightarrow> p \<phi> \<longrightarrow> p \<psi>)
\<and> (\<forall> \<phi> . p \<phi> \<or> p (\<phi> \<rightarrow> \<bottom>))"
definition (in classical_logic) possibilities :: "('a \<Rightarrow> bool) set" where
[simp]: "possibilities = {p. possibility p}"
lemma (in classical_logic) possibility_negation:
assumes "possibility p"
shows "p (\<phi> \<rightarrow> \<bottom>) = (\<not> p \<phi>)"
proof
assume "p (\<phi> \<rightarrow> \<bottom>)"
show "\<not> p \<phi>"
proof
assume "p \<phi>"
have "\<turnstile> \<phi> \<rightarrow> (\<phi> \<rightarrow> \<bottom>) \<rightarrow> \<bottom>"
by (simp add: double_negation_converse)
hence "p ((\<phi> \<rightarrow> \<bottom>) \<rightarrow> \<bottom>)"
using \<open>p \<phi>\<close> \<open>possibility p\<close> by auto
thus "False" using \<open>p (\<phi> \<rightarrow> \<bottom>)\<close> \<open>possibility p\<close> by auto
qed
next
show "\<not> p \<phi> \<Longrightarrow> p (\<phi> \<rightarrow> \<bottom>)" using \<open>possibility p\<close> by fastforce
qed
lemma (in classical_logic) possibilities_logical_closure:
assumes "possibility p"
and "{x. p x} \<tturnstile> \<phi>"
shows "p \<phi>"
proof -
{
fix \<Gamma>
assume "set \<Gamma> \<subseteq> Collect p"
hence "\<forall> \<phi>. \<Gamma> :\<turnstile> \<phi> \<longrightarrow> p \<phi>"
proof (induct \<Gamma>)
case Nil
have "\<forall>\<phi>. \<turnstile> \<phi> \<longrightarrow> p \<phi>"
using \<open>possibility p\<close> by auto
then show ?case
using list_deduction_base_theory by blast
next
case (Cons \<gamma> \<Gamma>)
hence "p \<gamma>"
by simp
have "\<forall> \<phi>. \<Gamma> :\<turnstile> \<gamma> \<rightarrow> \<phi> \<longrightarrow> p (\<gamma> \<rightarrow> \<phi>)"
using Cons.hyps Cons.prems by auto
then show ?case
by (meson \<open>p \<gamma>\<close> \<open>possibility p\<close> list_deduction_theorem possibility_def)
qed
}
thus ?thesis
using \<open>Collect p \<tturnstile> \<phi>\<close> set_deduction_def by auto
qed
lemma (in classical_logic) possibilities_are_MCS:
assumes "possibility p"
shows "MCS {x. p x}"
using assms
by (metis
(mono_tags, lifting)
formula_consistent_def
formula_maximally_consistent_set_def_def
maximally_consistent_set_def
possibilities_logical_closure
possibility_def
mem_Collect_eq)
lemma (in classical_logic) MCSs_are_possibilities:
assumes "MCS s"
shows "possibility (\<lambda> x. x \<in> s)"
proof -
have "\<bottom> \<notin> s"
using \<open>MCS s\<close>
formula_consistent_def
formula_maximally_consistent_set_def_def
maximally_consistent_set_def
set_deduction_reflection
by blast
moreover have "\<forall> \<phi>. \<turnstile> \<phi> \<longrightarrow> \<phi> \<in> s"
using \<open>MCS s\<close>
formula_maximally_consistent_set_def_reflection
maximally_consistent_set_def
set_deduction_weaken
by blast
moreover have "\<forall> \<phi> \<psi>. (\<phi> \<rightarrow> \<psi>) \<in> s \<longrightarrow> \<phi> \<in> s \<longrightarrow> \<psi> \<in> s"
using \<open>MCS s\<close>
formula_maximal_consistency
formula_maximally_consistent_set_def_implication
by blast
moreover have "\<forall> \<phi>. \<phi> \<in> s \<or> (\<phi> \<rightarrow> \<bottom>) \<in> s"
using assms
formula_maximally_consistent_set_def_implication
maximally_consistent_set_def
by blast
ultimately show ?thesis by simp
qed
definition (in classical_logic) negate_bets ("_\<^sup>\<sim>") where
"bets\<^sup>\<sim> = [b \<lparr> bet := \<sim> (bet b) \<rparr>. b \<leftarrow> bets]"
lemma (in classical_logic) possibility_payoff:
assumes "possibility p"
shows " \<pi> p \<lparr> buys = buys', sells = sells' \<rparr>
= settle p (buys'\<^sup>\<sim> @ sells') + total_amount buys' - total_amount sells' - length buys'"
proof (induct buys')
case Nil
then show ?case
unfolding payoff_alt_def2
negate_bets_def
total_amount_def
settle_def
settle_bet_def
by simp
next
case (Cons b buys')
have "p (\<sim> (bet b)) = (\<not> (p (bet b)))" using assms negation_def by auto
moreover have " total_amount ((b # buys') @ sells')
= amount b + total_amount buys' + total_amount sells'"
unfolding total_amount_def
by (induct buys', induct sells', auto)
ultimately show ?case
using Cons
unfolding payoff_alt_def2 negate_bets_def settle_def settle_bet_def
by simp
qed
lemma (in consistent_classical_logic) minimum_payoff_existence:
"\<exists>! x. (\<exists> p \<in> possibilities. \<pi> p bets = x) \<and> (\<forall> q \<in> possibilities. x \<le> \<pi> q bets)"
proof (rule ex_ex1I)
show "\<exists>x. (\<exists>p\<in>possibilities. \<pi> p bets = x) \<and> (\<forall>q\<in>possibilities. x \<le> \<pi> q bets)"
proof (rule ccontr)
obtain buys' sells' where "bets = \<lparr> buys = buys', sells = sells' \<rparr>"
by (metis book.cases)
assume "\<nexists>x. (\<exists> p \<in> possibilities. \<pi> p bets = x) \<and> (\<forall> q \<in> possibilities. x \<le> \<pi> q bets)"
hence "\<forall>x. (\<exists> p \<in> possibilities. \<pi> p bets = x) \<longrightarrow> (\<exists> q \<in> possibilities. \<pi> q bets < x)"
by (meson le_less_linear)
hence \<star>: "\<forall>p \<in> possibilities. \<exists> q \<in> possibilities. \<pi> q bets < \<pi> p bets"
by blast
have \<lozenge>: "\<forall> p \<in> possibilities. \<exists> q \<in> possibilities.
settle q (buys'\<^sup>\<sim> @ sells') < settle p (buys'\<^sup>\<sim> @ sells')"
proof
fix p
assume "p \<in> possibilities"
from this obtain q where "q \<in> possibilities" and "\<pi> q bets < \<pi> p bets"
using \<star> by blast
hence
" settle q (buys'\<^sup>\<sim> @ sells') + total_amount buys' - total_amount sells' - length buys'
< settle p (buys'\<^sup>\<sim> @ sells') + total_amount buys' - total_amount sells' - length buys'"
by (metis \<open>\<pi> q bets < \<pi> p bets\<close>
\<open>bets = \<lparr>buys = buys', sells = sells'\<rparr>\<close>
\<open>p \<in> possibilities\<close>
possibilities_def
possibility_payoff
mem_Collect_eq)
hence "settle q (buys'\<^sup>\<sim> @ sells') < settle p (buys'\<^sup>\<sim> @ sells')"
by simp
thus "\<exists>q\<in>possibilities. settle q (buys'\<^sup>\<sim> @ sells') < settle p (buys'\<^sup>\<sim> @ sells')"
using \<open>q \<in> possibilities\<close> by blast
qed
{
fix bets :: "('a bet_offer) list"
fix s :: "'a \<Rightarrow> bool"
have "\<exists> n \<in> \<nat>. settle s bets = real n"
unfolding settle_def settle_bet_def
by (induct bets, auto, metis Nats_1 Nats_add Suc_eq_plus1_left of_nat_Suc)
} note \<dagger> = this
{
fix n :: "nat"
have " (\<exists> p \<in> possibilities. settle p (buys'\<^sup>\<sim> @ sells') \<le> n)
\<longrightarrow> (\<exists> q \<in> possibilities. settle q (buys'\<^sup>\<sim> @ sells') < 0)" (is "_ \<longrightarrow> ?consequent")
proof (induct n)
case 0
{
fix p :: "'a \<Rightarrow> bool"
assume"p \<in> possibilities" and "settle p (buys'\<^sup>\<sim> @ sells') \<le> 0"
from this obtain q where
"q \<in> possibilities"
"settle q (buys'\<^sup>\<sim> @ sells') < settle p (buys'\<^sup>\<sim> @ sells')"
using \<lozenge> by blast
hence ?consequent
by (metis "\<dagger>" \<open>settle p (buys'\<^sup>\<sim> @ sells') \<le> 0\<close> of_nat_0_eq_iff of_nat_le_0_iff)
}
then show ?case by auto
next
case (Suc n)
{
fix p :: "'a \<Rightarrow> bool"
assume"p \<in> possibilities" and "settle p (buys'\<^sup>\<sim> @ sells') \<le> Suc n"
from this obtain q\<^sub>1 where
"q\<^sub>1 \<in> possibilities"
"settle q\<^sub>1 (buys'\<^sup>\<sim> @ sells') < Suc n"
by (metis \<lozenge> antisym_conv not_less)
from this obtain q\<^sub>2 where
"q\<^sub>2 \<in> possibilities"
"settle q\<^sub>2 (buys'\<^sup>\<sim> @ sells') < n"
using \<lozenge>
by (metis \<dagger> add.commute nat_le_real_less nat_less_le of_nat_Suc of_nat_less_iff)
hence ?consequent
by (metis \<dagger> Suc.hyps nat_less_le of_nat_le_iff of_nat_less_iff)
}
then show ?case by auto
qed
}
hence "\<nexists> p. p \<in> possibilities"
by (metis \<dagger> not_less0 of_nat_0 of_nat_less_iff order_refl)
moreover
have "\<not> {} \<tturnstile> \<bottom>"
using consistency set_deduction_base_theory by auto
from this obtain \<Gamma> where "MCS \<Gamma>"
by (meson formula_consistent_def
formula_maximal_consistency
formula_maximally_consistent_extension)
hence "(\<lambda> \<gamma>. \<gamma> \<in> \<Gamma>) \<in> possibilities"
using MCSs_are_possibilities possibilities_def by blast
ultimately show False
by blast
qed
next
fix x y
assume A: "(\<exists>p \<in> possibilities. \<pi> p bets = x) \<and> (\<forall>q \<in> possibilities. x \<le> \<pi> q bets)"
and B: "(\<exists>p \<in> possibilities. \<pi> p bets = y) \<and> (\<forall>q \<in> possibilities. y \<le> \<pi> q bets)"
from this obtain p\<^sub>x p\<^sub>y where
"p\<^sub>x \<in> possibilities"
"p\<^sub>y \<in> possibilities"
"\<pi> p\<^sub>x bets = x"
"\<pi> p\<^sub>y bets = y"
by blast
with A B have "x \<le> y" "y \<le> x"
by blast+
thus "x = y" by linarith
qed
definition (in consistent_classical_logic)
minimum_payoff :: "'a book \<Rightarrow> real" ("\<pi>\<^sub>m\<^sub>i\<^sub>n") where
"\<pi>\<^sub>m\<^sub>i\<^sub>n b \<equiv> THE x. (\<exists> p \<in> possibilities. \<pi> p b = x)
\<and> (\<forall> q \<in> possibilities. x \<le> \<pi> q b)"
lemma (in classical_logic) possibility_payoff_dual:
assumes "possibility p"
shows " \<pi> p \<lparr> buys = buys', sells = sells' \<rparr>
= - settle p (sells'\<^sup>\<sim> @ buys')
+ total_amount buys' + length sells' - total_amount sells'"
proof (induct sells')
case Nil
then show ?case
unfolding payoff_alt_def2
negate_bets_def
total_amount_def
settle_def
by simp
next
case (Cons sell' sells')
have "p (\<sim> (bet sell')) = (\<not> (p (bet sell')))"
using assms negation_def by auto
moreover have
"total_amount ((sell' # sells') @ buys')
= amount sell' + total_amount sells' + total_amount buys'"
unfolding total_amount_def
by (induct buys', induct sells', auto)
ultimately show ?case
using Cons
unfolding payoff_alt_def2 negate_bets_def settle_def settle_bet_def
by simp
qed
lemma settle_alt_def:
"settle q bets = length [\<phi> \<leftarrow> [ bet b . b \<leftarrow> bets ] . q \<phi>]"
unfolding settle_def settle_bet_def
by (induct bets, simp+)
section \<open> Dutch Book Theorems \label{sec:dutch-book-theorem} \<close>
subsection \<open> MaxSAT Dutch Book \label{subsec:dutch-book-maxsat-reduction} \<close>
theorem (in consistent_classical_logic) dutch_book_maxsat:
" (k \<le> \<pi>\<^sub>m\<^sub>i\<^sub>n \<lparr> buys = buys', sells = sells' \<rparr>)
= ( MaxSAT [bet b . b \<leftarrow> sells'\<^sup>\<sim> @ buys'] + (k :: real)
\<le> total_amount buys' + length sells' - total_amount sells')"
(is "(k \<le> \<pi>\<^sub>m\<^sub>i\<^sub>n ?bets) = (MaxSAT ?props + k \<le> total_amount _ + _ - _)")
proof
assume "k \<le> \<pi>\<^sub>m\<^sub>i\<^sub>n ?bets"
let ?P = "\<lambda> x . (\<exists> p \<in> possibilities. \<pi> p ?bets = x)
\<and> (\<forall> q \<in> possibilities. x \<le> \<pi> q ?bets)"
obtain p where
"possibility p" and
"\<forall> q \<in> possibilities. \<pi> p ?bets \<le> \<pi> q ?bets"
using \<open>k \<le> \<pi>\<^sub>m\<^sub>i\<^sub>n ?bets\<close>
minimum_payoff_existence [of ?bets]
by (metis possibilities_def mem_Collect_eq)
hence "?P (\<pi> p ?bets)"
using possibilities_def by blast
hence "\<pi>\<^sub>m\<^sub>i\<^sub>n ?bets = \<pi> p ?bets"
unfolding minimum_payoff_def
using minimum_payoff_existence [of ?bets]
the1_equality [where P = ?P and a = "\<pi> p ?bets"]
by blast
let ?\<Phi> = "[\<phi> \<leftarrow> ?props. p \<phi>]"
have "mset ?\<Phi> \<subseteq># mset ?props"
by(induct ?props,
auto,
simp add: subset_mset.add_mono)
moreover
have "\<not> (?\<Phi> :\<turnstile> \<bottom>)"
proof -
have "set ?\<Phi> \<subseteq> {x. p x}"
by auto
hence "\<not> (set ?\<Phi> \<tturnstile> \<bottom>)"
by (meson \<open>possibility p\<close>
possibilities_are_MCS [of p]
formula_consistent_def
formula_maximally_consistent_set_def_def
maximally_consistent_set_def
list_deduction_monotonic
set_deduction_def)
thus ?thesis
using set_deduction_def by blast
qed
moreover
{
fix \<Psi>
assume "mset \<Psi> \<subseteq># mset ?props" and "\<not> \<Psi> :\<turnstile> \<bottom>"
from this obtain \<Omega>\<^sub>\<Psi> where "MCS \<Omega>\<^sub>\<Psi>" and "set \<Psi> \<subseteq> \<Omega>\<^sub>\<Psi>"
by (meson formula_consistent_def
formula_maximal_consistency
formula_maximally_consistent_extension
list_deduction_monotonic
set_deduction_def)
let ?q = "\<lambda>\<phi> . \<phi> \<in> \<Omega>\<^sub>\<Psi>"
have "possibility ?q"
using \<open>MCS \<Omega>\<^sub>\<Psi>\<close> MCSs_are_possibilities by blast
hence "\<pi> p ?bets \<le> \<pi> ?q ?bets"
using \<open>\<forall>q\<in>possibilities. \<pi> p ?bets \<le> \<pi> q ?bets\<close>
possibilities_def
by blast
let ?c = "total_amount buys' + length sells' - total_amount sells'"
have "- settle p (sells'\<^sup>\<sim> @ buys') + ?c \<le> - settle ?q (sells'\<^sup>\<sim> @ buys') + ?c"
using \<open>\<pi> p ?bets \<le> \<pi> ?q ?bets\<close>
\<open>possibility p\<close>
possibility_payoff_dual [of p buys' sells']
\<open>possibility ?q\<close>
possibility_payoff_dual [of ?q buys' sells']
by linarith
hence "settle ?q (sells'\<^sup>\<sim> @ buys') \<le> settle p (sells'\<^sup>\<sim> @ buys')"
by linarith
let ?\<Psi>' = "[\<phi> \<leftarrow> ?props. ?q \<phi>]"
have "length ?\<Psi>' \<le> length ?\<Phi>"
using \<open>settle ?q (sells'\<^sup>\<sim> @ buys') \<le> settle p (sells'\<^sup>\<sim> @ buys')\<close>
unfolding settle_alt_def
by simp
moreover
have "length \<Psi> \<le> length ?\<Psi>'"
proof -
have "mset [\<psi> \<leftarrow> \<Psi>. ?q \<psi>] \<subseteq># mset ?\<Psi>'"
proof -
{
fix props :: "'a list"
have "\<forall> \<Psi>. \<forall> \<Omega>. mset \<Psi> \<subseteq># mset props \<longrightarrow>
mset [\<psi> \<leftarrow> \<Psi>. \<psi> \<in> \<Omega>] \<subseteq># mset [\<phi> \<leftarrow> props. \<phi> \<in> \<Omega>]"
by (simp add: multiset_filter_mono)
}
thus ?thesis
using \<open>mset \<Psi> \<subseteq># mset ?props\<close> by blast
qed
hence "length [\<psi> \<leftarrow> \<Psi>. ?q \<psi>] \<le> length ?\<Psi>'"
by (metis (no_types, lifting) length_sub_mset mset_eq_length nat_less_le not_le)
moreover have "length \<Psi> = length [\<psi> \<leftarrow> \<Psi>. ?q \<psi>]"
using \<open>set \<Psi> \<subseteq> \<Omega>\<^sub>\<Psi>\<close>
by (induct \<Psi>, simp+)
ultimately show ?thesis by linarith
qed
ultimately have "length \<Psi> \<le> length ?\<Phi>" by linarith
}
ultimately have "?\<Phi> \<in> \<C> ?props \<bottom>"
unfolding unproving_core_def
by blast
hence "MaxSAT ?props = length ?\<Phi>"
using core_size_intro by presburger
hence "MaxSAT ?props = settle p (sells'\<^sup>\<sim> @ buys')"
unfolding settle_alt_def
by simp
thus "MaxSAT ?props + k \<le> total_amount buys' + length sells' - total_amount sells'"
using possibility_payoff_dual [of p buys' sells']
\<open>k \<le> \<pi>\<^sub>m\<^sub>i\<^sub>n ?bets\<close>
\<open>\<pi>\<^sub>m\<^sub>i\<^sub>n ?bets = \<pi> p ?bets\<close>
\<open>possibility p\<close>
by linarith
next
let ?c = "total_amount buys' + length sells' - total_amount sells'"
assume "MaxSAT ?props + k \<le> ?c"
from this obtain \<Phi> where "\<Phi> \<in> \<C> ?props \<bottom>" and "length \<Phi> + k \<le> ?c"
using consistency core_size_intro unproving_core_existence by fastforce
hence "\<not> \<Phi> :\<turnstile> \<bottom>"
using unproving_core_def by blast
from this obtain \<Omega>\<^sub>\<Phi> where "MCS \<Omega>\<^sub>\<Phi>" and "set \<Phi> \<subseteq> \<Omega>\<^sub>\<Phi>"
by (meson formula_consistent_def
formula_maximal_consistency
formula_maximally_consistent_extension
list_deduction_monotonic
set_deduction_def)
let ?p = "\<lambda>\<phi> . \<phi> \<in> \<Omega>\<^sub>\<Phi>"
have "possibility ?p"
using \<open>MCS \<Omega>\<^sub>\<Phi>\<close> MCSs_are_possibilities by blast
have "mset \<Phi> \<subseteq># mset ?props"
using \<open>\<Phi> \<in> \<C> ?props \<bottom>\<close> unproving_core_def by blast
have "mset \<Phi> \<subseteq># mset [ b \<leftarrow> ?props. ?p b]"
by (metis \<open>mset \<Phi> \<subseteq># mset ?props\<close>
\<open>set \<Phi> \<subseteq> \<Omega>\<^sub>\<Phi>\<close>
filter_True
mset_filter
multiset_filter_mono
subset_code(1))
have "mset \<Phi> = mset [ b \<leftarrow> ?props. ?p b]"
proof (rule ccontr)
assume "mset \<Phi> \<noteq> mset [ b \<leftarrow> ?props. ?p b]"
hence "length \<Phi> < length [ b \<leftarrow> ?props. ?p b]"
using \<open>mset \<Phi> \<subseteq># mset [ b \<leftarrow> ?props. ?p b]\<close> length_sub_mset not_less by blast
moreover
have "\<not> [ b \<leftarrow> ?props. ?p b] :\<turnstile> \<bottom>"
by (metis IntE
\<open>MCS \<Omega>\<^sub>\<Phi>\<close>
inter_set_filter
formula_consistent_def
formula_maximally_consistent_set_def_def
maximally_consistent_set_def
set_deduction_def
subsetI)
hence "length [ b \<leftarrow> ?props. ?p b] \<le> length \<Phi>"
by (metis (mono_tags, lifting)
\<open>\<Phi> \<in> \<C> ?props \<bottom>\<close>
unproving_core_def [of ?props \<bottom>]
mem_Collect_eq
mset_filter
multiset_filter_subset)
ultimately show "False"
using not_le by blast
qed
hence "length \<Phi> = settle ?p (sells'\<^sup>\<sim> @ buys')"
unfolding settle_alt_def
using mset_eq_length by fastforce
hence "k \<le> settle ?p (sells'\<^sup>\<sim> @ buys')
+ total_amount buys' + length sells' - total_amount sells'"
using \<open>length \<Phi> + k \<le> ?c\<close> by linarith
hence "k \<le> \<pi> ?p ?bets"
using \<open>possibility ?p\<close>
possibility_payoff_dual [of ?p buys' sells']
\<open>length \<Phi> + k \<le> ?c\<close>
\<open>length \<Phi> = settle ?p (sells'\<^sup>\<sim> @ buys')\<close>
by linarith
have "\<forall> q \<in> possibilities. \<pi> ?p ?bets \<le> \<pi> q ?bets"
proof
fix q
assume "q \<in> possibilities"
hence "\<not> [ b \<leftarrow> ?props. q b] :\<turnstile> \<bottom>"
unfolding possibilities_def
by (metis filter_set
possibilities_logical_closure
possibility_def
set_deduction_def
mem_Collect_eq
member_filter
subsetI)
hence "length [ b \<leftarrow> ?props. q b] \<le> length \<Phi>"
by (metis (mono_tags, lifting)
\<open>\<Phi> \<in> \<C> ?props \<bottom>\<close>
unproving_core_def
mem_Collect_eq
mset_filter
multiset_filter_subset)
hence
" - settle ?p (sells'\<^sup>\<sim> @ buys') + total_amount buys' + length sells' - total_amount sells'
\<le> - settle q (sells'\<^sup>\<sim> @ buys') + total_amount buys' + length sells' - total_amount sells'"
using \<open>length \<Phi> = settle ?p (sells'\<^sup>\<sim> @ buys')\<close>
settle_alt_def [of q "sells'\<^sup>\<sim> @ buys'"]
by linarith
thus "\<pi> ?p ?bets \<le> \<pi> q ?bets"
using possibility_payoff_dual [of ?p buys' sells']
possibility_payoff_dual [of q buys' sells']
\<open>possibility ?p\<close>
\<open>q \<in> possibilities\<close>
unfolding possibilities_def
by (metis mem_Collect_eq)
qed
have "\<pi>\<^sub>m\<^sub>i\<^sub>n ?bets = \<pi> ?p ?bets"
unfolding minimum_payoff_def
proof
show "(\<exists>p\<in>possibilities. \<pi> p ?bets = \<pi> ?p ?bets) \<and> (\<forall>q\<in>possibilities. \<pi> ?p ?bets \<le> \<pi> q ?bets)"
using \<open>\<forall> q \<in> possibilities. \<pi> ?p ?bets \<le> \<pi> q ?bets\<close>
\<open>possibility ?p\<close>
unfolding possibilities_def
by blast
next
fix n
assume \<star>: "(\<exists>p\<in>possibilities. \<pi> p ?bets = n) \<and> (\<forall>q\<in>possibilities. n \<le> \<pi> q ?bets)"
from this obtain p where "\<pi> p ?bets = n" and "possibility p"
using possibilities_def by blast
hence "\<pi> p ?bets \<le> \<pi> ?p ?bets"
using \<star> \<open>possibility ?p\<close>
unfolding possibilities_def
by blast
moreover have "\<pi> ?p ?bets \<le> \<pi> p ?bets"
using \<open>\<forall> q \<in> possibilities. \<pi> ?p ?bets \<le> \<pi> q ?bets\<close>
\<open>possibility p\<close>
unfolding possibilities_def
by blast
ultimately show "n = \<pi> ?p ?bets" using \<open>\<pi> p ?bets = n\<close> by linarith
qed
thus "k \<le> \<pi>\<^sub>m\<^sub>i\<^sub>n ?bets"
using \<open>k \<le> \<pi> ?p ?bets\<close>
by auto
qed
subsection \<open> Probability Dutch Book \label{subsec:probability-dutch-book} \<close>
lemma (in consistent_classical_logic) nonstrict_dutch_book:
" (k \<le> \<pi>\<^sub>m\<^sub>i\<^sub>n \<lparr> buys = buys', sells = sells' \<rparr>)
= (\<forall> Pr \<in> probabilities.
(\<Sum>b\<leftarrow>buys'. Pr (bet b)) + total_amount sells' + k
\<le> (\<Sum>s\<leftarrow>sells'. Pr (bet s)) + total_amount buys')"
(is "?lhs = _")
proof -
let ?tot_ss = "total_amount sells'" and ?tot_bs = "total_amount buys'"
have "[bet b . b \<leftarrow> sells'\<^sup>\<sim> @ buys'] = \<^bold>\<sim> [bet s. s \<leftarrow> sells'] @ [bet b. b \<leftarrow> buys']"
(is "_ = \<^bold>\<sim> ?sell_\<phi>s @ ?buy_\<phi>s")
unfolding negate_bets_def
by (induct sells', simp+)
hence "?lhs = (MaxSAT (\<^bold>\<sim> ?sell_\<phi>s @ ?buy_\<phi>s) + k \<le> ?tot_bs + length sells' - ?tot_ss)"
using dutch_book_maxsat [of k buys' sells'] by auto
also have "\<dots> = (MaxSAT (\<^bold>\<sim> ?sell_\<phi>s @ ?buy_\<phi>s) + (?tot_ss - ?tot_bs + k) \<le> length sells')"
by linarith
also have "\<dots> = (MaxSAT (\<^bold>\<sim> ?sell_\<phi>s @ ?buy_\<phi>s) + (?tot_ss - ?tot_bs + k) \<le> length ?sell_\<phi>s)"
by simp
finally have I: "?lhs = (\<forall> Pr \<in> dirac_measures.
(\<Sum>\<phi>\<leftarrow>?buy_\<phi>s. Pr \<phi>) + (?tot_ss - ?tot_bs + k) \<le> (\<Sum>\<gamma>\<leftarrow>?sell_\<phi>s. Pr \<gamma>))"
using binary_inequality_equiv [of ?buy_\<phi>s "?tot_ss - ?tot_bs + k" ?sell_\<phi>s]
by blast
moreover
{
fix Pr :: "'a \<Rightarrow> real"
have "(\<Sum>\<phi>\<leftarrow>?buy_\<phi>s. Pr \<phi>) = (\<Sum>b\<leftarrow>buys'. Pr (bet b))"
"(\<Sum>\<gamma>\<leftarrow>?sell_\<phi>s. Pr \<gamma>) = (\<Sum>s\<leftarrow>sells'. Pr (bet s))"
by (simp add: comp_def)+
hence " ((\<Sum>\<phi>\<leftarrow>?buy_\<phi>s. Pr \<phi>) + (?tot_ss - ?tot_bs + k) \<le> (\<Sum>\<gamma>\<leftarrow>?sell_\<phi>s. Pr \<gamma>))
= ((\<Sum>b\<leftarrow>buys'. Pr (bet b)) + ?tot_ss + k \<le> (\<Sum>s\<leftarrow>sells'. Pr (bet s)) + ?tot_bs)"
by linarith
}
ultimately show ?thesis
by (meson dirac_measures_subset dirac_ceiling dirac_collapse subset_eq)
qed
lemma (in consistent_classical_logic) strict_dutch_book:
" (k < \<pi>\<^sub>m\<^sub>i\<^sub>n \<lparr> buys = buys', sells = sells' \<rparr>)
= (\<forall> Pr \<in> probabilities.
(\<Sum>b\<leftarrow>buys'. Pr (bet b)) + total_amount sells' + k
< (\<Sum>s\<leftarrow>sells'. Pr (bet s)) + total_amount buys')"
(is "?lhs = ?rhs")
proof
assume ?lhs
from this obtain \<epsilon> where "0 < \<epsilon>" "k + \<epsilon> \<le> \<pi>\<^sub>m\<^sub>i\<^sub>n \<lparr>buys = buys', sells = sells'\<rparr>"
using less_diff_eq by fastforce
hence "\<forall>Pr \<in> probabilities.
(\<Sum>b\<leftarrow>buys'. Pr (bet b)) + total_amount sells' + (k + \<epsilon>)
\<le> (\<Sum>s\<leftarrow>sells'. Pr (bet s)) + total_amount buys'"
using nonstrict_dutch_book [of "k + \<epsilon>" buys' sells'] by auto
thus ?rhs
using \<open>0 < \<epsilon>\<close> by auto
next
have "[bet b . b \<leftarrow> sells'\<^sup>\<sim> @ buys'] = \<^bold>\<sim> [bet s. s \<leftarrow> sells'] @ [bet b. b \<leftarrow> buys']"
(is "_ = \<^bold>\<sim> ?sell_\<phi>s @ ?buy_\<phi>s")
unfolding negate_bets_def
by (induct sells', simp+)
{
fix Pr :: "'a \<Rightarrow> real"
have "(\<Sum>b\<leftarrow>buys'. Pr (bet b)) = (\<Sum>\<phi>\<leftarrow>?buy_\<phi>s. Pr \<phi>)"
"(\<Sum>b\<leftarrow>sells'. Pr (bet b)) = (\<Sum>\<phi>\<leftarrow>?sell_\<phi>s. Pr \<phi>)"
by (induct buys', auto, induct sells', auto)
}
note \<star> = this
let ?tot_ss = "total_amount sells'" and ?tot_bs = "total_amount buys'"
let ?c = "?tot_ss + k - ?tot_bs"
assume ?rhs
have "\<forall> Pr \<in> probabilities. (\<Sum>b\<leftarrow>buys'. Pr (bet b)) + ?c < (\<Sum>s\<leftarrow>sells'. Pr (bet s))"
using \<open>?rhs\<close> by fastforce
hence "\<forall> Pr \<in> probabilities. (\<Sum>\<phi>\<leftarrow>?buy_\<phi>s. Pr \<phi>) + ?c < (\<Sum>\<phi>\<leftarrow>?sell_\<phi>s. Pr \<phi>)"
using \<star> by auto
hence "\<forall> Pr \<in> dirac_measures. (\<Sum>\<phi>\<leftarrow>?buy_\<phi>s. Pr \<phi>) + (\<lfloor>?c\<rfloor> + 1) \<le> (\<Sum>\<phi>\<leftarrow>?sell_\<phi>s. Pr \<phi>)"
using strict_dirac_collapse [of ?buy_\<phi>s ?c ?sell_\<phi>s]
by auto
hence "MaxSAT (\<^bold>\<sim> ?sell_\<phi>s @ ?buy_\<phi>s) + (\<lfloor>?c\<rfloor> + 1) \<le> length ?sell_\<phi>s"
by (metis floor_add_int floor_mono floor_of_nat binary_inequality_equiv)
hence "MaxSAT (\<^bold>\<sim> ?sell_\<phi>s @ ?buy_\<phi>s) + ?c < length ?sell_\<phi>s"
by linarith
from this obtain \<epsilon> :: real where
"0 < \<epsilon>"
"MaxSAT (\<^bold>\<sim> ?sell_\<phi>s @ ?buy_\<phi>s) + (k + \<epsilon>) \<le> ?tot_bs + length sells' - ?tot_ss"
using less_diff_eq by fastforce
hence "k + \<epsilon> \<le> \<pi>\<^sub>m\<^sub>i\<^sub>n \<lparr>buys = buys', sells = sells'\<rparr>"
using \<open>[bet b . b \<leftarrow> sells'\<^sup>\<sim> @ buys'] = \<^bold>\<sim> ?sell_\<phi>s @ ?buy_\<phi>s\<close>
dutch_book_maxsat [of "k + \<epsilon>" buys' sells']
by simp
thus ?lhs
using \<open>0 < \<epsilon>\<close> by linarith
qed
theorem (in consistent_classical_logic) dutch_book:
" (0 < \<pi>\<^sub>m\<^sub>i\<^sub>n \<lparr> buys = buys', sells = sells' \<rparr>)
= (\<forall> Pr \<in> probabilities.
(\<Sum>b\<leftarrow>buys'. Pr (bet b)) + total_amount sells'
< (\<Sum>s\<leftarrow>sells'. Pr (bet s)) + total_amount buys')"
by (simp add: strict_dutch_book)
end
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.