text
stringlengths 0
3.34M
|
---|
corollary connected_convex_diff_countable: fixes U :: "'a::euclidean_space set" assumes "convex U" "\<not> collinear U" "countable S" shows "connected(U - S)" |
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2005-2011. 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)
//
// See http://www.boost.org/libs/interprocess for documentation.
//
//////////////////////////////////////////////////////////////////////////////
//
// Parts of the pthread code come from Boost Threads code:
//
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001-2003
// William E. Kempf
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without fee,
// provided that the above copyright notice appear in all copies and
// that both that copyright notice and this permission notice appear
// in supporting documentation. William E. Kempf makes no representations
// about the suitability of this software for any purpose.
// It is provided "as is" without express or implied warranty.
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTERPROCESS_RECURSIVE_MUTEX_HPP
#define BOOST_INTERPROCESS_RECURSIVE_MUTEX_HPP
/// @cond
#if (defined _MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif
#include <boost/interprocess/detail/config_begin.hpp>
#include <boost/interprocess/detail/workaround.hpp>
#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
#include <boost/assert.hpp>
#if !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION) && \
(defined(BOOST_INTERPROCESS_POSIX_PROCESS_SHARED) && defined (BOOST_INTERPROCESS_POSIX_RECURSIVE_MUTEXES))
#include <boost/interprocess/sync/posix/recursive_mutex.hpp>
#define BOOST_INTERPROCESS_USE_POSIX
//Experimental...
#elif !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION) && defined (BOOST_INTERPROCESS_WINDOWS)
#include <boost/interprocess/sync/windows/recursive_mutex.hpp>
#define BOOST_INTERPROCESS_USE_WINDOWS
#elif !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
#include <boost/interprocess/sync/spin/recursive_mutex.hpp>
#define BOOST_INTERPROCESS_USE_GENERIC_EMULATION
#endif
#if defined (BOOST_INTERPROCESS_USE_GENERIC_EMULATION)
namespace boost {
namespace interprocess {
namespace ipcdetail{
namespace robust_emulation_helpers {
template<class T>
class mutex_traits;
}}}}
#endif
/// @endcond
//!\file
//!Describes interprocess_recursive_mutex and shared_recursive_try_mutex classes
namespace boost {
namespace interprocess {
//!Wraps a interprocess_mutex that can be placed in shared memory and can be
//!shared between processes. Allows several locking calls by the same
//!process. Allows timed lock tries
class interprocess_recursive_mutex
{
/// @cond
//Non-copyable
interprocess_recursive_mutex(const interprocess_recursive_mutex &);
interprocess_recursive_mutex &operator=(const interprocess_recursive_mutex &);
/// @endcond
public:
//!Constructor.
//!Throws interprocess_exception on error.
interprocess_recursive_mutex();
//!Destructor. If any process uses the mutex after the destructor is called
//!the result is undefined. Does not throw.
~interprocess_recursive_mutex();
//!Effects: The calling thread tries to obtain ownership of the mutex, and
//! if another thread has ownership of the mutex, it waits until it can
//! obtain the ownership. If a thread takes ownership of the mutex the
//! mutex must be unlocked by the same mutex. The mutex must be unlocked
//! the same number of times it is locked.
//!Throws: interprocess_exception on error.
void lock();
//!Tries to lock the interprocess_mutex, returns false when interprocess_mutex
//!is already locked, returns true when success. The mutex must be unlocked
//!the same number of times it is locked.
//!Throws: interprocess_exception if a severe error is found
bool try_lock();
//!Tries to lock the interprocess_mutex, if interprocess_mutex can't be locked before
//!abs_time time, returns false. The mutex must be unlocked
//! the same number of times it is locked.
//!Throws: interprocess_exception if a severe error is found
bool timed_lock(const boost::posix_time::ptime &abs_time);
//!Effects: The calling thread releases the exclusive ownership of the mutex.
//! If the mutex supports recursive locking, the mutex must be unlocked the
//! same number of times it is locked.
//!Throws: interprocess_exception on error.
void unlock();
/// @cond
private:
#if defined (BOOST_INTERPROCESS_USE_GENERIC_EMULATION)
#undef BOOST_INTERPROCESS_USE_GENERIC_EMULATION
void take_ownership(){ mutex.take_ownership(); }
friend class ipcdetail::robust_emulation_helpers::mutex_traits<interprocess_recursive_mutex>;
ipcdetail::spin_recursive_mutex mutex;
#elif defined(BOOST_INTERPROCESS_USE_POSIX)
#undef BOOST_INTERPROCESS_USE_POSIX
ipcdetail::posix_recursive_mutex mutex;
#elif defined(BOOST_INTERPROCESS_USE_WINDOWS)
#undef BOOST_INTERPROCESS_USE_WINDOWS
ipcdetail::windows_recursive_mutex mutex;
#else
#error "Unknown platform for interprocess_mutex"
#endif
/// @endcond
};
} //namespace interprocess {
} //namespace boost {
namespace boost {
namespace interprocess {
inline interprocess_recursive_mutex::interprocess_recursive_mutex(){}
inline interprocess_recursive_mutex::~interprocess_recursive_mutex(){}
inline void interprocess_recursive_mutex::lock()
{
#ifdef BOOST_INTERPROCESS_ENABLE_TIMEOUT_WHEN_LOCKING
boost::posix_time::ptime wait_time
= boost::posix_time::microsec_clock::universal_time()
+ boost::posix_time::milliseconds(BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS);
if (!mutex.timed_lock(wait_time)){
throw interprocess_exception(timeout_when_locking_error, "Interprocess mutex timeout when locking. Possible deadlock: owner died without unlocking?");
}
#else
mutex.lock();
#endif
}
inline bool interprocess_recursive_mutex::try_lock()
{ return mutex.try_lock(); }
inline bool interprocess_recursive_mutex::timed_lock(const boost::posix_time::ptime &abs_time)
{ return mutex.timed_lock(abs_time); }
inline void interprocess_recursive_mutex::unlock()
{ mutex.unlock(); }
} //namespace interprocess {
} //namespace boost {
#include <boost/interprocess/detail/config_end.hpp>
#endif //BOOST_INTERPROCESS_RECURSIVE_MUTEX_HPP
|
[STATEMENT]
lemma L_split:
"x * L \<le> x * bot \<squnion> L"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. x * L \<le> x * bot \<squnion> L
[PROOF STEP]
by (metis L_split_sup sup_monoid.add_0_left) |
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! EVB-QMDFF - RPMD molecular dynamics and rate constant calculations on
! black-box generated potential energy surfaces
!
! Copyright (c) 2021 by Julien Steffen ([email protected])
! Stefan Grimme ([email protected]) (QMDFF code)
!
! Permission is hereby granted, free of charge, to any person obtaining a
! copy of this software and associated documentation files (the "Software"),
! to deal in the Software without restriction, including without limitation
! the rights to use, copy, modify, merge, publish, distribute, sublicense,
! and/or sell copies of the Software, and to permit persons to whom the
! Software is furnished to do so, subject to the following conditions:
!
! The above copyright notice and this permission notice shall be included in
! all copies or substantial portions of the Software.
!
! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
! THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
! FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
! DEALINGS IN THE SOFTWARE.
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! subroutine mdinit_bias: initializes the velocities and momenta
! before each new umbrella sampling trajectory
!
! part of EVB
!
subroutine mdinit_bias(xi_ideal,dxi_act,derivs,thermos,bias_mode)
use general
use evb_mod
implicit none
integer::i ! loop index
integer::thermos ! if the thermostat shall be applied
! (0: no, 1: yes)
real(kind=8),dimension(3,natoms,nbeads)::derivs
real(kind=8),dimension(3,natoms)::derivs_1d,q_1b
real(kind=8),dimension(nat6)::act_int,int_ideal
real(kind=8)::dxi_act(3,natoms)
real(kind=8)::xi_ideal,xi_real
real(kind=8)::epot ! the actual potential energy
real(kind=8)::centroid(3,natoms) ! the centroid with all the
! com's of all beads
integer::bias_mode ! usual sampling traj.: 1, constraint: 2
!
! initalize the random number generator for the thermostat
!
!if (calc_modus .eq. 1) stop "Jgdi"
!
! get the potential energy and atomic forces
! for each bead at once: define its current structure and collect
! all results in a global derivs array thereafter
!
do i=1,nbeads
q_1b=q_i(:,:,i)
call gradient (q_1b,epot,derivs_1d,i)
derivs(:,:,i)=derivs_1d
end do
!if (calc_modus .eq. 1) stop "Jgdi2"
!
! Calculate the centroid (center of masses) for the
! ring polymer and use its positions for application
! of the force constant
!
call get_centroid(centroid)
!if (calc_modus .eq. 1) stop "Jgdi3"
!
! Add the bias potential for umbrella samplings!
!
if (bias_mode .eq. 1) then
call umbrella(centroid,xi_ideal,int_ideal,xi_real,dxi_act,derivs,1)
else if (bias_mode .eq. 2) then
call umbrella(centroid,xi_ideal,int_ideal,xi_real,dxi_act,derivs,0)
end if
!if (calc_modus .eq. 1) stop "Jgdi3"
!
! Reset the momentum to a pseudo random distribution
! --> apply the andersen thermostat or the GLE for partly resampling
!
if ((thermos .eq. 1) .and. (thermostat .eq. 0)) then
call andersen
else if (thermostat .eq. 1) then
stop "No GLE implemented!"
end if
!
! set momentum to zero for fixed atoms
!
if (fix_atoms) then
do i=1,fix_num
p_i(:,fix_list(i),:)=0.d0
end do
end if
return
end subroutine mdinit_bias
|
[STATEMENT]
lemma sfg_agroup:"sfg A a \<Longrightarrow> aGroup A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. sfg A a \<Longrightarrow> aGroup A
[PROOF STEP]
apply (simp add:sfg_def ag_single_gen_def)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done |
= French cruiser Sully =
|
integer :: j, k, jj(5)
real :: x(10), xx(10,10), yy(10,10)
! C.4.6 Examples of FORALL statements
! Example 1:
FORALL (J=1:M, K=1:N) xx(K, J) = yy(J, K)
FORALL (K=1:N) xx(K, 1:M) = yy(1:M, K)
! These statements both copy columns 1 through N of array Y into rows 1
! through N of array X. They are equivalent to
xx(1:N, 1:M) = TRANSPOSE (yy(1:M, 1:N) )
! Example 2:
! The following FORALL statement computes five partial sums of subarrays of J.
jj = (/ 1, 2, 3, 4, 5 /)
FORALL (K = 1:5) jj(K) = SUM (jj(1:K) )
! SUM is allowed in a FORALL because intrinsic functions are pure (12.7). After
! execution of the FORALL statement, J = (/ 1, 3, 6, 10, 15 /).
! Example 3:
FORALL (I = 2:N-1) X(I) = (X(I-1) + 2*X(I) + X(I+1) ) / 4
! has the same effect as
X(2:N-1) = (X(1:N-2) + 2*X(2:N-1) + X(3:N) ) / 4
end
|
State Before: 𝕜 : Type u_4
𝕝 : Type u_1
E : Type u_2
F : Type u_3
β : Type ?u.14448
inst✝¹⁰ : OrderedSemiring 𝕜
inst✝⁹ : TopologicalSpace E
inst✝⁸ : TopologicalSpace F
inst✝⁷ : AddCommMonoid E
inst✝⁶ : AddCommMonoid F
inst✝⁵ : Module 𝕜 E
inst✝⁴ : Module 𝕜 F
s : Set E
inst✝³ : Semiring 𝕝
inst✝² : Module 𝕝 E
inst✝¹ : Module 𝕝 F
inst✝ : LinearMap.CompatibleSMul E F 𝕜 𝕝
hs : StrictConvex 𝕜 s
f : E →ₗ[𝕝] F
hf : IsOpenMap ↑f
⊢ StrictConvex 𝕜 (↑f '' s) State After: case intro.intro.intro.intro
𝕜 : Type u_4
𝕝 : Type u_1
E : Type u_2
F : Type u_3
β : Type ?u.14448
inst✝¹⁰ : OrderedSemiring 𝕜
inst✝⁹ : TopologicalSpace E
inst✝⁸ : TopologicalSpace F
inst✝⁷ : AddCommMonoid E
inst✝⁶ : AddCommMonoid F
inst✝⁵ : Module 𝕜 E
inst✝⁴ : Module 𝕜 F
s : Set E
inst✝³ : Semiring 𝕝
inst✝² : Module 𝕝 E
inst✝¹ : Module 𝕝 F
inst✝ : LinearMap.CompatibleSMul E F 𝕜 𝕝
hs : StrictConvex 𝕜 s
f : E →ₗ[𝕝] F
hf : IsOpenMap ↑f
x : E
hx : x ∈ s
y : E
hy : y ∈ s
hxy : ↑f x ≠ ↑f y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ a • ↑f x + b • ↑f y ∈ interior (↑f '' s) Tactic: rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ hxy a b ha hb hab State Before: case intro.intro.intro.intro
𝕜 : Type u_4
𝕝 : Type u_1
E : Type u_2
F : Type u_3
β : Type ?u.14448
inst✝¹⁰ : OrderedSemiring 𝕜
inst✝⁹ : TopologicalSpace E
inst✝⁸ : TopologicalSpace F
inst✝⁷ : AddCommMonoid E
inst✝⁶ : AddCommMonoid F
inst✝⁵ : Module 𝕜 E
inst✝⁴ : Module 𝕜 F
s : Set E
inst✝³ : Semiring 𝕝
inst✝² : Module 𝕝 E
inst✝¹ : Module 𝕝 F
inst✝ : LinearMap.CompatibleSMul E F 𝕜 𝕝
hs : StrictConvex 𝕜 s
f : E →ₗ[𝕝] F
hf : IsOpenMap ↑f
x : E
hx : x ∈ s
y : E
hy : y ∈ s
hxy : ↑f x ≠ ↑f y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ a • ↑f x + b • ↑f y ∈ interior (↑f '' s) State After: case intro.intro.intro.intro
𝕜 : Type u_4
𝕝 : Type u_1
E : Type u_2
F : Type u_3
β : Type ?u.14448
inst✝¹⁰ : OrderedSemiring 𝕜
inst✝⁹ : TopologicalSpace E
inst✝⁸ : TopologicalSpace F
inst✝⁷ : AddCommMonoid E
inst✝⁶ : AddCommMonoid F
inst✝⁵ : Module 𝕜 E
inst✝⁴ : Module 𝕜 F
s : Set E
inst✝³ : Semiring 𝕝
inst✝² : Module 𝕝 E
inst✝¹ : Module 𝕝 F
inst✝ : LinearMap.CompatibleSMul E F 𝕜 𝕝
hs : StrictConvex 𝕜 s
f : E →ₗ[𝕝] F
hf : IsOpenMap ↑f
x : E
hx : x ∈ s
y : E
hy : y ∈ s
hxy : ↑f x ≠ ↑f y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ ↑f (a • x + b • y) = a • ↑f x + b • ↑f y Tactic: refine' hf.image_interior_subset _ ⟨a • x + b • y, hs hx hy (ne_of_apply_ne _ hxy) ha hb hab, _⟩ State Before: case intro.intro.intro.intro
𝕜 : Type u_4
𝕝 : Type u_1
E : Type u_2
F : Type u_3
β : Type ?u.14448
inst✝¹⁰ : OrderedSemiring 𝕜
inst✝⁹ : TopologicalSpace E
inst✝⁸ : TopologicalSpace F
inst✝⁷ : AddCommMonoid E
inst✝⁶ : AddCommMonoid F
inst✝⁵ : Module 𝕜 E
inst✝⁴ : Module 𝕜 F
s : Set E
inst✝³ : Semiring 𝕝
inst✝² : Module 𝕝 E
inst✝¹ : Module 𝕝 F
inst✝ : LinearMap.CompatibleSMul E F 𝕜 𝕝
hs : StrictConvex 𝕜 s
f : E →ₗ[𝕝] F
hf : IsOpenMap ↑f
x : E
hx : x ∈ s
y : E
hy : y ∈ s
hxy : ↑f x ≠ ↑f y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ ↑f (a • x + b • y) = a • ↑f x + b • ↑f y State After: no goals Tactic: rw [map_add, f.map_smul_of_tower a, f.map_smul_of_tower b] |
```python
%%HTML
<!-- Mejorar visualización en proyector -->
<style>
.rendered_html {font-size: 1.2em; line-height: 150%;}
div.prompt {min-width: 0ex; padding: 0px;}
.container {width:95% !important;}
</style>
```
<!-- Mejorar visualización en proyector -->
<style>
.rendered_html {font-size: 1.2em; line-height: 150%;}
div.prompt {min-width: 0ex; padding: 0px;}
.container {width:95% !important;}
</style>
```python
%autosave 0
%matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display
import ipywidgets as widgets
from matplotlib import animation
from functools import partial
slider_layout = widgets.Layout(width='600px', height='20px')
slider_style = {'description_width': 'initial'}
IntSlider_nice = partial(widgets.IntSlider, style=slider_style, layout=slider_layout, continuous_update=False)
FloatSlider_nice = partial(widgets.FloatSlider, style=slider_style, layout=slider_layout, continuous_update=False)
SelSlider_nice = partial(widgets.SelectionSlider, style=slider_style, layout=slider_layout, continuous_update=False)
```
Autosave disabled
# Aprendizaje Supervisado
Esquema donde se busca aprender un mapeo o función
$$
f_{\theta}: \mathcal{X} \rightarrow \mathcal{Y},
$$
donde $\mathcal{X}$ es el dominio de nuestros datos (entrada) e $\mathcal{Y}$ es un objetivo (salida)
Entrenamos nuestro modelo a partir de un conjunto de $N$ ejemplos:
$$
\{(x_1, y_1), (x_2, y_2), \ldots, (x_N, y_N)\},
$$
donde cada ejemplo es una tupla formada de datos $x_i \in \mathcal{X}$ y objetivo $y_i \in \mathcal{Y}$
Si la variable objetivo es
- continua: hablamos de un problema de regresión o aproximación de funciones
- categórica: hablamos de un problema de clasificación
La naturaleza de los datos depende del problema
Lo más común es que los datos $x_i$ se estructuren como arreglos de $M$ componentes
A los componentes los llamamos atributos o *features*
### Aprendizaje
El vector $\theta$ corresponde a los **parámetros** del modelo
> Aprender o ajustar el modelo corresponde a encontrar el valor "óptimo" de $\theta$
Usamos una **función de pérdida/costo** $L(\theta)$ para medir el error de nuestro modelo
> **Minimizamos** la función de costo para encontrar el mejor $\theta$
Cuando hablamos de $\theta$ "óptimo" lo decimos en el sentido de una función de costo particular
### Optimización
Queremos resolver el siguiente problema
$$
\min_\theta L(\theta)
$$
Una opción es evaluar $L()$ en todo el espacio de posibles $\theta$: Fuerza Bruta
Pero en general esto no es computacionalmente posible
Podemos usar **técnicas de optimización** para encontrar el mejor $\theta$
Si $L(\theta)$ es continua y derivable podemos escribir
$$
\nabla_\theta L(\theta) = \vec 0
$$
e intentar despejar $\theta~$
## Regresión lineal
Modelo para aprender una mapeo entre una o más variables continuas (atributos) hacia una variable continua (objetivo)
En un esquema con $M$ atributos y $N$ ejemplos tenemos
$$
y_i = f_\theta(\vec x_i) = \vec w^T \vec x_i + b = \sum_{j=1}^M w_j x_{ij} + b,
$$
donde $f_\theta$ es un modelo parámetrico (hiperplano) con $M+1$ parámetros
$$
\theta= \begin{pmatrix} b \\ w_1 \\ w_2 \\ \vdots \\ w_M \end{pmatrix}
$$
También podemos escribir el sistema matricialmente como
$$
Y = X \theta
$$
donde $Y= \begin{pmatrix} y_1 \\ y_2 \\ \vdots \\y_N\end{pmatrix} \in \mathbb{R}^N$, $X = \begin{pmatrix} 1 & x_{11} & x_{12}& \ldots& x_{1M} \\ \vdots & \vdots & \vdots& \ddots& \vdots \\ 1 & x_{N1} & x_{N2}& \ldots& x_{NM} \\ \end{pmatrix} \in \mathbb{R}^{N\times M}$ y $\theta \in \mathbb{R}^M$
Una función de costo razonable es
$$
L(\theta) = \frac{1}{2} (Y - X\theta)^T (Y - X\theta)
$$
que corresponde al cuadrado de los errores
Luego si derivamos e igualamos a cero obtenemos
$$
\nabla_\theta L(\theta) = -X^T(Y-X\theta) = 0,
$$
y despejando
$$
\hat \theta = (X^T X)^{-1} X^T Y
$$
siempre y cuando podamos invertir $X^T X$
> Esto se conoce como solución de mínimos cuadrados
#### Funciones base
Podemos generalizar el regresor lineal aplicando transformaciones a $X$
Por ejemplo una regresión polinomial de grado $M$ sería
$$
y_i = f_\theta(x_i) = \sum_{j=1}^M w_j x_{i}^j + b,
$$
y su solución sería
$$
\hat \theta = (\Phi^T \Phi)^{-1} \Phi^T Y,
$$
donde $\Phi = \begin{pmatrix} 1 & x_1 & x_1^2& \ldots& x_1^M \\ \vdots & \vdots & \vdots& \ddots& \vdots \\ 1 & x_N & x_N^2& \ldots& x_N^M \\ \end{pmatrix}$
```python
plt.close('all'); fig, ax = plt.subplots(figsize=(6, 4), tight_layout=True)
poly_basis = lambda x,N : np.vstack([x**k for k in range(N)]).T
theta = [10, -2, -0.3, 0.1]
x = np.linspace(-5, 6, num=21);
X = poly_basis(x, len(theta))
y = np.dot(X, theta)
rseed, sigma = 0, 1.
np.random.seed(rseed);
Y = y + sigma*np.random.randn(len(x))
P = np.random.permutation(len(x))
train_idx, valid_idx = P[:len(x)//2], P[len(x)//2:]
def update_plot(ax, N):
ax.cla();
Phi = poly_basis(x, N)
theta_hat = np.linalg.lstsq(Phi[train_idx, :], Y[train_idx], rcond=None)[0]
ax.plot(x, y, 'g-', linewidth=2, label='Implícito', alpha=0.6, zorder=-100)
ax.scatter(x[train_idx], Y[train_idx], s=50, label='Entrenamiento')
ax.scatter(x[valid_idx], Y[valid_idx], s=50, label='Validación')
ax.vlines(x[train_idx], np.dot(Phi[train_idx, :], theta_hat), Y[train_idx])
ax.vlines(x[valid_idx], np.dot(Phi[valid_idx, :], theta_hat), Y[valid_idx])
x_plot = np.linspace(-5, 6, num=100);
ax.plot(x_plot, np.dot(poly_basis(x_plot, N), theta_hat), 'k-', linewidth=2, label='Modelo')
ax.set_ylim([-5, 15]); plt.legend()
widgets.interact(update_plot, ax=widgets.fixed(ax), N=IntSlider_nice(min=1, max=11));
```
<IPython.core.display.Javascript object>
interactive(children=(IntSlider(value=1, continuous_update=False, description='N', layout=Layout(height='20px'…
# Complejidad y Sobreajuste
En el ejemplo anterior vimos que se puede obtener modelos más flexibles si aumentamos el grado del polinomio
> Aumentar la cantidad de parámetros (grados de libertad) hace al modelo más flexible y más complejo
Si la flexibilidad es excesiva aproximamos los datos con cero error
Esto no es bueno ya que estamos aprendiendo "de memoria" los datos y ajustandonos al ruido
> Sobreajuste: Aprender perfectamente los datos usados para entrenar
El modelo sobreajustado predice muy mal los datos "que no ha visto"
> El sobreajuste es inversamente proporcional a la capacidad de generalización
Por esta razón usamos conjuntos de validación
Figura: https://www.d2l.ai/chapter_multilayer-perceptrons/underfit-overfit.html
# Representatividad y Validación
El primer paso para entrenar nuestro modelo es obtener datos (duh)
Es crítico que los datos que utilizemos **representen** adecuadamente el problema que queremos resolver
Sea un espacio de datos (circulo negro) y muestras (puntos azules), ¿que puede decir de los siguientes casos?
```python
from matplotlib.patches import Circle
fig, ax = plt.subplots(1, 2, figsize=(7, 3))
np.random.seed(19)
for ax_ in ax:
ax_.axis('off')
ax_.set_xlim([-3, 3])
ax_.set_ylim([-3, 3])
r = 2.5*np.random.rand(100); t = np.random.rand(100);
ax[0].scatter(r*np.cos(2.0*np.pi*t), r*np.sin(2.0*np.pi*t))
p = Circle((0, 0), 3, fill=False, ec='k')
ax[0].add_artist(p)
r = 2.5*np.random.rand(100); t = np.random.rand(100);
ax[1].scatter(r*np.cos(t), r*np.sin(t))
p = Circle((0, 0), 3, fill=False, ec='k')
ax[1].add_artist(p);
```
<IPython.core.display.Javascript object>
Siempre que podamos controlar el proceso de muestreo debemos poner atención a evitar **sesgos**
Asumiendo que nuestro dataset es representativo el siguiente paso es **entrenar**
Para combatir el sobreajuste podemos usar **estrategias de validación**
Consisten en separar el conjunto en dos o más subconjuntos
- Holdout: Entrenamiento/Validación/Prueba
- K-fold cross-validation y Leave one-out (N-fold) cross-validation
- Versiones estratificadas/balanceadas de las anteriores
Para que nuestro conjuntos de entrenamiento y validación sigan siendo representativos del total los **seleccionamos aleatoriamente**
Medimos $L(\theta)$ en entrenamiento y validación
> Optimizamos nuestro modelo minimizando el error de entrenamiento
> Seleccionamos los parámetros e hiper-parámetros que dan mínimo error de validación
> Comparamos distintas familias de modelos con el error de prueba
En el ejemplo anterior:
```python
fig, ax = plt.subplots(figsize=(6, 4), tight_layout=True)
N_values = np.arange(1, 11)
mse = np.zeros(shape=(len(N_values), 2))
for i, N in enumerate(N_values):
Phi = poly_basis(x, N)
theta_hat = np.linalg.lstsq(Phi[train_idx, :], Y[train_idx], rcond=None)[0]
mse[i, 0] = np.mean(np.power(Y[train_idx] - np.dot(Phi[train_idx, :], theta_hat), 2))
mse[i, 1] = np.mean(np.power(Y[valid_idx] - np.dot(Phi[valid_idx, :], theta_hat), 2))
ax.plot(N_values, mse[:, 0], label='Entrenamiento')
ax.plot(N_values, mse[:, 1], label='Validación')
idx_best = np.argmin(mse[:, 1])
ax.scatter(N_values[idx_best], mse[idx_best, 1], c='k', s=100)
plt.legend()
ax.set_ylim([1e-4, 1e+4])
ax.set_yscale('log')
ax.set_xlabel('Grado del polinomio')
ax.set_ylabel('Loss');
```
<IPython.core.display.Javascript object>
En resumen
- Bajo error de entrenamiento y de validación: **Ideal**
- Bajo error de entrenamiento y alto error de validación: **Modelo sobreajustado**
- Alto error de entrenamiento y de validación: Considera otro modelo y/o revisa tu código
## Neurona artificial o regresor logístico
Modelo para aprender una mapeo entre una o más variables continuas (atributos) hacia una variable binaria (objetivo)
$$
y_i \leftarrow f_\theta(\vec x_i) = \mathcal{S} \left(\theta_0 + \sum_{j=1}^M \theta_j x_{ij}\right)
$$
donde $\mathcal{S}(z) = \frac{1}{1+\exp(-z)} \in [0, 1]$ se conoce como función logística o sigmoide
> Modelo de clasificación binaria (dos clases)
Podemos interpretar la salida del clasificador como una probabilidad
```python
```
```python
data = np.concatenate((np.random.randn(50, 2), 1.5 + np.random.randn(50, 2)), axis=0)
label = np.array([0]*50 + [1]*50)
fig, ax = plt.subplots(1, figsize=(9, 4))
from matplotlib import cm
#fig.colorbar(cm.ScalarMappable(cmap=plt.cm.RdBu_r), ax=ax)
x_min, x_max = data[:, 0].min() - 0.5, data[:, 0].max() + 0.5
y_min, y_max = data[:, 1].min() - 0.5, data[:, 1].max() + 0.5
xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.05), np.arange(y_min, y_max, 0.05))
def sigmoid(X, w, b):
Z = np.dot(X, w) + b
return 1./(1 + np.exp(-Z))
def update_plot(w1, w2, b):
ax.cla()
ax.scatter(data[:50, 0], data[:50, 1], c='k', s=20)
ax.scatter(data[50:, 0], data[50:, 1], c='k', s=20, marker='x')
ax.contourf(xx, yy, sigmoid(np.c_[xx.ravel(), yy.ravel()], np.array([w1, w2]), b).reshape(xx.shape),
cmap=plt.cm.RdBu_r, alpha=0.75)
widgets.interact(update_plot,
w1=FloatSlider_nice(min=-10, max=10),
w2=FloatSlider_nice(min=-10, max=10),
b=FloatSlider_nice(min=-10, max=10));
```
<IPython.core.display.Javascript object>
interactive(children=(FloatSlider(value=0.0, continuous_update=False, description='w1', layout=Layout(height='…
¿Qué función de costo es apropiada en este caso?
Tipicamente se usa la **Entropía Cruzada Binaria**
$$
L(\theta) = \sum_{i=1}^N -y_i \log( f_\theta(\vec x_i) ) - (1-y_i) \log(1 - f_\theta(\vec x_i))
$$
¿Por qué?
Calculemos su gradiente
$$
\begin{align}
\frac{d}{d \theta_j} L(\theta) &= \sum_{i=1}^N \left(-\frac{y_i}{f_\theta(\vec x_i)} + \frac{1-y_i}{1 - f_\theta(\vec x_i)}\right) \frac{f_\theta(\vec x_i)}{d\theta_j} \nonumber \\
&= (y_i - f_\theta(\vec x_i)) x_{ij}
\end{align}
$$
Por la no linealidad $f_\theta(\vec x_i)$ ya no podemos despejar analiticamente $\theta$
> Podemos usar métodos de optimización iterativos
## Optimización: Método de Newton
Sea el valor actual del vector de parámetros $\theta_t$
Queremos encontrar el mejor "próximo valor" según nuestra función objetivo
$$
\theta_{t+1} = \theta_t + \Delta \theta
$$
Consideremos la aproximación de Taylor de segundo orden de $f$
$$
f(\theta_{t} + \Delta \theta) \approx f(\theta_t) + \nabla f (\theta_t) \Delta \theta + \frac{1}{2} \Delta \theta^T H_f (\theta_t) \Delta \theta
$$
Derivando en función de $\Delta \theta$ e igualando a cero tenemos
$$
\begin{align}
\nabla f (\theta_t) + H_f (\theta_t) \Delta \theta &= 0 \nonumber \\
\Delta \theta &= - [H_f (\theta_t)]^{-1}\nabla f (\theta_t) \nonumber \\
\theta_{t+1} &= \theta_{t} - [H_f (\theta_t)]^{-1}\nabla f (\theta_t) \nonumber \\
\end{align}
$$
- Se obtiene una regla iterativa en función del **Gradiente** y del **Hessiano**
- La solución depende de $\theta_0$
- "Asumimos" que la aproximación de segundo orden es "buena"
- Si nuestro modelo tiene $N$ parámetros el Hessiano es de $N\times N$, ¿Qué pasa si $N$ es grande?
## Optimización: Gradiente descendente
Si el Hessiano es prohibitivo podemos usar una aproximación de primer orden
El método más clásico es el **gradiente descendente**
$$
\theta_{t+1} = \theta_{t} - \eta \nabla f (\theta_t)
$$
donde hemos reemplazado el Hessiano por una constante $\eta$ llamado "paso" o "tasa de aprendizaje"
- ¿Cómo cambia la optimización con distintos $\eta$?
- ¿Qué ocurre cuando la superficie de error tiene mínimos locales?
```python
plt.close('all'); fig, ax = plt.subplots(2, figsize=(7, 4), tight_layout=True, sharex=True)
x = np.linspace(-4, 6, num=100)
f = lambda theta : 5+ (theta-1.)**2 #+ 10*np.sin(theta)
df = lambda theta : 2*(theta -1.) #+ 10*np.cos(theta)
df2 = lambda theta : 2 #- 10*np.cos(theta)
t = 10*np.random.rand(10) - 4.
ax[0].plot(x, f(x))
sc = ax[0].scatter(t, f(t), s=100)
ax[1].set_xlabel(r'$\theta$')
ax[0].set_ylabel(r'$f(\theta)$')
ax[1].plot(x, -df(x))
ax[1].set_ylabel(r'$-\nabla f(\theta)$')
eta = 0.01
def update(n):
t = sc.get_offsets()[:, 0]
t -= eta*df(t)
#t -= df(t)/(df2(t)+10)
sc.set_offsets(np.c_[t, f(t)])
anim = animation.FuncAnimation(fig, update, frames=100, interval=200, repeat=False, blit=True)
```
<IPython.core.display.Javascript object>
# Neurona artificial en [PyTorch](https://pytorch.org/)
```python
import torch
from torch.utils.data import DataLoader, TensorDataset, Subset
torch_set = TensorDataset(torch.from_numpy(data.astype('float32')),
torch.from_numpy(label.astype('float32')))
import sklearn.model_selection
train_idx, test_idx = next(sklearn.model_selection.ShuffleSplit(train_size=0.6).split(data, label))
torch_train_loader = DataLoader(Subset(torch_set, train_idx), shuffle=True, batch_size=16)
torch_valid_loader = DataLoader(Subset(torch_set, test_idx), shuffle=False, batch_size=256)
```
/home/hackerter/.local/lib/python3.6/site-packages/sklearn/model_selection/_split.py:1788: FutureWarning: From version 0.21, test_size will always complement train_size unless both are specified.
FutureWarning)
```python
class Neurona(torch.nn.Module):
def __init__(self):
super(Neurona, self).__init__()
self.fc = torch.nn.Linear(in_features=2, out_features=1, bias=True)
self.activation = torch.nn.Sigmoid()
def forward(self, x):
return self.activation(self.fc(x))
```
```python
fig, ax = plt.subplots(1, 2, figsize=(8, 3.5), tight_layout=True)
net = Neurona()
n_epochs = 1000
optimizer = torch.optim.SGD(net.parameters(), lr=1e-2)
criterion = torch.nn.BCELoss(reduction='sum')
running_loss = np.zeros(shape=(n_epochs, 2))
def train_one_epoch(net):
train_loss, valid_loss = 0.0, 0.0
for sample_data, sample_label in torch_train_loader:
output = net(sample_data)
optimizer.zero_grad()
loss = criterion(output, sample_label)
train_loss += loss.item()
loss.backward()
optimizer.step()
for sample_data, sample_label in torch_valid_loader:
output = net(sample_data)
loss = criterion(output, sample_label)
valid_loss += loss.item()
return train_loss/torch_train_loader.dataset.__len__(), valid_loss/torch_valid_loader.dataset.__len__()
def update_plot(k):
global net, running_loss
[ax_.cla() for ax_ in ax]
running_loss[k, 0], running_loss[k, 1] = train_one_epoch(net)
Z = net.forward(torch.from_numpy(np.c_[xx.ravel(), yy.ravel()].astype('float32')))
Z = Z.detach().numpy().reshape(xx.shape)
ax[0].contourf(xx, yy, Z, cmap=plt.cm.RdBu_r, alpha=1., vmin=0, vmax=1)
for i, (marker, name) in enumerate(zip(['o', 'x'], ['Train', 'Test'])):
ax[0].scatter(data[label==i, 0], data[label==i, 1], color='k', s=10, marker=marker, alpha=0.5)
ax[1].plot(np.arange(0, k+1, step=1), running_loss[:k+1, i], '-', label=name+" cost")
plt.legend(); ax[1].grid()
#update_plot(0)
anim = animation.FuncAnimation(fig, update_plot, frames=n_epochs,
interval=10, repeat=False, blit=False)
```
<IPython.core.display.Javascript object>
# Métricas: Evaluando un clasificador binario
La salida de este clasificador es un valor en el rango $[0, 1]$
Para tomar un decisión binaria se debe seleccionar un umbral $\mathcal{T}$ tal que
$$
d_i =
\begin{cases}
0, & \text{si } f_\theta(\vec x_i) < \mathcal{T} \\
1, & \text{si } f_\theta(\vec x_i) \geq \mathcal{T}
\end{cases}
$$
Una vez seleccionado el umbral se puede contar la cantidad de
- **True positives** (TP): Era clase (1) y lo clasifico como (1)
- **True negative** (TN): Era clase (0) y lo clasifico como (0)
- **False positives** (FP): Era clase (0) y lo clasifico como (1): Error tipo I
- **False negative** (FN): Era clase (1) y lo clasifico como (0): Error tipo II
A partir de estas métricas se construye la **tabla de confusión** del clasificador
|Clasificado como/En realidad era|Positivo|Negativo|
|---|---|---|
|Positivo:|TP | FP |
|Negativo:| FN | TN |
En base a estas métricas se construyen otras
$$
\text{Recall} = \frac{TP}{TP + FN}
$$
también conocida como la **Tasa de verdaderos positivos** (TPR) o sensitividad
> TPR: La proporción de positivos correctamente clasificados respecto al total de positivos
$$
\text{FPR} = \frac{FP}{TN + FP} = 1 - \frac{TN}{TN + FP}
$$
la **tasa de falsos positivos** (FPR) también representada como "1 - especificidad"
> FPR: La proporción de negativos incorrectamente clasificados respecto al total de negativos
$$
\text{Precision} = \frac{TP}{TP + FP}
$$
también conocido como pureza
> Precision: La proporción de positivos correctamente clasificados respecto a todos los ejemplos clasificados como positivo
$$
\text{Accuracy} = \frac{TP+TN}{TP + FP + FN+ TN}
$$
> Accuracy: La proporción de ejemplos correctamente clasificados
$$
\text{f1-score} = \frac{2*\text{Recall}*\text{Precision}}{\text{Recall} + \text{Precision}}
$$
> f1-score: Media armónica entre Recall y Precision asumiendo igual ponderación
Si las clases son desbalanceadas entonces f1-score es más aconsejable que accuracy
```python
net = Neurona()
probability = net(torch_set.tensors[0]).detach().numpy()
import sklearn.metrics
print("Matriz de confusión:")
print(sklearn.metrics.confusion_matrix(y_true=torch_set.tensors[1].numpy().astype(int),
y_pred=probability[:, 0] > 0.5))
print(sklearn.metrics.classification_report(y_true=torch_set.tensors[1].numpy().astype(int),
y_pred=probability[:, 0] > 0.5))
```
Matriz de confusión:
[[40 10]
[ 9 41]]
precision recall f1-score support
0 0.82 0.80 0.81 50
1 0.80 0.82 0.81 50
micro avg 0.81 0.81 0.81 100
macro avg 0.81 0.81 0.81 100
weighted avg 0.81 0.81 0.81 100
Notar que a distintos umbrales $\mathcal{T}$ se obtienen distintas tablas de confusión
Se midemos estas métricas usando distintos umbrales podemos construir una curva de desempeño
Tipicamente se usan
- Curva ROC: TPR vs FPR
- Curva Precision vs Recall
```python
fpr, tpr, th = sklearn.metrics.roc_curve(y_true=torch_set.tensors[1].numpy().astype(int),
y_score=probability[:, 0])
fig, ax = plt.subplots(figsize=(7, 4))
ax.plot(fpr, tpr);
ax.set_xlabel('Tasa de Falsos positivos')
ax.set_ylabel('Tasa de Verdaderos Positivos (Recall)')
ax.set_title('AUC: %f' %sklearn.metrics.auc(fpr, tpr))
```
<IPython.core.display.Javascript object>
Text(0.5, 1.0, 'AUC: 0.866000')
```python
prec, rec, th = sklearn.metrics.precision_recall_curve(y_true=torch_set.tensors[1].numpy().astype(int),
probas_pred=probability[:, 0])
fig, ax = plt.subplots(figsize=(7, 4))
ax.plot(rec, prec, '-');
ax.set_xlabel('Recall')
ax.set_ylabel('Precision')
```
<IPython.core.display.Javascript object>
Text(0, 0.5, 'Precision')
# Ojo con:
#### La distribución de los datos donde se aplicará el clasificador es distinta a la que usaste para entrenar/validar
Actualiza tus conjuntos de datos para que sean representativos!
#### Usa los subconjuntos adecuadamente
Ajusta los parámetros con el set de validación
Compara distintas familias de modelos con el set de prueba
#### La métrica que usas no es la adecuada para el problema
Si el problema tiene clases desbalanceadas el *accuracy* puede ser muy alto, contrasta usando métricas sencibles al desbalance (e.g. *f1-score*)
#### Mi modelo se sobreajusta de inmediato
Prueba disminuyendo la complejidad/arquitectura del modelo o añadiendo **regularización**
Esto también puede ser señal de que necesitas más ejemplos para entrenar
Se pueden usar **Técnicas de aumentación** de datos
#### Mi modelo no está aprendiendo
Si estas seguro que no hay bugs prueba aumentando la complejidad del modelo
#### Estudia los errores de tu modelo para mejorarlo
Analiza los datos mal clasificados y busca patrones
Revisa que las etiquetas estén correctas
Revisa que los atributos estén adecuadamente calculados
Propon nuevos atributos que ayuden a clasificador los ejemplos difíciles
```python
```
|
Require Import Monad.
Require Import NCM.
Require Import List.
Require Import Orders.
Require Import Mergesort.
Require Import Arith.
Import ListNotations.
Variable A : Type.
Variable a1 a2 a3: A.
Module FinMapOrder <: TotalLeBool.
Definition t := nat * A.
Fixpoint leb (x y : t) := let (m,_) := x in
let (n,_) := y in
(m <=? n)%nat.
Infix "<=?" := leb (at level 70).
Theorem leb_total : forall a1 a2, (a1 <=? a2 =true) \/ (a2 <=? a1 = true).
Proof.
intros [a1] [a2].
simpl.
rewrite 2 Nat.leb_le.
apply Nat.le_ge_cases.
Qed.
End FinMapOrder.
Module Import FinMapSort := Sort FinMapOrder.
Section ListContext.
Set Implicit Arguments.
Definition FinMap := list (nat * A).
Definition ListContext := option FinMap.
Eval compute in (sort [(1,a1); (3,a3); (0,a2); (2,a1)]%nat).
(* TODO: Disjoint merge that also sorts the inputs *)
Definition mergeListContext' (ls1 ls2 : FinMap) : ListContext.
Admitted.
Definition mergeListContext (ls1 ls2 : ListContext) : ListContext :=
match ls1, ls2 with
| Some ls1', Some ls2' => mergeListContext' ls1' ls2'
| _, _ => None
end.
Definition singleton (x : nat) (a : A) : ListContext :=
Some ((x,a) :: nil).
Instance NCM_ListContext : NCM ListContext :=
{ one := Some nil
; zero := None
; m := mergeListContext
; base := fun b => exists x a, b = singleton x a}.
Opaque base.
Lemma singleton_base : forall x a, base (singleton x a).
Proof. intros. exists x. exists a. reflexivity. Defined.
Hint Resolve singleton_base.
(* TODO: laws *)
Instance NCM_ListContext_Laws : NCM_Laws ListContext.
Admitted.
Example test : forall (x : nat) (a : A), singleton x a ∙ singleton x a = 0.
Proof.
intros. reification.
Defined.
End ListContext.
|
[STATEMENT]
lemma [trans] : "P' \<subseteq> P \<Longrightarrow> \<Gamma>,\<Theta>\<turnstile>\<^sub>t\<^bsub>/F\<^esub> P c Q,A \<Longrightarrow> \<Gamma>,\<Theta>\<turnstile>\<^sub>t\<^bsub>/F\<^esub> P' c Q,A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<lbrakk>P' \<subseteq> P; \<Gamma>,\<Theta>\<turnstile>\<^sub>t\<^bsub>/F\<^esub> P c Q,A\<rbrakk> \<Longrightarrow> \<Gamma>,\<Theta>\<turnstile>\<^sub>t\<^bsub>/F\<^esub> P' c Q,A
[PROOF STEP]
by (rule conseqPre) |
module System.Concurrency.Raw
-- At the moment this is pretty fundamentally tied to the Scheme RTS
-- Given that different back ends will have entirely different threading
-- models, it might be unavoidable, but we might want to think about possible
-- primitives that back ends should support.
%foreign "scheme:blodwen-thisthread"
prim__threadID : PrimIO ThreadID
%foreign "scheme:blodwen-set-thread-data"
prim__setThreadData : {a : Type} -> a -> PrimIO ()
%foreign "scheme:blodwen-get-thread-data"
prim__getThreadData : (a : Type) -> PrimIO a
-- Mutexes and condition variables.
export
threadID : IO ThreadID
threadID = primIO prim__threadID
export
setThreadData : {a : Type} -> a -> IO ()
setThreadData val = primIO (prim__setThreadData val)
export
getThreadData : (a : Type) -> IO a
getThreadData a = primIO (prim__getThreadData a)
export
data Mutex : Type where [external]
%foreign "scheme:blodwen-mutex"
prim__makeMutex : PrimIO Mutex
%foreign "scheme:blodwen-lock"
prim__mutexAcquire : Mutex -> PrimIO ()
%foreign "scheme:blodwen-unlock"
prim__mutexRelease : Mutex -> PrimIO ()
export
makeMutex : IO Mutex
makeMutex = primIO prim__makeMutex
export
mutexAcquire : Mutex -> IO ()
mutexAcquire m = primIO (prim__mutexAcquire m)
export
mutexRelease : Mutex -> IO ()
mutexRelease m = primIO (prim__mutexRelease m)
export
data Condition : Type where [external]
%foreign "scheme:blodwen-condition"
prim__makeCondition : PrimIO Condition
%foreign "scheme:blodwen-condition-wait"
prim__conditionWait : Condition -> Mutex -> PrimIO ()
%foreign "scheme:blodwen-condition-wait-timeout"
prim__conditionWaitTimeout : Condition -> Mutex -> Int -> PrimIO ()
%foreign "scheme:blodwen-condition-signal"
prim__conditionSignal : Condition -> PrimIO ()
%foreign "scheme:blodwen-condition-broadcast"
prim__conditionBroadcast : Condition -> PrimIO ()
export
makeCondition : IO Condition
makeCondition = primIO prim__makeCondition
export
conditionWait : Condition -> Mutex -> IO ()
conditionWait c m = primIO (prim__conditionWait c m)
||| Timeout is in microseconds
export
conditionWaitTimeout : Condition -> Mutex -> Int -> IO ()
conditionWaitTimeout c m t = primIO (prim__conditionWaitTimeout c m t)
export
conditionSignal : Condition -> IO ()
conditionSignal c = primIO (prim__conditionSignal c)
export
conditionBroadcast : Condition -> IO ()
conditionBroadcast c = primIO (prim__conditionBroadcast c)
|
REBOL [
; -- Core Header attributes --
file: %app-theme-base.r
; -- slim - Library Manager --
slim-name: 'app-theme-base
slim-version: 1.2.7
slim-prefix: none
slim-update: http://www.revault.org/downloads/modules/sillica.r
]
slim/register [
; overide the basic theme values, which are derived by other theme values.
set 'theme-bg-color white
] |
module API.Web.Console
import IdrisScript
%access public export
%default total
-- TODO: Proper type
log : String -> JS_IO ()
log = jscall "console.log(%0)" (String -> JS_IO ())
|
Debats du Senat (hansard)
1ere Session, 36 e Legislature,
Volume 137, Numero 101
Le lundi 7 decembre 1998
L'honorable Gildas L. Molgat, President
L'honorable Jean B. Forest
Le quatre-vingt-unieme anniversaire de l'explosion dans le port de Halifax
Le cinquantieme anniversaire de la Declaration des droits de l'homme
La journee nationale de commemoration
La violence dirigee contre les femmes
L'anniversaire de la signature de la Charte de l'Atlantique a Terre-Neuve
Avis de motion sur sa nomination
Projet de loi modificatif-Premiere lecture
Projet de loi visant a changer le nom de la circonscription electorale de Stormont-Dundas
Projet de loi visant a changer le nom de la circonscription d'Argenteuil-Papineau
L'Association parlementaire Canada-Europe
La reunion du Conseil de l'Europe tenue a Strasbourg, en France-Depot du rapport
Garde et droit de visite des enfants
La Societe de developpement du Cap-Breton
Projet de loi modificatif-Troisieme lecture- Suite du debat
Le budget des depenses de 1998-1999
Adoption du rapport du comite des finances nationales sur le Budget supplementaire (B)
Projet de loi modificatif-Deuxieme lecture-Ajournement du debat
Les travaux du Senat
Projet de loi modificatif-Premiere lecture
Projet de loi sur la corruption d'agents publics etrangers
Le lundi 7 decembre 1998
La seance est ouverte a 16 heures, le President etant au fauteuil.
L'honorable Jean B. Forest
L'honorable B. Alasdair Graham (leader du gouvernement) :
On ne peut pas croire des choses impossibles.
Rever le reve impossible.
Cependant, elle est de retour parmi nous aujourd'hui et se trouve a la tribune.
Elle est egalement officier de l'Ordre du Canada.
Elle a ete une source d'inspiration pour nous tous.
Jean, vous nous manquez.
L'honorable Mabel M. DeWare :
Jean et son mari celebraient un anniversaire bien special cet automne-la.
Durant cette breve periode, elle a ete une parlementaire exemplaire.
J'apprecie la contribution utile qu'elle a apportee.
Elle s'est distinguee a d'autres comites senatoriaux, notamment celui des finances nationales.
Le senateur Forest et moi-meme attachons aussi beaucoup d'importance a la famille.
C'est une epouse, une mere et une grand-mere fiere et aimante.
L'honorable Jean Forest nous a quittes beaucoup trop tot.
L'honorable Therese Lavoie-Roux :
Honorables senateurs, il me fait plaisir de rendre hommage au senateur Jean Forest.
Pourquoi pas Jeanne Forest?
C'est de la petite histoire ici au Quebec.
Ce qui m'a frappee chez le senateur Forest, c'etait son impartialite.
Nous garderons de vous un excellent souvenir.
Nous nous impliquons dans autre chose.
L'honorable Sharon Carstairs (leader adjoint du gouvernement) :
Honorables senateurs, nous rendons hommage aujourd'hui a une dame tres speciale et tres elegante:
Je ne connaissais Jean que de reputation lorsqu'elle est arrivee au Senat.
Pour Jean et moi, la question des ecoles a Terre-Neuve a ete difficile.
Jean, assurez-vous que Rocky fait regulierement sa promenade.
Nous voulons qu'il reste encore longtemps parmi nous.
Prenez soin de lui.
Prenez soin de vous.
Surtout, n'oubliez pas que nous vous portons une tres grande affection.
Nous savons qu'elle ne fait que visiter Victoria et ces autres endroits.
Elle a repondu aux attentes avec distinction.
Elle faisait ce travail pour sa region et son pays.
C'est vrai de tous ceux qui ont eu affaire a elle.
Jean, nous vous souhaitons une vie heureuse, ainsi qu'a Rocky et a votre famille.
Nous esperons rester en contact avec vous.
L'honorable Gerry St. Germain :
Honorables senateurs, je veux, moi aussi, rendre hommage a madame le senateur Jean Forest.
C'etait l'une de mes voisines a l'edifice Victoria.
On a dit d'elle qu'elle etait speciale et elegante.
J'ai appris a la connaitre en siegeant avec elle a certains comites.
J'ai bien aime travailler avec elle.
J'ai pu constater que la tache etait lourde.
Je savais qu'elle prendrait la bonne decision et elle l'a fait.
Elle savait toujours mettre de l'ordre dans ses priorites.
Je n'en dirai pas plus.
Que Dieu vous protege et merci.
L'honorable A. Raynell Andreychuk :
Personne ne peut aller en Alberta sans en apprendre sur madame le senateur Forest.
Elle est bien connue dans le systeme des colleges communautaires et celui des universites.
De facon generale, on doit prendre position d'un cote ou de l'autre.
Cela lui a valu d'etre tres respectee.
Elle a assiste a pratiquement toutes les reunions du comite.
Elle a ete presente durant toutes les audiences.
Elle le merite certainement.
J'esperais qu'elle reste avec nous au Senat.
Sa famille a toujours passe en premier et continue de passer en premier.
Nous esperons que vous continuerez de vous devouer a la cause de l'enseignement postsecondaire.
Je le fais apres avoir entendu les paroles du senateur Lavoie-Roux.
J'ai revu les arguments mis de l'avant par les legistes du ministere.
Vous connaissez la suite des evenements.
L'honorable Marcel Prud'homme:
Elle avait prevu ces choses.
Je l'avais bien ecoutee.
Voyez ce qui arrive depuis la fin de semaine.
Nous aurons raison beaucoup plus tot que prevu.
Elle a fait preuve d'une grande independance d'esprit politique.
Tous ecoutaient avec attention les interventions du senateur Forest.
J'ai suivi tres exactement ce qu'elle m'avait suggere de faire.
Elle est un exemple a suivre.
Mes meilleurs voeux accompagnent madame le senateur Forest.
Je connais cette dame merveilleuse depuis le debut des annees 70.
En Alberta, c'est plutot rare.
Elle a toujours accorde la priorite a sa famille et a Rocky.
J'ai connu le senateur Forest au comite des finances nationales.
Le quatre-vingt-unieme anniversaire de l'explosion dans le port de Halifax
L'honorable J. Michael Forrestall :
Le nord de Halifax a ete rase et des degats ont ete causes a Dartmouth.
Honorables senateurs, la population etant de 50 000 habitants, les pertes ont ete horribles.
Ils ont envoye medecins, infirmieres, nourriture et vetements.
Le cinquantieme anniversaire de la Declaration des droits de l'homme
L'honorable Mabel M. DeWare :
Cet anniversaire sera une celebration glorieuse de la vie et de la liberte.
Mais surtout, la declaration protege ces droits.
Les droits des femmes font partie des droits de la personne.
Honorables senateurs, il est facile pour les Canadiens de tenir ces droits pour acquis.
Il faut, pour cela, remonter au tout debut de l'existence des Nations Unies.
Mais il reste beaucoup a faire.
Certains pays continuent de nier aux femmes leurs droits politiques.
La journee nationale de commemoration
La violence dirigee contre les femmes
Les femmes et les enfants du Canada comptent sur nous.
L'anniversaire de la signature de la Charte de l'Atlantique a Terre-Neuve
En 1942, 26 pays avaient declare leur appui.
Leur cooperation devait mener plus tard a la creation de l'Organisation des Nations Unies.
Son Honneur le President :
Avis de motion sur sa nomination
L'honorable Sharon Carstairs (leader adjoint du gouvernement) :
Honorables senateurs, je donne avis que demain, le 8 decembre 1998, je proposerai:
Projet de loi modificatif-Premiere lecture
(Le projet de loi est lu une premiere fois.)
Son Honneur le President :
Honorables senateurs, quand lirons-nous ce projet de loi une deuxieme fois?
Projet de loi visant a changer le nom de la circonscription electorale de Stormont-Dundas
(Le projet de loi est lu une premiere fois.)
Son Honneur le President :
Honorables senateurs, quand lirons-nous ce projet de loi une deuxieme fois?
(Le projet de loi est lu une premiere fois.)
Son Honneur le President :
Honorables senateurs, quand lirons-nous ce projet de loi une deuxieme fois?
Projet de loi visant a changer le nom de la circonscription d'Argenteuil-Papineau
(Le projet de loi est lu une premiere fois.)
Son Honneur le President :
Honorables senateurs, quand lirons-nous ce projet de loi une deuxieme fois?
L'Association parlementaire Canada-Europe
La reunion du Conseil de l'Europe tenue a Strasbourg, en France-Depot du rapport
Garde et droit de visite des enfants
L'honorable Anne C. Cools :
Que, compte tenu des faits suivants:
L'honorable Noel A. Kinsella (chef adjoint suppleant de l'opposition) :
Honorables senateurs, la saga des forces des tenebres poursuit.
L'honorable B. Alasdair Graham (leader du gouvernement) :
Il suivra les recommandations de la commission et de sa presidente.
L'honorable Noel A. Kinsella (chef adjoint suppleant de l'opposition) :
L'entente a ete confirmee par la GRC le 11 novembre 1997.
L'honorable B. Alasdair Graham (leader du gouvernement) :
Non, j'arriverais plutot a la conclusion contraire.
J'ai une question complementaire.
Il n'a pas cite les bons passages.
Cependant, cette lettre dit:
Le leader du gouvernement pourrait-il expliquer pourquoi il n'a pas depose ces documents?
L'honorable B. Alasdair Graham (leader du gouvernement) :
J'ai lu des extraits de la lettre, non pas des documents.
Senateur Tkachuk, ou bien je deposerai le document, qui est tres epais...
Je m'en remets a la decision des honorables senateurs.
Le senateur Kinsella a probablement le document en question sur son bureau.
Il peut le montrer.
Cela me conviendrait tres bien.
Pouvez-vous me dire quand ces documents seraient deposes?
Son Honneur le President :
Les senateurs permettent-ils le depot de ces documents?
L'honorable Donald H. Oliver :
Ma question s'adresse au leader du gouvernement au Senat.
L'honorable B. Alasdair Graham (leader du gouvernement) :
La question est interessante.
L'honorable J. Michael Forrestall:
Honorables senateurs, j'ai une question a l'adresse du leader du gouvernement au Senat.
L'honorable B. Alasdair Graham (leader du gouvernement) :
Nous ne l'avons appris qu'au debut de l'apres-midi.
Un navire de la Garde cotiere est sur place.
Il est a souhaiter que toutes les personnes manquantes soient retrouvees vivantes.
Nous prierons pour qu'il en soit ainsi.
Je vais repondre a la question au nom du ministre.
La situation est effectivement grave.
C'est parce que les equipages de Sea King sont utilises a fond.
Nous savons tous que les appareils sont disponibles moins de 50 p. 100 du temps.
Les Labrador de Greenwood ne sont toujours pas en etat de voler.
Jusqu'en novembre, le NCSM Halifax avait un helicoptere.
L'honorable Gerry St. Germain :
Honorables senateurs, ma question s'adresse au leader du gouvernement au Senat.
L'honorable B. Alasdair Graham (leader du gouvernement) :
C'est une bonne question, mais je n'en connais pas la reponse.
J'espere pouvoir apporter la reponse des qu'on prendra la decision.
La Societe de developpement du Cap-Breton
L'honorable B. Alasdair Graham (leader du gouvernement) :
Honorables senateurs, j'en suis reconnaissant.
Si ces negociations ont ete autorisees, elles l'ont ete par le Cabinet.
Toutefois, il y a certes beaucoup de conjectures a ce sujet.
Mon collegue est d'accord avec cette proposition, je le suppose?
Honorables senateurs, je vais poser une question supplementaire.
L'honorable B. Alasdair Graham (leader du gouvernement) :
Oui, c'est ce que je crois comprendre, senateur Buchanan.
Projet de loi modificatif-Troisieme lecture- Suite du debat
Ma principale preoccupation concerne la position adoptee par le gouvernement.L'article
22.1 de l'accord Tuktut Nogait, signe en 1996, stipule:
L'avenir economique des habitants de la region revet egalement une grande importance.
Le parc national de Tuktut Nogait couvre une superficie de 16 340 kilometres carres.
Le parc aurait alors une superficie de 28 000 kilometres carres.
Nous avons entendu des prospecteurs dire que ce n'etait pas exagere.
Les Inuvialuit voudraient maintenant l'acces a ces ressources.
Toutefois, Parcs Canada dit: Desole, vous avez deja signe une entente.
Il s'agit de 16 340 kilometres carres.
Les Sahtu et le Nunavut ont donne 11 660 kilometres carres au parc.
Nous nous sommes informes aupres de Darnley Bay Resources.
L'entreprise nous a montre des diapositives de la zone.
Les Inuvialuit ont regle leurs revendications territoriales avec le gouvernement federal.
L'autre parc est situe sur le versant nord entre l'Alaska et le Yukon.
Les caribous de la Porcupine s'y rendent depuis des annees.
L'ete, les caribous suivent habituellement une piste le long de la rive.
Des agriculteurs mettent dans leurs champs des blocs de sel que les vaches viennent lecher.
Les caribous recherchent aussi le sel.
Je suis preoccupe par l'economie des Inuvialuit.
Ces jeunes n'auront pas d'emplois.
Le ministre des Peches et des Oceans a visite Iqaluit il y a un mois.
Il y a un quota pour l'omble de l'Arctique vendue dans le commerce.
Il importe que ces gens-la s'occupent du developpement du caribou.
On ne leur dit jamais rien.
En 1999, le Nunavut se gouvernera lui-meme.
C'etait il y a quelque 48 annees.
C'etait il y a 32 ans.
C'etait il y a pres de 14 ans.
Avant la conclusion d'une entente avec NTI, ils ont pris le relais de ITC.
Il nous a fallu 25 ans pour conclure une entente avec le gouvernement du Canada.
En fevrier 1999, nous aurons des elections.
Nous elirons une assemblee de 19 deputes.
Ce bout de terrain dont les Inuvialuit se preoccupent est important pour eux.
Les Inuvialuit s'inquietent de leur avenir si la mine est mise en exploitation.
Falconbridge se dit preoccupee par notre retard.
Jusqu'a maintenant, rien n'a ete fait.
Honorables senateurs, je suis toujours inquiet.
Sans tuer le projet de loi, nous pouvons faire quelque chose.
En effet, les reglements stipulent qu'il faut avoir termine sa douzieme annee.
Les caribous ne migrent pas ensemble.
C'est ce que j'ai pu observer quand je vivais dans le Nord.
Les gens qui proposent la creation de ce parc ne voient pas cela.
Honorables senateurs, je crois que nous devrions examiner de nouveau ce projet de loi.
Son Honneur le President :
Plait-il aux honorables senateurs d'adopter la motion?
(Sur la motion du senateur Carstairs, le debat est ajourne.)
Le budget des depenses de 1998-1999
Adoption du rapport du comite des finances nationales sur le Budget supplementaire (B)
- Honorables senateurs, je voudrais traiter brievement de ce rapport.
Ils sont cooperatifs, aimables, intelligents et extremement bien informes.
Ils connaissent tres bien leurs documents.
C'est pourquoi je veux remercier ce dernier de facon particuliere.
Je veux faire une mise en garde.
Y a-t-il une limite ou non a la contribution du Canada?
Nos obligations sont donc limitees.
C'est ecrit dans la Convention de Chicago relative a l'aviation civile internationale.
Nous nous inquietons aussi du montant d'argent depense pour les secours aux sinistres.
On peut facilement doubler ce chiffre.
Les catastrophes ont des incidences economiques importantes sur notre pays.
On ne saurait rester les bras croises en pareilles circonstances.
On achete bien des heures de travail de consultants independants pour une telle somme.
Ils sont tres nombreux.
Comme s'assurer que ces systemes sont vraiment en securite?
Cette question ne suscite pas suffisamment d'attention.
Je vais terminer sur cette observation.
Le temps passe et les couts augmentent.
J'espere que la situation ne perdurera pas trop longtemps.
Son Honneur le President :
L'honorable Sharon Carstairs (leader adjoint du gouvernement) :
Il est convenu de ne pas tenir compte de l'heure.
Son Honneur le President :
Est-ce d'accord, honorables senateurs?
Son Honneur le President :
Je ne tiendrai donc pas compte de l'heure.
D'habitude, on a un cadre des depenses.
On a d'abord des estimations principales et des budgets supplementaires.
On va hausser les depenses des programmes budgetaires de trois milliards de dollars.
D'autre part, il y a les depenses statutaires.
Par consequent, les allocations servent a ces questions.
J'indique que c'est la Banque de Thailande.
Il en reste deux milliards.
Cela montre les effets systemiques de la finance internationale, du financement public et prive.
Dans notre rapport sur le Sud-Est asiatique, on fait allusion a ces questions.
Les depenses legislatives touchent a peu pres un milliard et demi de dollars.
Vous savez que 70 p. 100 du budget du Canada est sur le pilote automatique.
Je ris, mais je devrais pleurer.
On peut le comprendre, c'est dans les limites du bon sens.
Ce qui s'en vient sera encore plus fort que cela.
Sur ces trois milliards de dollars, les depenses pour les pecheurs ont du bon sens.
Ils ont ete frappes durement dans les Maritimes et meme au Quebec.
Cela fait 600 millions de dollars.
Je comprends qu'il faut aider les cultivateurs sur une courte periode.
Les explications fournies sur la facon dont cet argent sera depense ne sont pas satisfaisantes.
Pour les pecheurs, la ressource n'est pas la.
C'est une situation difficile.
Je ne chicanerai pas le gouvernement a ce sujet.
Il faudrait voir clair et savoir ou on s'en va.
Le gouvernement actuel n'est pas le seul a faire cela.
D'autres l'ont fait auparavant, je ne me fais pas d'illusion.
On change les gouvernements, ils brassent les problemes, mais les problemes demeurent.
Outres ces depenses pour les ressources, une autre chose me frappe.
Le ministere du Developpement des ressources humaines intervient.
On en arrive a des solutions incomprehensibles aux profanes.
D'une certaine facon, c'est malheureux.
Un autre 500 millions de dollars va au report des depenses.
Je ne veux pas en discuter.
Un autre 300 millions de dollars est prevu pour le bogue de l'an 2000.
En tout cas, je ne prendrai pas l'avion a cette date.
On est dans l'insecurite pour l'annee prochaine.
Il y a quatre ou cinq ans, des gens ont achete des ordinateurs.
On n'avait pas prevu cela dans les logiciels.
On en est a un etat d'urgence!
Nous avons 200 millions de dollars pour les conventions collectives.
Le gouvernement n'avait pas donne d'argent aux fonctionnaires depuis longtemps.
J'ai vecu cela.
D'autres depenses m'inquietent.
Il tire un 100 ou 60 millions pour differentes priorites dans la sante.
Pourquoi est-ce que le federal s'embarque encore la-dedans?
Ce n'est pas la premiere fois que je parle de cela.
Il faut faire attention et le ministre des Finances doit etre d'une prudence terrible.
Son affaire n'est pas si haut sur pattes que les gens le disent.
Les agriculteurs s'en viennent aussi.
Vous ne pensez pas que cela ne coutera pas cher!
Vous voyez, il y a des couts.
Le gouvernement, dans l'annee, doit etre capable de voir venir ces situations.
Il est tres important que le gouvernement soit conscient de cela.
Je sais que les ministres ont tous le pied sur le gaz.
Je dis au ministre des Finances:
Il va falloir la payer la dette.
On s'attire des problemes quand on fait cela.
Ce n'est pas bon.
On va avoir un budget.
Je sais que le ministre des Finances dit que tout va bien, et cetera.
Je peux vous dire que c'est complique.
Au Quebec, c'est encore pire.
Il faut etre realiste.
La concurrence est la et le monde international est la.
On a une taxation au Canada - tout le monde reconnait cela - qui est trop lourde.
On est a 25 p. 100 trop cher en termes de taxation pour les individus.
C'est pour cela que les compagnies etrangeres ne viennent pas investir ici.
Les investissements etrangers au Canada ont baisse a cause de cela.
Il faut changer cela.
Il faut aller au coeur du sujet.
Les cinq prochaines annees seront difficiles.
Son Honneur le President :
Vous plait-il, honorables senateurs, d'adopter la motion?
(La motion est adoptee, et le rapport est adopte.)
Projet de loi modificatif-Deuxieme lecture-Ajournement du debat
Si l'obstacle est si terrible, pourquoi se donner toute cette peine?
Quelle difference le projet de loi C-42 peut-il bien faire?
Les provinces doivent explorer toutes les solutions pour decourager la consommation de tabac.
Pourquoi est-ce si important?
Parce qu'il est prouve que la commercialisation de la cigarette est efficace.
J'aimerais, parvenu a ce point, resumer les principaux elements du projet de loi.
Cette periode de transition donnera aux organisateurs le temps de trouver d'autres parrains.
Autrement dit, le compte a rebours est deja commence.
Ils sont comme l'appel des sirenes qui attirent les Canadiens vers un danger manifeste.
J'exhorte donc tous mes collegues a appuyer cette mesure legislative.
Les travaux du Senat
L'honorable Sharon Carstairs (leader adjoint du gouvernement):
Son Honneur le President :
Est-ce d'accord, honorables senateurs?
L'honorable Marcel Prud'homme :
Honorables senateurs, le leader adjoint dit des deux cotes de la Chambre.
Nous suivrons l'ordre du jour de la facon normale.
Son Honneur le President :
Est-ce d'accord, honorables senateurs?
Projet de loi modificatif-Premiere lecture
(Le projet de loi est lu une premiere fois.)
Son Honneur le President :
Honorables senateurs, quand lirons-nous ce projet de loi une deuxieme fois?
Projet de loi sur la corruption d'agents publics etrangers
(Le Senat s'ajourne a 14 heures demain.)
|
import control proof_trace
open polya tactic expr
variables u v w x y z : ℚ
meta def polya_on_hyps' (hys : list name) (rct : bool := tt) : tactic unit :=
do exps ← hys.mmap get_local,
bb ← add_proof_to_blackboard blackboard.mk_empty `(rat_one_gt_zero),
bb ← add_proofs_to_blackboard bb exps,
let pb := polya_bundle.default.set_blackboard bb,
let (n, pb) := pb.cycle 0,
trace ("number of cycles:", n),
trace ("contr found", pb.contr_found),
if bnot pb.contr_found then /-bb.trace >>-/ fail "polya failed, no contradiction found" else do
pb.bb.contr.sketch >>= proof_sketch.trace,
if rct then pb.bb.contr.reconstruct >>= apply >> skip
else skip
example (h1 : x > 0) (h2 : x < 1*1) (h3 : rat.pow (1*1 + (-1)*x) (-1) ≤ 1*(rat.pow (1*1 + (-1)*rat.pow x 2) (-1))) : false :=
by
polya_on_hyps' [`h1, `h2, `h3]
example (h1 : u > 0) (h2 : u < 1*v) (h3 : z > 0) (h4 : 1*z + 1*1 < 1*w) (h5 : rat.pow (1*u + 1*v + 1*z) 3 ≥ 1* rat.pow (1*u + 1*v + 1*w + 1*1) 5) : false :=
by polya_on_hyps' [`h1, `h2, `h3, `h4, `h5]
|
function [year,month,day,hour,minute,second]=TT2Cal(Jul1,Jul2,givenDayFrac)
%%TT2CAL Convert terrestrial times (TT) given as a two-part pseudo-Julian
% dates to a date in terms of the Gregorian calendar in years,
% months, days, hours, minutes and seconds or in terms of the
% Gregorian calendar in years, months, days and the fraction of a
% day.
%
%INPUTS: Jul1, Jul2 Vectors or matrices of the two parts of Julian dates
% given in TT. The units of the date are days. The full
% date is the sum of both terms. The date is broken into
% two parts to provide more bits of precision. It does
% not matter how the date is split.
% giveDayFrac An optional boolean variable specifying whether the
% output should be as years months, days and a fraction
% of a day. If this parameter is omitted, the default is
% false. That means that the output will be given as
% years, months, days, hours, minutes, and seconds.
%
%OUTPUTS: Regardless of the value of giveDayFrac, the first three outputs
% are the same. They are:
% year A vector or matrix of years in the Gregorian calendar
% under UTC time, one for for each Julian date.
% month A vector or matrix of months in the Gregorian calendar
% under UTC time, one for each Julian date. 1<=month<=12
% day A vector or matrix of days in the Gregorian calendar
% under UTC time, one for each Julian date. Days count from
% 1.
% If giveDayFrac is omitted or is false, then three additional
% outputs are
% hour A vector or matrix of hours in the Gregorian calendar
% under UTC time, one for each Julian date. 0<=hour<=23.
% minute A vector or matrix of minutes in the Gregorian calendar
% under UTC time, one for each Julian date.
% 0<=minute<=59.
% second A vector or matrix of seconds in the Gregorian calendar
% under UTC time, one for each Julian date. This includes
% the possibility of a leap second on the day in question.
% On the other hand, if giveDayFrac is true, then the one
% additional output is
% dayFrac (Given as the hour output) A vector or matrix of values
% >=0 and <1 indicating the fraction of the day elapsed,
% one for each Julian date.
% and requesting more than four outputs will cause an error.
%
%This function just calls the function TT2UTC and then UTC2Cal.
%
%March 2017 David F. Crouse, Naval Research Laboratory, Washington D.C.
%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.
if(nargin<3||isempty(givenDayFrac))
givenDayFrac=false;
end
[Jul1,Jul2]=TT2UTC(Jul1,Jul2);
if(givenDayFrac==false)
[year,month,day,hour,minute,second]=UTC2Cal(Jul1,Jul2,givenDayFrac);
else
if(nargout>4)
error('Wrong number of outputs')
end
[year,month,day,hour]=UTC2Cal(Jul1,Jul2,true);
end
end
%LICENSE:
%
%The source code is in the public domain and not licensed or under
%copyright. The information and software may be used freely by the public.
%As required by 17 U.S.C. 403, third parties producing copyrighted works
%consisting predominantly of the material produced by U.S. government
%agencies must provide notice with such work(s) identifying the U.S.
%Government material incorporated and stating that such material is not
%subject to copyright protection.
%
%Derived works shall not identify themselves in a manner that implies an
%endorsement by or an affiliation with the Naval Research Laboratory.
%
%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE
%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL
%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS
%OF RECIPIENT IN THE USE OF THE SOFTWARE.
|
Require Import VST.concurrency.conclib.
Require Import VST.floyd.proofauto.
Require Import VST.floyd.library.
Require Import VST.atomics.general_locks.
Require Import bst.pair_conc.
Import FashNotation.
#[local] Instance CompSpecs : compspecs. make_compspecs prog. Defined.
Definition Vprog : varspecs. mk_varspecs prog. Defined.
Definition t_struct_pair := Tstruct _Pair noattr.
Definition t_struct_pair_impl := Tstruct _PairImpl noattr.
Definition acquire_spec := DECLARE _acquire acquire_spec.
Definition makelock_spec := DECLARE _makelock (makelock_spec _).
Definition spawn_spec := DECLARE _spawn spawn_spec.
Definition release_spec := DECLARE _release release_spec.
Definition freelock_spec := DECLARE _freelock (freelock_spec _).
Definition release2_spec := DECLARE _release2 release2_spec.
Definition freelock2_spec := DECLARE _freelock2 (freelock2_spec _).
Section HIST_GHOST.
Definition pair_impl := (Z * nat)%type.
(* Definition hist_item := (pair_impl * pair_impl)%type. *)
(* Definition hist_item_valid (it: hist_item): Prop := *)
(* it.1.2 = it.2.2 \/ S it.1.2 = it.2.2. *)
Definition pair_hist := nat -> option pair_impl.
(* Definition state_at (h: hist) (t: nat): option pair_impl := *)
(* match h t with *)
(* | None => None *)
(* | Some (p1, p2) => Some p2 *)
(* end. *)
Definition newest_state (h: pair_hist) (p: pair_impl) :=
exists t, h t = Some p /\ forall t', h t' ≠ None -> (t' <= t)%nat.
(* Lemma state_compatible: forall h1 h2, *)
(* compatible h1 h2 -> *)
(* forall t p, state_at h1 t = Some p -> state_at (map_add h1 h2) t = Some p. *)
(* Proof. *)
(* unfold state_at. intros. rewrite map_add_comm; auto. *)
(* destruct (h1 t) eqn:?H. 2: inversion H0. symmetry in H. *)
(* eapply compatible_k in H1; eauto. now rewrite H1. *)
(* Qed. *)
Definition hist_valid (h: pair_hist) := forall t1 t2 p1 p2,
h t1 = Some p1 -> h t2 = Some p2 ->
(p1.2 = p2.2 -> p1.1 = p2.1) /\ (t1 <= t2 -> (p1.2 <= p2.2)%nat).
#[global] Instance hist_Sep: @sepalg.Sep_alg pair_hist map_disj_join.
Proof.
exists (fun _ => empty_map); intros; auto.
repeat red. intros. destruct (t k); auto.
Defined.
#[global] Instance hist_Perm: @sepalg.Perm_alg pair_hist map_disj_join.
Proof.
constructor; intros.
- extensionality k. specialize (H k); specialize (H0 k).
destruct (x k), (y k); try congruence; contradiction.
- apply map_disj_join_spec in H as []; apply map_disj_join_spec in H0 as []; subst.
rewrite map_add_assoc. eexists; rewrite !map_disj_join_spec; repeat split.
+ eapply disjoint_incl; eauto. rewrite map_add_comm.
* apply map_incl_add.
* apply disjoint_compatible; auto.
+ apply disjoint_add; auto. eapply disjoint_incl; eauto. apply map_incl_add.
- rewrite map_disj_join_spec in H. rewrite map_disj_join_spec. destruct H. split.
+ now symmetry.
+ rewrite map_add_comm; auto. apply disjoint_compatible. now symmetry.
- extensionality k; specialize (H k); specialize (H0 k).
destruct (a k), (b k); auto.
+ destruct (a' k); [contradiction | auto].
+ destruct (a' k); [contradiction | auto].
+ destruct (b' k); [contradiction | auto].
Qed.
#[global, program] Instance pair_impl_ghost: Ghost :=
{ valid := hist_valid; Join_G := map_disj_join }.
Next Obligation.
- intros. specialize (H0 t1 t2 p1 p2). rewrite map_disj_join_spec in H.
destruct H. apply disjoint_compatible in H. subst x. symmetry in H.
eapply compatible_k in H1, H2; eauto. rewrite map_add_comm in H1, H2; auto.
specialize (H0 H1 H2). destruct H0. now apply H0.
- intros. specialize (H0 t1 t2 p1 p2). rewrite map_disj_join_spec in H.
destruct H. apply disjoint_compatible in H. subst x. symmetry in H.
eapply compatible_k in H1, H2; eauto. rewrite map_add_comm in H1, H2; auto.
specialize (H0 H1 H2). destruct H0. now apply H4.
Qed.
End HIST_GHOST.
Notation pair_impl_info := (@G pair_impl_ghost).
Definition pair_impl_state (p: val) (g: gname) (hist: pair_impl_info): mpred :=
EX content : Z, EX version: nat,
!! (newest_state hist (content, version)) &&
(field_at Ews t_struct_pair_impl (DOT _data) (vint content) p *
field_at Ews t_struct_pair_impl (DOT _version) (vint version) p).
Definition pair_impl_rep (p: val) (g: gname) (sh: share) lock :=
field_at sh t_struct_pair_impl (DOT _lock) lock p *
malloc_token sh tlock lock *
lock_inv sh lock (sync_inv g Tsh (pair_impl_state p)).
Definition surely_malloc_spec :=
DECLARE _surely_malloc
WITH t:type, gv: globals
PRE [ tuint ]
PROP (0 <= sizeof t <= Int.max_unsigned;
complete_legal_cosu_type t = true;
natural_aligned natural_alignment t = true)
PARAMS (Vint (Int.repr (sizeof t))) GLOBALS (gv)
SEP (mem_mgr gv)
POST [ tptr tvoid ] EX p:_,
PROP ()
RETURN (p)
SEP (mem_mgr gv; malloc_token Ews t p * data_at_ Ews t p).
Definition pair_rep (g: gname) (hist: pair_impl_info) :=
public_half g hist.
Definition pair_new_spec :=
DECLARE _pair_new
WITH gv: globals, value: Z
PRE [tint]
PROP ()
PARAMS (vint value)
GLOBALS (gv)
SEP (mem_mgr gv)
POST [tptr t_struct_pair_impl]
EX p: val, EX lock:val, EX g: gname,
PROP (valid (ghosts.singleton O (value, O)))
LOCAL (temp ret_temp p)
SEP (mem_mgr gv; pair_impl_rep p g Ews lock;
malloc_token Ews t_struct_pair_impl p;
pair_rep g (ghosts.singleton O (value, O))).
Definition pair_free_spec :=
DECLARE _pair_free
WITH gv: globals, pa_hist: pair_impl_info, p: val, lock:val, g: gname
PRE [tptr t_struct_pair_impl]
PROP ()
PARAMS (p)
GLOBALS (gv)
SEP (mem_mgr gv; pair_impl_rep p g Ews lock;
malloc_token Ews t_struct_pair_impl p;
pair_rep g pa_hist)
POST [tvoid]
PROP ()
LOCAL ()
SEP (mem_mgr gv).
Program Definition write_spec :=
DECLARE _write
ATOMIC TYPE (rmaps.ConstType _) OBJ hist INVS empty top
WITH sh, g, gv, lock, p, value
PRE [tptr t_struct_pair_impl, tint]
PROP (readable_share sh)
PARAMS (p; vint value)
GLOBALS (gv)
SEP (pair_impl_rep p g sh lock) | (pair_rep g hist)
POST [ tvoid ]
EX ph: (pair_impl * pair_hist)%type,
PROP ()
LOCAL ()
SEP (pair_impl_rep p g sh lock) | (!! (ph.1.1 = value /\
add_events hist [ph.1] ph.2) &&
pair_rep g ph.2).
Definition pair_snap_rep (ga gb: gname)
(pairsnap: (pair_impl_info * pair_impl_info)%type) :=
pair_rep ga (fst pairsnap) * pair_rep gb (snd pairsnap).
Definition pair_snap_rep_match (pairsnap: (pair_impl_info * pair_impl_info)%type)
(pp: (Z * Z)%type): Prop :=
exists p1 p2, newest_state pairsnap.1 p1 /\ newest_state pairsnap.2 p2 /\
p1.1 = pp.1 /\ p2.1 = pp.2.
Program Definition read_pair_spec :=
DECLARE _read_pair
ATOMIC TYPE (rmaps.ConstType _) OBJ pairsnap INVS empty top
WITH sh, gv, ga, gb, locka, lockb, pa, pb
PRE [tptr t_struct_pair_impl, tptr t_struct_pair_impl]
PROP (readable_share sh)
PARAMS (pa; pb)
GLOBALS (gv)
SEP (mem_mgr gv; pair_impl_rep pa ga sh locka; pair_impl_rep pb gb sh lockb) |
(pair_snap_rep ga gb pairsnap)
POST [ tptr t_struct_pair ]
EX pab: (val * (Z * Z))%type,
PROP ()
LOCAL (temp ret_temp (fst pab))
SEP (mem_mgr gv;
data_at Ews t_struct_pair
(vint (fst (snd pab)), vint (snd (snd pab))) (fst pab);
malloc_token Ews t_struct_pair (fst pab);
pair_impl_rep pa ga sh locka; pair_impl_rep pb gb sh lockb) |
(!! pair_snap_rep_match pairsnap pab.2 && pair_snap_rep ga gb pairsnap).
Definition Gprog : funspecs :=
ltac:(with_library prog [acquire_spec; release_spec; release2_spec; makelock_spec;
freelock_spec; freelock2_spec; spawn_spec;
surely_malloc_spec; pair_new_spec; pair_free_spec;
read_pair_spec; write_spec]).
Lemma body_surely_malloc: semax_body Vprog Gprog f_surely_malloc surely_malloc_spec.
Proof.
start_function.
forward_call (t, gv).
Intros p.
forward_if (p <> nullval).
- if_tac; entailer!.
- forward_call 1. contradiction.
- forward. rewrite -> if_false by auto; entailer!.
- forward. rewrite -> if_false by auto. Exists p; entailer!.
Qed.
Lemma newest_singleton: forall p t, newest_state (ghosts.singleton t p) p.
Proof.
intros. red. exists t. split.
- unfold ghosts.singleton. rewrite if_true; auto.
- intros. unfold ghosts.singleton in H. destruct (eq_dec t' t). 2: tauto.
subst. lia.
Qed.
Lemma valid_singleton: forall p (t: nat), valid (ghosts.singleton t p).
Proof.
intros. red. unfold pair_impl_ghost. repeat intro. unfold ghosts.singleton in H, H0.
destruct (eq_dec t1 t). 2: inversion H. subst t1. inversion H. subst p1.
destruct (eq_dec t2 t). 2: inversion H0. subst t2. inversion H0. subst p2.
split; intros; auto; lia.
Qed.
Lemma body_pair_new: semax_body Vprog Gprog f_pair_new pair_new_spec.
Proof.
start_function.
forward_call (t_struct_pair_impl, gv).
Intros p.
forward_call (tlock, gv). { vm_compute; split; intro; easy. }
Intros lock.
ghost_alloc (both_halves (ghosts.singleton O (value, O))). { apply @part_ref_valid. }
Intros g. rewrite <- both_halves_join. Intros.
forward_call (lock, Ews, (sync_inv g Tsh (pair_impl_state p))).
forward.
forward.
forward.
forward_call (lock, Ews, (sync_inv g Tsh (pair_impl_state p))). {
lock_props. unfold sync_inv, pair_impl_state.
Exists (ghosts.singleton O (value, O)) value O. entailer !.
1: apply newest_singleton. unfold_data_at (data_at Ews _ _ _); cancel. }
forward. pose proof (valid_singleton (value, O) O).
Exists p lock g. entailer !. unfold pair_impl_rep, pair_rep. cancel.
Qed.
Lemma body_pair_free: semax_body Vprog Gprog f_pair_free pair_free_spec.
Proof.
start_function.
unfold pair_impl_rep. Intros.
forward.
forward_call (lock, Ews, sync_inv g Tsh (pair_impl_state p)).
gather_SEP (pair_rep _ _).
viewshift_SEP 0 emp. {
go_lower. unfold pair_rep. iIntros "H". iMod (own_dealloc with "H"); auto. }
forward_call (lock, Ews, sync_inv g Tsh (pair_impl_state p)). {
lock_props. }
assert_PROP (lock <> nullval) by entailer !.
forward_call (tlock, lock, gv). {
rewrite if_false; auto. entailer !. } clear .
assert_PROP (p <> nullval) by entailer !.
unfold sync_inv. Intros a. unfold pair_impl_state. Intros content version.
gather_SEP (my_half _ _ _).
viewshift_SEP 0 emp. {
go_lower. iIntros "H". iMod (own_dealloc with "H"); auto. }
gather_SEP (field_at Ews t_struct_pair_impl (DOT _data) _ _)
(field_at Ews t_struct_pair_impl (DOT _version) _ _)
(field_at Ews t_struct_pair_impl (DOT _lock) _ _).
replace_SEP 0 (data_at Ews t_struct_pair_impl
(lock, (vint content, vint version)) p). {
entailer !. unfold_data_at (data_at Ews _ _ _). cancel. }
forward_call (t_struct_pair_impl, p, gv). {
rewrite if_false; auto. sep_apply (data_at_data_at_). cancel. }
entailer !.
Qed.
Lemma body_write: semax_body Vprog Gprog f_write write_spec.
Proof.
start_function.
unfold pair_impl_rep. Intros.
forward.
forward_call (lock, sh, sync_inv g Tsh (pair_impl_state p)).
unfold sync_inv at 2. Intros h. unfold pair_impl_state at 2.
Intros content version.
forward.
forward.
forward.
rewrite add_repr.
gather_SEP (atomic_shift _ _ _ _ _) (my_half _ _ _).
viewshift_SEP 0 (EX ph, Q ph * (!! (ph.1 = (value, S version) /\
newest_state ph.2 (value, S version)) &&
my_half g Tsh ph.2)). {
go_lower.
rewrite <- (sepcon_emp
(atomic_shift (λ hist : pair_impl_info, pair_rep g hist) ∅ ⊤
(λ (hist : pair_impl_info) (ph : Z * nat * (nat → option pair_impl)),
!! (ph.1.1 = value ∧ add_events hist [ph.1] ph.2) && pair_rep g ph.2 * emp)
Q * my_half g Tsh h)).
apply sync_commit_gen. intros h1.
eapply derives_trans; [|apply ghost_seplog.bupd_intro].
unfold pair_rep. Exists h1. cancel. rewrite if_true; auto.
apply imp_andp_adjoint. Intros. subst h1.
eapply derives_trans; [|apply ghost_seplog.bupd_intro].
Exists h h. entailer !. rewrite <- wand_sepcon_adjoint.
destruct H as [newt [? ?]].
remember (map_upd h (S newt) (value, S version)) as h'.
assert (add_events h [(value, S version)] h'). {
subst h'. apply add_events_1. red. intros. apply H0 in H1. lia. }
assert (newest_state h' (value, S version)). {
subst h'. exists (S newt). split.
- unfold map_upd. rewrite if_true; auto.
- intros. unfold map_upd in H2. destruct (eq_dec t' (S newt)).
1: subst; lia. apply H0 in H2. lia. }
sep_apply (public_update g h h h'). Intros. apply ghost_seplog.bupd_mono.
Exists ((value, S version), h'). simpl. entailer!. }
Intros ph. destruct ph as [pS h'].
forward_call (lock, sh, sync_inv g Tsh (pair_impl_state p)). {
lock_props. unfold sync_inv. Exists h'. simpl in H0, H1.
unfold pair_impl_state. Exists value (S version).
replace (vint (version + 1)) with (vint (S version)). 2: do 2 f_equal; lia.
subst pS. simpl. entailer !. }
unfold pair_impl_rep. Exists (pS, h'). entailer !.
Qed.
Lemma body_read_pair: semax_body Vprog Gprog f_read_pair read_pair_spec.
Proof.
start_function.
forward_call(t_struct_pair, gv).
Intros result. unfold fold_right_sepcon.
forward_loop (PROP ( )
LOCAL (temp _result result; gvars gv; temp _a pa; temp _b pb)
SEP (mem_mgr gv; malloc_token Ews t_struct_pair result;
data_at_ Ews t_struct_pair result;
atomic_shift
(λ pairsnap : pair_impl_info * pair_impl_info, pair_snap_rep ga gb pairsnap) ∅
⊤
(λ (pairsnap : pair_impl_info * pair_impl_info) (pab : val * (Z * Z)),
!! pair_snap_rep_match pairsnap pab.2 && pair_snap_rep ga gb pairsnap * emp)
Q; pair_impl_rep pa ga sh locka; pair_impl_rep pb gb sh lockb)). 1: auto.
unfold pair_impl_rep at 1. Intros.
forward.
forward_call (locka, sh, sync_inv ga Tsh (pair_impl_state pa)).
unfold sync_inv at 2. Intros ha. unfold pair_impl_state at 2. Intros da va.
forward.
forward.
gather_SEP (atomic_shift _ _ _ _ _) (my_half _ _ _).
viewshift_SEP 0 (atomic_shift (λ pairsnap : pair_impl_info * pair_impl_info, pair_snap_rep ga gb pairsnap) ∅ ⊤
(λ (pairsnap : pair_impl_info * pair_impl_info) (pab : val * (Z * Z)),
!! pair_snap_rep_match pairsnap pab.2 && pair_snap_rep ga gb pairsnap * emp) Q * my_half ga Tsh ha * (!!(exists t, ha t = Some (da, va)) && emp)). {
go_lower.
rewrite <-
(sepcon_emp
(atomic_shift
(λ pairsnap : pair_impl_info * pair_impl_info, pair_snap_rep ga gb pairsnap) ∅ ⊤
(λ (pairsnap : pair_impl_info * pair_impl_info) (pab : val * (Z * Z)),
!! pair_snap_rep_match pairsnap pab.2 && pair_snap_rep ga gb pairsnap * emp) Q *
my_half ga Tsh ha)) at 1.
eapply derives_trans; [|apply ghost_seplog.bupd_intro].
apply sync_rollback. intros. destruct x as [pair1 pair2].
eapply derives_trans; [|apply ghost_seplog.bupd_intro]. Exists pair1.
rewrite if_true; auto. unfold pair_snap_rep. simpl fst. simpl snd.
unfold pair_rep at 1. cancel. apply imp_andp_adjoint. Intros. subst pair1.
rewrite <- wand_sepcon_adjoint.
eapply derives_trans; [|apply ghost_seplog.bupd_intro]. unfold pair_rep at 2.
entailer !. destruct H as [t [? ?]]. now exists t. } Intros.
forward_call (locka, sh, sync_inv ga Tsh (pair_impl_state pa)). {
lock_props. unfold sync_inv. Exists ha. unfold pair_impl_state.
Exists da va. entailer !. }
Abort.
|
.*: file format elf32-.*arm
DYNAMIC RELOCATION RECORDS
OFFSET TYPE VALUE
[0-9a-f]+ R_ARM_TLS_DESC lib_gd2
|
[STATEMENT]
lemma dom_m_fmrestrict_set': \<open>dom_m (fmrestrict_set xs N) = mset_set (xs \<inter> set_mset (dom_m N))\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. dom_m (fmrestrict_set xs N) = mset_set (xs \<inter> set_mset (dom_m N))
[PROOF STEP]
using fset_fmdom_fmrestrict_set[of \<open>xs\<close> N] distinct_mset_dom[of N]
[PROOF STATE]
proof (prove)
using this:
fset (fmdom (fmrestrict_set xs N)) = fset (fmdom N) \<inter> xs
distinct_mset (dom_m N)
goal (1 subgoal):
1. dom_m (fmrestrict_set xs N) = mset_set (xs \<inter> set_mset (dom_m N))
[PROOF STEP]
by (auto simp: dom_m_def fset_mset_mset_fset finite_mset_set_inter multiset_inter_commute
remdups_mset_def) |
open import Function using (id) renaming (_∘′_ to _∘_)
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Control.Monad
module Control.Monad.Error (E : Set) where
-- The Error monad.
data Error (A : Set) : Set where
fail : (e : E) → Error A
return : (a : A) → Error A
-- The following are axiliary definitions for the constructor of errorIsMonad.
module Local where
-- Bind.
_>>=_ : ∀ {A B} (m : Error A) (k : A → Error B) → Error B
fail e >>= k = fail e
return a >>= k = k a
bind = _>>=_
-- Laws of bind.
beta : ∀ {A B} (k : A → Error B) (a : A) →
return a >>= k ≡ k a
beta k a = refl
eta : ∀ {A} (m : Error A) →
m >>= return ≡ m
eta (fail e) = refl
eta (return a) = refl
assoc : ∀ {A B C} (m : Error A) {k : A → Error B} {l : B → Error C} →
(m >>= k) >>= l ≡ m >>= λ a → (k a >>= l)
assoc (fail e) = refl
assoc (return a) = refl
open Local public
-- The monad instance of Error.
errorIsMonad : IsMonad Error
errorIsMonad = record
{ ops = record
{ return = return
; _>>=_ = bind
}
; laws = record
{ bind-β = beta
; bind-η = eta
; bind-assoc = assoc
}
}
|
theory array_remove
imports
"../../../isabelle/VCG/HTriple"
begin
locale "qemu_img_xen" = execution_context + exec_code +
fixes qemu_malloc_0xbb39_retval\<^sub>v memcpy_0xbb4c_retval\<^sub>v memmove_0xbb6e_retval\<^sub>v memcpy_0xbb7c_retval\<^sub>v free_0xbb84_retval\<^sub>v memmove_0xbbb6_retval\<^sub>v assert_fail_0xbbe1_retval\<^sub>v assert_fail_0xbc00_retval\<^sub>v assert_fail_addr free_addr memcpy_addr memmove_addr qemu_malloc_addr :: \<open>64 word\<close>
and assert_fail_acode free_acode memcpy_acode memmove_acode qemu_malloc_acode :: ACode
assumes fetch:
"fetch 0xbac0 \<equiv> (Unary (IS_8088 Push) (Storage (Reg (General SixtyFour r15))), 2)"
"fetch 0xbac2 \<equiv> (Unary (IS_8088 Push) (Storage (Reg (General SixtyFour r14))), 2)"
"fetch 0xbac4 \<equiv> (Unary (IS_8088 Push) (Storage (Reg (General SixtyFour r13))), 2)"
"fetch 0xbac6 \<equiv> (Unary (IS_8088 Push) (Storage (Reg (General SixtyFour r12))), 2)"
"fetch 0xbac8 \<equiv> (Unary (IS_8088 Push) (Storage (Reg (General SixtyFour rbp))), 1)"
"fetch 0xbac9 \<equiv> (Unary (IS_8088 Push) (Storage (Reg (General SixtyFour rbx))), 1)"
"fetch 0xbaca \<equiv> (Binary (IS_8088 Sub) (Reg (General SixtyFour rsp)) (Immediate SixtyFour (ImmVal 40)), 4)"
"fetch 0xbace \<equiv> (Binary (IS_8088 Test) (Reg (General ThirtyTwo rsi)) (Storage (Reg (General ThirtyTwo rsi))), 2)"
"fetch 0xbad0 \<equiv> (Unary (IS_8088 Js) (Immediate SixtyFour (ImmVal 48102)), 6)"
"fetch 0xbad6 \<equiv> (Binary (IS_8088 Mov) (Reg (General ThirtyTwo rax)) (Storage (Memory ThirtyTwo (A_SizeDirective 32 (A_Plus (A_FromReg (General SixtyFour rdi)) (A_WordConstant 12))))), 3)"
"fetch 0xbad9 \<equiv> (Binary (IS_8088 Lea) (Reg (General ThirtyTwo rdx)) (Storage (Memory SixtyFour (A_Plus (A_FromReg (General SixtyFour rsi)) (A_WordConstant 1)))), 3)"
"fetch 0xbadc \<equiv> (Binary (IS_8088 Mov) (Reg (General SixtyFour r15)) (Storage (Reg (General SixtyFour rdi))), 3)"
"fetch 0xbadf \<equiv> (Binary (IS_8088 Mov) (Reg (General ThirtyTwo rbx)) (Storage (Reg (General ThirtyTwo rsi))), 2)"
"fetch 0xbae1 \<equiv> (Binary (IS_8088 Cmp) (Reg (General ThirtyTwo rdx)) (Storage (Reg (General ThirtyTwo rax))), 2)"
"fetch 0xbae3 \<equiv> (Unary (IS_8088 Ja) (Immediate SixtyFour (ImmVal 48071)), 6)"
"fetch 0xbae9 \<equiv> (Binary (IS_8088 Mov) (Reg (General ThirtyTwo rbp)) (Storage (Reg (General ThirtyTwo rax))), 2)"
"fetch 0xbaeb \<equiv> (Binary (IS_8088 Sub) (Reg (General ThirtyTwo rbp)) (Immediate SixtyFour (ImmVal 1)), 3)"
"fetch 0xbaee \<equiv> (Unary (IS_8088 Js) (Immediate SixtyFour (ImmVal 48064)), 6)"
"fetch 0xbaf4 \<equiv> (Binary (IS_8088 Cmp) (Reg (General ThirtyTwo rax)) (Storage (Reg (General ThirtyTwo rsi))), 2)"
"fetch 0xbaf6 \<equiv> (Unary (IS_8088 Jbe) (Immediate SixtyFour (ImmVal 48064)), 6)"
"fetch 0xbafc \<equiv> (Binary (IS_8088 Cmp) (Reg (General ThirtyTwo rsi)) (Storage (Reg (General ThirtyTwo rbp))), 2)"
"fetch 0xbafe \<equiv> (Unary (IS_8088 Je) (Immediate SixtyFour (ImmVal 48016)), 6)"
"fetch 0xbb04 \<equiv> (Binary (IS_X86_64 Movsxd) (Reg (General SixtyFour r12)) (Storage (Memory ThirtyTwo (A_SizeDirective 32 (A_Plus (A_FromReg (General SixtyFour rdi)) (A_WordConstant 16))))), 4)"
"fetch 0xbb08 \<equiv> (Binary (IS_8088 Mov) (Reg (General ThirtyTwo r9)) (Storage (Reg (General ThirtyTwo rsi))), 3)"
"fetch 0xbb0b \<equiv> (Binary (IS_8088 Mov) (Reg (General ThirtyTwo r8)) (Storage (Reg (General ThirtyTwo rbp))), 3)"
"fetch 0xbb0e \<equiv> (Binary (IS_8088 Mov) (Reg (General SixtyFour r13)) (Storage (Memory SixtyFour (A_SizeDirective 64 (A_FromReg (General SixtyFour rdi))))), 3)"
"fetch 0xbb11 \<equiv> (Binary (IS_8088 Imul) (Reg (General ThirtyTwo r9)) (Storage (Reg (General ThirtyTwo r12))), 4)"
"fetch 0xbb15 \<equiv> (Binary (IS_8088 Mov) (Reg (General SixtyFour rdi)) (Storage (Reg (General SixtyFour r12))), 3)"
"fetch 0xbb18 \<equiv> (Binary (IS_8088 Imul) (Reg (General ThirtyTwo r8)) (Storage (Reg (General ThirtyTwo r12))), 4)"
"fetch 0xbb1c \<equiv> (Binary (IS_X86_64 Movsxd) (Reg (General SixtyFour r9)) (Storage (Reg (General ThirtyTwo r9))), 3)"
"fetch 0xbb1f \<equiv> (Binary (IS_8088 Lea) (Reg (General SixtyFour rax)) (Storage (Memory SixtyFour (A_Plus (A_FromReg (General SixtyFour r13)) (A_Plus (A_Mult 1 (A_FromReg (General SixtyFour r9))) (A_WordConstant 0))))), 5)"
"fetch 0xbb24 \<equiv> (Binary (IS_X86_64 Movsxd) (Reg (General SixtyFour r8)) (Storage (Reg (General ThirtyTwo r8))), 3)"
"fetch 0xbb27 \<equiv> (Binary (IS_8088 Mov) (Memory SixtyFour (A_SizeDirective 64 (A_Plus (A_FromReg (General SixtyFour rsp)) (A_WordConstant 24)))) (Storage (Reg (General SixtyFour r9))), 5)"
"fetch 0xbb2c \<equiv> (Binary (IS_8088 Add) (Reg (General SixtyFour r13)) (Storage (Reg (General SixtyFour r8))), 3)"
"fetch 0xbb2f \<equiv> (Binary (IS_8088 Mov) (Memory SixtyFour (A_SizeDirective 64 (A_Plus (A_FromReg (General SixtyFour rsp)) (A_WordConstant 16)))) (Storage (Reg (General SixtyFour r8))), 5)"
"fetch 0xbb34 \<equiv> (Binary (IS_8088 Mov) (Memory SixtyFour (A_SizeDirective 64 (A_Plus (A_FromReg (General SixtyFour rsp)) (A_WordConstant 8)))) (Storage (Reg (General SixtyFour rax))), 5)"
"fetch 0xbb39 \<equiv> (Unary (IS_8088 Call) (Immediate SixtyFour (ImmLabel ''qemu_malloc'')), 5)"
"fetch 0xbb3e \<equiv> (Binary (IS_8088 Mov) (Reg (General SixtyFour rsi)) (Storage (Memory SixtyFour (A_SizeDirective 64 (A_Plus (A_FromReg (General SixtyFour rsp)) (A_WordConstant 8))))), 5)"
"fetch 0xbb43 \<equiv> (Binary (IS_8088 Mov) (Reg (General SixtyFour rdx)) (Storage (Reg (General SixtyFour r12))), 3)"
"fetch 0xbb46 \<equiv> (Binary (IS_8088 Mov) (Reg (General SixtyFour rdi)) (Storage (Reg (General SixtyFour rax))), 3)"
"fetch 0xbb49 \<equiv> (Binary (IS_8088 Mov) (Reg (General SixtyFour r14)) (Storage (Reg (General SixtyFour rax))), 3)"
"fetch 0xbb4c \<equiv> (Unary (IS_8088 Call) (Immediate SixtyFour (ImmLabel ''memcpy'')), 5)"
"fetch 0xbb51 \<equiv> (Binary (IS_8088 Cmp) (Reg (General ThirtyTwo rbx)) (Storage (Reg (General ThirtyTwo rbp))), 2)"
"fetch 0xbb53 \<equiv> (Binary (IS_8088 Mov) (Reg (General SixtyFour r8)) (Storage (Memory SixtyFour (A_SizeDirective 64 (A_Plus (A_FromReg (General SixtyFour rsp)) (A_WordConstant 16))))), 5)"
"fetch 0xbb58 \<equiv> (Binary (IS_8088 Mov) (Reg (General SixtyFour r9)) (Storage (Memory SixtyFour (A_SizeDirective 64 (A_Plus (A_FromReg (General SixtyFour rsp)) (A_WordConstant 24))))), 5)"
"fetch 0xbb5d \<equiv> (Unary (IS_8088 Jg) (Immediate SixtyFour (ImmVal 48040)), 2)"
"fetch 0xbb5f \<equiv> (Binary (IS_8088 Mov) (Reg (General SixtyFour rdi)) (Storage (Memory SixtyFour (A_SizeDirective 64 (A_Plus (A_FromReg (General SixtyFour rsp)) (A_WordConstant 8))))), 5)"
"fetch 0xbb64 \<equiv> (Binary (IS_8088 Mov) (Reg (General SixtyFour rdx)) (Storage (Reg (General SixtyFour r8))), 3)"
"fetch 0xbb67 \<equiv> (Binary (IS_8088 Sub) (Reg (General SixtyFour rdx)) (Storage (Reg (General SixtyFour r9))), 3)"
"fetch 0xbb6a \<equiv> (Binary (IS_8088 Lea) (Reg (General SixtyFour rsi)) (Storage (Memory SixtyFour (A_Plus (A_FromReg (General SixtyFour rdi)) (A_Mult 1 (A_FromReg (General SixtyFour r12)))))), 4)"
"fetch 0xbb6e \<equiv> (Unary (IS_8088 Call) (Immediate SixtyFour (ImmLabel ''memmove'')), 5)"
"fetch 0xbb73 \<equiv> (Binary (IS_8088 Mov) (Reg (General SixtyFour rdx)) (Storage (Reg (General SixtyFour r12))), 3)"
"fetch 0xbb76 \<equiv> (Binary (IS_8088 Mov) (Reg (General SixtyFour rsi)) (Storage (Reg (General SixtyFour r14))), 3)"
"fetch 0xbb79 \<equiv> (Binary (IS_8088 Mov) (Reg (General SixtyFour rdi)) (Storage (Reg (General SixtyFour r13))), 3)"
"fetch 0xbb7c \<equiv> (Unary (IS_8088 Call) (Immediate SixtyFour (ImmLabel ''memcpy'')), 5)"
"fetch 0xbb81 \<equiv> (Binary (IS_8088 Mov) (Reg (General SixtyFour rdi)) (Storage (Reg (General SixtyFour r14))), 3)"
"fetch 0xbb84 \<equiv> (Unary (IS_8088 Call) (Immediate SixtyFour (ImmLabel ''free'')), 5)"
"fetch 0xbb89 \<equiv> (Binary (IS_8088 Mov) (Reg (General ThirtyTwo rax)) (Storage (Memory ThirtyTwo (A_SizeDirective 32 (A_Plus (A_FromReg (General SixtyFour r15)) (A_WordConstant 12))))), 4)"
"fetch 0xbb8d \<equiv> (Binary (IS_8088 Lea) (Reg (General ThirtyTwo rbp)) (Storage (Memory SixtyFour (A_Minus (A_FromReg (General SixtyFour rax)) (A_WordConstant 1)))), 3)"
"fetch 0xbb90 \<equiv> (Binary (IS_8088 Mov) (Memory ThirtyTwo (A_SizeDirective 32 (A_Plus (A_FromReg (General SixtyFour r15)) (A_WordConstant 12)))) (Storage (Reg (General ThirtyTwo rbp))), 4)"
"fetch 0xbb94 \<equiv> (Binary (IS_8088 Xor) (Reg (General ThirtyTwo rax)) (Storage (Reg (General ThirtyTwo rax))), 2)"
"fetch 0xbb96 \<equiv> (Binary (IS_8088 Add) (Reg (General SixtyFour rsp)) (Immediate SixtyFour (ImmVal 40)), 4)"
"fetch 0xbb9a \<equiv> (Unary (IS_8088 Pop) (Storage (Reg (General SixtyFour rbx))), 1)"
"fetch 0xbb9b \<equiv> (Unary (IS_8088 Pop) (Storage (Reg (General SixtyFour rbp))), 1)"
"fetch 0xbb9c \<equiv> (Unary (IS_8088 Pop) (Storage (Reg (General SixtyFour r12))), 2)"
"fetch 0xbb9e \<equiv> (Unary (IS_8088 Pop) (Storage (Reg (General SixtyFour r13))), 2)"
"fetch 0xbba0 \<equiv> (Unary (IS_8088 Pop) (Storage (Reg (General SixtyFour r14))), 2)"
"fetch 0xbba2 \<equiv> (Unary (IS_8088 Pop) (Storage (Reg (General SixtyFour r15))), 2)"
"fetch 0xbba4 \<equiv> (Nullary (IS_8088 Ret), 1)"
"fetch 0xbba5 \<equiv> (Unary (IS_8088 Nop) (Storage (Memory ThirtyTwo (A_SizeDirective 32 (A_FromReg (General SixtyFour rax))))), 3)"
"fetch 0xbba8 \<equiv> (Binary (IS_8088 Mov) (Reg (General SixtyFour rdx)) (Storage (Reg (General SixtyFour r9))), 3)"
"fetch 0xbbab \<equiv> (Binary (IS_8088 Lea) (Reg (General SixtyFour rdi)) (Storage (Memory SixtyFour (A_Plus (A_FromReg (General SixtyFour r13)) (A_Plus (A_Mult 1 (A_FromReg (General SixtyFour r12))) (A_WordConstant 0))))), 5)"
"fetch 0xbbb0 \<equiv> (Binary (IS_8088 Mov) (Reg (General SixtyFour rsi)) (Storage (Reg (General SixtyFour r13))), 3)"
"fetch 0xbbb3 \<equiv> (Binary (IS_8088 Sub) (Reg (General SixtyFour rdx)) (Storage (Reg (General SixtyFour r8))), 3)"
"fetch 0xbbb6 \<equiv> (Unary (IS_8088 Call) (Immediate SixtyFour (ImmLabel ''memmove'')), 5)"
"fetch 0xbbbb \<equiv> (Unary (IS_8088 Jmp) (Immediate SixtyFour (ImmVal 47987)), 2)"
"fetch 0xbbbd \<equiv> (Unary (IS_8088 Nop) (Storage (Memory ThirtyTwo (A_SizeDirective 32 (A_FromReg (General SixtyFour rax))))), 3)"
"fetch 0xbbc0 \<equiv> (Binary (IS_8088 Mov) (Reg (General ThirtyTwo rax)) (Immediate SixtyFour (ImmVal 4294967295)), 5)"
"fetch 0xbbc5 \<equiv> (Unary (IS_8088 Jmp) (Immediate SixtyFour (ImmVal 48022)), 2)"
"fetch 0xbbc7 \<equiv> (Binary (IS_8088 Lea) (Reg (General SixtyFour rcx)) (Storage (Memory SixtyFour (A_Plus (A_FromReg (General SixtyFour rip)) (A_WordConstant 88034)))), 7)"
"fetch 0xbbce \<equiv> (Binary (IS_8088 Mov) (Reg (General ThirtyTwo rdx)) (Immediate SixtyFour (ImmVal 181)), 5)"
"fetch 0xbbd3 \<equiv> (Binary (IS_8088 Lea) (Reg (General SixtyFour rsi)) (Storage (Memory SixtyFour (A_Plus (A_FromReg (General SixtyFour rip)) (A_WordConstant 85772)))), 7)"
"fetch 0xbbda \<equiv> (Binary (IS_8088 Lea) (Reg (General SixtyFour rdi)) (Storage (Memory SixtyFour (A_Plus (A_FromReg (General SixtyFour rip)) (A_WordConstant 85789)))), 7)"
"fetch 0xbbe1 \<equiv> (Unary (IS_8088 Call) (Immediate SixtyFour (ImmLabel ''__assert_fail'')), 5)"
"fetch 0xbbe6 \<equiv> (Binary (IS_8088 Lea) (Reg (General SixtyFour rcx)) (Storage (Memory SixtyFour (A_Plus (A_FromReg (General SixtyFour rip)) (A_WordConstant 88003)))), 7)"
"fetch 0xbbed \<equiv> (Binary (IS_8088 Mov) (Reg (General ThirtyTwo rdx)) (Immediate SixtyFour (ImmVal 179)), 5)"
"fetch 0xbbf2 \<equiv> (Binary (IS_8088 Lea) (Reg (General SixtyFour rsi)) (Storage (Memory SixtyFour (A_Plus (A_FromReg (General SixtyFour rip)) (A_WordConstant 85741)))), 7)"
"fetch 0xbbf9 \<equiv> (Binary (IS_8088 Lea) (Reg (General SixtyFour rdi)) (Storage (Memory SixtyFour (A_Plus (A_FromReg (General SixtyFour rip)) (A_WordConstant 85748)))), 7)"
"fetch 0xbc00 \<equiv> (Unary (IS_8088 Call) (Immediate SixtyFour (ImmLabel ''__assert_fail'')), 5)"
and \<alpha>_def: \<open>\<alpha> = \<lparr>text_sections = [], data_sections = [], labels_to_offsets = [], binary_offset = 0\<rparr>\<close>
and assert_fail\<^sub>a\<^sub>d\<^sub>d\<^sub>r[simp]: \<open>the (label_to_address \<alpha> ''__assert_fail'') = assert_fail_addr\<close>
and free\<^sub>a\<^sub>d\<^sub>d\<^sub>r[simp]: \<open>the (label_to_address \<alpha> ''free'') = free_addr\<close>
and memcpy\<^sub>a\<^sub>d\<^sub>d\<^sub>r[simp]: \<open>the (label_to_address \<alpha> ''memcpy'') = memcpy_addr\<close>
and memmove\<^sub>a\<^sub>d\<^sub>d\<^sub>r[simp]: \<open>the (label_to_address \<alpha> ''memmove'') = memmove_addr\<close>
and qemu_malloc\<^sub>a\<^sub>d\<^sub>d\<^sub>r[simp]: \<open>the (label_to_address \<alpha> ''qemu_malloc'') = qemu_malloc_addr\<close>
begin
text \<open>Using definitions that don't get unfolded immediately prevents locale argument issues.\<close>
definition \<open>qemu_malloc_0xbb39_retval \<equiv> qemu_malloc_0xbb39_retval\<^sub>v\<close>
definition \<open>memcpy_0xbb4c_retval \<equiv> memcpy_0xbb4c_retval\<^sub>v\<close>
definition \<open>memmove_0xbb6e_retval \<equiv> memmove_0xbb6e_retval\<^sub>v\<close>
definition \<open>memcpy_0xbb7c_retval \<equiv> memcpy_0xbb7c_retval\<^sub>v\<close>
definition \<open>free_0xbb84_retval \<equiv> free_0xbb84_retval\<^sub>v\<close>
definition \<open>memmove_0xbbb6_retval \<equiv> memmove_0xbbb6_retval\<^sub>v\<close>
definition \<open>assert_fail_0xbbe1_retval \<equiv> assert_fail_0xbbe1_retval\<^sub>v\<close>
definition \<open>assert_fail_0xbc00_retval \<equiv> assert_fail_0xbc00_retval\<^sub>v\<close>
text \<open>
Going with a binary offset of 0 for now to make things easier. (We do want to keep that field
around, though, for future more generic usage.)
\<close>
lemma \<alpha>_boffset[simp]: \<open>binary_offset \<alpha> = 0\<close>
unfolding \<alpha>_def
by simp
named_theorems blocks and Ps and Qs
method step uses add del =
subst exec_block.simps,
rewrite_one_let',
rewrite_one_let' add: fetch,
rewrite_one_let',
auto simp add: simp_rules Let'_def read_region'_def write_block'_def get'_def set'_def step_def exec_instr_def presimplify add simp del: del
method steps uses pre post regionset add del =
auto simp: pred_logic pre regionset,
(step add: add del: del)+,
(auto simp add: eq_def)[1],
auto simp: block_usage_def eq_def setcc_def cmovcc_def if'_then_else_def sub_sign_flag_def simp_rules Let'_def read_region'_def write_block'_def get'_def set'_def post regionset
method vcg_step uses assms =
((rule htriples)+, rule blocks)+,
(simp add: assms pred_logic Ps Qs)?,
(((auto simp: eq_def)[])+)?
method vcg_while for P :: state_pred uses assms =
((rule htriples)+)?,
rule HTriple_weaken[where P=P],
simp add: pred_logic Ps Qs assms,
rule HTriple_while
method vcg uses acode assms =
subst acode,
(vcg_step assms: assms)+
end
locale "array_remove" = "qemu_img_xen" +
fixes RAX\<^sub>0\<^sub>v RBX\<^sub>0\<^sub>v RCX\<^sub>0\<^sub>v RDX\<^sub>0\<^sub>v RDI\<^sub>0\<^sub>v RSI\<^sub>0\<^sub>v RSP\<^sub>0\<^sub>v RBP\<^sub>0\<^sub>v R15\<^sub>0\<^sub>v R14\<^sub>0\<^sub>v R13\<^sub>0\<^sub>v R12\<^sub>0\<^sub>v R9\<^sub>0\<^sub>v R8\<^sub>0\<^sub>v ret_address\<^sub>v :: \<open>64 word\<close>
begin
text \<open>Using definitions that don't get unfolded immediately prevents locale argument issues.\<close>
definition \<open>RAX\<^sub>0 \<equiv> RAX\<^sub>0\<^sub>v\<close>
definition \<open>RBX\<^sub>0 \<equiv> RBX\<^sub>0\<^sub>v\<close>
definition \<open>RCX\<^sub>0 \<equiv> RCX\<^sub>0\<^sub>v\<close>
definition \<open>RDX\<^sub>0 \<equiv> RDX\<^sub>0\<^sub>v\<close>
definition \<open>RDI\<^sub>0 \<equiv> RDI\<^sub>0\<^sub>v\<close>
definition \<open>RSI\<^sub>0 \<equiv> RSI\<^sub>0\<^sub>v\<close>
definition \<open>RSP\<^sub>0 \<equiv> RSP\<^sub>0\<^sub>v\<close>
definition \<open>RBP\<^sub>0 \<equiv> RBP\<^sub>0\<^sub>v\<close>
definition \<open>R15\<^sub>0 \<equiv> R15\<^sub>0\<^sub>v\<close>
definition \<open>R14\<^sub>0 \<equiv> R14\<^sub>0\<^sub>v\<close>
definition \<open>R13\<^sub>0 \<equiv> R13\<^sub>0\<^sub>v\<close>
definition \<open>R12\<^sub>0 \<equiv> R12\<^sub>0\<^sub>v\<close>
definition \<open>R9\<^sub>0 \<equiv> R9\<^sub>0\<^sub>v\<close>
definition \<open>R8\<^sub>0 \<equiv> R8\<^sub>0\<^sub>v\<close>
definition \<open>ret_address \<equiv> ret_address\<^sub>v\<close>
definition P_0xbac0_0 :: state_pred where
\<open>P_0xbac0_0 \<sigma> \<equiv> RIP \<sigma> = 0xbac0 \<and> RAX \<sigma> = RAX\<^sub>0 \<and> RBX \<sigma> = RBX\<^sub>0 \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = RDX\<^sub>0 \<and> RDI \<sigma> = RDI\<^sub>0 \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = RSP\<^sub>0 \<and> RBP \<sigma> = RBP\<^sub>0 \<and> R15 \<sigma> = R15\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address\<close>
declare P_0xbac0_0_def[Ps]
definition P_0xbac0_0_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbac0_0_regions_set \<sigma> \<equiv> {
(0, RSP\<^sub>0, 8),
(1, ((RSP\<^sub>0::64 word) - 0x8), 8),
(2, ((RSP\<^sub>0::64 word) - 0x10), 8),
(3, ((RSP\<^sub>0::64 word) - 0x18), 8),
(4, ((RSP\<^sub>0::64 word) - 0x20), 8),
(5, ((RSP\<^sub>0::64 word) - 0x28), 8),
(6, ((RSP\<^sub>0::64 word) - 0x30), 8)
}\<close>
definition P_0xbac0_0_regions :: state_pred where
\<open>P_0xbac0_0_regions \<sigma> \<equiv> \<exists>regions. P_0xbac0_0_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbad0_0 :: state_pred where
\<open>Q_0xbad0_0 \<sigma> \<equiv> RIP \<sigma> = 0xbad0 \<and> RAX \<sigma> = RAX\<^sub>0 \<and> RBX \<sigma> = RBX\<^sub>0 \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = RDX\<^sub>0 \<and> RDI \<sigma> = RDI\<^sub>0 \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = RBP\<^sub>0 \<and> R15 \<sigma> = R15\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare Q_0xbad0_0_def[Qs]
schematic_goal array_remove_0_8_0xbac0_0xbace_0[blocks]:
assumes \<open>(P_0xbac0_0 && P_0xbac0_0_regions) \<sigma>\<close>
shows \<open>exec_block 8 0xbace 0 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbad0_0 ?\<sigma> \<and> block_usage P_0xbac0_0_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbac0_0_def P_0xbac0_0_regions_def post: Q_0xbad0_0_def regionset: P_0xbac0_0_regions_set_def)
definition P_0xbad0_true_1 :: state_pred where
\<open>P_0xbad0_true_1 \<sigma> \<equiv> RIP \<sigma> = 0xbad0 \<and> RAX \<sigma> = RAX\<^sub>0 \<and> RBX \<sigma> = RBX\<^sub>0 \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = RDX\<^sub>0 \<and> RDI \<sigma> = RDI\<^sub>0 \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = RBP\<^sub>0 \<and> R15 \<sigma> = R15\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare P_0xbad0_true_1_def[Ps]
definition P_0xbad0_true_1_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbad0_true_1_regions_set \<sigma> \<equiv> {
(0, RSP\<^sub>0, 8),
(1, ((RSP\<^sub>0::64 word) - 0x8), 8),
(2, ((RSP\<^sub>0::64 word) - 0x10), 8),
(3, ((RSP\<^sub>0::64 word) - 0x18), 8),
(4, ((RSP\<^sub>0::64 word) - 0x20), 8),
(5, ((RSP\<^sub>0::64 word) - 0x28), 8),
(6, ((RSP\<^sub>0::64 word) - 0x30), 8)
}\<close>
definition P_0xbad0_true_1_regions :: state_pred where
\<open>P_0xbad0_true_1_regions \<sigma> \<equiv> \<exists>regions. P_0xbad0_true_1_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbc00_1 :: state_pred where
\<open>Q_0xbc00_1 \<sigma> \<equiv> RIP \<sigma> = 0xbc00 \<and> RAX \<sigma> = RAX\<^sub>0 \<and> RBX \<sigma> = RBX\<^sub>0 \<and> RCX \<sigma> = 0x213b0 \<and> RDX \<sigma> = 0xb3 \<and> RDI \<sigma> = 0x20af4 \<and> RSI \<sigma> = 0x20ae6 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = RBP\<^sub>0 \<and> R15 \<sigma> = R15\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare Q_0xbc00_1_def[Qs]
schematic_goal array_remove_0_5_0xbad0_0xbbf9_1[blocks]:
assumes \<open>(P_0xbad0_true_1 && P_0xbad0_true_1_regions && SF) \<sigma>\<close>
shows \<open>exec_block 5 0xbbf9 (Suc 0) \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbc00_1 ?\<sigma> \<and> block_usage P_0xbad0_true_1_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbad0_true_1_def P_0xbad0_true_1_regions_def post: Q_0xbc00_1_def regionset: P_0xbad0_true_1_regions_set_def)
definition P_0xbc00_2 :: state_pred where
\<open>P_0xbc00_2 \<sigma> \<equiv> RIP \<sigma> = 0xbc00 \<and> RAX \<sigma> = RAX\<^sub>0 \<and> RBX \<sigma> = RBX\<^sub>0 \<and> RCX \<sigma> = 0x213b0 \<and> RDX \<sigma> = 0xb3 \<and> RDI \<sigma> = 0x20af4 \<and> RSI \<sigma> = 0x20ae6 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = RBP\<^sub>0 \<and> R15 \<sigma> = R15\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare P_0xbc00_2_def[Ps]
definition P_0xbc00_2_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbc00_2_regions_set \<sigma> \<equiv> {
(0, RSP\<^sub>0, 8),
(1, ((RSP\<^sub>0::64 word) - 0x8), 8),
(2, ((RSP\<^sub>0::64 word) - 0x10), 8),
(3, ((RSP\<^sub>0::64 word) - 0x18), 8),
(4, ((RSP\<^sub>0::64 word) - 0x20), 8),
(5, ((RSP\<^sub>0::64 word) - 0x28), 8),
(6, ((RSP\<^sub>0::64 word) - 0x30), 8),
(7, ((RSP\<^sub>0::64 word) - 0x60), 8)
}\<close>
definition P_0xbc00_2_regions :: state_pred where
\<open>P_0xbc00_2_regions \<sigma> \<equiv> \<exists>regions. P_0xbc00_2_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_assert_fail_addr_0xbc00_2 :: state_pred where
\<open>Q_assert_fail_addr_0xbc00_2 \<sigma> \<equiv> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x60) \<and> RIP \<sigma> = assert_fail_addr \<and> RAX \<sigma> = RAX\<^sub>0 \<and> RBP \<sigma> = RBP\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare Q_assert_fail_addr_0xbc00_2_def[Qs]
schematic_goal array_remove_0_1_0xbc00_0xbc00_2[blocks]:
assumes \<open>(P_0xbc00_2 && P_0xbc00_2_regions) \<sigma>\<close>
shows \<open>exec_block (Suc 0) 0xbc00 2 \<sigma> \<triangleq> ?\<sigma> \<and> Q_assert_fail_addr_0xbc00_2 ?\<sigma> \<and> block_usage P_0xbc00_2_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbc00_2_def P_0xbc00_2_regions_def post: Q_assert_fail_addr_0xbc00_2_def regionset: P_0xbc00_2_regions_set_def)
definition P_0xbad0_false_3 :: state_pred where
\<open>P_0xbad0_false_3 \<sigma> \<equiv> RIP \<sigma> = 0xbad0 \<and> RAX \<sigma> = RAX\<^sub>0 \<and> RBX \<sigma> = RBX\<^sub>0 \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = RDX\<^sub>0 \<and> RDI \<sigma> = RDI\<^sub>0 \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = RBP\<^sub>0 \<and> R15 \<sigma> = R15\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare P_0xbad0_false_3_def[Ps]
definition P_0xbad0_false_3_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbad0_false_3_regions_set \<sigma> \<equiv> {
(0, RSP\<^sub>0, 8),
(1, ((RDI\<^sub>0::64 word) + 0xc), 4),
(2, ((RSP\<^sub>0::64 word) - 0x8), 8),
(3, ((RSP\<^sub>0::64 word) - 0x10), 8),
(4, ((RSP\<^sub>0::64 word) - 0x18), 8),
(5, ((RSP\<^sub>0::64 word) - 0x20), 8),
(6, ((RSP\<^sub>0::64 word) - 0x28), 8),
(7, ((RSP\<^sub>0::64 word) - 0x30), 8)
}\<close>
definition P_0xbad0_false_3_regions :: state_pred where
\<open>P_0xbad0_false_3_regions \<sigma> \<equiv> \<exists>regions. P_0xbad0_false_3_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbae3_3 :: state_pred where
\<open>Q_0xbae3_3 \<sigma> \<equiv> RIP \<sigma> = 0xbae3 \<and> RAX \<sigma> = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = ucast ((\<langle>31,0\<rangle>((RSI\<^sub>0::64 word) + 0x1)::32 word)) \<and> RDI \<sigma> = RDI\<^sub>0 \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = RBP\<^sub>0 \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare Q_0xbae3_3_def[Qs]
schematic_goal array_remove_0_6_0xbad0_0xbae1_3[blocks]:
assumes \<open>(P_0xbad0_false_3 && P_0xbad0_false_3_regions && ! SF) \<sigma>\<close>
shows \<open>exec_block 6 0xbae1 3 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbae3_3 ?\<sigma> \<and> block_usage P_0xbad0_false_3_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbad0_false_3_def P_0xbad0_false_3_regions_def post: Q_0xbae3_3_def regionset: P_0xbad0_false_3_regions_set_def)
definition P_0xbae3_true_4 :: state_pred where
\<open>P_0xbae3_true_4 \<sigma> \<equiv> RIP \<sigma> = 0xbae3 \<and> RAX \<sigma> = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = ucast ((\<langle>31,0\<rangle>((RSI\<^sub>0::64 word) + 0x1)::32 word)) \<and> RDI \<sigma> = RDI\<^sub>0 \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = RBP\<^sub>0 \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare P_0xbae3_true_4_def[Ps]
definition P_0xbae3_true_4_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbae3_true_4_regions_set \<sigma> \<equiv> {
(0, RSP\<^sub>0, 8),
(1, ((RDI\<^sub>0::64 word) + 0xc), 4),
(2, ((RSP\<^sub>0::64 word) - 0x8), 8),
(3, ((RSP\<^sub>0::64 word) - 0x10), 8),
(4, ((RSP\<^sub>0::64 word) - 0x18), 8),
(5, ((RSP\<^sub>0::64 word) - 0x20), 8),
(6, ((RSP\<^sub>0::64 word) - 0x28), 8),
(7, ((RSP\<^sub>0::64 word) - 0x30), 8)
}\<close>
definition P_0xbae3_true_4_regions :: state_pred where
\<open>P_0xbae3_true_4_regions \<sigma> \<equiv> \<exists>regions. P_0xbae3_true_4_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbbe1_4 :: state_pred where
\<open>Q_0xbbe1_4 \<sigma> \<equiv> RIP \<sigma> = 0xbbe1 \<and> RAX \<sigma> = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = 0x213b0 \<and> RDX \<sigma> = 0xb5 \<and> RDI \<sigma> = 0x20afe \<and> RSI \<sigma> = 0x20ae6 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = RBP\<^sub>0 \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare Q_0xbbe1_4_def[Qs]
schematic_goal array_remove_0_5_0xbae3_0xbbda_4[blocks]:
assumes \<open>(P_0xbae3_true_4 && P_0xbae3_true_4_regions && ja) \<sigma>\<close>
shows \<open>exec_block 5 0xbbda 4 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbbe1_4 ?\<sigma> \<and> block_usage P_0xbae3_true_4_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbae3_true_4_def P_0xbae3_true_4_regions_def post: Q_0xbbe1_4_def regionset: P_0xbae3_true_4_regions_set_def)
definition P_0xbbe1_5 :: state_pred where
\<open>P_0xbbe1_5 \<sigma> \<equiv> RIP \<sigma> = 0xbbe1 \<and> RAX \<sigma> = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = 0x213b0 \<and> RDX \<sigma> = 0xb5 \<and> RDI \<sigma> = 0x20afe \<and> RSI \<sigma> = 0x20ae6 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = RBP\<^sub>0 \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare P_0xbbe1_5_def[Ps]
definition P_0xbbe1_5_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbbe1_5_regions_set \<sigma> \<equiv> {
(0, RSP\<^sub>0, 8),
(1, ((RDI\<^sub>0::64 word) + 0xc), 4),
(2, ((RSP\<^sub>0::64 word) - 0x8), 8),
(3, ((RSP\<^sub>0::64 word) - 0x10), 8),
(4, ((RSP\<^sub>0::64 word) - 0x18), 8),
(5, ((RSP\<^sub>0::64 word) - 0x20), 8),
(6, ((RSP\<^sub>0::64 word) - 0x28), 8),
(7, ((RSP\<^sub>0::64 word) - 0x30), 8),
(8, ((RSP\<^sub>0::64 word) - 0x60), 8)
}\<close>
definition P_0xbbe1_5_regions :: state_pred where
\<open>P_0xbbe1_5_regions \<sigma> \<equiv> \<exists>regions. P_0xbbe1_5_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_assert_fail_addr_0xbbe1_5 :: state_pred where
\<open>Q_assert_fail_addr_0xbbe1_5 \<sigma> \<equiv> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x60) \<and> RIP \<sigma> = assert_fail_addr \<and> RAX \<sigma> = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> RBP \<sigma> = RBP\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare Q_assert_fail_addr_0xbbe1_5_def[Qs]
schematic_goal array_remove_0_1_0xbbe1_0xbbe1_5[blocks]:
assumes \<open>(P_0xbbe1_5 && P_0xbbe1_5_regions) \<sigma>\<close>
shows \<open>exec_block (Suc 0) 0xbbe1 5 \<sigma> \<triangleq> ?\<sigma> \<and> Q_assert_fail_addr_0xbbe1_5 ?\<sigma> \<and> block_usage P_0xbbe1_5_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbbe1_5_def P_0xbbe1_5_regions_def post: Q_assert_fail_addr_0xbbe1_5_def regionset: P_0xbbe1_5_regions_set_def)
definition P_0xbae3_false_6 :: state_pred where
\<open>P_0xbae3_false_6 \<sigma> \<equiv> RIP \<sigma> = 0xbae3 \<and> RAX \<sigma> = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = ucast ((\<langle>31,0\<rangle>((RSI\<^sub>0::64 word) + 0x1)::32 word)) \<and> RDI \<sigma> = RDI\<^sub>0 \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = RBP\<^sub>0 \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare P_0xbae3_false_6_def[Ps]
definition P_0xbae3_false_6_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbae3_false_6_regions_set \<sigma> \<equiv> {
(0, RSP\<^sub>0, 8),
(1, ((RDI\<^sub>0::64 word) + 0xc), 4),
(2, ((RSP\<^sub>0::64 word) - 0x8), 8),
(3, ((RSP\<^sub>0::64 word) - 0x10), 8),
(4, ((RSP\<^sub>0::64 word) - 0x18), 8),
(5, ((RSP\<^sub>0::64 word) - 0x20), 8),
(6, ((RSP\<^sub>0::64 word) - 0x28), 8),
(7, ((RSP\<^sub>0::64 word) - 0x30), 8)
}\<close>
definition P_0xbae3_false_6_regions :: state_pred where
\<open>P_0xbae3_false_6_regions \<sigma> \<equiv> \<exists>regions. P_0xbae3_false_6_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbaee_6 :: state_pred where
\<open>Q_0xbaee_6 \<sigma> \<equiv> RIP \<sigma> = 0xbaee \<and> RAX \<sigma> = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = ucast ((\<langle>31,0\<rangle>((RSI\<^sub>0::64 word) + 0x1)::32 word)) \<and> RDI \<sigma> = RDI\<^sub>0 \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare Q_0xbaee_6_def[Qs]
schematic_goal array_remove_0_3_0xbae3_0xbaeb_6[blocks]:
assumes \<open>(P_0xbae3_false_6 && P_0xbae3_false_6_regions && ! ja) \<sigma>\<close>
shows \<open>exec_block 3 0xbaeb 6 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbaee_6 ?\<sigma> \<and> block_usage P_0xbae3_false_6_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbae3_false_6_def P_0xbae3_false_6_regions_def post: Q_0xbaee_6_def regionset: P_0xbae3_false_6_regions_set_def)
definition P_0xbaee_true_7 :: state_pred where
\<open>P_0xbaee_true_7 \<sigma> \<equiv> RIP \<sigma> = 0xbaee \<and> RAX \<sigma> = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = ucast ((\<langle>31,0\<rangle>((RSI\<^sub>0::64 word) + 0x1)::32 word)) \<and> RDI \<sigma> = RDI\<^sub>0 \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare P_0xbaee_true_7_def[Ps]
definition P_0xbaee_true_7_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbaee_true_7_regions_set \<sigma> \<equiv> {
(0, RSP\<^sub>0, 8),
(1, ((RDI\<^sub>0::64 word) + 0xc), 4),
(2, ((RSP\<^sub>0::64 word) - 0x8), 8),
(3, ((RSP\<^sub>0::64 word) - 0x10), 8),
(4, ((RSP\<^sub>0::64 word) - 0x18), 8),
(5, ((RSP\<^sub>0::64 word) - 0x20), 8),
(6, ((RSP\<^sub>0::64 word) - 0x28), 8),
(7, ((RSP\<^sub>0::64 word) - 0x30), 8)
}\<close>
definition P_0xbaee_true_7_regions :: state_pred where
\<open>P_0xbaee_true_7_regions \<sigma> \<equiv> \<exists>regions. P_0xbaee_true_7_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbb96_7 :: state_pred where
\<open>Q_0xbb96_7 \<sigma> \<equiv> RIP \<sigma> = 0xbb96 \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare Q_0xbb96_7_def[Qs]
schematic_goal array_remove_0_3_0xbaee_0xbbc5_7[blocks]:
assumes \<open>(P_0xbaee_true_7 && P_0xbaee_true_7_regions && SF) \<sigma>\<close>
shows \<open>exec_block 3 0xbbc5 7 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbb96_7 ?\<sigma> \<and> block_usage P_0xbaee_true_7_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbaee_true_7_def P_0xbaee_true_7_regions_def post: Q_0xbb96_7_def regionset: P_0xbaee_true_7_regions_set_def)
definition P_0xbaee_false_8 :: state_pred where
\<open>P_0xbaee_false_8 \<sigma> \<equiv> RIP \<sigma> = 0xbaee \<and> RAX \<sigma> = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = ucast ((\<langle>31,0\<rangle>((RSI\<^sub>0::64 word) + 0x1)::32 word)) \<and> RDI \<sigma> = RDI\<^sub>0 \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare P_0xbaee_false_8_def[Ps]
definition P_0xbaee_false_8_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbaee_false_8_regions_set \<sigma> \<equiv> {
(0, RSP\<^sub>0, 8),
(1, ((RDI\<^sub>0::64 word) + 0xc), 4),
(2, ((RSP\<^sub>0::64 word) - 0x8), 8),
(3, ((RSP\<^sub>0::64 word) - 0x10), 8),
(4, ((RSP\<^sub>0::64 word) - 0x18), 8),
(5, ((RSP\<^sub>0::64 word) - 0x20), 8),
(6, ((RSP\<^sub>0::64 word) - 0x28), 8),
(7, ((RSP\<^sub>0::64 word) - 0x30), 8)
}\<close>
definition P_0xbaee_false_8_regions :: state_pred where
\<open>P_0xbaee_false_8_regions \<sigma> \<equiv> \<exists>regions. P_0xbaee_false_8_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbaf6_8 :: state_pred where
\<open>Q_0xbaf6_8 \<sigma> \<equiv> RIP \<sigma> = 0xbaf6 \<and> RAX \<sigma> = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = ucast ((\<langle>31,0\<rangle>((RSI\<^sub>0::64 word) + 0x1)::32 word)) \<and> RDI \<sigma> = RDI\<^sub>0 \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare Q_0xbaf6_8_def[Qs]
schematic_goal array_remove_0_2_0xbaee_0xbaf4_8[blocks]:
assumes \<open>(P_0xbaee_false_8 && P_0xbaee_false_8_regions && ! SF) \<sigma>\<close>
shows \<open>exec_block 2 0xbaf4 8 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbaf6_8 ?\<sigma> \<and> block_usage P_0xbaee_false_8_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbaee_false_8_def P_0xbaee_false_8_regions_def post: Q_0xbaf6_8_def regionset: P_0xbaee_false_8_regions_set_def)
definition P_0xbaf6_true_9 :: state_pred where
\<open>P_0xbaf6_true_9 \<sigma> \<equiv> RIP \<sigma> = 0xbaf6 \<and> RAX \<sigma> = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = ucast ((\<langle>31,0\<rangle>((RSI\<^sub>0::64 word) + 0x1)::32 word)) \<and> RDI \<sigma> = RDI\<^sub>0 \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare P_0xbaf6_true_9_def[Ps]
definition P_0xbaf6_true_9_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbaf6_true_9_regions_set \<sigma> \<equiv> {
(0, RSP\<^sub>0, 8),
(1, ((RDI\<^sub>0::64 word) + 0xc), 4),
(2, ((RSP\<^sub>0::64 word) - 0x8), 8),
(3, ((RSP\<^sub>0::64 word) - 0x10), 8),
(4, ((RSP\<^sub>0::64 word) - 0x18), 8),
(5, ((RSP\<^sub>0::64 word) - 0x20), 8),
(6, ((RSP\<^sub>0::64 word) - 0x28), 8),
(7, ((RSP\<^sub>0::64 word) - 0x30), 8)
}\<close>
definition P_0xbaf6_true_9_regions :: state_pred where
\<open>P_0xbaf6_true_9_regions \<sigma> \<equiv> \<exists>regions. P_0xbaf6_true_9_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbb96_9 :: state_pred where
\<open>Q_0xbb96_9 \<sigma> \<equiv> RIP \<sigma> = 0xbb96 \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare Q_0xbb96_9_def[Qs]
schematic_goal array_remove_0_3_0xbaf6_0xbbc5_9[blocks]:
assumes \<open>(P_0xbaf6_true_9 && P_0xbaf6_true_9_regions && jbe) \<sigma>\<close>
shows \<open>exec_block 3 0xbbc5 9 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbb96_9 ?\<sigma> \<and> block_usage P_0xbaf6_true_9_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbaf6_true_9_def P_0xbaf6_true_9_regions_def post: Q_0xbb96_9_def regionset: P_0xbaf6_true_9_regions_set_def)
definition P_0xbaf6_false_10 :: state_pred where
\<open>P_0xbaf6_false_10 \<sigma> \<equiv> RIP \<sigma> = 0xbaf6 \<and> RAX \<sigma> = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = ucast ((\<langle>31,0\<rangle>((RSI\<^sub>0::64 word) + 0x1)::32 word)) \<and> RDI \<sigma> = RDI\<^sub>0 \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare P_0xbaf6_false_10_def[Ps]
definition P_0xbaf6_false_10_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbaf6_false_10_regions_set \<sigma> \<equiv> {
(0, RSP\<^sub>0, 8),
(1, ((RDI\<^sub>0::64 word) + 0xc), 4),
(2, ((RSP\<^sub>0::64 word) - 0x8), 8),
(3, ((RSP\<^sub>0::64 word) - 0x10), 8),
(4, ((RSP\<^sub>0::64 word) - 0x18), 8),
(5, ((RSP\<^sub>0::64 word) - 0x20), 8),
(6, ((RSP\<^sub>0::64 word) - 0x28), 8),
(7, ((RSP\<^sub>0::64 word) - 0x30), 8)
}\<close>
definition P_0xbaf6_false_10_regions :: state_pred where
\<open>P_0xbaf6_false_10_regions \<sigma> \<equiv> \<exists>regions. P_0xbaf6_false_10_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbafe_10 :: state_pred where
\<open>Q_0xbafe_10 \<sigma> \<equiv> RIP \<sigma> = 0xbafe \<and> RAX \<sigma> = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = ucast ((\<langle>31,0\<rangle>((RSI\<^sub>0::64 word) + 0x1)::32 word)) \<and> RDI \<sigma> = RDI\<^sub>0 \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare Q_0xbafe_10_def[Qs]
schematic_goal array_remove_0_2_0xbaf6_0xbafc_10[blocks]:
assumes \<open>(P_0xbaf6_false_10 && P_0xbaf6_false_10_regions && ! jbe) \<sigma>\<close>
shows \<open>exec_block 2 0xbafc 10 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbafe_10 ?\<sigma> \<and> block_usage P_0xbaf6_false_10_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbaf6_false_10_def P_0xbaf6_false_10_regions_def post: Q_0xbafe_10_def regionset: P_0xbaf6_false_10_regions_set_def)
definition P_0xbafe_true_11 :: state_pred where
\<open>P_0xbafe_true_11 \<sigma> \<equiv> RIP \<sigma> = 0xbafe \<and> RAX \<sigma> = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = ucast ((\<langle>31,0\<rangle>((RSI\<^sub>0::64 word) + 0x1)::32 word)) \<and> RDI \<sigma> = RDI\<^sub>0 \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare P_0xbafe_true_11_def[Ps]
definition P_0xbafe_true_11_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbafe_true_11_regions_set \<sigma> \<equiv> {
(0, RSP\<^sub>0, 8),
(1, ((RDI\<^sub>0::64 word) + 0xc), 4),
(2, ((RSP\<^sub>0::64 word) - 0x8), 8),
(3, ((RSP\<^sub>0::64 word) - 0x10), 8),
(4, ((RSP\<^sub>0::64 word) - 0x18), 8),
(5, ((RSP\<^sub>0::64 word) - 0x20), 8),
(6, ((RSP\<^sub>0::64 word) - 0x28), 8),
(7, ((RSP\<^sub>0::64 word) - 0x30), 8)
}\<close>
definition P_0xbafe_true_11_regions :: state_pred where
\<open>P_0xbafe_true_11_regions \<sigma> \<equiv> \<exists>regions. P_0xbafe_true_11_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbb90_11 :: state_pred where
\<open>Q_0xbb90_11 \<sigma> \<equiv> RIP \<sigma> = 0xbb90 \<and> RAX \<sigma> = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare Q_0xbb90_11_def[Qs]
schematic_goal array_remove_0_1_0xbafe_0xbafe_11[blocks]:
assumes \<open>(P_0xbafe_true_11 && P_0xbafe_true_11_regions && ZF) \<sigma>\<close>
shows \<open>exec_block (Suc 0) 0xbafe 11 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbb90_11 ?\<sigma> \<and> block_usage P_0xbafe_true_11_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbafe_true_11_def P_0xbafe_true_11_regions_def post: Q_0xbb90_11_def regionset: P_0xbafe_true_11_regions_set_def)
definition P_0xbafe_false_12 :: state_pred where
\<open>P_0xbafe_false_12 \<sigma> \<equiv> RIP \<sigma> = 0xbafe \<and> RAX \<sigma> = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = ucast ((\<langle>31,0\<rangle>((RSI\<^sub>0::64 word) + 0x1)::32 word)) \<and> RDI \<sigma> = RDI\<^sub>0 \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> R9 \<sigma> = R9\<^sub>0 \<and> R8 \<sigma> = R8\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare P_0xbafe_false_12_def[Ps]
definition P_0xbafe_false_12_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbafe_false_12_regions_set \<sigma> \<equiv> {
(0, RDI\<^sub>0, 8),
(1, RSP\<^sub>0, 8),
(2, ((RDI\<^sub>0::64 word) + 0xc), 4),
(3, ((RDI\<^sub>0::64 word) + 0x10), 4),
(4, ((RSP\<^sub>0::64 word) - 0x8), 8),
(5, ((RSP\<^sub>0::64 word) - 0x10), 8),
(6, ((RSP\<^sub>0::64 word) - 0x18), 8),
(7, ((RSP\<^sub>0::64 word) - 0x20), 8),
(8, ((RSP\<^sub>0::64 word) - 0x28), 8),
(9, ((RSP\<^sub>0::64 word) - 0x30), 8),
(10, ((RSP\<^sub>0::64 word) - 0x40), 8),
(11, ((RSP\<^sub>0::64 word) - 0x48), 8),
(12, ((RSP\<^sub>0::64 word) - 0x50), 8)
}\<close>
definition P_0xbafe_false_12_regions :: state_pred where
\<open>P_0xbafe_false_12_regions \<sigma> \<equiv> \<exists>regions. P_0xbafe_false_12_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbb39_12 :: state_pred where
\<open>Q_0xbb39_12 \<sigma> \<equiv> RIP \<sigma> = 0xbb39 \<and> RAX \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = ucast ((\<langle>31,0\<rangle>((RSI\<^sub>0::64 word) + 0x1)::32 word)) \<and> RDI \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word))\<close>
declare Q_0xbb39_12_def[Qs]
schematic_goal array_remove_0_15_0xbafe_0xbb34_12[blocks]:
assumes \<open>(P_0xbafe_false_12 && P_0xbafe_false_12_regions && ! ZF) \<sigma>\<close>
shows \<open>exec_block 15 0xbb34 12 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbb39_12 ?\<sigma> \<and> block_usage P_0xbafe_false_12_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbafe_false_12_def P_0xbafe_false_12_regions_def post: Q_0xbb39_12_def regionset: P_0xbafe_false_12_regions_set_def)
definition P_0xbb39_13 :: state_pred where
\<open>P_0xbb39_13 \<sigma> \<equiv> RIP \<sigma> = 0xbb39 \<and> RAX \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = ucast ((\<langle>31,0\<rangle>((RSI\<^sub>0::64 word) + 0x1)::32 word)) \<and> RDI \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word))\<close>
declare P_0xbb39_13_def[Ps]
definition P_0xbb39_13_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbb39_13_regions_set \<sigma> \<equiv> {
(0, RDI\<^sub>0, 8),
(1, RSP\<^sub>0, 8),
(2, ((RDI\<^sub>0::64 word) + 0xc), 4),
(3, ((RDI\<^sub>0::64 word) + 0x10), 4),
(4, ((RSP\<^sub>0::64 word) - 0x8), 8),
(5, ((RSP\<^sub>0::64 word) - 0x10), 8),
(6, ((RSP\<^sub>0::64 word) - 0x18), 8),
(7, ((RSP\<^sub>0::64 word) - 0x20), 8),
(8, ((RSP\<^sub>0::64 word) - 0x28), 8),
(9, ((RSP\<^sub>0::64 word) - 0x30), 8),
(10, ((RSP\<^sub>0::64 word) - 0x40), 8),
(11, ((RSP\<^sub>0::64 word) - 0x48), 8),
(12, ((RSP\<^sub>0::64 word) - 0x50), 8),
(13, ((RSP\<^sub>0::64 word) - 0x60), 8)
}\<close>
definition P_0xbb39_13_regions :: state_pred where
\<open>P_0xbb39_13_regions \<sigma> \<equiv> \<exists>regions. P_0xbb39_13_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_qemu_malloc_addr_0xbb39_13 :: state_pred where
\<open>Q_qemu_malloc_addr_0xbb39_13 \<sigma> \<equiv> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x60) \<and> RIP \<sigma> = qemu_malloc_addr \<and> RAX \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = ucast ((\<langle>31,0\<rangle>((RSI\<^sub>0::64 word) + 0x1)::32 word)) \<and> RDI \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb3e\<close>
declare Q_qemu_malloc_addr_0xbb39_13_def[Qs]
schematic_goal array_remove_0_1_0xbb39_0xbb39_13[blocks]:
assumes \<open>(P_0xbb39_13 && P_0xbb39_13_regions) \<sigma>\<close>
shows \<open>exec_block (Suc 0) 0xbb39 13 \<sigma> \<triangleq> ?\<sigma> \<and> Q_qemu_malloc_addr_0xbb39_13 ?\<sigma> \<and> block_usage P_0xbb39_13_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbb39_13_def P_0xbb39_13_regions_def post: Q_qemu_malloc_addr_0xbb39_13_def regionset: P_0xbb39_13_regions_set_def)
definition P_0xbb3e_14 :: state_pred where
\<open>P_0xbb3e_14 \<sigma> \<equiv> RIP \<sigma> = 0xbb3e \<and> RAX \<sigma> = qemu_malloc_0xbb39_retval \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = ucast ((\<langle>31,0\<rangle>((RSI\<^sub>0::64 word) + 0x1)::32 word)) \<and> RDI \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RSI \<sigma> = RSI\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb3e\<close>
declare P_0xbb3e_14_def[Ps]
definition P_0xbb3e_14_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbb3e_14_regions_set \<sigma> \<equiv> {
(0, RDI\<^sub>0, 8),
(1, RSP\<^sub>0, 8),
(2, ((RDI\<^sub>0::64 word) + 0xc), 4),
(3, ((RDI\<^sub>0::64 word) + 0x10), 4),
(4, ((RSP\<^sub>0::64 word) - 0x8), 8),
(5, ((RSP\<^sub>0::64 word) - 0x10), 8),
(6, ((RSP\<^sub>0::64 word) - 0x18), 8),
(7, ((RSP\<^sub>0::64 word) - 0x20), 8),
(8, ((RSP\<^sub>0::64 word) - 0x28), 8),
(9, ((RSP\<^sub>0::64 word) - 0x30), 8),
(10, ((RSP\<^sub>0::64 word) - 0x40), 8),
(11, ((RSP\<^sub>0::64 word) - 0x48), 8),
(12, ((RSP\<^sub>0::64 word) - 0x50), 8),
(13, ((RSP\<^sub>0::64 word) - 0x60), 8)
}\<close>
definition P_0xbb3e_14_regions :: state_pred where
\<open>P_0xbb3e_14_regions \<sigma> \<equiv> \<exists>regions. P_0xbb3e_14_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbb4c_14 :: state_pred where
\<open>Q_0xbb4c_14 \<sigma> \<equiv> RIP \<sigma> = 0xbb4c \<and> RAX \<sigma> = qemu_malloc_0xbb39_retval \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RDI \<sigma> = qemu_malloc_0xbb39_retval \<and> RSI \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb3e\<close>
declare Q_0xbb4c_14_def[Qs]
schematic_goal array_remove_0_4_0xbb3e_0xbb49_14[blocks]:
assumes \<open>(P_0xbb3e_14 && P_0xbb3e_14_regions) \<sigma>\<close>
shows \<open>exec_block 4 0xbb49 14 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbb4c_14 ?\<sigma> \<and> block_usage P_0xbb3e_14_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbb3e_14_def P_0xbb3e_14_regions_def post: Q_0xbb4c_14_def regionset: P_0xbb3e_14_regions_set_def)
definition P_0xbb4c_15 :: state_pred where
\<open>P_0xbb4c_15 \<sigma> \<equiv> RIP \<sigma> = 0xbb4c \<and> RAX \<sigma> = qemu_malloc_0xbb39_retval \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RDI \<sigma> = qemu_malloc_0xbb39_retval \<and> RSI \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb3e\<close>
declare P_0xbb4c_15_def[Ps]
definition P_0xbb4c_15_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbb4c_15_regions_set \<sigma> \<equiv> {
(0, RDI\<^sub>0, 8),
(1, RSP\<^sub>0, 8),
(2, ((RDI\<^sub>0::64 word) + 0xc), 4),
(3, ((RDI\<^sub>0::64 word) + 0x10), 4),
(4, ((RSP\<^sub>0::64 word) - 0x8), 8),
(5, ((RSP\<^sub>0::64 word) - 0x10), 8),
(6, ((RSP\<^sub>0::64 word) - 0x18), 8),
(7, ((RSP\<^sub>0::64 word) - 0x20), 8),
(8, ((RSP\<^sub>0::64 word) - 0x28), 8),
(9, ((RSP\<^sub>0::64 word) - 0x30), 8),
(10, ((RSP\<^sub>0::64 word) - 0x40), 8),
(11, ((RSP\<^sub>0::64 word) - 0x48), 8),
(12, ((RSP\<^sub>0::64 word) - 0x50), 8),
(13, ((RSP\<^sub>0::64 word) - 0x60), 8)
}\<close>
definition P_0xbb4c_15_regions :: state_pred where
\<open>P_0xbb4c_15_regions \<sigma> \<equiv> \<exists>regions. P_0xbb4c_15_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_memcpy_addr_0xbb4c_15 :: state_pred where
\<open>Q_memcpy_addr_0xbb4c_15 \<sigma> \<equiv> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x60) \<and> RIP \<sigma> = memcpy_addr \<and> RAX \<sigma> = qemu_malloc_0xbb39_retval \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RDI \<sigma> = qemu_malloc_0xbb39_retval \<and> RSI \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb51\<close>
declare Q_memcpy_addr_0xbb4c_15_def[Qs]
schematic_goal array_remove_0_1_0xbb4c_0xbb4c_15[blocks]:
assumes \<open>(P_0xbb4c_15 && P_0xbb4c_15_regions) \<sigma>\<close>
shows \<open>exec_block (Suc 0) 0xbb4c 15 \<sigma> \<triangleq> ?\<sigma> \<and> Q_memcpy_addr_0xbb4c_15 ?\<sigma> \<and> block_usage P_0xbb4c_15_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbb4c_15_def P_0xbb4c_15_regions_def post: Q_memcpy_addr_0xbb4c_15_def regionset: P_0xbb4c_15_regions_set_def)
definition P_0xbb51_16 :: state_pred where
\<open>P_0xbb51_16 \<sigma> \<equiv> RIP \<sigma> = 0xbb51 \<and> RAX \<sigma> = memcpy_0xbb4c_retval \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RDI \<sigma> = qemu_malloc_0xbb39_retval \<and> RSI \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb51\<close>
declare P_0xbb51_16_def[Ps]
definition P_0xbb51_16_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbb51_16_regions_set \<sigma> \<equiv> {
(0, RDI\<^sub>0, 8),
(1, RSP\<^sub>0, 8),
(2, ((RDI\<^sub>0::64 word) + 0xc), 4),
(3, ((RDI\<^sub>0::64 word) + 0x10), 4),
(4, ((RSP\<^sub>0::64 word) - 0x8), 8),
(5, ((RSP\<^sub>0::64 word) - 0x10), 8),
(6, ((RSP\<^sub>0::64 word) - 0x18), 8),
(7, ((RSP\<^sub>0::64 word) - 0x20), 8),
(8, ((RSP\<^sub>0::64 word) - 0x28), 8),
(9, ((RSP\<^sub>0::64 word) - 0x30), 8),
(10, ((RSP\<^sub>0::64 word) - 0x40), 8),
(11, ((RSP\<^sub>0::64 word) - 0x48), 8),
(12, ((RSP\<^sub>0::64 word) - 0x50), 8),
(13, ((RSP\<^sub>0::64 word) - 0x60), 8)
}\<close>
definition P_0xbb51_16_regions :: state_pred where
\<open>P_0xbb51_16_regions \<sigma> \<equiv> \<exists>regions. P_0xbb51_16_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbb5d_16 :: state_pred where
\<open>Q_0xbb5d_16 \<sigma> \<equiv> RIP \<sigma> = 0xbb5d \<and> RAX \<sigma> = memcpy_0xbb4c_retval \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RDI \<sigma> = qemu_malloc_0xbb39_retval \<and> RSI \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb51\<close>
declare Q_0xbb5d_16_def[Qs]
schematic_goal array_remove_0_3_0xbb51_0xbb58_16[blocks]:
assumes \<open>(P_0xbb51_16 && P_0xbb51_16_regions) \<sigma>\<close>
shows \<open>exec_block 3 0xbb58 16 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbb5d_16 ?\<sigma> \<and> block_usage P_0xbb51_16_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbb51_16_def P_0xbb51_16_regions_def post: Q_0xbb5d_16_def regionset: P_0xbb51_16_regions_set_def)
definition P_0xbb5d_true_17 :: state_pred where
\<open>P_0xbb5d_true_17 \<sigma> \<equiv> RIP \<sigma> = 0xbb5d \<and> RAX \<sigma> = memcpy_0xbb4c_retval \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RDI \<sigma> = qemu_malloc_0xbb39_retval \<and> RSI \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb51\<close>
declare P_0xbb5d_true_17_def[Ps]
definition P_0xbb5d_true_17_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbb5d_true_17_regions_set \<sigma> \<equiv> {
(0, RDI\<^sub>0, 8),
(1, RSP\<^sub>0, 8),
(2, ((RDI\<^sub>0::64 word) + 0xc), 4),
(3, ((RDI\<^sub>0::64 word) + 0x10), 4),
(4, ((RSP\<^sub>0::64 word) - 0x8), 8),
(5, ((RSP\<^sub>0::64 word) - 0x10), 8),
(6, ((RSP\<^sub>0::64 word) - 0x18), 8),
(7, ((RSP\<^sub>0::64 word) - 0x20), 8),
(8, ((RSP\<^sub>0::64 word) - 0x28), 8),
(9, ((RSP\<^sub>0::64 word) - 0x30), 8),
(10, ((RSP\<^sub>0::64 word) - 0x40), 8),
(11, ((RSP\<^sub>0::64 word) - 0x48), 8),
(12, ((RSP\<^sub>0::64 word) - 0x50), 8),
(13, ((RSP\<^sub>0::64 word) - 0x60), 8)
}\<close>
definition P_0xbb5d_true_17_regions :: state_pred where
\<open>P_0xbb5d_true_17_regions \<sigma> \<equiv> \<exists>regions. P_0xbb5d_true_17_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbbb6_17 :: state_pred where
\<open>Q_0xbbb6_17 \<sigma> \<equiv> RIP \<sigma> = 0xbbb6 \<and> RAX \<sigma> = memcpy_0xbb4c_retval \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (((sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word) - (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> RDI \<sigma> = (((((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word))::64 word) + (\<langle>63,0\<rangle>(((sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word)::64 word) * 0x1)::64 word)) \<and> RSI \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb51\<close>
declare Q_0xbbb6_17_def[Qs]
schematic_goal array_remove_0_5_0xbb5d_0xbbb3_17[blocks]:
assumes \<open>(P_0xbb5d_true_17 && P_0xbb5d_true_17_regions && jg) \<sigma>\<close>
shows \<open>exec_block 5 0xbbb3 17 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbbb6_17 ?\<sigma> \<and> block_usage P_0xbb5d_true_17_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbb5d_true_17_def P_0xbb5d_true_17_regions_def post: Q_0xbbb6_17_def regionset: P_0xbb5d_true_17_regions_set_def)
definition P_0xbbb6_18 :: state_pred where
\<open>P_0xbbb6_18 \<sigma> \<equiv> RIP \<sigma> = 0xbbb6 \<and> RAX \<sigma> = memcpy_0xbb4c_retval \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (((sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word) - (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> RDI \<sigma> = (((((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word))::64 word) + (\<langle>63,0\<rangle>(((sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word)::64 word) * 0x1)::64 word)) \<and> RSI \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb51\<close>
declare P_0xbbb6_18_def[Ps]
definition P_0xbbb6_18_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbbb6_18_regions_set \<sigma> \<equiv> {
(0, RDI\<^sub>0, 8),
(1, RSP\<^sub>0, 8),
(2, ((RDI\<^sub>0::64 word) + 0xc), 4),
(3, ((RDI\<^sub>0::64 word) + 0x10), 4),
(4, ((RSP\<^sub>0::64 word) - 0x8), 8),
(5, ((RSP\<^sub>0::64 word) - 0x10), 8),
(6, ((RSP\<^sub>0::64 word) - 0x18), 8),
(7, ((RSP\<^sub>0::64 word) - 0x20), 8),
(8, ((RSP\<^sub>0::64 word) - 0x28), 8),
(9, ((RSP\<^sub>0::64 word) - 0x30), 8),
(10, ((RSP\<^sub>0::64 word) - 0x40), 8),
(11, ((RSP\<^sub>0::64 word) - 0x48), 8),
(12, ((RSP\<^sub>0::64 word) - 0x50), 8),
(13, ((RSP\<^sub>0::64 word) - 0x60), 8)
}\<close>
definition P_0xbbb6_18_regions :: state_pred where
\<open>P_0xbbb6_18_regions \<sigma> \<equiv> \<exists>regions. P_0xbbb6_18_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_memmove_addr_0xbbb6_18 :: state_pred where
\<open>Q_memmove_addr_0xbbb6_18 \<sigma> \<equiv> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x60) \<and> RIP \<sigma> = memmove_addr \<and> RAX \<sigma> = memcpy_0xbb4c_retval \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (((sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word) - (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> RDI \<sigma> = (((((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word))::64 word) + (\<langle>63,0\<rangle>(((sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word)::64 word) * 0x1)::64 word)) \<and> RSI \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbbbb\<close>
declare Q_memmove_addr_0xbbb6_18_def[Qs]
schematic_goal array_remove_0_1_0xbbb6_0xbbb6_18[blocks]:
assumes \<open>(P_0xbbb6_18 && P_0xbbb6_18_regions) \<sigma>\<close>
shows \<open>exec_block (Suc 0) 0xbbb6 18 \<sigma> \<triangleq> ?\<sigma> \<and> Q_memmove_addr_0xbbb6_18 ?\<sigma> \<and> block_usage P_0xbbb6_18_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbbb6_18_def P_0xbbb6_18_regions_def post: Q_memmove_addr_0xbbb6_18_def regionset: P_0xbbb6_18_regions_set_def)
definition P_0xbbbb_19 :: state_pred where
\<open>P_0xbbbb_19 \<sigma> \<equiv> RIP \<sigma> = 0xbbbb \<and> RAX \<sigma> = memmove_0xbbb6_retval \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (((sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word) - (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> RDI \<sigma> = (((((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word))::64 word) + (\<langle>63,0\<rangle>(((sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word)::64 word) * 0x1)::64 word)) \<and> RSI \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbbbb\<close>
declare P_0xbbbb_19_def[Ps]
definition P_0xbbbb_19_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbbbb_19_regions_set \<sigma> \<equiv> {
(0, RDI\<^sub>0, 8),
(1, RSP\<^sub>0, 8),
(2, ((RDI\<^sub>0::64 word) + 0xc), 4),
(3, ((RDI\<^sub>0::64 word) + 0x10), 4),
(4, ((RSP\<^sub>0::64 word) - 0x8), 8),
(5, ((RSP\<^sub>0::64 word) - 0x10), 8),
(6, ((RSP\<^sub>0::64 word) - 0x18), 8),
(7, ((RSP\<^sub>0::64 word) - 0x20), 8),
(8, ((RSP\<^sub>0::64 word) - 0x28), 8),
(9, ((RSP\<^sub>0::64 word) - 0x30), 8),
(10, ((RSP\<^sub>0::64 word) - 0x40), 8),
(11, ((RSP\<^sub>0::64 word) - 0x48), 8),
(12, ((RSP\<^sub>0::64 word) - 0x50), 8),
(13, ((RSP\<^sub>0::64 word) - 0x60), 8)
}\<close>
definition P_0xbbbb_19_regions :: state_pred where
\<open>P_0xbbbb_19_regions \<sigma> \<equiv> \<exists>regions. P_0xbbbb_19_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbb73_19 :: state_pred where
\<open>Q_0xbb73_19 \<sigma> \<equiv> RIP \<sigma> = 0xbb73 \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word))\<close>
declare Q_0xbb73_19_def[Qs]
schematic_goal array_remove_0_1_0xbbbb_0xbbbb_19[blocks]:
assumes \<open>(P_0xbbbb_19 && P_0xbbbb_19_regions) \<sigma>\<close>
shows \<open>exec_block (Suc 0) 0xbbbb 19 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbb73_19 ?\<sigma> \<and> block_usage P_0xbbbb_19_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbbbb_19_def P_0xbbbb_19_regions_def post: Q_0xbb73_19_def regionset: P_0xbbbb_19_regions_set_def)
definition P_0xbb5d_false_20 :: state_pred where
\<open>P_0xbb5d_false_20 \<sigma> \<equiv> RIP \<sigma> = 0xbb5d \<and> RAX \<sigma> = memcpy_0xbb4c_retval \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RDI \<sigma> = qemu_malloc_0xbb39_retval \<and> RSI \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb51\<close>
declare P_0xbb5d_false_20_def[Ps]
definition P_0xbb5d_false_20_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbb5d_false_20_regions_set \<sigma> \<equiv> {
(0, RDI\<^sub>0, 8),
(1, RSP\<^sub>0, 8),
(2, ((RDI\<^sub>0::64 word) + 0xc), 4),
(3, ((RDI\<^sub>0::64 word) + 0x10), 4),
(4, ((RSP\<^sub>0::64 word) - 0x8), 8),
(5, ((RSP\<^sub>0::64 word) - 0x10), 8),
(6, ((RSP\<^sub>0::64 word) - 0x18), 8),
(7, ((RSP\<^sub>0::64 word) - 0x20), 8),
(8, ((RSP\<^sub>0::64 word) - 0x28), 8),
(9, ((RSP\<^sub>0::64 word) - 0x30), 8),
(10, ((RSP\<^sub>0::64 word) - 0x40), 8),
(11, ((RSP\<^sub>0::64 word) - 0x48), 8),
(12, ((RSP\<^sub>0::64 word) - 0x50), 8),
(13, ((RSP\<^sub>0::64 word) - 0x60), 8)
}\<close>
definition P_0xbb5d_false_20_regions :: state_pred where
\<open>P_0xbb5d_false_20_regions \<sigma> \<equiv> \<exists>regions. P_0xbb5d_false_20_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbb6e_20 :: state_pred where
\<open>Q_0xbb6e_20 \<sigma> \<equiv> RIP \<sigma> = 0xbb6e \<and> RAX \<sigma> = memcpy_0xbb4c_retval \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (((sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word) - (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> RDI \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> RSI \<sigma> = (((((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word))::64 word) + (\<langle>63,0\<rangle>(((sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word)::64 word) * 0x1)::64 word)) \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb51\<close>
declare Q_0xbb6e_20_def[Qs]
schematic_goal array_remove_0_5_0xbb5d_0xbb6a_20[blocks]:
assumes \<open>(P_0xbb5d_false_20 && P_0xbb5d_false_20_regions && ! jg) \<sigma>\<close>
shows \<open>exec_block 5 0xbb6a 20 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbb6e_20 ?\<sigma> \<and> block_usage P_0xbb5d_false_20_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbb5d_false_20_def P_0xbb5d_false_20_regions_def post: Q_0xbb6e_20_def regionset: P_0xbb5d_false_20_regions_set_def)
definition P_0xbb6e_21 :: state_pred where
\<open>P_0xbb6e_21 \<sigma> \<equiv> RIP \<sigma> = 0xbb6e \<and> RAX \<sigma> = memcpy_0xbb4c_retval \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (((sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word) - (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> RDI \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> RSI \<sigma> = (((((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word))::64 word) + (\<langle>63,0\<rangle>(((sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word)::64 word) * 0x1)::64 word)) \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb51\<close>
declare P_0xbb6e_21_def[Ps]
definition P_0xbb6e_21_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbb6e_21_regions_set \<sigma> \<equiv> {
(0, RDI\<^sub>0, 8),
(1, RSP\<^sub>0, 8),
(2, ((RDI\<^sub>0::64 word) + 0xc), 4),
(3, ((RDI\<^sub>0::64 word) + 0x10), 4),
(4, ((RSP\<^sub>0::64 word) - 0x8), 8),
(5, ((RSP\<^sub>0::64 word) - 0x10), 8),
(6, ((RSP\<^sub>0::64 word) - 0x18), 8),
(7, ((RSP\<^sub>0::64 word) - 0x20), 8),
(8, ((RSP\<^sub>0::64 word) - 0x28), 8),
(9, ((RSP\<^sub>0::64 word) - 0x30), 8),
(10, ((RSP\<^sub>0::64 word) - 0x40), 8),
(11, ((RSP\<^sub>0::64 word) - 0x48), 8),
(12, ((RSP\<^sub>0::64 word) - 0x50), 8),
(13, ((RSP\<^sub>0::64 word) - 0x60), 8)
}\<close>
definition P_0xbb6e_21_regions :: state_pred where
\<open>P_0xbb6e_21_regions \<sigma> \<equiv> \<exists>regions. P_0xbb6e_21_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_memmove_addr_0xbb6e_21 :: state_pred where
\<open>Q_memmove_addr_0xbb6e_21 \<sigma> \<equiv> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x60) \<and> RIP \<sigma> = memmove_addr \<and> RAX \<sigma> = memcpy_0xbb4c_retval \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word))\<close>
declare Q_memmove_addr_0xbb6e_21_def[Qs]
schematic_goal array_remove_0_1_0xbb6e_0xbb6e_21[blocks]:
assumes \<open>(P_0xbb6e_21 && P_0xbb6e_21_regions) \<sigma>\<close>
shows \<open>exec_block (Suc 0) 0xbb6e 21 \<sigma> \<triangleq> ?\<sigma> \<and> Q_memmove_addr_0xbb6e_21 ?\<sigma> \<and> block_usage P_0xbb6e_21_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbb6e_21_def P_0xbb6e_21_regions_def post: Q_memmove_addr_0xbb6e_21_def regionset: P_0xbb6e_21_regions_set_def)
definition P_0xbb73_22 :: state_pred where
\<open>P_0xbb73_22 \<sigma> \<equiv> RIP \<sigma> = 0xbb73 \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word))\<close>
declare P_0xbb73_22_def[Ps]
definition P_0xbb73_22_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbb73_22_regions_set \<sigma> \<equiv> {
(0, RDI\<^sub>0, 8),
(1, RSP\<^sub>0, 8),
(2, ((RDI\<^sub>0::64 word) + 0xc), 4),
(3, ((RDI\<^sub>0::64 word) + 0x10), 4),
(4, ((RSP\<^sub>0::64 word) - 0x8), 8),
(5, ((RSP\<^sub>0::64 word) - 0x10), 8),
(6, ((RSP\<^sub>0::64 word) - 0x18), 8),
(7, ((RSP\<^sub>0::64 word) - 0x20), 8),
(8, ((RSP\<^sub>0::64 word) - 0x28), 8),
(9, ((RSP\<^sub>0::64 word) - 0x30), 8),
(10, ((RSP\<^sub>0::64 word) - 0x40), 8),
(11, ((RSP\<^sub>0::64 word) - 0x48), 8),
(12, ((RSP\<^sub>0::64 word) - 0x50), 8)
}\<close>
definition P_0xbb73_22_regions :: state_pred where
\<open>P_0xbb73_22_regions \<sigma> \<equiv> \<exists>regions. P_0xbb73_22_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbb7c_22 :: state_pred where
\<open>Q_0xbb7c_22 \<sigma> \<equiv> RIP \<sigma> = 0xbb7c \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RDI \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word))\<close>
declare Q_0xbb7c_22_def[Qs]
schematic_goal array_remove_0_3_0xbb73_0xbb79_22[blocks]:
assumes \<open>(P_0xbb73_22 && P_0xbb73_22_regions) \<sigma>\<close>
shows \<open>exec_block 3 0xbb79 22 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbb7c_22 ?\<sigma> \<and> block_usage P_0xbb73_22_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbb73_22_def P_0xbb73_22_regions_def post: Q_0xbb7c_22_def regionset: P_0xbb73_22_regions_set_def)
definition P_0xbb7c_23 :: state_pred where
\<open>P_0xbb7c_23 \<sigma> \<equiv> RIP \<sigma> = 0xbb7c \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RDI \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word))\<close>
declare P_0xbb7c_23_def[Ps]
definition P_0xbb7c_23_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbb7c_23_regions_set \<sigma> \<equiv> {
(0, RDI\<^sub>0, 8),
(1, RSP\<^sub>0, 8),
(2, ((RDI\<^sub>0::64 word) + 0xc), 4),
(3, ((RDI\<^sub>0::64 word) + 0x10), 4),
(4, ((RSP\<^sub>0::64 word) - 0x8), 8),
(5, ((RSP\<^sub>0::64 word) - 0x10), 8),
(6, ((RSP\<^sub>0::64 word) - 0x18), 8),
(7, ((RSP\<^sub>0::64 word) - 0x20), 8),
(8, ((RSP\<^sub>0::64 word) - 0x28), 8),
(9, ((RSP\<^sub>0::64 word) - 0x30), 8),
(10, ((RSP\<^sub>0::64 word) - 0x40), 8),
(11, ((RSP\<^sub>0::64 word) - 0x48), 8),
(12, ((RSP\<^sub>0::64 word) - 0x50), 8),
(13, ((RSP\<^sub>0::64 word) - 0x60), 8)
}\<close>
definition P_0xbb7c_23_regions :: state_pred where
\<open>P_0xbb7c_23_regions \<sigma> \<equiv> \<exists>regions. P_0xbb7c_23_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_memcpy_addr_0xbb7c_23 :: state_pred where
\<open>Q_memcpy_addr_0xbb7c_23 \<sigma> \<equiv> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x60) \<and> RIP \<sigma> = memcpy_addr \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RDI \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb81\<close>
declare Q_memcpy_addr_0xbb7c_23_def[Qs]
schematic_goal array_remove_0_1_0xbb7c_0xbb7c_23[blocks]:
assumes \<open>(P_0xbb7c_23 && P_0xbb7c_23_regions) \<sigma>\<close>
shows \<open>exec_block (Suc 0) 0xbb7c 23 \<sigma> \<triangleq> ?\<sigma> \<and> Q_memcpy_addr_0xbb7c_23 ?\<sigma> \<and> block_usage P_0xbb7c_23_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbb7c_23_def P_0xbb7c_23_regions_def post: Q_memcpy_addr_0xbb7c_23_def regionset: P_0xbb7c_23_regions_set_def)
definition P_0xbb81_24 :: state_pred where
\<open>P_0xbb81_24 \<sigma> \<equiv> RIP \<sigma> = 0xbb81 \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RDI \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb81\<close>
declare P_0xbb81_24_def[Ps]
definition P_0xbb81_24_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbb81_24_regions_set \<sigma> \<equiv> {
(0, RDI\<^sub>0, 8),
(1, RSP\<^sub>0, 8),
(2, ((RDI\<^sub>0::64 word) + 0xc), 4),
(3, ((RDI\<^sub>0::64 word) + 0x10), 4),
(4, ((RSP\<^sub>0::64 word) - 0x8), 8),
(5, ((RSP\<^sub>0::64 word) - 0x10), 8),
(6, ((RSP\<^sub>0::64 word) - 0x18), 8),
(7, ((RSP\<^sub>0::64 word) - 0x20), 8),
(8, ((RSP\<^sub>0::64 word) - 0x28), 8),
(9, ((RSP\<^sub>0::64 word) - 0x30), 8),
(10, ((RSP\<^sub>0::64 word) - 0x40), 8),
(11, ((RSP\<^sub>0::64 word) - 0x48), 8),
(12, ((RSP\<^sub>0::64 word) - 0x50), 8),
(13, ((RSP\<^sub>0::64 word) - 0x60), 8)
}\<close>
definition P_0xbb81_24_regions :: state_pred where
\<open>P_0xbb81_24_regions \<sigma> \<equiv> \<exists>regions. P_0xbb81_24_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbb84_24 :: state_pred where
\<open>Q_0xbb84_24 \<sigma> \<equiv> RIP \<sigma> = 0xbb84 \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RDI \<sigma> = qemu_malloc_0xbb39_retval \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb81\<close>
declare Q_0xbb84_24_def[Qs]
schematic_goal array_remove_0_1_0xbb81_0xbb81_24[blocks]:
assumes \<open>(P_0xbb81_24 && P_0xbb81_24_regions) \<sigma>\<close>
shows \<open>exec_block (Suc 0) 0xbb81 24 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbb84_24 ?\<sigma> \<and> block_usage P_0xbb81_24_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbb81_24_def P_0xbb81_24_regions_def post: Q_0xbb84_24_def regionset: P_0xbb81_24_regions_set_def)
definition P_0xbb84_25 :: state_pred where
\<open>P_0xbb84_25 \<sigma> \<equiv> RIP \<sigma> = 0xbb84 \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RDI \<sigma> = qemu_malloc_0xbb39_retval \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb81\<close>
declare P_0xbb84_25_def[Ps]
definition P_0xbb84_25_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbb84_25_regions_set \<sigma> \<equiv> {
(0, RDI\<^sub>0, 8),
(1, RSP\<^sub>0, 8),
(2, ((RDI\<^sub>0::64 word) + 0xc), 4),
(3, ((RDI\<^sub>0::64 word) + 0x10), 4),
(4, ((RSP\<^sub>0::64 word) - 0x8), 8),
(5, ((RSP\<^sub>0::64 word) - 0x10), 8),
(6, ((RSP\<^sub>0::64 word) - 0x18), 8),
(7, ((RSP\<^sub>0::64 word) - 0x20), 8),
(8, ((RSP\<^sub>0::64 word) - 0x28), 8),
(9, ((RSP\<^sub>0::64 word) - 0x30), 8),
(10, ((RSP\<^sub>0::64 word) - 0x40), 8),
(11, ((RSP\<^sub>0::64 word) - 0x48), 8),
(12, ((RSP\<^sub>0::64 word) - 0x50), 8),
(13, ((RSP\<^sub>0::64 word) - 0x60), 8)
}\<close>
definition P_0xbb84_25_regions :: state_pred where
\<open>P_0xbb84_25_regions \<sigma> \<equiv> \<exists>regions. P_0xbb84_25_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_free_addr_0xbb84_25 :: state_pred where
\<open>Q_free_addr_0xbb84_25 \<sigma> \<equiv> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x60) \<and> RIP \<sigma> = free_addr \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RDI \<sigma> = qemu_malloc_0xbb39_retval \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb89\<close>
declare Q_free_addr_0xbb84_25_def[Qs]
schematic_goal array_remove_0_1_0xbb84_0xbb84_25[blocks]:
assumes \<open>(P_0xbb84_25 && P_0xbb84_25_regions) \<sigma>\<close>
shows \<open>exec_block (Suc 0) 0xbb84 25 \<sigma> \<triangleq> ?\<sigma> \<and> Q_free_addr_0xbb84_25 ?\<sigma> \<and> block_usage P_0xbb84_25_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbb84_25_def P_0xbb84_25_regions_def post: Q_free_addr_0xbb84_25_def regionset: P_0xbb84_25_regions_set_def)
definition P_0xbb89_26 :: state_pred where
\<open>P_0xbb89_26 \<sigma> \<equiv> RIP \<sigma> = 0xbb89 \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RDX \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> RDI \<sigma> = qemu_malloc_0xbb39_retval \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> RBP \<sigma> = ucast ((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> R14 \<sigma> = qemu_malloc_0xbb39_retval \<and> R13 \<sigma> = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)) \<and> R12 \<sigma> = (sextend (ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))) 32 64::64 word) \<and> R9 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> R8 \<sigma> = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) = (\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word) \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x40),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x48),8]::64 word) = (sextend (ucast ((\<langle>31,0\<rangle>(((((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)::32 word) - 0x1)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x50),8]::64 word) = (((\<sigma> \<turnstile> *[RDI\<^sub>0,8]::64 word)::64 word) + (\<langle>63,0\<rangle>(((\<langle>63,0\<rangle>(sextend (ucast ((\<langle>31,0\<rangle>(((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)::32 word) * (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0x10),4]::32 word))::32 word))) 32 64::64 word)::64 word)::64 word) * 0x1)::64 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x60),8]::64 word) = 0xbb89\<close>
declare P_0xbb89_26_def[Ps]
definition P_0xbb89_26_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbb89_26_regions_set \<sigma> \<equiv> {
(0, RDI\<^sub>0, 8),
(1, RSP\<^sub>0, 8),
(2, ((RDI\<^sub>0::64 word) + 0xc), 4),
(3, ((RDI\<^sub>0::64 word) + 0x10), 4),
(4, ((RSP\<^sub>0::64 word) - 0x8), 8),
(5, ((RSP\<^sub>0::64 word) - 0x10), 8),
(6, ((RSP\<^sub>0::64 word) - 0x18), 8),
(7, ((RSP\<^sub>0::64 word) - 0x20), 8),
(8, ((RSP\<^sub>0::64 word) - 0x28), 8),
(9, ((RSP\<^sub>0::64 word) - 0x30), 8),
(10, ((RSP\<^sub>0::64 word) - 0x40), 8),
(11, ((RSP\<^sub>0::64 word) - 0x48), 8),
(12, ((RSP\<^sub>0::64 word) - 0x50), 8),
(13, ((RSP\<^sub>0::64 word) - 0x60), 8)
}\<close>
definition P_0xbb89_26_regions :: state_pred where
\<open>P_0xbb89_26_regions \<sigma> \<equiv> \<exists>regions. P_0xbb89_26_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbb90_26 :: state_pred where
\<open>Q_0xbb90_26 \<sigma> \<equiv> RIP \<sigma> = 0xbb90 \<and> RAX \<sigma> = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare Q_0xbb90_26_def[Qs]
schematic_goal array_remove_0_2_0xbb89_0xbb8d_26[blocks]:
assumes \<open>(P_0xbb89_26 && P_0xbb89_26_regions) \<sigma>\<close>
shows \<open>exec_block 2 0xbb8d 26 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbb90_26 ?\<sigma> \<and> block_usage P_0xbb89_26_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbb89_26_def P_0xbb89_26_regions_def post: Q_0xbb90_26_def regionset: P_0xbb89_26_regions_set_def)
definition P_0xbb90_27 :: state_pred where
\<open>P_0xbb90_27 \<sigma> \<equiv> RIP \<sigma> = 0xbb90 \<and> RAX \<sigma> = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word) = ucast ((\<sigma> \<turnstile> *[((RDI\<^sub>0::64 word) + 0xc),4]::32 word)) \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare P_0xbb90_27_def[Ps]
definition P_0xbb90_27_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbb90_27_regions_set \<sigma> \<equiv> {
(0, RSP\<^sub>0, 8),
(1, ((RDI\<^sub>0::64 word) + 0xc), 4),
(2, ((RSP\<^sub>0::64 word) - 0x8), 8),
(3, ((RSP\<^sub>0::64 word) - 0x10), 8),
(4, ((RSP\<^sub>0::64 word) - 0x18), 8),
(5, ((RSP\<^sub>0::64 word) - 0x20), 8),
(6, ((RSP\<^sub>0::64 word) - 0x28), 8),
(7, ((RSP\<^sub>0::64 word) - 0x30), 8)
}\<close>
definition P_0xbb90_27_regions :: state_pred where
\<open>P_0xbb90_27_regions \<sigma> \<equiv> \<exists>regions. P_0xbb90_27_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_0xbb96_27 :: state_pred where
\<open>Q_0xbb96_27 \<sigma> \<equiv> RIP \<sigma> = 0xbb96 \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare Q_0xbb96_27_def[Qs]
schematic_goal array_remove_0_2_0xbb90_0xbb94_27[blocks]:
assumes \<open>(P_0xbb90_27 && P_0xbb90_27_regions) \<sigma>\<close>
shows \<open>exec_block 2 0xbb94 27 \<sigma> \<triangleq> ?\<sigma> \<and> Q_0xbb96_27 ?\<sigma> \<and> block_usage P_0xbb90_27_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbb90_27_def P_0xbb90_27_regions_def post: Q_0xbb96_27_def regionset: P_0xbb90_27_regions_set_def)
definition P_0xbb96_28 :: state_pred where
\<open>P_0xbb96_28 \<sigma> \<equiv> RIP \<sigma> = 0xbb96 \<and> RBX \<sigma> = ucast ((\<langle>31,0\<rangle>RSI\<^sub>0::32 word)) \<and> RCX \<sigma> = RCX\<^sub>0 \<and> RSP \<sigma> = ((RSP\<^sub>0::64 word) - 0x58) \<and> R15 \<sigma> = RDI\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare P_0xbb96_28_def[Ps]
definition P_0xbb96_28_regions_set :: \<open>state \<Rightarrow> (nat \<times> 64 word \<times> nat) set\<close> where
\<open>P_0xbb96_28_regions_set \<sigma> \<equiv> {
(0, RSP\<^sub>0, 8),
(1, ((RSP\<^sub>0::64 word) - 0x8), 8),
(2, ((RSP\<^sub>0::64 word) - 0x10), 8),
(3, ((RSP\<^sub>0::64 word) - 0x18), 8),
(4, ((RSP\<^sub>0::64 word) - 0x20), 8),
(5, ((RSP\<^sub>0::64 word) - 0x28), 8),
(6, ((RSP\<^sub>0::64 word) - 0x30), 8)
}\<close>
definition P_0xbb96_28_regions :: state_pred where
\<open>P_0xbb96_28_regions \<sigma> \<equiv> \<exists>regions. P_0xbb96_28_regions_set \<sigma> \<subseteq> regions
\<and> (\<forall>i r. (i, r) \<in> regions \<longrightarrow> no_block_overflow r)
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<sqsubseteq> r' = (i = i' \<or> (i, i') \<in> {}))
\<and> (\<forall>i r i' r'. (i, r) \<in> regions \<longrightarrow> (i', r') \<in> regions \<longrightarrow> r \<bowtie> r' = (i \<noteq> i' \<and> (i, i') \<notin> {}))
\<close>
definition Q_ret_address_28 :: state_pred where
\<open>Q_ret_address_28 \<sigma> \<equiv> RIP \<sigma> = ret_address \<and> RBP \<sigma> = RBP\<^sub>0 \<and> R14 \<sigma> = R14\<^sub>0 \<and> R13 \<sigma> = R13\<^sub>0 \<and> R12 \<sigma> = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[RSP\<^sub>0,8]::64 word) = ret_address \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x8),8]::64 word) = R15\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x10),8]::64 word) = R14\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x18),8]::64 word) = R13\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x20),8]::64 word) = R12\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x28),8]::64 word) = RBP\<^sub>0 \<and> (\<sigma> \<turnstile> *[((RSP\<^sub>0::64 word) - 0x30),8]::64 word) = RBX\<^sub>0\<close>
declare Q_ret_address_28_def[Qs]
schematic_goal array_remove_0_8_0xbb96_0xbba4_28[blocks]:
assumes \<open>(P_0xbb96_28 && P_0xbb96_28_regions) \<sigma>\<close>
shows \<open>exec_block 8 0xbba4 28 \<sigma> \<triangleq> ?\<sigma> \<and> Q_ret_address_28 ?\<sigma> \<and> block_usage P_0xbb96_28_regions_set \<sigma> ?\<sigma>\<close>
using assms
by (steps pre: P_0xbb96_28_def P_0xbb96_28_regions_def post: Q_ret_address_28_def regionset: P_0xbb96_28_regions_set_def)
definition array_remove_acode :: ACode where
\<open>array_remove_acode =
Block 8 0xbace 0;
IF SF THEN
Block 5 0xbbf9 (Suc 0);
Block (Suc 0) 0xbc00 2;
CALL assert_fail_acode
ELSE
Block 6 0xbae1 3;
IF ja THEN
Block 5 0xbbda 4;
Block (Suc 0) 0xbbe1 5;
CALL assert_fail_acode
ELSE
Block 3 0xbaeb 6;
IF SF THEN
Block 3 0xbbc5 7
ELSE
Block 2 0xbaf4 8;
IF jbe THEN
Block 3 0xbbc5 9
ELSE
Block 2 0xbafc 10;
IF ZF THEN
Block (Suc 0) 0xbafe 11
ELSE
Block 15 0xbb34 12;
Block (Suc 0) 0xbb39 13;
CALL qemu_malloc_acode;
Block 4 0xbb49 14;
Block (Suc 0) 0xbb4c 15;
CALL memcpy_acode;
Block 3 0xbb58 16;
IF jg THEN
Block 5 0xbbb3 17;
Block (Suc 0) 0xbbb6 18;
CALL memmove_acode;
Block (Suc 0) 0xbbbb 19
ELSE
Block 5 0xbb6a 20;
Block (Suc 0) 0xbb6e 21;
CALL memmove_acode
FI;
Block 3 0xbb79 22;
Block (Suc 0) 0xbb7c 23;
CALL memcpy_acode;
Block (Suc 0) 0xbb81 24;
Block (Suc 0) 0xbb84 25;
CALL free_acode;
Block 2 0xbb8d 26
FI;
Block 2 0xbb94 27
FI
FI;
Block 8 0xbba4 28
FI
FI
\<close>
schematic_goal "array_remove":
assumes
\<open>\<forall>\<sigma>. RIP \<sigma> = 0xbad0 \<longrightarrow> P_0xbad0_true_1_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbc00 \<longrightarrow> P_0xbc00_2_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbad0 \<longrightarrow> P_0xbad0_false_3_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbae3 \<longrightarrow> P_0xbae3_true_4_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbbe1 \<longrightarrow> P_0xbbe1_5_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbae3 \<longrightarrow> P_0xbae3_false_6_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbaee \<longrightarrow> P_0xbaee_true_7_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbaee \<longrightarrow> P_0xbaee_false_8_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbaf6 \<longrightarrow> P_0xbaf6_true_9_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbaf6 \<longrightarrow> P_0xbaf6_false_10_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbafe \<longrightarrow> P_0xbafe_true_11_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbafe \<longrightarrow> P_0xbafe_false_12_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbb39 \<longrightarrow> P_0xbb39_13_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbb3e \<longrightarrow> P_0xbb3e_14_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbb4c \<longrightarrow> P_0xbb4c_15_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbb51 \<longrightarrow> P_0xbb51_16_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbb5d \<longrightarrow> P_0xbb5d_true_17_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbbb6 \<longrightarrow> P_0xbbb6_18_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbbbb \<longrightarrow> P_0xbbbb_19_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbb5d \<longrightarrow> P_0xbb5d_false_20_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbb6e \<longrightarrow> P_0xbb6e_21_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbb73 \<longrightarrow> P_0xbb73_22_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbb7c \<longrightarrow> P_0xbb7c_23_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbb81 \<longrightarrow> P_0xbb81_24_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbb84 \<longrightarrow> P_0xbb84_25_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbb89 \<longrightarrow> P_0xbb89_26_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbb90 \<longrightarrow> P_0xbb90_27_regions \<sigma>\<close>
and \<open>\<forall>\<sigma>. RIP \<sigma> = 0xbb96 \<longrightarrow> P_0xbb96_28_regions \<sigma>\<close>
and [blocks]: \<open>{{Q_assert_fail_addr_0xbc00_2}} \<box>assert_fail_acode {{Q_fail;M_0xbc00}}\<close>
and [blocks]: \<open>{{Q_assert_fail_addr_0xbbe1_5}} \<box>assert_fail_acode {{Q_fail;M_0xbbe1}}\<close>
and [blocks]: \<open>{{Q_qemu_malloc_addr_0xbb39_13}} \<box>qemu_malloc_acode {{P_0xbb3e_14;M_0xbb39}}\<close>
and [blocks]: \<open>{{Q_memcpy_addr_0xbb4c_15}} \<box>memcpy_acode {{P_0xbb51_16;M_0xbb4c}}\<close>
and [blocks]: \<open>{{Q_memmove_addr_0xbbb6_18}} \<box>memmove_acode {{P_0xbbbb_19;M_0xbbb6}}\<close>
and [blocks]: \<open>{{Q_memmove_addr_0xbb6e_21}} \<box>memmove_acode {{P_0xbb73_22;M_0xbb6e}}\<close>
and [blocks]: \<open>{{Q_memcpy_addr_0xbb7c_23}} \<box>memcpy_acode {{P_0xbb81_24;M_0xbb7c}}\<close>
and [blocks]: \<open>{{Q_free_addr_0xbb84_25}} \<box>free_acode {{P_0xbb89_26;M_0xbb84}}\<close>
shows \<open>{{?P}} array_remove_acode {{?Q;?M}}\<close>
by (vcg acode: array_remove_acode_def assms: assms)
end
|
theory "Cardinality-Domain"
imports "Launchbury.HOLCF-Utils"
begin
type_synonym oneShot = "one"
abbreviation notOneShot :: oneShot where "notOneShot \<equiv> ONE"
abbreviation oneShot :: oneShot where "oneShot \<equiv> \<bottom>"
type_synonym two = "oneShot\<^sub>\<bottom>"
abbreviation many :: two where "many \<equiv> up\<cdot>notOneShot"
abbreviation once :: two where "once \<equiv> up\<cdot>oneShot"
abbreviation none :: two where "none \<equiv> \<bottom>"
lemma many_max[simp]: "a \<sqsubseteq> many" by (cases a) auto
lemma two_conj: "c = many \<or> c = once \<or> c = none" by (metis Exh_Up one_neq_iffs(1))
lemma two_cases[case_names many once none]:
obtains "c = many" | "c = once" | "c = none" using two_conj by metis
definition two_pred where "two_pred = (\<Lambda> x. if x \<sqsubseteq> once then \<bottom> else x)"
lemma two_pred_simp: "two_pred\<cdot>c = (if c \<sqsubseteq> once then \<bottom> else c)"
unfolding two_pred_def
apply (rule beta_cfun)
apply (rule cont_if_else_above)
apply (auto elim: below_trans)
done
lemma two_pred_simps[simp]:
"two_pred\<cdot>many = many"
"two_pred\<cdot>once = none"
"two_pred\<cdot>none = none"
by (simp_all add: two_pred_simp)
lemma two_pred_below_arg: "two_pred \<cdot> f \<sqsubseteq> f"
by (auto simp add: two_pred_simp)
lemma two_pred_none: "two_pred\<cdot>c = none \<longleftrightarrow> c \<sqsubseteq> once"
by (auto simp add: two_pred_simp)
definition record_call where "record_call x = (\<Lambda> ce. (\<lambda> y. if x = y then two_pred\<cdot>(ce y) else ce y))"
lemma record_call_simp: "(record_call x \<cdot> f) x' = (if x = x' then two_pred \<cdot> (f x') else f x')"
unfolding record_call_def by auto
lemma record_call[simp]: "(record_call x \<cdot> f) x = two_pred \<cdot> (f x)"
unfolding record_call_simp by auto
lemma record_call_other[simp]: "x' \<noteq> x \<Longrightarrow> (record_call x \<cdot> f) x' = f x'"
unfolding record_call_simp by auto
lemma record_call_below_arg: "record_call x \<cdot> f \<sqsubseteq> f"
unfolding record_call_def
by (auto intro!: fun_belowI two_pred_below_arg)
definition two_add :: "two \<rightarrow> two \<rightarrow> two"
where "two_add = (\<Lambda> x. (\<Lambda> y. if x \<sqsubseteq> \<bottom> then y else (if y \<sqsubseteq> \<bottom> then x else many)))"
lemma two_add_simp: "two_add\<cdot>x\<cdot>y = (if x \<sqsubseteq> \<bottom> then y else (if y \<sqsubseteq> \<bottom> then x else many))"
unfolding two_add_def
apply (subst beta_cfun)
apply (rule cont2cont)
apply (rule cont_if_else_above)
apply (auto elim: below_trans)[1]
apply (rule cont_if_else_above)
apply (auto elim: below_trans)[8]
apply (rule beta_cfun)
apply (rule cont_if_else_above)
apply (auto elim: below_trans)[1]
apply (rule cont_if_else_above)
apply auto
done
lemma two_pred_two_add_once: "c \<sqsubseteq> two_pred\<cdot>(two_add\<cdot>once\<cdot>c)"
by (cases c rule: two_cases) (auto simp add: two_add_simp)
end
|
[GOAL]
m : Type u → Type u
inst✝¹ : _root_.Monad m
inst✝ : LawfulMonad m
α β : Type u
f : α → β
a : (ofTypeFunctor m ⋙ ofTypeFunctor m).obj α
⊢ ((ofTypeFunctor m ⋙ ofTypeFunctor m).map f ≫ joinM) a = (joinM ≫ (ofTypeFunctor m).map f) a
[PROOFSTEP]
apply joinM_map_map
[GOAL]
m : Type u → Type u
inst✝¹ : _root_.Monad m
inst✝ : LawfulMonad m
α : Type u
a : (ofTypeFunctor m).obj ((ofTypeFunctor m ⋙ ofTypeFunctor m).obj α)
⊢ ((ofTypeFunctor m).map (NatTrans.app (NatTrans.mk (@joinM m inst✝¹)) α) ≫
NatTrans.app (NatTrans.mk (@joinM m inst✝¹)) α)
a =
(NatTrans.app (NatTrans.mk (@joinM m inst✝¹)) ((ofTypeFunctor m).obj α) ≫
NatTrans.app (NatTrans.mk (@joinM m inst✝¹)) α)
a
[PROOFSTEP]
apply joinM_map_joinM
[GOAL]
m : Type u → Type u
inst✝¹ : _root_.Monad m
inst✝ : LawfulMonad m
α : Type u
a : (𝟭 (Type u)).obj ((ofTypeFunctor m).obj α)
⊢ (NatTrans.app (NatTrans.mk (@pure m Applicative.toPure)) ((ofTypeFunctor m).obj α) ≫
NatTrans.app (NatTrans.mk (@joinM m inst✝¹)) α)
a =
𝟙 ((𝟭 (Type u)).obj ((ofTypeFunctor m).obj α)) a
[PROOFSTEP]
apply joinM_pure
[GOAL]
m : Type u → Type u
inst✝¹ : _root_.Monad m
inst✝ : LawfulMonad m
α : Type u
a : (ofTypeFunctor m).obj ((𝟭 (Type u)).obj α)
⊢ ((ofTypeFunctor m).map (NatTrans.app (NatTrans.mk (@pure m Applicative.toPure)) α) ≫
NatTrans.app (NatTrans.mk (@joinM m inst✝¹)) α)
a =
𝟙 ((ofTypeFunctor m).obj ((𝟭 (Type u)).obj α)) a
[PROOFSTEP]
apply joinM_map_pure
[GOAL]
m : Type u → Type u
inst✝¹ : _root_.Monad m
inst✝ : LawfulMonad m
X✝ Y✝ Z✝ : KleisliCat m
f : X✝ ⟶ Y✝
g : Y✝ ⟶ Z✝
⊢ { obj := fun X => X, map := fun {X Y} f => f }.map (f ≫ g) =
{ obj := fun X => X, map := fun {X Y} f => f }.map f ≫ { obj := fun X => X, map := fun {X Y} f => f }.map g
[PROOFSTEP]
funext t
[GOAL]
case h
m : Type u → Type u
inst✝¹ : _root_.Monad m
inst✝ : LawfulMonad m
X✝ Y✝ Z✝ : KleisliCat m
f : X✝ ⟶ Y✝
g : Y✝ ⟶ Z✝
t : { obj := fun X => X, map := fun {X Y} f => f }.obj X✝
⊢ { obj := fun X => X, map := fun {X Y} f => f }.map (f ≫ g) t =
({ obj := fun X => X, map := fun {X Y} f => f }.map f ≫ { obj := fun X => X, map := fun {X Y} f => f }.map g) t
[PROOFSTEP]
change _ = joinM (g <$> (f t))
[GOAL]
case h
m : Type u → Type u
inst✝¹ : _root_.Monad m
inst✝ : LawfulMonad m
X✝ Y✝ Z✝ : KleisliCat m
f : X✝ ⟶ Y✝
g : Y✝ ⟶ Z✝
t : { obj := fun X => X, map := fun {X Y} f => f }.obj X✝
⊢ { obj := fun X => X, map := fun {X Y} f => f }.map (f ≫ g) t = joinM (g <$> f t)
[PROOFSTEP]
simp only [joinM, seq_bind_eq, Function.comp.left_id]
[GOAL]
case h
m : Type u → Type u
inst✝¹ : _root_.Monad m
inst✝ : LawfulMonad m
X✝ Y✝ Z✝ : KleisliCat m
f : X✝ ⟶ Y✝
g : Y✝ ⟶ Z✝
t : { obj := fun X => X, map := fun {X Y} f => f }.obj X✝
⊢ (f ≫ g) t = f t >>= g
[PROOFSTEP]
rfl
[GOAL]
m : Type u → Type u
inst✝¹ : _root_.Monad m
inst✝ : LawfulMonad m
X✝ Y✝ Z✝ : Kleisli (ofTypeMonad m)
f : X✝ ⟶ Y✝
g : Y✝ ⟶ Z✝
⊢ { obj := fun X => X, map := fun {X Y} f => f }.map (f ≫ g) =
{ obj := fun X => X, map := fun {X Y} f => f }.map f ≫ { obj := fun X => X, map := fun {X Y} f => f }.map g
[PROOFSTEP]
letI : _root_.Monad (ofTypeMonad m).obj := show _root_.Monad m from inferInstance
[GOAL]
m : Type u → Type u
inst✝¹ : _root_.Monad m
inst✝ : LawfulMonad m
X✝ Y✝ Z✝ : Kleisli (ofTypeMonad m)
f : X✝ ⟶ Y✝
g : Y✝ ⟶ Z✝
this : _root_.Monad (ofTypeMonad m).toFunctor.toPrefunctor.obj :=
let_fun this := inferInstance;
this
⊢ { obj := fun X => X, map := fun {X Y} f => f }.map (f ≫ g) =
{ obj := fun X => X, map := fun {X Y} f => f }.map f ≫ { obj := fun X => X, map := fun {X Y} f => f }.map g
[PROOFSTEP]
letI : LawfulMonad (ofTypeMonad m).obj := show LawfulMonad m from inferInstance
[GOAL]
m : Type u → Type u
inst✝¹ : _root_.Monad m
inst✝ : LawfulMonad m
X✝ Y✝ Z✝ : Kleisli (ofTypeMonad m)
f : X✝ ⟶ Y✝
g : Y✝ ⟶ Z✝
this✝ : _root_.Monad (ofTypeMonad m).toFunctor.toPrefunctor.obj :=
let_fun this := inferInstance;
this
this : LawfulMonad (ofTypeMonad m).toFunctor.toPrefunctor.obj :=
let_fun this := inferInstance;
this
⊢ { obj := fun X => X, map := fun {X Y} f => f }.map (f ≫ g) =
{ obj := fun X => X, map := fun {X Y} f => f }.map f ≫ { obj := fun X => X, map := fun {X Y} f => f }.map g
[PROOFSTEP]
funext t
[GOAL]
case h
m : Type u → Type u
inst✝¹ : _root_.Monad m
inst✝ : LawfulMonad m
X✝ Y✝ Z✝ : Kleisli (ofTypeMonad m)
f : X✝ ⟶ Y✝
g : Y✝ ⟶ Z✝
this✝ : _root_.Monad (ofTypeMonad m).toFunctor.toPrefunctor.obj :=
let_fun this := inferInstance;
this
this : LawfulMonad (ofTypeMonad m).toFunctor.toPrefunctor.obj :=
let_fun this := inferInstance;
this
t : { obj := fun X => X, map := fun {X Y} f => f }.obj X✝
⊢ { obj := fun X => X, map := fun {X Y} f => f }.map (f ≫ g) t =
({ obj := fun X => X, map := fun {X Y} f => f }.map f ≫ { obj := fun X => X, map := fun {X Y} f => f }.map g) t
[PROOFSTEP]
dsimp
-- Porting note: missing tactic `unfold_projs`, using `change` instead.
[GOAL]
case h
m : Type u → Type u
inst✝¹ : _root_.Monad m
inst✝ : LawfulMonad m
X✝ Y✝ Z✝ : Kleisli (ofTypeMonad m)
f : X✝ ⟶ Y✝
g : Y✝ ⟶ Z✝
this✝ : _root_.Monad (ofTypeMonad m).toFunctor.toPrefunctor.obj :=
let_fun this := inferInstance;
this
this : LawfulMonad (ofTypeMonad m).toFunctor.toPrefunctor.obj :=
let_fun this := inferInstance;
this
t : { obj := fun X => X, map := fun {X Y} f => f }.obj X✝
⊢ (f ≫ g) t = (f ≫ g) t
[PROOFSTEP]
change joinM (g <$> (f t)) = _
[GOAL]
case h
m : Type u → Type u
inst✝¹ : _root_.Monad m
inst✝ : LawfulMonad m
X✝ Y✝ Z✝ : Kleisli (ofTypeMonad m)
f : X✝ ⟶ Y✝
g : Y✝ ⟶ Z✝
this✝ : _root_.Monad (ofTypeMonad m).toFunctor.toPrefunctor.obj :=
let_fun this := inferInstance;
this
this : LawfulMonad (ofTypeMonad m).toFunctor.toPrefunctor.obj :=
let_fun this := inferInstance;
this
t : { obj := fun X => X, map := fun {X Y} f => f }.obj X✝
⊢ joinM (g <$> f t) = (f ≫ g) t
[PROOFSTEP]
simp only [joinM, seq_bind_eq, Function.comp.left_id]
[GOAL]
case h
m : Type u → Type u
inst✝¹ : _root_.Monad m
inst✝ : LawfulMonad m
X✝ Y✝ Z✝ : Kleisli (ofTypeMonad m)
f : X✝ ⟶ Y✝
g : Y✝ ⟶ Z✝
this✝ : _root_.Monad (ofTypeMonad m).toFunctor.toPrefunctor.obj :=
let_fun this := inferInstance;
this
this : LawfulMonad (ofTypeMonad m).toFunctor.toPrefunctor.obj :=
let_fun this := inferInstance;
this
t : { obj := fun X => X, map := fun {X Y} f => f }.obj X✝
⊢ f t >>= g = (f ≫ g) t
[PROOFSTEP]
rfl
[GOAL]
m : Type u → Type u
inst✝¹ : _root_.Monad m
inst✝ : LawfulMonad m
⊢ 𝟭 (KleisliCat m) ≅
Functor.mk { obj := fun X => X, map := fun {X Y} f => f } ⋙
Functor.mk { obj := fun X => X, map := fun {X Y} f => f }
[PROOFSTEP]
refine' NatIso.ofComponents (fun X => Iso.refl X) fun f => _
[GOAL]
m : Type u → Type u
inst✝¹ : _root_.Monad m
inst✝ : LawfulMonad m
X✝ Y✝ : KleisliCat m
f : X✝ ⟶ Y✝
⊢ (𝟭 (KleisliCat m)).map f ≫ ((fun X => Iso.refl X) Y✝).hom =
((fun X => Iso.refl X) X✝).hom ≫
(Functor.mk { obj := fun X => X, map := fun {X Y} f => f } ⋙
Functor.mk { obj := fun X => X, map := fun {X Y} f => f }).map
f
[PROOFSTEP]
change f >=> pure = pure >=> f
[GOAL]
m : Type u → Type u
inst✝¹ : _root_.Monad m
inst✝ : LawfulMonad m
X✝ Y✝ : KleisliCat m
f : X✝ ⟶ Y✝
⊢ f >=> pure = pure >=> f
[PROOFSTEP]
simp [functor_norm]
|
# Copyright (C) 2018-2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import unittest
import numpy as np
import onnx
from generator import generator, generate
import openvino.tools.mo.front.onnx.activation_ext as extractors
from openvino.tools.mo.ops.activation_ops import Elu
from openvino.tools.mo.graph.graph import Node
from openvino.tools.mo.ops.op import Op
from unit_tests.utils.extractors import PB
from unit_tests.utils.graph import build_graph
@generator
class ActivationOpsONNXExtractorTest(unittest.TestCase):
@staticmethod
def _create_node(op_name: str):
pb = onnx.helper.make_node(op_name, ["X"], ["Y"])
graph = build_graph({'node_0': {'pb': pb}}, [])
return Node(graph, 'node_0')
@staticmethod
def _base_attrs(op_name: str):
# reference output Node attributes
return (
dict(
op=op_name,
)
)
def _match(self, out, ref):
for key in ref.keys():
status = out[key] == ref[key]
if type(status) in [list, np.ndarray]:
status = np.all(status)
self.assertTrue(status, 'Mismatch for field {}, observed: {}, expected: {}'.format(key, out[key], ref[key]))
@staticmethod
def _extract(op_name):
node = __class__._create_node(op_name)
getattr(extractors, op_name + 'Extractor').extract(node)
return node.graph.node[node.id]
@generate(*['Abs', 'Acos', 'Asin', 'Atan', 'Acosh', 'Asinh', 'Atanh', 'Cos', 'Cosh', 'Erf', 'Exp', 'Floor', 'Log', 'Not', 'Sigmoid', 'Sin',
'Sinh', 'Tan', 'Tanh'])
def test_default(self, op_name):
ref = self._base_attrs(op_name)
if ref['op'] == 'Not':
ref['op'] = 'LogicalNot'
out = self._extract(op_name)
self._match(out, ref)
@generator
class TestEluONNXExt(unittest.TestCase):
@staticmethod
def _create_elu_node(alpha=1.0):
pb = onnx.helper.make_node(
'Elu',
inputs=['x'],
outputs=['y'],
alpha=alpha
)
node = PB({'pb': pb})
return node
@classmethod
def setUpClass(cls):
Op.registered_ops['Elu'] = Elu
@generate(*[1.0, 2.0, 3.0])
def test_elu_ext(self, alpha):
node = self._create_elu_node(alpha)
extractors.EluExtractor.extract(node)
exp_res = {
'type': 'Elu',
'alpha': alpha,
'infer': Elu.infer
}
for key in exp_res.keys():
self.assertEqual(node[key], exp_res[key])
|
import Data.Maybe
%default total
FromString Int where
fromString x = cast x
test1 : Int
test1 = "42"
test2 : Int
test2 = "abc"
convert : String -> Maybe Bool
convert "True" = Just True
convert "False" = Just False
convert _ = Nothing
fromString : (str : String) -> {auto prf : IsJust (convert str)} -> Bool
fromString str {prf} with (convert str)
fromString str {prf = ItIsJust} | (Just ret) = ret
|
lemma Zfun_ssubst: "eventually (\<lambda>x. f x = g x) F \<Longrightarrow> Zfun g F \<Longrightarrow> Zfun f F" |
\title{Miscellaneous Mathematical Functions}\name{MathFun}\alias{abs}\alias{sqrt}\keyword{math}\description{
\code{abs(x)} computes the absolute value of x, \code{sqrt(x)} computes the
(principal) square root of x, \eqn{\sqrt{x}}.% Details for complex x are below
The naming follows the standard for computer languages such as C or Fortran.
}\usage{
abs(x)
sqrt(x)
}\arguments{
\item{x}{a numeric or \code{\link{complex}} vector or array.}
}\details{
These are \link{internal generic} \link{primitive} functions: methods
can be defined for them individually or via the
\code{\link[=S3groupGeneric]{Math}} group generic. For complex
arguments (and the default method), \code{z}, \code{abs(z) ==
\link{Mod}(z)} and \code{sqrt(z) == z^0.5}.
\code{abs(x)} returns an \code{\link{integer}} vector when \code{x} is
\code{integer} or \code{\link{logical}}.
}\section{S4 methods}{
Both are S4 generic and members of the
\code{\link[=S4groupGeneric]{Math}} group generic.
}\references{
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
\emph{The New S Language}.
Wadsworth & Brooks/Cole.
}\seealso{
\code{\link{Arithmetic}} for simple, \code{\link{log}} for logarithmic,
\code{\link{sin}} for trigonometric, and \code{\link{Special}} for
special mathematical functions.
\sQuote{\link{plotmath}} for the use of \code{sqrt} in plot annotation.
}\examples{
require(stats) # for spline
require(graphics)
xx <- -9:9
plot(xx, sqrt(abs(xx)), col = "red")
lines(spline(xx, sqrt(abs(xx)), n=101), col = "pink")
|
/-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import analysis.normed_space.basic
/-!
# The integers as normed ring
This file contains basic facts about the integers as normed ring.
Recall that `∥n∥` denotes the norm of `n` as real number.
This norm is always nonnegative, so we can bundle the norm together with this fact,
to obtain a term of type `nnreal` (the nonnegative real numbers).
The resulting nonnegative real number is denoted by `∥n∥₊`.
-/
open_locale big_operators
namespace int
lemma nnnorm_coe_units (e : ℤˣ) : ∥(e : ℤ)∥₊ = 1 :=
begin
obtain (rfl|rfl) := int.units_eq_one_or e;
simp only [units.coe_neg_one, units.coe_one, nnnorm_neg, nnnorm_one],
end
lemma norm_coe_units (e : ℤˣ) : ∥(e : ℤ)∥ = 1 :=
by rw [← coe_nnnorm, int.nnnorm_coe_units, nnreal.coe_one]
@[simp] lemma nnnorm_coe_nat (n : ℕ) : ∥(n : ℤ)∥₊ = n := real.nnnorm_coe_nat _
@[simp] lemma norm_coe_nat (n : ℕ) : ∥(n : ℤ)∥ = n := real.norm_coe_nat _
@[simp] lemma to_nat_add_to_nat_neg_eq_nnnorm (n : ℤ) : ↑(n.to_nat) + ↑((-n).to_nat) = ∥n∥₊ :=
by rw [← nat.cast_add, to_nat_add_to_nat_neg_eq_nat_abs, nnreal.coe_nat_abs]
@[simp] lemma to_nat_add_to_nat_neg_eq_norm (n : ℤ) : ↑(n.to_nat) + ↑((-n).to_nat) = ∥n∥ :=
by simpa only [nnreal.coe_nat_cast, nnreal.coe_add]
using congr_arg (coe : _ → ℝ) (to_nat_add_to_nat_neg_eq_nnnorm n)
end int
|
using LinearAlgebra, Plots, Statistics, TaylorSeries, Printf, FileIO
# if !(pwd() in LOAD_PATH) push!(LOAD_PATH, pwd()) end
# using TaylorBigF
path1=realpath(dirname(@__FILE__)*"/..")
include(string(path1,"/src/TaylorBigF.jl"))
# 3.7 System Identification
p=2000;setprecision(p); setrounding(BigFloat, RoundUp);
L=BigFloat("1"); n=BigInt(100); iN=convert(Int64,n);
dx=BigFloat("1")*L/(n-1); x=convert(Array{BigFloat},0:dx:(n-1)*dx)
I=zeros(BigFloat, n, n);for i=1:n I[i,i]=BigFloat("1") end
V=TaylorBigF.calc_Vandermonde(x,n,n)
dV=TaylorBigF.calc_Vandermonde_dot(x,n,n)
ddV=TaylorBigF.calc_Vandermonde_dot_dot(x,n,n)
dddV=TaylorBigF.calc_Vandermonde_dot_dot_dot(x,n,n)
ddddV=TaylorBigF.calc_Vandermonde_dot_dot_dot_dot(x,n,n)
# x=time (t in manuscript) s=space dds=a=F/m
s=x.^BigInt(2)
# plot(x,s)
a=V\s
# plot(a)
# s_dot=s[2:end]-s[1:end-1]
# s_dot_dot=s_dot[2:end]-s_dot[1:end-1]
# VV=[ones(n-2) s[2:end-1] s_dot[1:end-1] s_dot_dot]
# aa=VV\ones(n-2)
# plot(aa)
# ss=V*a;ssd=dV*a;ssdd=ddV*a;
# VV=[ss ssd ssdd ss.^2 ss.*ssd ss.*ssdd ssd.^2 ssd.*ssdd ssdd.^2]
VV=[V*a dV*a ddV*a]
b=VV\ones(n)
# plot(b)
# xi=x[end]+dx:dx:x[end]+100dx
xi=x[end]+BigFloat("9525000000000")dx:dx:x[end]+BigFloat("9525000000010")*dx
Vi=TaylorBigF.calc_Vandermonde(xi,length(xi),n)
IVi=TaylorBigF.calc_Vandermonde_int(xi,length(xi),n)
IIVi=TaylorBigF.calc_Vandermonde_int_int(xi,length(xi),n)
IV=TaylorBigF.calc_Vandermonde_int(x,length(x),n)
IIV=TaylorBigF.calc_Vandermonde_int_int(x,length(x),n)
# t2=(x.^BigInt(2))/BigInt(2)
# mat1=(-t2+b[1]*IIV*a+b[2]*IV*a+b[3]*V*a)
# cc=[s[1] BigInt(1);s[end] BigInt(1)]\[mat1[1,:];mat1[end,:]]
# s_comp=(t2+cc[1].*x+cc[2].*ones(BigFloat,length(x))-b[1]*IIV*a-b[2]*IV*a)/b[3]
# # plot(s_comp)#confirmation
# t2=(xi.^BigInt(2))/BigInt(2)
# s_comp=(t2+cc[1].*xi+cc[2].*ones(BigFloat,length(xi))-b[1]*IIVi*a-b[2]*IVi*a)/b[3] # Equation 5
# plot(x,s,legend=:topleft,xaxis="t",yaxis="s",label="given s")
# plot!(xi,s_comp,label=string("identified s, p=",p))
# # savefig("syst_id.pdf")
t2=(xi.^BigInt(2))/BigInt(2)
s_comp=(t2+-b[1]*IIVi*a-b[2]*IVi*a)/b[3] # Equation 5
# plot(x,s,legend=:topleft,xaxis="t",yaxis="s",label="given s")
# plot!(xi,s_comp,label=string("identified s, p=",p))
# savefig("syst_id.pdf")
s_analyt=xi.^BigInt(2)
error1=s_comp-s_analyt
iok=abs.(error1).<1
xi[iok][end]
|
Kare was predeceased by his first wife Nellie, he is survived by his wife Helene, his children Leena and Donna, grandchildren, great grandchildren, his sister Ingeborg, his great niece Bertine, numerous nieces and nephews in Norway and his friends Jeff and Harry.
He was born in Norway; and came to Canada in 1953. Kare really enjoyed his work at Sproat Lake Division, as well as gardening and smoking fish.
Many thanks to Dr. Lund, the ER and ICU staff for their excellent care.
A Celebration of Life will be held January 25, 2019 at 1pm – Church of Latter-Day Saints, 4815 Compton Road, Port Alberni. |
import Playlean4.Group.Basic
import Playlean4.Group.Subgroup
namespace Group
open Group
section
variable (G : Type) (law : G → G → G) [grp : Group G law]
local infixl:70 " * " => id' law
@[appUnexpander id'] def normal.UnexpandGMul : Lean.PrettyPrinter.Unexpander
| `(id' law $x $y) => `($x * $y)
| _ => throw ()
local notation "one" => grp.one' -- HACK
section
variable {X : Type} (elaw : G → X → X) -- External Law
local infix:70 " • " => id' elaw
@[appUnexpander id'] def unexpandAction : Lean.PrettyPrinter.Unexpander
| `(id' elaw $x $y) => `($x * $y)
| _ => throw ()
class Action where
identity' : ∀ x : X, one • x = x
compat : ∀ (g g' : G) (x : X), (g * g') • x = g • (g' • x)
end
end
section
variable {G : Type} {law : G → G → G} [grp : Group G law]
local infixl:70 " * " => id' law
@[appUnexpander id'] def unexpandGMul : Lean.PrettyPrinter.Unexpander
| `(id' Magma.law G $x $y) => `($x * $y)
| _ => throw ()
local notation "one" => grp.one' -- HACK
local notation g"⁻¹" => grp.inv g
namespace Action
section
variable {X : Type} {elaw : G → X → X} [action : Action G law elaw]
local infix:70 " • " => id' elaw
@[appUnexpander id'] def unexpandAction : Lean.PrettyPrinter.Unexpander
| `(id' elaw $x $y) => `($x • $y)
| _ => throw ()
@[simp]
theorem identity (x : X) : one • x = x := action.identity' x
theorem reverseCompat (g g' : G) (x : X) : g • (g' • x) = (g * g') • x :=
Eq.symm <| action.compat g g' x
end
end Action
end
namespace Action
variable {G : Type} (law : G → G → G) [grp : Group G law]
local infixl:70 " * " => id' law
@[appUnexpander id'] def unexpandGMul : Lean.PrettyPrinter.Unexpander
| `(id' Magma.law G $x $y) => `($x * $y)
| _ => throw ()
local notation "one" => grp.one' -- HACK
local notation g"⁻¹" => grp.inv g
section
variable {X : Type} (elaw : G → X → X) [action : Action G law elaw]
local infix:70 " • " => id' elaw
@[appUnexpander id'] def unexpandAction' : Lean.PrettyPrinter.Unexpander
| `(id' elaw $x $y) => `($x • $y)
| _ => throw ()
def isStable (Y : Set X) : Prop := ∀ y : X, y ∈ Y → ∀ g : G, g • y ∈ Y
def orbit (x : X) : Set X := λ y => ∃ g : G, y = g • x
def memOfSelfOrbit (x : X) : x ∈ orbit elaw x := ⟨ one, by simp ⟩
theorem translatorOfMemOfOrbit {x : X} (y : orbit elaw x) : ∃ g : G, y.val = g • x := y.2
theorem orbitIsStable (x : X) : isStable elaw (orbit elaw x) :=
λ y yIn g => match yIn with
| ⟨ g', h ⟩ => ⟨ (g * g'), by rw [h, ← action.compat] ⟩
def stabilizer (x : X) : Set G := λ g => g • x = x
class Transitive where
singleOrbit : ∀ x y : X, ∃ g : G, y = g • x
end
namespace Remarkable
section
def onSelf : G → G → G := id' law
instance onSelfIsAction : Action G law (@onSelf G law) where
identity' := λ g => by simp [onSelf]; exact grp.oneNeutralLeft _
compat := λ g g' g'' => by simp [onSelf]; exact grp.assoc _ _ _
end
variable {X : Type} (elaw : G → X → X) [action : Action G law elaw]
local infix:70 " • " => id' elaw
@[appUnexpander id'] def unexpandAction : Lean.PrettyPrinter.Unexpander
| `(id' elaw $x $y) => `($x • $y)
| _ => throw ()
section
def liftToSet : (G → Set X → Set X) :=
λ (g : G) => Set.img (λ x => g • x)
instance actionOnSet : Action G law (liftToSet elaw) where
identity' := by
intro x
simp [liftToSet]
funext a
exact propext ⟨ (λ h => match h with
| ⟨ y, h ⟩ => by rw [h.2]; simp; exact h.1),
(λ h => ⟨ a, ⟨ h, by simp ⟩ ⟩) ⟩
compat := by
intro g g' x
simp [liftToSet]
funext a
exact propext ⟨
(λ h => match h with
| ⟨ y, h ⟩ => ⟨ g' • y, by simp only []; exact
(action.compat _ _ _) ▸ ⟨ ⟨ y, ⟨ h.1, rfl ⟩ ⟩, h.2 ⟩ ⟩),
(λ h => match h with
| ⟨ y₁, ⟨ ⟨ y₂, ⟨ y₂In, (h₁ : y₁ = g' • y₂) ⟩ ⟩, (h₂ : a = g • y₁) ⟩ ⟩ =>
⟨ y₂, ⟨ y₂In, by simp only []; exact (action.compat _ _ _).symm ▸ h₁ ▸ h₂ ⟩ ⟩) ⟩
end
section
variable (Y : Set X) (stable : isStable elaw Y)
def restr : G → Y → Y := λ g y => ⟨ g • y.1, stable y.1 y.2 g ⟩
instance restrAction : Action G law (restr elaw Y stable) where
identity' := by
intro y
apply Subtype.eq
simp [restr, id', show elaw one y = y from action.identity y]
compat := by
intro g g' y
apply Subtype.eq
simp [restr, id',
show elaw (law g g') y = elaw g (elaw g' y) from action.compat _ _ _]
end
section
variable (x₀ : X)
def onOrbit : G → orbit elaw x₀ → orbit elaw x₀ :=
restr elaw (orbit elaw x₀) (orbitIsStable law elaw x₀)
instance onOrbitTransitive : Transitive (onOrbit law elaw x₀) where
singleOrbit := by
intro ⟨ x, xIn ⟩ ⟨ y, yIn ⟩
match xIn, yIn with
| ⟨ g₁, xIs ⟩, ⟨ g₂, yIs ⟩ =>
suffices p₂ : y = (g₂ * g₁⁻¹) • x
from ⟨ (g₂ * g₁⁻¹), Subtype.eq p₂ ⟩
simp [xIs, yIs, action.reverseCompat]
end
section
def leftTranslation : G → G → G := λ g g' => g * g'
instance leftTranslationAction (g : G) : Action G law (leftTranslation law) where
identity' := λ x => by
simp [id', leftTranslation]
exact @oneNeutralLeft G law _ _
compat := λ g g' g'' => by
simp [id', leftTranslation]
exact @assoc G law _ _ _ _
def conjugation : G → G → G := λ g g' => g * g' * g⁻¹
instance conjugationAction (g : G) : Action G law (conjugation law) where
identity' := λ x => by
suffices one * x * one⁻¹ = x by exact this
simp
compat := λ g g' x => by
suffices ((g * g') * x * (g * g')⁻¹ = g * (g' * x * g'⁻¹) * g⁻¹) by exact this
simp
end
end Remarkable
end Action
end Group
|
[STATEMENT]
lemma a_idem [simp]: "ad x \<cdot> ad x = ad x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. ad x \<cdot> ad x = ad x
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. ad x \<cdot> ad x = ad x
[PROOF STEP]
have "ad x = (d x + ad x ) \<cdot> ad x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. ad x = (d x + ad x) \<cdot> ad x
[PROOF STEP]
by (simp add: ans_d_def)
[PROOF STATE]
proof (state)
this:
ad x = (d x + ad x) \<cdot> ad x
goal (1 subgoal):
1. ad x \<cdot> ad x = ad x
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
ad x = (d x + ad x) \<cdot> ad x
goal (1 subgoal):
1. ad x \<cdot> ad x = ad x
[PROOF STEP]
have "... = d x \<cdot> ad x + ad x \<cdot> ad x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (d x + ad x) \<cdot> ad x = d x \<cdot> ad x + ad x \<cdot> ad x
[PROOF STEP]
using distrib_right'
[PROOF STATE]
proof (prove)
using this:
(?x + ?y) \<cdot> ?z = ?x \<cdot> ?z + ?y \<cdot> ?z
goal (1 subgoal):
1. (d x + ad x) \<cdot> ad x = d x \<cdot> ad x + ad x \<cdot> ad x
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
(d x + ad x) \<cdot> ad x = d x \<cdot> ad x + ad x \<cdot> ad x
goal (1 subgoal):
1. ad x \<cdot> ad x = ad x
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
ad x = d x \<cdot> ad x + ad x \<cdot> ad x
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
ad x = d x \<cdot> ad x + ad x \<cdot> ad x
goal (1 subgoal):
1. ad x \<cdot> ad x = ad x
[PROOF STEP]
by (simp add: ans_d_def)
[PROOF STATE]
proof (state)
this:
ad x \<cdot> ad x = ad x
goal:
No subgoals!
[PROOF STEP]
qed |
[STATEMENT]
lemma trans_less_add1_hmset: "i < j \<Longrightarrow> i < j + m" for i j m :: hmultiset
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. i < j \<Longrightarrow> i < j + m
[PROOF STEP]
by (metis add_increasing2 leD le_less not_gr_zero_hmset) |
SUBROUTINE DFPSAV(TOTIME,XPARAM,GD,XLAST,FUNCT1,MDFP,XDFP)
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
INCLUDE 'SIZES'
DIMENSION XPARAM(*), GD(*), XLAST(*), MDFP(9),XDFP(9)
**********************************************************************
*
* DFPSAV STORES AND RESTORES DATA USED IN THE D-F-P GEOMETRY
* OPTIMISATION.
*
* ON INPUT TOTIME = TOTAL CPU TIME ELAPSED DURING THE CALCULATION.
* XPARAM = CURRENT VALUE OF PARAMETERS.
* GD = OLD GRADIENT.
* XLAST = OLD VALUE OF PARAMETERS.
* FUNCT1 = CURRENT VALUE OF HEAT OF FORMATION.
* MDFP = INTEGER CONSTANTS USED IN D-F-P.
* XDFP = REAL CONSTANTS USED IN D-F-P.
* MDFP(9)= 1 FOR DUMP, 0 FOR RESTORE.
**********************************************************************
COMMON /KEYWRD/ KEYWRD
COMMON /GRADNT/ GRAD(MAXPAR),GNORM
COMMON /GEOVAR/ NVAR,LOC(2,MAXPAR), IDUMY, DUMY(MAXPAR)
COMMON /DENSTY/ P(MPACK), PA(MPACK), PB(MPACK)
COMMON /ALPARM/ ALPARM(3,MAXPAR),X0, X1, X2, ILOOP
COMMON /PPARAM/ CURRT
COMMON /GPARAM/ CURRT1,CURRT2
COMMON /PROFIL/ PROFIL
COMMON /SURF / SURF
COMMON /KLOOP / KLOOP
COMMON /IJLP / IJLP, ILP, JLP, JLP1, IONE
COMMON /REACTN/ STEP, GEOA(3,NUMATM), GEOVEC(3,NUMATM),CALCST
COMMON /GEOM / GEO(3,NUMATM)
COMMON /GEOKST/ NATOMS,LABELS(NUMATM),
1 NA(NUMATM),NB(NUMATM),NC(NUMATM)
COMMON /ELEMTS/ ELEMNT(107)
CHARACTER KOMENT*81, TITLE*81
COMMON /TITLES/ KOMENT,TITLE
COMMON /PATH / LATOM,LPARAM,REACT(200)
COMMON /MESH / LATOM1,LPARA1,LATOM2,LPARA2
COMMON /MOLKST/ NUMAT,NAT(NUMATM),NFIRST(NUMATM),NMIDLE(NUMATM),
1 NLAST(NUMATM), NORBS, NELECS,NALPHA,NBETA,
2 NCLOSE,NOPEN,NDUMY,FRACT
COMMON /FMATRX/ HESINV(MAXPAR**2+MAXPAR*3+1), IDUMY2(4)
COMMON /ERRFN / ERRFN(MAXPAR), AICORR(MAXPAR)
COMMON /NUMCAL/ NUMCAL
DIMENSION COORD(3,NUMATM)
DIMENSION PROFIL(200)
DIMENSION SURF(23*23)
CHARACTER ELEMNT*2, KEYWRD*241, GETNAM*80
SAVE FIRST
LOGICAL FIRST, INTXYZ
DATA ICALCN/0/
FIRST=(ICALCN.EQ.NUMCAL)
OPEN(UNIT=9,FILE=GETNAM('FOR009')
+ ,STATUS='UNKNOWN',FORM='UNFORMATTED')
REWIND 9
OPEN(UNIT=10,FILE=GETNAM('FOR010')
+ ,STATUS='UNKNOWN',FORM='UNFORMATTED')
REWIND 10
IR=9
IF(MDFP(9) .NE. 0) THEN
IF(MDFP(9) .EQ. 1) THEN
WRITE(6,'(//10X,''- - - - - - - TIME UP - - - - - - -'',//)'
1)
IF(INDEX(KEYWRD,'SADDLE') .NE. 0) THEN
WRITE(6,'(//10X,'' NO RESTART EXISTS FOR SADDLE'',//
1 10X,'' HERE IS A DATA-FILE FILES THAT MIGHT BE SUITABLE'',/
2 10X,'' FOR RESTARTING THE CALCULATION'',///)')
WRITE(6,'(A)')KEYWRD,KOMENT,TITLE
INTXYZ=(NA(1).EQ.0)
DO 30 ILOOP=1,2
IF(INTXYZ)THEN
GEO(2,1)=0.D0
GEO(3,1)=0.D0
GEO(1,1)=0.D0
GEO(2,2)=0.D0
GEO(3,2)=0.D0
GEO(3,3)=0.D0
DO 10 I=1,NATOMS
DO 10 J=1,3
10 COORD(J,I)=GEO(J,I)
ELSE
CALL XYZINT(GEO,NUMAT,NA,NB,NC,1.D0,COORD)
ENDIF
CALL GEOUT(-6)
DO 20 I=1,NATOMS
DO 20 J=1,3
20 GEO(J,I)=GEOA(J,I)
NA(1)=99
30 CONTINUE
WRITE(6,'(///10X,''CALCULATION TERMINATED HERE'')')
STOP
ENDIF
WRITE(6,'(//10X,'' - THE CALCULATION IS BEING DUMPED TO DISK
1'', /10X,'' RESTART IT USING THE MAGIC WORD "RESTART"'')')
WRITE(6,'(//10X,''CURRENT VALUE OF HEAT OF FORMATION =''
1 ,F12.6)')FUNCT1
ENDIF
IF(MDFP(9) .EQ. 1)THEN
IF(NA(1) .EQ. 99) THEN
C
C CONVERT FROM CARTESIAN COORDINATES TO INTERNAL
C
DO 40 I=1,NATOMS
DO 40 J=1,3
40 COORD(J,I)=GEO(J,I)
CALL XYZINT(COORD,NUMAT,NA,NB,NC,1.D0,GEO)
ENDIF
GEO(2,1)=0.D0
GEO(3,1)=0.D0
GEO(1,1)=0.D0
GEO(2,2)=0.D0
GEO(3,2)=0.D0
GEO(3,3)=0.D0
NA(1)=0
CALL GEOUT(6)
ENDIF
WRITE(IR)MDFP,XDFP,TOTIME,FUNCT1
WRITE(IR)(XPARAM(I),I=1,NVAR),(GD(I),I=1,NVAR)
WRITE(IR)(XLAST(I),I=1,NVAR),(GRAD(I),I=1,NVAR)
LINEAR=(NVAR*(NVAR+1))/2
WRITE(IR)(HESINV(I),I=1,LINEAR)
LINEAR=(NORBS*(NORBS+1))/2
WRITE(10)(PA(I),I=1,LINEAR)
IF(NALPHA.NE.0)WRITE(10)(PB(I),I=1,LINEAR)
IF(LATOM.NE.0)THEN
IF(INDEX(KEYWRD,'STEP').NE.0)THEN
WRITE(IR) KLOOP
WRITE(IR) CURRT
WRITE(IR) (PROFIL(I),I=1,KLOOP)
ELSE
WRITE(IR)((ALPARM(J,I),J=1,3),I=1,NVAR)
WRITE(IR)ILOOP,X0, X1, X2
ENDIF
ENDIF
IF(INDEX(KEYWRD,'STEP1').NE.0)THEN
WRITE(IR)IJLP, ILP,JLP,JLP1,IONE
WRITE(IR) CURRT1,CURRT2
WRITE(IR) (SURF(I),I=1,IJLP)
ENDIF
WRITE(IR)(ERRFN(I),I=1,NVAR)
CLOSE (9)
CLOSE (10)
ELSE
IF (FIRST) WRITE(6,'(//10X,'' RESTORING DATA FROM DISK''/)')
READ(IR,END=60,ERR=60)MDFP,XDFP,TOTIME,FUNCT1
IF (FIRST) WRITE(6,'(10X,''FUNCTION ='',F13.6//)')FUNCT1
READ(IR)(XPARAM(I),I=1,NVAR),(GD(I),I=1,NVAR)
READ(IR)(XLAST(I),I=1,NVAR),(GRAD(I),I=1,NVAR)
LINEAR=(NVAR*(NVAR+1))/2
READ(IR)(HESINV(I),I=1,LINEAR)
LINEAR=(NORBS*(NORBS+1))/2
READ(10)(PA(I),I=1,LINEAR)
IF(NALPHA.NE.0)READ(10)(PB(I),I=1,LINEAR)
IF(LATOM.NE.0)THEN
IF(INDEX(KEYWRD,'STEP').NE.0)THEN
READ(IR) KLOOP
READ(IR) CURRT
READ(IR) (PROFIL(I),I=1,KLOOP)
ELSE
READ(IR)((ALPARM(J,I),J=1,3),I=1,NVAR)
READ(IR)ILOOP,X0, X1, X2
ENDIF
ENDIF
IF(INDEX(KEYWRD,'STEP1').NE.0)THEN
READ(IR)IJLP, ILP,JLP,JLP1,IONE
READ(IR) CURRT1,CURRT2
READ(IR) (SURF(I),I=1,IJLP)
ENDIF
READ(IR)(ERRFN(I),I=1,NVAR)
50 FIRST=.FALSE.
RETURN
60 WRITE(6,'(//10X,''NO RESTART FILE EXISTS!'')')
STOP
ENDIF
END
|
import os
from h5py import File
from tqdm import tqdm
from datetime import datetime
import numpy as np
from pynwb import NWBFile, NWBHDF5IO
from pynwb.behavior import SpatialSeries, Position
from to_nwb.utils import check_module
import sys
def read_ragged_array(struct, i=None, gid=None):
"""Read item x from ragged array STRUCT
Parameters
----------
struct: h5py.Group
gid: int (optional)
i: int (optional)
Returns
-------
np.array
"""
if i is not None and gid is not None:
raise ValueError('only i or gid can be supplied')
if i is None and gid is None:
return np.array([read_ragged_array(struct, i)
for i in tqdm(struct['Cell Index'][:])])
if gid:
if 'Cell Index' in struct:
i = np.argmax(struct['Cell Index'][:] == gid)[0]
else:
i = gid
i = int(i)
start = struct['Attribute Pointer'][i]
stop = struct['Attribute Pointer'][i+1]
return struct['Attribute Value'][start:stop].astype(float)
def get_neuroh5_cell_data(f):
"""
Parameters
----------
f: h5py.File
Yields
-------
dict
"""
labs = f['H5Types']['Population labels']
population_table = f['H5Types']['Populations']
cell_types_order = {labs.id.get_member_value(i): labs.id.get_member_name(i)
for i in range(labs.id.get_nmembers())}
start_dict = {pop_name.decode(): population_table['Start'][population_table['Population'] == pop_int][0]
for pop_int, pop_name in cell_types_order.items()}
pops = f['Populations']
for cell_type in pops:
spike_struct = pops[cell_type]['Vector Stimulus 100']['spiketrain']
for pop_id in spike_struct['Cell Index']:
spike_times = read_ragged_array(spike_struct, pop_id) / 1000
gid = pop_id + start_dict[cell_type]
yield {'id': int(gid), 'pop_id': int(pop_id), 'spike_times': spike_times, 'cell_type': cell_type}
def write_position(nwbfile, f, name='Trajectory 100'):
"""
Parameters
----------
nwbfile: pynwb.NWBFile
f: h5py.File
name: str (optional)
Returns
-------
pynwb.core.ProcessingModule
"""
obj = f[name]
behavior_mod = check_module(nwbfile, 'behavior')
spatial_series = SpatialSeries('Position', data=np.array([obj['x'], obj['y']]).T,
reference_frame='NA',
conversion=1 / 100.,
resolution=np.nan,
rate=float(1 / np.diff(obj['t'][:2]) * 1000))
behavior_mod.add_data_interface(Position(spatial_series))
return behavior_mod
def neuroh5_to_nwb(fpath, out_path=None):
"""
Parameters
----------
fpath: str | path
path of neuroh5 file
out_path: str (optional)
where the NWB file is saved
"""
if out_path is None:
out_path = fpath[:-3] + '.nwb'
fname = os.path.split(fpath)[1]
identifier = fname[:-4]
nwbfile = NWBFile(session_description='session_description',
identifier=identifier,
session_start_time=datetime.now().astimezone(),
institution='Stanford University', lab='Soltesz')
with File(fpath, 'r') as f:
write_position(nwbfile, f)
nwbfile.add_unit_column('cell_type', 'cell type')
nwbfile.add_unit_column('pop_id', 'cell number within population')
for unit_dict in tqdm(get_neuroh5_cell_data(f),
total=38000+34000,
desc='reading cell data'):
nwbfile.add_unit(**unit_dict)
with NWBHDF5IO(out_path, 'w') as io:
io.write(nwbfile)
def main(argv):
neuroh5_to_nwb('/Users/bendichter/Desktop/Soltesz/data/DG_PP_spiketrain_12142018.h5')
if __name__ == "__main__":
main(sys.argv[1:])
|
lemma continuous_diff [continuous_intros]: fixes f g :: "'a::t2_space \<Rightarrow> 'b::topological_group_add" shows "continuous F f \<Longrightarrow> continuous F g \<Longrightarrow> continuous F (\<lambda>x. f x - g x)" |
[STATEMENT]
lemma (in Semilat) pp_ub1':
assumes S: "snd`set S \<subseteq> A"
assumes y: "y \<in> A" and ab: "(a, b) \<in> set S"
shows "b \<sqsubseteq>\<^sub>r map snd [(p', t') \<leftarrow> S . p' = a] \<Squnion>\<^bsub>f\<^esub> y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. b \<sqsubseteq>\<^bsub>r\<^esub> map snd (filter (\<lambda>(p', t'). p' = a) S) \<Squnion>\<^bsub>f\<^esub> y
[PROOF STEP]
(*<*)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. b \<sqsubseteq>\<^bsub>r\<^esub> map snd (filter (\<lambda>(p', t'). p' = a) S) \<Squnion>\<^bsub>f\<^esub> y
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. b \<sqsubseteq>\<^bsub>r\<^esub> map snd (filter (\<lambda>(p', t'). p' = a) S) \<Squnion>\<^bsub>f\<^esub> y
[PROOF STEP]
from S
[PROOF STATE]
proof (chain)
picking this:
snd ` set S \<subseteq> A
[PROOF STEP]
have "\<forall>(x,y) \<in> set S. y \<in> A"
[PROOF STATE]
proof (prove)
using this:
snd ` set S \<subseteq> A
goal (1 subgoal):
1. \<forall>(x, y)\<in>set S. y \<in> A
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<forall>(x, y)\<in>set S. y \<in> A
goal (1 subgoal):
1. b \<sqsubseteq>\<^bsub>r\<^esub> map snd (filter (\<lambda>(p', t'). p' = a) S) \<Squnion>\<^bsub>f\<^esub> y
[PROOF STEP]
with Semilat_axioms
[PROOF STATE]
proof (chain)
picking this:
Semilat A r f
\<forall>(x, y)\<in>set S. y \<in> A
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
Semilat A r f
\<forall>(x, y)\<in>set S. y \<in> A
goal (1 subgoal):
1. b \<sqsubseteq>\<^bsub>r\<^esub> map snd (filter (\<lambda>(p', t'). p' = a) S) \<Squnion>\<^bsub>f\<^esub> y
[PROOF STEP]
using y ab
[PROOF STATE]
proof (prove)
using this:
Semilat A r f
\<forall>(x, y)\<in>set S. y \<in> A
y \<in> A
(a, b) \<in> set S
goal (1 subgoal):
1. b \<sqsubseteq>\<^bsub>r\<^esub> map snd (filter (\<lambda>(p', t'). p' = a) S) \<Squnion>\<^bsub>f\<^esub> y
[PROOF STEP]
by (rule ub1')
[PROOF STATE]
proof (state)
this:
b \<sqsubseteq>\<^bsub>r\<^esub> map snd (filter (\<lambda>(p', t'). p' = a) S) \<Squnion>\<^bsub>f\<^esub> y
goal:
No subgoals!
[PROOF STEP]
qed |
State Before: α : Type u
inst✝² : UniformSpace α
β : Type v
γ : Type w
inst✝¹ : UniformSpace β
inst✝ : UniformSpace γ
⊢ (Filter.lift' (Filter.lift' (𝓤 α) gen) fun s => s ○ s) = Filter.lift' (𝓤 α) fun s => gen s ○ gen s State After: case hg
α : Type u
inst✝² : UniformSpace α
β : Type v
γ : Type w
inst✝¹ : UniformSpace β
inst✝ : UniformSpace γ
⊢ Monotone gen
case hh
α : Type u
inst✝² : UniformSpace α
β : Type v
γ : Type w
inst✝¹ : UniformSpace β
inst✝ : UniformSpace γ
⊢ Monotone fun s => s ○ s Tactic: rw [lift'_lift'_assoc] State Before: case hg
α : Type u
inst✝² : UniformSpace α
β : Type v
γ : Type w
inst✝¹ : UniformSpace β
inst✝ : UniformSpace γ
⊢ Monotone gen State After: no goals Tactic: exact monotone_gen State Before: case hh
α : Type u
inst✝² : UniformSpace α
β : Type v
γ : Type w
inst✝¹ : UniformSpace β
inst✝ : UniformSpace γ
⊢ Monotone fun s => s ○ s State After: no goals Tactic: exact monotone_id.compRel monotone_id State Before: α : Type u
inst✝² : UniformSpace α
β : Type v
γ : Type w
inst✝¹ : UniformSpace β
inst✝ : UniformSpace γ
⊢ (Filter.lift' (𝓤 α) fun s => gen (s ○ s)) = Filter.lift' (Filter.lift' (𝓤 α) fun s => s ○ s) gen State After: case hg
α : Type u
inst✝² : UniformSpace α
β : Type v
γ : Type w
inst✝¹ : UniformSpace β
inst✝ : UniformSpace γ
⊢ Monotone fun s => s ○ s
case hh
α : Type u
inst✝² : UniformSpace α
β : Type v
γ : Type w
inst✝¹ : UniformSpace β
inst✝ : UniformSpace γ
⊢ Monotone gen Tactic: rw [lift'_lift'_assoc] State Before: case hg
α : Type u
inst✝² : UniformSpace α
β : Type v
γ : Type w
inst✝¹ : UniformSpace β
inst✝ : UniformSpace γ
⊢ Monotone fun s => s ○ s State After: no goals Tactic: exact monotone_id.compRel monotone_id State Before: case hh
α : Type u
inst✝² : UniformSpace α
β : Type v
γ : Type w
inst✝¹ : UniformSpace β
inst✝ : UniformSpace γ
⊢ Monotone gen State After: no goals Tactic: exact monotone_gen |
module Test.Spec
import Refined
import Props.Util
import Props.Char
import Props.String
import Props.Nat
%access public export
zeroIsDigit : Refined Char Digit
zeroIsDigit = '0'
upperAIsLetter : Refined Char Letter
upperAIsLetter = 'A'
lowerAIsAlpha : Refined Char AlphaNumeric
lowerAIsAlpha = 'a'
upperAIsAlpha : Refined Char AlphaNumeric
upperAIsAlpha = 'A'
zeroIsAlpha : Refined Char AlphaNumeric
zeroIsAlpha = '0'
-- TODO: Proof these using Void
--dollarIsNotAlpha : Refined Char AlphaNumeric -> Void
--dollarIsNotAlpha = '$'
blankIsWhitespace : Refined Char Whitespace
blankIsWhitespace = ' '
textIsNonEmpty : Refined String NonEmpty
textIsNonEmpty = "text"
-- FIXME: Somehow implicit conversion doesnt work here
oneIsGreaterThanZero : Refined Nat (Greater Z)
oneIsGreaterThanZero = toRefined $ S Z
--zeroIsGreaterThanZero : Refined Nat (Greater Z)
--zeroIsGreaterThanZero = toRefined $ Z
oneIsGreaterEqualOne : Refined Nat $ GreaterEqual $ S Z
oneIsGreaterEqualOne = toRefined $ S Z
zeroIsLessThanOne : Refined Nat (Less (S Z))
zeroIsLessThanOne = toRefined Z
--zeroIsLessThanZero : Refined Nat (Less Z)
--zeroIsLessThanZero = toRefined Z
testMe : IO()
testMe = putStrLn("Passed")
|
Anxiety is a word we use to describe feelings of unease, worry and fear. It incorporates both the emotions and the physical sensations we might experience when we are worried or nervous about something. Although we usually find it unpleasant, anxiety is related to the ‘fight or flight’ response – our normal biological reaction to feeling threatened.
In situations like these it’s understandable to have worries about how you will perform, or what the outcome will be. For a short time you might even find it hard to sleep, eat or concentrate. Then usually, after a short while or when the situation has passed, the feelings of worry stop.
Then when you feel the danger has passed, your body releases other hormones to help your muscles relax, which may cause you to shake.
This is commonly called the ‘fight or flight’ response – it’s something that happens automatically in our bodies, and we have no control over it. In modern society we don’t usually face situations where we need to physically fight or flee from danger, but our biological response to feeling threatened is still the same.
Because anxiety is a normal human experience, it’s sometimes hard to know when it’s becoming a problem for you – but if your feelings of anxiety are very strong, or last for a long time, it can be overwhelming.
You might find that you’re worrying all the time, perhaps about things that are a regular part of everyday life, or about things that aren’t likely to happen – or even worrying about worrying.
You might regularly experience unpleasant physical and psychological effects of anxiety, and maybe panic attacks.
Depending on the kind of problems you experience, you might be given a diagnosis of a specific anxiety disorder.
You can always talk to someone in one of the Liverpool CAMHS Community Plus Hubs. |
Require Import Logic.GeneralLogic.Base.
Require Import Logic.MinimumLogic.Syntax.
Require Import Logic.MinimumLogic.Semantics.Trivial.
Require Import Logic.PropositionalLogic.Syntax.
Local Open Scope logic_base.
Local Open Scope syntax.
Import PropositionalLanguageNotation.
Module Semantics.
Definition andp {model: Type} (X: Ensemble model) (Y: Ensemble model): Ensemble model :=
fun m => X m /\ Y m.
Definition orp {model: Type} (X: Ensemble model) (Y: Ensemble model): Ensemble model :=
fun m => X m \/ Y m.
Definition falsep {model: Type}: Ensemble model := fun m => False.
End Semantics.
Class TrivialPropositionalSemantics (L: Language) {minL: MinimumLanguage L} {pL: PropositionalLanguage L} (MD: Model) (SM: Semantics L MD): Type := {
denote_andp: forall x y, Same_set _ (denotation (x && y)) (Semantics.andp (denotation x) (denotation y));
denote_orp: forall x y, Same_set _ (denotation (x || y)) (Semantics.orp (denotation x) (denotation y));
denote_falsep: Same_set _ (denotation FF) Semantics.falsep
}.
Section Trivial.
Context {L: Language}
{minL: MinimumLanguage L}
{pL: PropositionalLanguage L}
{MD: Model}
{SM: Semantics L MD}
{tpSM: TrivialPropositionalSemantics L MD SM}.
Lemma sat_andp: forall m x y, m |= x && y <-> (m |= x /\ m |= y).
Proof.
intros; simpl.
unfold satisfies.
destruct (denote_andp x y).
split; auto; [apply H | apply H0].
Qed.
Lemma sat_orp: forall m x y, m |= x || y <-> (m |= x \/ m |= y).
Proof.
intros; simpl.
unfold satisfies.
destruct (denote_orp x y).
split; auto; [apply H | apply H0].
Qed.
Lemma sat_falsep: forall m, m |= FF <-> False.
Proof.
intros; simpl.
unfold satisfies.
destruct denote_falsep.
split; auto; [apply H | apply H0].
Qed.
End Trivial.
|
Address(Beech Lane) is a residential street, in Central Davis, one block in length running from West 14th Street to just past Mills Drive as a tiny Culdesacs culdesac. It is part of the Davis Senior High School Residential Parking Permits Preferential Parking District, which uses the S permit as of November 2004.
|
Require Import PeanoNat.
Local Open Scope nat_scope.
Inductive btree : Type :=
| empty : btree
| node : btree->nat->btree->btree.
Definition tree :=node (node empty 7 (node empty 2 empty)) 1 (node(node empty 10 empty)8 empty).
(*OR(orb) - AND(andb)*)
Fixpoint searchBT(t:btree) (value:nat) : bool :=
match t with
|empty =>false
|node l v r => if v=? value
then true
else orb (searchBT l value) (searchBT r value)
end.
Compute (searchBT tree 10).
Compute(searchBT tree 24).
(*Oglinditul unui arbore binar de cautare*)
Fixpoint mirroredBT(t:btree):btree:=
match t with
| empty =>empty
| node l v r => node (mirroredBT r) v (mirroredBT l)
end.
(*Verificare arbore binar de cautare*)
Compute (mirroredBT tree).
(*Valoare unui nod*)
Fixpoint returnNodeValue(t :btree):nat :=
match t with
|empty=>0
|node l v r =>v
end.
(*Este arbore binar de cautare?*)
Fixpoint isSearchBT(t:btree):bool :=
match t with
| empty => true
| node empty v empty => true
| node l v empty =>(returnNodeValue l) <?v
| node empty v r => v <? (returnNodeValue r)
| node l v r =>andb ((returnNodeValue l)<?v) (v<?(returnNodeValue r))
end.
Compute (isSearchBT tree).
Compute (isSearchBT (node (node empty 3 empty) 2 (node empty 4 empty ))).
(*Cautare intr-un arbore binar de cautare*)
Fixpoint searchInBST(t:btree) (n:nat):bool :=
match t with
|empty => false
|node l v r => if n=?v
then true
else if n<?v
then searchInBST l n
else searchInBST r n
end.
(*Inaltime unui arbore binar*)
Compute searchInBST (tree) (1).
Fixpoint lengthSearchBT(t:btree):nat :=
match t with
| empty=>0
| node l v r => max (lengthSearchBT l) (lengthSearchBT r ) + 1
end.
Compute(lengthSearchBT tree).
|
{-
Finitely presented algebras.
An R-algebra A is finitely presented, if there merely is an exact sequence
of R-modules:
(f₁,⋯,fₘ) → R[X₁,⋯,Xₙ] → A → 0
(where f₁,⋯,fₘ ∈ R[X₁,⋯,Xₙ])
-}
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommAlgebra.FPAlgebra where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Structure
open import Cubical.Data.FinData
open import Cubical.Data.Nat
open import Cubical.Data.Vec
open import Cubical.Data.Sigma
open import Cubical.Data.Empty
open import Cubical.HITs.PropositionalTruncation
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.FGIdeal using (inclOfFGIdeal)
open import Cubical.Algebra.CommAlgebra
open import Cubical.Algebra.CommAlgebra.FreeCommAlgebra
renaming (inducedHom to freeInducedHom)
open import Cubical.Algebra.CommAlgebra.QuotientAlgebra
renaming (inducedHom to quotientInducedHom)
open import Cubical.Algebra.CommAlgebra.Ideal
open import Cubical.Algebra.CommAlgebra.FGIdeal
open import Cubical.Algebra.CommAlgebra.Instances.Initial
open import Cubical.Algebra.CommAlgebra.Instances.Unit
renaming (UnitCommAlgebra to TerminalCAlg)
open import Cubical.Algebra.CommAlgebra.Kernel
open import Cubical.Algebra.Algebra.Properties
open import Cubical.Algebra.Algebra
private
variable
ℓ : Level
module _ {R : CommRing ℓ} where
open Construction using (var)
Polynomials : (n : ℕ) → CommAlgebra R ℓ
Polynomials n = R [ Fin n ]
evPoly : {n : ℕ} (A : CommAlgebra R ℓ) → ⟨ Polynomials n ⟩ → FinVec ⟨ A ⟩ n → ⟨ A ⟩
evPoly A P values = fst (freeInducedHom A values) P
evPolyPoly : {n : ℕ} (P : ⟨ Polynomials n ⟩) → evPoly (Polynomials n) P var ≡ P
evPolyPoly {n = n} P = cong (λ u → fst u P) (inducedHomVar R (Fin n))
evPolyHomomorphic : {n : ℕ} (A B : CommAlgebra R ℓ) (f : CommAlgebraHom A B)
→ (P : ⟨ Polynomials n ⟩) → (values : FinVec ⟨ A ⟩ n)
→ (fst f) (evPoly A P values) ≡ evPoly B P (fst f ∘ values)
evPolyHomomorphic A B f P values =
(fst f) (evPoly A P values) ≡⟨ refl ⟩
(fst f) (fst (freeInducedHom A values) P) ≡⟨ refl ⟩
fst (f ∘a freeInducedHom A values) P ≡⟨ cong (λ u → fst u P) (natIndHomR f values) ⟩
fst (freeInducedHom B (fst f ∘ values)) P ≡⟨ refl ⟩
evPoly B P (fst f ∘ values) ∎
where open AlgebraHoms
module _ {m : ℕ} (n : ℕ) (relation : FinVec ⟨ Polynomials n ⟩ m) where
open CommAlgebraStr using (0a)
open Cubical.Algebra.Algebra.Properties.AlgebraHoms
relationsIdeal = generatedIdeal (Polynomials n) relation
abstract
{-
The following definitions are abstract because of type checking speed
problems - complete unfolding of FPAlgebra is triggered otherwise.
This also means, the where blocks contain more type declarations than usual.
-}
FPAlgebra : CommAlgebra R ℓ
FPAlgebra = Polynomials n / relationsIdeal
modRelations : CommAlgebraHom (Polynomials n) (Polynomials n / relationsIdeal)
modRelations = quotientMap (Polynomials n) relationsIdeal
generator : (i : Fin n) → ⟨ FPAlgebra ⟩
generator = fst modRelations ∘ var
relationsHold : (i : Fin m) → evPoly FPAlgebra (relation i) generator ≡ 0a (snd FPAlgebra)
relationsHold i =
evPoly FPAlgebra (relation i) generator
≡⟨ sym (evPolyHomomorphic (Polynomials n) FPAlgebra modRelations (relation i) var) ⟩
fst modRelations (evPoly (Polynomials n) (relation i) var)
≡⟨ cong (λ u → fst modRelations u) (evPolyPoly (relation i)) ⟩
fst modRelations (relation i)
≡⟨ isZeroFromIdeal {R = R}
{A = (Polynomials n)}
{I = relationsIdeal}
(relation i)
(incInIdeal (Polynomials n) relation i ) ⟩
0a (snd FPAlgebra) ∎
inducedHom :
(A : CommAlgebra R ℓ)
(values : FinVec ⟨ A ⟩ n)
(relationsHold : (i : Fin m) → evPoly A (relation i) values ≡ 0a (snd A))
→ CommAlgebraHom FPAlgebra A
inducedHom A values relationsHold =
quotientInducedHom
(Polynomials n)
relationsIdeal
A
freeHom
isInKernel
where
freeHom : CommAlgebraHom (Polynomials n) A
freeHom = freeInducedHom A values
isInKernel : fst (generatedIdeal (Polynomials n) relation)
⊆ fst (kernel (Polynomials n) A freeHom)
isInKernel = inclOfFGIdeal
(CommAlgebra→CommRing (Polynomials n))
relation
(kernel (Polynomials n) A freeHom)
relationsHold
inducedHomOnGenerators :
(A : CommAlgebra R ℓ)
(values : FinVec ⟨ A ⟩ n)
(relationsHold : (i : Fin m) → evPoly A (relation i) values ≡ 0a (snd A))
(i : Fin n)
→ fst (inducedHom A values relationsHold) (generator i) ≡ values i
inducedHomOnGenerators _ _ _ _ = refl
unique :
{A : CommAlgebra R ℓ}
(values : FinVec ⟨ A ⟩ n)
(relationsHold : (i : Fin m) → evPoly A (relation i) values ≡ 0a (snd A))
(f : CommAlgebraHom FPAlgebra A)
→ ((i : Fin n) → fst f (generator i) ≡ values i)
→ inducedHom A values relationsHold ≡ f
unique {A = A} values relationsHold f hasCorrectValues =
injectivePrecomp
(Polynomials n)
relationsIdeal
A
(inducedHom A values relationsHold)
f
(sym (
f' ≡⟨ sym (inv f') ⟩
freeInducedHom A (evaluateAt A f') ≡⟨ cong (freeInducedHom A) (funExt hasCorrectValues) ⟩
freeInducedHom A values ≡⟨ cong (freeInducedHom A) refl ⟩
freeInducedHom A (evaluateAt A iHom') ≡⟨ inv iHom' ⟩
iHom' ∎))
where
{-
Poly n
| \
modRelations f'
↓ ↘
FPAlgebra ─f→ A
-}
f' iHom' : CommAlgebraHom (Polynomials n) A
f' = compAlgebraHom modRelations f
iHom' = compAlgebraHom modRelations (inducedHom A values relationsHold)
inv : retract (Iso.fun (homMapIso {I = Fin n} A)) (Iso.inv (homMapIso A))
inv = Iso.leftInv (homMapIso {R = R} {I = Fin n} A)
{- ∀ A : Comm-R-Algebra,
∀ J : Finitely-generated-Ideal,
Hom(R[I]/J,A) is isomorphic to the Set of roots of the generators of J
-}
zeroLocus : (A : CommAlgebra R ℓ) → Type ℓ
zeroLocus A = Σ[ v ∈ FinVec ⟨ A ⟩ n ] ((i : Fin m) → evPoly A (relation i) v ≡ 0a (snd A))
inducedHomFP : (A : CommAlgebra R ℓ) →
zeroLocus A → CommAlgebraHom FPAlgebra A
inducedHomFP A d = inducedHom A (fst d) (snd d)
evaluateAtFP : {A : CommAlgebra R ℓ} →
CommAlgebraHom FPAlgebra A → zeroLocus A
evaluateAtFP {A} f = value ,
λ i → evPoly A (relation i) value ≡⟨ step1 (relation i) ⟩
fst compHom (evPoly (Polynomials n) (relation i) var) ≡⟨ refl ⟩
(fst f) ((fst modRelations)
(evPoly (Polynomials n) (relation i) var)) ≡⟨ cong (fst f)
(evPolyHomomorphic
(Polynomials n)
FPAlgebra
modRelations
(relation i) var) ⟩
(fst f) (evPoly FPAlgebra (relation i) generator) ≡⟨ cong (fst f) (relationsHold i) ⟩
(fst f) (0a (snd FPAlgebra)) ≡⟨ IsAlgebraHom.pres0 (snd f) ⟩
0a (snd A) ∎
where
compHom : CommAlgebraHom (Polynomials n) A
compHom = CommAlgebraHoms.compCommAlgebraHom (Polynomials n) FPAlgebra A modRelations f
value : FinVec ⟨ A ⟩ n
value = (Iso.fun (homMapIso A)) compHom
step1 : (x : ⟨ Polynomials n ⟩) → evPoly A x value ≡ fst compHom (evPoly (Polynomials n) x var)
step1 x = sym (evPolyHomomorphic (Polynomials n) A compHom x var)
FPHomIso : {A : CommAlgebra R ℓ} →
Iso (CommAlgebraHom FPAlgebra A) (zeroLocus A)
Iso.fun FPHomIso = evaluateAtFP
Iso.inv FPHomIso = inducedHomFP _
Iso.rightInv (FPHomIso {A}) =
λ b → Σ≡Prop
(λ x → isPropΠ
(λ i → isSetCommAlgebra A
(evPoly A (relation i) x)
(0a (snd A))))
refl
Iso.leftInv (FPHomIso {A}) =
λ a → Σ≡Prop (λ f → isPropIsCommAlgebraHom {ℓ} {R} {ℓ} {ℓ} {FPAlgebra} {A} f)
λ i → fst (unique {A}
(fst (evaluateAtFP {A} a))
(snd (evaluateAtFP a))
a
(λ j → refl)
i)
homMapPathFP : (A : CommAlgebra R ℓ)→ CommAlgebraHom FPAlgebra A ≡ zeroLocus A
homMapPathFP A = isoToPath (FPHomIso {A})
isSetZeroLocus : (A : CommAlgebra R ℓ) → isSet (zeroLocus A)
isSetZeroLocus A = J (λ y _ → isSet y)
(isSetAlgebraHom (CommAlgebra→Algebra FPAlgebra) (CommAlgebra→Algebra A))
(homMapPathFP A)
record FinitePresentation (A : CommAlgebra R ℓ) : Type ℓ where
field
n : ℕ
m : ℕ
relations : FinVec ⟨ Polynomials n ⟩ m
equiv : CommAlgebraEquiv (FPAlgebra n relations) A
isFPAlgebra : (A : CommAlgebra R ℓ) → Type _
isFPAlgebra A = ∥ FinitePresentation A ∥₁
isFPAlgebraIsProp : {A : CommAlgebra R ℓ} → isProp (isFPAlgebra A)
isFPAlgebraIsProp = isPropPropTrunc
module Instances {R : CommRing ℓ} where
open FinitePresentation
{- Every (multivariate) polynomial algebra is finitely presented -}
module _ (n : ℕ) where
private
A : CommAlgebra R ℓ
A = Polynomials n
emptyGen : FinVec (fst A) 0
emptyGen = λ ()
B : CommAlgebra R ℓ
B = FPAlgebra n emptyGen
polynomialAlgFP : FinitePresentation A
FinitePresentation.n polynomialAlgFP = n
m polynomialAlgFP = 0
relations polynomialAlgFP = emptyGen
equiv polynomialAlgFP =
-- Idea: A and B enjoy the same universal property.
toAAsEquiv , snd toA
where
toA : CommAlgebraHom B A
toA = inducedHom n emptyGen A Construction.var (λ ())
fromA : CommAlgebraHom A B
fromA = freeInducedHom B (generator _ _)
open AlgebraHoms
inverse1 : fromA ∘a toA ≡ idAlgebraHom _
inverse1 =
fromA ∘a toA
≡⟨ sym (unique _ _ _ _ _ (λ i → cong (fst fromA) (
fst toA (generator n emptyGen i)
≡⟨ inducedHomOnGenerators _ _ _ _ _ _ ⟩
Construction.var i
∎))) ⟩
inducedHom n emptyGen B (generator _ _) (relationsHold _ _)
≡⟨ unique _ _ _ _ _ (λ i → refl) ⟩
idAlgebraHom _
∎
inverse2 : toA ∘a fromA ≡ idAlgebraHom _
inverse2 = isoFunInjective (homMapIso A) _ _ (
evaluateAt A (toA ∘a fromA) ≡⟨ sym (naturalEvR {A = B} {B = A} toA fromA) ⟩
fst toA ∘ evaluateAt B fromA ≡⟨ refl ⟩
fst toA ∘ generator _ _ ≡⟨ funExt (inducedHomOnGenerators _ _ _ _ _)⟩
Construction.var ∎)
toAAsEquiv : ⟨ B ⟩ ≃ ⟨ A ⟩
toAAsEquiv = isoToEquiv (iso (fst toA)
(fst fromA)
(λ a i → fst (inverse2 i) a)
(λ b i → fst (inverse1 i) b))
{- The initial R-algebra is finitely presented -}
private
R[⊥] : CommAlgebra R ℓ
R[⊥] = Polynomials 0
emptyGen : FinVec (fst R[⊥]) 0
emptyGen = λ ()
R[⊥]/⟨0⟩ : CommAlgebra R ℓ
R[⊥]/⟨0⟩ = FPAlgebra 0 emptyGen
R[⊥]/⟨0⟩IsInitial : (B : CommAlgebra R ℓ)
→ isContr (CommAlgebraHom R[⊥]/⟨0⟩ B)
R[⊥]/⟨0⟩IsInitial B = iHom , uniqueness
where
iHom : CommAlgebraHom R[⊥]/⟨0⟩ B
iHom = inducedHom 0 emptyGen B (λ ()) (λ ())
uniqueness : (f : CommAlgebraHom R[⊥]/⟨0⟩ B) →
iHom ≡ f
uniqueness f = unique 0 emptyGen {A = B} (λ ()) (λ ()) f (λ ())
initialCAlgFP : FinitePresentation (initialCAlg R)
n initialCAlgFP = 0
m initialCAlgFP = 0
relations initialCAlgFP = emptyGen
equiv initialCAlgFP =
equivByInitiality R R[⊥]/⟨0⟩ R[⊥]/⟨0⟩IsInitial
{- The terminal R-algebra is finitely presented -}
private
unitGen : FinVec (fst R[⊥]) 1
unitGen zero = 1a
where open CommAlgebraStr (snd R[⊥])
R[⊥]/⟨1⟩ : CommAlgebra R ℓ
R[⊥]/⟨1⟩ = FPAlgebra 0 unitGen
terminalCAlgFP : FinitePresentation (TerminalCAlg R)
n terminalCAlgFP = 0
m terminalCAlgFP = 1
relations terminalCAlgFP = unitGen
equiv terminalCAlgFP = equivFrom1≡0 R R[⊥]/⟨1⟩ (sym (⋆-lid 1a) ∙ relationsHold 0 unitGen zero)
where open CommAlgebraStr (snd R[⊥]/⟨1⟩)
|
@testset "Kaleidoscope" begin
include(joinpath(@__DIR__, "..", "examples", "Kaleidoscope", "Kaleidoscope.jl"))
@testset "recursion" begin
program = """
def fib(x) {
if x < 3 then
1
else
fib(x-1) + fib(x-2)
}
def entry() {
fib(10)
}
"""
LLVM.Context() do ctx
m = Kaleidoscope.generate_IR(program, ctx)
Kaleidoscope.optimize!(m)
v = Kaleidoscope.run(m, "entry")
@test v == 55.0
end
end
@testset "loops" begin
program = """
def fib(x) {
var a = 1, b = 1
for i = 3, i < x, 1.0 {
var c = a + b
a = b
b = c
}
b
}
def entry() {
fib(10)
}
"""
LLVM.Context() do ctx
m = Kaleidoscope.generate_IR(program, ctx)
Kaleidoscope.optimize!(m)
mktemp() do path, io
Kaleidoscope.write_objectfile(m, path)
end
v = Kaleidoscope.run(m, "entry")
@test v == 55.0
end
end
@testset "global vars" begin
program = """
var x = 5
var y = 3
def foo(a b) a + b + x + y
def entry() foo(2, 3)
"""
LLVM.Context() do ctx
m = Kaleidoscope.generate_IR(program, ctx)
Kaleidoscope.optimize!(m)
v = Kaleidoscope.run(m, "entry")
@test v == 13
end
end
end
|
theory ComputationCon imports "SmallStepCon" "HOL-Eisbach.Eisbach_Tools"
begin
type_synonym ('g,'l) c_state = "('g\<times>'l)\<times>('l list)"
type_synonym ('g, 'l, 'p,'f,'e) config_gs = "('g\<times>'l,'p,'f,'e)com \<times> ('g,'l) c_state"
(* inductive
"step_e"::"[('g\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \<Rightarrow> bool"
("_\<turnstile>\<^sub>c (_ \<rightarrow>\<^sub>e/ _)" [81,81,81] 100)
for \<Gamma>::"('g\<times>'l,'p,'f,'e) body"
where
Env:"(\<forall>ns'. t'\<noteq>Normal ns' \<or> (snd (fst ns) =snd (fst ns') \<and>
length (snd ns) = length (snd ns'))) \<Longrightarrow>
\<Gamma>\<turnstile>\<^sub>c (Ps, Normal ns) \<rightarrow>\<^sub>e (Ps, t')"
|Env_n: "(\<forall>ns. t\<noteq>Normal ns) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (Ps, t) \<rightarrow>\<^sub>e (Ps, t)"
inductive
"step_e1"::"[('g\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \<Rightarrow> bool"
("_\<turnstile>\<^sub>c (_ \<rightarrow>\<^sub>e\<^sub>1/ _)" [81,81,81] 100)
for \<Gamma>::"('g\<times>'l,'p,'f,'e) body"
where
Env1:"(\<forall>ns'. t'\<noteq>Normal ns') \<or> (\<exists>ns'. t'=Normal ns' \<and> (snd (fst ns) =snd (fst ns') \<and>
length (snd ns) = length (snd ns'))) \<Longrightarrow>
\<Gamma>\<turnstile>\<^sub>c (Ps, Normal ns) \<rightarrow>\<^sub>e\<^sub>1 (Ps, t')"
|Env_n1: "(\<forall>ns. t\<noteq>Normal ns) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (Ps, t) \<rightarrow>\<^sub>e\<^sub>1 (Ps, t)"
inductive
"step_e2"::"[('g\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \<Rightarrow> bool"
("_\<turnstile>\<^sub>c (_ \<rightarrow>\<^sub>e\<^sub>2/ _)" [81,81,81] 100)
for \<Gamma>::"('g\<times>'l,'p,'f,'e) body"
where
Env:"(\<forall>ns'. t'\<noteq>Normal ns' \<or> t'\<noteq>Abrupt ns') \<or>
(\<exists>ns'. t'=Normal ns' \<and> snd (fst ns) =snd (fst ns') \<and>
length (snd ns) = length (snd ns')) \<or>
(\<exists>ns'. t'=Abrupt ns' \<and> length (snd ns) = length (snd ns')) \<Longrightarrow>
\<Gamma>\<turnstile>\<^sub>c (Ps, Normal ns) \<rightarrow>\<^sub>e\<^sub>2 (Ps, t')"
|Env_n: "(\<forall>ns. t\<noteq>Normal ns) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (Ps, t) \<rightarrow>\<^sub>e\<^sub>2 (Ps, t)"
inductive
"step_e3"::"[('g\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \<Rightarrow> bool"
("_\<turnstile>\<^sub>c (_ \<rightarrow>\<^sub>e\<^sub>3/ _)" [81,81,81] 100)
for \<Gamma>::"('g\<times>'l,'p,'f,'e) body"
where
Env:"(\<forall>ns'. (t'\<noteq>Normal ns' \<and> t'\<noteq>Abrupt ns') \<or> (t'=Normal ns' \<and> snd (fst ns) =snd (fst ns') \<and>
length (snd ns) = length (snd ns')) \<or>
(t'=Abrupt ns' \<and> length (snd ns) = length (snd ns'))) \<Longrightarrow>
\<Gamma>\<turnstile>\<^sub>c (Ps, Normal ns) \<rightarrow>\<^sub>e\<^sub>3 (Ps, t')"
|Env_n: "(\<forall>ns. t\<noteq>Normal ns) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (Ps, t) \<rightarrow>\<^sub>e\<^sub>3 (Ps, t)" *)
inductive
"step_e"::"[('g\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \<Rightarrow> bool"
("_\<turnstile>\<^sub>c (_ \<rightarrow>\<^sub>e/ _)" [81,81,81] 100)
for \<Gamma>::"('g\<times>'l,'p,'f,'e) body"
where
Env:"snd (fst s) =snd (fst t) \<and> length (snd s) = length (snd t) \<Longrightarrow>
\<Gamma>\<turnstile>\<^sub>c (Ps, s) \<rightarrow>\<^sub>e (Ps, t)"
lemma etranE: "\<Gamma>\<turnstile>\<^sub>c c \<rightarrow>\<^sub>e c' \<Longrightarrow> (\<And>P s t. c = (P, s) \<Longrightarrow> c' = (P, t) \<Longrightarrow> Q) \<Longrightarrow> Q"
by (induct c, induct c', erule step_e.cases, blast)
inductive_cases stepe_elim_cases1 [cases set]:
"\<Gamma>\<turnstile>\<^sub>c(Ps,s) \<rightarrow>\<^sub>e (Ps',t)"
inductive_cases stepe_elim_cases [cases set]:
"\<Gamma>\<turnstile>\<^sub>c(Ps,s) \<rightarrow>\<^sub>e (Ps,t)"
lemma env_c_c'_false:
assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', s')"
shows "~(c=c') \<Longrightarrow> P"
using step_m etranE by blast
(* lemma eenv_normal_s'_normal_s:
assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', Normal s')"
shows "(\<And>s1. s\<noteq>Normal s1) \<Longrightarrow> P"
using step_m
using env_c_c'_false stepe_not_norm_elim_cases(4) by blast *)
lemma eenv_eq_length:
assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', s')" and
normal_s:"s= ((g,l),ls)" and normal_s':"s'= ((g',l'),ls')"
shows "(length ls \<noteq> length ls') \<Longrightarrow> P"
using step_m normal_s normal_s'
using env_c_c'_false stepe_elim_cases1 by fastforce
(* lemma env_normal_s'_normal_s:
assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', Normal s') "
shows "\<exists>s1. s= Normal s1"
using step_m
using env_c_c'_false stepe_not_norm_elim_cases(4) by blast
*)
lemma env_c_c':
assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', s')"
shows "(c=c')"
using env_c_c'_false step_m by fastforce
lemma env_normal_same_local_length:
assumes a1:"\<Gamma>\<turnstile>\<^sub>c (c, ((g,l),ls)) \<rightarrow>\<^sub>e (c', ((g',l'),ls'))"
shows "l=l' \<and> length ls = length ls'"
using a1
by (cases rule:step_e.cases,auto)
lemma env_normal_same_local:
assumes a1:"\<Gamma>\<turnstile>\<^sub>c (c, ((g,l),ls)) \<rightarrow>\<^sub>e (c', ((g',l'),ls'))"
shows "l=l'"
using a1 env_normal_same_local_length
by fast
lemma env_normal_same_length:
assumes a1:"\<Gamma>\<turnstile>\<^sub>c (c, ((g,l),ls)) \<rightarrow>\<^sub>e (c', ((g',l'),ls'))"
shows "length ls = length ls'"
using a1 env_normal_same_local_length
by fast
lemma env_intro:
assumes a1:"length ls = length ls'"
shows "\<Gamma>\<turnstile>\<^sub>c (c, ((g,l),ls)) \<rightarrow>\<^sub>e (c, ((g',l),ls'))"
using a1 by (auto intro: step_e.intros)
lemma env_intro_diff_p:"\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (P, t) \<Longrightarrow>
\<Gamma>\<turnstile>\<^sub>c (Q, s) \<rightarrow>\<^sub>e (Q, t)"
by (auto elim: stepe_elim_cases simp add: Env )
lemma snormal_enviroment:
" snd (fst s) =snd (fst t) \<and> length (snd s) = length (snd t) \<Longrightarrow>
\<Gamma>\<turnstile>\<^sub>c (x, s) \<rightarrow>\<^sub>e (x, t)"
by (simp add: step_e.intros)
(* definition final_glob:: "('g,'l,'p,'f,'e) config_gs \<Rightarrow> bool" where
"final_glob cfg \<equiv> (fst cfg=Skip \<or> ((fst cfg=Throw) \<and> (\<exists>s. snd cfg=Normal s)))"
lemma final_eq:"snd cfg = Normal s \<Longrightarrow> final_glob cfg = SmallStepCon.final (fst cfg, Normal (fst s))"
unfolding final_def final_glob_def SmallStepCon.final_def
by auto
*)
section \<open> computation with enviroment \<close>
fun toSeq ::"(('g\<times>'l)\<times>('l list)) \<Rightarrow> (('g\<times>'l)) "
where
"toSeq ns = (fst ns)"
lemma
assumes
a0:"snd s = snd s'" and
a1:"toSeq s = toSeq s'"
shows eq_toSeq:"s = s'" using a0 a1
by (cases s, simp)
inductive
"step_ce"::"[('g\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \<Rightarrow> bool"
("_\<turnstile>\<^sub>c (_ \<rightarrow>\<^sub>c\<^sub>e/ _)" [81,81,81] 100)
for \<Gamma>::"('g\<times>'l,'p,'f,'e) body"
where
c_step: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c (c, (toSeq s)) \<rightarrow> (c', toSeq s'); snd s = snd s'\<rbrakk> \<Longrightarrow>
\<Gamma>\<turnstile>\<^sub>c (c,s) \<rightarrow>\<^sub>c\<^sub>e (c',s')"
|e_step: "\<Gamma>\<turnstile>\<^sub>c (c,s) \<rightarrow>\<^sub>e (c',s') \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (c,s) \<rightarrow>\<^sub>c\<^sub>e (c',s') "
lemmas step_ce_induct = step_ce.induct [of _ "(c,s)" "(c',s')", split_format (complete), case_names
c_step e_step, induct set]
inductive_cases step_ce_elim_cases [cases set]:
"\<Gamma>\<turnstile>\<^sub>c cf0 \<rightarrow>\<^sub>c\<^sub>e cf1"
inductive_cases step_ce_elim_cases_eq_locals [cases set]:
"\<Gamma>\<turnstile>\<^sub>c (c,((g,l),ls)) \<rightarrow>\<^sub>c\<^sub>e (c', ((g',l),ls'))"
"\<Gamma>\<turnstile>\<^sub>c (c,((g,l),ls)) \<rightarrow>\<^sub>c\<^sub>e (c', ((g',l'),ls))"
lemma step_dest:
assumes a0:"\<Gamma>\<turnstile>\<^sub>c(P, s) \<rightarrow>\<^sub>c\<^sub>e (Q,t)"
shows "\<Gamma>\<turnstile>\<^sub>c(P, s) \<rightarrow>\<^sub>e (Q,t) \<or>
(\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Q, toSeq t) \<and> (snd s) = (snd t))"
using a0 apply clarsimp
apply (erule step_ce_elim_cases)
by auto
lemma step_dest1:
assumes a0:"\<Gamma>\<turnstile>\<^sub>c(P, s) \<rightarrow>\<^sub>c\<^sub>e (Q,t)" and
a1:"\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Q, toSeq t)"
shows"((snd s) = (snd t))"
using a0 a1 apply clarsimp
apply (erule step_ce_elim_cases)
apply auto
by (metis (no_types) mod_env_not_component stepe_elim_cases1)
lemma transfer_normal:"
\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow> (c', s') \<Longrightarrow>
\<Gamma>\<turnstile>\<^sub>c (c, (s, ls)) \<rightarrow>\<^sub>c\<^sub>e (c', (s', ls))"
by (auto intro: c_step)
lemma step_c_normal_normal: assumes a1: "\<Gamma>\<turnstile>\<^sub>c cf0 \<rightarrow> cf1"
shows "\<And> c\<^sub>1 s s'. \<lbrakk>cf0 = (c\<^sub>1,Normal s);cf1=(c\<^sub>1,s');(\<forall>sa. \<not>(s'=Normal sa))\<rbrakk>
\<Longrightarrow> P"
using a1
by (induct rule: stepc.induct, induct, auto)
lemma call_f_step_ce_not_s_eq_t_env_step:
assumes
a0:"\<Gamma>\<turnstile>\<^sub>c(P,s) \<rightarrow>\<^sub>c\<^sub>e (Q,t)" and
a1:"(redex P = Call fn \<and> \<Gamma> fn = Some bdy \<and> (s\<noteq>t)) \<or>
(redex P = Call fn \<and> \<Gamma> fn = Some bdy \<and> s=t \<and> P=Q \<and> \<Gamma> fn \<noteq> Some (Call fn)) "
shows "\<Gamma>\<turnstile>\<^sub>c(P,s) \<rightarrow>\<^sub>e (Q,t)"
by (metis (no_types, hide_lams) a0 a1 call_f_step_not_s_eq_t_false eq_toSeq step_dest)
abbreviation
"stepce_rtrancl" :: "[('g\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \<Rightarrow> bool"
("_\<turnstile>\<^sub>c (_ \<rightarrow>\<^sub>c\<^sub>e\<^sup>*/ _)" [81,81,81] 100)
where
"\<Gamma>\<turnstile>\<^sub>c cf0 \<rightarrow>\<^sub>c\<^sub>e\<^sup>* cf1 \<equiv> ((CONST step_ce \<Gamma>))\<^sup>*\<^sup>* cf0 cf1"
(* "\<Gamma>\<turnstile>\<^sub>c cf0 \<rightarrow>\<^sup>* cf1 \<equiv> (CONST ((stepc \<Gamma>) \<union> (step_e \<Gamma>)))\<^sup>*\<^sup>* cf0 cf1" *)
abbreviation
"stepce_trancl" :: "[('g\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \<Rightarrow> bool"
("_\<turnstile>\<^sub>c (_ \<rightarrow>\<^sub>c\<^sub>e\<^sup>+/ _)" [81,81,81] 100)
where
"\<Gamma>\<turnstile>\<^sub>c cf0 \<rightarrow>\<^sub>c\<^sub>e\<^sup>+ cf1 \<equiv> (CONST step_ce \<Gamma>)\<^sup>+\<^sup>+ cf0 cf1"
text \<open> lemmas about single step computation \<close>
(* lemma ce_not_normal_s:
assumes a1:"\<Gamma>\<turnstile>\<^sub>c cf0 \<rightarrow>\<^sub>c\<^sub>e cf1"
shows "\<And> c\<^sub>1 c\<^sub>2 s s'. \<lbrakk>cf0 = (c\<^sub>1,s);cf1=(c\<^sub>2,s');(\<forall>sa. (s\<noteq>Normal sa))\<rbrakk>
\<Longrightarrow> s=s'"
using a1
apply (clarify, cases rule:step_ce.cases)
apply (metis eq_toSeq prod.sel(1) prod.sel(2) step_not_normal_s_eq_t toSeq.simps xstate.simps(5))
using env_not_normal_s by blast *)
lemma not_eq_not_env:
assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e (c', s')"
shows "~(c=c') \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', s') \<Longrightarrow> P"
using step_m etranE by blast
lemma step_ce_not_step_e_step_c:
assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e (c', s')"
shows "\<not> (\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', s')) \<Longrightarrow>(\<Gamma>\<turnstile>\<^sub>c (c, toSeq s) \<rightarrow> (c', toSeq s'))"
using step_m
by (meson step_dest)
lemma step_ce_step_c_eq_c:
assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e (c', s')"
shows "(\<Gamma>\<turnstile>\<^sub>c (c, toSeq s) \<rightarrow> (c', toSeq s')) \<Longrightarrow> c=c' \<Longrightarrow> P"
using step_m step_ce_elim_cases step_ce_not_step_e_step_c
by (simp add: mod_env_not_component)
(* lemma step_ce_notNormal:
assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e (c', s')"
shows "(\<forall>sa. \<not>(s=Normal sa)) \<Longrightarrow> s'=s"
using step_m
proof (induct rule:step_ce_induct)
case (e_step a b a' b')
thus ?case
using env_not_normal_s by blast
next
case (c_step a b a' b')
thus ?case
using ce_not_normal_s step_ce.c_step by blast
qed *)
(* lemma steps_ce_not_Normal:
assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (c', s')"
shows "\<forall>sa. \<not>(s=Normal sa) \<Longrightarrow> s'=s"
using step_m
proof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])
case Refl then show ?case by auto
next
case (Trans a b a' b')
thus ?case using step_ce_notNormal by blast
qed *)
lemma step_ce_Normal_eq_l:
assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, (s,l)) \<rightarrow>\<^sub>c\<^sub>e (c', (s',l'))" and
step_ce:"\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow> (c', s')"
shows "l=l'"
by (metis env_c_c' mod_env_not_component snd_conv step_ce step_dest step_m)
lemma step_ce_dest:
assumes step_m: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e (c', s')"
shows "\<Gamma>\<turnstile>\<^sub>c (c, toSeq s) \<rightarrow> (c', toSeq s') \<or> \<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', s')"
using step_ce_not_step_e_step_c step_m by blast
(* lemma steps_not_normal_ce_c:
assumes steps: "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (c', s')"
shows "( \<forall>sa. \<not>(s=Normal sa)) \<Longrightarrow> \<Gamma>\<turnstile>\<^sub>c (c, toSeq s) \<rightarrow>\<^sup>* (c', toSeq s')"
using steps
proof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])
case Refl thus ?case by auto
next
case (Trans a b a' b') then show ?case
by (metis (no_types, hide_lams) converse_rtranclp_into_rtranclp env_c_c'
step_ce_notNormal step_ce_not_step_e_step_c)
qed *)
lemma ce_eq_length: assumes a0:"\<Gamma>\<turnstile>\<^sub>c (P,s) \<rightarrow>\<^sub>c\<^sub>e (Q,t)"
shows "length (snd s) = length (snd t)"
by (metis assms step_dest stepe_elim_cases1)
lemma ce_Throw_toSkip:
assumes a0:"\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Throw, s) \<rightarrow>\<^sub>c\<^sub>e x"
shows "fst x = Throw"
proof-
have "\<Gamma>\<turnstile>\<^sub>c (Throw, toSeq s) \<rightarrow> (fst x, toSeq (snd x))
\<or> \<Gamma>\<turnstile>\<^sub>c (Throw, s) \<rightarrow>\<^sub>e x" using a0 step_ce_dest
by (metis prod.collapse)
thus ?thesis
by (metis env_c_c' prod.collapse prod.inject stepc_elim_cases(11))
qed
subsection \<open>Computations\<close>
subsubsection \<open>Sequential computations\<close>
type_synonym ('g,'l,'p,'f,'e) confs =
"('g\<times>'l,'p,'f,'e) body \<times> (('g, 'l, 'p,'f,'e) config_gs) list"
inductive_set cptn :: "(('g,'l,'p,'f,'e) confs) set"
where
CptnOne: " (\<Gamma>, [(P,s)]) \<in> cptn"
| Cptn: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,s) \<rightarrow>\<^sub>c\<^sub>e (Q,t); (\<Gamma>,(Q, t)#xs) \<in> cptn \<rbrakk> \<Longrightarrow>
(\<Gamma>,(P,s)#(Q,t)#xs) \<in> cptn"
inductive_cases cptn_elim_cases [cases set]:
"(\<Gamma>, [(P,s)]) \<in> cptn"
"(\<Gamma>,(P,s)#(Q,t)#xs) \<in> cptn"
inductive_cases cptn_elim_cases_pair [cases set]:
"(\<Gamma>, [x]) \<in> cptn"
"(\<Gamma>, x#x1#xs) \<in> cptn"
lemma cptn_dest:"(\<Gamma>,(P,s)#(Q,t)#xs) \<in> cptn \<Longrightarrow> (\<Gamma>,(Q,t)#xs)\<in> cptn"
by (auto dest: cptn_elim_cases)
lemma cptn_dest_pair:"(\<Gamma>,x#x1#xs) \<in> cptn \<Longrightarrow> (\<Gamma>,x1#xs)\<in> cptn"
proof -
assume "(\<Gamma>,x#x1#xs) \<in> cptn"
thus ?thesis using cptn_dest prod.collapse by metis
qed
lemma cptn_dest1:"(\<Gamma>,(P,s)#(Q,t)#xs) \<in> cptn \<Longrightarrow> (\<Gamma>,(P,s)#[(Q,t)])\<in> cptn"
proof -
assume a1: "(\<Gamma>, (P, s) # (Q, t) # xs) \<in> cptn"
have "(\<Gamma>, [(Q, t)]) \<in> cptn"
by (meson cptn.CptnOne)
thus ?thesis
using a1 cptn.Cptn cptn_elim_cases(2) by blast
qed
lemma cptn_dest1_pair:"(\<Gamma>,x#x1#xs) \<in> cptn \<Longrightarrow> (\<Gamma>,x#[x1])\<in> cptn"
proof -
assume "(\<Gamma>,x#x1#xs) \<in> cptn"
thus ?thesis using cptn_dest1 prod.collapse by metis
qed
lemma cptn_append_is_cptn [rule_format]:
"\<forall>b a. (\<Gamma>,b#c1)\<in>cptn \<longrightarrow> (\<Gamma>,a#c2)\<in>cptn \<longrightarrow> (b#c1)!length c1=a \<longrightarrow> (\<Gamma>,b#c1@c2)\<in>cptn"
apply(induct c1)
apply simp
apply clarify
apply(erule cptn.cases,simp_all)
using cptn.Cptn by blast
(* apply (simp add: cptn.CptnEnv)
by (simp add: cptn.CptnComp) *)
lemma cptn_dest_2:
"(\<Gamma>,a#xs@ys) \<in> cptn \<Longrightarrow> (\<Gamma>,a#xs)\<in> cptn"
proof (induct "xs" arbitrary: a)
case Nil
then have "\<exists>p. [p] = [a]"
by blast
then show ?case
using cptn.simps by fastforce
next
case (Cons x xs')
then have "(\<Gamma>,a#[x])\<in>cptn" by (simp add: cptn_dest1_pair)
also have "(\<Gamma>, x # xs') \<in> cptn"
by (metis (no_types) Cons.hyps Cons.prems append_Cons cptn_dest_pair)
ultimately show ?case using cptn_append_is_cptn [of \<Gamma> a "[x]" x xs']
by force
qed
lemma tl_in_cptn: "\<lbrakk> (g,a#xs) \<in>cptn; xs\<noteq>[] \<rbrakk> \<Longrightarrow> (g,xs)\<in>cptn"
by (force elim: cptn.cases)
lemma sublist_in_cptn:"(\<Gamma>, ys@ xs) \<in> cptn \<Longrightarrow> xs\<noteq> [] \<Longrightarrow> (\<Gamma>, xs) \<in> cptn"
proof(induct ys)
case Nil
then show ?case by auto
next
case (Cons a ys)
then have "(\<Gamma>, a # (ys @ xs)) \<in> cptn " by auto
then show ?case
by (metis Cons.hyps Cons.prems(2) Nil_is_append_conv tl_in_cptn)
qed
subsection {* Relation between @{term "stepc_rtrancl"} and @{term "cptn"} *}
lemma stepc_rtrancl_cptn:
assumes step: "\<Gamma>\<turnstile>\<^sub>c (c,s) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (cf,sf)"
shows "\<exists>xs. (\<Gamma>,(c, s)#xs) \<in> cptn \<and>(cf,sf) = (last ((c,s)#xs))"
using step
proof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])
case Refl thus ?case using cptn.CptnOne
by (metis last_ConsL)
next
case (Trans c s c' s')
have "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>e (c', s') \<or> \<Gamma>\<turnstile>\<^sub>c (c, toSeq s) \<rightarrow> (c', toSeq s')"
using Trans.hyps(1) step_ce_not_step_e_step_c by blast
then show ?case
by (metis (no_types) Trans.hyps(1) Trans.hyps(3) cptn.Cptn
last_ConsR list.simps(3))
qed
lemma cptn_stepc_rtrancl:
assumes cptn_step: "(\<Gamma>,(c, s)#xs) \<in> cptn" and
cf_last:"(cf,sf) = (last ((c,s)#xs))"
shows "\<Gamma>\<turnstile>\<^sub>c (c,s) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (cf,sf)"
using cptn_step cf_last
proof (induct xs arbitrary: c s)
case Nil
thus ?case by simp
next
case (Cons a xs c s)
then obtain ca sa where eq_pair: "a=(ca,sa)" and "(cf, sf) = last ((ca,sa) # xs) "
using Cons
by (metis last.simps list.distinct(1) surj_pair)
then have "\<Gamma>\<turnstile>\<^sub>c (ca,sa) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (cf, sf)" using Cons
using cptn_dest_pair by blast
moreover have "\<Gamma>\<turnstile>\<^sub>c (c, s) \<rightarrow>\<^sub>c\<^sub>e (ca, sa)" using Cons eq_pair
using cptn_elim_cases(2) by blast
ultimately show ?case
by auto
qed
lemma cptn_stepc_rtran:
assumes cptn_step: "(\<Gamma>,x#xs) \<in> cptn" and
a1:"Suc i < length (x#xs)"
shows "\<Gamma>\<turnstile>\<^sub>c ((x#xs)!i) \<rightarrow>\<^sub>c\<^sub>e ((x#xs)!(Suc i))"
using cptn_step a1
proof (induct i arbitrary: x xs)
case 0
then obtain x1 xs1 where xs:"xs=x1#xs1"
by (metis length_Cons less_not_refl list.exhaust list.size(3))
then have "\<Gamma>\<turnstile>\<^sub>c x \<rightarrow>\<^sub>c\<^sub>e x1"
using "0.prems"(1) cptn_elim_cases_pair(2) by blast
then show ?case
by (simp add: xs)
next
case (Suc i)
then have "Suc i < length xs" by auto
moreover obtain x1 xs1 where xs:"xs=x1#xs1"
by (metis (full_types) calculation list.exhaust list.size(3) not_less0)
moreover have "\<Gamma>\<turnstile>\<^sub>c ((x1 # xs1) ! i) \<rightarrow>\<^sub>c\<^sub>e ((x1 # xs1) ! Suc i)"
using Suc
using calculation(1) cptn_dest_pair xs by blast
thus ?case using xs by auto
qed
lemma cptn_stepconf_rtrancl:
assumes cptn_step: "(\<Gamma>,cfg1#xs) \<in> cptn" and
cf_last:"cfg2 = (last (cfg1#xs))"
shows "\<Gamma>\<turnstile>\<^sub>c cfg1 \<rightarrow>\<^sub>c\<^sub>e\<^sup>* cfg2"
using cptn_step cf_last
by (metis cptn_stepc_rtrancl prod.collapse)
lemma cptn_all_steps_rtrancl:
assumes cptn_step: "(\<Gamma>,cfg1#xs) \<in> cptn"
shows "\<forall>i<length (cfg1#xs). \<Gamma>\<turnstile>\<^sub>c cfg1 \<rightarrow>\<^sub>c\<^sub>e\<^sup>* ((cfg1#xs)!i)"
using cptn_step
proof (induct xs arbitrary: cfg1)
case Nil thus ?case by auto
next
case (Cons x xs1) thus ?case
proof -
have hyp:"\<forall>i<length (x # xs1). \<Gamma>\<turnstile>\<^sub>c x \<rightarrow>\<^sub>c\<^sub>e\<^sup>* ((x # xs1) ! i)"
using Cons.hyps Cons.prems cptn_dest_pair by blast
thus ?thesis
proof
{
fix i
assume a0:"i<length (cfg1 # x # xs1)"
then have "Suc 0 < length (cfg1 # x # xs1)"
by simp
hence "\<Gamma>\<turnstile>\<^sub>c (cfg1 # x # xs1) ! 0 \<rightarrow>\<^sub>c\<^sub>e ((cfg1 # x # xs1) ! Suc 0)"
using Cons.prems cptn_stepc_rtran by blast
then have "\<Gamma>\<turnstile>\<^sub>c cfg1 \<rightarrow>\<^sub>c\<^sub>e x" using Cons by simp
also have "i < Suc (Suc (length xs1))"
using a0 by force
ultimately have "\<Gamma>\<turnstile>\<^sub>c cfg1 \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (cfg1 # x # xs1) ! i" using hyp Cons
using converse_rtranclp_into_rtranclp hyp less_Suc_eq_0_disj
by auto
} thus ?thesis by auto qed
qed
qed
(* lemma last_not_F:
assumes
a0:"(\<Gamma>,xs)\<in>cptn"
shows "snd (last xs) \<notin> Fault ` F \<Longrightarrow> \<forall>i < length xs. snd (xs!i) \<notin> Fault ` F"
using a0
proof(induct) print_cases
case (CptnOne \<Gamma> p s) thus ?case by auto
next
case (Cptn \<Gamma> P s t xs)
thus ?case
by (metis (no_types, hide_lams) ce_not_normal_s image_iff last_ConsR length_Cons less_Suc_eq_0_disj list.simps(3) nth_Cons_0
nth_Cons_Suc snd_conv xstate.distinct(3))
qed *)
(* lemma Normal_Normal:
assumes p1:"(\<Gamma>, (P, Normal s) # a # as) \<in> cptn" and
p2:"(\<exists>sb. snd (last ((P, Normal s) # a # as)) = Normal sb)"
shows "\<exists>sa. snd a = Normal sa"
proof -
obtain la1 la2 where last_prod:"last ((P, Normal s)# a#as) = (la1,la2)" by fastforce
obtain a1 a2 where a_prod:"a=(a1,a2)" by fastforce
from p1 have clos_p_a:"\<Gamma>\<turnstile>\<^sub>c (P,Normal s) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (a1, a2)"
using a_prod cptn_elim_cases(2)
by blast
then have "\<Gamma>\<turnstile>\<^sub>c (fst a, snd a) \<rightarrow>\<^sub>c\<^sub>e\<^sup>* (la1,la2)"
by (metis cptn_stepconf_rtrancl last_ConsR last_prod list.distinct(1)
p1 prod.exhaust_sel tl_in_cptn)
moreover obtain bb where "Normal bb = la2" using last_prod p2 by auto
ultimately show ?thesis by (metis (no_types) steps_ce_not_Normal)
qed *)
lemma cptn_eq_length:"(\<Gamma>,l)\<in>cptn \<Longrightarrow>
\<forall>i. Suc i< length l \<longrightarrow> length (snd (snd (l!i))) = length (snd (snd (l!(i+1))))"
proof-
assume a0:"(\<Gamma>,l)\<in>cptn"
{
fix i
assume a00:"Suc i< length l"
moreover obtain a as where "l = a#as"
using a0 calculation by (metis list.exhaust list.size(3) not_less_zero)
ultimately have "\<Gamma>\<turnstile>\<^sub>c(l!i) \<rightarrow>\<^sub>c\<^sub>e (l!Suc i)"
using a0
using cptn_stepc_rtran by blast
then have "length (snd (snd (l!i))) = length (snd (snd (l!(i+1))))"
by (metis Suc_eq_plus1 ce_eq_length prod.exhaust_sel)
}
then show ?thesis by auto
qed
lemma cptn_all_len_eq_0:
"(\<Gamma>,l)\<in>cptn \<Longrightarrow> snd ( (l!0)) = s \<Longrightarrow>
i<length l \<Longrightarrow>length (snd (snd (l!i))) =length (snd s)"
proof(induct i)
case 0
then show ?case
by simp
next
case (Suc i)
then have "length (snd (snd (l!i))) =length (snd s) " by auto
then show ?case using cptn_eq_length Suc by fastforce
qed
lemma skip_all_skip:
assumes a0:"(\<Gamma>,cfg)\<in>cptn" and
a1:"cfg = (Skip,s)#cfg1"
shows "\<forall>i<length cfg. fst(cfg!i) = Skip"
using a0 a1
proof(induct cfg1 arbitrary:cfg s)
case Nil thus ?case by auto
next
case (Cons x xs)
have cptn:"(\<Gamma>,x#xs)\<in>cptn"
using Cons.prems(1) Cons.prems(2) cptn_dest_pair by blast
have "\<Gamma>\<turnstile>\<^sub>c(Skip,s) \<rightarrow>\<^sub>e x" using cptn_elim_cases_pair(2)[OF Cons(2)[simplified Cons(3)]]
by (metis step_ce_dest stepc_elim_cases(1))
then obtain s' where x:"x = (Skip,s')"
by (metis env_c_c' prod.exhaust_sel)
moreover have cptn:"(\<Gamma>,x#xs)\<in>cptn"
using Cons.prems(1) Cons.prems(2) cptn_dest_pair by blast
moreover have
xs:"x # xs = (LanguageCon.com.Skip, s') # xs" using x by auto
ultimately show ?case using Cons(1)[OF cptn xs] Cons(3)
using diff_Suc_1 fstI length_Cons less_Suc_eq_0_disj nth_Cons' by auto
qed
lemma skip_all_skip_throw:
assumes a0:"(\<Gamma>,cfg)\<in>cptn" and
a1:"cfg = (Throw,s)#cfg1"
shows "\<forall>i<length cfg. fst(cfg!i) = Throw"
using a0 a1
proof(induct cfg1 arbitrary:cfg s)
case Nil thus ?case by auto
next
case (Cons x xs)
have cptn:"(\<Gamma>,x#xs)\<in>cptn"
using Cons.prems(1) Cons.prems(2) cptn_dest_pair by blast
have ce:"\<Gamma>\<turnstile>\<^sub>c(Throw,s) \<rightarrow>\<^sub>c\<^sub>e x"
by (auto intro:cptn_elim_cases_pair(2)[OF Cons(2)[simplified Cons(3)]])
then obtain s' where x:"x = (Throw, s')"
using ce_Throw_toSkip
by (metis eq_fst_iff)
show ?case using x
by (metis (no_types, lifting) Cons.hyps Cons.prems(2) cptn diff_Suc_1
fstI length_Cons less_Suc_eq_0_disj nth_Cons')
qed
lemma cptn_env_same_prog:
assumes a0: "(\<Gamma>, l) \<in> cptn" and
a1: "\<forall>k < j. (\<Gamma>\<turnstile>\<^sub>c(l!k) \<rightarrow>\<^sub>e (l!(Suc k)))" and
a2: "Suc j < length l"
shows "fst (l!j) = fst (l!0)"
using a0 a1 a2
proof (induct j arbitrary: l)
case 0 thus ?case by auto
next
case (Suc j)
then have "fst (l!j) = fst (l!0)" by fastforce
thus ?case using Suc
by (metis (no_types) env_c_c' lessI prod.collapse)
qed
lemma takecptn_is_cptn [rule_format, elim!]:
"\<forall>j. (\<Gamma>,c) \<in> cptn \<longrightarrow> (\<Gamma>, take (Suc j) c) \<in> cptn"
apply(induct "c")
apply(force elim: cptn.cases)
apply clarify
apply(case_tac j)
apply simp
apply(rule CptnOne)
apply simp
apply(force intro:cptn.intros elim:cptn.cases)
done
lemma dropcptn_is_cptn [rule_format,elim!]:
"\<forall>j<length c. (\<Gamma>,c) \<in> cptn \<longrightarrow> (\<Gamma>, drop j c) \<in> cptn"
apply(induct "c")
apply(force elim: cptn.cases)
apply clarify
apply(case_tac j,simp+)
apply(erule cptn.cases)
apply simp
apply force
done
subsection\<open>Modular Definition of Computation\<close>
definition lift :: "('g\<times>'l,'p,'f,'e)com \<Rightarrow> ('g, 'l, 'p,'f,'e) config_gs \<Rightarrow> ('g, 'l, 'p,'f,'e) config_gs" where
"lift Q \<equiv> \<lambda>(P, s). ((Seq P Q), s)"
definition lift_catch :: "('g\<times>'l,'p,'f,'e)com \<Rightarrow> ('g, 'l, 'p,'f,'e) config_gs \<Rightarrow> ('g, 'l, 'p,'f,'e) config_gs" where
"lift_catch Q \<equiv> \<lambda>(P, s). (Catch P Q, s)"
lemma map_lift_eq_xs_xs':"map (lift a) xs = map (lift a) xs' \<Longrightarrow> xs=xs'"
proof (induct xs arbitrary: xs')
case Nil thus ?case by auto
next
case (Cons x xsa)
then have a0:"(lift a) x # map (lift a) xsa = map (lift a) (x # xsa)"
by fastforce
also obtain x' xsa' where xs':"xs' = x'#xsa'"
using Cons by auto
ultimately have a1:"map (lift a) (x # xsa) =map (lift a) (x' # xsa')"
using Cons by auto
then have xs:"xsa=xsa'" using a0 a1 Cons by fastforce
then have "(lift a) x' = (lift a) x" using a0 a1 by auto
then have "x' = x" unfolding lift_def
by (metis (no_types, lifting) LanguageCon.com.inject(3)
case_prod_beta old.prod.inject prod.collapse)
thus ?case using xs xs' by auto
qed
lemma map_lift_catch_eq_xs_xs':"map (lift_catch a) xs = map (lift_catch a) xs' \<Longrightarrow> xs=xs'"
proof (induct xs arbitrary: xs')
case Nil thus ?case by auto
next
case (Cons x xsa)
then have a0:"(lift_catch a) x # map (lift_catch a) xsa = map (lift_catch a) (x # xsa)"
by auto
also obtain x' xsa' where xs':"xs' = x'#xsa'"
using Cons by auto
ultimately have a1:"map (lift_catch a) (x # xsa) =map (lift_catch a) (x' # xsa')"
using Cons by auto
then have xs:"xsa=xsa'" using a0 a1 Cons by fastforce
then have "(lift_catch a) x' = (lift_catch a) x" using a0 a1 by auto
then have "x' = x" unfolding lift_catch_def
by (simp add: prod.case_eq_if prod_eq_iff)
thus ?case using xs xs' by auto
qed
lemma map_lift_all_seq:
assumes a0:"zs=map (lift a) xs" and
a1:"i<length zs"
shows "\<exists>b. fst (zs!i) = Seq b a"
using a0 a1
proof (induct zs arbitrary: xs i)
case Nil thus ?case by auto
next
case (Cons z1 zsa) thus ?case unfolding lift_def
proof -
assume a1: "z1 # zsa = map (\<lambda>b. case b of (P, s) \<Rightarrow> (LanguageCon.com.Seq P a, s)) xs"
have "\<forall>p c. \<exists>x. \<forall>pa ca xa.
(pa \<noteq> (ca::('a, 'b, 'c, 'd) LanguageCon.com, xa::('a, 'c) xstate) \<or> ca = fst pa) \<and>
((c::('a, 'b, 'c, 'd) LanguageCon.com) \<noteq> fst p \<or> (c, x::('a, 'c) xstate) = p)"
by fastforce
then obtain xx :: "('a, 'b, 'c, 'd) LanguageCon.com \<times> ('a, 'c) xstate \<Rightarrow> ('a, 'b, 'c, 'd) LanguageCon.com \<Rightarrow> ('a, 'c) xstate" where
"\<And>p c x ca pa. (p \<noteq> (c::('a, 'b, 'c, 'd) LanguageCon.com, x::('a, 'c) xstate) \<or> c = fst p) \<and> (ca \<noteq> fst pa \<or> (ca, xx pa ca) = pa)"
by (metis (full_types))
then show ?thesis
using a1 \<open>i < length (z1 # zsa)\<close>
by (simp add: Cons.hyps Cons.prems(1) case_prod_beta')
qed
qed
lemma map_lift_catch_all_catch:
assumes a0:"zs=map (lift_catch a) xs" and
a1:"i<length zs"
shows "\<exists>b. fst (zs!i) = Catch b a"
using a0 a1
proof (induct zs arbitrary: xs i)
case Nil thus ?case by auto
next
case (Cons z1 zsa) thus ?case unfolding lift_catch_def
proof -
assume a1: "z1 # zsa = map (\<lambda>b. case b of (P, s) \<Rightarrow> (LanguageCon.com.Catch P a, s)) xs"
have "\<forall>p c. \<exists>x. \<forall>pa ca xa.
(pa \<noteq> (ca::('a, 'b, 'c, 'd) LanguageCon.com, xa::('a, 'c) xstate) \<or> ca = fst pa) \<and>
((c::('a, 'b, 'c, 'd) LanguageCon.com) \<noteq> fst p \<or> (c, x::('a, 'c) xstate) = p)"
by fastforce
then obtain xx :: "('a, 'b, 'c, 'd) LanguageCon.com \<times> ('a, 'c) xstate \<Rightarrow> ('a, 'b, 'c, 'd) LanguageCon.com \<Rightarrow> ('a, 'c) xstate" where
"\<And>p c x ca pa. (p \<noteq> (c::('a, 'b, 'c, 'd) LanguageCon.com, x::('a, 'c) xstate) \<or> c = fst p) \<and> (ca \<noteq> fst pa \<or> (ca, xx pa ca) = pa)"
by (metis (full_types))
then show ?thesis
using a1 \<open>i < length (z1 # zsa)\<close>
by (simp add: Cons.hyps Cons.prems(1) case_prod_beta')
qed
qed
lemma map_lift_some_eq_pos:
assumes a0:"map (lift P) xs @ (P1, s1)#ys =
map (lift P) xs'@ (P2, s2)#ys'" and
a1:"\<forall>p0. P1\<noteq>Seq p0 P" and
a2:"\<forall>p0. P2\<noteq>Seq p0 P"
shows "length xs = length xs'"
proof -
{assume ass:"length xs \<noteq> length xs'"
{ assume ass:"length xs < length xs'"
then have False using a0 map_lift_all_seq a1 a2
by (metis (no_types, lifting) fst_conv length_map nth_append nth_append_length)
}note l=this
{ assume ass:"length xs > length xs'"
then have False using a0 map_lift_all_seq a1 a2
by (metis (no_types, lifting) fst_conv length_map nth_append nth_append_length)
} then have False using l ass by fastforce
}
thus ?thesis by auto
qed
lemma map_lift_some_eq:
assumes a0:"map (lift P) xs @ (P1, s1)#ys =
map (lift P) xs'@ (P2, s2)#ys'" and
a1:"\<forall>p0. P1\<noteq>Seq p0 P" and
a2:"\<forall>p0. P2\<noteq>Seq p0 P"
shows "xs' = xs \<and> ys = ys'"
proof -
have "length xs = length xs'" using a0 map_lift_some_eq_pos a1 a2 by blast
also have "xs' = xs" using a0 assms calculation map_lift_eq_xs_xs' by fastforce
ultimately show ?thesis using a0 by fastforce
qed
lemma map_lift_catch_some_eq_pos:
assumes a0:"map (lift_catch P) xs @ (P1, s1)#ys =
map (lift_catch P) xs'@ (P2, s2)#ys'" and
a1:"\<forall>p0. P1\<noteq>Catch p0 P" and
a2:"\<forall>p0. P2\<noteq>Catch p0 P"
shows "length xs = length xs'"
proof -
{assume ass:"length xs \<noteq> length xs'"
{ assume ass:"length xs < length xs'"
then have False using a0 map_lift_catch_all_catch a1 a2
by (metis (no_types, lifting) fst_conv length_map nth_append nth_append_length)
}note l=this
{ assume ass:"length xs > length xs'"
then have False using a0 map_lift_catch_all_catch a1 a2
by (metis (no_types, lifting) fst_conv length_map nth_append nth_append_length)
} then have False using l ass by fastforce
}
thus ?thesis by auto
qed
lemma map_lift_catch_some_eq:
assumes a0:"map (lift_catch P) xs @ (P1, s1)#ys =
map (lift_catch P) xs'@ (P2, s2)#ys'" and
a1:"\<forall>p0. P1\<noteq>Catch p0 P" and
a2:"\<forall>p0. P2\<noteq>Catch p0 P"
shows "xs' = xs \<and> ys = ys'"
proof -
have "length xs = length xs'" using a0 map_lift_catch_some_eq_pos a1 a2 by blast
also have "xs' = xs" using a0 assms calculation map_lift_catch_eq_xs_xs' by fastforce
ultimately show ?thesis using a0 by fastforce
qed
inductive_set cptn_mod :: "(('g,'l,'p,'f,'e) confs) set"
where
CptnModOne: "(\<Gamma>,[(P, s)]) \<in> cptn_mod"
| CptnModEnv: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,s) \<rightarrow>\<^sub>e (P,t);(\<Gamma>,(P, t)#xs) \<in> cptn_mod \<rbrakk> \<Longrightarrow>
(\<Gamma>,(P, s)#(P, t)#xs) \<in> cptn_mod"
| CptnModSkip: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,toSeq s) \<rightarrow> (Skip,toSeq t); redex P = P;
snd s = snd t;
(\<Gamma>,(Skip, t)#xs) \<in> cptn_mod \<rbrakk> \<Longrightarrow>
(\<Gamma>,(P,s)#(Skip, t)#xs) \<in>cptn_mod"
| CptnModThrow: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,toSeq s) \<rightarrow> (Throw,toSeq t); redex P = P;
snd s = snd t; (\<Gamma>,(Throw, t)#xs) \<in> cptn_mod \<rbrakk> \<Longrightarrow>
(\<Gamma>,(P,s)#(Throw, t)#xs) \<in>cptn_mod"
| CptnModStuck: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,toSeq s) \<rightarrow> (Stuck,toSeq t); redex P = P;
snd s = snd t; (\<Gamma>,(Stuck, t)#xs) \<in> cptn_mod \<rbrakk> \<Longrightarrow>
(\<Gamma>,(P,s)#(Stuck, t)#xs) \<in>cptn_mod"
| CptnModFault: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,toSeq s) \<rightarrow> (Fault f,toSeq t); redex P = P;
snd s = snd t; (\<Gamma>,(Fault f, t)#xs) \<in> cptn_mod \<rbrakk> \<Longrightarrow>
(\<Gamma>,(P,s)#(Fault f, t)#xs) \<in>cptn_mod"
| CptnModCondT: "\<lbrakk>(\<Gamma>,(P0, s)#ys) \<in> cptn_mod; fst s \<in> b \<rbrakk> \<Longrightarrow>
(\<Gamma>,((Cond b P0 P1), s)#(P0, s)#ys) \<in> cptn_mod"
| CptnModCondF: "\<lbrakk>(\<Gamma>,(P1, s)#ys) \<in> cptn_mod; fst s \<notin> b \<rbrakk> \<Longrightarrow>
(\<Gamma>,((Cond b P0 P1), s)#(P1, s)#ys) \<in> cptn_mod"
| CptnModSeq1:
"\<lbrakk>(\<Gamma>,(P0, s)#xs) \<in> cptn_mod; zs=map (lift P1) xs \<rbrakk> \<Longrightarrow>
(\<Gamma>,((Seq P0 P1), s)#zs) \<in> cptn_mod"
| CptnModSeq2:
"\<lbrakk>(\<Gamma>, (P0, s)#xs) \<in> cptn_mod; fst(last ((P0, s)#xs)) = Skip;
(\<Gamma>,(P1, snd(last ((P0, s)#xs)))#ys) \<in> cptn_mod;
zs=(map (lift P1) xs)@((P1, snd(last ((P0, s)#xs)))#ys) \<rbrakk> \<Longrightarrow>
(\<Gamma>,((Seq P0 P1), s)#zs) \<in> cptn_mod"
(*| CptnModSeq3:
"\<lbrakk> (\<Gamma>,(P1, s)#xs) \<in> cptn_mod\<rbrakk> \<Longrightarrow> (\<Gamma>,((Seq Skip P1), s)#(P1, s)#xs) \<in> cptn_mod"*)
| CptnModSeq3:
"\<lbrakk>(\<Gamma>, (P0, s)#xs) \<in> cptn_mod;
fst(last ((P0, s)#xs)) = t;
t = Fault f \<or> t = Stuck \<or> t = Throw;
snd(last ((P0, s)#xs)) = s';
(\<Gamma>,(t, s')#ys) \<in> cptn_mod;
zs=(map (lift P1) xs)@((t, s')#ys) \<rbrakk> \<Longrightarrow>
(\<Gamma>,((Seq P0 P1), s)#zs) \<in> cptn_mod"
| CptnModWhile1:
"\<lbrakk>(\<Gamma>, (P, s)#xs) \<in> cptn_mod; fst s \<in> b;
zs=map (lift (While b P)) xs \<rbrakk> \<Longrightarrow>
(\<Gamma>, ((While b P), s)#
((Seq P (While b P)), s)#zs) \<in> cptn_mod"
| CptnModWhile2:
"\<lbrakk> (\<Gamma>, (P, s)#xs) \<in> cptn_mod;
fst(last ((P, s)#xs))=Skip; fst s \<in> b;
zs=(map (lift (While b P)) xs)@
(While b P, snd(last ((P, s)#xs)))#ys;
(\<Gamma>,(While b P, snd(last ((P, s)#xs)))#ys) \<in> cptn_mod\<rbrakk> \<Longrightarrow>
(\<Gamma>,(While b P, s)#
(Seq P (While b P), s)#zs) \<in> cptn_mod"
| CptnModWhile3:
"\<lbrakk> (\<Gamma>, (P, s)#xs) \<in> cptn_mod;
fst(last ((P, s)#xs))=t; t=Throw \<or> t= Fault f \<or> t = Stuck; fst s \<in> b;
snd(last ((P, s)#xs)) = s';
(\<Gamma>,(t, s')#ys) \<in> cptn_mod;
zs=(map (lift (While b P)) xs)@((t, s')#ys)\<rbrakk> \<Longrightarrow>
(\<Gamma>,(While b P, s)#
(Seq P (While b P), s)#zs) \<in> cptn_mod"
| CptnModCall: "\<lbrakk>(\<Gamma>,(bdy, s)#ys) \<in> cptn_mod;\<Gamma> p = Some bdy; bdy\<noteq>Call p \<rbrakk> \<Longrightarrow>
(\<Gamma>,((Call p), s)#(bdy, s)#ys) \<in> cptn_mod"
| CptnModDynCom: "\<lbrakk>(\<Gamma>,(c (fst s), s)#ys) \<in> cptn_mod \<rbrakk> \<Longrightarrow>
(\<Gamma>,(DynCom c, s)#(c (fst s), s)#ys) \<in> cptn_mod"
| CptnModGuard: "\<lbrakk>(\<Gamma>,(c, s)#ys) \<in> cptn_mod; fst s \<in> g \<rbrakk> \<Longrightarrow>
(\<Gamma>,(Guard f g c, s)#(c, s)#ys) \<in> cptn_mod"
| CptnModCatch1: "\<lbrakk>(\<Gamma>,(P0, s)#xs) \<in> cptn_mod; zs=map (lift_catch P1) xs \<rbrakk>
\<Longrightarrow> (\<Gamma>,((Catch P0 P1), s)#zs) \<in> cptn_mod"
| CptnModCatch2:
"\<lbrakk>(\<Gamma>, (P0, s)#xs) \<in> cptn_mod; fst(last ((P0, s)#xs)) = t;
t = Skip \<or> t = Fault f \<or> t=Stuck;
(\<Gamma>,(t,snd(last ((P0, s)#xs)))#ys) \<in> cptn_mod;
zs=(map (lift_catch P1) xs)@((t,snd(last ((P0, s)#xs)))#ys) \<rbrakk> \<Longrightarrow>
(\<Gamma>,((Catch P0 P1), s)#zs) \<in> cptn_mod"
| CptnModCatch3:
"\<lbrakk>(\<Gamma>, (P0, s)#xs) \<in> cptn_mod; fst(last ((P0, s)#xs)) = Throw;
snd(last ((P0, s)#xs)) = s';
(\<Gamma>,(P1, snd(last ((P0, s)#xs)))#ys) \<in> cptn_mod;
zs=(map (lift_catch P1) xs)@((P1, snd(last ((P0, s)#xs)))#ys) \<rbrakk> \<Longrightarrow>
(\<Gamma>,((Catch P0 P1), s)#zs) \<in> cptn_mod"
lemmas CptnMod_induct = cptn_mod.induct [of _ "[(c,s)]", split_format (complete), case_names
CptnModOne CptnModEnv CptnModSkip CptnModThrow CptnModStuck CptnModFault
CptnModCondT CptnModCondF CptnModSeq1 CptnModSeq2 CptnModSeq3 CptnModWhile1
CptnModWhile2 CptnModWhile3 CptnModCall CptnModDynCom CptnModGuard
CptnModCatch1 CptnModCatch2 CptnModCatch3, induct set]
inductive_cases CptnMod_elim_cases [cases set]:
"(\<Gamma>,(Skip, s)#u#xs) \<in> cptn_mod"
"(\<Gamma>,(Guard f g c, s)#u#xs) \<in> cptn_mod"
"(\<Gamma>,(Basic f e, s)#u#xs) \<in> cptn_mod"
"(\<Gamma>,(Spec r e, s)#u#xs) \<in> cptn_mod"
"(\<Gamma>,(Seq c1 c2, s)#u#xs) \<in> cptn_mod"
"(\<Gamma>,(Cond b c1 c2, s)#u#xs) \<in> cptn_mod"
"(\<Gamma>,(Await b c2 e, s)#u#xs) \<in> cptn_mod"
"(\<Gamma>,(Call p, s)#u#xs) \<in> cptn_mod"
"(\<Gamma>,(DynCom c,s)#u#xs) \<in> cptn_mod"
"(\<Gamma>,(Throw,s)#u#xs) \<in> cptn_mod"
"(\<Gamma>,(Catch c1 c2,s)#u#xs) \<in> cptn_mod"
"(\<Gamma>,(Fault f,s)#u#xs) \<in> cptn_mod"
"(\<Gamma>,(Stuck,s)#u#xs) \<in> cptn_mod"
inductive_cases CptnMod_env_elim_cases [cases set]:
"(\<Gamma>,(P, s)#(P,s')#xs) \<in> cptn_mod"
subsection \<open>Equivalence of small semantics and computational\<close>
definition catch_cond
where
"catch_cond zs Q xs P s s'' s' \<Gamma> \<equiv> (zs=(map (lift_catch Q) xs) \<or>
((fst(((P, s)#xs)!length xs)=Throw \<and>
snd(last ((P, s)#xs)) = s' \<and> s= s''\<and>
(\<exists>ys. (\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod \<and>
zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or>
(\<exists>t. (fst(((P, s)#xs)!length xs)=t \<and> (t=Skip \<or> (\<exists>f. t = Fault f) \<or> t = Stuck) \<and>
(\<exists>ys. (\<Gamma>,(t,snd(last ((P, s)#xs)))#ys) \<in> cptn_mod \<and>
zs=(map (lift_catch Q) xs)@((t,snd(last ((P, s)#xs)))#ys)))))
"
lemma div_catch: assumes cptn_m:"(\<Gamma>,list) \<in> cptn_mod"
shows "(\<forall>s P Q zs. list=(Catch P Q, s)#zs \<longrightarrow>
(\<exists>xs s' s''.
(\<Gamma>,(P, s)#xs) \<in> cptn_mod \<and>
catch_cond zs Q xs P s s'' s' \<Gamma>))"
unfolding catch_cond_def
using cptn_m
proof (induct rule: cptn_mod.induct)
case (CptnModOne \<Gamma> P s)
thus ?case using cptn_mod.CptnModOne by blast
next
case (CptnModSkip \<Gamma> P s t xs)
from CptnModSkip.hyps
have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Skip, toSeq t)" by auto
thus ?case
using CptnModSkip.hyps(2) redex_not_Catch by fast
next
case (CptnModThrow \<Gamma> P s t xs)
from CptnModThrow.hyps
have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Throw, toSeq t)" by auto
thus ?case
using CptnModThrow.hyps(2) redex_not_Catch by fast
next
case (CptnModFault \<Gamma> P s f t xs)
thus ?case
using redex_not_Catch by force
next
case (CptnModStuck \<Gamma> P s t xs)
thus ?case using redex_not_Catch by force
next
case (CptnModCondT \<Gamma> P0 s ys b P1)
thus ?case using CptnModOne by fast
next
case (CptnModCondF \<Gamma> P0 s ys b P1)
thus ?case using CptnModOne by fast
next
case (CptnModCatch1 sa P Q zs)
thus ?case by fast
next
case (CptnModCatch2 \<Gamma> P0 s xs t f ys zs P1)
from CptnModCatch2.hyps(3)
have last:"fst (((P0, s) # xs) ! length xs) = Skip \<or>
fst (((P0, s) # xs) ! length xs) = Stuck \<or>
(\<exists>f. fst (((P0, s) # xs) ! length xs) = Fault f)"
by (metis CptnModCatch2.hyps(4) last_length)
have P0cptn:"(\<Gamma>, (P0, s) # xs) \<in> cptn_mod" by fact
then have "zs = map (lift_catch P1) xs @((Skip, (snd(last ((P0, s)#xs))))#ys) \<or>
zs = map (lift_catch P1) xs @((Stuck, (snd(last ((P0, s)#xs))))#ys)\<or>
(\<exists>f. zs = map (lift_catch P1) xs @((Fault f, (snd(last ((P0, s)#xs))))#ys))"
using CptnModCatch2.hyps(4) CptnModCatch2.hyps(7) by auto
show ?case
proof -{
fix sa P Q zsa
assume eq:"(Catch P0 P1, s) # zs = (Catch P Q, sa) # zsa"
then have "P0 =P \<and> P1 = Q \<and> s=sa \<and> zs=zsa" by auto
then have "(P0, s) = (P, sa)" by auto
have "last ((P0, s) # xs) = ((P, sa) # xs) ! length xs"
by (simp add: `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa` last_length)
then have "zs = (map (lift_catch Q) xs)@((t,snd(last ((P0, s)#xs)))#ys)"
by (simp add: CptnModCatch2.hyps(7) \<open>P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa\<close>)
then have "\<exists>xs s' s''.
(\<Gamma>, (P, s) # xs) \<in> cptn_mod \<and>
(zs = map (lift_catch Q) xs \<or>
fst (((P, s) # xs) ! length xs) = LanguageCon.com.Throw \<and>
snd (last ((P, s) # xs)) = s' \<and>
s = s'' \<and>
(\<exists>ys. (\<Gamma>, (Q, snd (((P, s) # xs) ! length xs)) # ys) \<in> cptn_mod \<and>
zs =
map (lift_catch Q) xs @ (Q, snd (((P, s) # xs) ! length xs)) # ys) \<or>
(\<exists>t. fst (((P, s) # xs) ! length xs) = t \<and>
(t = LanguageCon.com.Skip \<or> (\<exists>f. t = com.Fault f) \<or> t = com.Stuck) \<and>
(\<exists>ys. (\<Gamma>, (t, snd (last ((P, s) # xs))) # ys) \<in> cptn_mod \<and>
zs =
map (lift_catch Q) xs @
(t, snd (last ((P, s) # xs))) # ys)))"
using P0cptn `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa`
last CptnModCatch2.hyps(4)
by (metis CptnModCatch2.hyps(3) CptnModCatch2.hyps(5) last_length)
}
thus ?thesis by auto
qed
next
case (CptnModCatch3 \<Gamma> P0 s xs s' P1 ys zs)
from CptnModCatch3.hyps(3)
have last:"fst (((P0, s) # xs) ! length xs) = Throw"
by (simp add: last_length)
from CptnModCatch3.hyps(4)
have lastnormal:"snd (last ((P0, s) # xs)) = s'"
by (simp add: last_length)
have P0cptn:"(\<Gamma>, (P0, s) # xs) \<in> cptn_mod" by fact
from CptnModCatch3.hyps(5) have P1cptn:"(\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod"
by (simp add: last_length)
then have "zs = map (lift_catch P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys"
by (simp add:CptnModCatch3.hyps)
show ?case
by (metis CptnModCatch3.hyps(3) CptnModCatch3.hyps(5) CptnModCatch3.hyps(7)
LanguageCon.com.inject(10) P0cptn fst_conv last_length
lastnormal list.inject snd_conv)
next
case (CptnModEnv \<Gamma> P s t xs)
then have step:"(\<Gamma>, (P, t) # xs) \<in> cptn_mod" by auto
have step_e: "\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (P, t)" using CptnModEnv by auto
show ?case
proof (cases P)
case (Catch P1 P2)
then have eq_P_Catch:"(P, t) # xs = (LanguageCon.com.Catch P1 P2, t) # xs" by auto
then obtain xsa t' t'' where
p1:"(\<Gamma>, (P1, t) # xsa) \<in> cptn_mod" and p2:"
(xs = map (lift_catch P2) xsa \<or>
fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \<and>
snd (last ((P1, t) # xsa)) = t' \<and>
t = t'' \<and>
(\<exists>ys. (\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<in> cptn_mod \<and>
xs = map (lift_catch P2) xsa @
(P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<or>
(\<exists>c. fst (((P1, t) # xsa) ! length xsa) = c \<and>
(c = Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
(\<exists>ys.(\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \<in> cptn_mod \<and>
xs = map (lift_catch P2) xsa @
((c, snd (last ((P1, t) # xsa)))#ys))))"
using CptnModEnv(3) by fastforce
have all_step:"(\<Gamma>, (P1, s)#((P1, t) # xsa)) \<in> cptn_mod"
using cptn_mod.CptnModEnv p1 step_e by (metis env_intro_diff_p)
show ?thesis using p2
proof
assume "xs = map (lift_catch P2) xsa"
have "(P, t) # xs = map (lift_catch P2) ((P1, t) # xsa)"
by (simp add: `xs = map (lift_catch P2) xsa` lift_catch_def local.Catch)
thus ?thesis using all_step eq_P_Catch by fastforce
next
assume
"fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \<and> snd (last ((P1, t) # xsa)) = t' \<and>
t = t'' \<and> (\<exists>ys. (\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<in> cptn_mod \<and>
xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<or>
(\<exists>c. fst (((P1, t) # xsa) ! length xsa) = c \<and>
(c = Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
(\<exists>ys.(\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \<in> cptn_mod \<and>
xs = map (lift_catch P2) xsa @ ((c, snd (last ((P1, t) # xsa)))#ys)))"
then show ?thesis
proof
assume
a1:"fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \<and> snd (last ((P1, t) # xsa)) = t' \<and>
t = t'' \<and> (\<exists>ys. (\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<in> cptn_mod \<and>
xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys)"
then obtain ys where p2_exec:"(\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<in> cptn_mod \<and>
xs = map (lift_catch P2) xsa @
(P2, snd (((P1, t) # xsa) ! length xsa)) # ys"
by fastforce
from a1 obtain t1 where t_normal: "t= t1" by blast
have f1:"fst (((P1, s)#(P1, t) # xsa) ! length ((P1, t)#xsa)) = LanguageCon.com.Throw"
using a1 by fastforce
from a1 have last_normal: "snd (last ((P1, s)#(P1, t) # xsa)) = t'"
by fastforce
then have p2_long_exec: "(\<Gamma>, (P2, snd (((P1, s)#(P1, t) # xsa) ! length ((P1, s)#xsa))) # ys) \<in> cptn_mod \<and>
(P, t)#xs = map (lift_catch P2) ((P1, t) # xsa) @
(P2, snd (((P1, s)#(P1, t) # xsa) ! length ((P1, s)#xsa))) # ys" using p2_exec
by (simp add: lift_catch_def local.Catch)
thus ?thesis using a1 f1 last_normal all_step eq_P_Catch by fastforce
next
assume as1:"\<exists>c. fst (((P1, t) # xsa) ! length xsa) = c \<and>
(c = Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
(\<exists>ys.(\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \<in> cptn_mod \<and>
xs = map (lift_catch P2) xsa @ ((c, snd (last ((P1, t) # xsa)))#ys))"
then obtain c where as1:"fst (((P1, t) # xsa) ! length xsa) = c \<and>
(c = Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
(\<exists>ys.(\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \<in> cptn_mod \<and>
xs = map (lift_catch P2) xsa @ ((c, snd (last ((P1, t) # xsa)))#ys))"
by auto
then have c:"c = Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck" by auto
then obtain ys where p1:"(\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \<in> cptn_mod \<and>
(P, t)#xs = map (lift_catch P2) ((P1, t) # xsa) @
((c, snd (last ((P1, t) # xsa)))#ys)"
proof -
assume a1: "\<And>ys. (\<Gamma>, (c, snd (last ((P1, t) # xsa))) # ys) \<in> cptn_mod \<and> (P, t) # xs = map (lift_catch P2) ((P1, t) # xsa) @ (c, snd (last ((P1, t) # xsa))) # ys \<Longrightarrow> thesis"
have "(LanguageCon.com.Catch P1 P2, t) # map (lift_catch P2) xsa = map (lift_catch P2) ((P1, t) # xsa)"
by (simp add: lift_catch_def)
thus ?thesis
using a1 as1 eq_P_Catch by fastforce
qed
show ?thesis using p1 as1 all_step eq_P_Catch
by fastforce
qed
qed
qed (auto)
qed(force+)
definition seq_cond
where
"seq_cond zs Q xs P s s'' s' \<Gamma> \<equiv> (zs=(map (lift Q) xs) \<or>
((fst(((P, s)#xs)!length xs)=Skip \<and>
(\<exists>ys. (\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod \<and>
zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or>
(\<exists>t. (fst(((P, s)#xs)!length xs)=t \<and> (t=Throw \<or> t=Stuck \<or> (\<exists>f. t = Fault f)) \<and>
snd(last ((P, s)#xs)) = s' \<and> s= s''\<and>
(\<exists>ys. (\<Gamma>,(t, s')#ys) \<in> cptn_mod \<and> zs=(map (lift Q) xs)@((t, s')#ys)))))
"
lemma div_seq: assumes cptn_m:"(\<Gamma>,list) \<in> cptn_mod"
shows "(\<forall>s P Q zs. list=(Seq P Q, s)#zs \<longrightarrow>
(\<exists>xs s' s''.
(\<Gamma>,(P, s)#xs) \<in> cptn_mod \<and>
seq_cond zs Q xs P s s'' s' \<Gamma>))
"
unfolding seq_cond_def
using cptn_m
proof (induct rule: cptn_mod.induct)
case (CptnModOne \<Gamma> P s)
thus ?case using cptn_mod.CptnModOne by blast
next
case (CptnModSkip \<Gamma> P s t xs)
from CptnModSkip.hyps
have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Skip, toSeq t)" by auto
from CptnModSkip.hyps
have noskip: "~(P=Skip)" using stepc_elim_cases(1)
by (metis (no_types) local.step stepc_elim_cases(1))
have x: "\<forall>c c1 c2. redex c = Seq c1 c2 \<Longrightarrow> False"
using redex_not_Seq by blast
from CptnModSkip.hyps
have in_cptn_mod: "(\<Gamma>, (Skip, t) # xs) \<in> cptn_mod" by auto
then show ?case using CptnModSkip.hyps(2) SmallStepCon.redex_not_Seq
by (metis fst_conv list.inject)
next
case (CptnModThrow \<Gamma> P s t xs)
from CptnModThrow.hyps
have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Throw, toSeq t)" by auto
moreover from CptnModThrow.hyps
have in_cptn_mod: "(\<Gamma>, (Throw, t) # xs) \<in> cptn_mod" by auto
have no_seq: "\<forall>p1 p2. \<not>(P=Seq p1 p2)"
using CptnModThrow.hyps(2) redex_not_Seq by auto
ultimately show ?case by auto
next case (CptnModStuck \<Gamma> P s t xs)
thus ?case
by (metis Pair_inject SmallStepCon.redex_not_Seq list.inject)
next case (CptnModFault \<Gamma> P s f t xs)
thus ?case
by (metis Pair_inject SmallStepCon.redex_not_Seq list.inject)
next
case (CptnModCondT \<Gamma> P0 s ys b P1)
thus ?case by auto
next
case (CptnModCondF \<Gamma> P0 s ys b P1)
thus ?case by auto
next
case (CptnModSeq1 \<Gamma> P0 s xs zs P1)
thus ?case by blast
next
case (CptnModSeq2 \<Gamma> P0 s xs P1 ys zs)
from CptnModSeq2.hyps(3) last_length have last:"fst (((P0, s) # xs) ! length xs) = Skip"
by (simp add: last_length)
have P0cptn:"(\<Gamma>, (P0, s) # xs) \<in> cptn_mod" by fact
from CptnModSeq2.hyps(4) have P1cptn:"(\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod"
by (simp add: last_length)
then have "zs = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys" by (simp add:CptnModSeq2.hyps)
show ?case
proof -{
fix sa P Q zsa
assume eq:"(Seq P0 P1, s) # zs = (Seq P Q, sa) # zsa"
then have "P0 =P \<and> P1 = Q \<and> s=sa \<and> zs=zsa" by auto
have "last ((P0, s) # xs) = ((P, sa) # xs) ! length xs"
by (simp add: `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa` last_length)
then have "zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys"
using `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa` `zs = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys`
by force
then have "\<exists>xs s' s''.
(\<Gamma>, (P, s) # xs) \<in> cptn_mod \<and>
(zs = map (lift Q) xs \<or>
fst (((P, s) # xs) ! length xs) = LanguageCon.com.Skip \<and>
(\<exists>ys. (\<Gamma>, (Q, snd (((P, s) # xs) ! length xs)) # ys) \<in> cptn_mod \<and>
zs = map (lift Q) xs @ (Q, snd (((P, s) # xs) ! length xs)) # ys) \<or>
(\<exists>t. fst (((P, s) # xs) ! length xs) = t \<and>
(t = LanguageCon.com.Throw \<or> t = com.Stuck \<or> (\<exists>f. t = com.Fault f)) \<and>
snd (last ((P, s) # xs)) = s' \<and>
s = s'' \<and>
(\<exists>ys. (\<Gamma>, (t, s') # ys) \<in> cptn_mod \<and>
zs = map (lift Q) xs @ (t, s') # ys)))"
using P0cptn P1cptn `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa` last
by blast
}
thus ?case by auto qed
next
case (CptnModSeq3 \<Gamma> P0 s xs t f s' ys zs P1)
from CptnModSeq3.hyps(3)
obtain c where
last:"fst (((P0, s) # xs) ! length xs) = c \<and>
(c = Throw \<or> c = Stuck \<or> (\<exists>f. c = Fault f))"
by (metis CptnModSeq3.hyps(4) last_length)
have P0cptn:"(\<Gamma>, (P0, s) # xs) \<in> cptn_mod" by fact
from CptnModSeq3.hyps(5)
have lastnormal:"snd (last ((P0, s) # xs)) = s'"
by blast
then have "zs = map (lift P1) xs @ ((c, s')#ys)"
by (metis CptnModSeq3.hyps(3) CptnModSeq3.hyps(8) last last_length)
show ?case
proof -{
fix sa P Q zsa
assume eq:"(Seq P0 P1, s) # zs = (Seq P Q, sa) # zsa"
then have "P0 =P \<and> P1 = Q \<and> s= sa \<and> zs=zsa" by auto
then have "(P0, s) = (P, sa)" by auto
have "last ((P0, s) # xs) = ((P, sa) # xs) ! length xs"
by (simp add: `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa` last_length)
then have zsa:"zsa = (map (lift Q) xs)@((c, s')#ys)"
using `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa`
`zs = map (lift P1) xs @ ((c, s')#ys)`
by force
then have a1:"(\<Gamma>,(c, s')#ys) \<in> cptn_mod" using CptnModSeq3.hyps(6)
using CptnModSeq3.hyps(3) \<open>(P0, s) = (P, sa)\<close>
\<open>last ((P0, s) # xs) = ((P, sa) # xs) ! length xs\<close> last by auto
then have "(\<exists>xs s' s''. (\<Gamma>, (P, sa) # xs) \<in> cptn_mod \<and>
(zsa = map (lift Q) xs \<or>
fst (((P, sa) # xs) ! length xs) = LanguageCon.com.Skip \<and>
(\<exists>ys. (\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<in> cptn_mod \<and>
zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<or>
(\<exists>t. fst (((P, sa) # xs) ! length xs) = t \<and>
(t = LanguageCon.com.Throw \<or> t = com.Stuck \<or> (\<exists>f. t = com.Fault f)) \<and>
snd (last ((P, sa) # xs)) = s' \<and>
sa = s'' \<and>
(\<exists>ys. (\<Gamma>, (t, s') # ys) \<in> cptn_mod \<and>
zsa = map (lift Q) xs @ (t, s') # ys))))"
using P0cptn zsa a1 last lastnormal
using \<open>P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa\<close> by blast
}
thus ?thesis by fastforce qed
next
case (CptnModEnv \<Gamma> P s t zs)
then have step:"(\<Gamma>, (P, t) # zs) \<in> cptn_mod" by auto
have step_e: "\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (P, t)" using CptnModEnv by auto
show ?case
proof (cases P)
case (Seq P1 P2)
then have eq_P:"(P, t) # zs = (LanguageCon.com.Seq P1 P2, t) # zs" by auto
then obtain xs t' t'' c where
p1:"(\<Gamma>, (P1, t) # xs) \<in> cptn_mod" and
p2:"(zs = map (lift P2) xs \<or>
fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \<and>
(\<exists>ys. (\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<in> cptn_mod \<and>
zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<or>
fst (((P1, t) # xs) ! length xs) =c \<and> (c = Throw \<or> c = Stuck \<or> (\<exists>f. c = Fault f)) \<and>
snd (last ((P1, t) # xs)) = t' \<and>
t = t'' \<and> (\<exists>ys. (\<Gamma>,(c, t')#ys) \<in> cptn_mod \<and>
zs = map (lift P2) xs @ ((c, t')#ys))) "
using CptnModEnv(3) by fastforce
have all_step:"(\<Gamma>, (P1, s)#((P1, t) # xs)) \<in> cptn_mod"
using cptn_mod.CptnModEnv p1 step_e
by (metis env_intro_diff_p)
show ?thesis using p2
proof
assume "zs = map (lift P2) xs"
have "(P, t) # zs = map (lift P2) ((P1, t) # xs)"
by (simp add: `zs = map (lift P2) xs` lift_def local.Seq)
thus ?thesis using all_step eq_P by fastforce
next
assume
"(fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \<and>
(\<exists>ys. (\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<in> cptn_mod \<and>
zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<or>
fst (((P1, t) # xs) ! length xs) =c \<and> (c = Throw \<or> c = Stuck \<or> (\<exists>f. c = Fault f)) \<and>
snd (last ((P1, t) # xs)) = t' \<and> t = t'' \<and> (\<exists>ys. (\<Gamma>,(c, t')#ys) \<in> cptn_mod \<and>
zs = map (lift P2) xs @ ((c, t')#ys))) "
then show ?thesis
proof
assume
a1:"fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \<and>
(\<exists>ys. (\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<in> cptn_mod \<and>
zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys)"
from a1 obtain ys where
p2_exec:"(\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<in> cptn_mod \<and>
zs = map (lift P2) xs @
(P2, snd (((P1, t) # xs) ! length xs)) # ys"
by auto
have f1:"fst (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs)) = LanguageCon.com.Skip"
using a1 by fastforce
then have p2_long_exec:
"(\<Gamma>, (P2, snd (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs))) # ys) \<in> cptn_mod \<and>
(P, t)#zs = map (lift P2) ((P1, t) # xs) @
(P2, snd (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs))) # ys"
using p2_exec by (simp add: lift_def local.Seq)
thus ?thesis using a1 f1 all_step eq_P by blast
next
assume
a1:"fst (((P1, t) # xs) ! length xs) =c \<and> (c = Throw \<or> c = Stuck \<or> (\<exists>f. c = Fault f)) \<and>
snd (last ((P1, t) # xs)) = t' \<and> t = t'' \<and> (\<exists>ys. (\<Gamma>,(c, t')#ys) \<in> cptn_mod \<and>
zs = map (lift P2) xs @ ((c, t')#ys))"
then have last_throw:
"fst (((P1, s)#(P1, t) # xs) ! length ((P1, t) #xs)) = c"
by fastforce
from a1 have last_normal: "snd (last ((P1, s)#(P1, t) # xs)) = t'"
by fastforce
have seq_lift:
"(LanguageCon.com.Seq P1 P2, t) # map (lift P2) xs = map (lift P2) ((P1, t) # xs)"
by (simp add: a1 lift_def)
thus ?thesis using a1 last_throw last_normal all_step eq_P
by (clarify, metis (no_types, lifting) append_Cons )
qed
qed
qed (auto)
qed (force)+
lemma cptn_onlyif_cptn_mod_aux:
assumes vars:"v = toSeq s" and vars1:"w = toSeq t" and stepseq:"\<Gamma>\<turnstile>\<^sub>c (P,v) \<rightarrow> (Q,w)" and
normal_eq_l:"snd s = snd t" and
stepmod:"(\<Gamma>,(Q,t)#xs) \<in> cptn_mod"
shows "(\<Gamma>,(P,s)#(Q,t)#xs) \<in> cptn_mod"
using stepseq normal_eq_l stepmod vars vars1
proof (induct arbitrary: xs)
case (Basicc f e s1)
thus ?case using stepc.Basicc[of \<Gamma> f e s1]
by (simp add: cptn_mod.CptnModSkip)
next
case (Specc s1 t1 r)
thus ?case using stepc.Specc[of s1 t1 r \<Gamma>] by (simp add: cptn_mod.CptnModSkip)
next
case (SpecStuckc s1 r)
thus ?case using stepc.SpecStuckc[of s1 _ \<Gamma>] by (simp add: cptn_mod.CptnModStuck)
next
case (Guardc s1 g f c)
thus ?case
by (metis cptn_modp.CptnModGuard cptn_modp_cptn_mod_eq prod.exhaust_sel toSeq.simps)
next
case (GuardFaultc)
thus ?case
by (simp add: cptn_mod.CptnModFault stepc.GuardFaultc)
next
case (Seqc c1 s1 c1' t1 c2)
have step: "\<Gamma>\<turnstile>\<^sub>c (c1, s1) \<rightarrow> (c1', t1)" by (simp add: Seqc.hyps(1))
then have nsc1: "c1\<noteq>Skip"
using stepc_elim_cases(1) by auto
have assum: "(\<Gamma>, (Seq c1' c2, t) # xs) \<in> cptn_mod" using Seqc.prems by blast
have divseq:"(\<forall>s P Q zs. (Seq c1' c2, t) # xs=(Seq P Q, s)#zs \<longrightarrow>
(\<exists>xs sv' sv''.
((\<Gamma>,(P, s)#xs) \<in> cptn_mod \<and>
(zs=(map (lift Q) xs) \<or>
((fst(((P, s)#xs)!length xs)=Skip \<and>
(\<exists>ys. (\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod \<and>
zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or>
(\<exists>c. (fst(((P, s)#xs)!length xs)=c \<and> (c=Throw \<or> c=Stuck \<or> (\<exists>f. c = Fault f)) \<and>
snd(last ((P, s)#xs)) = sv' \<and> t= sv''\<and>
(\<exists>ys. (\<Gamma>,(c, sv')#ys) \<in> cptn_mod \<and> zs=(map (lift Q) xs)@((c, sv')#ys))))))))"
using div_seq [OF assum] unfolding seq_cond_def by auto
{ fix sa P Q zsa
assume ass:"(Seq c1' c2, t) # xs = (Seq P Q, sa) # zsa"
then have eqs:"c1' = P \<and> c2 = Q \<and> t = sa \<and> xs = zsa" by auto
then have "\<exists>xs sv' sv''.
(\<Gamma>, (P, sa) # xs) \<in> cptn_mod \<and>
(zsa = map (lift Q) xs \<or>
fst (((P, sa) # xs) ! length xs) = Skip \<and>
(\<exists>ys. (\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<in> cptn_mod \<and>
zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<or>
(\<exists>c. (fst(((P, sa)#xs)!length xs)=c \<and> (c=Throw \<or> c=Stuck \<or> (\<exists>f. c = Fault f))\<and>
snd(last ((P, sa)#xs)) = sv' \<and> t= sv''\<and>
(\<exists>ys. (\<Gamma>,(c, sv')#ys) \<in> cptn_mod \<and> zsa=(map (lift Q) xs)@((c, sv')#ys)))))"
using ass divseq by blast
} note conc=this [of c1' c2 t xs]
then obtain xs' sa' sa''
where split:"(\<Gamma>, (c1', t) # xs') \<in> cptn_mod \<and>
(xs = map (lift c2) xs' \<or>
fst (((c1', t) # xs') ! length xs') = Skip \<and>
(\<exists>ys. (\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and>
xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or>
(\<exists>c. (fst(((c1', t)#xs')!length xs')=c \<and> (c=Throw \<or> c=Stuck \<or> (\<exists>f. c = Fault f)) \<and>
snd(last ((c1', t)#xs')) = sa' \<and> t= sa''\<and>
(\<exists>ys. (\<Gamma>,(c, sa')#ys) \<in> cptn_mod \<and>
xs=(map (lift c2) xs')@((c, sa')#ys)))))" by blast
then have "xs = map (lift c2) xs' \<or>
fst (((c1', t) # xs') ! length xs') = Skip \<and>
(\<exists>ys. (\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and>
xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or>
(\<exists>c. (fst(((c1', t)#xs')!length xs')=c \<and> (c=Throw \<or> c=Stuck \<or> (\<exists>f. c = Fault f)) \<and>
snd(last ((c1',t)#xs')) = sa' \<and> t= sa''\<and>
(\<exists>ys. (\<Gamma>,(c, sa')#ys) \<in> cptn_mod \<and>
xs=(map (lift c2) xs')@((c, sa')#ys))))" by auto
thus ?case
proof{
assume c1'nonf:"xs = map (lift c2) xs'"
then have c1'cptn:"(\<Gamma>, (c1', t) # xs') \<in> cptn_mod" using split by blast
then have induct_step: "(\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod"
using Seqc.hyps(2)
using Seqc.prems(3) Seqc.prems(4) normal_eq_l by blast
then have "(Seq c1' c2, t)#xs = map (lift c2) ((c1', t)#xs')"
using c1'nonf
by (simp add: CptnModSeq1 lift_def)
thus ?thesis
using c1'nonf c1'cptn induct_step by (auto simp add: CptnModSeq1)
next
assume "fst (((c1', t) # xs') ! length xs') = Skip \<and>
(\<exists>ys. (\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and>
xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or>
(\<exists>c. (fst(((c1', t)#xs')!length xs')=c \<and> (c=Throw \<or> c=Stuck \<or> (\<exists>f. c = Fault f)) \<and>
snd(last ((c1', t)#xs')) = sa' \<and> t= sa''\<and>
(\<exists>ys. (\<Gamma>,(c, sa')#ys) \<in> cptn_mod \<and> xs=(map (lift c2) xs')@((c, sa')#ys))))"
thus ?thesis
proof
assume assth:
"fst (((c1', t) # xs') ! length xs') = Skip \<and>
(\<exists>ys. (\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and>
xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys)"
then obtain ys where split':
"(\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and>
xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys"
by auto
then have c1'cptn:"(\<Gamma>, (c1', t) # xs') \<in> cptn_mod" using split by blast
then have induct_step: "(\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod"
using Seqc.hyps(2)
using Seqc.prems(3) Seqc.prems(4) normal_eq_l by blast
then have seqmap:"(Seq c1 c2, s)#(Seq c1' c2, t)#xs = map (lift c2) ((c1,s)#(c1', t)#xs') @ (c2, snd (((c1', t) # xs') ! length xs')) # ys"
using split'
by (simp add: CptnModSeq2 lift_def)
then have lastc1:"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'"
by (simp add: last_length)
then have lastc1skip:"fst (last ((c1, s) # (c1', t) # xs')) = Skip"
using assth by fastforce
thus ?thesis
using seqmap split' last_length cptn_mod.CptnModSeq2 induct_step lastc1 lastc1skip
by (smt append_Cons list.inject list.simps(9))
next
assume assm:
"\<exists>c. (fst(((c1', t)#xs')!length xs')=c \<and> (c=Throw \<or> c=Stuck \<or> (\<exists>f. c = Fault f)) \<and>
snd(last ((c1', t)#xs')) = sa' \<and> t= sa''\<and>
(\<exists>ys. (\<Gamma>,(c, sa')#ys) \<in> cptn_mod \<and> xs=(map (lift c2) xs')@((c, sa')#ys)))"
then obtain c where
c:"(fst(((c1', t)#xs')!length xs')=c \<and> (c=Throw \<or> c=Stuck \<or> (\<exists>f. c = Fault f)) \<and>
snd(last ((c1', t)#xs')) = sa' \<and> t= sa''\<and>
(\<exists>ys. (\<Gamma>,(c, sa')#ys) \<in> cptn_mod \<and> xs=(map (lift c2) xs')@((c, sa')#ys)))" by auto
then have s'eqsa'': "t= sa''" by auto
then have snormal: "\<exists>ns. s= ns" using c_step normal_eq_l by blast
then have c1'cptn:"(\<Gamma>, (c1', t) # xs') \<in> cptn_mod" using split by blast
then have induct_step: "(\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod"
using Seqc.hyps(2) Seqc.prems(3) Seqc.prems(4) normal_eq_l by blast
then obtain ys where seqmap:
"(Seq c1' c2, t)#xs = (map (lift c2) ((c1', t)#xs'))@((c, sa')#ys)"
using assm using c unfolding lift_def by auto
moreover have "fst (last ((c1, s) # (c1', t) # xs')) = c"
using c by (simp add: c last_length)
moreover have "snd (last ((c1, s) # (c1', t) # xs')) = sa'" using c by (auto simp add: last_length)
ultimately show ?thesis
using assm c1'cptn induct_step snormal seqmap s'eqsa''
by (auto simp add:cptn_mod.CptnModSeq3)
qed
}qed
next
case (SeqSkipc c2 s1 xs)
then have c2incptn:"(\<Gamma>, (c2, s) # xs) \<in> cptn_mod"
using eq_toSeq by blast
moreover have 1:"(\<Gamma>, [(Skip, s)]) \<in> cptn_mod" by (simp add: cptn_mod.CptnModOne)
moreover have 2:"fst(last ([(Skip, s)])) = Skip" by fastforce
moreover have 3:"(\<Gamma>,(c2, snd(last [(Skip, s)]))#xs) \<in> cptn_mod"
using c2incptn by auto
moreover have "(c2,s)#xs=(map (lift c2) [])@(c2, snd(last [(Skip, s)]))#xs"
by (auto simp add:lift_def)
moreover have "s=t" using eq_toSeq SeqSkipc by blast
ultimately show ?case
by (simp add: CptnModSeq2)
next
case (SeqThrowc c2 s1 xs)
have eq_st:"s=t" using eq_toSeq[OF SeqThrowc(1)] SeqThrowc by auto
obtain ns where normals:"s= ns" using SeqThrowc by auto
have "(\<Gamma>, [(Throw, ns)]) \<in> cptn_mod" by (simp add: cptn_mod.CptnModOne)
then obtain ys where ys_nil:"ys=[]" and last:"(\<Gamma>, (Throw, s)#ys)\<in> cptn_mod"
using normals by auto
moreover have "fst (last ((Throw, ns)#ys)) = Throw" using ys_nil last by auto
moreover have "snd (last ((Throw, ns)#ys)) = ns" using ys_nil last by auto
moreover from ys_nil have "(map (lift c2) ys) = []" by auto
ultimately show ?case using SeqThrowc.prems cptn_mod.CptnModSeq3 eq_st normals
by (metis append_Nil)
next
case (SeqFaultc f c2 sa xs)
have eq_st:"s=t"
using SeqFaultc.prems(3) SeqFaultc.prems(4) eq_toSeq normal_eq_l by blast
obtain ns where normals:"s= ns" by auto
have "(\<Gamma>, [(Fault f, ns)]) \<in> cptn_mod" by (simp add: cptn_mod.CptnModOne)
then obtain ys where ys_nil:"ys=[]" and last:"(\<Gamma>, (Fault f, s)#ys)\<in> cptn_mod"
using normals by auto
moreover have "fst (last ((Fault f, ns)#ys)) = Fault f" using ys_nil last by auto
moreover have "snd (last ((Fault f, ns)#ys)) = ns" using ys_nil last by auto
moreover from ys_nil have "(map (lift c2) ys) = []" by auto
ultimately show ?case using SeqFaultc.prems cptn_mod.CptnModSeq3 eq_st normals
by (metis append_Nil)
next
case (SeqStuckc c2 sa xs)
have eq_st:"s=t"
using SeqStuckc.prems(3) SeqStuckc.prems(4) eq_toSeq normal_eq_l by blast
obtain ns where normals:"s= ns" by auto
have "(\<Gamma>, [(Stuck, ns)]) \<in> cptn_mod" by (simp add: cptn_mod.CptnModOne)
then obtain ys where ys_nil:"ys=[]" and last:"(\<Gamma>, (Stuck, s)#ys)\<in> cptn_mod"
using normals by auto
moreover have "fst (last ((Stuck, ns)#ys)) = Stuck" using ys_nil last by auto
moreover have "snd (last ((Stuck, ns)#ys)) = ns" using ys_nil last by auto
moreover from ys_nil have "(map (lift c2) ys) = []" by auto
ultimately show ?case using SeqStuckc.prems cptn_mod.CptnModSeq3 eq_st normals
by (metis append_Nil)
next
case (CondTruec s1 b c1 c2)
moreover obtain ns where normals:"s= ns" by fastforce
moreover have "s=t"
using calculation(4,5) eq_toSeq[OF calculation(2)] by auto
ultimately show ?case by (simp add: cptn_mod.CptnModCondT)
next
case (CondFalsec s1 b c1 c2)
moreover obtain ns where normals:"s= ns" by fastforce
moreover have "s=t"
using calculation(4,5) eq_toSeq[OF calculation(2)] by auto
ultimately show ?case
by (simp add: cptn_mod.CptnModCondF)
next
case (WhileTruec s1 b c)
have sinb: "s1\<in>b" by fact
obtain ns where normals:"s= ns" by fastforce
have eq_st:"s=t" using eq_toSeq[OF WhileTruec(2)] WhileTruec by fastforce
have SeqcWhile: "(\<Gamma>, (Seq c (While b c), ns) # xs) \<in> cptn_mod"
using sinb normals eq_st WhileTruec by blast
have divseq:
"(\<forall>s P Q zs. (Seq c (While b c), ns) # xs=(Seq P Q, s)#zs \<longrightarrow>
(\<exists>xs s'. ((\<Gamma>,(P, s)#xs) \<in> cptn_mod \<and>
(zs=(map (lift Q) xs) \<or>
((fst(((P, s)#xs)!length xs)=Skip \<and>
(\<exists>ys. (\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod \<and>
zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or>
(\<exists>c. (fst(((P, s)#xs)!length xs)=c \<and> (c=Throw \<or> c=Stuck \<or> (\<exists>f. c = Fault f)) \<and>
snd(last ((P, s)#xs)) = s' \<and>
(\<exists>ys. (\<Gamma>,(c, s')#ys) \<in> cptn_mod \<and> zs=(map (lift Q) xs)@((c, s')#ys))))))
))"
using div_seq [OF SeqcWhile] eq_st normals unfolding seq_cond_def by fastforce
{ fix sa P Q zsa
assume ass:"(Seq c (While b c), ns) # xs = (Seq P Q, sa) # zsa"
then have eqs:"c = P \<and> (While b c) = Q \<and> ns = sa \<and> xs = zsa" by auto
then have
"(\<exists>xs s'. (\<Gamma>, (P, sa) # xs) \<in> cptn_mod \<and>
(zsa = map (lift Q) xs \<or>
fst (((P, sa) # xs) ! length xs) = Skip \<and>
(\<exists>ys. (\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<in> cptn_mod \<and>
zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<or>
(\<exists>c. (fst(((P, sa)#xs)!length xs)=c \<and> (c=Throw \<or> c=Stuck \<or> (\<exists>f. c = Fault f)) \<and>
snd(last ((P, sa)#xs)) = s' \<and>
(\<exists>ys. (\<Gamma>,(c, s')#ys) \<in> cptn_mod \<and> zsa=(map (lift Q) xs)@((c, s')#ys))))))"
using ass divseq by fastforce
} note conc=this [of c "While b c" " ns" xs]
then obtain xs' s'
where split:
"(\<Gamma>, (c, ns) # xs') \<in> cptn_mod \<and>
(xs = map (lift (While b c)) xs' \<or>
fst (((c, ns) # xs') ! length xs') = Skip \<and>
(\<exists>ys. (\<Gamma>, (While b c, snd (((c, ns) # xs') ! length xs')) # ys) \<in> cptn_mod \<and>
xs = map (lift (While b c)) xs' @ (While b c, snd (((c, ns) # xs') ! length xs')) # ys) \<or>
(\<exists>t. fst (((c, ns) # xs') ! length xs') = t \<and> (t=Throw \<or> t=Stuck \<or> (\<exists>f. t = Fault f)) \<and>
snd (last ((c, ns) # xs')) = s' \<and>
(\<exists>ys. (\<Gamma>, ((t, s')#ys)) \<in> cptn_mod \<and> xs = map (lift (While b c)) xs' @ ((t, s')#ys))))"
by blast
then have
"xs = map (lift (While b c)) xs' \<or>
fst (((c, ns) # xs') ! length xs') = Skip \<and>
(\<exists>ys. (\<Gamma>, (While b c, snd (((c, ns) # xs') ! length xs')) # ys)\<in> cptn_mod \<and>
xs = map (lift (While b c)) xs' @ (While b c, snd (((c, ns) # xs') ! length xs')) # ys) \<or>
(\<exists>t. fst (((c, ns) # xs') ! length xs') = t \<and> (t=Throw \<or> t=Stuck \<or> (\<exists>f. t = Fault f)) \<and>
snd (last ((c, ns) # xs')) = s' \<and>
(\<exists>ys. (\<Gamma>, ((t, s')#ys)) \<in> cptn_mod \<and>
xs = map (lift (While b c)) xs' @ ((t, s')#ys)))" ..
thus ?case
proof{
assume 1:"xs = map (lift (While b c)) xs'"
have 3:"(\<Gamma>, (c, ns) # xs') \<in> cptn_mod" using split by auto
then show ?thesis using "1" cptn_mod.CptnModWhile1 sinb normals eq_st WhileTruec.prems(3)
by fastforce
next
assume
"fst (((c, ns) # xs') ! length xs') = Skip \<and>
(\<exists>ys. (\<Gamma>, (While b c, snd (((c, ns) # xs') ! length xs')) # ys) \<in> cptn_mod \<and>
xs = map (lift (While b c)) xs' @ (While b c, snd (((c, ns) # xs') ! length xs')) # ys) \<or>
(\<exists>t. fst (((c, ns) # xs') ! length xs') = t \<and> (t=Throw \<or> t=Stuck \<or> (\<exists>f. t = Fault f)) \<and>
snd (last ((c, ns) # xs')) = s' \<and>
(\<exists>ys. (\<Gamma>, ((t, s')#ys)) \<in> cptn_mod \<and> xs = map (lift (While b c)) xs' @ ((t, s')#ys)))"
thus ?case
proof
assume asm:"fst (((c, ns) # xs') ! length xs') = Skip \<and>
(\<exists>ys. (\<Gamma>, (While b c, snd (((c, ns) # xs') ! length xs')) # ys) \<in> cptn_mod \<and>
xs = map (lift (While b c)) xs' @ (While b c, snd (((c, ns) # xs') ! length xs')) # ys)"
then obtain ys where asm':
"(\<Gamma>, (While b c, snd (((c, ns) # xs') ! length xs')) # ys) \<in> cptn_mod \<and>
xs = map (lift (While b c)) xs' @ (While b c, snd (((c, ns) # xs') ! length xs')) # ys"
by (auto simp add: last_length)
moreover have 3:"(\<Gamma>, (c, ns) # xs') \<in> cptn_mod" using split by auto
moreover from asm have "fst (last ((c, ns) # xs')) = Skip"
by (simp add: last_length)
ultimately show ?case using sinb normals eq_st WhileTruec.prems(3)
by (metis cptn_mod.CptnModWhile2 last_length toSeq.simps)
next
assume asm:
"\<exists>t. fst (((c, ns) # xs') ! length xs') = t \<and> (t=Throw \<or> t=Stuck \<or> (\<exists>f. t = Fault f)) \<and>
snd (last ((c, ns) # xs')) = s' \<and>
(\<exists>ys. (\<Gamma>, ((t, s')#ys)) \<in> cptn_mod \<and> xs = map (lift (While b c)) xs' @ ((t, s')#ys))"
moreover have 3:"(\<Gamma>, (c, ns) # xs') \<in> cptn_mod" using split by auto
moreover from asm obtain v
where "fst (last ((c, ns) # xs')) = v \<and> (v=Throw \<or> v=Stuck \<or> (\<exists>f. v = Fault f))"
by (metis last_length)
ultimately show ?case using sinb normals eq_st WhileTruec.prems(3) CptnModWhile3
by (metis (no_types, lifting) last_length toSeq.simps)
qed
}qed
next
case (WhileFalsec s1 b c)
thus ?case using stepc.WhileFalsec[of s1 b \<Gamma> c]
by (simp add: cptn_mod.CptnModSkip)
next
case (Awaitc s1 b \<Gamma>a c t1)
thus ?case using stepc.Awaitc[of s1 b \<Gamma>a \<Gamma>]
by (simp add: cptn_mod.CptnModSkip)
next
case (AwaitAbruptc s1 b \<Gamma>a c t1 ta)
thus ?case using stepc.AwaitAbruptc[of s1 b \<Gamma>a \<Gamma> c t1 ta] by (simp add: cptn_mod.CptnModThrow)
next
case (AwaitFaultc s1 b \<Gamma>a c f t1 ta)
thus ?case using stepc.AwaitFaultc
by (simp add: stepc.AwaitFaultc cptn_mod.CptnModFault)
next
case (AwaitStuckc s1 b \<Gamma>a c t1 ta)
thus ?case using stepc.AwaitStuckc
by (simp add: stepc.AwaitStuckc cptn_mod.CptnModStuck)
next
case (Callc p bdy s1)
moreover have eq_st:"s=t" using eq_toSeq[OF Callc(3)] Callc by auto
then show ?case using cptn_mod.CptnModCall
by (simp add: cptn_mod.CptnModCall calculation(1) calculation(2) calculation(4))
next
case (CallUndefinedc p s1)
thus ?case using stepc.CallUndefinedc[of \<Gamma> p s1,OF CallUndefinedc(1)]
by (simp add: cptn_mod.CptnModStuck)
next
case (DynComc c s1)
moreover obtain ns where "s= ns" by auto
moreover have "fst ns = s1"
using calculation(3) calculation(5) by auto
moreover have "s=t"
using calculation(3,4) eq_toSeq[OF DynComc(1)] by force
ultimately show ?case
proof -
show ?thesis
using \<open>(\<Gamma>, (c s1, t) # xs) \<in> cptn_mod\<close> \<open>fst ns = s1\<close> \<open>s = ns\<close> \<open>s = t\<close>
cptn_mod.CptnModDynCom by blast
qed
next
case (Catchc c1 s1 c1' t1 c2)
have step: "\<Gamma>\<turnstile>\<^sub>c (c1, s1) \<rightarrow> (c1', t1)" by (simp add: Catchc.hyps(1))
then have nsc1: "c1\<noteq>Skip" using stepc_elim_cases(1)
by fastforce
have assum: "(\<Gamma>, (Catch c1' c2, t) # xs) \<in> cptn_mod"
using Catchc.prems by blast
have divcatch:
"(\<forall>s P Q zs. (Catch c1' c2, t) # xs=(Catch P Q, s)#zs \<longrightarrow>
(\<exists>xs s' s''. ((\<Gamma>,(P, s)#xs) \<in> cptn_mod \<and>
(zs=(map (lift_catch Q) xs) \<or>
((fst(((P, s)#xs)!length xs)=Throw \<and> snd(last ((P, s)#xs)) = s' \<and> s= s''\<and>
(\<exists>ys. (\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod \<and>
zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or>
(\<exists>t. (fst(((P, s)#xs)!length xs)=t \<and> (t=Skip \<or> (\<exists>f. t = Fault f) \<or> t = Stuck) \<and>
(\<exists>ys. (\<Gamma>,(t,snd(last ((P, s)#xs)))#ys) \<in> cptn_mod \<and>
zs=(map (lift_catch Q) xs)@((t,snd(last ((P, s)#xs)))#ys))))))))"
using div_catch [OF assum] by (auto simp add: catch_cond_def)
{fix sa P Q zsa
assume ass:"(Catch c1' c2, t) # xs = (Catch P Q, sa) # zsa"
then have eqs:"c1' = P \<and> c2 = Q \<and> t = sa \<and> xs = zsa" by auto
then have "(\<exists>xs sv' sv''. ((\<Gamma>,(P, sa)#xs) \<in> cptn_mod \<and>
(zsa=(map (lift_catch Q) xs) \<or>
((fst(((P, sa)#xs)!length xs)=Throw \<and>
snd(last ((P, sa)#xs)) = sv' \<and> t= sv''\<and>
(\<exists>ys. (\<Gamma>,(Q, snd(((P, sa)#xs)!length xs))#ys) \<in> cptn_mod \<and>
zsa=(map (lift_catch Q) xs)@((Q, snd(((P, sa)#xs)!length xs))#ys)))) \<or>
(\<exists>c. (fst(((P, sa)#xs)!length xs)=c \<and> (c=Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
(\<exists>ys. (\<Gamma>,(c,snd(last ((P, sa)#xs)))#ys) \<in> cptn_mod \<and>
zsa=(map (lift_catch Q) xs)@((c,snd(last ((P, sa)#xs)))#ys)))))))"
using ass divcatch by fastforce
} note conc=this [of c1' c2 t xs]
then obtain xs' sa' sa'' where split:
"(\<Gamma>, (c1', t) # xs') \<in> cptn_mod \<and>
(xs = map (lift_catch c2) xs' \<or>
fst (((c1', t) # xs') ! length xs') = Throw \<and>
snd (last ((c1', t) # xs')) = sa' \<and> t = sa'' \<and>
(\<exists>ys. (\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and>
xs = map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or>
(\<exists>c. fst (((c1', t) # xs') ! length xs') = c \<and> (c=Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
(\<exists>ys. (\<Gamma>,(c,snd(last ((c1', t)#xs')))#ys) \<in> cptn_mod \<and>
xs=(map (lift_catch c2) xs')@((c,snd(last ((c1', t)#xs')))#ys))))"
by blast
note conjunct2[OF split]
thus ?case
proof{
assume c1'nonf:"xs = map (lift_catch c2) xs'"
then have c1'cptn:"(\<Gamma>, (c1', t) # xs') \<in> cptn_mod" using split by blast
then have induct_step: "(\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod"
using Catchc.hyps(2) Catchc.prems(3) Catchc.prems(4) normal_eq_l by blast
then have "(Catch c1' c2, t)#xs = map (lift_catch c2) ((c1', t)#xs')"
using c1'nonf
by (simp add: CptnModCatch1 lift_catch_def)
thus ?thesis
using c1'nonf c1'cptn induct_step by (auto simp add: CptnModCatch1)
next
assume "fst (((c1', t) # xs') ! length xs') = Throw \<and>
snd (last ((c1', t) # xs')) = sa' \<and> t = sa'' \<and>
(\<exists>ys. (\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and>
xs = map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or>
(\<exists>c. fst (((c1', t) # xs') ! length xs') = c \<and> (c=Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
(\<exists>ys. (\<Gamma>,(c,snd(last ((c1', t)#xs')))#ys) \<in> cptn_mod \<and>
xs=(map (lift_catch c2) xs')@((c,snd(last ((c1', t)#xs')))#ys)))"
thus ?thesis
proof
assume assth:
"fst (((c1', t) # xs') ! length xs') = Throw \<and>
snd (last ((c1', t) # xs')) = sa' \<and> t = sa'' \<and>
(\<exists>ys. (\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and>
xs = map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys)"
then have snormal: "\<exists>ns. s= ns" by auto
then obtain ys
where split':"(\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod \<and>
xs =map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys"
using assth by auto
then have c1'cptn:"(\<Gamma>, (c1',t) # xs') \<in> cptn_mod"
using split by blast
then have induct_step: "(\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod"
using Catchc.hyps(2) Catchc.prems(3) Catchc.prems(4) normal_eq_l by blast
then have seqmap:"(Catch c1 c2, s)#(Catch c1' c2, t)#xs =
map (lift_catch c2) ((c1,s)#(c1', t)#xs') @
(c2, snd (((c1', t) # xs') ! length xs')) # ys"
using split' by (simp add: CptnModCatch3 lift_catch_def)
then have lastc1:"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'"
by (simp add: last_length)
then have lastc1skip:"fst (last ((c1, s) # (c1', t) # xs')) = Throw"
using assth by fastforce
then have "snd (last ((c1, s) # (c1', t) # xs')) = sa'"
using assth by force
thus ?thesis
using snormal seqmap split'
cptn_mod.CptnModCatch3 induct_step lastc1 lastc1skip by fastforce
next
assume assm:
"(\<exists>c. fst (((c1', t) # xs') ! length xs') = c \<and> (c=Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
(\<exists>ys. (\<Gamma>,(c,snd(last ((c1', t)#xs')))#ys) \<in> cptn_mod \<and>
xs=(map (lift_catch c2) xs')@((c,snd(last ((c1', t)#xs')))#ys)))"
then obtain c where assm:
"fst (((c1', t) # xs') ! length xs') = c \<and> (c=Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
(\<exists>ys. (\<Gamma>,(c,snd(last ((c1', t)#xs')))#ys) \<in> cptn_mod \<and>
xs=(map (lift_catch c2) xs')@((c,snd(last ((c1', t)#xs')))#ys))" by auto
then have c1'cptn:"(\<Gamma>, (c1', t) # xs') \<in> cptn_mod" using split by blast
then have induct_step: "(\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod"
using Catchc.hyps(2) Catchc.prems(3) Catchc.prems(4) normal_eq_l by blast
then have "map (lift_catch c2) ((c1', t) # xs') =
(Catch c1' c2, t) # map (lift_catch c2) xs'"
by (auto simp add: lift_catch_def)
then obtain ys
where seqmap:"(Catch c1' c2, t)#xs =
(map (lift_catch c2) ((c1', t)#xs'))@((c,snd(last ((c1', t)#xs')))#ys)"
using assm by fastforce
then have lastc1:"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'"
by (simp add: last_length)
then have lastc1skip:"fst (last ((c1, s) # (c1', t) # xs')) = c"
using assm by fastforce
then have "snd (last ((c1, s) # (c1', t) # xs')) = snd (last ((c1',t) # xs'))"
using assm by force
thus ?thesis
using assm c1'cptn seqmap
cptn_mod.CptnModCatch2[OF induct_step lastc1skip]
by fastforce
qed
}qed
next
case (CatchThrowc c2 s1)
then obtain ns where ns:"s = ns"
by auto
then have eq_st: "s=t" using eq_toSeq[OF CatchThrowc(1)] CatchThrowc(3,4) by auto
then have c2incptn:"(\<Gamma>, (c2, ns) # xs) \<in> cptn_mod" using ns CatchThrowc
by auto
then have 1:"(\<Gamma>, [(Throw, ns)]) \<in> cptn_mod" by (simp add: cptn_mod.CptnModOne)
then have 2:"fst(last ([(Throw, ns)])) = Throw" by fastforce
then have 3:"(\<Gamma>,(c2, snd(last [(Throw, ns)]))#xs) \<in> cptn_mod"
using c2incptn by auto
then have "(c2, ns)#xs=(map (lift c2) [])@(c2, snd(last [(Throw, ns)]))#xs"
by (auto simp add:lift_def)
thus ?case using eq_st ns CptnModCatch3 1 2 3
by fastforce
next
case (CatchSkipc c2 s1)
have "(\<Gamma>, [(Skip, s)]) \<in> cptn_mod" by (simp add: cptn_mod.CptnModOne)
then obtain ys where ys_nil:"ys=[]" and last:"(\<Gamma>, (Skip, s)#ys)\<in> cptn_mod"
by auto
moreover have "fst (last ((Skip, s)#ys)) = Skip" using ys_nil last by auto
moreover have "snd (last ((Skip, s)#ys)) = s" using ys_nil last by auto
moreover from ys_nil have "(map (lift_catch c2) ys) = []" by auto
moreover have "s=t"
using CatchSkipc.prems(3) CatchSkipc.prems(4) eq_toSeq normal_eq_l by blast
ultimately show ?case using CatchSkipc.prems by (simp add: cptn_mod.CptnModCatch2 ys_nil)
next
case (CatchFaultc f c2 sa xs)
have "(\<Gamma>, [(Fault f, s)]) \<in> cptn_mod" by (simp add: cptn_mod.CptnModOne)
then obtain ys where ys_nil:"ys=[]" and last:"(\<Gamma>, (Fault f, s)#ys)\<in> cptn_mod"
by auto
moreover have "fst (last ((Fault f, s)#ys)) = Fault f" using ys_nil last by auto
moreover have "snd (last ((Fault f , s)#ys)) = s" using ys_nil last by auto
moreover from ys_nil have "(map (lift_catch c2) ys) = []" by auto
moreover have "s=t"
using CatchFaultc.prems(3) CatchFaultc.prems(4) eq_toSeq normal_eq_l by blast
ultimately show ?case
by (metis CatchFaultc.prems(2) append_Nil cptn_modp.CptnModCatch2 cptn_modp_cptn_mod_eq)
next
case (CatchStuckc c2 sa xs)
have "(\<Gamma>, [(Stuck, s)]) \<in> cptn_mod" by (simp add: cptn_mod.CptnModOne)
then obtain ys where ys_nil:"ys=[]" and last:"(\<Gamma>, (Stuck, s)#ys)\<in> cptn_mod"
by auto
moreover have "fst (last ((Stuck, s)#ys)) = Stuck" using ys_nil last by auto
moreover have "snd (last ((Stuck , s)#ys)) = s" using ys_nil last by auto
moreover from ys_nil have "(map (lift_catch c2) ys) = []" by auto
moreover have "s=t"
using CatchStuckc.prems(3) CatchStuckc.prems(4) eq_toSeq normal_eq_l by blast
ultimately show ?case
by (metis CatchStuckc.prems(2) append_Nil cptn_modp.CptnModCatch2 cptn_modp_cptn_mod_eq)
qed
lemma cptn_onlyif_cptn_mod:
assumes cptn_asm:"(\<Gamma>,c) \<in> cptn"
shows "(\<Gamma>,c) \<in> cptn_mod"
using cptn_asm
proof (induct)
case CptnOne thus ?case by (rule CptnModOne)
next
case (Cptn \<Gamma> P s Q t xs)
then have "\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (Q, t) \<or> \<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Q, toSeq t)"
using step_ce_not_step_e_step_c by blast
moreover{
assume "\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (Q, t)"
then have ?case
using Cptn.hyps(3) cptn_mod.CptnModEnv env_c_c' by blast
}
moreover{
assume a00:"\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Q, toSeq t)"
moreover have "\<not> \<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (Q, t)"
using env_c_c' mod_env_not_component calculation by fast
ultimately have ?case using cptn_onlyif_cptn_mod_aux[OF _ _ a00 _ Cptn(3)] Cptn
using step_dest1 by fast
}
ultimately show ?case by auto
qed
lemma lift_is_cptn:
assumes cptn_asm:"(\<Gamma>,c)\<in>cptn"
shows "(\<Gamma>,map (lift P) c) \<in> cptn"
using cptn_asm
proof (induct)
case CptnOne
have "\<forall>p f. (f, [p]) \<in> cptn"
using cptn.simps by fastforce
then show ?case by fastforce
next
case (Cptn \<Gamma> Pa s Q t xs)
have "\<Gamma>\<turnstile>\<^sub>c (Pa, s) \<rightarrow>\<^sub>e (Q, t) \<or> \<Gamma>\<turnstile>\<^sub>c (Pa, toSeq s) \<rightarrow> (Q, toSeq t)"
using Cptn.hyps(1) step_ce_not_step_e_step_c by blast
moreover{
assume "\<Gamma>\<turnstile>\<^sub>c (Pa, s) \<rightarrow>\<^sub>e (Q, t)"
then have ?case using Cptn unfolding lift_def
by (cases rule: step_e.cases, (simp add: Env cptn.Cptn e_step))
}
moreover {
assume "\<Gamma>\<turnstile>\<^sub>c (Pa, toSeq s) \<rightarrow> (Q, toSeq t)"
moreover have "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Seq Pa P, toSeq s) \<rightarrow> (LanguageCon.com.Seq Q P, toSeq t)"
using Seqc calculation
by (simp add: Seqc)
ultimately have "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Seq Pa P, s) \<rightarrow>\<^sub>c\<^sub>e (LanguageCon.com.Seq Q P, t)"
using Cptn.hyps(1) c_step[of \<Gamma> "LanguageCon.com.Seq Pa P" s "LanguageCon.com.Seq Q P" t]
env_c_c' step_ce_step_c_eq_c step_dest by blast
then have ?case using Cptn by (simp add: cptn.Cptn lift_def)
}
ultimately show ?case by auto
qed
lemma lift_catch_is_cptn:
assumes cptn_asm:"(\<Gamma>,c)\<in>cptn"
shows "(\<Gamma>,map (lift_catch P) c) \<in> cptn"
using cptn_asm
proof (induct)
case CptnOne
have "\<forall>p f. (f, [p]) \<in> cptn"
using cptn.simps by fastforce
then show ?case by fastforce
next
case (Cptn \<Gamma> Pa s Q t xs)
have "\<Gamma>\<turnstile>\<^sub>c (Pa, s) \<rightarrow>\<^sub>e (Q, t) \<or> \<Gamma>\<turnstile>\<^sub>c (Pa, toSeq s) \<rightarrow> (Q, toSeq t)"
using Cptn.hyps(1) step_ce_not_step_e_step_c by blast
moreover{
assume "\<Gamma>\<turnstile>\<^sub>c (Pa, s) \<rightarrow>\<^sub>e (Q, t)"
then have ?case using Cptn unfolding lift_catch_def
by (cases rule: step_e.cases, (simp add: Env cptn.Cptn e_step))
}
moreover {
assume "\<Gamma>\<turnstile>\<^sub>c (Pa, toSeq s) \<rightarrow> (Q, toSeq t)"
moreover have "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Catch Pa P, toSeq s) \<rightarrow> (LanguageCon.com.Catch Q P, toSeq t)"
using Catchc calculation by auto
ultimately have "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Catch Pa P, s) \<rightarrow>\<^sub>c\<^sub>e (LanguageCon.com.Catch Q P, t)"
using Cptn.hyps(1) c_step[of \<Gamma> "LanguageCon.com.Catch Pa P" s "LanguageCon.com.Catch Q P" t]
env_c_c' step_ce_step_c_eq_c step_dest by blast
then have ?case using Cptn by (simp add: cptn.Cptn lift_catch_def)
}
ultimately show ?case by auto
qed
lemma last_lift: "\<lbrakk>xs\<noteq>[]; fst(xs!(length xs - (Suc 0)))=Q\<rbrakk>
\<Longrightarrow> fst((map (lift P) xs)!(length (map (lift P) xs)- (Suc 0)))=Seq Q P"
by (cases "(xs ! (length xs - (Suc 0)))") (simp add:lift_def)
lemma last_lift_catch: "\<lbrakk>xs\<noteq>[]; fst(xs!(length xs - (Suc 0)))=Q\<rbrakk>
\<Longrightarrow> fst((map (lift_catch P) xs)!(length (map (lift_catch P) xs)- (Suc 0)))=Catch Q P"
by (cases "(xs ! (length xs - (Suc 0)))") (simp add:lift_catch_def)
lemma last_fst [rule_format]: "P((a#x)!length x) \<longrightarrow> \<not>P a \<longrightarrow> P (x!(length x - (Suc 0)))"
by (induct x) simp_all
lemma last_fst_esp:
"fst(((P,s)#xs)!(length xs))=Skip \<Longrightarrow> P\<noteq>Skip \<Longrightarrow> fst(xs!(length xs - (Suc 0)))=Skip"
apply(erule last_fst)
apply simp
done
lemma last_snd: "xs\<noteq>[] \<Longrightarrow>
snd(((map (lift P) xs))!(length (map (lift P) xs) - (Suc 0)))=snd(xs!(length xs - (Suc 0)))"
by (cases "(xs ! (length xs - (Suc 0)))") (simp_all add:lift_def)
lemma last_snd_catch: "xs\<noteq>[] \<Longrightarrow>
snd(((map (lift_catch P) xs))!(length (map (lift_catch P) xs) - (Suc 0)))=snd(xs!(length xs - (Suc 0)))"
by (cases "(xs ! (length xs - (Suc 0)))") (simp_all add:lift_catch_def)
lemma Cons_lift: "((Seq P Q), s) # (map (lift Q) xs) = map (lift Q) ((P, s) # xs)"
by (simp add:lift_def)
thm last_map eq_snd_iff list.inject list.simps(9) last_length
lemma Cons_lift_catch: "((Catch P Q), s) # (map (lift_catch Q) xs) = map (lift_catch Q) ((P, s) # xs)"
by (simp add:lift_catch_def)
lemma Cons_lift_append:
"((Seq P Q), s) # (map (lift Q) xs) @ ys = map (lift Q) ((P, s) # xs)@ ys "
by (simp add:lift_def)
lemma Cons_lift_catch_append:
"((Catch P Q), s) # (map (lift_catch Q) xs) @ ys = map (lift_catch Q) ((P, s) # xs)@ ys "
by (simp add:lift_catch_def)
lemma lift_nth: "i<length xs \<Longrightarrow> map (lift Q) xs ! i = lift Q (xs! i)"
by (simp add:lift_def)
lemma lift_catch_nth: "i<length xs \<Longrightarrow> map (lift_catch Q) xs ! i = lift_catch Q (xs! i)"
by (simp add:lift_catch_def)
thm list.simps(9) last_length lift_catch_def Cons_lift_catch
lemma snd_lift: "i< length xs \<Longrightarrow> snd(lift Q (xs ! i))= snd (xs ! i)"
by (cases "xs!i") (simp add:lift_def)
lemma snd_lift_catch: "i< length xs \<Longrightarrow> snd(lift_catch Q (xs ! i))= snd (xs ! i)"
by (cases "xs!i") (simp add:lift_catch_def)
lemma lift_P1:
assumes map_cptn:"(\<Gamma>, map (lift Q) ((P, s) # xs)) \<in> cptn" and
P_ends:"fst (last ((P, s) # xs)) = Skip"
shows "(\<Gamma>, map (lift Q) ((P, s) # xs) @ [(Q, snd (last ((P, s) # xs)))]) \<in> cptn"
using map_cptn P_ends
proof (induct xs arbitrary: P s)
case Nil
have P0_skips: "P=Skip" using Nil.prems(2) by auto
then have "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Seq LanguageCon.com.Skip Q, s) \<rightarrow>\<^sub>c\<^sub>e (Q, s)"
by (metis SeqSkipc c_step)
then have "(\<Gamma>,[(Seq Skip Q, s), (Q, s)]) \<in> cptn"
by (simp add: cptn.Cptn cptn.CptnOne)
then show ?case using P0_skips by (simp add: lift_def)
next
case (Cons a xs)
have "(\<Gamma>, map (lift Q) ((P, s) # a # xs)) \<in> cptn"
using Cons.prems(1) by blast
have "fst (last ( a # xs)) = Skip" using Cons.prems(2) by auto
also have seq_PQ:"(\<Gamma>,(Seq P Q,s) # (map (lift Q) (a#xs))) \<in> cptn"
by (metis Cons.prems(1) Cons_lift)
then have "(\<Gamma>,(map (lift Q) (a#xs))) \<in> cptn"
by (simp add: tl_in_cptn)
then have "(\<Gamma>, map (lift Q) (a#xs) @ [(Q, snd (last ((a#xs))))]) \<in> cptn"
by (metis Cons.hyps(1) calculation prod.collapse)
then have t1:"(\<Gamma>, (Seq (fst a) Q, (snd a))#map (lift Q) xs @ [(Q, snd (last ((P, s)#(a#xs))))]) \<in> cptn"
by (simp add: Cons_lift_append)
then have "(\<Gamma>,(Seq P Q,s) # (Seq (fst a) Q, (snd a))#map (lift Q) xs)\<in> cptn"
using seq_PQ by (simp add: Cons_lift)
then have t2: "(\<Gamma>,(Seq P Q,s) # [(Seq (fst a) Q, (snd a))]) \<in> cptn"
using cptn_dest1 by blast
then have"((Seq P Q,s) # [(Seq (fst a) Q, (snd a))])!length [(Seq (fst a) Q, (snd a))] = (Seq (fst a) Q, (snd a))"
by auto
then have "(\<Gamma>,(Seq P Q,s) # [(Seq (fst a) Q, (snd a))]@map (lift Q) xs @ [(Q, snd (last ((P, s)#(a#xs))))])\<in> cptn"
using cptn_append_is_cptn t1 t2 by blast
then have "(\<Gamma>, map (lift Q) ((P,s)#(fst a, snd a)#xs) @[(Q, snd (last ((P, s)#(a#xs))))])\<in>cptn"
using Cons_lift_append append_Cons append_Nil by metis
thus ?case by auto
qed
lemma lift_catch_P1:
assumes map_cptn:"(\<Gamma>, map (lift_catch Q) ((P, s) # xs)) \<in> cptn" and
P_ends:"fst (last ((P, s) # xs)) = Throw" and
P_ends_normal:"\<exists>p. snd(last ((P, s) # xs)) = p"
shows "(\<Gamma>, map (lift_catch Q) ((P, s) # xs) @ [(Q, snd (last ((P, s) # xs)))]) \<in> cptn"
using map_cptn P_ends P_ends_normal
proof (induct xs arbitrary: P s)
case Nil
have P0_skips: "P=Throw" using Nil.prems(2) by auto
then have "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Catch LanguageCon.com.Throw Q, s) \<rightarrow>\<^sub>c\<^sub>e (Q, s)"
by (metis CatchThrowc surj_pair transfer_normal)
then have "(\<Gamma>,[(Catch Throw Q, s), (Q, s)]) \<in> cptn"
by (simp add: cptn.Cptn CatchThrowc cptn.CptnOne)
then show ?case using P0_skips by (simp add: lift_catch_def)
next
case (Cons a xs)
have s1:"(\<Gamma>, map (lift_catch Q) ((P, s) # a # xs)) \<in> cptn"
using Cons.prems(1) by blast
have s2:"fst (last ( a # xs)) = Throw" using Cons.prems(2) by auto
then obtain p where s3:"snd(last (a #xs)) = p" using Cons.prems(3) by auto
also have seq_PQ:"(\<Gamma>,(Catch P Q, s) # (map (lift_catch Q) (a#xs))) \<in> cptn"
by (metis Cons.prems(1) Cons_lift_catch) thm Cons.hyps
then have axs_in_cptn:"(\<Gamma>,(map (lift_catch Q) (a#xs))) \<in> cptn"
by (simp add: tl_in_cptn)
then have "(\<Gamma>, map (lift_catch Q) (a#xs) @ [(Q, snd (last ((a#xs))))]) \<in> cptn"
by (metis Cons.hyps prod.exhaust_sel s2)
then have t1:"(\<Gamma>, (Catch (fst a) Q, (snd a))#map (lift_catch Q) xs @ [(Q, snd (last ((P, s)#(a#xs))))]) \<in> cptn"
by (simp add: Cons_lift_catch_append)
then have "(\<Gamma>,(Catch P Q, s) # (Catch (fst a) Q, (snd a))#map (lift_catch Q) xs)\<in> cptn"
using seq_PQ by (simp add: Cons_lift_catch)
then have t2: "(\<Gamma>,(Catch P Q, s) # [(Catch (fst a) Q, (snd a))]) \<in> cptn"
using cptn_dest1 by blast
then have"((Catch P Q, s) # [(Catch (fst a) Q, (snd a))])!length [(Catch (fst a) Q, (snd a))] =
(Catch (fst a) Q, (snd a))"
by auto
then have "(\<Gamma>,(Catch P Q, s) # [(Catch (fst a) Q, (snd a))]@
map (lift_catch Q) xs @ [(Q, snd (last ((P, s)#(a#xs))))])\<in> cptn"
using cptn_append_is_cptn t1 t2 by blast
then have "(\<Gamma>, map (lift_catch Q) ((P, s)#(fst a, snd a)#xs) @[(Q, snd (last ((P, s)#(a#xs))))])\<in>cptn"
using Cons_lift_catch_append append_Cons append_Nil by metis
thus ?case by auto
qed
lemma seq2:
assumes
p1:"(\<Gamma>, (P0, s) # xs) \<in> cptn_mod" and
p2:"(\<Gamma>, (P0, s) # xs) \<in> cptn" and
p3:"fst (last ((P0, s) # xs)) = Skip" and
p4:"(\<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod" and
p5:"(\<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \<in> cptn" and
p6:"zs = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys"
shows "(\<Gamma>, (Seq P0 P1, s) # zs) \<in> cptn"
using p1 p2 p3 p4 p5 p6
proof -
have last_skip:"fst (last ((P0, s) # xs)) = Skip" using p3 by blast
have "(\<Gamma>, (map (lift P1) ((P0, s) # xs))@(P1, snd (last ((P0, s) # xs))) # ys) \<in> cptn"
proof -
have "(\<Gamma>,map (lift P1) ((P0, s) #xs)) \<in> cptn"
using p2 lift_is_cptn by blast
then have "(\<Gamma>,map (lift P1) ((P0, s) #xs)@[(P1, snd (last ((P0, s) # xs)))]) \<in> cptn"
using last_skip lift_P1 by blast
then have "(\<Gamma>,(Seq P0 P1, s) # map (lift P1) xs@[(P1, snd (last ((P0, s) # xs)))]) \<in> cptn"
by (simp add: Cons_lift_append)
moreover have "last ((Seq P0 P1, s) # map (lift P1) xs @[(P1, snd (last ((P0, s) # xs)))]) = (P1, snd (last ((P0, s) # xs)))"
by auto
moreover have "last ((Seq P0 P1, s) # map (lift P1) xs @[(P1, snd (last ((P0, s) # xs)))]) =
((Seq P0 P1, s) # map (lift P1) xs @[(P1, snd (last ((P0, s) # xs)))])!length (map (lift P1) xs @[(P1, snd (last ((P0, s) # xs)))])"
by (metis last_length)
ultimately have "(\<Gamma>, (Seq P0 P1, s) # map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys)\<in> cptn"
using cptn_append_is_cptn p5 by fastforce
thus ?thesis by (simp add: Cons_lift_append)
qed
thus ?thesis
by (simp add: Cons_lift_append p6)
qed
lemma seq3:
assumes
p1:"(\<Gamma>, (P0, s) # xs) \<in> cptn_mod" and
p2:"(\<Gamma>, (P0, s) # xs) \<in> cptn" and
p3:"fst (last ((P0, s) # xs)) = c" and p3':"c = Throw \<or> c = Stuck \<or> (\<exists>f. c = Fault f)" and
p4:"snd (last ((P0, s) # xs)) = s'" and
p5:"(\<Gamma>,(c, s')#ys) \<in> cptn_mod" and
p6:"(\<Gamma>,(c, s')#ys) \<in> cptn" and
p7:"zs = map (lift P1) xs @((c, s')#ys)"
shows "(\<Gamma>, (Seq P0 P1, s) # zs) \<in> cptn"
using p1 p2 p3 p4 p5 p6 p7
proof (induct xs arbitrary: zs P0 s)
case Nil
have h:"\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Seq c P1, s') \<rightarrow>\<^sub>c\<^sub>e (c, s')"
using SeqThrowc
by (metis SeqFaultc SeqStuckc c_step p3')
show ?case using cptn.Cptn[OF h,of ys] Nil
by simp
next
case (Cons a as)
then obtain sa where "snd a = sa" by meson
obtain a1 a2 where a_prod:"a=(a1,a2)"
using prod.exhaust_sel by blast
obtain la1 la2 where last_prod:"last (a#as) = (la1,la2)"
using prod.exhaust_sel by blast
then have lasst_aas_last: "last (a#as) = (last ((P0, s) # a # as))" by auto
then have "la1 = c" using Cons.prems(3) last_prod by force
have "la2 = s'" using Cons.prems(4) last_prod lasst_aas_last by force
have f1: "(\<Gamma>, (a1, a2) # as) \<in> cptn"
using Cons.prems(2) a_prod cptn_dest by blast
have f2: " sa = a2"
using `snd a = sa` a_prod by force
have "(\<Gamma>, a # as) \<in> cptn_mod"
using f1 a_prod cptn_onlyif_cptn_mod by blast
then have hyp:"(\<Gamma>, (Seq a1 P1, sa) #
map (lift P1) as @ ((c, s')#ys)) \<in> cptn"
using Cons.hyps Cons.prems(3) Cons.prems(4)
Cons.prems(5) Cons.prems(6) a_prod f1 f2 by fastforce
thus ?case
proof -
have f1: "(LanguageCon.com.Seq a1 P1, a2) # map (lift P1) as = map (lift P1) (a # as)"
using Cons_lift a_prod by blast
have f2: "(LanguageCon.com.Seq a1 P1, a2) # map (lift P1) as @ (c, s') # ys = zs"
by (simp add: Cons.prems(7) Cons_lift_append a_prod)
have "[(LanguageCon.com.Seq a1 P1, a2)] \<noteq> []"
by fastforce
then have "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Seq P0 P1, s) \<rightarrow>\<^sub>c\<^sub>e (LanguageCon.com.Seq a1 P1, a2)"
using f1 by (metis (no_types) Cons.prems(2) Cons_lift cptn_dest1
cptn_stepc_rtran last.simps last_length length_Cons
lessI lift_is_cptn list.size(3) nth_Cons_0)
then show ?thesis
using f2 cptn.Cptn f2 hyp
by (metis \<open>snd a = sa\<close> a_prod snd_conv)
qed
qed
lemma cptn_if_cptn_mod:
assumes cptn_mod_asm:"(\<Gamma>,c) \<in> cptn_mod"
shows "(\<Gamma>,c) \<in> cptn"
using cptn_mod_asm
proof (induct)
case (CptnModOne) thus ?case using cptn.CptnOne by blast
next
case CptnModSkip thus ?case
by (simp add: c_step cptn.Cptn)
next
case CptnModThrow thus ?case by (simp add: c_step cptn.Cptn)
next
case CptnModStuck thus ?case by (simp add: c_step cptn.Cptn)
next
case CptnModFault thus ?case by (simp add: c_step cptn.Cptn)
next
case CptnModCondT thus ?case
by (metis CondTruec cptn.Cptn prod.exhaust_sel transfer_normal)
next
case CptnModCondF thus ?case
by (metis CondFalsec cptn.Cptn prod.exhaust_sel transfer_normal)
next
case (CptnModSeq1 \<Gamma> P0 s xs zs P1)
have "(\<Gamma>, map (lift P1) ((P0, s) # xs)) \<in> cptn"
using CptnModSeq1.hyps(2) lift_is_cptn by blast
thus ?case by (simp add: Cons_lift CptnModSeq1.hyps(3))
next
case (CptnModSeq2 \<Gamma> P0 s xs P1 ys zs)
thus ?case by (simp add:seq2)
next
case (CptnModSeq3 \<Gamma> P0 s xs t f s' ys zs P1)
thus ?case using seq3 by blast
next
case (CptnModWhile1 \<Gamma> P s xs b zs) thus ?case
by (metis Cons_lift WhileTruec cptn.Cptn lift_is_cptn prod.collapse transfer_normal)
next
case (CptnModWhile2 \<Gamma> P s xs b zs ys)
then have "(\<Gamma>, (Seq P (While b P), s) # zs) \<in> cptn"
by (simp add:seq2)
moreover have "\<Gamma>\<turnstile>\<^sub>c(While b P,toSeq ( s)) \<rightarrow> (Seq P (While b P),toSeq( s))"
by (simp add: CptnModWhile2.hyps(4) WhileTruec)
ultimately show ?case
by (metis cptn.Cptn prod.collapse toSeq.simps(1) transfer_normal)
next
case (CptnModWhile3 \<Gamma> P s xs t f b s' ys zs)
then have "(\<Gamma>,(Seq P (While b P), s) # zs) \<in> cptn"
using seq3 by blast
moreover have "\<Gamma>\<turnstile>\<^sub>c(While b P,toSeq ( s)) \<rightarrow> (Seq P (While b P),toSeq ( s))"
by (simp add: CptnModWhile3.hyps(5) WhileTruec)
ultimately show ?case by (metis cptn.Cptn prod.collapse toSeq.simps(1) transfer_normal)
next
case (CptnModCall \<Gamma> bdy s ys p) thus ?case
by (metis Callc cptn.Cptn prod.exhaust_sel transfer_normal)
next
case (CptnModDynCom \<Gamma> c s ys) thus ?case
by (metis DynComc cptn.Cptn prod.exhaust_sel transfer_normal)
next
case (CptnModGuard \<Gamma> c s ys g f) thus ?case
by (metis Guardc cptn.Cptn prod.exhaust_sel transfer_normal)
next
case (CptnModCatch1 \<Gamma> P0 s xs zs P1)
have "(\<Gamma>, map (lift_catch P1) ((P0, s) # xs)) \<in> cptn"
using CptnModCatch1.hyps(2) lift_catch_is_cptn by blast
thus ?case by (simp add: Cons_lift_catch CptnModCatch1.hyps(3))
next
case (CptnModCatch2 \<Gamma> P0 s xs t f ys zs P1)
thus ?case
proof (induct xs arbitrary: zs P0 s)
case Nil
then have step: "\<Gamma>\<turnstile>\<^sub>c (Catch t P1, s) \<rightarrow>\<^sub>c\<^sub>e (t, s)"
by (metis CatchFaultc CatchSkipc CatchStuckc c_step)
have "\<exists>c p. (c, p) # zs = (LanguageCon.com.Catch P0 P1, s) # zs \<and> \<Gamma>\<turnstile>\<^sub>c (c, p) \<rightarrow>\<^sub>c\<^sub>e (P0, s)"
using step Nil.prems(3) by force
then show ?case
using Nil.prems(7) Nil.prems(3) Nil.prems(6) cptn.simps by fastforce
next
case (Cons a as)
then obtain sa where "snd a = sa" by auto
then obtain a1 a2 where a_prod:"a=(a1,a2)" and sa_a2: "a2 =sa"
using prod.exhaust_sel by blast
obtain la1 la2 where last_prod:"last (a#as) = (la1,la2)"
using prod.exhaust_sel by blast
then have lasst_aas_last: "last (a#as) = (last ((P0, s) # a # as))" by auto
then have "la1 = t" using Cons.prems(3) last_prod by force
have f1: "(\<Gamma>, (a1, a2) # as) \<in> cptn"
using Cons.prems(2) a_prod cptn_dest by blast
have "(\<Gamma>, a # as) \<in> cptn_mod"
using f1 a_prod cptn_onlyif_cptn_mod by blast
then have hyp:"(\<Gamma>, (Catch a1 P1, a2) #
map (lift_catch P1) as @ ((t, la2)#ys)) \<in> cptn"
using Cons.prems a_prod f1 last_prod
by (simp add: Cons.hyps)
thus ?case
proof -
have "(a1, sa) # as = a # as"
using a_prod sa_a2 by fastforce
then have f1: "(LanguageCon.com.Catch a1 P1, sa) # map (lift_catch P1) as @ (t, la2) # ys = zs"
using Cons.prems(7) Cons_lift_catch_append last_prod by fastforce
have f2: "((LanguageCon.com.Catch P0 P1, s) # map (lift_catch P1) (a # as)) ! Suc 0 = lift_catch P1 (a1, a2)"
by (simp add: a_prod)
have f3: "lift_catch P1 (a1, a2) = (LanguageCon.com.Catch a1 P1, a2)"
by (metis (no_types) Cons_lift_catch list.inject list.simps(9))
have "Suc 0 < length ((LanguageCon.com.Catch P0 P1, s) # map (lift_catch P1) (a # as))"
by simp
then show ?thesis
using f3 f2 f1 by (metis (no_types) Cons.prems(2) Cons_lift_catch cptn.Cptn cptn_stepc_rtran hyp lift_catch_is_cptn nth_Cons_0 sa_a2)
qed
qed
next
case (CptnModCatch3 \<Gamma> P0 s xs s' P1 ys zs)
thus ?case
proof (induct xs arbitrary: zs P0 s)
case Nil
then have "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Catch LanguageCon.com.Throw P1, s) \<rightarrow>\<^sub>c\<^sub>e (P1, s)"
by (metis CatchThrowc prod.exhaust_sel transfer_normal)
then have "\<exists>c p. (c, p) # zs = (LanguageCon.com.Catch LanguageCon.com.Throw P1, s) # zs \<and> \<Gamma>\<turnstile>\<^sub>c (c, p) \<rightarrow>\<^sub>c\<^sub>e (P1, s)"
by auto
thus ?case using cptn.simps
using Nil.prems(3) Nil.prems(6) Nil.prems(7) by fastforce
next
case (Cons a as)
then obtain sa where "snd a = sa" by auto
obtain a1 a2 where a_prod:"a=(a1,a2)"
by (meson prod.exhaust_sel)
obtain la1 la2 where last_prod:"last (a#as) = (la1,la2)"
by (meson prod.exhaust_sel)
then have lasst_aas_last: "last (a#as) = (last ((P0, s) # a # as))" by auto
then have "la1 = Throw" using Cons.prems(3) last_prod by force
have "la2 = s'" using Cons.prems(4) last_prod lasst_aas_last by force
have f1: "(\<Gamma>, (a1, a2) # as) \<in> cptn"
using Cons.prems(2) a_prod cptn_dest by blast
have f2: "sa = a2"
using `snd a = sa` a_prod by force
have "(\<Gamma>, a # as) \<in> cptn_mod"
using f1 a_prod cptn_onlyif_cptn_mod by blast
then have hyp:"(\<Gamma>, (Catch a1 P1, sa) #
map (lift_catch P1) as @ (P1, snd (last ((a1, sa) # as))) # ys) \<in> cptn"
using Cons.hyps Cons.prems a_prod f1 f2
by (metis lasst_aas_last)
thus ?case
proof -
(* have "\<Gamma>\<turnstile>\<^sub>c (P0, Normal s) \<rightarrow>\<^sub>e (P0, a2)"
by (fastforce intro: step_e.intros)
then *)
have transit:"\<Gamma>\<turnstile>\<^sub>c(P0, s) \<rightarrow>\<^sub>c\<^sub>e (a1, sa)"
by (metis (no_types) Cons.prems(2) a_prod cptn_elim_cases(2) f2)
then have transit_catch:"\<Gamma>\<turnstile>\<^sub>c(Catch P0 P1, s) \<rightarrow>\<^sub>c\<^sub>e (Catch a1 P1, sa)"
proof -
have f1: "P0 = a1 \<or> \<not> \<Gamma>\<turnstile>\<^sub>c (P0, s) \<rightarrow>\<^sub>e (a1, sa)"
using not_eq_not_env transit by blast
have "\<Gamma>\<turnstile>\<^sub>c (a1, s) \<rightarrow>\<^sub>e (a1, sa) \<longrightarrow>
\<Gamma>\<turnstile>\<^sub>c (Catch a1 P1, s) \<rightarrow>\<^sub>e (Catch a1 P1, sa)"
using env_intro
by (simp add: env_intro_diff_p)
then show ?thesis
using f1 by (metis (no_types) Catchc e_step prod.collapse
step_dest toSeq.simps(1) transfer_normal transit)
qed
have "a=(a1, sa)" using a_prod f2 by auto
then have "snd (last ((a1, sa) # as)) = s'"
using Cons lasst_aas_last by fastforce
hence f1: "snd (last ((a1, sa) # as)) = la2"
using `la2 = s'` by blast
have "(Catch a1 P1, a2) # map (lift_catch P1) as @ (P1, la2) # ys = zs"
using Cons.prems Cons_lift_catch_append a_prod last_prod
by (simp add: Cons_lift_catch_append)
moreover have "\<Gamma>\<turnstile>\<^sub>c (LanguageCon.com.Catch P0 P1, s) \<rightarrow>\<^sub>c\<^sub>e (LanguageCon.com.Catch a1 P1, a2)"
using f2 transit_catch by blast
ultimately show ?thesis
using f1 cptn.Cptn f2 hyp by metis
qed
qed
next
case (CptnModEnv) thus ?case
by (simp add: cptn.Cptn e_step)
qed
lemma cptn_eq_cptn_mod:
shows "(x \<in>cptn_mod) = (x\<in>cptn)"
by (cases x, auto simp add: cptn_if_cptn_mod cptn_onlyif_cptn_mod)
lemma cptn_eq_cptn_mod_set:
shows "cptn_mod = cptn"
by (auto simp add: cptn_if_cptn_mod cptn_onlyif_cptn_mod)
subsection \<open>Computational modular semantic for nested calls\<close>
inductive_set cptn_mod_nest_call :: "(nat\<times>('g,'l,'p,'f,'e) confs) set"
where
CptnModNestOne: "(n,\<Gamma>,[(P, s)]) \<in> cptn_mod_nest_call"
| CptnModNestEnv: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,s) \<rightarrow>\<^sub>e (P,t);(n,\<Gamma>,(P, t)#xs) \<in> cptn_mod_nest_call\<rbrakk> \<Longrightarrow>
(n,\<Gamma>,(P, s)#(P, t)#xs) \<in> cptn_mod_nest_call"
| CptnModNestSkip: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,toSeq s) \<rightarrow> (Skip,toSeq t); redex P = P;
snd s= snd t;
\<forall>f. ((\<Gamma> f) = Some Skip \<longrightarrow> P \<noteq> Call f );
(n,\<Gamma>,(Skip, t)#xs) \<in> cptn_mod_nest_call \<rbrakk> \<Longrightarrow>
(n,\<Gamma>,(P,s)#(Skip, t)#xs) \<in>cptn_mod_nest_call"
| CptnModNestThrow: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,toSeq s) \<rightarrow> (Throw,toSeq t); redex P = P;
\<forall>f. ((\<Gamma> f) = Some Throw \<longrightarrow> P \<noteq> Call f ); snd s = snd t;
(n,\<Gamma>,(Throw, t)#xs) \<in> cptn_mod_nest_call \<rbrakk> \<Longrightarrow>
(n,\<Gamma>,(P,s)#(Throw, t)#xs) \<in>cptn_mod_nest_call"
| CptnModNestStuck: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,toSeq s) \<rightarrow> (Stuck,toSeq t); redex P = P;
\<forall>f. ((\<Gamma> f) = Some Stuck \<longrightarrow> P \<noteq> Call f ); snd s = snd t;
(n,\<Gamma>,(Stuck, t)#xs) \<in> cptn_mod_nest_call \<rbrakk> \<Longrightarrow>
(n,\<Gamma>,(P,s)#(Stuck, t)#xs) \<in>cptn_mod_nest_call"
| CptnModNestFault: "\<lbrakk>\<Gamma>\<turnstile>\<^sub>c(P,toSeq s) \<rightarrow> (Fault f,toSeq t); redex P = P;
\<forall>fn. ((\<Gamma> fn) = Some (Fault f) \<longrightarrow> P \<noteq> Call fn); snd s = snd t;
(n,\<Gamma>,((Fault f), t)#xs) \<in> cptn_mod_nest_call \<rbrakk> \<Longrightarrow>
(n,\<Gamma>,(P,s)#(Fault f, t)#xs) \<in>cptn_mod_nest_call"
| CptnModNestCondT: "\<lbrakk>(n,\<Gamma>,(P0, s)#ys) \<in> cptn_mod_nest_call; fst s \<in> b \<rbrakk> \<Longrightarrow>
(n,\<Gamma>,((Cond b P0 P1), s)#(P0, s)#ys) \<in> cptn_mod_nest_call"
| CptnModNestCondF: "\<lbrakk>(n,\<Gamma>,(P1, s)#ys) \<in> cptn_mod_nest_call; fst s \<notin> b \<rbrakk> \<Longrightarrow>
(n,\<Gamma>,((Cond b P0 P1), s)#(P1, s)#ys) \<in> cptn_mod_nest_call"
| CptnModNestSeq1:
"\<lbrakk>(n,\<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call; zs=map (lift P1) xs \<rbrakk> \<Longrightarrow>
(n,\<Gamma>,((Seq P0 P1), s)#zs) \<in> cptn_mod_nest_call"
| CptnModNestSeq2:
"\<lbrakk>(n,\<Gamma>, (P0, s)#xs) \<in> cptn_mod_nest_call; fst(last ((P0, s)#xs)) = Skip;
(n,\<Gamma>,(P1, snd(last ((P0, s)#xs)))#ys) \<in> cptn_mod_nest_call;
zs=(map (lift P1) xs)@((P1, snd(last ((P0, s)#xs)))#ys) \<rbrakk> \<Longrightarrow>
(n,\<Gamma>,((Seq P0 P1), s)#zs) \<in> cptn_mod_nest_call"
| CptnModNestSeq3:
"\<lbrakk>(n,\<Gamma>, (P0, s)#xs) \<in> cptn_mod_nest_call;
fst(last ((P0, s)#xs)) = t; t = Fault f \<or> t = Stuck \<or> t = Throw;
snd(last ((P0, s)#xs)) = s';
(n,\<Gamma>,(t, s')#ys) \<in> cptn_mod_nest_call;
zs=(map (lift P1) xs)@((t, s')#ys) \<rbrakk> \<Longrightarrow>
(n,\<Gamma>,((Seq P0 P1), s)#zs) \<in> cptn_mod_nest_call"
| CptnModNestWhile1:
"\<lbrakk>(n,\<Gamma>, (P, s)#xs) \<in> cptn_mod_nest_call; fst s \<in> b;
zs=map (lift (While b P)) xs \<rbrakk> \<Longrightarrow>
(n,\<Gamma>, ((While b P), s)#
((Seq P (While b P)), s)#zs) \<in> cptn_mod_nest_call"
| CptnModNestWhile2:
"\<lbrakk> (n,\<Gamma>, (P, s)#xs) \<in> cptn_mod_nest_call;
fst(last ((P, s)#xs))=Skip; fst s \<in> b;
zs=(map (lift (While b P)) xs)@
(While b P, snd(last ((P, s)#xs)))#ys;
(n,\<Gamma>,(While b P, snd(last ((P, s)#xs)))#ys) \<in>
cptn_mod_nest_call\<rbrakk> \<Longrightarrow>
(n,\<Gamma>,(While b P, s)#
(Seq P (While b P), s)#zs) \<in> cptn_mod_nest_call"
| CptnModNestWhile3:
"\<lbrakk> (n,\<Gamma>, (P, s)#xs) \<in> cptn_mod_nest_call;
fst(last ((P, s)#xs))=t; t=Throw \<or> t= Fault f \<or> t = Stuck; fst s \<in> b;
snd(last ((P, s)#xs)) = s';
(n,\<Gamma>,(t, s')#ys) \<in> cptn_mod_nest_call;
zs=(map (lift (While b P)) xs)@((t, s')#ys)\<rbrakk> \<Longrightarrow>
(n,\<Gamma>,(While b P, s)#
(Seq P (While b P), s)#zs) \<in> cptn_mod_nest_call"
| CptnModNestCall: "\<lbrakk>(n,\<Gamma>,(bdy, s)#ys) \<in> cptn_mod_nest_call;\<Gamma> p = Some bdy; bdy\<noteq>Call p \<rbrakk> \<Longrightarrow>
(Suc n, \<Gamma>,((Call p), s)#(bdy, s)#ys) \<in> cptn_mod_nest_call"
| CptnModNestDynCom: "\<lbrakk>(n,\<Gamma>,(c (fst s), s)#ys) \<in> cptn_mod_nest_call \<rbrakk> \<Longrightarrow>
(n,\<Gamma>,(DynCom c, s)#(c (fst s), s)#ys) \<in> cptn_mod_nest_call"
| CptnModNestGuard: "\<lbrakk>(n,\<Gamma>,(c, s)#ys) \<in> cptn_mod_nest_call; fst s \<in> g \<rbrakk> \<Longrightarrow>
(n,\<Gamma>,(Guard f g c, s)#(c, s)#ys) \<in> cptn_mod_nest_call"
| CptnModNestCatch1: "\<lbrakk>(n,\<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call; zs=map (lift_catch P1) xs \<rbrakk>
\<Longrightarrow> (n,\<Gamma>,((Catch P0 P1), s)#zs) \<in> cptn_mod_nest_call"
| CptnModNestCatch2:
"\<lbrakk>(n,\<Gamma>, (P0, s)#xs) \<in> cptn_mod_nest_call; fst(last ((P0, s)#xs)) = t;
t = Skip \<or> t = Fault f \<or> t=Stuck;
(n,\<Gamma>,(t,snd(last ((P0, s)#xs)))#ys) \<in> cptn_mod_nest_call;
zs=(map (lift_catch P1) xs)@((t,snd(last ((P0, s)#xs)))#ys) \<rbrakk> \<Longrightarrow>
(n,\<Gamma>,((Catch P0 P1), s)#zs) \<in> cptn_mod_nest_call"
| CptnModNestCatch3:
"\<lbrakk>(n,\<Gamma>, (P0, s)#xs) \<in> cptn_mod_nest_call; fst(last ((P0, s)#xs)) = Throw;
snd(last ((P0, s)#xs)) = s';
(n,\<Gamma>,(P1, snd(last ((P0, s)#xs)))#ys) \<in> cptn_mod_nest_call;
zs=(map (lift_catch P1) xs)@((P1, snd(last ((P0, s)#xs)))#ys) \<rbrakk> \<Longrightarrow>
(n,\<Gamma>,((Catch P0 P1), s)#zs) \<in> cptn_mod_nest_call"
lemmas CptnMod_nest_call_induct = cptn_mod_nest_call.induct [of _ _ "[(c,s)]", split_format (complete), case_names
CptnModOne CptnModEnv CptnModSkip CptnModThrow CptnModNestStuck CptnModNestFault CptnModCondT CptnModCondF
CptnModSeq1 CptnModSeq2 CptnModSeq3 CptnModSeq4 CptnModWhile1 CptnModWhile2 CptnModWhile3 CptnModCall CptnModDynCom CptnModGuard
CptnModCatch1 CptnModCatch2 CptnModCatch3, induct set]
inductive_cases CptnModNest_elim_cases [cases set]:
"(n,\<Gamma>,(Skip, s)#u#xs) \<in> cptn_mod_nest_call"
"(n,\<Gamma>,(Fault f, s)#u#xs) \<in> cptn_mod_nest_call"
"(n,\<Gamma>,(Stuck, s)#u#xs) \<in> cptn_mod_nest_call"
"(n,\<Gamma>,(Guard f g c, s)#u#xs) \<in> cptn_mod_nest_call"
"(n,\<Gamma>,(Basic f e, s)#u#xs) \<in> cptn_mod_nest_call"
"(n,\<Gamma>,(Spec r e, s)#u#xs) \<in> cptn_mod_nest_call"
"(n,\<Gamma>,(Seq c1 c2, s)#u#xs) \<in> cptn_mod_nest_call"
"(n,\<Gamma>,(Cond b c1 c2, s)#u#xs) \<in> cptn_mod_nest_call"
"(n,\<Gamma>,(Await b c2 e, s)#u#xs) \<in> cptn_mod_nest_call"
"(n,\<Gamma>,(Call p, s)#u#xs) \<in> cptn_mod_nest_call"
"(n,\<Gamma>,(DynCom c,s)#u#xs) \<in> cptn_mod_nest_call"
"(n,\<Gamma>,(Throw,s)#u#xs) \<in> cptn_mod_nest_call"
"(n,\<Gamma>,(Catch c1 c2,s)#u#xs) \<in> cptn_mod_nest_call"
inductive_cases stepc_elim_cases_Seq_Seq':
"\<Gamma>\<turnstile>\<^sub>c(Seq c1 c2,s) \<rightarrow> (Seq c1' c2',s')"
inductive_cases stepc_elim_cases_Catch_Catch':
"\<Gamma>\<turnstile>\<^sub>c(Catch c1 c2,s) \<rightarrow> (Catch c1' c2',s')"
inductive_cases CptnModNest_same_elim_cases [cases set]:
"(n,\<Gamma>,(u, s)#(u,t)#xs) \<in> cptn_mod_nest_call"
inductive_cases CptnModNest_elim_cases_Call_Skip [cases set]:
"(n,\<Gamma>,(Call p, s)#(Skip, s)#xs) \<in> cptn_mod_nest_call"
inductive_cases CptnModNest_elim_cases_Call_Stuck [cases set]:
"(n,\<Gamma>,(Call p, s)#(Stuck, s)#xs) \<in> cptn_mod_nest_call"
inductive_cases CptnModNest_elim_cases_Call_Fault [cases set]:
"(n,\<Gamma>,(Call p, s)#(Fault f, s)#xs) \<in> cptn_mod_nest_call"
inductive_cases CptnModNest_elim_cases_Call_Throw [cases set]:
"(n,\<Gamma>,(Call p, s)#(Throw, s)#xs) \<in> cptn_mod_nest_call"
inductive_cases CptnModNest_elim_cases_Call [cases set]:
"(0, \<Gamma>,((Call p), s)#(bdy, s)#ys) \<in> cptn_mod_nest_call"
inductive_cases CptnEmpty [cases set]:
"(n, \<Gamma>,[]) \<in> cptn_mod_nest_call"
inductive_cases CptnModNest_elim_cases_Call_normal [cases set]:
"(Suc n, \<Gamma>,((Call p), s)#(bdy, s)#ys) \<in> cptn_mod_nest_call"
lemma cptn_mod_nest_mono1: "(n,\<Gamma>,cfs) \<in> cptn_mod_nest_call \<Longrightarrow> (Suc n,\<Gamma>,cfs)\<in> cptn_mod_nest_call"
proof (induct rule:cptn_mod_nest_call.induct)
case (CptnModNestOne) thus ?case using cptn_mod_nest_call.CptnModNestOne by blast
next
case (CptnModNestEnv) thus ?case using cptn_mod_nest_call.CptnModNestEnv by blast
next
case (CptnModNestSkip) thus ?case using cptn_mod_nest_call.CptnModNestSkip by blast
next
case (CptnModNestThrow) thus ?case using cptn_mod_nest_call.intros(4) by blast
next
case (CptnModNestFault) thus ?case using cptn_mod_nest_call.intros(6) by fast
next
case (CptnModNestStuck) thus ?case using cptn_mod_nest_call.intros(5) by fast
next
case (CptnModNestCondT n) thus ?case
using cptn_mod_nest_call.CptnModNestCondT[of "Suc n"] by blast
next
case (CptnModNestCondF n) thus ?case
using cptn_mod_nest_call.CptnModNestCondF[of "Suc n"] by blast
next
case (CptnModNestSeq1 n) thus ?case
using cptn_mod_nest_call.CptnModNestSeq1[of "Suc n"] by blast
next
case (CptnModNestSeq2 n) thus ?case
using cptn_mod_nest_call.CptnModNestSeq2[of "Suc n"] by blast
next
case (CptnModNestSeq3 n) thus ?case
using cptn_mod_nest_call.CptnModNestSeq3[of "Suc n"]by fast
next
case (CptnModNestWhile1 n) thus ?case
using cptn_mod_nest_call.CptnModNestWhile1[of "Suc n"] by blast
next
case (CptnModNestWhile2 n) thus ?case
using cptn_mod_nest_call.CptnModNestWhile2[of "Suc n"] by blast
next
case (CptnModNestWhile3 n \<Gamma> P s xs t f b s' ys zs) thus ?case
using cptn_mod_nest_call.CptnModNestWhile3[of "Suc n" \<Gamma>] by blast
next
case (CptnModNestCall) thus ?case
using cptn_mod_nest_call.CptnModNestCall by fastforce
next
case (CptnModNestDynCom) thus ?case
using cptn_mod_nest_call.CptnModNestDynCom by blast
next
case (CptnModNestGuard n) thus ?case
using cptn_mod_nest_call.CptnModNestGuard[of "Suc n"] by fastforce
next
case (CptnModNestCatch1 n) thus ?case
using cptn_mod_nest_call.CptnModNestCatch1[of "Suc n"] by fastforce
next
case (CptnModNestCatch2 n) thus ?case
using cptn_mod_nest_call.CptnModNestCatch2[of "Suc n"] by fast
next
case (CptnModNestCatch3 n) thus ?case
using cptn_mod_nest_call.CptnModNestCatch3[of "Suc n"] by fast
qed
lemma cptn_mod_nest_mono2:
"(n,\<Gamma>,cfs) \<in> cptn_mod_nest_call \<Longrightarrow> m>n \<Longrightarrow>
(m,\<Gamma>,cfs)\<in> cptn_mod_nest_call"
proof (induct "m-n" arbitrary: m n)
case 0 thus ?case by auto
next
case (Suc k)
have "m - Suc n = k"
using Suc.hyps(2) Suc.prems(2) Suc_diff_Suc Suc_inject by presburger
then show ?case
using Suc.hyps(1) Suc.prems(1) Suc.prems(2) cptn_mod_nest_mono1 less_Suc_eq by blast
qed
lemma cptn_mod_nest_mono:
"(n,\<Gamma>,cfs) \<in> cptn_mod_nest_call \<Longrightarrow> m\<ge>n \<Longrightarrow>
(m,\<Gamma>,cfs)\<in> cptn_mod_nest_call"
proof (cases "n=m")
assume "(n, \<Gamma>, cfs) \<in> cptn_mod_nest_call" and
"n = m" thus ?thesis by auto
next
assume "(n, \<Gamma>, cfs) \<in> cptn_mod_nest_call" and
"n\<le>m" and
"n \<noteq> m"
thus ?thesis by (auto simp add: cptn_mod_nest_mono2)
qed
subsection \<open>Equivalence of comp mod semantics and comp mod nested\<close>
definition catch_cond_nest
where
"catch_cond_nest zs Q xs P s s'' s' \<Gamma> n \<equiv> (zs=(map (lift_catch Q) xs) \<or>
((fst(((P, s)#xs)!length xs)=Throw \<and>
snd(last ((P, s)#xs)) = s' \<and> s= s''\<and>
(\<exists>ys. (n,\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod_nest_call \<and>
zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or>
(\<exists>t. (fst(((P, s)#xs)!length xs)=t \<and> (t=Skip \<or> (\<exists>f. t = Fault f) \<or> t = Stuck) \<and>
(\<exists>ys. (n,\<Gamma>,(t,snd(last ((P, s)#xs)))#ys) \<in> cptn_mod_nest_call \<and>
zs=(map (lift_catch Q) xs)@((t,snd(last ((P, s)#xs)))#ys)))))
"
lemma div_catch_nest: assumes cptn_m:"(n,\<Gamma>,list) \<in> cptn_mod_nest_call"
shows "(\<forall>s P Q zs. list=(Catch P Q, s)#zs \<longrightarrow>
(\<exists>xs s' s''.
(n, \<Gamma>,(P, s)#xs) \<in> cptn_mod_nest_call \<and>
catch_cond_nest zs Q xs P s s'' s' \<Gamma> n))
"
unfolding catch_cond_nest_def
using cptn_m
proof (induct rule: cptn_mod_nest_call.induct)
case (CptnModNestOne \<Gamma> P s)
thus ?case using cptn_mod_nest_call.CptnModNestOne by blast
next
case (CptnModNestSkip \<Gamma> P s t n xs)
from CptnModNestSkip.hyps
have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Skip, toSeq t)" by auto
from CptnModNestSkip.hyps
have noskip: "~(P=Skip)" using stepc_elim_cases(1) by auto
have no_catch: "\<forall>p1 p2. \<not>(P=Catch p1 p2)" using CptnModNestSkip.hyps(2) redex_not_Catch by auto
from CptnModNestSkip.hyps
have in_cptn_mod: "(n,\<Gamma>, (Skip, t) # xs) \<in> cptn_mod_nest_call" by auto
then show ?case using no_catch by simp
next
case (CptnModNestThrow \<Gamma> P s t n xs)
from CptnModNestThrow.hyps
have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Throw, toSeq t)" by auto
from CptnModNestThrow.hyps
have in_cptn_mod: "(n,\<Gamma>, (Throw, t) # xs) \<in> cptn_mod_nest_call" by auto
have no_catch: "\<forall>p1 p2. \<not>(P=Catch p1 p2)" using CptnModNestThrow.hyps(2) redex_not_Catch by auto
then show ?case by auto
next
case (CptnModNestStuck \<Gamma> P s t n xs)
from CptnModNestStuck.hyps
have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Stuck, toSeq t)" by auto
from CptnModNestStuck.hyps
have in_cptn_mod: "(n,\<Gamma>, (Stuck, t) # xs) \<in> cptn_mod_nest_call" by auto
have no_catch: "\<forall>p1 p2. \<not>(P=Catch p1 p2)" using CptnModNestStuck.hyps(2) redex_not_Catch by auto
then show ?case by auto
next
case (CptnModNestFault \<Gamma> P s f t n xs)
from CptnModNestFault.hyps
have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Fault f, toSeq t)" by auto
from CptnModNestFault.hyps
have in_cptn_mod: "(n,\<Gamma>, (Fault f, t) # xs) \<in> cptn_mod_nest_call" by auto
have no_catch: "\<forall>p1 p2. \<not>(P=Catch p1 p2)" using CptnModNestFault.hyps(2) redex_not_Catch by auto
then show ?case by auto
next
case (CptnModNestCondT \<Gamma> P0 s ys b P1)
thus ?case using CptnModOne by blast
next
case (CptnModNestCondF \<Gamma> P0 s ys b P1)
thus ?case using CptnModOne by blast
next
case (CptnModNestCatch1 sa P Q zs)
thus ?case by blast
next
case (CptnModNestCatch2 n \<Gamma> P0 s xs t f ys zs P1)
from CptnModNestCatch2.hyps(3)
have last:"fst (((P0, s) # xs) ! length xs) = t"
by (simp add: last_length)
have P0cptn:"(n,\<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call" by fact
then have "zs = map (lift_catch P1) xs @((t,snd(last ((P0, s)#xs)))#ys)"
by (simp add:CptnModNestCatch2.hyps)
show ?case
proof -{
fix sa P Q zsa
assume eq:"(Catch P0 P1, s) # zs = (Catch P Q, sa) # zsa"
then have "P0 =P \<and> P1 = Q \<and> s=sa \<and> zs=zsa" by auto
then have "(P0, s) = (P, sa)" by auto
have "last ((P0, s) # xs) = ((P, sa) # xs) ! length xs"
by (simp add: `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa` last_length)
then have "zs = (map (lift_catch Q) xs)@((t,snd(last ((P0, s)#xs)))#ys)"
using `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa` `zs = map (lift_catch P1) xs @ ((t,snd(last ((P0, s)#xs)))#ys)`
by force
then have "(\<exists>xs s' s''. ((n,\<Gamma>,(P, s)#xs) \<in> cptn_mod_nest_call \<and>
((zs=(map (lift_catch Q) xs) \<or>
((fst(((P, s)#xs)!length xs)=Throw \<and>
snd(last ((P, s)#xs)) = s' \<and> s= s''\<and>
(\<exists>ys. (n,\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod_nest_call \<and>
zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or>
(\<exists>t. ((fst(((P, s)#xs)!length xs)=t \<and> (t = LanguageCon.com.Skip \<or> (\<exists>f. t = com.Fault f) \<or> t = com.Stuck) \<and>
(\<exists>ys. (n,\<Gamma>,(t,snd(last ((P, s)#xs)))#ys) \<in> cptn_mod_nest_call \<and>
zs=(map (lift_catch Q) xs)@((t,snd(last ((P0, s)#xs)))#ys)))))))))"
using P0cptn `P0 = P \<and> P1 = Q \<and> s = sa \<and> zs = zsa`
last CptnModNestCatch2.hyps(4,5)
by blast
}
thus ?thesis by blast
qed
next
case (CptnModNestCatch3 n \<Gamma> P0 s xs s' P1 ys zs)
from CptnModNestCatch3.hyps(3)
have last:"fst (((P0, s) # xs) ! length xs) = Throw"
by (simp add: last_length)
from CptnModNestCatch3.hyps(4)
have lastnormal:"snd (last ((P0, s) # xs)) = s'"
by (simp add: last_length)
have P0cptn:"(n,\<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call" by fact
from CptnModNestCatch3.hyps(5)
have P1cptn:"(n,\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call"
by (simp add: last_length)
then have "zs = map (lift_catch P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys"
by (simp add:CptnModNestCatch3.hyps)
show ?case
by (metis CptnModNestCatch3.hyps(3) CptnModNestCatch3.hyps(5) CptnModNestCatch3.hyps(7)
LanguageCon.com.inject(10) P0cptn fst_conv last_length list.sel(3) nth_Cons_0 snd_conv)
next
case (CptnModNestEnv \<Gamma> P s t n xs)
then have step:"(n, \<Gamma>, (P, t) # xs) \<in> cptn_mod_nest_call" by auto
have step_e: "\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (P, t)" using CptnModNestEnv by auto
show ?case
proof (cases P)
case (Catch P1 P2)
then have eq_P_Catch:"(P, t) # xs = (LanguageCon.com.Catch P1 P2, t) # xs" by auto
then obtain xsa t' t'' where
p1:"(n,\<Gamma>, (P1, t) # xsa) \<in> cptn_mod_nest_call" and
p2:" (xs = map (lift_catch P2) xsa \<or>
fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \<and>
snd (last ((P1, t) # xsa)) = t' \<and>
t = t'' \<and>
(\<exists>ys. (n,\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<or>
(\<exists>c. fst (((P1, t) # xsa) ! length xsa) = c \<and> (c = Skip \<or> c = Stuck \<or> (\<exists>f. c = Fault f))\<and>
(\<exists>ys.(n,\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift_catch P2) xsa @
((c, snd (last ((P1, t) # xsa)))#ys))))"
using CptnModNestEnv(3) by fastforce
have all_step:"(n,\<Gamma>, (P1, s)#((P1, t) # xsa)) \<in> cptn_mod_nest_call"
proof -
have "\<Gamma>\<turnstile>\<^sub>c (P1, s) \<rightarrow>\<^sub>e (P1, t)"
using step_e
by (metis env_intro_diff_p)
then show ?thesis
by (simp add: cptn_mod_nest_call.CptnModNestEnv p1)
qed
show ?thesis using p2
proof
assume "xs = map (lift_catch P2) xsa"
have "(P, t) # xs = map (lift_catch P2) ((P1, t) # xsa)"
by (simp add: `xs = map (lift_catch P2) xsa` lift_catch_def local.Catch)
thus ?thesis using all_step eq_P_Catch by fastforce
next
assume
"fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \<and>
snd (last ((P1, t) # xsa)) = t' \<and>
t = t'' \<and>
(\<exists>ys. (n,\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<or>
(\<exists>c. fst (((P1, t) # xsa) ! length xsa) = c \<and> (c = Skip \<or> c = Stuck \<or> (\<exists>f. c = Fault f)) \<and>
(\<exists>ys. (n,\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift_catch P2) xsa @ ((c, snd (last ((P1, t) # xsa)))#ys)))"
then show ?thesis
proof
assume
a1:"fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \<and>
snd (last ((P1, t) # xsa)) = t' \<and> t = t'' \<and>
(\<exists>ys. (n,\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys)"
then obtain ys where p2_exec:
"(n,\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys"
by fastforce
from a1 obtain t1 where t_normal: "t= t1"
by blast
have f1:"fst (((P1, s)#(P1, t) # xsa) ! length ((P1, t)#xsa)) = LanguageCon.com.Throw"
using a1 by fastforce
from a1 have last_normal: "snd (last ((P1, s)#(P1, t) # xsa)) = t'"
by fastforce
then have p2_long_exec:
"(n,\<Gamma>, (P2, snd (((P1, s)#(P1, t) # xsa) ! length ((P1, s)#xsa))) # ys) \<in>
cptn_mod_nest_call \<and>
(P, t)#xs = map (lift_catch P2) ((P1, t) # xsa) @
(P2, snd (((P1, s)#(P1, t) # xsa) ! length ((P1, s)#xsa))) # ys"
using p2_exec by (simp add: lift_catch_def local.Catch)
thus ?thesis using a1 f1 last_normal all_step eq_P_Catch by fastforce
next
assume
as1:
"\<exists>c. fst (((P1, t) # xsa) ! length xsa) =c \<and> (c = Skip \<or> c = Stuck \<or> (\<exists>f. c = Fault f)) \<and>
(\<exists>ys. (n,\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift_catch P2) xsa @ ((c, snd (last ((P1, t) # xsa)))#ys))"
then obtain c where
as1:"fst (((P1, t) # xsa) ! length xsa) =c \<and> (c = Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck ) \<and>
(\<exists>ys. (n,\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift_catch P2) xsa @ ((c, snd (last ((P1, t) # xsa)))#ys))"
by auto
then obtain ys where p1:
"(n,\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \<in> cptn_mod_nest_call \<and>
(P, t)#xs = map (lift_catch P2) ((P1, t) # xsa) @ ((c, snd (last ((P1, t) # xsa)))#ys)"
proof -
assume a1: "\<And>ys. (n,\<Gamma>, (c, snd (last ((P1, t) # xsa))) # ys) \<in> cptn_mod_nest_call \<and>
(P, t) # xs = map (lift_catch P2) ((P1, t) # xsa) @
(c, snd (last ((P1, t) # xsa))) # ys \<Longrightarrow> thesis"
have "(LanguageCon.com.Catch P1 P2, t) # map (lift_catch P2) xsa =
map (lift_catch P2) ((P1, t) # xsa)"
by (simp add: lift_catch_def)
thus ?thesis
using a1 as1 eq_P_Catch as1 by auto
qed
from as1 have p2: "fst (((P1, s)#(P1, t) # xsa) ! length ((P1, t) #xsa)) =c"
by fastforce
moreover have " (c = Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck )" using as1 by auto
ultimately show ?thesis using p1 all_step eq_P_Catch by fastforce
qed
qed
qed (auto)
qed(force+)
definition seq_cond_nest
where
"seq_cond_nest zs Q xs P s s'' s' \<Gamma> n \<equiv>
(zs=(map (lift Q) xs) \<or>
((fst(((P, s)#xs)!length xs)=Skip \<and>
(\<exists>ys. (n,\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod_nest_call \<and>
zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or>
(\<exists>c. (fst(((P, s)#xs)!length xs)=c \<and> (c = Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
snd(last ((P, s)#xs)) = s' \<and> s= s''\<and>
(\<exists>ys. (n,\<Gamma>,(c, s')#ys) \<in> cptn_mod_nest_call \<and> zs=(map (lift Q) xs)@((c, s')#ys)))))"
lemma Seq_P_Not_finish:
assumes
a0:"zs = map (lift Q) xs" and
a1:"(m, \<Gamma>,(LanguageCon.com.Seq P Q, s) # zs) \<in> cptn_mod_nest_call" and
a2:"seq_cond_nest zs Q xs' P s s'' s' \<Gamma> m"
shows "xs=xs'"
using a2 unfolding seq_cond_nest_def
proof
assume "zs= map (lift Q) xs'"
then have "map (lift Q) xs' =
map (lift Q) xs" using a0 by auto
thus ?thesis using map_lift_eq_xs_xs' by fastforce
next
assume
ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \<and>
(\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \<or>
(\<exists>c. fst (((P, s) # xs') ! length xs') = c \<and> (c = Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
snd (last ((P, s) # xs')) = s' \<and> s = s'' \<and>
(\<exists>ys. (m, \<Gamma>, (c, s') # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (c, s') # ys))"
{assume
ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \<and>
(\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)"
then obtain ys where
zs:"zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys"
by auto
then have zs_while:"fst (zs!(length (map (lift Q) xs'))) = Q"
by (metis fstI nth_append_length)
have "length zs = length (map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)"
using zs by auto
then have "(length (map (lift Q) xs')) < length zs" by auto
then have ?thesis using a0 zs_while map_lift_all_seq
using seq_and_if_not_eq(4) by fastforce
}note l = this
{assume ass:
"\<exists>c. fst (((P, s) # xs') ! length xs') = c \<and> (c = Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
snd (last ((P, s) # xs')) = s' \<and> s = s'' \<and>
(\<exists>ys. (m, \<Gamma>, (c, s') # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (c, s') # ys)"
then obtain c ys where zs:
"zs = map (lift Q) xs' @ (c, s') # ys \<and> (c = Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck)" by auto
then have zs_while:
"fst (zs!(length (map (lift Q) xs'))) = c" by (metis fstI nth_append_length)
have "length zs = length (map (lift Q) xs' @(c, s') # ys)"
using zs by auto
then have "(length (map (lift Q) xs')) < length zs" by auto
then have ?thesis using a0 zs_while map_lift_all_seq
by (metis LanguageCon.com.distinct(79) LanguageCon.com.distinct(85)
LanguageCon.com.distinct(87) zs)
} thus ?thesis using l ass by auto
qed
lemma Seq_P_Ends_Normal:
assumes
a0:"zs = map (lift Q) xs @ (Q, snd (last ((P, s) # xs))) # ys" and
a0':"fst (last ((P, s) # xs)) = Skip" and
a1:"(m, \<Gamma>,(LanguageCon.com.Seq P Q, s) # zs) \<in> cptn_mod_nest_call" and
a2:"seq_cond_nest zs Q xs' P s s'' s' \<Gamma> m"
shows "xs=xs' \<and> (m,\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod_nest_call"
using a2 unfolding seq_cond_nest_def
proof
assume ass:"zs= map (lift Q) xs'"
then have "map (lift Q) xs' =
map (lift Q) xs @ (Q, snd (last ((P, s) # xs))) # ys" using a0 by auto
then have zs_while:"fst (zs!(length (map (lift Q) xs))) = Q"
by (metis a0 fstI nth_append_length)
also have "length zs =
length (map (lift Q) xs @ (Q, snd (last ((P, s) # xs))) # ys)"
using a0 by auto
then have "(length (map (lift Q) xs)) < length zs" by auto
then show ?thesis using ass zs_while map_lift_all_seq
using seq_and_if_not_eq(4)
by metis
next
assume
ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \<and>
(\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \<or>
(\<exists>c. fst (((P, s) # xs') ! length xs') =c \<and> (c = Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
snd (last ((P, s) # xs')) = s' \<and> s = s'' \<and>
(\<exists>ys. (m, \<Gamma>, (c, s') # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift Q) xs' @ (c, s') # ys))"
{assume
ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \<and>
(\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)"
then obtain ys' where zs:
"zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys' \<and>
(m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys') \<in> cptn_mod_nest_call"
by auto
then have ?thesis
using map_lift_some_eq[of Q xs Q _ ys xs' Q _ ys'] a0 seq_and_if_not_eq(4)[of Q]
by fast
}note l = this
{assume ass:
"\<exists>c. fst (((P, s) # xs') ! length xs') = c \<and> (c = Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
snd (last ((P, s) # xs')) = s' \<and> s = s'' \<and>
(\<exists>ys. (m, \<Gamma>, (c, s') # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (c, s') # ys)"
then have "xs =xs'"
using a0 a0' map_lift_some_eq seq_and_if_not_eq(4)
by (metis (no_types) LanguageCon.com.distinct(79) LanguageCon.com.distinct(85)
LanguageCon.com.distinct(87))
then have False using a0' ass
by (metis LanguageCon.com.distinct(13)
LanguageCon.com.distinct(19) LanguageCon.com.distinct(21) last_length)
then have ?thesis by auto
} thus ?thesis using l ass by auto
qed
lemma Seq_P_Ends_Abort:
assumes
a0:"zs = map (lift Q) xs @ (c, s') # ys" and an:"c = Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck" and
a0':"fst (last ((P, s) # xs)) = c" and
a0'':"snd(last ((P, s) # xs)) = s'" and
a1:"(m, \<Gamma>,(LanguageCon.com.Seq P Q, s) # zs) \<in> cptn_mod_nest_call" and
a2:"seq_cond_nest zs Q xs' P s ns'' ns' \<Gamma> m"
shows "xs=xs' \<and> (m,\<Gamma>,(c, s')#ys) \<in> cptn_mod_nest_call"
using a2 unfolding seq_cond_nest_def
proof
assume ass:"zs= map (lift Q) xs'"
then have "map (lift Q) xs' =
map (lift Q) xs @ (c, s') # ys" using a0 by auto
then have zs_while:"fst (zs!(length (map (lift Q) xs))) = c"
by (metis a0 fstI nth_append_length)
also have "length zs =
length (map (lift Q) xs @ (c, s') # ys)"
using a0 by auto
then have "(length (map (lift Q) xs)) < length zs" by auto
then show ?thesis using ass zs_while map_lift_all_seq an
by (metis LanguageCon.com.distinct(79) LanguageCon.com.distinct(85) LanguageCon.com.simps(99))
next
assume
ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \<and>
(\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \<or>
(\<exists>c. fst (((P, s) # xs') ! length xs') = c \<and> (c = Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
snd (last ((P, s) # xs')) = ns' \<and> s = ns'' \<and>
(\<exists>ys. (m, \<Gamma>, (c, ns') # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (c, ns') # ys))"
{assume
ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \<and>
(\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)"
then obtain ys' where
zs:" (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys') \<in> cptn_mod_nest_call \<and>
zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys'"
by auto
then have "xs = xs'" and "ys = ys'"
using a0 a0' seq_and_if_not_eq(4)[of Q] ass map_lift_some_eq
by (metis LanguageCon.com.distinct(79)
LanguageCon.com.distinct(85) LanguageCon.com.distinct(87) an)+
then have ?thesis
using a0 ass by blast
}note l = this
{assume ass:"\<exists>c. fst (((P, s) # xs') ! length xs') = c \<and> (c = Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
snd (last ((P, s) # xs')) = ns' \<and> s = ns'' \<and>
(\<exists>ys. (m, \<Gamma>, (c, ns') # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (c, ns') # ys)"
then obtain c1 where
ass:"fst (((P, s) # xs') ! length xs') = c1 \<and> (c1 = Throw \<or> (\<exists>f. c1 = Fault f) \<or> c1 = Stuck) \<and>
snd (last ((P, s) # xs')) = ns' \<and> s = ns'' \<and>
(\<exists>ys. (m, \<Gamma>, (c1, ns') # ys) \<in> cptn_mod_nest_call \<and> zs = map (lift Q) xs' @ (c1, ns') # ys)"
by auto
then obtain ys' where
zs:"(m, \<Gamma>, (c1, ns') # ys') \<in> cptn_mod_nest_call \<and>
zs = map (lift Q) xs' @ (c1, ns') # ys'"
by auto
then have zs_while:
"fst (zs!(length (map (lift Q) xs'))) = c1"
by (metis fstI nth_append_length)
then have "xs=xs' \<and> ys = ys'"
using a0 zs map_lift_some_eq[of Q xs c s' ys xs' c1 ns' ys'] an ass
by (metis LanguageCon.com.distinct(79)
LanguageCon.com.distinct(85) LanguageCon.com.distinct(87))
then have ?thesis using a0 ass map_lift_some_eq an by blast
} thus ?thesis using l ass by auto
qed
lemma Catch_P_Not_finish:
assumes
a0:"zs = map (lift_catch Q) xs" and
a1:"catch_cond_nest zs Q xs' P s s'' s' \<Gamma> m"
shows "xs=xs'"
using a1 unfolding catch_cond_nest_def
proof
assume "zs= map (lift_catch Q) xs'"
then have "map (lift_catch Q) xs' =
map (lift_catch Q) xs" using a0 by auto
thus ?thesis using map_lift_catch_eq_xs_xs' by fastforce
next
assume
ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \<and>
snd (last ((P, s) # xs')) = s' \<and> s = s'' \<and>
(\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \<or>
(\<exists>c. fst (((P, s) # xs') ! length xs') = c \<and> (c = Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
(\<exists>ys. (m, \<Gamma>, (c, snd (last ((P, s) # xs'))) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys))"
{assume
ass:"\<exists>c. fst (((P, s) # xs') ! length xs') = c \<and> (c = Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
(\<exists>ys. (m, \<Gamma>, (c, snd (last ((P, s) # xs'))) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys)"
then obtain c where ass:
"fst (((P, s) # xs') ! length xs') = c \<and> (c = Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
(\<exists>ys. (m, \<Gamma>, (c, snd (last ((P, s) # xs'))) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys)"
by auto
then obtain ys where
zs:"(m, \<Gamma>, (c, snd (last ((P, s) # xs'))) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys"
by auto
then have zs_while:"fst (zs!(length (map (lift_catch Q) xs'))) = c "
by (metis fstI nth_append_length)
have "length zs = length (map (lift Q) xs' @
(Q, snd (((P, s) # xs') ! length xs')) # ys)"
using zs by auto
then have "(length (map (lift Q) xs')) < length zs" by auto
then have ?thesis using a0 zs_while map_lift_catch_all_catch ass
by (metis com.distinct(149) com.distinct(173) com.distinct(23) length_map)
}note l = this
{assume ass:"fst (((P, s) # xs') ! length xs') =Throw \<and>
snd (last ((P, s) # xs')) = s' \<and> s = s'' \<and>
(\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)"
then obtain ys where
zs:"zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys" by auto
then have zs_while:
"fst (zs!(length (map (lift Q) xs'))) = Q"
by (metis (no_types) eq_fst_iff length_map nth_append_length zs)
have "length zs = length (map (lift Q) xs' @(LanguageCon.com.Throw, s') # ys)"
using zs by auto
then have "(length (map (lift Q) xs')) <
length zs" by auto
then have ?thesis using a0 zs_while map_lift_catch_all_catch
by fastforce
} thus ?thesis using l ass by auto
qed
lemma Catch_P_Ends_Normal:
assumes
a0:"zs = map (lift_catch Q) xs @ (Q, snd (last ((P, s) # xs))) # ys" and
a0':"fst (last ((P, s) # xs)) = Throw" and
a1:"catch_cond_nest zs Q xs' P ( s) s'' s' \<Gamma> m"
shows "xs=xs' \<and> (m,\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod_nest_call"
using a1 unfolding catch_cond_nest_def
proof
assume ass:"zs= map (lift_catch Q) xs'"
then have "map (lift_catch Q) xs' =
map (lift_catch Q) xs @ (Q, snd (last ((P, s) # xs))) # ys"
using a0 by auto
then have zs_while:"fst (zs!(length (map (lift_catch Q) xs))) = Q"
by (metis a0 fstI nth_append_length)
also have "length zs = length (map (lift_catch Q) xs @ (Q, snd (last ((P, s) # xs))) # ys)"
using a0 by auto
then have "(length (map (lift_catch Q) xs)) < length zs" by auto
then show ?thesis using ass zs_while map_lift_catch_all_catch
using seq_and_if_not_eq(12)
by metis
next
assume ass: "fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \<and>
snd (last ((P, s) # xs')) = s' \<and> s = s'' \<and>
(\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \<or>
(\<exists>c. fst (((P, s) # xs') ! length xs') = c \<and> (c = Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
(\<exists>ys. (m, \<Gamma>, (c, snd (last ((P, s) # xs'))) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys))"
(* ass:"fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Throw \<and>
snd (last ((P, Normal s) # xs')) = ns' \<and>
s = ns'' \<and>
(\<exists>ys. (m, \<Gamma>, (Q, snd (((P, Normal s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (Q, snd (((P, Normal s) # xs') ! length xs')) # ys) \<or>
fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Skip \<and>
(\<exists>ys. (m, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P, Normal s) # xs'))) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, Normal s) # xs'))) # ys)" *)
{assume
ass:"(\<exists>c. fst (((P, s) # xs') ! length xs') = c \<and> (c = Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
(\<exists>ys. (m, \<Gamma>, (c, snd (last ((P, s) # xs'))) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys))"
then obtain c where ass:"fst (((P, s) # xs') ! length xs') = c \<and> (c = Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
(\<exists>ys. (m, \<Gamma>, (c, snd (last ((P, s) # xs'))) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys)"
by auto
then obtain ys' where
zs:"(m, \<Gamma>, (c, snd (last ((P, s) # xs'))) # ys') \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys'"
by auto
then have ?thesis
using map_lift_catch_some_eq[of Q xs Q _ ys xs' c _ ys']
zs a0 seq_and_if_not_eq(12)[of Q] a0' ass
by (metis com.distinct(147) com.distinct(149) com.distinct(171) com.distinct(173)
com.distinct(21) com.distinct(23) last_length)
}note l = this
{assume ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \<and>
snd (last ((P, s) # xs')) = s' \<and> s = s'' \<and>
(\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)"
then obtain ys' where
zs:"(m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys') \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys'"
by auto
then have zs_while:
"fst (zs!(length (map (lift_catch Q) xs'))) = Q" by (metis fstI nth_append_length)
then have ?thesis
using LanguageCon.com.distinct(17) LanguageCon.com.distinct(71)
a0 a0' ass last_length map_lift_catch_some_eq[of Q xs Q _ ys xs' Q _ ys']
seq_and_if_not_eq(12) zs
by blast
} thus ?thesis using l ass by auto
qed
lemma Catch_P_Ends_Skip:
assumes
a0:"zs = map (lift_catch Q) xs @ (c, snd (last ((P, s) # xs))) # ys" and
a0':"fst (last ((P,s) # xs)) = c" and an:"c = Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck" and
a1:"catch_cond_nest zs Q xs' P s s'' s' \<Gamma> m"
shows "xs=xs' \<and> (m,\<Gamma>,(c,snd(last ((P,s) # xs)))#ys) \<in> cptn_mod_nest_call"
using a1 unfolding catch_cond_nest_def
proof
assume ass:"zs= map (lift_catch Q) xs'"
then have "map (lift_catch Q) xs' =
map (lift_catch Q) xs @ (c, snd (last ((P, s) # xs))) # ys" using a0 by auto
then have zs_while:"fst (zs!(length (map (lift_catch Q) xs))) = c"
by (metis a0 fstI nth_append_length)
also have "length zs =
length (map (lift_catch Q) xs @ (c, snd (last ((P, s) # xs))) # ys)"
using a0 by auto
then have "(length (map (lift_catch Q) xs)) < length zs" by auto
then show ?thesis using ass zs_while map_lift_catch_all_catch an
by (metis com.distinct(149) com.distinct(173) com.distinct(23))
next
assume ass: "fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \<and>
snd (last ((P, s) # xs')) = s' \<and> s = s'' \<and>
(\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \<or>
(\<exists>c. fst (((P, s) # xs') ! length xs') = c \<and> (c = Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
(\<exists>ys. (m, \<Gamma>, (c, snd (last ((P, s) # xs'))) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys))"
{assume
ass:"\<exists>c. fst (((P, s) # xs') ! length xs') = c \<and> (c = Skip \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
(\<exists>ys. (m, \<Gamma>, (c, snd (last ((P, s) # xs'))) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys)"
then obtain c1 where ass: "fst (((P, s) # xs') ! length xs') = c1 \<and> (c1 = Skip \<or> (\<exists>f. c1 = Fault f) \<or> c1 = Stuck) \<and>
(\<exists>ys. (m, \<Gamma>, (c1, snd (last ((P, s) # xs'))) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (c1, snd (last ((P, s) # xs'))) # ys)"
by auto
then obtain ys' where
zs:"(m, \<Gamma>, (c1, snd (last ((P, s) # xs'))) # ys') \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (c1, snd (last ((P, s) # xs'))) # ys'"
by auto
then have "xs = xs' \<and> ys = ys'" using map_lift_catch_some_eq
by (metis com.distinct(149) com.distinct(173) com.distinct(23) a0 an ass)
then have ?thesis
by (metis a0' ass last_length zs)
}note l = this
{assume ass:"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \<and>
snd (last ((P, s) # xs')) = s' \<and> s = s'' \<and>
(\<exists>ys. (m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)"
then obtain ys' where
zs:"(m, \<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys') \<in> cptn_mod_nest_call \<and>
zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys'"
by auto
then have zs_while:
"fst (zs!(length (map (lift_catch Q) xs'))) = Q"
by (metis fstI nth_append_length)
then have "xs = xs' \<and> ys = ys'"
using map_lift_catch_some_eq a0 zs a0' ass
by (metis com.distinct(149) com.distinct(173) com.distinct(23) an seq_and_if_not_eq(12))
then have ?thesis
using a0 zs by auto
} thus ?thesis using l ass by fast
qed
lemma div_seq_nest:
assumes cptn_m:"(n,\<Gamma>,list) \<in> cptn_mod_nest_call"
shows "(\<forall>s P Q zs. list=(Seq P Q, s)#zs \<longrightarrow>
(\<exists>xs s' s''.
(n,\<Gamma>,(P, s)#xs) \<in> cptn_mod_nest_call \<and>
seq_cond_nest zs Q xs P s s'' s' \<Gamma> n))"
unfolding seq_cond_nest_def
using cptn_m
proof (induct rule: cptn_mod_nest_call.induct)
case (CptnModNestOne \<Gamma> P s)
thus ?case using cptn_mod_nest_call.CptnModNestOne
by blast
next
case (CptnModNestSkip \<Gamma> P s t n xs)
from CptnModNestSkip.hyps
have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Skip, toSeq t)" by auto
from CptnModNestSkip.hyps
have noskip: "~(P=Skip)" using stepc_elim_cases(1)
by auto
have x: "\<forall>c c1 c2. redex c = Seq c1 c2 \<Longrightarrow> False"
using redex_not_Seq by blast
from CptnModNestSkip.hyps
have in_cptn_mod: "(n,\<Gamma>, (Skip, t) # xs) \<in> cptn_mod_nest_call" by auto
then show ?case using CptnModNestSkip.hyps(2) SmallStepCon.redex_not_Seq by blast
next
case (CptnModNestThrow \<Gamma> P s t xs)
from CptnModNestThrow.hyps
have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Throw, toSeq t)" by auto
moreover from CptnModNestThrow.hyps
have no_seq: "\<forall>p1 p2. \<not>(P=Seq p1 p2)" using CptnModNestThrow.hyps(2) redex_not_Seq by auto
ultimately show ?case by auto
next
case (CptnModNestFault \<Gamma> P s f t n xs)
from CptnModNestFault.hyps
have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Fault f, toSeq t)" by auto
moreover from CptnModNestFault.hyps
have no_seq: "\<forall>p1 p2. \<not>(P=Seq p1 p2)" using CptnModNestFault.hyps(2) redex_not_Seq by auto
ultimately show ?case by auto
next
case (CptnModNestStuck \<Gamma> P s t xs)
from CptnModNestStuck.hyps
have step: "\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Stuck, toSeq t)" by auto
moreover from CptnModNestStuck.hyps
have no_seq: "\<forall>p1 p2. \<not>(P=Seq p1 p2)" using CptnModNestStuck.hyps(2) redex_not_Seq by auto
ultimately show ?case by auto
next
case (CptnModNestCondT \<Gamma> P0 s ys b P1)
thus ?case by auto
next
case (CptnModNestCondF \<Gamma> P0 s ys b P1)
thus ?case by auto
next
case (CptnModNestSeq1 n \<Gamma> P0 s xs zs P1) thus ?case
by blast
next
case (CptnModNestSeq2 n \<Gamma> P0 s xs P1 ys zs)
from CptnModNestSeq2.hyps(3) last_length have last:"fst (((P0, s) # xs) ! length xs) = Skip"
by (simp add: last_length)
have P0cptn:"(n,\<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call" by fact
from CptnModNestSeq2.hyps(4)
have P1cptn:"(n,\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call"
by (simp add: last_length)
then have "zs = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys"
by (simp add:CptnModNestSeq2.hyps)
show ?case
by (metis CptnModNestSeq2.hyps(3) CptnModNestSeq2.hyps(4) CptnModNestSeq2.hyps(6)
LanguageCon.com.inject(3) P0cptn fst_conv last_length list.inject snd_conv)
next
case (CptnModNestSeq3 n \<Gamma> P0 s xs t f s' ys zs P1)
from CptnModNestSeq3.hyps(3)
have last:"fst (((P0, s) # xs) ! length xs) = t"
by (simp add: last_length)
have P0cptn:"(n,\<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call" by fact
from CptnModNestSeq3.hyps(5)
have lastnormal:"snd (last ((P0, s) # xs)) = s'"
by (simp add: last_length)
then have "zs = map (lift P1) xs @ ((t, s')#ys)" by (simp add:CptnModNestSeq3.hyps)
show ?case
by (metis CptnModNestSeq3.hyps(3) CptnModNestSeq3.hyps(4) CptnModNestSeq3.hyps(6) CptnModNestSeq3.hyps(8)
LanguageCon.com.inject(3) P0cptn
fst_conv last_length lastnormal list.inject snd_conv)
next
case (CptnModNestEnv \<Gamma> P s t n zs)
then have step:"(n,\<Gamma>, (P, t) # zs) \<in> cptn_mod_nest_call" by auto
have step_e: "\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (P, t)" using CptnModNestEnv by auto
show ?case
proof (cases P)
case (Seq P1 P2)
then have eq_P:"(P, t) # zs = (LanguageCon.com.Seq P1 P2, t) # zs" by auto
then obtain xs t' t'' where
p1:"(n,\<Gamma>, (P1, t) # xs) \<in> cptn_mod_nest_call" and
p2:"(zs = map (lift P2) xs \<or>
fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \<and>
(\<exists>ys. (n,\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<or>
(\<exists>c. fst (((P1, t) # xs) ! length xs) =c \<and> (c = Throw \<or> (\<exists>f. Fault f = c) \<or> c = Stuck) \<and>
snd (last ((P1, t) # xs)) = t' \<and> t = t'' \<and>
(\<exists>ys. (n,\<Gamma>,(c, t')#ys) \<in> cptn_mod_nest_call \<and> zs = map (lift P2) xs @ ((c, t')#ys)))) "
using CptnModNestEnv(3) by fastforce
have all_step:"(n,\<Gamma>, (P1, s)#((P1, t) # xs)) \<in> cptn_mod_nest_call"
using p1 cptn_mod_nest_call.CptnModNestEnv step_e
using env_intro_diff_p by blast
show ?thesis using p2
proof
assume "zs = map (lift P2) xs"
have "(P, t) # zs = map (lift P2) ((P1, t) # xs)"
by (simp add: `zs = map (lift P2) xs` lift_def local.Seq)
thus ?thesis using all_step eq_P by fastforce
next
assume
"fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \<and>
(\<exists>ys. (n,\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<or>
(\<exists>c. fst (((P1, t) # xs) ! length xs) =c \<and> (c = Throw \<or> (\<exists>f. Fault f = c) \<or> c = Stuck) \<and>
snd (last ((P1, t) # xs)) = t' \<and> t = t'' \<and>
(\<exists>ys. (n,\<Gamma>,(c, t')#ys) \<in> cptn_mod_nest_call \<and> zs = map (lift P2) xs @ ((c, t')#ys)))"
then show ?thesis
proof
assume
a1:"fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \<and>
(\<exists>ys. (n,\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys)"
from a1 obtain ys where
p2_exec:"(n,\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and>
zs = map (lift P2) xs @
(P2, snd (((P1, t) # xs) ! length xs)) # ys"
by auto
have f1:"fst (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs)) = LanguageCon.com.Skip"
using a1 by fastforce
then have p2_long_exec:
"(n,\<Gamma>, (P2, snd (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs))) # ys) \<in> cptn_mod_nest_call \<and>
(P, t)#zs = map (lift P2) ((P1, t) # xs) @
(P2, snd (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs))) # ys"
using p2_exec by (simp add: lift_def local.Seq)
thus ?thesis using a1 f1 all_step eq_P by blast
next
assume
a1:"\<exists>c. fst (((P1, t) # xs) ! length xs) =c \<and> (c = Throw \<or> (\<exists>f. Fault f = c) \<or> c = Stuck) \<and>
snd (last ((P1, t) # xs)) = t' \<and> t = t'' \<and>
(\<exists>ys. (n,\<Gamma>,(c, t')#ys) \<in> cptn_mod_nest_call \<and> zs = map (lift P2) xs @ ((c, t')#ys))"
then obtain c where a1:
"fst (((P1, t) # xs) ! length xs) =c \<and> (c = Throw \<or> (\<exists>f. Fault f = c) \<or> c = Stuck) \<and>
snd (last ((P1, t) # xs)) = t' \<and> t = t'' \<and>
(\<exists>ys. (n,\<Gamma>,(c, t')#ys) \<in> cptn_mod_nest_call \<and> zs = map (lift P2) xs @ ((c, t')#ys))"
by auto
then have last_throw:
"fst (((P1, s)#(P1, t) # xs) ! length ((P1, t) #xs)) = c"
by fastforce
from a1 have last_normal: "snd (last ((P1, s)#(P1, t) # xs)) = t'"
by fastforce
have seq_lift:
"(LanguageCon.com.Seq P1 P2, t) # map (lift P2) xs = map (lift P2) ((P1, t) # xs)"
by (simp add: a1 lift_def)
thus ?thesis using a1 last_throw last_normal all_step eq_P
by (clarify, metis (no_types, lifting) append_Cons )
qed
qed
qed (auto)
qed (force)+
lemma exD: assumes a0:"\<exists>x. P x" obtains x where "P x"
using exE[OF a0] by auto
lemma not_func_redex_cptn_mod_nest_n':
assumes
vars:"v = toSeq s" and vars1:"w = toSeq t" and
a0:"\<Gamma>\<turnstile>\<^sub>c (P, v) \<rightarrow> (Q, w)" and
a0':"snd s = snd t" and
a1:"(n,\<Gamma>,(Q,t)#xs) \<in> cptn_mod_nest_call" and
a2:"(\<forall>fn. redex P \<noteq> Call fn) \<or>
(redex P = Call fn \<and> \<Gamma> fn = None) "
shows "(n,\<Gamma>,(P,s)#(Q,t)#xs) \<in> cptn_mod_nest_call"
using a0 a1 a2 a0' vars vars1
proof (induct arbitrary: xs)
case (Basicc f e s1)
thus ?case using stepc.Basicc[of \<Gamma> f e s1]
by (simp add: Basicc cptn_mod_nest_call.CptnModNestSkip)
next
case (Specc s1 t1 r)
thus ?case using stepc.Specc[of s1 t1 r \<Gamma>]
by (simp add: Specc cptn_mod_nest_call.CptnModNestSkip)
next
case (SpecStuckc s1 r)
thus ?case using stepc.SpecStuckc[of s1 _ \<Gamma>]
by (metis LanguageCon.com.distinct(57) SmallStepCon.redex.simps(3) CptnModNestStuck )
next
case (Guardc s1 g f c)
thus ?case
by (metis (mono_tags, lifting) cptn_mod_nest_call.CptnModNestGuard prod_eqI toSeq.simps(1) )
next
case (GuardFaultc s1 g f c)
thus ?case using stepc.GuardFaultc[of s1 g \<Gamma> f]
by (simp add: cptn_mod_nest_call.CptnModNestFault)
next
case (Seqc c1 s1 c1' t1 c2)
have step: "\<Gamma>\<turnstile>\<^sub>c (c1, s1) \<rightarrow> (c1', t1)" by (simp add: Seqc.hyps(1))
then have nsc1: "c1\<noteq>Skip"
by (meson stepc_elim_cases(1))
have assum: "(n, \<Gamma>, (Seq c1' c2, t) # xs) \<in> cptn_mod_nest_call" using Seqc.prems by blast
have divseq:
"(\<forall>s P Q zs. (Seq c1' c2, t) # xs=(Seq P Q, s)#zs \<longrightarrow>
(\<exists>xs sv' sv''.
((n,\<Gamma>,(P, s)#xs) \<in> cptn_mod_nest_call \<and>
(zs=(map (lift Q) xs) \<or>
((fst(((P, s)#xs)!length xs)=Skip \<and>
(\<exists>ys. (n,\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod_nest_call \<and>
zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or>
(\<exists>c. (fst(((P, s)#xs)!length xs)=c \<and> (c = Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
snd(last ((P, s)#xs)) = sv' \<and> t= sv''\<and>
(\<exists>ys. (n,\<Gamma>,(c, sv')#ys) \<in> cptn_mod_nest_call \<and>
zs=(map (lift Q) xs)@((c, sv')#ys)))))) ))"
using div_seq_nest [OF assum] unfolding seq_cond_nest_def by auto
{fix sa P Q zsa
assume ass:"(Seq c1' c2, t) # xs = (Seq P Q, sa) # zsa"
then have eqs:"c1' = P \<and> c2 = Q \<and> t = sa \<and> xs = zsa" by auto
then have
"(\<exists>xs sv' sv''. (n,\<Gamma>, (P, sa) # xs) \<in> cptn_mod_nest_call \<and>
(zsa = map (lift Q) xs \<or>
fst (((P, sa) # xs) ! length xs) = Skip \<and>
(\<exists>ys. (n,\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and>
zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<or>
(\<exists>c. (fst(((P, sa)#xs)!length xs)=c \<and> (c = Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
snd(last ((P, sa)#xs)) = sv' \<and> t= sv''\<and>
(\<exists>ys. (n,\<Gamma>,(c, sv')#ys) \<in> cptn_mod_nest_call \<and> zsa=(map (lift Q) xs)@((c, sv')#ys))))))"
using ass divseq by blast
} note conc=this [of c1' c2 t xs]
then obtain xs' sa' sa'' where
split:"(n,\<Gamma>, (c1',t) # xs') \<in> cptn_mod_nest_call \<and>
(xs = map (lift c2) xs' \<or>
fst (((c1', t) # xs') ! length xs') = Skip \<and>
(\<exists>ys. (n,\<Gamma>, (c2, snd (((c1',t) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or>
(\<exists>c. (fst(((c1', t)#xs')!length xs')=c \<and> (c= Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
snd(last ((c1', t)#xs')) = sa' \<and> t= sa''\<and>
(\<exists>ys. (n,\<Gamma>,(c, sa')#ys) \<in> cptn_mod_nest_call \<and>
xs=(map (lift c2) xs')@((c, sa')#ys)))))"
by blast
then have "xs = map (lift c2) xs' \<or>
fst (((c1', t) # xs') ! length xs') = Skip \<and>
(\<exists>ys. (n,\<Gamma>, (c2, snd (((c1',t) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or>
(\<exists>c. (fst(((c1', t)#xs')!length xs')=c \<and> (c= Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
snd(last ((c1', t)#xs')) = sa' \<and> t= sa''\<and>
(\<exists>ys. (n,\<Gamma>,(c, sa')#ys) \<in> cptn_mod_nest_call \<and>
xs=(map (lift c2) xs')@((c, sa')#ys))))"
by auto
thus ?case
proof{
assume c1'nonf:"xs = map (lift c2) xs'"
then have c1'cptn:"(n,\<Gamma>, (c1', t) # xs') \<in> cptn_mod_nest_call" using split by blast
then have induct_step: "(n,\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod_nest_call"
using Seqc.hyps(2) Seqc.prems(2) Seqc.prems(4) a0'
by (simp add: Seqc.prems(5))
then have "(Seq c1' c2, t)#xs = map (lift c2) ((c1', t)#xs')"
using c1'nonf
by (simp add: lift_def)
thus ?thesis
using c1'nonf c1'cptn induct_step by (auto simp add: CptnModNestSeq1)
next
assume "
fst (((c1', t) # xs') ! length xs') = Skip \<and>
(\<exists>ys. (n,\<Gamma>, (c2, snd (((c1',t) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or>
(\<exists>c. (fst(((c1', t)#xs')!length xs')=c \<and> (c= Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
snd(last ((c1', t)#xs')) = sa' \<and> t= sa''\<and>
(\<exists>ys. (n,\<Gamma>,(c, sa')#ys) \<in> cptn_mod_nest_call \<and>
xs=(map (lift c2) xs')@((c, sa')#ys))))"
thus ?thesis
proof
assume assth:"fst (((c1', t) # xs') ! length xs') = Skip \<and>
(\<exists>ys. (n,\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys)"
then obtain ys
where split':"(n,\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys"
by auto
then have c1'cptn:"(n,\<Gamma>, (c1', t) # xs') \<in> cptn_mod_nest_call" using split by blast
then have induct_step: "(n,\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod_nest_call"
using Seqc.hyps(2) Seqc.prems(2)
by (simp add: Seqc.prems(4) Seqc.prems(5) a0')
then have seqmap:"(Seq c1 c2, s)#(Seq c1' c2, t)#xs =
map (lift c2) ((c1,s)#(c1', t)#xs') @ (c2, snd (((c1', t) # xs') ! length xs')) # ys"
using split' by (simp add: lift_def)
then have lastc1:"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'"
by (simp add: last_length)
then have lastc1skip:"fst (last ((c1, s) # (c1', t) # xs')) = Skip"
using assth by fastforce
thus ?thesis
using seqmap split' cptn_mod_nest_call.CptnModNestSeq2 induct_step lastc1 lastc1skip
by (metis (no_types) Cons_lift_append )
next
assume assm:
"\<exists>c. (fst(((c1', t)#xs')!length xs')=c \<and> (c= Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
snd(last ((c1', t)#xs')) = sa' \<and> t= sa''\<and>
(\<exists>ys. (n,\<Gamma>,(c, sa')#ys) \<in> cptn_mod_nest_call \<and>
xs=(map (lift c2) xs')@((c, sa')#ys)))"
then obtain c where assm:
"(fst(((c1', t)#xs')!length xs')=c \<and> (c= Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
snd(last ((c1', t)#xs')) = sa' \<and> t= sa''\<and>
(\<exists>ys. (n,\<Gamma>,(c, sa')#ys) \<in> cptn_mod_nest_call \<and>
xs=(map (lift c2) xs')@((c, sa')#ys)))"
by auto
then have s'eqsa'': "t= sa''" by auto
then have snormal: "\<exists>ns. s= ns" by auto
then have c1'cptn:"(n,\<Gamma>, (c1', t) # xs') \<in> cptn_mod_nest_call" using split by blast
then have induct_step: "(n,\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod_nest_call"
using Seqc.hyps(2) Seqc.prems(2)
by (simp add: Seqc.prems(4) Seqc.prems(5) a0')
then obtain ys where
seqmap:"(Seq c1' c2, t)#xs =
(map (lift c2) ((c1', t)#xs'))@((c, sa')#ys)"
using assm
using Cons_lift_append by blast
then have lastc1:"last ((c1, s) # (c1',t) # xs') = ((c1', t) # xs') ! length xs'"
by (simp add: last_length)
then have lastc1skip:"fst (last ((c1, s) # (c1', t) # xs')) = c"
using assm by fastforce
then have "snd (last ((c1, s) # (c1', t) # xs')) = sa'"
using assm by force
thus ?thesis
using assm c1'cptn induct_step lastc1skip snormal seqmap s'eqsa''
by (auto simp add:cptn_mod_nest_call.CptnModNestSeq3)
qed
}qed
next
case (SeqSkipc c2 s1 xs)
have c2incptn:"(n,\<Gamma>, (c2, s) # xs) \<in> cptn_mod_nest_call"
using SeqSkipc.prems(1) SeqSkipc.prems(4) SeqSkipc.prems(5) a0' eq_toSeq by blast
moreover have 1:"(n,\<Gamma>, [(Skip, s)]) \<in> cptn_mod_nest_call"
by (simp add: cptn_mod_nest_call.CptnModNestOne)
moreover have 2:"fst(last ([(Skip, s)])) = Skip" by fastforce
moreover have 3:"(n,\<Gamma>,(c2, snd(last [(Skip, s)]))#xs) \<in> cptn_mod_nest_call"
using c2incptn by auto
moreover have "(c2,s)#xs=(map (lift c2) [])@(c2, snd(last [(Skip, s)]))#xs"
by (auto simp add:lift_def)
moreover have "s=t" using eq_toSeq SeqSkipc by blast
ultimately show ?case by (simp add: CptnModNestSeq2)
next
case (SeqThrowc c2 s1 xs)
have eq_st:"s=t" using eq_toSeq[OF SeqThrowc(3)] SeqThrowc by auto
obtain ns where normals:"s= ns" using SeqThrowc by auto
have "(n,\<Gamma>, [(Throw, ns)]) \<in> cptn_mod_nest_call"
by (simp add: cptn_mod_nest_call.CptnModNestOne)
then obtain ys where
ys_nil:"ys=[]" and
last:"(n, \<Gamma>, (Throw, s)#ys)\<in> cptn_mod_nest_call"
using normals
by auto
moreover have "fst (last ((Throw, ns)#ys)) = Throw" using ys_nil last by auto
moreover have "snd (last ((Throw, ns)#ys)) = ns" using ys_nil last by auto
moreover from ys_nil have "(map (lift c2) ys) = []" by auto
ultimately show ?case
using SeqThrowc.prems cptn_mod_nest_call.CptnModNestSeq3 eq_st normals
by (metis append_Nil)
next
case (SeqFaultc f c2 s1 xs)
have eq_st:"s=t" using eq_toSeq[OF SeqFaultc(3)] SeqFaultc by auto
obtain ns where normals:"s= ns" using SeqThrowc by auto
have f:"(n,\<Gamma>, [(Fault f, ns)]) \<in> cptn_mod_nest_call"
by (simp add: cptn_mod_nest_call.CptnModNestOne)
then obtain ys where
ys_nil:"ys=[]" and
last:"(n, \<Gamma>, (Fault f, s)#ys)\<in> cptn_mod_nest_call"
using normals
by auto
moreover have "fst (last ((Fault f, ns)#ys)) = Fault f" using ys_nil last by auto
moreover have "snd (last ((Fault f, ns)#ys)) = ns" using ys_nil last by auto
moreover from ys_nil have "(map (lift c2) ys) = []" by auto
ultimately show ?case
using SeqFaultc.prems cptn_mod_nest_call.CptnModNestSeq3 eq_st normals f
by (metis append_Nil)
next
case (SeqStuckc c2 s1 xs)
have eq_st:"s=t" using eq_toSeq[OF SeqStuckc(3)] SeqStuckc by auto
obtain ns where normals:"s= ns" using SeqThrowc by auto
have f:"(n,\<Gamma>, [(Stuck, ns)]) \<in> cptn_mod_nest_call"
by (simp add: cptn_mod_nest_call.CptnModNestOne)
then obtain ys where
ys_nil:"ys=[]" and
last:"(n, \<Gamma>, (Stuck, s)#ys)\<in> cptn_mod_nest_call"
using normals
by auto
moreover have "fst (last ((Stuck, ns)#ys)) = Stuck" using ys_nil last by auto
moreover have "snd (last ((Stuck, ns)#ys)) = ns" using ys_nil last by auto
moreover from ys_nil have "(map (lift c2) ys) = []" by auto
ultimately show ?case
using SeqStuckc.prems cptn_mod_nest_call.CptnModNestSeq3 eq_st normals f
by (metis append_Nil)
next
case (CondTruec s1 b c1 c2)
moreover obtain ns where normals:"s= ns" by auto
moreover have "s=t"
using calculation(5,6) eq_toSeq[OF calculation(4)] by auto
ultimately show ?case by (simp add: cptn_mod_nest_call.CptnModNestCondT)
next
case (CondFalsec s1 b c1 c2)
moreover obtain ns where normals:"s= ns" by auto
moreover have "s=t"
using calculation(5,6) eq_toSeq[OF calculation(4)] by auto
ultimately show ?case by (simp add: cptn_mod_nest_call.CptnModNestCondF)
next
case (WhileTruec s1 b c)
have sinb: "s1\<in>b" by fact
obtain ns where normals:"s= ns" by auto
have eq_st:"s=t" using eq_toSeq[OF WhileTruec(4)] WhileTruec by blast
have SeqcWhile: "(n,\<Gamma>, (Seq c (While b c), ns) # xs) \<in> cptn_mod_nest_call"
using WhileTruec.prems(1) eq_st normals by force
have divseq:
"(\<forall>s P Q zs. (Seq c (While b c), ns) # xs=(Seq P Q, s)#zs \<longrightarrow>
(\<exists>xs s'. ((n,\<Gamma>,(P, s)#xs) \<in> cptn_mod_nest_call \<and>
(zs=(map (lift Q) xs) \<or>
((fst(((P, s)#xs)!length xs)=Skip \<and>
(\<exists>ys. (n,\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod_nest_call \<and>
zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or>
(\<exists>c. (fst(((P, s)#xs)!length xs)=c \<and> (c = Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
snd(last ((P, s)#xs)) = s' \<and>
(\<exists>ys. (n,\<Gamma>,(c, s')#ys) \<in> cptn_mod_nest_call \<and> zs=(map (lift Q) xs)@((c, s')#ys))))))))"
using div_seq_nest [OF SeqcWhile] eq_st normals
unfolding seq_cond_nest_def by fastforce
{ fix sa P Q zsa
assume ass:"(Seq c (While b c), ns) # xs = (Seq P Q, sa) # zsa"
then have eqs:"c = P \<and> (While b c) = Q \<and> ns = sa \<and> xs = zsa" by auto
then have "(\<exists>xs s'. (n,\<Gamma>, (P, sa) # xs) \<in> cptn_mod_nest_call \<and>
(zsa = map (lift Q) xs \<or>
fst (((P, sa) # xs) ! length xs) = Skip \<and>
(\<exists>ys. (n,\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and>
zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \<or>
(\<exists>c. (fst(((P, sa)#xs)!length xs)=c \<and> (c = Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
snd(last ((P, sa)#xs)) = s' \<and>
(\<exists>ys. (n,\<Gamma>,(c, s')#ys) \<in> cptn_mod_nest_call \<and> zsa=(map (lift Q) xs)@((c, s')#ys))))))"
using ass divseq by auto
} note conc=this [of c "While b c" " ns" xs]
then obtain xs' s' where split:"(n,\<Gamma>, (c, ns) # xs') \<in> cptn_mod_nest_call \<and>
(xs = map (lift (While b c)) xs' \<or>
fst (((c, ns) # xs') ! length xs') = Skip \<and>
(\<exists>ys. (n,\<Gamma>, (While b c, snd (((c, ns) # xs') ! length xs')) # ys)
\<in> cptn_mod_nest_call \<and>
xs = map (lift (While b c)) xs' @
(While b c, snd (((c, ns) # xs') ! length xs')) # ys) \<or>
(\<exists>c1. fst (((c, ns) # xs') ! length xs') = c1 \<and>(c1 = Throw \<or> (\<exists>f. c1 = Fault f) \<or> c1 = Stuck) \<and>
snd (last ((c, ns) # xs')) = s' \<and>
(\<exists>ys. (n,\<Gamma>, ((c1, s')#ys)) \<in> cptn_mod_nest_call \<and>
xs = map (lift (While b c)) xs' @ ((c1, s')#ys))))"
by blast
then have "(xs = map (lift (While b c)) xs' \<or>
fst (((c, ns) # xs') ! length xs') = Skip \<and>
(\<exists>ys. (n,\<Gamma>, (While b c, snd (((c, ns) # xs') ! length xs')) # ys)
\<in> cptn_mod_nest_call \<and>
xs = map (lift (While b c)) xs' @
(While b c, snd (((c, ns) # xs') ! length xs')) # ys) \<or>
(\<exists>c1. fst (((c, ns) # xs') ! length xs') = c1 \<and>(c1 = Throw \<or> (\<exists>f. c1 = Fault f) \<or> c1 = Stuck) \<and>
snd (last ((c, ns) # xs')) = s' \<and>
(\<exists>ys. (n,\<Gamma>, ((c1, s')#ys)) \<in> cptn_mod_nest_call \<and>
xs = map (lift (While b c)) xs' @ ((c1, s')#ys))))" ..
thus ?case
proof{
assume 1:"xs = map (lift (While b c)) xs'"
have 3:"(n, \<Gamma>, (c, ns) # xs') \<in> cptn_mod_nest_call" using split by auto
then show ?thesis
using "1" cptn_mod_nest_call.CptnModNestWhile1 sinb normals eq_st WhileTruec.prems(4)
by fastforce
next
assume "fst (((c, ns) # xs') ! length xs') = Skip \<and>
(\<exists>ys. (n,\<Gamma>, (While b c, snd (((c, ns) # xs') ! length xs')) # ys)
\<in> cptn_mod_nest_call \<and>
xs = map (lift (While b c)) xs' @
(While b c, snd (((c, ns) # xs') ! length xs')) # ys) \<or>
(\<exists>c1. fst (((c, ns) # xs') ! length xs') = c1 \<and>(c1 = Throw \<or> (\<exists>f. c1 = Fault f) \<or> c1 = Stuck) \<and>
snd (last ((c, ns) # xs')) = s' \<and>
(\<exists>ys. (n,\<Gamma>, ((c1, s')#ys)) \<in> cptn_mod_nest_call \<and>
xs = map (lift (While b c)) xs' @ ((c1, s')#ys)))"
thus ?case
proof
assume asm:"fst (((c, ns) # xs') ! length xs') = Skip \<and>
(\<exists>ys. (n,\<Gamma>, (While b c, snd (((c, ns) # xs') ! length xs')) # ys)
\<in> cptn_mod_nest_call \<and>
xs = map (lift (While b c)) xs' @
(While b c, snd (((c, ns) # xs') ! length xs')) # ys)"
then obtain ys where
asm':"(n,\<Gamma>, (While b c, snd (last ((c, ns) # xs'))) # ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift (While b c)) xs' @ (While b c, snd (last ((c, ns) # xs'))) # ys"
by (auto simp add: last_length)
moreover have 3:"(n,\<Gamma>, (c, ns) # xs') \<in> cptn_mod_nest_call" using split by auto
moreover from asm have "fst (last ((c, ns) # xs')) = Skip"
by (simp add: last_length)
ultimately show ?case using sinb normals eq_st WhileTruec.prems(4)
by (auto simp add:CptnModNestWhile2)
next
assume asm:
"(\<exists>c1. fst (((c, ns) # xs') ! length xs') = c1 \<and>(c1 = Throw \<or> (\<exists>f. c1 = Fault f) \<or> c1 = Stuck) \<and>
snd (last ((c, ns) # xs')) = s' \<and>
(\<exists>ys. (n,\<Gamma>, ((c1, s')#ys)) \<in> cptn_mod_nest_call \<and> xs =
map (lift (While b c)) xs' @ ((c1, s')#ys)))"
then obtain c1 where asm:
"fst (((c, ns) # xs') ! length xs') = c1 \<and> (c1 = Throw \<or> (\<exists>f. c1 = Fault f) \<or> c1 = Stuck) \<and>
snd (last ((c, ns) # xs')) = s' \<and>
(\<exists>ys. (n,\<Gamma>, ((c1, s')#ys)) \<in> cptn_mod_nest_call \<and> xs =
map (lift (While b c)) xs' @ ((c1, s')#ys))"
by auto
moreover from asm have h:"fst (last ((c, ns) # xs')) = c1"
by (simp add: last_length)
ultimately show ?case
using sinb normals split eq_st asm WhileTruec.prems(4) CptnModNestWhile3[OF ]
by (auto simp add:CptnModNestWhile3)
qed
}qed
next
case (WhileFalsec s1 b c)
thus ?case using stepc.WhileFalsec[of s1 b \<Gamma> c]
by (simp add: cptn_mod_nest_call.CptnModNestSkip)
next
case (Awaitc s1 b \<Gamma>a c t1)
thus ?case using stepc.Awaitc[of s1 b \<Gamma>a \<Gamma>]
by (simp add: cptn_mod_nest_call.CptnModNestSkip)
next
case (AwaitAbruptc s1 b \<Gamma>a c t1 ta)
thus ?case using stepc.AwaitAbruptc[of s1 b \<Gamma>a \<Gamma> c t1 ta]
by (simp add: cptn_mod_nest_call.CptnModNestThrow)
next
case (AwaitFaultc s1 b \<Gamma>a c f e ta)
thus ?case using stepc.AwaitFaultc
by (simp add: stepc.AwaitFaultc cptn_mod_nest_call.CptnModNestFault)
next
case (AwaitStuckc s1 b \<Gamma>a c e ta)
thus ?case using stepc.AwaitStuckc
by (simp add: stepc.AwaitStuckc cptn_mod_nest_call.CptnModNestStuck)
next
case (Callc p bdy s1)
moreover have eq_st:"s=t" using eq_toSeq[OF Callc(5)] Callc by auto
moreover obtain ns where normals:"s= ns" by auto
ultimately show ?case
by (metis LanguageCon.com.inject(6) SmallStepCon.redex.simps(7) option.distinct(1))
next
case (CallUndefinedc p s1)
then have seq:"\<Gamma>\<turnstile>\<^sub>c( (LanguageCon.com.Call p),toSeq s) \<rightarrow> (Stuck,toSeq t)"
using stepc.CallUndefinedc[of \<Gamma> p s1] by auto
thus ?case
using CallUndefinedc CptnModNestStuck[OF seq _ _ _ CallUndefinedc(2)]
by force
next
case (DynComc c s1)
moreover have eq_st:"s=t"
using calculation(4) calculation(5) eq_toSeq[OF calculation(3)] by force
moreover obtain ns where normals:"s= ns" by auto
moreover have "(n, \<Gamma>, (LanguageCon.com.DynCom c, ns) #
(c (fst ns), ns) # xs) \<in> cptn_mod_nest_call"
using DynComc.prems(1) DynComc.prems(4)
cptn_mod_nest_call.CptnModNestDynCom eq_st normals by fastforce
then show ?case
using DynComc.prems(4) eq_st normals by fastforce
next (* (\<forall>s P Q zs. (Catch c1' c2, t) # xs=(Catch P Q, s)#zs \<longrightarrow>
(\<exists>xs s' s''. ((n,\<Gamma>,(P, s)#xs) \<in> cptn_mod_nest_call \<and>
(zs=(map (lift_catch Q) xs) \<or>
((fst(((P, s)#xs)!length xs)=Throw \<and>
snd(last ((P, s)#xs)) = Normal s' \<and> s=Normal s''\<and>
(\<exists>ys. (n,\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \<in> cptn_mod_nest_call \<and>
zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \<or>
((fst(((P, s)#xs)!length xs)=Skip \<and>
(\<exists>ys. (n,\<Gamma>,(Skip,snd(last ((P, s)#xs)))#ys) \<in> cptn_mod_nest_call \<and>
zs=(map (lift_catch Q) xs)@((Skip,snd(last ((P, s)#xs)))#ys))
))))
)) *)
case (Catchc c1 s1 c1' t1 c2 xs)
have step: "\<Gamma>\<turnstile>\<^sub>c (c1, s1) \<rightarrow> (c1', t1)" by (simp add: Catchc.hyps(1))
then have nsc1: "c1\<noteq>Skip" using stepc_elim_cases(1) by fastforce
have assum: "(n,\<Gamma>, (Catch c1' c2, t) # xs) \<in> cptn_mod_nest_call"
using Catchc.prems by blast
note div = div_catch_nest[OF assum, simplified catch_cond_nest_def]
{ fix sa P Q zsa
assume ass:"(Catch c1' c2,t) # xs = (Catch P Q, sa) # zsa"
then have eqs:"c1' = P \<and> c2 = Q \<and> t = sa \<and> xs = zsa" by auto
note univ = spec[OF spec[OF spec[OF spec[OF div, of sa], of P ], of Q], of zsa]
note cond = mp[OF univ ass]
} note conc=this [of c1' c2 t xs]
have ass:"(LanguageCon.com.Catch c1' c2, t) # xs = (LanguageCon.com.Catch c1' c2, t) # xs"
by auto
note body =conc[OF ass]
then obtain xs' sa' sa''
where split:
"(n, \<Gamma>, (c1', t) # xs') \<in> cptn_mod_nest_call \<and>
(xs = map (lift_catch c2) xs' \<or>
fst (((c1', t) # xs') ! length xs') = LanguageCon.com.Throw \<and>
snd (last ((c1', t) # xs')) = sa' \<and>
t = sa'' \<and>
(\<exists>ys. (n, \<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys)
\<in> cptn_mod_nest_call \<and>
xs = map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or>
(\<exists>ta. fst (((c1', t) # xs') ! length xs') = ta \<and>
(ta = LanguageCon.com.Skip \<or> (\<exists>f. ta = com.Fault f) \<or> ta = com.Stuck) \<and>
(\<exists>ys. (n, \<Gamma>, (ta, snd (last ((c1', t) # xs'))) # ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift_catch c2) xs' @ (ta, snd (last ((c1', t) # xs'))) # ys)))"
by blast
note c1 = conjunct2[OF this]
thus ?case
proof{
assume c1'nonf:"xs = map (lift_catch c2) xs'"
then have c1'cptn:"(n,\<Gamma>, (c1', t) # xs') \<in> cptn_mod_nest_call" using split by blast
then have induct_step: "(n, \<Gamma>, (c1, s) # (c1',t)#xs') \<in> cptn_mod_nest_call"
using Catchc.hyps(2) Catchc.prems(2)
by (simp add: Catchc.prems(4) Catchc.prems(5) a0')
then have "(Catch c1' c2, t)#xs = map (lift_catch c2) ((c1', t)#xs')"
using c1'nonf
by (simp add: CptnModCatch1 lift_catch_def)
thus ?thesis
using c1'nonf c1'cptn induct_step
by (auto simp add: CptnModNestCatch1)
next
assume "fst (((c1', t) # xs') ! length xs') = LanguageCon.com.Throw \<and>
snd (last ((c1', t) # xs')) = sa' \<and> t = sa'' \<and>
(\<exists>ys. (n, \<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<or>
(\<exists>ta. fst (((c1', t) # xs') ! length xs') = ta \<and>
(ta = LanguageCon.com.Skip \<or> (\<exists>f. ta = com.Fault f) \<or> ta = com.Stuck) \<and>
(\<exists>ys. (n, \<Gamma>, (ta, snd (last ((c1', t) # xs'))) # ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift_catch c2) xs' @ (ta, snd (last ((c1', t) # xs'))) # ys))"
thus ?thesis
proof
assume assth:
"fst (((c1', t) # xs') ! length xs') = LanguageCon.com.Throw \<and>
snd (last ((c1', t) # xs')) = sa' \<and> t = sa'' \<and>
(\<exists>ys. (n, \<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys)"
then have s'eqsa'': "t= sa''" by auto
then have snormal: "\<exists>ns. s= ns"
using Catchc.prems(4) Catchc.prems(5) a0' c_step local.step by blast
then obtain ys
where split':"(n,\<Gamma>, (c2, snd (((c1',t) # xs') ! length xs')) # ys) \<in> cptn_mod_nest_call \<and>
xs =map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys"
using assth by auto
then have c1'cptn:"(n,\<Gamma>, (c1', t) # xs') \<in> cptn_mod_nest_call"
using split by blast
then have induct_step: "(n,\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod_nest_call"
using Catchc.hyps(2) Catchc.prems(2) SmallStepCon.redex.simps(11)
by (simp add: Catchc.prems(4) Catchc.prems(5) a0')
then have seqmap:"(Catch c1 c2, s)#(Catch c1' c2, t)#xs =
map (lift_catch c2) ((c1,s)#(c1', t)#xs') @
(c2, snd (((c1', t) # xs') ! length xs')) # ys"
using split' by (simp add: CptnModCatch3 lift_catch_def)
then have lastc1:"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'"
by (simp add: last_length)
then have lastc1skip:"fst (last ((c1, s) # (c1', t) # xs')) = Throw"
using assth by fastforce
then have "snd (last ((c1, s) # (c1', t) # xs')) = sa'"
using assth by fastforce
thus ?thesis using snormal seqmap s'eqsa'' split'
cptn_mod_nest_call.CptnModNestCatch3
induct_step lastc1 lastc1skip
using Cons_lift_catch_append
by (metis)
next
assume assm:"(\<exists>ta. fst (((c1', t) # xs') ! length xs') = ta \<and>
(ta = LanguageCon.com.Skip \<or> (\<exists>f. ta = com.Fault f) \<or> ta = com.Stuck) \<and>
(\<exists>ys. (n, \<Gamma>, (ta, snd (last ((c1', t) # xs'))) # ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift_catch c2) xs' @ (ta, snd (last ((c1', t) # xs'))) # ys))"
then obtain c where assm:"fst (((c1', t) # xs') ! length xs') = c \<and>
(c = LanguageCon.com.Skip \<or> (\<exists>f. c = com.Fault f) \<or> c = com.Stuck) \<and>
(\<exists>ys. (n, \<Gamma>, (c, snd (last ((c1', t) # xs'))) # ys) \<in> cptn_mod_nest_call \<and>
xs = map (lift_catch c2) xs' @ (c, snd (last ((c1', t) # xs'))) # ys)"
by auto
then have c1'cptn:"(n,\<Gamma>, (c1', t) # xs') \<in> cptn_mod_nest_call"
using split by blast
then have induct_step: "(n,\<Gamma>, (c1, s) # (c1', t)#xs') \<in> cptn_mod_nest_call"
using Catchc.hyps(2) Catchc.prems(2) SmallStepCon.redex.simps(11)
by (simp add: Catchc.prems(4) Catchc.prems(5) a0')
then have "map (lift_catch c2) ((c1', t) # xs') = (Catch c1' c2, t) # map (lift_catch c2) xs'"
by (auto simp add: lift_catch_def)
then obtain ys
where seqmap:"(Catch c1' c2, t)#xs = (map (lift_catch c2) ((c1', t)#xs'))@((c,snd(last ((c1', t)#xs')))#ys)"
using assm by fastforce
then have lastc1:"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'"
by (simp add: last_length)
then have lastc1skip:"fst (last ((c1, s) # (c1', t) # xs')) = c"
using assm by fastforce
then have "snd (last ((c1, s) # (c1', t) # xs')) = snd (last ((c1', t) # xs'))"
using assm by force
then obtain f where c:"(c = LanguageCon.com.Skip \<or> (c = com.Fault f) \<or> c = com.Stuck)" using assm by auto
thus ?thesis
using assm c1'cptn induct_step lastc1skip seqmap
cptn_mod_nest_call.CptnModNestCatch2[OF induct_step lastc1skip c]
by auto
qed
}qed
next
case (CatchThrowc c2 s1)
then obtain ns where ns:"s = ns" by auto
then have eq_st: "s=t" using eq_toSeq[OF CatchThrowc(3)] CatchThrowc(4,5) by auto
have c2incptn:"(n,\<Gamma>, (c2, ns) # xs) \<in> cptn_mod_nest_call"
using CatchThrowc.prems(1) eq_st ns by fastforce
have 1:"(n,\<Gamma>, [(Throw, ns)]) \<in> cptn_mod_nest_call"
by (simp add: cptn_mod_nest_call.CptnModNestOne)
have 2:"fst(last ([(Throw, ns)])) = Throw" by fastforce
have 3:"(n,\<Gamma>,(c2, snd(last [(Throw, ns)]))#xs) \<in> cptn_mod_nest_call"
using c2incptn by auto
moreover have "(c2, ns)#xs=
(map (lift c2) [])@(c2, snd(last [(Throw, ns)]))#xs"
by (auto simp add:lift_def)
ultimately show ?case using eq_st ns CptnModNestCatch3[OF 1 2] by fastforce
next
case (CatchSkipc c2 s1)
have "(n,\<Gamma>, [(Skip, s)]) \<in> cptn_mod_nest_call"
by (simp add: cptn_mod_nest_call.CptnModNestOne)
then obtain ys where
ys_nil:"ys=[]" and
last:"(n,\<Gamma>, (Skip, s)#ys)\<in> cptn_mod_nest_call"
by auto
moreover have "fst (last ((Skip, s)#ys)) = Skip" using ys_nil last by auto
moreover have "snd (last ((Skip, s)#ys)) = s" using ys_nil last by auto
moreover from ys_nil have "(map (lift_catch c2) ys) = []" by auto
moreover have "s=t"
using CatchSkipc.prems(4) CatchSkipc.prems(5) a0' eq_toSeq by blast
ultimately show ?case using CatchSkipc.prems
by simp (simp add: cptn_mod_nest_call.CptnModNestCatch2 ys_nil)
next
case (CatchFaultc f c2 s1)
have "(n,\<Gamma>, [(Fault f, s)]) \<in> cptn_mod_nest_call"
by (simp add: cptn_mod_nest_call.CptnModNestOne)
then obtain ys where
ys_nil:"ys=[]" and
last:"(n,\<Gamma>, (Fault f, s)#ys)\<in> cptn_mod_nest_call"
by auto
moreover have "fst (last ((Fault f, s)#ys)) = Fault f" using ys_nil last by auto
moreover have "snd (last ((Fault f, s)#ys)) = s" using ys_nil last by auto
moreover from ys_nil have "(map (lift_catch c2) ys) = []" by auto
moreover have "s=t"
using CatchFaultc.prems(4) CatchFaultc.prems(5) a0' eq_toSeq by blast
ultimately show ?case using CatchFaultc.prems
by simp (simp add: cptn_mod_nest_call.CptnModNestCatch2 ys_nil)
next
case (CatchStuckc c2 s1)
have "(n,\<Gamma>, [(Stuck, s)]) \<in> cptn_mod_nest_call"
by (simp add: cptn_mod_nest_call.CptnModNestOne)
then obtain ys where
ys_nil:"ys=[]" and
last:"(n,\<Gamma>, (Stuck, s)#ys)\<in> cptn_mod_nest_call"
by auto
moreover have "fst (last ((Stuck, s)#ys)) = Stuck" using ys_nil last by auto
moreover have "snd (last ((Stuck, s)#ys)) = s" using ys_nil last by auto
moreover from ys_nil have "(map (lift_catch c2) ys) = []" by auto
moreover have "s=t"
using CatchStuckc.prems(4) CatchStuckc.prems(5) a0' eq_toSeq by blast
ultimately show ?case using CatchStuckc.prems
by simp (simp add: cptn_mod_nest_call.CptnModNestCatch2 ys_nil)
qed
lemma not_func_redex_cptn_mod_nest_n_env:
assumes a0:"\<Gamma>\<turnstile>\<^sub>c (P,s) \<rightarrow>\<^sub>e (P, t)" and
a1:"(n,\<Gamma>,(P,t)#xs) \<in> cptn_mod_nest_call"
shows "(n,\<Gamma>,(P,s)#(P,t)#xs) \<in> cptn_mod_nest_call"
by (simp add: a0 a1 cptn_mod_nest_call.CptnModNestEnv)
lemma cptn_mod_nest_cptn_mod:"(n,\<Gamma>,cfs) \<in> cptn_mod_nest_call \<Longrightarrow> (\<Gamma>,cfs)\<in> cptn_mod"
by (induct rule:cptn_mod_nest_call.induct, (auto simp:cptn_mod.intros )+)
lemma cptn_mod_cptn_mod_nest: "(\<Gamma>,cfs)\<in> cptn_mod \<Longrightarrow> \<exists>n. (n,\<Gamma>,cfs) \<in> cptn_mod_nest_call"
proof (induct rule:cptn_mod.induct)
case (CptnModSkip \<Gamma> P s t xs)
then obtain n where cptn_nest:"(n, \<Gamma>, (Skip, t) # xs) \<in> cptn_mod_nest_call" by auto
{assume asm:"\<forall>f. ((\<exists>sn. s = sn) \<and> (\<Gamma> f) = Some Skip \<longrightarrow> P \<noteq> Call f )"
then have ?case
by (meson CptnModSkip.hyps(1) CptnModSkip.hyps(2) CptnModSkip.hyps(3)
cptn_nest cptn_mod_nest_callp.CptnModNestSkip
cptn_mod_nest_callp_cptn_mod_nest_call_eq)
}note t1=this
{assume asm:"\<not> (\<forall>f. ((\<exists>sn. s = sn) \<and> (\<Gamma> f) = Some Skip \<longrightarrow> P \<noteq> Call f))"
then obtain f where asm:"((\<exists>sn. s = sn) \<and> (\<Gamma> f) = Some Skip \<and> P = Call f)" by auto
then obtain sn where normal_s:"s= sn" by auto
then have t_eq_s:"t=s"
using asm cptn_nest normal_s call_f_step_not_s_eq_t_false[OF CptnModSkip(1)]
eq_toSeq[OF CptnModSkip.hyps(3)] CptnModSkip.hyps(2) toSeq.simps(1)
by blast
then have "(Suc n, \<Gamma>,((Call f), sn)#(Skip, sn)#xs) \<in> cptn_mod_nest_call"
using asm cptn_nest normal_s CptnModNestCall by fastforce
then have ?case using asm normal_s t_eq_s by fastforce
}note t2 = this
then show ?case using t1 t2 by fastforce
next
case (CptnModThrow \<Gamma> P s t xs)
then obtain n where cptn_nest:"(n, \<Gamma>, (Throw, t) # xs) \<in> cptn_mod_nest_call" by auto
{assume asm:"\<forall>f. ((\<exists>sn. s = sn) \<and> (\<Gamma> f) = Some Throw \<longrightarrow> P \<noteq> Call f )"
then have ?case
using CptnModNestThrow[OF CptnModThrow(1) CptnModThrow(2) ] asm CptnModThrow(3)
using cptn_nest by blast
}note t1=this
{ assume asm:"\<not> (\<forall>f. ((\<exists>sn. s = sn) \<and> (\<Gamma> f) = Some Throw \<longrightarrow> P \<noteq> Call f))"
then obtain f where asm:"((\<exists>sn. s = sn) \<and> (\<Gamma> f) = Some Throw \<and> P = Call f)" by auto
then obtain sn where normal_s:"s= sn" by auto
then have t_eq_s:"t=s"
using asm cptn_nest normal_s eq_toSeq[OF CptnModThrow.hyps(3)]
CptnModThrow.hyps(1)
call_f_step_not_s_eq_t_false[OF CptnModThrow.hyps(1)]
by fastforce
then have "(Suc n, \<Gamma>,((Call f), sn)#(Throw, sn)#xs) \<in> cptn_mod_nest_call"
using asm cptn_nest normal_s CptnModNestCall by fastforce
then have ?case using asm normal_s t_eq_s by fastforce
}note t2 = this
then show ?case using t1 t2 by fastforce
next
case (CptnModFault \<Gamma> P s f1 t xs)
then obtain n where cptn_nest:"(n, \<Gamma>, (Fault f1, t) # xs) \<in> cptn_mod_nest_call" by auto
{assume asm:"\<forall>f. ((\<exists>sn. s = sn) \<and> (\<Gamma> f) = Some (Fault f1) \<longrightarrow> P \<noteq> Call f )"
then have ?case
using CptnModNestFault[OF CptnModFault(1) CptnModFault(2) ] asm CptnModFault(3)
using cptn_nest by blast
}note t1=this
{ assume asm:"\<not> (\<forall>f. ((\<exists>sn. s = sn) \<and> (\<Gamma> f) = Some (Fault f1) \<longrightarrow> P \<noteq> Call f))"
then obtain f where asm:"((\<exists>sn. s = sn) \<and> (\<Gamma> f) = Some (Fault f1) \<and> P = Call f)" by auto
then obtain sn where normal_s:"s= sn" by auto
then have t_eq_s:"t=s"
using asm cptn_nest normal_s eq_toSeq[OF CptnModFault.hyps(3)]
CptnModFault.hyps(1)
call_f_step_not_s_eq_t_false[OF CptnModFault.hyps(1)]
by fastforce
then have "(Suc n, \<Gamma>,((Call f), sn)#(Fault f1, sn)#xs) \<in> cptn_mod_nest_call"
using asm cptn_nest normal_s CptnModNestCall by fastforce
then have ?case using asm normal_s t_eq_s by fastforce
}note t2 = this
then show ?case using t1 t2 by fastforce
next
case (CptnModStuck \<Gamma> P s t xs)
then obtain n where cptn_nest:"(n, \<Gamma>, (Stuck, t) # xs) \<in> cptn_mod_nest_call" by auto
{assume asm:"\<forall>f. ((\<exists>sn. s = sn) \<and> (\<Gamma> f) = Some Stuck \<longrightarrow> P \<noteq> Call f )"
then have ?case
using CptnModNestStuck[OF CptnModStuck(1) CptnModStuck(2) ] asm CptnModStuck(3)
using cptn_nest by blast
}note t1=this
{ assume asm:"\<not> (\<forall>f. ((\<exists>sn. s = sn) \<and> (\<Gamma> f) = Some Stuck \<longrightarrow> P \<noteq> Call f))"
then obtain f where asm:"((\<exists>sn. s = sn) \<and> (\<Gamma> f) = Some Stuck \<and> P = Call f)" by auto
then obtain sn where normal_s:"s= sn" by auto
then have t_eq_s:"t=s"
using asm cptn_nest normal_s eq_toSeq[OF CptnModStuck.hyps(3)]
CptnModStuck.hyps(1)
call_f_step_not_s_eq_t_false[OF CptnModStuck.hyps(1)]
by fastforce
then have "(Suc n, \<Gamma>,((Call f), sn)#(Stuck, sn)#xs) \<in> cptn_mod_nest_call"
using asm cptn_nest normal_s CptnModNestCall by fastforce
then have ?case using asm normal_s t_eq_s by fastforce
}note t2 = this
then show ?case using t1 t2 by fastforce
next
case (CptnModSeq2 \<Gamma> P0 s xs P1 ys zs)
obtain n where n:"(n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call" using CptnModSeq2(2) by auto
also obtain m where m:"(m, \<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call"
using CptnModSeq2(5) by auto
ultimately show ?case
proof (cases "n\<ge>m")
case True thus ?thesis
using cptn_mod_nest_mono[of m \<Gamma> _ n] m n CptnModSeq2 cptn_mod_nest_call.CptnModNestSeq2 by blast
next
case False
thus ?thesis
using cptn_mod_nest_mono[of n \<Gamma> _ m] m n CptnModSeq2
cptn_mod_nest_call.CptnModNestSeq2 le_cases3 by blast
qed
next
case (CptnModSeq3 \<Gamma> P0 s xs t f s' ys zs P1)
obtain n where n:"(n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call" using CptnModSeq3(2) by auto
also obtain m where m:"(m, \<Gamma>, (t, s') # ys) \<in> cptn_mod_nest_call"
using CptnModSeq3.hyps(7) by blast
ultimately show ?case
proof (cases "n\<ge>m")
case True thus ?thesis
using cptn_mod_nest_mono[of m \<Gamma> _ n] m n CptnModSeq3 cptn_mod_nest_call.CptnModNestSeq3
by fast
next
case False
thus ?thesis
using cptn_mod_nest_mono[of n \<Gamma> _ m] m n CptnModSeq3
cptn_mod_nest_call.CptnModNestSeq3 le_cases3
by (smt cptn_mod_nest_mono)
qed
next
case (CptnModWhile2 \<Gamma> P s xs b zs ys)
obtain n where n:"(n, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call" using CptnModWhile2(2) by auto
also obtain m where
m:" (m, \<Gamma>, (LanguageCon.com.While b P, snd (last ((P, s) # xs))) # ys) \<in>
cptn_mod_nest_call"
using CptnModWhile2(7) by auto
ultimately show ?case
proof (cases "n\<ge>m")
case True thus ?thesis
using cptn_mod_nest_mono[of m \<Gamma> _ n] m n
CptnModWhile2 cptn_mod_nest_call.CptnModNestWhile2 by metis
next
case False
thus ?thesis
proof -
have f1: "\<not> n \<le> m \<or> (m, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call"
using cptn_mod_nest_mono[of n \<Gamma> _ m] n by presburger
have "n \<le> m"
using False by linarith
then have "(m, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call"
using f1 by metis
then show ?thesis
by (metis (no_types) CptnModWhile2(3) CptnModWhile2(4) CptnModWhile2(5)
cptn_mod_nest_call.CptnModNestWhile2 m)
qed
qed
next
case (CptnModWhile3 \<Gamma> P s xs t f b s' ys zs)
obtain n where n:"(n, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call"
using CptnModWhile3(2) by auto
also obtain m where
m:" (m, \<Gamma>, (t, s') # ys) \<in> cptn_mod_nest_call"
using CptnModWhile3(8) by auto
ultimately show ?case
proof (cases "n\<ge>m")
case True thus ?thesis
proof -
have "(n, \<Gamma>, (t, s') # ys) \<in> cptn_mod_nest_call"
using True cptn_mod_nest_mono[of m \<Gamma> _ n] m by presburger
then show ?thesis
by (metis (no_types) local.CptnModWhile3(3) local.CptnModWhile3(4)
local.CptnModWhile3(6) local.CptnModWhile3(9)
CptnModWhile3.hyps(5) cptn_mod_nest_call.CptnModNestWhile3 n)
qed
next
case False
thus ?thesis
using m n cptn_mod_nest_call.CptnModNestWhile3[OF n] cptn_mod_nest_mono[of n \<Gamma> _ m]
by (smt CptnModWhile3.hyps(3) CptnModWhile3.hyps(4) CptnModWhile3.hyps(5)
CptnModWhile3.hyps(6) CptnModWhile3.hyps(9) cptn_mod_nest_call.CptnModNestWhile3 le_cases3)
qed
next
case (CptnModCatch2 \<Gamma> P0 s xs t f ys zs P1)
obtain n where n:"(n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call"
using CptnModCatch2(2) by auto
also obtain m where m:"(m, \<Gamma>, (t, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call"
using CptnModCatch2(6) by auto
ultimately show ?case
proof (cases "n\<ge>m")
case True thus ?thesis
using cptn_mod_nest_mono[of m \<Gamma> _ n] m n
CptnModCatch2 cptn_mod_nest_call.CptnModNestCatch2 by fast
next
case False
then have "n\<le>m" by auto
thus ?thesis
using False cptn_mod_nest_mono[OF n] m n CptnModCatch2
CptnModNestCatch2[OF _ CptnModCatch2(3)]
by blast
qed
next
case (CptnModCatch3 \<Gamma> P0 s xs s' ys zs P1)
obtain n where n:"(n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call"
using CptnModCatch3(2) by auto
also obtain m where m:"(m, \<Gamma>, (ys, snd (last ((P0, s) # xs))) # zs) \<in> cptn_mod_nest_call"
using CptnModCatch3(6) by auto
ultimately show ?case
proof (cases "n\<ge>m")
case True thus ?thesis
using cptn_mod_nest_mono[of m \<Gamma> _ n] m n CptnModCatch3 cptn_mod_nest_call.CptnModNestCatch3
by blast
next
case False
have f1: "\<not> n \<le> m \<or> (m, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call"
using cptn_mod_nest_mono[of n \<Gamma> _ m] n by presburger
have "n \<le> m"
using False by auto
then have "(m, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call"
using f1 by meson
then show ?thesis
by (metis (no_types) CptnModCatch3(3,4,7) cptn_mod_nest_call.CptnModNestCatch3 m)
qed
qed(fastforce intro: cptn_mod_nest_call.intros)+
lemma cptn_mod_same_n:
assumes a0:"(\<Gamma>,cfs)\<in> cptn_mod"
shows "\<exists>n. (n,\<Gamma>,cfs) \<in> cptn_mod_nest_call"
proof -
show ?thesis using cptn_mod_cptn_mod_nest
by (metis a0 )
qed
lemma cptn_mod_same_n1:
assumes a0:"(\<Gamma>,cfs)\<in> cptn_mod" and
a1:"(\<Gamma>,cfs1)\<in> cptn_mod"
shows "\<exists>n. (n,\<Gamma>,cfs) \<in> cptn_mod_nest_call \<and> (n,\<Gamma>,cfs1) \<in> cptn_mod_nest_call"
proof -
show ?thesis using cptn_mod_nest_mono cptn_mod_cptn_mod_nest
by (metis a0 a1 cptn_mod_nest_mono2 leI)
qed
lemma cptn_mod_eq_cptn_mod_nest:
"(\<Gamma>,cfs)\<in> cptn_mod \<longleftrightarrow> (\<exists>n. (n,\<Gamma>,cfs) \<in> cptn_mod_nest_call)"
using cptn_mod_cptn_mod_nest cptn_mod_nest_cptn_mod by auto
lemma cptn_mod_eq_cptn_mod_nest':
"\<exists>n. ((\<Gamma>,cfs)\<in> cptn_mod \<longleftrightarrow> (n,\<Gamma>,cfs) \<in> cptn_mod_nest_call)"
using cptn_mod_eq_cptn_mod_nest by auto
lemma cptn_mod_eq_cptn_mod_nest1:
"(\<Gamma>,cfs)\<in> cptn_mod = (\<exists>n. (n,\<Gamma>,cfs) \<in> cptn_mod_nest_call)"
using cptn_mod_cptn_mod_nest cptn_mod_nest_cptn_mod by auto
lemma cptn_eq_cptn_mod_nest:
"(\<Gamma>,cfs)\<in> cptn = (\<exists>n. (n,\<Gamma>,cfs) \<in> cptn_mod_nest_call)"
using cptn_eq_cptn_mod_set cptn_mod_cptn_mod_nest cptn_mod_nest_cptn_mod by blast
subsection \<open>computation on nested calls limit\<close>
subsection \<open>Elimination theorems\<close>
lemma elim_cptn_mod_nest_step_c:
assumes a0:"(n,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and
a1:"cfg = (P,s)#(Q,t)#cfg1"
shows "\<Gamma>\<turnstile>\<^sub>c (P,toSeq s) \<rightarrow> (Q,toSeq t) \<or> \<Gamma>\<turnstile>\<^sub>c (P,s) \<rightarrow>\<^sub>e (Q,t)"
proof-
have "(\<Gamma>,cfg) \<in> cptn" using a0 cptn_mod_nest_cptn_mod
using cptn_eq_cptn_mod_set by auto
then have "\<Gamma>\<turnstile>\<^sub>c (P,s) \<rightarrow>\<^sub>c\<^sub>e (Q,t)" using a1
by (metis cptn_elim_cases(2))
thus ?thesis
using step_ce_not_step_e_step_c by blast
qed
lemma elim_cptn_mod_nest_call_env:
assumes a0:"(n,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and
a1:"cfg = (P,s)#(P,t)#cfg1" and
a2:"\<forall>f. \<Gamma> f = Some (LanguageCon.com.Call f) \<and>
s = t \<longrightarrow> SmallStepCon.redex P \<noteq> LanguageCon.com.Call f"
shows "(n,\<Gamma>,(P,t)#cfg1) \<in> cptn_mod_nest_call"
using a0 a1 a2
proof (induct arbitrary: P cfg1 s t rule:cptn_mod_nest_call.induct )
case (CptnModNestSeq1 n \<Gamma> P0 sa xs zs P1)
then obtain xs' where "xs = (P0, t)#xs'" unfolding lift_def by fastforce
then have step:"(n, \<Gamma>, (P0, t) # xs') \<in> cptn_mod_nest_call" using CptnModNestSeq1
apply auto
using CptnModNestSeq1.hyps(2) by blast
have "(P, t) = lift P1 (P0, t) \<and> cfg1 = map (lift P1) xs'"
using CptnModNestSeq1.hyps(3) CptnModNestSeq1.prems(1) \<open>xs = (P0, t) # xs'\<close> by auto
then have "(n, \<Gamma>, (LanguageCon.com.Seq P0 P1, t) # cfg1) \<in> cptn_mod_nest_call"
by (meson cptn_mod_nest_call.CptnModNestSeq1 local.step)
then show ?case
using CptnModNestSeq1.prems(1) by fastforce
next
case (CptnModNestSeq2 n \<Gamma> P0 sa xs P1 ys zs)
thus ?case
proof (induct xs)
case Nil thus ?case using Nil.prems(6) Nil.prems(7) by fastforce
next
case (Cons x xs')
have x:"x=(P0,t) \<and> s=sa \<and> P = Seq P0 P1"
proof-
have "zs=(Seq P0 P1,t)#cfg1" using Cons by fastforce
thus ?thesis using Cons(7) unfolding lift_def
proof -
assume "zs = map (\<lambda>a. case a of (P, s) \<Rightarrow> (LanguageCon.com.Seq P P1, s)) (x # xs') @
(P1, snd (last ((P0, sa) # x # xs'))) # ys"
then have "LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0 P1 \<and> snd x = t"
by (simp add: \<open>zs = (LanguageCon.com.Seq P0 P1, t) # cfg1\<close> case_prod_beta)
then show ?thesis using CptnModNestSeq2.prems(1)
by fastforce
qed
qed
then have step:"(n, \<Gamma>, (P0, t) # xs') \<in> cptn_mod_nest_call" using Cons x by auto
have "fst (last ((P0, t) # xs')) = LanguageCon.com.Skip"
using Cons.prems(3) x by force
then show ?case
using Cons.prems(4) Cons.prems(6) CptnModNestSeq2.prems(1) x
cptn_mod_nest_call.CptnModNestSeq2[OF step] by fastforce
qed
next
case (CptnModNestSeq3 n \<Gamma> P0 sa xs ta f s' ys zs P1)
thus ?case
proof (induct xs)
case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force
next
case (Cons x xs')
then have x:"x=(P0,t)"
proof-
have zs:"zs=(Seq P0 P1,t)#cfg1" using Cons by fastforce
have "(LanguageCon.com.Seq (fst x) P1, snd x) = lift P1 x"
by (simp add: lift_def prod.case_eq_if)
then have "LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0 P1 \<and> snd x = t"
using Cons.prems(8) zs by fastforce
then show ?thesis
by fastforce
qed
have s:"s=sa" using CptnModNestSeq3.prems(1) by auto
have P:"P= Seq P0 P1" using CptnModNestSeq3.prems(1) by auto
then have step:"(n, \<Gamma>, (P0, t) # xs') \<in> cptn_mod_nest_call" using Cons x s P by auto
then obtain t' where t:"t= t'" by auto
then show ?case using x Cons(5) Cons(6) cptn_mod_nest_call.CptnModNestSeq3 step
proof -
have "last ((P0, t') # xs') = last ((P0, sa) # x # xs')"
using t x by force
then have h:"fst (last ((P0, t') # xs')) = ta"
using Cons.prems(3) by presburger
show ?thesis
using Cons.prems(4) Cons.prems(5) Cons.prems(7)
CptnModNestSeq3.prems(1) Cons.prems(6) Cons.prems(8)
cptn_mod_nest_call.CptnModNestSeq3[OF local.step[simplified t] h]
t x s P
by fastforce
qed
qed
next
case (CptnModNestCatch1 n \<Gamma> P0 s xs zs P1)
then obtain xs' where "xs = (P0, t)#xs' " unfolding lift_catch_def by fastforce
then have step:"(n, \<Gamma>, (P0, t) # xs') \<in> cptn_mod_nest_call" using CptnModNestCatch1
by (metis SmallStepCon.redex.simps(11) fst_conv nth_Cons_0 snd_conv)
have "(P, t) = lift_catch P1 (P0, t) \<and> cfg1 = map (lift_catch P1) xs'"
using CptnModNestCatch1.hyps(3) CptnModNestCatch1.prems(1) \<open>xs = (P0, t) # xs'\<close> by auto
then have "(n, \<Gamma>, (Catch P0 P1, t) # cfg1) \<in> cptn_mod_nest_call"
by (meson cptn_mod_nest_call.CptnModNestCatch1 local.step)
then show ?case
using CptnModNestCatch1.prems(1) by fastforce
next
case (CptnModNestCatch2 n \<Gamma> P0 sa xs ta f ys zs P1)
thus ?case
proof (induct xs)
case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force
next
case (Cons x xs')
then have x:"x=(P0,t)"
proof-
have zs:"zs=(Catch P0 P1,t)#cfg1" using Cons by fastforce
have "(LanguageCon.com.Catch (fst x) P1, snd x) = lift_catch P1 x"
by (simp add: lift_catch_def prod.case_eq_if)
then have "LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0 P1 \<and> snd x = t"
using Cons.prems(7) zs by fastforce
then show ?thesis
by fastforce
qed
moreover have "s=sa \<and> P = Catch P0 P1" using CptnModNestCatch2.prems(1) by auto
ultimately have step:"(n, \<Gamma>, (P0, t) # xs') \<in> cptn_mod_nest_call" using Cons(3,9,10) by auto
have "fst (last ((P0, t) # xs')) = ta"
using Cons.prems(3) x CptnModNestCatch2.prems(1) by auto
then show ?case
using Cons.prems(4,5) Cons.prems(7) CptnModNestCatch2.prems(1)
cptn_mod_nest_call.CptnModNestCatch2[OF step] x by auto
qed
next
case (CptnModNestCatch3 n \<Gamma> P0 sa xs s' P1 ys zs)
thus ?case
proof (induct xs)
case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force
next
case (Cons x xs')
then have x:"x=(P0,t) \<and> s = sa \<and> P = Catch P0 P1"
proof-
have zs:"zs=(Catch P0 P1,t)#cfg1" using Cons by fastforce
thus ?thesis using Cons(8) lift_catch_def unfolding lift_def
proof -
assume "zs = map (lift_catch P1) (x # xs') @ (P1, snd (last ((P0, sa) # x # xs'))) # ys"
then have "LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0 P1 \<and> snd x = t"
by (simp add: case_prod_unfold lift_catch_def zs)
then show ?thesis
using CptnModNestCatch3.prems(1) by auto
qed
qed
then have step:"(n, \<Gamma>, (P0, t) # xs') \<in> cptn_mod_nest_call" using Cons by auto
then obtain t' where t:"t= t'" by auto
then show ?case
using cptn_mod_nest_call.CptnModNestCatch3[OF local.step[simplified t]]
Cons.prems(3,4,7) CptnModNestCatch3.hyps(4,5) CptnModNestCatch3.prems(1) x by fastforce
qed
qed(fastforce+)
lemma elim_cptn_mod_nest_not_env_call:
assumes a0:"(n,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and
a1:"cfg = (P,s)#(Q,t)#cfg1" and
a2:"(\<forall>f. redex P \<noteq> Call f) \<or>
SmallStepCon.redex P = LanguageCon.com.Call fn \<and> \<Gamma> fn = None"
shows "(n,\<Gamma>,(Q,t)#cfg1) \<in> cptn_mod_nest_call"
using a0 a1 a2
proof (induct arbitrary: P Q cfg1 s t rule:cptn_mod_nest_call.induct )
case (CptnModNestSeq1 n \<Gamma> P0 s xs zs P1)
then obtain P0' xs' where "xs = (P0', t)#xs'" unfolding lift_def by fastforce
then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using CptnModNestSeq1 by fastforce
have Q:"(Q, t) = lift P1 (P0', t) \<and> cfg1 = map (lift P1) xs'"
using CptnModNestSeq1.hyps(3) CptnModNestSeq1.prems(1) \<open>xs = (P0', t) # xs'\<close> by auto
also then have "(n, \<Gamma>, (LanguageCon.com.Seq P0' P1, t) # cfg1) \<in> cptn_mod_nest_call"
by (meson cptn_mod_nest_call.CptnModNestSeq1 local.step)
ultimately show ?case
using CptnModNestSeq1.prems(1)
by (simp add: Cons_lift Q)
next
case (CptnModNestSeq2 n \<Gamma> P0 sa xs P1 ys zs)
thus ?case
proof (induct xs)
case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force
next
case (Cons x xs')
then have x:"\<exists>P0'. x=(P0',t)"
proof-
obtain P0'' where zs: "zs=(Seq P0'' P1,t)#cfg1" using Cons(7) Cons(8)
unfolding lift_def by (simp add: Cons_eq_append_conv case_prod_beta')
thus ?thesis using Cons(7) unfolding lift_def
proof -
assume "zs = map (\<lambda>a. case a of (P, s) \<Rightarrow> (LanguageCon.com.Seq P P1, s)) (x # xs') @
(P1, snd (last ((P0, sa) # x # xs'))) # ys"
then have "LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0'' P1 \<and> snd x = t"
by (simp add: zs case_prod_beta)
also have "sa=s" using Cons by fastforce
ultimately show ?thesis by (meson eq_snd_iff)
qed
qed
then obtain P0' where x:"x=(P0',t) \<and> s = sa \<and> P = Seq P0 P1"
using CptnModNestSeq2.prems(1) by blast
then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using Cons by auto
have "fst (last ((P0', t) # xs')) = LanguageCon.com.Skip"
using Cons.prems(3) x by force
then show ?case
using Cons.prems(4) Cons.prems(6) CptnModNestSeq2.prems(1) x
local.step cptn_mod_nest_call.CptnModNestSeq2[of n \<Gamma> P0' t xs' P1 ys] Cons_lift_append
by (metis (no_types, lifting) last_ConsR list.inject list.simps(3))
qed
next
case (CptnModNestSeq3 n \<Gamma> P0 sa xs c f s' ys zs P1)
thus ?case
proof (induct xs)
case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force
next
case (Cons x xs')
then have x:"\<exists>P0'. x=(P0',t)"
proof-
obtain P0' where zs:"zs=(Seq P0' P1,t)#cfg1" using Cons(8) Cons(9)
unfolding lift_def
by (smt CptnModNestSeq3.prems(1) append_Cons list.sel(3)
list.simps(9) nth_Cons_0 prod.case_eq_if snd_conv)
have "(LanguageCon.com.Seq (fst x) P1, snd x) = lift P1 x"
by (simp add: lift_def prod.case_eq_if)
then have "LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0' P1 \<and> snd x = t"
using Cons.prems(8) zs by force
then show ?thesis by (meson eq_snd_iff)
qed
then obtain P0' where x:"x=(P0',t)" by auto
then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call"
proof -
have f1: "LanguageCon.com.Seq P0 P1 = P \<and> sa = s"
using CptnModNestSeq3.prems(1) by blast
then have "SmallStepCon.redex P = SmallStepCon.redex P0"
by (metis SmallStepCon.redex.simps(4))
then show ?thesis
using f1 Cons.prems(2) CptnModNestSeq3.prems(2) x by presburger
qed
then obtain t' where t:"t= t'" by auto
then show ?case using x Cons(5) Cons(6) cptn_mod_nest_call.CptnModNestSeq3 step
proof -
have "last ((P0', t') # xs') = last ((P0, sa) # x # xs')"
using t x by force
also then have "fst (last ((P0', t') # xs')) = c"
using Cons.prems(3) by presburger
ultimately show ?thesis
using Cons.prems(4,5,6,8)
CptnModNestSeq3.prems(1) cptn_mod_nest_call.CptnModNestSeq3[of n \<Gamma> P0' t' xs' c f s' ys]
local.step t x Cons_lift_append
by (metis (no_types, lifting) list.sel(3))
qed
qed
next
case (CptnModNestCatch1 n \<Gamma> P0 s xs zs P1)
then obtain P0' xs' where xs:"xs = (P0', t)#xs'" unfolding lift_catch_def by fastforce
then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using CptnModNestCatch1 by fastforce
have Q:"(Q, t) = lift_catch P1 (P0', t) \<and> cfg1 = map (lift_catch P1) xs'"
using CptnModNestCatch1.hyps(3) CptnModNestCatch1.prems(1) xs by auto
then have "(n, \<Gamma>, (Catch P0' P1, t) # cfg1) \<in> cptn_mod_nest_call"
by (meson cptn_mod_nest_call.CptnModNestCatch1 local.step)
then show ?case
using CptnModNestCatch1.prems(1) by (simp add:Cons_lift_catch Q)
next
case (CptnModNestCatch2 n \<Gamma> P0 sa xs c f ys zs P1)
thus ?case
proof (induct xs)
case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force
next
case (Cons x xs')
then have x:"\<exists>P0'. x=(P0',t)"
proof-
obtain P0' where zs:"zs=(Catch P0' P1,t)#cfg1" using Cons unfolding lift_catch_def
by (simp add: case_prod_unfold)
have "(LanguageCon.com.Catch (fst x) P1, snd x) = lift_catch P1 x"
by (simp add: lift_catch_def prod.case_eq_if)
then have "LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0' P1 \<and> snd x = t"
using Cons.prems(7) zs by fastforce
then show ?thesis by (meson eq_snd_iff)
qed
then obtain P0' where x:"x=(P0',t) \<and> s = sa \<and> P = Catch P0 P1" using CptnModNestCatch2.prems(1) by auto
then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call"
using Cons.prems(2) CptnModNestCatch2.prems(1) CptnModNestCatch2.prems(2) x by auto
have skip:"fst (last ((P0', t) # xs')) = c"
using Cons.prems(3) x by auto
show ?case
proof -
have "(P, s) # (Q, t) # cfg1 = (LanguageCon.com.Catch P0 P1, sa) # map (lift_catch P1) (x # xs') @
(c, snd (last ((P0, sa) # x # xs'))) # ys"
using CptnModNestCatch2.prems Cons.prems(7) by auto
then show ?thesis
using Cons_lift_catch_append Cons.prems(4,5)
cptn_mod_nest_call.CptnModNestCatch2[OF local.step skip] last.simps list.distinct(1)
x
by (smt list.inject)
qed
qed
next
case (CptnModNestCatch3 n \<Gamma> P0 sa xs s' P1 ys zs)
thus ?case
proof (induct xs)
case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force
next
case (Cons x xs')
then have x:"\<exists>P0'. x=(P0',t)"
proof-
obtain P0' where zs:"zs=(Catch P0' P1,t)#cfg1" using Cons unfolding lift_catch_def
by (simp add: case_prod_unfold)
thus ?thesis using Cons(8) lift_catch_def unfolding lift_def
proof -
assume "zs = map (lift_catch P1) (x # xs') @ (P1, snd (last ((P0, sa) # x # xs'))) # ys"
then have "LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0' P1 \<and> snd x = t"
by (simp add: case_prod_unfold lift_catch_def zs)
then show ?thesis by (meson eq_snd_iff)
qed
qed
then obtain P0' where x:"x=(P0',t) \<and> s = sa \<and> P = Catch P0 P1"
using CptnModNestCatch3.prems(1) by blast
then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using Cons
using Cons.prems(2) CptnModNestCatch3.prems(1) CptnModNestCatch3.prems(2) x by simp
then show ?case
proof -
have "last ((P0', t) # xs') = last ((P0, sa) # x # xs')"
using x by force
also then have "fst (last ((P0', t) # xs')) = LanguageCon.com.Throw"
using Cons.prems(3) by presburger
ultimately show ?thesis
using Cons.prems(4) Cons.prems(5) Cons.prems(7)
CptnModNestCatch3.prems(1) cptn_mod_nest_call.CptnModNestCatch3[of n \<Gamma> P0' t xs' s' P1]
local.step x by (metis Cons_lift_catch_append list.sel(3))
qed
qed
next
case (CptnModNestWhile1 n \<Gamma> P0 s' xs b zs)
thus ?case
using cptn_mod_nest_call.CptnModNestSeq1 list.inject by blast
next
case (CptnModNestWhile2 n \<Gamma> P0 s' xs b zs ys)
have "(LanguageCon.com.While b P0, s') = (P, s) \<and>
(LanguageCon.com.Seq P0 (LanguageCon.com.While b P0), s') # zs = (Q, t) # cfg1"
using CptnModNestWhile2.prems by fastforce
then show ?case
using CptnModNestWhile2.hyps(1) CptnModNestWhile2.hyps(3)
CptnModNestWhile2.hyps(5) CptnModNestWhile2.hyps(6)
cptn_mod_nest_call.CptnModNestSeq2 by blast
next
case (CptnModNestWhile3 n \<Gamma> P0 s' xs b zs) thus ?case
by (metis (no_types) CptnModNestWhile3.hyps(1,3,6) CptnModNestWhile3.prems(1)
cptn_mod_nest_call.CptnModNestSeq3 list.inject)
qed(fastforce+)
lemma elim_cptn_mod_nest_call_n_greater_zero:
assumes a0:"(n,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and
a1:"cfg = (P, s)#(Q,t)#cfg1 \<and> P = Call f \<and> \<Gamma> f = Some Q \<and> P\<noteq>Q"
shows "n>0"
using a0 a1 by (induct rule:cptn_mod_nest_call.induct, fast+)
lemma elim_cptn_mod_nest_call_0_False:
assumes a0:"(0,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and
a1:"cfg = (P, s)#(Q,t)#cfg1 \<and> P = Call f \<and> \<Gamma> f = Some Q \<and> P\<noteq>Q"
shows "PP"
using a0 a1 elim_cptn_mod_nest_call_n_greater_zero
by fast
lemma elim_cptn_mod_nest_call_n_dec1:
assumes a0:"(n,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and
a1:"cfg = (P, s)#(Q,t)#cfg1 \<and> P = Call f \<and> \<Gamma> f = Some Q \<and> t= s \<and> P\<noteq>Q"
shows "(n-1,\<Gamma>,(Q,t)#cfg1) \<in> cptn_mod_nest_call"
using a0 a1
by (induct rule:cptn_mod_nest_call.induct,force+)
lemma elim_cptn_mod_nest_call_n_dec:
assumes a0:"(n,\<Gamma>,(Call f, s)#(the (\<Gamma> f), s)#cfg1) \<in> cptn_mod_nest_call" and
a1:"\<Gamma> f = Some Q " and a2:"Call f\<noteq>the (\<Gamma> f)"
shows "(n-1,\<Gamma>,(the (\<Gamma> f), s)#cfg1) \<in> cptn_mod_nest_call"
using elim_cptn_mod_nest_call_n_dec1[OF a0] a1 a2
by fastforce
lemma elim_cptn_mod_nest_call_n:
assumes a0:"(n,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and
a1:"cfg = (P, s)#(Q,t)#cfg1"
shows "(n,\<Gamma>,(Q,t)#cfg1) \<in> cptn_mod_nest_call"
using a0 a1
proof (induct arbitrary: P Q cfg1 s t rule:cptn_mod_nest_call.induct )
case (CptnModNestCall n \<Gamma> bdy sa ys p)
thus ?case using cptn_mod_nest_mono1 list.inject by blast
next
case (CptnModNestSeq1 n \<Gamma> P0 s xs zs P1)
then obtain P0' xs' where "xs = (P0', t)#xs'" unfolding lift_def by fastforce
then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using CptnModNestSeq1 by fastforce
have Q:"(Q, t) = lift P1 (P0', t) \<and> cfg1 = map (lift P1) xs'"
using CptnModNestSeq1.hyps(3) CptnModNestSeq1.prems(1) \<open>xs = (P0', t) # xs'\<close> by auto
also then have "(n, \<Gamma>, (LanguageCon.com.Seq P0' P1, t) # cfg1) \<in> cptn_mod_nest_call"
by (meson cptn_mod_nest_call.CptnModNestSeq1 local.step)
ultimately show ?case
using CptnModNestSeq1.prems(1)
by (simp add: Cons_lift Q)
next
case (CptnModNestSeq2 n \<Gamma> P0 sa xs P1 ys zs)
thus ?case
proof (induct xs)
case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force
next
case (Cons x xs')
then have x:"\<exists>P0'. x=(P0',t)"
proof-
obtain P0'' where zs: "zs=(Seq P0'' P1,t)#cfg1" using Cons(7) Cons(8)
unfolding lift_def by (simp add: Cons_eq_append_conv case_prod_beta')
thus ?thesis using Cons(7) unfolding lift_def
proof -
assume "zs = map (\<lambda>a. case a of (P, s) \<Rightarrow> (LanguageCon.com.Seq P P1, s)) (x # xs') @
(P1, snd (last ((P0, sa) # x # xs'))) # ys"
then have "LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0'' P1 \<and> snd x = t"
by (simp add: zs case_prod_beta)
also have "sa=s" using Cons by fastforce
ultimately show ?thesis by (meson eq_snd_iff)
qed
qed
then obtain P0' where x:"x=(P0',t)" by auto
then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using Cons
by blast
have "fst (last ((P0', t) # xs')) = LanguageCon.com.Skip"
using Cons.prems(3) x by force
then show ?case
using Cons.prems(4) Cons.prems(6) CptnModNestSeq2.prems(1) x
local.step cptn_mod_nest_call.CptnModNestSeq2[of n \<Gamma> P0' t xs' P1 ys] Cons_lift_append
by (metis (no_types, lifting) last_ConsR list.inject list.simps(3))
qed
next
case (CptnModNestSeq3 n \<Gamma> P0 sa xs c f s' ys zs P1)
thus ?case
proof (induct xs)
case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force
next
case (Cons x xs')
then have x:"\<exists>P0'. x=(P0',t)"
proof-
obtain P0' where zs:"zs=(Seq P0' P1,t)#cfg1" using Cons(8) Cons(9) CptnModNestSeq3.prems
unfolding lift_def
by (smt append_Cons list.sel(3)
list.simps(9) nth_Cons_0 prod.case_eq_if snd_conv)
have "(LanguageCon.com.Seq (fst x) P1, snd x) = lift P1 x"
by (simp add: lift_def prod.case_eq_if)
then have "LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0' P1 \<and> snd x = t"
using zs by (simp add: Cons.prems(8))
then show ?thesis by (meson eq_snd_iff)
qed
then obtain P0' where x:"x=(P0',t) \<and> s = sa \<and> P = Seq P0 P1"
using CptnModNestSeq3.prems by blast
then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using Cons by auto
then show ?case using x Cons(5) Cons(6) cptn_mod_nest_call.CptnModNestSeq3 step
proof -
have "last ((P0', t) # xs') = last ((P0, sa) # x # xs')"
using x by force
also then have "fst (last ((P0', t) # xs')) = c"
using Cons.prems(3) by presburger
ultimately show ?thesis
using Cons.prems(4,5,6,8)
CptnModNestSeq3.prems(1) cptn_mod_nest_call.CptnModNestSeq3[of n \<Gamma> P0' t xs' c f s' ys]
local.step x Cons_lift_append
by (metis (no_types, lifting) list.sel(3))
qed
qed
next
case (CptnModNestCatch1 n \<Gamma> P0 s xs zs P1)
then obtain P0' xs' where xs:"xs = (P0', t)#xs'" unfolding lift_catch_def by fastforce
then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using CptnModNestCatch1 by fastforce
have Q:"(Q, t) = lift_catch P1 (P0', t) \<and> cfg1 = map (lift_catch P1) xs'"
using CptnModNestCatch1.hyps(3) CptnModNestCatch1.prems(1) xs by auto
then have "(n, \<Gamma>, (Catch P0' P1, t) # cfg1) \<in> cptn_mod_nest_call"
by (meson cptn_mod_nest_call.CptnModNestCatch1 local.step)
then show ?case
using CptnModNestCatch1.prems(1) by (simp add:Cons_lift_catch Q)
next
case (CptnModNestCatch2 n \<Gamma> P0 sa xs c f ys zs P1)
thus ?case
proof (induct xs)
case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force
next
case (Cons x xs')
then have x:"\<exists>P0'. x=(P0',t)"
proof-
obtain P0' where zs:"zs=(Catch P0' P1,t)#cfg1" using Cons unfolding lift_catch_def
by (simp add: case_prod_unfold)
have "(LanguageCon.com.Catch (fst x) P1, snd x) = lift_catch P1 x"
by (simp add: lift_catch_def prod.case_eq_if)
then have "LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0' P1 \<and> snd x = t"
using Cons.prems(6,7) zs by fastforce
then show ?thesis by (meson eq_snd_iff)
qed
then obtain P0' where x:"x=(P0',t) \<and> s = sa \<and> P = Catch P0 P1" using CptnModNestCatch2.prems by auto
then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using Cons by auto
have skip:"fst (last ((P0', t) # xs')) = c"
using Cons.prems(3) x by auto
show ?case
proof -
have "(P, s) # (Q, t) # cfg1 = (LanguageCon.com.Catch P0 P1, sa) # map (lift_catch P1) (x # xs') @
(c, snd (last ((P0, sa) # x # xs'))) # ys"
using CptnModNestCatch2.prems Cons.prems(6,7) by auto
then show ?thesis
using Cons_lift_catch_append Cons.prems(5,6,7)
cptn_mod_nest_call.CptnModNestCatch2[OF local.step skip Cons.prems(4) _ ] last.simps list.distinct(1)
x
by (metis (no_types) list.sel(3) )
qed
qed
next
case (CptnModNestCatch3 n \<Gamma> P0 sa xs s' P1 ys zs)
thus ?case
proof (induct xs)
case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force
next
case (Cons x xs')
then have x:"\<exists>P0'. x=(P0',t)"
proof-
obtain P0' where zs:"zs=(Catch P0' P1,t)#cfg1" using Cons unfolding lift_catch_def
by (simp add: case_prod_unfold)
thus ?thesis using Cons(8) lift_catch_def unfolding lift_def
proof -
assume "zs = map (lift_catch P1) (x # xs') @ (P1, snd (last ((P0, sa) # x # xs'))) # ys"
then have "LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0' P1 \<and> snd x = t"
by (simp add: case_prod_unfold lift_catch_def zs)
then show ?thesis by (meson eq_snd_iff)
qed
qed
then obtain P0' where x:"x=(P0',t)" by auto
then have step:"(n, \<Gamma>, (P0', t) # xs') \<in> cptn_mod_nest_call" using Cons by simp
then show ?case
proof -
have "last ((P0', t) # xs') = last ((P0, sa) # x # xs')"
using x by force
also then have "fst (last ((P0', t) # xs')) = LanguageCon.com.Throw"
using Cons.prems(3) by presburger
ultimately show ?thesis
using Cons.prems(4,5,7)
CptnModNestCatch3.prems(1) cptn_mod_nest_call.CptnModNestCatch3[of n \<Gamma> P0' t xs' s' P1]
local.step x by (metis Cons_lift_catch_append list.sel(3))
qed
qed
next
case (CptnModNestWhile1 n \<Gamma> P0 s' xs b zs)
thus ?case
using cptn_mod_nest_call.CptnModNestSeq1 list.inject by blast
next
case (CptnModNestWhile2 n \<Gamma> P0 s' xs b zs ys)
have "(LanguageCon.com.While b P0, s') = (P, s) \<and>
(LanguageCon.com.Seq P0 (LanguageCon.com.While b P0), s') # zs = (Q, t) # cfg1"
using CptnModNestWhile2.prems by fastforce
then show ?case
using CptnModNestWhile2.hyps(1) CptnModNestWhile2.hyps(3)
CptnModNestWhile2.hyps(5) CptnModNestWhile2.hyps(6)
cptn_mod_nest_call.CptnModNestSeq2 by blast
next
case (CptnModNestWhile3 n \<Gamma> P0 s' xs b zs) thus ?case
by (metis (no_types) CptnModNestWhile3.hyps(1,3,6) CptnModNestWhile3.prems
cptn_mod_nest_call.CptnModNestSeq3 list.inject)
qed (fastforce+)
lemma dropcptn_is_cptn1 [rule_format,elim!]:
"\<forall>j<length c. (n,\<Gamma>,c) \<in> cptn_mod_nest_call \<longrightarrow> (n,\<Gamma>, drop j c) \<in> cptn_mod_nest_call"
proof -
{fix j
assume "j<length c \<and> (n,\<Gamma>,c) \<in> cptn_mod_nest_call"
then have "(n,\<Gamma>, drop j c) \<in> cptn_mod_nest_call"
proof(induction j arbitrary: c)
case 0 then show ?case by auto
next
case (Suc j)
then obtain a b c' where "c=a#b#c'"
by (metis (no_types, hide_lams) Suc_less_eq length_Cons list.exhaust list.size(3) not_less0)
then also have "j<length (b#c')" using Suc by auto
ultimately moreover have "(n, \<Gamma>, drop j (b # c')) \<in> cptn_mod_nest_call" using elim_cptn_mod_nest_call_n[of n \<Gamma> c] Suc
by (metis surj_pair)
ultimately show ?case by auto
qed
} thus ?thesis by auto
qed
definition min_call where
"min_call n \<Gamma> cfs \<equiv> (n,\<Gamma>,cfs) \<in> cptn_mod_nest_call \<and> (\<forall>m<n. \<not>((m,\<Gamma>,cfs) \<in> cptn_mod_nest_call))"
lemma minimum_nest_call:
"(m,\<Gamma>,cfs) \<in> cptn_mod_nest_call \<Longrightarrow>
\<exists>n. min_call n \<Gamma> cfs"
unfolding min_call_def
proof (induct arbitrary: m rule:cptn_mod_nest_call.induct)
case (CptnModNestOne) thus ?case using cptn_mod_nest_call.CptnModNestOne by blast
next
case (CptnModNestEnv \<Gamma> P s t n xs)
then have "\<not> \<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (P, toSeq t)"
using mod_env_not_component step_change_p_or_eq_s by fastforce
then obtain min_n where min:"(min_n, \<Gamma>, (P, t) # xs) \<in> cptn_mod_nest_call \<and>
(\<forall>m<min_n. (m, \<Gamma>, (P, t) # xs) \<notin> cptn_mod_nest_call)"
using CptnModNestEnv by blast
then have "(min_n, \<Gamma>, (P,s)#(P, t) # xs) \<in> cptn_mod_nest_call"
using cptn_mod_nest_call.CptnModNestEnv CptnModNestEnv by blast
also have "(\<forall>m<min_n. (m, \<Gamma>, (P, s)#(P, t) # xs) \<notin> cptn_mod_nest_call)"
using elim_cptn_mod_nest_call_n min by blast
ultimately show ?case by auto
next
case (CptnModNestSkip \<Gamma> P s t n xs)
then obtain min_n where
min:"(min_n, \<Gamma>, (LanguageCon.com.Skip, t) # xs) \<in> cptn_mod_nest_call \<and>
(\<forall>m<min_n. (m, \<Gamma>, (LanguageCon.com.Skip, t) # xs) \<notin> cptn_mod_nest_call)"
by auto
then have "(min_n, \<Gamma>, (P,s)#(LanguageCon.com.Skip, t) # xs) \<in> cptn_mod_nest_call"
using cptn_mod_nest_call.CptnModNestSkip CptnModNestSkip by blast
also have "(\<forall>m<min_n. (m, \<Gamma>, (P, s)#(LanguageCon.com.Skip, t) # xs) \<notin> cptn_mod_nest_call)"
using elim_cptn_mod_nest_call_n min by blast
ultimately show ?case by fastforce
next
case (CptnModNestThrow \<Gamma> P s t n xs) thus ?case
using elim_cptn_mod_nest_call_n[OF CptnModNestThrow(5)]
by (metis (no_types, lifting) cptn_mod_nest_call.CptnModNestThrow elim_cptn_mod_nest_call_n)
next
case (CptnModNestStuck \<Gamma> P s t n xs) thus ?case
using elim_cptn_mod_nest_call_n[OF CptnModNestStuck(5)]
by (metis (no_types, lifting) cptn_mod_nest_call.CptnModNestStuck elim_cptn_mod_nest_call_n)
next
case (CptnModNestFault \<Gamma> P s f t n xs) thus ?case
using elim_cptn_mod_nest_call_n[OF CptnModNestFault(5)]
by (metis (no_types, lifting) cptn_mod_nest_call.CptnModNestFault elim_cptn_mod_nest_call_n)
next
case (CptnModNestCondT n \<Gamma> P0 s xs b P1) thus ?case
by (meson cptn_mod_nest_call.CptnModNestCondT elim_cptn_mod_nest_call_n)
next
case (CptnModNestCondF n \<Gamma> P1 s xs b P0) thus ?case
by (meson cptn_mod_nest_call.CptnModNestCondF elim_cptn_mod_nest_call_n)
next
case (CptnModNestSeq1 n \<Gamma> P s xs zs Q) thus ?case
by (metis (no_types, lifting) Seq_P_Not_finish cptn_mod_nest_call.CptnModNestSeq1 div_seq_nest)
next
case (CptnModNestSeq2 n \<Gamma> P s xs Q ys zs)
then obtain min_p where
min_p:"(min_p, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call \<and>
(\<forall>m<min_p. (m, \<Gamma>, (P, s) # xs) \<notin> cptn_mod_nest_call)"
by auto
from CptnModNestSeq2(5) obtain min_q where
min_q:"(min_q, \<Gamma>, (Q, snd (last ((P, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and>
(\<forall>m<min_q. (m, \<Gamma>, (Q, snd (last ((P, s) # xs))) # ys) \<notin> cptn_mod_nest_call)"
by auto
thus ?case
proof(cases "min_p\<ge>min_q")
case True
then have "(min_p, \<Gamma>, (Q, snd (last ((P,s) # xs))) # ys) \<in> cptn_mod_nest_call"
using min_q using cptn_mod_nest_mono by blast
then have "(min_p, \<Gamma>, (Seq P Q, s) # zs) \<in> cptn_mod_nest_call"
using conjunct1[OF min_p] cptn_mod_nest_call.CptnModNestSeq2[of min_p \<Gamma> P s xs Q ys zs]
CptnModNestSeq2(6) CptnModNestSeq2(3)
by blast
also have "\<forall>m<min_p. (m, \<Gamma>,(Seq P Q,s) # zs) \<notin> cptn_mod_nest_call"
by (metis CptnModNestSeq2.hyps(3) CptnModNestSeq2.hyps(6) Seq_P_Ends_Normal div_seq_nest min_p)
ultimately show ?thesis by auto
next
case False
then have "(min_q, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call"
using min_p cptn_mod_nest_mono by force
then have "(min_q, \<Gamma>, (Seq P Q, s) # zs) \<in> cptn_mod_nest_call"
using conjunct1[OF min_q] cptn_mod_nest_call.CptnModNestSeq2[of min_q \<Gamma> P s xs Q ys zs]
CptnModNestSeq2(6) CptnModNestSeq2(3)
by blast
also have "\<forall>m<min_q. (m, \<Gamma>,(Seq P Q,s) # zs) \<notin> cptn_mod_nest_call"
proof -
{fix m
assume min_m:"m<min_q"
then have "(m, \<Gamma>,(Seq P Q, s) # zs) \<notin> cptn_mod_nest_call"
proof -
{assume ass:"(m, \<Gamma>, (Seq P Q, s) # zs) \<in> cptn_mod_nest_call"
then obtain xs' s' s'' where
m_cptn:"(m, \<Gamma>, (P, s) # xs') \<in> cptn_mod_nest_call \<and>
seq_cond_nest zs Q xs' P s s'' s' \<Gamma> m"
using
div_seq_nest[of m \<Gamma> "(LanguageCon.com.Seq P Q, s) # zs"]
by fastforce
then have "seq_cond_nest zs Q xs' P s s'' s' \<Gamma> m" by auto
then have ?thesis
using Seq_P_Ends_Normal[OF CptnModNestSeq2(6) CptnModNestSeq2(3) ass]
min_m min_q
by (metis last_length)
} thus ?thesis by auto
qed
}thus ?thesis by auto
qed
ultimately show ?thesis by auto
qed
next
case (CptnModNestSeq3 n \<Gamma> P s xs c f s' ys zs Q)
then obtain min_p where
min_p:"(min_p, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call \<and>
(\<forall>m<min_p. (m, \<Gamma>, (P, s) # xs) \<notin> cptn_mod_nest_call)"
by auto
from CptnModNestSeq3(6,7) obtain min_q where
min_q:"(min_q, \<Gamma>, (c, s') # ys) \<in> cptn_mod_nest_call \<and>
(\<forall>m<min_q. (m, \<Gamma>, (c, s') # ys) \<notin> cptn_mod_nest_call)"
by auto
thus ?case
proof(cases "min_p\<ge>min_q")
case True
then have "(min_p, \<Gamma>, (c, s') # ys) \<in> cptn_mod_nest_call"
using min_q using cptn_mod_nest_mono by blast
then have "(min_p, \<Gamma>, (Seq P Q, s) # zs) \<in> cptn_mod_nest_call"
using conjunct1[OF min_p] cptn_mod_nest_call.CptnModNestSeq3[of min_p \<Gamma> P s xs c f s' ys zs Q]
CptnModNestSeq3(3,4,5,6,8)
by blast
also have "\<forall>m<min_p. (m, \<Gamma>,(Seq P Q, s) # zs) \<notin> cptn_mod_nest_call"
by (metis CptnModNestSeq3.hyps(3,4,5,8) Seq_P_Ends_Abort div_seq_nest min_p)
ultimately show ?thesis by auto
next
case False
then have "(min_q, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call"
using min_p cptn_mod_nest_mono by force
then have "(min_q, \<Gamma>, (Seq P Q, s) # zs) \<in> cptn_mod_nest_call"
using conjunct1[OF min_q] cptn_mod_nest_call.CptnModNestSeq3[of min_q \<Gamma> P s xs c f s' ys zs Q]
CptnModNestSeq3(3,4,5,8)
by blast
also have "\<forall>m<min_q. (m, \<Gamma>,(Seq P Q, s) # zs) \<notin> cptn_mod_nest_call"
by (metis CptnModNestSeq3.hyps(3,4,5,8) Seq_P_Ends_Abort div_seq_nest min_q)
ultimately show ?thesis by auto
qed
next
case (CptnModNestWhile1 n \<Gamma> P s xs b zs)
then obtain min_n where
min:"(min_n, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call \<and>
(\<forall>m<min_n. (m, \<Gamma>, (P, s) # xs) \<notin> cptn_mod_nest_call)"
by auto
then have "(min_n, \<Gamma>, (While b P, s) # (Seq P (While b P), s) # zs) \<in> cptn_mod_nest_call"
using cptn_mod_nest_call.CptnModNestWhile1[of min_n \<Gamma> P s xs b zs] CptnModNestWhile1
by meson
also have "\<forall>m<min_n. (m, \<Gamma>,(While b P, s) # (Seq P (While b P), s) # zs) \<notin> cptn_mod_nest_call"
by (metis CptnModNestWhile1.hyps(4) Seq_P_Not_finish div_seq_nest elim_cptn_mod_nest_call_n min)
ultimately show ?case by auto
next
case (CptnModNestWhile2 n \<Gamma> P s xs b zs ys)
then obtain min_n_p where
min_p:"(min_n_p, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call \<and>
(\<forall>m<min_n_p. (m, \<Gamma>, (P, s) # xs) \<notin> cptn_mod_nest_call)"
by auto
from CptnModNestWhile2 obtain min_n_w where
min_w:"(min_n_w, \<Gamma>, (LanguageCon.com.While b P, snd (last ((P, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and>
(\<forall>m<min_n_w. (m, \<Gamma>, (LanguageCon.com.While b P, snd (last ((P, s) # xs))) # ys)
\<notin> cptn_mod_nest_call)"
by auto
thus ?case
proof (cases "min_n_p\<ge>min_n_w")
case True
then have "(min_n_p, \<Gamma>,
(LanguageCon.com.While b P, snd (last ((P, s) # xs))) # ys) \<in> cptn_mod_nest_call"
using min_w using cptn_mod_nest_mono by blast
then have "(min_n_p, \<Gamma>, (While b P, s) # (Seq P (While b P), s) # zs) \<in> cptn_mod_nest_call"
using min_p cptn_mod_nest_call.CptnModNestWhile2[of min_n_p \<Gamma> P s xs b zs] CptnModNestWhile2
by blast
also have "\<forall>m<min_n_p. (m, \<Gamma>,(While b P, s) # (Seq P (While b P), s) # zs) \<notin> cptn_mod_nest_call"
by (metis CptnModNestWhile2.hyps(3) CptnModNestWhile2.hyps(5)
Seq_P_Ends_Normal div_seq_nest elim_cptn_mod_nest_call_n min_p)
ultimately show ?thesis by auto
next
case False
then have False:"min_n_p<min_n_w" by auto
then have "(min_n_w, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call"
using min_p cptn_mod_nest_mono by force
then have "(min_n_w, \<Gamma>, (While b P, s) # (Seq P (While b P), s) # zs) \<in> cptn_mod_nest_call"
using min_w min_p cptn_mod_nest_call.CptnModNestWhile2[of min_n_w \<Gamma> P s xs b zs] CptnModNestWhile2
by blast
also have "\<forall>m<min_n_w. (m, \<Gamma>,(While b P, s) # (Seq P (While b P), s) # zs) \<notin> cptn_mod_nest_call"
proof -
{fix m
assume min_m:"m<min_n_w"
then have "(m, \<Gamma>,(While b P, s) # (Seq P (While b P), s) # zs) \<notin> cptn_mod_nest_call"
proof -
{assume "(m, \<Gamma>,(While b P, s) # (Seq P (While b P), s) # zs) \<in> cptn_mod_nest_call"
then have a1:"(m, \<Gamma>,(Seq P (While b P), s) # zs) \<in> cptn_mod_nest_call"
by (meson elim_cptn_mod_nest_call_n)
then obtain xs' s' s'' where
m_cptn:"(m, \<Gamma>, (P, s) # xs') \<in> cptn_mod_nest_call \<and>
seq_cond_nest zs (While b P) xs' P ( s) s'' s' \<Gamma> m"
using
div_seq_nest[of m \<Gamma> "(LanguageCon.com.Seq P (LanguageCon.com.While b P), s) # zs"]
by fastforce
then have "seq_cond_nest zs (While b P) xs' P ( s) s'' s' \<Gamma> m" by auto
then have ?thesis unfolding seq_cond_nest_def
by (metis CptnModNestWhile2.hyps(3) CptnModNestWhile2.hyps(5) Seq_P_Ends_Normal a1 last_length m_cptn min_m min_w)
} thus ?thesis by auto
qed
}thus ?thesis by auto
qed
ultimately show ?thesis by auto
qed
next
case (CptnModNestWhile3 n \<Gamma> P s xs c f b s' ys zs)
then obtain min_n_p where
min_p:"(min_n_p, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call \<and>
(\<forall>m<min_n_p. (m, \<Gamma>, (P, s) # xs) \<notin> cptn_mod_nest_call)"
by auto
from CptnModNestWhile3 obtain min_n_w where
min_w:"(min_n_w, \<Gamma>, (c, snd (last ((P, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and>
(\<forall>m<min_n_w. (m, \<Gamma>, (c, snd (last ((P, s) # xs))) # ys)
\<notin> cptn_mod_nest_call)"
by auto
thus ?case
proof (cases "min_n_p\<ge>min_n_w")
case True
then have "(min_n_p, \<Gamma>,
(c, snd (last ((P, s) # xs))) # ys) \<in> cptn_mod_nest_call"
using min_w using cptn_mod_nest_mono by blast
then have "(min_n_p, \<Gamma>, (While b P, s) # (Seq P (While b P), s) # zs) \<in> cptn_mod_nest_call"
using min_p cptn_mod_nest_call.CptnModNestWhile3[of min_n_p \<Gamma> P s xs c f b s' ys zs]
CptnModNestWhile3
by fastforce
also have "\<forall>m<min_n_p. (m, \<Gamma>,(While b P, s) # (Seq P (While b P), s) # zs) \<notin> cptn_mod_nest_call"
by (metis CptnModNestWhile3.hyps(3,4,6,9)
Seq_P_Ends_Abort div_seq_nest elim_cptn_mod_nest_call_n min_p)
ultimately show ?thesis by auto
next
case False
then have False:"min_n_p<min_n_w" by auto
then have "(min_n_w, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call"
using min_p cptn_mod_nest_mono by force
then have "(min_n_w, \<Gamma>, (While b P, s) # (Seq P (While b P), s) # zs) \<in> cptn_mod_nest_call"
using min_w min_p cptn_mod_nest_call.CptnModNestWhile3[of min_n_w \<Gamma> P s xs c f b s' ys zs]
CptnModNestWhile3
by fastforce
also have "\<forall>m<min_n_w. (m, \<Gamma>,(While b P, s) # (Seq P (While b P), s) # zs) \<notin> cptn_mod_nest_call"
proof -
{fix m
assume min_m:"m<min_n_w"
then have "(m, \<Gamma>,(While b P, s) # (Seq P (While b P), s) # zs) \<notin> cptn_mod_nest_call"
proof -
{assume "(m, \<Gamma>,(While b P, s) # (Seq P (While b P), s) # zs) \<in> cptn_mod_nest_call"
then have s1:"(m, \<Gamma>,(Seq P (While b P), s) # zs) \<in> cptn_mod_nest_call"
using elim_cptn_mod_nest_not_env_call
by (meson elim_cptn_mod_nest_call_n)
then obtain xs' s' s'' where
m_cptn:"(m, \<Gamma>, (P, s) # xs') \<in> cptn_mod_nest_call \<and>
seq_cond_nest zs (While b P) xs' P ( s) s'' s' \<Gamma> m"
using
div_seq_nest[of m \<Gamma> "(LanguageCon.com.Seq P (LanguageCon.com.While b P), s) # zs"]
by fastforce
then have "seq_cond_nest zs (While b P) xs' P s s'' s' \<Gamma> m" by auto
then have ?thesis unfolding seq_cond_nest_def
by (metis CptnModNestWhile3.hyps(3,4,6,9) Seq_P_Ends_Abort s1 m_cptn min_m min_w)
} thus ?thesis by auto
qed
}thus ?thesis by auto
qed
ultimately show ?thesis by auto
qed
next
case (CptnModNestCall n \<Gamma> bdy s xs f) thus ?case
proof -
{ fix nn :: "nat \<Rightarrow> nat"
obtain nna :: nat where
ff1: "(nna, \<Gamma>, (bdy, s) # xs) \<in> cptn_mod_nest_call \<and> (\<forall>n. \<not> n < nna \<or> (n, \<Gamma>, (bdy, s) # xs) \<notin> cptn_mod_nest_call)"
by (meson CptnModNestCall.hyps(2))
moreover
{ assume "(nn (nn (Suc nna)), \<Gamma>, (bdy, s) # xs) \<in> cptn_mod_nest_call"
then have "\<not> Suc (nn (nn (Suc nna))) < Suc nna"
using ff1 by blast
then have "(nn (Suc nna), \<Gamma>, (LanguageCon.com.Call f, s) # (bdy, s) # xs) \<in> cptn_mod_nest_call \<longrightarrow> (\<exists>n. (n, \<Gamma>, (LanguageCon.com.Call f, s) # (bdy, s) # xs) \<in> cptn_mod_nest_call \<and>
(\<not> nn n < n \<or> (nn n, \<Gamma>, (LanguageCon.com.Call f, s) # (bdy, s) # xs) \<notin> cptn_mod_nest_call))"
using ff1 by (meson CptnModNestCall.hyps(3) CptnModNestCall.hyps(4) cptn_mod_nest_call.CptnModNestCall less_trans_Suc) }
ultimately have "\<exists>n. (n, \<Gamma>, (LanguageCon.com.Call f, s) # (bdy, s) # xs) \<in> cptn_mod_nest_call \<and> (\<not> nn n < n \<or> (nn n, \<Gamma>, (LanguageCon.com.Call f, s) # (bdy, s) # xs) \<notin> cptn_mod_nest_call)"
by (metis (no_types) CptnModNestCall.hyps(3) CptnModNestCall.hyps(4) cptn_mod_nest_call.CptnModNestCall elim_cptn_mod_nest_call_n) }
then show ?thesis
by meson
qed
next
case (CptnModNestDynCom n \<Gamma> c s xs) thus ?case
by (meson cptn_mod_nest_call.CptnModNestDynCom elim_cptn_mod_nest_call_n)
next
case (CptnModNestGuard n \<Gamma> c s xs g f) thus ?case
by (meson cptn_mod_nest_call.CptnModNestGuard elim_cptn_mod_nest_call_n)
next
case (CptnModNestCatch1 n \<Gamma> P s xs zs Q) thus ?case
by (metis (no_types, lifting) Catch_P_Not_finish cptn_mod_nest_call.CptnModNestCatch1 div_catch_nest)
next
case (CptnModNestCatch2 n \<Gamma> P s xs c f ys zs Q)
then obtain min_p where
min_p:"(min_p, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call \<and>
(\<forall>m<min_p. (m, \<Gamma>, (P, s) # xs) \<notin> cptn_mod_nest_call)"
by auto
from CptnModNestCatch2(5) obtain min_q where
min_q:"(min_q, \<Gamma>, (c, snd (last ((P, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and>
(\<forall>m<min_q. (m, \<Gamma>, (c, snd (last ((P, s) # xs))) # ys) \<notin> cptn_mod_nest_call)"
using CptnModNestCatch2.hyps(6) by blast
thus ?case
proof(cases "min_p\<ge>min_q")
case True
then have "(min_p, \<Gamma>, (c, snd (last ((P,s) # xs))) # ys) \<in> cptn_mod_nest_call"
using min_q using cptn_mod_nest_mono by blast
then have "(min_p, \<Gamma>, (Catch P Q, s) # zs) \<in> cptn_mod_nest_call"
using conjunct1[OF min_p] cptn_mod_nest_call.CptnModNestCatch2[of min_p \<Gamma> P s xs]
CptnModNestCatch2(3,4,7)
by blast
also have "\<forall>m<min_p. (m, \<Gamma>,(Catch P Q,s) # zs) \<notin> cptn_mod_nest_call"
proof -
{fix m
assume min_m:"m<min_p"
then have "(m, \<Gamma>,(Catch P Q, s) # zs) \<notin> cptn_mod_nest_call"
proof -
{assume ass:"(m, \<Gamma>, (Catch P Q, s) # zs) \<in> cptn_mod_nest_call"
then obtain xs' s' s'' where
m_cptn:"(m, \<Gamma>, (P, s) # xs') \<in> cptn_mod_nest_call \<and>
catch_cond_nest zs Q xs' P s s'' s' \<Gamma> m"
using
div_catch_nest[of m \<Gamma> "(Catch P Q, s) # zs"]
by fastforce
then have "catch_cond_nest zs Q xs' P s s'' s' \<Gamma> m" by auto
then have "xs=xs'"
using Catch_P_Ends_Skip[OF CptnModNestCatch2(7) CptnModNestCatch2(3)]
using CptnModNestCatch2.hyps(4) by blast
then have "(m, \<Gamma>, (P,s) # xs) \<in> cptn_mod_nest_call"
using m_cptn by auto
then have False using min_p min_m by fastforce
} thus ?thesis by auto
qed
}thus ?thesis by auto
qed
ultimately show ?thesis by auto
next
case False
then have "(min_q, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call"
using min_p cptn_mod_nest_mono by force
then have "(min_q, \<Gamma>, (Catch P Q, s) # zs) \<in> cptn_mod_nest_call"
using conjunct1[OF min_q] cptn_mod_nest_call.CptnModNestCatch2[of min_q \<Gamma> P s xs ]
CptnModNestCatch2(3,4,7)
by blast
also have "\<forall>m<min_q. (m, \<Gamma>,(Catch P Q,s) # zs) \<notin> cptn_mod_nest_call"
proof -
{fix m
assume min_m:"m<min_q"
then have "(m, \<Gamma>,(Catch P Q, s) # zs) \<notin> cptn_mod_nest_call"
proof -
{assume ass:"(m, \<Gamma>, (Catch P Q, s) # zs) \<in> cptn_mod_nest_call"
then obtain xs' s' s'' where
m_cptn:"(m, \<Gamma>, (P, s) # xs') \<in> cptn_mod_nest_call \<and>
catch_cond_nest zs Q xs' P s s'' s' \<Gamma> m"
using
div_catch_nest[of m \<Gamma> "(Catch P Q, s) # zs"]
by fastforce
then have "catch_cond_nest zs Q xs' P s s'' s' \<Gamma> m" by auto
then have ?thesis
using Catch_P_Ends_Skip[OF CptnModNestCatch2(7) CptnModNestCatch2(3)]
min_m min_q
using CptnModNestCatch2.hyps(4) by blast
} thus ?thesis by auto
qed
}thus ?thesis by auto
qed
ultimately show ?thesis by auto
qed
next
case (CptnModNestCatch3 n \<Gamma> P s xs s' Q ys zs ) then obtain min_p where
min_p:"(min_p, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call \<and>
(\<forall>m<min_p. (m, \<Gamma>, (P, s) # xs) \<notin> cptn_mod_nest_call)"
by auto
from CptnModNestCatch3(6) CptnModNestCatch3(4) obtain min_q where
min_q:"(min_q, \<Gamma>, (Q, snd (last ((P, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and>
(\<forall>m<min_q. (m, \<Gamma>, (Q, snd (last ((P, s) # xs))) # ys) \<notin> cptn_mod_nest_call)"
by auto
thus ?case
proof(cases "min_p\<ge>min_q")
case True
then have "(min_p, \<Gamma>, (Q, snd (last ((P, s) # xs))) # ys) \<in> cptn_mod_nest_call"
using min_q using cptn_mod_nest_mono by blast
then have "(min_p, \<Gamma>, (Catch P Q, s) # zs) \<in> cptn_mod_nest_call"
using conjunct1[OF min_p] cptn_mod_nest_call.CptnModNestCatch3[of min_p \<Gamma> P s xs s' Q ys zs]
CptnModNestCatch3(4) CptnModNestCatch3(3) CptnModNestCatch3(7)
by fastforce
also have "\<forall>m<min_p. (m, \<Gamma>,(Catch P Q, s) # zs) \<notin> cptn_mod_nest_call"
proof -
{fix m
assume min_m:"m<min_p"
then have "(m, \<Gamma>,(Catch P Q, s) # zs) \<notin> cptn_mod_nest_call"
proof -
{assume ass:"(m, \<Gamma>, (Catch P Q, s) # zs) \<in> cptn_mod_nest_call"
then obtain xs' ns' ns'' where
m_cptn:"(m, \<Gamma>, (P, s) # xs') \<in> cptn_mod_nest_call \<and>
catch_cond_nest zs Q xs' P ( s) ns'' ns' \<Gamma> m"
using
div_catch_nest[of m \<Gamma> "(Catch P Q, s) # zs"]
by fastforce
then have "catch_cond_nest zs Q xs' P ( s) ns'' ns' \<Gamma> m" by auto
then have "xs=xs'"
using Catch_P_Ends_Normal[OF CptnModNestCatch3(7) CptnModNestCatch3(3) ]
by fastforce
then have "(m, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call"
using m_cptn by auto
then have False using min_p min_m by fastforce
} thus ?thesis by auto
qed
}thus ?thesis by auto
qed
ultimately show ?thesis by auto
next
case False
then have "(min_q, \<Gamma>, (P, s) # xs) \<in> cptn_mod_nest_call"
using min_p cptn_mod_nest_mono by force
then have "(min_q, \<Gamma>, (Catch P Q, s) # zs) \<in> cptn_mod_nest_call"
using conjunct1[OF min_q] cptn_mod_nest_call.CptnModNestCatch3[of min_q \<Gamma> P s xs s' ]
CptnModNestCatch3(4) CptnModNestCatch3(3) CptnModNestCatch3(7)
by blast
also have "\<forall>m<min_q. (m, \<Gamma>,(Catch P Q, s) # zs) \<notin> cptn_mod_nest_call"
proof -
{fix m
assume min_m:"m<min_q"
then have "(m, \<Gamma>,(Catch P Q, s) # zs) \<notin> cptn_mod_nest_call"
proof -
{assume ass:"(m, \<Gamma>, (Catch P Q, s) # zs) \<in> cptn_mod_nest_call"
then obtain xs' ns' ns'' where
m_cptn:"(m, \<Gamma>, (P, s) # xs') \<in> cptn_mod_nest_call \<and>
catch_cond_nest zs Q xs' P ( s) ns'' ns' \<Gamma> m"
using
div_catch_nest[of m \<Gamma> "(Catch P Q, s) # zs"]
by fastforce
then have "catch_cond_nest zs Q xs' P ( s) ns'' ns' \<Gamma> m" by auto
then have ?thesis
using Catch_P_Ends_Normal[OF CptnModNestCatch3(7) CptnModNestCatch3(3) ]
min_m min_q
by (metis last_length)
} thus ?thesis by auto
qed
}thus ?thesis by auto
qed
ultimately show ?thesis by auto
qed
qed
lemma elim_cptn_mod_min_nest_call:
assumes a0:"min_call n \<Gamma> cfg" and
a1:"cfg = (P,s)#(Q,t)#cfg1" and
a2:"(\<forall>f. redex P \<noteq> Call f) \<or>
SmallStepCon.redex P = LanguageCon.com.Call fn \<and> \<Gamma> fn = None \<or>
(redex P = Call fn \<and> P=Q)"
shows "min_call n \<Gamma> ((Q,t)#cfg1)"
proof -
have a0: "(n,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and
a0': "(\<forall>m<n. (m, \<Gamma>, cfg) \<notin> cptn_mod_nest_call)"
using a0 unfolding min_call_def by auto
then have "(n,\<Gamma>,(Q,t)#cfg1) \<in> cptn_mod_nest_call"
using a0 a1 elim_cptn_mod_nest_call_n by blast
also have "(\<forall>m<n. (m, \<Gamma>, (Q,t)#cfg1) \<notin> cptn_mod_nest_call)"
proof-
{ assume "\<not>(\<forall>m<n. (m, \<Gamma>, (Q,t)#cfg1) \<notin> cptn_mod_nest_call)"
then obtain m where
asm0:"m<n" and
asm1:"(m, \<Gamma>, (Q,t)#cfg1) \<in> cptn_mod_nest_call"
by auto
have ce:"\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>c\<^sub>e (Q, t)"
using a0 a1 cptn_elim_cases(2) cptn_eq_cptn_mod_nest by blast
then have "\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (Q, t) \<or> \<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Q, toSeq t)"
using step_ce_dest by blast
then have "(m, \<Gamma>, cfg) \<in> cptn_mod_nest_call"
proof
assume "\<Gamma>\<turnstile>\<^sub>c (P, s) \<rightarrow>\<^sub>e (Q, t)"
then show ?thesis
using a0 a1 a2 cptn_mod_nest_call.CptnModNestEnv
by (metis asm1 env_c_c')
next
assume a00:"\<Gamma>\<turnstile>\<^sub>c (P, toSeq s) \<rightarrow> (Q, toSeq t)"
moreover have "P\<noteq>Q" using mod_env_not_component calculation
by fastforce
moreover have norm:"snd s = snd t"
using calculation ce step_dest1 by blast
then show ?thesis using mod_env_not_component a2 not_func_redex_cptn_mod_nest_n'[OF _ _ a00 norm]
by (simp add: a1 asm1 calculation(2))
qed
then have False using a0' asm0 by auto
} thus ?thesis by auto qed
ultimately show ?thesis unfolding min_call_def by auto
qed
lemma elim_call_cptn_mod_min_nest_call:
assumes a0:"min_call n \<Gamma> cfg" and
a1:"cfg = (P,s)#(Q,t)#cfg1" and
a2:"P = Call f \<and>
\<Gamma> f = Some Q \<and> P\<noteq>Q"
shows "min_call (n-1) \<Gamma> ((Q,t)#cfg1)"
proof -
have a0: "(n,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and
a0': "(\<forall>m<n. (m, \<Gamma>, cfg) \<notin> cptn_mod_nest_call)"
using a0 a2 unfolding min_call_def by auto
then have "(n-1,\<Gamma>,(Q,t)#cfg1) \<in> cptn_mod_nest_call"
using a1 a2 elim_cptn_mod_nest_call_n_dec[of n \<Gamma> f s cfg1 Q]
by (metis (no_types, lifting) SmallStepCon.redex.simps(7) call_f_step_ce_not_s_eq_t_env_step
cptn_elim_cases(2) cptn_if_cptn_mod cptn_mod_nest_cptn_mod
elim_cptn_mod_nest_call_n_dec1 not_eq_not_env)
moreover have "(\<forall>m<n - 1. (m, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call)"
proof -
{ fix m
assume "m<n-1"
then have "(m, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call"
by (smt SmallStepCon.redex.simps(7) Suc_eq_plus1 a0 a0' a1 a2
call_f_step_ce_not_s_eq_t_env_step cptn_elim_cases_pair(2) cptn_if_cptn_mod
cptn_mod_nest_call.CptnModNestCall cptn_mod_nest_cptn_mod
less_diff_conv not_eq_not_env)
}
thus ?thesis by auto
qed
ultimately show ?thesis unfolding min_call_def by auto
qed
lemma term_all_skip:
assumes a0:"(\<Gamma>,cfg)\<in>cptn" and
a1:"cfg = (c,s)#cfg1" and a1':"(c=Skip \<or> c=Throw \<or> c=Stuck \<or> (\<exists>f. c = Fault f))"
shows "\<forall>i<length cfg. fst(cfg!i) = c"
using a0 a1 a1'
proof(induct cfg1 arbitrary:cfg s)
case Nil thus ?case by auto
next
case (Cons x xs)
have cptn:"(\<Gamma>,x#xs)\<in>cptn"
using Cons.prems(1) Cons.prems(2) cptn_dest_pair by blast
have "\<Gamma>\<turnstile>\<^sub>c(c,s) \<rightarrow>\<^sub>e x" using cptn_elim_cases_pair(2)[OF Cons(2)[simplified Cons(3)]] a1'
by (metis SmallStepCon.final_def SmallStepCon.no_step_final fst_conv step_ce_not_step_e_step_c)
then obtain s' where x:"x = (c,s')"
by (metis env_c_c' prod.exhaust_sel)
moreover have cptn:"(\<Gamma>,x#xs)\<in>cptn"
using Cons.prems(1) Cons.prems(2) cptn_dest_pair by blast
moreover have
xs:"x # xs = (c, s') # xs" using x by auto
ultimately show ?case using Cons(1)[OF cptn xs] Cons(3)
using diff_Suc_1 fstI length_Cons less_Suc_eq_0_disj nth_Cons' a1' by auto
qed
lemma term_min_nested_call_0:
assumes a0:"min_call n \<Gamma> cfg" and
a1:"cfg = (c,s)#cfg1" and a1':"(c=Skip \<or> c=Throw \<or> c=Stuck \<or> (\<exists>f. c = Fault f))"
shows "n=0"
proof -
have asm0:"(n, \<Gamma>, cfg) \<in> cptn_mod_nest_call" and
asm1:"(\<forall>m<n. (m, \<Gamma>, cfg) \<notin> cptn_mod_nest_call)"
using a0 unfolding min_call_def by auto
show ?thesis using a1 asm0 asm1
proof (induct cfg1 arbitrary: cfg s n)
case Nil thus ?case
using cptn_mod_nest_call.CptnModNestOne neq0_conv by blast
next
case (Cons x xs)
then obtain Q s' where cfg:"cfg = (c, s) # (Q,s') # xs"
using prod.exhaust_sel by blast
then have min_call:"min_call n \<Gamma> cfg" using Cons unfolding min_call_def by auto
then have "(\<forall>f. SmallStepCon.redex c \<noteq> LanguageCon.com.Call f)" using a1' by auto
then have "min_call n \<Gamma> ((Q, s')#xs)"
using elim_cptn_mod_min_nest_call[OF min_call cfg] cfg
by simp
thus ?case using Cons cfg unfolding min_call_def
proof -
assume a1: "(n, \<Gamma>, (Q, s') # xs) \<in> cptn_mod_nest_call \<and>
(\<forall>m<n. (m, \<Gamma>, (Q, s') # xs) \<notin> cptn_mod_nest_call)"
have "c = Q" using term_all_skip
proof -
have "Suc 0 < length ((c, s) # (Q, s') # xs)"
by auto
then have "fst (((c, s) # (Q, s') # xs) ! Suc 0) = c"
using Cons.prems(2) a1' cfg cptn_if_cptn_mod cptn_mod_nest_cptn_mod term_all_skip by blast
then show ?thesis
by simp
qed
then show ?thesis
using a1 Cons.hyps by blast
qed
qed
qed
text \<open> function to calculate that there is not any subsequent where the nested call is n \<close>
definition cond_seq_1
where
"cond_seq_1 n \<Gamma> c1 s xs c2 zs ys \<equiv> ((n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<and>
fst(last((c1,s)#xs)) = Skip \<and>
(n,\<Gamma>,((c2, snd(last ((c1, s)#xs)))#ys)) \<in> cptn_mod_nest_call \<and>
zs=(map (lift c2) xs)@((c2, snd(last ((c1, s)#xs)))#ys))"
definition cond_seq_2
where
"cond_seq_2 n \<Gamma> c1 s xs c2 zs ys s' s'' \<equiv> s = s'' \<and>
(n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<and>
snd(last ((c1, s)#xs)) = s' \<and>
(\<exists>c. fst(last ((c1, s)#xs)) = c \<and> (c=Throw \<or> c=Stuck \<or> (\<exists>f. c = Fault f)) \<and>
(n,\<Gamma>,(c, s')#ys) \<in> cptn_mod_nest_call \<and>
zs=(map (lift c2) xs)@((c, s')#ys))"
definition cond_catch_1
where
"cond_catch_1 n \<Gamma> c1 s xs c2 zs ys \<equiv> ((n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<and>
(\<exists>c. fst(last((c1,s)#xs)) = c \<and> (c=Skip \<or> c=Stuck \<or> (\<exists>f. c = Fault f)) \<and>
(n,\<Gamma>,((c, snd(last ((c1, s)#xs)))#ys)) \<in> cptn_mod_nest_call \<and>
zs=(map (lift_catch c2) xs)@((c, snd(last ((c1, s)#xs)))#ys)))"
definition cond_catch_2
where
"cond_catch_2 n \<Gamma> c1 s xs c2 zs ys s' s'' \<equiv> s= s'' \<and>
(n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<and>
fst(last ((c1, s)#xs)) = Throw \<and>
snd(last ((c1, s)#xs)) = s' \<and>
(n,\<Gamma>,(c2, s')#ys) \<in> cptn_mod_nest_call \<and>
zs=(map (lift_catch c2) xs)@((c2, s')#ys)"
(* fun biggest_nest_call :: "('s,'p,'f,'e)com \<Rightarrow>
('s,'f) xstate \<Rightarrow>
(('s,'p,'f,'e) config) list \<Rightarrow>
('s,'p,'f,'e) body \<Rightarrow>
nat \<Rightarrow> bool"
where
"biggest_nest_call (Seq c1 c2) s zs \<Gamma> n =
(if (\<exists>xs. ((min_call n \<Gamma> ((c1,s)#xs)) \<and> (zs=map (lift c2) xs))) then
let xsa = (SOME xs. (min_call n \<Gamma> ((c1,s)#xs)) \<and> (zs=map (lift c2) xs)) in
(biggest_nest_call c1 s xsa \<Gamma> n)
else if (\<exists>xs ys. cond_seq_1 n \<Gamma> c1 s xs c2 zs ys) then
let xsa = (SOME xs. \<exists>ys. cond_seq_1 n \<Gamma> c1 s xs c2 zs ys);
ysa = (SOME ys. cond_seq_1 n \<Gamma> c1 s xsa c2 zs ys) in
if (min_call n \<Gamma> ((c2, snd(last ((c1, s)#xsa)))#ysa)) then True
else (biggest_nest_call c1 s xsa \<Gamma> n)
else let xsa = (SOME xs. \<exists>ys s' s''. cond_seq_2 n \<Gamma> c1 s xs c2 zs ys s' s'') in
(biggest_nest_call c1 s xsa \<Gamma> n))"
|"biggest_nest_call (Catch c1 c2) s zs \<Gamma> n =
(if (\<exists>xs. ((min_call n \<Gamma> ((c1,s)#xs)) \<and> (zs=map (lift_catch c2) xs))) then
let xsa = (SOME xs. (min_call n \<Gamma> ((c1,s)#xs)) \<and> (zs=map (lift_catch c2) xs)) in
(biggest_nest_call c1 s xsa \<Gamma> n)
else if (\<exists>xs ys. cond_catch_1 n \<Gamma> c1 s xs c2 zs ys) then
let xsa = (SOME xs. \<exists>ys. cond_catch_1 n \<Gamma> c1 s xs c2 zs ys) in
(biggest_nest_call c1 s xsa \<Gamma> n)
else let xsa = (SOME xs. \<exists>ys s' s''. cond_catch_2 n \<Gamma> c1 s xs c2 zs ys s' s'');
ysa = (SOME ys. \<exists>s' s''. cond_catch_2 n \<Gamma> c1 s xsa c2 zs ys s' s'') in
if (min_call n \<Gamma> ((c2, snd(last ((c1, s)#xsa)))#ysa)) then True
else (biggest_nest_call c1 s xsa \<Gamma> n))"
|"biggest_nest_call _ _ _ _ _ = False"
*)
lemma min_call_less_eq_n:
"(n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<Longrightarrow>
(n,\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call \<Longrightarrow>
min_call p \<Gamma> ((c1, s)#xs) \<and> min_call q \<Gamma> ((c2, snd(last ((c1, s)#xs)))#ys) \<Longrightarrow>
p\<le>n \<and> q\<le>n"
unfolding min_call_def
using le_less_linear by blast
lemma min_call_seq_less_eq_n':
"(n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<Longrightarrow>
min_call p \<Gamma> ((c1, s)#xs) \<Longrightarrow>
p\<le>n"
unfolding min_call_def
using le_less_linear by blast
lemma min_call_seq2:
"min_call n \<Gamma> ((Seq c1 c2,s)#zs) \<Longrightarrow>
(n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<Longrightarrow>
fst(last ((c1, s)#xs)) = Skip \<Longrightarrow>
(n,\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call \<Longrightarrow>
zs=(map (lift c2) xs)@((c2, snd(last ((c1, s)#xs)))#ys) \<Longrightarrow>
min_call n \<Gamma> ((c1, s)#xs) \<or> min_call n \<Gamma> ((c2, snd(last ((c1, s)#xs)))#ys)
"
proof -
assume a0:"min_call n \<Gamma> ((Seq c1 c2,s)#zs)" and
a1:"(n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call" and
a2:"fst(last ((c1, s)#xs)) = Skip" and
a3:"(n,\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call" and
a4:"zs=(map (lift c2) xs)@((c2, snd(last ((c1, s)#xs)))#ys)"
then obtain p q where min_calls:
"min_call p \<Gamma> ((c1, s)#xs) \<and> min_call q \<Gamma> ((c2, snd(last ((c1, s)#xs)))#ys)"
using a1 a3 minimum_nest_call by blast
then have p_q:"p\<le>n \<and> q\<le>n" using a0 a1 a3 a4 min_call_less_eq_n by blast
{
assume ass0:"p<n \<and> q <n"
then have "(p,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call" and
"(q,\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call"
using min_calls unfolding min_call_def by auto
then have ?thesis
proof (cases "p\<le>q")
case True
then have q_cptn_c1:"(q, \<Gamma>, (c1, s) # xs) \<in> cptn_mod_nest_call"
using cptn_mod_nest_mono min_calls unfolding min_call_def
by blast
have q_cptn_c2:"(q, \<Gamma>, (c2, snd (last ((c1, s) # xs))) # ys) \<in> cptn_mod_nest_call"
using min_calls unfolding min_call_def by auto
then have "(q,\<Gamma>,((Seq c1 c2,s)#zs)) \<in>cptn_mod_nest_call"
using True min_calls a2 a4 CptnModNestSeq2[OF q_cptn_c1 a2 q_cptn_c2 a4]
by auto
thus ?thesis using ass0 a0 unfolding min_call_def by auto
next
case False
then have q_cptn_c1:"(p, \<Gamma>, (c1, s) # xs) \<in> cptn_mod_nest_call"
using min_calls unfolding min_call_def
by blast
have q_cptn_c2:"(p, \<Gamma>, (c2, snd (last ((c1, s) # xs))) # ys) \<in> cptn_mod_nest_call"
using min_calls False unfolding min_call_def
by (metis (no_types, lifting) cptn_mod_nest_mono2 not_less)
then have "(p,\<Gamma>,((Seq c1 c2,s)#zs)) \<in>cptn_mod_nest_call"
using False min_calls a2 a4 CptnModNestSeq2[OF q_cptn_c1 a2 q_cptn_c2 a4]
by auto
thus ?thesis using ass0 a0 unfolding min_call_def by auto
qed
}note l=this
{
assume ass0:"p\<ge>n \<or> q \<ge>n"
then have ?thesis using p_q min_calls by fastforce
}
thus ?thesis using l by fastforce
qed
lemma min_call_seq3:
"min_call n \<Gamma> ((Seq c1 c2,s)#zs) \<Longrightarrow>
s= s'' \<Longrightarrow>
(n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<Longrightarrow>
fst(last ((c1, s)#xs)) = c \<Longrightarrow> (c=Throw \<or> c=Stuck \<or> (\<exists>f. c = Fault f)) \<Longrightarrow>
snd(last ((c1, s)#xs)) = s' \<Longrightarrow>
(n,\<Gamma>,(c, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call \<Longrightarrow>
zs=(map (lift c2) xs)@((c, snd(last ((c1, s)#xs)))#ys) \<Longrightarrow>
min_call n \<Gamma> ((c1, s)#xs)
"
proof -
assume a0:"min_call n \<Gamma> ((Seq c1 c2,s)#zs)" and
a0':"s= s''" and
a1:"(n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call" and
a2:"fst(last ((c1, s)#xs)) = c" and a2'':"(c=Throw \<or> c=Stuck \<or> (\<exists>f. c = Fault f))" and
a2':"snd(last ((c1, s)#xs)) = s'" and
a3:"(n,\<Gamma>,(c, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call" and
a4:"zs=(map (lift c2) xs)@((c, snd(last ((c1, s)#xs)))#ys)"
then obtain p where min_calls:
"min_call p \<Gamma> ((c1, s)#xs) \<and> min_call 0 \<Gamma> ((c, snd(last ((c1, s)#xs)))#ys)"
using a1 a3 minimum_nest_call term_min_nested_call_0 a2' by metis
then have p_q:"p\<le>n \<and> 0\<le>n" using a0 a1 a3 a4 min_call_less_eq_n by blast
{
assume ass0:"p<n \<and> 0 <n"
then have "(p,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call" and
"(0,\<Gamma>,(c, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call"
using min_calls unfolding min_call_def by auto
then have ?thesis
proof (cases "p\<le>0")
case True
then have q_cptn_c1:"(0, \<Gamma>, (c1, s'') # xs) \<in> cptn_mod_nest_call"
using cptn_mod_nest_mono min_calls a0' unfolding min_call_def
by blast
have q_cptn_c2:"(0, \<Gamma>, (c, snd (last ((c1, s) # xs))) # ys) \<in> cptn_mod_nest_call"
using min_calls unfolding min_call_def by auto
then have "(0,\<Gamma>,((Seq c1 c2,s)#zs)) \<in>cptn_mod_nest_call"
using True min_calls a2 a4 a2' a0' a2'' CptnModNestSeq3[OF q_cptn_c1 _ ]
by blast
thus ?thesis using ass0 a0 unfolding min_call_def by auto
next
case False
then have q_cptn_c1:"(p, \<Gamma>, (c1, s'') # xs) \<in> cptn_mod_nest_call"
using min_calls a0' unfolding min_call_def
by blast
have q_cptn_c2:"(p, \<Gamma>, (c, snd (last ((c1, s) # xs))) # ys) \<in> cptn_mod_nest_call"
using min_calls False unfolding min_call_def
by (metis (no_types, lifting) cptn_mod_nest_mono2 not_less)
then have "(p,\<Gamma>,((Seq c1 c2,s)#zs)) \<in>cptn_mod_nest_call"
using False min_calls a2 a4 a0' a2' a2'' CptnModNestSeq3[OF q_cptn_c1]
by blast
thus ?thesis using ass0 a0 unfolding min_call_def by auto
qed
}note l=this
{
assume ass0:"p\<ge>n \<or> 0 \<ge>n"
then have ?thesis using p_q min_calls by fastforce
}
thus ?thesis using l by fastforce
qed
lemma min_call_catch2:
"min_call n \<Gamma> ((Catch c1 c2,s)#zs) \<Longrightarrow>
(n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<Longrightarrow>
fst(last ((c1, s)#xs)) = c \<Longrightarrow> (c=Skip \<or> c=Stuck \<or> (\<exists>f. c = Fault f)) \<Longrightarrow>
(n,\<Gamma>,(c, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call \<Longrightarrow>
zs=(map (lift_catch c2) xs)@((c, snd(last ((c1, s)#xs)))#ys) \<Longrightarrow>
min_call n \<Gamma> ((c1, s)#xs)
"
proof -
assume a0:"min_call n \<Gamma> ((Catch c1 c2,s)#zs)" and
a1:"(n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call" and
a2:"fst(last ((c1, s)#xs)) = c" and a2':"(c=Skip \<or> c=Stuck \<or> (\<exists>f. c = Fault f))" and
a3:"(n,\<Gamma>,(c, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call" and
a4:"zs=(map (lift_catch c2) xs)@((c, snd(last ((c1, s)#xs)))#ys)"
then obtain p where min_calls:
"min_call p \<Gamma> ((c1, s)#xs) \<and> min_call 0 \<Gamma> ((c, snd(last ((c1, s)#xs)))#ys)"
using a1 a3 minimum_nest_call term_min_nested_call_0 by metis
then have p_q:"p\<le>n \<and> 0\<le>n" using a0 a1 a3 a4 min_call_less_eq_n by blast
{
assume ass0:"p<n \<and> 0 <n"
then have "(p,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call" and
"(0,\<Gamma>,(c, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call"
using min_calls unfolding min_call_def by auto
then have ?thesis
proof (cases "p\<le>0")
case True
then have q_cptn_c1:"(0, \<Gamma>, (c1, s) # xs) \<in> cptn_mod_nest_call"
using cptn_mod_nest_mono min_calls unfolding min_call_def
by blast
have q_cptn_c2:"(0, \<Gamma>, (c, snd (last ((c1, s) # xs))) # ys) \<in> cptn_mod_nest_call"
using min_calls unfolding min_call_def by auto
then have "(0,\<Gamma>,((Catch c1 c2,s)#zs)) \<in>cptn_mod_nest_call"
using True min_calls a2 a4 a2' CptnModNestCatch2[OF q_cptn_c1 ]
by blast
thus ?thesis using ass0 a0 unfolding min_call_def by auto
next
case False
then have q_cptn_c1:"(p, \<Gamma>, (c1, s) # xs) \<in> cptn_mod_nest_call"
using min_calls unfolding min_call_def
by blast
have q_cptn_c2:"(p, \<Gamma>, (c, snd (last ((c1, s) # xs))) # ys) \<in> cptn_mod_nest_call"
using min_calls False unfolding min_call_def
by (metis (no_types, lifting) cptn_mod_nest_mono2 not_less)
then have "(p,\<Gamma>,((Catch c1 c2,s)#zs)) \<in>cptn_mod_nest_call"
using False min_calls a2 a4 a2' CptnModNestCatch2[OF q_cptn_c1]
by blast
thus ?thesis using ass0 a0 unfolding min_call_def by auto
qed
}note l=this
{
assume ass0:"p\<ge>n \<or> 0 \<ge>n"
then have ?thesis using p_q min_calls by fastforce
}
thus ?thesis using l by fastforce
qed
lemma min_call_catch_less_eq_n:
"(n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<Longrightarrow>
(n,\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call \<Longrightarrow>
min_call p \<Gamma> ((c1, s)#xs) \<and> min_call q \<Gamma> ((c2, snd(last ((c1, s)#xs)))#ys) \<Longrightarrow>
p\<le>n \<and> q\<le>n"
unfolding min_call_def
using le_less_linear by blast
lemma min_call_catch3:
"min_call n \<Gamma> ((Catch c1 c2, s)#zs) \<Longrightarrow>
(n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call \<Longrightarrow>
fst(last ((c1, s)#xs)) = Throw \<Longrightarrow>
snd(last ((c1, s)#xs)) = s' \<Longrightarrow>
(n,\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call \<Longrightarrow>
zs=(map (lift_catch c2) xs)@((c2, snd(last ((c1, s)#xs)))#ys) \<Longrightarrow>
min_call n \<Gamma> ((c1, s)#xs) \<or> min_call n \<Gamma> ((c2, snd(last ((c1, s)#xs)))#ys)
"
proof -
assume a0:"min_call n \<Gamma> ((Catch c1 c2, s)#zs)" and
a1:"(n,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call" and
a2:"fst(last ((c1, s)#xs)) = Throw" and
a2':"snd(last ((c1, s)#xs)) = s'" and
a3:"(n,\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call" and
a4:"zs=(map (lift_catch c2) xs)@((c2, snd(last ((c1, s)#xs)))#ys)"
then obtain p q where min_calls:
"min_call p \<Gamma> ((c1, s)#xs) \<and> min_call q \<Gamma> ((c2, snd(last ((c1, s)#xs)))#ys)"
using a1 a3 minimum_nest_call by blast
then have p_q:"p\<le>n \<and> q\<le>n"
using a1 a2 a2' a3 a4 min_call_less_eq_n by blast
{
assume ass0:"p<n \<and> q <n"
then have "(p,\<Gamma>, (c1, s)#xs) \<in> cptn_mod_nest_call" and
"(q,\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \<in> cptn_mod_nest_call"
using min_calls unfolding min_call_def by auto
then have ?thesis
proof (cases "p\<le>q")
case True
then have q_cptn_c1:"(q, \<Gamma>, (c1, s) # xs) \<in> cptn_mod_nest_call"
using cptn_mod_nest_mono min_calls unfolding min_call_def
by blast
have q_cptn_c2:"(q, \<Gamma>, (c2, snd (last ((c1, s) # xs))) # ys) \<in> cptn_mod_nest_call"
using min_calls unfolding min_call_def by auto
then have "(q,\<Gamma>,((Catch c1 c2, s)#zs)) \<in>cptn_mod_nest_call"
using True min_calls a2 a2' a4 CptnModNestCatch3[OF q_cptn_c1 a2 a2' q_cptn_c2 a4]
by auto
thus ?thesis using ass0 a0 unfolding min_call_def by auto
next
case False
then have q_cptn_c1:"(p, \<Gamma>, (c1, s) # xs) \<in> cptn_mod_nest_call"
using min_calls unfolding min_call_def
by blast
have q_cptn_c2:"(p, \<Gamma>, (c2, snd (last ((c1, s) # xs))) # ys) \<in> cptn_mod_nest_call"
using min_calls False unfolding min_call_def
by (metis (no_types, lifting) cptn_mod_nest_mono2 not_less)
then have "(p,\<Gamma>,((Catch c1 c2, s)#zs)) \<in>cptn_mod_nest_call"
using False min_calls a2 a4 CptnModNestCatch3[OF q_cptn_c1 a2 a2' q_cptn_c2 a4]
by auto
thus ?thesis using ass0 a0 unfolding min_call_def by auto
qed
}note l=this
{
assume ass0:"p\<ge>n \<or> q \<ge>n"
then have ?thesis using p_q min_calls by fastforce
}
thus ?thesis using l by fastforce
qed
lemma min_call_seq_c1_not_finish:
"min_call n \<Gamma> cfg \<Longrightarrow>
cfg = (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1 \<Longrightarrow>
(n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call \<Longrightarrow>
(Q, t) # cfg1 = map (lift P1) xs \<Longrightarrow>
min_call n \<Gamma> ((P0, s)#xs)
"
proof -
assume a0:"min_call n \<Gamma> cfg" and
a1:" cfg = (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1" and
a2:"(n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call" and
a3:"(Q, t) # cfg1 = map (lift P1) xs"
then have "(n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call" using a2 by auto
moreover have "\<forall>m<n. (m, \<Gamma>,(P0, s)#xs) \<notin> cptn_mod_nest_call"
proof-
{fix m
assume ass:"m<n"
{ assume ass1:"(m, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call"
then have "(m,\<Gamma>,cfg) \<in> cptn_mod_nest_call"
using a1 a3 CptnModNestSeq1[OF ass1] by auto
then have False using ass a0 unfolding min_call_def by auto
}
then have "(m, \<Gamma>, (P0, s) # xs) \<notin> cptn_mod_nest_call" by auto
} then show ?thesis by auto
qed
ultimately show ?thesis unfolding min_call_def by auto
qed
lemma min_call_seq_not_finish:
" min_call n \<Gamma> ((P0, s)#xs) \<Longrightarrow>
cfg = (LanguageCon.com.Seq P0 P1, s) # cfg1 \<Longrightarrow>
cfg1 = map (lift P1) xs \<Longrightarrow>
min_call n \<Gamma> cfg
"
proof -
assume a0:"min_call n \<Gamma> ((P0, s)#xs)" and
a1:" cfg = (LanguageCon.com.Seq P0 P1, s) # cfg1" and
a2:" cfg1 = map (lift P1) xs"
then have "(n, \<Gamma>,cfg) \<in> cptn_mod_nest_call"
using a0 a1 a2 CptnModNestSeq1[of n \<Gamma> P0 s xs "cfg1" P1] unfolding min_call_def
by auto
moreover have "\<forall>m<n. (m, \<Gamma>,cfg) \<notin> cptn_mod_nest_call"
proof-
{fix m
assume ass:"m<n"
{ assume ass1:"(m, \<Gamma>, cfg) \<in> cptn_mod_nest_call"
then have "(m,\<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call"
using a1 a2 by (metis (no_types) Seq_P_Not_finish div_seq_nest)
then have False using ass a0 unfolding min_call_def by auto
}
then have "(m, \<Gamma>, cfg) \<notin> cptn_mod_nest_call" by auto
} then show ?thesis by auto
qed
ultimately show ?thesis unfolding min_call_def by auto
qed
lemma min_call_catch_c1_not_finish:
"min_call n \<Gamma> cfg \<Longrightarrow>
cfg = (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1 \<Longrightarrow>
(n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call \<Longrightarrow>
(Q, t) # cfg1 = map (lift_catch P1) xs \<Longrightarrow>
min_call n \<Gamma> ((P0, s)#xs)
"
proof -
assume a0:"min_call n \<Gamma> cfg" and
a1:" cfg = (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1" and
a2:"(n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call" and
a3:"(Q, t) # cfg1 = map (lift_catch P1) xs"
then have "(n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call" using a2 by auto
moreover have "\<forall>m<n. (m, \<Gamma>,(P0, s)#xs) \<notin> cptn_mod_nest_call"
proof-
{fix m
assume ass:"m<n"
{ assume ass1:"(m, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call"
then have "(m,\<Gamma>,cfg) \<in> cptn_mod_nest_call"
using a1 a3 CptnModNestCatch1[OF ass1] by auto
then have False using ass a0 unfolding min_call_def by auto
}
then have "(m, \<Gamma>, (P0, s) # xs) \<notin> cptn_mod_nest_call" by auto
} then show ?thesis by auto
qed
ultimately show ?thesis unfolding min_call_def by auto
qed
lemma min_call_catch_not_finish:
" min_call n \<Gamma> ((P0, s)#xs) \<Longrightarrow>
cfg = (LanguageCon.com.Catch P0 P1, s) # cfg1 \<Longrightarrow>
cfg1 = map (lift_catch P1) xs \<Longrightarrow>
min_call n \<Gamma> cfg
"
proof -
assume a0:"min_call n \<Gamma> ((P0, s)#xs)" and
a1:" cfg = (Catch P0 P1, s) # cfg1" and
a2:" cfg1 = map (lift_catch P1) xs"
then have "(n, \<Gamma>,cfg) \<in> cptn_mod_nest_call"
using a0 a1 a2 CptnModNestCatch1[of n \<Gamma> P0 s xs "cfg1" P1] unfolding min_call_def
by auto
moreover have "\<forall>m<n. (m, \<Gamma>,cfg) \<notin> cptn_mod_nest_call"
proof-
{fix m
assume ass:"m<n"
{ assume ass1:"(m, \<Gamma>, cfg) \<in> cptn_mod_nest_call"
then have "(m,\<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call"
using a1 a2 by (metis (no_types) Catch_P_Not_finish div_catch_nest)
then have False using ass a0 unfolding min_call_def by auto
}
then have "(m, \<Gamma>, cfg) \<notin> cptn_mod_nest_call" by auto
} then show ?thesis by auto
qed
ultimately show ?thesis unfolding min_call_def by auto
qed
lemma seq_xs_no_empty: assumes
seq:"seq_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \<Gamma> n" and
cfg:"cfg = (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1" and
a0:"SmallStepCon.redex (LanguageCon.com.Seq P0 P1) = LanguageCon.com.Call f"
shows"\<exists>Q' xs'. Q=Seq Q' P1 \<and> xs=(Q',t)#xs'"
using seq
unfolding lift_def seq_cond_nest_def
proof
assume "(Q, t) # cfg1 = map (\<lambda>(P, s). (LanguageCon.com.Seq P P1, s)) xs"
thus ?thesis by auto
next
assume "fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \<and>
(\<exists>ys. (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 =
map (\<lambda>(P, s). (LanguageCon.com.Seq P P1, s)) xs @
(P1, snd (((P0, s) # xs) ! length xs)) # ys) \<or>
(\<exists>c. fst (((P0, s) # xs) ! length xs) = c \<and> (c = Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
snd (last ((P0, s) # xs)) = s' \<and>
s = s'' \<and> (\<exists>ys. (n, \<Gamma>, (c, s') # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (\<lambda>(P, s). (Seq P P1, s)) xs @(c, s') # ys))"
thus ?thesis
proof
assume ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \<and>
(\<exists>ys. (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 =
map (\<lambda>(P, s). (LanguageCon.com.Seq P P1, s)) xs @
(P1, snd (((P0, s) # xs) ! length xs)) # ys)"
show ?thesis
proof (cases xs)
case Nil thus ?thesis using cfg a0 ass by auto
next
case (Cons xa xsa)
then obtain a b where xa:"xa = (a,b)"
using prod.exhaust_sel by blast
obtain pps where
"(Q, t) = (Seq a P1, b) \<and>
cfg1 = map (\<lambda>(c, y). (Seq c P1, y)) xsa @
(P1, snd (((P0, s) # xs) ! length xs)) # pps"
using ass local.Cons xa by moura
then show ?thesis
using local.Cons xa by auto
qed
next
assume ass:"\<exists>c. fst (((P0, s) # xs) ! length xs) = c \<and> (c = Throw \<or> (\<exists>f. c = Fault f) \<or> c = Stuck) \<and>
snd (last ((P0, s) # xs)) = s' \<and>
s = s'' \<and> (\<exists>ys. (n, \<Gamma>, (c, s') # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (\<lambda>(P, s). (Seq P P1, s)) xs @(c, s') # ys)"
thus ?thesis
proof (cases xs)
case Nil thus ?thesis using cfg a0 ass by auto
next
case (Cons xa xsa)
then obtain a b where xa:"xa = (a,b)" using prod.exhaust_sel Cons by blast
obtain c where c:" fst (((P0, s) # xs) ! length xs) = c \<and>
(c = LanguageCon.com.Throw \<or> (\<exists>f. c = com.Fault f) \<or> c = com.Stuck) \<and>
snd (last ((P0, s) # xs)) = s' \<and>
s = s'' \<and>
(\<exists>ys. (n, \<Gamma>, (c, s') # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (\<lambda>(P, s). (LanguageCon.com.Seq P P1, s)) xs @ (c, s') # ys)"
using ass by fastforce
then obtain pps where
"(Q, t) = (Seq a P1, b) \<and>
cfg1 = map (\<lambda>(c, y). (Seq c P1, y)) xsa @ (c, s') # pps"
using ass local.Cons xa by auto
then show ?thesis
using local.Cons xa by auto
qed
qed
qed
lemma catch_xs_no_empty: assumes
seq:"catch_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \<Gamma> n" and
cfg:"cfg = (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1" and
a0:"SmallStepCon.redex (LanguageCon.com.Catch P0 P1) = LanguageCon.com.Call f"
shows"\<exists>Q' xs'. Q=Catch Q' P1 \<and> xs=(Q',t)#xs'"
using seq
unfolding lift_catch_def catch_cond_nest_def
proof
assume "(Q, t) # cfg1 = map (\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs"
thus ?thesis by auto
next
assume "fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and>
snd (last ((P0, s) # xs)) = s' \<and>
s = s'' \<and>
(\<exists>ys. (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @
(P1, snd (((P0, s) # xs) ! length xs)) # ys) \<or>
(\<exists>c. fst (((P0, s) # xs) ! length xs) = c \<and> (c=Skip \<or> (\<exists>f. c = Fault f)\<or> c=Stuck) \<and>
(\<exists>ys. (n, \<Gamma>, (c, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 =
map (\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @
(c, snd (last ((P0, s) # xs))) # ys))"
thus ?thesis
proof
assume ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and>
snd (last ((P0, s) # xs)) = s' \<and>
s = s'' \<and>
(\<exists>ys. (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @
(P1, snd (((P0, s) # xs) ! length xs)) # ys)"
show ?thesis
proof (cases xs)
case Nil thus ?thesis using cfg a0 ass by auto
next
case (Cons xa xsa)
then obtain a b where xa:"xa = (a,b)"
using prod.exhaust_sel by blast
obtain pps where
"(Q, t) = (Catch a P1, b) \<and>
cfg1 = map (\<lambda>(c, y). (Catch c P1, y)) xsa @
(P1, snd (((P0, s) # xs) ! length xs)) # pps"
using ass local.Cons xa by moura
then show ?thesis
using local.Cons xa by auto
qed
next
assume ass:"(\<exists>c. fst (((P0, s) # xs) ! length xs) = c \<and> (c=Skip \<or> (\<exists>f. c = Fault f)\<or> c=Stuck) \<and>
(\<exists>ys. (n, \<Gamma>, (c, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 =
map (\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @
(c, snd (last ((P0, s) # xs))) # ys))"
thus ?thesis
proof (cases xs)
case Nil thus ?thesis using cfg a0 ass by auto
next
case (Cons xa xsa)
then obtain a b where xa:"xa = (a,b)"
using prod.exhaust_sel by blast
obtain c where "fst (((P0, s) # xs) ! length xs) = c \<and> (c=Skip \<or> (\<exists>f. c = Fault f)\<or> c=Stuck) \<and>
(\<exists>ys. (n, \<Gamma>, (c, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @
(c, snd (last ((P0, s) # xs))) # ys)"
using ass by auto
then obtain pps where
"(Q, t) = (Catch a P1, b) \<and>
cfg1 = map (\<lambda>(c, y). (Catch c P1, y)) xsa @ (c, snd (last ((P0, s) # xs))) # pps"
using ass local.Cons xa by auto
then show ?thesis
using local.Cons xa by auto
qed
qed
qed
lemma redex_call_cptn_mod_min_nest_call_gr_zero:
assumes a0:"min_call n \<Gamma> cfg" and
a1:"cfg = (P,s)#(Q,t)#cfg1" and
a2:"redex P = Call f \<and>
\<Gamma> f = Some bdy \<and> t=s" and
a3:"\<Gamma>\<turnstile>\<^sub>c(P,toSeq s)\<rightarrow>(Q,toSeq t)"
shows "n>0"
using a0 a1 a2 a3
proof (induct P arbitrary: Q cfg1 cfg s t n)
case (Call f1)
then show ?case using Call stepc_not_normal_elim_cases
elim_cptn_mod_nest_call_n_greater_zero unfolding min_call_def
by (metis SmallStepCon.redex.simps(7) option.distinct(1) )
next
case (Seq P0 P1)
then obtain xs s' s'' where
p0_cptn:"(n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call" and
seq:"seq_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \<Gamma> n"
using div_seq_nest[of n \<Gamma> cfg] unfolding min_call_def by blast
then obtain m where min:"min_call m \<Gamma> ((P0, s)#xs)"
using minimum_nest_call by blast
have xs':"\<exists>Q' xs'. Q=Seq Q' P1 \<and> xs=(Q',t)#xs'"
using seq Seq seq_xs_no_empty
by meson
then have "0<m" using Seq(1,5,6) min
using SmallStepCon.redex.simps(4) stepc_elim_cases_Seq_Seq by metis
thus ?case by (metis min min_call_def not_gr0 p0_cptn)
next
case (Catch P0 P1)
then obtain xs s' s'' where
p0_cptn:"(n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call" and
seq:"catch_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \<Gamma> n"
using div_catch_nest[of n \<Gamma> cfg] unfolding min_call_def by blast
then obtain m where min:"min_call m \<Gamma> ((P0, s)#xs)"
using minimum_nest_call by blast
obtain Q' xs' where xs':"Q=Catch Q' P1 \<and> xs=(Q',t)#xs'"
using catch_xs_no_empty[OF seq Catch(4)] Catch by blast
then have "0<m" using Catch(1,5,6) min
using stepc_elim_cases_Catch_Catch
by (metis SmallStepCon.redex.simps(11))
thus ?case by (metis min min_call_def not_gr0 p0_cptn)
qed(auto)
(* lemma elim_redex_call_cptn_mod_min_nest_call:
assumes a0:"min_call n \<Gamma> cfg" and
a1:"cfg = (P,s)#(Q,t)#cfg1" and
a2:"redex P = Call f \<and>
\<Gamma> f = Some bdy \<and> (\<exists>sa. s=Normal sa) \<and> t=s " and
a3:"biggest_nest_call P s ((Q,t)#cfg1) \<Gamma> n"
shows "min_call n \<Gamma> ((Q,t)#cfg1)"
using a0 a1 a2 a3
proof (induct P arbitrary: Q cfg1 cfg s t n)
case Cond thus ?case by fastforce
next
case (Seq P0 P1)
then obtain xs s' s'' where
p0_cptn:"(n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call" and
seq:"seq_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \<Gamma> n"
using div_seq_nest[of n \<Gamma> cfg] unfolding min_call_def by blast
show ?case using seq unfolding seq_cond_nest_def
proof
assume ass:"(Q, t) # cfg1 = map (lift P1) xs"
then obtain Q' xs' where xs':"Q=Seq Q' P1 \<and> xs=(Q',t)#xs'"
unfolding lift_def by fastforce
then have ctpn_P0:"(P0, s) # xs = (P0, s) # (Q', t) # xs'" by auto
then have min_p0:"min_call n \<Gamma> ((P0, s)#xs)"
using min_call_seq_c1_not_finish[OF Seq(3) Seq(4) p0_cptn] ass by auto
then have ex_xs:"\<exists>xs. min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift P1) xs"
using ass by auto
then have min_xs:"min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift P1) xs"
using min_p0 ass by auto
have "xs= (SOME xs. (min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift P1) xs))"
proof -
have "\<forall>xsa. min_call n \<Gamma> ((P0, s)#xsa) \<and> (Q, t) # cfg1 = map (lift P1) xsa \<longrightarrow> xsa = xs"
using xs' ass by (metis map_lift_eq_xs_xs')
thus ?thesis using min_xs some_equality by (metis (mono_tags, lifting))
qed
then have big:"biggest_nest_call P0 s ((Q', t) # xs') \<Gamma> n"
using biggest_nest_call.simps(1)[of P0 P1 s "((Q, t) # cfg1)" \<Gamma> n]
Seq(6) xs' ex_xs by auto
have reP0:"redex P0 = (Call f) \<and> \<Gamma> f = Some bdy \<and>
(\<exists>saa. s = Normal saa) \<and> t = s " using Seq(5) xs' by auto
have min_call:"min_call n \<Gamma> ((Q', t) # xs')"
using Seq(1)[OF min_p0 ctpn_P0 reP0] big xs' ass by auto
thus ?thesis using min_call_seq_not_finish[OF min_call] ass xs' by blast
next
assume ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \<and>
(\<exists>ys. (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<or>
fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and>
snd (last ((P0, s) # xs)) = Normal s' \<and>
s = Normal s'' \<and>
(\<exists>ys. (n, \<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift P1) xs @ (LanguageCon.com.Throw, Normal s') # ys)"
{assume ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \<and>
(\<exists>ys. (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys)"
have ?thesis
proof (cases xs)
case Nil thus ?thesis using Seq ass by fastforce
next
case (Cons xa xsa)
then obtain ys where
seq2_ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \<and>
(n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift P1) (xa#xsa) @ (P1, snd (((P0, s) # xs) ! length xs)) # ys"
using ass by auto
then obtain mq mp1 where
min_call_q:"min_call mq \<Gamma> ((P0, s) # xs)" and
min_call_p1:"min_call mp1 \<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)"
using seq2_ass minimum_nest_call p0_cptn by fastforce
then have mp: "mq\<le>n \<and> mp1 \<le>n"
using seq2_ass min_call_less_eq_n[of n \<Gamma> P0 s xs P1 ys mq mp1]
Seq(3,4) p0_cptn by (simp add: last_length)
have min_call:"min_call n \<Gamma> ((P0, s) # xs) \<or>
min_call n \<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)"
using seq2_ass min_call_seq2[of n \<Gamma> P0 P1 s "(Q, t) # cfg1" xs ys]
Seq(3,4) p0_cptn by (simp add: last_length local.Cons)
from seq2_ass obtain Q' where Q':"Q=Seq Q' P1 \<and> xa=(Q',t)"
unfolding lift_def
by (metis (mono_tags, lifting) fst_conv length_greater_0_conv
list.simps(3) list.simps(9) nth_Cons_0 nth_append prod.case_eq_if prod.collapse snd_conv)
then have q'_n_cptn:"(n,\<Gamma>,(Q',t)#xsa)\<in>cptn_mod_nest_call" using p0_cptn Q' Cons
using elim_cptn_mod_nest_call_n by blast
show ?thesis
proof(cases "mp1=n")
case True
then have "min_call n \<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)"
using min_call_p1 by auto
then have min_P1:"min_call n \<Gamma> ((P1, snd ((xa # xsa) ! length xsa)) # ys)"
using Cons seq2_ass by fastforce
then have p1_n_cptn:"(n, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call"
using Seq.prems(1) Seq.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast
also then have "(\<forall>m<n. (m, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call)"
proof-
{ fix m
assume ass:"m<n"
{ assume Q_m:"(m, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call"
then have False using min_P1 ass Q' Cons unfolding min_call_def
proof -
assume a1: "(n, \<Gamma>, (P1, snd ((xa # xsa) ! length xsa)) # ys) \<in> cptn_mod_nest_call \<and> (\<forall>m<n. (m, \<Gamma>, (P1, snd ((xa # xsa) ! length xsa)) # ys) \<notin> cptn_mod_nest_call)"
have f2: "\<forall>n f ps. (n, f, ps) \<notin> cptn_mod_nest_call \<or> (\<forall>x c ca psa. ps \<noteq> (LanguageCon.com.Seq (c::('b, 'a, 'c,'d) LanguageCon.com) ca, x) # psa \<or> (\<exists>ps b ba. (n, f, (c, x) # ps) \<in> cptn_mod_nest_call \<and> seq_cond_nest psa ca ps c x ba b f n))"
using div_seq_nest by blast
have f3: "(P1, snd (last ((Q', t) # xsa))) # ys = (P1, snd (((P0, s) # xs) ! length xs)) # ys"
by (simp add: Q' last_length local.Cons)
have "fst (last ((Q', t) # xsa)) = LanguageCon.com.Skip"
by (metis (no_types) Q' last_ConsR last_length list.distinct(1) local.Cons seq2_ass)
then show ?thesis
using f3 f2 a1 by (metis (no_types) Cons_lift_append Q' Seq_P_Ends_Normal Q_m ass seq2_ass)
qed
}
} then show ?thesis by auto
qed
ultimately show ?thesis unfolding min_call_def by auto
next
case False
then have "mp1<n" using mp by auto
then have not_min_call_p1_n:"\<not> min_call n \<Gamma> ((P1, snd (last ((P0, s) # xs))) # ys)"
using min_call_p1 last_length unfolding min_call_def by metis
then have min_call:"min_call n \<Gamma> ((P0, s) # xs)"
using min_call last_length unfolding min_call_def by metis
then have "(P0, s) # xs = (P0, s) # xa#xsa"
using Cons by auto
then have big:"biggest_nest_call P0 s (((Q',t))#xsa) \<Gamma> n"
proof-
have "\<not>(\<exists>xs. min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift P1) xs)"
using min_call seq2_ass Cons
proof -
have "min_call n \<Gamma> ((LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1)"
using Seq.prems(1) Seq.prems(2) by blast
then show ?thesis
by (metis (no_types) Seq_P_Not_finish append_Nil2 list.simps(3)
local.Cons min_call_def same_append_eq seq seq2_ass)
qed
moreover have "\<exists>xs ys. cond_seq_1 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys"
using seq2_ass p0_cptn unfolding cond_seq_1_def
by (metis last_length local.Cons)
moreover have "(SOME xs. \<exists>ys. cond_seq_1 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys) = xs"
proof -
let ?P = "\<lambda>xsa. \<exists>ys. (n, \<Gamma>, (P0, s) # xsa) \<in> cptn_mod_nest_call \<and>
fst (last ((P0, s) # xsa)) = LanguageCon.com.Skip \<and>
(n, \<Gamma>, (P1, snd (last ((P0, s) # xsa))) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift P1) xsa @ (P1, snd (last ((P0, s) # xsa))) # ys"
have "(\<And>x. \<exists>ys. (n, \<Gamma>, (P0, s) # x) \<in> cptn_mod_nest_call \<and>
fst (last ((P0, s) # x)) = LanguageCon.com.Skip \<and>
(n, \<Gamma>, (P1, snd (last ((P0, s) # x))) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift P1) x @ (P1, snd (last ((P0, s) # x))) # ys \<Longrightarrow>
x = xs)"
by (metis Seq_P_Ends_Normal cptn_mod_nest_call.CptnModNestSeq2 seq)
moreover have "\<exists>ys. (n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call \<and>
fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \<and>
(n, \<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys"
using ass p0_cptn by (simp add: last_length)
ultimately show ?thesis using some_equality[of ?P xs]
unfolding cond_seq_1_def by blast
qed
moreover have "(SOME ys. cond_seq_1 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys) = ys"
proof -
let ?P = "\<lambda>ys. (n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call \<and>
fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \<and>
(n, \<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys"
have "(n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call \<and>
fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \<and>
(n, \<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys"
using p0_cptn seq2_ass Cons by (simp add: last_length)
then show ?thesis using some_equality[of ?P ys]
unfolding cond_seq_1_def by fastforce
qed
ultimately have "biggest_nest_call P0 s xs \<Gamma> n"
using not_min_call_p1_n Seq(6)
biggest_nest_call.simps(1)[of P0 P1 s "(Q, t) # cfg1" \<Gamma> n]
by presburger
then show ?thesis using Cons Q' by auto
qed
have C:"(P0, s) # xs = (P0, s) # (Q', t) # xsa" using Cons Q' by auto
have reP0:"redex P0 = (Call f) \<and> \<Gamma> f = Some bdy \<and>
(\<exists>saa. s = Normal saa) \<and> t = s" using Seq(5) Q' by auto
then have min_call:"min_call n \<Gamma> ((Q', t) # xsa)" using Seq(1)[OF min_call C reP0 big]
by auto
have p1_n_cptn:"(n, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call"
using Seq.prems(1) Seq.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast
also then have "(\<forall>m<n. (m, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call)"
proof-
{ fix m
assume ass:"m<n"
{ assume Q_m:"(m, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call"
then obtain xsa' s1 s1' where
p0_cptn:"(m, \<Gamma>,(Q', t)#xsa') \<in> cptn_mod_nest_call" and
seq:"seq_cond_nest cfg1 P1 xsa' Q' t s1 s1' \<Gamma> m"
using div_seq_nest[of m \<Gamma> "(Q, t) # cfg1"] Q' by blast
then have "xsa=xsa'"
using seq2_ass
Seq_P_Ends_Normal[of cfg1 P1 xsa Q' t ys m \<Gamma> xsa' s1 s1'] Cons
by (metis Cons_lift_append Q' Q_m last.simps last_length list.inject list.simps(3))
then have False using min_call p0_cptn ass unfolding min_call_def by auto
}
} then show ?thesis by auto qed
ultimately show ?thesis unfolding min_call_def by auto
qed
qed
}note l=this
{assume ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and>
snd (last ((P0, s) # xs)) = Normal s' \<and>
s = Normal s'' \<and> (\<exists>ys. (n, \<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift P1) xs @ (LanguageCon.com.Throw, Normal s') # ys)"
have ?thesis
proof (cases "\<Gamma>\<turnstile>\<^sub>c(LanguageCon.com.Seq P0 P1, s) \<rightarrow> (Q,t)")
case True
thus ?thesis
proof (cases xs)
case Nil thus ?thesis using Seq ass by fastforce
next
case (Cons xa xsa)
then obtain ys where
seq2_ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and>
snd (last ((P0, s) # xs)) = Normal s' \<and>
s = Normal s'' \<and> (n, \<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift P1) xs @ (LanguageCon.com.Throw, Normal s') # ys"
using ass by auto
then have t_eq:"t=Normal s''" using Seq by fastforce
obtain mq mp1 where
min_call_q:"min_call mq \<Gamma> ((P0, s) # xs)" and
min_call_p1:"min_call mp1 \<Gamma> ((Throw, snd (((P0, s) # xs) ! length xs)) # ys)"
using seq2_ass minimum_nest_call p0_cptn by (metis last_length)
then have mp1_zero:"mp1=0" by (simp add: throw_min_nested_call_0)
then have min_call: "min_call n \<Gamma> ((P0, s) # xs)"
using seq2_ass min_call_seq3[of n \<Gamma> P0 P1 s "(Q, t) # cfg1" s'' xs s' ys]
Seq(3,4) p0_cptn by (metis last_length)
have n_z:"n>0" using redex_call_cptn_mod_min_nest_call_gr_zero[OF Seq(3) Seq(4) Seq(5) True]
by auto
from seq2_ass obtain Q' where Q':"Q=Seq Q' P1 \<and> xa=(Q',t)"
unfolding lift_def using Cons
proof -
assume a1: "\<And>Q'. Q = LanguageCon.com.Seq Q' P1 \<and> xa = (Q', t) \<Longrightarrow> thesis"
have "(LanguageCon.com.Seq (fst xa) P1, snd xa) = ((Q, t) # cfg1) ! 0"
using seq2_ass unfolding lift_def
by (simp add: Cons case_prod_unfold)
then show ?thesis
using a1 by fastforce
qed
have big_call:"biggest_nest_call P0 s ((Q',t)#xsa) \<Gamma> n"
proof-
have "\<not>(\<exists>xs. min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift P1) xs)"
using min_call seq2_ass Cons Seq.prems(1) Seq.prems(2)
by (metis Seq_P_Not_finish append_Nil2 list.simps(3) min_call_def same_append_eq seq)
moreover have "\<not>(\<exists>xs ys. cond_seq_1 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys)"
using min_call seq2_ass p0_cptn Cons Seq.prems(1) Seq.prems(2)
unfolding cond_seq_1_def
by (metis com.distinct(17) com.distinct(71) last_length
map_lift_some_eq seq_and_if_not_eq(4))
moreover have "(SOME xs. \<exists>ys s' s''. cond_seq_2 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys s' s'') = xs"
proof-
let ?P="\<lambda>xsa. \<exists>ys s' s''. s= Normal s'' \<and>
(n,\<Gamma>, (P0, s)#xs) \<in> cptn_mod_nest_call \<and>
fst(last ((P0, s)#xs)) = Throw \<and>
snd(last ((P0, s)#xs)) = Normal s' \<and>
(n,\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod_nest_call \<and>
((Q, t) # cfg1)=(map (lift P1) xs)@((Throw,Normal s')#ys)"
have "(\<And>x. \<exists>ys s' s''. s= Normal s'' \<and>
(n,\<Gamma>, (P0, s)#x) \<in> cptn_mod_nest_call \<and>
fst(last ((P0, s)#x)) = Throw \<and>
snd(last ((P0, s)#x)) = Normal s' \<and>
(n,\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod_nest_call \<and>
((Q, t) # cfg1)=(map (lift P1) x)@((Throw,Normal s')#ys) \<Longrightarrow>
x=xs)" using map_lift_some_eq seq2_ass by fastforce
moreover have "\<exists>ys s' s''. s= Normal s'' \<and>
(n,\<Gamma>, (P0, s)#xs) \<in> cptn_mod_nest_call \<and>
fst(last ((P0, s)#xs)) = Throw \<and>
snd(last ((P0, s)#xs)) = Normal s' \<and>
(n,\<Gamma>,(Throw,Normal s')#ys) \<in> cptn_mod_nest_call \<and>
((Q, t) # cfg1)=(map (lift P1) xs)@((Throw,Normal s')#ys)"
using ass p0_cptn by (simp add: last_length Cons)
ultimately show ?thesis using some_equality[of ?P xs]
unfolding cond_seq_2_def by blast
qed
ultimately have "biggest_nest_call P0 s xs \<Gamma> n"
using Seq(6)
biggest_nest_call.simps(1)[of P0 P1 s "(Q, t) # cfg1" \<Gamma> n]
by presburger
then show ?thesis using Cons Q' by auto
qed
have min_call:"min_call n \<Gamma> ((Q',t)#xsa)"
using Seq(1)[OF min_call _ _ big_call] Seq(5) Cons Q' by fastforce
then have p1_n_cptn:"(n, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call"
using Seq.prems(1) Seq.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast
also then have "(\<forall>m<n. (m, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call)"
proof-
{ fix m
assume ass:"m<n"
{ assume Q_m:"(m, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call"
then obtain xsa' s1 s1' where
p0_cptn:"(m, \<Gamma>,(Q', t)#xsa') \<in> cptn_mod_nest_call" and
seq:"seq_cond_nest cfg1 P1 xsa' Q' (Normal s'') s1 s1' \<Gamma> m"
using div_seq_nest[of m \<Gamma> "(Q, t) # cfg1"] Q' t_eq by blast
then have "xsa=xsa'"
using seq2_ass
Seq_P_Ends_Abort[of cfg1 P1 xsa s' ys Q' s'' m \<Gamma> xsa' s1 s1' ] Cons Q' Q_m
by (simp add: Cons_lift_append last_length t_eq)
then have False using min_call p0_cptn ass unfolding min_call_def by auto
}
} then show ?thesis by auto qed
ultimately show ?thesis unfolding min_call_def by auto
qed
next
case False
then have env:"\<Gamma>\<turnstile>\<^sub>c(LanguageCon.com.Seq P0 P1, s) \<rightarrow>\<^sub>e (Q,t)" using Seq
by (meson elim_cptn_mod_nest_step_c min_call_def)
moreover then have Q:"Q=Seq P0 P1" using env_c_c' by blast
ultimately show ?thesis using Seq
proof -
obtain nn :: "(('b, 'a, 'c,'d) LanguageCon.com \<times> ('b, 'c) xstate) list \<Rightarrow>
('a \<Rightarrow> ('b, 'a, 'c,'d) LanguageCon.com option) \<Rightarrow> nat \<Rightarrow> nat" where
f1: "\<forall>x0 x1 x2. (\<exists>v3<x2. (v3, x1, x0) \<in> cptn_mod_nest_call) = (nn x0 x1 x2 < x2 \<and> (nn x0 x1 x2, x1, x0) \<in> cptn_mod_nest_call)"
by moura
have f2: "(n, \<Gamma>, (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1) \<in> cptn_mod_nest_call \<and> (\<forall>n. \<not> n < n \<or> (n, \<Gamma>, (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1) \<notin> cptn_mod_nest_call)"
using local.Seq(3) local.Seq(4) min_call_def by blast
then have "\<not> nn ((Q, t) # cfg1) \<Gamma> n < n \<or> (nn ((Q, t) # cfg1) \<Gamma> n, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call"
using False env env_c_c' not_func_redex_cptn_mod_nest_n_env
by (metis Seq.prems(1) Seq.prems(2) min_call_def)
then show ?thesis
using f2 f1 by (meson elim_cptn_mod_nest_call_n min_call_def)
qed
qed
}
thus ?thesis using l ass by fastforce
qed
next
case (Catch P0 P1)
then obtain xs s' s'' where
p0_cptn:"(n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call" and
catch:"catch_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \<Gamma> n"
using div_catch_nest[of n \<Gamma> cfg] unfolding min_call_def by blast
show ?case using catch unfolding catch_cond_nest_def
proof
assume ass:"(Q, t) # cfg1 = map (lift_catch P1) xs"
then obtain Q' xs' where xs':"Q=Catch Q' P1 \<and> xs=(Q',t)#xs'"
unfolding lift_catch_def by fastforce
then have ctpn_P0:"(P0, s) # xs = (P0, s) # (Q', t) # xs'" by auto
then have min_p0:"min_call n \<Gamma> ((P0, s)#xs)"
using min_call_catch_c1_not_finish[OF Catch(3) Catch(4) p0_cptn] ass by auto
then have ex_xs:"\<exists>xs. min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift_catch P1) xs"
using ass by auto
then have min_xs:"min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift_catch P1) xs"
using min_p0 ass by auto
have "xs= (SOME xs. (min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift_catch P1) xs))"
proof -
have "\<forall>xsa. min_call n \<Gamma> ((P0, s)#xsa) \<and> (Q, t) # cfg1 = map (lift_catch P1) xsa \<longrightarrow> xsa = xs"
using xs' ass by (metis map_lift_catch_eq_xs_xs')
thus ?thesis using min_xs some_equality by (metis (mono_tags, lifting))
qed
then have big:"biggest_nest_call P0 s ((Q', t) # xs') \<Gamma> n"
using biggest_nest_call.simps(2)[of P0 P1 s "((Q, t) # cfg1)" \<Gamma> n]
Catch(6) xs' ex_xs by auto
have reP0:"redex P0 = (Call f) \<and> \<Gamma> f = Some bdy \<and>
(\<exists>saa. s = Normal saa) \<and> t = s " using Catch(5) xs' by auto
have min_call:"min_call n \<Gamma> ((Q', t) # xs')"
using Catch(1)[OF min_p0 ctpn_P0 reP0] big xs' ass by auto
thus ?thesis using min_call_catch_not_finish[OF min_call] ass xs' by blast
next
assume ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and>
snd (last ((P0, s) # xs)) = Normal s' \<and>
s = Normal s'' \<and>
(\<exists>ys. (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<or>
fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \<and>
(\<exists>ys. (n, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift_catch P1) xs @ (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys)"
{assume ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and>
snd (last ((P0, s) # xs)) = Normal s' \<and>
s = Normal s'' \<and>
(\<exists>ys. (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys)"
have ?thesis
proof (cases xs)
case Nil thus ?thesis using Catch ass by fastforce
next
case (Cons xa xsa)
then obtain ys where
catch2_ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and>
snd (last ((P0, s) # xs)) = Normal s' \<and>
s = Normal s'' \<and>
(n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys"
using ass by auto
then obtain mq mp1 where
min_call_q:"min_call mq \<Gamma> ((P0, s) # xs)" and
min_call_p1:"min_call mp1 \<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)"
using catch2_ass minimum_nest_call p0_cptn by fastforce
then have mp: "mq\<le>n \<and> mp1 \<le>n"
using catch2_ass min_call_less_eq_n
Catch(3,4) p0_cptn by (metis last_length)
have min_call:"min_call n \<Gamma> ((P0, s) # xs) \<or>
min_call n \<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)"
using catch2_ass min_call_catch3[of n \<Gamma> P0 P1 s'' "(Q, t) # cfg1" xs s' ys]
Catch(3,4) p0_cptn by (metis last_length)
from catch2_ass obtain Q' where Q':"Q=Catch Q' P1 \<and> xa=(Q',t)"
unfolding lift_catch_def
proof -
assume a1: "\<And>Q'. Q = LanguageCon.com.Catch Q' P1 \<and> xa = (Q', t) \<Longrightarrow> thesis"
assume "fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \<and> snd (last ((P0, s) # xs)) = Normal s' \<and> s = Normal s'' \<and> (n, \<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys"
then have "(LanguageCon.com.Catch (fst xa) P1, snd xa) = ((Q, t) # cfg1) ! 0"
by (simp add: local.Cons prod.case_eq_if)
then show ?thesis
using a1 by force
qed
then have q'_n_cptn:"(n,\<Gamma>,(Q',t)#xsa)\<in>cptn_mod_nest_call" using p0_cptn Q' Cons
using elim_cptn_mod_nest_call_n by blast
show ?thesis
proof(cases "mp1=n")
case True
then have "min_call n \<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)"
using min_call_p1 by auto
then have min_P1:"min_call n \<Gamma> ((P1, snd ((xa # xsa) ! length xsa)) # ys)"
using Cons catch2_ass by fastforce
then have p1_n_cptn:"(n, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call"
using Catch.prems(1) Catch.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast
also then have "(\<forall>m<n. (m, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call)"
proof-
{ fix m
assume ass:"m<n"
{ assume Q_m:"(m, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call"
then have t_eq_s:"t=Normal s''" using Catch catch2_ass by fastforce
then obtain xsa' s1 s1' where
p0_cptn:"(m, \<Gamma>,(Q', t)#xsa') \<in> cptn_mod_nest_call" and
catch_cond:"catch_cond_nest cfg1 P1 xsa' Q' (Normal s'') s1 s1' \<Gamma> m"
using Q_m div_catch_nest[of m \<Gamma> "(Q, t) # cfg1"] Q' by blast
have fst:"fst (last ((Q', Normal s'') # xsa)) = LanguageCon.com.Throw"
using catch2_ass Cons Q' by (simp add: last_length t_eq_s)
have cfg:"cfg1 = map (lift_catch P1) xsa @ (P1, snd (last ((Q', Normal s'') # xsa))) # ys"
using catch2_ass Cons Q' by (simp add: last_length t_eq_s)
have snd:"snd (last ((Q', Normal s'') # xsa)) = Normal s'"
using catch2_ass Cons Q' by (simp add: last_length t_eq_s)
then have "xsa=xsa' \<and>
(m, \<Gamma>, (P1, snd (((Q', Normal s'') # xsa) ! length xsa)) # ys) \<in> cptn_mod_nest_call"
using catch2_ass Catch_P_Ends_Normal[OF cfg fst snd catch_cond] Cons
by auto
then have False using min_P1 ass Q' t_eq_s unfolding min_call_def by auto
}
} then show ?thesis by auto
qed
ultimately show ?thesis unfolding min_call_def by auto
next
case False
then have "mp1<n" using mp by auto
then have not_min_call_p1_n:"\<not> min_call n \<Gamma> ((P1, snd (last ((P0, s) # xs))) # ys)"
using min_call_p1 last_length unfolding min_call_def by metis
then have min_call:"min_call n \<Gamma> ((P0, s) # xs)"
using min_call last_length unfolding min_call_def by metis
then have "(P0, s) # xs = (P0, s) # xa#xsa"
using Cons by auto
then have big:"biggest_nest_call P0 s (((Q',t))#xsa) \<Gamma> n"
proof-
have "\<not>(\<exists>xs. min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift_catch P1) xs)"
using min_call catch2_ass Cons
proof -
have "min_call n \<Gamma> ((Catch P0 P1, s) # (Q, t) # cfg1)"
using Catch.prems(1) Catch.prems(2) by blast
then show ?thesis
by (metis (no_types) Catch_P_Not_finish append_Nil2 list.simps(3)
same_append_eq catch catch2_ass)
qed
moreover have "\<not>(\<exists>xs ys. cond_catch_1 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys)"
unfolding cond_catch_1_def using catch2_ass
by (metis Catch_P_Ends_Skip LanguageCon.com.distinct(17) catch last_length)
moreover have "\<exists>xs ys. cond_catch_2 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys s' s''"
using catch2_ass p0_cptn unfolding cond_catch_2_def last_length
by metis
moreover have "(SOME xs. \<exists>ys s' s''. cond_catch_2 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys s' s'') = xs"
proof -
let ?P = "\<lambda>xsa. s = Normal s'' \<and>
(n, \<Gamma>, (P0, s) # xsa) \<in> cptn_mod_nest_call \<and>
fst (last ((P0, s) # xsa)) = LanguageCon.com.Throw \<and>
snd (last ((P0, s) # xsa)) = Normal s' \<and>
(n, \<Gamma>, (P1, Normal s') # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift_catch P1) xsa @ (P1, Normal s') # ys"
have "(\<And>x. \<exists>ys s' s''. s = Normal s'' \<and>
(n, \<Gamma>, (P0, s) # x) \<in> cptn_mod_nest_call \<and>
fst (last ((P0, s) # x)) = LanguageCon.com.Throw \<and>
snd (last ((P0, s) # x)) = Normal s' \<and>
(n, \<Gamma>, (P1, Normal s') # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift_catch P1) x @ (P1, Normal s') # ys \<Longrightarrow>
x = xs)"
by (metis Catch_P_Ends_Normal catch)
moreover have "\<exists>ys. s = Normal s'' \<and>
(n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call \<and>
fst (last ((P0, s) # xs)) = LanguageCon.com.Throw \<and>
snd (last ((P0, s) # xs)) = Normal s' \<and>
(n, \<Gamma>, (P1, Normal s') # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, Normal s') # ys"
using ass p0_cptn by (metis (full_types) last_length )
ultimately show ?thesis using some_equality[of ?P xs]
unfolding cond_catch_2_def by blast
qed
moreover have "(SOME ys. \<exists>s' s''. cond_catch_2 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys s' s'') = ys"
proof -
let ?P = "\<lambda>ysa. s = Normal s'' \<and>
(n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call \<and>
fst (last ((P0, s) # xs)) = LanguageCon.com.Throw \<and>
snd (last ((P0, s) # xs)) = Normal s' \<and>
(n, \<Gamma>, (P1, Normal s') # ysa) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, Normal s') # ysa"
have "(\<And>x. \<exists>s' s''. s = Normal s'' \<and>
(n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call \<and>
fst (last ((P0, s) # xs)) = LanguageCon.com.Throw \<and>
snd (last ((P0, s) # xs)) = Normal s' \<and>
(n, \<Gamma>, (P1, Normal s') # x) \<in> cptn_mod_nest_call \<and> (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, Normal s') # x \<Longrightarrow>
x = ys)" using catch2_ass by auto
moreover have "s = Normal s'' \<and>
(n, \<Gamma>, (P0, s) # xs) \<in> cptn_mod_nest_call \<and>
fst (last ((P0, s) # xs)) = LanguageCon.com.Throw \<and>
snd (last ((P0, s) # xs)) = Normal s' \<and>
(n, \<Gamma>, (P1, Normal s') # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, Normal s') # ys"
using ass p0_cptn by (metis (full_types) catch2_ass last_length p0_cptn)
ultimately show ?thesis using some_equality[of ?P ys]
unfolding cond_catch_2_def by blast
qed
ultimately have "biggest_nest_call P0 s xs \<Gamma> n"
using not_min_call_p1_n Catch(6)
biggest_nest_call.simps(2)[of P0 P1 s "(Q, t) # cfg1" \<Gamma> n]
by presburger
then show ?thesis using Cons Q' by auto
qed
have C:"(P0, s) # xs = (P0, s) # (Q', t) # xsa" using Cons Q' by auto
have reP0:"redex P0 = (Call f) \<and> \<Gamma> f = Some bdy \<and>
(\<exists>saa. s = Normal saa) \<and> t = s " using Catch(5) Q' by auto
then have min_call:"min_call n \<Gamma> ((Q', t) # xsa)" using Catch(1)[OF min_call C reP0 big]
by auto
have p1_n_cptn:"(n, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call"
using Catch.prems(1) Catch.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast
also then have "(\<forall>m<n. (m, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call)"
proof-
{ fix m
assume ass:"m<n"
{ assume Q_m:"(m, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call"
then have t_eq_s:"t=Normal s''" using Catch catch2_ass by fastforce
then obtain xsa' s1 s1' where
p0_cptn:"(m, \<Gamma>,(Q', t)#xsa') \<in> cptn_mod_nest_call" and
catch_cond:"catch_cond_nest cfg1 P1 xsa' Q' (Normal s'') s1 s1' \<Gamma> m"
using Q_m div_catch_nest[of m \<Gamma> "(Q, t) # cfg1"] Q' by blast
have fst:"fst (last ((Q', Normal s'') # xsa)) = LanguageCon.com.Throw"
using catch2_ass Cons Q' by (simp add: last_length t_eq_s)
have cfg:"cfg1 = map (lift_catch P1) xsa @ (P1, snd (last ((Q', Normal s'') # xsa))) # ys"
using catch2_ass Cons Q' by (simp add: last_length t_eq_s)
have snd:"snd (last ((Q', Normal s'') # xsa)) = Normal s'"
using catch2_ass Cons Q' by (simp add: last_length t_eq_s)
then have "xsa=xsa'"
using catch2_ass Catch_P_Ends_Normal[OF cfg fst snd catch_cond] Cons
by auto
then have False using min_call p0_cptn ass unfolding min_call_def by auto
}
} then show ?thesis by auto qed
ultimately show ?thesis unfolding min_call_def by auto
qed
qed
}note l=this
{assume ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \<and>
(\<exists>ys. (n, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift_catch P1) xs @ (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys)"
have ?thesis
proof (cases "\<Gamma>\<turnstile>\<^sub>c(Catch P0 P1, s) \<rightarrow> (Q,t)")
case True
thus ?thesis
proof (cases xs)
case Nil thus ?thesis using Catch ass by fastforce
next
case (Cons xa xsa)
then obtain ys where
catch2_ass:"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \<and>
(n, \<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift_catch P1) xs @ (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys"
using ass by auto
then have t_eq:"t=s" using Catch by fastforce
obtain mq mp1 where
min_call_q:"min_call mq \<Gamma> ((P0, s) # xs)" and
min_call_p1:"min_call mp1 \<Gamma> ((Skip, snd (((P0, s) # xs) ! length xs)) # ys)"
using catch2_ass minimum_nest_call p0_cptn by (metis last_length)
then have mp1_zero:"mp1=0" by (simp add: skip_min_nested_call_0)
then have min_call: "min_call n \<Gamma> ((P0, s) # xs)"
using catch2_ass min_call_catch2[of n \<Gamma> P0 P1 s "(Q, t) # cfg1" xs ys]
Catch(3,4) p0_cptn by (metis last_length)
have n_z:"n>0" using redex_call_cptn_mod_min_nest_call_gr_zero[OF Catch(3) Catch(4) Catch(5) True]
by auto
from catch2_ass obtain Q' where Q':"Q=Catch Q' P1 \<and> xa=(Q',t)"
unfolding lift_catch_def using Cons
proof -
assume a1: "\<And>Q'. Q = Catch Q' P1 \<and> xa = (Q', t) \<Longrightarrow> thesis"
have "(Catch (fst xa) P1, snd xa) = ((Q, t) # cfg1) ! 0"
using catch2_ass unfolding lift_catch_def
by (simp add: Cons case_prod_unfold)
then show ?thesis
using a1 by fastforce
qed
have big_call:"biggest_nest_call P0 s ((Q',t)#xsa) \<Gamma> n"
proof-
have "\<not>(\<exists>xs. min_call n \<Gamma> ((P0, s)#xs) \<and> (Q, t) # cfg1 = map (lift_catch P1) xs)"
using min_call catch2_ass Cons
proof -
have "min_call n \<Gamma> ((Catch P0 P1, s) # (Q, t) # cfg1)"
using Catch.prems(1) Catch.prems(2) by blast
then show ?thesis
by (metis (no_types) Catch_P_Not_finish append_Nil2 list.simps(3)
same_append_eq catch catch2_ass)
qed
moreover have "(\<exists>xs ys. cond_catch_1 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys)"
using catch2_ass p0_cptn unfolding cond_catch_1_def last_length
by metis
moreover have "(SOME xs. \<exists>ys. cond_catch_1 n \<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys) = xs"
proof -
let ?P = "\<lambda>xsa. \<exists>ys. (n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call \<and>
fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \<and>
(n, \<Gamma>, (LanguageCon.com.Skip,
snd (last ((P0, s) # xsa))) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift_catch P1) xsa @
(LanguageCon.com.Skip, snd (last ((P0, s) # xsa))) # ys"
have "\<And>xsa. \<exists>ys. (n, \<Gamma>,(P0, s)#xsa) \<in> cptn_mod_nest_call \<and>
fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \<and>
(n, \<Gamma>, (LanguageCon.com.Skip,
snd (last ((P0, s) # xsa))) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift_catch P1) xsa @
(LanguageCon.com.Skip, snd (last ((P0, s) # xsa))) # ys \<Longrightarrow>
xsa = xs"
using Catch_P_Ends_Skip catch catch2_ass map_lift_catch_some_eq by fastforce
moreover have "\<exists>ys. (n, \<Gamma>,(P0, s)#xs) \<in> cptn_mod_nest_call \<and>
fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \<and>
(n, \<Gamma>, (LanguageCon.com.Skip,
snd (last ((P0, s) # xs))) # ys) \<in> cptn_mod_nest_call \<and>
(Q, t) # cfg1 = map (lift_catch P1) xs @
(LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys"
using ass p0_cptn by (simp add: last_length)
ultimately show ?thesis using some_equality[of ?P xs]
unfolding cond_catch_1_def by blast
qed
ultimately have "biggest_nest_call P0 s xs \<Gamma> n"
using Catch(6)
biggest_nest_call.simps(2)[of P0 P1 s "(Q, t) # cfg1" \<Gamma> n]
by presburger
then show ?thesis using Cons Q' by auto
qed
have min_call:"min_call n \<Gamma> ((Q',t)#xsa)"
using Catch(1)[OF min_call _ _ big_call] Catch(5) Cons Q' by fastforce
then have p1_n_cptn:"(n, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call"
using Catch.prems(1) Catch.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast
also then have "(\<forall>m<n. (m, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call)"
proof-
{ fix m
assume ass:"m<n"
{ assume Q_m:"(m, \<Gamma>, (Q, t) # cfg1) \<in> cptn_mod_nest_call"
then obtain xsa' s1 s1' where
p0_cptn:"(m, \<Gamma>,(Q', t)#xsa') \<in> cptn_mod_nest_call" and
seq:"catch_cond_nest cfg1 P1 xsa' Q' t s1 s1' \<Gamma> m"
using div_catch_nest[of m \<Gamma> "(Q, t) # cfg1"] Q' t_eq by blast
then have "xsa=xsa'"
using catch2_ass
Catch_P_Ends_Skip[of cfg1 P1 xsa Q' t ys xsa' s1 s1']
Cons Q' Q_m
by (simp add: last_length)
then have False using min_call p0_cptn ass unfolding min_call_def by auto
}
} then show ?thesis by auto qed
ultimately show ?thesis unfolding min_call_def by auto
qed
next
case False
then have env:"\<Gamma>\<turnstile>\<^sub>c(Catch P0 P1, s) \<rightarrow>\<^sub>e (Q,t)" using Catch
by (meson elim_cptn_mod_nest_step_c min_call_def)
moreover then have Q:"Q=Catch P0 P1" using env_c_c' by blast
ultimately show ?thesis using Catch
proof -
obtain nn :: "(('b, 'a, 'c,'d) LanguageCon.com \<times> ('b, 'c) xstate) list \<Rightarrow> ('a \<Rightarrow> ('b, 'a, 'c,'d) LanguageCon.com option) \<Rightarrow> nat \<Rightarrow> nat" where
f1: "\<forall>x0 x1 x2. (\<exists>v3<x2. (v3, x1, x0) \<in> cptn_mod_nest_call) = (nn x0 x1 x2 < x2 \<and> (nn x0 x1 x2, x1, x0) \<in> cptn_mod_nest_call)"
by moura
have f2: "(n, \<Gamma>, (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1) \<in> cptn_mod_nest_call \<and> (\<forall>n. \<not> n < n \<or> (n, \<Gamma>, (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1) \<notin> cptn_mod_nest_call)"
using local.Catch(3) local.Catch(4) min_call_def by blast
then have "\<not> nn ((Q, t) # cfg1) \<Gamma> n < n \<or> (nn ((Q, t) # cfg1) \<Gamma> n, \<Gamma>, (Q, t) # cfg1) \<notin> cptn_mod_nest_call"
using False env env_c_c' not_func_redex_cptn_mod_nest_n_env
by (metis Catch.prems(1) Catch.prems(2) min_call_def)
then show ?thesis
using f2 f1 by (meson elim_cptn_mod_nest_call_n min_call_def)
qed
qed
}
thus ?thesis using l ass by fastforce
qed
qed (fastforce)+
*)
lemma cptn_mod_nest_n_1:
assumes a0:"(n,\<Gamma>,cfs) \<in> cptn_mod_nest_call" and
a1:"cfs=(p,s)#cfs'" and
a2:"\<not> (min_call n \<Gamma> cfs)"
shows "(n-1,\<Gamma>,cfs) \<in> cptn_mod_nest_call"
using a0 a1 a2
by (metis (no_types, lifting) Suc_diff_1 Suc_leI cptn_mod_nest_mono less_nat_zero_code min_call_def not_less)
lemma cptn_mod_nest_tl_n_1:
assumes a0:"(n,\<Gamma>,cfs) \<in> cptn_mod_nest_call" and
a1:"cfs=(p,s)#(q,t)#cfs'" and
a2:"\<not> (min_call n \<Gamma> cfs)"
shows "(n-1,\<Gamma>,(q,t)#cfs') \<in> cptn_mod_nest_call"
using a0 a1 a2
by (meson elim_cptn_mod_nest_call_n cptn_mod_nest_n_1)
lemma cptn_mod_nest_tl_not_min:
assumes a0:"(n,\<Gamma>,cfg) \<in> cptn_mod_nest_call" and
a1:"cfg=(p,s)#cfg'" and
a2:"\<not> (min_call n \<Gamma> cfg)"
shows "\<not> (min_call n \<Gamma> cfg')"
proof (cases cfg')
case Nil
have "(\<Gamma>, []) \<notin> cptn"
using cptn.simps by blast
then show ?thesis unfolding min_call_def
using cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod local.Nil by blast
next
case (Cons xa cfga)
then obtain q t where "xa = (q,t)"
using prod.exhaust_sel by blast
then have "(n-1,\<Gamma>,cfg') \<in> cptn_mod_nest_call"
using a0 a1 a2 cptn_mod_nest_tl_n_1 Cons by blast
also then have "(n,\<Gamma>,cfg') \<in> cptn_mod_nest_call"
using cptn_mod_nest_mono Nat.diff_le_self by blast
ultimately show ?thesis unfolding min_call_def
using a0 a2 min_call_def by force
qed
definition cp :: "('g\<times>'l,'p,'f,'e) body \<Rightarrow> ('g\<times>'l,'p,'f,'e)com \<Rightarrow>
('g\<times>'l)\<times>('l list) \<Rightarrow> (('g,'l,'p,'f,'e) confs) set" where
"cp \<Gamma> P s \<equiv> {(\<Gamma>1,l). l!0=(P,s) \<and> (\<Gamma>,l) \<in> cptn \<and> \<Gamma>1=\<Gamma>}"
lemma cp_sub:
assumes a0: "(\<Gamma>,(x#l0)@l1) \<in> cp \<Gamma> P s"
shows "(\<Gamma>,(x#l0)) \<in> cp \<Gamma> P s"
proof -
have "(x#l0)!0 = (P,s)" using a0 unfolding cp_def by auto
also have "(\<Gamma>,(x#l0))\<in>cptn" using a0 unfolding cp_def
using cptn_dest_2 by fastforce
ultimately show ?thesis using a0 unfolding cp_def by blast
qed
definition cpn :: "nat \<Rightarrow> ('g\<times>'l,'p,'f,'e) body \<Rightarrow> ('g\<times>'l,'p,'f,'e)com \<Rightarrow>
('g\<times>'l)\<times>('l list) \<Rightarrow> (('g,'l,'p,'f,'e) confs) set"
where
"cpn n \<Gamma> P s \<equiv> {(\<Gamma>1,l). l!0=(P,s) \<and> (n,\<Gamma>,l) \<in> cptn_mod_nest_call \<and> \<Gamma>1=\<Gamma>}"
end
|
/-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import data.buffer.parser
import tactic.doc_commands
open lean.parser tactic interactive parser
/--
`restate_axiom` takes a structure field, and makes a new, definitionally simplified copy of it.
If the existing field name ends with a `'`, the new field just has the prime removed. Otherwise,
we append `_lemma`.
The main application is to provide clean versions of structure fields that have been tagged with
an auto_param.
-/
meta def restate_axiom (d : declaration) (new_name : name) : tactic unit :=
do (levels, type, value, reducibility, trusted) ← pure (match d.to_definition with
| declaration.defn name levels type value reducibility trusted :=
(levels, type, value, reducibility, trusted)
| _ := undefined
end),
(s, u) ← mk_simp_set ff [] [],
new_type ← (s.dsimplify [] type) <|> pure (type),
prop ← is_prop new_type,
let new_decl := if prop then
declaration.thm new_name levels new_type (task.pure value)
else
declaration.defn new_name levels new_type value reducibility trusted,
updateex_env $ λ env, env.add new_decl
private meta def name_lemma (old : name) (new : option name := none) : tactic name :=
match new with
| none :=
match old.components.reverse with
| last :: most := (do let last := last.to_string,
let last := if last.to_list.ilast = ''' then
(last.to_list.reverse.drop 1).reverse.as_string
else last ++ "_lemma",
return (mk_str_name old.get_prefix last)) <|> failed
| nil := undefined
end
| (some new) := return (mk_str_name old.get_prefix new.to_string)
end
/--
`restate_axiom` makes a new copy of a structure field, first definitionally simplifying the type.
This is useful to remove `auto_param` or `opt_param` from the statement.
As an example, we have:
```lean
structure A :=
(x : ℕ)
(a' : x = 1 . skip)
example (z : A) : z.x = 1 := by rw A.a' -- rewrite tactic failed, lemma is not an equality nor a iff
restate_axiom A.a'
example (z : A) : z.x = 1 := by rw A.a
```
By default, `restate_axiom` names the new lemma by removing a trailing `'`, or otherwise appending
`_lemma` if there is no trailing `'`. You can also give `restate_axiom` a second argument to
specify the new name, as in
```lean
restate_axiom A.a f
example (z : A) : z.x = 1 := by rw A.f
```
-/
@[user_command] meta def restate_axiom_cmd (_ : parse $ tk "restate_axiom") : lean.parser unit :=
do from_lemma ← ident,
new_name ← optional ident,
from_lemma_fully_qualified ← resolve_constant from_lemma,
d ← get_decl from_lemma_fully_qualified <|>
fail ("declaration " ++ to_string from_lemma ++ " not found"),
do {
new_name ← name_lemma from_lemma_fully_qualified new_name,
restate_axiom d new_name
}
add_tactic_doc
{ name := "restate_axiom",
category := doc_category.cmd,
decl_names := [`restate_axiom_cmd],
tags := ["renaming", "environment"] }
|
Formal statement is: theorem Edelstein_fix: fixes S :: "'a::metric_space set" assumes S: "compact S" "S \<noteq> {}" and gs: "(g ` S) \<subseteq> S" and dist: "\<forall>x\<in>S. \<forall>y\<in>S. x \<noteq> y \<longrightarrow> dist (g x) (g y) < dist x y" shows "\<exists>!x\<in>S. g x = x" Informal statement is: If $S$ is a compact set with more than one point, and $g$ is a function from $S$ to $S$ such that $g(x)$ is closer to $g(y)$ than $x$ is to $y$ for all $x$ and $y$ in $S$, then $g$ has a unique fixed point. |
lemma LIM_offset: "f \<midarrow>a\<rightarrow> L \<Longrightarrow> (\<lambda>x. f (x + k)) \<midarrow>(a - k)\<rightarrow> L" for a :: "'a::real_normed_vector" |
(*
Author: Norbert Schirmer
Maintainer: Norbert Schirmer, norbert.schirmer at web de
License: LGPL
*)
(* Title: XVcgEx.thy
Author: Norbert Schirmer, TU Muenchen
Copyright (C) 2006-2008 Norbert Schirmer
Some rights reserved, TU Muenchen
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*)
section "Examples for Parallel Assignments"
theory XVcgEx
imports "../XVcg"
begin
record "globals" =
"G_'"::"nat"
"H_'"::"nat"
record 'g vars = "'g state" +
A_' :: nat
B_' :: nat
C_' :: nat
I_' :: nat
M_' :: nat
N_' :: nat
R_' :: nat
S_' :: nat
Arr_' :: "nat list"
Abr_':: string
term "BASIC
\<acute>A :== x,
\<acute>B :== y
END"
term "BASIC
\<acute>G :== \<acute>H,
\<acute>H :== \<acute>G
END"
term "BASIC
LET (x,y) = (\<acute>A,b);
z = \<acute>B
IN \<acute>A :== x,
\<acute>G :== \<acute>A + y + z
END"
lemma "\<Gamma>\<turnstile> \<lbrace>\<acute>A = 0\<rbrace>
\<lbrace>\<acute>A < 0\<rbrace> \<longmapsto> BASIC
LET (a,b,c) = foo \<acute>A
IN
\<acute>A :== a,
\<acute>B :== b,
\<acute>C :== c
END
\<lbrace>\<acute>A = x \<and> \<acute>B = y \<and> \<acute>C = c\<rbrace>"
apply vcg
oops
lemma "\<Gamma>\<turnstile> \<lbrace>\<acute>A = 0\<rbrace>
\<lbrace>\<acute>A < 0\<rbrace> \<longmapsto> BASIC
LET (a,b,c) = foo \<acute>A
IN
\<acute>A :== a,
\<acute>G :== b + \<acute>B,
\<acute>H :== c
END
\<lbrace>\<acute>A = x \<and> \<acute>G = y \<and> \<acute>H = c\<rbrace>"
apply vcg
oops
definition foo:: "nat \<Rightarrow> (nat \<times> nat \<times> nat)"
where "foo n = (n,n+1,n+2)"
lemma "\<Gamma>\<turnstile> \<lbrace>\<acute>A = 0\<rbrace>
\<lbrace>\<acute>A < 0\<rbrace> \<longmapsto> BASIC
LET (a,b,c) = foo \<acute>A
IN
\<acute>A :== a,
\<acute>G :== b + \<acute>B,
\<acute>H :== c
END
\<lbrace>\<acute>A = x \<and> \<acute>G = y \<and> \<acute>H = c\<rbrace>"
apply (vcg add: foo_def snd_conv fst_conv)
oops
end
|
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro
-/
import algebra.invertible
import algebra.order.group
import algebra.order.sub
import data.set.intervals.basic
/-!
# Ordered rings and semirings
This file develops the basics of ordered (semi)rings.
Each typeclass here comprises
* an algebraic class (`semiring`, `comm_semiring`, `ring`, `comm_ring`)
* an order class (`partial_order`, `linear_order`)
* assumptions on how both interact ((strict) monotonicity, canonicity)
For short,
* "`+` respects `≤`" means "monotonicity of addition"
* "`*` respects `<`" means "strict monotonicity of multiplication by a positive number".
## Typeclasses
* `ordered_semiring`: Semiring with a partial order such that `+` respects `≤` and `*` respects `<`.
* `ordered_comm_semiring`: Commutative semiring with a partial order such that `+` respects `≤` and
`*` respects `<`.
* `ordered_ring`: Ring with a partial order such that `+` respects `≤` and `*` respects `<`.
* `ordered_comm_ring`: Commutative ring with a partial order such that `+` respects `≤` and
`*` respects `<`.
* `linear_ordered_semiring`: Semiring with a linear order such that `+` respects `≤` and
`*` respects `<`.
* `linear_ordered_ring`: Ring with a linear order such that `+` respects `≤` and `*` respects `<`.
* `linear_ordered_comm_ring`: Commutative ring with a linear order such that `+` respects `≤` and
`*` respects `<`.
* `canonically_ordered_comm_semiring`: Commutative semiring with a partial order such that `+`
respects `≤`, `*` respects `<`, and `a ≤ b ↔ ∃ c, b = a + c`.
and some typeclasses to define ordered rings by specifying their nonegative elements:
* `nonneg_ring`: To define `ordered_ring`s.
* `linear_nonneg_ring`: To define `linear_ordered_ring`s.
## Hierarchy
The hardest part of proving order lemmas might be to figure out the correct generality and its
corresponding typeclass. Here's an attempt at demystifying it. For each typeclass, we list its
immediate predecessors and what conditions are added to each of them.
* `ordered_semiring`
- `ordered_cancel_add_comm_monoid` & multiplication & `*` respects `<`
- `semiring` & partial order structure & `+` respects `≤` & `*` respects `<`
* `ordered_comm_semiring`
- `ordered_semiring` & commutativity of multiplication
- `comm_semiring` & partial order structure & `+` respects `≤` & `*` respects `<`
* `ordered_ring`
- `ordered_semiring` & additive inverses
- `ordered_add_comm_group` & multiplication & `*` respects `<`
- `ring` & partial order structure & `+` respects `≤` & `*` respects `<`
* `ordered_comm_ring`
- `ordered_ring` & commutativity of multiplication
- `ordered_comm_semiring` & additive inverses
- `comm_ring` & partial order structure & `+` respects `≤` & `*` respects `<`
* `linear_ordered_semiring`
- `ordered_semiring` & totality of the order & nontriviality
- `linear_ordered_add_comm_monoid` & multiplication & nontriviality & `*` respects `<`
* `linear_ordered_ring`
- `ordered_ring` & totality of the order & nontriviality
- `linear_ordered_semiring` & additive inverses
- `linear_ordered_add_comm_group` & multiplication & `*` respects `<`
- `domain` & linear order structure
* `linear_ordered_comm_ring`
- `ordered_comm_ring` & totality of the order & nontriviality
- `linear_ordered_ring` & commutativity of multiplication
- `is_domain` & linear order structure
* `canonically_ordered_comm_semiring`
- `canonically_ordered_add_monoid` & multiplication & `*` respects `<` & no zero divisors
- `comm_semiring` & `a ≤ b ↔ ∃ c, b = a + c` & no zero divisors
## TODO
We're still missing some typeclasses, like
* `linear_ordered_comm_semiring`
* `canonically_ordered_semiring`
They have yet to come up in practice.
-/
set_option old_structure_cmd true
universe u
variable {α : Type u}
lemma add_one_le_two_mul [preorder α] [semiring α] [covariant_class α α (+) (≤)]
{a : α} (a1 : 1 ≤ a) :
a + 1 ≤ 2 * a :=
calc a + 1 ≤ a + a : add_le_add_left a1 a
... = 2 * a : (two_mul _).symm
/-- An `ordered_semiring α` is a semiring `α` with a partial order such that
addition is monotone and multiplication by a positive number is strictly monotone. -/
@[protect_proj]
class ordered_semiring (α : Type u) extends semiring α, ordered_cancel_add_comm_monoid α :=
(zero_le_one : 0 ≤ (1 : α))
(mul_lt_mul_of_pos_left : ∀ a b c : α, a < b → 0 < c → c * a < c * b)
(mul_lt_mul_of_pos_right : ∀ a b c : α, a < b → 0 < c → a * c < b * c)
section ordered_semiring
variables [ordered_semiring α] {a b c d : α}
@[simp] lemma zero_le_one : 0 ≤ (1:α) :=
ordered_semiring.zero_le_one
lemma zero_le_two : 0 ≤ (2:α) :=
add_nonneg zero_le_one zero_le_one
lemma one_le_two : 1 ≤ (2:α) :=
calc (1:α) = 0 + 1 : (zero_add _).symm
... ≤ 1 + 1 : add_le_add_right zero_le_one _
section nontrivial
variables [nontrivial α]
@[simp] lemma zero_lt_one : 0 < (1 : α) :=
lt_of_le_of_ne zero_le_one zero_ne_one
lemma zero_lt_two : 0 < (2:α) := add_pos zero_lt_one zero_lt_one
@[field_simps] lemma two_ne_zero : (2:α) ≠ 0 :=
ne.symm (ne_of_lt zero_lt_two)
lemma one_lt_two : 1 < (2:α) :=
calc (2:α) = 1+1 : one_add_one_eq_two
... > 1+0 : add_lt_add_left zero_lt_one _
... = 1 : add_zero 1
lemma zero_lt_three : 0 < (3:α) := add_pos zero_lt_two zero_lt_one
lemma zero_lt_four : 0 < (4:α) := add_pos zero_lt_two zero_lt_two
end nontrivial
lemma mul_lt_mul_of_pos_left (h₁ : a < b) (h₂ : 0 < c) : c * a < c * b :=
ordered_semiring.mul_lt_mul_of_pos_left a b c h₁ h₂
lemma mul_lt_mul_of_pos_right (h₁ : a < b) (h₂ : 0 < c) : a * c < b * c :=
ordered_semiring.mul_lt_mul_of_pos_right a b c h₁ h₂
-- See Note [decidable namespace]
protected lemma decidable.mul_le_mul_of_nonneg_left [@decidable_rel α (≤)]
(h₁ : a ≤ b) (h₂ : 0 ≤ c) : c * a ≤ c * b :=
begin
by_cases ba : b ≤ a, { simp [ba.antisymm h₁] },
by_cases c0 : c ≤ 0, { simp [c0.antisymm h₂] },
exact (mul_lt_mul_of_pos_left (h₁.lt_of_not_le ba) (h₂.lt_of_not_le c0)).le,
end
lemma mul_le_mul_of_nonneg_left : a ≤ b → 0 ≤ c → c * a ≤ c * b :=
by classical; exact decidable.mul_le_mul_of_nonneg_left
-- See Note [decidable namespace]
protected lemma decidable.mul_le_mul_of_nonneg_right [@decidable_rel α (≤)]
(h₁ : a ≤ b) (h₂ : 0 ≤ c) : a * c ≤ b * c :=
begin
by_cases ba : b ≤ a, { simp [ba.antisymm h₁] },
by_cases c0 : c ≤ 0, { simp [c0.antisymm h₂] },
exact (mul_lt_mul_of_pos_right (h₁.lt_of_not_le ba) (h₂.lt_of_not_le c0)).le,
end
lemma mul_le_mul_of_nonneg_right : a ≤ b → 0 ≤ c → a * c ≤ b * c :=
by classical; exact decidable.mul_le_mul_of_nonneg_right
-- TODO: there are four variations, depending on which variables we assume to be nonneg
-- See Note [decidable namespace]
protected lemma decidable.mul_le_mul [@decidable_rel α (≤)]
(hac : a ≤ c) (hbd : b ≤ d) (nn_b : 0 ≤ b) (nn_c : 0 ≤ c) : a * b ≤ c * d :=
calc
a * b ≤ c * b : decidable.mul_le_mul_of_nonneg_right hac nn_b
... ≤ c * d : decidable.mul_le_mul_of_nonneg_left hbd nn_c
lemma mul_le_mul : a ≤ c → b ≤ d → 0 ≤ b → 0 ≤ c → a * b ≤ c * d :=
by classical; exact decidable.mul_le_mul
-- See Note [decidable namespace]
protected lemma decidable.mul_nonneg_le_one_le {α : Type*} [ordered_semiring α]
[@decidable_rel α (≤)] {a b c : α}
(h₁ : 0 ≤ c) (h₂ : a ≤ c) (h₃ : 0 ≤ b) (h₄ : b ≤ 1) : a * b ≤ c :=
by simpa only [mul_one] using decidable.mul_le_mul h₂ h₄ h₃ h₁
lemma mul_nonneg_le_one_le {α : Type*} [ordered_semiring α] {a b c : α} :
0 ≤ c → a ≤ c → 0 ≤ b → b ≤ 1 → a * b ≤ c :=
by classical; exact decidable.mul_nonneg_le_one_le
-- See Note [decidable namespace]
protected lemma decidable.mul_nonneg [@decidable_rel α (≤)]
(ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b :=
have h : 0 * b ≤ a * b, from decidable.mul_le_mul_of_nonneg_right ha hb,
by rwa [zero_mul] at h
lemma mul_nonneg : 0 ≤ a → 0 ≤ b → 0 ≤ a * b := by classical; exact decidable.mul_nonneg
-- See Note [decidable namespace]
protected lemma decidable.mul_nonpos_of_nonneg_of_nonpos [@decidable_rel α (≤)]
(ha : 0 ≤ a) (hb : b ≤ 0) : a * b ≤ 0 :=
have h : a * b ≤ a * 0, from decidable.mul_le_mul_of_nonneg_left hb ha,
by rwa mul_zero at h
lemma mul_nonpos_of_nonneg_of_nonpos : 0 ≤ a → b ≤ 0 → a * b ≤ 0 :=
by classical; exact decidable.mul_nonpos_of_nonneg_of_nonpos
-- See Note [decidable namespace]
protected lemma decidable.mul_nonpos_of_nonpos_of_nonneg [@decidable_rel α (≤)]
(ha : a ≤ 0) (hb : 0 ≤ b) : a * b ≤ 0 :=
have h : a * b ≤ 0 * b, from decidable.mul_le_mul_of_nonneg_right ha hb,
by rwa zero_mul at h
lemma mul_nonpos_of_nonpos_of_nonneg : a ≤ 0 → 0 ≤ b → a * b ≤ 0 :=
by classical; exact decidable.mul_nonpos_of_nonpos_of_nonneg
-- See Note [decidable namespace]
protected lemma decidable.mul_lt_mul [@decidable_rel α (≤)]
(hac : a < c) (hbd : b ≤ d) (pos_b : 0 < b) (nn_c : 0 ≤ c) : a * b < c * d :=
calc
a * b < c * b : mul_lt_mul_of_pos_right hac pos_b
... ≤ c * d : decidable.mul_le_mul_of_nonneg_left hbd nn_c
lemma mul_lt_mul : a < c → b ≤ d → 0 < b → 0 ≤ c → a * b < c * d :=
by classical; exact decidable.mul_lt_mul
-- See Note [decidable namespace]
protected lemma decidable.mul_lt_mul' [@decidable_rel α (≤)]
(h1 : a ≤ c) (h2 : b < d) (h3 : 0 ≤ b) (h4 : 0 < c) : a * b < c * d :=
calc
a * b ≤ c * b : decidable.mul_le_mul_of_nonneg_right h1 h3
... < c * d : mul_lt_mul_of_pos_left h2 h4
lemma mul_lt_mul' : a ≤ c → b < d → 0 ≤ b → 0 < c → a * b < c * d :=
by classical; exact decidable.mul_lt_mul'
lemma mul_pos (ha : 0 < a) (hb : 0 < b) : 0 < a * b :=
have h : 0 * b < a * b, from mul_lt_mul_of_pos_right ha hb,
by rwa zero_mul at h
lemma mul_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a * b < 0 :=
have h : a * b < a * 0, from mul_lt_mul_of_pos_left hb ha,
by rwa mul_zero at h
lemma mul_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a * b < 0 :=
have h : a * b < 0 * b, from mul_lt_mul_of_pos_right ha hb,
by rwa zero_mul at h
-- See Note [decidable namespace]
protected lemma decidable.mul_self_lt_mul_self [@decidable_rel α (≤)]
(h1 : 0 ≤ a) (h2 : a < b) : a * a < b * b :=
decidable.mul_lt_mul' h2.le h2 h1 $ h1.trans_lt h2
lemma mul_self_lt_mul_self (h1 : 0 ≤ a) (h2 : a < b) : a * a < b * b :=
mul_lt_mul' h2.le h2 h1 $ h1.trans_lt h2
-- See Note [decidable namespace]
protected lemma decidable.strict_mono_on_mul_self [@decidable_rel α (≤)] :
strict_mono_on (λ x : α, x * x) (set.Ici 0) :=
λ x hx y hy hxy, decidable.mul_self_lt_mul_self hx hxy
lemma strict_mono_on_mul_self : strict_mono_on (λ x : α, x * x) (set.Ici 0) :=
λ x hx y hy hxy, mul_self_lt_mul_self hx hxy
-- See Note [decidable namespace]
protected lemma decidable.mul_self_le_mul_self [@decidable_rel α (≤)]
(h1 : 0 ≤ a) (h2 : a ≤ b) : a * a ≤ b * b :=
decidable.mul_le_mul h2 h2 h1 $ h1.trans h2
lemma mul_self_le_mul_self (h1 : 0 ≤ a) (h2 : a ≤ b) : a * a ≤ b * b :=
mul_le_mul h2 h2 h1 $ h1.trans h2
-- See Note [decidable namespace]
protected lemma decidable.mul_lt_mul'' [@decidable_rel α (≤)]
(h1 : a < c) (h2 : b < d) (h3 : 0 ≤ a) (h4 : 0 ≤ b) : a * b < c * d :=
h4.lt_or_eq_dec.elim
(λ b0, decidable.mul_lt_mul h1 h2.le b0 $ h3.trans h1.le)
(λ b0, by rw [← b0, mul_zero]; exact
mul_pos (h3.trans_lt h1) (h4.trans_lt h2))
lemma mul_lt_mul'' : a < c → b < d → 0 ≤ a → 0 ≤ b → a * b < c * d :=
by classical; exact decidable.mul_lt_mul''
-- See Note [decidable namespace]
protected lemma decidable.le_mul_of_one_le_right [@decidable_rel α (≤)]
(hb : 0 ≤ b) (h : 1 ≤ a) : b ≤ b * a :=
suffices b * 1 ≤ b * a, by rwa mul_one at this,
decidable.mul_le_mul_of_nonneg_left h hb
lemma le_mul_of_one_le_right : 0 ≤ b → 1 ≤ a → b ≤ b * a :=
by classical; exact decidable.le_mul_of_one_le_right
-- See Note [decidable namespace]
protected lemma decidable.le_mul_of_one_le_left [@decidable_rel α (≤)]
(hb : 0 ≤ b) (h : 1 ≤ a) : b ≤ a * b :=
suffices 1 * b ≤ a * b, by rwa one_mul at this,
decidable.mul_le_mul_of_nonneg_right h hb
lemma le_mul_of_one_le_left : 0 ≤ b → 1 ≤ a → b ≤ a * b :=
by classical; exact decidable.le_mul_of_one_le_left
-- See Note [decidable namespace]
protected lemma decidable.lt_mul_of_one_lt_right [@decidable_rel α (≤)]
(hb : 0 < b) (h : 1 < a) : b < b * a :=
suffices b * 1 < b * a, by rwa mul_one at this,
decidable.mul_lt_mul' (le_refl _) h zero_le_one hb
lemma lt_mul_of_one_lt_right : 0 < b → 1 < a → b < b * a :=
by classical; exact decidable.lt_mul_of_one_lt_right
-- See Note [decidable namespace]
protected lemma decidable.lt_mul_of_one_lt_left [@decidable_rel α (≤)]
(hb : 0 < b) (h : 1 < a) : b < a * b :=
suffices 1 * b < a * b, by rwa one_mul at this,
decidable.mul_lt_mul h (le_refl _) hb (zero_le_one.trans h.le)
lemma lt_mul_of_one_lt_left : 0 < b → 1 < a → b < a * b :=
by classical; exact decidable.lt_mul_of_one_lt_left
-- See Note [decidable namespace]
protected lemma decidable.add_le_mul_two_add [@decidable_rel α (≤)] {a b : α}
(a2 : 2 ≤ a) (b0 : 0 ≤ b) : a + (2 + b) ≤ a * (2 + b) :=
calc a + (2 + b) ≤ a + (a + a * b) :
add_le_add_left (add_le_add a2 (decidable.le_mul_of_one_le_left b0 (one_le_two.trans a2))) a
... ≤ a * (2 + b) : by rw [mul_add, mul_two, add_assoc]
lemma add_le_mul_two_add {a b : α} : 2 ≤ a → 0 ≤ b → a + (2 + b) ≤ a * (2 + b) :=
by classical; exact decidable.add_le_mul_two_add
-- See Note [decidable namespace]
protected lemma decidable.one_le_mul_of_one_le_of_one_le [@decidable_rel α (≤)]
{a b : α} (a1 : 1 ≤ a) (b1 : 1 ≤ b) : (1 : α) ≤ a * b :=
(mul_one (1 : α)).symm.le.trans (decidable.mul_le_mul a1 b1 zero_le_one (zero_le_one.trans a1))
lemma one_le_mul_of_one_le_of_one_le {a b : α} : 1 ≤ a → 1 ≤ b → (1 : α) ≤ a * b :=
by classical; exact decidable.one_le_mul_of_one_le_of_one_le
/-- Pullback an `ordered_semiring` under an injective map.
See note [reducible non-instances]. -/
@[reducible]
def function.injective.ordered_semiring {β : Type*}
[has_zero β] [has_one β] [has_add β] [has_mul β]
(f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) :
ordered_semiring β :=
{ zero_le_one := show f 0 ≤ f 1, by simp only [zero, one, zero_le_one],
mul_lt_mul_of_pos_left := λ a b c ab c0, show f (c * a) < f (c * b),
begin
rw [mul, mul],
refine mul_lt_mul_of_pos_left ab _,
rwa ← zero,
end,
mul_lt_mul_of_pos_right := λ a b c ab c0, show f (a * c) < f (b * c),
begin
rw [mul, mul],
refine mul_lt_mul_of_pos_right ab _,
rwa ← zero,
end,
..hf.ordered_cancel_add_comm_monoid f zero add,
..hf.semiring f zero one add mul }
section
variable [nontrivial α]
lemma bit1_pos (h : 0 ≤ a) : 0 < bit1 a :=
lt_add_of_le_of_pos (add_nonneg h h) zero_lt_one
lemma lt_add_one (a : α) : a < a + 1 :=
lt_add_of_le_of_pos le_rfl zero_lt_one
lemma lt_one_add (a : α) : a < 1 + a :=
by { rw [add_comm], apply lt_add_one }
end
lemma bit1_pos' (h : 0 < a) : 0 < bit1 a :=
begin
nontriviality,
exact bit1_pos h.le,
end
-- See Note [decidable namespace]
protected lemma decidable.one_lt_mul [@decidable_rel α (≤)]
(ha : 1 ≤ a) (hb : 1 < b) : 1 < a * b :=
begin
nontriviality,
exact (one_mul (1 : α)) ▸ decidable.mul_lt_mul' ha hb zero_le_one (zero_lt_one.trans_le ha)
end
lemma one_lt_mul : 1 ≤ a → 1 < b → 1 < a * b :=
by classical; exact decidable.one_lt_mul
-- See Note [decidable namespace]
protected lemma decidable.mul_le_one [@decidable_rel α (≤)]
(ha : a ≤ 1) (hb' : 0 ≤ b) (hb : b ≤ 1) : a * b ≤ 1 :=
begin rw ← one_mul (1 : α), apply decidable.mul_le_mul; {assumption <|> apply zero_le_one} end
lemma mul_le_one : a ≤ 1 → 0 ≤ b → b ≤ 1 → a * b ≤ 1 :=
by classical; exact decidable.mul_le_one
-- See Note [decidable namespace]
protected lemma decidable.one_lt_mul_of_le_of_lt [@decidable_rel α (≤)]
(ha : 1 ≤ a) (hb : 1 < b) : 1 < a * b :=
begin
nontriviality,
calc 1 = 1 * 1 : by rw one_mul
... < a * b : decidable.mul_lt_mul' ha hb zero_le_one (zero_lt_one.trans_le ha)
end
lemma one_lt_mul_of_le_of_lt : 1 ≤ a → 1 < b → 1 < a * b :=
by classical; exact decidable.one_lt_mul_of_le_of_lt
-- See Note [decidable namespace]
protected lemma decidable.one_lt_mul_of_lt_of_le [@decidable_rel α (≤)]
(ha : 1 < a) (hb : 1 ≤ b) : 1 < a * b :=
begin
nontriviality,
calc 1 = 1 * 1 : by rw one_mul
... < a * b : decidable.mul_lt_mul ha hb zero_lt_one $ zero_le_one.trans ha.le
end
lemma one_lt_mul_of_lt_of_le : 1 < a → 1 ≤ b → 1 < a * b :=
by classical; exact decidable.one_lt_mul_of_lt_of_le
-- See Note [decidable namespace]
protected lemma decidable.mul_le_of_le_one_right [@decidable_rel α (≤)]
(ha : 0 ≤ a) (hb1 : b ≤ 1) : a * b ≤ a :=
calc a * b ≤ a * 1 : decidable.mul_le_mul_of_nonneg_left hb1 ha
... = a : mul_one a
lemma mul_le_of_le_one_right : 0 ≤ a → b ≤ 1 → a * b ≤ a :=
by classical; exact decidable.mul_le_of_le_one_right
-- See Note [decidable namespace]
protected lemma decidable.mul_le_of_le_one_left [@decidable_rel α (≤)]
(hb : 0 ≤ b) (ha1 : a ≤ 1) : a * b ≤ b :=
calc a * b ≤ 1 * b : decidable.mul_le_mul ha1 le_rfl hb zero_le_one
... = b : one_mul b
lemma mul_le_of_le_one_left : 0 ≤ b → a ≤ 1 → a * b ≤ b :=
by classical; exact decidable.mul_le_of_le_one_left
-- See Note [decidable namespace]
protected lemma decidable.mul_lt_one_of_nonneg_of_lt_one_left [@decidable_rel α (≤)]
(ha0 : 0 ≤ a) (ha : a < 1) (hb : b ≤ 1) : a * b < 1 :=
calc a * b ≤ a : decidable.mul_le_of_le_one_right ha0 hb
... < 1 : ha
lemma mul_lt_one_of_nonneg_of_lt_one_left : 0 ≤ a → a < 1 → b ≤ 1 → a * b < 1 :=
by classical; exact decidable.mul_lt_one_of_nonneg_of_lt_one_left
-- See Note [decidable namespace]
protected lemma decidable.mul_lt_one_of_nonneg_of_lt_one_right [@decidable_rel α (≤)]
(ha : a ≤ 1) (hb0 : 0 ≤ b) (hb : b < 1) : a * b < 1 :=
calc a * b ≤ b : decidable.mul_le_of_le_one_left hb0 ha
... < 1 : hb
lemma mul_lt_one_of_nonneg_of_lt_one_right : a ≤ 1 → 0 ≤ b → b < 1 → a * b < 1 :=
by classical; exact decidable.mul_lt_one_of_nonneg_of_lt_one_right
end ordered_semiring
section ordered_comm_semiring
/-- An `ordered_comm_semiring α` is a commutative semiring `α` with a partial order such that
addition is monotone and multiplication by a positive number is strictly monotone. -/
@[protect_proj]
class ordered_comm_semiring (α : Type u) extends ordered_semiring α, comm_semiring α
/-- Pullback an `ordered_comm_semiring` under an injective map.
See note [reducible non-instances]. -/
@[reducible]
def function.injective.ordered_comm_semiring [ordered_comm_semiring α] {β : Type*}
[has_zero β] [has_one β] [has_add β] [has_mul β]
(f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) :
ordered_comm_semiring β :=
{ ..hf.comm_semiring f zero one add mul,
..hf.ordered_semiring f zero one add mul }
end ordered_comm_semiring
/--
A `linear_ordered_semiring α` is a nontrivial semiring `α` with a linear order
such that addition is monotone and multiplication by a positive number is strictly monotone.
-/
-- It's not entirely clear we should assume `nontrivial` at this point;
-- it would be reasonable to explore changing this,
-- but be warned that the instances involving `domain` may cause
-- typeclass search loops.
@[protect_proj]
class linear_ordered_semiring (α : Type u)
extends ordered_semiring α, linear_ordered_add_comm_monoid α, nontrivial α
section linear_ordered_semiring
variables [linear_ordered_semiring α] {a b c d : α}
-- `norm_num` expects the lemma stating `0 < 1` to have a single typeclass argument
-- (see `norm_num.prove_pos_nat`).
-- Rather than working out how to relax that assumption,
-- we provide a synonym for `zero_lt_one` (which needs both `ordered_semiring α` and `nontrivial α`)
-- with only a `linear_ordered_semiring` typeclass argument.
lemma zero_lt_one' : 0 < (1 : α) := zero_lt_one
lemma lt_of_mul_lt_mul_left (h : c * a < c * b) (hc : 0 ≤ c) : a < b :=
by haveI := @linear_order.decidable_le α _; exact lt_of_not_ge
(assume h1 : b ≤ a,
have h2 : c * b ≤ c * a, from decidable.mul_le_mul_of_nonneg_left h1 hc,
h2.not_lt h)
lemma lt_of_mul_lt_mul_right (h : a * c < b * c) (hc : 0 ≤ c) : a < b :=
by haveI := @linear_order.decidable_le α _; exact lt_of_not_ge
(assume h1 : b ≤ a,
have h2 : b * c ≤ a * c, from decidable.mul_le_mul_of_nonneg_right h1 hc,
h2.not_lt h)
lemma le_of_mul_le_mul_left (h : c * a ≤ c * b) (hc : 0 < c) : a ≤ b :=
le_of_not_gt
(assume h1 : b < a,
have h2 : c * b < c * a, from mul_lt_mul_of_pos_left h1 hc,
h2.not_le h)
lemma le_of_mul_le_mul_right (h : a * c ≤ b * c) (hc : 0 < c) : a ≤ b :=
le_of_not_gt
(assume h1 : b < a,
have h2 : b * c < a * c, from mul_lt_mul_of_pos_right h1 hc,
h2.not_le h)
lemma pos_and_pos_or_neg_and_neg_of_mul_pos (hab : 0 < a * b) :
(0 < a ∧ 0 < b) ∨ (a < 0 ∧ b < 0) :=
begin
haveI := @linear_order.decidable_le α _,
rcases lt_trichotomy 0 a with (ha|rfl|ha),
{ refine or.inl ⟨ha, lt_imp_lt_of_le_imp_le (λ hb, _) hab⟩,
exact decidable.mul_nonpos_of_nonneg_of_nonpos ha.le hb },
{ rw [zero_mul] at hab, exact hab.false.elim },
{ refine or.inr ⟨ha, lt_imp_lt_of_le_imp_le (λ hb, _) hab⟩,
exact decidable.mul_nonpos_of_nonpos_of_nonneg ha.le hb }
end
lemma nonneg_and_nonneg_or_nonpos_and_nonpos_of_mul_nnonneg (hab : 0 ≤ a * b) :
(0 ≤ a ∧ 0 ≤ b) ∨ (a ≤ 0 ∧ b ≤ 0) :=
begin
haveI := @linear_order.decidable_le α _,
refine decidable.or_iff_not_and_not.2 _,
simp only [not_and, not_le], intros ab nab, apply not_lt_of_le hab _,
rcases lt_trichotomy 0 a with (ha|rfl|ha),
exacts [mul_neg_of_pos_of_neg ha (ab ha.le), ((ab le_rfl).asymm (nab le_rfl)).elim,
mul_neg_of_neg_of_pos ha (nab ha.le)]
end
lemma pos_of_mul_pos_left (h : 0 < a * b) (ha : 0 ≤ a) : 0 < b :=
((pos_and_pos_or_neg_and_neg_of_mul_pos h).resolve_right $ λ h, h.1.not_le ha).2
lemma pos_of_mul_pos_right (h : 0 < a * b) (hb : 0 ≤ b) : 0 < a :=
((pos_and_pos_or_neg_and_neg_of_mul_pos h).resolve_right $ λ h, h.2.not_le hb).1
@[simp] lemma inv_of_pos [invertible a] : 0 < ⅟a ↔ 0 < a :=
begin
have : 0 < a * ⅟a, by simp only [mul_inv_of_self, zero_lt_one],
exact ⟨λ h, pos_of_mul_pos_right this h.le, λ h, pos_of_mul_pos_left this h.le⟩
end
@[simp] lemma inv_of_nonpos [invertible a] : ⅟a ≤ 0 ↔ a ≤ 0 :=
by simp only [← not_lt, inv_of_pos]
lemma nonneg_of_mul_nonneg_left (h : 0 ≤ a * b) (h1 : 0 < a) : 0 ≤ b :=
le_of_not_gt (assume h2 : b < 0, (mul_neg_of_pos_of_neg h1 h2).not_le h)
lemma nonneg_of_mul_nonneg_right (h : 0 ≤ a * b) (h1 : 0 < b) : 0 ≤ a :=
le_of_not_gt (assume h2 : a < 0, (mul_neg_of_neg_of_pos h2 h1).not_le h)
@[simp] lemma inv_of_nonneg [invertible a] : 0 ≤ ⅟a ↔ 0 ≤ a :=
begin
have : 0 < a * ⅟a, by simp only [mul_inv_of_self, zero_lt_one],
exact ⟨λ h, (pos_of_mul_pos_right this h).le, λ h, (pos_of_mul_pos_left this h).le⟩
end
@[simp] lemma inv_of_lt_zero [invertible a] : ⅟a < 0 ↔ a < 0 :=
by simp only [← not_le, inv_of_nonneg]
@[simp] lemma inv_of_le_one [invertible a] (h : 1 ≤ a) : ⅟a ≤ 1 :=
by haveI := @linear_order.decidable_le α _; exact
mul_inv_of_self a ▸ decidable.le_mul_of_one_le_left (inv_of_nonneg.2 $ zero_le_one.trans h) h
lemma neg_of_mul_neg_left (h : a * b < 0) (h1 : 0 ≤ a) : b < 0 :=
by haveI := @linear_order.decidable_le α _; exact
lt_of_not_ge (assume h2 : b ≥ 0, (decidable.mul_nonneg h1 h2).not_lt h)
lemma neg_of_mul_neg_right (h : a * b < 0) (h1 : 0 ≤ b) : a < 0 :=
by haveI := @linear_order.decidable_le α _; exact
lt_of_not_ge (assume h2 : a ≥ 0, (decidable.mul_nonneg h2 h1).not_lt h)
lemma nonpos_of_mul_nonpos_left (h : a * b ≤ 0) (h1 : 0 < a) : b ≤ 0 :=
le_of_not_gt (assume h2 : b > 0, (mul_pos h1 h2).not_le h)
lemma nonpos_of_mul_nonpos_right (h : a * b ≤ 0) (h1 : 0 < b) : a ≤ 0 :=
le_of_not_gt (assume h2 : a > 0, (mul_pos h2 h1).not_le h)
@[simp] lemma mul_le_mul_left (h : 0 < c) : c * a ≤ c * b ↔ a ≤ b :=
by haveI := @linear_order.decidable_le α _; exact
⟨λ h', le_of_mul_le_mul_left h' h, λ h', decidable.mul_le_mul_of_nonneg_left h' h.le⟩
@[simp] lemma mul_le_mul_right (h : 0 < c) : a * c ≤ b * c ↔ a ≤ b :=
by haveI := @linear_order.decidable_le α _; exact
⟨λ h', le_of_mul_le_mul_right h' h, λ h', decidable.mul_le_mul_of_nonneg_right h' h.le⟩
@[simp] lemma mul_lt_mul_left (h : 0 < c) : c * a < c * b ↔ a < b :=
by haveI := @linear_order.decidable_le α _; exact
⟨lt_imp_lt_of_le_imp_le $ λ h', decidable.mul_le_mul_of_nonneg_left h' h.le,
λ h', mul_lt_mul_of_pos_left h' h⟩
@[simp] lemma mul_lt_mul_right (h : 0 < c) : a * c < b * c ↔ a < b :=
by haveI := @linear_order.decidable_le α _; exact
⟨lt_imp_lt_of_le_imp_le $ λ h', decidable.mul_le_mul_of_nonneg_right h' h.le,
λ h', mul_lt_mul_of_pos_right h' h⟩
@[simp] lemma zero_le_mul_left (h : 0 < c) : 0 ≤ c * b ↔ 0 ≤ b :=
by { convert mul_le_mul_left h, simp }
@[simp] lemma zero_le_mul_right (h : 0 < c) : 0 ≤ b * c ↔ 0 ≤ b :=
by { convert mul_le_mul_right h, simp }
@[simp] lemma zero_lt_mul_left (h : 0 < c) : 0 < c * b ↔ 0 < b :=
by { convert mul_lt_mul_left h, simp }
@[simp] lemma zero_lt_mul_right (h : 0 < c) : 0 < b * c ↔ 0 < b :=
by { convert mul_lt_mul_right h, simp }
lemma add_le_mul_of_left_le_right (a2 : 2 ≤ a) (ab : a ≤ b) : a + b ≤ a * b :=
have 0 < b, from
calc 0 < 2 : zero_lt_two
... ≤ a : a2
... ≤ b : ab,
calc a + b ≤ b + b : add_le_add_right ab b
... = 2 * b : (two_mul b).symm
... ≤ a * b : (mul_le_mul_right this).mpr a2
lemma add_le_mul_of_right_le_left (b2 : 2 ≤ b) (ba : b ≤ a) : a + b ≤ a * b :=
have 0 < a, from
calc 0 < 2 : zero_lt_two
... ≤ b : b2
... ≤ a : ba,
calc a + b ≤ a + a : add_le_add_left ba a
... = a * 2 : (mul_two a).symm
... ≤ a * b : (mul_le_mul_left this).mpr b2
lemma add_le_mul (a2 : 2 ≤ a) (b2 : 2 ≤ b) : a + b ≤ a * b :=
if hab : a ≤ b then add_le_mul_of_left_le_right a2 hab
else add_le_mul_of_right_le_left b2 (le_of_not_le hab)
lemma add_le_mul' (a2 : 2 ≤ a) (b2 : 2 ≤ b) : a + b ≤ b * a :=
(le_of_eq (add_comm _ _)).trans (add_le_mul b2 a2)
section
variables [nontrivial α]
@[simp] lemma bit0_le_bit0 : bit0 a ≤ bit0 b ↔ a ≤ b :=
by rw [bit0, bit0, ← two_mul, ← two_mul, mul_le_mul_left (zero_lt_two : 0 < (2:α))]
@[simp] lemma bit0_lt_bit0 : bit0 a < bit0 b ↔ a < b :=
by rw [bit0, bit0, ← two_mul, ← two_mul, mul_lt_mul_left (zero_lt_two : 0 < (2:α))]
@[simp] lemma bit1_le_bit1 : bit1 a ≤ bit1 b ↔ a ≤ b :=
(add_le_add_iff_right 1).trans bit0_le_bit0
@[simp] lemma bit1_lt_bit1 : bit1 a < bit1 b ↔ a < b :=
(add_lt_add_iff_right 1).trans bit0_lt_bit0
@[simp] lemma one_le_bit1 : (1 : α) ≤ bit1 a ↔ 0 ≤ a :=
by rw [bit1, le_add_iff_nonneg_left, bit0, ← two_mul, zero_le_mul_left (zero_lt_two : 0 < (2:α))]
@[simp] lemma one_lt_bit1 : (1 : α) < bit1 a ↔ 0 < a :=
by rw [bit1, lt_add_iff_pos_left, bit0, ← two_mul, zero_lt_mul_left (zero_lt_two : 0 < (2:α))]
@[simp] lemma zero_le_bit0 : (0 : α) ≤ bit0 a ↔ 0 ≤ a :=
by rw [bit0, ← two_mul, zero_le_mul_left (zero_lt_two : 0 < (2:α))]
@[simp] lemma zero_lt_bit0 : (0 : α) < bit0 a ↔ 0 < a :=
by rw [bit0, ← two_mul, zero_lt_mul_left (zero_lt_two : 0 < (2:α))]
end
lemma le_mul_iff_one_le_left (hb : 0 < b) : b ≤ a * b ↔ 1 ≤ a :=
suffices 1 * b ≤ a * b ↔ 1 ≤ a, by rwa one_mul at this,
mul_le_mul_right hb
lemma lt_mul_iff_one_lt_left (hb : 0 < b) : b < a * b ↔ 1 < a :=
suffices 1 * b < a * b ↔ 1 < a, by rwa one_mul at this,
mul_lt_mul_right hb
lemma le_mul_iff_one_le_right (hb : 0 < b) : b ≤ b * a ↔ 1 ≤ a :=
suffices b * 1 ≤ b * a ↔ 1 ≤ a, by rwa mul_one at this,
mul_le_mul_left hb
lemma lt_mul_iff_one_lt_right (hb : 0 < b) : b < b * a ↔ 1 < a :=
suffices b * 1 < b * a ↔ 1 < a, by rwa mul_one at this,
mul_lt_mul_left hb
theorem mul_nonneg_iff_right_nonneg_of_pos (ha : 0 < a) : 0 ≤ a * b ↔ 0 ≤ b :=
by haveI := @linear_order.decidable_le α _; exact
⟨λ h, nonneg_of_mul_nonneg_left h ha, λ h, decidable.mul_nonneg ha.le h⟩
theorem mul_nonneg_iff_left_nonneg_of_pos (hb : 0 < b) : 0 ≤ a * b ↔ 0 ≤ a :=
by haveI := @linear_order.decidable_le α _; exact
⟨λ h, nonneg_of_mul_nonneg_right h hb, λ h, decidable.mul_nonneg h hb.le⟩
lemma mul_le_iff_le_one_left (hb : 0 < b) : a * b ≤ b ↔ a ≤ 1 :=
⟨ λ h, le_of_not_lt (mt (lt_mul_iff_one_lt_left hb).2 h.not_lt),
λ h, le_of_not_lt (mt (lt_mul_iff_one_lt_left hb).1 h.not_lt) ⟩
lemma mul_lt_iff_lt_one_left (hb : 0 < b) : a * b < b ↔ a < 1 :=
lt_iff_lt_of_le_iff_le $ le_mul_iff_one_le_left hb
lemma mul_le_iff_le_one_right (hb : 0 < b) : b * a ≤ b ↔ a ≤ 1 :=
⟨ λ h, le_of_not_lt (mt (lt_mul_iff_one_lt_right hb).2 h.not_lt),
λ h, le_of_not_lt (mt (lt_mul_iff_one_lt_right hb).1 h.not_lt) ⟩
lemma mul_lt_iff_lt_one_right (hb : 0 < b) : b * a < b ↔ a < 1 :=
lt_iff_lt_of_le_iff_le $ le_mul_iff_one_le_right hb
lemma nonpos_of_mul_nonneg_left (h : 0 ≤ a * b) (hb : b < 0) : a ≤ 0 :=
le_of_not_gt (λ ha, absurd h (mul_neg_of_pos_of_neg ha hb).not_le)
lemma nonpos_of_mul_nonneg_right (h : 0 ≤ a * b) (ha : a < 0) : b ≤ 0 :=
le_of_not_gt (λ hb, absurd h (mul_neg_of_neg_of_pos ha hb).not_le)
lemma neg_of_mul_pos_left (h : 0 < a * b) (hb : b ≤ 0) : a < 0 :=
by haveI := @linear_order.decidable_le α _; exact
lt_of_not_ge (λ ha, absurd h (decidable.mul_nonpos_of_nonneg_of_nonpos ha hb).not_lt)
lemma neg_of_mul_pos_right (h : 0 < a * b) (ha : a ≤ 0) : b < 0 :=
by haveI := @linear_order.decidable_le α _; exact
lt_of_not_ge (λ hb, absurd h (decidable.mul_nonpos_of_nonpos_of_nonneg ha hb).not_lt)
@[priority 100] -- see Note [lower instance priority]
instance linear_ordered_semiring.to_no_top_order {α : Type*} [linear_ordered_semiring α] :
no_top_order α :=
⟨assume a, ⟨a + 1, lt_add_of_pos_right _ zero_lt_one⟩⟩
/-- Pullback a `linear_ordered_semiring` under an injective map.
See note [reducible non-instances]. -/
@[reducible]
def function.injective.linear_ordered_semiring {β : Type*}
[has_zero β] [has_one β] [has_add β] [has_mul β]
(f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) :
linear_ordered_semiring β :=
{ .. linear_order.lift f hf,
.. pullback_nonzero f zero one,
.. hf.ordered_semiring f zero one add mul }
end linear_ordered_semiring
section mono
variables {β : Type*} [linear_ordered_semiring α] [preorder β] {f g : β → α} {a : α}
lemma monotone_mul_left_of_nonneg (ha : 0 ≤ a) : monotone (λ x, a*x) :=
by haveI := @linear_order.decidable_le α _; exact
assume b c b_le_c, decidable.mul_le_mul_of_nonneg_left b_le_c ha
lemma monotone_mul_right_of_nonneg (ha : 0 ≤ a) : monotone (λ x, x*a) :=
by haveI := @linear_order.decidable_le α _; exact
assume b c b_le_c, decidable.mul_le_mul_of_nonneg_right b_le_c ha
lemma monotone.mul_const (hf : monotone f) (ha : 0 ≤ a) :
monotone (λ x, (f x) * a) :=
(monotone_mul_right_of_nonneg ha).comp hf
lemma monotone.const_mul (hf : monotone f) (ha : 0 ≤ a) :
monotone (λ x, a * (f x)) :=
(monotone_mul_left_of_nonneg ha).comp hf
lemma monotone.mul (hf : monotone f) (hg : monotone g) (hf0 : ∀ x, 0 ≤ f x) (hg0 : ∀ x, 0 ≤ g x) :
monotone (λ x, f x * g x) :=
by haveI := @linear_order.decidable_le α _; exact
λ x y h, decidable.mul_le_mul (hf h) (hg h) (hg0 x) (hf0 y)
lemma strict_mono_mul_left_of_pos (ha : 0 < a) : strict_mono (λ x, a * x) :=
assume b c b_lt_c, (mul_lt_mul_left ha).2 b_lt_c
lemma strict_mono_mul_right_of_pos (ha : 0 < a) : strict_mono (λ x, x * a) :=
assume b c b_lt_c, (mul_lt_mul_right ha).2 b_lt_c
lemma strict_mono.mul_const (hf : strict_mono f) (ha : 0 < a) :
strict_mono (λ x, (f x) * a) :=
(strict_mono_mul_right_of_pos ha).comp hf
lemma strict_mono.const_mul (hf : strict_mono f) (ha : 0 < a) :
strict_mono (λ x, a * (f x)) :=
(strict_mono_mul_left_of_pos ha).comp hf
lemma strict_mono.mul_monotone (hf : strict_mono f) (hg : monotone g) (hf0 : ∀ x, 0 ≤ f x)
(hg0 : ∀ x, 0 < g x) :
strict_mono (λ x, f x * g x) :=
by haveI := @linear_order.decidable_le α _; exact
λ x y h, decidable.mul_lt_mul (hf h) (hg h.le) (hg0 x) (hf0 y)
lemma monotone.mul_strict_mono (hf : monotone f) (hg : strict_mono g) (hf0 : ∀ x, 0 < f x)
(hg0 : ∀ x, 0 ≤ g x) :
strict_mono (λ x, f x * g x) :=
by haveI := @linear_order.decidable_le α _; exact
λ x y h, decidable.mul_lt_mul' (hf h.le) (hg h) (hg0 x) (hf0 y)
lemma strict_mono.mul (hf : strict_mono f) (hg : strict_mono g) (hf0 : ∀ x, 0 ≤ f x)
(hg0 : ∀ x, 0 ≤ g x) :
strict_mono (λ x, f x * g x) :=
by haveI := @linear_order.decidable_le α _; exact
λ x y h, decidable.mul_lt_mul'' (hf h) (hg h) (hf0 x) (hg0 x)
end mono
section linear_ordered_semiring
variables [linear_ordered_semiring α] {a b c : α}
lemma mul_max_of_nonneg (b c : α) (ha : 0 ≤ a) : a * max b c = max (a * b) (a * c) :=
(monotone_mul_left_of_nonneg ha).map_max
lemma mul_min_of_nonneg (b c : α) (ha : 0 ≤ a) : a * min b c = min (a * b) (a * c) :=
(monotone_mul_left_of_nonneg ha).map_min
lemma max_mul_of_nonneg (a b : α) (hc : 0 ≤ c) : max a b * c = max (a * c) (b * c) :=
(monotone_mul_right_of_nonneg hc).map_max
lemma min_mul_of_nonneg (a b : α) (hc : 0 ≤ c) : min a b * c = min (a * c) (b * c) :=
(monotone_mul_right_of_nonneg hc).map_min
end linear_ordered_semiring
/-- An `ordered_ring α` is a ring `α` with a partial order such that
addition is monotone and multiplication by a positive number is strictly monotone. -/
@[protect_proj]
class ordered_ring (α : Type u) extends ring α, ordered_add_comm_group α :=
(zero_le_one : 0 ≤ (1 : α))
(mul_pos : ∀ a b : α, 0 < a → 0 < b → 0 < a * b)
section ordered_ring
variables [ordered_ring α] {a b c : α}
-- See Note [decidable namespace]
protected lemma decidable.ordered_ring.mul_nonneg [@decidable_rel α (≤)]
{a b : α} (h₁ : 0 ≤ a) (h₂ : 0 ≤ b) : 0 ≤ a * b :=
begin
by_cases ha : a ≤ 0, { simp [le_antisymm ha h₁] },
by_cases hb : b ≤ 0, { simp [le_antisymm hb h₂] },
exact (le_not_le_of_lt (ordered_ring.mul_pos a b (h₁.lt_of_not_le ha) (h₂.lt_of_not_le hb))).1,
end
lemma ordered_ring.mul_nonneg : 0 ≤ a → 0 ≤ b → 0 ≤ a * b :=
by classical; exact decidable.ordered_ring.mul_nonneg
-- See Note [decidable namespace]
protected lemma decidable.ordered_ring.mul_le_mul_of_nonneg_left
[@decidable_rel α (≤)] (h₁ : a ≤ b) (h₂ : 0 ≤ c) : c * a ≤ c * b :=
begin
rw [← sub_nonneg, ← mul_sub],
exact decidable.ordered_ring.mul_nonneg h₂ (sub_nonneg.2 h₁),
end
lemma ordered_ring.mul_le_mul_of_nonneg_left : a ≤ b → 0 ≤ c → c * a ≤ c * b :=
by classical; exact decidable.ordered_ring.mul_le_mul_of_nonneg_left
-- See Note [decidable namespace]
protected lemma decidable.ordered_ring.mul_le_mul_of_nonneg_right
[@decidable_rel α (≤)] (h₁ : a ≤ b) (h₂ : 0 ≤ c) : a * c ≤ b * c :=
begin
rw [← sub_nonneg, ← sub_mul],
exact decidable.ordered_ring.mul_nonneg (sub_nonneg.2 h₁) h₂,
end
lemma ordered_ring.mul_le_mul_of_nonneg_right : a ≤ b → 0 ≤ c → a * c ≤ b * c :=
by classical; exact decidable.ordered_ring.mul_le_mul_of_nonneg_right
lemma ordered_ring.mul_lt_mul_of_pos_left (h₁ : a < b) (h₂ : 0 < c) : c * a < c * b :=
begin
rw [← sub_pos, ← mul_sub],
exact ordered_ring.mul_pos _ _ h₂ (sub_pos.2 h₁),
end
lemma ordered_ring.mul_lt_mul_of_pos_right (h₁ : a < b) (h₂ : 0 < c) : a * c < b * c :=
begin
rw [← sub_pos, ← sub_mul],
exact ordered_ring.mul_pos _ _ (sub_pos.2 h₁) h₂,
end
@[priority 100] -- see Note [lower instance priority]
instance ordered_ring.to_ordered_semiring : ordered_semiring α :=
{ mul_zero := mul_zero,
zero_mul := zero_mul,
add_left_cancel := @add_left_cancel α _,
le_of_add_le_add_left := @le_of_add_le_add_left α _ _ _,
mul_lt_mul_of_pos_left := @ordered_ring.mul_lt_mul_of_pos_left α _,
mul_lt_mul_of_pos_right := @ordered_ring.mul_lt_mul_of_pos_right α _,
..‹ordered_ring α› }
-- See Note [decidable namespace]
protected lemma decidable.mul_le_mul_of_nonpos_left [@decidable_rel α (≤)]
{a b c : α} (h : b ≤ a) (hc : c ≤ 0) : c * a ≤ c * b :=
have -c ≥ 0, from neg_nonneg_of_nonpos hc,
have -c * b ≤ -c * a, from decidable.mul_le_mul_of_nonneg_left h this,
have -(c * b) ≤ -(c * a), by rwa [← neg_mul_eq_neg_mul, ← neg_mul_eq_neg_mul] at this,
le_of_neg_le_neg this
lemma mul_le_mul_of_nonpos_left {a b c : α} : b ≤ a → c ≤ 0 → c * a ≤ c * b :=
by classical; exact decidable.mul_le_mul_of_nonpos_left
-- See Note [decidable namespace]
protected lemma decidable.mul_le_mul_of_nonpos_right [@decidable_rel α (≤)]
{a b c : α} (h : b ≤ a) (hc : c ≤ 0) : a * c ≤ b * c :=
have -c ≥ 0, from neg_nonneg_of_nonpos hc,
have b * -c ≤ a * -c, from decidable.mul_le_mul_of_nonneg_right h this,
have -(b * c) ≤ -(a * c), by rwa [← neg_mul_eq_mul_neg, ← neg_mul_eq_mul_neg] at this,
le_of_neg_le_neg this
lemma mul_le_mul_of_nonpos_right {a b c : α} : b ≤ a → c ≤ 0 → a * c ≤ b * c :=
by classical; exact decidable.mul_le_mul_of_nonpos_right
-- See Note [decidable namespace]
protected lemma decidable.mul_nonneg_of_nonpos_of_nonpos [@decidable_rel α (≤)]
{a b : α} (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a * b :=
have 0 * b ≤ a * b, from decidable.mul_le_mul_of_nonpos_right ha hb,
by rwa zero_mul at this
lemma mul_nonneg_of_nonpos_of_nonpos {a b : α} : a ≤ 0 → b ≤ 0 → 0 ≤ a * b :=
by classical; exact decidable.mul_nonneg_of_nonpos_of_nonpos
lemma mul_lt_mul_of_neg_left {a b c : α} (h : b < a) (hc : c < 0) : c * a < c * b :=
have -c > 0, from neg_pos_of_neg hc,
have -c * b < -c * a, from mul_lt_mul_of_pos_left h this,
have -(c * b) < -(c * a), by rwa [← neg_mul_eq_neg_mul, ← neg_mul_eq_neg_mul] at this,
lt_of_neg_lt_neg this
lemma mul_lt_mul_of_neg_right {a b c : α} (h : b < a) (hc : c < 0) : a * c < b * c :=
have -c > 0, from neg_pos_of_neg hc,
have b * -c < a * -c, from mul_lt_mul_of_pos_right h this,
have -(b * c) < -(a * c), by rwa [← neg_mul_eq_mul_neg, ← neg_mul_eq_mul_neg] at this,
lt_of_neg_lt_neg this
lemma mul_pos_of_neg_of_neg {a b : α} (ha : a < 0) (hb : b < 0) : 0 < a * b :=
have 0 * b < a * b, from mul_lt_mul_of_neg_right ha hb,
by rwa zero_mul at this
/-- Pullback an `ordered_ring` under an injective map.
See note [reducible non-instances]. -/
@[reducible]
def function.injective.ordered_ring {β : Type*}
[has_zero β] [has_one β] [has_add β] [has_mul β] [has_neg β] [has_sub β]
(f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(neg : ∀ x, f (- x) = - f x) (sub : ∀ x y, f (x - y) = f x - f y) :
ordered_ring β :=
{ mul_pos := λ a b a0 b0, show f 0 < f (a * b), by { rw [zero, mul], apply mul_pos; rwa ← zero },
..hf.ordered_semiring f zero one add mul,
..hf.ring f zero one add mul neg sub }
lemma le_iff_exists_nonneg_add (a b : α) : a ≤ b ↔ ∃ c ≥ 0, b = a + c :=
⟨λ h, ⟨b - a, sub_nonneg.mpr h, by simp⟩,
λ ⟨c, hc, h⟩, by { rw [h, le_add_iff_nonneg_right], exact hc }⟩
end ordered_ring
section ordered_comm_ring
/-- An `ordered_comm_ring α` is a commutative ring `α` with a partial order such that
addition is monotone and multiplication by a positive number is strictly monotone. -/
@[protect_proj]
class ordered_comm_ring (α : Type u) extends ordered_ring α, comm_ring α
@[priority 100] -- See note [lower instance priority]
instance ordered_comm_ring.to_ordered_comm_semiring {α : Type u} [ordered_comm_ring α] :
ordered_comm_semiring α :=
{ .. (by apply_instance : ordered_semiring α),
.. ‹ordered_comm_ring α› }
/-- Pullback an `ordered_comm_ring` under an injective map.
See note [reducible non-instances]. -/
@[reducible]
def function.injective.ordered_comm_ring [ordered_comm_ring α] {β : Type*}
[has_zero β] [has_one β] [has_add β] [has_mul β] [has_neg β] [has_sub β]
(f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(neg : ∀ x, f (- x) = - f x) (sub : ∀ x y, f (x - y) = f x - f y) :
ordered_comm_ring β :=
{ ..hf.ordered_ring f zero one add mul neg sub,
..hf.comm_ring f zero one add mul neg sub }
end ordered_comm_ring
/-- A `linear_ordered_ring α` is a ring `α` with a linear order such that
addition is monotone and multiplication by a positive number is strictly monotone. -/
@[protect_proj] class linear_ordered_ring (α : Type u)
extends ordered_ring α, linear_order α, nontrivial α
@[priority 100] -- see Note [lower instance priority]
instance linear_ordered_ring.to_linear_ordered_add_comm_group [s : linear_ordered_ring α] :
linear_ordered_add_comm_group α :=
{ .. s }
section linear_ordered_ring
variables [linear_ordered_ring α] {a b c : α}
@[priority 100] -- see Note [lower instance priority]
instance linear_ordered_ring.to_linear_ordered_semiring : linear_ordered_semiring α :=
{ mul_zero := mul_zero,
zero_mul := zero_mul,
add_left_cancel := @add_left_cancel α _,
le_of_add_le_add_left := @le_of_add_le_add_left α _ _ _,
mul_lt_mul_of_pos_left := @mul_lt_mul_of_pos_left α _,
mul_lt_mul_of_pos_right := @mul_lt_mul_of_pos_right α _,
le_total := linear_ordered_ring.le_total,
..‹linear_ordered_ring α› }
@[priority 100] -- see Note [lower instance priority]
instance linear_ordered_ring.is_domain : is_domain α :=
{ eq_zero_or_eq_zero_of_mul_eq_zero :=
begin
intros a b hab,
refine decidable.or_iff_not_and_not.2 (λ h, _), revert hab,
cases lt_or_gt_of_ne h.1 with ha ha; cases lt_or_gt_of_ne h.2 with hb hb,
exacts [(mul_pos_of_neg_of_neg ha hb).ne.symm, (mul_neg_of_neg_of_pos ha hb).ne,
(mul_neg_of_pos_of_neg ha hb).ne, (mul_pos ha hb).ne.symm]
end,
.. ‹linear_ordered_ring α› }
@[simp] lemma abs_one : |(1 : α)| = 1 := abs_of_pos zero_lt_one
@[simp] lemma abs_two : |(2 : α)| = 2 := abs_of_pos zero_lt_two
lemma abs_mul (a b : α) : |a * b| = |a| * |b| :=
begin
haveI := @linear_order.decidable_le α _,
rw [abs_eq (decidable.mul_nonneg (abs_nonneg a) (abs_nonneg b))],
cases le_total a 0 with ha ha; cases le_total b 0 with hb hb;
simp only [abs_of_nonpos, abs_of_nonneg, true_or, or_true, eq_self_iff_true,
neg_mul_eq_neg_mul_symm, mul_neg_eq_neg_mul_symm, neg_neg, *]
end
/-- `abs` as a `monoid_with_zero_hom`. -/
def abs_hom : monoid_with_zero_hom α α := ⟨abs, abs_zero, abs_one, abs_mul⟩
@[simp] lemma abs_mul_abs_self (a : α) : |a| * |a| = a * a :=
abs_by_cases (λ x, x * x = a * a) rfl (neg_mul_neg a a)
@[simp] lemma abs_mul_self (a : α) : |a * a| = a * a :=
by rw [abs_mul, abs_mul_abs_self]
lemma mul_pos_iff : 0 < a * b ↔ 0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 :=
⟨pos_and_pos_or_neg_and_neg_of_mul_pos,
λ h, h.elim (and_imp.2 mul_pos) (and_imp.2 mul_pos_of_neg_of_neg)⟩
lemma mul_neg_iff : a * b < 0 ↔ 0 < a ∧ b < 0 ∨ a < 0 ∧ 0 < b :=
by rw [← neg_pos, neg_mul_eq_mul_neg, mul_pos_iff, neg_pos, neg_lt_zero]
lemma mul_nonneg_iff : 0 ≤ a * b ↔ 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 :=
by haveI := @linear_order.decidable_le α _; exact
⟨nonneg_and_nonneg_or_nonpos_and_nonpos_of_mul_nnonneg,
λ h, h.elim (and_imp.2 decidable.mul_nonneg) (and_imp.2 decidable.mul_nonneg_of_nonpos_of_nonpos)⟩
/-- Out of three elements of a `linear_ordered_ring`, two must have the same sign. -/
lemma mul_nonneg_of_three (a b c : α) :
0 ≤ a * b ∨ 0 ≤ b * c ∨ 0 ≤ c * a :=
by iterate 3 { rw mul_nonneg_iff };
have := le_total 0 a; have := le_total 0 b; have := le_total 0 c; itauto
lemma mul_nonpos_iff : a * b ≤ 0 ↔ 0 ≤ a ∧ b ≤ 0 ∨ a ≤ 0 ∧ 0 ≤ b :=
by rw [← neg_nonneg, neg_mul_eq_mul_neg, mul_nonneg_iff, neg_nonneg, neg_nonpos]
lemma mul_self_nonneg (a : α) : 0 ≤ a * a :=
abs_mul_self a ▸ abs_nonneg _
@[simp] lemma neg_le_self_iff : -a ≤ a ↔ 0 ≤ a :=
by simp [neg_le_iff_add_nonneg, ← two_mul, mul_nonneg_iff, zero_le_one, (@zero_lt_two α _ _).not_le]
@[simp] lemma neg_lt_self_iff : -a < a ↔ 0 < a :=
by simp [neg_lt_iff_pos_add, ← two_mul, mul_pos_iff, zero_lt_one, (@zero_lt_two α _ _).not_lt]
@[simp] lemma le_neg_self_iff : a ≤ -a ↔ a ≤ 0 :=
calc a ≤ -a ↔ -(-a) ≤ -a : by rw neg_neg
... ↔ 0 ≤ -a : neg_le_self_iff
... ↔ a ≤ 0 : neg_nonneg
@[simp] lemma lt_neg_self_iff : a < -a ↔ a < 0 :=
calc a < -a ↔ -(-a) < -a : by rw neg_neg
... ↔ 0 < -a : neg_lt_self_iff
... ↔ a < 0 : neg_pos
@[simp] lemma abs_eq_self : |a| = a ↔ 0 ≤ a := by simp [abs_eq_max_neg]
@[simp] lemma abs_eq_neg_self : |a| = -a ↔ a ≤ 0 := by simp [abs_eq_max_neg]
/-- For an element `a` of a linear ordered ring, either `abs a = a` and `0 ≤ a`,
or `abs a = -a` and `a < 0`.
Use cases on this lemma to automate linarith in inequalities -/
lemma abs_cases (a : α) : (|a| = a ∧ 0 ≤ a) ∨ (|a| = -a ∧ a < 0) :=
begin
by_cases 0 ≤ a,
{ left,
exact ⟨abs_eq_self.mpr h, h⟩ },
{ right,
push_neg at h,
exact ⟨abs_eq_neg_self.mpr (le_of_lt h), h⟩ }
end
lemma gt_of_mul_lt_mul_neg_left (h : c * a < c * b) (hc : c ≤ 0) : b < a :=
have nhc : 0 ≤ -c, from neg_nonneg_of_nonpos hc,
have h2 : -(c * b) < -(c * a), from neg_lt_neg h,
have h3 : (-c) * b < (-c) * a, from calc
(-c) * b = - (c * b) : by rewrite neg_mul_eq_neg_mul
... < -(c * a) : h2
... = (-c) * a : by rewrite neg_mul_eq_neg_mul,
lt_of_mul_lt_mul_left h3 nhc
lemma neg_one_lt_zero : -1 < (0:α) := neg_lt_zero.2 zero_lt_one
lemma le_of_mul_le_of_one_le {a b c : α} (h : a * c ≤ b) (hb : 0 ≤ b) (hc : 1 ≤ c) : a ≤ b :=
by haveI := @linear_order.decidable_le α _; exact
have h' : a * c ≤ b * c, from calc
a * c ≤ b : h
... = b * 1 : by rewrite mul_one
... ≤ b * c : decidable.mul_le_mul_of_nonneg_left hc hb,
le_of_mul_le_mul_right h' (zero_lt_one.trans_le hc)
lemma nonneg_le_nonneg_of_sq_le_sq {a b : α} (hb : 0 ≤ b) (h : a * a ≤ b * b) : a ≤ b :=
by haveI := @linear_order.decidable_le α _; exact
le_of_not_gt (λhab, (decidable.mul_self_lt_mul_self hb hab).not_le h)
lemma mul_self_le_mul_self_iff {a b : α} (h1 : 0 ≤ a) (h2 : 0 ≤ b) : a ≤ b ↔ a * a ≤ b * b :=
by haveI := @linear_order.decidable_le α _; exact
⟨decidable.mul_self_le_mul_self h1, nonneg_le_nonneg_of_sq_le_sq h2⟩
lemma mul_self_lt_mul_self_iff {a b : α} (h1 : 0 ≤ a) (h2 : 0 ≤ b) : a < b ↔ a * a < b * b :=
by haveI := @linear_order.decidable_le α _; exact
((@decidable.strict_mono_on_mul_self α _ _).lt_iff_lt h1 h2).symm
lemma mul_self_inj {a b : α} (h1 : 0 ≤ a) (h2 : 0 ≤ b) : a * a = b * b ↔ a = b :=
by haveI := @linear_order.decidable_le α _; exact
(@decidable.strict_mono_on_mul_self α _ _).inj_on.eq_iff h1 h2
@[simp] lemma mul_le_mul_left_of_neg {a b c : α} (h : c < 0) : c * a ≤ c * b ↔ b ≤ a :=
by haveI := @linear_order.decidable_le α _; exact
⟨le_imp_le_of_lt_imp_lt $ λ h', mul_lt_mul_of_neg_left h' h,
λ h', decidable.mul_le_mul_of_nonpos_left h' h.le⟩
@[simp] lemma mul_le_mul_right_of_neg {a b c : α} (h : c < 0) : a * c ≤ b * c ↔ b ≤ a :=
by haveI := @linear_order.decidable_le α _; exact
⟨le_imp_le_of_lt_imp_lt $ λ h', mul_lt_mul_of_neg_right h' h,
λ h', decidable.mul_le_mul_of_nonpos_right h' h.le⟩
@[simp] lemma mul_lt_mul_left_of_neg {a b c : α} (h : c < 0) : c * a < c * b ↔ b < a :=
lt_iff_lt_of_le_iff_le (mul_le_mul_left_of_neg h)
@[simp] lemma mul_lt_mul_right_of_neg {a b c : α} (h : c < 0) : a * c < b * c ↔ b < a :=
lt_iff_lt_of_le_iff_le (mul_le_mul_right_of_neg h)
lemma sub_one_lt (a : α) : a - 1 < a :=
sub_lt_iff_lt_add.2 (lt_add_one a)
lemma mul_self_pos {a : α} (ha : a ≠ 0) : 0 < a * a :=
by rcases lt_trichotomy a 0 with h|h|h;
[exact mul_pos_of_neg_of_neg h h, exact (ha h).elim, exact mul_pos h h]
lemma mul_self_le_mul_self_of_le_of_neg_le {x y : α} (h₁ : x ≤ y) (h₂ : -x ≤ y) : x * x ≤ y * y :=
begin
haveI := @linear_order.decidable_le α _,
rw [← abs_mul_abs_self x],
exact decidable.mul_self_le_mul_self (abs_nonneg x) (abs_le.2 ⟨neg_le.2 h₂, h₁⟩)
end
lemma nonneg_of_mul_nonpos_left {a b : α} (h : a * b ≤ 0) (hb : b < 0) : 0 ≤ a :=
le_of_not_gt (λ ha, absurd h (mul_pos_of_neg_of_neg ha hb).not_le)
lemma nonneg_of_mul_nonpos_right {a b : α} (h : a * b ≤ 0) (ha : a < 0) : 0 ≤ b :=
le_of_not_gt (λ hb, absurd h (mul_pos_of_neg_of_neg ha hb).not_le)
lemma pos_of_mul_neg_left {a b : α} (h : a * b < 0) (hb : b ≤ 0) : 0 < a :=
by haveI := @linear_order.decidable_le α _; exact
lt_of_not_ge (λ ha, absurd h (decidable.mul_nonneg_of_nonpos_of_nonpos ha hb).not_lt)
lemma pos_of_mul_neg_right {a b : α} (h : a * b < 0) (ha : a ≤ 0) : 0 < b :=
by haveI := @linear_order.decidable_le α _; exact
lt_of_not_ge (λ hb, absurd h (decidable.mul_nonneg_of_nonpos_of_nonpos ha hb).not_lt)
/-- The sum of two squares is zero iff both elements are zero. -/
lemma mul_self_add_mul_self_eq_zero {x y : α} : x * x + y * y = 0 ↔ x = 0 ∧ y = 0 :=
by rw [add_eq_zero_iff', mul_self_eq_zero, mul_self_eq_zero]; apply mul_self_nonneg
lemma eq_zero_of_mul_self_add_mul_self_eq_zero (h : a * a + b * b = 0) : a = 0 :=
(mul_self_add_mul_self_eq_zero.mp h).left
lemma abs_eq_iff_mul_self_eq : |a| = |b| ↔ a * a = b * b :=
begin
rw [← abs_mul_abs_self, ← abs_mul_abs_self b],
exact (mul_self_inj (abs_nonneg a) (abs_nonneg b)).symm,
end
lemma abs_lt_iff_mul_self_lt : |a| < |b| ↔ a * a < b * b :=
begin
rw [← abs_mul_abs_self, ← abs_mul_abs_self b],
exact mul_self_lt_mul_self_iff (abs_nonneg a) (abs_nonneg b)
end
lemma abs_le_iff_mul_self_le : |a| ≤ |b| ↔ a * a ≤ b * b :=
begin
rw [← abs_mul_abs_self, ← abs_mul_abs_self b],
exact mul_self_le_mul_self_iff (abs_nonneg a) (abs_nonneg b)
end
lemma abs_le_one_iff_mul_self_le_one : |a| ≤ 1 ↔ a * a ≤ 1 :=
by simpa only [abs_one, one_mul] using @abs_le_iff_mul_self_le α _ a 1
/-- Pullback a `linear_ordered_ring` under an injective map.
See note [reducible non-instances]. -/
@[reducible]
def function.injective.linear_ordered_ring {β : Type*}
[has_zero β] [has_one β] [has_add β] [has_mul β] [has_neg β] [has_sub β]
(f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) :
linear_ordered_ring β :=
{ .. linear_order.lift f hf,
.. pullback_nonzero f zero one,
.. hf.ordered_ring f zero one add mul neg sub }
end linear_ordered_ring
/-- A `linear_ordered_comm_ring α` is a commutative ring `α` with a linear order
such that addition is monotone and multiplication by a positive number is strictly monotone. -/
@[protect_proj]
class linear_ordered_comm_ring (α : Type u) extends linear_ordered_ring α, comm_monoid α
@[priority 100] -- see Note [lower instance priority]
instance linear_ordered_comm_ring.to_ordered_comm_ring [d : linear_ordered_comm_ring α] :
ordered_comm_ring α :=
{ ..d }
@[priority 100] -- see Note [lower instance priority]
instance linear_ordered_comm_ring.to_linear_ordered_semiring [d : linear_ordered_comm_ring α] :
linear_ordered_semiring α :=
{ .. d, ..linear_ordered_ring.to_linear_ordered_semiring }
section linear_ordered_comm_ring
variables [linear_ordered_comm_ring α] {a b c d : α}
lemma max_mul_mul_le_max_mul_max (b c : α) (ha : 0 ≤ a) (hd: 0 ≤ d) :
max (a * b) (d * c) ≤ max a c * max d b :=
by haveI := @linear_order.decidable_le α _; exact
have ba : b * a ≤ max d b * max c a, from
decidable.mul_le_mul (le_max_right d b) (le_max_right c a) ha (le_trans hd (le_max_left d b)),
have cd : c * d ≤ max a c * max b d, from
decidable.mul_le_mul (le_max_right a c) (le_max_right b d) hd (le_trans ha (le_max_left a c)),
max_le
(by simpa [mul_comm, max_comm] using ba)
(by simpa [mul_comm, max_comm] using cd)
lemma abs_sub_sq (a b : α) : |a - b| * |a - b| = a * a + b * b - (1 + 1) * a * b :=
begin
rw abs_mul_abs_self,
simp only [mul_add, add_comm, add_left_comm, mul_comm, sub_eq_add_neg,
mul_one, mul_neg_eq_neg_mul_symm, neg_add_rev, neg_neg],
end
end linear_ordered_comm_ring
section
variables [ring α] [linear_order α] {a b : α}
@[simp] lemma abs_dvd (a b : α) : |a| ∣ b ↔ a ∣ b :=
by { cases abs_choice a with h h; simp only [h, neg_dvd] }
lemma abs_dvd_self (a : α) : |a| ∣ a :=
(abs_dvd a a).mpr (dvd_refl a)
@[simp] lemma dvd_abs (a b : α) : a ∣ |b| ↔ a ∣ b :=
by { cases abs_choice b with h h; simp only [h, dvd_neg] }
lemma self_dvd_abs (a : α) : a ∣ |a| :=
(dvd_abs a a).mpr (dvd_refl a)
lemma abs_dvd_abs (a b : α) : |a| ∣ |b| ↔ a ∣ b :=
(abs_dvd _ _).trans (dvd_abs _ _)
lemma even_abs {a : α} : even (|a|) ↔ even a :=
dvd_abs _ _
lemma odd_abs {a : α} : odd (abs a) ↔ odd a :=
by { cases abs_choice a with h h; simp only [h, odd_neg] }
end
section linear_ordered_comm_ring
variables [linear_ordered_comm_ring α]
/-- Pullback a `linear_ordered_comm_ring` under an injective map.
See note [reducible non-instances]. -/
@[reducible]
def function.injective.linear_ordered_comm_ring {β : Type*}
[has_zero β] [has_one β] [has_add β] [has_mul β] [has_neg β] [has_sub β]
(f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) :
linear_ordered_comm_ring β :=
{ .. linear_order.lift f hf,
.. pullback_nonzero f zero one,
.. hf.ordered_comm_ring f zero one add mul neg sub }
end linear_ordered_comm_ring
namespace ring
/-- A positive cone in a ring consists of a positive cone in underlying `add_comm_group`,
which contains `1` and such that the positive elements are closed under multiplication. -/
@[nolint has_inhabited_instance]
structure positive_cone (α : Type*) [ring α] extends add_comm_group.positive_cone α :=
(one_nonneg : nonneg 1)
(mul_pos : ∀ (a b), pos a → pos b → pos (a * b))
/-- Forget that a positive cone in a ring respects the multiplicative structure. -/
add_decl_doc positive_cone.to_positive_cone
/-- A positive cone in a ring induces a linear order if `1` is a positive element. -/
@[nolint has_inhabited_instance]
structure total_positive_cone (α : Type*) [ring α]
extends positive_cone α, add_comm_group.total_positive_cone α :=
(one_pos : pos 1)
/-- Forget that a `total_positive_cone` in a ring is total. -/
add_decl_doc total_positive_cone.to_positive_cone
/-- Forget that a `total_positive_cone` in a ring respects the multiplicative structure. -/
add_decl_doc total_positive_cone.to_total_positive_cone
end ring
namespace ordered_ring
open ring
/-- Construct an `ordered_ring` by
designating a positive cone in an existing `ring`. -/
def mk_of_positive_cone {α : Type*} [ring α] (C : positive_cone α) :
ordered_ring α :=
{ zero_le_one := by { change C.nonneg (1 - 0), convert C.one_nonneg, simp, },
mul_pos := λ x y xp yp, begin
change C.pos (x*y - 0),
convert C.mul_pos x y (by { convert xp, simp, }) (by { convert yp, simp, }),
simp,
end,
..‹ring α›,
..ordered_add_comm_group.mk_of_positive_cone C.to_positive_cone }
end ordered_ring
namespace linear_ordered_ring
open ring
/-- Construct a `linear_ordered_ring` by
designating a positive cone in an existing `ring`. -/
def mk_of_positive_cone {α : Type*} [ring α] (C : total_positive_cone α) :
linear_ordered_ring α :=
{ exists_pair_ne := ⟨0, 1, begin
intro h,
have one_pos := C.one_pos,
rw [←h, C.pos_iff] at one_pos,
simpa using one_pos,
end⟩,
..ordered_ring.mk_of_positive_cone C.to_positive_cone,
..linear_ordered_add_comm_group.mk_of_positive_cone C.to_total_positive_cone, }
end linear_ordered_ring
/-- A canonically ordered commutative semiring is an ordered, commutative semiring
in which `a ≤ b` iff there exists `c` with `b = a + c`. This is satisfied by the
natural numbers, for example, but not the integers or other ordered groups. -/
@[protect_proj]
class canonically_ordered_comm_semiring (α : Type*) extends
canonically_ordered_add_monoid α, comm_semiring α :=
(eq_zero_or_eq_zero_of_mul_eq_zero : ∀ a b : α, a * b = 0 → a = 0 ∨ b = 0)
namespace canonically_ordered_comm_semiring
variables [canonically_ordered_comm_semiring α] {a b : α}
@[priority 100] -- see Note [lower instance priority]
instance to_no_zero_divisors : no_zero_divisors α :=
⟨canonically_ordered_comm_semiring.eq_zero_or_eq_zero_of_mul_eq_zero⟩
@[priority 100] -- see Note [lower instance priority]
instance to_covariant_mul_le : covariant_class α α (*) (≤) :=
begin
refine ⟨λ a b c h, _⟩,
rcases le_iff_exists_add.1 h with ⟨c, rfl⟩,
rw mul_add,
apply self_le_add_right
end
/-- A version of `zero_lt_one : 0 < 1` for a `canonically_ordered_comm_semiring`. -/
lemma zero_lt_one [nontrivial α] : (0:α) < 1 := (zero_le 1).lt_of_ne zero_ne_one
@[simp] lemma mul_pos : 0 < a * b ↔ (0 < a) ∧ (0 < b) :=
by simp only [pos_iff_ne_zero, ne.def, mul_eq_zero, not_or_distrib]
end canonically_ordered_comm_semiring
section sub
variables [canonically_ordered_comm_semiring α] {a b c : α}
variables [has_sub α] [has_ordered_sub α]
variables [is_total α (≤)]
namespace add_le_cancellable
protected lemma mul_tsub (h : add_le_cancellable (a * c)) :
a * (b - c) = a * b - a * c :=
begin
cases total_of (≤) b c with hbc hcb,
{ rw [tsub_eq_zero_iff_le.2 hbc, mul_zero, tsub_eq_zero_iff_le.2 (mul_le_mul_left' hbc a)] },
{ apply h.eq_tsub_of_add_eq, rw [← mul_add, tsub_add_cancel_of_le hcb] }
end
protected lemma tsub_mul (h : add_le_cancellable (b * c)) : (a - b) * c = a * c - b * c :=
by { simp only [mul_comm _ c] at *, exact h.mul_tsub }
end add_le_cancellable
variables [contravariant_class α α (+) (≤)]
lemma mul_tsub (a b c : α) : a * (b - c) = a * b - a * c :=
contravariant.add_le_cancellable.mul_tsub
lemma tsub_mul (a b c : α) : (a - b) * c = a * c - b * c :=
contravariant.add_le_cancellable.tsub_mul
end sub
/-! ### Structures involving `*` and `0` on `with_top` and `with_bot`
The main results of this section are `with_top.canonically_ordered_comm_semiring` and
`with_bot.comm_monoid_with_zero`.
-/
namespace with_top
instance [nonempty α] : nontrivial (with_top α) :=
option.nontrivial
variable [decidable_eq α]
section has_mul
variables [has_zero α] [has_mul α]
instance : mul_zero_class (with_top α) :=
{ zero := 0,
mul := λm n, if m = 0 ∨ n = 0 then 0 else m.bind (λa, n.bind $ λb, ↑(a * b)),
zero_mul := assume a, if_pos $ or.inl rfl,
mul_zero := assume a, if_pos $ or.inr rfl }
lemma mul_def {a b : with_top α} :
a * b = if a = 0 ∨ b = 0 then 0 else a.bind (λa, b.bind $ λb, ↑(a * b)) := rfl
@[simp] lemma mul_top {a : with_top α} (h : a ≠ 0) : a * ⊤ = ⊤ :=
by cases a; simp [mul_def, h]; refl
@[simp] lemma top_mul {a : with_top α} (h : a ≠ 0) : ⊤ * a = ⊤ :=
by cases a; simp [mul_def, h]; refl
@[simp] lemma top_mul_top : (⊤ * ⊤ : with_top α) = ⊤ :=
top_mul top_ne_zero
end has_mul
section mul_zero_class
variables [mul_zero_class α]
@[norm_cast] lemma coe_mul {a b : α} : (↑(a * b) : with_top α) = a * b :=
decidable.by_cases (assume : a = 0, by simp [this]) $ assume ha,
decidable.by_cases (assume : b = 0, by simp [this]) $ assume hb,
by { simp [*, mul_def], refl }
lemma mul_coe {b : α} (hb : b ≠ 0) : ∀{a : with_top α}, a * b = a.bind (λa:α, ↑(a * b))
| none := show (if (⊤:with_top α) = 0 ∨ (b:with_top α) = 0 then 0 else ⊤ : with_top α) = ⊤,
by simp [hb]
| (some a) := show ↑a * ↑b = ↑(a * b), from coe_mul.symm
@[simp] lemma mul_eq_top_iff {a b : with_top α} : a * b = ⊤ ↔ (a ≠ 0 ∧ b = ⊤) ∨ (a = ⊤ ∧ b ≠ 0) :=
begin
cases a; cases b; simp only [none_eq_top, some_eq_coe],
{ simp [← coe_mul] },
{ suffices : ⊤ * (b : with_top α) = ⊤ ↔ b ≠ 0, by simpa,
by_cases hb : b = 0; simp [hb] },
{ suffices : (a : with_top α) * ⊤ = ⊤ ↔ a ≠ 0, by simpa,
by_cases ha : a = 0; simp [ha] },
{ simp [← coe_mul] }
end
lemma mul_lt_top [partial_order α] {a b : with_top α} (ha : a ≠ ⊤) (hb : b ≠ ⊤) : a * b < ⊤ :=
begin
lift a to α using ha,
lift b to α using hb,
simp only [← coe_mul, coe_lt_top]
end
end mul_zero_class
/-- `nontrivial α` is needed here as otherwise we have `1 * ⊤ = ⊤` but also `= 0 * ⊤ = 0`. -/
instance [mul_zero_one_class α] [nontrivial α] : mul_zero_one_class (with_top α) :=
{ mul := (*),
one := 1,
zero := 0,
one_mul := λ a, match a with
| none := show ((1:α) : with_top α) * ⊤ = ⊤, by simp [-with_top.coe_one]
| (some a) := show ((1:α) : with_top α) * a = a, by simp [coe_mul.symm, -with_top.coe_one]
end,
mul_one := λ a, match a with
| none := show ⊤ * ((1:α) : with_top α) = ⊤, by simp [-with_top.coe_one]
| (some a) := show ↑a * ((1:α) : with_top α) = a, by simp [coe_mul.symm, -with_top.coe_one]
end,
.. with_top.mul_zero_class }
instance [mul_zero_class α] [no_zero_divisors α] : no_zero_divisors (with_top α) :=
⟨λ a b, by cases a; cases b; dsimp [mul_def]; split_ifs;
simp [*, none_eq_top, some_eq_coe, mul_eq_zero] at *⟩
instance [semigroup_with_zero α] [no_zero_divisors α] : semigroup_with_zero (with_top α) :=
{ mul := (*),
zero := 0,
mul_assoc := λ a b c, begin
cases a,
{ by_cases hb : b = 0; by_cases hc : c = 0;
simp [*, none_eq_top] },
cases b,
{ by_cases ha : a = 0; by_cases hc : c = 0;
simp [*, none_eq_top, some_eq_coe] },
cases c,
{ by_cases ha : a = 0; by_cases hb : b = 0;
simp [*, none_eq_top, some_eq_coe] },
simp [some_eq_coe, coe_mul.symm, mul_assoc]
end,
.. with_top.mul_zero_class }
instance [monoid_with_zero α] [no_zero_divisors α] [nontrivial α] : monoid_with_zero (with_top α) :=
{ .. with_top.mul_zero_one_class, .. with_top.semigroup_with_zero }
instance [comm_monoid_with_zero α] [no_zero_divisors α] [nontrivial α] :
comm_monoid_with_zero (with_top α) :=
{ mul := (*),
zero := 0,
mul_comm := λ a b, begin
by_cases ha : a = 0, { simp [ha] },
by_cases hb : b = 0, { simp [hb] },
simp [ha, hb, mul_def, option.bind_comm a b, mul_comm]
end,
.. with_top.monoid_with_zero }
variables [canonically_ordered_comm_semiring α]
private lemma distrib' (a b c : with_top α) : (a + b) * c = a * c + b * c :=
begin
cases c,
{ show (a + b) * ⊤ = a * ⊤ + b * ⊤,
by_cases ha : a = 0; simp [ha] },
{ show (a + b) * c = a * c + b * c,
by_cases hc : c = 0, { simp [hc] },
simp [mul_coe hc], cases a; cases b,
repeat { refl <|> exact congr_arg some (add_mul _ _ _) } }
end
/-- This instance requires `canonically_ordered_comm_semiring` as it is the smallest class
that derives from both `non_assoc_non_unital_semiring` and `canonically_ordered_add_monoid`, both
of which are required for distributivity. -/
instance [nontrivial α] : comm_semiring (with_top α) :=
{ right_distrib := distrib',
left_distrib := assume a b c, by rw [mul_comm, distrib', mul_comm b, mul_comm c]; refl,
.. with_top.add_comm_monoid, .. with_top.comm_monoid_with_zero,}
instance [nontrivial α] : canonically_ordered_comm_semiring (with_top α) :=
{ .. with_top.comm_semiring,
.. with_top.canonically_ordered_add_monoid,
.. with_top.no_zero_divisors, }
end with_top
namespace with_bot
instance [nonempty α] : nontrivial (with_bot α) :=
option.nontrivial
variable [decidable_eq α]
section has_mul
variables [has_zero α] [has_mul α]
instance : mul_zero_class (with_bot α) :=
with_top.mul_zero_class
lemma mul_def {a b : with_bot α} :
a * b = if a = 0 ∨ b = 0 then 0 else a.bind (λa, b.bind $ λb, ↑(a * b)) := rfl
@[simp] lemma mul_bot {a : with_bot α} (h : a ≠ 0) : a * ⊥ = ⊥ :=
with_top.mul_top h
@[simp] lemma bot_mul {a : with_bot α} (h : a ≠ 0) : ⊥ * a = ⊥ :=
with_top.top_mul h
@[simp] lemma bot_mul_bot : (⊥ * ⊥ : with_bot α) = ⊥ :=
with_top.top_mul_top
end has_mul
section mul_zero_class
variables [mul_zero_class α]
@[norm_cast] lemma coe_mul {a b : α} : (↑(a * b) : with_bot α) = a * b :=
decidable.by_cases (assume : a = 0, by simp [this]) $ assume ha,
decidable.by_cases (assume : b = 0, by simp [this]) $ assume hb,
by { simp [*, mul_def], refl }
lemma mul_coe {b : α} (hb : b ≠ 0) {a : with_bot α} : a * b = a.bind (λa:α, ↑(a * b)) :=
with_top.mul_coe hb
@[simp] lemma mul_eq_bot_iff {a b : with_bot α} : a * b = ⊥ ↔ (a ≠ 0 ∧ b = ⊥) ∨ (a = ⊥ ∧ b ≠ 0) :=
with_top.mul_eq_top_iff
lemma bot_lt_mul [partial_order α] {a b : with_bot α} (ha : ⊥ < a) (hb : ⊥ < b) : ⊥ < a * b :=
begin
lift a to α using ne_bot_of_gt ha,
lift b to α using ne_bot_of_gt hb,
simp only [← coe_mul, bot_lt_coe],
end
end mul_zero_class
/-- `nontrivial α` is needed here as otherwise we have `1 * ⊥ = ⊥` but also `= 0 * ⊥ = 0`. -/
instance [mul_zero_one_class α] [nontrivial α] : mul_zero_one_class (with_bot α) :=
with_top.mul_zero_one_class
instance [mul_zero_class α] [no_zero_divisors α] : no_zero_divisors (with_bot α) :=
with_top.no_zero_divisors
instance [semigroup_with_zero α] [no_zero_divisors α] : semigroup_with_zero (with_bot α) :=
with_top.semigroup_with_zero
instance [monoid_with_zero α] [no_zero_divisors α] [nontrivial α] : monoid_with_zero (with_bot α) :=
with_top.monoid_with_zero
instance [comm_monoid_with_zero α] [no_zero_divisors α] [nontrivial α] :
comm_monoid_with_zero (with_bot α) :=
with_top.comm_monoid_with_zero
instance [canonically_ordered_comm_semiring α] [nontrivial α] : comm_semiring (with_bot α) :=
with_top.comm_semiring
end with_bot
|
lemma contour_integrable_reversepath_eq: "valid_path g \<Longrightarrow> (f contour_integrable_on (reversepath g) \<longleftrightarrow> f contour_integrable_on g)" |
\section{Related work}
\label{sec:related}
Bitcoin Covenants~\cite{moser2016bitcoin} allow Bitcoin transactions
to restrict how the transferred value can be used in the future,
including propagating themselves to ongoing outputs. This provides
contract continuity and allows the implementation of simple state
machines. Our work is inspired by Covenants, although our addition of
a datum is novel and simplifies the state passing.
The Bitcoin Modelling Language (BitML)~\cite{bitml} is an idealistic process calculus
that specifically targets smart contracts running on Bitcoin.
The semantics of BitML contracts essentially comprise a (labelled) \textit{transition system}, aka a state machine.
Nonetheless, due to the constrained nature of the plain \UTXO{} model without any extensions,
the construction is far from straightforward and requires quite a bit of off-chain communication to set everything up.
Most importantly, the BitML compilation scheme only concerns a restricted form of state machines,
while ours deals with a more generic form that admits any user-defined type of states and inputs.
BitML builds upon an abstract model of Bitcoin transactions by the same
authors~\cite{formal-model-of-bitcoin-transactions};
one of our main contributions is an extended version of such an abstract model,
which also accounts for the added functionality apparent in \Bcc{}.
Ethereum and its smart contract language, Solidity~\cite{Solidity}, are powerful
enough to implement state machines, due to their native support for
global contract instances and state. However, this approach has some major downsides,
notably that contract state is global, and must be kept indefinitely by all core nodes.
In the \EUTXO{} model, contract state is localised to where it is used, and
it is the responsibility of clients to manage it.
Scilla~\cite{scilla} is a intermediate-level language for writing smart
contracts as state machines. It compiles to Solidity and is amendable to formal verification.
Since Scilla supports the asynchronous messaging capabilities of Ethereum,
Scilla contracts correspond to a richer class of automata, called
\textit{Communicating State Transition Systems}~\cite{csta}.
In the future, we plan to formally compare this class of state machines with our own class of \CEM{}s,
which would also pave the way to a systematic comparison of Ethereum's account-based model against \Bcc{}'s \UTXO{}-based one.
Finally, there has been an attempt to model Bitcoin contracts using \textit{timed automata}~\cite{timed-btc},
which enables semi-automatic verification using the UPPAAL model checker~\cite{uppaal}.
While this provides a pragmatic way to verify temporal properties of concrete smart contracts,
there is no formal claim that this class of automata actually corresponds to the semantics of Bitcoin smart contracts.
In contrast, our bisimulation proof achieves the bridging of this semantic gap.
|
[STATEMENT]
lemma Cesare:
assumes "A E B " and "A Q C" shows "B E C"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. B E C
[PROOF STEP]
using Celarent aristo_conversion1 assms
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?A E ?B; ?B Q ?C\<rbrakk> \<Longrightarrow> ?A E ?C
?A E ?B \<Longrightarrow> ?B E ?A
A E B
A Q C
goal (1 subgoal):
1. B E C
[PROOF STEP]
by blast |
open import Agda.Builtin.Equality
_∋_ : ∀ {a} (A : Set a) → A → A
A ∋ x = x
cong : ∀ {a b} {A : Set a} {B : Set b}
(f : A → B) {x y} → x ≡ y → f x ≡ f y
cong f refl = refl
record IsRG (Node : Set) (Edge : Set) : Set where
field
src : Edge → Node
tgt : Edge → Node
rfl : Node → Edge
eq-src-rfl : ∀{x} → src (rfl x) ≡ x
eq-tgt-rfl : ∀{x} → tgt (rfl x) ≡ x
open IsRG {{...}} public
module norecord where
source : ∀{Node Edge : Set} {{i : IsRG Node Edge}} → Edge → Node
source x = src x
lemma1 : ∀{Node Edge : Set} {{i : IsRG Node Edge}} → (e : Edge) → (Node ∋ source e) ≡ src e
lemma1 e = refl
rfl-src : ∀{Node Edge : Set} {{i : IsRG Node Edge}} → Edge → Edge
rfl-src {Node} e = rfl (Node ∋ src e)
lemma2 : ∀{Node Edge : Set} {{i : IsRG Node Edge}} → (n : Node) → rfl-src {Node} (rfl n) ≡ (Edge ∋ rfl n)
lemma2 {Node}{Edge} n = cong (rfl {Node = Node}) (eq-src-rfl {Edge = Edge})
module yesrecord where
record RG : Set₁ where
constructor mkRG
field
Node : Set
Edge : Set
{{isRG}} : IsRG Node Edge
open RG public
source : ∀{rg} → Edge rg → Node rg
source x = src x
lemma1 : ∀{rg} → (e : Edge rg) → (Node rg ∋ source {mkRG (Node rg) (Edge rg)} e) ≡ src e
--causes problems:
--lemma1 : ∀{rg} → (e : Edge rg) → (Node rg ∋ source {_} e) ≡ src e
lemma1 e = refl
rfl-src : ∀{rg} → Edge rg → Edge rg
rfl-src {rg} e = rfl (Node rg ∋ src e)
lemma2 : ∀{rg} → (n : Node rg) → rfl-src {rg} (rfl n) ≡ (Edge rg ∋ rfl n)
lemma2 {rg} n = cong (rfl {Node = Node rg}) (eq-src-rfl {Edge = Edge rg})
|
The interior of the empty set is the empty set. |
Formal statement is: lemma linear_invertible_bounded_below_pos: fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::euclidean_space" assumes "linear f" "linear g" "g \<circ> f = id" obtains B where "B > 0" "\<And>x. B * norm x \<le> norm(f x)" Informal statement is: If $f$ is a linear map from a normed vector space to a Euclidean space, and $g$ is a linear map from the Euclidean space to the normed vector space such that $g \circ f = id$, then there exists a constant $B > 0$ such that for all $x$, we have $B \cdot \|x\| \leq \|f(x)\|$. |
""" Masks areas to be carved out based on contour """
import itertools
import numpy, scipy.interpolate, numpy.random
import vec
narrowing_factor = 1.5 # Used when river occupies both sides of a chunk
corner_radius_offset = 0.9
river_deviation_centre = (-2, 2)
river_deviation_width = (-1, 1)
river_frequency_centre = 5.1
river_frequency_width = 2.8
class ChunkSeed(object):
"""
Used to seed generation of chunk specific features such
as winding rivers.
"""
def __init__(self, level_seed, location):
self.level_seed = numpy.cast[int](numpy.array(level_seed))
self.location = numpy.cast[int](numpy.array(location))
def offset(self, relative):
"""
Returns another ChunkSeed object for a chunk offset
by the specified amount.
"""
return ChunkSeed(self.level_seed, self.location + numpy.array(relative))
def __side_seed(self, side):
# Generated seeds will be the same for shared edges
side = self.location + numpy.cast[int]((side + numpy.ones(len(side)))/2)
return side*self.level_seed
def centre_seed(self, side):
""" Seed for river centre generation """
return numpy.cast[numpy.int32](self.__side_seed(side))
def width_seed(self, side):
""" Seed for river width generation """
return numpy.cast[numpy.int32](self.__side_seed(side)*2)
class Meander(object):
"""
Using the 'seed' integer, used to produce a series of
values sampled at an integral interval, interpolated from
a random series at interval 'step' found in the
specified 'range'.
If a final value is specified for the output series
then it's allowed to deviate by the 'final_precision'
fraction of the full range.
"""
def __init__(self, seed, step, range=(-1, 1), final_precision=0.05):
self.seed = seed
self.step = step
self.range = range
self.final_precision = final_precision
@property
def seed(self):
return self._seed
@seed.setter
def seed(self, val):
# Numpy now enforces mtrand 32-bit seed integer restriction
self._seed = val & 0xffffffff
def first(self):
"""
Return value of the first point of the generated
series.
"""
gen = numpy.random.mtrand.RandomState(self.seed)
return int(numpy.round(gen.uniform(self.range[0], self.range[1], 1)[0]))
def series(self, points, final=None):
"""
Produces a 'points' number long series of interpolated
values. If a 'final' vale is supplied then the last
value in the returned series will match this value to
within the precision specified by 'final_precision'.
"""
# Get the source random samples
source_points = int(numpy.ceil(float(points)/self.step))
gen = numpy.random.mtrand.RandomState(self.seed)
y1 = gen.uniform(self.range[0], self.range[1], source_points)
#x1 = numpy.linspace(-(float(source_points) % step), float(points) - 1, source_points)
x1 = numpy.linspace(0, float(points) + float(source_points) % self.step - 1, source_points)
# Adjust final sample to meet required result
if final is not None:
accept = abs(self.range[1] - self.range[0])*self.final_precision
for i in xrange(0, 20): # Really shouldn't go deeper than this but let's be sure
f = scipy.interpolate.interp1d(x1, y1, kind='cubic')
error = final - f(float(points) - 1)
if abs(error) < accept:
break
else:
y1[-1] = y1[-1] + error
# Find interpolated points
x2 = numpy.linspace(0.0, float(points) - 1, points)
y2 = scipy.interpolate.interp1d(x1, y1, kind='cubic')(x2)
return numpy.cast[int](numpy.round(y2))
def river_shore(shape, seed, base_width, v):
"""
Produce a series of points representing a meandering river width
"""
# Set up some required variables
axis, axis_inv = (0, 1) if v[0] != 0 else (1, 0)
next = numpy.ones(len(v), v.dtype); next[axis] = 0
centre_range = numpy.array(river_deviation_centre)
width_range = numpy.array(river_deviation_width)
# Discover the final point in the sequence based on the next block over
final_centre = Meander(seed.offset(next).centre_seed(v), river_frequency_centre, centre_range).first()
final_width = Meander(seed.offset(next).width_seed(v), river_frequency_width, width_range).first()
# Find the centre and width sequences that will contribute to the overall river
river_centres = Meander(seed.centre_seed(v), river_frequency_centre, centre_range).series(shape[axis_inv], final_centre)
river_widths = Meander(seed.width_seed(v), river_frequency_width, width_range).series(shape[axis_inv], final_width)
# Add everything up and make sure river never moves out of the chunk
widths = (base_width + c*v[axis] + w for c, w in itertools.izip(river_centres, river_widths))
return [w if w > 1 else 1 for w in widths]
def trace_ellipse(centre, axes, bound=((0, 0), (15, 15))):
"""
Trace the pixels of a quadrant of a specified ellipse
constrained to within a given window.
"""
# Ellipse interior checking function
abs_axes = numpy.abs(numpy.array(axes)) - corner_radius_offset
ax2, az2 = numpy.power(abs_axes, 2)
in_ellipse = lambda x, z: (float(x)**2/ax2 + float(z)**2/az2 < 1)
# Step through possible points until we find one in ellipse
upper = int(numpy.floor(abs_axes[1]))
for x in xrange(0, int(numpy.floor(abs_axes[0])) + 1):
for z in xrange(upper, -1, -1):
if in_ellipse(x, z):
upper = z
point = numpy.cast[int](centre + numpy.sign(axes)*numpy.array([x, z]))
if (numpy.array(bound[0]) <= point).all() and (numpy.array(bound[1]) >= point).all():
yield point
break
def mask_square(shape, inner, outer):
"""
Create an appropriately sized boolean mask with the
defined corner coordinates.
"""
a = numpy.zeros(shape, dtype=bool)
mx, my = shape
for x in xrange(inner[0], outer[0]):
a.data[mx*x+inner[1]:mx*x+outer[1]] = '\x01'*(outer[1] - inner[1])
return a
def mask_lines(shape, limits, start=0, step=1):
"""
Accepts a list of tuples with (start, end) horizontal
ranges. Start from specified x coordinate.
"""
a = numpy.zeros(shape, dtype=bool)
mx, my = shape
x = start
for line in limits:
if x < 0 or x >= mx:
break
start = my if line[0] > my else line[0]
end = my if line[1] > my else line[1]
a.data[mx*x+start:mx*x+end] = '\x01'*(end - start)
x += step
return a
def get_straights(edge):
""" Get vectors representing straight edges """
return [v for v in edge if v[0] == 0 or v[1] == 0]
def get_induced_corners(edge):
""" These corners are induced by straight edges """
corners = []
for x in (-1, 1):
for z in (-1, 1):
corner = numpy.array([x, z])
if all(vec.inside(v, edge) for v in vec.decompose(corner)):
corners.append(corner)
return corners
def get_corners(edge, straights):
""" Get vectors representing corners """
concave_corners = []
convex_corners = []
for corner in (v for v in edge if v[0] != 0 and v[1] != 0):
# Are the corner component vectors in straight edges?
in_straight = [vec.inside(v, straights) for v in vec.decompose(corner)]
# If all or none of the component vectors are in straight edges then it's a real corner
if all(in_straight):
convex_corners.append(corner)
elif not any(in_straight):
concave_corners.append(corner)
return concave_corners, convex_corners
def get_features(edge):
""" Returns only the edge components specifying neighbouring erosion features """
straights = get_straights(edge)
all_corners = itertools.chain(edge, (x for x in get_induced_corners(edge) if not vec.inside(x, edge)))
concave, convex = get_corners(all_corners, straights)
return straights, concave, convex
def mask_edge(shape, v, widths):
""" Create mask for one side of an area out of a sequence of widths """
axis = 0 if v[0] != 0 else 1
limits = ((0, x) for x in widths) if any(v < 0) else ((shape[axis] - x, shape[axis]) for x in widths)
vert = mask_lines(shape, limits)
return vert.T if axis == 0 else vert
def mask_concave_corner(shape, v, widths):
""" Creates mask for one corner of an area """
centre = (v+1)/2 * (numpy.array(shape) - 1)
sign = numpy.sign(v)
ellipse = trace_ellipse(centre, -sign*widths, (numpy.zeros(len(shape), int), numpy.array(shape) - 1))
limits = (numpy.sort([centre[1], z]) + numpy.array([0, 1]) for x, z in ellipse)
return mask_lines(shape, limits, centre[0], -sign[0])
def mask_convex_corner(shape, v, widths):
""" Creates mask for one corner of an area """
corner = (v+1)/2 * (numpy.array(shape) - 1)
sign = numpy.sign(v)
centre = corner + sign - 2*sign*widths
ellipse = list(trace_ellipse(centre, sign*widths, (numpy.zeros(len(shape), int), numpy.array(shape) - 1)))
clipped = numpy.maximum(numpy.minimum(centre, numpy.array(shape) - 1), numpy.zeros(len(shape), int))
limits1 = [numpy.sort([corner[1], z + sign[1]]) + numpy.array([0, 1]) for x, z in ellipse]
limits2 = (numpy.sort([corner[1], clipped[1]]) + numpy.array([0, 1]) for z in xrange(0, shape[0] - len(limits1)))
return mask_lines(shape, itertools.chain(limits1, limits2), clipped[0], sign[0])
def make_mask_straights(shape, width, seed, components, straights):
""" Make a mask out of all straight edge types """
mask = numpy.zeros(shape, dtype=bool)
for v in straights:
base_width = int(numpy.round(width/narrowing_factor)) if vec.inside(-v, components) else int(numpy.round(width))
shore = itertools.repeat(base_width) if seed is None else river_shore(shape, seed, base_width, v)
mask = numpy.logical_or(mask, mask_edge(shape, v, shore))
return mask
def make_mask_corners(shape, width, seed, components, concave, convex):
""" Make a mask out of all corners """
mask = numpy.zeros(shape, dtype=bool)
for corners, masker in ((concave, mask_concave_corner), (convex, mask_convex_corner)):
for v in corners:
xwidth = int(numpy.round(width/narrowing_factor)) if vec.inside(v*numpy.array([-1, 0], int), components) else int(numpy.round(width))
zwidth = int(numpy.round(width/narrowing_factor)) if vec.inside(v*numpy.array([ 0, -1], int), components) else int(numpy.round(width))
if seed is not None and masker is mask_concave_corner:
xwidth = river_shore(shape, seed, xwidth, v*numpy.array([1, 0]))[shape[1] - 1 if v[0] > 0 else 0]
zwidth = river_shore(shape, seed, zwidth, v*numpy.array([0, 1]))[shape[0] - 1 if v[1] > 0 else 0]
mask = numpy.logical_or(mask, masker(shape, v, (xwidth, zwidth)))
return mask
def make_mask(shape, edge, width, seed):
""" Make a mask representing a valley out of a countour edge specification """
straights, concave, convex = get_features(edge)
components = vec.uniques(itertools.chain.from_iterable(vec.decompose(v) for v in itertools.chain(straights, concave, convex)))
return numpy.logical_or(
make_mask_straights(shape, width, seed, components, straights),
make_mask_corners(shape, width, seed, components, concave, convex)
)
|
(* -------------------------------------------------------------------- *)
From mathcomp Require Import all_ssreflect all_algebra.
(* ------- *) Require Import misc.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Unset SsrOldRewriteGoalsOrder.
Import GRing.Theory Num.Theory Order.Theory.
Local Open Scope ring_scope.
(* -------------------------------------------------------------------- *)
Local Notation "x @ i" := (x 0 i) (at level 20).
Local Notation "x @^ i" := (x i 0) (at level 20).
Declare Scope syntax_scope.
(* -------------------------------------------------------------------- *)
Section LPDef.
Context {F : realFieldType} (n p : nat).
Context (A : 'M[F]_(n,p)) (b : 'rV[F]_p) (C : 'cV[F]_n).
Implicit Types (x : 'rV[F]_n).
(* -------------------------------------------------------------------- *)
Definition lpcost x := ((x *m C) 0 0).
Lemma lpcost_is_linear : scalar lpcost.
Proof.
by move=> a u v; rewrite /lpcost mulmxDl -scalemxAl 2!mxE.
Qed.
Canonical lpcost_additive := Additive lpcost_is_linear.
Canonical lpcost_linear := AddLinear lpcost_is_linear.
(* -------------------------------------------------------------------- *)
Definition lpset x :=
[forall i, 0 <= x @ i] && (x *m A == b).
Lemma lpsetP x :
reflect ((forall i, 0 <= x @ i) /\ x *m A = b) (lpset x).
Proof. apply: (iffP andP).
+ by case=> /forallP ? /eqP.
+ by case=> h1 h2; split; [apply/forallP | apply/eqP].
Qed.
Lemma lpset_ge0 x : lpset x -> forall i, 0 <= x @ i.
Proof. by case/lpsetP. Qed.
Lemma lpset_sol x : lpset x -> x *m A = b.
Proof. by case/lpsetP. Qed.
(* -------------------------------------------------------------------- *)
Definition lpconvex (S : 'rV[F]_n -> Prop) :=
forall x y, S x -> S y ->
forall k : F, 0 <= k <= 1 -> S (k *: x + (1 - k) *: y).
(* -------------------------------------------------------------------- *)
Definition lpcvxcb (S : 'rV[F]_n -> Prop) (x : 'rV[F]_n) :=
exists k (c : 'I_k -> F) (A : 'I_k -> 'rV[F]_n),
[/\ x = \sum_i c i *: A i
, \sum_i c i = 1
, forall i, 0 <= c i
& forall i, S (A i)].
(* -------------------------------------------------------------------- *)
CoInductive lpcvxcb_spec S x : Prop :=
| LPCvxCb k (c : 'I_k -> F) (A : 'I_k -> 'rV[F]_n) of
(x = \sum_i c i *: A i)
& (\sum_i c i = 1)
& (forall i, 0 <= c i)
& forall i, S (A i).
(* -------------------------------------------------------------------- *)
Lemma lpcvxcbP S x : lpcvxcb S x <-> lpcvxcb_spec S x.
Proof. split.
+ by case=> [k] [c] [G] [-> h1 h2 h3]; exists k c G.
+ by case=> k c G -> h1 h2 h3; exists k, c, G; split.
Qed.
(* -------------------------------------------------------------------- *)
Definition lpextrem x := lpset x /\
forall x1 x2 k,
0 < k < 1 -> lpset x1 -> lpset x2
-> x = k *: x1 + (1 - k) *: x2
-> x1 = x2.
(* -------------------------------------------------------------------- *)
Lemma lpextrem_sol x : lpextrem x -> lpset x.
Proof. by case. Qed.
(* -------------------------------------------------------------------- *)
Lemma lpextrem_ext x : lpextrem x ->
forall x1 x2 k,
0 < k < 1 -> lpset x1 -> lpset x2
-> x = k *: x1 + (1 - k) *: x2
-> x1 = x2.
Proof. by case. Qed.
(* -------------------------------------------------------------------- *)
Definition lpbounded :=
exists M : F, forall x, lpset x -> forall i, x @ i < M.
(* -------------------------------------------------------------------- *)
Definition lpbasei x :=
[seq i <- enum 'I_n | x @ i != 0].
(* -------------------------------------------------------------------- *)
Definition lpbase x :=
[seq row i A | i <- lpbasei x].
(* -------------------------------------------------------------------- *)
Lemma lpbaseiP x i : reflect (x @ i <> 0) (i \in lpbasei x).
Proof. by rewrite mem_filter mem_enum andbT; apply/(iffP idP) => /eqP. Qed.
(* -------------------------------------------------------------------- *)
Lemma lpbaseiPn x i : i \notin lpbasei x <-> x @ i = 0.
Proof. split.
+ by rewrite mem_filter mem_enum andbT negbK (rwP eqP).
+ by move=> z_xi; rewrite mem_filter z_xi eqxx mem_enum.
Qed.
(* -------------------------------------------------------------------- *)
Lemma uniq_lpbasei x : uniq (lpbasei x).
Proof. by apply/filter_uniq/enum_uniq. Qed.
(* -------------------------------------------------------------------- *)
Lemma cvxcb_mem (S : 'rV[F]_n -> Prop) x : S x -> lpcvxcb S x.
Proof.
exists 1%N, (fun i => 1), (fun u => x); split=> //.
- by rewrite big_const_ord iterS addr0 scale1r.
- by rewrite big_const_ord iterS addr0.
- by rewrite ltW // ltr01.
Qed.
(* -------------------------------------------------------------------- *)
Lemma cvx_cvxcb S : lpconvex (lpcvxcb S).
Proof.
move=> x1 x2 /lpcvxcbP[k1 c1 A1 -> sm1 ge01 SA1].
move=> /lpcvxcbP[k2 c2 A2 -> sm2 ge02 SA2] k /andP[ge0_k le1_k].
pose c := fsplit (fun i => k * c1 i) (fun i => (1 - k) * c2 i).
pose G := fsplit (fun i => A1 i) (fun i => A2 i).
pose Z1 i : 'rV[F]_n := (k * c1 i) *: A1 i.
pose Z2 i : 'rV[F]_n := ((1 - k) * c2 i) *: A2 i.
apply/lpcvxcbP; exists _ c G.
- rewrite !scaler_sumr [RHS](eq_bigr (fsplit Z1 Z2)).
+ by move=> i _; rewrite /c /G /fsplit; case: split.
by rewrite big_fsplit /= /Z1 /Z2; congr +%R;
apply/eq_bigr => i _; rewrite scalerA.
- rewrite big_fsplit /= -!mulr_sumr !(sm1, sm2) !mulr1.
by rewrite addrCA subrr addr0.
- move=> i; rewrite /c /fsplit; case: split => j.
+ by rewrite mulr_ge0.
+ by rewrite mulr_ge0 // subr_ge0.
- by move=> i; rewrite /G /fsplit; case: split => j.
Qed.
End LPDef.
(* ==================================================================== *)
Section LP.
Context {F : realFieldType} (n' p' : nat).
Local Notation n := n'.+1.
Local Notation p := p'.+1.
Context (A : 'M[F]_(n,p)) (b : 'rV[F]_p) (C : 'cV[F]_n).
Local Notation lpbase := (lpbase A).
Local Notation lpbounded := (lpbounded A b).
Local Notation lpset x := (lpset A b x).
Local Notation lpextrem := (fun x => lpextrem A b x).
Local Notation lpcost := (lpcost C).
Implicit Types (x : 'rV[F]_n).
Lemma free_lpbaseP x (μ : 'I_n -> F) :
free (lpbase x)
-> (forall i : 'I_n, i \notin lpbasei x -> μ i = 0)
-> \sum_j (μ j *: row j A) = 0
-> forall i, μ i = 0.
Proof.
move=> frx zμ; rewrite (bigID (mem (lpbasei x))) /= addrC big1.
+ by move=> i /zμ ->; rewrite scale0r.
rewrite add0r -big_uniq ?uniq_lpbasei //= => h.
move: frx; rewrite -[lpbase x]in_tupleE => /freeP.
have eqp: size (lpbase x) = size (lpbasei x) by rewrite size_map.
pose k j := μ (tnth (in_tuple (lpbasei x)) (cast_ord eqp j)).
move/(_ k) => zk i; case/boolP: (i \in lpbasei x); last by apply/zμ.
case/seq_tnthP=> [[j ltji] ->]; rewrite (tnth_nth 0) /=.
have ltj: (j < size (lpbase x))%N by rewrite eqp.
have := zk _ (Ordinal ltj); rewrite /k (tnth_nth 0); apply.
pose G i : 'rV[F]_p := μ (lpbasei x)`_i *: row (lpbasei x)`_i A.
rewrite (eq_bigr (G \o val)) => /= [z _|].
+ by rewrite {}/G (tnth_nth 0) (nth_map 0) // -eqp.
rewrite -(big_mkord xpredT G) {}/G eqp.
by rewrite -(big_nth 0 xpredT (fun i => μ i *: row i A)).
Qed.
(* -------------------------------------------------------------------- *)
Lemma free_lpbasePn x :
~~ free (lpbase x) -> exists (μ : 'rV[F]_n),
[/\ \sum_(i < n) μ @ i *: row i A = 0
, forall i, i \notin lpbasei x -> μ @ i = 0
& μ != 0].
Proof.
rewrite -[lpbase _]in_tupleE freeNE => /existsP[j /coord_span /=].
have ltj: (j < size (lpbasei x))%N by move: j; rewrite /= size_map.
set s := drop_tuple _ _; set e := lpbase x.
pose X := [seq coord s i e`_j | i <- enum 'I_(size e - j.+1)].
pose G i : 'rV[F]_p := ((nseq j.+1 0) ++ X)`_i *: e`_i.
rewrite (eq_bigr ((G \o (fun i => i + j.+1)%N) \o val)) => [/= i _|].
+ rewrite {}/G [(i+_)%N]addnC -!nth_drop drop_size_cat ?size_nseq //.
by rewrite (nth_map i) ?size_enum_ord // nth_ord_enum.
rewrite -(big_mkord xpredT) /= -(big_addn _ _ _ xpredT) add0n => ejE.
exists (\row_i (nseq j 0 ++ (-1) :: X)`_(index i (lpbasei x))); split.
+ rewrite (bigID (fun i => i \in lpbasei x)) /= addrC big1 ?add0r.
- move=> i ix; rewrite !mxE nth_default ?scale0r //.
rewrite /X /= size_cat size_nseq /= -addSnnS !size_map.
by rewrite size_enum_ord subnKC // leqNgt size_map index_mem.
rewrite -big_uniq ?uniq_lpbasei //= (big_nth 0).
pose H i := (nseq j 0 ++ (-1) :: X)`_i *: e`_i.
rewrite (eq_big_nat _ _ (F2 := H)) {}/H => /= [i lti|].
- by rewrite !mxE index_uniq ?uniq_lpbasei // /e (nth_map 0).
rewrite (big_cat_nat _ (n := j.+1)) //= big_nat_recr //=.
rewrite big_nat big1 ?add0r => /= [i lt_ij|].
- by rewrite nth_cat size_nseq lt_ij nth_nseq lt_ij scale0r.
rewrite nth_cat size_nseq ltnn subnn /= scaleN1r ejE addrC.
rewrite {4}[size e]size_map -sumrB big_nat big1 //.
move=> i /andP[lt_ji lt_i]; rewrite /G !nth_cat !size_nseq.
rewrite ![(i < _)%N]ltnNge ltnW // lt_ji /= subnS.
move: lt_ji; rewrite -subn_gt0; case: (i - j)%N => //=.
by move=> n _; rewrite subrr.
+ move=> i ix; rewrite !mxE nth_default // size_cat size_nseq /=.
rewrite -addSnnS /X /= size_map size_enum_ord subnKC //.
by rewrite leqNgt size_map index_mem.
+ apply/eqP/rowP => /(_ (lpbasei x)`_j); rewrite !mxE.
rewrite index_uniq ?uniq_lpbasei // nth_cat size_nseq.
by rewrite ltnn subnn /= (rwP eqP) oppr_eq0 oner_eq0.
Qed.
(* -------------------------------------------------------------------- *)
Local Lemma L1 (μ : 'rV[F]_n) x :
lpbounded -> lpset x -> μ != 0
-> (forall i : 'I_n, i \notin lpbasei x -> μ @ i = 0)
-> \sum_i μ @ i *: row i A = 0
-> exists2 ij, 0 < μ @ ij.1 & 0 > μ @ ij.2.
Proof.
case=> M ltM solx nzμ basμ bdμ; move/eqP/rowP/eqfunP: nzμ.
case/forallPn=> /= i; rewrite !mxE => /negP nz_μi.
wlog: i μ basμ bdμ nz_μi / 0 < μ @ i => [wlog|].
+ case/lt_total/orP: (nz_μi) => [lt0_μi|]; last by apply/wlog.
case: (wlog i (- μ)); rewrite ?mxE ?(oppr_cp0, oppr_eq0) //.
* by move=> j hj; rewrite !mxE (rwP eqP) oppr_eq0 basμ.
* rewrite -[RHS]oppr0 -[X in _=-X]bdμ (rwP eqP) -addr_eq0.
rewrite -big_split big1 //= => j _; rewrite !mxE.
by rewrite scaleNr addNr.
by case=> j1 j2 /=; rewrite !mxE !oppr_cp0; exists (j2, j1).
move=> gt0_μi; case/boolP: [forall i, 0 <= μ @ i]; last first.
+ by case/forallPn=> /= j /negP; rewrite -ltNge; exists (i, j).
move/forallP=> /= ge0_μ; have ix: i \in lpbasei x.
+ by apply/contraLR: nz_μi => /basμ ->; rewrite negbK.
have lp_xDkμ: forall k, 0 <= k -> lpset (x + k *: μ).
+ move=> k ge0_k; apply/lpsetP; split.
* move=> j; rewrite !mxE addr_ge0 1?(lpset_ge0, mulr_ge0) //.
by apply/(lpset_ge0 solx).
rewrite mulmxDl (lpset_sol solx) // -scalemxAl mulmx_sum_row.
by rewrite bdμ scaler0 addr0.
have: 0 <= M / μ@i; first rewrite divr_ge0 //.
+ by apply/ltW/(le_lt_trans (lpset_ge0 solx i))/ltM.
move/lp_xDkμ => {lp_xDkμ} /ltM/(_ i); rewrite !mxE.
by rewrite -mulrA mulVf // mulr1 gtr_addr ltNge (lpset_ge0 solx).
Qed.
(* -------------------------------------------------------------------- *)
Local Lemma L2 (μ : 'rV[F]_n) x :
lpbounded -> lpset x -> μ != 0
-> (forall i : 'I_n, i \notin lpbasei x -> μ @ i = 0)
-> \sum_i μ @ i *: row i A = 0
-> exists (t : F) (i : 'I_n), [/\
0 < t, lpset (x - t *: μ),
x @ i != 0 & (x - t *: μ) @ i == 0].
Proof.
move=> bd lpx nzμ basμ bdμ; case: (@L1 μ x) => //.
case=> i _ /= gt0_μi _; have hp: exists i, 0 < μ @ i by exists i.
pose k : 'I_n := arg_minr (fun i => x @ i / μ @ i) hp.
pose t : F := x @ k / μ @ k; exists t, k.
rewrite /t /k; case: arg_minrP=> {t k gt0_μi hp} /=.
move=> k gt0_μk bdk; split; rewrite ?mxE.
+ rewrite divr_gt0 // lt_neqAle (lpset_ge0 lpx) // andbT.
rewrite eq_sym; apply/eqP/lpbaseiPn => /basμ.
by move/eqP; rewrite gt_eqF.
+ apply/lpsetP; split => [j|]; rewrite ?mxE.
* rewrite subr_ge0; case: (ltrP 0 (μ @ j)).
- by move=> gt0_μj; rewrite -ler_pdivl_mulr // bdk.
move=> le0_μj; apply/(@le_trans _ _ 0)/(lpset_ge0 lpx) => //.
by rewrite mulr_ge0_le0 // divr_ge0 ?(lpset_ge0 lpx) ?ltW.
* rewrite mulmxBl (lpset_sol lpx) // -scalemxAl mulmx_sum_row.
by rewrite bdμ scaler0 subr0.
+ by apply/eqP => /lpbaseiPn /basμ /eqP; rewrite gt_eqF.
+ rewrite -mulrA mulVf; first by rewrite gt_eqF.
by rewrite mulr1 subrr.
Qed.
(* -------------------------------------------------------------------- *)
Local Lemma L3 x :
lpbounded -> lpset x -> ~~ free (lpbase x) ->
exists x1 x2 k, [/\
0 < k < 1, x1 != x2, x = k *: x1 + (1 - k) *: x2,
[/\ lpset x1 & lpset x2] &
[/\ {subset lpbasei x1 ++ lpbasei x2 <= lpbasei x}
, exists2 e : 'I_n, e \in lpbasei x & e \notin lpbasei x1
& exists2 e : 'I_n, e \in lpbasei x & e \notin lpbasei x2]].
Proof.
move=> bd lpx /free_lpbasePn [μ /= [bdμ basμ nzμ]].
pose y k : 'rV[F]_n := x + k *: μ.
have h j: {subset lpbasei (y j) <= lpbasei x}.
+ move=> /= z /lpbaseiP; rewrite {}/y !mxE.
case/boolP: (z \in lpbasei x) => // h.
by rewrite basμ // mulr0 addr0; move/lpbaseiPn: h.
case: (@L2 μ x) => // t1 [i1 [ge0_t1 lpx1 /eqP nz_xi1 z_x1]].
have {z_x1} st1: i1 \notin lpbasei (y (-t1)).
+ by apply/lpbaseiPn; rewrite /y scaleNr (eqP z_x1).
case: (@L2 (- μ) x) => //; last move=> t2 [i2 []].
+ by rewrite oppr_eq0.
+ by move=> i /basμ; rewrite !mxE => ->; rewrite oppr0.
+ rewrite -[RHS]oppr0 -[0 in RHS]bdμ (rwP eqP).
rewrite -addr_eq0 -big_split /= big1 // => i _.
by rewrite !mxE scaleNr addNr.
rewrite !scalerN !opprK => ge0_t2 lpx2 /eqP nz_xi2 z_x2.
have {z_x2} st2: i2 \notin lpbasei (y t2).
+ by apply/lpbaseiPn; rewrite /y (eqP z_x2).
pose k := t2 / (t1 + t2); have in01_k: 0 < k < 1.
+ rewrite divr_gt0 1?addr_gt0 //= ltr_pdivr_mulr ?addr_gt0 //.
by rewrite mul1r ltr_addr.
have xE: x = k *: (x - t1 *: μ) + (1 - k) *: (x + t2 *: μ).
+ rewrite !(scalerBr, scalerDr) addrACA -scalerDl.
rewrite [k + _]addrCA subrr addr0 scale1r -!scaleNr.
rewrite !scalerA -scalerDl; set l := (X in X *: _).
suff ->: l = 0 by rewrite scale0r addr0.
rewrite {}/l {in01_k}/k -mulNr mulrAC -[1]divr1.
rewrite addf_div ?oner_neq0 // ?gt_eqF ?addr_gt0 //.
rewrite !(mul1r, mulr1) [X in _ + X]mulrAC -mulrDl.
by rewrite -addrA subrr addr0 mulNr [t2*_]mulrC addNr mul0r.
exists (x - t1 *: μ), (x + t2 *: μ), k; split=> //; last first.
+ split.
* by move=> e; rewrite mem_cat => /orP[]; rewrite -?scaleNr => /h.
* by exists i1; rewrite -?scaleNr //; apply/lpbaseiP.
* by exists i2 => //; apply/lpbaseiP.
rewrite -subr_eq0 opprD addrACA subrr add0r -scaleNr.
rewrite -scalerBl scaler_eq0 (negbTE nzμ) orbF.
by rewrite -opprD oppr_eq0 gt_eqF // addr_gt0.
Qed.
(* -------------------------------------------------------------------- *)
Lemma lpbase_freeP x : lpset x -> free (lpbase x) -> lpextrem x.
Proof.
move=> lpx frx; split=> // x1 x2 k /andP [ge0k lt1k] lp1 lp2 xE.
apply/rowP=> i; have h (j : 'I_n): j \notin lpbasei x -> x1 @ j = x2 @ j.
+ move/lpbaseiPn; rewrite xE !mxE (rwP eqP) paddr_eq0.
- by rewrite mulr_ge0 1?(lpset_ge0 lp1) 1?ltW.
- by rewrite mulr_ge0 1?(lpset_ge0 lp2) 1?ltW // subr_gt0.
case/andP; rewrite !mulf_eq0 subr_eq0 [_ == k]eq_sym.
by rewrite [k == 0]gt_eqF 1?[k == 1]lt_eqF //= => /eqP-> /eqP->.
case/boolP: (i \in lpbasei x) => [i_in_nzx|/h //]; apply/eqP.
rewrite -subr_eq0 -(rwP eqP); pose w i := x1 @ i - x2 @ i.
apply/(free_lpbaseP (μ := w) frx) => /=.
+ by move=> j /h /eqP; rewrite -subr_eq0 (rwP eqP).
rewrite -[RHS](subrr b) -{1}(lpset_sol lp1) -(lpset_sol lp2).
rewrite !mulmx_sum_row -sumrB; apply/eq_bigr.
by move=> /= o _; rewrite scalerBl.
Qed.
(* -------------------------------------------------------------------- *)
Lemma lpbase_freePn x :
lpbounded -> lpextrem x -> free (lpbase x).
Proof.
move=> bd [lpx lpex]; case/boolP: (free _) => // /L3.
case=> // [x1] [x2] [k] [in01_k neq_xi xE [lpx1 lpx2] _].
move/(_ _ _ _ in01_k lpx1 lpx2 xE): lpex => {lpx1 lpx2 xE}.
by rewrite (rwP eqP) (negbTE neq_xi).
Qed.
(* -------------------------------------------------------------------- *)
Lemma lp_cvx_hull x :
lpbounded -> lpset x -> lpcvxcb lpextrem x.
Proof.
move=> bp; move: x; suff h: forall n x,
(size (lpbasei x) < n)%N -> lpset x -> lpcvxcb lpextrem x.
+ by move=> x lpx; apply: (h (size (lpbasei x)).+1).
elim=> [|k ih] x; rewrite (ltn0, ltnS) // => ltn lpx.
case/boolP: (free (lpbase x)) => [fpx|].
+ by apply/cvxcb_mem/lpbase_freeP.
case/L3 => // [x1] [x2] [l] [in01_l neq_xi xE [lpx1 lpx2]].
case=> lep [i1 st1 stN1] [i2 st2 stN2].
have sub1: {subset lpbasei x1 <= lpbasei x}.
+ by move=> i hi; apply/lep; rewrite mem_cat hi.
have sub2: {subset lpbasei x2 <= lpbasei x}.
+ by move=> i hi; apply/lep; rewrite mem_cat hi orbT.
have lt1: (size (lpbasei x1) < k)%N.
+ apply/(leq_trans _ ltn); rewrite ltnNge; apply/negP=> le_sz.
case: (uniq_min_size (uniq_lpbasei _) sub1 le_sz).
by move=> _ mi; move: stN1; rewrite mi st1.
have lt2: (size (lpbasei x2) < k)%N.
+ apply/(leq_trans _ ltn); rewrite ltnNge; apply/negP=> le_sz.
case: (uniq_min_size (uniq_lpbasei _) sub2 le_sz).
by move=> _ mi; move: stN2; rewrite mi st2.
have [h1 h2] := (ih _ lt1 lpx1, ih _ lt2 lpx2).
rewrite xE; apply/cvx_cvxcb=> //.
by case/andP: in01_l=> *; rewrite !ltW.
Qed.
(* -------------------------------------------------------------------- *)
Lemma lpmax_on_extrems x :
lpbounded -> lpset x ->
exists2 e, lpextrem e & lpcost x <= lpcost e.
Proof.
move=>lpb /lp_cvx_hull /lpcvxcbP[] // k c E xE sm1 ge0_c ex.
case/boolP: [exists i, lpcost (E i) >= lpcost x].
+ by case/existsP=> /= i le; exists (E i).
move/existsPn=> /= gt; suff: lpcost x < lpcost x by rewrite ltxx.
have {1}->: lpcost x = \sum_i c i * (lpcost (E i)).
+ by rewrite xE linear_sum /=; apply/eq_bigr=> i _; rewrite linearZ.
rewrite -[X in _ < X]mul1r -sm1 mulr_suml; have: exists i, 0 < c i.
+ apply/existsP; move/eqP: sm1; apply/contraLR => /existsPn=> /= eq0.
rewrite big1 1?eq_sym ?oner_eq0 // => i _; apply/eqP.
by rewrite eq_le ge0_c andbT leNgt -(rwP negP).
case=> i gt0_ci; rewrite [X in X < _](bigD1 i) //=.
rewrite [X in _ < X](bigD1 i) //=; apply/ltr_le_add.
+ by rewrite ltr_pmul2l // ltNge -(rwP negP).
+ apply/ler_sum=> j ne_ji; rewrite ler_wpmul2l //.
by apply/ltW; rewrite ltNge -(rwP negP).
Qed.
(* -------------------------------------------------------------------- *)
Local Notation lpmask m := (mask m (enum 'I_n)).
CoInductive lpesol_spec (m : n.-tuple bool) (s : seq 'rV[F]_n) : Prop :=
| LPENFree of
~~ free [seq row i A | i <- lpmask m] & s = [::]
| LPEFree of
free [seq row i A | i <- lpmask m]
& (size s <= 1)%N
& (forall x, reflect (lpset x /\ {subset lpbasei x <= lpmask m}) (x \in s)).
Lemma lpesolP (m : n.-tuple bool) : {s : seq 'rV[F]_n | lpesol_spec m s}.
Proof.
case/boolP: (free [seq row i A | i <- lpmask m]); last first.
+ by move=> Nfrx; exists [::]; apply/LPENFree.
move=> frx; set X := [seq row i A | i <- lpmask m] in frx.
case/boolP: (b \in <<X>>%VS); last first.
+ move=> bNX; exists [::]; apply/LPEFree=> // x; rewrite in_nil.
constructor=> -[lpx lpbx]; move/negP: bNX; apply; rewrite -[X]in_tupleE.
apply/spanP=> /=; exists (fun i => x @ ((lpmask m)`_i)); apply/esym.
rewrite -[RHS](lpset_sol lpx) mulmx_sum_row; apply/esym.
rewrite (bigID (mem (lpmask m))) /= addrC big1 ?add0r => [i ilpi|].
* case: (x @ i =P 0) => [->|]; first by rewrite scale0r.
by move/lpbaseiPn/negP/negbNE/lpbx; rewrite (negbTE ilpi).
pose G i : 'rV[F]_p := x @ (lpmask m)`_i *: X`_i.
rewrite [RHS](eq_bigr (G \o val)) -?(big_mkord xpredT) /=.
* by move=> i _; rewrite {}/G (tnth_nth 0).
rewrite -big_uniq ?mask_uniq ?enum_uniq //= (big_nth 0).
rewrite /X size_map; apply/eq_big_nat => i.
by case/andP=> _ lti; rewrite /G (nth_map 0).
case/(free_span frx) => /= μ bE uq; have uqX := free_uniq frx.
pose x := \row_i (if i \in lpmask m then μ X`_(index i (lpmask m)) else 0).
have uqx y: {subset lpbasei y <= lpmask m} -> y *m A = b -> x = y.
+ move=> ylpi; rewrite mulmx_sum_row (bigID (mem (lpmask m))) /=.
rewrite addrC big1 ?add0r => [i iNlpi|].
* suff ->: y @ i = 0 by rewrite scale0r.
by apply/lpbaseiPn/negP => /ylpi; rewrite (negbTE iNlpi).
rewrite -big_uniq ?mask_uniq ?enum_uniq //=.
pose G (x : 'rV_p) : 'rV_p := y @ (lpmask m)`_(index x X) *: x.
rewrite big_seq (eq_bigr (G \o (fun i : 'I_n => X`_(index i (lpmask m))))).
* move=> i ilpi /=; rewrite {}/G; congr *:%R; last first.
- by rewrite (nth_map 0) ?index_mem // nth_index.
by rewrite index_uniq ?size_map ?index_mem // nth_index.
rewrite -big_seq /= -(big_map _ xpredT); set s := map _ _.
have ->: s = X; first apply/(@eq_from_nth _ 0).
* by rewrite !size_map.
* move=> i; rewrite !size_map => ilpi; rewrite !(nth_map 0) //.
- by rewrite index_uniq // ?mask_uniq ?enum_uniq.
by rewrite nth_index // mem_nth.
rewrite {}/G => /esym /uq eqμ; apply/rowP=> i.
rewrite !mxE; case: ifPn => [ilpi|]; last first.
* move=> iNlpi; apply/esym/lpbaseiPn/negP.
by move/ylpi; rewrite (negbTE iNlpi).
rewrite -eqμ ?mem_nth // ?size_map ?index_mem //.
by rewrite index_uniq ?size_map ?index_mem // nth_index.
case/boolP: [forall i, 0 <= x @ i]; last first.
+ move=> h; exists [::]; apply/LPEFree=> //= y.
constructor; move/forallPn: h=> /= [j]; rewrite (rwP negP) -ltNge.
move=> lt0_xj -[] /lpsetP[ge0_y soly] /uqx /(_ soly) /rowP /(_ j).
by move=> xjE; move: lt0_xj; rewrite xjE ltNge ge0_y.
move/forallP=> /= ge0_x; exists [:: x]; apply/LPEFree=> //.
move=> y; rewrite mem_seq1; apply: (iffP eqP) => [->|]; last first.
+ by case=> /lpset_sol h1 h2; apply/esym/uqx.
split; first (apply/lpsetP; split => //).
* rewrite mulmx_sum_row (bigID (mem (lpmask m))) /= addrC big1.
- by move=> i iNlpi; rewrite /x !mxE (negbTE iNlpi) scale0r.
rewrite add0r [RHS]bE [RHS]big_map -big_uniq /=.
- by rewrite mask_uniq ?enum_uniq.
rewrite !big_seq; apply/eq_bigr => /= i ilpi.
by rewrite /x !mxE ilpi (nth_map 0) ?index_mem ?nth_index.
* move=> i /lpbaseiP /eqP; apply/contraR => iNlpi.
by rewrite /x !mxE (negbTE iNlpi).
Qed.
(* -------------------------------------------------------------------- *)
Definition lpextrems : seq 'rV[F]_n :=
undup (flatten [seq tag (lpesolP m) | m <- enum {: n.-tuple bool}]).
(* -------------------------------------------------------------------- *)
Lemma lpextremsP x : lpbounded ->
reflect (lpextrem x) (x \in lpextrems).
Proof. move=> bd; apply: (iffP idP).
+ rewrite mem_undup => /flatten_mapP [/= m _].
case: lpesolP => /= rv [_ ->//| frx _ /(_ x) /rwP [_ h /h {h}]].
case=> lpx lpi; apply/lpbase_freeP => //.
apply/(sub_free _ frx); last first.
* rewrite map_inj_in_uniq ?uniq_lpbasei // => /= y1 y2.
move=> /lpi h1 /lpi h2; set s := map _ _ in frx.
have ->: row y1 A = s`_(index y1 (lpmask m)).
- by rewrite (nth_map 0) ?index_mem // nth_index.
have ->: row y2 A = s`_(index y2 (lpmask m)).
- by rewrite (nth_map 0) ?index_mem // nth_index.
move/eqP; rewrite nth_uniq ?size_map ?index_mem //.
- by apply/free_uniq.
rewrite -(@nth_uniq _ 0 (lpmask m)) ?index_mem //.
- by rewrite mask_uniq ?enum_uniq.
by rewrite !nth_index // (rwP eqP).
by move=> /= y /mapP[/= i /lpi im ->]; apply/map_f.
+ case=> lpx lpex; rewrite mem_undup; apply/flatten_mapP => /=.
exists [tuple x @ i != 0 | i < n]; first by rewrite mem_enum.
have frx := (@lpbase_freePn x bd (conj lpx lpex)).
case: lpesolP => /= rv [/= h _|]; first move: h.
* by rewrite -filter_mask frx.
move=> _ _ /(_ x) /rwP [h _]; apply/h; split=> //= {h} i.
rewrite -filter_mask => /lpbaseiP /eqP nz_xi.
by rewrite mem_filter nz_xi mem_enum.
Qed.
(* -------------------------------------------------------------------- *)
Lemma lpsolvebd_r : lpbounded -> {x | lpset x} ->
{x | lpset x /\ forall y, lpset y -> lpcost y <= lpcost x}.
Proof.
move=> bd [x lpx]; pose I := seq_sub lpextrems; have x0: I.
+ case E: lpextrems => [|y s]; last first.
* have pr: y \in lpextrems by rewrite E mem_head.
by apply: (SeqSub pr).
absurd False => //; case: (lp_cvx_hull bd lpx) => -[|k] [c] [M] [_].
* by rewrite big_ord0 (rwP eqP) eq_sym oner_eq0.
by move=> _ _ /(_ 0) /(@lpextremsP _ bd); rewrite E.
have h := ex_intro xpredT x0 (erefl true).
pose m : I := arg_minr (fun x : I => - lpcost (val x)) h.
exists (val m); rewrite {}/m; case: arg_minrP => -[/= m lme] _ min.
move/lpextremsP: lme => /(_ bd) [lpm _]; split=> // y lpy.
have {}min: forall j, lpextrem j -> lpcost j <= lpcost m.
+ move=> j /lpextremsP -/(_ bd) lje; have /= := min (SeqSub lje).
by rewrite ler_oppr opprK; apply.
have /lpcvxcbP [k c M -> sc1 ge0_c exM] := lp_cvx_hull bd lpy.
rewrite linear_sum /=; apply/(@le_trans _ _ (\sum_i (c i * lpcost m))).
+ apply/ler_sum=> i _; rewrite linearZ /= ler_wpmul2l //.
by apply/min/exM.
+ by rewrite -mulr_suml sc1 mul1r.
Qed.
End LP.
(* -------------------------------------------------------------------- *)
Lemma lpsolvebd {F : realFieldType} {n p} (A : 'M[F]_(n, p)) b c :
lpbounded A b -> {x | lpset A b x} ->
{x | lpset A b x /\ forall y, lpset A b y -> lpcost c y <= lpcost c x}.
Proof.
case: n A c => [|n] A c.
+ move=> _ [x hx]; exists x; split=> // y _; rewrite /lpcost.
by rewrite !mulmx_sum_row !summxE !big_ord0.
case: p A b => [|p] A b; last by apply/lpsolvebd_r.
move=> h _; absurd false => //; case: h => M h.
have ge0_M: 0 < M; first have := h 0 _ 0.
- rewrite mxE; apply; apply/lpsetP; split.
* by move=> i; rewrite mxE.
* by apply/rowP=> -[].
pose x := \row_(_ < n.+1) M; have: lpset A b x.
- apply/lpsetP; split; last by apply/rowP=> -[].
by move=> i; apply/ltW; rewrite mxE.
by move/h=> /(_ 0); rewrite mxE ltxx.
Qed.
(* ==================================================================== *)
Delimit Scope syntax_scope with T.
Section LPPb.
Context {F : realFieldType} (n : nat).
Inductive lprel := LPRLe | LPRGe | LPREq.
Bind Scope syntax_scope with lprel.
Notation "<=%:T" := LPRLe : syntax_scope.
Notation ">=%:T" := LPRGe : syntax_scope.
Notation "==%:T" := LPREq : syntax_scope.
Scheme Equality for lprel.
Lemma lprel_eqP : Equality.axiom lprel_beq.
Proof. by case=> [] [] /=; constructor. Qed.
Definition lprel_eqMixin := EqMixin lprel_eqP.
Canonical lprel_eqType := Eval hnf in EqType lprel lprel_eqMixin.
Definition rel_of_lprel (r : lprel) :=
match r return rel F with
| (<=%:T)%T => <=%R
| (>=%:T)%T => >=%R
| (==%:T)%T => eq_op
end.
Coercion rel_of_lprel : lprel >-> rel.
Record lpeq := LPEq {
lpeq_coeffs : 'cV[F]_n;
lpeq_rel : lprel;
lpeq_const : F;
}.
Coercion lpeq_coeffs : lpeq >-> matrix.
Coercion lpeq_rel : lpeq >-> lprel.
Notation "a <= b" := (LPEq a <=%:T b) : syntax_scope.
Notation "a >= b" := (LPEq a >=%:T b) : syntax_scope.
Notation "a == b" := (LPEq a ==%:T b) : syntax_scope.
Notation "a =[ r ]= b" := (LPEq a r b)
(at level 70, no associativity, format "a =[ r ]= b")
: syntax_scope.
Definition mem_lpeq (e : lpeq) (x : 'rV[F]_n) :=
let: LPEq a r b := e in r ((x *m a) 0 0) b.
Canonical lpeq_predType :=
Eval hnf in PredType (fun e : lpeq => mem_lpeq e).
Lemma mem_lpeqE (e : lpeq) (x : 'rV[F]_n) : (x \in e) = mem_lpeq e x.
Proof. by []. Qed.
Record lppb (k : nat) := LPPb {
lppb_eqs : k.-tuple lpeq;
lppb_bnd : F;
lppb_cost : {linear 'rV[F]_n -> F^o};
}.
Definition mem_lppb {k} (pb : lppb k) (x : 'rV[F]_n) :=
[forall i, x \in tnth pb.(lppb_eqs) i]
&& [forall i, `|x @ i| <= pb.(lppb_bnd)].
Canonical lppb_predType {k} :=
Eval hnf in PredType (fun pb : lppb k => mem_lppb pb).
Lemma lppbP {k} (pb : lppb k) (x : 'rV[F]_n) :
reflect
( (forall i, x \in tnth pb.(lppb_eqs) i)
/\ (forall i, `|x @ i| <= pb.(lppb_bnd)))
(x \in pb).
Proof. apply: (iffP andP).
+ by case=> /forallP? /forallP?; split.
+ by case=> ??; split; apply/forallP.
Qed.
(* -------------------------------------------------------------------- *)
Notation vshift k x := (lshift (n+n) (@lshift (n+n) k x)).
Notation eshift k x := (lshift (n+n) (@rshift (n+n) k x)).
Notation bshift k x := (@rshift ((n+n)+k) (n+n) x).
(* -------------------------------------------------------------------- *)
Local Notation Z k := ((n + n) + k + (n + n))%N.
Section ZInd.
Context {k} (P : 'I_(Z k) -> Prop).
Hypothesis hvl : forall i, P (vshift _ (lshift _ i)).
Hypothesis hvr : forall i, P (vshift _ (rshift _ i)).
Hypothesis he : forall i, P (eshift _ i).
Hypothesis hbl : forall i, P (bshift _ (lshift _ i)).
Hypothesis hbr : forall i, P (bshift _ (rshift _ i)).
Lemma zW i : P i.
Proof. by move: i; do! elim/splitW. Qed.
End ZInd.
(* -------------------------------------------------------------------- *)
Definition lpeq_var (x : 'I_n) : 'cV[F]_n := delta_mx x 0.
Definition lpeq_shift {k} (x : 'I_k) : 'cV[F]_k := delta_mx x 0.
Definition lpeq_bd (x : 'I_n) : 'cV[F]_n := delta_mx x 0.
Definition lprel_sign (r : lprel) :=
match r return F with
| (<=%:T)%T => 1
| (>=%:T)%T => -1
| (==%:T)%T => 0
end.
(* -------------------------------------------------------------------- *)
Record nmpb (n k : nat) := NMPb {
nmpb_coeffs : 'M[F]_(n, k);
nmpb_const : 'rV[F]_k;
nmpb_cost : 'cV[F]_n;
}.
Definition mem_nmpb {n k} (pb : nmpb n k) (x : 'rV[F]_n) :=
lpset pb.(nmpb_coeffs) pb.(nmpb_const) x.
Canonical nmpb_predType {n k} :=
Eval hnf in PredType (fun pb : nmpb n k => mem_nmpb pb).
Lemma nmpbP {m k} (pb : nmpb m k) (x : 'rV[F]_m) :
(x \in pb) = lpset pb.(nmpb_coeffs) pb.(nmpb_const) x.
Proof. by []. Qed.
(* -------------------------------------------------------------------- *)
Definition normmx {k} xp xn s bp bn : 'cV[F]_(Z k) :=
col_mx (col_mx (col_mx xp xn) s) (col_mx bp bn).
Definition mxvar {k} (M : 'rV[F]_(Z k)) :=
lsubmx (lsubmx M).
Definition mxbd {k} (M : 'rV[F]_(Z k)) :=
rsubmx M.
Definition mxvarp {k} (M : 'rV[F]_(Z k)) := lsubmx (mxvar M).
Definition mxvarn {k} (M : 'rV[F]_(Z k)) := rsubmx (mxvar M).
Definition mxshift {k} (M : 'rV[F]_(Z k)) := rsubmx (lsubmx M).
Definition mxbdp {k} (M : 'rV[F]_(Z k)) := lsubmx (mxbd M).
Definition mxbdn {k} (M : 'rV[F]_(Z k)) := rsubmx (mxbd M).
(* -------------------------------------------------------------------- *)
Definition norm_lpeq k (e : lpeq) (i : 'I_k) : 'cV[F]_(Z k) :=
normmx
(\sum_(j < n) ( e @^ j *: lpeq_var j))
(\sum_(j < n) (- e @^ j *: lpeq_var j))
(lprel_sign e *: lpeq_shift i)
0 0.
Definition norm_lpeqs k (e : k.-tuple lpeq) : 'M[F]_(Z k, k) :=
\matrix_(i < _, j < k) norm_lpeq (tnth e j) j i 0.
Definition norm_bndp k (i : 'I_n) : 'cV[F]_(Z k) :=
normmx (lpeq_var i) 0 0 (lpeq_bd i) 0.
Definition norm_bndn k (i : 'I_n) : 'cV[F]_(Z k) :=
normmx 0 (lpeq_var i) 0 0 (lpeq_bd i).
Definition norm_bnde k (e : lpeq) (i : 'I_k) : 'cV[F]_(Z k) :=
let m := (lpeq_rel e == ==%:T%T)%:R *: lpeq_shift i in
normmx 0 0 m 0 0.
Definition norm_bnds k (e : k.-tuple lpeq) : 'M[F]_(Z k, (n + n) + k) :=
row_mx
(row_mx
(\matrix_(i < _, j < n) (norm_bndp k j) i 0)
(\matrix_(i < _, j < n) (norm_bndn k j) i 0))
(\matrix_(i < _, j < k) (norm_bnde (tnth e j) j i 0)).
Definition norm_lpeqs_bnd k (e : k.-tuple lpeq) : 'M[F]_(Z k, k + ((n + n) + k)) :=
row_mx (norm_lpeqs e) (norm_bnds e).
Definition norm_const k (e : k.-tuple lpeq) : 'rV[F]_k :=
\row_(i < k) lpeq_const (tnth e i).
Definition norm_const_bnd k M (e : k.-tuple lpeq) : 'rV[F]_(k + ((n + n) + k)) :=
row_mx
(norm_const e)
(row_mx
(const_mx M)
(\row_(i < k) (lpeq_rel (tnth e i) == ==%:T%T)%:R)).
Definition norm_cost k (f : 'rV[F]_n -> F) : 'cV[F]_(Z k) :=
let m : 'cV[F]_n := \col_(i < n) f (delta_mx 0 i) in
col_mx (col_mx (col_mx m (-m)) 0) 0.
(* -------------------------------------------------------------------- *)
Definition norm_pb k (pb : lppb k) : nmpb (Z k) (k + ((n + n) + k)) :=
{| nmpb_coeffs := norm_lpeqs_bnd pb.(lppb_eqs);
nmpb_const := norm_const_bnd pb.(lppb_bnd) pb.(lppb_eqs);
nmpb_cost := norm_cost k pb.(lppb_cost); |}.
(* -------------------------------------------------------------------- *)
Section LPPbTx.
Context {k : nat} (pb : lppb k).
Notation A := (norm_pb pb).(nmpb_coeffs).
Notation b := (norm_pb pb).(nmpb_const).
Notation c := (norm_pb pb).(nmpb_cost).
Notation E := (tnth pb.(lppb_eqs)).
Definition lp2pb (x : 'rV[F]_(Z k)) : 'rV[F]_n :=
mxvarp x - mxvarn x.
Let simpmx := (mxE, splitlr).
(* -------------------------------------------------------------------- *)
Local Lemma norm_bnd_vE i j :
A (vshift k j) (rshift k (lshift _ i)) = (j == i)%:R.
Proof.
elim/splitW: j => j; elim/splitW: i => i;
rewrite !simpmx -?val_eqE ?eqn_add2l ?andbT //=.
+ by rewrite ltn_eqF // ltn_addr.
+ by rewrite gtn_eqF // ltn_addr.
Qed.
Local Lemma norm_bnd_bE i j :
A (bshift k j) (rshift k (lshift _ i)) = (j == i)%:R.
Proof.
elim/splitW: j => j; elim/splitW: i => i;
rewrite !simpmx -?val_eqE ?eqn_add2l ?andbT //=.
+ by rewrite ltn_eqF // ltn_addr.
+ by rewrite gtn_eqF // ltn_addr.
Qed.
Local Lemma norm_bndE (x : 'rV[F]_(Z k)) (i : 'I_(n + n)) :
(x *m A) @ (rshift _ (lshift _ i)) = x @ (vshift _ i) + x @ (bshift _ i) .
Proof.
rewrite mulmx_sum_rowE 2!big_split_ord /=.
rewrite [X in _+X+_=_]big1 ?addr0 => [j _|].
+ by elim/splitW: i => i; rewrite !simpmx mulr0.
rewrite (bigD1 i) //= -!addrA; congr +%R.
+ by rewrite norm_bnd_vE eqxx mulr1.
rewrite big1 ?add0r => [j ne_ji|].
+ by rewrite norm_bnd_vE (negbTE ne_ji) mulr0.
rewrite (bigD1 i) //= big1 ?addr0 => [j ne_ji|].
+ by rewrite norm_bnd_bE (negbTE ne_ji) mulr0.
by rewrite norm_bnd_bE eqxx mulr1.
Qed.
(* -------------------------------------------------------------------- *)
Local Lemma norm_eqE (x : 'rV[F]_(Z k)) i :
(x *m A) @ (lshift _ i)
= \sum_(j < n) E i @^ j *
(x @ (vshift _ (lshift _ j)) - x @ (vshift _ (rshift _ j)))
+ x @ eshift _ i * lprel_sign (E i).
Proof.
rewrite mulmx_sum_rowE big_split_ord /= [X in _+X]big1 ?addr0.
+ by elim/splitW => j; rewrite !simpmx mulr0.
rewrite big_split_ord /=; congr +%R; last first.
+ rewrite (bigD1 i) //= big1 ?addr0; last first.
* by rewrite !simpmx !eqxx mulr1.
by move=> j ne_ji; rewrite !simpmx andbT (negbTE ne_ji) !mulr0.
rewrite big_split_ord -big_split /=; apply/eq_bigr=> j _.
rewrite !simpmx !summxE !(bigD1 (P := xpredT) j) //= !big1 ?addr0.
+ by move=> m ne_mj; rewrite !mxE [j==_]eq_sym (negbTE ne_mj) mulr0.
+ by move=> m ne_mj; rewrite !mxE [j==_]eq_sym (negbTE ne_mj) mulr0.
by rewrite !simpmx !eqxx !mulr1 mulrN -mulrBl mulrC.
Qed.
(* -------------------------------------------------------------------- *)
Local Lemma norm_vbndE (x : 'rV[F]_(Z k)) i :
(x *m A) @ (rshift _ (rshift _ i))
= x @ eshift k i * (lpeq_rel (E i) == ==%:T%T)%:R.
Proof.
rewrite mulmx_sum_rowE big_split_ord /= [X in _+X]big1 ?addr0.
+ by elim/splitW => j _; rewrite !simpmx mulr0.
rewrite big_split_ord /= [X in X+_]big1 ?add0r.
+ by elim/splitW => j _; rewrite !simpmx mulr0.
rewrite (bigD1 i) //= big1 ?addr0 => [m ne|].
+ by rewrite !simpmx (negbTE ne) !mulr0.
by rewrite !simpmx !eqxx mulr1.
Qed.
(* -------------------------------------------------------------------- *)
Lemma sol_lp2pb (x : 'rV[F]_(Z k)) :
x \in norm_pb pb -> lp2pb x \in pb.
Proof.
rewrite nmpbP => /lpsetP[ge0_x solx]; apply/lppbP; split; last first.
+ move=> i; rewrite !mxE.
move/rowP: (solx) => /(_ (rshift _ (lshift _ (lshift _ i)))).
move/rowP: (solx) => /(_ (rshift _ (lshift _ (rshift _ i)))).
rewrite !norm_bndE !(mxE,splitlr) ler_norml => h1 h2.
rewrite ler_oppl opprB -{1}h1 -{1}h2 !ler_add2l.
rewrite (le_trans _ (ge0_x _)) ?oppr_le0 //=.
by rewrite (le_trans _ (ge0_x _)) ?oppr_le0.
move=> i; rewrite mem_lpeqE /mem_lpeq.
case E: (tnth _ _) => [a r e]; move/rowP: solx.
move/(_ (lshift _ i)); rewrite norm_eqE !simpmx E /=.
set f := BIG_F; have eqf j: f j = (lp2pb @^ x) j * a @^ j.
+ by rewrite {}/f mulrC !simpmx.
rewrite {f eqf}(eq_bigr _ (fun i _ => eqf i)) => /esym/eqP.
rewrite -subr_eq => /eqP <-; case: {E} r => //=.
+ by rewrite mulr1 ler_subl_addr ler_addl ge0_x.
+ by rewrite mulrN1 opprK ler_addl ge0_x.
+ by rewrite mulr0 subr0.
Qed.
(* -------------------------------------------------------------------- *)
Lemma cost_lp2pb (x : 'rV[F]_(Z k)) :
pb.(lppb_cost) (lp2pb x) = (x *m (norm_pb pb).(nmpb_cost)) 0 0.
Proof.
rewrite !simpmx big_split_ord /= [X in _ + X]big1 ?addr0.
+ by elim/splitW=> i _; rewrite !simpmx mulr0.
rewrite big_split_ord /= [X in _ + X]big1 ?addr0.
+ by move=> i _; rewrite !simpmx mulr0.
rewrite big_split_ord -big_split /=; set f := BIG_F.
have eqf i: f i = (lp2pb x) @ i * (lppb_cost pb) (delta_mx 0 i).
+ by rewrite {}/f !simpmx mulrN -mulrBl.
rewrite {eqf f}(eq_bigr _ (fun i _ => eqf i)).
rewrite {1}[lp2pb x]row_sum_delta linear_sum.
by apply/eq_bigr=> /= i _; rewrite linearZ.
Qed.
End LPPbTx.
(* -------------------------------------------------------------------- *)
Section LpPbRevTx.
Context {k : nat} (pb : lppb k).
Notation A := (norm_pb pb).(nmpb_coeffs).
Notation b := (norm_pb pb).(nmpb_const).
Notation c := (norm_pb pb).(nmpb_cost).
Notation E := (tnth pb.(lppb_eqs)).
Let simpmx := (mxE, splitlr).
Let ε (x : 'rV[F]_n) i : F :=
lprel_sign (E i) *
(lpeq_const (E i) - (x *m (E i)) 0 0).
Definition pb2lp (x : 'rV[F]_n) :=
trmx (normmx
(\col_i Num.max (x @ i) 0)
(\col_i - Num.min (x @ i) 0)
(\col_i if lpeq_rel (tnth pb.(lppb_eqs) i) is ==%:T%T then 1 else ε x i)
(\col_i (pb.(lppb_bnd) - Num.max (x @ i) 0))
(\col_i (pb.(lppb_bnd) + Num.min (x @ i) 0))).
(* -------------------------------------------------------------------- *)
Lemma sol_pb2lp x : x \in pb -> lpset A b (pb2lp x).
Proof.
case/lppbP => solx bdx; apply/lpsetP; split.
+ elim/(@zW k) => i; rewrite !simpmx.
* by rewrite le_maxr lexx orbT.
* by rewrite oppr_ge0 le_minl lexx orbT.
* move/(_ i): solx; rewrite mem_lpeqE /mem_lpeq /ε.
case: (E i) => [a r e]; case: r => /=; rewrite ?Monoid.simpm.
+ by rewrite subr_ge0.
+ by rewrite mulN1r oppr_ge0 subr_le0.
+ by rewrite ler01.
* by rewrite subr_ge0 le_maxl !(le_trans _ (bdx i)) ?ler_norm.
* rewrite -ler_subl_addr sub0r oppr_min oppr0.
rewrite le_maxl !(le_trans _ (bdx i)) ?normr_ge0 //.
by rewrite -normrN ler_norm.
apply/rowP; elim/splitW => i.
+ rewrite norm_eqE [X in X+_](_ : _ = (x *m E i) 0 0).
* rewrite !simpmx; apply/eq_bigr=> /= j _; rewrite mulrC.
by congr *%R; rewrite !simpmx opprK addr_max_min addr0.
rewrite ![in X in _+X]simpmx ![in RHS]simpmx /ε.
case EE: (E i) => [a [] e] /=.
* by rewrite !Monoid.simpm /= addrAC subrr add0r.
* by rewrite !(mulN1r, mulrN1) opprK addrCA subrr addr0.
rewrite !Monoid.simpm /=; move/(_ i): solx.
by rewrite mem_lpeqE /mem_lpeq EE /= => /eqP.
+ elim/splitW: i; last first.
* move=> i; rewrite norm_vbndE !simpmx.
by case: (lpeq_rel _); rewrite !Monoid.simpm //=.
elim/splitW=> i; rewrite norm_bndE !simpmx.
* by rewrite addrCA subrr addr0.
* by rewrite addrCA addNr addr0.
Qed.
(* -------------------------------------------------------------------- *)
Lemma cost_pb2lp (x : 'rV[F]_n) :
pb.(lppb_cost) x = (pb2lp x *m (norm_pb pb).(nmpb_cost)) 0 0.
Proof.
rewrite !simpmx big_split_ord /= [X in _ + X]big1 ?addr0.
+ by elim/splitW=> i _; rewrite !simpmx mulr0.
rewrite big_split_ord /= [X in _ + X]big1 ?addr0.
+ by move=> i _; rewrite !simpmx mulr0.
rewrite big_split_ord -big_split /= {1}[x]row_sum_delta.
rewrite linear_sum; apply/eq_bigr=> /= i _.
rewrite !simpmx linearZ /= !(mulNr, mulrN) opprK.
by rewrite -mulrDl addr_max_min addr0.
Qed.
End LpPbRevTx.
(* ==================================================================== *)
Section LpPbTxBnd.
Context {k : nat} (pb : lppb k).
Notation A := (norm_pb pb).(nmpb_coeffs).
Notation b := (norm_pb pb).(nmpb_const).
Notation c := (norm_pb pb).(nmpb_cost).
Notation E := (tnth pb.(lppb_eqs)).
Let simpmx := (mxE, splitlr).
(* -------------------------------------------------------------------- *)
Lemma norm_pb_bnd : lpbounded A b.
Proof.
pose T i := `|lpeq_const (E i)| + \sum_(j < n) `|E i @^ j| * `|pb.(lppb_bnd)|.
pose N := \sum_(i < k) (1 + T i); have ge0_T i : 0 <= T i.
+ rewrite addr_ge0 ?normr_ge0 //; apply/sumr_ge0=> /= j _.
by rewrite mulr_ge0 ?normr_ge0.
pose M := `|pb.(lppb_bnd)| + N; have ge0_N: 0 <= N.
+ by apply/sumr_ge0=> /= i _; rewrite addr_ge0.
exists (1 + M) => x /lpsetP[ge0_x solx] => i.
rewrite (@le_lt_trans _ _ M) ?ltr_addr ?ltr01 // /M.
elim/splitW: i => i; move/rowP: solx => solx; last first.
+ move/(_ (rshift _ (lshift _ i))): solx.
rewrite norm_bndE !simpmx => <-.
rewrite ger0_norm ?addr_ge0 ?ge0_x //.
by rewrite -addrA addrCA ler_addl addr_ge0 ?ge0_x.
elim/splitW: i => i.
+ move/(_ (rshift _ (lshift _ i))): solx.
rewrite norm_bndE !simpmx=> <-.
rewrite ger0_norm ?addr_ge0 ?ge0_x //.
by rewrite -addrA ler_addl addr_ge0 ?ge0_x.
rewrite -[X in X <= _]add0r ler_add ?normr_ge0 //.
rewrite /N (bigD1 i) //= -[X in X <= _]addr0 ler_add //; last first.
+ by apply/sumr_ge0 => j _; rewrite addr_ge0.
case EE: (E i) => [a r e] /=; case: (r =P ==%:T%T) => /eqP eqr.
+ move/(_ (rshift _ (rshift _ i))): solx; rewrite norm_vbndE.
by rewrite !simpmx EE eqr /= mulr1 => ->; rewrite ler_addl.
rewrite ler_paddl // /T; move/(_ (lshift _ i)): (solx).
rewrite norm_eqE !simpmx EE /=; set s := lprel_sign _.
rewrite (rwP eqP) addrC eq_sym -subr_eq => /eqP.
move/(congr1 Num.norm); rewrite normrM (_ : `|s| = 1) /s.
+ by case: {+}r eqr => //=; rewrite (normr1, normrN1).
rewrite mulr1 => eq; apply/(le_trans (ler_norm _)).
rewrite -{}eq (le_trans (ler_norm_sub _ _)) //.
rewrite ler_add2l (le_trans (ler_norm_sum _ _ _)) //.
apply/ler_sum=> j _; rewrite normrM ler_wpmul2l //.
rewrite ler_normr; apply/orP; left.
move/(_ (rshift _ (lshift _ (lshift _ j)))): (solx).
move/(_ (rshift _ (lshift _ (rshift _ j)))): (solx).
rewrite !norm_bndE !(mxE,splitlr) ler_norml => h1 h2.
rewrite ler_oppl opprB -{1}h1 -{1}h2 !ler_add2l.
rewrite (le_trans _ (ge0_x _)) ?oppr_le0 //=.
by rewrite (le_trans _ (ge0_x _)) ?oppr_le0.
Qed.
End LpPbTxBnd.
(* ==================================================================== *)
Section LPPbSol.
Context {k : nat} (pb : lppb k).
Notation A := (norm_pb pb).(nmpb_coeffs).
Notation b := (norm_pb pb).(nmpb_const).
Notation c := (norm_pb pb).(nmpb_cost).
Notation E := (tnth pb.(lppb_eqs)).
Lemma lppbsolve :
{x | x \in pb} -> {x | x \in pb /\
forall y, y \in pb -> pb.(lppb_cost) y <= pb.(lppb_cost) x}.
Proof.
move=> solx; case: (@lpsolvebd _ _ _ A b c).
+ by apply/norm_pb_bnd.
+ by case: solx => x solx; exists (pb2lp pb x); apply/sol_pb2lp.
move=> {solx} x [solx maxx]; exists (lp2pb x); split.
+ by apply/sol_lp2pb.
+ move=> y /sol_pb2lp soly; rewrite cost_lp2pb.
by apply/(le_trans _ (maxx _ soly)); rewrite cost_pb2lp.
Qed.
End LPPbSol.
End LPPb.
(* ==================================================================== *)
Bind Scope syntax_scope with lprel.
Notation "<=%:T" := LPRLe : syntax_scope.
Notation ">=%:T" := LPRGe : syntax_scope.
Notation "==%:T" := LPREq : syntax_scope.
Notation "a <= b" := (LPEq a <=%:T b) : syntax_scope.
Notation "a >= b" := (LPEq a >=%:T b) : syntax_scope.
Notation "a == b" := (LPEq a ==%:T b) : syntax_scope.
|
Family relationships are a common type of connection between gods . Deities often form male and female pairs , reflecting the importance of procreation in Egyptian religious thought . Families of three deities , with a father , mother , and child , represent the creation of new life and the succession of the father by the child , a pattern that connects divine families with royal succession . Osiris , Isis , and Horus formed the quintessential family of this type . The pattern they set grew more widespread over time , so that many deities in local cult centers , like Ptah , Sekhmet , and their child <unk> at Memphis and Amun , Mut , and Khonsu at Thebes , were assembled into family triads . Genealogical connections like these are changeable , in keeping with the multiple perspectives in Egyptian belief . Hathor , as a fertility goddess , could act as mother to any child god , including the child form of the sun god , although in other circumstances she was the sun god 's daughter .
|
A sequence $X$ is Cauchy if and only if for every $j \in \mathbb{N}$, there exists $M \in \mathbb{N}$ such that for all $m, n \geq M$, we have $|X_m - X_n| < \frac{1}{j+1}$. |
State Before: A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
⊢ a ≤ b ∨ b ≤ a State After: case mk
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a✝ b : ValueGroup A K
a : K
⊢ Quot.mk Setoid.r a ≤ b ∨ b ≤ Quot.mk Setoid.r a Tactic: rcases a with ⟨a⟩ State Before: case mk
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a✝ b : ValueGroup A K
a : K
⊢ Quot.mk Setoid.r a ≤ b ∨ b ≤ Quot.mk Setoid.r a State After: case mk.mk
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a✝ b✝ : ValueGroup A K
a b : K
⊢ Quot.mk Setoid.r a ≤ Quot.mk Setoid.r b ∨ Quot.mk Setoid.r b ≤ Quot.mk Setoid.r a Tactic: rcases b with ⟨b⟩ State Before: case mk.mk
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a✝ b✝ : ValueGroup A K
a b : K
⊢ Quot.mk Setoid.r a ≤ Quot.mk Setoid.r b ∨ Quot.mk Setoid.r b ≤ Quot.mk Setoid.r a State After: case mk.mk.intro.intro.intro
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b✝ : ValueGroup A K
b : K
xa ya : A
hya : ya ∈ nonZeroDivisors A
⊢ Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) ≤ Quot.mk Setoid.r b ∨
Quot.mk Setoid.r b ≤ Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) Tactic: obtain ⟨xa, ya, hya, rfl⟩ : ∃ a b : A, _ := IsFractionRing.div_surjective a State Before: case mk.mk.intro.intro.intro
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b✝ : ValueGroup A K
b : K
xa ya : A
hya : ya ∈ nonZeroDivisors A
⊢ Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) ≤ Quot.mk Setoid.r b ∨
Quot.mk Setoid.r b ≤ Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) State After: case mk.mk.intro.intro.intro.intro.intro.intro
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
⊢ Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ∨
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) Tactic: obtain ⟨xb, yb, hyb, rfl⟩ : ∃ a b : A, _ := IsFractionRing.div_surjective b State Before: case mk.mk.intro.intro.intro.intro.intro.intro
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
⊢ Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ∨
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) State After: case mk.mk.intro.intro.intro.intro.intro.intro
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this : ↑(algebraMap A K) ya ≠ 0
⊢ Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ∨
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) Tactic: have : (algebraMap A K) ya ≠ 0 := IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors hya State Before: case mk.mk.intro.intro.intro.intro.intro.intro
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this : ↑(algebraMap A K) ya ≠ 0
⊢ Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ∨
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) State After: case mk.mk.intro.intro.intro.intro.intro.intro
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
⊢ Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ∨
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) Tactic: have : (algebraMap A K) yb ≠ 0 := IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors hyb State Before: case mk.mk.intro.intro.intro.intro.intro.intro
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
⊢ Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ∨
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) State After: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inl
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xa * yb * c = xb * ya
⊢ Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ∨
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya)
case mk.mk.intro.intro.intro.intro.intro.intro.intro.inr
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xb * ya * c = xa * yb
⊢ Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ∨
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) Tactic: obtain ⟨c, h | h⟩ := ValuationRing.cond (xa * yb) (xb * ya) State Before: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inl
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xa * yb * c = xb * ya
⊢ Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ∨
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) State After: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inl.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xa * yb * c = xb * ya
⊢ Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) Tactic: right State Before: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inl.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xa * yb * c = xb * ya
⊢ Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) State After: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inl.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xa * yb * c = xb * ya
⊢ c • (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) = ↑(algebraMap A K) xb / ↑(algebraMap A K) yb Tactic: use c State Before: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inl.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xa * yb * c = xb * ya
⊢ c • (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) = ↑(algebraMap A K) xb / ↑(algebraMap A K) yb State After: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inl.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xa * yb * c = xb * ya
⊢ ↑(algebraMap A K) c * (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) = ↑(algebraMap A K) xb / ↑(algebraMap A K) yb Tactic: rw [Algebra.smul_def] State Before: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inl.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xa * yb * c = xb * ya
⊢ ↑(algebraMap A K) c * (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) = ↑(algebraMap A K) xb / ↑(algebraMap A K) yb State After: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inl.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xa * yb * c = xb * ya
⊢ ↑(algebraMap A K) c * ↑(algebraMap A K) xa * ↑(algebraMap A K) yb = ↑(algebraMap A K) xb * ↑(algebraMap A K) ya Tactic: field_simp State Before: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inl.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xa * yb * c = xb * ya
⊢ ↑(algebraMap A K) c * ↑(algebraMap A K) xa * ↑(algebraMap A K) yb = ↑(algebraMap A K) xb * ↑(algebraMap A K) ya State After: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inl.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xa * yb * c = xb * ya
⊢ ↑(algebraMap A K) (c * xa * yb) = ↑(algebraMap A K) (xa * yb * c) Tactic: simp only [← RingHom.map_mul, ← h] State Before: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inl.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xa * yb * c = xb * ya
⊢ ↑(algebraMap A K) (c * xa * yb) = ↑(algebraMap A K) (xa * yb * c) State After: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inl.h.h.e_6.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xa * yb * c = xb * ya
⊢ c * xa * yb = xa * yb * c Tactic: congr 1 State Before: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inl.h.h.e_6.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xa * yb * c = xb * ya
⊢ c * xa * yb = xa * yb * c State After: no goals Tactic: ring State Before: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inr
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xb * ya * c = xa * yb
⊢ Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ∨
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) State After: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inr.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xb * ya * c = xa * yb
⊢ Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) Tactic: left State Before: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inr.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xb * ya * c = xa * yb
⊢ Quot.mk Setoid.r (↑(algebraMap A K) xa / ↑(algebraMap A K) ya) ≤
Quot.mk Setoid.r (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) State After: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inr.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xb * ya * c = xa * yb
⊢ c • (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) = ↑(algebraMap A K) xa / ↑(algebraMap A K) ya Tactic: use c State Before: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inr.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xb * ya * c = xa * yb
⊢ c • (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) = ↑(algebraMap A K) xa / ↑(algebraMap A K) ya State After: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inr.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xb * ya * c = xa * yb
⊢ ↑(algebraMap A K) c * (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) = ↑(algebraMap A K) xa / ↑(algebraMap A K) ya Tactic: rw [Algebra.smul_def] State Before: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inr.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xb * ya * c = xa * yb
⊢ ↑(algebraMap A K) c * (↑(algebraMap A K) xb / ↑(algebraMap A K) yb) = ↑(algebraMap A K) xa / ↑(algebraMap A K) ya State After: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inr.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xb * ya * c = xa * yb
⊢ ↑(algebraMap A K) c * ↑(algebraMap A K) xb * ↑(algebraMap A K) ya = ↑(algebraMap A K) xa * ↑(algebraMap A K) yb Tactic: field_simp State Before: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inr.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xb * ya * c = xa * yb
⊢ ↑(algebraMap A K) c * ↑(algebraMap A K) xb * ↑(algebraMap A K) ya = ↑(algebraMap A K) xa * ↑(algebraMap A K) yb State After: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inr.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xb * ya * c = xa * yb
⊢ ↑(algebraMap A K) (c * xb * ya) = ↑(algebraMap A K) (xb * ya * c) Tactic: simp only [← RingHom.map_mul, ← h] State Before: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inr.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xb * ya * c = xa * yb
⊢ ↑(algebraMap A K) (c * xb * ya) = ↑(algebraMap A K) (xb * ya * c) State After: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inr.h.h.e_6.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xb * ya * c = xa * yb
⊢ c * xb * ya = xb * ya * c Tactic: congr 1 State Before: case mk.mk.intro.intro.intro.intro.intro.intro.intro.inr.h.h.e_6.h
A : Type u
inst✝⁵ : CommRing A
K : Type v
inst✝⁴ : Field K
inst✝³ : Algebra A K
inst✝² : IsDomain A
inst✝¹ : ValuationRing A
inst✝ : IsFractionRing A K
a b : ValueGroup A K
xa ya : A
hya : ya ∈ nonZeroDivisors A
xb yb : A
hyb : yb ∈ nonZeroDivisors A
this✝ : ↑(algebraMap A K) ya ≠ 0
this : ↑(algebraMap A K) yb ≠ 0
c : A
h : xb * ya * c = xa * yb
⊢ c * xb * ya = xb * ya * c State After: no goals Tactic: ring |
Require Import Arith.
Require Import List.
Import ListNotations.
Set Implicit Arguments.
Lemma leb_false_lt : forall m n, leb m n = false -> n < m.
Proof.
induction m; intros.
- discriminate.
- simpl in *.
destruct n; subst; auto with arith.
Qed.
|
\section{Orc Warrior}
asdf |
module assert
use, intrinsic:: iso_fortran_env, stderr=>error_unit, sp=>real32, dp=>real64
use, intrinsic:: ieee_arithmetic
implicit none (type, external)
private
public :: isclose, assert_isclose
interface isclose
module procedure isclose_32, isclose_64
end interface isclose
interface assert_isclose
module procedure assert_isclose_32, assert_isclose_64
end interface assert_isclose
contains
elemental logical function isclose_32(actual, desired, rtol, atol, equal_nan) result (isclose)
! inputs
! ------
! actual: value "measured"
! desired: value "wanted"
! rtol: relative tolerance
! atol: absolute tolerance
! equal_nan: consider NaN to be equal?
!
! rtol overrides atol when both are specified
!
! https://www.python.org/dev/peps/pep-0485/#proposed-implementation
! https://github.com/PythonCHB/close_pep/blob/master/is_close.py
real(sp), intent(in) :: actual, desired
real(sp), intent(in), optional :: rtol, atol
logical, intent(in), optional :: equal_nan
real(sp) :: r,a
logical :: n
! this is appropriate INSTEAD OF merge(), since non present values aren't defined.
r = 1e-5_sp
a = 0
n = .false.
if (present(rtol)) r = rtol
if (present(atol)) a = atol
if (present(equal_nan)) n = equal_nan
!print*,r,a,n,actual,desired
!--- sanity check
if ((r < 0).or.(a < 0)) error stop 'invalid tolerance parameter(s)'
!--- equal nan
isclose = n.and.(ieee_is_nan(actual).and.ieee_is_nan(desired))
if (isclose) return
!--- Inf /= Inf, unequal NaN
if (.not.ieee_is_finite(actual) .or. .not.ieee_is_finite(desired)) return
!--- floating point closeness check
isclose = abs(actual-desired) <= max(r * max(abs(actual), abs(desired)), a)
end function isclose_32
elemental logical function isclose_64(actual, desired, rtol, atol, equal_nan) result (isclose)
! inputs
! ------
! actual: value "measured"
! desired: value "wanted"
! rtol: relative tolerance
! atol: absolute tolerance
! equal_nan: consider NaN to be equal?
!
! rtol overrides atol when both are specified
!
! https://www.python.org/dev/peps/pep-0485/#proposed-implementation
! https://github.com/PythonCHB/close_pep/blob/master/is_close.py
real(dp), intent(in) :: actual, desired
real(dp), intent(in), optional :: rtol, atol
logical, intent(in), optional :: equal_nan
real(dp) :: r,a
logical :: n
! this is appropriate INSTEAD OF merge(), since non present values aren't defined.
r = 1e-5_dp
a = 0
n = .false.
if (present(rtol)) r = rtol
if (present(atol)) a = atol
if (present(equal_nan)) n = equal_nan
!print*,r,a,n,actual,desired
!--- sanity check
if ((r < 0).or.(a < 0)) error stop 'invalid tolerance parameter(s)'
!--- equal nan
isclose = n.and.(ieee_is_nan(actual).and.ieee_is_nan(desired))
if (isclose) return
!--- Inf /= Inf, unequal NaN
if (.not.ieee_is_finite(actual) .or. .not.ieee_is_finite(desired)) return
!--- floating point closeness check
isclose = abs(actual-desired) <= max(r * max(abs(actual), abs(desired)), a)
end function isclose_64
impure elemental subroutine assert_isclose_64(actual, desired, rtol, atol, equal_nan, err_msg)
! inputs
! ------
! actual: value "measured"
! desired: value "wanted"
! rtol: relative tolerance
! atol: absolute tolerance
! equal_nan: consider NaN to be equal?
! err_msg: message to print on mismatch
!
! rtol overrides atol when both are specified
real(dp), intent(in) :: actual, desired
real(dp), intent(in), optional :: rtol, atol
logical, intent(in), optional :: equal_nan
character(*), intent(in), optional :: err_msg
if (.not.isclose(actual,desired,rtol,atol,equal_nan)) then
write(stderr,*) merge(err_msg,'',present(err_msg)),': actual',actual,'desired',desired
error stop
endif
end subroutine assert_isclose_64
impure elemental subroutine assert_isclose_32(actual, desired, rtol, atol, equal_nan, err_msg)
! inputs
! ------
! actual: value "measured"
! desired: value "wanted"
! rtol: relative tolerance
! atol: absolute tolerance
! equal_nan: consider NaN to be equal?
! err_msg: message to print on mismatch
!
! rtol overrides atol when both are specified
real(sp), intent(in) :: actual, desired
real(sp), intent(in), optional :: rtol, atol
logical, intent(in), optional :: equal_nan
character(*), intent(in), optional :: err_msg
if (.not.isclose(actual,desired,rtol,atol,equal_nan)) then
write(stderr,*) merge(err_msg,'',present(err_msg)),': actual',actual,'desired',desired
error stop
endif
end subroutine assert_isclose_32
end module assert
|
If $S$ is a compact set such that for all $c \geq 0$ and $x \in S$, if $cx \in S$, then $c = 1$, then $S$ is a null set. |
Require Import FP.Data.Ascii.
Require Import FP.Data.String.
Require Import FP.Structures.Injection.
Require Import FP.Structures.Monoid.
Import MonoidNotation.
Class ShowResult r :=
{ show_result_Monoid : Monoid r
; show_result_Injection_ascii : HasInjection ascii r
}.
Hint Resolve Build_ShowResult : typeclass_instances.
Hint Immediate show_result_Monoid : typeclass_instances.
Hint Immediate show_result_Injection_ascii : typeclass_instances.
Class Show t := { show : forall {r} {SR:ShowResult r}, t -> r }.
Section raw.
Context {r} {SR:ShowResult r}.
Definition raw_char : ascii -> r := inject.
Fixpoint raw_string s :=
match s with
| EmptyString => gunit
| String c s' => raw_char c ** raw_string s'
end.
End raw.
|
Extraction Language Haskell.
Require Import NArith.
Require Import Arith.
Require Import Bool.
Require Import List.
Require Import Bag.
Require Import Dict.
Require Import Misc.
Require Import SpaceSearch.CpdtTactics.
Require Import JamesTactics.
Require Import KonneTactics.
Require Import Coq.Program.Basics.
Require Import SpaceSearch.EqDec.
Require Import Enumerable.
Require Import BGPSpec.
Require Import Equality.
Require Import SymbolicExecution.
Require Import Graph.
Import ListNotations.
Import EqNotations.
Section Simulation.
Definition decide P := {P} + {~P}.
Parameter CIDR : Type.
Parameter eqDecideCIDR : forall (c c':CIDR), decide (c = c').
Parameter IP : Type.
Parameter eqDecideIP : forall (i i':IP), decide (i = i').
Parameter ASN : Type.
Parameter eqDecideASN : forall (a a':ASN), decide (a = a').
Instance eqDecCIDR : eqDec CIDR.
constructor.
exact eqDecideCIDR.
Defined.
Instance eqDecIP : eqDec IP.
constructor.
exact eqDecideIP.
Defined.
Instance eqDecASN : eqDec ASN.
constructor.
exact eqDecideASN.
Defined.
Existing Instance eqDecProd.
Existing Instance eqDecMode.
Existing Instance eqDecUpdateMessage.
Instance natPrefix : PrefixClass := {| Prefix := CIDR |}.
(* see main bgp spec and https://tools.ietf.org/html/rfc1997 *)
Inductive BGPPathAttributes := {
LOCAL_PREF : nat;
COMMUNITIES : list nat;
AS_PATH : list ASN
}.
Inductive Match :=
| RAny : Match
| RCommunityIs : nat -> Match
| RNot : Match -> Match
| RAnd : Match -> Match -> Match
| ROr : Match -> Match -> Match.
Inductive Modify :=
| MAddCommunity : nat -> Modify
| MStripCommunities : Modify.
Inductive Action :=
| AModify : Modify -> Action
| AAccept : Action
| AReject : Action.
Definition Rule := (Match * Action)%type.
Instance eqDecBGPPathAttributes : eqDec BGPPathAttributes.
constructor.
decide equality; apply eqDecide.
Defined.
Instance bgpPathAttributes : PathAttributesClass := {|
PathAttributes := BGPPathAttributes;
leDecPathAttributes a a' := Nat.leb (LOCAL_PREF a) (LOCAL_PREF a')
|}.
Proof.
intros.
apply leb_correct.
Require Import Omega.
omega.
Defined.
Record Setup := {
ases : list (ASN * list IP);
links : list ((ASN * IP * list Rule * list Rule) * (ASN * IP * list Rule * list Rule));
injections : list ((ASN * IP) * CIDR)
}.
Inductive PolicyResult := replaced | filtered.
Fixpoint zipIn {A} `{eqDec A} l : list {a:A | In a l}.
refine (match l with
| [] => []
| a::l' => exist _ a _ :: (fun s => exist _ (proj1_sig s) _) <$> (zipIn _ _ l')
end).
- cbn.
left.
reflexivity.
- destruct s as [a'].
cbn.
destruct (a =? a'); intuition.
Defined.
Lemma zipInOk {A} `{eqDec A} {l} : forall a : {a : A | In a l}, In a (zipIn l).
intros.
revert a.
induction l.
- cbn.
intros [].
trivial.
- intros [a' ?].
cbn.
destruct (a =? a').
+ left.
subst_max.
generalize_proofs.
reflexivity.
+ right.
destruct i; [congruence|].
specialize (IHl (exist _ a' i)).
Arguments exist [_ _] _ _.
idtac.
Arguments exist [_] _ _ _.
admit.
Admitted.
Instance enumerableSigIn {A} `{eqDec A} {l} : enumerable {a:A | In a l}.
refine {| enumerate := zipIn l |}.
Proof.
apply zipInOk.
Defined.
Typeclasses Transparent const.
Instance eqDecProp {P:Prop} : eqDec P.
constructor.
intros.
proof_irrelevance.
left.
reflexivity.
Defined.
Instance eqDecEmptySet : eqDec Empty_set.
constructor.
intros [].
Defined.
Definition routers (setup:Setup) : list (ASN * IP) :=
bindList (ases setup) (fun asips => map (fun ip => (fst asips, ip)) (snd asips)).
Definition linkWithoutRules (l : ((ASN * IP * list Rule * list Rule) * (ASN * IP * list Rule * list Rule))) : ((ASN * IP) * (ASN * IP)) :=
((fst (fst (fst (fst l)))), (snd (fst (fst (fst l)))), (fst (fst (snd l)))).
Definition linksWithoutRules (s : Setup) : list ((ASN * IP) * (ASN * IP)).
destruct s.
exact (map linkWithoutRules links0).
Defined.
Variable setup:Setup.
Definition inDec {A} `{eqDec A} (a:A) l : decide (In a l).
refine (in_dec _ a l).
Proof.
intros a' a''.
destruct (a' =? a'').
- left. trivial.
- right. trivial.
Defined.
Definition hasConnection (r r':ASN*IP) : bool :=
(((fst r) =? (fst r')) && negb ((snd r) =? (snd r'))) ||
inDec (r , r') (linksWithoutRules setup) ||
inDec (r', r ) (linksWithoutRules setup).
Instance bgpTopology : TopologyClass. refine {|
Router := {r:ASN * IP | In r (routers setup)};
connections := fun r r' => if hasConnection (proj1_sig r) (proj1_sig r') then unit else Empty_set;
mode := fun r r' _ => if (fst (proj1_sig r)) =? (fst (proj1_sig r'))
then ibgp else ebgp
|}.
Proof.
- intros.
unfold edge.
break_match.
+ exact eqDecUnit.
+ exact eqDecEmptySet.
- intros.
unfold edge.
break_match.
+ exact enumerableUnit.
+ exact enumerableEmptySet.
Defined.
Definition extendPath (asn:ASN) (a:PathAttributes) : PathAttributes :=
{| LOCAL_PREF := LOCAL_PREF a; COMMUNITIES := COMMUNITIES a; AS_PATH := asn :: AS_PATH a |}.
Definition setPref (pref : nat) (a : PathAttributes) : PathAttributes :=
{| LOCAL_PREF := pref; COMMUNITIES := COMMUNITIES a; AS_PATH := AS_PATH a |}.
Fixpoint indexOf' {A} `{eqDec A} (l : list A) a (n : nat) : option nat :=
match l with
| a' :: l' =>
if eqDecide a a' then
Some n
else
indexOf' l' a (S n)
| [] => None
end.
Definition indexOf {A} `{eqDec A} (l : list A) a := indexOf' l a 0.
Definition pref {r} (i : incoming r) : option nat.
refine (match i with
| injected => None
| received r' => _
end).
destruct r'. destruct x. destruct r.
destruct (indexOf (linksWithoutRules setup) ( x0, x )).
- exact (Some (100 + (2 * n))).
- destruct (indexOf (linksWithoutRules setup) ( x, x0 )).
+ exact (Some (S (100 + (2 * n)))).
+ exact None.
Defined.
Definition adjustPref {r} (i : incoming r) a :=
match pref i with
| Some n => setPref n a
| _ => a
end.
Definition sameRouter {r} (i : incoming r) (o : outgoing r) : bool.
destruct i.
- exact false.
- destruct s, o.
destruct (eqDecide x x0).
+ exact true.
+ exact false.
Defined.
Definition inASPath {r} (o : outgoing r) (a : PathAttributes) : bool.
destruct a. destruct o. destruct x.
destruct (inDec (fst x) AS_PATH0).
- exact true.
- exact false.
Defined.
Fixpoint lookupRules (r r' : (ASN * IP)) (l : list ((ASN * IP * list Rule * list Rule) *
(ASN * IP * list Rule * list Rule))) :
option ( list Rule * list Rule ).
refine (match l with
| [] => None
| c :: l' => _
end).
destruct (eqDecide (r, r') (linkWithoutRules c)).
- exact (Some (snd (fst (fst c)), (snd (fst c)))).
- destruct (eqDecide (r', r) (linkWithoutRules c)).
+ exact (Some (snd (fst (snd c)), (snd (snd c)))).
+ exact (lookupRules r r' l').
Defined.
Definition importRules {r} (i : incoming r) : list Rule.
destruct r. destruct i.
- exact [].
- destruct s. destruct x0.
exact (match (lookupRules x x0 (links setup)) with
| None => []
| Some (i, e) => i
end).
Defined.
Definition exportRules {r} (o : outgoing r) : list Rule.
destruct r. destruct o. destruct x0.
exact (match (lookupRules x x0 (links setup)) with
| None => []
| Some (i, e) => e
end).
Defined.
Fixpoint matches (m : Match) (a : PathAttributes) :=
match m with
| RAny => true
| RCommunityIs c => if inDec c (COMMUNITIES a) then true else false
| RNot m' => negb (matches m' a)
| RAnd m1 m2 => andb (matches m1 a) (matches m2 a)
| ROr m1 m2 => orb (matches m1 a) (matches m2 a)
end.
Definition modify (m : Modify) (a : PathAttributes) :=
match m with
| MAddCommunity c =>
{| LOCAL_PREF := LOCAL_PREF a; COMMUNITIES := c :: COMMUNITIES a; AS_PATH := AS_PATH a |}
| MStripCommunities =>
{| LOCAL_PREF := LOCAL_PREF a; COMMUNITIES := []; AS_PATH := AS_PATH a |}
end.
Fixpoint executeRules (rules : list Rule) (a : PathAttributes) : RoutingInformation :=
match rules with
| [] => available a
| (m, ac) :: rules' =>
if (matches m a) then
match ac with
| AAccept => available a
| AReject => notAvailable
| AModify mo => executeRules rules' (modify mo a)
end
else
executeRules rules' a
end.
Existing Instance enumerableIncoming.
Lemma cbgb_best_best:
forall (r : Router) (f : incoming r -> RoutingInformation) (i : incoming r),
leDecRoutingInformation (f i)
(f
(argMax'
(compose
(fun a : RoutingInformation =>
match a with
| available a0 => S (LOCAL_PREF a0)
| notAvailable => 0
end) f) injected)) = true.
Proof.
intros.
unfold leDecRoutingInformation.
branch; [|congruence].
branch.
- cbn.
apply leb_correct.
unfold compose in *.
Admitted.
Instance cbgpConfiguration r : ConfigurationClass r.
refine {|
import i p a := executeRules (importRules i) (adjustPref i a);
export i o p a := if ((sameRouter i o) : bool) then notAvailable else
if (inASPath o a) then notAvailable else _;
originate p a := true;
bestIncoming f := argMax' (compose (fun a => match a with
| notAvailable => 0
| available a => S (LOCAL_PREF a)
end) f) injected
|}. {
destruct (executeRules (exportRules o) a) as [a'|].
+ destruct o as [d c].
exact (available (if mode c =? ebgp then extendPath (fst (proj1_sig r)) a' else a')).
+ exact notAvailable.
}
Proof.
apply cbgb_best_best.
Defined.
Definition TraceExists := NetworkState.
Definition BGPRouter : Type := ASN * IP.
Definition BGPAttributes : Type := option BGPPathAttributes.
Definition BGPMessage : Type := CIDR * BGPAttributes.
Typeclasses Transparent BGPRouter.
Typeclasses Transparent BGPAttributes.
Typeclasses Transparent BGPMessage.
Definition bgpAttributes (a:RoutingInformation) : BGPAttributes :=
match a with available a => Some a | notAvailable => None end.
Definition bgpMessage (m:UpdateMessage) : BGPMessage :=
(nlri m, bgpAttributes (attributes m)).
Record Event := {
number : nat;
srcRouter : BGPRouter;
handlingRouter : BGPRouter;
incomingNlri : option CIDR;
incomingAnnouncement : BGPAttributes
(*
eligibleAnnouncements : list BGPAttributes;
oldBestAnnouncement : BGPAttributes;
newBestAnnouncement : BGPAttributes;
disseminates : list (BGPRouter * PolicyResult) *)
}.
Inductive TraceError :=
handlerNotARouter (r:BGPRouter)
| sourceNotARouter (r:BGPRouter)
| sourceAndHandlerNotConnected (s d:BGPRouter)
| originationNotAllowed (a:BGPMessage)
| messageNotOnLink (sender : IP) (receiver : IP) (e_num : nat) (m m':BGPMessage) (ms:list BGPMessage)
| linkEmpty (m : option BGPMessage) (e_num : nat)
| incorrectWithdraw
.
Fixpoint applyInjection (i : BGPRouter * CIDR) (ns:TraceExists) : TraceError + TraceExists.
destruct i as [r p].
refine (if inDec r (routers setup) then _ else inl (handlerNotARouter r)).
refine (let a := available {| LOCAL_PREF := 0; COMMUNITIES := []; AS_PATH := [] |} in _).
refine (let m := {| nlri := p; attributes := a |} in _).
refine (if originate' (exist _ r _) p a then _ else inl (originationNotAllowed (bgpMessage m))); [trivial|].
refine (let ls := linkState ns in _).
refine (let rs := routerState ns in _).
simple refine (let Ers' := generateHandler (exist _ r _) m rs in _); [trivial|].
refine (let E := fst Ers' in _).
refine (let rs' := snd Ers' in _).
refine (inr {| routerState := rs'; linkState := build (fun c => lookup ls c ++ lookup E c) |}).
Defined.
Instance eqDecOption {A} `{eqDec A} : eqDec (option A).
constructor.
decide equality.
apply eqDecide.
Defined.
Definition messageWithoutCommunities (m : UpdateMessage) : UpdateMessage.
destruct m. destruct attributes.
- exact (updateMessage nlri (available (modify MStripCommunities p))).
- exact (updateMessage nlri notAvailable).
Defined.
Definition applyEvent (e:Event) (ns:TraceExists) : TraceError + TraceExists.
refine (let s := srcRouter e in _).
refine (let r := handlingRouter e in _).
refine (if inDec s (routers setup) then _ else inl (sourceNotARouter s)).
refine (if inDec r (routers setup) then _ else inl (handlerNotARouter r)).
destruct (hasConnection s r) eqn:?; [|exact (inl (sourceAndHandlerNotConnected s r))].
refine (let ls0 := linkState ns in _).
refine (let rs := routerState ns in _).
refine (let ai := match incomingAnnouncement e with None => notAvailable | Some a => available a end in _).
simple refine (let c : Connection := _ in _). {
simple refine [ (exist _ s _, exist _ r _) & _].
- trivial.
- trivial.
- cbn.
break_match; [|congruence].
exact tt.
}
destruct (incomingNlri e).
- refine (let m := {| nlri := c0; attributes := ai |} in _).
refine (match ls0 c with
| [] => inl (linkEmpty (Some (bgpMessage m)) (number e))
| m'::ms => if m =? (messageWithoutCommunities m') then _
else inl (messageNotOnLink (snd s) (snd r) (number e) (bgpMessage m) (bgpMessage m') (bgpMessage <$> ms))
end).
refine (let ls := overwrite ls0 c ms in _).
refine (let Ers' := forwardHandler c m' rs in _).
refine (let E := fst Ers' in _).
refine (let rs' := snd Ers' in _).
refine (inr {| routerState := rs'; linkState := build (fun c => lookup ls c ++ lookup E c) |}).
- refine (match ls0 c with
| [] => inl (linkEmpty None (number e))
| m' :: ms => _
end).
destruct m'. destruct attributes.
+ exact (inl incorrectWithdraw).
+ remember ({| nlri := nlri; attributes := notAvailable |}) as m'.
refine (let ls := overwrite ls0 c ms in _).
refine (let Ers' := forwardHandler c m' rs in _).
refine (let E := fst Ers' in _).
refine (let rs' := snd Ers' in _).
refine (inr {| routerState := rs'; linkState := build (fun c => lookup ls c ++ lookup E c) |}).
Defined.
(*
TODO: Check that the following matc
Record Event := {
eligibleAnnouncements : list (option BGPPathAttributes);
oldBestAnnouncement : option BGPPathAttributes;
newBestAnnouncement : option BGPPathAttributes;
disseminates : list ((ASN * IP) * PolicyResult)
}.
*)
Definition emptyNetwork : TraceExists := emptyNetworkState.
Definition debugTraceExists (ns:TraceExists) :
list (BGPRouter * BGPRouter * list (BGPMessage)).
refine (bindList (routers setup) (fun s => _)).
refine (bindList (routers setup) (fun r => _)).
refine (if inDec s (routers setup) then _ else []).
refine (if inDec r (routers setup) then _ else []).
destruct (hasConnection s r) eqn:?; [|exact []].
simple refine (let c : Connection := _ in _). {
simple refine [ (exist _ s _, exist _ r _) & _].
- trivial.
- trivial.
- cbn.
break_match; [|congruence].
exact tt.
}
refine (let ms := bgpMessage <$> linkState ns c in _).
refine [(s, r, ms)].
Defined.
End Simulation.
(* TODO move connection into Prop *)
Require Import ExtractPrelude.
Extract Inlined Constant map => "Prelude.map".
Extract Inlined Constant concat => "List.concat".
Extract Inlined Constant bindList => "(Prelude.>>=)".
Extract Inductive nat => "Prelude.Int" [ "0" "Prelude.succ" ]
"(\fO fS n -> if n==0 then fO () else fS (n-1))".
Extract Inlined Constant plus => "(Prelude.+)".
Extract Inlined Constant mult => "(Prelude.*)".
Extract Inlined Constant Nat.leb => "(Prelude.<=)".
Extract Inlined Constant False_rect => "Prelude.undefined".
Extract Inlined Constant sumBoolAnd => "(Prelude.&&)".
Extract Inductive sigT => "(,)" [ "(,)" ].
Extract Inlined Constant projT1 => "Prelude.fst".
Extract Inlined Constant projT2 => "Prelude.snd".
Extraction Inline sumbool_rec.
Extraction Inline sumbool_rect.
Extraction Inline eq_rect.
Extraction Inline eq_rect_r.
Extraction Inline eq_rec_r.
Extraction Inline eq_rec.
Extraction Inline unit_rec.
Extraction Inline unit_rect.
Extraction Inline nat_rec.
Extraction Inline nat_rect.
Extraction Inline list_rec.
Extraction Inline list_rect.
Extract Inlined Constant eqDecNat => "(Prelude.==)".
Extraction Inline Mode_rect.
Extraction Inline Mode_rec.
Extraction Inline incoming_rect.
Extraction Inline incoming_rec.
Extraction Inline RoutingInformation_rect.
Extraction Inline RoutingInformation_rec.
Extraction Inline BGPPathAttributes_rect.
Extraction Inline BGPPathAttributes_rec.
Extract Inlined Constant CIDR => "Prelude.String".
Extract Inlined Constant eqDecideCIDR => "(Prelude.==)".
Extract Inlined Constant IP => "Prelude.String".
Extract Inlined Constant eqDecideIP => "(Prelude.==)".
Extract Inlined Constant ASN => "Prelude.Int".
Extract Inlined Constant eqDecideASN => "(Prelude.==)".
Extraction "MessageHandling.hs" Setup links emptyNetwork applyEvent applyInjection injections emptyNetwork debugTraceExists PolicyResult.
|
Copyrighted works of writing, art, or music.
Trademarked brand names and logos.
The trade dress of your business, which includes unique visual aspects of your website as well as products, packaging, and even building architecture.
Trade secrets, including proprietary processes and methods, algorithms, patterns, client lists … any information you would closely guard to keep it out of the hands of competitors.
Do you know the value of your intellectual property? If you really think about the scope of your business, you probably have more intellectual property than you first thought. List your most important IP assets, and ask yourself two questions. First, do I have sufficient protections in place, given the value of this IP? Second, how much am I willing to spend to defend this IP? If a competitor should infringe on your intellectual property rights, you will want to react quickly to avoid potential losses and to collect compensation for any financial damage that may have already occurred. At the same time, you need to take a cost-effective approach to protecting your IP, considering the financial investment and future revenue at stake.
No longer is it necessary for one to key-in a password of letters and numbers in order to gain access to computers, smartphones, or other electronically-secured information. The use of one’s facial features, fingerprints, and even their iris for electronic security purposes is becoming more common, yet concerns pertaining to personal privacy and use of stored information is now facing legal challenges.
More and more companies recognize the value of using the Internet to grow and strengthen their business. Whether for communications, marketing, e-commerce, research, or other purposes, online activity among employees and customers has expanded exponentially. However, with this growth comes the increased threat to information moving along or stored by electronic means.
Hand-held devices have taken on an increased presence among business operations throughout a variety of industries. From tracking inventory to recording important statistics and other real-time data, the threat to the information stored on these devices is no less real. This may complicate matters for cyber professionals charged with protecting intellectual property. |
!!# MODULE SUBROUTINE <<SUB_Reallocate>>
MODULE SUB_Reallocate
!!## PURPOSE
!! Reallocates a pointer.
!!## MODULES
USE KND_IntrinsicTypes !!((01-A-KND_IntrinsicTypes.f90))
USE ISO_varying_string !!((03-A-ISO_varying_string.f90))
!!## DEFAULT IMPLICIT
IMPLICIT NONE
!!## DEFAULT ACCESS
PRIVATE
!!## PROCEDURE OVERLOADING
INTERFACE Reallocate
MODULE PROCEDURE Reallocate_P1Rsp
MODULE PROCEDURE Reallocate_P1Rdp
MODULE PROCEDURE Reallocate_P1Csp
MODULE PROCEDURE Reallocate_P1Cdp
MODULE PROCEDURE Reallocate_P1I1
MODULE PROCEDURE Reallocate_P1I2
MODULE PROCEDURE Reallocate_P1I4
MODULE PROCEDURE Reallocate_P1I8
MODULE PROCEDURE Reallocate_P1L1
MODULE PROCEDURE Reallocate_P1L2
MODULE PROCEDURE Reallocate_P1L4
MODULE PROCEDURE Reallocate_P1S
MODULE PROCEDURE Reallocate_P1VS
MODULE PROCEDURE Reallocate_P2Rsp
MODULE PROCEDURE Reallocate_P2Rdp
MODULE PROCEDURE Reallocate_P2Csp
MODULE PROCEDURE Reallocate_P2Cdp
MODULE PROCEDURE Reallocate_P2I1
MODULE PROCEDURE Reallocate_P2I2
MODULE PROCEDURE Reallocate_P2I4
MODULE PROCEDURE Reallocate_P2I8
MODULE PROCEDURE Reallocate_P2L1
MODULE PROCEDURE Reallocate_P2L2
MODULE PROCEDURE Reallocate_P2L4
MODULE PROCEDURE Reallocate_P2S
MODULE PROCEDURE Reallocate_P2VS
MODULE PROCEDURE Reallocate_P3Rsp
MODULE PROCEDURE Reallocate_P3Rdp
MODULE PROCEDURE Reallocate_P3Csp
MODULE PROCEDURE Reallocate_P3Cdp
MODULE PROCEDURE Reallocate_P3I1
MODULE PROCEDURE Reallocate_P3I2
MODULE PROCEDURE Reallocate_P3I4
MODULE PROCEDURE Reallocate_P3I8
MODULE PROCEDURE Reallocate_P3L1
MODULE PROCEDURE Reallocate_P3L2
MODULE PROCEDURE Reallocate_P3L4
MODULE PROCEDURE Reallocate_P3S
MODULE PROCEDURE Reallocate_P3VS
END INTERFACE
!!## PUBLIC ACCESS LIST
PUBLIC :: Reallocate
PUBLIC :: Reallocate_P1Rsp
PUBLIC :: Reallocate_P1Rdp
PUBLIC :: Reallocate_P1Csp
PUBLIC :: Reallocate_P1Cdp
PUBLIC :: Reallocate_P1I1
PUBLIC :: Reallocate_P1I2
PUBLIC :: Reallocate_P1I4
PUBLIC :: Reallocate_P1I8
PUBLIC :: Reallocate_P1L1
PUBLIC :: Reallocate_P1L2
PUBLIC :: Reallocate_P1L4
PUBLIC :: Reallocate_P1S
PUBLIC :: Reallocate_P1VS
PUBLIC :: Reallocate_P2Rsp
PUBLIC :: Reallocate_P2Rdp
PUBLIC :: Reallocate_P2Csp
PUBLIC :: Reallocate_P2Cdp
PUBLIC :: Reallocate_P2I1
PUBLIC :: Reallocate_P2I2
PUBLIC :: Reallocate_P2I4
PUBLIC :: Reallocate_P2I8
PUBLIC :: Reallocate_P2L1
PUBLIC :: Reallocate_P2L2
PUBLIC :: Reallocate_P2L4
PUBLIC :: Reallocate_P2S
PUBLIC :: Reallocate_P2VS
PUBLIC :: Reallocate_P3Rsp
PUBLIC :: Reallocate_P3Rdp
PUBLIC :: Reallocate_P3Csp
PUBLIC :: Reallocate_P3Cdp
PUBLIC :: Reallocate_P3I1
PUBLIC :: Reallocate_P3I2
PUBLIC :: Reallocate_P3I4
PUBLIC :: Reallocate_P3I8
PUBLIC :: Reallocate_P3L1
PUBLIC :: Reallocate_P3L2
PUBLIC :: Reallocate_P3L4
PUBLIC :: Reallocate_P3S
PUBLIC :: Reallocate_P3VS
!!## MODULE PROCEDURES
CONTAINS
!!### SUBROUTINE <<Reallocate_P1Rsp>>
SUBROUTINE Reallocate_P1Rsp( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P1R.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P1.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P1.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P1Rdp>>
SUBROUTINE Reallocate_P1Rdp( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P1R.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P1.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P1.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P1Csp>>
SUBROUTINE Reallocate_P1Csp( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_C=>KIND_Csp !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P1C.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P1.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P1.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P1Cdp>>
SUBROUTINE Reallocate_P1Cdp( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_C=>KIND_Cdp !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P1C.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P1.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P1.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P1I1>>
SUBROUTINE Reallocate_P1I1( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I1 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P1I.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P1.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P1.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P1I2>>
SUBROUTINE Reallocate_P1I2( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I2 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P1I.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P1.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P1.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P1I4>>
SUBROUTINE Reallocate_P1I4( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I4 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P1I.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P1.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P1.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P1I8>>
SUBROUTINE Reallocate_P1I8( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I8 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P1I.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P1.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P1.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P1L1>>
SUBROUTINE Reallocate_P1L1( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_L=>KIND_L1 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P1L.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P1.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P1.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P1L2>>
SUBROUTINE Reallocate_P1L2( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_L=>KIND_L2 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P1L.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P1.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P1.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P1L4>>
SUBROUTINE Reallocate_P1L4( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_L=>KIND_L4 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P1L.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P1.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P1.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P1S>>
SUBROUTINE Reallocate_P1S( data , dn , dnl , fill , noisy )
INCLUDE "04-B-SUB_Reallocate_P1S.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P1.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P1.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P1VS>>
SUBROUTINE Reallocate_P1VS( data , dn , dnl , fill , noisy )
INCLUDE "04-B-SUB_Reallocate_P1VS.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P1.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P1.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P2Rsp>>
SUBROUTINE Reallocate_P2Rsp( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P2R.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P2.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P2.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P2Rdp>>
SUBROUTINE Reallocate_P2Rdp( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P2R.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P2.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P2.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P2Csp>>
SUBROUTINE Reallocate_P2Csp( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_C=>KIND_Csp !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P2C.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P2.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P2.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P2Cdp>>
SUBROUTINE Reallocate_P2Cdp( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_C=>KIND_Cdp !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P2C.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P2.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P2.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P2I1>>
SUBROUTINE Reallocate_P2I1( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I1 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P2I.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P2.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P2.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P2I2>>
SUBROUTINE Reallocate_P2I2( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I2 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P2I.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P2.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P2.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P2I4>>
SUBROUTINE Reallocate_P2I4( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I4 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P2I.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P2.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P2.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P2I8>>
SUBROUTINE Reallocate_P2I8( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I8 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P2I.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P2.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P2.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P2L1>>
SUBROUTINE Reallocate_P2L1( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_L=>KIND_L1 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P2L.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P2.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P2.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P2L2>>
SUBROUTINE Reallocate_P2L2( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_L=>KIND_L2 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P2L.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P2.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P2.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P2L4>>
SUBROUTINE Reallocate_P2L4( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_L=>KIND_L4 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P2L.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P2.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P2.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P2S>>
SUBROUTINE Reallocate_P2S( data , dn , dnl , fill , noisy )
INCLUDE "04-B-SUB_Reallocate_P2S.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P2.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P2.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P2VS>>
SUBROUTINE Reallocate_P2VS( data , dn , dnl , fill , noisy )
INCLUDE "04-B-SUB_Reallocate_P2VS.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P2.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P2.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P3Rsp>>
SUBROUTINE Reallocate_P3Rsp( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P3R.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P3.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P3.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P3Rdp>>
SUBROUTINE Reallocate_P3Rdp( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P3R.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P3.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P3.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P3Csp>>
SUBROUTINE Reallocate_P3Csp( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_C=>KIND_Csp !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P3C.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P3.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P3.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P3Cdp>>
SUBROUTINE Reallocate_P3Cdp( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_C=>KIND_Cdp !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P3C.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P3.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P3.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P3I1>>
SUBROUTINE Reallocate_P3I1( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I1 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P3I.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P3.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P3.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P3I2>>
SUBROUTINE Reallocate_P3I2( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I2 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P3I.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P3.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P3.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P3I4>>
SUBROUTINE Reallocate_P3I4( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I4 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P3I.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P3.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P3.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P3I8>>
SUBROUTINE Reallocate_P3I8( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I8 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P3I.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P3.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P3.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P3L1>>
SUBROUTINE Reallocate_P3L1( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_L=>KIND_L1 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P3L.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P3.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P3.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P3L2>>
SUBROUTINE Reallocate_P3L2( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_L=>KIND_L2 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P3L.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P3.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P3.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P3L4>>
SUBROUTINE Reallocate_P3L4( data , dn , dnl , fill , noisy )
USE KND_IntrinsicTypes,ONLY: KIND_L=>KIND_L4 !!((01-A-KND_IntrinsicTypes.f90))
INCLUDE "04-B-SUB_Reallocate_P3L.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P3.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P3.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P3S>>
SUBROUTINE Reallocate_P3S( data , dn , dnl , fill , noisy )
INCLUDE "04-B-SUB_Reallocate_P3S.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P3.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P3.f90.bdy"
!!--end--
END SUBROUTINE
!!### SUBROUTINE <<Reallocate_P3VS>>
SUBROUTINE Reallocate_P3VS( data , dn , dnl , fill , noisy )
INCLUDE "04-B-SUB_Reallocate_P3VS.f90.hdr"
INCLUDE "04-B-SUB_Reallocate_P3.f90.hdr"
!!--begin--
INCLUDE "04-B-SUB_Reallocate_P3.f90.bdy"
!!--end--
END SUBROUTINE
!!### FUNCTION <<getNewLowBound>>
FUNCTION getNewLowBound( lbo , dnl ) RESULT(lb)
INTEGER,INTENT(IN) :: lbo
INTEGER,INTENT(IN),OPTIONAL :: dnl
INTEGER :: lb
!!--begin
!modify lower bound
IF( PRESENT(dnl) )THEN
lb = lbo+dnl
ELSE
lb = lbo
END IF
!!--end
END FUNCTION
!!### FUNCTION <<getNewUppBound>>
FUNCTION getNewUppBound( ubo , dn ) RESULT(ub)
INTEGER,INTENT(IN) :: ubo
INTEGER,INTENT(IN),OPTIONAL :: dn
INTEGER :: ub
!!--begin
!modify lower bound
IF( PRESENT(dn) )THEN
ub = ubo+dn
ELSE
ub = ubo
END IF
!!--end
END FUNCTION
!!### FUNCTION <<getCoreUppBound>>
FUNCTION getCoreUppBound( ubo , ub ) RESULT(uc)
INTEGER,INTENT(IN) :: ubo,ub
INTEGER :: uc
!!--begin
uc = MIN(ub,ubo)
!!--end
END FUNCTION
!!### FUNCTION <<getCoreLowBound>>
FUNCTION getCoreLowBound( lbo , lb ) RESULT(lc)
INTEGER,INTENT(IN) :: lbo,lb
INTEGER :: lc
!!--begin
lc = MAX(lb,lbo)
!!--end
END FUNCTION
!!### FUNCTION <<getFillUppBound>>
FUNCTION getFillUppBound( ubo , ub ) RESULT(uf)
INTEGER,INTENT(IN) :: ubo,ub
INTEGER :: uf
!!--begin
uf = ubo+1
!!--end
END FUNCTION
!!### FUNCTION <<getFillLowBound>>
FUNCTION getFillLowBound( lbo , lb ) RESULT(lf)
INTEGER,INTENT(IN) :: lbo,lb
INTEGER :: lf
!!--begin
lf = lbo-1
!!--end
END FUNCTION
END MODULE
|
//
// The MIT License (MIT)
//
// Copyright (c) 2019 Livox. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#include "device_discovery.h"
#include <algorithm>
#include <boost/thread/lock_guard.hpp>
#include <boost/thread/locks.hpp>
#include <iostream>
#include <vector>
#include "apr_network_io.h"
#include "apr_pools.h"
#ifdef WIN32
#include "winsock.h"
#else
#include "arpa/inet.h"
#endif
#include "base/logging.h"
#include "base/network_util.h"
#include "command_handler/command_impl.h"
#include "device_manager.h"
#include "livox_def.h"
using boost::tuple;
using std::string;
using std::vector;
namespace livox {
uint16_t DeviceDiscovery::port_count = 0;
bool DeviceDiscovery::Init() {
apr_status_t rv = apr_pool_create(&mem_pool_, NULL);
if (rv != APR_SUCCESS) {
LOG_ERROR(PrintAPRStatus(rv));
return false;
}
if (comm_port_ == NULL) {
comm_port_.reset(new CommPort());
}
return true;
}
bool DeviceDiscovery::Start(IOLoop *loop) {
if (loop == NULL) {
return false;
}
loop_ = loop;
sock_ = util::CreateBindSocket(kListenPort, mem_pool_, true);
if (sock_ == NULL) {
LOG_ERROR("DeviceDiscovery Create Socket Failed");
return false;
}
loop_->AddDelegate(sock_, this);
return true;
}
void DeviceDiscovery::OnData(apr_socket_t *sock, void *) {
apr_sockaddr_t addr;
uint32_t buf_size = 0;
uint8_t *cache_buf = comm_port_->FetchCacheFreeSpace(&buf_size);
apr_size_t size = buf_size;
apr_status_t rv = apr_socket_recvfrom(&addr, sock, 0, reinterpret_cast<char *>(cache_buf), &size);
comm_port_->UpdateCacheWrIdx(size);
if (rv != APR_SUCCESS) {
LOG_WARN(" Receive Failed {}", PrintAPRStatus(rv));
return;
}
CommPacket packet;
memset(&packet, 0, sizeof(packet));
while ((kParseSuccess == comm_port_->ParseCommStream(&packet))) {
if (packet.cmd_set == kCommandSetGeneral && packet.cmd_code == kCommandIDGeneralBroadcast) {
OnBroadcast(packet, &addr);
} else if (packet.cmd_set == kCommandSetGeneral && packet.cmd_code == kCommandIDGeneralHandshake) {
if (connecting_devices_.find(sock) == connecting_devices_.end()) {
continue;
}
DeviceInfo info = boost::get<2>(connecting_devices_[sock]);
loop_->RemoveDelegate(sock, this);
apr_socket_close(sock);
apr_pool_destroy(boost::get<0>(connecting_devices_[sock]));
connecting_devices_.erase(sock);
if (packet.data == NULL) {
continue;
}
if (*(uint8_t *)packet.data == 0) {
LOG_INFO("New Device");
LOG_INFO("Handle: {}", static_cast<uint16_t>(info.handle));
LOG_INFO("Broadcast Code: {}", info.broadcast_code);
LOG_INFO("Type: {}", info.type);
LOG_INFO("IP: {}", info.ip);
LOG_INFO("Command Port: {}", info.cmd_port);
LOG_INFO("Data Port: {}", info.data_port);
DeviceFound(info);
}
}
}
}
void DeviceDiscovery::OnTimer(apr_time_t now) {
ConnectingDeviceMap::iterator ite = connecting_devices_.begin();
while (ite != connecting_devices_.end()) {
tuple<apr_pool_t *, apr_time_t, DeviceInfo> &device_tuple = ite->second;
if (now - boost::get<1>(device_tuple) > apr_time_from_msec(500)) {
loop_->RemoveDelegate(ite->first, this);
apr_socket_close(ite->first);
apr_pool_destroy(boost::get<0>(device_tuple));
connecting_devices_.erase(ite++);
} else {
++ite;
}
}
}
void DeviceDiscovery::Uninit() {
if (sock_) {
loop_->RemoveDelegate(sock_, this);
apr_socket_close(sock_);
sock_ = NULL;
}
if (comm_port_) {
comm_port_.reset(NULL);
}
if (mem_pool_) {
apr_pool_destroy(mem_pool_);
mem_pool_ = NULL;
}
}
void DeviceDiscovery::OnBroadcast(const CommPacket &packet, apr_sockaddr_t *addr) {
if (packet.data == NULL) {
return;
}
BroadcastDeviceInfo device_info;
memcpy((void*)(&device_info),(void*)(packet.data),(sizeof(BroadcastDeviceInfo)-sizeof(device_info.ip)));
string broadcast_code = device_info.broadcast_code;
LOG_INFO(" Broadcast broadcast code: {}", broadcast_code);
char ip[16];
memset(&ip, 0, sizeof(ip));
apr_status_t rv = apr_sockaddr_ip_getbuf(ip, sizeof(ip), addr);
if (rv != APR_SUCCESS) {
LOG_ERROR(PrintAPRStatus(rv));
return;
}
strncpy(device_info.ip, ip, sizeof(device_info.ip));
device_manager().BroadcastDevices(&device_info);
DeviceInfo lidar_info;
bool found = device_manager().FindDevice(broadcast_code, lidar_info);
if (!found) {
LOG_INFO("Broadcast code : {} not add to connect", broadcast_code);
}
if (!found || device_manager().IsDeviceConnected(lidar_info.handle)) {
return;
}
++port_count;
strncpy(lidar_info.broadcast_code, broadcast_code.c_str(), sizeof(lidar_info.broadcast_code));
lidar_info.cmd_port = kListenPort + kCmdPortOffset + port_count;
lidar_info.data_port = kListenPort + kDataPortOffset + port_count;
lidar_info.sensor_port = kListenPort + kSensorPortOffset + port_count;
lidar_info.type = device_info.dev_type;
lidar_info.state = kLidarStateUnknown;
lidar_info.feature = kLidarFeatureNone;
lidar_info.status.progress = 0;
strncpy(lidar_info.ip, ip, sizeof(lidar_info.ip));
apr_pool_t *pool = NULL;
rv = apr_pool_create(&pool, mem_pool_);
if (rv != APR_SUCCESS) {
LOG_ERROR(PrintAPRStatus(rv));
return;
}
apr_socket_t *cmd_sock = util::CreateBindSocket(lidar_info.cmd_port, pool);
if (cmd_sock == NULL) {
apr_pool_destroy(pool);
pool = NULL;
return;
}
loop_->AddDelegate(cmd_sock, this);
OnTimer(apr_time_now());
boost::get<0>(connecting_devices_[cmd_sock]) = pool;
boost::get<2>(connecting_devices_[cmd_sock]) = lidar_info;
bool result = false;
do {
HandshakeRequest handshake_req;
uint32_t local_ip = 0;
if (util::FindLocalIp(addr->sa.sin, local_ip) == false) {
result = false;
LOG_INFO("LocalIp and DeviceIp are not in same subnet");
break;
}
LOG_INFO("LocalIP: {}", inet_ntoa(*(struct in_addr *)&local_ip));
LOG_INFO("Command Port: {}", lidar_info.cmd_port);
LOG_INFO("Data Port: {}", lidar_info.data_port);
CommPacket packet;
memset(&packet, 0, sizeof(packet));
handshake_req.ip_addr = local_ip;
handshake_req.cmd_port = lidar_info.cmd_port;
handshake_req.data_port = lidar_info.data_port;
handshake_req.sensor_port = lidar_info.sensor_port;
packet.packet_type = kCommandTypeAck;
packet.seq_num = CommandChannel::GenerateSeq();
packet.cmd_set = kCommandSetGeneral;
packet.cmd_code = kCommandIDGeneralHandshake;
packet.data_len = sizeof(handshake_req);
packet.data = (uint8_t *)&handshake_req;
vector<uint8_t> buf(kMaxCommandBufferSize + 1);
apr_size_t o_len = kMaxCommandBufferSize;
comm_port_->Pack(buf.data(), kMaxCommandBufferSize, (uint32_t *)&o_len, packet);
rv = apr_socket_sendto(cmd_sock, addr, 0, reinterpret_cast<const char *>(buf.data()), &o_len);
if (rv != APR_SUCCESS) {
result = false;
break;
}
boost::get<1>(connecting_devices_[cmd_sock]) = apr_time_now();
result = true;
} while (0);
if (result == false) {
loop_->RemoveDelegate(cmd_sock, this);
apr_socket_close(cmd_sock);
apr_pool_destroy(pool);
connecting_devices_.erase(cmd_sock);
}
}
DeviceDiscovery &device_discovery() {
static DeviceDiscovery discovery;
return discovery;
}
} // namespace livox
|
-- ----------------------------------------------------------- [ Structure.idr ]
-- Module : Structure.idr
-- Copyright : (c) Jan de Muijnck-Hughes
-- License : see LICENSE
-- --------------------------------------------------------------------- [ EOH ]
||| This section details the check for structural link insertion.
|||
||| Correctness/Soundess Properties of a Structural Link
|||
||| 1. The src and destination must not be the same.
||| 2. A node can only be decomposed once.
||| 3. The decomposition type must be valid for the parent.
||| 4. A parent cannot be contained by its children.
|||
module GRL.Property.Structure
import public Data.AVL.Graph
import public Data.List
import public Data.Stack
import GRL.Model
import GRL.IR
import GRL.Common
%default partial
%access export
-- ----------------------------------------------- [ Structural Link Insertion ]
||| No loops and all different children.
allDiff : GExpr ELEM -> List (GExpr ELEM) -> Bool
allDiff src ds = diffDSTs ds && noLoopBack src ds
where
diffDSTs : List (GExpr ELEM) -> Bool
diffDSTs xs = if length xs == 1
then True
else not $ and [ eqGExpr x y | x <- xs, y <- xs]
noLoopBack : GExpr ELEM -> List (GExpr ELEM) -> Bool
noLoopBack y xs = not $ and $ map (\x => eqGExpr x y) xs
||| Nodes are all valid nodes
validNodes : List (GExpr ELEM) -> GModel -> Bool
validNodes ns m = and $ map (\n => isValid n m) ns
where
isValid : GExpr ELEM -> GModel -> Bool
isValid (Elem ty t s) m = hasGoal t m
||| The node is free to be decomposed, or has been decomposed and are
||| adding the same decomposition.
validDTy : GExpr ELEM -> GStructTy -> GModel -> Bool
validDTy (Elem ty t s) dty m =
case getGoalByTitle t m of
Nothing => False
Just n => case getStructTy n of
Nothing => True
Just xty => xty == dty
-- -------------------------------------------------------------- [ Evaluation ]
private
record ComputeState where
constructor MkState
next : Stack NodeID
seen : List NodeID
private
defState : List NodeID -> ComputeState
defState is = MkState (pushSThings is mkStack) (List.Nil)
private
cycleCheck : NodeID -> NodeID -> List NodeID -> Bool
cycleCheck id curr seen = elem curr seen || curr == id || elem id seen
partial
private
doComputeSpan : (id : NodeID)
-> (model : GModel)
-> (st : ComputeState)
-> Bool
doComputeSpan id g st =
case popS' (next st) of
Nothing => True
Just (curr, newS) => -- TODO
if cycleCheck id curr (seen st)
then False
else let cs = children curr in
if isNil cs
then True && doComputeSpan id g
(record { next = newS} st)
else
if elem id cs
then False -- If thing is in children
else True && doComputeSpan id g
(record { seen = curr :: (seen st)
, next = newS ++ cs} st)
where
children : NodeID -> List NodeID
children n = map fst $ getDeCompEdges n g
%assert_total
computeSpan : GExpr STRUCT -> GModel -> Bool
computeSpan (SLink ty (Elem ty' t s) ds) m =
case initID of
Nothing => False
Just id => doComputeSpan id m (defState ds')
where
initID : Maybe NodeID
initID = getGoalIDByTitle t m
ds' : List (NodeID)
ds' = catMaybes $ map (\x => getGoalIDByTitle (getTitle x) m) ds
partial
checkStructBool : GExpr STRUCT -> GModel -> Bool
checkStructBool l@(SLink ty src ds) m =
length ds >= 1
&& allDiff src ds
&& validNodes (src :: ds) m
&& validDTy src ty m
&& computeSpan l m
-- --------------------------------------------------------------------- [ EOF ]
|
Require Import Coq.Setoids.Setoid.
Require Import Coq.Lists.List.
Import ListNotations.
Require Import Tactics.
Require Import Sequence.
Require Import Syntax.
Require Import Subst.
Require Import SimpSub.
Require Import Promote.
Require Import Hygiene.
Require Import Rules.
Require Import DerivedRules.
Require Defs.
Require Import Obligations.
Require Import Morphism.
Require Import DefsEquiv.
Require Import Equivalence.
Require Import Equivalences.
Require Import Dots.
Require Import Relation.
Require Import Dynamic.
Require Import ValidationUtil.
Lemma substitution_valid : substitution_obligation.
Proof.
prepare.
intros G1 G2 a b m ext1 ext0 n Hb Hm Hn.
simpsubin Hb.
simpsubin Hm.
eapply tr_substitution; eauto.
Qed.
Lemma substitutionSimple_valid : substitutionSimple_obligation.
Proof.
prepare.
intros G1 G2 a b m ext0 n Hm Hn.
simpsubin Hm.
eapply tr_substitution_simple; eauto.
Qed.
Lemma generalize_valid : generalize_obligation.
Proof.
prepare.
intros G a b m ext0 n Hm Hn.
cut (tr G (substj (dot m id) (deq n n b))).
{
intro H.
simpsubin H.
exact H.
}
eapply tr_generalize; eauto.
Qed.
Lemma def_lett :
forall m n,
equiv (app (app Defs.lett m) (lam n)) (app (lam n) m).
Proof.
intros a m.
unfold Defs.lett.
eapply equiv_trans.
{
apply steps_equiv.
eapply star_step.
{
apply step_app1.
apply step_app2.
}
simpsub.
eapply star_step.
{
apply step_app2.
}
simpsub.
apply star_refl.
}
apply equiv_refl.
Qed.
Lemma assert_valid : assert_obligation.
Proof.
prepare.
intros G a b m n Hm Hn.
rewrite -> def_lett.
eapply tr_pi_elim'; eauto.
{
apply tr_pi_intro; eauto.
eapply tr_inhabitation_formation; eauto.
}
{
simpsub.
auto.
}
Qed.
Lemma assert'_valid : assert'_obligation.
Proof.
prepare.
intros G a b m n Hm Hn.
cut (tr G (substj (dot m id) (deq n n (subst sh1 b)))).
{
intro H.
simpsubin H.
exact H.
}
eapply tr_generalize; eauto.
Qed.
Lemma inhabitant_valid : inhabitant_obligation.
Proof.
prepare.
intros G a m ext0 H.
auto.
Qed.
Lemma eeqtpSymm_valid : eeqtpSymm_obligation.
Proof.
prepare.
intros G a b m H.
rewrite -> def_eeqtp in H |- *.
apply tr_prod_intro.
{
apply (tr_subtype_eta2 _#3 (ppi2 m) (ppi2 m)).
eapply tr_prod_elim2; eauto.
}
{
apply (tr_subtype_eta2 _#3 (ppi1 m) (ppi1 m)).
eapply tr_prod_elim1; eauto.
}
Qed.
Lemma weakenEqtpEeqtp_valid : weakenEqtpEeqtp_obligation.
Proof.
prepare.
intros G a b ext0 H.
rewrite -> def_eeqtp.
apply tr_prod_intro.
{
apply tr_subtype_intro.
{
eapply tr_eqtype_formation_left; eauto.
}
{
eapply tr_eqtype_formation_right; eauto.
}
apply (tr_eqtype_convert _ _ _ (subst sh1 a)).
{
apply (weakening _ [_] []).
{
cbn [length unlift].
simpsub.
auto.
}
{
cbn [length unlift].
simpsub.
auto.
}
cbn [length unlift].
simpsub.
cbn [List.app].
auto.
}
{
eapply hypothesis; eauto using index_0.
}
}
{
apply tr_subtype_intro.
{
eapply tr_eqtype_formation_right; eauto.
}
{
eapply tr_eqtype_formation_left; eauto.
}
apply (tr_eqtype_convert _ _ _ (subst sh1 b)).
{
apply tr_eqtype_symmetry.
apply (weakening _ [_] []).
{
cbn [length unlift].
simpsub.
auto.
}
{
cbn [length unlift].
simpsub.
auto.
}
cbn [length unlift].
simpsub.
cbn [List.app].
auto.
}
{
eapply hypothesis; eauto using index_0.
}
}
Qed.
Lemma letForm_valid : letForm_obligation.
Proof.
prepare.
intros G a b m n ext1 ext0 Hm Hn.
unfold Defs.lett.
rewrite -> equiv_beta.
simpsub.
rewrite -> equiv_beta.
simpsub.
eapply tr_pi_elim'; eauto.
{
apply tr_pi_intro.
{
eapply tr_inhabitation_formation; eauto.
}
exact Hn.
}
{
simpsub.
auto.
}
Qed.
|
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.algebra.basic
import Mathlib.PostPort
universes u v
namespace Mathlib
/-!
# Trivial Square-Zero Extension
Given a module `M` over a ring `R`, the trivial square-zero extension of `M` over `R` is defined
to be the `R`-algebra `R ⊕ M` with multiplication given by
`(r₁ + m₁) * (r₂ + m₂) = r₁ r₂ + r₁ m₂ + r₂ m₁`.
It is a square-zero extension because `M^2 = 0`.
-/
/--
"Trivial Square-Zero Extension".
Given a module `M` over a ring `R`, the trivial square-zero extension of `M` over `R` is defined
to be the `R`-algebra `R × M` with multiplication given by
`(r₁ + m₁) * (r₂ + m₂) = r₁ r₂ + r₁ m₂ + r₂ m₁`.
It is a square-zero extension because `M^2 = 0`.
-/
def triv_sq_zero_ext (R : Type u) (M : Type v) :=
R × M
namespace triv_sq_zero_ext
/-- The canonical inclusion `R → triv_sq_zero_ext R M`. -/
def inl {R : Type u} {M : Type v} [HasZero M] (r : R) : triv_sq_zero_ext R M :=
(r, 0)
/-- The canonical inclusion `M → triv_sq_zero_ext R M`. -/
def inr {R : Type u} {M : Type v} [HasZero R] (m : M) : triv_sq_zero_ext R M :=
(0, m)
/-- The canonical projection `triv_sq_zero_ext R M → R`. -/
def fst {R : Type u} {M : Type v} (x : triv_sq_zero_ext R M) : R :=
prod.fst x
/-- The canonical projection `triv_sq_zero_ext R M → M`. -/
def snd {R : Type u} {M : Type v} (x : triv_sq_zero_ext R M) : M :=
prod.snd x
theorem ext {R : Type u} {M : Type v} {x : triv_sq_zero_ext R M} {y : triv_sq_zero_ext R M} (h1 : fst x = fst y) (h2 : snd x = snd y) : x = y :=
prod.ext h1 h2
@[simp] theorem fst_inl {R : Type u} {M : Type v} [HasZero M] (r : R) : fst (inl r) = r :=
rfl
@[simp] theorem snd_inl {R : Type u} {M : Type v} [HasZero M] (r : R) : snd (inl r) = 0 :=
rfl
@[simp] theorem fst_inr {R : Type u} {M : Type v} [HasZero R] (m : M) : fst (inr m) = 0 :=
rfl
@[simp] theorem snd_inr {R : Type u} {M : Type v} [HasZero R] (m : M) : snd (inr m) = m :=
rfl
theorem inl_injective {R : Type u} {M : Type v} [HasZero M] : function.injective inl :=
function.left_inverse.injective fst_inl
theorem inr_injective {R : Type u} {M : Type v} [HasZero R] : function.injective inr :=
function.left_inverse.injective snd_inr
protected instance has_zero (R : Type u) (M : Type v) [HasZero R] [HasZero M] : HasZero (triv_sq_zero_ext R M) :=
prod.has_zero
@[simp] theorem fst_zero (R : Type u) (M : Type v) [HasZero R] [HasZero M] : fst 0 = 0 :=
rfl
@[simp] theorem snd_zero (R : Type u) (M : Type v) [HasZero R] [HasZero M] : snd 0 = 0 :=
rfl
@[simp] theorem inl_zero (R : Type u) (M : Type v) [HasZero R] [HasZero M] : inl 0 = 0 :=
rfl
@[simp] theorem inr_zero (R : Type u) (M : Type v) [HasZero R] [HasZero M] : inr 0 = 0 :=
rfl
protected instance has_add (R : Type u) (M : Type v) [Add R] [Add M] : Add (triv_sq_zero_ext R M) :=
prod.has_add
@[simp] theorem fst_add (R : Type u) (M : Type v) [Add R] [Add M] (x₁ : triv_sq_zero_ext R M) (x₂ : triv_sq_zero_ext R M) : fst (x₁ + x₂) = fst x₁ + fst x₂ :=
rfl
@[simp] theorem snd_add (R : Type u) (M : Type v) [Add R] [Add M] (x₁ : triv_sq_zero_ext R M) (x₂ : triv_sq_zero_ext R M) : snd (x₁ + x₂) = snd x₁ + snd x₂ :=
rfl
protected instance has_neg (R : Type u) (M : Type v) [Neg R] [Neg M] : Neg (triv_sq_zero_ext R M) :=
prod.has_neg
@[simp] theorem fst_neg (R : Type u) (M : Type v) [Neg R] [Neg M] (x : triv_sq_zero_ext R M) : fst (-x) = -fst x :=
rfl
@[simp] theorem snd_neg (R : Type u) (M : Type v) [Neg R] [Neg M] (x : triv_sq_zero_ext R M) : snd (-x) = -snd x :=
rfl
protected instance add_semigroup (R : Type u) (M : Type v) [add_semigroup R] [add_semigroup M] : add_semigroup (triv_sq_zero_ext R M) :=
prod.add_semigroup
protected instance add_monoid (R : Type u) (M : Type v) [add_monoid R] [add_monoid M] : add_monoid (triv_sq_zero_ext R M) :=
prod.add_monoid
@[simp] theorem inl_add (R : Type u) (M : Type v) [Add R] [add_monoid M] (r₁ : R) (r₂ : R) : inl (r₁ + r₂) = inl r₁ + inl r₂ :=
ext rfl (Eq.symm (add_zero 0))
@[simp] theorem inr_add (R : Type u) (M : Type v) [add_monoid R] [Add M] (m₁ : M) (m₂ : M) : inr (m₁ + m₂) = inr m₁ + inr m₂ :=
ext (Eq.symm (add_zero 0)) rfl
theorem inl_fst_add_inr_snd_eq (R : Type u) (M : Type v) [add_monoid R] [add_monoid M] (x : triv_sq_zero_ext R M) : inl (fst x) + inr (snd x) = x :=
ext (add_zero (prod.fst x)) (zero_add (prod.snd x))
protected instance add_group (R : Type u) (M : Type v) [add_group R] [add_group M] : add_group (triv_sq_zero_ext R M) :=
prod.add_group
@[simp] theorem inl_neg (R : Type u) (M : Type v) [Neg R] [add_group M] (r : R) : inl (-r) = -inl r :=
ext rfl (Eq.symm neg_zero)
@[simp] theorem inr_neg (R : Type u) (M : Type v) [add_group R] [Neg M] (m : M) : inr (-m) = -inr m :=
ext (Eq.symm neg_zero) rfl
protected instance add_comm_semigroup (R : Type u) (M : Type v) [add_comm_semigroup R] [add_comm_semigroup M] : add_comm_semigroup (triv_sq_zero_ext R M) :=
prod.add_comm_semigroup
protected instance add_comm_monoid (R : Type u) (M : Type v) [add_comm_monoid R] [add_comm_monoid M] : add_comm_monoid (triv_sq_zero_ext R M) :=
prod.add_comm_monoid
protected instance add_comm_group (R : Type u) (M : Type v) [add_comm_group R] [add_comm_group M] : add_comm_group (triv_sq_zero_ext R M) :=
prod.add_comm_group
protected instance has_scalar (R : Type u) (M : Type v) [Mul R] [has_scalar R M] : has_scalar R (triv_sq_zero_ext R M) :=
has_scalar.mk fun (r : R) (x : triv_sq_zero_ext R M) => (r * prod.fst x, r • prod.snd x)
@[simp] theorem fst_smul (R : Type u) (M : Type v) [Mul R] [has_scalar R M] (r : R) (x : triv_sq_zero_ext R M) : fst (r • x) = r * fst x :=
rfl
@[simp] theorem snd_smul (R : Type u) (M : Type v) [Mul R] [has_scalar R M] (r : R) (x : triv_sq_zero_ext R M) : snd (r • x) = r • snd x :=
rfl
@[simp] theorem inr_smul (R : Type u) (M : Type v) [mul_zero_class R] [has_scalar R M] (r : R) (m : M) : inr (r • m) = r • inr m :=
ext (Eq.symm (mul_zero r)) rfl
protected instance mul_action (R : Type u) (M : Type v) [monoid R] [mul_action R M] : mul_action R (triv_sq_zero_ext R M) :=
mul_action.mk sorry sorry
protected instance distrib_mul_action (R : Type u) (M : Type v) [semiring R] [add_monoid M] [distrib_mul_action R M] : distrib_mul_action R (triv_sq_zero_ext R M) :=
distrib_mul_action.mk sorry sorry
protected instance semimodule (R : Type u) (M : Type v) [semiring R] [add_comm_monoid M] [semimodule R M] : semimodule R (triv_sq_zero_ext R M) :=
semimodule.mk sorry sorry
protected instance module (R : Type u) (M : Type v) [ring R] [add_comm_group M] [module R M] : module R (triv_sq_zero_ext R M) :=
semimodule.mk sorry sorry
/-- The canonical `R`-linear inclusion `M → triv_sq_zero_ext R M`. -/
@[simp] theorem inr_hom_apply (R : Type u) (M : Type v) [semiring R] [add_comm_monoid M] [semimodule R M] (m : M) : coe_fn (inr_hom R M) m = inr m :=
Eq.refl (coe_fn (inr_hom R M) m)
protected instance has_one (R : Type u) (M : Type v) [HasOne R] [HasZero M] : HasOne (triv_sq_zero_ext R M) :=
{ one := (1, 0) }
@[simp] theorem fst_one (R : Type u) (M : Type v) [HasOne R] [HasZero M] : fst 1 = 1 :=
rfl
@[simp] theorem snd_one (R : Type u) (M : Type v) [HasOne R] [HasZero M] : snd 1 = 0 :=
rfl
@[simp] theorem inl_one (R : Type u) (M : Type v) [HasOne R] [HasZero M] : inl 1 = 1 :=
rfl
protected instance has_mul (R : Type u) (M : Type v) [Mul R] [Add M] [has_scalar R M] : Mul (triv_sq_zero_ext R M) :=
{ mul :=
fun (x y : triv_sq_zero_ext R M) => (prod.fst x * prod.fst y, prod.fst x • prod.snd y + prod.fst y • prod.snd x) }
@[simp] theorem fst_mul (R : Type u) (M : Type v) [Mul R] [Add M] [has_scalar R M] (x₁ : triv_sq_zero_ext R M) (x₂ : triv_sq_zero_ext R M) : fst (x₁ * x₂) = fst x₁ * fst x₂ :=
rfl
@[simp] theorem snd_mul (R : Type u) (M : Type v) [Mul R] [Add M] [has_scalar R M] (x₁ : triv_sq_zero_ext R M) (x₂ : triv_sq_zero_ext R M) : snd (x₁ * x₂) = fst x₁ • snd x₂ + fst x₂ • snd x₁ :=
rfl
@[simp] theorem inl_mul (R : Type u) (M : Type v) [monoid R] [add_monoid M] [distrib_mul_action R M] (r₁ : R) (r₂ : R) : inl (r₁ * r₂) = inl r₁ * inl r₂ := sorry
theorem inl_mul_inl (R : Type u) (M : Type v) [monoid R] [add_monoid M] [distrib_mul_action R M] (r₁ : R) (r₂ : R) : inl r₁ * inl r₂ = inl (r₁ * r₂) :=
Eq.symm (inl_mul R M r₁ r₂)
theorem inl_mul_inr (R : Type u) (M : Type v) [semiring R] [add_comm_monoid M] [semimodule R M] (r : R) (m : M) : inl r * inr m = inr (r • m) := sorry
theorem inr_mul_inl (R : Type u) (M : Type v) [semiring R] [add_comm_monoid M] [semimodule R M] (r : R) (m : M) : inr m * inl r = inr (r • m) := sorry
@[simp] theorem inr_mul_inr (R : Type u) (M : Type v) [semiring R] [add_comm_monoid M] [semimodule R M] (m₁ : M) (m₂ : M) : inr m₁ * inr m₂ = 0 := sorry
protected instance monoid (R : Type u) (M : Type v) [comm_monoid R] [add_monoid M] [distrib_mul_action R M] : monoid (triv_sq_zero_ext R M) :=
monoid.mk Mul.mul sorry 1 sorry sorry
protected instance comm_semiring (R : Type u) (M : Type v) [comm_semiring R] [add_comm_monoid M] [semimodule R M] : comm_semiring (triv_sq_zero_ext R M) :=
comm_semiring.mk add_comm_monoid.add sorry add_comm_monoid.zero sorry sorry sorry monoid.mul sorry monoid.one sorry
sorry sorry sorry sorry sorry sorry
/-- The canonical inclusion of rings `R → triv_sq_zero_ext R M`. -/
def inl_hom (R : Type u) (M : Type v) [comm_semiring R] [add_comm_monoid M] [semimodule R M] : R →+* triv_sq_zero_ext R M :=
ring_hom.mk inl sorry sorry sorry sorry
protected instance algebra (R : Type u) (M : Type v) [comm_semiring R] [add_comm_monoid M] [semimodule R M] : algebra R (triv_sq_zero_ext R M) :=
algebra.mk (ring_hom.mk (ring_hom.to_fun (inl_hom R M)) sorry sorry sorry sorry) sorry sorry
/-- The canonical `R`-algebra projection `triv_sq_zero_ext R M → R`. -/
def fst_hom (R : Type u) (M : Type v) [comm_semiring R] [add_comm_monoid M] [semimodule R M] : alg_hom R (triv_sq_zero_ext R M) R :=
alg_hom.mk fst sorry sorry sorry sorry sorry
/-- The canonical `R`-module projection `triv_sq_zero_ext R M → M`. -/
@[simp] theorem snd_hom_apply (R : Type u) (M : Type v) [semiring R] [add_comm_monoid M] [semimodule R M] (x : triv_sq_zero_ext R M) : coe_fn (snd_hom R M) x = snd x :=
Eq.refl (coe_fn (snd_hom R M) x)
|
Everyone that goes on ahead and shops at an online head shop will discover that this is by far the most convenient way that they can possible get all the smoking items that they would like for themselves. You no longer have to get up, get dressed, and travel anywhere when you shop in an online head shop. The only thing that people need to do all the shopping that they want nowadays is connection to the internet, and they can shop … Read More..
in the case of your job, you are able to create the right conditions that are required through creativity, this will result to you being able to have to achieve the best in terms of your job and hence you will get to do your job well. Creativity is something that can be boosted through certain conditions, one is listening to music and ensure that you buy here, this will ensure … Read More.. |
double : Num ty => ty -> ty
double x = x + x |
The City Limits of Davis:
The city limits do not include the university or most anything west of it, which is almost exclusively student housing. The net effect is that nearly half of the citys student population doesnt get to participate in city elections, exactly the way the rest of the city likes it. Students, who are poor and need a place to live, tend to be in favor of new development, whereas old residents, who own homes, tend to be in favor of driving up the scarcity of housing as much as they can in order to raise their property values.
Interestingly, although much of the University lies outside of the city of Davis, the borders of Yolo county follow Putah Creek and thus include most of the University owned land and virtually all of the developed land. The remainder south of Putah is Solano County.
The University owns an enormous amount of land and is technically in unincorporated Yolo county. To skirt Davis nogrowth politics, many of the Real Estate new developments proposed are on University property in unincorporated county.
See: NIMBY
Additional topics needing to be covered in this article include buffer space and the agreement with the County where the City pays to extend their control over development outside of the city limits.
|
If $f$ is a Z-function and $r > 0$, then $f$ is eventually less than $r$. |
function [grad, roiCoords, view] = checkSpatialGradMap(view, scan, roi, preserveCoords);
%
% [grad, roiCoords, view] = checkSpatialGradMap(view, [scan=1], [roi], [preserveCoords=0]);
%
% Get a spatial gradient map for detrending purposes, loading and/or
% computing in the view as needed. Returns a gradient matrix (size
% is dataSize(view)) for the selected scan.
%
% If an ROI is specified (see tc_roiStruct for the ways to specify), will
% also return a 3xN set of coordinates into the gradient map corresponding
% to the ROI, appropriate for the current view. The roiCoords are intended
% for use with er_preporcessTSeries.
%
% ras, 02/2007
if notDefined('view'), view = getCurView; end
if notDefined('scan'), scan = view.curScan; end
if notDefined('preserveCoords'), preserveCoords = 0; end
grad = [];
roiCoords = [];
if ~isfield(view, 'spatialGrad') | isempty(view.spatialGrad)
% load and/or compute
mapPath = fullfile(dataDir(view), 'spatialGrad.mat');
if ~exist(mapPath, 'file') % offer to compute it
q = ['The inomogeity correction flag is set to use the spatial ' ...
'gradient map (inhomoCorrect=3). This map is not found. ' ...
'Compute it now? '];
resp = questdlg(q);
if ~isequal(resp, 'Yes')
error('Aborted--no spatial gradient map.')
end
view = computeSpatialGradient(view);
end
view = loadSpatialGradient(view);
% ensure the loaded spatial grad map propagates back
% to the base workspace (global variable):
updateGlobal(view);
end
grad = view.spatialGrad{scan};
if exist('roi', 'var') & ~isempty(roi)
% get map coordinates for the ROI
roi = tc_roiStruct(view, roi);
if preserveCoords==0
subCoords = roiSubCoords(view, roi.coords);
else
subCoords = roi.coords;
end
[indices roiCoords] = roiIndices(view, subCoords, preserveCoords);
% for volume/gray views, we want the indices and not coords
% for the map (which is size 1 x nIndices). Mock up a 3xN
% coords array, in which the columns reflec the indices into the map:
if ismember(view.viewType, {'Volume' 'Gray'})
roiCoords = ones(3, size(indices,2));
roiCoords(2,:) = indices;
end
end
return
|
[STATEMENT]
lemma mult_vec_right_diff_distrib: "r ** (p - q) = r ** p - r ** q"
for r::"_ \<Rightarrow>\<^sub>0 'b::ring"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. r ** (p - q) = r ** p - r ** q
[PROOF STEP]
using mult_vec_distrib_left [of r p "- q"]
[PROOF STATE]
proof (prove)
using this:
r ** (p + - q) = r ** p + r ** - q
goal (1 subgoal):
1. r ** (p - q) = r ** p - r ** q
[PROOF STEP]
by (simp add: mult_vec_minus_mult_right) |
open import Data.Product using ( _,_ ; proj₁ ; proj₂ )
open import Data.Sum using ( _⊎_ ; inj₁ ; inj₂ )
open import Relation.Binary.PropositionalEquality using ( refl )
open import Relation.Unary using ( _∈_ )
open import Web.Semantic.DL.ABox using ( ABox ; _,_ ; ⟨ABox⟩ )
open import Web.Semantic.DL.ABox.Interp using ( Interp ; _,_ ; ⌊_⌋ ; ind ; _*_ )
open import Web.Semantic.DL.ABox.Interp.Morphism using
( _≲_ ; _,_ ; ≲⌊_⌋ ; ≲-resp-ind ; _**_ ; ≡³-impl-≈ ; ≡³-impl-≲ )
open import Web.Semantic.DL.ABox.Model using
( _⊨a_ ; _⊨b_ ; bnodes ; on-bnode ; _,_
; ⟨ABox⟩-resp-⊨ ; ⊨a-resp-≲ ; *-resp-⟨ABox⟩ )
open import Web.Semantic.DL.Category.Morphism using
( _⇒_ ; _⇒_w/_ ; _,_ ; BN ; impl ; impl✓ )
open import Web.Semantic.DL.Category.Object using
( Object ; _,_ ; IN ; fin ; iface )
open import Web.Semantic.DL.Integrity using
( _⊕_⊨_ ; Unique ; Mediated ; Mediator ; Initial
; _,_ ; extension ; ext-init ; ext-⊨ ; ext✓ ; init-≲ )
open import Web.Semantic.DL.KB using ( _,_ )
open import Web.Semantic.DL.KB.Model using ( _⊨_ )
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox using ( TBox ; _,_ )
open import Web.Semantic.DL.TBox.Interp using
( Δ ; _⊨_≈_ ; ≈-refl ; ≈-sym ; ≈-trans )
open import Web.Semantic.DL.TBox.Model using ( _⊨t_ )
open import Web.Semantic.DL.TBox.Interp.Morphism using
( ≲-image ; ≲-resp-≈ ; ≲-trans ) renaming ( _≲_ to _≲′_ )
open import Web.Semantic.Util using
( _∘_ ; Finite ; ⊎-resp-Fin ; _⊕_⊕_ ; inode ; bnode ; enode ; up ; down ; vmerge )
module Web.Semantic.DL.Category.Tensor {Σ : Signature} where
_&_ : ∀ {X₁ X₂} → ABox Σ X₁ → ABox Σ X₂ → ABox Σ (X₁ ⊎ X₂)
A₁ & A₂ = (⟨ABox⟩ inj₁ A₁ , ⟨ABox⟩ inj₂ A₂)
_⊗_ : ∀ {S T : TBox Σ} → Object S T → Object S T → Object S T
A₁ ⊗ A₂ =
( (IN A₁ ⊎ IN A₂)
, ⊎-resp-Fin (fin A₁) (fin A₂)
, iface A₁ & iface A₂ )
_⟨&⟩_ : ∀ {V₁ V₂ X₁ X₂ Y₁ Y₂} →
ABox Σ (X₁ ⊕ V₁ ⊕ Y₁) → ABox Σ (X₂ ⊕ V₂ ⊕ Y₂) →
ABox Σ ((X₁ ⊎ X₂) ⊕ (V₁ ⊎ V₂) ⊕ (Y₁ ⊎ Y₂))
F₁ ⟨&⟩ F₂ = (⟨ABox⟩ up F₁ , ⟨ABox⟩ down F₂)
⊨a-intro-⟨&⟩ : ∀ {V₁ V₂ X₁ X₂ Y₁ Y₂} →
(I : Interp Σ ((X₁ ⊎ X₂) ⊕ (V₁ ⊎ V₂) ⊕ (Y₁ ⊎ Y₂))) →
(F₁ : ABox Σ (X₁ ⊕ V₁ ⊕ Y₁)) → (F₂ : ABox Σ (X₂ ⊕ V₂ ⊕ Y₂)) →
(up * I ⊨a F₁) → (down * I ⊨a F₂) → (I ⊨a F₁ ⟨&⟩ F₂)
⊨a-intro-⟨&⟩ (I , i) F₁ F₂ I₁⊨F₁ I₂⊨F₂ =
( ⟨ABox⟩-resp-⊨ up (λ x → ≈-refl I) F₁ I₁⊨F₁
, ⟨ABox⟩-resp-⊨ down (λ x → ≈-refl I) F₂ I₂⊨F₂ )
⊨b-intro-⟨&⟩ : ∀ {V₁ V₂ W₁ W₂ X₁ X₂ Y₁ Y₂} →
(I : Interp Σ ((X₁ ⊎ X₂) ⊕ (W₁ ⊎ W₂) ⊕ (Y₁ ⊎ Y₂))) →
(F₁ : ABox Σ (X₁ ⊕ V₁ ⊕ Y₁)) → (F₂ : ABox Σ (X₂ ⊕ V₂ ⊕ Y₂)) →
(up * I ⊨b F₁) → (down * I ⊨b F₂) → (I ⊨b F₁ ⟨&⟩ F₂)
⊨b-intro-⟨&⟩ {V₁} {V₂} I F₁ F₂ (f₁ , I₁⊨F₁) (f₂ , I₂⊨F₂) =
(f , I⊨F₁F₂) where
f : (V₁ ⊎ V₂) → Δ ⌊ I ⌋
f (inj₁ v) = f₁ v
f (inj₂ v) = f₂ v
I⊨F₁F₂ : bnodes I f ⊨a F₁ ⟨&⟩ F₂
I⊨F₁F₂ =
( ⟨ABox⟩-resp-⊨ up
(≡³-impl-≈ ⌊ I ⌋ (on-bnode f₁ (ind I ∘ up))
(on-bnode f (ind I) ∘ up) refl)
F₁ I₁⊨F₁
, ⟨ABox⟩-resp-⊨ down
(≡³-impl-≈ ⌊ I ⌋ (on-bnode f₂ (ind I ∘ down))
(on-bnode f (ind I) ∘ down) refl)
F₂ I₂⊨F₂ )
go₂ : ∀ {V₁ X₁ X₂ Y₁} → (I : Interp Σ (X₁ ⊎ X₂)) →
(J₁ : Interp Σ (X₁ ⊕ V₁ ⊕ Y₁)) → (⌊ I ⌋ ≲′ ⌊ J₁ ⌋) →
Interp Σ X₂
go₂ I J₁ I≲J = (⌊ J₁ ⌋ , ≲-image I≲J ∘ ind I ∘ inj₂)
go₂-≳ : ∀ {V₁ X₁ X₂ Y₁} → (I : Interp Σ (X₁ ⊎ X₂)) →
(J₁ : Interp Σ (X₁ ⊕ V₁ ⊕ Y₁)) → (I≲J : ⌊ I ⌋ ≲′ ⌊ J₁ ⌋) →
(inj₂ * I ≲ go₂ I J₁ I≲J)
go₂-≳ I (J , j₁) I≲J = (I≲J , λ x → ≈-refl J)
go₂-≲ : ∀ {V₁ V₂ X₁ X₂ Y₁ Y₂} → (I : Interp Σ (X₁ ⊎ X₂)) →
(J₁ : Interp Σ (X₁ ⊕ V₁ ⊕ Y₁)) →
(L : Interp Σ ((X₁ ⊎ X₂) ⊕ (V₁ ⊎ V₂) ⊕ (Y₁ ⊎ Y₂))) →
(I₁≲J₁ : inj₁ * I ≲ inode * J₁) → (I≲L : I ≲ inode * L) →
(Mediated (inj₁ * I) J₁ (up * L) I₁≲J₁ (inj₁ ** I≲L)) →
(go₂ I J₁ ≲⌊ I₁≲J₁ ⌋ ≲ inode * (down * L))
go₂-≲ (I , i) (J , j₁) (L , l) (I≲J , i₁≲j₁) (I≲L , i≲l)
((J≲L , j₁≲l₁) , I≲L≋I≲J≲L , J₁≲L₁-uniq) =
(J≲L , λ x → ≈-trans L (≈-sym L (I≲L≋I≲J≲L (i (inj₂ x)))) (i≲l (inj₂ x)))
par : ∀ {V₁ V₂ X₁ X₂ Y₁ Y₂} → (J₁ : Interp Σ (X₁ ⊕ V₁ ⊕ Y₁)) →
(K₂ : Interp Σ (X₂ ⊕ V₂ ⊕ Y₂)) → (⌊ J₁ ⌋ ≲′ ⌊ K₂ ⌋) →
Interp Σ ((X₁ ⊎ X₂) ⊕ (V₁ ⊎ V₂) ⊕ (Y₁ ⊎ Y₂))
par J₁ K₂ J≲K =
(⌊ K₂ ⌋ , vmerge (≲-image J≲K ∘ ind J₁) (ind K₂))
par-inj₁ : ∀ {V₁ V₂ X₁ X₂ Y₁ Y₂} → (J₁ : Interp Σ (X₁ ⊕ V₁ ⊕ Y₁)) →
(K₂ : Interp Σ (X₂ ⊕ V₂ ⊕ Y₂)) → (J≲K : ⌊ J₁ ⌋ ≲′ ⌊ K₂ ⌋) →
(J₁ ≲ up * par J₁ K₂ J≲K)
par-inj₁ (J , j₁) (K , k₂) J≲K =
( J≲K
, ≡³-impl-≈ K
(≲-image J≲K ∘ j₁)
(vmerge (≲-image J≲K ∘ j₁) k₂ ∘ up)
refl )
par-inj₂ : ∀ {V₁ V₂ X₁ X₂ Y₁ Y₂} → (J₁ : Interp Σ (X₁ ⊕ V₁ ⊕ Y₁)) →
(K₂ : Interp Σ (X₂ ⊕ V₂ ⊕ Y₂)) → (J≲K : ⌊ J₁ ⌋ ≲′ ⌊ K₂ ⌋) →
(K₂ ≲ down * par J₁ K₂ J≲K)
par-inj₂ (J , j₁) (K , k₂) J≲K =
≡³-impl-≲ (K , k₂) (vmerge (≲-image J≲K ∘ j₁) k₂ ∘ down) refl
par-exp : ∀ {V₁ V₂ X₁ X₂ Y₁ Y₂} → (J₁ : Interp Σ (X₁ ⊕ V₁ ⊕ Y₁)) →
(K₂ : Interp Σ (X₂ ⊕ V₂ ⊕ Y₂)) → (J≲K : ⌊ J₁ ⌋ ≲′ ⌊ K₂ ⌋) →
(T : TBox Σ) → (B₁ : ABox Σ Y₁) → (B₂ : ABox Σ Y₂) →
(enode * J₁ ⊨ T , B₁) → (enode * K₂ ⊨ T , B₂) →
(enode * (par J₁ K₂ J≲K) ⊨ T , (B₁ & B₂))
par-exp J₁ K₂ J≲K T B₁ B₂ (J⊨T , J₁⊨B₁) (K⊨T , K₂⊨B₂) =
( K⊨T
, ⟨ABox⟩-resp-⊨ inj₁ (λ y → ≈-refl ⌊ K₂ ⌋) B₁
(⊨a-resp-≲ (enode ** par-inj₁ J₁ K₂ J≲K) B₁ J₁⊨B₁)
, ⟨ABox⟩-resp-⊨ inj₂ (λ y → ≈-refl ⌊ K₂ ⌋) B₂ K₂⊨B₂)
par-≳ : ∀ {V₁ V₂ X₁ X₂ Y₁ Y₂} → (I : Interp Σ (X₁ ⊎ X₂)) →
(J₁ : Interp Σ (X₁ ⊕ V₁ ⊕ Y₁)) → (K₂ : Interp Σ (X₂ ⊕ V₂ ⊕ Y₂)) →
(I₁≲J₁ : inj₁ * I ≲ inode * J₁) →
(J₂≲K₂ : go₂ I J₁ ≲⌊ I₁≲J₁ ⌋ ≲ inode * K₂) →
(I ≲ inode * par J₁ K₂ ≲⌊ J₂≲K₂ ⌋)
par-≳ I J₁ K₂ (I≲J , i₁≲j₁) (J≲K , j₂≲k₂) =
( ≲-trans I≲J J≲K , lemma ) where
lemma : ∀ x → ⌊ K₂ ⌋ ⊨
≲-image J≲K (≲-image I≲J (ind I x)) ≈
vmerge (≲-image J≲K ∘ ind J₁) (ind K₂) (inode x)
lemma (inj₁ x) = ≲-resp-≈ J≲K (i₁≲j₁ x)
lemma (inj₂ x) = j₂≲k₂ x
par-impl : ∀ {V₁ V₂ X₁ X₂ Y₁ Y₂} → (J₁ : Interp Σ (X₁ ⊕ V₁ ⊕ Y₁)) →
(K₂ : Interp Σ (X₂ ⊕ V₂ ⊕ Y₂)) → (J≲K : ⌊ J₁ ⌋ ≲′ ⌊ K₂ ⌋) →
(F₁ : ABox Σ (X₁ ⊕ V₁ ⊕ Y₁)) → (F₂ : ABox Σ (X₂ ⊕ V₂ ⊕ Y₂)) →
(J₁ ⊨a F₁) → (K₂ ⊨a F₂) →
(par J₁ K₂ J≲K ⊨a F₁ ⟨&⟩ F₂)
par-impl J₁ K₂ J≲K F₁ F₂ J₁⊨F₁ K₂⊨F₂ =
( ⟨ABox⟩-resp-⊨ up (λ x → ≈-refl ⌊ K₂ ⌋) F₁
(⊨a-resp-≲ (par-inj₁ J₁ K₂ J≲K) F₁ J₁⊨F₁)
, ⟨ABox⟩-resp-⊨ down (λ x → ≈-refl ⌊ K₂ ⌋) F₂
(⊨a-resp-≲ (par-inj₂ J₁ K₂ J≲K) F₂ K₂⊨F₂) )
par-mediated : ∀ {V₁ V₂ X₁ X₂ Y₁ Y₂} → (I : Interp Σ (X₁ ⊎ X₂)) →
(J₁ : Interp Σ (X₁ ⊕ V₁ ⊕ Y₁)) → (K₂ : Interp Σ (X₂ ⊕ V₂ ⊕ Y₂)) →
(L : Interp Σ ((X₁ ⊎ X₂) ⊕ (V₁ ⊎ V₂) ⊕ (Y₁ ⊎ Y₂))) →
(I₁≲J₁ : inj₁ * I ≲ inode * J₁) → (I≲L : I ≲ inode * L) →
(J₂≲K₂ : go₂ I J₁ ≲⌊ I₁≲J₁ ⌋ ≲ inode * K₂) →
(m : Mediated (inj₁ * I) J₁ (up * L) I₁≲J₁ (inj₁ ** I≲L)) →
(Mediated (go₂ I J₁ ≲⌊ I₁≲J₁ ⌋) K₂ (down * L) J₂≲K₂ (go₂-≲ I J₁ L I₁≲J₁ I≲L m)) →
(Mediated I (par J₁ K₂ ≲⌊ J₂≲K₂ ⌋) L (par-≳ I J₁ K₂ I₁≲J₁ J₂≲K₂) I≲L)
par-mediated (I , i) (J , j₁) (K , k₂) (L , l) (I≲J , i₁≲j₁) (I≲L , i≲l) (J≲K , j₂≲k₂)
((J≲L , j₁≲l₁) , I≲L≋I≲J≲L , J₁≲L₁-uniq) ((K≲L , k₂≲l₂) , J≲L≋J≲K≲L , K₂≲L₂-uniq) =
((K≲L , k≲l) , I≲L≋I≲K≲L , K≲L-uniq) where
k = vmerge (≲-image J≲K ∘ j₁) k₂
I≲K : I ≲′ K
I≲K = ≲-trans I≲J J≲K
i≲k : ∀ x → K ⊨ ≲-image I≲K (i x) ≈ k (inode x)
i≲k = ≲-resp-ind (par-≳ (I , i) (J , j₁) (K , k₂) (I≲J , i₁≲j₁) (J≲K , j₂≲k₂))
k≲l : ∀ x → L ⊨ ≲-image K≲L (k x) ≈ l x
k≲l (inode (inj₁ x)) = ≈-trans L (≈-sym L (J≲L≋J≲K≲L (j₁ (inode x)))) (j₁≲l₁ (inode x))
k≲l (inode (inj₂ x)) = k₂≲l₂ (inode x)
k≲l (bnode (inj₁ v)) = ≈-trans L (≈-sym L (J≲L≋J≲K≲L (j₁ (bnode v)))) (j₁≲l₁ (bnode v))
k≲l (bnode (inj₂ v)) = k₂≲l₂ (bnode v)
k≲l (enode (inj₁ y)) = ≈-trans L (≈-sym L (J≲L≋J≲K≲L (j₁ (enode y)))) (j₁≲l₁ (enode y))
k≲l (enode (inj₂ y)) = k₂≲l₂ (enode y)
I≲L≋I≲K≲L : ∀ x → L ⊨ ≲-image I≲L x ≈ ≲-image K≲L (≲-image I≲K x)
I≲L≋I≲K≲L x = ≈-trans L (I≲L≋I≲J≲L x) (J≲L≋J≲K≲L (≲-image I≲J x))
lemma₁ : ∀ (K≲L : (K , k) ≲ (L , l)) x → (L ⊨ ≲-image ≲⌊ K≲L ⌋ (≲-image J≲K (j₁ x)) ≈ l (up x))
lemma₁ (K≲L' , k≲l) (inode x) = k≲l (inode (inj₁ x))
lemma₁ (K≲L' , k≲l) (bnode v) = k≲l (bnode (inj₁ v))
lemma₁ (K≲L' , k≲l) (enode y) = k≲l (enode (inj₁ y))
lemma₂ : ∀ (K≲L : (K , k) ≲ (L , l)) x → (L ⊨ ≲-image ≲⌊ K≲L ⌋ (k₂ x) ≈ l (down x))
lemma₂ (K≲L , k≲l) (inode x) = k≲l (inode (inj₂ x))
lemma₂ (K≲L , k≲l) (bnode v) = k≲l (bnode (inj₂ v))
lemma₂ (K≲L , k≲l) (enode y) = k≲l (enode (inj₂ y))
K≲L-uniq : Unique (I , i) (K , k) (L , l) (I≲K , i≲k) (I≲L , i≲l)
K≲L-uniq (K≲₁L , k≲₁l) (K≲₂L , k≲₂l) I≲L≋I≲K≲₁L I≲L≋I≲K≲₂L =
K₂≲L₂-uniq (K≲₁L , lemma₂ (K≲₁L , k≲₁l)) (K≲₂L , lemma₂ (K≲₂L , k≲₂l))
(J₁≲L₁-uniq (J≲L , j₁≲l₁) (≲-trans J≲K K≲₁L , lemma₁ (K≲₁L , k≲₁l)) I≲L≋I≲J≲L I≲L≋I≲K≲₁L)
(J₁≲L₁-uniq (J≲L , j₁≲l₁) (≲-trans J≲K K≲₂L , lemma₁ (K≲₂L , k≲₂l)) I≲L≋I≲J≲L I≲L≋I≲K≲₂L)
par-mediator : ∀ {V₁ V₂ X₁ X₂ Y₁ Y₂} → (I : Interp Σ (X₁ ⊎ X₂)) →
(J₁ : Interp Σ (X₁ ⊕ V₁ ⊕ Y₁)) → (K₂ : Interp Σ (X₂ ⊕ V₂ ⊕ Y₂)) →
(I₁≲J₁ : inj₁ * I ≲ inode * J₁) →
(J₂≲K₂ : go₂ I J₁ ≲⌊ I₁≲J₁ ⌋ ≲ inode * K₂) → (S : TBox Σ) →
(F₁ : ABox Σ (X₁ ⊕ V₁ ⊕ Y₁)) → (F₂ : ABox Σ (X₂ ⊕ V₂ ⊕ Y₂)) →
(Mediator (inj₁ * I) J₁ I₁≲J₁ (S , F₁)) →
(Mediator (go₂ I J₁ ≲⌊ I₁≲J₁ ⌋) K₂ J₂≲K₂ (S , F₂)) →
(Mediator I (par J₁ K₂ ≲⌊ J₂≲K₂ ⌋)
(par-≳ I J₁ K₂ I₁≲J₁ J₂≲K₂) (S , (F₁ ⟨&⟩ F₂)))
par-mediator I J₁ K₂ I₁≲J₁ J₂≲K₂ S F₁ F₂ J₁-med K₂-med L I≲L (L⊨S , L⊨F₁ , L⊨F₂) =
par-mediated I J₁ K₂ L I₁≲J₁ I≲L J₂≲K₂ I₁≲J₁≲L₁-med J₂≲K₂≲L₂-med where
I₁≲J₁≲L₁-med : Mediated (inj₁ * I) J₁ (up * L) I₁≲J₁ (inj₁ ** I≲L)
I₁≲J₁≲L₁-med = J₁-med (up * L) (inj₁ ** I≲L) (L⊨S , *-resp-⟨ABox⟩ up L F₁ L⊨F₁)
J₂≲K₂≲L₂-med : Mediated (go₂ I J₁ ≲⌊ I₁≲J₁ ⌋) K₂ (down * L) J₂≲K₂ (go₂-≲ I J₁ L I₁≲J₁ I≲L I₁≲J₁≲L₁-med)
J₂≲K₂≲L₂-med = K₂-med (down * L) (go₂-≲ I J₁ L I₁≲J₁ I≲L I₁≲J₁≲L₁-med) (L⊨S , *-resp-⟨ABox⟩ down L F₂ L⊨F₂)
par-init : ∀ {V₁ V₂ X₁ X₂ Y₁ Y₂} → (I : Interp Σ (X₁ ⊎ X₂)) →
(J₁ : Interp Σ (X₁ ⊕ V₁ ⊕ Y₁)) → (K₂ : Interp Σ (X₂ ⊕ V₂ ⊕ Y₂)) →
(S : TBox Σ) → (F₁ : ABox Σ (X₁ ⊕ V₁ ⊕ Y₁)) → (F₂ : ABox Σ (X₂ ⊕ V₂ ⊕ Y₂)) →
(J₁-init : J₁ ∈ Initial (inj₁ * I) (S , F₁)) →
(K₂-init : K₂ ∈ Initial (go₂ I J₁ ≲⌊ init-≲ J₁-init ⌋) (S , F₂)) →
(par J₁ K₂ ≲⌊ init-≲ K₂-init ⌋ ∈
Initial I (S , (F₁ ⟨&⟩ F₂)))
par-init I J₁ K₂ S F₁ F₂
(I₁≲J₁ , (J⊨S , J₁⊨F₁) , J₁-med) (J₂≲K₂ , (K⊨S , K₂⊨F₂) , K₂-med) =
( par-≳ I J₁ K₂ I₁≲J₁ J₂≲K₂
, (K⊨S , par-impl J₁ K₂ ≲⌊ J₂≲K₂ ⌋ F₁ F₂ J₁⊨F₁ K₂⊨F₂)
, par-mediator I J₁ K₂ I₁≲J₁ J₂≲K₂ S F₁ F₂ J₁-med K₂-med )
tensor-⊨ : ∀ {V₁ V₂ X₁ X₂ Y₁ Y₂} → (S T : TBox Σ) →
(A₁ : ABox Σ X₁) → (A₂ : ABox Σ X₂) → (B₁ : ABox Σ Y₁) → (B₂ : ABox Σ Y₂) →
(F₁ : ABox Σ (X₁ ⊕ V₁ ⊕ Y₁)) (F₂ : ABox Σ (X₂ ⊕ V₂ ⊕ Y₂)) →
(∀ I → (I ⊨ (S , T) , A₁) → (I ⊕ S , F₁ ⊨ T , B₁)) →
(∀ I → (I ⊨ (S , T) , A₂) → (I ⊕ S , F₂ ⊨ T , B₂)) →
(∀ I → (I ⊨ (S , T) , (A₁ & A₂)) →
(I ⊕ S , F₁ ⟨&⟩ F₂ ⊨ T , (B₁ & B₂)))
tensor-⊨ {V₁} {V₂} {X₁} {X₂} {Y₁} {Y₂}
S T A₁ A₂ B₁ B₂ F₁ F₂ F₁✓ F₂✓ I (I⊨ST , (I⊨A₁ , I⊨A₂)) =
( par J₁ K₂ ≲⌊ J₂≲K₂ ⌋
, par-init I J₁ K₂ S F₁ F₂ J₁-init K₂-init
, par-exp J₁ K₂ ≲⌊ J₂≲K₂ ⌋ T B₁ B₂
(ext-⊨ I₁⊕SF₁⊨TB₁) (ext-⊨ J₂⊕SF₂⊨TB₂) ) where
I₁ : Interp Σ X₁
I₁ = inj₁ * I
I₂ : Interp Σ X₂
I₂ = inj₂ * I
I₁⊨A₁ : I₁ ⊨a A₁
I₁⊨A₁ = *-resp-⟨ABox⟩ inj₁ I A₁ I⊨A₁
I₂⊨A₂ : I₂ ⊨a A₂
I₂⊨A₂ = *-resp-⟨ABox⟩ inj₂ I A₂ I⊨A₂
I₁⊕SF₁⊨TB₁ : I₁ ⊕ S , F₁ ⊨ T , B₁
I₁⊕SF₁⊨TB₁ = F₁✓ I₁ (I⊨ST , I₁⊨A₁)
J₁ : Interp Σ (X₁ ⊕ V₁ ⊕ Y₁)
J₁ = extension I₁⊕SF₁⊨TB₁
J₁-init : J₁ ∈ Initial I₁ (S , F₁)
J₁-init = ext-init I₁⊕SF₁⊨TB₁
I₁≲J₁ : I₁ ≲ inode * J₁
I₁≲J₁ = init-≲ J₁-init
J₂ : Interp Σ X₂
J₂ = go₂ I J₁ ≲⌊ I₁≲J₁ ⌋
I₂≲J₂ : I₂ ≲ J₂
I₂≲J₂ = go₂-≳ I J₁ ≲⌊ I₁≲J₁ ⌋
J⊨ST : ⌊ J₂ ⌋ ⊨t (S , T)
J⊨ST = proj₁ (ext✓ I₁⊕SF₁⊨TB₁)
J₂⊨A₂ : J₂ ⊨a A₂
J₂⊨A₂ = ⊨a-resp-≲ I₂≲J₂ A₂ I₂⊨A₂
J₂⊕SF₂⊨TB₂ : J₂ ⊕ S , F₂ ⊨ T , B₂
J₂⊕SF₂⊨TB₂ = F₂✓ J₂ (J⊨ST , J₂⊨A₂)
K₂ : Interp Σ (X₂ ⊕ V₂ ⊕ Y₂)
K₂ = extension J₂⊕SF₂⊨TB₂
K₂-init : K₂ ∈ Initial J₂ (S , F₂)
K₂-init = ext-init J₂⊕SF₂⊨TB₂
J₂≲K₂ : J₂ ≲ inode * K₂
J₂≲K₂ = init-≲ K₂-init
_⟨⊗⟩′_ : ∀ {S T : TBox Σ} {A₁ A₂ B₁ B₂ : Object S T} →
(F₁ : A₁ ⇒ B₁) → (F₂ : A₂ ⇒ B₂) →
((A₁ ⊗ A₂) ⇒ (B₁ ⊗ B₂) w/ (BN F₁ ⊎ BN F₂))
_⟨⊗⟩′_ {S} {T} {X₁ , X₁∈Fin , A₁} {X₂ , X₂∈Fin , A₂} {Y₁ , Y₁∈Fin , B₁} {Y₂ , Y₂∈Fin , B₂}
(V₁ , F₁ , F₁✓) (V₂ , F₂ , F₂✓) =
(F₁ ⟨&⟩ F₂ , tensor-⊨ S T A₁ A₂ B₁ B₂ F₁ F₂ F₁✓ F₂✓)
_⟨⊗⟩_ : ∀ {S T : TBox Σ} {A₁ A₂ B₁ B₂ : Object S T} →
(A₁ ⇒ B₁) → (A₂ ⇒ B₂) → ((A₁ ⊗ A₂) ⇒ (B₁ ⊗ B₂))
F₁ ⟨⊗⟩ F₂ = ( (BN F₁ ⊎ BN F₂) , F₁ ⟨⊗⟩′ F₂ )
|
In 2005 Hibiscus was one of three restaurants to be awarded three @-@ stars by the Egon Ronay Restaurant Guide , along with The Waterside Inn and Restaurant Tom Aikens , and was named Ronay 's Restaurant of the Year .
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
-- The Category of Elements
open import Cubical.Categories.Category
module Cubical.Categories.Constructions.Elements {ℓ ℓ'} {C : Precategory ℓ ℓ'} where
open import Cubical.Categories.Instances.Sets
open import Cubical.Categories.Functor
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
import Cubical.Categories.Morphism as Morphism
import Cubical.Categories.Constructions.Slice as Slice
-- some issues
-- * always need to specify objects during composition because can't infer isSet
open Precategory
open Functor
getIsSet : ∀ {ℓS} {C : Precategory ℓ ℓ'} (F : Functor C (SET ℓS)) → (c : C .ob) → isSet (fst (F ⟅ c ⟆))
getIsSet F c = snd (F ⟅ c ⟆)
infix 50 ∫_
∫_ : ∀ {ℓS} → Functor C (SET ℓS) → Precategory (ℓ-max ℓ ℓS) (ℓ-max ℓ' ℓS)
-- objects are (c , x) pairs where c ∈ C and x ∈ F c
(∫ F) .ob = Σ[ c ∈ C .ob ] fst (F ⟅ c ⟆)
-- morphisms are f : c → c' which take x to x'
(∫ F) .Hom[_,_] (c , x) (c' , x') = Σ[ f ∈ C [ c , c' ] ] x' ≡ (F ⟪ f ⟫) x
(∫ F) .id (c , x) = C .id c , sym (funExt⁻ (F .F-id) x ∙ refl)
(∫ F) ._⋆_ {c , x} {c₁ , x₁} {c₂ , x₂} (f , p) (g , q)
= (f ⋆⟨ C ⟩ g) , (x₂
≡⟨ q ⟩
(F ⟪ g ⟫) x₁ -- basically expanding out function composition
≡⟨ cong (F ⟪ g ⟫) p ⟩
(F ⟪ g ⟫) ((F ⟪ f ⟫) x)
≡⟨ funExt⁻ (sym (F .F-seq _ _)) _ ⟩
(F ⟪ f ⋆⟨ C ⟩ g ⟫) x
∎)
(∫ F) .⋆IdL o@{c , x} o1@{c' , x'} f'@(f , p) i
= (cIdL i) , isOfHLevel→isOfHLevelDep 1 (λ a → isS' x' ((F ⟪ a ⟫) x)) p' p cIdL i
where
isS = getIsSet F c
isS' = getIsSet F c'
cIdL = C .⋆IdL f
-- proof from composition with id
p' : x' ≡ (F ⟪ C .id c ⋆⟨ C ⟩ f ⟫) x
p' = snd ((∫ F) ._⋆_ ((∫ F) .id o) f')
(∫ F) .⋆IdR o@{c , x} o1@{c' , x'} f'@(f , p) i
= (cIdR i) , isOfHLevel→isOfHLevelDep 1 (λ a → isS' x' ((F ⟪ a ⟫) x)) p' p cIdR i
where
cIdR = C .⋆IdR f
isS' = getIsSet F c'
p' : x' ≡ (F ⟪ f ⋆⟨ C ⟩ C .id c' ⟫) x
p' = snd ((∫ F) ._⋆_ f' ((∫ F) .id o1))
(∫ F) .⋆Assoc o@{c , x} o1@{c₁ , x₁} o2@{c₂ , x₂} o3@{c₃ , x₃} f'@(f , p) g'@(g , q) h'@(h , r) i
= (cAssoc i) , isOfHLevel→isOfHLevelDep 1 (λ a → isS₃ x₃ ((F ⟪ a ⟫) x)) p1 p2 cAssoc i
where
cAssoc = C .⋆Assoc f g h
isS₃ = getIsSet F c₃
p1 : x₃ ≡ (F ⟪ (f ⋆⟨ C ⟩ g) ⋆⟨ C ⟩ h ⟫) x
p1 = snd ((∫ F) ._⋆_ ((∫ F) ._⋆_ {o} {o1} {o2} f' g') h')
p2 : x₃ ≡ (F ⟪ f ⋆⟨ C ⟩ (g ⋆⟨ C ⟩ h) ⟫) x
p2 = snd ((∫ F) ._⋆_ f' ((∫ F) ._⋆_ {o1} {o2} {o3} g' h'))
-- same thing but for presheaves
∫ᴾ_ : ∀ {ℓS} → Functor (C ^op) (SET ℓS) → Precategory (ℓ-max ℓ ℓS) (ℓ-max ℓ' ℓS)
-- objects are (c , x) pairs where c ∈ C and x ∈ F c
(∫ᴾ F) .ob = Σ[ c ∈ C .ob ] fst (F ⟅ c ⟆)
-- morphisms are f : c → c' which take x to x'
(∫ᴾ F) .Hom[_,_] (c , x) (c' , x') = Σ[ f ∈ C [ c , c' ] ] x ≡ (F ⟪ f ⟫) x'
(∫ᴾ F) .id (c , x) = C .id c , sym (funExt⁻ (F .F-id) x ∙ refl)
(∫ᴾ F) ._⋆_ {c , x} {c₁ , x₁} {c₂ , x₂} (f , p) (g , q)
= (f ⋆⟨ C ⟩ g) , (x
≡⟨ p ⟩
(F ⟪ f ⟫) x₁ -- basically expanding out function composition
≡⟨ cong (F ⟪ f ⟫) q ⟩
(F ⟪ f ⟫) ((F ⟪ g ⟫) x₂)
≡⟨ funExt⁻ (sym (F .F-seq _ _)) _ ⟩
(F ⟪ f ⋆⟨ C ⟩ g ⟫) x₂
∎)
(∫ᴾ F) .⋆IdL o@{c , x} o1@{c' , x'} f'@(f , p) i
= (cIdL i) , isOfHLevel→isOfHLevelDep 1 (λ a → isS x ((F ⟪ a ⟫) x')) p' p cIdL i
where
isS = getIsSet F c
isS' = getIsSet F c'
cIdL = C .⋆IdL f
-- proof from composition with id
p' : x ≡ (F ⟪ C .id c ⋆⟨ C ⟩ f ⟫) x'
p' = snd ((∫ᴾ F) ._⋆_ ((∫ᴾ F) .id o) f')
(∫ᴾ F) .⋆IdR o@{c , x} o1@{c' , x'} f'@(f , p) i
= (cIdR i) , isOfHLevel→isOfHLevelDep 1 (λ a → isS x ((F ⟪ a ⟫) x')) p' p cIdR i
where
cIdR = C .⋆IdR f
isS = getIsSet F c
p' : x ≡ (F ⟪ f ⋆⟨ C ⟩ C .id c' ⟫) x'
p' = snd ((∫ᴾ F) ._⋆_ f' ((∫ᴾ F) .id o1))
(∫ᴾ F) .⋆Assoc o@{c , x} o1@{c₁ , x₁} o2@{c₂ , x₂} o3@{c₃ , x₃} f'@(f , p) g'@(g , q) h'@(h , r) i
= (cAssoc i) , isOfHLevel→isOfHLevelDep 1 (λ a → isS x ((F ⟪ a ⟫) x₃)) p1 p2 cAssoc i
where
cAssoc = C .⋆Assoc f g h
isS = getIsSet F c
p1 : x ≡ (F ⟪ (f ⋆⟨ C ⟩ g) ⋆⟨ C ⟩ h ⟫) x₃
p1 = snd ((∫ᴾ F) ._⋆_ ((∫ᴾ F) ._⋆_ {o} {o1} {o2} f' g') h')
p2 : x ≡ (F ⟪ f ⋆⟨ C ⟩ (g ⋆⟨ C ⟩ h) ⟫) x₃
p2 = snd ((∫ᴾ F) ._⋆_ f' ((∫ᴾ F) ._⋆_ {o1} {o2} {o3} g' h'))
-- helpful results
module _ {ℓS} {F : Functor (C ^op) (SET ℓS)} where
-- morphisms are equal as long as the morphisms in C are equals
∫ᴾhomEq : ∀ {o1 o1' o2 o2'} (f : (∫ᴾ F) [ o1 , o2 ]) (g : (∫ᴾ F) [ o1' , o2' ])
→ (p : o1 ≡ o1') (q : o2 ≡ o2')
→ (eqInC : PathP (λ i → C [ fst (p i) , fst (q i) ]) (fst f) (fst g))
→ PathP (λ i → (∫ᴾ F) [ p i , q i ]) f g
∫ᴾhomEq (f , eqf) (g , eqg) p q eqInC
= ΣPathP (eqInC
, isOfHLevel→isOfHLevelDep 1 {A = Σ[ (o1 , o2) ∈ (∫ᴾ F) .ob × (∫ᴾ F) .ob ] (C [ fst o1 , fst o2 ])}
{B = λ ((o1 , o2) , f) → snd o1 ≡ (F ⟪ f ⟫) (snd o2)}
(λ ((o1 , o2) , f) → snd (F ⟅ (fst o1) ⟆) (snd o1) ((F ⟪ f ⟫) (snd o2)))
eqf
eqg
λ i → ((p i , q i) , eqInC i))
|
<unk> of charges in the betaine by <unk> such as lithium with greater solvation allowing more facile rotation in the betaine intermediate , lowering the amount of reversibility .
|
{-# OPTIONS --without-K --exact-split --safe #-}
open import Fragment.Algebra.Signature
module Fragment.Algebra.Homomorphism (Σ : Signature) where
open import Fragment.Algebra.Homomorphism.Base Σ public
open import Fragment.Algebra.Homomorphism.Definitions Σ public
open import Fragment.Algebra.Homomorphism.Properties Σ public
open import Fragment.Algebra.Homomorphism.Setoid Σ public
open import Fragment.Algebra.Homomorphism.Equivalence Σ public
|
(*
* Copyright 2014, NICTA
*
* This software may be distributed and modified according to the terms of
* the BSD 2-Clause license. Note that NO WARRANTY is provided.
* See "LICENSE_BSD2.txt" for details.
*
* @TAG(NICTA_BSD)
*)
theory NonDetMonadVCG
imports
NonDetMonadLemmas
"wp/WP"
"wp/WPC"
"wp/WPFix"
"Strengthen"
"../Simp_No_Conditional"
begin
(* Wrap up the standard usage pattern of wp/wpc/simp into its own command: *)
method wpsimp uses wp wp_del simp simp_del split split_del cong comb =
((determ \<open>wpfix | wp add: wp del: wp_del comb: comb| wpc |
clarsimp_no_cond simp: simp simp del: simp_del split: split split del: split_del cong: cong |
clarsimp simp: simp simp del: simp_del split: split split del: split_del cong: cong\<close>)+)[1]
declare K_def [simp]
section "Satisfiability"
text \<open>
The dual to validity: an existential instead of a universal
quantifier for the post condition. In refinement, it is
often sufficient to know that there is one state that
satisfies a condition.
\<close>
definition
exs_valid :: "('a \<Rightarrow> bool) \<Rightarrow> ('a, 'b) nondet_monad \<Rightarrow>
('b \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
("\<lbrace>_\<rbrace> _ \<exists>\<lbrace>_\<rbrace>")
where
"exs_valid P f Q \<equiv> (\<forall>s. P s \<longrightarrow> (\<exists>(rv, s') \<in> fst (f s). Q rv s'))"
text \<open>The above for the exception monad\<close>
definition
ex_exs_validE :: "('a \<Rightarrow> bool) \<Rightarrow> ('a, 'e + 'b) nondet_monad \<Rightarrow>
('b \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('e \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
("\<lbrace>_\<rbrace> _ \<exists>\<lbrace>_\<rbrace>, \<lbrace>_\<rbrace>")
where
"ex_exs_validE P f Q E \<equiv>
exs_valid P f (\<lambda>rv. case rv of Inl e \<Rightarrow> E e | Inr v \<Rightarrow> Q v)"
section "Lemmas"
subsection \<open>Determinism\<close>
lemma det_set_iff:
"det f \<Longrightarrow> (r \<in> fst (f s)) = (fst (f s) = {r})"
apply (simp add: det_def)
apply (rule iffI)
apply (erule_tac x=s in allE)
apply auto
done
lemma return_det [iff]:
"det (return x)"
by (simp add: det_def return_def)
lemma put_det [iff]:
"det (put s)"
by (simp add: det_def put_def)
lemma get_det [iff]:
"det get"
by (simp add: det_def get_def)
lemma det_gets [iff]:
"det (gets f)"
by (auto simp add: gets_def det_def get_def return_def bind_def)
lemma det_UN:
"det f \<Longrightarrow> (\<Union>x \<in> fst (f s). g x) = (g (THE x. x \<in> fst (f s)))"
unfolding det_def
apply simp
apply (drule spec [of _ s])
apply clarsimp
done
lemma bind_detI [simp, intro!]:
"\<lbrakk> det f; \<forall>x. det (g x) \<rbrakk> \<Longrightarrow> det (f >>= g)"
apply (simp add: bind_def det_def split_def)
apply clarsimp
apply (erule_tac x=s in allE)
apply clarsimp
apply (erule_tac x="a" in allE)
apply (erule_tac x="b" in allE)
apply clarsimp
done
lemma the_run_stateI:
"fst (M s) = {s'} \<Longrightarrow> the_run_state M s = s'"
by (simp add: the_run_state_def)
lemma the_run_state_det:
"\<lbrakk> s' \<in> fst (M s); det M \<rbrakk> \<Longrightarrow> the_run_state M s = s'"
by (simp add: the_run_stateI det_set_iff)
subsection "Lifting and Alternative Basic Definitions"
lemma liftE_liftM: "liftE = liftM Inr"
apply (rule ext)
apply (simp add: liftE_def liftM_def)
done
lemma liftME_liftM: "liftME f = liftM (case_sum Inl (Inr \<circ> f))"
apply (rule ext)
apply (simp add: liftME_def liftM_def bindE_def returnOk_def lift_def)
apply (rule_tac f="bind x" in arg_cong)
apply (rule ext)
apply (case_tac xa)
apply (simp_all add: lift_def throwError_def)
done
lemma liftE_bindE:
"(liftE a) >>=E b = a >>= b"
apply (simp add: liftE_def bindE_def lift_def bind_assoc)
done
lemma liftM_id[simp]: "liftM id = id"
apply (rule ext)
apply (simp add: liftM_def)
done
lemma liftM_bind:
"(liftM t f >>= g) = (f >>= (\<lambda>x. g (t x)))"
by (simp add: liftM_def bind_assoc)
lemma gets_bind_ign: "gets f >>= (\<lambda>x. m) = m"
apply (rule ext)
apply (simp add: bind_def simpler_gets_def)
done
lemma get_bind_apply: "(get >>= f) x = f x x"
by (simp add: get_def bind_def)
lemma exec_get:
"(get >>= m) s = m s s"
by (simp add: get_def bind_def)
lemma bind_eqI:
"\<lbrakk> f = f'; \<And>x. g x = g' x \<rbrakk> \<Longrightarrow> f >>= g = f' >>= g'"
apply (rule ext)
apply (simp add: bind_def)
apply (auto simp: split_def)
done
subsection "Simplification Rules for Lifted And/Or"
lemma pred_andE[elim!]: "\<lbrakk> (A and B) x; \<lbrakk> A x; B x \<rbrakk> \<Longrightarrow> R \<rbrakk> \<Longrightarrow> R"
by(simp add:pred_conj_def)
lemma pred_andI[intro!]: "\<lbrakk> A x; B x \<rbrakk> \<Longrightarrow> (A and B) x"
by(simp add:pred_conj_def)
lemma pred_conj_app[simp]: "(P and Q) x = (P x \<and> Q x)"
by(simp add:pred_conj_def)
lemma bipred_andE[elim!]: "\<lbrakk> (A And B) x y; \<lbrakk> A x y; B x y \<rbrakk> \<Longrightarrow> R \<rbrakk> \<Longrightarrow> R"
by(simp add:bipred_conj_def)
lemma bipred_andI[intro!]: "\<lbrakk> A x y; B x y \<rbrakk> \<Longrightarrow> (A And B) x y"
by (simp add:bipred_conj_def)
lemma bipred_conj_app[simp]: "(P And Q) x = (P x and Q x)"
by(simp add:pred_conj_def bipred_conj_def)
lemma pred_disjE[elim!]: "\<lbrakk> (P or Q) x; P x \<Longrightarrow> R; Q x \<Longrightarrow> R \<rbrakk> \<Longrightarrow> R"
by (fastforce simp: pred_disj_def)
lemma pred_disjI1[intro]: "P x \<Longrightarrow> (P or Q) x"
by (simp add: pred_disj_def)
lemma pred_disjI2[intro]: "Q x \<Longrightarrow> (P or Q) x"
by (simp add: pred_disj_def)
lemma pred_disj_app[simp]: "(P or Q) x = (P x \<or> Q x)"
by auto
lemma bipred_disjI1[intro]: "P x y \<Longrightarrow> (P Or Q) x y"
by (simp add: bipred_disj_def)
lemma bipred_disjI2[intro]: "Q x y \<Longrightarrow> (P Or Q) x y"
by (simp add: bipred_disj_def)
lemma bipred_disj_app[simp]: "(P Or Q) x = (P x or Q x)"
by(simp add:pred_disj_def bipred_disj_def)
lemma pred_notnotD[simp]: "(not not P) = P"
by(simp add:pred_neg_def)
lemma pred_and_true[simp]: "(P and \<top>) = P"
by(simp add:pred_conj_def)
lemma pred_and_true_var[simp]: "(\<top> and P) = P"
by(simp add:pred_conj_def)
lemma pred_and_false[simp]: "(P and \<bottom>) = \<bottom>"
by(simp add:pred_conj_def)
lemma pred_and_false_var[simp]: "(\<bottom> and P) = \<bottom>"
by(simp add:pred_conj_def)
subsection "Hoare Logic Rules"
lemma validE_def2:
"\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>R\<rbrace> \<equiv> \<forall>s. P s \<longrightarrow> (\<forall>(r,s') \<in> fst (f s). case r of Inr b \<Rightarrow> Q b s'
| Inl a \<Rightarrow> R a s')"
by (unfold valid_def validE_def)
lemma seq':
"\<lbrakk> \<lbrace>A\<rbrace> f \<lbrace>B\<rbrace>;
\<forall>x. P x \<longrightarrow> \<lbrace>C\<rbrace> g x \<lbrace>D\<rbrace>;
\<forall>x s. B x s \<longrightarrow> P x \<and> C s \<rbrakk> \<Longrightarrow>
\<lbrace>A\<rbrace> do x \<leftarrow> f; g x od \<lbrace>D\<rbrace>"
apply (clarsimp simp: valid_def bind_def)
apply fastforce
done
lemma seq:
assumes f_valid: "\<lbrace>A\<rbrace> f \<lbrace>B\<rbrace>"
assumes g_valid: "\<And>x. P x \<Longrightarrow> \<lbrace>C\<rbrace> g x \<lbrace>D\<rbrace>"
assumes bind: "\<And>x s. B x s \<Longrightarrow> P x \<and> C s"
shows "\<lbrace>A\<rbrace> do x \<leftarrow> f; g x od \<lbrace>D\<rbrace>"
apply (insert f_valid g_valid bind)
apply (blast intro: seq')
done
lemma seq_ext':
"\<lbrakk> \<lbrace>A\<rbrace> f \<lbrace>B\<rbrace>;
\<forall>x. \<lbrace>B x\<rbrace> g x \<lbrace>C\<rbrace> \<rbrakk> \<Longrightarrow>
\<lbrace>A\<rbrace> do x \<leftarrow> f; g x od \<lbrace>C\<rbrace>"
by (fastforce simp: valid_def bind_def Let_def split_def)
lemma seq_ext:
assumes f_valid: "\<lbrace>A\<rbrace> f \<lbrace>B\<rbrace>"
assumes g_valid: "\<And>x. \<lbrace>B x\<rbrace> g x \<lbrace>C\<rbrace>"
shows "\<lbrace>A\<rbrace> do x \<leftarrow> f; g x od \<lbrace>C\<rbrace>"
apply(insert f_valid g_valid)
apply(blast intro: seq_ext')
done
lemma seqE':
"\<lbrakk> \<lbrace>A\<rbrace> f \<lbrace>B\<rbrace>,\<lbrace>E\<rbrace>;
\<forall>x. \<lbrace>B x\<rbrace> g x \<lbrace>C\<rbrace>,\<lbrace>E\<rbrace> \<rbrakk> \<Longrightarrow>
\<lbrace>A\<rbrace> doE x \<leftarrow> f; g x odE \<lbrace>C\<rbrace>,\<lbrace>E\<rbrace>"
apply(simp add:bindE_def lift_def bind_def Let_def split_def)
apply(clarsimp simp:validE_def2)
apply (fastforce simp add: throwError_def return_def lift_def
split: sum.splits)
done
lemma seqE:
assumes f_valid: "\<lbrace>A\<rbrace> f \<lbrace>B\<rbrace>,\<lbrace>E\<rbrace>"
assumes g_valid: "\<And>x. \<lbrace>B x\<rbrace> g x \<lbrace>C\<rbrace>,\<lbrace>E\<rbrace>"
shows "\<lbrace>A\<rbrace> doE x \<leftarrow> f; g x odE \<lbrace>C\<rbrace>,\<lbrace>E\<rbrace>"
apply(insert f_valid g_valid)
apply(blast intro: seqE')
done
lemma hoare_TrueI: "\<lbrace>P\<rbrace> f \<lbrace>\<lambda>_. \<top>\<rbrace>"
by (simp add: valid_def)
lemma hoareE_TrueI: "\<lbrace>P\<rbrace> f \<lbrace>\<lambda>_. \<top>\<rbrace>, \<lbrace>\<lambda>r. \<top>\<rbrace>"
by (simp add: validE_def valid_def)
lemma hoare_True_E_R [simp]:
"\<lbrace>P\<rbrace> f \<lbrace>\<lambda>r s. True\<rbrace>, -"
by (auto simp add: validE_R_def validE_def valid_def split: sum.splits)
lemma hoare_post_conj [intro]:
"\<lbrakk> \<lbrace> P \<rbrace> a \<lbrace> Q \<rbrace>; \<lbrace> P \<rbrace> a \<lbrace> R \<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace> P \<rbrace> a \<lbrace> Q And R \<rbrace>"
by (fastforce simp: valid_def split_def bipred_conj_def)
lemma hoare_pre_disj [intro]:
"\<lbrakk> \<lbrace> P \<rbrace> a \<lbrace> R \<rbrace>; \<lbrace> Q \<rbrace> a \<lbrace> R \<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace> P or Q \<rbrace> a \<lbrace> R \<rbrace>"
by (simp add:valid_def pred_disj_def)
lemma hoare_conj:
"\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>; \<lbrace>P'\<rbrace> f \<lbrace>Q'\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>P and P'\<rbrace> f \<lbrace>Q And Q'\<rbrace>"
unfolding valid_def by auto
lemma hoare_post_taut: "\<lbrace> P \<rbrace> a \<lbrace> \<top>\<top> \<rbrace>"
by (simp add:valid_def)
lemma wp_post_taut: "\<lbrace>\<lambda>r. True\<rbrace> f \<lbrace>\<lambda>r s. True\<rbrace>"
by (rule hoare_post_taut)
lemma wp_post_tautE: "\<lbrace>\<lambda>r. True\<rbrace> f \<lbrace>\<lambda>r s. True\<rbrace>,\<lbrace>\<lambda>f s. True\<rbrace>"
proof -
have P: "\<And>r. (case r of Inl a \<Rightarrow> True | _ \<Rightarrow> True) = True"
by (case_tac r, simp_all)
show ?thesis
by (simp add: validE_def P wp_post_taut)
qed
lemma hoare_pre_cont [simp]: "\<lbrace> \<bottom> \<rbrace> a \<lbrace> P \<rbrace>"
by (simp add:valid_def)
subsection \<open>Strongest Postcondition Rules\<close>
lemma get_sp:
"\<lbrace>P\<rbrace> get \<lbrace>\<lambda>a s. s = a \<and> P s\<rbrace>"
by(simp add:get_def valid_def)
lemma put_sp:
"\<lbrace>\<top>\<rbrace> put a \<lbrace>\<lambda>_ s. s = a\<rbrace>"
by(simp add:put_def valid_def)
lemma return_sp:
"\<lbrace>P\<rbrace> return a \<lbrace>\<lambda>b s. b = a \<and> P s\<rbrace>"
by(simp add:return_def valid_def)
lemma assert_sp:
"\<lbrace> P \<rbrace> assert Q \<lbrace> \<lambda>r s. P s \<and> Q \<rbrace>"
by (simp add: assert_def fail_def return_def valid_def)
lemma hoare_gets_sp:
"\<lbrace>P\<rbrace> gets f \<lbrace>\<lambda>rv s. rv = f s \<and> P s\<rbrace>"
by (simp add: valid_def simpler_gets_def)
lemma hoare_return_drop_var [iff]: "\<lbrace> Q \<rbrace> return x \<lbrace> \<lambda>r. Q \<rbrace>"
by (simp add:valid_def return_def)
lemma hoare_gets [intro]: "\<lbrakk> \<And>s. P s \<Longrightarrow> Q (f s) s \<rbrakk> \<Longrightarrow> \<lbrace> P \<rbrace> gets f \<lbrace> Q \<rbrace>"
by (simp add:valid_def gets_def get_def bind_def return_def)
lemma hoare_modifyE_var:
"\<lbrakk> \<And>s. P s \<Longrightarrow> Q (f s) \<rbrakk> \<Longrightarrow> \<lbrace> P \<rbrace> modify f \<lbrace> \<lambda>r s. Q s \<rbrace>"
by(simp add: valid_def modify_def put_def get_def bind_def)
lemma hoare_if:
"\<lbrakk> P \<Longrightarrow> \<lbrace> Q \<rbrace> a \<lbrace> R \<rbrace>; \<not> P \<Longrightarrow> \<lbrace> Q \<rbrace> b \<lbrace> R \<rbrace> \<rbrakk> \<Longrightarrow>
\<lbrace> Q \<rbrace> if P then a else b \<lbrace> R \<rbrace>"
by (simp add:valid_def)
lemma hoare_pre_subst: "\<lbrakk> A = B; \<lbrace>A\<rbrace> a \<lbrace>C\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>B\<rbrace> a \<lbrace>C\<rbrace>"
by(clarsimp simp:valid_def split_def)
lemma hoare_post_subst: "\<lbrakk> B = C; \<lbrace>A\<rbrace> a \<lbrace>B\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>A\<rbrace> a \<lbrace>C\<rbrace>"
by(clarsimp simp:valid_def split_def)
lemma hoare_pre_tautI: "\<lbrakk> \<lbrace>A and P\<rbrace> a \<lbrace>B\<rbrace>; \<lbrace>A and not P\<rbrace> a \<lbrace>B\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>A\<rbrace> a \<lbrace>B\<rbrace>"
by(fastforce simp:valid_def split_def pred_conj_def pred_neg_def)
lemma hoare_pre_imp: "\<lbrakk> \<And>s. P s \<Longrightarrow> Q s; \<lbrace>Q\<rbrace> a \<lbrace>R\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> a \<lbrace>R\<rbrace>"
by (fastforce simp add:valid_def)
lemma hoare_post_imp: "\<lbrakk> \<And>r s. Q r s \<Longrightarrow> R r s; \<lbrace>P\<rbrace> a \<lbrace>Q\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> a \<lbrace>R\<rbrace>"
by(fastforce simp:valid_def split_def)
lemma hoare_post_impErr': "\<lbrakk> \<lbrace>P\<rbrace> a \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>;
\<forall>r s. Q r s \<longrightarrow> R r s;
\<forall>e s. E e s \<longrightarrow> F e s \<rbrakk> \<Longrightarrow>
\<lbrace>P\<rbrace> a \<lbrace>R\<rbrace>,\<lbrace>F\<rbrace>"
apply (simp add: validE_def)
apply (rule_tac Q="\<lambda>r s. case r of Inl a \<Rightarrow> E a s | Inr b \<Rightarrow> Q b s" in hoare_post_imp)
apply (case_tac r)
apply simp_all
done
lemma hoare_post_impErr: "\<lbrakk> \<lbrace>P\<rbrace> a \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>;
\<And>r s. Q r s \<Longrightarrow> R r s;
\<And>e s. E e s \<Longrightarrow> F e s \<rbrakk> \<Longrightarrow>
\<lbrace>P\<rbrace> a \<lbrace>R\<rbrace>,\<lbrace>F\<rbrace>"
apply (blast intro: hoare_post_impErr')
done
lemma hoare_validE_cases:
"\<lbrakk> \<lbrace> P \<rbrace> f \<lbrace> Q \<rbrace>, \<lbrace> \<lambda>_ _. True \<rbrace>; \<lbrace> P \<rbrace> f \<lbrace> \<lambda>_ _. True \<rbrace>, \<lbrace> R \<rbrace> \<rbrakk>
\<Longrightarrow> \<lbrace> P \<rbrace> f \<lbrace> Q \<rbrace>, \<lbrace> R \<rbrace>"
by (simp add: validE_def valid_def split: sum.splits) blast
lemma hoare_post_imp_dc:
"\<lbrakk>\<lbrace>P\<rbrace> a \<lbrace>\<lambda>r. Q\<rbrace>; \<And>s. Q s \<Longrightarrow> R s\<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> a \<lbrace>\<lambda>r. R\<rbrace>,\<lbrace>\<lambda>r. R\<rbrace>"
by (simp add: validE_def valid_def split: sum.splits) blast
lemma hoare_post_imp_dc2:
"\<lbrakk>\<lbrace>P\<rbrace> a \<lbrace>\<lambda>r. Q\<rbrace>; \<And>s. Q s \<Longrightarrow> R s\<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> a \<lbrace>\<lambda>r. R\<rbrace>,\<lbrace>\<lambda>r s. True\<rbrace>"
by (simp add: validE_def valid_def split: sum.splits) blast
lemma hoare_post_imp_dc2E:
"\<lbrakk>\<lbrace>P\<rbrace> a \<lbrace>\<lambda>r. Q\<rbrace>; \<And>s. Q s \<Longrightarrow> R s\<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> a \<lbrace>\<lambda>r s. True\<rbrace>, \<lbrace>\<lambda>r. R\<rbrace>"
by (simp add: validE_def valid_def split: sum.splits) fast
lemma hoare_post_imp_dc2E_actual:
"\<lbrakk>\<lbrace>P\<rbrace> a \<lbrace>\<lambda>r. R\<rbrace>\<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> a \<lbrace>\<lambda>r s. True\<rbrace>, \<lbrace>\<lambda>r. R\<rbrace>"
by (simp add: validE_def valid_def split: sum.splits) fast
lemma hoare_post_imp_dc2_actual:
"\<lbrakk>\<lbrace>P\<rbrace> a \<lbrace>\<lambda>r. R\<rbrace>\<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> a \<lbrace>\<lambda>r. R\<rbrace>, \<lbrace>\<lambda>r s. True\<rbrace>"
by (simp add: validE_def valid_def split: sum.splits) fast
lemma hoare_post_impE: "\<lbrakk> \<And>r s. Q r s \<Longrightarrow> R r s; \<lbrace>P\<rbrace> a \<lbrace>Q\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> a \<lbrace>R\<rbrace>"
by (fastforce simp:valid_def split_def)
lemma hoare_conjD1:
"\<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv. Q rv and R rv\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv. Q rv\<rbrace>"
unfolding valid_def by auto
lemma hoare_conjD2:
"\<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv. Q rv and R rv\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv. R rv\<rbrace>"
unfolding valid_def by auto
lemma hoare_post_disjI1:
"\<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv. Q rv\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv. Q rv or R rv\<rbrace>"
unfolding valid_def by auto
lemma hoare_post_disjI2:
"\<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv. R rv\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv. Q rv or R rv\<rbrace>"
unfolding valid_def by auto
lemma hoare_weaken_pre:
"\<lbrakk>\<lbrace>Q\<rbrace> a \<lbrace>R\<rbrace>; \<And>s. P s \<Longrightarrow> Q s\<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> a \<lbrace>R\<rbrace>"
apply (rule hoare_pre_imp)
prefer 2
apply assumption
apply blast
done
lemma hoare_strengthen_post:
"\<lbrakk>\<lbrace>P\<rbrace> a \<lbrace>Q\<rbrace>; \<And>r s. Q r s \<Longrightarrow> R r s\<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> a \<lbrace>R\<rbrace>"
apply (rule hoare_post_imp)
prefer 2
apply assumption
apply blast
done
lemma use_valid: "\<lbrakk>(r, s') \<in> fst (f s); \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>; P s \<rbrakk> \<Longrightarrow> Q r s'"
apply (simp add: valid_def)
apply blast
done
lemma use_validE_norm: "\<lbrakk> (Inr r', s') \<in> fst (B s); \<lbrace> P \<rbrace> B \<lbrace> Q \<rbrace>,\<lbrace> E \<rbrace>; P s \<rbrakk> \<Longrightarrow> Q r' s'"
apply (clarsimp simp: validE_def valid_def)
apply force
done
lemma use_validE_except: "\<lbrakk> (Inl r', s') \<in> fst (B s); \<lbrace> P \<rbrace> B \<lbrace> Q \<rbrace>,\<lbrace> E \<rbrace>; P s \<rbrakk> \<Longrightarrow> E r' s'"
apply (clarsimp simp: validE_def valid_def)
apply force
done
lemma in_inv_by_hoareD:
"\<lbrakk> \<And>P. \<lbrace>P\<rbrace> f \<lbrace>\<lambda>_. P\<rbrace>; (x,s') \<in> fst (f s) \<rbrakk> \<Longrightarrow> s' = s"
by (auto simp add: valid_def) blast
subsection "Satisfiability"
lemma exs_hoare_post_imp: "\<lbrakk>\<And>r s. Q r s \<Longrightarrow> R r s; \<lbrace>P\<rbrace> a \<exists>\<lbrace>Q\<rbrace>\<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> a \<exists>\<lbrace>R\<rbrace>"
apply (simp add: exs_valid_def)
apply safe
apply (erule_tac x=s in allE, simp)
apply blast
done
lemma use_exs_valid: "\<lbrakk>\<lbrace>P\<rbrace> f \<exists>\<lbrace>Q\<rbrace>; P s \<rbrakk> \<Longrightarrow> \<exists>(r, s') \<in> fst (f s). Q r s'"
by (simp add: exs_valid_def)
definition "exs_postcondition P f \<equiv> (\<lambda>a b. \<exists>(rv, s)\<in> f a b. P rv s)"
lemma exs_valid_is_triple:
"exs_valid P f Q = triple_judgement P f (exs_postcondition Q (\<lambda>s f. fst (f s)))"
by (simp add: triple_judgement_def exs_postcondition_def exs_valid_def)
lemmas [wp_trip] = exs_valid_is_triple
lemma exs_valid_weaken_pre[wp_pre]:
"\<lbrakk> \<lbrace> P' \<rbrace> f \<exists>\<lbrace> Q \<rbrace>; \<And>s. P s \<Longrightarrow> P' s \<rbrakk> \<Longrightarrow> \<lbrace> P \<rbrace> f \<exists>\<lbrace> Q \<rbrace>"
apply atomize
apply (clarsimp simp: exs_valid_def)
done
lemma exs_valid_chain:
"\<lbrakk> \<lbrace> P \<rbrace> f \<exists>\<lbrace> Q \<rbrace>; \<And>s. R s \<Longrightarrow> P s; \<And>r s. Q r s \<Longrightarrow> S r s \<rbrakk> \<Longrightarrow> \<lbrace> R \<rbrace> f \<exists>\<lbrace> S \<rbrace>"
apply atomize
apply (fastforce simp: exs_valid_def Bex_def)
done
lemma exs_valid_assume_pre:
"\<lbrakk> \<And>s. P s \<Longrightarrow> \<lbrace> P \<rbrace> f \<exists>\<lbrace> Q \<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace> P \<rbrace> f \<exists>\<lbrace> Q \<rbrace>"
apply (fastforce simp: exs_valid_def)
done
lemma exs_valid_bind [wp_split]:
"\<lbrakk> \<And>x. \<lbrace>B x\<rbrace> g x \<exists>\<lbrace>C\<rbrace>; \<lbrace>A\<rbrace> f \<exists>\<lbrace>B\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace> A \<rbrace> f >>= (\<lambda>x. g x) \<exists>\<lbrace> C \<rbrace>"
apply atomize
apply (clarsimp simp: exs_valid_def bind_def')
apply blast
done
lemma exs_valid_return [wp]:
"\<lbrace> Q v \<rbrace> return v \<exists>\<lbrace> Q \<rbrace>"
by (clarsimp simp: exs_valid_def return_def)
lemma exs_valid_select [wp]:
"\<lbrace> \<lambda>s. \<exists>r \<in> S. Q r s \<rbrace> select S \<exists>\<lbrace> Q \<rbrace>"
by (clarsimp simp: exs_valid_def select_def)
lemma exs_valid_get [wp]:
"\<lbrace> \<lambda>s. Q s s \<rbrace> get \<exists>\<lbrace> Q \<rbrace>"
by (clarsimp simp: exs_valid_def get_def)
lemma exs_valid_gets [wp]:
"\<lbrace> \<lambda>s. Q (f s) s \<rbrace> gets f \<exists>\<lbrace> Q \<rbrace>"
by (clarsimp simp: gets_def) wp
lemma exs_valid_put [wp]:
"\<lbrace> Q v \<rbrace> put v \<exists>\<lbrace> Q \<rbrace>"
by (clarsimp simp: put_def exs_valid_def)
lemma exs_valid_state_assert [wp]:
"\<lbrace> \<lambda>s. Q () s \<and> G s \<rbrace> state_assert G \<exists>\<lbrace> Q \<rbrace>"
by (clarsimp simp: state_assert_def exs_valid_def get_def
assert_def bind_def' return_def)
lemmas exs_valid_guard = exs_valid_state_assert
lemma exs_valid_fail [wp]:
"\<lbrace> \<lambda>_. False \<rbrace> fail \<exists>\<lbrace> Q \<rbrace>"
by (clarsimp simp: fail_def exs_valid_def)
lemma exs_valid_condition [wp]:
"\<lbrakk> \<lbrace> P \<rbrace> L \<exists>\<lbrace> Q \<rbrace>; \<lbrace> P' \<rbrace> R \<exists>\<lbrace> Q \<rbrace> \<rbrakk> \<Longrightarrow>
\<lbrace> \<lambda>s. (C s \<and> P s) \<or> (\<not> C s \<and> P' s) \<rbrace> condition C L R \<exists>\<lbrace> Q \<rbrace>"
by (clarsimp simp: condition_def exs_valid_def split: sum.splits)
subsection MISC
lemma hoare_return_simp:
"\<lbrace>P\<rbrace> return x \<lbrace>Q\<rbrace> = (\<forall>s. P s \<longrightarrow> Q x s)"
by (simp add: valid_def return_def)
lemma hoare_gen_asm:
"(P \<Longrightarrow> \<lbrace>P'\<rbrace> f \<lbrace>Q\<rbrace>) \<Longrightarrow> \<lbrace>P' and K P\<rbrace> f \<lbrace>Q\<rbrace>"
by (fastforce simp add: valid_def)
lemma hoare_gen_asm_lk:
"(P \<Longrightarrow> \<lbrace>P'\<rbrace> f \<lbrace>Q\<rbrace>) \<Longrightarrow> \<lbrace>K P and P'\<rbrace> f \<lbrace>Q\<rbrace>"
by (fastforce simp add: valid_def)
\<comment> \<open>Useful for forward reasoning, when P is known.
The first version allows weakening the precondition.\<close>
lemma hoare_gen_asm_spec':
"(\<And>s. P s \<Longrightarrow> S \<and> R s)
\<Longrightarrow> (S \<Longrightarrow> \<lbrace>R\<rbrace> f \<lbrace>Q\<rbrace>)
\<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>"
by (fastforce simp: valid_def)
lemma hoare_gen_asm_spec:
"(\<And>s. P s \<Longrightarrow> S)
\<Longrightarrow> (S \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>)
\<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>"
by (rule hoare_gen_asm_spec'[where S=S and R=P]) simp
lemma hoare_conjI:
"\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>; \<lbrace>P\<rbrace> f \<lbrace>R\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>r s. Q r s \<and> R r s\<rbrace>"
unfolding valid_def by blast
lemma hoare_disjI1:
"\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>r s. Q r s \<or> R r s \<rbrace>"
unfolding valid_def by blast
lemma hoare_disjI2:
"\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>R\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>r s. Q r s \<or> R r s \<rbrace>"
unfolding valid_def by blast
lemma hoare_assume_pre:
"(\<And>s. P s \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>) \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>"
by (auto simp: valid_def)
lemma hoare_returnOk_sp:
"\<lbrace>P\<rbrace> returnOk x \<lbrace>\<lambda>r s. r = x \<and> P s\<rbrace>, \<lbrace>Q\<rbrace>"
by (simp add: valid_def validE_def returnOk_def return_def)
lemma hoare_assume_preE:
"(\<And>s. P s \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>R\<rbrace>) \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>R\<rbrace>"
by (auto simp: valid_def validE_def)
lemma hoare_allI:
"(\<And>x. \<lbrace>P\<rbrace>f\<lbrace>Q x\<rbrace>) \<Longrightarrow> \<lbrace>P\<rbrace>f\<lbrace>\<lambda>r s. \<forall>x. Q x r s\<rbrace>"
by (simp add: valid_def) blast
lemma validE_allI:
"(\<And>x. \<lbrace>P\<rbrace> f \<lbrace>\<lambda>r s. Q x r s\<rbrace>,\<lbrace>E\<rbrace>) \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>r s. \<forall>x. Q x r s\<rbrace>,\<lbrace>E\<rbrace>"
by (fastforce simp: valid_def validE_def split: sum.splits)
lemma hoare_exI:
"\<lbrace>P\<rbrace> f \<lbrace>Q x\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>r s. \<exists>x. Q x r s\<rbrace>"
by (simp add: valid_def) blast
lemma hoare_impI:
"(R \<Longrightarrow> \<lbrace>P\<rbrace>f\<lbrace>Q\<rbrace>) \<Longrightarrow> \<lbrace>P\<rbrace>f\<lbrace>\<lambda>r s. R \<longrightarrow> Q r s\<rbrace>"
by (simp add: valid_def) blast
lemma validE_impI:
" \<lbrakk>\<And>E. \<lbrace>P\<rbrace> f \<lbrace>\<lambda>_ _. True\<rbrace>,\<lbrace>E\<rbrace>; (P' \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>)\<rbrakk> \<Longrightarrow>
\<lbrace>P\<rbrace> f \<lbrace>\<lambda>r s. P' \<longrightarrow> Q r s\<rbrace>, \<lbrace>E\<rbrace>"
by (fastforce simp: validE_def valid_def split: sum.splits)
lemma hoare_case_option_wp:
"\<lbrakk> \<lbrace>P\<rbrace> f None \<lbrace>Q\<rbrace>;
\<And>x. \<lbrace>P' x\<rbrace> f (Some x) \<lbrace>Q' x\<rbrace> \<rbrakk>
\<Longrightarrow> \<lbrace>case_option P P' v\<rbrace> f v \<lbrace>\<lambda>rv. case v of None \<Rightarrow> Q rv | Some x \<Rightarrow> Q' x rv\<rbrace>"
by (cases v) auto
subsection "Reasoning directly about states"
lemma in_throwError:
"((v, s') \<in> fst (throwError e s)) = (v = Inl e \<and> s' = s)"
by (simp add: throwError_def return_def)
lemma in_returnOk:
"((v', s') \<in> fst (returnOk v s)) = (v' = Inr v \<and> s' = s)"
by (simp add: returnOk_def return_def)
lemma in_bind:
"((r,s') \<in> fst ((do x \<leftarrow> f; g x od) s)) =
(\<exists>s'' x. (x, s'') \<in> fst (f s) \<and> (r, s') \<in> fst (g x s''))"
apply (simp add: bind_def split_def)
apply force
done
lemma in_bindE_R:
"((Inr r,s') \<in> fst ((doE x \<leftarrow> f; g x odE) s)) =
(\<exists>s'' x. (Inr x, s'') \<in> fst (f s) \<and> (Inr r, s') \<in> fst (g x s''))"
apply (simp add: bindE_def lift_def split_def bind_def)
apply (clarsimp simp: throwError_def return_def lift_def split: sum.splits)
apply safe
apply (case_tac a)
apply fastforce
apply fastforce
apply force
done
lemma in_bindE_L:
"((Inl r, s') \<in> fst ((doE x \<leftarrow> f; g x odE) s)) \<Longrightarrow>
(\<exists>s'' x. (Inr x, s'') \<in> fst (f s) \<and> (Inl r, s') \<in> fst (g x s'')) \<or> ((Inl r, s') \<in> fst (f s))"
apply (simp add: bindE_def lift_def bind_def)
apply safe
apply (simp add: return_def throwError_def lift_def split_def split: sum.splits if_split_asm)
apply force
done
lemma in_liftE:
"((v, s') \<in> fst (liftE f s)) = (\<exists>v'. v = Inr v' \<and> (v', s') \<in> fst (f s))"
by (force simp add: liftE_def bind_def return_def split_def)
lemma in_whenE: "((v, s') \<in> fst (whenE P f s)) = ((P \<longrightarrow> (v, s') \<in> fst (f s)) \<and>
(\<not>P \<longrightarrow> v = Inr () \<and> s' = s))"
by (simp add: whenE_def in_returnOk)
lemma inl_whenE:
"((Inl x, s') \<in> fst (whenE P f s)) = (P \<and> (Inl x, s') \<in> fst (f s))"
by (auto simp add: in_whenE)
lemma inr_in_unlessE_throwError[termination_simp]:
"(Inr (), s') \<in> fst (unlessE P (throwError E) s) = (P \<and> s'=s)"
by (simp add: unlessE_def returnOk_def throwError_def return_def)
lemma in_fail:
"r \<in> fst (fail s) = False"
by (simp add: fail_def)
lemma in_return:
"(r, s') \<in> fst (return v s) = (r = v \<and> s' = s)"
by (simp add: return_def)
lemma in_assert:
"(r, s') \<in> fst (assert P s) = (P \<and> s' = s)"
by (simp add: assert_def return_def fail_def)
lemma in_assertE:
"(r, s') \<in> fst (assertE P s) = (P \<and> r = Inr () \<and> s' = s)"
by (simp add: assertE_def returnOk_def return_def fail_def)
lemma in_assert_opt:
"(r, s') \<in> fst (assert_opt v s) = (v = Some r \<and> s' = s)"
by (auto simp: assert_opt_def in_fail in_return split: option.splits)
lemma in_get:
"(r, s') \<in> fst (get s) = (r = s \<and> s' = s)"
by (simp add: get_def)
lemma in_gets:
"(r, s') \<in> fst (gets f s) = (r = f s \<and> s' = s)"
by (simp add: simpler_gets_def)
lemma in_put:
"(r, s') \<in> fst (put x s) = (s' = x \<and> r = ())"
by (simp add: put_def)
lemma in_when:
"(v, s') \<in> fst (when P f s) = ((P \<longrightarrow> (v, s') \<in> fst (f s)) \<and> (\<not>P \<longrightarrow> v = () \<and> s' = s))"
by (simp add: when_def in_return)
lemma in_modify:
"(v, s') \<in> fst (modify f s) = (s'=f s \<and> v = ())"
by (simp add: modify_def bind_def get_def put_def)
lemma gets_the_in_monad:
"((v, s') \<in> fst (gets_the f s)) = (s' = s \<and> f s = Some v)"
by (auto simp: gets_the_def in_bind in_gets in_assert_opt split: option.split)
lemma in_alternative:
"(r,s') \<in> fst ((f \<sqinter> g) s) = ((r,s') \<in> fst (f s) \<or> (r,s') \<in> fst (g s))"
by (simp add: alternative_def)
lemmas in_monad = inl_whenE in_whenE in_liftE in_bind in_bindE_L
in_bindE_R in_returnOk in_throwError in_fail
in_assertE in_assert in_return in_assert_opt
in_get in_gets in_put in_when unlessE_whenE
unless_when in_modify gets_the_in_monad
in_alternative
subsection "Non-Failure"
lemma no_failD:
"\<lbrakk> no_fail P m; P s \<rbrakk> \<Longrightarrow> \<not>(snd (m s))"
by (simp add: no_fail_def)
lemma non_fail_modify [wp,simp]:
"no_fail \<top> (modify f)"
by (simp add: no_fail_def modify_def get_def put_def bind_def)
lemma non_fail_gets_simp[simp]:
"no_fail P (gets f)"
unfolding no_fail_def gets_def get_def return_def bind_def
by simp
lemma non_fail_gets:
"no_fail \<top> (gets f)"
by simp
lemma non_fail_select [simp]:
"no_fail \<top> (select S)"
by (simp add: no_fail_def select_def)
lemma no_fail_pre:
"\<lbrakk> no_fail P f; \<And>s. Q s \<Longrightarrow> P s\<rbrakk> \<Longrightarrow> no_fail Q f"
by (simp add: no_fail_def)
lemma no_fail_alt [wp]:
"\<lbrakk> no_fail P f; no_fail Q g \<rbrakk> \<Longrightarrow> no_fail (P and Q) (f OR g)"
by (simp add: no_fail_def alternative_def)
lemma no_fail_return [simp, wp]:
"no_fail \<top> (return x)"
by (simp add: return_def no_fail_def)
lemma no_fail_get [simp, wp]:
"no_fail \<top> get"
by (simp add: get_def no_fail_def)
lemma no_fail_put [simp, wp]:
"no_fail \<top> (put s)"
by (simp add: put_def no_fail_def)
lemma no_fail_when [wp]:
"(P \<Longrightarrow> no_fail Q f) \<Longrightarrow> no_fail (if P then Q else \<top>) (when P f)"
by (simp add: when_def)
lemma no_fail_unless [wp]:
"(\<not>P \<Longrightarrow> no_fail Q f) \<Longrightarrow> no_fail (if P then \<top> else Q) (unless P f)"
by (simp add: unless_def when_def)
lemma no_fail_fail [simp, wp]:
"no_fail \<bottom> fail"
by (simp add: fail_def no_fail_def)
lemmas [wp] = non_fail_gets
lemma no_fail_assert [simp, wp]:
"no_fail (\<lambda>_. P) (assert P)"
by (simp add: assert_def)
lemma no_fail_assert_opt [simp, wp]:
"no_fail (\<lambda>_. P \<noteq> None) (assert_opt P)"
by (simp add: assert_opt_def split: option.splits)
lemma no_fail_case_option [wp]:
assumes f: "no_fail P f"
assumes g: "\<And>x. no_fail (Q x) (g x)"
shows "no_fail (if x = None then P else Q (the x)) (case_option f g x)"
by (clarsimp simp add: f g)
lemma no_fail_if [wp]:
"\<lbrakk> P \<Longrightarrow> no_fail Q f; \<not>P \<Longrightarrow> no_fail R g \<rbrakk> \<Longrightarrow>
no_fail (if P then Q else R) (if P then f else g)"
by simp
lemma no_fail_apply [wp]:
"no_fail P (f (g x)) \<Longrightarrow> no_fail P (f $ g x)"
by simp
lemma no_fail_undefined [simp, wp]:
"no_fail \<bottom> undefined"
by (simp add: no_fail_def)
lemma no_fail_returnOK [simp, wp]:
"no_fail \<top> (returnOk x)"
by (simp add: returnOk_def)
lemma no_fail_bind [wp]:
assumes f: "no_fail P f"
assumes g: "\<And>rv. no_fail (R rv) (g rv)"
assumes v: "\<lbrace>Q\<rbrace> f \<lbrace>R\<rbrace>"
shows "no_fail (P and Q) (f >>= (\<lambda>rv. g rv))"
apply (clarsimp simp: no_fail_def bind_def)
apply (rule conjI)
prefer 2
apply (erule no_failD [OF f])
apply clarsimp
apply (drule (1) use_valid [OF _ v])
apply (drule no_failD [OF g])
apply simp
done
text \<open>Empty results implies non-failure\<close>
lemma empty_fail_modify [simp, wp]:
"empty_fail (modify f)"
by (simp add: empty_fail_def simpler_modify_def)
lemma empty_fail_gets [simp, wp]:
"empty_fail (gets f)"
by (simp add: empty_fail_def simpler_gets_def)
lemma empty_failD:
"\<lbrakk> empty_fail m; fst (m s) = {} \<rbrakk> \<Longrightarrow> snd (m s)"
by (simp add: empty_fail_def)
lemma empty_fail_select_f [simp]:
assumes ef: "fst S = {} \<Longrightarrow> snd S"
shows "empty_fail (select_f S)"
by (fastforce simp add: empty_fail_def select_f_def intro: ef)
lemma empty_fail_bind [simp]:
"\<lbrakk> empty_fail a; \<And>x. empty_fail (b x) \<rbrakk> \<Longrightarrow> empty_fail (a >>= b)"
apply (simp add: bind_def empty_fail_def split_def)
apply clarsimp
apply (case_tac "fst (a s) = {}")
apply blast
apply (clarsimp simp: ex_in_conv [symmetric])
done
lemma empty_fail_return [simp, wp]:
"empty_fail (return x)"
by (simp add: empty_fail_def return_def)
lemma empty_fail_mapM [simp]:
assumes m: "\<And>x. empty_fail (m x)"
shows "empty_fail (mapM m xs)"
proof (induct xs)
case Nil
thus ?case by (simp add: mapM_def sequence_def)
next
case Cons
have P: "\<And>m x xs. mapM m (x # xs) = (do y \<leftarrow> m x; ys \<leftarrow> (mapM m xs); return (y # ys) od)"
by (simp add: mapM_def sequence_def Let_def)
from Cons
show ?case by (simp add: P m)
qed
lemma empty_fail [simp]:
"empty_fail fail"
by (simp add: fail_def empty_fail_def)
lemma empty_fail_assert_opt [simp]:
"empty_fail (assert_opt x)"
by (simp add: assert_opt_def split: option.splits)
lemma empty_fail_mk_ef:
"empty_fail (mk_ef o m)"
by (simp add: empty_fail_def mk_ef_def)
lemma empty_fail_gets_map[simp]:
"empty_fail (gets_map f p)"
unfolding gets_map_def by simp
subsection "Failure"
lemma fail_wp: "\<lbrace>\<lambda>x. True\<rbrace> fail \<lbrace>Q\<rbrace>"
by (simp add: valid_def fail_def)
lemma failE_wp: "\<lbrace>\<lambda>x. True\<rbrace> fail \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
by (simp add: validE_def fail_wp)
lemma fail_update [iff]:
"fail (f s) = fail s"
by (simp add: fail_def)
text \<open>We can prove postconditions using hoare triples\<close>
lemma post_by_hoare: "\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>; P s; (r, s') \<in> fst (f s) \<rbrakk> \<Longrightarrow> Q r s'"
apply (simp add: valid_def)
apply blast
done
text \<open>Weakest Precondition Rules\<close>
lemma hoare_vcg_prop:
"\<lbrace>\<lambda>s. P\<rbrace> f \<lbrace>\<lambda>rv s. P\<rbrace>"
by (simp add: valid_def)
lemma return_wp:
"\<lbrace>P x\<rbrace> return x \<lbrace>P\<rbrace>"
by(simp add:valid_def return_def)
lemma get_wp:
"\<lbrace>\<lambda>s. P s s\<rbrace> get \<lbrace>P\<rbrace>"
by(simp add:valid_def split_def get_def)
lemma gets_wp:
"\<lbrace>\<lambda>s. P (f s) s\<rbrace> gets f \<lbrace>P\<rbrace>"
by(simp add:valid_def split_def gets_def return_def get_def bind_def)
lemma modify_wp:
"\<lbrace>\<lambda>s. P () (f s)\<rbrace> modify f \<lbrace>P\<rbrace>"
by(simp add:valid_def split_def modify_def get_def put_def bind_def)
lemma put_wp:
"\<lbrace>\<lambda>s. P () x\<rbrace> put x \<lbrace>P\<rbrace>"
by(simp add:valid_def put_def)
lemma returnOk_wp:
"\<lbrace>P x\<rbrace> returnOk x \<lbrace>P\<rbrace>,\<lbrace>E\<rbrace>"
by(simp add:validE_def2 returnOk_def return_def)
lemma throwError_wp:
"\<lbrace>E e\<rbrace> throwError e \<lbrace>P\<rbrace>,\<lbrace>E\<rbrace>"
by(simp add:validE_def2 throwError_def return_def)
lemma returnOKE_R_wp : "\<lbrace>P x\<rbrace> returnOk x \<lbrace>P\<rbrace>, -"
by (simp add: validE_R_def validE_def valid_def returnOk_def return_def)
lemma liftE_wp:
"\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> liftE f \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
by(clarsimp simp:valid_def validE_def2 liftE_def split_def Let_def bind_def return_def)
lemma catch_wp:
"\<lbrakk> \<And>x. \<lbrace>E x\<rbrace> handler x \<lbrace>Q\<rbrace>; \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace> \<rbrakk> \<Longrightarrow>
\<lbrace>P\<rbrace> catch f handler \<lbrace>Q\<rbrace>"
apply (unfold catch_def valid_def validE_def return_def)
apply (fastforce simp: bind_def split: sum.splits)
done
lemma handleE'_wp:
"\<lbrakk> \<And>x. \<lbrace>F x\<rbrace> handler x \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>; \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>F\<rbrace> \<rbrakk> \<Longrightarrow>
\<lbrace>P\<rbrace> f <handle2> handler \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
apply (unfold handleE'_def valid_def validE_def return_def)
apply (fastforce simp: bind_def split: sum.splits)
done
lemma handleE_wp:
assumes x: "\<And>x. \<lbrace>F x\<rbrace> handler x \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
assumes y: "\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>F\<rbrace>"
shows "\<lbrace>P\<rbrace> f <handle> handler \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
by (simp add: handleE_def handleE'_wp [OF x y])
lemma hoare_vcg_if_split:
"\<lbrakk> P \<Longrightarrow> \<lbrace>Q\<rbrace> f \<lbrace>S\<rbrace>; \<not>P \<Longrightarrow> \<lbrace>R\<rbrace> g \<lbrace>S\<rbrace> \<rbrakk> \<Longrightarrow>
\<lbrace>\<lambda>s. (P \<longrightarrow> Q s) \<and> (\<not>P \<longrightarrow> R s)\<rbrace> if P then f else g \<lbrace>S\<rbrace>"
by simp
lemma hoare_vcg_if_splitE:
"\<lbrakk> P \<Longrightarrow> \<lbrace>Q\<rbrace> f \<lbrace>S\<rbrace>,\<lbrace>E\<rbrace>; \<not>P \<Longrightarrow> \<lbrace>R\<rbrace> g \<lbrace>S\<rbrace>,\<lbrace>E\<rbrace> \<rbrakk> \<Longrightarrow>
\<lbrace>\<lambda>s. (P \<longrightarrow> Q s) \<and> (\<not>P \<longrightarrow> R s)\<rbrace> if P then f else g \<lbrace>S\<rbrace>,\<lbrace>E\<rbrace>"
by simp
lemma hoare_liftM_subst: "\<lbrace>P\<rbrace> liftM f m \<lbrace>Q\<rbrace> = \<lbrace>P\<rbrace> m \<lbrace>Q \<circ> f\<rbrace>"
apply (simp add: liftM_def bind_def return_def split_def)
apply (simp add: valid_def Ball_def)
apply (rule_tac f=All in arg_cong)
apply (rule ext)
apply fastforce
done
lemma liftE_validE[simp]: "\<lbrace>P\<rbrace> liftE f \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace> = \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>"
apply (simp add: liftE_liftM validE_def hoare_liftM_subst o_def)
done
lemma liftM_wp: "\<lbrace>P\<rbrace> m \<lbrace>Q \<circ> f\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> liftM f m \<lbrace>Q\<rbrace>"
by (simp add: hoare_liftM_subst)
lemma hoare_liftME_subst: "\<lbrace>P\<rbrace> liftME f m \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace> = \<lbrace>P\<rbrace> m \<lbrace>Q \<circ> f\<rbrace>,\<lbrace>E\<rbrace>"
apply (simp add: validE_def liftME_liftM hoare_liftM_subst o_def)
apply (rule_tac f="valid P m" in arg_cong)
apply (rule ext)+
apply (case_tac x, simp_all)
done
lemma liftME_wp: "\<lbrace>P\<rbrace> m \<lbrace>Q \<circ> f\<rbrace>,\<lbrace>E\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> liftME f m \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
by (simp add: hoare_liftME_subst)
(* FIXME: Move *)
lemma o_const_simp[simp]: "(\<lambda>x. C) \<circ> f = (\<lambda>x. C)"
by (simp add: o_def)
lemma hoare_vcg_split_case_option:
"\<lbrakk> \<And>x. x = None \<Longrightarrow> \<lbrace>P x\<rbrace> f x \<lbrace>R x\<rbrace>;
\<And>x y. x = Some y \<Longrightarrow> \<lbrace>Q x y\<rbrace> g x y \<lbrace>R x\<rbrace> \<rbrakk> \<Longrightarrow>
\<lbrace>\<lambda>s. (x = None \<longrightarrow> P x s) \<and>
(\<forall>y. x = Some y \<longrightarrow> Q x y s)\<rbrace>
case x of None \<Rightarrow> f x
| Some y \<Rightarrow> g x y
\<lbrace>R x\<rbrace>"
apply(simp add:valid_def split_def)
apply(case_tac x, simp_all)
done
lemma hoare_vcg_split_case_optionE:
assumes none_case: "\<And>x. x = None \<Longrightarrow> \<lbrace>P x\<rbrace> f x \<lbrace>R x\<rbrace>,\<lbrace>E x\<rbrace>"
assumes some_case: "\<And>x y. x = Some y \<Longrightarrow> \<lbrace>Q x y\<rbrace> g x y \<lbrace>R x\<rbrace>,\<lbrace>E x\<rbrace>"
shows "\<lbrace>\<lambda>s. (x = None \<longrightarrow> P x s) \<and>
(\<forall>y. x = Some y \<longrightarrow> Q x y s)\<rbrace>
case x of None \<Rightarrow> f x
| Some y \<Rightarrow> g x y
\<lbrace>R x\<rbrace>,\<lbrace>E x\<rbrace>"
apply(case_tac x, simp_all)
apply(rule none_case, simp)
apply(rule some_case, simp)
done
lemma hoare_vcg_split_case_sum:
"\<lbrakk> \<And>x a. x = Inl a \<Longrightarrow> \<lbrace>P x a\<rbrace> f x a \<lbrace>R x\<rbrace>;
\<And>x b. x = Inr b \<Longrightarrow> \<lbrace>Q x b\<rbrace> g x b \<lbrace>R x\<rbrace> \<rbrakk> \<Longrightarrow>
\<lbrace>\<lambda>s. (\<forall>a. x = Inl a \<longrightarrow> P x a s) \<and>
(\<forall>b. x = Inr b \<longrightarrow> Q x b s) \<rbrace>
case x of Inl a \<Rightarrow> f x a
| Inr b \<Rightarrow> g x b
\<lbrace>R x\<rbrace>"
apply(simp add:valid_def split_def)
apply(case_tac x, simp_all)
done
lemma hoare_vcg_split_case_sumE:
assumes left_case: "\<And>x a. x = Inl a \<Longrightarrow> \<lbrace>P x a\<rbrace> f x a \<lbrace>R x\<rbrace>"
assumes right_case: "\<And>x b. x = Inr b \<Longrightarrow> \<lbrace>Q x b\<rbrace> g x b \<lbrace>R x\<rbrace>"
shows "\<lbrace>\<lambda>s. (\<forall>a. x = Inl a \<longrightarrow> P x a s) \<and>
(\<forall>b. x = Inr b \<longrightarrow> Q x b s) \<rbrace>
case x of Inl a \<Rightarrow> f x a
| Inr b \<Rightarrow> g x b
\<lbrace>R x\<rbrace>"
apply(case_tac x, simp_all)
apply(rule left_case, simp)
apply(rule right_case, simp)
done
lemma hoare_vcg_precond_imp:
"\<lbrakk> \<lbrace>Q\<rbrace> f \<lbrace>R\<rbrace>; \<And>s. P s \<Longrightarrow> Q s \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>R\<rbrace>"
by (fastforce simp add:valid_def)
lemma hoare_vcg_precond_impE:
"\<lbrakk> \<lbrace>Q\<rbrace> f \<lbrace>R\<rbrace>,\<lbrace>E\<rbrace>; \<And>s. P s \<Longrightarrow> Q s \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>R\<rbrace>,\<lbrace>E\<rbrace>"
by (fastforce simp add:validE_def2)
lemma hoare_seq_ext:
assumes g_valid: "\<And>x. \<lbrace>B x\<rbrace> g x \<lbrace>C\<rbrace>"
assumes f_valid: "\<lbrace>A\<rbrace> f \<lbrace>B\<rbrace>"
shows "\<lbrace>A\<rbrace> do x \<leftarrow> f; g x od \<lbrace>C\<rbrace>"
apply(insert f_valid g_valid)
apply(blast intro: seq_ext')
done
lemma hoare_vcg_seqE:
assumes g_valid: "\<And>x. \<lbrace>B x\<rbrace> g x \<lbrace>C\<rbrace>,\<lbrace>E\<rbrace>"
assumes f_valid: "\<lbrace>A\<rbrace> f \<lbrace>B\<rbrace>,\<lbrace>E\<rbrace>"
shows "\<lbrace>A\<rbrace> doE x \<leftarrow> f; g x odE \<lbrace>C\<rbrace>,\<lbrace>E\<rbrace>"
apply(insert f_valid g_valid)
apply(blast intro: seqE')
done
lemma hoare_seq_ext_nobind:
"\<lbrakk> \<lbrace>B\<rbrace> g \<lbrace>C\<rbrace>;
\<lbrace>A\<rbrace> f \<lbrace>\<lambda>r s. B s\<rbrace> \<rbrakk> \<Longrightarrow>
\<lbrace>A\<rbrace> do f; g od \<lbrace>C\<rbrace>"
apply (clarsimp simp: valid_def bind_def Let_def split_def)
apply fastforce
done
lemma hoare_seq_ext_nobindE:
"\<lbrakk> \<lbrace>B\<rbrace> g \<lbrace>C\<rbrace>,\<lbrace>E\<rbrace>;
\<lbrace>A\<rbrace> f \<lbrace>\<lambda>r s. B s\<rbrace>,\<lbrace>E\<rbrace> \<rbrakk> \<Longrightarrow>
\<lbrace>A\<rbrace> doE f; g odE \<lbrace>C\<rbrace>,\<lbrace>E\<rbrace>"
apply (clarsimp simp:validE_def)
apply (simp add:bindE_def Let_def split_def bind_def lift_def)
apply (fastforce simp add: valid_def throwError_def return_def lift_def
split: sum.splits)
done
lemma hoare_chain:
"\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>;
\<And>s. R s \<Longrightarrow> P s;
\<And>r s. Q r s \<Longrightarrow> S r s \<rbrakk> \<Longrightarrow>
\<lbrace>R\<rbrace> f \<lbrace>S\<rbrace>"
by(fastforce simp add:valid_def split_def)
lemma validE_weaken:
"\<lbrakk> \<lbrace>P'\<rbrace> A \<lbrace>Q'\<rbrace>,\<lbrace>E'\<rbrace>; \<And>s. P s \<Longrightarrow> P' s; \<And>r s. Q' r s \<Longrightarrow> Q r s; \<And>r s. E' r s \<Longrightarrow> E r s \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> A \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
by (fastforce simp: validE_def2 split: sum.splits)
lemmas hoare_chainE = validE_weaken
lemma hoare_vcg_handle_elseE:
"\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>;
\<And>e. \<lbrace>E e\<rbrace> g e \<lbrace>R\<rbrace>,\<lbrace>F\<rbrace>;
\<And>x. \<lbrace>Q x\<rbrace> h x \<lbrace>R\<rbrace>,\<lbrace>F\<rbrace> \<rbrakk> \<Longrightarrow>
\<lbrace>P\<rbrace> f <handle> g <else> h \<lbrace>R\<rbrace>,\<lbrace>F\<rbrace>"
apply (simp add: handle_elseE_def validE_def)
apply (rule seq_ext)
apply assumption
apply (case_tac x, simp_all)
done
lemma alternative_valid:
assumes x: "\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>"
assumes y: "\<lbrace>P\<rbrace> f' \<lbrace>Q\<rbrace>"
shows "\<lbrace>P\<rbrace> f OR f' \<lbrace>Q\<rbrace>"
apply (simp add: valid_def alternative_def)
apply safe
apply (simp add: post_by_hoare [OF x])
apply (simp add: post_by_hoare [OF y])
done
lemma alternative_wp:
assumes x: "\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>"
assumes y: "\<lbrace>P'\<rbrace> f' \<lbrace>Q\<rbrace>"
shows "\<lbrace>P and P'\<rbrace> f OR f' \<lbrace>Q\<rbrace>"
apply (rule alternative_valid)
apply (rule hoare_pre_imp [OF _ x], simp)
apply (rule hoare_pre_imp [OF _ y], simp)
done
lemma alternativeE_wp:
assumes x: "\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>" and y: "\<lbrace>P'\<rbrace> f' \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
shows "\<lbrace>P and P'\<rbrace> f OR f' \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
apply (unfold validE_def)
apply (wp add: x y alternative_wp | simp | fold validE_def)+
done
lemma alternativeE_R_wp:
"\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,-; \<lbrace>P'\<rbrace> f' \<lbrace>Q\<rbrace>,- \<rbrakk> \<Longrightarrow> \<lbrace>P and P'\<rbrace> f OR f' \<lbrace>Q\<rbrace>,-"
apply (simp add: validE_R_def)
apply (rule alternativeE_wp)
apply assumption+
done
lemma alternative_R_wp:
"\<lbrakk> \<lbrace>P\<rbrace> f -,\<lbrace>Q\<rbrace>; \<lbrace>P'\<rbrace> g -,\<lbrace>Q\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>P and P'\<rbrace> f \<sqinter> g -, \<lbrace>Q\<rbrace>"
by (fastforce simp: alternative_def validE_E_def validE_def valid_def)
lemma select_wp: "\<lbrace>\<lambda>s. \<forall>x \<in> S. Q x s\<rbrace> select S \<lbrace>Q\<rbrace>"
by (simp add: select_def valid_def)
lemma select_f_wp:
"\<lbrace>\<lambda>s. \<forall>x\<in>fst S. Q x s\<rbrace> select_f S \<lbrace>Q\<rbrace>"
by (simp add: select_f_def valid_def)
lemma state_select_wp [wp]: "\<lbrace> \<lambda>s. \<forall>t. (s, t) \<in> f \<longrightarrow> P () t \<rbrace> state_select f \<lbrace> P \<rbrace>"
apply (clarsimp simp: state_select_def)
apply (clarsimp simp: valid_def)
done
lemma condition_wp [wp]:
"\<lbrakk> \<lbrace> Q \<rbrace> A \<lbrace> P \<rbrace>; \<lbrace> R \<rbrace> B \<lbrace> P \<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace> \<lambda>s. if C s then Q s else R s \<rbrace> condition C A B \<lbrace> P \<rbrace>"
apply (clarsimp simp: condition_def)
apply (clarsimp simp: valid_def pred_conj_def pred_neg_def split_def)
done
lemma conditionE_wp [wp]:
"\<lbrakk> \<lbrace> P \<rbrace> A \<lbrace> Q \<rbrace>,\<lbrace> R \<rbrace>; \<lbrace> P' \<rbrace> B \<lbrace> Q \<rbrace>,\<lbrace> R \<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace> \<lambda>s. if C s then P s else P' s \<rbrace> condition C A B \<lbrace>Q\<rbrace>,\<lbrace>R\<rbrace>"
apply (clarsimp simp: condition_def)
apply (clarsimp simp: validE_def valid_def)
done
lemma state_assert_wp [wp]: "\<lbrace> \<lambda>s. f s \<longrightarrow> P () s \<rbrace> state_assert f \<lbrace> P \<rbrace>"
apply (clarsimp simp: state_assert_def get_def
assert_def bind_def valid_def return_def fail_def)
done
text \<open>The weakest precondition handler which works on conjunction\<close>
lemma hoare_vcg_conj_lift:
assumes x: "\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>"
assumes y: "\<lbrace>P'\<rbrace> f \<lbrace>Q'\<rbrace>"
shows "\<lbrace>\<lambda>s. P s \<and> P' s\<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<and> Q' rv s\<rbrace>"
apply (subst bipred_conj_def[symmetric], rule hoare_post_conj)
apply (rule hoare_pre_imp [OF _ x], simp)
apply (rule hoare_pre_imp [OF _ y], simp)
done
lemma hoare_vcg_conj_liftE1:
"\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,-; \<lbrace>P'\<rbrace> f \<lbrace>Q'\<rbrace>,\<lbrace>E\<rbrace> \<rbrakk> \<Longrightarrow>
\<lbrace>P and P'\<rbrace> f \<lbrace>\<lambda>r s. Q r s \<and> Q' r s\<rbrace>,\<lbrace>E\<rbrace>"
unfolding valid_def validE_R_def validE_def
apply (clarsimp simp: split_def split: sum.splits)
apply (erule allE, erule (1) impE)
apply (erule allE, erule (1) impE)
apply (drule (1) bspec)
apply (drule (1) bspec)
apply clarsimp
done
lemma hoare_vcg_disj_lift:
assumes x: "\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>"
assumes y: "\<lbrace>P'\<rbrace> f \<lbrace>Q'\<rbrace>"
shows "\<lbrace>\<lambda>s. P s \<or> P' s\<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<or> Q' rv s\<rbrace>"
apply (simp add: valid_def)
apply safe
apply (erule(1) post_by_hoare [OF x])
apply (erule notE)
apply (erule(1) post_by_hoare [OF y])
done
lemma hoare_vcg_const_Ball_lift:
"\<lbrakk> \<And>x. x \<in> S \<Longrightarrow> \<lbrace>P x\<rbrace> f \<lbrace>Q x\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. \<forall>x\<in>S. P x s\<rbrace> f \<lbrace>\<lambda>rv s. \<forall>x\<in>S. Q x rv s\<rbrace>"
by (fastforce simp: valid_def)
lemma hoare_vcg_const_Ball_lift_R:
"\<lbrakk> \<And>x. x \<in> S \<Longrightarrow> \<lbrace>P x\<rbrace> f \<lbrace>Q x\<rbrace>,- \<rbrakk> \<Longrightarrow>
\<lbrace>\<lambda>s. \<forall>x \<in> S. P x s\<rbrace> f \<lbrace>\<lambda>rv s. \<forall>x \<in> S. Q x rv s\<rbrace>,-"
apply (simp add: validE_R_def validE_def)
apply (rule hoare_strengthen_post)
apply (erule hoare_vcg_const_Ball_lift)
apply (simp split: sum.splits)
done
lemma hoare_vcg_all_lift:
"\<lbrakk> \<And>x. \<lbrace>P x\<rbrace> f \<lbrace>Q x\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. \<forall>x. P x s\<rbrace> f \<lbrace>\<lambda>rv s. \<forall>x. Q x rv s\<rbrace>"
by (fastforce simp: valid_def)
lemma hoare_vcg_all_lift_R:
"(\<And>x. \<lbrace>P x\<rbrace> f \<lbrace>Q x\<rbrace>, -) \<Longrightarrow> \<lbrace>\<lambda>s. \<forall>x. P x s\<rbrace> f \<lbrace>\<lambda>rv s. \<forall>x. Q x rv s\<rbrace>, -"
by (rule hoare_vcg_const_Ball_lift_R[where S=UNIV, simplified])
lemma hoare_vcg_imp_lift:
"\<lbrakk> \<lbrace>P'\<rbrace> f \<lbrace>\<lambda>rv s. \<not> P rv s\<rbrace>; \<lbrace>Q'\<rbrace> f \<lbrace>Q\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. P' s \<or> Q' s\<rbrace> f \<lbrace>\<lambda>rv s. P rv s \<longrightarrow> Q rv s\<rbrace>"
apply (simp only: imp_conv_disj)
apply (erule(1) hoare_vcg_disj_lift)
done
lemma hoare_vcg_imp_lift':
"\<lbrakk> \<lbrace>P'\<rbrace> f \<lbrace>\<lambda>rv s. \<not> P rv s\<rbrace>; \<lbrace>Q'\<rbrace> f \<lbrace>Q\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. \<not> P' s \<longrightarrow> Q' s\<rbrace> f \<lbrace>\<lambda>rv s. P rv s \<longrightarrow> Q rv s\<rbrace>"
apply (simp only: imp_conv_disj)
apply simp
apply (erule (1) hoare_vcg_imp_lift)
done
lemma hoare_vcg_imp_conj_lift[wp_comb]:
"\<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<longrightarrow> Q' rv s\<rbrace> \<Longrightarrow> \<lbrace>P'\<rbrace> f \<lbrace>\<lambda>rv s. (Q rv s \<longrightarrow> Q'' rv s) \<and> Q''' rv s\<rbrace>
\<Longrightarrow> \<lbrace>P and P'\<rbrace> f \<lbrace>\<lambda>rv s. (Q rv s \<longrightarrow> Q' rv s \<and> Q'' rv s) \<and> Q''' rv s\<rbrace>"
by (auto simp: valid_def)
lemmas hoare_vcg_imp_conj_lift'[wp_unsafe] = hoare_vcg_imp_conj_lift[where Q'''="\<top>\<top>", simplified]
lemma hoare_absorb_imp:
"\<lbrace> P \<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<and> R rv s \<rbrace> \<Longrightarrow> \<lbrace> P \<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<longrightarrow> R rv s \<rbrace>"
by (erule hoare_post_imp[rotated], blast)
lemma hoare_weaken_imp:
"\<lbrakk> \<And>rv s. Q rv s \<Longrightarrow> Q' rv s ; \<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv s. Q' rv s \<longrightarrow> R rv s\<rbrace> \<rbrakk>
\<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<longrightarrow> R rv s\<rbrace>"
by (clarsimp simp: NonDetMonad.valid_def split_def)
lemma hoare_vcg_const_imp_lift:
"\<lbrakk> P \<Longrightarrow> \<lbrace>Q\<rbrace> m \<lbrace>R\<rbrace> \<rbrakk> \<Longrightarrow>
\<lbrace>\<lambda>s. P \<longrightarrow> Q s\<rbrace> m \<lbrace>\<lambda>rv s. P \<longrightarrow> R rv s\<rbrace>"
by (cases P, simp_all add: hoare_vcg_prop)
lemma hoare_vcg_const_imp_lift_R:
"(P \<Longrightarrow> \<lbrace>Q\<rbrace> m \<lbrace>R\<rbrace>,-) \<Longrightarrow> \<lbrace>\<lambda>s. P \<longrightarrow> Q s\<rbrace> m \<lbrace>\<lambda>rv s. P \<longrightarrow> R rv s\<rbrace>,-"
by (fastforce simp: validE_R_def validE_def valid_def split_def split: sum.splits)
lemma hoare_weak_lift_imp:
"\<lbrace>P'\<rbrace> f \<lbrace>Q\<rbrace> \<Longrightarrow> \<lbrace>\<lambda>s. P \<longrightarrow> P' s\<rbrace> f \<lbrace>\<lambda>rv s. P \<longrightarrow> Q rv s\<rbrace>"
by (auto simp add: valid_def split_def)
lemma hoare_vcg_weaken_imp:
"\<lbrakk> \<And>rv s. Q rv s \<Longrightarrow> Q' rv s ; \<lbrace> P \<rbrace> f \<lbrace>\<lambda>rv s. Q' rv s \<longrightarrow> R rv s\<rbrace> \<rbrakk>
\<Longrightarrow> \<lbrace> P \<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<longrightarrow> R rv s\<rbrace>"
by (clarsimp simp: valid_def split_def)
lemma hoare_vcg_ex_lift:
"\<lbrakk> \<And>x. \<lbrace>P x\<rbrace> f \<lbrace>Q x\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. \<exists>x. P x s\<rbrace> f \<lbrace>\<lambda>rv s. \<exists>x. Q x rv s\<rbrace>"
by (clarsimp simp: valid_def, blast)
lemma hoare_vcg_ex_lift_R1:
"(\<And>x. \<lbrace>P x\<rbrace> f \<lbrace>Q\<rbrace>, -) \<Longrightarrow> \<lbrace>\<lambda>s. \<exists>x. P x s\<rbrace> f \<lbrace>Q\<rbrace>, -"
by (fastforce simp: valid_def validE_R_def validE_def split: sum.splits)
lemma hoare_liftP_ext:
assumes "\<And>P x. m \<lbrace>\<lambda>s. P (f s x)\<rbrace>"
shows "m \<lbrace>\<lambda>s. P (f s)\<rbrace>"
unfolding valid_def
apply clarsimp
apply (erule rsubst[where P=P])
apply (rule ext)
apply (drule use_valid, rule assms, rule refl)
apply simp
done
(* for instantiations *)
lemma hoare_triv: "\<lbrace>P\<rbrace>f\<lbrace>Q\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace>f\<lbrace>Q\<rbrace>" .
lemma hoare_trivE: "\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>" .
lemma hoare_trivE_R: "\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,- \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,-" .
lemma hoare_trivR_R: "\<lbrace>P\<rbrace> f -,\<lbrace>E\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f -,\<lbrace>E\<rbrace>" .
lemma hoare_weaken_preE_E:
"\<lbrakk> \<lbrace>P'\<rbrace> f -,\<lbrace>Q\<rbrace>; \<And>s. P s \<Longrightarrow> P' s \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f -,\<lbrace>Q\<rbrace>"
by (fastforce simp add: validE_E_def validE_def valid_def)
lemma hoare_vcg_E_conj:
"\<lbrakk> \<lbrace>P\<rbrace> f -,\<lbrace>E\<rbrace>; \<lbrace>P'\<rbrace> f \<lbrace>Q'\<rbrace>,\<lbrace>E'\<rbrace> \<rbrakk>
\<Longrightarrow> \<lbrace>\<lambda>s. P s \<and> P' s\<rbrace> f \<lbrace>Q'\<rbrace>, \<lbrace>\<lambda>rv s. E rv s \<and> E' rv s\<rbrace>"
apply (unfold validE_def validE_E_def)
apply (rule hoare_post_imp [OF _ hoare_vcg_conj_lift], simp_all)
apply (case_tac r, simp_all)
done
lemma hoare_vcg_E_elim:
"\<lbrakk> \<lbrace>P\<rbrace> f -,\<lbrace>E\<rbrace>; \<lbrace>P'\<rbrace> f \<lbrace>Q\<rbrace>,- \<rbrakk>
\<Longrightarrow> \<lbrace>\<lambda>s. P s \<and> P' s\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
by (rule hoare_post_impErr [OF hoare_vcg_E_conj],
(simp add: validE_R_def)+)
lemma hoare_vcg_R_conj:
"\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,-; \<lbrace>P'\<rbrace> f \<lbrace>Q'\<rbrace>,- \<rbrakk>
\<Longrightarrow> \<lbrace>\<lambda>s. P s \<and> P' s\<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<and> Q' rv s\<rbrace>,-"
apply (unfold validE_R_def validE_def)
apply (rule hoare_post_imp [OF _ hoare_vcg_conj_lift], simp_all)
apply (case_tac r, simp_all)
done
lemma valid_validE:
"\<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv. Q\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv. Q\<rbrace>,\<lbrace>\<lambda>rv. Q\<rbrace>"
apply (simp add: validE_def)
done
lemma valid_validE2:
"\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>_. Q'\<rbrace>; \<And>s. Q' s \<Longrightarrow> Q s; \<And>s. Q' s \<Longrightarrow> E s \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>_. Q\<rbrace>,\<lbrace>\<lambda>_. E\<rbrace>"
unfolding valid_def validE_def
by (clarsimp split: sum.splits) blast
lemma validE_valid: "\<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv. Q\<rbrace>,\<lbrace>\<lambda>rv. Q\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv. Q\<rbrace>"
apply (unfold validE_def)
apply (rule hoare_post_imp)
defer
apply assumption
apply (case_tac r, simp_all)
done
lemma valid_validE_R:
"\<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv. Q\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv. Q\<rbrace>,-"
by (simp add: validE_R_def hoare_post_impErr [OF valid_validE])
lemma valid_validE_E:
"\<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv. Q\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f -,\<lbrace>\<lambda>rv. Q\<rbrace>"
by (simp add: validE_E_def hoare_post_impErr [OF valid_validE])
lemma validE_validE_R: "\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>\<top>\<top>\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,-"
by (simp add: validE_R_def)
lemma validE_R_validE: "\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,- \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>\<top>\<top>\<rbrace>"
by (simp add: validE_R_def)
lemma validE_validE_E: "\<lbrace>P\<rbrace> f \<lbrace>\<top>\<top>\<rbrace>,\<lbrace>E\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f -,\<lbrace>E\<rbrace>"
by (simp add: validE_E_def)
lemma validE_E_validE: "\<lbrace>P\<rbrace> f -,\<lbrace>E\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<top>\<top>\<rbrace>,\<lbrace>E\<rbrace>"
by (simp add: validE_E_def)
lemma hoare_post_imp_R: "\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>Q'\<rbrace>,-; \<And>r s. Q' r s \<Longrightarrow> Q r s \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,-"
apply (unfold validE_R_def)
apply (erule hoare_post_impErr, simp+)
done
lemma hoare_post_imp_E: "\<lbrakk> \<lbrace>P\<rbrace> f -,\<lbrace>Q'\<rbrace>; \<And>r s. Q' r s \<Longrightarrow> Q r s \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f -,\<lbrace>Q\<rbrace>"
apply (unfold validE_E_def)
apply (erule hoare_post_impErr, simp+)
done
lemma hoare_post_comb_imp_conj:
"\<lbrakk> \<lbrace>P'\<rbrace> f \<lbrace>Q\<rbrace>; \<lbrace>P\<rbrace> f \<lbrace>Q'\<rbrace>; \<And>s. P s \<Longrightarrow> P' s \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<and> Q' rv s\<rbrace>"
apply (rule hoare_pre_imp)
defer
apply (rule hoare_vcg_conj_lift)
apply assumption+
apply simp
done
lemma hoare_vcg_precond_impE_R: "\<lbrakk> \<lbrace>P'\<rbrace> f \<lbrace>Q\<rbrace>,-; \<And>s. P s \<Longrightarrow> P' s \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,-"
by (unfold validE_R_def, rule hoare_vcg_precond_impE, simp+)
lemma valid_is_triple:
"valid P f Q = triple_judgement P f (postcondition Q (\<lambda>s f. fst (f s)))"
by (simp add: triple_judgement_def valid_def postcondition_def)
lemma validE_is_triple:
"validE P f Q E = triple_judgement P f
(postconditions (postcondition Q (\<lambda>s f. {(rv, s'). (Inr rv, s') \<in> fst (f s)}))
(postcondition E (\<lambda>s f. {(rv, s'). (Inl rv, s') \<in> fst (f s)})))"
apply (simp add: validE_def triple_judgement_def valid_def postcondition_def
postconditions_def split_def split: sum.split)
apply fastforce
done
lemma validE_R_is_triple:
"validE_R P f Q = triple_judgement P f
(postcondition Q (\<lambda>s f. {(rv, s'). (Inr rv, s') \<in> fst (f s)}))"
by (simp add: validE_R_def validE_is_triple postconditions_def postcondition_def)
lemma validE_E_is_triple:
"validE_E P f E = triple_judgement P f
(postcondition E (\<lambda>s f. {(rv, s'). (Inl rv, s') \<in> fst (f s)}))"
by (simp add: validE_E_def validE_is_triple postconditions_def postcondition_def)
lemmas hoare_wp_combs = hoare_vcg_conj_lift
lemmas hoare_wp_combsE =
validE_validE_R
hoare_vcg_R_conj
hoare_vcg_E_elim
hoare_vcg_E_conj
lemmas hoare_wp_state_combsE =
valid_validE_R
hoare_vcg_R_conj[OF valid_validE_R]
hoare_vcg_E_elim[OF valid_validE_E]
hoare_vcg_E_conj[OF valid_validE_E]
lemmas hoare_classic_wp_combs
= hoare_post_comb_imp_conj hoare_vcg_precond_imp hoare_wp_combs
lemmas hoare_classic_wp_combsE
= hoare_vcg_precond_impE hoare_vcg_precond_impE_R hoare_wp_combsE
lemmas hoare_classic_wp_state_combsE
= hoare_vcg_precond_impE[OF valid_validE]
hoare_vcg_precond_impE_R[OF valid_validE_R] hoare_wp_state_combsE
lemmas all_classic_wp_combs =
hoare_classic_wp_state_combsE hoare_classic_wp_combsE hoare_classic_wp_combs
lemmas hoare_wp_splits [wp_split] =
hoare_seq_ext hoare_vcg_seqE handleE'_wp handleE_wp
validE_validE_R [OF hoare_vcg_seqE [OF validE_R_validE]]
validE_validE_R [OF handleE'_wp [OF validE_R_validE]]
validE_validE_R [OF handleE_wp [OF validE_R_validE]]
catch_wp hoare_vcg_if_split hoare_vcg_if_splitE
validE_validE_R [OF hoare_vcg_if_splitE [OF validE_R_validE validE_R_validE]]
liftM_wp liftME_wp
validE_validE_R [OF liftME_wp [OF validE_R_validE]]
validE_valid
lemmas [wp_comb] = hoare_wp_state_combsE hoare_wp_combsE hoare_wp_combs
lemmas [wp] = hoare_vcg_prop
wp_post_taut
return_wp
put_wp
get_wp
gets_wp
modify_wp
returnOk_wp
throwError_wp
fail_wp
failE_wp
liftE_wp
select_f_wp
lemmas [wp_trip] = valid_is_triple validE_is_triple validE_E_is_triple validE_R_is_triple
lemmas validE_E_combs[wp_comb] =
hoare_vcg_E_conj[where Q'="\<top>\<top>", folded validE_E_def]
valid_validE_E
hoare_vcg_E_conj[where Q'="\<top>\<top>", folded validE_E_def, OF valid_validE_E]
text \<open>Simplifications on conjunction\<close>
lemma hoare_post_eq: "\<lbrakk> Q = Q'; \<lbrace>P\<rbrace> f \<lbrace>Q'\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>"
by simp
lemma hoare_post_eqE1: "\<lbrakk> Q = Q'; \<lbrace>P\<rbrace> f \<lbrace>Q'\<rbrace>,\<lbrace>E\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
by simp
lemma hoare_post_eqE2: "\<lbrakk> E = E'; \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>E'\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
by simp
lemma hoare_post_eqE_R: "\<lbrakk> Q = Q'; \<lbrace>P\<rbrace> f \<lbrace>Q'\<rbrace>,- \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,-"
by simp
lemma pred_conj_apply_elim: "(\<lambda>r. Q r and Q' r) = (\<lambda>r s. Q r s \<and> Q' r s)"
by (simp add: pred_conj_def)
lemma pred_conj_conj_elim: "(\<lambda>r s. (Q r and Q' r) s \<and> Q'' r s) = (\<lambda>r s. Q r s \<and> Q' r s \<and> Q'' r s)"
by simp
lemma conj_assoc_apply: "(\<lambda>r s. (Q r s \<and> Q' r s) \<and> Q'' r s) = (\<lambda>r s. Q r s \<and> Q' r s \<and> Q'' r s)"
by simp
lemma all_elim: "(\<lambda>rv s. \<forall>x. P rv s) = P"
by simp
lemma all_conj_elim: "(\<lambda>rv s. (\<forall>x. P rv s) \<and> Q rv s) = (\<lambda>rv s. P rv s \<and> Q rv s)"
by simp
lemmas vcg_rhs_simps = pred_conj_apply_elim pred_conj_conj_elim
conj_assoc_apply all_elim all_conj_elim
lemma if_apply_reduct: "\<lbrace>P\<rbrace> If P' (f x) (g x) \<lbrace>Q\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> If P' f g x \<lbrace>Q\<rbrace>"
by (cases P', simp_all)
lemma if_apply_reductE: "\<lbrace>P\<rbrace> If P' (f x) (g x) \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> If P' f g x \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
by (cases P', simp_all)
lemma if_apply_reductE_R: "\<lbrace>P\<rbrace> If P' (f x) (g x) \<lbrace>Q\<rbrace>,- \<Longrightarrow> \<lbrace>P\<rbrace> If P' f g x \<lbrace>Q\<rbrace>,-"
by (cases P', simp_all)
lemmas hoare_wp_simps [wp_split] =
vcg_rhs_simps [THEN hoare_post_eq] vcg_rhs_simps [THEN hoare_post_eqE1]
vcg_rhs_simps [THEN hoare_post_eqE2] vcg_rhs_simps [THEN hoare_post_eqE_R]
if_apply_reduct if_apply_reductE if_apply_reductE_R TrueI
schematic_goal if_apply_test: "\<lbrace>?Q\<rbrace> (if A then returnOk else K fail) x \<lbrace>P\<rbrace>,\<lbrace>E\<rbrace>"
by wpsimp
lemma hoare_elim_pred_conj:
"\<lbrace>P\<rbrace> f \<lbrace>\<lambda>r s. Q r s \<and> Q' r s\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>r. Q r and Q' r\<rbrace>"
by (unfold pred_conj_def)
lemma hoare_elim_pred_conjE1:
"\<lbrace>P\<rbrace> f \<lbrace>\<lambda>r s. Q r s \<and> Q' r s\<rbrace>,\<lbrace>E\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>r. Q r and Q' r\<rbrace>,\<lbrace>E\<rbrace>"
by (unfold pred_conj_def)
lemma hoare_elim_pred_conjE2:
"\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>, \<lbrace>\<lambda>x s. E x s \<and> E' x s\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>\<lambda>x. E x and E' x\<rbrace>"
by (unfold pred_conj_def)
lemma hoare_elim_pred_conjE_R:
"\<lbrace>P\<rbrace> f \<lbrace>\<lambda>r s. Q r s \<and> Q' r s\<rbrace>,- \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>r. Q r and Q' r\<rbrace>,-"
by (unfold pred_conj_def)
lemmas hoare_wp_pred_conj_elims =
hoare_elim_pred_conj hoare_elim_pred_conjE1
hoare_elim_pred_conjE2 hoare_elim_pred_conjE_R
lemmas hoare_weaken_preE = hoare_vcg_precond_impE
lemmas hoare_pre [wp_pre] =
hoare_weaken_pre
hoare_weaken_preE
hoare_vcg_precond_impE_R
hoare_weaken_preE_E
declare no_fail_pre [wp_pre]
bundle no_pre = hoare_pre [wp_pre del] no_fail_pre [wp_pre del]
bundle classic_wp_pre = hoare_pre [wp_pre del] no_fail_pre [wp_pre del]
all_classic_wp_combs[wp_comb del] all_classic_wp_combs[wp_comb]
text \<open>Miscellaneous lemmas on hoare triples\<close>
lemma hoare_vcg_mp:
assumes a: "\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>"
assumes b: "\<lbrace>P\<rbrace> f \<lbrace>\<lambda>r s. Q r s \<longrightarrow> Q' r s\<rbrace>"
shows "\<lbrace>P\<rbrace> f \<lbrace>Q'\<rbrace>"
using assms
by (auto simp: valid_def split_def)
(* note about this precond stuff: rules get a chance to bind directly
before any of their combined forms. As a result, these precondition
implication rules are only used when needed. *)
lemma hoare_add_post:
assumes r: "\<lbrace>P'\<rbrace> f \<lbrace>Q'\<rbrace>"
assumes impP: "\<And>s. P s \<Longrightarrow> P' s"
assumes impQ: "\<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv s. Q' rv s \<longrightarrow> Q rv s\<rbrace>"
shows "\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>"
apply (rule hoare_chain)
apply (rule hoare_vcg_conj_lift)
apply (rule r)
apply (rule impQ)
apply simp
apply (erule impP)
apply simp
done
lemma hoare_gen_asmE:
"(P \<Longrightarrow> \<lbrace>P'\<rbrace> f \<lbrace>Q\<rbrace>,-) \<Longrightarrow> \<lbrace>P' and K P\<rbrace> f \<lbrace>Q\<rbrace>, -"
by (simp add: validE_R_def validE_def valid_def) blast
lemma hoare_list_case:
assumes P1: "\<lbrace>P1\<rbrace> f f1 \<lbrace>Q\<rbrace>"
assumes P2: "\<And>y ys. xs = y#ys \<Longrightarrow> \<lbrace>P2 y ys\<rbrace> f (f2 y ys) \<lbrace>Q\<rbrace>"
shows "\<lbrace>case xs of [] \<Rightarrow> P1 | y#ys \<Rightarrow> P2 y ys\<rbrace>
f (case xs of [] \<Rightarrow> f1 | y#ys \<Rightarrow> f2 y ys)
\<lbrace>Q\<rbrace>"
apply (cases xs; simp)
apply (rule P1)
apply (rule P2)
apply simp
done
lemma hoare_when_wp [wp_split]:
"\<lbrakk> P \<Longrightarrow> \<lbrace>Q\<rbrace> f \<lbrace>R\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>if P then Q else R ()\<rbrace> when P f \<lbrace>R\<rbrace>"
by (clarsimp simp: when_def valid_def return_def)
lemma hoare_unless_wp[wp_split]:
"(\<not>P \<Longrightarrow> \<lbrace>Q\<rbrace> f \<lbrace>R\<rbrace>) \<Longrightarrow> \<lbrace>if P then R () else Q\<rbrace> unless P f \<lbrace>R\<rbrace>"
unfolding unless_def by wp auto
lemma hoare_whenE_wp:
"(P \<Longrightarrow> \<lbrace>Q\<rbrace> f \<lbrace>R\<rbrace>, \<lbrace>E\<rbrace>) \<Longrightarrow> \<lbrace>if P then Q else R ()\<rbrace> whenE P f \<lbrace>R\<rbrace>, \<lbrace>E\<rbrace>"
unfolding whenE_def by clarsimp wp
lemmas hoare_whenE_wps[wp_split]
= hoare_whenE_wp hoare_whenE_wp[THEN validE_validE_R] hoare_whenE_wp[THEN validE_validE_E]
lemma hoare_unlessE_wp:
"(\<not> P \<Longrightarrow> \<lbrace>Q\<rbrace> f \<lbrace>R\<rbrace>, \<lbrace>E\<rbrace>) \<Longrightarrow> \<lbrace>if P then R () else Q\<rbrace> unlessE P f \<lbrace>R\<rbrace>, \<lbrace>E\<rbrace>"
unfolding unlessE_def by wp auto
lemmas hoare_unlessE_wps[wp_split]
= hoare_unlessE_wp hoare_unlessE_wp[THEN validE_validE_R] hoare_unlessE_wp[THEN validE_validE_E]
lemma hoare_use_eq:
assumes x: "\<And>P. \<lbrace>\<lambda>s. P (f s)\<rbrace> m \<lbrace>\<lambda>rv s. P (f s)\<rbrace>"
assumes y: "\<And>f. \<lbrace>\<lambda>s. P f s\<rbrace> m \<lbrace>\<lambda>rv s. Q f s\<rbrace>"
shows "\<lbrace>\<lambda>s. P (f s) s\<rbrace> m \<lbrace>\<lambda>rv s. Q (f s :: 'c :: type) s \<rbrace>"
apply (rule_tac Q="\<lambda>rv s. \<exists>f'. f' = f s \<and> Q f' s" in hoare_post_imp)
apply simp
apply (wpsimp wp: hoare_vcg_ex_lift x y)
done
lemma hoare_return_sp:
"\<lbrace>P\<rbrace> return x \<lbrace>\<lambda>r. P and K (r = x)\<rbrace>"
by (simp add: valid_def return_def)
lemma hoare_fail_any [simp]:
"\<lbrace>P\<rbrace> fail \<lbrace>Q\<rbrace>" by wp
lemma hoare_failE [simp]: "\<lbrace>P\<rbrace> fail \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>" by wp
lemma hoare_FalseE [simp]:
"\<lbrace>\<lambda>s. False\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
by (simp add: valid_def validE_def)
lemma hoare_K_bind [wp_split]:
"\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> K_bind f x \<lbrace>Q\<rbrace>"
by simp
lemma validE_K_bind [wp_split]:
"\<lbrace> P \<rbrace> x \<lbrace> Q \<rbrace>, \<lbrace> E \<rbrace> \<Longrightarrow> \<lbrace> P \<rbrace> K_bind x f \<lbrace> Q \<rbrace>, \<lbrace> E \<rbrace>"
by simp
text \<open>Setting up the precondition case splitter.\<close>
lemma wpc_helper_valid:
"\<lbrace>Q\<rbrace> g \<lbrace>S\<rbrace> \<Longrightarrow> wpc_helper (P, P') (Q, Q') \<lbrace>P\<rbrace> g \<lbrace>S\<rbrace>"
by (clarsimp simp: wpc_helper_def elim!: hoare_pre)
lemma wpc_helper_validE:
"\<lbrace>Q\<rbrace> f \<lbrace>R\<rbrace>,\<lbrace>E\<rbrace> \<Longrightarrow> wpc_helper (P, P') (Q, Q') \<lbrace>P\<rbrace> f \<lbrace>R\<rbrace>,\<lbrace>E\<rbrace>"
by (clarsimp simp: wpc_helper_def elim!: hoare_pre)
lemma wpc_helper_validE_R:
"\<lbrace>Q\<rbrace> f \<lbrace>R\<rbrace>,- \<Longrightarrow> wpc_helper (P, P') (Q, Q') \<lbrace>P\<rbrace> f \<lbrace>R\<rbrace>,-"
by (clarsimp simp: wpc_helper_def elim!: hoare_pre)
lemma wpc_helper_validR_R:
"\<lbrace>Q\<rbrace> f -,\<lbrace>E\<rbrace> \<Longrightarrow> wpc_helper (P, P') (Q, Q') \<lbrace>P\<rbrace> f -,\<lbrace>E\<rbrace>"
by (clarsimp simp: wpc_helper_def elim!: hoare_pre)
lemma wpc_helper_no_fail_final:
"no_fail Q f \<Longrightarrow> wpc_helper (P, P') (Q, Q') (no_fail P f)"
by (clarsimp simp: wpc_helper_def elim!: no_fail_pre)
lemma wpc_helper_empty_fail_final:
"empty_fail f \<Longrightarrow> wpc_helper (P, P') (Q, Q') (empty_fail f)"
by (clarsimp simp: wpc_helper_def)
lemma wpc_helper_validNF:
"\<lbrace>Q\<rbrace> g \<lbrace>S\<rbrace>! \<Longrightarrow> wpc_helper (P, P') (Q, Q') \<lbrace>P\<rbrace> g \<lbrace>S\<rbrace>!"
apply (clarsimp simp: wpc_helper_def)
by (metis hoare_vcg_precond_imp no_fail_pre validNF_def)
wpc_setup "\<lambda>m. \<lbrace>P\<rbrace> m \<lbrace>Q\<rbrace>" wpc_helper_valid
wpc_setup "\<lambda>m. \<lbrace>P\<rbrace> m \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>" wpc_helper_validE
wpc_setup "\<lambda>m. \<lbrace>P\<rbrace> m \<lbrace>Q\<rbrace>,-" wpc_helper_validE_R
wpc_setup "\<lambda>m. \<lbrace>P\<rbrace> m -,\<lbrace>E\<rbrace>" wpc_helper_validR_R
wpc_setup "\<lambda>m. no_fail P m" wpc_helper_no_fail_final
wpc_setup "\<lambda>m. empty_fail m" wpc_helper_empty_fail_final
wpc_setup "\<lambda>m. \<lbrace>P\<rbrace> m \<lbrace>Q\<rbrace>!" wpc_helper_validNF
lemma in_liftM:
"((r, s') \<in> fst (liftM t f s)) = (\<exists>r'. (r', s') \<in> fst (f s) \<and> r = t r')"
apply (simp add: liftM_def return_def bind_def)
apply (simp add: Bex_def)
done
(* FIXME: eliminate *)
lemmas handy_liftM_lemma = in_liftM
lemma hoare_fun_app_wp[wp]:
"\<lbrace>P\<rbrace> f' x \<lbrace>Q'\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f' $ x \<lbrace>Q'\<rbrace>"
"\<lbrace>P\<rbrace> f x \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f $ x \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
"\<lbrace>P\<rbrace> f x \<lbrace>Q\<rbrace>,- \<Longrightarrow> \<lbrace>P\<rbrace> f $ x \<lbrace>Q\<rbrace>,-"
"\<lbrace>P\<rbrace> f x -,\<lbrace>E\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f $ x -,\<lbrace>E\<rbrace>"
by simp+
lemma hoare_validE_pred_conj:
"\<lbrakk> \<lbrace>P\<rbrace>f\<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>; \<lbrace>P\<rbrace>f\<lbrace>R\<rbrace>,\<lbrace>E\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace>f\<lbrace>Q And R\<rbrace>,\<lbrace>E\<rbrace>"
unfolding valid_def validE_def by (simp add: split_def split: sum.splits)
lemma hoare_validE_conj:
"\<lbrakk> \<lbrace>P\<rbrace>f\<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>; \<lbrace>P\<rbrace>f\<lbrace>R\<rbrace>,\<lbrace>E\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>r s. Q r s \<and> R r s\<rbrace>,\<lbrace>E\<rbrace>"
unfolding valid_def validE_def by (simp add: split_def split: sum.splits)
lemmas hoare_valid_validE = valid_validE
lemma liftE_validE_E [wp]:
"\<lbrace>\<top>\<rbrace> liftE f -, \<lbrace>Q\<rbrace>"
by (clarsimp simp: validE_E_def valid_def)
declare validE_validE_E[wp_comb]
(*
* if_validE_E:
*
* \<lbrakk>?P1 \<Longrightarrow> \<lbrace>?Q1\<rbrace> ?f1 -, \<lbrace>?E\<rbrace>; \<not> ?P1 \<Longrightarrow> \<lbrace>?R1\<rbrace> ?g1 -, \<lbrace>?E\<rbrace>\<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. (?P1 \<longrightarrow> ?Q1 s) \<and> (\<not> ?P1 \<longrightarrow> ?R1 s)\<rbrace> if ?P1 then ?f1 else ?g1 -, \<lbrace>?E\<rbrace>
*)
lemmas if_validE_E [wp_split] =
validE_validE_E [OF hoare_vcg_if_splitE [OF validE_E_validE validE_E_validE]]
lemma returnOk_E [wp]:
"\<lbrace>\<top>\<rbrace> returnOk r -, \<lbrace>Q\<rbrace>"
by (simp add: validE_E_def) wp
lemma hoare_drop_imp:
"\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>r s. R r s \<longrightarrow> Q r s\<rbrace>"
by (auto simp: valid_def)
lemma hoare_drop_impE:
"\<lbrakk>\<lbrace>P\<rbrace> f \<lbrace>\<lambda>r. Q\<rbrace>, \<lbrace>E\<rbrace>\<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>r s. R r s \<longrightarrow> Q s\<rbrace>, \<lbrace>E\<rbrace>"
by (simp add: validE_weaken)
lemma hoare_drop_impE_R:
"\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,- \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>r s. R r s \<longrightarrow> Q r s\<rbrace>, -"
by (auto simp: validE_R_def validE_def valid_def split_def split: sum.splits)
lemma hoare_drop_impE_E:
"\<lbrace>P\<rbrace> f -,\<lbrace>Q\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f -,\<lbrace>\<lambda>r s. R r s \<longrightarrow> Q r s\<rbrace>"
by (auto simp: validE_E_def validE_def valid_def split_def split: sum.splits)
lemmas hoare_drop_imps = hoare_drop_imp hoare_drop_impE_R hoare_drop_impE_E
(*This is unsafe, but can be very useful when supplied as a comb rule.*)
lemma hoare_drop_imp_conj[wp_unsafe]:
"\<lbrace>P\<rbrace> f \<lbrace>Q'\<rbrace> \<Longrightarrow> \<lbrace>P'\<rbrace> f \<lbrace>\<lambda>rv s. (Q rv s \<longrightarrow> Q'' rv s) \<and> Q''' rv s\<rbrace>
\<Longrightarrow> \<lbrace>P and P'\<rbrace> f \<lbrace>\<lambda>rv s. (Q rv s \<longrightarrow> Q' rv s \<and> Q'' rv s) \<and> Q''' rv s\<rbrace>"
by (auto simp: valid_def)
lemmas hoare_drop_imp_conj'[wp_unsafe] = hoare_drop_imp_conj[where Q'''="\<top>\<top>", simplified]
lemma bind_det_exec:
"fst (a s) = {(r,s')} \<Longrightarrow> fst ((a >>= b) s) = fst (b r s')"
by (simp add: bind_def)
lemma in_bind_det_exec:
"fst (a s) = {(r,s')} \<Longrightarrow> (s'' \<in> fst ((a >>= b) s)) = (s'' \<in> fst (b r s'))"
by (simp add: bind_def)
lemma exec_put:
"(put s' >>= m) s = m () s'"
by (simp add: bind_def put_def)
lemma bind_execI:
"\<lbrakk> (r'',s'') \<in> fst (f s); \<exists>x \<in> fst (g r'' s''). P x \<rbrakk> \<Longrightarrow>
\<exists>x \<in> fst ((f >>= g) s). P x"
by (force simp: in_bind split_def bind_def)
lemma True_E_E [wp]: "\<lbrace>\<top>\<rbrace> f -,\<lbrace>\<top>\<top>\<rbrace>"
by (auto simp: validE_E_def validE_def valid_def split: sum.splits)
(*
* \<lbrakk>\<And>x. \<lbrace>?B1 x\<rbrace> ?g1 x -, \<lbrace>?E\<rbrace>; \<lbrace>?P\<rbrace> ?f1 \<lbrace>?B1\<rbrace>, \<lbrace>?E\<rbrace>\<rbrakk> \<Longrightarrow> \<lbrace>?P\<rbrace> ?f1 >>=E ?g1 -, \<lbrace>?E\<rbrace>
*)
lemmas [wp_split] =
validE_validE_E [OF hoare_vcg_seqE [OF validE_E_validE]]
lemma case_option_wp:
assumes x: "\<And>x. \<lbrace>P x\<rbrace> m x \<lbrace>Q\<rbrace>"
assumes y: "\<lbrace>P'\<rbrace> m' \<lbrace>Q\<rbrace>"
shows "\<lbrace>\<lambda>s. (x = None \<longrightarrow> P' s) \<and> (x \<noteq> None \<longrightarrow> P (the x) s)\<rbrace>
case_option m' m x \<lbrace>Q\<rbrace>"
apply (cases x; simp)
apply (rule y)
apply (rule x)
done
lemma case_option_wpE:
assumes x: "\<And>x. \<lbrace>P x\<rbrace> m x \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
assumes y: "\<lbrace>P'\<rbrace> m' \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
shows "\<lbrace>\<lambda>s. (x = None \<longrightarrow> P' s) \<and> (x \<noteq> None \<longrightarrow> P (the x) s)\<rbrace>
case_option m' m x \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
apply (cases x; simp)
apply (rule y)
apply (rule x)
done
lemma in_bindE:
"(rv, s') \<in> fst ((f >>=E (\<lambda>rv'. g rv')) s) =
((\<exists>ex. rv = Inl ex \<and> (Inl ex, s') \<in> fst (f s)) \<or>
(\<exists>rv' s''. (rv, s') \<in> fst (g rv' s'') \<and> (Inr rv', s'') \<in> fst (f s)))"
apply (rule iffI)
apply (clarsimp simp: bindE_def bind_def)
apply (case_tac a)
apply (clarsimp simp: lift_def throwError_def return_def)
apply (clarsimp simp: lift_def)
apply safe
apply (clarsimp simp: bindE_def bind_def)
apply (erule rev_bexI)
apply (simp add: lift_def throwError_def return_def)
apply (clarsimp simp: bindE_def bind_def)
apply (erule rev_bexI)
apply (simp add: lift_def)
done
(*
* \<lbrace>?P\<rbrace> ?m1 -, \<lbrace>?E\<rbrace> \<Longrightarrow> \<lbrace>?P\<rbrace> liftME ?f1 ?m1 -, \<lbrace>?E\<rbrace>
*)
lemmas [wp_split] = validE_validE_E [OF liftME_wp, simplified, OF validE_E_validE]
lemma assert_A_True[simp]: "assert True = return ()"
by (simp add: assert_def)
lemma assert_wp [wp]: "\<lbrace>\<lambda>s. P \<longrightarrow> Q () s\<rbrace> assert P \<lbrace>Q\<rbrace>"
by (cases P, (simp add: assert_def | wp)+)
lemma list_cases_wp:
assumes a: "\<lbrace>P_A\<rbrace> a \<lbrace>Q\<rbrace>"
assumes b: "\<And>x xs. ts = x#xs \<Longrightarrow> \<lbrace>P_B x xs\<rbrace> b x xs \<lbrace>Q\<rbrace>"
shows "\<lbrace>case_list P_A P_B ts\<rbrace> case ts of [] \<Rightarrow> a | x # xs \<Rightarrow> b x xs \<lbrace>Q\<rbrace>"
by (cases ts, auto simp: a b)
(* FIXME: make wp *)
lemma whenE_throwError_wp:
"\<lbrace>\<lambda>s. \<not>Q \<longrightarrow> P s\<rbrace> whenE Q (throwError e) \<lbrace>\<lambda>rv. P\<rbrace>, -"
unfolding whenE_def by wpsimp
lemma select_throwError_wp:
"\<lbrace>\<lambda>s. \<forall>x\<in>S. Q x s\<rbrace> select S >>= throwError -, \<lbrace>Q\<rbrace>"
by (simp add: bind_def throwError_def return_def select_def validE_E_def
validE_def valid_def)
lemma assert_opt_wp[wp]:
"\<lbrace>\<lambda>s. x \<noteq> None \<longrightarrow> Q (the x) s\<rbrace> assert_opt x \<lbrace>Q\<rbrace>"
by (case_tac x, (simp add: assert_opt_def | wp)+)
lemma gets_the_wp[wp]:
"\<lbrace>\<lambda>s. (f s \<noteq> None) \<longrightarrow> Q (the (f s)) s\<rbrace> gets_the f \<lbrace>Q\<rbrace>"
by (unfold gets_the_def, wp)
lemma gets_the_wp':
"\<lbrace>\<lambda>s. \<forall>rv. f s = Some rv \<longrightarrow> Q rv s\<rbrace> gets_the f \<lbrace>Q\<rbrace>"
unfolding gets_the_def by wpsimp
lemma gets_map_wp:
"\<lbrace>\<lambda>s. f s p \<noteq> None \<longrightarrow> Q (the (f s p)) s\<rbrace> gets_map f p \<lbrace>Q\<rbrace>"
unfolding gets_map_def by wpsimp
lemma gets_map_wp'[wp]:
"\<lbrace>\<lambda>s. \<forall>rv. f s p = Some rv \<longrightarrow> Q rv s\<rbrace> gets_map f p \<lbrace>Q\<rbrace>"
unfolding gets_map_def by wpsimp
lemma no_fail_gets_map[wp]:
"no_fail (\<lambda>s. f s p \<noteq> None) (gets_map f p)"
unfolding gets_map_def by wpsimp
lemma hoare_vcg_set_pred_lift:
assumes "\<And>P x. m \<lbrace> \<lambda>s. P (f x s) \<rbrace>"
shows "m \<lbrace> \<lambda>s. P {x. f x s} \<rbrace>"
using assms[where P="\<lambda>x . x"] assms[where P=Not] use_valid
by (fastforce simp: valid_def elim!: rsubst[where P=P])
lemma hoare_vcg_set_pred_lift_mono:
assumes f: "\<And>x. m \<lbrace> f x \<rbrace>"
assumes mono: "\<And>A B. A \<subseteq> B \<Longrightarrow> P A \<Longrightarrow> P B"
shows "m \<lbrace> \<lambda>s. P {x. f x s} \<rbrace>"
by (fastforce simp: valid_def elim!: mono[rotated] dest: use_valid[OF _ f])
section "validNF Rules"
subsection "Basic validNF theorems"
lemma validNF [intro?]:
"\<lbrakk> \<lbrace> P \<rbrace> f \<lbrace> Q \<rbrace>; no_fail P f \<rbrakk> \<Longrightarrow> \<lbrace> P \<rbrace> f \<lbrace> Q \<rbrace>!"
by (clarsimp simp: validNF_def)
lemma validNF_valid: "\<lbrakk> \<lbrace> P \<rbrace> f \<lbrace> Q \<rbrace>! \<rbrakk> \<Longrightarrow> \<lbrace> P \<rbrace> f \<lbrace> Q \<rbrace>"
by (clarsimp simp: validNF_def)
lemma validNF_no_fail: "\<lbrakk> \<lbrace> P \<rbrace> f \<lbrace> Q \<rbrace>! \<rbrakk> \<Longrightarrow> no_fail P f"
by (clarsimp simp: validNF_def)
lemma snd_validNF:
"\<lbrakk> \<lbrace> P \<rbrace> f \<lbrace> Q \<rbrace>!; P s \<rbrakk> \<Longrightarrow> \<not> snd (f s)"
by (clarsimp simp: validNF_def no_fail_def)
lemma use_validNF:
"\<lbrakk> (r', s') \<in> fst (f s); \<lbrace> P \<rbrace> f \<lbrace> Q \<rbrace>!; P s \<rbrakk> \<Longrightarrow> Q r' s'"
by (fastforce simp: validNF_def valid_def)
subsection "validNF weakest pre-condition rules"
lemma validNF_return [wp]:
"\<lbrace> P x \<rbrace> return x \<lbrace> P \<rbrace>!"
by (wp validNF)+
lemma validNF_get [wp]:
"\<lbrace> \<lambda>s. P s s \<rbrace> get \<lbrace> P \<rbrace>!"
by (wp validNF)+
lemma validNF_put [wp]:
"\<lbrace> \<lambda>s. P () x \<rbrace> put x \<lbrace> P \<rbrace>!"
by (wp validNF)+
lemma validNF_K_bind [wp]:
"\<lbrace> P \<rbrace> x \<lbrace> Q \<rbrace>! \<Longrightarrow> \<lbrace> P \<rbrace> K_bind x f \<lbrace> Q \<rbrace>!"
by simp
lemma validNF_fail [wp]:
"\<lbrace> \<lambda>s. False \<rbrace> fail \<lbrace> Q \<rbrace>!"
by (clarsimp simp: validNF_def fail_def no_fail_def)
lemma validNF_prop [wp_unsafe]:
"\<lbrakk> no_fail (\<lambda>s. P) f \<rbrakk> \<Longrightarrow> \<lbrace> \<lambda>s. P \<rbrace> f \<lbrace> \<lambda>rv s. P \<rbrace>!"
by (wp validNF)+
lemma validNF_post_conj [intro!]:
"\<lbrakk> \<lbrace> P \<rbrace> a \<lbrace> Q \<rbrace>!; \<lbrace> P \<rbrace> a \<lbrace> R \<rbrace>! \<rbrakk> \<Longrightarrow> \<lbrace> P \<rbrace> a \<lbrace> Q And R \<rbrace>!"
by (auto simp: validNF_def)
lemma no_fail_or:
"\<lbrakk>no_fail P a; no_fail Q a\<rbrakk> \<Longrightarrow> no_fail (P or Q) a"
by (clarsimp simp: no_fail_def)
lemma validNF_pre_disj [intro!]:
"\<lbrakk> \<lbrace> P \<rbrace> a \<lbrace> R \<rbrace>!; \<lbrace> Q \<rbrace> a \<lbrace> R \<rbrace>! \<rbrakk> \<Longrightarrow> \<lbrace> P or Q \<rbrace> a \<lbrace> R \<rbrace>!"
by (rule validNF) (auto dest: validNF_valid validNF_no_fail intro: no_fail_or)
(*
* Set up combination rules for WP, which also requires
* a "wp_trip" rule for validNF.
*)
definition "validNF_property Q s b \<equiv> \<not> snd (b s) \<and> (\<forall>(r', s') \<in> fst (b s). Q r' s')"
lemma validNF_is_triple [wp_trip]:
"validNF P f Q = triple_judgement P f (validNF_property Q)"
apply (clarsimp simp: validNF_def triple_judgement_def validNF_property_def)
apply (auto simp: no_fail_def valid_def)
done
lemma validNF_weaken_pre[wp_pre]:
"\<lbrakk>\<lbrace>Q\<rbrace> a \<lbrace>R\<rbrace>!; \<And>s. P s \<Longrightarrow> Q s\<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> a \<lbrace>R\<rbrace>!"
by (metis hoare_pre_imp no_fail_pre validNF_def)
lemma validNF_post_comb_imp_conj:
"\<lbrakk> \<lbrace>P'\<rbrace> f \<lbrace>Q\<rbrace>!; \<lbrace>P\<rbrace> f \<lbrace>Q'\<rbrace>!; \<And>s. P s \<Longrightarrow> P' s \<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<and> Q' rv s\<rbrace>!"
by (fastforce simp: validNF_def valid_def)
lemma validNF_post_comb_conj_L:
"\<lbrakk> \<lbrace>P'\<rbrace> f \<lbrace>Q\<rbrace>!; \<lbrace>P\<rbrace> f \<lbrace>Q'\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. P s \<and> P' s \<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<and> Q' rv s\<rbrace>!"
apply (clarsimp simp: validNF_def valid_def no_fail_def)
apply force
done
lemma validNF_post_comb_conj_R:
"\<lbrakk> \<lbrace>P'\<rbrace> f \<lbrace>Q\<rbrace>; \<lbrace>P\<rbrace> f \<lbrace>Q'\<rbrace>! \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. P s \<and> P' s \<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<and> Q' rv s\<rbrace>!"
apply (clarsimp simp: validNF_def valid_def no_fail_def)
apply force
done
lemma validNF_post_comb_conj:
"\<lbrakk> \<lbrace>P'\<rbrace> f \<lbrace>Q\<rbrace>!; \<lbrace>P\<rbrace> f \<lbrace>Q'\<rbrace>! \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. P s \<and> P' s \<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<and> Q' rv s\<rbrace>!"
apply (clarsimp simp: validNF_def valid_def no_fail_def)
apply force
done
lemma validNF_if_split [wp_split]:
"\<lbrakk>P \<Longrightarrow> \<lbrace>Q\<rbrace> f \<lbrace>S\<rbrace>!; \<not> P \<Longrightarrow> \<lbrace>R\<rbrace> g \<lbrace>S\<rbrace>!\<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. (P \<longrightarrow> Q s) \<and> (\<not> P \<longrightarrow> R s)\<rbrace> if P then f else g \<lbrace>S\<rbrace>!"
by simp
lemma validNF_vcg_conj_lift:
"\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>!; \<lbrace>P'\<rbrace> f \<lbrace>Q'\<rbrace>! \<rbrakk> \<Longrightarrow>
\<lbrace>\<lambda>s. P s \<and> P' s\<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<and> Q' rv s\<rbrace>!"
apply (subst bipred_conj_def[symmetric], rule validNF_post_conj)
apply (erule validNF_weaken_pre, fastforce)
apply (erule validNF_weaken_pre, fastforce)
done
lemma validNF_vcg_disj_lift:
"\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>!; \<lbrace>P'\<rbrace> f \<lbrace>Q'\<rbrace>! \<rbrakk> \<Longrightarrow>
\<lbrace>\<lambda>s. P s \<or> P' s\<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<or> Q' rv s\<rbrace>!"
apply (clarsimp simp: validNF_def)
apply safe
apply (auto intro!: hoare_vcg_disj_lift)[1]
apply (clarsimp simp: no_fail_def)
done
lemma validNF_vcg_all_lift [wp]:
"\<lbrakk> \<And>x. \<lbrace>P x\<rbrace> f \<lbrace>Q x\<rbrace>! \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. \<forall>x. P x s\<rbrace> f \<lbrace>\<lambda>rv s. \<forall>x. Q x rv s\<rbrace>!"
apply atomize
apply (rule validNF)
apply (clarsimp simp: validNF_def)
apply (rule hoare_vcg_all_lift)
apply force
apply (clarsimp simp: no_fail_def validNF_def)
done
lemma validNF_bind [wp_split]:
"\<lbrakk> \<And>x. \<lbrace>B x\<rbrace> g x \<lbrace>C\<rbrace>!; \<lbrace>A\<rbrace> f \<lbrace>B\<rbrace>! \<rbrakk> \<Longrightarrow>
\<lbrace>A\<rbrace> do x \<leftarrow> f; g x od \<lbrace>C\<rbrace>!"
apply (rule validNF)
apply (metis validNF_valid hoare_seq_ext)
apply (clarsimp simp: no_fail_def validNF_def bind_def' valid_def)
apply blast
done
lemmas validNF_seq_ext = validNF_bind
subsection "validNF compound rules"
lemma validNF_state_assert [wp]:
"\<lbrace> \<lambda>s. P () s \<and> G s \<rbrace> state_assert G \<lbrace> P \<rbrace>!"
apply (rule validNF)
apply wpsimp
apply (clarsimp simp: no_fail_def state_assert_def
bind_def' assert_def return_def get_def)
done
lemma validNF_modify [wp]:
"\<lbrace> \<lambda>s. P () (f s) \<rbrace> modify f \<lbrace> P \<rbrace>!"
apply (clarsimp simp: modify_def)
apply wp
done
lemma validNF_gets [wp]:
"\<lbrace>\<lambda>s. P (f s) s\<rbrace> gets f \<lbrace>P\<rbrace>!"
apply (clarsimp simp: gets_def)
apply wp
done
lemma validNF_condition [wp]:
"\<lbrakk> \<lbrace> Q \<rbrace> A \<lbrace>P\<rbrace>!; \<lbrace> R \<rbrace> B \<lbrace>P\<rbrace>!\<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. if C s then Q s else R s\<rbrace> condition C A B \<lbrace>P\<rbrace>!"
apply rule
apply (drule validNF_valid)+
apply (erule (1) condition_wp)
apply (drule validNF_no_fail)+
apply (clarsimp simp: no_fail_def condition_def)
done
lemma validNF_alt_def:
"validNF P m Q = (\<forall>s. P s \<longrightarrow> ((\<forall>(r', s') \<in> fst (m s). Q r' s') \<and> \<not> snd (m s)))"
by (fastforce simp: validNF_def valid_def no_fail_def)
lemma validNF_assert [wp]:
"\<lbrace> (\<lambda>s. P) and (R ()) \<rbrace> assert P \<lbrace> R \<rbrace>!"
apply (rule validNF)
apply (clarsimp simp: valid_def in_return)
apply (clarsimp simp: no_fail_def return_def)
done
lemma validNF_false_pre:
"\<lbrace> \<lambda>_. False \<rbrace> P \<lbrace> Q \<rbrace>!"
by (clarsimp simp: validNF_def no_fail_def)
lemma validNF_chain:
"\<lbrakk>\<lbrace>P'\<rbrace> a \<lbrace>R'\<rbrace>!; \<And>s. P s \<Longrightarrow> P' s; \<And>r s. R' r s \<Longrightarrow> R r s\<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> a \<lbrace>R\<rbrace>!"
by (fastforce simp: validNF_def valid_def no_fail_def Ball_def)
lemma validNF_case_prod [wp]:
"\<lbrakk> \<And>x y. validNF (P x y) (B x y) Q \<rbrakk> \<Longrightarrow> validNF (case_prod P v) (case_prod (\<lambda>x y. B x y) v) Q"
by (metis prod.exhaust split_conv)
lemma validE_NF_case_prod [wp]:
"\<lbrakk> \<And>a b. \<lbrace>P a b\<rbrace> f a b \<lbrace>Q\<rbrace>, \<lbrace>E\<rbrace>! \<rbrakk> \<Longrightarrow>
\<lbrace>case x of (a, b) \<Rightarrow> P a b\<rbrace> case x of (a, b) \<Rightarrow> f a b \<lbrace>Q\<rbrace>, \<lbrace>E\<rbrace>!"
apply (clarsimp simp: validE_NF_alt_def)
apply (erule validNF_case_prod)
done
lemma no_fail_is_validNF_True: "no_fail P s = (\<lbrace> P \<rbrace> s \<lbrace> \<lambda>_ _. True \<rbrace>!)"
by (clarsimp simp: no_fail_def validNF_def valid_def)
subsection "validNF reasoning in the exception monad"
lemma validE_NF [intro?]:
"\<lbrakk> \<lbrace> P \<rbrace> f \<lbrace> Q \<rbrace>,\<lbrace> E \<rbrace>; no_fail P f \<rbrakk> \<Longrightarrow> \<lbrace> P \<rbrace> f \<lbrace> Q \<rbrace>,\<lbrace> E \<rbrace>!"
apply (clarsimp simp: validE_NF_def)
done
lemma validE_NF_valid:
"\<lbrakk> \<lbrace> P \<rbrace> f \<lbrace> Q \<rbrace>,\<lbrace> E \<rbrace>! \<rbrakk> \<Longrightarrow> \<lbrace> P \<rbrace> f \<lbrace> Q \<rbrace>,\<lbrace> E \<rbrace>"
apply (clarsimp simp: validE_NF_def)
done
lemma validE_NF_no_fail:
"\<lbrakk> \<lbrace> P \<rbrace> f \<lbrace> Q \<rbrace>,\<lbrace> E \<rbrace>! \<rbrakk> \<Longrightarrow> no_fail P f"
apply (clarsimp simp: validE_NF_def)
done
lemma validE_NF_weaken_pre[wp_pre]:
"\<lbrakk>\<lbrace>Q\<rbrace> a \<lbrace>R\<rbrace>,\<lbrace>E\<rbrace>!; \<And>s. P s \<Longrightarrow> Q s\<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> a \<lbrace>R\<rbrace>,\<lbrace>E\<rbrace>!"
apply (clarsimp simp: validE_NF_alt_def)
apply (erule validNF_weaken_pre)
apply simp
done
lemma validE_NF_post_comb_conj_L:
"\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>, \<lbrace> E \<rbrace>!; \<lbrace>P'\<rbrace> f \<lbrace>Q'\<rbrace>, \<lbrace> \<lambda>_ _. True \<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. P s \<and> P' s \<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<and> Q' rv s\<rbrace>, \<lbrace> E \<rbrace>!"
apply (clarsimp simp: validE_NF_alt_def validE_def validNF_def
valid_def no_fail_def split: sum.splits)
apply force
done
lemma validE_NF_post_comb_conj_R:
"\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>, \<lbrace> \<lambda>_ _. True \<rbrace>; \<lbrace>P'\<rbrace> f \<lbrace>Q'\<rbrace>, \<lbrace> E \<rbrace>! \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. P s \<and> P' s \<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<and> Q' rv s\<rbrace>, \<lbrace> E \<rbrace>!"
apply (clarsimp simp: validE_NF_alt_def validE_def validNF_def
valid_def no_fail_def split: sum.splits)
apply force
done
lemma validE_NF_post_comb_conj:
"\<lbrakk> \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>, \<lbrace> E \<rbrace>!; \<lbrace>P'\<rbrace> f \<lbrace>Q'\<rbrace>, \<lbrace> E \<rbrace>! \<rbrakk> \<Longrightarrow> \<lbrace>\<lambda>s. P s \<and> P' s \<rbrace> f \<lbrace>\<lambda>rv s. Q rv s \<and> Q' rv s\<rbrace>, \<lbrace> E \<rbrace>!"
apply (clarsimp simp: validE_NF_alt_def validE_def validNF_def
valid_def no_fail_def split: sum.splits)
apply force
done
lemma validE_NF_chain:
"\<lbrakk>\<lbrace>P'\<rbrace> a \<lbrace>R'\<rbrace>,\<lbrace>E'\<rbrace>!;
\<And>s. P s \<Longrightarrow> P' s;
\<And>r' s'. R' r' s' \<Longrightarrow> R r' s';
\<And>r'' s''. E' r'' s'' \<Longrightarrow> E r'' s''\<rbrakk> \<Longrightarrow>
\<lbrace>\<lambda>s. P s \<rbrace> a \<lbrace>\<lambda>r' s'. R r' s'\<rbrace>,\<lbrace>\<lambda>r'' s''. E r'' s''\<rbrace>!"
by (fastforce simp: validE_NF_def validE_def2 no_fail_def Ball_def split: sum.splits)
lemma validE_NF_bind_wp [wp]:
"\<lbrakk>\<And>x. \<lbrace>B x\<rbrace> g x \<lbrace>C\<rbrace>, \<lbrace>E\<rbrace>!; \<lbrace>A\<rbrace> f \<lbrace>B\<rbrace>, \<lbrace>E\<rbrace>!\<rbrakk> \<Longrightarrow> \<lbrace>A\<rbrace> f >>=E (\<lambda>x. g x) \<lbrace>C\<rbrace>, \<lbrace>E\<rbrace>!"
apply (unfold validE_NF_alt_def bindE_def)
apply (rule validNF_bind [rotated])
apply assumption
apply (clarsimp simp: lift_def throwError_def split: sum.splits)
apply wpsimp
done
lemma validNF_catch [wp]:
"\<lbrakk>\<And>x. \<lbrace>E x\<rbrace> handler x \<lbrace>Q\<rbrace>!; \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>, \<lbrace>E\<rbrace>!\<rbrakk> \<Longrightarrow> \<lbrace>P\<rbrace> f <catch> (\<lambda>x. handler x) \<lbrace>Q\<rbrace>!"
apply (unfold validE_NF_alt_def catch_def)
apply (rule validNF_bind [rotated])
apply assumption
apply (clarsimp simp: lift_def throwError_def split: sum.splits)
apply wp
done
lemma validNF_throwError [wp]:
"\<lbrace>E e\<rbrace> throwError e \<lbrace>P\<rbrace>, \<lbrace>E\<rbrace>!"
by (unfold validE_NF_alt_def throwError_def o_def) wpsimp
lemma validNF_returnOk [wp]:
"\<lbrace>P e\<rbrace> returnOk e \<lbrace>P\<rbrace>, \<lbrace>E\<rbrace>!"
by (clarsimp simp: validE_NF_alt_def returnOk_def) wpsimp
lemma validNF_whenE [wp]:
"(P \<Longrightarrow> \<lbrace>Q\<rbrace> f \<lbrace>R\<rbrace>, \<lbrace>E\<rbrace>!) \<Longrightarrow> \<lbrace>if P then Q else R ()\<rbrace> whenE P f \<lbrace>R\<rbrace>, \<lbrace>E\<rbrace>!"
unfolding whenE_def by clarsimp wp
lemma validNF_nobindE [wp]:
"\<lbrakk> \<lbrace>B\<rbrace> g \<lbrace>C\<rbrace>,\<lbrace>E\<rbrace>!;
\<lbrace>A\<rbrace> f \<lbrace>\<lambda>r s. B s\<rbrace>,\<lbrace>E\<rbrace>! \<rbrakk> \<Longrightarrow>
\<lbrace>A\<rbrace> doE f; g odE \<lbrace>C\<rbrace>,\<lbrace>E\<rbrace>!"
by clarsimp wp
text \<open>
Setup triple rules for @{term validE_NF} so that we can use
wp combinator rules.
\<close>
definition "validE_NF_property Q E s b \<equiv> \<not> snd (b s)
\<and> (\<forall>(r', s') \<in> fst (b s). case r' of Inl x \<Rightarrow> E x s' | Inr x \<Rightarrow> Q x s')"
lemma validE_NF_is_triple [wp_trip]:
"validE_NF P f Q E = triple_judgement P f (validE_NF_property Q E)"
apply (clarsimp simp: validE_NF_def validE_def2 no_fail_def triple_judgement_def
validE_NF_property_def split: sum.splits)
apply blast
done
lemma validNF_cong:
"\<lbrakk> \<And>s. P s = P' s; \<And>s. P s \<Longrightarrow> m s = m' s;
\<And>r' s' s. \<lbrakk> P s; (r', s') \<in> fst (m s) \<rbrakk> \<Longrightarrow> Q r' s' = Q' r' s' \<rbrakk> \<Longrightarrow>
(\<lbrace> P \<rbrace> m \<lbrace> Q \<rbrace>!) = (\<lbrace> P' \<rbrace> m' \<lbrace> Q' \<rbrace>!)"
by (fastforce simp: validNF_alt_def)
lemma validE_NF_liftE [wp]:
"\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>! \<Longrightarrow> \<lbrace>P\<rbrace> liftE f \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>!"
by (wpsimp simp: validE_NF_alt_def liftE_def)
lemma validE_NF_handleE' [wp]:
"\<lbrakk> \<And>x. \<lbrace>F x\<rbrace> handler x \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>!; \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>F\<rbrace>! \<rbrakk> \<Longrightarrow>
\<lbrace>P\<rbrace> f <handle2> (\<lambda>x. handler x) \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>!"
apply (unfold validE_NF_alt_def handleE'_def)
apply (rule validNF_bind [rotated])
apply assumption
apply (clarsimp split: sum.splits)
apply wpsimp
done
lemma validE_NF_handleE [wp]:
"\<lbrakk> \<And>x. \<lbrace>F x\<rbrace> handler x \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>!; \<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>,\<lbrace>F\<rbrace>! \<rbrakk> \<Longrightarrow>
\<lbrace>P\<rbrace> f <handle> handler \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>!"
apply (unfold handleE_def)
apply (metis validE_NF_handleE')
done
lemma validE_NF_condition [wp]:
"\<lbrakk> \<lbrace> Q \<rbrace> A \<lbrace>P\<rbrace>,\<lbrace> E \<rbrace>!; \<lbrace> R \<rbrace> B \<lbrace>P\<rbrace>,\<lbrace> E \<rbrace>!\<rbrakk>
\<Longrightarrow> \<lbrace>\<lambda>s. if C s then Q s else R s\<rbrace> condition C A B \<lbrace>P\<rbrace>,\<lbrace> E \<rbrace>!"
apply rule
apply (drule validE_NF_valid)+
apply wp
apply (drule validE_NF_no_fail)+
apply (clarsimp simp: no_fail_def condition_def)
done
text \<open>Strengthen setup.\<close>
context strengthen_implementation begin
lemma strengthen_hoare [strg]:
"(\<And>r s. st F (\<longrightarrow>) (Q r s) (R r s))
\<Longrightarrow> st F (\<longrightarrow>) (\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>) (\<lbrace>P\<rbrace> f \<lbrace>R\<rbrace>)"
by (cases F, auto elim: hoare_strengthen_post)
lemma strengthen_validE_R_cong[strg]:
"(\<And>r s. st F (\<longrightarrow>) (Q r s) (R r s))
\<Longrightarrow> st F (\<longrightarrow>) (\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>, -) (\<lbrace>P\<rbrace> f \<lbrace>R\<rbrace>, -)"
by (cases F, auto intro: hoare_post_imp_R)
lemma strengthen_validE_cong[strg]:
"(\<And>r s. st F (\<longrightarrow>) (Q r s) (R r s))
\<Longrightarrow> (\<And>r s. st F (\<longrightarrow>) (S r s) (T r s))
\<Longrightarrow> st F (\<longrightarrow>) (\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>, \<lbrace>S\<rbrace>) (\<lbrace>P\<rbrace> f \<lbrace>R\<rbrace>, \<lbrace>T\<rbrace>)"
by (cases F, auto elim: hoare_post_impErr)
lemma strengthen_validE_E_cong[strg]:
"(\<And>r s. st F (\<longrightarrow>) (S r s) (T r s))
\<Longrightarrow> st F (\<longrightarrow>) (\<lbrace>P\<rbrace> f -, \<lbrace>S\<rbrace>) (\<lbrace>P\<rbrace> f -, \<lbrace>T\<rbrace>)"
by (cases F, auto elim: hoare_post_impErr simp: validE_E_def)
lemma wpfix_strengthen_hoare:
"(\<And>s. st (\<not> F) (\<longrightarrow>) (P s) (P' s))
\<Longrightarrow> (\<And>r s. st F (\<longrightarrow>) (Q r s) (Q' r s))
\<Longrightarrow> st F (\<longrightarrow>) (\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>) (\<lbrace>P'\<rbrace> f \<lbrace>Q'\<rbrace>)"
by (cases F, auto elim: hoare_chain)
lemma wpfix_strengthen_validE_R_cong:
"(\<And>s. st (\<not> F) (\<longrightarrow>) (P s) (P' s))
\<Longrightarrow> (\<And>r s. st F (\<longrightarrow>) (Q r s) (Q' r s))
\<Longrightarrow> st F (\<longrightarrow>) (\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>, -) (\<lbrace>P'\<rbrace> f \<lbrace>Q'\<rbrace>, -)"
by (cases F, auto elim: hoare_chainE simp: validE_R_def)
lemma wpfix_strengthen_validE_cong:
"(\<And>s. st (\<not> F) (\<longrightarrow>) (P s) (P' s))
\<Longrightarrow> (\<And>r s. st F (\<longrightarrow>) (Q r s) (R r s))
\<Longrightarrow> (\<And>r s. st F (\<longrightarrow>) (S r s) (T r s))
\<Longrightarrow> st F (\<longrightarrow>) (\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace>, \<lbrace>S\<rbrace>) (\<lbrace>P'\<rbrace> f \<lbrace>R\<rbrace>, \<lbrace>T\<rbrace>)"
by (cases F, auto elim: hoare_chainE)
lemma wpfix_strengthen_validE_E_cong:
"(\<And>s. st (\<not> F) (\<longrightarrow>) (P s) (P' s))
\<Longrightarrow> (\<And>r s. st F (\<longrightarrow>) (S r s) (T r s))
\<Longrightarrow> st F (\<longrightarrow>) (\<lbrace>P\<rbrace> f -, \<lbrace>S\<rbrace>) (\<lbrace>P'\<rbrace> f -, \<lbrace>T\<rbrace>)"
by (cases F, auto elim: hoare_chainE simp: validE_E_def)
lemma wpfix_no_fail_cong:
"(\<And>s. st (\<not> F) (\<longrightarrow>) (P s) (P' s))
\<Longrightarrow> st F (\<longrightarrow>) (no_fail P f) (no_fail P' f)"
by (cases F, auto elim: no_fail_pre)
lemmas nondet_wpfix_strgs =
wpfix_strengthen_validE_R_cong
wpfix_strengthen_validE_E_cong
wpfix_strengthen_validE_cong
wpfix_strengthen_hoare
wpfix_no_fail_cong
end
lemmas nondet_wpfix_strgs[wp_fix_strgs]
= strengthen_implementation.nondet_wpfix_strgs
end
|
module Structure.Signature where
open import Data.Tuple.Raise
open import Data.Tuple.Raiseᵣ.Functions
import Lvl
open import Numeral.Natural
open import Structure.Function
open import Structure.Setoid
open import Structure.Relator
open import Type
private variable ℓ ℓᵢ ℓᵢ₁ ℓᵢ₂ ℓᵢ₃ ℓd ℓd₁ ℓd₂ ℓᵣ ℓᵣ₁ ℓᵣ₂ ℓₑ ℓₑ₁ ℓₑ₂ : Lvl.Level
private variable n : ℕ
-- A signature consists of a countable family of sets of function and relation symbols.
-- `functions(n)` and `relations(n)` should be interpreted as the indices for functions/relations of arity `n`.
record Signature : Type{Lvl.𝐒(ℓᵢ₁ Lvl.⊔ ℓᵢ₂)} where
field
functions : ℕ → Type{ℓᵢ₁}
relations : ℕ → Type{ℓᵢ₂}
private variable s : Signature{ℓᵢ₁}{ℓᵢ₂}
import Data.Tuple.Equiv as Tuple
-- A structure with a signature `s` consists of a domain and interpretations of the function/relation symbols in `s`.
record Structure (s : Signature{ℓᵢ₁}{ℓᵢ₂}) : Type{Lvl.𝐒(ℓₑ Lvl.⊔ ℓd Lvl.⊔ ℓᵣ) Lvl.⊔ ℓᵢ₁ Lvl.⊔ ℓᵢ₂} where
open Signature(s)
field
domain : Type{ℓd}
⦃ equiv ⦄ : ∀{n} → Equiv{ℓₑ}(domain ^ n)
⦃ ext ⦄ : ∀{n} → Tuple.Extensionality(equiv{𝐒(𝐒 n)})
function : functions(n) → ((domain ^ n) → domain)
⦃ function-func ⦄ : ∀{fi} → Function(function{n} fi)
relation : relations(n) → ((domain ^ n) → Type{ℓᵣ})
⦃ relation-func ⦄ : ∀{ri} → UnaryRelator(relation{n} ri)
open Structure public using() renaming (domain to dom ; function to fn ; relation to rel)
open import Logic.Predicate
module _ {s : Signature{ℓᵢ₁}{ℓᵢ₂}} where
private variable A B C S : Structure{ℓd = ℓd}{ℓᵣ = ℓᵣ}(s)
private variable fi : Signature.functions s n
private variable ri : Signature.relations s n
private variable xs : dom(S) ^ n
record Homomorphism
(A : Structure{ℓₑ = ℓₑ₁}{ℓd = ℓd₁}{ℓᵣ = ℓᵣ₁}(s))
(B : Structure{ℓₑ = ℓₑ₂}{ℓd = ℓd₂}{ℓᵣ = ℓᵣ₂}(s))
(f : dom(A) → dom(B))
: Type{ℓₑ₁ Lvl.⊔ ℓₑ₂ Lvl.⊔ ℓd₁ Lvl.⊔ ℓd₂ Lvl.⊔ ℓᵣ₁ Lvl.⊔ ℓᵣ₂ Lvl.⊔ Lvl.ofType(Type.of s)}
where
field
⦃ function ⦄ : Function(f)
preserve-functions : ∀{xs : dom(A) ^ n} → (f(fn(A) fi xs) ≡ fn(B) fi (map f xs))
preserve-relations : ∀{xs : dom(A) ^ n} → (rel(A) ri xs) → (rel(B) ri (map f xs))
_→ₛₜᵣᵤ_ : Structure{ℓₑ = ℓₑ₁}{ℓd = ℓd₁}{ℓᵣ = ℓᵣ₁}(s) → Structure{ℓₑ = ℓₑ₂}{ℓd = ℓd₂}{ℓᵣ = ℓᵣ₂}(s) → Type
A →ₛₜᵣᵤ B = ∃(Homomorphism A B)
open import Data
open import Data.Tuple as Tuple using (_,_)
open import Data.Tuple.Raiseᵣ.Proofs
open import Functional
open import Function.Proofs
open import Lang.Instance
open import Structure.Operator
open import Structure.Relator.Properties
open import Syntax.Transitivity
idₛₜᵣᵤ : A →ₛₜᵣᵤ A
∃.witness idₛₜᵣᵤ = id
Homomorphism.preserve-functions (∃.proof (idₛₜᵣᵤ {A = A})) {n} {fi} {xs} = congruence₁(fn A fi) (symmetry(Equiv._≡_ (Structure.equiv A)) ⦃ Equiv.symmetry infer ⦄ map-id)
Homomorphism.preserve-relations (∃.proof (idₛₜᵣᵤ {A = A})) {n} {ri} {xs} = substitute₁ₗ(rel A ri) map-id
_∘ₛₜᵣᵤ_ : let _ = A , B , C in (B →ₛₜᵣᵤ C) → (A →ₛₜᵣᵤ B) → (A →ₛₜᵣᵤ C)
∃.witness (([∃]-intro f) ∘ₛₜᵣᵤ ([∃]-intro g)) = f ∘ g
Homomorphism.function (∃.proof ([∃]-intro f ∘ₛₜᵣᵤ [∃]-intro g)) = [∘]-function {f = f}{g = g}
Homomorphism.preserve-functions (∃.proof (_∘ₛₜᵣᵤ_ {A = A} {B = B} {C = C} ([∃]-intro f ⦃ hom-f ⦄) ([∃]-intro g ⦃ hom-g ⦄))) {fi = fi} = transitivity(_≡_) ⦃ Equiv.transitivity infer ⦄ (transitivity(_≡_) ⦃ Equiv.transitivity infer ⦄ (congruence₁(f) (Homomorphism.preserve-functions hom-g)) (Homomorphism.preserve-functions hom-f)) (congruence₁(fn C fi) (symmetry(Equiv._≡_ (Structure.equiv C)) ⦃ Equiv.symmetry infer ⦄ (map-[∘] {f = f}{g = g})))
Homomorphism.preserve-relations (∃.proof (_∘ₛₜᵣᵤ_ {A = A} {B = B} {C = C} ([∃]-intro f ⦃ hom-f ⦄) ([∃]-intro g ⦃ hom-g ⦄))) {ri = ri} = substitute₁ₗ (rel C ri) map-[∘] ∘ Homomorphism.preserve-relations hom-f ∘ Homomorphism.preserve-relations hom-g
open import Function.Equals
open import Function.Equals.Proofs
open import Logic.Predicate.Equiv
open import Structure.Category
open import Structure.Categorical.Properties
Structure-Homomorphism-category : Category(_→ₛₜᵣᵤ_ {ℓₑ}{ℓd}{ℓᵣ})
Category._∘_ Structure-Homomorphism-category = _∘ₛₜᵣᵤ_
Category.id Structure-Homomorphism-category = idₛₜᵣᵤ
BinaryOperator.congruence (Category.binaryOperator Structure-Homomorphism-category) = [⊜][∘]-binaryOperator-raw
_⊜_.proof (Morphism.Associativity.proof (Category.associativity Structure-Homomorphism-category) {_} {_} {_} {_} {[∃]-intro f} {[∃]-intro g} {[∃]-intro h}) {x} = reflexivity(_≡_) ⦃ Equiv.reflexivity infer ⦄ {f(g(h(x)))}
_⊜_.proof (Morphism.Identityₗ.proof (Tuple.left (Category.identity Structure-Homomorphism-category)) {f = [∃]-intro f}) {x} = reflexivity(_≡_) ⦃ Equiv.reflexivity infer ⦄ {f(x)}
_⊜_.proof (Morphism.Identityᵣ.proof (Tuple.right (Category.identity Structure-Homomorphism-category)) {f = [∃]-intro f}) {x} = reflexivity(_≡_) ⦃ Equiv.reflexivity infer ⦄ {f(x)}
module _ (s : Signature{ℓᵢ₁}{ℓᵢ₂}) where
data Term : Type{ℓᵢ₁} where
var : ℕ → Term
func : (Signature.functions s n) → (Term ^ n) → Term
|
CurtisBray grew up in Davis, left for college and then returned to Parenting raise a family with his wife Sarah. Checkout their site at http://www.brayfamily.com for a quick snapshot of their family.
Curtis now works locally at UC Davis, the first time in his life that hes lived and worked in the same city!
|
@discord_object struct Emoji
id::Snowflake
name::String
roles::Vector{Snowflake}
user::User
require_colons::Bool
managed::Bool
animated::Bool
available::Bool
end
|
lemma filterlim_at_top_mult_tendsto_pos: assumes f: "(f \<longlongrightarrow> c) F" and c: "0 < c" and g: "LIM x F. g x :> at_top" shows "LIM x F. (g x * f x:: real) :> at_top" |
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : AddCommMonoid E
inst✝ : SMul 𝕜 E
s : Set E
x✝ y✝ x y : E
⊢ [x-[𝕜]y] = (fun p => p.fst • x + p.snd • y) '' {p | 0 ≤ p.fst ∧ 0 ≤ p.snd ∧ p.fst + p.snd = 1}
[PROOFSTEP]
simp only [segment, image, Prod.exists, mem_setOf_eq, exists_prop, and_assoc]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : AddCommMonoid E
inst✝ : SMul 𝕜 E
s : Set E
x✝ y✝ x y : E
⊢ openSegment 𝕜 x y = (fun p => p.fst • x + p.snd • y) '' {p | 0 < p.fst ∧ 0 < p.snd ∧ p.fst + p.snd = 1}
[PROOFSTEP]
simp only [openSegment, image, Prod.exists, mem_setOf_eq, exists_prop, and_assoc]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : AddCommMonoid E
inst✝ : MulActionWithZero 𝕜 E
x y : E
⊢ 1 • x + 0 • y = x
[PROOFSTEP]
rw [zero_smul, one_smul, add_zero]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : AddCommMonoid E
inst✝ : Module 𝕜 E
s : Set E
x✝¹ y z✝ x z : E
x✝ : z ∈ [x-[𝕜]x]
a b : 𝕜
w✝¹ : 0 ≤ a
w✝ : 0 ≤ b
hab : a + b = 1
hz : a • x + b • x = z
⊢ z ∈ {x}
[PROOFSTEP]
simpa only [(add_smul _ _ _).symm, mem_singleton_iff, hab, one_smul, eq_comm] using hz
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : AddCommMonoid E
inst✝ : Module 𝕜 E
s : Set E
x✝ y✝ z x y : E
⊢ insert x (insert y (openSegment 𝕜 x y)) = [x-[𝕜]y]
[PROOFSTEP]
simp only [subset_antisymm_iff, insert_subset_iff, left_mem_segment, right_mem_segment, openSegment_subset_segment,
true_and_iff]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : AddCommMonoid E
inst✝ : Module 𝕜 E
s : Set E
x✝ y✝ z x y : E
⊢ [x-[𝕜]y] ⊆ insert x (insert y (openSegment 𝕜 x y))
[PROOFSTEP]
rintro z ⟨a, b, ha, hb, hab, rfl⟩
[GOAL]
case intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : AddCommMonoid E
inst✝ : Module 𝕜 E
s : Set E
x✝ y✝ z x y : E
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
⊢ a • x + b • y ∈ insert x (insert y (openSegment 𝕜 x y))
[PROOFSTEP]
refine' hb.eq_or_gt.imp _ fun hb' => ha.eq_or_gt.imp _ fun ha' => _
[GOAL]
case intro.intro.intro.intro.intro.refine'_1
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : AddCommMonoid E
inst✝ : Module 𝕜 E
s : Set E
x✝ y✝ z x y : E
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
⊢ b = 0 → a • x + b • y = x
[PROOFSTEP]
rintro rfl
[GOAL]
case intro.intro.intro.intro.intro.refine'_1
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : AddCommMonoid E
inst✝ : Module 𝕜 E
s : Set E
x✝ y✝ z x y : E
a : 𝕜
ha : 0 ≤ a
hb : 0 ≤ 0
hab : a + 0 = 1
⊢ a • x + 0 • y = x
[PROOFSTEP]
rw [← add_zero a, hab, one_smul, zero_smul, add_zero]
[GOAL]
case intro.intro.intro.intro.intro.refine'_2
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : AddCommMonoid E
inst✝ : Module 𝕜 E
s : Set E
x✝ y✝ z x y : E
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
hb' : 0 < b
⊢ a = 0 → a • x + b • y = y
[PROOFSTEP]
rintro rfl
[GOAL]
case intro.intro.intro.intro.intro.refine'_2
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : AddCommMonoid E
inst✝ : Module 𝕜 E
s : Set E
x✝ y✝ z x y : E
b : 𝕜
hb : 0 ≤ b
hb' : 0 < b
ha : 0 ≤ 0
hab : 0 + b = 1
⊢ 0 • x + b • y = y
[PROOFSTEP]
rw [← zero_add b, hab, one_smul, zero_smul, zero_add]
[GOAL]
case intro.intro.intro.intro.intro.refine'_3
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : AddCommMonoid E
inst✝ : Module 𝕜 E
s : Set E
x✝ y✝ z x y : E
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
hb' : 0 < b
ha' : 0 < a
⊢ a • x + b • y ∈ openSegment 𝕜 x y
[PROOFSTEP]
exact ⟨a, b, ha', hb', hab, rfl⟩
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : AddCommMonoid E
inst✝ : Module 𝕜 E
s : Set E
x y z : E
hx : x ≠ z
hy : y ≠ z
hz : z ∈ [x-[𝕜]y]
⊢ z ∈ openSegment 𝕜 x y
[PROOFSTEP]
rw [← insert_endpoints_openSegment] at hz
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : AddCommMonoid E
inst✝ : Module 𝕜 E
s : Set E
x y z : E
hx : x ≠ z
hy : y ≠ z
hz : z ∈ insert x (insert y (openSegment 𝕜 x y))
⊢ z ∈ openSegment 𝕜 x y
[PROOFSTEP]
exact (hz.resolve_left hx.symm).resolve_left hy.symm
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : AddCommMonoid E
inst✝ : Module 𝕜 E
s : Set E
x y z : E
hx : x ∈ s
hy : y ∈ s
⊢ openSegment 𝕜 x y ⊆ s ↔ [x-[𝕜]y] ⊆ s
[PROOFSTEP]
simp only [← insert_endpoints_openSegment, insert_subset_iff, *, true_and_iff]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁷ : OrderedRing 𝕜
inst✝⁶ : AddCommGroup E
inst✝⁵ : AddCommGroup F
inst✝⁴ : AddCommGroup G
inst✝³ : Module 𝕜 E
inst✝² : Module 𝕜 F
inst✝¹ : Nontrivial 𝕜
inst✝ : DenselyOrdered 𝕜
x z : E
x✝ : z ∈ openSegment 𝕜 x x
a b : 𝕜
w✝¹ : 0 < a
w✝ : 0 < b
hab : a + b = 1
hz : a • x + b • x = z
⊢ z ∈ {x}
[PROOFSTEP]
simpa only [← add_smul, mem_singleton_iff, hab, one_smul, eq_comm] using hz
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁷ : OrderedRing 𝕜
inst✝⁶ : AddCommGroup E
inst✝⁵ : AddCommGroup F
inst✝⁴ : AddCommGroup G
inst✝³ : Module 𝕜 E
inst✝² : Module 𝕜 F
inst✝¹ : Nontrivial 𝕜
inst✝ : DenselyOrdered 𝕜
x z : E
h : z = x
⊢ z ∈ openSegment 𝕜 x x
[PROOFSTEP]
obtain ⟨a, ha₀, ha₁⟩ := DenselyOrdered.dense (0 : 𝕜) 1 zero_lt_one
[GOAL]
case intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁷ : OrderedRing 𝕜
inst✝⁶ : AddCommGroup E
inst✝⁵ : AddCommGroup F
inst✝⁴ : AddCommGroup G
inst✝³ : Module 𝕜 E
inst✝² : Module 𝕜 F
inst✝¹ : Nontrivial 𝕜
inst✝ : DenselyOrdered 𝕜
x z : E
h : z = x
a : 𝕜
ha₀ : 0 < a
ha₁ : a < 1
⊢ z ∈ openSegment 𝕜 x x
[PROOFSTEP]
refine' ⟨a, 1 - a, ha₀, sub_pos_of_lt ha₁, add_sub_cancel'_right _ _, _⟩
[GOAL]
case intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁷ : OrderedRing 𝕜
inst✝⁶ : AddCommGroup E
inst✝⁵ : AddCommGroup F
inst✝⁴ : AddCommGroup G
inst✝³ : Module 𝕜 E
inst✝² : Module 𝕜 F
inst✝¹ : Nontrivial 𝕜
inst✝ : DenselyOrdered 𝕜
x z : E
h : z = x
a : 𝕜
ha₀ : 0 < a
ha₁ : a < 1
⊢ a • x + (1 - a) • x = z
[PROOFSTEP]
rw [← add_smul, add_sub_cancel'_right, one_smul, h]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁵ : OrderedRing 𝕜
inst✝⁴ : AddCommGroup E
inst✝³ : AddCommGroup F
inst✝² : AddCommGroup G
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x y z : E
x✝ : z ∈ [x-[𝕜]y]
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
hz : a • x + b • y = z
⊢ (fun θ => (a + b - θ) • x + θ • y) b = a • x + b • y
[PROOFSTEP]
simp only [add_sub_cancel]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁵ : OrderedRing 𝕜
inst✝⁴ : AddCommGroup E
inst✝³ : AddCommGroup F
inst✝² : AddCommGroup G
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x y z : E
x✝ : z ∈ openSegment 𝕜 x y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
hz : a • x + b • y = z
⊢ (fun θ => (a + b - θ) • x + θ • y) b = a • x + b • y
[PROOFSTEP]
simp only [add_sub_cancel]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁵ : OrderedRing 𝕜
inst✝⁴ : AddCommGroup E
inst✝³ : AddCommGroup F
inst✝² : AddCommGroup G
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x y : E
⊢ [x-[𝕜]y] = (fun θ => x + θ • (y - x)) '' Icc 0 1
[PROOFSTEP]
convert segment_eq_image 𝕜 x y using 2
[GOAL]
case h.e'_3.h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁵ : OrderedRing 𝕜
inst✝⁴ : AddCommGroup E
inst✝³ : AddCommGroup F
inst✝² : AddCommGroup G
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x y : E
a✝¹ : 𝕜
a✝ : a✝¹ ∈ Icc 0 1
⊢ x + a✝¹ • (y - x) = (1 - a✝¹) • x + a✝¹ • y
[PROOFSTEP]
simp only [smul_sub, sub_smul, one_smul]
[GOAL]
case h.e'_3.h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁵ : OrderedRing 𝕜
inst✝⁴ : AddCommGroup E
inst✝³ : AddCommGroup F
inst✝² : AddCommGroup G
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x y : E
a✝¹ : 𝕜
a✝ : a✝¹ ∈ Icc 0 1
⊢ x + (a✝¹ • y - a✝¹ • x) = x - a✝¹ • x + a✝¹ • y
[PROOFSTEP]
abel
[GOAL]
case h.e'_3.h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁵ : OrderedRing 𝕜
inst✝⁴ : AddCommGroup E
inst✝³ : AddCommGroup F
inst✝² : AddCommGroup G
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x y : E
a✝¹ : 𝕜
a✝ : a✝¹ ∈ Icc 0 1
⊢ x + (a✝¹ • y - a✝¹ • x) = x - a✝¹ • x + a✝¹ • y
[PROOFSTEP]
abel
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁵ : OrderedRing 𝕜
inst✝⁴ : AddCommGroup E
inst✝³ : AddCommGroup F
inst✝² : AddCommGroup G
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x y : E
⊢ openSegment 𝕜 x y = (fun θ => x + θ • (y - x)) '' Ioo 0 1
[PROOFSTEP]
convert openSegment_eq_image 𝕜 x y using 2
[GOAL]
case h.e'_3.h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁵ : OrderedRing 𝕜
inst✝⁴ : AddCommGroup E
inst✝³ : AddCommGroup F
inst✝² : AddCommGroup G
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x y : E
a✝¹ : 𝕜
a✝ : a✝¹ ∈ Ioo 0 1
⊢ x + a✝¹ • (y - x) = (1 - a✝¹) • x + a✝¹ • y
[PROOFSTEP]
simp only [smul_sub, sub_smul, one_smul]
[GOAL]
case h.e'_3.h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁵ : OrderedRing 𝕜
inst✝⁴ : AddCommGroup E
inst✝³ : AddCommGroup F
inst✝² : AddCommGroup G
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x y : E
a✝¹ : 𝕜
a✝ : a✝¹ ∈ Ioo 0 1
⊢ x + (a✝¹ • y - a✝¹ • x) = x - a✝¹ • x + a✝¹ • y
[PROOFSTEP]
abel
[GOAL]
case h.e'_3.h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁵ : OrderedRing 𝕜
inst✝⁴ : AddCommGroup E
inst✝³ : AddCommGroup F
inst✝² : AddCommGroup G
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x y : E
a✝¹ : 𝕜
a✝ : a✝¹ ∈ Ioo 0 1
⊢ x + (a✝¹ • y - a✝¹ • x) = x - a✝¹ • x + a✝¹ • y
[PROOFSTEP]
abel
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁵ : OrderedRing 𝕜
inst✝⁴ : AddCommGroup E
inst✝³ : AddCommGroup F
inst✝² : AddCommGroup G
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x y : E
⊢ [x-[𝕜]y] = ↑(AffineMap.lineMap x y) '' Icc 0 1
[PROOFSTEP]
convert segment_eq_image 𝕜 x y using 2
[GOAL]
case h.e'_3.h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁵ : OrderedRing 𝕜
inst✝⁴ : AddCommGroup E
inst✝³ : AddCommGroup F
inst✝² : AddCommGroup G
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x y : E
a✝¹ : 𝕜
a✝ : a✝¹ ∈ Icc 0 1
⊢ ↑(AffineMap.lineMap x y) a✝¹ = (1 - a✝¹) • x + a✝¹ • y
[PROOFSTEP]
exact AffineMap.lineMap_apply_module _ _ _
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁵ : OrderedRing 𝕜
inst✝⁴ : AddCommGroup E
inst✝³ : AddCommGroup F
inst✝² : AddCommGroup G
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x y : E
⊢ openSegment 𝕜 x y = ↑(AffineMap.lineMap x y) '' Ioo 0 1
[PROOFSTEP]
convert openSegment_eq_image 𝕜 x y using 2
[GOAL]
case h.e'_3.h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁵ : OrderedRing 𝕜
inst✝⁴ : AddCommGroup E
inst✝³ : AddCommGroup F
inst✝² : AddCommGroup G
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x y : E
a✝¹ : 𝕜
a✝ : a✝¹ ∈ Ioo 0 1
⊢ ↑(AffineMap.lineMap x y) a✝¹ = (1 - a✝¹) • x + a✝¹ • y
[PROOFSTEP]
exact AffineMap.lineMap_apply_module _ _ _
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁵ : OrderedRing 𝕜
inst✝⁴ : AddCommGroup E
inst✝³ : AddCommGroup F
inst✝² : AddCommGroup G
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
f : E →ᵃ[𝕜] F
a b : E
x : F
⊢ x ∈ ↑f '' [a-[𝕜]b] ↔ x ∈ [↑f a-[𝕜]↑f b]
[PROOFSTEP]
simp_rw [segment_eq_image_lineMap, mem_image, exists_exists_and_eq_and, AffineMap.apply_lineMap]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁵ : OrderedRing 𝕜
inst✝⁴ : AddCommGroup E
inst✝³ : AddCommGroup F
inst✝² : AddCommGroup G
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
f : E →ᵃ[𝕜] F
a b : E
x : F
⊢ x ∈ ↑f '' openSegment 𝕜 a b ↔ x ∈ openSegment 𝕜 (↑f a) (↑f b)
[PROOFSTEP]
simp_rw [openSegment_eq_image_lineMap, mem_image, exists_exists_and_eq_and, AffineMap.apply_lineMap]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁵ : OrderedRing 𝕜
inst✝⁴ : AddCommGroup E
inst✝³ : AddCommGroup F
inst✝² : AddCommGroup G
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
a x b c : E
⊢ a + x ∈ [a + b-[𝕜]a + c] ↔ x ∈ [b-[𝕜]c]
[PROOFSTEP]
simp_rw [← vadd_eq_add, ← vadd_segment, vadd_mem_vadd_set_iff]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁵ : OrderedRing 𝕜
inst✝⁴ : AddCommGroup E
inst✝³ : AddCommGroup F
inst✝² : AddCommGroup G
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
a x b c : E
⊢ a + x ∈ openSegment 𝕜 (a + b) (a + c) ↔ x ∈ openSegment 𝕜 b c
[PROOFSTEP]
simp_rw [← vadd_eq_add, ← vadd_openSegment, vadd_mem_vadd_set_iff]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : StrictOrderedCommRing 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x y z : E
h : x ∈ [y-[𝕜]z]
⊢ SameRay 𝕜 (x - y) (z - x)
[PROOFSTEP]
rw [segment_eq_image'] at h
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : StrictOrderedCommRing 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x y z : E
h : x ∈ (fun θ => y + θ • (z - y)) '' Icc 0 1
⊢ SameRay 𝕜 (x - y) (z - x)
[PROOFSTEP]
rcases h with ⟨θ, ⟨hθ₀, hθ₁⟩, rfl⟩
[GOAL]
case intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : StrictOrderedCommRing 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
y z : E
θ : 𝕜
hθ₀ : 0 ≤ θ
hθ₁ : θ ≤ 1
⊢ SameRay 𝕜 ((fun θ => y + θ • (z - y)) θ - y) (z - (fun θ => y + θ • (z - y)) θ)
[PROOFSTEP]
simpa only [add_sub_cancel', ← sub_sub, sub_smul, one_smul] using
(SameRay.sameRay_nonneg_smul_left (z - y) hθ₀).nonneg_smul_right (sub_nonneg.2 hθ₁)
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : LinearOrderedRing 𝕜
inst✝² : AddCommGroup E
inst✝¹ : Module 𝕜 E
x✝ y✝ : E
inst✝ : Invertible 2
x y : E
⊢ midpoint 𝕜 x y ∈ [x-[𝕜]y]
[PROOFSTEP]
rw [segment_eq_image_lineMap]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : LinearOrderedRing 𝕜
inst✝² : AddCommGroup E
inst✝¹ : Module 𝕜 E
x✝ y✝ : E
inst✝ : Invertible 2
x y : E
⊢ midpoint 𝕜 x y ∈ ↑(AffineMap.lineMap x y) '' Icc 0 1
[PROOFSTEP]
exact ⟨⅟2, ⟨invOf_nonneg.mpr zero_le_two, invOf_le_one one_le_two⟩, rfl⟩
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : LinearOrderedRing 𝕜
inst✝² : AddCommGroup E
inst✝¹ : Module 𝕜 E
x✝ y✝ : E
inst✝ : Invertible 2
x y : E
⊢ x ∈ [x - y-[𝕜]x + y]
[PROOFSTEP]
convert @midpoint_mem_segment 𝕜 _ _ _ _ _ _ _
[GOAL]
case h.e'_4
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : LinearOrderedRing 𝕜
inst✝² : AddCommGroup E
inst✝¹ : Module 𝕜 E
x✝ y✝ : E
inst✝ : Invertible 2
x y : E
⊢ x = midpoint 𝕜 (x - y) (x + y)
[PROOFSTEP]
rw [midpoint_sub_add]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : LinearOrderedRing 𝕜
inst✝² : AddCommGroup E
inst✝¹ : Module 𝕜 E
x✝ y✝ : E
inst✝ : Invertible 2
x y : E
⊢ x ∈ [x + y-[𝕜]x - y]
[PROOFSTEP]
convert @midpoint_mem_segment 𝕜 _ _ _ _ _ _ _
[GOAL]
case h.e'_4
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : LinearOrderedRing 𝕜
inst✝² : AddCommGroup E
inst✝¹ : Module 𝕜 E
x✝ y✝ : E
inst✝ : Invertible 2
x y : E
⊢ x = midpoint 𝕜 (x + y) (x - y)
[PROOFSTEP]
rw [midpoint_add_sub]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : LinearOrderedRing 𝕜
inst✝³ : AddCommGroup E
inst✝² : Module 𝕜 E
x y : E
inst✝¹ : DenselyOrdered 𝕜
inst✝ : NoZeroSMulDivisors 𝕜 E
⊢ x ∈ openSegment 𝕜 x y ↔ x = y
[PROOFSTEP]
constructor
[GOAL]
case mp
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : LinearOrderedRing 𝕜
inst✝³ : AddCommGroup E
inst✝² : Module 𝕜 E
x y : E
inst✝¹ : DenselyOrdered 𝕜
inst✝ : NoZeroSMulDivisors 𝕜 E
⊢ x ∈ openSegment 𝕜 x y → x = y
[PROOFSTEP]
rintro ⟨a, b, _, hb, hab, hx⟩
[GOAL]
case mp.intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : LinearOrderedRing 𝕜
inst✝³ : AddCommGroup E
inst✝² : Module 𝕜 E
x y : E
inst✝¹ : DenselyOrdered 𝕜
inst✝ : NoZeroSMulDivisors 𝕜 E
a b : 𝕜
w✝ : 0 < a
hb : 0 < b
hab : a + b = 1
hx : a • x + b • y = x
⊢ x = y
[PROOFSTEP]
refine' smul_right_injective _ hb.ne' ((add_right_inj (a • x)).1 _)
[GOAL]
case mp.intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : LinearOrderedRing 𝕜
inst✝³ : AddCommGroup E
inst✝² : Module 𝕜 E
x y : E
inst✝¹ : DenselyOrdered 𝕜
inst✝ : NoZeroSMulDivisors 𝕜 E
a b : 𝕜
w✝ : 0 < a
hb : 0 < b
hab : a + b = 1
hx : a • x + b • y = x
⊢ a • x + (fun x x_1 => x • x_1) b x = a • x + (fun x x_1 => x • x_1) b y
[PROOFSTEP]
rw [hx, ← add_smul, hab, one_smul]
[GOAL]
case mpr
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : LinearOrderedRing 𝕜
inst✝³ : AddCommGroup E
inst✝² : Module 𝕜 E
x y : E
inst✝¹ : DenselyOrdered 𝕜
inst✝ : NoZeroSMulDivisors 𝕜 E
⊢ x = y → x ∈ openSegment 𝕜 x y
[PROOFSTEP]
rintro rfl
[GOAL]
case mpr
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : LinearOrderedRing 𝕜
inst✝³ : AddCommGroup E
inst✝² : Module 𝕜 E
x : E
inst✝¹ : DenselyOrdered 𝕜
inst✝ : NoZeroSMulDivisors 𝕜 E
⊢ x ∈ openSegment 𝕜 x x
[PROOFSTEP]
rw [openSegment_same]
[GOAL]
case mpr
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : LinearOrderedRing 𝕜
inst✝³ : AddCommGroup E
inst✝² : Module 𝕜 E
x : E
inst✝¹ : DenselyOrdered 𝕜
inst✝ : NoZeroSMulDivisors 𝕜 E
⊢ x ∈ {x}
[PROOFSTEP]
exact mem_singleton _
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : LinearOrderedRing 𝕜
inst✝³ : AddCommGroup E
inst✝² : Module 𝕜 E
x y : E
inst✝¹ : DenselyOrdered 𝕜
inst✝ : NoZeroSMulDivisors 𝕜 E
⊢ y ∈ openSegment 𝕜 x y ↔ x = y
[PROOFSTEP]
rw [openSegment_symm, left_mem_openSegment_iff, eq_comm]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x y z : E
⊢ x ∈ [y-[𝕜]z] ↔ ∃ a b, 0 ≤ a ∧ 0 ≤ b ∧ 0 < a + b ∧ (a / (a + b)) • y + (b / (a + b)) • z = x
[PROOFSTEP]
constructor
[GOAL]
case mp
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x y z : E
⊢ x ∈ [y-[𝕜]z] → ∃ a b, 0 ≤ a ∧ 0 ≤ b ∧ 0 < a + b ∧ (a / (a + b)) • y + (b / (a + b)) • z = x
[PROOFSTEP]
rintro ⟨a, b, ha, hb, hab, rfl⟩
[GOAL]
case mp.intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
y z : E
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
⊢ ∃ a_1 b_1, 0 ≤ a_1 ∧ 0 ≤ b_1 ∧ 0 < a_1 + b_1 ∧ (a_1 / (a_1 + b_1)) • y + (b_1 / (a_1 + b_1)) • z = a • y + b • z
[PROOFSTEP]
use a, b, ha, hb
[GOAL]
case right
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
y z : E
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
⊢ 0 < a + b ∧ (a / (a + b)) • y + (b / (a + b)) • z = a • y + b • z
[PROOFSTEP]
simp [*]
[GOAL]
case mpr
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x y z : E
⊢ (∃ a b, 0 ≤ a ∧ 0 ≤ b ∧ 0 < a + b ∧ (a / (a + b)) • y + (b / (a + b)) • z = x) → x ∈ [y-[𝕜]z]
[PROOFSTEP]
rintro ⟨a, b, ha, hb, hab, rfl⟩
[GOAL]
case mpr.intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
y z : E
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : 0 < a + b
⊢ (a / (a + b)) • y + (b / (a + b)) • z ∈ [y-[𝕜]z]
[PROOFSTEP]
refine' ⟨a / (a + b), b / (a + b), by positivity, by positivity, _, rfl⟩
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
y z : E
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : 0 < a + b
⊢ 0 ≤ a / (a + b)
[PROOFSTEP]
positivity
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
y z : E
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : 0 < a + b
⊢ 0 ≤ b / (a + b)
[PROOFSTEP]
positivity
[GOAL]
case mpr.intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
y z : E
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : 0 < a + b
⊢ a / (a + b) + b / (a + b) = 1
[PROOFSTEP]
rw [← add_div, div_self hab.ne']
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x y z : E
⊢ x ∈ openSegment 𝕜 y z ↔ ∃ a b, 0 < a ∧ 0 < b ∧ (a / (a + b)) • y + (b / (a + b)) • z = x
[PROOFSTEP]
constructor
[GOAL]
case mp
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x y z : E
⊢ x ∈ openSegment 𝕜 y z → ∃ a b, 0 < a ∧ 0 < b ∧ (a / (a + b)) • y + (b / (a + b)) • z = x
[PROOFSTEP]
rintro ⟨a, b, ha, hb, hab, rfl⟩
[GOAL]
case mp.intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
y z : E
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ ∃ a_1 b_1, 0 < a_1 ∧ 0 < b_1 ∧ (a_1 / (a_1 + b_1)) • y + (b_1 / (a_1 + b_1)) • z = a • y + b • z
[PROOFSTEP]
use a, b, ha, hb
[GOAL]
case right
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
y z : E
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ (a / (a + b)) • y + (b / (a + b)) • z = a • y + b • z
[PROOFSTEP]
rw [hab, div_one, div_one]
[GOAL]
case mpr
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x y z : E
⊢ (∃ a b, 0 < a ∧ 0 < b ∧ (a / (a + b)) • y + (b / (a + b)) • z = x) → x ∈ openSegment 𝕜 y z
[PROOFSTEP]
rintro ⟨a, b, ha, hb, rfl⟩
[GOAL]
case mpr.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
y z : E
a b : 𝕜
ha : 0 < a
hb : 0 < b
⊢ (a / (a + b)) • y + (b / (a + b)) • z ∈ openSegment 𝕜 y z
[PROOFSTEP]
have hab : 0 < a + b := by positivity
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
y z : E
a b : 𝕜
ha : 0 < a
hb : 0 < b
⊢ 0 < a + b
[PROOFSTEP]
positivity
[GOAL]
case mpr.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
y z : E
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : 0 < a + b
⊢ (a / (a + b)) • y + (b / (a + b)) • z ∈ openSegment 𝕜 y z
[PROOFSTEP]
refine' ⟨a / (a + b), b / (a + b), by positivity, by positivity, _, rfl⟩
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
y z : E
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : 0 < a + b
⊢ 0 < a / (a + b)
[PROOFSTEP]
positivity
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
y z : E
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : 0 < a + b
⊢ 0 < b / (a + b)
[PROOFSTEP]
positivity
[GOAL]
case mpr.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedSemifield 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
y z : E
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : 0 < a + b
⊢ a / (a + b) + b / (a + b) = 1
[PROOFSTEP]
rw [← add_div, div_self hab.ne']
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x y z : E
⊢ x ∈ [y-[𝕜]z] ↔ SameRay 𝕜 (x - y) (z - x)
[PROOFSTEP]
refine' ⟨sameRay_of_mem_segment, fun h => _⟩
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x y z : E
h : SameRay 𝕜 (x - y) (z - x)
⊢ x ∈ [y-[𝕜]z]
[PROOFSTEP]
rcases h.exists_eq_smul_add with ⟨a, b, ha, hb, hab, hxy, hzx⟩
[GOAL]
case intro.intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x y z : E
h : SameRay 𝕜 (x - y) (z - x)
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
hxy : x - y = a • (x - y + (z - x))
hzx : z - x = b • (x - y + (z - x))
⊢ x ∈ [y-[𝕜]z]
[PROOFSTEP]
rw [add_comm, sub_add_sub_cancel] at hxy hzx
[GOAL]
case intro.intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x y z : E
h : SameRay 𝕜 (x - y) (z - x)
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
hxy : x - y = a • (z - y)
hzx : z - x = b • (z - y)
⊢ x ∈ [y-[𝕜]z]
[PROOFSTEP]
rw [← mem_segment_translate _ (-x), neg_add_self]
[GOAL]
case intro.intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x y z : E
h : SameRay 𝕜 (x - y) (z - x)
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
hxy : x - y = a • (z - y)
hzx : z - x = b • (z - y)
⊢ 0 ∈ [-x + y-[𝕜]-x + z]
[PROOFSTEP]
refine' ⟨b, a, hb, ha, add_comm a b ▸ hab, _⟩
[GOAL]
case intro.intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x y z : E
h : SameRay 𝕜 (x - y) (z - x)
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
hxy : x - y = a • (z - y)
hzx : z - x = b • (z - y)
⊢ b • (-x + y) + a • (-x + z) = 0
[PROOFSTEP]
rw [← sub_eq_neg_add, ← neg_sub, hxy, ← sub_eq_neg_add, hzx, smul_neg, smul_comm, neg_add_self]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x✝ y✝ z✝ x y z : E
hz : z ∈ range ↑(lineMap x y)
⊢ openSegment 𝕜 x y ⊆ insert z (openSegment 𝕜 x z ∪ openSegment 𝕜 z y)
[PROOFSTEP]
rcases hz with ⟨c, rfl⟩
[GOAL]
case intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x✝ y✝ z x y : E
c : 𝕜
⊢ openSegment 𝕜 x y ⊆
insert (↑(lineMap x y) c) (openSegment 𝕜 x (↑(lineMap x y) c) ∪ openSegment 𝕜 (↑(lineMap x y) c) y)
[PROOFSTEP]
simp only [openSegment_eq_image_lineMap, ← mapsTo']
[GOAL]
case intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x✝ y✝ z x y : E
c : 𝕜
⊢ MapsTo (fun a => ↑(lineMap x y) a) (Ioo 0 1)
(insert (↑(lineMap x y) c)
((fun a => ↑(lineMap x (↑(lineMap x y) c)) a) '' Ioo 0 1 ∪
(fun a => ↑(lineMap (↑(lineMap x y) c) y) a) '' Ioo 0 1))
[PROOFSTEP]
rintro a ⟨h₀, h₁⟩
[GOAL]
case intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x✝ y✝ z x y : E
c a : 𝕜
h₀ : 0 < a
h₁ : a < 1
⊢ (fun a => ↑(lineMap x y) a) a ∈
insert (↑(lineMap x y) c)
((fun a => ↑(lineMap x (↑(lineMap x y) c)) a) '' Ioo 0 1 ∪
(fun a => ↑(lineMap (↑(lineMap x y) c) y) a) '' Ioo 0 1)
[PROOFSTEP]
rcases lt_trichotomy a c with (hac | rfl | hca)
[GOAL]
case intro.intro.inl
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x✝ y✝ z x y : E
c a : 𝕜
h₀ : 0 < a
h₁ : a < 1
hac : a < c
⊢ (fun a => ↑(lineMap x y) a) a ∈
insert (↑(lineMap x y) c)
((fun a => ↑(lineMap x (↑(lineMap x y) c)) a) '' Ioo 0 1 ∪
(fun a => ↑(lineMap (↑(lineMap x y) c) y) a) '' Ioo 0 1)
[PROOFSTEP]
right
[GOAL]
case intro.intro.inl.h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x✝ y✝ z x y : E
c a : 𝕜
h₀ : 0 < a
h₁ : a < 1
hac : a < c
⊢ (fun a => ↑(lineMap x y) a) a ∈
(fun a => ↑(lineMap x (↑(lineMap x y) c)) a) '' Ioo 0 1 ∪ (fun a => ↑(lineMap (↑(lineMap x y) c) y) a) '' Ioo 0 1
[PROOFSTEP]
left
[GOAL]
case intro.intro.inl.h.h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x✝ y✝ z x y : E
c a : 𝕜
h₀ : 0 < a
h₁ : a < 1
hac : a < c
⊢ (fun a => ↑(lineMap x y) a) a ∈ (fun a => ↑(lineMap x (↑(lineMap x y) c)) a) '' Ioo 0 1
[PROOFSTEP]
have hc : 0 < c := h₀.trans hac
[GOAL]
case intro.intro.inl.h.h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x✝ y✝ z x y : E
c a : 𝕜
h₀ : 0 < a
h₁ : a < 1
hac : a < c
hc : 0 < c
⊢ (fun a => ↑(lineMap x y) a) a ∈ (fun a => ↑(lineMap x (↑(lineMap x y) c)) a) '' Ioo 0 1
[PROOFSTEP]
refine' ⟨a / c, ⟨div_pos h₀ hc, (div_lt_one hc).2 hac⟩, _⟩
[GOAL]
case intro.intro.inl.h.h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x✝ y✝ z x y : E
c a : 𝕜
h₀ : 0 < a
h₁ : a < 1
hac : a < c
hc : 0 < c
⊢ (fun a => ↑(lineMap x (↑(lineMap x y) c)) a) (a / c) = (fun a => ↑(lineMap x y) a) a
[PROOFSTEP]
simp only [← homothety_eq_lineMap, ← homothety_mul_apply, div_mul_cancel _ hc.ne']
[GOAL]
case intro.intro.inr.inl
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x✝ y✝ z x y : E
a : 𝕜
h₀ : 0 < a
h₁ : a < 1
⊢ (fun a => ↑(lineMap x y) a) a ∈
insert (↑(lineMap x y) a)
((fun a_1 => ↑(lineMap x (↑(lineMap x y) a)) a_1) '' Ioo 0 1 ∪
(fun a_1 => ↑(lineMap (↑(lineMap x y) a) y) a_1) '' Ioo 0 1)
[PROOFSTEP]
left
[GOAL]
case intro.intro.inr.inl.h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x✝ y✝ z x y : E
a : 𝕜
h₀ : 0 < a
h₁ : a < 1
⊢ (fun a => ↑(lineMap x y) a) a = ↑(lineMap x y) a
[PROOFSTEP]
rfl
[GOAL]
case intro.intro.inr.inr
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x✝ y✝ z x y : E
c a : 𝕜
h₀ : 0 < a
h₁ : a < 1
hca : c < a
⊢ (fun a => ↑(lineMap x y) a) a ∈
insert (↑(lineMap x y) c)
((fun a => ↑(lineMap x (↑(lineMap x y) c)) a) '' Ioo 0 1 ∪
(fun a => ↑(lineMap (↑(lineMap x y) c) y) a) '' Ioo 0 1)
[PROOFSTEP]
right
[GOAL]
case intro.intro.inr.inr.h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x✝ y✝ z x y : E
c a : 𝕜
h₀ : 0 < a
h₁ : a < 1
hca : c < a
⊢ (fun a => ↑(lineMap x y) a) a ∈
(fun a => ↑(lineMap x (↑(lineMap x y) c)) a) '' Ioo 0 1 ∪ (fun a => ↑(lineMap (↑(lineMap x y) c) y) a) '' Ioo 0 1
[PROOFSTEP]
right
[GOAL]
case intro.intro.inr.inr.h.h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x✝ y✝ z x y : E
c a : 𝕜
h₀ : 0 < a
h₁ : a < 1
hca : c < a
⊢ (fun a => ↑(lineMap x y) a) a ∈ (fun a => ↑(lineMap (↑(lineMap x y) c) y) a) '' Ioo 0 1
[PROOFSTEP]
have hc : 0 < 1 - c := sub_pos.2 (hca.trans h₁)
[GOAL]
case intro.intro.inr.inr.h.h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x✝ y✝ z x y : E
c a : 𝕜
h₀ : 0 < a
h₁ : a < 1
hca : c < a
hc : 0 < 1 - c
⊢ (fun a => ↑(lineMap x y) a) a ∈ (fun a => ↑(lineMap (↑(lineMap x y) c) y) a) '' Ioo 0 1
[PROOFSTEP]
simp only [← lineMap_apply_one_sub y]
[GOAL]
case intro.intro.inr.inr.h.h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x✝ y✝ z x y : E
c a : 𝕜
h₀ : 0 < a
h₁ : a < 1
hca : c < a
hc : 0 < 1 - c
⊢ ↑(lineMap y x) (1 - a) ∈ (fun a => ↑(lineMap y (↑(lineMap y x) (1 - c))) (1 - a)) '' Ioo 0 1
[PROOFSTEP]
refine' ⟨(a - c) / (1 - c), ⟨div_pos (sub_pos.2 hca) hc, (div_lt_one hc).2 <| sub_lt_sub_right h₁ _⟩, _⟩
[GOAL]
case intro.intro.inr.inr.h.h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : LinearOrderedField 𝕜
inst✝¹ : AddCommGroup E
inst✝ : Module 𝕜 E
x✝ y✝ z x y : E
c a : 𝕜
h₀ : 0 < a
h₁ : a < 1
hca : c < a
hc : 0 < 1 - c
⊢ (fun a => ↑(lineMap y (↑(lineMap y x) (1 - c))) (1 - a)) ((a - c) / (1 - c)) = ↑(lineMap y x) (1 - a)
[PROOFSTEP]
simp only [← homothety_eq_lineMap, ← homothety_mul_apply, sub_mul, one_mul, div_mul_cancel _ hc.ne',
sub_sub_sub_cancel_right]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : OrderedAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
x y : E
h : x ≤ y
⊢ [x-[𝕜]y] ⊆ Icc x y
[PROOFSTEP]
rintro z ⟨a, b, ha, hb, hab, rfl⟩
[GOAL]
case intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : OrderedAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
x y : E
h : x ≤ y
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
⊢ a • x + b • y ∈ Icc x y
[PROOFSTEP]
constructor
[GOAL]
case intro.intro.intro.intro.intro.left
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : OrderedAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
x y : E
h : x ≤ y
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
⊢ x ≤ a • x + b • y
case intro.intro.intro.intro.intro.right
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : OrderedAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
x y : E
h : x ≤ y
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
⊢ a • x + b • y ≤ y
[PROOFSTEP]
calc
x = a • x + b • x := (Convex.combo_self hab _).symm
_ ≤ a • x + b • y := by gcongr
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : OrderedAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
x y : E
h : x ≤ y
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
⊢ a • x + b • x ≤ a • x + b • y
[PROOFSTEP]
gcongr
[GOAL]
case intro.intro.intro.intro.intro.right
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : OrderedAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
x y : E
h : x ≤ y
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
⊢ a • x + b • y ≤ y
[PROOFSTEP]
calc
a • x + b • y ≤ a • y + b • y := by gcongr
_ = y := Convex.combo_self hab _
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : OrderedAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
x y : E
h : x ≤ y
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
⊢ a • x + b • y ≤ a • y + b • y
[PROOFSTEP]
gcongr
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : OrderedCancelAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
x y : E
h : x < y
⊢ openSegment 𝕜 x y ⊆ Ioo x y
[PROOFSTEP]
rintro z ⟨a, b, ha, hb, hab, rfl⟩
[GOAL]
case intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : OrderedCancelAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
x y : E
h : x < y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ a • x + b • y ∈ Ioo x y
[PROOFSTEP]
constructor
[GOAL]
case intro.intro.intro.intro.intro.left
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : OrderedCancelAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
x y : E
h : x < y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ x < a • x + b • y
case intro.intro.intro.intro.intro.right
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : OrderedCancelAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
x y : E
h : x < y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ a • x + b • y < y
[PROOFSTEP]
calc
x = a • x + b • x := (Convex.combo_self hab _).symm
_ < a • x + b • y := by gcongr
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : OrderedCancelAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
x y : E
h : x < y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ a • x + b • x < a • x + b • y
[PROOFSTEP]
gcongr
[GOAL]
case intro.intro.intro.intro.intro.right
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : OrderedCancelAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
x y : E
h : x < y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ a • x + b • y < y
[PROOFSTEP]
calc
a • x + b • y < a • y + b • y := by gcongr
_ = y := Convex.combo_self hab _
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : OrderedCancelAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
x y : E
h : x < y
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ a • x + b • y < a • y + b • y
[PROOFSTEP]
gcongr
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : LinearOrderedAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
a b : 𝕜
x y : E
⊢ [x-[𝕜]y] ⊆ uIcc x y
[PROOFSTEP]
cases' le_total x y with h h
[GOAL]
case inl
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : LinearOrderedAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
a b : 𝕜
x y : E
h : x ≤ y
⊢ [x-[𝕜]y] ⊆ uIcc x y
[PROOFSTEP]
rw [uIcc_of_le h]
[GOAL]
case inl
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : LinearOrderedAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
a b : 𝕜
x y : E
h : x ≤ y
⊢ [x-[𝕜]y] ⊆ Icc x y
[PROOFSTEP]
exact segment_subset_Icc h
[GOAL]
case inr
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : LinearOrderedAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
a b : 𝕜
x y : E
h : y ≤ x
⊢ [x-[𝕜]y] ⊆ uIcc x y
[PROOFSTEP]
rw [uIcc_of_ge h, segment_symm]
[GOAL]
case inr
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : LinearOrderedAddCommMonoid E
inst✝¹ : Module 𝕜 E
inst✝ : OrderedSMul 𝕜 E
a b : 𝕜
x y : E
h : y ≤ x
⊢ [y-[𝕜]x] ⊆ Icc y x
[PROOFSTEP]
exact segment_subset_Icc h
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z : 𝕜
⊢ Icc x y ⊆ [x-[𝕜]y]
[PROOFSTEP]
rintro z ⟨hxz, hyz⟩
[GOAL]
case intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z✝ z : 𝕜
hxz : x ≤ z
hyz : z ≤ y
⊢ z ∈ [x-[𝕜]y]
[PROOFSTEP]
obtain rfl | h := (hxz.trans hyz).eq_or_lt
[GOAL]
case intro.inl
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x z✝ z : 𝕜
hxz : x ≤ z
hyz : z ≤ x
⊢ z ∈ [x-[𝕜]x]
[PROOFSTEP]
rw [segment_same]
[GOAL]
case intro.inl
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x z✝ z : 𝕜
hxz : x ≤ z
hyz : z ≤ x
⊢ z ∈ {x}
[PROOFSTEP]
exact hyz.antisymm hxz
[GOAL]
case intro.inr
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z✝ z : 𝕜
hxz : x ≤ z
hyz : z ≤ y
h : x < y
⊢ z ∈ [x-[𝕜]y]
[PROOFSTEP]
rw [← sub_nonneg] at hxz hyz
[GOAL]
case intro.inr
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z✝ z : 𝕜
hxz✝ : x ≤ z
hxz : 0 ≤ z - x
hyz✝ : z ≤ y
hyz : 0 ≤ y - z
h : x < y
⊢ z ∈ [x-[𝕜]y]
[PROOFSTEP]
rw [← sub_pos] at h
[GOAL]
case intro.inr
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z✝ z : 𝕜
hxz✝ : x ≤ z
hxz : 0 ≤ z - x
hyz✝ : z ≤ y
hyz : 0 ≤ y - z
h✝ : x < y
h : 0 < y - x
⊢ z ∈ [x-[𝕜]y]
[PROOFSTEP]
refine' ⟨(y - z) / (y - x), (z - x) / (y - x), div_nonneg hyz h.le, div_nonneg hxz h.le, _, _⟩
[GOAL]
case intro.inr.refine'_1
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z✝ z : 𝕜
hxz✝ : x ≤ z
hxz : 0 ≤ z - x
hyz✝ : z ≤ y
hyz : 0 ≤ y - z
h✝ : x < y
h : 0 < y - x
⊢ (y - z) / (y - x) + (z - x) / (y - x) = 1
[PROOFSTEP]
rw [← add_div, sub_add_sub_cancel, div_self h.ne']
[GOAL]
case intro.inr.refine'_2
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z✝ z : 𝕜
hxz✝ : x ≤ z
hxz : 0 ≤ z - x
hyz✝ : z ≤ y
hyz : 0 ≤ y - z
h✝ : x < y
h : 0 < y - x
⊢ ((y - z) / (y - x)) • x + ((z - x) / (y - x)) • y = z
[PROOFSTEP]
rw [smul_eq_mul, smul_eq_mul, ← mul_div_right_comm, ← mul_div_right_comm, ← add_div, div_eq_iff h.ne', add_comm,
sub_mul, sub_mul, mul_comm x, sub_add_sub_cancel, mul_sub]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x✝ y✝ z x y : 𝕜
⊢ [x-[𝕜]y] = Icc (min x y) (max x y)
[PROOFSTEP]
cases' le_total x y with h h
[GOAL]
case inl
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x✝ y✝ z x y : 𝕜
h : x ≤ y
⊢ [x-[𝕜]y] = Icc (min x y) (max x y)
[PROOFSTEP]
rw [segment_eq_Icc h, max_eq_right h, min_eq_left h]
[GOAL]
case inr
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x✝ y✝ z x y : 𝕜
h : y ≤ x
⊢ [x-[𝕜]y] = Icc (min x y) (max x y)
[PROOFSTEP]
rw [segment_symm, segment_eq_Icc h, max_eq_left h, min_eq_right h]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z : 𝕜
hxy : x ≠ y
⊢ openSegment 𝕜 x y = Ioo (min x y) (max x y)
[PROOFSTEP]
cases' hxy.lt_or_lt with h h
[GOAL]
case inl
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z : 𝕜
hxy : x ≠ y
h : x < y
⊢ openSegment 𝕜 x y = Ioo (min x y) (max x y)
[PROOFSTEP]
rw [openSegment_eq_Ioo h, max_eq_right h.le, min_eq_left h.le]
[GOAL]
case inr
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z : 𝕜
hxy : x ≠ y
h : y < x
⊢ openSegment 𝕜 x y = Ioo (min x y) (max x y)
[PROOFSTEP]
rw [openSegment_symm, openSegment_eq_Ioo h, max_eq_left h.le, min_eq_right h.le]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z : 𝕜
h : x ≤ y
⊢ z ∈ Icc x y ↔ ∃ a b, 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ a * x + b * y = z
[PROOFSTEP]
rw [← segment_eq_Icc h]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z : 𝕜
h : x ≤ y
⊢ z ∈ [x-[𝕜]y] ↔ ∃ a b, 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ a * x + b * y = z
[PROOFSTEP]
simp_rw [← exists_prop]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z : 𝕜
h : x ≤ y
⊢ z ∈ [x-[𝕜]y] ↔ ∃ a b _h _h _h, a * x + b * y = z
[PROOFSTEP]
rfl
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z : 𝕜
h : x < y
⊢ z ∈ Ioo x y ↔ ∃ a b, 0 < a ∧ 0 < b ∧ a + b = 1 ∧ a * x + b * y = z
[PROOFSTEP]
rw [← openSegment_eq_Ioo h]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z : 𝕜
h : x < y
⊢ z ∈ openSegment 𝕜 x y ↔ ∃ a b, 0 < a ∧ 0 < b ∧ a + b = 1 ∧ a * x + b * y = z
[PROOFSTEP]
simp_rw [← exists_prop]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z : 𝕜
h : x < y
⊢ z ∈ openSegment 𝕜 x y ↔ ∃ a b _h _h _h, a * x + b * y = z
[PROOFSTEP]
rfl
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z : 𝕜
h : x < y
⊢ z ∈ Ioc x y ↔ ∃ a b, 0 ≤ a ∧ 0 < b ∧ a + b = 1 ∧ a * x + b * y = z
[PROOFSTEP]
refine' ⟨fun hz => _, _⟩
[GOAL]
case refine'_1
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z : 𝕜
h : x < y
hz : z ∈ Ioc x y
⊢ ∃ a b, 0 ≤ a ∧ 0 < b ∧ a + b = 1 ∧ a * x + b * y = z
[PROOFSTEP]
obtain ⟨a, b, ha, hb, hab, rfl⟩ := (Convex.mem_Icc h.le).1 (Ioc_subset_Icc_self hz)
[GOAL]
case refine'_1.intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y : 𝕜
h : x < y
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
hz : a * x + b * y ∈ Ioc x y
⊢ ∃ a_1 b_1, 0 ≤ a_1 ∧ 0 < b_1 ∧ a_1 + b_1 = 1 ∧ a_1 * x + b_1 * y = a * x + b * y
[PROOFSTEP]
obtain rfl | hb' := hb.eq_or_lt
[GOAL]
case refine'_1.intro.intro.intro.intro.intro.inl
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y : 𝕜
h : x < y
a : 𝕜
ha : 0 ≤ a
hb : 0 ≤ 0
hab : a + 0 = 1
hz : a * x + 0 * y ∈ Ioc x y
⊢ ∃ a_1 b, 0 ≤ a_1 ∧ 0 < b ∧ a_1 + b = 1 ∧ a_1 * x + b * y = a * x + 0 * y
[PROOFSTEP]
rw [add_zero] at hab
[GOAL]
case refine'_1.intro.intro.intro.intro.intro.inl
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y : 𝕜
h : x < y
a : 𝕜
ha : 0 ≤ a
hb : 0 ≤ 0
hab : a = 1
hz : a * x + 0 * y ∈ Ioc x y
⊢ ∃ a_1 b, 0 ≤ a_1 ∧ 0 < b ∧ a_1 + b = 1 ∧ a_1 * x + b * y = a * x + 0 * y
[PROOFSTEP]
rw [hab, one_mul, zero_mul, add_zero] at hz
[GOAL]
case refine'_1.intro.intro.intro.intro.intro.inl
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y : 𝕜
h : x < y
a : 𝕜
ha : 0 ≤ a
hb : 0 ≤ 0
hab : a = 1
hz : x ∈ Ioc x y
⊢ ∃ a_1 b, 0 ≤ a_1 ∧ 0 < b ∧ a_1 + b = 1 ∧ a_1 * x + b * y = a * x + 0 * y
[PROOFSTEP]
exact (hz.1.ne rfl).elim
[GOAL]
case refine'_1.intro.intro.intro.intro.intro.inr
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y : 𝕜
h : x < y
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
hz : a * x + b * y ∈ Ioc x y
hb' : 0 < b
⊢ ∃ a_1 b_1, 0 ≤ a_1 ∧ 0 < b_1 ∧ a_1 + b_1 = 1 ∧ a_1 * x + b_1 * y = a * x + b * y
[PROOFSTEP]
exact ⟨a, b, ha, hb', hab, rfl⟩
[GOAL]
case refine'_2
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z : 𝕜
h : x < y
⊢ (∃ a b, 0 ≤ a ∧ 0 < b ∧ a + b = 1 ∧ a * x + b * y = z) → z ∈ Ioc x y
[PROOFSTEP]
rintro ⟨a, b, ha, hb, hab, rfl⟩
[GOAL]
case refine'_2.intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y : 𝕜
h : x < y
a b : 𝕜
ha : 0 ≤ a
hb : 0 < b
hab : a + b = 1
⊢ a * x + b * y ∈ Ioc x y
[PROOFSTEP]
obtain rfl | ha' := ha.eq_or_lt
[GOAL]
case refine'_2.intro.intro.intro.intro.intro.inl
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y : 𝕜
h : x < y
b : 𝕜
hb : 0 < b
ha : 0 ≤ 0
hab : 0 + b = 1
⊢ 0 * x + b * y ∈ Ioc x y
[PROOFSTEP]
rw [zero_add] at hab
[GOAL]
case refine'_2.intro.intro.intro.intro.intro.inl
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y : 𝕜
h : x < y
b : 𝕜
hb : 0 < b
ha : 0 ≤ 0
hab : b = 1
⊢ 0 * x + b * y ∈ Ioc x y
[PROOFSTEP]
rwa [hab, one_mul, zero_mul, zero_add, right_mem_Ioc]
[GOAL]
case refine'_2.intro.intro.intro.intro.intro.inr
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y : 𝕜
h : x < y
a b : 𝕜
ha : 0 ≤ a
hb : 0 < b
hab : a + b = 1
ha' : 0 < a
⊢ a * x + b * y ∈ Ioc x y
[PROOFSTEP]
exact Ioo_subset_Ioc_self ((Convex.mem_Ioo h).2 ⟨a, b, ha', hb, hab, rfl⟩)
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z : 𝕜
h : x < y
⊢ z ∈ Ico x y ↔ ∃ a b, 0 < a ∧ 0 ≤ b ∧ a + b = 1 ∧ a * x + b * y = z
[PROOFSTEP]
refine' ⟨fun hz => _, _⟩
[GOAL]
case refine'_1
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z : 𝕜
h : x < y
hz : z ∈ Ico x y
⊢ ∃ a b, 0 < a ∧ 0 ≤ b ∧ a + b = 1 ∧ a * x + b * y = z
[PROOFSTEP]
obtain ⟨a, b, ha, hb, hab, rfl⟩ := (Convex.mem_Icc h.le).1 (Ico_subset_Icc_self hz)
[GOAL]
case refine'_1.intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y : 𝕜
h : x < y
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
hz : a * x + b * y ∈ Ico x y
⊢ ∃ a_1 b_1, 0 < a_1 ∧ 0 ≤ b_1 ∧ a_1 + b_1 = 1 ∧ a_1 * x + b_1 * y = a * x + b * y
[PROOFSTEP]
obtain rfl | ha' := ha.eq_or_lt
[GOAL]
case refine'_1.intro.intro.intro.intro.intro.inl
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y : 𝕜
h : x < y
b : 𝕜
hb : 0 ≤ b
ha : 0 ≤ 0
hab : 0 + b = 1
hz : 0 * x + b * y ∈ Ico x y
⊢ ∃ a b_1, 0 < a ∧ 0 ≤ b_1 ∧ a + b_1 = 1 ∧ a * x + b_1 * y = 0 * x + b * y
[PROOFSTEP]
rw [zero_add] at hab
[GOAL]
case refine'_1.intro.intro.intro.intro.intro.inl
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y : 𝕜
h : x < y
b : 𝕜
hb : 0 ≤ b
ha : 0 ≤ 0
hab : b = 1
hz : 0 * x + b * y ∈ Ico x y
⊢ ∃ a b_1, 0 < a ∧ 0 ≤ b_1 ∧ a + b_1 = 1 ∧ a * x + b_1 * y = 0 * x + b * y
[PROOFSTEP]
rw [hab, one_mul, zero_mul, zero_add] at hz
[GOAL]
case refine'_1.intro.intro.intro.intro.intro.inl
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y : 𝕜
h : x < y
b : 𝕜
hb : 0 ≤ b
ha : 0 ≤ 0
hab : b = 1
hz : y ∈ Ico x y
⊢ ∃ a b_1, 0 < a ∧ 0 ≤ b_1 ∧ a + b_1 = 1 ∧ a * x + b_1 * y = 0 * x + b * y
[PROOFSTEP]
exact (hz.2.ne rfl).elim
[GOAL]
case refine'_1.intro.intro.intro.intro.intro.inr
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y : 𝕜
h : x < y
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
hz : a * x + b * y ∈ Ico x y
ha' : 0 < a
⊢ ∃ a_1 b_1, 0 < a_1 ∧ 0 ≤ b_1 ∧ a_1 + b_1 = 1 ∧ a_1 * x + b_1 * y = a * x + b * y
[PROOFSTEP]
exact ⟨a, b, ha', hb, hab, rfl⟩
[GOAL]
case refine'_2
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y z : 𝕜
h : x < y
⊢ (∃ a b, 0 < a ∧ 0 ≤ b ∧ a + b = 1 ∧ a * x + b * y = z) → z ∈ Ico x y
[PROOFSTEP]
rintro ⟨a, b, ha, hb, hab, rfl⟩
[GOAL]
case refine'_2.intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y : 𝕜
h : x < y
a b : 𝕜
ha : 0 < a
hb : 0 ≤ b
hab : a + b = 1
⊢ a * x + b * y ∈ Ico x y
[PROOFSTEP]
obtain rfl | hb' := hb.eq_or_lt
[GOAL]
case refine'_2.intro.intro.intro.intro.intro.inl
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y : 𝕜
h : x < y
a : 𝕜
ha : 0 < a
hb : 0 ≤ 0
hab : a + 0 = 1
⊢ a * x + 0 * y ∈ Ico x y
[PROOFSTEP]
rw [add_zero] at hab
[GOAL]
case refine'_2.intro.intro.intro.intro.intro.inl
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y : 𝕜
h : x < y
a : 𝕜
ha : 0 < a
hb : 0 ≤ 0
hab : a = 1
⊢ a * x + 0 * y ∈ Ico x y
[PROOFSTEP]
rwa [hab, one_mul, zero_mul, add_zero, left_mem_Ico]
[GOAL]
case refine'_2.intro.intro.intro.intro.intro.inr
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝ : LinearOrderedField 𝕜
x y : 𝕜
h : x < y
a b : 𝕜
ha : 0 < a
hb : 0 ≤ b
hab : a + b = 1
hb' : 0 < b
⊢ a * x + b * y ∈ Ico x y
[PROOFSTEP]
exact Ioo_subset_Ico_self ((Convex.mem_Ioo h).2 ⟨a, b, ha, hb', hab, rfl⟩)
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x y : E × F
⊢ [x-[𝕜]y] ⊆ [x.fst-[𝕜]y.fst] ×ˢ [x.snd-[𝕜]y.snd]
[PROOFSTEP]
rintro z ⟨a, b, ha, hb, hab, hz⟩
[GOAL]
case intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x y z : E × F
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
hz : a • x + b • y = z
⊢ z ∈ [x.fst-[𝕜]y.fst] ×ˢ [x.snd-[𝕜]y.snd]
[PROOFSTEP]
exact ⟨⟨a, b, ha, hb, hab, congr_arg Prod.fst hz⟩, a, b, ha, hb, hab, congr_arg Prod.snd hz⟩
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x y : E × F
⊢ openSegment 𝕜 x y ⊆ openSegment 𝕜 x.fst y.fst ×ˢ openSegment 𝕜 x.snd y.snd
[PROOFSTEP]
rintro z ⟨a, b, ha, hb, hab, hz⟩
[GOAL]
case intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x y z : E × F
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
hz : a • x + b • y = z
⊢ z ∈ openSegment 𝕜 x.fst y.fst ×ˢ openSegment 𝕜 x.snd y.snd
[PROOFSTEP]
exact ⟨⟨a, b, ha, hb, hab, congr_arg Prod.fst hz⟩, a, b, ha, hb, hab, congr_arg Prod.snd hz⟩
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x₁ x₂ : E
y : F
⊢ (fun x => (x, y)) '' [x₁-[𝕜]x₂] = [(x₁, y)-[𝕜](x₂, y)]
[PROOFSTEP]
ext ⟨x', y'⟩
[GOAL]
case h.mk
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x₁ x₂ : E
y : F
x' : E
y' : F
⊢ (x', y') ∈ (fun x => (x, y)) '' [x₁-[𝕜]x₂] ↔ (x', y') ∈ [(x₁, y)-[𝕜](x₂, y)]
[PROOFSTEP]
simp_rw [Set.mem_image, segment, Set.mem_setOf, Prod.smul_mk, Prod.mk_add_mk, Prod.mk.inj_iff, ← exists_and_right,
@exists_comm E, exists_eq_left']
[GOAL]
case h.mk
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x₁ x₂ : E
y : F
x' : E
y' : F
⊢ (∃ b b_1 h h h, b • x₁ + b_1 • x₂ = x' ∧ y = y') ↔ ∃ a b h h h, a • x₁ + b • x₂ = x' ∧ a • y + b • y = y'
[PROOFSTEP]
refine' exists₅_congr fun a b ha hb hab => _
[GOAL]
case h.mk
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x₁ x₂ : E
y : F
x' : E
y' : F
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
⊢ a • x₁ + b • x₂ = x' ∧ y = y' ↔ a • x₁ + b • x₂ = x' ∧ a • y + b • y = y'
[PROOFSTEP]
rw [Convex.combo_self hab]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x : E
y₁ y₂ : F
⊢ (fun y => (x, y)) '' [y₁-[𝕜]y₂] = [(x, y₁)-[𝕜](x, y₂)]
[PROOFSTEP]
ext ⟨x', y'⟩
[GOAL]
case h.mk
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x : E
y₁ y₂ : F
x' : E
y' : F
⊢ (x', y') ∈ (fun y => (x, y)) '' [y₁-[𝕜]y₂] ↔ (x', y') ∈ [(x, y₁)-[𝕜](x, y₂)]
[PROOFSTEP]
simp_rw [Set.mem_image, segment, Set.mem_setOf, Prod.smul_mk, Prod.mk_add_mk, Prod.mk.inj_iff, ← exists_and_right,
@exists_comm F, exists_eq_left']
[GOAL]
case h.mk
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x : E
y₁ y₂ : F
x' : E
y' : F
⊢ (∃ b b_1 h h h, x = x' ∧ b • y₁ + b_1 • y₂ = y') ↔ ∃ a b h h h, a • x + b • x = x' ∧ a • y₁ + b • y₂ = y'
[PROOFSTEP]
refine' exists₅_congr fun a b ha hb hab => _
[GOAL]
case h.mk
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x : E
y₁ y₂ : F
x' : E
y' : F
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
⊢ x = x' ∧ a • y₁ + b • y₂ = y' ↔ a • x + b • x = x' ∧ a • y₁ + b • y₂ = y'
[PROOFSTEP]
rw [Convex.combo_self hab]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x₁ x₂ : E
y : F
⊢ (fun x => (x, y)) '' openSegment 𝕜 x₁ x₂ = openSegment 𝕜 (x₁, y) (x₂, y)
[PROOFSTEP]
ext ⟨x', y'⟩
[GOAL]
case h.mk
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x₁ x₂ : E
y : F
x' : E
y' : F
⊢ (x', y') ∈ (fun x => (x, y)) '' openSegment 𝕜 x₁ x₂ ↔ (x', y') ∈ openSegment 𝕜 (x₁, y) (x₂, y)
[PROOFSTEP]
simp_rw [Set.mem_image, openSegment, Set.mem_setOf, Prod.smul_mk, Prod.mk_add_mk, Prod.mk.inj_iff, ← exists_and_right,
@exists_comm E, exists_eq_left']
[GOAL]
case h.mk
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x₁ x₂ : E
y : F
x' : E
y' : F
⊢ (∃ b b_1 h h h, b • x₁ + b_1 • x₂ = x' ∧ y = y') ↔ ∃ a b h h h, a • x₁ + b • x₂ = x' ∧ a • y + b • y = y'
[PROOFSTEP]
refine' exists₅_congr fun a b ha hb hab => _
[GOAL]
case h.mk
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x₁ x₂ : E
y : F
x' : E
y' : F
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ a • x₁ + b • x₂ = x' ∧ y = y' ↔ a • x₁ + b • x₂ = x' ∧ a • y + b • y = y'
[PROOFSTEP]
rw [Convex.combo_self hab]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x : E
y₁ y₂ : F
⊢ (fun y => (x, y)) '' openSegment 𝕜 y₁ y₂ = openSegment 𝕜 (x, y₁) (x, y₂)
[PROOFSTEP]
ext ⟨x', y'⟩
[GOAL]
case h.mk
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x : E
y₁ y₂ : F
x' : E
y' : F
⊢ (x', y') ∈ (fun y => (x, y)) '' openSegment 𝕜 y₁ y₂ ↔ (x', y') ∈ openSegment 𝕜 (x, y₁) (x, y₂)
[PROOFSTEP]
simp_rw [Set.mem_image, openSegment, Set.mem_setOf, Prod.smul_mk, Prod.mk_add_mk, Prod.mk.inj_iff, ← exists_and_right,
@exists_comm F, exists_eq_left']
[GOAL]
case h.mk
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x : E
y₁ y₂ : F
x' : E
y' : F
⊢ (∃ b b_1 h h h, x = x' ∧ b • y₁ + b_1 • y₂ = y') ↔ ∃ a b h h h, a • x + b • x = x' ∧ a • y₁ + b • y₂ = y'
[PROOFSTEP]
refine' exists₅_congr fun a b ha hb hab => _
[GOAL]
case h.mk
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝⁴ : OrderedSemiring 𝕜
inst✝³ : AddCommMonoid E
inst✝² : AddCommMonoid F
inst✝¹ : Module 𝕜 E
inst✝ : Module 𝕜 F
x : E
y₁ y₂ : F
x' : E
y' : F
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ x = x' ∧ a • y₁ + b • y₂ = y' ↔ a • x + b • x = x' ∧ a • y₁ + b • y₂ = y'
[PROOFSTEP]
rw [Convex.combo_self hab]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : (i : ι) → AddCommMonoid (π i)
inst✝ : (i : ι) → Module 𝕜 (π i)
s : Set ι
x y : (i : ι) → π i
⊢ [x-[𝕜]y] ⊆ pi s fun i => [x i-[𝕜]y i]
[PROOFSTEP]
rintro z ⟨a, b, ha, hb, hab, hz⟩ i -
[GOAL]
case intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : (i : ι) → AddCommMonoid (π i)
inst✝ : (i : ι) → Module 𝕜 (π i)
s : Set ι
x y z : (i : ι) → π i
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
hz : a • x + b • y = z
i : ι
⊢ z i ∈ (fun i => [x i-[𝕜]y i]) i
[PROOFSTEP]
exact ⟨a, b, ha, hb, hab, congr_fun hz i⟩
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : (i : ι) → AddCommMonoid (π i)
inst✝ : (i : ι) → Module 𝕜 (π i)
s : Set ι
x y : (i : ι) → π i
⊢ openSegment 𝕜 x y ⊆ pi s fun i => openSegment 𝕜 (x i) (y i)
[PROOFSTEP]
rintro z ⟨a, b, ha, hb, hab, hz⟩ i -
[GOAL]
case intro.intro.intro.intro.intro
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝² : OrderedSemiring 𝕜
inst✝¹ : (i : ι) → AddCommMonoid (π i)
inst✝ : (i : ι) → Module 𝕜 (π i)
s : Set ι
x y z : (i : ι) → π i
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
hz : a • x + b • y = z
i : ι
⊢ z i ∈ (fun i => openSegment 𝕜 (x i) (y i)) i
[PROOFSTEP]
exact ⟨a, b, ha, hb, hab, congr_fun hz i⟩
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : (i : ι) → AddCommMonoid (π i)
inst✝¹ : (i : ι) → Module 𝕜 (π i)
s : Set ι
inst✝ : DecidableEq ι
i : ι
x₁ x₂ : π i
y : (i : ι) → π i
⊢ update y i '' [x₁-[𝕜]x₂] = [update y i x₁-[𝕜]update y i x₂]
[PROOFSTEP]
ext z
[GOAL]
case h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : (i : ι) → AddCommMonoid (π i)
inst✝¹ : (i : ι) → Module 𝕜 (π i)
s : Set ι
inst✝ : DecidableEq ι
i : ι
x₁ x₂ : π i
y z : (a : ι) → π a
⊢ z ∈ update y i '' [x₁-[𝕜]x₂] ↔ z ∈ [update y i x₁-[𝕜]update y i x₂]
[PROOFSTEP]
simp_rw [Set.mem_image, segment, Set.mem_setOf, ← update_smul, ← update_add, update_eq_iff, ← exists_and_right,
@exists_comm (π i), exists_eq_left']
[GOAL]
case h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : (i : ι) → AddCommMonoid (π i)
inst✝¹ : (i : ι) → Module 𝕜 (π i)
s : Set ι
inst✝ : DecidableEq ι
i : ι
x₁ x₂ : π i
y z : (a : ι) → π a
⊢ (∃ b b_1 h h h, b • x₁ + b_1 • x₂ = z i ∧ ∀ (x : ι), x ≠ i → y x = z x) ↔
∃ a b h h h, a • x₁ + b • x₂ = z i ∧ ∀ (x : ι), x ≠ i → (a • y + b • y) x = z x
[PROOFSTEP]
refine' exists₅_congr fun a b ha hb hab => _
[GOAL]
case h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : (i : ι) → AddCommMonoid (π i)
inst✝¹ : (i : ι) → Module 𝕜 (π i)
s : Set ι
inst✝ : DecidableEq ι
i : ι
x₁ x₂ : π i
y z : (a : ι) → π a
a b : 𝕜
ha : 0 ≤ a
hb : 0 ≤ b
hab : a + b = 1
⊢ (a • x₁ + b • x₂ = z i ∧ ∀ (x : ι), x ≠ i → y x = z x) ↔
a • x₁ + b • x₂ = z i ∧ ∀ (x : ι), x ≠ i → (a • y + b • y) x = z x
[PROOFSTEP]
rw [Convex.combo_self hab]
[GOAL]
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : (i : ι) → AddCommMonoid (π i)
inst✝¹ : (i : ι) → Module 𝕜 (π i)
s : Set ι
inst✝ : DecidableEq ι
i : ι
x₁ x₂ : π i
y : (i : ι) → π i
⊢ update y i '' openSegment 𝕜 x₁ x₂ = openSegment 𝕜 (update y i x₁) (update y i x₂)
[PROOFSTEP]
ext z
[GOAL]
case h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : (i : ι) → AddCommMonoid (π i)
inst✝¹ : (i : ι) → Module 𝕜 (π i)
s : Set ι
inst✝ : DecidableEq ι
i : ι
x₁ x₂ : π i
y z : (a : ι) → π a
⊢ z ∈ update y i '' openSegment 𝕜 x₁ x₂ ↔ z ∈ openSegment 𝕜 (update y i x₁) (update y i x₂)
[PROOFSTEP]
simp_rw [Set.mem_image, openSegment, Set.mem_setOf, ← update_smul, ← update_add, update_eq_iff, ← exists_and_right,
@exists_comm (π i), exists_eq_left']
[GOAL]
case h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : (i : ι) → AddCommMonoid (π i)
inst✝¹ : (i : ι) → Module 𝕜 (π i)
s : Set ι
inst✝ : DecidableEq ι
i : ι
x₁ x₂ : π i
y z : (a : ι) → π a
⊢ (∃ b b_1 h h h, b • x₁ + b_1 • x₂ = z i ∧ ∀ (x : ι), x ≠ i → y x = z x) ↔
∃ a b h h h, a • x₁ + b • x₂ = z i ∧ ∀ (x : ι), x ≠ i → (a • y + b • y) x = z x
[PROOFSTEP]
refine' exists₅_congr fun a b ha hb hab => _
[GOAL]
case h
𝕜 : Type u_1
E : Type u_2
F : Type u_3
G : Type u_4
ι : Type u_5
π : ι → Type u_6
inst✝³ : OrderedSemiring 𝕜
inst✝² : (i : ι) → AddCommMonoid (π i)
inst✝¹ : (i : ι) → Module 𝕜 (π i)
s : Set ι
inst✝ : DecidableEq ι
i : ι
x₁ x₂ : π i
y z : (a : ι) → π a
a b : 𝕜
ha : 0 < a
hb : 0 < b
hab : a + b = 1
⊢ (a • x₁ + b • x₂ = z i ∧ ∀ (x : ι), x ≠ i → y x = z x) ↔
a • x₁ + b • x₂ = z i ∧ ∀ (x : ι), x ≠ i → (a • y + b • y) x = z x
[PROOFSTEP]
rw [Convex.combo_self hab]
|
Address(Frontera) is a residential street in East Davis.
Intersecting Streets
Pastal Way
Escolar Court
Santander Court
Caceres Way
Vigo Court
|
[STATEMENT]
lemma "filter_bool_list bs xs = map snd (filter fst (zip bs xs))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. filter_bool_list bs xs = map snd (filter fst (zip bs xs))
[PROOF STEP]
by(induct bs xs rule: filter_bool_list.induct) auto |
module Function where
import Lvl
open import Type
-- The domain type of a function.
domain : ∀{ℓ₁ ℓ₂} {A : Type{ℓ₁}}{B : Type{ℓ₂}} → (A → B) → Type{ℓ₁}
domain{A = A} _ = A
-- The codomain type of a function.
codomain : ∀{ℓ₁ ℓ₂} {A : Type{ℓ₁}}{B : Type{ℓ₂}} → (A → B) → Type{ℓ₂}
codomain{B = B} _ = B
|
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import category_theory.limits.shapes.split_coequalizer
import category_theory.limits.preserves.basic
/-!
# Preserving (co)equalizers
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Constructions to relate the notions of preserving (co)equalizers and reflecting (co)equalizers
to concrete (co)forks.
In particular, we show that `equalizer_comparison f g G` is an isomorphism iff `G` preserves
the limit of the parallel pair `f,g`, as well as the dual result.
-/
noncomputable theory
universes w v₁ v₂ u₁ u₂
open category_theory category_theory.category category_theory.limits
variables {C : Type u₁} [category.{v₁} C]
variables {D : Type u₂} [category.{v₂} D]
variables (G : C ⥤ D)
namespace category_theory.limits
section equalizers
variables {X Y Z : C} {f g : X ⟶ Y} {h : Z ⟶ X} (w : h ≫ f = h ≫ g)
/--
The map of a fork is a limit iff the fork consisting of the mapped morphisms is a limit. This
essentially lets us commute `fork.of_ι` with `functor.map_cone`.
-/
def is_limit_map_cone_fork_equiv :
is_limit (G.map_cone (fork.of_ι h w)) ≃
is_limit (fork.of_ι (G.map h) (by simp only [←G.map_comp, w]) : fork (G.map f) (G.map g)) :=
(is_limit.postcompose_hom_equiv (diagram_iso_parallel_pair _) _).symm.trans
(is_limit.equiv_iso_limit (fork.ext (iso.refl _) (by { simp [fork.ι] })))
/-- The property of preserving equalizers expressed in terms of forks. -/
def is_limit_fork_map_of_is_limit [preserves_limit (parallel_pair f g) G]
(l : is_limit (fork.of_ι h w)) :
is_limit (fork.of_ι (G.map h) (by simp only [←G.map_comp, w]) : fork (G.map f) (G.map g)) :=
is_limit_map_cone_fork_equiv G w (preserves_limit.preserves l)
/-- The property of reflecting equalizers expressed in terms of forks. -/
def is_limit_of_is_limit_fork_map [reflects_limit (parallel_pair f g) G]
(l : is_limit (fork.of_ι (G.map h) (by simp only [←G.map_comp, w]) : fork (G.map f) (G.map g))) :
is_limit (fork.of_ι h w) :=
reflects_limit.reflects ((is_limit_map_cone_fork_equiv G w).symm l)
variables (f g) [has_equalizer f g]
/--
If `G` preserves equalizers and `C` has them, then the fork constructed of the mapped morphisms of
a fork is a limit.
-/
def is_limit_of_has_equalizer_of_preserves_limit
[preserves_limit (parallel_pair f g) G] :
is_limit (fork.of_ι (G.map (equalizer.ι f g))
(by simp only [←G.map_comp, equalizer.condition])) :=
is_limit_fork_map_of_is_limit G _ (equalizer_is_equalizer f g)
variables [has_equalizer (G.map f) (G.map g)]
/--
If the equalizer comparison map for `G` at `(f,g)` is an isomorphism, then `G` preserves the
equalizer of `(f,g)`.
-/
def preserves_equalizer.of_iso_comparison [i : is_iso (equalizer_comparison f g G)] :
preserves_limit (parallel_pair f g) G :=
begin
apply preserves_limit_of_preserves_limit_cone (equalizer_is_equalizer f g),
apply (is_limit_map_cone_fork_equiv _ _).symm _,
apply is_limit.of_point_iso (limit.is_limit (parallel_pair (G.map f) (G.map g))),
apply i,
end
variables [preserves_limit (parallel_pair f g) G]
/--
If `G` preserves the equalizer of `(f,g)`, then the equalizer comparison map for `G` at `(f,g)` is
an isomorphism.
-/
def preserves_equalizer.iso :
G.obj (equalizer f g) ≅ equalizer (G.map f) (G.map g) :=
is_limit.cone_point_unique_up_to_iso
(is_limit_of_has_equalizer_of_preserves_limit G f g)
(limit.is_limit _)
@[simp]
lemma preserves_equalizer.iso_hom :
(preserves_equalizer.iso G f g).hom = equalizer_comparison f g G :=
rfl
instance : is_iso (equalizer_comparison f g G) :=
begin
rw ← preserves_equalizer.iso_hom,
apply_instance
end
end equalizers
section coequalizers
variables {X Y Z : C} {f g : X ⟶ Y} {h : Y ⟶ Z} (w : f ≫ h = g ≫ h)
/--
The map of a cofork is a colimit iff the cofork consisting of the mapped morphisms is a colimit.
This essentially lets us commute `cofork.of_π` with `functor.map_cocone`.
-/
def is_colimit_map_cocone_cofork_equiv :
is_colimit (G.map_cocone (cofork.of_π h w)) ≃
is_colimit (cofork.of_π (G.map h) (by simp only [←G.map_comp, w]) : cofork (G.map f) (G.map g)) :=
(is_colimit.precompose_inv_equiv (diagram_iso_parallel_pair _) _).symm.trans $
is_colimit.equiv_iso_colimit $ cofork.ext (iso.refl _) $
begin
dsimp only [cofork.π, cofork.of_π_ι_app],
dsimp, rw [category.comp_id, category.id_comp]
end
/-- The property of preserving coequalizers expressed in terms of coforks. -/
def is_colimit_cofork_map_of_is_colimit [preserves_colimit (parallel_pair f g) G]
(l : is_colimit (cofork.of_π h w)) :
is_colimit (cofork.of_π (G.map h) (by simp only [←G.map_comp, w]) : cofork (G.map f) (G.map g)) :=
is_colimit_map_cocone_cofork_equiv G w (preserves_colimit.preserves l)
/-- The property of reflecting coequalizers expressed in terms of coforks. -/
def is_colimit_of_is_colimit_cofork_map [reflects_colimit (parallel_pair f g) G]
(l : is_colimit (cofork.of_π (G.map h) (by simp only [←G.map_comp, w])
: cofork (G.map f) (G.map g))) :
is_colimit (cofork.of_π h w) :=
reflects_colimit.reflects ((is_colimit_map_cocone_cofork_equiv G w).symm l)
variables (f g) [has_coequalizer f g]
/--
If `G` preserves coequalizers and `C` has them, then the cofork constructed of the mapped morphisms
of a cofork is a colimit.
-/
def is_colimit_of_has_coequalizer_of_preserves_colimit
[preserves_colimit (parallel_pair f g) G] :
is_colimit (cofork.of_π (G.map (coequalizer.π f g)) _) :=
is_colimit_cofork_map_of_is_colimit G _ (coequalizer_is_coequalizer f g)
variables [has_coequalizer (G.map f) (G.map g)]
/--
If the coequalizer comparison map for `G` at `(f,g)` is an isomorphism, then `G` preserves the
coequalizer of `(f,g)`.
-/
def of_iso_comparison [i : is_iso (coequalizer_comparison f g G)] :
preserves_colimit (parallel_pair f g) G :=
begin
apply preserves_colimit_of_preserves_colimit_cocone (coequalizer_is_coequalizer f g),
apply (is_colimit_map_cocone_cofork_equiv _ _).symm _,
apply is_colimit.of_point_iso (colimit.is_colimit (parallel_pair (G.map f) (G.map g))),
apply i,
end
variables [preserves_colimit (parallel_pair f g) G]
/--
If `G` preserves the coequalizer of `(f,g)`, then the coequalizer comparison map for `G` at `(f,g)`
is an isomorphism.
-/
def preserves_coequalizer.iso :
coequalizer (G.map f) (G.map g) ≅ G.obj (coequalizer f g) :=
is_colimit.cocone_point_unique_up_to_iso
(colimit.is_colimit _)
(is_colimit_of_has_coequalizer_of_preserves_colimit G f g)
@[simp]
lemma preserves_coequalizer.iso_hom :
(preserves_coequalizer.iso G f g).hom = coequalizer_comparison f g G :=
rfl
instance : is_iso (coequalizer_comparison f g G) :=
begin
rw ← preserves_coequalizer.iso_hom,
apply_instance
end
instance map_π_epi : epi (G.map (coequalizer.π f g)) :=
⟨λ W h k, by { rw ←ι_comp_coequalizer_comparison, apply (cancel_epi _).1, apply epi_comp }⟩
@[reassoc]
lemma map_π_preserves_coequalizer_inv :
G.map (coequalizer.π f g) ≫ (preserves_coequalizer.iso G f g).inv =
coequalizer.π (G.map f) (G.map g) :=
begin
rw [←ι_comp_coequalizer_comparison_assoc, ←preserves_coequalizer.iso_hom,
iso.hom_inv_id, comp_id],
end
@[reassoc]
lemma map_π_preserves_coequalizer_inv_desc
{W : D} (k : G.obj Y ⟶ W) (wk : G.map f ≫ k = G.map g ≫ k) :
G.map (coequalizer.π f g) ≫ (preserves_coequalizer.iso G f g).inv ≫ coequalizer.desc k wk = k :=
by rw [←category.assoc, map_π_preserves_coequalizer_inv, coequalizer.π_desc]
@[reassoc]
lemma map_π_preserves_coequalizer_inv_colim_map
{X' Y' : D} (f' g' : X' ⟶ Y') [has_coequalizer f' g'] (p : G.obj X ⟶ X') (q : G.obj Y ⟶ Y')
(wf : (G.map f) ≫ q = p ≫ f') (wg : (G.map g) ≫ q = p ≫ g') :
G.map (coequalizer.π f g) ≫ (preserves_coequalizer.iso G f g).inv ≫
colim_map (parallel_pair_hom (G.map f) (G.map g) f' g' p q wf wg) =
q ≫ coequalizer.π f' g' :=
by rw [←category.assoc, map_π_preserves_coequalizer_inv, ι_colim_map, parallel_pair_hom_app_one]
@[reassoc]
lemma map_π_preserves_coequalizer_inv_colim_map_desc
{X' Y' : D} (f' g' : X' ⟶ Y') [has_coequalizer f' g'] (p : G.obj X ⟶ X') (q : G.obj Y ⟶ Y')
(wf : (G.map f) ≫ q = p ≫ f') (wg : (G.map g) ≫ q = p ≫ g')
{Z' : D} (h : Y' ⟶ Z') (wh : f' ≫ h = g' ≫ h) :
G.map (coequalizer.π f g) ≫ (preserves_coequalizer.iso G f g).inv ≫
colim_map (parallel_pair_hom (G.map f) (G.map g) f' g' p q wf wg) ≫
coequalizer.desc h wh =
q ≫ h :=
begin
slice_lhs 1 3 { rw map_π_preserves_coequalizer_inv_colim_map },
slice_lhs 2 3 { rw coequalizer.π_desc },
end
/-- Any functor preserves coequalizers of split pairs. -/
@[priority 1]
instance preserves_split_coequalizers (f g : X ⟶ Y) [has_split_coequalizer f g] :
preserves_colimit (parallel_pair f g) G :=
begin
apply preserves_colimit_of_preserves_colimit_cocone
((has_split_coequalizer.is_split_coequalizer f g).is_coequalizer),
apply (is_colimit_map_cocone_cofork_equiv G _).symm
((has_split_coequalizer.is_split_coequalizer f g).map G).is_coequalizer,
end
end coequalizers
end category_theory.limits
|
/-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import ring_theory.finiteness
import linear_algebra.dimension
/-!
# A module over a division ring is noetherian if and only if it is finite.
-/
universes u v
open_locale classical cardinal
open cardinal submodule module function
namespace is_noetherian
variables {K : Type u} {V : Type v} [division_ring K] [add_comm_group V] [module K V]
-- PROJECT: Show all division rings are noetherian.
-- This is currently annoying because we only have ideal of commutative rings.
variables [is_noetherian_ring K]
/--
A module over a division ring is noetherian if and only if
its dimension (as a cardinal) is strictly less than the first infinite cardinal `ω`.
-/
lemma iff_dim_lt_omega : is_noetherian K V ↔ module.rank K V < ω :=
begin
let b := basis.of_vector_space K V,
rw [← b.mk_eq_dim'', lt_omega_iff_finite],
split,
{ introI,
exact finite_of_linear_independent (basis.of_vector_space_index.linear_independent K V) },
{ assume hbfinite,
refine @is_noetherian_of_linear_equiv K (⊤ : submodule K V) V _
_ _ _ _ (linear_equiv.of_top _ rfl) (id _),
refine is_noetherian_of_fg_of_noetherian _ ⟨set.finite.to_finset hbfinite, _⟩,
rw [set.finite.coe_to_finset, ← b.span_eq, basis.coe_of_vector_space, subtype.range_coe] }
end
variables (K V)
/-- The dimension of a noetherian module over a division ring, as a cardinal,
is strictly less than the first infinite cardinal `ω`. -/
lemma dim_lt_omega : ∀ [is_noetherian K V], module.rank K V < ω :=
is_noetherian.iff_dim_lt_omega.1
variables {K V}
/-- In a noetherian module over a division ring, all bases are indexed by a finite type. -/
noncomputable def fintype_basis_index {ι : Type*} [is_noetherian K V] (b : basis ι K V) :
fintype ι :=
b.fintype_index_of_dim_lt_omega (dim_lt_omega K V)
/-- In a noetherian module over a division ring,
`basis.of_vector_space` is indexed by a finite type. -/
noncomputable instance [is_noetherian K V] : fintype (basis.of_vector_space_index K V) :=
fintype_basis_index (basis.of_vector_space K V)
/-- In a noetherian module over a division ring,
if a basis is indexed by a set, that set is finite. -/
lemma finite_basis_index {ι : Type*} {s : set ι} [is_noetherian K V] (b : basis s K V) :
s.finite :=
b.finite_index_of_dim_lt_omega (dim_lt_omega K V)
variables (K V)
/-- In a noetherian module over a division ring,
there exists a finite basis. This is the indexing `finset`. -/
noncomputable def finset_basis_index [is_noetherian K V] :
finset V :=
(finite_basis_index (basis.of_vector_space K V)).to_finset
@[simp] lemma coe_finset_basis_index [is_noetherian K V] :
(↑(finset_basis_index K V) : set V) = basis.of_vector_space_index K V :=
set.finite.coe_to_finset _
@[simp] lemma coe_sort_finset_basis_index [is_noetherian K V] :
((finset_basis_index K V) : Type*) = basis.of_vector_space_index K V :=
set.finite.coe_sort_to_finset _
/--
In a noetherian module over a division ring, there exists a finite basis.
This is indexed by the `finset` `finite_dimensional.finset_basis_index`.
This is in contrast to the result `finite_basis_index (basis.of_vector_space K V)`,
which provides a set and a `set.finite`.
-/
noncomputable def finset_basis [is_noetherian K V] :
basis (finset_basis_index K V) K V :=
(basis.of_vector_space K V).reindex (by simp)
@[simp] lemma range_finset_basis [is_noetherian K V] :
set.range (finset_basis K V) = basis.of_vector_space_index K V :=
by rw [finset_basis, basis.range_reindex, basis.range_of_vector_space]
variables {K V}
/-- A module over a division ring is noetherian if and only if it is finitely generated. -/
lemma iff_fg :
is_noetherian K V ↔ module.finite K V :=
begin
split,
{ introI h,
exact ⟨⟨finset_basis_index K V, by { convert (finset_basis K V).span_eq, simp }⟩⟩ },
{ rintros ⟨s, hs⟩,
rw [is_noetherian.iff_dim_lt_omega, ← dim_top, ← hs],
exact lt_of_le_of_lt (dim_span_le _) (lt_omega_iff_finite.2 (set.finite_mem_finset s)) }
end
end is_noetherian
|
-- import topology.sheaves.sheaf
-- import topology.sheaves.sheaf_condition.unique_gluing
-- import sort
-- import oc
-- import lemmas.lemmas
-- import data.nat.parity
-- import algebra.category.Group.limits
-- import algebra.category.Group.abelian
-- import simplex
-- import tactic
-- section
-- open category_theory Top Top.sheaf topological_space finset simplex
-- open opposite
-- open_locale big_operators
-- universe u
-- variable (X : Top.{u})
-- variable {X}
-- variable (𝓕 : sheaf Ab X)
-- variable (𝔘 : oc X)
-- local notation `ι ` := 𝔘.ι
-- local notation `𝓕.obj` := 𝓕.1.obj
-- local notation `𝓕.map` := 𝓕.1.map
-- namespace Cech
-- def carrier (n : ℕ) : Type* :=
-- Π σ : simplex 𝔘 n, 𝓕.obj (op $ σ.face)
-- instance (n : ℕ) : has_zero (carrier 𝓕 𝔘 n) :=
-- { zero := λ σ, 0 }
-- instance (n : ℕ) : has_add (carrier 𝓕 𝔘 n) :=
-- { add := λ f g σ, f σ + g σ }
-- lemma add_assoc' {n : ℕ} (f g h : carrier 𝓕 𝔘 n) : f + g + h = f + (g + h) :=
-- funext $ λ σ, add_assoc _ _ _
-- lemma zero_add' {n : ℕ} (f : carrier 𝓕 𝔘 n) : 0 + f = f :=
-- funext $ λ σ, zero_add _
-- lemma add_zero' {n : ℕ} (f : carrier 𝓕 𝔘 n) : f + 0 = f :=
-- funext $ λ σ, add_zero _
-- @[simp] lemma zero_apply {n : ℕ} (σ : simplex 𝔘 n) :
-- (0 : carrier 𝓕 𝔘 n) σ = 0 :=
-- pi.zero_apply _
-- @[simp] lemma add_apply {n : ℕ} (x y : carrier 𝓕 𝔘 n) (σ : simplex 𝔘 n) :
-- (x + y) σ = x σ + y σ :=
-- pi.add_apply _ _ _
-- section smul
-- variables (α : Type*) [Π U : (opens X)ᵒᵖ, has_scalar α (𝓕.obj U)]
-- instance (n : ℕ) : has_scalar α (carrier 𝓕 𝔘 n) :=
-- { smul := λ a f σ, a • f σ }
-- end smul
-- instance (n : ℕ) : add_monoid (carrier 𝓕 𝔘 n) :=
-- { add := (+),
-- add_assoc := add_assoc' _ _,
-- zero := 0,
-- zero_add := zero_add' _ _,
-- add_zero := add_zero' _ _,
-- nsmul := (•),
-- nsmul_zero' := λ f, funext $ λ σ, by simp,
-- nsmul_succ' := λ m f, funext $ λ σ, by simp [nat.succ_eq_add_one, add_nsmul, one_nsmul, add_comm] }
-- instance (n : ℕ) : has_neg (carrier 𝓕 𝔘 n) :=
-- { neg := λ f σ, - f σ }
-- instance (n : ℕ) : add_comm_group (carrier 𝓕 𝔘 n) :=
-- { neg := has_neg.neg,
-- add_left_neg := λ f, funext $ λ σ, by simp,
-- add_comm := λ f g, funext $ λ σ, by simp [add_comm],
-- ..(_ : add_monoid (carrier 𝓕 𝔘 n))}
-- end Cech
-- section
-- variable {X}
-- def C (n : ℕ) : Ab :=
-- ⟨Cech.carrier 𝓕 𝔘 n⟩
-- lemma Cech.finset_sum_apply (n : ℕ) {α : Type*} [decidable_eq α]
-- (f : α → C 𝓕 𝔘 n) (s : finset α) (σ : simplex 𝔘 n) :
-- (∑ i in s, f i) σ = ∑ i in s, f i σ :=
-- begin
-- induction s using finset.induction_on with a s ha ih,
-- { simp, },
-- { rw [finset.sum_insert ha, finset.sum_insert ha, pi.add_apply, ih] },
-- end
-- section d0
-- variables {𝓕 𝔘}
-- def d0 : C 𝓕 𝔘 0 ⟶ C 𝓕 𝔘 1 :=
-- { to_fun := λ f σ,
-- 𝓕.map (σ.der (nat.zero_lt_succ 0) ⟨0, _⟩).op (f (σ.ignore (nat.zero_lt_succ 0) 0)) -
-- 𝓕.map (σ.der (nat.zero_lt_succ 0) ⟨1, _⟩).op (f (σ.ignore (nat.zero_lt_succ 0) 1)),
-- map_zero' := funext $ λ σ , begin
-- rw [Cech.zero_apply, Cech.zero_apply, map_zero, map_zero, sub_zero, Cech.zero_apply],
-- end,
-- map_add' := λ x y, funext $ λ σ, begin
-- rw [Cech.add_apply, map_add, Cech.add_apply, map_add, Cech.add_apply],
-- dsimp only,
-- abel,
-- end }
-- end d0
-- namespace d_pos_def
-- variables {n : ℕ} (hn : 0 < n)
-- def to_fun.component (m : fin n.succ) : C 𝓕 𝔘 n.pred → C 𝓕 𝔘 n := λ f σ,
-- ite (even m.1) id has_neg.neg (𝓕.map (σ.der hn m).op (f (σ.ignore hn m)))
-- def to_fun : C 𝓕 𝔘 n.pred → C 𝓕 𝔘 n := λ f,
-- ∑ i in (range n.succ).attach, d_pos_def.to_fun.component 𝓕 𝔘 hn ⟨i.1, mem_range.mp i.2⟩ f
-- def map_zero' : to_fun 𝓕 𝔘 hn 0 = 0 := finset.sum_eq_zero $ λ ⟨m, hm⟩ h,
-- begin
-- rw mem_range at hm,
-- unfold to_fun.component,
-- split_ifs;
-- ext σ;
-- simp,
-- end
-- def map_add' (x y : C 𝓕 𝔘 n.pred) :
-- to_fun 𝓕 𝔘 hn (x + y) = to_fun 𝓕 𝔘 hn x + to_fun 𝓕 𝔘 hn y :=
-- begin
-- unfold to_fun,
-- rw ← sum_add_distrib,
-- apply sum_congr rfl,
-- rintros m hm,
-- unfold to_fun.component,
-- split_ifs,
-- { ext σ, simp only [Cech.add_apply, map_add, id], },
-- { ext σ,
-- change - _ = - _ + - _,
-- rw [neg_eq_iff_neg_eq, neg_add, neg_neg, neg_neg, Cech.add_apply, map_add] },
-- end
-- end d_pos_def
-- variables {𝓕 𝔘}
-- def d_pos {n : ℕ} (hn : 0 < n) : C 𝓕 𝔘 n.pred ⟶ C 𝓕 𝔘 n :=
-- { to_fun := d_pos_def.to_fun 𝓕 𝔘 hn,
-- map_zero' := d_pos_def.map_zero' _ _ _,
-- map_add' := d_pos_def.map_add' _ _ _ }
-- lemma d_pos.def {n : ℕ} (hn : 0 < n) (f : C 𝓕 𝔘 n.pred) (σ : simplex 𝔘 n) :
-- d_pos hn f σ =
-- ∑ i in (range n.succ).attach,
-- ite (even i.1) id has_neg.neg
-- (𝓕.map (σ.der hn ⟨i.1, mem_range.mp i.2⟩).op (f (σ.ignore hn ⟨i.1, mem_range.mp i.2⟩))) :=
-- begin
-- dsimp only [d_pos],
-- -- unfold d_pos d_pos.to_fun,
-- rw [add_monoid_hom.coe_mk],
-- dsimp only [d_pos_def.to_fun],
-- rw [Cech.finset_sum_apply],
-- refine finset.sum_congr rfl (λ m hm, _),
-- refl,
-- end
-- lemma d_pos_01 : @d_pos X 𝓕 𝔘 1 (nat.zero_lt_succ 0) = d0 :=
-- begin
-- ext f σ,
-- rw d_pos.def,
-- change _ = _ - _,
-- generalize_proofs h1 h2,
-- transitivity ∑ i in finset.attach {0, 1}, ite (even i.1) id has_neg.neg
-- (𝓕.map (σ.der h2 ⟨i.1, mem_range.mp i.2⟩).op (f (σ.ignore h2 ⟨i.1, mem_range.mp i.2⟩))),
-- { apply sum_congr,
-- refl,
-- intros x hx,
-- refl, },
-- { rw [finset.attach_insert, finset.sum_insert],
-- dsimp only,
-- rw [if_pos even_zero, id],
-- rw [finset.sum_image, sub_eq_add_neg],
-- apply congr_arg2 (+),
-- { refl, },
-- { dsimp only,
-- transitivity ∑ (i : ℕ) in {1}, - (𝓕.val.map (der h2 σ ⟨1, _x⟩).op) (f (ignore h2 σ 1)),
-- { conv_rhs { rw ← finset.sum_attach },
-- apply finset.sum_congr rfl,
-- rintros ⟨x, h⟩ hx,
-- rw mem_singleton at h,
-- rw if_neg,
-- dsimp only,
-- subst h,
-- refl,
-- subst h,
-- exact nat.not_even_one, },
-- rw finset.sum_singleton },
-- { rintros ⟨x, ⟨h1⟩⟩ trivial ⟨y, ⟨h2⟩⟩ trivial h3,
-- subst h1,
-- subst h2,
-- rw subtype.ext_iff_val at h3 ⊢,
-- exact h3,
-- rw subtype.ext_iff_val at h3 ⊢,
-- exact h3,
-- rw subtype.ext_iff_val at h3 ⊢,
-- exact h3, },
-- { intros r,
-- rw finset.mem_image at r,
-- rcases r with ⟨x, h1, h2⟩,
-- have := x.2,
-- simp only [mem_singleton] at this,
-- simp only [this] at h2,
-- linarith, } },
-- end
-- abbreviation dd_pos {n : ℕ} (hn : 0 < n) (f : C 𝓕 𝔘 n.pred) : C 𝓕 𝔘 n.succ := d_pos (nat.zero_lt_succ _) (d_pos hn f)
-- section lemmas
-- variables {n : ℕ} (hn : 0 < n) (f : C 𝓕 𝔘 n.pred) (σ : simplex 𝔘 n.succ)
-- lemma dd_pos.eq1 :
-- dd_pos hn f σ =
-- d_pos (nat.zero_lt_succ _) (d_pos hn f) σ := rfl
-- lemma dd_pos.eq2 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- (ite (even i.1) id has_neg.neg)
-- (𝓕.map (σ.der (nat.zero_lt_succ _) ⟨i.1, mem_range.mp i.2⟩).op
-- ((d_pos hn f) (σ.ignore (nat.zero_lt_succ _) ⟨i.1, mem_range.mp i.2⟩))) :=
-- by rw [dd_pos.eq1, d_pos.def]
-- lemma dd_pos.eq3 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- ite (even i.1) id has_neg.neg
-- (𝓕.map (σ.der (nat.zero_lt_succ _) ⟨i.1, mem_range.mp i.2⟩).op
-- (∑ j in (range n.succ).attach,
-- ite (even j.1) id has_neg.neg
-- (𝓕.map ((σ.ignore (nat.zero_lt_succ _) ⟨i.1, mem_range.mp i.2⟩).der hn ⟨j.1, mem_range.mp j.2⟩).op
-- (f ((σ.ignore (nat.zero_lt_succ _) ⟨i.1, mem_range.mp i.2⟩).ignore hn ⟨j.1, mem_range.mp j.2⟩))))) :=
-- begin
-- rw dd_pos.eq2,
-- apply sum_congr rfl (λ m hm, _),
-- apply congr_arg,
-- congr' 1,
-- rw d_pos.def,
-- end
-- lemma dd_pos.eq4 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- ite (even i.1) id has_neg.neg
-- (∑ j in (range n.succ).attach,
-- 𝓕.map (σ.der (nat.zero_lt_succ _) ⟨i.1, mem_range.mp i.2⟩).op
-- (ite (even j.1) id has_neg.neg
-- (𝓕.map ((σ.ignore (nat.zero_lt_succ _) ⟨i.1, mem_range.mp i.2⟩).der hn ⟨j.1, mem_range.mp j.2⟩).op
-- (f ((σ.ignore (nat.zero_lt_succ _) ⟨i.1, mem_range.mp i.2⟩).ignore hn ⟨j.1, mem_range.mp j.2⟩))))) :=
-- begin
-- rw dd_pos.eq3,
-- apply sum_congr rfl (λ m hm, _),
-- apply congr_arg,
-- rw add_monoid_hom.map_sum,
-- end
-- lemma dd_pos.eq5 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- ite (even i.1) id has_neg.neg
-- (∑ j in (range n.succ).attach,
-- ite (even j.1) id has_neg.neg
-- (𝓕.map (σ.der (nat.zero_lt_succ _) ⟨i.1, mem_range.mp i.2⟩).op
-- (𝓕.map ((σ.ignore (nat.zero_lt_succ _) ⟨i.1, mem_range.mp i.2⟩).der hn ⟨j.1, mem_range.mp j.2⟩).op
-- (f ((σ.ignore (nat.zero_lt_succ _) ⟨i.1, mem_range.mp i.2⟩).ignore hn ⟨j.1, mem_range.mp j.2⟩))))) :=
-- begin
-- rw dd_pos.eq4,
-- apply sum_congr rfl (λ m hm, _),
-- apply congr_arg,
-- apply sum_congr rfl (λ m' hm', _),
-- by_cases e' : even m'.1,
-- { conv_rhs { rw [if_pos e', id] },
-- congr' 1,
-- rw [if_pos e', id],
-- },
-- { conv_rhs { rw [if_neg e', ← map_neg] },
-- congr' 1,
-- rw [if_neg e'], },
-- end
-- lemma dd_pos.eq6₀ :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- ite (even i.1) id has_neg.neg
-- (∑ j in (range n.succ).attach,
-- ite (even j.1) id has_neg.neg
-- (𝓕.map (((σ.ignore (nat.zero_lt_succ _) ⟨i.1, mem_range.mp i.2⟩).der hn ⟨j.1, mem_range.mp j.2⟩).op ≫ (σ.der (nat.zero_lt_succ _) ⟨i.1, mem_range.mp i.2⟩).op)
-- (f ((σ.ignore (nat.zero_lt_succ _) ⟨i.1, mem_range.mp i.2⟩).ignore hn ⟨j.1, mem_range.mp j.2⟩)))) :=
-- begin
-- rw dd_pos.eq5,
-- apply sum_congr rfl (λ m hm, _),
-- apply congr_arg,
-- apply sum_congr rfl (λ m' hm', _),
-- apply congr_arg,
-- rw category_theory.functor.map_comp,
-- refl,
-- end
-- lemma dd_pos.eq6₁ :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- ite (even i.1) id has_neg.neg
-- (∑ j in (range n.succ).attach,
-- ite (even j.1) id has_neg.neg
-- (𝓕.map ((σ.der (nat.zero_lt_succ _) ⟨i.1, mem_range.mp i.2⟩) ≫ ((σ.ignore (nat.zero_lt_succ _) ⟨i.1, mem_range.mp i.2⟩).der hn ⟨j.1, mem_range.mp j.2⟩)).op
-- (f ((σ.ignore (nat.zero_lt_succ _) ⟨i.1, mem_range.mp i.2⟩).ignore hn ⟨j.1, mem_range.mp j.2⟩)))) :=
-- begin
-- rw dd_pos.eq6₀,
-- apply sum_congr rfl (λ m hm, _),
-- apply congr_arg,
-- apply sum_congr rfl (λ m' hm', _),
-- congr,
-- end
-- lemma dd_pos.eq6₂ :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- ite (even i.1) id has_neg.neg
-- (∑ j in (range n.succ).attach,
-- ite (even j.1) id has_neg.neg
-- (𝓕.map (σ.dder hn ⟨i.1, mem_range.mp i.2⟩ ⟨j.1, mem_range.mp j.2⟩).op
-- (f (σ.ignore₂ hn ⟨i.1, mem_range.mp i.2⟩ ⟨j.1, mem_range.mp j.2⟩)))) :=
-- begin
-- rw dd_pos.eq6₁,
-- apply sum_congr rfl (λ m hm, _),
-- apply congr_arg,
-- apply sum_congr rfl (λ m' hm', _),
-- apply congr_arg,
-- unfold dder simplex.ignore₂,
-- refl,
-- end
-- lemma dd_pos.eq7 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- ∑ j in (range n.succ).attach,
-- ite (even i.1) id has_neg.neg
-- (ite (even j.1) id has_neg.neg
-- (𝓕.map (σ.dder hn ⟨i.1, mem_range.mp i.2⟩ ⟨j.1, mem_range.mp j.2⟩).op
-- (f (σ.ignore₂ hn ⟨i.1, mem_range.mp i.2⟩ ⟨j.1, mem_range.mp j.2⟩)))) :=
-- begin
-- rw dd_pos.eq6₂,
-- apply sum_congr rfl (λ m hm, _),
-- by_cases e : even m.1,
-- { rw [if_pos e, id],
-- simp_rw [id], },
-- { rw [if_neg e, neg_sum], },
-- end
-- lemma dd_pos.eq8 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- ∑ j in (range n.succ).attach,
-- ite (even (i.1 + j.1)) id has_neg.neg
-- (𝓕.map (σ.dder hn ⟨i.1, mem_range.mp i.2⟩ ⟨j.1, mem_range.mp j.2⟩).op
-- (f (σ.ignore₂ hn ⟨i.1, mem_range.mp i.2⟩ ⟨j.1, mem_range.mp j.2⟩))) :=
-- begin
-- rw dd_pos.eq7,
-- apply sum_congr rfl (λ m hm, _),
-- apply sum_congr rfl (λ m' hm', _),
-- by_cases e : even m.1;
-- by_cases e' : even m'.1,
-- { rw [if_pos e, id, if_pos e', id, if_pos (even.add_even e e'), id] },
-- { rw [if_pos e, id, if_neg e', if_neg],
-- contrapose! e',
-- convert nat.even.sub_even e' e,
-- rw [add_comm, nat.add_sub_cancel], },
-- { rw [if_neg e, if_pos e', id, if_neg],
-- contrapose! e,
-- convert nat.even.sub_even e e',
-- rw nat.add_sub_cancel },
-- { rw [if_neg e, if_neg e', neg_neg, if_pos, id],
-- rw [nat.even_add', nat.odd_iff_not_even, nat.odd_iff_not_even],
-- exact ⟨λ _, e', λ _, e⟩, },
-- end
-- lemma dd_pos.eq9 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- (∑ j in (range n.succ).attach.filter (λ n, i.1 ≤ n.1),
-- ite (even (i.1 + j.1)) id has_neg.neg
-- (𝓕.map (σ.dder hn ⟨i.1, mem_range.mp i.2⟩ ⟨j.1, mem_range.mp j.2⟩).op
-- (f (σ.ignore₂ hn ⟨i.1, mem_range.mp i.2⟩ ⟨j.1, mem_range.mp j.2⟩))) +
-- ∑ j in (range n.succ).attach.filter (λ n, n.1 < i.1),
-- ite (even (i.1 + j.1)) id has_neg.neg
-- (𝓕.map (σ.dder hn ⟨i.1, mem_range.mp i.2⟩ ⟨j.1, mem_range.mp j.2⟩).op
-- (f (σ.ignore₂ hn ⟨i.1, mem_range.mp i.2⟩ ⟨j.1, mem_range.mp j.2⟩)))) :=
-- begin
-- rw dd_pos.eq8,
-- apply sum_congr rfl (λ i hi, _),
-- have set_eq : (range n.succ).attach =
-- (range n.succ).attach.filter (λ n, i.1 ≤ n.1) ∪ (range n.succ).attach.filter (λ n, n.1 < i.1),
-- { have := filter_union_filter_neg_eq (λ n : (range n.succ), i.1 ≤ n.1) (range n.succ).attach,
-- conv_lhs { rw ← this },
-- congr' 2,
-- ext,
-- dsimp only,
-- rw not_le },
-- conv_lhs { rw [set_eq] },
-- rw sum_union,
-- rintros ⟨k, hk⟩ h,
-- simp only [inf_eq_inter, mem_inter, mem_filter, mem_attach, subtype.coe_mk, true_and] at h,
-- linarith,
-- end
-- lemma dd_pos.eq10 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- (∑ j in ((range n.succ).filter (λ n, i.1 ≤ n)).attach,
-- ite (even (i.1 + j.1)) id has_neg.neg
-- (𝓕.map (σ.dder hn ⟨i.1, mem_range.mp i.2⟩ ⟨j.1, mem_range.mp (mem_filter.mp j.2).1⟩).op
-- (f (σ.ignore₂ hn ⟨i.1, mem_range.mp i.2⟩ ⟨j.1, mem_range.mp (mem_filter.mp j.2).1⟩))) +
-- ∑ j in (range n.succ).attach.filter (λ n, n.1 < i.1),
-- ite (even (i.1 + j.1)) id has_neg.neg
-- (𝓕.map (σ.dder hn ⟨i.1, mem_range.mp i.2⟩ ⟨j.1, mem_range.mp j.2⟩).op
-- (f (σ.ignore₂ hn ⟨i.1, mem_range.mp i.2⟩ ⟨j.1, mem_range.mp j.2⟩)))) :=
-- begin
-- rw dd_pos.eq9,
-- apply sum_congr rfl (λ i hi, _),
-- congr' 1,
-- apply sum_bij',
-- work_on_goal 4 { intros a ha, refine ⟨a.1, mem_filter.mpr ⟨a.2, (mem_filter.mp ha).2⟩⟩ },
-- work_on_goal 5 { intros a ha, refine ⟨a.1, (mem_filter.mp a.2).1⟩ },
-- { intros a ha, rw mem_filter at ha, },
-- { intros a ha, rw subtype.ext_iff_val, },
-- { intros a ha, rw subtype.ext_iff_val, },
-- { intros a ha, simp only [mem_attach], },
-- { intros a ha,
-- simp only [mem_filter, mem_attach, subtype.coe_mk, true_and],
-- exact (mem_filter.mp a.2).2, }
-- end
-- lemma dd_pos.eq11 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- ∑ j in (range n.succ).attach.filter (λ m, i.val ≤ m.val),
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, mem_range.mp i.2⟩ ⟨j.val, mem_range.mp j.2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))) +
-- ∑ i in (range n.succ.succ).attach,
-- ∑ j in (range n.succ).attach.filter (λ m, m.val < i.val),
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, mem_range.mp i.2⟩ ⟨j.val, mem_range.mp j.2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))) :=
-- begin
-- rw [dd_pos.eq9, sum_add_distrib],
-- end
-- lemma dd_pos.eq12 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- ∑ j in (range n.succ).attach.filter (λ m, i.val ≤ m.val),
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, mem_range.mp i.2⟩ ⟨j.val, mem_range.mp j.2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))) +
-- ∑ i in (range n.succ.succ).attach,
-- ∑ j in (range n.succ).attach.filter (λ m, m.val < i.val),
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, mem_range.mp i.2⟩ ⟨j.val, mem_range.mp j.2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))) :=
-- begin
-- rw [dd_pos.eq11],
-- end
-- lemma dd_pos.eq13 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- ∑ j in (Ico i.1 n.succ).attach,
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, mem_range.mp i.2⟩ ⟨j.val, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))) +
-- ∑ i in (range n.succ.succ).attach,
-- ∑ j in (range n.succ).attach.filter (λ m, m.val < i.val),
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, mem_range.mp i.2⟩ ⟨j.val, mem_range.mp j.2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))) :=
-- begin
-- rw [dd_pos.eq12],
-- apply congr_arg2 (+) _ rfl,
-- apply sum_congr rfl (λ i hi, _),
-- apply sum_bij',
-- work_on_goal 4
-- { refine λ a ha, ⟨a.1, mem_Ico.mpr ⟨_, _⟩⟩,
-- { rcases mem_filter.mp ha with ⟨h1, h2⟩,
-- exact h2 },
-- { exact mem_range.mp a.2 }, },
-- work_on_goal 5
-- { refine λ a ha, ⟨a.1, mem_range.mpr _⟩,
-- exact (mem_Ico.mp a.2).2, },
-- { intros a ha, refl, },
-- { intros a ha, rw subtype.ext_iff_val, },
-- { intros a ha, rw subtype.ext_iff_val, },
-- { intros a ha, apply mem_attach },
-- { intros a ha,
-- simp only [mem_attach, mem_filter, subtype.coe_mk, true_and],
-- exact (mem_Ico.mp a.2).1, },
-- end
-- lemma dd_pos.eq14 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- ∑ j in (Ico i.1 n.succ).attach,
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, mem_range.mp i.2⟩ ⟨j.val, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))) +
-- ∑ i in (range n.succ.succ).attach,
-- ∑ j in (range i.1).attach,
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, mem_range.mp i.2⟩ ⟨j.val, lt_of_lt_of_le (mem_range.mp j.2) (nat.le_of_lt_succ (mem_range.mp i.2))⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))) :=
-- begin
-- rw [dd_pos.eq13],
-- apply congr_arg2 (+) rfl _,
-- apply sum_congr rfl (λ j hj, _),
-- apply sum_bij',
-- work_on_goal 4
-- { refine λ a ha, ⟨a.1, mem_range.mpr _⟩,
-- rcases mem_filter.mp ha with ⟨h1, h2⟩,
-- exact h2 },
-- work_on_goal 5
-- { refine λ a ha, ⟨a.1, mem_range.mpr _⟩,
-- refine lt_of_lt_of_le (mem_range.mp a.2) _,
-- apply nat.le_of_lt_succ,
-- exact mem_range.mp j.2 },
-- { intros a ha, refl, },
-- { intros a ha, rw subtype.ext_iff_val, },
-- { intros a ha, rw subtype.ext_iff_val, },
-- { intros a ha, apply mem_attach },
-- { intros a ha,
-- simp only [mem_filter, mem_attach, subtype.coe_mk, true_and],
-- exact mem_range.mp a.2, },
-- end
-- lemma dd_pos.eq15 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- ∑ j in (Ico i.1 n.succ).attach,
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, mem_range.mp i.2⟩ ⟨j.val, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))) +
-- ∑ j in (range n.succ).attach,
-- ∑ i in (Ico j.1.succ n.succ.succ).attach,
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, (mem_Ico.mp i.2).2⟩ ⟨j.val, mem_range.mp j.2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))) :=
-- begin
-- rw [dd_pos.eq14],
-- apply congr_arg2 (+) rfl _,
-- rw [finset.sum_sigma', finset.sum_sigma'],
-- apply sum_bij',
-- work_on_goal 4
-- { refine λ ⟨a, b⟩ h, ⟨⟨b.1, mem_range.mpr begin
-- refine lt_of_lt_of_le (mem_range.mp b.2) _,
-- apply nat.le_of_lt_succ,
-- exact mem_range.mp a.2,
-- end⟩, ⟨a.1, mem_Ico.mpr ⟨begin
-- apply nat.le_of_lt_succ,
-- apply nat.succ_lt_succ,
-- exact mem_range.mp b.2,
-- end, begin
-- exact mem_range.mp a.2,
-- end⟩⟩⟩, },
-- work_on_goal 5
-- { refine λ ⟨a, b⟩ h, ⟨⟨b.1, mem_range.mpr begin
-- exact (mem_Ico.mp b.2).2,
-- end⟩, ⟨a.1, mem_range.mpr begin
-- have := (mem_Ico.mp b.2).1,
-- omega,
-- end⟩⟩ },
-- { rintros ⟨a, b⟩ h, refl, },
-- { rintros ⟨a, b⟩ h, simp only [subtype.val_eq_coe, subtype.coe_eta, sigma.mk.inj_iff, eq_self_iff_true, heq_iff_eq, and_self], },
-- { rintros ⟨a, b⟩ h, simp only [subtype.val_eq_coe, subtype.coe_eta, sigma.mk.inj_iff, eq_self_iff_true, heq_iff_eq, and_self], },
-- { rintros ⟨a, b⟩ h, simp only [mem_sigma, mem_attach, and_self], },
-- { rintros ⟨a, b⟩ h, simp only [mem_sigma, mem_attach, and_self], },
-- end
-- lemma dd_pos.eq16 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- ∑ j in (Ico i.1 n.succ).attach,
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, mem_range.mp i.2⟩ ⟨j.val, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))) +
-- ∑ i in (range n.succ).attach,
-- ∑ j in (Ico i.1.succ n.succ.succ).attach,
-- ite (even (j.val + i.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨j.val, (mem_Ico.mp j.2).2⟩ ⟨i.val, mem_range.mp i.2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨j.val, _⟩ ⟨i.val, _⟩))) := dd_pos.eq15 _ _ _
-- lemma 𝓕_map_congr (σ1 σ2 : simplex 𝔘 n.pred) (h : σ1 = σ2) (f : C 𝓕 𝔘 n.pred)
-- (i1 : σ.face ⟶ σ1.face) (i2 : σ.face ⟶ σ2.face) :
-- 𝓕.map i1.op (f σ1) = 𝓕.map i2.op (f σ2) :=
-- begin
-- subst h,
-- congr,
-- end
-- lemma dd_pos.eq17 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- ∑ j in (Ico i.1 n.succ).attach,
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, mem_range.mp i.2⟩ ⟨j.val, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))) +
-- ∑ i in (range n.succ).attach,
-- ∑ j in (Ico i.1 n.succ).attach,
-- ite (even (j.1.succ + i.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨j.1.succ, nat.succ_lt_succ (mem_Ico.mp j.2).2⟩ ⟨i.val, mem_range.mp i.2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨j.1.succ, _⟩ ⟨i.val, _⟩))) :=
-- begin
-- rw dd_pos.eq16,
-- apply congr_arg2 (+) rfl,
-- apply sum_congr rfl (λ i hi, _),
-- apply sum_bij',
-- work_on_goal 4
-- { refine λ a ha, ⟨a.1.pred, mem_Ico.mpr _⟩,
-- rcases mem_Ico.mp a.2 with ⟨h1, h2⟩,
-- have ineq1 : 0 < a.1,
-- { have := (mem_Ico.mp a.2).1,
-- omega },
-- have eq2 : a.1.pred.succ = a.1 := nat.succ_pred_eq_of_pos ineq1,
-- split,
-- { rwa [← eq2, nat.succ_le_succ_iff] at h1 },
-- { rwa [← eq2, nat.succ_lt_succ_iff] at h2 } },
-- work_on_goal 5
-- { refine λ a ha, ⟨a.1.succ, mem_Ico.mpr ⟨_, _⟩⟩,
-- { apply nat.succ_le_succ,
-- exact (mem_Ico.mp a.2).1, },
-- { apply nat.succ_lt_succ,
-- exact (mem_Ico.mp a.2).2, }, },
-- { intros a ha,
-- have ineq1 : 0 < a.1,
-- { have := (mem_Ico.mp a.2).1,
-- omega },
-- have eq2 : a.1.pred.succ = a.1 := nat.succ_pred_eq_of_pos ineq1,
-- by_cases e : even (a.1 + i.1),
-- { rw [if_pos e, id, if_pos, id],
-- dsimp only,
-- apply 𝓕_map_congr,
-- simp only [eq2],
-- dsimp only,
-- rwa eq2, },
-- { rw [if_neg e, if_neg],
-- apply congr_arg,
-- apply 𝓕_map_congr,
-- simp only [eq2],
-- simp only [eq2],
-- exact e, }, },
-- { intros a ha,
-- have ineq1 : 0 < a.1,
-- { have := (mem_Ico.mp a.2).1,
-- omega },
-- have eq2 : a.1.pred.succ = a.1 := nat.succ_pred_eq_of_pos ineq1,
-- rw subtype.ext_iff_val,
-- dsimp only,
-- rw eq2, },
-- { intros a ha,
-- rw subtype.ext_iff_val,
-- dsimp only,
-- rw nat.pred_succ, },
-- { intros a ha,
-- apply mem_attach, },
-- { intros a ha,
-- apply mem_attach, },
-- end
-- lemma dd_pos.eq18 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- ∑ j in (Ico i.1 n.succ).attach,
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, mem_range.mp i.2⟩ ⟨j.val, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))) +
-- ∑ i in (range n.succ).attach,
-- ∑ j in (Ico i.1 n.succ).attach,
-- ite (even (j.1.succ + i.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.1, lt_trans (mem_range.mp i.2) (lt_add_one _)⟩ ⟨j.1, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.1, _⟩ ⟨j.1, _⟩))) :=
-- begin
-- rw dd_pos.eq17,
-- apply congr_arg2 (+) rfl,
-- apply sum_congr rfl (λ i hi, _),
-- apply sum_congr rfl (λ j hj, _),
-- by_cases e : even (j.val.succ + i.val),
-- { rw [if_pos e, id, id],
-- apply 𝓕_map_congr,
-- symmetry,
-- apply simplex.ignore₂_eq_ignore₂ hn σ,
-- exact (mem_Ico.mp j.2).1 },
-- { rw [if_neg e],
-- apply congr_arg,
-- apply 𝓕_map_congr,
-- symmetry,
-- apply simplex.ignore₂_eq_ignore₂ hn σ,
-- exact (mem_Ico.mp j.2).1 },
-- end
-- lemma dd_pos.eq19 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ.succ).attach,
-- ∑ j in (Ico i.1 n.succ).attach,
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, mem_range.mp i.2⟩ ⟨j.val, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))) +
-- ∑ i in (range n.succ).attach,
-- -∑ j in (Ico i.1 n.succ).attach,
-- ite (even (j.1 + i.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.1, lt_trans (mem_range.mp i.2) (lt_add_one _)⟩ ⟨j.1, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.1, _⟩ ⟨j.1, _⟩))) :=
-- begin
-- rw dd_pos.eq18,
-- apply congr_arg2 (+) rfl,
-- apply sum_congr rfl (λ i hi, _),
-- rw neg_sum,
-- apply sum_congr rfl (λ j hj, _),
-- by_cases e : even (j.val.succ + i.val),
-- { rw [if_pos e, id, if_neg, neg_neg],
-- intro r,
-- have r' := nat.even.sub_even e r,
-- have eq1 : j.val.succ + i.val = (j.1 + i.1).succ := by omega,
-- rw [eq1, nat.succ_sub, nat.sub_self] at r',
-- apply nat.not_even_one,
-- exact r',
-- exact le_refl _, },
-- { rw [if_neg e, if_pos, id],
-- by_contra r,
-- rw ← nat.odd_iff_not_even at e r,
-- have r' := nat.odd.sub_odd e r,
-- have eq1 : j.val.succ + i.val = (j.1 + i.1).succ := by omega,
-- rw [eq1, nat.succ_sub, nat.sub_self] at r',
-- apply nat.not_even_one,
-- exact r',
-- exact le_refl _, },
-- end
-- lemma dd_pos.eq20 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ).attach,
-- ∑ j in (Ico i.1 n.succ).attach,
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, lt_trans (mem_range.mp i.2) (lt_add_one _)⟩ ⟨j.val, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))) +
-- ∑ j in (Ico n.succ n.succ).attach,
-- ite (even (n.succ + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨n.succ, lt_add_one _⟩ ⟨j.val, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨n.succ, _⟩ ⟨j.val, _⟩))) +
-- ∑ i in (range n.succ).attach,
-- -∑ j in (Ico i.1 n.succ).attach,
-- ite (even (j.1 + i.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.1, lt_trans (mem_range.mp i.2) (lt_add_one _)⟩ ⟨j.1, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.1, _⟩ ⟨j.1, _⟩))) :=
-- have eq0 : ∑ i in (range n.succ.succ).attach,
-- ∑ j in (Ico i.1 n.succ).attach,
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, mem_range.mp i.2⟩ ⟨j.val, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))) =
-- ∑ i in (insert n.succ (range n.succ)).attach,
-- ∑ j in (Ico i.1 n.succ).attach,
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, begin
-- have h := i.2,
-- simp only [← range_succ] at h,
-- rwa mem_range at h,
-- end⟩ ⟨j.val, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))),
-- begin
-- apply sum_bij',
-- work_on_goal 4
-- { refine λ a ha, ⟨a.1, _⟩,
-- rw ← range_succ,
-- exact a.2 },
-- work_on_goal 5
-- { refine λ a ha, ⟨a.1, _⟩,
-- convert a.2,
-- rw ← range_succ, },
-- { intros a ha, refl, },
-- { intros a ha, rw subtype.ext_iff_val, },
-- { intros a ha, rw subtype.ext_iff_val, },
-- { intros a ha, apply mem_attach },
-- { intros a ha, apply mem_attach },
-- end,
-- begin
-- rw dd_pos.eq19,
-- apply congr_arg2 (+) _ rfl,
-- rw [eq0, attach_insert, sum_insert, add_comm],
-- apply congr_arg2 (+),
-- { apply sum_bij',
-- work_on_goal 4
-- { refine λ a ha, ⟨a.1, mem_range.mpr _⟩,
-- rw mem_image at ha,
-- rcases ha with ⟨x, hx1, hx2⟩,
-- rw ← hx2,
-- dsimp only,
-- exact mem_range.mp x.2, },
-- work_on_goal 5
-- { refine λ a ha, ⟨a.1, _⟩,
-- rw mem_insert,
-- right,
-- exact a.2 },
-- { intros a ha, dsimp only, refl, },
-- { intros a ha, rw subtype.ext_iff_val, },
-- { intros a ha, rw subtype.ext_iff_val, },
-- { intros a ha, apply mem_attach },
-- { intros a ha, rw mem_image, use a.1, exact a.2,
-- refine ⟨_, _⟩, apply mem_attach, rw subtype.ext_iff_val, }, },
-- { refl, },
-- { intro r,
-- rw mem_image at r,
-- rcases r with ⟨⟨a, ha⟩, h1, h2⟩,
-- rw subtype.ext_iff_val at h2,
-- dsimp only at h2,
-- rw h2 at ha,
-- rw mem_range at ha,
-- linarith only [ha], },
-- end
-- lemma dd_pos.eq21 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ).attach,
-- ∑ j in (Ico i.1 n.succ).attach,
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, lt_trans (mem_range.mp i.2) (lt_add_one _)⟩ ⟨j.val, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))) +
-- ∑ i in (range n.succ).attach,
-- -∑ j in (Ico i.1 n.succ).attach,
-- ite (even (j.1 + i.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.1, lt_trans (mem_range.mp i.2) (lt_add_one _)⟩ ⟨j.1, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.1, _⟩ ⟨j.1, _⟩))) +
-- ∑ j in (Ico n.succ n.succ).attach,
-- ite (even (n.succ + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨n.succ, lt_add_one _⟩ ⟨j.val, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨n.succ, _⟩ ⟨j.val, _⟩))) :=
-- begin
-- rw dd_pos.eq20,
-- abel,
-- end
-- lemma dd_pos.eq22 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ).attach,
-- (∑ j in (Ico i.1 n.succ).attach,
-- ite (even (i.val + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.val, lt_trans (mem_range.mp i.2) (lt_add_one _)⟩ ⟨j.val, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.val, _⟩ ⟨j.val, _⟩))) +
-- -∑ j in (Ico i.1 n.succ).attach,
-- ite (even (j.1 + i.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨i.1, lt_trans (mem_range.mp i.2) (lt_add_one _)⟩ ⟨j.1, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨i.1, _⟩ ⟨j.1, _⟩)))) +
-- ∑ j in (Ico n.succ n.succ).attach,
-- ite (even (n.succ + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨n.succ, lt_add_one _⟩ ⟨j.val, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨n.succ, _⟩ ⟨j.val, _⟩))) :=
-- begin
-- rw [dd_pos.eq21, sum_add_distrib],
-- end
-- lemma dd_pos.eq23 :
-- dd_pos hn f σ =
-- ∑ i in (range n.succ).attach, 0 +
-- ∑ j in (Ico n.succ n.succ).attach,
-- ite (even (n.succ + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨n.succ, lt_add_one _⟩ ⟨j.val, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨n.succ, _⟩ ⟨j.val, _⟩))) :=
-- begin
-- rw [dd_pos.eq22],
-- apply congr_arg2 (+) _ rfl,
-- apply sum_congr rfl (λ i hi, _),
-- rw [← sub_eq_add_neg, sub_eq_zero],
-- apply sum_congr rfl (λ j hj, _),
-- rw add_comm,
-- end
-- lemma dd_pos.eq24 :
-- dd_pos hn f σ =
-- 0 + ∑ j in (Ico n.succ n.succ).attach,
-- ite (even (n.succ + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨n.succ, lt_add_one _⟩ ⟨j.val, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨n.succ, _⟩ ⟨j.val, _⟩))) :=
-- begin
-- rw [dd_pos.eq23],
-- apply congr_arg2 (+) _ rfl,
-- apply finset.sum_eq_zero,
-- intros,
-- refl,
-- end
-- lemma dd_pos.eq25 :
-- dd_pos hn f σ =
-- ∑ j in (Ico n.succ n.succ).attach,
-- ite (even (n.succ + j.val)) id has_neg.neg
-- ((𝓕.val.map (σ.dder hn ⟨n.succ, lt_add_one _⟩ ⟨j.val, (mem_Ico.mp j.2).2⟩).op)
-- (f (simplex.ignore₂ hn σ ⟨n.succ, _⟩ ⟨j.val, _⟩))) :=
-- by rw [dd_pos.eq24, zero_add]
-- lemma dd_pos_eq_zero :
-- dd_pos hn f σ = 0 :=
-- begin
-- rw [dd_pos.eq25],
-- convert sum_empty,
-- rw Ico_self,
-- refl,
-- end
-- end lemmas
-- lemma dd_pos.eq0 {n : ℕ} (hn : 0 < n) : (d_pos hn : C 𝓕 𝔘 _ ⟶ _) ≫ d_pos (nat.zero_lt_succ _) = 0 :=
-- begin
-- ext f σ,
-- convert dd_pos_eq_zero hn f σ,
-- end
-- end
-- end |
State Before: α : Type u_1
β : Type ?u.46161
γ : Type ?u.46164
a : α
s : Multiset α
n : ℕ
h : a ∈ n • s
⊢ a ∈ s State After: case zero
α : Type u_1
β : Type ?u.46161
γ : Type ?u.46164
a : α
s : Multiset α
n : ℕ
h✝ : a ∈ n • s
h : a ∈ zero • s
⊢ a ∈ s
case succ
α : Type u_1
β : Type ?u.46161
γ : Type ?u.46164
a : α
s : Multiset α
n✝ : ℕ
h✝ : a ∈ n✝ • s
n : ℕ
ih : a ∈ n • s → a ∈ s
h : a ∈ succ n • s
⊢ a ∈ s Tactic: induction' n with n ih State Before: case zero
α : Type u_1
β : Type ?u.46161
γ : Type ?u.46164
a : α
s : Multiset α
n : ℕ
h✝ : a ∈ n • s
h : a ∈ zero • s
⊢ a ∈ s State After: case zero
α : Type u_1
β : Type ?u.46161
γ : Type ?u.46164
a : α
s : Multiset α
n : ℕ
h✝ : a ∈ n • s
h : a ∈ 0
⊢ a ∈ s Tactic: rw [zero_nsmul] at h State Before: case zero
α : Type u_1
β : Type ?u.46161
γ : Type ?u.46164
a : α
s : Multiset α
n : ℕ
h✝ : a ∈ n • s
h : a ∈ 0
⊢ a ∈ s State After: no goals Tactic: exact absurd h (not_mem_zero _) State Before: case succ
α : Type u_1
β : Type ?u.46161
γ : Type ?u.46164
a : α
s : Multiset α
n✝ : ℕ
h✝ : a ∈ n✝ • s
n : ℕ
ih : a ∈ n • s → a ∈ s
h : a ∈ succ n • s
⊢ a ∈ s State After: case succ
α : Type u_1
β : Type ?u.46161
γ : Type ?u.46164
a : α
s : Multiset α
n✝ : ℕ
h✝ : a ∈ n✝ • s
n : ℕ
ih : a ∈ n • s → a ∈ s
h : a ∈ s ∨ a ∈ n • s
⊢ a ∈ s Tactic: rw [succ_nsmul, mem_add] at h State Before: case succ
α : Type u_1
β : Type ?u.46161
γ : Type ?u.46164
a : α
s : Multiset α
n✝ : ℕ
h✝ : a ∈ n✝ • s
n : ℕ
ih : a ∈ n • s → a ∈ s
h : a ∈ s ∨ a ∈ n • s
⊢ a ∈ s State After: no goals Tactic: exact h.elim id ih |
Require Export Coq.Classes.RelationClasses.
Set Default Goal Selector "all".
Class Ordered(A : Set) :=
{ lt : A -> A -> Prop;
lt_strict :> StrictOrder lt
}.
Class OrderedKeyed (A K : Set) :=
{ keyof : A -> K;
OA :> Ordered A
}.
Class KeyOrdered (A K : Set) :=
{ getkey : A -> K;
OK :> Ordered K
}.
Definition KOlt{A K : Set}`{KeyOrdered A K}(a b : A) : Prop := lt (getkey a) (getkey b).
Instance KOisO A K `{KeyOrdered A K} : Ordered A.
Proof.
destruct (_:KeyOrdered A K) as [gk [ltk [SOI SOT]]]. unshelve eexists.
- intros a b. exact (ltk (gk a) (gk b)).
- split.
+ unfold Irreflexive, Reflexive, complement in *. intro. apply SOI.
+ unfold Transitive in *. intros x y z. apply SOT.
Defined.
Instance KOisOK A K `{KeyOrdered A K} : OrderedKeyed A K :=
{ keyof := getkey }.
Class ComparableKeyed (A K : Set) :=
{ OKOK :> OrderedKeyed A K;
compare : K -> K -> comparison;
compare_spec x y: CompareSpecT (eq x y)
(forall (a b : A), x = keyof a -> y = keyof b -> lt a b)
(forall (a b : A), x = keyof a -> y = keyof b -> lt b a)
(compare x y);
lt_same_keys w x y z: lt w y -> keyof x = keyof w -> keyof z = keyof y -> lt x z
}.
Require Coq.Init.Nat.
Require Coq.Arith.PeanoNat.
Module Test.
Import Nat.
Import PeanoNat.
Open Scope nat_scope.
Context {A : Set}.
Context {Ord : Ordered A}.
Record OK : Set := { val : A; key : nat }.
Definition OKlt (a b : OK) : Prop := a.(key) < b.(key).
Lemma le_Sn_n : forall n, S n <= n -> False.
Proof.
induction n as [|? IHn]. intro H.
- inversion H.
- apply IHn. apply le_S_n. assumption.
Qed.
Lemma OKlt_strict : StrictOrder OKlt.
Proof.
eexists. red.
- red. red. intros [v k]. cbv. apply le_Sn_n.
- intros [? ?] [? ykey] [? ?]. unfold OKlt, key. transitivity ykey. assumption.
Qed.
Instance OKOrd : Ordered OK := { lt := OKlt; lt_strict := OKlt_strict }.
Lemma OKOrd_compare_spec (x y:nat) :
CompareSpecT (eq x y)
(forall (a b : OK), x = a.(key) -> y = b.(key) -> OKlt a b)
(forall (a b : OK), x = a.(key) -> y = b.(key) -> OKlt b a)
(Nat.compare x y).
Proof.
destruct (CompareSpec2Type (Nat.compare_spec x y)). constructor.
- assumption.
- intros ? ? -> -> . assumption.
- intros ? ? -> -> . assumption.
Qed.
Lemma OKOrd_lt_same_keys w x y z :
OKlt w y -> x.(key) = w.(key) -> z.(key) = y.(key) -> OKlt x z.
Proof.
unfold OKlt. intros H -> -> . assumption.
Qed.
Instance OKnat : OrderedKeyed OK nat := { keyof := key }.
Instance CKnat : ComparableKeyed OK nat :=
{ compare := Nat.compare;
compare_spec := OKOrd_compare_spec;
lt_same_keys := OKOrd_lt_same_keys
}.
End Test.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.