text
stringlengths 0
3.34M
|
---|
module Test.String
import Data.Prim.String
import Data.SOP
import Hedgehog
allString : Gen String
allString = string (linear 0 30) unicodeAll
prop_ltMin : Property
prop_ltMin = property $ do
b8 <- forAll allString
(b8 >= MinString) === True
prop_comp : Property
prop_comp = property $ do
[m,n] <- forAll $ np [allString, allString]
toOrdering (comp m n) === compare m n
export
props : Group
props = MkGroup "String"
[ ("prop_ltMin", prop_ltMin)
, ("prop_comp", prop_comp)
]
|
repeat process ACV_cubes {
/execute @e[type=armor_stand,name=ACV_Cube] ~ ~ ~ detect ~ ~1 ~ minecraft:lava * kill @e[type=armor_stand,name=ACV_Cube,r=0,c=1]
/execute @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID=0] ~ ~ ~ detect ~ ~1 ~ minecraft:air * tp @e[type=armor_stand,name=ACV_Cube,r=0,c=1] ~ ~-0.25 ~
/execute @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID=0] ~ ~ ~ detect ~ ~1 ~ minecraft:stone_pressure_plate * tp @e[type=armor_stand,name=ACV_Cube,r=0,c=1] ~ ~-0.25 ~
/execute @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID=0] ~ ~ ~ detect ~ ~1 ~ minecraft:carpet * tp @e[type=armor_stand,name=ACV_Cube,r=0,c=1] ~ ~-0.25 ~
/execute @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID=0] ~ ~ ~ detect ~ ~1 ~ minecraft:tallgrass * tp @e[type=armor_stand,name=ACV_Cube,r=0,c=1] ~ ~-0.25 ~
/scoreboard players add @a ACV_CUBE_ID 0
/scoreboard players add @e[type=armor_stand,name=ACV_Cube] ACV_CUBE_ID 0
/scoreboard players tag @a remove ACV_HoldingArrow
/scoreboard players tag @a add ACV_HoldingArrow {SelectedItem:{id:"minecraft:arrow",tag:{display:{Name:"Picking up Cubes"}}}}
/scoreboard players set @a[score_ACV_CUBE_ID_min=1,tag=!ACV_HoldingArrow] ACV_CUBE_ID 0
/execute @p[score_ACV_CUBE_ID=0,tag=ACV_HoldingArrow] ~ ~ ~ scoreboard players operation ACV_Last_ID ACV_CUBE_ID %= 5 ACV_CONSTANT
/execute @p[score_ACV_CUBE_ID=0,tag=ACV_HoldingArrow] ~ ~ ~ scoreboard players add ACV_Last_ID ACV_CUBE_ID 1
/scoreboard players operation @r[type=player,score_ACV_CUBE_ID=0,tag=ACV_HoldingArrow] ACV_CUBE_ID += ACV_Last_ID ACV_CUBE_ID
/scoreboard players tag @a remove ACV_CubeLinked
/scoreboard players tag @e[type=armor_stand,name=ACV_Cube] remove ACV_CubeLinked
/execute @p[score_ACV_CUBE_ID_min=1,score_ACV_CUBE_ID=1] ~ ~ ~ execute @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=1,score_ACV_CUBE_ID=1] ~ ~ ~ scoreboard players tag @e[score_ACV_CUBE_ID_min=1,score_ACV_CUBE_ID=1] add ACV_CubeLinked
/execute @p[score_ACV_CUBE_ID_min=2,score_ACV_CUBE_ID=2] ~ ~ ~ execute @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=2,score_ACV_CUBE_ID=2] ~ ~ ~ scoreboard players tag @e[score_ACV_CUBE_ID_min=2,score_ACV_CUBE_ID=2] add ACV_CubeLinked
/execute @p[score_ACV_CUBE_ID_min=3,score_ACV_CUBE_ID=3] ~ ~ ~ execute @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=3,score_ACV_CUBE_ID=3] ~ ~ ~ scoreboard players tag @e[score_ACV_CUBE_ID_min=3,score_ACV_CUBE_ID=3] add ACV_CubeLinked
/execute @p[score_ACV_CUBE_ID_min=4,score_ACV_CUBE_ID=4] ~ ~ ~ execute @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=4,score_ACV_CUBE_ID=4] ~ ~ ~ scoreboard players tag @e[score_ACV_CUBE_ID_min=4,score_ACV_CUBE_ID=4] add ACV_CubeLinked
/execute @p[score_ACV_CUBE_ID_min=5,score_ACV_CUBE_ID=5] ~ ~ ~ execute @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=5,score_ACV_CUBE_ID=5] ~ ~ ~ scoreboard players tag @e[score_ACV_CUBE_ID_min=5,score_ACV_CUBE_ID=5] add ACV_CubeLinked
/scoreboard players set @e[type=armor_stand,name=ACV_Cube,tag=!ACV_CubeLinked] ACV_CUBE_ID 0
/execute @a[tag=!ACV_CubeLinked] ~ ~ ~ /scoreboard players operation @e[type=armor_stand,name=ACV_Cube,r=3,c=1] ACV_CUBE_ID += @p[tag=!ACV_CubeLinked] ACV_CUBE_ID
/execute @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=1,score_ACV_CUBE_ID=1] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,c=1] @p[score_ACV_CUBE_ID_min=1,score_ACV_CUBE_ID=1]
/execute @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=2,score_ACV_CUBE_ID=2] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,c=1] @p[score_ACV_CUBE_ID_min=2,score_ACV_CUBE_ID=2]
/execute @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=3,score_ACV_CUBE_ID=3] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,c=1] @p[score_ACV_CUBE_ID_min=3,score_ACV_CUBE_ID=3]
/execute @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=4,score_ACV_CUBE_ID=4] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,c=1] @p[score_ACV_CUBE_ID_min=4,score_ACV_CUBE_ID=4]
/execute @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=5,score_ACV_CUBE_ID=5] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,c=1] @p[score_ACV_CUBE_ID_min=5,score_ACV_CUBE_ID=5]
// r=1 wegen https://bugs.mojang.com/browse/MC-90967
/execute @a[rym=169,ry=-168,score_ACV_CUBE_ID_min=1] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=1,r=1,c=1] ~0 ~-0.25 ~-2
/execute @a[rym=-167,ry=-146,score_ACV_CUBE_ID_min=1] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=1,r=1,c=1] ~0.7653668647301795434569199680608 ~-0.25 ~-1.8477590650225735122563663787936
/execute @a[rym=-145,ry=-123,score_ACV_CUBE_ID_min=1] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=1,r=1,c=1] ~1.4142135623730950488016887242097 ~-0.25 ~-1.4142135623730950488016887242097
/execute @a[rym=-122,ry=-101,score_ACV_CUBE_ID_min=1] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=1,r=1,c=1] ~1.8477590650225735122563663787936 ~-0.25 ~-0.7653668647301795434569199680608
/execute @a[rym=-100,ry=-78,score_ACV_CUBE_ID_min=1] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=1,r=1,c=1] ~2 ~-0.25 ~0
/execute @a[rym=-77,ry=-56,score_ACV_CUBE_ID_min=1] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=1,r=1,c=1] ~1.8477590650225735122563663787936 ~-0.25 ~0.7653668647301795434569199680608
/execute @a[rym=-55,ry=-33,score_ACV_CUBE_ID_min=1] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=1,r=1,c=1] ~1.4142135623730950488016887242097 ~-0.25 ~1.4142135623730950488016887242097
/execute @a[rym=-32,ry=-11,score_ACV_CUBE_ID_min=1] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=1,r=1,c=1] ~0.7653668647301795434569199680608 ~-0.25 ~1.8477590650225735122563663787936
/execute @a[rym=-10,ry=11,score_ACV_CUBE_ID_min=1] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=1,r=1,c=1] ~0 ~-0.25 ~2
/execute @a[rym=12,ry=33,score_ACV_CUBE_ID_min=1] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=1,r=1,c=1] ~-0.7653668647301795434569199680608 ~-0.25 ~1.8477590650225735122563663787936
/execute @a[rym=34,ry=56,score_ACV_CUBE_ID_min=1] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=1,r=1,c=1] ~-1.4142135623730950488016887242097 ~-0.25 ~1.4142135623730950488016887242097
/execute @a[rym=57,ry=78,score_ACV_CUBE_ID_min=1] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=1,r=1,c=1] ~-1.8477590650225735122563663787936 ~-0.25 ~0.7653668647301795434569199680608
/execute @a[rym=79,ry=101,score_ACV_CUBE_ID_min=1] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=1,r=1,c=1] ~-2 ~-0.25 ~0
/execute @a[rym=102,ry=123,score_ACV_CUBE_ID_min=1] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=1,r=1,c=1] ~-1.8477590650225735122563663787936 ~-0.25 ~-0.7653668647301795434569199680608
/execute @a[rym=124,ry=146,score_ACV_CUBE_ID_min=1] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=1,r=1,c=1] ~-1.4142135623730950488016887242097 ~-0.25 ~-1.4142135623730950488016887242097
/execute @a[rym=147,ry=168,score_ACV_CUBE_ID_min=1] ~ ~ ~ tp @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID_min=1,r=1,c=1] ~-0.7653668647301795434569199680608 ~-0.25 ~-1.8477590650225735122563663787936
/kill @e[type=armor_stand,name=cube_update]
/execute @e[type=armor_stand,name=ACV_Cube,score_ACV_CUBE_ID=0] ~ ~ ~ summon armor_stand ~ ~1.25 ~ {CustomName:"cube_update",Invisible:1b,Invulnerable:1b,Marker:1b}
}
|
FUNCTION:NAME
:test 128, 0, 2, 3, 4, 5, 6, 7, 8, 9
-- @@stderr --
dtrace: script 'test/demo/dt_test/args.d' matched 1 probe
|
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.list.range
import Mathlib.PostPort
namespace Mathlib
namespace list
namespace nat
/-- The antidiagonal of a natural number `n` is the list of pairs `(i,j)` such that `i+j = n`. -/
def antidiagonal (n : ℕ) : List (ℕ × ℕ) := map (fun (i : ℕ) => (i, n - i)) (range (n + 1))
/-- A pair (i,j) is contained in the antidiagonal of `n` if and only if `i+j=n`. -/
@[simp] theorem mem_antidiagonal {n : ℕ} {x : ℕ × ℕ} :
x ∈ antidiagonal n ↔ prod.fst x + prod.snd x = n :=
sorry
/-- The length of the antidiagonal of `n` is `n+1`. -/
@[simp] theorem length_antidiagonal (n : ℕ) : length (antidiagonal n) = n + 1 := sorry
/-- The antidiagonal of `0` is the list `[(0,0)]` -/
@[simp] theorem antidiagonal_zero : antidiagonal 0 = [(0, 0)] := rfl
/-- The antidiagonal of `n` does not contain duplicate entries. -/
theorem nodup_antidiagonal (n : ℕ) : nodup (antidiagonal n) :=
nodup_map (function.left_inverse.injective fun (i : ℕ) => rfl) (nodup_range (n + 1))
@[simp] theorem antidiagonal_succ {n : ℕ} :
antidiagonal (n + 1) = (0, n + 1) :: map (prod.map Nat.succ id) (antidiagonal n) :=
sorry
end Mathlib |
\section{sort}
|
A bounded open set $S$ is simply connected if and only if $S$ and $-S$ are connected. |
[STATEMENT]
lemma traversed_states_nempty: "traversed_states s as \<noteq> {}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. traversed_states s as \<noteq> {}
[PROOF STEP]
unfolding traversed_states_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. set (state_list s as) \<noteq> {}
[PROOF STEP]
by (induction as) auto |
proposition homotopic_loops_conjugate: fixes s :: "'a::real_normed_vector set" assumes "path p" "path q" and pip: "path_image p \<subseteq> s" and piq: "path_image q \<subseteq> s" and pq: "pathfinish p = pathstart q" and qloop: "pathfinish q = pathstart q" shows "homotopic_loops s (p +++ q +++ reversepath p) q" |
```python
from IPython.core.display import HTML
from IPython.display import Image
from IPython.display import display, Math
from IPython.display import display as disp
HTML("""
<style>
.output_png {
display: table-cell;
text-align: center;
vertical-align: middle;
}
</style>
""")
```
# *Circuitos Elétricos I - Semana 6*
### Problema 1
Para o circuito abaixo, tem-se que $v(t)=-1800te^{-20t}$ para $t\geq0$ e $i_1(0)=4\;A$ e $i_2(0)=-16\;A$
a) Determine $i_1(t)$ e $i_2(t)$ para $t\geq0$.\
b) Determine a energia fornecida à fonte de tensão no intervalo $0\leq t \leq\infty$.\
c) Determine a energia inicial armazenada nos indutores.\
d) Determine a energia final armazenada nos indutores.
```python
Image("./figures/J8C1.png", width=500)
```
```python
import matplotlib.pyplot as plt
import numpy as np
tmax = 1
t = np.linspace(0, tmax, num = 1000)
v = -1800*t*np.exp(-20*t)
plt.plot(t, v)
plt.xlim(0, tmax)
plt.grid()
plt.xlabel('t [s]')
plt.ylabel('v(t) [V]')
plt.show()
```
```python
# valores das indutâncias
L1 = 10
L2 = 30
# valores iniciais das correntes
i1_0 = 4
i2_0 = -16
```
```python
from sympy import *
# define as variáveis
t, τ = symbols('t, τ')
# define v(τ)
v = -1800*τ*exp(-20*τ)
# correntes nos indutores em função da tensão aplicada aos terminais
i1 = -(1/L1)*integrate(v, (τ, 0, t)) + i1_0
i2 = -(1/L2)*integrate(v, (τ, 0, t)) + i2_0
print('Correntes nos indutores:')
print('i1(t) = ', i1 , ' A')
print('i2(t) = ', i2 , ' A')
```
```python
# LKC
i = i1 + i2
# define v(t)
v = -1800*t*exp(-20*t)
# potência fornecida à fonte
p = v*i
# energia entrege à fonte
E = integrate(p, (t, 0, oo))
print('Energia entrege à fonte:')
print('E = %.2f J' %E)
```
```python
i1.simplify()
```
```python
# calculando os valores de energia em t=0
E1_0 = (1/2)*L1*(i1.evalf(subs={t:0}))**2
E2_0 = (1/2)*L2*(i2.evalf(subs={t:0}))**2
print('Energia inicial armazenada nos indutores:')
print('E1(0) = %.2f J' %E1_0)
print('E2(0) = %.2f J' %E2_0)
```
```python
# calculando os valores de energia em t =oo
E1_inf = (1/2)*L1*(i1.evalf(subs={t:100}))**2
E2_inf = (1/2)*L2*(i2.evalf(subs={t:100}))**2
print('Energia final armazenada nos indutores:')
print('E1(oo) = %.2f J' %E1_inf)
print('E2(oo) = %.2f J' %E2_inf)
```
```python
# calculando a variação de energia nos indutores
ΔE = (E1_inf-E1_0) + (E2_inf-E2_0)
print('Variação da energia armazenada nos indutores:')
print('ΔE = %.2f J' %ΔE)
```
### Problema 2
Cálculo de indutâncias equivalentes com acoplamento magnético
```python
Image("./figures/J8C2.png", width=700)
```
$$
\begin{aligned}
&v_L = L_{1} \frac{d i_{1}}{d t}+M \frac{d i_{2}}{d t}\\
&v_L = L_{2} \frac{d i_{2}}{d t}+M \frac{d i_{1}}{d t}
\end{aligned}
$$
```python
L1, L2, M, vL, t = symbols('L_1, L_2, M, v_L, t', real=True)
```
```python
i1 = Function('i_1')(t)
i2 = Function('i_2')(t)
A = Matrix([[L1, M],[M, L2]])
V = Matrix([[vL],[vL]])
I = Matrix([[i1],[i2]])
dI = diff(I, t)
disp(Math('A = '+latex(A)))
disp(Math('V = '+latex(V)))
disp(Math('dI = '+latex(dI)))
```
```python
Eq(V, A*dI)
```
```python
# matriz inversa de A
disp(Math(r'A^{-1} = '+latex(A**-1)))
```
```python
# calcula o vetor de derivadas das correntes
dI = (A**-1)*V
dI.simplify()
disp(Math(r'\frac{dI}{dt} = '+latex(dI)))
```
```python
# di0/dt = di1/dt + di2/dt
dI0 = dI[0] + dI[1]
disp(Math(r'\frac{di_0}{dt} = \frac{di_1}{dt} + \frac{di_2}{dt} = '+latex(dI0.simplify())))
```
```python
# indutância equivalente: vL = Leq*di0/dt -> Leq = vL/di0/dt
Leq = vL/dI0
disp(Math('L_{eq} = '+latex(Leq.simplify())))
```
|
Guard , office , and police duties .
|
LAURA'S is just what Oyster Bay needs and its residents know it. They have taken this newly opened American restaurant to their hearts and made it an instant hit. Even midweek evenings find nearly every table filled; on Saturdays there are crowds waiting in the bar.
Part of the draw is James Paskins, the restaurant's chef and owner, who acquired a following during his years at the Coach Grill, also in Oyster Bay. His wife and other family members efficiently handle the front of the house. Another crowd pleaser is the reasonable prices. Entrees start at $11 and top out at $18.
Laura's, named for Mr. Paskins's late mother, looks much as it did last year, when 68 West Main was at this location. It is spacious and comfortable. The dining room is defined by white columns, carved molding, smoky mirrors and crystal chandeliers. In a town filled with casual cafes, Laura's smart good looks make it stand out.
One new feature is the entrance through the bar. This, no doubt, eliminates drafts in the dining room but the crowded, smoky bar does not make a positive first impression. The dining room, however, is a place of charm and serenity.
Other salad sensations are a just-right Caesar and a plate of grilled vegetables served atop baby greens with a balsamic vinaigrette as a dipping sauce. The seafood salad carries a price tag ($12) that is higher than some entrees, but this abundant assembly could be a main course. It stars jumbo shrimp, sea scallops, calamari, scungilli, chopped peppers, red onions, celery and black olives in a lemon-basil vinaigrette.
Other openers I would order again are tender clams oreganata with a refreshingly spare use of bread crumbs, New Zealand mussels in a sherry pink sauce enlivened by spicy, smoky andouille sausage, a huge crab cake made lighter by the inclusion of shredded vegetables and two big portobellos served on a bed of grilled tomatoes and baby spinach. One creation that does not work, though, is the smoked-salmon-crusted-oysters. The delicate bivalves never had a chance. The assertive bready topping was too much for them. Every day a different homemade ravioli ($13) is featured. On my visit, they were filled with sun-dried tomatoes and black olives and tossed with big chunks of succulent chicken, chopped tomatoes, broccoli and an abundance of garlic. A winner! Another tasty pasta pick was fettuccine hidden under a mountain of sliced shell steak, three types of mushrooms and a chunky tomato sauce.
Fish were all cooked with precision. The herb-crusted tuna was rare as ordered and a special of striped bass in a tomato-basil sauce was moist and flaky as was sauteed tilapia in a mushroom-lemon-wine sauce.
Good meat selections include chicken medallions in a brown sauce spiked with bourbon and touched with cream, a juicy grilled rib eye, a tasty shell steak marinated in teriyaki sauce and a memorable rack of lamb special, served pink as ordered, atop a bed of barely wilted baby spinach. That spinach aside, the same vegetables show up with every entree. But, it should be said, the creamy mashed potatoes are terrific.
Desserts are not homemade but high-quality bakery fare. The ganache-like chocolate mousse cake and the creamy New York-style cheesecake are the most noteworthy.
Prices here are gentle, with 15 of 21 table wines in the $14 to $20 range. A glass of flinty Fetzer Sundial chardonnay costs $5 and a bottle of 1995 Tessera zinfandel, displaying a velvety texture and accessible fruit flavors, is $20.
68 West Main Street, Oyster Bay, 624-7100.
Recommended dishes Clams oreganata, crab cake, portobello mushrooms, mussels, all salads, bourbon chicken, rib eye, marinated shell steak, rack of lamb, ravioli, shell steak fettuccine, tuna, tilapia, striped bass, chocolate mousse cake, cheesecake.
Price range Lunch, entrees $5 to $11. At dinner, appetizers $4 to $12; entrees $11 to $18.
Hours Lunch, 11 A.M. to 3 P.M. Tuesday through Saturday; Sunday brunch 11:30 A.M. to 3 P.M.; Dinner 5 to 10 P.M. Tuesday and Wednesday, till 11 P.M. Thursday through Saturday, 4 to 10 P.M. Sunday. |
theory T88
imports Main
begin
lemma "(
(\<forall> x::nat. \<forall> y::nat. meet(x, y) = meet(y, x)) &
(\<forall> x::nat. \<forall> y::nat. join(x, y) = join(y, x)) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, meet(y, z)) = meet(meet(x, y), z)) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(x, join(y, z)) = join(join(x, y), z)) &
(\<forall> x::nat. \<forall> y::nat. meet(x, join(x, y)) = x) &
(\<forall> x::nat. \<forall> y::nat. join(x, meet(x, y)) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, join(y, z)) = join(mult(x, y), mult(x, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(join(x, y), z) = join(mult(x, z), mult(y, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, over(join(mult(x, y), z), y)) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(y, undr(x, join(mult(x, y), z))) = y) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(over(x, y), y), x) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(y, undr(y, x)), x) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, meet(y, z)) = meet(mult(x, y), mult(x, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(meet(x, y), z) = meet(mult(x, z), mult(y, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. over(join(x, y), z) = join(over(x, z), over(y, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(meet(x, y), z) = join(undr(x, z), undr(y, z))) &
(\<forall> x::nat. \<forall> y::nat. invo(join(x, y)) = meet(invo(x), invo(y))) &
(\<forall> x::nat. \<forall> y::nat. invo(meet(x, y)) = join(invo(x), invo(y))) &
(\<forall> x::nat. invo(invo(x)) = x)
) \<longrightarrow>
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(x, join(y, z)) = join(undr(x, y), undr(x, z)))
"
nitpick[card nat=4,timeout=86400]
oops
end |
```python
from sympy import symbols, solve, cos
from sympy.physics.mechanics import dynamicsymbols, ReferenceFrame, Point, Particle
from sympy.physics.mechanics import RigidBody, inertia, KanesMethod, init_vprinting, Lagrangian, LagrangesMethod
```
```python
init_vprinting()
```
```python
x1, x2 = dynamicsymbols('x1, x2')
v1, v2 = dynamicsymbols('v1, v2')
m1, m2, k, g = symbols('m1, m2, k, g')
```
```python
N = ReferenceFrame('N')
```
```python
O = Point('O')
P1 = O.locatenew('P1', x1 * N.x)
P2 = O.locatenew('P2', x2 * N.x)
```
```python
O.set_vel(N, 0)
P1.set_vel(N, v1 * N.x)
P2.set_vel(N, v2 * N.x)
```
```python
block1 = Particle('block1', P1, m1)
block2 = Particle('block2', P2, m2)
```
# Kane's Method
```python
force1 = (P1, m1 * g * N.x - k * x1 * N.x + k * (x2 - x1) * N.x)
force2 = (P2, m2 * g * N.x - k * (x2 - x1) * N.x)
```
```python
kane = KanesMethod(N, (x1, x2), (v1, v2), kd_eqs=(x1.diff() - v1, x2.diff() - v2))
fr, frstar = kane.kanes_equations((force1, force2), (block1, block2))
```
```python
fr_plus_frstar = fr + frstar
fr_plus_frstar.simplify()
fr_plus_frstar
```
This gives the two equilibrium points:
```python
eq_points = solve(fr_plus_frstar.subs({v1.diff(): 0, v2.diff(): 0, v1: 0, v2: 0}), x1, x2)
eq_points
```
# Lagrange's Method
```python
P1.set_vel(N, x1.diff() * N.x)
P2.set_vel(N, x2.diff() * N.x)
```
```python
block1.kinetic_energy(N) + block2.kinetic_energy(N)
```
```python
block1.potential_energy = k * x1**2 / 2 + k * (x2 - x1)**2 / 2 - m1 * g * x1
block2.potential_energy = -m2 * g * x2
```
```python
L = Lagrangian(N, block1, block2)
L
```
```python
lagrange = LagrangesMethod(L, (x1, x2))
```
```python
lagranges_equations = lagrange.form_lagranges_equations()
lagranges_equations.simplify()
lagranges_equations
```
```python
eq_points = solve(lagranges_equations.subs({x1.diff().diff(): 0,
x2.diff().diff(): 0,
x1.diff(): 0, x2.diff(): 0}), x1, x2)
eq_points
```
# Compare
```python
should_be_zero = fr_plus_frstar.subs({v1: x1.diff(), v2: x2.diff()}) + lagranges_equations
should_be_zero.simplify()
should_be_zero
```
|
Base.show(io::IO, r::OneToRange) = print(io, typeof(r).name, "(", last(r), ")")
function Base.show(io::IO, r::AbstractStepRangeLen)
print(io, typeof(r).name, "(", first(r), ":", step(r), ":", last(r), ")")
end
function Base.show(io::IO, r::StepMRange)
print(io, "StepMRange(", first(r), ":", step(r), ":", last(r), ")")
end
function Base.show(io::IO, r::StepSRange)
print(io, "StepSRange(", first(r), ":", step(r), ":", last(r), ")")
end
function Base.show(io::IO, r::StaticUnitRange)
print(io, typeof(r).name, "(", repr(first(r)), ':', repr(last(r)), ")")
end
|
-- Andreas, 2014-09-23
-- Check fixity declarations also in new 'instance' block.
module _ where
postulate
D : Set
instance
infixl 0 D Undeclared
postulate d : D
-- Should fail with error:
-- Names out of scope in fixity declarations: Undeclared
|
module Properties.Dec where
open import Properties.Contradiction using (¬)
data Dec(A : Set) : Set where
yes : A → Dec A
no : ¬ A → Dec A
|
try_require <- function(package, fun) {
if (requireNamespace(package, quietly = TRUE)) {
library(package, character.only = TRUE)
return(invisible())
}
stop("Package `", package, "` required for `", fun , "`.\n", # nocov start
"Please install and try again.", call. = FALSE) # nocov end
}
# authenticate to drill
# sets up a cookie in the httr handle pool ref for the drill REST API url
auth_drill <- function(ssl, host, port, username, password) {
httr::set_config(config(ssl_verifypeer = 0L))
httr::RETRY(
"POST",
url = sprintf("%s://%s:%s", ifelse(ssl[1], "https", "http"), host, port),
path = "/j_security_check",
encode = "form",
body = list(
j_username = username,
j_password = password
),
terminate_on = c(403, 404)
) -> res
httr::stop_for_status(res)
}
set_names <- function(object = nm, nm) {
names(object) <- nm
object
}
|
-- Andreas, 2014-09-23
-- Issue 1194, reported by marco.vax91, 2014-06-13
-- {-# OPTIONS -v scope.operators:50 #-}
module _ where
module A where
data D1 : Set where
c : D1
-- Just default notation for c here.
module B where
data D2 : Set where
c : A.D1 → D2
-- Interesting notation for c here.
syntax c x = ⟦ x ⟧
open A
open B
-- Since there is only one interesting notation for c in scope
-- we should be able to use it.
test : D2
test = ⟦ c ⟧
|
theory T61
imports Main
begin
lemma "(
(\<forall> x::nat. \<forall> y::nat. meet(x, y) = meet(y, x)) &
(\<forall> x::nat. \<forall> y::nat. join(x, y) = join(y, x)) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, meet(y, z)) = meet(meet(x, y), z)) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(x, join(y, z)) = join(join(x, y), z)) &
(\<forall> x::nat. \<forall> y::nat. meet(x, join(x, y)) = x) &
(\<forall> x::nat. \<forall> y::nat. join(x, meet(x, y)) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, join(y, z)) = join(mult(x, y), mult(x, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(join(x, y), z) = join(mult(x, z), mult(y, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, over(join(mult(x, y), z), y)) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(y, undr(x, join(mult(x, y), z))) = y) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(over(x, y), y), x) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(y, undr(y, x)), x) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, meet(y, z)) = meet(mult(x, y), mult(x, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(x, join(y, z)) = join(undr(x, y), undr(x, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. over(join(x, y), z) = join(over(x, z), over(y, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. over(x, meet(y, z)) = join(over(x, y), over(x, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(meet(x, y), z) = join(undr(x, z), undr(y, z))) &
(\<forall> x::nat. \<forall> y::nat. invo(join(x, y)) = meet(invo(x), invo(y))) &
(\<forall> x::nat. \<forall> y::nat. invo(meet(x, y)) = join(invo(x), invo(y))) &
(\<forall> x::nat. invo(invo(x)) = x)
) \<longrightarrow>
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(meet(x, y), z) = meet(mult(x, z), mult(y, z)))
"
nitpick[card nat=7,timeout=86400]
oops
end |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import order.galois_connection
/-!
# Heyting regular elements
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines Heyting regular elements, elements of an Heyting algebra that are their own double
complement, and proves that they form a boolean algebra.
From a logic standpoint, this means that we can perform classical logic within intuitionistic logic
by simply double-negating all propositions. This is practical for synthetic computability theory.
## Main declarations
* `is_regular`: `a` is Heyting-regular if `aᶜᶜ = a`.
* `regular`: The subtype of Heyting-regular elements.
* `regular.boolean_algebra`: Heyting-regular elements form a boolean algebra.
## References
* [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3]
-/
open function
variables {α : Type*}
namespace heyting
section has_compl
variables [has_compl α] {a : α}
/-- An element of an Heyting algebra is regular if its double complement is itself. -/
def is_regular (a : α) : Prop := aᶜᶜ = a
protected lemma is_regular.eq : is_regular a → aᶜᶜ = a := id
instance is_regular.decidable_pred [decidable_eq α] : @decidable_pred α is_regular :=
λ _, ‹decidable_eq α› _ _
end has_compl
section heyting_algebra
variables [heyting_algebra α] {a b : α}
lemma is_regular_bot : is_regular (⊥ : α) := by rw [is_regular, compl_bot, compl_top]
lemma is_regular_top : is_regular (⊤ : α) := by rw [is_regular, compl_top, compl_bot]
lemma is_regular.inf (ha : is_regular a) (hb : is_regular b) : is_regular (a ⊓ b) :=
by rw [is_regular, compl_compl_inf_distrib, ha.eq, hb.eq]
lemma is_regular.himp (ha : is_regular a) (hb : is_regular b) : is_regular (a ⇨ b) :=
by rw [is_regular, compl_compl_himp_distrib, ha.eq, hb.eq]
lemma is_regular_compl (a : α) : is_regular aᶜ := compl_compl_compl _
protected lemma is_regular.disjoint_compl_left_iff (ha : is_regular a) : disjoint aᶜ b ↔ b ≤ a :=
by rw [←le_compl_iff_disjoint_left, ha.eq]
protected lemma is_regular.disjoint_compl_right_iff (hb : is_regular b) : disjoint a bᶜ ↔ a ≤ b :=
by rw [←le_compl_iff_disjoint_right, hb.eq]
/-- A Heyting algebra with regular excluded middle is a boolean algebra. -/
@[reducible] -- See note [reducible non-instances]
def _root_.boolean_algebra.of_regular (h : ∀ a : α, is_regular (a ⊔ aᶜ)) : boolean_algebra α :=
have ∀ a : α, is_compl a aᶜ := λ a, ⟨disjoint_compl_right, codisjoint_iff.2 $
by erw [←(h a).eq, compl_sup, inf_compl_eq_bot, compl_bot]⟩,
{ himp_eq := λ a b, eq_of_forall_le_iff $ λ c,
le_himp_iff.trans ((this _).le_sup_right_iff_inf_left_le).symm,
inf_compl_le_bot := λ a, (this _).1.le_bot,
top_le_sup_compl := λ a, (this _).2.top_le,
..‹heyting_algebra α›, ..generalized_heyting_algebra.to_distrib_lattice }
variables (α)
/-- The boolean algebra of Heyting regular elements. -/
def regular : Type* := {a : α // is_regular a}
variables {α}
namespace regular
instance : has_coe (regular α) α := coe_subtype
lemma coe_injective : injective (coe : regular α → α) := subtype.coe_injective
@[simp] lemma coe_inj {a b : regular α} : (a : α) = b ↔ a = b := subtype.coe_inj
instance : has_top (regular α) := ⟨⟨⊤, is_regular_top⟩⟩
instance : has_bot (regular α) := ⟨⟨⊥, is_regular_bot⟩⟩
instance : has_inf (regular α) := ⟨λ a b, ⟨a ⊓ b, a.2.inf b.2⟩⟩
instance : has_himp (regular α) := ⟨λ a b, ⟨a ⇨ b, a.2.himp b.2⟩⟩
instance : has_compl (regular α) := ⟨λ a, ⟨aᶜ, is_regular_compl _⟩⟩
@[simp, norm_cast] lemma coe_top : ((⊤ : regular α) : α) = ⊤ := rfl
@[simp, norm_cast] lemma coe_bot : ((⊥ : regular α) : α) = ⊥ := rfl
@[simp, norm_cast] lemma coe_inf (a b : regular α) : (↑(a ⊓ b) : α) = a ⊓ b := rfl
@[simp, norm_cast] lemma coe_himp (a b : regular α) : (↑(a ⇨ b) : α) = a ⇨ b := rfl
@[simp, norm_cast] lemma coe_compl (a : regular α) : (↑(aᶜ) : α) = aᶜ := rfl
instance : inhabited (regular α) := ⟨⊥⟩
instance : semilattice_inf (regular α) := coe_injective.semilattice_inf _ coe_inf
instance : bounded_order (regular α) := bounded_order.lift coe (λ _ _, id) coe_top coe_bot
@[simp, norm_cast] lemma coe_le_coe {a b : regular α} : (a : α) ≤ b ↔ a ≤ b := iff.rfl
@[simp, norm_cast] lemma coe_lt_coe {a b : regular α} : (a : α) < b ↔ a < b := iff.rfl
/-- **Regularization** of `a`. The smallest regular element greater than `a`. -/
def to_regular : α →o regular α :=
⟨λ a, ⟨aᶜᶜ, is_regular_compl _⟩, λ a b h, coe_le_coe.1 $ compl_le_compl $ compl_le_compl h⟩
@[simp, norm_cast] lemma coe_to_regular (a : α) : (to_regular a : α) = aᶜᶜ := rfl
@[simp]
/-- The Galois insertion between `regular.to_regular` and `coe`. -/
def gi : galois_insertion to_regular (coe : regular α → α) :=
{ choice := λ a ha, ⟨a, ha.antisymm le_compl_compl⟩,
gc := λ a b, coe_le_coe.symm.trans $
⟨le_compl_compl.trans, λ h, (compl_anti $ compl_anti h).trans_eq b.2⟩,
le_l_u := λ _, le_compl_compl,
choice_eq := λ a ha, coe_injective $ le_compl_compl.antisymm ha }
instance : lattice (regular α) := gi.lift_lattice
@[simp, norm_cast] lemma coe_sup (a b : regular α) : (↑(a ⊔ b) : α) = (a ⊔ b)ᶜᶜ := rfl
instance : boolean_algebra (regular α) :=
{ le_sup_inf := λ a b c, coe_le_coe.1 $ by { dsimp, rw [sup_inf_left, compl_compl_inf_distrib] },
inf_compl_le_bot := λ a, coe_le_coe.1 $ disjoint_iff_inf_le.1 disjoint_compl_right,
top_le_sup_compl := λ a, coe_le_coe.1 $
by { dsimp, rw [compl_sup, inf_compl_eq_bot, compl_bot], refl },
himp_eq := λ a b, coe_injective begin
dsimp,
rw [compl_sup, a.prop.eq],
refine eq_of_forall_le_iff (λ c, le_himp_iff.trans _),
rw [le_compl_iff_disjoint_right, disjoint_left_comm, b.prop.disjoint_compl_left_iff],
end,
..regular.lattice, ..regular.bounded_order, ..regular.has_himp,
..regular.has_compl }
@[simp, norm_cast] lemma coe_sdiff (a b : regular α) : (↑(a \ b) : α) = a ⊓ bᶜ := rfl
end regular
end heyting_algebra
variables [boolean_algebra α]
lemma is_regular_of_boolean : ∀ a : α, is_regular a := compl_compl
/-- A decidable proposition is intuitionistically Heyting-regular. -/
@[nolint decidable_classical]
lemma is_regular_of_decidable (p : Prop) [decidable p] : is_regular p :=
propext $ decidable.not_not_iff _
end heyting
|
-- This file gives the definition of Gaussian Integers, and common
-- operations on them.
{-# OPTIONS --without-K --safe #-}
module GauInt.Base where
open import Data.Bool using (Bool ; true ; false ; T ; not ; _∧_)
open import Data.Nat using (ℕ ; _≡ᵇ_)
open import Data.Integer renaming (-_ to -ℤ_ ; _-_ to _-ℤ_ ; _+_ to _+ℤ_ ; _*_ to _*ℤ_ ) hiding (NonZero)
infix 4 _==_ -- boolean equality on 𝔾.
infix 4 _==ℤ_ -- boolean equality on ℤ.
infixl 6 _+_ _-_
infixl 7 _*_
infix 8 -_
infixl 9 _ᶜ -- conjugation on 𝔾.
-- A Gaussian integer is a pair of integers.
infix 5 _+_i
data 𝔾 : Set where
_+_i : ℤ -> ℤ -> 𝔾
-- Addition.
_+_ : 𝔾 -> 𝔾 -> 𝔾
(a + b i) + (c + d i) = x + y i where
x = a +ℤ c
y = b +ℤ d
-- Additive identity.
0𝔾 : 𝔾
0𝔾 = 0ℤ + 0ℤ i
-- Additive inverse.
-_ : 𝔾 -> 𝔾
- (a + b i) = (-ℤ a) + (-ℤ b) i
-- Subtraction.
_-_ : 𝔾 -> 𝔾 -> 𝔾
_-_ x y = x + (- y)
-- Multiplication.
_*_ : 𝔾 -> 𝔾 -> 𝔾
(a + b i) * (c + d i) = x + y i where
x = a *ℤ c -ℤ b *ℤ d
y = (a *ℤ d) +ℤ b *ℤ c
-- Multiplicative identity.
1𝔾 : 𝔾
1𝔾 = 1ℤ + 0ℤ i
-- imaginary unit i.
iG : 𝔾
iG = 0ℤ + 1ℤ i
-- Real and imaginary part.
Re : 𝔾 -> ℤ
Re (a + b i) = a
Im : 𝔾 -> ℤ
Im (a + b i) = b
-- Conjugation of complex numbers retricted to Gaussian integers.
_ᶜ : 𝔾 -> 𝔾
_ᶜ (a + b i) = a + (-ℤ b) i
-- Rank.
rank : 𝔾 -> ℕ
rank (a + b i) = ∣ a *ℤ a +ℤ b *ℤ b ∣
-- Boolean equality on ℤ.
_==ℤ_ : ℤ -> ℤ -> Bool
+_ n ==ℤ +_ m = n ≡ᵇ m
+_ n ==ℤ -[1+_] n₁ = false
-[1+_] n ==ℤ +_ n₁ = false
-[1+_] n ==ℤ -[1+_] m = n ≡ᵇ m
-- Boolean equality on 𝔾.
_==_ : 𝔾 -> 𝔾 -> Bool
a + b i == c + d i = (a ==ℤ c) ∧ (b ==ℤ d)
-- NonZero predicate. Intended to use as implicit argument to deal
-- with the zero divisor case.
record NonZero (x : 𝔾) : Set where
field
nonZero : T (not ( x == 0𝔾))
-- ----------------------------------------------------------------------
-- Injections
-- I don't have good notation for this.
infix 5 _+0i'
_+0i' : ℤ -> 𝔾
_+0i' n = n + 0ℤ i
-- Injection of naturals are used more often.
infix 5 _+0i
_+0i : ℕ -> 𝔾
_+0i n = + n +0i'
|
lemma infnorm_pos_le: fixes x :: "'a::euclidean_space" shows "0 \<le> infnorm x" |
The imaginary part of a complex number divided by a real number is the imaginary part of the complex number divided by the real number. |
import topology.basic
open topological_space set filter
localized "notation `𝓝` := nhds" in topological_space
localized "notation `𝓝[` s `] ` x:100 := nhds_within x s" in topological_space
noncomputable theory
open classical
variables {X : Type} [topological_space X] [nonempty X]
class t0_space (X : Type) [topological_space X] : Prop :=
(t0 : ∀ x y, x ≠ y → ∃ (U : set X), is_open U ∧ ((x ∈ U ∧ y ∉ U) ∨ (x ∉ U ∧ y ∈ U)) )
class t1_space (X : Type) [topological_space X] : Prop :=
(t1 : ∀ x y, x ≠ y → ∃ (U : set X), is_open U ∧ x ∈ U ∧ y ∉ U)
instance t1_space.t0_space [t1_space X] : t0_space X :=
begin
-- sorry
fconstructor,
intros x y hxy,
obtain ⟨U, hU, hh⟩ := t1_space.t1 x y hxy,
use U,
split,
{ exact hU },
{ exact or.inl hh }
-- sorry
end
lemma t1_iff_singleton_closed : t1_space X ↔ ∀ x, is_closed ({x} : set X) :=
begin
-- sorry
split,
{
introI,
intro x,
rw ← is_open_compl_iff,
have p : ⋃₀ {U : set X | (x ∉ U) ∧ (is_open U)} = {x}ᶜ,
{ apply subset.antisymm; intros t ht,
{ rcases ht with ⟨A, ⟨hxA, hA⟩, htA⟩,
rw [mem_compl_eq, mem_singleton_iff],
intro h,
exact hxA (by rwa h at htA) },
{ obtain ⟨U, hU, hh⟩ := t1_space.t1 t x (mem_compl_singleton_iff.mp ht),
use U,
split,
{ exact ⟨hh.2, hU⟩ },
{ exact hh.1 } } },
rw ← p,
apply is_open_sUnion,
intros B hB,
exact hB.2,
},
{
intro h,
fconstructor,
intros x y hxy,
use {y}ᶜ,
split,
{ exact is_open_compl_iff.mpr (h y) },
split,
{ exact mem_compl_singleton_iff.mpr hxy },
{ exact not_not.mpr rfl }
}
-- sorry
end
class t2_space (X : Type) [topological_space X] : Prop :=
(t2 : ∀ x y, x ≠ y → ∃ (U V: set X) (hU : is_open U) (hV: is_open V) (hUV : U ∩ V = ∅), x ∈ U ∧ y ∈ V)
instance t2_space.t1_space [t2_space X] : t1_space X :=
begin
-- sorry
fconstructor,
intros x y hxy,
obtain ⟨U, V, hU, hV, hUV, h⟩ := t2_space.t2 x y hxy,
use U,
split,
{ exact hU },
split,
{ exact h.1 },
{ intro con,
have ht : y ∈ (∅ : set X),
{
rw ← hUV,
exact ⟨con, h.2⟩
},
exact not_mem_empty y ht }
-- sorry
end
variables (f : filter X) (x : X)
def filter_lim (f : filter X) (x : X) := f ≤ 𝓝 x ∧ f ≠ ⊥
def limit_unicity (X : Type) [topological_space X] [nonempty X] :=
∀ (x y : X) (f : filter X) (hx : filter_lim f x) (hy : filter_lim f y), x=y
lemma t2_iff_unicity : t2_space X ↔ limit_unicity X :=
begin
-- sorry
split,
{
introI,
intros x y f hx hy,
by_contradiction hxy,
obtain ⟨U, V, hU, hV, hUV, hh⟩ := t2_space.t2 x y hxy,
have hhU : U ∈ f,
{ exact le_def.1 hx.1 U (is_open.mem_nhds hU hh.left) },
have hhV : V ∈ f,
{ exact le_def.1 hy.1 V (is_open.mem_nhds hV hh.right) },
obtain hf := filter.inter_sets f hhU hhV,
rw hUV at hf,
exact hx.2 (empty_mem_iff_bot.1 hf)
},
{
intro h1,
fconstructor,
intros x y hxy,
by_contra,
push_neg at h,
have : 𝓝 x ⊓ 𝓝 y ≠ ⊥,
{ intro t,
rw ← empty_mem_iff_bot at t,
rw mem_inf_iff at t,
obtain ⟨U₁, hU₁, V₁, hV₁, hUV₁⟩ := t,
obtain ⟨U, hU, hU_op, hxU⟩ := mem_nhds_iff.1 hU₁,
obtain ⟨V, hV, hV_op, hyV⟩ := mem_nhds_iff.1 hV₁,
have : U ∩ V = ∅,
{ have : U ∩ V ⊆ ∅,
{ rw hUV₁,
exact inter_subset_inter hU hV },
exact subset_eq_empty this rfl },
exact (h U V hU_op hV_op this hxU) hyV },
have hx : 𝓝 x ⊓ 𝓝 y ≤ 𝓝 x,
{ apply le_def.2,
intros T hT,
exact mem_inf_of_left hT },
have hy : 𝓝 x ⊓ 𝓝 y ≤ 𝓝 y,
{ apply le_def.2,
intros T hT,
exact mem_inf_of_right hT },
exact hxy (h1 x y (𝓝 x ⊓ 𝓝 y) ⟨hx, this⟩ ⟨hy, this⟩),
}
-- sorry
end
class t2_5_space (X : Type) [topological_space X] : Prop :=
(t2_5 : ∀ x y (h : x ≠ y), ∃ (U V: set X), is_open U ∧ is_open V ∧
closure U ∩ closure V = ∅ ∧ x ∈ U ∧ y ∈ V)
instance t2_5_space.t2_space [t2_5_space X] : t2_space X :=
begin
-- sorry
fconstructor,
intros x y hxy,
obtain ⟨U, V, hU, hV, hUV, h⟩ := t2_5_space.t2_5 x y hxy,
use U,
use V,
split,
{ exact hU },
split,
{ exact hV },
split,
{ have : U ∩ V ⊆ ∅,
{ rw ← hUV,
exact inter_subset_inter subset_closure subset_closure },
exact subset_eq_empty this rfl },
{ exact h }
-- sorry
end
def regular_space (X : Type) [topological_space X] := ∀ (x : X) (F : set X) (hF : is_closed F) (hxF : x ∉ F),
∃ (U V : set X) (hU : is_open U) (hV : is_open V) (hUV : U ∩ V = ∅), x ∈ U ∧ F ⊆ V
class t3_space (X : Type) [topological_space X] extends t1_space X : Prop :=
(regular : regular_space X)
instance t3_space.t2_space [t3_space X] : t2_space X :=
begin
-- sorry
fconstructor,
intros x y hxy,
obtain hsingleton := (@t1_iff_singleton_closed X _ _).1 t3_space.to_t1_space,
obtain ⟨U, V, hU, hV, hUV, h⟩ := t3_space.regular x {y} (hsingleton y) hxy,
obtain hyV := singleton_subset_iff.mp h.2,
exact ⟨U, V, hU, hV, hUV, h.1, hyV⟩,
-- sorry
end
instance t2_space.t2_5_space [t3_space X] : t2_5_space X :=
begin
-- sorry
fconstructor,
intros x y hxy,
obtain ⟨U, V, hU, hV, hUV, hh⟩ := t2_space.t2 x y hxy,
have hxcV : x ∉ closure V,
{ rw closure_eq_compl_interior_compl,
have : U ⊆ interior Vᶜ,
{ have : U ⊆ Vᶜ,
{ exact subset_compl_iff_disjoint.mpr hUV },
exact interior_maximal this hU },
tauto },
obtain ⟨A, B, hA, hB, hAB, hh2 ⟩ := t3_space.regular x (closure V) (is_closed_closure) hxcV,
have t : closure A ∩ closure V = ∅,
{
have hABc : A ⊆ Bᶜ,
{ exact subset_compl_iff_disjoint.mpr hAB },
have hBc_clos : is_closed Bᶜ,
{ exact is_closed_compl_iff.mpr hB },
have hcA_B: closure A ⊆ Bᶜ,
{ exact closure_minimal hABc hBc_clos },
have hB_emp : B ∩ Bᶜ = ∅,
{ exact sdiff_self },
have : closure A ∩ closure V ⊆ ∅,
{ rw [← hB_emp, inter_comm B Bᶜ],
exact inter_subset_inter hcA_B hh2.2 },
exact subset_eq_empty this rfl
},
exact ⟨A, V, hA, hV, t, hh2.1, hh.2⟩,
-- sorry
end
lemma inter_is_not_is_empty_intersection {X : Type} {x : X} {U V : set X}
(hxU : x ∈ U) (hUV : U ∩ V = ∅ ) : x ∉ V := disjoint_left.1 (disjoint_iff_inter_eq_empty.2 hUV) hxU
lemma t3_iff_t0_regular : t3_space X ↔ t0_space X ∧ regular_space X :=
begin
-- sorry
split,
{
introI,
split,
{ exact t1_space.t0_space },
{ exact t3_space.regular }
},
{
intro h,
haveI := h.1,
exact { t1:=
begin
intros x y hxy,
obtain ⟨U, hU, hh⟩ := t0_space.t0 x y hxy,
cases hh,
{ exact ⟨U, hU, hh⟩ },
{
have h_not_in_com : y ∉ Uᶜ,
{ intro t,
exact (not_mem_of_mem_compl t) hh.2 },
obtain ⟨V, T, hV, hT, hVT, hhh⟩ := h.2 y Uᶜ (is_closed_compl_iff.mpr hU) h_not_in_com,
use T,
split,
{ exact hT },
split,
{ exact hhh.2 hh.1 },
{ exact inter_is_not_is_empty_intersection hhh.1 hVT }
}
end, regular := h.2 },
}
-- sorry
end
lemma regular_iff_filter_def : regular_space X ↔ ∀{s:set X} {a}, is_closed s → a ∉ s → ∃t, is_open t ∧ s ⊆ t ∧ 𝓝[t] a = ⊥ :=
begin
-- sorry
split; intro h,
{
intros F x hF hxF,
obtain ⟨U, V, hU, hV, hUV, hh⟩ := h x F hF hxF,
use V,
split,
{ exact hV },
split,
{ exact hh.2 },
{ rw ← empty_mem_iff_bot,
have : ∅ ∈ 𝓝 x ⊓ principal V,
{
rw mem_inf_iff,
use U,
split,
{ exact is_open.mem_nhds hU hh.1 },
use V,
split,
{ exact mem_principal_self V },
{ exact eq.symm hUV }
},
exact this }
},
{
intros x F hF hxF,
obtain ⟨U, hU, hh⟩ := h hF hxF,
rw [← empty_mem_iff_bot] at hh,
have hexU : ∅ ∈ 𝓝 x ⊓ principal U,
{ exact hh.2 },
rw mem_inf_iff at hexU,
obtain ⟨T₁, hT₁, V, hV, hTV₁⟩ := hexU,
obtain ⟨T, hTT₁, hT⟩ := mem_nhds_iff.1 hT₁,
use T,
use U,
split,
{ exact hT.1 },
split,
{ exact hU },
split,
{ have : T ∩ U ⊆ ∅,
{ rw hTV₁,
exact inter_subset_inter hTT₁ (mem_principal.mp hV) },
exact subset_eq_empty this rfl },
{ exact ⟨hT.2, hh.1⟩ }
}
-- sorry
end
lemma t3_iff_open_closure : t3_space X ↔ t1_space X ∧ (∀ (x : X) (U : set X) (hx : x ∈ U) (hU : is_open U),
∃ (V : set X) (hV : is_open V), x ∈ V ∧ closure V ⊆ U) :=
begin
-- sorry
split,
{
introsI,
split,
{ exact t2_space.t1_space },
{
intros x U hx hU,
obtain ⟨V, T, hV, hT, hVT, h⟩ := t3_space.regular x Uᶜ (is_closed_compl_iff.mpr hU) (not_not.mpr hx),
use V,
split,
{ exact hV },
split,
{ exact h.1 },
{ have hclos_V_Tc : closure V ⊆ Tᶜ,
{ obtain HTc_clo := is_closed_compl_iff.mpr hT,
exact closure_minimal (subset_compl_iff_disjoint.mpr hVT) HTc_clo },
have hTc_U : Tᶜ ⊆ U,
{ exact compl_subset_comm.mp h.right },
exact powerset_mono.mpr hTc_U hclos_V_Tc }
},
},
{
intro h,
haveI := h.1,
exact {t1 := t1_space.t1, regular :=
begin
intros x F hF hxF,
obtain ⟨U, hU, hh⟩ := h.2 x Fᶜ (mem_compl hxF) (is_open_compl_iff.mpr hF),
use U,
use (closure U)ᶜ,
split,
{ exact hU },
split,
{ exact is_open_compl_iff.mpr is_closed_closure },
split,
{ have sub_empt : U ∩ (closure U)ᶜ ⊆ ∅,
{ rw ← (closure U).inter_compl_self,
exact (closure U)ᶜ.inter_subset_inter_left subset_closure },
exact subset_eq_empty sub_empt rfl },
split,
{ exact hh.1 },
{ exact subset_compl_comm.mp hh.right }
end},
}
-- sorry
end
def normal_space (X : Type) [topological_space X] := ∀ (F T : set X) (hF : is_closed F) (hT : is_closed T) (hFT : F ∩ T = ∅),
∃ (U V : set X) (hU : is_open U) (hV : is_open V) (hUV : U ∩ V = ∅), F ⊆ U ∧ T ⊆ V
class t4_space (X : Type) [topological_space X] extends t1_space X : Prop :=
(normal : normal_space X)
instance t4_space.t3_space [t4_space X] : t3_space X :=
begin
-- sorry
exact {t1 := t1_space.t1, regular :=
begin
intros x F hF hxF,
obtain hx := t1_iff_singleton_closed.1 t4_space.to_t1_space x,
have : {x} ∩ F = ∅,
{ exact singleton_inter_eq_empty.2 hxF },
obtain ⟨U, V, hU, hV, hUV, h⟩ := t4_space.normal {x} F hx hF this,
have hhx : x ∈ U,
{ exact singleton_subset_iff.mp h.left },
exact ⟨U, V, hU, hV, hUV, hhx, h.2⟩
end },
-- sorry
end
lemma t4_iff_open_closure : t4_space X ↔ t1_space X ∧ (∀ (U K : set X) (hK : is_closed K) (hU : is_open U) (hKU: K ⊆ U),
∃ (V : set X) (hV : is_open V), K ⊆ V ∧ closure V ⊆ U) :=
begin
-- sorry
split,
{
introI,
split,
{ exact t4_space.to_t1_space },
{
intros U K hK hU hKU,
have : K ∩ Uᶜ = ∅,
{ exact sdiff_eq_bot_iff.mpr hKU },
obtain ⟨V, T, hV, hT, hVT, h⟩ := t4_space.normal K Uᶜ hK (is_closed_compl_iff.mpr hU) this,
use V,
split,
{ exact hV },
split,
{ exact h.1 },
{ have hV_Tc : V ⊆ Tᶜ,
{ exact subset_compl_iff_disjoint.mpr hVT },
have hT_clos : is_closed Tᶜ,
{ exact is_closed_compl_iff.mpr hT },
obtain hVclos_T_com := closure_minimal hV_Tc hT_clos,
obtain hTcom_U := compl_subset_comm.mp h.right,
exact powerset_mono.mpr hTcom_U hVclos_T_com }
},
},
{
intro h,
haveI := h.1,
exact {t1 := t1_space.t1, normal :=
begin
intros F K hF hK hFK,
have hF_Kcom : F ⊆ Kᶜ,
{ exact subset_compl_iff_disjoint.mpr hFK },
obtain ⟨U, hU, hh⟩ := h.2 Kᶜ F hF (is_open_compl_iff.mpr hK) hF_Kcom,
use U,
use (closure U)ᶜ,
split,
{ exact hU },
split,
{ exact is_open_compl_iff.mpr is_closed_closure },
split,
{ have : U ∩ (closure U)ᶜ ⊆ ∅,
{ rw ← (closure U).inter_compl_self,
exact (closure U)ᶜ.inter_subset_inter_left subset_closure },
exact subset_eq_empty this rfl },
split,
{ exact hh.1 },
{ exact subset_compl_comm.mp hh.right }
end}
}
-- sorry
end |
program demo_fileclose
use M_io, only : fileclose, fileopen
implicit none
integer :: lun
integer :: ios, ierr
lun=fileopen('<input.txt',ios=ierr)
if(ierr.ne.0)then
write(*,*)'<ERROR> opening file'
endif
ios=fileclose(lun)
end program demo_fileclose
|
The limit of the complex conjugate of a function is the complex conjugate of the limit of the function. |
from classes.trainers.Trainer import Trainer
from classes.cv.FeatureSelector import FeatureSelector
from classes.factories.ClassifiersFactory import ClassifiersFactory
from classes.handlers.ParamsHandler import ParamsHandler
from classes.factories.DataSplitterFactory import DataSplitterFactory
import numpy as np
import random
import os
import pandas as pd
class TaskFusionTrainer(Trainer):
def __init__(self):
super().__init__()
@staticmethod
def average_results(data: list, model) -> object:
"""
:param data: list of Trainer objects that contain attributes pred_probs, preds, etc.
:param model: classifier for which the aggregation is to be done (only used to refer to a particular entry in the dictionary)
:return: Trainer object with updated values
"""
method = 'task_fusion'
avg_preds = {}
avg_pred_probs = {}
sub_data = None
num = 0
new_data = None
# This portion gets activated when across_tasks or across modalities aggregation is required
# since the model being passed is a single model (either GNB, or RF, or LR)
if type(model) == str:
new_data = data[-1][model]
num = len(data)
sub_data = np.array([data[t][model] for t in range(num)])
# This portion gets activated when within_tasks aggregation is required
# since the models being passed will be more than one
elif type(model) == list:
new_data = data[model[-1]]
num = len(model)
sub_data = np.array([data[m] for m in model])
# Find the union of all pids across all tasks
union_pids = np.unique(np.concatenate([list(sub_data[i].pred_probs[method].keys()) for i in range(num)]))
pred_probs_dict = {}
# averaging the pred_probs for a certain PID whenever it's seen across all tasks
for i in union_pids:
pred_probs_sum_list = np.zeros(3)
for t in range(num):
if i in sub_data[t].pred_probs[method]:
pred_probs_sum_list[0] += sub_data[t].pred_probs[method][i][0]
pred_probs_sum_list[1] += sub_data[t].pred_probs[method][i][1]
pred_probs_sum_list[2] += 1
pred_probs_dict[i] = np.array(
[pred_probs_sum_list[0] / pred_probs_sum_list[2], pred_probs_sum_list[1] / pred_probs_sum_list[2]])
avg_pred_probs[method] = pred_probs_dict
new_data.pred_probs = avg_pred_probs
# preds ------------------------------------------------------------------------------------------------------
# assigning True or False for preds based on what the averaged pred_probs were found in the previous step
preds_dict = {}
for i in avg_pred_probs[method]:
preds_dict[i] = avg_pred_probs[method][i][0] < avg_pred_probs[method][i][1]
avg_preds[method] = preds_dict
new_data.preds = avg_preds
# Return the updated new_data - only pred_probs and preds are changed, the rest are the same as the initially chosen new_data
return new_data
def train(self, data: dict, clf: str, seed: int, feature_set: str = '', feature_importance: bool = True):
self._clf = clf
self._method = 'task_fusion'
self._seed = seed
self._x = data['x']
self._y = data['y']
self._labels = np.array(data['labels'])
feature_names = list(self._x.columns.values)
splitter = DataSplitterFactory().get(mode=self._mode)
self._splits = splitter.make_splits(data=data, seed=self._seed)
# defining metrics
acc = []
fms = []
roc = []
precision = []
recall = []
specificity = []
pred = {}
pred_prob = {}
k_range = None
print("Model %s" % self._clf)
print("=========================")
for idx, fold in enumerate(self._splits):
print("Processing fold: %i" % idx)
x_train, y_train = fold['x_train'], fold['y_train'].ravel()
x_test, y_test = fold['x_test'], fold['y_test'].ravel()
labels_train, labels_test = fold['train_labels'], fold['test_labels']
acc_scores = []
fms_scores = []
roc_scores = []
p_scores = [] # precision
r_scores = [] # recall
spec_scores = []
# getting feature selected x_train, x_test and the list of selected features
x_train_fs, x_test_fs, selected_feature_names, k_range = \
FeatureSelector().select_features(fold_data=fold, feature_names=feature_names, k_range=k_range)
# fit the model
model = ClassifiersFactory.get_model(clf)
model = model.fit(x_train_fs, y_train)
# make predictions
yhat = model.predict(x_test_fs)
yhat_probs = model.predict_proba(x_test_fs)
for i in range(labels_test.shape[0]):
pred[labels_test[i]] = yhat[i]
pred_prob[labels_test[i]] = yhat_probs[i]
# calculating metrics for each fold
acc_scores, fms_scores, roc_scores, p_scores, r_scores, spec_scores = \
self.compute_save_results(y_true=y_test, y_pred=yhat,
y_prob=yhat_probs[:, 1], acc_saved=acc_scores,
fms_saved=fms_scores, roc_saved=roc_scores,
precision_saved=p_scores, recall_saved=r_scores, spec_saved=spec_scores)
# adding every fold metric to the bigger list of metrics
acc.append(acc_scores)
fms.append(fms_scores)
roc.append(roc_scores)
precision.append(p_scores)
recall.append(r_scores)
specificity.append(spec_scores)
self._save_results(method=self._method, acc=acc, fms=fms, roc=roc,
precision=precision, recall=recall, specificity=specificity,
pred=pred, pred_prob=pred_prob, k_range=k_range)
return self
def calculate_task_fusion_results(self, data):
acc = []
fms = []
roc = []
precision = []
recall = []
specificity = []
params = ParamsHandler.load_parameters('settings')
output_folder = params["output_folder"]
extraction_method = params["PID_extraction_method"]
nfolds = params['folds']
# get list of superset_ids from the saved file
super_pids_file_path = os.path.join('results', output_folder, extraction_method + '_super_pids.csv')
superset_ids = list(pd.read_csv(super_pids_file_path)['interview'])
# random shuffle based on random seed
random.Random(self._seed).shuffle(superset_ids)
splits = np.array_split(superset_ids, nfolds)
method = 'task_fusion'
pred = data.preds[method]
pred_prob = data.pred_probs[method]
k_range = data._best_k[method]['k_range']
# compute performance measures for each of the splits
for i in splits:
acc_scores = []
fms_scores = []
roc_scores = []
p_scores = [] # precision
r_scores = [] # recall
spec_scores = [] # specificity
# get the prediction probabilities, predicted outcomes, and labels for each of the PIDs in this split
y_true_sub = []
y_pred_sub = []
y_prob_sub = []
for j in i:
if j in data.y.keys():
y_true_sub.append(data.y[j])
y_pred_sub.append(data.preds[method][j])
y_prob_sub.append(data.pred_probs[method][j])
y_true_sub = np.array(y_true_sub)
y_pred_sub = np.array(y_pred_sub)
y_prob_sub = np.array(y_prob_sub)
# calculate the performance metrics at the fold level
acc_scores, fms_scores, roc_scores, p_scores, r_scores, spec_scores = \
self.compute_save_results(y_true=y_true_sub, y_pred=y_pred_sub,
y_prob=y_prob_sub[:, 1], acc_saved=acc_scores,
fms_saved=fms_scores, roc_saved=roc_scores,
precision_saved=p_scores, recall_saved=r_scores, spec_saved=spec_scores)
# saving performance metrics for each fold
acc.append(acc_scores)
fms.append(fms_scores)
roc.append(roc_scores)
precision.append(p_scores)
recall.append(r_scores)
specificity.append(spec_scores)
# save performance metrics
self._save_results(method, acc=acc, fms=fms, roc=roc,
precision=precision, recall=recall, specificity=specificity,
pred=pred, pred_prob=pred_prob, k_range=k_range)
return self
|
State Before: α : Type uu
r : α → α → Prop
a : α
l✝ l : List α
h : Sorted r l
k : ℕ
x y : α
hx : x ∈ take k l
hy : y ∈ drop k l
⊢ r x y State After: case intro.mk
α : Type uu
r : α → α → Prop
a : α
l✝ l : List α
h : Sorted r l
k : ℕ
x : α
hx : x ∈ take k l
iy : ℕ
hiy : iy < length (drop k l)
hy : get (drop k l) { val := iy, isLt := hiy } ∈ drop k l
⊢ r x (get (drop k l) { val := iy, isLt := hiy }) Tactic: obtain ⟨⟨iy, hiy⟩, rfl⟩ := get_of_mem hy State Before: case intro.mk
α : Type uu
r : α → α → Prop
a : α
l✝ l : List α
h : Sorted r l
k : ℕ
x : α
hx : x ∈ take k l
iy : ℕ
hiy : iy < length (drop k l)
hy : get (drop k l) { val := iy, isLt := hiy } ∈ drop k l
⊢ r x (get (drop k l) { val := iy, isLt := hiy }) State After: case intro.mk.intro.mk
α : Type uu
r : α → α → Prop
a : α
l✝ l : List α
h : Sorted r l
k iy : ℕ
hiy : iy < length (drop k l)
hy : get (drop k l) { val := iy, isLt := hiy } ∈ drop k l
ix : ℕ
hix : ix < length (take k l)
hx : get (take k l) { val := ix, isLt := hix } ∈ take k l
⊢ r (get (take k l) { val := ix, isLt := hix }) (get (drop k l) { val := iy, isLt := hiy }) Tactic: obtain ⟨⟨ix, hix⟩, rfl⟩ := get_of_mem hx State Before: case intro.mk.intro.mk
α : Type uu
r : α → α → Prop
a : α
l✝ l : List α
h : Sorted r l
k iy : ℕ
hiy : iy < length (drop k l)
hy : get (drop k l) { val := iy, isLt := hiy } ∈ drop k l
ix : ℕ
hix : ix < length (take k l)
hx : get (take k l) { val := ix, isLt := hix } ∈ take k l
⊢ r (get (take k l) { val := ix, isLt := hix }) (get (drop k l) { val := iy, isLt := hiy }) State After: case intro.mk.intro.mk
α : Type uu
r : α → α → Prop
a : α
l✝ l : List α
h : Sorted r l
k iy : ℕ
hiy : iy < length (drop k l)
hy : get (drop k l) { val := iy, isLt := hiy } ∈ drop k l
ix : ℕ
hix : ix < length (take k l)
hx : get (take k l) { val := ix, isLt := hix } ∈ take k l
⊢ r (get l { val := ↑{ val := ix, isLt := hix }, isLt := (_ : ↑{ val := ix, isLt := hix } < length l) })
(get l { val := k + ↑{ val := iy, isLt := hiy }, isLt := (_ : k + ↑{ val := iy, isLt := hiy } < length l) }) Tactic: rw [get_take', get_drop'] State Before: case intro.mk.intro.mk
α : Type uu
r : α → α → Prop
a : α
l✝ l : List α
h : Sorted r l
k iy : ℕ
hiy : iy < length (drop k l)
hy : get (drop k l) { val := iy, isLt := hiy } ∈ drop k l
ix : ℕ
hix : ix < length (take k l)
hx : get (take k l) { val := ix, isLt := hix } ∈ take k l
⊢ r (get l { val := ↑{ val := ix, isLt := hix }, isLt := (_ : ↑{ val := ix, isLt := hix } < length l) })
(get l { val := k + ↑{ val := iy, isLt := hiy }, isLt := (_ : k + ↑{ val := iy, isLt := hiy } < length l) }) State After: case intro.mk.intro.mk
α : Type uu
r : α → α → Prop
a : α
l✝ l : List α
h : Sorted r l
k iy : ℕ
hiy : iy < length (drop k l)
hy : get (drop k l) { val := iy, isLt := hiy } ∈ drop k l
ix : ℕ
hix✝ : ix < length (take k l)
hix : ix < min k (length l)
hx : get (take k l) { val := ix, isLt := hix✝ } ∈ take k l
⊢ r (get l { val := ↑{ val := ix, isLt := hix✝ }, isLt := (_ : ↑{ val := ix, isLt := hix✝ } < length l) })
(get l { val := k + ↑{ val := iy, isLt := hiy }, isLt := (_ : k + ↑{ val := iy, isLt := hiy } < length l) }) Tactic: rw [length_take] at hix State Before: case intro.mk.intro.mk
α : Type uu
r : α → α → Prop
a : α
l✝ l : List α
h : Sorted r l
k iy : ℕ
hiy : iy < length (drop k l)
hy : get (drop k l) { val := iy, isLt := hiy } ∈ drop k l
ix : ℕ
hix✝ : ix < length (take k l)
hix : ix < min k (length l)
hx : get (take k l) { val := ix, isLt := hix✝ } ∈ take k l
⊢ r (get l { val := ↑{ val := ix, isLt := hix✝ }, isLt := (_ : ↑{ val := ix, isLt := hix✝ } < length l) })
(get l { val := k + ↑{ val := iy, isLt := hiy }, isLt := (_ : k + ↑{ val := iy, isLt := hiy } < length l) }) State After: no goals Tactic: exact h.rel_nthLe_of_lt _ _ (ix.lt_add_right _ _ (lt_min_iff.mp hix).left) |
(* Title: Binary Search Trees, Tactic-Style
Author: Viktor Kuncak, MIT CSAIL, November 2003
Maintainer: Larry Paulson <Larry.Paulson at cl.cam.ac.uk>
License: LGPL
*)
section \<open>Tactic-Style Reasoning for Binary Tree Operations\<close>
theory BinaryTree_TacticStyle imports Main begin
text \<open>This example theory illustrates automated proofs of correctness
for binary tree operations using tactic-style reasoning.
The current proofs for remove operation are by Tobias Nipkow,
some modifications and the remaining tree operations are
by Viktor Kuncak.\<close>
(*============================================================*)
section \<open>Definition of a sorted binary tree\<close>
(*============================================================*)
datatype tree = Tip | Nd tree nat tree
primrec set_of :: "tree => nat set"
\<comment> \<open>The set of nodes stored in a tree.\<close>
where
"set_of Tip = {}"
| "set_of(Nd l x r) = set_of l Un set_of r Un {x}"
primrec sorted :: "tree => bool"
\<comment> \<open>Tree is sorted\<close>
where
"sorted Tip = True"
| "sorted(Nd l y r) =
(sorted l & sorted r & (\<forall>x \<in> set_of l. x < y) & (\<forall>z \<in> set_of r. y < z))"
(*============================================================*)
section \<open>Tree Membership\<close>
(*============================================================*)
primrec
memb :: "nat => tree => bool"
where
"memb e Tip = False"
| "memb e (Nd t1 x t2) =
(if e < x then memb e t1
else if x < e then memb e t2
else True)"
lemma member_set: "sorted t --> memb e t = (e : set_of t)"
by (induct t) auto
(*============================================================*)
section \<open>Insertion operation\<close>
(*============================================================*)
primrec binsert :: "nat => tree => tree"
\<comment> \<open>Insert a node into sorted tree.\<close>
where
"binsert x Tip = (Nd Tip x Tip)"
| "binsert x (Nd t1 y t2) = (if x < y then
(Nd (binsert x t1) y t2)
else
(if y < x then
(Nd t1 y (binsert x t2))
else (Nd t1 y t2)))"
theorem set_of_binsert [simp]: "set_of (binsert x t) = set_of t Un {x}"
by (induct t) auto
theorem binsert_sorted: "sorted t --> sorted (binsert x t)"
by (induct t) (auto simp add: set_of_binsert)
corollary binsert_spec: (* summary specification of binsert *)
"sorted t ==>
sorted (binsert x t) &
set_of (binsert x t) = set_of t Un {x}"
by (simp add: binsert_sorted)
(*============================================================*)
section \<open>Remove operation\<close>
(*============================================================*)
primrec
rm :: "tree => nat" \<comment> \<open>find the rightmost element in the tree\<close>
where
"rm(Nd l x r) = (if r = Tip then x else rm r)"
primrec
rem :: "tree => tree" \<comment> \<open>find the tree without the rightmost element\<close>
where
"rem(Nd l x r) = (if r=Tip then l else Nd l x (rem r))"
primrec
remove:: "nat => tree => tree" \<comment> \<open>remove a node from sorted tree\<close>
where
"remove x Tip = Tip"
| "remove x (Nd l y r) =
(if x < y then Nd (remove x l) y r else
if y < x then Nd l y (remove x r) else
if l = Tip then r
else Nd (rem l) (rm l) r)"
lemma rm_in_set_of: "t ~= Tip ==> rm t : set_of t"
by (induct t) auto
lemma set_of_rem: "t ~= Tip ==> set_of t = set_of(rem t) Un {rm t}"
by (induct t) auto
lemma sorted_rem: "[| t ~= Tip; x \<in> set_of(rem t); sorted t |] ==> x < rm t"
by (induct t) (auto simp add:set_of_rem split:if_splits)
theorem set_of_remove [simp]: "sorted t ==> set_of(remove x t) = set_of t - {x}"
apply(induct t)
apply simp
apply simp
apply(rule conjI)
apply fastforce
apply(rule impI)
apply(rule conjI)
apply fastforce
apply(fastforce simp:set_of_rem)
done
theorem remove_sorted: "sorted t ==> sorted(remove x t)"
by (induct t) (auto intro: less_trans rm_in_set_of sorted_rem)
corollary remove_spec: \<comment> \<open>summary specification of remove\<close>
"sorted t ==>
sorted (remove x t) &
set_of (remove x t) = set_of t - {x}"
by (simp add: remove_sorted)
text \<open>Finally, note that rem and rm can be computed
using a single tree traversal given by remrm.\<close>
primrec remrm :: "tree => tree * nat"
where
"remrm(Nd l x r) = (if r=Tip then (l,x) else
let (r',y) = remrm r in (Nd l x r',y))"
lemma "t ~= Tip ==> remrm t = (rem t, rm t)"
by (induct t) (auto simp:Let_def)
text \<open>We can test this implementation by generating code.\<close>
definition "test = memb 4 (remove (3::nat) (binsert 4 (binsert 3 Tip)))"
export_code test
in SML module_name BinaryTree_TacticStyle_Code file \<open>BinaryTree_TacticStyle_Code.ML\<close>
end
|
using IncludeGuards
println("TestModuleWorking.jl, module = ", @__MODULE__)
@includeonce "ModB.jl"
@includeonce "ModA.jl"
module TestModuleWorking
using ..A
using ..B
p = A.Parameters(1)
b = B.BStruct(params = p)
B.g(b)
end # module
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Relation.Binary.Raw.Construct.Intersection where
open import Cubical.Core.Everything
open import Cubical.Foundations.Function using (_∘_)
open import Cubical.Data.Prod
open import Cubical.Data.Sum.Base using (_⊎_; inl; inr; rec)
open import Cubical.Relation.Binary.Raw
open import Cubical.Relation.Nullary using (yes; no)
------------------------------------------------------------------------
-- Definition
_∩_ : ∀ {a b ℓ₁ ℓ₂} {A : Type a} {B : Type b} →
RawREL A B ℓ₁ → RawREL A B ℓ₂ → RawREL A B (ℓ-max ℓ₁ ℓ₂)
L ∩ R = λ i j → L i j × R i j
------------------------------------------------------------------------
-- Properties
module _ {a ℓ₁ ℓ₂} {A : Type a} (L : RawRel A ℓ₁) (R : RawRel A ℓ₂) where
reflexive : Reflexive L → Reflexive R → Reflexive (L ∩ R)
reflexive L-refl R-refl = L-refl , R-refl
symmetric : Symmetric L → Symmetric R → Symmetric (L ∩ R)
symmetric L-sym R-sym = map L-sym R-sym
transitive : Transitive L → Transitive R → Transitive (L ∩ R)
transitive L-trans R-trans (xLy , xRy) (yLz , yRz) = L-trans xLy yLz , R-trans xRy yRz
respects : ∀ {p} (P : A → Type p) →
P Respects L ⊎ P Respects R → P Respects (L ∩ R)
respects P resp (Lxy , Rxy) = rec (λ x → x Lxy) (λ x → x Rxy) resp
min : ∀ {⊤} → Minimum L ⊤ → Minimum R ⊤ → Minimum (L ∩ R) ⊤
min L-min R-min = intro L-min R-min
max : ∀ {⊥} → Maximum L ⊥ → Maximum R ⊥ → Maximum (L ∩ R) ⊥
max L-max R-max = intro L-max R-max
toNotEq : ToNotEq L ⊎ ToNotEq R → ToNotEq (L ∩ R)
toNotEq tonoteq (Lxy , Rxy) x≡y = rec (λ x → x Lxy x≡y) (λ y → y Rxy x≡y) tonoteq
irreflexive : Irreflexive L ⊎ Irreflexive R → Irreflexive (L ∩ R)
irreflexive irrefl (xLx , xRx) = rec (λ x → x xLx) (λ y → y xRx) irrefl
antisymmetric : Antisymmetric L ⊎ Antisymmetric R → Antisymmetric (L ∩ R)
antisymmetric (inl L-antisym) (Lxy , _) (Lyx , _) = L-antisym Lxy Lyx
antisymmetric (inr R-antisym) (_ , Rxy) (_ , Ryx) = R-antisym Rxy Ryx
module _ {a b ℓ₁ ℓ₂ ℓ₃} {A : Type a} {B : Type b}
(≈ : RawREL A B ℓ₁) {L : RawREL A B ℓ₂} {R : RawREL A B ℓ₃} where
implies : (≈ ⇒ L) → (≈ ⇒ R) → ≈ ⇒ (L ∩ R)
implies ≈⇒L ≈⇒R = intro ≈⇒L ≈⇒R
module _ {a ℓ₁ ℓ₂ ℓ₃} {A : Type a}
(≈ : RawRel A ℓ₁) (L : RawRel A ℓ₂) (R : RawRel A ℓ₃) where
respectsˡ : L Respectsˡ ≈ → R Respectsˡ ≈ → (L ∩ R) Respectsˡ ≈
respectsˡ L-resp R-resp x≈y = map (L-resp x≈y) (R-resp x≈y)
respectsʳ : L Respectsʳ ≈ → R Respectsʳ ≈ → (L ∩ R) Respectsʳ ≈
respectsʳ L-resp R-resp x≈y = map (L-resp x≈y) (R-resp x≈y)
respects₂ : L Respects₂ ≈ → R Respects₂ ≈ → (L ∩ R) Respects₂ ≈
respects₂ (Lʳ , Lˡ) (Rʳ , Rˡ) = respectsʳ Lʳ Rʳ , respectsˡ Lˡ Rˡ
module _ {a b ℓ₁ ℓ₂} {A : Type a} {B : Type b} {L : RawREL A B ℓ₁} {R : RawREL A B ℓ₂} where
decidable : Decidable L → Decidable R → Decidable (L ∩ R)
decidable L? R? x y = ×-dec (L? x y) (R? x y)
------------------------------------------------------------------------
-- Structures
module _ {a ℓ₁ ℓ₂} {A : Type a} {L : RawRel A ℓ₁} {R : RawRel A ℓ₂} where
isPartialEquivalence : IsPartialEquivalence L → IsPartialEquivalence R → IsPartialEquivalence (L ∩ R)
isPartialEquivalence eqₗ eqᵣ = record
{ symmetric = symmetric L R Eqₗ.symmetric Eqᵣ.symmetric
; transitive = transitive L R Eqₗ.transitive Eqᵣ.transitive
}
where module Eqₗ = IsPartialEquivalence eqₗ; module Eqᵣ = IsPartialEquivalence eqᵣ
isEquivalence : IsEquivalence L → IsEquivalence R → IsEquivalence (L ∩ R)
isEquivalence eqₗ eqᵣ = record
{ isPartialEquivalence = isPartialEquivalence Eqₗ.isPartialEquivalence Eqᵣ.isPartialEquivalence
; reflexive = reflexive L R Eqₗ.reflexive Eqᵣ.reflexive
}
where module Eqₗ = IsEquivalence eqₗ; module Eqᵣ = IsEquivalence eqᵣ
isDecEquivalence : IsDecEquivalence L → IsDecEquivalence R → IsDecEquivalence (L ∩ R)
isDecEquivalence eqₗ eqᵣ = record
{ isEquivalence = isEquivalence Eqₗ.isEquivalence Eqᵣ.isEquivalence
; _≟_ = decidable Eqₗ._≟_ Eqᵣ._≟_
}
where module Eqₗ = IsDecEquivalence eqₗ; module Eqᵣ = IsDecEquivalence eqᵣ
isPreorder : IsPreorder L → IsPreorder R → IsPreorder (L ∩ R)
isPreorder Oₗ Oᵣ = record
{ reflexive = reflexive L R Oₗ.reflexive Oᵣ.reflexive
; transitive = transitive L R Oₗ.transitive Oᵣ.transitive
}
where module Oₗ = IsPreorder Oₗ; module Oᵣ = IsPreorder Oᵣ
isPartialOrderˡ : IsPartialOrder L → IsPreorder R → IsPartialOrder (L ∩ R)
isPartialOrderˡ Oₗ Oᵣ = record
{ isPreorder = isPreorder Oₗ.isPreorder Oᵣ
; antisym = antisymmetric L R (inl Oₗ.antisym)
}
where module Oₗ = IsPartialOrder Oₗ; module Oᵣ = IsPreorder Oᵣ
isPartialOrderʳ : IsPreorder L → IsPartialOrder R → IsPartialOrder (L ∩ R)
isPartialOrderʳ Oₗ Oᵣ = record
{ isPreorder = isPreorder Oₗ Oᵣ.isPreorder
; antisym = antisymmetric L R (inr Oᵣ.antisym)
}
where module Oₗ = IsPreorder Oₗ; module Oᵣ = IsPartialOrder Oᵣ
isStrictPartialOrderˡ : IsStrictPartialOrder L → Transitive R → IsStrictPartialOrder (L ∩ R)
isStrictPartialOrderˡ Oₗ transitiveᵣ = record
{ irrefl = irreflexive L R (inl Oₗ.irrefl)
; transitive = transitive L R Oₗ.transitive transitiveᵣ
}
where module Oₗ = IsStrictPartialOrder Oₗ
isStrictPartialOrderʳ : Transitive L → IsStrictPartialOrder R → IsStrictPartialOrder (L ∩ R)
isStrictPartialOrderʳ transitiveₗ Oᵣ = record
{ irrefl = irreflexive L R (inr Oᵣ.irrefl)
; transitive = transitive L R transitiveₗ Oᵣ.transitive
}
where module Oᵣ = IsStrictPartialOrder Oᵣ
|
est_pi := proc(num_steps::integer)
local step, s, x, mypi, i, start_time, stop_time:
printf(" Estimating Pi using: %1d slices\n", num_steps):
start_time := time[real]():
step := 1.0/num_steps:
s:=0:
for i from 1 to num_steps do
x:=(i-0.5)*step:
s:=s+(4.0/(1.0 + x*x)):
end do:
mypi:=s*step:
stop_time := time[real]():
printf("Estimated value of Pi: %.16g\n", mypi):
printf(" Elapsed time(s): %.16g\n", stop_time - start_time):
printf(" Observed difference: %.16g\n", abs(Pi - mypi)):
mypi;
end proc:
native_est_pi := proc(num_steps::integer)
local step, mypi, k, start_time, stop_time:
printf(" Estimating Pi using: %1d slices\n", num_steps):
start_time := time[real]():
mypi:=Re(sum((4/(1+(((k-0.5)/num_steps)^2))),k=1..num_steps)/num_steps):
stop_time := time[real]():
printf("Estimated value of Pi: %.16g\n", mypi):
printf(" Elapsed time(s): %.16g\n", stop_time - start_time):
printf(" Observed difference: %.16g\n", abs(Pi - mypi)):
mypi;
end proc: |
Require Export Helpers.
(**
* Operator Definitions
- UnaryOperator : For unary operations
- BinaryArithOperator : For Binary Arithmetic Only
- BinaryCompOperator : For comparison of two values
*)
Inductive UnaryOperator : Type :=
| unot : UnaryOperator.
Inductive BinaryArithOperator : Type :=
| badd : BinaryArithOperator
| bsub : BinaryArithOperator
| bmult : BinaryArithOperator
| bdiv : BinaryArithOperator
| bmod : BinaryArithOperator
.
(**
- | band : BinaryArithOperator
- | bor : BinaryArithOperator
- | bxor : BinaryArithOperator
For later
*)
Inductive BinaryCompOperator : Type :=
| beq : BinaryCompOperator
| blt : BinaryCompOperator
| bgt : BinaryCompOperator.
Inductive PrimType : Type :=
| Int | Char | Bool.
Inductive Prim : Type :=
| boolean : nat -> Prim
| char : nat -> Prim
| int : nat -> Prim.
(**
* Signature for Functionality module on primitives
*)
Module Type PrimitiveType.
Parameter t : Type. (** ADT for primitives which is Prim *)
Parameter t_type : Type. (** ADT for primitive types *)
Parameter cast : t_type -> t -> t.
Parameter comp : t -> t -> nat.
Parameter toNat : t -> nat.
Parameter fromNat : t_type -> nat -> t.
Parameter getType : t -> t_type.
(**
- Axiom castToSame : forall x ty, ty = (getType x) -> (cast ty x) = x.
- Axiom castType : forall x ty, getType (cast ty x) = ty.
Not a priority, since Primitives are in separate modules, there execution can be updated anytime
without breaking whole system
*)
End PrimitiveType.
(**
* PType an implementation module
*)
Module PType <: PrimitiveType.
(**
Declares parameter ADTs for Primitive and PrimitiveType
*)
Definition t := Prim.
Definition t_type := PrimType.
(**
** Operations
- toNat : Prim to nat conversion
- fromNat : nat and input type to Prim of input type
- getType : return type of current Prim
- comp : compares two prims
- cast : cast given prim to prim of input type
*)
Fixpoint toNat (x:t) : nat :=
match x with
| boolean n => n
| char n => n
| int n => n
end.
Inductive toNatRel : t -> nat -> Prop :=
| boolToNatRel : forall n:nat, toNatRel (boolean n) n
| charToNatRel : forall n:nat, toNatRel (char n) n
| intToNatRel : forall n:nat, toNatRel (int n) n.
Theorem toNatRelEq : forall (x:t) (n:nat), toNat x = n <-> toNatRel x n.
Proof.
destruct x; split; intro; simpl in H; subst; try econstructor; try (inversion H; simpl; reflexivity).
Qed.
Fixpoint fromNat (ty:t_type) (n:nat) : t :=
match ty with
| Bool => boolean n
| Char => char n
| Int => int n
end.
Inductive fromNatRel : t_type -> nat -> t -> Prop :=
| boolFromNatRel : forall n:nat, fromNatRel Bool n (boolean n)
| charFromNatRel : forall n:nat, fromNatRel Char n (char n)
| intFromNatRel : forall n:nat, fromNatRel Int n (int n).
Theorem fromNatRelEq : forall (ty:t_type) (x:t) (n:nat), fromNat ty n = x <-> fromNatRel ty n x.
Proof.
destruct ty; split; intro; simpl in H; subst; try econstructor; try inversion H; simpl; reflexivity.
Qed.
Fixpoint getType (x:t) : t_type :=
match x with
| boolean x => Bool
| char x => Char
| int x => Int
end.
Inductive getTypeRel : t -> t_type -> Prop :=
| boolGetTypeRel: forall n:nat, getTypeRel (boolean n) Bool
| charGetTypeRel: forall n:nat, getTypeRel (char n) Char
| intGetTypeRel: forall n:nat, getTypeRel (int n) Int.
Theorem getTypeRelEq : forall (x:t) (ty:t_type), getType x = ty <-> getTypeRel x ty.
Proof.
destruct x; split; intro; simpl in H; subst; try econstructor; inversion H; simpl; reflexivity.
Qed.
Definition cast (ty:t_type) (x:t) : t :=
fromNat ty (toNat x).
Inductive castRel : t_type -> t -> t -> Prop:=
| castRelConstructor : forall (x1 x2:t) (ty:t_type) (n:nat), toNatRel x1 n -> fromNatRel ty n x2 -> castRel ty x1 x2.
Theorem castRelEq : forall (ty:t_type) (x1 x2:t), cast ty x1 = x2 <-> castRel ty x1 x2.
Proof.
intros; split; intro.
unfold cast in H.
remember (toNat x1) as n.
econstructor. eapply toNatRelEq. symmetry. eapply Heqn.
apply fromNatRelEq. assumption.
inversion H. unfold cast. apply toNatRelEq in H0. subst. apply fromNatRelEq.
assumption.
Qed.
Definition comp (x1 x2:t) : nat :=
(toNat x1) - (toNat x2).
End PType. |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jeremy Avigad, Yury Kudryashov
-/
import order.filter.at_top_bot
import order.filter.pi
/-!
# The cofinite filter
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file we define
`cofinite`: the filter of sets with finite complement
and prove its basic properties. In particular, we prove that for `ℕ` it is equal to `at_top`.
## TODO
Define filters for other cardinalities of the complement.
-/
open set function
open_locale classical
variables {ι α β : Type*} {l : filter α}
namespace filter
/-- The cofinite filter is the filter of subsets whose complements are finite. -/
def cofinite : filter α :=
{ sets := {s | sᶜ.finite},
univ_sets := by simp only [compl_univ, finite_empty, mem_set_of_eq],
sets_of_superset := assume s t (hs : sᶜ.finite) (st: s ⊆ t),
hs.subset $ compl_subset_compl.2 st,
inter_sets := assume s t (hs : sᶜ.finite) (ht : tᶜ.finite),
by simp only [compl_inter, finite.union, ht, hs, mem_set_of_eq] }
@[simp] lemma mem_cofinite {s : set α} : s ∈ (@cofinite α) ↔ sᶜ.finite := iff.rfl
@[simp] lemma eventually_cofinite {p : α → Prop} :
(∀ᶠ x in cofinite, p x) ↔ {x | ¬p x}.finite := iff.rfl
lemma has_basis_cofinite : has_basis cofinite (λ s : set α, s.finite) compl :=
⟨λ s, ⟨λ h, ⟨sᶜ, h, (compl_compl s).subset⟩, λ ⟨t, htf, hts⟩, htf.subset $ compl_subset_comm.2 hts⟩⟩
instance cofinite_ne_bot [infinite α] : ne_bot (@cofinite α) :=
has_basis_cofinite.ne_bot_iff.2 $ λ s hs, hs.infinite_compl.nonempty
lemma frequently_cofinite_iff_infinite {p : α → Prop} :
(∃ᶠ x in cofinite, p x) ↔ set.infinite {x | p x} :=
by simp only [filter.frequently, filter.eventually, mem_cofinite, compl_set_of, not_not,
set.infinite]
lemma _root_.set.finite.compl_mem_cofinite {s : set α} (hs : s.finite) : sᶜ ∈ (@cofinite α) :=
mem_cofinite.2 $ (compl_compl s).symm ▸ hs
lemma _root_.set.finite.eventually_cofinite_nmem {s : set α} (hs : s.finite) :
∀ᶠ x in cofinite, x ∉ s :=
hs.compl_mem_cofinite
lemma _root_.finset.eventually_cofinite_nmem (s : finset α) : ∀ᶠ x in cofinite, x ∉ s :=
s.finite_to_set.eventually_cofinite_nmem
lemma _root_.set.infinite_iff_frequently_cofinite {s : set α} :
set.infinite s ↔ (∃ᶠ x in cofinite, x ∈ s) :=
frequently_cofinite_iff_infinite.symm
lemma eventually_cofinite_ne (x : α) : ∀ᶠ a in cofinite, a ≠ x :=
(set.finite_singleton x).eventually_cofinite_nmem
lemma le_cofinite_iff_compl_singleton_mem : l ≤ cofinite ↔ ∀ x, {x}ᶜ ∈ l :=
begin
refine ⟨λ h x, h (finite_singleton x).compl_mem_cofinite, λ h s (hs : sᶜ.finite), _⟩,
rw [← compl_compl s, ← bUnion_of_singleton sᶜ, compl_Union₂,filter.bInter_mem hs],
exact λ x _, h x
end
lemma le_cofinite_iff_eventually_ne : l ≤ cofinite ↔ ∀ x, ∀ᶠ y in l, y ≠ x :=
le_cofinite_iff_compl_singleton_mem
/-- If `α` is a preorder with no maximal element, then `at_top ≤ cofinite`. -/
lemma at_top_le_cofinite [preorder α] [no_max_order α] : (at_top : filter α) ≤ cofinite :=
le_cofinite_iff_eventually_ne.mpr eventually_ne_at_top
lemma comap_cofinite_le (f : α → β) : comap f cofinite ≤ cofinite :=
le_cofinite_iff_eventually_ne.mpr $ λ x,
mem_comap.2 ⟨{f x}ᶜ, (finite_singleton _).compl_mem_cofinite, λ y, ne_of_apply_ne f⟩
/-- The coproduct of the cofinite filters on two types is the cofinite filter on their product. -/
lemma coprod_cofinite : (cofinite : filter α).coprod (cofinite : filter β) = cofinite :=
filter.coext $ λ s, by simp only [compl_mem_coprod, mem_cofinite, compl_compl,
finite_image_fst_and_snd_iff]
/-- Finite product of finite sets is finite -/
lemma Coprod_cofinite {α : ι → Type*} [finite ι] :
filter.Coprod (λ i, (cofinite : filter (α i))) = cofinite :=
filter.coext $ λ s, by simp only [compl_mem_Coprod, mem_cofinite, compl_compl,
forall_finite_image_eval_iff]
@[simp] lemma disjoint_cofinite_left : disjoint cofinite l ↔ ∃ s ∈ l, set.finite s :=
begin
simp only [has_basis_cofinite.disjoint_iff l.basis_sets, id, disjoint_compl_left_iff_subset],
exact ⟨λ ⟨s, hs, t, ht, hts⟩, ⟨t, ht, hs.subset hts⟩, λ ⟨s, hs, hsf⟩, ⟨s, hsf, s, hs, subset.rfl⟩⟩
end
@[simp] lemma disjoint_cofinite_right : disjoint l cofinite ↔ ∃ s ∈ l, set.finite s :=
disjoint.comm.trans disjoint_cofinite_left
end filter
open filter
/-- For natural numbers the filters `cofinite` and `at_top` coincide. -/
lemma nat.cofinite_eq_at_top : @cofinite ℕ = at_top :=
begin
refine le_antisymm _ at_top_le_cofinite,
refine at_top_basis.ge_iff.2 (λ N hN, _),
simpa only [mem_cofinite, compl_Ici] using finite_lt_nat N
end
lemma nat.frequently_at_top_iff_infinite {p : ℕ → Prop} :
(∃ᶠ n in at_top, p n) ↔ set.infinite {n | p n} :=
by rw [← nat.cofinite_eq_at_top, frequently_cofinite_iff_infinite]
lemma filter.tendsto.exists_within_forall_le {α β : Type*} [linear_order β] {s : set α}
(hs : s.nonempty)
{f : α → β} (hf : filter.tendsto f filter.cofinite filter.at_top) :
∃ a₀ ∈ s, ∀ a ∈ s, f a₀ ≤ f a :=
begin
rcases em (∃ y ∈ s, ∃ x, f y < x) with ⟨y, hys, x, hx⟩|not_all_top,
{ -- the set of points `{y | f y < x}` is nonempty and finite, so we take `min` over this set
have : {y | ¬x ≤ f y}.finite := (filter.eventually_cofinite.mp (tendsto_at_top.1 hf x)),
simp only [not_le] at this,
obtain ⟨a₀, ⟨ha₀ : f a₀ < x, ha₀s⟩, others_bigger⟩ :=
exists_min_image _ f (this.inter_of_left s) ⟨y, hx, hys⟩,
refine ⟨a₀, ha₀s, λ a has, (lt_or_le (f a) x).elim _ (le_trans ha₀.le)⟩,
exact λ h, others_bigger a ⟨h, has⟩ },
{ -- in this case, f is constant because all values are at top
push_neg at not_all_top,
obtain ⟨a₀, ha₀s⟩ := hs,
exact ⟨a₀, ha₀s, λ a ha, not_all_top a ha (f a₀)⟩ }
end
lemma filter.tendsto.exists_forall_le [nonempty α] [linear_order β] {f : α → β}
(hf : tendsto f cofinite at_top) :
∃ a₀, ∀ a, f a₀ ≤ f a :=
let ⟨a₀, _, ha₀⟩ := hf.exists_within_forall_le univ_nonempty in ⟨a₀, λ a, ha₀ a (mem_univ _)⟩
lemma filter.tendsto.exists_within_forall_ge [linear_order β] {s : set α} (hs : s.nonempty)
{f : α → β} (hf : filter.tendsto f filter.cofinite filter.at_bot) :
∃ a₀ ∈ s, ∀ a ∈ s, f a ≤ f a₀ :=
@filter.tendsto.exists_within_forall_le _ βᵒᵈ _ _ hs _ hf
lemma filter.tendsto.exists_forall_ge [nonempty α] [linear_order β] {f : α → β}
(hf : tendsto f cofinite at_bot) :
∃ a₀, ∀ a, f a ≤ f a₀ :=
@filter.tendsto.exists_forall_le _ βᵒᵈ _ _ _ hf
/-- For an injective function `f`, inverse images of finite sets are finite. See also
`filter.comap_cofinite_le` and `function.injective.comap_cofinite_eq`. -/
lemma function.injective.tendsto_cofinite {f : α → β} (hf : injective f) :
tendsto f cofinite cofinite :=
λ s h, h.preimage (hf.inj_on _)
/-- The pullback of the `filter.cofinite` under an injective function is equal to `filter.cofinite`.
See also `filter.comap_cofinite_le` and `function.injective.tendsto_cofinite`. -/
lemma function.injective.comap_cofinite_eq {f : α → β} (hf : injective f) :
comap f cofinite = cofinite :=
(comap_cofinite_le f).antisymm hf.tendsto_cofinite.le_comap
/-- An injective sequence `f : ℕ → ℕ` tends to infinity at infinity. -/
lemma function.injective.nat_tendsto_at_top {f : ℕ → ℕ} (hf : injective f) :
tendsto f at_top at_top :=
nat.cofinite_eq_at_top ▸ hf.tendsto_cofinite
|
/-
Copyright (c) 2020 The Xena project. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Kevin Buzzard
Thanks: Imperial College London, leanprover-community
-/
-- import levels 1 and 2
import complex.Level_02_I
/-! # Level 3: Complex conjugation -/
namespace complex
-- First complete the definition using `complex.mk` or `⟨x, y⟩` notation
/-- The complex conjugate of a complex number -/
def conj (z : ℂ) : ℂ := sorry
-- Now prove how it interacts with everything else
/-! ## Real and imaginary parts -/
@[simp] lemma conj_re (z : ℂ) : re(conj z) = re(z) := sorry
@[simp] lemma conj_im (z : ℂ) : im(conj z) = -im(z) := sorry
/-! ## Behaviour with respect to 0, 1 and I -/
@[simp] lemma conj_zero : conj 0 = 0 := sorry
@[simp] lemma conj_one : conj 1 = 1 := sorry
@[simp] lemma conj_I : conj I = -I := sorry
@[simp] lemma conj_neg_I : conj (-I) = I := sorry
/-! ## Behaviour with respect to +, - and * -/
@[simp] lemma conj_add (z w : ℂ) : conj (z + w) = conj z + conj w :=
sorry
@[simp] lemma conj_neg (z : ℂ) : conj (-z) = -conj z := sorry
@[simp] lemma conj_mul (z w : ℂ) : conj (z * w) = conj z * conj w :=
sorry
/-! ## Behaviour with respect to real numbers -/
@[simp] lemma conj_of_real (r : ℝ) : conj r = r := sorry
lemma im_eq_zero_of_eq_conj {z : ℂ} : conj z = z → im z = 0 := sorry
lemma eq_conj_iff_real {z : ℂ} : conj z = z ↔ ∃ r : ℝ, z = r :=
sorry
lemma eq_conj_iff_re {z : ℂ} : conj z = z ↔ (z.re : ℂ) = z :=
sorry
theorem add_conj (z : ℂ) : z + conj z = (2 * z.re : ℝ) :=
sorry
/-! ## Properties of the `conj` map -/
@[simp] lemma conj_conj (z : ℂ) : conj (conj z) = z :=
sorry
lemma conj_inj {z w : ℂ} : conj z = conj w ↔ z = w :=
sorry
@[simp] lemma conj_eq_zero {z : ℂ} : conj z = 0 ↔ z = 0 :=
sorry
/-
A ring homomorphism in Lean is the following collection
of data: a map, and the proof that it commutes with
the ring structures in the obvious way. Here we observe
that the work we've done is enough to define the
ring homomorphism complex conjugation.
-/
/-- the ring homomorphism complex conjugation -/
def Conj : ℂ →+* ℂ :=
{ to_fun := conj,
map_zero' := conj_zero,
map_one' := conj_one,
map_add' := conj_add,
map_mul' := conj_mul
}
-- Two optional lemmas which computer scientists like,
-- giving us easy access to some basic properties
-- of conj
open function
lemma conj_involutive : involutive conj := sorry
lemma conj_bijective : bijective conj := sorry
end complex
|
! This file is part of mctc-lib.
!
! Licensed under the Apache License, Version 2.0 (the "License");
! you may not use this file except in compliance with the License.
! You may obtain a copy of the License at
!
! http://www.apache.org/licenses/LICENSE-2.0
!
! Unless required by applicable law or agreed to in writing, software
! distributed under the License is distributed on an "AS IS" BASIS,
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
! See the License for the specific language governing permissions and
! limitations under the License.
module mctc_io_write_xyz
use mctc_io_convert, only : autoaa
use mctc_io_structure, only : structure_type
implicit none
private
public :: write_xyz
contains
subroutine write_xyz(self, unit, comment_line)
class(structure_type), intent(in) :: self
integer, intent(in) :: unit
character(len=*), intent(in), optional :: comment_line
integer :: iat
logical :: expo
write(unit, '(i0)') self%nat
if (present(comment_line)) then
write(unit, '(a)') comment_line
else
if (allocated(self%comment)) then
write(unit, '(a)') self%comment
else
write(unit, '(a)')
end if
end if
expo = maxval(self%xyz) > 1.0e+5 .or. minval(self%xyz) < -1.0e+5
if (expo) then
do iat = 1, self%nat
write(unit, '(a4, 1x, 3es24.14)') &
& self%sym(self%id(iat)), self%xyz(:, iat)*autoaa
enddo
else
do iat = 1, self%nat
write(unit, '(a4, 1x, 3f24.14)') &
& self%sym(self%id(iat)), self%xyz(:, iat)*autoaa
enddo
end if
end subroutine write_xyz
end module mctc_io_write_xyz
|
/-
Copyright (c) 2021 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import analysis.special_functions.exp
import topology.continuous_function.basic
/-!
# The circle
This file defines `circle` to be the metric sphere (`metric.sphere`) in `ℂ` centred at `0` of
radius `1`. We equip it with the following structure:
* a submonoid of `ℂ`
* a group
* a topological group
We furthermore define `exp_map_circle` to be the natural map `λ t, exp (t * I)` from `ℝ` to
`circle`, and show that this map is a group homomorphism.
## Implementation notes
Because later (in `geometry.manifold.instances.sphere`) one wants to equip the circle with a smooth
manifold structure borrowed from `metric.sphere`, the underlying set is
`{z : ℂ | abs (z - 0) = 1}`. This prevents certain algebraic facts from working definitionally --
for example, the circle is not defeq to `{z : ℂ | abs z = 1}`, which is the kernel of `complex.abs`
considered as a homomorphism from `ℂ` to `ℝ`, nor is it defeq to `{z : ℂ | norm_sq z = 1}`, which
is the kernel of the homomorphism `complex.norm_sq` from `ℂ` to `ℝ`.
-/
noncomputable theory
open complex metric
open_locale complex_conjugate
/-- The unit circle in `ℂ`, here given the structure of a submonoid of `ℂ`. -/
def circle : submonoid ℂ :=
{ carrier := sphere (0:ℂ) 1,
one_mem' := by simp,
mul_mem' := λ a b, begin
simp only [norm_eq_abs, mem_sphere_zero_iff_norm],
intros ha hb,
simp [ha, hb],
end }
@[simp] lemma mem_circle_iff_abs {z : ℂ} : z ∈ circle ↔ abs z = 1 := mem_sphere_zero_iff_norm
lemma circle_def : ↑circle = {z : ℂ | abs z = 1} := set.ext $ λ z, mem_circle_iff_abs
@[simp] lemma abs_coe_circle (z : circle) : abs z = 1 :=
mem_circle_iff_abs.mp z.2
lemma mem_circle_iff_norm_sq {z : ℂ} : z ∈ circle ↔ norm_sq z = 1 :=
by rw [mem_circle_iff_abs, complex.abs, real.sqrt_eq_one]
@[simp] lemma norm_sq_eq_of_mem_circle (z : circle) : norm_sq z = 1 := by simp [norm_sq_eq_abs]
lemma ne_zero_of_mem_circle (z : circle) : (z:ℂ) ≠ 0 := ne_zero_of_mem_unit_sphere z
instance : comm_group circle :=
{ inv := λ z, ⟨conj (z : ℂ), by simp⟩,
mul_left_inv := λ z, subtype.ext $ by { simp [has_inv.inv, ← norm_sq_eq_conj_mul_self,
← mul_self_abs] },
.. circle.to_comm_monoid }
lemma coe_inv_circle_eq_conj (z : circle) : ↑(z⁻¹) = conj (z : ℂ) := rfl
@[simp] lemma coe_inv_circle (z : circle) : ↑(z⁻¹) = (z : ℂ)⁻¹ :=
begin
rw coe_inv_circle_eq_conj,
apply eq_inv_of_mul_right_eq_one,
rw [mul_comm, ← complex.norm_sq_eq_conj_mul_self],
simp,
end
@[simp] lemma coe_div_circle (z w : circle) : ↑(z / w) = (z:ℂ) / w :=
show ↑(z * w⁻¹) = (z:ℂ) * w⁻¹, by simp
/-- The elements of the circle embed into the units. -/
@[simps]
def circle.to_units : circle →* units ℂ :=
{ to_fun := λ x, units.mk0 x $ ne_zero_of_mem_circle _,
map_one' := units.ext rfl,
map_mul' := λ x y, units.ext rfl }
instance : compact_space circle := metric.sphere.compact_space _ _
-- the following result could instead be deduced from the Lie group structure on the circle using
-- `topological_group_of_lie_group`, but that seems a little awkward since one has to first provide
-- and then forget the model space
instance : topological_group circle :=
{ continuous_mul := let h : continuous (λ x : circle, (x : ℂ)) := continuous_subtype_coe in
continuous_induced_rng (continuous_mul.comp (h.prod_map h)),
continuous_inv := continuous_induced_rng $
complex.conj_cle.continuous.comp continuous_subtype_coe }
/-- The map `λ t, exp (t * I)` from `ℝ` to the unit circle in `ℂ`. -/
def exp_map_circle : C(ℝ, circle) :=
{ to_fun := λ t, ⟨exp (t * I), by simp [exp_mul_I, abs_cos_add_sin_mul_I]⟩ }
@[simp] lemma exp_map_circle_apply (t : ℝ) : ↑(exp_map_circle t) = complex.exp (t * complex.I) :=
rfl
@[simp] lemma exp_map_circle_zero : exp_map_circle 0 = 1 :=
subtype.ext $ by rw [exp_map_circle_apply, of_real_zero, zero_mul, exp_zero, submonoid.coe_one]
@[simp] lemma exp_map_circle_add (x y : ℝ) :
exp_map_circle (x + y) = exp_map_circle x * exp_map_circle y :=
subtype.ext $ by simp only [exp_map_circle_apply, submonoid.coe_mul, of_real_add, add_mul,
complex.exp_add]
/-- The map `λ t, exp (t * I)` from `ℝ` to the unit circle in `ℂ`, considered as a homomorphism of
groups. -/
@[simps]
def exp_map_circle_hom : ℝ →+ (additive circle) :=
{ to_fun := additive.of_mul ∘ exp_map_circle,
map_zero' := exp_map_circle_zero,
map_add' := exp_map_circle_add }
@[simp] lemma exp_map_circle_sub (x y : ℝ) :
exp_map_circle (x - y) = exp_map_circle x / exp_map_circle y :=
exp_map_circle_hom.map_sub x y
|
[STATEMENT]
lemma cyclic_on_funpow_in:
assumes "cyclic_on f S" "s \<in> S" shows "(f^^n) s \<in> S"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (f ^^ n) s \<in> S
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
cyclic_on f S
s \<in> S
goal (1 subgoal):
1. (f ^^ n) s \<in> S
[PROOF STEP]
unfolding cyclic_on_def
[PROOF STATE]
proof (prove)
using this:
\<exists>s\<in>S. S = orbit f s
s \<in> S
goal (1 subgoal):
1. (f ^^ n) s \<in> S
[PROOF STEP]
by (auto intro: funpow_in_orbit) |
! { dg-do compile }
! Tests the fix for PR36366 a regression in which the order of USE statements
! in 'test2' would cause the result of 'test1' not to have a reference to
! the derived type 'inner'.
!
! Contributed by Jakub Jelinek <[email protected]>
!
MODULE types
IMPLICIT NONE
TYPE :: inner
INTEGER, POINTER :: i(:)
END TYPE inner
TYPE :: outer
TYPE(inner), POINTER :: inr(:)
END TYPE outer
END MODULE types
MODULE mymod
IMPLICIT NONE
CONTAINS
FUNCTION test1()
USE types
IMPLICIT NONE
TYPE(outer), POINTER :: test1
NULLIFY(test1)
END FUNCTION test1
END MODULE mymod
MODULE test
IMPLICIT NONE
CONTAINS
SUBROUTINE test2(a)
USE mymod
USE types
IMPLICIT NONE
TYPE(outer), INTENT(INOUT) :: a
INTEGER :: i
i = a%inr(1)%i(1)
END SUBROUTINE test2
SUBROUTINE test3(a)
USE types
IMPLICIT NONE
TYPE(outer), INTENT(IN) :: a
END SUBROUTINE test3
END MODULE test
|
module Text.Markup.Edda.Org
import public Text.Markup.Edda.Model
import public Text.Markup.Edda.Walk
import public Text.Markup.Edda.Query
import public Text.Markup.Edda.Reader.Org
import public Text.Markup.Edda.Writer.Org
|
(* Title: HOL/Auth/n_mutualExSimp_lemma_on_inv__2.thy
Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences
Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences
*)
header{*The n_mutualExSimp Protocol Case Study*}
theory n_mutualExSimp_lemma_on_inv__2 imports n_mutualExSimp_base
begin
section{*All lemmas on causal relation between inv__2 and some rule r*}
lemma n_CritVsinv__2:
assumes a1: "(\<exists> i. i\<le>N\<and>r=n_Crit i)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__2 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain i where a1:"i\<le>N\<and>r=n_Crit i" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__2 p__Inv4" apply fastforce done
have "(i=p__Inv4)\<or>(i~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(i=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_ExitVsinv__2:
assumes a1: "(\<exists> i. i\<le>N\<and>r=n_Exit i)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__2 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain i where a1:"i\<le>N\<and>r=n_Exit i" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__2 p__Inv4" apply fastforce done
have "(i=p__Inv4)\<or>(i~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(i=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv4)"
have "?P2 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_IdleVsinv__2:
assumes a1: "(\<exists> i. i\<le>N\<and>r=n_Idle i)" and
a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__2 p__Inv4)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain i where a1:"i\<le>N\<and>r=n_Idle i" apply fastforce done
from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__2 p__Inv4" apply fastforce done
have "(i=p__Inv4)\<or>(i~=p__Inv4)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(i=p__Inv4)"
have "?P1 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv4)"
have "?P3 s"
apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Para (Ident ''n'') p__Inv4)) (Const C)) (eqn (IVar (Para (Ident ''n'') i)) (Const E))))" in exI, auto) done
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
end
|
lemma islimpt_Un_finite: fixes x :: "'a::t1_space" shows "finite s \<Longrightarrow> x islimpt (s \<union> t) \<longleftrightarrow> x islimpt t" |
State Before: R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsDomain R
inst✝ : DiscreteValuationRing R
ϖ : R
hirr : Irreducible ϖ
u v : Rˣ
m n : ℕ
h : ↑u * ϖ ^ m = ↑v * ϖ ^ n
⊢ u = v State After: R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsDomain R
inst✝ : DiscreteValuationRing R
ϖ : R
hirr : Irreducible ϖ
u v : Rˣ
m : ℕ
h : ↑u * ϖ ^ m = ↑v * ϖ ^ m
⊢ u = v Tactic: obtain rfl : m = n := unit_mul_pow_congr_pow hirr hirr u v m n h State Before: R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsDomain R
inst✝ : DiscreteValuationRing R
ϖ : R
hirr : Irreducible ϖ
u v : Rˣ
m : ℕ
h : ↑u * ϖ ^ m = ↑v * ϖ ^ m
⊢ u = v State After: R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsDomain R
inst✝ : DiscreteValuationRing R
ϖ : R
hirr : Irreducible ϖ
u v : Rˣ
m : ℕ
h✝ : ↑u * ϖ ^ m = ↑v * ϖ ^ m
h : ↑u * ϖ ^ m - ↑v * ϖ ^ m = 0
⊢ u = v Tactic: rw [← sub_eq_zero] at h State Before: R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsDomain R
inst✝ : DiscreteValuationRing R
ϖ : R
hirr : Irreducible ϖ
u v : Rˣ
m : ℕ
h✝ : ↑u * ϖ ^ m = ↑v * ϖ ^ m
h : ↑u * ϖ ^ m - ↑v * ϖ ^ m = 0
⊢ u = v State After: R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsDomain R
inst✝ : DiscreteValuationRing R
ϖ : R
hirr : Irreducible ϖ
u v : Rˣ
m : ℕ
h✝ : ↑u * ϖ ^ m = ↑v * ϖ ^ m
h : ↑u - ↑v = 0 ∨ ϖ ^ m = 0
⊢ u = v Tactic: rw [← sub_mul, mul_eq_zero] at h State Before: R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsDomain R
inst✝ : DiscreteValuationRing R
ϖ : R
hirr : Irreducible ϖ
u v : Rˣ
m : ℕ
h✝ : ↑u * ϖ ^ m = ↑v * ϖ ^ m
h : ↑u - ↑v = 0 ∨ ϖ ^ m = 0
⊢ u = v State After: case inl
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsDomain R
inst✝ : DiscreteValuationRing R
ϖ : R
hirr : Irreducible ϖ
u v : Rˣ
m : ℕ
h✝ : ↑u * ϖ ^ m = ↑v * ϖ ^ m
h : ↑u - ↑v = 0
⊢ u = v
case inr
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsDomain R
inst✝ : DiscreteValuationRing R
ϖ : R
hirr : Irreducible ϖ
u v : Rˣ
m : ℕ
h✝ : ↑u * ϖ ^ m = ↑v * ϖ ^ m
h : ϖ ^ m = 0
⊢ u = v Tactic: cases' h with h h State Before: case inl
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsDomain R
inst✝ : DiscreteValuationRing R
ϖ : R
hirr : Irreducible ϖ
u v : Rˣ
m : ℕ
h✝ : ↑u * ϖ ^ m = ↑v * ϖ ^ m
h : ↑u - ↑v = 0
⊢ u = v State After: case inl
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsDomain R
inst✝ : DiscreteValuationRing R
ϖ : R
hirr : Irreducible ϖ
u v : Rˣ
m : ℕ
h✝ : ↑u * ϖ ^ m = ↑v * ϖ ^ m
h : ↑u = ↑v
⊢ u = v Tactic: rw [sub_eq_zero] at h State Before: case inl
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsDomain R
inst✝ : DiscreteValuationRing R
ϖ : R
hirr : Irreducible ϖ
u v : Rˣ
m : ℕ
h✝ : ↑u * ϖ ^ m = ↑v * ϖ ^ m
h : ↑u = ↑v
⊢ u = v State After: no goals Tactic: exact_mod_cast h State Before: case inr
R : Type u_1
inst✝² : CommRing R
inst✝¹ : IsDomain R
inst✝ : DiscreteValuationRing R
ϖ : R
hirr : Irreducible ϖ
u v : Rˣ
m : ℕ
h✝ : ↑u * ϖ ^ m = ↑v * ϖ ^ m
h : ϖ ^ m = 0
⊢ u = v State After: no goals Tactic: apply (hirr.ne_zero (pow_eq_zero h)).elim |
module Package.IkanAssets
%access public export
flGitignore : String
flGitignore = """
*.ibc
*.o
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*
ikan
"""
flMain : String
flMain = """
module Main\n
"""
flPkg : String->String
flPkg nm = """
package $nm
modules = Main
main = Main
sourcedir = src
executable = main
"""
|
[STATEMENT]
lemma bis_coind:
assumes *: "mono Retr" and "sym theta" and **: "theta \<subseteq> Retr (theta Un (bis Retr))"
shows "theta \<subseteq> bis Retr"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. theta \<subseteq> bis Retr
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. theta \<subseteq> bis Retr
[PROOF STEP]
let ?theta' = "theta Un (bis Retr)"
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. theta \<subseteq> bis Retr
[PROOF STEP]
have "sym ?theta'"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. sym (theta \<union> bis Retr)
[PROOF STEP]
by (metis Bisim.sym_Un sym_bis assms)
[PROOF STATE]
proof (state)
this:
sym (theta \<union> bis Retr)
goal (1 subgoal):
1. theta \<subseteq> bis Retr
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
sym (theta \<union> bis Retr)
goal (1 subgoal):
1. theta \<subseteq> bis Retr
[PROOF STEP]
have "?theta' \<subseteq> Retr ?theta'"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. theta \<union> bis Retr \<subseteq> Retr (theta \<union> bis Retr)
[PROOF STEP]
by (metis assms mono_Un Un_least bis_prefix le_supI2 subset_trans)
[PROOF STATE]
proof (state)
this:
theta \<union> bis Retr \<subseteq> Retr (theta \<union> bis Retr)
goal (1 subgoal):
1. theta \<subseteq> bis Retr
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
sym (theta \<union> bis Retr)
theta \<union> bis Retr \<subseteq> Retr (theta \<union> bis Retr)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
sym (theta \<union> bis Retr)
theta \<union> bis Retr \<subseteq> Retr (theta \<union> bis Retr)
goal (1 subgoal):
1. theta \<subseteq> bis Retr
[PROOF STEP]
using * bis_raw_coind
[PROOF STATE]
proof (prove)
using this:
sym (theta \<union> bis Retr)
theta \<union> bis Retr \<subseteq> Retr (theta \<union> bis Retr)
Bisim.mono Retr
\<lbrakk>Bisim.mono ?Retr; sym ?theta; ?theta \<subseteq> ?Retr ?theta\<rbrakk> \<Longrightarrow> ?theta \<subseteq> bis ?Retr
goal (1 subgoal):
1. theta \<subseteq> bis Retr
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
theta \<subseteq> bis Retr
goal:
No subgoals!
[PROOF STEP]
qed |
module Data.Bit where
open import Data.Nat.Literal using (Number; ℕ-num; Fin-num)
open import Data.Nat using (ℕ ; suc; zero; ⌊_/2⌋)
renaming (_*_ to ℕ*; _+_ to ℕ+; _≤_ to ℕ≤; _^_ to ℕ^)
open import Data.Int.Literal using (Negative)
open import Data.Fin using (Fin; suc; zero; raise)
renaming (toℕ to finToℕ; fromℕ to finFromℕ)
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import Data.Vec using (Vec; []; _∷_; _++_; replicate; insert; head; tail)
renaming (map to mapVec)
open import Data.Unit using (⊤)
open import Data.Empty using (⊥)
open import Level using (_⊔_)
open import Data.Bool using (Bool; false; true) renaming (_∧_ to Bool-∧)
open import Data.Maybe using (Maybe; just; nothing; map)
record WithCarry {a} {c} (A : Set a) (C : Set c) : Set (a ⊔ c) where
constructor _with-carry:_
field
result : A
carry : C
open WithCarry public
record Overflowing {a} (A : Set a) : Set a where
constructor _overflow:_
field
result : A
overflow : Bool
open Overflowing public
data Bit : Set where
b0 : Bit
b1 : Bit
infixl 8 _-_ _+_
infixl 7 _<<_ _>>_
infixl 6 _∧_ _&_
infixl 5 _⊕_ _^_
infixl 4 _∨_ _~|_
infixl 3 _↔_ _==_
infixl 1 _with-carry:_
fromBool : Bool → Bit
fromBool false = b0
fromBool true = b1
toBool : Bit → Bool
toBool b0 = false
toBool b1 = true
! : Bit → Bit
! b0 = b1
! b1 = b0
_∧_ : Bit → Bit → Bit
b0 ∧ _ = b0
b1 ∧ q = q
_∨_ : Bit → Bit → Bit
b0 ∨ q = q
b1 ∨ _ = b1
_⊕_ : Bit → Bit → Bit
b0 ⊕ q = q
b1 ⊕ q = ! q
_↔_ : Bit → Bit → Bit
b0 ↔ q = ! q
b1 ↔ q = q
maj3 : Bit → Bit → Bit → Bit
maj3 p q r = p ∧ q ∨ p ∧ r ∨ q ∧ r
half-add : Bit → Bit → WithCarry Bit Bit
half-add p q = p ⊕ q with-carry: p ∧ q
full-add : Bit → Bit → Bit → WithCarry Bit Bit
full-add p q r = p ⊕ q ⊕ r with-carry: maj3 p q r
full-addₙ : {n : ℕ} →
Vec Bit n →
Vec Bit n →
Bit →
WithCarry (Vec Bit n) (Vec Bit 2)
full-addₙ [] [] r = [] with-carry: b0 ∷ r ∷ []
full-addₙ (p ∷ []) (q ∷ []) r = result s ∷ [] with-carry: r ∷ carry s ∷ [] where
s = full-add p q r
full-addₙ (p ∷ ps) (q ∷ qs) r = result s ∷ result ss with-carry: carry ss where
s = full-add p q r
ss = full-addₙ ps qs (carry s)
!ₙ : {n : ℕ} → Vec Bit n → Vec Bit n
!ₙ = mapVec !
_+_ : {n : ℕ} → Vec Bit n → Vec Bit n → WithCarry (Vec Bit n) (Vec Bit 2)
ps + qs = full-addₙ ps qs b0
_-_ : {n : ℕ} → Vec Bit n → Vec Bit n → WithCarry (Vec Bit n) (Vec Bit 2)
ps - qs = full-addₙ ps (!ₙ qs) b1
inc : {n : ℕ} → Vec Bit n → WithCarry (Vec Bit n) (Vec Bit 2)
inc ps = full-addₙ ps (replicate b0) b1
dec : {n : ℕ} → Vec Bit n → WithCarry (Vec Bit n) (Vec Bit 2)
dec ps = full-addₙ ps (replicate b1) b0
_>>_ : {m : ℕ} → Vec Bit m → Fin m → WithCarry (Vec Bit m) (Vec Bit m)
ps >> zero = ps with-carry: replicate b0
_>>_ {suc m} (p ∷ ps) (suc i) = new-result with-carry: new-carry
where
qs : WithCarry (Vec Bit m) (Vec Bit m)
qs = ps >> i
new-result : Vec Bit (suc m)
new-result = insert (result qs) (finFromℕ m) b0
new-carry : Vec Bit (suc m)
new-carry = insert (carry qs) (finFromℕ m) p
_<<_ : {m : ℕ} → Vec Bit m → Fin m → WithCarry (Vec Bit m) (Vec Bit m)
_<<_ {m} ps i = proj₂ (do-shift ps) where
do-shift : {n : ℕ} → Vec Bit n → Fin m × WithCarry (Vec Bit n) (Vec Bit n)
do-shift [] = i , ([] with-carry: [])
do-shift {suc n} (p ∷ ps) = ret (proj₁ pair) where
pair : Fin m × WithCarry (Vec Bit n) (Vec Bit n)
pair = do-shift ps
qs : WithCarry (Vec Bit n) (Vec Bit n)
qs = proj₂ pair
ret : Fin m → Fin m × WithCarry (Vec Bit (suc n)) (Vec Bit (suc n))
ret zero = zero , (b0 ∷ result qs with-carry: p ∷ carry qs)
ret (suc j) = raise 1 j , (p ∷ result qs with-carry: b0 ∷ carry qs)
_>>>_ : {m : ℕ} → Vec Bit m → Fin m → WithCarry (Vec Bit m) (Vec Bit m)
ps >>> zero = ps with-carry: replicate b0
_>>>_ {suc m} (p ∷ ps) (suc i) = new-result with-carry: new-carry where
qs : WithCarry (Vec Bit m) (Vec Bit m)
qs = ps >> i
new-result : Vec Bit (suc m)
new-result = insert (result qs) (finFromℕ m) p
new-carry : Vec Bit (suc m)
new-carry = b0 ∷ carry qs
_<<<_ : {m : ℕ} → Vec Bit m → Fin m → WithCarry (Vec Bit m) (Vec Bit m)
ps <<< zero = ps with-carry: replicate b0
_<<<_ {suc m} (p ∷ ps) (suc i) = new-result with-carry: new-carry where
qs : WithCarry (Vec Bit m) (Vec Bit m)
qs = ps << i
new-result : Vec Bit (suc m)
new-result = p ∷ result qs
new-carry : Vec Bit (suc m)
new-carry = insert (result qs) (finFromℕ m) b0
_&_ : {n : ℕ} → Vec Bit n → Vec Bit n → Vec Bit n
[] & [] = []
(p ∷ ps) & (q ∷ qs) = p ∧ q ∷ ps & qs
_~|_ : {n : ℕ} → Vec Bit n → Vec Bit n → Vec Bit n
[] ~| [] = []
(p ∷ ps) ~| (q ∷ qs) = (p ∨ q) ∷ (ps ~| qs)
_^_ : {n : ℕ} → Vec Bit n → Vec Bit n → Vec Bit n
[] ^ [] = []
(p ∷ ps) ^ (q ∷ qs) = (p ⊕ q) ∷ (ps ^ qs)
~ : {n : ℕ} → Vec Bit n → WithCarry (Vec Bit n) (Vec Bit 2)
~ n = inc (!ₙ n)
toℕ : Bit → ℕ
toℕ b0 = 0
toℕ b1 = 1
toFin : {n : ℕ} → Bit → Fin (suc (suc n))
toFin b0 = 0
toFin b1 = 1
toℕₙ : {n : ℕ} → Vec Bit n → ℕ
toℕₙ [] = 0
toℕₙ (p ∷ ps) = ℕ+ (toℕ p) (ℕ* 2 (toℕₙ ps))
tryToFinₙ : {m n : ℕ} → Vec Bit m → Maybe (Fin n)
tryToFinₙ {_} {n} ps = tryℕ n (toℕₙ ps) where
tryℕ : (k : ℕ) → ℕ → Maybe (Fin k)
tryℕ zero _ = nothing
tryℕ (suc _) zero = just zero
tryℕ (suc m) (suc n) = map suc (tryℕ m n)
ℕ-mod2 : ℕ → Bit
ℕ-mod2 zero = b0
ℕ-mod2 (suc zero) = b1
ℕ-mod2 (suc (suc n)) = ℕ-mod2 n
instance
Bit-num : Number Bit
Bit-num .Number.Constraint n = constrain n where
constrain : ℕ → Set
constrain zero = ⊤
constrain (suc zero) = ⊤
constrain _ = ⊥
Bit-num .Number.fromNat n ⦃ p ⦄ = fromNat n p where
fromNat : (m : ℕ) → (Number.Constraint Bit-num) m → Bit
fromNat zero _ = b0
fromNat (suc zero) _ = b1
fromNat (suc (suc _)) ()
instance
Bits-num : {m : ℕ} → Number (Vec Bit m)
Bits-num {m} .Number.Constraint n = ℕ≤ (suc n) (ℕ^ 2 m)
Bits-num {m} .Number.fromNat n = fromNat m n where
fromNat : (m : ℕ) → ℕ → Vec Bit m
fromNat zero _ = []
fromNat (suc m) n = ℕ-mod2 n ∷ fromNat m ⌊ n /2⌋
instance
Bits-neg : {m : ℕ} → Negative (Vec Bit (suc m))
Bits-neg {m} .Negative.Constraint n = ℕ≤ n (ℕ^ 2 m)
Bits-neg {m} .Negative.fromNeg n = number where
iterateBits : (m : ℕ) → ℕ → Vec Bit m × Bit
iterateBits zero _ = [] , b0 where
iterateBits (suc m) n = newVec , newSign where
subRes : Vec Bit m × Bit
subRes = iterateBits m ⌊ n /2⌋
newVec : Vec Bit (suc m)
newVec = ℕ-mod2 n ∷ proj₁ subRes
newSign : Bit
newSign = ℕ-mod2 n ∨ proj₂ subRes
iteration : Vec Bit (suc m) × Bit
iteration = iterateBits (suc m) n
preNumber : Vec Bit (suc m)
preNumber = proj₁ iteration
signBit : Bit
signBit = proj₂ iteration
number : Vec Bit (suc m)
number = (head preNumber ∨ signBit) ∷ tail preNumber
_==_ : {n : ℕ} → Vec Bit n → Vec Bit n → Bool
[] == [] = true
p ∷ ps == q ∷ qs = Bool-∧ (toBool (p ↔ q)) (ps == qs)
|
#####
##### LSMR implementation copied from IterativeSolvers.jl
##### modified to make it non-allocating and to add multi-threading
##### https://github.com/JuliaLinearAlgebra/IterativeSolvers.jl/blob/v0.9.2/src/lsmr.jl
#####
struct LSMRWorkspace{TA, Tx, Tb, Tw}
A::TA
x::Tx
b::Tb
v::Tw
h::Tw
hbar::Tw
Av::Tb
Atu::Tw
end
function LSMRWorkspace(A)
T = eltype(A)
x = tfill!(Vector{T}(undef, size(A, 2)), zero(T))
b = tfill!(Vector{T}(undef, size(A, 1)), zero(T))
v = similar(x, T)
h = similar(x, T)
h̄ = similar(x, T)
Atu = similar(x, T)
Av = similar(b)
return LSMRWorkspace(A, x, b, v, h, h̄, Av, Atu)
end
function LSMRWorkspace(A, b::AbstractArray)
T = typeof(one(eltype(b)) / one(eltype(A)))
x = similar(b, T, size(A, 2))
return LSMRWorkspace(x, A, b)
end
function LSMRWorkspace(x::AbstractArray, A, b::AbstractArray)
T = typeof(one(eltype(b)) / one(eltype(A)))
u = isa(b, Array) ? tcopy(b) : copy(b)
v = similar(x, T)
h = similar(x, T)
h̄ = similar(x, T)
Atu = similar(x, T)
Av = similar(b)
return LSMRWorkspace(A, x, u, v, h, h̄, Av, Atu)
end
#== Not exported. Don't generate docs
"""
lsmr(A, b; kwargs...) -> x
Same as [`lsmr!`](@ref), but allocates a solution vector `x` initialized with
zeros.
"""
==#
lsmr(A, b; kwargs...) = lsmr!(LSMRWorkspace(A, b); kwargs...)
#== Not exported. Don't generate docs
"""
lsmr!(x, A, b; kwargs...) -> x
Minimizes ``\\|Ax - b\\|^2 + \\|λx\\|^2`` in the Euclidean norm. If multiple
solutions exists the minimum norm solution is returned.
The method is based on the Golub-Kahan bidiagonalization process. It is
algebraically equivalent to applying MINRES to the normal equations
``(A^*A + λ^2I)x = A^*b``, but has better numerical properties, especially if
``A`` is ill-conditioned.
### Arguments
- `x`: solution array
- `A`: linear operator
- `b`: right-hand side
### Keywords
- `lambda::Real = 0`: regularization parameter
- `atol::Real = 1e-6`: stopping tolerance
- `btol::Real = 1e-6`: stopping tolerance
- `conlim::Real = 1e8`: stopping tolerance
- `maxit::Int = 1 + min(size(A, 1), size(A, 2))`: maximum number of iterations
- `verbose::Bool = false`: print convergence information
### Returns
- `x`: approximated solution
### Notes
- `atol`, `btol`: LSMR continues iterations until a certain backward error
estimate is smaller than some quantity depending on ATOL and BTOL.
Let RES = B - A*X be the residual vector for the current approximate
solution X. If A*X = B seems to be consistent, LSMR terminates when
NORM(RES) <= ATOL*NORM(A)*NORM(X) + BTOL*NORM(B). Otherwise, LSMR
terminates when NORM(A'*RES) <= ATOL*NORM(A)*NORM(RES). If both tolerances
are 1.0e-6 (say), the final NORM(RES) should be accurate to about 6 digits.
(The final X will usually have fewer correct digits, depending on cond(A)
and the size of LAMBDA.) If ATOL or BTOL is [], a default value of 1.0e-6
will be used. Ideally, they should be estimates of the relative error in
the entries of A and B respectively. For example, if the entries of A
have 7 correct digits, set ATOL = 1e-7. This prevents the algorithm
from doing unnecessary work beyond the uncertainty of the input data.
- `conlim`: LSMR terminates if an estimate of cond(A) exceeds CONLIM. For
compatible systems Ax = b, conlim could be as large as 1.0e+12 (say).
For least-squares problems, conlim should be less than 1.0e+8. If CONLIM
is [], the default value is CONLIM = 1e+8. Maximum precision can be
obtained by setting ATOL = BTOL = CONLIM = 0, but the number of iterations
may then be excessive.
### References
D. C.-L. Fong and M. A. Saunders,
LSMR: An iterative algorithm for sparse least-squares problems,
SIAM J. Sci. Comput., submitted 1 June 2010.
See http://www.stanford.edu/~clfong/lsmr.html.
"""
==#
lsmr!(x, A, b; kwargs...) = lsmr!(LSMRWorkspace(x, A, b); kwargs...)
function lsmr!(
L::LSMRWorkspace;
atol::Real = 1e-6,
btol::Real = 1e-6,
conlim::Real = 1e8,
maxit::Int = 1 + min(size(L.A, 1), size(L.A, 2)),
lambda::Real = 0,
verbose::Bool = false
)
A, x, b = L.A, L.x, L.b
v, h, hbar, Av, Atu = L.v, L.h, L.hbar, L.Av, L.Atu
T = typeof(one(eltype(b)) / one(eltype(A)))
Tr = real(T)
At = adjoint(A)
# form the first vectors u and v (satisfy β*u = b, α*v = A'u)
u = b
β = norm(u)
if !iszero(β)
u = _scal!(inv(β), u)
end
mul!(v, At, u)
α = norm(v)
if !iszero(α)
v = _scal!(inv(α), v)
end
# Initialize variables for 1st iteration.
λ = convert(Tr, lambda)
ζbar = α * β
αbar = α
ρ = one(Tr)
ρbar = one(Tr)
cbar = one(Tr)
sbar = zero(Tr)
if isa(x, Array)
tfill!(x, 0)
else
fill!(x, 0)
end
if isa(h, Array) && isa(v, Array)
_tcopyto!(h, v)
else
copyto!(h, v)
end
if isa(hbar, Array)
tfill!(hbar, 0)
else
fill!(hbar, 0)
end
# Initialize variables for estimation of ||r||.
βdd = β
βd = zero(Tr)
ρdold = one(Tr)
τtildeold = zero(Tr)
θtilde = zero(Tr)
ζ = zero(Tr)
d = zero(Tr)
# Initialize variables for estimation of ||A|| and cond(A).
normA2 = abs2(α)
maxrbar = zero(Tr)
minrbar = typemax(Tr)
# Items for use in stopping rules.
i = 0
istop = 0
normb = β
normr = β
ϵa = convert(Tr, atol)
ϵb = convert(Tr, btol)
ϵc = conlim > 0 ? convert(Tr, inv(conlim)) : zero(Tr)
# Exit if b = 0 or A'b = 0.
normAr = α * β
if iszero(normAr)
if verbose
@printf("The exact solution is x = 0")
end
return x
end
if verbose
@printf("\nLSMR Least-squares solution of Ax = b\n")
@printf("The matrix A has %d rows and %d cols\n", size(A, 1), size(A, 2))
@printf("lambda = %16.10e\n", lambda)
@printf("atol = %8.2e\n", atol)
@printf("btol = %8.2e\n", btol)
@printf("conlim = %8.2e\n", conlim)
@printf("\n%7s %11s\t%8s %11s %5s\t%6s\t%8s\n",
"i", "||r||", "||A'r||", "compatible", "LS", "||A||", "cond A"
)
end
while i < maxit
i += 1
# u = A*v - α*u
# β = norm(u)
mul!(Av, A, v)
u, β = _xpby_norm!(Av, -α, u)
if !iszero(β)
u = _scal!(inv(β), u)
# v = A'*u - β*v
# α = norm(v)
mul!(Atu, At, u)
v, α = _xpby_norm!(Atu, -β, v)
if !iszero(α)
v = _scal!(inv(α), v)
end
end
# Construct rotation Qhat_{k,2k+1}.
αhat = hypot(αbar, λ)
chat = αbar / αhat
shat = λ / αhat
# Use a plane rotation (Q_i) to turn B_i to R_i.
ρold = ρ
ρ = hypot(αhat, β)
c = αhat / ρ
s = β / ρ
θnew = s * α
αbar = c * α
# Use a plane rotation (Qbar_i) to turn R_i^T to R_i^bar.
ρbarold = ρbar
ζold = ζ
θbar = sbar * ρ
ρtmp = cbar * ρ
ρbar = hypot(ρtmp, θnew)
cbar = ρtmp / ρbar
sbar = θnew / ρbar
ζ = cbar * ζbar
ζbar = -sbar * ζbar
# Update h, h_hat, x.
hbar, x, h, normx =
_update_hbar_x_h!(hbar, x, h, v, θbar, ρ, ρold, ρbarold, ζ, ρbar, θnew)
# Estimate of ||r||
# Apply rotation Qhat_{k,2k+1}.
βacute = chat * βdd
βcheck = -shat * βdd
# Apply rotation Q_{k,k+1}.
βhat = c * βacute
βdd = -s * βacute
# Apply rotation Qtilde_{k-1}.
θtildeold = θtilde
ρtildeold = hypot(ρdold, θbar)
ctildeold = ρdold / ρtildeold
stildeold = θbar / ρtildeold
θtilde = stildeold * ρbar
ρdold = ctildeold * ρbar
βd = -stildeold*βd + ctildeold*βhat
τtildeold = (ζold - θtildeold * τtildeold) / ρtildeold
τd = (ζ - θtilde * τtildeold) / ρdold
d += abs2(βcheck)
normr = sqrt(d + abs2(βd - τd) + abs2(βdd))
# Estimate ||A||.
normA2 += abs2(β)
normA = sqrt(normA2)
normA2 += abs2(α)
# Estimate cond(A).
maxrbar = max(maxrbar, ρbarold)
if i > 1
minrbar = min(minrbar, ρbarold)
end
condA = max(maxrbar, ρtmp) / min(minrbar, ρtmp)
# Test for convergence
# Compute norms for convergence testing.
normAr = abs(ζbar)
# Now use these norms to estimate certain other quantities,
# some of which will be small near a solution.
test1 = normr / normb
test2 = normAr / (normA * normr)
test3 = inv(condA)
t1 = test1 / (1 + normA * normx / normb)
ϵr = ϵb + ϵa * normA * normx / normb
# Allow for tolerances set by the user.
if test1 <= ϵr istop = 1
elseif test2 <= ϵa istop = 2
elseif test3 <= ϵc istop = 3
# The following tests guard against extremely small values of
# atol, btol or ctol. (The user may have set any or all of
# the parameters atol, btol, conlim to 0.)
# The effect is equivalent to the normAl tests using
# atol = eps, btol = eps, conlim = 1/eps.
elseif 1 + t1 <= 1 istop = 4
elseif 1 + test2 <= 1 istop = 5
elseif 1 + test3 <= 1 istop = 6
elseif i >= maxit istop = 7
end
if verbose
if size(A, 2) <= 50 ||
maxit <= 50 ||
i <= 10 ||
i >= maxit-10 ||
mod(i, 25) == 0 ||
test3 <= 1.1*ϵc ||
test2 <= 1.1*ϵa ||
test1 <= 1.1*ϵr ||
istop != 0
@printf("[%4d/%d]", i, maxit)
@printf(" %10.3e %10.3e", normr, normAr)
@printf(" %8.1e %8.1e", test1, test2)
@printf(" %8.1e %8.1e\n", normA, condA)
end
end
if istop > 0
break
end
end
if verbose
@printf("\n")
end
return x
end
@inline function _xpby_norm!(X, b, Y)
@. Y = muladd(b, Y, X)
return Y, norm(Y)
end
@inline function _xpby_norm!(X::Array, b::Real, Y::Array{T}) where {T}
Tr = real(T)
bT = convert(Tr, b)
@inbounds @batch threadlocal=zero(T)::T for I in eachindex(Y)
Y[I] = muladd(bT, Y[I], X[I])
threadlocal = muladd(conj(Y[I]), Y[I], threadlocal)
end
normY = sqrt(sum(real, threadlocal::Vector{T}))
return Y, normY
end
@inline function _scal!(a, X)
X .*= a
return X
end
@inline function _scal!(a, X::Array{T}) where {T}
aT = convert(real(T), a)
@inbounds @batch for I in eachindex(X)
X[I] *= aT
end
return X
end
@inline function _update_hbar_x_h!(h̄, x, h, v, θbar, ρ, ρold, ρbarold, ζ, ρbar, θnew)
δ = -θbar * ρ / (ρold * ρbarold)
σ = ζ / (ρ * ρbar)
ν = -θnew / ρ
@. h̄ = muladd(δ, h̄, h)
@. x = muladd(σ, h̄, x)
@. h = muladd(ν, h, v)
return h̄, x, h, norm(x)
end
@inline function _update_hbar_x_h!(
h̄::Array,
x::Array{T},
h::Array,
v::Array,
θbar::Real,
ρ::Real,
ρold::Real,
ρbarold::Real,
ζ::Real,
ρbar::Real,
θnew::Real
) where {T}
δ = -θbar * ρ / (ρold * ρbarold)
σ = ζ / (ρ * ρbar)
ν = -θnew / ρ
@inbounds @batch threadlocal=zero(T)::T for I in eachindex(x)
h̄[I] = muladd(δ, h̄[I], h[I])
x[I] = muladd(σ, h̄[I], x[I])
h[I] = muladd(ν, h[I], v[I])
threadlocal = muladd(conj(x[I]), x[I], threadlocal)
end
normx = sqrt(sum(real, threadlocal::Vector{T}))
return h̄, x, h, normx
end
|
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Mario Carneiro
-/
import data.option.basic
import data.sum
import logic.unique
import logic.function.basic
import data.quot
import tactic.simps
import logic.function.conjugate
import data.prod
import tactic.norm_cast
import data.sigma.basic
import data.subtype
/-!
# Equivalence between types
In this file we define two types:
* `equiv α β` a.k.a. `α ≃ β`: a bijective map `α → β` bundled with its inverse map; we use this (and
not equality!) to express that various `Type`s or `Sort`s are equivalent.
* `equiv.perm α`: the group of permutations `α ≃ α`. More lemmas about `equiv.perm` can be found in
`group_theory/perm`.
Then we define
* canonical isomorphisms between various types: e.g.,
- `equiv.refl α` is the identity map interpreted as `α ≃ α`;
- `equiv.sum_equiv_sigma_bool` is the canonical equivalence between the sum of two types `α ⊕ β`
and the sigma-type `Σ b : bool, cond b α β`;
- `equiv.prod_sum_distrib : α × (β ⊕ γ) ≃ (α × β) ⊕ (α × γ)` shows that type product and type sum
satisfy the distributive law up to a canonical equivalence;
* operations on equivalences: e.g.,
- `equiv.symm e : β ≃ α` is the inverse of `e : α ≃ β`;
- `equiv.trans e₁ e₂ : α ≃ γ` is the composition of `e₁ : α ≃ β` and `e₂ : β ≃ γ` (note the order
of the arguments!);
- `equiv.prod_congr ea eb : α₁ × β₁ ≃ α₂ × β₂`: combine two equivalences `ea : α₁ ≃ α₂` and
`eb : β₁ ≃ β₂` using `prod.map`.
* definitions that transfer some instances along an equivalence. By convention, we transfer
instances from right to left.
- `equiv.inhabited` takes `e : α ≃ β` and `[inhabited β]` and returns `inhabited α`;
- `equiv.unique` takes `e : α ≃ β` and `[unique β]` and returns `unique α`;
- `equiv.decidable_eq` takes `e : α ≃ β` and `[decidable_eq β]` and returns `decidable_eq α`.
More definitions of this kind can be found in other files. E.g., `data/equiv/transfer_instance`
does it for many algebraic type classes like `group`, `module`, etc.
## Tags
equivalence, congruence, bijective map
-/
open function
universes u v w z
variables {α : Sort u} {β : Sort v} {γ : Sort w}
/-- `α ≃ β` is the type of functions from `α → β` with a two-sided inverse. -/
@[nolint has_inhabited_instance]
structure equiv (α : Sort*) (β : Sort*) :=
(to_fun : α → β)
(inv_fun : β → α)
(left_inv : left_inverse inv_fun to_fun)
(right_inv : right_inverse inv_fun to_fun)
infix ` ≃ `:25 := equiv
/-- Convert an involutive function `f` to an equivalence with `to_fun = inv_fun = f`. -/
def function.involutive.to_equiv (f : α → α) (h : involutive f) : α ≃ α :=
⟨f, f, h.left_inverse, h.right_inverse⟩
namespace equiv
/-- `perm α` is the type of bijections from `α` to itself. -/
@[reducible] def perm (α : Sort*) := equiv α α
instance : has_coe_to_fun (α ≃ β) (λ _, α → β) := ⟨to_fun⟩
@[simp] theorem coe_fn_mk (f : α → β) (g l r) : (equiv.mk f g l r : α → β) = f :=
rfl
/-- The map `coe_fn : (r ≃ s) → (r → s)` is injective. -/
theorem coe_fn_injective : @function.injective (α ≃ β) (α → β) coe_fn
| ⟨f₁, g₁, l₁, r₁⟩ ⟨f₂, g₂, l₂, r₂⟩ h :=
have f₁ = f₂, from h,
have g₁ = g₂, from l₁.eq_right_inverse (this.symm ▸ r₂),
by simp *
@[simp, norm_cast] protected lemma coe_inj {e₁ e₂ : α ≃ β} : (e₁ : α → β) = e₂ ↔ e₁ = e₂ :=
coe_fn_injective.eq_iff
@[ext] lemma ext {f g : equiv α β} (H : ∀ x, f x = g x) : f = g :=
coe_fn_injective (funext H)
protected lemma congr_arg {f : equiv α β} : Π {x x' : α}, x = x' → f x = f x'
| _ _ rfl := rfl
protected lemma congr_fun {f g : equiv α β} (h : f = g) (x : α) : f x = g x := h ▸ rfl
lemma ext_iff {f g : equiv α β} : f = g ↔ ∀ x, f x = g x :=
⟨λ h x, h ▸ rfl, ext⟩
@[ext] lemma perm.ext {σ τ : equiv.perm α} (H : ∀ x, σ x = τ x) : σ = τ :=
equiv.ext H
protected lemma perm.congr_arg {f : equiv.perm α} {x x' : α} : x = x' → f x = f x' :=
equiv.congr_arg
protected lemma perm.congr_fun {f g : equiv.perm α} (h : f = g) (x : α) : f x = g x :=
equiv.congr_fun h x
lemma perm.ext_iff {σ τ : equiv.perm α} : σ = τ ↔ ∀ x, σ x = τ x :=
ext_iff
/-- Any type is equivalent to itself. -/
@[refl] protected def refl (α : Sort*) : α ≃ α := ⟨id, id, λ x, rfl, λ x, rfl⟩
instance inhabited' : inhabited (α ≃ α) := ⟨equiv.refl α⟩
/-- Inverse of an equivalence `e : α ≃ β`. -/
@[symm] protected def symm (e : α ≃ β) : β ≃ α := ⟨e.inv_fun, e.to_fun, e.right_inv, e.left_inv⟩
/-- See Note [custom simps projection] -/
def simps.symm_apply (e : α ≃ β) : β → α := e.symm
initialize_simps_projections equiv (to_fun → apply, inv_fun → symm_apply)
-- Generate the `simps` projections for previously defined equivs.
attribute [simps] function.involutive.to_equiv
/-- Composition of equivalences `e₁ : α ≃ β` and `e₂ : β ≃ γ`. -/
@[trans] protected def trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ :=
⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm,
e₂.left_inv.comp e₁.left_inv, e₂.right_inv.comp e₁.right_inv⟩
@[simp]
lemma to_fun_as_coe (e : α ≃ β) : e.to_fun = e := rfl
@[simp]
lemma inv_fun_as_coe (e : α ≃ β) : e.inv_fun = e.symm := rfl
protected theorem injective (e : α ≃ β) : injective e :=
e.left_inv.injective
protected theorem surjective (e : α ≃ β) : surjective e :=
e.right_inv.surjective
protected theorem bijective (f : α ≃ β) : bijective f :=
⟨f.injective, f.surjective⟩
protected theorem subsingleton (e : α ≃ β) [subsingleton β] : subsingleton α :=
e.injective.subsingleton
protected theorem subsingleton.symm (e : α ≃ β) [subsingleton α] : subsingleton β :=
e.symm.injective.subsingleton
lemma subsingleton_congr (e : α ≃ β) : subsingleton α ↔ subsingleton β :=
⟨λ h, by exactI e.symm.subsingleton, λ h, by exactI e.subsingleton⟩
instance equiv_subsingleton_cod [subsingleton β] :
subsingleton (α ≃ β) :=
⟨λ f g, equiv.ext $ λ x, subsingleton.elim _ _⟩
instance equiv_subsingleton_dom [subsingleton α] :
subsingleton (α ≃ β) :=
⟨λ f g, equiv.ext $ λ x, @subsingleton.elim _ (equiv.subsingleton.symm f) _ _⟩
instance perm_unique [subsingleton α] : unique (perm α) :=
unique_of_subsingleton (equiv.refl α)
lemma perm.subsingleton_eq_refl [subsingleton α] (e : perm α) :
e = equiv.refl α := subsingleton.elim _ _
/-- Transfer `decidable_eq` across an equivalence. -/
protected def decidable_eq (e : α ≃ β) [decidable_eq β] : decidable_eq α :=
e.injective.decidable_eq
lemma nonempty_congr (e : α ≃ β) : nonempty α ↔ nonempty β :=
nonempty.congr e e.symm
protected lemma nonempty (e : α ≃ β) [nonempty β] : nonempty α :=
e.nonempty_congr.mpr ‹_›
/-- If `α ≃ β` and `β` is inhabited, then so is `α`. -/
protected def inhabited [inhabited β] (e : α ≃ β) : inhabited α :=
⟨e.symm (default _)⟩
/-- If `α ≃ β` and `β` is a singleton type, then so is `α`. -/
protected def unique [unique β] (e : α ≃ β) : unique α :=
e.symm.surjective.unique
/-- Equivalence between equal types. -/
protected def cast {α β : Sort*} (h : α = β) : α ≃ β :=
⟨cast h, cast h.symm, λ x, by { cases h, refl }, λ x, by { cases h, refl }⟩
@[simp] theorem coe_fn_symm_mk (f : α → β) (g l r) : ((equiv.mk f g l r).symm : β → α) = g :=
rfl
@[simp] theorem coe_refl : ⇑(equiv.refl α) = id := rfl
@[simp] theorem perm.coe_subsingleton {α : Type*} [subsingleton α] (e : perm α) : ⇑(e) = id :=
by rw [perm.subsingleton_eq_refl e, coe_refl]
theorem refl_apply (x : α) : equiv.refl α x = x := rfl
@[simp] theorem coe_trans (f : α ≃ β) (g : β ≃ γ) : ⇑(f.trans g) = g ∘ f := rfl
theorem trans_apply (f : α ≃ β) (g : β ≃ γ) (a : α) : (f.trans g) a = g (f a) := rfl
@[simp] theorem apply_symm_apply (e : α ≃ β) (x : β) : e (e.symm x) = x :=
e.right_inv x
@[simp] theorem symm_apply_apply (e : α ≃ β) (x : α) : e.symm (e x) = x :=
e.left_inv x
@[simp] theorem symm_comp_self (e : α ≃ β) : e.symm ∘ e = id := funext e.symm_apply_apply
@[simp] theorem self_comp_symm (e : α ≃ β) : e ∘ e.symm = id := funext e.apply_symm_apply
@[simp] lemma symm_trans_apply (f : α ≃ β) (g : β ≃ γ) (a : γ) :
(f.trans g).symm a = f.symm (g.symm a) := rfl
-- The `simp` attribute is needed to make this a `dsimp` lemma.
-- `simp` will always rewrite with `equiv.symm_symm` before this has a chance to fire.
@[simp, nolint simp_nf] theorem symm_symm_apply (f : α ≃ β) (b : α) : f.symm.symm b = f b := rfl
@[simp] theorem apply_eq_iff_eq (f : α ≃ β) {x y : α} : f x = f y ↔ x = y :=
f.injective.eq_iff
theorem apply_eq_iff_eq_symm_apply {α β : Sort*} (f : α ≃ β) {x : α} {y : β} :
f x = y ↔ x = f.symm y :=
begin
conv_lhs { rw ←apply_symm_apply f y, },
rw apply_eq_iff_eq,
end
@[simp] theorem cast_apply {α β} (h : α = β) (x : α) : equiv.cast h x = cast h x := rfl
@[simp] theorem cast_symm {α β} (h : α = β) : (equiv.cast h).symm = equiv.cast h.symm := rfl
@[simp] theorem cast_refl {α} (h : α = α := rfl) : equiv.cast h = equiv.refl α := rfl
@[simp] theorem cast_trans {α β γ} (h : α = β) (h2 : β = γ) :
(equiv.cast h).trans (equiv.cast h2) = equiv.cast (h.trans h2) :=
ext $ λ x, by { substs h h2, refl }
lemma cast_eq_iff_heq {α β} (h : α = β) {a : α} {b : β} : equiv.cast h a = b ↔ a == b :=
by { subst h, simp }
lemma symm_apply_eq {α β} (e : α ≃ β) {x y} : e.symm x = y ↔ x = e y :=
⟨λ H, by simp [H.symm], λ H, by simp [H]⟩
lemma eq_symm_apply {α β} (e : α ≃ β) {x y} : y = e.symm x ↔ e y = x :=
(eq_comm.trans e.symm_apply_eq).trans eq_comm
@[simp] theorem symm_symm (e : α ≃ β) : e.symm.symm = e := by { cases e, refl }
@[simp] theorem trans_refl (e : α ≃ β) : e.trans (equiv.refl β) = e := by { cases e, refl }
@[simp] theorem refl_symm : (equiv.refl α).symm = equiv.refl α := rfl
@[simp] theorem refl_trans (e : α ≃ β) : (equiv.refl α).trans e = e := by { cases e, refl }
@[simp] theorem symm_trans_self (e : α ≃ β) : e.symm.trans e = equiv.refl β := ext (by simp)
@[simp] theorem self_trans_symm (e : α ≃ β) : e.trans e.symm = equiv.refl α := ext (by simp)
lemma trans_assoc {δ} (ab : α ≃ β) (bc : β ≃ γ) (cd : γ ≃ δ) :
(ab.trans bc).trans cd = ab.trans (bc.trans cd) :=
equiv.ext $ assume a, rfl
theorem left_inverse_symm (f : equiv α β) : left_inverse f.symm f := f.left_inv
theorem right_inverse_symm (f : equiv α β) : function.right_inverse f.symm f := f.right_inv
@[simp] lemma injective_comp (e : α ≃ β) (f : β → γ) : injective (f ∘ e) ↔ injective f :=
injective.of_comp_iff' f e.bijective
@[simp] lemma comp_injective (f : α → β) (e : β ≃ γ) : injective (e ∘ f) ↔ injective f :=
e.injective.of_comp_iff f
@[simp] lemma surjective_comp (e : α ≃ β) (f : β → γ) : surjective (f ∘ e) ↔ surjective f :=
e.surjective.of_comp_iff f
@[simp] lemma comp_surjective (f : α → β) (e : β ≃ γ) : surjective (e ∘ f) ↔ surjective f :=
surjective.of_comp_iff' e.bijective f
@[simp] lemma bijective_comp (e : α ≃ β) (f : β → γ) : bijective (f ∘ e) ↔ bijective f :=
e.bijective.of_comp_iff f
@[simp] lemma comp_bijective (f : α → β) (e : β ≃ γ) : bijective (e ∘ f) ↔ bijective f :=
bijective.of_comp_iff' e.bijective f
/-- If `α` is equivalent to `β` and `γ` is equivalent to `δ`, then the type of equivalences `α ≃ γ`
is equivalent to the type of equivalences `β ≃ δ`. -/
def equiv_congr {δ} (ab : α ≃ β) (cd : γ ≃ δ) : (α ≃ γ) ≃ (β ≃ δ) :=
⟨ λac, (ab.symm.trans ac).trans cd, λbd, ab.trans $ bd.trans $ cd.symm,
assume ac, by { ext x, simp }, assume ac, by { ext x, simp } ⟩
@[simp] lemma equiv_congr_refl {α β} :
(equiv.refl α).equiv_congr (equiv.refl β) = equiv.refl (α ≃ β) := by { ext, refl }
@[simp] lemma equiv_congr_symm {δ} (ab : α ≃ β) (cd : γ ≃ δ) :
(ab.equiv_congr cd).symm = ab.symm.equiv_congr cd.symm := by { ext, refl }
@[simp] lemma equiv_congr_trans {δ ε ζ} (ab : α ≃ β) (de : δ ≃ ε) (bc : β ≃ γ) (ef : ε ≃ ζ) :
(ab.equiv_congr de).trans (bc.equiv_congr ef) = (ab.trans bc).equiv_congr (de.trans ef) :=
by { ext, refl }
@[simp] lemma equiv_congr_refl_left {α β γ} (bg : β ≃ γ) (e : α ≃ β) :
(equiv.refl α).equiv_congr bg e = e.trans bg := rfl
@[simp] lemma equiv_congr_refl_right {α β} (ab e : α ≃ β) :
ab.equiv_congr (equiv.refl β) e = ab.symm.trans e := rfl
@[simp] lemma equiv_congr_apply_apply {δ} (ab : α ≃ β) (cd : γ ≃ δ) (e : α ≃ γ) (x) :
ab.equiv_congr cd e x = cd (e (ab.symm x)) := rfl
section perm_congr
variables {α' β' : Type*} (e : α' ≃ β')
/-- If `α` is equivalent to `β`, then `perm α` is equivalent to `perm β`. -/
def perm_congr : perm α' ≃ perm β' :=
equiv_congr e e
lemma perm_congr_def (p : equiv.perm α') :
e.perm_congr p = (e.symm.trans p).trans e := rfl
@[simp] lemma perm_congr_refl :
e.perm_congr (equiv.refl _) = equiv.refl _ :=
by simp [perm_congr_def]
@[simp] lemma perm_congr_symm :
e.perm_congr.symm = e.symm.perm_congr := rfl
@[simp] lemma perm_congr_apply (p : equiv.perm α') (x) :
e.perm_congr p x = e (p (e.symm x)) := rfl
lemma perm_congr_symm_apply (p : equiv.perm β') (x) :
e.perm_congr.symm p x = e.symm (p (e x)) := rfl
lemma perm_congr_trans (p p' : equiv.perm α') :
(e.perm_congr p).trans (e.perm_congr p') = e.perm_congr (p.trans p') :=
by { ext, simp }
end perm_congr
/-- If `α` is an empty type, then it is equivalent to the `empty` type. -/
def equiv_empty (α : Sort u) [is_empty α] : α ≃ empty :=
⟨is_empty_elim, λ e, e.rec _, is_empty_elim, λ e, e.rec _⟩
/-- `α` is equivalent to an empty type iff `α` is empty. -/
def equiv_empty_equiv (α : Sort u) : (α ≃ empty) ≃ is_empty α :=
⟨λ e, function.is_empty e, @equiv_empty α, λ e, ext $ λ x, (e x).elim, λ p, rfl⟩
/-- `false` is equivalent to `empty`. -/
def false_equiv_empty : false ≃ empty :=
equiv_empty _
/-- If `α` is an empty type, then it is equivalent to the `pempty` type in any universe. -/
def {u' v'} equiv_pempty (α : Sort v') [is_empty α] : α ≃ pempty.{u'} :=
⟨is_empty_elim, λ e, e.rec _, is_empty_elim, λ e, e.rec _⟩
/-- `false` is equivalent to `pempty`. -/
def false_equiv_pempty : false ≃ pempty :=
equiv_pempty _
/-- `empty` is equivalent to `pempty`. -/
def empty_equiv_pempty : empty ≃ pempty :=
equiv_pempty _
/-- `pempty` types from any two universes are equivalent. -/
def pempty_equiv_pempty : pempty.{v} ≃ pempty.{w} :=
equiv_pempty _
/-- The `Sort` of proofs of a true proposition is equivalent to `punit`. -/
def prop_equiv_punit {p : Prop} (h : p) : p ≃ punit :=
⟨λ x, (), λ x, h, λ _, rfl, λ ⟨⟩, rfl⟩
/-- The `Sort` of proofs of a false proposition is equivalent to `pempty`. -/
def prop_equiv_pempty {p : Prop} (h : ¬p) : p ≃ pempty :=
⟨λ x, absurd x h, λ x, by cases x, λ x, absurd x h, λ x, by cases x⟩
/-- `true` is equivalent to `punit`. -/
def true_equiv_punit : true ≃ punit := prop_equiv_punit trivial
/-- `ulift α` is equivalent to `α`. -/
@[simps apply symm_apply {fully_applied := ff}]
protected def ulift {α : Type v} : ulift.{u} α ≃ α :=
⟨ulift.down, ulift.up, ulift.up_down, λ a, rfl⟩
/-- `plift α` is equivalent to `α`. -/
@[simps apply symm_apply {fully_applied := ff}]
protected def plift : plift α ≃ α :=
⟨plift.down, plift.up, plift.up_down, plift.down_up⟩
/-- `pprod α β` is equivalent to `α × β` -/
@[simps apply symm_apply]
def pprod_equiv_prod {α β : Type*} : pprod α β ≃ α × β :=
{ to_fun := λ x, (x.1, x.2),
inv_fun := λ x, ⟨x.1, x.2⟩,
left_inv := λ ⟨x, y⟩, rfl,
right_inv := λ ⟨x, y⟩, rfl }
/-- equivalence of propositions is the same as iff -/
def of_iff {P Q : Prop} (h : P ↔ Q) : P ≃ Q :=
{ to_fun := h.mp,
inv_fun := h.mpr,
left_inv := λ x, rfl,
right_inv := λ y, rfl }
/-- If `α₁` is equivalent to `α₂` and `β₁` is equivalent to `β₂`, then the type of maps `α₁ → β₁`
is equivalent to the type of maps `α₂ → β₂`. -/
@[congr, simps apply] def arrow_congr {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) :
(α₁ → β₁) ≃ (α₂ → β₂) :=
{ to_fun := λ f, e₂ ∘ f ∘ e₁.symm,
inv_fun := λ f, e₂.symm ∘ f ∘ e₁,
left_inv := λ f, funext $ λ x, by simp,
right_inv := λ f, funext $ λ x, by simp }
lemma arrow_congr_comp {α₁ β₁ γ₁ α₂ β₂ γ₂ : Sort*}
(ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) (ec : γ₁ ≃ γ₂) (f : α₁ → β₁) (g : β₁ → γ₁) :
arrow_congr ea ec (g ∘ f) = (arrow_congr eb ec g) ∘ (arrow_congr ea eb f) :=
by { ext, simp only [comp, arrow_congr_apply, eb.symm_apply_apply] }
@[simp] lemma arrow_congr_refl {α β : Sort*} :
arrow_congr (equiv.refl α) (equiv.refl β) = equiv.refl (α → β) := rfl
@[simp] lemma arrow_congr_trans {α₁ β₁ α₂ β₂ α₃ β₃ : Sort*}
(e₁ : α₁ ≃ α₂) (e₁' : β₁ ≃ β₂) (e₂ : α₂ ≃ α₃) (e₂' : β₂ ≃ β₃) :
arrow_congr (e₁.trans e₂) (e₁'.trans e₂') = (arrow_congr e₁ e₁').trans (arrow_congr e₂ e₂') :=
rfl
@[simp] lemma arrow_congr_symm {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) :
(arrow_congr e₁ e₂).symm = arrow_congr e₁.symm e₂.symm :=
rfl
/--
A version of `equiv.arrow_congr` in `Type`, rather than `Sort`.
The `equiv_rw` tactic is not able to use the default `Sort` level `equiv.arrow_congr`,
because Lean's universe rules will not unify `?l_1` with `imax (1 ?m_1)`.
-/
@[congr, simps apply]
def arrow_congr' {α₁ β₁ α₂ β₂ : Type*} (hα : α₁ ≃ α₂) (hβ : β₁ ≃ β₂) : (α₁ → β₁) ≃ (α₂ → β₂) :=
equiv.arrow_congr hα hβ
@[simp] lemma arrow_congr'_refl {α β : Type*} :
arrow_congr' (equiv.refl α) (equiv.refl β) = equiv.refl (α → β) := rfl
@[simp] lemma arrow_congr'_trans {α₁ β₁ α₂ β₂ α₃ β₃ : Type*}
(e₁ : α₁ ≃ α₂) (e₁' : β₁ ≃ β₂) (e₂ : α₂ ≃ α₃) (e₂' : β₂ ≃ β₃) :
arrow_congr' (e₁.trans e₂) (e₁'.trans e₂') = (arrow_congr' e₁ e₁').trans (arrow_congr' e₂ e₂') :=
rfl
@[simp] lemma arrow_congr'_symm {α₁ β₁ α₂ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) :
(arrow_congr' e₁ e₂).symm = arrow_congr' e₁.symm e₂.symm :=
rfl
/-- Conjugate a map `f : α → α` by an equivalence `α ≃ β`. -/
@[simps apply]
def conj (e : α ≃ β) : (α → α) ≃ (β → β) := arrow_congr e e
@[simp] lemma conj_refl : conj (equiv.refl α) = equiv.refl (α → α) := rfl
@[simp] lemma conj_symm (e : α ≃ β) : e.conj.symm = e.symm.conj := rfl
@[simp] lemma conj_trans (e₁ : α ≃ β) (e₂ : β ≃ γ) :
(e₁.trans e₂).conj = e₁.conj.trans e₂.conj :=
rfl
-- This should not be a simp lemma as long as `(∘)` is reducible:
-- when `(∘)` is reducible, Lean can unify `f₁ ∘ f₂` with any `g` using
-- `f₁ := g` and `f₂ := λ x, x`. This causes nontermination.
lemma conj_comp (e : α ≃ β) (f₁ f₂ : α → α) :
e.conj (f₁ ∘ f₂) = (e.conj f₁) ∘ (e.conj f₂) :=
by apply arrow_congr_comp
section binary_op
variables {α₁ β₁ : Type*} (e : α₁ ≃ β₁) (f : α₁ → α₁ → α₁)
lemma semiconj_conj (f : α₁ → α₁) : semiconj e f (e.conj f) := λ x, by simp
lemma semiconj₂_conj : semiconj₂ e f (e.arrow_congr e.conj f) := λ x y, by simp
instance [is_associative α₁ f] :
is_associative β₁ (e.arrow_congr (e.arrow_congr e) f) :=
(e.semiconj₂_conj f).is_associative_right e.surjective
instance [is_idempotent α₁ f] :
is_idempotent β₁ (e.arrow_congr (e.arrow_congr e) f) :=
(e.semiconj₂_conj f).is_idempotent_right e.surjective
instance [is_left_cancel α₁ f] :
is_left_cancel β₁ (e.arrow_congr (e.arrow_congr e) f) :=
⟨e.surjective.forall₃.2 $ λ x y z, by simpa using @is_left_cancel.left_cancel _ f _ x y z⟩
instance [is_right_cancel α₁ f] :
is_right_cancel β₁ (e.arrow_congr (e.arrow_congr e) f) :=
⟨e.surjective.forall₃.2 $ λ x y z, by simpa using @is_right_cancel.right_cancel _ f _ x y z⟩
end binary_op
/-- `punit` sorts in any two universes are equivalent. -/
def punit_equiv_punit : punit.{v} ≃ punit.{w} :=
⟨λ _, punit.star, λ _, punit.star, λ u, by { cases u, refl }, λ u, by { cases u, reflexivity }⟩
section
/-- The sort of maps to `punit.{v}` is equivalent to `punit.{w}`. -/
def arrow_punit_equiv_punit (α : Sort*) : (α → punit.{v}) ≃ punit.{w} :=
⟨λ f, punit.star, λ u f, punit.star,
λ f, by { funext x, cases f x, refl }, λ u, by { cases u, reflexivity }⟩
/-- If `α` has a unique term, then the type of function `α → β` is equivalent to `β`. -/
@[simps { fully_applied := ff }] def fun_unique (α β) [unique α] : (α → β) ≃ β :=
{ to_fun := eval (default α),
inv_fun := const α,
left_inv := λ f, funext $ λ a, congr_arg f $ subsingleton.elim _ _,
right_inv := λ b, rfl }
/-- The sort of maps from `punit` is equivalent to the codomain. -/
def punit_arrow_equiv (α : Sort*) : (punit.{u} → α) ≃ α :=
fun_unique _ _
/-- The sort of maps from `true` is equivalent to the codomain. -/
def true_arrow_equiv (α : Sort*) : (true → α) ≃ α :=
fun_unique _ _
/-- The sort of maps from a type that `is_empty` is equivalent to `punit`. -/
def arrow_punit_of_is_empty (α β : Sort*) [is_empty α] : (α → β) ≃ punit.{u} :=
⟨λ f, punit.star, λ u, is_empty_elim, λ f, funext is_empty_elim, λ u, by { cases u, refl }⟩
/-- The sort of maps from `empty` is equivalent to `punit`. -/
def empty_arrow_equiv_punit (α : Sort*) : (empty → α) ≃ punit.{u} :=
arrow_punit_of_is_empty _ _
/-- The sort of maps from `pempty` is equivalent to `punit`. -/
def pempty_arrow_equiv_punit (α : Sort*) : (pempty → α) ≃ punit.{u} :=
arrow_punit_of_is_empty _ _
/-- The sort of maps from `false` is equivalent to `punit`. -/
def false_arrow_equiv_punit (α : Sort*) : (false → α) ≃ punit.{u} :=
arrow_punit_of_is_empty _ _
end
/-- Product of two equivalences. If `α₁ ≃ α₂` and `β₁ ≃ β₂`, then `α₁ × β₁ ≃ α₂ × β₂`. -/
@[congr, simps apply]
def prod_congr {α₁ β₁ α₂ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : α₁ × β₁ ≃ α₂ × β₂ :=
⟨prod.map e₁ e₂, prod.map e₁.symm e₂.symm, λ ⟨a, b⟩, by simp, λ ⟨a, b⟩, by simp⟩
@[simp] theorem prod_congr_symm {α₁ β₁ α₂ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) :
(prod_congr e₁ e₂).symm = prod_congr e₁.symm e₂.symm :=
rfl
/-- Type product is commutative up to an equivalence: `α × β ≃ β × α`. -/
@[simps apply] def prod_comm (α β : Type*) : α × β ≃ β × α :=
⟨prod.swap, prod.swap, λ⟨a, b⟩, rfl, λ⟨a, b⟩, rfl⟩
@[simp] lemma prod_comm_symm (α β) : (prod_comm α β).symm = prod_comm β α := rfl
/-- Type product is associative up to an equivalence. -/
@[simps] def prod_assoc (α β γ : Sort*) : (α × β) × γ ≃ α × (β × γ) :=
⟨λ p, (p.1.1, p.1.2, p.2), λp, ((p.1, p.2.1), p.2.2), λ ⟨⟨a, b⟩, c⟩, rfl, λ ⟨a, ⟨b, c⟩⟩, rfl⟩
/-- Functions on `α × β` are equivalent to functions `α → β → γ`. -/
@[simps {fully_applied := ff}] def curry (α β γ : Type*) :
(α × β → γ) ≃ (α → β → γ) :=
{ to_fun := curry,
inv_fun := uncurry,
left_inv := uncurry_curry,
right_inv := curry_uncurry }
section
/-- `punit` is a right identity for type product up to an equivalence. -/
@[simps] def prod_punit (α : Type*) : α × punit.{u+1} ≃ α :=
⟨λ p, p.1, λ a, (a, punit.star), λ ⟨_, punit.star⟩, rfl, λ a, rfl⟩
/-- `punit` is a left identity for type product up to an equivalence. -/
@[simps] def punit_prod (α : Type*) : punit.{u+1} × α ≃ α :=
calc punit × α ≃ α × punit : prod_comm _ _
... ≃ α : prod_punit _
/-- `empty` type is a right absorbing element for type product up to an equivalence. -/
def prod_empty (α : Type*) : α × empty ≃ empty :=
equiv_empty _
/-- `empty` type is a left absorbing element for type product up to an equivalence. -/
def empty_prod (α : Type*) : empty × α ≃ empty :=
equiv_empty _
/-- `pempty` type is a right absorbing element for type product up to an equivalence. -/
def prod_pempty (α : Type*) : α × pempty ≃ pempty :=
equiv_pempty _
/-- `pempty` type is a left absorbing element for type product up to an equivalence. -/
def pempty_prod (α : Type*) : pempty × α ≃ pempty :=
equiv_pempty _
end
section
open sum
/-- `psum` is equivalent to `sum`. -/
def psum_equiv_sum (α β : Type*) : psum α β ≃ α ⊕ β :=
⟨λ s, psum.cases_on s inl inr,
λ s, sum.cases_on s psum.inl psum.inr,
λ s, by cases s; refl,
λ s, by cases s; refl⟩
/-- If `α ≃ α'` and `β ≃ β'`, then `α ⊕ β ≃ α' ⊕ β'`. -/
@[simps apply]
def sum_congr {α₁ β₁ α₂ β₂ : Type*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : α₁ ⊕ β₁ ≃ α₂ ⊕ β₂ :=
⟨sum.map ea eb, sum.map ea.symm eb.symm, λ x, by simp, λ x, by simp⟩
@[simp] lemma sum_congr_trans {α₁ α₂ β₁ β₂ γ₁ γ₂ : Sort*}
(e : α₁ ≃ β₁) (f : α₂ ≃ β₂) (g : β₁ ≃ γ₁) (h : β₂ ≃ γ₂) :
(equiv.sum_congr e f).trans (equiv.sum_congr g h) = (equiv.sum_congr (e.trans g) (f.trans h)) :=
by { ext i, cases i; refl }
@[simp] lemma sum_congr_symm {α β γ δ : Sort*} (e : α ≃ β) (f : γ ≃ δ) :
(equiv.sum_congr e f).symm = (equiv.sum_congr (e.symm) (f.symm)) :=
rfl
@[simp] lemma sum_congr_refl {α β : Sort*} :
equiv.sum_congr (equiv.refl α) (equiv.refl β) = equiv.refl (α ⊕ β) :=
by { ext i, cases i; refl }
namespace perm
/-- Combine a permutation of `α` and of `β` into a permutation of `α ⊕ β`. -/
@[reducible]
def sum_congr {α β : Type*} (ea : equiv.perm α) (eb : equiv.perm β) : equiv.perm (α ⊕ β) :=
equiv.sum_congr ea eb
@[simp] lemma sum_congr_apply {α β : Type*} (ea : equiv.perm α) (eb : equiv.perm β) (x : α ⊕ β) :
sum_congr ea eb x = sum.map ⇑ea ⇑eb x := equiv.sum_congr_apply ea eb x
@[simp] lemma sum_congr_trans {α β : Sort*}
(e : equiv.perm α) (f : equiv.perm β) (g : equiv.perm α) (h : equiv.perm β) :
(sum_congr e f).trans (sum_congr g h) = sum_congr (e.trans g) (f.trans h) :=
equiv.sum_congr_trans e f g h
@[simp] lemma sum_congr_symm {α β : Sort*} (e : equiv.perm α) (f : equiv.perm β) :
(sum_congr e f).symm = sum_congr (e.symm) (f.symm) :=
equiv.sum_congr_symm e f
@[simp] lemma sum_congr_refl {α β : Sort*} :
sum_congr (equiv.refl α) (equiv.refl β) = equiv.refl (α ⊕ β) :=
equiv.sum_congr_refl
end perm
/-- `bool` is equivalent the sum of two `punit`s. -/
def bool_equiv_punit_sum_punit : bool ≃ punit.{u+1} ⊕ punit.{v+1} :=
⟨λ b, cond b (inr punit.star) (inl punit.star),
λ s, sum.rec_on s (λ_, ff) (λ_, tt),
λ b, by cases b; refl,
λ s, by rcases s with ⟨⟨⟩⟩ | ⟨⟨⟩⟩; refl⟩
/-- `Prop` is noncomputably equivalent to `bool`. -/
noncomputable def Prop_equiv_bool : Prop ≃ bool :=
⟨λ p, @to_bool p (classical.prop_decidable _),
λ b, b, λ p, by simp, λ b, by simp⟩
/-- Sum of types is commutative up to an equivalence. -/
@[simps apply]
def sum_comm (α β : Sort*) : α ⊕ β ≃ β ⊕ α :=
⟨sum.swap, sum.swap, sum.swap_swap, sum.swap_swap⟩
@[simp] lemma sum_comm_symm (α β) : (sum_comm α β).symm = sum_comm β α := rfl
/-- Sum of types is associative up to an equivalence. -/
def sum_assoc (α β γ : Sort*) : (α ⊕ β) ⊕ γ ≃ α ⊕ (β ⊕ γ) :=
⟨sum.elim (sum.elim sum.inl (sum.inr ∘ sum.inl)) (sum.inr ∘ sum.inr),
sum.elim (sum.inl ∘ sum.inl) $ sum.elim (sum.inl ∘ sum.inr) sum.inr,
by rintros (⟨_ | _⟩ | _); refl,
by rintros (_ | ⟨_ | _⟩); refl⟩
@[simp] theorem sum_assoc_apply_in1 {α β γ} (a) : sum_assoc α β γ (inl (inl a)) = inl a := rfl
@[simp] theorem sum_assoc_apply_in2 {α β γ} (b) : sum_assoc α β γ (inl (inr b)) = inr (inl b) := rfl
@[simp] theorem sum_assoc_apply_in3 {α β γ} (c) : sum_assoc α β γ (inr c) = inr (inr c) := rfl
/-- Sum with `empty` is equivalent to the original type. -/
@[simps symm_apply] def sum_empty (α β : Type*) [is_empty β] : α ⊕ β ≃ α :=
⟨sum.elim id is_empty_elim,
inl,
λ s, by { rcases s with _ | x, refl, exact is_empty_elim x },
λ a, rfl⟩
@[simp] lemma sum_empty_apply_inl {α β : Type*} [is_empty β] (a : α) :
sum_empty α β (sum.inl a) = a := rfl
/-- The sum of `empty` with any `Sort*` is equivalent to the right summand. -/
@[simps symm_apply] def empty_sum (α β : Type*) [is_empty α] : α ⊕ β ≃ β :=
(sum_comm _ _).trans $ sum_empty _ _
@[simp] lemma empty_sum_apply_inr {α β : Type*} [is_empty α] (b : β) :
empty_sum α β (sum.inr b) = b := rfl
/-- `option α` is equivalent to `α ⊕ punit` -/
def option_equiv_sum_punit (α : Type*) : option α ≃ α ⊕ punit.{u+1} :=
⟨λ o, match o with none := inr punit.star | some a := inl a end,
λ s, match s with inr _ := none | inl a := some a end,
λ o, by cases o; refl,
λ s, by rcases s with _ | ⟨⟨⟩⟩; refl⟩
@[simp] lemma option_equiv_sum_punit_none {α} :
option_equiv_sum_punit α none = sum.inr punit.star := rfl
@[simp] lemma option_equiv_sum_punit_some {α} (a) :
option_equiv_sum_punit α (some a) = sum.inl a := rfl
@[simp] lemma option_equiv_sum_punit_coe {α} (a : α) :
option_equiv_sum_punit α a = sum.inl a := rfl
@[simp] lemma option_equiv_sum_punit_symm_inl {α} (a) :
(option_equiv_sum_punit α).symm (sum.inl a) = a :=
rfl
@[simp] lemma option_equiv_sum_punit_symm_inr {α} (a) :
(option_equiv_sum_punit α).symm (sum.inr a) = none :=
rfl
/-- The set of `x : option α` such that `is_some x` is equivalent to `α`. -/
@[simps] def option_is_some_equiv (α : Type*) : {x : option α // x.is_some} ≃ α :=
{ to_fun := λ o, option.get o.2,
inv_fun := λ x, ⟨some x, dec_trivial⟩,
left_inv := λ o, subtype.eq $ option.some_get _,
right_inv := λ x, option.get_some _ _ }
/-- The product over `option α` of `β a` is the binary product of the
product over `α` of `β (some α)` and `β none` -/
@[simps] def pi_option_equiv_prod {α : Type*} {β : option α → Type*} :
(Π a : option α, β a) ≃ (β none × Π a : α, β (some a)) :=
{ to_fun := λ f, (f none, λ a, f (some a)),
inv_fun := λ x a, option.cases_on a x.fst x.snd,
left_inv := λ f, funext $ λ a, by cases a; refl,
right_inv := λ x, by simp }
/-- `α ⊕ β` is equivalent to a `sigma`-type over `bool`. Note that this definition assumes `α` and
`β` to be types from the same universe, so it cannot by used directly to transfer theorems about
sigma types to theorems about sum types. In many cases one can use `ulift` to work around this
difficulty. -/
def sum_equiv_sigma_bool (α β : Type u) : α ⊕ β ≃ (Σ b: bool, cond b α β) :=
⟨λ s, s.elim (λ x, ⟨tt, x⟩) (λ x, ⟨ff, x⟩),
λ s, match s with ⟨tt, a⟩ := inl a | ⟨ff, b⟩ := inr b end,
λ s, by cases s; refl,
λ s, by rcases s with ⟨_|_, _⟩; refl⟩
/-- `sigma_preimage_equiv f` for `f : α → β` is the natural equivalence between
the type of all fibres of `f` and the total space `α`. -/
@[simps]
def sigma_preimage_equiv {α β : Type*} (f : α → β) :
(Σ y : β, {x // f x = y}) ≃ α :=
⟨λ x, ↑x.2, λ x, ⟨f x, x, rfl⟩, λ ⟨y, x, rfl⟩, rfl, λ x, rfl⟩
end
section sum_compl
/-- For any predicate `p` on `α`,
the sum of the two subtypes `{a // p a}` and its complement `{a // ¬ p a}`
is naturally equivalent to `α`.
See `subtype_or_equiv` for sum types over subtypes `{x // p x}` and `{x // q x}`
that are not necessarily `is_compl p q`. -/
def sum_compl {α : Type*} (p : α → Prop) [decidable_pred p] :
{a // p a} ⊕ {a // ¬ p a} ≃ α :=
{ to_fun := sum.elim coe coe,
inv_fun := λ a, if h : p a then sum.inl ⟨a, h⟩ else sum.inr ⟨a, h⟩,
left_inv := by { rintros (⟨x,hx⟩|⟨x,hx⟩); dsimp; [rw dif_pos, rw dif_neg], },
right_inv := λ a, by { dsimp, split_ifs; refl } }
@[simp] lemma sum_compl_apply_inl {α : Type*} (p : α → Prop) [decidable_pred p]
(x : {a // p a}) :
sum_compl p (sum.inl x) = x := rfl
@[simp] lemma sum_compl_apply_inr {α : Type*} (p : α → Prop) [decidable_pred p]
(x : {a // ¬ p a}) :
sum_compl p (sum.inr x) = x := rfl
@[simp] lemma sum_compl_apply_symm_of_pos {α : Type*} (p : α → Prop) [decidable_pred p]
(a : α) (h : p a) :
(sum_compl p).symm a = sum.inl ⟨a, h⟩ := dif_pos h
@[simp] lemma sum_compl_apply_symm_of_neg {α : Type*} (p : α → Prop) [decidable_pred p]
(a : α) (h : ¬ p a) :
(sum_compl p).symm a = sum.inr ⟨a, h⟩ := dif_neg h
/-- Combines an `equiv` between two subtypes with an `equiv` between their complements to form a
permutation. -/
def subtype_congr {α : Type*} {p q : α → Prop} [decidable_pred p] [decidable_pred q]
(e : {x // p x} ≃ {x // q x}) (f : {x // ¬p x} ≃ {x // ¬q x}) : perm α :=
(sum_compl p).symm.trans ((sum_congr e f).trans
(sum_compl q))
open equiv
variables {ε : Type*} {p : ε → Prop} [decidable_pred p]
variables (ep ep' : perm {a // p a}) (en en' : perm {a // ¬ p a})
/-- Combining permutations on `ε` that permute only inside or outside the subtype
split induced by `p : ε → Prop` constructs a permutation on `ε`. -/
def perm.subtype_congr : equiv.perm ε :=
perm_congr (sum_compl p) (sum_congr ep en)
lemma perm.subtype_congr.apply (a : ε) :
ep.subtype_congr en a = if h : p a then ep ⟨a, h⟩ else en ⟨a, h⟩ :=
by { by_cases h : p a; simp [perm.subtype_congr, h] }
@[simp] lemma perm.subtype_congr.left_apply {a : ε} (h : p a) :
ep.subtype_congr en a = ep ⟨a, h⟩ :=
by simp [perm.subtype_congr.apply, h]
@[simp] lemma perm.subtype_congr.left_apply_subtype (a : {a // p a}) :
ep.subtype_congr en a = ep a :=
by { convert perm.subtype_congr.left_apply _ _ a.property, simp }
@[simp] lemma perm.subtype_congr.right_apply {a : ε} (h : ¬ p a) :
ep.subtype_congr en a = en ⟨a, h⟩ :=
by simp [perm.subtype_congr.apply, h]
@[simp] lemma perm.subtype_congr.right_apply_subtype (a : {a // ¬ p a}) :
ep.subtype_congr en a = en a :=
by { convert perm.subtype_congr.right_apply _ _ a.property, simp }
@[simp] lemma perm.subtype_congr.refl :
perm.subtype_congr (equiv.refl {a // p a}) (equiv.refl {a // ¬ p a}) = equiv.refl ε :=
by { ext x, by_cases h : p x; simp [h] }
@[simp] lemma perm.subtype_congr.symm :
(ep.subtype_congr en).symm = perm.subtype_congr ep.symm en.symm :=
begin
ext x,
by_cases h : p x,
{ have : p (ep.symm ⟨x, h⟩) := subtype.property _,
simp [perm.subtype_congr.apply, h, symm_apply_eq, this] },
{ have : ¬ p (en.symm ⟨x, h⟩) := subtype.property (en.symm _),
simp [perm.subtype_congr.apply, h, symm_apply_eq, this] }
end
@[simp] lemma perm.subtype_congr.trans :
(ep.subtype_congr en).trans (ep'.subtype_congr en') =
perm.subtype_congr (ep.trans ep') (en.trans en') :=
begin
ext x,
by_cases h : p x,
{ have : p (ep ⟨x, h⟩) := subtype.property _,
simp [perm.subtype_congr.apply, h, this] },
{ have : ¬ p (en ⟨x, h⟩) := subtype.property (en _),
simp [perm.subtype_congr.apply, h, symm_apply_eq, this] }
end
end sum_compl
section subtype_preimage
variables (p : α → Prop) [decidable_pred p] (x₀ : {a // p a} → β)
/-- For a fixed function `x₀ : {a // p a} → β` defined on a subtype of `α`,
the subtype of functions `x : α → β` that agree with `x₀` on the subtype `{a // p a}`
is naturally equivalent to the type of functions `{a // ¬ p a} → β`. -/
@[simps]
def subtype_preimage :
{x : α → β // x ∘ coe = x₀} ≃ ({a // ¬ p a} → β) :=
{ to_fun := λ (x : {x : α → β // x ∘ coe = x₀}) a, (x : α → β) a,
inv_fun := λ x, ⟨λ a, if h : p a then x₀ ⟨a, h⟩ else x ⟨a, h⟩,
funext $ λ ⟨a, h⟩, dif_pos h⟩,
left_inv := λ ⟨x, hx⟩, subtype.val_injective $ funext $ λ a,
(by { dsimp, split_ifs; [ rw ← hx, skip ]; refl }),
right_inv := λ x, funext $ λ ⟨a, h⟩,
show dite (p a) _ _ = _, by { dsimp, rw [dif_neg h] } }
lemma subtype_preimage_symm_apply_coe_pos (x : {a // ¬ p a} → β) (a : α) (h : p a) :
((subtype_preimage p x₀).symm x : α → β) a = x₀ ⟨a, h⟩ :=
dif_pos h
lemma subtype_preimage_symm_apply_coe_neg (x : {a // ¬ p a} → β) (a : α) (h : ¬ p a) :
((subtype_preimage p x₀).symm x : α → β) a = x ⟨a, h⟩ :=
dif_neg h
end subtype_preimage
section
/-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Π a, β₁ a` and
`Π a, β₂ a`. -/
def Pi_congr_right {α} {β₁ β₂ : α → Sort*} (F : Π a, β₁ a ≃ β₂ a) : (Π a, β₁ a) ≃ (Π a, β₂ a) :=
⟨λ H a, F a (H a), λ H a, (F a).symm (H a),
λ H, funext $ by simp, λ H, funext $ by simp⟩
/-- Dependent `curry` equivalence: the type of dependent functions on `Σ i, β i` is equivalent
to the type of dependent functions of two arguments (i.e., functions to the space of functions).
This is `sigma.curry` and `sigma.uncurry` together as an equiv. -/
def Pi_curry {α} {β : α → Sort*} (γ : Π a, β a → Sort*) :
(Π x : Σ i, β i, γ x.1 x.2) ≃ (Π a b, γ a b) :=
{ to_fun := sigma.curry,
inv_fun := sigma.uncurry,
left_inv := sigma.uncurry_curry,
right_inv := sigma.curry_uncurry }
end
section
/-- A `psigma`-type is equivalent to the corresponding `sigma`-type. -/
@[simps apply symm_apply] def psigma_equiv_sigma {α} (β : α → Type*) : (Σ' i, β i) ≃ Σ i, β i :=
⟨λ a, ⟨a.1, a.2⟩, λ a, ⟨a.1, a.2⟩, λ ⟨a, b⟩, rfl, λ ⟨a, b⟩, rfl⟩
/-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Σ' a, β₁ a` and
`Σ' a, β₂ a`. -/
@[simps apply]
def psigma_congr_right {α} {β₁ β₂ : α → Sort*} (F : Π a, β₁ a ≃ β₂ a) : (Σ' a, β₁ a) ≃ Σ' a, β₂ a :=
⟨λ a, ⟨a.1, F a.1 a.2⟩, λ a, ⟨a.1, (F a.1).symm a.2⟩,
λ ⟨a, b⟩, congr_arg (psigma.mk a) $ symm_apply_apply (F a) b,
λ ⟨a, b⟩, congr_arg (psigma.mk a) $ apply_symm_apply (F a) b⟩
@[simp] lemma psigma_congr_right_trans {α} {β₁ β₂ β₃ : α → Sort*}
(F : Π a, β₁ a ≃ β₂ a) (G : Π a, β₂ a ≃ β₃ a) :
(psigma_congr_right F).trans (psigma_congr_right G) =
psigma_congr_right (λ a, (F a).trans (G a)) :=
by { ext1 x, cases x, refl }
@[simp] lemma psigma_congr_right_symm {α} {β₁ β₂ : α → Sort*} (F : Π a, β₁ a ≃ β₂ a) :
(psigma_congr_right F).symm = psigma_congr_right (λ a, (F a).symm) :=
by { ext1 x, cases x, refl }
@[simp] lemma psigma_congr_right_refl {α} {β : α → Sort*} :
(psigma_congr_right (λ a, equiv.refl (β a))) = equiv.refl (Σ' a, β a) :=
by { ext1 x, cases x, refl }
/-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Σ a, β₁ a` and
`Σ a, β₂ a`. -/
@[simps apply]
def sigma_congr_right {α} {β₁ β₂ : α → Type*} (F : Π a, β₁ a ≃ β₂ a) : (Σ a, β₁ a) ≃ Σ a, β₂ a :=
⟨λ a, ⟨a.1, F a.1 a.2⟩, λ a, ⟨a.1, (F a.1).symm a.2⟩,
λ ⟨a, b⟩, congr_arg (sigma.mk a) $ symm_apply_apply (F a) b,
λ ⟨a, b⟩, congr_arg (sigma.mk a) $ apply_symm_apply (F a) b⟩
@[simp] lemma sigma_congr_right_trans {α} {β₁ β₂ β₃ : α → Type*}
(F : Π a, β₁ a ≃ β₂ a) (G : Π a, β₂ a ≃ β₃ a) :
(sigma_congr_right F).trans (sigma_congr_right G) = sigma_congr_right (λ a, (F a).trans (G a)) :=
by { ext1 x, cases x, refl }
@[simp] lemma sigma_congr_right_symm {α} {β₁ β₂ : α → Type*} (F : Π a, β₁ a ≃ β₂ a) :
(sigma_congr_right F).symm = sigma_congr_right (λ a, (F a).symm) :=
by { ext1 x, cases x, refl }
@[simp] lemma sigma_congr_right_refl {α} {β : α → Type*} :
(sigma_congr_right (λ a, equiv.refl (β a))) = equiv.refl (Σ a, β a) :=
by { ext1 x, cases x, refl }
/-- A `psigma` with `Prop` fibers is equivalent to the subtype. -/
def psigma_equiv_subtype {α : Type v} (P : α → Prop) :
(Σ' i, P i) ≃ subtype P :=
{ to_fun := λ x, ⟨x.1, x.2⟩,
inv_fun := λ x, ⟨x.1, x.2⟩,
left_inv := λ x, by { cases x, refl, },
right_inv := λ x, by { cases x, refl, }, }
/-- A `sigma` with `plift` fibers is equivalent to the subtype. -/
def sigma_plift_equiv_subtype {α : Type v} (P : α → Prop) :
(Σ i, plift (P i)) ≃ subtype P :=
((psigma_equiv_sigma _).symm.trans (psigma_congr_right (λ a, equiv.plift))).trans
(psigma_equiv_subtype P)
/--
A `sigma` with `λ i, ulift (plift (P i))` fibers is equivalent to `{ x // P x }`.
Variant of `sigma_plift_equiv_subtype`.
-/
def sigma_ulift_plift_equiv_subtype {α : Type v} (P : α → Prop) :
(Σ i, ulift (plift (P i))) ≃ subtype P :=
(sigma_congr_right (λ a, equiv.ulift)).trans (sigma_plift_equiv_subtype P)
namespace perm
/-- A family of permutations `Π a, perm (β a)` generates a permuation `perm (Σ a, β₁ a)`. -/
@[reducible]
def sigma_congr_right {α} {β : α → Sort*} (F : Π a, perm (β a)) : perm (Σ a, β a) :=
equiv.sigma_congr_right F
@[simp] lemma sigma_congr_right_trans {α} {β : α → Sort*}
(F : Π a, perm (β a)) (G : Π a, perm (β a)) :
(sigma_congr_right F).trans (sigma_congr_right G) = sigma_congr_right (λ a, (F a).trans (G a)) :=
equiv.sigma_congr_right_trans F G
@[simp] lemma sigma_congr_right_symm {α} {β : α → Sort*} (F : Π a, perm (β a)) :
(sigma_congr_right F).symm = sigma_congr_right (λ a, (F a).symm) :=
equiv.sigma_congr_right_symm F
@[simp] lemma sigma_congr_right_refl {α} {β : α → Sort*} :
(sigma_congr_right (λ a, equiv.refl (β a))) = equiv.refl (Σ a, β a) :=
equiv.sigma_congr_right_refl
end perm
/-- An equivalence `f : α₁ ≃ α₂` generates an equivalence between `Σ a, β (f a)` and `Σ a, β a`. -/
@[simps apply]
def sigma_congr_left {α₁ α₂} {β : α₂ → Sort*} (e : α₁ ≃ α₂) : (Σ a:α₁, β (e a)) ≃ (Σ a:α₂, β a) :=
⟨λ a, ⟨e a.1, a.2⟩, λ a, ⟨e.symm a.1, @@eq.rec β a.2 (e.right_inv a.1).symm⟩,
λ ⟨a, b⟩, match e.symm (e a), e.left_inv a : ∀ a' (h : a' = a),
@sigma.mk _ (β ∘ e) _ (@@eq.rec β b (congr_arg e h.symm)) = ⟨a, b⟩ with
| _, rfl := rfl end,
λ ⟨a, b⟩, match e (e.symm a), _ : ∀ a' (h : a' = a),
sigma.mk a' (@@eq.rec β b h.symm) = ⟨a, b⟩ with
| _, rfl := rfl end⟩
/-- Transporting a sigma type through an equivalence of the base -/
def sigma_congr_left' {α₁ α₂} {β : α₁ → Sort*} (f : α₁ ≃ α₂) :
(Σ a:α₁, β a) ≃ (Σ a:α₂, β (f.symm a)) :=
(sigma_congr_left f.symm).symm
/-- Transporting a sigma type through an equivalence of the base and a family of equivalences
of matching fibers -/
def sigma_congr {α₁ α₂} {β₁ : α₁ → Sort*} {β₂ : α₂ → Sort*} (f : α₁ ≃ α₂)
(F : ∀ a, β₁ a ≃ β₂ (f a)) :
sigma β₁ ≃ sigma β₂ :=
(sigma_congr_right F).trans (sigma_congr_left f)
/-- `sigma` type with a constant fiber is equivalent to the product. -/
@[simps apply symm_apply] def sigma_equiv_prod (α β : Type*) : (Σ_:α, β) ≃ α × β :=
⟨λ a, ⟨a.1, a.2⟩, λ a, ⟨a.1, a.2⟩, λ ⟨a, b⟩, rfl, λ ⟨a, b⟩, rfl⟩
/-- If each fiber of a `sigma` type is equivalent to a fixed type, then the sigma type
is equivalent to the product. -/
def sigma_equiv_prod_of_equiv {α β} {β₁ : α → Sort*} (F : Π a, β₁ a ≃ β) : sigma β₁ ≃ α × β :=
(sigma_congr_right F).trans (sigma_equiv_prod α β)
/-- Dependent product of types is associative up to an equivalence. -/
def sigma_assoc {α : Type*} {β : α → Type*} (γ : Π (a : α), β a → Type*) :
(Σ (ab : Σ (a : α), β a), γ ab.1 ab.2) ≃ Σ (a : α), (Σ (b : β a), γ a b) :=
{ to_fun := λ x, ⟨x.1.1, ⟨x.1.2, x.2⟩⟩,
inv_fun := λ x, ⟨⟨x.1, x.2.1⟩, x.2.2⟩,
left_inv := λ ⟨⟨a, b⟩, c⟩, rfl,
right_inv := λ ⟨a, ⟨b, c⟩⟩, rfl }
end
section prod_congr
variables {α₁ β₁ β₂ : Type*} (e : α₁ → β₁ ≃ β₂)
/-- A family of equivalences `Π (a : α₁), β₁ ≃ β₂` generates an equivalence
between `β₁ × α₁` and `β₂ × α₁`. -/
def prod_congr_left : β₁ × α₁ ≃ β₂ × α₁ :=
{ to_fun := λ ab, ⟨e ab.2 ab.1, ab.2⟩,
inv_fun := λ ab, ⟨(e ab.2).symm ab.1, ab.2⟩,
left_inv := by { rintros ⟨a, b⟩, simp },
right_inv := by { rintros ⟨a, b⟩, simp } }
@[simp] lemma prod_congr_left_apply (b : β₁) (a : α₁) :
prod_congr_left e (b, a) = (e a b, a) := rfl
lemma prod_congr_refl_right (e : β₁ ≃ β₂) :
prod_congr e (equiv.refl α₁) = prod_congr_left (λ _, e) :=
by { ext ⟨a, b⟩ : 1, simp }
/-- A family of equivalences `Π (a : α₁), β₁ ≃ β₂` generates an equivalence
between `α₁ × β₁` and `α₁ × β₂`. -/
def prod_congr_right : α₁ × β₁ ≃ α₁ × β₂ :=
{ to_fun := λ ab, ⟨ab.1, e ab.1 ab.2⟩,
inv_fun := λ ab, ⟨ab.1, (e ab.1).symm ab.2⟩,
left_inv := by { rintros ⟨a, b⟩, simp },
right_inv := by { rintros ⟨a, b⟩, simp } }
@[simp] lemma prod_congr_right_apply (a : α₁) (b : β₁) :
prod_congr_right e (a, b) = (a, e a b) := rfl
lemma prod_congr_refl_left (e : β₁ ≃ β₂) :
prod_congr (equiv.refl α₁) e = prod_congr_right (λ _, e) :=
by { ext ⟨a, b⟩ : 1, simp }
@[simp] lemma prod_congr_left_trans_prod_comm :
(prod_congr_left e).trans (prod_comm _ _) = (prod_comm _ _).trans (prod_congr_right e) :=
by { ext ⟨a, b⟩ : 1, simp }
@[simp] lemma prod_congr_right_trans_prod_comm :
(prod_congr_right e).trans (prod_comm _ _) = (prod_comm _ _).trans (prod_congr_left e) :=
by { ext ⟨a, b⟩ : 1, simp }
lemma sigma_congr_right_sigma_equiv_prod :
(sigma_congr_right e).trans (sigma_equiv_prod α₁ β₂) =
(sigma_equiv_prod α₁ β₁).trans (prod_congr_right e) :=
by { ext ⟨a, b⟩ : 1, simp }
lemma sigma_equiv_prod_sigma_congr_right :
(sigma_equiv_prod α₁ β₁).symm.trans (sigma_congr_right e) =
(prod_congr_right e).trans (sigma_equiv_prod α₁ β₂).symm :=
by { ext ⟨a, b⟩ : 1, simp }
/-- A variation on `equiv.prod_congr` where the equivalence in the second component can depend
on the first component. A typical example is a shear mapping, explaining the name of this
declaration. -/
@[simps {fully_applied := ff}]
def prod_shear {α₁ β₁ α₂ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : α₁ → β₁ ≃ β₂) : α₁ × β₁ ≃ α₂ × β₂ :=
{ to_fun := λ x : α₁ × β₁, (e₁ x.1, e₂ x.1 x.2),
inv_fun := λ y : α₂ × β₂, (e₁.symm y.1, (e₂ $ e₁.symm y.1).symm y.2),
left_inv := by { rintro ⟨x₁, y₁⟩, simp only [symm_apply_apply] },
right_inv := by { rintro ⟨x₁, y₁⟩, simp only [apply_symm_apply] } }
end prod_congr
namespace perm
variables {α₁ β₁ β₂ : Type*} [decidable_eq α₁] (a : α₁) (e : perm β₁)
/-- `prod_extend_right a e` extends `e : perm β` to `perm (α × β)` by sending `(a, b)` to
`(a, e b)` and keeping the other `(a', b)` fixed. -/
def prod_extend_right : perm (α₁ × β₁) :=
{ to_fun := λ ab, if ab.fst = a then (a, e ab.snd) else ab,
inv_fun := λ ab, if ab.fst = a then (a, e.symm ab.snd) else ab,
left_inv := by { rintros ⟨k', x⟩, simp only, split_ifs with h; simp [h] },
right_inv := by { rintros ⟨k', x⟩, simp only, split_ifs with h; simp [h] } }
@[simp] lemma prod_extend_right_apply_eq (b : β₁) :
prod_extend_right a e (a, b) = (a, e b) := if_pos rfl
lemma prod_extend_right_apply_ne {a a' : α₁} (h : a' ≠ a) (b : β₁) :
prod_extend_right a e (a', b) = (a', b) := if_neg h
lemma eq_of_prod_extend_right_ne {e : perm β₁} {a a' : α₁} {b : β₁}
(h : prod_extend_right a e (a', b) ≠ (a', b)) : a' = a :=
by { contrapose! h, exact prod_extend_right_apply_ne _ h _ }
@[simp] lemma fst_prod_extend_right (ab : α₁ × β₁) :
(prod_extend_right a e ab).fst = ab.fst :=
begin
rw [prod_extend_right, coe_fn_mk],
split_ifs with h,
{ rw h },
{ refl }
end
end perm
section
/-- The type of functions to a product `α × β` is equivalent to the type of pairs of functions
`γ → α` and `γ → β`. -/
def arrow_prod_equiv_prod_arrow (α β γ : Type*) : (γ → α × β) ≃ (γ → α) × (γ → β) :=
⟨λ f, (λ c, (f c).1, λ c, (f c).2),
λ p c, (p.1 c, p.2 c),
λ f, funext $ λ c, prod.mk.eta,
λ p, by { cases p, refl }⟩
open sum
/-- The type of functions on a sum type `α ⊕ β` is equivalent to the type of pairs of functions
on `α` and on `β`. -/
def sum_arrow_equiv_prod_arrow (α β γ : Type*) : ((α ⊕ β) → γ) ≃ (α → γ) × (β → γ) :=
⟨λ f, (f ∘ inl, f ∘ inr),
λ p, sum.elim p.1 p.2,
λ f, by { ext ⟨⟩; refl },
λ p, by { cases p, refl }⟩
@[simp] lemma sum_arrow_equiv_prod_arrow_apply_fst {α β γ} (f : (α ⊕ β) → γ) (a : α) :
(sum_arrow_equiv_prod_arrow α β γ f).1 a = f (inl a) := rfl
@[simp] lemma sum_arrow_equiv_prod_arrow_apply_snd {α β γ} (f : (α ⊕ β) → γ) (b : β) :
(sum_arrow_equiv_prod_arrow α β γ f).2 b = f (inr b) := rfl
@[simp] lemma sum_arrow_equiv_prod_arrow_symm_apply_inl {α β γ} (f : α → γ) (g : β → γ) (a : α) :
((sum_arrow_equiv_prod_arrow α β γ).symm (f, g)) (inl a) = f a := rfl
@[simp] lemma sum_arrow_equiv_prod_arrow_symm_apply_inr {α β γ} (f : α → γ) (g : β → γ) (b : β) :
((sum_arrow_equiv_prod_arrow α β γ).symm (f, g)) (inr b) = g b := rfl
/-- Type product is right distributive with respect to type sum up to an equivalence. -/
def sum_prod_distrib (α β γ : Sort*) : (α ⊕ β) × γ ≃ (α × γ) ⊕ (β × γ) :=
⟨λ p, match p with (inl a, c) := inl (a, c) | (inr b, c) := inr (b, c) end,
λ s, match s with inl q := (inl q.1, q.2) | inr q := (inr q.1, q.2) end,
λ p, by rcases p with ⟨_ | _, _⟩; refl,
λ s, by rcases s with ⟨_, _⟩ | ⟨_, _⟩; refl⟩
@[simp] theorem sum_prod_distrib_apply_left {α β γ} (a : α) (c : γ) :
sum_prod_distrib α β γ (sum.inl a, c) = sum.inl (a, c) := rfl
@[simp] theorem sum_prod_distrib_apply_right {α β γ} (b : β) (c : γ) :
sum_prod_distrib α β γ (sum.inr b, c) = sum.inr (b, c) := rfl
/-- Type product is left distributive with respect to type sum up to an equivalence. -/
def prod_sum_distrib (α β γ : Sort*) : α × (β ⊕ γ) ≃ (α × β) ⊕ (α × γ) :=
calc α × (β ⊕ γ) ≃ (β ⊕ γ) × α : prod_comm _ _
... ≃ (β × α) ⊕ (γ × α) : sum_prod_distrib _ _ _
... ≃ (α × β) ⊕ (α × γ) : sum_congr (prod_comm _ _) (prod_comm _ _)
@[simp] theorem prod_sum_distrib_apply_left {α β γ} (a : α) (b : β) :
prod_sum_distrib α β γ (a, sum.inl b) = sum.inl (a, b) := rfl
@[simp] theorem prod_sum_distrib_apply_right {α β γ} (a : α) (c : γ) :
prod_sum_distrib α β γ (a, sum.inr c) = sum.inr (a, c) := rfl
/-- The product of an indexed sum of types (formally, a `sigma`-type `Σ i, α i`) by a type `β` is
equivalent to the sum of products `Σ i, (α i × β)`. -/
def sigma_prod_distrib {ι : Type*} (α : ι → Type*) (β : Type*) :
((Σ i, α i) × β) ≃ (Σ i, (α i × β)) :=
⟨λ p, ⟨p.1.1, (p.1.2, p.2)⟩,
λ p, (⟨p.1, p.2.1⟩, p.2.2),
λ p, by { rcases p with ⟨⟨_, _⟩, _⟩, refl },
λ p, by { rcases p with ⟨_, ⟨_, _⟩⟩, refl }⟩
/-- The product `bool × α` is equivalent to `α ⊕ α`. -/
def bool_prod_equiv_sum (α : Type u) : bool × α ≃ α ⊕ α :=
calc bool × α ≃ (unit ⊕ unit) × α : prod_congr bool_equiv_punit_sum_punit (equiv.refl _)
... ≃ (unit × α) ⊕ (unit × α) : sum_prod_distrib _ _ _
... ≃ α ⊕ α : sum_congr (punit_prod _) (punit_prod _)
/-- The function type `bool → α` is equivalent to `α × α`. -/
@[simps] def bool_arrow_equiv_prod (α : Type u) : (bool → α) ≃ α × α :=
{ to_fun := λ f, (f tt, f ff),
inv_fun := λ p b, cond b p.1 p.2,
left_inv := λ f, funext $ bool.forall_bool.2 ⟨rfl, rfl⟩,
right_inv := λ ⟨x, y⟩, rfl }
end
section
open sum nat
/-- The set of natural numbers is equivalent to `ℕ ⊕ punit`. -/
def nat_equiv_nat_sum_punit : ℕ ≃ ℕ ⊕ punit.{u+1} :=
⟨λ n, match n with zero := inr punit.star | succ a := inl a end,
λ s, match s with inl n := succ n | inr punit.star := zero end,
λ n, begin cases n, repeat { refl } end,
λ s, begin cases s with a u, { refl }, {cases u, { refl }} end⟩
/-- `ℕ ⊕ punit` is equivalent to `ℕ`. -/
def nat_sum_punit_equiv_nat : ℕ ⊕ punit.{u+1} ≃ ℕ :=
nat_equiv_nat_sum_punit.symm
/-- The type of integer numbers is equivalent to `ℕ ⊕ ℕ`. -/
def int_equiv_nat_sum_nat : ℤ ≃ ℕ ⊕ ℕ :=
by refine ⟨_, _, _, _⟩; intro z; {cases z; [left, right]; assumption} <|> {cases z; refl}
end
/-- An equivalence between `α` and `β` generates an equivalence between `list α` and `list β`. -/
def list_equiv_of_equiv {α β : Type*} (e : α ≃ β) : list α ≃ list β :=
{ to_fun := list.map e,
inv_fun := list.map e.symm,
left_inv := λ l, by rw [list.map_map, e.symm_comp_self, list.map_id],
right_inv := λ l, by rw [list.map_map, e.self_comp_symm, list.map_id] }
/-- `fin n` is equivalent to `{m // m < n}`. -/
def fin_equiv_subtype (n : ℕ) : fin n ≃ {m // m < n} :=
⟨λ x, ⟨x.1, x.2⟩, λ x, ⟨x.1, x.2⟩, λ ⟨a, b⟩, rfl,λ ⟨a, b⟩, rfl⟩
/-- If `α` is equivalent to `β`, then `unique α` is equivalent to `unique β`. -/
def unique_congr (e : α ≃ β) : unique α ≃ unique β :=
{ to_fun := λ h, @equiv.unique _ _ h e.symm,
inv_fun := λ h, @equiv.unique _ _ h e,
left_inv := λ _, subsingleton.elim _ _,
right_inv := λ _, subsingleton.elim _ _ }
/-- If `α` is equivalent to `β`, then `is_empty α` is equivalent to `is_empty β`. -/
lemma is_empty_congr (e : α ≃ β) : is_empty α ↔ is_empty β :=
⟨λ h, @function.is_empty _ _ h e.symm, λ h, @function.is_empty _ _ h e⟩
protected lemma is_empty (e : α ≃ β) [is_empty β] : is_empty α :=
e.is_empty_congr.mpr ‹_›
section
open subtype
/-- If `α` is equivalent to `β` and the predicates `p : α → Prop` and `q : β → Prop` are equivalent
at corresponding points, then `{a // p a}` is equivalent to `{b // q b}`.
For the statement where `α = β`, that is, `e : perm α`, see `perm.subtype_perm`. -/
def subtype_equiv {p : α → Prop} {q : β → Prop}
(e : α ≃ β) (h : ∀ a, p a ↔ q (e a)) : {a : α // p a} ≃ {b : β // q b} :=
⟨λ x, ⟨e x, (h _).1 x.2⟩,
λ y, ⟨e.symm y, (h _).2 (by { simp, exact y.2 })⟩,
λ ⟨x, h⟩, subtype.ext_val $ by simp,
λ ⟨y, h⟩, subtype.ext_val $ by simp⟩
@[simp] lemma subtype_equiv_refl {p : α → Prop}
(h : ∀ a, p a ↔ p (equiv.refl _ a) := λ a, iff.rfl) :
(equiv.refl α).subtype_equiv h = equiv.refl {a : α // p a} :=
by { ext, refl }
@[simp] lemma subtype_equiv_symm {p : α → Prop} {q : β → Prop} (e : α ≃ β)
(h : ∀ (a : α), p a ↔ q (e a)) :
(e.subtype_equiv h).symm = e.symm.subtype_equiv (λ a, by
{ convert (h $ e.symm a).symm,
exact (e.apply_symm_apply a).symm }) :=
rfl
@[simp] lemma subtype_equiv_trans {p : α → Prop} {q : β → Prop} {r : γ → Prop}
(e : α ≃ β) (f : β ≃ γ)
(h : ∀ (a : α), p a ↔ q (e a)) (h' : ∀ (b : β), q b ↔ r (f b)):
(e.subtype_equiv h).trans (f.subtype_equiv h') =
(e.trans f).subtype_equiv (λ a, (h a).trans (h' $ e a)) :=
rfl
@[simp] lemma subtype_equiv_apply {p : α → Prop} {q : β → Prop} (e : α ≃ β)
(h : ∀ (a : α), p a ↔ q (e a)) (x : {x // p x}) :
e.subtype_equiv h x = ⟨e x, (h _).1 x.2⟩ :=
rfl
/-- If two predicates `p` and `q` are pointwise equivalent, then `{x // p x}` is equivalent to
`{x // q x}`. -/
@[simps]
def subtype_equiv_right {p q : α → Prop} (e : ∀x, p x ↔ q x) : {x // p x} ≃ {x // q x} :=
subtype_equiv (equiv.refl _) e
/-- If `α ≃ β`, then for any predicate `p : β → Prop` the subtype `{a // p (e a)}` is equivalent
to the subtype `{b // p b}`. -/
def subtype_equiv_of_subtype {p : β → Prop} (e : α ≃ β) :
{a : α // p (e a)} ≃ {b : β // p b} :=
subtype_equiv e $ by simp
/-- If `α ≃ β`, then for any predicate `p : α → Prop` the subtype `{a // p a}` is equivalent
to the subtype `{b // p (e.symm b)}`. This version is used by `equiv_rw`. -/
def subtype_equiv_of_subtype' {p : α → Prop} (e : α ≃ β) :
{a : α // p a} ≃ {b : β // p (e.symm b)} :=
e.symm.subtype_equiv_of_subtype.symm
/-- If two predicates are equal, then the corresponding subtypes are equivalent. -/
def subtype_equiv_prop {α : Type*} {p q : α → Prop} (h : p = q) : subtype p ≃ subtype q :=
subtype_equiv (equiv.refl α) (assume a, h ▸ iff.rfl)
/-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. This
version allows the “inner” predicate to depend on `h : p a`. -/
def subtype_subtype_equiv_subtype_exists {α : Type u} (p : α → Prop) (q : subtype p → Prop) :
subtype q ≃ {a : α // ∃h:p a, q ⟨a, h⟩ } :=
⟨λ⟨⟨a, ha⟩, ha'⟩, ⟨a, ha, ha'⟩,
λ⟨a, ha⟩, ⟨⟨a, ha.cases_on $ assume h _, h⟩, by { cases ha, exact ha_h }⟩,
assume ⟨⟨a, ha⟩, h⟩, rfl, assume ⟨a, h₁, h₂⟩, rfl⟩
@[simp] lemma subtype_subtype_equiv_subtype_exists_apply {α : Type u} (p : α → Prop)
(q : subtype p → Prop) (a) : (subtype_subtype_equiv_subtype_exists p q a : α) = a :=
by { cases a, cases a_val, refl }
/-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. -/
def subtype_subtype_equiv_subtype_inter {α : Type u} (p q : α → Prop) :
{x : subtype p // q x.1} ≃ subtype (λ x, p x ∧ q x) :=
(subtype_subtype_equiv_subtype_exists p _).trans $
subtype_equiv_right $ λ x, exists_prop
@[simp] lemma subtype_subtype_equiv_subtype_inter_apply {α : Type u} (p q : α → Prop) (a) :
(subtype_subtype_equiv_subtype_inter p q a : α) = a :=
by { cases a, cases a_val, refl }
/-- If the outer subtype has more restrictive predicate than the inner one,
then we can drop the latter. -/
def subtype_subtype_equiv_subtype {α : Type u} {p q : α → Prop} (h : ∀ {x}, q x → p x) :
{x : subtype p // q x.1} ≃ subtype q :=
(subtype_subtype_equiv_subtype_inter p _).trans $
subtype_equiv_right $
assume x,
⟨and.right, λ h₁, ⟨h h₁, h₁⟩⟩
@[simp] lemma subtype_subtype_equiv_subtype_apply {α : Type u} {p q : α → Prop} (h : ∀ x, q x → p x)
(a : {x : subtype p // q x.1}) :
(subtype_subtype_equiv_subtype h a : α) = a :=
by { cases a, cases a_val, refl }
/-- If a proposition holds for all elements, then the subtype is
equivalent to the original type. -/
@[simps apply symm_apply]
def subtype_univ_equiv {α : Type u} {p : α → Prop} (h : ∀ x, p x) :
subtype p ≃ α :=
⟨λ x, x, λ x, ⟨x, h x⟩, λ x, subtype.eq rfl, λ x, rfl⟩
/-- A subtype of a sigma-type is a sigma-type over a subtype. -/
def subtype_sigma_equiv {α : Type u} (p : α → Type v) (q : α → Prop) :
{ y : sigma p // q y.1 } ≃ Σ(x : subtype q), p x.1 :=
⟨λ x, ⟨⟨x.1.1, x.2⟩, x.1.2⟩,
λ x, ⟨⟨x.1.1, x.2⟩, x.1.2⟩,
λ ⟨⟨x, h⟩, y⟩, rfl,
λ ⟨⟨x, y⟩, h⟩, rfl⟩
/-- A sigma type over a subtype is equivalent to the sigma set over the original type,
if the fiber is empty outside of the subset -/
def sigma_subtype_equiv_of_subset {α : Type u} (p : α → Type v) (q : α → Prop)
(h : ∀ x, p x → q x) :
(Σ x : subtype q, p x) ≃ Σ x : α, p x :=
(subtype_sigma_equiv p q).symm.trans $ subtype_univ_equiv $ λ x, h x.1 x.2
/-- If a predicate `p : β → Prop` is true on the range of a map `f : α → β`, then
`Σ y : {y // p y}, {x // f x = y}` is equivalent to `α`. -/
def sigma_subtype_preimage_equiv {α : Type u} {β : Type v} (f : α → β) (p : β → Prop)
(h : ∀ x, p (f x)) :
(Σ y : subtype p, {x : α // f x = y}) ≃ α :=
calc _ ≃ Σ y : β, {x : α // f x = y} : sigma_subtype_equiv_of_subset _ p (λ y ⟨x, h'⟩, h' ▸ h x)
... ≃ α : sigma_preimage_equiv f
/-- If for each `x` we have `p x ↔ q (f x)`, then `Σ y : {y // q y}, f ⁻¹' {y}` is equivalent
to `{x // p x}`. -/
def sigma_subtype_preimage_equiv_subtype {α : Type u} {β : Type v} (f : α → β)
{p : α → Prop} {q : β → Prop} (h : ∀ x, p x ↔ q (f x)) :
(Σ y : subtype q, {x : α // f x = y}) ≃ subtype p :=
calc (Σ y : subtype q, {x : α // f x = y}) ≃
Σ y : subtype q, {x : subtype p // subtype.mk (f x) ((h x).1 x.2) = y} :
begin
apply sigma_congr_right,
assume y,
symmetry,
refine (subtype_subtype_equiv_subtype_exists _ _).trans (subtype_equiv_right _),
assume x,
exact ⟨λ ⟨hp, h'⟩, congr_arg subtype.val h', λ h', ⟨(h x).2 (h'.symm ▸ y.2), subtype.eq h'⟩⟩
end
... ≃ subtype p : sigma_preimage_equiv (λ x : subtype p, (⟨f x, (h x).1 x.property⟩ : subtype q))
/-- A sigma type over an `option` is equivalent to the sigma set over the original type,
if the fiber is empty at none. -/
def sigma_option_equiv_of_some {α : Type u} (p : option α → Type v) (h : p none → false) :
(Σ x : option α, p x) ≃ (Σ x : α, p (some x)) :=
begin
have h' : ∀ x, p x → x.is_some,
{ intro x,
cases x,
{ intro n, exfalso, exact h n },
{ intro s, exact rfl } },
exact (sigma_subtype_equiv_of_subset _ _ h').symm.trans
(sigma_congr_left' (option_is_some_equiv α)),
end
/-- The `pi`-type `Π i, π i` is equivalent to the type of sections `f : ι → Σ i, π i` of the
`sigma` type such that for all `i` we have `(f i).fst = i`. -/
def pi_equiv_subtype_sigma (ι : Type*) (π : ι → Type*) :
(Π i, π i) ≃ {f : ι → Σ i, π i // ∀ i, (f i).1 = i } :=
⟨ λf, ⟨λi, ⟨i, f i⟩, assume i, rfl⟩, λf i, begin rw ← f.2 i, exact (f.1 i).2 end,
assume f, funext $ assume i, rfl,
assume ⟨f, hf⟩, subtype.eq $ funext $ assume i, sigma.eq (hf i).symm $
eq_of_heq $ rec_heq_of_heq _ $ rec_heq_of_heq _ $ heq.refl _⟩
/-- The set of functions `f : Π a, β a` such that for all `a` we have `p a (f a)` is equivalent
to the set of functions `Π a, {b : β a // p a b}`. -/
def subtype_pi_equiv_pi {α : Sort u} {β : α → Sort v} {p : Πa, β a → Prop} :
{f : Πa, β a // ∀a, p a (f a) } ≃ Πa, { b : β a // p a b } :=
⟨λf a, ⟨f.1 a, f.2 a⟩, λf, ⟨λa, (f a).1, λa, (f a).2⟩,
by { rintro ⟨f, h⟩, refl },
by { rintro f, funext a, exact subtype.ext_val rfl }⟩
/-- A subtype of a product defined by componentwise conditions
is equivalent to a product of subtypes. -/
def subtype_prod_equiv_prod {α : Type u} {β : Type v} {p : α → Prop} {q : β → Prop} :
{c : α × β // p c.1 ∧ q c.2} ≃ ({a // p a} × {b // q b}) :=
⟨λ x, ⟨⟨x.1.1, x.2.1⟩, ⟨x.1.2, x.2.2⟩⟩,
λ x, ⟨⟨x.1.1, x.2.1⟩, ⟨x.1.2, x.2.2⟩⟩,
λ ⟨⟨_, _⟩, ⟨_, _⟩⟩, rfl,
λ ⟨⟨_, _⟩, ⟨_, _⟩⟩, rfl⟩
/-- A subtype of a `prod` is equivalent to a sigma type whose fibers are subtypes. -/
def subtype_prod_equiv_sigma_subtype {α β : Type*} (p : α → β → Prop) :
{x : α × β // p x.1 x.2} ≃ Σ a, {b : β // p a b} :=
{ to_fun := λ x, ⟨x.1.1, x.1.2, x.prop⟩,
inv_fun := λ x, ⟨⟨x.1, x.2⟩, x.2.prop⟩,
left_inv := λ x, by ext; refl,
right_inv := λ ⟨a, b, pab⟩, rfl }
/-- The type `Π (i : α), β i` can be split as a product by separating the indices in `α`
depending on whether they satisfy a predicate `p` or not. -/
@[simps] def pi_equiv_pi_subtype_prod
{α : Type*} (p : α → Prop) (β : α → Type*) [decidable_pred p] :
(Π (i : α), β i) ≃ (Π (i : {x // p x}), β i) × (Π (i : {x // ¬ p x}), β i) :=
{ to_fun := λ f, (λ x, f x, λ x, f x),
inv_fun := λ f x, if h : p x then f.1 ⟨x, h⟩ else f.2 ⟨x, h⟩,
right_inv := begin
rintros ⟨f, g⟩,
ext1;
{ ext y,
rcases y,
simp only [y_property, dif_pos, dif_neg, not_false_iff, subtype.coe_mk],
refl },
end,
left_inv := λ f, begin
ext x,
by_cases h : p x;
{ simp only [h, dif_neg, dif_pos, not_false_iff],
refl },
end }
end
section subtype_equiv_codomain
variables {X : Type*} {Y : Type*} [decidable_eq X] {x : X}
/-- The type of all functions `X → Y` with prescribed values for all `x' ≠ x`
is equivalent to the codomain `Y`. -/
def subtype_equiv_codomain (f : {x' // x' ≠ x} → Y) : {g : X → Y // g ∘ coe = f} ≃ Y :=
(subtype_preimage _ f).trans $
@fun_unique {x' // ¬ x' ≠ x} _ $
show unique {x' // ¬ x' ≠ x}, from @equiv.unique _ _
(show unique {x' // x' = x}, from
{ default := ⟨x, rfl⟩, uniq := λ ⟨x', h⟩, subtype.val_injective h })
(subtype_equiv_right $ λ a, not_not)
@[simp] lemma coe_subtype_equiv_codomain (f : {x' // x' ≠ x} → Y) :
(subtype_equiv_codomain f : {g : X → Y // g ∘ coe = f} → Y) = λ g, (g : X → Y) x := rfl
@[simp] lemma subtype_equiv_codomain_apply (f : {x' // x' ≠ x} → Y)
(g : {g : X → Y // g ∘ coe = f}) :
subtype_equiv_codomain f g = (g : X → Y) x := rfl
lemma coe_subtype_equiv_codomain_symm (f : {x' // x' ≠ x} → Y) :
((subtype_equiv_codomain f).symm : Y → {g : X → Y // g ∘ coe = f}) =
λ y, ⟨λ x', if h : x' ≠ x then f ⟨x', h⟩ else y,
by { funext x', dsimp, erw [dif_pos x'.2, subtype.coe_eta] }⟩ := rfl
@[simp] lemma subtype_equiv_codomain_symm_apply (f : {x' // x' ≠ x} → Y) (y : Y) (x' : X) :
((subtype_equiv_codomain f).symm y : X → Y) x' = if h : x' ≠ x then f ⟨x', h⟩ else y :=
rfl
@[simp] lemma subtype_equiv_codomain_symm_apply_eq (f : {x' // x' ≠ x} → Y) (y : Y) :
((subtype_equiv_codomain f).symm y : X → Y) x = y :=
dif_neg (not_not.mpr rfl)
lemma subtype_equiv_codomain_symm_apply_ne (f : {x' // x' ≠ x} → Y) (y : Y) (x' : X) (h : x' ≠ x) :
((subtype_equiv_codomain f).symm y : X → Y) x' = f ⟨x', h⟩ :=
dif_pos h
end subtype_equiv_codomain
/-- If `f` is a bijective function, then its domain is equivalent to its codomain. -/
@[simps apply]
noncomputable def of_bijective {α β} (f : α → β) (hf : bijective f) : α ≃ β :=
{ to_fun := f,
inv_fun := function.surj_inv hf.surjective,
left_inv := function.left_inverse_surj_inv hf,
right_inv := function.right_inverse_surj_inv _}
lemma of_bijective_apply_symm_apply {α β} (f : α → β) (hf : bijective f) (x : β) :
f ((of_bijective f hf).symm x) = x :=
(of_bijective f hf).apply_symm_apply x
@[simp] lemma of_bijective_symm_apply_apply {α β} (f : α → β) (hf : bijective f) (x : α) :
(of_bijective f hf).symm (f x) = x :=
(of_bijective f hf).symm_apply_apply x
section
variables {α' β' : Type*} (e : perm α') {p : β' → Prop} [decidable_pred p]
(f : α' ≃ subtype p)
/--
Extend the domain of `e : equiv.perm α` to one that is over `β` via `f : α → subtype p`,
where `p : β → Prop`, permuting only the `b : β` that satisfy `p b`.
This can be used to extend the domain across a function `f : α → β`,
keeping everything outside of `set.range f` fixed. For this use-case `equiv` given by `f` can
be constructed by `equiv.of_left_inverse'` or `equiv.of_left_inverse` when there is a known
inverse, or `equiv.of_injective` in the general case.`.
-/
def perm.extend_domain : perm β' :=
(perm_congr f e).subtype_congr (equiv.refl _)
@[simp] lemma perm.extend_domain_apply_image (a : α') :
e.extend_domain f (f a) = f (e a) :=
by simp [perm.extend_domain]
lemma perm.extend_domain_apply_subtype {b : β'} (h : p b) :
e.extend_domain f b = f (e (f.symm ⟨b, h⟩)) :=
by simp [perm.extend_domain, h]
lemma perm.extend_domain_apply_not_subtype {b : β'} (h : ¬ p b) :
e.extend_domain f b = b :=
by simp [perm.extend_domain, h]
@[simp] lemma perm.extend_domain_refl : perm.extend_domain (equiv.refl _) f = equiv.refl _ :=
by simp [perm.extend_domain]
@[simp] lemma perm.extend_domain_symm :
(e.extend_domain f).symm = perm.extend_domain e.symm f := rfl
lemma perm.extend_domain_trans (e e' : perm α') :
(e.extend_domain f).trans (e'.extend_domain f) = perm.extend_domain (e.trans e') f :=
by simp [perm.extend_domain, perm_congr_trans]
end
/-- Subtype of the quotient is equivalent to the quotient of the subtype. Let `α` be a setoid with
equivalence relation `~`. Let `p₂` be a predicate on the quotient type `α/~`, and `p₁` be the lift
of this predicate to `α`: `p₁ a ↔ p₂ ⟦a⟧`. Let `~₂` be the restriction of `~` to `{x // p₁ x}`.
Then `{x // p₂ x}` is equivalent to the quotient of `{x // p₁ x}` by `~₂`. -/
def subtype_quotient_equiv_quotient_subtype (p₁ : α → Prop) [s₁ : setoid α]
[s₂ : setoid (subtype p₁)] (p₂ : quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧)
(h : ∀ x y : subtype p₁, @setoid.r _ s₂ x y ↔ (x : α) ≈ y) :
{x // p₂ x} ≃ quotient s₂ :=
{ to_fun := λ a, quotient.hrec_on a.1 (λ a h, ⟦⟨a, (hp₂ _).2 h⟩⟧)
(λ a b hab, hfunext (by rw quotient.sound hab)
(λ h₁ h₂ _, heq_of_eq (quotient.sound ((h _ _).2 hab)))) a.2,
inv_fun := λ a, quotient.lift_on a (λ a, (⟨⟦a.1⟧, (hp₂ _).1 a.2⟩ : {x // p₂ x}))
(λ a b hab, subtype.ext_val (quotient.sound ((h _ _).1 hab))),
left_inv := λ ⟨a, ha⟩, quotient.induction_on a (λ a ha, rfl) ha,
right_inv := λ a, quotient.induction_on a (λ ⟨a, ha⟩, rfl) }
section swap
variable [decidable_eq α]
/-- A helper function for `equiv.swap`. -/
def swap_core (a b r : α) : α :=
if r = a then b
else if r = b then a
else r
theorem swap_core_self (r a : α) : swap_core a a r = r :=
by { unfold swap_core, split_ifs; cc }
theorem swap_core_swap_core (r a b : α) : swap_core a b (swap_core a b r) = r :=
by { unfold swap_core, split_ifs; cc }
theorem swap_core_comm (r a b : α) : swap_core a b r = swap_core b a r :=
by { unfold swap_core, split_ifs; cc }
/-- `swap a b` is the permutation that swaps `a` and `b` and
leaves other values as is. -/
def swap (a b : α) : perm α :=
⟨swap_core a b, swap_core a b, λr, swap_core_swap_core r a b, λr, swap_core_swap_core r a b⟩
@[simp] theorem swap_self (a : α) : swap a a = equiv.refl _ :=
ext $ λ r, swap_core_self r a
theorem swap_comm (a b : α) : swap a b = swap b a :=
ext $ λ r, swap_core_comm r _ _
theorem swap_apply_def (a b x : α) : swap a b x = if x = a then b else if x = b then a else x :=
rfl
@[simp] theorem swap_apply_left (a b : α) : swap a b a = b :=
if_pos rfl
@[simp] theorem swap_apply_right (a b : α) : swap a b b = a :=
by { by_cases h : b = a; simp [swap_apply_def, h], }
theorem swap_apply_of_ne_of_ne {a b x : α} : x ≠ a → x ≠ b → swap a b x = x :=
by simp [swap_apply_def] {contextual := tt}
@[simp] theorem swap_swap (a b : α) : (swap a b).trans (swap a b) = equiv.refl _ :=
ext $ λ x, swap_core_swap_core _ _ _
@[simp] lemma symm_swap (a b : α) : (swap a b).symm = swap a b := rfl
@[simp] lemma swap_eq_refl_iff {x y : α} : swap x y = equiv.refl _ ↔ x = y :=
begin
refine ⟨λ h, (equiv.refl _).injective _, λ h, h ▸ (swap_self _)⟩,
rw [←h, swap_apply_left, h, refl_apply]
end
theorem swap_comp_apply {a b x : α} (π : perm α) :
π.trans (swap a b) x = if π x = a then b else if π x = b then a else π x :=
by { cases π, refl }
lemma swap_eq_update (i j : α) :
(equiv.swap i j : α → α) = update (update id j i) i j :=
funext $ λ x, by rw [update_apply _ i j, update_apply _ j i, equiv.swap_apply_def, id.def]
lemma comp_swap_eq_update (i j : α) (f : α → β) :
f ∘ equiv.swap i j = update (update f j (f i)) i (f j) :=
by rw [swap_eq_update, comp_update, comp_update, comp.right_id]
@[simp] lemma symm_trans_swap_trans [decidable_eq β] (a b : α) (e : α ≃ β) :
(e.symm.trans (swap a b)).trans e = swap (e a) (e b) :=
equiv.ext (λ x, begin
have : ∀ a, e.symm x = a ↔ x = e a :=
λ a, by { rw @eq_comm _ (e.symm x), split; intros; simp * at * },
simp [swap_apply_def, this],
split_ifs; simp
end)
@[simp] lemma trans_swap_trans_symm [decidable_eq β] (a b : β)
(e : α ≃ β) : (e.trans (swap a b)).trans e.symm = swap (e.symm a) (e.symm b) :=
symm_trans_swap_trans a b e.symm
@[simp] lemma swap_apply_self (i j a : α) :
swap i j (swap i j a) = a :=
by rw [← equiv.trans_apply, equiv.swap_swap, equiv.refl_apply]
/-- A function is invariant to a swap if it is equal at both elements -/
lemma apply_swap_eq_self {v : α → β} {i j : α} (hv : v i = v j) (k : α) : v (swap i j k) = v k :=
begin
by_cases hi : k = i, { rw [hi, swap_apply_left, hv] },
by_cases hj : k = j, { rw [hj, swap_apply_right, hv] },
rw swap_apply_of_ne_of_ne hi hj,
end
lemma swap_apply_eq_iff {x y z w : α} :
swap x y z = w ↔ z = swap x y w :=
by rw [apply_eq_iff_eq_symm_apply, symm_swap]
lemma swap_apply_ne_self_iff {a b x : α} : swap a b x ≠ x ↔ a ≠ b ∧ (x = a ∨ x = b) :=
begin
by_cases hab : a = b,
{ simp [hab] },
by_cases hax : x = a,
{ simp [hax, eq_comm] },
by_cases hbx : x = b,
{ simp [hbx] },
simp [hab, hax, hbx, swap_apply_of_ne_of_ne]
end
namespace perm
@[simp] lemma sum_congr_swap_refl {α β : Sort*} [decidable_eq α] [decidable_eq β] (i j : α) :
equiv.perm.sum_congr (equiv.swap i j) (equiv.refl β) = equiv.swap (sum.inl i) (sum.inl j) :=
begin
ext x,
cases x,
{ simp [sum.map, swap_apply_def],
split_ifs; refl},
{ simp [sum.map, swap_apply_of_ne_of_ne] },
end
@[simp] lemma sum_congr_refl_swap {α β : Sort*} [decidable_eq α] [decidable_eq β] (i j : β) :
equiv.perm.sum_congr (equiv.refl α) (equiv.swap i j) = equiv.swap (sum.inr i) (sum.inr j) :=
begin
ext x,
cases x,
{ simp [sum.map, swap_apply_of_ne_of_ne] },
{ simp [sum.map, swap_apply_def],
split_ifs; refl},
end
end perm
/-- Augment an equivalence with a prescribed mapping `f a = b` -/
def set_value (f : α ≃ β) (a : α) (b : β) : α ≃ β :=
(swap a (f.symm b)).trans f
@[simp] theorem set_value_eq (f : α ≃ β) (a : α) (b : β) : set_value f a b a = b :=
by { dsimp [set_value], simp [swap_apply_left] }
end swap
end equiv
lemma plift.eq_up_iff_down_eq {x : plift α} {y : α} : x = plift.up y ↔ x.down = y :=
equiv.plift.eq_symm_apply
lemma function.injective.map_swap {α β : Type*} [decidable_eq α] [decidable_eq β]
{f : α → β} (hf : function.injective f) (x y z : α) :
f (equiv.swap x y z) = equiv.swap (f x) (f y) (f z) :=
begin
conv_rhs { rw equiv.swap_apply_def },
split_ifs with h₁ h₂,
{ rw [hf h₁, equiv.swap_apply_left] },
{ rw [hf h₂, equiv.swap_apply_right] },
{ rw [equiv.swap_apply_of_ne_of_ne (mt (congr_arg f) h₁) (mt (congr_arg f) h₂)] }
end
namespace equiv
protected lemma exists_unique_congr {p : α → Prop} {q : β → Prop} (f : α ≃ β)
(h : ∀{x}, p x ↔ q (f x)) : (∃! x, p x) ↔ ∃! y, q y :=
begin
split,
{ rintro ⟨a, ha₁, ha₂⟩,
exact ⟨f a, h.1 ha₁, λ b hb, f.symm_apply_eq.1 (ha₂ (f.symm b) (h.2 (by simpa using hb)))⟩ },
{ rintro ⟨b, hb₁, hb₂⟩,
exact ⟨f.symm b, h.2 (by simpa using hb₁), λ y hy, (eq_symm_apply f).2 (hb₂ _ (h.1 hy))⟩ }
end
protected lemma exists_unique_congr_left' {p : α → Prop} (f : α ≃ β) :
(∃! x, p x) ↔ (∃! y, p (f.symm y)) :=
equiv.exists_unique_congr f (λx, by simp)
protected lemma exists_unique_congr_left {p : β → Prop} (f : α ≃ β) :
(∃! x, p (f x)) ↔ (∃! y, p y) :=
(equiv.exists_unique_congr_left' f.symm).symm
protected lemma forall_congr {p : α → Prop} {q : β → Prop} (f : α ≃ β)
(h : ∀{x}, p x ↔ q (f x)) : (∀x, p x) ↔ (∀y, q y) :=
begin
split; intros h₂ x,
{ rw [←f.right_inv x], apply h.mp, apply h₂ },
apply h.mpr, apply h₂
end
protected lemma forall_congr' {p : α → Prop} {q : β → Prop} (f : α ≃ β)
(h : ∀{x}, p (f.symm x) ↔ q x) : (∀x, p x) ↔ (∀y, q y) :=
(equiv.forall_congr f.symm (λ x, h.symm)).symm
-- We next build some higher arity versions of `equiv.forall_congr`.
-- Although they appear to just be repeated applications of `equiv.forall_congr`,
-- unification of metavariables works better with these versions.
-- In particular, they are necessary in `equiv_rw`.
-- (Stopping at ternary functions seems reasonable: at least in 1-categorical mathematics,
-- it's rare to have axioms involving more than 3 elements at once.)
universes ua1 ua2 ub1 ub2 ug1 ug2
variables {α₁ : Sort ua1} {α₂ : Sort ua2}
{β₁ : Sort ub1} {β₂ : Sort ub2}
{γ₁ : Sort ug1} {γ₂ : Sort ug2}
protected lemma forall₂_congr {p : α₁ → β₁ → Prop} {q : α₂ → β₂ → Prop} (eα : α₁ ≃ α₂)
(eβ : β₁ ≃ β₂) (h : ∀{x y}, p x y ↔ q (eα x) (eβ y)) :
(∀x y, p x y) ↔ (∀x y, q x y) :=
begin
apply equiv.forall_congr,
intros,
apply equiv.forall_congr,
intros,
apply h,
end
protected lemma forall₂_congr' {p : α₁ → β₁ → Prop} {q : α₂ → β₂ → Prop} (eα : α₁ ≃ α₂)
(eβ : β₁ ≃ β₂) (h : ∀{x y}, p (eα.symm x) (eβ.symm y) ↔ q x y) :
(∀x y, p x y) ↔ (∀x y, q x y) :=
(equiv.forall₂_congr eα.symm eβ.symm (λ x y, h.symm)).symm
protected lemma forall₃_congr {p : α₁ → β₁ → γ₁ → Prop} {q : α₂ → β₂ → γ₂ → Prop}
(eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (eγ : γ₁ ≃ γ₂)
(h : ∀{x y z}, p x y z ↔ q (eα x) (eβ y) (eγ z)) : (∀x y z, p x y z) ↔ (∀x y z, q x y z) :=
begin
apply equiv.forall₂_congr,
intros,
apply equiv.forall_congr,
intros,
apply h,
end
protected lemma forall₃_congr' {p : α₁ → β₁ → γ₁ → Prop} {q : α₂ → β₂ → γ₂ → Prop}
(eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (eγ : γ₁ ≃ γ₂)
(h : ∀{x y z}, p (eα.symm x) (eβ.symm y) (eγ.symm z) ↔ q x y z) :
(∀x y z, p x y z) ↔ (∀x y z, q x y z) :=
(equiv.forall₃_congr eα.symm eβ.symm eγ.symm (λ x y z, h.symm)).symm
protected lemma forall_congr_left' {p : α → Prop} (f : α ≃ β) :
(∀x, p x) ↔ (∀y, p (f.symm y)) :=
equiv.forall_congr f (λx, by simp)
protected lemma forall_congr_left {p : β → Prop} (f : α ≃ β) :
(∀x, p (f x)) ↔ (∀y, p y) :=
(equiv.forall_congr_left' f.symm).symm
protected lemma exists_congr_left {α β} (f : α ≃ β) {p : α → Prop} :
(∃ a, p a) ↔ (∃ b, p (f.symm b)) :=
⟨λ ⟨a, h⟩, ⟨f a, by simpa using h⟩, λ ⟨b, h⟩, ⟨_, h⟩⟩
section
variables (P : α → Sort w) (e : α ≃ β)
/--
Transport dependent functions through an equivalence of the base space.
-/
@[simps] def Pi_congr_left' : (Π a, P a) ≃ (Π b, P (e.symm b)) :=
{ to_fun := λ f x, f (e.symm x),
inv_fun := λ f x, begin rw [← e.symm_apply_apply x], exact f (e x) end,
left_inv := λ f, funext $ λ x, eq_of_heq ((eq_rec_heq _ _).trans
(by { dsimp, rw e.symm_apply_apply })),
right_inv := λ f, funext $ λ x, eq_of_heq ((eq_rec_heq _ _).trans
(by { rw e.apply_symm_apply })) }
end
section
variables (P : β → Sort w) (e : α ≃ β)
/--
Transporting dependent functions through an equivalence of the base,
expressed as a "simplification".
-/
def Pi_congr_left : (Π a, P (e a)) ≃ (Π b, P b) :=
(Pi_congr_left' P e.symm).symm
end
section
variables
{W : α → Sort w} {Z : β → Sort z} (h₁ : α ≃ β) (h₂ : Π a : α, (W a ≃ Z (h₁ a)))
/--
Transport dependent functions through
an equivalence of the base spaces and a family
of equivalences of the matching fibers.
-/
def Pi_congr : (Π a, W a) ≃ (Π b, Z b) :=
(equiv.Pi_congr_right h₂).trans (equiv.Pi_congr_left _ h₁)
@[simp] lemma coe_Pi_congr_symm :
((h₁.Pi_congr h₂).symm : (Π b, Z b) → (Π a, W a)) = λ f a, (h₂ a).symm (f (h₁ a)) :=
rfl
lemma Pi_congr_symm_apply (f : Π b, Z b) :
(h₁.Pi_congr h₂).symm f = λ a, (h₂ a).symm (f (h₁ a)) :=
rfl
@[simp] lemma Pi_congr_apply_apply (f : Π a, W a) (a : α) :
h₁.Pi_congr h₂ f (h₁ a) = h₂ a (f a) :=
begin
change cast _ ((h₂ (h₁.symm (h₁ a))) (f (h₁.symm (h₁ a)))) = (h₂ a) (f a),
generalize_proofs hZa,
revert hZa,
rw h₁.symm_apply_apply a,
simp,
end
end
section
variables
{W : α → Sort w} {Z : β → Sort z} (h₁ : α ≃ β) (h₂ : Π b : β, (W (h₁.symm b) ≃ Z b))
/--
Transport dependent functions through
an equivalence of the base spaces and a family
of equivalences of the matching fibres.
-/
def Pi_congr' : (Π a, W a) ≃ (Π b, Z b) :=
(Pi_congr h₁.symm (λ b, (h₂ b).symm)).symm
@[simp] lemma coe_Pi_congr' :
(h₁.Pi_congr' h₂ : (Π a, W a) → (Π b, Z b)) = λ f b, h₂ b $ f $ h₁.symm b :=
rfl
lemma Pi_congr'_apply (f : Π a, W a) :
h₁.Pi_congr' h₂ f = λ b, h₂ b $ f $ h₁.symm b :=
rfl
@[simp] lemma Pi_congr'_symm_apply_symm_apply (f : Π b, Z b) (b : β) :
(h₁.Pi_congr' h₂).symm f (h₁.symm b) = (h₂ b).symm (f b) :=
begin
change cast _ ((h₂ (h₁ (h₁.symm b))).symm (f (h₁ (h₁.symm b)))) = (h₂ b).symm (f b),
generalize_proofs hWb,
revert hWb,
generalize hb : h₁ (h₁.symm b) = b',
rw h₁.apply_symm_apply b at hb,
subst hb,
simp,
end
end
end equiv
lemma function.injective.swap_apply [decidable_eq α] [decidable_eq β] {f : α → β}
(hf : function.injective f) (x y z : α) :
equiv.swap (f x) (f y) (f z) = f (equiv.swap x y z) :=
begin
by_cases hx : z = x, by simp [hx],
by_cases hy : z = y, by simp [hy],
rw [equiv.swap_apply_of_ne_of_ne hx hy, equiv.swap_apply_of_ne_of_ne (hf.ne hx) (hf.ne hy)]
end
lemma function.injective.swap_comp [decidable_eq α] [decidable_eq β] {f : α → β}
(hf : function.injective f) (x y : α) :
equiv.swap (f x) (f y) ∘ f = f ∘ equiv.swap x y :=
funext $ λ z, hf.swap_apply _ _ _
/-- If both `α` and `β` are singletons, then `α ≃ β`. -/
def equiv_of_unique_of_unique [unique α] [unique β] : α ≃ β :=
{ to_fun := λ _, default β,
inv_fun := λ _, default α,
left_inv := λ _, subsingleton.elim _ _,
right_inv := λ _, subsingleton.elim _ _ }
/-- If `α` is a singleton, then it is equivalent to any `punit`. -/
def equiv_punit_of_unique [unique α] : α ≃ punit.{v} :=
equiv_of_unique_of_unique
/-- If `α` is a subsingleton, then it is equivalent to `α × α`. -/
def subsingleton_prod_self_equiv {α : Type*} [subsingleton α] : α × α ≃ α :=
{ to_fun := λ p, p.1,
inv_fun := λ a, (a, a),
left_inv := λ p, subsingleton.elim _ _,
right_inv := λ p, subsingleton.elim _ _, }
/-- To give an equivalence between two subsingleton types, it is sufficient to give any two
functions between them. -/
def equiv_of_subsingleton_of_subsingleton [subsingleton α] [subsingleton β]
(f : α → β) (g : β → α) : α ≃ β :=
{ to_fun := f,
inv_fun := g,
left_inv := λ _, subsingleton.elim _ _,
right_inv := λ _, subsingleton.elim _ _ }
/-- A nonempty subsingleton type is (noncomputably) equivalent to `punit`. -/
noncomputable
def equiv.punit_of_nonempty_of_subsingleton {α : Sort*} [h : nonempty α] [subsingleton α] :
α ≃ punit.{v} :=
equiv_of_subsingleton_of_subsingleton
(λ _, punit.star) (λ _, h.some)
/-- `unique (unique α)` is equivalent to `unique α`. -/
def unique_unique_equiv : unique (unique α) ≃ unique α :=
equiv_of_subsingleton_of_subsingleton (λ h, h.default)
(λ h, { default := h, uniq := λ _, subsingleton.elim _ _ })
namespace quot
/-- An equivalence `e : α ≃ β` generates an equivalence between quotient spaces,
if `ra a₁ a₂ ↔ rb (e a₁) (e a₂). -/
protected def congr {ra : α → α → Prop} {rb : β → β → Prop} (e : α ≃ β)
(eq : ∀a₁ a₂, ra a₁ a₂ ↔ rb (e a₁) (e a₂)) :
quot ra ≃ quot rb :=
{ to_fun := quot.map e (assume a₁ a₂, (eq a₁ a₂).1),
inv_fun := quot.map e.symm
(assume b₁ b₂ h,
(eq (e.symm b₁) (e.symm b₂)).2
((e.apply_symm_apply b₁).symm ▸ (e.apply_symm_apply b₂).symm ▸ h)),
left_inv := by { rintros ⟨a⟩, dunfold quot.map, simp only [equiv.symm_apply_apply] },
right_inv := by { rintros ⟨a⟩, dunfold quot.map, simp only [equiv.apply_symm_apply] } }
@[simp]
lemma congr_mk {ra : α → α → Prop} {rb : β → β → Prop} (e : α ≃ β)
(eq : ∀ (a₁ a₂ : α), ra a₁ a₂ ↔ rb (e a₁) (e a₂)) (a : α) :
quot.congr e eq (quot.mk ra a) = quot.mk rb (e a) := rfl
/-- Quotients are congruent on equivalences under equality of their relation.
An alternative is just to use rewriting with `eq`, but then computational proofs get stuck. -/
protected def congr_right {r r' : α → α → Prop} (eq : ∀a₁ a₂, r a₁ a₂ ↔ r' a₁ a₂) :
quot r ≃ quot r' :=
quot.congr (equiv.refl α) eq
/-- An equivalence `e : α ≃ β` generates an equivalence between the quotient space of `α`
by a relation `ra` and the quotient space of `β` by the image of this relation under `e`. -/
protected def congr_left {r : α → α → Prop} (e : α ≃ β) :
quot r ≃ quot (λ b b', r (e.symm b) (e.symm b')) :=
@quot.congr α β r (λ b b', r (e.symm b) (e.symm b')) e (λ a₁ a₂, by simp only [e.symm_apply_apply])
end quot
namespace quotient
/-- An equivalence `e : α ≃ β` generates an equivalence between quotient spaces,
if `ra a₁ a₂ ↔ rb (e a₁) (e a₂). -/
protected def congr {ra : setoid α} {rb : setoid β} (e : α ≃ β)
(eq : ∀a₁ a₂, @setoid.r α ra a₁ a₂ ↔ @setoid.r β rb (e a₁) (e a₂)) :
quotient ra ≃ quotient rb :=
quot.congr e eq
@[simp]
lemma congr_mk {ra : setoid α} {rb : setoid β} (e : α ≃ β)
(eq : ∀ (a₁ a₂ : α), setoid.r a₁ a₂ ↔ setoid.r (e a₁) (e a₂)) (a : α):
quotient.congr e eq (quotient.mk a) = quotient.mk (e a) :=
rfl
/-- Quotients are congruent on equivalences under equality of their relation.
An alternative is just to use rewriting with `eq`, but then computational proofs get stuck. -/
protected def congr_right {r r' : setoid α}
(eq : ∀a₁ a₂, @setoid.r α r a₁ a₂ ↔ @setoid.r α r' a₁ a₂) : quotient r ≃ quotient r' :=
quot.congr_right eq
end quotient
namespace function
lemma update_comp_equiv {α β α' : Sort*} [decidable_eq α'] [decidable_eq α] (f : α → β) (g : α' ≃ α)
(a : α) (v : β) :
update f a v ∘ g = update (f ∘ g) (g.symm a) v :=
by rw [← update_comp_eq_of_injective _ g.injective, g.apply_symm_apply]
lemma update_apply_equiv_apply {α β α' : Sort*} [decidable_eq α'] [decidable_eq α]
(f : α → β) (g : α' ≃ α) (a : α) (v : β) (a' : α') :
update f a v (g a') = update (f ∘ g) (g.symm a) v a' :=
congr_fun (update_comp_equiv f g a v) a'
end function
|
State Before: k : Type u₁
G : Type u₂
R : Type ?u.522014
inst✝¹ : Semiring k
inst✝ : MulOneClass G
f : MonoidAlgebra k G
r : k
x a : G
⊢ 1 * a = x ↔ a = x State After: no goals Tactic: rw [one_mul] |
{-# OPTIONS --without-K --safe #-}
-- Take a relation that is already reflexive and transitive
-- and make it symmetric.
-- (Borrowed from Categories/Support/ZigZag from copumpkin's Categories library
module Relation.Binary.Construct.Symmetrize where
open import Level
open import Relation.Binary
open import Relation.Binary.Construct.On using () renaming (isEquivalence to on-preserves-equivalence)
data Direction : Set where
↘ ↗ : Direction
rotate : Direction → Direction
rotate ↘ = ↗
rotate ↗ = ↘
private
variable
c ℓ₁ ℓ₂ : Level
Carrier : Set c
data ZigZag′ (_∼_ : Rel Carrier ℓ₂) : (x y : Carrier) (begin end : Direction) → Set (levelOfTerm x ⊔ ℓ₂) where
zig : ∀ {x y z e} (first : x ∼ y) (rest : ZigZag′ _∼_ y z ↗ e) → ZigZag′ _∼_ x z ↘ e
zag : ∀ {x y z e} (first : y ∼ x) (rest : ZigZag′ _∼_ y z ↘ e) → ZigZag′ _∼_ x z ↗ e
slish : ∀ {x y} (last : x ∼ y) → ZigZag′ _∼_ x y ↘ ↘
slash : ∀ {x y} (last : y ∼ x) → ZigZag′ _∼_ x y ↗ ↗
data Alternating′ (_∼_ : Carrier -> Carrier -> Set ℓ₂) (x y : Carrier) : Set (levelOfTerm x ⊔ ℓ₂) where
disorient : ∀ {begin end} (zz : ZigZag′ _∼_ x y begin end) → Alternating′ _∼_ x y
module _ (Base : Preorder c ℓ₁ ℓ₂) where
ZigZag : (x y : Preorder.Carrier Base) (begin end : Direction) → Set (c ⊔ ℓ₂)
ZigZag = ZigZag′ (Preorder._∼_ Base)
private
sym′ : {x y z : Preorder.Carrier Base} {begin middle end : Direction} → ZigZag y z middle end →
ZigZag y x middle begin → ZigZag z x (rotate end) begin
sym′ (zig first rest) accum = sym′ rest (zag first accum)
sym′ (zag first rest) accum = sym′ rest (zig first accum)
sym′ (slish last) accum = zag last accum
sym′ (slash last) accum = zig last accum
sym : ∀ {x y begin end} → ZigZag x y begin end → ZigZag y x (rotate end) (rotate begin)
sym (zig first rest) = sym′ rest (slash first)
sym (zag first rest) = sym′ rest (slish first)
sym (slish last) = slash last
sym (slash last) = slish last
trans : ∀ {x y z begin end begin′ end′} → ZigZag x y begin end → ZigZag y z begin′ end′ → ZigZag x z begin end′
trans (zig first rest) yz = zig first (trans rest yz)
trans (zag first rest) yz = zag first (trans rest yz)
trans (slish last) (zig first rest) = zig (Preorder.trans Base last first) rest
trans (slish last) (zag first rest) = zig last (zag first rest)
trans (slish last) (slish only) = slish (Preorder.trans Base last only)
trans (slish last) (slash only) = zig last (slash only)
trans (slash last) (zig first rest) = zag last (zig first rest)
trans (slash last) (zag first rest) = zag (Preorder.trans Base first last) rest
trans (slash last) (slish only) = zag last (slish only)
trans (slash last) (slash only) = slash (Preorder.trans Base only last)
Alternating : (x y : Preorder.Carrier Base) → Set (c ⊔ ℓ₂)
Alternating = Alternating′ (Preorder._∼_ Base)
private
is-equivalence : IsEquivalence Alternating
is-equivalence = record
{ refl = disorient (slash (Preorder.refl Base))
; sym = λ where (disorient zz) → disorient (sym zz)
; trans = λ where (disorient ij) (disorient jk) → disorient (trans ij jk)
}
setoid : Setoid c (c ⊔ ℓ₂)
setoid = record
{ Carrier = Preorder.Carrier Base
; _≈_ = Alternating
; isEquivalence = is-equivalence
}
-- the main eliminators for Alternating -- they prove that any equivalence that
-- respects the base preorder also respects its Alternating completion.
locally-minimal : ∀ {ℓ′} {_≈_ : Rel (Preorder.Carrier Base) ℓ′} (≈-isEquivalence : IsEquivalence _≈_) →
(Preorder._∼_ Base ⇒ _≈_) → (Alternating ⇒ _≈_)
locally-minimal {_} {_≋_} isEq inj (disorient zz) = impl zz
where
open IsEquivalence isEq renaming (sym to >sym; trans to _>trans>_)
impl : {i j : Preorder.Carrier Base} {b e : Direction} → ZigZag i j b e → i ≋ j
impl (zig first rest) = inj first >trans> impl rest
impl (zag first rest) = >sym (inj first) >trans> impl rest
impl (slish last) = inj last
impl (slash last) = >sym (inj last)
minimal : ∀ {c′ ℓ′} (Dest : Setoid c′ ℓ′) (f : Preorder.Carrier Base → Setoid.Carrier Dest) →
(Preorder._∼_ Base =[ f ]⇒ Setoid._≈_ Dest) → (Alternating =[ f ]⇒ Setoid._≈_ Dest)
minimal Dest f inj = locally-minimal (on-preserves-equivalence f (Setoid.isEquivalence Dest)) inj
|
{-# OPTIONS --without-K --safe #-}
open import Level
open import Categories.Category
module Categories.Category.Construction.Path {o ℓ e : Level} (C : Category o ℓ e) where
open import Function using (flip)
open import Relation.Binary hiding (_⇒_)
open import Relation.Binary.Construct.Closure.Transitive
open Category C
-- Defining the Path Category
∘-tc : {A B : Obj} → A [ _⇒_ ]⁺ B → A ⇒ B
∘-tc [ f ] = f
∘-tc (_ ∼⁺⟨ f⁺ ⟩ f⁺′) = ∘-tc f⁺′ ∘ ∘-tc f⁺
infix 4 _≈⁺_
_≈⁺_ : {A B : Obj} → (i j : A [ _⇒_ ]⁺ B) → Set e
f⁺ ≈⁺ g⁺ = ∘-tc f⁺ ≈ ∘-tc g⁺
Path : Category o (o ⊔ ℓ) e
Path = record
{ Obj = Obj
; _⇒_ = λ A B → A [ _⇒_ ]⁺ B
; _≈_ = _≈⁺_
; id = [ id ]
; _∘_ = flip (_ ∼⁺⟨_⟩_)
; assoc = assoc
; sym-assoc = sym-assoc
; identityˡ = identityˡ
; identityʳ = identityʳ
; identity² = identity²
; equiv = record
{ refl = refl
; sym = sym
; trans = trans
}
; ∘-resp-≈ = ∘-resp-≈
}
where open HomReasoning
|
{-# OPTIONS --without-K #-}
module equality.reasoning where
open import equality.core
module ≡-Reasoning {i} {X : Set i} where
infix 4 _IsRelatedTo_
infix 2 _∎
infixr 2 _≡⟨_⟩_
infix 1 begin_
-- This seemingly unnecessary type is used to make it possible to
-- infer arguments even if the underlying equality evaluates.
data _IsRelatedTo_ (x y : X) : Set i where
relTo : x ≡ y → x IsRelatedTo y
begin_ : ∀ {x y} → x IsRelatedTo y → x ≡ y
begin relTo p = p
_≡⟨_⟩_ : ∀ x {y z} → x ≡ y → y IsRelatedTo z → x IsRelatedTo z
_ ≡⟨ p ⟩ relTo q = relTo (p · q)
_∎ : ∀ x → x IsRelatedTo x
_∎ _ = relTo refl
|
theory T90
imports Main
begin
lemma "(
(\<forall> x::nat. \<forall> y::nat. meet(x, y) = meet(y, x)) &
(\<forall> x::nat. \<forall> y::nat. join(x, y) = join(y, x)) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, meet(y, z)) = meet(meet(x, y), z)) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(x, join(y, z)) = join(join(x, y), z)) &
(\<forall> x::nat. \<forall> y::nat. meet(x, join(x, y)) = x) &
(\<forall> x::nat. \<forall> y::nat. join(x, meet(x, y)) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, join(y, z)) = join(mult(x, y), mult(x, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(join(x, y), z) = join(mult(x, z), mult(y, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, over(join(mult(x, y), z), y)) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(y, undr(x, join(mult(x, y), z))) = y) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(over(x, y), y), x) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(y, undr(y, x)), x) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, meet(y, z)) = meet(mult(x, y), mult(x, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. over(join(x, y), z) = join(over(x, z), over(y, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. over(x, meet(y, z)) = join(over(x, y), over(x, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(meet(x, y), z) = join(undr(x, z), undr(y, z))) &
(\<forall> x::nat. \<forall> y::nat. invo(join(x, y)) = meet(invo(x), invo(y))) &
(\<forall> x::nat. \<forall> y::nat. invo(meet(x, y)) = join(invo(x), invo(y))) &
(\<forall> x::nat. invo(invo(x)) = x)
) \<longrightarrow>
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(x, join(y, z)) = join(undr(x, y), undr(x, z)))
"
nitpick[card nat=10,timeout=86400]
oops
end |
theory T25
imports Main
begin
lemma "(
(\<forall> x::nat. \<forall> y::nat. meet(x, y) = meet(y, x)) &
(\<forall> x::nat. \<forall> y::nat. join(x, y) = join(y, x)) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, meet(y, z)) = meet(meet(x, y), z)) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(x, join(y, z)) = join(join(x, y), z)) &
(\<forall> x::nat. \<forall> y::nat. meet(x, join(x, y)) = x) &
(\<forall> x::nat. \<forall> y::nat. join(x, meet(x, y)) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, join(y, z)) = join(mult(x, y), mult(x, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(join(x, y), z) = join(mult(x, z), mult(y, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, over(join(mult(x, y), z), y)) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(y, undr(x, join(mult(x, y), z))) = y) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(over(x, y), y), x) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(y, undr(y, x)), x) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(meet(x, y), z) = meet(mult(x, z), mult(y, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(x, join(y, z)) = join(undr(x, y), undr(x, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. over(join(x, y), z) = join(over(x, z), over(y, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. over(x, meet(y, z)) = join(over(x, y), over(x, z))) &
(\<forall> x::nat. \<forall> y::nat. invo(join(x, y)) = meet(invo(x), invo(y))) &
(\<forall> x::nat. \<forall> y::nat. invo(meet(x, y)) = join(invo(x), invo(y))) &
(\<forall> x::nat. invo(invo(x)) = x)
) \<longrightarrow>
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, meet(y, z)) = meet(mult(x, y), mult(x, z)))
"
nitpick[card nat=8,timeout=86400]
oops
end |
Great washi tape for scrapbooking layouts, card making and holding dies in place while die cutting them.
Roll size 15mm x 10m.
Good for scrapbooking layouts and making cards. Roll size 15mm x 10m. |
{-# OPTIONS --cubical --no-import-sorts #-}
open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero)
module Number.Structures where
private
variable
ℓ ℓ' : Level
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Relation.Nullary.Base -- ¬_
open import Cubical.Relation.Binary.Base -- Rel
-- open import Data.Nat.Base using (ℕ) renaming (_≤_ to _≤ₙ_)
open import Cubical.Data.Nat using (ℕ; zero; suc) renaming (_+_ to _+ₙ_)
open import Cubical.Data.Nat.Order renaming (zero-≤ to z≤n; suc-≤-suc to s≤s; _≤_ to _≤ₙ_; _<_ to _<ₙ_)
open import Cubical.Data.Unit.Base -- Unit
open import Cubical.Data.Empty -- ⊥
open import Cubical.Data.Sum.Base renaming (_⊎_ to infixr 4 _⊎_)
open import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_)
open import Cubical.Data.Empty renaming (elim to ⊥-elim) -- `⊥` and `elim`
open import Cubical.Data.Maybe.Base
import MoreAlgebra
open MoreAlgebra.Definitions
import Algebra.Structures
-- ℕ ℤ ℚ ℝ ℂ and ℚ₀⁺ ℝ₀⁺ ...
-- ring without additive inverse
-- see Algebra.Structures.IsCommutativeSemiring
record IsRCommSemiring {F : Type ℓ} (_#_ : Rel F F ℓ') (0f 1f : F) (_+_ _·_ : F → F → F) : Type (ℓ-max ℓ ℓ') where
field
isApartnessRel : IsApartnessRel _#_
-- TODO: properties
open IsApartnessRel isApartnessRel public
renaming
( isIrrefl to #-irrefl
; isSym to #-sym
; isCotrans to #-cotrans )
-- ℤ ℚ ℝ ℂ
-- see Algebra.Structures.IsCommutativeRing
record IsRCommRing {F : Type ℓ} (_#_ : Rel F F ℓ') (0f 1f : F) (_+_ _·_ : F → F → F) (-_ : F → F) : Type (ℓ-max ℓ ℓ') where
field
isRCommSemiring : IsRCommSemiring _#_ 0f 1f _+_ _·_
open IsRCommSemiring isRCommSemiring public
-- ℚ ℝ ℂ
record IsRField {F : Type ℓ} (_#_ : Rel F F ℓ') (0f 1f : F) (_+_ _·_ : F → F → F) (-_ : F → F) (_⁻¹ : (x : F) → {{ x # 0f }} → F) : Type (ℓ-max ℓ ℓ') where
field
isRCommRing : IsRCommRing _#_ 0f 1f _+_ _·_ -_
+-assoc : ∀ x y z → (x + y) + z ≡ x + (y + z)
+-comm : ∀ x y → x + y ≡ y + x
distrib : ∀ x y z → (x + y) · z ≡ (x · z) + (y · z)
⁻¹-preserves-#0 : ∀ x → (p : x # 0f) → _⁻¹ x {{p}} # 0f
-preserves-# : ∀ x y → x # y → (- x) # (- y)
-preserves-#0 : ∀ x → x # 0f → (- x) # 0f
·-#0-#0-implies-#0 : ∀ a b → a # 0f → b # 0f → (a · b) # 0f
1#0 : 1f # 0f
-- TODO: properties
open IsRCommRing isRCommRing public
-- Finₖ ℕ ℤ ℚ ℝ and ℚ₀⁺ ℚ⁺ ℝ₀⁺ ℝ⁺ ...
record IsRLattice {F : Type ℓ} (_<_ _≤_ _#_ : Rel F F ℓ') (min max : F → F → F) : Type (ℓ-max ℓ ℓ') where
field
isPartialOrder : IsPartialOrder _≤_
glb : ∀ x y z → z ≤ min x y → z ≤ x × z ≤ y
glb-back : ∀ x y z → z ≤ x × z ≤ y → z ≤ min x y
lub : ∀ x y z → max x y ≤ z → x ≤ z × y ≤ z
lub-back : ∀ x y z → x ≤ z × y ≤ z → max x y ≤ z
-- TODO: derived properties
<-implies-# : ∀ x y → x < y → x # y
≤-#-implies-< : ∀ x y → x ≤ y → x # y → x < y
#-sym : ∀ x y → x # y → y # x
max-sym : ∀ x y → max x y ≡ max y x
max-id : ∀ x → max x x ≡ x
open IsPartialOrder isPartialOrder public
-- ℕ ℤ ℚ ℝ and ℚ₀⁺ ℚ⁺ ℝ₀⁺ ℝ⁺ ...
-- ring without additive inverse
record IsROrderedCommSemiring {F : Type ℓ} (_<_ _≤_ _#_ : Rel F F ℓ') (min max : F → F → F) (0f 1f : F) (_+_ _·_ : F → F → F) : Type (ℓ-max ℓ ℓ') where
field
isRLattice : IsRLattice _<_ _≤_ _#_ min max
isRCommSemiring : IsRCommSemiring _#_ 0f 1f _+_ _·_
-- TODO: properties
-- TODO: the following can be derived
0<1 : 0f < 1f
+-0<-0<-implies-0< : ∀ a b → 0f < a → 0f < b → 0f < (a + b)
+-0<-0≤-implies-0< : ∀ a b → 0f < a → 0f ≤ b → 0f < (a + b)
+-0≤-0<-implies-0< : ∀ a b → 0f ≤ a → 0f < b → 0f < (a + b)
+-0≤-0≤-implies-0≤ : ∀ a b → 0f ≤ a → 0f ≤ b → 0f ≤ (a + b)
+-<0-<0-implies-<0 : ∀ a b → a < 0f → b < 0f → (a + b) < 0f
+-<0-≤0-implies-<0 : ∀ a b → a < 0f → b ≤ 0f → (a + b) < 0f
+-≤0-<0-implies-<0 : ∀ a b → a ≤ 0f → b < 0f → (a + b) < 0f
+-≤0-≤0-implies-≤0 : ∀ a b → a ≤ 0f → b ≤ 0f → (a + b) ≤ 0f
·-#0-#0-implies-#0 : ∀ a b → a # 0f → b # 0f → (a · b) # 0f
·-#0-0<-implies-#0 : ∀ a b → a # 0f → 0f < b → (a · b) # 0f
·-#0-<0-implies-#0 : ∀ a b → a # 0f → b < 0f → (a · b) # 0f
·-0≤-0≤-implies-0≤ : ∀ a b → 0f ≤ a → 0f ≤ b → 0f ≤ (a · b)
·-0≤-0<-implies-0≤ : ∀ a b → 0f ≤ a → 0f < b → 0f ≤ (a · b)
·-0≤-<0-implies-≤0 : ∀ a b → 0f ≤ a → b < 0f → (a · b) ≤ 0f
·-0≤-≤0-implies-≤0 : ∀ a b → 0f ≤ a → b ≤ 0f → (a · b) ≤ 0f
·-0<-#0-implies-#0 : ∀ a b → 0f < a → b # 0f → (a · b) # 0f
·-0<-0≤-implies-0≤ : ∀ a b → 0f < a → 0f ≤ b → 0f ≤ (a · b)
·-0<-0<-implies-0< : ∀ a b → 0f < a → 0f < b → 0f < (a · b)
·-0<-<0-implies-<0 : ∀ a b → 0f < a → b < 0f → (a · b) < 0f
·-0<-≤0-implies-≤0 : ∀ a b → 0f < a → b ≤ 0f → (a · b) ≤ 0f
·-<0-#0-implies-#0 : ∀ a b → a < 0f → b # 0f → (a · b) # 0f
·-<0-0≤-implies-≤0 : ∀ a b → a < 0f → 0f ≤ b → (a · b) ≤ 0f
·-<0-0<-implies-<0 : ∀ a b → a < 0f → 0f < b → (a · b) < 0f
·-<0-<0-implies-0< : ∀ a b → a < 0f → b < 0f → 0f < (a · b)
·-<0-≤0-implies-0≤ : ∀ a b → a < 0f → b ≤ 0f → 0f ≤ (a · b)
·-≤0-0≤-implies-≤0 : ∀ a b → a ≤ 0f → 0f ≤ b → (a · b) ≤ 0f
·-≤0-0<-implies-≤0 : ∀ a b → a ≤ 0f → 0f < b → (a · b) ≤ 0f
·-≤0-<0-implies-0≤ : ∀ a b → a ≤ 0f → b < 0f → 0f ≤ (a · b)
·-≤0-≤0-implies-0≤ : ∀ a b → a ≤ 0f → b ≤ 0f → 0f ≤ (a · b)
0≤-#0-implies-0< : ∀ x → 0f ≤ x → x # 0f → 0f < x
{-
·-#0-#0-implies-#0 : ∀ a b → a # 0f → b # 0f → (a · b) # 0f
·-#0-0<-implies-#0 : ∀ a b → a # 0f → 0f < b → (a · b) # 0f
·-0≤-0≤-implies-0≤ : ∀ a b → 0f ≤ a → 0f ≤ b → 0f ≤ (a · b)
·-0≤-0<-implies-0≤ : ∀ a b → 0f ≤ a → 0f < b → 0f ≤ (a · b)
·-0≤-≤0-implies-≤0 : ∀ a b → 0f ≤ a → b ≤ 0f → (a · b) ≤ 0f
·-0<-#0-implies-#0 : ∀ a b → 0f < a → b # 0f → (a · b) # 0f
·-0<-0≤-implies-0≤ : ∀ a b → 0f < a → 0f ≤ b → 0f ≤ (a · b)
·-0<-0<-implies-0< : ∀ a b → 0f < a → 0f < b → 0f < (a · b)
·-0<-≤0-implies-≤0 : ∀ a b → 0f < a → b ≤ 0f → (a · b) ≤ 0f
·-≤0-0≤-implies-≤0 : ∀ a b → a ≤ 0f → 0f ≤ b → (a · b) ≤ 0f
·-≤0-0<-implies-≤0 : ∀ a b → a ≤ 0f → 0f < b → (a · b) ≤ 0f
·-≤0-≤0-implies-0≤ : ∀ a b → a ≤ 0f → b ≤ 0f → 0f ≤ (a · b)
-}
open IsRLattice isRLattice public
-- ℤ ℚ ℝ
record IsROrderedCommRing {F : Type ℓ} (_<_ _≤_ _#_ : Rel F F ℓ') (min max : F → F → F) (0f 1f : F) (_+_ _·_ : F → F → F) (-_ : F → F) : Type (ℓ-max ℓ ℓ') where
field
isROrderedCommSemiring : IsROrderedCommSemiring _<_ _≤_ _#_ min max 0f 1f _+_ _·_
isRCommRing : IsRCommRing _#_ 0f 1f _+_ _·_ -_
0≡-0 : 0f ≡ - 0f
-flips-< : ∀ x y → x < y → (- y) < (- x)
-flips-<0 : ∀ x → x < 0f → 0f < (- x)
-flips-0< : ∀ x → 0f < x → (- x) < 0f
-flips-≤ : ∀ x y → x ≤ y → (- y) ≤ (- x)
-flips-≤0 : ∀ x → x ≤ 0f → 0f ≤ (- x)
-flips-0≤ : ∀ x → 0f ≤ x → (- x) ≤ 0f
-preserves-# : ∀ x y → x # y → (- x) # (- y)
-preserves-#0 : ∀ x → x # 0f → (- x) # 0f
-- TODO: properties
open IsROrderedCommSemiring isROrderedCommSemiring public
-- Remark 6.7.7. As we define absolute values by | x | = max(x, -x), as is common in constructive analysis,
-- if x has a locator, then so does | x |, and we use this fact in the proof of the above theorem.
-- Remark 4.1.9.
--
-- 1. From the fact that (A, ≤, min, max) is a lattice, it does not follow that
-- for every x and y,
--
-- max(x, y) = x ∨ max(x, y) = y,
--
-- which would hold in a linear order.
-- However, in Lemma 6.7.1 we characterize max as
--
-- z < max(x, y) ⇔ z < x ∨ z < y,
--
-- and similarly for min.
{- from: https://isabelle.in.tum.de/doc/tutorial.pdf "8.4.5 The Numeric Type Classes"
Absolute Value.
The absolute value function `abs` is available for all ordered rings, including types int, rat and real.
It satisfies many properties, such as the following:
| x * y | ≡ | x | * | y | (abs_mult)
| a | ≤ b ⇔ (a ≤ b) ∧ (- a) ≤ b (abs_le_iff)
| a + b | ≤ | a | + | b | (abs_triangle_ineq)
-}
-- also see https://en.wikipedia.org/wiki/Ordered_ring#Basic_properties
record IsAbsOrderedCommRing {F : Type ℓ} (_<_ _≤_ _#_ : Rel F F ℓ') (min max : F → F → F) (0f 1f : F) (_+_ _·_ : F → F → F) (-_ : F → F) (abs : F → F) : Type (ℓ-max ℓ ℓ') where
field
abs0≡0 : abs 0f ≡ 0f
abs-preserves-· : ∀ x y → abs (x · y) ≡ abs x · abs y
triangle-ineq : ∀ x y → abs (x + y) ≤ (abs x + abs y)
-- -trichotomy : ∀ x → (x ≡ 0f) ⊎ (0f < x) ⊎ (0f < (- x))
abs-≤ : ∀ x y → abs x ≤ y → (x ≤ y) × ((- x) ≤ y)
abs-≤-back : ∀ x y → (x ≤ y) × ((- x) ≤ y) → abs x ≤ y
0≤abs : ∀ x → 0f ≤ abs x
-- ℚ ℝ
record IsROrderedField {F : Type ℓ} (_<_ _≤_ _#_ : Rel F F ℓ') (min max : F → F → F) (0f 1f : F) (_+_ _·_ : F → F → F) (-_ : F → F) (_⁻¹ : (x : F) → {{ x # 0f }} → F) : Type (ℓ-max ℓ ℓ') where
field
isROrderedCommRing : IsROrderedCommRing _<_ _≤_ _#_ min max 0f 1f _+_ _·_ -_
isRField : IsRField _#_ 0f 1f _+_ _·_ -_ _⁻¹
-- TODO: properties
open IsROrderedCommRing isROrderedCommRing hiding
( -preserves-#
; -preserves-#0
) public
open IsRField isRField hiding
( ·-#0-#0-implies-#0
) public
field
⁻¹-preserves-<0 : ∀ x → (x < 0f) → (p : x # 0f) → _⁻¹ x {{p}} < 0f
⁻¹-preserves-0< : ∀ x → (0f < x) → (p : x # 0f) → 0f < _⁻¹ x {{p}}
-- ℚ₀⁺ ℚ₀⁻ ℝ₀⁺ ℝ₀⁻
{-
record IsROrderedSemifield {F : Type ℓ} (_<_ _≤_ _#_ : Rel F F ℓ') (min max : F → F → F) (0f 1f : F) (_+_ _·_ : F → F → F) (_⁻¹ : (x : F) → {{ x < 0f }} → F) : Type (ℓ-max ℓ ℓ') where
field
isROrderedCommSemiring : IsROrderedCommSemiring _<_ _≤_ _#_ min max 0f 1f _+_ _·_
-- TODO: properties
#0-implies-0< : ∀ x → 0f # x → 0f < x
positivity : ∀ x → 0f ≤ x
open IsROrderedCommSemiring isROrderedCommSemiring public
-}
-- ℚ⁺ ℚ⁻ ℝ⁺ ℝ⁻
{-
record IsROrderedSemifieldWithoutZero {F : Type ℓ} (_<_ _≤_ _#_ : Rel F F ℓ') (min max : F → F → F) (0f 1f : F) (_+_ _·_ : F → F → F) (_⁻¹ : (x : F) → F) : Type (ℓ-max ℓ ℓ') where
field
isRLattice : IsRLattice _<_ _≤_ _#_ min max
-- isGroup : IsGroup 1f _·_ _⁻¹
+-assoc : ∀ x y z → (x + y) + z ≡ x + (y + z)
+-comm : ∀ x y → x + y ≡ y + x
distrib : ∀ x y z → (x + y) · z ≡ (x · z) + (y · z)
-- TODO: properties
open IsRLattice isRLattice public
-}
|
{-
This second-order signature was created from the following second-order syntax description:
syntax Sum | S
type
_⊕_ : 2-ary | l30
term
inl : α -> α ⊕ β
inr : β -> α ⊕ β
case : α ⊕ β α.γ β.γ -> γ
theory
(lβ) a : α f : α.γ g : β.γ |> case (inl(a), x.f[x], y.g[y]) = f[a]
(rβ) b : β f : α.γ g : β.γ |> case (inr(b), x.f[x], y.g[y]) = g[b]
(cη) s : α ⊕ β c : (α ⊕ β).γ |> case (s, x.c[inl(x)], y.c[inr(y)]) = c[s]
-}
module Sum.Signature where
open import SOAS.Context
-- Type declaration
data ST : Set where
_⊕_ : ST → ST → ST
infixl 30 _⊕_
open import SOAS.Syntax.Signature ST public
open import SOAS.Syntax.Build ST public
-- Operator symbols
data Sₒ : Set where
inlₒ inrₒ : {α β : ST} → Sₒ
caseₒ : {α β γ : ST} → Sₒ
-- Term signature
S:Sig : Signature Sₒ
S:Sig = sig λ
{ (inlₒ {α}{β}) → (⊢₀ α) ⟼₁ α ⊕ β
; (inrₒ {α}{β}) → (⊢₀ β) ⟼₁ α ⊕ β
; (caseₒ {α}{β}{γ}) → (⊢₀ α ⊕ β) , (α ⊢₁ γ) , (β ⊢₁ γ) ⟼₃ γ
}
open Signature S:Sig public
|
theory T88
imports Main
begin
lemma "(
(\<forall> x::nat. \<forall> y::nat. meet(x, y) = meet(y, x)) &
(\<forall> x::nat. \<forall> y::nat. join(x, y) = join(y, x)) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, meet(y, z)) = meet(meet(x, y), z)) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(x, join(y, z)) = join(join(x, y), z)) &
(\<forall> x::nat. \<forall> y::nat. meet(x, join(x, y)) = x) &
(\<forall> x::nat. \<forall> y::nat. join(x, meet(x, y)) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, join(y, z)) = join(mult(x, y), mult(x, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(join(x, y), z) = join(mult(x, z), mult(y, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, over(join(mult(x, y), z), y)) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(y, undr(x, join(mult(x, y), z))) = y) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(over(x, y), y), x) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(y, undr(y, x)), x) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, meet(y, z)) = meet(mult(x, y), mult(x, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(meet(x, y), z) = meet(mult(x, z), mult(y, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. over(join(x, y), z) = join(over(x, z), over(y, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(meet(x, y), z) = join(undr(x, z), undr(y, z))) &
(\<forall> x::nat. \<forall> y::nat. invo(join(x, y)) = meet(invo(x), invo(y))) &
(\<forall> x::nat. \<forall> y::nat. invo(meet(x, y)) = join(invo(x), invo(y))) &
(\<forall> x::nat. invo(invo(x)) = x)
) \<longrightarrow>
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(x, join(y, z)) = join(undr(x, y), undr(x, z)))
"
nitpick[card nat=10,timeout=86400]
oops
end |
Formal statement is: lemma tendsto_at_topI_sequentially_real: fixes f :: "real \<Rightarrow> real" assumes mono: "mono f" and limseq: "(\<lambda>n. f (real n)) \<longlonglongrightarrow> y" shows "(f \<longlongrightarrow> y) at_top" Informal statement is: If $f$ is a monotone function and $(f(n))_{n \in \mathbb{N}}$ converges to $y$, then $(f(x))_{x \in \mathbb{R}}$ converges to $y$ as $x \to \infty$. |
%!TEX root = ../thesis.tex
%%%%% Chapter: Conclusion %%%%%
\chapter{Conclusion}
\label{chap:conclusion}
\ifpdf
\graphicspath{{Chapter10/Figs/Raster/}{Chapter10/Figs/PDF/}{Chapter10/Figs/}}
\else
\graphicspath{{Chapter10/Figs/Vector/}{Chapter10/Figs/}}
\fi
\section{Summary of the Tesseract OCR engine}
The Tesseract OCR engine is a straightforward tool to convert handout images to chunks of extracted text. It contains a built-in Page Layout Analysis which identifies distinct chunks of text information. The Tesseract PLA provides 5 different scales: word, line, paragraph, block and page. The alignment accuracy is roughly proportional to the size of the scale.
Recognising handwritten text with OCR engine is generally hard, and fine-tuning the original Tesseract model with external handwritten data also didn't work quite well, according to the evaluation results in \Cref{chap:eval-results}.
\section{Summary of the \texttt{diff}-based Alignment Algorithm}
The design of alignment algorithm of the system is based on the idea of the Unix command-line tool \texttt{diff}. The core part of the alignment algorithm in the system solves the optimal alignment between the sequence words in the handout and the sequence of words in the lecture audio file. The alignment algorithm could be parameterised by using different joint weight functions (JWF).
In the final alignment algorithm, two more constraints have been added on top of the baseline \texttt{diff} algorithm, which are the time constraint and the common-word penalty. These constraints have improved the final alignment accuracy but only by a little amount.
\section{Feasibility of the General Idea}
The project aims to test the feasibility of the idea of making a software system to provide direct links from chunks of the handouts to the cooresponding segments in the lecture audio files. A simple software system based on the Tesseract OCR engine, the Google Cloud speech recogniser and the \texttt{diff}-based alignment algorithm has been developed to investigate this idea. An evaluation framework has been designed and implemented to quantify the performance of the system. A GUI system has been developed to visualise the core elements in the system, including a visualisation of the bounding-boxes in the input handout and a playback system which takes the user from a specific chunk of handout to the matched parts in the audio file.
As a conclusion, this idea should be regarded as feasible based on the results from the evaluation framework. When the OCR scale is set to `paragraph', the best alignment accuracy that can be achieved is 46.67\%. Although this number does not seem to be high, the actual experience of using the alignment functionality of the GUI is actually quite satisfactory. For most of the time, the alignment can find the positions of the audio segments at roughly the right place and these segments usually have half of their total length intersected with the ground-truth segments (this agrees with the alignment accuracy 46.67\%). In practice we just need to move around the audio cursor by a little bit if the alignment could link us to the roughly correct position.
Furthermore, considering that we have used an extremely simple system architecture which roughly solves the task, it would be completely possible for us to achieve even better results using more sophisticated architectures.
\section{Future Work}
The Tesseract OCR engine has done a very decent job in general, with the only obvious weak point that it cannot recognise handwritten data very well. Recognising handwritten text with decent accuracy would be very helpful to achieve even better alignment results, which is definitely worthwhile to be investigated in the future.
The \texttt{diff}-based alignment algorithm is capable of computing satisfactory alignment results for simple input data which complies with our basic assumptions. However its performance is expected to drop when the complexity of the task increases. Hence, investigating alternative algorithm to the \texttt{diff}-based one that solves more sophisticated tasks should also be interesting.
Equations also form a crucial part in the CUED handouts. It is also worth investigating how the lecturers refer to equations and how to convert printed and handwritten equations to the spoken form. The alignment accuracy is likely to be significantly boosted if equations could be recognised with acceptable accuracy.
|
-- Andreas, 2017-07-27
module _ where
module A where
record A : Set where
open A
open A
-- ERROR WAS:
-- Ambiguous module name A. It could refer to any one of
-- A.A
-- Issue705.A
-- EXPECTED:
-- Ambiguous module name A. It could refer to any one of
-- A.A (record module)
-- Issue705.A
|
lemma cohomotopically_trivial_retraction_gen: assumes P: "\<And>f. \<lbrakk>continuous_on t f; f ` t \<subseteq> U; Q f\<rbrakk> \<Longrightarrow> P(f \<circ> h)" and Q: "\<And>f. \<lbrakk>continuous_on s f; f ` s \<subseteq> U; P f\<rbrakk> \<Longrightarrow> Q(f \<circ> k)" and Qeq: "\<And>h k. (\<And>x. x \<in> t \<Longrightarrow> h x = k x) \<Longrightarrow> Q h = Q k" and hom: "\<And>f g. \<lbrakk>continuous_on s f; f ` s \<subseteq> U; P f; continuous_on s g; g ` s \<subseteq> U; P g\<rbrakk> \<Longrightarrow> homotopic_with_canon P s U f g" and contf: "continuous_on t f" and imf: "f ` t \<subseteq> U" and Qf: "Q f" and contg: "continuous_on t g" and img: "g ` t \<subseteq> U" and Qg: "Q g" shows "homotopic_with_canon Q t U f g" |
This adorable Aqua Dot trim kini maternity swimsuit from Prego features a beautiful aqua colored base with black dots and black neckline straps.
Has lined cups for extra support and coverage and black under the belly bottoms.
Made in USA! 80% Nylon and 20% Lycra. Wash in cold non chlorine detergent. |
module options where
open import lib
open import options-types public
----------------------------------------------------------------------------------
-- Run-rewriting rules
----------------------------------------------------------------------------------
data gratr2-nt : Set where
_ws-plus-34 : gratr2-nt
_ws : gratr2-nt
_str-bool : gratr2-nt
_start : gratr2-nt
_squote : gratr2-nt
_posinfo : gratr2-nt
_paths : gratr2-nt
_path-star-1 : gratr2-nt
_path : gratr2-nt
_ows-star-35 : gratr2-nt
_ows : gratr2-nt
_opts : gratr2-nt
_opt : gratr2-nt
_numpunct-bar-8 : gratr2-nt
_numpunct-bar-7 : gratr2-nt
_numpunct : gratr2-nt
_numone-range-5 : gratr2-nt
_numone : gratr2-nt
_num-plus-6 : gratr2-nt
_num : gratr2-nt
_comment-star-30 : gratr2-nt
_comment : gratr2-nt
_aws-bar-33 : gratr2-nt
_aws-bar-32 : gratr2-nt
_aws-bar-31 : gratr2-nt
_aws : gratr2-nt
_anychar-bar-9 : gratr2-nt
_anychar-bar-29 : gratr2-nt
_anychar-bar-28 : gratr2-nt
_anychar-bar-27 : gratr2-nt
_anychar-bar-26 : gratr2-nt
_anychar-bar-25 : gratr2-nt
_anychar-bar-24 : gratr2-nt
_anychar-bar-23 : gratr2-nt
_anychar-bar-22 : gratr2-nt
_anychar-bar-21 : gratr2-nt
_anychar-bar-20 : gratr2-nt
_anychar-bar-19 : gratr2-nt
_anychar-bar-18 : gratr2-nt
_anychar-bar-17 : gratr2-nt
_anychar-bar-16 : gratr2-nt
_anychar-bar-15 : gratr2-nt
_anychar-bar-14 : gratr2-nt
_anychar-bar-13 : gratr2-nt
_anychar-bar-12 : gratr2-nt
_anychar-bar-11 : gratr2-nt
_anychar-bar-10 : gratr2-nt
_anychar : gratr2-nt
_alpha-range-3 : gratr2-nt
_alpha-range-2 : gratr2-nt
_alpha-bar-4 : gratr2-nt
_alpha : gratr2-nt
gratr2-nt-eq : gratr2-nt → gratr2-nt → 𝔹
gratr2-nt-eq _ws-plus-34 _ws-plus-34 = tt
gratr2-nt-eq _ws _ws = tt
gratr2-nt-eq _str-bool _str-bool = tt
gratr2-nt-eq _start _start = tt
gratr2-nt-eq _squote _squote = tt
gratr2-nt-eq _posinfo _posinfo = tt
gratr2-nt-eq _paths _paths = tt
gratr2-nt-eq _path-star-1 _path-star-1 = tt
gratr2-nt-eq _path _path = tt
gratr2-nt-eq _ows-star-35 _ows-star-35 = tt
gratr2-nt-eq _ows _ows = tt
gratr2-nt-eq _opts _opts = tt
gratr2-nt-eq _opt _opt = tt
gratr2-nt-eq _numpunct-bar-8 _numpunct-bar-8 = tt
gratr2-nt-eq _numpunct-bar-7 _numpunct-bar-7 = tt
gratr2-nt-eq _numpunct _numpunct = tt
gratr2-nt-eq _numone-range-5 _numone-range-5 = tt
gratr2-nt-eq _numone _numone = tt
gratr2-nt-eq _num-plus-6 _num-plus-6 = tt
gratr2-nt-eq _num _num = tt
gratr2-nt-eq _comment-star-30 _comment-star-30 = tt
gratr2-nt-eq _comment _comment = tt
gratr2-nt-eq _aws-bar-33 _aws-bar-33 = tt
gratr2-nt-eq _aws-bar-32 _aws-bar-32 = tt
gratr2-nt-eq _aws-bar-31 _aws-bar-31 = tt
gratr2-nt-eq _aws _aws = tt
gratr2-nt-eq _anychar-bar-9 _anychar-bar-9 = tt
gratr2-nt-eq _anychar-bar-29 _anychar-bar-29 = tt
gratr2-nt-eq _anychar-bar-28 _anychar-bar-28 = tt
gratr2-nt-eq _anychar-bar-27 _anychar-bar-27 = tt
gratr2-nt-eq _anychar-bar-26 _anychar-bar-26 = tt
gratr2-nt-eq _anychar-bar-25 _anychar-bar-25 = tt
gratr2-nt-eq _anychar-bar-24 _anychar-bar-24 = tt
gratr2-nt-eq _anychar-bar-23 _anychar-bar-23 = tt
gratr2-nt-eq _anychar-bar-22 _anychar-bar-22 = tt
gratr2-nt-eq _anychar-bar-21 _anychar-bar-21 = tt
gratr2-nt-eq _anychar-bar-20 _anychar-bar-20 = tt
gratr2-nt-eq _anychar-bar-19 _anychar-bar-19 = tt
gratr2-nt-eq _anychar-bar-18 _anychar-bar-18 = tt
gratr2-nt-eq _anychar-bar-17 _anychar-bar-17 = tt
gratr2-nt-eq _anychar-bar-16 _anychar-bar-16 = tt
gratr2-nt-eq _anychar-bar-15 _anychar-bar-15 = tt
gratr2-nt-eq _anychar-bar-14 _anychar-bar-14 = tt
gratr2-nt-eq _anychar-bar-13 _anychar-bar-13 = tt
gratr2-nt-eq _anychar-bar-12 _anychar-bar-12 = tt
gratr2-nt-eq _anychar-bar-11 _anychar-bar-11 = tt
gratr2-nt-eq _anychar-bar-10 _anychar-bar-10 = tt
gratr2-nt-eq _anychar _anychar = tt
gratr2-nt-eq _alpha-range-3 _alpha-range-3 = tt
gratr2-nt-eq _alpha-range-2 _alpha-range-2 = tt
gratr2-nt-eq _alpha-bar-4 _alpha-bar-4 = tt
gratr2-nt-eq _alpha _alpha = tt
gratr2-nt-eq _ _ = ff
open import rtn gratr2-nt
options-start : gratr2-nt → 𝕃 gratr2-rule
options-start _ws-plus-34 = (just "P132" , nothing , just _ws-plus-34 , inj₁ _aws :: inj₁ _ws-plus-34 :: []) :: (just "P131" , nothing , just _ws-plus-34 , inj₁ _aws :: []) :: []
options-start _ws = (just "P133" , nothing , just _ws , inj₁ _ws-plus-34 :: []) :: []
options-start _str-bool = (just "StrBoolTrue" , nothing , just _str-bool , inj₂ 't' :: inj₂ 'r' :: inj₂ 'u' :: inj₂ 'e' :: []) :: (just "StrBoolFalse" , nothing , just _str-bool , inj₂ 'f' :: inj₂ 'a' :: inj₂ 'l' :: inj₂ 's' :: inj₂ 'e' :: []) :: []
options-start _start = (just "File" , nothing , just _start , inj₁ _opts :: inj₁ _ows :: []) :: []
options-start _squote = (just "P0" , nothing , just _squote , inj₂ '\"' :: []) :: []
options-start _posinfo = (just "Posinfo" , nothing , just _posinfo , []) :: []
options-start _paths = (just "PathsNil" , nothing , just _paths , []) :: (just "PathsCons" , nothing , just _paths , inj₁ _ws :: inj₁ _path :: inj₁ _paths :: []) :: []
options-start _path-star-1 = (just "P2" , nothing , just _path-star-1 , inj₁ _anychar :: inj₁ _path-star-1 :: []) :: (just "P1" , nothing , just _path-star-1 , []) :: []
options-start _path = (just "P3" , nothing , just _path , inj₁ _squote :: inj₁ _path-star-1 :: inj₁ _squote :: []) :: []
options-start _ows-star-35 = (just "P135" , nothing , just _ows-star-35 , inj₁ _aws :: inj₁ _ows-star-35 :: []) :: (just "P134" , nothing , just _ows-star-35 , []) :: []
options-start _ows = (just "P136" , nothing , just _ows , inj₁ _ows-star-35 :: []) :: []
options-start _opts = (just "OptsNil" , nothing , just _opts , []) :: (just "OptsCons" , nothing , just _opts , inj₁ _ows :: inj₁ _opt :: inj₁ _opts :: []) :: []
options-start _opt = (just "UseCedeFiles" , nothing , just _opt , inj₂ 'u' :: inj₂ 's' :: inj₂ 'e' :: inj₂ '-' :: inj₂ 'c' :: inj₂ 'e' :: inj₂ 'd' :: inj₂ 'e' :: inj₂ '-' :: inj₂ 'f' :: inj₂ 'i' :: inj₂ 'l' :: inj₂ 'e' :: inj₂ 's' :: inj₁ _ows :: inj₂ '=' :: inj₁ _ows :: inj₁ _str-bool :: inj₁ _ows :: inj₂ '.' :: inj₁ _ows :: []) :: (just "ShowQualifiedVars" , nothing , just _opt , inj₂ 's' :: inj₂ 'h' :: inj₂ 'o' :: inj₂ 'w' :: inj₂ '-' :: inj₂ 'q' :: inj₂ 'u' :: inj₂ 'a' :: inj₂ 'l' :: inj₂ 'i' :: inj₂ 'f' :: inj₂ 'i' :: inj₂ 'e' :: inj₂ 'd' :: inj₂ '-' :: inj₂ 'v' :: inj₂ 'a' :: inj₂ 'r' :: inj₂ 's' :: inj₁ _ows :: inj₂ '=' :: inj₁ _ows :: inj₁ _str-bool :: inj₁ _ows :: inj₂ '.' :: inj₁ _ows :: []) :: (just "MakeRktFiles" , nothing , just _opt , inj₂ 'm' :: inj₂ 'a' :: inj₂ 'k' :: inj₂ 'e' :: inj₂ '-' :: inj₂ 'r' :: inj₂ 'k' :: inj₂ 't' :: inj₂ '-' :: inj₂ 'f' :: inj₂ 'i' :: inj₂ 'l' :: inj₂ 'e' :: inj₂ 's' :: inj₁ _ows :: inj₂ '=' :: inj₁ _ows :: inj₁ _str-bool :: inj₁ _ows :: inj₂ '.' :: inj₁ _ows :: []) :: (just "Lib" , nothing , just _opt , inj₂ 'i' :: inj₂ 'm' :: inj₂ 'p' :: inj₂ 'o' :: inj₂ 'r' :: inj₂ 't' :: inj₂ '-' :: inj₂ 'd' :: inj₂ 'i' :: inj₂ 'r' :: inj₂ 'e' :: inj₂ 'c' :: inj₂ 't' :: inj₂ 'o' :: inj₂ 'r' :: inj₂ 'i' :: inj₂ 'e' :: inj₂ 's' :: inj₁ _ows :: inj₂ '=' :: inj₁ _ows :: inj₁ _paths :: inj₁ _ows :: inj₂ '.' :: []) :: (just "GenerateLogs" , nothing , just _opt , inj₂ 'g' :: inj₂ 'e' :: inj₂ 'n' :: inj₂ 'e' :: inj₂ 'r' :: inj₂ 'a' :: inj₂ 't' :: inj₂ 'e' :: inj₂ '-' :: inj₂ 'l' :: inj₂ 'o' :: inj₂ 'g' :: inj₂ 's' :: inj₁ _ows :: inj₂ '=' :: inj₁ _ows :: inj₁ _str-bool :: inj₁ _ows :: inj₂ '.' :: inj₁ _ows :: []) :: []
options-start _numpunct-bar-8 = (just "P76" , nothing , just _numpunct-bar-8 , inj₁ _numpunct-bar-7 :: []) :: (just "P75" , nothing , just _numpunct-bar-8 , inj₁ _numone :: []) :: []
options-start _numpunct-bar-7 = (just "P74" , nothing , just _numpunct-bar-7 , inj₂ '-' :: []) :: (just "P73" , nothing , just _numpunct-bar-7 , inj₂ '\'' :: []) :: []
options-start _numpunct = (just "P77" , nothing , just _numpunct , inj₁ _numpunct-bar-8 :: []) :: []
options-start _numone-range-5 = (just "P68" , nothing , just _numone-range-5 , inj₂ '9' :: []) :: (just "P67" , nothing , just _numone-range-5 , inj₂ '8' :: []) :: (just "P66" , nothing , just _numone-range-5 , inj₂ '7' :: []) :: (just "P65" , nothing , just _numone-range-5 , inj₂ '6' :: []) :: (just "P64" , nothing , just _numone-range-5 , inj₂ '5' :: []) :: (just "P63" , nothing , just _numone-range-5 , inj₂ '4' :: []) :: (just "P62" , nothing , just _numone-range-5 , inj₂ '3' :: []) :: (just "P61" , nothing , just _numone-range-5 , inj₂ '2' :: []) :: (just "P60" , nothing , just _numone-range-5 , inj₂ '1' :: []) :: (just "P59" , nothing , just _numone-range-5 , inj₂ '0' :: []) :: []
options-start _numone = (just "P69" , nothing , just _numone , inj₁ _numone-range-5 :: []) :: []
options-start _num-plus-6 = (just "P71" , nothing , just _num-plus-6 , inj₁ _numone :: inj₁ _num-plus-6 :: []) :: (just "P70" , nothing , just _num-plus-6 , inj₁ _numone :: []) :: []
options-start _num = (just "P72" , nothing , just _num , inj₁ _num-plus-6 :: []) :: []
options-start _comment-star-30 = (just "P122" , nothing , just _comment-star-30 , inj₁ _anychar :: inj₁ _comment-star-30 :: []) :: (just "P121" , nothing , just _comment-star-30 , []) :: []
options-start _comment = (just "P123" , nothing , just _comment , inj₂ '%' :: inj₁ _comment-star-30 :: inj₂ '\n' :: []) :: []
options-start _aws-bar-33 = (just "P129" , nothing , just _aws-bar-33 , inj₁ _aws-bar-32 :: []) :: (just "P128" , nothing , just _aws-bar-33 , inj₂ '\n' :: []) :: []
options-start _aws-bar-32 = (just "P127" , nothing , just _aws-bar-32 , inj₁ _aws-bar-31 :: []) :: (just "P126" , nothing , just _aws-bar-32 , inj₂ '\t' :: []) :: []
options-start _aws-bar-31 = (just "P125" , nothing , just _aws-bar-31 , inj₁ _comment :: []) :: (just "P124" , nothing , just _aws-bar-31 , inj₂ ' ' :: []) :: []
options-start _aws = (just "P130" , nothing , just _aws , inj₁ _aws-bar-33 :: []) :: []
options-start _anychar-bar-9 = (just "P79" , nothing , just _anychar-bar-9 , inj₂ '_' :: []) :: (just "P78" , nothing , just _anychar-bar-9 , inj₂ '/' :: []) :: []
options-start _anychar-bar-29 = (just "P119" , nothing , just _anychar-bar-29 , inj₁ _anychar-bar-28 :: []) :: (just "P118" , nothing , just _anychar-bar-29 , inj₁ _alpha :: []) :: []
options-start _anychar-bar-28 = (just "P117" , nothing , just _anychar-bar-28 , inj₁ _anychar-bar-27 :: []) :: (just "P116" , nothing , just _anychar-bar-28 , inj₁ _numpunct :: []) :: []
options-start _anychar-bar-27 = (just "P115" , nothing , just _anychar-bar-27 , inj₁ _anychar-bar-26 :: []) :: (just "P114" , nothing , just _anychar-bar-27 , inj₂ '\t' :: []) :: []
options-start _anychar-bar-26 = (just "P113" , nothing , just _anychar-bar-26 , inj₁ _anychar-bar-25 :: []) :: (just "P112" , nothing , just _anychar-bar-26 , inj₂ ' ' :: []) :: []
options-start _anychar-bar-25 = (just "P111" , nothing , just _anychar-bar-25 , inj₁ _anychar-bar-24 :: []) :: (just "P110" , nothing , just _anychar-bar-25 , inj₂ '%' :: []) :: []
options-start _anychar-bar-24 = (just "P109" , nothing , just _anychar-bar-24 , inj₁ _anychar-bar-23 :: []) :: (just "P108" , nothing , just _anychar-bar-24 , inj₂ '(' :: []) :: []
options-start _anychar-bar-23 = (just "P107" , nothing , just _anychar-bar-23 , inj₁ _anychar-bar-22 :: []) :: (just "P106" , nothing , just _anychar-bar-23 , inj₂ ')' :: []) :: []
options-start _anychar-bar-22 = (just "P105" , nothing , just _anychar-bar-22 , inj₁ _anychar-bar-21 :: []) :: (just "P104" , nothing , just _anychar-bar-22 , inj₂ ':' :: []) :: []
options-start _anychar-bar-21 = (just "P103" , nothing , just _anychar-bar-21 , inj₁ _anychar-bar-20 :: []) :: (just "P102" , nothing , just _anychar-bar-21 , inj₂ '.' :: []) :: []
options-start _anychar-bar-20 = (just "P101" , nothing , just _anychar-bar-20 , inj₁ _anychar-bar-19 :: []) :: (just "P100" , nothing , just _anychar-bar-20 , inj₂ '[' :: []) :: []
options-start _anychar-bar-19 = (just "P99" , nothing , just _anychar-bar-19 , inj₁ _anychar-bar-18 :: []) :: (just "P98" , nothing , just _anychar-bar-19 , inj₂ ']' :: []) :: []
options-start _anychar-bar-18 = (just "P97" , nothing , just _anychar-bar-18 , inj₁ _anychar-bar-17 :: []) :: (just "P96" , nothing , just _anychar-bar-18 , inj₂ ',' :: []) :: []
options-start _anychar-bar-17 = (just "P95" , nothing , just _anychar-bar-17 , inj₁ _anychar-bar-16 :: []) :: (just "P94" , nothing , just _anychar-bar-17 , inj₂ '!' :: []) :: []
options-start _anychar-bar-16 = (just "P93" , nothing , just _anychar-bar-16 , inj₁ _anychar-bar-15 :: []) :: (just "P92" , nothing , just _anychar-bar-16 , inj₂ '{' :: []) :: []
options-start _anychar-bar-15 = (just "P91" , nothing , just _anychar-bar-15 , inj₁ _anychar-bar-14 :: []) :: (just "P90" , nothing , just _anychar-bar-15 , inj₂ '}' :: []) :: []
options-start _anychar-bar-14 = (just "P89" , nothing , just _anychar-bar-14 , inj₁ _anychar-bar-13 :: []) :: (just "P88" , nothing , just _anychar-bar-14 , inj₂ '-' :: []) :: []
options-start _anychar-bar-13 = (just "P87" , nothing , just _anychar-bar-13 , inj₁ _anychar-bar-12 :: []) :: (just "P86" , nothing , just _anychar-bar-13 , inj₂ '=' :: []) :: []
options-start _anychar-bar-12 = (just "P85" , nothing , just _anychar-bar-12 , inj₁ _anychar-bar-11 :: []) :: (just "P84" , nothing , just _anychar-bar-12 , inj₂ '+' :: []) :: []
options-start _anychar-bar-11 = (just "P83" , nothing , just _anychar-bar-11 , inj₁ _anychar-bar-10 :: []) :: (just "P82" , nothing , just _anychar-bar-11 , inj₂ '<' :: []) :: []
options-start _anychar-bar-10 = (just "P81" , nothing , just _anychar-bar-10 , inj₁ _anychar-bar-9 :: []) :: (just "P80" , nothing , just _anychar-bar-10 , inj₂ '>' :: []) :: []
options-start _anychar = (just "P120" , nothing , just _anychar , inj₁ _anychar-bar-29 :: []) :: []
options-start _alpha-range-3 = (just "P55" , nothing , just _alpha-range-3 , inj₂ 'Z' :: []) :: (just "P54" , nothing , just _alpha-range-3 , inj₂ 'Y' :: []) :: (just "P53" , nothing , just _alpha-range-3 , inj₂ 'X' :: []) :: (just "P52" , nothing , just _alpha-range-3 , inj₂ 'W' :: []) :: (just "P51" , nothing , just _alpha-range-3 , inj₂ 'V' :: []) :: (just "P50" , nothing , just _alpha-range-3 , inj₂ 'U' :: []) :: (just "P49" , nothing , just _alpha-range-3 , inj₂ 'T' :: []) :: (just "P48" , nothing , just _alpha-range-3 , inj₂ 'S' :: []) :: (just "P47" , nothing , just _alpha-range-3 , inj₂ 'R' :: []) :: (just "P46" , nothing , just _alpha-range-3 , inj₂ 'Q' :: []) :: (just "P45" , nothing , just _alpha-range-3 , inj₂ 'P' :: []) :: (just "P44" , nothing , just _alpha-range-3 , inj₂ 'O' :: []) :: (just "P43" , nothing , just _alpha-range-3 , inj₂ 'N' :: []) :: (just "P42" , nothing , just _alpha-range-3 , inj₂ 'M' :: []) :: (just "P41" , nothing , just _alpha-range-3 , inj₂ 'L' :: []) :: (just "P40" , nothing , just _alpha-range-3 , inj₂ 'K' :: []) :: (just "P39" , nothing , just _alpha-range-3 , inj₂ 'J' :: []) :: (just "P38" , nothing , just _alpha-range-3 , inj₂ 'I' :: []) :: (just "P37" , nothing , just _alpha-range-3 , inj₂ 'H' :: []) :: (just "P36" , nothing , just _alpha-range-3 , inj₂ 'G' :: []) :: (just "P35" , nothing , just _alpha-range-3 , inj₂ 'F' :: []) :: (just "P34" , nothing , just _alpha-range-3 , inj₂ 'E' :: []) :: (just "P33" , nothing , just _alpha-range-3 , inj₂ 'D' :: []) :: (just "P32" , nothing , just _alpha-range-3 , inj₂ 'C' :: []) :: (just "P31" , nothing , just _alpha-range-3 , inj₂ 'B' :: []) :: (just "P30" , nothing , just _alpha-range-3 , inj₂ 'A' :: []) :: []
options-start _alpha-range-2 = (just "P9" , nothing , just _alpha-range-2 , inj₂ 'f' :: []) :: (just "P8" , nothing , just _alpha-range-2 , inj₂ 'e' :: []) :: (just "P7" , nothing , just _alpha-range-2 , inj₂ 'd' :: []) :: (just "P6" , nothing , just _alpha-range-2 , inj₂ 'c' :: []) :: (just "P5" , nothing , just _alpha-range-2 , inj₂ 'b' :: []) :: (just "P4" , nothing , just _alpha-range-2 , inj₂ 'a' :: []) :: (just "P29" , nothing , just _alpha-range-2 , inj₂ 'z' :: []) :: (just "P28" , nothing , just _alpha-range-2 , inj₂ 'y' :: []) :: (just "P27" , nothing , just _alpha-range-2 , inj₂ 'x' :: []) :: (just "P26" , nothing , just _alpha-range-2 , inj₂ 'w' :: []) :: (just "P25" , nothing , just _alpha-range-2 , inj₂ 'v' :: []) :: (just "P24" , nothing , just _alpha-range-2 , inj₂ 'u' :: []) :: (just "P23" , nothing , just _alpha-range-2 , inj₂ 't' :: []) :: (just "P22" , nothing , just _alpha-range-2 , inj₂ 's' :: []) :: (just "P21" , nothing , just _alpha-range-2 , inj₂ 'r' :: []) :: (just "P20" , nothing , just _alpha-range-2 , inj₂ 'q' :: []) :: (just "P19" , nothing , just _alpha-range-2 , inj₂ 'p' :: []) :: (just "P18" , nothing , just _alpha-range-2 , inj₂ 'o' :: []) :: (just "P17" , nothing , just _alpha-range-2 , inj₂ 'n' :: []) :: (just "P16" , nothing , just _alpha-range-2 , inj₂ 'm' :: []) :: (just "P15" , nothing , just _alpha-range-2 , inj₂ 'l' :: []) :: (just "P14" , nothing , just _alpha-range-2 , inj₂ 'k' :: []) :: (just "P13" , nothing , just _alpha-range-2 , inj₂ 'j' :: []) :: (just "P12" , nothing , just _alpha-range-2 , inj₂ 'i' :: []) :: (just "P11" , nothing , just _alpha-range-2 , inj₂ 'h' :: []) :: (just "P10" , nothing , just _alpha-range-2 , inj₂ 'g' :: []) :: []
options-start _alpha-bar-4 = (just "P57" , nothing , just _alpha-bar-4 , inj₁ _alpha-range-3 :: []) :: (just "P56" , nothing , just _alpha-bar-4 , inj₁ _alpha-range-2 :: []) :: []
options-start _alpha = (just "P58" , nothing , just _alpha , inj₁ _alpha-bar-4 :: []) :: []
options-return : maybe gratr2-nt → 𝕃 gratr2-rule
options-return _ = []
options-rtn : gratr2-rtn
options-rtn = record { start = _start ; _eq_ = gratr2-nt-eq ; gratr2-start = options-start ; gratr2-return = options-return }
open import run ptr
open noderiv
------------------------------------------
-- Length-decreasing rules
------------------------------------------
len-dec-rewrite : Run → maybe (Run × ℕ)
len-dec-rewrite {- File-} ((Id "File") :: (ParseTree (parsed-opts x0)) :: _::_(ParseTree parsed-ows) rest) = just (ParseTree (parsed-start (norm-start (File x0))) ::' rest , 3)
len-dec-rewrite {- GenerateLogs-} ((Id "GenerateLogs") :: (InputChar 'g') :: (InputChar 'e') :: (InputChar 'n') :: (InputChar 'e') :: (InputChar 'r') :: (InputChar 'a') :: (InputChar 't') :: (InputChar 'e') :: (InputChar '-') :: (InputChar 'l') :: (InputChar 'o') :: (InputChar 'g') :: (InputChar 's') :: (ParseTree parsed-ows) :: (InputChar '=') :: (ParseTree parsed-ows) :: (ParseTree (parsed-str-bool x0)) :: (ParseTree parsed-ows) :: (InputChar '.') :: _::_(ParseTree parsed-ows) rest) = just (ParseTree (parsed-opt (norm-opt (GenerateLogs x0))) ::' rest , 21)
len-dec-rewrite {- Lib-} ((Id "Lib") :: (InputChar 'i') :: (InputChar 'm') :: (InputChar 'p') :: (InputChar 'o') :: (InputChar 'r') :: (InputChar 't') :: (InputChar '-') :: (InputChar 'd') :: (InputChar 'i') :: (InputChar 'r') :: (InputChar 'e') :: (InputChar 'c') :: (InputChar 't') :: (InputChar 'o') :: (InputChar 'r') :: (InputChar 'i') :: (InputChar 'e') :: (InputChar 's') :: (ParseTree parsed-ows) :: (InputChar '=') :: (ParseTree parsed-ows) :: (ParseTree (parsed-paths x0)) :: (ParseTree parsed-ows) :: _::_(InputChar '.') rest) = just (ParseTree (parsed-opt (norm-opt (Lib x0))) ::' rest , 25)
len-dec-rewrite {- MakeRktFiles-} ((Id "MakeRktFiles") :: (InputChar 'm') :: (InputChar 'a') :: (InputChar 'k') :: (InputChar 'e') :: (InputChar '-') :: (InputChar 'r') :: (InputChar 'k') :: (InputChar 't') :: (InputChar '-') :: (InputChar 'f') :: (InputChar 'i') :: (InputChar 'l') :: (InputChar 'e') :: (InputChar 's') :: (ParseTree parsed-ows) :: (InputChar '=') :: (ParseTree parsed-ows) :: (ParseTree (parsed-str-bool x0)) :: (ParseTree parsed-ows) :: (InputChar '.') :: _::_(ParseTree parsed-ows) rest) = just (ParseTree (parsed-opt (norm-opt (MakeRktFiles x0))) ::' rest , 22)
len-dec-rewrite {- OptsCons-} ((Id "OptsCons") :: (ParseTree parsed-ows) :: (ParseTree (parsed-opt x0)) :: _::_(ParseTree (parsed-opts x1)) rest) = just (ParseTree (parsed-opts (norm-opts (OptsCons x0 x1))) ::' rest , 4)
len-dec-rewrite {- P0-} ((Id "P0") :: _::_(InputChar '\"') rest) = just (ParseTree parsed-squote ::' rest , 2)
len-dec-rewrite {- P10-} ((Id "P10") :: _::_(InputChar 'g') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'g'))) ::' rest , 2)
len-dec-rewrite {- P100-} ((Id "P100") :: _::_(InputChar '[') rest) = just (ParseTree (parsed-anychar-bar-20 (string-append 0 (char-to-string '['))) ::' rest , 2)
len-dec-rewrite {- P101-} ((Id "P101") :: _::_(ParseTree (parsed-anychar-bar-19 x0)) rest) = just (ParseTree (parsed-anychar-bar-20 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P102-} ((Id "P102") :: _::_(InputChar '.') rest) = just (ParseTree (parsed-anychar-bar-21 (string-append 0 (char-to-string '.'))) ::' rest , 2)
len-dec-rewrite {- P103-} ((Id "P103") :: _::_(ParseTree (parsed-anychar-bar-20 x0)) rest) = just (ParseTree (parsed-anychar-bar-21 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P104-} ((Id "P104") :: _::_(InputChar ':') rest) = just (ParseTree (parsed-anychar-bar-22 (string-append 0 (char-to-string ':'))) ::' rest , 2)
len-dec-rewrite {- P105-} ((Id "P105") :: _::_(ParseTree (parsed-anychar-bar-21 x0)) rest) = just (ParseTree (parsed-anychar-bar-22 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P106-} ((Id "P106") :: _::_(InputChar ')') rest) = just (ParseTree (parsed-anychar-bar-23 (string-append 0 (char-to-string ')'))) ::' rest , 2)
len-dec-rewrite {- P107-} ((Id "P107") :: _::_(ParseTree (parsed-anychar-bar-22 x0)) rest) = just (ParseTree (parsed-anychar-bar-23 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P108-} ((Id "P108") :: _::_(InputChar '(') rest) = just (ParseTree (parsed-anychar-bar-24 (string-append 0 (char-to-string '('))) ::' rest , 2)
len-dec-rewrite {- P109-} ((Id "P109") :: _::_(ParseTree (parsed-anychar-bar-23 x0)) rest) = just (ParseTree (parsed-anychar-bar-24 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P11-} ((Id "P11") :: _::_(InputChar 'h') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'h'))) ::' rest , 2)
len-dec-rewrite {- P110-} ((Id "P110") :: _::_(InputChar '%') rest) = just (ParseTree (parsed-anychar-bar-25 (string-append 0 (char-to-string '%'))) ::' rest , 2)
len-dec-rewrite {- P111-} ((Id "P111") :: _::_(ParseTree (parsed-anychar-bar-24 x0)) rest) = just (ParseTree (parsed-anychar-bar-25 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P112-} ((Id "P112") :: _::_(InputChar ' ') rest) = just (ParseTree (parsed-anychar-bar-26 (string-append 0 (char-to-string ' '))) ::' rest , 2)
len-dec-rewrite {- P113-} ((Id "P113") :: _::_(ParseTree (parsed-anychar-bar-25 x0)) rest) = just (ParseTree (parsed-anychar-bar-26 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P114-} ((Id "P114") :: _::_(InputChar '\t') rest) = just (ParseTree (parsed-anychar-bar-27 (string-append 0 (char-to-string '\t'))) ::' rest , 2)
len-dec-rewrite {- P115-} ((Id "P115") :: _::_(ParseTree (parsed-anychar-bar-26 x0)) rest) = just (ParseTree (parsed-anychar-bar-27 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P116-} ((Id "P116") :: _::_(ParseTree (parsed-numpunct x0)) rest) = just (ParseTree (parsed-anychar-bar-28 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P117-} ((Id "P117") :: _::_(ParseTree (parsed-anychar-bar-27 x0)) rest) = just (ParseTree (parsed-anychar-bar-28 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P118-} ((Id "P118") :: _::_(ParseTree (parsed-alpha x0)) rest) = just (ParseTree (parsed-anychar-bar-29 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P119-} ((Id "P119") :: _::_(ParseTree (parsed-anychar-bar-28 x0)) rest) = just (ParseTree (parsed-anychar-bar-29 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P12-} ((Id "P12") :: _::_(InputChar 'i') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'i'))) ::' rest , 2)
len-dec-rewrite {- P120-} ((Id "P120") :: _::_(ParseTree (parsed-anychar-bar-29 x0)) rest) = just (ParseTree (parsed-anychar (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P122-} ((Id "P122") :: (ParseTree (parsed-anychar x0)) :: _::_(ParseTree parsed-comment-star-30) rest) = just (ParseTree parsed-comment-star-30 ::' rest , 3)
len-dec-rewrite {- P123-} ((Id "P123") :: (InputChar '%') :: (ParseTree parsed-comment-star-30) :: _::_(InputChar '\n') rest) = just (ParseTree parsed-comment ::' rest , 4)
len-dec-rewrite {- P124-} ((Id "P124") :: _::_(InputChar ' ') rest) = just (ParseTree parsed-aws-bar-31 ::' rest , 2)
len-dec-rewrite {- P125-} ((Id "P125") :: _::_(ParseTree parsed-comment) rest) = just (ParseTree parsed-aws-bar-31 ::' rest , 2)
len-dec-rewrite {- P126-} ((Id "P126") :: _::_(InputChar '\t') rest) = just (ParseTree parsed-aws-bar-32 ::' rest , 2)
len-dec-rewrite {- P127-} ((Id "P127") :: _::_(ParseTree parsed-aws-bar-31) rest) = just (ParseTree parsed-aws-bar-32 ::' rest , 2)
len-dec-rewrite {- P128-} ((Id "P128") :: _::_(InputChar '\n') rest) = just (ParseTree parsed-aws-bar-33 ::' rest , 2)
len-dec-rewrite {- P129-} ((Id "P129") :: _::_(ParseTree parsed-aws-bar-32) rest) = just (ParseTree parsed-aws-bar-33 ::' rest , 2)
len-dec-rewrite {- P13-} ((Id "P13") :: _::_(InputChar 'j') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'j'))) ::' rest , 2)
len-dec-rewrite {- P130-} ((Id "P130") :: _::_(ParseTree parsed-aws-bar-33) rest) = just (ParseTree parsed-aws ::' rest , 2)
len-dec-rewrite {- P131-} ((Id "P131") :: _::_(ParseTree parsed-aws) rest) = just (ParseTree parsed-ws-plus-34 ::' rest , 2)
len-dec-rewrite {- P132-} ((Id "P132") :: (ParseTree parsed-aws) :: _::_(ParseTree parsed-ws-plus-34) rest) = just (ParseTree parsed-ws-plus-34 ::' rest , 3)
len-dec-rewrite {- P133-} ((Id "P133") :: _::_(ParseTree parsed-ws-plus-34) rest) = just (ParseTree parsed-ws ::' rest , 2)
len-dec-rewrite {- P135-} ((Id "P135") :: (ParseTree parsed-aws) :: _::_(ParseTree parsed-ows-star-35) rest) = just (ParseTree parsed-ows-star-35 ::' rest , 3)
len-dec-rewrite {- P136-} ((Id "P136") :: _::_(ParseTree parsed-ows-star-35) rest) = just (ParseTree parsed-ows ::' rest , 2)
len-dec-rewrite {- P14-} ((Id "P14") :: _::_(InputChar 'k') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'k'))) ::' rest , 2)
len-dec-rewrite {- P15-} ((Id "P15") :: _::_(InputChar 'l') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'l'))) ::' rest , 2)
len-dec-rewrite {- P16-} ((Id "P16") :: _::_(InputChar 'm') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'm'))) ::' rest , 2)
len-dec-rewrite {- P17-} ((Id "P17") :: _::_(InputChar 'n') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'n'))) ::' rest , 2)
len-dec-rewrite {- P18-} ((Id "P18") :: _::_(InputChar 'o') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'o'))) ::' rest , 2)
len-dec-rewrite {- P19-} ((Id "P19") :: _::_(InputChar 'p') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'p'))) ::' rest , 2)
len-dec-rewrite {- P2-} ((Id "P2") :: (ParseTree (parsed-anychar x0)) :: _::_(ParseTree (parsed-path-star-1 x1)) rest) = just (ParseTree (parsed-path-star-1 (string-append 1 x0 x1)) ::' rest , 3)
len-dec-rewrite {- P20-} ((Id "P20") :: _::_(InputChar 'q') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'q'))) ::' rest , 2)
len-dec-rewrite {- P21-} ((Id "P21") :: _::_(InputChar 'r') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'r'))) ::' rest , 2)
len-dec-rewrite {- P22-} ((Id "P22") :: _::_(InputChar 's') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 's'))) ::' rest , 2)
len-dec-rewrite {- P23-} ((Id "P23") :: _::_(InputChar 't') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 't'))) ::' rest , 2)
len-dec-rewrite {- P24-} ((Id "P24") :: _::_(InputChar 'u') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'u'))) ::' rest , 2)
len-dec-rewrite {- P25-} ((Id "P25") :: _::_(InputChar 'v') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'v'))) ::' rest , 2)
len-dec-rewrite {- P26-} ((Id "P26") :: _::_(InputChar 'w') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'w'))) ::' rest , 2)
len-dec-rewrite {- P27-} ((Id "P27") :: _::_(InputChar 'x') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'x'))) ::' rest , 2)
len-dec-rewrite {- P28-} ((Id "P28") :: _::_(InputChar 'y') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'y'))) ::' rest , 2)
len-dec-rewrite {- P29-} ((Id "P29") :: _::_(InputChar 'z') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'z'))) ::' rest , 2)
len-dec-rewrite {- P3-} ((Id "P3") :: (ParseTree parsed-squote) :: (ParseTree (parsed-path-star-1 x0)) :: _::_(ParseTree parsed-squote) rest) = just (ParseTree (parsed-path (string-append 0 x0)) ::' rest , 4)
len-dec-rewrite {- P30-} ((Id "P30") :: _::_(InputChar 'A') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'A'))) ::' rest , 2)
len-dec-rewrite {- P31-} ((Id "P31") :: _::_(InputChar 'B') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'B'))) ::' rest , 2)
len-dec-rewrite {- P32-} ((Id "P32") :: _::_(InputChar 'C') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'C'))) ::' rest , 2)
len-dec-rewrite {- P33-} ((Id "P33") :: _::_(InputChar 'D') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'D'))) ::' rest , 2)
len-dec-rewrite {- P34-} ((Id "P34") :: _::_(InputChar 'E') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'E'))) ::' rest , 2)
len-dec-rewrite {- P35-} ((Id "P35") :: _::_(InputChar 'F') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'F'))) ::' rest , 2)
len-dec-rewrite {- P36-} ((Id "P36") :: _::_(InputChar 'G') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'G'))) ::' rest , 2)
len-dec-rewrite {- P37-} ((Id "P37") :: _::_(InputChar 'H') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'H'))) ::' rest , 2)
len-dec-rewrite {- P38-} ((Id "P38") :: _::_(InputChar 'I') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'I'))) ::' rest , 2)
len-dec-rewrite {- P39-} ((Id "P39") :: _::_(InputChar 'J') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'J'))) ::' rest , 2)
len-dec-rewrite {- P4-} ((Id "P4") :: _::_(InputChar 'a') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'a'))) ::' rest , 2)
len-dec-rewrite {- P40-} ((Id "P40") :: _::_(InputChar 'K') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'K'))) ::' rest , 2)
len-dec-rewrite {- P41-} ((Id "P41") :: _::_(InputChar 'L') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'L'))) ::' rest , 2)
len-dec-rewrite {- P42-} ((Id "P42") :: _::_(InputChar 'M') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'M'))) ::' rest , 2)
len-dec-rewrite {- P43-} ((Id "P43") :: _::_(InputChar 'N') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'N'))) ::' rest , 2)
len-dec-rewrite {- P44-} ((Id "P44") :: _::_(InputChar 'O') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'O'))) ::' rest , 2)
len-dec-rewrite {- P45-} ((Id "P45") :: _::_(InputChar 'P') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'P'))) ::' rest , 2)
len-dec-rewrite {- P46-} ((Id "P46") :: _::_(InputChar 'Q') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'Q'))) ::' rest , 2)
len-dec-rewrite {- P47-} ((Id "P47") :: _::_(InputChar 'R') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'R'))) ::' rest , 2)
len-dec-rewrite {- P48-} ((Id "P48") :: _::_(InputChar 'S') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'S'))) ::' rest , 2)
len-dec-rewrite {- P49-} ((Id "P49") :: _::_(InputChar 'T') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'T'))) ::' rest , 2)
len-dec-rewrite {- P5-} ((Id "P5") :: _::_(InputChar 'b') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'b'))) ::' rest , 2)
len-dec-rewrite {- P50-} ((Id "P50") :: _::_(InputChar 'U') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'U'))) ::' rest , 2)
len-dec-rewrite {- P51-} ((Id "P51") :: _::_(InputChar 'V') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'V'))) ::' rest , 2)
len-dec-rewrite {- P52-} ((Id "P52") :: _::_(InputChar 'W') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'W'))) ::' rest , 2)
len-dec-rewrite {- P53-} ((Id "P53") :: _::_(InputChar 'X') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'X'))) ::' rest , 2)
len-dec-rewrite {- P54-} ((Id "P54") :: _::_(InputChar 'Y') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'Y'))) ::' rest , 2)
len-dec-rewrite {- P55-} ((Id "P55") :: _::_(InputChar 'Z') rest) = just (ParseTree (parsed-alpha-range-3 (string-append 0 (char-to-string 'Z'))) ::' rest , 2)
len-dec-rewrite {- P56-} ((Id "P56") :: _::_(ParseTree (parsed-alpha-range-2 x0)) rest) = just (ParseTree (parsed-alpha-bar-4 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P57-} ((Id "P57") :: _::_(ParseTree (parsed-alpha-range-3 x0)) rest) = just (ParseTree (parsed-alpha-bar-4 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P58-} ((Id "P58") :: _::_(ParseTree (parsed-alpha-bar-4 x0)) rest) = just (ParseTree (parsed-alpha (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P59-} ((Id "P59") :: _::_(InputChar '0') rest) = just (ParseTree (parsed-numone-range-5 (string-append 0 (char-to-string '0'))) ::' rest , 2)
len-dec-rewrite {- P6-} ((Id "P6") :: _::_(InputChar 'c') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'c'))) ::' rest , 2)
len-dec-rewrite {- P60-} ((Id "P60") :: _::_(InputChar '1') rest) = just (ParseTree (parsed-numone-range-5 (string-append 0 (char-to-string '1'))) ::' rest , 2)
len-dec-rewrite {- P61-} ((Id "P61") :: _::_(InputChar '2') rest) = just (ParseTree (parsed-numone-range-5 (string-append 0 (char-to-string '2'))) ::' rest , 2)
len-dec-rewrite {- P62-} ((Id "P62") :: _::_(InputChar '3') rest) = just (ParseTree (parsed-numone-range-5 (string-append 0 (char-to-string '3'))) ::' rest , 2)
len-dec-rewrite {- P63-} ((Id "P63") :: _::_(InputChar '4') rest) = just (ParseTree (parsed-numone-range-5 (string-append 0 (char-to-string '4'))) ::' rest , 2)
len-dec-rewrite {- P64-} ((Id "P64") :: _::_(InputChar '5') rest) = just (ParseTree (parsed-numone-range-5 (string-append 0 (char-to-string '5'))) ::' rest , 2)
len-dec-rewrite {- P65-} ((Id "P65") :: _::_(InputChar '6') rest) = just (ParseTree (parsed-numone-range-5 (string-append 0 (char-to-string '6'))) ::' rest , 2)
len-dec-rewrite {- P66-} ((Id "P66") :: _::_(InputChar '7') rest) = just (ParseTree (parsed-numone-range-5 (string-append 0 (char-to-string '7'))) ::' rest , 2)
len-dec-rewrite {- P67-} ((Id "P67") :: _::_(InputChar '8') rest) = just (ParseTree (parsed-numone-range-5 (string-append 0 (char-to-string '8'))) ::' rest , 2)
len-dec-rewrite {- P68-} ((Id "P68") :: _::_(InputChar '9') rest) = just (ParseTree (parsed-numone-range-5 (string-append 0 (char-to-string '9'))) ::' rest , 2)
len-dec-rewrite {- P69-} ((Id "P69") :: _::_(ParseTree (parsed-numone-range-5 x0)) rest) = just (ParseTree (parsed-numone (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P7-} ((Id "P7") :: _::_(InputChar 'd') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'd'))) ::' rest , 2)
len-dec-rewrite {- P70-} ((Id "P70") :: _::_(ParseTree (parsed-numone x0)) rest) = just (ParseTree (parsed-num-plus-6 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P71-} ((Id "P71") :: (ParseTree (parsed-numone x0)) :: _::_(ParseTree (parsed-num-plus-6 x1)) rest) = just (ParseTree (parsed-num-plus-6 (string-append 1 x0 x1)) ::' rest , 3)
len-dec-rewrite {- P72-} ((Id "P72") :: _::_(ParseTree (parsed-num-plus-6 x0)) rest) = just (ParseTree (parsed-num (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P73-} ((Id "P73") :: _::_(InputChar '\'') rest) = just (ParseTree (parsed-numpunct-bar-7 (string-append 0 (char-to-string '\''))) ::' rest , 2)
len-dec-rewrite {- P74-} ((Id "P74") :: _::_(InputChar '-') rest) = just (ParseTree (parsed-numpunct-bar-7 (string-append 0 (char-to-string '-'))) ::' rest , 2)
len-dec-rewrite {- P75-} ((Id "P75") :: _::_(ParseTree (parsed-numone x0)) rest) = just (ParseTree (parsed-numpunct-bar-8 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P76-} ((Id "P76") :: _::_(ParseTree (parsed-numpunct-bar-7 x0)) rest) = just (ParseTree (parsed-numpunct-bar-8 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P77-} ((Id "P77") :: _::_(ParseTree (parsed-numpunct-bar-8 x0)) rest) = just (ParseTree (parsed-numpunct (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P78-} ((Id "P78") :: _::_(InputChar '/') rest) = just (ParseTree (parsed-anychar-bar-9 (string-append 0 (char-to-string '/'))) ::' rest , 2)
len-dec-rewrite {- P79-} ((Id "P79") :: _::_(InputChar '_') rest) = just (ParseTree (parsed-anychar-bar-9 (string-append 0 (char-to-string '_'))) ::' rest , 2)
len-dec-rewrite {- P8-} ((Id "P8") :: _::_(InputChar 'e') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'e'))) ::' rest , 2)
len-dec-rewrite {- P80-} ((Id "P80") :: _::_(InputChar '>') rest) = just (ParseTree (parsed-anychar-bar-10 (string-append 0 (char-to-string '>'))) ::' rest , 2)
len-dec-rewrite {- P81-} ((Id "P81") :: _::_(ParseTree (parsed-anychar-bar-9 x0)) rest) = just (ParseTree (parsed-anychar-bar-10 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P82-} ((Id "P82") :: _::_(InputChar '<') rest) = just (ParseTree (parsed-anychar-bar-11 (string-append 0 (char-to-string '<'))) ::' rest , 2)
len-dec-rewrite {- P83-} ((Id "P83") :: _::_(ParseTree (parsed-anychar-bar-10 x0)) rest) = just (ParseTree (parsed-anychar-bar-11 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P84-} ((Id "P84") :: _::_(InputChar '+') rest) = just (ParseTree (parsed-anychar-bar-12 (string-append 0 (char-to-string '+'))) ::' rest , 2)
len-dec-rewrite {- P85-} ((Id "P85") :: _::_(ParseTree (parsed-anychar-bar-11 x0)) rest) = just (ParseTree (parsed-anychar-bar-12 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P86-} ((Id "P86") :: _::_(InputChar '=') rest) = just (ParseTree (parsed-anychar-bar-13 (string-append 0 (char-to-string '='))) ::' rest , 2)
len-dec-rewrite {- P87-} ((Id "P87") :: _::_(ParseTree (parsed-anychar-bar-12 x0)) rest) = just (ParseTree (parsed-anychar-bar-13 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P88-} ((Id "P88") :: _::_(InputChar '-') rest) = just (ParseTree (parsed-anychar-bar-14 (string-append 0 (char-to-string '-'))) ::' rest , 2)
len-dec-rewrite {- P89-} ((Id "P89") :: _::_(ParseTree (parsed-anychar-bar-13 x0)) rest) = just (ParseTree (parsed-anychar-bar-14 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P9-} ((Id "P9") :: _::_(InputChar 'f') rest) = just (ParseTree (parsed-alpha-range-2 (string-append 0 (char-to-string 'f'))) ::' rest , 2)
len-dec-rewrite {- P90-} ((Id "P90") :: _::_(InputChar '}') rest) = just (ParseTree (parsed-anychar-bar-15 (string-append 0 (char-to-string '}'))) ::' rest , 2)
len-dec-rewrite {- P91-} ((Id "P91") :: _::_(ParseTree (parsed-anychar-bar-14 x0)) rest) = just (ParseTree (parsed-anychar-bar-15 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P92-} ((Id "P92") :: _::_(InputChar '{') rest) = just (ParseTree (parsed-anychar-bar-16 (string-append 0 (char-to-string '{'))) ::' rest , 2)
len-dec-rewrite {- P93-} ((Id "P93") :: _::_(ParseTree (parsed-anychar-bar-15 x0)) rest) = just (ParseTree (parsed-anychar-bar-16 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P94-} ((Id "P94") :: _::_(InputChar '!') rest) = just (ParseTree (parsed-anychar-bar-17 (string-append 0 (char-to-string '!'))) ::' rest , 2)
len-dec-rewrite {- P95-} ((Id "P95") :: _::_(ParseTree (parsed-anychar-bar-16 x0)) rest) = just (ParseTree (parsed-anychar-bar-17 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P96-} ((Id "P96") :: _::_(InputChar ',') rest) = just (ParseTree (parsed-anychar-bar-18 (string-append 0 (char-to-string ','))) ::' rest , 2)
len-dec-rewrite {- P97-} ((Id "P97") :: _::_(ParseTree (parsed-anychar-bar-17 x0)) rest) = just (ParseTree (parsed-anychar-bar-18 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P98-} ((Id "P98") :: _::_(InputChar ']') rest) = just (ParseTree (parsed-anychar-bar-19 (string-append 0 (char-to-string ']'))) ::' rest , 2)
len-dec-rewrite {- P99-} ((Id "P99") :: _::_(ParseTree (parsed-anychar-bar-18 x0)) rest) = just (ParseTree (parsed-anychar-bar-19 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- PathsCons-} ((Id "PathsCons") :: (ParseTree parsed-ws) :: (ParseTree (parsed-path x0)) :: _::_(ParseTree (parsed-paths x1)) rest) = just (ParseTree (parsed-paths (norm-paths (PathsCons x0 x1))) ::' rest , 4)
len-dec-rewrite {- ShowQualifiedVars-} ((Id "ShowQualifiedVars") :: (InputChar 's') :: (InputChar 'h') :: (InputChar 'o') :: (InputChar 'w') :: (InputChar '-') :: (InputChar 'q') :: (InputChar 'u') :: (InputChar 'a') :: (InputChar 'l') :: (InputChar 'i') :: (InputChar 'f') :: (InputChar 'i') :: (InputChar 'e') :: (InputChar 'd') :: (InputChar '-') :: (InputChar 'v') :: (InputChar 'a') :: (InputChar 'r') :: (InputChar 's') :: (ParseTree parsed-ows) :: (InputChar '=') :: (ParseTree parsed-ows) :: (ParseTree (parsed-str-bool x0)) :: (ParseTree parsed-ows) :: (InputChar '.') :: _::_(ParseTree parsed-ows) rest) = just (ParseTree (parsed-opt (norm-opt (ShowQualifiedVars x0))) ::' rest , 27)
len-dec-rewrite {- StrBoolFalse-} ((Id "StrBoolFalse") :: (InputChar 'f') :: (InputChar 'a') :: (InputChar 'l') :: (InputChar 's') :: _::_(InputChar 'e') rest) = just (ParseTree (parsed-str-bool (norm-str-bool StrBoolFalse)) ::' rest , 6)
len-dec-rewrite {- StrBoolTrue-} ((Id "StrBoolTrue") :: (InputChar 't') :: (InputChar 'r') :: (InputChar 'u') :: _::_(InputChar 'e') rest) = just (ParseTree (parsed-str-bool (norm-str-bool StrBoolTrue)) ::' rest , 5)
len-dec-rewrite {- UseCedeFiles-} ((Id "UseCedeFiles") :: (InputChar 'u') :: (InputChar 's') :: (InputChar 'e') :: (InputChar '-') :: (InputChar 'c') :: (InputChar 'e') :: (InputChar 'd') :: (InputChar 'e') :: (InputChar '-') :: (InputChar 'f') :: (InputChar 'i') :: (InputChar 'l') :: (InputChar 'e') :: (InputChar 's') :: (ParseTree parsed-ows) :: (InputChar '=') :: (ParseTree parsed-ows) :: (ParseTree (parsed-str-bool x0)) :: (ParseTree parsed-ows) :: (InputChar '.') :: _::_(ParseTree parsed-ows) rest) = just (ParseTree (parsed-opt (norm-opt (UseCedeFiles x0))) ::' rest , 22)
len-dec-rewrite {- OptsNil-} (_::_(Id "OptsNil") rest) = just (ParseTree (parsed-opts (norm-opts OptsNil)) ::' rest , 1)
len-dec-rewrite {- P1-} (_::_(Id "P1") rest) = just (ParseTree (parsed-path-star-1 empty-string) ::' rest , 1)
len-dec-rewrite {- P121-} (_::_(Id "P121") rest) = just (ParseTree parsed-comment-star-30 ::' rest , 1)
len-dec-rewrite {- P134-} (_::_(Id "P134") rest) = just (ParseTree parsed-ows-star-35 ::' rest , 1)
len-dec-rewrite {- PathsNil-} (_::_(Id "PathsNil") rest) = just (ParseTree (parsed-paths (norm-paths PathsNil)) ::' rest , 1)
len-dec-rewrite {- Posinfo-} (_::_(Posinfo n) rest) = just (ParseTree (parsed-posinfo (ℕ-to-string n)) ::' rest , 1)
len-dec-rewrite x = nothing
rrs : rewriteRules
rrs = record { len-dec-rewrite = len-dec-rewrite }
|
Require Import Coq.Strings.String.
Require Import Coq.Strings.Ascii.
Require Import Coq.Init.Decimal.
Open Scope list.
Fixpoint option_list_map{A B:Type}(f:A -> option B)(l:list A) : list B :=
match l with
|nil => nil
|x :: xs => match f x with
|None => (option_list_map f xs)
|Some b => b :: (option_list_map f xs)
end
end.
Open Scope string_scope.
(*if s begins with prefix, returns the rest of the string, otherwise none*)
Fixpoint clear_prefix (s prefix:string) : option string :=
match s, prefix with
| _, "" => Some s
| "", String _ _ => None
| String hd_s tl_s, String hd_p tl_p =>
if Ascii.eqb hd_s hd_p
then clear_prefix tl_s tl_p
else None
end.
Fixpoint read_uint (s:string) : option uint :=
match s with
|"" => Some Nil
|String hd tl =>
(match hd with
|"0"%char => option_map D0
|"1"%char => option_map D1
|"2"%char => option_map D2
|"3"%char => option_map D3
|"4"%char => option_map D4
|"5"%char => option_map D5
|"6"%char => option_map D6
|"7"%char => option_map D7
|"8"%char => option_map D8
|"9"%char => option_map D9
|_ => fun _:_ => None
end) (read_uint tl)
end.
Definition read_nat := fun s:_ => option_map Nat.of_uint (read_uint s).
Fixpoint split_string (s:string)(sep:ascii) : list string :=
match s with
|"" => nil
|String hd tl => if Ascii.eqb hd sep
then "" :: (split_string tl sep)
else match (split_string tl sep) with
|nil => (String hd "") :: nil
|cons x xs => (String hd x) :: xs
end
end.
Inductive sub_instruction : Set :=
up : nat -> sub_instruction
|down : nat -> sub_instruction
|forward : nat -> sub_instruction.
Definition read_sub_instruction(s:string) : option sub_instruction.
destruct (clear_prefix s "up ").
destruct (read_nat s0).
apply (Some (up n)).
apply None.
destruct (clear_prefix s "down ").
destruct (read_nat s0).
apply (Some (down n)).
apply None.
destruct (clear_prefix s "forward ").
destruct (read_nat s0).
apply (Some (forward n)).
apply None.
apply None.
Optimize Proof.
Defined.
Require Import Coq.ZArith.ZArith.
Open Scope Z.
Open Scope list.
Fixpoint find_position (course : list sub_instruction) : Z*Z :=
match course with
|nil => (0, 0)
|x :: xs => match (find_position xs) with
|(n, m) => match x with
|up k => (n, m - (BinIntDef.Z.of_nat k))
|down k => (n, m + (BinIntDef.Z.of_nat k))
|forward k => (n + (BinIntDef.Z.of_nat k), m)
end
end
end.
Require Import Day2_puzzle_input.
Compute (fun p:Z*Z => match p with |(n, m) => n * m end) (find_position (option_list_map read_sub_instruction (split_string Day2_puzzle_input "010"%char))).
Fixpoint find_position_aim_helper (course : list sub_instruction)(hor depth aim:Z) : Z*Z*Z :=
match course with
|nil => (hor, depth, aim)
|x :: xs => let p := match x with
|up k => (0, 0, - (BinIntDef.Z.of_nat k))
|down k => (0, 0, BinIntDef.Z.of_nat k)
|forward k => ((BinIntDef.Z.of_nat k), aim * (BinIntDef.Z.of_nat k), 0)
end in
match p with
|(hor_delta, depth_delta, aim_delta) => find_position_aim_helper xs (hor + hor_delta) (depth + depth_delta) (aim + aim_delta)
end
end.
Definition find_position_aim (course : list sub_instruction) : Z*Z*Z := find_position_aim_helper course 0 0 0.
Compute (fun p:Z*Z*Z => match p with |(n, m, _) => n * m end) (find_position_aim (option_list_map read_sub_instruction (split_string Day2_puzzle_input "010"%char))).
|
function w = moments_normal_01 ( m )
%*****************************************************************************80
%
%% MOMENTS_NORMAL_01 returns moments of the standard Normal distribution.
%
% Discussion:
%
% pdf(x) = exp ( -x^2/2 ) / sqrt ( pi * 2 )
% mu(k) = integral ( -oo < x < +oo ) x^k pdf(x) dx
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 15 September 2013
%
% Author:
%
% John Burkardt
%
% Parameters:
%
% Input, integer M, the number of moments desired.
%
% Output, real W(M), the weighted integrals of X^0 through X^(M-1).
%
w = zeros ( m, 1 );
w(1) = 1.0;
for k = 3 : 2: m
w(k) = r8_factorial2 ( k - 2 );
end
for k = 2 : 2 : m
w(k) = 0.0;
end
return
end
|
[STATEMENT]
lemma LIMSEQ_le_const2: "X \<longlonglongrightarrow> x \<Longrightarrow> \<exists>N. \<forall>n\<ge>N. X n \<le> a \<Longrightarrow> x \<le> a"
for a x :: "'a::linorder_topology"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<lbrakk>X \<longlonglongrightarrow> x; \<exists>N. \<forall>n\<ge>N. X n \<le> a\<rbrakk> \<Longrightarrow> x \<le> a
[PROOF STEP]
by (rule LIMSEQ_le[of X x "\<lambda>n. a"]) auto |
State Before: R : Type u
S : Type v
a b : R
n✝ m : ℕ
inst✝ : Semiring R
p✝ q r p : R[X]
n : ℕ
h : n < natTrailingDegree p
⊢ coeff p n = 0 State After: case h
R : Type u
S : Type v
a b : R
n✝ m : ℕ
inst✝ : Semiring R
p✝ q r p : R[X]
n : ℕ
h : n < natTrailingDegree p
⊢ ↑n < trailingDegree p Tactic: apply coeff_eq_zero_of_trailingDegree_lt State Before: case h
R : Type u
S : Type v
a b : R
n✝ m : ℕ
inst✝ : Semiring R
p✝ q r p : R[X]
n : ℕ
h : n < natTrailingDegree p
⊢ ↑n < trailingDegree p State After: case pos
R : Type u
S : Type v
a b : R
n✝ m : ℕ
inst✝ : Semiring R
p✝ q r p : R[X]
n : ℕ
h : n < natTrailingDegree p
hp : p = 0
⊢ ↑n < trailingDegree p
case neg
R : Type u
S : Type v
a b : R
n✝ m : ℕ
inst✝ : Semiring R
p✝ q r p : R[X]
n : ℕ
h : n < natTrailingDegree p
hp : ¬p = 0
⊢ ↑n < trailingDegree p Tactic: by_cases hp : p = 0 State Before: case pos
R : Type u
S : Type v
a b : R
n✝ m : ℕ
inst✝ : Semiring R
p✝ q r p : R[X]
n : ℕ
h : n < natTrailingDegree p
hp : p = 0
⊢ ↑n < trailingDegree p State After: case pos
R : Type u
S : Type v
a b : R
n✝ m : ℕ
inst✝ : Semiring R
p✝ q r p : R[X]
n : ℕ
h : n < natTrailingDegree p
hp : p = 0
⊢ ↑n < ⊤ Tactic: rw [hp, trailingDegree_zero] State Before: case pos
R : Type u
S : Type v
a b : R
n✝ m : ℕ
inst✝ : Semiring R
p✝ q r p : R[X]
n : ℕ
h : n < natTrailingDegree p
hp : p = 0
⊢ ↑n < ⊤ State After: no goals Tactic: exact WithTop.coe_lt_top n State Before: case neg
R : Type u
S : Type v
a b : R
n✝ m : ℕ
inst✝ : Semiring R
p✝ q r p : R[X]
n : ℕ
h : n < natTrailingDegree p
hp : ¬p = 0
⊢ ↑n < trailingDegree p State After: case neg
R : Type u
S : Type v
a b : R
n✝ m : ℕ
inst✝ : Semiring R
p✝ q r p : R[X]
n : ℕ
h : n < natTrailingDegree p
hp : ¬p = 0
⊢ ↑n < ↑(natTrailingDegree p) Tactic: rw [trailingDegree_eq_natTrailingDegree hp] State Before: case neg
R : Type u
S : Type v
a b : R
n✝ m : ℕ
inst✝ : Semiring R
p✝ q r p : R[X]
n : ℕ
h : n < natTrailingDegree p
hp : ¬p = 0
⊢ ↑n < ↑(natTrailingDegree p) State After: no goals Tactic: exact WithTop.coe_lt_coe.2 h |
[GOAL]
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : LinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
s : Set α
a : α
h_mono : StrictMonoOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : ∀ (b : β), b > f a → ∃ c, c ∈ s ∧ f c ∈ Ioc (f a) b
⊢ ContinuousWithinAt f (Ici a) a
[PROOFSTEP]
have ha : a ∈ Ici a := left_mem_Ici
[GOAL]
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : LinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
s : Set α
a : α
h_mono : StrictMonoOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : ∀ (b : β), b > f a → ∃ c, c ∈ s ∧ f c ∈ Ioc (f a) b
ha : a ∈ Ici a
⊢ ContinuousWithinAt f (Ici a) a
[PROOFSTEP]
have has : a ∈ s := mem_of_mem_nhdsWithin ha hs
[GOAL]
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : LinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
s : Set α
a : α
h_mono : StrictMonoOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : ∀ (b : β), b > f a → ∃ c, c ∈ s ∧ f c ∈ Ioc (f a) b
ha : a ∈ Ici a
has : a ∈ s
⊢ ContinuousWithinAt f (Ici a) a
[PROOFSTEP]
refine' tendsto_order.2 ⟨fun b hb => _, fun b hb => _⟩
[GOAL]
case refine'_1
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : LinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
s : Set α
a : α
h_mono : StrictMonoOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : ∀ (b : β), b > f a → ∃ c, c ∈ s ∧ f c ∈ Ioc (f a) b
ha : a ∈ Ici a
has : a ∈ s
b : β
hb : b < f a
⊢ ∀ᶠ (b_1 : α) in 𝓝[Ici a] a, b < f b_1
[PROOFSTEP]
filter_upwards [hs, @self_mem_nhdsWithin _ _ a (Ici a)] with _ hxs hxa using
hb.trans_le ((h_mono.le_iff_le has hxs).2 hxa)
[GOAL]
case refine'_2
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : LinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
s : Set α
a : α
h_mono : StrictMonoOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : ∀ (b : β), b > f a → ∃ c, c ∈ s ∧ f c ∈ Ioc (f a) b
ha : a ∈ Ici a
has : a ∈ s
b : β
hb : b > f a
⊢ ∀ᶠ (b_1 : α) in 𝓝[Ici a] a, f b_1 < b
[PROOFSTEP]
rcases hfs b hb with ⟨c, hcs, hac, hcb⟩
[GOAL]
case refine'_2.intro.intro.intro
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : LinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
s : Set α
a : α
h_mono : StrictMonoOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : ∀ (b : β), b > f a → ∃ c, c ∈ s ∧ f c ∈ Ioc (f a) b
ha : a ∈ Ici a
has : a ∈ s
b : β
hb : b > f a
c : α
hcs : c ∈ s
hac : f a < f c
hcb : f c ≤ b
⊢ ∀ᶠ (b_1 : α) in 𝓝[Ici a] a, f b_1 < b
[PROOFSTEP]
rw [h_mono.lt_iff_lt has hcs] at hac
[GOAL]
case refine'_2.intro.intro.intro
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : LinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
s : Set α
a : α
h_mono : StrictMonoOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : ∀ (b : β), b > f a → ∃ c, c ∈ s ∧ f c ∈ Ioc (f a) b
ha : a ∈ Ici a
has : a ∈ s
b : β
hb : b > f a
c : α
hcs : c ∈ s
hac : a < c
hcb : f c ≤ b
⊢ ∀ᶠ (b_1 : α) in 𝓝[Ici a] a, f b_1 < b
[PROOFSTEP]
filter_upwards [hs, Ico_mem_nhdsWithin_Ici (left_mem_Ico.2 hac)]
[GOAL]
case h
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : LinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
s : Set α
a : α
h_mono : StrictMonoOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : ∀ (b : β), b > f a → ∃ c, c ∈ s ∧ f c ∈ Ioc (f a) b
ha : a ∈ Ici a
has : a ∈ s
b : β
hb : b > f a
c : α
hcs : c ∈ s
hac : a < c
hcb : f c ≤ b
⊢ ∀ (a_1 : α), a_1 ∈ s → a_1 ∈ Ico a c → f a_1 < b
[PROOFSTEP]
rintro x hx ⟨_, hxc⟩
[GOAL]
case h.intro
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : LinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
s : Set α
a : α
h_mono : StrictMonoOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : ∀ (b : β), b > f a → ∃ c, c ∈ s ∧ f c ∈ Ioc (f a) b
ha : a ∈ Ici a
has : a ∈ s
b : β
hb : b > f a
c : α
hcs : c ∈ s
hac : a < c
hcb : f c ≤ b
x : α
hx : x ∈ s
left✝ : a ≤ x
hxc : x < c
⊢ f x < b
[PROOFSTEP]
exact ((h_mono.lt_iff_lt hx hcs).2 hxc).trans_le hcb
[GOAL]
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : LinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
s : Set α
a : α
h_mono : MonotoneOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : ∀ (b : β), b > f a → ∃ c, c ∈ s ∧ f c ∈ Ioo (f a) b
⊢ ContinuousWithinAt f (Ici a) a
[PROOFSTEP]
have ha : a ∈ Ici a := left_mem_Ici
[GOAL]
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : LinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
s : Set α
a : α
h_mono : MonotoneOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : ∀ (b : β), b > f a → ∃ c, c ∈ s ∧ f c ∈ Ioo (f a) b
ha : a ∈ Ici a
⊢ ContinuousWithinAt f (Ici a) a
[PROOFSTEP]
have has : a ∈ s := mem_of_mem_nhdsWithin ha hs
[GOAL]
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : LinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
s : Set α
a : α
h_mono : MonotoneOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : ∀ (b : β), b > f a → ∃ c, c ∈ s ∧ f c ∈ Ioo (f a) b
ha : a ∈ Ici a
has : a ∈ s
⊢ ContinuousWithinAt f (Ici a) a
[PROOFSTEP]
refine' tendsto_order.2 ⟨fun b hb => _, fun b hb => _⟩
[GOAL]
case refine'_1
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : LinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
s : Set α
a : α
h_mono : MonotoneOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : ∀ (b : β), b > f a → ∃ c, c ∈ s ∧ f c ∈ Ioo (f a) b
ha : a ∈ Ici a
has : a ∈ s
b : β
hb : b < f a
⊢ ∀ᶠ (b_1 : α) in 𝓝[Ici a] a, b < f b_1
[PROOFSTEP]
filter_upwards [hs, @self_mem_nhdsWithin _ _ a (Ici a)] with _ hxs hxa using hb.trans_le (h_mono has hxs hxa)
[GOAL]
case refine'_2
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : LinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
s : Set α
a : α
h_mono : MonotoneOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : ∀ (b : β), b > f a → ∃ c, c ∈ s ∧ f c ∈ Ioo (f a) b
ha : a ∈ Ici a
has : a ∈ s
b : β
hb : b > f a
⊢ ∀ᶠ (b_1 : α) in 𝓝[Ici a] a, f b_1 < b
[PROOFSTEP]
rcases hfs b hb with ⟨c, hcs, hac, hcb⟩
[GOAL]
case refine'_2.intro.intro.intro
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : LinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
s : Set α
a : α
h_mono : MonotoneOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : ∀ (b : β), b > f a → ∃ c, c ∈ s ∧ f c ∈ Ioo (f a) b
ha : a ∈ Ici a
has : a ∈ s
b : β
hb : b > f a
c : α
hcs : c ∈ s
hac : f a < f c
hcb : f c < b
⊢ ∀ᶠ (b_1 : α) in 𝓝[Ici a] a, f b_1 < b
[PROOFSTEP]
have : a < c := not_le.1 fun h => hac.not_le <| h_mono hcs has h
[GOAL]
case refine'_2.intro.intro.intro
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : LinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
s : Set α
a : α
h_mono : MonotoneOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : ∀ (b : β), b > f a → ∃ c, c ∈ s ∧ f c ∈ Ioo (f a) b
ha : a ∈ Ici a
has : a ∈ s
b : β
hb : b > f a
c : α
hcs : c ∈ s
hac : f a < f c
hcb : f c < b
this : a < c
⊢ ∀ᶠ (b_1 : α) in 𝓝[Ici a] a, f b_1 < b
[PROOFSTEP]
filter_upwards [hs, Ico_mem_nhdsWithin_Ici (left_mem_Ico.2 this)]
[GOAL]
case h
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : LinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
s : Set α
a : α
h_mono : MonotoneOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : ∀ (b : β), b > f a → ∃ c, c ∈ s ∧ f c ∈ Ioo (f a) b
ha : a ∈ Ici a
has : a ∈ s
b : β
hb : b > f a
c : α
hcs : c ∈ s
hac : f a < f c
hcb : f c < b
this : a < c
⊢ ∀ (a_1 : α), a_1 ∈ s → a_1 ∈ Ico a c → f a_1 < b
[PROOFSTEP]
rintro x hx ⟨_, hxc⟩
[GOAL]
case h.intro
α : Type u_1
β : Type u_2
inst✝⁵ : LinearOrder α
inst✝⁴ : TopologicalSpace α
inst✝³ : OrderTopology α
inst✝² : LinearOrder β
inst✝¹ : TopologicalSpace β
inst✝ : OrderTopology β
f : α → β
s : Set α
a : α
h_mono : MonotoneOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : ∀ (b : β), b > f a → ∃ c, c ∈ s ∧ f c ∈ Ioo (f a) b
ha : a ∈ Ici a
has : a ∈ s
b : β
hb : b > f a
c : α
hcs : c ∈ s
hac : f a < f c
hcb : f c < b
this : a < c
x : α
hx : x ∈ s
left✝ : a ≤ x
hxc : x < c
⊢ f x < b
[PROOFSTEP]
exact (h_mono hx hcs hxc.le).trans_lt hcb
[GOAL]
α : Type u_1
β : Type u_2
inst✝⁶ : LinearOrder α
inst✝⁵ : TopologicalSpace α
inst✝⁴ : OrderTopology α
inst✝³ : LinearOrder β
inst✝² : TopologicalSpace β
inst✝¹ : OrderTopology β
inst✝ : DenselyOrdered β
f : α → β
s : Set α
a : α
h_mono : MonotoneOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : closure (f '' s) ∈ 𝓝[Ici (f a)] f a
⊢ ContinuousWithinAt f (Ici a) a
[PROOFSTEP]
refine' continuousWithinAt_right_of_monotoneOn_of_exists_between h_mono hs fun b hb => _
[GOAL]
α : Type u_1
β : Type u_2
inst✝⁶ : LinearOrder α
inst✝⁵ : TopologicalSpace α
inst✝⁴ : OrderTopology α
inst✝³ : LinearOrder β
inst✝² : TopologicalSpace β
inst✝¹ : OrderTopology β
inst✝ : DenselyOrdered β
f : α → β
s : Set α
a : α
h_mono : MonotoneOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : closure (f '' s) ∈ 𝓝[Ici (f a)] f a
b : β
hb : b > f a
⊢ ∃ c, c ∈ s ∧ f c ∈ Ioo (f a) b
[PROOFSTEP]
rcases(mem_nhdsWithin_Ici_iff_exists_mem_Ioc_Ico_subset hb).1 hfs with ⟨b', ⟨hab', hbb'⟩, hb'⟩
[GOAL]
case intro.intro.intro
α : Type u_1
β : Type u_2
inst✝⁶ : LinearOrder α
inst✝⁵ : TopologicalSpace α
inst✝⁴ : OrderTopology α
inst✝³ : LinearOrder β
inst✝² : TopologicalSpace β
inst✝¹ : OrderTopology β
inst✝ : DenselyOrdered β
f : α → β
s : Set α
a : α
h_mono : MonotoneOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : closure (f '' s) ∈ 𝓝[Ici (f a)] f a
b : β
hb : b > f a
b' : β
hb' : Ico (f a) b' ⊆ closure (f '' s)
hab' : f a < b'
hbb' : b' ≤ b
⊢ ∃ c, c ∈ s ∧ f c ∈ Ioo (f a) b
[PROOFSTEP]
rcases exists_between hab' with ⟨c', hc'⟩
[GOAL]
case intro.intro.intro.intro
α : Type u_1
β : Type u_2
inst✝⁶ : LinearOrder α
inst✝⁵ : TopologicalSpace α
inst✝⁴ : OrderTopology α
inst✝³ : LinearOrder β
inst✝² : TopologicalSpace β
inst✝¹ : OrderTopology β
inst✝ : DenselyOrdered β
f : α → β
s : Set α
a : α
h_mono : MonotoneOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : closure (f '' s) ∈ 𝓝[Ici (f a)] f a
b : β
hb : b > f a
b' : β
hb' : Ico (f a) b' ⊆ closure (f '' s)
hab' : f a < b'
hbb' : b' ≤ b
c' : β
hc' : f a < c' ∧ c' < b'
⊢ ∃ c, c ∈ s ∧ f c ∈ Ioo (f a) b
[PROOFSTEP]
rcases mem_closure_iff.1 (hb' ⟨hc'.1.le, hc'.2⟩) (Ioo (f a) b') isOpen_Ioo hc' with ⟨_, hc, ⟨c, hcs, rfl⟩⟩
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro
α : Type u_1
β : Type u_2
inst✝⁶ : LinearOrder α
inst✝⁵ : TopologicalSpace α
inst✝⁴ : OrderTopology α
inst✝³ : LinearOrder β
inst✝² : TopologicalSpace β
inst✝¹ : OrderTopology β
inst✝ : DenselyOrdered β
f : α → β
s : Set α
a : α
h_mono : MonotoneOn f s
hs : s ∈ 𝓝[Ici a] a
hfs : closure (f '' s) ∈ 𝓝[Ici (f a)] f a
b : β
hb : b > f a
b' : β
hb' : Ico (f a) b' ⊆ closure (f '' s)
hab' : f a < b'
hbb' : b' ≤ b
c' : β
hc' : f a < c' ∧ c' < b'
c : α
hcs : c ∈ s
hc : f c ∈ Ioo (f a) b'
⊢ ∃ c, c ∈ s ∧ f c ∈ Ioo (f a) b
[PROOFSTEP]
exact ⟨c, hcs, hc.1, hc.2.trans_le hbb'⟩
[GOAL]
α : Type u_1
β : Type u_2
inst✝⁶ : LinearOrder α
inst✝⁵ : TopologicalSpace α
inst✝⁴ : OrderTopology α
inst✝³ : LinearOrder β
inst✝² : TopologicalSpace β
inst✝¹ : OrderTopology β
inst✝ : DenselyOrdered β
f : α → β
h_mono : Monotone f
h_dense : DenseRange f
a : α
⊢ closure (f '' univ) ∈ 𝓝 (f a)
[PROOFSTEP]
simp only [image_univ, h_dense.closure_eq, univ_mem]
[GOAL]
α : Type u_1
β : Type u_2
inst✝⁵ : PartialOrder α
inst✝⁴ : PartialOrder β
inst✝³ : TopologicalSpace α
inst✝² : TopologicalSpace β
inst✝¹ : OrderTopology α
inst✝ : OrderTopology β
e : α ≃o β
⊢ Continuous ↑e
[PROOFSTEP]
rw [‹OrderTopology β›.topology_eq_generate_intervals]
[GOAL]
α : Type u_1
β : Type u_2
inst✝⁵ : PartialOrder α
inst✝⁴ : PartialOrder β
inst✝³ : TopologicalSpace α
inst✝² : TopologicalSpace β
inst✝¹ : OrderTopology α
inst✝ : OrderTopology β
e : α ≃o β
⊢ Continuous ↑e
[PROOFSTEP]
refine' continuous_generateFrom fun s hs => _
[GOAL]
α : Type u_1
β : Type u_2
inst✝⁵ : PartialOrder α
inst✝⁴ : PartialOrder β
inst✝³ : TopologicalSpace α
inst✝² : TopologicalSpace β
inst✝¹ : OrderTopology α
inst✝ : OrderTopology β
e : α ≃o β
s : Set β
hs : s ∈ {s | ∃ a, s = Ioi a ∨ s = Iio a}
⊢ IsOpen (↑e ⁻¹' s)
[PROOFSTEP]
rcases hs with ⟨a, rfl | rfl⟩
[GOAL]
case intro.inl
α : Type u_1
β : Type u_2
inst✝⁵ : PartialOrder α
inst✝⁴ : PartialOrder β
inst✝³ : TopologicalSpace α
inst✝² : TopologicalSpace β
inst✝¹ : OrderTopology α
inst✝ : OrderTopology β
e : α ≃o β
a : β
⊢ IsOpen (↑e ⁻¹' Ioi a)
[PROOFSTEP]
rw [e.preimage_Ioi]
[GOAL]
case intro.inl
α : Type u_1
β : Type u_2
inst✝⁵ : PartialOrder α
inst✝⁴ : PartialOrder β
inst✝³ : TopologicalSpace α
inst✝² : TopologicalSpace β
inst✝¹ : OrderTopology α
inst✝ : OrderTopology β
e : α ≃o β
a : β
⊢ IsOpen (Ioi (↑(symm e) a))
[PROOFSTEP]
apply isOpen_lt'
[GOAL]
case intro.inr
α : Type u_1
β : Type u_2
inst✝⁵ : PartialOrder α
inst✝⁴ : PartialOrder β
inst✝³ : TopologicalSpace α
inst✝² : TopologicalSpace β
inst✝¹ : OrderTopology α
inst✝ : OrderTopology β
e : α ≃o β
a : β
⊢ IsOpen (↑e ⁻¹' Iio a)
[PROOFSTEP]
rw [e.preimage_Iio]
[GOAL]
case intro.inr
α : Type u_1
β : Type u_2
inst✝⁵ : PartialOrder α
inst✝⁴ : PartialOrder β
inst✝³ : TopologicalSpace α
inst✝² : TopologicalSpace β
inst✝¹ : OrderTopology α
inst✝ : OrderTopology β
e : α ≃o β
a : β
⊢ IsOpen (Iio (↑(symm e) a))
[PROOFSTEP]
apply isOpen_gt'
|
[STATEMENT]
lemma sim_while_cong: "c \<sim> c' \<Longrightarrow> WHILE b DO c \<sim> WHILE b DO c'"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. c \<sim> c' \<Longrightarrow> WHILE b DO c \<sim> WHILE b DO c'
[PROOF STEP]
by (metis sim_while_cong_aux) |
||| Spec: https://webassembly.github.io/spec/core/syntax/types.html#table-types
module WebAssembly.Structure.Types.TableTypes
import WebAssembly.Structure.Types.Limits
import Decidable.Equality
-- Definition
public export
data ElemType : Type where
FuncRef : ElemType
public export
TableType : Type
TableType = (Limits, ElemType)
-- Equality
-- Decidable Equality
public export
implementation DecEq ElemType where
decEq FuncRef FuncRef = Yes Refl
|
function mpc = case9target
%CASE9TARGET Target injection power flow data for 9 bus, 3 generator case.
% Please see CASEFORMAT for details on the case file format.
%
% Modified version of case9.m used as target for example CPF.
% MATPOWER
%% MATPOWER Case Format : Version 2
mpc.version = '2';
%%----- Power Flow Data -----%%
%% system MVA base
mpc.baseMVA = 100;
%% bus data
% bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin
mpc.bus = [
1 3 0 0 0 0 1 1 0 345 1 1.1 0.9;
2 2 0 0 0 0 1 1 0 345 1 1.1 0.9;
3 2 0 0 0 0 1 1 0 345 1 1.1 0.9;
4 1 0 0 0 0 1 1 0 345 1 1.1 0.9;
5 1 305.4 123.15 0 0 1 1 0 345 1 1.1 0.9;
6 1 0 0 0 0 1 1 0 345 1 1.1 0.9;
7 1 214.11 71.09 0 0 1 1 0 345 1 1.1 0.9;
8 1 0 0 0 0 1 1 0 345 1 1.1 0.9;
9 1 235.61 81.44 0 0 1 1 0 345 1 1.1 0.9;
];
%% generator data
% bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf
mpc.gen = [
1 72.3 27.03 300 -300 1.04 100 1 250 10 0 0 0 0 0 0 0 0 0 0 0;
2 248 0 300 -300 1.025 100 1 300 10 0 0 0 0 0 0 0 0 0 0 0;
3 124.59 0 300 -300 1.025 100 1 270 10 0 0 0 0 0 0 0 0 0 0 0;
];
%% branch data
% fbus tbus r x b rateA rateB rateC ratio angle status angmin angmax
mpc.branch = [
1 4 0 0.0576 0 250 250 250 0 0 1 -360 360;
4 5 0.017 0.092 0.158 250 250 250 0 0 1 -360 360;
5 6 0.039 0.17 0.358 150 150 150 0 0 1 -360 360;
3 6 0 0.0586 0 300 300 300 0 0 1 -360 360;
6 7 0.0119 0.1008 0.209 150 150 150 0 0 1 -360 360;
7 8 0.0085 0.072 0.149 250 250 250 0 0 1 -360 360;
8 2 0 0.0625 0 250 250 250 0 0 1 -360 360;
8 9 0.032 0.161 0.306 250 250 250 0 0 1 -360 360;
9 4 0.01 0.085 0.176 250 250 250 0 0 1 -360 360;
];
%%----- OPF Data -----%%
%% generator cost data
% 1 startup shutdown n x1 y1 ... xn yn
% 2 startup shutdown n c(n-1) ... c0
mpc.gencost = [
2 1500 0 3 0.11 5 150;
2 2000 0 3 0.085 1.2 600;
2 3000 0 3 0.1225 1 335;
];
|
{-# OPTIONS --cubical #-}
open import Agda.Builtin.Cubical.Path
data D : Set where
c : D
data E : Set where
c : (x y : E) → x ≡ y
postulate
A : Set
f : (x y : E) → x ≡ y → (u v : A) → u ≡ v
works : E → A
works (c x y i) = f x y (E.c x y) (works x) (works y) i
fails : E → A
fails (c x y i) = f x y ( c x y) (fails x) (fails y) i
|
! Test program for using customized calling subroutine, use
! the Rosenbrock function from driver 1, added constants
!
! CHANGES
! 21.12.2018 - Miha Polajnar
! Initial version
!
program custom1
use iso_fortran_env, only: rk => real64
use l_bfgs_b_ag, only: l_bfgs_b, optim_prob_t, lbfgsb_opt_t
implicit none
integer, parameter :: n = 2
integer :: i
type :: rconst_t
real(rk) :: a, b
end type
type(optim_prob_t) :: optim_prob
type(lbfgsb_opt_t) :: lbfgsb_opt
!
lbfgsb_opt = lbfgsb_opt_t(iprint=-200,factr=1.e7_rk,pgtol=1.e-5_rk,&
maxeval=500)
!
optim_prob%name = 'NOCEDAL EX. 17.1'
optim_prob%n = n
optim_prob%x = [(0._rk,i=1,n)]
optim_prob%nbd=[(2,i=1,n)]
allocate(optim_prob%lb(n),optim_prob%ub(n))
optim_prob%lb = [(-5.12_rk,i=1,n)]
optim_prob%ub = [(5.12_rk,i=1,n)]
optim_prob%func => nocedal_ex_17_1
optim_prob%grad => grad_nocedal_ex_17_1
optim_prob%neqc = 1
optim_prob%eq_const => nocedal_ex_17_1_eq_const
optim_prob%grad_eq_const => grad_nocedal_ex_17_1_eq_const
allocate(optim_prob%lagr(optim_prob%neqc),source=10._rk)
allocate(optim_prob%dat,source=2._rk)
! Run the algorithm
call l_bfgs_b(optim_prob,lbfgsb_opt)
contains
real(rk) pure function nocedal_ex_17_1(x,dat)
real(rk), intent(in) :: x(:)
class(*), intent(in) :: dat
nocedal_ex_17_1 = x(1) + x(2)
end function
pure subroutine grad_nocedal_ex_17_1(x,dat,grad)
real(rk), intent(in) :: x(:)
class(*), intent(in) :: dat
real(rk), intent(out) :: grad(:)
grad(1) = 1._rk
grad(2) = 1._rk
end subroutine
pure subroutine nocedal_ex_17_1_eq_const(x,dat,ce)
real(rk), intent(in) :: x(:)
class(*), intent(in) :: dat
real(rk), intent(out) :: ce(:)
select type(dat)
type is (real(rk))
ce(1) = x(1)**2 + x(2)**2 - dat
class default
error stop 'Nocedal EX. 17.1 wrong type.'
end select
end subroutine
pure subroutine grad_nocedal_ex_17_1_eq_const(x,dat,grad)
real(rk), intent(in) :: x(:)
class(*), intent(in) :: dat
real(rk), intent(out) :: grad(:,:)
grad(1,1) = 2._rk * x(1)
grad(1,2) = 2._rk * x(2)
end subroutine
end program
|
theory T168
imports Main
begin
lemma "(
(\<forall> x::nat. \<forall> y::nat. meet(x, y) = meet(y, x)) &
(\<forall> x::nat. \<forall> y::nat. join(x, y) = join(y, x)) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, meet(y, z)) = meet(meet(x, y), z)) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(x, join(y, z)) = join(join(x, y), z)) &
(\<forall> x::nat. \<forall> y::nat. meet(x, join(x, y)) = x) &
(\<forall> x::nat. \<forall> y::nat. join(x, meet(x, y)) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, join(y, z)) = join(mult(x, y), mult(x, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(join(x, y), z) = join(mult(x, z), mult(y, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, over(join(mult(x, y), z), y)) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(y, undr(x, join(mult(x, y), z))) = y) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(over(x, y), y), x) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(y, undr(y, x)), x) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(x, join(y, z)) = join(undr(x, y), undr(x, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. over(x, meet(y, z)) = join(over(x, y), over(x, z))) &
(\<forall> x::nat. \<forall> y::nat. invo(join(x, y)) = meet(invo(x), invo(y))) &
(\<forall> x::nat. \<forall> y::nat. invo(meet(x, y)) = join(invo(x), invo(y))) &
(\<forall> x::nat. invo(invo(x)) = x)
) \<longrightarrow>
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(meet(x, y), z) = join(undr(x, z), undr(y, z)))
"
nitpick[card nat=4,timeout=86400]
oops
end |
module LightClick.Types
import public Data.Vect
import public Toolkit.Data.DVect
import public Toolkit.Data.Rig
import public LightClick.Types.Meta
import public LightClick.Types.Direction
import public LightClick.Types.Sensitivity
import public LightClick.Types.WireType
%default total
public export
data Ty : MTy -> Type where
TyLogic : Ty DATA
TyArray : (type : Ty DATA) -> (length : Nat) -> Ty DATA
TyStruct : {n : Nat} -> (kvs : Vect (S n) (Pair String (Ty DATA))) -> Ty DATA
TyUnion : {n : Nat} -> (kvs : Vect (S n) (Pair String (Ty DATA))) -> Ty DATA
TyUnit : Ty UNIT
TyConn : Ty CONN
TyGate : Ty GATE
TyPort : (label : String)
-> (dir : Direction)
-> (sense: Sensitivity)
-> (wty : Wire)
-> (type : Ty DATA)
-> (usage : TyRig)
-> Ty (PORT label)
TyModule : {n : Nat}
-> {names : Vect (S n) String}
-> DVect String (Ty . PORT) (S n) names
-> Ty (MODULE names)
-- [ Accessors and ]
public export
mkDual : Ty (PORT label) -> Ty (PORT label)
mkDual (TyPort l d s w t u) with (d)
mkDual (TyPort l d s w t u) | IN = TyPort l OUT s w t u
mkDual (TyPort l d s w t u) | OUT = TyPort l IN s w t u
mkDual (TyPort l d s w t u) | INOUT = TyPort l INOUT s w t u
namespace Control
public export
mkDual : Ty (PORT label) -> Ty (PORT label)
mkDual (TyPort l d s w t u) with (d)
mkDual (TyPort l d s w t u) | IN = TyPort l OUT s Control t u
mkDual (TyPort l d s w t u) | OUT = TyPort l IN s Control t u
mkDual (TyPort l d s w t u) | INOUT = TyPort l INOUT s Control t u
getPortLabel : {label : String} -> Ty (PORT label) -> String
getPortLabel {label} p = label
export
getUsage : Ty (PORT s) -> TyRig
getUsage (TyPort label dir sense wty type usage) = usage
export
setUsage : Ty (PORT s) -> TyRig -> Ty (PORT s)
setUsage (TyPort label dir sense wty type _) = TyPort label dir sense wty type
-- [ EOF ]
|
(* Property from Productive Use of Failure in Inductive Proof,
Andrew Ireland and Alan Bundy, JAR 1996.
This Isabelle theory is produced using the TIP tool offered at the following website:
https://github.com/tip-org/tools
This file was originally provided as part of TIP benchmark at the following website:
https://github.com/tip-org/benchmarks
Yutaka Nagashima at CIIRC, CTU changed the TIP output theory file slightly
to make it compatible with Isabelle2017.*)
theory TIP_prop_20
imports "../../Test_Base"
begin
datatype 'a list = nil2 | cons2 "'a" "'a list"
datatype Nat = Z | S "Nat"
fun x :: "'a list => 'a list => 'a list" where
"x (nil2) z = z"
| "x (cons2 z2 xs) z = cons2 z2 (x xs z)"
fun length :: "'a list => Nat" where
"length (nil2) = Z"
| "length (cons2 z xs) = S (length xs)"
fun even :: "Nat => bool" where
"even (Z) = True"
| "even (S (Z)) = False"
| "even (S (S z2)) = even z2"
theorem property0 :
"even (length (x y y))"
oops
end
|
theory T88
imports Main
begin
lemma "(
(\<forall> x::nat. \<forall> y::nat. meet(x, y) = meet(y, x)) &
(\<forall> x::nat. \<forall> y::nat. join(x, y) = join(y, x)) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, meet(y, z)) = meet(meet(x, y), z)) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(x, join(y, z)) = join(join(x, y), z)) &
(\<forall> x::nat. \<forall> y::nat. meet(x, join(x, y)) = x) &
(\<forall> x::nat. \<forall> y::nat. join(x, meet(x, y)) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, join(y, z)) = join(mult(x, y), mult(x, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(join(x, y), z) = join(mult(x, z), mult(y, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, over(join(mult(x, y), z), y)) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(y, undr(x, join(mult(x, y), z))) = y) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(over(x, y), y), x) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(y, undr(y, x)), x) = x) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, meet(y, z)) = meet(mult(x, y), mult(x, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(meet(x, y), z) = meet(mult(x, z), mult(y, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. over(join(x, y), z) = join(over(x, z), over(y, z))) &
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(meet(x, y), z) = join(undr(x, z), undr(y, z))) &
(\<forall> x::nat. \<forall> y::nat. invo(join(x, y)) = meet(invo(x), invo(y))) &
(\<forall> x::nat. \<forall> y::nat. invo(meet(x, y)) = join(invo(x), invo(y))) &
(\<forall> x::nat. invo(invo(x)) = x)
) \<longrightarrow>
(\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(x, join(y, z)) = join(undr(x, y), undr(x, z)))
"
nitpick[card nat=7,timeout=86400]
oops
end |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.int.basic
import Mathlib.data.nat.cast
import Mathlib.PostPort
universes u_1 u_2
namespace Mathlib
namespace int
/- cast (injection into groups with one) -/
@[simp] theorem nat_cast_eq_coe_nat (n : ℕ) : ↑n = ↑n := sorry
/-- Coercion `ℕ → ℤ` as a `ring_hom`. -/
def of_nat_hom : ℕ →+* ℤ := ring_hom.mk coe sorry of_nat_mul sorry of_nat_add
/-- Canonical homomorphism from the integers to any ring(-like) structure `α` -/
protected def cast {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] : ℤ → α := sorry
-- see Note [coercion into rings]
protected instance cast_coe {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] : has_coe_t ℤ α :=
has_coe_t.mk int.cast
@[simp] theorem cast_zero {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] : ↑0 = 0 := rfl
theorem cast_of_nat {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] (n : ℕ) :
↑(Int.ofNat n) = ↑n :=
rfl
@[simp] theorem cast_coe_nat {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] (n : ℕ) :
↑↑n = ↑n :=
rfl
theorem cast_coe_nat' {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] (n : ℕ) : ↑↑n = ↑n :=
sorry
@[simp] theorem cast_neg_succ_of_nat {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] (n : ℕ) :
↑(Int.negSucc n) = -(↑n + 1) :=
rfl
@[simp] theorem cast_one {α : Type u_1} [add_monoid α] [HasOne α] [Neg α] : ↑1 = 1 := nat.cast_one
@[simp] theorem cast_sub_nat_nat {α : Type u_1} [add_group α] [HasOne α] (m : ℕ) (n : ℕ) :
↑(sub_nat_nat m n) = ↑m - ↑n :=
sorry
@[simp] theorem cast_neg_of_nat {α : Type u_1} [add_group α] [HasOne α] (n : ℕ) :
↑(neg_of_nat n) = -↑n :=
nat.cases_on n (idRhs (0 = -0) (Eq.symm neg_zero))
fun (n : ℕ) => idRhs (↑(neg_of_nat (n + 1)) = ↑(neg_of_nat (n + 1))) rfl
@[simp] theorem cast_add {α : Type u_1} [add_group α] [HasOne α] (m : ℤ) (n : ℤ) :
↑(m + n) = ↑m + ↑n :=
sorry
@[simp] theorem cast_neg {α : Type u_1} [add_group α] [HasOne α] (n : ℤ) : ↑(-n) = -↑n :=
int.cases_on n (fun (n : ℕ) => idRhs (↑(neg_of_nat n) = -↑n) (cast_neg_of_nat n))
fun (n : ℕ) =>
idRhs (↑(-Int.negSucc n) = --↑(-Int.negSucc n)) (Eq.symm (neg_neg ↑(-Int.negSucc n)))
@[simp] theorem cast_sub {α : Type u_1} [add_group α] [HasOne α] (m : ℤ) (n : ℤ) :
↑(m - n) = ↑m - ↑n :=
sorry
@[simp] theorem cast_mul {α : Type u_1} [ring α] (m : ℤ) (n : ℤ) : ↑(m * n) = ↑m * ↑n := sorry
/-- `coe : ℤ → α` as an `add_monoid_hom`. -/
def cast_add_hom (α : Type u_1) [add_group α] [HasOne α] : ℤ →+ α :=
add_monoid_hom.mk coe sorry cast_add
@[simp] theorem coe_cast_add_hom {α : Type u_1} [add_group α] [HasOne α] :
⇑(cast_add_hom α) = coe :=
rfl
/-- `coe : ℤ → α` as a `ring_hom`. -/
def cast_ring_hom (α : Type u_1) [ring α] : ℤ →+* α := ring_hom.mk coe sorry cast_mul sorry sorry
@[simp] theorem coe_cast_ring_hom {α : Type u_1} [ring α] : ⇑(cast_ring_hom α) = coe := rfl
theorem cast_commute {α : Type u_1} [ring α] (m : ℤ) (x : α) : commute (↑m) x :=
int.cases_on m (fun (n : ℕ) => nat.cast_commute n x)
fun (n : ℕ) => commute.neg_left (nat.cast_commute (n + 1) x)
theorem commute_cast {α : Type u_1} [ring α] (x : α) (m : ℤ) : commute x ↑m :=
commute.symm (cast_commute m x)
@[simp] theorem coe_nat_bit0 (n : ℕ) : ↑(bit0 n) = bit0 ↑n := sorry
@[simp] theorem coe_nat_bit1 (n : ℕ) : ↑(bit1 n) = bit1 ↑n := sorry
@[simp] theorem cast_bit0 {α : Type u_1} [ring α] (n : ℤ) : ↑(bit0 n) = bit0 ↑n := cast_add n n
@[simp] theorem cast_bit1 {α : Type u_1} [ring α] (n : ℤ) : ↑(bit1 n) = bit1 ↑n := sorry
theorem cast_two {α : Type u_1} [ring α] : ↑(bit0 1) = bit0 1 := sorry
theorem cast_mono {α : Type u_1} [ordered_ring α] : monotone coe := sorry
@[simp] theorem cast_nonneg {α : Type u_1} [ordered_ring α] [nontrivial α] {n : ℤ} :
0 ≤ ↑n ↔ 0 ≤ n :=
sorry
@[simp] theorem cast_le {α : Type u_1} [ordered_ring α] [nontrivial α] {m : ℤ} {n : ℤ} :
↑m ≤ ↑n ↔ m ≤ n :=
sorry
theorem cast_strict_mono {α : Type u_1} [ordered_ring α] [nontrivial α] : strict_mono coe :=
strict_mono_of_le_iff_le fun (m n : ℤ) => iff.symm cast_le
@[simp] theorem cast_lt {α : Type u_1} [ordered_ring α] [nontrivial α] {m : ℤ} {n : ℤ} :
↑m < ↑n ↔ m < n :=
strict_mono.lt_iff_lt cast_strict_mono
@[simp] theorem cast_nonpos {α : Type u_1} [ordered_ring α] [nontrivial α] {n : ℤ} :
↑n ≤ 0 ↔ n ≤ 0 :=
eq.mpr (id (Eq._oldrec (Eq.refl (↑n ≤ 0 ↔ n ≤ 0)) (Eq.symm cast_zero)))
(eq.mpr (id (Eq._oldrec (Eq.refl (↑n ≤ ↑0 ↔ n ≤ 0)) (propext cast_le))) (iff.refl (n ≤ 0)))
@[simp] theorem cast_pos {α : Type u_1} [ordered_ring α] [nontrivial α] {n : ℤ} : 0 < ↑n ↔ 0 < n :=
eq.mpr (id (Eq._oldrec (Eq.refl (0 < ↑n ↔ 0 < n)) (Eq.symm cast_zero)))
(eq.mpr (id (Eq._oldrec (Eq.refl (↑0 < ↑n ↔ 0 < n)) (propext cast_lt))) (iff.refl (0 < n)))
@[simp] theorem cast_lt_zero {α : Type u_1} [ordered_ring α] [nontrivial α] {n : ℤ} :
↑n < 0 ↔ n < 0 :=
eq.mpr (id (Eq._oldrec (Eq.refl (↑n < 0 ↔ n < 0)) (Eq.symm cast_zero)))
(eq.mpr (id (Eq._oldrec (Eq.refl (↑n < ↑0 ↔ n < 0)) (propext cast_lt))) (iff.refl (n < 0)))
@[simp] theorem cast_min {α : Type u_1} [linear_ordered_ring α] {a : ℤ} {b : ℤ} :
↑(min a b) = min ↑a ↑b :=
monotone.map_min cast_mono
@[simp] theorem cast_max {α : Type u_1} [linear_ordered_ring α] {a : ℤ} {b : ℤ} :
↑(max a b) = max ↑a ↑b :=
monotone.map_max cast_mono
@[simp] theorem cast_abs {α : Type u_1} [linear_ordered_ring α] {q : ℤ} : ↑(abs q) = abs ↑q := sorry
theorem coe_int_dvd {α : Type u_1} [comm_ring α] (m : ℤ) (n : ℤ) (h : m ∣ n) : ↑m ∣ ↑n :=
ring_hom.map_dvd (cast_ring_hom α) h
end int
namespace add_monoid_hom
/-- Two additive monoid homomorphisms `f`, `g` from `ℤ` to an additive monoid are equal
if `f 1 = g 1`. -/
theorem ext_int {A : Type u_1} [add_monoid A] {f : ℤ →+ A} {g : ℤ →+ A}
(h1 : coe_fn f 1 = coe_fn g 1) : f = g :=
sorry
theorem eq_int_cast_hom {A : Type u_1} [add_group A] [HasOne A] (f : ℤ →+ A) (h1 : coe_fn f 1 = 1) :
f = int.cast_add_hom A :=
sorry
theorem eq_int_cast {A : Type u_1} [add_group A] [HasOne A] (f : ℤ →+ A) (h1 : coe_fn f 1 = 1)
(n : ℤ) : coe_fn f n = ↑n :=
iff.mp ext_iff (eq_int_cast_hom f h1)
end add_monoid_hom
namespace monoid_hom
theorem ext_int {M : Type u_1} [monoid M] {f : multiplicative ℤ →* M} {g : multiplicative ℤ →* M}
(h1 : coe_fn f (coe_fn multiplicative.of_add 1) = coe_fn g (coe_fn multiplicative.of_add 1)) :
f = g :=
ext fun (x : multiplicative ℤ) => iff.mp add_monoid_hom.ext_iff (add_monoid_hom.ext_int h1) x
end monoid_hom
namespace ring_hom
@[simp] theorem eq_int_cast {α : Type u_1} [ring α] (f : ℤ →+* α) (n : ℤ) : coe_fn f n = ↑n :=
add_monoid_hom.eq_int_cast (to_add_monoid_hom f) (map_one f) n
theorem eq_int_cast' {α : Type u_1} [ring α] (f : ℤ →+* α) : f = int.cast_ring_hom α :=
ext (eq_int_cast f)
@[simp] theorem map_int_cast {α : Type u_1} {β : Type u_2} [ring α] [ring β] (f : α →+* β) (n : ℤ) :
coe_fn f ↑n = ↑n :=
eq_int_cast (comp f (int.cast_ring_hom α)) n
theorem ext_int {R : Type u_1} [semiring R] (f : ℤ →+* R) (g : ℤ →+* R) : f = g :=
coe_add_monoid_hom_injective (add_monoid_hom.ext_int (Eq.trans (map_one f) (Eq.symm (map_one g))))
protected instance int.subsingleton_ring_hom {R : Type u_1} [semiring R] : subsingleton (ℤ →+* R) :=
subsingleton.intro ext_int
end ring_hom
@[simp] theorem int.cast_id (n : ℤ) : ↑n = n := Eq.symm (ring_hom.eq_int_cast (ring_hom.id ℤ) n)
end Mathlib |
/* -----------------------------------------------------------------------------
* Copyright 2021 Jonathan Haigh
* SPDX-License-Identifier: MIT
* ---------------------------------------------------------------------------*/
#ifndef SQ_INCLUDE_GUARD_system_linux_udev_inl_h_
#define SQ_INCLUDE_GUARD_system_linux_udev_inl_h_
#include "core/errors.h"
#include "core/typeutil.h"
#include <fmt/format.h>
#include <gsl/gsl>
namespace sq::system::linux {
template <typename T> UdevPtr<T>::UdevPtr(SQ_MU std::nullptr_t np) noexcept {}
template <typename T>
UdevPtr<T>::UdevPtr(const UdevPtr &other) noexcept : t_{other.t_.p_} {
if (t_.p_ != nullptr) {
t_.add_ref();
}
}
template <typename T>
UdevPtr<T>::UdevPtr(UdevPtr &&other) noexcept : t_{other.t_.p_} {
other.t_.p_ = nullptr;
}
// When a raw pointer is first obtained from libudev it already has a reference
// count of 1 so we don't need to adjust it here.
template <typename T> UdevPtr<T>::UdevPtr(RawPtr p) noexcept : t_{p} {
Expects(p != nullptr);
Ensures(t_.p_ != nullptr);
}
template <typename T>
UdevPtr<T> &UdevPtr<T>::operator=(const UdevPtr &other) noexcept {
// Note: must call add_ref before remove_ref to deal with the case where
// *this == other
if (other.t_.p_ != nullptr) {
other.t_.add_ref();
}
if (t_.p_ != nullptr) {
t_.remove_ref();
}
t_.p_ = other.t_.p_;
return *this;
}
template <typename T> UdevPtr<T>::~UdevPtr() noexcept {
if (t_.p_ != nullptr) {
t_.remove_ref();
}
}
template <typename T>
UdevPtr<T> &UdevPtr<T>::operator=(UdevPtr &&other) noexcept {
std::swap(t_.p_, other.t_.p_);
return *this;
}
template <typename T> void UdevPtr<T>::reset() noexcept {
UdevPtr<T>{}.swap(*this);
}
template <typename T> void UdevPtr<T>::swap(UdevPtr &other) noexcept {
std::swap(t_.p_, other.t_.p_);
}
template <typename T> T *UdevPtr<T>::get() const noexcept {
if (t_.p_ == nullptr) {
return nullptr;
}
return &t_;
}
template <typename T> T &UdevPtr<T>::operator*() const noexcept {
Expects(t_.p_ != nullptr);
return t_;
}
template <typename T> T *UdevPtr<T>::operator->() const noexcept {
return get();
}
template <typename T> UdevPtr<T>::operator bool() const noexcept {
return t_.p_ != nullptr;
}
template <typename T>
auto UdevPtr<T>::operator<=>(const UdevPtr<T> &other) const noexcept {
return std::compare_three_way{}(t_.p_, other.t_.p_);
}
template <typename T>
bool UdevPtr<T>::operator==(const UdevPtr<T> &other) const noexcept {
return t_.p_ == other.t_.p_;
}
template <typename T>
auto UdevPtr<T>::operator<=>(std::nullptr_t np) const noexcept {
return std::compare_three_way{}(t_.p_, static_cast<decltype(t_.p_)>(np));
}
template <typename T>
bool UdevPtr<T>::operator==(std::nullptr_t np) const noexcept {
return t_.p_ == static_cast<decltype(t_.p_)>(np);
}
template <typename U, typename... Args> UdevPtr<U> make_udev(Args &&...args) {
auto *const p = U::create_new(SQ_FWD(args)...);
if (p == nullptr) {
throw UdevError{fmt::format("Failed to create new {}", base_type_name(p))};
}
return UdevPtr<U>{p};
}
} // namespace sq::system::linux
#endif // SQ_INCLUDE_GUARD_system_linux_udev_inl_h_
|
Formal statement is: lemma Reals_cnj_iff: "z \<in> \<real> \<longleftrightarrow> cnj z = z" Informal statement is: A complex number $z$ is real if and only if $z = \overline{z}$. |
[STATEMENT]
lemma isomorphic_is_subgraph_isomorphic: "G\<^sub>1 \<simeq> G\<^sub>2 \<Longrightarrow> G\<^sub>1 \<sqsubseteq> G\<^sub>2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. G\<^sub>1 \<simeq> G\<^sub>2 \<Longrightarrow> G\<^sub>1 \<sqsubseteq> G\<^sub>2
[PROOF STEP]
unfolding subgraph_isomorphic_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. G\<^sub>1 \<simeq> G\<^sub>2 \<Longrightarrow> uwellformed G\<^sub>2 \<and> (\<exists>G''. G\<^sub>1 \<simeq> G'' \<and> subgraph G'' G\<^sub>2)
[PROOF STEP]
by (metis subgraph_refl) |
Require Import compcert.lib.Coqlib.
Require Import compcert.lib.Integers.
Require Import compcert.lib.Floats.
Require Import compcert.common.Values.
Require Import compcert.common.Memory.
Require Import Coq.micromega.Lia.
Require Import VST.msl.eq_dec.
Definition address : Type := (block * Z)%type.
#[export] Instance EqDec_block: EqDec block := eq_block.
#[export] Instance EqDec_address: EqDec address.
Proof.
intros [b1 z1] [b2 z2].
destruct (eq_dec b1 b2).
destruct (Z.eq_dec z1 z2).
left; congruence.
right; congruence.
right; congruence.
Qed.
#[export] Instance EqDec_Z : EqDec Z := zeq.
#[export] Instance EqDec_int: EqDec int := Int.eq_dec.
#[export] Instance EqDec_float: EqDec float := Float.eq_dec.
#[export] Instance EqDec_float32: EqDec float32 := Float32.eq_dec.
#[export] Instance EqDec_int64: EqDec int64 := Int64.eq_dec.
#[export] Instance EqDec_ptr : EqDec ptrofs := Ptrofs.eq_dec.
#[export] Instance EqDec_val: EqDec val.
Proof.
hnf. decide equality; apply eq_dec.
Defined.
Definition adr_range (base: address) (size: Z) (loc: address) : Prop :=
match base, loc with
| (b, ofs) , (b', ofs') => b=b' /\ (ofs <= ofs' < ofs + size)
end.
Lemma adr_range_dec: forall base n loc, {adr_range base n loc} + {~adr_range base n loc}.
Proof.
unfold adr_range; intros.
destruct base as [b z]; destruct loc as [b' z'].
destruct (eq_block b b').
subst b'.
destruct (zle z z').
destruct (zlt z' (z+n)).
left; auto.
right; intros [? ?]; lia.
right; intros [? ?]; lia.
right; intros [? ?]; lia.
Qed.
(*
Definition size_chunk (chunk: memory_chunk) : Z :=
match chunk with
| Mint8signed => 1
| Mint8unsigned => 1
| Mint16signed => 2
| Mint16unsigned => 2
| Mint32 => 4
| Mfloat32 => 4
| Mfloat64 => 8
| Mfloat64al32 => 4
end.
*)
Remark size_chunk_pos:
forall chunk1, size_chunk chunk1 > 0.
Proof.
destruct chunk1; simpl; lia.
Qed.
Lemma zero_in_chunk: forall ch, 0 <= 0 < size_chunk ch.
Proof.
intros; generalize (size_chunk_pos ch); lia.
Qed.
#[export] Hint Resolve zero_in_chunk : mem.
Definition range_overlap (base1: address) (sz1: Z) (base2: address) (sz2: Z) : Prop :=
exists loc, adr_range base1 sz1 loc /\ adr_range base2 sz2 loc.
Definition adr_add (loc: address) (ofs: Z) : address := (fst loc, snd loc + ofs).
Definition val2adr (v: val) (l: address) : Prop :=
(* match v with Vptr b ofs => l = (b, Int.unsigned ofs) | _ => False end.*)
match v with Vptr b ofs => l = (b, Ptrofs.unsigned ofs) | _ => False end.
Lemma adr_range_non_zero: forall l1 n l2, adr_range l1 n l2 -> n > 0.
Proof.
intros.
unfold adr_range in H.
destruct l1, l2.
destruct (zlt 0 n); lia.
Qed.
Lemma adr_range_shift_1: forall bl ofs n l, adr_range (bl, ofs + 1) (Z.of_nat n) l -> adr_range (bl, ofs) (Z.of_nat (S n)) l.
Proof.
intros.
destruct l.
unfold adr_range in *.
rewrite Nat2Z.inj_succ.
destruct H.
repeat split; auto; lia.
Qed.
Lemma adr_range_S_split: forall bl ofs n l, adr_range (bl, ofs) (Z.of_nat (S n)) l -> adr_range (bl, ofs + 1) (Z.of_nat n) l \/ l = (bl, ofs).
Proof.
intros.
destruct l.
unfold adr_range in *.
rewrite Nat2Z.inj_succ in H.
destruct H.
subst bl.
destruct (zlt ofs z); [left | right].
+ split; auto; lia.
+ f_equal; lia.
Qed.
|
using Deprecations
using Test
@testset "Deprecations.jl" begin
# Write your own tests here.
end
|
struct ConstFactor <: AbstractFactor{UInt8}
name::String
level::String
length::Integer
end
Base.length(factor::ConstFactor) = factor.length
getlevels(factor::ConstFactor) = [factor.level]
function ConstFactor(length::Integer)
ConstFactor("Intercept", "Intercept", length)
end
function slice(factor::ConstFactor, fromobs::Integer, toobs::Integer, slicelength::Integer)
if fromobs > toobs
EmptySeq{AbstractVector{UInt8}}()
else
fromobs = max(1, fromobs)
toobs = min(toobs, length(factor))
slicelength = verifyslicelength(fromobs, toobs, slicelength)
buffer = ones(UInt8, slicelength)
map(Seq(Tuple{Int64, Int64}, (fromobs, toobs, slicelength), nextslice), SubArray{UInt8,1,Array{UInt8,1},Tuple{UnitRange{Int64}},true}) do rng
view(buffer, 1:(rng[2] - rng[1] + 1))
end
end
end
function Base.map(factor::ConstFactor, dataframe::AbstractDataFrame)
ConstFactor(factor.name, factor.level, length(dataframe))
end |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import order.category.BoolAlg
import order.category.FinPartialOrder
import order.hom.complete_lattice
/-!
# The category of finite boolean algebras
This file defines `FinBoolAlg`, the category of finite boolean algebras.
## TODO
Birkhoff's representation for finite Boolean algebras.
`Fintype_to_FinBoolAlg_op.left_op ⋙ FinBoolAlg.dual ≅ Fintype_to_FinBoolAlg_op.left_op`
`FinBoolAlg` is essentially small.
-/
universes u
open category_theory order_dual opposite
/-- The category of finite boolean algebras with bounded lattice morphisms. -/
structure FinBoolAlg :=
(to_BoolAlg : BoolAlg)
[is_fintype : fintype to_BoolAlg]
namespace FinBoolAlg
instance : has_coe_to_sort FinBoolAlg Type* := ⟨λ X, X.to_BoolAlg⟩
instance (X : FinBoolAlg) : boolean_algebra X := X.to_BoolAlg.str
attribute [instance] FinBoolAlg.is_fintype
@[simp] lemma coe_to_BoolAlg (X : FinBoolAlg) : ↥X.to_BoolAlg = ↥X := rfl
/-- Construct a bundled `FinBoolAlg` from `boolean_algebra` + `fintype`. -/
def of (α : Type*) [boolean_algebra α] [fintype α] : FinBoolAlg := ⟨⟨α⟩⟩
@[simp] lemma coe_of (α : Type*) [boolean_algebra α] [fintype α] : ↥(of α) = α := rfl
instance : inhabited FinBoolAlg := ⟨of punit⟩
instance large_category : large_category FinBoolAlg :=
induced_category.category FinBoolAlg.to_BoolAlg
instance concrete_category : concrete_category FinBoolAlg :=
induced_category.concrete_category FinBoolAlg.to_BoolAlg
instance has_forget_to_BoolAlg : has_forget₂ FinBoolAlg BoolAlg :=
induced_category.has_forget₂ FinBoolAlg.to_BoolAlg
instance forget_to_BoolAlg_full : full (forget₂ FinBoolAlg BoolAlg) := induced_category.full _
instance forget_to_BoolAlg_faithful : faithful (forget₂ FinBoolAlg BoolAlg) :=
induced_category.faithful _
@[simps] instance has_forget_to_FinPartialOrder : has_forget₂ FinBoolAlg FinPartialOrder :=
{ forget₂ := { obj := λ X, FinPartialOrder.of X, map := λ X Y f,
show order_hom X Y, from ↑(show bounded_lattice_hom X Y, from f) } }
instance forget_to_FinPartialOrder_faithful : faithful (forget₂ FinBoolAlg FinPartialOrder) :=
⟨λ X Y f g h, by { have := congr_arg (coe_fn : _ → X → Y) h, exact fun_like.coe_injective this }⟩
/-- Constructs an equivalence between finite Boolean algebras from an order isomorphism between
them. -/
@[simps] def iso.mk {α β : FinBoolAlg.{u}} (e : α ≃o β) : α ≅ β :=
{ hom := (e : bounded_lattice_hom α β),
inv := (e.symm : bounded_lattice_hom β α),
hom_inv_id' := by { ext, exact e.symm_apply_apply _ },
inv_hom_id' := by { ext, exact e.apply_symm_apply _ } }
/-- `order_dual` as a functor. -/
@[simps] def dual : FinBoolAlg ⥤ FinBoolAlg :=
{ obj := λ X, of (order_dual X), map := λ X Y, bounded_lattice_hom.dual }
/-- The equivalence between `FinBoolAlg` and itself induced by `order_dual` both ways. -/
@[simps functor inverse] def dual_equiv : FinBoolAlg ≌ FinBoolAlg :=
equivalence.mk dual dual
(nat_iso.of_components (λ X, iso.mk $ order_iso.dual_dual X) $ λ X Y f, rfl)
(nat_iso.of_components (λ X, iso.mk $ order_iso.dual_dual X) $ λ X Y f, rfl)
end FinBoolAlg
/-- The powerset functor. `set` as a functor. -/
@[simps] def Fintype_to_FinBoolAlg_op : Fintype ⥤ FinBoolAlgᵒᵖ :=
{ obj := λ X, op $ FinBoolAlg.of (set X),
map := λ X Y f, quiver.hom.op $
(complete_lattice_hom.set_preimage f : bounded_lattice_hom (set Y) (set X)) }
|
lemma homeomorphic_contractible: fixes S :: "'a::real_normed_vector set" and T :: "'b::real_normed_vector set" shows "\<lbrakk>contractible S; S homeomorphic T\<rbrakk> \<Longrightarrow> contractible T" |
'''
Measures perplexity of a smoothed unigram model on note text
'''
import sys
import numpy as np
def read_unigram(path, alpha):
ind2word = []
ind2count = []
word2ind = {}
with open(path) as f:
for line in f:
word, count = line.strip().split()
count = float(count) + alpha # lidstone smoothing
ind2word.append(word)
ind2count.append(count)
word2ind[word] = len(word2ind)
log_probabilities = np.log(np.asarray(ind2count)/sum(ind2count))
return word2ind, log_probabilities
if __name__ == '__main__':
if len(sys.argv) < 3:
print("Usage: %s <test-filename> <vocab-filename> [smoothing-factor]" % sys.argv[0])
sys.exit(1)
test_filename = sys.argv[1]
unigram_filename = sys.argv[2]
alpha = float(sys.argv[3]) if len(sys.argv) > 3 else 1.0
print('Using smoothing factor: ', alpha)
word2ind, log_probs = read_unigram(unigram_filename, alpha)
words_num = 0
last_read_word = '<eon>'
tot_log_prob = 0
with open(test_filename, 'r') as f:
for line in f:
toks = line.strip().split()
if len(toks) == 0:
tot_log_prob += log_probs[word2ind['<eon>']]
words_num += 1
else:
for tok in toks:
tot_log_prob += log_probs[word2ind[tok]]
tot_log_prob += log_probs[word2ind['<eos>']]
words_num += len(toks)+1
print('Read words:', words_num)
print('perp:',np.exp(-tot_log_prob/words_num))
|
/-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Kevin Buzzard, Scott Morrison, Johan Commelin, Chris Hughes,
Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.group.commute
import Mathlib.algebra.group_with_zero.defs
import Mathlib.PostPort
universes u_6 u_7 l u_1 u_2 u_3 u_4 u_5
namespace Mathlib
/-!
# monoid and group homomorphisms
This file defines the bundled structures for monoid and group homomorphisms. Namely, we define
`monoid_hom` (resp., `add_monoid_hom`) to be bundled homomorphisms between multiplicative (resp.,
additive) monoids or groups.
We also define coercion to a function, and usual operations: composition, identity homomorphism,
pointwise multiplication and pointwise inversion.
This file also defines the lesser-used (and notation-less) homomorphism types which are used as
building blocks for other homomorphisms:
* `zero_hom`
* `one_hom`
* `add_hom`
* `mul_hom`
* `monoid_with_zero_hom`
## Notations
* `→*` for bundled monoid homs (also use for group homs)
* `→+` for bundled add_monoid homs (also use for add_group homs)
## implementation notes
There's a coercion from bundled homs to fun, and the canonical
notation is to use the bundled hom as a function via this coercion.
There is no `group_hom` -- the idea is that `monoid_hom` is used.
The constructor for `monoid_hom` needs a proof of `map_one` as well
as `map_mul`; a separate constructor `monoid_hom.mk'` will construct
group homs (i.e. monoid homs between groups) given only a proof
that multiplication is preserved,
Implicit `{}` brackets are often used instead of type class `[]` brackets. This is done when the
instances can be inferred because they are implicit arguments to the type `monoid_hom`. When they
can be inferred from the type it is faster to use this method than to use type class inference.
Historically this file also included definitions of unbundled homomorphism classes; they were
deprecated and moved to `deprecated/group`.
## Tags
monoid_hom, add_monoid_hom
-/
-- for easy multiple inheritance
/-- Homomorphism that preserves zero -/
structure zero_hom (M : Type u_6) (N : Type u_7) [HasZero M] [HasZero N] where
to_fun : M → N
map_zero' : to_fun 0 = 0
/-- Homomorphism that preserves addition -/
structure add_hom (M : Type u_6) (N : Type u_7) [Add M] [Add N] where
to_fun : M → N
map_add' : ∀ (x y : M), to_fun (x + y) = to_fun x + to_fun y
/-- Bundled add_monoid homomorphisms; use this for bundled add_group homomorphisms too. -/
structure add_monoid_hom (M : Type u_6) (N : Type u_7) [add_monoid M] [add_monoid N]
extends zero_hom M N, add_hom M N where
infixr:25 " →+ " => Mathlib.add_monoid_hom
/-- Homomorphism that preserves one -/
structure one_hom (M : Type u_6) (N : Type u_7) [HasOne M] [HasOne N] where
to_fun : M → N
map_one' : to_fun 1 = 1
/-- Homomorphism that preserves multiplication -/
structure mul_hom (M : Type u_6) (N : Type u_7) [Mul M] [Mul N] where
to_fun : M → N
map_mul' : ∀ (x y : M), to_fun (x * y) = to_fun x * to_fun y
/-- Bundled monoid homomorphisms; use this for bundled group homomorphisms too. -/
structure monoid_hom (M : Type u_6) (N : Type u_7) [monoid M] [monoid N]
extends one_hom M N, mul_hom M N where
/-- Bundled monoid with zero homomorphisms; use this for bundled group with zero homomorphisms
too. -/
structure monoid_with_zero_hom (M : Type u_6) (N : Type u_7) [monoid_with_zero M]
[monoid_with_zero N]
extends zero_hom M N, monoid_hom M N where
infixr:25 " →* " => Mathlib.monoid_hom
-- completely uninteresting lemmas about coercion to function, that all homs need
/-! Bundled morphisms can be down-cast to weaker bundlings -/
protected instance monoid_hom.has_coe_to_one_hom {M : Type u_1} {N : Type u_2} {mM : monoid M}
{mN : monoid N} : has_coe (M →* N) (one_hom M N) :=
has_coe.mk monoid_hom.to_one_hom
protected instance add_monoid_hom.has_coe_to_add_hom {M : Type u_1} {N : Type u_2}
{mM : add_monoid M} {mN : add_monoid N} : has_coe (M →+ N) (add_hom M N) :=
has_coe.mk add_monoid_hom.to_add_hom
protected instance monoid_with_zero_hom.has_coe_to_monoid_hom {M : Type u_1} {N : Type u_2}
{mM : monoid_with_zero M} {mN : monoid_with_zero N} :
has_coe (monoid_with_zero_hom M N) (M →* N) :=
has_coe.mk monoid_with_zero_hom.to_monoid_hom
protected instance monoid_with_zero_hom.has_coe_to_zero_hom {M : Type u_1} {N : Type u_2}
{mM : monoid_with_zero M} {mN : monoid_with_zero N} :
has_coe (monoid_with_zero_hom M N) (zero_hom M N) :=
has_coe.mk monoid_with_zero_hom.to_zero_hom
/-! The simp-normal form of morphism coercion is `f.to_..._hom`. This choice is primarily because
this is the way things were before the above coercions were introduced. Bundled morphisms defined
elsewhere in Mathlib may choose `↑f` as their simp-normal form instead. -/
@[simp] theorem monoid_hom.coe_eq_to_one_hom {M : Type u_1} {N : Type u_2} {mM : monoid M}
{mN : monoid N} (f : M →* N) : ↑f = monoid_hom.to_one_hom f :=
rfl
@[simp] theorem add_monoid_hom.coe_eq_to_add_hom {M : Type u_1} {N : Type u_2} {mM : add_monoid M}
{mN : add_monoid N} (f : M →+ N) : ↑f = add_monoid_hom.to_add_hom f :=
rfl
@[simp] theorem monoid_with_zero_hom.coe_eq_to_monoid_hom {M : Type u_1} {N : Type u_2}
{mM : monoid_with_zero M} {mN : monoid_with_zero N} (f : monoid_with_zero_hom M N) :
↑f = monoid_with_zero_hom.to_monoid_hom f :=
rfl
@[simp] theorem monoid_with_zero_hom.coe_eq_to_zero_hom {M : Type u_1} {N : Type u_2}
{mM : monoid_with_zero M} {mN : monoid_with_zero N} (f : monoid_with_zero_hom M N) :
↑f = monoid_with_zero_hom.to_zero_hom f :=
rfl
protected instance zero_hom.has_coe_to_fun {M : Type u_1} {N : Type u_2} {mM : HasZero M}
{mN : HasZero N} : has_coe_to_fun (zero_hom M N) :=
has_coe_to_fun.mk (fun (x : zero_hom M N) => M → N) zero_hom.to_fun
protected instance mul_hom.has_coe_to_fun {M : Type u_1} {N : Type u_2} {mM : Mul M} {mN : Mul N} :
has_coe_to_fun (mul_hom M N) :=
has_coe_to_fun.mk (fun (x : mul_hom M N) => M → N) mul_hom.to_fun
protected instance add_monoid_hom.has_coe_to_fun {M : Type u_1} {N : Type u_2} {mM : add_monoid M}
{mN : add_monoid N} : has_coe_to_fun (M →+ N) :=
has_coe_to_fun.mk (fun (x : M →+ N) => M → N) add_monoid_hom.to_fun
protected instance monoid_with_zero_hom.has_coe_to_fun {M : Type u_1} {N : Type u_2}
{mM : monoid_with_zero M} {mN : monoid_with_zero N} :
has_coe_to_fun (monoid_with_zero_hom M N) :=
has_coe_to_fun.mk (fun (x : monoid_with_zero_hom M N) => M → N) monoid_with_zero_hom.to_fun
-- these must come after the coe_to_fun definitions
@[simp] theorem zero_hom.to_fun_eq_coe {M : Type u_1} {N : Type u_2} [HasZero M] [HasZero N]
(f : zero_hom M N) : zero_hom.to_fun f = ⇑f :=
rfl
@[simp] theorem mul_hom.to_fun_eq_coe {M : Type u_1} {N : Type u_2} [Mul M] [Mul N]
(f : mul_hom M N) : mul_hom.to_fun f = ⇑f :=
rfl
@[simp] theorem add_monoid_hom.to_fun_eq_coe {M : Type u_1} {N : Type u_2} [add_monoid M]
[add_monoid N] (f : M →+ N) : add_monoid_hom.to_fun f = ⇑f :=
rfl
@[simp] theorem monoid_with_zero_hom.to_fun_eq_coe {M : Type u_1} {N : Type u_2}
[monoid_with_zero M] [monoid_with_zero N] (f : monoid_with_zero_hom M N) :
monoid_with_zero_hom.to_fun f = ⇑f :=
rfl
@[simp] theorem one_hom.coe_mk {M : Type u_1} {N : Type u_2} [HasOne M] [HasOne N] (f : M → N)
(h1 : f 1 = 1) : ⇑(one_hom.mk f h1) = f :=
rfl
@[simp] theorem add_hom.coe_mk {M : Type u_1} {N : Type u_2} [Add M] [Add N] (f : M → N)
(hmul : ∀ (x y : M), f (x + y) = f x + f y) : ⇑(add_hom.mk f hmul) = f :=
rfl
@[simp] theorem add_monoid_hom.coe_mk {M : Type u_1} {N : Type u_2} [add_monoid M] [add_monoid N]
(f : M → N) (h1 : f 0 = 0) (hmul : ∀ (x y : M), f (x + y) = f x + f y) :
⇑(add_monoid_hom.mk f h1 hmul) = f :=
rfl
@[simp] theorem monoid_with_zero_hom.coe_mk {M : Type u_1} {N : Type u_2} [monoid_with_zero M]
[monoid_with_zero N] (f : M → N) (h0 : f 0 = 0) (h1 : f 1 = 1)
(hmul : ∀ (x y : M), f (x * y) = f x * f y) : ⇑(monoid_with_zero_hom.mk f h0 h1 hmul) = f :=
rfl
@[simp] theorem monoid_hom.to_one_hom_coe {M : Type u_1} {N : Type u_2} [monoid M] [monoid N]
(f : M →* N) : ⇑(monoid_hom.to_one_hom f) = ⇑f :=
rfl
@[simp] theorem add_monoid_hom.to_add_hom_coe {M : Type u_1} {N : Type u_2} [add_monoid M]
[add_monoid N] (f : M →+ N) : ⇑(add_monoid_hom.to_add_hom f) = ⇑f :=
rfl
@[simp] theorem monoid_with_zero_hom.to_zero_hom_coe {M : Type u_1} {N : Type u_2}
[monoid_with_zero M] [monoid_with_zero N] (f : monoid_with_zero_hom M N) :
⇑(monoid_with_zero_hom.to_zero_hom f) = ⇑f :=
rfl
@[simp] theorem monoid_with_zero_hom.to_monoid_hom_coe {M : Type u_1} {N : Type u_2}
[monoid_with_zero M] [monoid_with_zero N] (f : monoid_with_zero_hom M N) :
⇑(monoid_with_zero_hom.to_monoid_hom f) = ⇑f :=
rfl
theorem one_hom.congr_fun {M : Type u_1} {N : Type u_2} [HasOne M] [HasOne N] {f : one_hom M N}
{g : one_hom M N} (h : f = g) (x : M) : coe_fn f x = coe_fn g x :=
congr_arg (fun (h : one_hom M N) => coe_fn h x) h
theorem add_hom.congr_fun {M : Type u_1} {N : Type u_2} [Add M] [Add N] {f : add_hom M N}
{g : add_hom M N} (h : f = g) (x : M) : coe_fn f x = coe_fn g x :=
congr_arg (fun (h : add_hom M N) => coe_fn h x) h
theorem add_monoid_hom.congr_fun {M : Type u_1} {N : Type u_2} [add_monoid M] [add_monoid N]
{f : M →+ N} {g : M →+ N} (h : f = g) (x : M) : coe_fn f x = coe_fn g x :=
congr_arg (fun (h : M →+ N) => coe_fn h x) h
theorem monoid_with_zero_hom.congr_fun {M : Type u_1} {N : Type u_2} [monoid_with_zero M]
[monoid_with_zero N] {f : monoid_with_zero_hom M N} {g : monoid_with_zero_hom M N} (h : f = g)
(x : M) : coe_fn f x = coe_fn g x :=
congr_arg (fun (h : monoid_with_zero_hom M N) => coe_fn h x) h
theorem one_hom.congr_arg {M : Type u_1} {N : Type u_2} [HasOne M] [HasOne N] (f : one_hom M N)
{x : M} {y : M} (h : x = y) : coe_fn f x = coe_fn f y :=
congr_arg (fun (x : M) => coe_fn f x) h
theorem add_hom.congr_arg {M : Type u_1} {N : Type u_2} [Add M] [Add N] (f : add_hom M N) {x : M}
{y : M} (h : x = y) : coe_fn f x = coe_fn f y :=
congr_arg (fun (x : M) => coe_fn f x) h
theorem add_monoid_hom.congr_arg {M : Type u_1} {N : Type u_2} [add_monoid M] [add_monoid N]
(f : M →+ N) {x : M} {y : M} (h : x = y) : coe_fn f x = coe_fn f y :=
congr_arg (fun (x : M) => coe_fn f x) h
theorem monoid_with_zero_hom.congr_arg {M : Type u_1} {N : Type u_2} [monoid_with_zero M]
[monoid_with_zero N] (f : monoid_with_zero_hom M N) {x : M} {y : M} (h : x = y) :
coe_fn f x = coe_fn f y :=
congr_arg (fun (x : M) => coe_fn f x) h
theorem one_hom.coe_inj {M : Type u_1} {N : Type u_2} [HasOne M] [HasOne N] {f : one_hom M N}
{g : one_hom M N} (h : ⇑f = ⇑g) : f = g :=
sorry
theorem mul_hom.coe_inj {M : Type u_1} {N : Type u_2} [Mul M] [Mul N] {f : mul_hom M N}
{g : mul_hom M N} (h : ⇑f = ⇑g) : f = g :=
sorry
theorem add_monoid_hom.coe_inj {M : Type u_1} {N : Type u_2} [add_monoid M] [add_monoid N]
{f : M →+ N} {g : M →+ N} (h : ⇑f = ⇑g) : f = g :=
sorry
theorem monoid_with_zero_hom.coe_inj {M : Type u_1} {N : Type u_2} [monoid_with_zero M]
[monoid_with_zero N] {f : monoid_with_zero_hom M N} {g : monoid_with_zero_hom M N}
(h : ⇑f = ⇑g) : f = g :=
sorry
theorem zero_hom.ext {M : Type u_1} {N : Type u_2} [HasZero M] [HasZero N] {f : zero_hom M N}
{g : zero_hom M N} (h : ∀ (x : M), coe_fn f x = coe_fn g x) : f = g :=
zero_hom.coe_inj (funext h)
theorem mul_hom.ext {M : Type u_1} {N : Type u_2} [Mul M] [Mul N] {f : mul_hom M N}
{g : mul_hom M N} (h : ∀ (x : M), coe_fn f x = coe_fn g x) : f = g :=
mul_hom.coe_inj (funext h)
theorem add_monoid_hom.ext {M : Type u_1} {N : Type u_2} [add_monoid M] [add_monoid N] {f : M →+ N}
{g : M →+ N} (h : ∀ (x : M), coe_fn f x = coe_fn g x) : f = g :=
add_monoid_hom.coe_inj (funext h)
theorem monoid_with_zero_hom.ext {M : Type u_1} {N : Type u_2} [monoid_with_zero M]
[monoid_with_zero N] {f : monoid_with_zero_hom M N} {g : monoid_with_zero_hom M N}
(h : ∀ (x : M), coe_fn f x = coe_fn g x) : f = g :=
monoid_with_zero_hom.coe_inj (funext h)
theorem zero_hom.ext_iff {M : Type u_1} {N : Type u_2} [HasZero M] [HasZero N] {f : zero_hom M N}
{g : zero_hom M N} : f = g ↔ ∀ (x : M), coe_fn f x = coe_fn g x :=
{ mp := fun (h : f = g) (x : M) => h ▸ rfl,
mpr := fun (h : ∀ (x : M), coe_fn f x = coe_fn g x) => zero_hom.ext h }
theorem mul_hom.ext_iff {M : Type u_1} {N : Type u_2} [Mul M] [Mul N] {f : mul_hom M N}
{g : mul_hom M N} : f = g ↔ ∀ (x : M), coe_fn f x = coe_fn g x :=
{ mp := fun (h : f = g) (x : M) => h ▸ rfl,
mpr := fun (h : ∀ (x : M), coe_fn f x = coe_fn g x) => mul_hom.ext h }
theorem add_monoid_hom.ext_iff {M : Type u_1} {N : Type u_2} [add_monoid M] [add_monoid N]
{f : M →+ N} {g : M →+ N} : f = g ↔ ∀ (x : M), coe_fn f x = coe_fn g x :=
{ mp := fun (h : f = g) (x : M) => h ▸ rfl,
mpr := fun (h : ∀ (x : M), coe_fn f x = coe_fn g x) => add_monoid_hom.ext h }
theorem monoid_with_zero_hom.ext_iff {M : Type u_1} {N : Type u_2} [monoid_with_zero M]
[monoid_with_zero N] {f : monoid_with_zero_hom M N} {g : monoid_with_zero_hom M N} :
f = g ↔ ∀ (x : M), coe_fn f x = coe_fn g x :=
{ mp := fun (h : f = g) (x : M) => h ▸ rfl,
mpr := fun (h : ∀ (x : M), coe_fn f x = coe_fn g x) => monoid_with_zero_hom.ext h }
@[simp] theorem zero_hom.mk_coe {M : Type u_1} {N : Type u_2} [HasZero M] [HasZero N]
(f : zero_hom M N) (h1 : coe_fn f 0 = 0) : zero_hom.mk (⇑f) h1 = f :=
zero_hom.ext fun (_x : M) => rfl
@[simp] theorem mul_hom.mk_coe {M : Type u_1} {N : Type u_2} [Mul M] [Mul N] (f : mul_hom M N)
(hmul : ∀ (x y : M), coe_fn f (x * y) = coe_fn f x * coe_fn f y) : mul_hom.mk (⇑f) hmul = f :=
mul_hom.ext fun (_x : M) => rfl
@[simp] theorem add_monoid_hom.mk_coe {M : Type u_1} {N : Type u_2} [add_monoid M] [add_monoid N]
(f : M →+ N) (h1 : coe_fn f 0 = 0)
(hmul : ∀ (x y : M), coe_fn f (x + y) = coe_fn f x + coe_fn f y) :
add_monoid_hom.mk (⇑f) h1 hmul = f :=
add_monoid_hom.ext fun (_x : M) => rfl
@[simp] theorem monoid_with_zero_hom.mk_coe {M : Type u_1} {N : Type u_2} [monoid_with_zero M]
[monoid_with_zero N] (f : monoid_with_zero_hom M N) (h0 : coe_fn f 0 = 0) (h1 : coe_fn f 1 = 1)
(hmul : ∀ (x y : M), coe_fn f (x * y) = coe_fn f x * coe_fn f y) :
monoid_with_zero_hom.mk (⇑f) h0 h1 hmul = f :=
monoid_with_zero_hom.ext fun (_x : M) => rfl
/-- If `f` is a monoid homomorphism then `f 1 = 1`. -/
@[simp] theorem one_hom.map_one {M : Type u_1} {N : Type u_2} [HasOne M] [HasOne N]
(f : one_hom M N) : coe_fn f 1 = 1 :=
one_hom.map_one' f
@[simp] theorem monoid_hom.map_one {M : Type u_1} {N : Type u_2} [monoid M] [monoid N]
(f : M →* N) : coe_fn f 1 = 1 :=
monoid_hom.map_one' f
@[simp] theorem monoid_with_zero_hom.map_one {M : Type u_1} {N : Type u_2} [monoid_with_zero M]
[monoid_with_zero N] (f : monoid_with_zero_hom M N) : coe_fn f 1 = 1 :=
monoid_with_zero_hom.map_one' f
/-- If `f` is an additive monoid homomorphism then `f 0 = 0`. -/
@[simp] theorem monoid_with_zero_hom.map_zero {M : Type u_1} {N : Type u_2} [monoid_with_zero M]
[monoid_with_zero N] (f : monoid_with_zero_hom M N) : coe_fn f 0 = 0 :=
monoid_with_zero_hom.map_zero' f
@[simp] theorem mul_hom.map_mul {M : Type u_1} {N : Type u_2} [Mul M] [Mul N] (f : mul_hom M N)
(a : M) (b : M) : coe_fn f (a * b) = coe_fn f a * coe_fn f b :=
mul_hom.map_mul' f a b
/-- If `f` is a monoid homomorphism then `f (a * b) = f a * f b`. -/
@[simp] theorem add_monoid_hom.map_add {M : Type u_1} {N : Type u_2} [add_monoid M] [add_monoid N]
(f : M →+ N) (a : M) (b : M) : coe_fn f (a + b) = coe_fn f a + coe_fn f b :=
add_monoid_hom.map_add' f a b
@[simp] theorem monoid_with_zero_hom.map_mul {M : Type u_1} {N : Type u_2} [monoid_with_zero M]
[monoid_with_zero N] (f : monoid_with_zero_hom M N) (a : M) (b : M) :
coe_fn f (a * b) = coe_fn f a * coe_fn f b :=
monoid_with_zero_hom.map_mul' f a b
/-- If `f` is an additive monoid homomorphism then `f (a + b) = f a + f b`. -/
namespace monoid_hom
theorem Mathlib.add_monoid_hom.map_add_eq_zero {M : Type u_1} {N : Type u_2} {mM : add_monoid M}
{mN : add_monoid N} (f : M →+ N) {a : M} {b : M} (h : a + b = 0) :
coe_fn f a + coe_fn f b = 0 :=
eq.mpr
(id
(Eq._oldrec (Eq.refl (coe_fn f a + coe_fn f b = 0)) (Eq.symm (add_monoid_hom.map_add f a b))))
(eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn f (a + b) = 0)) h))
(eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn f 0 = 0)) (add_monoid_hom.map_zero f))) (Eq.refl 0)))
/-- Given a monoid homomorphism `f : M →* N` and an element `x : M`, if `x` has a right inverse,
then `f x` has a right inverse too. For elements invertible on both sides see `is_unit.map`. -/
theorem Mathlib.add_monoid_hom.map_exists_right_neg {M : Type u_1} {N : Type u_2}
{mM : add_monoid M} {mN : add_monoid N} (f : M →+ N) {x : M} (hx : ∃ (y : M), x + y = 0) :
∃ (y : N), coe_fn f x + y = 0 :=
sorry
/-- Given a monoid homomorphism `f : M →* N` and an element `x : M`, if `x` has a left inverse,
then `f x` has a left inverse too. For elements invertible on both sides see `is_unit.map`. -/
theorem Mathlib.add_monoid_hom.map_exists_left_neg {M : Type u_1} {N : Type u_2} {mM : add_monoid M}
{mN : add_monoid N} (f : M →+ N) {x : M} (hx : ∃ (y : M), y + x = 0) :
∃ (y : N), y + coe_fn f x = 0 :=
sorry
end monoid_hom
/-- The identity map from a type with 1 to itself. -/
def one_hom.id (M : Type u_1) [HasOne M] : one_hom M M := one_hom.mk id sorry
/-- The identity map from a type with multiplication to itself. -/
def add_hom.id (M : Type u_1) [Add M] : add_hom M M := add_hom.mk id sorry
/-- The identity map from a monoid to itself. -/
def add_monoid_hom.id (M : Type u_1) [add_monoid M] : M →+ M := add_monoid_hom.mk id sorry sorry
/-- The identity map from a monoid_with_zero to itself. -/
def monoid_with_zero_hom.id (M : Type u_1) [monoid_with_zero M] : monoid_with_zero_hom M M :=
monoid_with_zero_hom.mk id sorry sorry sorry
/-- The identity map from an type with zero to itself. -/
/-- The identity map from an type with addition to itself. -/
/-- The identity map from an additive monoid to itself. -/
@[simp] theorem zero_hom.id_apply {M : Type u_1} [HasZero M] (x : M) :
coe_fn (zero_hom.id M) x = x :=
rfl
@[simp] theorem mul_hom.id_apply {M : Type u_1} [Mul M] (x : M) : coe_fn (mul_hom.id M) x = x := rfl
@[simp] theorem monoid_hom.id_apply {M : Type u_1} [monoid M] (x : M) :
coe_fn (monoid_hom.id M) x = x :=
rfl
@[simp] theorem monoid_with_zero_hom.id_apply {M : Type u_1} [monoid_with_zero M] (x : M) :
coe_fn (monoid_with_zero_hom.id M) x = x :=
rfl
/-- Composition of `one_hom`s as a `one_hom`. -/
def zero_hom.comp {M : Type u_1} {N : Type u_2} {P : Type u_3} [HasZero M] [HasZero N] [HasZero P]
(hnp : zero_hom N P) (hmn : zero_hom M N) : zero_hom M P :=
zero_hom.mk (⇑hnp ∘ ⇑hmn) sorry
/-- Composition of `mul_hom`s as a `mul_hom`. -/
def mul_hom.comp {M : Type u_1} {N : Type u_2} {P : Type u_3} [Mul M] [Mul N] [Mul P]
(hnp : mul_hom N P) (hmn : mul_hom M N) : mul_hom M P :=
mul_hom.mk (⇑hnp ∘ ⇑hmn) sorry
/-- Composition of monoid morphisms as a monoid morphism. -/
def monoid_hom.comp {M : Type u_1} {N : Type u_2} {P : Type u_3} [monoid M] [monoid N] [monoid P]
(hnp : N →* P) (hmn : M →* N) : M →* P :=
monoid_hom.mk (⇑hnp ∘ ⇑hmn) sorry sorry
/-- Composition of `monoid_with_zero_hom`s as a `monoid_with_zero_hom`. -/
def monoid_with_zero_hom.comp {M : Type u_1} {N : Type u_2} {P : Type u_3} [monoid_with_zero M]
[monoid_with_zero N] [monoid_with_zero P] (hnp : monoid_with_zero_hom N P)
(hmn : monoid_with_zero_hom M N) : monoid_with_zero_hom M P :=
monoid_with_zero_hom.mk (⇑hnp ∘ ⇑hmn) sorry sorry sorry
/-- Composition of `zero_hom`s as a `zero_hom`. -/
/-- Composition of `add_hom`s as a `add_hom`. -/
/-- Composition of additive monoid morphisms as an additive monoid morphism. -/
@[simp] theorem one_hom.coe_comp {M : Type u_1} {N : Type u_2} {P : Type u_3} [HasOne M] [HasOne N]
[HasOne P] (g : one_hom N P) (f : one_hom M N) : ⇑(one_hom.comp g f) = ⇑g ∘ ⇑f :=
rfl
@[simp] theorem add_hom.coe_comp {M : Type u_1} {N : Type u_2} {P : Type u_3} [Add M] [Add N]
[Add P] (g : add_hom N P) (f : add_hom M N) : ⇑(add_hom.comp g f) = ⇑g ∘ ⇑f :=
rfl
@[simp] theorem add_monoid_hom.coe_comp {M : Type u_1} {N : Type u_2} {P : Type u_3} [add_monoid M]
[add_monoid N] [add_monoid P] (g : N →+ P) (f : M →+ N) :
⇑(add_monoid_hom.comp g f) = ⇑g ∘ ⇑f :=
rfl
@[simp] theorem monoid_with_zero_hom.coe_comp {M : Type u_1} {N : Type u_2} {P : Type u_3}
[monoid_with_zero M] [monoid_with_zero N] [monoid_with_zero P] (g : monoid_with_zero_hom N P)
(f : monoid_with_zero_hom M N) : ⇑(monoid_with_zero_hom.comp g f) = ⇑g ∘ ⇑f :=
rfl
theorem one_hom.comp_apply {M : Type u_1} {N : Type u_2} {P : Type u_3} [HasOne M] [HasOne N]
[HasOne P] (g : one_hom N P) (f : one_hom M N) (x : M) :
coe_fn (one_hom.comp g f) x = coe_fn g (coe_fn f x) :=
rfl
theorem add_hom.comp_apply {M : Type u_1} {N : Type u_2} {P : Type u_3} [Add M] [Add N] [Add P]
(g : add_hom N P) (f : add_hom M N) (x : M) :
coe_fn (add_hom.comp g f) x = coe_fn g (coe_fn f x) :=
rfl
theorem monoid_hom.comp_apply {M : Type u_1} {N : Type u_2} {P : Type u_3} [monoid M] [monoid N]
[monoid P] (g : N →* P) (f : M →* N) (x : M) :
coe_fn (monoid_hom.comp g f) x = coe_fn g (coe_fn f x) :=
rfl
theorem monoid_with_zero_hom.comp_apply {M : Type u_1} {N : Type u_2} {P : Type u_3}
[monoid_with_zero M] [monoid_with_zero N] [monoid_with_zero P] (g : monoid_with_zero_hom N P)
(f : monoid_with_zero_hom M N) (x : M) :
coe_fn (monoid_with_zero_hom.comp g f) x = coe_fn g (coe_fn f x) :=
rfl
/-- Composition of monoid homomorphisms is associative. -/
theorem zero_hom.comp_assoc {M : Type u_1} {N : Type u_2} {P : Type u_3} {Q : Type u_4} [HasZero M]
[HasZero N] [HasZero P] [HasZero Q] (f : zero_hom M N) (g : zero_hom N P) (h : zero_hom P Q) :
zero_hom.comp (zero_hom.comp h g) f = zero_hom.comp h (zero_hom.comp g f) :=
rfl
theorem mul_hom.comp_assoc {M : Type u_1} {N : Type u_2} {P : Type u_3} {Q : Type u_4} [Mul M]
[Mul N] [Mul P] [Mul Q] (f : mul_hom M N) (g : mul_hom N P) (h : mul_hom P Q) :
mul_hom.comp (mul_hom.comp h g) f = mul_hom.comp h (mul_hom.comp g f) :=
rfl
theorem add_monoid_hom.comp_assoc {M : Type u_1} {N : Type u_2} {P : Type u_3} {Q : Type u_4}
[add_monoid M] [add_monoid N] [add_monoid P] [add_monoid Q] (f : M →+ N) (g : N →+ P)
(h : P →+ Q) :
add_monoid_hom.comp (add_monoid_hom.comp h g) f =
add_monoid_hom.comp h (add_monoid_hom.comp g f) :=
rfl
theorem monoid_with_zero_hom.comp_assoc {M : Type u_1} {N : Type u_2} {P : Type u_3} {Q : Type u_4}
[monoid_with_zero M] [monoid_with_zero N] [monoid_with_zero P] [monoid_with_zero Q]
(f : monoid_with_zero_hom M N) (g : monoid_with_zero_hom N P) (h : monoid_with_zero_hom P Q) :
monoid_with_zero_hom.comp (monoid_with_zero_hom.comp h g) f =
monoid_with_zero_hom.comp h (monoid_with_zero_hom.comp g f) :=
rfl
theorem one_hom.cancel_right {M : Type u_1} {N : Type u_2} {P : Type u_3} [HasOne M] [HasOne N]
[HasOne P] {g₁ : one_hom N P} {g₂ : one_hom N P} {f : one_hom M N}
(hf : function.surjective ⇑f) : one_hom.comp g₁ f = one_hom.comp g₂ f ↔ g₁ = g₂ :=
sorry
theorem add_hom.cancel_right {M : Type u_1} {N : Type u_2} {P : Type u_3} [Add M] [Add N] [Add P]
{g₁ : add_hom N P} {g₂ : add_hom N P} {f : add_hom M N} (hf : function.surjective ⇑f) :
add_hom.comp g₁ f = add_hom.comp g₂ f ↔ g₁ = g₂ :=
sorry
theorem add_monoid_hom.cancel_right {M : Type u_1} {N : Type u_2} {P : Type u_3} [add_monoid M]
[add_monoid N] [add_monoid P] {g₁ : N →+ P} {g₂ : N →+ P} {f : M →+ N}
(hf : function.surjective ⇑f) : add_monoid_hom.comp g₁ f = add_monoid_hom.comp g₂ f ↔ g₁ = g₂ :=
sorry
theorem monoid_with_zero_hom.cancel_right {M : Type u_1} {N : Type u_2} {P : Type u_3}
[monoid_with_zero M] [monoid_with_zero N] [monoid_with_zero P] {g₁ : monoid_with_zero_hom N P}
{g₂ : monoid_with_zero_hom N P} {f : monoid_with_zero_hom M N} (hf : function.surjective ⇑f) :
monoid_with_zero_hom.comp g₁ f = monoid_with_zero_hom.comp g₂ f ↔ g₁ = g₂ :=
sorry
theorem one_hom.cancel_left {M : Type u_1} {N : Type u_2} {P : Type u_3} [HasOne M] [HasOne N]
[HasOne P] {g : one_hom N P} {f₁ : one_hom M N} {f₂ : one_hom M N}
(hg : function.injective ⇑g) : one_hom.comp g f₁ = one_hom.comp g f₂ ↔ f₁ = f₂ :=
sorry
theorem add_hom.cancel_left {M : Type u_1} {N : Type u_2} {P : Type u_3} [HasZero M] [HasZero N]
[HasZero P] {g : zero_hom N P} {f₁ : zero_hom M N} {f₂ : zero_hom M N}
(hg : function.injective ⇑g) : zero_hom.comp g f₁ = zero_hom.comp g f₂ ↔ f₁ = f₂ :=
sorry
theorem monoid_hom.cancel_left {M : Type u_1} {N : Type u_2} {P : Type u_3} [monoid M] [monoid N]
[monoid P] {g : N →* P} {f₁ : M →* N} {f₂ : M →* N} (hg : function.injective ⇑g) :
monoid_hom.comp g f₁ = monoid_hom.comp g f₂ ↔ f₁ = f₂ :=
sorry
theorem monoid_with_zero_hom.cancel_left {M : Type u_1} {N : Type u_2} {P : Type u_3}
[monoid_with_zero M] [monoid_with_zero N] [monoid_with_zero P] {g : monoid_with_zero_hom N P}
{f₁ : monoid_with_zero_hom M N} {f₂ : monoid_with_zero_hom M N} (hg : function.injective ⇑g) :
monoid_with_zero_hom.comp g f₁ = monoid_with_zero_hom.comp g f₂ ↔ f₁ = f₂ :=
sorry
@[simp] theorem one_hom.comp_id {M : Type u_1} {N : Type u_2} [HasOne M] [HasOne N]
(f : one_hom M N) : one_hom.comp f (one_hom.id M) = f :=
one_hom.ext fun (x : M) => rfl
@[simp] theorem mul_hom.comp_id {M : Type u_1} {N : Type u_2} [Mul M] [Mul N] (f : mul_hom M N) :
mul_hom.comp f (mul_hom.id M) = f :=
mul_hom.ext fun (x : M) => rfl
@[simp] theorem add_monoid_hom.comp_id {M : Type u_1} {N : Type u_2} [add_monoid M] [add_monoid N]
(f : M →+ N) : add_monoid_hom.comp f (add_monoid_hom.id M) = f :=
add_monoid_hom.ext fun (x : M) => rfl
@[simp] theorem monoid_with_zero_hom.comp_id {M : Type u_1} {N : Type u_2} [monoid_with_zero M]
[monoid_with_zero N] (f : monoid_with_zero_hom M N) :
monoid_with_zero_hom.comp f (monoid_with_zero_hom.id M) = f :=
monoid_with_zero_hom.ext fun (x : M) => rfl
@[simp] theorem zero_hom.id_comp {M : Type u_1} {N : Type u_2} [HasZero M] [HasZero N]
(f : zero_hom M N) : zero_hom.comp (zero_hom.id N) f = f :=
zero_hom.ext fun (x : M) => rfl
@[simp] theorem mul_hom.id_comp {M : Type u_1} {N : Type u_2} [Mul M] [Mul N] (f : mul_hom M N) :
mul_hom.comp (mul_hom.id N) f = f :=
mul_hom.ext fun (x : M) => rfl
@[simp] theorem monoid_hom.id_comp {M : Type u_1} {N : Type u_2} [monoid M] [monoid N]
(f : M →* N) : monoid_hom.comp (monoid_hom.id N) f = f :=
monoid_hom.ext fun (x : M) => rfl
@[simp] theorem monoid_with_zero_hom.id_comp {M : Type u_1} {N : Type u_2} [monoid_with_zero M]
[monoid_with_zero N] (f : monoid_with_zero_hom M N) :
monoid_with_zero_hom.comp (monoid_with_zero_hom.id N) f = f :=
monoid_with_zero_hom.ext fun (x : M) => rfl
namespace monoid
/-- The monoid of endomorphisms. -/
protected def End (M : Type u_1) [monoid M] := M →* M
namespace End
protected instance monoid (M : Type u_1) [monoid M] : monoid (monoid.End M) :=
mk monoid_hom.comp sorry (monoid_hom.id M) monoid_hom.id_comp monoid_hom.comp_id
protected instance inhabited (M : Type u_1) [monoid M] : Inhabited (monoid.End M) :=
{ default := 1 }
protected instance has_coe_to_fun (M : Type u_1) [monoid M] : has_coe_to_fun (monoid.End M) :=
has_coe_to_fun.mk (fun (x : monoid.End M) => M → M) monoid_hom.to_fun
end End
@[simp] theorem coe_one (M : Type u_1) [monoid M] : ⇑1 = id := rfl
@[simp] theorem coe_mul (M : Type u_1) [monoid M] (f : monoid.End M) (g : monoid.End M) :
⇑(f * g) = ⇑f ∘ ⇑g :=
rfl
end monoid
namespace add_monoid
/-- The monoid of endomorphisms. -/
protected def End (A : Type u_6) [add_monoid A] := A →+ A
namespace End
protected instance monoid (A : Type u_6) [add_monoid A] : monoid (add_monoid.End A) :=
monoid.mk add_monoid_hom.comp sorry (add_monoid_hom.id A) add_monoid_hom.id_comp
add_monoid_hom.comp_id
protected instance inhabited (A : Type u_6) [add_monoid A] : Inhabited (add_monoid.End A) :=
{ default := 1 }
protected instance has_coe_to_fun (A : Type u_6) [add_monoid A] :
has_coe_to_fun (add_monoid.End A) :=
has_coe_to_fun.mk (fun (x : add_monoid.End A) => A → A) add_monoid_hom.to_fun
end End
@[simp] theorem coe_one (A : Type u_6) [add_monoid A] : ⇑1 = id := rfl
@[simp] theorem coe_mul (A : Type u_6) [add_monoid A] (f : add_monoid.End A)
(g : add_monoid.End A) : ⇑(f * g) = ⇑f ∘ ⇑g :=
rfl
end add_monoid
/-- `1` is the homomorphism sending all elements to `1`. -/
/-- `1` is the multiplicative homomorphism sending all elements to `1`. -/
protected instance zero_hom.has_zero {M : Type u_1} {N : Type u_2} [HasZero M] [HasZero N] :
HasZero (zero_hom M N) :=
{ zero := zero_hom.mk (fun (_x : M) => 0) sorry }
/-- `1` is the monoid homomorphism sending all elements to `1`. -/
protected instance add_hom.has_zero {M : Type u_1} {N : Type u_2} [Add M] [add_monoid N] :
HasZero (add_hom M N) :=
{ zero := add_hom.mk (fun (_x : M) => 0) sorry }
protected instance add_monoid_hom.has_zero {M : Type u_1} {N : Type u_2} [add_monoid M]
[add_monoid N] : HasZero (M →+ N) :=
{ zero := add_monoid_hom.mk (fun (_x : M) => 0) sorry sorry }
/-- `0` is the homomorphism sending all elements to `0`. -/
/-- `0` is the additive homomorphism sending all elements to `0`. -/
/-- `0` is the additive monoid homomorphism sending all elements to `0`. -/
@[simp] theorem one_hom.one_apply {M : Type u_1} {N : Type u_2} [HasOne M] [HasOne N] (x : M) :
coe_fn 1 x = 1 :=
rfl
@[simp] theorem add_monoid_hom.zero_apply {M : Type u_1} {N : Type u_2} [add_monoid M]
[add_monoid N] (x : M) : coe_fn 0 x = 0 :=
rfl
@[simp] theorem zero_hom.zero_comp {M : Type u_1} {N : Type u_2} {P : Type u_3} [HasZero M]
[HasZero N] [HasZero P] (f : zero_hom M N) : zero_hom.comp 0 f = 0 :=
rfl
@[simp] theorem zero_hom.comp_zero {M : Type u_1} {N : Type u_2} {P : Type u_3} [HasZero M]
[HasZero N] [HasZero P] (f : zero_hom N P) : zero_hom.comp f 0 = 0 :=
sorry
protected instance one_hom.inhabited {M : Type u_1} {N : Type u_2} [HasOne M] [HasOne N] :
Inhabited (one_hom M N) :=
{ default := 1 }
protected instance add_hom.inhabited {M : Type u_1} {N : Type u_2} [Add M] [add_monoid N] :
Inhabited (add_hom M N) :=
{ default := 0 }
-- unlike the other homs, `monoid_with_zero_hom` does not have a `1` or `0`
protected instance add_monoid_hom.inhabited {M : Type u_1} {N : Type u_2} [add_monoid M]
[add_monoid N] : Inhabited (M →+ N) :=
{ default := 0 }
protected instance monoid_with_zero_hom.inhabited {M : Type u_1} [monoid_with_zero M] :
Inhabited (monoid_with_zero_hom M M) :=
{ default := monoid_with_zero_hom.id M }
namespace monoid_hom
/-- Given two monoid morphisms `f`, `g` to a commutative monoid, `f * g` is the monoid morphism
sending `x` to `f x * g x`. -/
protected instance has_mul {M : Type u_1} {N : Type u_2} {mM : monoid M} [comm_monoid N] :
Mul (M →* N) :=
{ mul := fun (f g : M →* N) => mk (fun (m : M) => coe_fn f m * coe_fn g m) sorry sorry }
/-- Given two additive monoid morphisms `f`, `g` to an additive commutative monoid, `f + g` is the
additive monoid morphism sending `x` to `f x + g x`. -/
@[simp] theorem Mathlib.add_monoid_hom.add_apply {M : Type u_1} {N : Type u_2} {mM : add_monoid M}
{mN : add_comm_monoid N} (f : M →+ N) (g : M →+ N) (x : M) :
coe_fn (f + g) x = coe_fn f x + coe_fn g x :=
rfl
@[simp] theorem one_comp {M : Type u_1} {N : Type u_2} {P : Type u_3} [monoid M] [monoid N]
[monoid P] (f : M →* N) : comp 1 f = 1 :=
rfl
@[simp] theorem Mathlib.add_monoid_hom.comp_zero {M : Type u_1} {N : Type u_2} {P : Type u_3}
[add_monoid M] [add_monoid N] [add_monoid P] (f : N →+ P) : add_monoid_hom.comp f 0 = 0 :=
sorry
theorem mul_comp {M : Type u_1} {N : Type u_2} {P : Type u_3} [monoid M] [comm_monoid N]
[comm_monoid P] (g₁ : N →* P) (g₂ : N →* P) (f : M →* N) :
comp (g₁ * g₂) f = comp g₁ f * comp g₂ f :=
rfl
theorem comp_mul {M : Type u_1} {N : Type u_2} {P : Type u_3} [monoid M] [comm_monoid N]
[comm_monoid P] (g : N →* P) (f₁ : M →* N) (f₂ : M →* N) :
comp g (f₁ * f₂) = comp g f₁ * comp g f₂ :=
sorry
/-- (M →* N) is a comm_monoid if N is commutative. -/
protected instance comm_monoid {M : Type u_1} {N : Type u_2} [monoid M] [comm_monoid N] :
comm_monoid (M →* N) :=
comm_monoid.mk Mul.mul sorry 1 sorry sorry sorry
/-- `flip` arguments of `f : M →* N →* P` -/
def Mathlib.add_monoid_hom.flip {M : Type u_1} {N : Type u_2} {P : Type u_3} {mM : add_monoid M}
{mN : add_monoid N} {mP : add_comm_monoid P} (f : M →+ N →+ P) : N →+ M →+ P :=
add_monoid_hom.mk
(fun (y : N) => add_monoid_hom.mk (fun (x : M) => coe_fn (coe_fn f x) y) sorry sorry) sorry
sorry
@[simp] theorem flip_apply {M : Type u_1} {N : Type u_2} {P : Type u_3} {mM : monoid M}
{mN : monoid N} {mP : comm_monoid P} (f : M →* N →* P) (x : M) (y : N) :
coe_fn (coe_fn (flip f) y) x = coe_fn (coe_fn f x) y :=
rfl
/-- Evaluation of a `monoid_hom` at a point as a monoid homomorphism. See also `monoid_hom.apply`
for the evaluation of any function at a point. -/
def Mathlib.add_monoid_hom.eval {M : Type u_1} {N : Type u_2} [add_monoid M] [add_comm_monoid N] :
M →+ (M →+ N) →+ N :=
add_monoid_hom.flip (add_monoid_hom.id (M →+ N))
@[simp] theorem Mathlib.add_monoid_hom.eval_apply {M : Type u_1} {N : Type u_2} [add_monoid M]
[add_comm_monoid N] (x : M) (f : M →+ N) :
coe_fn (coe_fn add_monoid_hom.eval x) f = coe_fn f x :=
rfl
/-- Composition of monoid morphisms (`monoid_hom.comp`) as a monoid morphism. -/
def Mathlib.add_monoid_hom.comp_hom {M : Type u_1} {N : Type u_2} {P : Type u_3} [add_monoid M]
[add_comm_monoid N] [add_comm_monoid P] : (N →+ P) →+ (M →+ N) →+ M →+ P :=
add_monoid_hom.mk
(fun (g : N →+ P) =>
add_monoid_hom.mk (add_monoid_hom.comp g) sorry (add_monoid_hom.comp_add g))
sorry sorry
/-- If two homomorphism from a group to a monoid are equal at `x`, then they are equal at `x⁻¹`. -/
theorem eq_on_inv {M : Type u_1} {G : Type u_2} [group G] [monoid M] {f : G →* M} {g : G →* M}
{x : G} (h : coe_fn f x = coe_fn g x) : coe_fn f (x⁻¹) = coe_fn g (x⁻¹) :=
left_inv_eq_right_inv (map_mul_eq_one f (inv_mul_self x))
(Eq.subst (Eq.symm h) (map_mul_eq_one g) (mul_inv_self x))
/-- Group homomorphisms preserve inverse. -/
@[simp] theorem Mathlib.add_monoid_hom.map_neg {G : Type u_1} {H : Type u_2} [add_group G]
[add_group H] (f : G →+ H) (g : G) : coe_fn f (-g) = -coe_fn f g :=
eq_neg_of_add_eq_zero (add_monoid_hom.map_add_eq_zero f (neg_add_self g))
/-- Group homomorphisms preserve division. -/
@[simp] theorem Mathlib.add_monoid_hom.map_add_neg {G : Type u_1} {H : Type u_2} [add_group G]
[add_group H] (f : G →+ H) (g : G) (h : G) : coe_fn f (g + -h) = coe_fn f g + -coe_fn f h :=
sorry
/-- A homomorphism from a group to a monoid is injective iff its kernel is trivial. -/
theorem injective_iff {G : Type u_1} {H : Type u_2} [group G] [monoid H] (f : G →* H) :
function.injective ⇑f ↔ ∀ (a : G), coe_fn f a = 1 → a = 1 :=
sorry
/-- Makes a group homomorphism from a proof that the map preserves multiplication. -/
def Mathlib.add_monoid_hom.mk' {M : Type u_1} {G : Type u_4} [mM : add_monoid M] [add_group G]
(f : M → G) (map_mul : ∀ (a b : M), f (a + b) = f a + f b) : M →+ G :=
add_monoid_hom.mk f sorry map_mul
@[simp] theorem Mathlib.add_monoid_hom.coe_mk' {M : Type u_1} {G : Type u_4} [mM : add_monoid M]
[add_group G] {f : M → G} (map_mul : ∀ (a b : M), f (a + b) = f a + f b) :
⇑(add_monoid_hom.mk' f map_mul) = f :=
rfl
/-- Makes a group homomorphism from a proof that the map preserves right division `λ x y, x * y⁻¹`.
-/
def of_map_mul_inv {G : Type u_4} [group G] {H : Type u_1} [group H] (f : G → H)
(map_div : ∀ (a b : G), f (a * (b⁻¹)) = f a * (f b⁻¹)) : G →* H :=
mk' f sorry
@[simp] theorem Mathlib.add_monoid_hom.coe_of_map_add_neg {G : Type u_4} [add_group G]
{H : Type u_1} [add_group H] (f : G → H) (map_div : ∀ (a b : G), f (a + -b) = f a + -f b) :
⇑(add_monoid_hom.of_map_add_neg f map_div) = f :=
rfl
/-- If `f` is a monoid homomorphism to a commutative group, then `f⁻¹` is the homomorphism sending
`x` to `(f x)⁻¹`. -/
protected instance Mathlib.add_monoid_hom.has_neg {M : Type u_1} {G : Type u_2} [add_monoid M]
[add_comm_group G] : Neg (M →+ G) :=
{ neg := fun (f : M →+ G) => add_monoid_hom.mk' (fun (g : M) => -coe_fn f g) sorry }
/-- If `f` is an additive monoid homomorphism to an additive commutative group, then `-f` is the
homomorphism sending `x` to `-(f x)`. -/
@[simp] theorem inv_apply {M : Type u_1} {G : Type u_2} {mM : monoid M} {gG : comm_group G}
(f : M →* G) (x : M) : coe_fn (f⁻¹) x = (coe_fn f x⁻¹) :=
rfl
/-- If `f` and `g` are monoid homomorphisms to a commutative group, then `f / g` is the homomorphism
sending `x` to `(f x) / (g x). -/
protected instance has_div {M : Type u_1} {G : Type u_2} [monoid M] [comm_group G] : Div (M →* G) :=
{ div := fun (f g : M →* G) => mk' (fun (x : M) => coe_fn f x / coe_fn g x) sorry }
/-- If `f` and `g` are monoid homomorphisms to an additive commutative group, then `f - g`
is the homomorphism sending `x` to `(f x) - (g x). -/
@[simp] theorem Mathlib.add_monoid_hom.sub_apply {M : Type u_1} {G : Type u_2} {mM : add_monoid M}
{gG : add_comm_group G} (f : M →+ G) (g : M →+ G) (x : M) :
coe_fn (f - g) x = coe_fn f x - coe_fn g x :=
rfl
/-- If `G` is a commutative group, then `M →* G` a commutative group too. -/
protected instance Mathlib.add_monoid_hom.add_comm_group {M : Type u_1} {G : Type u_2}
[add_monoid M] [add_comm_group G] : add_comm_group (M →+ G) :=
add_comm_group.mk add_comm_monoid.add sorry add_comm_monoid.zero sorry sorry Neg.neg Sub.sub sorry
sorry
/-- If `G` is an additive commutative group, then `M →+ G` an additive commutative group too. -/
end monoid_hom
namespace add_monoid_hom
/-- Additive group homomorphisms preserve subtraction. -/
@[simp] theorem map_sub {G : Type u_4} {H : Type u_5} [add_group G] [add_group H] (f : G →+ H)
(g : G) (h : G) : coe_fn f (g - h) = coe_fn f g - coe_fn f h :=
sorry
/-- Define a morphism of additive groups given a map which respects difference. -/
def of_map_sub {G : Type u_4} {H : Type u_5} [add_group G] [add_group H] (f : G → H)
(hf : ∀ (x y : G), f (x - y) = f x - f y) : G →+ H :=
of_map_add_neg f sorry
@[simp] theorem coe_of_map_sub {G : Type u_4} {H : Type u_5} [add_group G] [add_group H] (f : G → H)
(hf : ∀ (x y : G), f (x - y) = f x - f y) : ⇑(of_map_sub f hf) = f :=
rfl
end add_monoid_hom
@[simp] protected theorem add_semiconj_by.map {M : Type u_1} {N : Type u_2} [add_monoid M]
[add_monoid N] {a : M} {x : M} {y : M} (h : add_semiconj_by a x y) (f : M →+ N) :
add_semiconj_by (coe_fn f a) (coe_fn f x) (coe_fn f y) :=
sorry
@[simp] protected theorem add_commute.map {M : Type u_1} {N : Type u_2} [add_monoid M]
[add_monoid N] {x : M} {y : M} (h : add_commute x y) (f : M →+ N) :
add_commute (coe_fn f x) (coe_fn f y) :=
add_semiconj_by.map h f
end Mathlib |
module Data.PullRequest
import Data.Config
import Data.Date
import Data.Either
import Data.List
import Data.Vect
import Language.JSON
import Language.JSON.Accessors
%default total
public export
data PRState = Open | Closed
export
Show PRState where
show Open = "open"
show Closed = "closed"
export
Eq PRState where
Open == Open = True
Closed == Closed = True
_ == _ = False
public export
record PullRequest where
constructor MkPullRequest
||| The pull request's "number" (as seen in URIs referring to the PR).
number : Integer
||| When the PR was created.
createdAt : Date
||| The `login` of the author of the pull request.
author : String
||| Open or Closed status.
state : PRState
||| A List of all reviewers requested on the PR.
reviewers : List String
%name PullRequest pr, pr1, pr2
export
Show PullRequest where
show (MkPullRequest number _ author state _) = "\{show number}: \{show author} (\{show state})"
export
(.webURI) : Config => PullRequest -> String
pr.webURI @{config} = "https://github.com/\{config.org}/\{config.repo}/pull/\{show pr.number}"
export
isAuthor : String -> PullRequest -> Bool
isAuthor login = (== login) . author
export
isRequestedReviewer : String -> PullRequest -> Bool
isRequestedReviewer login = any (== login) . reviewers
parseState : String -> Either String PRState
parseState "open" = Right Open
parseState "closed" = Right Closed
parseState str = Left "Failed to parse a Pull Request State (open/closed). Found \{str}."
parseDateTime : String -> Either String Date
parseDateTime = maybeToEither "Failed to parse Date" . parseDateTimeString
export
parsePR : JSON -> Either String PullRequest
parsePR json =
do pr <- object json
[pullNumber, authorLogin, stateStr, createdAtStr, reviewerList] <- lookupAll ["pull_number", "author", "state", "created_at", "reviewers"] pr
number <- integer pullNumber
author <- string authorLogin
state <- parseState =<< string stateStr
createdAt <- parseDateTime =<< string createdAtStr
reviewers <- array string reviewerList
pure $ MkPullRequest {
number
, createdAt
, author
, state
, reviewers
}
||| Parse a single user from a JSON String
export
parsePullRequestString : String -> Either String PullRequest
parsePullRequestString =
(maybeToEither "Failed to parse JSON" . JSON.parse) >=> parsePR
||| Parse a list of users from a JSON String
export
parsePullRequestsString : String -> Either String (List PullRequest)
parsePullRequestsString =
(maybeToEither "Failed to parse JSON" . JSON.parse) >=> array parsePR
|
Formal statement is: lemma (in ring_of_sets) positive_cong_eq: "(\<And>a. a \<in> M \<Longrightarrow> \<mu>' a = \<mu> a) \<Longrightarrow> positive M \<mu>' = positive M \<mu>" Informal statement is: If two measures agree on a ring of sets, then they agree on the positive sets of that ring. |
`is_element/morse_matchings` := (A::set) -> (R) -> proc(M)
global reason;
local e,H,F;
if not(type(M,set)) then
reason := ["is_element/morse_matchings","M is not a set",M];
return false;
fi;
for e in M do
if not(type(e,list)) and nops(e) = 2 then
reason := ["is_element/morse_matchings","M is not a set of lists of length 2",M,e];
return false;
fi;
if {op(e)} minus A <> {} then
reason := ["is_element/morse_matchings","M is not a set of lists of length 2 in A",M,e];
return false;
fi;
od:
H := `hasse_diagram/partord`(A)(R);
if M minus H <> {} then
reason := ["is_element/morse_matchings","M is not a subset of the Hasse diagram",M,H];
return false;
fi;
for e in M do
if select(f -> {op(f)} intersect {op(e)} <> {}, M) <> {e} then
reason := ["is_element/morse_matchings","edges in M are not disjoint",M,e];
return false;
fi;
od:
F := M union map(e -> [e[2],e[1]],H minus M);
F := `transitive_closure/autorel`(A)(F);
F := F intersect `op/autorel`(A)(F);
if F minus `id/autorel`(A) <> {} then
reason := ["is_element/morse_matchings","M has cycles",M,F];
return false;
fi;
return true;
end:
|
[STATEMENT]
lemma wd_repeat:
"well_def a \<Longrightarrow> well_def (repeat n a)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. well_def a \<Longrightarrow> well_def (repeat n a)
[PROOF STEP]
by(blast intro:healthy_wp_repeat nearly_healthy_wlp_repeat
wp_under_wlp_repeat sdp_repeat sublinear_wp_repeat cts_wp_repeat) |
#' metacell
#'
#' @import dplyr
#' @import ggplot2
#' @import tgconfig
#' @import tgstat
#' @import tgutil
#' @import igraph
#' @importFrom pdist pdist
#' @importFrom cluster silhouette
#' @name metacell
#' @docType package
NULL
|
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.int.basic
import Mathlib.data.nat.cast
import Mathlib.PostPort
universes u_1 u_2
namespace Mathlib
namespace int
/- cast (injection into groups with one) -/
@[simp] theorem nat_cast_eq_coe_nat (n : ℕ) : ↑n = ↑n := sorry
/-- Coercion `ℕ → ℤ` as a `ring_hom`. -/
def of_nat_hom : ℕ →+* ℤ :=
ring_hom.mk coe sorry of_nat_mul sorry of_nat_add
/-- Canonical homomorphism from the integers to any ring(-like) structure `α` -/
protected def cast {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] : ℤ → α :=
sorry
-- see Note [coercion into rings]
protected instance cast_coe {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] : has_coe_t ℤ α :=
has_coe_t.mk int.cast
@[simp] theorem cast_zero {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] : ↑0 = 0 :=
rfl
theorem cast_of_nat {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] (n : ℕ) : ↑(Int.ofNat n) = ↑n :=
rfl
@[simp] theorem cast_coe_nat {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] (n : ℕ) : ↑↑n = ↑n :=
rfl
theorem cast_coe_nat' {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] (n : ℕ) : ↑↑n = ↑n := sorry
@[simp] theorem cast_neg_succ_of_nat {α : Type u_1} [HasZero α] [HasOne α] [Add α] [Neg α] (n : ℕ) : ↑(Int.negSucc n) = -(↑n + 1) :=
rfl
@[simp] theorem cast_one {α : Type u_1} [add_monoid α] [HasOne α] [Neg α] : ↑1 = 1 :=
nat.cast_one
@[simp] theorem cast_sub_nat_nat {α : Type u_1} [add_group α] [HasOne α] (m : ℕ) (n : ℕ) : ↑(sub_nat_nat m n) = ↑m - ↑n := sorry
@[simp] theorem cast_neg_of_nat {α : Type u_1} [add_group α] [HasOne α] (n : ℕ) : ↑(neg_of_nat n) = -↑n :=
nat.cases_on n (idRhs (0 = -0) (Eq.symm neg_zero))
fun (n : ℕ) => idRhs (↑(neg_of_nat (n + 1)) = ↑(neg_of_nat (n + 1))) rfl
@[simp] theorem cast_add {α : Type u_1} [add_group α] [HasOne α] (m : ℤ) (n : ℤ) : ↑(m + n) = ↑m + ↑n := sorry
@[simp] theorem cast_neg {α : Type u_1} [add_group α] [HasOne α] (n : ℤ) : ↑(-n) = -↑n :=
int.cases_on n (fun (n : ℕ) => idRhs (↑(neg_of_nat n) = -↑n) (cast_neg_of_nat n))
fun (n : ℕ) => idRhs (↑(-Int.negSucc n) = --↑(-Int.negSucc n)) (Eq.symm (neg_neg ↑(-Int.negSucc n)))
@[simp] theorem cast_sub {α : Type u_1} [add_group α] [HasOne α] (m : ℤ) (n : ℤ) : ↑(m - n) = ↑m - ↑n := sorry
@[simp] theorem cast_mul {α : Type u_1} [ring α] (m : ℤ) (n : ℤ) : ↑(m * n) = ↑m * ↑n := sorry
/-- `coe : ℤ → α` as an `add_monoid_hom`. -/
def cast_add_hom (α : Type u_1) [add_group α] [HasOne α] : ℤ →+ α :=
add_monoid_hom.mk coe sorry cast_add
@[simp] theorem coe_cast_add_hom {α : Type u_1} [add_group α] [HasOne α] : ⇑(cast_add_hom α) = coe :=
rfl
/-- `coe : ℤ → α` as a `ring_hom`. -/
def cast_ring_hom (α : Type u_1) [ring α] : ℤ →+* α :=
ring_hom.mk coe sorry cast_mul sorry sorry
@[simp] theorem coe_cast_ring_hom {α : Type u_1} [ring α] : ⇑(cast_ring_hom α) = coe :=
rfl
theorem cast_commute {α : Type u_1} [ring α] (m : ℤ) (x : α) : commute (↑m) x :=
int.cases_on m (fun (n : ℕ) => nat.cast_commute n x) fun (n : ℕ) => commute.neg_left (nat.cast_commute (n + 1) x)
theorem commute_cast {α : Type u_1} [ring α] (x : α) (m : ℤ) : commute x ↑m :=
commute.symm (cast_commute m x)
@[simp] theorem coe_nat_bit0 (n : ℕ) : ↑(bit0 n) = bit0 ↑n := sorry
@[simp] theorem coe_nat_bit1 (n : ℕ) : ↑(bit1 n) = bit1 ↑n := sorry
@[simp] theorem cast_bit0 {α : Type u_1} [ring α] (n : ℤ) : ↑(bit0 n) = bit0 ↑n :=
cast_add n n
@[simp] theorem cast_bit1 {α : Type u_1} [ring α] (n : ℤ) : ↑(bit1 n) = bit1 ↑n := sorry
theorem cast_two {α : Type u_1} [ring α] : ↑(bit0 1) = bit0 1 := sorry
theorem cast_mono {α : Type u_1} [ordered_ring α] : monotone coe := sorry
@[simp] theorem cast_nonneg {α : Type u_1} [ordered_ring α] [nontrivial α] {n : ℤ} : 0 ≤ ↑n ↔ 0 ≤ n := sorry
@[simp] theorem cast_le {α : Type u_1} [ordered_ring α] [nontrivial α] {m : ℤ} {n : ℤ} : ↑m ≤ ↑n ↔ m ≤ n := sorry
theorem cast_strict_mono {α : Type u_1} [ordered_ring α] [nontrivial α] : strict_mono coe :=
strict_mono_of_le_iff_le fun (m n : ℤ) => iff.symm cast_le
@[simp] theorem cast_lt {α : Type u_1} [ordered_ring α] [nontrivial α] {m : ℤ} {n : ℤ} : ↑m < ↑n ↔ m < n :=
strict_mono.lt_iff_lt cast_strict_mono
@[simp] theorem cast_nonpos {α : Type u_1} [ordered_ring α] [nontrivial α] {n : ℤ} : ↑n ≤ 0 ↔ n ≤ 0 :=
eq.mpr (id (Eq._oldrec (Eq.refl (↑n ≤ 0 ↔ n ≤ 0)) (Eq.symm cast_zero)))
(eq.mpr (id (Eq._oldrec (Eq.refl (↑n ≤ ↑0 ↔ n ≤ 0)) (propext cast_le))) (iff.refl (n ≤ 0)))
@[simp] theorem cast_pos {α : Type u_1} [ordered_ring α] [nontrivial α] {n : ℤ} : 0 < ↑n ↔ 0 < n :=
eq.mpr (id (Eq._oldrec (Eq.refl (0 < ↑n ↔ 0 < n)) (Eq.symm cast_zero)))
(eq.mpr (id (Eq._oldrec (Eq.refl (↑0 < ↑n ↔ 0 < n)) (propext cast_lt))) (iff.refl (0 < n)))
@[simp] theorem cast_lt_zero {α : Type u_1} [ordered_ring α] [nontrivial α] {n : ℤ} : ↑n < 0 ↔ n < 0 :=
eq.mpr (id (Eq._oldrec (Eq.refl (↑n < 0 ↔ n < 0)) (Eq.symm cast_zero)))
(eq.mpr (id (Eq._oldrec (Eq.refl (↑n < ↑0 ↔ n < 0)) (propext cast_lt))) (iff.refl (n < 0)))
@[simp] theorem cast_min {α : Type u_1} [linear_ordered_ring α] {a : ℤ} {b : ℤ} : ↑(min a b) = min ↑a ↑b :=
monotone.map_min cast_mono
@[simp] theorem cast_max {α : Type u_1} [linear_ordered_ring α] {a : ℤ} {b : ℤ} : ↑(max a b) = max ↑a ↑b :=
monotone.map_max cast_mono
@[simp] theorem cast_abs {α : Type u_1} [linear_ordered_ring α] {q : ℤ} : ↑(abs q) = abs ↑q := sorry
theorem coe_int_dvd {α : Type u_1} [comm_ring α] (m : ℤ) (n : ℤ) (h : m ∣ n) : ↑m ∣ ↑n :=
ring_hom.map_dvd (cast_ring_hom α) h
end int
namespace add_monoid_hom
/-- Two additive monoid homomorphisms `f`, `g` from `ℤ` to an additive monoid are equal
if `f 1 = g 1`. -/
theorem ext_int {A : Type u_1} [add_monoid A] {f : ℤ →+ A} {g : ℤ →+ A} (h1 : coe_fn f 1 = coe_fn g 1) : f = g := sorry
theorem eq_int_cast_hom {A : Type u_1} [add_group A] [HasOne A] (f : ℤ →+ A) (h1 : coe_fn f 1 = 1) : f = int.cast_add_hom A := sorry
theorem eq_int_cast {A : Type u_1} [add_group A] [HasOne A] (f : ℤ →+ A) (h1 : coe_fn f 1 = 1) (n : ℤ) : coe_fn f n = ↑n :=
iff.mp ext_iff (eq_int_cast_hom f h1)
end add_monoid_hom
namespace monoid_hom
theorem ext_int {M : Type u_1} [monoid M] {f : multiplicative ℤ →* M} {g : multiplicative ℤ →* M} (h1 : coe_fn f (coe_fn multiplicative.of_add 1) = coe_fn g (coe_fn multiplicative.of_add 1)) : f = g :=
ext fun (x : multiplicative ℤ) => iff.mp add_monoid_hom.ext_iff (add_monoid_hom.ext_int h1) x
end monoid_hom
namespace ring_hom
@[simp] theorem eq_int_cast {α : Type u_1} [ring α] (f : ℤ →+* α) (n : ℤ) : coe_fn f n = ↑n :=
add_monoid_hom.eq_int_cast (to_add_monoid_hom f) (map_one f) n
theorem eq_int_cast' {α : Type u_1} [ring α] (f : ℤ →+* α) : f = int.cast_ring_hom α :=
ext (eq_int_cast f)
@[simp] theorem map_int_cast {α : Type u_1} {β : Type u_2} [ring α] [ring β] (f : α →+* β) (n : ℤ) : coe_fn f ↑n = ↑n :=
eq_int_cast (comp f (int.cast_ring_hom α)) n
theorem ext_int {R : Type u_1} [semiring R] (f : ℤ →+* R) (g : ℤ →+* R) : f = g :=
coe_add_monoid_hom_injective (add_monoid_hom.ext_int (Eq.trans (map_one f) (Eq.symm (map_one g))))
protected instance int.subsingleton_ring_hom {R : Type u_1} [semiring R] : subsingleton (ℤ →+* R) :=
subsingleton.intro ext_int
end ring_hom
@[simp] theorem int.cast_id (n : ℤ) : ↑n = n :=
Eq.symm (ring_hom.eq_int_cast (ring_hom.id ℤ) n)
|
[STATEMENT]
lemma ex_crossing_path:
assumes path_Q: "Q \<in> \<P>"
shows "\<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
obtain a where a_inQ: "a \<in> Q"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (\<And>a. a \<in> Q \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using ge2_events_lax path_Q
[PROOF STATE]
proof (prove)
using this:
?Q \<in> \<P> \<Longrightarrow> \<exists>a\<in>?Q. \<exists>b\<in>?Q. a \<noteq> b
Q \<in> \<P>
goal (1 subgoal):
1. (\<And>a. a \<in> Q \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
a \<in> Q
goal (1 subgoal):
1. \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
obtain d where d_event: "d \<in> \<E>"
and d_notinQ: "d \<notin> Q"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (\<And>d. \<lbrakk>d \<in> \<E>; d \<notin> Q\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using external_event path_Q
[PROOF STATE]
proof (prove)
using this:
?Q \<in> \<P> \<Longrightarrow> \<exists>d\<in>\<E>. d \<notin> ?Q
Q \<in> \<P>
goal (1 subgoal):
1. (\<And>d. \<lbrakk>d \<in> \<E>; d \<notin> Q\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
d \<in> \<E>
d \<notin> Q
goal (1 subgoal):
1. \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
d \<in> \<E>
d \<notin> Q
[PROOF STEP]
have "a \<noteq> d"
[PROOF STATE]
proof (prove)
using this:
d \<in> \<E>
d \<notin> Q
goal (1 subgoal):
1. a \<noteq> d
[PROOF STEP]
using a_inQ
[PROOF STATE]
proof (prove)
using this:
d \<in> \<E>
d \<notin> Q
a \<in> Q
goal (1 subgoal):
1. a \<noteq> d
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
a \<noteq> d
goal (1 subgoal):
1. \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
a \<noteq> d
[PROOF STEP]
have ex_through_d: "\<exists>R\<in>\<P>. \<exists>S\<in>\<P>. a \<in> R \<and> d \<in> S \<and> R \<inter> S \<noteq> {}"
[PROOF STATE]
proof (prove)
using this:
a \<noteq> d
goal (1 subgoal):
1. \<exists>R\<in>\<P>. \<exists>S\<in>\<P>. a \<in> R \<and> d \<in> S \<and> R \<inter> S \<noteq> {}
[PROOF STEP]
using events_paths [where a = a and b = d]
path_Q a_inQ in_path_event d_event
[PROOF STATE]
proof (prove)
using this:
a \<noteq> d
\<lbrakk>a \<in> \<E>; d \<in> \<E>; a \<noteq> d\<rbrakk> \<Longrightarrow> \<exists>R\<in>\<P>. \<exists>S\<in>\<P>. a \<in> R \<and> d \<in> S \<and> R \<inter> S \<noteq> {}
Q \<in> \<P>
a \<in> Q
\<lbrakk>?Q \<in> \<P>; ?a \<in> ?Q\<rbrakk> \<Longrightarrow> ?a \<in> \<E>
d \<in> \<E>
goal (1 subgoal):
1. \<exists>R\<in>\<P>. \<exists>S\<in>\<P>. a \<in> R \<and> d \<in> S \<and> R \<inter> S \<noteq> {}
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
\<exists>R\<in>\<P>. \<exists>S\<in>\<P>. a \<in> R \<and> d \<in> S \<and> R \<inter> S \<noteq> {}
goal (1 subgoal):
1. \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<exists>R\<in>\<P>. \<exists>S\<in>\<P>. a \<in> R \<and> d \<in> S \<and> R \<inter> S \<noteq> {}
[PROOF STEP]
obtain R S where path_R: "R \<in> \<P>"
and path_S: "S \<in> \<P>"
and a_inR: "a \<in> R"
and d_inS: "d \<in> S"
and R_crosses_S: "R \<inter> S \<noteq> {}"
[PROOF STATE]
proof (prove)
using this:
\<exists>R\<in>\<P>. \<exists>S\<in>\<P>. a \<in> R \<and> d \<in> S \<and> R \<inter> S \<noteq> {}
goal (1 subgoal):
1. (\<And>R S. \<lbrakk>R \<in> \<P>; S \<in> \<P>; a \<in> R; d \<in> S; R \<inter> S \<noteq> {}\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
R \<in> \<P>
S \<in> \<P>
a \<in> R
d \<in> S
R \<inter> S \<noteq> {}
goal (1 subgoal):
1. \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
have S_neq_Q: "S \<noteq> Q"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. S \<noteq> Q
[PROOF STEP]
using d_notinQ d_inS
[PROOF STATE]
proof (prove)
using this:
d \<notin> Q
d \<in> S
goal (1 subgoal):
1. S \<noteq> Q
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
S \<noteq> Q
goal (1 subgoal):
1. \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
proof cases
[PROOF STATE]
proof (state)
goal (2 subgoals):
1. ?P \<Longrightarrow> \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
2. \<not> ?P \<Longrightarrow> \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
assume "R = Q"
[PROOF STATE]
proof (state)
this:
R = Q
goal (2 subgoals):
1. ?P \<Longrightarrow> \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
2. \<not> ?P \<Longrightarrow> \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
R = Q
[PROOF STEP]
have "Q \<inter> S \<noteq> {}"
[PROOF STATE]
proof (prove)
using this:
R = Q
goal (1 subgoal):
1. Q \<inter> S \<noteq> {}
[PROOF STEP]
using R_crosses_S
[PROOF STATE]
proof (prove)
using this:
R = Q
R \<inter> S \<noteq> {}
goal (1 subgoal):
1. Q \<inter> S \<noteq> {}
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
Q \<inter> S \<noteq> {}
goal (2 subgoals):
1. ?P \<Longrightarrow> \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
2. \<not> ?P \<Longrightarrow> \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
thus ?thesis
[PROOF STATE]
proof (prove)
using this:
Q \<inter> S \<noteq> {}
goal (1 subgoal):
1. \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
using S_neq_Q path_S
[PROOF STATE]
proof (prove)
using this:
Q \<inter> S \<noteq> {}
S \<noteq> Q
S \<in> \<P>
goal (1 subgoal):
1. \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
\<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
goal (1 subgoal):
1. R \<noteq> Q \<Longrightarrow> \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. R \<noteq> Q \<Longrightarrow> \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
assume "R \<noteq> Q"
[PROOF STATE]
proof (state)
this:
R \<noteq> Q
goal (1 subgoal):
1. R \<noteq> Q \<Longrightarrow> \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
thus ?thesis
[PROOF STATE]
proof (prove)
using this:
R \<noteq> Q
goal (1 subgoal):
1. \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
using a_inQ a_inR path_R
[PROOF STATE]
proof (prove)
using this:
R \<noteq> Q
a \<in> Q
a \<in> R
R \<in> \<P>
goal (1 subgoal):
1. \<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
\<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)
goal:
No subgoals!
[PROOF STEP]
qed |
(* Title: HOL/Auth/n_german_lemma_inv__3_on_rules.thy
Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences
Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences
*)
header{*The n_german Protocol Case Study*}
theory n_german_lemma_inv__3_on_rules imports n_german_lemma_on_inv__3
begin
section{*All lemmas on causal relation between inv__3*}
lemma lemma_inv__3_on_rules:
assumes b1: "r \<in> rules N" and b2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__3 p__Inv4)"
shows "invHoldForRule s f r (invariants N)"
proof -
have c1: "(\<exists> j. j\<le>N\<and>r=n_SendReqS j)\<or>
(\<exists> i. i\<le>N\<and>r=n_SendReqEI i)\<or>
(\<exists> i. i\<le>N\<and>r=n_SendReqES i)\<or>
(\<exists> i. i\<le>N\<and>r=n_RecvReq N i)\<or>
(\<exists> i. i\<le>N\<and>r=n_SendInvE i)\<or>
(\<exists> i. i\<le>N\<and>r=n_SendInvS i)\<or>
(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)\<or>
(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)\<or>
(\<exists> i. i\<le>N\<and>r=n_SendGntS i)\<or>
(\<exists> i. i\<le>N\<and>r=n_SendGntE N i)\<or>
(\<exists> i. i\<le>N\<and>r=n_RecvGntS i)\<or>
(\<exists> i. i\<le>N\<and>r=n_RecvGntE i)\<or>
(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)"
apply (cut_tac b1, auto) done
moreover {
assume d1: "(\<exists> j. j\<le>N\<and>r=n_SendReqS j)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_SendReqSVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqEI i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_SendReqEIVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqES i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_SendReqESVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReq N i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_RecvReqVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInvE i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_SendInvEVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInvS i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_SendInvSVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_SendInvAckVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_RecvInvAckVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendGntS i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_SendGntSVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendGntE N i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_SendGntEVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntS i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_RecvGntSVsinv__3) done
}
moreover {
assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntE i)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_RecvGntEVsinv__3) done
}
moreover {
assume d1: "(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)"
have "invHoldForRule s f r (invariants N)"
apply (cut_tac b2 d1, metis n_StoreVsinv__3) done
}
ultimately show "invHoldForRule s f r (invariants N)"
by satx
qed
end
|
lemma bounded_translation: fixes S :: "'a::real_normed_vector set" assumes "bounded S" shows "bounded ((\<lambda>x. a + x) ` S)" |
Formal statement is: lemma residue_simple: assumes "open s" "z\<in>s" and f_holo:"f holomorphic_on s" shows "residue (\<lambda>w. f w / (w - z)) z = f z" Informal statement is: If $f$ is holomorphic on an open set $s$ and $z \in s$, then the residue of $f(w)/(w-z)$ at $z$ is $f(z)$. |
$-a \in \mathbb{R}$ if and only if $a \in \mathbb{R}$. |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.