text
stringlengths 0
3.34M
|
---|
# http://juliastats.github.io/StatsBase.jl/stable/weights.html
mutable struct Packed_AliasingScalarSampler
samples::Vector{Float64}
weights::Vector{Float64}
end
## avert your eyes, C++ below
# class MvNormal : public Distribution {
# std::vector<double> mean_;
# std::vector<std::vector<double>> cov_;
#
# public:
# MvNormal(const std::vector<double> &mean,
# const std::vector<std::vector<double>> &cov)
# : mean_(mean), cov_(cov) {}
# json ToJson(void) const {
# json j;
# j["mean"] = mean_;
# j["cov"] = cov_;
# return (j);
# }
# };
|
= = NBA career statistics = =
|
(*
Copyright (C) 2017 M.A.L. Marques
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*)
(* type: work_mgga_c *)
par_n := 5:
gamma_x := 0.004:
par_x := [
[ 1.000, 0, 0],
[ 1.308, 0, 1],
[ 1.901, 0, 2],
[ 0.416, 1, 0],
[ 3.070, 1, 1]
]:
gamma_ss := 0.2:
par_ss := [
[ 1.000, 0, 0],
[ -1.855, 0, 2],
[ -5.668, 1, 0],
[-20.497, 3, 2],
[-20.364, 4, 2]
]:
gamma_os := 0.006:
par_os := [
[ 1.000, 0, 0],
[ 1.573, 0, 1],
[ -6.298, 0, 3],
[ 2.535, 1, 0],
[ -6.427, 3, 2]
]:
$define lda_x_params
$include "lda_x.mpl"
$include "b97mv.mpl"
f := (rs, z, xt, xs0, xs1, ts0, ts1, us0, us1) ->
f_b97mv(f_lda_x, rs, z, xt, xs0, xs1, ts0, ts1):
|
import numpy as np
import math
def lcm(list_numbers):
'''
Computes the lcm of numbers in a list.
'''
lcm = list_numbers[0]
for idx_number in range(1, len(list_numbers)):
lcm = (lcm*list_numbers[idx_number])/math.gcd(lcm, list_numbers[idx_number])
lcm = int(lcm)
return lcm
def multimode(list_input):
'''
`statistics.multimode` does not exist in all python versions.
Therefore minimath.multimode is implemented.
'''
set_data = set(list_input)
dict_freqs = {val:0 for val in set_data}
for elem in list_input:
dict_freqs[elem] = dict_freqs[elem] + 1
mode = max((v, k) for k, v in dict_freqs.items())[1]
return mode
def multiminority(list_input):
'''
Returns the minority in a list. This function works if there are many minorities available in the list.
'''
set_data = set(list_input)
dict_freqs = {val:0 for val in set_data}
for elem in list_input:
dict_freqs[elem] = dict_freqs[elem] + 1
minority = min((v, k) for k, v in dict_freqs.items())[1]
return minority
|
{-# OPTIONS --cubical-compatible #-}
module Common.Char where
open import Agda.Builtin.Char public
open import Common.Bool
charEq : Char -> Char -> Bool
charEq = primCharEquality
|
lemma (in t1_space) limit_frequently_eq: assumes "F \<noteq> bot" and "frequently (\<lambda>x. f x = c) F" and "(f \<longlongrightarrow> d) F" shows "d = c"
|
-- Export only the experiments that are expected to compile (without
-- any holes)
{-# OPTIONS --cubical #-}
module Cubical.Experiments.Everything where
open import Cubical.Experiments.Brunerie public
open import Cubical.Experiments.Generic public
open import Cubical.Experiments.Problem
open import Cubical.Experiments.FunExtFromUA public
|
[STATEMENT]
lemma term_ok'_decr: "term_ok' \<Sigma> t \<Longrightarrow> term_ok' \<Sigma> (decr i t)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. term_ok' \<Sigma> t \<Longrightarrow> term_ok' \<Sigma> (decr i t)
[PROOF STEP]
by (induction i t rule: decr.induct) auto
|
/* multiset/multiset.c
* based on combination/combination.c by Szymon Jaroszewicz
* based on permutation/permutation.c by Brian Gough
*
* Copyright (C) 2001 Szymon Jaroszewicz
* Copyright (C) 2009 Rhys Ulerich
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_multiset.h>
size_t
gsl_multiset_n (const gsl_multiset * c)
{
return c->n ;
}
size_t
gsl_multiset_k (const gsl_multiset * c)
{
return c->k ;
}
size_t *
gsl_multiset_data (const gsl_multiset * c)
{
return c->data ;
}
int
gsl_multiset_valid (gsl_multiset * c)
{
const size_t n = c->n ;
const size_t k = c->k ;
size_t i, j ;
for (i = 0; i < k; i++)
{
const size_t ci = c->data[i];
if (ci >= n)
{
GSL_ERROR("multiset index outside range", GSL_FAILURE) ;
}
for (j = 0; j < i; j++)
{
if (c->data[j] > ci)
{
GSL_ERROR("multiset indices not in increasing order",
GSL_FAILURE) ;
}
}
}
return GSL_SUCCESS;
}
int
gsl_multiset_next (gsl_multiset * c)
{
/* Replaces c with the next multiset (in the standard lexicographical
* ordering). Returns GSL_FAILURE if there is no next multiset.
*/
const size_t n = c->n;
const size_t k = c->k;
size_t *data = c->data;
size_t i;
if(k == 0)
{
return GSL_FAILURE;
}
i = k - 1;
while(i > 0 && data[i] == n-1)
{
--i;
}
if (i == 0 && data[0] == n-1)
{
return GSL_FAILURE;
}
++data[i];
while(i < k-1)
{
data[i+1] = data[i];
++i;
}
return GSL_SUCCESS;
}
int
gsl_multiset_prev (gsl_multiset * c)
{
/* Replaces c with the previous multiset (in the standard
* lexicographical ordering). Returns GSL_FAILURE if there is no
* previous multiset.
*/
const size_t n = c->n;
const size_t k = c->k;
size_t *data = c->data;
size_t i;
if(k == 0)
{
return GSL_FAILURE;
}
i = k - 1;
while(i > 0 && data[i-1] == data[i])
{
--i;
}
if(i == 0 && data[i] == 0)
{
return GSL_FAILURE;
}
data[i]--;
if (data[i] < n-1)
{
while (i < k-1) {
data[++i] = n - 1;
}
}
return GSL_SUCCESS;
}
int
gsl_multiset_memcpy (gsl_multiset * dest, const gsl_multiset * src)
{
const size_t src_n = src->n;
const size_t src_k = src->k;
const size_t dest_n = dest->n;
const size_t dest_k = dest->k;
if (src_n != dest_n || src_k != dest_k)
{
GSL_ERROR ("multiset lengths are not equal", GSL_EBADLEN);
}
{
size_t j;
for (j = 0; j < src_k; j++)
{
dest->data[j] = src->data[j];
}
}
return GSL_SUCCESS;
}
|
r=0.78
https://sandbox.dams.library.ucdavis.edu/fcrepo/rest/collection/sherry-lehmann/catalogs/d7sg6b/media/images/d7sg6b-001/svc:tesseract/full/full/0.78/default.jpg Accept:application/hocr+xml
|
function MV = ffmInteractionsSparse(X,Xbox,Y,Ybox,V,Ibox,green,k,edg,tol)
%+========================================================================+
%| |
%| OPENFFM - LIBRARY FOR FAST AND FREE MEMORY CONVOLUTION |
%| openFfm is part of the GYPSILAB toolbox for Matlab |
%| |
%| COPYRIGHT : Matthieu Aussal (c) 2017-2019. |
%| PROPERTY : Centre de Mathematiques Appliquees, Ecole polytechnique, |
%| route de Saclay, 91128 Palaiseau, France. All rights reserved. |
%| LICENCE : This program is free software, distributed in the hope that|
%| it will be useful, but WITHOUT ANY WARRANTY. Natively, you can use, |
%| redistribute and/or modify it under the terms of the GNU General Public|
%| License, as published by the Free Software Foundation (version 3 or |
%| later, http://www.gnu.org/licenses). For private use, dual licencing |
%| is available, please contact us to activate a "pay for remove" option. |
%| CONTACT : [email protected] |
%| WEBSITE : www.cmap.polytechnique.fr/~aussal/gypsilab |
%| |
%| Please acknowledge the gypsilab toolbox in programs or publications in |
%| which you use it. |
%|________________________________________________________________________|
%| '&` | |
%| # | FILE : ffmInteractionsSparse.m |
%| # | VERSION : 0.61 |
%| _#_ | AUTHOR(S) : Matthieu Aussal |
%| ( # ) | CREATION : 14.03.2017 |
%| / 0 \ | LAST MODIF : 05.09.2019 |
%| ( === ) | SYNOPSIS : Sparse product for low-frequency compressible |
%| `---' | leaves |
%+========================================================================+
% Initialisation du produit Matrice-Vecteur
MV = zeros(size(X,1),1,class(V));
% Quadrature des interpolations lagrangiennes
[Xq,ii,jj,kk,xq] = ffmQuadrature(green,k,edg,tol);
% Unicite des vecteurs de translation
XY = Ybox.ctr(Ibox(:,2),:) - Xbox.ctr(Ibox(:,1),:);
[~,Il,It] = unique(floor(XY*1e6),'rows','stable');
Nt = length(Il);
% Fonctions de transfert
Tx = cell(Nt,1);
Ty = cell(Nt,1);
for i = 1:Nt
[Tx{i},Ty{i}] = ffmTransfert(Xq,XY(Il(i),:),green,k,edg,tol);
end
% Interpolations en Y
Vy = cell(size(Ybox.ind));
for i = unique(Ibox(:,2)')
% Boite centree en Y dans le cube unitaire d'interpolation
iy = Ybox.ind{i};
ny = length(iy);
Ym = (2/edg) .* (Y(iy,:) - ones(ny,1)*Ybox.ctr(i,:));
% Interpolation de Lagrange (Ym->Xq)
Vy{i} = ffmInterp(ii,jj,kk,xq,Ym,V(iy),-1);
end
% Translations
TVy = cell(size(Xbox.ind));
for i = 1:length(TVy)
TVy{i} = 0;
end
for i = 1:size(Ibox,1)
TVy{Ibox(i,1)} = TVy{Ibox(i,1)} + Tx{It(i)} * (Ty{It(i)} * Vy{Ibox(i,2)});
end
% Interpolations en X
for i = unique(Ibox(:,1)')
% Boite centree en X dans le cube unitaire d'interpolation
ix = Xbox.ind{i};
nx = length(ix);
Xm = (2/edg) .* (X(ix,:) - ones(nx,1)*Xbox.ctr(i,:));
% Interpolation de Lagrange (Xq->Xm)
MV(ix) = ffmInterp(ii,jj,kk,xq,Xm,TVy{i},+1);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Xq,ii,jj,kk,xq] = ffmQuadrature(green,k,edg,tol)
% Nuages de reference emetteurs X
x = (-0.5*edg:edg/(10-1):0.5*edg)';
[x,y,z] = ndgrid(x,x,x);
Xref = [x(:) y(:) z(:)];
Nref = size(Xref,1);
% Nuage de reference transmetteur avec translation minimale
r0 = [2*edg 0 0];
Yref = [Xref(:,1)+r0(1) , Xref(:,2:3)];
% Xref dans le cube unitaire d'interpolation
a = [-0.5 -0.5 -0.5]*edg;
b = [0.5 0.5 0.5]*edg;
Xuni = ones(Nref,1)*(2./(b-a)) .* (Xref-ones(Nref,1)*(b+a)./2);
% Solution de reference
V = ones(Nref,1) + 1i;
[I,J] = ndgrid(1:Nref,1:1:Nref);
ref = reshape(ffmGreenKernel(Xref(I,:),Yref(J,:),green,k),Nref,Nref) * V;
% Initialisation
sol = 1e6;
nq = 1;
% Boucle sur l'ordre de quadrature
while norm(ref-sol)/norm(ref) > tol
% Incrementation
nq = nq + 1;
% Indices de construction de l'interpolateur de Lagrange
[ii,jj,kk] = ndgrid(1:nq,1:nq,1:nq);
% Points de quadratures Tchebitchev (1D et 3D)
xq = cos( (2*(nq:-1:1)-1)*pi/(2*nq))';
Xq = [xq(ii(:)) xq(jj(:)) xq(kk(:))];
% Vecteur de la translation
[TA,TB] = ffmTransfert(Xq,r0,green,k,edg,tol);
% Interpolation de Lagrange (Ym->Yq)
Vy = ffmInterp(ii,jj,kk,xq,Xuni,V,-1);
% Transfert (Yq->Xq)
TVy = TA * (TB * Vy);
% Interpolation de Lagrange (Xq->Xm)
sol = ffmInterp(ii,jj,kk,xq,Xuni,TVy,+1);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [TA,TB] = ffmTransfert(Xq,xy,green,k,edg,tol)
% Dimensions
Nq = size(Xq,1);
% Interpolants en X
a = [0 0 0];
b = [1 1 1]*edg;
Txq = (ones(Nq,1)*(b-a)/2).*Xq + ones(Nq,1)*(b+a)/2;
% Interpolants en Y
a = xy + a;
b = xy + b;
Tyq = (ones(Nq,1)*(b-a)/2).*Xq + ones(Nq,1)*(b+a)/2;
% Noyaux de green avec compression aux interpolants
[TA,TB,flag] = hmxACA(Txq,Tyq,green,k,tol/10);
% Calcul direct si necessaire
if ~flag
[I,J] = ndgrid(1:Nq,1:1:Nq);
TA = reshape(ffmGreenKernel(Txq(I,:),Tyq(J,:),green,k),Nq,Nq);
TB = 1;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function MV = ffmInterp(ii,jj,kk,xq,X,V,iflag)
% Dimensions
Nx = size(X,1);
nq = length(xq);
% Interpolateur de Lagrange par dimension d'espace
Aq = cell(1,nq);
for l = 1:nq^2
if isempty(Aq{ii(l)})
Aq{ii(l)} = ones(Nx,3,class(V));
end
if ii(l) ~= jj(l)
Aq{ii(l)} = Aq{ii(l)} .* (X-xq(jj(l)))./(xq(ii(l))-xq(jj(l)));
end
end
% Interpolation (X->Xq)
if (iflag == -1)
MV = zeros(nq^3,1,class(V));
for l = 1:nq^3
MV(l) = (Aq{ii(l)}(:,1) .* Aq{jj(l)}(:,2) .* Aq{kk(l)}(:,3)).' * V;
end
% Interpolation (Xq->X)
elseif (iflag == +1)
MV = zeros(Nx,1,class(V));
for l = 1:nq^3
MV = MV + Aq{ii(l)}(:,1) .* Aq{jj(l)}(:,2) .* Aq{kk(l)}(:,3) .* V(l);
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
#!/usr/bin/Rscript
# Copyright © 2016 Martin Ueding <[email protected]>
# Licensed under the MIT license.
box_muller_alternative_2 = function() {
# Sample from the exponential distribution until a suitable `y2` has been
# found.
repeat {
y1 = rexp(1)
y2 = rexp(1)
if (y2 > (1 - y1)^2 / 2) {
break;
}
}
# Randomly determine the sign and return that value.
u = runif(1)
x = sign(2 * u - 1) * y1
return(x)
}
# Draw a bunch of samples
samples = replicate(10000, box_muller_alternative_2())
# Make a quantile-quantile plot which the actual against the theoretical
# quantiles. That should quickly tell whether the resulting numbers are sampled
# from a normal distribution.
qqnorm(samples)
lines(c(-4, 4), c(-4, 4))
grid()
|
Formal statement is: lemma offset_poly_single: "offset_poly [:a:] h = [:a:]" Informal statement is: The offset of a constant polynomial is itself.
|
using Test
using LinearAlgebra
using DiffEqProblemLibrary.ODEProblemLibrary: importodeproblems;
importodeproblems();
import DiffEqProblemLibrary.ODEProblemLibrary:
prob_ode_linear, prob_ode_2Dlinear, prob_ode_lotkavoltera, prob_ode_fitzhughnagumo
prob = prob_ode_lotkavoltera
prob = remake(prob, tspan=(0.0, 10.0))
prob = ProbNumDiffEq.remake_prob_with_jac(prob)
@testset "Condition numbers of A,Q" begin
h = 0.1 * rand()
σ = rand()
d, q = 2, 3
A!, Q! = ProbNumDiffEq.vanilla_ibm(d, q)
Ah = diagm(0 => ones(d * (q + 1)))
Qh = zeros(d * (q + 1), d * (q + 1))
A!(Ah, h)
Q!(Qh, h, σ^2)
A_p, Q_p = ProbNumDiffEq.ibm(d, q)
Ah_p = A_p
Qh_p = Q_p * σ^2
# First test that they're both equivalent
D = d * (q + 1)
P, PI = ProbNumDiffEq.init_preconditioner(d, q)
ProbNumDiffEq.make_preconditioner!(P, h, d, q)
ProbNumDiffEq.make_preconditioner_inv!(PI, h, d, q)
@test Qh_p ≈ P * Qh * P'
@test Ah_p ≈ P * Ah * PI
# Check that the preconditioning actually helps
# @info "Condition numbers" cond(Qh) cond(Matrix(Qh_p)) cond(Ah) cond(Ah_p)
@test cond(Qh) > cond(Matrix(Qh_p))
@test cond(Qh) > cond(Matrix(Qh_p))^2
end
|
import numpy as np
from astropy.io import fits
import os
from numpy.lib.recfunctions import stack_arrays, drop_fields
from time import sleep
fields_to_drop = ['px','py','pz','vx','vy','vz']
edges = np.load('edges.npy')
#MW
for i in np.arange(1000):
x = fits.getdata('../output/GDR3mock/%d/GDR3mock207.fits' %(i) )
x = drop_fields(x,fields_to_drop,usemask= False, asrecarray = True)
print(i,len(x))
x=np.sort(x,order='source_id')
indexes = np.searchsorted(x.source_id,edges)
for j, jtem in enumerate(indexes[:-1]):
np.save('../data/%d_%d.npy' %(i,j) ,x[jtem:indexes[j+1]])
os.remove('../output/GDR3mock/%d/GDR3mock207.fits' %(i) )
#MC
for i in np.arange(10):
x = fits.getdata('../output/GDR3mock_extra/MCs_%d/nbody.fits' %(i) )
x = drop_fields(x,fields_to_drop,usemask= False, asrecarray = True)
print(i,len(x))
x=np.sort(x,order='source_id')
indexes = np.searchsorted(x.source_id,edges)
for j, jtem in enumerate(indexes[:-1]):
np.save('../data/%d_%d.npy' %(i+1000,j) ,x[jtem:indexes[j+1]])
#CL
for i in np.arange(1):
x = fits.getdata('../output/GDR3mock_extra/Clusters_1/nbody.fits')
x = drop_fields(x,fields_to_drop,usemask= False, asrecarray = True)
print(i,len(x))
x=np.sort(x,order='source_id')
indexes = np.searchsorted(x.source_id,edges)
for j, jtem in enumerate(indexes[:-1]):
np.save('../data/%d_%d.npy' %(i+1010,j) ,x[jtem:indexes[j+1]])
count = 0
for i in np.arange(400):
array_stack = []
for j in np.arange(1011):
array_stack.append(np.load('../data/%d_%d.npy' %(j,i)))
x = stack_arrays(array_stack, usemask = False, asrecarray=True,autoconvert = True)
for j in np.arange(1011):
os.remove('../data/%d_%d.npy' %(j,i))
count+=len(x)
print(i,len(x))
x=np.sort(x,order = 'source_id', kind = 'mergesort')
fits.writeto('../data/%d.fits' %(i),x)
np.save('total_starcount.npy', count)
|
State Before: α : Sort u
β : α → Sort v
α' : Sort w
inst✝¹ : DecidableEq α
inst✝ : DecidableEq α'
f✝ g : (a : α) → β a
a✝ : α
b✝ : β a✝
f : (a : α) → β a
a : α
b : β a
p : (a : α) → β a → Prop
⊢ (∃ x, p x (update f a b x)) ↔ p a b ∨ ∃ x x_1, p x (f x) State After: α : Sort u
β : α → Sort v
α' : Sort w
inst✝¹ : DecidableEq α
inst✝ : DecidableEq α'
f✝ g : (a : α) → β a
a✝ : α
b✝ : β a✝
f : (a : α) → β a
a : α
b : β a
p : (a : α) → β a → Prop
⊢ ¬(¬p a b ∧ ∀ (x : α), x ≠ a → ¬p x (f x)) ↔ p a b ∨ ∃ x x_1, p x (f x) Tactic: rw [← not_forall_not, forall_update_iff f fun a b ↦ ¬p a b] State Before: α : Sort u
β : α → Sort v
α' : Sort w
inst✝¹ : DecidableEq α
inst✝ : DecidableEq α'
f✝ g : (a : α) → β a
a✝ : α
b✝ : β a✝
f : (a : α) → β a
a : α
b : β a
p : (a : α) → β a → Prop
⊢ ¬(¬p a b ∧ ∀ (x : α), x ≠ a → ¬p x (f x)) ↔ p a b ∨ ∃ x x_1, p x (f x) State After: no goals Tactic: simp [-not_and, not_and_or]
|
#include <metal.hpp>
#include "example.hpp"
#if !defined(METAL_WORKAROUND)
#include <array>
#include <chrono>
#include <complex>
#include <tuple>
#include <type_traits>
#include <utility>
/// [make_array]
template<typename... Xs,
typename R = std::array<std::common_type_t<Xs...>, sizeof...(Xs)>
>
constexpr R make_array(Xs&&... xs) {
return R{{std::forward<Xs>(xs)...}};
}
/// [make_array]
/// [tuples]
using namespace std::chrono;
using namespace std::literals::chrono_literals;
using namespace std::literals::complex_literals;
auto tup1 = std::make_tuple(42ns, 0x42, 42.f);
auto tup2 = std::make_tuple(42us, 042L, 42.L);
auto tup3 = std::make_tuple(42ms, 42LL, 42.i);
/// [tuples]
#if 0
/// [naive_array_of_tuples]
auto array_of_tuples = make_array(tup1, tup2, tup3);
/// [naive_array_of_tuples]
#endif
#include <boost/hana/config.hpp>
#if defined(BOOST_HANA_CONFIG_GCC) && \
BOOST_HANA_CONFIG_GCC < BOOST_HANA_CONFIG_VERSION(5, 4, 0)
# define SKIP
#endif
#if defined(BOOST_HANA_CONFIG_CLANG) && \
BOOST_HANA_CONFIG_CLANG < BOOST_HANA_CONFIG_VERSION(3, 5, 0)
# define SKIP
#endif
#if !defined(SKIP)
#include <boost/hana/ext/std/tuple.hpp>
#include <boost/hana/transform.hpp>
#include <boost/hana/type.hpp>
#include <boost/hana/unpack.hpp>
#include <boost/hana/zip.hpp>
namespace hana {
/// [hana_common_tuple_t]
template<typename... xs>
using hana_common_tuple_t = typename decltype(
boost::hana::unpack(
boost::hana::zip_with(
boost::hana::template_<std::common_type_t>,
boost::hana::zip_with(boost::hana::decltype_, std::declval<xs>())...
),
boost::hana::template_<std::tuple>
)
)::type;
/// [hana_common_tuple_t]
/// [hana_make_array_of_tuples]
template<typename... Xs,
typename R = std::array<std::common_type_t<Xs...>, sizeof...(Xs)>
>
constexpr R hana_make_array(Xs&&... xs) {
return R{{std::forward<Xs>(xs)...}};
}
template<typename Head, typename... Tail,
typename R = std::array<hana_common_tuple_t<std::decay_t<Head>, std::decay_t<Tail>...>, 1 + sizeof...(Tail)>
>
constexpr R hana_make_array(Head&& head, Tail&&... tail) {
return R{{std::forward<Head>(head), std::forward<Tail>(tail)...}};
}
/// [hana_make_array_of_tuples]
#if !defined(_LIBCPP_VERSION) || _LIBCPP_VERSION >= 5000
/// [hana_array_of_tuples]
auto array_of_tuples = hana_make_array(tup1, tup2, tup3);
IS_SAME(decltype(array_of_tuples), std::array<std::tuple<nanoseconds, long long, std::complex<double>>, 3>);
/// [hana_array_of_tuples]
#endif
#if 0
/// [hana_array_of_numbers]
IS_SAME(decltype(hana_make_array(42, 42L, 42LL)), std::array<long long, 3>);
/// [hana_array_of_numbers]
#endif
}
#endif
namespace
{
/// [common_tuple_t]
template<typename... xs>
using common_tuple_t = metal::apply<
std::common_type_t<metal::lambda<std::tuple>, metal::as_lambda<xs>...>,
metal::transform<metal::lambda<std::common_type_t>, metal::as_list<xs>...>
>;
/// [common_tuple_t]
/// [make_array_of_tuples]
template<typename... Xs,
typename R = std::array<std::common_type_t<Xs...>, sizeof...(Xs)>
>
constexpr R make_array(Xs&&... xs) {
return R{{std::forward<Xs>(xs)...}};
}
template<typename Head, typename... Tail,
typename R = std::array<common_tuple_t<std::decay_t<Head>, std::decay_t<Tail>...>, 1 + sizeof...(Tail)>
>
constexpr R make_array(Head&& head, Tail&&... tail) {
return R{{std::forward<Head>(head), std::forward<Tail>(tail)...}};
}
/// [make_array_of_tuples]
#if !defined(_LIBCPP_VERSION) || _LIBCPP_VERSION >= 5000
/// [array_of_tuples]
auto array_of_tuples = make_array(tup1, tup2, tup3);
IS_SAME(decltype(array_of_tuples), std::array<std::tuple<nanoseconds, long long, std::complex<double>>, 3>);
/// [array_of_tuples]
#endif
/// [array_of_numbers]
IS_SAME(decltype(make_array(42, 42L, 42LL)), std::array<long long, 3>);
/// [array_of_numbers]
}
#endif
|
(* Title: HOL/Auth/n_flash_lemma_on_inv__132.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_flash Protocol Case Study*}
theory n_flash_lemma_on_inv__132 imports n_flash_base
begin
section{*All lemmas on causal relation between inv__132 and some rule r*}
lemma n_NI_Local_Get_Put_HeadVsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put_Head N src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put_Head N src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P2 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_Get_PutVsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_Get_Put_DirtyVsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put_Dirty src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put_Dirty src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_1Vsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_1 N src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_1 N src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_2Vsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_2 N src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_2 N src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_3Vsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_3 N src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_3 N src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_4Vsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_4 N src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_4 N src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_5Vsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_5 N src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_5 N src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_6Vsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_6 N src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_6 N src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_7__part__0Vsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__0 N src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__0 N src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_7__part__1Vsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__1 N src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__1 N src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_7_NODE_Get__part__0Vsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_7_NODE_Get__part__1Vsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_8_HomeVsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home N src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home N src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_8_Home_NODE_GetVsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_8Vsinv__132:
assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8 N src pp)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8 N src pp" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_8_NODE_GetVsinv__132:
assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_9__part__0Vsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__0 N src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__0 N src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_9__part__1Vsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__1 N src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__1 N src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_10_HomeVsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_10_Home N src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_10_Home N src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_10Vsinv__132:
assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_10 N src pp)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_10 N src pp" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_GetX_PutX_11Vsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_11 N src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_11 N src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_ReplaceVsinv__132:
assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Replace src)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Replace src" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(src=p__Inv4)"
have "((formEval (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) s))\<or>((formEval (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) s))" by auto
moreover {
assume c1: "((formEval (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) s))"
have "?P1 s"
proof(cut_tac a1 a2 b1 c1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume c1: "((formEval (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) s))"
have "?P2 s"
proof(cut_tac a1 a2 b1 c1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately have "invHoldForRule s f r (invariants N)" by satx
}
moreover {
assume b1: "(src~=p__Inv4)"
have "?P2 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_PI_Local_GetX_PutX_HeadVld__part__0Vsinv__132:
assumes a1: "(r=n_PI_Local_GetX_PutX_HeadVld__part__0 N )" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "?P1 s"
proof(cut_tac a1 a2 , auto) qed
then show "invHoldForRule s f r (invariants N)" by auto
qed
lemma n_PI_Local_GetX_PutX_HeadVld__part__1Vsinv__132:
assumes a1: "(r=n_PI_Local_GetX_PutX_HeadVld__part__1 N )" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "?P1 s"
proof(cut_tac a1 a2 , auto) qed
then show "invHoldForRule s f r (invariants N)" by auto
qed
lemma n_NI_Local_PutXAcksDoneVsinv__132:
assumes a1: "(r=n_NI_Local_PutXAcksDone )" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "?P3 s"
apply (cut_tac a1 a2 , simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_PutX)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))))" in exI, auto) done
then show "invHoldForRule s f r (invariants N)" by auto
qed
lemma n_NI_WbVsinv__132:
assumes a1: "(r=n_NI_Wb )" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "?P3 s"
apply (cut_tac a1 a2 , simp, rule_tac x="(neg (andForm (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''WbMsg'') ''Cmd'')) (Const WB_Wb))))" in exI, auto) done
then show "invHoldForRule s f r (invariants N)" by auto
qed
lemma n_NI_ShWbVsinv__132:
assumes a1: "(r=n_NI_ShWb N )" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__132 p__Inv4" apply fastforce done
have "((formEval (andForm (eqn (Const (index p__Inv4)) (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''Proc''))) (eqn (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''HomeProc'')) (Const false))) s))\<or>((formEval (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true)) s))\<or>((formEval (andForm (neg (eqn (Const (index p__Inv4)) (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''Proc'')))) (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''HomeProc'')) (Const false))) (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true)))) s))" by auto
moreover {
assume c1: "((formEval (andForm (eqn (Const (index p__Inv4)) (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''Proc''))) (eqn (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''HomeProc'')) (Const false))) s))"
have "?P3 s"
apply (cut_tac a1 a2 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const false)) (eqn (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''Cmd'')) (Const SHWB_ShWb))))" in exI, auto) done
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume c1: "((formEval (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true)) s))"
have "?P3 s"
apply (cut_tac a1 a2 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const false))))" in exI, auto) done
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume c1: "((formEval (andForm (neg (eqn (Const (index p__Inv4)) (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''Proc'')))) (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true)))) s))"
have "?P1 s"
proof(cut_tac a1 a2 c1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''HomeProc'')) (Const false))) (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true)))) s))"
have "?P1 s"
proof(cut_tac a1 a2 c1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_NI_Local_Get_Get__part__1Vsinv__132:
assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Get__part__1 src" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Remote_GetX_PutX_HomeVsinv__132:
assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_GetX_PutX_Home dst" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_PI_Remote_GetVsinv__132:
assumes a1: "\<exists> src. src\<le>N\<and>r=n_PI_Remote_Get src" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_PI_Local_GetX_PutX__part__0Vsinv__132:
assumes a1: "r=n_PI_Local_GetX_PutX__part__0 " and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_StoreVsinv__132:
assumes a1: "\<exists> src data. src\<le>N\<and>data\<le>N\<and>r=n_Store src data" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Local_GetX_GetX__part__1Vsinv__132:
assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__1 src" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_InvAck_3Vsinv__132:
assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_3 N src" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_InvAck_1Vsinv__132:
assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_1 N src" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_PI_Local_GetX_GetX__part__1Vsinv__132:
assumes a1: "r=n_PI_Local_GetX_GetX__part__1 " and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_PI_Local_GetX_GetX__part__0Vsinv__132:
assumes a1: "r=n_PI_Local_GetX_GetX__part__0 " and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_PI_Remote_ReplaceVsinv__132:
assumes a1: "\<exists> src. src\<le>N\<and>r=n_PI_Remote_Replace src" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_Store_HomeVsinv__132:
assumes a1: "\<exists> data. data\<le>N\<and>r=n_Store_Home data" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_PI_Local_ReplaceVsinv__132:
assumes a1: "r=n_PI_Local_Replace " and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Local_GetX_Nak__part__1Vsinv__132:
assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__1 src" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Local_Get_Nak__part__1Vsinv__132:
assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__1 src" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Local_Get_Get__part__0Vsinv__132:
assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Get__part__0 src" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_InvAck_existsVsinv__132:
assumes a1: "\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_InvAck_exists src pp" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Local_GetX_Nak__part__2Vsinv__132:
assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__2 src" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_PI_Remote_PutXVsinv__132:
assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_PI_Remote_PutX dst" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Remote_Get_Put_HomeVsinv__132:
assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Get_Put_Home dst" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_InvVsinv__132:
assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Inv dst" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_PI_Local_PutXVsinv__132:
assumes a1: "r=n_PI_Local_PutX " and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Local_Get_Nak__part__2Vsinv__132:
assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__2 src" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Local_GetX_GetX__part__0Vsinv__132:
assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__0 src" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_PI_Local_Get_PutVsinv__132:
assumes a1: "r=n_PI_Local_Get_Put " and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Remote_GetX_Nak_HomeVsinv__132:
assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_GetX_Nak_Home dst" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Remote_GetX_NakVsinv__132:
assumes a1: "\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_Nak src dst" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_NakVsinv__132:
assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Nak dst" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_PI_Remote_GetXVsinv__132:
assumes a1: "\<exists> src. src\<le>N\<and>r=n_PI_Remote_GetX src" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_PI_Local_GetX_PutX__part__1Vsinv__132:
assumes a1: "r=n_PI_Local_GetX_PutX__part__1 " and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Remote_Get_Nak_HomeVsinv__132:
assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Get_Nak_Home dst" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Remote_PutXVsinv__132:
assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_PutX dst" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Remote_PutVsinv__132:
assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Put dst" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Local_GetX_Nak__part__0Vsinv__132:
assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__0 src" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_InvAck_exists_HomeVsinv__132:
assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_exists_Home src" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Replace_HomeVsinv__132:
assumes a1: "r=n_NI_Replace_Home " and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Remote_GetX_PutXVsinv__132:
assumes a1: "\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_PutX src dst" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Local_PutVsinv__132:
assumes a1: "r=n_NI_Local_Put " and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Remote_Get_NakVsinv__132:
assumes a1: "\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Nak src dst" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Nak_ClearVsinv__132:
assumes a1: "r=n_NI_Nak_Clear " and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Local_Get_Nak__part__0Vsinv__132:
assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__0 src" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_PI_Local_Get_GetVsinv__132:
assumes a1: "r=n_PI_Local_Get_Get " and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Remote_Get_PutVsinv__132:
assumes a1: "\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Put src dst" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_Nak_HomeVsinv__132:
assumes a1: "r=n_NI_Nak_Home " and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_InvAck_2Vsinv__132:
assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_2 N src" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_NI_FAckVsinv__132:
assumes a1: "r=n_NI_FAck " and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__132 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
end
|
\section{Design and Implementation}
In this section, we introduce the design and implementation details of HydraMini. The structure of the system is shown in Fig.~\ref{fig:framework_overview}. Based on the middle ware, users are able to add more kinds of sensors or create more workers to handle the data while the middle ware provides apis for users to take advantage of computing resource and control the car. It's easy for users to add or remove component to or from the system.
\begin{figure}[t]
\centering
\includegraphics[width=3.25in]{framework_overview}
\caption{HydraMini Framework Overview.}
\label{fig:framework_overview}
\end{figure}
\subsection{Hardware Design}
As shown in Fig.~\ref{fig:hardware}, HydraMini is equipped with a Xilinx PYNQ-Z2 board which acts as the main controller, PYNQ\cite{tul2019tulpynqz2} is an open-source project from Xilinx that makes it easy to design embedded systems with Xilinx Zynq Systems on Chips (SoCs). Users create high performance embedded applications with parallel hardware execution, high frame-rate video processing, hardware accelerated algorithms, real-time signal processing, high bandwidth I/O and low latency control. Software developers will take advantage of the capabilities of Zynq and programmable hardware without having to use ASIC-style design tools to design hardware. System architects will have an easy software interface and framework for rapid prototyping and development of their Zynq design. It's suitable to be used in our platform because of the convenience and high performance. The board collects the data from multiple sensors and feeds the data to several computing tasks in real-time. An I/O expansion board V7.1 receives the control message output from the computing tasks and then sends the control signals to the motor drivers to control the movement of HydraMini. The whole HydraMini platform is powered by two Batteries. And to provide steady voltage for PK370PH-4743 motor and DF15MG electric servo motor, a QuicRun WP 1060 Brushed electronic speed controller is used. The basic sensor is one VIMICRO camera, also we provide a study case using LeiShen LS01D LIDAR. It's easy for you to add more sensors to the platform.
\textbf{Programmable Logic (PL)} The programmable logic in PYNQ-Z2 is equivalent to Artix-7 FPGA\cite{2019artix}. The components below are embedded in it:
\begin{itemize}
\item{13,300 logic slices, each with four 6-input LUTs and 8 flip-flops }
\item{630 KB of fast block RAM }
\item{4 clock management tiles, each with a phase locked loop (PLL) and mixed-mode clock manager (MMCM) }
\item{220 DSP slices }
\item{On-chip analog-to-digital converter (XADC) }
\end{itemize}
\textbf{Processing System (PS).} The Cortex-A9\cite{2019arma9} processor is embedded in PYNQ-Z2, it's a performance and power optimized multi-core processor. It features a dual-issue, partially out-of-order pipeline and a flexible system architecture with configurable caches and system coherency using ACP port. The Cortex-A9 processor achieves a better than 50\% performance over the Cortex-A8 processor in a single-core configuration. It has an L1 cache subsystem that provides full virtual memory capabilities. The Cortex-A9 processor implements the ARMv7-A architecture and runs 32-bit ARM instructions, 16-bit and 32-bit Thumb instructions, and 8-bit Java bytecodes in Jazelle state.
\begin{figure}[t]
\centering
\includegraphics[width=3.5in]{hardware}
\caption{HydraMini Hardware Design.}
\label{fig:hardware}
\end{figure}
\subsection{Software Design}
\textbf{Framework Overview.} The operating system on PYNQ-Z2 is based on Ubuntu 18.04, so libraries are easily installed. The system on PYNQ-Z2 also provides many jupyter notebook documents about how to fully utilize the hardware resources in PYNQ-Z2. To make the control process more efficient and easier to extend, we implement a producer-consumer model\cite{producerconsumer} which is a classic design pattern in multi-process synchronization environment. The whole control system depends on three main components: mechanical controller, AI model inference and computer vision analysis.
\textbf{Producer-Consumer model.} Many indoor AD driving platforms like HydraOne\cite{wang2019hydraone} and F1/10\cite{o2019f1} use ROS\cite{quigley2009ros} to manage the hardware and software resources nowadays because ROS provides the car with an easy way to communicate with the server and many existing applications. However, to make a balance between the platform's cost and performance, we focuses mainly on core functions in AD and the communication between car and server is not so important. Using ROS will bring unnecessary overhead to CPU. So a more streamlined and efficient method is used as the base of the control system. Refer to Fig.~\ref{fig:producer_consumer} for an overview of this model.
\begin{figure}[t]
\centering
\includegraphics[width=3.25in]{producer_consumer}
\caption{Producer-Consumer Model.}
\label{fig:producer_consumer}
\end{figure}
The sensors like camera will play the role of producer while the decision makers like AI model and computer vision methods will be consumers. Each kind of data will be stored in a queue in memory. Different producer processes add the data they get to the specified queue and will be handled by consumers who cares about this kind of data. It's easy to add more producers or consumers and new kind of data. If one process want to handle or provide different kind of data, just read or write the related queue. The synchronism of the system is maintained by locks, each queue will have a lock.
The consumers who usually act as controller have a shared clock. They will check if their commands to send is outdated according to the clock, this clock ensures that the car won't receive outdated commands. Also, there exists a token which indicates who has the current property in control power. Users are able to define their own strategy for the transformation of property.
\textbf{Mechanical Controller.} The HydraMini platform has one motor for providing power and one servo motor for direction control. This design has been widely used in real cars. We provide basic control apis for users. The rotate speed of the motor and the angle of deflection of servo motor are set directly. Also higher level methods like accelerating are provided too.
Besides driving on its own, the car is controlled by using the keyboard. We invoke OpenCV\cite{opencv} library to read the keyboard signals and then call the mechanical api. Users are able to define their own button layout easily. This ability is mostly used to generate training data.
\textbf{AI Inference.} AI technology is an important part in AD, it handles many tasks like objects identification, lane keeping and so on. In our platform AI inference process is packed as a consumer thread, it reads data from produced data queue and use it as the input of AI network. Then the model produces control commands directly or just provide information for controller thread to make decisions.
And with the power of DPU\cite{dnndk} which is one accelerator in FPGA, the process of AI reference will be accelerated. The AI inference thread is copied and they run concurrently in DPU, which means higher inference performance.
To make good use of DPU and to make the optimization process easy, we provide scripts to do a complete set of optimized tool chains provided by DNNDK, including compression, compilation and runtime. Refer to Fig.~\ref{fig:dnndk} to see the framework of DNNDK. First the Deep Compression Tool DECENT\cite{dnndk}, employs coarse-grained pruning, trained quantization and weight sharing to make the inference process in edge meet the low latency and high throughput requirement with very small accuracy degradation. Second the DNNC (Deep Neural Network Compiler)\cite{dnndk} which is the dedicated proprietary compiler designed for the DPU will map the neural network algorithm to the DPU instructions to achieve maxim utilization of DPU resources by balancing computing workload and memory access. Third the users use the Cube of Neutral Networks (N2Cube)\cite{dnndk} the DPU runtime engine to load DNNDK applications and manage resource allocation and DPU scheduling. Its core components include DPU driver, DPU loader, tracer, and programming APIs for application development.
After using DPU, the performance of end-to-end model described in case study is up to $7,000$ FPS which is fast enough to satisfy the requirement of low-latency in AD. We also test YoloV3\cite{redmon2018yolov3} model in DPU and it achieves 3 fps when detecting 80 categories of things.
\begin{figure}[t]
\centering
\includegraphics[width=3.25in]{dnndk.pdf}
\caption{DNNDK Framework.}
\label{fig:dnndk}
\end{figure}
\textbf{Computer Vision Analysis.} OpenCV\cite{opencv} is a widely used library for computer vision analysis. Due to the native support for OpenCV in PYNQ-Z2, existing computer vision algorithms are easily invoked and their own algorithms can be implemented. We have a case below which shows how to use traditional computer vision methods to manage AD tasks. The control process of these methods is just the same as AI model's, the thread running computer vision algorithms will read data from producers and output commands or information. More threads can be created to increase throughput.
However, these computer vision algorithms may be very time consuming running in ARM Cortex-A9 in Xilinx PYNQ-Z2. To reduce computation complexity, we do several pre-process like cropping and down-sampling. Time consuming tasks such as Gaussian filter, Canny edge detection, Hough transform can be moved to FPGA using Xilinx xfopencv library\cite{xfopencv}, BP neural network can be implemented in FPGA using Xilinx Vivado HLS. However, when implementing accelerators in FPGA, users should take the board's resource into consideration and choose the heaviest computational task to implement while not beyond the resource limit. If there remains enough PL space for your algorithms, you put them in PL side, or just put them in PS side.
|
(* Author: Dmitriy Traytel *)
header "Partial Derivatives-like Normalization"
(*<*)
theory PNormalization
imports Pi_Derivatives
begin
(*>*)
fun pnPlus :: "'a::linorder rexp \<Rightarrow> 'a rexp \<Rightarrow> 'a rexp" where
"pnPlus Zero r = r"
| "pnPlus r Zero = r"
(*<*)
(*
| "pnPlus Full r = Full"
| "pnPlus r Full = Full"
*)
(*>*)
| "pnPlus (Plus r s) t = pnPlus r (pnPlus s t)"
| "pnPlus r (Plus s t) =
(if r = s then (Plus s t)
else if r \<le> s then Plus r (Plus s t)
else Plus s (pnPlus r t))"
| "pnPlus r s =
(if r = s then r
else if r \<le> s then Plus r s
else Plus s r)"
lemma (in alphabet) wf_pnPlus[simp]: "\<lbrakk>wf n r; wf n s\<rbrakk> \<Longrightarrow> wf n (pnPlus r s)"
by (induct r s rule: pnPlus.induct) auto
lemma (in project) lang_pnPlus[simp]: "\<lbrakk>wf n r; wf n s\<rbrakk> \<Longrightarrow> lang n (pnPlus r s) = lang n (Plus r s)"
by (induct r s rule: pnPlus.induct) (auto dest!: lang_subset_lists dest: project
subsetD[OF star_subset_lists, unfolded in_lists_conv_set, rotated -1]
subsetD[OF conc_subset_lists, unfolded in_lists_conv_set, rotated -1])
fun pnTimes :: "'a::linorder rexp \<Rightarrow> 'a rexp \<Rightarrow> 'a rexp" where
"pnTimes Zero r = Zero"
| "pnTimes One r = r"
| "pnTimes (Plus r s) t = pnPlus (pnTimes r t) (pnTimes s t)"
| "pnTimes r s = Times r s"
lemma (in alphabet) wf_pnTimes[simp]: "\<lbrakk>wf n r; wf n s\<rbrakk> \<Longrightarrow> wf n (pnTimes r s)"
by (induct r s rule: pnTimes.induct) auto
lemma (in project) lang_pnTimes[simp]: "\<lbrakk>wf n r; wf n s\<rbrakk> \<Longrightarrow> lang n (pnTimes r s) = lang n (Times r s)"
by (induct r s rule: pnTimes.induct) auto
fun pnInter :: "'a::linorder rexp \<Rightarrow> 'a rexp \<Rightarrow> 'a rexp" where
"pnInter Zero r = Zero"
| "pnInter r Zero = Zero"
| "pnInter Full r = r"
| "pnInter r Full = r"
| "pnInter (Plus r s) t = pnPlus (pnInter r t) (pnInter s t)"
| "pnInter r (Plus s t) = pnPlus (pnInter r s) (pnInter r t)"
| "pnInter (Inter r s) t = pnInter r (pnInter s t)"
| "pnInter r (Inter s t) =
(if r = s then Inter s t
else if r \<le> s then Inter r (Inter s t)
else Inter s (pnInter r t))"
| "pnInter r s =
(if r = s then s
else if r \<le> s then Inter r s
else Inter s r)"
lemma (in alphabet) wf_pnInter[simp]: "\<lbrakk>wf n r; wf n s\<rbrakk> \<Longrightarrow> wf n (pnInter r s)"
by (induct r s rule: pnInter.induct) auto
lemma (in project) lang_pnInter[simp]: "\<lbrakk>wf n r; wf n s\<rbrakk> \<Longrightarrow> lang n (pnInter r s) = lang n (Inter r s)"
by (induct r s rule: pnInter.induct) (auto, auto dest!: lang_subset_lists dest: project
subsetD[OF star_subset_lists, unfolded in_lists_conv_set, rotated -1]
subsetD[OF conc_subset_lists, unfolded in_lists_conv_set, rotated -1])
fun pnNot :: "'a::linorder rexp \<Rightarrow> 'a rexp" where
"pnNot (Plus r s) = pnInter (pnNot r) (pnNot s)"
| "pnNot (Inter r s) = pnPlus (pnNot r) (pnNot s)"
| "pnNot Full = Zero"
| "pnNot Zero = Full"
| "pnNot (Not r) = r"
| "pnNot r = Not r"
lemma (in alphabet) wf_pnNot[simp]: "wf n r \<Longrightarrow> wf n (pnNot r)"
by (induct r rule: pnNot.induct) auto
lemma (in project) lang_pnNot[simp]: "wf n r \<Longrightarrow> lang n (pnNot r) = lang n (Not r)"
by (induct r rule: pnNot.induct) (auto dest: lang_subset_lists)
fun pnPr :: "'a::linorder rexp \<Rightarrow> 'a rexp" where
"pnPr Zero = Zero"
| "pnPr One = One"
| "pnPr (Plus r s) = pnPlus (pnPr r) (pnPr s)"
| "pnPr r = Pr r"
lemma (in alphabet) wf_pnPr[simp]: "wf (Suc n) r \<Longrightarrow> wf n (pnPr r)"
by (induct r rule: pnPr.induct) auto
lemma (in project) lang_pnPr[simp]: "wf (Suc n) r \<Longrightarrow> lang n (pnPr r) = lang n (Pr r)"
by (induct r rule: pnPr.induct) auto
primrec pnorm :: "'a::linorder rexp \<Rightarrow> 'a rexp" where
"pnorm Zero = Zero"
| "pnorm Full = Full"
| "pnorm One = One"
| "pnorm (Atom a) = Atom a"
| "pnorm (Plus r s) = pnPlus (pnorm r) (pnorm s)"
| "pnorm (Times r s) = pnTimes (pnorm r) s"
| "pnorm (Star r) = Star r"
| "pnorm (Inter r s) = pnInter (pnorm r) (pnorm s)"
| "pnorm (Not r) = pnNot (pnorm r)"
| "pnorm (Pr r) = pnPr (pnorm r)"
lemma (in alphabet) wf_pnorm[simp]: "wf n r \<Longrightarrow> wf n (pnorm r)"
by (induct r arbitrary: n) auto
lemma (in project) lang_pnorm[simp]: "wf n r \<Longrightarrow> lang n (pnorm r) = lang n r"
by (induct r arbitrary: n) auto
(*<*)
end
(*>*)
|
-- Las partes simétricas son simétricas
-- ====================================
-- ----------------------------------------------------
-- Ej. 1. La parte simétrica de una relación R es la
-- relación S definida por
-- S x y := R x y ∧ R y x
--
-- Demostrar que la parte simétrica de cualquier
-- relación es simétrica.
-- ----------------------------------------------------
section
parameter A : Type
parameter R : A → A → Prop
def S (x y : A) := R x y ∧ R y x
-- 1ª demostración
example : symmetric S :=
begin
intros x y h,
split,
{ exact h.right, },
{ exact h.left, },
end
-- 2ª demostración
example : symmetric S :=
begin
intros x y h,
exact ⟨h.right, h.left⟩,
end
-- 3ª demostración
example : symmetric S :=
λ x y h, ⟨h.right, h.left⟩
-- 4ª demostración
example : symmetric S :=
assume x y,
assume h : S x y,
have h1 : R x y, from h.left,
have h2 : R y x, from h.right,
show S y x, from ⟨h2, h1⟩
-- 5ª demostración
example : symmetric S :=
assume x y,
assume h : S x y,
show S y x, from ⟨h.right, h.left⟩
-- 6ª demostración
example : symmetric S :=
λ x y h, ⟨h.right, h.left⟩
end
|
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#pragma once
#include "BaseFeatureMatcher.h"
#include "OnlineBow.h"
#include <gsl\gsl>
#include <unordered_map>
namespace mage
{
class Keyframe;
class OnlineBowFeatureMatcher : public BaseFeatureMatcher
{
public:
OnlineBowFeatureMatcher(const OnlineBow& onlineBow, const Id<Keyframe>& id, gsl::span<const ORBDescriptor> features);
virtual size_t QueryFeatures(const ORBDescriptor& descriptor, std::vector<ptrdiff_t>& matches) const override;
virtual const Id<Keyframe>& GetId() const override;
private:
// a Map of NodeId <==> the indexes of the features which are assigned to the Node.
std::unordered_map<ptrdiff_t, std::vector<ptrdiff_t>> m_featureMap;
const OnlineBow& m_onlineBow;
const Id<Keyframe> m_id;
};
}
|
import numpy as np
from scipy import misc
import pandas as pd
import os
# 1) Examen
## 2) Crear un vector de ceros de tamaño 10
vector_zeros_2 = np.zeros(10)
print('2) --> ', vector_zeros_2)
## 3) Crear un vector de ceros de tamaño 10 y el de la posicion 5 sea igual a 1
vector_zeros_3 = np.zeros(10)
vector_zeros_3[5] = 1
print('3) --> ', vector_zeros_3)
## 4) Cambiar el orden de un vector de 50 elementos, el de la posicion 1 es el de la 50 etc.
vector_zeros_4 = np.arange(50)
vector_zeros_4 = vector_zeros_4[::-1]
print('4) --> ', vector_zeros_4)
## 5) Crear una matriz de 3 x 3 con valores del cero al 8
matriz = np.arange(9)
matriz = matriz.reshape((3,3))
print('5) --> ', matriz)
## 6) Encontrar los indices que no sean cero en un arreglo
arreglo_indices = [1,2,0,0,4,0]
arreglo_indices = np.array(arreglo_indices)
resultado = np.where(arreglo_indices != 0)[0]
print('6) --> ', resultado)
## 7) Crear una matriz de identidad 3 x 3
matriz_identidad = np.eye(3)
print('7) --> ', matriz_identidad)
## 8) Crear una matriz 3 x 3 x 3 con valores randomicos
matriz_randomica = np.random.randint(27, size=27).reshape(3,3,3)
print('8) --> ', matriz_randomica)
## 9) Crear una matriz 10 x 10 y encontrar el mayor y el menor
matriz_diez = np.arange(100).reshape(10,10)
menor_valor = matriz_diez.min()
mayor_valor = matriz_diez.max()
print('9) menor --> ', menor_valor)
print('9) mayor --> ', mayor_valor)
## 10) Sacar los colores RGB unicos en una imagen (cuales rgb existen ej: 0, 0, 0 - 255,255,255 -> 2 colores)
imagen = misc.face()
resultado = len(np.unique(imagen, axis=0))
print('10) --> ', resultado)
## 11) ¿Como crear una serie de una lista, diccionario o arreglo?
mylist = list('abcdefghijklmnsopqrstuvwxyz')
myarr = np.arange(26)
mydict = dict(zip(mylist, myarr))
serie = pd.Series(mylist)
serie_diccionario = pd.Series(mydict)
serie_arreglo = pd.Series(myarr)
print('11) --> Serie de lista: ', serie, '\n')
print('11) --> Serie de diccionario: ', serie_diccionario, '\n')
print('11) --> Serie de arreglo ', serie_arreglo, '\n')
## 12) ¿Como convertir el indice de una serie en una columna de un DataFrame?
mylist = list('abcedfghijklmnopqrstuvwxyz')
myarr = np.arange(26)
mydict = dict(zip(mylist, myarr))
ser = pd.Series(mydict)
df = pd.DataFrame(ser).reset_index()
# Transformar la serie en dataframe y hacer una columna indice
df1 = pd.DataFrame(ser, index=['a'])
## 13) ¿Como combinar varias series para hacer un DataFrame?
ser1 = pd.Series(list('abcedfghijklmnopqrstuvwxyz'))
ser2 = pd.Series(np.arange(26))
df_combinado = pd.concat([ser1, ser2], axis = 1)
df_combinado = pd.DataFrame(df_combinado)
print('13) --> ', df_combinado)
## 14) ¿Como obtener los items que esten en una serie A y no en una serie B?
ser1 = pd.Series([1, 2, 3, 4, 5])
ser2 = pd.Series([4, 5, 6, 7, 8])
items_diferencia = np.setdiff1d(ser1, ser2)
print('14) --> ', items_diferencia)
## 15) ¿Como obtener los items que no son comunes en una serie A y serie B?
ser1 = pd.Series([1, 2, 3, 4, 5])
ser2 = pd.Series([4, 5, 6, 7, 8])
items_conjuncion = set(ser1) ^ set(ser2)
items_conjuncion = list(items_conjuncion)
items_conjuncion = pd.Series(items_conjuncion)
print('15) --> ', items_conjuncion, '\n')
## 16) ¿Como obtener el numero de veces que se repite un valor en una serie?
ser = pd.Series(np.take(list('abcdefgh'), np.random.randint(8, size=30)))
repeticiones, contador = np.unique(ser, return_counts=True)
repeticiones = dict(zip(repeticiones, contador))
print(repeticiones)
print(contador)
print('16) --> ', repeticiones, '\n')
## 17) ¿Como mantener los 2 valores mas repetidos de una serie, y a los demas valores cambiarles por 0 ?
np.random.RandomState(100)
ser = pd.Series(np.random.randint(1, 5, [12]))
valores_repetidos, contador = np.unique(ser, return_counts=True)
print('serie --> ', ser)
print('contador --> ', ser)
indice = np.argsort(-contador)
print('indice --> ', indice)
valores_repetidos = valores_repetidos[indice]
valores_repetidos[2:] = 0
print('17) --> Valores repetidos', valores_repetidos)
## 18) ¿Como transformar una serie de un arreglo de numpy a un DataFrame con un `shape` definido?
ser = pd.Series(np.random.randint(1, 10, 35))
df_shape = pd.DataFrame(ser.values.reshape(7,5))
print('18) --> ', df_shape)
## 19) ¿Obtener los valores de una serie conociendo la posicion por indice?
ser = pd.Series(list('abcdefghijklmnopqrstuvwxyz'))
pos = [0, 4, 8, 14, 20]
# a e i o u
resultado = ser[pos]
print('19) --> ', resultado)
## 20) ¿Como anadir series vertical u horizontalmente a un DataFrame?
ser1 = pd.Series(range(5))
ser2 = pd.Series(list('abcde'))
#Verical
df1 = pd.concat([pd.DataFrame(),ser2], ignore_index = True)
#Horizontal
df2 = pd.DataFrame().append(ser1, ignore_index=True)
print('20) Vertical --> ', df1)
print('21) Horizontal --> ', df2)
## 21)¿Obtener la media de una serie agrupada por otra serie?
#`groupby` tambien esta disponible en series.
frutas = pd.Series(np.random.choice(['manzana', 'banana', 'zanahoria'], 10))
pesos = pd.Series(np.linspace(1, 10, 10))
print(pesos.tolist())
print(frutas.tolist())
#> [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
#> ['banana', 'carrot', 'apple', 'carrot', 'carrot', 'apple', 'banana', 'carrot', 'apple', 'carrot']
# Los valores van a cambiar por ser random
# apple 6.0
# banana 4.0
# carrot 5.8
# dtype: float64
media_agrupada = pd.concat([frutas, pesos], axis = 1)
media_agrupada = media_agrupada.groupby(media_agrupada[0], as_index=False)[1].mean()
print('21) --> \n', media_agrupada)
## 22)¿Como importar solo columnas especificas de un archivo csv?
#https://raw.githubusercontent.com/selva86/datasets/master/BostonHousing.csv.
path = "./archivo.csv"
data_csv = pd.read_csv(
path,
nrows = 10)
columnas = ['crim', 'zn', 'indus']
data_tres_columnas = pd.read_csv(path, nrows=10, usecols=columnas)
print('22) --> ', data_tres_columnas)
|
$z + \overline{z} = 2 \cdot \text{Re}(z)$.
|
Formal statement is: lemma eventually_uniformity_metric: "eventually P uniformity \<longleftrightarrow> (\<exists>e>0. \<forall>x y. dist x y < e \<longrightarrow> P (x, y))" Informal statement is: A predicate $P$ holds eventually in the uniformity of a metric space if and only if there exists $\epsilon > 0$ such that $P$ holds for all pairs of points whose distance is less than $\epsilon$.
|
State Before: R : Type u
S : Type v
a b : R
n m : ℕ
inst✝ : Semiring R
p q r : R[X]
hp : p ≠ 0
hn : ∀ (m : ℕ), m < n → coeff p m = 0
⊢ n ≤ natTrailingDegree p State After: R : Type u
S : Type v
a b : R
n m : ℕ
inst✝ : Semiring R
p q r : R[X]
hp : p ≠ 0
hn : ∀ (m : ℕ), m < n → coeff p m = 0
⊢ n ≤ min' (support p) (_ : Finset.Nonempty (support p)) Tactic: rw [natTrailingDegree_eq_support_min' hp] State Before: R : Type u
S : Type v
a b : R
n m : ℕ
inst✝ : Semiring R
p q r : R[X]
hp : p ≠ 0
hn : ∀ (m : ℕ), m < n → coeff p m = 0
⊢ n ≤ min' (support p) (_ : Finset.Nonempty (support p)) State After: no goals Tactic: exact Finset.le_min' _ _ _ fun m hm => not_lt.1 fun hmn => mem_support_iff.1 hm <| hn _ hmn
|
function c=children(t,j)
%CHILDEREN Child nodes.
% C=CHILDREN(T) returns an N-by-2 array C containing the numbers of the
% child nodes for each node in the tree T, where N is the number of
% nodes in the tree. The children for leaf nodes (those with no children)
% are returned as 0.
%
% P=CHILDREN(T,J) takes an array J of node numbers and returns the children
% for the specified nodes.
%
% See also CLASSREGTREE, CLASSREGTREE/NUMNODES, CLASSREGTREE/PARENT.
% Copyright 2006-2007 The MathWorks, Inc.
% $Revision: 1.1.6.2 $ $Date: 2007/02/15 21:48:00 $
if nargin>=2 && ~validatenodes(t,j)
error('stats:classregtree:children:InvalidNode',...
'J must be an array of node numbers or a logical array of the proper size.');
end
if nargin<2
c = t.children;
else
c = t.children(j,:);
end
|
//
// Copyright (c) 2019 Vinnie Falco ([email protected])
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/boostorg/json
//
#ifndef BOOST_JSON_IMPL_VALUE_REF_IPP
#define BOOST_JSON_IMPL_VALUE_REF_IPP
#include <boost/json/value_ref.hpp>
#include <boost/json/array.hpp>
#include <boost/json/value.hpp>
BOOST_JSON_NS_BEGIN
value_ref::
operator
value() const
{
return make_value({});
}
value
value_ref::
from_init_list(
void const* p,
storage_ptr sp)
{
return make_value(
*reinterpret_cast<
init_list const*>(p),
std::move(sp));
}
bool
value_ref::
is_key_value_pair() const noexcept
{
if(what_ != what::ini)
return false;
if(arg_.init_list_.size() != 2)
return false;
auto const& e =
*arg_.init_list_.begin();
if( e.what_ != what::str &&
e.what_ != what::strfunc)
return false;
return true;
}
bool
value_ref::
maybe_object(
std::initializer_list<
value_ref> init) noexcept
{
for(auto const& e : init)
if(! e.is_key_value_pair())
return false;
return true;
}
string_view
value_ref::
get_string() const noexcept
{
BOOST_ASSERT(
what_ == what::str ||
what_ == what::strfunc);
if (what_ == what::strfunc)
return *static_cast<const string*>(f_.p);
return arg_.str_;
}
value
value_ref::
make_value(
storage_ptr sp) const
{
switch(what_)
{
default:
case what::str:
return string(
arg_.str_,
std::move(sp));
case what::ini:
return make_value(
arg_.init_list_,
std::move(sp));
case what::func:
return f_.f(f_.p,
std::move(sp));
case what::strfunc:
return f_.f(f_.p,
std::move(sp));
case what::cfunc:
return cf_.f(cf_.p,
std::move(sp));
}
}
value
value_ref::
make_value(
std::initializer_list<
value_ref> init,
storage_ptr sp)
{
if(maybe_object(init))
return make_object(
init, std::move(sp));
return make_array(
init, std::move(sp));
}
object
value_ref::
make_object(
std::initializer_list<value_ref> init,
storage_ptr sp)
{
object obj(std::move(sp));
obj.reserve(init.size());
for(auto const& e : init)
obj.emplace(
e.arg_.init_list_.begin()[0].get_string(),
e.arg_.init_list_.begin()[1].make_value(
obj.storage()));
return obj;
}
array
value_ref::
make_array(
std::initializer_list<
value_ref> init,
storage_ptr sp)
{
array arr(std::move(sp));
arr.reserve(init.size());
for(auto const& e : init)
arr.emplace_back(
e.make_value(
arr.storage()));
return arr;
}
void
value_ref::
write_array(
value* dest,
std::initializer_list<
value_ref> init,
storage_ptr const& sp)
{
struct undo
{
value* const base;
value* pos;
~undo()
{
if(pos)
while(pos > base)
(--pos)->~value();
}
};
undo u{dest, dest};
for(auto const& e : init)
{
::new(u.pos) value(
e.make_value(sp));
++u.pos;
}
u.pos = nullptr;
}
BOOST_JSON_NS_END
#endif
|
lemma neg_divideR_le_eq [field_simps]: "b /\<^sub>R c \<le> a \<longleftrightarrow> c *\<^sub>R a \<le> b" if "c < 0" for a b :: "'a :: ordered_real_vector"
|
library(dslabs)
data(murders)
pop <<- sort(murders$population, decreasing = TRUE)
# Define a variable states to be the state names from the murders data frame
states <<- murders$state[order(murders$population, decreasing = TRUE)]
# Define a variable ranks to determine the population size ranks
ranks <<- rank(murders$population)
# Define a variable ind to store the indexes needed to order the population values
ind <<- order(ranks)
# Create a data frame my_df with the state name and its rank and ordered from least populous to most
my_df <<- data.frame(STATES = states, POP = pop, POP_RANK = ranks[ind])
my_df
|
function [X,rho,eta,F] = pnu(A,L,W,b,k,nu,sm)
%PNU "Preconditioned" version of Brakhage's nu-method.
%
% [X,rho,eta,F] = pnu(A,L,W,b,k,nu,sm)
%
% Performs k steps of a `preconditioned' version of Brakhage's
% nu-method for the problem
% min || (A*L_p) x - b || ,
% where L_p is the A-weighted generalized inverse of L. Notice
% that the matrix W holding a basis for the null space of L must
% also be specified.
%
% The routine returns all k solutions, stored as columns of
% the matrix X. The solution seminorm and residual norm are returned
% in eta and rho, respectively.
%
% If nu is not specified, nu = .5 is the default value, which gives
% the Chebychev method of Nemirovskii and Polyak.
%
% If the generalized singular values sm of (A,L) are also provided,
% then pnu computes the filter factors associated with each step and
% stores them columnwise in the matrix F.
% Reference: H. Brakhage, "On ill-posed problems and the method of
% conjugate gradients"; in H. W. Engl & G. W. Groetsch, "Inverse and
% Ill-Posed Problems", Academic Press, 1987.
% Martin Hanke, Institut fuer Praktische Mathematik, Universitaet
% Karlsruhe and Per Christian Hansen, IMM, 06/25/92.
% Set parameters.
l_steps = 3; % Number of Lanczos steps for est. of || A*L_p ||.
fudge = 0.99; % Scale A and b by fudge/|| A*L_p ||.
fudge_thr = 1e-4; % Used to prevent filter factors from exploding.
% Initialization.
if (k < 1), error('Number of steps k must be positive'), end
if (nargin==5), nu = .5; end
[m,n] = size(A); p = size(L,1); X = zeros(n,k);
if (nargout > 1)
rho = zeros(k,1); eta = rho;
end;
if (nargin==7)
F = zeros(n,k); Fd = zeros(n,1); s = (sm(:,1)./sm(:,2)).^2;
end
V = zeros(p,l_steps); B = zeros(l_steps+1,l_steps);
v = zeros(p,1);
% Prepare for computations with L_p.
[NAA,x_0] = pinit(W,A,b); x1 = x_0;
% Compute a rough estimate of || A*L_p || by means of a few steps of
% Lanczos bidiagonalization, and scale A and b such that || A*L_p || is
% slightly less than one.
b_0 = b - A*x_0; beta = norm(b_0); u = b_0/beta;
for i=1:l_steps
r = ltsolve(L,A'*u,W,NAA) - beta*v;
alpha = norm(r); v = r/alpha;
B(i,i) = alpha; V(:,i) = v;
p = A*lsolve(L,v,W,NAA) - alpha*u;
beta = norm(p); u = p/beta;
B(i+1,i) = beta;
end
scale = fudge/norm(B); A = scale*A;
if (nargin==7), s = scale^2*s; end
% Prepare for iteration.
x = x_0;
z = -scale*b_0;
r = A'*z;
d1 = ltsolve(L,r);
d = lsolve(L,d1,W,NAA);
if (nargout>2), x1 = L*x_0; end
% Iterate.
for j=0:k-1
% Updates.
alpha = 4*(j+nu)*(j+nu+0.5)/(j+2*nu)/(j+2*nu+0.5);
beta = -(j+nu)*(j+1)*(j+0.5)/(j+2*nu)/(j+2*nu+0.5)/(j+nu+1);
Ad = A*d; AAd = A'*Ad;
x = x - alpha*d;
r = r - alpha*AAd;
rr1 = ltsolve(L,r);
rr = lsolve(L,rr1,W,NAA);
d = rr - beta*d;
X(:,j+1) = x;
if (nargout>1 )
z = z - alpha*Ad; rho(j+1) = norm(z)/scale;
end
if (nargout>2)
x1 = x1 - alpha*d1; d1 = rr1 - beta*d1;
eta(j+1) = norm(x1);
end
% Filter factors.
if (nargin==7)
if (j==0)
F(:,1) = alpha*s;
Fd = s - s.*F(:,1) + beta*s;
else
F(:,j+1) = F(:,j) + alpha*Fd;
Fd = s - s.*F(:,j+1) + beta*Fd;
end
if (j > 1)
f = find(abs(F(:,j)-1) < fudge_thr & abs(F(:,j-1)-1) < fudge_thr);
if ~isempty(f), F(f,j+1) = ones(length(f),1); end
end
end
end
|
Two continuous maps $f, g: S \to T$ are homotopic if and only if $S$ is empty or $T$ is path-connected and $f$ is homotopic to a constant map.
|
# Symbolic Computation
Symbolic computation deals with symbols, representing them exactly, instead of numerical approximations (floating point)
```python
import math
math.sqrt(3)
```
1.7320508075688772
```python
math.sqrt(8)
```
2.8284271247461903
$\sqrt(8) = 2\sqrt(2)$, but it's hard to see that here
```python
import sympy
sympy.sqrt(3)
```
$\displaystyle \sqrt{3}$
Sympy can even simplify symbolic computations
```python
sympy.sqrt(8)
```
$\displaystyle 2 \sqrt{2}$
```python
from sympy import symbols
x, y = symbols('x y')
expr = x + 2*y
expr
```
$\displaystyle x + 2 y$
Note that simply adding two symbols creates an expression. Now let's play around with it.
```python
expr + 1
```
$\displaystyle x + 2 y + 1$
```python
expr - x
```
$\displaystyle 2 y$
Note that `expr - x` was not `x + 2y -x`
```python
x*expr
```
$\displaystyle x \left(x + 2 y\right)$
```python
from sympy import expand, factor
expanded_expr = expand(x*expr)
expanded_expr
```
$\displaystyle x^{2} + 2 x y$
```python
factor(expanded_expr)
```
$\displaystyle x \left(x + 2 y\right)$
```python
from sympy import diff, sin, exp
diff(sin(x)*exp(x), x)
```
$\displaystyle e^{x} \sin{\left(x \right)} + e^{x} \cos{\left(x \right)}$
```python
from sympy import limit
limit(sin(x)/x, x, 0)
```
$\displaystyle 1$
### Exercise
Solve $x^2 - 2 = 0$ using sympy.solve
```python
# Type solution here
from sympy import solve
```
## Pretty printing
```python
from sympy import init_printing, Integral, sqrt
init_printing(use_latex=True)
```
```python
Integral(sqrt(1/x), x)
```
```python
from sympy import latex
latex(Integral(sqrt(1/x), x))
```
'\\int \\sqrt{\\frac{1}{x}}\\, dx'
More symbols
```python
expr2 = x + 2*y +3*z
```
### Exercise
Solve $x + 2*y + 3*z$ for $x$
```python
# Solution here
solve()
```
Difference between symbol name and python variable name
```python
x, y = symbols("y z")
```
```python
x
```
```python
y
```
```python
z
```
Symbol names can be more than one character long
```python
crazy = symbols('unrelated')
crazy + 1
```
```python
x = symbols("x")
expr = x + 1
x = 2
```
What happens when I print expr now? Does it print 3?
```python
print(expr)
```
x + 1
How do we get 3?
```python
x = symbols("x")
expr = x + 1
expr.subs(x, 2)
```
## Equalities
```python
x + 1 == 4
```
False
```python
from sympy import Eq
Eq(x + 1, 4)
```
Suppose we want to ask whether $(x + 1)^2 = x^2 + 2x + 1$
```python
(x + 1)**2 == x**2 + 2*x + 1
```
False
```python
from sympy import simplify
a = (x + 1)**2
b = x**2 + 2*x + 1
simplify(a-b)
```
### Exercise
Write a function that takes two expressions as input, and returns a tuple of two booleans. The first if they are equal symbolically, and the second if they are equal mathematically.
## More operations
```python
z = symbols("z")
expr = x**3 + 4*x*y - z
expr.subs([(x, 2), (y, 4), (z, 0)])
```
```python
from sympy import sympify
str_expr = "x**2 + 3*x - 1/2"
expr = sympify(str_expr)
expr
```
```python
expr.subs(x, 2)
```
```python
expr = sqrt(8)
```
```python
expr
```
```python
expr.evalf()
```
```python
from sympy import pi
pi.evalf(100)
```
```python
from sympy import cos
expr = cos(2*x)
expr.evalf(subs={x: 2.4})
```
### Exercise
```python
from IPython.core.display import Image
Image(filename='figures/comic.png')
```
Write a function that takes a symbolic expression (like pi), and determines the first place where 999999 appears.
Tip: Use the string representation of the number. Python starts counting at 0, but the decimal point offsets this
## Solving an ODE
```python
from sympy import Function
f, g = symbols('f g', cls=Function)
f(x)
```
```python
f(x).diff()
```
```python
diffeq = Eq(f(x).diff(x, x) - 2*f(x).diff(x) + f(x), sin(x))
diffeq
```
```python
from sympy import dsolve
dsolve(diffeq, f(x))
```
## Finite Differences
```python
from sympy import as_finite_diff
f = Function('f')
dfdx = f(x).diff(x)
as_finite_diff(dfdx)
```
```python
from sympy import Symbol
d2fdx2 = f(x).diff(x, 2)
h = Symbol('h')
as_finite_diff(d2fdx2, h)
```
```python
```
|
context("TwoSampleMR")
library(gwasglue)
test_that("gwasvcf_to_TwoSampleMR", {
fn <- system.file("extdata","data.vcf.gz", package="gwasvcf")
vcf1 <- VariantAnnotation::readVcf(fn)
exposure_dat <- gwasvcf_to_TwoSampleMR(vcf1)
expect_true(nrow(exposure_dat) == nrow(vcf1))
})
test_that("ieugwasr_to_TwoSampleMR", {
a <- ieugwasr::tophits("ieu-a-2")
b <- ieugwasr::associations(a$rsid, "ieu-a-7")
exposure_dat <- ieugwasr_to_TwoSampleMR(a)
outcome_dat <- ieugwasr_to_TwoSampleMR(b, type="outcome")
dat <- TwoSampleMR::harmonise_data(exposure_dat, outcome_dat)
out <- TwoSampleMR::mr(dat)
expect_true(nrow(exposure_dat) == nrow(dat))
expect_true(nrow(out) > 3)
})
|
import numpy as np
import pytest
from opt_einsum import contract, helpers, contract_expression, backends
try:
import tensorflow as tf
found_tensorflow = True
except ImportError:
found_tensorflow = False
try:
import os
os.environ['MKL_THREADING_LAYER'] = 'GNU'
import theano
found_theano = True
except ImportError:
found_theano = False
try:
import cupy
found_cupy = True
except ImportError:
found_cupy = False
try:
import dask.array as da
found_dask = True
except ImportError:
found_dask = False
try:
import sparse
found_sparse = True
except ImportError:
found_sparse = False
tests = [
'ab,bc->ca',
'abc,bcd,dea',
'abc,def->fedcba',
# test 'prefer einsum' ops
'ijk,ikj',
'i,j->ij',
'ijk,k->ij',
]
@pytest.mark.skipif(not found_tensorflow, reason="Tensorflow not installed.")
@pytest.mark.parametrize("string", tests)
def test_tensorflow(string):
views = helpers.build_views(string)
ein = contract(string, *views, optimize=False, use_blas=False)
opt = np.empty_like(ein)
shps = [v.shape for v in views]
expr = contract_expression(string, *shps, optimize=True)
sess = tf.Session()
with sess.as_default():
expr(*views, backend='tensorflow', out=opt)
assert np.allclose(ein, opt)
# test non-conversion mode
tensorflow_views = backends.convert_arrays_to_tensorflow(views)
expr(*tensorflow_views, backend='tensorflow')
@pytest.mark.skipif(not found_cupy, reason="Cupy not installed.")
@pytest.mark.parametrize("string", tests)
def test_cupy(string): # pragma: no cover
views = helpers.build_views(string)
ein = contract(string, *views, optimize=False, use_blas=False)
shps = [v.shape for v in views]
expr = contract_expression(string, *shps, optimize=True)
opt = expr(*views, backend='cupy')
assert np.allclose(ein, opt)
# test non-conversion mode
cupy_views = backends.convert_arrays_to_cupy(views)
cupy_opt = expr(*cupy_views, backend='cupy')
assert isinstance(cupy_opt, cupy.ndarray)
assert np.allclose(ein, cupy.asnumpy(cupy_opt))
@pytest.mark.skipif(not found_theano, reason="Theano not installed.")
@pytest.mark.parametrize("string", tests)
def test_theano(string):
views = helpers.build_views(string)
ein = contract(string, *views, optimize=False, use_blas=False)
shps = [v.shape for v in views]
expr = contract_expression(string, *shps, optimize=True)
opt = expr(*views, backend='theano')
assert np.allclose(ein, opt)
# test non-conversion mode
theano_views = backends.convert_arrays_to_theano(views)
theano_opt = expr(*theano_views, backend='theano')
assert isinstance(theano_opt, theano.tensor.TensorVariable)
@pytest.mark.skipif(not found_dask, reason="Dask not installed.")
@pytest.mark.parametrize("string", tests)
def test_dask(string):
views = helpers.build_views(string)
ein = contract(string, *views, optimize=False, use_blas=False)
shps = [v.shape for v in views]
expr = contract_expression(string, *shps, optimize=True)
# test non-conversion mode
da_views = [da.from_array(x, chunks=(2)) for x in views]
da_opt = expr(*da_views, backend='dask')
# check type is maintained when not using numpy arrays
assert isinstance(da_opt, da.Array)
assert np.allclose(ein, np.array(da_opt))
# try raw contract
da_opt = contract(string, *da_views, backend='dask')
assert isinstance(da_opt, da.Array)
assert np.allclose(ein, np.array(da_opt))
@pytest.mark.skipif(not found_sparse, reason="Sparse not installed.")
@pytest.mark.parametrize("string", tests)
def test_sparse(string):
views = helpers.build_views(string)
# sparsify views so they don't become dense during contraction
for view in views:
np.random.seed(42)
mask = np.random.choice([False, True], view.shape, True, [0.05, 0.95])
view[mask] = 0
ein = contract(string, *views, optimize=False, use_blas=False)
shps = [v.shape for v in views]
expr = contract_expression(string, *shps, optimize=True)
# test non-conversion mode
sparse_views = [sparse.COO.from_numpy(x) for x in views]
sparse_opt = expr(*sparse_views, backend='sparse')
# check type is maintained when not using numpy arrays
assert isinstance(sparse_opt, sparse.COO)
assert np.allclose(ein, sparse_opt.todense())
# try raw contract
sparse_opt = contract(string, *sparse_views, backend='sparse')
assert isinstance(sparse_opt, sparse.COO)
assert np.allclose(ein, sparse_opt.todense())
|
\section{Real numbers}
|
(* Copyright 2021 (C) Mihails Milehins *)
section\<open>\<open>Hom\<close>-functor\<close>
theory CZH_ECAT_Hom
imports
CZH_ECAT_Set
CZH_ECAT_PCategory
begin
subsection\<open>\<open>hom\<close>-function\<close>
text\<open>
The \<open>hom\<close>-function is a part of the definition of the \<open>Hom\<close>-functor,
as presented in \<^cite>\<open>"noauthor_nlab_nodate"\<close>\footnote{\url{
https://ncatlab.org/nlab/show/hom-functor
}}.
\<close>
definition cf_hom :: "V \<Rightarrow> V \<Rightarrow> V"
where "cf_hom \<CC> f =
[
(
\<lambda>q\<in>\<^sub>\<circ>Hom \<CC> (\<CC>\<lparr>Cod\<rparr>\<lparr>vpfst f\<rparr>) (\<CC>\<lparr>Dom\<rparr>\<lparr>vpsnd f\<rparr>).
vpsnd f \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> q \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> vpfst f
),
Hom \<CC> (\<CC>\<lparr>Cod\<rparr>\<lparr>vpfst f\<rparr>) (\<CC>\<lparr>Dom\<rparr>\<lparr>vpsnd f\<rparr>),
Hom \<CC> (\<CC>\<lparr>Dom\<rparr>\<lparr>vpfst f\<rparr>) (\<CC>\<lparr>Cod\<rparr>\<lparr>vpsnd f\<rparr>)
]\<^sub>\<circ>"
text\<open>Components.\<close>
lemma cf_hom_components:
shows "cf_hom \<CC> f\<lparr>ArrVal\<rparr> =
(
\<lambda>q\<in>\<^sub>\<circ>Hom \<CC> (\<CC>\<lparr>Cod\<rparr>\<lparr>vpfst f\<rparr>) (\<CC>\<lparr>Dom\<rparr>\<lparr>vpsnd f\<rparr>).
vpsnd f \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> q \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> vpfst f
)"
and "cf_hom \<CC> f\<lparr>ArrDom\<rparr> = Hom \<CC> (\<CC>\<lparr>Cod\<rparr>\<lparr>vpfst f\<rparr>) (\<CC>\<lparr>Dom\<rparr>\<lparr>vpsnd f\<rparr>)"
and "cf_hom \<CC> f\<lparr>ArrCod\<rparr> = Hom \<CC> (\<CC>\<lparr>Dom\<rparr>\<lparr>vpfst f\<rparr>) (\<CC>\<lparr>Cod\<rparr>\<lparr>vpsnd f\<rparr>)"
unfolding cf_hom_def arr_field_simps by (simp_all add: nat_omega_simps)
subsubsection\<open>Arrow value\<close>
mk_VLambda cf_hom_components(1)
|vsv cf_hom_ArrVal_vsv[cat_cs_intros]|
lemma cf_hom_ArrVal_vdomain[cat_cs_simps]:
assumes "g : a \<mapsto>\<^bsub>op_cat \<CC>\<^esub> b" and "f : a' \<mapsto>\<^bsub>\<CC>\<^esub> b'"
shows "\<D>\<^sub>\<circ> (cf_hom \<CC> [g, f]\<^sub>\<circ>\<lparr>ArrVal\<rparr>) = Hom \<CC> a a'"
using assms
unfolding cf_hom_components
by (simp_all add: nat_omega_simps cat_op_simps cat_cs_simps)
lemma cf_hom_ArrVal_app[cat_cs_simps]:
assumes "g : c \<mapsto>\<^bsub>op_cat \<CC>\<^esub> d" and "q : c \<mapsto>\<^bsub>\<CC>\<^esub> c'" and "f : c' \<mapsto>\<^bsub>\<CC>\<^esub> d'"
shows "cf_hom \<CC> [g, f]\<^sub>\<circ>\<lparr>ArrVal\<rparr>\<lparr>q\<rparr> = f \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> q \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> g"
using assms
unfolding cf_hom_components
by (simp_all add: nat_omega_simps cat_op_simps cat_cs_simps)
lemma (in category) cf_hom_ArrVal_vrange:
assumes "g : a \<mapsto>\<^bsub>op_cat \<CC>\<^esub> b" and "f : a' \<mapsto>\<^bsub>\<CC>\<^esub> b'"
shows "\<R>\<^sub>\<circ> (cf_hom \<CC> [g, f]\<^sub>\<circ>\<lparr>ArrVal\<rparr>) \<subseteq>\<^sub>\<circ> Hom \<CC> b b'"
proof(intro vsubsetI)
interpret gf: vsv \<open>cf_hom \<CC> [g, f]\<^sub>\<circ>\<lparr>ArrVal\<rparr>\<close>
unfolding cf_hom_components by auto
fix y assume "y \<in>\<^sub>\<circ> \<R>\<^sub>\<circ> (cf_hom \<CC> [g, f]\<^sub>\<circ>\<lparr>ArrVal\<rparr>)"
then obtain q where y_def: "y = cf_hom \<CC> [g, f]\<^sub>\<circ>\<lparr>ArrVal\<rparr>\<lparr>q\<rparr>"
and "q \<in>\<^sub>\<circ> \<D>\<^sub>\<circ> (cf_hom \<CC> [g, f]\<^sub>\<circ>\<lparr>ArrVal\<rparr>)"
by (metis gf.vrange_atD)
then have q: "q : a \<mapsto>\<^bsub>\<CC>\<^esub> a'"
unfolding cf_hom_ArrVal_vdomain[OF assms] by simp
from assms q show "y \<in>\<^sub>\<circ> Hom \<CC> b b'"
unfolding y_def cf_hom_ArrVal_app[OF assms(1) q assms(2)] cat_op_simps
by (auto intro: cat_cs_intros)
qed
subsubsection\<open>Arrow domain\<close>
lemma (in category) cf_hom_ArrDom:
assumes "gf : [c, c']\<^sub>\<circ> \<mapsto>\<^bsub>op_cat \<CC> \<times>\<^sub>C \<CC>\<^esub> dd'"
shows "cf_hom \<CC> gf\<lparr>ArrDom\<rparr> = Hom \<CC> c c'"
proof-
from assms obtain g f d d'
where "gf = [g, f]\<^sub>\<circ>" and "g : c \<mapsto>\<^bsub>op_cat \<CC>\<^esub> d" and "f : c' \<mapsto>\<^bsub>\<CC>\<^esub> d'"
unfolding cf_hom_components
by (elim cat_prod_2_is_arrE[rotated 2]) (auto intro: cat_cs_intros)
then show ?thesis
unfolding cf_hom_components
by (simp_all add: nat_omega_simps cat_op_simps cat_cs_simps)
qed
lemmas [cat_cs_simps] = category.cf_hom_ArrDom
subsubsection\<open>Arrow codomain\<close>
lemma (in category) cf_hom_ArrCod:
assumes "gf : cc' \<mapsto>\<^bsub>op_cat \<CC> \<times>\<^sub>C \<CC>\<^esub> [d, d']\<^sub>\<circ>"
shows "cf_hom \<CC> gf\<lparr>ArrCod\<rparr> = Hom \<CC> d d'"
proof-
from assms obtain g f c c'
where "gf = [g, f]\<^sub>\<circ>" and "g : c \<mapsto>\<^bsub>op_cat \<CC>\<^esub> d" and "f : c' \<mapsto>\<^bsub>\<CC>\<^esub> d'"
unfolding cf_hom_components
by (elim cat_prod_2_is_arrE[rotated 2]) (auto intro: cat_cs_intros)
then show ?thesis
unfolding cf_hom_components
by (simp_all add: nat_omega_simps cat_op_simps cat_cs_simps)
qed
lemmas [cat_cs_simps] = category.cf_hom_ArrCod
subsubsection\<open>\<open>hom\<close>-function is an arrow in the category \<open>Set\<close>\<close>
lemma (in category) cat_cf_hom_ArrRel:
assumes "gf : cc' \<mapsto>\<^bsub>op_cat \<CC> \<times>\<^sub>C \<CC>\<^esub> dd'"
shows "arr_Set \<alpha> (cf_hom \<CC> gf)"
proof(intro arr_SetI)
from assms obtain g f c c' d d'
where gf_def: "gf = [g, f]\<^sub>\<circ>"
and cc'_def: "cc' = [c, c']\<^sub>\<circ>"
and dd'_def: "dd' = [d, d']\<^sub>\<circ>"
and op_g: "g : c \<mapsto>\<^bsub>op_cat \<CC>\<^esub> d"
and f: "f : c' \<mapsto>\<^bsub>\<CC>\<^esub> d'"
unfolding cf_hom_components
by (elim cat_prod_2_is_arrE[rotated 2]) (auto intro: cat_cs_intros)
from op_g have g: "g : d \<mapsto>\<^bsub>\<CC>\<^esub> c" unfolding cat_op_simps by simp
then have [simp]: "\<CC>\<lparr>Dom\<rparr>\<lparr>g\<rparr> = d" "\<CC>\<lparr>Cod\<rparr>\<lparr>g\<rparr> = c"
and d: "d \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>" and c: "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
by auto
from f have [simp]: "\<CC>\<lparr>Dom\<rparr>\<lparr>f\<rparr> = c'" "\<CC>\<lparr>Cod\<rparr>\<lparr>f\<rparr> = d'"
and c': "c' \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>" and d': "d' \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
by auto
show "vfsequence (cf_hom \<CC> gf)" unfolding cf_hom_def by simp
show vsv_hom_fg: "vsv (cf_hom \<CC> gf\<lparr>ArrVal\<rparr>)"
unfolding cf_hom_components by auto
show "vcard (cf_hom \<CC> gf) = 3\<^sub>\<nat>"
unfolding cf_hom_def by (simp add: nat_omega_simps)
show [simp]: "\<D>\<^sub>\<circ> (cf_hom \<CC> gf\<lparr>ArrVal\<rparr>) = cf_hom \<CC> gf\<lparr>ArrDom\<rparr>"
unfolding cf_hom_components by auto
show "\<R>\<^sub>\<circ> (cf_hom \<CC> gf\<lparr>ArrVal\<rparr>) \<subseteq>\<^sub>\<circ> cf_hom \<CC> gf\<lparr>ArrCod\<rparr>"
proof(rule vsubsetI)
interpret hom_fg: vsv \<open>cf_hom \<CC> gf\<lparr>ArrVal\<rparr>\<close> by (simp add: vsv_hom_fg)
fix y assume "y \<in>\<^sub>\<circ> \<R>\<^sub>\<circ> (cf_hom \<CC> gf\<lparr>ArrVal\<rparr>)"
then obtain q where y_def: "y = cf_hom \<CC> gf\<lparr>ArrVal\<rparr>\<lparr>q\<rparr>"
and q: "q \<in>\<^sub>\<circ> \<D>\<^sub>\<circ> (cf_hom \<CC> gf\<lparr>ArrVal\<rparr>)"
by (blast dest: hom_fg.vrange_atD)
from q have q: "q : c \<mapsto>\<^bsub>\<CC>\<^esub> c'"
by (simp add: cf_hom_ArrDom[OF assms[unfolded cc'_def]])
with g f have "f \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> q \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> g : d \<mapsto>\<^bsub>\<CC>\<^esub> d'"
by (auto intro: cat_cs_intros)
then show "y \<in>\<^sub>\<circ> cf_hom \<CC> gf\<lparr>ArrCod\<rparr>"
unfolding cf_hom_ArrCod[OF assms[unfolded dd'_def]]
unfolding y_def gf_def cf_hom_ArrVal_app[OF op_g q f]
by auto
qed
from c c' show "cf_hom \<CC> gf\<lparr>ArrDom\<rparr> \<in>\<^sub>\<circ> Vset \<alpha>"
unfolding cf_hom_components gf_def
by (auto simp: nat_omega_simps intro: cat_cs_intros)
from d d' show "cf_hom \<CC> gf\<lparr>ArrCod\<rparr> \<in>\<^sub>\<circ> Vset \<alpha>"
unfolding cf_hom_components gf_def
by (auto simp: nat_omega_simps intro: cat_cs_intros)
qed auto
lemmas [cat_cs_intros] = category.cat_cf_hom_ArrRel
lemma (in category) cat_cf_hom_cat_Set_is_arr:
assumes "gf : [a, b]\<^sub>\<circ> \<mapsto>\<^bsub>op_cat \<CC> \<times>\<^sub>C \<CC>\<^esub> [c, d]\<^sub>\<circ>"
shows "cf_hom \<CC> gf : Hom \<CC> a b \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom \<CC> c d"
proof(intro is_arrI)
from assms cat_cf_hom_ArrRel show "cf_hom \<CC> gf \<in>\<^sub>\<circ> cat_Set \<alpha>\<lparr>Arr\<rparr>"
unfolding cat_Set_components by auto
with assms show
"cat_Set \<alpha>\<lparr>Dom\<rparr>\<lparr>cf_hom \<CC> gf\<rparr> = Hom \<CC> a b"
"cat_Set \<alpha>\<lparr>Cod\<rparr>\<lparr>cf_hom \<CC> gf\<rparr> = Hom \<CC> c d"
unfolding cat_Set_components
by (simp_all add: cf_hom_ArrDom[OF assms] cf_hom_ArrCod[OF assms])
qed
lemma (in category) cat_cf_hom_cat_Set_is_arr':
assumes "gf : [a, b]\<^sub>\<circ> \<mapsto>\<^bsub>op_cat \<CC> \<times>\<^sub>C \<CC>\<^esub> [c, d]\<^sub>\<circ>"
and "\<AA>' = Hom \<CC> a b"
and "\<BB>' = Hom \<CC> c d"
and "\<CC>' = cat_Set \<alpha>"
shows "cf_hom \<CC> gf : \<AA>' \<mapsto>\<^bsub>\<CC>'\<^esub> \<BB>'"
using assms(1) unfolding assms(2-4) by (rule cat_cf_hom_cat_Set_is_arr)
lemmas [cat_cs_intros] = category.cat_cf_hom_cat_Set_is_arr'
subsubsection\<open>Composition\<close>
lemma (in category) cat_cf_hom_Comp:
assumes "g : b \<mapsto>\<^bsub>op_cat \<CC>\<^esub> c"
and "g' : b' \<mapsto>\<^bsub>\<CC>\<^esub> c'"
and "f : a \<mapsto>\<^bsub>op_cat \<CC>\<^esub> b"
and "f' : a' \<mapsto>\<^bsub>\<CC>\<^esub> b'"
shows
"cf_hom \<CC> [g, g']\<^sub>\<circ> \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub> cf_hom \<CC> [f, f']\<^sub>\<circ> =
cf_hom \<CC> [g \<circ>\<^sub>A\<^bsub>op_cat \<CC>\<^esub> f, g' \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> f']\<^sub>\<circ>"
proof-
interpret Set: category \<alpha> \<open>cat_Set \<alpha>\<close> by (rule category_cat_Set)
from assms(1,3) have g: "g : c \<mapsto>\<^bsub>\<CC>\<^esub> b" and f: "f : b \<mapsto>\<^bsub>\<CC>\<^esub> a"
unfolding cat_op_simps by simp_all
from assms(2,4) g f Set.category_axioms category_axioms have gg'_ff':
"cf_hom \<CC> [g, g']\<^sub>\<circ> \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub> cf_hom \<CC> [f, f']\<^sub>\<circ> :
Hom \<CC> a a' \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom \<CC> c c'"
by
(
cs_concl cs_shallow
cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros
)
then have dom_lhs:
"\<D>\<^sub>\<circ> ((cf_hom \<CC> [g, g']\<^sub>\<circ> \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub> cf_hom \<CC> [f, f']\<^sub>\<circ>)\<lparr>ArrVal\<rparr>) =
Hom \<CC> a a'"
by (cs_concl cs_shallow cs_simp: cat_cs_simps)+
from assms(2,4) g f Set.category_axioms category_axioms have gf_g'f':
"cf_hom \<CC> [g \<circ>\<^sub>A\<^bsub>op_cat \<CC>\<^esub> f, g' \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> f']\<^sub>\<circ> :
Hom \<CC> a a' \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom \<CC> c c'"
by (cs_concl cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros)
then have dom_rhs:
"\<D>\<^sub>\<circ> (cf_hom \<CC> [g \<circ>\<^sub>A\<^bsub>op_cat \<CC>\<^esub> f, g' \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> f']\<^sub>\<circ>\<lparr>ArrVal\<rparr>) = Hom \<CC> a a'"
by (cs_concl cs_simp: cat_cs_simps)
show ?thesis
proof(rule arr_Set_eqI[of \<alpha>])
from gg'_ff' show arr_Set_gg'_ff':
"arr_Set \<alpha> (cf_hom \<CC> [g, g']\<^sub>\<circ> \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub> cf_hom \<CC> [f, f']\<^sub>\<circ>)"
by (auto dest: cat_Set_is_arrD(1))
from gf_g'f' show arr_Set_gf_g'f':
"arr_Set \<alpha> (cf_hom \<CC> [g \<circ>\<^sub>A\<^bsub>op_cat \<CC>\<^esub> f, g' \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> f']\<^sub>\<circ>)"
by (auto dest: cat_Set_is_arrD(1))
show "(cf_hom \<CC> [g, g']\<^sub>\<circ> \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub> cf_hom \<CC> [f, f']\<^sub>\<circ>)\<lparr>ArrVal\<rparr> =
cf_hom \<CC> [g \<circ>\<^sub>A\<^bsub>op_cat \<CC>\<^esub> f, g' \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> f']\<^sub>\<circ>\<lparr>ArrVal\<rparr>"
proof(rule vsv_eqI, unfold dom_lhs dom_rhs)
fix q assume "q \<in>\<^sub>\<circ> Hom \<CC> a a'"
then have q: "q : a \<mapsto>\<^bsub>\<CC>\<^esub> a'" by auto
from category_axioms g f assms(2,4) q Set.category_axioms show
"(cf_hom \<CC> [g, g']\<^sub>\<circ> \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub> cf_hom \<CC> [f, f']\<^sub>\<circ>)\<lparr>ArrVal\<rparr>\<lparr>q\<rparr> =
cf_hom \<CC> [g \<circ>\<^sub>A\<^bsub>op_cat \<CC>\<^esub> f, g' \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> f']\<^sub>\<circ>\<lparr>ArrVal\<rparr>\<lparr>q\<rparr>"
by
(
cs_concl
cs_intro: cat_op_intros cat_cs_intros cat_prod_cs_intros
cs_simp: cat_op_simps cat_cs_simps
)
qed (use arr_Set_gg'_ff' arr_Set_gf_g'f' in auto)
qed (use gg'_ff' gf_g'f' in \<open>cs_concl cs_simp: cat_cs_simps\<close>)+
qed
lemmas [cat_cs_simps] = category.cat_cf_hom_Comp
subsubsection\<open>Identity\<close>
lemma (in category) cat_cf_hom_CId:
assumes "[c, c']\<^sub>\<circ> \<in>\<^sub>\<circ> (op_cat \<CC> \<times>\<^sub>C \<CC>)\<lparr>Obj\<rparr>"
shows "cf_hom \<CC> [\<CC>\<lparr>CId\<rparr>\<lparr>c\<rparr>, \<CC>\<lparr>CId\<rparr>\<lparr>c'\<rparr>]\<^sub>\<circ> = cat_Set \<alpha>\<lparr>CId\<rparr>\<lparr>Hom \<CC> c c'\<rparr>"
proof-
interpret Set: category \<alpha> \<open>cat_Set \<alpha>\<close> by (rule category_cat_Set)
interpret op_\<CC>: category \<alpha> \<open>op_cat \<CC>\<close> by (rule category_op)
from assms have op_c: "c \<in>\<^sub>\<circ> op_cat \<CC>\<lparr>Obj\<rparr>" and c': "c' \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
by (auto elim: cat_prod_2_ObjE[rotated 2] intro: cat_cs_intros)
then have c: "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>" unfolding cat_op_simps by simp
from c c' category_axioms Set.category_axioms have cf_hom_cc':
"cf_hom \<CC> [\<CC>\<lparr>CId\<rparr>\<lparr>c\<rparr>, \<CC>\<lparr>CId\<rparr>\<lparr>c'\<rparr>]\<^sub>\<circ> : Hom \<CC> c c' \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom \<CC> c c'"
by
(
cs_concl
cs_simp: cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros
)
then have dom_lhs: "\<D>\<^sub>\<circ> (cf_hom \<CC> [\<CC>\<lparr>CId\<rparr>\<lparr>c\<rparr>, \<CC>\<lparr>CId\<rparr>\<lparr>c'\<rparr>]\<^sub>\<circ>\<lparr>ArrVal\<rparr>) = Hom \<CC> c c'"
by (cs_concl cs_simp: cat_cs_simps)
from c c' category_axioms Set.category_axioms have CId_cc':
"cat_Set \<alpha>\<lparr>CId\<rparr>\<lparr>Hom \<CC> c c'\<rparr> : Hom \<CC> c c' \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom \<CC> c c'"
by
(
cs_concl
cs_simp: cat_Set_cs_simps cat_Set_components(1)
cs_intro: cat_cs_intros cat_prod_cs_intros
)
then have dom_rhs: "\<D>\<^sub>\<circ> (cat_Set \<alpha>\<lparr>CId\<rparr>\<lparr>Hom \<CC> c c'\<rparr>\<lparr>ArrVal\<rparr>) = Hom \<CC> c c'"
by (cs_concl cs_shallow cs_simp: cat_cs_simps )
show ?thesis
proof(rule arr_Set_eqI[of \<alpha>])
from cf_hom_cc' show arr_Set_CId_cc':
"arr_Set \<alpha> (cf_hom \<CC> [\<CC>\<lparr>CId\<rparr>\<lparr>c\<rparr>, \<CC>\<lparr>CId\<rparr>\<lparr>c'\<rparr>]\<^sub>\<circ>)"
by (auto dest: cat_Set_is_arrD(1))
from CId_cc' show arr_Set_Hom_cc':
"arr_Set \<alpha> (cat_Set \<alpha>\<lparr>CId\<rparr>\<lparr>Hom \<CC> c c'\<rparr>)"
by (auto simp: cat_Set_is_arrD(1))
show "cf_hom \<CC> [\<CC>\<lparr>CId\<rparr>\<lparr>c\<rparr>, \<CC>\<lparr>CId\<rparr>\<lparr>c'\<rparr>]\<^sub>\<circ>\<lparr>ArrVal\<rparr> =
cat_Set \<alpha>\<lparr>CId\<rparr>\<lparr>Hom \<CC> c c'\<rparr>\<lparr>ArrVal\<rparr>"
proof(rule vsv_eqI, unfold dom_lhs dom_rhs in_Hom_iff)
fix q assume "q : c \<mapsto>\<^bsub>\<CC>\<^esub> c'"
with category_axioms show
"cf_hom \<CC> [\<CC>\<lparr>CId\<rparr>\<lparr>c\<rparr>, \<CC>\<lparr>CId\<rparr>\<lparr>c'\<rparr>]\<^sub>\<circ>\<lparr>ArrVal\<rparr>\<lparr>q\<rparr> =
cat_Set \<alpha>\<lparr>CId\<rparr>\<lparr>Hom \<CC> c c'\<rparr>\<lparr>ArrVal\<rparr>\<lparr>q\<rparr>"
by (*slow*)
(
cs_concl
cs_simp: cat_cs_simps cat_op_simps cat_Set_cs_simps
cs_intro: cat_cs_intros
)
qed (use arr_Set_CId_cc' arr_Set_Hom_cc' in auto)
qed (use cf_hom_cc' CId_cc' in \<open>cs_concl cs_simp: cat_cs_simps\<close>)+
qed
lemmas [cat_cs_simps] = category.cat_cf_hom_CId
subsubsection\<open>Opposite \<open>hom\<close>-function\<close>
lemma (in category) cat_op_cat_cf_hom:
assumes "g : a \<mapsto>\<^bsub>\<CC>\<^esub> b" and "g' : a' \<mapsto>\<^bsub>op_cat \<CC>\<^esub> b'"
shows "cf_hom (op_cat \<CC>) [g, g']\<^sub>\<circ> = cf_hom \<CC> [g', g]\<^sub>\<circ>"
proof(rule arr_Set_eqI[of \<alpha>])
from assms show "arr_Set \<alpha> (cf_hom (op_cat \<CC>) [g, g']\<^sub>\<circ>)"
by
(
cs_concl cs_shallow
cs_simp: cat_op_simps cs_intro: cat_cs_intros cat_prod_cs_intros
)
from assms show "arr_Set \<alpha> (cf_hom \<CC> [g', g]\<^sub>\<circ>)"
by
(
cs_concl cs_shallow
cs_simp: cat_op_simps
cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros
)
from assms have dom_lhs:
"\<D>\<^sub>\<circ> (cf_hom (op_cat \<CC>) [g, g']\<^sub>\<circ>\<lparr>ArrVal\<rparr>) = Hom \<CC> a' a"
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps cs_intro: cat_cs_intros
)
from assms have dom_rhs: "\<D>\<^sub>\<circ> (cf_hom \<CC> [g', g]\<^sub>\<circ>\<lparr>ArrVal\<rparr>) = Hom \<CC> a' a"
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps cs_intro: cat_cs_intros
)
show "cf_hom (op_cat \<CC>) [g, g']\<^sub>\<circ>\<lparr>ArrVal\<rparr> = cf_hom \<CC> [g', g]\<^sub>\<circ>\<lparr>ArrVal\<rparr>"
proof(rule vsv_eqI, unfold dom_lhs dom_rhs in_Hom_iff)
fix f assume "f : a' \<mapsto>\<^bsub>\<CC>\<^esub> a"
with assms show
"cf_hom (op_cat \<CC>) [g, g']\<^sub>\<circ>\<lparr>ArrVal\<rparr>\<lparr>f\<rparr> = cf_hom \<CC> [g', g]\<^sub>\<circ>\<lparr>ArrVal\<rparr>\<lparr>f\<rparr>"
unfolding cat_op_simps
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps cs_intro: cat_cs_intros
)
qed (simp_all add: cf_hom_components)
from category_axioms assms show
"cf_hom (op_cat \<CC>) [g, g']\<^sub>\<circ>\<lparr>ArrDom\<rparr> = cf_hom \<CC> [g', g]\<^sub>\<circ>\<lparr>ArrDom\<rparr>"
by
(
cs_concl cs_shallow
cs_simp: category.cf_hom_ArrDom cat_op_simps
cs_intro: cat_op_intros cat_prod_cs_intros
)
from category_axioms assms show
"cf_hom (op_cat \<CC>) [g, g']\<^sub>\<circ>\<lparr>ArrCod\<rparr> = cf_hom \<CC> [g', g]\<^sub>\<circ>\<lparr>ArrCod\<rparr>"
by
(
cs_concl cs_shallow
cs_simp: category.cf_hom_ArrCod cat_op_simps
cs_intro: cat_op_intros cat_prod_cs_intros
)
qed
lemmas [cat_cs_simps] = category.cat_op_cat_cf_hom
subsection\<open>\<open>Hom\<close>-functor\<close>
subsubsection\<open>Definition and elementary properties\<close>
text\<open>
See \<^cite>\<open>"noauthor_nlab_nodate"\<close>\footnote{\url{
https://ncatlab.org/nlab/show/hom-functor
}}.
\<close>
definition cf_Hom :: "V \<Rightarrow> V \<Rightarrow> V" (\<open>Hom\<^sub>O\<^sub>.\<^sub>C\<index>_'(/-,-/')\<close>)
where "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-) =
[
(\<lambda>a\<in>\<^sub>\<circ>(op_cat \<CC> \<times>\<^sub>C \<CC>)\<lparr>Obj\<rparr>. Hom \<CC> (vpfst a) (vpsnd a)),
(\<lambda>f\<in>\<^sub>\<circ>(op_cat \<CC> \<times>\<^sub>C \<CC>)\<lparr>Arr\<rparr>. cf_hom \<CC> f),
op_cat \<CC> \<times>\<^sub>C \<CC>,
cat_Set \<alpha>
]\<^sub>\<circ>"
text\<open>Components.\<close>
lemma cf_Hom_components:
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ObjMap\<rparr> =
(\<lambda>a\<in>\<^sub>\<circ>(op_cat \<CC> \<times>\<^sub>C \<CC>)\<lparr>Obj\<rparr>. Hom \<CC> (vpfst a) (vpsnd a))"
and "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ArrMap\<rparr> = (\<lambda>f\<in>\<^sub>\<circ>(op_cat \<CC> \<times>\<^sub>C \<CC>)\<lparr>Arr\<rparr>. cf_hom \<CC> f)"
and "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>HomDom\<rparr> = op_cat \<CC> \<times>\<^sub>C \<CC>"
and "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>HomCod\<rparr> = cat_Set \<alpha>"
unfolding cf_Hom_def dghm_field_simps by (simp_all add: nat_omega_simps)
subsubsection\<open>Object map\<close>
mk_VLambda cf_Hom_components(1)
|vsv cf_Hom_ObjMap_vsv|
lemma cf_Hom_ObjMap_vdomain[cat_cs_simps]:
"\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ObjMap\<rparr>) = (op_cat \<CC> \<times>\<^sub>C \<CC>)\<lparr>Obj\<rparr>"
unfolding cf_Hom_components by simp
lemma cf_Hom_ObjMap_app[cat_cs_simps]:
assumes "[a, b]\<^sub>\<circ> \<in>\<^sub>\<circ> (op_cat \<CC> \<times>\<^sub>C \<CC>)\<lparr>Obj\<rparr>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ObjMap\<rparr>\<lparr>a, b\<rparr>\<^sub>\<bullet> = Hom \<CC> a b"
using assms unfolding cf_Hom_components by (simp add: nat_omega_simps)
lemma (in category) cf_Hom_ObjMap_vrange:
"\<R>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ObjMap\<rparr>) \<subseteq>\<^sub>\<circ> cat_Set \<alpha>\<lparr>Obj\<rparr>"
proof(intro vsubsetI)
interpret op_\<CC>: category \<alpha> \<open>op_cat \<CC>\<close> by (simp add: category_op)
fix y assume "y \<in>\<^sub>\<circ> \<R>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ObjMap\<rparr>)"
then obtain x where y_def: "y = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ObjMap\<rparr>\<lparr>x\<rparr>"
and x: "x \<in>\<^sub>\<circ> (op_cat \<CC> \<times>\<^sub>C \<CC>)\<lparr>Obj\<rparr>"
unfolding cf_Hom_components by auto
then obtain a b where x_def: "x = [a, b]\<^sub>\<circ>"
and a: "a \<in>\<^sub>\<circ> op_cat \<CC>\<lparr>Obj\<rparr>"
and b: "b \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
by (elim cat_prod_2_ObjE[OF op_\<CC>.category_axioms category_axioms x])
from a have a: "a \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>" unfolding cat_op_simps by simp
from a b show "y \<in>\<^sub>\<circ> cat_Set \<alpha>\<lparr>Obj\<rparr>"
unfolding
y_def x_def cf_Hom_ObjMap_app[OF x[unfolded x_def]] cat_Set_components
by (auto simp: cat_cs_intros)
qed
subsubsection\<open>Arrow map\<close>
mk_VLambda cf_Hom_components(2)
|vsv cf_Hom_ArrMap_vsv|
|vdomain cf_Hom_ArrMap_vdomain[cat_cs_simps]|
|app cf_Hom_ArrMap_app[cat_cs_simps]|
subsubsection\<open>\<open>Hom\<close>-functor is a functor\<close>
lemma (in category) cat_Hom_is_functor:
"Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-) : op_cat \<CC> \<times>\<^sub>C \<CC> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
proof-
interpret Set: category \<alpha> \<open>cat_Set \<alpha>\<close> by (rule category_cat_Set)
interpret \<CC>\<CC>: category \<alpha> \<open>op_cat \<CC> \<times>\<^sub>C \<CC>\<close>
by (simp add: category_axioms category_cat_prod_2 category_op)
interpret op_\<CC>: category \<alpha> \<open>op_cat \<CC>\<close> by (rule category_op)
show ?thesis
proof(intro is_functorI')
show "vfsequence Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)"
unfolding cf_Hom_def by simp
show op_\<CC>_\<CC>: "category \<alpha> (op_cat \<CC> \<times>\<^sub>C \<CC>)" by (auto simp: cat_cs_intros)
show "vcard Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-) = 4\<^sub>\<nat>"
unfolding cf_Hom_def by (simp add: nat_omega_simps)
show "\<R>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ObjMap\<rparr>) \<subseteq>\<^sub>\<circ> cat_Set \<alpha>\<lparr>Obj\<rparr>"
by (simp add: cf_Hom_ObjMap_vrange)
show "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ArrMap\<rparr>\<lparr>gf\<rparr> :
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ObjMap\<rparr>\<lparr>ab\<rparr> \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ObjMap\<rparr>\<lparr>cd\<rparr>"
if gf: "gf : ab \<mapsto>\<^bsub>op_cat \<CC> \<times>\<^sub>C \<CC>\<^esub> cd" for gf ab cd
unfolding slicing_simps cat_smc_cat_Set[symmetric]
proof-
obtain g f a b c d where gf_def: "gf = [g, f]\<^sub>\<circ>"
and ab_def: "ab = [a, b]\<^sub>\<circ>"
and cd_def: "cd = [c, d]\<^sub>\<circ>"
and "g : a \<mapsto>\<^bsub>op_cat \<CC>\<^esub> c"
and f: "f : b \<mapsto>\<^bsub>\<CC>\<^esub> d"
by (elim cat_prod_2_is_arrE[OF category_op category_axioms gf])
then have g: "g : c \<mapsto>\<^bsub>\<CC>\<^esub> a" unfolding cat_op_simps by simp
from category_axioms that g f show "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ArrMap\<rparr>\<lparr>gf\<rparr> :
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ObjMap\<rparr>\<lparr>ab\<rparr> \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ObjMap\<rparr>\<lparr>cd\<rparr>"
unfolding gf_def ab_def cd_def (*slow*)
by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_op_intros)
qed
show "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ArrMap\<rparr>\<lparr>gg' \<circ>\<^sub>A\<^bsub>op_cat \<CC> \<times>\<^sub>C \<CC>\<^esub> ff'\<rparr> =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ArrMap\<rparr>\<lparr>gg'\<rparr> \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub> Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ArrMap\<rparr>\<lparr>ff'\<rparr>"
if gg': "gg' : bb' \<mapsto>\<^bsub>op_cat \<CC> \<times>\<^sub>C \<CC>\<^esub> cc'"
and ff': "ff' : aa' \<mapsto>\<^bsub>op_cat \<CC> \<times>\<^sub>C \<CC>\<^esub> bb'"
for gg' bb' cc' ff' aa'
proof-
obtain g g' b b' c c'
where gg'_def: "gg' = [g, g']\<^sub>\<circ>"
and bb'_def: "bb' = [b, b']\<^sub>\<circ>"
and cc'_def: "cc' = [c, c']\<^sub>\<circ>"
and "g : b \<mapsto>\<^bsub>op_cat \<CC>\<^esub> c"
and g': "g' : b' \<mapsto>\<^bsub>\<CC>\<^esub> c'"
by (elim cat_prod_2_is_arrE[OF category_op category_axioms gg'])
moreover obtain f f' a a' b'' b'''
where ff'_def: "ff' = [f, f']\<^sub>\<circ>"
and aa'_def: "aa' = [a, a']\<^sub>\<circ>"
and "bb' = [b'', b''']\<^sub>\<circ>"
and "f : a \<mapsto>\<^bsub>op_cat \<CC>\<^esub> b''"
and "f' : a' \<mapsto>\<^bsub>\<CC>\<^esub> b'''"
by (elim cat_prod_2_is_arrE[OF category_op category_axioms ff'])
ultimately have f: "f : b \<mapsto>\<^bsub>\<CC>\<^esub> a"
and f': "f' : a' \<mapsto>\<^bsub>\<CC>\<^esub> b'"
and g: "g : c \<mapsto>\<^bsub>\<CC>\<^esub> b"
by (auto simp: cat_op_simps)
from category_axioms that g f g' f' show ?thesis
unfolding
slicing_simps cat_smc_cat_Set[symmetric]
gg'_def bb'_def cc'_def ff'_def aa'_def
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps cat_prod_cs_simps
cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros
)
qed
show "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ArrMap\<rparr>\<lparr>(op_cat \<CC> \<times>\<^sub>C \<CC>)\<lparr>CId\<rparr>\<lparr>cc'\<rparr>\<rparr> =
cat_Set \<alpha>\<lparr>CId\<rparr>\<lparr>Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ObjMap\<rparr>\<lparr>cc'\<rparr>\<rparr>"
if "cc' \<in>\<^sub>\<circ> (op_cat \<CC> \<times>\<^sub>C \<CC>)\<lparr>Obj\<rparr>" for cc'
proof-
from that obtain c c'
where cc'_def: "cc' = [c, c']\<^sub>\<circ>"
and c: "c \<in>\<^sub>\<circ> op_cat \<CC>\<lparr>Obj\<rparr>"
and c': "c' \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
by (elim cat_prod_2_ObjE[rotated 2]) (auto intro: cat_cs_intros)
then have c: "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>" unfolding cat_op_simps by simp
with c' category_axioms Set.category_axioms that show ?thesis
unfolding cc'_def
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps cat_prod_cs_simps
cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros
)
qed
qed (auto simp: cf_Hom_components cat_cs_intros)
qed
lemma (in category) cat_Hom_is_functor':
assumes "\<beta> = \<alpha>" and "\<AA>' = op_cat \<CC> \<times>\<^sub>C \<CC>" and "\<BB>' = cat_Set \<alpha>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-) : \<AA>' \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> \<BB>'"
unfolding assms by (rule cat_Hom_is_functor)
lemmas [cat_cs_intros] = category.cat_Hom_is_functor'
subsection\<open>Composition of a \<open>Hom\<close>-functor and two functors\<close>
subsubsection\<open>Definition and elementary properties\<close>
definition cf_bcomp_Hom :: "V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V" (\<open>Hom\<^sub>O\<^sub>.\<^sub>C\<index>_'(/_-,_-/')\<close>)
\<comment>\<open>The following definition may seem redundant, but it will help to avoid
proof duplication later.\<close>
where "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,\<GG>-) = cf_cn_cov_bcomp (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)) \<FF> \<GG>"
subsubsection\<open>Object map\<close>
lemma cf_bcomp_Hom_ObjMap_vsv: "vsv (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,\<GG>-)\<lparr>ObjMap\<rparr>)"
unfolding cf_bcomp_Hom_def by (rule cf_cn_cov_bcomp_ObjMap_vsv)
lemma cf_bcomp_Hom_ObjMap_vdomain[cat_cs_simps]:
assumes "\<FF> : \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>" and "\<GG> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
shows "\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,\<GG>-)\<lparr>ObjMap\<rparr>) = (op_cat \<AA> \<times>\<^sub>C \<BB>)\<lparr>Obj\<rparr>"
using assms unfolding cf_bcomp_Hom_def by (rule cf_cn_cov_bcomp_ObjMap_vdomain)
lemma cf_bcomp_Hom_ObjMap_app[cat_cs_simps]:
assumes "\<FF> : \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<GG> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "[a, b]\<^sub>\<circ> \<in>\<^sub>\<circ> (op_cat \<AA> \<times>\<^sub>C \<BB>)\<lparr>Obj\<rparr>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,\<GG>-)\<lparr>ObjMap\<rparr>\<lparr>a, b\<rparr>\<^sub>\<bullet> =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ObjMap\<rparr>\<lparr>\<FF>\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>, \<GG>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>\<rparr>\<^sub>\<bullet>"
using assms unfolding cf_bcomp_Hom_def by (rule cf_cn_cov_bcomp_ObjMap_app)
lemma (in category) cf_bcomp_Hom_ObjMap_vrange:
assumes "\<FF> : \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<GG> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
shows "\<R>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,\<GG>-)\<lparr>ObjMap\<rparr>) \<subseteq>\<^sub>\<circ> cat_Set \<alpha>\<lparr>Obj\<rparr>"
using category_axioms
unfolding cf_bcomp_Hom_def
by (intro cf_cn_cov_bcomp_ObjMap_vrange[OF assms])
(cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)
subsubsection\<open>Arrow map\<close>
lemma cf_bcomp_Hom_ArrMap_vsv: "vsv (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,\<GG>-)\<lparr>ArrMap\<rparr>)"
unfolding cf_bcomp_Hom_def by (rule cf_cn_cov_bcomp_ArrMap_vsv)
lemma cf_bcomp_Hom_ArrMap_vdomain[cat_cs_simps]:
assumes "\<FF> : \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>" and "\<GG> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
shows "\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,\<GG>-)\<lparr>ArrMap\<rparr>) = (op_cat \<AA> \<times>\<^sub>C \<BB>)\<lparr>Arr\<rparr>"
using assms
unfolding cf_bcomp_Hom_def
by (rule cf_cn_cov_bcomp_ArrMap_vdomain)
lemma cf_bcomp_Hom_ArrMap_app[cat_cs_simps]:
assumes "\<FF> : \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<GG> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "[f, g]\<^sub>\<circ> \<in>\<^sub>\<circ> (op_cat \<AA> \<times>\<^sub>C \<BB>)\<lparr>Arr\<rparr>"
shows
"Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,\<GG>-)\<lparr>ArrMap\<rparr>\<lparr>f, g\<rparr>\<^sub>\<bullet> =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ArrMap\<rparr>\<lparr>\<FF>\<lparr>ArrMap\<rparr>\<lparr>f\<rparr>, \<GG>\<lparr>ArrMap\<rparr>\<lparr>g\<rparr>\<rparr>\<^sub>\<bullet>"
using assms
unfolding cf_bcomp_Hom_def
by (rule cf_cn_cov_bcomp_ArrMap_app)
lemma (in category) cf_bcomp_Hom_ArrMap_vrange:
assumes "\<FF> : \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<GG> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
shows "\<R>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,\<GG>-)\<lparr>ArrMap\<rparr>) \<subseteq>\<^sub>\<circ> cat_Set \<alpha>\<lparr>Arr\<rparr>"
using category_axioms
unfolding cf_bcomp_Hom_def
by (intro cf_cn_cov_bcomp_ArrMap_vrange[OF assms])
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_op_intros
)
subsubsection\<open>Composition of a \<open>Hom\<close>-functor and two functors is a functor\<close>
lemma (in category) cat_cf_bcomp_Hom_is_functor:
assumes "\<FF> : \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>" and "\<GG> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,\<GG>-) : op_cat \<AA> \<times>\<^sub>C \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
using assms category_axioms
unfolding cf_bcomp_Hom_def
by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)
lemma (in category) cat_cf_bcomp_Hom_is_functor':
assumes "\<FF> : \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<GG> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<beta> = \<alpha>"
and "\<AA>' = op_cat \<AA> \<times>\<^sub>C \<BB>"
and "\<BB>' = cat_Set \<alpha>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,\<GG>-) : \<AA>' \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> \<BB>'"
using assms(1,2) unfolding assms(3-5) by (rule cat_cf_bcomp_Hom_is_functor)
lemmas [cat_cs_intros] = category.cat_cf_bcomp_Hom_is_functor'
subsection\<open>Composition of a \<open>Hom\<close>-functor and a functor\<close>
subsubsection\<open>Definition and elementary properties\<close>
text\<open>See subsection 1.15 in \<^cite>\<open>"bodo_categories_1970"\<close>.\<close>
definition cf_lcomp_Hom :: "V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V" (\<open>Hom\<^sub>O\<^sub>.\<^sub>C\<index>_'(/_-,-/')\<close>)
where "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,-) = cf_cn_cov_lcomp \<CC> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)) \<FF>"
definition cf_rcomp_Hom :: "V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V" (\<open>Hom\<^sub>O\<^sub>.\<^sub>C\<index>_'(/-,_-/')\<close>)
where "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-) = cf_cn_cov_rcomp \<CC> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)) \<GG>"
subsubsection\<open>Object map\<close>
lemma cf_lcomp_Hom_ObjMap_vsv[cat_cs_intros]: "vsv (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,-)\<lparr>ObjMap\<rparr>)"
unfolding cf_lcomp_Hom_def by (rule cf_cn_cov_lcomp_ObjMap_vsv)
lemma cf_rcomp_Hom_ObjMap_vsv[cat_cs_intros]: "vsv (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-)\<lparr>ObjMap\<rparr>)"
unfolding cf_rcomp_Hom_def by (rule cf_cn_cov_rcomp_ObjMap_vsv)
lemma cf_lcomp_Hom_ObjMap_vdomain[cat_cs_simps]:
assumes "category \<alpha> \<CC>" and "\<FF> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
shows "\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,-)\<lparr>ObjMap\<rparr>) = (op_cat \<BB> \<times>\<^sub>C \<CC>)\<lparr>Obj\<rparr>"
using assms
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cf_lcomp_Hom_def cs_intro: cat_cs_intros
)
lemma cf_rcomp_Hom_ObjMap_vdomain[cat_cs_simps]:
assumes "\<GG> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
shows "\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-)\<lparr>ObjMap\<rparr>) = (op_cat \<CC> \<times>\<^sub>C \<BB>)\<lparr>Obj\<rparr>"
using assms
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cf_rcomp_Hom_def cs_intro: cat_cs_intros
)
lemma cf_lcomp_Hom_ObjMap_app[cat_cs_simps]:
assumes "category \<alpha> \<CC>"
and "\<FF> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "b \<in>\<^sub>\<circ> op_cat \<BB>\<lparr>Obj\<rparr>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,-)\<lparr>ObjMap\<rparr>\<lparr>b, c\<rparr>\<^sub>\<bullet> =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ObjMap\<rparr>\<lparr>\<FF>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>, c\<rparr>\<^sub>\<bullet>"
using assms
unfolding cf_lcomp_Hom_def
by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_prod_cs_intros)
lemma cf_rcomp_Hom_ObjMap_app[cat_cs_simps]:
assumes "\<GG> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "c \<in>\<^sub>\<circ> op_cat \<CC>\<lparr>Obj\<rparr>"
and "b \<in>\<^sub>\<circ> \<BB>\<lparr>Obj\<rparr>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-)\<lparr>ObjMap\<rparr>\<lparr>c, b\<rparr>\<^sub>\<bullet> =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ObjMap\<rparr>\<lparr>c, \<GG>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>\<rparr>\<^sub>\<bullet>"
using assms
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cf_rcomp_Hom_def
cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros
)
lemma (in category) cat_cf_lcomp_Hom_ObjMap_vrange:
assumes "\<FF> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
shows "\<R>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,-)\<lparr>ObjMap\<rparr>) \<subseteq>\<^sub>\<circ> cat_Set \<alpha>\<lparr>Obj\<rparr>"
using category_axioms assms
unfolding cf_lcomp_Hom_def
by (intro cf_cn_cov_lcomp_ObjMap_vrange)
(cs_concl cs_shallow cs_intro: cat_cs_intros)
lemma (in category) cat_cf_rcomp_Hom_ObjMap_vrange:
assumes "\<GG> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
shows "\<R>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-)\<lparr>ObjMap\<rparr>) \<subseteq>\<^sub>\<circ> cat_Set \<alpha>\<lparr>Obj\<rparr>"
using category_axioms assms
unfolding cf_rcomp_Hom_def
by (intro cf_cn_cov_rcomp_ObjMap_vrange)
(cs_concl cs_shallow cs_intro: cat_cs_intros)
subsubsection\<open>Arrow map\<close>
lemma cf_lcomp_Hom_ArrMap_vsv[cat_cs_intros]: "vsv (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,-)\<lparr>ArrMap\<rparr>)"
unfolding cf_lcomp_Hom_def by (rule cf_cn_cov_lcomp_ArrMap_vsv)
lemma cf_rcomp_Hom_ArrMap_vsv[cat_cs_intros]: "vsv (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-)\<lparr>ArrMap\<rparr>)"
unfolding cf_rcomp_Hom_def by (rule cf_cn_cov_rcomp_ArrMap_vsv)
lemma cf_lcomp_Hom_ArrMap_vdomain[cat_cs_simps]:
assumes "category \<alpha> \<CC>" and "\<FF> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
shows "\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,-)\<lparr>ArrMap\<rparr>) = (op_cat \<BB> \<times>\<^sub>C \<CC>)\<lparr>Arr\<rparr>"
using assms
unfolding cf_lcomp_Hom_def
by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)
lemma cf_rcomp_Hom_ArrMap_vdomain[cat_cs_simps]:
assumes "category \<alpha> \<CC>" and "\<GG> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
shows "\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-)\<lparr>ArrMap\<rparr>) = (op_cat \<CC> \<times>\<^sub>C \<BB>)\<lparr>Arr\<rparr>"
using assms
unfolding cf_rcomp_Hom_def
by (cs_concl cs_shallow cs_simp: cat_cs_simps)
lemma cf_lcomp_Hom_ArrMap_app[cat_cs_simps]:
assumes "category \<alpha> \<CC>"
and "\<FF> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "g : a \<mapsto>\<^bsub>op_cat \<BB>\<^esub> b"
and "f : a' \<mapsto>\<^bsub>\<CC>\<^esub> b'"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,-)\<lparr>ArrMap\<rparr>\<lparr>g, f\<rparr>\<^sub>\<bullet> =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ArrMap\<rparr>\<lparr>\<FF>\<lparr>ArrMap\<rparr>\<lparr>g\<rparr>, f\<rparr>\<^sub>\<bullet>"
using assms
unfolding cf_lcomp_Hom_def cat_op_simps
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros cat_prod_cs_intros
)
lemma cf_rcomp_Hom_ArrMap_app[cat_cs_simps]:
assumes "\<GG> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "g : a \<mapsto>\<^bsub>op_cat \<CC>\<^esub> b"
and "f : a' \<mapsto>\<^bsub>\<BB>\<^esub> b'"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-)\<lparr>ArrMap\<rparr>\<lparr>g, f\<rparr>\<^sub>\<bullet> =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ArrMap\<rparr>\<lparr>g, \<GG>\<lparr>ArrMap\<rparr>\<lparr>f\<rparr>\<rparr>\<^sub>\<bullet>"
using assms
by
(
cs_concl
cs_simp: cat_cs_simps cf_rcomp_Hom_def
cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros
)
lemma (in category) cf_lcomp_Hom_ArrMap_vrange:
assumes "\<FF> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
shows "\<R>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,-)\<lparr>ArrMap\<rparr>) \<subseteq>\<^sub>\<circ> cat_Set \<alpha>\<lparr>Arr\<rparr>"
using category_axioms assms
unfolding cf_lcomp_Hom_def
by (intro cf_cn_cov_lcomp_ArrMap_vrange)
(cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)
lemma (in category) cf_rcomp_Hom_ArrMap_vrange:
assumes "\<GG> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
shows "\<R>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-)\<lparr>ArrMap\<rparr>) \<subseteq>\<^sub>\<circ> cat_Set \<alpha>\<lparr>Arr\<rparr>"
using category_axioms assms
unfolding cf_rcomp_Hom_def
by (intro cf_cn_cov_rcomp_ArrMap_vrange)
(cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)
subsubsection\<open>Further properties\<close>
lemma cf_bcomp_Hom_cf_lcomp_Hom[cat_cs_simps]:
"Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,cf_id \<CC>-) = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,-)"
unfolding cf_lcomp_Hom_def cf_cn_cov_lcomp_def cf_bcomp_Hom_def ..
lemma cf_bcomp_Hom_cf_rcomp_Hom[cat_cs_simps]:
"Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(cf_id \<CC>-,\<GG>-) = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-)"
unfolding cf_rcomp_Hom_def cf_cn_cov_rcomp_def cf_bcomp_Hom_def ..
subsubsection\<open>Composition of a \<open>Hom\<close>-functor and a functor is a functor\<close>
lemma (in category) cat_cf_lcomp_Hom_is_functor:
assumes "\<FF> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,-) : op_cat \<BB> \<times>\<^sub>C \<CC> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
using category_axioms assms
unfolding cf_lcomp_Hom_def
by (intro cf_cn_cov_lcomp_is_functor)
(cs_concl cs_shallow cs_intro: cat_cs_intros)
lemma (in category) cat_cf_lcomp_Hom_is_functor':
assumes "\<FF> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<beta> = \<alpha>"
and "\<AA>' = op_cat \<BB> \<times>\<^sub>C \<CC>"
and "\<BB>' = cat_Set \<alpha>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,-) : \<AA>' \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> \<BB>'"
using assms(1)
unfolding assms(2-4)
by (rule cat_cf_lcomp_Hom_is_functor)
lemmas [cat_cs_intros] = category.cat_cf_lcomp_Hom_is_functor'
lemma (in category) cat_cf_rcomp_Hom_is_functor:
assumes "\<GG> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-) : op_cat \<CC> \<times>\<^sub>C \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
using category_axioms assms
unfolding cf_rcomp_Hom_def
by (intro cf_cn_cov_rcomp_is_functor)
(cs_concl cs_shallow cs_intro: cat_cs_intros cat_op_intros)
lemma (in category) cat_cf_rcomp_Hom_is_functor':
assumes "\<GG> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>" and "\<beta> = \<alpha>"
and "\<AA>' = op_cat \<CC> \<times>\<^sub>C \<BB>"
and "\<BB>' = cat_Set \<alpha>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-) : \<AA>' \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> \<BB>'"
using assms(1)
unfolding assms(2-4)
by (rule cat_cf_rcomp_Hom_is_functor)
lemmas [cat_cs_intros] = category.cat_cf_rcomp_Hom_is_functor'
subsubsection\<open>Flip of a projections of a \<open>Hom\<close>-functor\<close>
lemma (in category) cat_bifunctor_flip_cf_rcomp_Hom:
assumes "\<GG> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
shows
"bifunctor_flip (op_cat \<CC>) \<BB> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-)) =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(op_cf \<GG>-,-)"
proof(rule cf_eqI)
interpret \<GG>: is_functor \<alpha> \<BB> \<CC> \<GG> by (rule assms)
from category_axioms assms show bf_Hom:
"bifunctor_flip (op_cat \<CC>) \<BB> Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-) :
\<BB> \<times>\<^sub>C op_cat \<CC> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
by (cs_concl cs_shallow cs_intro: cat_cs_intros)
from category_axioms assms show op_Hom:
"Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(op_cf \<GG>-,-) : \<BB> \<times>\<^sub>C op_cat \<CC> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
by
(
cs_concl cs_shallow
cs_simp: cat_op_simps cs_intro: cat_cs_intros cat_op_intros
)
from bf_Hom have ObjMap_dom_lhs:
"\<D>\<^sub>\<circ> (bifunctor_flip (op_cat \<CC>) \<BB> Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-)\<lparr>ObjMap\<rparr>) =
(\<BB> \<times>\<^sub>C op_cat \<CC>)\<lparr>Obj\<rparr>"
by (cs_concl cs_simp: cat_cs_simps)
from op_Hom have ObjMap_dom_rhs:
"\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(op_cf \<GG>-,-)\<lparr>ObjMap\<rparr>) = (\<BB> \<times>\<^sub>C op_cat \<CC>)\<lparr>Obj\<rparr>"
by (cs_concl cs_simp: cat_cs_simps)
from bf_Hom have ArrMap_dom_lhs:
"\<D>\<^sub>\<circ> (bifunctor_flip (op_cat \<CC>) \<BB> Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-)\<lparr>ArrMap\<rparr>) =
(\<BB> \<times>\<^sub>C op_cat \<CC>)\<lparr>Arr\<rparr>"
by (cs_concl cs_simp: cat_cs_simps)
from op_Hom have ArrMap_dom_rhs:
"\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(op_cf \<GG>-,-)\<lparr>ArrMap\<rparr>) = (\<BB> \<times>\<^sub>C op_cat \<CC>)\<lparr>Arr\<rparr>"
by (cs_concl cs_simp: cat_cs_simps)
show
"bifunctor_flip (op_cat \<CC>) \<BB> Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-)\<lparr>ObjMap\<rparr> =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(op_cf \<GG>-,-)\<lparr>ObjMap\<rparr>"
proof(rule vsv_eqI, unfold ObjMap_dom_lhs ObjMap_dom_rhs)
fix bc assume "bc \<in>\<^sub>\<circ> (\<BB> \<times>\<^sub>C op_cat \<CC>)\<lparr>Obj\<rparr>"
then obtain b c
where bc_def: "bc = [b, c]\<^sub>\<circ>" and b: "b \<in>\<^sub>\<circ> \<BB>\<lparr>Obj\<rparr>" and c: "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
by
(
auto
elim: cat_prod_2_ObjE[OF \<GG>.HomDom.category_axioms category_op]
simp: cat_op_simps
)
from category_axioms assms b c show
"bifunctor_flip (op_cat \<CC>) \<BB> Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-)\<lparr>ObjMap\<rparr>\<lparr>bc\<rparr> =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(op_cf \<GG>-,-)\<lparr>ObjMap\<rparr>\<lparr>bc\<rparr>"
unfolding bc_def
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros
)
qed (auto intro: cat_cs_intros)
show
"bifunctor_flip (op_cat \<CC>) \<BB> Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-)\<lparr>ArrMap\<rparr> =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(op_cf \<GG>-,-)\<lparr>ArrMap\<rparr>"
proof(rule vsv_eqI, unfold ArrMap_dom_lhs ArrMap_dom_rhs)
fix gf assume "gf \<in>\<^sub>\<circ> (\<BB> \<times>\<^sub>C op_cat \<CC>)\<lparr>Arr\<rparr>"
then obtain g f
where gf_def: "gf = [g, f]\<^sub>\<circ>" and "g \<in>\<^sub>\<circ> \<BB>\<lparr>Arr\<rparr>" and "f \<in>\<^sub>\<circ> \<CC>\<lparr>Arr\<rparr>"
by
(
auto
elim: cat_prod_2_ArrE[OF \<GG>.HomDom.category_axioms category_op]
simp: cat_op_simps
)
then obtain a b c d where g: "g : a \<mapsto>\<^bsub>\<BB>\<^esub> b" and f: "f : c \<mapsto>\<^bsub>\<CC>\<^esub> d"
by (auto intro!: is_arrI)
from category_axioms assms g f show
"bifunctor_flip (op_cat \<CC>) \<BB> Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-)\<lparr>ArrMap\<rparr>\<lparr>gf\<rparr> =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(op_cf \<GG>-,-)\<lparr>ArrMap\<rparr>\<lparr>gf\<rparr>"
unfolding gf_def
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros
)
qed (auto intro: cat_cs_intros)
qed (auto intro: cat_cs_intros simp: cat_op_simps)
lemmas [cat_cs_simps] = category.cat_bifunctor_flip_cf_rcomp_Hom
lemma (in category) cat_bifunctor_flip_cf_lcomp_Hom:
assumes "\<FF> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
shows
"bifunctor_flip (op_cat \<BB>) \<CC> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,-)) =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(-,op_cf \<FF>-)"
proof-
interpret \<FF>: is_functor \<alpha> \<BB> \<CC> \<FF> by (rule assms(1))
note Hom_\<FF> =
category.cat_bifunctor_flip_cf_rcomp_Hom
[
OF category_op is_functor_op[OF assms],
unfolded cat_op_simps,
symmetric
]
from category_axioms assms show ?thesis
by (subst Hom_\<FF>)
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros cat_op_intros
)+
qed
lemmas [cat_cs_simps] = category.cat_bifunctor_flip_cf_lcomp_Hom
subsection\<open>Projections of the \<open>Hom\<close>-functor\<close>
text\<open>
The projections of the \<open>Hom\<close>-functor coincide with the definitions
of the \<open>Hom\<close>-functor given in Chapter II-2 in \<^cite>\<open>"mac_lane_categories_2010"\<close>.
They are also exposed in the aforementioned article in
nLab \<^cite>\<open>"noauthor_nlab_nodate"\<close>\footnote{\url{
https://ncatlab.org/nlab/show/hom-functor
}}.
\<close>
subsubsection\<open>Definitions and elementary properties\<close>
definition cf_Hom_snd :: "V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V" (\<open>Hom\<^sub>O\<^sub>.\<^sub>C\<index>_'(/_,-/')\<close>)
where "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(a,-) = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<^bsub>op_cat \<CC>,\<CC>\<^esub>(a,-)\<^sub>C\<^sub>F"
definition cf_Hom_fst :: "V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V" (\<open>Hom\<^sub>O\<^sub>.\<^sub>C\<index>_'(/-,_/')\<close>)
where "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,b) = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<^bsub>op_cat \<CC>,\<CC>\<^esub>(-,b)\<^sub>C\<^sub>F"
subsubsection\<open>Projections of the \<open>Hom\<close>-functor are functors\<close>
lemma (in category) cat_cf_Hom_snd_is_functor:
assumes "a \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(a,-) : \<CC> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
proof-
from assms have a: "a \<in>\<^sub>\<circ> op_cat \<CC>\<lparr>Obj\<rparr>" unfolding cat_op_simps by simp
have op_\<CC>: "category \<alpha> (op_cat \<CC>)" by (auto intro: cat_cs_intros)
from op_\<CC> category_axioms cat_Hom_is_functor a show ?thesis
unfolding cf_Hom_snd_def by (rule bifunctor_proj_snd_is_functor)
qed
lemma (in category) cat_cf_Hom_snd_is_functor':
assumes "a \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>" and "\<beta> = \<alpha>" and "\<CC>' = \<CC>" and "\<DD>' = cat_Set \<alpha>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(a,-) : \<CC>' \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> \<DD>'"
using assms(1) unfolding assms(2-4) by (rule cat_cf_Hom_snd_is_functor)
lemmas [cat_cs_intros] = category.cat_cf_Hom_snd_is_functor'
lemma (in category) cat_cf_Hom_fst_is_functor:
assumes "b \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,b) : op_cat \<CC> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
proof-
have op_\<CC>: "category \<alpha> (op_cat \<CC>)" by (auto intro: cat_cs_intros)
from op_\<CC> category_axioms cat_Hom_is_functor assms show ?thesis
unfolding cf_Hom_fst_def by (rule bifunctor_proj_fst_is_functor)
qed
lemma (in category) cat_cf_Hom_fst_is_functor':
assumes "b \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>" and "\<beta> = \<alpha>" and "\<CC>' = op_cat \<CC>" and "\<DD>' = cat_Set \<alpha>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,b) : \<CC>' \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> \<DD>'"
using assms(1) unfolding assms(2-4) by (rule cat_cf_Hom_fst_is_functor)
lemmas [cat_cs_intros] = category.cat_cf_Hom_fst_is_functor'
subsubsection\<open>Object maps\<close>
lemma (in category) cat_cf_Hom_snd_ObjMap_vsv[cat_cs_intros]:
assumes "a \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "vsv (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(a,-)\<lparr>ObjMap\<rparr>)"
unfolding cf_Hom_snd_def
using category_axioms assms
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_op_intros
)
lemmas [cat_cs_intros] = category.cat_cf_Hom_snd_ObjMap_vsv
lemma (in category) cat_cf_Hom_fst_ObjMap_vsv[cat_cs_intros]:
assumes "b \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "vsv (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,b)\<lparr>ObjMap\<rparr>)"
unfolding cf_Hom_fst_def
using category_axioms assms
by
(
cs_concl cs_shallow
cs_simp: cat_prod_cs_simps cat_cs_simps
cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros
)
lemmas [cat_cs_intros] = category.cat_cf_Hom_fst_ObjMap_vsv
lemma (in category) cat_cf_Hom_snd_ObjMap_vdomain[cat_cs_simps]:
assumes "a \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(a,-)\<lparr>ObjMap\<rparr>) = \<CC>\<lparr>Obj\<rparr>"
using category_axioms assms
unfolding cf_Hom_snd_def
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_op_intros
)
lemmas [cat_cs_simps] = category.cat_cf_Hom_snd_ObjMap_vdomain
lemma (in category) cat_cf_Hom_fst_ObjMap_vdomain[cat_cs_simps]:
assumes "b \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,b)\<lparr>ObjMap\<rparr>) = op_cat \<CC>\<lparr>Obj\<rparr>"
using category_axioms assms
unfolding cf_Hom_fst_def
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_op_intros
)
lemmas [cat_cs_simps] = category.cat_cf_Hom_fst_ObjMap_vdomain
lemma (in category) cat_cf_Hom_snd_ObjMap_app[cat_cs_simps]:
assumes "a \<in>\<^sub>\<circ> op_cat \<CC>\<lparr>Obj\<rparr>" and "b \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(a,-)\<lparr>ObjMap\<rparr>\<lparr>b\<rparr> = Hom \<CC> a b"
proof-
from assms have ab: "[a, b]\<^sub>\<circ> \<in>\<^sub>\<circ> (op_cat \<CC> \<times>\<^sub>C \<CC>)\<lparr>Obj\<rparr>"
by (intro cat_prod_2_ObjI) (auto intro: cat_cs_intros)
show ?thesis
unfolding
cf_Hom_snd_def
bifunctor_proj_snd_ObjMap_app[OF category_op category_axioms ab]
cf_Hom_ObjMap_app[OF ab]
..
qed
lemmas [cat_cs_simps] = category.cat_cf_Hom_snd_ObjMap_app
lemma (in category) cat_cf_Hom_fst_ObjMap_app[cat_cs_simps]:
assumes "b \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>" and "a \<in>\<^sub>\<circ> op_cat \<CC>\<lparr>Obj\<rparr>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,b)\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> = Hom \<CC> a b"
proof-
from assms have ab: "[a, b]\<^sub>\<circ> \<in>\<^sub>\<circ> (op_cat \<CC> \<times>\<^sub>C \<CC>)\<lparr>Obj\<rparr>"
by (intro cat_prod_2_ObjI) (auto intro: cat_cs_intros)
show ?thesis
unfolding
cf_Hom_fst_def
bifunctor_proj_fst_ObjMap_app[OF category_op category_axioms ab]
cf_Hom_ObjMap_app[OF ab]
..
qed
lemmas [cat_cs_simps] = category.cat_cf_Hom_fst_ObjMap_app
subsubsection\<open>Arrow maps\<close>
lemma (in category) cat_cf_Hom_snd_ArrMap_vsv[cat_cs_intros]:
assumes "a \<in>\<^sub>\<circ> op_cat \<CC>\<lparr>Obj\<rparr>"
shows "vsv (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(a,-)\<lparr>ArrMap\<rparr>)"
unfolding cf_Hom_snd_def
using category_axioms assms
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps
cs_intro: bifunctor_proj_snd_ArrMap_vsv cat_cs_intros cat_op_intros
)
lemmas [cat_cs_intros] = category.cat_cf_Hom_snd_ArrMap_vsv
lemma (in category) cat_cf_Hom_fst_ArrMap_vsv[cat_cs_intros]:
assumes "b \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "vsv (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,b)\<lparr>ArrMap\<rparr>)"
unfolding cf_Hom_fst_def
using category_axioms assms
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps
cs_intro: bifunctor_proj_fst_ArrMap_vsv cat_cs_intros cat_op_intros
)
lemmas [cat_cs_intros] = category.cat_cf_Hom_fst_ArrMap_vsv
lemma (in category) cat_cf_Hom_snd_ArrMap_vdomain[cat_cs_simps]:
assumes "a \<in>\<^sub>\<circ> op_cat \<CC>\<lparr>Obj\<rparr>"
shows "\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(a,-)\<lparr>ArrMap\<rparr>) = \<CC>\<lparr>Arr\<rparr>"
using category_axioms assms
unfolding cf_Hom_snd_def
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_op_intros
)
lemmas [cat_cs_simps] = category.cat_cf_Hom_snd_ArrMap_vdomain
lemma (in category) cat_cf_Hom_fst_ArrMap_vdomain[cat_cs_simps]:
assumes "b \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,b)\<lparr>ArrMap\<rparr>) = op_cat \<CC>\<lparr>Arr\<rparr>"
using category_axioms assms
unfolding cf_Hom_fst_def
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_op_intros
)
lemmas [cat_cs_simps] = category.cat_cf_Hom_fst_ArrMap_vdomain
lemma (in category) cat_cf_Hom_snd_ArrMap_app[cat_cs_simps]:
assumes "a \<in>\<^sub>\<circ> op_cat \<CC>\<lparr>Obj\<rparr>" and "f : b \<mapsto>\<^bsub>\<CC>\<^esub> b'"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(a,-)\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> = cf_hom \<CC> [op_cat \<CC>\<lparr>CId\<rparr>\<lparr>a\<rparr>, f]\<^sub>\<circ>"
proof-
from assms(2) have f: "f \<in>\<^sub>\<circ> \<CC>\<lparr>Arr\<rparr>" by (simp add: cat_cs_intros)
from category_axioms assms show ?thesis
unfolding
cf_Hom_snd_def
bifunctor_proj_snd_ArrMap_app[OF category_op category_axioms assms(1) f]
cat_op_simps
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps
cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros
)
qed
lemmas [cat_cs_simps] = category.cat_cf_Hom_snd_ArrMap_app
lemma (in category) cat_cf_Hom_fst_ArrMap_app[cat_cs_simps]:
assumes "b \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>" and "f : a \<mapsto>\<^bsub>op_cat \<CC>\<^esub> a'"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,b)\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> = cf_hom \<CC> [f, \<CC>\<lparr>CId\<rparr>\<lparr>b\<rparr>]\<^sub>\<circ>"
proof-
from assms(2) have f: "f \<in>\<^sub>\<circ> op_cat \<CC>\<lparr>Arr\<rparr>" by (simp add: cat_cs_intros)
with category_axioms assms show ?thesis
unfolding
cf_Hom_fst_def
bifunctor_proj_fst_ArrMap_app[OF category_op category_axioms assms(1) f]
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps
cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros
)
qed
lemmas [cat_cs_simps] = category.cat_cf_Hom_fst_ArrMap_app
subsubsection\<open>Opposite \<open>Hom\<close>-functor projections\<close>
lemma (in category) cat_op_cat_cf_Hom_snd:
assumes "a \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(a,-) = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,a)"
proof(rule cf_eqI[of \<alpha>])
from assms category_axioms show
"Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(a,-) : op_cat \<CC> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros cat_op_intros
)
from assms category_axioms show
"Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,a) : op_cat \<CC> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros cat_op_intros
)
show "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(a,-)\<lparr>ObjMap\<rparr> = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,a)\<lparr>ObjMap\<rparr>"
proof(rule vsv_eqI)
from assms category_axioms show "vsv (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(a,-)\<lparr>ObjMap\<rparr>)"
by (intro is_functor.cf_ObjMap_vsv)
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros cat_op_intros
)
from assms category_axioms show "vsv (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,a)\<lparr>ObjMap\<rparr>)"
by (intro is_functor.cf_ObjMap_vsv)
(cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)
from assms category_axioms show
"\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(a,-)\<lparr>ObjMap\<rparr>) = \<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,a)\<lparr>ObjMap\<rparr>)"
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros cat_op_intros
)
show "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(a,-)\<lparr>ObjMap\<rparr>\<lparr>b\<rparr> = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,a)\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
if "b \<in>\<^sub>\<circ> \<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(a,-)\<lparr>ObjMap\<rparr>)" for b
proof-
from that have "b \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
by
(
simp add:
category.cat_cf_Hom_snd_ObjMap_vdomain[
OF category_op, unfolded cat_op_simps, OF assms
]
)
from category_axioms assms this show ?thesis
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps cs_intro: cat_op_intros
)
qed
qed
show "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(a,-)\<lparr>ArrMap\<rparr> = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,a)\<lparr>ArrMap\<rparr>"
proof(rule vsv_eqI)
from assms category_axioms show "vsv (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(a,-)\<lparr>ArrMap\<rparr>)"
by (intro is_functor.cf_ArrMap_vsv)
(cs_concl cs_shallow cs_intro: cat_cs_intros cat_op_intros)
from assms category_axioms show "vsv (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,a)\<lparr>ArrMap\<rparr>)"
by (intro is_functor.cf_ArrMap_vsv)
(cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)
from assms category_axioms show
"\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(a,-)\<lparr>ArrMap\<rparr>) = \<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,a)\<lparr>ArrMap\<rparr>)"
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps cs_intro: cat_op_intros
)
show "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(a,-)\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,a)\<lparr>ArrMap\<rparr>\<lparr>f\<rparr>"
if "f \<in>\<^sub>\<circ> \<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(a,-)\<lparr>ArrMap\<rparr>)" for f
proof-
from that have "f \<in>\<^sub>\<circ> \<CC>\<lparr>Arr\<rparr>"
by
(
simp add:
category.cat_cf_Hom_snd_ArrMap_vdomain[
OF category_op, unfolded cat_op_simps, OF assms
]
)
then obtain a b where "f : a \<mapsto>\<^bsub>\<CC>\<^esub> b" by auto
from category_axioms assms this show ?thesis
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros cat_op_intros
)
qed
qed
qed simp_all
lemmas [cat_op_simps] = category.cat_op_cat_cf_Hom_snd
lemma (in category) cat_op_cat_cf_Hom_fst:
assumes "a \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<CC>(-,a) = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(a,-)"
proof-
from assms have a: "a \<in>\<^sub>\<circ> op_cat \<CC>\<lparr>Obj\<rparr>" unfolding cat_op_simps .
have "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(a,-) = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat (op_cat \<CC>)(a,-)"
unfolding cat_op_simps ..
also have "\<dots> = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>(op_cat \<CC>)(-,a)"
unfolding category.cat_op_cat_cf_Hom_snd[OF category_op a] by simp
finally show "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>(op_cat \<CC>)(-,a) = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(a,-)" by simp
qed
lemmas [cat_op_simps] = category.cat_op_cat_cf_Hom_fst
subsubsection\<open>\<open>Hom\<close>-functors are injections on objects\<close>
lemma (in category) cat_cf_Hom_snd_inj:
assumes "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(a,-) = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(b,-)"
and "a \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
and "b \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "a = b"
proof(rule ccontr)
assume prems: "a \<noteq> b"
from assms(1) have "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(a,-)\<lparr>ObjMap\<rparr>\<lparr>b\<rparr> = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(b,-)\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
by simp
then have "Hom \<CC> a b = Hom \<CC> b b"
unfolding
cat_cf_Hom_snd_ObjMap_app[unfolded cat_op_simps, OF assms(2,3)]
cat_cf_Hom_snd_ObjMap_app[unfolded cat_op_simps, OF assms(3,3)]
by simp
with assms prems show False by (force intro: cat_cs_intros)
qed
lemma (in category) cat_cf_Hom_fst_inj:
assumes "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,a) = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,b)" and "a \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>" and "b \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "a = b"
proof(rule ccontr)
assume prems: "a \<noteq> b"
from assms(1) have "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,a)\<lparr>ObjMap\<rparr>\<lparr>b\<rparr> = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,b)\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
by simp
then have "Hom \<CC> b a = Hom \<CC> b b"
unfolding
cat_cf_Hom_fst_ObjMap_app[unfolded cat_op_simps, OF assms(2,3)]
cat_cf_Hom_fst_ObjMap_app[unfolded cat_op_simps, OF assms(3,3)]
by simp
with assms prems show False by (force intro: cat_cs_intros)
qed
subsubsection\<open>\<open>Hom\<close>-functor is an array bifunctor\<close>
lemma (in category) cat_cf_Hom_is_cf_array:
\<comment>\<open>See Chapter II-3 in \cite{mac_lane_categories_2010}.\<close>
"Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-) =
cf_array (op_cat \<CC>) \<CC> (cat_Set \<alpha>) (cf_Hom_fst \<alpha> \<CC>) (cf_Hom_snd \<alpha> \<CC>)"
proof(rule cf_eqI[of \<alpha>])
show "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-) : op_cat \<CC> \<times>\<^sub>C \<CC> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
by (rule cat_Hom_is_functor)
have c1: "category \<alpha> (op_cat \<CC>)" by (auto intro: cat_cs_intros)
have c2: "category \<alpha> \<CC>" by (auto intro: cat_cs_intros)
have c3: "category \<alpha> (cat_Set \<alpha>)" by (simp add: category_cat_Set)
have c4: "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,c) : op_cat \<CC> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
if "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>" for c
using that by (rule cat_cf_Hom_fst_is_functor)
have c5: "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(b,-) : \<CC> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
if "b \<in>\<^sub>\<circ> op_cat \<CC>\<lparr>Obj\<rparr>" for b
using that unfolding cat_op_simps by (rule cat_cf_Hom_snd_is_functor)
have c6: "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(b,-)\<lparr>ObjMap\<rparr>\<lparr>c\<rparr> = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,c)\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
if "b \<in>\<^sub>\<circ> op_cat \<CC>\<lparr>Obj\<rparr>" and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>" for b c
using that category_axioms
by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)
have c7:
"Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(b',-)\<lparr>ArrMap\<rparr>\<lparr>g\<rparr> \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub> Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,c)\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,c' )\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub> Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(b,- )\<lparr>ArrMap\<rparr>\<lparr>g\<rparr>"
if "f : b \<mapsto>\<^bsub>op_cat \<CC>\<^esub> b'" and "g : c \<mapsto>\<^bsub>\<CC>\<^esub> c'" for b c b' c' f g
using that category_axioms
unfolding cat_op_simps
by
(
cs_concl
cs_simp: cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros cat_op_intros
)
let ?cfa =
\<open>cf_array (op_cat \<CC>) \<CC> (cat_Set \<alpha>) (cf_Hom_fst \<alpha> \<CC>) (cf_Hom_snd \<alpha> \<CC>)\<close>
note cf_array_specification =
cf_array_specification[OF c1 c2 c3 c4 c5 c6 c7, simplified]
from c1 c2 c3 c4 c5 c6 c7 show "?cfa : op_cat \<CC> \<times>\<^sub>C \<CC> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
by (rule cf_array_is_functor)
show "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ObjMap\<rparr> = ?cfa\<lparr>ObjMap\<rparr>"
proof(rule vsv_eqI, unfold cat_cs_simps)
fix aa' assume "aa' \<in>\<^sub>\<circ> (op_cat \<CC> \<times>\<^sub>C \<CC>)\<lparr>Obj\<rparr>"
then obtain a a'
where aa'_def: "aa' = [a, a']\<^sub>\<circ>"
and a: "a \<in>\<^sub>\<circ> op_cat \<CC>\<lparr>Obj\<rparr>"
and a': "a' \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
by (elim cat_prod_2_ObjE[OF c1 c2])
from category_axioms a a' show
"Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ObjMap\<rparr>\<lparr>aa'\<rparr> = ?cfa\<lparr>ObjMap\<rparr>\<lparr>aa'\<rparr>"
unfolding aa'_def cf_array_specification(2)[OF a a'] cat_op_simps
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cs_intro: cat_op_intros cat_prod_cs_intros
)
qed (auto simp: cf_array_ObjMap_vsv cf_Hom_ObjMap_vsv cat_cs_simps)
show "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,-)\<lparr>ArrMap\<rparr> = ?cfa\<lparr>ArrMap\<rparr>"
proof(rule vsv_eqI, unfold cat_cs_simps)
fix ff' assume "ff' \<in>\<^sub>\<circ> (op_cat \<CC> \<times>\<^sub>C \<CC>)\<lparr>Arr\<rparr>"
then obtain f f'
where ff'_def: "ff' = [f, f']\<^sub>\<circ>"
and f: "f \<in>\<^sub>\<circ> op_cat \<CC>\<lparr>Arr\<rparr>"
and f': "f' \<in>\<^sub>\<circ> \<CC>\<lparr>Arr\<rparr>"
by (elim cat_prod_2_ArrE[OF c1 c2])
then obtain a b a' b'
where f: "f : a \<mapsto>\<^bsub>op_cat \<CC>\<^esub> b" and f': "f' : a' \<mapsto>\<^bsub>\<CC>\<^esub> b'"
by (blast intro: is_arrI)
from category_axioms f f' show "cf_hom \<CC> ff' = ?cfa\<lparr>ArrMap\<rparr>\<lparr>ff'\<rparr>"
unfolding ff'_def cat_op_simps
by
(
cs_concl
cs_simp: cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros cat_op_intros
)
qed (auto simp: cf_array_ArrMap_vsv cf_Hom_ArrMap_vsv cat_cs_simps)
qed simp_all
subsubsection\<open>
Projections of the compositions of a \<open>Hom\<close>-functor and a functor are
projections of the \<open>Hom\<close>-functor
\<close>
lemma (in category) cat_cf_rcomp_Hom_cf_Hom_snd:
assumes "\<GG> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>" and "a \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<GG>-)\<^bsub>op_cat \<CC>,\<BB>\<^esub>(a,-)\<^sub>C\<^sub>F = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(a,-) \<circ>\<^sub>C\<^sub>F \<GG>"
using category_axioms assms
unfolding cf_rcomp_Hom_def cf_Hom_snd_def
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_op_intros
)
lemmas [cat_cs_simps] = category.cat_cf_rcomp_Hom_cf_Hom_snd
lemma (in category) cat_cf_lcomp_Hom_cf_Hom_snd:
assumes "\<FF> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>" and "b \<in>\<^sub>\<circ> \<BB>\<lparr>Obj\<rparr>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>-,-)\<^bsub>op_cat \<BB>,\<CC>\<^esub>(b,-)\<^sub>C\<^sub>F = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(\<FF>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>,-)"
using category_axioms assms
unfolding cf_lcomp_Hom_def cf_Hom_snd_def
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_op_intros
)
lemmas [cat_cs_simps] = category.cat_cf_lcomp_Hom_cf_Hom_snd
lemma (in category) cat_cf_rcomp_Hom_cf_Hom_fst:
assumes "\<FF> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>" and "b \<in>\<^sub>\<circ> \<BB>\<lparr>Obj\<rparr>"
shows "Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>-)\<^bsub>op_cat \<CC>,\<BB>\<^esub>(-,b)\<^sub>C\<^sub>F = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)"
proof-
from category_axioms assms have H\<FF>b:
"Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>-)\<^bsub>op_cat \<CC>,\<BB>\<^esub>(-,b)\<^sub>C\<^sub>F : op_cat \<CC> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
by (cs_concl cs_intro: cat_cs_intros)
from category_axioms assms have H\<FF>b':
"Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>) : op_cat \<CC> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
by (cs_concl cs_intro: cat_cs_intros)
from category_axioms assms have [cat_cs_simps]:
"\<D>\<^sub>\<circ> ((Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>-)\<^bsub>op_cat \<CC>,\<BB>\<^esub>(-,b)\<^sub>C\<^sub>F)\<lparr>ObjMap\<rparr>) = op_cat \<CC>\<lparr>Obj\<rparr>"
by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_op_intros)+
from category_axioms assms have [cat_cs_simps]:
"\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)\<lparr>ObjMap\<rparr>) = op_cat \<CC>\<lparr>Obj\<rparr>"
by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros)
from category_axioms assms have [cat_cs_simps]:
"\<D>\<^sub>\<circ> ((Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>-)\<^bsub>op_cat \<CC>,\<BB>\<^esub>(-,b)\<^sub>C\<^sub>F)\<lparr>ArrMap\<rparr>) = op_cat \<CC>\<lparr>Arr\<rparr>"
by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_op_intros)+
from category_axioms assms have [cat_cs_simps]:
"\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)\<lparr>ArrMap\<rparr>) = op_cat \<CC>\<lparr>Arr\<rparr>"
by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros)
show ?thesis
proof(rule cf_eqI[OF H\<FF>b H\<FF>b'])
show
"(Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>-)\<^bsub>op_cat \<CC>,\<BB>\<^esub>(-,b)\<^sub>C\<^sub>F)\<lparr>ObjMap\<rparr> =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)\<lparr>ObjMap\<rparr>"
proof(rule vsv_eqI, unfold cat_cs_simps)
from category_axioms assms show
"vsv ((Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>-)\<^bsub>op_cat \<CC>,\<BB>\<^esub>(-,b)\<^sub>C\<^sub>F)\<lparr>ObjMap\<rparr>)"
by (intro bifunctor_proj_fst_ObjMap_vsv[of \<alpha>])
(cs_concl cs_intro: cat_cs_intros)+
from assms show "vsv (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)\<lparr>ObjMap\<rparr>)"
by (intro cat_cf_Hom_fst_ObjMap_vsv)
(cs_concl cs_intro: cat_cs_intros)+
fix a assume prems: "a \<in>\<^sub>\<circ> op_cat \<CC>\<lparr>Obj\<rparr>"
with category_axioms assms show
"(Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>-)\<^bsub>op_cat \<CC>,\<BB>\<^esub>(-,b)\<^sub>C\<^sub>F)\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
by
(
cs_concl
cs_simp: cat_cs_simps
cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros
)
qed simp
show
"(Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>-)\<^bsub>op_cat \<CC>,\<BB>\<^esub>(-,b)\<^sub>C\<^sub>F)\<lparr>ArrMap\<rparr> =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)\<lparr>ArrMap\<rparr>"
proof(rule vsv_eqI, unfold cat_cs_simps cat_op_simps)
from category_axioms assms show
"vsv ((Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>-)\<^bsub>op_cat \<CC>,\<BB>\<^esub>(-,b)\<^sub>C\<^sub>F)\<lparr>ArrMap\<rparr>)"
by (intro bifunctor_proj_fst_ArrMap_vsv[of \<alpha>])
(cs_concl cs_intro: cat_cs_intros)+
from assms show "vsv (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)\<lparr>ArrMap\<rparr>)"
by (intro cat_cf_Hom_fst_ArrMap_vsv)
(cs_concl cs_intro: cat_cs_intros)+
fix f assume "f \<in>\<^sub>\<circ> \<CC>\<lparr>Arr\<rparr>"
then obtain a' b' where "f : a' \<mapsto>\<^bsub>\<CC>\<^esub> b'" by (auto simp: cat_op_simps)
from category_axioms assms this show
"(Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>-)\<^bsub>op_cat \<CC>,\<BB>\<^esub>(-,b)\<^sub>C\<^sub>F)\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(-,\<FF>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)\<lparr>ArrMap\<rparr>\<lparr>f\<rparr>"
by
(
cs_concl
cs_simp: cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros
)
qed simp
qed simp_all
qed
lemmas [cat_cs_simps] = category.cat_cf_rcomp_Hom_cf_Hom_fst
text\<open>\newpage\<close>
end
|
(* https://coq.github.io/doc/master/stdlib/Coq.Unicode.Utf8_core.html *)
Require Import Unicode.Utf8_core.
Inductive day : Type :=
| monday : day
| tuesday : day
| wednesday : day
| thursday : day
| friday : day
| saturday : day
| sunday : day.
Inductive month: Type :=
| Jan : month.
Definition next_weekday (d: day): day :=
match d with
| monday => tuesday
| tuesday => wednesday
| wednesday => thursday
| thursday => friday
| friday => monday
| saturday => monday
| sunday => monday
end.
Compute next_weekday monday.
Eval simpl in (next_weekday friday).
Eval simpl in (next_weekday (next_weekday saturday)).
Example test_next_weekday:
(next_weekday (next_weekday saturday)) = tuesday.
Proof.
simpl. reflexivity.
Qed.
Inductive bool: Type :=
| true : bool
| false : bool.
Definition negb (b:bool): bool :=
match b with
| true => false
| false => true
end.
Definition andb (b1 b2 : bool) : bool :=
match b1 with
| true => b2
| false => false
end.
Definition orb (b1 b2 : bool) : bool :=
match b1 with
| true => true
| false => b2
end.
Example test_orb1: (orb true false) = true.
Proof. simpl. reflexivity. Qed.
Example test_orb2: (orb false false) = false.
Proof. simpl. reflexivity. Qed.
Example test_orb3: (orb false true) = true.
Proof. simpl. reflexivity. Qed.
Example test_orb4: (orb true false) = true.
Proof. simpl. reflexivity. Qed.
Definition admit {T: Type} : T. Admitted.
Check admit.
Definition nandb (b1 b2: bool) : bool :=
admit.
Example test_nandb1: (nandb true false) = true.
Admitted.
Example test_nandb2: (nandb false false) = true.
Admitted.
Example test_nandb3: (nandb false true) = true.
Admitted.
Example test_nandb4: (nandb true true) = false.
Admitted.
Definition andb3 (b1:bool) (b2:bool) (b3:bool) : bool :=
admit.
Example test_andb31: (andb3 true true true) = true.
Admitted.
Example test_andb32: (andb3 false true true) = false.
Admitted.
Example test_andb33: (andb3 true false true) = false.
Admitted.
Example test_andb34: (andb3 true true false) = false.
Admitted.
(* Checkで型を確認 *)
Check (negb true).
Check negb.
Check admit.
Module Playground1.
Inductive nat: Type :=
| O : nat
| S : nat -> nat.
End Playground1.
Definition minustwo (n: nat): nat :=
match n with
| O => O
| S O => O
| S (S n') => n'
end.
Check S (S (S (S O))).
Eval simpl in (minustwo 4).
Check S.
Check pred.
Check minustwo.
Fixpoint evenb (n: nat): bool :=
match n with
| O => true
| S O => false
| S (S n') => evenb n'
end.
(* Definition oddb (n: nat): nat := negb (evenb n). *)
(* 型推論すげー *)
Definition oddb n := negb (evenb n).
Example test_oddb1: (oddb (S O)) = true.
Proof. simpl. reflexivity. Qed.
Example test_oddb2: (oddb (S (S (S (S O))))) = false.
Proof. simpl. reflexivity. Qed.
Module Playground2.
Fixpoint plus n m : nat :=
match n with
| O => m
| S n' => S (plus n' m)
end.
Eval simpl in (plus (S (S (S O))) (S (S O))).
Check plus.
Fixpoint mult n m : nat :=
match n with
| O => O
| S n' => plus m (mult n' m)
end.
Fixpoint minus n m : nat :=
match n, m with
| O, _ => O
| S _, O => n
| S n', S m' => minus n' m'
end.
End Playground2.
Fixpoint exp (base power : nat) : nat :=
match power with
| O => S O
| S p => mult base (exp base p)
end.
Example test_mult1: mult 3 3 = 9.
Proof. simpl. reflexivity. Qed.
Fixpoint factorial (n:nat) : nat :=
match n with
| O => S O
| S n' => mult n (factorial n')
end.
Example test_factorial1: (factorial 3) = 6.
Proof. auto. Qed.
Example test_factorial2: (factorial 5) = (mult 10 12).
Proof. auto. Qed.
Notation "x + y" := (plus x y) (at level 50, left associativity) : nat_scope.
Notation "x - y" := (minus x y) (at level 50, left associativity) : nat_scope.
Notation "x * y" := (mult x y) (at level 40, left associativity) : nat_scope.
Check ((0 + 1) + 1).
Check Type.
Check nat.
Check Set.
Compute (nat*nat)%type.
Fixpoint beq_nat (n m : nat) : bool :=
match n with
| O => match m with
| O => true
| S m' => false
end
| S n' => match m with
| O => false
| S m' => beq_nat n' m'
end
end.
Fixpoint ble_nat (n m : nat) : bool :=
match n with
| O => true
| S n' =>
match m with
| O => false
| S m' => ble_nat n' m'
end
end.
Example test_ble_nat1: (ble_nat 2 2) = true.
Proof. simpl. reflexivity. Qed.
Example test_ble_nat2: (ble_nat 2 4) = true.
Proof. simpl. reflexivity. Qed.
Example test_ble_nat3: (ble_nat 4 2) = false.
Proof. simpl. reflexivity. Qed.
Fixpoint blt_nat (n m : nat) : bool :=
match n with
| O =>
match m with
| O => false
| _ => true
end
| S n' =>
match m with
| O => false
| S m' => blt_nat n' m'
end
end.
Example test_blt_nat1: (blt_nat 2 2) = false.
Proof. auto. Qed.
Example test_blt_nat2: (blt_nat 2 4) = true.
Proof. auto. Qed.
Example test_blt_nat3: (blt_nat 4 2) = false.
Proof. auto. Qed.
Theorem plus_O_n' : forall n:nat, 0 + n = n.
Proof.
reflexivity. Qed.
Eval simpl in (forall n:nat, n + 0 = n).
Eval simpl in (forall n:nat, 0 + n = n).
Theorem plus_O_n'' : forall n:nat, 0 + n = n.
Proof.
intros n. reflexivity. Qed.
Theorem plus_1_l : forall n:nat, 1 + n = S n.
Proof.
intros n.
Info 3 reflexivity. Qed.
Theorem mult_0_l : forall n:nat, 0 * n = 0.
Proof.
intros n. reflexivity. Qed.
Theorem plus_id_example: forall n m : nat,
n = m -> n + n = m + m.
Proof.
intros n m.
intros H.
rewrite -> H.
reflexivity.
Qed.
(* 練習問題 x *)
Theorem plus_id_exercise : ∀ n m o : nat,
n = m → m = o → n + m = m + o.
Proof.
intros.
rewrite H.
rewrite H0.
reflexivity.
Qed.
Theorem mult_0_plus : ∀ n m : nat,
(0 + n) * m = n * m.
Proof.
intros n m.
rewrite -> plus_O_n.
reflexivity. Qed.
(* 練習問題 xx *)
Theorem mult_1_plus : ∀ n m : nat,
(1 + n) * m = m + (n * m).
Proof.
intros.
simpl.
reflexivity.
Qed.
Theorem plus_1_neq_0 : ∀ n : nat,
beq_nat (n + 1) 0 = false.
Proof.
intros n. simpl.
(* destruct n as [| n']. *) (* as いらなさそうだよね *)
destruct n.
simpl. reflexivity.
simpl.
(*
なぜ beq_nat (plus n (S 0)) 0 だと簡約化できなくて,
beq_nat (plus (S n) (S 0)) 0 だと簡約化できたのか.
S だとわかっているから,
S (plus S n (S 0)) へと simplify されます
beq_nat の match にひっかかります,ってかんじか
*)
reflexivity.
Qed.
Theorem negb_involutive : ∀ b : bool,
negb (negb b) = b.
Proof.
intros b. destruct b.
reflexivity.
reflexivity. Qed.
Theorem zero_nbeq_plus_1 : ∀ n : nat,
beq_nat 0 (n + 1) = false.
Proof.
intros.
simpl.
destruct n.
reflexivity.
reflexivity.
Qed.
Require String. Open Scope string_scope.
Ltac move_to_top x :=
match reverse goal with
| H : _ |- _ => try move x after H
end.
Tactic Notation "assert_eq" ident(x) constr(v) :=
let H := fresh in
assert (x = v) as H by reflexivity;
clear H.
Tactic Notation "Case_aux" ident(x) constr(name) :=
first [
set (x := name); move_to_top x
| assert_eq x name; move_to_top x
| fail 1 "because we are working on a different case" ].
Tactic Notation "Case" constr(name) := Case_aux Case name.
Tactic Notation "SCase" constr(name) := Case_aux SCase name.
Tactic Notation "SSCase" constr(name) := Case_aux SSCase name.
Tactic Notation "SSSCase" constr(name) := Case_aux SSSCase name.
Tactic Notation "SSSSCase" constr(name) := Case_aux SSSSCase name.
Tactic Notation "SSSSSCase" constr(name) := Case_aux SSSSSCase name.
Tactic Notation "SSSSSSCase" constr(name) := Case_aux SSSSSSCase name.
Tactic Notation "SSSSSSSCase" constr(name) := Case_aux SSSSSSSCase name.
Theorem andb_true_elim1 : ∀ b c : bool,
andb b c = true → b = true.
Proof.
intros b c H.
destruct b.
- (* b = fales *)
reflexivity.
- (* b = false *)
rewrite <- H.
simpl. reflexivity. Qed.
(* TODO : う, Case なんか使えない *)
Theorem andb_true_elim2 : ∀ b c : bool,
andb b c = true → c = true.
Proof.
intros.
destruct c.
- (* c = true *)
reflexivity.
- (* c = false *)
rewrite <- H.
destruct b.
-- (* b = true *)
simpl. reflexivity.
-- (* b = false *)
simpl. reflexivity.
Qed.
Theorem plus_0_r: ∀ n:nat,
n + 0 = n.
Proof.
intros n. induction n as [| n'].
-
simpl. reflexivity.
-
simpl. rewrite IHn'. reflexivity.
Qed.
Theorem minus_diag : ∀ n,
minus n n = 0.
Proof.
intros n. induction n as [| n'].
-
simpl. reflexivity.
-
simpl. rewrite -> IHn'. reflexivity. Qed.
(* 練習問題 xx -- *)
Theorem mult_0_r : ∀ n:nat,
n * 0 = 0.
Proof.
intros. induction n.
-
reflexivity.
-
Print Nat.mul.
simpl. trivial.
Qed.
Theorem plus_n_Sm : ∀ n m : nat,
S (n + m) = n + (S m).
Proof.
intros.
induction n.
- auto.
- auto.
Qed.
Theorem plus_comm : ∀ n m : nat,
n + m = m + n.
Proof.
intros.
induction n.
-
auto.
-
simpl. rewrite IHn.
induction m.
--
auto.
--
auto.
Qed.
(* -- *)
Fixpoint double (n:nat) :=
match n with
| O => O
| S n' => S (S (double n'))
end.
(* 練習問題 xx *)
Lemma double_plus : ∀ n, double n = n + n .
Proof.
intros.
induction n.
-
trivial.
-
simpl. rewrite IHn.
Print plus_comm.
specialize (plus_comm n (S n)).
intro. rewrite H. simpl.
reflexivity.
Qed.
(*
練習問題: ★ (destruct_induction)
destructとinductionの違いを短く説明しなさい。
*)
(*
場合分けと帰納法 ?
destruct x.
は, x : A だとしたら,
Inductive A :=
| なんとか1 : A
| なんとか2 : A.
みたいに定義されているものについて,どの定義の形をしているか,を分ける.
induction x.
は, x : A だとしたら,
Inductive A :=
| O : A
| S O : A -> A.
みたいに定義されているとしたら,
もとのゴールが forall x:A, P x.
だとしたら,
P 0 /\ (forall n:A, P n -> P (S n)) を導出して,もとのゴールを示す.
*)
(* CoqIDE おちてデータ少し飛んだ,いいや *)
Theorem plus_assoc : forall n m p : nat,
(n + m) + p = n + (m + p).
Proof.
intros.
induction n.
trivial.
simpl.
rewrite IHn.
reflexivity.
Qed.
Theorem plus_swap' : ∀ n m p : nat,
n + (m + p) = m + (n + p).
Proof.
intros n m p.
rewrite <- plus_assoc.
rewrite <- plus_assoc.
Admitted.
|
function Y = sptenrand(sz,nz)
%SPTENRAND Sparse uniformly distributed random tensor.
%
% R = SPTENRAND(sz,density) creates a random sparse tensor of the
% specified sz with approximately density*prod(sz) nonzero
% entries.
%
% R = SPTENRAND(sz,nz) creates a random sparse tensor of the
% specified sz with approximately nz nonzero entries.
%
% Example: R = sptenrand([5 4 2],12);
%
% See also SPTENSOR, TENRAND, RAND.
%
%MATLAB Tensor Toolbox.
%Copyright 2012, Sandia Corporation.
% This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others.
% http://www.sandia.gov/~tgkolda/TensorToolbox.
% Copyright (2012) Sandia Corporation. Under the terms of Contract
% DE-AC04-94AL85000, there is a non-exclusive license for use of this
% work by or on behalf of the U.S. Government. Export of this data may
% require a license from the United States Government.
% The full license terms can be found in the file LICENSE.txt
% Error check on siz
if ndims(sz) ~= 2 || size(sz,1) ~= 1
error('Size must be a row vector');
end
% Error check on nz
if ~exist('nz','var') || (nz < 0)
error('2nd argument must be positive');
end
% Is nz an number or a fraction? Ultimately want a number.
if (nz < 1)
nz = prod(sz) * nz;
end
% Make sure nz is an integer
nz = ceil(nz);
% Keep iterating until we find enough unique nonzeros or we
% give up
subs = [];
cnt = 0;
while (size(subs,1) < nz) && (cnt < 10)
subs = ceil( rand(nz, size(sz,2)) * diag(sz) );
subs = unique(subs, 'rows');
cnt = cnt + 1;
end
% Extract nnz subscipts and create a corresponding list of
% values
nz = min(nz, size(subs,1));
subs = subs(1:nz,:);
vals = rand(nz,1);
Y = sptensor(subs,vals,sz);
return;
|
The fleet remained in captivity during the negotiations that ultimately produced the Treaty of Versailles . Von Reuter believed that the British intended to seize the German ships on 21 June 1919 , which was the deadline for Germany to have signed the peace treaty . Unaware that the deadline had been extended to the 23rd , Reuter ordered the ships to be sunk at the first opportunity . On the morning of 21 June , the British fleet left Scapa Flow to conduct training maneuvers , and at 11 : 20 Reuter transmitted the order to his ships . Markgraf sank at 16 : 45 . The British soldiers in the guard detail panicked in their attempt to prevent the Germans from scuttling the ships ; they shot and killed Markgraf 's captain , Walter Schumann , who was in a lifeboat , and an enlisted man . In total , the guards killed nine Germans and wounded twenty @-@ one . The remaining crews , totaling some 1 @,@ 860 officers and enlisted men , were imprisoned .
|
||| Implementation of ordering relations for `Nat`ural numbers
module Data.Nat.Order
import Data.Nat
import Data.Fun
import Data.Rel
import Decidable.Decidable
%default total
public export
zeroNeverGreater : Not (LTE (S n) Z)
zeroNeverGreater LTEZero impossible
zeroNeverGreater (LTESucc _) impossible
public export
zeroAlwaysSmaller : {n : Nat} -> LTE Z n
zeroAlwaysSmaller = LTEZero
public export
ltesuccinjective : {0 n, m : Nat} -> Not (LTE n m) -> Not (LTE (S n) (S m))
ltesuccinjective disprf (LTESucc nLTEm) = void (disprf nLTEm)
ltesuccinjective disprf LTEZero impossible
-- Remove any time after release of 0.6.0
||| Deprecated. Use `Nat.isLTE`.
public export
decideLTE : (n : Nat) -> (m : Nat) -> Dec (LTE n m)
decideLTE = isLTE
public export
Decidable 2 [Nat,Nat] LTE where
decide = decideLTE
public export
Decidable 2 [Nat,Nat] LT where
decide m = decideLTE (S m)
public export
lte : (m : Nat) -> (n : Nat) -> Dec (LTE m n)
lte m n = decide {ts = [Nat,Nat]} {p = LTE} m n
public export
shift : (m : Nat) -> (n : Nat) -> LTE m n -> LTE (S m) (S n)
shift m n mLTEn = LTESucc mLTEn
|
## Computing a running variance the smart way
Suppose we compute the running mean of a list of numbers $x_1,\,x_2,\,...,x_p,...$ when the $p^{th}$ number $x_p$ arrives the *smart way* (as shown above)
\begin{equation}
h_{p}^{\text{ave}} = \frac{p-1}{p}h_{p-1}^{\text{ave}} + \frac{1}{p}x_p
\end{equation}
and then - on top of this - we would like to compute the *running variance* of our ever-increasing list of numbers. If we used the standard formula for variance we would compute
\begin{equation}
h_p^{\text{var}} = \frac{1}{p}\sum_{j=1}^p\left(x_j - h_p^{\text{ave}}\right)^2
\end{equation}
each time a new point $x_p$ arrived. However computing the running variance this way would be wasteful - both in terms of storage (we would need to store all of the previous input points) and computation (we're repeating the same sorts of computation over and over again) - in complete analogy to the use of the standard formula when computing the running mean (as we saw above).
Multiplying both sides of Equation (2) by $p$ we have
\begin{equation}
p\,h_p^{\text{var}} = \sum_{j=1}^p\left(x_j - h_p^{\text{ave}}\right)^2
\end{equation}
Plugging in $p-1$ in place of $p$ in the Equation above yields
\begin{equation}
\left(p-1\right)\,h_{p-1}^{\text{var}} = \sum_{j=1}^{p-1}\left(x_j - h_{p-1}^{\text{ave}}\right)^2
\end{equation}
Subtracting (4) from (3), and simple re-arrangement of terms gives
\begin{equation}
\begin{split}
p\,h_p^{\text{var}} - \left(p-1\right)\,h_{p-1}^{\text{var}} & = \sum_{j=1}^p\left(x_j - h_p^{\text{ave}}\right)^2 - \sum_{j=1}^{p-1}\left(x_j - h_{p-1}^{\text{ave}}\right)^2 \\
& = \left[\left(x_p - h_p^{\text{ave}}\right)^2 + \sum_{j=1}^{p-1}\left(x_j - h_p^{\text{ave}}\right)^2 \right] - \sum_{j=1}^{p-1}\left(x_j - h_{p-1}^{\text{ave}}\right)^2 \\
& = \left(x_p - h_p^{\text{ave}}\right)^2 + \left[\sum_{j=1}^{p-1}\left(x_j - h_p^{\text{ave}}\right)^2 - \sum_{j=1}^{p-1}\left(x_j - h_{p-1}^{\text{ave}}\right)^2\right] \\
& = \left(x_p - h_p^{\text{ave}}\right)^2 + \sum_{j=1}^{p-1}\left[\left(x_j - h_p^{\text{ave}}\right)^2 - \left(x_j - h_{p-1}^{\text{ave}}\right)^2\right] \\
\end{split}
\end{equation}
We now use the identity $a^2 - b^2 = \left(a-b\right)\left(a+b\right)$ to simplify each summand in Equation (5) as follows
\begin{equation}
\begin{split}
p\,h_p^{\text{var}} - \left(p-1\right)\,h_{p-1}^{\text{var}} & = \left(x_p - h_p^{\text{ave}}\right)^2 + \sum_{j=1}^{p-1}\left(h_{p-1}^{\text{ave}} - h_p^{\text{ave}}\right) \left(2 x_j - h_{p}^{\text{ave}}-h_{p-1}^{\text{ave}}\right) \\
& = \left(x_p - h_p^{\text{ave}}\right)^2 + \left(h_{p-1}^{\text{ave}} - h_p^{\text{ave}}\right) \sum_{j=1}^{p-1} \left(2 x_j - h_{p}^{\text{ave}}-h_{p-1}^{\text{ave}}\right)\\
\end{split}
\end{equation}
Notice, the last summation in Equation above can be written equivalently as
\begin{equation}
\begin{split}
\sum_{j=1}^{p-1} \left(2 x_j - h_{p}^{\text{ave}}-h_{p-1}^{\text{ave}}\right) & = \left(2\sum_{j=1}^{p-1} x_j\right) - \left(p-1\right) \left( h_{p}^{\text{ave}} + h_{p-1}^{\text{ave}} \right)\\
& = 2\left(p-1\right)h_{p-1}^{\text{ave}} - \left(p-1\right) \left( h_{p}^{\text{ave}} + h_{p-1}^{\text{ave}} \right)\\
& = \left(p-1\right) h_{p-1}^{\text{ave}} - \left(p-1\right) h_{p}^{\text{ave}} \\
& = \left(p \,h_{p}^{\text{ave}} - x_p\right) - \left(p-1\right) h_{p}^{\text{ave}} \\
& = h_{p}^{\text{ave}} - x_p
\end{split}
\end{equation}
where we have made use of the fact that $\left(p-1\right) h_{p-1}^{\text{ave}} = p \,h_{p}^{\text{ave}} - x_p$.
Substituting the result above into (6) we now have
\begin{equation}
\begin{split}
p\,h_p^{\text{var}} - \left(p-1\right)\,h_{p-1}^{\text{var}} & = \left(x_p - h_p^{\text{ave}}\right)^2 + \left(h_{p-1}^{\text{ave}} - h_p^{\text{ave}}\right) \left(h_{p}^{\text{ave}} - x_p\right)\\
& = \left(x_p - h_p^{\text{ave}}\right)\left(x_p - h_{p-1}^{\text{ave}}\right)
\end{split}
\end{equation}
A little re-arrangement finally gives
\begin{equation}
h_{p}^{\text{var}} = \frac{p-1}{p}h_{p-1}^{\text{var}} + \frac{1}{p}\left(x_p^{\,} - h_{p}^{\text{ave}}\right)\left(x_p^{\,} - h_{p-1}^{\text{ave}}\right)
\end{equation}
|
open import Nat
open import Prelude
open import contexts
open import dynamics-core
open import type-assignment-unicity
module canonical-indeterminate-forms where
-- this type gives somewhat nicer syntax for the output of the canonical
-- forms lemma for indeterminates at num type
data cif-num : (Δ : hctx) (d : ihexp) → Set where
CIFNPlus1 : ∀{Δ d} →
Σ[ d1 ∈ ihexp ] Σ[ d2 ∈ ihexp ]
((d == d1 ·+ d2) ×
(Δ , ∅ ⊢ d1 :: num) ×
(Δ , ∅ ⊢ d2 :: num) ×
(d1 indet) ×
(d2 final)
)
→ cif-num Δ d
CIFNPlus2 : ∀{Δ d} →
Σ[ d1 ∈ ihexp ] Σ[ d2 ∈ ihexp ]
((d == d1 ·+ d2) ×
(Δ , ∅ ⊢ d1 :: num) ×
(Δ , ∅ ⊢ d2 :: num) ×
(d1 final) ×
(d2 indet)
)
→ cif-num Δ d
CIFNAp : ∀{Δ d} →
Σ[ d1 ∈ ihexp ] Σ[ d2 ∈ ihexp ] Σ[ τ2 ∈ htyp ]
((d == d1 ∘ d2) ×
(Δ , ∅ ⊢ d1 :: τ2 ==> num) ×
(Δ , ∅ ⊢ d2 :: τ2) ×
(d1 indet) ×
(d2 final) ×
((τ3 τ4 τ3' τ4' : htyp) (d1' : ihexp) → d1 ≠ (d1' ⟨ τ3 ==> τ4 ⇒ τ3' ==> τ4' ⟩))
)
→ cif-num Δ d
CIFNCase : ∀{Δ d} →
Σ[ d1 ∈ ihexp ] Σ[ x ∈ Nat ] Σ[ d2 ∈ ihexp ] Σ[ y ∈ Nat ] Σ[ d3 ∈ ihexp ]
Σ[ τ1 ∈ htyp ] Σ[ τ2 ∈ htyp ]
((d == case d1 x d2 y d3) ×
(Δ , ∅ ⊢ d1 :: τ1 ⊕ τ2) ×
(Δ , ■ (x , τ1) ⊢ d2 :: num) ×
(Δ , ■ (y , τ2) ⊢ d3 :: num) ×
(d1 indet) ×
((τ : htyp) (d' : ihexp) → d1 ≠ inl τ d') ×
((τ : htyp) (d' : ihexp) → d1 ≠ inr τ d') ×
((τ3 τ4 τ3' τ4' : htyp) (d' : ihexp) →
d1 ≠ (d' ⟨(τ3 ⊕ τ4) ⇒ (τ3' ⊕ τ4')⟩))
)
→ cif-num Δ d
CIFNFst : ∀{Δ d} →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == fst d') ×
(Δ , ∅ ⊢ d' :: num ⊠ τ') ×
(d' indet) ×
((d1 d2 : ihexp) → d' ≠ ⟨ d1 , d2 ⟩) ×
((τ3 τ4 τ3' τ4' : htyp) (d'' : ihexp) →
d' ≠ (d'' ⟨(τ3 ⊠ τ4) ⇒ (τ3' ⊠ τ4')⟩))
)
→ cif-num Δ d
CIFNSnd : ∀{Δ d} →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == snd d') ×
(Δ , ∅ ⊢ d' :: τ' ⊠ num) ×
(d' indet) ×
((d1 d2 : ihexp) → d' ≠ ⟨ d1 , d2 ⟩) ×
((τ3 τ4 τ3' τ4' : htyp) (d'' : ihexp) →
d' ≠ (d'' ⟨(τ3 ⊠ τ4) ⇒ (τ3' ⊠ τ4')⟩))
)
→ cif-num Δ d
CIFNEHole : ∀{Δ d} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ]
((d == ⦇-⦈⟨ u , σ ⟩) ×
((u :: num [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-num Δ d
CIFNNEHole : ∀{Δ d} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ] Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == ⦇⌜ d' ⌟⦈⟨ u , σ ⟩) ×
(Δ , ∅ ⊢ d' :: τ') ×
(d' final) ×
((u :: num [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-num Δ d
CIFNCast : ∀{Δ d} →
Σ[ d' ∈ ihexp ]
((d == d' ⟨ ⦇-⦈ ⇒ num ⟩) ×
(Δ , ∅ ⊢ d' :: ⦇-⦈) ×
(d' indet) ×
((d'' : ihexp) (τ' : htyp) → d' ≠ (d'' ⟨ τ' ⇒ ⦇-⦈ ⟩))
)
→ cif-num Δ d
CIFNFailedCast : ∀{Δ d} →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == d' ⟨ τ' ⇒⦇-⦈⇏ num ⟩) ×
(Δ , ∅ ⊢ d' :: τ') ×
(τ' ground) ×
(τ' ≠ num)
)
→ cif-num Δ d
canonical-indeterminate-forms-num : ∀{Δ d} →
Δ , ∅ ⊢ d :: num →
d indet →
cif-num Δ d
canonical-indeterminate-forms-num TANum ()
canonical-indeterminate-forms-num (TAPlus wt wt₁) (IPlus1 x x₁) = CIFNPlus1 (_ , _ , refl , wt , wt₁ , x , x₁)
canonical-indeterminate-forms-num (TAPlus wt wt₁) (IPlus2 x x₁) = CIFNPlus2 (_ , _ , refl , wt , wt₁ , x , x₁)
canonical-indeterminate-forms-num (TAVar x₁) ()
canonical-indeterminate-forms-num (TAAp wt wt₁) (IAp x ind x₁) = CIFNAp (_ , _ , _ , refl , wt , wt₁ , ind , x₁ , x)
canonical-indeterminate-forms-num {Δ = Δ} (TACase {τ1 = τ1} {τ2 = τ2} {x = x} {d1 = d1} {y = y} {d2 = d2} wt _ wt₁ _ wt₂) (ICase ninl ninr ncast ind) = CIFNCase (_ , _ , _ , _ , _ , _ , _ , refl , wt , tr (λ Γ' → Δ , Γ' ⊢ d1 :: num) (extend-empty x τ1) wt₁ , tr (λ Γ' → Δ , Γ' ⊢ d2 :: num) (extend-empty y τ2) wt₂ , ind , ninl , ninr , ncast)
canonical-indeterminate-forms-num (TAFst wt) (IFst x x₁ ind) = CIFNFst (_ , _ , refl , wt , ind , x , x₁)
canonical-indeterminate-forms-num (TASnd wt) (ISnd x x₁ ind) = CIFNSnd (_ , _ , refl , wt , ind , x , x₁)
canonical-indeterminate-forms-num (TAEHole x x₁) IEHole = CIFNEHole (_ , _ , _ , refl , x , x₁)
canonical-indeterminate-forms-num (TANEHole x wt x₁) (INEHole x₂) = CIFNNEHole (_ , _ , _ , _ , _ , refl , wt , x₂ , x , x₁)
canonical-indeterminate-forms-num (TACast wt x) (ICastHoleGround x₁ ind x₂) = CIFNCast (_ , refl , wt , ind , x₁)
canonical-indeterminate-forms-num (TAFailedCast x x₁ x₂ x₃) (IFailedCast x₄ x₅ x₆ x₇) = CIFNFailedCast (_ , _ , refl , x , x₅ , x₇)
-- this type gives somewhat nicer syntax for the output of the canonical
-- forms lemma for indeterminates at arrow type
data cif-arr : (Δ : hctx) (d : ihexp) (τ1 τ2 : htyp) → Set where
CIFAEHole : ∀{d Δ τ1 τ2} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ]
((d == ⦇-⦈⟨ u , σ ⟩) ×
((u :: (τ1 ==> τ2) [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-arr Δ d τ1 τ2
CIFANEHole : ∀{d Δ τ1 τ2} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ] Σ[ Γ ∈ tctx ]
((d == ⦇⌜ d' ⌟⦈⟨ u , σ ⟩) ×
(Δ , ∅ ⊢ d' :: τ') ×
(d' final) ×
((u :: (τ1 ==> τ2) [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-arr Δ d τ1 τ2
CIFAAp : ∀{d Δ τ1 τ2} →
Σ[ d1 ∈ ihexp ] Σ[ d2 ∈ ihexp ] Σ[ τ2' ∈ htyp ] Σ[ τ1 ∈ htyp ] Σ[ τ2 ∈ htyp ]
((d == d1 ∘ d2) ×
(Δ , ∅ ⊢ d1 :: τ2' ==> (τ1 ==> τ2)) ×
(Δ , ∅ ⊢ d2 :: τ2') ×
(d1 indet) ×
(d2 final) ×
((τ3 τ4 τ3' τ4' : htyp) (d1' : ihexp) → d1 ≠ (d1' ⟨ τ3 ==> τ4 ⇒ τ3' ==> τ4' ⟩))
)
→ cif-arr Δ d τ1 τ2
CIFACase : ∀{Δ d τ1 τ2} →
Σ[ d1 ∈ ihexp ] Σ[ x ∈ Nat ] Σ[ d2 ∈ ihexp ] Σ[ y ∈ Nat ] Σ[ d3 ∈ ihexp ]
Σ[ τ3 ∈ htyp ] Σ[ τ4 ∈ htyp ]
((d == case d1 x d2 y d3) ×
(Δ , ∅ ⊢ d1 :: τ3 ⊕ τ4) ×
(Δ , ■ (x , τ3) ⊢ d2 :: τ1 ==> τ2) ×
(Δ , ■ (y , τ4) ⊢ d3 :: τ1 ==> τ2) ×
(d1 indet) ×
((τ : htyp) (d' : ihexp) → d1 ≠ inl τ d') ×
((τ : htyp) (d' : ihexp) → d1 ≠ inr τ d') ×
((τ5 τ6 τ5' τ6' : htyp) (d' : ihexp) →
d1 ≠ (d' ⟨(τ5 ⊕ τ6) ⇒ (τ5' ⊕ τ6')⟩))
)
→ cif-arr Δ d τ1 τ2
CIFAFst : ∀{Δ d τ1 τ2} →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == fst d') ×
(Δ , ∅ ⊢ d' :: (τ1 ==> τ2) ⊠ τ') ×
(d' indet) ×
((d1 d2 : ihexp) → d' ≠ ⟨ d1 , d2 ⟩) ×
((τ3 τ4 τ3' τ4' : htyp) (d'' : ihexp) →
d' ≠ (d'' ⟨(τ3 ⊠ τ4) ⇒ (τ3' ⊠ τ4')⟩))
)
→ cif-arr Δ d τ1 τ2
CIFASnd : ∀{Δ d τ1 τ2} →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == snd d') ×
(Δ , ∅ ⊢ d' :: τ' ⊠ (τ1 ==> τ2)) ×
(d' indet) ×
((d1 d2 : ihexp) → d' ≠ ⟨ d1 , d2 ⟩) ×
((τ3 τ4 τ3' τ4' : htyp) (d'' : ihexp) →
d' ≠ (d'' ⟨(τ3 ⊠ τ4) ⇒ (τ3' ⊠ τ4')⟩))
)
→ cif-arr Δ d τ1 τ2
CIFACast : ∀{d Δ τ1 τ2} →
Σ[ d' ∈ ihexp ] Σ[ τ1 ∈ htyp ] Σ[ τ2 ∈ htyp ] Σ[ τ1' ∈ htyp ] Σ[ τ2' ∈ htyp ]
((d == d' ⟨ (τ1' ==> τ2') ⇒ (τ1 ==> τ2) ⟩) ×
(Δ , ∅ ⊢ d' :: τ1' ==> τ2') ×
(d' indet) ×
((τ1' ==> τ2') ≠ (τ1 ==> τ2))
)
→ cif-arr Δ d τ1 τ2
CIFACastHole : ∀{d Δ τ1 τ2} →
Σ[ d' ∈ ihexp ]
((d == (d' ⟨ ⦇-⦈ ⇒ ⦇-⦈ ==> ⦇-⦈ ⟩)) ×
(τ1 == ⦇-⦈) ×
(τ2 == ⦇-⦈) ×
(Δ , ∅ ⊢ d' :: ⦇-⦈) ×
(d' indet) ×
((d'' : ihexp) (τ' : htyp) → d' ≠ (d'' ⟨ τ' ⇒ ⦇-⦈ ⟩))
)
→ cif-arr Δ d τ1 τ2
CIFAFailedCast : ∀{d Δ τ1 τ2} →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == (d' ⟨ τ' ⇒⦇-⦈⇏ ⦇-⦈ ==> ⦇-⦈ ⟩) ) ×
(τ1 == ⦇-⦈) ×
(τ2 == ⦇-⦈) ×
(Δ , ∅ ⊢ d' :: τ') ×
(τ' ground) ×
(τ' ≠ (⦇-⦈ ==> ⦇-⦈))
)
→ cif-arr Δ d τ1 τ2
canonical-indeterminate-forms-arr : ∀{Δ d τ1 τ2 } →
Δ , ∅ ⊢ d :: (τ1 ==> τ2) →
d indet →
cif-arr Δ d τ1 τ2
canonical-indeterminate-forms-arr (TAVar x₁) ()
canonical-indeterminate-forms-arr (TALam _ wt) ()
canonical-indeterminate-forms-arr (TAAp wt wt₁) (IAp x ind x₁) = CIFAAp (_ , _ , _ , _ , _ , refl , wt , wt₁ , ind , x₁ , x)
canonical-indeterminate-forms-arr {Δ = Δ} (TACase {τ1 = τ1} {τ2 = τ2} {τ = τ3 ==> τ4} {x = x} {d1 = d1} {y = y} {d2 = d2} wt _ wt₁ _ wt₂) (ICase ninl ninr ncast ind) = CIFACase (_ , _ , _ , _ , _ , _ , _ , refl , wt , tr (λ Γ' → Δ , Γ' ⊢ d1 :: τ3 ==> τ4) (extend-empty x τ1) wt₁ , tr (λ Γ' → Δ , Γ' ⊢ d2 :: τ3 ==> τ4) (extend-empty y τ2) wt₂ , ind , ninl , ninr , ncast)
canonical-indeterminate-forms-arr (TAFst wt) (IFst x x₁ ind) = CIFAFst (_ , _ , refl , wt , ind , x , x₁)
canonical-indeterminate-forms-arr (TASnd wt) (ISnd x x₁ ind) = CIFASnd (_ , _ , refl , wt , ind , x , x₁)
canonical-indeterminate-forms-arr (TAEHole x x₁) IEHole = CIFAEHole (_ , _ , _ , refl , x , x₁)
canonical-indeterminate-forms-arr (TANEHole x wt x₁) (INEHole x₂) = CIFANEHole (_ , _ , _ , _ , _ , refl , wt , x₂ , x , x₁)
canonical-indeterminate-forms-arr (TACast wt x) (ICastArr x₁ ind) = CIFACast (_ , _ , _ , _ , _ , refl , wt , ind , x₁)
canonical-indeterminate-forms-arr (TACast wt TCHole2) (ICastHoleGround x₁ ind GArrHole) = CIFACastHole (_ , refl , refl , refl , wt , ind , x₁)
canonical-indeterminate-forms-arr (TAFailedCast x x₁ GArrHole x₃) (IFailedCast x₄ x₅ GArrHole x₇) = CIFAFailedCast (_ , _ , refl , refl , refl , x , x₅ , x₇)
-- this type gives somewhat nicer syntax for the output of the canonical
-- forms lemma for indeterminates at sum type
data cif-sum : (Δ : hctx) (d : ihexp) (τ1 τ2 : htyp) → Set where
CIFSEHole : ∀{d Δ τ1 τ2} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ]
((d == ⦇-⦈⟨ u , σ ⟩) ×
((u :: (τ1 ⊕ τ2) [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-sum Δ d τ1 τ2
CIFSNEHole : ∀{d Δ τ1 τ2} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ] Σ[ Γ ∈ tctx ]
((d == ⦇⌜ d' ⌟⦈⟨ u , σ ⟩) ×
(Δ , ∅ ⊢ d' :: τ') ×
(d' final) ×
((u :: (τ1 ⊕ τ2) [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-sum Δ d τ1 τ2
CIFSAp : ∀{d Δ τ1 τ2} →
Σ[ d1 ∈ ihexp ] Σ[ d2 ∈ ihexp ] Σ[ τ2' ∈ htyp ] Σ[ τ1 ∈ htyp ] Σ[ τ2 ∈ htyp ]
((d == d1 ∘ d2) ×
(Δ , ∅ ⊢ d1 :: τ2' ==> (τ1 ⊕ τ2)) ×
(Δ , ∅ ⊢ d2 :: τ2') ×
(d1 indet) ×
(d2 final) ×
((τ3 τ4 τ3' τ4' : htyp) (d1' : ihexp) → d1 ≠ (d1' ⟨ τ3 ==> τ4 ⇒ τ3' ==> τ4' ⟩))
)
→ cif-sum Δ d τ1 τ2
CIFSInl : ∀{Δ d τ1 τ2} →
Σ[ d' ∈ ihexp ]
((d == inl τ2 d') ×
(Δ , ∅ ⊢ d' :: τ1) ×
(d' indet)
)
→ cif-sum Δ d τ1 τ2
CIFSInr : ∀{Δ d τ1 τ2} →
Σ[ d' ∈ ihexp ]
((d == inr τ1 d') ×
(Δ , ∅ ⊢ d' :: τ2) ×
(d' indet)
)
→ cif-sum Δ d τ1 τ2
CIFSCase : ∀{Δ d τ1 τ2} →
Σ[ d1 ∈ ihexp ] Σ[ x ∈ Nat ] Σ[ d2 ∈ ihexp ] Σ[ y ∈ Nat ] Σ[ d3 ∈ ihexp ]
Σ[ τ3 ∈ htyp ] Σ[ τ4 ∈ htyp ]
((d == case d1 x d2 y d3) ×
(Δ , ∅ ⊢ d1 :: τ3 ⊕ τ4) ×
(Δ , ■ (x , τ3) ⊢ d2 :: τ1 ⊕ τ2) ×
(Δ , ■ (y , τ4) ⊢ d3 :: τ1 ⊕ τ2) ×
(d1 indet) ×
((τ : htyp) (d' : ihexp) → d1 ≠ inl τ d') ×
((τ : htyp) (d' : ihexp) → d1 ≠ inr τ d') ×
((τ5 τ6 τ5' τ6' : htyp) (d' : ihexp) →
d1 ≠ (d' ⟨(τ5 ⊕ τ6) ⇒ (τ5' ⊕ τ6')⟩))
)
→ cif-sum Δ d τ1 τ2
CIFSFst : ∀{Δ d τ1 τ2} →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == fst d') ×
(Δ , ∅ ⊢ d' :: (τ1 ⊕ τ2) ⊠ τ') ×
(d' indet) ×
((d1 d2 : ihexp) → d' ≠ ⟨ d1 , d2 ⟩) ×
((τ3 τ4 τ3' τ4' : htyp) (d'' : ihexp) →
d' ≠ (d'' ⟨(τ3 ⊠ τ4) ⇒ (τ3' ⊠ τ4')⟩))
)
→ cif-sum Δ d τ1 τ2
CIFSSnd : ∀{Δ d τ1 τ2} →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == snd d') ×
(Δ , ∅ ⊢ d' :: τ' ⊠ (τ1 ⊕ τ2)) ×
(d' indet) ×
((d1 d2 : ihexp) → d' ≠ ⟨ d1 , d2 ⟩) ×
((τ3 τ4 τ3' τ4' : htyp) (d'' : ihexp) →
d' ≠ (d'' ⟨(τ3 ⊠ τ4) ⇒ (τ3' ⊠ τ4')⟩))
)
→ cif-sum Δ d τ1 τ2
CIFSCast : ∀{d Δ τ1 τ2} →
Σ[ d' ∈ ihexp ] Σ[ τ1 ∈ htyp ] Σ[ τ2 ∈ htyp ] Σ[ τ1' ∈ htyp ] Σ[ τ2' ∈ htyp ]
((d == d' ⟨ (τ1' ⊕ τ2') ⇒ (τ1 ⊕ τ2) ⟩) ×
(Δ , ∅ ⊢ d' :: τ1' ⊕ τ2') ×
(d' indet) ×
((τ1' ⊕ τ2') ≠ (τ1 ⊕ τ2))
)
→ cif-sum Δ d τ1 τ2
CIFSCastHole : ∀{d Δ τ1 τ2} →
Σ[ d' ∈ ihexp ]
((d == (d' ⟨ ⦇-⦈ ⇒ ⦇-⦈ ⊕ ⦇-⦈ ⟩)) ×
(τ1 == ⦇-⦈) ×
(τ2 == ⦇-⦈) ×
(Δ , ∅ ⊢ d' :: ⦇-⦈) ×
(d' indet) ×
((d'' : ihexp) (τ' : htyp) → d' ≠ (d'' ⟨ τ' ⇒ ⦇-⦈ ⟩))
)
→ cif-sum Δ d τ1 τ2
CIFSFailedCast : ∀{d Δ τ1 τ2} →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == (d' ⟨ τ' ⇒⦇-⦈⇏ ⦇-⦈ ⊕ ⦇-⦈ ⟩) ) ×
(τ1 == ⦇-⦈) ×
(τ2 == ⦇-⦈) ×
(Δ , ∅ ⊢ d' :: τ') ×
(τ' ground) ×
(τ' ≠ (⦇-⦈ ⊕ ⦇-⦈))
)
→ cif-sum Δ d τ1 τ2
canonical-indeterminate-forms-sum : ∀{Δ d τ1 τ2 } →
Δ , ∅ ⊢ d :: (τ1 ⊕ τ2) →
d indet →
cif-sum Δ d τ1 τ2
canonical-indeterminate-forms-sum (TAAp wt wt₁) (IAp x ind x₁) = CIFSAp (_ , _ , _ , _ , _ , refl , wt , wt₁ , ind , x₁ , x)
canonical-indeterminate-forms-sum (TAInl wt) (IInl ind) = CIFSInl (_ , refl , wt , ind)
canonical-indeterminate-forms-sum (TAInr wt) (IInr ind) = CIFSInr (_ , refl , wt , ind)
canonical-indeterminate-forms-sum {Δ = Δ} (TACase {τ1 = τ1} {τ2 = τ2} {τ = τ3 ⊕ τ4} {x = x} {d1 = d1} {y = y} {d2 = d2} wt _ wt₁ _ wt₂) (ICase ninl ninr ncast ind) = CIFSCase (_ , _ , _ , _ , _ , _ , _ , refl , wt , tr (λ Γ' → Δ , Γ' ⊢ d1 :: (τ3 ⊕ τ4)) (extend-empty x τ1) wt₁ , tr (λ Γ' → Δ , Γ' ⊢ d2 :: (τ3 ⊕ τ4)) (extend-empty y τ2) wt₂ , ind , ninl , ninr , ncast)
canonical-indeterminate-forms-sum (TAFst wt) (IFst x x₁ ind) = CIFSFst (_ , _ , refl , wt , ind , x , x₁)
canonical-indeterminate-forms-sum (TASnd wt) (ISnd x x₁ ind) = CIFSSnd (_ , _ , refl , wt , ind , x , x₁)
canonical-indeterminate-forms-sum (TAEHole x x₁) IEHole = CIFSEHole (_ , _ , _ , refl , x , x₁)
canonical-indeterminate-forms-sum (TANEHole x wt x₁) (INEHole x₂) = CIFSNEHole (_ , _ , _ , _ , _ , refl , wt , x₂ , x , x₁)
canonical-indeterminate-forms-sum (TACast wt x) (ICastSum x₁ ind) = CIFSCast (_ , _ , _ , _ , _ , refl , wt , ind , x₁)
canonical-indeterminate-forms-sum (TACast wt x) (ICastHoleGround x₁ ind GSumHole) = CIFSCastHole (_ , refl , refl , refl , wt , ind , x₁)
canonical-indeterminate-forms-sum (TAFailedCast wt x x₁ x₂) (IFailedCast x₃ x₄ GSumHole x₆) = CIFSFailedCast (_ , _ , refl , refl , refl , wt , x₄ , x₆)
canonical-indeterminate-forms-sum (TAVar x) ()
-- this type gives somewhat nicer syntax for the output of the canonical
-- forms lemma for indeterminates at product type
data cif-prod : (Δ : hctx) (d : ihexp) (τ1 τ2 : htyp) → Set where
CIFPEHole : ∀{d Δ τ1 τ2} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ]
((d == ⦇-⦈⟨ u , σ ⟩) ×
((u :: (τ1 ⊠ τ2) [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-prod Δ d τ1 τ2
CIFPNEHole : ∀{d Δ τ1 τ2} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ] Σ[ Γ ∈ tctx ]
((d == ⦇⌜ d' ⌟⦈⟨ u , σ ⟩) ×
(Δ , ∅ ⊢ d' :: τ') ×
(d' final) ×
((u :: (τ1 ⊠ τ2) [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-prod Δ d τ1 τ2
CIFPAp : ∀{d Δ τ1 τ2} →
Σ[ d1 ∈ ihexp ] Σ[ d2 ∈ ihexp ] Σ[ τ2' ∈ htyp ] Σ[ τ1 ∈ htyp ] Σ[ τ2 ∈ htyp ]
((d == d1 ∘ d2) ×
(Δ , ∅ ⊢ d1 :: τ2' ==> (τ1 ⊠ τ2)) ×
(Δ , ∅ ⊢ d2 :: τ2') ×
(d1 indet) ×
(d2 final) ×
((τ3 τ4 τ3' τ4' : htyp) (d1' : ihexp) → d1 ≠ (d1' ⟨ τ3 ==> τ4 ⇒ τ3' ==> τ4' ⟩))
)
→ cif-prod Δ d τ1 τ2
CIFPCase : ∀{Δ d τ1 τ2} →
Σ[ d1 ∈ ihexp ] Σ[ x ∈ Nat ] Σ[ d2 ∈ ihexp ] Σ[ y ∈ Nat ] Σ[ d3 ∈ ihexp ]
Σ[ τ3 ∈ htyp ] Σ[ τ4 ∈ htyp ]
((d == case d1 x d2 y d3) ×
(Δ , ∅ ⊢ d1 :: τ3 ⊕ τ4) ×
(Δ , ■ (x , τ3) ⊢ d2 :: τ1 ⊠ τ2) ×
(Δ , ■ (y , τ4) ⊢ d3 :: τ1 ⊠ τ2) ×
(d1 indet) ×
((τ : htyp) (d' : ihexp) → d1 ≠ inl τ d') ×
((τ : htyp) (d' : ihexp) → d1 ≠ inr τ d') ×
((τ5 τ6 τ5' τ6' : htyp) (d' : ihexp) →
d1 ≠ (d' ⟨(τ5 ⊕ τ6) ⇒ (τ5' ⊕ τ6')⟩))
)
→ cif-prod Δ d τ1 τ2
CIFPPair1 : ∀{Δ d τ1 τ2} →
Σ[ d1 ∈ ihexp ] Σ[ d2 ∈ ihexp ]
((d == ⟨ d1 , d2 ⟩) ×
(Δ , ∅ ⊢ d1 :: τ1) ×
(Δ , ∅ ⊢ d2 :: τ2) ×
d1 indet ×
d2 final
)
→ cif-prod Δ d τ1 τ2
CIFPPair2 : ∀{Δ d τ1 τ2} →
Σ[ d1 ∈ ihexp ] Σ[ d2 ∈ ihexp ]
((d == ⟨ d1 , d2 ⟩) ×
(Δ , ∅ ⊢ d1 :: τ1) ×
(Δ , ∅ ⊢ d2 :: τ2) ×
d1 final ×
d2 indet
)
→ cif-prod Δ d τ1 τ2
CIFPFst : ∀{Δ d τ1 τ2} →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == fst d') ×
(Δ , ∅ ⊢ d' :: (τ1 ⊠ τ2) ⊠ τ') ×
(d' indet) ×
((d1 d2 : ihexp) → d' ≠ ⟨ d1 , d2 ⟩) ×
((τ3 τ4 τ3' τ4' : htyp) (d'' : ihexp) →
d' ≠ (d'' ⟨(τ3 ⊠ τ4) ⇒ (τ3' ⊠ τ4')⟩))
)
→ cif-prod Δ d τ1 τ2
CIFPSnd : ∀{Δ d τ1 τ2} →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == snd d') ×
(Δ , ∅ ⊢ d' :: τ' ⊠ (τ1 ⊠ τ2)) ×
(d' indet) ×
((d1 d2 : ihexp) → d' ≠ ⟨ d1 , d2 ⟩) ×
((τ3 τ4 τ3' τ4' : htyp) (d'' : ihexp) →
d' ≠ (d'' ⟨(τ3 ⊠ τ4) ⇒ (τ3' ⊠ τ4')⟩))
)
→ cif-prod Δ d τ1 τ2
CIFPCast : ∀{d Δ τ1 τ2} →
Σ[ d' ∈ ihexp ] Σ[ τ1 ∈ htyp ] Σ[ τ2 ∈ htyp ] Σ[ τ1' ∈ htyp ] Σ[ τ2' ∈ htyp ]
((d == d' ⟨ (τ1' ⊠ τ2') ⇒ (τ1 ⊠ τ2) ⟩) ×
(Δ , ∅ ⊢ d' :: τ1' ⊠ τ2') ×
(d' indet) ×
((τ1' ⊠ τ2') ≠ (τ1 ⊠ τ2))
)
→ cif-prod Δ d τ1 τ2
CIFPCastHole : ∀{d Δ τ1 τ2} →
Σ[ d' ∈ ihexp ]
((d == (d' ⟨ ⦇-⦈ ⇒ ⦇-⦈ ⊠ ⦇-⦈ ⟩)) ×
(τ1 == ⦇-⦈) ×
(τ2 == ⦇-⦈) ×
(Δ , ∅ ⊢ d' :: ⦇-⦈) ×
(d' indet) ×
((d'' : ihexp) (τ' : htyp) → d' ≠ (d'' ⟨ τ' ⇒ ⦇-⦈ ⟩))
)
→ cif-prod Δ d τ1 τ2
CIFPFailedCast : ∀{d Δ τ1 τ2} →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == (d' ⟨ τ' ⇒⦇-⦈⇏ ⦇-⦈ ⊠ ⦇-⦈ ⟩) ) ×
(τ1 == ⦇-⦈) ×
(τ2 == ⦇-⦈) ×
(Δ , ∅ ⊢ d' :: τ') ×
(τ' ground) ×
(τ' ≠ (⦇-⦈ ⊠ ⦇-⦈))
)
→ cif-prod Δ d τ1 τ2
canonical-indeterminate-forms-prod : ∀{Δ d τ1 τ2} →
Δ , ∅ ⊢ d :: (τ1 ⊠ τ2) →
d indet →
cif-prod Δ d τ1 τ2
canonical-indeterminate-forms-prod (TAVar x) ()
canonical-indeterminate-forms-prod (TAAp wt wt₁) (IAp x ind x₁) = CIFPAp (_ , _ , _ , _ , _ , refl , wt , wt₁ , ind , x₁ , x)
canonical-indeterminate-forms-prod {Δ = Δ} (TACase {τ1 = τ1} {τ2 = τ2} {τ = τ3 ⊠ τ4} {x = x} {d1 = d1} {y = y} {d2 = d2} wt _ wt₁ _ wt₂) (ICase ninl ninr ncast ind) = CIFPCase (_ , _ , _ , _ , _ , _ , _ , refl , wt , tr (λ Γ' → Δ , Γ' ⊢ d1 :: (τ3 ⊠ τ4)) (extend-empty x τ1) wt₁ , tr (λ Γ' → Δ , Γ' ⊢ d2 :: (τ3 ⊠ τ4)) (extend-empty y τ2) wt₂ , ind , ninl , ninr , ncast)
canonical-indeterminate-forms-prod (TAPair wt wt₁) (IPair1 ind x) = CIFPPair1 (_ , _ , refl , wt , wt₁ , ind , x)
canonical-indeterminate-forms-prod (TAPair wt wt₁) (IPair2 x ind) = CIFPPair2 (_ , _ , refl , wt , wt₁ , x , ind)
canonical-indeterminate-forms-prod (TAFst wt) (IFst x x₁ ind) = CIFPFst (_ , _ , refl , wt , ind , x , x₁)
canonical-indeterminate-forms-prod (TASnd wt) (ISnd x x₁ ind) = CIFPSnd (_ , _ , refl , wt , ind , x , x₁)
canonical-indeterminate-forms-prod (TAEHole x x₁) IEHole = CIFPEHole (_ , _ , _ , refl , x , x₁)
canonical-indeterminate-forms-prod (TANEHole x wt x₁) (INEHole x₂) = CIFPNEHole (_ , _ , _ , _ , _ , refl , wt , x₂ , x , x₁)
canonical-indeterminate-forms-prod (TACast wt x) (ICastProd x₁ ind) = CIFPCast (_ , _ , _ , _ , _ , refl , wt , ind , x₁)
canonical-indeterminate-forms-prod (TACast wt x) (ICastHoleGround x₁ ind GProdHole) = CIFPCastHole (_ , refl , refl , refl , wt , ind , x₁)
canonical-indeterminate-forms-prod (TAFailedCast wt x GProdHole x₂) (IFailedCast x₃ x₄ GProdHole x₆) = CIFPFailedCast (_ , _ , refl , refl , refl , wt , x₄ , x₆)
-- this type gives somewhat nicer syntax for the output of the canonical
-- forms lemma for indeterminates at hole type
data cif-hole : (Δ : hctx) (d : ihexp) → Set where
CIFHEHole : ∀{Δ d} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ]
((d == ⦇-⦈⟨ u , σ ⟩) ×
((u :: ⦇-⦈ [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-hole Δ d
CIFHNEHole : ∀{Δ d} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ] Σ[ Γ ∈ tctx ]
((d == ⦇⌜ d' ⌟⦈⟨ u , σ ⟩) ×
(Δ , ∅ ⊢ d' :: τ') ×
(d' final) ×
((u :: ⦇-⦈ [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-hole Δ d
CIFHAp : ∀{Δ d} →
Σ[ d1 ∈ ihexp ] Σ[ d2 ∈ ihexp ] Σ[ τ2 ∈ htyp ]
((d == d1 ∘ d2) ×
(Δ , ∅ ⊢ d1 :: (τ2 ==> ⦇-⦈)) ×
(Δ , ∅ ⊢ d2 :: τ2) ×
(d1 indet) ×
(d2 final) ×
((τ3 τ4 τ3' τ4' : htyp) (d1' : ihexp) → d1 ≠ (d1' ⟨ τ3 ==> τ4 ⇒ τ3' ==> τ4' ⟩))
)
→ cif-hole Δ d
CIFHCase : ∀{Δ d} →
Σ[ d1 ∈ ihexp ] Σ[ x ∈ Nat ] Σ[ d2 ∈ ihexp ] Σ[ y ∈ Nat ] Σ[ d3 ∈ ihexp ]
Σ[ τ1 ∈ htyp ] Σ[ τ2 ∈ htyp ]
((d == case d1 x d2 y d3) ×
(Δ , ∅ ⊢ d1 :: τ1 ⊕ τ2) ×
(Δ , ■ (x , τ1) ⊢ d2 :: ⦇-⦈) ×
(Δ , ■ (y , τ2) ⊢ d3 :: ⦇-⦈) ×
(d1 indet) ×
((τ : htyp) (d' : ihexp) → d1 ≠ inl τ d') ×
((τ : htyp) (d' : ihexp) → d1 ≠ inr τ d') ×
((τ3 τ4 τ3' τ4' : htyp) (d' : ihexp) →
d1 ≠ (d' ⟨(τ3 ⊕ τ4) ⇒ (τ3' ⊕ τ4')⟩))
)
→ cif-hole Δ d
CIFHFst : ∀{Δ d} →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == fst d') ×
(Δ , ∅ ⊢ d' :: ⦇-⦈ ⊠ τ') ×
(d' indet) ×
((d1 d2 : ihexp) → d' ≠ ⟨ d1 , d2 ⟩) ×
((τ3 τ4 τ3' τ4' : htyp) (d'' : ihexp) →
d' ≠ (d'' ⟨(τ3 ⊠ τ4) ⇒ (τ3' ⊠ τ4')⟩))
)
→ cif-hole Δ d
CIFHSnd : ∀{Δ d} →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == snd d') ×
(Δ , ∅ ⊢ d' :: τ' ⊠ ⦇-⦈) ×
(d' indet) ×
((d1 d2 : ihexp) → d' ≠ ⟨ d1 , d2 ⟩) ×
((τ3 τ4 τ3' τ4' : htyp) (d'' : ihexp) →
d' ≠ (d'' ⟨(τ3 ⊠ τ4) ⇒ (τ3' ⊠ τ4')⟩))
)
→ cif-hole Δ d
CIFHCast : ∀{Δ d} →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == d' ⟨ τ' ⇒ ⦇-⦈ ⟩) ×
(Δ , ∅ ⊢ d' :: τ') ×
(τ' ground) ×
(d' indet)
)
→ cif-hole Δ d
canonical-indeterminate-forms-hole : ∀{Δ d} →
Δ , ∅ ⊢ d :: ⦇-⦈ →
d indet →
cif-hole Δ d
canonical-indeterminate-forms-hole (TAVar x₁) ()
canonical-indeterminate-forms-hole (TAAp wt wt₁) (IAp x ind x₁) = CIFHAp (_ , _ , _ , refl , wt , wt₁ , ind , x₁ , x)
canonical-indeterminate-forms-hole {Δ = Δ} (TACase {τ1 = τ1} {τ2 = τ2} {x = x} {d1 = d1} {y = y} {d2 = d2} wt _ wt₁ _ wt₂) (ICase ninl ninr ncast ind) = CIFHCase (_ , _ , _ , _ , _ , _ , _ , refl , wt , tr (λ Γ' → Δ , Γ' ⊢ d1 :: ⦇-⦈) (extend-empty x τ1) wt₁ , tr (λ Γ' → Δ , Γ' ⊢ d2 :: ⦇-⦈) (extend-empty y τ2) wt₂ , ind , ninl , ninr , ncast)
canonical-indeterminate-forms-hole (TAFst wt) (IFst x x₁ ind) = CIFHFst (_ , _ , refl , wt , ind , x , x₁)
canonical-indeterminate-forms-hole (TASnd wt) (ISnd x x₁ ind) = CIFHSnd (_ , _ , refl , wt , ind , x , x₁)
canonical-indeterminate-forms-hole (TAEHole x x₁) IEHole = CIFHEHole (_ , _ , _ , refl , x , x₁)
canonical-indeterminate-forms-hole (TANEHole x wt x₁) (INEHole x₂) = CIFHNEHole (_ , _ , _ , _ , _ , refl , wt , x₂ , x , x₁)
canonical-indeterminate-forms-hole (TACast wt x) (ICastGroundHole x₁ ind) = CIFHCast (_ , _ , refl , wt , x₁ , ind)
canonical-indeterminate-forms-hole (TACast wt x) (ICastHoleGround x₁ ind ())
canonical-indeterminate-forms-hole (TAFailedCast x x₁ () x₃) (IFailedCast x₄ x₅ x₆ x₇)
canonical-indeterminate-forms-coverage : ∀{Δ d τ} →
Δ , ∅ ⊢ d :: τ →
d indet →
τ ≠ num →
((τ1 : htyp) (τ2 : htyp) → τ ≠ (τ1 ==> τ2)) →
((τ1 : htyp) (τ2 : htyp) → τ ≠ (τ1 ⊕ τ2)) →
((τ1 : htyp) (τ2 : htyp) → τ ≠ (τ1 ⊠ τ2)) →
τ ≠ ⦇-⦈ →
⊥
canonical-indeterminate-forms-coverage {τ = num} wt ind nn na ns np nh = nn refl
canonical-indeterminate-forms-coverage {τ = ⦇-⦈} wt ind nn na ns np nh = nh refl
canonical-indeterminate-forms-coverage {τ = τ ==> τ₁} wt ind nn na ns np nh = na τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = τ ⊕ τ₁} wt ind nn na ns np nh = ns τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = τ ⊠ τ₁} wt ind nn na ns np nh = np τ τ₁ refl
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import groups.Pointed
module groups.Int where
abstract
ℤ→ᴳ-η : ∀ {i} {G : Group i} (φ : ℤ-group →ᴳ G)
→ GroupHom.f φ ∼ Group.exp G (GroupHom.f φ 1)
ℤ→ᴳ-η φ (pos 0) = GroupHom.pres-ident φ
ℤ→ᴳ-η φ (pos 1) = idp
ℤ→ᴳ-η {G = G} φ (pos (S (S n))) =
GroupHom.pres-comp φ 1 (pos (S n))
∙ ap (Group.comp G (GroupHom.f φ 1)) (ℤ→ᴳ-η φ (pos (S n)))
∙ ! (Group.exp-+ G (GroupHom.f φ 1) 1 (pos (S n)))
ℤ→ᴳ-η φ (negsucc 0) = GroupHom.pres-inv φ 1
ℤ→ᴳ-η {G = G} φ (negsucc (S n)) =
GroupHom.pres-comp φ -1 (negsucc n)
∙ ap2 (Group.comp G) (GroupHom.pres-inv φ 1) (ℤ→ᴳ-η φ (negsucc n))
∙ ! (Group.exp-+ G (GroupHom.f φ 1) -1 (negsucc n))
ℤ-idf-η : ∀ i → i == Group.exp ℤ-group 1 i
ℤ-idf-η = ℤ→ᴳ-η (idhom _)
ℤ→ᴳ-unicity : ∀ {i} {G : Group i}
→ (φ ψ : ℤ-group →ᴳ G)
→ GroupHom.f φ 1 == GroupHom.f ψ 1
→ GroupHom.f φ ∼ GroupHom.f ψ
ℤ→ᴳ-unicity {G = G} φ ψ p i =
ℤ→ᴳ-η φ i ∙ ap (λ g₁ → Group.exp G g₁ i) p ∙ ! (ℤ→ᴳ-η ψ i)
ℤ→ᴳ-equiv-idf : ∀ {i} (G : Group i) → (ℤ-group →ᴳ G) ≃ Group.El G
ℤ→ᴳ-equiv-idf G = equiv (λ φ → GroupHom.f φ 1) (exp-hom G)
(λ _ → idp) (λ φ → group-hom= $ λ= $ ! ∘ ℤ→ᴳ-η φ)
where open Group G
ℤ→ᴳ-iso-idf : ∀ {i} (G : AbGroup i) → hom-group ℤ-group G ≃ᴳ AbGroup.grp G
ℤ→ᴳ-iso-idf G = ≃-to-≃ᴳ (ℤ→ᴳ-equiv-idf (AbGroup.grp G)) (λ _ _ → idp)
ℤ-⊙group : ⊙Group₀
ℤ-⊙group = ⊙[ ℤ-group , 1 ]ᴳ
ℤ-is-infinite-cyclic : is-infinite-cyclic ℤ-⊙group
ℤ-is-infinite-cyclic = is-eq
(Group.exp ℤ-group 1)
(idf ℤ)
(! ∘ ℤ-idf-η)
(! ∘ ℤ-idf-η)
|
function modelPlane = sr_extract_plane(imgPath, imgName, opt)
% SR_EXTRACT_PLANE:
%
% Extract plane model from an image
%
% The code is adapted and modified from the paper
%
% Jia-Bin Huang, Sing Bing Kang, Narendra Ahuja, Johannes Kopf
% Image Completion using Planar Structure Guidance
% ACM Transactions on Graphics (Proceedings of SIGGRAPH 2014).
%
% Output: modelPlane
% The model plane has the following data structure
%
% modelPlane
% modelPlane.vpData: Vanishing point data
% modelPlane.numPlane Number of planes
% modelPlane.plane{indPlane}.vLine The vanishing line of the plane
% modelPlane.plane{indPlane}.imgPlaneProb; The planar location density
% modelPlane.plane{indPlane}.sourceVP Which two VPs form the plane
% modelPlane.plane{indPlane}.rotPar(vpInd) Rotation parameters for aligning
% two sets of lines with the x-axis x-axis
% modelPlane.plane{indPlane}.postProb Posteior probability of the plane
% =========================================================================
% Vanishing point detection
% =========================================================================
vpFilePath = 'cache\vpdetection';
vpFileName = [imgName(1:end-4), '-vanishingpoints.txt'];
recomputeFlag = 1;
if(~exist(fullfile(vpFilePath, 'text', vpFileName), 'file') || recomputeFlag)
vpExeFile = 'source\EdgeDetectTest.exe';
vpDetectCMD = [vpExeFile, ' -indir ', imgPath, ' -infile ', imgName, ' -outdir ', vpFilePath];
system(vpDetectCMD);
end
% Read vanishing point data
vpData = sr_read_vpdata(fullfile(vpFilePath, 'text', vpFileName));
img = imread(fullfile(imgPath, imgName));
% =========================================================================
% Plane localization
% =========================================================================
modelPlane = sr_detect_plane_from_vp(vpData, img, opt);
% figure(1), imshow(modelPlane.postProb(:,:,1:3));
visVPFlag = 0;
if(visVPFlag)
[vpVis, planeVis] = vis_vp(img, vpData, modelPlane.postProb(:,:,1:3));
end
end
function [vpVis, planeVis] = vis_vp(img, vpData, postProb)
img = im2double(img);
[imgH, imgW, nCh] = size(img);
vpVis = zeros(imgH, imgW, nCh);
planeVis = zeros(imgH, imgW, nCh);
whiteImg = ones(imgH, imgW, nCh);
% blackImg = zeros()
alphaW = 0.5;
imgW = img*(1 - alphaW) + whiteImg*(alphaW);
% Plot VP
h1 = figure(1);
imshow(imgW); hold on;
lineWidth = 4;
for vpInd = 1: vpData.numVP
vpCurr = vpData.vp{vpInd};
for lineInd = 1: vpCurr.numLines
lineCur = vpCurr.lines(lineInd,:);
lineCur = lineCur + 1;
if(vpInd == 1)
plot(lineCur([1,3]), lineCur([2,4]), 'r', 'LineWidth', lineWidth);
elseif(vpInd == 2)
plot(lineCur([1,3]), lineCur([2,4]), 'g', 'LineWidth', lineWidth);
elseif(vpInd == 3)
plot(lineCur([1,3]), lineCur([2,4]), 'b', 'LineWidth', lineWidth);
end
end
end
hold off;
print(h1, '-dpng', fullfile('paper\planar_struct_SR_CVPR2015\figures\plane', 'vpdetection.png'));
% Plot posterior
alphaP = 0.9;
imgP = (1 - alphaP)*img + alphaP*postProb;
figure(2); imshow(imgP);
imwrite(imgP, fullfile('paper\planar_struct_SR_CVPR2015\figures\plane', 'planedetection.png'));
end
function vpData = sr_read_vpdata(fileName)
% SC_READ_VPDATA: read the data from vanishing point detection algorithm
% Input:
% - fileName: the txt file containing the pre-computed vanishing point
% detection code
% Output:
% - vpData
% The data structure of vpData
% - vpData.numVP: number of detected vanishing points
% - vpData.vp{i}.pos: the vanishing point position in the homogenous coordiante
% - vpData.vp{i}.score: the score of the vanishing point
% - vpData.vp{i}.numLines: number of lines supporting the vanishing point
% - vpData.vp{i}.lines{j}.p1: (x1, y1): starting position
% - vpData.vp{i}.lines{j}.p2: (x2, y2): ending position
% - vpData.vp{i}.lines{j}.length: length of the line segment
vpData = [];
% Read data
fid = fopen(fileName);
%% Parse VP positions
temp = fscanf(fid, '%s ', [1 5]);
numVP = 0;
readVPFlag = 1;
VP = [];
while(readVPFlag)
numVP = numVP + 1;
vpCurr = fscanf(fid, '%g %g %g %g %g', [5 1]);
if(~isempty(vpCurr))
VP(:,numVP) = vpCurr;
else
temp = fscanf(fid, '%s ', [1 6]);
readVPFlag = 0;
end
end
VP = VP';
vpData.numVP = size(VP, 1);
% Save VP position data
for i = 1: vpData.numVP
vpData.vp{i}.pos = VP(i, 1:3);
vpData.vp{i}.score = VP(i, 4);
vpData.vp{i}.numLines = VP(i, 5);
end
%% Parse each set of line segments for the corresponding VP
for i = 1: vpData.numVP
numLine = fscanf(fid, '%d ', [1 1]);
lines = fscanf(fid, '%g %g %g %g %g', [5 numLine]);
vpData.vp{i}.lines = lines';
end
fclose(fid);
end
function modelPlane = sr_detect_plane_from_vp(vpData, img, opt)
% SC_DETECT_PLANE_FROM_VP: simple plane detection algorithm
% Input:
% - vpData: vanishing point data
% - img: input image
% - mask: hole mask
% Output:
% - modelPlane
%%
modelPlane = [];
% === Setting up ===
[imgH, imgW, ch] = size(img);
HfilterX = fspecial('gaussian', [1, opt.filterSize], opt.filterSigma);
HfilterY = HfilterX';
% fspecial('gaussian', opt.filterSize, opt.filterSigma);
img = im2double(img);
% === Supporting lines spatial support estimation ===
shapeInserter = vision.ShapeInserter('Shape', 'Lines','BorderColor', 'White');
for i = 1: vpData.numVP
% The support lines
imgLines = zeros(imgH, imgW);
imgLines = step(shapeInserter, imgLines, int16(round(vpData.vp{i}.lines(:,1:4))));
% Spatial density estimation via blurring
imgLinesPosMap = imgLines;
for k = 1:opt.numFilterIter
imgLinesPosMap = imfilter(imgLinesPosMap, HfilterX, 'conv', 'replicate');
end
for k = 1:opt.numFilterIter
imgLinesPosMap = imfilter(imgLinesPosMap, HfilterY, 'conv', 'replicate');
end
% Save results
modelPlane.vp{i}.imgLines = imgLines;
modelPlane.vp{i}.imgLinesPosMap = imgLinesPosMap;
end
% === Estimate plane support and plane parameters ===
numPlane = (vpData.numVP)*(vpData.numVP-1)/2;
% Initialize plane data
modelPlane.plane = cell(numPlane, 1);
indPlane = 1;
% A pair of vanishing points forms a plane hypothesis
for i = 1: vpData.numVP - 1
for j = i+1: vpData.numVP
% Compute the vanishing line
modelPlane.plane{indPlane}.vLine = vLineFromTwoVP(vpData.vp{i}.pos, vpData.vp{j}.pos);
% Element-wise product of two support line density
modelPlane.plane{indPlane}.imgPlaneProb = modelPlane.vp{i}.imgLinesPosMap.*modelPlane.vp{j}.imgLinesPosMap; % Product of two probability maps
% modelPlane.plane{indPlane}.imgPlaneProb(mask) = 1e-10;
modelPlane.plane{indPlane}.sourceVP = [i, j];
indPlane = indPlane + 1;
end
end
% === Compute rectified rotation parameters ===
for i = 1: numPlane
for vpInd = 1: 2
linesCurr = vpData.vp{modelPlane.plane{i}.sourceVP(vpInd)}.lines;
invalidLineInd = linesCurr(:,5) == 0;
linesCurr = linesCurr(~invalidLineInd,:);
numLines = size(linesCurr, 1);
vLineCurr = modelPlane.plane{i}.vLine;
% Rectified homography
H = eye(3);
H(3,:) = vLineCurr;
end
end
% === Add a fronto-parallel plane ===
modelPlane.plane{indPlane}.vLine = [0 0 1];
modelPlane.plane{indPlane}.imgPlaneProb = opt.fpPlaneProb*ones(imgH, imgW);
modelPlane.plane{indPlane}.score = sum(modelPlane.plane{indPlane}.imgPlaneProb(:));
numPlane = numPlane + 1;
modelPlane.numPlane = numPlane;
% === Compute posterior probability ===
planeProb = zeros(imgH, imgW, numPlane);
for i = 1 : numPlane
planeProb(:,:,i) = modelPlane.plane{i}.imgPlaneProb;
end
planeProbSum = sum(planeProb, 3);
planeProb = bsxfun(@rdivide, planeProb, planeProbSum);
planeProb = planeProb + 0.1; % blur the posterior map
planeProb = bsxfun(@rdivide, planeProb, sum(planeProb, 3));
modelPlane.postProb = planeProb;
end
function vLine = vLineFromTwoVP(vp1, vp2)
A = cat(1, vp1, vp2);
[U S V] = svd(A, 0);
vLine = V(:,end);
vLine = vLine/vLine(3); % [h7, h8, 1]
end
|
(* Title: HOL/HOLCF/Adm.thy
Author: Franz Regensburger and Brian Huffman
*)
section {* Admissibility and compactness *}
theory Adm
imports Cont
begin
default_sort cpo
subsection {* Definitions *}
definition
adm :: "('a::cpo \<Rightarrow> bool) \<Rightarrow> bool" where
"adm P = (\<forall>Y. chain Y \<longrightarrow> (\<forall>i. P (Y i)) \<longrightarrow> P (\<Squnion>i. Y i))"
lemma admI:
"(\<And>Y. \<lbrakk>chain Y; \<forall>i. P (Y i)\<rbrakk> \<Longrightarrow> P (\<Squnion>i. Y i)) \<Longrightarrow> adm P"
unfolding adm_def by fast
lemma admD: "\<lbrakk>adm P; chain Y; \<And>i. P (Y i)\<rbrakk> \<Longrightarrow> P (\<Squnion>i. Y i)"
unfolding adm_def by fast
lemma admD2: "\<lbrakk>adm (\<lambda>x. \<not> P x); chain Y; P (\<Squnion>i. Y i)\<rbrakk> \<Longrightarrow> \<exists>i. P (Y i)"
unfolding adm_def by fast
lemma triv_admI: "\<forall>x. P x \<Longrightarrow> adm P"
by (rule admI, erule spec)
subsection {* Admissibility on chain-finite types *}
text {* For chain-finite (easy) types every formula is admissible. *}
lemma adm_chfin [simp]: "adm (P::'a::chfin \<Rightarrow> bool)"
by (rule admI, frule chfin, auto simp add: maxinch_is_thelub)
subsection {* Admissibility of special formulae and propagation *}
lemma adm_const [simp]: "adm (\<lambda>x. t)"
by (rule admI, simp)
lemma adm_conj [simp]:
"\<lbrakk>adm (\<lambda>x. P x); adm (\<lambda>x. Q x)\<rbrakk> \<Longrightarrow> adm (\<lambda>x. P x \<and> Q x)"
by (fast intro: admI elim: admD)
lemma adm_all [simp]:
"(\<And>y. adm (\<lambda>x. P x y)) \<Longrightarrow> adm (\<lambda>x. \<forall>y. P x y)"
by (fast intro: admI elim: admD)
lemma adm_ball [simp]:
"(\<And>y. y \<in> A \<Longrightarrow> adm (\<lambda>x. P x y)) \<Longrightarrow> adm (\<lambda>x. \<forall>y\<in>A. P x y)"
by (fast intro: admI elim: admD)
text {* Admissibility for disjunction is hard to prove. It requires 2 lemmas. *}
lemma adm_disj_lemma1:
assumes adm: "adm P"
assumes chain: "chain Y"
assumes P: "\<forall>i. \<exists>j\<ge>i. P (Y j)"
shows "P (\<Squnion>i. Y i)"
proof -
def f \<equiv> "\<lambda>i. LEAST j. i \<le> j \<and> P (Y j)"
have chain': "chain (\<lambda>i. Y (f i))"
unfolding f_def
apply (rule chainI)
apply (rule chain_mono [OF chain])
apply (rule Least_le)
apply (rule LeastI2_ex)
apply (simp_all add: P)
done
have f1: "\<And>i. i \<le> f i" and f2: "\<And>i. P (Y (f i))"
using LeastI_ex [OF P [rule_format]] by (simp_all add: f_def)
have lub_eq: "(\<Squnion>i. Y i) = (\<Squnion>i. Y (f i))"
apply (rule below_antisym)
apply (rule lub_mono [OF chain chain'])
apply (rule chain_mono [OF chain f1])
apply (rule lub_range_mono [OF _ chain chain'])
apply clarsimp
done
show "P (\<Squnion>i. Y i)"
unfolding lub_eq using adm chain' f2 by (rule admD)
qed
lemma adm_disj_lemma2:
"\<forall>n::nat. P n \<or> Q n \<Longrightarrow> (\<forall>i. \<exists>j\<ge>i. P j) \<or> (\<forall>i. \<exists>j\<ge>i. Q j)"
apply (erule contrapos_pp)
apply (clarsimp, rename_tac a b)
apply (rule_tac x="max a b" in exI)
apply simp
done
lemma adm_disj [simp]:
"\<lbrakk>adm (\<lambda>x. P x); adm (\<lambda>x. Q x)\<rbrakk> \<Longrightarrow> adm (\<lambda>x. P x \<or> Q x)"
apply (rule admI)
apply (erule adm_disj_lemma2 [THEN disjE])
apply (erule (2) adm_disj_lemma1 [THEN disjI1])
apply (erule (2) adm_disj_lemma1 [THEN disjI2])
done
lemma adm_imp [simp]:
"\<lbrakk>adm (\<lambda>x. \<not> P x); adm (\<lambda>x. Q x)\<rbrakk> \<Longrightarrow> adm (\<lambda>x. P x \<longrightarrow> Q x)"
by (subst imp_conv_disj, rule adm_disj)
lemma adm_iff [simp]:
"\<lbrakk>adm (\<lambda>x. P x \<longrightarrow> Q x); adm (\<lambda>x. Q x \<longrightarrow> P x)\<rbrakk>
\<Longrightarrow> adm (\<lambda>x. P x = Q x)"
by (subst iff_conv_conj_imp, rule adm_conj)
text {* admissibility and continuity *}
lemma adm_below [simp]:
"\<lbrakk>cont (\<lambda>x. u x); cont (\<lambda>x. v x)\<rbrakk> \<Longrightarrow> adm (\<lambda>x. u x \<sqsubseteq> v x)"
by (simp add: adm_def cont2contlubE lub_mono ch2ch_cont)
lemma adm_eq [simp]:
"\<lbrakk>cont (\<lambda>x. u x); cont (\<lambda>x. v x)\<rbrakk> \<Longrightarrow> adm (\<lambda>x. u x = v x)"
by (simp add: po_eq_conv)
lemma adm_subst: "\<lbrakk>cont (\<lambda>x. t x); adm P\<rbrakk> \<Longrightarrow> adm (\<lambda>x. P (t x))"
by (simp add: adm_def cont2contlubE ch2ch_cont)
lemma adm_not_below [simp]: "cont (\<lambda>x. t x) \<Longrightarrow> adm (\<lambda>x. t x \<notsqsubseteq> u)"
by (rule admI, simp add: cont2contlubE ch2ch_cont lub_below_iff)
subsection {* Compactness *}
definition
compact :: "'a::cpo \<Rightarrow> bool" where
"compact k = adm (\<lambda>x. k \<notsqsubseteq> x)"
lemma compactI: "adm (\<lambda>x. k \<notsqsubseteq> x) \<Longrightarrow> compact k"
unfolding compact_def .
lemma compactD: "compact k \<Longrightarrow> adm (\<lambda>x. k \<notsqsubseteq> x)"
unfolding compact_def .
lemma compactI2:
"(\<And>Y. \<lbrakk>chain Y; x \<sqsubseteq> (\<Squnion>i. Y i)\<rbrakk> \<Longrightarrow> \<exists>i. x \<sqsubseteq> Y i) \<Longrightarrow> compact x"
unfolding compact_def adm_def by fast
lemma compactD2:
"\<lbrakk>compact x; chain Y; x \<sqsubseteq> (\<Squnion>i. Y i)\<rbrakk> \<Longrightarrow> \<exists>i. x \<sqsubseteq> Y i"
unfolding compact_def adm_def by fast
lemma compact_below_lub_iff:
"\<lbrakk>compact x; chain Y\<rbrakk> \<Longrightarrow> x \<sqsubseteq> (\<Squnion>i. Y i) \<longleftrightarrow> (\<exists>i. x \<sqsubseteq> Y i)"
by (fast intro: compactD2 elim: below_lub)
lemma compact_chfin [simp]: "compact (x::'a::chfin)"
by (rule compactI [OF adm_chfin])
lemma compact_imp_max_in_chain:
"\<lbrakk>chain Y; compact (\<Squnion>i. Y i)\<rbrakk> \<Longrightarrow> \<exists>i. max_in_chain i Y"
apply (drule (1) compactD2, simp)
apply (erule exE, rule_tac x=i in exI)
apply (rule max_in_chainI)
apply (rule below_antisym)
apply (erule (1) chain_mono)
apply (erule (1) below_trans [OF is_ub_thelub])
done
text {* admissibility and compactness *}
lemma adm_compact_not_below [simp]:
"\<lbrakk>compact k; cont (\<lambda>x. t x)\<rbrakk> \<Longrightarrow> adm (\<lambda>x. k \<notsqsubseteq> t x)"
unfolding compact_def by (rule adm_subst)
lemma adm_neq_compact [simp]:
"\<lbrakk>compact k; cont (\<lambda>x. t x)\<rbrakk> \<Longrightarrow> adm (\<lambda>x. t x \<noteq> k)"
by (simp add: po_eq_conv)
lemma adm_compact_neq [simp]:
"\<lbrakk>compact k; cont (\<lambda>x. t x)\<rbrakk> \<Longrightarrow> adm (\<lambda>x. k \<noteq> t x)"
by (simp add: po_eq_conv)
lemma compact_bottom [simp, intro]: "compact \<bottom>"
by (rule compactI, simp)
text {* Any upward-closed predicate is admissible. *}
lemma adm_upward:
assumes P: "\<And>x y. \<lbrakk>P x; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> P y"
shows "adm P"
by (rule admI, drule spec, erule P, erule is_ub_thelub)
lemmas adm_lemmas =
adm_const adm_conj adm_all adm_ball adm_disj adm_imp adm_iff
adm_below adm_eq adm_not_below
adm_compact_not_below adm_compact_neq adm_neq_compact
end
|
```julia
using NPZ
using PyPlot
using SpecialFunctions
```
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused
(.:14921): Gdk-CRITICAL **: 18:21:09.991: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
(.:14921): Gdk-CRITICAL **: 18:21:10.006: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
<a id='table_of_contents'></a>
# Table of Contents
1. [Loading crystal data](#loading_crystal_data)
2. [Sorting $i,j,k$](#sorting_ijk)
3. [Manybody potential at single $z$-slice](#manybody_potential_at_single_z-slice)
4. [3D manybody potential](#3d_manybody_potential)
<a id='loading_crystal_data'></a>
## Loading crystal data
[Table of Contents](#table_of_contents)
First, we load the data generated from [this notebook](effective_parameters_to_cylindrical_potential_MCM-41_PYTHON.ipynb).
```julia
#xyz atom positions withn the unit cell
mcm41_xyz_shifted = NPZ.npzread("data/mcm41_xyz_shifted_CVFF.npz");
mcm41_x = mcm41_xyz_shifted["x"];
mcm41_y = mcm41_xyz_shifted["y"];
mcm41_z = mcm41_xyz_shifted["z"];
#mixed sigma and epsilon parameters for the Lennard-Jones potential (helium and MCM-41 atoms)
sigma = mcm41_xyz_shifted["sigma"];
epsilon = mcm41_xyz_shifted["epsilon"];
```
```julia
#lattice vectors for MCM-41 unit cell
mcm41_lattice_vectors = NPZ.npzread("data/mcm41_lattice_vectors.npz");
A1 = mcm41_lattice_vectors["A1"];
A2 = mcm41_lattice_vectors["A2"];
A3 = mcm41_lattice_vectors["A3"];
```
Recall, we wish to generate the manybody potential within a single pore by summing a 12-6 Lennard-Jones potential over the atoms within a semi-infinite MCM-41 supercell
\begin{equation}
U_\mathrm{MCM-41}^\mathrm{He}(\vec{r}) = \sum_{i,j,k = -\infty}^\infty \sum_\alpha^N 4\varepsilon_\alpha \biggl( \frac{\sigma_\alpha^{12}}{\lvert \vec{r} - \vec{r}_{ijk\alpha}\rvert^{12}} - \frac{\sigma_\alpha^6}{\lvert \vec{r} - \vec{r}_{ijk\alpha}\rvert^6} \biggr)
\end{equation}
where $\alpha$ indexes over each atom within the unit cell, $\varepsilon_\alpha$ and $\sigma_\alpha$ are the appropriately mixed Lennard-Jones parameters, and
\begin{equation}
\vec{r}_{ijk\alpha} = \vec{r}_\alpha + i\vec{A}_a + j\vec{A}_b + k\vec{A}_c
\end{equation}
is the position of each atom within the semi-infinite supercell with unit cell vectors $\vec{A}_{\{a,b,c\}}$.
The procedure will be to expand the unit cell in each unit cell direction and perform the summation until we reach the single precision floating point limit. Here we show a birds-eye view example of expanding once in each lattice vector direction.
```julia
fig,ax = subplots(figsize=(10,10))
k = 0
for i in -1:1:1
for j in -1:1:1
_A = ((i .* A1) .+ (j .* A2) .+ (k .* A3))
ax.scatter(mcm41_x .+ _A[1], mcm41_y .+ _A[2])
end
end
ax.set_xlabel(L"$x\ \mathrm{[\AA]}$")
ax.set_ylabel(L"$y\ \mathrm{[\AA]}$")
arrowprops = PyPlot.PyDict()
arrowprops["arrowstyle"]="->"
arrowprops["shrinkA"]=0.0
arrowprops["shrinkB"]=0.0
ax.annotate("", xy=(A1[1], A1[2]), xytext=(0, 0), arrowprops=arrowprops)
ax.annotate(L"$\vec{A}_a$", xy=(A1[1], A1[2]))
ax.annotate("", xy=(A2[1], A2[2]), xytext=(0, 0), arrowprops=arrowprops)
ax.annotate(L"$\vec{A}_b$", xy=(A2[1], A2[2]))
ax.set_aspect("equal")
```
<a id='sorting_ijk'></a>
## Sorting $i,j,k$
[Table of Contents](#table_of_contents)
We created a sorted array over the summation integers $i,j,k$ since the atoms closest to the central pore will contribute the most the the manybody potential. The array is sorted by $\lvert\vec{r}_{ijk}\rvert=\lvert i\vec{A}_a + j\vec{A}_b + k\vec{A}_c \rvert$.
```julia
# we create a large collection of ijk indices
i_arr = collect(-200:1:200);
j_arr = collect(-200:1:200);
k_arr = collect(-200:1:200);
r_arr = Array{Float64,3}(undef,size(i_arr,1),size(j_arr,1),size(k_arr,1));
```
```julia
# Here we find the magnitude to center of each replicated unit cell within the very large supercell
for i in i_arr
for j in j_arr
for k in k_arr
_A = ((i .* A1) .+ (j .* A2) .+ (k .* A3));
_r = sqrt(sum(_A.^2))
r_arr[i+201,j+201,k+201] = _r
end
end
end
```
```julia
#initialize and fill the arrays to hold the combinations of ijk
_i_arr = Array{Int64,3}(undef,size(i_arr,1),size(j_arr,1),size(k_arr,1));
_j_arr = Array{Int64,3}(undef,size(i_arr,1),size(j_arr,1),size(k_arr,1));
_k_arr = Array{Int64,3}(undef,size(i_arr,1),size(j_arr,1),size(k_arr,1));
for i in i_arr
for j in j_arr
for k in k_arr
_i_arr[i+201,j+201,k+201] = i
_j_arr[i+201,j+201,k+201] = j
_k_arr[i+201,j+201,k+201] = k
end
end
end
```
```julia
#flatten each ijk array and sort by the distance to each unit cell within the supercell
r_arr_flat = vec(r_arr);
_i_arr_flat = vec(_i_arr);
_j_arr_flat = vec(_j_arr);
_k_arr_flat = vec(_k_arr);
p = sortperm(r_arr_flat); #get the index for sorting by distance
r_arr_flat = r_arr_flat[p];
_i_arr_flat = _i_arr_flat[p];
_j_arr_flat = _j_arr_flat[p];
_k_arr_flat = _k_arr_flat[p];
```
<a id='manybody_potential_at_single_z-slice'></a>
## Manybody potential at single $z$-slice
[Table of Contents](#table_of_contents)
Now that we have sorted the summation indeces for a suitably large supercell, we can calculate the manybody potential at a single $z$-slice within a nanopore in the MCM-41. First we define the Lennard-Jones potential functions.
```julia
function U(r::Float64,sigma::Float64,epsilon::Float64)
pf = 4 * epsilon;
t12 = (sigma/r)^12;
t6 = (sigma/r)^6;
return pf * (t12 - t6)
end
function U(r::Float32,sigma::Float32,epsilon::Float32)
pf = 4 * epsilon;
t12 = (sigma/r)^12;
t6 = (sigma/r)^6;
return pf * (t12 - t6)
end
function U(r::Float64,sigma::Float64,epsilon::Float64)
pf = 4 * epsilon;
t12 = (sigma/r)^12;
t6 = (sigma/r)^6;
return pf * (t12 - t6)
end
function U_mb(r::Array{Float64,1},sigma::Array{Float64,1},epsilon::Array{Float64,1})
V = 0.0;
@inbounds for i in 1:size(r)
V += U(r[i],sigma[i],epsilon[i]);
end
return V
end
```
U_mb (generic function with 1 method)
Next, we generate a mesh of points in the xy-plane ecompassing the pore.
```julia
x_min = -20.0;
x_max = 20.0;
y_min = -20.0;
y_max = 20.0;
res = 101;
x = zeros(res,res);
y = zeros(res,res);
x_range = collect(range(x_min,x_max,length=res));
y_range = collect(range(y_min,y_max,length=res));
for i in 1:res
_x = x_range[i];
for j in 1:res
_y = y_range[j];
x[i,j] = _x;
y[i,j] = _y;
end
end
```
Now we convert some the variables to Julia Float32 types since we are calculating the manybody potential to within the single precision floating point limit.
```julia
r_tmp = zeros(Float32,size(x));
x32 = convert.(Float32,x);
y32 = convert.(Float32,y);
A1_32 = convert.(Float32,A1);
A2_32 = convert.(Float32,A2);
A3_32 = convert.(Float32,A3);
# We will look at the z-slice for z=0.0 Angstroms
Z_VALUE = 0.0;
Z_VALUE32 = convert(Float32,Z_VALUE);
V = zeros(Float32,size(x32));
V_old = zeros(Float32,size(x32));
```
Finally, everything is set up to generate the manybody potential at a single $z$-slice.
```julia
ii_max = 10000 #Set some maximum just in case
for ii = 1:ii_max
i = _i_arr_flat[ii];
j = _j_arr_flat[ii];
k = _k_arr_flat[ii];
for atom in 1:size(mcm41_x,1)
# get distance to single atom within supercell
r_tmp .= sqrt.(((mcm41_x[atom] + (A1_32[1]*i) + (A2_32[1]*j)) .- x32).^2 .+ ((mcm41_y[atom] + (A2_32[2]*j)) .- y32).^2 .+ ((mcm41_z[atom] + (A3_32[3]*k)) - Z_VALUE32)^2);
#Calculate the Lennard-Jones potential at the separation for helium and MCM-41 atom and increment the total potential
V .+= U.(r_tmp,sigma[atom],epsilon[atom])
end
if all(V .== V_old)
# if the old potential is the same as the new potential for
# every point within the xy-mesh, then we have reached the
# single precision floating point limit
println(ii) # Show progress for each slice iteration
break
elseif (ii == ii_max)
println("WARNING: ii_max reached")
break
else
# if we haven't reached the stopping critereon, copy current potential
copy!(V_old,V);
end
end
```
574
We have calculated the manybody potential for a single $z$-slice. Here is a view of the potential.
```julia
extent = (-20.0,20.0,-20.0,20.0)
fig,ax = plt.subplots()
im = ax.imshow(transpose(V),origin="lower",vmax=200,vmin=-200,extent=extent)
ax.set_xlabel(L"$x\ \mathrm{[\AA]}$")
ax.set_ylabel(L"$y\ \mathrm{[\AA]}$")
fig.colorbar(im)
```
<a id='3d_manybody_potential'></a>
## 3D manybody potential
[Table of Contents](#table_of_contents)
Now that we have seen how to calculate the manybody potential for a single slice, we are ready to caculate the full 3D manybody potential. Here, we will calculate from the bottom of the single unitcell to the top.
```julia
z_min = -A3[3]/2; # bottom of unit cell
z_max = A3[3]/2; # top of unit cell
z_range = collect(range(z_min,z_max,length=res));
V_3D = zeros(Float32,size(x32,1),size(x32,2),res); # initialize 3D potential
```
```julia
for jj in 1:res
print("jj = $jj: ") # A more descriptive output for each slice
Z_VALUE = z_range[jj];
Z_VALUE32 = convert(Float32,Z_VALUE);
V = zeros(Float32,size(x32));
V_old = zeros(Float32,size(x32));
ii_max = 10000
for ii = 1:ii_max
i = _i_arr_flat[ii];
j = _j_arr_flat[ii];
k = _k_arr_flat[ii];
for atom in 1:size(mcm41_x,1)
r_tmp .= sqrt.(((mcm41_x[atom] + (A1_32[1]*i) + (A2_32[1]*j)) .- x32).^2 .+ ((mcm41_y[atom] + (A2_32[2]*j)) .- y32).^2 .+ ((mcm41_z[atom] + (A3_32[3]*k)) - Z_VALUE32)^2);
V .+= U.(r_tmp,sigma[atom],epsilon[atom])
end
if all(V .== V_old)
println(ii)
break
elseif (ii == ii_max)
break
else
copy!(V_old,V);
end
end
V_3D[:,:,jj] .= V;
end
```
jj = 1: 1009
jj = 2: 383
jj = 3: 1402
jj = 4: 575
jj = 5: 1010
jj = 6: 383
jj = 7: 557
jj = 8: 575
jj = 9: 1471
jj = 10: 2078
jj = 11: 385
jj = 12: 587
jj = 13: 313
jj = 14: 1083
jj = 15: 383
jj = 16: 313
jj = 17: 575
jj = 18: 704
jj = 19: 575
jj = 20: 1404
jj = 21: 575
jj = 22: 441
jj = 23: 739
jj = 24: 385
jj = 25: 575
jj = 26: 1180
jj = 27: 2117
jj = 28: 739
jj = 29: 1143
jj = 30: 312
jj = 31: 431
jj = 32: 440
jj = 33: 1143
jj = 34: 1180
jj = 35: 312
jj = 36: 2877
jj = 37: 1143
jj = 38: 575
jj = 39: 794
jj = 40: 849
jj = 41: 709
jj = 42: 312
jj = 43: 848
jj = 44: 3022
jj = 45: 689
jj = 46: 501
jj = 47: 440
jj = 48: 849
jj = 49: 836
jj = 50: 440
jj = 51: 574
jj = 52: 440
jj = 53: 849
jj = 54: 1530
jj = 55: 574
jj = 56: 789
jj = 57: 440
jj = 58: 440
jj = 59: 1394
jj = 60: 574
jj = 61: 1595
jj = 62: 1180
jj = 63: 312
jj = 64: 551
jj = 65: 2103
jj = 66: 1494
jj = 67: 574
jj = 68: 574
jj = 69: 428
jj = 70: 312
jj = 71: 312
jj = 72: 2116
jj = 73: 574
jj = 74: 1136
jj = 75: 574
jj = 76: 554
jj = 77: 428
jj = 78: 312
jj = 79: 5830
jj = 80: 312
jj = 81: 550
jj = 82: 738
jj = 83: 426
jj = 84: 1470
jj = 85: 312
jj = 86: 2116
jj = 87: 738
jj = 88: 427
jj = 89: 738
jj = 90: 574
jj = 91: 378
jj = 92: 440
jj = 93: 514
jj = 94: 555
jj = 95: 550
jj = 96: 374
jj = 97: 374
jj = 98: 468
jj = 99: 252
jj = 100: 519
jj = 101: 1005
Now that we have the 3D manybody potential, we can save it and continue our analysis in the [effective parameters to cylindrical potential notebook](effective_parameters_to_cylindrical_potential_MCM-41_PYTHON.ipynb#determining_the_effective_parameters_to_cylindrical_potential).
```julia
NPZ.npzwrite("data/V_3D_-20.0_20.0_-20.0_20.0_-6.10_6.10_101_CVFF.npz",
Dict("x_range" => convert.(Float32,x_range),
"y_range" => convert.(Float32,y_range),
"z_range" => convert.(Float32,z_range),
"V" => V_3D,
"x_grid" => x32,
"y_grid" => y32,
"extent" => convert.(Float32,[x_min,x_max,y_min,y_max])
))
```
|
Require Import Crypto.Arithmetic.PrimeFieldTheorems.
Require Import Crypto.Specific.montgomery32_2e251m9_8limbs.Synthesis.
(* TODO : change this to field once field isomorphism happens *)
Definition opp :
{ opp : feBW_small -> feBW_small
| forall a, phiM_small (opp a) = F.opp (phiM_small a) }.
Proof.
Set Ltac Profiling.
Time synthesize_opp ().
Show Ltac Profile.
Time Defined.
Print Assumptions opp.
|
[GOAL]
α : Type u
⊢ Inhabited (FreeRing α)
[PROOFSTEP]
dsimp only [FreeRing]
[GOAL]
α : Type u
⊢ Inhabited (FreeAbelianGroup (FreeMonoid α))
[PROOFSTEP]
infer_instance
[GOAL]
α : Type u
C : FreeRing α → Prop
z : FreeRing α
hn1 : C (-1)
hb : ∀ (b : α), C (of b)
ha : ∀ (x y : FreeRing α), C x → C y → C (x + y)
hm : ∀ (x y : FreeRing α), C x → C y → C (x * y)
hn : ∀ (x : FreeRing α), C x → C (-x)
h1 : C 1
m✝ : FreeMonoid α
a : α
m : List α
ih : C (FreeAbelianGroup.of m)
⊢ C (FreeAbelianGroup.of (a :: m))
[PROOFSTEP]
convert hm _ _ (hb a) ih
[GOAL]
case h.e'_1
α : Type u
C : FreeRing α → Prop
z : FreeRing α
hn1 : C (-1)
hb : ∀ (b : α), C (of b)
ha : ∀ (x y : FreeRing α), C x → C y → C (x + y)
hm : ∀ (x y : FreeRing α), C x → C y → C (x * y)
hn : ∀ (x : FreeRing α), C x → C (-x)
h1 : C 1
m✝ : FreeMonoid α
a : α
m : List α
ih : C (FreeAbelianGroup.of m)
⊢ FreeAbelianGroup.of (a :: m) = of a * FreeAbelianGroup.of m
[PROOFSTEP]
rw [of, ← FreeAbelianGroup.of_mul]
[GOAL]
case h.e'_1
α : Type u
C : FreeRing α → Prop
z : FreeRing α
hn1 : C (-1)
hb : ∀ (b : α), C (of b)
ha : ∀ (x y : FreeRing α), C x → C y → C (x + y)
hm : ∀ (x y : FreeRing α), C x → C y → C (x * y)
hn : ∀ (x : FreeRing α), C x → C (-x)
h1 : C 1
m✝ : FreeMonoid α
a : α
m : List α
ih : C (FreeAbelianGroup.of m)
⊢ FreeAbelianGroup.of (a :: m) = FreeAbelianGroup.of (FreeMonoid.of a * m)
[PROOFSTEP]
rfl
|
\documentclass{ctexart}
\usepackage{bbm}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\graphicspath{{images/}}
\usepackage[backend=biber, style=numeric, sorting=ynt]{biblatex}
\addbibresource{refs.bib}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{subfiles}
\title{You Only Look Once:\\Unified, Real-Time Object Detection}
\author{Joseph Redmon, Santosh Divvala, Ross Girshick, Ali Farhadi}
\date{}
\begin{document}
\maketitle
\begin{abstract}
\subfile{sections/abstract}
\end{abstract}
\section{Introduction}
\subfile{sections/introduction}
\section{Unified Detection}
\subfile{sections/detection}
\printbibliography
\end{document}
|
//
// editor.hpp
// PretendToWork
//
// Created by tqtifnypmb on 14/12/2017.
// Copyright © 2017 tqtifnypmb. All rights reserved.
//
#pragma once
#include "../crdt/Engine.h"
#include "../types.h"
#include <memory>
#include <gsl/gsl>
#include <map>
namespace brick
{
class Rope;
class Editor {
public:
using DeltaList = std::vector<std::tuple<Revision, size_t, size_t>>; // [(delta, begRow, endRow)]
using SyncCb = std::function<void(const Editor::DeltaList& deltaList)>;
Editor(size_t viewId, const detail::CodePointList& cplist, SyncCb syncCb);
Editor(size_t viewId, SyncCb syncCb);
template <class Converter>
void insert(gsl::span<const char> bytes, size_t pos);
void insert(const detail::CodePointList& cplist, size_t pos);
void erase(Range range);
void undo();
void sync(Editor& editor);
std::map<size_t, detail::CodePointList> region(size_t begLine, size_t endLine);
void clearRevisions() {
engine_.revisions().clear();
}
private:
Editor::DeltaList convertEngineDelta(const Engine::DeltaList& deltas);
void updateLines(size_t pos, const detail::CodePointList& cplist);
void updateLines(Range r);
std::unique_ptr<Rope> rope_;
Engine engine_;
std::vector<size_t> linesIndex_;
SyncCb sync_cb_;
};
template <class Converter>
void Editor::insert(gsl::span<const char> bytes, size_t pos) {
insert(Converter::encode(bytes), pos);
}
} // namespace brick
|
open classical
/- Fill in the `sorry`s below -/
local attribute [instance, priority 0] prop_decidable
example (p : Prop) : p ∨ ¬ p :=
begin
by_cases p,
{ sorry },
{ sorry }
end
example (p : Prop) : p ∨ ¬ p :=
begin
by_cases h' : p,
{ sorry },
{ sorry }
end
/-
Give a calculational proof of the theorem log_mul below. You can use the
rewrite tactic `rw` (and `calc` if you want), but not `simp`.
These objects are actually defined in mathlib, but for now, we'll
just declare them.
-/
constant real : Type
@[instance] constant orreal : ordered_ring real
constants (log exp : real → real)
constant log_exp_eq : ∀ x, log (exp x) = x
constant exp_log_eq : ∀ {x}, x > 0 → exp (log x) = x
constant exp_pos : ∀ x, exp x > 0
constant exp_add : ∀ x y, exp (x + y) = exp x * exp y
example (x y z : real) :
exp (x + y + z) = exp x * exp y * exp z :=
sorry
example (y : real) (h : y > 0) : exp (log y) = y :=
sorry
theorem log_mul' {x y : real} (hx : x > 0) (hy : y > 0) :
log (x * y) = log x + log y :=
sorry
section
variables {p q r : Prop}
example : (p → q) → (¬q → ¬p) :=
sorry
example : (p → (q → r)) → (p ∧ q → r) :=
sorry
example : p ∧ ¬q → ¬(p → q) :=
sorry
example : (¬p ∨ q) → (p → q) :=
sorry
example : (p ∨ q → r) → (p → r) ∧ (q → r) :=
sorry
example : (p → q) → (¬p ∨ q) :=
sorry
end
section
variables {α β : Type} (p q : α → Prop) (r : α → β → Prop)
example : (∀ x, p x) ∧ (∀ x, q x) → ∀ x, p x ∧ q x :=
sorry
example : (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x :=
sorry
example : (∃ x, ∀ y, r x y) → ∀ y, ∃ x, r x y :=
sorry
theorem e1 : (¬ ∃ x, p x) → ∀ x, ¬ p x :=
sorry
example : (¬ ∀ x, ¬ p x) → ∃ x, p x :=
sorry
example : (¬ ∀ x, ¬ p x) → ∃ x, p x :=
sorry
end
section
/-
There is a man in the town who is the barber. The barber shaves all men who do not shave themselves.
Does the barber shave himself?
-/
variables (man : Type) (barber : man)
variable (shaves : man → man → Prop)
example (H : ∀ x : man, shaves barber x ↔ ¬ shaves x x) : false :=
sorry
end
section
variables {α : Type} (p : α → Prop) (r : Prop) (a : α)
include a
example : (r → ∃ x, p x) → ∃ x, (r → p x) :=
sorry
end
/-
Prove the theorem below, using only the ring properties of ℤ enumerated
in Section 4.2 and the theorem sub_self. You should probably work out
a pen-and-paper proof first.
-/
example (x : ℤ) : x * 0 = 0 :=
sorry
section
open list
variable {α : Type*}
variables s t : list α
variable a : α
example : length (s ++ t) = length s + length t :=
sorry
end
/-
Define an inductive data type consisting of terms built up from the
following constructors:
`const n`, a constant denoting the natural number n
`var n`, a variable, numbered n
`plus s t`, denoting the sum of s and t
`times s t`, denoting the product of s and t
-/
inductive nat_term
| const : ℕ → nat_term
| var : ℕ → nat_term
| plus : nat_term → nat_term → nat_term
| times : nat_term → nat_term → nat_term
open nat_term
/-
Recursively define a function that evaluates any such term with respect to
an assignment `val : ℕ → ℕ` of values to the variables.
For example, if `val 4 = 3
-/
def eval (val : ℕ → ℕ) : nat_term → ℕ
| (const k) := k
| (var k) := val k
| (plus s t) := (eval s) + (eval t)
| (times s t) := (eval s) * (eval t)
/-
Test it out by using #eval on some terms. You can use the following `val` function. In that case, for example, we would expect to have
eval val (plus (const 2) (var 1)) = 5
-/
def val : ℕ → ℕ
| 0 := 4
| 1 := 3
| 2 := 8
| _ := 0
example : eval val (plus (const 2) (var 1)) = 5 := rfl
#eval eval val (plus (const 2) (var 1))
/-
Below, we define a function `rev` that reverses a list. It uses an auxiliary function
`append1`.
If you can, prove that the length of the list is preserved, and that
`rev (rev l) = l` for every `l`. The theorem below is given as an example, and should
be helpful.
Note that when you use the equation compiler to define a function foo, `rw [foo]` uses
one of the defining equations if it can. For example, `rw [append1, ...]` in the theorem
uses the second equation in the definition of `append1`
-/
section
open list
variable {α : Type*}
def append1 (a : α) : list α → list α
| nil := [a]
| (b :: l) := b :: (append1 l)
def rev : list α → list α
| nil := nil
| (a :: l) := append1 a (rev l)
theorem length_append1 (a : α) (l : list α): length (append1 a l) = length l + 1 :=
sorry
theorem length_rev (l : list α) : length (rev l) = length l :=
sorry
lemma hd_rev (a : α) (l : list α) :
a :: rev l = rev (append1 a l) :=
sorry
theorem rev_rev (l : list α) : rev (rev l) = l :=
sorry
end
|
function sev = read_tdt_sev(filename, dtype, begsample, endsample)
% READ_TDT_SEV
%
% Use as
% sev = read_tdt_sev(filename, dtype, begsample, endsample)
%
% Note: sev files contain raw broadband data that is streamed to the RS4
fid = fopen(filename, 'rb', 'ieee-le');
if nargin<3
begsample = 1;
end
if nargin<4
endsample = inf;
end
switch dtype
case 0
fmt = 'float32';
wsize = 4;
case 1
fmt = 'int32';
wsize = 4;
case 2
fmt = 'int16';
wsize = 2;
case 3
fmt = 'int8';
wsize = 1;
case 4
fmt = 'double';
wsize = 8;
case 5
error('don''t know what a DFORM_QWORD is');
otherwise
error('unknown dtype');
end
fseek(fid, begsample*wsize, 'cof');
sev = fread(fid, endsample-begsample, fmt);
fclose(fid);
|
\section{\module{EasyDialogs} ---
Basic Macintosh dialogs}
\declaremodule{standard}{EasyDialogs}
\platform{Mac}
\modulesynopsis{Basic Macintosh dialogs.}
The \module{EasyDialogs} module contains some simple dialogs for
the Macintosh, modelled after the
\module{stdwin}\refbimodindex{stdwin} dialogs with similar names. All
routines have an optional parameter \var{id} with which you can
override the DLOG resource used for the dialog, as long as the item
numbers correspond. See the source for details.
The \module{EasyDialogs} module defines the following functions:
\begin{funcdesc}{Message}{str}
A modal dialog with the message text \var{str}, which should be at
most 255 characters long, is displayed. Control is returned when the
user clicks ``OK''.
\end{funcdesc}
\begin{funcdesc}{AskString}{prompt\optional{, default}}
Ask the user to input a string value, in a modal dialog. \var{prompt}
is the promt message, the optional \var{default} arg is the initial
value for the string. All strings can be at most 255 bytes
long. \function{AskString()} returns the string entered or \code{None}
in case the user cancelled.
\end{funcdesc}
\begin{funcdesc}{AskYesNoCancel}{question\optional{, default}}
Present a dialog with text \var{question} and three buttons labelled
``yes'', ``no'' and ``cancel''. Return \code{1} for yes, \code{0} for
no and \code{-1} for cancel. The default return value chosen by
hitting return is \code{0}. This can be changed with the optional
\var{default} argument.
\end{funcdesc}
\begin{funcdesc}{ProgressBar}{\optional{label\optional{, maxval}}}
Display a modeless progress dialog with a thermometer bar. \var{label}
is the text string displayed (default ``Working...''), \var{maxval} is
the value at which progress is complete (default \code{100}). The
returned object has one method, \code{set(\var{value})}, which sets
the value of the progress bar. The bar remains visible until the
object returned is discarded.
The progress bar has a ``cancel'' button, but it is currently
non-functional.
\end{funcdesc}
Note that \module{EasyDialogs} does not currently use the notification
manager. This means that displaying dialogs while the program is in
the background will lead to unexpected results and possibly
crashes. Also, all dialogs are modeless and hence expect to be at the
top of the stacking order. This is true when the dialogs are created,
but windows that pop-up later (like a console window) may also result
in crashes.
|
Load LFindLoad.
From lfind Require Import LFind.
From QuickChick Require Import QuickChick.
From adtind Require Import goal33.
Derive Show for natural.
Derive Arbitrary for natural.
Instance Dec_Eq_natural : Dec_Eq natural.
Proof. dec_eq. Qed.
Lemma conj11eqsynthconj6 : forall (lv0 : natural) (lv1 : natural), (@eq natural (plus lv0 lv1) (plus lv1 lv0)).
Admitted.
QuickChick conj11eqsynthconj6.
|
module Determinism
import BigStep
import Progress
import Step
import Subst
import Term
import Equivalence
%default total
%access export
------------------------------------------------------------------------------
-- Begin: DETERMINISM OF INDUCTIVELY DEFINED SMALL-STEP AND BIG-STEP SEMANTICS
stepDeterministic : (Step e1 e2) -> (Step e1 e3) ->
e2 = e3
-- case split in the following order: (Step e1 e2), (Step e1 e3)
stepDeterministic {e1 = TApp _ e11} (StApp1 x) (StApp1 y) =
cong {f = \e => TApp e e11} $ stepDeterministic x y
--
stepDeterministic (StApp1 x) (StApp2 y z) = absurd $ valueIrreducible _ y x
--
stepDeterministic (StApp1 x) (StBeta y) = absurd $ valueIrreducible _ VAbs x
--
stepDeterministic (StApp2 x z) (StApp1 y) = absurd $ valueIrreducible _ x y
--
stepDeterministic {e1 = TApp e11 _} (StApp2 x z) (StApp2 y w) =
cong {f = \e => TApp e11 e} $ stepDeterministic z w
--
stepDeterministic (StApp2 x z) (StBeta y) = absurd $ valueIrreducible _ y z
--
stepDeterministic (StBeta x) (StApp2 y z) = absurd $ valueIrreducible _ x z
--
stepDeterministic (StBeta x) (StBeta y) = Refl
--
stepDeterministic (StFix x) (StFix y) = cong $ stepDeterministic x y
--
stepDeterministic (StFix x) StFixBeta = absurd $ valueIrreducible _ VAbs x
--
stepDeterministic StFixBeta StFixBeta = Refl
--
stepDeterministic (StSucc x) (StSucc y) = cong $ stepDeterministic x y
--
stepDeterministic (StPred x) (StPred y) = cong $ stepDeterministic x y
--
stepDeterministic (StPred x) StPredZero = absurd $ valueIrreducible _ VZero x
--
stepDeterministic (StPred x) (StPredSucc y) = absurd $ valueIrreducible _ (VSucc y) x
--
stepDeterministic StPredZero (StPred x) = absurd $ valueIrreducible _ VZero x
--
stepDeterministic StPredZero StPredZero = Refl
--
stepDeterministic (StPredSucc x) (StPred y) = absurd $ valueIrreducible _ (VSucc x) y
--
stepDeterministic (StPredSucc x) (StPredSucc y) = Refl
--
stepDeterministic {e1 = TIfz _ e12 e13} (StIfz x) (StIfz y) =
cong {f = \e => TIfz e e12 e13} $ stepDeterministic x y
--
stepDeterministic (StIfz x) StIfzZero = absurd $ valueIrreducible _ VZero x
--
stepDeterministic (StIfz x) (StIfzSucc y) = absurd $ valueIrreducible _ (VSucc y) x
--
stepDeterministic StIfzZero (StIfz x) = absurd $ valueIrreducible _ VZero x
--
stepDeterministic StIfzZero StIfzZero = Refl
--
stepDeterministic (StIfzSucc x) (StIfz y) = absurd $ valueIrreducible _ (VSucc x) y
--
stepDeterministic (StIfzSucc x) (StIfzSucc y) = Refl
transStepDeterministic : (v2 : Value e2) -> (TransStep e1 e2) ->
(v3 : Value e3) -> (TransStep e1 e3) ->
e2 = e3
transStepDeterministic v2 (TStRefl e3) v3 (TStRefl e3) = Refl
--
transStepDeterministic v2 (TStRefl e2) v3 (TStTrans x y) =
absurd $ valueIrreducible e2 v2 x
--
transStepDeterministic v2 (TStTrans x z) v3 (TStRefl e3) =
absurd $ valueIrreducible e3 v3 x
--
transStepDeterministic {e2 = e2} v2 (TStTrans x z) v3 (TStTrans y w) =
let eq = stepDeterministic x y
z' = replace {P = \x => x} (cong {f = \e => TransStep e e2} eq) z
in transStepDeterministic v2 z' v3 w
-- The following proof of the determinism of 'BigStep'
-- relies on the equivalence of 'Step' and 'BigStep'.
bigStepDeterministic' : (BigStep e1 e2) ->
(BigStep e1 e3) ->
e2 = e3
bigStepDeterministic' x y =
let (tst2, v2) = bigStepToTransStep x
(tst3, v3) = bigStepToTransStep y
in transStepDeterministic v2 tst2 v3 tst3
injectiveAbs : (TAbs e1 = TAbs e2) -> e1 = e2
injectiveAbs Refl = Refl
injectiveSucc : (TSucc e1 = TSucc e2) -> e1 = e2
injectiveSucc Refl = Refl
zeroNotSucc : (TZero = TSucc _) -> Void
zeroNotSucc Refl impossible
pairEq : a = b -> c = d -> (a, c) = (b, d)
pairEq Refl Refl = Refl
valueBigStepEq : Value e1 -> BigStep e1 e2 -> e1 = e2
valueBigStepEq VZero (BStValue _) = Refl
valueBigStepEq (VSucc x) (BStValue _) = Refl
valueBigStepEq (VSucc x) (BStSucc y) = cong $ valueBigStepEq x y
valueBigStepEq VAbs (BStValue _) = Refl
bigStepDeterministic : (BigStep e1 e2) -> (BigStep e1 e3) ->
e2 = e3
-- case split in the following order: (BigStep e1 e2), (BigStep e1 e3)
bigStepDeterministic (BStValue _) (BStValue _) = Refl
--
bigStepDeterministic (BStValue _) (BStApp z w t) impossible
--
bigStepDeterministic (BStValue _) (BStFix y z) impossible
--
bigStepDeterministic (BStValue v2) (BStSucc x) = case v2 of
VAbs impossible
VZero impossible
VSucc v2' => cong $ valueBigStepEq v2' x
--
bigStepDeterministic (BStValue _) (BStPredZero y) impossible
--
bigStepDeterministic (BStValue _) (BStPredSucc x) impossible
--
bigStepDeterministic (BStValue _) (BStIfzZero z w) impossible
--
bigStepDeterministic (BStValue _) (BStIfzSucc w s) impossible
--
bigStepDeterministic (BStApp w t u) (BStValue _) impossible
--
bigStepDeterministic {e2 = e2} (BStApp w t u) (BStApp z s v) =
let ih1 = injectiveAbs $ bigStepDeterministic w z
ih2 = bigStepDeterministic t s
peq = pairEq ih1 ih2
u' = replace {P = \x => BigStep (subst (snd x) First (fst x)) e2} peq u
in bigStepDeterministic u' v
--
bigStepDeterministic (BStFix z w) (BStValue v3) impossible
--
bigStepDeterministic {e2 = e2} (BStFix z w) (BStFix y s) =
let ih = injectiveAbs $ bigStepDeterministic z y
w' = replace {P = \x => BigStep (subst (TFix (TAbs x)) First x) e2} ih w
in bigStepDeterministic w' s
--
bigStepDeterministic (BStSucc x) (BStValue v3) = case v3 of
VAbs impossible
VZero impossible
VSucc v3' => cong . sym $ valueBigStepEq v3' x
--
bigStepDeterministic (BStSucc x) (BStSucc y) = cong $ bigStepDeterministic x y
--
bigStepDeterministic (BStPredZero z) (BStValue _) impossible
--
bigStepDeterministic (BStPredZero z) (BStPredZero y) = Refl
--
bigStepDeterministic (BStPredZero z) (BStPredSucc x) =
let ih = bigStepDeterministic z x
in absurd $ zeroNotSucc ih
--
bigStepDeterministic (BStPredSucc x) (BStValue _) impossible
--
bigStepDeterministic (BStPredSucc x) (BStPredZero z) =
let ih = bigStepDeterministic x z
in absurd . zeroNotSucc $ sym ih
--
bigStepDeterministic (BStPredSucc x) (BStPredSucc y) =
injectiveSucc $ bigStepDeterministic x y
--
bigStepDeterministic (BStIfzZero w s) (BStValue _) impossible
--
bigStepDeterministic (BStIfzZero w s) (BStIfzZero y z) = bigStepDeterministic s z
--
bigStepDeterministic (BStIfzZero w s) (BStIfzSucc z t) =
let ih = bigStepDeterministic w z
in absurd $ zeroNotSucc ih
--
bigStepDeterministic (BStIfzSucc s t) (BStValue _) impossible
--
bigStepDeterministic (BStIfzSucc s t) (BStIfzZero y z) =
let ih = bigStepDeterministic s y
in absurd . zeroNotSucc $ sym ih
--
bigStepDeterministic (BStIfzSucc s t) (BStIfzSucc z w) = bigStepDeterministic t w
-- End: DETERMINISM OF INDUCTIVELY DEFINED SMALL-STEP AND BIG-STEP SEMANTICS
----------------------------------------------------------------------------
----------------------------------------------------------------------------------
-- Begin: VERY RESTRICTED FROM OF DETERMINISM FOR CO-INDUCTIVELY DEFINED SEMANTICS
-- The coinductive relation 'CoBigStep' is not deterministic as, for example,
-- the term 'omega' can evaluate to anything. However, the following form of
-- determinism holds for terminating terms:
-- (cf. Lemma 35 in "Coinductive big-step operational semantics" by
-- X. Leroy and H. Grall)
coBigStepDeterministic' : BigStep e1 e2 -> CoBigStep e1 e3 -> e2 = e3
--
coBigStepDeterministic' (BStValue v) cbst = coBigStepValueIrreducible cbst v
--
coBigStepDeterministic' (BStApp bst1 bst2 bst3) cbst = case cbst of
(CoBStValue v) impossible
(CoBStApp cbst1 cbst2 cbst3) =>
case coBigStepDeterministic' bst1 cbst1 of
Refl => case coBigStepDeterministic' bst2 cbst2 of
Refl => case coBigStepDeterministic' bst3 cbst3 of
Refl => Refl
--
coBigStepDeterministic' (BStFix bst1 bst2) cbst = case cbst of
(CoBStValue v) impossible
(CoBStFix cbst1 cbst2) =>
case coBigStepDeterministic' bst1 cbst1 of
Refl => case coBigStepDeterministic' bst2 cbst2 of
Refl => Refl
--
coBigStepDeterministic' (BStSucc bst) cbst = case cbst of
(CoBStValue (VSucc v)) => cong . sym $ bigStepValueIrreducible bst v
(CoBStSucc cbst) => case coBigStepDeterministic' bst cbst of
Refl => Refl
--
coBigStepDeterministic' (BStPredZero bst) cbst = case cbst of
(CoBStValue v) impossible
(CoBStPredZero cbst) => case coBigStepDeterministic' bst cbst of
Refl => Refl
(CoBStPredSucc cbst) => case coBigStepDeterministic' bst cbst of
Refl impossible
--
coBigStepDeterministic' (BStPredSucc bst) cbst = case cbst of
(CoBStValue v) impossible
(CoBStPredZero cbst) => case coBigStepDeterministic' bst cbst of
Refl impossible
(CoBStPredSucc cbst) => case coBigStepDeterministic' bst cbst of
Refl => Refl
--
coBigStepDeterministic' (BStIfzZero bst1 bst2) cbst = case cbst of
(CoBStValue v) impossible
(CoBStIfzZero cbst1 cbst2) => coBigStepDeterministic' bst2 cbst2
(CoBStIfzSucc cbst1 cbst2) => case coBigStepDeterministic' bst1 cbst1 of
Refl impossible
--
coBigStepDeterministic' (BStIfzSucc bst1 bst2) cbst = case cbst of
(CoBStValue v) impossible
(CoBStIfzZero cbst1 cbst2) => case coBigStepDeterministic' bst1 cbst1 of
Refl impossible
(CoBStIfzSucc cbst1 cbst2) => coBigStepDeterministic' bst2 cbst2
-- An analogous statement holds for terminating terms and the coinductive
-- relation 'CoTransStep', which is generally not deterministic either:
coTransStepDeterministic' : Value e2 -> TransStep e1 e2 ->
Value e3 -> CoTransStep e1 e3 ->
e2 = e3
coTransStepDeterministic' v2 (TStRefl e1) v3 (CoTStRefl e1) = Refl
coTransStepDeterministic' v2 (TStRefl e1) v3 (CoTStTrans st _) =
absurd $ valueIrreducible _ v2 st
coTransStepDeterministic' v2 (TStTrans st tst) v3 (CoTStRefl e1) =
absurd $ valueIrreducible _ v3 st
coTransStepDeterministic' v2 (TStTrans st1 tst) v3 (CoTStTrans st2 ctst) =
case stepDeterministic st1 st2 of
Refl => coTransStepDeterministic' v2 tst v3 ctst
-- The following statement can also be seen as a restricted
-- from of determinism of the 'CoTransStep' relation given
-- that 'TransStep' terminates:
coTransStepExtends : TransStep e1 e2 -> Value e2 ->
CoTransStep e1 e3 -> CoTransStep e3 e2
coTransStepExtends (TStRefl e2) v (CoTStRefl e2) = CoTStRefl e2
coTransStepExtends (TStRefl e2) v (CoTStTrans st ctst) =
absurd $ valueIrreducible _ v st
coTransStepExtends (TStTrans st tst) v (CoTStRefl e1) =
CoTStTrans st $ transToCoTrans tst
coTransStepExtends (TStTrans st1 tst) v (CoTStTrans st2 ctst) =
case stepDeterministic st1 st2 of
Refl => coTransStepExtends tst v ctst
coTransStepExtends' : TransStep e1 e2 -> Value e2 ->
CoTransStep e1 e3 -> CoTransStep e1 e2
coTransStepExtends' tst v ctst = coTransStepTransitive ctst $ coTransStepExtends tst v ctst
-- Another result that relies on
-- (a) irreducibility of values and
-- (b) determinism of the 'Step' relation:
coTransStepInterpolates : CoTransStep e1 e3 -> Value e3 -> Step e1 e2 -> CoTransStep e2 e3
coTransStepInterpolates (CoTStRefl e1) v st = absurd $ valueIrreducible _ v st
coTransStepInterpolates (CoTStTrans st' ctst) v st =
let eq = stepDeterministic st st'
in rewrite eq in ctst
-- End: VERY RESTRICTED FROM OF DETERMINISM FOR CO-INDUCTIVELY DEFINED SEMANTICS
--------------------------------------------------------------------------------
-----------------------------------------------------------
-- Begin: DIVERGENCE OF TERM 'Subst.omega' UNDER SMALL-STEP
-- Term 'omega' steps to itself in one step:
stepOmega : Step Subst.omega Subst.omega
stepOmega = StFixBeta
-- That 'omega' steps to itself under the reflexive,
-- transitive closure of 'Step' is trivial:
transStepOmega : TransStep Subst.omega Subst.omega
transStepOmega = TStRefl _
-- By determinism of 'Step', the term 'omega' steps to nothing but itself:
stepOmegaOnly : Step Subst.omega e -> e = Subst.omega
stepOmegaOnly st = stepDeterministic st stepOmega
-- To extend the previous result 'stepOmegaOnly' to the transitive closure
-- of the 'Step' relation, an indexed version of 'TransStep' is needed:
data TransStepN : Nat -> Term [] t -> Term [] t -> Type where
TStNRefl : (e : Term [] t) -> TransStepN Z e e
TStNTrans : {e : Term [] t} -> {e' : Term [] t} -> {e'' : Term [] t} ->
Step e e' -> TransStepN n e' e'' -> TransStepN (S n) e e''
transStepFromN : TransStepN n e1 e2 -> TransStep e1 e2
transStepFromN (TStNRefl e1) = TStRefl e1
transStepFromN (TStNTrans st tstn) = TStTrans st (transStepFromN tstn)
transStepToN : TransStep e1 e2 -> (n : Nat ** TransStepN n e1 e2)
transStepToN (TStRefl e1) = (Z ** TStNRefl e1)
transStepToN (TStTrans st tst) = let (m ** tstn) = transStepToN tst
in ((S m) ** TStNTrans st tstn)
transStepNOmegaOnly : (n : Nat) -> TransStepN n Subst.omega e -> e = Subst.omega
transStepNOmegaOnly Z (TStNRefl _) = Refl
transStepNOmegaOnly {e} (S k) (TStNTrans st tstk) =
let eq = stepOmegaOnly st
tstk' = replace {P = \x => TransStepN k x e} eq tstk
in transStepNOmegaOnly k tstk'
-- Finally, the fact that 'omega' only steps to itself is proven
-- by appealing to the indexed version of the transitive closure:
-- (An induction argument analogous to the one in 'transStepNOmegaOnly'
-- is not accepted by Idris' totality checker. Induction would proceed on
-- the structure of the 'TransStep omega e' argument, and the induction
-- hypothesis would be applied to the second argument of the 'TStTrans'
-- constructor, which would again have the type 'TransStep omega e' but
-- only after rewriting with the equation obtained from 'stepOmegaOnly'.)
transStepOmegaOnly : TransStep Subst.omega e -> e = Subst.omega
transStepOmegaOnly tst = let (n ** tstn) = transStepToN tst
in transStepNOmegaOnly n tstn
transStepDivergenceOmega : TransStep Subst.omega e -> (Value e -> Void)
transStepDivergenceOmega tst v = let eq = transStepOmegaOnly tst
in case (replace {P = \x => Value x} eq v) of
VZero impossible
(VSucc _) impossible
VAbs impossible
-- Instead of diverging, the term 'omega' can evaluate to anything
-- under the coinductive relation 'CoTransStep'. Hence evaluation
-- under 'CoTransStep' is not deterministic:
coTransStepOmegaAny : CoTransStep Subst.omega e
coTransStepOmegaAny = CoTStTrans StFixBeta (coTransStepOmegaAny)
-- End: DIVERGENCE OF TERM 'Subst.omega' UNDER SMALL-STEP
---------------------------------------------------------
---------------------------------------------------------
-- Begin: DIVERGENCE OF TERM 'Subst.omega' UNDER BIG-STEP
-- The following straightforward approach to proving
-- that 'omega' diverges does not pass Idris' totality
-- checker because of the rewriting of 'bst' in the
-- induction step:
--
-- divergenceOmega : BigStep Subst.omega e -> Void
-- divergenceOmega {e = _} (BStValue v) = case v of
-- VZero impossible
-- (VSucc _) impossible
-- VAbs impossible
-- divergenceOmega {e = e} (BStFix (BStValue v) bst) =
-- let bst' = replace {P = \x => BigStep x e} substOmega bst
-- in divergenceOmega bst'
-- To prove that 'omega' diverges under big-step semantics,
-- an indexed version of the 'BigStep' relation is introduced:
data BigStepN : Nat -> Term [] t -> (y: Term [] t) -> Type where
BStValueN : (v : Value e) -> BigStepN Z e e
--
BStAppN : BigStepN k e1 (TAbs e1') ->
BigStepN m e2 e2' ->
BigStepN n (subst e2' First e1') e ->
BigStepN (S $ k+m+n) (TApp e1 e2) e
--
BStFixN : BigStepN m e (TAbs e') ->
BigStepN n (subst (TFix (TAbs e')) First e') e'' ->
BigStepN (S $ m+n) (TFix e) e''
--
BStSuccN : BigStepN n e e' ->
BigStepN (S n) (TSucc e) (TSucc e')
--
BStPredZeroN : BigStepN n e TZero ->
BigStepN (S n) (TPred e) TZero
--
BStPredSuccN : BigStepN n e (TSucc e') ->
BigStepN (S n) (TPred e) e'
--
BStIfzZeroN : BigStepN m e1 TZero ->
BigStepN n e2 e ->
BigStepN (S $ m+n) (TIfz e1 e2 _) e
--
BStIfzSuccN : BigStepN m e1 (TSucc _) ->
BigStepN n e3 e ->
BigStepN (S $ m+n) (TIfz e1 _ e3) e
bigStepToN : BigStep e1 e2 -> (n : Nat ** BigStepN n e1 e2)
bigStepToN (BStValue v) = (Z ** BStValueN v)
--
bigStepToN (BStApp bst1 bst2 bst3) = let (n1 ** bstn1) = bigStepToN bst1
(n2 ** bstn2) = bigStepToN bst2
(n3 ** bstn3) = bigStepToN bst3
in ((S $ n1+n2+n3) ** BStAppN bstn1 bstn2 bstn3)
--
bigStepToN (BStFix bst1 bst2) = let (n1 ** bstn1) = bigStepToN bst1
(n2 ** bstn2) = bigStepToN bst2
in ((S $ n1+n2) ** BStFixN bstn1 bstn2)
--
bigStepToN (BStSucc bst) = let (n ** bstn) = bigStepToN bst
in ((S n) ** BStSuccN bstn)
--
bigStepToN (BStPredZero bst) = let (n ** bstn) = bigStepToN bst
in ((S n) ** BStPredZeroN bstn)
--
bigStepToN (BStPredSucc bst) = let (n ** bstn) = bigStepToN bst
in ((S n) ** BStPredSuccN bstn)
--
bigStepToN (BStIfzZero bst1 bst2) = let (n1 ** bstn1) = bigStepToN bst1
(n2 ** bstn2) = bigStepToN bst2
in ((S $ n1+n2) ** BStIfzZeroN bstn1 bstn2)
--
bigStepToN (BStIfzSucc bst1 bst2) = let (n1 ** bstn1) = bigStepToN bst1
(n2 ** bstn2) = bigStepToN bst2
in ((S $ n1+n2) ** BStIfzSuccN bstn1 bstn2)
bigStepFromN : BigStepN n e1 e2 -> BigStep e1 e2
bigStepFromN (BStValueN v) = BStValue v
--
bigStepFromN (BStAppN bstn1 bstn2 bstn3) = let bst1 = bigStepFromN bstn1
bst2 = bigStepFromN bstn2
bst3 = bigStepFromN bstn3
in BStApp bst1 bst2 bst3
--
bigStepFromN (BStFixN bstn1 bstn2) = let bst1 = bigStepFromN bstn1
bst2 = bigStepFromN bstn2
in BStFix bst1 bst2
--
bigStepFromN (BStSuccN bstn) = let bst = bigStepFromN bstn
in BStSucc bst
--
bigStepFromN (BStPredZeroN bstn) = let bst = bigStepFromN bstn
in BStPredZero bst
--
bigStepFromN (BStPredSuccN bstn) = let bst = bigStepFromN bstn
in BStPredSucc bst
--
bigStepFromN (BStIfzZeroN bstn1 bstn2) = let bst1 = bigStepFromN bstn1
bst2 = bigStepFromN bstn2
in BStIfzZero bst1 bst2
--
bigStepFromN (BStIfzSuccN bstn1 bstn2) = let bst1 = bigStepFromN bstn1
bst2 = bigStepFromN bstn2
in BStIfzSucc bst1 bst2
-- Divergence of 'omega' under the indexed version of big-step semantics:
bigStepDivergenceOmega' : (n : Nat) -> BigStepN n Subst.omega e -> Void
bigStepDivergenceOmega' Z (BStValueN v) = case v of
VZero impossible
(VSucc _) impossible
VAbs impossible
bigStepDivergenceOmega' {e} (S n) bstn = case bstn of
(BStFixN (BStValueN v) bstn2) => let bstn2' = replace {P = \x => BigStepN n x e}
substOmega bstn2
in bigStepDivergenceOmega' n bstn2'
bigStepDivergenceOmega : BigStep Subst.omega e -> Void
bigStepDivergenceOmega bst = let (n ** bstn) = bigStepToN bst
in bigStepDivergenceOmega' n bstn
-- Instead of diverging, the term 'omega' can evaluate to anything
-- under the coinductive relation 'CoBigStep'. Hence, evaluation
-- under 'CoBigStep' is non-deterministic:
coBigStepOmegaAny : CoBigStep Subst.omega e
coBigStepOmegaAny = CoBStFix (CoBStValue VAbs) Determinism.coBigStepOmegaAny
-- End: DIVERGENCE OF TERM 'Subst.omega' UNDER BIG-STEP
-------------------------------------------------------
|
!!# MODULE <<VAR_Units>>
MODULE VAR_Units
!!## PURPOSE
!! This module contains the unit-numbers for default
!! units.
!!## EXTERNAL PARAMETERS
USE PAR_Units,ONLY: keyboard_unit,window_unit !!((02-A-PAR_Units.f90))
!!## VARIABLES
!! * Default input and output units
INTEGER :: DEFAULT_INPUT_UNIT = keyboard_unit
INTEGER :: DEFAULT_OUTPUT_UNIT = window_unit
END MODULE
|
```python
import numpy as np
import sympy as sp
from PIL import Image
from scipy import interpolate
import matplotlib.pyplot as plt
```
# Tarea 3:Interpolación Bicúbica
## Instrucciones
* La tarea es individual.
* Las consultas sobre las tareas se deben realizar por medio de la plataforma Aula.
* La tarea debe ser realizada en `Jupyter Notebook` (`Python3`).
* Se evaluará la correcta utilización de librerias `NumPy`, `SciPy`, entre otras, así como la correcta implementación de algoritmos de forma vectorizada.
* **El archivo de entrega debe denominarse ROL-tarea-numero.ipynb**. _De no respetarse este formato existirá un descuento de **50 puntos**_
* La fecha de entrega es el viernes 24 de Julio a las **18:00 hrs**. Se aceptarán entregas hasta las 19:00 hrs sin descuento en caso de existir algun problema, posteriormente existirá un descuento lineal hasta las 20:00 hrs del mismo día.
* Las tareas que sean entregadas antes del jueves a mediodía recibirán una bonificación de 10 puntos
* Debe citar cualquier código ajeno utilizado (incluso si proviene de los Jupyter Notebooks del curso).
## Introducción
En la siguiente tarea estudiaremos un método de interpolación denominado **Interpolación Bicúbica**, utilizada frecuentemente sobre imágenes. Aplicaremos el método para aumentar la resolución de una imagen intentando preservar las propiedades de la versión original.
## Contexto
Supongamos que usted conoce $f$ y las derivadas $f_x$, $f_y$ y $f_{xy}$ dentro de las coordenadas $(0,0),(0,1),(1,0)$ y $(1,1)$ de un cuadrado unitario. La superficie que interpola estos 4 puntos es:
$$
p(x,y) = \sum\limits_{i=0}^3 \sum_{j=0}^3 a_{ij} x^i y^j.
$$
Como se puede observar el problema de interpolación se resume en determinar los 16 coeficientes $a_{ij}$ y para esto se genera un total de $16$ ecuaciones utilizando los valores conocidos de $f$,$f_x$,$f_y$ y $f_{xy}$. Por ejemplo, las primeras $4$ ecuaciones son:
$$
\begin{aligned}
f(0,0)&=p(0,0)=a_{00},\\
f(1,0)&=p(1,0)=a_{00}+a_{10}+a_{20}+a_{30},\\
f(0,1)&=p(0,1)=a_{00}+a_{01}+a_{02}+a_{03},\\
f(1,1)&=p(1,1)=\textstyle \sum \limits _{i=0}^{3}\sum \limits _{j=0}^{3}a_{ij}.
\end{aligned}
$$
Para las $12$ ecuaciones restantes se debe utilizar:
$$
\begin{aligned}
f_{x}(x,y)&=p_{x}(x,y)=\textstyle \sum \limits _{i=1}^{3}\sum \limits _{j=0}^{3}a_{ij}ix^{i-1}y^{j},\\
f_{y}(x,y)&=p_{y}(x,y)=\textstyle \sum \limits _{i=0}^{3}\sum \limits _{j=1}^{3}a_{ij}x^{i}jy^{j-1},\\
f_{xy}(x,y)&=p_{xy}(x,y)=\textstyle \sum \limits _{i=1}^{3}\sum \limits _{j=1}^{3}a_{ij}ix^{i-1}jy^{j-1}.
\end{aligned}
$$
Una vez planteadas las ecuaciones, los coeficientes se pueden obtener al resolver el problema $A\alpha=x$, donde $\alpha=\left[\begin{smallmatrix}a_{00}&a_{10}&a_{20}&a_{30}&a_{01}&a_{11}&a_{21}&a_{31}&a_{02}&a_{12}&a_{22}&a_{32}&a_{03}&a_{13}&a_{23}&a_{33}\end{smallmatrix}\right]^T$ y ${\displaystyle x=\left[{\begin{smallmatrix}f(0,0)&f(1,0)&f(0,1)&f(1,1)&f_{x}(0,0)&f_{x}(1,0)&f_{x}(0,1)&f_{x}(1,1)&f_{y}(0,0)&f_{y}(1,0)&f_{y}(0,1)&f_{y}(1,1)&f_{xy}(0,0)&f_{xy}(1,0)&f_{xy}(0,1)&f_{xy}(1,1)\end{smallmatrix}}\right]^{T}}$.
En un contexto más aplicado, podemos hacer uso de la interpolación bicúbica para aumentar la resolución de una imagen. Supongamos que tenemos la siguiente imagen de tamaño $5 \times 5$:
Podemos ir tomando segmentos de la imagen de tamaño $2 \times 2$ de la siguiente forma:
Por cada segmento podemos generar una superficie interpoladora mediante el algoritmo de interpolación cubica. Para el ejemplo anterior estariamos generando $16$ superficies interpoladoras distintas. La idea es hacer uso de estas superficies para estimar los valores de los pixeles correspondienets a una imagen más grande. Por ejemplo, la imagen $5 \times 5$ la podemos convertir a una imagen de $9 \times 9$ agregando un pixel entre cada par de pixeles originales además de uno en el centro para que no quede un hueco.
Aca los pixeles verdes son los mismos que la imagen original y los azules son obtenidos de evaluar cada superficie interpoladora. Notar que existen pixeles azules que se pueden obtener a partir de dos superficies interpoladoras distintas, en esos casos se puede promediar el valor de los pixeles o simplemente dejar uno de los dos.
Para trabajar con la interpolación bicubica necesitamos conocer los valores de $f_x$, $f_y$ y $f_{xy}$. En el caso de las imagenes solo tenemos acceso al valor de cada pixel por lo que deberemos estimar cual es el valor de estos. Para estimar $f_x$ haremos lo siguiente:
Para estimar el valor de $f_x$ en cada pixel haremos una interpolación con los algoritmos conocidos, usando tres pixels en dirección de las filas, luego derivaremos el polinomio obtenido y finalmente evaluaremos en la posición de interes. La misma idea aplica para $f_y$ solo que ahora interpolaremos en dirección de las columnas.
Por ejemplo si queremos obtener el valor de $f_x$ en la posición $(0,0)$ (imagen de la izquierda) entonces haremos una interpolación de Lagrange utilizando los pixeles $(0,0),(0,1)$ y $(0,2)$. Derivaremos el polinomio interpolador y evaluaremos en $(0,0)$. Por otro lado si queremos obtener el valor de $f_y$ en la posición $(0,0)$ (imagen de la derecha) entonces interpolaremos los pixeles $(0,0),(1,0)$ y $(2,0)$. Luego derivaremos el polinomio interpolador y evaluaremos en $(0,0)$.
Para obtener $f_{xy}$ seguiremos la idea anterior. Solo que esta vez se utilizaran los valores de $f_y$ y se interpolaran estos en dirección de las filas.
# Preguntas
```python
#Codigo para abrir y visualizar imágenes
img = Image.open('imagen.jpg')
array=np.array(img)
imgplot = plt.imshow(array)
plt.show()
```
## 1. Interpolación bicubica
### 1.1 Obtener derivadas (30 puntos)
Implemente la función `derivativeValues` que reciba como input un arreglo con valores, el método de interpolación y si es que se considera el uso de los puntos de chebyshev . La función debe retornar un arreglo de igual dimensión con los valores de las derivadas de los puntos obtenidas
Los métodos de interpolación serán representados por los siguientes valores
* Interpolación de lagrange: `'lagrange'`
* Diferencias divididas de Newton: `'newton'`
* Spline cubica: `'spline3'`
```python
def derivativeValues(values, method, cheb):
"""
Parameters
----------
values: (int array) points values
method: (string) interpolation method
cheb: (boolean) if chebyshev points are used
Returns
-------
d: (float array) derivative value of interpolated points
"""
return d
```
### 1.2 Interpolación de imagen (50 puntos)
Implemente la función `bicubicInterpolation` que reciba como input la matriz de la imagen y cuantos píxeles extra se quiere agregar entre los píxeles originales y el algoritmo de interpolación a utilizar. La función debe retornar la matriz con la imagen de dimensión nueva. Considere que se debe aplicar el método de interpolación en cada canal RGB por separado.
```python
def bicubicInterpolation(image, interiorPixels, method,cheb):
"""
Parameters
----------
image: (nxnx3 array) image array in RGB format
interiorPixels: (int) interpolation method
method: (string) interpolation method
cheb: (boolean) if chebyshev points are used
Returns
-------
newImage: (nxnx3 array) image array in RGB format
"""
return newImage
```
## 2. Evaluacion de algoritmos
### 2.1 Tiempo de ejecucion
Implemente la funcion `timeInterpolation` que mida el tiempo de interpolacion de una imagen dado el algoritmo de interpolacion , en segundos.(5 puntos)
```python
def timeInterpolation(image, interiorPixels, method,cheb):
"""
Parameters
----------
image: (nxnx3 array) image array in RGB format
interiorPixels: (int) interpolation method
method: (string) interpolation method
cheb: (boolean) if chebyshev points are used
Returns
-------
time: (float) time in seconds
"""
return time
```
***Pregunta: ¿Cual es el metodo que presenta mayor velocidad en general? (5 puntos)***
### 2.2 Calculo de error
Implemente la funcion `errorInterpolation` la cual debe obtener el error de la imagen obtenida comparandola con una de referencia. El error debe ser calculado utilizando el indice SSIM (Structural similarity) (5 puntos)
```python
def errorInterpolation(original,new):
"""
Parameters
----------
image: (nxn array) original image array in RGB format
new: (nxn array) new image array in RGB format obtained from interpolation
Returns
-------
error: (float) difference between images
"""
return error
```
***Pregunta: ¿Cual metodo presenta menor error? (5 puntos)***
# Consideraciones
* Solo trabajaremos con imagenes cuadradas
* En el caso que el valor interpolado de un punto sea mayor a 255 o menor a 0, este se trunca a 255 o 0 respectivamente
* Esta permitido el uso de sympy para calcular derivadas y para construir el polinomio interpolador
* El calculo de error puede ser calculado utilizando la imagen en escala de grises [(ejemplo)](https://scikit-image.org/docs/dev/auto_examples/transform/plot_ssim.html)
```python
```
|
[STATEMENT]
lemma [iff]: "is_Ref Null"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. is_Ref Null
[PROOF STEP]
by (simp add: is_Ref_def2)
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
= = History = =
|
" West End Girls " has been generally well received by music critics . Stephen Thomas Erlewine from Allmusic in a review of the album Please called the song " hypnotic " , adding that " it 's not only a classic dance single , it 's a classic pop single " . In a review for the group 's second studio album Actually , Rob Hoerburger from Rolling Stone magazine commented that " West End Girls " was " as catchy as anything on the radio in 1986 " , praising " its enticing bass line and foreboding synth riffs " , but felt that it was almost " nullified by peevish spoken asides and the cryptic posturing of the duo 's lyrics " . In a review of the live album Concrete , Michael Hubbard from musicOMH said that " West End Girls " was one of the songs that " round out a collection that never feels too long or superfluous " , adding that it " goes some way to installing Tennant and Lowe as national treasures " .
|
SUBROUTINE DT_AAEVT(Nevts,Epn,Npmass,Npchar,Ntmass,Ntchar,Idp,
& Iglau)
C***********************************************************************
C This version dated 22.03.96 is written by S. Roesler. *
C***********************************************************************
IMPLICIT NONE
DOUBLE PRECISION dum , Epn
INTEGER i , idmnyr , Idp , ievt , Iglau , irej , kkmat , Nevts ,
& nmsg , Npchar , Npmass , Ntchar , Ntmass
SAVE
INCLUDE 'inc/dtflka'
C emulsion treatment
INCLUDE 'inc/dtcomp'
C event flag
INCLUDE 'inc/dtevno'
INCLUDE 'inc/dtflg1'
C COMMON /PRTANU/ IAPROJ,IATARG
CHARACTER*8 date , hhmmss
DIMENSION idmnyr(3)
kkmat = 1
nmsg = MAX(Nevts/100,1)
C initialization of run-statistics and histograms
CALL DT_STATIS(1)
CALL PHO_PHIST(1000,dum)
C initialization of Glauber-formalism
IF ( NCOmpo.LE.0 ) THEN
CALL DT_SHMAKI(Npmass,Npchar,Ntmass,Ntchar,Idp,Epn,Iglau)
ELSE
DO i = 1 , NCOmpo
CALL DT_SHMAKI(Npmass,Npchar,IEMuma(i),IEMuch(i),Idp,Epn,0)
END DO
END IF
CALL DT_SIGEMU
CALL IDATE(idmnyr)
WRITE (date,'(I2,''/'',I2,''/'',I2)') idmnyr(1) , idmnyr(2) ,
& MOD(idmnyr(3),100)
CALL ITIME(idmnyr)
WRITE (hhmmss,'(I2,'':'',I2,'':'',I2)') idmnyr(1) , idmnyr(2) ,
& idmnyr(3)
IF ( LPRi.GT.4 ) WRITE (LOUt,99010) date , hhmmss
99010 FORMAT (/,' DT_AAEVT: Initialisation finished. ( Date: ',A8,
& ' Time: ',A8,' )')
C generate NEVTS events
DO ievt = 1 , Nevts
C print run-status message
IF ( MOD(ievt,nmsg).EQ.0 ) THEN
CALL IDATE(idmnyr)
WRITE (date,'(I2,''/'',I2,''/'',I2)') idmnyr(1) , idmnyr(2)
& , MOD(idmnyr(3),100)
CALL ITIME(idmnyr)
WRITE (hhmmss,'(I2,'':'',I2,'':'',I2)') idmnyr(1) ,
& idmnyr(2) , idmnyr(3)
IF ( LPRi.GT.4 ) WRITE (LOUt,99020) ievt - 1 , Nevts ,
& date , hhmmss
99020 FORMAT (/,1X,I8,' out of ',I8,' events sampled ( Date: ',A,
& ' Time: ',A,' )',/)
C WRITE(LOUT,1000) IEVT-1
C1000 FORMAT(1X,I8,' events sampled')
END IF
NEVent = ievt
C treat nuclear emulsions
C composite targets only
IF ( IEMul.GT.0 ) CALL DT_GETEMU(Ntmass,Ntchar,kkmat,0)
kkmat = -kkmat
C sample this event
CALL DT_KKINC(Npmass,Npchar,Ntmass,Ntchar,Idp,Epn,kkmat,irej)
C chain fusion
C WRITE(6,*)' IFUSION,IAPROJ,IATARG ',IFUSION,IAPROJ,IATARG
IF ( (IFUsion.EQ.1) .AND. (Npmass.GT.12) .AND. (Ntmass.GT.12) )
& CALL DT_DENSITY
C
C
CALL PHO_PHIST(2000,dum)
END DO
C print run-statistics and histograms to output-unit 6
CALL PHO_PHIST(3000,dum)
CALL DT_STATIS(2)
END SUBROUTINE
|
r=359.03
https://sandbox.dams.library.ucdavis.edu/fcrepo/rest/collection/sherry-lehmann/catalogs/d7jp4g/media/images/d7jp4g-075/svc:tesseract/full/full/359.03/default.jpg Accept:application/hocr+xml
|
From Test Require Import tactic.
Section FOFProblem.
Variable Universe : Set.
Variable UniverseElement : Universe.
Variable wd_ : Universe -> Universe -> Prop.
Variable col_ : Universe -> Universe -> Universe -> Prop.
Variable col_swap1_1 : (forall A B C : Universe, (col_ A B C -> col_ B A C)).
Variable col_swap2_2 : (forall A B C : Universe, (col_ A B C -> col_ B C A)).
Variable col_triv_3 : (forall A B : Universe, col_ A B B).
Variable wd_swap_4 : (forall A B : Universe, (wd_ A B -> wd_ B A)).
Variable col_trans_5 : (forall P Q A B C : Universe, ((wd_ P Q /\ (col_ P Q A /\ (col_ P Q B /\ col_ P Q C))) -> col_ A B C)).
Theorem pipo_6 : (forall O B C Bprime Cprime X Y : Universe, ((wd_ Cprime O /\ (wd_ Bprime O /\ (wd_ B O /\ (wd_ B C /\ (wd_ C O /\ (wd_ X Y /\ (wd_ B Bprime /\ (wd_ C Bprime /\ (wd_ B Cprime /\ (wd_ Cprime C /\ (wd_ Cprime Bprime /\ (col_ O Bprime Cprime /\ (col_ B O C /\ (col_ O X Y /\ col_ X Y B)))))))))))))) -> col_ X Y C)).
Proof.
time tac.
Qed.
End FOFProblem.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.