text
stringlengths 0
3.34M
|
---|
-- ------------------------------------------------------------- [ Chargen.idr ]
--
-- This RFC specifies a standard for the ARPA Internet community.
-- Hosts on the ARPA Internet that choose to implement a Character
-- Generator Protocol are expected to adopt and implement this
-- standard.
-- A useful debugging and measurement tool is a character generator
-- service. A character generator service simply sends data without
-- regard to the input.
--
-- The data may be anything. It is recommended that a recognizable
-- pattern be used in tha data.
--
-- One popular pattern is 72 chraracter lines of the ASCII printing
-- characters. There are 95 printing characters in the ASCII
-- character set. Sort the characters into an ordered sequence and
-- number the characters from 0 through 94. Think of the sequence as
-- a ring so that character number 0 follows character number 94. On
-- the first line (line 0) put the characters numbered 0 through
-- 71. On the next line (line 1) put the characters numbered 1 through
-- 72. And so on. On line N, put characters (0+N mod 95) through
-- (71+N mod 95). End each line with carriage return and line feed.
--
-- http://tools.ietf.org/html/rfc864
-- --------------------------------------------------------------------- [ EOH ]
module RFC.CharGen
import Effects
import Effect.Default
import Effect.StdIO
import System.Protocol
||| A useful debugging and measurement tool is a character generator
||| service. A character generator service simply sends data without
||| regard to the input. The data may be anything. It is recommended
||| that a recognizable pattern be used in tha data.
total
chargen : Protocol ['Client, 'Server] ()
chargen = do
msg <- 'Client ==> 'Server | Maybe String
case msg of
Just m => do
'Server ==> 'Client | String
Rec chargen
Nothing => Done
-- --------------------------------------------------------------------- [ EOF ]
|
import order.galois_connection
universe u
variables X Y : Type u
def VR {X Y} (R: X → Y → Prop) (S : set X) : set Y := {y : Y | ∀ (s ∈ S), R s y}
def IR {X Y} (R: X → Y → Prop) (T : set Y) : set X := {x : X | ∀ (t ∈ T), R x t}
def subsetrel {X} : preorder (set X) := {
le := λ A B, A ⊆ B,
le_refl := set.subset.refl,
le_trans := begin
intros A B C,
dsimp,
exact set.subset.trans,
end,
}
def supsetrel {Y} : preorder (set Y) := {
le := λ A B, A ⊇ B,
le_refl := set.subset.refl,
le_trans := begin
intros A B C,
dsimp,
intros hAB hBC,
apply set.subset.trans,
exact hBC,
exact hAB,
end,
}
-- exercise 1a
-- use @galois_connection to be able to provide all arguments explicitly
-- in particular we want to provide the preorders that way to be able to use different ones on P(X) and P(Y)
lemma ex1a (R : X → Y → Prop): @galois_connection (set X) (set Y) subsetrel supsetrel (VR R) (IR R) := begin
intros S T,
split,
{
show VR R S ⊇ T → S ⊆ IR R T,
intro h,
intros s hs,
intros t ht,
specialize h ht,
specialize h s hs,
exact h,
},
{
show S ⊆ IR R T → VR R S ⊇ T,
intro h,
intros t ht,
intros s hs,
specialize h hs,
specialize h t ht,
exact h,
},
end
|
%% Transient diffusion equation evaluated using FVTool
%
% adapted from A.A. Eftekhari by M.H.V. Werts (2020)
%
% GNU Octave 4.2.2 was used for development
%
% This script is intended to be run from the command line interface.
% It is called in this manner from within the accompanying Jupyter
% Python notebook.
%
% It should be inside the 'FVTool' directory tree as downloaded/cloned
% from Github, under
% './Examples/External/Diffusion1DSpherical_Analytic-vs-FVTool-vs-Fipy'
%
% Script calculates diffusion in a 1D spherical geometry for an 'infinite'
% medium, with the initial condition that all mass at $t = 0$ is
% homogeneously confined inside a sphere of radius $a$. This is sometimes
% called a 'spherical initial condition'.
%
% see J. Crank (1975) "The Mathematics of Diffusion", 2nd Ed.,
% Clarendon Press (Oxford), pages 29-30
% Equation 3.8, Figure 3.1
%
% The transient diffusion equation reads
%
% $$\alpha\frac{\partial c}{\partial t}+\nabla.\left(-D\nabla c\right)=0,$$
%
% where $c$ is the independent variable (concentration, temperature, etc),
% $D$ is the diffusion coefficient, and $\alpha$ is a constant (1, here).
%
%
clc; clear;
more off;
run('../../../FVToolStartUp.m')
%% Define the domain and create a mesh structure
% Here we work in a 1D spherical coordinate system (r coordinate)
L = 10.0; % domain length
Nx = 2000; % number of cells
m = createMeshSpherical1D(Nx, L);
%% Create the boundary condition structure
BC = createBC(m); % all Neumann boundary condition structure
%% define the transfer coeffs
D = createCellVariable(m, 1.0);
alfa = createCellVariable(m, 1.0);
%% define initial condition
c_init = 0;
c_old = createCellVariable(m, c_init, BC); % initial values
r = c_old.domain.cellcenters.x;
c_old.value(r<1.0) = 1.0;
%% calculate volumes of FV cellslices
% We use this for demonstrating mass conservation
cellA = m.facecenters.x(1:end-1);
cellB = m.facecenters.x(2:end);
cellvol = 4/3 .* pi .* (cellB.^3 - cellA.^3);
cellsum = sum(cellvol)
c = c_old; % assign the old value of the cells to the current values
t = 0.0; % master time
deltat = 0.0625/20; % time step
% output total mass in the system
m_tot = sum(c.value(2:end-1) .* cellvol);
t,m_tot
%% loop for "time-stepping" the solution
% It outputs the spatial profile C(r) after
% 20, 80 and 320 time-steps
% This corresponds to t=0.0625, t=0.25 and t=1, respectively.
ti = 0
for s=[20,60,240]
for n=1:s
[M_trans, RHS_trans] = transientTerm(c, deltat, alfa);
Dave = harmonicMean(D);
Mdiff = diffusionTerm(Dave);
[Mbc, RHSbc] = boundaryCondition(BC);
M = M_trans-Mdiff+Mbc;
RHS = RHS_trans+RHSbc;
c = solvePDE(m,M, RHS);
t += deltat;
c_old = c;
endfor
m_tot = sum(c.value(2:end-1) .* cellvol);
n,t,m_tot
% The following writes the result to a file
% adapted from visualizeCells with domain.dimension = 1.8
x = [c.domain.facecenters.x(1); c.domain.cellcenters.x; c.domain.facecenters.x(end)];
cval = [0.5*(c.value(1)+c.value(2)); c.value(2:end-1); 0.5*(c.value(end-1)+c.value(end))];
ti += s;
filename = ["diffusion1Dspherical_FVTool_tstep",num2str(ti),".mat"]
save('-6',filename,'x','cval');
endfor
|
# Base rate fallacy example
In this notenook we work an example of the base rate fallacy using Bayes Theorem.
Assume that we have two random variables $HasDisease$ and $FailsTest$. $HasDisease=y$ indicates that a person has the disease while $HasDisease=n$ indicates that the person in disease free. In addition, we have a test which attempts to detect the disease. $FailsTest=y$ indicates that our test says a person hasthe disease while $FailsTest=n$ indicates that our test says a person does not have the disease.
In this notebook you can play around with the probabilities of interest and see now likely it is that, given you fail the test, that you actually have the disease.
Suppose we know the following probabilities:
\begin{align}
Pr(FailsTest=y | HasDisease=y) &= FailAndHasDisease \\
Pr(FailsTest=n | HasDisease=y) &= NotFailAndHasDisease \\
Pr(FailsTest=y | HasDisease=n) &= FailAndNotHasDisease \\
Pr(FailsTest=n | HasDisease=n) &= NotFailAndNotHasDisease \\
\end{align}
And we know the prior probability of the disease in the population
$$
Pr(HasDisease=y).
$$
Note, the point of the base rate fallacy is that you need all <i>5</i> probabilities to compute what you are interested in, namely <i>the probability you have the disease given you fail the test</i>, denoted
$$
Pr(HasDisease=y | FailsTest=y).
$$
Without, $Pr(HasDisease=y)$ you cannot truly understand $Pr(HasDisease=y | FailsTest=y)$.
You can play aroun with the numbers in the next cell to see how things work out.
```python
FailAndHasDisease = 1.0
NotFailAndHasDisease = 0.0
FailAndNotHasDisease = 0.01
NotFailAndNotHasDisease = 0.99
HasDisease = 1./1000
```
Bayes theorem says that
$$
Pr(HasDisease=y | FailsTest=y) = \frac{Pr(FailsTest=y | HasDisease=y) Pr(HasDisease=y)}{Pr(FailsTest=y)}
$$
Our table gives us the two terms in the numerator, we get the demoninator from the Law of total probability.
\begin{align}
Pr(FailsTest=y) & = Pr(FailsTest=y | HasDisease=y) Pr(HasDisease=y) + Pr(FailsTest=y | HasDisease=n) Pr(HasDisease=n) \\
& = Pr(FailsTest=y | HasDisease=y) Pr(HasDisease=y) + Pr(FailsTest=y | HasDisease=n) (1- Pr(HasDisease=y))
\end{align}
So, the whole thing is
$$
Pr(HasDisease=y | FailsTest=y) = \frac{Pr(FailsTest=y | HasDisease=y) Pr(HasDisease=y)}{(Pr(FailsTest=y | HasDisease=y) Pr(HasDisease=y) + Pr(FailsTest=y | HasDisease=n) (1- Pr(HasDisease=y)))}
$$
```python
FailAndHasDisease*HasDisease/(FailAndHasDisease*HasDisease + FailAndNotHasDisease*(1-HasDisease))
```
0.09099181073703368
This matches the result we did by hand in class. Play around with the probabilities and see what you discover.
```python
```
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.finset.lattice
import data.multiset.powerset
/-!
# The powerset of a finset
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
-/
namespace finset
open function multiset
variables {α : Type*} {s t : finset α}
/-! ### powerset -/
section powerset
/-- When `s` is a finset, `s.powerset` is the finset of all subsets of `s` (seen as finsets). -/
def powerset (s : finset α) : finset (finset α) :=
⟨s.1.powerset.pmap finset.mk $ λ t h, nodup_of_le (mem_powerset.1 h) s.nodup,
s.nodup.powerset.pmap $ λ a ha b hb, congr_arg finset.val⟩
@[simp] theorem mem_powerset {s t : finset α} : s ∈ powerset t ↔ s ⊆ t :=
by cases s; simp only [powerset, mem_mk, mem_pmap, mem_powerset, exists_prop, exists_eq_right];
rw ← val_le_iff
@[simp, norm_cast] lemma coe_powerset (s : finset α) :
(s.powerset : set (finset α)) = coe ⁻¹' (s : set α).powerset :=
by { ext, simp }
@[simp] theorem empty_mem_powerset (s : finset α) : ∅ ∈ powerset s :=
mem_powerset.2 (empty_subset _)
@[simp] lemma mem_powerset_self (s : finset α) : s ∈ powerset s := mem_powerset.2 subset.rfl
lemma powerset_nonempty (s : finset α) : s.powerset.nonempty := ⟨∅, empty_mem_powerset _⟩
@[simp] theorem powerset_mono {s t : finset α} : powerset s ⊆ powerset t ↔ s ⊆ t :=
⟨λ h, (mem_powerset.1 $ h $ mem_powerset_self _),
λ st u h, mem_powerset.2 $ subset.trans (mem_powerset.1 h) st⟩
lemma powerset_injective : injective (powerset : finset α → finset (finset α)) :=
injective_of_le_imp_le _ $ λ s t, powerset_mono.1
@[simp] lemma powerset_inj : powerset s = powerset t ↔ s = t := powerset_injective.eq_iff
@[simp] lemma powerset_empty : (∅ : finset α).powerset = {∅} := rfl
@[simp] lemma powerset_eq_singleton_empty : s.powerset = {∅} ↔ s = ∅ :=
by rw [←powerset_empty, powerset_inj]
/-- **Number of Subsets of a Set** -/
@[simp] theorem card_powerset (s : finset α) :
card (powerset s) = 2 ^ card s :=
(card_pmap _ _ _).trans (card_powerset s.1)
lemma not_mem_of_mem_powerset_of_not_mem {s t : finset α} {a : α}
(ht : t ∈ s.powerset) (h : a ∉ s) : a ∉ t :=
by { apply mt _ h, apply mem_powerset.1 ht }
lemma powerset_insert [decidable_eq α] (s : finset α) (a : α) :
powerset (insert a s) = s.powerset ∪ s.powerset.image (insert a) :=
begin
ext t,
simp only [exists_prop, mem_powerset, mem_image, mem_union, subset_insert_iff],
by_cases h : a ∈ t,
{ split,
{ exact λH, or.inr ⟨_, H, insert_erase h⟩ },
{ intros H,
cases H,
{ exact subset.trans (erase_subset a t) H },
{ rcases H with ⟨u, hu⟩,
rw ← hu.2,
exact subset.trans (erase_insert_subset a u) hu.1 } } },
{ have : ¬ ∃ (u : finset α), u ⊆ s ∧ insert a u = t,
by simp [ne.symm (ne_insert_of_not_mem _ _ h)],
simp [finset.erase_eq_of_not_mem h, this] }
end
/-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for any subset. -/
instance decidable_exists_of_decidable_subsets {s : finset α} {p : Π t ⊆ s, Prop}
[Π t (h : t ⊆ s), decidable (p t h)] : decidable (∃ t (h : t ⊆ s), p t h) :=
decidable_of_iff (∃ t (hs : t ∈ s.powerset), p t (mem_powerset.1 hs))
⟨(λ ⟨t, _, hp⟩, ⟨t, _, hp⟩), (λ ⟨t, hs, hp⟩, ⟨t, mem_powerset.2 hs, hp⟩)⟩
/-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for every subset. -/
instance decidable_forall_of_decidable_subsets {s : finset α} {p : Π t ⊆ s, Prop}
[Π t (h : t ⊆ s), decidable (p t h)] : decidable (∀ t (h : t ⊆ s), p t h) :=
decidable_of_iff (∀ t (h : t ∈ s.powerset), p t (mem_powerset.1 h))
⟨(λ h t hs, h t (mem_powerset.2 hs)), (λ h _ _, h _ _)⟩
/-- A version of `finset.decidable_exists_of_decidable_subsets` with a non-dependent `p`.
Typeclass inference cannot find `hu` here, so this is not an instance. -/
def decidable_exists_of_decidable_subsets' {s : finset α} {p : finset α → Prop}
(hu : Π t (h : t ⊆ s), decidable (p t)) : decidable (∃ t (h : t ⊆ s), p t) :=
@finset.decidable_exists_of_decidable_subsets _ _ _ hu
/-- A version of `finset.decidable_forall_of_decidable_subsets` with a non-dependent `p`.
Typeclass inference cannot find `hu` here, so this is not an instance. -/
def decidable_forall_of_decidable_subsets' {s : finset α} {p : finset α → Prop}
(hu : Π t (h : t ⊆ s), decidable (p t)) : decidable (∀ t (h : t ⊆ s), p t) :=
@finset.decidable_forall_of_decidable_subsets _ _ _ hu
end powerset
section ssubsets
variables [decidable_eq α]
/-- For `s` a finset, `s.ssubsets` is the finset comprising strict subsets of `s`. -/
def ssubsets (s : finset α) : finset (finset α) :=
erase (powerset s) s
@[simp] lemma mem_ssubsets {s t : finset α} : t ∈ s.ssubsets ↔ t ⊂ s :=
by rw [ssubsets, mem_erase, mem_powerset, ssubset_iff_subset_ne, and.comm]
lemma empty_mem_ssubsets {s : finset α} (h : s.nonempty) : ∅ ∈ s.ssubsets :=
by { rw [mem_ssubsets, ssubset_iff_subset_ne], exact ⟨empty_subset s, h.ne_empty.symm⟩, }
/-- For predicate `p` decidable on ssubsets, it is decidable whether `p` holds for any ssubset. -/
instance decidable_exists_of_decidable_ssubsets {s : finset α} {p : Π t ⊂ s, Prop}
[Π t (h : t ⊂ s), decidable (p t h)] : decidable (∃ t h, p t h) :=
decidable_of_iff (∃ t (hs : t ∈ s.ssubsets), p t (mem_ssubsets.1 hs))
⟨(λ ⟨t, _, hp⟩, ⟨t, _, hp⟩), (λ ⟨t, hs, hp⟩, ⟨t, mem_ssubsets.2 hs, hp⟩)⟩
/-- For predicate `p` decidable on ssubsets, it is decidable whether `p` holds for every ssubset. -/
instance decidable_forall_of_decidable_ssubsets {s : finset α} {p : Π t ⊂ s, Prop}
[Π t (h : t ⊂ s), decidable (p t h)] : decidable (∀ t h, p t h) :=
decidable_of_iff (∀ t (h : t ∈ s.ssubsets), p t (mem_ssubsets.1 h))
⟨(λ h t hs, h t (mem_ssubsets.2 hs)), (λ h _ _, h _ _)⟩
/-- A version of `finset.decidable_exists_of_decidable_ssubsets` with a non-dependent `p`.
Typeclass inference cannot find `hu` here, so this is not an instance. -/
def decidable_exists_of_decidable_ssubsets' {s : finset α} {p : finset α → Prop}
(hu : Π t (h : t ⊂ s), decidable (p t)) : decidable (∃ t (h : t ⊂ s), p t) :=
@finset.decidable_exists_of_decidable_ssubsets _ _ _ _ hu
/-- A version of `finset.decidable_forall_of_decidable_ssubsets` with a non-dependent `p`.
Typeclass inference cannot find `hu` here, so this is not an instance. -/
def decidable_forall_of_decidable_ssubsets' {s : finset α} {p : finset α → Prop}
(hu : Π t (h : t ⊂ s), decidable (p t)) : decidable (∀ t (h : t ⊂ s), p t) :=
@finset.decidable_forall_of_decidable_ssubsets _ _ _ _ hu
end ssubsets
section powerset_len
/-- Given an integer `n` and a finset `s`, then `powerset_len n s` is the finset of subsets of `s`
of cardinality `n`. -/
def powerset_len (n : ℕ) (s : finset α) : finset (finset α) :=
⟨(s.1.powerset_len n).pmap finset.mk $ λ t h, nodup_of_le (mem_powerset_len.1 h).1 s.2,
s.2.powerset_len.pmap $ λ a ha b hb, congr_arg finset.val⟩
/-- **Formula for the Number of Combinations** -/
theorem mem_powerset_len {n} {s t : finset α} :
s ∈ powerset_len n t ↔ s ⊆ t ∧ card s = n :=
by cases s; simp [powerset_len, val_le_iff.symm]; refl
@[simp] theorem powerset_len_mono {n} {s t : finset α} (h : s ⊆ t) :
powerset_len n s ⊆ powerset_len n t :=
λ u h', mem_powerset_len.2 $
and.imp (λ h₂, subset.trans h₂ h) id (mem_powerset_len.1 h')
/-- **Formula for the Number of Combinations** -/
@[simp] theorem card_powerset_len (n : ℕ) (s : finset α) :
card (powerset_len n s) = nat.choose (card s) n :=
(card_pmap _ _ _).trans (card_powerset_len n s.1)
@[simp] lemma powerset_len_zero (s : finset α) : finset.powerset_len 0 s = {∅} :=
begin
ext, rw [mem_powerset_len, mem_singleton, card_eq_zero],
refine ⟨λ h, h.2, λ h, by { rw h, exact ⟨empty_subset s, rfl⟩ }⟩,
end
@[simp] theorem powerset_len_empty (n : ℕ) {s : finset α} (h : s.card < n) :
powerset_len n s = ∅ :=
finset.card_eq_zero.mp (by rw [card_powerset_len, nat.choose_eq_zero_of_lt h])
theorem powerset_len_eq_filter {n} {s : finset α} :
powerset_len n s = (powerset s).filter (λ x, x.card = n) :=
by { ext, simp [mem_powerset_len] }
lemma powerset_len_succ_insert [decidable_eq α] {x : α} {s : finset α} (h : x ∉ s) (n : ℕ) :
powerset_len n.succ (insert x s) = powerset_len n.succ s ∪ (powerset_len n s).image (insert x) :=
begin
rw [powerset_len_eq_filter, powerset_insert, filter_union, ←powerset_len_eq_filter],
congr,
rw [powerset_len_eq_filter, image_filter],
congr' 1,
ext t,
simp only [mem_powerset, mem_filter, function.comp_app, and.congr_right_iff],
intro ht,
have : x ∉ t := λ H, h (ht H),
simp [card_insert_of_not_mem this, nat.succ_inj']
end
lemma powerset_len_nonempty {n : ℕ} {s : finset α} (h : n ≤ s.card) :
(powerset_len n s).nonempty :=
begin
classical,
induction s using finset.induction_on with x s hx IH generalizing n,
{ rw [card_empty, le_zero_iff] at h,
rw [h, powerset_len_zero],
exact finset.singleton_nonempty _, },
{ cases n,
{ simp },
{ rw [card_insert_of_not_mem hx, nat.succ_le_succ_iff] at h,
rw powerset_len_succ_insert hx,
refine nonempty.mono _ ((IH h).image (insert x)),
convert (subset_union_right _ _) } }
end
@[simp] lemma powerset_len_self (s : finset α) :
powerset_len s.card s = {s} :=
begin
ext,
rw [mem_powerset_len, mem_singleton],
split,
{ exact λ ⟨hs, hc⟩, eq_of_subset_of_card_le hs hc.ge },
{ rintro rfl,
simp }
end
lemma pairwise_disjoint_powerset_len (s : finset α) :
_root_.pairwise (λ i j, disjoint (s.powerset_len i) (s.powerset_len j)) :=
λ i j hij, finset.disjoint_left.mpr $ λ x hi hj, hij $
(mem_powerset_len.mp hi).2.symm.trans (mem_powerset_len.mp hj).2
lemma powerset_card_disj_Union (s : finset α) :
finset.powerset s =
(range (s.card + 1)).disj_Union (λ i, powerset_len i s)
(s.pairwise_disjoint_powerset_len.set_pairwise _) :=
begin
refine ext (λ a, ⟨λ ha, _, λ ha, _ ⟩),
{ rw mem_disj_Union,
exact ⟨a.card, mem_range.mpr (nat.lt_succ_of_le (card_le_of_subset (mem_powerset.mp ha))),
mem_powerset_len.mpr ⟨mem_powerset.mp ha, rfl⟩⟩ },
{ rcases mem_disj_Union.mp ha with ⟨i, hi, ha⟩,
exact mem_powerset.mpr (mem_powerset_len.mp ha).1, }
end
lemma powerset_card_bUnion [decidable_eq (finset α)] (s : finset α) :
finset.powerset s = (range (s.card + 1)).bUnion (λ i, powerset_len i s) :=
by simpa only [disj_Union_eq_bUnion] using powerset_card_disj_Union s
lemma powerset_len_sup [decidable_eq α] (u : finset α) (n : ℕ) (hn : n < u.card) :
(powerset_len n.succ u).sup id = u :=
begin
apply le_antisymm,
{ simp_rw [finset.sup_le_iff, mem_powerset_len],
rintros x ⟨h, -⟩,
exact h },
{ rw [sup_eq_bUnion, le_iff_subset, subset_iff],
cases (nat.succ_le_of_lt hn).eq_or_lt with h' h',
{ simp [h'] },
{ intros x hx,
simp only [mem_bUnion, exists_prop, id.def],
obtain ⟨t, ht⟩ : ∃ t, t ∈ powerset_len n (u.erase x) := powerset_len_nonempty _,
{ refine ⟨insert x t, _, mem_insert_self _ _⟩,
rw [←insert_erase hx, powerset_len_succ_insert (not_mem_erase _ _)],
exact mem_union_right _ (mem_image_of_mem _ ht) },
{ rw [card_erase_of_mem hx],
exact nat.le_pred_of_lt hn, } } }
end
@[simp]
lemma powerset_len_card_add (s : finset α) {i : ℕ} (hi : 0 < i) :
s.powerset_len (s.card + i) = ∅ :=
finset.powerset_len_empty _ (lt_add_of_pos_right (finset.card s) hi)
@[simp] theorem map_val_val_powerset_len (s : finset α) (i : ℕ) :
(s.powerset_len i).val.map finset.val = s.1.powerset_len i :=
by simp [finset.powerset_len, map_pmap, pmap_eq_map, map_id']
theorem powerset_len_map {β : Type*} (f : α ↪ β) (n : ℕ) (s : finset α) :
powerset_len n (s.map f) = (powerset_len n s).map (map_embedding f).to_embedding :=
eq_of_veq $ multiset.map_injective (@eq_of_veq _) $
by simp_rw [map_val_val_powerset_len, map_val, multiset.map_map, function.comp,
rel_embedding.coe_fn_to_embedding, map_embedding_apply, map_val, ←multiset.map_map _ val,
map_val_val_powerset_len, multiset.powerset_len_map]
end powerset_len
end finset
|
56 amazing Lollipop Pictures images in these Lollipop Pictures group starting with L letter.
Giant Chupa Chups Lollipop: 65 times larger than a normal sucker.
Giant Lollipop: Traditional style sucker the size of your face.
What is your Lollipop Moment?
Original Honey Lollipops for every occasion. Gifts. Treats. Tea.
|
module Nnaskell ( NN(..)
, randomNN
, activateNN
, cost
, optimizeCost
, loadNN
, saveNN
) where
import Data.Function
import Data.List
import Control.Monad
import System.Random
import Numeric.LinearAlgebra.Data
import Numeric.LinearAlgebra.HMatrix
data NN = NN { nnWs :: [Matrix R]
, nnBs :: [Vector R]
} deriving (Show, Read)
randomVec :: Int -> IO (Vector R)
randomVec n = vector <$> (replicateM n $ randomRIO (-1.0, 1.0))
randomMatrix :: Int -> Int -> IO (Matrix R)
randomMatrix n m = matrix m <$> (replicateM ((*) n m) $ randomRIO (-1.0, 1.0))
randomLayer :: Int -> Int -> IO (Matrix R, Vector R)
randomLayer n m = liftM2 (\ws bs -> (ws, bs)) (randomMatrix m n) (randomVec m)
randomNN :: [Int] -> IO NN
randomNN ns = do (ws, bs) <- unzip <$> (sequence $ map (uncurry randomLayer) $ pairScan ns)
return $ NN { nnWs = ws
, nnBs = bs
}
sigmoid :: R -> R
sigmoid t = 1 / (1 + exp (-1 * t))
sigmoidVec :: Vector R -> Vector R
sigmoidVec = fromList . map sigmoid . toList
activateLayer :: Vector R -> (Matrix R, Vector R) -> Vector R
activateLayer as (ws, bs) = sigmoidVec (ws #> as + bs)
activateNN :: NN -> Vector R -> Vector R
activateNN nn as = foldl activateLayer as $ zip ws bs
where ws = nnWs nn
bs = nnBs nn
pairScan :: [a] -> [(a, a)]
pairScan (x:y:rest) = (x, y) : pairScan (y:rest)
pairScan _ = []
cost :: [(Vector R, Vector R)] -> NN -> R
cost td nn = (sum $ map inputCost td) / n
where inputCost (input, output) = sumElements $ cmap (** 2) (activateNN nn input - output)
n = fromIntegral $ length td
stepBias :: NN -> Int -> R -> NN
stepBias nn updateIdx s = nn { nnBs = map (\(v, idx) -> if idx <= updateIdx && updateIdx < idx + size v
then accum v (+) [(updateIdx - idx, s)]
else v)
$ zip bs
$ scanl (\idx v -> idx + size v) 0 bs
}
where bs = nnBs nn
stepWeight :: NN -> Int -> R -> NN
stepWeight nn updateIdx s = nn { nnWs = map (\(mx, idx) -> let (n, m) = size mx
effIdx = updateIdx - idx
in if idx <= updateIdx && updateIdx < idx + (n * m)
then accum mx (+) [((effIdx `div` m, effIdx `mod` m), s)]
else mx)
$ zip ws
$ scanl (\idx m -> idx + uncurry (*) (size m)) 0 ws
}
where ws = nnWs nn
class Domain d where
countArgs :: d -> Int
stepArg :: d -> Int -> R -> d
instance Domain NN where
countArgs nn = bsCount + wsCount
where bsCount = sum $ map (length . toList) $ nnBs nn
wsCount = sum $ map length $ concatMap toLists $ nnWs nn
stepArg nn idx s = if idx < bsCount
then stepBias nn idx s
else stepWeight nn (idx - bsCount) s
where bsCount = sum $ map (length . toList) $ nnBs nn
optimizeCost :: Domain d => (d -> R) -> d -> [d]
optimizeCost cost d = scanl optimizeStep d $ cycle [0 .. n - 1]
where n = countArgs d
optimizeStep d idx = minimumBy (compare `on` cost) $ map (stepArg d idx) [-step, 0, step]
step = 0.1
loadNN :: FilePath -> IO NN
loadNN filePath = read <$> readFile filePath
saveNN :: FilePath -> NN -> IO ()
saveNN filePath nn = writeFile filePath $ show nn
|
function h = plus(f, g)
%+ Plus for SEPARABLEAPPROX objects.
%
% F + G adds F and G. F and G can be scalars or SEPARABLEAPPROX objects.
% Copyright 2017 by The University of Oxford and The Chebfun Developers.
% See http://www.chebfun.org/ for Chebfun information.
if ( ~isa(f, 'separableApprox') ) % ??? + SEPARABLEAPPROX
h = plus(g, f);
elseif ( isempty(g) ) % SEPARABLEAPPROX + []
h = f;
elseif ( isempty(f) ) % [] + SEPARABLEAPPROX
h = g;
elseif ( isa( g, 'double' ) ) % SEPARABLEAPPROX + DOUBLE
g = compose( 0*f,@plus, g); % promote double to object class.
h = plus(f, g);
elseif ( ~isa(g, 'separableApprox') ) % SEPARABLEAPPROX + ???
error( 'CHEBFUN:SEPARABLEAPPROX:plus:unknown', ...
['Undefined function ''plus'' for input arguments of type %s ' ...
'and %s.'], class(f), class(g));
else % SEPARABLEAPPROX + SEPARABLEAPPROX
% Domain Check:
if ( ~domainCheck(f, g) )
error('CHEBFUN:SEPARABLEAPPROX:plus:domain', 'Inconsistent domains.');
end
% Type check:
if ( ~strcmp( class(f),class(g) ) )
error( 'CHEBFUN:SEPARABLEAPPROX:plus:unknown', ...
['Undefined function ''plus'' for input arguments of type %s ' ...
'and %s. Try converting to the same type.'], class(f), class(g));
end
% Check for zero SEPARABLEAPPROX objects:
if ( iszero(f) )
h = g;
elseif ( iszero(g) )
h = f;
else
% Add together two nonzero SEPARABLEAPPROX objects:
h = compression_plus(f, g);
end
end
end
function h = compression_plus(f, g)
% Add SEPARABLEAPPROX objects together by a compression algorithm.
% The algorithm is as follows:
% If A = XY^T and B = WZ^T, then A + B = [X W]*[Y Z]^T,
% [Qleft, Rleft] = qr([X W])
% [Qright, Rright] = qr([Y Z])
% A + B = Qleft * (Rleft * Rright') * Qright'
% [U, S, V] = svd( Rleft * Rright' )
% A + B = (Qleft * U) * S * (V' * Qright') -> new low rank representation
% Hack: Ensure g has the smaller pivot values.
if ( norm(f.pivotValues, -inf) < norm(g.pivotValues, -inf) )
% [TODO]: Understand why this works!
h = compression_plus(g, f);
return
end
fScl = diag(1./f.pivotValues);
gScl = diag(1./g.pivotValues);
cols = [f.cols, g.cols];
rows = [f.rows, g.rows];
[Qcols, Rcols] = qr(cols);
[Qrows, Rrows] = qr(rows);
Z = zeros(length(fScl), length(gScl));
D = [ fScl, Z ; Z.', gScl ];
[U, S, V] = svd(Rcols * D * Rrows.');
% Take diagonal from SIGMA:
s = diag(S);
% Compress the format if possible.
% [TODO]: What should EPS be in the tolerance check below?
vf = vscale(f);
vg = vscale(g);
vscl = 2*max(vf, vg);
% Remove singular values that fall below eps*vscale:
idx = find( s > 10*eps * vscl, 1, 'last');
if ( isempty(idx) )
% Return 0 separableApprox
h = 0*f;
else
U = U(:,1:idx);
V = V(:,1:idx);
s = s(1:idx);
h = f;
h.cols = Qcols * U;
h.rows = Qrows * conj(V);
% [TODO]: PivotValues have very little meaning after this compression step.
% For now we assign the singular values as the pivot values.
h.pivotValues = 1./s;
end
end
|
/-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Reid Barton, Bhavik Mehta
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.category_theory.over
import Mathlib.category_theory.limits.shapes.pullbacks
import Mathlib.category_theory.limits.shapes.wide_pullbacks
import Mathlib.category_theory.limits.shapes.finite_products
import Mathlib.PostPort
universes v u
namespace Mathlib
/-!
# Products in the over category
Shows that products in the over category can be derived from wide pullbacks in the base category.
The main result is `over_product_of_wide_pullback`, which says that if `C` has `J`-indexed wide
pullbacks, then `over B` has `J`-indexed products.
-/
namespace category_theory.over
namespace construct_products
/--
(Implementation)
Given a product diagram in `C/B`, construct the corresponding wide pullback diagram
in `C`.
-/
def wide_pullback_diagram_of_diagram_over {C : Type u} [category C] (B : C) {J : Type v} (F : discrete J ⥤ over B) : limits.wide_pullback_shape J ⥤ C :=
limits.wide_pullback_shape.wide_cospan B (fun (j : J) => comma.left (functor.obj F j))
fun (j : J) => comma.hom (functor.obj F j)
/-- (Impl) A preliminary definition to avoid timeouts. -/
def cones_equiv_inverse_obj {C : Type u} [category C] (B : C) {J : Type v} (F : discrete J ⥤ over B) (c : limits.cone F) : limits.cone (wide_pullback_diagram_of_diagram_over B F) :=
limits.cone.mk (comma.left (limits.cone.X c))
(nat_trans.mk
fun (X : limits.wide_pullback_shape J) =>
option.cases_on X (comma.hom (limits.cone.X c))
fun (j : J) => comma_morphism.left (nat_trans.app (limits.cone.π c) j))
/-- (Impl) A preliminary definition to avoid timeouts. -/
def cones_equiv_inverse {C : Type u} [category C] (B : C) {J : Type v} (F : discrete J ⥤ over B) : limits.cone F ⥤ limits.cone (wide_pullback_diagram_of_diagram_over B F) :=
functor.mk (cones_equiv_inverse_obj B F)
fun (c₁ c₂ : limits.cone F) (f : c₁ ⟶ c₂) =>
limits.cone_morphism.mk (comma_morphism.left (limits.cone_morphism.hom f))
/-- (Impl) A preliminary definition to avoid timeouts. -/
@[simp] theorem cones_equiv_functor_map_hom {C : Type u} [category C] (B : C) {J : Type v} (F : discrete J ⥤ over B) (c₁ : limits.cone (wide_pullback_diagram_of_diagram_over B F)) (c₂ : limits.cone (wide_pullback_diagram_of_diagram_over B F)) (f : c₁ ⟶ c₂) : limits.cone_morphism.hom (functor.map (cones_equiv_functor B F) f) = hom_mk (limits.cone_morphism.hom f) :=
Eq.refl (limits.cone_morphism.hom (functor.map (cones_equiv_functor B F) f))
/-- (Impl) A preliminary definition to avoid timeouts. -/
@[simp] def cones_equiv_unit_iso {J : Type v} {C : Type u} [category C] (B : C) (F : discrete J ⥤ over B) : 𝟭 ≅ cones_equiv_functor B F ⋙ cones_equiv_inverse B F :=
nat_iso.of_components
(fun (_x : limits.cone (wide_pullback_diagram_of_diagram_over B F)) => limits.cones.ext (iso.mk 𝟙 𝟙) sorry) sorry
/-- (Impl) A preliminary definition to avoid timeouts. -/
@[simp] def cones_equiv_counit_iso {J : Type v} {C : Type u} [category C] (B : C) (F : discrete J ⥤ over B) : cones_equiv_inverse B F ⋙ cones_equiv_functor B F ≅ 𝟭 :=
nat_iso.of_components (fun (_x : limits.cone F) => limits.cones.ext (iso.mk (hom_mk 𝟙) (hom_mk 𝟙)) sorry) sorry
-- TODO: Can we add `. obviously` to the second arguments of `nat_iso.of_components` and
-- `cones.ext`?
/--
(Impl) Establish an equivalence between the category of cones for `F` and for the "grown" `F`.
-/
@[simp] theorem cones_equiv_unit_iso_2 {J : Type v} {C : Type u} [category C] (B : C) (F : discrete J ⥤ over B) : equivalence.unit_iso (cones_equiv B F) = cones_equiv_unit_iso B F :=
Eq.refl (equivalence.unit_iso (cones_equiv B F))
/-- Use the above equivalence to prove we have a limit. -/
theorem has_over_limit_discrete_of_wide_pullback_limit {J : Type v} {C : Type u} [category C] {B : C} (F : discrete J ⥤ over B) [limits.has_limit (wide_pullback_diagram_of_diagram_over B F)] : limits.has_limit F := sorry
/-- Given a wide pullback in `C`, construct a product in `C/B`. -/
theorem over_product_of_wide_pullback {J : Type v} {C : Type u} [category C] [limits.has_limits_of_shape (limits.wide_pullback_shape J) C] {B : C} : limits.has_limits_of_shape (discrete J) (over B) :=
limits.has_limits_of_shape.mk fun (F : discrete J ⥤ over B) => has_over_limit_discrete_of_wide_pullback_limit F
/-- Given a pullback in `C`, construct a binary product in `C/B`. -/
theorem over_binary_product_of_pullback {C : Type u} [category C] [limits.has_pullbacks C] {B : C} : limits.has_binary_products (over B) :=
over_product_of_wide_pullback
/-- Given all wide pullbacks in `C`, construct products in `C/B`. -/
theorem over_products_of_wide_pullbacks {C : Type u} [category C] [limits.has_wide_pullbacks C] {B : C} : limits.has_products (over B) :=
fun (J : Type v) => over_product_of_wide_pullback
/-- Given all finite wide pullbacks in `C`, construct finite products in `C/B`. -/
theorem over_finite_products_of_finite_wide_pullbacks {C : Type u} [category C] [limits.has_finite_wide_pullbacks C] {B : C} : limits.has_finite_products (over B) :=
fun (J : Type v) (𝒥₁ : DecidableEq J) (𝒥₂ : fintype J) => over_product_of_wide_pullback
end construct_products
/--
Construct terminal object in the over category. This isn't an instance as it's not typically the
way we want to define terminal objects.
(For instance, this gives a terminal object which is different from the generic one given by
`over_product_of_wide_pullback` above.)
-/
theorem over_has_terminal {C : Type u} [category C] (B : C) : limits.has_terminal (over B) := sorry
|
/-
Copyright (c) 2018 Kevin Buzzard and Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Patrick Massot.
This file is to a certain extent based on `quotient_module.lean` by Johannes Hölzl.
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.group_theory.coset
import Mathlib.PostPort
universes u u_1 v
namespace Mathlib
namespace quotient_group
-- Define the `div_inv_monoid` before the `group` structure,
-- to make sure we have `inv` fully defined before we show `mul_left_inv`.
-- TODO: is there a non-invasive way of defining this in one declaration?
protected instance Mathlib.quotient_add_group.div_inv_monoid {G : Type u} [add_group G]
(N : add_subgroup G) [nN : add_subgroup.normal N] :
sub_neg_monoid (quotient_add_group.quotient N) :=
sub_neg_monoid.mk (quotient.map₂' Add.add sorry) sorry ↑0 sorry sorry
(fun (a : quotient_add_group.quotient N) => quotient.lift_on' a (fun (a : G) => ↑(-a)) sorry)
fun (a b : quotient_add_group.quotient N) =>
quotient.map₂' Add.add sorry a (quotient.lift_on' b (fun (a : G) => ↑(-a)) sorry)
protected instance Mathlib.quotient_add_group.add_group {G : Type u} [add_group G]
(N : add_subgroup G) [nN : add_subgroup.normal N] : add_group (quotient_add_group.quotient N) :=
add_group.mk sub_neg_monoid.add sorry sub_neg_monoid.zero sorry sorry sub_neg_monoid.neg
sub_neg_monoid.sub sorry
/-- The group homomorphism from `G` to `G/N`. -/
def mk' {G : Type u} [group G] (N : subgroup G) [nN : subgroup.normal N] : G →* quotient N :=
monoid_hom.mk' mk sorry
@[simp] theorem Mathlib.quotient_add_group.ker_mk {G : Type u} [add_group G] (N : add_subgroup G)
[nN : add_subgroup.normal N] : add_monoid_hom.ker (quotient_add_group.mk' N) = N :=
sorry
-- for commutative groups we don't need normality assumption
protected instance Mathlib.quotient_add_group.add_comm_group {G : Type u_1} [add_comm_group G]
(N : add_subgroup G) : add_comm_group (quotient_add_group.quotient N) :=
add_comm_group.mk add_group.add sorry add_group.zero sorry sorry add_group.neg add_group.sub sorry
sorry
@[simp] theorem Mathlib.quotient_add_group.coe_zero {G : Type u} [add_group G] (N : add_subgroup G)
[nN : add_subgroup.normal N] : ↑0 = 0 :=
rfl
@[simp] theorem coe_mul {G : Type u} [group G] (N : subgroup G) [nN : subgroup.normal N] (a : G)
(b : G) : ↑(a * b) = ↑a * ↑b :=
rfl
@[simp] theorem Mathlib.quotient_add_group.coe_neg {G : Type u} [add_group G] (N : add_subgroup G)
[nN : add_subgroup.normal N] (a : G) : ↑(-a) = -↑a :=
rfl
@[simp] theorem coe_pow {G : Type u} [group G] (N : subgroup G) [nN : subgroup.normal N] (a : G)
(n : ℕ) : ↑(a ^ n) = ↑a ^ n :=
monoid_hom.map_pow (mk' N) a n
@[simp] theorem coe_gpow {G : Type u} [group G] (N : subgroup G) [nN : subgroup.normal N] (a : G)
(n : ℤ) : ↑(a ^ n) = ↑a ^ n :=
monoid_hom.map_gpow (mk' N) a n
/-- A group homomorphism `φ : G →* H` with `N ⊆ ker(φ)` descends (i.e. `lift`s) to a
group homomorphism `G/N →* H`. -/
def lift {G : Type u} [group G] (N : subgroup G) [nN : subgroup.normal N] {H : Type v} [group H]
(φ : G →* H) (HN : ∀ (x : G), x ∈ N → coe_fn φ x = 1) : quotient N →* H :=
monoid_hom.mk' (fun (q : quotient N) => quotient.lift_on' q ⇑φ sorry) sorry
@[simp] theorem Mathlib.quotient_add_group.lift_mk {G : Type u} [add_group G] (N : add_subgroup G)
[nN : add_subgroup.normal N] {H : Type v} [add_group H] {φ : G →+ H}
(HN : ∀ (x : G), x ∈ N → coe_fn φ x = 0) (g : G) :
coe_fn (quotient_add_group.lift N φ HN) ↑g = coe_fn φ g :=
rfl
@[simp] theorem lift_mk' {G : Type u} [group G] (N : subgroup G) [nN : subgroup.normal N]
{H : Type v} [group H] {φ : G →* H} (HN : ∀ (x : G), x ∈ N → coe_fn φ x = 1) (g : G) :
coe_fn (lift N φ HN) (mk g) = coe_fn φ g :=
rfl
@[simp] theorem Mathlib.quotient_add_group.lift_quot_mk {G : Type u} [add_group G]
(N : add_subgroup G) [nN : add_subgroup.normal N] {H : Type v} [add_group H] {φ : G →+ H}
(HN : ∀ (x : G), x ∈ N → coe_fn φ x = 0) (g : G) :
coe_fn (quotient_add_group.lift N φ HN) (Quot.mk setoid.r g) = coe_fn φ g :=
rfl
/-- A group homomorphism `f : G →* H` induces a map `G/N →* H/M` if `N ⊆ f⁻¹(M)`. -/
def Mathlib.quotient_add_group.map {G : Type u} [add_group G] (N : add_subgroup G)
[nN : add_subgroup.normal N] {H : Type v} [add_group H] (M : add_subgroup H)
[add_subgroup.normal M] (f : G →+ H) (h : N ≤ add_subgroup.comap f M) :
quotient_add_group.quotient N →+ quotient_add_group.quotient M :=
quotient_add_group.lift N (add_monoid_hom.comp (quotient_add_group.mk' M) f) sorry
/-- The induced map from the quotient by the kernel to the codomain. -/
def ker_lift {G : Type u} [group G] {H : Type v} [group H] (φ : G →* H) :
quotient (monoid_hom.ker φ) →* H :=
lift (monoid_hom.ker φ) φ sorry
@[simp] theorem ker_lift_mk {G : Type u} [group G] {H : Type v} [group H] (φ : G →* H) (g : G) :
coe_fn (ker_lift φ) ↑g = coe_fn φ g :=
lift_mk (monoid_hom.ker φ) (ker_lift._proof_1 φ) g
@[simp] theorem Mathlib.quotient_add_group.ker_lift_mk' {G : Type u} [add_group G] {H : Type v}
[add_group H] (φ : G →+ H) (g : G) :
coe_fn (quotient_add_group.ker_lift φ) (quotient_add_group.mk g) = coe_fn φ g :=
quotient_add_group.lift_mk' (add_monoid_hom.ker φ) (quotient_add_group.ker_lift._proof_1 φ) g
theorem ker_lift_injective {G : Type u} [group G] {H : Type v} [group H] (φ : G →* H) :
function.injective ⇑(ker_lift φ) :=
sorry
-- Note that ker φ isn't definitionally ker (to_range φ)
-- so there is a bit of annoying code duplication here
/-- The induced map from the quotient by the kernel to the range. -/
def Mathlib.quotient_add_group.range_ker_lift {G : Type u} [add_group G] {H : Type v} [add_group H]
(φ : G →+ H) :
quotient_add_group.quotient (add_monoid_hom.ker φ) →+ ↥(add_monoid_hom.range φ) :=
quotient_add_group.lift (add_monoid_hom.ker φ) (add_monoid_hom.to_range φ) sorry
theorem range_ker_lift_injective {G : Type u} [group G] {H : Type v} [group H] (φ : G →* H) :
function.injective ⇑(range_ker_lift φ) :=
sorry
theorem Mathlib.quotient_add_group.range_ker_lift_surjective {G : Type u} [add_group G] {H : Type v}
[add_group H] (φ : G →+ H) : function.surjective ⇑(quotient_add_group.range_ker_lift φ) :=
sorry
/-- The first isomorphism theorem (a definition): the canonical isomorphism between
`G/(ker φ)` to `range φ`. -/
def Mathlib.quotient_add_group.quotient_ker_equiv_range {G : Type u} [add_group G] {H : Type v}
[add_group H] (φ : G →+ H) :
quotient_add_group.quotient (add_monoid_hom.ker φ) ≃+ ↥(add_monoid_hom.range φ) :=
add_equiv.of_bijective (quotient_add_group.range_ker_lift φ) sorry
/-- The canonical isomorphism `G/(ker φ) ≃* H` induced by a surjection `φ : G →* H`. -/
def Mathlib.quotient_add_group.quotient_ker_equiv_of_surjective {G : Type u} [add_group G]
{H : Type v} [add_group H] (φ : G →+ H) (hφ : function.surjective ⇑φ) :
quotient_add_group.quotient (add_monoid_hom.ker φ) ≃+ H :=
add_equiv.of_bijective (quotient_add_group.ker_lift φ) sorry
end Mathlib
|
# -*- coding: utf-8 -*-
""" Exploring Sphere animation.
Inquisitive sphere.
"""
import numpy as np
import time
from ..engine import Animation
from ..sprites import Sphere
class ExploringSphere(Animation):
ANIMATION = __name__
ARGS = {
}
def post_init(self):
self._max_radius = 6
self._hz = 0.2
self._spheres = [
Sphere(pos=(2, 2, 2), sharpness=0.5),
Sphere(pos=(6, 6, 6), sharpness=0.5),
]
def render(self, frame):
t = time.time()
r = self._max_radius * (1 + np.sin(t * self._hz * 2 * np.pi)) / 2
for s in self._spheres:
s.radius = r
s.render(frame)
|
/*!
\file KernelTimer.cpp
\author Andrew Kerr <[email protected]>
\date June 29, 2012
\brief measures the total kernel runtime of an application
*/
// Ocelot includes
#include <ocelot/trace/interface/KernelTimer.h>
#include <ocelot/executive/interface/Device.h>
#include <ocelot/executive/interface/ExecutableKernel.h>
#include <ocelot/api/interface/OcelotConfiguration.h>
// Boost includes
#include <boost/lexical_cast.hpp>
// C++ includes
#include <fstream>
#include <cstdlib>
////////////////////////////////////////////////////////////////////////////////////////////////////
trace::KernelTimer::KernelTimer(): outputFile("traceKernelTimer.json"), kernel(nullptr), kernelSequenceNumber(0), dynamicInstructions(0) {
outputFile = api::OcelotConfiguration::get().trace.kernelTimer.outputFile;
}
trace::KernelTimer::~KernelTimer() {
}
void trace::KernelTimer::initialize(const executive::ExecutableKernel& kernel) {
this->kernel = &kernel;
dynamicInstructions = 0;
timer.start();
}
void trace::KernelTimer::event(const TraceEvent &) {
++dynamicInstructions;
}
void trace::KernelTimer::finish() {
timer.stop();
double seconds = timer.seconds();
std::ofstream file(outputFile.c_str(), std::ios_base::app);
const char *appname = std::getenv("APPNAME");
if (!appname) { appname = kernel->module->path().c_str(); }
file << "{ \"application\": \"" << appname << "\", ";
const char *trial = std::getenv("TRIALNAME");
if (trial) {
file << " \"trial\": \"" << trial << "\", ";
}
const char *execution = std::getenv("EXECUTION");
if (execution) {
file << " \"execution\": " << boost::lexical_cast<int, const char *>(execution) << ", ";
}
file
<< "\"ISA\": \"" << ir::Instruction::toString(kernel->device->properties().ISA) << "\", "
<< "\"device\": \"" << kernel->device->properties().name << "\", "
<< "\"kernel\": \"" << kernel->name << "\", "
<< "\"sequenceNumberInApplication\": " << kernelSequenceNumber++ << ", "
<< "\"instructions\": " << dynamicInstructions << ", "
<< "\"kernelRuntime\": " << seconds << " }, " << std::endl;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
|
"""
`module Constraints`
TODO: write documentation
"""
module Constraints
import JuLIP: Dofs, AbstractConstraint,
dofs, project!, set_positions!, positions,
mat, vecs, JVecs,
AbstractAtoms
export FixedCell
function zeros_free{T}(n::Integer, x::Vector{T}, free::Vector{Int})
z = zeros(T, n)
z[free] = x
return z
end
function insert_free!{T}(p::Array{T}, x::Vector{T}, free::Vector{Int})
p[free] = x
return p
end
"""
`FixedCell`: no constraints are placed on the motion of atoms, but the
cell shape is fixed
Constructor:
```julia
FixedCell(at::AbstractAtoms; free=..., clamp=..., mask=...)
```
Set at most one of the kwargs:
* no kwarg: all atoms are free
* `free` : list of free atom indices (not dof indices)
* `clamp` : list of clamped atom indices (not dof indices)
* `mask` : TODO
"""
type FixedCell <: AbstractConstraint
ifree::Vector{Int}
end
function FixedCell(at::AbstractAtoms; free=nothing, clamp=nothing, mask=nothing)
if length(find((free != nothing, clamp != nothing, mask != nothing))) > 1
error("FixedCell: only one of `free`, `clamp`, `mask` may be provided")
elseif all( (free == nothing, clamp == nothing, mask == nothing) )
# in this case (default) all atoms are free
return FixedCell(collect(1:3*length(at)))
end
# determine free dof indices
Nat = length(at)
if clamp != nothing
# revert to setting free
free = setdiff(1:Nat, clamp)
end
if free != nothing
# revert to setting mask
mask = Matrix{Bool}(3, Nat)
fill!(mask, false)
mask[:, free] = true
end
return FixedCell(find( mask[:] ))
end
dofs{T}( at::AbstractAtoms, cons::FixedCell, v::JVecs{T}) = mat(v)[cons.ifree]
# !!!!!!!! this may end up being a problem !!!!!!!
# dofs{T}( at::AbstractAtoms, cons::FixedCell, p::JPts{T}) = mat(p)[cons.ifree]
vecs(cons::FixedCell, at::AbstractAtoms, dofs::Dofs) =
zeros_free(length(at), dofs, cons.ifree) |> vecs
positions(cons::FixedCell, at::AbstractAtoms, dofs::Dofs) =
insert_free!(positions(at) |> mat, dofs, cons.ifree) |> vecs
project!(cons::FixedCell, at::AbstractAtoms) = at
# TODO: this is a temporaruy hack, and I think we need to
# figure out how to do this for more general constraints
project!(cons::FixedCell, A::SparseMatrixCSC) = A[cons.ifree, cons.ifree]
end
|
In this tutorial we simulate dynamics of the Heisenberg model
\begin{equation}\label{eq:1}
\hat{H} = J_\text{ex} \sum_{ i,\delta }\hat{S}_i \cdot \hat{S}_{i+\delta},
\end{equation}
defined on a rectangular lattice with $6\times 2$ spins, and where $\delta = [\pm 1,0],\,[0,\pm 1]$. Dynamics is excited via the following perturbation term
\begin{equation}
\hat{H} = \Delta J_\text{ex} f(t) \sum_{ i,\delta }(e_y \cdot \delta)^2\hat{S}_i \cdot \hat{S}_{i+\delta},
\end{equation}
where $e_y$ is a unit vector along the $y$ axis, and $f(t) = e^{(t-1)^2/(2\cdot 0.4^2)}\sin(8t)$. In the following, we set $\Delta J_\text{ex} = 0.02$.
The input data, such as network size, the optimization hyperparameters and model-dependent quantities used in this tutorial are set in the file "Examples/dynamics/main.jl". In this example, it is required to have pre-optimized ground state parameters for a $6x2$ Heisenberg model. Below, we initizilize an RBM with $\alpha=4$ and we time evolve it until time $t=4$ by using a Heun integrator with step size $\delta t =0.002$. We choose 2000 Monte Carlo samples and we parallelize the simulation across 6 workers (plus the master worker).
```julia
include("src/main/main.jl")
```
# Starting dynamics for 12 = 6 x 2 spins and α=4
# Time evolution = [0.,4.0], time-step = 0.002.
# Number of sweeps = 2000
# Number of workers = 7
time 0.0- total energy: -28.05119685773342 +- 8.592333444857377e-7
time 0.002- total energy: -28.051433977345283 +- 8.57561818011876e-7
time 0.004- total energy: -28.051676503760035 +- 8.559942227085967e-7
time 0.006- total energy: -28.051925392626888 +- 8.54560996354272e-7
time 0.008- total energy: -28.052178957655215 +- 8.53209788974029e-7
time 0.01- total energy: -28.052438802259807 +- 8.519878855111645e-7
time 0.012- total energy: -28.05270063896646 +- 8.503274928588696e-7
time 0.014- total energy: -28.05297103060799 +- 8.493230066176439e-7
time 0.016- total energy: -28.05324714022353 +- 8.484373979019145e-7
time 0.018- total energy: -28.053525425020617 +- 8.471204979795577e-7
time 0.02- total energy: -28.05381319227207 +- 8.464832449140801e-7
time 0.022- total energy: -28.054106443001498 +- 8.459648711917276e-7
time 0.024- total energy: -28.05440593949106 +- 8.455702446574453e-7
time 0.026- total energy: -28.054711208854993 +- 8.45295581515675e-7
time 0.028- total energy: -28.055021991118238 +- 8.451439530070677e-7
time 0.03- total energy: -28.05533871252032 +- 8.451158723773264e-7
time 0.032- total energy: -28.055661341785047 +- 8.45211851278415e-7
time 0.034- total energy: -28.055989937410125 +- 8.454315937940393e-7
time 0.036- total energy: -28.056565265477236 +- 8.421006287895409e-7
time 0.038- total energy: -28.056898742050766 +- 8.430717460652957e-7
time 0.04- total energy: -28.057236744587723 +- 8.442188983429875e-7
time 0.042- total energy: -28.057581293865336 +- 8.455061308544576e-7
time 0.044- total energy: -28.057932129872757 +- 8.469408335849679e-7
time 0.046- total energy: -28.058290377261432 +- 8.484812802940422e-7
time 0.048- total energy: -28.058654521468846 +- 8.501839638197278e-7
time 0.05- total energy: -28.059025841769927 +- 8.519930637465432e-7
time 0.052- total energy: -28.05940370556524 +- 8.539346001267091e-7
time 0.054- total energy: -28.059787994064116 +- 8.560199447723086e-7
time 0.056- total energy: -28.059982753587 +- 9.141385378070276e-7
time 0.058- total energy: -28.060379912191316 +- 9.164232731860859e-7
time 0.06- total energy: -28.06078372754369 +- 9.188410950892328e-7
time 0.062- total energy: -28.061195018458744 +- 9.213139504401966e-7
time 0.064- total energy: -28.06176917371936 +- 3.471862305925138e-6
time 0.066- total energy: -28.061172465967974 +- 4.558015117548723e-6
time 0.068- total energy: -28.061604406982894 +- 4.557310967104082e-6
time 0.07- total energy: -28.06204950365263 +- 4.5565376975636125e-6
time 0.072- total energy: -28.06145560125796 +- 3.976584979392504e-6
time 0.074- total energy: -28.061926066984164 +- 3.962113747579224e-6
time 0.076- total energy: -28.06240820164258 +- 3.9477160618927635e-6
time 0.078- total energy: -28.06290210914923 +- 3.933429380785106e-6
time 0.08- total energy: -28.063638008124293 +- 3.9273184354326404e-6
time 0.082- total energy: -28.064817852989044 +- 4.168034592345859e-6
time 0.084- total energy: -28.06542253785088 +- 4.1550480404120635e-6
time 0.086- total energy: -28.066035583470818 +- 4.142108682993372e-6
time 0.088- total energy: -28.06729718130434 +- 2.1654373693598954e-6
time 0.09- total energy: -28.068282204543134 +- 2.2752530116907795e-6
time 0.092- total energy: -28.068828396614343 +- 2.269235647499471e-6
time 0.094- total energy: -28.069380528248445 +- 2.2632916257555953e-6
time 0.096- total energy: -28.069984734961555 +- 1.9539657494435158e-6
time 0.098- total energy: -28.070547254781577 +- 1.951479955564516e-6
time 0.1- total energy: -28.07111563491334 +- 1.949128875242312e-6
time 0.102- total energy: -28.071689517794443 +- 1.9468848824133304e-6
time 0.104- total energy: -28.07410942594757 +- 4.072023445274277e-6
time 0.106- total energy: -28.074638481408062 +- 4.067296899201304e-6
time 0.108- total energy: -28.075172029065712 +- 4.0618116080457e-6
time 0.11- total energy: -28.075709877363174 +- 4.055592588634003e-6
time 0.112- total energy: -28.076251835960253 +- 4.048671191769572e-6
time 0.114- total energy: -28.076797716517138 +- 4.0410843317738495e-6
time 0.116- total energy: -28.07707722559206 +- 4.008270353605012e-6
time 0.118- total energy: -28.07810391747852 +- 4.2749910472751595e-6
time 0.12- total energy: -28.078606292311022 +- 4.258511428329557e-6
time 0.122- total energy: -28.079110120540385 +- 4.241692866595973e-6
time 0.124- total energy: -28.07959209562149 +- 4.225429169079379e-6
time 0.126- total energy: -28.080159118951602 +- 5.113333481605038e-6
time 0.128- total energy: -28.081331757783076 +- 4.7116290363061785e-6
time 0.13- total energy: -28.081885783202665 +- 4.683837191419568e-6
time 0.132- total energy: -28.082467020039946 +- 4.896913895866369e-6
time 0.134- total energy: -28.08293814450202 +- 4.864521818965218e-6
time 0.136- total energy: -28.08341023622182 +- 4.833607608431965e-6
time 0.138- total energy: -28.08360106470819 +- 4.061779304873359e-6
time 0.14- total energy: -28.084060965772018 +- 4.037373802589521e-6
time 0.142- total energy: -28.084524335923476 +- 4.014756038920659e-6
time 0.144- total energy: -28.084407909532842 +- 3.991484383272256e-6
time 0.146- total energy: -28.084605517576424 +- 3.958566685403236e-6
time 0.148- total energy: -28.08575715939622 +- 3.9353246204325215e-6
time 0.15- total energy: -28.084738932294673 +- 5.460930949704481e-6
time 0.152- total energy: -28.08478604738058 +- 4.613631609105139e-6
time 0.154- total energy: -28.085261427957573 +- 4.569413953585368e-6
time 0.156- total energy: -28.0859378013855 +- 4.356272334201251e-6
time 0.158- total energy: -28.086494054672094 +- 4.349353639652909e-6
time 0.16- total energy: -28.087049399398673 +- 4.342400530574152e-6
time 0.162- total energy: -28.08817178963864 +- 3.045417789770622e-6
time 0.164- total energy: -28.088696758766567 +- 3.0462583034849967e-6
time 0.166- total energy: -28.088280632365866 +- 4.18697494785632e-6
time 0.168- total energy: -28.08945459237547 +- 5.887151277837709e-6
time 0.17- total energy: -28.090045391807678 +- 5.878029771003561e-6
time 0.172- total energy: -28.090631273944535 +- 5.863047358787635e-6
time 0.174- total energy: -28.09089972324737 +- 5.732859177107007e-6
time 0.176- total energy: -28.09130208749626 +- 5.724285910463877e-6
time 0.178- total energy: -28.091855345778935 +- 5.719891617139813e-6
time 0.18- total energy: -28.09240680411124 +- 5.7150421531683785e-6
time 0.182- total energy: -28.092967188115683 +- 5.714232473851044e-6
time 0.184- total energy: -28.09351833904136 +- 5.7082700587653185e-6
time 0.186- total energy: -28.094066389297048 +- 5.701814514999744e-6
time 0.188- total energy: -28.094610871347264 +- 5.694828896217077e-6
time 0.19- total energy: -28.09408655775113 +- 6.808060276294929e-6
time 0.192- total energy: -28.094599872652438 +- 6.776985050863965e-6
time 0.194- total energy: -28.095152765409438 +- 6.743924986835198e-6
time 0.196- total energy: -28.095675506450007 +- 6.751274172999059e-6
time 0.198- total energy: -28.096673581171284 +- 6.726502572979178e-6
time 0.2- total energy: -28.097195050257895 +- 6.7340431879873595e-6
time 0.202- total energy: -28.097576733407607 +- 4.262074840995045e-6
time 0.204- total energy: -28.098236104451072 +- 6.778964490002235e-6
time 0.206- total energy: -28.09877574327725 +- 6.7750647494279326e-6
time 0.208- total energy: -28.098215518604672 +- 7.765168739271685e-6
time 0.21- total energy: -28.099286763956414 +- 7.846630222560367e-6
time 0.212- total energy: -28.09952819091225 +- 4.437648616740244e-6
time 0.214- total energy: -28.10022526613904 +- 4.529843179849106e-6
time 0.216- total energy: -28.100611359410696 +- 4.522534104056735e-6
time 0.218- total energy: -28.10159430998804 +- 4.021738417977149e-6
time 0.22- total energy: -28.101025661134912 +- 3.3817514262396893e-6
time 0.222- total energy: -28.101751365752005 +- 3.8308049991730605e-6
time 0.224- total energy: -28.10202115428392 +- 3.822331578533565e-6
time 0.226- total energy: -28.10228097560132 +- 3.814972698891349e-6
time 0.228- total energy: -28.10258207664029 +- 3.804510443983055e-6
time 0.23- total energy: -28.102826973307266 +- 3.799282950212712e-6
time 0.232- total energy: -28.103061278533293 +- 3.795246567010511e-6
time 0.234- total energy: -28.103284420400907 +- 3.7924124244347186e-6
time 0.236- total energy: -28.103527426354308 +- 3.826042336274857e-6
time 0.238- total energy: -28.103729377392117 +- 3.824596730046736e-6
time 0.24- total energy: -28.10362882411383 +- 3.812105346619252e-6
time 0.242- total energy: -28.103776274773264 +- 3.8140259893043957e-6
time 0.244- total energy: -28.103910835050364 +- 3.812802937862997e-6
time 0.246- total energy: -28.10420570254808 +- 3.87732552754016e-6
time 0.248- total energy: -28.104322204023195 +- 3.8740774717379715e-6
time 0.25- total energy: -28.104424438129954 +- 3.8714137691599674e-6
time 0.252- total energy: -28.10451018715658 +- 3.868804956646195e-6
time 0.254- total energy: -28.106813156008588 +- 4.012009792086295e-6
time 0.256- total energy: -28.105815895605815 +- 6.620714177280022e-6
time 0.258- total energy: -28.106005325133438 +- 4.050708389651952e-6
time 0.26- total energy: -28.10600029689773 +- 4.049677539876503e-6
time 0.262- total energy: -28.105692478895666 +- 4.248005647456836e-6
time 0.264- total energy: -28.10566118748747 +- 4.248257310989059e-6
time 0.266- total energy: -28.105609472715905 +- 4.248745807182436e-6
time 0.268- total energy: -28.10553184297706 +- 4.248870801720277e-6
time 0.27- total energy: -28.105436547169955 +- 4.249630090048313e-6
time 0.272- total energy: -28.10674848098779 +- 4.4726086454441045e-6
time 0.274- total energy: -28.10756914664103 +- 4.4683514727126355e-6
time 0.276- total energy: -28.106884720813298 +- 4.386822733493522e-6
time 0.278- total energy: -28.107021007412975 +- 4.54006833612175e-6
time 0.28- total energy: -28.107197238644545 +- 4.767192442214939e-6
time 0.282- total energy: -28.105745354510905 +- 4.636691111592143e-6
time 0.284- total energy: -28.106176084826316 +- 4.505362397073471e-6
time 0.286- total energy: -28.104667681409047 +- 3.915114266584204e-6
time 0.288- total energy: -28.105764063714112 +- 4.488992337023836e-6
time 0.29- total energy: -28.105481069317527 +- 4.530031844246836e-6
time 0.292- total energy: -28.105109568030432 +- 4.538597671132478e-6
time 0.294- total energy: -28.1047828969709 +- 4.5803977335425275e-6
time 0.296- total energy: -28.10297349996052 +- 4.1618242883868625e-6
time 0.298- total energy: -28.104003458213892 +- 4.639558703130365e-6
time 0.3- total energy: -28.102876464105304 +- 4.6113056306986934e-6
time 0.302- total energy: -28.102559508434897 +- 5.051508583815827e-6
time 0.304- total energy: -28.10202261438422 +- 5.059467063562319e-6
time 0.306- total energy: -28.101461077528523 +- 5.067716793749651e-6
time 0.308- total energy: -28.10087426761215 +- 5.079360110350976e-6
time 0.31- total energy: -28.10040092716331 +- 5.11663502822614e-6
time 0.312- total energy: -28.10105721605927 +- 8.13639189632903e-6
time 0.314- total energy: -28.09964032012445 +- 7.89281915242894e-6
time 0.316- total energy: -28.097978919775247 +- 7.735158958948915e-6
time 0.318- total energy: -28.09819109527093 +- 9.827686662506946e-6
time 0.32- total energy: -28.097858025299697 +- 9.792306995388792e-6
time 0.322- total energy: -28.097137326679594 +- 9.793899134395916e-6
time 0.324- total energy: -28.096386408496826 +- 9.795675111907889e-6
time 0.326- total energy: -28.095468741534358 +- 8.486215463802637e-6
time 0.328- total energy: -28.09575609073613 +- 6.742460407309016e-6
time 0.33- total energy: -28.094934351012785 +- 6.744106350458555e-6
time 0.332- total energy: -28.094084374360467 +- 6.745936852278849e-6
time 0.334- total energy: -28.093205742733623 +- 6.747963822381701e-6
time 0.336- total energy: -28.09229809238695 +- 6.7502225103050165e-6
time 0.338- total energy: -28.091362832654458 +- 6.646257481014559e-6
time 0.34- total energy: -28.090461877003488 +- 6.65331487902918e-6
time 0.342- total energy: -28.089219230895083 +- 6.895288044425525e-6
time 0.344- total energy: -28.08823494184697 +- 6.90361009563135e-6
time 0.346- total energy: -28.086814016857986 +- 6.860737704381512e-6
time 0.348- total energy: -28.08573842824139 +- 6.869564995737614e-6
time 0.35- total energy: -28.08462711590765 +- 6.878735974315677e-6
time 0.352- total energy: -28.083479807264137 +- 6.888305757618142e-6
time 0.354- total energy: -28.08229642184162 +- 6.89825285624107e-6
time 0.356- total energy: -28.08107689338357 +- 6.908559009489493e-6
time 0.358- total energy: -28.079821123806056 +- 6.919238306097206e-6
time 0.36- total energy: -28.078530012835188 +- 6.929960638657748e-6
time 0.362- total energy: -28.07720222117717 +- 6.9412459999461055e-6
time 0.364- total energy: -28.07740988510721 +- 6.36535182472962e-6
time 0.366- total energy: -28.076044459224104 +- 6.376171935556491e-6
time 0.368- total energy: -28.07503961520548 +- 6.39927841602529e-6
time 0.37- total energy: -28.071128516855644 +- 7.731416234551943e-6
time 0.372- total energy: -28.069557574053228 +- 6.791980015547641e-6
time 0.374- total energy: -28.067880203588977 +- 5.847518339355483e-6
time 0.376- total energy: -28.066271289286092 +- 5.865761354134833e-6
time 0.378- total energy: -28.06462946880441 +- 5.884910642637221e-6
time 0.38- total energy: -28.062955040985653 +- 5.904966728385805e-6
time 0.382- total energy: -28.06045512884089 +- 6.463199740047118e-6
time 0.384- total energy: -28.058760899031636 +- 6.4812123304807254e-6
time 0.386- total energy: -28.057038142918817 +- 6.5001953601898795e-6
time 0.388- total energy: -28.05525998042755 +- 6.430161876480169e-6
time 0.39- total energy: -28.05368768490972 +- 6.124793149625171e-6
time 0.392- total energy: -28.05189595479828 +- 6.147612512170838e-6
time 0.394- total energy: -28.04929429239626 +- 6.82018504575925e-6
time 0.396- total energy: -28.047532788194495 +- 6.837397469249188e-6
time 0.398- total energy: -28.04574311352751 +- 6.855414245580505e-6
time 0.4- total energy: -28.04392543561646 +- 6.874208026673181e-6
time 0.402- total energy: -28.04102487068054 +- 5.818665646426089e-6
time 0.404- total energy: -28.03913288381969 +- 5.8346635735783246e-6
time 0.406- total energy: -28.03815540129317 +- 5.635210543731999e-6
time 0.408- total energy: -28.0362146554495 +- 5.657504303191888e-6
time 0.41- total energy: -28.03329375038163 +- 5.753775193151803e-6
time 0.412- total energy: -28.031287811259325 +- 5.776504140628689e-6
time 0.414- total energy: -28.030827779268982 +- 5.024401061470155e-6
time 0.416- total energy: -28.0281708782879 +- 5.42380416839872e-6
time 0.418- total energy: -28.025902259488472 +- 6.7467315436633326e-6
time 0.42- total energy: -28.023740896961023 +- 6.788533246327677e-6
time 0.422- total energy: -28.021791128476796 +- 5.908946102764282e-6
time 0.424- total energy: -28.019633894529015 +- 5.9436698654665735e-6
time 0.426- total energy: -28.017458040912217 +- 5.978602641538241e-6
time 0.428- total energy: -28.015264149959847 +- 6.013663914703906e-6
time 0.43- total energy: -28.01305267446895 +- 6.048889482329946e-6
time 0.432- total energy: -28.011277588033533 +- 6.488691158368333e-6
time 0.434- total energy: -28.00909173449202 +- 6.518985116509382e-6
time 0.436- total energy: -28.00568562517818 +- 8.119659407846553e-6
time 0.438- total energy: -28.004281710473606 +- 8.157302260412778e-6
time 0.44- total energy: -28.001414905380425 +- 8.087414901866125e-6
time 0.442- total energy: -27.999508642394673 +- 8.125408145140397e-6
time 0.444- total energy: -27.997163955711425 +- 8.192439791920152e-6
time 0.446- total energy: -27.994811046340605 +- 8.259554954530707e-6
time 0.448- total energy: -27.992450320315672 +- 8.32709801249629e-6
time 0.45- total energy: -27.98887485514682 +- 1.0699544987080338e-5
time 0.452- total energy: -27.986538887078503 +- 1.0750233815714849e-5
time 0.454- total energy: -27.98498678123507 +- 8.264747377696593e-6
time 0.456- total energy: -27.982660990692743 +- 8.329723155824342e-6
time 0.458- total energy: -27.9806481615293 +- 8.394049207629937e-6
time 0.46- total energy: -27.978261043775362 +- 8.46148080485418e-6
time 0.462- total energy: -27.97581015099889 +- 9.036606457476151e-6
time 0.464- total energy: -27.974292819258636 +- 9.057971033255472e-6
time 0.466- total energy: -27.972319102703953 +- 8.9132829970519e-6
time 0.468- total energy: -27.969922223856504 +- 8.989485489801733e-6
time 0.47- total energy: -27.967581184963965 +- 8.969737454734918e-6
time 0.472- total energy: -27.965780640805868 +- 9.107512519753731e-6
time 0.474- total energy: -27.96339807031184 +- 9.182623506526135e-6
time 0.476- total energy: -27.95959924434622 +- 1.0086374249917733e-5
time 0.478- total energy: -27.957477801064304 +- 9.48171581247241e-6
time 0.48- total energy: -27.95654270474809 +- 9.525363501944864e-6
time 0.482- total energy: -27.95416687992779 +- 8.507357301696397e-6
time 0.484- total energy: -27.951428719977613 +- 8.540105987746013e-6
time 0.486- total energy: -27.94897472286486 +- 8.56803754344521e-6
time 0.488- total energy: -27.946516910176122 +- 8.596203367778252e-6
time 0.49- total energy: -27.944056143433674 +- 8.624673713524004e-6
time 0.492- total energy: -27.941592868874114 +- 8.653426042692316e-6
time 0.494- total energy: -27.938314739088177 +- 9.744092860860574e-6
time 0.496- total energy: -27.936635981083317 +- 1.0328899354085992e-5
time 0.498- total energy: -27.93464452149285 +- 7.802918988023779e-6
time 0.5- total energy: -27.93217750505704 +- 8.106753367716853e-6
time 0.502- total energy: -27.92956781502012 +- 8.15137581958376e-6
time 0.504- total energy: -27.926965242693917 +- 8.196140718694449e-6
time 0.506- total energy: -27.924370691968385 +- 8.2415692674763e-6
time 0.508- total energy: -27.92178585278479 +- 8.287501973919478e-6
time 0.51- total energy: -27.918645002469198 +- 8.38604472451457e-6
time 0.512- total energy: -27.91617174139622 +- 8.426498307130992e-6
time 0.514- total energy: -27.91371545445772 +- 8.467401979812794e-6
time 0.516- total energy: -27.911277421302035 +- 8.508661841170751e-6
time 0.518- total energy: -27.908719685698305 +- 8.53459904138182e-6
time 0.52- total energy: -27.906317689030708 +- 8.576454365304508e-6
time 0.522- total energy: -27.903619049388137 +- 8.586426036218933e-6
time 0.524- total energy: -27.901254349537687 +- 8.629073913867602e-6
time 0.526- total energy: -27.898915168284013 +- 8.671785455552592e-6
time 0.528- total energy: -27.895576213668487 +- 1.0466805803391247e-5
time 0.53- total energy: -27.895822681509827 +- 8.920002511238248e-6
time 0.532- total energy: -27.892211875313176 +- 1.1362031751337386e-5
time 0.534- total energy: -27.887295036092002 +- 1.0994486816624142e-5
time 0.536- total energy: -27.88510897535614 +- 1.1027771363097622e-5
time 0.538- total energy: -27.882955940280315 +- 1.1061452452736558e-5
time 0.54- total energy: -27.880830490772862 +- 1.1098854469638635e-5
time 0.542- total energy: -27.87948082559189 +- 1.117029434282025e-5
time 0.544- total energy: -27.877447557351392 +- 1.1199255170496992e-5
time 0.546- total energy: -27.875449414551998 +- 1.122847496624083e-5
time 0.548- total energy: -27.872749524810143 +- 1.2756691808026929e-5
time 0.55- total energy: -27.87072626832271 +- 1.2819912390133553e-5
time 0.552- total energy: -27.86711832265932 +- 1.2986201565632853e-5
time 0.554- total energy: -27.865049782633925 +- 1.5242703799735829e-5
time 0.556- total energy: -27.86208585638804 +- 1.4770706123934897e-5
time 0.558- total energy: -27.86207795570682 +- 1.7187477313951052e-5
time 0.56- total energy: -27.860199568108765 +- 1.718637919204386e-5
time 0.562- total energy: -27.85974076301885 +- 1.5134974656300237e-5
time 0.564- total energy: -27.860505972771215 +- 1.4597704097607837e-5
time 0.566- total energy: -27.8587417184598 +- 1.4562917049864754e-5
time 0.568- total energy: -27.857885758312346 +- 1.4003222665427047e-5
time 0.57- total energy: -27.856108771650245 +- 1.3113672038647482e-5
time 0.572- total energy: -27.854618718804474 +- 1.3399067883676e-5
time 0.574- total energy: -27.853210255791865 +- 1.340556245392983e-5
time 0.576- total energy: -27.851532358747203 +- 1.1711142407222699e-5
time 0.578- total energy: -27.84994632215356 +- 1.2086422227643049e-5
time 0.58- total energy: -27.846620358912133 +- 1.3002690201252476e-5
time 0.582- total energy: -27.84540888596376 +- 1.3032048313817179e-5
time 0.584- total energy: -27.84424469595933 +- 1.306331426084793e-5
time 0.586- total energy: -27.84291842390397 +- 1.4785065678477007e-5
time 0.588- total energy: -27.841620704848967 +- 1.5679059025893877e-5
time 0.59- total energy: -27.84069793128696 +- 1.5719889784927124e-5
time 0.592- total energy: -27.840521876953076 +- 1.5254433728194043e-5
time 0.594- total energy: -27.839713750114154 +- 1.5311812652104795e-5
time 0.596- total energy: -27.839349145821135 +- 1.620337745067262e-5
time 0.598- total energy: -27.8375813114248 +- 1.6789964537611834e-5
time 0.6- total energy: -27.838886204600424 +- 1.6733218946252368e-5
time 0.602- total energy: -27.838322062497383 +- 1.6737473429575927e-5
time 0.604- total energy: -27.83740327855096 +- 1.698378878345606e-5
time 0.606- total energy: -27.83426177102897 +- 1.5059887249130685e-5
time 0.608- total energy: -27.83607082938949 +- 1.4984376417285619e-5
time 0.61- total energy: -27.83688496310893 +- 1.4939652402640258e-5
time 0.612- total energy: -27.836501668693185 +- 1.4929130687952919e-5
time 0.614- total energy: -27.834084808210598 +- 1.5979995622001852e-5
time 0.616- total energy: -27.833900833657204 +- 1.5974394211570793e-5
time 0.618- total energy: -27.83203532166095 +- 1.619516473617167e-5
time 0.62- total energy: -27.83200355359461 +- 1.6200577139918346e-5
time 0.622- total energy: -27.832032714058343 +- 1.6206382033357108e-5
time 0.624- total energy: -27.83135585142639 +- 1.5602391673682342e-5
time 0.626- total energy: -27.83159393823279 +- 1.580085440438671e-5
time 0.628- total energy: -27.833078312534184 +- 1.572837739065598e-5
time 0.63- total energy: -27.835024311257328 +- 1.7726576213200702e-5
time 0.632- total energy: -27.83545876265868 +- 1.7734516079201146e-5
time 0.634- total energy: -27.833730888882137 +- 1.639128797188123e-5
time 0.636- total energy: -27.834129900183804 +- 1.6404293005452838e-5
time 0.638- total energy: -27.83459749918574 +- 1.6413861542297966e-5
time 0.64- total energy: -27.833969346919588 +- 1.691878403036642e-5
time 0.642- total energy: -27.83390281026553 +- 1.5681748231804248e-5
time 0.644- total energy: -27.834484887618526 +- 1.5692249206397734e-5
time 0.646- total energy: -27.834408061248773 +- 1.5643124126578972e-5
time 0.648- total energy: -27.83515135957326 +- 1.5666749673552185e-5
time 0.65- total energy: -27.836945491417925 +- 1.5898559995363888e-5
time 0.652- total energy: -27.83771731993331 +- 1.4699472165903753e-5
time 0.654- total energy: -27.838077318438256 +- 1.3421662993740358e-5
time 0.656- total energy: -27.84095481888613 +- 1.384803006424662e-5
time 0.658- total energy: -27.843305734389276 +- 1.2797138800305823e-5
time 0.66- total energy: -27.844580631762845 +- 1.277114410821636e-5
time 0.662- total energy: -27.845698123445192 +- 1.3370366345717872e-5
time 0.664- total energy: -27.84451809879475 +- 1.4093216598616662e-5
time 0.666- total energy: -27.84591173321631 +- 1.409196417604673e-5
time 0.668- total energy: -27.84817859848016 +- 1.2752853481080656e-5
time 0.67- total energy: -27.84940533879412 +- 1.2316881050270772e-5
time 0.672- total energy: -27.851042162512904 +- 1.2311494115345085e-5
time 0.674- total energy: -27.85274972574279 +- 1.2309379649892023e-5
time 0.676- total energy: -27.854990920992165 +- 1.2816655805235048e-5
time 0.678- total energy: -27.85685080394908 +- 1.2816941984331917e-5
time 0.68- total energy: -27.858781244979923 +- 1.2819006518470385e-5
time 0.682- total energy: -27.860782029817393 +- 1.2822793596094076e-5
time 0.684- total energy: -27.863014143849295 +- 1.2821650618965367e-5
time 0.686- total energy: -27.866438025123408 +- 1.2452799839080349e-5
time 0.688- total energy: -27.86929640224932 +- 1.2073696705256722e-5
time 0.69- total energy: -27.872784136414275 +- 1.2427786927391022e-5
time 0.692- total energy: -27.874005965016877 +- 1.4594262495058346e-5
time 0.694- total energy: -27.87527690609096 +- 1.4506594057540516e-5
time 0.696- total energy: -27.878044482847685 +- 1.2931298814370924e-5
time 0.698- total energy: -27.88067207323807 +- 1.2955191318577673e-5
time 0.7- total energy: -27.88363409363513 +- 1.2816980520795944e-5
time 0.702- total energy: -27.886388476135373 +- 1.2843474915837825e-5
time 0.704- total energy: -27.88686597261773 +- 1.2729919605689003e-5
time 0.706- total energy: -27.887881615002275 +- 1.4847030640942761e-5
time 0.708- total energy: -27.890743196122248 +- 1.4899056908294696e-5
time 0.71- total energy: -27.89522593504993 +- 1.5338563558256418e-5
time 0.712- total energy: -27.899492921641034 +- 1.5587464655976878e-5
time 0.714- total energy: -27.90079958242132 +- 1.5343523124469353e-5
time 0.716- total energy: -27.903352380825364 +- 1.540786467669228e-5
time 0.718- total energy: -27.90723636918779 +- 1.7619303842346498e-5
time 0.72- total energy: -27.911875546798083 +- 1.998618805090209e-5
time 0.722- total energy: -27.91405984686889 +- 1.697406455721032e-5
time 0.724- total energy: -27.91699156740101 +- 1.9609381347899224e-5
time 0.726- total energy: -27.92008894113713 +- 1.9820603842005254e-5
time 0.728- total energy: -27.922657015769357 +- 2.0037018082764982e-5
time 0.73- total energy: -27.92648190765828 +- 2.098945331447362e-5
time 0.732- total energy: -27.93069378681068 +- 1.923111360246812e-5
time 0.734- total energy: -27.93392288271959 +- 1.7205870743049646e-5
time 0.736- total energy: -27.937510382462968 +- 1.7285878553432157e-5
time 0.738- total energy: -27.942280586489545 +- 1.8934642761988076e-5
time 0.74- total energy: -27.949454136816062 +- 2.1370899262970116e-5
time 0.742- total energy: -27.9534518049126 +- 2.1530078379611668e-5
time 0.744- total energy: -27.95749998860283 +- 2.169080728300641e-5
time 0.746- total energy: -27.961510904744294 +- 2.2393071528030705e-5
time 0.748- total energy: -27.968532796467244 +- 2.18033511568263e-5
time 0.75- total energy: -27.972772435350798 +- 2.078544447012418e-5
time 0.752- total energy: -27.975740791920263 +- 2.0882418437285202e-5
time 0.754- total energy: -27.979217742569215 +- 2.1307732850291507e-5
time 0.756- total energy: -27.983506103009063 +- 2.140952461809727e-5
time 0.758- total energy: -27.986784449019783 +- 2.1980608893651377e-5
time 0.76- total energy: -27.991129633824013 +- 2.3331068189339067e-5
time 0.762- total energy: -27.99554344278015 +- 2.346380961224892e-5
time 0.764- total energy: -27.999940739874386 +- 2.4407809601119484e-5
time 0.766- total energy: -28.010264739172857 +- 2.4763073394041055e-5
time 0.768- total energy: -28.01515523450584 +- 2.498117338903697e-5
time 0.77- total energy: -28.01980575441867 +- 2.5101156837925858e-5
time 0.772- total energy: -28.02315197377959 +- 2.67535040441477e-5
time 0.774- total energy: -28.027594552120384 +- 2.710090621057102e-5
time 0.776- total energy: -28.03391045130564 +- 2.4907735205623995e-5
time 0.778- total energy: -28.038548575144983 +- 2.5016414083847512e-5
time 0.78- total energy: -28.043211985564678 +- 2.5130084369512466e-5
time 0.782- total energy: -28.048419572925685 +- 2.7736351370118917e-5
time 0.784- total energy: -28.05132173416402 +- 2.6963671119802336e-5
time 0.786- total energy: -28.059012090340385 +- 2.6267233807372624e-5
time 0.788- total energy: -28.06266453057563 +- 2.78443381090079e-5
time 0.79- total energy: -28.06608328736396 +- 2.8710100419934563e-5
time 0.792- total energy: -28.07343815478576 +- 2.261958399268747e-5
time 0.794- total energy: -28.079054245852404 +- 2.269991137726567e-5
time 0.796- total energy: -28.08288508884733 +- 2.298731104671233e-5
time 0.798- total energy: -28.08103615588736 +- 2.8130712787837194e-5
time 0.8- total energy: -28.08534061270771 +- 2.5785024228286364e-5
time 0.802- total energy: -28.090060468150142 +- 2.5901329475581246e-5
time 0.804- total energy: -28.098374369203796 +- 2.7734220520822274e-5
time 0.806- total energy: -28.100248674998625 +- 2.737495203055675e-5
time 0.808- total energy: -28.106207842731408 +- 2.7894225592346735e-5
time 0.81- total energy: -28.11211082830355 +- 2.8315347480936558e-5
time 0.812- total energy: -28.1162984657045 +- 2.734880209334995e-5
time 0.814- total energy: -28.121800536761317 +- 2.76859657947638e-5
time 0.816- total energy: -28.1270374250762 +- 2.2484662233940418e-5
time 0.818- total energy: -28.1255683877721 +- 2.3227956891775655e-5
time 0.82- total energy: -28.130702819119026 +- 2.3489107629640506e-5
time 0.822- total energy: -28.137124640168548 +- 2.5259554227843005e-5
time 0.824- total energy: -28.14221287186139 +- 2.5512177037384056e-5
time 0.826- total energy: -28.14932737665051 +- 2.6116931083769423e-5
time 0.828- total energy: -28.155326880986866 +- 2.6706690382727682e-5
time 0.83- total energy: -28.160320600039096 +- 2.6882361249387745e-5
time 0.832- total energy: -28.165340256907353 +- 2.705800713701297e-5
time 0.834- total energy: -28.170303383786006 +- 2.7237846116980493e-5
time 0.836- total energy: -28.170171840293044 +- 2.549017150800262e-5
time 0.838- total energy: -28.174665955717252 +- 2.6622825686146656e-5
time 0.84- total energy: -28.179499101228945 +- 2.6793026363669978e-5
time 0.842- total energy: -28.18501922904108 +- 2.6867707807519202e-5
time 0.844- total energy: -28.189864399754935 +- 2.7049298064799982e-5
time 0.846- total energy: -28.195820616459233 +- 2.9495337325201407e-5
time 0.848- total energy: -28.195086799112474 +- 2.7387899256199687e-5
time 0.85- total energy: -28.19890068298653 +- 2.5047966180834092e-5
time 0.852- total energy: -28.20360771222843 +- 2.5214205952104217e-5
time 0.854- total energy: -28.20819473994522 +- 2.5521915105224787e-5
time 0.856- total energy: -28.213571142467494 +- 2.834311816147247e-5
time 0.858- total energy: -28.21964889235525 +- 2.7464113183039672e-5
time 0.86- total energy: -28.22386484092784 +- 2.584383609376319e-5
time 0.862- total energy: -28.230832423079633 +- 2.671505787639029e-5
time 0.864- total energy: -28.235532834419804 +- 2.6933807196003175e-5
time 0.866- total energy: -28.24019332720621 +- 2.7153716823483237e-5
time 0.868- total energy: -28.24254281550143 +- 2.678687071204532e-5
time 0.87- total energy: -28.244527799843404 +- 2.5946254912450345e-5
time 0.872- total energy: -28.253112541920604 +- 2.9590822032543594e-5
time 0.874- total energy: -28.26557682420953 +- 3.0697205647796475e-5
time 0.876- total energy: -28.26945815032112 +- 3.080923479912608e-5
time 0.878- total energy: -28.272952104380728 +- 3.205731193096308e-5
time 0.88- total energy: -28.274874197562585 +- 3.4748829070681086e-5
time 0.882- total energy: -28.28603415677881 +- 3.7736813404674934e-5
time 0.884- total energy: -28.291389075743307 +- 3.705012546818148e-5
time 0.886- total energy: -28.295744814832826 +- 3.628932585388413e-5
time 0.888- total energy: -28.29966390944634 +- 3.554901357941017e-5
time 0.89- total energy: -28.2993124827368 +- 3.5576354926979205e-5
time 0.892- total energy: -28.30312671173359 +- 3.570501654112895e-5
time 0.894- total energy: -28.306883044743564 +- 3.582836870254559e-5
time 0.896- total energy: -28.308045200282155 +- 3.744863655504284e-5
time 0.898- total energy: -28.31328356709289 +- 3.729805176745895e-5
time 0.9- total energy: -28.319434214479138 +- 3.8819718435117016e-5
time 0.902- total energy: -28.322950972671535 +- 3.8988514801820456e-5
time 0.904- total energy: -28.32597198863158 +- 3.8339911040445503e-5
time 0.906- total energy: -28.329329819619208 +- 3.848167166380602e-5
time 0.908- total energy: -28.333122333126003 +- 3.978965923718907e-5
time 0.91- total energy: -28.334482564666853 +- 3.758320526515927e-5
time 0.912- total energy: -28.335407493760695 +- 3.7706565941259454e-5
time 0.914- total energy: -28.34083170930714 +- 3.7756316311723514e-5
time 0.916- total energy: -28.34289960719446 +- 3.8686485982003225e-5
time 0.918- total energy: -28.35634504885192 +- 4.2660650892099145e-5
time 0.92- total energy: -28.36216797405991 +- 4.193844146006942e-5
time 0.922- total energy: -28.364901253192027 +- 4.179172682375835e-5
time 0.924- total energy: -28.366813369639317 +- 4.2370528157473786e-5
time 0.926- total energy: -28.36714986661168 +- 3.980792005246672e-5
time 0.928- total energy: -28.37101407366226 +- 4.214736074166316e-5
time 0.93- total energy: -28.375665908555334 +- 4.3539104217585975e-5
time 0.932- total energy: -28.375893601126393 +- 4.305513647304569e-5
time 0.934- total energy: -28.37368763285708 +- 3.8689591861675896e-5
time 0.936- total energy: -28.37777701616954 +- 3.613594968125151e-5
time 0.938- total energy: -28.381361230423487 +- 3.680887665993233e-5
time 0.94- total energy: -28.38313936566597 +- 3.694285009091726e-5
time 0.942- total energy: -28.384825252886742 +- 3.877467877762779e-5
time 0.944- total energy: -28.383399637407052 +- 4.016357001550146e-5
time 0.946- total energy: -28.386326637470077 +- 4.3135166905089724e-5
time 0.948- total energy: -28.38658487179065 +- 4.1389139250840615e-5
time 0.95- total energy: -28.381253200359666 +- 4.213116749990444e-5
time 0.952- total energy: -28.383823771807116 +- 4.57858643920596e-5
time 0.954- total energy: -28.385289082644345 +- 4.572500350403954e-5
time 0.956- total energy: -28.38684215664194 +- 4.600940797559473e-5
time 0.958- total energy: -28.388145487920706 +- 4.3952726665366384e-5
time 0.96- total energy: -28.389266829097355 +- 4.3909420736741415e-5
time 0.962- total energy: -28.39114060760074 +- 4.2468185182450646e-5
time 0.964- total energy: -28.39446167771455 +- 4.446094862886735e-5
time 0.966- total energy: -28.395172027161557 +- 4.4475694726788796e-5
time 0.968- total energy: -28.39483555828841 +- 4.264801539291122e-5
time 0.97- total energy: -28.39300497719884 +- 4.129927978710075e-5
time 0.972- total energy: -28.395512527309545 +- 4.099082708120129e-5
time 0.974- total energy: -28.400109418286508 +- 3.9177164001915565e-5
time 0.976- total energy: -28.40427986839914 +- 4.179829281946604e-5
time 0.978- total energy: -28.40354654676351 +- 4.1738261563812844e-5
time 0.98- total energy: -28.404103891792897 +- 4.237911859467957e-5
time 0.982- total energy: -28.403592993000387 +- 4.1240207624970505e-5
time 0.984- total energy: -28.4011238882832 +- 5.284762036913411e-5
time 0.986- total energy: -28.40053830530253 +- 5.256459345451542e-5
time 0.988- total energy: -28.404663119246752 +- 5.647149831086998e-5
time 0.99- total energy: -28.401207109179225 +- 5.4524706022045706e-5
time 0.992- total energy: -28.394578652855035 +- 5.309183640262582e-5
time 0.994- total energy: -28.39417179216368 +- 5.2333741212743406e-5
time 0.996- total energy: -28.392822396990045 +- 5.2361282143701796e-5
time 0.998- total energy: -28.397202976884735 +- 4.7393667194716e-5
time 1.0- total energy: -28.39568883090904 +- 4.2458260380578304e-5
time 1.002- total energy: -28.39282341531159 +- 4.470235371280534e-5
time 1.004- total energy: -28.391814371953622 +- 4.4997256724892975e-5
time 1.006- total energy: -28.39176240144323 +- 5.028358111232545e-5
time 1.008- total energy: -28.3905068438167 +- 5.014147200450915e-5
time 1.01- total energy: -28.388227403065034 +- 5.696008091443774e-5
time 1.012- total energy: -28.38721655915544 +- 5.5671012594364295e-5
time 1.014- total energy: -28.38597490576902 +- 5.6604615845935854e-5
time 1.016- total energy: -28.388882837262162 +- 4.634240167963981e-5
time 1.018- total energy: -28.384742754518346 +- 5.5918713094051346e-5
time 1.02- total energy: -28.38527036701319 +- 6.120344791921985e-5
time 1.022- total energy: -28.386136246932534 +- 5.8689942926345504e-5
time 1.024- total energy: -28.381530597559795 +- 5.795650761474579e-5
time 1.026- total energy: -28.38118664397399 +- 5.820904158779755e-5
time 1.028- total energy: -28.37923477166934 +- 5.82779645060008e-5
time 1.03- total energy: -28.37265857912382 +- 5.024958069068132e-5
time 1.032- total energy: -28.37173064663906 +- 5.3955508750082536e-5
time 1.034- total energy: -28.3617227051363 +- 5.466223707631868e-5
time 1.036- total energy: -28.365415235493074 +- 5.733518584626258e-5
time 1.038- total energy: -28.36293806459808 +- 4.968641364024795e-5
time 1.04- total energy: -28.359201426198442 +- 5.167398516825145e-5
time 1.042- total energy: -28.3560166738246 +- 5.2208798575358875e-5
time 1.044- total energy: -28.351425779727528 +- 4.7601966283756535e-5
time 1.046- total energy: -28.346608219582365 +- 4.792750470226269e-5
time 1.048- total energy: -28.3435817311187 +- 4.349679966018403e-5
time 1.05- total energy: -28.33932713622847 +- 4.3223965912137996e-5
time 1.052- total energy: -28.336684583054517 +- 4.655851846751369e-5
time 1.054- total energy: -28.333321054294668 +- 4.660839838284581e-5
time 1.056- total energy: -28.328289318977568 +- 4.728378390005659e-5
time 1.058- total energy: -28.325226007281348 +- 4.844535985921069e-5
time 1.06- total energy: -28.323341698632017 +- 4.7548373417944386e-5
time 1.062- total energy: -28.331669252780255 +- 4.632359956813298e-5
time 1.064- total energy: -28.327173687335833 +- 4.561033873212981e-5
time 1.066- total energy: -28.31852238093578 +- 4.988173136666655e-5
time 1.068- total energy: -28.31751167627435 +- 5.019127929838392e-5
time 1.07- total energy: -28.316756194099106 +- 5.559656955394874e-5
time 1.072- total energy: -28.31514986803525 +- 5.547584648076168e-5
time 1.074- total energy: -28.30909971536517 +- 5.117255861042507e-5
time 1.076- total energy: -28.302325621658742 +- 4.593222828152734e-5
time 1.078- total energy: -28.29757420994904 +- 4.507454837209417e-5
time 1.08- total energy: -28.29525063806156 +- 4.5359900767657455e-5
time 1.082- total energy: -28.29320802734192 +- 4.4059011786506287e-5
time 1.084- total energy: -28.288743154154112 +- 4.295061793889404e-5
time 1.086- total energy: -28.282490463510108 +- 4.787728176727754e-5
time 1.088- total energy: -28.276455629161955 +- 5.006508712784898e-5
time 1.09- total energy: -28.273624606854604 +- 4.976936902016088e-5
time 1.092- total energy: -28.266993049746883 +- 4.960777139408744e-5
time 1.094- total energy: -28.26274570520434 +- 5.04615441420598e-5
time 1.096- total energy: -28.258475932170786 +- 5.05652389630508e-5
time 1.098- total energy: -28.24716720329791 +- 4.868219602539942e-5
time 1.1- total energy: -28.242762495052347 +- 4.737246989733793e-5
time 1.102- total energy: -28.24162445098327 +- 4.703712178843484e-5
time 1.104- total energy: -28.238305643829005 +- 4.788605568680736e-5
time 1.106- total energy: -28.235164555585712 +- 4.822490278497482e-5
time 1.108- total energy: -28.22680075420626 +- 4.8060033314307067e-5
time 1.11- total energy: -28.221713018096587 +- 4.824647037952131e-5
time 1.112- total energy: -28.209414117987144 +- 5.454762371758502e-5
time 1.114- total energy: -28.204325438801522 +- 5.166822407207735e-5
time 1.116- total energy: -28.196281972922396 +- 5.240236794791864e-5
time 1.118- total energy: -28.191195535734003 +- 5.252359161161576e-5
time 1.12- total energy: -28.189167755705054 +- 4.8668751167449086e-5
time 1.122- total energy: -28.18390021442702 +- 5.048140005516382e-5
time 1.124- total energy: -28.17477385870152 +- 5.057719512695203e-5
time 1.126- total energy: -28.16697602038685 +- 4.891779698889043e-5
time 1.128- total energy: -28.162282691703762 +- 5.593022780237023e-5
time 1.13- total energy: -28.16232561378818 +- 5.5169724996304974e-5
time 1.132- total energy: -28.158074387468577 +- 5.938957560368322e-5
time 1.134- total energy: -28.160966475965296 +- 5.809767718676732e-5
time 1.136- total energy: -28.156434506793452 +- 5.66335064012985e-5
time 1.138- total energy: -28.15677139766733 +- 5.957827916075721e-5
time 1.14- total energy: -28.154485487475448 +- 5.8300427001628474e-5
time 1.142- total energy: -28.137258488596633 +- 5.5773569988014764e-5
time 1.144- total energy: -28.12868122800595 +- 5.8221368068123753e-5
time 1.146- total energy: -28.124226453363644 +- 5.797650542913236e-5
time 1.148- total energy: -28.12087333928547 +- 5.8692634631648665e-5
time 1.15- total energy: -28.116650442386916 +- 5.8800770874729006e-5
time 1.152- total energy: -28.112234243010874 +- 6.0440275218347445e-5
time 1.154- total energy: -28.107081856050502 +- 6.070545756653997e-5
time 1.156- total energy: -28.101916941002756 +- 5.9360193423002706e-5
time 1.158- total energy: -28.08855802030304 +- 6.08366166440559e-5
time 1.16- total energy: -28.09763331661347 +- 6.265420959722048e-5
time 1.162- total energy: -28.087686873673373 +- 5.912290277558081e-5
time 1.164- total energy: -28.078391977077843 +- 5.8633753873610286e-5
time 1.166- total energy: -28.06815907825567 +- 6.106150542353975e-5
time 1.168- total energy: -28.062800198813434 +- 6.123611925231196e-5
time 1.17- total energy: -28.05927754561676 +- 7.132056382598615e-5
time 1.172- total energy: -28.05519215246454 +- 7.085128566538023e-5
time 1.174- total energy: -28.05243808699326 +- 7.020485383798802e-5
time 1.176- total energy: -28.047605375003876 +- 6.907276242400992e-5
time 1.178- total energy: -28.044915405564574 +- 7.011779440192069e-5
time 1.18- total energy: -28.044826765674934 +- 6.471269409278847e-5
time 1.182- total energy: -28.049614560037536 +- 6.973810468538042e-5
time 1.184- total energy: -28.03925497394027 +- 6.989165726241658e-5
time 1.186- total energy: -28.031125237093466 +- 7.000264996285082e-5
time 1.188- total energy: -28.028988880075552 +- 7.431920819833145e-5
time 1.19- total energy: -28.02392558869645 +- 7.474604879386366e-5
time 1.192- total energy: -28.0066754988153 +- 7.507880178729146e-5
time 1.194- total energy: -28.001879692514535 +- 7.526228865188569e-5
time 1.196- total energy: -27.994302420653675 +- 7.690374754379654e-5
time 1.198- total energy: -27.991188314199217 +- 7.973534062776675e-5
time 1.2- total energy: -27.985472080982227 +- 8.787960380039596e-5
time 1.202- total energy: -27.980525271245188 +- 8.925112270305954e-5
time 1.204- total energy: -27.97963803502379 +- 8.869609144035211e-5
time 1.206- total energy: -27.9752596882306 +- 8.669308127218784e-5
time 1.208- total energy: -27.973152579389883 +- 8.740377282119872e-5
time 1.21- total energy: -27.9708109247408 +- 8.46483897235796e-5
time 1.212- total energy: -27.964164209942417 +- 8.460450028967265e-5
time 1.214- total energy: -27.9618153309689 +- 9.14430934454831e-5
time 1.216- total energy: -27.957602510958488 +- 9.155262509242935e-5
time 1.218- total energy: -27.95345825983769 +- 9.16741467037228e-5
time 1.22- total energy: -27.95178190230638 +- 9.315963841586551e-5
time 1.222- total energy: -27.927760709376713 +- 8.603723577095586e-5
time 1.224- total energy: -27.923612595777897 +- 8.618670592290015e-5
time 1.226- total energy: -27.91505381283136 +- 7.78002395844642e-5
time 1.228- total energy: -27.922844234491542 +- 7.808307269347925e-5
time 1.23- total energy: -27.927271418244484 +- 7.681458557318463e-5
time 1.232- total energy: -27.922175855851886 +- 7.554431931772811e-5
time 1.234- total energy: -27.918354493025607 +- 7.828892602762148e-5
time 1.236- total energy: -27.914263068014066 +- 7.84572891234418e-5
time 1.238- total energy: -27.910221040818413 +- 7.862519906264847e-5
time 1.24- total energy: -27.899069870144622 +- 7.481079428240924e-5
time 1.242- total energy: -27.895224287161206 +- 7.500710367882176e-5
time 1.244- total energy: -27.900631849981867 +- 7.391786436546721e-5
time 1.246- total energy: -27.88489605298859 +- 7.84271416236193e-5
time 1.248- total energy: -27.88111505252541 +- 7.85125333713314e-5
time 1.25- total energy: -27.875535064326368 +- 7.998635499432813e-5
time 1.252- total energy: -27.86714575674651 +- 7.932523368402342e-5
time 1.254- total energy: -27.863726171435594 +- 7.705619910505693e-5
time 1.256- total energy: -27.86216239559392 +- 7.947493742566431e-5
time 1.258- total energy: -27.873597711423105 +- 8.26325026489632e-5
time 1.26- total energy: -27.870178249264434 +- 8.362278855809937e-5
time 1.262- total energy: -27.869315734537214 +- 8.545821719268333e-5
time 1.264- total energy: -27.862279719025008 +- 7.708809309390336e-5
time 1.266- total energy: -27.857344639473055 +- 7.623255674566082e-5
time 1.268- total energy: -27.846728779728434 +- 7.622050440029205e-5
time 1.27- total energy: -27.851931016461503 +- 7.677323098797176e-5
time 1.272- total energy: -27.84569883112081 +- 7.832322043271618e-5
time 1.274- total energy: -27.844795547067033 +- 7.850318750460345e-5
time 1.276- total energy: -27.84674971455107 +- 8.217011229490105e-5
time 1.278- total energy: -27.846655400566988 +- 8.228523428017942e-5
time 1.28- total energy: -27.84081088688103 +- 7.932715765977476e-5
time 1.282- total energy: -27.84002670931854 +- 8.174669539551729e-5
time 1.284- total energy: -27.841633440239068 +- 8.599015897580813e-5
time 1.286- total energy: -27.838793137099973 +- 8.001356527539642e-5
time 1.288- total energy: -27.827410248414402 +- 8.369238576197461e-5
time 1.29- total energy: -27.826777499397217 +- 8.339647096356257e-5
time 1.292- total energy: -27.826810877883613 +- 7.686471775233794e-5
time 1.294- total energy: -27.823789504438444 +- 7.715673022447535e-5
time 1.296- total energy: -27.819452350213005 +- 7.46317097937747e-5
time 1.298- total energy: -27.813106396475867 +- 7.216657981909733e-5
time 1.3- total energy: -27.81646187358982 +- 7.188444262993237e-5
time 1.302- total energy: -27.814565517525125 +- 6.803391165812519e-5
time 1.304- total energy: -27.81112779440136 +- 6.792783261212261e-5
time 1.306- total energy: -27.811376825802697 +- 7.343974697852806e-5
time 1.308- total energy: -27.80987271466639 +- 7.325639588033287e-5
time 1.31- total energy: -27.808580469189096 +- 7.336557412112461e-5
time 1.312- total energy: -27.811884172148677 +- 8.315917848725213e-5
time 1.314- total energy: -27.81419025233243 +- 7.876856846895376e-5
time 1.316- total energy: -27.81313059339435 +- 8.11890579739619e-5
time 1.318- total energy: -27.81190975834619 +- 8.13416807822841e-5
time 1.32- total energy: -27.809720294014387 +- 8.440860481638356e-5
time 1.322- total energy: -27.811134974592967 +- 8.215884407383499e-5
time 1.324- total energy: -27.80897813596403 +- 8.537599842411601e-5
time 1.326- total energy: -27.806561766784007 +- 8.399099845268209e-5
time 1.328- total energy: -27.808030334605917 +- 8.233032518148991e-5
time 1.33- total energy: -27.80576989707278 +- 8.179133685150409e-5
time 1.332- total energy: -27.805539539229844 +- 8.232963805774861e-5
time 1.334- total energy: -27.80700676202166 +- 8.187149665800119e-5
time 1.336- total energy: -27.809890469966724 +- 7.756760124128466e-5
time 1.338- total energy: -27.809674705100818 +- 7.991176715271554e-5
time 1.34- total energy: -27.806652669555827 +- 8.318470295209342e-5
time 1.342- total energy: -27.80383336617173 +- 7.654509016350822e-5
time 1.344- total energy: -27.79917548590909 +- 8.22083326608534e-5
time 1.346- total energy: -27.797062826776877 +- 7.880362969071974e-5
time 1.348- total energy: -27.799830732032554 +- 8.145046767223574e-5
time 1.35- total energy: -27.802294243739592 +- 8.187452525895518e-5
time 1.352- total energy: -27.80325120685125 +- 8.23542730451625e-5
time 1.354- total energy: -27.80208748832571 +- 7.589809446896997e-5
time 1.356- total energy: -27.799710941720924 +- 7.690119350307085e-5
time 1.358- total energy: -27.80123078857937 +- 7.31199071494618e-5
time 1.36- total energy: -27.804810306521492 +- 7.391873114926832e-5
time 1.362- total energy: -27.804725311601775 +- 6.844471830940256e-5
time 1.364- total energy: -27.804680959167445 +- 6.878065511155633e-5
time 1.366- total energy: -27.804380071192362 +- 6.816946436961401e-5
time 1.368- total energy: -27.80564299654999 +- 7.640162863862252e-5
time 1.37- total energy: -27.804720100242587 +- 7.228685120441889e-5
time 1.372- total energy: -27.803558080017545 +- 7.401391856645059e-5
time 1.374- total energy: -27.805973092408056 +- 7.449017168069761e-5
time 1.376- total energy: -27.80679452279928 +- 7.43845633357298e-5
time 1.378- total energy: -27.80569159801076 +- 7.507794220358453e-5
time 1.38- total energy: -27.810056275147453 +- 8.211802621001081e-5
time 1.382- total energy: -27.813372477759287 +- 8.16210722327426e-5
time 1.384- total energy: -27.822603648266277 +- 7.6144103990053e-5
time 1.386- total energy: -27.82392968132708 +- 7.46329573255709e-5
time 1.388- total energy: -27.823303928581506 +- 7.167029395292329e-5
time 1.39- total energy: -27.823502101013613 +- 6.928218876315981e-5
time 1.392- total energy: -27.816832496754206 +- 7.107533273982259e-5
time 1.394- total energy: -27.82226333972078 +- 7.237210623785498e-5
time 1.396- total energy: -27.82495317826152 +- 7.057033049375316e-5
time 1.398- total energy: -27.82662462091307 +- 6.942018775190668e-5
time 1.4- total energy: -27.82747881957767 +- 7.233157250322764e-5
time 1.402- total energy: -27.83162599306808 +- 7.066452994828792e-5
time 1.404- total energy: -27.833315016891447 +- 7.078074426988083e-5
time 1.406- total energy: -27.834430178679494 +- 7.112615458198845e-5
time 1.408- total energy: -27.833105979388648 +- 7.051066831320317e-5
time 1.41- total energy: -27.839192828755 +- 7.106492280232918e-5
time 1.412- total energy: -27.845274451610408 +- 7.003043797702636e-5
time 1.414- total energy: -27.84613969163674 +- 7.074851574884936e-5
time 1.416- total energy: -27.849012960691983 +- 7.226784380662133e-5
time 1.418- total energy: -27.85020235060827 +- 7.84782587528081e-5
time 1.42- total energy: -27.8506961732405 +- 7.145239783228932e-5
time 1.422- total energy: -27.853792843702692 +- 6.896955645249743e-5
time 1.424- total energy: -27.855563419961413 +- 7.360129616249876e-5
time 1.426- total energy: -27.85325242020229 +- 7.88236843082917e-5
time 1.428- total energy: -27.856187659033292 +- 7.045432431890353e-5
time 1.43- total energy: -27.859355705422416 +- 7.671359140515931e-5
time 1.432- total energy: -27.863293677455957 +- 8.2861982078659e-5
time 1.434- total energy: -27.8718965882285 +- 7.646232793574132e-5
time 1.436- total energy: -27.868535921367275 +- 8.169590669693366e-5
time 1.438- total energy: -27.872187134969383 +- 8.499158176238524e-5
time 1.44- total energy: -27.874185431025367 +- 8.250884131534845e-5
time 1.442- total energy: -27.87089305288405 +- 8.633196329757472e-5
time 1.444- total energy: -27.874207688339837 +- 8.771676689262683e-5
time 1.446- total energy: -27.87745862291449 +- 8.693119612529272e-5
time 1.448- total energy: -27.87824381775786 +- 8.52312707664745e-5
time 1.45- total energy: -27.87889965661932 +- 8.220095828172446e-5
time 1.452- total energy: -27.881083874374564 +- 8.330007829582914e-5
time 1.454- total energy: -27.879222948424133 +- 8.298088574196115e-5
time 1.456- total energy: -27.879911707728294 +- 7.969664167341987e-5
time 1.458- total energy: -27.8803342430429 +- 7.95558446859434e-5
time 1.46- total energy: -27.896954163998714 +- 9.529145608047813e-5
time 1.462- total energy: -27.898878127110944 +- 8.96294444996532e-5
time 1.464- total energy: -27.904540461229892 +- 8.698009483202006e-5
time 1.466- total energy: -27.90615922583252 +- 8.749597733127399e-5
time 1.468- total energy: -27.908050224198085 +- 8.757462665618548e-5
time 1.47- total energy: -27.910631383546015 +- 8.77536485442249e-5
time 1.472- total energy: -27.91310479345082 +- 8.601962422044185e-5
time 1.474- total energy: -27.914388066816024 +- 7.623082299694835e-5
time 1.476- total energy: -27.917211698316468 +- 7.651849941857992e-5
time 1.478- total energy: -27.92127992354427 +- 7.04339380074785e-5
time 1.48- total energy: -27.92304745287586 +- 7.131225556396963e-5
time 1.482- total energy: -27.920760723109154 +- 7.025358507284576e-5
time 1.484- total energy: -27.922496420269667 +- 6.696797470074863e-5
time 1.486- total energy: -27.924957648611844 +- 6.859284705481723e-5
time 1.488- total energy: -27.928342607523923 +- 7.071967270015894e-5
time 1.49- total energy: -27.927874887748292 +- 6.890258938568218e-5
time 1.492- total energy: -27.92872611189641 +- 7.319157809817622e-5
time 1.494- total energy: -27.934456270199085 +- 7.670738312016313e-5
time 1.496- total energy: -27.941863544709115 +- 7.955278316045984e-5
time 1.498- total energy: -27.960456462783814 +- 8.404219185800459e-5
time 1.5- total energy: -27.961519221938406 +- 8.334853201664862e-5
time 1.502- total energy: -27.955328545278338 +- 7.154619789817614e-5
time 1.504- total energy: -27.95346898812549 +- 6.721543056139505e-5
time 1.506- total energy: -27.9610006619161 +- 6.987623370573035e-5
time 1.508- total energy: -27.965116228662946 +- 6.811271386913031e-5
time 1.51- total energy: -27.96797726613524 +- 6.949375341651579e-5
time 1.512- total energy: -27.95850236594474 +- 6.80157843756022e-5
time 1.514- total energy: -27.96380873125676 +- 6.82795684083793e-5
time 1.516- total energy: -27.965722142209152 +- 6.825013094852221e-5
time 1.518- total energy: -27.970943394979713 +- 6.726367958990992e-5
time 1.52- total energy: -27.96348298936823 +- 6.774407299342452e-5
time 1.522- total energy: -27.96008894718478 +- 7.279153995704887e-5
time 1.524- total energy: -27.963675481010526 +- 7.291289609656331e-5
time 1.526- total energy: -27.973442774721565 +- 7.348291276207241e-5
time 1.528- total energy: -27.97830595251701 +- 8.08483803672354e-5
time 1.53- total energy: -27.977200162565776 +- 9.333144762431236e-5
time 1.532- total energy: -27.979925373315076 +- 9.393113742178786e-5
time 1.534- total energy: -27.98023874683874 +- 9.351703121719581e-5
time 1.536- total energy: -27.980537864804884 +- 8.842696402894348e-5
time 1.538- total energy: -27.983019903081104 +- 8.881650028820822e-5
time 1.54- total energy: -27.98783236141137 +- 8.970744771989843e-5
time 1.542- total energy: -27.98717156023659 +- 8.509262207092001e-5
time 1.544- total energy: -27.98060212158343 +- 8.937605861393848e-5
time 1.546- total energy: -27.983234522995982 +- 8.984316453278589e-5
time 1.548- total energy: -27.997323028603457 +- 9.094675114685962e-5
time 1.55- total energy: -28.00813562299224 +- 7.621020873842333e-5
time 1.552- total energy: -28.010414532282343 +- 7.653027798948298e-5
time 1.554- total energy: -28.007089229786768 +- 7.697233736399855e-5
time 1.556- total energy: -28.009550102066253 +- 7.726730673617736e-5
time 1.558- total energy: -28.006543253247006 +- 7.278319316410754e-5
time 1.56- total energy: -28.011462537355875 +- 7.383423572743606e-5
time 1.562- total energy: -28.012425754895695 +- 7.947525200621096e-5
time 1.564- total energy: -28.00516331543033 +- 8.05179997558071e-5
time 1.566- total energy: -28.026143296995997 +- 8.089381927254927e-5
time 1.568- total energy: -28.020709798611414 +- 8.037985297945727e-5
time 1.57- total energy: -28.023478605417495 +- 8.06175294327619e-5
time 1.572- total energy: -28.02257084194412 +- 8.126995144785766e-5
time 1.574- total energy: -28.024711396354125 +- 8.15936641537759e-5
time 1.576- total energy: -28.02682437985004 +- 8.191726721063256e-5
time 1.578- total energy: -28.02604288398161 +- 8.881992938602709e-5
time 1.58- total energy: -28.038084161165486 +- 8.555392466437721e-5
time 1.582- total energy: -28.038729178394565 +- 8.557167697239867e-5
time 1.584- total energy: -28.04091653997187 +- 8.492421217625491e-5
time 1.586- total energy: -28.055164732561003 +- 9.78550110204928e-5
time 1.588- total energy: -28.056810840636256 +- 9.617668054887798e-5
time 1.59- total energy: -28.06003309603863 +- 8.662030365725863e-5
time 1.592- total energy: -28.060043010167604 +- 9.439744937793436e-5
time 1.594- total energy: -28.062673455173467 +- 9.31861945901051e-5
time 1.596- total energy: -28.064559769376974 +- 9.341197084251077e-5
time 1.598- total energy: -28.06780644182499 +- 0.00010042530960018589
time 1.6- total energy: -28.069514482211062 +- 0.00010038909721079648
time 1.602- total energy: -28.074030685489916 +- 8.988136799955603e-5
time 1.604- total energy: -28.074193626594493 +- 9.072582998544712e-5
time 1.606- total energy: -28.073305094116172 +- 9.174477003496302e-5
time 1.608- total energy: -28.07618374883189 +- 8.677293459986969e-5
time 1.61- total energy: -28.074473070664745 +- 9.314763674603655e-5
time 1.612- total energy: -28.075883828837313 +- 9.351121202759697e-5
time 1.614- total energy: -28.077013036592586 +- 9.388056661688079e-5
time 1.616- total energy: -28.079929633648103 +- 9.848199651687696e-5
time 1.618- total energy: -28.085815097371384 +- 9.717017454803653e-5
time 1.62- total energy: -28.082521385356973 +- 9.9965003311974e-5
time 1.622- total energy: -28.08549128605678 +- 9.754883093182863e-5
time 1.624- total energy: -28.077686540783095 +- 0.00010172266638678259
time 1.626- total energy: -28.078549913542204 +- 0.00010190142528865972
time 1.628- total energy: -28.071043957551108 +- 9.633453872843349e-5
time 1.63- total energy: -28.07450510165726 +- 0.00010551377082692157
time 1.632- total energy: -28.08005602455793 +- 0.00010979390259824225
time 1.634- total energy: -28.080757207461616 +- 0.0001098622443589126
time 1.636- total energy: -28.081312841326753 +- 0.00010935954828248896
time 1.638- total energy: -28.084750191088933 +- 0.00010395343119931783
time 1.64- total energy: -28.085398507925035 +- 0.00010386707359035348
time 1.642- total energy: -28.07596653470854 +- 0.00010431656542376974
time 1.644- total energy: -28.07574997360475 +- 0.00010389957162505488
time 1.646- total energy: -28.09243720055925 +- 0.00010428387808466373
time 1.648- total energy: -28.077257756034406 +- 9.889741325527639e-5
time 1.65- total energy: -28.080447437545683 +- 0.0001000251069131869
time 1.652- total energy: -28.07565382313341 +- 0.00011043546452958789
time 1.654- total energy: -28.082177989021137 +- 0.00010514600411067964
time 1.656- total energy: -28.085728709882215 +- 9.954314679856071e-5
time 1.658- total energy: -28.079933011057726 +- 9.946774839697242e-5
time 1.66- total energy: -28.083914214544116 +- 9.87668966935954e-5
time 1.662- total energy: -28.080018553936704 +- 0.0001032839755401442
time 1.664- total energy: -28.0756048216908 +- 0.00010132553319528061
time 1.666- total energy: -28.07656215584185 +- 9.84548682227691e-5
time 1.668- total energy: -28.083225331511315 +- 9.801657119181698e-5
time 1.67- total energy: -28.081607982135164 +- 9.890470581570939e-5
time 1.672- total energy: -28.07815519161965 +- 9.764671116534293e-5
time 1.674- total energy: -28.0891266958275 +- 9.337792506650931e-5
time 1.676- total energy: -28.093527150236227 +- 9.727592529502065e-5
time 1.678- total energy: -28.090690861634908 +- 0.00010050403999832422
time 1.68- total energy: -28.089344005257352 +- 9.889326487423834e-5
time 1.682- total energy: -28.09213209230086 +- 9.970072772708502e-5
time 1.684- total energy: -28.0931887038263 +- 0.00010462611364812802
time 1.686- total energy: -28.0903384266855 +- 0.00011015753411620041
time 1.688- total energy: -28.09560709752173 +- 0.00011250900137128858
time 1.69- total energy: -28.09357080351952 +- 0.00011019899378896635
time 1.692- total energy: -28.090639198144196 +- 0.00010075842600815203
time 1.694- total energy: -28.09122746354781 +- 0.0001047466852105093
time 1.696- total energy: -28.091922169605635 +- 0.00012003782728191425
time 1.698- total energy: -28.09401036120686 +- 0.0001200307399341239
time 1.7- total energy: -28.095668717330053 +- 0.0001134329034997092
time 1.702- total energy: -28.089453329044513 +- 0.00010255574475356493
time 1.704- total energy: -28.09195630106674 +- 0.00010568386542642423
time 1.706- total energy: -28.0948017717936 +- 9.803102983117872e-5
time 1.708- total energy: -28.09933749928637 +- 0.00011200789104638433
time 1.71- total energy: -28.097359457912017 +- 0.00010688183691714778
time 1.712- total energy: -28.095111334801675 +- 0.00011017753188829925
time 1.714- total energy: -28.08981112514523 +- 0.00011388354270176109
time 1.716- total energy: -28.09741818918891 +- 0.00011692996890350881
time 1.718- total energy: -28.102987799570187 +- 0.0001214262146935285
time 1.72- total energy: -28.102024314851448 +- 0.00012309962877796472
time 1.722- total energy: -28.099427180491393 +- 0.0001229022407988061
time 1.724- total energy: -28.097391712862347 +- 0.00011655414204835224
time 1.726- total energy: -28.095616881397863 +- 0.0001232383222993369
time 1.728- total energy: -28.096813759857 +- 0.00011997453888074497
time 1.73- total energy: -28.096646693852996 +- 0.00011961375090033855
time 1.732- total energy: -28.094125833187697 +- 0.00010689446572631133
time 1.734- total energy: -28.088140695921084 +- 9.809020252257017e-5
time 1.736- total energy: -28.093627849127888 +- 9.083011704849729e-5
time 1.738- total energy: -28.09550192956781 +- 0.00010164462868755471
time 1.74- total energy: -28.09921584902499 +- 0.00010172082906451563
time 1.742- total energy: -28.093595129013664 +- 9.837590692385431e-5
time 1.744- total energy: -28.091999064516752 +- 9.237877644638267e-5
time 1.746- total energy: -28.091402072271944 +- 9.402245128193744e-5
time 1.748- total energy: -28.09217057772725 +- 9.651744445134973e-5
time 1.75- total energy: -28.099083649325372 +- 0.00010304632304739393
time 1.752- total energy: -28.089692438930125 +- 0.00010564129963832377
time 1.754- total energy: -28.089218138882632 +- 0.00010309357265770169
time 1.756- total energy: -28.086769974089318 +- 0.00020228974413640454
time 1.758- total energy: -28.086028610397346 +- 0.00019039217324013478
time 1.76- total energy: -28.082884655086026 +- 0.00018223496170370122
time 1.762- total energy: -28.086713860205354 +- 0.00017850588637679263
time 1.764- total energy: -28.087108533382242 +- 0.00017817650631769052
time 1.766- total energy: -28.090043562583542 +- 0.0001774636740572057
time 1.768- total energy: -28.083057615557564 +- 0.000167858504832432
time 1.77- total energy: -28.083823431864744 +- 0.00016321732745173086
time 1.772- total energy: -28.08258449335363 +- 0.00016055621954896653
time 1.774- total energy: -28.072592372916557 +- 0.00016207642537834776
time 1.776- total energy: -28.077995054160144 +- 0.00017311731086969417
time 1.778- total energy: -28.075251145451332 +- 0.0001614534843709251
time 1.78- total energy: -28.074721783928975 +- 0.0001560449678108529
time 1.782- total energy: -28.080990976264033 +- 0.0001509692733556795
time 1.784- total energy: -28.0745666812731 +- 0.00015616158102088905
time 1.786- total energy: -28.08039287357715 +- 0.00010714806144210615
time 1.788- total energy: -28.080909578679883 +- 0.0001096377218150379
time 1.79- total energy: -28.081482360426694 +- 0.00010781518119448908
time 1.792- total energy: -28.081353025270435 +- 0.0001071542811275123
time 1.794- total energy: -28.080686591194993 +- 0.00010946627475431923
time 1.796- total energy: -28.078569444954894 +- 0.00010827335031251798
time 1.798- total energy: -28.07968847757103 +- 0.00010595929040551151
time 1.8- total energy: -28.07547685898573 +- 0.00011155717309401886
time 1.802- total energy: -28.07976172357196 +- 0.00010982842456125576
time 1.804- total energy: -28.07000995496134 +- 0.0001493438054296894
time 1.806- total energy: -28.07262833856423 +- 0.00014450812073955413
time 1.808- total energy: -28.07806854341081 +- 9.851167036121994e-5
time 1.81- total energy: -28.081516190336785 +- 9.978945147183347e-5
time 1.812- total energy: -28.074325939826227 +- 0.00010224500298281326
time 1.814- total energy: -28.073517818360102 +- 0.00010215536068321817
time 1.816- total energy: -28.071934153190746 +- 0.00011214276643612779
time 1.818- total energy: -28.071757984695875 +- 0.00011508404630731806
time 1.82- total energy: -28.068899318023174 +- 0.00011305270203404362
time 1.822- total energy: -28.0670878049238 +- 9.131586007955069e-5
time 1.824- total energy: -28.064283701911716 +- 0.00011353794882464427
time 1.826- total energy: -28.062793637846287 +- 0.00011513407482616864
time 1.828- total energy: -28.06414397639816 +- 0.00012887016966898798
time 1.83- total energy: -28.0659763318868 +- 0.00012655808000424572
time 1.832- total energy: -28.061174871387195 +- 0.00012452026230897115
time 1.834- total energy: -28.058525639678155 +- 0.00012507040520580619
time 1.836- total energy: -28.057896932171634 +- 0.0001132061177373721
time 1.838- total energy: -28.063243653764047 +- 9.424048655193689e-5
time 1.84- total energy: -28.061002716138773 +- 9.387261880800629e-5
time 1.842- total energy: -28.068818435393528 +- 9.604210828070551e-5
time 1.844- total energy: -28.076975314260824 +- 0.00011005081060418213
time 1.846- total energy: -28.053834227907988 +- 0.00035871630977161783
time 1.848- total energy: -28.04430374093416 +- 0.00034861638472790985
time 1.85- total energy: -28.04138909123226 +- 0.00035841259837797034
time 1.852- total energy: -28.04793972210574 +- 0.0001204615890314436
time 1.854- total energy: -28.049785440596494 +- 0.00011728318719585358
time 1.856- total energy: -28.049829745577394 +- 0.0001171218896205413
time 1.858- total energy: -28.050861546744805 +- 0.00012054242122673189
time 1.86- total energy: -28.064404557369482 +- 0.00010906268293003848
time 1.862- total energy: -28.068897566331533 +- 0.00011873065403789612
time 1.864- total energy: -28.052232260225033 +- 0.0001302524985208275
time 1.866- total energy: -28.050530770119543 +- 0.00013521112368769275
time 1.868- total energy: -28.064366867134247 +- 0.00016099987355140924
time 1.87- total energy: -28.05732291283562 +- 0.00016046768122934845
time 1.872- total energy: -28.063829879143224 +- 0.00014894368246251384
time 1.874- total energy: -28.064289601547344 +- 0.00012248325526130003
time 1.876- total energy: -28.058010328065865 +- 0.00011502240533801013
time 1.878- total energy: -28.063624356852003 +- 0.0001286030620758323
time 1.88- total energy: -28.054928532145635 +- 0.00014520330405790792
time 1.882- total energy: -28.04819550573747 +- 0.00012952708386185693
time 1.884- total energy: -28.044543160630685 +- 0.000131316208123607
time 1.886- total energy: -28.057198159347376 +- 0.00011926526159841169
time 1.888- total energy: -28.05038582238622 +- 0.00011979277098156132
time 1.89- total energy: -28.05376726180648 +- 0.00011342883775019623
time 1.892- total energy: -28.063662807440647 +- 0.00011889955011289477
time 1.894- total energy: -28.05792647463945 +- 0.000118265701537401
time 1.896- total energy: -28.05601489524149 +- 0.00012412131333866343
time 1.898- total energy: -28.05168340291267 +- 0.00012623094101319208
time 1.9- total energy: -28.04902650550894 +- 0.00012322643978754437
time 1.902- total energy: -28.043948320374017 +- 0.00012220933113696658
time 1.904- total energy: -28.05322220314462 +- 0.0001212299030123245
time 1.906- total energy: -28.050719233982626 +- 0.0001276563801363293
time 1.908- total energy: -28.056817556882084 +- 0.00012575131806401182
time 1.91- total energy: -28.05986138898221 +- 0.00012747449788590712
time 1.912- total energy: -28.063017763873344 +- 0.00012681947756765807
time 1.914- total energy: -28.057662386301146 +- 0.00012547149504997786
time 1.916- total energy: -28.065376480444733 +- 0.00013205183604369968
time 1.918- total energy: -28.054650718788547 +- 0.00012817085111156248
time 1.92- total energy: -28.04045275492231 +- 0.00011345961638914772
time 1.922- total energy: -28.04921523486113 +- 0.00011744036914831578
time 1.924- total energy: -28.054178947379917 +- 0.00011954540115281346
time 1.926- total energy: -28.048697942897498 +- 0.00011872662356941563
time 1.928- total energy: -28.042983523366463 +- 0.00010941541496809834
time 1.93- total energy: -28.042362054895243 +- 0.00011142176694396895
time 1.932- total energy: -28.04348480667903 +- 0.0001075433435516669
time 1.934- total energy: -28.045264617543904 +- 0.00010990226124910052
time 1.936- total energy: -28.048999249393642 +- 0.00010806960126718293
time 1.938- total energy: -28.054223080115094 +- 0.00011914009607268868
time 1.94- total energy: -28.045898833317533 +- 0.00011460044823031842
time 1.942- total energy: -28.031606980737664 +- 0.00012192001809408355
time 1.944- total energy: -28.03704261968523 +- 0.00012768744650312646
time 1.946- total energy: -28.032619872272367 +- 0.00012197369745905082
time 1.948- total energy: -28.028951074004677 +- 0.0001159031468448661
time 1.95- total energy: -28.038397051817718 +- 0.00010274679632053858
time 1.952- total energy: -28.041990910586716 +- 0.00010359116490516085
time 1.954- total energy: -28.04467491170979 +- 0.00010927645292109241
time 1.956- total energy: -28.04206433805394 +- 0.00010877942826343219
time 1.958- total energy: -28.050058736607173 +- 0.00011133933576398782
time 1.96- total energy: -28.045697483939236 +- 0.00011310056495818639
time 1.962- total energy: -28.038173399129196 +- 0.00011922656310990159
time 1.964- total energy: -28.045457542992143 +- 0.00011324183624715183
time 1.966- total energy: -28.041733157976445 +- 0.00012149860985689289
time 1.968- total energy: -28.043364138187957 +- 0.00011610827404798828
time 1.97- total energy: -28.039335968410175 +- 0.00011673603082045135
time 1.972- total energy: -28.03552142324874 +- 0.00011595469252130967
time 1.974- total energy: -28.03431250527693 +- 0.00011081140254591318
time 1.976- total energy: -28.03455356955006 +- 0.00011340104199700435
time 1.978- total energy: -28.036186795598905 +- 0.0001108436820173157
time 1.98- total energy: -28.034677991840347 +- 0.00010756205668886873
time 1.982- total energy: -28.043411460638584 +- 0.00010184369782607792
time 1.984- total energy: -28.043268716805336 +- 9.61366546461293e-5
time 1.986- total energy: -28.049830206847663 +- 9.321304115990887e-5
time 1.988- total energy: -28.051948912414037 +- 9.375447825467317e-5
time 1.99- total energy: -28.05527513368728 +- 9.778525398523265e-5
time 1.992- total energy: -28.04828007671631 +- 9.537153481755083e-5
time 1.994- total energy: -28.05943590588032 +- 0.00010016547884304983
time 1.996- total energy: -28.065797544285882 +- 0.00011395150084857639
time 1.998- total energy: -28.056254001441356 +- 0.00011386864018322871
time 2.0- total energy: -28.03175186934168 +- 0.00029550108083540357
time 2.002- total energy: -28.04084214974858 +- 0.00029133950428436773
time 2.004- total energy: -28.035115240103245 +- 0.0002883744410874171
time 2.006- total energy: -28.02209384367438 +- 0.00028129988225431533
time 2.008- total energy: -28.04737665196388 +- 0.00011101198575722232
time 2.01- total energy: -28.039777377765148 +- 0.00011087855927436361
time 2.012- total energy: -28.04812411985593 +- 0.00011191818556147587
time 2.014- total energy: -28.04437001191604 +- 0.00011369504044811511
time 2.016- total energy: -28.04373369285612 +- 0.00011476758936313304
time 2.018- total energy: -28.04589975388167 +- 0.00011449522367517846
time 2.02- total energy: -28.042323834875944 +- 0.00011436641421118661
time 2.022- total energy: -28.05239881263958 +- 0.00011586700934634962
time 2.024- total energy: -28.043005713729205 +- 0.00011374430922285048
time 2.026- total energy: -28.041148254389814 +- 0.0001171631586487382
time 2.028- total energy: -28.04353387637476 +- 0.00013133427865551363
time 2.03- total energy: -28.038875670992674 +- 0.00012870672077422193
time 2.032- total energy: -28.043229375431093 +- 0.00012922043692664345
time 2.034- total energy: -28.04106358325081 +- 0.00013189250429180847
time 2.036- total energy: -28.030671730356673 +- 0.00012512211358082763
time 2.038- total energy: -28.03441742678912 +- 0.00011824048798613692
time 2.04- total energy: -28.033713911583934 +- 0.00011845410197248136
time 2.042- total energy: -28.025506169081268 +- 0.00011727158802488887
time 2.044- total energy: -28.019855361429133 +- 0.00011903608220055507
time 2.046- total energy: -28.019575649513524 +- 0.00011984982932288497
time 2.048- total energy: -28.01602359871538 +- 0.00011777966689761675
time 2.05- total energy: -28.019569872149994 +- 0.0001161189069666202
time 2.052- total energy: -28.027396313685788 +- 0.00011819535944371432
time 2.054- total energy: -28.033308561695918 +- 0.00012519659695755004
time 2.056- total energy: -28.027434147270952 +- 0.00013144905509137188
time 2.058- total energy: -28.011882110199046 +- 0.0003087118739395258
time 2.06- total energy: -28.01355681982893 +- 0.00030442120429034417
time 2.062- total energy: -28.016905751839317 +- 0.0003038067847225279
time 2.064- total energy: -28.01918317377219 +- 0.00030623267576546266
time 2.066- total energy: -28.01304013802711 +- 0.0002977897156259156
time 2.068- total energy: -28.018932564422457 +- 0.0002935259221625761
time 2.07- total energy: -28.01703856169551 +- 0.0002883617292964469
time 2.072- total energy: -28.00546406320891 +- 0.00027782827631956715
time 2.074- total energy: -28.00304733739446 +- 0.00028387248589230226
time 2.076- total energy: -28.00915524603435 +- 0.0002832124091383184
time 2.078- total energy: -28.003978034092587 +- 0.0002845690258888741
time 2.08- total energy: -28.00573855232102 +- 0.0002890540691037767
time 2.082- total energy: -28.023404311521837 +- 0.0004831569237934102
time 2.084- total energy: -28.030499938227724 +- 0.00046973399784369223
time 2.086- total energy: -28.01079334260159 +- 0.0002627589698451691
time 2.088- total energy: -28.00924318239485 +- 0.00026963948280672826
time 2.09- total energy: -28.025143996325607 +- 0.00011763484100078463
time 2.092- total energy: -28.02655778995429 +- 0.00011954449675486392
time 2.094- total energy: -28.02566629647795 +- 0.00011981229594000801
time 2.096- total energy: -28.024450830206938 +- 0.00010839666227751915
time 2.098- total energy: -28.023521735500772 +- 0.00011373133158202118
time 2.1- total energy: -28.020411511979564 +- 0.00010771462218164939
time 2.102- total energy: -28.01786442353245 +- 0.00011232482867786994
time 2.104- total energy: -28.014785528339544 +- 0.00011417335909593591
time 2.106- total energy: -28.02963007009211 +- 0.00011172964010523279
time 2.108- total energy: -28.034890212812527 +- 0.0001143021676058703
time 2.11- total energy: -28.03703266004361 +- 0.00011349482084057034
time 2.112- total energy: -28.021694099440385 +- 0.00011072942004197369
time 2.114- total energy: -28.02634127100766 +- 0.00010921533116771011
time 2.116- total energy: -28.02338052559262 +- 0.00011677229131629109
time 2.118- total energy: -28.019342508083433 +- 0.00011918620628638441
time 2.12- total energy: -28.02865528002725 +- 0.0001222172330826228
time 2.122- total energy: -28.025797199688217 +- 0.00013348768140576602
time 2.124- total energy: -28.025853645644762 +- 0.00013353607215637272
time 2.126- total energy: -28.02246461048839 +- 0.00013133375470587982
time 2.128- total energy: -28.02488228343168 +- 0.00013020975882597016
time 2.13- total energy: -28.018874011946913 +- 0.00012486270082408786
time 2.132- total energy: -28.02072763467651 +- 0.00012026796156686771
time 2.134- total energy: -28.022569335011173 +- 0.00011849242310252937
time 2.136- total energy: -28.02334367069452 +- 0.00011305975269000458
time 2.138- total energy: -28.023783229487666 +- 0.00011072747493485894
time 2.14- total energy: -28.022121802901534 +- 0.00011121377730076962
time 2.142- total energy: -28.021834944131598 +- 0.00012246202143197354
time 2.144- total energy: -28.021397376357303 +- 0.00011990771288645626
time 2.146- total energy: -28.02748326411049 +- 0.00012745641494596875
time 2.148- total energy: -28.027425522464153 +- 0.00012363130872915397
time 2.15- total energy: -28.031770342724073 +- 0.00024262650856358273
time 2.152- total energy: -28.03282142869706 +- 0.0002450035586127096
time 2.154- total energy: -28.029960211629017 +- 0.00023794612112928854
time 2.156- total energy: -28.02934054541069 +- 0.00021826454402755984
time 2.158- total energy: -28.027549115119736 +- 0.00021275950976791015
time 2.16- total energy: -28.028471576435738 +- 0.00021034643066349552
time 2.162- total energy: -28.033725613262437 +- 0.0001301965279010741
time 2.164- total energy: -28.0394720955607 +- 0.0001261415891006221
time 2.166- total energy: -28.03521614711237 +- 0.00013122162685791185
time 2.168- total energy: -28.028736975047572 +- 0.0001469471567801832
time 2.17- total energy: -28.026626891131915 +- 0.0001451252472457838
time 2.172- total energy: -28.028837650856108 +- 0.00014024336961283824
time 2.174- total energy: -28.031279942046073 +- 0.00014114662096965613
time 2.176- total energy: -28.028925735315344 +- 0.00014280840227152866
time 2.178- total energy: -28.02353590597392 +- 0.0001356513302356268
time 2.18- total energy: -28.025341876603907 +- 0.00013404910732946234
time 2.182- total energy: -28.02942944861695 +- 0.00013288718850342155
time 2.184- total energy: -28.031232031961363 +- 0.00011512563926136537
time 2.186- total energy: -28.02605784986826 +- 0.00012070807218866364
time 2.188- total energy: -28.020230959583255 +- 0.00013905671831348338
time 2.19- total energy: -28.021039197254698 +- 0.0001473154071731933
time 2.192- total energy: -28.023169460738956 +- 0.00013886435460538763
time 2.194- total energy: -28.02234363102464 +- 0.00013668240459256513
time 2.196- total energy: -28.019041853513606 +- 0.000129869176853238
time 2.198- total energy: -28.017110360850666 +- 0.00013019280946593783
time 2.2- total energy: -28.02277926566196 +- 0.00013371401397460847
time 2.202- total energy: -28.017595454581123 +- 0.00013939431807388596
time 2.204- total energy: -28.021766821033577 +- 0.00013126277334130301
time 2.206- total energy: -28.02422037158693 +- 0.0001358075794574408
time 2.208- total energy: -28.02262772613949 +- 0.0001386797109963546
time 2.21- total energy: -28.02227435831409 +- 0.0001375932379154183
time 2.212- total energy: -28.020994589604545 +- 0.00013763925874266775
time 2.214- total energy: -28.019170540930833 +- 0.00013590426355856473
time 2.216- total energy: -28.02120862108172 +- 0.00018687393473493632
time 2.218- total energy: -28.02605548756068 +- 0.00018291718950813558
time 2.22- total energy: -28.028449601100977 +- 0.0001749885085416386
time 2.222- total energy: -28.021847798994294 +- 0.0001410001860001173
time 2.224- total energy: -28.029297197723483 +- 0.0001366854054457263
time 2.226- total energy: -28.020906470140332 +- 0.00012613149221672336
time 2.228- total energy: -28.020693460169433 +- 0.0001261966056473711
time 2.23- total energy: -28.020371717405705 +- 0.00012917569878942095
time 2.232- total energy: -28.022629827053404 +- 0.00012949562165614397
time 2.234- total energy: -28.020087072249716 +- 0.00012748682453478618
time 2.236- total energy: -28.025302552306755 +- 0.00012821926745079746
time 2.238- total energy: -28.026553192585055 +- 0.0001237807749297531
time 2.24- total energy: -28.026910573814234 +- 0.00012384508596969588
time 2.242- total energy: -28.022285976568575 +- 0.00012410730638293496
time 2.244- total energy: -28.02473420979265 +- 0.000122628585193097
time 2.246- total energy: -28.01674925735816 +- 0.00012617383923932171
time 2.248- total energy: -28.020049458250064 +- 0.00013516393476108548
time 2.25- total energy: -28.018931346360976 +- 0.00012771643762113396
time 2.252- total energy: -28.02344213872742 +- 0.00013330995451616817
time 2.254- total energy: -28.01593095830074 +- 0.00013755924882573542
time 2.256- total energy: -28.013623217105092 +- 0.0001364221501779904
time 2.258- total energy: -28.002906296410394 +- 0.00024280348553556812
time 2.26- total energy: -28.0102616413311 +- 0.000196184864734263
time 2.262- total energy: -28.020916919478097 +- 0.00013033438969581903
time 2.264- total energy: -28.017989855738954 +- 0.00013176677437131776
time 2.266- total energy: -28.020669438336252 +- 0.00014070649961402766
time 2.268- total energy: -28.02785496911269 +- 0.00018421999725857087
time 2.27- total energy: -28.03424359891888 +- 0.00014863386949526896
time 2.272- total energy: -28.012308103878716 +- 0.00013893087916452333
time 2.274- total energy: -28.011230783723118 +- 0.00013470230721782095
time 2.276- total energy: -28.02082310527191 +- 0.00013430309487953444
time 2.278- total energy: -28.025402074237185 +- 0.00012555914607587006
time 2.28- total energy: -28.024637490904272 +- 0.00012464022869625133
time 2.282- total energy: -28.018381643278527 +- 0.00012957074493764276
time 2.284- total energy: -28.01714847929402 +- 0.00013549899804973846
time 2.286- total energy: -28.025674565252988 +- 0.00013617693789077953
time 2.288- total energy: -28.02252027546701 +- 0.0001408150390970974
time 2.29- total energy: -28.024779238761216 +- 0.00014304903492342783
time 2.292- total energy: -28.033904116356627 +- 0.00013804403590925296
time 2.294- total energy: -28.027946539783148 +- 0.00014911932949011742
time 2.296- total energy: -28.023971102464934 +- 0.00013045650685853752
time 2.298- total energy: -28.023666196985054 +- 0.00013361778832942406
time 2.3- total energy: -28.02280854316037 +- 0.0001295280263824052
time 2.302- total energy: -28.02832464026562 +- 0.00013129609573379826
time 2.304- total energy: -28.028895442615664 +- 0.00013164529975543814
time 2.306- total energy: -28.04180018456771 +- 0.00012330935182550012
time 2.308- total energy: -28.03516694682659 +- 0.00012350004354300773
time 2.31- total energy: -28.0461536400713 +- 0.00018785063945472418
time 2.312- total energy: -28.038085969355627 +- 0.0002263570689999584
time 2.314- total energy: -28.03948142968624 +- 0.00021838770912782662
time 2.316- total energy: -28.004571810399035 +- 0.0003129307837393239
time 2.318- total energy: -28.017328999143526 +- 0.00021620437594903664
time 2.32- total energy: -28.010022066459623 +- 0.00021451869229985803
time 2.322- total energy: -28.0172458676655 +- 0.00021560914680690874
time 2.324- total energy: -28.040916643308886 +- 0.00022173189728123436
time 2.326- total energy: -28.047340592492795 +- 0.00022424184567944446
time 2.328- total energy: -28.036581390556915 +- 0.0001264789135472699
time 2.33- total energy: -28.032297043725126 +- 0.0001269463142476836
time 2.332- total energy: -28.018812745636374 +- 0.00014233154203591777
time 2.334- total energy: -28.023458138050074 +- 0.0001447980758686982
time 2.336- total energy: -28.031021314711392 +- 0.00013825875340782513
time 2.338- total energy: -28.033493392845322 +- 0.00013481266466078943
time 2.34- total energy: -28.030725727436895 +- 0.00014075828899462692
time 2.342- total energy: -28.03105197922775 +- 0.0001402741871910089
time 2.344- total energy: -28.036802203699203 +- 0.00014071692907607604
time 2.346- total energy: -28.036736471928794 +- 0.00012966511917385356
time 2.348- total energy: -28.037763845678857 +- 0.00012406269851884499
time 2.35- total energy: -28.03614411145286 +- 0.0001269916627050244
time 2.352- total energy: -28.039733703377372 +- 0.00012576742421152538
time 2.354- total energy: -28.04238634196488 +- 0.00012467666357661049
time 2.356- total energy: -28.04233750412489 +- 0.00012444534539845522
time 2.358- total energy: -28.038939011453373 +- 0.00013563065153875104
time 2.36- total energy: -28.026197248004415 +- 0.0002336479353279434
time 2.362- total energy: -28.019897736079113 +- 0.0002444436990132403
time 2.364- total energy: -28.022688180736147 +- 0.0002428529020287956
time 2.366- total energy: -28.025983021681203 +- 0.0002379571136050947
time 2.368- total energy: -28.040189469689114 +- 0.0001454648715358327
time 2.37- total energy: -28.041342335201954 +- 0.00014116545418956482
time 2.372- total energy: -28.043128428498672 +- 0.0001441295364987946
time 2.374- total energy: -28.04669326563563 +- 0.0001428039149187924
time 2.376- total energy: -28.046950083026804 +- 0.00014325782364909837
time 2.378- total energy: -28.041025332404427 +- 0.00017762739076442548
time 2.38- total energy: -28.03834722737947 +- 0.00016990733822523293
time 2.382- total energy: -28.035918162573235 +- 0.00017680573113775273
time 2.384- total energy: -28.0364254325587 +- 0.00017781042481277966
time 2.386- total energy: -28.05666861150863 +- 0.0001825899099525642
time 2.388- total energy: -28.063447943327983 +- 0.00016941322069132067
time 2.39- total energy: -28.055722757775513 +- 0.00015032439785797234
time 2.392- total energy: -28.061314591670136 +- 0.0001403859555742494
time 2.394- total energy: -28.06106562405839 +- 0.0001403905705275661
time 2.396- total energy: -28.0533281322705 +- 0.0001371071954862879
time 2.398- total energy: -28.053281089230445 +- 0.00013726033506650077
time 2.4- total energy: -28.04903552309123 +- 0.00013535818614747016
time 2.402- total energy: -28.051799582008183 +- 0.00012353762740900887
time 2.404- total energy: -28.05154623569073 +- 0.00012648546033067648
time 2.406- total energy: -28.0451355708749 +- 0.0001555000098891483
time 2.408- total energy: -28.047662469867877 +- 0.000134535261755926
time 2.41- total energy: -28.044330598553323 +- 0.0001401223999204299
time 2.412- total energy: -28.0354038487523 +- 0.0001269968036586695
time 2.414- total energy: -28.037041086881093 +- 0.00012312209605060267
time 2.416- total energy: -28.035235177799034 +- 0.00012289378715961289
time 2.418- total energy: -28.02863280733338 +- 0.0001334413351348534
time 2.42- total energy: -28.033223835453004 +- 0.00013710805322510124
time 2.422- total energy: -28.033112945732107 +- 0.0001241304617269622
time 2.424- total energy: -28.032786627130807 +- 0.0001239764677684945
time 2.426- total energy: -28.029194931147483 +- 0.00012824427691202967
time 2.428- total energy: -28.02553871159735 +- 0.00013063091818096335
time 2.43- total energy: -28.02630727509333 +- 0.00013036489216636515
time 2.432- total energy: -28.029634823816956 +- 0.00012882703717487584
time 2.434- total energy: -28.0430884488947 +- 0.00013765291270665213
time 2.436- total energy: -28.042762069374966 +- 0.00013703439757800447
time 2.438- total energy: -28.043935809011476 +- 0.00014092620216758385
time 2.44- total energy: -28.047212793954344 +- 0.0001323481118752633
time 2.442- total energy: -28.03816567084705 +- 0.00012990683269036702
time 2.444- total energy: -28.03850227192637 +- 0.0001251023684873939
time 2.446- total energy: -28.03546279646177 +- 0.0001281459672066861
time 2.448- total energy: -28.020553786345996 +- 0.00011908224557484756
time 2.45- total energy: -28.026098739140714 +- 0.00011539249039588314
time 2.452- total energy: -28.02914360570411 +- 0.0001193849901755222
time 2.454- total energy: -28.03214878073232 +- 0.00011671735401818884
time 2.456- total energy: -28.027019126691727 +- 0.0001201917021014044
time 2.458- total energy: -28.024589440557442 +- 0.00013197318038893772
time 2.46- total energy: -28.028024794236373 +- 0.00012768165886963253
time 2.462- total energy: -28.043792604462226 +- 0.000123529417877561
time 2.464- total energy: -28.045369310245157 +- 0.0001209442084187019
time 2.466- total energy: -28.023946310926434 +- 0.00015653446930265842
time 2.468- total energy: -28.020959524460526 +- 0.00015835313346619824
time 2.47- total energy: -28.023375174648404 +- 0.00015970893563313208
time 2.472- total energy: -28.0253899640644 +- 0.00016415256807942295
time 2.474- total energy: -28.02626829577317 +- 0.00012292235883526977
time 2.476- total energy: -28.02915890349039 +- 0.00013045431129696255
time 2.478- total energy: -28.018101604816508 +- 0.0001300862497145654
time 2.48- total energy: -28.02365420789737 +- 0.00012101321068593699
time 2.482- total energy: -28.024611145528407 +- 0.00011948588211555652
time 2.484- total energy: -28.02902413990995 +- 0.00012039096346823265
time 2.486- total energy: -28.03001571755203 +- 0.00011966709358935688
time 2.488- total energy: -28.04119228772132 +- 0.00012473088877813335
time 2.49- total energy: -28.042361690481176 +- 0.00012923750769956952
time 2.492- total energy: -28.03742903694077 +- 0.00013416114291619775
time 2.494- total energy: -28.03354258574151 +- 0.0001721561611654023
time 2.496- total energy: -28.038073506691134 +- 0.00017831766158146262
time 2.498- total energy: -28.030688859519014 +- 0.00017009132428169154
time 2.5- total energy: -28.03286096704672 +- 0.00013742988957136373
time 2.502- total energy: -28.03429197010378 +- 0.0001325794044035266
time 2.504- total energy: -28.031745828128535 +- 0.0001382941733450926
time 2.506- total energy: -28.032088478389177 +- 0.00013479606914205776
time 2.508- total energy: -28.0307332776016 +- 0.00014036268746462933
time 2.51- total energy: -28.031138868044877 +- 0.00016224409614443668
time 2.512- total energy: -28.025317137717405 +- 0.0001576574217732504
time 2.514- total energy: -28.025203816862767 +- 0.0001576392172255838
time 2.516- total energy: -28.022369583848658 +- 0.00015828512125901792
time 2.518- total energy: -28.011008360236676 +- 0.0001419065628558178
time 2.52- total energy: -28.01589086311183 +- 0.0001394592332760294
time 2.522- total energy: -28.014009127798357 +- 0.0001808081886202415
time 2.524- total energy: -28.026037472306488 +- 0.00013144969694363736
time 2.526- total energy: -28.025760150181977 +- 0.000126066088900077
time 2.528- total energy: -28.021705143713188 +- 0.0001298397169355198
time 2.53- total energy: -28.026087316888674 +- 0.00013368244542486356
time 2.532- total energy: -28.022572725702865 +- 0.00012883049705797746
time 2.534- total energy: -28.031021979082848 +- 0.00012147468108831283
time 2.536- total energy: -28.02779832763423 +- 0.00011985395065112865
time 2.538- total energy: -28.021614555568767 +- 0.0001722297569272711
time 2.54- total energy: -28.02031044640863 +- 0.00018470017884413028
time 2.542- total energy: -28.015498627341927 +- 0.0001998004265960008
time 2.544- total energy: -28.01525993292783 +- 0.0001967242225284312
time 2.546- total energy: -28.027669764769005 +- 0.0001690249498596241
time 2.548- total energy: -28.02750918051299 +- 0.00017129288947798405
time 2.55- total energy: -28.030901150903354 +- 0.00014918515492931789
time 2.552- total energy: -28.03106935342371 +- 0.0001540167937547527
time 2.554- total energy: -28.03195055016957 +- 0.00014197528210731095
time 2.556- total energy: -28.036144624151284 +- 0.00011538159198931233
time 2.558- total energy: -28.0362558651832 +- 0.00012715966234004843
time 2.56- total energy: -28.041179789033205 +- 0.0001324863071700846
time 2.562- total energy: -28.033737152835897 +- 0.00015566616646049973
time 2.564- total energy: -28.03640066860783 +- 0.00015097228131295227
time 2.566- total energy: -28.031333578827805 +- 0.00015352479447579517
time 2.568- total energy: -28.038156288978023 +- 0.00013171128259311206
time 2.57- total energy: -28.037622092611308 +- 0.0001320432708992341
time 2.572- total energy: -28.03180572107649 +- 0.00013666201659080516
time 2.574- total energy: -28.024489294263233 +- 0.00013081553121374243
time 2.576- total energy: -28.02800875949805 +- 0.00013868002203453565
time 2.578- total energy: -28.028399994013757 +- 0.00012792425339191958
time 2.58- total energy: -28.029366646568935 +- 0.0001283103699664038
time 2.582- total energy: -28.03009043774732 +- 0.00012723361498766215
time 2.584- total energy: -28.026832260921434 +- 0.00013166735401306327
time 2.586- total energy: -28.02238556355483 +- 0.00014201404354674253
time 2.588- total energy: -28.025103020574992 +- 0.0001362385277031322
time 2.59- total energy: -28.029063223813772 +- 0.00013267047268652972
time 2.592- total energy: -28.024460008315398 +- 0.00013671635759267503
time 2.594- total energy: -28.02057199121476 +- 0.00015689222634898475
time 2.596- total energy: -28.020404280255363 +- 0.00015511968088259686
time 2.598- total energy: -28.02121537941361 +- 0.00012117337579961103
time 2.6- total energy: -28.02052287661362 +- 0.00012112621013859329
time 2.602- total energy: -28.012287380716 +- 0.0001383490570698906
time 2.604- total energy: -28.020259973269113 +- 0.00013599358265217255
time 2.606- total energy: -28.025047363825042 +- 0.00014122632676480588
time 2.608- total energy: -28.023983056789117 +- 0.0001338398856853614
time 2.61- total energy: -28.03494389126774 +- 0.0001381696332386546
time 2.612- total energy: -28.03710073634495 +- 0.00013142549408162282
time 2.614- total energy: -28.040474334524454 +- 0.00014051373998586614
time 2.616- total energy: -28.03597714169433 +- 0.00013517201602001387
time 2.618- total energy: -28.04085277088132 +- 0.0001279021180433246
time 2.62- total energy: -28.03821387965943 +- 0.00012952081965402566
time 2.622- total energy: -28.041972237377713 +- 0.00013042039853659884
time 2.624- total energy: -28.030774917029188 +- 0.000135155152349001
time 2.626- total energy: -28.02932566328249 +- 0.0001466823454438046
time 2.628- total energy: -28.021568425909713 +- 0.00016016551128781917
time 2.63- total energy: -28.023174923277942 +- 0.0001601502425926369
time 2.632- total energy: -28.03288568383242 +- 0.00012979297929622576
time 2.634- total energy: -28.026188771569675 +- 0.00013226385062812802
time 2.636- total energy: -28.02688471874851 +- 0.00012429532859259466
time 2.638- total energy: -28.027095122770753 +- 0.00012416611887932136
time 2.64- total energy: -28.026344125170766 +- 0.0001370042879692122
time 2.642- total energy: -28.02198898669361 +- 0.00013587328493982893
time 2.644- total energy: -28.016437734339526 +- 0.00013634959842918917
time 2.646- total energy: -28.02966864057056 +- 0.00012250187337516712
time 2.648- total energy: -28.02948454181859 +- 0.00012628980140200853
time 2.65- total energy: -28.020692041485358 +- 0.0001343031605734346
time 2.652- total energy: -28.01631149213558 +- 0.00016026238099072578
time 2.654- total energy: -28.02086550450383 +- 0.00015887016457248555
time 2.656- total energy: -28.027497709426108 +- 0.00015952295063123657
time 2.658- total energy: -28.026461840728818 +- 0.00015871384405965347
time 2.66- total energy: -28.030983819074915 +- 0.00013877772655989968
time 2.662- total energy: -28.03007446454615 +- 0.0001328206262401928
time 2.664- total energy: -28.03250804609846 +- 0.00014124145935317554
time 2.666- total energy: -28.032606124522133 +- 0.00014104981371782248
time 2.668- total energy: -28.03093360411283 +- 0.0001407519476721844
time 2.67- total energy: -28.025966762978577 +- 0.00013512995207395578
time 2.672- total energy: -28.02699725412789 +- 0.0001338623080625186
time 2.674- total energy: -28.020570854419162 +- 0.00012896714808199696
time 2.676- total energy: -28.019870966451855 +- 0.00012272656877932562
time 2.678- total energy: -28.01566436868802 +- 0.0001207766386763732
time 2.68- total energy: -28.018859644027078 +- 0.0001331539652289345
time 2.682- total energy: -28.01485423976378 +- 0.00013302126291140143
time 2.684- total energy: -28.013884224318407 +- 0.00013326128556827578
time 2.686- total energy: -28.020680434585042 +- 0.00012172912862303192
time 2.688- total energy: -28.017214477287606 +- 0.00012251735848973813
time 2.69- total energy: -28.02571242063866 +- 0.00012576025964351628
time 2.692- total energy: -28.036122450365532 +- 0.0001303429812044117
time 2.694- total energy: -28.034495661800904 +- 0.00013921143326350808
time 2.696- total energy: -28.03446213068495 +- 0.0001428528539769133
time 2.698- total energy: -28.036611702773044 +- 0.00014407121788818025
time 2.7- total energy: -28.026696437396428 +- 0.00014348438247092197
time 2.702- total energy: -28.030039296639416 +- 0.00013926700144958987
time 2.704- total energy: -28.029719907472668 +- 0.00014189858833799776
time 2.706- total energy: -28.018595154391015 +- 0.0002543263136624013
time 2.708- total energy: -28.045171483141566 +- 0.0002707089090939002
time 2.71- total energy: -28.032809421087737 +- 0.00026883969592880156
time 2.712- total energy: -28.031776124022173 +- 0.00025507863702426683
time 2.714- total energy: -28.031899036957615 +- 0.00025383659249306114
time 2.716- total energy: -28.03201386173229 +- 0.00025283592513782933
time 2.718- total energy: -28.026334100231537 +- 0.00025296135566574025
time 2.72- total energy: -28.02370350148056 +- 0.00023888695408558696
time 2.722- total energy: -28.01875404434929 +- 0.00023646162895090333
time 2.724- total energy: -28.02524068824919 +- 0.00023827938875215055
time 2.726- total energy: -28.03543393091038 +- 0.00024376111223655788
time 2.728- total energy: -28.046322427139827 +- 0.00013507549777171877
time 2.73- total energy: -28.04933730790025 +- 0.00013152372677531734
time 2.732- total energy: -28.049633387481535 +- 0.0001314940806604388
time 2.734- total energy: -28.049456347441197 +- 0.00013148163147399354
time 2.736- total energy: -28.05720108472019 +- 0.0001307440474253914
time 2.738- total energy: -28.059330447133842 +- 0.00012878675412181988
time 2.74- total energy: -28.059099600120078 +- 0.0001292644546575479
time 2.742- total energy: -28.044111985924612 +- 0.00012872719107529358
time 2.744- total energy: -28.05119327679819 +- 0.00013395993975505308
time 2.746- total energy: -28.04857946254511 +- 0.0001377043414587593
time 2.748- total energy: -28.047330958207937 +- 0.00013414458837650414
time 2.75- total energy: -28.048821948902724 +- 0.00013167800145042128
time 2.752- total energy: -28.039522000850855 +- 0.00013289849005782125
time 2.754- total energy: -28.038702449717775 +- 0.00012764274319634552
time 2.756- total energy: -28.03672955176602 +- 0.00013363218686367876
time 2.758- total energy: -28.036667095829156 +- 0.0001336458101049793
time 2.76- total energy: -28.033570299713634 +- 0.0001332995726981487
time 2.762- total energy: -28.040455953191145 +- 0.00012194588004880779
time 2.764- total energy: -28.040446794305968 +- 0.00012196818237101904
time 2.766- total energy: -28.062708157469007 +- 0.000128854461008115
time 2.768- total energy: -28.049959480138888 +- 0.00013575356358680002
time 2.77- total energy: -28.04109093261643 +- 0.00014104702710573112
time 2.772- total energy: -28.0379236642429 +- 0.00014568432595701857
time 2.774- total energy: -28.046716560036128 +- 0.00013915571144813827
time 2.776- total energy: -28.040302441087686 +- 0.00014087429235033234
time 2.778- total energy: -28.040597447394134 +- 0.00013741643912552545
time 2.78- total energy: -28.0400857233551 +- 0.00014365777330452325
time 2.782- total energy: -28.01103315103193 +- 0.00013555618982593633
time 2.784- total energy: -28.00265185536899 +- 0.0001408590274882861
time 2.786- total energy: -28.003915949371503 +- 0.00014086053760870986
time 2.788- total energy: -28.004081921872814 +- 0.00013973958380678568
time 2.79- total energy: -28.019940115306444 +- 0.00014502172959884876
time 2.792- total energy: -28.018757326466027 +- 0.00014635284222851353
time 2.794- total energy: -28.01686064165458 +- 0.00014384754190409252
time 2.796- total energy: -28.016696210532615 +- 0.0001440212660611574
time 2.798- total energy: -28.041610512622047 +- 0.00014804705385587985
time 2.8- total energy: -28.056693939583344 +- 0.00015396473135102464
time 2.802- total energy: -28.051322031777975 +- 0.00015749337576366606
time 2.804- total energy: -28.060538459559034 +- 0.00014848732913662135
time 2.806- total energy: -28.047636896903 +- 0.0001503677590408602
time 2.808- total energy: -28.041326835301554 +- 0.00013327982963143807
time 2.81- total energy: -28.050767359214966 +- 0.00012104256639122199
time 2.812- total energy: -28.051486143646766 +- 0.00012553864377875374
time 2.814- total energy: -28.031271548486718 +- 0.00013734308714729115
time 2.816- total energy: -28.026227862106932 +- 0.00013679312621201118
time 2.818- total energy: -28.027461837338446 +- 0.00013367772241151262
time 2.82- total energy: -28.02538147752803 +- 0.00013362216175295618
time 2.822- total energy: -28.026685772681557 +- 0.00014181868695843438
time 2.824- total energy: -28.024470217937754 +- 0.0001446097004645901
time 2.826- total energy: -28.020327826618406 +- 0.0001428537556085862
time 2.828- total energy: -28.023120274432053 +- 0.0001402431751520907
time 2.83- total energy: -28.02211951393079 +- 0.00014085982867802018
time 2.832- total energy: -28.028484867531844 +- 0.00014699146995771133
time 2.834- total energy: -28.03751235259568 +- 0.00014069688954234134
time 2.836- total energy: -28.04411960162943 +- 0.0001414395870183987
time 2.838- total energy: -28.03840893355047 +- 0.00017156568541383416
time 2.84- total energy: -28.044768735930386 +- 0.00017206308060109692
time 2.842- total energy: -28.03573300385071 +- 0.00016926887815841462
time 2.844- total energy: -28.03585265225881 +- 0.00013379049120642656
time 2.846- total energy: -28.04244507129319 +- 0.00013573032257496376
time 2.848- total energy: -28.03620378481982 +- 0.0001346402706044222
time 2.85- total energy: -28.02520370050676 +- 0.00014531197855555616
time 2.852- total energy: -28.020177254957193 +- 0.0001415269256565262
time 2.854- total energy: -28.0117780072221 +- 0.0001453120399692192
time 2.856- total energy: -28.017986313208194 +- 0.00014058799507070613
time 2.858- total energy: -28.02874248882636 +- 0.00015053834942109972
time 2.86- total energy: -28.02387094331842 +- 0.00015961768420778518
time 2.862- total energy: -28.03378270498142 +- 0.00016027442090183792
time 2.864- total energy: -28.029077153072787 +- 0.00016368969302778694
time 2.866- total energy: -28.032060852132123 +- 0.00016158498554893225
time 2.868- total energy: -28.02568919708 +- 0.00016864167698717075
time 2.87- total energy: -28.03232751611115 +- 0.00015322533696614859
time 2.872- total energy: -28.036413508830396 +- 0.00014826536625735037
time 2.874- total energy: -28.028063749079866 +- 0.00015168916574909342
time 2.876- total energy: -28.030796863813613 +- 0.00015464414810472123
time 2.878- total energy: -28.025338987053043 +- 0.00014778673687495167
time 2.88- total energy: -28.016165636973245 +- 0.00014321475145701281
time 2.882- total energy: -28.01361138805001 +- 0.00014476203596304262
time 2.884- total energy: -28.020088468302028 +- 0.00014717263584149742
time 2.886- total energy: -28.027829839321118 +- 0.00013402347600178593
time 2.888- total energy: -28.03123893723 +- 0.0001351313675666059
time 2.89- total energy: -28.025800259170797 +- 0.00012868944747357512
time 2.892- total energy: -28.0312894149962 +- 0.00012845360315154485
time 2.894- total energy: -28.028653392161985 +- 0.0001351445978068865
time 2.896- total energy: -28.020804261847946 +- 0.0001407754730633354
time 2.898- total energy: -28.024642446201426 +- 0.000142396085785342
time 2.9- total energy: -28.024973001407965 +- 0.00014139879227684872
time 2.902- total energy: -28.02988329596329 +- 0.0002503808545717693
time 2.904- total energy: -28.026469421454063 +- 0.00024298899642153293
time 2.906- total energy: -28.029719944955467 +- 0.00023479938359942588
time 2.908- total energy: -28.02648936230295 +- 0.00022957515674074745
time 2.91- total energy: -28.023261580258833 +- 0.0002309796174498628
time 2.912- total energy: -28.022428402741255 +- 0.0002260141223398965
time 2.914- total energy: -28.02021748606789 +- 0.0002271552453112832
time 2.916- total energy: -28.01906468796137 +- 0.00022694326936478995
time 2.918- total energy: -28.029847120936296 +- 0.00013742126928165195
time 2.92- total energy: -28.027393027821038 +- 0.00013618075573051323
time 2.922- total energy: -28.02856505792577 +- 0.0001339863453503617
time 2.924- total energy: -28.022735992186284 +- 0.00014523605920279659
time 2.926- total energy: -28.024891871392075 +- 0.0001418807180938707
time 2.928- total energy: -28.01827407384058 +- 0.00015301986873781214
time 2.93- total energy: -28.016648891318482 +- 0.00015616683040156198
time 2.932- total energy: -28.014744649590725 +- 0.00015607723406384187
time 2.934- total energy: -28.018757399741673 +- 0.00015184816642326514
time 2.936- total energy: -28.021430185054612 +- 0.0001315975816629949
time 2.938- total energy: -28.022756613325154 +- 0.0001328585923132598
time 2.94- total energy: -28.020226981575775 +- 0.00013398626523990412
time 2.942- total energy: -28.018526468986572 +- 0.00014060791713397944
time 2.944- total energy: -28.021590257614672 +- 0.00014778211376156397
time 2.946- total energy: -28.02524643270544 +- 0.00015215691881130945
time 2.948- total energy: -28.026962339821658 +- 0.0001473713902094024
time 2.95- total energy: -28.020524626566118 +- 0.00013681489917477077
time 2.952- total energy: -28.022496752228363 +- 0.00014152571391145937
time 2.954- total energy: -28.02615651306693 +- 0.00015318532365539282
time 2.956- total energy: -28.02044264184292 +- 0.0002753377412382093
time 2.958- total energy: -28.0232779876577 +- 0.00027543031897644466
time 2.96- total energy: -28.04503703547035 +- 0.0001423360234480241
time 2.962- total energy: -28.042359458076533 +- 0.00014561120369045006
time 2.964- total energy: -28.03266934348723 +- 0.00014284795449465243
time 2.966- total energy: -28.029297753171363 +- 0.00014263386428167544
time 2.968- total energy: -28.030114457565894 +- 0.00014977277666961824
time 2.97- total energy: -28.036084312255802 +- 0.00014145218670099353
time 2.972- total energy: -28.027823582003567 +- 0.00014235369515868
time 2.974- total energy: -28.03081313624225 +- 0.00015204823741182726
time 2.976- total energy: -28.027915038666933 +- 0.00014533068445390438
time 2.978- total energy: -28.02413799148001 +- 0.000154191714090856
time 2.98- total energy: -28.02461712831871 +- 0.00013513554493693785
time 2.982- total energy: -28.031477364786124 +- 0.00013818486037471547
time 2.984- total energy: -28.03135687789519 +- 0.00013875398920033775
time 2.986- total energy: -28.02307877658395 +- 0.0001305598768935366
time 2.988- total energy: -28.02297882879205 +- 0.0001306297057059346
time 2.99- total energy: -28.02461906532264 +- 0.00014216171272044117
time 2.992- total energy: -28.030224603058834 +- 0.0001401912965933272
time 2.994- total energy: -28.031525572901266 +- 0.00014898575987611475
time 2.996- total energy: -28.027190258701108 +- 0.00015392441065838983
time 2.998- total energy: -28.03642799840787 +- 0.00014995574554151663
time 3.0- total energy: -28.031056680921093 +- 0.00014114895301250117
time 3.002- total energy: -28.030404882436542 +- 0.0001476948152557061
time 3.004- total energy: -28.038860364626277 +- 0.0001495330839078866
time 3.006- total energy: -28.03183884730999 +- 0.00015845979318063997
time 3.008- total energy: -28.027143124303677 +- 0.00028993398538011776
time 3.01- total energy: -28.015003415316652 +- 0.00030139309712032763
time 3.012- total energy: -28.02119429069486 +- 0.0001385146010965094
time 3.014- total energy: -28.02164224102493 +- 0.0001422779448531749
time 3.016- total energy: -28.027329154476643 +- 0.00014322889195889248
time 3.018- total energy: -28.039689184414353 +- 0.00015353342720284086
time 3.02- total energy: -28.040524571072275 +- 0.00015824085292256656
time 3.022- total energy: -28.049282996173964 +- 0.00019067204222498777
time 3.024- total energy: -28.03583010353864 +- 0.00018218725792832824
time 3.026- total energy: -28.033730693945493 +- 0.00014391897867748724
time 3.028- total energy: -28.037574013689607 +- 0.00014579142972705013
time 3.03- total energy: -28.031978948997843 +- 0.00013639016467922844
time 3.032- total energy: -28.02832135561298 +- 0.00013161001362636002
time 3.034- total energy: -28.03181779936816 +- 0.000141750756445049
time 3.036- total energy: -28.032175729774806 +- 0.00014552476933181628
time 3.038- total energy: -28.037432551857034 +- 0.0001556827871887649
time 3.04- total energy: -28.03455703995175 +- 0.0001536509426522341
time 3.042- total energy: -28.024339002846542 +- 0.00015813158779427896
time 3.044- total energy: -28.018221389640946 +- 0.0001604361868433023
time 3.046- total energy: -28.02937845774042 +- 0.0001537064318851363
time 3.048- total energy: -28.04609168613149 +- 0.00015088543224332305
time 3.05- total energy: -28.044800052572842 +- 0.00015488625873991596
time 3.052- total energy: -28.044808989547384 +- 0.0001548987725643219
time 3.054- total energy: -28.03625127569633 +- 0.000139628020523038
time 3.056- total energy: -28.04047665303137 +- 0.00015011775964494516
time 3.058- total energy: -28.041164295128308 +- 0.00015057329168787701
time 3.06- total energy: -28.043731854453934 +- 0.00014536634983232342
time 3.062- total energy: -28.036234751987244 +- 0.00014933751198688205
time 3.064- total energy: -28.03074960911425 +- 0.0001445961033914333
time 3.066- total energy: -28.036255568078065 +- 0.0001251376229461605
time 3.068- total energy: -28.05101095278014 +- 0.00012048725271766967
time 3.07- total energy: -28.052494543370454 +- 0.0001383843726013377
time 3.072- total energy: -28.053468465663418 +- 0.00013640316186123205
time 3.074- total energy: -28.043627804502293 +- 0.00013728808953334022
time 3.076- total energy: -28.044916768465104 +- 0.00012778870830282036
time 3.078- total energy: -28.037321421422373 +- 0.00014011330433913148
time 3.08- total energy: -28.03567290071471 +- 0.00013908124411768504
time 3.082- total energy: -28.02486453095183 +- 0.0001317137685914177
time 3.084- total energy: -28.01735482880216 +- 0.0001317166446266921
time 3.086- total energy: -28.019567344878592 +- 0.00018694180758044648
time 3.088- total energy: -28.01797267156914 +- 0.0001926527178664588
time 3.09- total energy: -28.016142316358177 +- 0.000193056257868505
time 3.092- total energy: -28.004354623195532 +- 0.00015562362435414716
time 3.094- total energy: -28.00795844387248 +- 0.00015735001720649448
time 3.096- total energy: -28.014184569596523 +- 0.0001606921693423693
time 3.098- total energy: -28.014977220525054 +- 0.00015213599856659028
time 3.1- total energy: -28.00509022587933 +- 0.0001520852150445623
time 3.102- total energy: -28.016185384461043 +- 0.00014456848098638622
time 3.104- total energy: -28.016385993375472 +- 0.00014489975570945875
time 3.106- total energy: -28.016623725528124 +- 0.0001452291558223083
time 3.108- total energy: -28.008981729710605 +- 0.00015348062416362503
time 3.11- total energy: -28.003296681630253 +- 0.0001405943124495236
time 3.112- total energy: -28.00977499917495 +- 0.0001455227989540738
time 3.114- total energy: -28.01590158844413 +- 0.00014807195500272894
time 3.116- total energy: -28.017324222599466 +- 0.00014603631901505
time 3.118- total energy: -28.02368849673171 +- 0.0001479448264667099
time 3.12- total energy: -28.027432664460846 +- 0.00015269567687801718
time 3.122- total energy: -28.03115705421813 +- 0.00014969577534851552
time 3.124- total energy: -28.039434236356325 +- 0.00013799618909383373
time 3.126- total energy: -28.039617078118116 +- 0.00013789591433118327
time 3.128- total energy: -28.03630484006818 +- 0.00013339454472609524
time 3.13- total energy: -28.036970226282033 +- 0.00013366580011668457
time 3.132- total energy: -28.042374017117343 +- 0.00014210221666677482
time 3.134- total energy: -28.04263247673196 +- 0.00014239839707269679
time 3.136- total energy: -28.032303705728324 +- 0.00013463425604029195
time 3.138- total energy: -28.031352831786027 +- 0.00015026595896822572
time 3.14- total energy: -28.02519015603177 +- 0.00020719419633945634
time 3.142- total energy: -28.023996080804 +- 0.00020127361976879856
time 3.144- total energy: -28.023380719854266 +- 0.0001973959912118876
time 3.146- total energy: -28.029874004846917 +- 0.0001368438466302998
time 3.148- total energy: -28.029632944145746 +- 0.00013480429813923068
time 3.15- total energy: -28.027399522661714 +- 0.0001386893387562674
time 3.152- total energy: -28.019021069673936 +- 0.0001402809409112086
time 3.154- total energy: -28.022995798746756 +- 0.00014185057156515372
time 3.156- total energy: -28.031782042798465 +- 0.00014629835795558276
time 3.158- total energy: -28.026163873672626 +- 0.00015077819052859123
time 3.16- total energy: -28.025766239040074 +- 0.00023509060004934666
time 3.162- total energy: -28.033652084626958 +- 0.00023293732611251764
time 3.164- total energy: -28.022937952940346 +- 0.0001402379960388396
time 3.166- total energy: -28.020981403002676 +- 0.00014191542178685696
time 3.168- total energy: -28.028578217049407 +- 0.00014228245980567778
time 3.17- total energy: -28.01359472286767 +- 0.00014343601947492155
time 3.172- total energy: -28.01313541991727 +- 0.00014070935823468566
time 3.174- total energy: -28.022836934040203 +- 0.00015152918312513956
time 3.176- total energy: -28.02726657852377 +- 0.00016037369471248896
time 3.178- total energy: -28.024594372175127 +- 0.0001571833107518245
time 3.18- total energy: -28.026952027542833 +- 0.00015730028481679596
time 3.182- total energy: -28.022844041089094 +- 0.00016464008751054847
time 3.184- total energy: -28.040890715060794 +- 0.00016945693127044055
time 3.186- total energy: -28.003362897173503 +- 0.00015144313230027487
time 3.188- total energy: -28.011734029196308 +- 0.00014407047429078787
time 3.19- total energy: -28.004283328315548 +- 0.00014358143002896837
time 3.192- total energy: -28.024325929876184 +- 0.0001448340730726874
time 3.194- total energy: -28.025979654317233 +- 0.00014719254777389998
time 3.196- total energy: -28.025997144117497 +- 0.00014756765380187294
time 3.198- total energy: -28.02423315850773 +- 0.0001423777722832463
time 3.2- total energy: -28.019167504831543 +- 0.00015147859578370455
time 3.202- total energy: -28.017869299614514 +- 0.00016942531703325342
time 3.204- total energy: -28.02969840779483 +- 0.00017733132992293375
time 3.206- total energy: -28.02653266688449 +- 0.00015670887729447202
time 3.208- total energy: -28.027046971956707 +- 0.0001573306842277327
time 3.21- total energy: -28.020549956722228 +- 0.00015515240967412818
time 3.212- total energy: -28.01872678366318 +- 0.00016685966754542716
time 3.214- total energy: -28.009298452404025 +- 0.0001728883794458831
time 3.216- total energy: -28.012639607637634 +- 0.0001725251795893091
time 3.218- total energy: -28.010479457868005 +- 0.00017543510022819837
time 3.22- total energy: -28.029522081363115 +- 0.00018705137779675838
time 3.222- total energy: -28.032670535650624 +- 0.00018836913208673876
time 3.224- total energy: -28.036514127135035 +- 0.0004402027551714718
time 3.226- total energy: -28.04096484649801 +- 0.00019329934964188168
time 3.228- total energy: -28.0322751926683 +- 0.0001839536529146086
time 3.23- total energy: -28.033641290867365 +- 0.0001840440018801307
time 3.232- total energy: -28.02345238345493 +- 0.00018781815018554995
time 3.234- total energy: -28.021437236162416 +- 0.00016136601782989183
time 3.236- total energy: -28.03165536796368 +- 0.00016705815125245212
time 3.238- total energy: -28.019294782734793 +- 0.00015076440419474116
time 3.24- total energy: -28.00772420045792 +- 0.00015314058630753072
time 3.242- total energy: -28.0148564511641 +- 0.000152282072321673
time 3.244- total energy: -28.03366992143276 +- 0.00015678162829814478
time 3.246- total energy: -28.04694164212445 +- 0.0001645143758164823
time 3.248- total energy: -28.045437036654757 +- 0.00016504902492307046
time 3.25- total energy: -28.029995956349183 +- 0.0001583915545242274
time 3.252- total energy: -28.030744214054334 +- 0.00017617979675157405
time 3.254- total energy: -28.044006106688894 +- 0.00017698025443400861
time 3.256- total energy: -28.037179068876377 +- 0.00017440851007018298
time 3.258- total energy: -28.02618376984358 +- 0.00017056102659100705
time 3.26- total energy: -28.039105488975174 +- 0.0001951522499476288
time 3.262- total energy: -28.020383564328903 +- 0.00018242676534128795
time 3.264- total energy: -28.025862557401002 +- 0.00017591373900875746
time 3.266- total energy: -28.01560612243889 +- 0.000238775950601165
time 3.268- total energy: -28.026566989268655 +- 0.000251106769273901
time 3.27- total energy: -28.017470580440108 +- 0.00017993851123001834
time 3.272- total energy: -28.031114256238066 +- 0.00016381452911220804
time 3.274- total energy: -28.0261791624406 +- 0.00012918061436373743
time 3.276- total energy: -28.022967083419147 +- 0.00012879816495826638
time 3.278- total energy: -28.013063406670106 +- 0.0001484209117824597
time 3.28- total energy: -28.018551208479607 +- 0.00016913418003609954
time 3.282- total energy: -28.019586770744617 +- 0.00017563332062751148
time 3.284- total energy: -28.02942803402309 +- 0.00013812415032804647
time 3.286- total energy: -28.029298259905087 +- 0.00013770645212042457
time 3.288- total energy: -28.037909769745102 +- 0.0001578996965162565
time 3.29- total energy: -28.0379403176111 +- 0.00016041346039235833
time 3.292- total energy: -28.0448791869157 +- 0.00017486116554283723
time 3.294- total energy: -28.03116064897536 +- 0.00015982371501922825
time 3.296- total energy: -28.04105144143755 +- 0.0001636479057640274
time 3.298- total energy: -28.045295382868513 +- 0.00015987835623247808
time 3.3- total energy: -28.045816417473198 +- 0.00016823609429135502
time 3.302- total energy: -28.040183305065053 +- 0.00017770338777239943
time 3.304- total energy: -28.03722838306987 +- 0.0001912406600730202
time 3.306- total energy: -28.036700496803462 +- 0.000204182505926474
time 3.308- total energy: -28.0305761202235 +- 0.00017959349227748847
time 3.31- total energy: -28.02509974217074 +- 0.0002276759044105404
time 3.312- total energy: -28.021371308945948 +- 0.00020416187512244368
time 3.314- total energy: -28.030514074769506 +- 0.00023166702002695364
time 3.316- total energy: -28.019568864001144 +- 0.0002262931628271066
time 3.318- total energy: -28.01768134684227 +- 0.0002078958761618812
time 3.32- total energy: -28.025475627121658 +- 0.00022336388417315998
time 3.322- total energy: -28.03576509257594 +- 0.00021685153646640266
time 3.324- total energy: -28.030318875594407 +- 0.00018856645533721562
time 3.326- total energy: -28.03982742806393 +- 0.00017439896030697476
time 3.328- total energy: -28.03747340092099 +- 0.00017713259415592141
time 3.33- total energy: -28.014792117454192 +- 0.00017816971192805966
time 3.332- total energy: -28.018264800276288 +- 0.00017512900576241352
time 3.334- total energy: -28.022245020279637 +- 0.00015734258503755102
time 3.336- total energy: -28.02910750306733 +- 0.0001719213670261483
time 3.338- total energy: -28.03047285181776 +- 0.00017823552465196202
time 3.34- total energy: -28.027581987881042 +- 0.00019080728942738977
time 3.342- total energy: -28.02381467188125 +- 0.00020808619631034074
time 3.344- total energy: -28.02657863454107 +- 0.00020978718187100045
time 3.346- total energy: -28.029988854723538 +- 0.00019004766019895873
time 3.348- total energy: -28.024133288851093 +- 0.0001810529149193697
time 3.35- total energy: -28.022682820601528 +- 0.00017996640163256468
time 3.352- total energy: -28.034753031520733 +- 0.00018982539172370064
time 3.354- total energy: -28.032880487141085 +- 0.0001873824773988397
time 3.356- total energy: -28.026490811813943 +- 0.00019583757615182504
time 3.358- total energy: -28.02558833670967 +- 0.00016146393462832033
time 3.36- total energy: -28.023728828064545 +- 0.00017788588476370725
time 3.362- total energy: -28.036931430513896 +- 0.00018009158773622284
time 3.364- total energy: -28.04336301632225 +- 0.000152706037934061
time 3.366- total energy: -28.038655497638313 +- 0.00016295632456678433
time 3.368- total energy: -28.04350370494098 +- 0.00015552712396251587
time 3.37- total energy: -28.051068708468332 +- 0.00016575658158310609
time 3.372- total energy: -28.04068796802918 +- 0.00016995070498085701
time 3.374- total energy: -28.036974581551778 +- 0.0001804812141522523
time 3.376- total energy: -28.044898544706623 +- 0.00018889962514805127
time 3.378- total energy: -28.0334718387028 +- 0.00018941481089715525
time 3.38- total energy: -28.03072268223039 +- 0.00018953713599457675
time 3.382- total energy: -28.029255110696372 +- 0.00018532896063040173
time 3.384- total energy: -28.036057695130637 +- 0.00018135842333297225
time 3.386- total energy: -28.035561193449286 +- 0.00016935355446811654
time 3.388- total energy: -28.035483670850475 +- 0.00017423796185744647
time 3.39- total energy: -28.043289290925017 +- 0.00014585260288270738
time 3.392- total energy: -28.03919722316161 +- 0.0001607674441487199
time 3.394- total energy: -28.040148020444253 +- 0.00016325724093477507
time 3.396- total energy: -28.033354253063514 +- 0.0001642642877700293
time 3.398- total energy: -28.02824314464095 +- 0.00015914612934065983
time 3.4- total energy: -28.02605937554827 +- 0.00014886516272404735
time 3.402- total energy: -28.02588423711564 +- 0.00014288188789113158
time 3.404- total energy: -28.0316563771072 +- 0.00014605493596605456
time 3.406- total energy: -28.031858167746822 +- 0.00014572814498088068
time 3.408- total energy: -28.01912025851253 +- 0.00016984393325919497
time 3.41- total energy: -28.019784991510857 +- 0.0001510952710494262
time 3.412- total energy: -28.02414336730675 +- 0.00016589312252890382
time 3.414- total energy: -28.01457201632946 +- 0.00018825521709801398
time 3.416- total energy: -28.024472649306514 +- 0.00016834304096114756
time 3.418- total energy: -28.02010301367378 +- 0.0001678044849796794
time 3.42- total energy: -28.029004005171814 +- 0.00016250307436117156
time 3.422- total energy: -28.0283414963004 +- 0.00017637508388438752
time 3.424- total energy: -28.028151794464637 +- 0.0001788928323430779
time 3.426- total energy: -28.00646525663241 +- 0.00045754272460732674
time 3.428- total energy: -27.999326449622597 +- 0.0004715304559908569
time 3.43- total energy: -27.996352424611402 +- 0.0004879244152701389
time 3.432- total energy: -27.99308675700881 +- 0.0005003078717667077
time 3.434- total energy: -27.996581207951017 +- 0.0005087777857217542
time 3.436- total energy: -28.02773655259011 +- 0.00018223361396060695
time 3.438- total energy: -28.022853695022977 +- 0.0001783216700056847
time 3.44- total energy: -28.0172644743449 +- 0.00016598792802051106
time 3.442- total energy: -28.00065688179495 +- 0.0002113644289045934
time 3.444- total energy: -27.997208544510602 +- 0.0002096479916266818
time 3.446- total energy: -28.004359914307216 +- 0.00022416717261685852
time 3.448- total energy: -28.005454524456 +- 0.00022513440854139913
time 3.45- total energy: -28.02074815241845 +- 0.00021851639475306285
time 3.452- total energy: -28.009404329159377 +- 0.00021320762987860599
time 3.454- total energy: -28.020932658031413 +- 0.0002166356207951846
time 3.456- total energy: -28.022957694418956 +- 0.0002208842298356001
time 3.458- total energy: -28.028275379347175 +- 0.00022622160027316256
time 3.46- total energy: -28.023851004035 +- 0.00022533153686034562
time 3.462- total energy: -28.033740965699202 +- 0.00021703094888214284
time 3.464- total energy: -28.02284562728959 +- 0.00018600230494942942
time 3.466- total energy: -28.02306837785856 +- 0.00018620321788666825
time 3.468- total energy: -28.026936779919115 +- 0.00018844575201805696
time 3.47- total energy: -28.02436523078738 +- 0.00018437677309761626
time 3.472- total energy: -28.022586508872212 +- 0.00017842439908552938
time 3.474- total energy: -28.024942896274364 +- 0.0001888367326631343
time 3.476- total energy: -28.026114596334022 +- 0.00019104698950773335
time 3.478- total energy: -28.017679004849253 +- 0.00023802385121722756
time 3.48- total energy: -28.026103377009694 +- 0.00023924992674179452
time 3.482- total energy: -28.047171634657975 +- 0.00019756182214855723
time 3.484- total energy: -28.054582487810162 +- 0.0002014298196382077
time 3.486- total energy: -28.01935474542959 +- 0.00021713658617662733
time 3.488- total energy: -28.02875278392922 +- 0.00019470220938830497
time 3.49- total energy: -28.02167724270247 +- 0.00019864255130528497
time 3.492- total energy: -28.035982292618026 +- 0.0002097983377371087
time 3.494- total energy: -28.035146078276476 +- 0.00021072912951052307
time 3.496- total energy: -28.047742059234437 +- 0.00020154967678305972
time 3.498- total energy: -28.02709923351214 +- 0.0001881277931998392
time 3.5- total energy: -28.0264475842001 +- 0.0001796530701621613
time 3.502- total energy: -28.01444645131904 +- 0.00018329904726100126
time 3.504- total energy: -28.014805375305986 +- 0.00018342812287591877
time 3.506- total energy: -28.01701649084447 +- 0.0001666140204014672
time 3.508- total energy: -28.017092019361247 +- 0.00016979381645294042
time 3.51- total energy: -28.023719939241175 +- 0.00015357974809688252
time 3.512- total energy: -28.02965583577679 +- 0.00015510363851324672
time 3.514- total energy: -28.034385027835796 +- 0.0001637852698623287
time 3.516- total energy: -28.032483817887552 +- 0.00015554572692361775
time 3.518- total energy: -28.042722336777192 +- 0.0001750999169532611
time 3.52- total energy: -28.036192083268567 +- 0.0001844200115356888
time 3.522- total energy: -28.02346538378116 +- 0.0002599051040582694
time 3.524- total energy: -28.024888053457463 +- 0.00025388252865288555
time 3.526- total energy: -28.049566906859752 +- 0.00019796681955272925
time 3.528- total energy: -28.050281457546717 +- 0.00019818835438091117
time 3.53- total energy: -28.044804412829027 +- 0.00018172551795517998
time 3.532- total energy: -28.043067930900946 +- 0.0001895863895012096
time 3.534- total energy: -28.030106435358995 +- 0.00018510264671905814
time 3.536- total energy: -28.03176051535852 +- 0.00019126294881460434
time 3.538- total energy: -28.023425889161164 +- 0.0002035658358355185
time 3.54- total energy: -28.020367253454445 +- 0.0001928241002111924
time 3.542- total energy: -28.027018861623066 +- 0.00018318142968368016
time 3.544- total energy: -28.013509949138808 +- 0.00020373078941989062
time 3.546- total energy: -28.01675561512866 +- 0.00021408251717207571
time 3.548- total energy: -28.01693949739562 +- 0.00022198432212835556
time 3.55- total energy: -28.013887924574902 +- 0.00019847826527757902
time 3.552- total energy: -28.015331860104816 +- 0.00019639733292939505
time 3.554- total energy: -28.013174539417122 +- 0.0001994117966682077
time 3.556- total energy: -28.0166057376302 +- 0.0001925961720445445
time 3.558- total energy: -28.024487955910185 +- 0.00018077675136201498
time 3.56- total energy: -28.016322394012867 +- 0.00016977754470164143
time 3.562- total energy: -28.007271754528485 +- 0.00019067625477359832
time 3.564- total energy: -28.018670956950004 +- 0.00019312220783475543
time 3.566- total energy: -28.023512091332428 +- 0.00020293429061632467
time 3.568- total energy: -28.03228054414586 +- 0.00021632047701932128
time 3.57- total energy: -28.028520476723635 +- 0.00022893761699377508
time 3.572- total energy: -28.026634057996233 +- 0.0002289927091252882
time 3.574- total energy: -28.03742362473085 +- 0.00020795862043545817
time 3.576- total energy: -28.021553936565017 +- 0.00021410222496020734
time 3.578- total energy: -28.021099261408214 +- 0.00019536867415047578
time 3.58- total energy: -28.016733920129905 +- 0.00019194120736959236
time 3.582- total energy: -28.007945487367664 +- 0.00021408044086230764
time 3.584- total energy: -28.01571265633543 +- 0.00019044441505501803
time 3.586- total energy: -28.016376792895333 +- 0.0002149607010951574
time 3.588- total energy: -28.017850460060018 +- 0.0001982464885792779
time 3.59- total energy: -28.030558917540766 +- 0.00019542281760114027
time 3.592- total energy: -28.02905545058516 +- 0.00021758688944557904
time 3.594- total energy: -28.03122858051338 +- 0.00021227691940572786
time 3.596- total energy: -28.01348761292178 +- 0.0002712680577150083
time 3.598- total energy: -28.026620113091813 +- 0.00021078090973932696
time 3.6- total energy: -28.032226388741027 +- 0.0002198305501081339
time 3.602- total energy: -28.03048271813106 +- 0.00024027256471673226
time 3.604- total energy: -28.040280556371748 +- 0.00023849337709914924
time 3.606- total energy: -28.03558670291477 +- 0.0002504404400853801
time 3.608- total energy: -28.02759093664212 +- 0.0002439648566153428
time 3.61- total energy: -28.020707316521566 +- 0.00024232826908057706
time 3.612- total energy: -28.005013926656368 +- 0.0004431711793958452
time 3.614- total energy: -28.001113351616777 +- 0.00043768473351117295
time 3.616- total energy: -27.99712668199185 +- 0.0004355718602927961
time 3.618- total energy: -28.020727260294652 +- 0.00020675050073183106
time 3.62- total energy: -28.01799197555222 +- 0.00020868373636905932
time 3.622- total energy: -28.021305956547575 +- 0.00020904146241949726
time 3.624- total energy: -28.01439620029297 +- 0.00021847800986028994
time 3.626- total energy: -28.010099100270875 +- 0.0002233361831214862
time 3.628- total energy: -27.987749920313014 +- 0.0004920558452439105
time 3.63- total energy: -28.00971807768669 +- 0.00022598297413735797
time 3.632- total energy: -28.023794417469407 +- 0.00020872626325520847
time 3.634- total energy: -28.00665531309346 +- 0.0004185412468212506
time 3.636- total energy: -28.03419564202061 +- 0.0001968593845032875
time 3.638- total energy: -28.03048038408806 +- 0.0001867454451756704
time 3.64- total energy: -28.021870182643045 +- 0.00020038721789810733
time 3.642- total energy: -28.022827300896168 +- 0.00018735255850245203
time 3.644- total energy: -28.019600547283684 +- 0.00019254423899184447
time 3.646- total energy: -28.017746461311628 +- 0.00019696873578916888
time 3.648- total energy: -27.999797251320263 +- 0.00044584045044309827
time 3.65- total energy: -28.013896906398074 +- 0.0002293514086959731
time 3.652- total energy: -28.024583867622162 +- 0.00021082917914481763
time 3.654- total energy: -28.006919347229214 +- 0.00044364546765901725
time 3.656- total energy: -27.975488057665583 +- 0.0008752799169523154
time 3.658- total energy: -28.025661649441485 +- 0.00019762335396805226
time 3.66- total energy: -28.034660637806052 +- 0.00019245111630626955
time 3.662- total energy: -28.03099674099641 +- 0.00018891582059731636
time 3.664- total energy: -28.02584821730239 +- 0.0001899292244443993
time 3.666- total energy: -27.996313385553574 +- 0.00044309734967556985
time 3.668- total energy: -28.003834664190823 +- 0.00042364057701450473
time 3.67- total energy: -28.00525806053444 +- 0.00040479872482206115
time 3.672- total energy: -28.005665739011985 +- 0.0006504651724857831
time 3.674- total energy: -28.021649203814455 +- 0.0004060043061589267
time 3.676- total energy: -28.028835287231384 +- 0.0001677209702134414
time 3.678- total energy: -28.020329695842463 +- 0.00027957025183633237
time 3.68- total energy: -28.011049815135056 +- 0.0005146777973440753
time 3.682- total energy: -27.99690959805117 +- 0.0004802147107851606
time 3.684- total energy: -27.992636242036518 +- 0.0004973816008005597
time 3.686- total energy: -27.99790469333954 +- 0.0004840455507289476
time 3.688- total energy: -27.982642331962 +- 0.0004909960925462224
time 3.69- total energy: -27.974840464850708 +- 0.000741355721469761
time 3.692- total energy: -28.01146844412342 +- 0.0007085833873820848
time 3.694- total energy: -28.02978091561111 +- 0.00021761365124466428
time 3.696- total energy: -28.03214000925631 +- 0.00022196599189700758
time 3.698- total energy: -28.038519370612626 +- 0.0002302172618601071
time 3.7- total energy: -28.016342182623937 +- 0.0004753317801716882
time 3.702- total energy: -28.024547525720042 +- 0.000485280797098854
time 3.704- total energy: -28.027879866117157 +- 0.0004909253256438315
time 3.706- total energy: -28.024036091310315 +- 0.00046266314654300574
time 3.708- total energy: -28.037963249412872 +- 0.0001919427194022833
time 3.71- total energy: -28.029171845483507 +- 0.00019366173366944947
time 3.712- total energy: -28.033809472053942 +- 0.0001961502446383613
time 3.714- total energy: -28.02602774482199 +- 0.00020382641858571622
time 3.716- total energy: -28.02830978232166 +- 0.0002170057865879659
time 3.718- total energy: -28.029024935508154 +- 0.00022194235435507123
time 3.72- total energy: -28.013345092972603 +- 0.00022364557134160707
time 3.722- total energy: -28.02112508573594 +- 0.0002556113066191338
time 3.724- total energy: -28.017332397576176 +- 0.0002871726853223208
time 3.726- total energy: -28.02532785242496 +- 0.00020120746720306144
time 3.728- total energy: -28.01689169384731 +- 0.00019927990735664226
time 3.73- total energy: -28.031326106924638 +- 0.00018126813100246853
time 3.732- total energy: -28.036531479700567 +- 0.00018205720619194653
time 3.734- total energy: -28.037067869814983 +- 0.0002161252225231661
time 3.736- total energy: -28.02146446648236 +- 0.00020099824469176227
time 3.738- total energy: -28.022288933366312 +- 0.00021163104280695538
time 3.74- total energy: -28.016802138694143 +- 0.0002165951641988168
time 3.742- total energy: -28.02385676302654 +- 0.0002658183111502701
time 3.744- total energy: -28.013621544463614 +- 0.00024794538909767743
time 3.746- total energy: -28.012827178841494 +- 0.00025116303069428787
time 3.748- total energy: -28.022396972606614 +- 0.0002279268852410595
time 3.75- total energy: -28.023023266670204 +- 0.00020182482714373181
time 3.752- total energy: -28.04056885188759 +- 0.0002758104622206765
time 3.754- total energy: -28.030270785416704 +- 0.0002515277971112942
time 3.756- total energy: -28.016226513365634 +- 0.00023178714662711362
time 3.758- total energy: -28.012765594046765 +- 0.0002194245498608594
time 3.76- total energy: -28.011889632608604 +- 0.00021077576902165635
time 3.762- total energy: -28.018803242563802 +- 0.00021438419637237092
time 3.764- total energy: -28.02280955761444 +- 0.00022104105021290775
time 3.766- total energy: -28.02433620017332 +- 0.00020383527945705686
time 3.768- total energy: -28.01652940345939 +- 0.00023516056814318613
time 3.77- total energy: -28.02577938624213 +- 0.00021790594935255792
time 3.772- total energy: -28.0125180757302 +- 0.0002023102950407735
time 3.774- total energy: -28.02332629464599 +- 0.0002365525553733534
time 3.776- total energy: -28.00877782922624 +- 0.00024295921668035481
time 3.778- total energy: -28.006341068302902 +- 0.00024301419173965914
time 3.78- total energy: -28.002340859779153 +- 0.00021363670185900902
time 3.782- total energy: -27.99699953376916 +- 0.00022482475257829858
time 3.784- total energy: -28.00370936661814 +- 0.00023003005222897412
time 3.786- total energy: -28.014852156459533 +- 0.00022410552961912243
time 3.788- total energy: -28.01013845561627 +- 0.000216425272577841
time 3.79- total energy: -28.00683500471631 +- 0.00021445017745305625
time 3.792- total energy: -28.002987265258188 +- 0.00021308336702800364
time 3.794- total energy: -28.006396140824684 +- 0.0002239570605295063
time 3.796- total energy: -28.01468346256093 +- 0.0002490099244554175
time 3.798- total energy: -28.01039208434487 +- 0.00022337202928903875
time 3.8- total energy: -28.017362785109892 +- 0.0002278642858823817
time 3.802- total energy: -28.01332646595923 +- 0.0002318944358235326
time 3.804- total energy: -28.023153443786303 +- 0.00022029097572164903
time 3.806- total energy: -28.01339161280807 +- 0.000234081671147295
time 3.808- total energy: -28.010613096322142 +- 0.00021015124812826539
time 3.81- total energy: -28.03505532066321 +- 0.00021526375785157822
time 3.812- total energy: -28.037208981711093 +- 0.00021646759802680698
time 3.814- total energy: -28.030193010267883 +- 0.0002398350526977573
time 3.816- total energy: -28.022031315001634 +- 0.0002205013759316144
time 3.818- total energy: -28.024299703342553 +- 0.00021617464688584477
time 3.82- total energy: -28.028336659373572 +- 0.0002435210448594625
time 3.822- total energy: -28.03867404265518 +- 0.00027947701792843985
time 3.824- total energy: -28.034788170769044 +- 0.0002513765469471873
time 3.826- total energy: -28.029994882786667 +- 0.00021723185792847286
time 3.828- total energy: -28.02669358962903 +- 0.00023118425228902295
time 3.83- total energy: -28.028770429579303 +- 0.00023531749025651382
time 3.832- total energy: -28.019052902248205 +- 0.00023068793563138173
time 3.834- total energy: -28.023919584315827 +- 0.000274788352364801
time 3.836- total energy: -28.034809987912936 +- 0.0002536625713438989
time 3.838- total energy: -28.035377577367463 +- 0.00025295700399462993
time 3.84- total energy: -28.039323859017625 +- 0.0002494935205621709
time 3.842- total energy: -28.040312525784586 +- 0.00027891566611303823
time 3.844- total energy: -28.026202671140393 +- 0.0002752397007425756
time 3.846- total energy: -28.026436784460707 +- 0.00021125519985948552
time 3.848- total energy: -28.021434855769392 +- 0.00020863843220164782
time 3.85- total energy: -28.0225131827879 +- 0.0004096645709554422
time 3.852- total energy: -28.02870471556351 +- 0.0003545018685558279
time 3.854- total energy: -28.01713700310319 +- 0.00040642339576390477
time 3.856- total energy: -28.04466506881766 +- 0.00029030751025799185
time 3.858- total energy: -28.026766332433215 +- 0.00029933740904458433
time 3.86- total energy: -28.00945971099282 +- 0.0002476728475181178
time 3.862- total energy: -28.01921382168663 +- 0.00029437359161727753
time 3.864- total energy: -28.00289033872212 +- 0.00023038583140785556
time 3.866- total energy: -28.028897157156695 +- 0.0002768880790503045
time 3.868- total energy: -28.030914410536433 +- 0.00029087832651871176
time 3.87- total energy: -28.035531704744702 +- 0.000305080592928414
time 3.872- total energy: -28.042489784860102 +- 0.0003049962360115656
time 3.874- total energy: -28.050310368726496 +- 0.0003071602114553796
time 3.876- total energy: -28.041867448779804 +- 0.00030281014632589355
time 3.878- total energy: -28.02709163802931 +- 0.0003636538529788504
time 3.88- total energy: -28.03301130632344 +- 0.00034981277797575355
time 3.882- total energy: -28.020687173542125 +- 0.00034582691643165537
time 3.884- total energy: -28.00960714197455 +- 0.00034736884811631684
time 3.886- total energy: -28.006402674720963 +- 0.0003516736157987341
time 3.888- total energy: -28.00336766464086 +- 0.0003622890078610896
time 3.89- total energy: -28.00065242709687 +- 0.0003588229116503119
time 3.892- total energy: -27.998604118912308 +- 0.0003531322868964093
time 3.894- total energy: -28.003732876845376 +- 0.0003396750965759971
time 3.896- total energy: -28.01736792314246 +- 0.00033893753683440466
time 3.898- total energy: -28.004148602079635 +- 0.0003392300870004735
time 3.9- total energy: -28.040680279885123 +- 0.00022978496952052758
time 3.902- total energy: -28.045166039858316 +- 0.0002008042978399916
time 3.904- total energy: -28.019813917726935 +- 0.0002108268792573116
time 3.906- total energy: -28.03664335590447 +- 0.00021377507375164512
time 3.908- total energy: -28.0451870991747 +- 0.0002258159047745156
time 3.91- total energy: -28.026279954445986 +- 0.0002101534205438285
time 3.912- total energy: -28.02488647380766 +- 0.00022019348541402466
time 3.914- total energy: -28.029445784376467 +- 0.00022077620509490062
time 3.916- total energy: -28.007855689336605 +- 0.00039031784649386296
time 3.918- total energy: -28.010824627447466 +- 0.0003058255644574624
time 3.92- total energy: -28.008077143963583 +- 0.0002495763377102564
time 3.922- total energy: -28.022616975424647 +- 0.00022564346019531632
time 3.924- total energy: -28.019788663266905 +- 0.0002147972357593381
time 3.926- total energy: -28.02042557590934 +- 0.0002147564491284126
time 3.928- total energy: -28.03224509133099 +- 0.000277498435106079
time 3.93- total energy: -28.023559524377024 +- 0.0002773028098936877
time 3.932- total energy: -28.015470353061833 +- 0.0003292460855770534
time 3.934- total energy: -28.008066082999438 +- 0.00031444396675088987
time 3.936- total energy: -28.01771823394471 +- 0.0002925466790876625
time 3.938- total energy: -28.019282897440927 +- 0.0002951805687984328
time 3.94- total energy: -28.030364658601673 +- 0.0002723346680885051
time 3.942- total energy: -28.0276060797755 +- 0.00026732957305638746
time 3.944- total energy: -28.01854034985648 +- 0.00034918672621945526
time 3.946- total energy: -28.014770098021668 +- 0.0003422658441014322
time 3.948- total energy: -28.01903652039706 +- 0.0003349700381033717
time 3.95- total energy: -27.99668102266363 +- 0.00039536441100270473
time 3.952- total energy: -28.006472305666797 +- 0.0002739714672816425
time 3.954- total energy: -28.0102746415322 +- 0.00027638318160226805
time 3.956- total energy: -28.019699276660155 +- 0.0002803479380634641
time 3.958- total energy: -28.015552552539038 +- 0.00027881954202262944
time 3.96- total energy: -28.03061950332464 +- 0.00032251576087182274
time 3.962- total energy: -28.028492797699425 +- 0.000327331036185595
time 3.964- total energy: -28.022690933156785 +- 0.000315232047243167
time 3.966- total energy: -28.027250810709972 +- 0.0003484653762132523
time 3.968- total energy: -28.02411130862023 +- 0.0003838454613395775
time 3.97- total energy: -28.026295151527883 +- 0.00032738266274258995
time 3.972- total energy: -28.016935988190355 +- 0.00030014075158874427
time 3.974- total energy: -28.019240879772536 +- 0.00032940344046383617
time 3.976- total energy: -28.019372385364985 +- 0.00037001980817953607
time 3.978- total energy: -28.029040497488488 +- 0.00027771121934526183
time 3.98- total energy: -28.018971037344333 +- 0.00032975689098949595
time 3.982- total energy: -28.037148745778143 +- 0.00032846727449029755
time 3.984- total energy: -28.01726688640151 +- 0.00037818506572307093
time 3.986- total energy: -28.007488548857044 +- 0.00034467234966549477
time 3.988- total energy: -28.00437002020694 +- 0.0003838502611206468
time 3.99- total energy: -28.011878147919035 +- 0.0003573753099759243
time 3.992- total energy: -28.011559493494254 +- 0.00036032882450645566
time 3.994- total energy: -28.007811273611104 +- 0.000395067141490122
time 3.996- total energy: -28.00030735858598 +- 0.0004296194711432698
time 3.998- total energy: -28.00196061410168 +- 0.00038402789626624086
time 4.0- total energy: -28.030602408391314 +- 0.00026754445399438114
587.548448 seconds (73.92 M allocations: 13.797 GiB, 0.37% gc time, 0.13% compilation time)
The dynamic simulation looks fine! To check this, we can compute the spin-spin correlation functions. First of all, we need to upload the time-dependent parameters obtained during the previous run. Then, we launch the function Spincorr_DYN() for $i=1$, $j=2$ and we use 50000 Monte Carlo samples.
```julia
W_RBM_t = readdlm("W_RBM_t_12_4_real.jl") + im*readdlm("W_RBM_t_12_4_imag.jl")
```
2002×52 Matrix{ComplexF64}:
6.82924e-5+0.00150202im … 0.0625271-0.358968im
0.000125297+0.00152667im 0.0625122-0.35883im
0.000183471+0.00154867im 0.0624984-0.358693im
0.000241601+0.00156786im 0.0624896-0.358568im
0.000301586+0.00158444im 0.0624782-0.358434im
0.000361432+0.00159823im … 0.0624709-0.35831im
0.000419166+0.00161242im 0.062459-0.358184im
0.000480984+0.00162075im 0.0624504-0.358055im
0.00054305+0.00162622im 0.0624429-0.357927im
0.0006025+0.00163197im 0.0624311-0.357799im
0.000664648+0.0016319im … 0.0624255-0.357677im
0.000727013+0.00162887im 0.0624194-0.357552im
0.000788614+0.00162315im 0.0624154-0.357434im
⋮ ⋱
-0.000471763+0.00523758im … -0.0485144-0.446356im
-0.000355153+0.00511443im -0.0495857-0.445523im
-0.000251872+0.00503134im -0.0507383-0.444921im
-0.000165851+0.0050446im -0.0520788-0.444577im
-7.14917e-5+0.00505292im -0.0534601-0.444258im
3.08079e-5+0.00499196im … -0.0547876-0.443979im
0.000112533+0.00491312im -0.0560102-0.443828im
0.000143295+0.00488195im -0.0570701-0.443831im
0.000202843+0.00487366im -0.0581427-0.443883im
0.000310479+0.00486542im -0.0593187-0.443966im
0.000435231+0.0048647im … -0.0603591-0.443919im
0.000568543+0.00489329im -0.0611621-0.443752im
```julia
spinCorr = Spincorr_DYN(W_RBM_t,50000,1,2)
```
2002-element Vector{Float64}:
-1.4660865798135296
-1.486972472841151
-1.4933548203798506
-1.4933544710535935
-1.4916862492652896
-1.4834924893485872
-1.4831951955748606
-1.4807223068273077
-1.4852224393510707
-1.4893519351374938
-1.4893523003408735
-1.4822742219199838
-1.4827659594802356
⋮
-1.4206550006437926
-1.4379890549339234
-1.4350071024021123
-1.4376086559451948
-1.4110439791505431
-1.4250792019486702
-1.4293711246427945
-1.436604044894268
-1.4356674533242764
-1.4216821407013331
-1.4105172601901497
-1.4281029236954652
```julia
using Plots
plot(collect(0:stepSizeHeun:totTime+stepSizeHeun),spinCorr)
```
A bit noisy! To make it cleaner try to increase the sample size...
|
[GOAL]
α : Type u
ι : Type v
inst✝¹ : MetricSpace α
inst✝ : ProperSpace α
c : ι → α
x : α
r✝ : ℝ
s : Set α
r : ι → ℝ
hs : IsClosed s
uf : ∀ (x : α), x ∈ s → Set.Finite {i | x ∈ ball (c i) (r i)}
us : s ⊆ ⋃ (i : ι), ball (c i) (r i)
⊢ ∃ r', s ⊆ ⋃ (i : ι), ball (c i) (r' i) ∧ ∀ (i : ι), r' i < r i
[PROOFSTEP]
rcases exists_subset_iUnion_closed_subset hs (fun i => @isOpen_ball _ _ (c i) (r i)) uf us with ⟨v, hsv, hvc, hcv⟩
[GOAL]
case intro.intro.intro
α : Type u
ι : Type v
inst✝¹ : MetricSpace α
inst✝ : ProperSpace α
c : ι → α
x : α
r✝ : ℝ
s : Set α
r : ι → ℝ
hs : IsClosed s
uf : ∀ (x : α), x ∈ s → Set.Finite {i | x ∈ ball (c i) (r i)}
us : s ⊆ ⋃ (i : ι), ball (c i) (r i)
v : ι → Set α
hsv : s ⊆ iUnion v
hvc : ∀ (i : ι), IsClosed (v i)
hcv : ∀ (i : ι), v i ⊆ ball (c i) (r i)
⊢ ∃ r', s ⊆ ⋃ (i : ι), ball (c i) (r' i) ∧ ∀ (i : ι), r' i < r i
[PROOFSTEP]
have := fun i => exists_lt_subset_ball (hvc i) (hcv i)
[GOAL]
case intro.intro.intro
α : Type u
ι : Type v
inst✝¹ : MetricSpace α
inst✝ : ProperSpace α
c : ι → α
x : α
r✝ : ℝ
s : Set α
r : ι → ℝ
hs : IsClosed s
uf : ∀ (x : α), x ∈ s → Set.Finite {i | x ∈ ball (c i) (r i)}
us : s ⊆ ⋃ (i : ι), ball (c i) (r i)
v : ι → Set α
hsv : s ⊆ iUnion v
hvc : ∀ (i : ι), IsClosed (v i)
hcv : ∀ (i : ι), v i ⊆ ball (c i) (r i)
this : ∀ (i : ι), ∃ r', r' < r i ∧ v i ⊆ ball (c i) r'
⊢ ∃ r', s ⊆ ⋃ (i : ι), ball (c i) (r' i) ∧ ∀ (i : ι), r' i < r i
[PROOFSTEP]
choose r' hlt hsub using this
[GOAL]
case intro.intro.intro
α : Type u
ι : Type v
inst✝¹ : MetricSpace α
inst✝ : ProperSpace α
c : ι → α
x : α
r✝ : ℝ
s : Set α
r : ι → ℝ
hs : IsClosed s
uf : ∀ (x : α), x ∈ s → Set.Finite {i | x ∈ ball (c i) (r i)}
us : s ⊆ ⋃ (i : ι), ball (c i) (r i)
v : ι → Set α
hsv : s ⊆ iUnion v
hvc : ∀ (i : ι), IsClosed (v i)
hcv : ∀ (i : ι), v i ⊆ ball (c i) (r i)
r' : ι → ℝ
hlt : ∀ (i : ι), r' i < r i
hsub : ∀ (i : ι), v i ⊆ ball (c i) (r' i)
⊢ ∃ r', s ⊆ ⋃ (i : ι), ball (c i) (r' i) ∧ ∀ (i : ι), r' i < r i
[PROOFSTEP]
exact ⟨r', hsv.trans <| iUnion_mono <| hsub, hlt⟩
[GOAL]
α : Type u
ι : Type v
inst✝¹ : MetricSpace α
inst✝ : ProperSpace α
c : ι → α
x : α
r✝ : ℝ
s : Set α
r : ι → ℝ
hr : ∀ (i : ι), 0 < r i
hs : IsClosed s
uf : ∀ (x : α), x ∈ s → Set.Finite {i | x ∈ ball (c i) (r i)}
us : s ⊆ ⋃ (i : ι), ball (c i) (r i)
⊢ ∃ r', s ⊆ ⋃ (i : ι), ball (c i) (r' i) ∧ ∀ (i : ι), r' i ∈ Ioo 0 (r i)
[PROOFSTEP]
rcases exists_subset_iUnion_closed_subset hs (fun i => @isOpen_ball _ _ (c i) (r i)) uf us with ⟨v, hsv, hvc, hcv⟩
[GOAL]
case intro.intro.intro
α : Type u
ι : Type v
inst✝¹ : MetricSpace α
inst✝ : ProperSpace α
c : ι → α
x : α
r✝ : ℝ
s : Set α
r : ι → ℝ
hr : ∀ (i : ι), 0 < r i
hs : IsClosed s
uf : ∀ (x : α), x ∈ s → Set.Finite {i | x ∈ ball (c i) (r i)}
us : s ⊆ ⋃ (i : ι), ball (c i) (r i)
v : ι → Set α
hsv : s ⊆ iUnion v
hvc : ∀ (i : ι), IsClosed (v i)
hcv : ∀ (i : ι), v i ⊆ ball (c i) (r i)
⊢ ∃ r', s ⊆ ⋃ (i : ι), ball (c i) (r' i) ∧ ∀ (i : ι), r' i ∈ Ioo 0 (r i)
[PROOFSTEP]
have := fun i => exists_pos_lt_subset_ball (hr i) (hvc i) (hcv i)
[GOAL]
case intro.intro.intro
α : Type u
ι : Type v
inst✝¹ : MetricSpace α
inst✝ : ProperSpace α
c : ι → α
x : α
r✝ : ℝ
s : Set α
r : ι → ℝ
hr : ∀ (i : ι), 0 < r i
hs : IsClosed s
uf : ∀ (x : α), x ∈ s → Set.Finite {i | x ∈ ball (c i) (r i)}
us : s ⊆ ⋃ (i : ι), ball (c i) (r i)
v : ι → Set α
hsv : s ⊆ iUnion v
hvc : ∀ (i : ι), IsClosed (v i)
hcv : ∀ (i : ι), v i ⊆ ball (c i) (r i)
this : ∀ (i : ι), ∃ r', r' ∈ Ioo 0 (r i) ∧ v i ⊆ ball (c i) r'
⊢ ∃ r', s ⊆ ⋃ (i : ι), ball (c i) (r' i) ∧ ∀ (i : ι), r' i ∈ Ioo 0 (r i)
[PROOFSTEP]
choose r' hlt hsub using this
[GOAL]
case intro.intro.intro
α : Type u
ι : Type v
inst✝¹ : MetricSpace α
inst✝ : ProperSpace α
c : ι → α
x : α
r✝ : ℝ
s : Set α
r : ι → ℝ
hr : ∀ (i : ι), 0 < r i
hs : IsClosed s
uf : ∀ (x : α), x ∈ s → Set.Finite {i | x ∈ ball (c i) (r i)}
us : s ⊆ ⋃ (i : ι), ball (c i) (r i)
v : ι → Set α
hsv : s ⊆ iUnion v
hvc : ∀ (i : ι), IsClosed (v i)
hcv : ∀ (i : ι), v i ⊆ ball (c i) (r i)
r' : ι → ℝ
hlt : ∀ (i : ι), r' i ∈ Ioo 0 (r i)
hsub : ∀ (i : ι), v i ⊆ ball (c i) (r' i)
⊢ ∃ r', s ⊆ ⋃ (i : ι), ball (c i) (r' i) ∧ ∀ (i : ι), r' i ∈ Ioo 0 (r i)
[PROOFSTEP]
exact ⟨r', hsv.trans <| iUnion_mono hsub, hlt⟩
[GOAL]
α : Type u
ι : Type v
inst✝¹ : MetricSpace α
inst✝ : ProperSpace α
c : ι → α
x : α
r : ℝ
s : Set α
hs : IsClosed s
R : α → ℝ
hR : ∀ (x : α), x ∈ s → 0 < R x
⊢ ∃ ι c r r',
(∀ (i : ι), c i ∈ s ∧ 0 < r i ∧ r i < r' i ∧ r' i < R (c i)) ∧
(LocallyFinite fun i => ball (c i) (r' i)) ∧ s ⊆ ⋃ (i : ι), ball (c i) (r i)
[PROOFSTEP]
have : ∀ x ∈ s, (𝓝 x).HasBasis (fun r : ℝ => 0 < r ∧ r < R x) fun r => ball x r := fun x hx =>
nhds_basis_uniformity (uniformity_basis_dist_lt (hR x hx))
[GOAL]
α : Type u
ι : Type v
inst✝¹ : MetricSpace α
inst✝ : ProperSpace α
c : ι → α
x : α
r : ℝ
s : Set α
hs : IsClosed s
R : α → ℝ
hR : ∀ (x : α), x ∈ s → 0 < R x
this : ∀ (x : α), x ∈ s → Filter.HasBasis (𝓝 x) (fun r => 0 < r ∧ r < R x) fun r => ball x r
⊢ ∃ ι c r r',
(∀ (i : ι), c i ∈ s ∧ 0 < r i ∧ r i < r' i ∧ r' i < R (c i)) ∧
(LocallyFinite fun i => ball (c i) (r' i)) ∧ s ⊆ ⋃ (i : ι), ball (c i) (r i)
[PROOFSTEP]
rcases refinement_of_locallyCompact_sigmaCompact_of_nhds_basis_set hs this with ⟨ι, c, r', hr', hsub', hfin⟩
[GOAL]
case intro.intro.intro.intro.intro
α : Type u
ι✝ : Type v
inst✝¹ : MetricSpace α
inst✝ : ProperSpace α
c✝ : ι✝ → α
x : α
r : ℝ
s : Set α
hs : IsClosed s
R : α → ℝ
hR : ∀ (x : α), x ∈ s → 0 < R x
this : ∀ (x : α), x ∈ s → Filter.HasBasis (𝓝 x) (fun r => 0 < r ∧ r < R x) fun r => ball x r
ι : Type u
c : ι → α
r' : ι → ℝ
hr' : ∀ (a : ι), c a ∈ s ∧ 0 < r' a ∧ r' a < R (c a)
hsub' : s ⊆ ⋃ (a : ι), ball (c a) (r' a)
hfin : LocallyFinite fun a => ball (c a) (r' a)
⊢ ∃ ι c r r',
(∀ (i : ι), c i ∈ s ∧ 0 < r i ∧ r i < r' i ∧ r' i < R (c i)) ∧
(LocallyFinite fun i => ball (c i) (r' i)) ∧ s ⊆ ⋃ (i : ι), ball (c i) (r i)
[PROOFSTEP]
rcases exists_subset_iUnion_ball_radius_pos_lt (fun i => (hr' i).2.1) hs (fun x _ => hfin.point_finite x) hsub' with
⟨r, hsub, hlt⟩
[GOAL]
case intro.intro.intro.intro.intro.intro.intro
α : Type u
ι✝ : Type v
inst✝¹ : MetricSpace α
inst✝ : ProperSpace α
c✝ : ι✝ → α
x : α
r✝ : ℝ
s : Set α
hs : IsClosed s
R : α → ℝ
hR : ∀ (x : α), x ∈ s → 0 < R x
this : ∀ (x : α), x ∈ s → Filter.HasBasis (𝓝 x) (fun r => 0 < r ∧ r < R x) fun r => ball x r
ι : Type u
c : ι → α
r' : ι → ℝ
hr' : ∀ (a : ι), c a ∈ s ∧ 0 < r' a ∧ r' a < R (c a)
hsub' : s ⊆ ⋃ (a : ι), ball (c a) (r' a)
hfin : LocallyFinite fun a => ball (c a) (r' a)
r : ι → ℝ
hsub : s ⊆ ⋃ (i : ι), ball (c i) (r i)
hlt : ∀ (i : ι), r i ∈ Ioo 0 (r' i)
⊢ ∃ ι c r r',
(∀ (i : ι), c i ∈ s ∧ 0 < r i ∧ r i < r' i ∧ r' i < R (c i)) ∧
(LocallyFinite fun i => ball (c i) (r' i)) ∧ s ⊆ ⋃ (i : ι), ball (c i) (r i)
[PROOFSTEP]
exact ⟨ι, c, r, r', fun i => ⟨(hr' i).1, (hlt i).1, (hlt i).2, (hr' i).2.2⟩, hfin, hsub⟩
|
\chapter{Introduction}
\label{chapter:introduction}
In this chapter, we introduce this thesis by presenting its motivation,
describing our research questions and providing an overview of the thesis
structure.
\section{Motivation and objective}
There is a recent trend of increasingly complex deep learning models achieving
state-of-the-art performance on \ac{ml} and \ac{nlp} tasks, as shown in Figure
\ref{fig:nlp_progress}. To address emerging concerns such as security risks and
inductive biases, several studies argue for focused research into \ac{xai}
\citep{doran2017does,townsend2019extracting,danilevsky2020survey,arrieta2020explainable}.
Of these studies, \citet{arrieta2020explainable} provide an extensive overview
of \ac{xai} and related concepts based on a thorough literature review of
$\sim$400 \ac{xai} research contributions published to date. In particular,
\citet{arrieta2020explainable} explore and classify a variety of \ac{ml} models
into transparent and black-box categories depending on their degrees of
transparency. Furthermore, they explore taxonomies of post-hoc explainability
techniques aimed at effectively explaining black-box models. Notable
explainability techniques used in recent research include local explanations,
feature relevance and explanations by simplification.
Through our own survey of recent literature on explainability techniques in
\ac{nlp}, we came across several interesting studies employing the three
aforementioned post-hoc explainability techniques to better explain deep neural networks
\citep{schwartz2018sopa,peng2018rational,suresh-etal-2019-distilling,wang2019state,jiang2020cold}.
Of these studies, we draw inspiration from \citet{schwartz2018sopa} who
developed the novel hybridized \ac{rnn}, \ac{cnn} and weighted finite-state
\ac{sopa} model architecture with a special focus in model explainability. While
the \ac{sopa} model functions well, we find its explainability techniques to be
localized and indirect despite its neural architecture being suited for the
globalized and direct explanations by simplification explainability technique.
The main objective of this thesis is to address these limitations and to propose
a modified model, \textbf{\ac{spp}}, which could allow for effective explanations
by simplification. To facilitate this objective, we study both the performance and
explanations by simplification of the modified \ac{spp} model on the recently
released \ac{fmtod} data set from \citet{schuster-etal-2019-cross-lingual};
focusing on the English-language intent classification task.
\begin{figure}[t!]
\centering
\includegraphics[width=13cm]{pdfs/borrowed/nlp_sota_model_size_progress.pdf}
\caption{Parameter counts of recently released pre-trained language models
which showed competitive or state-of-the-art performance when fine-tuned
over a range of NLP tasks; figure taken from \citet{sanh2019distilbert}}
\label{fig:nlp_progress}
\end{figure}
\section{Research questions}
\label{section:rq}
To guide us in addressing our objective, we aim to answer the following three
research questions:
\begin{enumerate}
\item Does \ac{spp} provide competitive\footnote{We define
competitive performance as the scenario where a mean performance metric on a
certain task falls within the range obtained from other recent studies on
the same task} performance on the \ac{fmtod} English language intent classification task?
\item To what extent does \ac{spp} contribute to effective explanations by
simplification on the \ac{fmtod} English language intent classification task?
\item What interesting and relevant explanations can \ac{spp} provide on the
\ac{fmtod} English language intent classification task?
\end{enumerate}
\section{Thesis structure}
We now summarize the contents and structure of this thesis.
\begin{description}[align=left]
\item [Chapter \ref{chapter:introduction}:] Introduce this thesis, its
contents and our research questions.
\item [Chapter \ref{chapter:background}:] Describe the background concepts
utilized in this thesis.
\item [Chapter \ref{chapter:methodologies}:] Describe the \ac{fmtod} data set and
methodologies pursued in this thesis.
\item [Chapter \ref{chapter:results}:] Describe the results obtained from our
methodologies.
\item [Chapter \ref{chapter:discussion}:] Interpret the results and discuss their
implications.
\item [Chapter \ref{chapter:conclusions}:] Summarize the findings
of this thesis.
\item [Chapter \ref{chapter:further_work}:] Describe future work to expand on
our research questions.
\end{description}
% LocalWords: explainability pre NLP
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "main"
%%% End:
|
$(a - a')b = ab - a'b$.
|
# where to run?
# setwd("C:/cygwin64/home/landau/working/PreservationSimulation/pictures/COPIES5LONGTERM")
debugprint<-0
source("./GetCopies5LongTermData.r")
cat("summarise() complains about some column, but I don't know which. --RBL\n")
|
theory Live_Variables imports Reaching_Definitions begin
section \<open>Live Variables Analysis\<close>
fun use_action :: "'v action \<Rightarrow> 'v set" where
"use_action (x ::= a) = fv_arith a"
| "use_action (Bool b) = fv_boolean b"
| "use_action Skip = {}"
fun use_edge :: "('n,'v) edge \<Rightarrow> 'v set" where
"use_edge (q1, \<alpha>, q2) = use_action \<alpha>"
definition use_edge_list :: "('n,'v) edge list \<Rightarrow> 'v \<Rightarrow> bool" where
"use_edge_list \<pi> x = (\<exists>\<pi>1 \<pi>2 e. \<pi> = \<pi>1 @ [e] @ \<pi>2 \<and> x \<in> use_edge e \<and> (\<not>(\<exists>e' \<in> set \<pi>1. x \<in> def_edge e')))"
definition use_path :: "'n list \<times> 'v action list \<Rightarrow> 'v set" where
"use_path \<pi> = {x. use_edge_list (LTS.transition_list \<pi>) x}"
locale analysis_LV = finite_program_graph pg
for pg :: "('n::finite,'v::finite) program_graph"
begin
interpretation LTS edge_set .
definition analysis_dom_LV :: "'v set" where
"analysis_dom_LV = UNIV"
fun kill_set_LV :: "('n,'v) edge \<Rightarrow> 'v set" where
"kill_set_LV (q\<^sub>o, x ::= a, q\<^sub>s) = {x}"
| "kill_set_LV (q\<^sub>o, Bool b, q\<^sub>s) = {}"
| "kill_set_LV (v, Skip, vc) = {}"
fun gen_set_LV :: "('n,'v) edge \<Rightarrow> 'v set" where
"gen_set_LV (q\<^sub>o, x ::= a, q\<^sub>s) = fv_arith a"
| "gen_set_LV (q\<^sub>o, Bool b, q\<^sub>s) = fv_boolean b"
| "gen_set_LV (v, Skip, vc) = {}"
definition d_init_LV :: "'v set" where
"d_init_LV = {}"
interpretation bw_may: analysis_BV_backward_may pg analysis_dom_LV kill_set_LV gen_set_LV d_init_LV
using analysis_BV_backward_may.intro analysis_LV_axioms analysis_LV_def analysis_dom_LV_def
finite_UNIV subset_UNIV analysis_BV_backward_may_axioms_def finite_program_graph_def by metis
lemma use_edge_list_S_hat_edge_list:
assumes "use_edge_list \<pi> x"
shows "x \<in> bw_may.S_hat_edge_list \<pi> d_init_LV"
using assms
proof (induction \<pi>)
case Nil
then have False
unfolding use_edge_list_def by auto
then show ?case
by metis
next
case (Cons e \<pi>)
note Cons_inner = Cons
from Cons(2) have "\<exists>\<pi>1 \<pi>2 e'. e # \<pi> = \<pi>1 @ [e'] @ \<pi>2 \<and> x \<in> use_edge e' \<and> \<not> (\<exists>e''\<in>set \<pi>1. x \<in> def_edge e'')"
unfolding use_edge_list_def by auto
then obtain \<pi>1 \<pi>2 e' where \<pi>1_\<pi>2_e'_p:
"e # \<pi> = \<pi>1 @ [e'] @ \<pi>2"
"x \<in> use_edge e'"
"\<not>(\<exists>e''\<in>set \<pi>1. x \<in> def_edge e'')"
by auto
then show ?case
proof (cases \<pi>1)
case Nil
have "e = e'"
using \<pi>1_\<pi>2_e'_p(1) Nil by auto
then have x_used_a: "x \<in> use_edge e"
using \<pi>1_\<pi>2_e'_p(2) by auto
obtain p \<alpha> q where a_split: "e = (p, \<alpha>, q)"
by (cases e)
show ?thesis
using x_used_a bw_may.S_hat_def a_split by (cases \<alpha>) auto
next
case (Cons hd_\<pi>1 tl_\<pi>1)
obtain p \<alpha> q where e_split: "e' = (p, \<alpha>, q)"
by (cases e')
have "(\<pi> = tl_\<pi>1 @ (p, \<alpha>, q) # \<pi>2) \<and> x \<in> use_action \<alpha> \<and> (\<forall>e'\<in>set tl_\<pi>1. x \<notin> def_edge e')"
using Cons \<pi>1_\<pi>2_e'_p e_split by auto
then have "use_edge_list \<pi> x"
unfolding use_edge_list_def by force
then have x_in_S_hat_\<pi>: "x \<in> bw_may.S_hat_edge_list \<pi> d_init_LV"
using Cons_inner by auto
have "e \<in> set \<pi>1"
using \<pi>1_\<pi>2_e'_p(1) Cons(1) by auto
then have x_not_def_a: "\<not>x \<in> def_edge e"
using \<pi>1_\<pi>2_e'_p(3) by auto
obtain p' \<alpha>' q' where a_split: "e = (p', \<alpha>', q')"
by (cases e)
show ?thesis
proof (cases "x \<in> kill_set_LV e")
case True
show ?thesis
using True a_split x_not_def_a by (cases \<alpha>'; force)
next
case False
then show ?thesis
by (simp add: bw_may.S_hat_def x_in_S_hat_\<pi>)
qed
qed
qed
lemma S_hat_edge_list_use_edge_list:
assumes "x \<in> bw_may.S_hat_edge_list \<pi> d_init_LV"
shows "use_edge_list \<pi> x"
using assms
proof (induction \<pi>)
case Nil
then have False
using d_init_LV_def by auto
then show ?case
by metis
next
case (Cons e \<pi>)
from Cons(2) have "x \<in> bw_may.S_hat_edge_list \<pi> d_init_LV - kill_set_LV e \<union> gen_set_LV e"
unfolding bw_may.S_hat_edge_list.simps unfolding bw_may.S_hat_def by auto
then show ?case
proof
assume a: "x \<in> bw_may.S_hat_edge_list \<pi> d_init_LV - kill_set_LV e"
then have "x \<in> bw_may.S_hat_edge_list \<pi> d_init_LV"
by auto
then have "use_edge_list \<pi> x"
using Cons by auto
then have "\<exists>\<pi>1 \<pi>2 e'. \<pi> = \<pi>1 @ [e'] @ \<pi>2 \<and> x \<in> use_edge e' \<and> \<not>(\<exists>e''\<in>set \<pi>1. x \<in> def_edge e'')"
unfolding use_edge_list_def by auto
then obtain \<pi>1 \<pi>2 e' where \<pi>1_\<pi>2_e'_p:
"\<pi> = \<pi>1 @ [e'] @ \<pi>2"
"x \<in> use_edge e'"
"\<not>(\<exists>e''\<in>set \<pi>1. x \<in> def_edge e'')"
by auto
obtain q1 \<alpha> q2 where e_split: "e = (q1, \<alpha>, q2)"
by (cases e) auto
from a have "x \<notin> kill_set_LV e"
by auto
then have x_not_killed: "x \<notin> kill_set_LV (q1, \<alpha>, q2)"
using e_split by auto
have "use_edge_list ((q1, \<alpha>, q2) # \<pi>) x"
proof (cases \<alpha>)
case (Asg y exp)
then have "x \<notin> kill_set_LV (q1, y ::= exp, q2)"
using x_not_killed by auto
then have x_not_y: "x \<noteq> y"
by auto
have "(q1, y ::= exp, q2) # \<pi> = ((q1, y ::= exp, q2) # \<pi>1) @ [e'] @ \<pi>2"
using \<pi>1_\<pi>2_e'_p by force
moreover
have "\<not> (\<exists>e'\<in>set ((q1, y ::= exp, q2) # \<pi>1). x \<in> def_edge e')"
using \<pi>1_\<pi>2_e'_p x_not_y by force
ultimately
have "use_edge_list ((q1, y ::= exp, q2) # \<pi>) x"
unfolding use_edge_list_def using \<pi>1_\<pi>2_e'_p x_not_y by metis
then show ?thesis
by (simp add: Asg)
next
case (Bool b)
have "(q1, Bool b, q2) # \<pi> = ((q1, Bool b, q2) # \<pi>1) @ [e'] @ \<pi>2"
using \<pi>1_\<pi>2_e'_p unfolding use_edge_list_def by auto
moreover
have "\<not> (\<exists>e'\<in>set ((q1, Bool b, q2) # \<pi>1). x \<in> def_edge e')"
using \<pi>1_\<pi>2_e'_p unfolding use_edge_list_def by auto
ultimately
have "use_edge_list ((q1, Bool b, q2) # \<pi>) x"
unfolding use_edge_list_def using \<pi>1_\<pi>2_e'_p by metis
then show ?thesis
using Bool by auto
next
case Skip
have "(q1, Skip, q2) # \<pi> = ((q1, Skip, q2) # \<pi>1) @ [e'] @ \<pi>2"
using \<pi>1_\<pi>2_e'_p unfolding use_edge_list_def by auto
moreover
have "\<not> (\<exists>e'\<in>set ((q1, Skip, q2) # \<pi>1). x \<in> def_edge e')"
using \<pi>1_\<pi>2_e'_p unfolding use_edge_list_def by auto
ultimately
have "use_edge_list ((q1, Skip, q2) # \<pi>) x"
unfolding use_edge_list_def using \<pi>1_\<pi>2_e'_p by metis
then show ?thesis
using Skip by auto
qed
then show "use_edge_list (e # \<pi>) x"
using e_split by auto
next
assume a: "x \<in> gen_set_LV e"
obtain p \<alpha> q where a_split: "e = (p, \<alpha>, q)"
by (cases e)
have "use_edge_list ((p, \<alpha>, q) # \<pi>) x"
using a a_split unfolding use_edge_list_def by (cases \<alpha>; force)
then show "use_edge_list (e # \<pi>) x"
using a_split by auto
qed
qed
lemma use_edge_list_UNIV_S_hat_edge_list: "{x. use_edge_list \<pi> x} = bw_may.S_hat_edge_list \<pi> d_init_LV"
using use_edge_list_S_hat_edge_list S_hat_edge_list_use_edge_list by auto
lemma use_path_S_hat_path: "use_path \<pi> = bw_may.S_hat_path \<pi> d_init_LV"
by (simp add: use_edge_list_UNIV_S_hat_edge_list bw_may.S_hat_path_def use_path_def)
definition summarizes_LV :: "(pred, ('n,'v,'v) cst) pred_val \<Rightarrow> bool" where
"summarizes_LV \<rho> \<longleftrightarrow> (\<forall>\<pi> d. \<pi> \<in> path_with_word_to end \<longrightarrow> d \<in> use_path \<pi> \<longrightarrow>
\<rho> \<Turnstile>\<^sub>l\<^sub>h may\<langle>[Cst\<^sub>N (start_of \<pi>), Cst\<^sub>E d]\<rangle>.)"
theorem LV_sound:
assumes "\<rho> \<Turnstile>\<^sub>l\<^sub>s\<^sub>t bw_may.ana_pg_bw_may s_BV"
shows "summarizes_LV \<rho>"
proof -
from assms have "bw_may.summarizes_bw_may \<rho>"
using bw_may.sound_ana_pg_bw_may[of \<rho>] by auto
then show ?thesis
unfolding summarizes_LV_def bw_may.summarizes_bw_may_def edge_set_def edge_set_def
end_def end_def use_path_S_hat_path by blast
qed
end
end
|
State Before: M✝ : Type ?u.29021
N✝ : Type ?u.29024
G : Type ?u.29027
A : Type ?u.29030
B : Type ?u.29033
α : Type ?u.29036
β : Type ?u.29039
γ : Type ?u.29042
δ : Type ?u.29045
M : Type u_1
N : Type u_2
inst✝¹ : Monoid N
inst✝ : SMul M N
h : ∀ (x : M) (y : N), x • 1 * y = x • y
x : M
y z : N
⊢ (x • y) • z = x • y • z State After: no goals Tactic: rw [← h, smul_eq_mul, mul_assoc, h, smul_eq_mul]
|
module timedisc_const_mod
use constants_mod
real(dp), parameter :: A0 = 1.00000000000000_dp
real(dp), parameter :: A1 = 1.00000000000000_dp
real(dp), parameter :: A2 = 0.00000000000000_dp
real(dp), parameter :: A3 = 0.39175222700392_dp
real(dp), parameter :: B0 = 0.39175222700392_dp
real(dp), parameter :: B1 = 0.44437049406734_dp
real(dp), parameter :: B2 = 0.55562950593266_dp
real(dp), parameter :: B3 = 0.36841059262959_dp
real(dp), parameter :: C0 = 0.58607968896780_dp
real(dp), parameter :: C1 = 0.62010185138540_dp
real(dp), parameter :: C2 = 0.37989814861460_dp
real(dp), parameter :: C3 = 0.25189177424738_dp
real(dp), parameter :: D0 = 0.47454236302687_dp
real(dp), parameter :: D1 = 0.17807995410773_dp
real(dp), parameter :: D2 = 0.82192004589227_dp
real(dp), parameter :: D3 = 0.54497475021237_dp
real(dp), parameter :: E0 = 0.93501063100924_dp
real(dp), parameter :: E1 = 0.00683325884039_dp
real(dp), parameter :: E2 = 0.34833675773694_dp
real(dp), parameter :: E3 = 0.22600748319395_dp
real(dp), parameter :: E4 = 0.51723167208978_dp
real(dp), parameter :: E5 = 0.12759831133288_dp
real(dp), parameter :: E6 = 0.08460416338212_dp
integer, parameter :: nstages = 5
real(dp), parameter :: dt_coeffs(nstages) = (/A0, B0, C0, D0, E0/)
end module
|
/-
Copyright (c) 2023 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author : Jujian Zhang
-/
import tactic
import topology.subset_properties
import ring_theory.int.basic
/-!
# Proof of infinitude of prime numbers using topology
This file contains an interesting proof of infinitude of prime numbers.
Define a topology on `ℤ` by declaring a set `U` is open if and only if
for every `x ∈ U`, there exists an `1 ≤ m` such that `mk + x ∈ U` for all `k`.
Then one can see that every nonempty open set is infinite and every arithmetic
progression `{mk + a | k ∈ ℤ}` is both open and closed where `1 ≤ m`.
Then suppose there are only finitely many prime numbers, then `⋃_p {pk | k ∈ ℤ}`
is a finite union of arithmetic progression thus closed, so its complement is open.
However, the complement of `⋃_p {pk | k ∈ ℤ}` is precisely `{-1, 1}` which cannot
be open because it is nonempty but finite.
-/
open topological_space
def contains_arith_progression (U : set ℤ) : Prop :=
∀ (x : ℤ), x ∈ U → ∃ (m : ℤ), 1 ≤ m ∧ ∀ (k : ℤ), m * k + x ∈ U
lemma univ_contains_arith_progression : contains_arith_progression set.univ :=
sorry
lemma inter_contains_arith_progression (s t : set ℤ)
(hs : contains_arith_progression s) (ht : contains_arith_progression t) :
contains_arith_progression (s ∩ t) := sorry
lemma sUnion_contains_arith_progression (s : set (set ℤ))
(hs : ∀ i ∈ s, contains_arith_progression i) : contains_arith_progression (⋃₀ s) :=
sorry
instance weird_top_on_int : topological_space ℤ :=
{ is_open := contains_arith_progression,
is_open_univ := univ_contains_arith_progression,
is_open_inter := inter_contains_arith_progression,
is_open_sUnion := sUnion_contains_arith_progression }
lemma is_open_iff_weird (s : set ℤ) : is_open s ↔ contains_arith_progression s := iff.rfl
lemma nonempty_open_is_infinite (s : set ℤ) (hs1 : is_open s) (hs2 : s.nonempty) :
s.infinite :=
sorry
def arith_progression (a m : ℤ) := {z : ℤ | ∃ k, m * k + a = z }
lemma arith_progression_open (a m : ℤ) (hm : 1 ≤ m) : is_open (arith_progression a m) :=
sorry
lemma arith_progression_closed (a m : ℤ) (hm : 1 ≤ m) : is_closed (arith_progression a m) :=
sorry
lemma arith_progression_clopen (a m : ℤ) (hm : 1 ≤ m) :
is_clopen (arith_progression a m) :=
sorry
lemma seteq1 : (⋃ (p : ℕ) (hp : nat.prime p), arith_progression 0 p)ᶜ = {1, -1} :=
sorry
lemma not_closed : ¬ is_closed (⋃ (p : ℕ) (hp : nat.prime p), arith_progression 0 p) :=
sorry
lemma not_closed' : ¬ is_closed (⋃ (p : set_of nat.prime), arith_progression 0 (p : ℤ)) :=
sorry
lemma infinite_prime : (set_of nat.prime).infinite :=
sorry
|
import os
from PIL import Image
import numpy as np
import torch.utils.data as data
from utils.datasets.preprocess import get_tuple_transform_ops
from utils.eval.measure import sampson_distance
from utils.eval.geometry import pose2fund
class ImMatchDatasetMega(data.Dataset):
'''Data wrapper for train image-matching with triplets'''
def __init__(self, data_root, match_file, scene_list=None, wt=480, ht=320, item_type='triplet'):
print('\nInitialize ImMatchDatasetMega...')
self.dataset = 'MegaDepth_undistort'
self.data_root = os.path.join(data_root, self.dataset)
self.match_file = match_file
self.transform_ops = get_tuple_transform_ops(resize=(ht, wt), normalize=True)
self.wt, self.ht = wt, ht
self.item_type = item_type
# Initialize data
self.ims = {} # {scene: {im: imsize}}
self.pos_pair_pool = [] # [pair]
self.load_pairs(scene_list)
self.Fs = {}
self.Ks = {}
def load_im(self, im_ref, crop=None):
im = Image.open(im_ref)
if crop:
dw, dh = crop
im = np.array(im)
# Crop from right and buttom to keep the target aspect ratio
h, w, _ = im.shape
im = im[0: h - int(dh), 0: w - int(dw)]
#print(h, w, im.shape)
im = Image.fromarray(im)
return im
def load_pairs(self, scene_list=None):
match_dict = np.load(self.match_file, allow_pickle=True).item()
self.scenes = scene_list if scene_list else match_dict.keys()
print('Loading data from {}'.format(self.match_file))
num_ims = 0
for sc in self.scenes:
self.pos_pair_pool += match_dict[sc]['pairs']
self.ims[sc] = match_dict[sc]['ims']
num_ims += len(match_dict[sc]['ims'])
print('Loaded scenes {} ims: {} pos pairs:{}'.format(len(self.scenes), num_ims, len(self.pos_pair_pool)))
def get_fundmat(self, pair, im1, im2):
def scale_intrinsic(K, wi, hi):
sx, sy = self.wt / wi, self.ht / hi
sK = np.array([[sx, 0, 0],
[0, sy, 0],
[0, 0, 1]])
return sK.dot(K)
pair_key = (pair.im1, pair.im2)
if pair_key not in self.Fs:
# Recompute camera intrinsic matrix due to the resize
K1 = scale_intrinsic(pair.K1, im1.width, im1.height)
K2 = scale_intrinsic(pair.K2, im2.width, im2.height)
# Calculate F
F = pose2fund(K1, K2, pair.R, pair.t)
self.Fs[pair_key] = (F, K1, K2)
# Sanity check
# scale = np.array([[im1.width/self.wt, im1.height/self.ht, im2.width/self.wt, im2.height/self.ht]])
# matches = pair.sanity_matches * scale
# dists = sampson_distance(matches[:, :2], matches[:,2:], F)
# print(np.mean(dists))
return self.Fs[pair_key]
def __getitem__(self, index):
"""
Batch dict:
- 'src_im': anchor image
- 'pos_im': positive image sample to the anchor
- 'neg_im': negative image sample to the anchor
- 'im_pair_refs': path of images (src, pos, neg)
- 'pair_data': namedtuple contains relative pose information between src and pos ims.
"""
data_dict = {}
# Load positive pair data
pair = self.pos_pair_pool[index]
im_src_ref = os.path.join(self.data_root, pair.im1)
im_pos_ref = os.path.join(self.data_root, pair.im2)
im_src = self.load_im(im_src_ref, crop=pair.crop1)
im_pos = self.load_im(im_pos_ref, crop=pair.crop2)
# Select a negative image from other scences
if self.item_type == 'triplet':
other_scenes = list(self.scenes)
other_scenes.remove(pair.im1.split('/')[0])
neg_scene = np.random.choice(other_scenes)
im_neg_data = np.random.choice(self.ims[neg_scene])
im_neg_ref = os.path.join(self.data_root, im_neg_data.name)
im_neg = self.load_im(im_neg_ref, crop=im_neg_data.crop)
im_neg = self.transform_ops([im_neg])[0]
#print(im_neg.shape)
else:
im_neg = None
im_neg_ref = None
# Compute fundamental matrix before RESIZE
F, K1, K2 = self.get_fundmat(pair, im_src, im_pos)
# Process images
im_src, im_pos = self.transform_ops((im_src, im_pos))
#print(im_src.shape, im_pos.shape)
# Wrap data item
data_dict = {'src_im': im_src,
'pos_im': im_pos,
'neg_im': im_neg,
'im_pair_refs': (im_src_ref, im_pos_ref, im_neg_ref),
'F': F,
'K1': K1,
'K2': K2
}
return data_dict
def __len__(self):
return len(self.pos_pair_pool)
def __repr__(self):
fmt_str = 'ImMatchDatasetMega scenes:{} data type:{}\n'.format(len(self.scenes), self.item_type)
fmt_str += 'Number of data pairs: {}\n'.format(self.__len__())
fmt_str += 'Image root location: {}\n'.format(self.data_root)
fmt_str += 'Match file: {}\n'.format(self.match_file)
fmt_str += 'Transforms: {}\n'.format(self.transform_ops.__repr__().replace('\n', '\n '))
return fmt_str
|
! { dg-do compile }
! { dg-options "-fcoarray=single" }
!
use iso_fortran_env
implicit none
type t
integer, pointer :: caf2[:] ! { dg-error "must be allocatable with deferred shape" }
end type t
integer, pointer :: caf[*] ! { dg-error "POINTER attribute conflicts with CODIMENSION attribute" }
type t2
type(lock_type), pointer :: lock_it ! { dg-error "Component lock_it at .1. of type LOCK_TYPE must have a codimension or be a subcomponent of a coarray, which is not possible as the component has the pointer attribute" }
end type t2
type(t2) :: caf3[*]
type t3
type(lock_type) :: x
end type t3
type t4
type(t3), pointer :: y ! { dg-error "Pointer component y at .1. has a noncoarray subcomponent of type LOCK_TYPE, which must have a codimension or be a subcomponent of a coarray" }
end type t4
end
|
If $c < 0$, then $a \leq b/c$ if and only if $b \leq ca$.
|
\documentclass[9pt,twocolumn,twoside]{../../styles/osajnl}
\usepackage{fancyvrb}
\journal{i524}
\title{Apache Flink: Stream and Batch Processing}
\author[1,*]{Jimmy Ardiansyah}
\affil[1]{School of Informatics and Computing, Bloomington, IN 47408, U.S.A.}
\affil[*]{[email protected] - S17-IR-2002}
\dates{Research Article-02, \today}
\ociscodes{Apache Flink, Batch Data Processing, Stream Data Processing}
% replace this with your url in github/gitlab
\doi{\url{https://github.com/jardians/sp17-i524/blob/master/paper2/S17-IR-2002/report.pdf}}
\begin{abstract}
Apache Flink is an open-source system for processing streaming and batch data. Flink is built on the philosophy that many classes of data processing applications, including real-time analytics, continuous data pipelines, historic data processing (batch), and iterative algorithms can be expressed and executed as pipelined fault-tolerant dataflows.
\newline
\newline
\end{abstract}
\setboolean{displaycopyright}{true}
\begin{document}
\maketitle
\section{Introduction}
Data stream and batch data processing were traditionally considered as two very different types of applications. They were programmed using different programming models and APIs, and were executed by different systems. Normally, batch data analysis made up for the biggest share of the use cases, data sizes, and market, while streaming data analysis mostly served specialized applications.
These continuous streams of data come for example from web log files, application log files, and databases log files. Rather than treating the streams as streams, today’s setups ignore the continuous and timely nature of data production. Instead, data records are batched into static data sets (hourly, daily, or monthly) and then processed in a time-based fashion. Data collection tools, workflow managers, and schedulers orchestrate the creation and processing of batches, in what is actually a continuous data processing pipeline. Apache Flink follows a paradigm that embraces data stream processing as the unifying model for real time analysis, continuous streams, and batch processing both in the programming model and in the execution engine.
Flink programs can compute both data stream and batch data accurately that avoiding the need to combine different systems for the two use cases. Flink also supports different notions of time (event-time, ingestion-time, processing-time) in order to give programmers high flexibility in defining how events should be correlated. ~\cite{inproceeding-flink}.
\section{History Development}
Flink has its origins in the Stratosphere project, a research project conducted by three Berlin-based Universities as well as other European Universities between 2010 and 2014. The project had already attracted a broader community base such as NoSQL and Big Data Developers Groups. This strong community base is one reason the project was appropriate for incubation under the Apache Software Foundation (ASF).
A fork of the Stratosphere code was donated in April 2014 to the Apache Software Foundation (ASF) as an incubating project with an initial set of committers consisting of the core developer of the system. Shortly thereafter, many of the founding committers left university to start a company to commercialize Flink such as Data Artisans.
During incubation, the project name had to be changed from Stratosphere because of potential confusion with an unrelated project. The name Flink was selected to honor the style of this stream and batch processor. In German, the word “Flink” means fast or agile. A logo showing a colorful squirrel was chosen because of squirrel are fast and agile. The project completed incubation quickly, and in December 2014, Flink graduated to become a top-level project of the Apache Software Foundation (ASF). Flink is one of the 5 largest big data projects of Apache Software Foundation (ASF) with a community of more than 200 developers across the globe and several production installations in Fortune Global 500 companies. In Octorber2015, the Flink project held its first annual conference in Berlin called Flink Forward ~\cite{wiki-flink} ~\cite{book-flink}.
\section{Design}
The core computational fabric of Flink (labeled as “Flink runtime” in the Figure-1) is a distributed system that accept streaming dataflow programs and executes them in a fault-tolerant manner in one or more machines. This runtime can run in a cluster as an application of YARN (Yet Another Resources Negotiator) or within a single machine which is very useful for debugging Flink applications.
The program accepted by the runtime are very powerful, but are verbose and difficult to program directly. For that reason, Flink offer developer-friendly APIs that layer on the top of the runtime and generate there streaming dataflow programs. Apache Flink includes two core APIs: a DataStream API for bounded or unbounded streams of data and a DataSet API for bounded data sets. Flink also offers a Table API, which is a SQL-like expression language for relational stream and batch processing that can be easily embedded in Flink’s DataStream and DataSet APIs. The highest-level language supported by Flink is SQL, which is semantically similar to the Table API and represents programs as SQL query expressions ~\cite{www-flink}.
\begin{figure}[H]
\centering
\includegraphics[scale=0.7]{images/image6}
\caption{Key concept of Flink Stack ~\cite{www-flink}}
\end{figure}
\subsection{Data Stream API}
DataStream programs in Flink are regular programs that implement transformations on data streams (e.g., filtering, updating state, defining windows, aggregating). The data streams are initially created from various sources (e.g., message queues, socket streams, files). Results are returned via sinks, which may for example write the data to files, or to standard output (for example the command line terminal). Flink programs run in a variety of contexts, standalone, or embedded in other programs. The execution can happen in a local JVM, or on clusters of many machines. The DataStream API includes more than 20 different types of transformations and is available in Java and Scala languages. A simple example of a stateful stream processing program is an application that emits a word count from a continuous input stream and groups the data in 5-second windows.
\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{images/image7}
\caption{Scala Example Program: Counts the words coming from a web socket in 5 second windows ~\cite{www-flink}}
\end{figure}
\subsection{DataSet API}
DataSet programs in Flink are regular programs that implement transformations on data sets (e.g., filtering, mapping, joining, grouping). The data sets are initially created from certain sources (e.g., by reading files, or from local collections).
Results are returned via sinks, which may for example write the data to (distributed) files, or to standard output (for example the command line terminal). Flink programs run in a variety of contexts, standalone, or embedded in other programs. The execution can happen in a local JVM, or on clusters of many machines.
\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{images/image8}
\caption{Scala Example Program: WordCount ~\cite{www-flink}}
\end{figure}
\subsection{ Table API}
The Table API is a declarative DSL centered around tables, which may be dynamically changing tables (when representing streams). The Table API follows the (extended) relational model: Tables have a schema attached (similar to tables in relational databases) and the API offers comparable operations, such as select, project, join, group-by, aggregate, etc. Table API programs declaratively define what logical operation should be done rather than specifying exactly how the code for the operation looks.
Though, the Table API is extensible by various types of user-defined functions, it is less expressive than the Core APIs, but more concise to use (less code to write). In addition, Table API programs also go through an optimizer that applies optimization rules before execution ~\cite{article-flink}. One can seamlessly convert between tables and DataStream/DataSet, allowing programs to mix Table API and with the DataStream and DataSet APIs. The highest level abstraction offered by Flink is SQL. This abstraction is similar to the Table API both in semantics and expressiveness, but represents programs as SQL query expressions. The SQL abstraction closely interacts with the Table API, and SQL queries can be executed over tables defined in the Table API.
\section{Implementation of Apache Flink }
\subsection{Alibaba}
~\cite{book-flink}This huge e-commerce group works with buyer and suppliers via its web portal. The company’s online recommendation are produced by Flink. One of the attractions of working with true streaming engines such as Flink is that purchases that are being made during the day can be taken into account when recommending products to users. This particularly important on special day (holidays) when the activities is unusually high. This is an example of a use case where efficient stream processing is a big advantage over batch processing.
\subsection{Otto Group}
~\cite{book-flink}The Otto is the world’s second-largest online retailer in fashion and lifestyle in Europe. Otto had resorted to developing its own streaming engine because when it first evaluate the open source options, it could not find one that fit its requirement. After testing Flink, Otto found it fit their needs for streaming processing which include crowd-sourced user-agent identification, and a search session identifier.
\section{Conclusion}
Flink is not the only technology available to work with streaming and batch processing. There are a number of emerging technologies being developed and improved to address these needs. Obviously people choose to work with a particular technology for a variety of reason, but the strengths of Flink, the ease of working with it, and the wide range of ways it can be used to advantage make it an attractive option.
\section{Acknowledgements}
This work was done as part of the course "I524: Big Data and Open Source Software Projects" at Indiana University during Spring 2017
% Bibliography
\bibliography{references}
\end{document}
|
# **Save this file as studentid1_studentid2_lab2.ipynb**, please check this suffix when you upload your lab, especially when you have multiple copy's in the same folder!
(Your student-id is the number shown on your student card.)
E.g. if you work with 3 people, the notebook should be named:
12301230_3434343_1238938934_lab2.ipynb.
**This will be parsed by a regexp, so please double check your filename.**
Before you turn this problem in, please make sure everything runs correctly. First, **restart the kernel** (in the menubar, select Kernel$\rightarrow$Restart) and then **run all cells** (in the menubar, select Cell$\rightarrow$Run All). Note, that **you are not allowed to use Google Colab**.
**Make sure you fill in any place that says `YOUR CODE HERE` or "YOUR ANSWER HERE", as well as your names and email adresses below.**
```python
NAME = "Philipp Lintl"
NAME2 = "Anca Diana Vicol"
EMAIL = "[email protected]"
EMAIL2 = "[email protected]"
```
# Lab 2: Classification
### Machine Learning 1, November 2018
Notes on implementation:
* You should write your code and answers in this IPython Notebook: http://ipython.org/notebook.html. If you have problems, please contact your teaching assistant.
* Please write your answers right below the questions.
* Among the first lines of your notebook should be "%pylab inline". This imports all required modules, and your plots will appear inline.
* Use the provided test cells to check if your answers are correct
* **Make sure your output and plots are correct before handing in your assignment with Kernel -> Restart & Run All**
* **If possible, all your implementations should be vectorized and rely on loops as little as possible. Therefore for some questions, we give you a maximum number of loops that are necessary for an efficient implementation. This number refers to the loops in this particular function and does not count the ones in functions that are called from the function. You should not go above this number for the maximum number of points.**
$\newcommand{\bx}{\mathbf{x}}$
$\newcommand{\bw}{\mathbf{w}}$
$\newcommand{\bt}{\mathbf{t}}$
$\newcommand{\by}{\mathbf{y}}$
$\newcommand{\bm}{\mathbf{m}}$
$\newcommand{\bb}{\mathbf{b}}$
$\newcommand{\bS}{\mathbf{S}}$
$\newcommand{\ba}{\mathbf{a}}$
$\newcommand{\bz}{\mathbf{z}}$
$\newcommand{\bv}{\mathbf{v}}$
$\newcommand{\bq}{\mathbf{q}}$
$\newcommand{\bp}{\mathbf{p}}$
$\newcommand{\bh}{\mathbf{h}}$
$\newcommand{\bI}{\mathbf{I}}$
$\newcommand{\bX}{\mathbf{X}}$
$\newcommand{\bT}{\mathbf{T}}$
$\newcommand{\bPhi}{\mathbf{\Phi}}$
$\newcommand{\bW}{\mathbf{W}}$
$\newcommand{\bV}{\mathbf{V}}$
```python
%pylab inline
plt.rcParams["figure.figsize"] = [9,5]
import time
start = time.time()
```
Populating the interactive namespace from numpy and matplotlib
/home/anca/miniconda3/envs/ml1labs/lib/python3.6/site-packages/IPython/core/magics/pylab.py:160: UserWarning: pylab import has clobbered these variables: ['indices', 'tanh']
`%matplotlib` prevents importing * from pylab and numpy
"\n`%matplotlib` prevents importing * from pylab and numpy"
```python
# This cell makes sure that you have all the necessary libraries installed
import sys
import platform
from importlib.util import find_spec, module_from_spec
def check_newer_version(version_inst, version_nec):
version_inst_split = version_inst.split('.')
version_nec_split = version_nec.split('.')
for i in range(min(len(version_inst_split), len(version_nec_split))):
if int(version_nec_split[i]) > int(version_inst_split[i]):
return False
elif int(version_nec_split[i]) < int(version_inst_split[i]):
return True
return True
module_list = [('jupyter', '1.0.0'),
('matplotlib', '2.0.2'),
('numpy', '1.13.1'),
('python', '3.6.2'),
('sklearn', '0.19.0'),
('scipy', '0.19.1'),
('nb_conda', '2.2.1')]
packages_correct = True
packages_errors = []
for module_name, version in module_list:
if module_name == 'scikit-learn':
module_name = 'sklearn'
if module_name == 'pyyaml':
module_name = 'yaml'
if 'python' in module_name:
python_version = platform.python_version()
if not check_newer_version(python_version, version):
packages_correct = False
error = f'Update {module_name} to version {version}. Current version is {python_version}.'
packages_errors.append(error)
print(error)
else:
spec = find_spec(module_name)
if spec is None:
packages_correct = False
error = f'Install {module_name} with version {version} or newer, it is required for this assignment!'
packages_errors.append(error)
print(error)
else:
x =__import__(module_name)
if hasattr(x, '__version__') and not check_newer_version(x.__version__, version):
packages_correct = False
error = f'Update {module_name} to version {version}. Current version is {x.__version__}.'
packages_errors.append(error)
print(error)
try:
from google.colab import drive
packages_correct = False
error = """Please, don't use google colab!
It will make it much more complicated for us to check your homework as it merges all the cells into one."""
packages_errors.append(error)
print(error)
except:
pass
packages_errors = '\n'.join(packages_errors)
```
# Part 1. Multiclass logistic regression
Scenario: you have a friend with one big problem: she's completely blind. You decided to help her: she has a special smartphone for blind people, and you are going to develop a mobile phone app that can do _machine vision_ using the mobile camera: converting a picture (from the camera) to the meaning of the image. You decide to start with an app that can read handwritten digits, i.e. convert an image of handwritten digits to text (e.g. it would enable her to read precious handwritten phone numbers).
A key building block for such an app would be a function `predict_digit(x)` that returns the digit class of an image patch $\bx$. Since hand-coding this function is highly non-trivial, you decide to solve this problem using machine learning, such that the internal parameters of this function are automatically learned using machine learning techniques.
The dataset you're going to use for this is the MNIST handwritten digits dataset (`http://yann.lecun.com/exdb/mnist/`). You can download the data with scikit learn, and load it as follows:
```python
from sklearn.datasets import fetch_mldata
import os
# Fetch the data
try:
mnist = fetch_mldata('MNIST original', data_home='.')
except Exception:
raise FileNotFoundError('Please download mnist-original.mat from Canvas and put it in %s/mldata' % os.getcwd())
data, target = mnist.data, mnist.target.astype('int')
# Shuffle
indices = np.arange(len(data))
np.random.seed(123)
np.random.shuffle(indices)
data, target = data[indices].astype('float32'), target[indices]
# Normalize the data between 0.0 and 1.0:
data /= 255.
# Split
x_train, x_valid, x_test = data[:50000], data[50000:60000], data[60000: 70000]
t_train, t_valid, t_test = target[:50000], target[50000:60000], target[60000: 70000]
```
MNIST consists of small 28 by 28 pixel images of written digits (0-9). We split the dataset into a training, validation and testing arrays. The variables `x_train`, `x_valid` and `x_test` are $N \times M$ matrices, where $N$ is the number of datapoints in the respective set, and $M = 28^2 = 784$ is the dimensionality of the data. The second set of variables `t_train`, `t_valid` and `t_test` contain the corresponding $N$-dimensional vector of integers, containing the true class labels.
Here's a visualisation of the first 8 digits of the trainingset:
```python
def plot_digits(data, num_cols, targets=None, shape=(28,28)):
num_digits = data.shape[0]
num_rows = int(num_digits/num_cols)
for i in range(num_digits):
plt.subplot(num_rows, num_cols, i+1)
plt.imshow(data[i].reshape(shape), interpolation='none', cmap='Greys')
if targets is not None:
plt.title(int(targets[i]))
plt.colorbar()
plt.axis('off')
plt.tight_layout()
plt.show()
plot_digits(x_train[0:40000:5000], num_cols=4, targets=t_train[0:40000:5000])
```
In _multiclass_ logistic regression, the conditional probability of class label $j$ given the image $\bx$ for some datapoint is given by:
$ \log p(t = j \;|\; \bx, \bb, \bW) = \log q_j - \log Z$
where $\log q_j = \bw_j^T \bx + b_j$ (the log of the unnormalized probability of the class $j$), and $Z = \sum_k q_k$ is the normalizing factor. $\bw_j$ is the $j$-th column of $\bW$ (a matrix of size $784 \times 10$) corresponding to the class label, $b_j$ is the $j$-th element of $\bb$.
Given an input image, the multiclass logistic regression model first computes the intermediate vector $\log \bq$ (of size $10 \times 1$), using $\log q_j = \bw_j^T \bx + b_j$, containing the unnormalized log-probabilities per class.
The unnormalized probabilities are then normalized by $Z$ such that $\sum_j p_j = \sum_j \exp(\log p_j) = 1$. This is done by $\log p_j = \log q_j - \log Z$ where $Z = \sum_i \exp(\log q_i)$. This is known as the _softmax_ transformation, and is also used as a last layer of many classifcation neural network models, to ensure that the output of the network is a normalized distribution, regardless of the values of second-to-last layer ($\log \bq$)
**Warning**: when computing $\log Z$, you are likely to encounter numerical problems. Save yourself countless hours of debugging and learn the [log-sum-exp trick](https://www.xarg.org/2016/06/the-log-sum-exp-trick-in-machine-learning/ "Title").
The network's output $\log \bp$ of size $10 \times 1$ then contains the conditional log-probabilities $\log p(t = j \;|\; \bx, \bb, \bW)$ for each digit class $j$. In summary, the computations are done in this order:
$\bx \rightarrow \log \bq \rightarrow Z \rightarrow \log \bp$
Given some dataset with $N$ independent, identically distributed datapoints, the log-likelihood is given by:
$ \mathcal{L}(\bb, \bW) = \sum_{n=1}^N \mathcal{L}^{(n)}$
where we use $\mathcal{L}^{(n)}$ to denote the partial log-likelihood evaluated over a single datapoint. It is important to see that the log-probability of the class label $t^{(n)}$ given the image, is given by the $t^{(n)}$-th element of the network's output $\log \bp$, denoted by $\log p_{t^{(n)}}$:
$\mathcal{L}^{(n)} = \log p(t = t^{(n)} \;|\; \bx = \bx^{(n)}, \bb, \bW) = \log p_{t^{(n)}} = \log q_{t^{(n)}} - \log Z^{(n)}$
where $\bx^{(n)}$ and $t^{(n)}$ are the input (image) and class label (integer) of the $n$-th datapoint, and $Z^{(n)}$ is the normalizing constant for the distribution over $t^{(n)}$.
## 1.1 Gradient-based stochastic optimization
### 1.1.1 Derive gradient equations (20 points)
Derive the equations for computing the (first) partial derivatives of the log-likelihood w.r.t. all the parameters, evaluated at a _single_ datapoint $n$.
You should start deriving the equations for $\frac{\partial \mathcal{L}^{(n)}}{\partial \log q_j}$ for each $j$. For clarity, we'll use the shorthand $\delta^q_j = \frac{\partial \mathcal{L}^{(n)}}{\partial \log q_j}$.
For $j = t^{(n)}$:
$$
\delta^q_j
= \frac{\partial \log q_{t^{(n)}}}{\partial \log q_j}
-
\frac{\partial \log Z}{\partial Z}
\frac{\partial Z}{\partial \log q_j}
= 1
-
\frac{\partial \log Z}{\partial Z}
\frac{\partial Z}{\partial \log q_j}
$$
For $j \neq t^{(n)}$:
$$
\delta^q_j
= \frac{\partial \log q_{t^{(n)}}}{\partial \log q_j}
-
\frac{\partial \log Z}{\partial Z}
\frac{\partial Z}{\partial \log q_j}
=0 - \frac{\partial \log Z}{\partial Z}
\frac{\partial Z}{\partial \log q_j}
$$
Complete the above derivations for $\delta^q_j$ by furtherly developing $\frac{\partial \log Z}{\partial Z}$ and $\frac{\partial Z}{\partial \log q_j}$. Both are quite simple. For these it doesn't matter whether $j = t^{(n)}$ or not.
For $j = t^{(n)}$:
\begin{align}
\delta^q_j
&=1-\frac{exp(log(q_j))}{\sum_iexp(log(q_i))}=1-\frac{q_j}{\sum_iq_i}
\end{align}
For $j \neq t^{(n)}$:
\begin{align}
\delta^q_j
&= 0-\frac{exp(log(q_j))}{\sum_iexp(log(q_i))}=-\frac{q_j}{\sum_iq_i},
\end{align}
as $\frac{\partial \log Z}{\partial Z}=\frac{1}{Z}$ and
$\frac{\partial Z}{\partial \log q_j}=\frac{\partial \sum_iexp(log(q_i))}{\partial \log q_j}=exp(log(q_j))$
Given your equations for computing the gradients $\delta^q_j$ it should be quite straightforward to derive the equations for the gradients of the parameters of the model, $\frac{\partial \mathcal{L}^{(n)}}{\partial W_{ij}}$ and $\frac{\partial \mathcal{L}^{(n)}}{\partial b_j}$. The gradients for the biases $\bb$ are given by:
$
\frac{\partial \mathcal{L}^{(n)}}{\partial b_j}
= \frac{\partial \mathcal{L}^{(n)}}{\partial \log q_j}
\frac{\partial \log q_j}{\partial b_j}
= \delta^q_j
\cdot 1
= \delta^q_j
$
The equation above gives the derivative of $\mathcal{L}^{(n)}$ w.r.t. a single element of $\bb$, so the vector $\nabla_\bb \mathcal{L}^{(n)}$ with all derivatives of $\mathcal{L}^{(n)}$ w.r.t. the bias parameters $\bb$ is:
$
\nabla_\bb \mathcal{L}^{(n)} = \mathbf{\delta}^q
$
where $\mathbf{\delta}^q$ denotes the vector of size $10 \times 1$ with elements $\mathbf{\delta}_j^q$.
The (not fully developed) equation for computing the derivative of $\mathcal{L}^{(n)}$ w.r.t. a single element $W_{ij}$ of $\bW$ is:
$
\frac{\partial \mathcal{L}^{(n)}}{\partial W_{ij}} =
\frac{\partial \mathcal{L}^{(n)}}{\partial \log q_j}
\frac{\partial \log q_j}{\partial W_{ij}}
= \mathbf{\delta}_j^q
\frac{\partial \log q_j}{\partial W_{ij}}
$
What is $\frac{\partial \log q_j}{\partial W_{ij}}$? Complete the equation above.
If you want, you can give the resulting equation in vector format ($\nabla_{\bw_j} \mathcal{L}^{(n)} = ...$), like we did for $\nabla_\bb \mathcal{L}^{(n)}$.
It has to be noted that the gradients shapes given have to be obtained by the gradient convention to get column vectors. This is contrary to the entire course so far and caused confusion, which is why we adapted the column convention throughout our formula derivations.
With $\log q_j=\mathbf{w}_j^T\mathbf{x}+b_j=\sum_{i=1}w_{ij}\cdot x_i +b_j$, that's why $\frac{\partial \log q_j}{\partial W_{ij}}=x_i$.
For the entire $\mathbf{w}_j$ vector:
$\frac{\partial \log q_j}{\partial \mathbf{w}_{j}}=\frac{\partial (\mathbf{w}_j^T\mathbf{x}^{(n)}+b_j)}{\partial \mathbf{w}_{j}}
= \mathbf{x}^{(n)},\quad \in \mathbb{R}^{784\times 1}$
So, for $j=t^{(n)}$:
$
\frac{\partial \mathcal{L}^{(n)}}{\partial W_{ij}} =
\frac{\partial \mathcal{L}^{(n)}}{\partial \log q_j}
\frac{\partial \log q_j}{\partial W_{ij}}
= \mathbf{\delta}_j^q\cdot x_i^{(n)}\,\,\Rightarrow \frac{\partial \mathcal{L}^{(n)}}{\partial \mathbf{w_{j}}}=\nabla_{w_j}\mathcal{L}^{(n)}=\delta_j^{q}\cdot\mathbf{x}^{(n)}
$
and for $j\neq t^{(n)}$:
$
\frac{\partial \mathcal{L}^{(n)}}{\partial W_{ij}} =
\frac{\partial \mathcal{L}^{(n)}}{\partial \log q_j}
\frac{\partial \log q_j}{\partial W_{ij}}
= (1-\mathbf{\delta}_j^q)\cdot x_i^{(n)}\,\,\Rightarrow \frac{\partial \mathcal{L}^{(n)}}{\partial \mathbf{w_{j}}}=(1-\delta_j^{q})\cdot\mathbf{x}^{(n)}
$
If we aggregate these columns for all j's, we end up with a $\mathbb{R}^{784\times 10}$ matrix, which has the $\frac{\partial \mathcal{L}^{(n)}}{\partial \mathbf{w}_{j}}$ as columns and can be obtained by matrix multiplication.
### 1.1.2 Implement gradient computations (15 points)
Implement the gradient calculations you derived in the previous question. Write a function `logreg_gradient(x, t, w, b)` that returns the gradients $\nabla_{\bw_j} \mathcal{L}^{(n)}$ (for each $j$) and $\nabla_{\bb} \mathcal{L}^{(n)}$, i.e. the first partial derivatives of the log-likelihood w.r.t. the parameters $\bW$ and $\bb$, evaluated at a single datapoint (`x`, `t`).
The computation will contain roughly the following intermediate variables:
$
\log \bq \rightarrow Z \rightarrow \log \bp\,,\, \mathbf{\delta}^q
$
followed by computation of the gradient vectors $\nabla_{\bw_j} \mathcal{L}^{(n)}$ (contained in a $784 \times 10$ matrix) and $\nabla_{\bb} \mathcal{L}^{(n)}$ (a $10 \times 1$ vector).
For maximum points, ensure the function is numerically stable.
```python
# 1.1.2 Compute gradient of log p(t|x;w,b) wrt w and b
def log_probability(x, t, w, b):
#
logq = numpy.matmul(x,w) + b.reshape(1,10)
# ensures numerical stability
a = numpy.max(logq)
logZ = a + numpy.log(numpy.sum(numpy.exp(logq - a)))
Z = numpy.exp(logZ)
logp = logq - logZ
#print(logZ.shape, Z.shape, logp.shape)
return logq, logp, Z
def logreg_gradient(x, t, w, b):
logq, logp, Z = log_probability(x, t, w, b)
# Use one-hot-ecoding for the target.
t_vec = numpy.zeros(w.shape[1])
t_vec[t] = 1
dL_dlogq = t_vec.reshape(1,10) - (1/Z) * numpy.exp(logq)
dL_dw = numpy.matmul(numpy.transpose(x), dL_dlogq)
dL_db = dL_dlogq.reshape(10,1)
# here the statement contains logp[:,t] where logp is meant tas a matrix of shape 1x10
return logp[:,t].squeeze(), dL_dw, dL_db.squeeze()
```
```python
# Hidden tests for efficiency
```
```python
np.random.seed(123)
# scalar, 10 X 768 matrix, 10 X 1 vector
w = np.random.normal(size=(28*28,10), scale=0.001)
# w = np.zeros((784,10))
b = np.zeros((10,))
# test gradients, train on 1 sample
logpt, grad_w, grad_b = logreg_gradient(x_train[0:1,:], t_train[0:1], w, b)
print("Test gradient on one point")
print("Log Likelihood:\t", logpt)
print("\nGrad_W_ij\t",grad_w.shape,"matrix")
print("Grad_W_ij[0,152:158]=\t", grad_w[152:158,0])
print("\nGrad_B_i shape\t",grad_b.shape,"vector")
print("Grad_B_i=\t", grad_b.T)
print("i in {0,...,9}; j in M")
assert logpt.shape == (), logpt.shape
assert grad_w.shape == (784, 10), grad_w.shape
assert grad_b.shape == (10,), grad_b.shape
```
Test gradient on one point
Log Likelihood: -2.2959726720744777
Grad_W_ij (784, 10) matrix
Grad_W_ij[0,152:158]= [-0.04518971 -0.06758809 -0.07819784 -0.09077237 -0.07584012 -0.06365855]
Grad_B_i shape (10,) vector
Grad_B_i= [-0.10020327 -0.09977827 -0.1003198 0.89933657 -0.10037941 -0.10072863
-0.09982729 -0.09928672 -0.09949324 -0.09931994]
i in {0,...,9}; j in M
```python
# It's always good to check your gradient implementations with finite difference checking:
# Scipy provides the check_grad function, which requires flat input variables.
# So we write two helper functions that provide the gradient and output with 'flat' weights:
from scipy.optimize import check_grad
np.random.seed(123)
# scalar, 10 X 768 matrix, 10 X 1 vector
w = np.random.normal(size=(28*28,10), scale=0.001)
# w = np.zeros((784,10))
b = np.zeros((10,))
def func(w):
logpt, grad_w, grad_b = logreg_gradient(x_train[0:1,:], t_train[0:1], w.reshape(784,10), b)
return logpt
def grad(w):
logpt, grad_w, grad_b = logreg_gradient(x_train[0:1,:], t_train[0:1], w.reshape(784,10), b)
return grad_w.flatten()
finite_diff_error = check_grad(func, grad, w.flatten())
print('Finite difference error grad_w:', finite_diff_error)
assert finite_diff_error < 1e-3, 'Your gradient computation for w seems off'
def func(b):
logpt, grad_w, grad_b = logreg_gradient(x_train[0:1,:], t_train[0:1], w, b)
return logpt
def grad(b):
logpt, grad_w, grad_b = logreg_gradient(x_train[0:1,:], t_train[0:1], w, b)
return grad_b.flatten()
finite_diff_error = check_grad(func, grad, b)
print('Finite difference error grad_b:', finite_diff_error)
assert finite_diff_error < 1e-3, 'Your gradient computation for b seems off'
```
Finite difference error grad_w: 6.411502515218292e-07
Finite difference error grad_b: 5.235117487930228e-08
```python
# DO NOT REMOVE THIS CELL!
# It contains hidden tests
```
### 1.1.3 Stochastic gradient descent (15 points)
Write a function `sgd_iter(x_train, t_train, w, b)` that performs one iteration of stochastic gradient descent (SGD), and returns the new weights. It should go through the trainingset once in randomized order, call `logreg_gradient(x, t, w, b)` for each datapoint to get the gradients, and update the parameters **using a small learning rate of `1e-6`**. Note that in this case we're maximizing the likelihood function, so we should actually performing gradient ___ascent___... For more information about SGD, see Bishop 5.2.4 or an online source (i.e. https://en.wikipedia.org/wiki/Stochastic_gradient_descent)
```python
def sgd_iter(x_train, t_train, W, b):
(N, D) = x_train.shape
learning_rate = 10**(-4)
random_iterator = list(range(len(x_train)))
random.shuffle(random_iterator)
logp_train = []
for index in random_iterator:
logp, grad_w, grad_b = logreg_gradient(x_train[index].reshape(1, D), t_train[index], W, b)
W = W + learning_rate * grad_w
b = b + learning_rate * grad_b
logp_train += [logp]
return logp_train, W, b
# helper function to calculate logps of validation set
def valid_logp(x_valid, t_valid, W, b):
logp_valid = []
true_log_p = []
for index in range(len(x_valid)):
logq, logp_val, Z = log_probability(x_valid[index].reshape(1,784), t_valid[index], W, b)
logp_valid += [logp_val]
true_log_p += [logp_val[:,t_valid[index]]]
return logp_valid, true_log_p
```
```python
# Hidden tests for efficiency
```
```python
# Sanity check:
np.random.seed(1243)
w = np.zeros((28*28, 10))
b = np.zeros(10)
logp_train, W, b = sgd_iter(x_train[:5], t_train[:5], w, b)
```
## 1.2. Train
### 1.2.1 Train (12 points)
Perform SGD on the training set. Plot (in one graph) the conditional log-probability of the training set and validation set after each iteration. (6 points)
Instead of running SGD for a fixed number of steps, run it until convergence. Think of a reasonable criterion for determining convergence. As a reference: choose a criterion such that the algorithm terminates in less than 15 iterations over the training set. (2 points)
Make sure your implementation (in particular, the output of the conditional log-probability of the training set and validation set) is independent of the size of the dataset. (2 points)
```python
# epsilon chosen thus it converges ~ 14 iterations (still < 15) and yields
# 'clearer' weights
def test_sgd(x_train, t_train, x_valid, t_valid, w, b):
epsilon = 0.005
log_p = -2
last_log_p = -3
log_prob_train = []
log_prob_valid = []
log_p_valid = []
counter = 0
while numpy.abs(log_p - last_log_p) > epsilon:
last_log_p = log_p #otherwise convergence criterion does not apply
log_p, w, b = sgd_iter(x_train, t_train, w, b)
log_p = mean(log_p)
log_prob_train += [log_p]
# same for valid set
not_imp, log_p_valid = valid_logp(x_valid, t_valid, w, b)
log_p_valid = mean(log_p_valid)
log_prob_valid += [log_p_valid]
counter += 1
if counter > 20:
break
plt.plot(range(counter), log_prob_train, label='training data')
plt.plot(range(counter), log_prob_valid, label='test data')
plt.legend()
plt.title("average log-likelihood per iteration for both training and test data")
plt.show()
return w, b
np.random.seed(1243)
w = np.zeros((28*28, 10))
b = np.zeros(10)
w,b = test_sgd(x_train, t_train, x_valid, t_valid, w, b)
```
```python
# Hidden tests for efficiency
```
### 1.2.2 Visualize weights (10 points)
Visualize the resulting parameters $\bW$ after a few iterations through the training set, by treating each column of $\bW$ as an image. If you want, you can use or edit the `plot_digits(...)` above.
```python
def plot_digits_indiv(data, num_cols, targets=None, shape=(28,28)):
num_digits = data.shape[0]
num_rows = int(num_digits/num_cols)
for i in range(num_digits):
plt.subplot(num_rows, num_cols, i+1)
plt.imshow(data[i].reshape(shape), interpolation='none', cmap='jet')
if targets is not None:
plt.title(int(targets[i]))
plt.colorbar()
plt.axis('off')
plt.tight_layout()
plt.show()
plot_digits_indiv(numpy.transpose(w), 5, targets=None, shape=(28,28))
```
**Describe in less than 100 words why these weights minimize the loss**
The weights are clearly showing the shape of the digits.
There seems to be high contrast in the center, the weights directly linked to the current digit's pixels are quite high while the weights around it are very low (reaching negative values). These low weights are used to discriminate between the different digits.
The outer part of all the weights are around zero meaning that the model is not concerned with the pixels there, which makes sense considering we are expecting those to be simply white background.
### 1.2.3. Visualize the 8 hardest and 8 easiest digits (10 points)
Visualize the 8 digits in the validation set with the highest probability of the true class label under the model.
Also plot the 8 digits that were assigned the lowest probability.
```python
# gets logp of each class for each dataoṕoint of the validation set
log_p, not_imp = valid_logp(x_valid, t_valid, w, b)
# gets logp of the true class (t_valid)
prob_true_class = [(log_p[i][0][t_valid[i]], i) for i in range(len(log_p))]
# Sorts this list and keeps indexnumber to match to original datapoint
sorted_probabilities = sorted(prob_true_class, key=lambda pair: pair[0])
# take highest 8
easiest_examples = numpy.array([x_valid[i] for (_, i) in sorted_probabilities[-8:]])
easiest_targets = numpy.array([t_valid[i] for (_, i) in sorted_probabilities[-8:]])
# take lowest 8
hardest_examples = numpy.array([x_valid[i] for (_, i) in sorted_probabilities[:8]])
hardest_targets = numpy.array([t_valid[i] for (_, i) in sorted_probabilities[:8]])
easiest_examples_targets = numpy.array([t_valid[i] for (_, i) in sorted_probabilities[-8:]])
hardest_examples_targets = numpy.array([t_valid[i] for (_, i) in sorted_probabilities[:8]])
print("Easiest digits in validation set.")
plot_digits_indiv(easiest_examples, 4, targets=easiest_examples_targets, shape=(28,28))
print("Hardest digits in validation set.")
plot_digits_indiv(hardest_examples, 4, targets=hardest_examples_targets, shape=(28,28))
```
Ask yourself if these results make sense. Explain in no more then two sentences what it means that a digit is hard to classify.
A digit will be hard to clasify if it is either different from the other examples of its kind and/or similar to examples of other digits. The results make sense.
# Part 2. Multilayer perceptron
You discover that the predictions by the logistic regression classifier are not good enough for your application: the model is too simple. You want to increase the accuracy of your predictions by using a better model. For this purpose, you're going to use a multilayer perceptron (MLP), a simple kind of neural network. The perceptron will have a single hidden layer $\bh$ with $L$ elements. The parameters of the model are $\bV$ (connections between input $\bx$ and hidden layer $\bh$), $\ba$ (the biases/intercepts of $\bh$), $\bW$ (connections between $\bh$ and $\log q$) and $\bb$ (the biases/intercepts of $\log q$).
The conditional probability of the class label $j$ is given by:
$\log p(t = j \;|\; \bx, \bb, \bW) = \log q_j - \log Z$
where $q_j$ are again the unnormalized probabilities per class, and $Z = \sum_j q_j$ is again the probability normalizing factor. Each $q_j$ is computed using:
$\log q_j = \bw_j^T \bh + b_j$
where $\bh$ is a $L \times 1$ vector with the hidden layer activations (of a hidden layer with size $L$), and $\bw_j$ is the $j$-th column of $\bW$ (a $L \times 10$ matrix). Each element of the hidden layer is computed from the input vector $\bx$ using:
$h_j = \sigma(\bv_j^T \bx + a_j)$
where $\bv_j$ is the $j$-th column of $\bV$ (a $784 \times L$ matrix), $a_j$ is the $j$-th element of $\ba$, and $\sigma(.)$ is the so-called sigmoid activation function, defined by:
$\sigma(x) = \frac{1}{1 + \exp(-x)}$
Note that this model is almost equal to the multiclass logistic regression model, but with an extra 'hidden layer' $\bh$. The activations of this hidden layer can be viewed as features computed from the input, where the feature transformation ($\bV$ and $\ba$) is learned.
## 2.1 Derive gradient equations (20 points)
State (shortly) why $\nabla_{\bb} \mathcal{L}^{(n)}$ is equal to the earlier (multiclass logistic regression) case, and why $\nabla_{\bw_j} \mathcal{L}^{(n)}$ is almost equal to the earlier case.
Like in multiclass logistic regression, you should use intermediate variables $\mathbf{\delta}_j^q$. In addition, you should use intermediate variables $\mathbf{\delta}_j^h = \frac{\partial \mathcal{L}^{(n)}}{\partial h_j}$.
Given an input image, roughly the following intermediate variables should be computed:
$
\log \bq \rightarrow Z \rightarrow \log \bp \rightarrow \mathbf{\delta}^q \rightarrow \mathbf{\delta}^h
$
where $\mathbf{\delta}_j^h = \frac{\partial \mathcal{L}^{(n)}}{\partial \bh_j}$.
Give the equations for computing $\mathbf{\delta}^h$, and for computing the derivatives of $\mathcal{L}^{(n)}$ w.r.t. $\bW$, $\bb$, $\bV$ and $\ba$.
You can use the convenient fact that $\frac{\partial}{\partial x} \sigma(x) = \sigma(x) (1 - \sigma(x))$.
1.) $\nabla_\mathbf{b}\mathcal{L}^{(n)}$ stays the same, as $\log q_j=\mathbf{w}_j^T\mathbf{h}+b_j$ and thus $\frac{\partial \log q_j}{\partial b_j}=1$, as the only change to the case from before is the term $\mathbf{h}$, which is independent of $b_j$. The therm $\frac{\partial\mathcal{L}^{(n)}}{\partial \log q_j}$ stays unchanged equal to $\delta_j^q$. So, again $\frac{\partial\mathcal{L}^{(n)}}{\partial b_j}=\delta_j^q\cdot 1$ holds, implying for the gradient of all classes: $\nabla_\mathbf{b}\mathcal{L}^{(n)}=\delta^q\cdot 1\in\mathbb{R}^{10\times 1}$
2.) For $ \nabla_{\mathbf{w}_j}\mathcal{L}^{(n)}$, we look at $\frac{\partial \mathcal{L}^{(n)}}{\partial \mathbf{w}_j}$:
$
\frac{\partial \mathcal{L}^{(n)}}{\partial \mathbf{w}_j}=\frac{\partial\mathcal{L}^{(n)}}{\partial \log q_j}\cdot \frac{\partial \log q_j}{\partial \mathbf{w}_j}=\delta_j^q\cdot \mathbf{h}^{(n)}\quad \in\mathbb{R}^{L\times 1}
$, meaning that the gradient stays the same with the replacement of $\mathbf{x}$ with $\mathbf{h}$, the activation values of the hiddenlayer and a different shape, as $\mathbf{h}\in\mathbb{R}^{L\times 1}$
3.) Equations for computing $\delta^h$:
$\delta_j^h=\frac{\partial \mathcal{L}^{(n)}}{\partial \mathbf{h}_j}=\sum_i\frac{\partial\mathcal{L}^{(n)}}{\partial \log q_i}\cdot \frac{\partial \log q_i}{\partial \mathbf{h}_j}=\sum_i\delta_i^q\cdot w_{ji}=\mathbf{w}_j\cdot\delta^q, \quad \in\mathbb{R}^{1\times 10}\cdot\mathbb{R}^{10\times 1}=\mathbb{R}^{1\times 1}$,
where $\mathbf{w}_j$ is the j-th row of $\mathbf{W}$ as a row-vector.
Then, $\forall j \in\{1,\ldots,L\}\quad\Rightarrow \quad \delta^h$ emerges as:
$\delta^h=\mathbf{W}\cdot\delta^q, \quad \in\mathbb{R}^{L\times 10}\cdot\mathbb{R}^{10\times 1}=\mathbb{R}^{L\times 1}$, which is exactly the given shape of $\mathbf{h}$.
4.) Derivative of $\frac{\partial\mathcal{L}^{(n)}}{\partial \mathbf{V}}$:
For a single $j \in\{1,\ldots,L\}$:
$
\nabla_{\mathbf{v}_j}\mathcal{L^{(n)}}= \sum_i\frac{\partial\mathcal{L}^{(n)}}{\partial \log q_i}\cdot \frac{\partial \log q_i}{\partial h_j}\cdot\frac{\partial h_j}{\partial\mathbf{v}_j}=\delta_j^h\cdot\frac{\partial \sigma(\mathbf{v}_j^T\mathbf{x}+a_j)}{\partial \mathbf{v}_j}=\delta_j^h\cdot h_j(1-h_j)\frac{\mathbf{v}_j^T\mathbf{x}+a_j}{\partial \mathbf{v}_j}=\delta_j^h\cdot h_j(1-h_j)\cdot\mathbf{x}^{(n)}
$
5.) Derivative of $\frac{\partial\mathcal{L}^{(n)}}{\partial \mathbf{a}}$:
$
\frac{\partial\mathcal{L}^{(n)}}{\partial a_j}=\delta_j^h\cdot\frac{\partial \sigma(\mathbf{v}_j^T\mathbf{x}+a_j)}{\partial a_j}=\delta_j^h\cdot h_j(1-h_j)\cdot 1 \quad \Rightarrow \quad \frac{\partial\mathcal{L}^{(n)}}{\partial \mathbf{a}}\in\mathbb{R}^{L\times 1}
$
## 2.2 MAP optimization (10 points)
You derived equations for finding the _maximum likelihood_ solution of the parameters. Explain, in a few sentences, how you could extend this approach so that it optimizes towards a _maximum a posteriori_ (MAP) solution of the parameters, with a Gaussian prior on the parameters.
To extend the approach for MAP, we would need to add the logarithm of the prior distribution to the logarithm of the likelihood. After deriving with respect to w and v, we get the loss functions that these parameters should minimize. The loss functions will contain the parameters themselsves, thus leading to minimizing parameters as well. This is regularization.
## 2.3. Implement and train a MLP (15 points)
Implement an MLP model with a single hidden layer of **20 neurons**.
Train the model for **10 epochs**.
Test your implementation for learning rates of 1e-2, 1e-3 and 1e-4 and plot (in one graph) the conditional log-probability of the trainingset and validation set.
For the best model plot the weights of the first layer for in epoch 0,4 and 9.
- 10 points: Working MLP that learns with plots
- +5 points: Fast, numerically stable, vectorized implementation
```python
# Write all helper functions here
def sigmoid(x):
return 1.0 / (1.0 + numpy.exp(-x))
def iter_mlp(x_train, t_train, learning_rate, V, W, a, b):
(N, D) = x_train.shape
random_iterator = list(range(len(x_train)))
random.shuffle(random_iterator)
logp_train = []
for index in random_iterator:
x = x_train[index]
h = sigmoid(numpy.matmul(x, V) + a)
h_input = numpy.transpose(h.reshape((-1, 1)))
logp, grad_w, grad_b = logreg_gradient(h_input, t_train[index], W, b)
delta_h = numpy.matmul(grad_b, numpy.transpose(W))
partial_grad_h = numpy.multiply(delta_h, \
numpy.multiply(h, (1 - h))).reshape((1, -1))
grad_v = numpy.matmul(x.reshape((-1, 1)), partial_grad_h)
grad_a = numpy.multiply(delta_h, \
numpy.multiply(h, (1 - h)))
W = W + learning_rate * grad_w
b = b + learning_rate * grad_b
V = V + learning_rate * grad_v
a = a + learning_rate * grad_a
logp_train += [logp]
return mean(logp_train), V, W, a, b
def test_mlp(x, t, V, W, a, b):
h = sigmoid(numpy.matmul(x, V) + a)
logp_true_class = []
for i in range(len(x)):
logq, logp, Z = log_probability(h[i], t, W, b)
logp_true_class += [logp[0][t[i]]]
return numpy.average(logp_true_class)
```
```python
# Hidden tests for efficiency
```
```python
def train_mlp(learning_rate):
np.random.seed(1243)
V = np.random.normal(size=(28*28, 20), scale=0.01)
a = np.random.normal(size=(20, ), scale=0.01)
W = np.random.normal(size=(20, 10), scale=0.01)
b = np.random.normal(size=(10, ), scale=0.01)
logps_train = []
logps_valid = []
for epoch in range(10):
logp_train, V, W, a, b = iter_mlp(x_train, t_train, learning_rate, V, W, a, b)
logps_train += [logp_train]
logps_valid += [test_mlp(x_valid, t_valid, V, W, a, b)]
return logps_train, logps_valid, V, W, a, b
```
```python
# plot the train and validation logp for all three learning rates in one figure
def train_and_plot(learning_rate, color):
logps_train, logps_valid, V, W, a, b = train_mlp(learning_rate)
plt.plot(range(10), logps_train, color=color, label="Training; lr=" + str(learning_rate))
plt.plot(range(10), logps_valid, color=color, dashes=[6, 2], label="Validation; lr=" + str(learning_rate))
return V, W, a, b
models = {}
for (learning_rate, color) in [(10**(-2), 'b'), (10**(-3), 'r'), (10**(-4), 'g')]:
V, W, a, b = train_and_plot(learning_rate, color)
models[learning_rate] = (V, W, a, b)
plt.xlabel("Epoch")
plt.ylabel("Log Likelihood")
plt.tight_layout()
plt.legend()
plt.show()
```
### 2.3.1. Explain the learning curves (5 points)
In less than 80 words, explain the observed behaviour for the different learning rates.
From the graph we conclude that the largest learning rate is the most appropriate.
For the first 2 learning rates, the model reaches close to the optimum point, but than the smaller one is not strong enough to move it as close as the larger one.
With the smallest learning rate the steps are so small that the model does not even come close to the optimum in the giving epochs.
### 2.3.2. Explain the weights (5 points)
In less than 80 words, explain how and why the weights of the hidden layer of the MLP differ from the logistic regression model, and relate this to the stronger performance of the MLP.
```python
# Plot the weights of the first layer for the best model
plot_digits_indiv(numpy.transpose(models[10**(-2)][0]), 5, targets=None, shape=(28,28))
```
Because the model is using more than one layer, and the hidden layer has more than 10 neurons, the weights do not resemble the digits anymore.
This makes sense as with more neurons the model can learn more specific features, like a horizontal line in the middle of the image. These are then used to predict the actual digits in the following layer.
### 2.3.2. Different activation functions (10 points)
In the task above we use a sigmoid as an activation function.
Two other popular choices for activation functions are tanh and the rectified linear unit (ReLU). The ReLU is defined as:
$$f(x) = \max(0.,x)$$
You already derived the derivative of the softmax function above. Here, write down the derivative for both the tanh and the ReLU function. Furthermore, for all three, plot the function and its derivative in a range $x\in[-3,3]$
Write down the derivative of ReLU and tanh w.r.t. their respective argument:
ReLu:
$\frac{\partial f(x)}{\partial x} = \{0$ for $x < 0$; 1 for $x>0$; undefined for $x=0\}$
tanh:
$\tanh(x)=\frac{e^{x}-e^{-x}}{e^{x}+e^{-x}}\quad \Rightarrow \quad\frac{\partial \tanh(x)}{\partial x}=\frac{(e^x+e^{-x})(e^x+e^{-x})-(e^x-e^{-x})(e^x-e^{-x})}{(e^x+e^{-x})^2}=1-\frac{(e^x-e^{-x})^2}{(e^x+e^{-x})^2}=1-\tanh^2(x)$
Name two properties that you would like your activation function to have (one sentence each). Why are they important?
1) Non Linearity, as linear activation functions would resemble a simple regression model, which is limited in its power and mostly it is not sufficient to classify linearly especially in complex data situations such as texts or images.
2) Differentiability, as the parameters need to be 'learned', in particaular with a backpropagation step that requires the existence of a gradient and thus the computed activation functions need to be differentiable.
```python
# plot the function and the derivative for the activations sigmoid, tanh and ReLU.
def sigmoid(x):
return(1/(1+numpy.exp(-x)))
def derivative_sigmoid(x):
return sigmoid(x)*(1-sigmoid(x))
def tanh(x):
return((numpy.exp(x)-numpy.exp(-x))/(numpy.exp(x)+numpy.exp(-x)))
def derivative_tanh(x):
return(1-tanh(x)**2)
def ReLu(x):
if(x>0):
return(x)
else:
return(0)
def derivative_ReLu(x):
if(x==0):
return
if(x > 0):
return 1
else:
return 0
x = [i / 1000 for i in range(-3000, 3000, 1)]
plt.plot(x, [sigmoid(i) for i in x], label='sigmoid')
plt.plot(x, [tanh(i) for i in x], label='tanh')
plt.plot(x, [ReLu(i) for i in x], label='ReLu')
plt.legend()
plt.title("Activation functions")
plt.show()
plt.plot(x, [derivative_sigmoid(i) for i in x], label='sigmoid')
plt.plot(x, [derivative_tanh(i) for i in x], label='tanh')
plt.plot(x, [derivative_ReLu(i) for i in x], label='ReLu')
plt.legend()
plt.title("Derivatives of activation functions")
plt.show()
```
Now that you plotted the activations and derivatives, which activation do you think is the best? Why would you choose this activation function? For your answer consider what you named as essential properties for an activation function above. Keep your answer short at no more then 3 sentences.
Considering non-linearity and differentiability, clearly Relu is neither and thus in this case ruled out (though very popular for deep neural nets as it combats very small gradients which lead to a stop in updates -the Vanishing Gradient Problem-). Choosing between sigmoid and tanh, we would argue for tanh, as its range incorporates negative values as well and the derivatives range is also larger, thus alowing larger steps to be made.
```python
print('Notebook ran in {:2.3} minutes.'.format((time.time()-start)/60))
```
Notebook ran in 8.5e+02 minutes.
|
State Before: ι : Type ?u.387507
α : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α
p : α → Bool
l : List α
⊢ dropWhile p l = [] ↔ ∀ (x : α), x ∈ l → p x = true State After: case nil
ι : Type ?u.387507
α : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α
p : α → Bool
l : List α
⊢ dropWhile p [] = [] ↔ ∀ (x : α), x ∈ [] → p x = true
case cons
ι : Type ?u.387507
α : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α
p : α → Bool
l : List α
x : α
xs : List α
IH : dropWhile p xs = [] ↔ ∀ (x : α), x ∈ xs → p x = true
⊢ dropWhile p (x :: xs) = [] ↔ ∀ (x_1 : α), x_1 ∈ x :: xs → p x_1 = true Tactic: induction' l with x xs IH State Before: case nil
ι : Type ?u.387507
α : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α
p : α → Bool
l : List α
⊢ dropWhile p [] = [] ↔ ∀ (x : α), x ∈ [] → p x = true State After: no goals Tactic: simp [dropWhile] State Before: case cons
ι : Type ?u.387507
α : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α
p : α → Bool
l : List α
x : α
xs : List α
IH : dropWhile p xs = [] ↔ ∀ (x : α), x ∈ xs → p x = true
⊢ dropWhile p (x :: xs) = [] ↔ ∀ (x_1 : α), x_1 ∈ x :: xs → p x_1 = true State After: no goals Tactic: by_cases hp : p x <;> simp [hp, dropWhile, IH]
|
# Exercise session nº 2
---
# Sonic Hedgehog Signaling Gradient Readout in the Vertebrate Neural Tube
__*Sacha Ichbiah, 31/01/22, ENS Paris*__
This subject is extracted from :
> N. Balaskas et Al., *Gene Regulatory Logic for Reading the Sonic Hedgehog Signaling Gradient in the Vertebrate Neural Tube*, Cell, 2012.
> https://doi.org/10.1016/j.cell.2011.10.047
Secreted signals, known as morphogens, provide the positional information that organizes gene expression and cellular differentiation in many developing tissues. Several morphogens gradients can be observed on biological systems during development. However, the way the cells integrate the signal is often complicated and organism dependent. A simple model introduced by __Lewis Wolpert__, called the __French flag model__, postulates that the different cell fates adopted is the result of the crossing of thresholds of morphogens concentrations.
In the vertebrate neural tube, Sonic Hedgehog (Shh) acts as a morphogen to control the pattern of neuronal subtype specification. However, it was not clear how Shh gradient were interpreted by the cell to induce different cell fates. This article shows that a spatially and temporally changing gradient of Shh signaling is interpreted by the regulatory logic of a downstream transcriptional network. The design of the network, which links three transcription factors to Shh signaling, is responsible for differential spatial and temporal gene expression. In addition, the network renders cells insensitive to fluctuations in signaling and confers hysteresis - memory of the signal. The morphogen interpretation is an emergent property of the architecture of a transcriptional network that provides robustness and reliability to tissue patterning.
During this session, we will model the gene regulation network using differential equations and observe the behaviour induced by the architecture of this network.
---
## I - Temporal evolution of the GRN :
The relations between these proteins can be modeled as such :
$
\begin{align}
\frac{dP}{dt} &=\frac{\alpha}{1 + (\frac{N}{N_{critP}})^{h_1} + (\frac{O}{O_{critP}})^{h_2} } - k_1P \newline
\frac{dO}{dt} &=\frac{\beta G}{1 + G} \frac{1}{1 + (\frac{N}{N_{critO}})^{h_3} } - k_2O \newline
\frac{dN}{dt} &=\frac{\gamma G}{1 + G} \frac{1}{1 + (\frac{O}{O_{critN}})^{h_4} + (\frac{P}{P_{critN}})^{h_5} } - k_3N \newline
\end{align}
$
#### **Question 1 :**
> Discretize these differential equations with a forward euler-scheme
#### **Question 2 :**
> Integrate these equations for the given parameters for $t \in [0,50]$, starting with $P(0)=3, O(0)=N(0)=0$. Try with G $\in [1,2,3,4,5]$ What do you observe ?
```python
import numpy as np
import matplotlib.pyplot as plt
alpha = 3
beta = 5
gamma = 5
h1 = 6
h2 = 2
h3 = 5
h4 = 1
h5 = 1
k1 = 1
k2 = 1
k3 = 1
OcritP = 1
NcritP = 1
NcritO = 1
PcritN = 1
tfinal = 50
npoints = 1000
timepoints = np.linspace(0,tfinal,npoints)
```
## II - Phase diagram of the GRN :
#### **Question 3 :**
> Plot the phase diagram of the steady states values of P,O and D for G $\in G_{vals}$. Then plot the phase diagram for $\alpha = 0, \beta=0 \text{ and } (\alpha,\beta)=0$
```python
n_gvals = 100
Gvals = np.linspace(0,5,n_gvals)
```
## III - Noise buffering by the GRN :
#### **Question 4 :**
> Compare the temporal evolution with $G = 5$ to the one with $G \mapsto \mathcal{N}(5,1)$, a normal law of mean 5 and of variance 1. What are the effects of the noise on the proteins concentrations ?
```python
alpha = 3
beta = 5
gamma = 5
h1 = 6
h2 = 2
h3 = 5
h4 = 1
h5 = 1
k1 = 1
k2 = 1
k3 = 1
OcritP = 1
NcritP = 1
NcritO = 1
PcritN = 1
G_mean = 5
G_std = 1
```
## IV - Hysteresis
#### **Question 5 :**
> From the steady state at G = 0, make G evolve slowly such that the steady state is reached at each variation of G. Then when G = 5, make G decrease back to zero. what do you observe ?
# Conclusion
The proposed model provides evidence that Shh morphogen interpretation in the neural tube is a property of the downstream GNN. Cells transform the extracellular gradient of Shh into a dynamic profile of intracellular Gli activity that engages a transcriptional circuit, the regulatory logic of which is responsible for the generation of the characteristic temporal and spatial patterns of gene expression. This mechanism offers a powerful strategy to achieve the characteristic precision and robustness of morphogen-mediated pattern formation.
In the following of the article, the authors introduce another model, extending the preceding one by taking into account a forth protein, Gli. It allows them to reproduce the behaviours observed in their in-vivo experiments. On top of explaining the variable spatial patterns of gene expression, the networks confers both robustness and hysteresis of protein production. The insensitivity of the circuit to transient changes in the level of signaling provides a way to achieve reliable patterning in spite of the inherent noisiness of development. The study highlights the information-processing power of transcriptional networks and the simplicity and adaptability of this mechanism suggest that it is likely to be relevant for the control of patterning of tissues other than the neural tube.
The gene regulatory networks encountered in biological systems are often too complicated to construct them heuristically. Eric H. Davidson pionnered the use of bioinformatical tools to automatically infer gene regulation networks from genomic and transcriptomic data. It gives an engineer view of the genes relationships during developments, showing the complexity of the mechanisms involved.
> Gene regulation network for endomesoderm specification made with biotapestry : http://www.biotapestry.org. Don't try to understand this graph !
_Additional references :_
> Michael Akam, *Making stripes ineleganty*, Nature, 1989. https://doi.org/10.1038/341282a0
> Eric H. Davidson, *Emerging properties of animal gene regulatory networks*, Nature, 2010. https://doi.org/10.1038/nature09645
> Eric H. Davidson, Samuel Levine *Properties of developmental gene regulatory networks*, PNAS, 2008 https://doi.org/10.1073/pnas.0806007105
> Lewis Wolpert, *Positional information and the spatial pattern of cellular differentiation*, Journal of Theoretical Biology, 1969. https://doi.org/10.1016/S0022-5193(69)80016-0
|
# Transvectant computations
```python
from sympy import Function, Symbol, symbols, init_printing, expand
from IPython.display import Math, display
init_printing()
from transvectants import *
def disp(expr):
display(Math(my_latex(expr)))
```
```python
x, y = symbols('x y')
f = Function('f')(x, y)
```
```python
disp(expand(partial_transvectant((f, f), [[0, 1]])))
```
$\displaystyle 0$
```python
disp(expand(partial_transvectant((f, f), [[0, 1], [0, 1], [0, 1], [0, 1]])))
```
$\displaystyle 2 f_{xxxx} f_{yyyy} - 8 f_{xyyy} f_{xxxy} + 6 \left(f_{xxyy}\right)^{2}$
```python
disp(expand(partial_transvectant((f, f, f, f, f, f), [[0, 1], [1, 2], [3, 4], [4, 5]])))
```
$\displaystyle \left(f_{x}\right)^{4} \left(f_{yy}\right)^{2} - 4 \left(f_{x}\right)^{3} f_{y} f_{yy} f_{xy} + 2 \left(f_{x}\right)^{2} f_{xx} \left(f_{y}\right)^{2} f_{yy} + 4 \left(f_{x}\right)^{2} \left(f_{y}\right)^{2} \left(f_{xy}\right)^{2} - 4 f_{x} f_{xx} \left(f_{y}\right)^{3} f_{xy} + \left(f_{xx}\right)^{2} \left(f_{y}\right)^{4}$
```python
disp(expand(partial_transvectant((f, f, f), [[0, 1], [0, 1], [0, 2], [0, 2]])))
```
$\displaystyle \left(f_{xx}\right)^{2} f_{yyyy} + 2 f_{xx} f_{yy} f_{xxyy} - 4 f_{xx} f_{xy} f_{xyyy} + f_{xxxx} \left(f_{yy}\right)^{2} - 4 f_{yy} f_{xy} f_{xxxy} + 4 \left(f_{xy}\right)^{2} f_{xxyy}$
```python
disp(expand(partial_transvectant((f, f, f, f, f), [[0, 1], [0, 1], [2, 3], [2, 3], [2, 4]]) ) -2*(expand(partial_transvectant((f, f, f, f, f), [[0, 1], [1, 2], [2, 3], [3, 0], [0, 4]]) )))
```
$\displaystyle 0$
```python
disp(expand(partial_transvectant((f, f, f), [[0, 1], [0, 1], [0, 1], [0, 2]])))
```
$\displaystyle f_{x} f_{xxx} f_{yyyy} - f_{x} f_{yyy} f_{xxxy} + 3 f_{x} f_{xyy} f_{xxyy} - 3 f_{x} f_{xyyy} f_{xxy} - f_{xxx} f_{y} f_{xyyy} + f_{xxxx} f_{y} f_{yyy} - 3 f_{y} f_{xyy} f_{xxxy} + 3 f_{y} f_{xxy} f_{xxyy}$
```python
disp(expand(partial_transvectant((f, f), [[0, 1], [0, 1], [0, 1]])))
```
$\displaystyle 0$
```python
#C = transvectant(f, f, 2)
#D = -partial_transvectant((f, f, f), [[0, 1], [1, 2]])
# We are going to build these by weight, not degree.
# Hence order does not match dispaper
# Weight 4 (2 of 'em)
I4_1 = partial_transvectant((f,f),[[0,1],[0,1]]) # = C
I4_2 = partial_transvectant((f, f, f), [[0, 1], [1, 2]]) # = -D
# Weight 6 (2 of 'em)
print('weight 3:')
I6_1 = partial_transvectant((f,f,f),[[0,1],[0,1],[0,2]]) # = transvectant(f, C, 1)
I6_2 = partial_transvectant((f,f,f,f),[[0,1],[0,2],[0,3]])
# Weight 8 (7 of 'em??)
print('weight 4:')
I8_1 = expand(partial_transvectant((f,f,f),[[0,1],[0,1],[1,2],[0,2]]))
I8_2 = expand(partial_transvectant((f,f,f,f),[[0,1],[0,1],[1,2],[2,3]]))
I8_3 = expand(partial_transvectant((f,f,f,f),[[0,1],[1,2],[2,3],[3,0]]))
I8_4 = expand(partial_transvectant((f,f,f,f),[[0,1],[1,2],[1,2],[2,3]]))
I8_5 = expand(partial_transvectant((f,f,f,f,f),[[0,1],[1,2],[2,3],[3,4]]))
I8_6 = expand(partial_transvectant((f,f,f,f,f),[[0,1],[0,2],[0,3],[3,4]]))
I8_7 = expand(partial_transvectant((f,f,f,f,f),[[0,1],[0,2],[0,3],[0,4]]))
print('weight 2')
disp(I4_1)
disp(I4_2)
print('weight 3')
disp(I6_1)
disp(expand(I6_2))
print('weight 4')
disp(I8_1)
print('')
disp(I8_2)
print('')
disp(I8_3)
print('')
disp(I8_4)
print('')
disp(I8_5)
print('')
disp(I8_6)
print('')
disp(I8_7)
```
weight 3:
weight 4:
weight 2
$\displaystyle 2 f_{xx} f_{yy} - 2 \left(f_{xy}\right)^{2}$
$\displaystyle - \left(f_{x}\right)^{2} f_{yy} + 2 f_{x} f_{y} f_{xy} - f_{xx} \left(f_{y}\right)^{2}$
weight 3
$\displaystyle - \left(f_{xx} f_{yyy} + f_{yy} f_{xxy} - 2 f_{xy} f_{xyy}\right) f_{x} + \left(f_{xx} f_{xyy} + f_{xxx} f_{yy} - 2 f_{xy} f_{xxy}\right) f_{y}$
$\displaystyle - \left(f_{x}\right)^{3} f_{yyy} + 3 \left(f_{x}\right)^{2} f_{y} f_{xyy} - 3 f_{x} \left(f_{y}\right)^{2} f_{xxy} + f_{xxx} \left(f_{y}\right)^{3}$
weight 4
$\displaystyle 2 f_{xx} f_{yyy} f_{xxy} - 2 f_{xx} \left(f_{xyy}\right)^{2} + 2 f_{xxx} f_{yy} f_{xyy} - 2 f_{xxx} f_{yyy} f_{xy} - 2 f_{yy} \left(f_{xxy}\right)^{2} + 2 f_{xy} f_{xyy} f_{xxy}$
$\displaystyle - f_{x} f_{xx} f_{yy} f_{xyy} + f_{x} f_{xx} f_{yyy} f_{xy} - f_{x} f_{xxx} \left(f_{yy}\right)^{2} + 3 f_{x} f_{yy} f_{xy} f_{xxy} - 2 f_{x} \left(f_{xy}\right)^{2} f_{xyy} - \left(f_{xx}\right)^{2} f_{y} f_{yyy} - f_{xx} f_{y} f_{yy} f_{xxy} + 3 f_{xx} f_{y} f_{xy} f_{xyy} + f_{xxx} f_{y} f_{yy} f_{xy} - 2 f_{y} \left(f_{xy}\right)^{2} f_{xxy}$
$\displaystyle 2 \left(f_{xx}\right)^{2} \left(f_{yy}\right)^{2} - 4 f_{xx} f_{yy} \left(f_{xy}\right)^{2} + 2 \left(f_{xy}\right)^{4}$
$\displaystyle - 2 \left(f_{x}\right)^{2} f_{yyy} f_{xxy} + 2 \left(f_{x}\right)^{2} \left(f_{xyy}\right)^{2} + 2 f_{x} f_{xxx} f_{y} f_{yyy} - 2 f_{x} f_{y} f_{xyy} f_{xxy} - 2 f_{xxx} \left(f_{y}\right)^{2} f_{xyy} + 2 \left(f_{y}\right)^{2} \left(f_{xxy}\right)^{2}$
$\displaystyle \left(f_{x}\right)^{2} f_{xx} \left(f_{yy}\right)^{2} - \left(f_{x}\right)^{2} f_{yy} \left(f_{xy}\right)^{2} - 2 f_{x} f_{xx} f_{y} f_{yy} f_{xy} + 2 f_{x} f_{y} \left(f_{xy}\right)^{3} + \left(f_{xx}\right)^{2} \left(f_{y}\right)^{2} f_{yy} - f_{xx} \left(f_{y}\right)^{2} \left(f_{xy}\right)^{2}$
$\displaystyle - \left(f_{x}\right)^{3} f_{yy} f_{xyy} + \left(f_{x}\right)^{3} f_{yyy} f_{xy} - \left(f_{x}\right)^{2} f_{xx} f_{y} f_{yyy} + 2 \left(f_{x}\right)^{2} f_{y} f_{yy} f_{xxy} - \left(f_{x}\right)^{2} f_{y} f_{xy} f_{xyy} + 2 f_{x} f_{xx} \left(f_{y}\right)^{2} f_{xyy} - f_{x} f_{xxx} \left(f_{y}\right)^{2} f_{yy} - f_{x} \left(f_{y}\right)^{2} f_{xy} f_{xxy} - f_{xx} \left(f_{y}\right)^{3} f_{xxy} + f_{xxx} \left(f_{y}\right)^{3} f_{xy}$
$\displaystyle \left(f_{x}\right)^{4} f_{yyyy} - 4 \left(f_{x}\right)^{3} f_{y} f_{xyyy} + 6 \left(f_{x}\right)^{2} \left(f_{y}\right)^{2} f_{xxyy} - 4 f_{x} \left(f_{y}\right)^{3} f_{xxxy} + f_{xxxx} \left(f_{y}\right)^{4}$
```python
# Only 'weight 4' affine invariant
disp(I4_2/I4_1)
# Only 'weight 6' affine invariant
disp(I6_2/I6_1)
```
$$\frac{- \left(f_{x}\right)^{2} f_{yy} + 2 f_{x} f_{y} f_{xy} - \left(f_{y}\right)^{2} f_{xx}}{2 f_{xx} f_{yy} - 2 \left(f_{xy}\right)^{2}}$$
$$\frac{- \left(f_{x}\right)^{3} f_{yyy} + 3 \left(f_{x}\right)^{2} f_{y} f_{xyy} - 3 f_{x} \left(f_{y}\right)^{2} f_{xxy} + \left(f_{y}\right)^{3} f_{xxx}}{\left(f_{xx} f_{xyy} - 2 f_{xy} f_{xxy} + f_{yy} f_{xxx}\right) f_{y} - \left(f_{xx} f_{yyy} - 2 f_{xy} f_{xyy} + f_{yy} f_{xxy}\right) f_{x}}$$
```python
disp(partial_transvectant((f,f,f,f,f),[[0,2],[1,2],[2,3],[3,4]]))
```
$$- \left(f_{x}\right)^{3} f_{xy} f_{yyy} + \left(f_{x}\right)^{3} f_{yy} f_{xyy} + \left(f_{x}\right)^{2} f_{y} f_{xx} f_{yyy} + \left(f_{x}\right)^{2} f_{y} f_{xy} f_{xyy} - 2 \left(f_{x}\right)^{2} f_{y} f_{yy} f_{xxy} - 2 f_{x} \left(f_{y}\right)^{2} f_{xx} f_{xyy} + f_{x} \left(f_{y}\right)^{2} f_{xy} f_{xxy} + f_{x} \left(f_{y}\right)^{2} f_{yy} f_{xxx} + \left(f_{y}\right)^{3} f_{xx} f_{xxy} - \left(f_{y}\right)^{3} f_{xy} f_{xxx}$$
```python
disp(partial_transvectant((f,f,C),[[0,1],[1,2]]))
```
$$4 \left(\left(f_{x} f_{xy} - f_{y} f_{xx}\right) \left(f_{xx} f_{yyy} - 2 f_{xy} f_{xyy} + f_{yy} f_{xxy}\right) - \left(f_{x} f_{yy} - f_{y} f_{xy}\right) \left(f_{xx} f_{xyy} - 2 f_{xy} f_{xxy} + f_{yy} f_{xxx}\right)\right) f{\left (x,y \right )}$$
```python
#disp(transvectant(C, C, 2))
funcs = (C, f**2)
pairs = [[0, 1]]
disp(partial_transvectant(funcs, pairs))
```
$$4 \left(\left(f_{xx} f_{xyy} - 2 f_{xy} f_{xxy} + f_{yy} f_{xxx}\right) f_{y} - \left(f_{xx} f_{yyy} - 2 f_{xy} f_{xyy} + f_{yy} f_{xxy}\right) f_{x}\right) f{\left (x,y \right )}$$
```python
# Construct linear, quadratic, cubic forms
fx, fy, fxx, fxy, fyy, fxxx, fxxy, fxyy, fyyy = symbols('f_x, f_y, f_{xx}, f_{xy}, f_{yy}, f_{xxx}, f_{xxy}, f_{xyy}, f_{yyy}')
l = fx*x + fy*y
q = fxx*x*x + 2*fxy*x*y + fyy*y*y
c = fxxx*x*x*x + 3*fxxy*x*x*y + 3*fxyy*x*y*y + fyyy*y*y*y
```
```python
# I3 as a form (Robert's method to annoy us...)
disp(-expand(transvectant(q,transvectant(c,c,2),2)/288))
# I5
disp(expand(transvectant(transvectant(c,c,2),transvectant(c,c,2),2)/10368))
# I6
disp(transvectant(c,l**3,3)/36)
```
$$- f_{xxx} f_{xyy} f_{yy} + f_{xxx} f_{xy} f_{yyy} + f_{xxy}^{2} f_{yy} - f_{xxy} f_{xx} f_{yyy} - f_{xxy} f_{xyy} f_{xy} + f_{xx} f_{xyy}^{2}$$
```python
```
```python
```
$$- 2 f_{xx} f_{xxy} f_{yyy} + 2 f_{xx} \left(f_{xyy}\right)^{2} + 2 f_{xy} f_{xxx} f_{yyy} - 2 f_{xy} f_{xxy} f_{xyy} - 2 f_{yy} f_{xxx} f_{xyy} + 2 f_{yy} \left(f_{xxy}\right)^{2}$$
```python
```
$$2 f_{xx} f_{xxy} f_{yyy} - 2 f_{xx} \left(f_{xyy}\right)^{2} - 2 f_{xy} f_{xxx} f_{yyy} + 2 f_{xy} f_{xxy} f_{xyy} + 2 f_{yy} f_{xxx} f_{xyy} - 2 f_{yy} \left(f_{xxy}\right)^{2}$$
```python
```
$$0$$
```python
disp(simplify(partial_transvectant((f,f,f,f),[[0,1],[1,2],[2,3]])))
disp(simplify(partial_transvectant((f,f,f,f),[[0,1],[1,2],[2,3],[0,1]])))
disp(simplify(partial_transvectant((f,f,f,f),[[0,1],[1,2],[2,3],[0,2]])))
disp(simplify(partial_transvectant((f,f,f,f),[[0,1],[1,2],[2,3],[0,1],[0,2]])))
disp(simplify(partial_transvectant((f,f,f,f),[[0,1],[1,2],[2,3],[3,0]])))
disp(simplify(partial_transvectant((f,f,f,f),[[0,1],[1,2],[2,3],[3,0],[0,1]])))
disp(simplify(partial_transvectant((f,f,f,f),[[0,1],[1,2],[2,3],[3,0],[0,2]])))
disp(simplify(partial_transvectant((f,f,f,f),[[0,1],[0,1],[1,2],[1,2],[2,3]])))
disp(simplify(partial_transvectant((f,f,f,f),[[0,1],[0,1],[1,2],[1,2],[2,3],[2,3]])))
disp(simplify(partial_transvectant((f,f,f,f),[[0,1],[1,2],[2,3],[3,0],[0,1],[1,2]])))
```
$$0$$
$$f_{x} f_{xx} f_{xy} f_{yyy} - f_{x} f_{xx} f_{yy} f_{xyy} - 2 f_{x} \left(f_{xy}\right)^{2} f_{xyy} + 3 f_{x} f_{xy} f_{yy} f_{xxy} - f_{x} \left(f_{yy}\right)^{2} f_{xxx} - f_{y} \left(f_{xx}\right)^{2} f_{yyy} + 3 f_{y} f_{xx} f_{xy} f_{xyy} - f_{y} f_{xx} f_{yy} f_{xxy} - 2 f_{y} \left(f_{xy}\right)^{2} f_{xxy} + f_{y} f_{xy} f_{yy} f_{xxx}$$
$$0$$
$$0$$
$$2 \left(f_{xx}\right)^{2} \left(f_{yy}\right)^{2} - 4 f_{xx} \left(f_{xy}\right)^{2} f_{yy} + 2 \left(f_{xy}\right)^{4}$$
$$0$$
$$0$$
$$\left(\left(f_{xx} f_{xxyy} - 2 f_{xy} f_{xxxy} + f_{yy} f_{xxxx}\right) f_{xyy} - 2 \left(f_{xx} f_{xyyy} - 2 f_{xy} f_{xxyy} + f_{yy} f_{xxxy}\right) f_{xxy} + \left(f_{xx} f_{yyyy} - 2 f_{xy} f_{xyyy} + f_{yy} f_{xxyy}\right) f_{xxx}\right) f_{y} - \left(\left(f_{xx} f_{xxyy} - 2 f_{xy} f_{xxxy} + f_{yy} f_{xxxx}\right) f_{yyy} - 2 \left(f_{xx} f_{xyyy} - 2 f_{xy} f_{xxyy} + f_{yy} f_{xxxy}\right) f_{xyy} + \left(f_{xx} f_{yyyy} - 2 f_{xy} f_{xyyy} + f_{yy} f_{xxyy}\right) f_{xxy}\right) f_{x}$$
$$2 \left(f_{xx}\right)^{2} f_{xxyy} f_{yyyy} - 2 \left(f_{xx}\right)^{2} \left(f_{xyyy}\right)^{2} - 4 f_{xx} f_{xy} f_{xxxy} f_{yyyy} + 4 f_{xx} f_{xy} f_{xxyy} f_{xyyy} + 2 f_{xx} f_{yy} f_{xxxx} f_{yyyy} - 4 f_{xx} f_{yy} f_{xxxy} f_{xyyy} + 2 f_{xx} f_{yy} \left(f_{xxyy}\right)^{2} + 8 \left(f_{xy}\right)^{2} f_{xxxy} f_{xyyy} - 8 \left(f_{xy}\right)^{2} \left(f_{xxyy}\right)^{2} - 4 f_{xy} f_{yy} f_{xxxx} f_{xyyy} + 4 f_{xy} f_{yy} f_{xxxy} f_{xxyy} + 2 \left(f_{yy}\right)^{2} f_{xxxx} f_{xxyy} - 2 \left(f_{yy}\right)^{2} \left(f_{xxxy}\right)^{2}$$
$$- f_{xx} \left(f_{xxy}\right)^{2} f_{yyyy} + 4 f_{xx} f_{xxy} f_{xyy} f_{xyyy} - 2 f_{xx} f_{xxy} f_{yyy} f_{xxyy} - 4 f_{xx} \left(f_{xyy}\right)^{2} f_{xxyy} + 4 f_{xx} f_{xyy} f_{yyy} f_{xxxy} - f_{xx} \left(f_{yyy}\right)^{2} f_{xxxx} + 2 f_{xy} f_{xxx} f_{xxy} f_{yyyy} - 4 f_{xy} f_{xxx} f_{xyy} f_{xyyy} + 2 f_{xy} f_{xxx} f_{yyy} f_{xxyy} - 4 f_{xy} \left(f_{xxy}\right)^{2} f_{xyyy} + 10 f_{xy} f_{xxy} f_{xyy} f_{xxyy} - 4 f_{xy} f_{xxy} f_{yyy} f_{xxxy} - 4 f_{xy} \left(f_{xyy}\right)^{2} f_{xxxy} + 2 f_{xy} f_{xyy} f_{yyy} f_{xxxx} - f_{yy} \left(f_{xxx}\right)^{2} f_{yyyy} + 4 f_{yy} f_{xxx} f_{xxy} f_{xyyy} - 2 f_{yy} f_{xxx} f_{xyy} f_{xxyy} - 4 f_{yy} \left(f_{xxy}\right)^{2} f_{xxyy} + 4 f_{yy} f_{xxy} f_{xyy} f_{xxxy} - f_{yy} \left(f_{xyy}\right)^{2} f_{xxxx}$$
```python
disp(simplify(partial_transvectant((f,f,f),[[0,1],[1,2],[2,0]])))
disp(simplify(partial_transvectant((f,f,f),[[0,1],[1,2],[0,1]])))
disp(simplify(partial_transvectant((f,f,f),[[0,1],[1,2],[2,0],[0,1]])))
```
```python
disp(simplify(partial_transvectant((f,f,f,f),[[0,1],[0,1],[1,2],[1,2],[2,3]])))
disp(simplify(partial_transvectant((f,f,f,f),[[0,1],[0,1],[1,2],[1,2],[2,3],[2,3]])))
```
$$\left(\left(f_{xx} f_{xxyy} - 2 f_{xy} f_{xxxy} + f_{yy} f_{xxxx}\right) f_{xyy} - 2 \left(f_{xx} f_{xyyy} - 2 f_{xy} f_{xxyy} + f_{yy} f_{xxxy}\right) f_{xxy} + \left(f_{xx} f_{yyyy} - 2 f_{xy} f_{xyyy} + f_{yy} f_{xxyy}\right) f_{xxx}\right) f_{y} - \left(\left(f_{xx} f_{xxyy} - 2 f_{xy} f_{xxxy} + f_{yy} f_{xxxx}\right) f_{yyy} - 2 \left(f_{xx} f_{xyyy} - 2 f_{xy} f_{xxyy} + f_{yy} f_{xxxy}\right) f_{xyy} + \left(f_{xx} f_{yyyy} - 2 f_{xy} f_{xyyy} + f_{yy} f_{xxyy}\right) f_{xxy}\right) f_{x}$$
$$2 \left(f_{xx}\right)^{2} f_{xxyy} f_{yyyy} - 2 \left(f_{xx}\right)^{2} \left(f_{xyyy}\right)^{2} - 4 f_{xx} f_{xy} f_{xxxy} f_{yyyy} + 4 f_{xx} f_{xy} f_{xxyy} f_{xyyy} + 2 f_{xx} f_{yy} f_{xxxx} f_{yyyy} - 4 f_{xx} f_{yy} f_{xxxy} f_{xyyy} + 2 f_{xx} f_{yy} \left(f_{xxyy}\right)^{2} + 8 \left(f_{xy}\right)^{2} f_{xxxy} f_{xyyy} - 8 \left(f_{xy}\right)^{2} \left(f_{xxyy}\right)^{2} - 4 f_{xy} f_{yy} f_{xxxx} f_{xyyy} + 4 f_{xy} f_{yy} f_{xxxy} f_{xxyy} + 2 \left(f_{yy}\right)^{2} f_{xxxx} f_{xxyy} - 2 \left(f_{yy}\right)^{2} \left(f_{xxxy}\right)^{2}$$
```python
disp(expand(partial_transvectant((f,f,f,f,f),[[0,1],[1,2],[2,3],[3,4]])))
```
$$\left(f_{x}\right)^{2} f_{xx} \left(f_{yy}\right)^{2} - \left(f_{x}\right)^{2} \left(f_{xy}\right)^{2} f_{yy} - 2 f_{x} f_{y} f_{xx} f_{xy} f_{yy} + 2 f_{x} f_{y} \left(f_{xy}\right)^{3} + \left(f_{y}\right)^{2} \left(f_{xx}\right)^{2} f_{yy} - \left(f_{y}\right)^{2} f_{xx} \left(f_{xy}\right)^{2}$$
```python
disp(expand(partial_transvectant((f,f,f,f,f),[[0,1],[1,2],[2,3],[3,4]])))
disp(expand(partial_transvectant((f,f,f,f,f),[[0,1],[0,2],[0,3],[3,4]])))
disp(expand(partial_transvectant((f,f,f,f,f),[[0,1],[0,2],[0,3],[0,4]])))
```
$$\left(f_{x}\right)^{2} f_{xx} \left(f_{yy}\right)^{2} - \left(f_{x}\right)^{2} \left(f_{xy}\right)^{2} f_{yy} - 2 f_{x} f_{y} f_{xx} f_{xy} f_{yy} + 2 f_{x} f_{y} \left(f_{xy}\right)^{3} + \left(f_{y}\right)^{2} \left(f_{xx}\right)^{2} f_{yy} - \left(f_{y}\right)^{2} f_{xx} \left(f_{xy}\right)^{2}$$
$$- \left(f_{x}\right)^{2} f_{xx} \left(f_{yy}\right)^{2} + \left(f_{x}\right)^{2} \left(f_{xy}\right)^{2} f_{yy} + 2 f_{x} f_{y} f_{xx} f_{xy} f_{yy} - 2 f_{x} f_{y} \left(f_{xy}\right)^{3} - \left(f_{y}\right)^{2} \left(f_{xx}\right)^{2} f_{yy} + \left(f_{y}\right)^{2} f_{xx} \left(f_{xy}\right)^{2}$$
$$\left(f_{x}\right)^{3} f_{xy} f_{yyy} - \left(f_{x}\right)^{3} f_{yy} f_{xyy} - \left(f_{x}\right)^{2} f_{y} f_{xx} f_{yyy} - \left(f_{x}\right)^{2} f_{y} f_{xy} f_{xyy} + 2 \left(f_{x}\right)^{2} f_{y} f_{yy} f_{xxy} + 2 f_{x} \left(f_{y}\right)^{2} f_{xx} f_{xyy} - f_{x} \left(f_{y}\right)^{2} f_{xy} f_{xxy} - f_{x} \left(f_{y}\right)^{2} f_{yy} f_{xxx} - \left(f_{y}\right)^{3} f_{xx} f_{xxy} + \left(f_{y}\right)^{3} f_{xy} f_{xxx}$$
$$\left(f_{x}\right)^{4} f_{yyyy} - 4 \left(f_{x}\right)^{3} f_{y} f_{xyyy} + 6 \left(f_{x}\right)^{2} \left(f_{y}\right)^{2} f_{xxyy} - 4 f_{x} \left(f_{y}\right)^{3} f_{xxxy} + \left(f_{y}\right)^{4} f_{xxxx}$$
```python
```
Transvectants:
(1) We can use transvectants to create lots of invariants. More than Robert can.
(2) We understand the role of weight and degree, and have a nice graph-based picture for all the invariants up to weight 8
(3) There is no issue with SA(2), but for A(2) the weight 4 invariants have non-removable singularities. There are three possible solutions: (i) claim you only do this on parts of images, (ii) look at the weight 8 invariants instead, particularly I8_1 and I8_3 which do not have f_x in at all, or I4^2/I8, (iii) consider projection as Robert did. Our preference is (ii) but we haven't done it yet.
Moving frame:
(1) We understand it, but it is still ugly
(2) So we just write it as is
Hence:
We can build all the invariants we need now.
We still have a projection issue. And hence a high weight invariant issue. And hence a serious noise problem.
But we probably now have enough for a paper. So we should write it.
|
theory SQRL_2015_nospoof
imports
"../../Primitive_Matchers/Parser"
begin
section\<open>Example: Implementing spoofing protection\<close>
definition "everything_but_private_ips = all_but_those_ips [
(ipv4addr_of_dotdecimal (192,168,0,0), 16),
(ipv4addr_of_dotdecimal (172,16,0,0), 12),
(ipv4addr_of_dotdecimal (10,0,0,0), 8)
]"
definition "ipassmt = [(Iface ''ldit'', [(ipv4addr_of_dotdecimal (10,13,42,136), 29)]),
(Iface ''lmd'', [(ipv4addr_of_dotdecimal (10,13,42,128), 29)]),
(Iface ''loben'', [(ipv4addr_of_dotdecimal (10,13,42,144), 28)]),
(Iface ''wg'', [(ipv4addr_of_dotdecimal (10,13,42,176), 28)]),
(Iface ''wt'', [(ipv4addr_of_dotdecimal (10,13,42,160), 28)]),
(Iface ''lup'', everything_but_private_ips), (*INET*)
(*no protection fo the following interfaces*)
(Iface ''lo'', [(0,0)]),
(Iface ''vpriv'', [(0,0)]),
(Iface ''vshit'', [(0,0)]),
(Iface ''vocb'', [(0,0)]),
(Iface ''lua'', [(0,0)])
]"
lemma "ipassmt_sanity_nowildcards (map_of ipassmt)" by eval
lemma"ipassmt_sanity_complete ipassmt" by eval (* obviously with all these 0/0 ifaces*)
definition "interfaces = (map (iface_sel \<circ> fst) ipassmt)"
lemma "interfaces = [''ldit'', ''lmd'', ''loben'', ''wg'', ''wt'', ''lup'', ''lo'', ''vpriv'', ''vshit'', ''vocb'', ''lua'']" by eval
definition "spoofing_protection fw \<equiv> map (\<lambda>ifce. (ifce, no_spoofing_iface (Iface ifce) (map_of_ipassmt ipassmt) fw)) interfaces"
text\<open>We only consider packets which are @{const CT_New}. Packets which already belong to an established connection are okay be definition.
A very interesting side aspect: In theory, this theory only supports the filter table.
For efficiency, the firewall's administrator implemented the spoofing protection in the raw table's PREROUTING chain.
Because the administrator only used actions which are supported by our semantics, we can apply our theory here.
\<close>
definition "preprocess default_policy fw \<equiv> (upper_closure (ctstate_assume_new (unfold_ruleset_CHAIN ''PREROUTING'' default_policy (map_of_string_ipv4 fw))))"
local_setup \<open>
parse_iptables_save "raw" @{binding raw_fw1} ["2015_aug_iptables-save-spoofing-protection"]
\<close>
thm raw_fw1_def
thm raw_fw1_PREROUTING_default_policy_def
text\<open>sanity check that @{const ipassmt} is complete\<close>
(*This actually caught a typo I made in the ipassmt!*)
lemma "ipassmt_sanity_defined (preprocess raw_fw1_PREROUTING_default_policy raw_fw1) (map_of_ipassmt ipassmt)" by eval
value[code] "debug_ipassmt_ipv4 ipassmt (preprocess raw_fw1_PREROUTING_default_policy raw_fw1)"
text\<open>The administrator wanted to make sure that he will not lock himself out of the firewall.
Hence, we must verify that ssh packets are still accepted by the firewall.
Therefore, we also load the filter table.\<close>
parse_iptables_save filter_fw1="2015_aug_iptables-save-spoofing-protection"
thm filter_fw1_def
(* To verify that we can still access the firewall via ssh, we assume that the ssh rate limiting rule will not drop us.
Therefore, we change this --and only this-- rule:
--A SSHLimit -m recent --update --seconds 60 --hitcount 2 --name SSHA --mask 255.255.255.255 --rsource -j DROP
+-A SSHLimit -m recent --update --seconds 60 --hitcount 2 --name SSHA --mask 255.255.255.255 --rsource -j LOG
*)
value[code] "remdups (collect_ifaces (unfold_ruleset_INPUT filter_fw1_INPUT_default_policy (map_of_string_ipv4 filter_fw1)))"
lemma "ipassmt_sanity_defined (unfold_ruleset_INPUT filter_fw1_INPUT_default_policy (map_of_string_ipv4 filter_fw1)) (map_of_ipassmt ipassmt)" by eval
lemma "ipassmt_sanity_defined (unfold_ruleset_FORWARD filter_fw1_FORWARD_default_policy (map_of_string_ipv4 filter_fw1)) (map_of_ipassmt ipassmt)" by eval
lemma "ipassmt_sanity_defined (unfold_ruleset_OUTPUT filter_fw1_OUTPUT_default_policy (map_of_string_ipv4 filter_fw1)) (map_of_ipassmt ipassmt)" by eval
text\<open>the parsed firewall raw table:\<close>
value[code] "map (\<lambda>(c,rs). (c, map (quote_rewrite \<circ> common_primitive_rule_toString) rs)) raw_fw1"
text\<open>Printing the simplified PREROUTING chain of the raw table:\<close>
value[code] "let x = to_simple_firewall (upper_closure
(unfold_ruleset_CHAIN ''PREROUTING'' raw_fw1_PREROUTING_default_policy (map_of raw_fw1)))
in map simple_rule_ipv4_toString x"
text\<open>First, we check that NEW and ESTABLISHED ssh packets from the Internet are definitely allowed by the firewall:
The packets must be allowed by both the PREROUTING and INPUT chain.
We use @{const in_doubt_deny} to be absolutely sure that these packets will be accepted by the firewall.\<close>
definition "ssh_packet_new = \<lparr>p_iiface = ''lup'', p_oiface = ''anything'',
p_src = ipv4addr_of_dotdecimal (123,123,123,123), p_dst = ipv4addr_of_dotdecimal (131,159,14,9),
p_proto = TCP, p_sport = 12345, p_dport = 22, p_tcp_flags = {TCP_SYN},
p_payload='''', p_tag_ctstate = CT_New\<rparr>"
definition "ssh_packet_established = ssh_packet_new\<lparr>p_tag_ctstate := CT_Established\<rparr>"
text\<open>it is possible to reach the firewall over ssh\<close>
lemma "approximating_bigstep_fun (common_matcher, in_doubt_deny) ssh_packet_new
(unfold_ruleset_CHAIN ''PREROUTING'' raw_fw1_PREROUTING_default_policy (map_of_string_ipv4 raw_fw1)) Undecided
= Decision FinalAllow" by eval
lemma "approximating_bigstep_fun (common_matcher, in_doubt_deny) ssh_packet_established
(unfold_ruleset_CHAIN ''PREROUTING'' raw_fw1_PREROUTING_default_policy (map_of_string_ipv4 raw_fw1)) Undecided
= Decision FinalAllow" by eval
lemma "approximating_bigstep_fun (common_matcher, in_doubt_deny) ssh_packet_new
(unfold_ruleset_INPUT filter_fw1_INPUT_default_policy (map_of_string_ipv4 filter_fw1)) Undecided
= Decision FinalAllow" by eval
lemma "approximating_bigstep_fun (common_matcher, in_doubt_deny) ssh_packet_established
(unfold_ruleset_INPUT filter_fw1_INPUT_default_policy (map_of_string_ipv4 filter_fw1)) Undecided
= Decision FinalAllow" by eval
text\<open>Finally, we show that the PREROUTING chain correctly implements spoofing protection.\<close>
lemma "spoofing_protection (preprocess raw_fw1_PREROUTING_default_policy raw_fw1) =
[(''ldit'', True),
(''lmd'', True),
(''loben'', True),
(''wg'', True),
(''wt'', True),
(''lup'', True),
(''lo'', True),
(''vpriv'', True),
(''vshit'', True),
(''vocb'', True),
(''lua'', True)]" by eval
end
|
module ListNat where
data Nat : Set where
zero : Nat
succ : Nat -> Nat
data List (a : Set) : Set where
[] : List a
_::_ : a -> List a -> List a
infixr 30 _::_
[1,0,2] = one :: zero :: succ one :: []
where one = succ zero
|
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Data.List
import Data.Bits
import qualified Data.Set as S
import qualified Data.Map.Strict as M
import qualified Data.Map.Lazy as LM
import Text.Printf
import Numeric.LinearAlgebra hiding (find, (<>))
import Data.Functor
import Options.Applicative
import Control.Monad
import Data.Monoid
import Data.Function
import Debug.Trace
-- no warning about Debug.Trace please
_trace = trace
type Width = Int
type Mealy a b = [(a, ((a, [b]), (a, [b])))]
data L = S | M deriving (Eq, Ord, Enum, Bounded)
instance Show L where
showsPrec _ S = ('S':)
showsPrec _ M = ('M':)
showList [] = ('·':)
showList xs = foldr ((.) . shows) id xs
buildMealyRTL :: Width -> Mealy Int L
buildMealyRTL 1 = [ (0, ((0, [S]), (0, [M]))) ]
buildMealyRTL w =
[ (0, ((0, [S]), (1, [M]))) ] ++
[ (i, ((j, [S]), (j, [S]))) | i <- [1..w-1] , let j = (i+1) `mod` w]
buildMealy :: Width -> Mealy Int L
buildMealy 1 = [ (0, ((0, [S]), (0,[M]))) ]
buildMealy w = [ (n, edges n) | n <- [0..2^(w-1)-1] ]
where
-- The root
edges 0 = ( (0, [S]), (1, []) )
-- The intermediate nodes (scanning until the end of the window)
edges n | n < 2^(w-2) = ( (2*n, []), (2*n+1, []) )
-- The last bit of the window, we can output the leak
edges n = ( (0, output (2*n)), (0, output (2*n+1)) )
output n = replicate (w - lastbit - 1) S ++ [M] ++ replicate lastbit S
where Just lastbit = find (\i -> n `testBit` i) [0..]
-- | This function reduces the number of nodes by commoning up
-- equivalent nodes. Needs to be iterated.
reduceMealyOnce :: (Ord a, Ord b) => Mealy a b -> Mealy a b
reduceMealyOnce m
= [ (n, ((f n0,s0), (f n1,s1)))
| (n, ((n0,s0), (n1,s1))) <- m
, f n == n
]
where
f = (M.!) $
M.fromList
[ (x, head dup)
| dupSet <- M.elems $ M.fromListWith S.union [ (e,S.singleton n) | (n,e) <- m ]
, let dup = S.toList dupSet
, x <- dup
]
reduceMealy :: (Ord a, Ord b) => Mealy a b -> Mealy a b
reduceMealy m | length m == length m' = m
| otherwise = reduceMealy m'
where m' = reduceMealyOnce m
mealy2dot :: (Show a, Show b) => Mealy a b -> String
mealy2dot nodes = unlines $
[ "digraph {" ] ++
[ printf "%s -> %s [label=\"0/%s\"];\n" (show n) (show n0) (show s0) ++
printf "%s -> %s [label=\"1/%s\"];" (show n) (show n1) (show s1)
| (n, ((n0, s0), (n1,s1))) <- nodes ] ++
[ "}" ]
type Markov a = [(a, [a])]
buildMarkov :: (Ord a, Ord b) => (a,[b]) -> Mealy a b -> Markov (a,[b])
buildMarkov start mealy = go (S.singleton start) S.empty []
where
go todo done
| S.null todo = id
| (node,text) `S.member` done = go todo' done
| otherwise = (((node,text), [n0', n1']):) .
go todo'' (S.insert (node,text) done)
where
((node,text), todo') = S.deleteFindMin todo
Just ((n0, s0), (n1, s1)) = lookup node mealy
n0' = (n0, tail text ++ s0)
n1' = (n1, tail text ++ s1)
todo'' = S.insert n0' (S.insert n1' todo')
markov2dot :: (a -> String) -> (a -> String) -> Markov a -> String
markov2dot col s nodes = unlines $
[ "digraph {"
-- , "layout = neato;"
, "margin = 0;"
, "epsilon = 0.0001;"
, "splines=true;"
-- , "edge [len = 0.8];"
, "edge [len = 1.3];"
, "node [width=0.2];"
, "node [height=0.2];"
, "node [style=filled];"
] ++
[ printf "%s [ color=%s]" (s n) (col n)
| (n, _) <- nodes ] ++
[ printf "%s -> %s;\n" (s n) (s n')
| (n, succs) <- nodes , n' <- succs] ++
[ "}" ]
type Dist a = M.Map a Double
stationary :: Ord a => Markov a -> Dist a
stationary = stationaryCond (const True)
findMaxIndex f xs = snd (maximum (zip (map f xs) [0..]))
stationaryCond :: Ord a => (a -> Bool) -> Markov a -> Dist a
stationaryCond nonDead markov
-- | not ok1 = error "First eigenvalue not 1"
| not ok2 = error "Eigenvector does not consist of probabilities"
-- | not ok3 = error "Eigenvector does not have eigenvalue 1"
| otherwise = M.fromList $ zip (map fst markov) (toList evec)
where
n = length markov
transMatrix :: Matrix Double
transMatrix = (n >< n) $
[ if nonDead n then sum [ p | n' <- e, n' == n0 ] else 0
| (n,e) <- markov
, (n0,_) <- markov
, let p = 1/fromIntegral (length e)
]
(evals, evecs) = eig (tr transMatrix)
-- Just i = findIndex isOne (toList evals)
i = findMaxIndex realPart (toList evals)
eval = evals `atIndex` i
evecC = toColumns evecs !! i
evecNorm = scale (1/sum (toList evecC)) evecC
evec = cmap realPart evecNorm
isOne c = magnitude (c - 1) < 0.0000001
isProb c = abs (imagPart c) < 0.0000001 && realPart c >= 0 && realPart c <= 1
ok1 = magnitude (eval - 1) < 0.001
ok2 = all isProb (toList evecNorm)
ok3 = norm_2 (evec - (evec <# transMatrix)) < 0.001
prodMarkov :: Markov a -> Markov (a,a)
prodMarkov markov =
[ ((n1,n2), (,) <$> e1 <*> e2)
| (n1, e1) <- markov
, (n2, e2) <- markov
]
filterMarkov :: (a -> Bool) -> Markov a -> Markov (Maybe a)
filterMarkov p markov =
(Nothing, [Nothing]) : [ (Just n, map (justIf p) e) | (n, e) <- markov, p n ]
justIf p n = if p n then Just n else Nothing
-- Removes all edges from nodes where p does not hold, and all nodes
-- not reachable
deadEnd :: Ord a => (a -> Bool) -> a -> Markov a -> Markov a
deadEnd p start markov = go S.empty [start]
where
edges = (M.fromList markov M.!)
go done [] = []
go done (x:todo) | x `elem` done = go done todo
| otherwise = (x, e) : go (S.insert x done) todo'
where e = edges x
todo' | p x = e ++ todo
| otherwise = todo
liveNodes :: Ord a => a -> Markov a -> S.Set a
liveNodes start markov = go (S.singleton start)
where
edges = (M.fromList markov M.!)
go live | S.size live == S.size live' = live
| otherwise = go live'
where live' = live `S.union` S.fromList [ n | (n,e) <- markov, any (`S.member` live) e ]
-- | This function reduces the number of nodes by commoning up
-- equivalent nodes. Needs to be iterated.
reduceMarkovOnce :: (Ord a, Ord b) => (a -> b) -> Markov a -> Markov a
reduceMarkovOnce l m
= [ (n, map f e) | (n, e) <- m, f n == n ]
where
f = (M.!) $
M.fromList
[ (x, head dup)
| dupSet <- M.elems $ M.fromListWith S.union [ ((l n,sort e),S.singleton n) | (n,e) <- m ]
, let dup = S.toList dupSet
, x <- dup
]
reduceMarkov :: (Ord a, Ord b) => (a -> b) -> Markov a -> Markov a
reduceMarkov leak m | length m == length m' = m
| otherwise = reduceMarkov leak m'
where m' = reduceMarkovOnce leak m
-- If two independent copies of the markov chain, starting in the given
-- distribution are run n steps, what is the probability that the output is the
-- same?
sampleCollisions :: forall a b. (Ord a, Eq b) => Int -> (a -> b) -> Markov a -> Dist a -> Double
sampleCollisions n f markov dist =
sum [ p * fromIntegral (countCollisions n n1 n2)
| ((n1, n2),p) <- M.toList $ prodDist dist
] / 2^(2*n)
where
edges = (M.fromList markov M.!)
-- From these two states on for further n steps, how many collisions?
countCollisions :: Int -> a -> a -> Integer
countCollisions 0 _ _ = 1
countCollisions i n1 n2
| f n1 == f n2 = sum [ countMemo (i-1) (n1', n2')
| n1' <- edges n1
, n2' <- edges n2
]
| otherwise = 0
-- Yay, memoization!
countMemo = curry (LM.fromList [ ((i,(n1,n2)), countCollisions i n1 n2) | i <- [0..n], n1 <- map fst markov, n2 <- map fst markov] M.!)
-- A typical output function
leak :: (a,[b]) -> b
leak (_,s) = head s
colorNode :: (a,[L]) -> String
colorNode s = if leak s == S then "lightblue" else "green1"
showNode :: (Show a, Show b) => (a,[b]) -> String
showNode (node,s) = show s ++ show node
showNode2 :: (Show a, Show b) => ((a,[b]),(a,[b])) -> String
showNode2 (n1,n2) = showNode n1 ++ "_" ++ showNode n2
calcPnl :: forall a b. (Ord a, Ord b) => Int -> (a -> b) -> Markov a -> Dist a -> Dist (a, [b])
calcPnl n f markov dist = jointDist dist $ \x1 -> normDist $ leakDist n x1
where
edges = (M.fromList markov M.!)
-- Calculate the distribution of leaks
-- (of the given length, starting in the given node)
-- This is the performance hot spot in this program! (until I introduce memoization)
leakDist :: Int -> a -> Dist [b]
leakDist 0 _ = M.singleton [] 1
leakDist i node = M.mapKeysMonotonic (f node :) $ addDists $
[ leakDistMemo (i-1) n' | n' <- edges node ]
-- Yay, memoization!
leakDistMemo = curry (LM.fromList [ ((i,node), leakDist i node) | i <- [0..n], node <- map fst markov ] M.!)
calcPl :: forall a b. (Ord a, Ord b) => Int -> (a -> b) -> Markov a -> Dist a -> Dist [b]
calcPl n f markov dist =
addDists [ fmap (p*) (normDist $ leakDist n x1) | (x1, p) <- M.toList dist ]
where
edges = (M.fromList markov M.!)
-- Calculate the distribution of leaks
-- (of the given length, starting in the given node)
-- This is the performance hot spot in this program! (until I introduce memoization)
leakDist :: Int -> a -> Dist [b]
leakDist 0 _ = M.singleton [] 1
leakDist i node = M.mapKeysMonotonic (f node :) $ addDists $
[ leakDistMemo (i-1) n' | n' <- edges node ]
-- Yay, memoization!
leakDistMemo = curry (LM.fromList [ ((i,node), leakDist i node) | i <- [0..n], node <- map fst markov ] M.!)
condEntropyLB :: (Ord a, Ord b) => Dist (a, [b]) -> Dist (a, [b]) -> Double
condEntropyLB pnl pnlbar = sum
[ pxy * logb (px/pxy)
| ((xi,ys),pxy) <- M.toList pnl
, let px = pnlbar M.! (xi, init ys)
]
condEntropyUB :: Ord b => Dist [b] -> Dist [b] -> Double
condEntropyUB pl plbar = sum
[ pxy * logb (px/pxy)
| (ys,pxy) <- M.toList pl
, let px = plbar M.! init ys
]
markovStepProb :: Ord a => (a -> Bool) -> Markov a -> Dist a -> Double
markovStepProb p markov dist = sum
[ pn * sum [ 1 | n' <- e, p n'] / fromIntegral (length e)
| (n,pn) <- M.toList dist
, let e = edges n
]
where
edges = (M.fromList markov M.!)
logb :: Double -> Double
logb = logBase 2
samplesToDist :: Ord a => [a] -> Dist a
samplesToDist xs = normDist $ M.fromListWith (+) [ (x,1) | x <- xs ]
-- | Take the union of two distributions (not normalised)
addDist :: Ord a => Dist a -> Dist a -> Dist a
addDist = M.unionWith (+)
addDists :: Ord a => [Dist a]-> Dist a
addDists = M.unionsWith (+)
mapDist :: Ord b => (a -> b) -> Dist a -> Dist b
mapDist = M.mapKeysWith (+)
normDist :: M.Map a Double -> M.Map a Double
normDist m = fmap (/sum m) m
jointDist :: (Ord a, Ord b) => Dist a -> (a -> Dist b) -> Dist (a,b)
jointDist d1 f = M.unionsWith (error "Not disjoint") $
[ M.mapKeysMonotonic (a,) $ fmap (p_a*) (f a)
| (a, p_a) <- M.toList d1
]
prodDist :: Ord a => Dist a -> Dist (a,a)
prodDist d = M.fromListWith (error "input wrong") $
[ ((x,y), px * py) | (x,px) <- M.toList d, (y,py) <- M.toList d ]
samplePred :: (a -> Bool) -> Dist a -> Double
samplePred ok d = sum [ p | (x,p) <- M.toList d, ok x ]
conditionalDist :: Ord a => Dist (Maybe a) -> Dist a
conditionalDist d = normDist $ M.fromListWith (error "input wrong") $
[ (n, p) | (Just n, p) <- M.toList d ]
data WhichGraph = RTL | LTR deriving Eq
data WhatToDo = PrintMealy
| PrintMarkov
| PrintCollMarkov
| PrintEntropy
| PrintTableRow
| PrintColl
deriving Eq
run :: Int -> Int -> WhichGraph -> WhatToDo -> IO ()
run w n which todo = do
let my = case which of
RTL -> reduceMealy $ buildMealyRTL w
LTR -> reduceMealy $ buildMealy w
let n0 = (0, replicate w S)
let mv = buildMarkov n0 my
let sd = stationary mv
let singletonDist = M.singleton n0 1
let ud = M.fromList mv $> ((1::Double) / fromIntegral (length mv))
let pnl = calcPnl n leak mv sd
let pnlbar = calcPnl (n-1) leak mv sd
let eLB = condEntropyLB pnl pnlbar
let pl = calcPl n leak mv sd
let plbar = calcPl (n-1) leak mv sd
let eUB = condEntropyUB pl plbar
let prodMv = prodMarkov mv
let thinProdMV = reduceMarkov (\(n1,n2) -> leak n1 == leak n2) prodMv
-- ^ This is just to feed less data to the linear algrebra system
let collSD = stationaryCond (\(n1,n2) -> leak n1 == leak n2) thinProdMV
let collP = samplePred (\(n1,n2) -> leak n1 == leak n2) collSD
let collRate = - logb collP
let simCollP = sampleCollisions n leak mv sd -- singletonDist
let simCollisions = simCollP^(2::Int) * 2^n
let simCollRate = - (logb simCollP) / fromIntegral n
case todo of
PrintMealy -> putStrLn (mealy2dot my)
PrintMarkov -> putStrLn (markov2dot colorNode showNode mv)
PrintCollMarkov -> error "unimplemented" -- putStrLn (markov2dot showNode2 collidingMv)
PrintTableRow -> printf "%d\t%d\t%f\t%f\t%f\n" w n eLB eUB collRate
PrintColl -> error "unimplemented" -- print collisions
PrintEntropy -> printf "w: %2d. n: %3d. %.4f ≤ H(Y) ≤ %.4f. coll rate: %.4f. sim coll rate: %.4f \n"
w n eLB eUB collRate simCollRate
main :: IO ()
main = join . execParser $
info (helper <*> parser)
( fullDesc
<> header "Entropy calculation"
)
where
parser :: Parser (IO ())
parser = run
<$> option auto
( long "width"
<> short 'w'
<> metavar "WIDTH"
<> help "Width of the window (typical 4 or 5)"
<> value 4
<> showDefault
)
<*> option auto
( long "n"
<> short 'n'
<> metavar "N"
<> help "approximation"
<> value 10
<> showDefault
)
<*> choice
[ flag' LTR (long "ltr" <> help "Analyse left-to-right")
, flag' RTL (long "rtl" <> help "Analyse right-to-left")
, pure LTR
]
<*> choice
[ flag' PrintMealy (long "mealy" <> help "Print Mealy graph in .dot format")
, flag' PrintMarkov (long "markov" <> help "Print Markov graph in .dot format")
, flag' PrintCollMarkov (long "colliding-markov" <> help "Print colliding Markov graph in .dot format")
, flag' PrintTableRow (long "table" <> help "Print a tsv table row")
, flag' PrintColl (long "coll" <> help "Print collision probability tsv row")
, pure PrintEntropy
]
choice :: Alternative f => [f a] -> f a
choice = foldr1 (<|>)
|
import Data.Vect
append_nil : Vect m elem -> Vect (plus m 0) elem
append_nil xs = rewrite plusZeroRightNeutral m in xs
append_xs : Vect (S (m + len)) elem -> Vect (m + (S len)) elem
append_xs xs = rewrite sym (plusSuccRightSucc m len) in xs
-- by "carelessly" changing `n + m` to `m + n` we need use a few rewrites
-- to prove to idris that the definition is valid
append : Vect n elem -> Vect m elem -> Vect (m + n) elem
append [] ys = append_nil ys
append (x :: xs) ys = append_xs (x :: append xs ys)
|
module E2ga
import Base.show, Base.+, Base.-, Base.*
export Geometric2
struct Geometric2{T <: Real}
α::T
x::T
y::T
β::T
end
Geometric2(α::Real, x::Real, y::Real, β::Real) = Geometric2(promote(α, x, y, β)...)
Geometric2(α::Real) = Geometric2(α, zero(α), zero(α), zero(α))
promote_rule(::Type{Geometric2{T}}, ::Type{S}) where {T <: Real,S <: Real} = Geometric2{promote_type(T, S)}
promote_rule(::Type{Geometric2{T}}, ::Type{Geometric2{S}}) where {T <: Real,S <: Real} = Geometric2{promote_type(T, S)}
function +(a::Geometric2, b::Geometric2)
α = a.α + b.α
x = a.x + b.x
y = a.y + b.y
β = a.β + b.β
return Geometric2(α, x, y, β)
end
function -(a::Geometric2, b::Geometric2)
α = a.α - b.α
x = a.x - b.x
y = a.y - b.y
β = a.β - b.β
return Geometric2(α, x, y, β)
end
function *(a::Geometric2, b::Geometric2)
α = a.α * b.α + a.x * b.x + a.y * b.y - a.β * b.β
x = a.α * b.x + a.x * b.α - a.y * b.β + a.β * b.y
y = a.α * b.y + a.x * b.β + a.y * b.α - a.β * b.x
β = a.α * b.β + a.x * b.y - a.y * b.x + a.β * b.α
return Geometric2(α, x, y, β)
end
function show(io::IO, m::Geometric2)
print(io, "$(m.α) + $(m.x)e1 + $(m.y)e2 + $(m.β)I")
end
end
|
State Before: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q p : R[X]
⊢ 0 /ₘ p = 0 State After: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q p : R[X]
⊢ (if h : Monic p then
(if h_1 : degree p ≤ degree 0 ∧ 0 ≠ 0 then
let z := ↑C (leadingCoeff 0) * X ^ (natDegree 0 - natDegree p);
let_fun _wf := (_ : degree (0 - ↑C (leadingCoeff 0) * X ^ (natDegree 0 - natDegree p) * p) < degree 0);
let dm := divModByMonicAux (0 - z * p) (_ : Monic p);
(z + dm.fst, dm.snd)
else (0, 0)).fst
else 0) =
0 Tactic: unfold divByMonic divModByMonicAux State Before: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q p : R[X]
⊢ (if h : Monic p then
(if h_1 : degree p ≤ degree 0 ∧ 0 ≠ 0 then
let z := ↑C (leadingCoeff 0) * X ^ (natDegree 0 - natDegree p);
let_fun _wf := (_ : degree (0 - ↑C (leadingCoeff 0) * X ^ (natDegree 0 - natDegree p) * p) < degree 0);
let dm := divModByMonicAux (0 - z * p) (_ : Monic p);
(z + dm.fst, dm.snd)
else (0, 0)).fst
else 0) =
0 State After: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q p : R[X]
⊢ (if h : Monic p then
(if degree p ≤ ⊥ ∧ ¬0 = 0 then
(↑C 0 * X ^ (0 - natDegree p) + (divModByMonicAux (0 - ↑C 0 * X ^ (0 - natDegree p) * p) (_ : Monic p)).fst,
(divModByMonicAux (0 - ↑C 0 * X ^ (0 - natDegree p) * p) (_ : Monic p)).snd)
else (0, 0)).fst
else 0) =
0 Tactic: dsimp State Before: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q p : R[X]
⊢ (if h : Monic p then
(if degree p ≤ ⊥ ∧ ¬0 = 0 then
(↑C 0 * X ^ (0 - natDegree p) + (divModByMonicAux (0 - ↑C 0 * X ^ (0 - natDegree p) * p) (_ : Monic p)).fst,
(divModByMonicAux (0 - ↑C 0 * X ^ (0 - natDegree p) * p) (_ : Monic p)).snd)
else (0, 0)).fst
else 0) =
0 State After: case pos
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q p : R[X]
hp : Monic p
⊢ (if h : Monic p then
(if degree p ≤ ⊥ ∧ ¬0 = 0 then
(↑C 0 * X ^ (0 - natDegree p) + (divModByMonicAux (0 - ↑C 0 * X ^ (0 - natDegree p) * p) (_ : Monic p)).fst,
(divModByMonicAux (0 - ↑C 0 * X ^ (0 - natDegree p) * p) (_ : Monic p)).snd)
else (0, 0)).fst
else 0) =
0
case neg
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q p : R[X]
hp : ¬Monic p
⊢ (if h : Monic p then
(if degree p ≤ ⊥ ∧ ¬0 = 0 then
(↑C 0 * X ^ (0 - natDegree p) + (divModByMonicAux (0 - ↑C 0 * X ^ (0 - natDegree p) * p) (_ : Monic p)).fst,
(divModByMonicAux (0 - ↑C 0 * X ^ (0 - natDegree p) * p) (_ : Monic p)).snd)
else (0, 0)).fst
else 0) =
0 Tactic: by_cases hp : Monic p State Before: case pos
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q p : R[X]
hp : Monic p
⊢ (if h : Monic p then
(if degree p ≤ ⊥ ∧ ¬0 = 0 then
(↑C 0 * X ^ (0 - natDegree p) + (divModByMonicAux (0 - ↑C 0 * X ^ (0 - natDegree p) * p) (_ : Monic p)).fst,
(divModByMonicAux (0 - ↑C 0 * X ^ (0 - natDegree p) * p) (_ : Monic p)).snd)
else (0, 0)).fst
else 0) =
0 State After: no goals Tactic: rw [dif_pos hp, if_neg (mt And.right (not_not_intro rfl))] State Before: case neg
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q p : R[X]
hp : ¬Monic p
⊢ (if h : Monic p then
(if degree p ≤ ⊥ ∧ ¬0 = 0 then
(↑C 0 * X ^ (0 - natDegree p) + (divModByMonicAux (0 - ↑C 0 * X ^ (0 - natDegree p) * p) (_ : Monic p)).fst,
(divModByMonicAux (0 - ↑C 0 * X ^ (0 - natDegree p) * p) (_ : Monic p)).snd)
else (0, 0)).fst
else 0) =
0 State After: no goals Tactic: rw [dif_neg hp]
|
function [Jul1,Jul2]=TT2TDB(Jul1,Jul2,deltaTTUT1,clockLoc)
%%TT2TDB Convert from terrestrial time (TT) to barycentric dynamical time
% (TDB) to an accuracy of nanoseconds (if deltaT is accurate)
% using the routines from the International Astronomical Union's
% library that do not require external ephemeris data.
%
%INPUTS: Jul1,Jul2 Two parts of a Julian date given in TT. The units of
% the date are days. The full date is the sum of both
% terms. The date is broken into two parts to provide
% more bits of precision. It does not matter how the date
% is split.
% deltaTTUT1 An optional parameter specifying the offset between TT
% and UT1 in seconds. If this parameter is omitted or an
% empty matrix is passed, then the value of the function
% getEOP will be used.
% clockLoc An optional 3X1 vector specifying the location of the
% clock in the Terrestrial Intermediate Reference System
% (TIRS), though it would not make much of a difference
% if the International Terrestrial Reference System
% (ITRS) were used. The units are meters. Due to
% relativistic effects, clocks that are synchronized with
% respect to TT are not synchronized with respect to TDB.
% If this parameter is omitted, then a clock at the
% center of the Earth is used.
%
%OUTPUTS:Jul1,Jul2 Two parts of a Julian date given in TDB.
%
%This function relies on a number of functions in the International
%Astronomical Union's Standards of Fundamental Astronomy library. The
%implementation is essentially the same as TT2TCB except a final
%conversion step is omitted.
%
%The algorithm can be compiled for use in Matlab using the
%CompileCLibraries function.
%
%The algorithm is run in Matlab using the command format
%[Jul1,Jul2]=TT2TDB(Jul1,Jul2,deltaTTUT1,clockLoc);
%or
%[Jul1,Jul2]=TT2TDB(Jul1,Jul2);
%
%Many temporal coordinate systems standards are compared in [1].
%
%REFERENCES:
%[1] D. F. Crouse, "An Overview of Major Terrestrial, Celestial, and
% Temporal Coordinate Systems for Target Tracking," Formal Report,
% Naval Research Laboratory, no. NRL/FR/5344--16-10,279, 10 Aug. 2016,
% 173 pages.
%
%March 2014 David F. Crouse, Naval Research Laboratory, Washington D.C.
%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.
error('This function is only implemented as a mexed C or C++ function. Please run CompileCLibraries.m to compile the function for use.')
end
%LICENSE:
%
%The source code is in the public domain and not licensed or under
%copyright. The information and software may be used freely by the public.
%As required by 17 U.S.C. 403, third parties producing copyrighted works
%consisting predominantly of the material produced by U.S. government
%agencies must provide notice with such work(s) identifying the U.S.
%Government material incorporated and stating that such material is not
%subject to copyright protection.
%
%Derived works shall not identify themselves in a manner that implies an
%endorsement by or an affiliation with the Naval Research Laboratory.
%
%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE
%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL
%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS
%OF RECIPIENT IN THE USE OF THE SOFTWARE.
|
The issue of synonyms is complicated by the type specimen of Allosaurus fragillis ( catalogue number YPM 1930 ) being extremely fragmentary , consisting of a few incomplete vertebrae , limb bone fragments , rib fragments , and a tooth . Because of this , several scientists have noted that the type specimen , and thus the genus Allosaurus itself or at least the species A. fragillis , is technically a nomen dubium ( " dubious name " , based on a specimen too incomplete to compare to other specimens or to classify ) . In an attempt to fix this situation , Gregory S. Paul and Kenneth Carpenter ( 2010 ) submitted a petition to the ICZN to have the name A. fragillis officially transferred to the more complete specimen <unk> ( as a neotype ) . This request is currently pending review .
|
//
// ePDF
//
#pragma once
#include "ePDF/ndistributions.h"
#include <yaml-cpp/yaml.h>
#include <complex>
#include <vector>
#include <memory>
#include <gsl/gsl_integration.h>
#include <functional>
namespace ePDF
{
/**
* @brief The "evol_params" structure contains the evolution
* parameters.
*/
struct evol_params
{
double x;
double Q;
int id;
std::shared_ptr<NDistributions> Ndist;
evol_params operator = (evol_params const& p)
{
x = p.x;
Q = p.Q;
id = p.id;
Ndist = p.Ndist;
return *this;
}
};
/**
* @brief The "xDistribution" class
*/
class xDistributions
{
public:
/**
* @brief The "xDistribution" constructor.
* @param config: the YAML:Node with the parameters
*/
xDistributions(YAML::Node const& config);
/**
* @brief The "xDistribution" destructor.
*/
~xDistributions();
/**
* @brief Function that returns the PDFs in x space.
* @param x: Bjorken x
* @param Q: the final scale
*/
std::vector<double> Evolve(double const& x, double const& Q);
/**
* @brief Interfaces to the integrand functions according to the
* path chosen to perform the inverse Mellin transform.
*/
std::vector<double> integrand(double const& y) const;
std::vector<double> talbot(double const& y) const;
std::vector<double> straight(double const& y) const;
/**
* @brief Integrators functions
*/
std::vector<double> trapezoid(double const& a, double const& b) const;
std::vector<double> gauss(double const& a, double const& b) const;
std::vector<double> gaussGSL(double const& a, double const& b);
/**
* @brief Function that returns the N-th (complex) moment of PDFs.
* @param N: moment
* @param Q: the final scale
*/
std::vector<std::complex<double>> Moments(std::complex<double> const& N, double const& Q) const;
/**
* @brief Function that sets the parameter structure externally
* @param p: the input structure
*/
void SetParameters(evol_params const& p) { _p = p; };
private:
std::string const _contour;
std::string const _integrator;
double const _eps;
evol_params _p;
gsl_integration_workspace *_w;
};
}
|
(* Title: HOL/Auth/n_german_lemma_on_inv__9.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_on_inv__9 imports n_german_base
begin
section{*All lemmas on causal relation between inv__9 and some rule r*}
lemma n_StoreVsinv__9:
assumes a1: "(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__9 p__Inv2)"
shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s")
proof -
from a1 obtain i d where a1:"i\<le>N\<and>d\<le>N\<and>r=n_Store i d" apply fastforce done
from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__9 p__Inv2" apply fastforce done
have "(i=p__Inv2)\<or>(i~=p__Inv2)\<or>(i~=p__Inv2)\<or>(i=p__Inv2)\<or>(i~=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(i=p__Inv2)"
have "?P3 s"
apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv2) ''Cmd'')) (Const InvAck)) (eqn (IVar (Field (Para (Ident ''Cache'') p__Inv2) ''State'')) (Const E))))" in exI, auto) done
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv2)"
have "?P3 s"
apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv2) ''Cmd'')) (Const InvAck)) (eqn (IVar (Field (Para (Ident ''Cache'') i) ''State'')) (Const E))))" in exI, auto) done
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv2)"
have "?P3 s"
apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv2) ''Cmd'')) (Const InvAck)) (eqn (IVar (Field (Para (Ident ''Cache'') i) ''State'')) (Const E))))" in exI, auto) done
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i=p__Inv2)"
have "?P3 s"
apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv2) ''Cmd'')) (Const InvAck)) (eqn (IVar (Field (Para (Ident ''Cache'') p__Inv2) ''State'')) (Const E))))" in exI, auto) done
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv2)"
have "?P3 s"
apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv2) ''Cmd'')) (Const InvAck)) (eqn (IVar (Field (Para (Ident ''Cache'') i) ''State'')) (Const E))))" in exI, auto) done
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv2)"
have "?P3 s"
apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv2) ''Cmd'')) (Const InvAck)) (eqn (IVar (Field (Para (Ident ''Cache'') i) ''State'')) (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
lemma n_SendInvAckVsinv__9:
assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__9 p__Inv2)"
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_SendInvAck i" apply fastforce done
from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__9 p__Inv2" apply fastforce done
have "(i=p__Inv2)\<or>(i~=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(i=p__Inv2)"
have "((formEval (eqn (IVar (Field (Para (Ident ''Cache'') p__Inv2) ''State'')) (Const E)) s))\<or>((formEval (neg (eqn (IVar (Field (Para (Ident ''Cache'') p__Inv2) ''State'')) (Const E))) s))" by auto
moreover {
assume c1: "((formEval (eqn (IVar (Field (Para (Ident ''Cache'') p__Inv2) ''State'')) (Const E)) s))"
have "?P3 s"
apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Chan2'') p__Inv2) ''Cmd'')) (Const Inv)) (neg (eqn (IVar (Field (Para (Ident ''Cache'') p__Inv2) ''Data'')) (IVar (Ident ''AuxData''))))))" in exI, auto) done
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume c1: "((formEval (neg (eqn (IVar (Field (Para (Ident ''Cache'') p__Inv2) ''State'')) (Const E))) s))"
have "?P3 s"
apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (andForm (andForm (eqn (IVar (Field (Para (Ident ''Chan2'') p__Inv2) ''Cmd'')) (Const Inv)) (neg (eqn (IVar (Field (Para (Ident ''Cache'') p__Inv2) ''State'')) (Const E)))) (eqn (IVar (Ident ''ExGntd'')) (Const true))))" in exI, auto) done
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately have "invHoldForRule s f r (invariants N)" by satx
}
moreover {
assume b1: "(i~=p__Inv2)"
have "?P2 s"
proof(cut_tac a1 a2 b1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv2)"
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_RecvInvAckVsinv__9:
assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__9 p__Inv2)"
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_RecvInvAck i" apply fastforce done
from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__9 p__Inv2" apply fastforce done
have "(i=p__Inv2)\<or>(i~=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(i=p__Inv2)"
have "((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\<or>((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))" by auto
moreover {
assume c1: "((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))"
have "?P1 s"
proof(cut_tac a1 a2 b1 c1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume c1: "((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))"
have "?P1 s"
proof(cut_tac a1 a2 b1 c1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately have "invHoldForRule s f r (invariants N)" by satx
}
moreover {
assume b1: "(i~=p__Inv2)"
have "((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\<or>((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))" by auto
moreover {
assume c1: "((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))"
have "?P1 s"
proof(cut_tac a1 a2 b1 c1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume c1: "((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))"
have "?P2 s"
proof(cut_tac a1 a2 b1 c1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately have "invHoldForRule s f r (invariants N)" by satx
}
moreover {
assume b1: "(i~=p__Inv2)"
have "((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\<or>((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))" by auto
moreover {
assume c1: "((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))"
have "?P1 s"
proof(cut_tac a1 a2 b1 c1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume c1: "((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))"
have "?P2 s"
proof(cut_tac a1 a2 b1 c1, auto) qed
then have "invHoldForRule s f r (invariants N)" by auto
}
ultimately have "invHoldForRule s f r (invariants N)" by satx
}
ultimately show "invHoldForRule s f r (invariants N)" by satx
qed
lemma n_SendGntEVsinv__9:
assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendGntE N i)" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__9 p__Inv2)"
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_SendGntE N i" apply fastforce done
from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__9 p__Inv2" apply fastforce done
have "(i=p__Inv2)\<or>(i~=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done
moreover {
assume b1: "(i=p__Inv2)"
have "?P3 s"
apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const false)) (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv2) ''Cmd'')) (Const InvAck))))" in exI, auto) done
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv2)"
have "?P3 s"
apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const false)) (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv2) ''Cmd'')) (Const InvAck))))" in exI, auto) done
then have "invHoldForRule s f r (invariants N)" by auto
}
moreover {
assume b1: "(i~=p__Inv2)"
have "?P3 s"
apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const false)) (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv2) ''Cmd'')) (Const InvAck))))" 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
lemma n_SendReqE__part__1Vsinv__9:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__9 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_RecvGntSVsinv__9:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvGntS i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__9 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_SendGntSVsinv__9:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendGntS i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__9 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_RecvReqEVsinv__9:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvReqE N i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__9 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_RecvGntEVsinv__9:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvGntE i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__9 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_SendInv__part__0Vsinv__9:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__9 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_SendReqE__part__0Vsinv__9:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__9 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_SendInv__part__1Vsinv__9:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__9 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_SendReqSVsinv__9:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqS i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__9 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
lemma n_RecvReqSVsinv__9:
assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvReqS N i" and
a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__9 p__Inv2)"
shows "invHoldForRule s f r (invariants N)"
apply (rule noEffectOnRule, cut_tac a1 a2, auto) done
end
|
(* Copyright (c) 2022, choukh <[email protected]> *)
Require Import GOO.Ordinal.Ord.
Require Import GOO.Ordinal.WellFormed.
Require Import GOO.Ordinal.Operation.
Require Import GOO.Ordinal.Recursion.
Require Import GOO.Ordinal.Arithmetic.
Local Open Scope 序数域.
Local Open Scope 序数算术域.
Definition 左迭代 α β := 递归 (幂运算 α) α β.
Notation "α ^^ᴸ β" := (左迭代 α β) (at level 25) : 序数算术域.
Lemma 左迭代零次 : ∀ α, α ^^ᴸ [0] = α.
Proof. easy. Qed.
Lemma 左迭代后继次 : ∀ α β, α ^^ᴸ β⁺ = α ^ (α ^^ᴸ β).
Proof. easy. Qed.
Lemma 左迭代极限次 : ∀ α f, α ^^ᴸ lim f = lim (λ n, α ^^ᴸ f n).
Proof. easy. Qed.
Lemma 左迭代_弱保序_右 : ∀ α, [1] < α → 弱保序 (左迭代 α).
Proof.
intros α H1 β γ H. apply 递归_弱保序_右.
intros. apply 幂运算_弱放大_左. apply H1.
apply 幂运算_弱保序_右. apply 诉诸强序. apply H1. apply H.
Qed.
Lemma 左迭代在ω后继处不递增 : ∀ α, [1] < α → α ^^ᴸ ω⁺ ≃ α ^^ᴸ ω.
Proof.
intros. unfold ω. rewrite 左迭代后继次, 左迭代极限次, 极限次幂.
split; constructor; intros n.
- apply 弱序_极限_介入 with (S n). simpl. rewrite 左迭代后继次. reflexivity.
- eapply 弱序_极限_介入. apply 幂运算_弱放大_左. apply H.
Qed.
Theorem 左迭代在ω次之后不变 : ∀ α β, [1] < α → 良构 β → ω ≤ β → α ^^ᴸ β ≃ α ^^ᴸ ω.
Proof with auto.
intros α β H1 WF Inf. induction β as [|β IH|f IH].
- exfalso. apply 弱序_反转 in Inf...
- split. 2: apply 左迭代_弱保序_右... apply 良构无穷序数后继 in Inf...
rewrite <- 左迭代在ω后继处不递增, 左迭代后继次, 左迭代后继次...
apply 幂运算_弱保序_右... rewrite IH... reflexivity.
- destruct WF as [WF Inc]. unfold ω. rewrite 左迭代极限次, 左迭代极限次.
split; constructor; intros n.
+ pose proof (良构对ω排中 (f n)) as []...
* apply 良构有限序数有自然数表示 in H as [m H]...
rewrite H. eapply 弱序_极限_介入. reflexivity.
* rewrite IH... unfold ω. rewrite 左迭代极限次. constructor. intros m.
apply 弱序_极限_介入 with (S m). apply 左迭代_弱保序_右... simpl...
+ pose proof (良构对ω排中 (f n)) as []...
* apply 弱序_极限_介入 with n. apply 左迭代_弱保序_右... apply 递增序列弱放大...
* apply 弱序_极限_介入 with n. rewrite IH... apply 左迭代_弱保序_右...
Qed.
Definition 右迭代 α β := 递归 (λ ξ, ξ ^ α) α β.
Notation "α ^^ᴿ β" := (右迭代 α β) (at level 25) : 序数算术域.
Lemma 右迭代零次 : ∀ α, α ^^ᴿ [0] = α.
Proof. easy. Qed.
Lemma 右迭代后继次 : ∀ α β, α ^^ᴿ β⁺ = (α ^^ᴿ β) ^ α.
Proof. easy. Qed.
Lemma 右迭代极限次 : ∀ α f, α ^^ᴿ lim f = lim (λ n, α ^^ᴿ f n).
Proof. easy. Qed.
Theorem 右迭代化简 : ∀ α β, α ≠ [0] → α ^^ᴿ β ≃ α ^ (α ^ β).
Proof.
intros. induction β as [|β IH|f IH].
- rewrite 右迭代零次, 零次幂, 一次幂. reflexivity.
- rewrite 右迭代后继次, 后继次幂, 指数积运算律.
apply 幂运算_改写_左. apply IH.
- rewrite 右迭代极限次, 极限次幂, 极限次幂. split; constructor; intros n;
eapply 弱序_极限_介入; rewrite IH; reflexivity.
Qed.
(* α ^ α ^ ... ^ α ^ τ *)
Definition 顶迭代 := λ α β τ, 递归 (幂运算 α) τ β.
Notation "α ^^ᵀ β" := (顶迭代 α β) (at level 25) : 序数域.
Theorem 顶迭代零次 : ∀ τ α, (α ^^ᵀ [0]) τ = τ.
Proof. easy. Qed.
Theorem 顶迭代后继次 : ∀ τ α β, (α ^^ᵀ β⁺) τ = α ^ (α ^^ᵀ β) τ.
Proof. easy. Qed.
Theorem 顶迭代极限次 : ∀ τ α f, (α ^^ᵀ (lim f)) τ = lim (λ n, (α ^^ᵀ (f n)) τ).
Proof. easy. Qed.
Theorem 顶迭代一次 : ∀ τ α, (α ^^ᵀ [1]) τ = α ^ τ.
Proof. easy. Qed.
Lemma 有限顶迭代小于左迭代 : ∀ α τ n, [1] < α → τ < α → (α ^^ᵀ [n]) τ < α ^^ᴸ [n].
Proof with auto.
intros. induction n.
- easy.
- simpl. rewrite 顶迭代后继次, 左迭代后继次... apply 幂运算_强保序_右...
Qed.
Lemma 有限左迭代小于后继顶迭代 : ∀ α τ n, [1] < τ → τ < α → α ^^ᴸ [n] < (α ^^ᵀ [S n]) τ.
Proof with auto.
intros. assert ([1] < α). eapply 强序_传递; eauto.
induction n.
- rewrite 顶迭代一次, 左迭代零次... apply 幂运算_强放大_右...
- simpl. rewrite 顶迭代后继次, 左迭代后继次... apply 幂运算_强保序_右...
Qed.
Theorem 无穷顶迭代等于左迭代 : ∀ α τ, [1] < τ → τ < α → (α ^^ᵀ ω) τ ≃ α ^^ᴸ ω.
Proof with auto.
intros. assert ([1] < α). eapply 强序_传递; eauto.
unfold ω. rewrite 顶迭代极限次, 左迭代极限次.
split; constructor; intros n.
- eapply 弱序_极限_介入 with n. apply 诉诸强序. apply 有限顶迭代小于左迭代...
- eapply 弱序_极限_介入 with (S n). apply 诉诸强序. apply 有限左迭代小于后继顶迭代...
Qed.
|
library(readr)
library(modEvA)
library(sjPlot)
adam_measures <- read_csv('data/measures_csv/adam-measures-with-d-2.csv')
sarah_measures <- read_csv('data/measures_csv/sarah-measures-with-d-2.csv')
adam_glm <- glm(CHI_CP ~ Semantic*Age + PosBi*Age + LexUni*Age + ADT_CP*Age,
data=adam_measures)
adam_dsq <- Dsquared(model = adam_glm, adjust = TRUE)
summary(adam_glm)
print(paste('adjusted D^2:', adam_dsq))
sarah_glm <- glm(CHI_CP ~ Semantic*Age + PosBi*Age + LexUni*Age + ADT_CP*Age,
data=sarah_measures)
sarah_dsq <- Dsquared(model = sarah_glm, adjust = TRUE)
summary(sarah_glm)
print(paste('adjusted D^2:', sarah_dsq))
# plot interaction effects
# Age:Adt_Complexity (Adam)
plot_model(adam_glm, type='eff', terms=c('ADT_CP', 'Age'))
# Age:PosBi_Recurrence (Adam)
plot_model(adam_glm, type='eff', terms=c('PosBi', 'Age'))
# Age:Adt_Complexity (Sarah)
plot_model(sarah_glm, type='eff', terms=c('ADT_CP', 'Age'))
|
[GOAL]
c : Type u → Type u
hom : ⦃α β : Type u⦄ → c α → c β → Type u
𝒞 : BundledHom hom
⊢ Category.{?u.1823, u + 1} (Bundled c)
[PROOFSTEP]
refine'
{ Hom := fun X Y => @hom X Y X.str Y.str
id := fun X => @BundledHom.id c hom 𝒞 X X.str
comp := @fun X Y Z f g => @BundledHom.comp c hom 𝒞 X Y Z X.str Y.str Z.str g f
comp_id := _
id_comp := _
assoc := _ }
[GOAL]
case refine'_1
c : Type u → Type u
hom : ⦃α β : Type u⦄ → c α → c β → Type u
𝒞 : BundledHom hom
⊢ ∀ {X Y : Bundled c} (f : X ⟶ Y), 𝟙 X ≫ f = f
[PROOFSTEP]
intros
[GOAL]
case refine'_2
c : Type u → Type u
hom : ⦃α β : Type u⦄ → c α → c β → Type u
𝒞 : BundledHom hom
⊢ ∀ {X Y : Bundled c} (f : X ⟶ Y), f ≫ 𝟙 Y = f
[PROOFSTEP]
intros
[GOAL]
case refine'_3
c : Type u → Type u
hom : ⦃α β : Type u⦄ → c α → c β → Type u
𝒞 : BundledHom hom
⊢ ∀ {W X Y Z : Bundled c} (f : W ⟶ X) (g : X ⟶ Y) (h : Y ⟶ Z), (f ≫ g) ≫ h = f ≫ g ≫ h
[PROOFSTEP]
intros
[GOAL]
case refine'_1
c : Type u → Type u
hom : ⦃α β : Type u⦄ → c α → c β → Type u
𝒞 : BundledHom hom
X✝ Y✝ : Bundled c
f✝ : X✝ ⟶ Y✝
⊢ 𝟙 X✝ ≫ f✝ = f✝
[PROOFSTEP]
apply 𝒞.hom_ext
[GOAL]
case refine'_2
c : Type u → Type u
hom : ⦃α β : Type u⦄ → c α → c β → Type u
𝒞 : BundledHom hom
X✝ Y✝ : Bundled c
f✝ : X✝ ⟶ Y✝
⊢ f✝ ≫ 𝟙 Y✝ = f✝
[PROOFSTEP]
apply 𝒞.hom_ext
[GOAL]
case refine'_3
c : Type u → Type u
hom : ⦃α β : Type u⦄ → c α → c β → Type u
𝒞 : BundledHom hom
W✝ X✝ Y✝ Z✝ : Bundled c
f✝ : W✝ ⟶ X✝
g✝ : X✝ ⟶ Y✝
h✝ : Y✝ ⟶ Z✝
⊢ (f✝ ≫ g✝) ≫ h✝ = f✝ ≫ g✝ ≫ h✝
[PROOFSTEP]
apply 𝒞.hom_ext
[GOAL]
case refine'_1.a
c : Type u → Type u
hom : ⦃α β : Type u⦄ → c α → c β → Type u
𝒞 : BundledHom hom
X✝ Y✝ : Bundled c
f✝ : X✝ ⟶ Y✝
⊢ toFun 𝒞 X✝.str Y✝.str (𝟙 X✝ ≫ f✝) = toFun 𝒞 X✝.str Y✝.str f✝
[PROOFSTEP]
aesop_cat
[GOAL]
case refine'_2.a
c : Type u → Type u
hom : ⦃α β : Type u⦄ → c α → c β → Type u
𝒞 : BundledHom hom
X✝ Y✝ : Bundled c
f✝ : X✝ ⟶ Y✝
⊢ toFun 𝒞 X✝.str Y✝.str (f✝ ≫ 𝟙 Y✝) = toFun 𝒞 X✝.str Y✝.str f✝
[PROOFSTEP]
aesop_cat
[GOAL]
case refine'_3.a
c : Type u → Type u
hom : ⦃α β : Type u⦄ → c α → c β → Type u
𝒞 : BundledHom hom
W✝ X✝ Y✝ Z✝ : Bundled c
f✝ : W✝ ⟶ X✝
g✝ : X✝ ⟶ Y✝
h✝ : Y✝ ⟶ Z✝
⊢ toFun 𝒞 W✝.str Z✝.str ((f✝ ≫ g✝) ≫ h✝) = toFun 𝒞 W✝.str Z✝.str (f✝ ≫ g✝ ≫ h✝)
[PROOFSTEP]
aesop_cat
[GOAL]
c : Type u → Type u
hom : ⦃α β : Type u⦄ → c α → c β → Type u
𝒞 : BundledHom hom
X✝ Y✝ Z✝ : Bundled c
f : X✝ ⟶ Y✝
g : Y✝ ⟶ Z✝
⊢ { obj := fun X => ↑X, map := fun X Y f => toFun 𝒞 X.str Y.str f }.map (f ≫ g) =
{ obj := fun X => ↑X, map := fun X Y f => toFun 𝒞 X.str Y.str f }.map f ≫
{ obj := fun X => ↑X, map := fun X Y f => toFun 𝒞 X.str Y.str f }.map g
[PROOFSTEP]
dsimp
[GOAL]
c : Type u → Type u
hom : ⦃α β : Type u⦄ → c α → c β → Type u
𝒞 : BundledHom hom
X✝ Y✝ Z✝ : Bundled c
f : X✝ ⟶ Y✝
g : Y✝ ⟶ Z✝
⊢ toFun 𝒞 X✝.str Z✝.str (f ≫ g) = toFun 𝒞 X✝.str Y✝.str f ≫ toFun 𝒞 Y✝.str Z✝.str g
[PROOFSTEP]
erw [𝒞.comp_toFun]
[GOAL]
c : Type u → Type u
hom : ⦃α β : Type u⦄ → c α → c β → Type u
𝒞 : BundledHom hom
X✝ Y✝ Z✝ : Bundled c
f : X✝ ⟶ Y✝
g : Y✝ ⟶ Z✝
⊢ toFun 𝒞 Y✝.str Z✝.str g ∘ toFun 𝒞 X✝.str Y✝.str f = toFun 𝒞 X✝.str Y✝.str f ≫ toFun 𝒞 Y✝.str Z✝.str g
[PROOFSTEP]
rfl
[GOAL]
c : Type u → Type u
hom : ⦃α β : Type u⦄ → c α → c β → Type u
𝒞 : BundledHom hom
⊢ ∀ {X Y : Bundled c},
Function.Injective (Functor.mk { obj := fun X => ↑X, map := fun X Y f => toFun 𝒞 X.str Y.str f }).map
[PROOFSTEP]
intros
[GOAL]
c : Type u → Type u
hom : ⦃α β : Type u⦄ → c α → c β → Type u
𝒞 : BundledHom hom
X✝ Y✝ : Bundled c
⊢ Function.Injective (Functor.mk { obj := fun X => ↑X, map := fun X Y f => toFun 𝒞 X.str Y.str f }).map
[PROOFSTEP]
apply 𝒞.hom_ext
[GOAL]
c : Type u → Type u
hom : ⦃α β : Type u⦄ → c α → c β → Type u
𝒞 : BundledHom hom
d : Type u → Type u
hom_d : ⦃α β : Type u⦄ → d α → d β → Type u
inst✝ : BundledHom hom_d
obj : ⦃α : Type u⦄ → c α → d α
map : {X Y : Bundled c} → (X ⟶ Y) → (Bundled.map obj X ⟶ Bundled.map obj Y)
h_map : ∀ {X Y : Bundled c} (f : X ⟶ Y), ↑(map f) = ↑f
⊢ ∀ {X Y : Bundled c} {f : X ⟶ Y}, HEq ((forget (Bundled d)).map ((fun {X Y} => map) f)) ((forget (Bundled c)).map f)
[PROOFSTEP]
intros X Y f
[GOAL]
c : Type u → Type u
hom : ⦃α β : Type u⦄ → c α → c β → Type u
𝒞 : BundledHom hom
d : Type u → Type u
hom_d : ⦃α β : Type u⦄ → d α → d β → Type u
inst✝ : BundledHom hom_d
obj : ⦃α : Type u⦄ → c α → d α
map : {X Y : Bundled c} → (X ⟶ Y) → (Bundled.map obj X ⟶ Bundled.map obj Y)
h_map : ∀ {X Y : Bundled c} (f : X ⟶ Y), ↑(map f) = ↑f
X Y : Bundled c
f : X ⟶ Y
⊢ HEq ((forget (Bundled d)).map ((fun {X Y} => map) f)) ((forget (Bundled c)).map f)
[PROOFSTEP]
rw [heq_eq_eq, forget_map_eq_coe, forget_map_eq_coe, h_map f]
|
(* Copyright 2021 (C) Mihails Milehins *)
section\<open>Pointwise Kan extensions\<close>
theory CZH_UCAT_PWKan
imports CZH_UCAT_Kan
begin
subsection\<open>Pointwise Kan extensions\<close>
text\<open>
The following subsection is based on elements of the
content of section 6.3 in \<^cite>\<open>"riehl_category_2016"\<close> and
Chapter X-5 in \<^cite>\<open>"mac_lane_categories_2010"\<close>.
\<close>
locale is_cat_pw_rKe = is_cat_rKe \<alpha> \<BB> \<CC> \<AA> \<KK> \<TT> \<GG> \<epsilon>
for \<alpha> \<BB> \<CC> \<AA> \<KK> \<TT> \<GG> \<epsilon> +
assumes cat_pw_rKe_preserved: "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr> \<Longrightarrow>
\<epsilon> :
\<GG> \<circ>\<^sub>C\<^sub>F \<KK> \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>r\<^sub>K\<^sub>e\<^bsub>\<alpha>\<^esub> \<TT> :
\<BB> \<mapsto>\<^sub>C \<CC> \<mapsto>\<^sub>C (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-) : \<AA> \<mapsto>\<mapsto>\<^sub>C cat_Set \<alpha>)"
syntax "_is_cat_pw_rKe" :: "V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> bool"
(
\<open>(_ :/ _ \<circ>\<^sub>C\<^sub>F _ \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>r\<^sub>K\<^sub>e\<^sub>.\<^sub>p\<^sub>w\<index> _ :/ _ \<mapsto>\<^sub>C _ \<mapsto>\<^sub>C _)\<close>
[51, 51, 51, 51, 51, 51, 51] 51
)
translations "\<epsilon> : \<GG> \<circ>\<^sub>C\<^sub>F \<KK> \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>r\<^sub>K\<^sub>e\<^sub>.\<^sub>p\<^sub>w\<^bsub>\<alpha>\<^esub> \<TT> : \<BB> \<mapsto>\<^sub>C \<CC> \<mapsto>\<^sub>C \<AA>" \<rightleftharpoons>
"CONST is_cat_pw_rKe \<alpha> \<BB> \<CC> \<AA> \<KK> \<TT> \<GG> \<epsilon>"
locale is_cat_pw_lKe = is_cat_lKe \<alpha> \<BB> \<CC> \<AA> \<KK> \<TT> \<FF> \<eta>
for \<alpha> \<BB> \<CC> \<AA> \<KK> \<TT> \<FF> \<eta> +
assumes cat_pw_lKe_preserved: "a \<in>\<^sub>\<circ> op_cat \<AA>\<lparr>Obj\<rparr> \<Longrightarrow>
op_ntcf \<eta> :
op_cf \<FF> \<circ>\<^sub>C\<^sub>F op_cf \<KK> \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>r\<^sub>K\<^sub>e\<^bsub>\<alpha>\<^esub> op_cf \<TT> :
op_cat \<BB> \<mapsto>\<^sub>C op_cat \<CC> \<mapsto>\<^sub>C (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(-,a) : op_cat \<AA> \<mapsto>\<mapsto>\<^sub>C cat_Set \<alpha>)"
syntax "_is_cat_pw_lKe" :: "V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> bool"
(
\<open>(_ :/ _ \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>l\<^sub>K\<^sub>e\<^sub>.\<^sub>p\<^sub>w\<index> _ \<circ>\<^sub>C\<^sub>F _ :/ _ \<mapsto>\<^sub>C _ \<mapsto>\<^sub>C _)\<close>
[51, 51, 51, 51, 51, 51, 51] 51
)
translations "\<eta> : \<TT> \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>l\<^sub>K\<^sub>e\<^sub>.\<^sub>p\<^sub>w\<^bsub>\<alpha>\<^esub> \<FF> \<circ>\<^sub>C\<^sub>F \<KK> : \<BB> \<mapsto>\<^sub>C \<CC> \<mapsto>\<^sub>C \<AA>" \<rightleftharpoons>
"CONST is_cat_pw_lKe \<alpha> \<BB> \<CC> \<AA> \<KK> \<TT> \<FF> \<eta>"
lemma (in is_cat_pw_rKe) cat_pw_rKe_preserved'[cat_Kan_cs_intros]:
assumes "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
and "\<AA>' = \<AA>"
and "\<HH>' = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-)"
and "\<EE>' = cat_Set \<alpha>"
shows "\<epsilon> : \<GG> \<circ>\<^sub>C\<^sub>F \<KK> \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>r\<^sub>K\<^sub>e\<^bsub>\<alpha>\<^esub> \<TT> : \<BB> \<mapsto>\<^sub>C \<CC> \<mapsto>\<^sub>C (\<HH>' : \<AA>' \<mapsto>\<mapsto>\<^sub>C \<EE>')"
using assms(1) unfolding assms(2-4) by (rule cat_pw_rKe_preserved)
lemmas [cat_Kan_cs_intros] = is_cat_pw_rKe.cat_pw_rKe_preserved'
lemma (in is_cat_pw_lKe) cat_pw_lKe_preserved'[cat_Kan_cs_intros]:
assumes "a \<in>\<^sub>\<circ> op_cat \<AA>\<lparr>Obj\<rparr>"
and "\<FF>' = op_cf \<FF>"
and "\<KK>' = op_cf \<KK>"
and "\<TT>' = op_cf \<TT>"
and "\<BB>' = op_cat \<BB>"
and "\<CC>' = op_cat \<CC>"
and "\<AA>' = op_cat \<AA>"
and "\<HH>' = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(-,a)"
and "\<EE>' = cat_Set \<alpha>"
shows "op_ntcf \<eta> :
\<FF>' \<circ>\<^sub>C\<^sub>F \<KK>' \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>r\<^sub>K\<^sub>e\<^bsub>\<alpha>\<^esub> \<TT>' : \<BB>' \<mapsto>\<^sub>C \<CC>' \<mapsto>\<^sub>C (\<HH>' : \<AA>' \<mapsto>\<mapsto>\<^sub>C \<EE>')"
using assms(1) unfolding assms by (rule cat_pw_lKe_preserved)
lemmas [cat_Kan_cs_intros] = is_cat_pw_lKe.cat_pw_lKe_preserved'
text\<open>Rules.\<close>
lemma (in is_cat_pw_rKe) is_cat_pw_rKe_axioms'[cat_Kan_cs_intros]:
assumes "\<alpha>' = \<alpha>"
and "\<GG>' = \<GG>"
and "\<KK>' = \<KK>"
and "\<TT>' = \<TT>"
and "\<BB>' = \<BB>"
and "\<AA>' = \<AA>"
and "\<CC>' = \<CC>"
shows "\<epsilon> : \<GG>' \<circ>\<^sub>C\<^sub>F \<KK>' \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>r\<^sub>K\<^sub>e\<^sub>.\<^sub>p\<^sub>w\<^bsub>\<alpha>'\<^esub> \<TT>' : \<BB>' \<mapsto>\<^sub>C \<CC>' \<mapsto>\<^sub>C \<AA>'"
unfolding assms by (rule is_cat_pw_rKe_axioms)
mk_ide rf is_cat_pw_rKe_def[unfolded is_cat_pw_rKe_axioms_def]
|intro is_cat_pw_rKeI|
|dest is_cat_pw_rKeD[dest]|
|elim is_cat_pw_rKeE[elim]|
lemmas [cat_Kan_cs_intros] = is_cat_pw_rKeD(1)
lemma (in is_cat_pw_lKe) is_cat_pw_lKe_axioms'[cat_Kan_cs_intros]:
assumes "\<alpha>' = \<alpha>"
and "\<FF>' = \<FF>"
and "\<KK>' = \<KK>"
and "\<TT>' = \<TT>"
and "\<BB>' = \<BB>"
and "\<AA>' = \<AA>"
and "\<CC>' = \<CC>"
shows "\<eta> : \<TT>' \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>l\<^sub>K\<^sub>e\<^sub>.\<^sub>p\<^sub>w\<^bsub>\<alpha>'\<^esub> \<FF>' \<circ>\<^sub>C\<^sub>F \<KK>' : \<BB>' \<mapsto>\<^sub>C \<CC>' \<mapsto>\<^sub>C \<AA>'"
unfolding assms by (rule is_cat_pw_lKe_axioms)
mk_ide rf is_cat_pw_lKe_def[unfolded is_cat_pw_lKe_axioms_def]
|intro is_cat_pw_lKeI|
|dest is_cat_pw_lKeD[dest]|
|elim is_cat_pw_lKeE[elim]|
lemmas [cat_Kan_cs_intros] = is_cat_pw_lKeD(1)
text\<open>Duality.\<close>
lemma (in is_cat_pw_rKe) is_cat_pw_lKe_op:
"op_ntcf \<epsilon> :
op_cf \<TT> \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>l\<^sub>K\<^sub>e\<^sub>.\<^sub>p\<^sub>w\<^bsub>\<alpha>\<^esub> op_cf \<GG> \<circ>\<^sub>C\<^sub>F op_cf \<KK> :
op_cat \<BB> \<mapsto>\<^sub>C op_cat \<CC> \<mapsto>\<^sub>C op_cat \<AA>"
proof(intro is_cat_pw_lKeI, unfold cat_op_simps)
fix a assume prems: "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
from cat_pw_rKe_preserved[OF prems] prems show
"\<epsilon> :
\<GG> \<circ>\<^sub>C\<^sub>F \<KK> \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>r\<^sub>K\<^sub>e\<^bsub>\<alpha>\<^esub> \<TT> :
\<BB> \<mapsto>\<^sub>C \<CC> \<mapsto>\<^sub>C (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<AA>(-,a) : \<AA> \<mapsto>\<mapsto>\<^sub>C cat_Set \<alpha>)"
by (cs_concl cs_shallow cs_simp: cat_op_simps cs_intro: cat_cs_intros)
qed (cs_concl cs_shallow cs_intro: cat_op_intros)
lemma (in is_cat_pw_rKe) is_cat_pw_lKe_op'[cat_op_intros]:
assumes "\<TT>' = op_cf \<TT>"
and "\<GG>' = op_cf \<GG>"
and "\<KK>' = op_cf \<KK>"
and "\<BB>' = op_cat \<BB>"
and "\<AA>' = op_cat \<AA>"
and "\<CC>' = op_cat \<CC>"
shows "op_ntcf \<epsilon> : \<TT>' \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>l\<^sub>K\<^sub>e\<^sub>.\<^sub>p\<^sub>w\<^bsub>\<alpha>\<^esub> \<GG>' \<circ>\<^sub>C\<^sub>F \<KK>' : \<BB>' \<mapsto>\<^sub>C \<CC>' \<mapsto>\<^sub>C \<AA>'"
unfolding assms by (rule is_cat_pw_lKe_op)
lemmas [cat_op_intros] = is_cat_pw_rKe.is_cat_pw_lKe_op'
lemma (in is_cat_pw_lKe) is_cat_pw_rKe_op:
"op_ntcf \<eta> :
op_cf \<FF> \<circ>\<^sub>C\<^sub>F op_cf \<KK> \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>r\<^sub>K\<^sub>e\<^sub>.\<^sub>p\<^sub>w\<^bsub>\<alpha>\<^esub> op_cf \<TT> :
op_cat \<BB> \<mapsto>\<^sub>C op_cat \<CC> \<mapsto>\<^sub>C op_cat \<AA>"
proof(intro is_cat_pw_rKeI, unfold cat_op_simps)
fix a assume prems: "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
from cat_pw_lKe_preserved[unfolded cat_op_simps, OF prems] prems show
"op_ntcf \<eta> :
op_cf \<FF> \<circ>\<^sub>C\<^sub>F op_cf \<KK> \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>r\<^sub>K\<^sub>e\<^bsub>\<alpha>\<^esub> op_cf \<TT> :
op_cat \<BB> \<mapsto>\<^sub>C op_cat \<CC> \<mapsto>\<^sub>C
(Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>op_cat \<AA>(a,-) : op_cat \<AA> \<mapsto>\<mapsto>\<^sub>C cat_Set \<alpha>)"
by (cs_concl cs_shallow cs_simp: cat_op_simps cs_intro: cat_cs_intros)
qed (cs_concl cs_shallow cs_intro: cat_op_intros)
lemma (in is_cat_pw_lKe) is_cat_pw_lKe_op'[cat_op_intros]:
assumes "\<TT>' = op_cf \<TT>"
and "\<FF>' = op_cf \<FF>"
and "\<KK>' = op_cf \<KK>"
and "\<BB>' = op_cat \<BB>"
and "\<AA>' = op_cat \<AA>"
and "\<CC>' = op_cat \<CC>"
shows "op_ntcf \<eta> : \<FF>' \<circ>\<^sub>C\<^sub>F \<KK>' \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>r\<^sub>K\<^sub>e\<^sub>.\<^sub>p\<^sub>w\<^bsub>\<alpha>\<^esub> \<TT>' : \<BB>' \<mapsto>\<^sub>C \<CC>' \<mapsto>\<^sub>C \<AA>'"
unfolding assms by (rule is_cat_pw_rKe_op)
lemmas [cat_op_intros] = is_cat_pw_lKe.is_cat_pw_lKe_op'
subsection\<open>Lemma X.5: \<open>L_10_5_N\<close>\label{sec:lem_X_5_start}\<close>
text\<open>
This subsection and several further subsections
(\ref{sec:lem_X_5_start}-\ref{sec:lem_X_5_end})
expose definitions that are used in the proof of the technical lemma that
was used in the proof of Theorem 3 from Chapter X-5
in \<^cite>\<open>"mac_lane_categories_2010"\<close>.
\<close>
definition L_10_5_N :: "V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V"
where "L_10_5_N \<alpha> \<beta> \<TT> \<KK> c =
[
(
\<lambda>a\<in>\<^sub>\<circ>\<TT>\<lparr>HomCod\<rparr>\<lparr>Obj\<rparr>.
cf_nt \<alpha> \<beta> \<KK>\<lparr>ObjMap\<rparr>\<lparr>cf_map (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<TT>\<lparr>HomCod\<rparr>(a,-) \<circ>\<^sub>C\<^sub>F \<TT>), c\<rparr>\<^sub>\<bullet>
),
(
\<lambda>f\<in>\<^sub>\<circ>\<TT>\<lparr>HomCod\<rparr>\<lparr>Arr\<rparr>.
cf_nt \<alpha> \<beta> \<KK>\<lparr>ArrMap\<rparr>\<lparr>
ntcf_arrow (Hom\<^sub>A\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<TT>\<lparr>HomCod\<rparr>(f,-) \<circ>\<^sub>N\<^sub>T\<^sub>C\<^sub>F\<^sub>-\<^sub>C\<^sub>F \<TT>), \<KK>\<lparr>HomCod\<rparr>\<lparr>CId\<rparr>\<lparr>c\<rparr>
\<rparr>\<^sub>\<bullet>
),
op_cat (\<TT>\<lparr>HomCod\<rparr>),
cat_Set \<beta>
]\<^sub>\<circ>"
text\<open>Components.\<close>
lemma L_10_5_N_components:
shows "L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr> =
(
\<lambda>a\<in>\<^sub>\<circ>\<TT>\<lparr>HomCod\<rparr>\<lparr>Obj\<rparr>.
cf_nt \<alpha> \<beta> \<KK>\<lparr>ObjMap\<rparr>\<lparr>cf_map (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<TT>\<lparr>HomCod\<rparr>(a,-) \<circ>\<^sub>C\<^sub>F \<TT>), c\<rparr>\<^sub>\<bullet>
)"
and "L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ArrMap\<rparr> =
(
\<lambda>f\<in>\<^sub>\<circ>\<TT>\<lparr>HomCod\<rparr>\<lparr>Arr\<rparr>.
cf_nt \<alpha> \<beta> \<KK>\<lparr>ArrMap\<rparr>\<lparr>
ntcf_arrow (Hom\<^sub>A\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<TT>\<lparr>HomCod\<rparr>(f,-) \<circ>\<^sub>N\<^sub>T\<^sub>C\<^sub>F\<^sub>-\<^sub>C\<^sub>F \<TT>), \<KK>\<lparr>HomCod\<rparr>\<lparr>CId\<rparr>\<lparr>c\<rparr>
\<rparr>\<^sub>\<bullet>
)"
and "L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>HomDom\<rparr> = op_cat (\<TT>\<lparr>HomCod\<rparr>)"
and "L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>HomCod\<rparr> = cat_Set \<beta>"
unfolding L_10_5_N_def dghm_field_simps by (simp_all add: nat_omega_simps)
context
fixes \<alpha> \<BB> \<CC> \<AA> \<KK> \<TT>
assumes \<KK>: "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and \<TT>: "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
begin
interpretation \<KK>: is_functor \<alpha> \<BB> \<CC> \<KK> by (rule \<KK>)
interpretation \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule \<TT>)
lemmas L_10_5_N_components' = L_10_5_N_components[
where \<TT>=\<TT> and \<KK>=\<KK>, unfolded cat_cs_simps
]
lemmas [cat_Kan_cs_simps] = L_10_5_N_components'(3,4)
end
subsubsection\<open>Object map\<close>
mk_VLambda L_10_5_N_components(1)
|vsv L_10_5_N_ObjMap_vsv[cat_Kan_cs_intros]|
context
fixes \<alpha> \<BB> \<CC> \<AA> \<KK> \<TT> c
assumes \<KK>: "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and \<TT>: "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
begin
mk_VLambda L_10_5_N_components'(1)[OF \<KK> \<TT>]
|vdomain L_10_5_N_ObjMap_vdomain[cat_Kan_cs_simps]|
|app L_10_5_N_ObjMap_app[cat_Kan_cs_simps]|
end
subsubsection\<open>Arrow map\<close>
mk_VLambda L_10_5_N_components(2)
|vsv L_10_5_N_ArrMap_vsv[cat_Kan_cs_intros]|
context
fixes \<alpha> \<BB> \<CC> \<AA> \<KK> \<TT> c
assumes \<KK>: "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and \<TT>: "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
begin
mk_VLambda L_10_5_N_components'(2)[OF \<KK> \<TT>]
|vdomain L_10_5_N_ArrMap_vdomain[cat_Kan_cs_simps]|
|app L_10_5_N_ArrMap_app[cat_Kan_cs_simps]|
end
subsubsection\<open>\<open>L_10_5_N\<close> is a functor\<close>
lemma L_10_5_N_is_functor:
assumes "\<Z> \<beta>"
and "\<alpha> \<in>\<^sub>\<circ> \<beta>"
and "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "L_10_5_N \<alpha> \<beta> \<TT> \<KK> c : op_cat \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> cat_Set \<beta>"
proof-
let ?FUNCT = \<open>\<lambda>\<AA>. cat_FUNCT \<alpha> \<AA> (cat_Set \<alpha>)\<close>
interpret \<beta>: \<Z> \<beta> by (rule assms(1))
interpret \<KK>: is_functor \<alpha> \<BB> \<CC> \<KK> by (rule assms(3))
interpret \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule assms(4))
from assms(2) interpret FUNCT_\<BB>: tiny_category \<beta> \<open>?FUNCT \<BB>\<close>
by (cs_concl cs_intro: cat_cs_intros cat_FUNCT_cs_intros)
interpret \<beta>\<KK>: is_tiny_functor \<beta> \<BB> \<CC> \<KK>
by (rule is_functor.cf_is_tiny_functor_if_ge_Limit)
(use assms(2) in \<open>cs_concl cs_intro: cat_cs_intros\<close>)+
interpret \<beta>\<TT>: is_tiny_functor \<beta> \<BB> \<AA> \<TT>
by (rule is_functor.cf_is_tiny_functor_if_ge_Limit)
(use assms(2) in \<open>cs_concl cs_intro: cat_cs_intros\<close>)+
from assms(2) interpret cf_nt:
is_functor \<beta> \<open>?FUNCT \<BB> \<times>\<^sub>C \<CC>\<close> \<open>cat_Set \<beta>\<close> \<open>cf_nt \<alpha> \<beta> \<KK>\<close>
by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros)
show ?thesis
proof(intro is_functorI')
show "vfsequence (L_10_5_N \<alpha> \<beta> \<TT> \<KK> c)" unfolding L_10_5_N_def by simp
show "vcard (L_10_5_N \<alpha> \<beta> \<TT> \<KK> c) = 4\<^sub>\<nat>"
unfolding L_10_5_N_def by (simp add: nat_omega_simps)
show "vsv (L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr>)"
by (cs_concl cs_shallow cs_intro: cat_Kan_cs_intros)
from assms(3,4) show "vsv (L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ArrMap\<rparr>)"
by (cs_concl cs_shallow cs_intro: cat_Kan_cs_intros)
from assms show "\<D>\<^sub>\<circ> (L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr>) = op_cat \<AA>\<lparr>Obj\<rparr>"
by
(
cs_concl cs_shallow
cs_simp: cat_Kan_cs_simps cat_op_simps cs_intro: cat_cs_intros
)
show "\<R>\<^sub>\<circ> (L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr>) \<subseteq>\<^sub>\<circ> cat_Set \<beta>\<lparr>Obj\<rparr>"
unfolding L_10_5_N_components'[OF \<KK>.is_functor_axioms \<TT>.is_functor_axioms]
proof(rule vrange_VLambda_vsubset)
fix a assume prems: "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
from prems assms show
"cf_nt \<alpha> \<beta> \<KK>\<lparr>ObjMap\<rparr>\<lparr>cf_map (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-) \<circ>\<^sub>C\<^sub>F \<TT>), c\<rparr>\<^sub>\<bullet> \<in>\<^sub>\<circ>
cat_Set \<beta>\<lparr>Obj\<rparr>"
by
(
cs_concl
cs_simp: cat_Set_components(1) cat_cs_simps cat_FUNCT_cs_simps
cs_intro:
cat_cs_intros FUNCT_\<BB>.cat_Hom_in_Vset cat_FUNCT_cs_intros
)
qed
from assms show "\<D>\<^sub>\<circ> (L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ArrMap\<rparr>) = op_cat \<AA>\<lparr>Arr\<rparr>"
by
(
cs_concl cs_shallow
cs_simp: cat_Kan_cs_simps cat_op_simps cs_intro: cat_cs_intros
)
show "L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> :
L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> \<mapsto>\<^bsub>cat_Set \<beta>\<^esub> L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
if "f : a \<mapsto>\<^bsub>op_cat \<AA>\<^esub> b" for a b f
using that assms
unfolding cat_op_simps
by
(
cs_concl
cs_simp: L_10_5_N_ArrMap_app L_10_5_N_ObjMap_app
cs_intro: cat_cs_intros cat_prod_cs_intros cat_FUNCT_cs_intros
)
show
"L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ArrMap\<rparr>\<lparr>g \<circ>\<^sub>A\<^bsub>op_cat \<AA>\<^esub> f\<rparr> =
L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ArrMap\<rparr>\<lparr>g\<rparr> \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ArrMap\<rparr>\<lparr>f\<rparr>"
if "g : b' \<mapsto>\<^bsub>op_cat \<AA>\<^esub> c'" and "f : a' \<mapsto>\<^bsub>op_cat \<AA>\<^esub> b'" for b' c' g a' f
proof-
from that assms(5) show ?thesis
unfolding cat_op_simps
by (*slow*)
(
cs_concl
cs_intro:
cat_cs_intros
cat_prod_cs_intros
cat_FUNCT_cs_intros
cat_op_intros
cs_simp:
cat_cs_simps
cat_Kan_cs_simps
cat_FUNCT_cs_simps
cat_prod_cs_simps
cat_op_simps
cf_nt.cf_ArrMap_Comp[symmetric]
)
qed
show
"L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ArrMap\<rparr>\<lparr>op_cat \<AA>\<lparr>CId\<rparr>\<lparr>a\<rparr>\<rparr> =
cat_Set \<beta>\<lparr>CId\<rparr>\<lparr>L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>\<rparr>"
if "a \<in>\<^sub>\<circ> op_cat \<AA>\<lparr>Obj\<rparr>" for a
proof-
note [cat_cs_simps] =
ntcf_id_cf_comp[symmetric]
ntcf_arrow_id_ntcf_id[symmetric]
cat_FUNCT_CId_app[symmetric]
from that[unfolded cat_op_simps] assms show ?thesis
by (*slow*)
(
cs_concl
cs_intro:
cat_cs_intros
cat_FUNCT_cs_intros
cat_prod_cs_intros
cat_op_intros
cs_simp:
cat_FUNCT_cs_simps cat_cs_simps cat_Kan_cs_simps cat_op_simps
)
qed
qed (cs_concl cs_simp: cat_Kan_cs_simps cs_intro: cat_cs_intros)+
qed
lemma L_10_5_N_is_functor'[cat_Kan_cs_intros]:
assumes "\<Z> \<beta>"
and "\<alpha> \<in>\<^sub>\<circ> \<beta>"
and "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
and "\<AA>' = op_cat \<AA>"
and "\<BB>' = cat_Set \<beta>"
and "\<beta>' = \<beta>"
shows "L_10_5_N \<alpha> \<beta> \<TT> \<KK> c : \<AA>' \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>'\<^esub> \<BB>'"
using assms(1-5) unfolding assms(6-8) by (rule L_10_5_N_is_functor)
subsection\<open>Lemma X.5: \<open>L_10_5_\<upsilon>_arrow\<close>\<close>
subsubsection\<open>Definition and elementary properties\<close>
definition L_10_5_\<upsilon>_arrow :: "V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V"
where "L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau> a b =
[
(\<lambda>f\<in>\<^sub>\<circ>Hom (\<KK>\<lparr>HomCod\<rparr>) c (\<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>). \<tau>\<lparr>NTMap\<rparr>\<lparr>0, b, f\<rparr>\<^sub>\<bullet>),
Hom (\<KK>\<lparr>HomCod\<rparr>) c (\<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>),
Hom (\<TT>\<lparr>HomCod\<rparr>) a (\<TT>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)
]\<^sub>\<circ>"
text\<open>Components.\<close>
lemma L_10_5_\<upsilon>_arrow_components:
shows "L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau> a b\<lparr>ArrVal\<rparr> =
(\<lambda>f\<in>\<^sub>\<circ>Hom (\<KK>\<lparr>HomCod\<rparr>) c (\<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>). \<tau>\<lparr>NTMap\<rparr>\<lparr>0, b, f\<rparr>\<^sub>\<bullet>)"
and "L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau> a b\<lparr>ArrDom\<rparr> = Hom (\<KK>\<lparr>HomCod\<rparr>) c (\<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)"
and "L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau> a b\<lparr>ArrCod\<rparr> = Hom (\<TT>\<lparr>HomCod\<rparr>) a (\<TT>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)"
unfolding L_10_5_\<upsilon>_arrow_def arr_field_simps
by (simp_all add: nat_omega_simps)
context
fixes \<alpha> \<BB> \<CC> \<AA> \<KK> \<TT>
assumes \<KK>: "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and \<TT>: "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
begin
interpretation \<KK>: is_functor \<alpha> \<BB> \<CC> \<KK> by (rule \<KK>)
interpretation \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule \<TT>)
lemmas L_10_5_\<upsilon>_arrow_components' = L_10_5_\<upsilon>_arrow_components[
where \<TT>=\<TT> and \<KK>=\<KK>, unfolded cat_cs_simps
]
lemmas [cat_Kan_cs_simps] = L_10_5_\<upsilon>_arrow_components'(2,3)
end
subsubsection\<open>Arrow value\<close>
mk_VLambda L_10_5_\<upsilon>_arrow_components(1)
|vsv L_10_5_\<upsilon>_arrow_ArrVal_vsv[cat_Kan_cs_intros]|
context
fixes \<alpha> \<BB> \<CC> \<AA> \<KK> \<TT>
assumes \<KK>: "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and \<TT>: "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
begin
mk_VLambda L_10_5_\<upsilon>_arrow_components'(1)[OF \<KK> \<TT>]
|vdomain L_10_5_\<upsilon>_arrow_ArrVal_vdomain[cat_Kan_cs_simps]|
|app L_10_5_\<upsilon>_arrow_ArrVal_app[unfolded in_Hom_iff]|
end
lemma L_10_5_\<upsilon>_arrow_ArrVal_app':
assumes "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "f : c \<mapsto>\<^bsub>\<CC>\<^esub> \<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
shows "L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau> a b\<lparr>ArrVal\<rparr>\<lparr>f\<rparr> = \<tau>\<lparr>NTMap\<rparr>\<lparr>0, b, f\<rparr>\<^sub>\<bullet>"
proof-
interpret \<KK>: is_functor \<alpha> \<BB> \<CC> \<KK> by (rule assms(1))
interpret \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule assms(2))
from assms(3) have c: "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>" by auto
show ?thesis by (rule L_10_5_\<upsilon>_arrow_ArrVal_app[OF assms(1,2,3)])
qed
subsubsection\<open>\<open>L_10_5_\<upsilon>_arrow\<close> is an arrow\<close>
lemma L_10_5_\<upsilon>_arrow_ArrVal_is_arr:
assumes "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "\<tau>' = ntcf_arrow \<tau>"
and "\<tau> : a <\<^sub>C\<^sub>F\<^sub>.\<^sub>c\<^sub>o\<^sub>n\<^sub>e \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "f : c \<mapsto>\<^bsub>\<CC>\<^esub> \<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
and "b \<in>\<^sub>\<circ> \<BB>\<lparr>Obj\<rparr>"
shows "L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau>' a b\<lparr>ArrVal\<rparr>\<lparr>f\<rparr> : a \<mapsto>\<^bsub>\<AA>\<^esub> \<TT>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
proof-
interpret \<KK>: is_functor \<alpha> \<BB> \<CC> \<KK> by (rule assms(1))
interpret \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule assms(2))
interpret \<tau>: is_cat_cone \<alpha> a \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close> \<AA> \<open>\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>\<close> \<tau> by (rule assms(4))
from assms(5,6) show ?thesis
unfolding assms(3)
by
(
cs_concl
cs_simp:
cat_cs_simps
L_10_5_\<upsilon>_arrow_ArrVal_app
cat_comma_cs_simps
cat_FUNCT_cs_simps
cs_intro: cat_cs_intros cat_comma_cs_intros
)
qed
lemma L_10_5_\<upsilon>_arrow_ArrVal_is_arr'[cat_Kan_cs_intros]:
assumes "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "\<tau>' = ntcf_arrow \<tau>"
and "a' = a"
and "b' = \<TT>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
and "\<AA>' = \<AA>"
and "\<tau> : a <\<^sub>C\<^sub>F\<^sub>.\<^sub>c\<^sub>o\<^sub>n\<^sub>e \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "f : c \<mapsto>\<^bsub>\<CC>\<^esub> \<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
and "b \<in>\<^sub>\<circ> \<BB>\<lparr>Obj\<rparr>"
shows "L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau>' a b\<lparr>ArrVal\<rparr>\<lparr>f\<rparr> : a' \<mapsto>\<^bsub>\<AA>\<^esub> b'"
using assms(1-3, 7-9)
unfolding assms(3-6)
by (rule L_10_5_\<upsilon>_arrow_ArrVal_is_arr)
subsubsection\<open>Further properties\<close>
lemma L_10_5_\<upsilon>_arrow_is_arr:
assumes "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
and "\<tau>' = ntcf_arrow \<tau>"
and "\<tau> : a <\<^sub>C\<^sub>F\<^sub>.\<^sub>c\<^sub>o\<^sub>n\<^sub>e \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "b \<in>\<^sub>\<circ> \<BB>\<lparr>Obj\<rparr>"
shows "L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau>' a b :
Hom \<CC> c (\<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>) \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom \<AA> a (\<TT>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)"
proof-
note L_10_5_\<upsilon>_arrow_components = L_10_5_\<upsilon>_arrow_components'[OF assms(1,2)]
interpret \<KK>: is_functor \<alpha> \<BB> \<CC> \<KK> by (rule assms(1))
interpret \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule assms(2))
interpret \<tau>: is_cat_cone \<alpha> a \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close> \<AA> \<open>\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>\<close> \<tau> by (rule assms(5))
show ?thesis
proof(intro cat_Set_is_arrI)
show "arr_Set \<alpha> (L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau>' a b)"
proof(intro arr_SetI)
show "vfsequence (L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau>' a b)"
unfolding L_10_5_\<upsilon>_arrow_def by simp
show "vcard (L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau>' a b) = 3\<^sub>\<nat>"
unfolding L_10_5_\<upsilon>_arrow_def by (simp add: nat_omega_simps)
show
"\<R>\<^sub>\<circ> (L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau>' a b\<lparr>ArrVal\<rparr>) \<subseteq>\<^sub>\<circ>
L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau>' a b\<lparr>ArrCod\<rparr>"
unfolding L_10_5_\<upsilon>_arrow_components
proof(intro vrange_VLambda_vsubset, unfold in_Hom_iff)
fix f assume "f : c \<mapsto>\<^bsub>\<CC>\<^esub> \<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
from L_10_5_\<upsilon>_arrow_ArrVal_is_arr[OF assms(1,2,4,5) this assms(6)] this
show "\<tau>'\<lparr>NTMap\<rparr>\<lparr>0, b, f\<rparr>\<^sub>\<bullet> : a \<mapsto>\<^bsub>\<AA>\<^esub> \<TT>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
by
(
cs_prems cs_shallow
cs_simp: L_10_5_\<upsilon>_arrow_ArrVal_app' cat_cs_simps
cs_intro: cat_cs_intros
)
qed
from assms(3,6) show "L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau>' a b\<lparr>ArrDom\<rparr> \<in>\<^sub>\<circ> Vset \<alpha>"
by (cs_concl cs_simp: cat_Kan_cs_simps cs_intro: cat_cs_intros)
from assms(1-3,6) \<tau>.cat_cone_obj show
"L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau>' a b\<lparr>ArrCod\<rparr> \<in>\<^sub>\<circ> Vset \<alpha>"
by (cs_concl cs_simp: cat_Kan_cs_simps cs_intro: cat_cs_intros)
qed (auto simp: L_10_5_\<upsilon>_arrow_components)
qed (simp_all add: L_10_5_\<upsilon>_arrow_components)
qed
lemma L_10_5_\<upsilon>_arrow_is_arr'[cat_Kan_cs_intros]:
assumes "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
and "\<tau>' = ntcf_arrow \<tau>"
and "\<tau> : a <\<^sub>C\<^sub>F\<^sub>.\<^sub>c\<^sub>o\<^sub>n\<^sub>e \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "b \<in>\<^sub>\<circ> \<BB>\<lparr>Obj\<rparr>"
and "A = Hom \<CC> c (\<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)"
and "B = Hom \<AA> a (\<TT>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)"
and "\<CC>' = cat_Set \<alpha>"
shows "L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau>' a b : A \<mapsto>\<^bsub>\<CC>'\<^esub> B"
using assms(1-6) unfolding assms(7-9) by (rule L_10_5_\<upsilon>_arrow_is_arr)
lemma L_10_5_\<upsilon>_cf_hom[cat_Kan_cs_simps]:
assumes "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
and "\<tau>' = ntcf_arrow \<tau>"
and "\<tau> : a <\<^sub>C\<^sub>F\<^sub>.\<^sub>c\<^sub>o\<^sub>n\<^sub>e \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
and "f : a' \<mapsto>\<^bsub>\<BB>\<^esub> b'"
shows
"L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau>' a b' \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub>
cf_hom \<CC> [\<CC>\<lparr>CId\<rparr>\<lparr>c\<rparr>, \<KK>\<lparr>ArrMap\<rparr>\<lparr>f\<rparr>]\<^sub>\<circ> =
cf_hom \<AA> [\<AA>\<lparr>CId\<rparr>\<lparr>a\<rparr>, \<TT>\<lparr>ArrMap\<rparr>\<lparr>f\<rparr>]\<^sub>\<circ> \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub>
L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau>' a a'"
(is "?lhs = ?rhs")
proof-
interpret \<KK>: is_functor \<alpha> \<BB> \<CC> \<KK> by (rule assms(1))
interpret \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule assms(2))
interpret \<tau>: is_cat_cone \<alpha> a \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close> \<AA> \<open>\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>\<close> \<tau> by (rule assms(5))
have [cat_Kan_cs_simps]:
"\<tau>\<lparr>NTMap\<rparr>\<lparr>a'', b'', \<KK>\<lparr>ArrMap\<rparr>\<lparr>h'\<rparr> \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> f'\<rparr>\<^sub>\<bullet> =
\<TT>\<lparr>ArrMap\<rparr>\<lparr>h'\<rparr> \<circ>\<^sub>A\<^bsub>\<AA>\<^esub> \<tau>\<lparr>NTMap\<rparr>\<lparr>a', b', f'\<rparr>\<^sub>\<bullet>"
if F_def: "F = [[a', b', f']\<^sub>\<circ>, [a'', b'', f'']\<^sub>\<circ>, [g', h']\<^sub>\<circ>]\<^sub>\<circ>"
and A_def: "A = [a', b', f']\<^sub>\<circ>"
and B_def: "B = [a'', b'', f'']\<^sub>\<circ>"
and F: "F : A \<mapsto>\<^bsub>c \<down>\<^sub>C\<^sub>F \<KK>\<^esub> B"
for F A B a' b' f' a'' b'' f'' g' h'
proof-
from F[unfolded F_def A_def B_def] assms(3) have a'_def: "a' = 0"
and a''_def: "a'' = 0"
and g'_def: "g' = 0"
and h': "h' : b' \<mapsto>\<^bsub>\<BB>\<^esub> b''"
and f': "f' : c \<mapsto>\<^bsub>\<CC>\<^esub> \<KK>\<lparr>ObjMap\<rparr>\<lparr>b'\<rparr>"
and f'': "f'' : c \<mapsto>\<^bsub>\<CC>\<^esub> \<KK>\<lparr>ObjMap\<rparr>\<lparr>b''\<rparr>"
and f''_def: "\<KK>\<lparr>ArrMap\<rparr>\<lparr>h'\<rparr> \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> f' = f''"
by auto
note \<tau>.cat_cone_Comp_commute[cat_cs_simps del]
from
\<tau>.ntcf_Comp_commute[OF F]
that(2) F g' h' f' f''
\<KK>.is_functor_axioms
\<TT>.is_functor_axioms
show
"\<tau>\<lparr>NTMap\<rparr>\<lparr>a'', b'', \<KK>\<lparr>ArrMap\<rparr>\<lparr>h'\<rparr> \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> f'\<rparr>\<^sub>\<bullet> =
\<TT>\<lparr>ArrMap\<rparr>\<lparr>h'\<rparr> \<circ>\<^sub>A\<^bsub>\<AA>\<^esub> \<tau>\<lparr>NTMap\<rparr>\<lparr>a', b', f'\<rparr>\<^sub>\<bullet>"
unfolding F_def A_def B_def a'_def a''_def g'_def
by (*slow*)
(
cs_prems
cs_simp: cat_cs_simps cat_comma_cs_simps f''_def[symmetric]
cs_intro: cat_cs_intros cat_comma_cs_intros
)
qed
from assms(3) assms(6,7) \<KK>.HomCod.category_axioms have lhs_is_arr:
"?lhs : Hom \<CC> c (\<KK>\<lparr>ObjMap\<rparr>\<lparr>a'\<rparr>) \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom \<AA> a (\<TT>\<lparr>ObjMap\<rparr>\<lparr>b'\<rparr>)"
unfolding assms(4)
by
(
cs_concl cs_intro:
cat_lim_cs_intros
cat_cs_intros
cat_Kan_cs_intros
cat_prod_cs_intros
cat_op_intros
)
then have dom_lhs: "\<D>\<^sub>\<circ> ((?lhs)\<lparr>ArrVal\<rparr>) = Hom \<CC> c (\<KK>\<lparr>ObjMap\<rparr>\<lparr>a'\<rparr>)"
by (cs_concl cs_shallow cs_simp: cat_cs_simps)
from assms(3) assms(6,7) \<KK>.HomCod.category_axioms \<TT>.HomCod.category_axioms
have rhs_is_arr:
"?rhs : Hom \<CC> c (\<KK>\<lparr>ObjMap\<rparr>\<lparr>a'\<rparr>) \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom \<AA> a (\<TT>\<lparr>ObjMap\<rparr>\<lparr>b'\<rparr>)"
unfolding assms(4)
by
(
cs_concl cs_intro:
cat_lim_cs_intros
cat_cs_intros
cat_Kan_cs_intros
cat_prod_cs_intros
cat_op_intros
)
then have dom_rhs: "\<D>\<^sub>\<circ> ((?rhs)\<lparr>ArrVal\<rparr>) = Hom \<CC> c (\<KK>\<lparr>ObjMap\<rparr>\<lparr>a'\<rparr>)"
by (cs_concl cs_shallow cs_simp: cat_cs_simps)
show ?thesis
proof(rule arr_Set_eqI)
from lhs_is_arr show arr_Set_lhs: "arr_Set \<alpha> ?lhs"
by (auto dest: cat_Set_is_arrD(1))
from rhs_is_arr show arr_Set_rhs: "arr_Set \<alpha> ?rhs"
by (auto dest: cat_Set_is_arrD(1))
show "?lhs\<lparr>ArrVal\<rparr> = ?rhs\<lparr>ArrVal\<rparr>"
proof(rule vsv_eqI, unfold dom_lhs dom_rhs in_Hom_iff)
fix g assume prems: "g : c \<mapsto>\<^bsub>\<CC>\<^esub> \<KK>\<lparr>ObjMap\<rparr>\<lparr>a'\<rparr>"
from prems assms(7) have \<KK>f:
"\<KK>\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> g : c \<mapsto>\<^bsub>\<CC>\<^esub> \<KK>\<lparr>ObjMap\<rparr>\<lparr>b'\<rparr>"
by (cs_concl cs_shallow cs_intro: cat_cs_intros)
with assms(6,7) prems \<KK>.HomCod.category_axioms \<TT>.HomCod.category_axioms
show "?lhs\<lparr>ArrVal\<rparr>\<lparr>g\<rparr> = ?rhs\<lparr>ArrVal\<rparr>\<lparr>g\<rparr>"
by (*slow*)
(
cs_concl
cs_intro:
cat_lim_cs_intros
cat_cs_intros
cat_Kan_cs_intros
cat_comma_cs_intros
cat_prod_cs_intros
cat_op_intros
cat_1_is_arrI
cs_simp:
L_10_5_\<upsilon>_arrow_ArrVal_app'
cat_cs_simps
cat_Kan_cs_simps
cat_op_simps
cat_FUNCT_cs_simps
cat_comma_cs_simps
assms(4)
)+
qed (use arr_Set_lhs arr_Set_rhs in auto)
qed
(
use lhs_is_arr rhs_is_arr in
\<open>cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros\<close>
)+
qed
subsection\<open>Lemma X.5: \<open>L_10_5_\<tau>\<close>\<close>
subsubsection\<open>Definition and elementary properties\<close>
definition L_10_5_\<tau> where "L_10_5_\<tau> \<TT> \<KK> c \<upsilon> a =
[
(\<lambda>bf\<in>\<^sub>\<circ>c \<down>\<^sub>C\<^sub>F \<KK>\<lparr>Obj\<rparr>. \<upsilon>\<lparr>NTMap\<rparr>\<lparr>bf\<lparr>1\<^sub>\<nat>\<rparr>\<rparr>\<lparr>ArrVal\<rparr>\<lparr>bf\<lparr>2\<^sub>\<nat>\<rparr>\<rparr>),
cf_const (c \<down>\<^sub>C\<^sub>F \<KK>) (\<TT>\<lparr>HomCod\<rparr>) a,
\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>,
c \<down>\<^sub>C\<^sub>F \<KK>,
(\<TT>\<lparr>HomCod\<rparr>)
]\<^sub>\<circ>"
text\<open>Components.\<close>
lemma L_10_5_\<tau>_components:
shows "L_10_5_\<tau> \<TT> \<KK> c \<upsilon> a\<lparr>NTMap\<rparr> =
(\<lambda>bf\<in>\<^sub>\<circ>c \<down>\<^sub>C\<^sub>F \<KK>\<lparr>Obj\<rparr>. \<upsilon>\<lparr>NTMap\<rparr>\<lparr>bf\<lparr>1\<^sub>\<nat>\<rparr>\<rparr>\<lparr>ArrVal\<rparr>\<lparr>bf\<lparr>2\<^sub>\<nat>\<rparr>\<rparr>)"
and "L_10_5_\<tau> \<TT> \<KK> c \<upsilon> a\<lparr>NTDom\<rparr> = cf_const (c \<down>\<^sub>C\<^sub>F \<KK>) (\<TT>\<lparr>HomCod\<rparr>) a"
and "L_10_5_\<tau> \<TT> \<KK> c \<upsilon> a\<lparr>NTCod\<rparr> = \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>"
and "L_10_5_\<tau> \<TT> \<KK> c \<upsilon> a\<lparr>NTDGDom\<rparr> = c \<down>\<^sub>C\<^sub>F \<KK>"
and "L_10_5_\<tau> \<TT> \<KK> c \<upsilon> a\<lparr>NTDGCod\<rparr> = (\<TT>\<lparr>HomCod\<rparr>)"
unfolding L_10_5_\<tau>_def nt_field_simps by (simp_all add: nat_omega_simps)
context
fixes \<alpha> \<BB> \<CC> \<AA> \<KK> \<TT>
assumes \<KK>: "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and \<TT>: "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
begin
interpretation \<KK>: is_functor \<alpha> \<BB> \<CC> \<KK> by (rule \<KK>)
interpretation \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule \<TT>)
lemmas L_10_5_\<tau>_components' = L_10_5_\<tau>_components[
where \<TT>=\<TT> and \<KK>=\<KK>, unfolded cat_cs_simps
]
lemmas [cat_Kan_cs_simps] = L_10_5_\<tau>_components'(2-5)
end
subsubsection\<open>Natural transformation map\<close>
mk_VLambda L_10_5_\<tau>_components(1)
|vsv L_10_5_\<tau>_NTMap_vsv[cat_Kan_cs_intros]|
|vdomain L_10_5_\<tau>_NTMap_vdomain[cat_Kan_cs_simps]|
lemma L_10_5_\<tau>_NTMap_app[cat_Kan_cs_simps]:
assumes "bf = [0, b, f]\<^sub>\<circ>" and "bf \<in>\<^sub>\<circ> c \<down>\<^sub>C\<^sub>F \<KK>\<lparr>Obj\<rparr>"
shows "L_10_5_\<tau> \<TT> \<KK> c \<upsilon> a\<lparr>NTMap\<rparr>\<lparr>bf\<rparr> = \<upsilon>\<lparr>NTMap\<rparr>\<lparr>b\<rparr>\<lparr>ArrVal\<rparr>\<lparr>f\<rparr>"
using assms unfolding L_10_5_\<tau>_components by (simp add: nat_omega_simps)
subsubsection\<open>\<open>L_10_5_\<tau>\<close> is a cone\<close>
lemma L_10_5_\<tau>_is_cat_cone[cat_cs_intros]:
assumes "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
and \<upsilon>'_def: "\<upsilon>' = ntcf_arrow \<upsilon>"
and \<upsilon>: "\<upsilon> :
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(c,-) \<circ>\<^sub>C\<^sub>F \<KK> \<mapsto>\<^sub>C\<^sub>F Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-) \<circ>\<^sub>C\<^sub>F \<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
and a: "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
shows "L_10_5_\<tau> \<TT> \<KK> c \<upsilon>' a : a <\<^sub>C\<^sub>F\<^sub>.\<^sub>c\<^sub>o\<^sub>n\<^sub>e \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
proof-
let ?H_\<CC> = \<open>\<lambda>c. Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(c,-)\<close>
let ?H_\<AA> = \<open>\<lambda>a. Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-)\<close>
interpret \<KK>: is_functor \<alpha> \<BB> \<CC> \<KK> by (rule assms(1))
interpret \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule assms(2))
from assms(3) interpret c\<KK>: category \<alpha> \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close>
by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)
from assms(3) interpret \<Pi>c: is_functor \<alpha> \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close> \<BB> \<open>c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>\<close>
by
(
cs_concl cs_shallow
cs_simp: cat_comma_cs_simps
cs_intro: cat_cs_intros cat_comma_cs_intros
)
interpret \<upsilon>: is_ntcf \<alpha> \<BB> \<open>cat_Set \<alpha>\<close> \<open>?H_\<CC> c \<circ>\<^sub>C\<^sub>F \<KK>\<close> \<open>?H_\<AA> a \<circ>\<^sub>C\<^sub>F \<TT>\<close> \<upsilon>
by (rule \<upsilon>)
show ?thesis
proof(intro is_cat_coneI is_ntcfI')
show "vfsequence (L_10_5_\<tau> \<TT> \<KK> c \<upsilon>' a)" unfolding L_10_5_\<tau>_def by simp
show "vcard (L_10_5_\<tau> \<TT> \<KK> c \<upsilon>' a) = 5\<^sub>\<nat>"
unfolding L_10_5_\<tau>_def by (simp add: nat_omega_simps)
from a interpret cf_const:
is_functor \<alpha> \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close> \<AA> \<open>cf_const (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> a\<close>
by (cs_concl cs_intro: cat_cs_intros)
show "L_10_5_\<tau> \<TT> \<KK> c \<upsilon>' a\<lparr>NTMap\<rparr>\<lparr>bf\<rparr> :
cf_const (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> a\<lparr>ObjMap\<rparr>\<lparr>bf\<rparr> \<mapsto>\<^bsub>\<AA>\<^esub> (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)\<lparr>ObjMap\<rparr>\<lparr>bf\<rparr>"
if "bf \<in>\<^sub>\<circ> c \<down>\<^sub>C\<^sub>F \<KK>\<lparr>Obj\<rparr>" for bf
proof-
from that assms(3) obtain b f
where bf_def: "bf = [0, b, f]\<^sub>\<circ>"
and b: "b \<in>\<^sub>\<circ> \<BB>\<lparr>Obj\<rparr>"
and f: "f : c \<mapsto>\<^bsub>\<CC>\<^esub> \<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
by auto
from \<upsilon>.ntcf_NTMap_is_arr[OF b] a b assms(3) f have "\<upsilon>\<lparr>NTMap\<rparr>\<lparr>b\<rparr> :
Hom \<CC> c (\<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>) \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom \<AA> a (\<TT>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)"
by
(
cs_prems cs_shallow
cs_simp: cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros cat_op_intros
)
with that b f show "L_10_5_\<tau> \<TT> \<KK> c \<upsilon>' a\<lparr>NTMap\<rparr>\<lparr>bf\<rparr> :
cf_const (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> a\<lparr>ObjMap\<rparr>\<lparr>bf\<rparr> \<mapsto>\<^bsub>\<AA>\<^esub> (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)\<lparr>ObjMap\<rparr>\<lparr>bf\<rparr>"
unfolding bf_def \<upsilon>'_def
by
(
cs_concl
cs_simp:
cat_cs_simps
cat_Kan_cs_simps
cat_comma_cs_simps
cat_FUNCT_cs_simps
cs_intro: cat_cs_intros cat_comma_cs_intros
)
qed
show
"L_10_5_\<tau> \<TT> \<KK> c \<upsilon>' a\<lparr>NTMap\<rparr>\<lparr>B\<rparr> \<circ>\<^sub>A\<^bsub>\<AA>\<^esub> cf_const (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> a\<lparr>ArrMap\<rparr>\<lparr>F\<rparr> =
(\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)\<lparr>ArrMap\<rparr>\<lparr>F\<rparr> \<circ>\<^sub>A\<^bsub>\<AA>\<^esub> L_10_5_\<tau> \<TT> \<KK> c \<upsilon>' a\<lparr>NTMap\<rparr>\<lparr>A\<rparr>"
if "F : A \<mapsto>\<^bsub>c \<down>\<^sub>C\<^sub>F \<KK>\<^esub> B" for A B F
proof-
from \<KK>.is_functor_axioms that assms(3) obtain a' f a'' f' g
where F_def: "F = [[0, a', f]\<^sub>\<circ>, [0, a'', f']\<^sub>\<circ>, [0, g]\<^sub>\<circ>]\<^sub>\<circ>"
and A_def: "A = [0, a', f]\<^sub>\<circ>"
and B_def: "B = [0, a'', f']\<^sub>\<circ>"
and g: "g : a' \<mapsto>\<^bsub>\<BB>\<^esub> a''"
and f: "f : c \<mapsto>\<^bsub>\<CC>\<^esub> \<KK>\<lparr>ObjMap\<rparr>\<lparr>a'\<rparr>"
and f': "f' : c \<mapsto>\<^bsub>\<CC>\<^esub> \<KK>\<lparr>ObjMap\<rparr>\<lparr>a''\<rparr>"
and f'_def: "\<KK>\<lparr>ArrMap\<rparr>\<lparr>g\<rparr> \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> f = f'"
by auto
from \<upsilon>.ntcf_Comp_commute[OF g] have
"(\<upsilon>\<lparr>NTMap\<rparr>\<lparr>a''\<rparr> \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub> (?H_\<CC> c \<circ>\<^sub>C\<^sub>F \<KK>)\<lparr>ArrMap\<rparr>\<lparr>g\<rparr>)\<lparr>ArrVal\<rparr>\<lparr>f\<rparr> =
((?H_\<AA> a \<circ>\<^sub>C\<^sub>F \<TT>)\<lparr>ArrMap\<rparr>\<lparr>g\<rparr> \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub> \<upsilon>\<lparr>NTMap\<rparr>\<lparr>a'\<rparr>)\<lparr>ArrVal\<rparr>\<lparr>f\<rparr>"
by simp
from this a g f f' \<KK>.HomCod.category_axioms \<TT>.HomCod.category_axioms
have [cat_cs_simps]:
"\<upsilon>\<lparr>NTMap\<rparr>\<lparr>a''\<rparr>\<lparr>ArrVal\<rparr>\<lparr>\<KK>\<lparr>ArrMap\<rparr>\<lparr>g\<rparr> \<circ>\<^sub>A\<^bsub>\<CC>\<^esub> f\<rparr> =
\<TT>\<lparr>ArrMap\<rparr>\<lparr>g\<rparr> \<circ>\<^sub>A\<^bsub>\<AA>\<^esub> \<upsilon>\<lparr>NTMap\<rparr>\<lparr>a'\<rparr>\<lparr>ArrVal\<rparr>\<lparr>f\<rparr>"
by (*slow*)
(
cs_prems
cs_simp: cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros cat_prod_cs_intros cat_op_intros
)
from that a g f f' \<KK>.HomCod.category_axioms \<TT>.HomCod.category_axioms
show ?thesis
unfolding F_def A_def B_def \<upsilon>'_def (*slow*)
by
(
cs_concl
cs_simp:
f'_def[symmetric]
cat_cs_simps
cat_Kan_cs_simps
cat_comma_cs_simps
cat_FUNCT_cs_simps
cat_op_simps
cs_intro: cat_cs_intros cat_op_intros
)
qed
qed
(
use assms in
\<open>
cs_concl
cs_simp: cat_cs_simps cat_Kan_cs_simps
cs_intro: cat_cs_intros cat_Kan_cs_intros a
\<close>
)+
qed
lemma L_10_5_\<tau>_is_cat_cone'[cat_Kan_cs_intros]:
assumes "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
and "\<upsilon>' = ntcf_arrow \<upsilon>"
and "\<FF>' = \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>"
and "c\<KK> = c \<down>\<^sub>C\<^sub>F \<KK>"
and "\<AA>' = \<AA>"
and "\<alpha>' = \<alpha>"
and "\<upsilon> :
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(c,-) \<circ>\<^sub>C\<^sub>F \<KK> \<mapsto>\<^sub>C\<^sub>F Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-) \<circ>\<^sub>C\<^sub>F \<TT> :
\<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
and "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
shows "L_10_5_\<tau> \<TT> \<KK> c \<upsilon>' a : a <\<^sub>C\<^sub>F\<^sub>.\<^sub>c\<^sub>o\<^sub>n\<^sub>e \<FF>' : c\<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>'\<^esub> \<AA>'"
using assms(1-4,9,10) unfolding assms(5-8) by (rule L_10_5_\<tau>_is_cat_cone)
subsection\<open>Lemma X.5: \<open>L_10_5_\<upsilon>\<close>\<close>
subsubsection\<open>Definition and elementary properties\<close>
definition L_10_5_\<upsilon> :: "V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V"
where "L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c \<tau> a =
[
(\<lambda>b\<in>\<^sub>\<circ>\<TT>\<lparr>HomDom\<rparr>\<lparr>Obj\<rparr>. L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau> a b),
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<KK>\<lparr>HomCod\<rparr>(c,-) \<circ>\<^sub>C\<^sub>F \<KK>,
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<TT>\<lparr>HomCod\<rparr>(a,-) \<circ>\<^sub>C\<^sub>F \<TT>,
\<TT>\<lparr>HomDom\<rparr>,
cat_Set \<alpha>
]\<^sub>\<circ>"
text\<open>Components.\<close>
lemma L_10_5_\<upsilon>_components:
shows "L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c \<tau> a\<lparr>NTMap\<rparr> =
(\<lambda>b\<in>\<^sub>\<circ>\<TT>\<lparr>HomDom\<rparr>\<lparr>Obj\<rparr>. L_10_5_\<upsilon>_arrow \<TT> \<KK> c \<tau> a b)"
and "L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c \<tau> a\<lparr>NTDom\<rparr> = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<KK>\<lparr>HomCod\<rparr>(c,-) \<circ>\<^sub>C\<^sub>F \<KK>"
and "L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c \<tau> a\<lparr>NTCod\<rparr> = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<TT>\<lparr>HomCod\<rparr>(a,-) \<circ>\<^sub>C\<^sub>F \<TT>"
and "L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c \<tau> a\<lparr>NTDGDom\<rparr> = \<TT>\<lparr>HomDom\<rparr>"
and "L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c \<tau> a\<lparr>NTDGCod\<rparr> = cat_Set \<alpha>"
unfolding L_10_5_\<upsilon>_def nt_field_simps by (simp_all add: nat_omega_simps)
context
fixes \<alpha> \<BB> \<CC> \<AA> \<KK> \<TT>
assumes \<KK>: "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>" and \<TT>: "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
begin
interpretation \<KK>: is_functor \<alpha> \<BB> \<CC> \<KK> by (rule \<KK>)
interpretation \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule \<TT>)
lemmas L_10_5_\<upsilon>_components' = L_10_5_\<upsilon>_components[
where \<TT>=\<TT> and \<KK>=\<KK>, unfolded cat_cs_simps
]
lemmas [cat_Kan_cs_simps] = L_10_5_\<upsilon>_components'(2-5)
end
subsubsection\<open>Natural transformation map\<close>
mk_VLambda L_10_5_\<upsilon>_components(1)
|vsv L_10_5_\<upsilon>_NTMap_vsv[cat_Kan_cs_intros]|
context
fixes \<alpha> \<BB> \<CC> \<AA> \<KK> \<TT>
assumes \<KK>: "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and \<TT>: "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
begin
interpretation \<KK>: is_functor \<alpha> \<BB> \<CC> \<KK> by (rule \<KK>)
interpretation \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule \<TT>)
mk_VLambda L_10_5_\<upsilon>_components'(1)[OF \<KK> \<TT>]
|vdomain L_10_5_\<upsilon>_NTMap_vdomain[cat_Kan_cs_simps]|
|app L_10_5_\<upsilon>_NTMap_app[cat_Kan_cs_simps]|
end
subsubsection\<open>\<open>L_10_5_\<upsilon>\<close> is a natural transformation\<close>
lemma L_10_5_\<upsilon>_is_ntcf:
assumes "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
and \<tau>'_def: "\<tau>' = ntcf_arrow \<tau>"
and \<tau>: "\<tau> : a <\<^sub>C\<^sub>F\<^sub>.\<^sub>c\<^sub>o\<^sub>n\<^sub>e \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and a: "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
shows "L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c \<tau>' a :
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(c,-) \<circ>\<^sub>C\<^sub>F \<KK> \<mapsto>\<^sub>C\<^sub>F Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-) \<circ>\<^sub>C\<^sub>F \<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
(is \<open>?L_10_5_\<upsilon> : ?H_\<CC> c \<circ>\<^sub>C\<^sub>F \<KK> \<mapsto>\<^sub>C\<^sub>F ?H_\<AA> a \<circ>\<^sub>C\<^sub>F \<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>\<close>)
proof-
interpret \<KK>: is_functor \<alpha> \<BB> \<CC> \<KK> by (rule assms(1))
interpret \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule assms(2))
interpret \<tau>: is_cat_cone \<alpha> a \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close> \<AA> \<open>\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>\<close> \<tau>
by (rule assms(5))
from assms(3) interpret c\<KK>: category \<alpha> \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close>
by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)
from assms(3) interpret \<Pi>c: is_functor \<alpha> \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close> \<BB> \<open>c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>\<close>
by
(
cs_concl cs_shallow
cs_simp: cat_comma_cs_simps
cs_intro: cat_cs_intros cat_comma_cs_intros
)
show "?L_10_5_\<upsilon> : ?H_\<CC> c \<circ>\<^sub>C\<^sub>F \<KK> \<mapsto>\<^sub>C\<^sub>F ?H_\<AA> a \<circ>\<^sub>C\<^sub>F \<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
proof(intro is_ntcfI')
show "vfsequence ?L_10_5_\<upsilon>" unfolding L_10_5_\<upsilon>_def by auto
show "vcard ?L_10_5_\<upsilon> = 5\<^sub>\<nat>"
unfolding L_10_5_\<upsilon>_def by (simp add: nat_omega_simps)
show "?L_10_5_\<upsilon>\<lparr>NTMap\<rparr>\<lparr>b\<rparr> :
(?H_\<CC> c \<circ>\<^sub>C\<^sub>F \<KK>)\<lparr>ObjMap\<rparr>\<lparr>b\<rparr> \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> (?H_\<AA> a \<circ>\<^sub>C\<^sub>F \<TT>)\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
if "b \<in>\<^sub>\<circ> \<BB>\<lparr>Obj\<rparr>" for b
proof-
from a that assms(3) show ?thesis
unfolding \<tau>'_def
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_Kan_cs_simps
cs_intro:
cat_Kan_cs_intros
cat_lim_cs_intros
cat_cs_intros
cat_op_intros
)
qed
show
"?L_10_5_\<upsilon>\<lparr>NTMap\<rparr>\<lparr>b'\<rparr> \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub> (?H_\<CC> c \<circ>\<^sub>C\<^sub>F \<KK>)\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> =
(?H_\<AA> a \<circ>\<^sub>C\<^sub>F \<TT>)\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub> ?L_10_5_\<upsilon>\<lparr>NTMap\<rparr>\<lparr>a'\<rparr>"
if "f : a' \<mapsto>\<^bsub>\<BB>\<^esub> b'" for a' b' f
proof-
from that a assms(3) show ?thesis
by
(
cs_concl
cs_simp: cat_cs_simps cat_Kan_cs_simps cat_op_simps \<tau>'_def
cs_intro: cat_lim_cs_intros cat_cs_intros
)
qed
qed
(
use assms(3,6) in
\<open>
cs_concl
cs_simp: cat_cs_simps cat_Kan_cs_simps
cs_intro: cat_cs_intros cat_Kan_cs_intros
\<close>
)+
qed
lemma L_10_5_\<upsilon>_is_ntcf'[cat_Kan_cs_intros]:
assumes "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
and "\<tau>' = ntcf_arrow \<tau>"
and "\<FF>' = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(c,-) \<circ>\<^sub>C\<^sub>F \<KK>"
and "\<GG>' = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-) \<circ>\<^sub>C\<^sub>F \<TT>"
and "\<BB>' = \<BB>"
and "\<CC>' = cat_Set \<alpha>"
and "\<alpha>' = \<alpha>"
and "\<tau> : a <\<^sub>C\<^sub>F\<^sub>.\<^sub>c\<^sub>o\<^sub>n\<^sub>e \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
shows "L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c \<tau>' a : \<FF>' \<mapsto>\<^sub>C\<^sub>F \<GG>' : \<BB>' \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>'\<^esub> \<CC>'"
using assms(1-4,10,11) unfolding assms(5-9) by (rule L_10_5_\<upsilon>_is_ntcf)
subsection\<open>Lemma X.5: \<open>L_10_5_\<chi>_arrow\<close>\<close>
subsubsection\<open>Definition and elementary properties\<close>
definition L_10_5_\<chi>_arrow
where "L_10_5_\<chi>_arrow \<alpha> \<beta> \<TT> \<KK> c a =
[
(\<lambda>\<upsilon>\<in>\<^sub>\<circ>L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>. ntcf_arrow (L_10_5_\<tau> \<TT> \<KK> c \<upsilon> a)),
L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>,
cf_Cone \<alpha> \<beta> (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>
]\<^sub>\<circ>"
text\<open>Components.\<close>
lemma L_10_5_\<chi>_arrow_components:
shows "L_10_5_\<chi>_arrow \<alpha> \<beta> \<TT> \<KK> c a\<lparr>ArrVal\<rparr> =
(\<lambda>\<upsilon>\<in>\<^sub>\<circ>L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>. ntcf_arrow (L_10_5_\<tau> \<TT> \<KK> c \<upsilon> a))"
and "L_10_5_\<chi>_arrow \<alpha> \<beta> \<TT> \<KK> c a\<lparr>ArrDom\<rparr> = L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
and "L_10_5_\<chi>_arrow \<alpha> \<beta> \<TT> \<KK> c a\<lparr>ArrCod\<rparr> =
cf_Cone \<alpha> \<beta> (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
unfolding L_10_5_\<chi>_arrow_def arr_field_simps
by (simp_all add: nat_omega_simps)
lemmas [cat_Kan_cs_simps] = L_10_5_\<chi>_arrow_components(2,3)
subsubsection\<open>Arrow value\<close>
mk_VLambda L_10_5_\<chi>_arrow_components(1)
|vsv L_10_5_\<chi>_arrow_vsv[cat_Kan_cs_intros]|
|vdomain L_10_5_\<chi>_arrow_vdomain|
|app L_10_5_\<chi>_arrow_app|
lemma L_10_5_\<chi>_arrow_vdomain'[cat_Kan_cs_simps]:
assumes "\<Z> \<beta>"
and "\<alpha> \<in>\<^sub>\<circ> \<beta>"
and "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
and "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
shows "\<D>\<^sub>\<circ> (L_10_5_\<chi>_arrow \<alpha> \<beta> \<TT> \<KK> c a\<lparr>ArrVal\<rparr>) = Hom
(cat_FUNCT \<alpha> \<BB> (cat_Set \<alpha>))
(cf_map (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(c,-) \<circ>\<^sub>C\<^sub>F \<KK>))
(cf_map (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-) \<circ>\<^sub>C\<^sub>F \<TT>))"
using assms
by
(
cs_concl
cs_simp: cat_cs_simps cat_Kan_cs_simps L_10_5_\<chi>_arrow_vdomain
cs_intro: cat_cs_intros
)
lemma L_10_5_\<chi>_arrow_app'[cat_Kan_cs_simps]:
assumes "\<Z> \<beta>"
and "\<alpha> \<in>\<^sub>\<circ> \<beta>"
and "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
and \<upsilon>'_def: "\<upsilon>' = ntcf_arrow \<upsilon>"
and \<upsilon>: "\<upsilon> :
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(c,-) \<circ>\<^sub>C\<^sub>F \<KK> \<mapsto>\<^sub>C\<^sub>F Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-) \<circ>\<^sub>C\<^sub>F \<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
and a: "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
shows
"L_10_5_\<chi>_arrow \<alpha> \<beta> \<TT> \<KK> c a\<lparr>ArrVal\<rparr>\<lparr>\<upsilon>'\<rparr> =
ntcf_arrow (L_10_5_\<tau> \<TT> \<KK> c \<upsilon>' a)"
using assms
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_Kan_cs_simps L_10_5_\<chi>_arrow_app
cs_intro: cat_cs_intros cat_FUNCT_cs_intros
)
lemma \<upsilon>\<tau>a_def:
assumes "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
and \<upsilon>\<tau>a'_def: "\<upsilon>\<tau>a' = ntcf_arrow \<upsilon>\<tau>a"
and \<upsilon>\<tau>a: "\<upsilon>\<tau>a :
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(c,-) \<circ>\<^sub>C\<^sub>F \<KK> \<mapsto>\<^sub>C\<^sub>F Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-) \<circ>\<^sub>C\<^sub>F \<TT> :
\<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
and a: "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
shows "\<upsilon>\<tau>a = L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c (ntcf_arrow (L_10_5_\<tau> \<TT> \<KK> c \<upsilon>\<tau>a' a)) a"
(is \<open>\<upsilon>\<tau>a = ?L_10_5_\<upsilon> (ntcf_arrow ?L_10_5_\<tau>) a\<close>)
proof-
interpret \<KK>: is_functor \<alpha> \<BB> \<CC> \<KK> by (rule assms(1))
interpret \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule assms(2))
interpret \<upsilon>\<tau>a: is_ntcf
\<alpha> \<BB> \<open>cat_Set \<alpha>\<close> \<open>Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(c,-) \<circ>\<^sub>C\<^sub>F \<KK>\<close> \<open>Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-) \<circ>\<^sub>C\<^sub>F \<TT>\<close> \<upsilon>\<tau>a
by (rule \<upsilon>\<tau>a)
show ?thesis
proof(rule ntcf_eqI)
show "\<upsilon>\<tau>a :
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(c,-) \<circ>\<^sub>C\<^sub>F \<KK> \<mapsto>\<^sub>C\<^sub>F Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-) \<circ>\<^sub>C\<^sub>F \<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
by (rule \<upsilon>\<tau>a)
from assms(1-3) a show
"?L_10_5_\<upsilon> (ntcf_arrow ?L_10_5_\<tau>) a :
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(c,-) \<circ>\<^sub>C\<^sub>F \<KK> \<mapsto>\<^sub>C\<^sub>F Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-) \<circ>\<^sub>C\<^sub>F \<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
by
(
cs_concl
cs_simp: cat_Kan_cs_simps \<upsilon>\<tau>a'_def
cs_intro: cat_cs_intros cat_Kan_cs_intros
)
have dom_lhs: "\<D>\<^sub>\<circ> (\<upsilon>\<tau>a\<lparr>NTMap\<rparr>) = \<BB>\<lparr>Obj\<rparr>"
by (cs_concl cs_shallow cs_simp: cat_cs_simps)
have dom_rhs: "\<D>\<^sub>\<circ> (?L_10_5_\<upsilon> (ntcf_arrow (?L_10_5_\<tau>)) a\<lparr>NTMap\<rparr>) = \<BB>\<lparr>Obj\<rparr>"
by (cs_concl cs_shallow cs_simp: cat_Kan_cs_simps cs_intro: cat_cs_intros)
show "\<upsilon>\<tau>a\<lparr>NTMap\<rparr> = ?L_10_5_\<upsilon> (ntcf_arrow ?L_10_5_\<tau>) a\<lparr>NTMap\<rparr>"
proof(rule vsv_eqI, unfold dom_lhs dom_rhs)
fix b assume prems: "b \<in>\<^sub>\<circ> \<BB>\<lparr>Obj\<rparr>"
from prems assms(3) a have lhs: "\<upsilon>\<tau>a\<lparr>NTMap\<rparr>\<lparr>b\<rparr> :
Hom \<CC> c (\<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>) \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom \<AA> a (\<TT>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)"
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_op_intros
)
then have dom_lhs: "\<D>\<^sub>\<circ> (\<upsilon>\<tau>a\<lparr>NTMap\<rparr>\<lparr>b\<rparr>\<lparr>ArrVal\<rparr>) = Hom \<CC> c (\<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)"
by (cs_concl cs_shallow cs_simp: cat_cs_simps)
from prems assms(3) a have rhs:
"L_10_5_\<upsilon>_arrow \<TT> \<KK> c (ntcf_arrow ?L_10_5_\<tau>) a b :
Hom \<CC> c (\<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>) \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom \<AA> a (\<TT>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)"
unfolding \<upsilon>\<tau>a'_def
by
(
cs_concl cs_shallow
cs_simp: cat_Kan_cs_simps
cs_intro: cat_Kan_cs_intros cat_cs_intros
)
then have dom_rhs:
"\<D>\<^sub>\<circ> (L_10_5_\<upsilon>_arrow \<TT> \<KK> c (ntcf_arrow ?L_10_5_\<tau>) a b\<lparr>ArrVal\<rparr>) =
Hom \<CC> c (\<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)"
by (cs_concl cs_shallow cs_simp: cat_cs_simps)
have [cat_cs_simps]:
"\<upsilon>\<tau>a\<lparr>NTMap\<rparr>\<lparr>b\<rparr> = L_10_5_\<upsilon>_arrow \<TT> \<KK> c (ntcf_arrow ?L_10_5_\<tau>) a b"
proof(rule arr_Set_eqI)
from lhs show arr_Set_lhs: "arr_Set \<alpha> (\<upsilon>\<tau>a\<lparr>NTMap\<rparr>\<lparr>b\<rparr>)"
by (auto dest: cat_Set_is_arrD(1))
from rhs show arr_Set_rhs:
"arr_Set \<alpha> (L_10_5_\<upsilon>_arrow \<TT> \<KK> c (ntcf_arrow (?L_10_5_\<tau>)) a b)"
by (auto dest: cat_Set_is_arrD(1))
show "\<upsilon>\<tau>a\<lparr>NTMap\<rparr>\<lparr>b\<rparr>\<lparr>ArrVal\<rparr> =
L_10_5_\<upsilon>_arrow \<TT> \<KK> c (ntcf_arrow ?L_10_5_\<tau>) a b\<lparr>ArrVal\<rparr>"
proof(rule vsv_eqI, unfold dom_lhs dom_rhs in_Hom_iff)
fix f assume "f : c \<mapsto>\<^bsub>\<CC>\<^esub> \<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
with assms prems show
"\<upsilon>\<tau>a\<lparr>NTMap\<rparr>\<lparr>b\<rparr>\<lparr>ArrVal\<rparr>\<lparr>f\<rparr> =
L_10_5_\<upsilon>_arrow \<TT> \<KK> c (ntcf_arrow ?L_10_5_\<tau>) a b\<lparr>ArrVal\<rparr>\<lparr>f\<rparr>"
unfolding \<upsilon>\<tau>a'_def
by
(
cs_concl cs_shallow
cs_simp:
cat_Kan_cs_simps cat_FUNCT_cs_simps L_10_5_\<upsilon>_arrow_ArrVal_app
cs_intro: cat_cs_intros cat_comma_cs_intros
)
qed (use arr_Set_lhs arr_Set_rhs in auto)
qed (use lhs rhs in \<open>cs_concl cs_shallow cs_simp: cat_cs_simps\<close>)+
from prems show
"\<upsilon>\<tau>a\<lparr>NTMap\<rparr>\<lparr>b\<rparr> = L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c (ntcf_arrow ?L_10_5_\<tau>) a\<lparr>NTMap\<rparr>\<lparr>b\<rparr>"
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_Kan_cs_simps cs_intro: cat_cs_intros
)
qed (cs_concl cs_intro: cat_cs_intros cat_Kan_cs_intros V_cs_intros)+
qed simp_all
qed
subsection\<open>Lemma X.5: \<open>L_10_5_\<chi>'_arrow\<close>\<close>
subsubsection\<open>Definition and elementary properties\<close>
definition L_10_5_\<chi>'_arrow :: "V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V"
where "L_10_5_\<chi>'_arrow \<alpha> \<beta> \<TT> \<KK> c a =
[
(
\<lambda>\<tau>\<in>\<^sub>\<circ>cf_Cone \<alpha> \<beta> (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>.
ntcf_arrow (L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c \<tau> a)
),
cf_Cone \<alpha> \<beta> (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>,
L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>
]\<^sub>\<circ>"
text\<open>Components.\<close>
lemma L_10_5_\<chi>'_arrow_components:
shows "L_10_5_\<chi>'_arrow \<alpha> \<beta> \<TT> \<KK> c a\<lparr>ArrVal\<rparr> =
(
\<lambda>\<tau>\<in>\<^sub>\<circ>cf_Cone \<alpha> \<beta> (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>.
ntcf_arrow (L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c \<tau> a)
)"
and [cat_Kan_cs_simps]: "L_10_5_\<chi>'_arrow \<alpha> \<beta> \<TT> \<KK> c a\<lparr>ArrDom\<rparr> =
cf_Cone \<alpha> \<beta> (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
and [cat_Kan_cs_simps]: "L_10_5_\<chi>'_arrow \<alpha> \<beta> \<TT> \<KK> c a\<lparr>ArrCod\<rparr> =
L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
unfolding L_10_5_\<chi>'_arrow_def arr_field_simps by (simp_all add: nat_omega_simps)
subsubsection\<open>Arrow value\<close>
mk_VLambda L_10_5_\<chi>'_arrow_components(1)
|vsv L_10_5_\<chi>'_arrow_ArrVal_vsv[cat_Kan_cs_intros]|
|vdomain L_10_5_\<chi>'_arrow_ArrVal_vdomain|
|app L_10_5_\<chi>'_arrow_ArrVal_app|
lemma L_10_5_\<chi>'_arrow_ArrVal_vdomain'[cat_Kan_cs_simps]:
assumes "\<Z> \<beta>"
and "\<alpha> \<in>\<^sub>\<circ> \<beta>"
and \<tau>: "\<tau> : a <\<^sub>C\<^sub>F\<^sub>.\<^sub>c\<^sub>o\<^sub>n\<^sub>e \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and a: "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
shows "\<D>\<^sub>\<circ> (L_10_5_\<chi>'_arrow \<alpha> \<beta> \<TT> \<KK> c a\<lparr>ArrVal\<rparr>) = Hom
(cat_FUNCT \<alpha> (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA>)
(cf_map (cf_const (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> a))
(cf_map (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>))"
proof-
interpret \<beta>: \<Z> \<beta> by (rule assms(1))
interpret \<tau>: is_cat_cone \<alpha> a \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close> \<AA> \<open>\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>\<close> \<tau>
by (rule assms(3))
from assms(1,2,4) show ?thesis
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps L_10_5_\<chi>'_arrow_ArrVal_vdomain
cs_intro: cat_cs_intros
)
qed
lemma L_10_5_\<chi>'_arrow_ArrVal_app'[cat_cs_simps]:
assumes "\<Z> \<beta>"
and "\<alpha> \<in>\<^sub>\<circ> \<beta>"
and \<tau>'_def: "\<tau>' = ntcf_arrow \<tau>"
and \<tau>: "\<tau> : a <\<^sub>C\<^sub>F\<^sub>.\<^sub>c\<^sub>o\<^sub>n\<^sub>e \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and a: "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
shows "L_10_5_\<chi>'_arrow \<alpha> \<beta> \<TT> \<KK> c a\<lparr>ArrVal\<rparr>\<lparr>\<tau>'\<rparr> =
ntcf_arrow (L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c \<tau>' a)"
proof-
interpret \<beta>: \<Z> \<beta> by (rule assms(1))
interpret \<tau>: is_cat_cone \<alpha> a \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close> \<AA> \<open>\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>\<close> \<tau>
by (rule assms(4))
from assms(2,5) have "\<tau>' \<in>\<^sub>\<circ> cf_Cone \<alpha> \<beta> (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
unfolding \<tau>'_def
by
(
cs_concl
cs_simp: cat_cs_simps
cs_intro: cat_FUNCT_cs_intros cat_cs_intros
)
then show
"L_10_5_\<chi>'_arrow \<alpha> \<beta> \<TT> \<KK> c a\<lparr>ArrVal\<rparr>\<lparr>\<tau>'\<rparr> =
ntcf_arrow (L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c \<tau>' a)"
unfolding L_10_5_\<chi>'_arrow_components by auto
qed
subsubsection\<open>\<open>L_10_5_\<chi>'_arrow\<close> is an isomorphism in the category \<open>Set\<close>\<close>
lemma L_10_5_\<chi>'_arrow_is_iso_arr:
assumes "\<Z> \<beta>"
and "\<alpha> \<in>\<^sub>\<circ> \<beta>"
and "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
and "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
shows "L_10_5_\<chi>'_arrow \<alpha> \<beta> \<TT> \<KK> c a :
cf_Cone \<alpha> \<beta> (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> \<mapsto>\<^sub>i\<^sub>s\<^sub>o\<^bsub>cat_Set \<beta>\<^esub>
L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>" (*FIXME: any reason not to evaluate ObjMap?*)
(
is
\<open>
?L_10_5_\<chi>'_arrow :
cf_Cone \<alpha> \<beta> (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> \<mapsto>\<^sub>i\<^sub>s\<^sub>o\<^bsub>cat_Set \<beta>\<^esub>
?L_10_5_N\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>
\<close>
)
proof-
let ?FUNCT = \<open>\<lambda>\<AA>. cat_FUNCT \<alpha> \<AA> (cat_Set \<alpha>)\<close>
let ?c\<KK>_\<AA> = \<open>cat_FUNCT \<alpha> (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA>\<close>
let ?H_\<CC> = \<open>\<lambda>c. Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(c,-)\<close>
let ?H_\<AA> = \<open>\<lambda>c. Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-)\<close>
from assms(1,2) interpret \<beta>: \<Z> \<beta> by simp
interpret \<KK>: is_functor \<alpha> \<BB> \<CC> \<KK> by (rule assms(3))
interpret \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule assms(4))
from \<KK>.vempty_is_zet assms interpret c\<KK>: category \<alpha> \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close>
by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)
from assms(2,6) interpret c\<KK>_\<AA>: category \<beta> ?c\<KK>_\<AA>
by
(
cs_concl cs_intro:
cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros
)
from \<KK>.vempty_is_zet assms interpret \<Pi>c:
is_functor \<alpha> \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close> \<BB> \<open>c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>\<close>
by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)
from assms(2) interpret FUNCT_\<AA>: tiny_category \<beta> \<open>?FUNCT \<AA>\<close>
by (cs_concl cs_intro: cat_cs_intros cat_FUNCT_cs_intros)
from assms(2) interpret FUNCT_\<BB>: tiny_category \<beta> \<open>?FUNCT \<BB>\<close>
by (cs_concl cs_intro: cat_cs_intros cat_FUNCT_cs_intros)
from assms(2) interpret FUNCT_\<CC>: tiny_category \<beta> \<open>?FUNCT \<CC>\<close>
by (cs_concl cs_intro: cat_cs_intros cat_FUNCT_cs_intros)
have \<TT>\<Pi>: "\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
by (cs_concl cs_intro: cat_cs_intros)
from assms(5,6) have [cat_cs_simps]:
"cf_of_cf_map (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> (cf_map (cf_const (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> a)) =
cf_const (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> a"
"cf_of_cf_map (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> (cf_map (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)) = \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>"
"cf_of_cf_map \<BB> (cat_Set \<alpha>) (cf_map (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(c,-) \<circ>\<^sub>C\<^sub>F \<KK>)) =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(c,-) \<circ>\<^sub>C\<^sub>F \<KK>"
"cf_of_cf_map \<BB> (cat_Set \<alpha>) (cf_map (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-) \<circ>\<^sub>C\<^sub>F \<TT>)) =
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-) \<circ>\<^sub>C\<^sub>F \<TT>"
by (cs_concl cs_simp: cat_FUNCT_cs_simps cs_intro: cat_cs_intros)+
note cf_Cone_ObjMap_app = is_functor.cf_Cone_ObjMap_app[OF \<TT>\<Pi> assms(1,2,6)]
show ?thesis
proof
(
intro cat_Set_is_iso_arrI cat_Set_is_arrI arr_SetI,
unfold L_10_5_\<chi>'_arrow_components(3) cf_Cone_ObjMap_app
)
show "vfsequence ?L_10_5_\<chi>'_arrow"
unfolding L_10_5_\<chi>'_arrow_def by auto
show \<chi>'_arrow_ArrVal_vsv: "vsv (?L_10_5_\<chi>'_arrow\<lparr>ArrVal\<rparr>)"
unfolding L_10_5_\<chi>'_arrow_components by auto
show "vcard ?L_10_5_\<chi>'_arrow = 3\<^sub>\<nat>"
unfolding L_10_5_\<chi>'_arrow_def by (simp add: nat_omega_simps)
show [cat_cs_simps]:
"\<D>\<^sub>\<circ> (?L_10_5_\<chi>'_arrow\<lparr>ArrVal\<rparr>) = ?L_10_5_\<chi>'_arrow\<lparr>ArrDom\<rparr>"
unfolding L_10_5_\<chi>'_arrow_components by simp
show vrange_\<chi>'_arrow_vsubset_N'':
"\<R>\<^sub>\<circ> (?L_10_5_\<chi>'_arrow\<lparr>ArrVal\<rparr>) \<subseteq>\<^sub>\<circ> ?L_10_5_N\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
unfolding L_10_5_\<chi>'_arrow_components
proof(rule vrange_VLambda_vsubset)
fix \<tau> assume prems: "\<tau> \<in>\<^sub>\<circ> cf_Cone \<alpha> \<beta> (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
from this assms c\<KK>_\<AA>.category_axioms have \<tau>_is_arr:
"\<tau> : cf_map (cf_const (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> a) \<mapsto>\<^bsub>?c\<KK>_\<AA>\<^esub> cf_map (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)"
by
(
cs_prems
cs_simp: cat_cs_simps cat_Kan_cs_simps cat_FUNCT_components(1)
cs_intro: cat_cs_intros
)
note \<tau> = cat_FUNCT_is_arrD(1,2)[OF \<tau>_is_arr, unfolded cat_cs_simps]
have "cf_of_cf_map (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> (cf_map (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)) = \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>"
by (cs_concl cs_simp: cat_FUNCT_cs_simps cs_intro: cat_cs_intros)
from prems assms \<tau>(1) show
"ntcf_arrow (L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c \<tau> a) \<in>\<^sub>\<circ> ?L_10_5_N\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
by (subst \<tau>(2)) (*slow*)
(
cs_concl
cs_simp: cat_cs_simps cat_Kan_cs_simps
cs_intro:
is_cat_coneI cat_cs_intros cat_Kan_cs_intros cat_FUNCT_cs_intros
)
qed
show "\<R>\<^sub>\<circ> (?L_10_5_\<chi>'_arrow\<lparr>ArrVal\<rparr>) = ?L_10_5_N\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
proof
(
intro vsubset_antisym[OF vrange_\<chi>'_arrow_vsubset_N''],
intro vsubsetI
)
fix \<upsilon>\<tau>a assume "\<upsilon>\<tau>a \<in>\<^sub>\<circ> ?L_10_5_N\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
from this assms have \<upsilon>\<tau>a:
"\<upsilon>\<tau>a : cf_map (?H_\<CC> c \<circ>\<^sub>C\<^sub>F \<KK>) \<mapsto>\<^bsub>?FUNCT \<BB>\<^esub> cf_map (?H_\<AA> a \<circ>\<^sub>C\<^sub>F \<TT>)"
by
(
cs_prems
cs_simp: cat_cs_simps cat_Kan_cs_simps cs_intro: cat_cs_intros
)
note \<upsilon>\<tau>a = cat_FUNCT_is_arrD[OF this, unfolded cat_cs_simps]
interpret \<tau>:
is_cat_cone \<alpha> a \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close> \<AA> \<open>\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>\<close> \<open>L_10_5_\<tau> \<TT> \<KK> c \<upsilon>\<tau>a a\<close>
by (rule L_10_5_\<tau>_is_cat_cone[OF assms(3,4,5) \<upsilon>\<tau>a(2,1) assms(6)])
show "\<upsilon>\<tau>a \<in>\<^sub>\<circ> \<R>\<^sub>\<circ> (?L_10_5_\<chi>'_arrow\<lparr>ArrVal\<rparr>)"
proof(rule vsv.vsv_vimageI2')
show "vsv (?L_10_5_\<chi>'_arrow\<lparr>ArrVal\<rparr>)" by (rule \<chi>'_arrow_ArrVal_vsv)
from \<tau>.is_cat_cone_axioms assms show
"ntcf_arrow (L_10_5_\<tau> \<TT> \<KK> c \<upsilon>\<tau>a a) \<in>\<^sub>\<circ> \<D>\<^sub>\<circ> (?L_10_5_\<chi>'_arrow\<lparr>ArrVal\<rparr>)"
by
(
cs_concl
cs_simp: cat_Kan_cs_simps
cs_intro: cat_cs_intros cat_FUNCT_cs_intros
)
from assms \<upsilon>\<tau>a(1,2) show
"\<upsilon>\<tau>a = ?L_10_5_\<chi>'_arrow\<lparr>ArrVal\<rparr>\<lparr>ntcf_arrow (L_10_5_\<tau> \<TT> \<KK> c \<upsilon>\<tau>a a)\<rparr>"
by
(
subst \<upsilon>\<tau>a(2),
cs_concl_step \<upsilon>\<tau>a_def[OF assms(3,4,5) \<upsilon>\<tau>a(2,1) assms(6)]
)
(cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)
qed
qed
from assms show "?L_10_5_\<chi>'_arrow\<lparr>ArrDom\<rparr> \<in>\<^sub>\<circ> Vset \<beta>"
by
(
cs_concl
cs_simp: cat_Kan_cs_simps cat_FUNCT_components(1) cf_Cone_ObjMap_app
cs_intro: cat_cs_intros cat_FUNCT_cs_intros c\<KK>_\<AA>.cat_Hom_in_Vset
)
with assms(2) have "?L_10_5_\<chi>'_arrow\<lparr>ArrDom\<rparr> \<in>\<^sub>\<circ> Vset \<beta>"
by (meson Vset_in_mono Vset_trans)
from assms show "?L_10_5_N\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> \<in>\<^sub>\<circ> Vset \<beta>"
by
(
cs_concl
cs_simp: cat_cs_simps cat_Kan_cs_simps cat_FUNCT_cs_simps
cs_intro: cat_cs_intros FUNCT_\<BB>.cat_Hom_in_Vset cat_FUNCT_cs_intros
)
show dom_\<chi>'_arrow: "\<D>\<^sub>\<circ> (?L_10_5_\<chi>'_arrow\<lparr>ArrVal\<rparr>) =
Hom ?c\<KK>_\<AA> (cf_map (cf_const (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> a)) (cf_map (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>))"
unfolding L_10_5_\<chi>'_arrow_components cf_Cone_ObjMap_app by simp
show "?L_10_5_\<chi>'_arrow\<lparr>ArrDom\<rparr> =
Hom ?c\<KK>_\<AA> (cf_map (cf_const (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> a)) (cf_map (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>))"
unfolding L_10_5_\<chi>'_arrow_components cf_Cone_ObjMap_app by simp
show "v11 (?L_10_5_\<chi>'_arrow\<lparr>ArrVal\<rparr>)"
proof(rule vsv.vsv_valeq_v11I, unfold dom_\<chi>'_arrow in_Hom_iff)
fix \<tau>' \<tau>'' assume prems:
"\<tau>' : cf_map (cf_const (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> a) \<mapsto>\<^bsub>?c\<KK>_\<AA>\<^esub> cf_map (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)"
"\<tau>'' : cf_map (cf_const (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> a) \<mapsto>\<^bsub>?c\<KK>_\<AA>\<^esub> cf_map (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)"
"?L_10_5_\<chi>'_arrow\<lparr>ArrVal\<rparr>\<lparr>\<tau>'\<rparr> = ?L_10_5_\<chi>'_arrow\<lparr>ArrVal\<rparr>\<lparr>\<tau>''\<rparr>"
note \<tau>' = cat_FUNCT_is_arrD[OF prems(1), unfolded cat_cs_simps]
and \<tau>'' = cat_FUNCT_is_arrD[OF prems(2), unfolded cat_cs_simps]
interpret \<tau>': is_cat_cone
\<alpha> a \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close> \<AA> \<open>\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>\<close> \<open>ntcf_of_ntcf_arrow (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> \<tau>'\<close>
by (rule is_cat_coneI[OF \<tau>'(1) assms(6)])
interpret \<tau>'': is_cat_cone
\<alpha> a \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close> \<AA> \<open>\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>\<close> \<open>ntcf_of_ntcf_arrow (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> \<tau>''\<close>
by (rule is_cat_coneI[OF \<tau>''(1) assms(6)])
have \<tau>'\<tau>': "ntcf_arrow (ntcf_of_ntcf_arrow (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> \<tau>') = \<tau>'"
by (subst (2) \<tau>'(2)) (cs_concl cs_shallow cs_simp: cat_FUNCT_cs_simps)
have \<tau>''\<tau>'': "ntcf_arrow (ntcf_of_ntcf_arrow (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> \<tau>'') = \<tau>''"
by (subst (2) \<tau>''(2)) (cs_concl cs_shallow cs_simp: cat_FUNCT_cs_simps)
from prems(3) \<tau>'(1) \<tau>''(1) assms have
"L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c \<tau>' a = L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c \<tau>'' a"
by (subst (asm) \<tau>'(2), use nothing in \<open>subst (asm) \<tau>''(2)\<close>) (*slow*)
(
cs_prems cs_shallow
cs_simp: \<tau>'\<tau>' \<tau>''\<tau>'' cat_cs_simps cat_FUNCT_cs_simps
cs_intro: cat_lim_cs_intros cat_Kan_cs_intros cat_cs_intros
)
from this have \<upsilon>\<tau>'a_\<upsilon>\<tau>''a:
"L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c \<tau>' a\<lparr>NTMap\<rparr>\<lparr>b\<rparr>\<lparr>ArrVal\<rparr>\<lparr>f\<rparr> =
L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c \<tau>'' a\<lparr>NTMap\<rparr>\<lparr>b\<rparr>\<lparr>ArrVal\<rparr>\<lparr>f\<rparr>"
if "b \<in>\<^sub>\<circ> \<BB>\<lparr>Obj\<rparr>" and "f : c \<mapsto>\<^bsub>\<CC>\<^esub> (\<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)" for b f
by simp
have [cat_cs_simps]: "\<tau>'\<lparr>NTMap\<rparr>\<lparr>0, b, f\<rparr>\<^sub>\<bullet> = \<tau>''\<lparr>NTMap\<rparr>\<lparr>0, b, f\<rparr>\<^sub>\<bullet>"
if "b \<in>\<^sub>\<circ> \<BB>\<lparr>Obj\<rparr>" and "f : c \<mapsto>\<^bsub>\<CC>\<^esub> (\<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>)" for b f
using \<upsilon>\<tau>'a_\<upsilon>\<tau>''a[OF that] that
by
(
cs_prems cs_shallow
cs_simp: cat_Kan_cs_simps L_10_5_\<upsilon>_arrow_ArrVal_app
cs_intro: cat_cs_intros
)
have
"ntcf_of_ntcf_arrow (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> \<tau>' =
ntcf_of_ntcf_arrow (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> \<tau>''"
proof(rule ntcf_eqI)
show "ntcf_of_ntcf_arrow (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> \<tau>' :
cf_const (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> a \<mapsto>\<^sub>C\<^sub>F \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
by (rule \<tau>'.is_ntcf_axioms)
then have dom_lhs:
"\<D>\<^sub>\<circ> (ntcf_of_ntcf_arrow (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> \<tau>'\<lparr>NTMap\<rparr>) = c \<down>\<^sub>C\<^sub>F \<KK>\<lparr>Obj\<rparr>"
by (cs_concl cs_shallow cs_simp: cat_cs_simps)
show "ntcf_of_ntcf_arrow (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> \<tau>'' :
cf_const (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> a \<mapsto>\<^sub>C\<^sub>F \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
by (rule \<tau>''.is_ntcf_axioms)
then have dom_rhs:
"\<D>\<^sub>\<circ> (ntcf_of_ntcf_arrow (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> \<tau>''\<lparr>NTMap\<rparr>) = c \<down>\<^sub>C\<^sub>F \<KK>\<lparr>Obj\<rparr>"
by (cs_concl cs_shallow cs_simp: cat_cs_simps)
show
"ntcf_of_ntcf_arrow (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> \<tau>'\<lparr>NTMap\<rparr> =
ntcf_of_ntcf_arrow (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> \<tau>''\<lparr>NTMap\<rparr>"
proof(rule vsv_eqI, unfold dom_lhs dom_rhs)
fix A assume "A \<in>\<^sub>\<circ> c \<down>\<^sub>C\<^sub>F \<KK>\<lparr>Obj\<rparr>"
with assms(5) obtain b f
where A_def: "A = [0, b, f]\<^sub>\<circ>"
and b: "b \<in>\<^sub>\<circ> \<BB>\<lparr>Obj\<rparr>"
and f: "f : c \<mapsto>\<^bsub>\<CC>\<^esub> \<KK>\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
by auto
from b f show
"ntcf_of_ntcf_arrow (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> \<tau>'\<lparr>NTMap\<rparr>\<lparr>A\<rparr> =
ntcf_of_ntcf_arrow (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> \<tau>''\<lparr>NTMap\<rparr>\<lparr>A\<rparr>"
unfolding A_def
by (cs_concl cs_simp: cat_cs_simps cat_map_extra_cs_simps)
qed (cs_concl cs_shallow cs_intro: V_cs_intros)+
qed simp_all
then show "\<tau>' = \<tau>''"
proof(rule inj_onD[OF bij_betw_imp_inj_on[OF bij_betw_ntcf_of_ntcf_arrow]])
show "\<tau>' \<in>\<^sub>\<circ> ntcf_arrows \<alpha> (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA>"
by (subst \<tau>'(2))
(
cs_concl cs_intro:
cat_lim_cs_intros cat_cs_intros cat_FUNCT_cs_intros
)
show "\<tau>'' \<in>\<^sub>\<circ> ntcf_arrows \<alpha> (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA>"
by (subst \<tau>''(2))
(
cs_concl cs_intro:
cat_lim_cs_intros cat_cs_intros cat_FUNCT_cs_intros
)
qed
qed (cs_concl cs_shallow cs_intro: cat_Kan_cs_intros)
qed auto
qed
lemma L_10_5_\<chi>'_arrow_is_iso_arr'[cat_Kan_cs_intros]:
assumes "\<Z> \<beta>"
and "\<alpha> \<in>\<^sub>\<circ> \<beta>"
and "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
and "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
and "A = cf_Cone \<alpha> \<beta> (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
and "B = L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
and "\<CC>' = cat_Set \<beta>"
shows "L_10_5_\<chi>'_arrow \<alpha> \<beta> \<TT> \<KK> c a : A \<mapsto>\<^sub>i\<^sub>s\<^sub>o\<^bsub>\<CC>'\<^esub> B"
using assms(1-6)
unfolding assms(7-9)
by (rule L_10_5_\<chi>'_arrow_is_iso_arr)
lemma L_10_5_\<chi>'_arrow_is_arr:
assumes "\<Z> \<beta>"
and "\<alpha> \<in>\<^sub>\<circ> \<beta>"
and "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
and "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
shows "L_10_5_\<chi>'_arrow \<alpha> \<beta> \<TT> \<KK> c a :
cf_Cone \<alpha> \<beta> (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> \<mapsto>\<^bsub>cat_Set \<beta>\<^esub>
L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
by
(
rule cat_Set_is_iso_arrD(1)[
OF L_10_5_\<chi>'_arrow_is_iso_arr[OF assms(1-6)]
]
)
lemma L_10_5_\<chi>'_arrow_is_arr'[cat_Kan_cs_intros]:
assumes "\<Z> \<beta>"
and "\<alpha> \<in>\<^sub>\<circ> \<beta>"
and "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
and "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
and "A = cf_Cone \<alpha> \<beta> (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
and "B = L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
and "\<CC>' = cat_Set \<beta>"
shows "L_10_5_\<chi>'_arrow \<alpha> \<beta> \<TT> \<KK> c a : A \<mapsto>\<^bsub>\<CC>'\<^esub> B"
using assms(1-6) unfolding assms(7-9) by (rule L_10_5_\<chi>'_arrow_is_arr)
subsection\<open>Lemma X.5: \<open>L_10_5_\<chi>\<close>\label{sec:lem_X_5_end}\<close>
subsubsection\<open>Definition and elementary properties\<close>
definition L_10_5_\<chi> :: "V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V"
where "L_10_5_\<chi> \<alpha> \<beta> \<TT> \<KK> c =
[
(\<lambda>a\<in>\<^sub>\<circ>\<TT>\<lparr>HomCod\<rparr>\<lparr>Obj\<rparr>. L_10_5_\<chi>'_arrow \<alpha> \<beta> \<TT> \<KK> c a),
cf_Cone \<alpha> \<beta> (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>),
L_10_5_N \<alpha> \<beta> \<TT> \<KK> c,
op_cat (\<TT>\<lparr>HomCod\<rparr>),
cat_Set \<beta>
]\<^sub>\<circ>"
text\<open>Components.\<close>
lemma L_10_5_\<chi>_components:
shows "L_10_5_\<chi> \<alpha> \<beta> \<TT> \<KK> c\<lparr>NTMap\<rparr> =
(\<lambda>a\<in>\<^sub>\<circ>\<TT>\<lparr>HomCod\<rparr>\<lparr>Obj\<rparr>. L_10_5_\<chi>'_arrow \<alpha> \<beta> \<TT> \<KK> c a)"
and [cat_Kan_cs_simps]:
"L_10_5_\<chi> \<alpha> \<beta> \<TT> \<KK> c\<lparr>NTDom\<rparr> = cf_Cone \<alpha> \<beta> (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>)"
and [cat_Kan_cs_simps]:
"L_10_5_\<chi> \<alpha> \<beta> \<TT> \<KK> c\<lparr>NTCod\<rparr> = L_10_5_N \<alpha> \<beta> \<TT> \<KK> c"
and "L_10_5_\<chi> \<alpha> \<beta> \<TT> \<KK> c\<lparr>NTDGDom\<rparr> = op_cat (\<TT>\<lparr>HomCod\<rparr>)"
and [cat_Kan_cs_simps]: "L_10_5_\<chi> \<alpha> \<beta> \<TT> \<KK> c\<lparr>NTDGCod\<rparr> = cat_Set \<beta>"
unfolding L_10_5_\<chi>_def nt_field_simps by (simp_all add: nat_omega_simps)
context
fixes \<alpha> \<AA> \<BB> \<TT>
assumes \<TT>: "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
begin
interpretation is_functor \<alpha> \<BB> \<AA> \<TT> by (rule \<TT>)
lemmas L_10_5_\<chi>_components' =
L_10_5_\<chi>_components[where \<TT>=\<TT>, unfolded cat_cs_simps]
lemmas [cat_Kan_cs_simps] = L_10_5_\<chi>_components'(4)
end
subsubsection\<open>Natural transformation map\<close>
mk_VLambda L_10_5_\<chi>_components(1)
|vsv L_10_5_\<chi>_NTMap_vsv[cat_Kan_cs_intros]|
context
fixes \<alpha> \<AA> \<BB> \<TT>
assumes \<TT>: "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
begin
interpretation is_functor \<alpha> \<BB> \<AA> \<TT> by (rule \<TT>)
mk_VLambda L_10_5_\<chi>_components(1)[where \<TT>=\<TT>, unfolded cat_cs_simps]
|vdomain L_10_5_\<chi>_NTMap_vdomain[cat_Kan_cs_simps]|
|app L_10_5_\<chi>_NTMap_app[cat_Kan_cs_simps]|
end
subsubsection\<open>\<open>L_10_5_\<chi>\<close> is a natural isomorphism\<close>
lemma L_10_5_\<chi>_is_iso_ntcf:
\<comment>\<open>See lemma on page 245 in \cite{mac_lane_categories_2010}.\<close>
assumes "\<Z> \<beta>"
and "\<alpha> \<in>\<^sub>\<circ> \<beta>"
and "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "L_10_5_\<chi> \<alpha> \<beta> \<TT> \<KK> c :
cf_Cone \<alpha> \<beta> (\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>) \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>i\<^sub>s\<^sub>o L_10_5_N \<alpha> \<beta> \<TT> \<KK> c :
op_cat \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> cat_Set \<beta>"
(is \<open>?L_10_5_\<chi> : ?cf_Cone \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>i\<^sub>s\<^sub>o ?L_10_5_N : op_cat \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> cat_Set \<beta>\<close>)
proof-
let ?FUNCT = \<open>\<lambda>\<AA>. cat_FUNCT \<alpha> \<AA> (cat_Set \<alpha>)\<close>
let ?c\<KK>_\<AA> = \<open>cat_FUNCT \<alpha> (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA>\<close>
let ?ntcf_c\<KK>_\<AA> = \<open>ntcf_const (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA>\<close>
let ?\<TT>_c\<KK> = \<open>\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>\<close>
let ?H_\<CC> = \<open>\<lambda>c. Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(c,-)\<close>
let ?H_\<AA> = \<open>\<lambda>a. Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-)\<close>
let ?L_10_5_\<chi>'_arrow = \<open>L_10_5_\<chi>'_arrow \<alpha> \<beta> \<TT> \<KK> c\<close>
let ?cf_c\<KK>_\<AA> = \<open>cf_const (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA>\<close>
let ?L_10_5_\<upsilon> = \<open>L_10_5_\<upsilon> \<alpha> \<TT> \<KK> c\<close>
let ?L_10_5_\<upsilon>_arrow = \<open>L_10_5_\<upsilon>_arrow \<TT> \<KK> c\<close>
interpret \<beta>: \<Z> \<beta> by (rule assms(1))
interpret \<KK>: is_functor \<alpha> \<BB> \<CC> \<KK> by (rule assms(3))
interpret \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule assms(4))
from \<KK>.vempty_is_zet assms(5) interpret c\<KK>: category \<alpha> \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close>
by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)
from assms(1,2,5) interpret c\<KK>_\<AA>: category \<beta> ?c\<KK>_\<AA>
by
(
cs_concl cs_intro:
cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros
)
interpret \<beta>_c\<KK>_\<AA>: category \<beta> ?c\<KK>_\<AA>
by (cs_concl cs_shallow cs_intro: cat_cs_intros assms(2))+
from assms(2,5) interpret \<Delta>: is_functor \<beta> \<AA> ?c\<KK>_\<AA> \<open>\<Delta>\<^sub>C\<^sub>F \<alpha> (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA>\<close>
by (cs_concl cs_intro: cat_cs_intros cat_op_intros)+
from \<KK>.vempty_is_zet assms(5) interpret \<Pi>c:
is_functor \<alpha> \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close> \<BB> \<open>c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>\<close>
by
(
cs_concl cs_shallow
cs_simp: cat_comma_cs_simps
cs_intro: cat_cs_intros cat_comma_cs_intros
)
interpret \<beta>\<Pi>c: is_tiny_functor \<beta> \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close> \<BB> \<open>c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>\<close>
by (rule \<Pi>c.cf_is_tiny_functor_if_ge_Limit[OF assms(1,2)])
interpret E: is_functor \<beta> \<open>?FUNCT \<CC> \<times>\<^sub>C \<CC>\<close> \<open>cat_Set \<beta>\<close> \<open>cf_eval \<alpha> \<beta> \<CC>\<close>
by (rule \<KK>.HomCod.cat_cf_eval_is_functor[OF assms(1,2)])
from assms(2) interpret FUNCT_\<AA>: tiny_category \<beta> \<open>?FUNCT \<AA>\<close>
by (cs_concl cs_intro: cat_cs_intros cat_FUNCT_cs_intros)
from assms(2) interpret FUNCT_\<BB>: tiny_category \<beta> \<open>?FUNCT \<BB>\<close>
by (cs_concl cs_intro: cat_cs_intros cat_FUNCT_cs_intros)
from assms(2) interpret FUNCT_\<CC>: tiny_category \<beta> \<open>?FUNCT \<CC>\<close>
by (cs_concl cs_intro: cat_cs_intros cat_FUNCT_cs_intros)
interpret \<beta>\<AA>: tiny_category \<beta> \<AA>
by (rule category.cat_tiny_category_if_ge_Limit)
(use assms(2) in \<open>cs_concl cs_intro: cat_cs_intros\<close>)+
interpret \<beta>\<BB>: tiny_category \<beta> \<BB>
by (rule category.cat_tiny_category_if_ge_Limit)
(use assms(2) in \<open>cs_concl cs_intro: cat_cs_intros\<close>)+
interpret \<beta>\<CC>: tiny_category \<beta> \<CC>
by (rule category.cat_tiny_category_if_ge_Limit)
(use assms(2) in \<open>cs_concl cs_intro: cat_cs_intros\<close>)+
interpret \<beta>\<KK>: is_tiny_functor \<beta> \<BB> \<CC> \<KK>
by (rule is_functor.cf_is_tiny_functor_if_ge_Limit)
(use assms(2) in \<open>cs_concl cs_intro: cat_cs_intros\<close>)+
interpret \<beta>\<TT>: is_tiny_functor \<beta> \<BB> \<AA> \<TT>
by (rule is_functor.cf_is_tiny_functor_if_ge_Limit)
(use assms(2) in \<open>cs_concl cs_intro: cat_cs_intros\<close>)+
interpret cat_Set_\<alpha>\<beta>: subcategory \<beta> \<open>cat_Set \<alpha>\<close> \<open>cat_Set \<beta>\<close>
by (rule \<KK>.subcategory_cat_Set_cat_Set[OF assms(1,2)])
show ?thesis
proof(intro is_iso_ntcfI is_ntcfI', unfold cat_op_simps)
show "vfsequence (?L_10_5_\<chi>)" unfolding L_10_5_\<chi>_def by auto
show "vcard (?L_10_5_\<chi>) = 5\<^sub>\<nat>"
unfolding L_10_5_\<chi>_def by (simp add: nat_omega_simps)
from assms(2) show "?cf_Cone : op_cat \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> cat_Set \<beta>"
by (intro is_functor.tm_cf_cf_Cone_is_functor_if_ge_Limit)
(cs_concl cs_intro: cat_cs_intros)+
from assms show "?L_10_5_N : op_cat \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> cat_Set \<beta>"
by (cs_concl cs_shallow cs_intro: cat_Kan_cs_intros)
show "?L_10_5_\<chi>\<lparr>NTMap\<rparr>\<lparr>a\<rparr> :
?cf_Cone\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> \<mapsto>\<^sub>i\<^sub>s\<^sub>o\<^bsub>cat_Set \<beta>\<^esub> ?L_10_5_N\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
if "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>" for a
using assms(2,3,4,5) that
by
(
cs_concl
cs_simp: L_10_5_\<chi>_NTMap_app
cs_intro: cat_cs_intros L_10_5_\<chi>'_arrow_is_iso_arr
)
from cat_Set_is_iso_arrD[OF this] show
"?L_10_5_\<chi>\<lparr>NTMap\<rparr>\<lparr>a\<rparr> : ?cf_Cone\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> \<mapsto>\<^bsub>cat_Set \<beta>\<^esub> ?L_10_5_N\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
if "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>" for a
using that by auto
have [cat_cs_simps]:
"?L_10_5_\<chi>'_arrow b \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub>
cf_hom ?c\<KK>_\<AA> [ntcf_arrow (?ntcf_c\<KK>_\<AA> f), ntcf_arrow (ntcf_id ?\<TT>_c\<KK>)]\<^sub>\<circ> =
cf_hom (?FUNCT \<BB>)
[
ntcf_arrow (ntcf_id (?H_\<CC> c \<circ>\<^sub>C\<^sub>F \<KK>)),
ntcf_arrow (Hom\<^sub>A\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(f,-) \<circ>\<^sub>N\<^sub>T\<^sub>C\<^sub>F\<^sub>-\<^sub>C\<^sub>F \<TT>)
]\<^sub>\<circ> \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?L_10_5_\<chi>'_arrow a"
(
is
"?L_10_5_\<chi>'_arrow b \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?cf_hom_lhs =
?cf_hom_rhs \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?L_10_5_\<chi>'_arrow a"
)
if "f : b \<mapsto>\<^bsub>\<AA>\<^esub> a" for a b f
proof-
let ?H_f = \<open>Hom\<^sub>A\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(f,-)\<close>
from that assms c\<KK>_\<AA>.category_axioms c\<KK>_\<AA>.category_axioms have lhs:
"?L_10_5_\<chi>'_arrow b \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?cf_hom_lhs :
Hom ?c\<KK>_\<AA> (cf_map (?cf_c\<KK>_\<AA> a)) (cf_map ?\<TT>_c\<KK>) \<mapsto>\<^bsub>cat_Set \<beta>\<^esub>
?L_10_5_N\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
by (*slow*)
(
cs_concl
cs_simp:
cat_Kan_cs_simps
cat_cs_simps
cat_FUNCT_cs_simps
cat_FUNCT_components(1)
cat_op_simps
cs_intro:
cat_Kan_cs_intros
cat_FUNCT_cs_intros
cat_cs_intros
cat_prod_cs_intros
cat_op_intros
)
then have dom_lhs:
"\<D>\<^sub>\<circ> ((?L_10_5_\<chi>'_arrow b \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?cf_hom_lhs)\<lparr>ArrVal\<rparr>) =
Hom ?c\<KK>_\<AA> (cf_map (?cf_c\<KK>_\<AA> a)) (cf_map ?\<TT>_c\<KK>)"
by (cs_concl cs_shallow cs_simp: cat_cs_simps)
from that assms c\<KK>_\<AA>.category_axioms c\<KK>_\<AA>.category_axioms have rhs:
"?cf_hom_rhs \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?L_10_5_\<chi>'_arrow a :
Hom ?c\<KK>_\<AA> (cf_map (?cf_c\<KK>_\<AA> a)) (cf_map ?\<TT>_c\<KK>) \<mapsto>\<^bsub>cat_Set \<beta>\<^esub>
?L_10_5_N\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
by (*slow*)
(
cs_concl
cs_simp:
cat_Kan_cs_simps
cat_cs_simps
cat_FUNCT_components(1)
cat_op_simps
cs_intro:
cat_Kan_cs_intros
cat_cs_intros
cat_prod_cs_intros
cat_FUNCT_cs_intros
cat_op_intros
)
then have dom_rhs:
"\<D>\<^sub>\<circ> ((?cf_hom_rhs \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?L_10_5_\<chi>'_arrow a)\<lparr>ArrVal\<rparr>) =
Hom ?c\<KK>_\<AA> (cf_map (?cf_c\<KK>_\<AA> a)) (cf_map ?\<TT>_c\<KK>)"
by (cs_concl cs_shallow cs_simp: cat_cs_simps)
show ?thesis
proof(rule arr_Set_eqI)
from lhs show arr_Set_lhs:
"arr_Set \<beta> (?L_10_5_\<chi>'_arrow b \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?cf_hom_lhs)"
by (auto dest: cat_Set_is_arrD(1))
from rhs show arr_Set_rhs:
"arr_Set \<beta> (?cf_hom_rhs \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?L_10_5_\<chi>'_arrow a)"
by (auto dest: cat_Set_is_arrD(1))
show
"(?L_10_5_\<chi>'_arrow b \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?cf_hom_lhs)\<lparr>ArrVal\<rparr> =
(?cf_hom_rhs \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?L_10_5_\<chi>'_arrow a)\<lparr>ArrVal\<rparr>"
proof(rule vsv_eqI, unfold dom_lhs dom_rhs in_Hom_iff)
fix F assume prems: "F : cf_map (?cf_c\<KK>_\<AA> a) \<mapsto>\<^bsub>?c\<KK>_\<AA>\<^esub> cf_map ?\<TT>_c\<KK>"
let ?F = \<open>ntcf_of_ntcf_arrow (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> F\<close>
from that have [cat_cs_simps]:
"cf_of_cf_map (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> (cf_map (?cf_c\<KK>_\<AA> a)) = ?cf_c\<KK>_\<AA> a"
"cf_of_cf_map (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> (cf_map (?\<TT>_c\<KK>)) = ?\<TT>_c\<KK>"
by (cs_concl cs_simp: cat_FUNCT_cs_simps cs_intro: cat_cs_intros)
note F = cat_FUNCT_is_arrD[OF prems, unfolded cat_cs_simps]
from that F(1) have F_const_is_cat_cone:
"?F \<bullet>\<^sub>N\<^sub>T\<^sub>C\<^sub>F ?ntcf_c\<KK>_\<AA> f : b <\<^sub>C\<^sub>F\<^sub>.\<^sub>c\<^sub>o\<^sub>n\<^sub>e ?\<TT>_c\<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
by
(
cs_concl
cs_simp: cat_cs_simps cs_intro: is_cat_coneI cat_cs_intros
)
have [cat_cs_simps]:
"?L_10_5_\<upsilon> (ntcf_arrow (?F \<bullet>\<^sub>N\<^sub>T\<^sub>C\<^sub>F ?ntcf_c\<KK>_\<AA> f)) b =
?H_f \<circ>\<^sub>N\<^sub>T\<^sub>C\<^sub>F\<^sub>-\<^sub>C\<^sub>F \<TT> \<bullet>\<^sub>N\<^sub>T\<^sub>C\<^sub>F ?L_10_5_\<upsilon> (ntcf_arrow ?F) a"
proof(rule ntcf_eqI)
from assms that F(1) show
"?L_10_5_\<upsilon> (ntcf_arrow (?F \<bullet>\<^sub>N\<^sub>T\<^sub>C\<^sub>F ?ntcf_c\<KK>_\<AA> f)) b :
?H_\<CC> c \<circ>\<^sub>C\<^sub>F \<KK> \<mapsto>\<^sub>C\<^sub>F ?H_\<AA> b \<circ>\<^sub>C\<^sub>F \<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
by
(
cs_concl cs_intro:
cat_Kan_cs_intros cat_cs_intros is_cat_coneI
)
then have dom_\<upsilon>:
"\<D>\<^sub>\<circ> (?L_10_5_\<upsilon> (ntcf_arrow (?F \<bullet>\<^sub>N\<^sub>T\<^sub>C\<^sub>F ?ntcf_c\<KK>_\<AA> f)) b\<lparr>NTMap\<rparr>) =
\<BB>\<lparr>Obj\<rparr>"
by (cs_concl cs_shallow cs_simp: cat_cs_simps)
from assms that F(1) show
"?H_f \<circ>\<^sub>N\<^sub>T\<^sub>C\<^sub>F\<^sub>-\<^sub>C\<^sub>F \<TT> \<bullet>\<^sub>N\<^sub>T\<^sub>C\<^sub>F ?L_10_5_\<upsilon> (ntcf_arrow ?F) a :
?H_\<CC> c \<circ>\<^sub>C\<^sub>F \<KK> \<mapsto>\<^sub>C\<^sub>F ?H_\<AA> b \<circ>\<^sub>C\<^sub>F \<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
by
(
cs_concl cs_intro:
cat_Kan_cs_intros cat_cs_intros is_cat_coneI
)
then have dom_f\<TT>\<upsilon>:
"\<D>\<^sub>\<circ> ((?H_f \<circ>\<^sub>N\<^sub>T\<^sub>C\<^sub>F\<^sub>-\<^sub>C\<^sub>F \<TT> \<bullet>\<^sub>N\<^sub>T\<^sub>C\<^sub>F ?L_10_5_\<upsilon> (ntcf_arrow ?F) a)\<lparr>NTMap\<rparr>) =
\<BB>\<lparr>Obj\<rparr>"
by (cs_concl cs_simp: cat_cs_simps)
show
"?L_10_5_\<upsilon> (ntcf_arrow (?F \<bullet>\<^sub>N\<^sub>T\<^sub>C\<^sub>F ?ntcf_c\<KK>_\<AA> f)) b\<lparr>NTMap\<rparr> =
(?H_f \<circ>\<^sub>N\<^sub>T\<^sub>C\<^sub>F\<^sub>-\<^sub>C\<^sub>F \<TT> \<bullet>\<^sub>N\<^sub>T\<^sub>C\<^sub>F ?L_10_5_\<upsilon> (ntcf_arrow ?F) a)\<lparr>NTMap\<rparr>"
proof(rule vsv_eqI, unfold dom_\<upsilon> dom_f\<TT>\<upsilon>)
fix b' assume prems': "b' \<in>\<^sub>\<circ> \<BB>\<lparr>Obj\<rparr>"
let ?Y = \<open>Yoneda_component (?H_\<AA> b) a f (\<TT>\<lparr>ObjMap\<rparr>\<lparr>b'\<rparr>)\<close>
let ?\<KK>b' = \<open>\<KK>\<lparr>ObjMap\<rparr>\<lparr>b'\<rparr>\<close>
let ?\<TT>b' = \<open>\<TT>\<lparr>ObjMap\<rparr>\<lparr>b'\<rparr>\<close>
have [cat_cs_simps]:
"?L_10_5_\<upsilon>_arrow (ntcf_arrow (?F \<bullet>\<^sub>N\<^sub>T\<^sub>C\<^sub>F ?ntcf_c\<KK>_\<AA> f)) b b' =
?Y \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub> ?L_10_5_\<upsilon>_arrow (ntcf_arrow ?F) a b'"
(is \<open>?\<upsilon>_Ffbb' = ?Y\<upsilon>\<close>)
proof-
from assms prems' F_const_is_cat_cone have \<upsilon>_Ffbb':
"?\<upsilon>_Ffbb' : Hom \<CC> c ?\<KK>b' \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom \<AA> b ?\<TT>b'"
by
(
cs_concl cs_shallow
cs_intro: cat_cs_intros L_10_5_\<upsilon>_arrow_is_arr
)
then have dom_\<upsilon>_Ffbb': "\<D>\<^sub>\<circ> (?\<upsilon>_Ffbb'\<lparr>ArrVal\<rparr>) = Hom \<CC> c (?\<KK>b')"
by (cs_concl cs_shallow cs_simp: cat_cs_simps)
from assms that \<TT>.HomCod.category_axioms prems' F(1) have Y\<upsilon>:
"?Y\<upsilon> : Hom \<CC> c ?\<KK>b' \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom \<AA> b ?\<TT>b'"
by
(
cs_concl
cs_simp: cat_Kan_cs_simps cat_cs_simps cat_op_simps
cs_intro: is_cat_coneI cat_Kan_cs_intros cat_cs_intros
)
then have dom_Y\<upsilon>: "\<D>\<^sub>\<circ> (?Y\<upsilon>\<lparr>ArrVal\<rparr>) = Hom \<CC> c (?\<KK>b')"
by (cs_concl cs_shallow cs_simp: cat_cs_simps)
show ?thesis
proof(rule arr_Set_eqI)
from \<upsilon>_Ffbb' show arr_Set_\<upsilon>_Ffbb': "arr_Set \<alpha> ?\<upsilon>_Ffbb'"
by (auto dest: cat_Set_is_arrD(1))
from Y\<upsilon> show arr_Set_Y\<upsilon>: "arr_Set \<alpha> ?Y\<upsilon>"
by (auto dest: cat_Set_is_arrD(1))
show "?\<upsilon>_Ffbb'\<lparr>ArrVal\<rparr> = ?Y\<upsilon>\<lparr>ArrVal\<rparr>"
proof(rule vsv_eqI, unfold dom_\<upsilon>_Ffbb' dom_Y\<upsilon> in_Hom_iff)
fix g assume "g : c \<mapsto>\<^bsub>\<CC>\<^esub> ?\<KK>b'"
with
assms(2-)
\<KK>.is_functor_axioms
\<TT>.is_functor_axioms
\<TT>.HomCod.category_axioms
\<KK>.HomCod.category_axioms
that prems' F(1)
show "?\<upsilon>_Ffbb'\<lparr>ArrVal\<rparr>\<lparr>g\<rparr> = ?Y\<upsilon>\<lparr>ArrVal\<rparr>\<lparr>g\<rparr>"
by (*slow*)
(
cs_concl
cs_simp:
cat_Kan_cs_simps
cat_cs_simps
L_10_5_\<upsilon>_arrow_ArrVal_app
cat_comma_cs_simps
cat_op_simps
cs_intro:
cat_Kan_cs_intros
is_cat_coneI
cat_cs_intros
cat_comma_cs_intros
cat_op_intros
cs_simp: cat_FUNCT_cs_simps
)
qed (use arr_Set_\<upsilon>_Ffbb' arr_Set_Y\<upsilon> in auto)
qed
(
use \<upsilon>_Ffbb' Y\<upsilon> in
\<open>cs_concl cs_shallow cs_simp: cat_cs_simps\<close>
)+
qed
from assms prems' that F(1) show
"?L_10_5_\<upsilon> (ntcf_arrow (?F \<bullet>\<^sub>N\<^sub>T\<^sub>C\<^sub>F ?ntcf_c\<KK>_\<AA> f)) b\<lparr>NTMap\<rparr>\<lparr>b'\<rparr> =
(?H_f \<circ>\<^sub>N\<^sub>T\<^sub>C\<^sub>F\<^sub>-\<^sub>C\<^sub>F \<TT> \<bullet>\<^sub>N\<^sub>T\<^sub>C\<^sub>F ?L_10_5_\<upsilon> (ntcf_arrow ?F) a)\<lparr>NTMap\<rparr>\<lparr>b'\<rparr>"
by
(
cs_concl
cs_simp: cat_Kan_cs_simps cat_cs_simps
cs_intro: is_cat_coneI cat_Kan_cs_intros cat_cs_intros
)
qed (cs_concl cs_intro: cat_Kan_cs_intros cat_cs_intros)+
qed simp_all
from that F(1) interpret F: is_cat_cone \<alpha> a \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close> \<AA> \<open>?\<TT>_c\<KK>\<close> ?F
by (cs_concl cs_shallow cs_intro: is_cat_coneI cat_cs_intros)
from
assms(2-) prems F(1) that
\<TT>.HomCod.cat_ntcf_Hom_snd_is_ntcf[OF that] (*speedup*)
c\<KK>_\<AA>.category_axioms (*speedup*)
show
"(?L_10_5_\<chi>'_arrow b \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?cf_hom_lhs)\<lparr>ArrVal\<rparr>\<lparr>F\<rparr> =
(?cf_hom_rhs \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?L_10_5_\<chi>'_arrow a)\<lparr>ArrVal\<rparr>\<lparr>F\<rparr>"
by (subst (1 2) F(2)) (*exceptionally slow*)
(
cs_concl
cs_simp:
cat_cs_simps
cat_Kan_cs_simps
cat_FUNCT_cs_simps
cat_FUNCT_components(1)
cat_op_simps
cs_intro:
is_cat_coneI
cat_Kan_cs_intros
cat_cs_intros
cat_prod_cs_intros
cat_FUNCT_cs_intros
cat_op_intros
)
qed (use arr_Set_lhs arr_Set_rhs in auto)
qed (use lhs rhs in \<open>cs_concl cs_shallow cs_simp: cat_cs_simps\<close>)+
qed
show
"?L_10_5_\<chi>\<lparr>NTMap\<rparr>\<lparr>b\<rparr> \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?cf_Cone\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> =
?L_10_5_N\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?L_10_5_\<chi>\<lparr>NTMap\<rparr>\<lparr>a\<rparr>"
if "f : b \<mapsto>\<^bsub>\<AA>\<^esub> a" for a b f
using that assms
by
(
cs_concl
cs_simp:
cat_cs_simps
cat_Kan_cs_simps
cat_FUNCT_components(1)
cat_FUNCT_cs_simps
cat_op_simps
cs_intro:
cat_Kan_cs_intros
cat_cs_intros
cat_FUNCT_cs_intros
cat_op_intros
)
qed
(
cs_concl
cs_simp: cat_Kan_cs_simps cs_intro: cat_cs_intros cat_Kan_cs_intros
)+
qed
subsection\<open>
The existence of a canonical limit or a canonical colimit for the
pointwise Kan extensions
\<close>
lemma (in is_cat_pw_rKe) cat_pw_rKe_ex_cat_limit:
\<comment>\<open>Based on the elements of Chapter X-5 in \cite{mac_lane_categories_2010}.\<close>
assumes "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
obtains UA
where "UA : \<GG>\<lparr>ObjMap\<rparr>\<lparr>c\<rparr> <\<^sub>C\<^sub>F\<^sub>.\<^sub>l\<^sub>i\<^sub>m \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
proof-
define \<beta> where "\<beta> = \<alpha> + \<omega>"
have \<beta>: "\<Z> \<beta>" and \<alpha>\<beta>: "\<alpha> \<in>\<^sub>\<circ> \<beta>"
by (simp_all add: \<beta>_def AG.\<Z>_Limit_\<alpha>\<omega> AG.\<Z>_\<omega>_\<alpha>\<omega> \<Z>_def AG.\<Z>_\<alpha>_\<alpha>\<omega>)
then interpret \<beta>: \<Z> \<beta> by simp
let ?FUNCT = \<open>\<lambda>\<AA>. cat_FUNCT \<alpha> \<AA> (cat_Set \<alpha>)\<close>
let ?H_A = \<open>\<lambda>f. Hom\<^sub>A\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(f,-)\<close>
let ?H_A\<GG> = \<open>\<lambda>f. ?H_A f \<circ>\<^sub>N\<^sub>T\<^sub>C\<^sub>F\<^sub>-\<^sub>C\<^sub>F \<GG>\<close>
let ?H_\<AA> = \<open>\<lambda>a. Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<AA>(a,-)\<close>
let ?H_\<AA>\<TT> = \<open>\<lambda>a. ?H_\<AA> a \<circ>\<^sub>C\<^sub>F \<TT>\<close>
let ?H_\<AA>\<GG> = \<open>\<lambda>a. ?H_\<AA> a \<circ>\<^sub>C\<^sub>F \<GG>\<close>
let ?H_\<CC> = \<open>\<lambda>c. Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<alpha>\<^esub>\<CC>(c,-)\<close>
let ?H_\<CC>\<KK> = \<open>\<lambda>c. ?H_\<CC> c \<circ>\<^sub>C\<^sub>F \<KK>\<close>
let ?H_\<AA>\<epsilon> = \<open>\<lambda>b. ?H_\<AA> b \<circ>\<^sub>C\<^sub>F\<^sub>-\<^sub>N\<^sub>T\<^sub>C\<^sub>F \<epsilon>\<close>
let ?SET_\<KK> = \<open>exp_cat_cf \<alpha> (cat_Set \<alpha>) \<KK>\<close>
let ?H_FUNCT = \<open>\<lambda>\<CC> \<FF>. Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<beta>\<^esub>?FUNCT \<CC>(-,cf_map \<FF>)\<close>
let ?ua_NTDGDom = \<open>op_cat (?FUNCT \<CC>)\<close>
let ?ua_NTDom = \<open>\<lambda>a. ?H_FUNCT \<CC> (?H_\<AA>\<GG> a)\<close>
let ?ua_NTCod = \<open>\<lambda>a. ?H_FUNCT \<BB> (?H_\<AA>\<TT> a) \<circ>\<^sub>C\<^sub>F op_cf ?SET_\<KK>\<close>
let ?c\<KK>_\<AA> = \<open>cat_FUNCT \<alpha> (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA>\<close>
let ?ua =
\<open>
\<lambda>a. ntcf_ua_fo
\<beta>
?SET_\<KK>
(cf_map (?H_\<AA>\<TT> a))
(cf_map (?H_\<AA>\<GG> a))
(ntcf_arrow (?H_\<AA>\<epsilon> a))
\<close>
let ?cf_nt = \<open>cf_nt \<alpha> \<beta> (cf_id \<CC>)\<close>
let ?cf_eval = \<open>cf_eval \<alpha> \<beta> \<CC>\<close>
let ?\<TT>_c\<KK> = \<open>\<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>\<close>
let ?cf_c\<KK>_\<AA> = \<open>cf_const (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA>\<close>
let ?\<GG>c = \<open>\<GG>\<lparr>ObjMap\<rparr>\<lparr>c\<rparr>\<close>
let ?\<Delta> = \<open>\<Delta>\<^sub>C\<^sub>F \<alpha> (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA>\<close>
let ?ntcf_ua_fo =
\<open>
\<lambda>a. ntcf_ua_fo
\<beta>
?SET_\<KK>
(cf_map (?H_\<AA>\<TT> a))
(cf_map (?H_\<AA>\<GG> a))
(ntcf_arrow (?H_\<AA>\<epsilon> a))
\<close>
let ?umap_fo =
\<open>
\<lambda>b. umap_fo
?SET_\<KK>
(cf_map (?H_\<AA>\<TT> b))
(cf_map (?H_\<AA>\<GG> b))
(ntcf_arrow (?H_\<AA>\<epsilon> b))
(cf_map (?H_\<CC> c))
\<close>
interpret \<KK>: is_functor \<alpha> \<BB> \<CC> \<KK> by (rule assms(1))
interpret \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule assms(2))
from AG.vempty_is_zet assms(3) interpret c\<KK>: category \<alpha> \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close>
by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)
from \<alpha>\<beta> assms(3) interpret c\<KK>_\<AA>: category \<beta> ?c\<KK>_\<AA>
by
(
cs_concl cs_intro:
cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros
)
from \<alpha>\<beta> assms(3) interpret \<Delta>: is_functor \<beta> \<AA> ?c\<KK>_\<AA> ?\<Delta>
by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_op_intros)+
from AG.vempty_is_zet assms(3) interpret \<Pi>c:
is_functor \<alpha> \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close> \<BB> \<open>c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>\<close>
by
(
cs_concl cs_shallow
cs_simp: cat_comma_cs_simps
cs_intro: cat_cs_intros cat_comma_cs_intros
)
interpret \<beta>\<Pi>c: is_tiny_functor \<beta> \<open>c \<down>\<^sub>C\<^sub>F \<KK>\<close> \<BB> \<open>c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK>\<close>
by (rule \<Pi>c.cf_is_tiny_functor_if_ge_Limit[OF \<beta> \<alpha>\<beta>])
interpret E: is_functor \<beta> \<open>?FUNCT \<CC> \<times>\<^sub>C \<CC>\<close> \<open>cat_Set \<beta>\<close> ?cf_eval
by (rule AG.HomCod.cat_cf_eval_is_functor[OF \<beta> \<alpha>\<beta>])
from \<alpha>\<beta> interpret FUNCT_\<AA>: tiny_category \<beta> \<open>?FUNCT \<AA>\<close>
by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_FUNCT_cs_intros)
from \<alpha>\<beta> interpret FUNCT_\<BB>: tiny_category \<beta> \<open>?FUNCT \<BB>\<close>
by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_FUNCT_cs_intros)
from \<alpha>\<beta> interpret FUNCT_\<CC>: tiny_category \<beta> \<open>?FUNCT \<CC>\<close>
by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_FUNCT_cs_intros)
interpret \<beta>\<AA>: tiny_category \<beta> \<AA>
by (rule category.cat_tiny_category_if_ge_Limit)
(use \<alpha>\<beta> in \<open>cs_concl cs_intro: cat_cs_intros\<close>)+
interpret \<beta>\<BB>: tiny_category \<beta> \<BB>
by (rule category.cat_tiny_category_if_ge_Limit)
(use \<alpha>\<beta> in \<open>cs_concl cs_intro: cat_cs_intros\<close>)+
interpret \<beta>\<CC>: tiny_category \<beta> \<CC>
by (rule category.cat_tiny_category_if_ge_Limit)
(use \<alpha>\<beta> in \<open>cs_concl cs_intro: cat_cs_intros\<close>)+
interpret \<beta>\<KK>: is_tiny_functor \<beta> \<BB> \<CC> \<KK>
by (rule is_functor.cf_is_tiny_functor_if_ge_Limit)
(use \<alpha>\<beta> in \<open>cs_concl cs_shallow cs_intro: cat_cs_intros\<close>)+
interpret \<beta>\<GG>: is_tiny_functor \<beta> \<CC> \<AA> \<GG>
by (rule is_functor.cf_is_tiny_functor_if_ge_Limit)
(use \<alpha>\<beta> in \<open>cs_concl cs_shallow cs_intro: cat_cs_intros\<close>)+
interpret \<beta>\<TT>: is_tiny_functor \<beta> \<BB> \<AA> \<TT>
by (rule is_functor.cf_is_tiny_functor_if_ge_Limit)
(use \<alpha>\<beta> in \<open>cs_concl cs_shallow cs_intro: cat_cs_intros\<close>)+
interpret cat_Set_\<alpha>\<beta>: subcategory \<beta> \<open>cat_Set \<alpha>\<close> \<open>cat_Set \<beta>\<close>
by (rule AG.subcategory_cat_Set_cat_Set[OF \<beta> \<alpha>\<beta>])
from assms(3) \<alpha>\<beta> interpret Hom_c: is_functor \<alpha> \<CC> \<open>cat_Set \<alpha>\<close> \<open>?H_\<CC> c\<close>
by (cs_concl cs_intro: cat_cs_intros)
(** E' **)
define E' :: V where "E' =
[
(\<lambda>a\<in>\<^sub>\<circ>\<AA>\<lparr>Obj\<rparr>. ?cf_eval\<lparr>ObjMap\<rparr>\<lparr>cf_map (?H_\<AA>\<GG> a), c\<rparr>\<^sub>\<bullet>),
(\<lambda>f\<in>\<^sub>\<circ>\<AA>\<lparr>Arr\<rparr>. ?cf_eval\<lparr>ArrMap\<rparr>\<lparr>ntcf_arrow (?H_A\<GG> f), \<CC>\<lparr>CId\<rparr>\<lparr>c\<rparr>\<rparr>\<^sub>\<bullet>),
op_cat \<AA>,
cat_Set \<beta>
]\<^sub>\<circ> "
have E'_components:
"E'\<lparr>ObjMap\<rparr> = (\<lambda>a\<in>\<^sub>\<circ>\<AA>\<lparr>Obj\<rparr>. ?cf_eval\<lparr>ObjMap\<rparr>\<lparr>cf_map (?H_\<AA>\<GG> a), c\<rparr>\<^sub>\<bullet>)"
"E'\<lparr>ArrMap\<rparr> =
(\<lambda>f\<in>\<^sub>\<circ>\<AA>\<lparr>Arr\<rparr>. ?cf_eval\<lparr>ArrMap\<rparr>\<lparr>ntcf_arrow (?H_A\<GG> f), \<CC>\<lparr>CId\<rparr>\<lparr>c\<rparr>\<rparr>\<^sub>\<bullet>)"
"E'\<lparr>HomDom\<rparr> = op_cat \<AA>"
"E'\<lparr>HomCod\<rparr> = cat_Set \<beta>"
unfolding E'_def dghm_field_simps by (simp_all add: nat_omega_simps)
note [cat_cs_simps] = E'_components(3,4)
have E'_ObjMap_app[cat_cs_simps]:
"E'\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> = ?cf_eval\<lparr>ObjMap\<rparr>\<lparr>cf_map (?H_\<AA>\<GG> a), c\<rparr>\<^sub>\<bullet>"
if "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>" for a
using that unfolding E'_components by simp
have E'_ArrMap_app[cat_cs_simps]:
"E'\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> = ?cf_eval\<lparr>ArrMap\<rparr>\<lparr>ntcf_arrow (?H_A\<GG> f), \<CC>\<lparr>CId\<rparr>\<lparr>c\<rparr>\<rparr>\<^sub>\<bullet>"
if "f \<in>\<^sub>\<circ> \<AA>\<lparr>Arr\<rparr>" for f
using that unfolding E'_components by simp
have E': "E' : op_cat \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> cat_Set \<beta>"
proof(intro is_functorI')
show "vfsequence E'" unfolding E'_def by auto
show "vcard E' = 4\<^sub>\<nat>" unfolding E'_def by (simp add: nat_omega_simps)
show "vsv (E'\<lparr>ObjMap\<rparr>)" unfolding E'_components by simp
show "vsv (E'\<lparr>ArrMap\<rparr>)" unfolding E'_components by simp
show "\<D>\<^sub>\<circ> (E'\<lparr>ObjMap\<rparr>) = op_cat \<AA>\<lparr>Obj\<rparr>"
unfolding E'_components by (simp add: cat_op_simps)
show "\<R>\<^sub>\<circ> (E'\<lparr>ObjMap\<rparr>) \<subseteq>\<^sub>\<circ> cat_Set \<beta>\<lparr>Obj\<rparr>"
unfolding E'_components
proof(rule vrange_VLambda_vsubset)
fix a assume prems: "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
then have "?H_\<AA>\<GG> a : \<CC> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros)
with assms(3) prems show
"?cf_eval\<lparr>ObjMap\<rparr>\<lparr>cf_map (?H_\<AA>\<GG> a), c\<rparr>\<^sub>\<bullet> \<in>\<^sub>\<circ> cat_Set \<beta>\<lparr>Obj\<rparr>"
by
(
cs_concl
cs_simp: cat_cs_simps cat_Set_components(1)
cs_intro: cat_cs_intros cat_op_intros Ran.HomCod.cat_Hom_in_Vset
)
qed
show "\<D>\<^sub>\<circ> (E'\<lparr>ArrMap\<rparr>) = op_cat \<AA>\<lparr>Arr\<rparr>"
unfolding E'_components by (simp add: cat_op_simps)
show "E'\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> : E'\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> \<mapsto>\<^bsub>cat_Set \<beta>\<^esub> E'\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
if "f : a \<mapsto>\<^bsub>op_cat \<AA>\<^esub> b" for a b f
proof-
from that[unfolded cat_op_simps] assms(3) show ?thesis
by (intro cat_Set_\<alpha>\<beta>.subcat_is_arrD)
(
cs_concl
cs_simp:
category.cf_eval_ObjMap_app
category.cf_eval_ArrMap_app
E'_ObjMap_app
E'_ArrMap_app
cs_intro: cat_cs_intros
)
qed
then have [cat_cs_intros]: "E'\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> : A \<mapsto>\<^bsub>cat_Set \<beta>\<^esub> B"
if "A = E'\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>" and "B = E'\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>" and "f : b \<mapsto>\<^bsub>\<AA>\<^esub> a"
for a b f A B
using that by (simp add: cat_op_simps)
show
"E'\<lparr>ArrMap\<rparr>\<lparr>g \<circ>\<^sub>A\<^bsub>op_cat \<AA>\<^esub> f\<rparr> = E'\<lparr>ArrMap\<rparr>\<lparr>g\<rparr> \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> E'\<lparr>ArrMap\<rparr>\<lparr>f\<rparr>"
if "g : b \<mapsto>\<^bsub>op_cat \<AA>\<^esub> c" and "f : a \<mapsto>\<^bsub>op_cat \<AA>\<^esub> b" for b c g a f
proof-
note g = that(1)[unfolded cat_op_simps]
and f = that(2)[unfolded cat_op_simps]
from g f assms(3) \<alpha>\<beta> show ?thesis
by
(
cs_concl
cs_intro:
cat_cs_intros
cat_prod_cs_intros
cat_FUNCT_cs_intros
cat_op_intros
cs_simp:
cat_cs_simps
cat_FUNCT_cs_simps
cat_prod_cs_simps
cat_op_simps
E.cf_ArrMap_Comp[symmetric]
)+
qed
show "E'\<lparr>ArrMap\<rparr>\<lparr>op_cat \<AA>\<lparr>CId\<rparr>\<lparr>a\<rparr>\<rparr> = cat_Set \<beta>\<lparr>CId\<rparr>\<lparr>E'\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>\<rparr>"
if "a \<in>\<^sub>\<circ> op_cat \<AA>\<lparr>Obj\<rparr>" for a
proof(cs_concl_step cat_Set_\<alpha>\<beta>.subcat_CId[symmetric])
from that[unfolded cat_op_simps] assms(3) show
"E'\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> \<in>\<^sub>\<circ> cat_Set \<alpha>\<lparr>Obj\<rparr>"
by
(
cs_concl
cs_simp: cat_Set_components(1) cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros
)
from that[unfolded cat_op_simps] assms(3) show
"E'\<lparr>ArrMap\<rparr>\<lparr>op_cat \<AA>\<lparr>CId\<rparr>\<lparr>a\<rparr>\<rparr> = cat_Set \<alpha>\<lparr>CId\<rparr>\<lparr>E'\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>\<rparr>"
by
(
cs_concl
cs_intro: cat_cs_intros
cs_simp:
cat_Set_components(1)
cat_cs_simps
cat_op_simps
ntcf_id_cf_comp[symmetric]
)
qed
qed (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)+
then interpret E': is_functor \<beta> \<open>op_cat \<AA>\<close> \<open>cat_Set \<beta>\<close> E' by simp
(** N' **)
define N' :: V where "N' =
[
(\<lambda>a\<in>\<^sub>\<circ>\<AA>\<lparr>Obj\<rparr>. ?cf_nt\<lparr>ObjMap\<rparr>\<lparr>cf_map (?H_\<AA>\<GG> a), c\<rparr>\<^sub>\<bullet>),
(\<lambda>f\<in>\<^sub>\<circ>\<AA>\<lparr>Arr\<rparr>. ?cf_nt\<lparr>ArrMap\<rparr>\<lparr>ntcf_arrow (?H_A\<GG> f), \<CC>\<lparr>CId\<rparr>\<lparr>c\<rparr>\<rparr>\<^sub>\<bullet>),
op_cat \<AA>,
cat_Set \<beta>
]\<^sub>\<circ> "
have N'_components:
"N'\<lparr>ObjMap\<rparr> = (\<lambda>a\<in>\<^sub>\<circ>\<AA>\<lparr>Obj\<rparr>. ?cf_nt\<lparr>ObjMap\<rparr>\<lparr>cf_map (?H_\<AA>\<GG> a), c\<rparr>\<^sub>\<bullet>)"
"N'\<lparr>ArrMap\<rparr> =
(\<lambda>f\<in>\<^sub>\<circ>\<AA>\<lparr>Arr\<rparr>. ?cf_nt\<lparr>ArrMap\<rparr>\<lparr>ntcf_arrow (?H_A\<GG> f), \<CC>\<lparr>CId\<rparr>\<lparr>c\<rparr>\<rparr>\<^sub>\<bullet>)"
"N'\<lparr>HomDom\<rparr> = op_cat \<AA>"
"N'\<lparr>HomCod\<rparr> = cat_Set \<beta>"
unfolding N'_def dghm_field_simps by (simp_all add: nat_omega_simps)
note [cat_cs_simps] = N'_components(3,4)
have N'_ObjMap_app[cat_cs_simps]:
"N'\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> = ?cf_nt\<lparr>ObjMap\<rparr>\<lparr>cf_map (?H_\<AA>\<GG> a), c\<rparr>\<^sub>\<bullet>"
if "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>" for a
using that unfolding N'_components by simp
have N'_ArrMap_app[cat_cs_simps]:
"N'\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> = ?cf_nt\<lparr>ArrMap\<rparr>\<lparr>ntcf_arrow (?H_A\<GG> f), \<CC>\<lparr>CId\<rparr>\<lparr>c\<rparr>\<rparr>\<^sub>\<bullet>"
if "f \<in>\<^sub>\<circ> \<AA>\<lparr>Arr\<rparr>" for f
using that unfolding N'_components by simp
from \<alpha>\<beta> interpret cf_nt_\<CC>: is_functor \<beta> \<open>?FUNCT \<CC> \<times>\<^sub>C \<CC>\<close> \<open>cat_Set \<beta>\<close> \<open>?cf_nt\<close>
by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros)
have N': "N' : op_cat \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> cat_Set \<beta>"
proof(intro is_functorI')
show "vfsequence N'" unfolding N'_def by simp
show "vcard N' = 4\<^sub>\<nat>" unfolding N'_def by (simp add: nat_omega_simps)
show "vsv (N'\<lparr>ObjMap\<rparr>)" unfolding N'_components by simp
show "vsv (N'\<lparr>ArrMap\<rparr>)" unfolding N'_components by simp
show "\<D>\<^sub>\<circ> (N'\<lparr>ObjMap\<rparr>) = op_cat \<AA>\<lparr>Obj\<rparr>"
unfolding N'_components by (simp add: cat_op_simps)
show "\<R>\<^sub>\<circ> (N'\<lparr>ObjMap\<rparr>) \<subseteq>\<^sub>\<circ> cat_Set \<beta>\<lparr>Obj\<rparr>"
unfolding N'_components
proof(rule vrange_VLambda_vsubset)
fix a assume prems: "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
with assms(3) \<alpha>\<beta> show
"?cf_nt\<lparr>ObjMap\<rparr>\<lparr>cf_map (?H_\<AA>\<GG> a), c\<rparr>\<^sub>\<bullet> \<in>\<^sub>\<circ> cat_Set \<beta>\<lparr>Obj\<rparr>"
by
(
cs_concl
cs_simp: cat_Set_components(1) cat_cs_simps cat_FUNCT_cs_simps
cs_intro: cat_cs_intros FUNCT_\<CC>.cat_Hom_in_Vset cat_FUNCT_cs_intros
)
qed
show "\<D>\<^sub>\<circ> (N'\<lparr>ArrMap\<rparr>) = op_cat \<AA>\<lparr>Arr\<rparr>"
unfolding N'_components by (simp add: cat_op_simps)
show "N'\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> : N'\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> \<mapsto>\<^bsub>cat_Set \<beta>\<^esub> N'\<lparr>ObjMap\<rparr>\<lparr>b\<rparr>"
if "f : a \<mapsto>\<^bsub>op_cat \<AA>\<^esub> b" for a b f
using that[unfolded cat_op_simps] assms(3)
by
(
cs_concl
cs_simp: N'_ObjMap_app N'_ArrMap_app
cs_intro: cat_cs_intros cat_prod_cs_intros cat_FUNCT_cs_intros
)
show
"N'\<lparr>ArrMap\<rparr>\<lparr>g \<circ>\<^sub>A\<^bsub>op_cat \<AA>\<^esub> f\<rparr> = N'\<lparr>ArrMap\<rparr>\<lparr>g\<rparr> \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> N'\<lparr>ArrMap\<rparr>\<lparr>f\<rparr>"
if "g : b \<mapsto>\<^bsub>op_cat \<AA>\<^esub> c" and "f : a \<mapsto>\<^bsub>op_cat \<AA>\<^esub> b" for b c g a f
proof-
from that assms(3) \<alpha>\<beta> show ?thesis
unfolding cat_op_simps
by
(
cs_concl
cs_intro:
cat_cs_intros
cat_prod_cs_intros
cat_FUNCT_cs_intros
cat_op_intros
cs_simp:
cat_cs_simps
cat_FUNCT_cs_simps
cat_prod_cs_simps
cat_op_simps
cf_nt_\<CC>.cf_ArrMap_Comp[symmetric]
)
qed
show "N'\<lparr>ArrMap\<rparr>\<lparr>op_cat \<AA>\<lparr>CId\<rparr>\<lparr>a\<rparr>\<rparr> = cat_Set \<beta>\<lparr>CId\<rparr>\<lparr>N'\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>\<rparr>"
if "a \<in>\<^sub>\<circ> op_cat \<AA>\<lparr>Obj\<rparr>" for a
proof-
note [cat_cs_simps] =
ntcf_id_cf_comp[symmetric]
ntcf_arrow_id_ntcf_id[symmetric]
cat_FUNCT_CId_app[symmetric]
from that[unfolded cat_op_simps] assms(3) \<alpha>\<beta> show ?thesis
by (*very slow*)
(
cs_concl
cs_intro:
cat_cs_intros
cat_FUNCT_cs_intros
cat_prod_cs_intros
cat_op_intros
cs_simp: cat_FUNCT_cs_simps cat_cs_simps cat_op_simps
)+
qed
qed (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)+
then interpret N': is_functor \<beta> \<open>op_cat \<AA>\<close> \<open>cat_Set \<beta>\<close> N' by simp
(** Y' **)
define Y' :: V where "Y' =
[
(\<lambda>a\<in>\<^sub>\<circ>\<AA>\<lparr>Obj\<rparr>. ntcf_Yoneda \<alpha> \<beta> \<CC>\<lparr>NTMap\<rparr>\<lparr>cf_map (?H_\<AA>\<GG> a), c\<rparr>\<^sub>\<bullet>),
N',
E',
op_cat \<AA>,
cat_Set \<beta>
]\<^sub>\<circ>"
have Y'_components:
"Y'\<lparr>NTMap\<rparr> = (\<lambda>a\<in>\<^sub>\<circ>\<AA>\<lparr>Obj\<rparr>. ntcf_Yoneda \<alpha> \<beta> \<CC>\<lparr>NTMap\<rparr>\<lparr>cf_map (?H_\<AA>\<GG> a), c\<rparr>\<^sub>\<bullet>)"
"Y'\<lparr>NTDom\<rparr> = N'"
"Y'\<lparr>NTCod\<rparr> = E'"
"Y'\<lparr>NTDGDom\<rparr> = op_cat \<AA>"
"Y'\<lparr>NTDGCod\<rparr> = cat_Set \<beta>"
unfolding Y'_def nt_field_simps by (simp_all add: nat_omega_simps)
note [cat_cs_simps] = Y'_components(2-5)
have Y'_NTMap_app[cat_cs_simps]:
"Y'\<lparr>NTMap\<rparr>\<lparr>a\<rparr> = ntcf_Yoneda \<alpha> \<beta> \<CC>\<lparr>NTMap\<rparr>\<lparr>cf_map (?H_\<AA>\<GG> a), c\<rparr>\<^sub>\<bullet>"
if "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>" for a
using that unfolding Y'_components by simp
from \<beta> \<alpha>\<beta> interpret Y:
is_iso_ntcf \<beta> \<open>?FUNCT \<CC> \<times>\<^sub>C \<CC>\<close> \<open>cat_Set \<beta>\<close> ?cf_nt ?cf_eval \<open>ntcf_Yoneda \<alpha> \<beta> \<CC>\<close>
by (rule AG.HomCod.cat_ntcf_Yoneda_is_ntcf)
have Y': "Y' : N' \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>i\<^sub>s\<^sub>o E' : op_cat \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> cat_Set \<beta>"
proof(intro is_iso_ntcfI is_ntcfI')
show "vfsequence Y'" unfolding Y'_def by simp
show "vcard Y' = 5\<^sub>\<nat>"
unfolding Y'_def by (simp add: nat_omega_simps)
show "vsv (Y'\<lparr>NTMap\<rparr>)" unfolding Y'_components by auto
show "\<D>\<^sub>\<circ> (Y'\<lparr>NTMap\<rparr>) = op_cat \<AA>\<lparr>Obj\<rparr>"
unfolding Y'_components by (simp add: cat_op_simps)
show Y'_NTMap_a: "Y'\<lparr>NTMap\<rparr>\<lparr>a\<rparr> : N'\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> \<mapsto>\<^sub>i\<^sub>s\<^sub>o\<^bsub>cat_Set \<beta>\<^esub> E'\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
if "a \<in>\<^sub>\<circ> op_cat \<AA>\<lparr>Obj\<rparr>" for a
using that[unfolded cat_op_simps] assms(3) \<alpha>\<beta>
by (*slow*)
(
cs_concl
cs_simp: cat_cs_simps cat_FUNCT_cs_simps cat_op_simps
cs_intro:
cat_arrow_cs_intros
cat_cs_intros
cat_prod_cs_intros
cat_FUNCT_cs_intros
)
then show "Y'\<lparr>NTMap\<rparr>\<lparr>a\<rparr> : N'\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> \<mapsto>\<^bsub>cat_Set \<beta>\<^esub> E'\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
if "a \<in>\<^sub>\<circ> op_cat \<AA>\<lparr>Obj\<rparr>" for a
by (intro cat_Set_is_iso_arrD[OF Y'_NTMap_a[OF that]])
show
"Y'\<lparr>NTMap\<rparr>\<lparr>b\<rparr> \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> N'\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> =
E'\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> Y'\<lparr>NTMap\<rparr>\<lparr>a\<rparr>"
if "f : a \<mapsto>\<^bsub>op_cat \<AA>\<^esub> b" for a b f
proof-
note f = that[unfolded cat_op_simps]
from f assms(3) show ?thesis
by
(
cs_concl
cs_simp: cat_cs_simps Y.ntcf_Comp_commute
cs_intro: cat_cs_intros cat_prod_cs_intros cat_FUNCT_cs_intros
)+
qed
qed (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)+
have E'_def: "E' = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<beta>\<^esub>\<AA>(-,?\<GG>c)"
proof(rule cf_eqI)
show "E' : op_cat \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> cat_Set \<beta>"
by (cs_concl cs_shallow cs_intro: cat_cs_intros)
from assms(3) show
"Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<beta>\<^esub>\<AA>(-,?\<GG>c) : op_cat \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> cat_Set \<beta>"
by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)
have dom_lhs: "\<D>\<^sub>\<circ> (E'\<lparr>ObjMap\<rparr>) = \<AA>\<lparr>Obj\<rparr>" unfolding E'_components by simp
from assms(3) have dom_rhs:
"\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<beta>\<^esub>\<AA>(-,?\<GG>c)\<lparr>ObjMap\<rparr>) = \<AA>\<lparr>Obj\<rparr>"
unfolding E'_components
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps cs_intro: cat_cs_intros
)
show "E'\<lparr>ObjMap\<rparr> = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<beta>\<^esub>\<AA>(-,?\<GG>c)\<lparr>ObjMap\<rparr>"
proof(rule vsv_eqI, unfold dom_lhs dom_rhs)
fix a assume "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
with assms(3) show "E'\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<beta>\<^esub>\<AA>(-,?\<GG>c)\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
by
(
cs_concl
cs_simp: cat_op_simps cat_cs_simps
cs_intro: cat_cs_intros cat_op_intros
)
qed (auto simp: E'_components cat_cs_intros assms(3))
have dom_lhs: "\<D>\<^sub>\<circ> (E'\<lparr>ArrMap\<rparr>) = \<AA>\<lparr>Arr\<rparr>" unfolding E'_components by simp
from assms(3) have dom_rhs:
"\<D>\<^sub>\<circ> (Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<beta>\<^esub>\<AA>(-,?\<GG>c)\<lparr>ArrMap\<rparr>) = \<AA>\<lparr>Arr\<rparr>"
unfolding E'_components
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps cs_intro: cat_cs_intros
)
show "E'\<lparr>ArrMap\<rparr> = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<beta>\<^esub>\<AA>(-,?\<GG>c)\<lparr>ArrMap\<rparr>"
proof(rule vsv_eqI, unfold dom_lhs dom_rhs)
fix f assume prems: "f \<in>\<^sub>\<circ> \<AA>\<lparr>Arr\<rparr>"
then obtain a b where f: "f : a \<mapsto>\<^bsub>\<AA>\<^esub> b" by auto
have [cat_cs_simps]:
"cf_eval_arrow \<CC> (ntcf_arrow (?H_A\<GG> f)) (\<CC>\<lparr>CId\<rparr>\<lparr>c\<rparr>) =
cf_hom \<AA> [f, \<AA>\<lparr>CId\<rparr>\<lparr>?\<GG>c\<rparr>]\<^sub>\<circ>"
(is \<open>?cf_eval_arrow = ?cf_hom_f\<GG>c\<close>)
proof-
have cf_eval_arrow_f_CId_\<GG>c:
"?cf_eval_arrow :
Hom \<AA> b ?\<GG>c \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom \<AA> a ?\<GG>c"
proof(rule cf_eval_arrow_is_arr')
from f show "?H_A\<GG> f : ?H_\<AA>\<GG> b \<mapsto>\<^sub>C\<^sub>F ?H_\<AA>\<GG> a : \<CC> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
by (cs_concl cs_intro: cat_cs_intros)
qed
(
use f assms(3) in
\<open>
cs_concl
cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_op_intros
\<close>
)+
from f assms(3) have dom_lhs:
"\<D>\<^sub>\<circ> (?cf_eval_arrow\<lparr>ArrVal\<rparr>) = Hom \<AA> b ?\<GG>c"
by
(
cs_concl
cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_op_intros
)
from assms(3) f Ran.HomCod.category_axioms have cf_hom_f\<GG>c:
"?cf_hom_f\<GG>c :
Hom \<AA> b ?\<GG>c \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom \<AA> a ?\<GG>c"
by
(
cs_concl cs_shallow cs_intro:
cat_cs_intros cat_prod_cs_intros cat_op_intros
)
from f assms(3) have dom_rhs:
"\<D>\<^sub>\<circ> (?cf_hom_f\<GG>c\<lparr>ArrVal\<rparr>) = Hom \<AA> b ?\<GG>c"
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_op_intros
)
show ?thesis
proof(rule arr_Set_eqI)
from cf_eval_arrow_f_CId_\<GG>c show "arr_Set \<alpha> ?cf_eval_arrow"
by (auto dest: cat_Set_is_arrD(1))
from cf_hom_f\<GG>c show "arr_Set \<alpha> ?cf_hom_f\<GG>c"
by (auto dest: cat_Set_is_arrD(1))
show "?cf_eval_arrow\<lparr>ArrVal\<rparr> = ?cf_hom_f\<GG>c\<lparr>ArrVal\<rparr>"
proof(rule vsv_eqI, unfold dom_lhs dom_rhs, unfold in_Hom_iff)
from f assms(3) show "vsv (?cf_eval_arrow\<lparr>ArrVal\<rparr>)"
by (cs_concl cs_intro: cat_cs_intros)
from f assms(3) show "vsv (?cf_hom_f\<GG>c\<lparr>ArrVal\<rparr>)"
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros cat_op_intros
)
fix g assume "g : b \<mapsto>\<^bsub>\<AA>\<^esub> ?\<GG>c"
with f assms(3) show
"?cf_eval_arrow\<lparr>ArrVal\<rparr>\<lparr>g\<rparr> = ?cf_hom_f\<GG>c\<lparr>ArrVal\<rparr>\<lparr>g\<rparr>"
by
(
cs_concl
cs_simp: cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros cat_op_intros
)
qed simp
qed
(
use cf_eval_arrow_f_CId_\<GG>c cf_hom_f\<GG>c in
\<open>cs_concl cs_simp: cat_cs_simps\<close>
)+
qed
from f prems assms(3) show "E'\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> = Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<beta>\<^esub>\<AA>(-,?\<GG>c)\<lparr>ArrMap\<rparr>\<lparr>f\<rparr>"
by
(
cs_concl
cs_simp: cat_op_simps cat_cs_simps
cs_intro: cat_cs_intros cat_op_intros
)
qed (auto simp: E'_components cat_cs_intros assms(3))
qed simp_all
from Y' have inv_Y': "inv_ntcf Y' :
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<beta>\<^esub>\<AA>(-,?\<GG>c) \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>i\<^sub>s\<^sub>o N' : op_cat \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> cat_Set \<beta>"
unfolding E'_def by (auto intro: iso_ntcf_is_iso_arr)
interpret N'': is_functor \<beta> \<open>op_cat \<AA>\<close> \<open>cat_Set \<beta>\<close> \<open>L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<close>
by (rule L_10_5_N_is_functor[OF \<beta> \<alpha>\<beta> assms])
(** \<psi> **)
define \<psi> :: V
where "\<psi> =
[
(\<lambda>a\<in>\<^sub>\<circ>\<AA>\<lparr>Obj\<rparr>. ?ntcf_ua_fo a\<lparr>NTMap\<rparr>\<lparr>cf_map (?H_\<CC> c)\<rparr>),
N',
L_10_5_N \<alpha> \<beta> \<TT> \<KK> c,
op_cat \<AA>,
cat_Set \<beta>
]\<^sub>\<circ>"
have \<psi>_components:
"\<psi>\<lparr>NTMap\<rparr> = (\<lambda>a\<in>\<^sub>\<circ>\<AA>\<lparr>Obj\<rparr>. ?ntcf_ua_fo a\<lparr>NTMap\<rparr>\<lparr>cf_map (?H_\<CC> c)\<rparr>)"
"\<psi>\<lparr>NTDom\<rparr> = N'"
"\<psi>\<lparr>NTCod\<rparr> = L_10_5_N \<alpha> \<beta> \<TT> \<KK> c"
"\<psi>\<lparr>NTDGDom\<rparr> = op_cat \<AA>"
"\<psi>\<lparr>NTDGCod\<rparr> = cat_Set \<beta>"
unfolding \<psi>_def nt_field_simps by (simp_all add: nat_omega_simps)
note [cat_cs_simps] = Y'_components(2-5)
have \<psi>_NTMap_app[cat_cs_simps]:
"\<psi>\<lparr>NTMap\<rparr>\<lparr>a\<rparr> = ?ntcf_ua_fo a\<lparr>NTMap\<rparr>\<lparr>cf_map (?H_\<CC> c)\<rparr>"
if "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>" for a
using that unfolding \<psi>_components by simp
have \<psi>: "\<psi> : N' \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>i\<^sub>s\<^sub>o L_10_5_N \<alpha> \<beta> \<TT> \<KK> c : op_cat \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> cat_Set \<beta>"
proof-
show ?thesis
proof(intro is_iso_ntcfI is_ntcfI')
show "vfsequence \<psi>" unfolding \<psi>_def by auto
show "vcard \<psi> = 5\<^sub>\<nat>" unfolding \<psi>_def by (simp_all add: nat_omega_simps)
show "N' : op_cat \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> cat_Set \<beta>" by (rule N')
show "L_10_5_N \<alpha> \<beta> \<TT> \<KK> c : op_cat \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> cat_Set \<beta>"
by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)
show "\<psi>\<lparr>NTDom\<rparr> = N'" unfolding \<psi>_components by simp
show "\<psi>\<lparr>NTCod\<rparr> = L_10_5_N \<alpha> \<beta> \<TT> \<KK> c" unfolding \<psi>_components by simp
show "\<psi>\<lparr>NTDGDom\<rparr> = op_cat \<AA>" unfolding \<psi>_components by simp
show "\<psi>\<lparr>NTDGCod\<rparr> = cat_Set \<beta>" unfolding \<psi>_components by simp
show "vsv (\<psi>\<lparr>NTMap\<rparr>)" unfolding \<psi>_components by simp
show "\<D>\<^sub>\<circ> (\<psi>\<lparr>NTMap\<rparr>) = op_cat \<AA>\<lparr>Obj\<rparr>"
unfolding \<psi>_components by (simp add: cat_op_simps)
show \<psi>_NTMap_is_iso_arr[unfolded cat_op_simps]:
"\<psi>\<lparr>NTMap\<rparr>\<lparr>a\<rparr> : N'\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> \<mapsto>\<^sub>i\<^sub>s\<^sub>o\<^bsub>cat_Set \<beta>\<^esub> L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
if "a \<in>\<^sub>\<circ> op_cat \<AA>\<lparr>Obj\<rparr>" for a
proof-
note a = that[unfolded cat_op_simps]
interpret \<epsilon>:
is_cat_rKe_preserves \<alpha> \<BB> \<CC> \<AA> \<open>cat_Set \<alpha>\<close> \<KK> \<TT> \<GG> \<open>?H_\<AA> a\<close> \<epsilon>
by (rule cat_pw_rKe_preserved[OF a])
interpret a\<epsilon>:
is_cat_rKe \<alpha> \<BB> \<CC> \<open>cat_Set \<alpha>\<close> \<KK> \<open>?H_\<AA>\<TT> a\<close> \<open>?H_\<AA>\<GG> a\<close> \<open>?H_\<AA>\<epsilon> a\<close>
by (rule \<epsilon>.cat_rKe_preserves)
interpret is_iso_ntcf
\<beta>
\<open>op_cat (?FUNCT \<CC>)\<close>
\<open>cat_Set \<beta>\<close>
\<open>?H_FUNCT \<CC> (?H_\<AA>\<GG> a)\<close>
\<open>?H_FUNCT \<BB> (?H_\<AA>\<TT> a) \<circ>\<^sub>C\<^sub>F op_cf ?SET_\<KK>\<close>
\<open>?ntcf_ua_fo a\<close>
by (rule a\<epsilon>.cat_rKe_ntcf_ua_fo_is_iso_ntcf_if_ge_Limit[OF \<beta> \<alpha>\<beta>])
have "cf_map (?H_\<CC> c) \<in>\<^sub>\<circ> ?FUNCT \<CC>\<lparr>Obj\<rparr>"
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cat_FUNCT_cs_simps
cs_intro: cat_cs_intros cat_FUNCT_cs_intros
)
from
iso_ntcf_is_iso_arr[unfolded cat_op_simps, OF this]
a assms \<alpha>\<beta>
show ?thesis
by (*very slow*)
(
cs_prems
cs_simp:
cat_cs_simps cat_Kan_cs_simps cat_FUNCT_cs_simps cat_op_simps
cs_intro:
cat_small_cs_intros
cat_Kan_cs_intros
cat_cs_intros
cat_FUNCT_cs_intros
cat_op_intros
)
qed
show \<psi>_NTMap_is_arr[unfolded cat_op_simps]:
"\<psi>\<lparr>NTMap\<rparr>\<lparr>a\<rparr> : N'\<lparr>ObjMap\<rparr>\<lparr>a\<rparr> \<mapsto>\<^bsub>cat_Set \<beta>\<^esub> L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ObjMap\<rparr>\<lparr>a\<rparr>"
if "a \<in>\<^sub>\<circ> op_cat \<AA>\<lparr>Obj\<rparr>" for a
by
(
rule cat_Set_is_iso_arrD[
OF \<psi>_NTMap_is_iso_arr[OF that[unfolded cat_op_simps]]
]
)
show
"\<psi>\<lparr>NTMap\<rparr>\<lparr>b\<rparr> \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> N'\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> =
L_10_5_N \<alpha> \<beta> \<TT> \<KK> c\<lparr>ArrMap\<rparr>\<lparr>f\<rparr> \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> \<psi>\<lparr>NTMap\<rparr>\<lparr>a\<rparr>"
if "f : a \<mapsto>\<^bsub>op_cat \<AA>\<^esub> b" for a b f
proof-
note f = that[unfolded cat_op_simps]
from f have a: "a \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>" and b: "b \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>" by auto
interpret p_a_\<epsilon>:
is_cat_rKe_preserves \<alpha> \<BB> \<CC> \<AA> \<open>cat_Set \<alpha>\<close> \<KK> \<TT> \<GG> \<open>?H_\<AA> a\<close> \<epsilon>
by (rule cat_pw_rKe_preserved[OF a])
interpret a_\<epsilon>: is_cat_rKe
\<alpha> \<BB> \<CC> \<open>cat_Set \<alpha>\<close> \<KK> \<open>?H_\<AA>\<TT> a\<close> \<open>?H_\<AA>\<GG> a\<close> \<open>?H_\<AA>\<epsilon> a\<close>
by (rule p_a_\<epsilon>.cat_rKe_preserves)
interpret ntcf_ua_fo_a_\<epsilon>: is_iso_ntcf
\<beta> ?ua_NTDGDom \<open>cat_Set \<beta>\<close> \<open>?ua_NTDom a\<close> \<open>?ua_NTCod a\<close> \<open>?ua a\<close>
by (rule a_\<epsilon>.cat_rKe_ntcf_ua_fo_is_iso_ntcf_if_ge_Limit[OF \<beta> \<alpha>\<beta>])
interpret p_b_\<epsilon>:
is_cat_rKe_preserves \<alpha> \<BB> \<CC> \<AA> \<open>cat_Set \<alpha>\<close> \<KK> \<TT> \<GG> \<open>?H_\<AA> b\<close> \<epsilon>
by (rule cat_pw_rKe_preserved[OF b])
interpret b_\<epsilon>: is_cat_rKe
\<alpha> \<BB> \<CC> \<open>cat_Set \<alpha>\<close> \<KK> \<open>?H_\<AA>\<TT> b\<close> \<open>?H_\<AA>\<GG> b\<close> \<open>?H_\<AA>\<epsilon> b\<close>
by (rule p_b_\<epsilon>.cat_rKe_preserves)
interpret ntcf_ua_fo_b_\<epsilon>: is_iso_ntcf
\<beta> ?ua_NTDGDom \<open>cat_Set \<beta>\<close> \<open>?ua_NTDom b\<close> \<open>?ua_NTCod b\<close> \<open>?ua b\<close>
by (rule b_\<epsilon>.cat_rKe_ntcf_ua_fo_is_iso_ntcf_if_ge_Limit[OF \<beta> \<alpha>\<beta>])
interpret \<KK>_SET: is_tiny_functor \<beta> \<open>?FUNCT \<CC>\<close> \<open>?FUNCT \<BB>\<close> ?SET_\<KK>
by
(
rule exp_cat_cf_is_tiny_functor[
OF \<beta> \<alpha>\<beta> AG.category_cat_Set AG.is_functor_axioms
]
)
from f interpret Hom_f:
is_ntcf \<alpha> \<AA> \<open>cat_Set \<alpha>\<close> \<open>?H_\<AA> a\<close> \<open>?H_\<AA> b\<close> \<open>?H_A f\<close>
by (cs_concl cs_intro: cat_cs_intros)
let ?cf_hom_lhs =
\<open>
cf_hom
(?FUNCT \<CC>)
[ntcf_arrow (ntcf_id (?H_\<CC> c)), ntcf_arrow (?H_A\<GG> f)]\<^sub>\<circ>
\<close>
let ?cf_hom_rhs =
\<open>
cf_hom
(?FUNCT \<BB>)
[
ntcf_arrow (ntcf_id (?H_\<CC> c \<circ>\<^sub>C\<^sub>F \<KK>)),
ntcf_arrow (?H_A f \<circ>\<^sub>N\<^sub>T\<^sub>C\<^sub>F\<^sub>-\<^sub>C\<^sub>F \<TT>)
]\<^sub>\<circ>
\<close>
let ?dom =
\<open>Hom (?FUNCT \<CC>) (cf_map (?H_\<CC> c)) (cf_map (?H_\<AA>\<GG> a))\<close>
let ?cod = \<open>Hom (?FUNCT \<BB>) (cf_map (?H_\<CC>\<KK> c)) (cf_map (?H_\<AA>\<TT> b))\<close>
let ?cf_hom_lhs_umap_fo_inter =
\<open>Hom (?FUNCT \<CC>) (cf_map (?H_\<CC> c)) (cf_map (?H_\<AA>\<GG> b))\<close>
let ?umap_fo_cf_hom_rhs_inter =
\<open>Hom (?FUNCT \<BB>) (cf_map (?H_\<CC>\<KK> c)) (cf_map (?H_\<AA>\<TT> a))\<close>
have [cat_cs_simps]:
"?umap_fo b \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?cf_hom_lhs =
?cf_hom_rhs \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?umap_fo a"
proof-
from f assms(3) \<alpha>\<beta> have cf_hom_lhs:
"?cf_hom_lhs : ?dom \<mapsto>\<^bsub>cat_Set \<beta>\<^esub> ?cf_hom_lhs_umap_fo_inter"
by
(
cs_concl
cs_simp: cat_cs_simps cat_FUNCT_cs_simps
cs_intro:
cat_cs_intros
cat_FUNCT_cs_intros
cat_prod_cs_intros
cat_op_intros
)
from f assms(3) \<alpha>\<beta> have umap_fo_b:
"?umap_fo b : ?cf_hom_lhs_umap_fo_inter \<mapsto>\<^bsub>cat_Set \<beta>\<^esub> ?cod"
by
(
cs_concl
cs_simp: cat_cs_simps cat_FUNCT_cs_simps
cs_intro:
cat_cs_intros
cat_FUNCT_cs_intros
cat_prod_cs_intros
cat_op_intros
)
from cf_hom_lhs umap_fo_b have umap_fo_cf_hom_lhs:
"?umap_fo b \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?cf_hom_lhs : ?dom \<mapsto>\<^bsub>cat_Set \<beta>\<^esub> ?cod"
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cs_intro: cat_cs_intros
)
then have dom_umap_fo_cf_hom_lhs:
"\<D>\<^sub>\<circ> ((?umap_fo b \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?cf_hom_lhs)\<lparr>ArrVal\<rparr>) = ?dom"
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cs_intro: cat_cs_intros
)
from f assms(3) \<alpha>\<beta> have cf_hom_rhs:
"?cf_hom_rhs : ?umap_fo_cf_hom_rhs_inter \<mapsto>\<^bsub>cat_Set \<beta>\<^esub> ?cod"
by (*slow*)
(
cs_concl
cs_simp: cat_cs_simps cat_FUNCT_cs_simps
cs_intro:
cat_cs_intros
cat_FUNCT_cs_intros
cat_prod_cs_intros
cat_op_intros
)
from f assms(3) \<alpha>\<beta> have umap_fo_a:
"?umap_fo a : ?dom \<mapsto>\<^bsub>cat_Set \<beta>\<^esub> ?umap_fo_cf_hom_rhs_inter"
by (*slow*)
(
cs_concl
cs_simp: cat_cs_simps cat_FUNCT_cs_simps
cs_intro:
cat_cs_intros
cat_FUNCT_cs_intros
cat_prod_cs_intros
cat_op_intros
)
from cf_hom_rhs umap_fo_a have cf_hom_rhs_umap_fo_a:
"?cf_hom_rhs \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?umap_fo a : ?dom \<mapsto>\<^bsub>cat_Set \<beta>\<^esub> ?cod"
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cs_intro: cat_cs_intros
)
then have dom_cf_hom_rhs_umap_fo_a:
"\<D>\<^sub>\<circ> ((?cf_hom_rhs \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?umap_fo a)\<lparr>ArrVal\<rparr>) = ?dom"
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps cs_intro: cat_cs_intros
)
show ?thesis
proof(rule arr_Set_eqI)
from umap_fo_cf_hom_lhs show arr_Set_umap_fo_cf_hom_lhs:
"arr_Set \<beta> (?umap_fo b \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?cf_hom_lhs)"
by (auto dest: cat_Set_is_arrD(1))
from cf_hom_rhs_umap_fo_a show arr_Set_cf_hom_rhs_umap_fo_a:
"arr_Set \<beta> (?cf_hom_rhs \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?umap_fo a)"
by (auto dest: cat_Set_is_arrD(1))
show
"(?umap_fo b \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?cf_hom_lhs)\<lparr>ArrVal\<rparr> =
(?cf_hom_rhs \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?umap_fo a)\<lparr>ArrVal\<rparr>"
proof
(
rule vsv_eqI,
unfold
dom_umap_fo_cf_hom_lhs dom_cf_hom_rhs_umap_fo_a in_Hom_iff;
(rule refl)?
)
fix \<HH> assume prems:
"\<HH> : cf_map (?H_\<CC> c) \<mapsto>\<^bsub>?FUNCT \<CC>\<^esub> cf_map (?H_\<AA>\<GG> a)"
let ?\<HH> = \<open>ntcf_of_ntcf_arrow \<CC> (cat_Set \<alpha>) \<HH>\<close>
let ?lhs = \<open>?H_\<AA>\<epsilon> b \<bullet>\<^sub>N\<^sub>T\<^sub>C\<^sub>F ((?H_A\<GG> f \<bullet>\<^sub>N\<^sub>T\<^sub>C\<^sub>F ?\<HH>) \<circ>\<^sub>N\<^sub>T\<^sub>C\<^sub>F\<^sub>-\<^sub>C\<^sub>F \<KK>)\<close>
let ?rhs =
\<open>(?H_A f \<circ>\<^sub>N\<^sub>T\<^sub>C\<^sub>F\<^sub>-\<^sub>C\<^sub>F \<TT> \<bullet>\<^sub>N\<^sub>T\<^sub>C\<^sub>F ?H_\<AA>\<epsilon> a \<bullet>\<^sub>N\<^sub>T\<^sub>C\<^sub>F (?\<HH> \<circ>\<^sub>N\<^sub>T\<^sub>C\<^sub>F\<^sub>-\<^sub>C\<^sub>F \<KK>))\<close>
let ?cf_hom_\<AA>\<epsilon> = \<open>\<lambda>b b'. cf_hom \<AA> [\<AA>\<lparr>CId\<rparr>\<lparr>b\<rparr>, \<epsilon>\<lparr>NTMap\<rparr>\<lparr>b'\<rparr>]\<^sub>\<circ>\<close>
let ?Yc = \<open>\<lambda>Q. Yoneda_component (?H_\<AA> b) a f Q\<close>
let ?\<HH>\<KK> = \<open>\<lambda>b'. ?\<HH>\<lparr>NTMap\<rparr>\<lparr>\<KK>\<lparr>ObjMap\<rparr>\<lparr>b'\<rparr>\<rparr>\<close>
let ?\<GG>\<KK> = \<open>\<lambda>b'. \<GG>\<lparr>ObjMap\<rparr>\<lparr>\<KK>\<lparr>ObjMap\<rparr>\<lparr>b'\<rparr>\<rparr>\<close>
have [cat_cs_simps]:
"cf_of_cf_map \<CC> (cat_Set \<alpha>) (cf_map (?H_\<CC> c)) = ?H_\<CC> c"
by
(
cs_concl cs_shallow
cs_simp: cat_FUNCT_cs_simps cs_intro: cat_cs_intros
)
have [cat_cs_simps]:
"cf_of_cf_map \<CC> (cat_Set \<alpha>) (cf_map (?H_\<AA>\<GG> a)) = ?H_\<AA>\<GG> a"
by
(
cs_concl cs_shallow
cs_simp: cat_FUNCT_cs_simps cs_intro: cat_cs_intros
)
note \<HH> = cat_FUNCT_is_arrD[OF prems, unfolded cat_cs_simps]
have Hom_c: "?H_\<CC>\<KK> c : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros)
have [cat_cs_simps]: "?lhs = ?rhs"
proof(rule ntcf_eqI)
from \<HH>(1) f show lhs:
"?lhs : ?H_\<CC>\<KK> c \<mapsto>\<^sub>C\<^sub>F ?H_\<AA>\<TT> b : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
by (cs_concl cs_simp: cs_intro: cat_cs_intros)
then have dom_lhs: "\<D>\<^sub>\<circ> (?lhs\<lparr>NTMap\<rparr>) = \<BB>\<lparr>Obj\<rparr>"
by (cs_concl cs_simp: cat_cs_simps)+
from \<HH>(1) f show rhs:
"?rhs : ?H_\<CC>\<KK> c \<mapsto>\<^sub>C\<^sub>F ?H_\<AA>\<TT> b : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> cat_Set \<alpha>"
by (cs_concl cs_intro: cat_cs_intros)
then have dom_rhs: "\<D>\<^sub>\<circ> (?rhs\<lparr>NTMap\<rparr>) = \<BB>\<lparr>Obj\<rparr>"
by (cs_concl cs_simp: cat_cs_simps)+
have [cat_cs_simps]:
"?cf_hom_\<AA>\<epsilon> b b' \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub>
(?Yc (?\<GG>\<KK> b') \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub> ?\<HH>\<KK> b') =
?Yc (\<TT>\<lparr>ObjMap\<rparr>\<lparr>b'\<rparr>) \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub>
(?cf_hom_\<AA>\<epsilon> a b' \<circ>\<^sub>A\<^bsub>cat_Set \<alpha>\<^esub> ?\<HH>\<KK> b')"
(is \<open>?lhs_Set = ?rhs_Set\<close>)
if "b' \<in>\<^sub>\<circ> \<BB>\<lparr>Obj\<rparr>" for b'
proof-
let ?\<KK>b' = \<open>\<KK>\<lparr>ObjMap\<rparr>\<lparr>b'\<rparr>\<close>
from \<HH>(1) f that assms(3) Ran.HomCod.category_axioms
have lhs_Set_is_arr: "?lhs_Set :
Hom \<CC> c (?\<KK>b') \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom \<AA> b (\<TT>\<lparr>ObjMap\<rparr>\<lparr>b'\<rparr>)"
by
(
cs_concl
cs_simp: cat_cs_simps cat_op_simps
cs_intro:
cat_cs_intros cat_prod_cs_intros cat_op_intros
)
then have dom_lhs_Set: "\<D>\<^sub>\<circ> (?lhs_Set\<lparr>ArrVal\<rparr>) = Hom \<CC> c ?\<KK>b'"
by (cs_concl cs_shallow cs_simp: cat_cs_simps)
from \<HH>(1) f that assms(3) Ran.HomCod.category_axioms
have rhs_Set_is_arr: "?rhs_Set :
Hom \<CC> c (?\<KK>b') \<mapsto>\<^bsub>cat_Set \<alpha>\<^esub> Hom \<AA> b (\<TT>\<lparr>ObjMap\<rparr>\<lparr>b'\<rparr>)"
by
(
cs_concl
cs_simp: cat_cs_simps cat_op_simps
cs_intro:
cat_cs_intros cat_prod_cs_intros cat_op_intros
)
then have dom_rhs_Set: "\<D>\<^sub>\<circ> (?rhs_Set\<lparr>ArrVal\<rparr>) = Hom \<CC> c ?\<KK>b'"
by (cs_concl cs_shallow cs_simp: cat_cs_simps)
show ?thesis
proof(rule arr_Set_eqI)
from lhs_Set_is_arr show arr_Set_lhs_Set: "arr_Set \<alpha> ?lhs_Set"
by (auto dest: cat_Set_is_arrD(1))
from rhs_Set_is_arr show arr_Set_rhs_Set: "arr_Set \<alpha> ?rhs_Set"
by (auto dest: cat_Set_is_arrD(1))
show "?lhs_Set\<lparr>ArrVal\<rparr> = ?rhs_Set\<lparr>ArrVal\<rparr>"
proof(rule vsv_eqI, unfold dom_lhs_Set dom_rhs_Set in_Hom_iff)
fix h assume "h : c \<mapsto>\<^bsub>\<CC>\<^esub> ?\<KK>b'"
with \<HH>(1) f that assms Ran.HomCod.category_axioms show
"?lhs_Set\<lparr>ArrVal\<rparr>\<lparr>h\<rparr> = ?rhs_Set\<lparr>ArrVal\<rparr>\<lparr>h\<rparr>"
by (*exceptionally slow*)
(
cs_concl
cs_simp: cat_cs_simps cat_op_simps
cs_intro:
cat_cs_intros cat_prod_cs_intros cat_op_intros
)
qed (use arr_Set_lhs_Set arr_Set_rhs_Set in auto)
qed
(
use lhs_Set_is_arr rhs_Set_is_arr in
\<open>cs_concl cs_shallow cs_simp: cat_cs_simps\<close>
)+
qed
show "?lhs\<lparr>NTMap\<rparr> = ?rhs\<lparr>NTMap\<rparr>"
proof(rule vsv_eqI, unfold dom_lhs dom_rhs)
fix b' assume "b' \<in>\<^sub>\<circ> \<BB>\<lparr>Obj\<rparr>"
with \<HH>(1) f assms(3) show "?lhs\<lparr>NTMap\<rparr>\<lparr>b'\<rparr> = ?rhs\<lparr>NTMap\<rparr>\<lparr>b'\<rparr>"
by (*slow*)
(
cs_concl
cs_simp: cat_cs_simps cat_op_simps
cs_intro: cat_cs_intros
)
qed (cs_concl cs_intro: cat_cs_intros)
qed simp_all
from
assms(3) f \<HH>(1) prems \<alpha>\<beta>
(*speedup*)
Ran.HomCod.category_axioms
FUNCT_\<CC>.category_axioms
FUNCT_\<BB>.category_axioms
AG.is_functor_axioms
Ran.is_functor_axioms
Hom_f.is_ntcf_axioms
show
"(?umap_fo b \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?cf_hom_lhs)\<lparr>ArrVal\<rparr>\<lparr>\<HH>\<rparr> =
(?cf_hom_rhs \<circ>\<^sub>A\<^bsub>cat_Set \<beta>\<^esub> ?umap_fo a)\<lparr>ArrVal\<rparr>\<lparr>\<HH>\<rparr>"
by (subst (1 2) \<HH>(2)) (*exceptionally slow*)
(
cs_concl
cs_simp: cat_cs_simps cat_FUNCT_cs_simps cat_op_simps
cs_intro:
cat_cs_intros
cat_prod_cs_intros
cat_FUNCT_cs_intros
cat_op_intros
)
qed
(
use arr_Set_umap_fo_cf_hom_lhs arr_Set_cf_hom_rhs_umap_fo_a in
auto
)
qed
(
use umap_fo_cf_hom_lhs cf_hom_rhs_umap_fo_a in
\<open>cs_concl cs_shallow cs_simp: cat_cs_simps\<close>
)+
qed
from f assms \<alpha>\<beta> show ?thesis
by (*slow*)
(
cs_concl
cs_simp: cat_cs_simps cat_Kan_cs_simps cat_FUNCT_cs_simps
cs_intro: cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros
)
qed
qed auto
qed
(**main**)
from L_10_5_\<chi>_is_iso_ntcf[OF \<beta> \<alpha>\<beta> assms] have inv_\<chi>:
"inv_ntcf (L_10_5_\<chi> \<alpha> \<beta> \<TT> \<KK> c) :
L_10_5_N \<alpha> \<beta> \<TT> \<KK> c \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>i\<^sub>s\<^sub>o cf_Cone \<alpha> \<beta> ?\<TT>_c\<KK> :
op_cat \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> cat_Set \<beta>"
by (auto intro: iso_ntcf_is_iso_arr)
define \<phi> where "\<phi> = inv_ntcf (L_10_5_\<chi> \<alpha> \<beta> \<TT> \<KK> c) \<bullet>\<^sub>N\<^sub>T\<^sub>C\<^sub>F \<psi> \<bullet>\<^sub>N\<^sub>T\<^sub>C\<^sub>F inv_ntcf Y'"
from inv_Y' \<psi> inv_\<chi> have \<phi>: "\<phi> :
Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<beta>\<^esub>\<AA>(-,?\<GG>c) \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>i\<^sub>s\<^sub>o cf_Cone \<alpha> \<beta> ?\<TT>_c\<KK> :
op_cat \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> cat_Set \<beta>"
unfolding \<phi>_def by (cs_concl cs_shallow cs_intro: cat_cs_intros)
interpret \<phi>: is_iso_ntcf
\<beta> \<open>op_cat \<AA>\<close> \<open>cat_Set \<beta>\<close> \<open>Hom\<^sub>O\<^sub>.\<^sub>C\<^bsub>\<beta>\<^esub>\<AA>(-,?\<GG>c)\<close> \<open>cf_Cone \<alpha> \<beta> ?\<TT>_c\<KK>\<close> \<phi>
by (rule \<phi>)
let ?\<phi>_\<GG>c_CId = \<open>\<phi>\<lparr>NTMap\<rparr>\<lparr>?\<GG>c\<rparr>\<lparr>ArrVal\<rparr>\<lparr>\<AA>\<lparr>CId\<rparr>\<lparr>?\<GG>c\<rparr>\<rparr>\<close>
let ?ntcf_\<phi>_\<GG>c_CId = \<open>ntcf_of_ntcf_arrow (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> ?\<phi>_\<GG>c_CId\<close>
from AG.vempty_is_zet assms(3) have \<Delta>: "?\<Delta> : \<AA> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<beta>\<^esub> ?c\<KK>_\<AA>"
by
(
cs_concl cs_shallow
cs_simp: cat_comma_cs_simps
cs_intro: cat_cs_intros cat_comma_cs_intros
)
from assms(3) have \<GG>c: "?\<GG>c \<in>\<^sub>\<circ> \<AA>\<lparr>Obj\<rparr>"
by (cs_concl cs_shallow cs_intro: cat_cs_intros)
from AG.vempty_is_zet have \<TT>_c\<KK>: "cf_map (?\<TT>_c\<KK>) \<in>\<^sub>\<circ> ?c\<KK>_\<AA>\<lparr>Obj\<rparr>"
by
(
cs_concl
cs_simp: cat_FUNCT_components(1)
cs_intro: cat_cs_intros cat_FUNCT_cs_intros
)
from
\<phi>.ntcf_NTMap_is_arr[unfolded cat_op_simps, OF \<GG>c]
assms(3)
AG.vempty_is_zet
\<beta>.vempty_is_zet
\<alpha>\<beta>
have \<phi>_\<GG>c: "\<phi>\<lparr>NTMap\<rparr>\<lparr>?\<GG>c\<rparr> :
Hom \<AA> ?\<GG>c?\<GG>c \<mapsto>\<^bsub>cat_Set \<beta>\<^esub>
Hom ?c\<KK>_\<AA> (cf_map (?cf_c\<KK>_\<AA> ?\<GG>c)) (cf_map ?\<TT>_c\<KK>)"
by (*very slow*)
(
cs_prems
cs_simp:
cat_cs_simps
cat_Kan_cs_simps
cat_comma_cs_simps
cat_op_simps
cat_FUNCT_components(1)
cs_intro:
cat_Kan_cs_intros
cat_comma_cs_intros
cat_cs_intros
cat_FUNCT_cs_intros
cat_op_intros
)
with assms(3) have \<phi>_\<GG>c_CId:
"?\<phi>_\<GG>c_CId : cf_map (?cf_c\<KK>_\<AA> ?\<GG>c) \<mapsto>\<^bsub>?c\<KK>_\<AA>\<^esub> cf_map ?\<TT>_c\<KK>"
by (cs_concl cs_shallow cs_intro: cat_cs_intros)
have ntcf_arrow_\<phi>_\<GG>c_CId: "ntcf_arrow ?ntcf_\<phi>_\<GG>c_CId = ?\<phi>_\<GG>c_CId"
by (rule cat_FUNCT_is_arrD(2)[OF \<phi>_\<GG>c_CId, symmetric])
have ua: "universal_arrow_fo ?\<Delta> (cf_map (?\<TT>_c\<KK>)) ?\<GG>c ?\<phi>_\<GG>c_CId"
by
(
rule is_functor.cf_universal_arrow_fo_if_is_iso_ntcf[
OF \<Delta> \<GG>c \<TT>_c\<KK> \<phi>[unfolded cf_Cone_def cat_cs_simps]
]
)
moreover have ntcf_\<phi>_\<GG>c_CId:
"?ntcf_\<phi>_\<GG>c_CId : ?\<GG>c <\<^sub>C\<^sub>F\<^sub>.\<^sub>c\<^sub>o\<^sub>n\<^sub>e ?\<TT>_c\<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
proof(intro is_cat_coneI)
from cat_FUNCT_is_arrD(1)[OF \<phi>_\<GG>c_CId] assms(3) AG.vempty_is_zet show
"ntcf_of_ntcf_arrow (c \<down>\<^sub>C\<^sub>F \<KK>) \<AA> ?\<phi>_\<GG>c_CId :
?cf_c\<KK>_\<AA> ?\<GG>c \<mapsto>\<^sub>C\<^sub>F ?\<TT>_c\<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
by
(
cs_prems
cs_simp: cat_cs_simps cat_FUNCT_cs_simps
cs_intro: cat_cs_intros cat_FUNCT_cs_intros
)
qed (rule \<GG>c)
ultimately have "?ntcf_\<phi>_\<GG>c_CId : ?\<GG>c <\<^sub>C\<^sub>F\<^sub>.\<^sub>l\<^sub>i\<^sub>m ?\<TT>_c\<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
by (intro is_cat_cone.cat_cone_is_cat_limit)
(simp_all add: ntcf_arrow_\<phi>_\<GG>c_CId)
then show ?thesis using that by auto
qed
lemma (in is_cat_pw_lKe) cat_pw_lKe_ex_cat_colimit:
\<comment>\<open>Based on the elements of Chapter X-5 in \cite{mac_lane_categories_2010}.\<close>
assumes "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>"
and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
obtains UA
where "UA : \<TT> \<circ>\<^sub>C\<^sub>F \<KK> \<^sub>C\<^sub>F\<Sqinter>\<^sub>O c >\<^sub>C\<^sub>F\<^sub>.\<^sub>c\<^sub>o\<^sub>l\<^sub>i\<^sub>m \<FF>\<lparr>ObjMap\<rparr>\<lparr>c\<rparr> : \<KK> \<^sub>C\<^sub>F\<down> c \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
proof-
from
is_cat_pw_rKe.cat_pw_rKe_ex_cat_limit
[
OF is_cat_pw_rKe_op AG.is_functor_op ntcf_lKe.NTDom.is_functor_op,
unfolded cat_op_simps,
OF assms(3)
]
obtain UA where UA: "UA :
\<FF>\<lparr>ObjMap\<rparr>\<lparr>c\<rparr> <\<^sub>C\<^sub>F\<^sub>.\<^sub>l\<^sub>i\<^sub>m op_cf \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F (op_cf \<KK>) :
c \<down>\<^sub>C\<^sub>F (op_cf \<KK>) \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> op_cat \<AA>"
by auto
from assms(3) have [cat_cs_simps]:
"op_cf \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F (op_cf \<KK>) \<circ>\<^sub>C\<^sub>F op_cf_obj_comma \<KK> c =
op_cf \<TT> \<circ>\<^sub>C\<^sub>F op_cf (\<KK> \<^sub>C\<^sub>F\<Sqinter>\<^sub>O c)"
by
(
cs_concl cs_shallow
cs_simp: cat_cs_simps AG.op_cf_cf_obj_comma_proj[OF assms(3)]
cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros
)
from assms(3) have [cat_op_simps]:
"\<TT> \<circ>\<^sub>C\<^sub>F op_cf (c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F (op_cf \<KK>)) \<circ>\<^sub>C\<^sub>F op_cf (op_cf_obj_comma \<KK> c) =
\<TT> \<circ>\<^sub>C\<^sub>F \<KK> \<^sub>C\<^sub>F\<Sqinter>\<^sub>O c"
by
(
cs_concl cs_shallow
cs_simp:
cat_cs_simps cat_op_simps
op_cf_cf_comp[symmetric] AG.op_cf_cf_obj_comma_proj[symmetric]
cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros
)
from assms(3) have [cat_op_simps]: "op_cat (op_cat (\<KK> \<^sub>C\<^sub>F\<down> c)) = \<KK> \<^sub>C\<^sub>F\<down> c"
by
(
cs_concl cs_shallow
cs_simp: cat_op_simps cs_intro: cat_cs_intros cat_comma_cs_intros
)
note ntcf_cf_comp_is_cat_limit_if_is_iso_functor =
ntcf_cf_comp_is_cat_limit_if_is_iso_functor
[
OF UA AG.op_cf_obj_comma_is_iso_functor[OF assms(3)],
unfolded cat_op_simps
]
have "op_ntcf UA \<circ>\<^sub>N\<^sub>T\<^sub>C\<^sub>F\<^sub>-\<^sub>C\<^sub>F op_cf (op_cf_obj_comma \<KK> c) :
\<TT> \<circ>\<^sub>C\<^sub>F \<KK> \<^sub>C\<^sub>F\<Sqinter>\<^sub>O c >\<^sub>C\<^sub>F\<^sub>.\<^sub>c\<^sub>o\<^sub>l\<^sub>i\<^sub>m \<FF>\<lparr>ObjMap\<rparr>\<lparr>c\<rparr> : \<KK> \<^sub>C\<^sub>F\<down> c \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
by
(
rule is_cat_limit.is_cat_colimit_op
[
OF ntcf_cf_comp_is_cat_limit_if_is_iso_functor,
unfolded cat_op_simps
]
)
then show ?thesis using that by auto
qed
subsection\<open>The limit and the colimit for the pointwise Kan extensions\<close>
subsubsection\<open>Definition and elementary properties\<close>
text\<open>See Theorem 3 in Chapter X-5 in \<^cite>\<open>"mac_lane_categories_2010"\<close>.\<close>
definition the_pw_cat_rKe_limit :: "V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V"
where "the_pw_cat_rKe_limit \<alpha> \<KK> \<TT> \<GG> c =
[
\<GG>\<lparr>ObjMap\<rparr>\<lparr>c\<rparr>,
(
SOME UA.
UA : \<GG>\<lparr>ObjMap\<rparr>\<lparr>c\<rparr> <\<^sub>C\<^sub>F\<^sub>.\<^sub>l\<^sub>i\<^sub>m \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<TT>\<lparr>HomCod\<rparr>
)
]\<^sub>\<circ>"
definition the_pw_cat_lKe_colimit :: "V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V \<Rightarrow> V"
where "the_pw_cat_lKe_colimit \<alpha> \<KK> \<TT> \<FF> c =
[
\<FF>\<lparr>ObjMap\<rparr>\<lparr>c\<rparr>,
op_ntcf
(
the_pw_cat_rKe_limit \<alpha> (op_cf \<KK>) (op_cf \<TT>) (op_cf \<FF>) c\<lparr>UArr\<rparr> \<circ>\<^sub>N\<^sub>T\<^sub>C\<^sub>F\<^sub>-\<^sub>C\<^sub>F
op_cf_obj_comma \<KK> c
)
]\<^sub>\<circ>"
text\<open>Components.\<close>
lemma the_pw_cat_rKe_limit_components:
shows "the_pw_cat_rKe_limit \<alpha> \<KK> \<TT> \<GG> c\<lparr>UObj\<rparr> = \<GG>\<lparr>ObjMap\<rparr>\<lparr>c\<rparr>"
and "the_pw_cat_rKe_limit \<alpha> \<KK> \<TT> \<GG> c\<lparr>UArr\<rparr> =
(
SOME UA.
UA : \<GG>\<lparr>ObjMap\<rparr>\<lparr>c\<rparr> <\<^sub>C\<^sub>F\<^sub>.\<^sub>l\<^sub>i\<^sub>m \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<TT>\<lparr>HomCod\<rparr>
)"
unfolding the_pw_cat_rKe_limit_def ua_field_simps
by (simp_all add: nat_omega_simps)
lemma the_pw_cat_lKe_colimit_components:
shows "the_pw_cat_lKe_colimit \<alpha> \<KK> \<TT> \<FF> c\<lparr>UObj\<rparr> = \<FF>\<lparr>ObjMap\<rparr>\<lparr>c\<rparr>"
and "the_pw_cat_lKe_colimit \<alpha> \<KK> \<TT> \<FF> c\<lparr>UArr\<rparr> = op_ntcf
(
the_pw_cat_rKe_limit \<alpha> (op_cf \<KK>) (op_cf \<TT>) (op_cf \<FF>) c\<lparr>UArr\<rparr> \<circ>\<^sub>N\<^sub>T\<^sub>C\<^sub>F\<^sub>-\<^sub>C\<^sub>F
op_cf_obj_comma \<KK> c
)"
unfolding the_pw_cat_lKe_colimit_def ua_field_simps
by (simp_all add: nat_omega_simps)
context is_functor
begin
lemmas the_pw_cat_rKe_limit_components' =
the_pw_cat_rKe_limit_components[where \<TT>=\<FF>, unfolded cat_cs_simps]
end
subsubsection\<open>
The limit for the pointwise right Kan extension is a limit,
the colimit for the pointwise left Kan extension is a colimit
\<close>
lemma (in is_cat_pw_rKe) cat_pw_rKe_the_pw_cat_rKe_limit_is_cat_limit:
assumes "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>" and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>" and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "the_pw_cat_rKe_limit \<alpha> \<KK> \<TT> \<GG> c\<lparr>UArr\<rparr> :
the_pw_cat_rKe_limit \<alpha> \<KK> \<TT> \<GG> c\<lparr>UObj\<rparr> <\<^sub>C\<^sub>F\<^sub>.\<^sub>l\<^sub>i\<^sub>m \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK> :
c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
proof-
from cat_pw_rKe_ex_cat_limit[OF assms] obtain UA
where UA: "UA : \<GG>\<lparr>ObjMap\<rparr>\<lparr>c\<rparr> <\<^sub>C\<^sub>F\<^sub>.\<^sub>l\<^sub>i\<^sub>m \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F \<KK> : c \<down>\<^sub>C\<^sub>F \<KK> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
by auto
show ?thesis
unfolding the_pw_cat_rKe_limit_components
by (rule someI2, unfold cat_cs_simps, rule UA)
qed
lemma (in is_cat_pw_lKe) cat_pw_lKe_the_pw_cat_lKe_colimit_is_cat_colimit:
assumes "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>" and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>" and "c \<in>\<^sub>\<circ> \<CC>\<lparr>Obj\<rparr>"
shows "the_pw_cat_lKe_colimit \<alpha> \<KK> \<TT> \<FF> c\<lparr>UArr\<rparr> :
\<TT> \<circ>\<^sub>C\<^sub>F \<KK> \<^sub>C\<^sub>F\<Sqinter>\<^sub>O c >\<^sub>C\<^sub>F\<^sub>.\<^sub>c\<^sub>o\<^sub>l\<^sub>i\<^sub>m the_pw_cat_lKe_colimit \<alpha> \<KK> \<TT> \<FF> c\<lparr>UObj\<rparr> :
\<KK> \<^sub>C\<^sub>F\<down> c \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
proof-
interpret \<KK>: is_functor \<alpha> \<BB> \<CC> \<KK> by (rule assms(1))
interpret \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule assms(2))
note cat_pw_rKe_the_pw_cat_rKe_limit_is_cat_limit =
is_cat_pw_rKe.cat_pw_rKe_the_pw_cat_rKe_limit_is_cat_limit
[
OF is_cat_pw_rKe_op AG.is_functor_op ntcf_lKe.NTDom.is_functor_op,
unfolded cat_op_simps,
OF assms(3)
]
from assms(3) have
"op_cf \<TT> \<circ>\<^sub>C\<^sub>F c \<^sub>O\<Sqinter>\<^sub>C\<^sub>F (op_cf \<KK>) \<circ>\<^sub>C\<^sub>F op_cf_obj_comma \<KK> c =
op_cf \<TT> \<circ>\<^sub>C\<^sub>F op_cf (\<KK> \<^sub>C\<^sub>F\<Sqinter>\<^sub>O c)"
by
(
cs_concl cs_shallow
cs_simp:
cat_cs_simps cat_comma_cs_simps cat_op_simps
AG.op_cf_cf_obj_comma_proj[OF assms(3)]
cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros
)
note ntcf_cf_comp_is_cat_limit_if_is_iso_functor =
ntcf_cf_comp_is_cat_limit_if_is_iso_functor
[
OF
cat_pw_rKe_the_pw_cat_rKe_limit_is_cat_limit
AG.op_cf_obj_comma_is_iso_functor[OF assms(3)],
unfolded this, folded op_cf_cf_comp
]
from assms(3) have [cat_op_simps]: "op_cat (op_cat (\<KK> \<^sub>C\<^sub>F\<down> c)) = \<KK> \<^sub>C\<^sub>F\<down> c"
by
(
cs_concl cs_shallow
cs_simp: cat_op_simps cs_intro: cat_cs_intros cat_comma_cs_intros
)
from assms(3) have [cat_op_simps]: "op_cf (op_cf (\<KK> \<^sub>C\<^sub>F\<Sqinter>\<^sub>O c)) = \<KK> \<^sub>C\<^sub>F\<Sqinter>\<^sub>O c"
by
(
cs_concl cs_shallow
cs_simp: cat_op_simps cs_intro: cat_cs_intros cat_comma_cs_intros
)
have [cat_op_simps]:
"the_pw_cat_rKe_limit \<alpha> (op_cf \<KK>) (op_cf \<TT>) (op_cf \<FF>) c\<lparr>UObj\<rparr> =
the_pw_cat_lKe_colimit \<alpha> \<KK> \<TT> \<FF> c\<lparr>UObj\<rparr>"
unfolding
the_pw_cat_lKe_colimit_components
the_pw_cat_rKe_limit_components
cat_op_simps
by simp
show ?thesis
by
(
rule is_cat_limit.is_cat_colimit_op
[
OF ntcf_cf_comp_is_cat_limit_if_is_iso_functor,
folded the_pw_cat_lKe_colimit_components,
unfolded cat_op_simps
]
)
qed
lemma (in is_cat_pw_rKe) cat_pw_rKe_the_ntcf_rKe_is_cat_rKe:
assumes "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>" and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
shows "the_ntcf_rKe \<alpha> \<TT> \<KK> (the_pw_cat_rKe_limit \<alpha> \<KK> \<TT> \<GG>) :
the_cf_rKe \<alpha> \<TT> \<KK> (the_pw_cat_rKe_limit \<alpha> \<KK> \<TT> \<GG>) \<circ>\<^sub>C\<^sub>F \<KK> \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>r\<^sub>K\<^sub>e\<^bsub>\<alpha>\<^esub> \<TT> :
\<BB> \<mapsto>\<^sub>C \<CC> \<mapsto>\<^sub>C \<AA>"
proof-
interpret \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule assms(2))
show "the_ntcf_rKe \<alpha> \<TT> \<KK> (the_pw_cat_rKe_limit \<alpha> \<KK> \<TT> \<GG>) :
the_cf_rKe \<alpha> \<TT> \<KK> (the_pw_cat_rKe_limit \<alpha> \<KK> \<TT> \<GG>) \<circ>\<^sub>C\<^sub>F \<KK> \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>r\<^sub>K\<^sub>e\<^bsub>\<alpha>\<^esub> \<TT> :
\<BB> \<mapsto>\<^sub>C \<CC> \<mapsto>\<^sub>C \<AA>"
by
(
rule
the_ntcf_rKe_is_cat_rKe
[
OF
assms(1)
ntcf_rKe.NTCod.is_functor_axioms
cat_pw_rKe_the_pw_cat_rKe_limit_is_cat_limit[OF assms]
]
)
qed
lemma (in is_cat_pw_lKe) cat_pw_lKe_the_ntcf_lKe_is_cat_lKe:
assumes "\<KK> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<CC>" and "\<TT> : \<BB> \<mapsto>\<mapsto>\<^sub>C\<^bsub>\<alpha>\<^esub> \<AA>"
shows "the_ntcf_lKe \<alpha> \<TT> \<KK> (the_pw_cat_lKe_colimit \<alpha> \<KK> \<TT> \<FF>) :
\<TT> \<mapsto>\<^sub>C\<^sub>F\<^sub>.\<^sub>l\<^sub>K\<^sub>e\<^bsub>\<alpha>\<^esub> the_cf_lKe \<alpha> \<TT> \<KK> (the_pw_cat_lKe_colimit \<alpha> \<KK> \<TT> \<FF>) \<circ>\<^sub>C\<^sub>F \<KK> :
\<BB> \<mapsto>\<^sub>C \<CC> \<mapsto>\<^sub>C \<AA>"
proof-
interpret \<TT>: is_functor \<alpha> \<BB> \<AA> \<TT> by (rule assms(2))
show ?thesis
by
(
rule the_ntcf_lKe_is_cat_lKe
[
OF
assms(1,2)
cat_pw_lKe_the_pw_cat_lKe_colimit_is_cat_colimit[OF assms],
simplified
]
)
qed
text\<open>\newpage\<close>
end
|
The convex hull of three points $a$, $b$, and $c$ is the set of all points of the form $a + u(b - a) + v(c - a)$ where $u$ and $v$ are nonnegative real numbers that sum to at most $1$.
|
/**
* Connected Vision - https://github.com/ConnectedVision
* MIT License
*/
/******************************************************
** HTTPServerPoco.cpp
**
** written by Michael Rauter and Stephan Veigl
**
*******************************************************/
#include "HTTPServerPoco.h"
#include <IConnectedVisionModule.h>
#include <vector>
#include <boost/algorithm/string.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/lexical_cast.hpp>
#include <Poco/Net/HTMLForm.h>
#include <Poco/StreamCopier.h>
#include <Poco/URI.h>
#include <Poco/Net/NetworkInterface.h>
#include <Poco/Net/NetException.h>
using namespace ConnectedVision;
using namespace ConnectedVision::HTTP;
using namespace Poco;
using namespace Poco::Net;
using namespace Poco::Util;
#define MAXQUEUED 100
class HTTPServerPoco_HTTPRequestHandler : public Poco::Net::HTTPRequestHandler
{
public:
HTTPServerPoco_HTTPRequestHandler(ConnectedVision::HTTP::IHTTPAbstractionCallback *pCallbackObject) : Poco::Net::HTTPRequestHandler()
{
this->pCallbackObject = pCallbackObject;
}
void handleRequest(Poco::Net::HTTPServerRequest& request,
Poco::Net::HTTPServerResponse& response)
{
try
{
ConnectedVision::HTTP::HTTPServerRequest requestConverted;
requestConverted.setHost(request.getHost());
Poco::Net::SocketAddress serverAddress = request.serverAddress();
requestConverted.setServerAddress(serverAddress.toString());
requestConverted.setHttpVersion(request.getVersion());
Poco::Net::HTMLForm htmlForm(request);
const std::string nameTargetURL = "targetURL";
if (htmlForm.has(nameTargetURL)) { // it is intended that the .has() and .get() functions of HTMLForm are used instead of operator[] to decrease Poco Exception messages in debug mode
requestConverted.setTargetURL(htmlForm.get(nameTargetURL));
}
//try
//{
// requestConverted.setTargetURL(htmlForm["targetURL"]);
//}
//catch (Poco::NotFoundException &e)
//{
//}
const std::string nameJsonString = "callback";
if (htmlForm.has(nameJsonString)) {
requestConverted.setJsonString(htmlForm.get(nameJsonString));
}
//try
//{
// requestConverted.setJsonString(htmlForm["callback"]);
//}
//catch (Poco::NotFoundException &e)
//{
//}
const std::string nameSenderID = "senderID";
if (htmlForm.has(nameSenderID)) {
requestConverted.setSenderID(htmlForm.get(nameSenderID));
}
//std::string uri = request.getURI();
std::string uri;
URI::decode(request.getURI(), uri);
std::string queryString = "";
// cut off query string from uri for ModuleDispatcher
size_t pos = uri.find_first_of("?", 0);
if (pos != std::string::npos)
{
queryString = uri.substr(pos+1); // queryString is part of Poco Uri from "?" to end
uri = uri.substr(0, pos); // uri is remaining Poco uri to "?" (excluding "?")
}
requestConverted.setUri(uri);
std::string clientIp = request.clientAddress().toString();
std::string clientPort;
pos = clientIp.find_first_of(":", 0);
if (pos != std::string::npos)
{
clientPort = clientIp.substr(pos+1);
clientIp = clientIp.substr(0, pos);
}
requestConverted.setRemoteIp(clientIp);
requestConverted.setRemotePort(boost::lexical_cast<int>(clientPort));
//LOG_DEBUG("handle new request");
boost::shared_ptr<ConnectedVision::Module::IModule> module;
ConnectedVisionResponse responsePayload;
ConnectedVision::HTTP::EnumConnectedVisionCommandType cmd = CMD_NA;
if (request.getMethod() == Poco::Net::HTTPRequest::HTTP_GET)
{
//LOG_DEBUG("HTTP Command: GET");
cmd = CMD_GET;
std::string cmdString = "GET";
const std::string nameCmd = "cmd";
if (htmlForm.has(nameCmd)) {
cmdString = htmlForm.get(nameCmd);
}
//try
//{
// cmdString = htmlForm["cmd"];
//}
//catch (Poco::NotFoundException &e)
//{
//}
if ( cmdString == "SET" )
{
//LOG_DEBUG("Parameter Command: SET");
cmd = CMD_SET;
const std::string namePayload = "payload";
if (htmlForm.has(namePayload)) {
requestConverted.setPayload(htmlForm.get(namePayload));
}
//try
//{
// requestConverted.payload = htmlForm["payload"];
//}
//catch (Poco::NotFoundException &e)
//{
//}
}
if ( cmdString == "DELETE" )
{
//LOG_DEBUG("Parameter Command: DELETE");
cmd = CMD_DEL;
}
}
if ( request.getMethod() == Poco::Net::HTTPRequest::HTTP_PUT )
{
//LOG_DEBUG("HTTP Command: PUT");
cmd = CMD_SET;
Poco::StreamCopier::copyToString(request.stream(), requestConverted.getRefPayload());
}
if ( request.getMethod() == Poco::Net::HTTPRequest::HTTP_POST )
{
//LOG_DEBUG("HTTP Command: POST");
cmd = CMD_SET;
//boost::posix_time::ptime start = boost::posix_time::microsec_clock::universal_time();
htmlForm.read(request.stream());
const std::string namePayload = "payload";
if (htmlForm.has(namePayload)) {
requestConverted.setPayload(htmlForm.get(namePayload));
}
else {
throw ConnectedVision::runtime_error("payload field not found in http post request (in HTTPRequestHandler (HTTPServerPoco))");
}
//try
//{
// requestConverted.payload = htmlForm["payload"];
//}
//catch (Poco::NotFoundException &e)
//{
// throw ConnectedVision::runtime_error("payload field not found in http post request (in HTTPRequestHandler (HTTPServerPoco))");
//}
//boost::posix_time::ptime end = boost::posix_time::microsec_clock::universal_time();
//int64_t delta = (end - start).total_milliseconds();
//LOG_DEBUG("readQueryString runtime: " + delta);
}
if ( request.getMethod() == Poco::Net::HTTPRequest::HTTP_DELETE )
{
//LOG_DEBUG("HTTP Command: DELETE");
cmd = CMD_DEL;
}
requestConverted.setCommandType(cmd);
ConnectedVision::HTTP::HTTPResponse responseResult;
if (pCallbackObject)
{
pCallbackObject->handleRequest(requestConverted, responseResult);
}
else
{
throw ConnectedVision::runtime_error("pCallbackObject is null (in HTTPRequestHandler (HTTPServerPoco))");
}
response.setChunkedTransferEncoding(true);
response.setContentType(responseResult.content.getContentTypeConst());
response.set("Access-Control-Allow-Origin", "*"); // implement CORS (thanks to Lenis Dimitrios)
response.set("Access-Control-Allow-Headers", "*"); // implement CORS (thanks to Lenis Dimitrios)
response.setStatus((Poco::Net::HTTPResponse::HTTPStatus)responseResult.status);
std::ostream& ostr = response.send();
std::string jsonP = requestConverted.getJsonString();
if ( !jsonP.empty() && responseResult.content.getContentTypeConst() == "application/json" )
{
ostr << jsonP;
ostr << "(";
ostr << responseResult.content.getContentConst();
ostr << ")";
}
else
{
ostr << responseResult.content.getContentConst();
}
}
catch(Poco::Net::NetException& ex)
{
std::string err = ex.displayText();
throw ConnectedVision::runtime_error( err );
}
catch(...)
{
throw ConnectedVision::runtime_error( "error" ); // FIXME
}
}
private:
ConnectedVision::HTTP::IHTTPAbstractionCallback *pCallbackObject;
std::string dataAsString;
};
class HTTPServerPoco_RequestHandlerFactory : public
Poco::Net::HTTPRequestHandlerFactory
{
public:
HTTPServerPoco_RequestHandlerFactory(ConnectedVision::HTTP::IHTTPAbstractionCallback *pCallbackObject)
{
this->pCallbackObject = pCallbackObject;
}
Poco::Net::HTTPRequestHandler* createRequestHandler(
const Poco::Net::HTTPServerRequest& request)
{
return new HTTPServerPoco_HTTPRequestHandler(pCallbackObject);
}
private:
ConnectedVision::HTTP::IHTTPAbstractionCallback *pCallbackObject;
};
HTTPServerPoco::HTTPServerPoco() : pCallbackObject(NULL) {
pServerParams = new Poco::Net::HTTPServerParams;
if (!pServerParams) throw ConnectedVision::runtime_error("allocation of Poco::Net::HTTPServerParams failed in HTTPServerPoco::HTTPServerPoco()");
pServerParams->setMaxQueued(MAXQUEUED);
this->pOriginalPocoErrorHandler = Poco::ErrorHandler::get();
Poco::ErrorHandler::set( &this->customErrorHandler );
};
HTTPServerPoco::~HTTPServerPoco() {
// restore POCO error handler
Poco::ErrorHandler::set(this->pOriginalPocoErrorHandler);
}
Poco::Net::ServerSocket HTTPServerPoco::createServerSocket(int port)
{
Poco::Net::ServerSocket socket(port); // set-up a server socket
return(socket);
}
void HTTPServerPoco::start() {
Poco::Net::ServerSocket socket = this->createServerSocket(port);
pServer.reset(new Poco::Net::HTTPServer(new HTTPServerPoco_RequestHandlerFactory(this->pCallbackObject), socket, pServerParams));
Poco::Net::NetworkInterface::List networkInterfaces = Poco::Net::NetworkInterface::list(true, true);
Poco::Net::IPAddress ipAddress;
Poco::Net::NetworkInterface::List::const_iterator it;
for (it = networkInterfaces.begin(); it != networkInterfaces.end(); it++)
{
if ((!it->isLoopback())&&(it->supportsIPv4()))
{
ipAddress = it->address();
std::string protocol = this->getProtocol();
this->serverURIs.push_back(protocol + "://" + ipAddress.toString() + ":" + boost::lexical_cast<std::string>(port) + "/");
}
}
if (serverURIs.size() == 0)
{
throw ConnectedVision::runtime_error("no network interface found (install at least a loopback adapter)");
}
pServer->start();
};
void HTTPServerPoco::stop() {
pCallbackObject = NULL;
if (pServer)
{
pServer->stop();
pServer->stopAll(true);
int currentConnections = pServer->currentConnections();
int currentThreads = pServer->currentThreads();
int totalConnections = pServer->totalConnections();
pServer.reset();
}
};
void HTTPServerPoco::setImplementationCallbackInterface(ConnectedVision::HTTP::IHTTPAbstractionCallback *pCallbackObject) {
this->pCallbackObject = pCallbackObject;
};
void HTTPServerPoco::setOption_listeningPort(const int port)
{
this->port = port;
}
void HTTPServerPoco::setOption_numThreads(const int numThreads)
{
pServerParams->setMaxThreads(numThreads);
}
void HTTPServerPoco::setOption_maxQueued(const int maxQueued)
{
pServerParams->setMaxQueued(maxQueued);
}
void HTTPServerPoco::CustomErrorHandler::exception(const Poco::Exception& exc)
{
std::string className( exc.className() );
if ( className.find("ConnectionResetException") != std::string::npos )
{
// ignore ConnectionResetException
return;
}
if ( className.find("ConnectionAbortedException") != std::string::npos )
{
// ignore ConnectionAbortedException
return;
}
// use default handling for other exceptions
Poco::ErrorHandler::exception(exc);
}
|
# Realization of Non-Recursive Filters
*This jupyter notebook is part of a [collection of notebooks](../index.ipynb) on various topics of Digital Signal Processing. Please direct questions and suggestions to [[email protected]](mailto:[email protected]).*
## Fast Convolution
The straightforward convolution of two finite-length signals $x[k]$ and $h[k]$ is a numerically complex task. This has led to the development of various techniques with considerably lower complexity. The basic concept of the *fast convolution* is to exploit the correspondence between the convolution and the scalar multiplication in the frequency domain.
### Convolution of Finite-Length Signals
The convolution of a causal signal $x_L[k]$ of length $L$ with a causal impulse response $h_N[k]$ of length $N$ is given as
\begin{equation}
y[k] = x_L[k] * h_N[k] = \sum_{\kappa = 0}^{L-1} x_L[\kappa] \; h_N[k - \kappa] = \sum_{\kappa = 0}^{N-1} h_N[\kappa] \; x_L[k - \kappa]
\end{equation}
where $x_L[k] = 0$ for $k<0 \wedge k \geq L$ and $h_N[k] = 0$ for $k<0 \wedge k \geq N$. The resulting signal $y[k]$ is of finite length $M = N+L-1$. The computation of $y[k]$ for $k=0,1, \dots, M-1$ requires $M \cdot N$ multiplications and $M \cdot (N-1)$ additions. The computational complexity of the convolution is consequently [in the order of](https://en.wikipedia.org/wiki/Big_O_notation) $\mathcal{O}(M \cdot N)$. Discrete-time Fourier transformation (DTFT) of above relation yields
\begin{equation}
Y(e^{j \Omega}) = X_L(e^{j \Omega}) \cdot H_N(e^{j \Omega})
\end{equation}
Discarding the effort of transformation, the computationally complex convolution is replaced by a scalar multiplication with respect to the frequency $\Omega$. However, $\Omega$ is a continuous frequency variable which limits the numerical evaluation of this scalar multiplication. In practice, the DTFT is replaced by the discrete Fourier transformation (DFT). Two aspects have to be considered before a straightforward application of the DFT
1. The DFTs $X_L[\mu]$ and $H_N[\mu]$ are of length $L$ and $N$ respectively and cannot be multiplied straightforwardly
2. For $N = L$, the multiplication of the two spectra $X_L[\mu]$ and $H_L[\mu]$ would result in the [periodic/circular convolution](https://en.wikipedia.org/wiki/Circular_convolution) $x_L[k] \circledast h_L[k]$ due to the periodicity of the DFT. Since we aim at realizing the linear convolution $x_L[k] * h_N[k]$ with the DFT, special care has to be taken to avoid cyclic effects.
### Linear Convolution by Periodic Convolution
The periodic convolution of the two signals $x_L[k]$ and $h_N[k]$ is defined as
\begin{equation}
x_L[k] \circledast h_N[k] = \sum_{\kappa=0}^{M-1} \tilde{x}_M[k - \kappa] \; \tilde{h}_M[\kappa]
\end{equation}
where the periodic continuations $\tilde{x}_M[k]$ of $x_L[k]$ and $\tilde{h}_M[k]$ of $h_N[k]$ with period $M$ are given as
\begin{align}
\tilde{x}_M[k] &= \sum_{m = -\infty}^{\infty} x_L[m \cdot M + k] \\
\tilde{h}_M[k] &= \sum_{m = -\infty}^{\infty} h_N[m \cdot M + k]
\end{align}
The result of the circular convolution has a periodicity of $M$.
To compute the linear convolution by the periodic convolution one has to take care that the result of the linear convolution fits into one period of the periodic convolution. Hence, the periodicity has to be chosen as $M \geq N+L-1$. This can be achieved by zero-padding of $x_L[k]$ and $h_N[k]$ to a total length of $M$
\begin{align}
x_M[k] &= \begin{cases}
x_L[k] & \mathrm{for} \; k=0, 1, \dots, L-1 \\
0 & \mathrm{for} \; k=L, L+1, \dots, M-1
\end{cases}
\\
h_M[k] &= \begin{cases}
h_N[k] & \mathrm{for} \; k=0, 1, \dots, N-1 \\
0 & \mathrm{for} \; k=N, N+1, \dots, M-1
\end{cases}
\end{align}
This results in the desired equality of linear and periodic convolution
\begin{equation}
x_L[k] * h_N[k] = x_M[k] \circledast h_M[k]
\end{equation}
for $k = 0,1,\dots, M-1$ with $M = N+L-1$.
#### Example - Linear by periodic convolution
The following example computes the linear, periodic and linear by periodic convolution of a rectangular signal $x[k] = \text{rect}_L[k]$ of length $L$ with a triangular signal $h[k] = \Lambda_N[k]$ of length $N$.
```python
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import scipy.signal as sig
L = 32 # length of signal x[k]
N = 16 # length of signal h[k]
M = 16 # periodicity of periodic convolution
def periodic_summation(x, N):
"Zero-padding to length N or periodic summation with period N."
M = len(x)
rows = int(np.ceil(M/N))
if (M < int(N*rows)):
x = np.pad(x, (0, int(N*rows-M)), 'constant')
x = np.reshape(x, (rows, N))
return np.sum(x, axis=0)
def periodic_convolve(x, y, P):
"Periodic convolution of two signals x and y with period P."
x = periodic_summation(x, P)
h = periodic_summation(y, P)
return np.array([np.dot(np.roll(x[::-1], k+1), h) for k in range(P)], float)
# generate signals
x = np.ones(L)
h = sig.triang(N)
# linear convolution
y1 = np.convolve(x, h, 'full')
# periodic convolution
y2 = periodic_convolve(x, h, M)
# linear convolution via periodic convolution
xp = np.append(x, np.zeros(N-1))
hp = np.append(h, np.zeros(L-1))
y3 = periodic_convolve(xp, hp, L+N-1)
# plot results
def plot_signal(x):
plt.figure(figsize = (10, 3))
plt.stem(x)
plt.xlabel(r'$k$')
plt.ylabel(r'$y[k]$')
plt.axis([0, N+L, 0, 1.1*x.max()])
plot_signal(x)
plt.title('Signal $x[k]$')
plot_signal(y1)
plt.title('Linear convolution')
plot_signal(y2)
plt.title('Periodic convolution with period M = %d' %M)
plot_signal(y3)
plt.title('Linear convolution by periodic convolution');
```
**Exercise**
* Change the lengths `L`, `N` and `M` and check how the results for the different convolutions change
### The Fast Convolution
Using the above derived equality of the linear and periodic convolution one can express the linear convolution $y[k] = x_L[k] * h_N[k]$ by the DFT as
\begin{equation}
y[k] = \text{IDFT}_M \{ \; \text{DFT}_M\{ x_M[k] \} \cdot \text{DFT}_M\{ h_M[k] \} \; \}
\end{equation}
This operation requires three DFTs of length $M$ and $M$ complex multiplications. On first sight this does not seem to be an improvement, since one DFT/IDFT requires $M^2$ complex multiplications and $M \cdot (M-1)$ complex additions. The overall numerical complexity is hence in the order of $\mathcal{O}(M^2)$. The DFT can be realized efficiently by the [fast Fourier transformation](https://en.wikipedia.org/wiki/Fast_Fourier_transform) (FFT), which lowers the computational complexity to $\mathcal{O}(M \log_2 M)$. The resulting algorithm is known as *fast convolution* due to its computational efficiency.
The fast convolution algorithm is composed of the following steps
1. Zero-padding of the two input signals $x_L[k]$ and $h_N[k]$ to at least a total length of $M \geq N+L-1$
2. Computation of the DFTs $X[\mu]$ and $H[\mu]$ using a FFT of length $M$
3. Multiplication of the spectra $Y[\mu] = X[\mu] \cdot H[\mu]$
4. Inverse DFT of $Y[\mu]$ using an inverse FFT of length $M$
The overall complexity depends on the particular implementation of the FFT. Many FFTs are most efficient for lengths which are a power of two. It therefore can make sense, in terms of computational complexity, to choose $M$ as a power of two instead of the shortest possible length $N+L-1$. For real valued signals $x[k] \in \mathbb{R}$ and $h[k] \in \mathbb{R}$ the computational complexity can be reduced significantly by using a real valued FFT.
#### Example - Fast convolution
The implementation of the fast convolution algorithm is straightforward. Most implementations of the FFT include zero-padding to a given length $M$, e.g in `numpy` by `numpy.fft.fft(x, M)`. In the following example an implementation of the fast convolution is shown. For illustration the convolution of a rectangular signal $x[k] = \text{rect}_L[k]$ of length $L$ with a triangular signal $h[k] = \Lambda_N[k]$ of length $N$ is considered.
```python
L = 16 # length of signal x[k]
N = 16 # length of signal h[k]
M = N+L-1
# generate signals
x = np.ones(L)
h = sig.triang(N)
# linear convolution
y1 = np.convolve(x, h, 'full')
# fast convolution
y2 = np.fft.ifft(np.fft.fft(x, M) * np.fft.fft(h, M))
plt.figure(figsize=(10, 6))
plt.subplot(211)
plt.stem(y1)
plt.xlabel(r'$k$')
plt.ylabel(r'$y[k] = x_L[k] * h_N[k]$')
plt.title('Result of linear convolution')
plt.subplot(212)
plt.stem(y1)
plt.xlabel(r'$k$')
plt.ylabel(r'$y[k] = x_L[k] * h_N[k]$')
plt.title('Result of fast convolution')
plt.tight_layout()
```
#### Example - Numerical complexity
It was already argued that the numerical complexity of the fast convolution is considerably lower due to the usage of the FFT. The gain with respect to the convolution is evaluated in the following. In order to measure the execution times for both algorithms the `timeit` module is used. The algorithms are evaluated for the convolution of two random signals $x_L[k]$ and $h_N[k]$ of length $L=N=2^n$ for $n=0, 1, \dots, 16$.
```python
import timeit
n = np.arange(17) # lengths = 2**n to evaluate
reps = 50 # number of repetitions for timeit
gain = np.zeros(len(n))
for N in n:
length = 2**N
# setup environment for timeit
tsetup = 'import numpy as np; from numpy.fft import rfft, irfft; \
x=np.random.randn(%d); h=np.random.randn(%d)' % (length, length)
# direct convolution
tc = timeit.timeit('np.convolve(x, x, mode="full")', setup=tsetup, number=reps)
# fast convolution
tf = timeit.timeit('irfft(rfft(x, %d) * rfft(h, %d))' % (2*length, 2*length), setup=tsetup, number=reps)
# speedup by using the fast convolution
gain[N] = tc/tf
# show the results
plt.figure(figsize = (15, 10))
plt.barh(n, gain, log=True)
plt.plot([1, 1], [-1, n[-1]+1], 'r-')
plt.yticks(n, 2**n)
plt.xlabel('Gain of fast convolution')
plt.ylabel('Length of signals')
plt.title('Comparison between direct/fast convolution')
plt.grid()
```
**Exercise**
* When is the fast convolution more efficient/faster than a direct convolution?
* Why is it slower below a given signal length?
* Is the trend of the gain as expected by the numerical complexity of the FFT?
Solution: The gain in execution time of a fast convolution over a direct implementation of the the convolution for different signal lengths depends heavily on the particular implementation and hardware used. The fast convolution in this example is faster for two signals having a length equal or larger than 1024 samples. Discarding the outliers and short lengths, the overall trend in the gain is approximately logarithmic as predicted above.
**Copyright**
This notebook is provided as [Open Educational Resource](https://en.wikipedia.org/wiki/Open_educational_resources). Feel free to use the notebook for your own purposes. The text is licensed under [Creative Commons Attribution 4.0](https://creativecommons.org/licenses/by/4.0/), the code of the IPython examples under the [MIT license](https://opensource.org/licenses/MIT). Please attribute the work as follows: *Sascha Spors, Digital Signal Processing - Lecture notes featuring computational examples, 2016-2018*.
|
(* --------------------------------------------------------------------
* Copyright (c) - 2006--2012 - IMDEA Software Institute
* Copyright (c) - 2006--2012 - Inria
* Copyright (c) - 2006--2012 - Microsoft Coprporation
*
* Distributed under the terms of the CeCILL-B-V1 license
* -------------------------------------------------------------------- *)
Require Import SMain.
Require Import Field_tac.
Require Import Program.
Require Import EGroup.
Require Import FGroup.
Require Import UList.
Require Import Arith.
Require Import Znumtheory.
Require Import ZAux.
Require Import FilterMap.
Require Import Znumtheory.
Require Import SMain.
Require Import Ring.
Require Import PrimeLib.
Require Import Padding.
Require Import EC.
Require Import EncodingAux.
Require Import RO.
Set Implicit Arguments.
Module Type SOLVE_DEGREE_4 (A : FIELD).
Parameter solve_degree_4 : forall k (a b c d e : A.t k), list (A.t k).
Notation "x + y" := (A.kplus x y).
Notation "x * y" := (A.kmul x y).
Parameter solve_degree_4_correct : forall k (a b c d e sol : A.t k),
In sol (solve_degree_4 a b c d e) <->
(fun x => a * x*x*x*x + b * x*x*x + c * x*x + d * x + e) sol = A.kO k.
Parameter solve_degree_4_size : forall k (a b c d e : A.t k),
(length (solve_degree_4 a b c d e) <= 4)%nat.
Parameter solve_degree_4_NoDup : forall k (a b c d e : A.t k),
NoDup (solve_degree_4 a b c d e).
End SOLVE_DEGREE_4.
Declare Module F : FIELD
with Definition order_mod1 := fun (_:nat) => 3%Z
with Definition order_mod2 := fun (_:nat) => 2%Z.
Declare Module CP : CURVE_PROPERTIES F.
Declare Module S4 : SOLVE_DEGREE_4 F.
Module EC_GROUP <: CFG := (EC.EC F CP).
Module PAD := Padding.Padding EC_GROUP.
Module IcartEncoding <: ENCODING F PAD.B.
Import F CP S4.
Section ENC.
Variable k : nat.
Add Field Kfield : (@K_field k) (abstract).
Notation "x + y" := (kplus x y).
Notation "x * y" := (kmul x y).
Notation "x - y" := (ksub x y).
Notation "- x" := (kopp x).
Notation "/ x" := (kinv x).
Notation "x / y" := (kdiv x y).
Notation "0" := (kO k).
Notation "1" := (kI k).
Notation "2" := (1+1).
Notation "3" := (1+1+1).
Notation "4" := (2*2).
Notation "5" := (4+1).
Notation "6" := (2*3).
Notation "8" := (2*2*2).
Notation "16" := (2*2*2*2).
Notation "20" := (4*5).
Notation "27" := (3*3*3).
Notation "256" := (2*2*2*2*2*2*2*2).
Notation "x ^ n" := (kpow x n).
Lemma kpow_S : forall (x:t k) n, x ^ (S n) = x * (x ^ n).
Proof.
intros; simpl; trivial.
Qed.
Lemma kpow_kplus : forall (x:t k) n m, ((x ^ n) * (x ^ m) = x ^ (n + m)).
Proof.
intros x n m.
induction m; simpl.
rewrite plus_0_r; field.
rewrite <- plus_n_Sm, kpow_S, <- IHm; field.
Qed.
Lemma kpow_pow : forall x n1 n2, kpow (@kpow k x n1) n2 = kpow x (n1 * n2).
Proof.
intros x n1 n2.
induction n2.
rewrite mult_0_r; simpl; trivial.
rewrite mult_succ_r, <- kpow_kplus; simpl.
rewrite IHn2; field.
Qed.
Lemma kpow_kplus_n : forall (x y:t k) n, (x ^ n) * (y ^ n) = (x * y) ^ n.
Proof.
intros x y n.
induction n; simpl.
ring.
rewrite <- IHn; ring.
Qed.
Definition sqr (x : t k) : t k := x * x.
Definition cube (x : t k) : t k := x * x * x.
Definition pow4 (x : t k) : t k := x * x * x * x.
Lemma cube_pow (x : t k) : cube x = kpow x 3%nat.
Proof.
intros; unfold cube; simpl; ring.
Qed.
Lemma cube_plus a b :
cube (a + b) = (cube a) + 3 * a*a * b + 3 * b*b * a + (cube b).
Proof.
intros a b; unfold cube; ring.
Qed.
Lemma cube_minus a b :
cube (a - b) = (cube a) - 3 * a*a * b + 3 * b*b * a - (cube b).
Proof.
intros a b; unfold cube; ring.
Qed.
Definition cube_root (x : t k) : t k :=
kpow x (Zabs_nat ((2 * (orderZ k) - 1) / 3)).
Lemma order_pos : (0 < orderZ k)%Z.
Proof.
change 0%Z with (Z_of_nat 0).
apply inj_lt.
generalize (@elems_notnil k).
destruct (elems k); intros; simpl.
elim H; trivial.
omega.
Qed.
Lemma cube_root_spec : forall x, cube_root (cube x) = x.
Proof.
intros x; unfold cube_root.
assert (Ho := order_pos).
rewrite cube_pow, kpow_pow.
change 3%nat with (Zabs_nat 3).
rewrite <- Zabs_nat_mult, <- Zdivide_Zdiv_eq;[ | omega | ].
cutrewrite (2 * orderZ k - 1 = 1 + (orderZ k - 1) + (orderZ k - 1))%Z;[ | ring].
repeat rewrite Zabs_nat_Zplus; try omega.
repeat rewrite <- kpow_kplus; simpl.
cutrewrite (Zabs_nat (orderZ k - 1) = (order k - 1)%nat ).
repeat rewrite fermat; ring.
rewrite Zabs_nat_Zminus.
unfold orderZ; rewrite Zabs_nat_Z_of_nat; auto.
omega.
apply Zmod_divide; [ omega | ].
rewrite <- Zminus_mod_idemp_l, Zmult_comm, <- Zmult_mod_idemp_l, order_mod.
vm_compute; trivial.
Qed.
Lemma cube_spec : forall x, cube (cube_root x) = x.
Proof.
intros x; unfold cube_root.
rewrite cube_pow, kpow_pow, mult_comm, <- kpow_pow, <- cube_pow.
apply cube_root_spec.
Qed.
Lemma cube_root_mul x y : cube_root x * cube_root y = cube_root (x * y).
Proof.
intros x y; unfold cube_root.
rewrite kpow_kplus_n; trivial.
Qed.
Lemma diff_opp_0 x : x <> 0 -> -x <> 0.
Proof.
intros x H1 Heq.
apply H1.
apply (f_equal (fun x => kopp x)) in Heq.
cutrewrite (- - x = x) in Heq; [ | ring ].
ring [Heq].
Qed.
Lemma mult_inj x y z : z <> 0 -> x * z = y * z -> x = y.
Proof.
intros x y z Hz H.
apply (f_equal (fun x => x / z)) in H.
cutrewrite (x = x * z / z).
rewrite H.
field; trivial.
field; trivial.
Qed.
Lemma diff_1_0 : 1 <> 0.
Proof.
generalize (K_field k); intros.
inversion H; trivial.
Qed.
Lemma diff_1_2_0 : 1 + 2 <> 0.
Proof.
cutrewrite (1 + 2 = 3).
apply diff_3_0.
ring.
Qed.
Lemma diff_3_0' : 1 + 1 + 1 <> 0.
Proof.
apply diff_3_0.
Qed.
Lemma diff_4_0 : 4 <> 0.
Proof.
apply diff_mul_0; apply diff_2_0.
Qed.
Lemma diff_6_0 : 2 * (1 + 2) <> 0.
Proof.
apply diff_mul_0.
apply diff_2_0.
apply diff_1_2_0.
Qed.
Lemma diff_8_0 : 8 <> 0.
Proof.
apply diff_mul_0.
apply diff_4_0.
apply diff_2_0.
Qed.
Lemma diff_27_0 : 1 + 2 * (1 + 2 * (2 * (1 + 2))) <> 0.
Proof.
cutrewrite (1 + 2 * (1 + 2 * (2 * (1 + 2))) = 3 * 3 * 3).
apply diff_mul_0.
apply diff_mul_0.
apply diff_3_0.
apply diff_3_0.
apply diff_3_0.
ring.
Qed.
Hint Resolve diff_1_2_0 diff_1_0 diff_2_0 diff_3_0 diff_3_0'
diff_4_0 diff_6_0 diff_27_0 diff_8_0 diff_opp_0.
Lemma is_zero_eq_false : forall x, is_zero x = false <-> x <> 0.
Proof.
generalize (EC_GROUP.ECB.Eth k); intros.
inversion H; trivial.
split; intro He.
intro Heq.
apply is_zero_correct in Heq.
rewrite He in Heq; discriminate.
apply not_true_is_false.
intro Heq.
apply is_zero_correct in Heq.
subst.
elim He; trivial.
Qed.
Lemma mult_sqr (x y : t k) : x = y \/ x = -y -> x * x = y * y.
Proof.
intros x y [H | H]; subst; ring.
Qed.
Lemma eqb_dec : forall (x y : F.t k), {x = y} + {x <> y}.
Proof.
intros.
generalize (eqb_spec x y).
case (eqb x y); auto.
Qed.
Definition f_def : F.t k -> PAD.B.t k.
intro u.
destruct (eqb_dec u 0).
destruct (eqb_dec (A k) 0).
pose (x := cube_root (- B k )).
(* if A = 0 then f(0) = ( (-b)^(1/3), 0). cf (mail with Thomas Icart) *)
refine (curve_elt (kI k) (@kplus k) (@kmul k) (A k) (B k) x 0 _).
symmetry; unfold SMain.pow.
rewrite e0.
ring_simplify.
cutrewrite (x * x * x = cube x); auto.
unfold x.
rewrite cube_spec.
ring.
(* A <> 0 (Icart's paper) *)
exact (PAD.B.default k).
pose (v := kdiv ((3 * A k) - (u*u*u*u)) (6 * u)).
pose (x := cube_root ((v * v) - B k - ((u ^ 6) / 27)) + ( (u^2) / 3)).
pose (y := (u * x) + v).
refine (curve_elt (kI k) (@kplus k) (@kmul k) (A k) (B k) x y _).
symmetry; unfold SMain.pow.
ring_simplify.
assert (x = cube_root (v * v - B k - u ^ 6 / 27) + u ^ 2 / 3) by trivial.
apply (f_equal cube) in H.
assert (cube (x - ((u*u) / 3)) = (v*v) - B k - (u^6)/27).
rewrite cube_minus, H, cube_plus, cube_spec; clear H; unfold x.
generalize (v * v - B k - u ^ 6 / 27); intro.
rewrite <- (cube_spec t0) at 1 8; unfold cube.
cutrewrite (u ^ 2 = u * u); [ | unfold kpow]; ring.
assert (cube x = u * u * x * x - ((u * u * u * u) / 3) * x + (- B k + v * v)).
cutrewrite <- (cube (x - u * u / 3) + u ^ 6 / 27 = - B k + v * v);
[ | ring [H0] ].
rewrite cube_minus; set (n1 := 1); unfold kpow, cube; field; auto.
cutrewrite (u * u * u * u / 3 = A k - 2 * u * v) in H1.
unfold y; unfold cube in H1; ring [H1].
unfold v; set (n1 := 1); field.
split;[ | split ]; auto.
apply diff_2_0.
Defined.
Lemma Feqb : forall a b : t k, {a = b} + {a <> b}.
Proof.
intros.
generalize (eqb_spec a b).
case (eqb a b); intros; auto.
Qed.
Lemma Geqb : forall a b : PAD.B.t k, {a = b} + {a <> b}.
Proof.
intros.
generalize (PAD.B.eqb_spec _ a b).
case (PAD.B.eqb _ a b); intros; auto.
Qed.
Definition Im_f := nodup Geqb (map f_def (elems k)).
Lemma NoDup_Im_f : NoDup Im_f.
Proof.
apply Nodup_nodup.
Qed.
Definition finv_def : (PAD.B.t k) -> list (F.t k).
intros p.
destruct p.
destruct (eqb_dec (A k) 0).
exact nil.
exact [0].
destruct (eqb_dec (A k) 0).
refine (solve_degree_4 0 1 0 (- x * 6) (6 * y)). (* cf. Icart's suggestion *)
refine (solve_degree_4 1 0 (- x * 6) (6 * y) (- A k * 3)).
Defined.
Definition finv_len : nat := 4%nat.
Parameter cost_f : F.t k -> nat.
Parameter cost_f_poly : polynomial.
Parameter cost_f_poly_spec : forall (x:F.t k),
(cost_f x <= peval cost_f_poly k)%nat.
Parameter cost_finv : PAD.B.t k -> nat.
Parameter cost_finv_poly : polynomial.
Parameter cost_finv_poly_spec : forall (x:PAD.B.t k),
(cost_finv x <= peval cost_finv_poly k)%nat.
Definition finv_len_poly := pcst 4.
Lemma finv_len_poly_spec : finv_len <= finv_len_poly k.
Proof.
unfold finv_len, finv_len_poly.
rewrite pcst_spec; auto.
Qed.
Ltac elim_if :=
match goal with
|- context [if ?a then ?b else ?c] => case_eq a; intros
end.
Lemma finv_len_spec : forall x, length (finv_def x) <= finv_len.
Proof.
unfold finv_def, finv_len; intros.
destruct x; repeat elim_if; simpl; auto;
apply solve_degree_4_size.
Qed.
Lemma finv_len_not_0 : 0 < finv_len.
Proof.
unfold finv_len; auto.
Qed.
End ENC.
End IcartEncoding.
Require Import ssreflect.
Module Icart_PI <: POLYNOMIALLY_INVERTIBLE_ENCODING F PAD.B IcartEncoding.
Import IcartEncoding CP F.
Section PI.
Variable k : nat.
Add Field Kfield : (@K_field k) (abstract).
Notation "x + y" := (kplus x y).
Notation "x * y" := (kmul x y).
Notation "x - y" := (ksub x y).
Notation "- x" := (kopp x).
Notation "/ x" := (kinv x).
Notation "x / y" := (kdiv x y).
Notation "0" := (kO k).
Notation "1" := (kI k).
Notation "2" := (1+1).
Notation "3" := (1+1+1).
Notation "4" := (2*2).
Notation "5" := (4+1).
Notation "6" := (2*3).
Notation "8" := (2*2*2).
Notation "16" := (2*2*2*2).
Notation "20" := (4*5).
Notation "27" := (3*3*3).
Notation "256" := (2*2*2*2*2*2*2*2).
Notation "x ^ n" := (kpow x n).
Lemma finv_NoDup : forall (x:PAD.B.t k), NoDup (finv_def x).
Proof.
intros; unfold finv_def.
destruct x.
destruct (eqb_dec (CP.A k) (F.kO k)); auto.
destruct (eqb_dec (CP.A k) (F.kO k));
apply S4.solve_degree_4_NoDup.
Qed.
Hint Resolve diff_1_2_0 diff_1_0 diff_2_0 diff_3_0 diff_3_0'
diff_4_0 diff_6_0 diff_27_0 diff_8_0 diff_opp_0.
Lemma finv_spec1 : forall (g : PAD.B.t k) (u : F.t k),
In u (finv_def g) -> f_def u = g.
Proof.
intros g u; unfold finv_def, f_def.
(* case_eq ( p_in g Im_f ); intros Hpin. *)
destruct g; simpl; intros.
(** inf *)
destruct (eqb_dec (A k) 0); simpl in *.
elim H.
destruct H.
subst.
destruct (eqb_dec 0 0); intros.
auto.
elim n0; trivial.
elim H.
(** (x,y) *)
unfold SMain.pow in e.
destruct (eqb_dec (A k) 0).
(*** A = 0 *)
apply S4.solve_degree_4_correct in H.
destruct (eqb_dec u 0); intros.
(**** u = 0 *)
rewrite e1 in H.
ring_simplify in H.
assert (y = 0).
rewrite e0 in e.
cutrewrite (2 * (1 + 2) * y = y * (2 * (1 + 2))) in H;[ | ring ].
cutrewrite (0 = 0 * (2 * (1 + 2))) in H.
apply mult_inj in H; auto.
ring.
apply (curve_elt_irr (EC_GROUP.ECB.Eth k)).
rewrite H0 e0 in e.
cutrewrite (- B k = x * x * x).
apply cube_root_spec.
cutrewrite (x * x * x = - (0 * 0) + x * x * x);[ | ring].
rewrite e; ring.
auto.
(**** u <> 0 *)
ring_simplify in H.
assert (u * u * u - x * 6 * u + 6 * y = 0).
rewrite <- H; ring.
clear H.
assert (u * u * u / 6 = x * u - y).
cutrewrite (u * u * u = u * u * u - 0);[ | ring ].
rewrite <- H0; field; auto.
assert (B k = y * y - x * x * x).
rewrite e e0; ring.
pose (v := - (u * u * u / 6)).
assert (y = u * x + v).
unfold v.
rewrite H.
ring.
assert (v * v - B k - u ^ 6 / 27 = cube (x - u * u / 3)).
cutrewrite <- (u * u * x * x + 2 * u * v * x + v * v = y * y) in e.
rewrite e0 in e.
ring_simplify in e.
assert ((x * x * x + B k) - u * u * x * x - 2 * u * v * x - v * v = 0).
rewrite <- e; ring.
clear e.
assert (x * x * x - u * u * x * x + (- (2 * u * v)) * x + B k - v * v = 0).
rewrite <- H3; ring.
clear H3.
rewrite cube_minus.
assert ( v * v - B k = cube x - 3 * x * x * (u * u / 3) + 3 * (u * u / 3) * (u * u / 3) * x ).
cutrewrite (v * v = v * v + 0);[ | ring ].
rewrite <- H4.
unfold v.
ring_simplify.
unfold cube; field; auto.
rewrite H3.
unfold cube.
simpl; field; auto.
rewrite H2; ring.
simpl in H3.
assert ( cube_root
((3 * 0 - u * u * u * u) / (6 * u) * ((3 * 0 - u * u * u * u) / (6 * u)) -
B k - u * (u * (u * (u * (u * (u * 1))))) / 27) = x - u * (u * 1) / 3).
apply (f_equal (@cube_root k)) in H3.
rewrite cube_root_spec in H3.
cutrewrite ( x - u * (u * 1) / 3 = x - u * u / 3 );[ | field; auto ].
rewrite <- H3.
f_equal.
unfold v; field; auto.
apply (curve_elt_irr (EC_GROUP.ECB.Eth k)).
rewrite e0 H4.
field; auto.
rewrite e0 H4 H2.
unfold v.
field; auto.
(*** A <> 0 *)
apply S4.solve_degree_4_correct in H.
destruct (eqb_dec u 0); intros.
(**** u = 0 *)
rewrite e0 in H.
ring_simplify in H.
cutrewrite (0 = 0 * (A k)) in H.
apply mult_inj in H; trivial.
assert (- (1 + 2) <> 0).
apply diff_opp_0; auto.
elim H0; trivial.
ring.
(**** u <> 0 *)
ring_simplify in H.
assert (u * u * u * u - x * 6 * u * u + 6 * y * u - A k * 3 = 0).
rewrite <- H; ring.
clear H.
pose (v := kdiv ((3 * A k ) - (u * u * u * u)) (6 * u)).
assert (y = u * x + v).
unfold v.
assert (3 * A k = u * u * u * u - x * 6 * u * u + 6 * y * u).
cutrewrite (3 * A k = 3 * A k + 0);[ | ring ].
rewrite <- H0; field.
rewrite H; field.
split; auto.
assert (v * v - B k - u ^ 6 / 27 = cube (x - u * u / 3)).
generalize e; intro He.
cutrewrite <- (u * u * x * x + 2 * u * v * x + v * v = y * y) in He.
assert ((x*(x*x) + A k * x + B k) - u * u * x * x - 2 * u * v * x - v * v = 0).
rewrite <- He; ring.
clear He.
assert (x * x * x - u * u * x * x + (A k - 2 * u * v) * x + B k - v * v = 0).
rewrite <- H1; ring.
clear H1.
cutrewrite (A k - 2 * u * v = u * u * u * u / 3) in H2.
cutrewrite (v * v = v * v + 0);[ | ring ].
rewrite <- H2.
unfold cube; simpl; field; auto.
unfold v; field; auto.
rewrite H; field.
simpl in H1.
apply (curve_elt_irr (EC_GROUP.ECB.Eth k)).
fold v.
rewrite H1 cube_root_spec.
simpl; field; auto.
fold v.
rewrite H1 cube_root_spec.
rewrite H.
simpl; field; auto.
Qed.
Lemma finv_spec2 : forall (g : PAD.B.t k) (u : F.t k),
f_def u = g -> In u (finv_def g).
Proof.
intros g u; unfold finv_def, f_def; intros.
destruct (eqb_dec u 0); destruct (eqb_dec (A k) 0);
destruct g; try discriminate.
apply S4.solve_degree_4_correct.
injection H; intros; subst; ring.
subst; simpl; auto.
apply S4.solve_degree_4_correct.
injection H; intros; subst; clear H.
rewrite e; field; auto.
injection H; intros; subst; clear H.
apply S4.solve_degree_4_correct.
field; auto.
Qed.
Lemma finv_spec : forall (g : PAD.B.t k) (u : F.t k),
In u (finv_def g) <-> f_def u = g.
Proof.
intros; split.
apply finv_spec1.
apply finv_spec2.
Qed.
Lemma finv_len_group : (length (F.elems k) <= length (PAD.B.elems k) * finv_len).
Proof.
apply le_trans with
(length (nodup (@Geqb k) (map (@f_def k) (elems k))) * finv_len)%nat.
apply length_surj_mult with (finv := @finv_def k).
intros; apply finv_spec.
intros; apply finv_len_spec.
apply elems_NoDup.
apply mult_le_compat_r.
apply le_trans with (length (PAD.B.elems k)).
apply length_surj.
apply Nodup_nodup.
red; intros.
apply PAD.B.elems_full.
auto.
Qed.
End PI.
End Icart_PI.
|
module System.Info
%default total
%extern prim__os : String
%extern prim__codegen : String
export
os : String
os = prim__os
export
codegen : String
codegen = prim__codegen
export
isWindows : Bool
isWindows = os `elem` ["windows", "mingw32", "cygwin32"]
%foreign "C:idris2_getNProcessors, libidris2_support, idris_support.h"
"jvm:getAvailableProcessors(int),io/github/mmhelloworld/idrisjvm/runtime/Runtime"
prim__getNProcessors : PrimIO Int
export
getNProcessors : IO (Maybe Nat)
getNProcessors = do
i <- fromPrim prim__getNProcessors
pure (if i < 0 then Nothing else Just (integerToNat (cast i)))
|
     
     
     
     
   
[Home Page](../../Start_Here.ipynb)
[Previous Notebook](../introduction/Introductory_Notebook.ipynb)
     
     
     
     
   
[1](../introduction/Introductory_Notebook.ipynb)
[2]
[3](../spring_mass/Spring_Mass_Problem_Notebook.ipynb)
[4](../chip_2d/Challenge_CFD_Problem_Notebook.ipynb)
     
     
     
     
[Next Notebook](../spring_mass/Spring_Mass_Problem_Notebook.ipynb)
# Steady State 1D Diffusion in a Composite Bar using PINNs
This notebook give you a headstart in solving your own Partial Differential Equations (PDEs) using neural networks. Let's quickly recap the theory of PINNs before proceeding. We will embed the physics of the problem in the the neural networks and in such setting, we can use them to approximate the solution to a given differential equation and boundary condition without any training data from other solvers. More specifically, the neural network will be trained to minimize a loss function which is formed using the differential equation and the boundary conditions. If the network is able to minimize this loss then it will in effect solve the given differential equation. More information about the Physics Informed Neural Networks (PINNs) can be found in the [paper](https://www.sciencedirect.com/science/article/pii/S0021999118307125?casa_token=1CnSbVeDwJ0AAAAA:-8a6ZMjO7RgYjFBAxIoVU2sWAdsqFzLRTNHA1BkRryNPXx5Vjc8hCDCkS99gcZR0B1rpa33a30yG) published by Raissi et al.
In this notebook we will solve the steady 1 dimensional heat transfer in a composite bar. We will use NVIDIA's SimNet library to create the problem setup. You can refer to the *SimNet User Guide* for more examples on solving different types of PDEs using the SimNet library. Also, for more information about the SimNet APIs you can refer the *SimNet Source Code Documentation*.
### Learning Outcomes
1. How to use SimNet to simulate physics problems using PINNs
1. How to write your own PDEs and formulate the different losses
2. How to use the Constructive Solid Geometry (CSG) module
2. How to use SimNet to solve a parameterized PDEs
## Problem Description
Our aim is to obtain the temperature distribution inside the bar that is made up of two materials with different thermal conductivity. The geometry and the problem specification of the problem can be seen below
The composite bar extends from $x=0$ to $x=2$. The bar has material of conductivity $D_1=10$ from $x=0$ to $x=1$ and $D_2=0.1$ from $x=1$ to $x=2$. Both the ends of the bar, $x=0$ and $x=2$ are maintained at a constant temperatures of $0$ and $100$ respectively. For simplicity of modeling, we will treat the composite bar as two separate bars, bar 1 and bar 2, whose ends are joined together. We will treat the temperatures in the bar 1 as $U_1$ and the temperature in bar 2 as $U_2$.
The equations and boundary conditions governing the problem can be mathematically expressed as
One dimensional diffusion of temperature in bar 1 and 2:
$$
\begin{align}
\frac{d}{dx}\left( D_1\frac{dU_1}{dx} \right) = 0, && \text{when } 0<x<1 \\
\frac{d}{dx}\left( D_2\frac{dU_2}{dx} \right) = 0, && \text{when } 1<x<2 \\
\end{align}
$$
Flux and temperature continuity at interface $(x=1)$
$$
\begin{align}
D_1\frac{dU_1}{dx} = D_1\frac{dU_1}{dx}, && \text{when } x=1 \\
U_1 = U_2, && \text{when } x=1 \\
\end{align}
$$
## Case Setup
Now that we have our problem defined, let's take a look at the code required to solve it using SimNet's PINN library. SimNet has a variety of helper functions that will help us to set up the problem with ease. It has APIs to model geometry in a parameterized fashion using the Constructive Solid Geometry (CSG) module, write-up the required equations in a user-friendly symbolic format and comes with several advanced neural network architectures to choose for more complicated problems.
Now let's start the problem by importing the required libraries and packages
```python
# import SimNet library
from sympy import Symbol, Function, Number, sin, Eq, Abs, exp
import numpy as np
import tensorflow as tf
from simnet.solver import Solver
from simnet.dataset import TrainDomain, ValidationDomain, MonitorDomain
from simnet.data import Validation, Monitor
from simnet.sympy_utils.geometry_1d import Line1D
from simnet.controller import SimNetController
from simnet.node import Node
from simnet.pdes import PDES
from simnet.variables import Variables
```
The `Solver` class trains and evaluates the SimNet's neural network solver. The class `TrainDomain` is used to define the training data for the problem, while the other classes like `ValidationDomain`, `MonitorDomain`, etc. are used to create other data evaluations during the training.
The modules like `PDES` and `sympy_utils` contain predefined differential equations and geometries respectively that one can use to define the problem. We will describe each of them in detail as we move forward in the code. For more detailed information on all the different modules present in SimNet, we recommended you to refer the *SimNet Source Code Documentation*.
## Creating the geometry
In this problem, we will create the 1-dimensional geometry using the `Line1D` from the geometry module. The module also contains several 2d and 3d shapes like rectangle, circle, triangle, cuboids, sphere, torus, cones, tetrahedrons, etc. We will define the one dimensional line object using the two end-points. For composite bar, we will create two separate bars as defined in the problem statement
```python
# params for domain
L1 = Line1D(0,1)
L2 = Line1D(1,2)
```
Next we will define the properties for the problem which will later be used while making the equations, boundary conditions, etc. Also, for this problem, we can find the temperature at the interface analytically and we will use that as to form validation domain to compare our neural network results
```python
# defining the parameters for boundary conditions and equations of the problem
D1 = 1e1
D2 = 1e-1
Ta = 0
Tc = 100
# temperature at the interface from analytical solution
Tb = (Tc + (D1/D2)*Ta)/(1 + (D1/D2))
```
## Defining the differential equations for the problem
The `PDES` class allows us to write the equations symbolically in Sympy. This allows users to quickly write their equations in the most natural way possible. The Sympy equations are converted to TensorFlow expressions in the back-end and can also be printed to ensure correct implementation.
SimNet also comes with several common PDEs predefined for the user to choose from. Some of the PDEs that are already available in the PDEs module are: Navier Stokes, Linear Elasticity, Advection Diffusion, Wave Equations, etc.
Let's create the PDE to define the diffusion equation. We will define the equation in its most generic, transient 3-dimensional, form and then have an argument `dim` that can reduce it to lower dimensional forms.
$$\frac{\partial T}{\partial t}= \nabla\cdot \left( D \nabla T \right) + Q$$
Let's start defining the equation by inhereting from the `PDES` class. We will create the initialization method for this class that defines the equation(s) of interest. We will be defining the diffusion equation using the source(`Q`), diffusivity(`D`), symbol for diffusion(`T`). If `D` or `Q` is given as a string we will convert it to functional form. This will allow us to solve problems with spatially/temporally varying properties.
```python
class Diffusion(PDES):
name = 'Diffusion'
def __init__(self, T='T', D='D', Q=0, dim=3, time=True):
# set params
self.T = T
self.dim = dim
self.time = time
# coordinates
x, y, z = Symbol('x'), Symbol('y'), Symbol('z')
# time
t = Symbol('t')
# make input variables
input_variables = {'x':x,'y':y,'z':z,'t':t}
if self.dim == 1:
input_variables.pop('y')
input_variables.pop('z')
elif self.dim == 2:
input_variables.pop('z')
if not self.time:
input_variables.pop('t')
# Temperature
assert type(T) == str, "T needs to be string"
T = Function(T)(*input_variables)
# Diffusivity
if type(D) is str:
D = Function(D)(*input_variables)
elif type(D) in [float, int]:
D = Number(D)
# Source
if type(Q) is str:
Q = Function(Q)(*input_variables)
elif type(Q) in [float, int]:
Q = Number(Q)
# set equations
self.equations = Variables()
self.equations['diffusion_'+self.T] = (T.diff(t)
- (D*T.diff(x)).diff(x)
- (D*T.diff(y)).diff(y)
- (D*T.diff(z)).diff(z)
- Q)
```
First we defined the input variables $x, y, z$ and $t$ with Sympy symbols. Then we defined the functions for $T$, $D$ and $Q$ that are dependent on the input variables $(x, y, z, t)$. Using these we can write out our simple equation $T_t = \nabla \cdot (D \nabla T) + Q$. We store this equation in the class by adding it to the dictionary of `equations`.
Note that we moved all the terms of the PDE either to LHS or RHS. This way, while using the equations in the `TrainDomain`, we
can assign a custom source function to the `’diffusion_T’` key instead of 0 to add more source terms to our PDE.
Great! We just wrote our own PDE in SimNet! Once you have understood the process to code a simple PDE, you can easily extend the procedure for different PDEs. You can also bundle multiple PDEs together in a same file by adding new keys to the equations dictionary. Below we show the code for the interface boundary condition where we need to maintain the field (dirichlet) and flux (neumann) continuity. *(More examples of coding your own PDE can be found in the SimNet User Guide Chapter 4)*.
**Note :** The field continuity condition is needed because we are solving for two different temperatures in the two bars.
```python
class DiffusionInterface(PDES):
name = 'DiffusionInterface'
def __init__(self, T_1, T_2, D_1, D_2, dim=3, time=True):
# set params
self.T_1 = T_1
self.T_2 = T_2
self.D_1 = D_1
self.D_2 = D_2
self.dim = dim
self.time = time
# coordinates
x, y, z = Symbol('x'), Symbol('y'), Symbol('z')
normal_x, normal_y, normal_z = Symbol('normal_x'), Symbol('normal_y'), Symbol('normal_z')
# time
t = Symbol('t')
# make input variables
input_variables = {'x':x,'y':y,'z':z,'t':t}
if self.dim == 1:
input_variables.pop('y')
input_variables.pop('z')
elif self.dim == 2:
input_variables.pop('z')
if not self.time:
input_variables.pop('t')
# variables to match the boundary conditions (example Temperature)
T_1 = Function(T_1)(*input_variables)
T_2 = Function(T_2)(*input_variables)
# set equations
self.equations = Variables()
self.equations['diffusion_interface_dirichlet_'+self.T_1+'_'+self.T_2] = T_1 - T_2
flux_1 = self.D_1 * (normal_x * T_1.diff(x) + normal_y * T_1.diff(y) + normal_z * T_1.diff(z))
flux_2 = self.D_2 * (normal_x * T_2.diff(x) + normal_y * T_2.diff(y) + normal_z * T_2.diff(z))
self.equations['diffusion_interface_neumann_'+self.T_1+'_'+self.T_2] = flux_1 - flux_2
```
## Creating Train Domain: Assigning the boundary conditions and equations to the geometry
As described earlier, we need to define a training domain for training our neural network. A loss function is then constructed which is a combination of contributions from the boundary conditions and equations that a neural network must satisfy at the end of the training. These training points (BCs and equations) are defined in a class that inherits from the `TrainDomain` parent class. The boundary conditions are implemented as soft constraints. These BCs along with the equations to be solved are used to formulate a composite loss that is minimized by the network during training.
$$L = L_{BC} + L_{Residual}$$
**Boundary conditions:** For generating a boundary condition, we need to sample the points on the required boundary/surface of the geometry and then assign them the desired values. We will use the method `boundary_bc` to sample the points on the boundary of the geometry we already created. `boundary_bc` will sample the entire boundary of the geometry, in this case, both the endpoints of the 1d line. A particular boundary of the geometry can be sub-sampled by using a particular criterion for the boundary_bc using the criteria parameter. For example, to sample the left end of `L1`, criteria is set to `Eq(x, 0)`.
The desired values for the boundary condition are listed as a dictionary in `outvar_sympy` parameter. In SimNet we define these variables as keys of this dictionary which are converted to appropriate nodes in the computational graph. For this problem, we have `'u_1':0` at $x=0$ and `'u_2':100` at $x=2$. At $x=1$, we have the interface condition `'diffusion_interface_dirichlet_u_1_u_2':0` and `'diffusion_interface_neumann_u_1_u_2':0` that we defined earlier (i.e. $U_1=U_2$ and $D_1\frac{dU_1}{dx}=D_2\frac{dU_2}{dx}$).
The number of points to sample on each boundary are specified using the `batch_size_per_area` parameter. The
actual number of points sampled is then equal to the length/area of the geometry being sampled (boundary or interior)
times the batch_size_per_area.
In this case, since we only have 1 point on the boundary, we specify the `batch_size_per_area` as 1 for all the boundaries.
**Equations to solve:** The Diffusion PDE we defined is enforced on all the points in the
interior of both the bars, `L1` and `L2`. We will use `interior_bc` method to sample points in the interior of the geometry. Again, the equations to solve are specified as a dictionary input to `outvar_sympy` parameter. These dictionaries are then used when unrolling the computational graph for training.
For this problem we have the `'diffusion_u_1':0` and `'diffusion_u_2':0` for bars `L1` and `L2` respectively. The parameter `bounds`, determines the range for sampling the values for variables $x$ and $y$. The `lambda_sympy` parameter is used to determine the weights for different losses. In this problem, we weight each point equally and hence keep the variable to 1 for each key (default).
```python
class DiffusionTrain(TrainDomain):
def __init__(self, **config):
super(DiffusionTrain, self).__init__()
# sympy variables
x = Symbol('x')
c = Symbol('c')
# right hand side (x = 2) Pt c
IC = L2.boundary_bc(outvar_sympy={'u_2': Tc},
batch_size_per_area=1,
criteria=Eq(x, 2))
self.add(IC, name="RightHandSide")
# left hand side (x = 0) Pt a
IC = L1.boundary_bc(outvar_sympy={'u_1': Ta},
batch_size_per_area=1,
criteria=Eq(x, 0))
self.add(IC, name="LeftHandSide")
# interface 1-2
IC = L1.boundary_bc(outvar_sympy={'diffusion_interface_dirichlet_u_1_u_2': 0,
'diffusion_interface_neumann_u_1_u_2': 0},
lambda_sympy={'lambda_diffusion_interface_dirichlet_u_1_u_2': 1,
'lambda_diffusion_interface_neumann_u_1_u_2': 1},
batch_size_per_area=1,
criteria=Eq(x, 1))
self.add(IC, name="Interface1n2")
# interior 1
interior = L1.interior_bc(outvar_sympy={'diffusion_u_1': 0},
lambda_sympy={'lambda_diffusion_u_1': 1},
bounds={x: (0, 1)},
batch_size_per_area=200)
self.add(interior, name="Interior1")
# interior 2
interior = L2.interior_bc(outvar_sympy={'diffusion_u_2': 0},
lambda_sympy={'lambda_diffusion_u_2': 1},
bounds={x: (1, 2)},
batch_size_per_area=200)
self.add(interior, name="Interior2")
```
At this point you might be wondering where do we input the parameters of the equation, for eg. values for $D_1, D_2$, etc. Don't worry, we will discuss them while making the neural network solver. But before that, let's create the validation data to verify our simulation results against the analytical solution.
## Creating Validation Domain
For this 1d bar problem where the conductivity is constant in each bar, the temperature varies linearly with position inside the solid. The analytical solution can then be given as:
$$
\begin{align}
U_1 = xT_b + (1-x)T_a, && \text{when } 0 \leq x \leq 1 \\
U_2 = (x-1)T_c + (2-x)T_b, && \text{when } 1 \leq x \leq 2 \\
\end{align}
$$
where,
$$
\begin{align}
T_a = U_1|_{x=0}, && T_c = U_2|_{x=2}, && \frac{\left(T_c + \left( D_1/D_2 \right)T_a \right)}{1+ \left( D_1/D_2 \right)}\\
\end{align}
$$
Now let's create the validation domains. The validation domain is created by inheriting from the `ValidationDomain` parent class. We use numpy to solve for the `u_1` and `u_2` based on the analytical expressions we showed above. The dictionary of generated numpy arrays (`invar_numpy` and `outvar_numpy`)for input and output variables is used as an input to the class method `from_numpy`.
```python
class DiffusionVal(ValidationDomain):
def __init__(self, **config):
super(DiffusionVal, self).__init__()
x = np.expand_dims(np.linspace(0, 1, 100), axis=-1)
u_1 = x*Tb + (1-x)*Ta
invar_numpy = {'x': x}
outvar_numpy = {'u_1': u_1}
val = Validation.from_numpy(invar_numpy, outvar_numpy)
self.add(val, name='Val1')
# make validation data line 2
x = np.expand_dims(np.linspace(1, 2, 100), axis=-1)
u_2 = (x-1)*Tc + (2-x)*Tb
invar_numpy = {'x': x}
outvar_numpy = {'u_2': u_2}
val = Validation.from_numpy(invar_numpy, outvar_numpy)
self.add(val, name='Val2')
```
## Creating Monitor Domain
SimNet library allows you to monitor desired quantities in Tensorboard as the simulation progresses and
assess the convergence. A `MonitorDomain` can be used to create such an feature. This a useful feature when we want
to monitor convergence based on a quantity of interest. Examples of such quantities can be point values of variables,
surface averages, volume averages or any other derived quantities. The variables are available as TensorFlow tensors. We can perform tensor operations available in TensorFlow to compute any desired derived quantity of our choice.
In the code below, we create monitors for flux at the interface. The variable `u_1__x` represents the derivative of `u_1` in x-direction (two underscores (`__`) and the variable (`x`)). The same notation is used while handling other derivatives using the SimNet library. (eg. a neumann boundary condition of $\frac{dU_1}{dx}=0$ can be assigned as `'u_1__x':0` in the train domain for solving the same problem with a adiabatic/fixed flux boundary condition).
The points to sample can be selected in a similar way as we did for specifying the Train domain. We create the monitors by inheriting from the `MonitorDoamin` parent class
```python
class DiffusionMonitor(MonitorDomain):
def __init__(self, **config):
super(DiffusionMonitor, self).__init__()
x = Symbol('x')
# flux in U1 at x = 1
fluxU1 = Monitor(L1.sample_boundary(10, criteria=Eq(x, 1)),
{'flux_U1': lambda var: tf.reduce_mean(D1*var['u_1__x'])})
self.add(fluxU1, 'FluxU1')
# flux in U2 at x = 1
fluxU2 = Monitor(L2.sample_boundary(10, criteria=Eq(x, 1)),
{'flux_U2': lambda var: tf.reduce_mean(D2*var['u_2__x'])})
self.add(fluxU2, 'FluxU2')
```
## Creating the Neural Network Solver
Now that we have the train domain and other validation and monitor domains defined, we can prepare the neural network solver and run the problem. The solver is defined by inheriting the `Solver` parent class. The `train_domain`, `val_domain`, and `monitor_domains` are assigned. The equations to be solved are specified under `self.equations`. Here, we will call the `Diffusion` and `DiffusionInterface` classes we defined earlier to include the PDEs of the problem. Now we will pass the appropriate values for the parameters like the variable name (eg. `T='u_1'`) and also specify the dimensions of the problem (1d and steady).
The inputs and the outputs of the neural network are specified and the nodes of the architecture are made. The default
network architecture is a simple fully connected multi-layer perceptron architecture with *swish* activation function. The network consists of 6 hidden layers with 512 nodes in each layer. Here we are using two separate neural networks for each variable (`u_1` and `u_2`). All these values can be modified through `update_defaults` function. Also, the different architectures in SimNet library can be used (eg. Fourier Net architecture, Radial Basis Neural Network architecture, etc. More details can be found in *SimNet User Guide*). We use the default exponential learning rate decay, set the start learning rate and decay steps and also assign the `'max_steps'` to 5000.
```python
# Define neural network
class DiffusionSolver(Solver):
train_domain = DiffusionTrain
val_domain = DiffusionVal
monitor_domain = DiffusionMonitor
def __init__(self, **config):
super(DiffusionSolver, self).__init__(**config)
self.equations = (Diffusion(T='u_1', D=D1, dim=1, time=False).make_node()
+ Diffusion(T='u_2', D=D2, dim=1, time=False).make_node()
+ DiffusionInterface('u_1', 'u_2', D1, D2, dim=1, time=False).make_node())
diff_net_u_1 = self.arch.make_node(name='diff_net_u_1',
inputs=['x'],
outputs=['u_1'])
diff_net_u_2 = self.arch.make_node(name='diff_net_u_2',
inputs=['x'],
outputs=['u_2'])
self.nets = [diff_net_u_1, diff_net_u_2]
@classmethod
def update_defaults(cls, defaults):
defaults.update({
'network_dir': './network_checkpoint_diff',
'max_steps': 5000,
'decay_steps': 100,
'start_lr': 1e-4,
#'end_lr': 1e-6,
})
```
Awesome! We have just completed the file set up for the problem using the SimNet library. We are now ready to solve the PDEs using Neural Networks!
Before we can start training, we can make use of Tensorboard for visualizing the loss values and convergence of several other monitors we just created. This can be done inside the jupyter framework by selecting the directory in which the checkpoint will be stored by clicking on the small checkbox next to it. The option to launch a Tensorboard then shows up in that directory.
Also, SimNet is desinged such that it can accept command line arguments. This causes issues when the code is directly executed through the jupyter notebook. So as a workaround, we will save the code in form of a python script and execute that script inside the jupyter cell. This example is already saved for you and the code block below executes that script `diffusion_bar.py`. You are encouraged to open the script in a different window and go through the code once before executing. Also, feel free to edit the parameters of the model and see its effect on the results.
```python
import os
import sys
sys.path.append('../../source_code/diffusion_1d')
!python ../../source_code/diffusion_1d/diffusion_bar.py
```
## Visualizing the solution
SimNet saves the data in .vtu and .npz format by default. The .npz arrays can be plotted to visualize the output of the simulation. The .npz files that are created are found in the `network_checkpoint*` directory.
Now let's plot the temperature along the bar for the analytical and the neural network solution. A sample script to plot the results is shown below. If the training is complete, you should get the results like shown below. As we can see, our neural network solution and the analytical solution match almost exactly for this diffusion problem.
```python
%%capture
import sys
!{sys.executable} -m pip install ipympl
%matplotlib inline
import matplotlib.pyplot as plt
plt.figure()
network_dir = './network_checkpoint_diff/val_domain/results/'
u_1_pred = np.load(network_dir + 'Val1_pred.npz', allow_pickle=True)
u_2_pred = np.load(network_dir + 'Val2_pred.npz', allow_pickle=True)
u_1_pred = np.atleast_1d(u_1_pred.f.arr_0)[0]
u_2_pred = np.atleast_1d(u_2_pred.f.arr_0)[0]
plt.plot(u_1_pred['x'][:,0], u_1_pred['u_1'][:,0], '--', label='u_1_pred')
plt.plot(u_2_pred['x'][:,0], u_2_pred['u_2'][:,0], '--', label='u_2_pred')
u_1_true = np.load(network_dir + 'Val1_true.npz', allow_pickle=True)
u_2_true = np.load(network_dir + 'Val2_true.npz', allow_pickle=True)
u_1_true = np.atleast_1d(u_1_true.f.arr_0)[0]
u_2_true = np.atleast_1d(u_2_true.f.arr_0)[0]
plt.plot(u_1_true['x'][:,0], u_1_true['u_1'][:,0], label='u_1_true')
plt.plot(u_2_true['x'][:,0], u_2_true['u_2'][:,0], label='u_2_true')
plt.legend()
plt.savefig('image_diffusion_problem_bootcamp.png')
```
```python
from IPython.display import Image
Image(filename='image_diffusion_problem_bootcamp.png')
```
# Parameterizing the PDE
As we discussed in the introductory notebook, one important advantage of a PINN solver over traditional numerical methods is its ability to solve parameterized geometries and PDEs. This was initially proposed in the [paper](https://arxiv.org/abs/1906.02382) published by Sun et al. This allows us to significant computational advantage as one can now use PINNs to solve for multiple desigs/cases in a single training. Once the training is complete, it is possible to run inference on several geometry/physical parameter combinations as a post-processing step, without solving the forward problem again.
To demonstrate the concept, we will train the same 1d diffusion problem, but now by parameterizing the conductivity of the first bar in the range (5, 25). Once the training is complete, we can obtain the results for any conductivity value in that range saving us the time to train multiple models.
## Case Setup
The definition of equations remain the same for this part. Since earlier while defining the equations, we already defined the constants and coefficients of the PDE to be either numerical values or strings, this will allow us to paramterize `D1` by passing it as a string while calling the equations and making the neural network. Now let's start by creating the paramterized train domain. We will skip the parts that are common to the previous section and only discuss the changes. The complete script can be referred in `diffusion_bar_parameterized.py`
## Creating Train Domain
Before starting out to create the train domain using the `TrainDomain` class, we will create the symbolic variable for the $D_1$ and also specify the range of variation for the variable. While the simulation runs, we will validate it against the same diffusion coefficient that we solved earlier i.e. $D_1=10$. Once the sybolic variables and the ranges are described for sampling, these parameter ranges need to be inputted to the `param_ranges` attribute of each boundary and internal sampling (`boundary_bc` and `interior_bc`)
```python
# params for domain
L1 = Line1D(0,1)
L2 = Line1D(1,2)
D1 = Symbol('D1')
D1_range = {D1: (5, 25)}
D1_validation = 1e1
D2 = 1e-1
Tc = 100
Ta = 0
Tb = (Tc + (D1/D2)*Ta)/(1 + (D1/D2))
Tb_validation = float(Tb.evalf(subs={D1: 1e1}))
class DiffusionTrain(TrainDomain):
def __init__(self, **config):
super(DiffusionTrain, self).__init__()
# sympy variables
x = Symbol('x')
c = Symbol('c')
# right hand side (x = 2) Pt c
IC = L2.boundary_bc(outvar_sympy={'u_2': Tc},
batch_size_per_area=10,
criteria=Eq(x, 2),
param_ranges=D1_range)
self.add(IC, name="RightHandSide")
# left hand side (x = 0) Pt a
IC = L1.boundary_bc(outvar_sympy={'u_1': Ta},
batch_size_per_area=10,
criteria=Eq(x, 0),
param_ranges=D1_range)
self.add(IC, name="LeftHandSide")
# interface 1-2
IC = L1.boundary_bc(outvar_sympy={'diffusion_interface_dirichlet_u_1_u_2': 0,
'diffusion_interface_neumann_u_1_u_2': 0},
lambda_sympy={'lambda_diffusion_interface_dirichlet_u_1_u_2': 1,
'lambda_diffusion_interface_neumann_u_1_u_2': 1},
batch_size_per_area=10,
criteria=Eq(x, 1),
param_ranges=D1_range)
self.add(IC, name="Interface1n2")
# interior 1
interior = L1.interior_bc(outvar_sympy={'diffusion_u_1': 0},
lambda_sympy={'lambda_diffusion_u_1': 1},
bounds={x: (0, 1)},
batch_size_per_area=400,
param_ranges=D1_range)
self.add(interior, name="Interior1")
# interior 2
interior = L2.interior_bc(outvar_sympy={'diffusion_u_2': 0},
lambda_sympy={'lambda_diffusion_u_2': 1},
bounds={x: (1, 2)},
batch_size_per_area=400,
param_ranges=D1_range)
self.add(interior, name="Interior2")
```
## Creating Validation and Monitor Domains
The process to create these domains is again similar to the previous section. For validation data, we need to create an additional key for the string `'D1'` in the `invar_numpy`. The value for this string can be in the range we specified earlier and which we would like to validate against. It is possible to create multiple validations if required, eg. different $D_1$ values. For monitor domain, similar to `interior_bc` and `boundary_bc` in the train domain, we will supply the paramter ranges for monitoring in the `param_ranges` attribute of the `sample_boundary` method.
```python
class DiffusionVal(ValidationDomain):
def __init__(self, **config):
super(DiffusionVal, self).__init__()
# make validation data line 1
x = np.expand_dims(np.linspace(0, 1, 100), axis=-1)
D1 = np.zeros_like(x) + D1_validation # For creating D1 input array
u_1 = x*Tb_validation + (1-x)*Ta
invar_numpy = {'x': x} # Set the invars for the required D1
invar_numpy.update({'D1': np.full_like(invar_numpy['x'], D1_validation)})
outvar_numpy = {'u_1': u_1}
val = Validation.from_numpy(invar_numpy, outvar_numpy)
self.add(val, name='Val1')
# make validation data line 2
x = np.expand_dims(np.linspace(1, 2, 100), axis=-1)
u_2 = (x-1)*Tc + (2-x)*Tb_validation
invar_numpy = {'x': x} # Set the invars for the required D1
invar_numpy.update({'D1': np.full_like(invar_numpy['x'], D1_validation)})
outvar_numpy = {'u_2': u_2}
val = Validation.from_numpy(invar_numpy, outvar_numpy)
self.add(val, name='Val2')
class DiffusionMonitor(MonitorDomain):
def __init__(self, **config):
super(DiffusionMonitor, self).__init__()
x = Symbol('x')
# flux in U1 at x = 1
fluxU1 = Monitor(L1.sample_boundary(10, criteria=Eq(x, 1), param_ranges={D1: D1_validation}), # Set the parameter range for the required D1
{'flux_U1': lambda var: tf.reduce_mean(D1_validation*var['u_1__x'])})
self.add(fluxU1, 'FluxU1')
# flux in U2 at x = 1
fluxU2 = Monitor(L2.sample_boundary(10, criteria=Eq(x, 1), param_ranges={D1: D1_validation}), # Set the parameter range for the required D1
{'flux_U2': lambda var: tf.reduce_mean(D2*var['u_2__x'])})
self.add(fluxU2, 'FluxU2')
```
## Creating the Neural Network Solver
Once all the parameterized domain definitions are completed, for training the parameterized model, we will have the symbolic parameters we defined earlier as inputs to both the neural networks in `diff_net_u_1` and `diff_net_u_2` viz. `'D1'` along with the usual x coordinate. The outputs remain the same as what we would have for any other non-parameterized simulation.
```python
# Define neural network
class DiffusionSolver(Solver):
train_domain = DiffusionTrain
val_domain = DiffusionVal
monitor_domain = DiffusionMonitor
def __init__(self, **config):
super(DiffusionSolver, self).__init__(**config)
self.equations = (Diffusion(T='u_1', D='D1', dim=1, time=False).make_node() # Symbolic input to the equation
+ Diffusion(T='u_2', D=D2, dim=1, time=False).make_node()
+ DiffusionInterface('u_1', 'u_2', 'D1', D2, dim=1, time=False).make_node())
diff_net_u_1 = self.arch.make_node(name='diff_net_u_1',
inputs=['x', 'D1'], # Add the parameters to the network
outputs=['u_1'])
diff_net_u_2 = self.arch.make_node(name='diff_net_u_2',
inputs=['x', 'D1'],
outputs=['u_2'])
self.nets = [diff_net_u_1, diff_net_u_2]
@classmethod # Explain This
def update_defaults(cls, defaults):
defaults.update({
'network_dir': './network_checkpoint_diff_parameterized',
'max_steps': 10000,
'decay_steps': 200,
'start_lr': 1e-4,
'layer_size': 256,
'xla': True,
})
```
## Visualizing the solution
The .npz arrays can be plotted similar to previous section to visualize the output of the simulation. You can see that we get the same answer as the analytical solution. You can try to run the problem in `eval` mode by chaning the validation data and see how it performs for the other `D1` values as well. To run the model in evaluation mode (i.e. without training), you just need to add the `--run_mode=eval` flag while executing the script.
You can see that at a fractional increase in computational time, we solved the PDE for $D_1$ ranging from (5, 25). This concept can easily be extended to more complicated problems and this ability of solving parameterized problems comes very handy during desing optimization and exploring the desing space. For more examples of solving parameterized problems, please refer to *SimNet User Guide Chapter 13*
# Licensing
This material is released by NVIDIA Corporation under the Creative Commons Attribution 4.0 International (CC BY 4.0)
     
     
     
     
   
[Home Page](../../Start_Here.ipynb)
[Previous Notebook](../introduction/Introductory_Notebook.ipynb)
     
     
     
     
   
[1](../introduction/Introductory_Notebook.ipynb)
[2]
[3](../spring_mass/Spring_Mass_Problem_Notebook.ipynb)
[4](../chip_2d/Challenge_CFD_Problem_Notebook.ipynb)
     
     
     
     
[Next Notebook](../spring_mass/Spring_Mass_Problem_Notebook.ipynb)
|
(***********************************************************************************
* Copyright (c) 2016-2018 The University of Sheffield, UK
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* SPDX-License-Identifier: BSD-2-Clause
***********************************************************************************)
section\<open>Document\<close>
text\<open>In this theory, we introduce the types for the Document class.\<close>
theory DocumentClass
imports
CharacterDataClass
begin
text\<open>The type @{type "doctype"} is a type synonym for @{type "string"}, defined
in \autoref{sec:Core_DOM_Basic_Datatypes}.\<close>
record ('node_ptr, 'element_ptr, 'character_data_ptr) RDocument = RObject +
nothing :: unit
doctype :: doctype
document_element :: "(_) element_ptr option"
disconnected_nodes :: "('node_ptr, 'element_ptr, 'character_data_ptr) node_ptr list"
type_synonym
('node_ptr, 'element_ptr, 'character_data_ptr, 'Document) Document
= "('node_ptr, 'element_ptr, 'character_data_ptr, 'Document option) RDocument_scheme"
register_default_tvars
"('node_ptr, 'element_ptr, 'character_data_ptr, 'Document) Document"
type_synonym
('node_ptr, 'element_ptr, 'character_data_ptr, 'shadow_root_ptr, 'Object, 'Node,
'Element, 'CharacterData, 'Document) Object
= "('node_ptr, 'element_ptr, 'character_data_ptr, 'shadow_root_ptr,
('node_ptr, 'element_ptr, 'character_data_ptr, 'Document option)
RDocument_ext + 'Object, 'Node, 'Element, 'CharacterData) Object"
register_default_tvars "('node_ptr, 'element_ptr, 'character_data_ptr, 'shadow_root_ptr,
'Object, 'Node, 'Element, 'CharacterData, 'Document) Object"
type_synonym ('object_ptr, 'node_ptr, 'element_ptr, 'character_data_ptr, 'document_ptr,
'shadow_root_ptr, 'Object, 'Node, 'Element, 'CharacterData, 'Document) heap
= "('object_ptr, 'node_ptr, 'element_ptr, 'character_data_ptr, 'document_ptr,
'shadow_root_ptr,
('node_ptr, 'element_ptr, 'character_data_ptr, 'Document option) RDocument_ext + 'Object, 'Node,
'Element, 'CharacterData) heap"
register_default_tvars
"('object_ptr, 'node_ptr, 'element_ptr, 'character_data_ptr, 'document_ptr,
'shadow_root_ptr, 'Object, 'Node, 'Element, 'CharacterData, 'Document) heap"
definition document_ptr_kinds :: "(_) heap \<Rightarrow> (_) document_ptr fset"
where
"document_ptr_kinds heap = the |`| (cast\<^sub>o\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t\<^sub>_\<^sub>p\<^sub>t\<^sub>r\<^sub>2\<^sub>d\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t\<^sub>_\<^sub>p\<^sub>t\<^sub>r |`|
(ffilter is_document_ptr_kind (object_ptr_kinds heap)))"
definition document_ptrs :: "(_) heap \<Rightarrow> (_) document_ptr fset"
where
"document_ptrs heap = ffilter is_document_ptr (document_ptr_kinds heap)"
definition cast\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t\<^sub>2\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t :: "(_) Object \<Rightarrow> (_) Document option"
where
"cast\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t\<^sub>2\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t obj = (case RObject.more obj of
Inr (Inl document) \<Rightarrow> Some (RObject.extend (RObject.truncate obj) document)
| _ \<Rightarrow> None)"
adhoc_overloading cast cast\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t\<^sub>2\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t
definition cast\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t\<^sub>2\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t:: "(_) Document \<Rightarrow> (_) Object"
where
"cast\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t\<^sub>2\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t document = (RObject.extend (RObject.truncate document)
(Inr (Inl (RObject.more document))))"
adhoc_overloading cast cast\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t\<^sub>2\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t
definition is_document_kind :: "(_) Object \<Rightarrow> bool"
where
"is_document_kind ptr \<longleftrightarrow> cast\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t\<^sub>2\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t ptr \<noteq> None"
lemma document_ptr_kinds_simp [simp]:
"document_ptr_kinds (Heap (fmupd (cast document_ptr) document (the_heap h)))
= {|document_ptr|} |\<union>| document_ptr_kinds h"
apply(auto simp add: document_ptr_kinds_def)[1]
by force
lemma document_ptr_kinds_commutes [simp]:
"cast document_ptr |\<in>| object_ptr_kinds h \<longleftrightarrow> document_ptr |\<in>| document_ptr_kinds h"
apply(auto simp add: object_ptr_kinds_def document_ptr_kinds_def)[1]
by (metis (no_types, lifting) document_ptr_casts_commute2 document_ptr_document_ptr_cast
ffmember_filter fimage_eqI fset.map_comp option.sel)
definition get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t :: "(_) document_ptr \<Rightarrow> (_) heap \<Rightarrow> (_) Document option"
where
"get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t document_ptr h = Option.bind (get (cast document_ptr) h) cast"
adhoc_overloading get get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t
locale l_type_wf_def\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t
begin
definition a_type_wf :: "(_) heap \<Rightarrow> bool"
where
"a_type_wf h = (CharacterDataClass.type_wf h \<and>
(\<forall>document_ptr. document_ptr |\<in>| document_ptr_kinds h \<longrightarrow> get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t document_ptr h \<noteq> None))"
end
global_interpretation l_type_wf_def\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t defines type_wf = a_type_wf .
lemmas type_wf_defs = a_type_wf_def
locale l_type_wf\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t = l_type_wf type_wf for type_wf :: "((_) heap \<Rightarrow> bool)" +
assumes type_wf\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t: "type_wf h \<Longrightarrow> DocumentClass.type_wf h"
sublocale l_type_wf\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t \<subseteq> l_type_wf\<^sub>C\<^sub>h\<^sub>a\<^sub>r\<^sub>a\<^sub>c\<^sub>t\<^sub>e\<^sub>r\<^sub>D\<^sub>a\<^sub>t\<^sub>a
apply(unfold_locales)
by (metis (full_types) type_wf_defs l_type_wf\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_axioms l_type_wf\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def)
locale l_get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_lemmas = l_type_wf\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t
begin
sublocale l_get\<^sub>C\<^sub>h\<^sub>a\<^sub>r\<^sub>a\<^sub>c\<^sub>t\<^sub>e\<^sub>r\<^sub>D\<^sub>a\<^sub>t\<^sub>a_lemmas by unfold_locales
lemma get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_type_wf:
assumes "type_wf h"
shows "document_ptr |\<in>| document_ptr_kinds h \<longleftrightarrow> get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t document_ptr h \<noteq> None"
using l_type_wf\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_axioms assms
apply(simp add: type_wf_defs get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def l_type_wf\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def)
by (metis bind_eq_None_conv document_ptr_kinds_commutes local.get\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t_type_wf
option.distinct(1))
end
global_interpretation l_get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_lemmas type_wf by unfold_locales
definition put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t :: "(_) document_ptr \<Rightarrow> (_) Document \<Rightarrow> (_) heap \<Rightarrow> (_) heap"
where
"put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t document_ptr document = put (cast document_ptr) (cast document)"
adhoc_overloading put put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t
lemma put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_ptr_in_heap:
assumes "put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t document_ptr document h = h'"
shows "document_ptr |\<in>| document_ptr_kinds h'"
using assms
unfolding put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def
by (metis document_ptr_kinds_commutes put\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t_ptr_in_heap)
lemma put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_put_ptrs:
assumes "put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t document_ptr document h = h'"
shows "object_ptr_kinds h' = object_ptr_kinds h |\<union>| {|cast document_ptr|}"
using assms
by (simp add: put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def put\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t_put_ptrs)
lemma cast\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t\<^sub>2\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t_inject [simp]: "cast\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t\<^sub>2\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t x = cast\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t\<^sub>2\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t y \<longleftrightarrow> x = y"
apply(simp add: cast\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t\<^sub>2\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t_def RObject.extend_def)
by (metis (full_types) RObject.surjective old.unit.exhaust)
lemma cast\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t\<^sub>2\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_none [simp]:
"cast\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t\<^sub>2\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t obj = None \<longleftrightarrow> \<not> (\<exists>document. cast\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t\<^sub>2\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t document = obj)"
apply(auto simp add: cast\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t\<^sub>2\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def cast\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t\<^sub>2\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t_def RObject.extend_def
split: sum.splits)[1]
by (metis (full_types) RObject.select_convs(2) RObject.surjective old.unit.exhaust)
lemma cast\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t\<^sub>2\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_some [simp]:
"cast\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t\<^sub>2\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t obj = Some document \<longleftrightarrow> cast document = obj"
by(auto simp add: cast\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t\<^sub>2\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def cast\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t\<^sub>2\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t_def RObject.extend_def
split: sum.splits)
lemma cast\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t\<^sub>2\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_inv [simp]: "cast\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t\<^sub>2\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t (cast\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t\<^sub>2\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t document) = Some document"
by simp
lemma cast_document_not_node [simp]:
"cast\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t\<^sub>2\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t document \<noteq> cast\<^sub>N\<^sub>o\<^sub>d\<^sub>e\<^sub>2\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t node"
"cast\<^sub>N\<^sub>o\<^sub>d\<^sub>e\<^sub>2\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t node \<noteq> cast\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t\<^sub>2\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t document"
by(auto simp add: cast\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t\<^sub>2\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t_def cast\<^sub>N\<^sub>o\<^sub>d\<^sub>e\<^sub>2\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t_def RObject.extend_def)
lemma get_document_ptr_simp1 [simp]:
"get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t document_ptr (put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t document_ptr document h) = Some document"
by(auto simp add: get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def)
lemma get_document_ptr_simp2 [simp]:
"document_ptr \<noteq> document_ptr'
\<Longrightarrow> get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t document_ptr (put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t document_ptr' document h) = get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t document_ptr h"
by(auto simp add: get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def)
lemma get_document_ptr_simp3 [simp]:
"get\<^sub>E\<^sub>l\<^sub>e\<^sub>m\<^sub>e\<^sub>n\<^sub>t element_ptr (put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t document_ptr f h) = get\<^sub>E\<^sub>l\<^sub>e\<^sub>m\<^sub>e\<^sub>n\<^sub>t element_ptr h"
by(auto simp add: get\<^sub>E\<^sub>l\<^sub>e\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def get\<^sub>N\<^sub>o\<^sub>d\<^sub>e_def put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def)
lemma get_document_ptr_simp4 [simp]: "get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t document_ptr (put\<^sub>E\<^sub>l\<^sub>e\<^sub>m\<^sub>e\<^sub>n\<^sub>t element_ptr f h) = get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t document_ptr h"
by(auto simp add: get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def put\<^sub>E\<^sub>l\<^sub>e\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def put\<^sub>N\<^sub>o\<^sub>d\<^sub>e_def)
lemma get_document_ptr_simp5 [simp]:
"get\<^sub>C\<^sub>h\<^sub>a\<^sub>r\<^sub>a\<^sub>c\<^sub>t\<^sub>e\<^sub>r\<^sub>D\<^sub>a\<^sub>t\<^sub>a character_data_ptr (put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t document_ptr f h) = get\<^sub>C\<^sub>h\<^sub>a\<^sub>r\<^sub>a\<^sub>c\<^sub>t\<^sub>e\<^sub>r\<^sub>D\<^sub>a\<^sub>t\<^sub>a character_data_ptr h"
by(auto simp add: get\<^sub>C\<^sub>h\<^sub>a\<^sub>r\<^sub>a\<^sub>c\<^sub>t\<^sub>e\<^sub>r\<^sub>D\<^sub>a\<^sub>t\<^sub>a_def get\<^sub>N\<^sub>o\<^sub>d\<^sub>e_def put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def)
lemma get_document_ptr_simp6 [simp]: "get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t document_ptr (put\<^sub>C\<^sub>h\<^sub>a\<^sub>r\<^sub>a\<^sub>c\<^sub>t\<^sub>e\<^sub>r\<^sub>D\<^sub>a\<^sub>t\<^sub>a character_data_ptr f h) = get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t document_ptr h"
by(auto simp add: get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def put\<^sub>C\<^sub>h\<^sub>a\<^sub>r\<^sub>a\<^sub>c\<^sub>t\<^sub>e\<^sub>r\<^sub>D\<^sub>a\<^sub>t\<^sub>a_def put\<^sub>N\<^sub>o\<^sub>d\<^sub>e_def)
lemma new\<^sub>E\<^sub>l\<^sub>e\<^sub>m\<^sub>e\<^sub>n\<^sub>t_get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t [simp]:
assumes "new\<^sub>E\<^sub>l\<^sub>e\<^sub>m\<^sub>e\<^sub>n\<^sub>t h = (new_element_ptr, h')"
shows "get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t ptr h = get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t ptr h'"
using assms
by(auto simp add: new\<^sub>E\<^sub>l\<^sub>e\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def Let_def)
lemma new\<^sub>C\<^sub>h\<^sub>a\<^sub>r\<^sub>a\<^sub>c\<^sub>t\<^sub>e\<^sub>r\<^sub>D\<^sub>a\<^sub>t\<^sub>a_get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t [simp]:
assumes "new\<^sub>C\<^sub>h\<^sub>a\<^sub>r\<^sub>a\<^sub>c\<^sub>t\<^sub>e\<^sub>r\<^sub>D\<^sub>a\<^sub>t\<^sub>a h = (new_character_data_ptr, h')"
shows "get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t ptr h = get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t ptr h'"
using assms
by(auto simp add: new\<^sub>C\<^sub>h\<^sub>a\<^sub>r\<^sub>a\<^sub>c\<^sub>t\<^sub>e\<^sub>r\<^sub>D\<^sub>a\<^sub>t\<^sub>a_def Let_def)
abbreviation
create_document_obj :: "char list \<Rightarrow> (_) element_ptr option \<Rightarrow> (_) node_ptr list \<Rightarrow> (_) Document"
where
"create_document_obj doctype_arg document_element_arg disconnected_nodes_arg
\<equiv> \<lparr> RObject.nothing = (), RDocument.nothing = (), doctype = doctype_arg,
document_element = document_element_arg,
disconnected_nodes = disconnected_nodes_arg, \<dots> = None \<rparr>"
definition new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t :: "(_)heap \<Rightarrow> ((_) document_ptr \<times> (_) heap)"
where
"new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t h =
(let new_document_ptr = document_ptr.Ref (Suc (fMax (document_ptr.the_ref |`| (document_ptrs h))))
in
(new_document_ptr, put new_document_ptr (create_document_obj '''' None []) h))"
lemma new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_ptr_in_heap:
assumes "new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t h = (new_document_ptr, h')"
shows "new_document_ptr |\<in>| document_ptr_kinds h'"
using assms
unfolding new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def Let_def
using put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_ptr_in_heap by blast
lemma new_document_ptr_new:
"document_ptr.Ref (Suc (fMax (finsert 0 (document_ptr.the_ref |`| document_ptrs h))))
|\<notin>| document_ptrs h"
by (metis Suc_n_not_le_n document_ptr.sel(1) fMax_ge fimage_finsert finsertI1 finsertI2 set_finsert)
lemma new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_ptr_not_in_heap:
assumes "new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t h = (new_document_ptr, h')"
shows "new_document_ptr |\<notin>| document_ptr_kinds h"
using assms
unfolding new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def
by (metis Pair_inject document_ptrs_def fMax_finsert fempty_iff ffmember_filter
fimage_is_fempty is_document_ptr_ref max_0L new_document_ptr_new)
lemma new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_new_ptr:
assumes "new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t h = (new_document_ptr, h')"
shows "object_ptr_kinds h' = object_ptr_kinds h |\<union>| {|cast new_document_ptr|}"
using assms
by (metis Pair_inject new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_put_ptrs)
lemma new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_is_document_ptr:
assumes "new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t h = (new_document_ptr, h')"
shows "is_document_ptr new_document_ptr"
using assms
by(auto simp add: new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def Let_def)
lemma new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_get\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t [simp]:
assumes "new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t h = (new_document_ptr, h')"
assumes "ptr \<noteq> cast new_document_ptr"
shows "get\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t ptr h = get\<^sub>O\<^sub>b\<^sub>j\<^sub>e\<^sub>c\<^sub>t ptr h'"
using assms
by(auto simp add: new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def Let_def put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def)
lemma new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_get\<^sub>N\<^sub>o\<^sub>d\<^sub>e [simp]:
assumes "new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t h = (new_document_ptr, h')"
shows "get\<^sub>N\<^sub>o\<^sub>d\<^sub>e ptr h = get\<^sub>N\<^sub>o\<^sub>d\<^sub>e ptr h'"
using assms
apply(simp add: new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def Let_def put\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def)
by(auto simp add: get\<^sub>N\<^sub>o\<^sub>d\<^sub>e_def)
lemma new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_get\<^sub>E\<^sub>l\<^sub>e\<^sub>m\<^sub>e\<^sub>n\<^sub>t [simp]:
assumes "new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t h = (new_document_ptr, h')"
shows "get\<^sub>E\<^sub>l\<^sub>e\<^sub>m\<^sub>e\<^sub>n\<^sub>t ptr h = get\<^sub>E\<^sub>l\<^sub>e\<^sub>m\<^sub>e\<^sub>n\<^sub>t ptr h'"
using assms
by(auto simp add: new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def Let_def)
lemma new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_get\<^sub>C\<^sub>h\<^sub>a\<^sub>r\<^sub>a\<^sub>c\<^sub>t\<^sub>e\<^sub>r\<^sub>D\<^sub>a\<^sub>t\<^sub>a [simp]:
assumes "new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t h = (new_document_ptr, h')"
shows "get\<^sub>C\<^sub>h\<^sub>a\<^sub>r\<^sub>a\<^sub>c\<^sub>t\<^sub>e\<^sub>r\<^sub>D\<^sub>a\<^sub>t\<^sub>a ptr h = get\<^sub>C\<^sub>h\<^sub>a\<^sub>r\<^sub>a\<^sub>c\<^sub>t\<^sub>e\<^sub>r\<^sub>D\<^sub>a\<^sub>t\<^sub>a ptr h'"
using assms
by(auto simp add: new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def Let_def)
lemma new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t [simp]:
assumes "new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t h = (new_document_ptr, h')"
assumes "ptr \<noteq> new_document_ptr"
shows "get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t ptr h = get\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t ptr h'"
using assms
by(auto simp add: new\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t_def Let_def)
locale l_known_ptr\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t
begin
definition a_known_ptr :: "(_) object_ptr \<Rightarrow> bool"
where
"a_known_ptr ptr = (known_ptr ptr \<or> is_document_ptr ptr)"
lemma known_ptr_not_document_ptr: "\<not>is_document_ptr ptr \<Longrightarrow> a_known_ptr ptr \<Longrightarrow> known_ptr ptr"
by(simp add: a_known_ptr_def)
end
global_interpretation l_known_ptr\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t defines known_ptr = a_known_ptr .
lemmas known_ptr_defs = a_known_ptr_def
locale l_known_ptrs\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t = l_known_ptr known_ptr for known_ptr :: "(_) object_ptr \<Rightarrow> bool"
begin
definition a_known_ptrs :: "(_) heap \<Rightarrow> bool"
where
"a_known_ptrs h = (\<forall>ptr. ptr |\<in>| object_ptr_kinds h \<longrightarrow> known_ptr ptr)"
lemma known_ptrs_known_ptr: "a_known_ptrs h \<Longrightarrow> ptr |\<in>| object_ptr_kinds h \<Longrightarrow> known_ptr ptr"
by(simp add: a_known_ptrs_def)
lemma known_ptrs_preserved:
"object_ptr_kinds h = object_ptr_kinds h' \<Longrightarrow> a_known_ptrs h = a_known_ptrs h'"
by(auto simp add: a_known_ptrs_def)
lemma known_ptrs_subset:
"object_ptr_kinds h' |\<subseteq>| object_ptr_kinds h \<Longrightarrow> a_known_ptrs h \<Longrightarrow> a_known_ptrs h'"
by(auto simp add: a_known_ptrs_def)
end
global_interpretation l_known_ptrs\<^sub>D\<^sub>o\<^sub>c\<^sub>u\<^sub>m\<^sub>e\<^sub>n\<^sub>t known_ptr defines known_ptrs = a_known_ptrs .
lemmas known_ptrs_defs = a_known_ptrs_def
lemma known_ptrs_is_l_known_ptrs [instances]: "l_known_ptrs known_ptr known_ptrs"
using known_ptrs_known_ptr known_ptrs_preserved l_known_ptrs_def known_ptrs_subset by blast
end
|
[STATEMENT]
lemma insert3_insert2:
"bal_i n (height t) \<Longrightarrow> insert3 x (t,n) = insert2 x (t,n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. bal_i n (height t) \<Longrightarrow> insert3 x (t, n) = insert2 x (t, n)
[PROOF STEP]
by(simp add: ins3_ins2 split: up2.split)
|
# Angular velocity in 3D movements
> Renato Naville Watanabe, Marcos Duarte
> [Laboratory of Biomechanics and Motor Control](http://pesquisa.ufabc.edu.br/bmclab)
> Federal University of ABC, Brazil
<h1>Contents<span class="tocSkip"></span></h1>
<div class="toc"><ul class="toc-item"><li><span><a href="#Axis-of-rotation" data-toc-modified-id="Axis-of-rotation-1"><span class="toc-item-num">1 </span>Axis of rotation</a></span></li><li><span><a href="#Computing-the-angular-velocity" data-toc-modified-id="Computing-the-angular-velocity-2"><span class="toc-item-num">2 </span>Computing the angular velocity</a></span><ul class="toc-item"><li><span><a href="#1-)-3D-pendulum-bar" data-toc-modified-id="1-)-3D-pendulum-bar-2.1"><span class="toc-item-num">2.1 </span>1 ) 3D pendulum bar </a></span></li></ul></li><li><span><a href="#Further-reading" data-toc-modified-id="Further-reading-3"><span class="toc-item-num">3 </span>Further reading</a></span></li><li><span><a href="#Problems" data-toc-modified-id="Problems-4"><span class="toc-item-num">4 </span>Problems</a></span></li><li><span><a href="#References" data-toc-modified-id="References-5"><span class="toc-item-num">5 </span>References</a></span></li></ul></div>
An usual problem found in Biomechanics (and Mechanics in general) is to find the angular velocity of an object. We consider that a basis <span class="notranslate">
$\hat{\boldsymbol e_1}$, $\hat{\boldsymbol e_2}$</span> and <span class="notranslate">$\hat{\boldsymbol e_3}$</span> is attached to the body and is known. To learn how to find a basis of a frame of reference, see [this notebook](https://nbviewer.jupyter.org/github/BMClab/bmc/blob/master/notebooks/ReferenceFrame.ipynb).
<figure>
## Axis of rotation
As in the planar movement, the angular velocity is a vector perpendicular to the rotation. The line in the direction of the angular velocity vector is known as the axis of rotation.
The rotation beween two frames of reference is characterized by the rotation matrix <span class="notranslate">$R$</span> obtained by stacking the versors <span class="notranslate">$\hat{\boldsymbol e_1}$, $\hat{\boldsymbol e_2}$</span> and <span class="notranslate">$\hat{\boldsymbol e_3}$</span> in each column of the matrix (for a revision on rotation matrices see [this](https://nbviewer.jupyter.org/github/bmclab/bmc/blob/master/notebooks/Transformation2D.ipynb) and [this](https://nbviewer.jupyter.org/github/bmclab/bmc/blob/master/notebooks/Transformation3D.ipynb) notebooks).
A vector in the direction of the axis of rotation is a vector that does not changes the position after the rotation. That is:
<span class="notranslate">
\begin{equation}
v = Rv
\end{equation}
</span>
This vector is the eigenvector of the rotation matrix <span class="notranslate">$R$</span> with eigenvalue equal to one.
Below the yellow arrow indicates the axis of rotation of the rotation between the position of the reference frame <span class="notranslate">$\hat{\boldsymbol i}$, $\hat{\boldsymbol j}$</span> and <span class="notranslate">$\hat{\boldsymbol k}$</span> and the reference frame of <span class="notranslate">$\hat{\boldsymbol e_1}$, $\hat{\boldsymbol e_2}$</span> and <span class="notranslate">$\hat{\boldsymbol e_3}$</span>.
```python
from IPython.core.display import Math, display
import sympy as sym
import sys
sys.path.insert(1, r'./../functions') # add to pythonpath
%matplotlib notebook
from CCSbasis import CCSbasis
import numpy as np
a, b, g = sym.symbols('alpha, beta, gamma')
# Elemental rotation matrices of xyz in relation to XYZ:
RX = sym.Matrix([[1, 0, 0],
[0, sym.cos(a), -sym.sin(a)],
[0, sym.sin(a), sym.cos(a)]])
RY = sym.Matrix([[sym.cos(b), 0, sym.sin(b)],
[0, 1, 0],
[-sym.sin(b), 0, sym.cos(b)]])
RZ = sym.Matrix([[sym.cos(g), -sym.sin(g), 0],
[sym.sin(g), sym.cos(g), 0],
[0, 0, 1]])
# Rotation matrix of xyz in relation to XYZ:
R = RY@RX@RZ
R = sym.lambdify((a, b, g), R, 'numpy')
alpha = np.pi/4
beta = np.pi/4
gamma = np.pi/4
R = R(alpha, beta, gamma)
e1 = np.array([[1, 0, 0]])
e2 = np.array([[0, 1, 0]])
e3 = np.array([[0, 0, 1]])
basis = np.vstack((e1, e2, e3))
basisRot = R@basis
lv, v = np.linalg.eig(R)
axisOfRotation = [np.real(np.squeeze(v[:, np.abs(lv-1) < 1e-6]))]
CCSbasis(Oijk=np.array([0, 0, 0]), Oxyz=np.array([0, 0, 0]), ijk=basis.T,
xyz=basisRot.T, vector=True, point=axisOfRotation);
```
<IPython.core.display.Javascript object>
## Computing the angular velocity
The angular velocity <span class="notranslate">$\vec{\boldsymbol\omega}$</span> is in the direction of the axis of rotation (hence it is parallel to the axis of rotation) and can be described in the basis fixed in the body:
<span class="notranslate">
\begin{equation}
\vec{\boldsymbol{\omega}} = \omega_1\hat{\boldsymbol{e_1}} + \omega_2\hat{\boldsymbol{e_2}} + \omega_3\hat{\boldsymbol{e_3}}
\end{equation}
</span>
So, we must find <span class="notranslate">$\omega_1$, $\omega_2$</span> and <span class="notranslate">$\omega_3$</span>.
First we will express the angular velocity <span class="notranslate">$\vec{\boldsymbol{\omega}}$</span> in terms of these derivatives.
Remember that the angular velocity is described as a vector in the orthogonal plane of the rotation. (<span class="notranslate">$\vec{\boldsymbol{\omega_1}} = \frac{d\theta_1}{dt}\hat{\boldsymbol{e_1}}$, $\vec{\boldsymbol{\omega_2}} = \frac{d\theta_2}{dt}\hat{\boldsymbol{e_2}}$</span> and <span class="notranslate">$\vec{\boldsymbol{\omega_3}} = \frac{d\theta_3}{dt}\hat{\boldsymbol{e_3}}$</span>).
Note also that the derivative of the angle <span class="notranslate">$\theta_1$</span> can be described as the projection of the vector <span class="notranslate">$\frac{d\hat{\boldsymbol{e_2}}}{dt}$</span> on the vector <span class="notranslate">$\hat{\boldsymbol{e_3}}$</span>.
This can be written by using the scalar product between these vectors: <span class="notranslate">$\frac{d\theta_1}{dt} = \frac{d\hat{\boldsymbol{e_2}}}{dt}\cdot \hat{\boldsymbol{e_3}}$</span>.
<figure>
Similarly, the same is valid for the angles in the other two directions: <span class="notranslate">$\frac{d\theta_2}{dt} = \frac{d\hat{\boldsymbol{e_3}}}{dt}\cdot \hat{\boldsymbol{e_1}}$</span> and <span class="notranslate">$\frac{d\theta_3}{dt} = \frac{d\hat{\boldsymbol{e_1}}}{dt}\cdot \hat{\boldsymbol{e_2}}$</span>.
So, we can write the angular velocity as:
<span class="notranslate">
\begin{equation}
\vec{\boldsymbol{\omega}} = \left(\frac{d\hat{\boldsymbol{e_2}}}{dt}\cdot \hat{\boldsymbol{e_3}}\right) \hat{\boldsymbol{e_1}} + \left(\frac{d\hat{\boldsymbol{e_3}}}{dt}\cdot \hat{\boldsymbol{e_1}}\right) \hat{\boldsymbol{e_2}} + \left(\frac{d\hat{\boldsymbol{e_1}}}{dt}\cdot \hat{\boldsymbol{e_2}}\right) \hat{\boldsymbol{e_3}}
\end{equation}
</span>
Note that the angular velocity <span class="notranslate">$\vec{\boldsymbol\omega}$</span> is expressed in the reference frame of the object. If you want it described as a linear combination of the versors of the global basis <span class="notranslate">$\hat{\boldsymbol{i}}$, $\hat{\boldsymbol{j}}$</span> and <span class="notranslate">$\hat{\boldsymbol{k}}$</span>, just multiply the vector <span class="notranslate">$\vec{\boldsymbol\omega}$</span> by the rotation matrix formed by stacking each versor in a column of the rotation matrix (for a revision on rotation matrices see [this](https://nbviewer.jupyter.org/github/bmclab/bmc/blob/master/notebooks/Transformation2D.ipynb) and [this](https://nbviewer.jupyter.org/github/bmclab/bmc/blob/master/notebooks/Transformation3D.ipynb) notebooks).
### 3D pendulum bar
At the file '../data/3Dpendulum.txt' there are 3 seconds of data of 3 points of a three-dimensional cylindrical pendulum. It can move in every direction and has a motor at the upper part of the cylindrical bar producing torques to move the bar.
The point m1 is at the upper part of the cylinder and is the origin of the system.
The point m2 is at the center of mass of the cylinder.
The point m3 is a point at the surface of the cylinder.
Below we compute its angular velocity.
First we load the file.
```python
import numpy as np
import matplotlib.pyplot as plt
np.set_printoptions(precision=4, suppress=True)
data = np.loadtxt('../data/3dPendulum.txt', skiprows=1, delimiter = ',')
```
And separate each mark in a variable.
```python
t = data[:, 0]
m1 = data[:, 1:4]
m2 = data[:, 4:7]
m3 = data[:, 7:]
dt = t[1]
```
Now, we form the basis <span class="notranslate">$\hat{\boldsymbol e_1}$, $\hat{\boldsymbol e_2}$</span> and <span class="notranslate">$\hat{\boldsymbol e_3}$</span>.
```python
V1 = m2 - m1
e1 = V1 / np.linalg.norm(V1, axis=1, keepdims=True)
V2 = m3-m2
V3 = np.cross(V2, V1)
e2 = V3 / np.linalg.norm(V3, axis=1, keepdims=True)
e3 = np.cross(e1, e2)
```
Below, we compute the derivative of each of the versors.
```python
de1dt = np.diff(e1, axis=0) / dt
de2dt = np.diff(e2, axis=0) / dt
de3dt = np.diff(e3, axis=0) / dt
```
Here we compute each of the components <span class="notranslate">$\omega_1$, $\omega_2$</span> and <span class="notranslate">$\omega_3$</span> of the angular velocity <span class="notranslate">$\vec{\boldsymbol \omega}$</span> by using the scalar product.
```python
omega1 = np.sum(de2dt*e3[0:-1, :], axis=1).reshape(-1, 1)
omega2 = np.sum(de3dt*e1[0:-1, :], axis=1).reshape(-1, 1)
omega3 = np.sum(de1dt*e2[0:-1, :], axis=1).reshape(-1, 1)
```
Finally, the angular velocity vector <span class="notranslate">$\vec{\boldsymbol \omega}$</span> is formed by stacking the three components together.
```python
omega = np.hstack((omega1, omega2, omega3))
```
```python
%matplotlib inline
fig, ax = plt.subplots(1, 1, figsize=(8, 4))
ax.plot(t[:-1], omega)
ax.set_xlabel('Time [s]')
ax.set_ylabel('Angular velocity [rad/s]')
ax.legend(labels=['$ω_1$', '$ω_2$', '$ω_3$'])
plt.tight_layout()
```
## Further reading
- Read pages 66-92 of the 1st chapter of the [Ruina and Rudra's book](http://ruina.tam.cornell.edu/Book/index.html) for a review of Gram-Schmidt, dot product and cross product.
- [Scalar and Vector](https://nbviewer.jupyter.org/github/bmclab/bmc/blob/master/notebooks/ScalarVector.ipynb)
## Problems
1) Initially, the lateral malleolus, medial malleolus, fibular head and medial condyle of the leg have the following positions (described in the laboratory coordinate system with coordinates 𝑥,𝑦,𝑧 in cm, the 𝑥 axis points forward and the 𝑦 axes points upward): lateral malleolus (lm = [2.92, 10.10, 18.85]), medial malleolus (mm = [2.71, 10.22, 26.52]), fibular head (fh = [5.05, 41.90, 15.41]), and medial condyle (mc = [8.29, 41.88, 26.52]). After 0.05 seconds the markers have the following positions: lateral malleolus (lm = [2.95, 10.19, 18.41]), medial malleolus (mm = [3.16, 10.04, 26.10]), fibular head (fh = [4.57, 42.13, 15.97]), and medial condyle (mc = [8.42, 41.76, 26.90]).
Find the angular velocity of of the leg.
## References
- Kane T, Levinson D (1985) [Dynamics: Theory and Applications](https://ecommons.cornell.edu/handle/1813/638). McGraw-Hill, Inc
|
module Extra.Op
public export
(>>) : (a -> b) -> (b -> c) -> (a -> c)
(>>) f g = g . f
infixr 9 >>
public export
(|>) : a -> (a -> b) -> b
(|>) x f = f x
infixr 5 |>
|
import numpy as np
from mip.mip_nn import MIP_NN
from globals import BIN, CONT, TARGET_ERROR, MARGIN, EPSILON
class SAT_MARGIN(MIP_NN):
def __init__(self, data, architecture, bound, reg, fair):
MIP_NN.__init__(self, data, architecture, bound, reg, fair)
# Cutoff set so as not too optimize fully.
self.cutoff = self.N*TARGET_ERROR
self.init_output()
if reg:
self.add_regularizer()
if reg == -1:
self.calc_multi_obj()
else:
self.calc_objective()
self.add_output_constraints()
def init_output(self):
self.output = np.full((self.N, self.architecture[-1]), None)
for k in range(self.N):
for j in range(self.architecture[-1]):
self.output[k,j] = self.add_var(BIN, name="output_%s-%s" % (j,k))
def add_output_constraints(self):
layer = len(self.architecture) - 1
lastLayer = layer - 1
neurons_in = self.architecture[lastLayer]
neurons_out = self.architecture[layer]
#self.raw_output = np.full((self.N, neurons_out), None)
if self.reg:
self.margin = self.add_var(CONT, name="margin", bound=self.out_bound)
self.new_out_bound = (self.H[len(self.architecture)-2].sum() + 1)*self.bound
self.add_constraint(self.margin >= 0.5*self.new_out_bound/2)
for k in range(self.N):
for j in range(neurons_out):
#self.raw_output[k,j] = self.add_var(CONT, name="raw_output", bound=self.out_bound)
inputs = []
for i in range(neurons_in):
if layer == 1:
inputs.append(self.train_x[k,i]*self.weights[layer][i,j])
else:
inputs.append(self.var_c[layer][k,i,j])
pre_activation = sum(inputs) + self.biases[layer][j]
#self.add_constraint(self.raw_output[k,j] == pre_activation)
#self.raw_output[k,j] = pre_activation
if self.reg:
self.add_constraint((self.output[k,j] == 1) >> (pre_activation*self.data['oh_train_y'][k,j] >= self.margin))
self.add_constraint((self.output[k,j] == 0) >> (pre_activation*self.data['oh_train_y'][k,j] <= self.margin - EPSILON))
else:
pre_activation = 2*pre_activation/self.out_bound
# HYPERPARAMETER 0.5
self.add_constraint((self.output[k,j] == 1) >> (pre_activation*self.data['oh_train_y'][k,j] >= MARGIN))
self.add_constraint((self.output[k,j] == 0) >> (pre_activation*self.data['oh_train_y'][k,j] <= MARGIN - EPSILON))
def calc_objective(self):
self.obj = np.prod(self.output.shape) - self.output.sum()
if self.reg:
for layer in self.H:
self.obj += self.reg*self.H[layer].sum()
self.set_objective()
def calc_multi_obj(self):
self.obj = np.prod(self.output.shape) - self.output.sum()
self.m.setObjectiveN(self.obj, 0, 2)
#self.m.ObjNAbsTol = self.cutoff
if self.reg:
regObj = 0
for layer in self.H:
regObj += self.H[layer].sum()
self.m.setObjectiveN(regObj, 1, 1)
def extract_values(self, get_func=lambda z: z.x):
varMatrices = MIP_NN.extract_values(self, get_func)
varMatrices["output"] = self.get_val(self.output, get_func)
if self.reg:
for layer in self.H:
varMatrices["H_%s" % layer] = self.get_val(self.H[layer], get_func)
return varMatrices
|
Formal statement is: lemma synthetic_div_eq_0_iff: "synthetic_div p c = 0 \<longleftrightarrow> degree p = 0" Informal statement is: The synthetic division of a polynomial $p$ by a constant $c$ is zero if and only if $p$ is a constant polynomial.
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import topology.order.basic
import topology.algebra.group.basic
/-!
# Topology on a linear ordered additive commutative group
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file we prove that a linear ordered additive commutative group with order topology is a
topological group. We also prove continuity of `abs : G → G` and provide convenience lemmas like
`continuous_at.abs`.
-/
open set filter
open_locale topology filter
variables {α G : Type*} [topological_space G] [linear_ordered_add_comm_group G] [order_topology G]
variables {l : filter α} {f g : α → G}
@[priority 100] -- see Note [lower instance priority]
instance linear_ordered_add_comm_group.topological_add_group : topological_add_group G :=
{ continuous_add :=
begin
refine continuous_iff_continuous_at.2 _,
rintro ⟨a, b⟩,
refine linear_ordered_add_comm_group.tendsto_nhds.2 (λ ε ε0, _),
rcases dense_or_discrete 0 ε with (⟨δ, δ0, δε⟩|⟨h₁, h₂⟩),
{ -- If there exists `δ ∈ (0, ε)`, then we choose `δ`-nhd of `a` and `(ε-δ)`-nhd of `b`
filter_upwards [(eventually_abs_sub_lt a δ0).prod_nhds
(eventually_abs_sub_lt b (sub_pos.2 δε))],
rintros ⟨x, y⟩ ⟨hx : |x - a| < δ, hy : |y - b| < ε - δ⟩,
rw [add_sub_add_comm],
calc |x - a + (y - b)| ≤ |x - a| + |y - b| : abs_add _ _
... < δ + (ε - δ) : add_lt_add hx hy
... = ε : add_sub_cancel'_right _ _ },
{ -- Otherwise `ε`-nhd of each point `a` is `{a}`
have hε : ∀ {x y}, |x - y| < ε → x = y,
{ intros x y h,
simpa [sub_eq_zero] using h₂ _ h },
filter_upwards [(eventually_abs_sub_lt a ε0).prod_nhds (eventually_abs_sub_lt b ε0)],
rintros ⟨x, y⟩ ⟨hx : |x - a| < ε, hy : |y - b| < ε⟩,
simpa [hε hx, hε hy] }
end,
continuous_neg := continuous_iff_continuous_at.2 $ λ a,
linear_ordered_add_comm_group.tendsto_nhds.2 $ λ ε ε0,
(eventually_abs_sub_lt a ε0).mono $ λ x hx, by rwa [neg_sub_neg, abs_sub_comm] }
@[continuity]
lemma continuous_abs : continuous (abs : G → G) := continuous_id.max continuous_neg
protected lemma filter.tendsto.abs {a : G} (h : tendsto f l (𝓝 a)) :
tendsto (λ x, |f x|) l (𝓝 (|a|)) :=
(continuous_abs.tendsto _).comp h
lemma tendsto_zero_iff_abs_tendsto_zero (f : α → G) :
tendsto f l (𝓝 0) ↔ tendsto (abs ∘ f) l (𝓝 0) :=
begin
refine ⟨λ h, (abs_zero : |(0 : G)| = 0) ▸ h.abs, λ h, _⟩,
have : tendsto (λ a, -|f a|) l (𝓝 0) := (neg_zero : -(0 : G) = 0) ▸ h.neg,
exact tendsto_of_tendsto_of_tendsto_of_le_of_le this h
(λ x, neg_abs_le_self $ f x) (λ x, le_abs_self $ f x),
end
variables [topological_space α] {a : α} {s : set α}
protected lemma continuous.abs (h : continuous f) : continuous (λ x, |f x|) := continuous_abs.comp h
protected lemma continuous_at.abs (h : continuous_at f a) : continuous_at (λ x, |f x|) a := h.abs
protected lemma continuous_within_at.abs (h : continuous_within_at f s a) :
continuous_within_at (λ x, |f x|) s a := h.abs
protected lemma continuous_on.abs (h : continuous_on f s) : continuous_on (λ x, |f x|) s :=
λ x hx, (h x hx).abs
lemma tendsto_abs_nhds_within_zero : tendsto (abs : G → G) (𝓝[≠] 0) (𝓝[>] 0) :=
(continuous_abs.tendsto' (0 : G) 0 abs_zero).inf $ tendsto_principal_principal.2 $ λ x, abs_pos.2
|
{-# LANGUAGE TemplateHaskell #-}
import Test.QuickCheck
import System.Exit
import Data.Complex as C
import FFT
-- Helpers
allClose :: (Ord a, Fractional a) => [a] -> [a] -> Bool
allClose xs ys = and $ fmap (\diff -> diff < 1e-4) diffs
where
diffs = [abs $ x - y | (x,y) <- zip xs ys]
allCloseComplex :: (RealFloat a) => [Complex a] -> [Complex a] -> Bool
allCloseComplex xs ys = and $ fmap (\diff -> diff < 1e-4) diffs
where
diffs = [C.magnitude $ x - y | (x,y) <- zip xs ys]
-- Properties
prop_dftInverse :: [Complex Double] -> Bool
prop_dftInverse xs = allCloseComplex xs $ idft (dft xs)
prop_rdftInverse :: [Double] -> Bool
prop_rdftInverse xs = allClose xs $ irdft (rdft xs)
prop_fftInverse :: [Complex Double] -> Bool
prop_fftInverse xs = allCloseComplex xs $ ifft (fft xs)
prop_rfftInverse :: [Double] -> Bool
prop_rfftInverse xs = allClose xs $ irfft (rfft xs)
prop_fft :: [Complex Double] -> Bool
prop_fft xs = allCloseComplex (fft xs) (dft xs)
prop_rfft :: [Double] -> Bool
prop_rfft xs = allCloseComplex (rfft xs) (rdft xs)
-- https://hackage.haskell.org/package/QuickCheck-2.13.2/docs/Test-QuickCheck-All.html
return []
runTests :: IO Bool
runTests = $quickCheckAll
main :: IO ()
main = do
success <- and <$> sequence [runTests]
if success then exitSuccess else exitFailure
|
[STATEMENT]
lemma fold_pls'_eq: "Finite_Set.fold (pls' \<circ> g) z A = Finite_Set.fold (pls \<circ> g) z A"
if "g ` A \<subseteq> S"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. Finite_Set.fold (pls' \<circ> g) z A = Finite_Set.fold (pls \<circ> g) z A
[PROOF STEP]
using add_assoc add_commute add_mem zero_mem that
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?a \<in> S; ?b \<in> S; ?c \<in> S\<rbrakk> \<Longrightarrow> pls (pls ?a ?b) ?c = pls ?a (pls ?b ?c)
\<lbrakk>?a \<in> S; ?b \<in> S\<rbrakk> \<Longrightarrow> pls ?a ?b = pls ?b ?a
\<lbrakk>?a \<in> S; ?b \<in> S\<rbrakk> \<Longrightarrow> pls ?a ?b \<in> S
z \<in> S
g ` A \<subseteq> S
goal (1 subgoal):
1. Finite_Set.fold (pls' \<circ> g) z A = Finite_Set.fold (pls \<circ> g) z A
[PROOF STEP]
by (intro fold_closed_eq[where B=S]) auto
|
Set Warnings "-notation-overridden".
Require Import Category.Theory.
Require Import Category.Structure.Monoidal.
Require Import Category.Lib.
Require Import Category.Structure.Monoidal.Proofs.
Require Import Enriched.Category.
Require Import Enriched.Functor.
Require Import Enriched.Forget.Lib.
Generalizable All Variables.
Set Primitive Projections.
Set Universe Polymorphism.
Unset Transparent Obligations.
Section NaturalTransformation.
Context {V0: Category} {V : Monoidal}.
Context {C D : EnrichedCategory}.
Context {F G : C ⟶ D}.
Class EnrichedTransform := {
etransform {x} : I ~> ehom (F x) (G x);
enaturality {x y} :
(postcompose etransform ∘ efmap (EnrichedFunctor:=F) << ehom x y ~~> ehom (F x) (G y) >> precompose etransform ∘ efmap (EnrichedFunctor:=G))%morphism;
}.
End NaturalTransformation.
Bind Scope enriched_transform_scope with EnrichedTransform.
Delimit Scope enriched_transform_type_scope with enriched_transform_type.
Delimit Scope enriched_transform_scope with enriched_transform.
Open Scope enriched_transform_type_scope.
Open Scope enriched_transform_scope.
Notation "F ⟹ G" := (@EnrichedTransform _ _ _ _ F G)
(at level 90, right associativity) : enriched_transform_type_scope.
Coercion etransform : EnrichedTransform >-> Funclass.
Section Equivalence.
Context {V0: Category} {V : Monoidal}.
Context {C D : EnrichedCategory}.
Program Definition enat_equiv {F G : C ⟶ D} : crelation (F ⟹ G) :=
fun n m => ∀ A, n A ≈ m A.
Hint Unfold enat_equiv.
Global Program Definition enat_equiv_equivalence {F G : C ⟶ D} :
Equivalence (@enat_equiv F G).
Proof.
equivalence.
transitivity (y A);auto.
Qed.
Global Program Instance enat_Setoid {F G : C ⟶ D} :
Setoid (F ⟹ G) := {
equiv := enat_equiv;
setoid_equiv := enat_equiv_equivalence
}.
End Equivalence.
Section Compose.
Context {V0: Category} {V : Monoidal}.
Program Definition outside {C D : EnrichedCategory} {F G : C ⟶ D} (a : F ⟹ G)
{E : EnrichedCategory} (H : E ⟶ C) : F ○ H ⟹ G ○ H := {|
etransform := fun _ => etransform (EnrichedTransform:=a)%morphism;
|}.
Next Obligation.
normal.
rewrite enaturality.
reflexivity.
Qed.
Program Definition inside {C D : EnrichedCategory} {F G : C ⟶ D} (a : F ⟹ G)
{E : EnrichedCategory} (H : D ⟶ E) : H ○ F ⟹ H ○ G := {|
etransform := fun _ => (efmap ∘ etransform (EnrichedTransform:=a))%morphism;
|}.
Next Obligation.
normal.
unfold postcompose, precompose.
rewrite (comp_assoc_sym _ unit_left⁻¹).
rewrite <- from_unit_left_natural.
rewrite (comp_assoc_sym _ unit_right⁻¹).
rewrite <- from_unit_right_natural.
normal.
assert ((efmap ∘ a y) ⨂ efmap << I ⨂ ehom (F x) (F y) ~~> ehom (H (F y)) (H (G y)) ⨂ ehom (H (F x)) (H (F y)) >> efmap ⨂ efmap ∘ a y ⨂ id)%morphism.
{
normal.
reflexivity.
}
rewrite X;clear X.
assert (efmap ⨂ (efmap ∘ a x) << ehom (G x) (G y) ⨂ I ~~> ehom (H (G x)) (H (G y)) ⨂ ehom (H (F x)) (H (G x)) >> efmap ⨂ efmap ∘ id ⨂ a x)%morphism.
{
normal.
reflexivity.
}
rewrite X;clear X.
repeat rewrite comp_assoc.
do 2 rewrite efmap_comp.
repeat rewrite comp_assoc_sym.
f_equiv.
repeat rewrite comp_assoc.
fold (postcompose (a y) : ehom (F x) (F y) ~> ehom (F x) (G y)).
fold (precompose (a x) : ehom (G x) (G y) ~> ehom (F x) (G y)).
rewrite enaturality.
reflexivity.
Qed.
Program Definition VerticalComposite {C D : EnrichedCategory} {F G H : C ⟶ D} (b : G ⟹ H) (a : F ⟹ G) : F ⟹ H := {|
etransform := fun _ => ecompose0 (etransform (EnrichedTransform:=b)) (etransform (EnrichedTransform:=a));
|}.
Next Obligation.
rewrite post_comp, pre_comp.
rewrite comp_assoc_sym, enaturality, comp_assoc.
rewrite pre_post_commute.
rewrite comp_assoc_sym, enaturality, comp_assoc.
reflexivity.
Qed.
Global Instance vert_comp_respects {C D : EnrichedCategory} {F G H : C ⟶ D} :
Proper (equiv ==> equiv ==> equiv) (@VerticalComposite C D F G H).
Proof.
proper.
unfold ecompose0.
rewrite (X A).
rewrite (X0 A).
reflexivity.
Qed.
Program Definition enat_id {C D : EnrichedCategory} {F : C ⟶ D} : F ⟹ F := {|
etransform := fun _ => eid
|}.
Next Obligation.
rewrite post_id.
rewrite pre_id.
reflexivity.
Qed.
Lemma vert_comp_id_right {C D : EnrichedCategory} {F G : C ⟶ D} {a : F ⟹ G} : VerticalComposite a enat_id ≈ a.
Proof.
intro.
simpl.
apply ecomp0_id_right.
Qed.
Lemma vert_comp_id_left {C D : EnrichedCategory} {F G : C ⟶ D} {a : F ⟹ G} : VerticalComposite enat_id a ≈ a.
Proof.
intro.
simpl.
apply ecomp0_id_left.
Qed.
Lemma vert_comp_assoc {C D : EnrichedCategory} {F G H K : C ⟶ D} (c : H ⟹ K) (b : G ⟹ H) (a : F ⟹ G) :
VerticalComposite (VerticalComposite c b) a ≈ VerticalComposite c (VerticalComposite b a).
Proof.
intro.
simpl.
apply ecomp0_assoc.
Qed.
Lemma inside_outside {C D E : EnrichedCategory} {F G : C ⟶ D} {H K : D ⟶ E} {a : F ⟹ G} {b : H ⟹ K} : VerticalComposite (outside b G) (inside a H) ≈ VerticalComposite (inside a K) (outside b F).
Proof.
intro.
simpl.
rewrite ecompose0_postcompose.
rewrite ecompose0_precompose.
normal.
rewrite <- enaturality.
reflexivity.
Qed.
Definition HorizontalComposite {C D E : EnrichedCategory} {F G : C ⟶ D} {H K : D ⟶ E} (b : H ⟹ K) (a : F ⟹ G) : H ○ F ⟹ K ○ G := VerticalComposite (outside b G) (inside a H).
Lemma outside_id {C D E : EnrichedCategory} {F : C ⟶ D} {G : D ⟶ E} : outside enat_id F ≈ enat_id.
Proof.
intro.
simpl.
reflexivity.
Qed.
Lemma inside_id {C D E : EnrichedCategory} {F : C ⟶ D} {G : E ⟶ C} : inside enat_id F ≈ enat_id.
Proof.
intro.
simpl.
apply efmap_id.
Qed.
Lemma outside_vertical {C D E : EnrichedCategory} {F G H : C ⟶ D} {K : E ⟶ C} {a : F ⟹ G} {b : G ⟹ H} : outside (VerticalComposite b a) K ≈ VerticalComposite (outside b K) (outside a K).
Proof.
intro.
simpl.
reflexivity.
Qed.
Lemma inside_vertical {C D E : EnrichedCategory} {F G H : C ⟶ D} {K : D ⟶ E} {a : F ⟹ G} {b : G ⟹ H} : inside (VerticalComposite b a) K ≈ VerticalComposite (inside b K) (inside a K).
Proof.
intro.
simpl.
apply efmap_comp0.
Qed.
Lemma interchange_law {C D E : EnrichedCategory} {F G H : C ⟶ D} {K L M : D ⟶ E} {a : F ⟹ G} {b : G ⟹ H} {c : K ⟹ L} {d : L ⟹ M}
: HorizontalComposite (VerticalComposite d c) (VerticalComposite b a) ≈ VerticalComposite (HorizontalComposite d b) (HorizontalComposite c a).
Proof.
unfold HorizontalComposite.
rewrite outside_vertical.
rewrite inside_vertical.
rewrite vert_comp_assoc.
rewrite <- (vert_comp_assoc (outside c H)).
rewrite inside_outside.
repeat rewrite vert_comp_assoc.
reflexivity.
Qed.
(*
Lemma hori_comp_id_right {C D : EnrichedCategory} {F G : C ⟶ D} {a : F ⟹ G} : HorizontalComposite a enat_id ≈ a.
*)
End Compose.
Notation "F ⊙ G" := (VerticalComposite F G) (at level 40, left associativity) : enriched_category_scope.
|
# ***Introduction to Radar Using Python and MATLAB***
## Andy Harrison - Copyright (C) 2019 Artech House
<br/>
# Burn-through Range
***
For an escort type jammer, the burn-through range may be expressed as (Equation 11.20)
\begin{equation}\label{eq:burn_escort}
r_b = \left[ {JSR}_0\, \frac{P_t\, G_t^2 \,\sigma\, r_j^2 \,B_j}{{ERP}\, \, G_r \,4 \,\pi \,B_r \,L_r}\right]^{1/4} \hspace{0.5in} \text{(m)},
\end{equation}
and for a self-screening type jammer (Equation 11.21)
\begin{equation}\label{eq:burn_self}
r_b = \sqrt{{JSR}_0\, \frac{P_t\, G_t^2 \,\sigma \,B_j}{{ERP}\, \, G_r \,4 \,\pi \,B_r \,L_r}} \hspace{0.5in} \text{(m)}
\end{equation}
***
Begin by getting the library path
```python
import lib_path
```
Set the jammer effective radiated power (dBW)
```python
jammer_erp = [20, 40]
```
Import the `linspace` routine from `scipy` for create the jammer ERP array
```python
from numpy import linspace
jammer_erp_vector = linspace(float(jammer_erp[0]), float(jammer_erp[1]), 1000)
```
Set the peak power (W), the antenna gain (dB), the target RCS (dBsm), the jammer bandwidth (Hz), the radar bandwidth (Hz), the losses (dB), and the required jammer to signal ratio (dB)
```python
peak_power = 100e3
antenna_gain = 25.0
target_rcs = -5.0
jammer_bandwidth = 20e6
radar_bandwidth = 23.5e6
losses = 4.0
jammer_to_signal_req = 12.0
```
Set up the keyword args
```python
kwargs = {'peak_power': peak_power,
'antenna_gain': 10 ** (antenna_gain / 10.0),
'target_rcs': 10 ** (target_rcs / 10.0),
'jammer_bandwidth': jammer_bandwidth,
'effective_radiated_power': 10 ** (jammer_erp_vector / 10),
'radar_bandwidth': radar_bandwidth,
'losses': 10 ** (losses / 10.0),
'jammer_to_signal_req': 10 ** (jammer_to_signal_req / 10.0)}
```
Import the `burn_through_range_selfscreen` routine from `countermeasures`
```python
from Libs.ecm.countermeasures import burn_through_range_selfscreen
```
Calculate the burn-through range for the self-screening type jammer (m)
```python
burnthrough_range = burn_through_range_selfscreen(**kwargs)
```
Import the `matplotlib` routines for plotting the burn-through range for a self-screening type jammer
```python
from matplotlib import pyplot as plt
```
Display the results
```python
# Set the figure size
plt.rcParams["figure.figsize"] = (15, 10)
# Display the results
plt.plot(jammer_erp_vector, burnthrough_range, '')
# Set the plot title and labels
plt.title('Burn Through Range', size=14)
plt.xlabel('Jammer ERP (dBW)', size=12)
plt.ylabel('Burn Through Range (m)', size=12)
# Turn on the grid
plt.grid(linestyle=':', linewidth=0.5)
# Set the tick label size
plt.tick_params(labelsize=12)
```
Set the jammer range (m) and antenna gain in the direction of the jammer (dB) for an escort type jammer
```python
jammer_range = 10e3
antenna_gain_jammer_direction = 10.0
```
Set up the keyword args
```python
kwargs = {'peak_power': peak_power,
'antenna_gain': 10 ** (antenna_gain / 10.0),
'target_rcs': 10 ** (target_rcs / 10.0),
'jammer_range': jammer_range,
'jammer_bandwidth': jammer_bandwidth,
'effective_radiated_power': 10 ** (jammer_erp_vector / 10),
'radar_bandwidth': radar_bandwidth,
'losses': 10 ** (losses / 10.0),
'antenna_gain_jammer_direction': 10 ** (antenna_gain_jammer_direction / 10.0),
'jammer_to_signal_req': 10 ** (jammer_to_signal_req / 10.0)}
```
Import the `burn_through_range_escort` routine from `countermeasures`
```python
from Libs.ecm.countermeasures import burn_through_range_escort
```
Calculate the burn-through range for an escort type jammer (m)
```python
burnthrough_range = burn_through_range_escort(**kwargs)
```
Display the results
```python
# Set the figure size
plt.rcParams["figure.figsize"] = (15, 10)
plt.plot(jammer_erp_vector, burnthrough_range, '')
# Set the plot title and labels
plt.title('Burn Through Range', size=14)
plt.xlabel('Jammer ERP (dBW)', size=12)
plt.ylabel('Burn Through Range (m)', size=12)
# Turn on the grid
plt.grid(linestyle=':', linewidth=0.5)
# Set the tick label size
plt.tick_params(labelsize=12)
```
|
using Multigraphs: Multigraph
import ZXCalculus
using ZXCalculus: ZXDiagram, SpiderType, add_spider!, Phase
function ZXCalculus.ZXDiagram(nin::Integer, nout::Integer)
N = nin + nout
mg = Multigraph(nin + nout)
st = vcat([SpiderType.In for _ = 1:nin], [SpiderType.Out for _ = 1:nout])
ps = [Phase(0//1) for _ = 1:N]
zxd = ZXDiagram(mg, st, ps)
sort!(zxd.inputs)
sort!(zxd.outputs)
return zxd
end
function ZXCalculus.ZXDiagram(q::Tait)
simplify!(q, Rule(:genus_fusion))
nin = length(q.inputs)
nout = length(q.outputs)
zxd = ZXDiagram(nin, nout)
v_map = Dict{Int, Int}()
for i = 1:nin
v_map[q.inputs[i]] = i
end
for i = 1:nout
v_map[q.outputs[i]] = i + nin
end
for v in vertices(q)
haskey(v_map, v) && continue
is_genus(q, v) && continue
v_map[v] = add_spider!(zxd, SpiderType.Z)
end
he_map = Dict{Int, Int}()
for he in half_edges(q)
he_twin = twin(q, he)
s = src(q, he)
d = dst(q, he)
if !haskey(he_map, he)
if haskey(q.quon_params, he)
p = quon_param(q, he)
if is_genus(q, s) || is_genus(q, d)
v_z = v_map[is_genus(q, s) ? d : s]
if real(p.param) == 0
if !is_parallel(p)
zxd.ps[v_z] += imag(p.param) / pi
he_map[he] = v_z
he_map[he_twin] = v_z
else
v_x = add_spider!(zxd, SpiderType.X, Phase(imag(p.param) / pi), [v_z])
he_map[he] = v_x
he_map[he_twin] = v_x
end
else # the parameter is not pure imag number
p1 = QuonParam{QuonComplex}(real(p.param) + pi/2*im, is_parallel(p))
p2 = QuonParam{QuonComplex}(imag(p.param) - pi/2*im, is_parallel(p))
p1 = change_direction(p1)
if !is_parallel(p1)
zxd.ps[v_z] += imag(p1.param) / pi
he_map[he] = v_z
he_map[he_twin] = v_z
else
v_x = add_spider!(zxd, SpiderType.X, Phase(imag(p1.param) / pi), [v_z])
he_map[he] = v_x
he_map[he_twin] = v_x
end
if !is_parallel(p2)
zxd.ps[v_z] += imag(p2.param) / pi
he_map[he] = v_z
he_map[he_twin] = v_z
else
v_x = add_spider!(zxd, SpiderType.X, Phase(imag(p2.param) / pi), [v_z])
he_map[he] = v_x
he_map[he_twin] = v_x
end
end
else
if real(p.param) == 0
if is_parallel(p)
v_x = add_spider!(zxd, SpiderType.X, Phase(imag(p.param) / pi), [v_map[s], v_map[d]])
he_map[he] = v_x
he_map[he_twin] = v_x
else
v_x = add_spider!(zxd, SpiderType.X, Phase(0//1), [v_map[s], v_map[d]])
v_z = add_spider!(zxd, SpiderType.Z, Phase(imag(p.param) / pi), [v_x])
he_map[he] = v_z
he_map[he_twin] = v_z
end
else # the parameter is not pure imag number
p1 = QuonParam{QuonComplex}(real(p.param) + pi/2*im, is_parallel(p))
p2 = QuonParam{QuonComplex}(imag(p.param) - pi/2*im, is_parallel(p))
p1 = change_direction(p1)
if is_parallel(p1)
v_x = add_spider!(zxd, SpiderType.X, Phase(imag(p1.param) / pi), [v_map[s], v_map[d]])
v_z = add_spider!(zxd, SpiderType.Z, Phase(imag(p2.param) / pi), [v_x])
he_map[he] = v_x
he_map[he_twin] = v_x
else
v_x = add_spider!(zxd, SpiderType.X, Phase(imag(p2.param) / pi), [v_map[s], v_map[d]])
v_z = add_spider!(zxd, SpiderType.Z, Phase(imag(p1.param) / pi), [v_x])
he_map[he] = v_z
he_map[he_twin] = v_z
end
end
end
else
if !(is_genus(q, s) || is_genus(q, d))
ZXCalculus.add_edge!(zxd, v_map[s], v_map[d])
he_map[he] = v_map[s]
he_map[he_twin] = v_map[d]
end
end
end
end
return zxd
end
|
!> 计算光滑函数 Wij 及其倒数 dWdxij 的子例程
!> subroutine to calculate the smoothing kernel wij and its
!> derivatives dwdxij.
subroutine kernel(r, dx, hsml, w, dwdx)
use sph_kind, only: rk
use parameter
implicit none
!> 粒子 i 和 j 之间的距离
!> distance between particles i and j
real(rk), intent(in) :: r
!> 粒子 i 和 j 之间的坐标差
!> x-, y- and z-distance between i and j
real(rk), intent(in) :: dx(dim)
!> 粒子的光滑长度
!> smoothing length
real(rk), intent(in) :: hsml
!> 给定相互作用对的光滑核函数
!> kernel for all interaction pairs
real(rk), intent(out) :: w
!> 核函数对 x, y, z 的导数
!> derivative of kernel with respect to x, y and z
real(rk), intent(out) :: dwdx(dim)
integer :: i, j, d
real(rk) :: q, dw, factor
q = r/hsml
w = 0._rk
do d = 1, dim
dwdx(d) = 0._rk
end do
if (skf == 1) then
if (dim == 1) then
factor = 1._rk/hsml
else if (dim == 2) then
factor = 15._rk/(7._rk*pi*hsml*hsml)
else if (dim == 3) then
factor = 3._rk/(2._rk*pi*hsml*hsml*hsml)
else
print *, ' >>> error <<< : wrong dimension: dim =', dim
stop
end if
if (q >= 0 .and. q <= 1._rk) then
w = factor*(2._rk/3._rk - q*q + q**3._rk/2._rk)
do d = 1, dim
dwdx(d) = factor*(-2._rk + 3._rk/2._rk*q)/hsml**2*dx(d)
end do
else if (q > 1._rk .and. q <= 2) then
w = factor*1._rk/6._rk*(2._rk - q)**3
do d = 1, dim
dwdx(d) = -factor*1._rk/6._rk*3.*(2._rk - q)**2/hsml*(dx(d)/r)
end do
else
w = 0._rk
do d = 1, dim
dwdx(d) = 0._rk
end do
end if
else if (skf == 2) then
factor = 1._rk/(hsml**dim*pi**(dim/2._rk))
if (q >= 0 .and. q <= 3) then
w = factor*exp(-q*q)
do d = 1, dim
dwdx(d) = w*(-2._rk*dx(d)/hsml/hsml)
end do
else
w = 0._rk
do d = 1, dim
dwdx(d) = 0._rk
end do
end if
else if (skf == 3) then
if (dim == 1) then
factor = 1._rk/(120._rk*hsml)
else if (dim == 2) then
factor = 7._rk/(478._rk*pi*hsml*hsml)
else if (dim == 3) then
factor = 1._rk/(120._rk*pi*hsml*hsml*hsml)
else
print *, ' >>> error <<< : wrong dimension: dim =', dim
stop
end if
if (q >= 0 .and. q <= 1) then
w = factor*((3 - q)**5 - 6*(2 - q)**5 + 15*(1 - q)**5)
do d = 1, dim
dwdx(d) = factor*((-120 + 120*q - 50*q**2)/hsml**2*dx(d))
end do
else if (q > 1 .and. q <= 2) then
w = factor*((3 - q)**5 - 6*(2 - q)**5)
do d = 1, dim
dwdx(d) = factor*(-5*(3 - q)**4 + 30*(2 - q)**4)/hsml*(dx(d)/r)
end do
else if (q > 2 .and. q <= 3) then
w = factor*(3 - q)**5
do d = 1, dim
dwdx(d) = factor*(-5*(3 - q)**4)/hsml*(dx(d)/r)
end do
else
w = 0._rk
do d = 1, dim
dwdx(d) = 0._rk
end do
end if
end if
end subroutine kernel
|
@testset "B-splines" begin
include("knot_sets.jl")
include("splines.jl")
include("operators.jl")
include("derivatives.jl")
end
|
lemma Cauchy_theorem_null_homotopic: "\<lbrakk>f holomorphic_on S; open S; valid_path g; homotopic_loops S g (linepath a a)\<rbrakk> \<Longrightarrow> (f has_contour_integral 0) g"
|
# Windows:
# set JULIA_NUM_THREADS=4
# Linux:
# export JULIA_NUM_THREADS=4
using Random
Threads.nthreads()
Threads.@threads for i in 1:10
println("i = $i on thread $(Threads.threadid())")
end
Threads.@threads for i in 1:10
println(Threads.threadid()=>pointer_from_objref(Random.default_rng()))
end
function fib1(n)
if n < 2
return n
end
return fib1(n - 1) + fib1(n - 2)
end
function fib2(n)
if n < 2
return n
end
t = Threads.@spawn fib2(n - 2)
return fib2(n - 1) + fetch(t)
end
function fib3(n, cutoff)
if n < cutoff
return fib1(n)
end
t = Threads.@spawn fib3(n - 2, cutoff)
return fib3(n - 1, cutoff) + fetch(t)
end
fib1(31)
fib2(31)
fib3(31, 28)
@time fib1(31)
@time fib2(31)
@time fib3(31, 28)
@time fib1(43)
@time fib3(43, 40)
function f_bad(n)
x = 0
Threads.@threads for i in 1:n
x += rand() < 0.5
end
x / n
end
function f_good_slow1(n)
r = ReentrantLock()
x = 0
Threads.@threads for i in 1:n
lock(r)
x += rand() < 0.5
unlock(r)
end
x / n
end
function f_good_slow2(n)
x = Threads.Atomic{Int}(0)
Threads.@threads for i in 1:n
Threads.atomic_add!(x, Int(rand() < 0.5))
end
x[] / n
end
function f_good_slow3(n)
x = zeros(Int, Threads.nthreads())
Threads.@threads for i in 1:n
@inbounds x[Threads.threadid()] += rand() < 0.5
end
sum(x) / n
end
function f_good_slow4(n)
x = zeros(Int, 4*Threads.nthreads())
Threads.@threads for i in 1:n
@inbounds x[4*Threads.threadid()] += rand() < 0.5
end
sum(x) / n
end
function f_good_fast1(n)
nt = Threads.nthreads()
x = zeros(Int, nt)
Threads.@threads for i in 1:nt
tid = Threads.threadid()
v = 0
for j in 1:(div(n, nt) + (tid <= mod(n, nt)))
v += rand() < 0.5
end
x[tid] = v
end
sum(x) / n
end
function f_good_fast2(n)
nt = Threads.nthreads()
x = 0
r = ReentrantLock()
Threads.@threads for i in 1:nt
tid = Threads.threadid()
v = 0
for j in 1:(div(n, nt) + (tid <= mod(n, nt)))
v += rand() < 0.5
end
lock(r)
x += v
unlock(r)
end
x / n
end
f_bad(10^8)
f_good_slow1(10^6)
f_good_slow2(10^8)
f_good_slow3(10^8)
f_good_slow4(10^8)
f_good_fast1(10^8)
f_good_fast2(10^8)
@time f_bad(10^8)
@time f_good_slow1(10^6)
@time f_good_slow2(10^8)
@time f_good_slow3(10^8)
@time f_good_slow4(10^8)
@time f_good_fast1(10^8)
@time f_good_fast2(10^8)
|
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*
*/
#include "qpid/client/MessageReplayTracker.h"
#include <boost/bind.hpp>
namespace qpid {
namespace client {
MessageReplayTracker::MessageReplayTracker(uint f) : flushInterval(f), count(0) {}
void MessageReplayTracker::send(const Message& message, const std::string& destination)
{
buffer.push_back(ReplayRecord(message, destination));
buffer.back().send(*this);
if (flushInterval && (++count % flushInterval == 0)) {
checkCompletion();
if (!buffer.empty()) session.flush();
}
}
void MessageReplayTracker::init(AsyncSession s)
{
session = s;
}
void MessageReplayTracker::replay(AsyncSession s)
{
session = s;
std::for_each(buffer.begin(), buffer.end(), boost::bind(&ReplayRecord::send, _1, boost::ref(*this)));
session.flush();
count = 0;
}
void MessageReplayTracker::setFlushInterval(uint f)
{
flushInterval = f;
}
uint MessageReplayTracker::getFlushInterval()
{
return flushInterval;
}
void MessageReplayTracker::checkCompletion()
{
buffer.remove_if(boost::bind(&ReplayRecord::isComplete, _1));
}
MessageReplayTracker::ReplayRecord::ReplayRecord(const Message& m, const std::string& d) : message(m), destination(d) {}
void MessageReplayTracker::ReplayRecord::send(MessageReplayTracker& tracker)
{
status = tracker.session.messageTransfer(arg::destination=destination, arg::content=message);
}
bool MessageReplayTracker::ReplayRecord::isComplete()
{
return status.isComplete();
}
}} // namespace qpid::client
|
# Test clusters sizes read and fit
hkBin <- "~/Dropbox/cpp/SpatialAnalysis/Clusters/hk"
meta <- "L"
Repl <- 0.0002
p <-expand.grid(MetaType=meta,Repl=ReplRate)
if(toupper(p$MetaType[i])=="L") {
bname <- paste0("neuFish",nsp,"_",side,"R", p$Repl[i])
} else {
bname <- paste0("neuUnif",nsp,"_",side,"R", p$Repl[i])
}
fname <- paste0(bname,"-",formatC(time,width=4,flag=0),".sed")
## assume the last is the one with sed
#
clu <-readClusterOut(bname)
spanSp <- clu$SpanningSpecies[nrow(clu)]
if(spanSp==0) # No tiene spanning cluster
|
State Before: 𝕜 : Type u_1
inst✝⁶ : NontriviallyNormedField 𝕜
E : Type u_2
inst✝⁵ : NormedAddCommGroup E
inst✝⁴ : NormedSpace 𝕜 E
F : Type u_4
inst✝³ : NormedAddCommGroup F
inst✝² : NormedSpace 𝕜 F
G : Type u_3
inst✝¹ : NormedAddCommGroup G
inst✝ : NormedSpace 𝕜 G
f✝ : E × F → G
f : E →L[𝕜] F →L[𝕜] G
x : E
y : F
⊢ ‖f‖ * ‖x‖ * ‖y‖ ≤ max ‖f‖ 1 * ‖x‖ * ‖y‖ State After: no goals Tactic: apply_rules [mul_le_mul_of_nonneg_right, norm_nonneg, le_max_left]
|
Pattycake was brought to New York Medical College for surgery and she was given a cast for her arm . Due to concerns that Lulu would try to remove Pattycake 's cast , she was separated from her mother and moved to the Bronx Zoo for convalescence . Pattycake was treated by veterinarian Emil <unk> who later replaced her cast with a sling . After an examination , the staff discovered that Pattycake had intestinal parasites and determined she was underfed . They also believed that as a result of the incident , Lulu wasn 't capable as a mother .
|
module Inigo.Async.FS
import Inigo.Async.Promise
import Inigo.Async.Util
import Data.Buffer
import Extra.Buffer
import System.Path
%foreign (promisifyPrim "(path)=>require('fs').promises.readFile(path,'utf8')")
fs_readFile__prim : String -> promise String
%foreign (promisifyPrim "(path)=>require('fs').promises.readFile(path)")
fs_readFileBuf__prim : String -> promise Buffer
%foreign (promisifyPrim "(path,contents)=>require('fs').promises.writeFile(path,contents)")
fs_writeFile__prim : String -> String -> promise ()
%foreign (promisifyPrim "(path,contents)=>require('fs').promises.writeFile(path,contents)")
fs_writeFileBuf__prim : String -> Buffer -> promise ()
%foreign (promisifyPrim "(path,r)=>require('fs').promises.mkdir(path,{recursive: r === 1})")
fs_mkdir__prim : String -> Int -> promise ()
%foreign (promisifyPrim "(path,r)=>require('fs').promises.rmdir(path,{recursive: r === 1})")
fs_rmdir__prim : String -> Int -> promise ()
%foreign (promisifyPrim "(path)=>require('fs').promises.readdir(path).then(__prim_js2idris_array)")
fs_getFiles__prim : String -> promise (List String)
%foreign (promisifyPrim "(path)=>require('fs').promises.stat(path).then((s)=>s.isDirectory() ? 1 : 0)")
fs_isDir__prim : String -> promise Int
%foreign (promisifyPrim "(path)=>require('fs').promises.access(path).then(()=>1).catch(()=>0)")
fs_exists__prim : String -> promise Int
export
fs_readFile : String -> Promise String
fs_readFile path =
promisify (fs_readFile__prim path)
export
fs_writeFile : String -> String -> Promise ()
fs_writeFile path contents =
promisify (fs_writeFile__prim path contents)
export
fs_readFileBuf : String -> Promise Buffer
fs_readFileBuf path =
promisify (fs_readFileBuf__prim path)
export
fs_writeFileBuf : String -> Buffer -> Promise ()
fs_writeFileBuf path contents =
promisify (fs_writeFileBuf__prim path contents)
export
fs_mkdir : Bool -> String -> Promise ()
fs_mkdir recursive path =
promisify (fs_mkdir__prim path (boolToInt recursive))
export
fs_rmdir : Bool -> String -> Promise ()
fs_rmdir recursive path =
promisify (fs_rmdir__prim path (boolToInt recursive))
export
fs_getFiles : String -> Promise (List String)
fs_getFiles path =
promisify (fs_getFiles__prim path)
export
fs_isDir : String -> Promise Bool
fs_isDir path =
intToBool <$> promisify (fs_isDir__prim path)
export
fs_exists : String -> Promise Bool
fs_exists path =
intToBool <$> promisify (fs_exists__prim path)
export
fs_getFilesR : String -> Promise (List String)
fs_getFilesR path =
doGetFilesR path
where
doGetFilesR : String -> Promise (List String)
doGetFilesR path =
do
isDir <- fs_isDir path
if isDir
then do
entries <- fs_getFiles path
let fullEntries = map (path </>) entries
allFiles <- all (map doGetFilesR fullEntries)
pure (concat allFiles)
else
pure [path]
|
function Table_SINDY_PI(s, epsilon, npoly, ntrig, w)
nvar = length(s)
table = []
#push!(table, "")
push!(table, "1")
if npoly >=1
for i in 1:nvar
push!(table, s[i])
end
end
if npoly >= 2
for i in 1:nvar
for j in i:nvar
push!(table, string(s[i], s[j]))
end
end
end
if npoly >= 3
for i in 1:nvar
for j in i:nvar
for k in j:nvar
push!(table, string(s[i], s[j], s[k]))
end
end
end
end
if npoly >= 4
for i in 1:nvar
for j in i:nvar
for k in j:nvar
for l in k:nvar
push!(table, string(s[i], s[j], s[k], s[l]))
end
end
end
end
end
if npoly >= 5
for i in 1:nvar
for j in i:nvar
for k in j:nvar
for l in k:nvar
for m in l:nvar
push!(table, string(s[i], s[j], s[k], s[l], s[m]))
end
end
end
end
end
end
if npoly >= 6
for i in 1:nvar
for j in i:nvar
for k in j:nvar
for l in k:nvar
for m in l:nvar
for n in m:nvar
push!(table, string(s[i], s[j], s[k], s[l], s[m], s[n]))
end
end
end
end
end
end
end
if ntrig >=1
for i in 1:nvar
push!(table, string("sin", "", s[i]))
end
for i in 1:nvar
push!(table, string("cos", "", s[i]))
end
end
if ntrig >=2
for i in 1:nvar
push!(table, string("cos^{2}", "", s[i]))
end
end
if ntrig >=3
for i in 1:nvar
for j in 1:nvar
push!(table, string(s[i], "*", s[i], "sin", "", s[j], "cos", "", s[j]))
end
end
end
if ntrig >=4
for i in 1:nvar
for j in 1:nvar
push!(table, string(s[i], "*", s[i], "sin", "", s[j]))
end
end
for i in 1:nvar
for j in 1:nvar
push!(table, string(s[i], "*", s[i], "cos", "", s[j]))
end
end
for i in 1:nvar
for j in 1:nvar
push!(table, string("sin", "", s[i], "cos", "", s[j]))
end
end
end
tablecopy = deepcopy(table)
for i in 1:length(table)-1
push!(table, string("dot", "(", s[w], ")" , "", tablecopy[i+1]))
end
table = hcat(table, epsilon)
return table
end
|
(* *********************************************************************)
(* *)
(* The Compcert verified compiler *)
(* *)
(* Xavier Leroy, INRIA Paris-Rocquencourt *)
(* *)
(* Copyright Institut National de Recherche en Informatique et en *)
(* Automatique. All rights reserved. This file is distributed *)
(* under the terms of the GNU General Public License as published by *)
(* the Free Software Foundation, either version 2 of the License, or *)
(* (at your option) any later version. This file is also distributed *)
(* under the terms of the INRIA Non-Commercial License Agreement. *)
(* *)
(* *********************************************************************)
(** Defining recursive functions by Noetherian induction. This is a simplified
interface to the [Wf] module of Coq's standard library, where the functions
to be defined have non-dependent types, and function extensionality is assumed. *)
Require Import Axioms.
Require Import Init.Wf.
Require Import Wf_nat.
Set Implicit Arguments.
Section FIX.
Variables A B: Type.
Variable R: A -> A -> Prop.
Hypothesis Rwf: well_founded R.
Variable F: forall (x: A), (forall (y: A), R y x -> B) -> B.
Definition Fix (x: A) : B := Wf.Fix Rwf (fun (x: A) => B) F x.
Theorem unroll_Fix:
forall x, Fix x = F (fun (y: A) (P: R y x) => Fix y).
Proof.
unfold Fix; intros. apply Wf.Fix_eq with (P := fun (x: A) => B).
intros. assert (f = g). apply functional_extensionality_dep; intros.
apply functional_extensionality; intros. auto.
subst g; auto.
Qed.
End FIX.
(** Same, with a nonnegative measure instead of a well-founded ordering *)
Section FIXM.
Variables A B: Type.
Variable measure: A -> nat.
Variable F: forall (x: A), (forall (y: A), measure y < measure x -> B) -> B.
Definition Fixm (x: A) : B := Wf.Fix (well_founded_ltof A measure) (fun (x: A) => B) F x.
Theorem unroll_Fixm:
forall x, Fixm x = F (fun (y: A) (P: measure y < measure x) => Fixm y).
Proof.
unfold Fixm; intros. apply Wf.Fix_eq with (P := fun (x: A) => B).
intros. assert (f = g). apply functional_extensionality_dep; intros.
apply functional_extensionality; intros. auto.
subst g; auto.
Qed.
End FIXM.
|
include defs
# lower - fold all letters to lower case
subroutine lower (token)
character token (ARB)
call fold (token)
return
end
|
[STATEMENT]
lemma bisimCoinduct[case_names cSim cSym , consumes 1]:
assumes p: "(P, Q) \<in> X"
and rSim: "\<And>R S. (R, S) \<in> X \<Longrightarrow> R \<leadsto>[(X \<union> bisim)] S"
and rSym: "\<And>R S. (R, S) \<in> X \<Longrightarrow> (S, R) \<in> X"
shows "P \<sim> Q"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. P \<sim> Q
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. P \<sim> Q
[PROOF STEP]
have aux: "X \<union> bisim = {(P, Q). (P, Q) \<in> X \<or> P \<sim> Q}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. X \<union> bisim = {(P, Q). (P, Q) \<in> X \<or> P \<sim> Q}
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
X \<union> bisim = {(P, Q). (P, Q) \<in> X \<or> P \<sim> Q}
goal (1 subgoal):
1. P \<sim> Q
[PROOF STEP]
from p
[PROOF STATE]
proof (chain)
picking this:
(P, Q) \<in> X
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(P, Q) \<in> X
goal (1 subgoal):
1. P \<sim> Q
[PROOF STEP]
apply(coinduct, auto)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
1. \<And>x1 x2. \<lbrakk>(x1, x2) \<in> X; (P, Q) \<in> X\<rbrakk> \<Longrightarrow> x1 \<leadsto>[{(xa, x). (xa, x) \<in> X \<or> xa \<sim> x}] x2
2. \<And>x1 x2. \<lbrakk>(x1, x2) \<in> X; (P, Q) \<in> X; (x2, x1) \<notin> bisim\<rbrakk> \<Longrightarrow> (x2, x1) \<in> X
[PROOF STEP]
apply(fastforce dest: rSim simp add: aux)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<And>x1 x2. \<lbrakk>(x1, x2) \<in> X; (P, Q) \<in> X; (x2, x1) \<notin> bisim\<rbrakk> \<Longrightarrow> (x2, x1) \<in> X
[PROOF STEP]
by(fastforce dest: rSym)
[PROOF STATE]
proof (state)
this:
P \<sim> Q
goal:
No subgoals!
[PROOF STEP]
qed
|
lemma scaleR_nonpos_nonneg: "a \<le> 0 \<Longrightarrow> 0 \<le> x \<Longrightarrow> a *\<^sub>R x \<le> 0" for x :: "'a::ordered_real_vector"
|
Require Import compcert.lib.Coqlib.
Require Import List. Import ListNotations.
Require Import compcert.lib.Integers.
Require Import msl.Coqlib2.
Require Import floyd.coqlib3.
Require Import floyd.sublist.
Local Open Scope nat.
Fixpoint map2 {A B C: Type} (f: A -> B -> C) (al: list A) (bl: list B) : list C :=
match al, bl with
| a::al', b::bl' => f a b :: map2 f al' bl'
| _, _ => nil
end.
Lemma length_map2:
forall A B C (f: A -> B -> C) al bl n,
length al = n -> length bl = n ->
length (map2 f al bl) = n.
Proof.
induction al; destruct bl,n; simpl; intros; auto.
inv H.
Qed.
Lemma list_repeat_injective {A} (a a':A) n: (0<n)%nat ->
list_repeat n a = list_repeat n a' -> a=a'.
Proof. intros.
destruct n. omega. simpl in H0. inversion H0. trivial.
Qed.
Local Open Scope Z.
Definition roundup (a b : Z) := (a + (b-1))/b*b.
Lemma roundup_minus:
forall a b, b > 0 -> roundup a b - a = (- a) mod b.
Proof.
unfold roundup; intros.
replace (a+(b-1)) with (a-1+1*b) by omega.
rewrite Z_div_plus_full by omega.
rewrite Z.mul_add_distr_r.
assert (H4 := Zmod_eq a b H).
assert (a mod b = 0 \/ a mod b <> 0) by omega.
destruct H0; [rewrite Z.mod_opp_l_z | rewrite Z.mod_opp_l_nz]; try omega.
rewrite H0 in H4.
assert (a = a/b*b) by omega.
rewrite H1 at 1.
replace (a/b*b-1) with (a/b*b+ -1) by omega.
rewrite Z_div_plus_full_l by omega.
rewrite Z.mul_add_distr_r.
rewrite <- H1.
assert (b=1 \/ b>1) by omega.
destruct H2.
subst b. simpl. omega.
rewrite (Z_div_nz_opp_full 1) by (rewrite Z.mod_small; omega).
rewrite Z.div_small by omega.
omega.
rewrite H4.
assert ( (a-1)/b*b = a/b*b); [ | omega].
f_equal.
assert (a = a mod b + a/b*b) by omega.
replace (a-1) with (a mod b - 1 + a/b*b) by omega.
rewrite Z_div_plus_full by omega.
rewrite Z.div_small; try omega.
pose proof (Z_mod_lt a b H).
omega.
Qed.
Definition isbyteZ (i: Z) := (0 <= i < 256)%Z.
Definition Shr b x := Int.shru x (Int.repr b).
Lemma isbyteZ_testbit:
forall i j, 0 <= i < 256 -> j >= 8 -> Z.testbit i j = false.
Proof.
intros; erewrite Byte.Ztestbit_above with (n:=8%nat); auto.
Qed.
Fixpoint intlist_to_Zlist (l: list int) : list Z :=
match l with
| nil => nil
| i::r =>
Int.unsigned (Shr 24 i) ::
Int.unsigned (Int.and (Shr 16 i) (Int.repr 255)) ::
Int.unsigned (Int.and (Shr 8 i) (Int.repr 255)) ::
Int.unsigned (Int.and i (Int.repr 255)) ::
intlist_to_Zlist r
end.
(*combining four Z into a Integer*)
Definition Z_to_Int (a b c d : Z) : Int.int :=
Int.or (Int.or (Int.or (Int.shl (Int.repr a) (Int.repr 24)) (Int.shl (Int.repr b) (Int.repr 16)))
(Int.shl (Int.repr c) (Int.repr 8))) (Int.repr d).
Fixpoint Zlist_to_intlist (nl: list Z) : list int :=
match nl with
| h1::h2::h3::h4::t => Z_to_Int h1 h2 h3 h4 :: Zlist_to_intlist t
| _ => nil
end.
Lemma int_min_signed_eq: Int.min_signed = -2147483648.
Proof. reflexivity. Qed.
Lemma int_max_signed_eq: Int.max_signed = 2147483647.
Proof. reflexivity. Qed.
Lemma int_max_unsigned_eq: Int.max_unsigned = 4294967295.
Proof. reflexivity. Qed.
Ltac repable_signed :=
pose proof int_min_signed_eq;
pose proof int_max_signed_eq;
pose proof int_max_unsigned_eq;
omega.
Hint Rewrite Int.bits_or using omega : testbit.
Hint Rewrite Int.bits_shl using omega : testbit.
Hint Rewrite Int.bits_and using omega : testbit.
Hint Rewrite Int.bits_shru using omega : testbit.
Hint Rewrite Int.unsigned_repr using omega : testbit.
Hint Rewrite Int.testbit_repr using omega : testbit.
Hint Rewrite if_false using omega : testbit.
Hint Rewrite if_true using omega : testbit.
Hint Rewrite Z.ones_spec_low using omega : testbit.
Hint Rewrite Z.ones_spec_high using omega : testbit.
Hint Rewrite orb_false_r orb_true_r andb_false_r andb_true_r : testbit.
Hint Rewrite orb_false_l orb_true_l andb_false_l andb_true_l : testbit.
Hint Rewrite Z.add_simpl_r : testbit.
Hint Rewrite Int.unsigned_repr using repable_signed : testbit.
Lemma Ztest_Inttest:
forall a, Z.testbit (Int.unsigned a) = Int.testbit a.
Proof. reflexivity. Qed.
Hint Rewrite Ztest_Inttest : testbit.
Definition swap (i: int) : int :=
Int.or (Int.shl (Int.and i (Int.repr 255)) (Int.repr 24))
(Int.or (Int.shl (Int.and (Shr 8 i) (Int.repr 255)) (Int.repr 16))
(Int.or (Int.shl (Int.and (Shr 16 i) (Int.repr 255)) (Int.repr 8))
(Shr 24 i))).
Lemma swap_swap: forall w, swap (swap w) = w.
Proof.
unfold swap, Shr; intros.
apply Int.same_bits_eq; intros.
assert (Int.zwordsize=32) by reflexivity.
change 255 with (Z.ones 8).
assert (32 < Int.max_unsigned) by (compute; auto).
autorewrite with testbit.
if_tac; [if_tac; [if_tac | ] | ]; autorewrite with testbit; f_equal; omega.
Qed.
Lemma map_swap_involutive:
forall l, map swap (map swap l) = l.
Proof. intros.
rewrite map_map.
replace (fun x => swap (swap x)) with (@Datatypes.id int).
apply map_id. extensionality x. symmetry; apply swap_swap.
Qed.
Lemma length_intlist_to_Zlist:
forall l, length (intlist_to_Zlist l) = (4 * length l)%nat.
Proof.
induction l.
simpl. reflexivity. simpl. omega.
Qed.
Lemma intlist_to_Zlist_Z_to_int_cons:
forall a b c d l,
isbyteZ a -> isbyteZ b -> isbyteZ c -> isbyteZ d ->
intlist_to_Zlist (Z_to_Int a b c d :: l) =
a::b::c::d:: intlist_to_Zlist l.
Proof.
intros. simpl.
unfold isbyteZ in *.
assert (Int.zwordsize=32)%Z by reflexivity.
unfold Z_to_Int, Shr; simpl.
change 255%Z with (Z.ones 8).
repeat f_equal; auto;
match goal with |- _ = ?A => transitivity (Int.unsigned (Int.repr A));
[f_equal | apply Int.unsigned_repr; repable_signed]
end;
apply Int.same_bits_eq; intros;
autorewrite with testbit.
*
if_tac; autorewrite with testbit; [ | symmetry; apply isbyteZ_testbit; omega].
rewrite (isbyteZ_testbit b) by omega.
rewrite (isbyteZ_testbit c) by omega.
rewrite (isbyteZ_testbit d) by omega.
autorewrite with testbit; auto.
*
if_tac; autorewrite with testbit; [ | symmetry; apply isbyteZ_testbit; omega].
if_tac; autorewrite with testbit; [ | symmetry; apply isbyteZ_testbit; omega].
rewrite (isbyteZ_testbit c) by omega.
rewrite (isbyteZ_testbit d) by omega.
autorewrite with testbit; auto.
*
if_tac; autorewrite with testbit; [ | symmetry; apply isbyteZ_testbit; omega].
if_tac; autorewrite with testbit; [ | symmetry; apply isbyteZ_testbit; omega].
if_tac; autorewrite with testbit; [ | symmetry; apply isbyteZ_testbit; omega].
rewrite (isbyteZ_testbit d) by omega.
autorewrite with testbit; auto.
*
destruct (zlt i 8); autorewrite with testbit; [ | symmetry; apply isbyteZ_testbit; omega].
auto.
Qed.
Lemma intlist_to_Zlist_to_intlist:
forall il: list int,
Zlist_to_intlist (intlist_to_Zlist il) = il.
Proof.
induction il.
reflexivity.
simpl.
f_equal; auto. clear.
assert (Int.zwordsize=32)%Z by reflexivity.
unfold Z_to_Int, Shr; simpl.
change 255%Z with (Z.ones 8).
apply Int.same_bits_eq; intros.
rewrite Int.repr_unsigned.
autorewrite with testbit.
if_tac; autorewrite with testbit; [ | f_equal; omega].
if_tac; autorewrite with testbit; [ | f_equal; omega].
if_tac; autorewrite with testbit; [ | f_equal; omega].
auto.
Qed.
Lemma intlist_to_Zlist_app:
forall al bl, intlist_to_Zlist (al++bl) = intlist_to_Zlist al ++ intlist_to_Zlist bl.
Proof. intros; induction al; simpl; auto. repeat f_equal; auto. Qed.
Local Open Scope nat.
Local Open Scope Z.
Lemma isbyte_intlist_to_Zlist : forall l, Forall isbyteZ (intlist_to_Zlist l).
Proof.
induction l; simpl; intros.
constructor.
assert (forall i, Int.unsigned (Int.and i (Int.repr 255)) < 256).
clear; intro.
eapply Z.lt_le_trans.
apply (Int.and_interval i (Int.repr (Z.ones 8))).
change (Int.size (Int.repr (Z.ones 8))) with 8.
rewrite Zmin_spec.
if_tac.
eapply Z.le_trans with (two_p 8).
apply two_p_monotone.
split; [ | omega].
apply Int.size_range.
compute; congruence.
compute; congruence.
unfold Shr, isbyteZ; repeat constructor; try apply Int.unsigned_range; auto; clear IHl.
rewrite <- (Int.divu_pow2 a (Int.repr (2 ^ 24)) (Int.repr 24) (eq_refl _)).
unfold Int.divu.
rewrite Int.unsigned_repr.
rewrite Int.unsigned_repr by (compute; split; congruence).
apply Z.div_lt_upper_bound.
compute; congruence.
change (2 ^ 24 * 256)%Z with (Int.modulus).
apply Int.unsigned_range.
assert (0 < 2 ^ 24)
by (apply Z.pow_pos_nonneg; clear; omega).
rewrite Int.unsigned_repr by (compute; split; congruence).
split.
apply Z.div_pos; auto.
apply Int.unsigned_range.
apply Z.div_le_upper_bound; auto.
apply Z.le_trans with (Int.modulus+1).
destruct (Int.unsigned_range a).
omega.
compute; congruence.
Qed.
Lemma isbyte_intlist_to_Zlist' : forall l,
Forall isbyteZ (map Int.unsigned (map Int.repr (intlist_to_Zlist l))).
Proof.
intro.
replace (map Int.unsigned (map Int.repr (intlist_to_Zlist l))) with (intlist_to_Zlist l).
apply isbyte_intlist_to_Zlist.
induction l; simpl; auto.
repeat f_equal; auto; symmetry; apply Int.repr_unsigned.
Qed.
Lemma Forall_isbyte_repr_unsigned:
forall l: list int, map Int.repr (map Int.unsigned l) = l.
Proof.
induction l; intros.
reflexivity.
simpl.
f_equal; auto.
apply Int.repr_unsigned.
Qed.
Lemma map_unsigned_repr_isbyte:
forall l : list Z , Forall isbyteZ l -> map Int.unsigned (map Int.repr l) = l.
Proof. induction l; simpl; intros; auto.
inv H. f_equal; auto. unfold isbyteZ in H2; apply Int.unsigned_repr.
assert (Int.max_unsigned > 256)%Z by (compute; congruence).
omega.
Qed.
Lemma int_unsigned_inj: forall a b, Int.unsigned a = Int.unsigned b -> a=b.
Proof.
intros.
rewrite <- (Int.repr_unsigned a); rewrite <- (Int.repr_unsigned b).
congruence.
Qed.
Lemma intlist_to_Zlist_inj: forall al bl, intlist_to_Zlist al = intlist_to_Zlist bl -> al=bl.
Proof.
induction al; destruct bl; intros; auto.
inv H.
inv H.
simpl in H.
injection H; intros.
f_equal; auto.
clear - H1 H2 H3 H4.
rename i into b.
apply int_unsigned_inj in H1.
apply int_unsigned_inj in H2.
apply int_unsigned_inj in H3.
apply int_unsigned_inj in H4.
unfold Shr in *.
apply Int.same_bits_eq; intros.
assert (Int.zwordsize=32)%Z by reflexivity.
change 255%Z with (Z.ones 8) in *.
destruct (zlt i 8).
transitivity (Int.testbit (Int.and a (Int.repr (Z.ones 8))) i).
autorewrite with testbit; auto.
rewrite H1. autorewrite with testbit; auto.
destruct (zlt i 16).
transitivity (Int.testbit (Int.and (Int.shru a (Int.repr 8)) (Int.repr (Z.ones 8))) (i-8)).
autorewrite with testbit.
change (Int.unsigned (Int.repr 8)) with 8%Z.
rewrite Z.sub_add; auto.
rewrite H2.
autorewrite with testbit.
rewrite Z.sub_add. auto.
destruct (zlt i 24).
transitivity (Int.testbit (Int.and (Int.shru a (Int.repr 16)) (Int.repr (Z.ones 8))) (i-16)).
autorewrite with testbit.
change (Int.unsigned (Int.repr 16)) with 16%Z.
rewrite Z.sub_add. auto.
rewrite H3.
autorewrite with testbit.
change (Int.unsigned (Int.repr 16)) with 16%Z.
rewrite Z.sub_add. auto.
transitivity (Int.testbit (Int.shru a (Int.repr 24)) (i-24)).
autorewrite with testbit.
change (Int.unsigned (Int.repr 24)) with 24%Z.
rewrite Z.sub_add. auto.
rewrite H4.
autorewrite with testbit.
change (Int.unsigned (Int.repr 24)) with 24%Z.
rewrite Z.sub_add. auto.
Qed.
Lemma Zlength_intlist_to_Zlist_app:
forall al bl, Zlength (intlist_to_Zlist (al++bl)) =
(Zlength (intlist_to_Zlist al) + Zlength (intlist_to_Zlist bl))%Z.
Proof.
induction al; simpl; intros; auto.
repeat rewrite Zlength_cons.
rewrite IHal.
omega.
Qed.
Local Open Scope Z.
Lemma Forall_isbyteZ_unsigned_repr:
forall l, Forall isbyteZ l -> Forall isbyteZ (map Int.unsigned (map Int.repr l)).
Proof. induction 1. constructor.
constructor. rewrite Int.unsigned_repr; auto.
unfold isbyteZ in H; repable_signed.
apply IHForall.
Qed.
Lemma divide_length_app:
forall {A} n (al bl: list A),
(n | Zlength al) ->
(n | Zlength bl) ->
(n | Zlength (al++bl)).
Proof.
intros. destruct H,H0. exists (x+x0)%Z.
rewrite Zlength_app,H,H0;
rewrite Z.mul_add_distr_r; omega.
Qed.
Lemma nth_list_repeat: forall A i n (x :A),
nth i (list_repeat n x) x = x.
Proof.
induction i; destruct n; simpl; auto.
Qed.
Lemma map_list_repeat:
forall A B (f: A -> B) n x,
map f (list_repeat n x) = list_repeat n (f x).
Proof. induction n; simpl; intros; f_equal; auto.
Qed.
Lemma isbyteZ_sublist data lo hi: Forall isbyteZ data -> Forall isbyteZ (sublist lo hi data).
Proof. intros. destruct (Forall_forall isbyteZ data) as [F _].
apply Forall_forall. intros. apply (F H x). eapply sublist_In. apply H0.
Qed.
Lemma map_IntReprOfBytes_injective: forall l m, Forall isbyteZ l ->
Forall isbyteZ m -> map Int.repr l = map Int.repr m -> l=m.
Proof. induction l; intros.
+ destruct m; simpl in *; inv H1; trivial.
+ destruct m; simpl in *. inv H1.
assert (Int.repr a = Int.repr z /\ map Int.repr l = map Int.repr m).
{ forget (Int.repr a) as q. forget (Int.repr z) as w. inv H1; split; trivial. }
clear H1. destruct H2. inv H. inv H0.
rewrite (IHl m); trivial. f_equal.
clear IHl H2 H6 H7.
unfold isbyteZ in *. simpl in *.
rewrite <- (Int.unsigned_repr a), <- (Int.unsigned_repr z), H1; trivial;
rewrite int_max_unsigned_eq; omega.
Qed.
|
module tests.Mutual where
open import Prelude.IO
open import Prelude.String
open import Prelude.Unit
mutual
data G : Set where
GA : {g : G}(f : F g) -> G
GB : G
data F : G -> Set where
FA : (g : G) -> F g
FB : F GB
mutual
incG : G -> G
incG GB = GA FB
incG (GA f) = GA (incF f)
incF : {g : G} -> F g -> F (incG g)
incF FB = FA (GA FB)
incF (FA g) = FA (incG g)
mutual
PrintF : {g : G} -> F g -> String
PrintF FB = "FB"
PrintF (FA g) = "(FA " +S+ PrintG g +S+ ")"
PrintG : G -> String
PrintG GB = "GB"
PrintG (GA f) = "(GA " +S+ PrintF f +S+ ")"
main : IO Unit
main =
putStrLn (PrintF (FA (GA (FA GB)))) ,,
putStrLn (PrintG (incG (GA (incF FB)))) ,, --
return unit
|
# Portfolio Optimization using Second Order Cone
In this notebook we show how to use the Second Order Cone (SOC) constraint in the variance portfolio optimization problem.
## 1. Variance Optimization
### 1.1 Variance Minimization
The minimization of portfolio variance is a quadratic optimization problem that can be posed as:
$$
\begin{equation}
\begin{aligned}
& \underset{x}{\text{min}} & & x^{\tau} \Sigma x \\
& \text{s.t.} & & \mu x^{\tau} \geq \bar{\mu} \\
& & & \sum_{i=1}^{N} x_i = 1 \\
& & & x_i \geq 0 \; ; \; \forall \; i =1, \ldots, N \\
\end{aligned}
\end{equation}
$$
Where $x$ are the weights of assets, $\mu$ is the mean vector of expected returns and $\bar{\mu}$ the minimum expected return of portfolio.
```python
####################################
# Downloading Data
####################################
!pip install --quiet yfinance
import numpy as np
import pandas as pd
import yfinance as yf
import warnings
warnings.filterwarnings("ignore")
yf.pdr_override()
pd.options.display.float_format = '{:.4%}'.format
# Date range
start = '2016-01-01'
end = '2019-12-30'
# Tickers of assets
assets = ['JCI', 'TGT', 'CMCSA', 'CPB', 'MO', 'APA', 'MMC', 'JPM',
'ZION', 'PSA', 'BAX', 'BMY', 'LUV', 'PCAR', 'TXT', 'TMO',
'DE', 'MSFT', 'HPQ', 'SEE', 'VZ', 'CNP', 'NI', 'T', 'BA']
assets.sort()
# Downloading data
data = yf.download(assets, start = start, end = end)
data = data.loc[:,('Adj Close', slice(None))]
data.columns = assets
# Calculating returns
Y = data[assets].pct_change().dropna()
display(Y.head())
```
[*********************100%***********************] 25 of 25 completed
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>APA</th>
<th>BA</th>
<th>BAX</th>
<th>BMY</th>
<th>CMCSA</th>
<th>CNP</th>
<th>CPB</th>
<th>DE</th>
<th>HPQ</th>
<th>JCI</th>
<th>...</th>
<th>NI</th>
<th>PCAR</th>
<th>PSA</th>
<th>SEE</th>
<th>T</th>
<th>TGT</th>
<th>TMO</th>
<th>TXT</th>
<th>VZ</th>
<th>ZION</th>
</tr>
<tr>
<th>Date</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<th>2016-01-05</th>
<td>-2.0257%</td>
<td>0.4057%</td>
<td>0.4036%</td>
<td>1.9693%</td>
<td>0.0180%</td>
<td>0.9305%</td>
<td>0.3678%</td>
<td>0.5783%</td>
<td>0.9483%</td>
<td>-1.1953%</td>
<td>...</td>
<td>1.5881%</td>
<td>0.0212%</td>
<td>2.8236%</td>
<td>0.9758%</td>
<td>0.6987%</td>
<td>1.7539%</td>
<td>-0.1730%</td>
<td>0.2410%</td>
<td>1.3735%</td>
<td>-1.0857%</td>
</tr>
<tr>
<th>2016-01-06</th>
<td>-11.4863%</td>
<td>-1.5878%</td>
<td>0.2412%</td>
<td>-1.7557%</td>
<td>-0.7727%</td>
<td>-1.2473%</td>
<td>-0.1736%</td>
<td>-1.1239%</td>
<td>-3.5867%</td>
<td>-0.9551%</td>
<td>...</td>
<td>0.5547%</td>
<td>0.0212%</td>
<td>0.1592%</td>
<td>-1.5647%</td>
<td>-0.1466%</td>
<td>-1.0155%</td>
<td>-0.7653%</td>
<td>-3.0048%</td>
<td>-0.9034%</td>
<td>-2.9145%</td>
</tr>
<tr>
<th>2016-01-07</th>
<td>-5.1388%</td>
<td>-4.1922%</td>
<td>-1.6573%</td>
<td>-2.7699%</td>
<td>-1.1047%</td>
<td>-1.9769%</td>
<td>-1.2207%</td>
<td>-0.8855%</td>
<td>-4.6059%</td>
<td>-2.5394%</td>
<td>...</td>
<td>-2.2066%</td>
<td>-3.0309%</td>
<td>-1.0410%</td>
<td>-3.1557%</td>
<td>-1.6148%</td>
<td>-0.2700%</td>
<td>-2.2845%</td>
<td>-2.0570%</td>
<td>-0.5492%</td>
<td>-3.0020%</td>
</tr>
<tr>
<th>2016-01-08</th>
<td>0.2736%</td>
<td>-2.2705%</td>
<td>-1.6037%</td>
<td>-2.5425%</td>
<td>0.1099%</td>
<td>-0.2241%</td>
<td>0.5707%</td>
<td>-1.6402%</td>
<td>-1.7641%</td>
<td>-0.1649%</td>
<td>...</td>
<td>-0.1538%</td>
<td>-1.1366%</td>
<td>-0.7308%</td>
<td>-0.1449%</td>
<td>0.0895%</td>
<td>-3.3838%</td>
<td>-0.1117%</td>
<td>-1.1387%</td>
<td>-0.9720%</td>
<td>-1.1254%</td>
</tr>
<tr>
<th>2016-01-11</th>
<td>-4.3383%</td>
<td>0.1692%</td>
<td>-1.6851%</td>
<td>-1.0215%</td>
<td>0.0914%</td>
<td>-1.1792%</td>
<td>0.5674%</td>
<td>0.5288%</td>
<td>0.6616%</td>
<td>0.0330%</td>
<td>...</td>
<td>1.6436%</td>
<td>0.0000%</td>
<td>0.9869%</td>
<td>-0.1450%</td>
<td>1.2225%</td>
<td>1.4570%</td>
<td>0.5367%</td>
<td>-0.4607%</td>
<td>0.5800%</td>
<td>-1.9919%</td>
</tr>
</tbody>
</table>
<p>5 rows × 25 columns</p>
</div>
```python
####################################
# Minimizing Portfolio Variance
####################################
import cvxpy as cp
from timeit import default_timer as timer
# Defining initial inputs
mu = Y.mean().to_numpy().reshape(1,-1)
sigma = Y.cov().to_numpy()
# Defining initial variables
x = cp.Variable((mu.shape[1], 1))
# Budget and weights constraints
constraints = [cp.sum(x) == 1,
x <= 1,
x >= 0]
# Defining risk objective
risk = cp.quad_form(x, sigma)
objective = cp.Minimize(risk)
weights = pd.DataFrame([])
# Solving the problem with several solvers
prob = cp.Problem(objective, constraints)
solvers = ['ECOS', 'SCS']
for i in solvers:
prob.solve(solver=i)
# Showing Optimal Weights
weights_1 = pd.DataFrame(x.value, index=assets, columns=[i])
weights = pd.concat([weights, weights_1], axis=1)
display(weights)
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>ECOS</th>
<th>SCS</th>
</tr>
</thead>
<tbody>
<tr>
<th>APA</th>
<td>0.0002%</td>
<td>-0.0007%</td>
</tr>
<tr>
<th>BA</th>
<td>0.0012%</td>
<td>0.0006%</td>
</tr>
<tr>
<th>BAX</th>
<td>5.2647%</td>
<td>5.2662%</td>
</tr>
<tr>
<th>BMY</th>
<td>4.3893%</td>
<td>4.3904%</td>
</tr>
<tr>
<th>CMCSA</th>
<td>2.1705%</td>
<td>2.1772%</td>
</tr>
<tr>
<th>CNP</th>
<td>6.9881%</td>
<td>6.9878%</td>
</tr>
<tr>
<th>CPB</th>
<td>3.2388%</td>
<td>3.2403%</td>
</tr>
<tr>
<th>DE</th>
<td>0.0707%</td>
<td>0.0874%</td>
</tr>
<tr>
<th>HPQ</th>
<td>0.0001%</td>
<td>-0.0005%</td>
</tr>
<tr>
<th>JCI</th>
<td>2.8381%</td>
<td>2.8435%</td>
</tr>
<tr>
<th>JPM</th>
<td>6.9786%</td>
<td>6.9421%</td>
</tr>
<tr>
<th>LUV</th>
<td>2.8524%</td>
<td>2.8590%</td>
</tr>
<tr>
<th>MMC</th>
<td>12.5818%</td>
<td>12.6038%</td>
</tr>
<tr>
<th>MO</th>
<td>7.2325%</td>
<td>7.2291%</td>
</tr>
<tr>
<th>MSFT</th>
<td>0.0002%</td>
<td>-0.0006%</td>
</tr>
<tr>
<th>NI</th>
<td>11.4513%</td>
<td>11.4451%</td>
</tr>
<tr>
<th>PCAR</th>
<td>0.0003%</td>
<td>-0.0019%</td>
</tr>
<tr>
<th>PSA</th>
<td>14.9188%</td>
<td>14.9124%</td>
</tr>
<tr>
<th>SEE</th>
<td>0.1563%</td>
<td>0.1671%</td>
</tr>
<tr>
<th>T</th>
<td>6.4205%</td>
<td>6.4208%</td>
</tr>
<tr>
<th>TGT</th>
<td>4.0908%</td>
<td>4.0965%</td>
</tr>
<tr>
<th>TMO</th>
<td>0.0004%</td>
<td>0.0005%</td>
</tr>
<tr>
<th>TXT</th>
<td>0.0007%</td>
<td>-0.0021%</td>
</tr>
<tr>
<th>VZ</th>
<td>8.3448%</td>
<td>8.3447%</td>
</tr>
<tr>
<th>ZION</th>
<td>0.0087%</td>
<td>-0.0074%</td>
</tr>
</tbody>
</table>
</div>
As we can see the use of CVXPY's __quad_form__ in portfolio optimization can give small negative values to weights that must be zero.
```python
# Calculating Annualized Portfolio Stats
var = weights * (Y.cov() @ weights) * 252
var = var.sum().to_frame().T
std = np.sqrt(var)
ret = Y.mean().to_frame().T @ weights * 252
stats = pd.concat([ret, std, var], axis=0)
stats.index = ['Return', 'Std. Dev.', 'Variance']
display(stats)
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>ECOS</th>
<th>SCS</th>
</tr>
</thead>
<tbody>
<tr>
<th>Return</th>
<td>12.8507%</td>
<td>12.8498%</td>
</tr>
<tr>
<th>Std. Dev.</th>
<td>10.3737%</td>
<td>10.3738%</td>
</tr>
<tr>
<th>Variance</th>
<td>1.0761%</td>
<td>1.0761%</td>
</tr>
</tbody>
</table>
</div>
### 1.2 Return Maximization with Variance Constraint
The maximization of portfolio return is a problem with a quadratic constraint that can be posed as:
$$
\begin{equation}
\begin{aligned}
& \underset{x}{\text{max}} & & \mu x^{\tau} \\
& \text{s.t.} & & x^{\tau} \Sigma x \leq \bar{\sigma}^{2} \\
& & & \sum_{i=1}^{N} x_i = 1 \\
& & & x_i \geq 0 \; ; \; \forall \; i =1, \ldots, N \\
\end{aligned}
\end{equation}
$$
Where $x$ are the weights of assets and $\bar{\sigma}$ is the maximum expected standard deviation of portfolio..
```python
#########################################
# Maximizing Portfolio Return with
# Variance Constraint
#########################################
import cvxpy as cp
from timeit import default_timer as timer
# Defining initial inputs
mu = Y.mean().to_numpy().reshape(1,-1)
sigma = Y.cov().to_numpy()
# Defining initial variables
x = cp.Variable((mu.shape[1], 1))
sigma_hat = 15 / (252**0.5 * 100)
ret = mu @ x
# Budget and weights constraints
constraints = [cp.sum(x) == 1,
x <= 1,
x >= 0]
# Defining risk constraint and objective
risk = cp.quad_form(x, sigma)
constraints += [risk <= sigma_hat**2] # variance constraint
objective = cp.Maximize(ret)
weights = pd.DataFrame([])
# Solving the problem with several solvers
prob = cp.Problem(objective, constraints)
solvers = ['ECOS', 'SCS']
for i in solvers:
prob.solve(solver=i)
# Showing Optimal Weights
weights_1 = pd.DataFrame(x.value, index=assets, columns=[i])
weights = pd.concat([weights, weights_1], axis=1)
display(weights)
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>ECOS</th>
<th>SCS</th>
</tr>
</thead>
<tbody>
<tr>
<th>APA</th>
<td>0.0000%</td>
<td>0.0006%</td>
</tr>
<tr>
<th>BA</th>
<td>9.5892%</td>
<td>9.6764%</td>
</tr>
<tr>
<th>BAX</th>
<td>12.6176%</td>
<td>12.5937%</td>
</tr>
<tr>
<th>BMY</th>
<td>0.0000%</td>
<td>0.0051%</td>
</tr>
<tr>
<th>CMCSA</th>
<td>0.0000%</td>
<td>0.0072%</td>
</tr>
<tr>
<th>CNP</th>
<td>3.7021%</td>
<td>3.2811%</td>
</tr>
<tr>
<th>CPB</th>
<td>0.0000%</td>
<td>0.0089%</td>
</tr>
<tr>
<th>DE</th>
<td>6.2565%</td>
<td>6.3273%</td>
</tr>
<tr>
<th>HPQ</th>
<td>0.0000%</td>
<td>-0.0003%</td>
</tr>
<tr>
<th>JCI</th>
<td>0.0000%</td>
<td>0.0053%</td>
</tr>
<tr>
<th>JPM</th>
<td>6.5739%</td>
<td>6.5254%</td>
</tr>
<tr>
<th>LUV</th>
<td>0.0000%</td>
<td>0.0048%</td>
</tr>
<tr>
<th>MMC</th>
<td>18.7461%</td>
<td>18.5184%</td>
</tr>
<tr>
<th>MO</th>
<td>0.0000%</td>
<td>0.0161%</td>
</tr>
<tr>
<th>MSFT</th>
<td>35.7121%</td>
<td>36.2356%</td>
</tr>
<tr>
<th>NI</th>
<td>0.0278%</td>
<td>0.0099%</td>
</tr>
<tr>
<th>PCAR</th>
<td>0.0000%</td>
<td>0.0008%</td>
</tr>
<tr>
<th>PSA</th>
<td>0.0000%</td>
<td>0.0179%</td>
</tr>
<tr>
<th>SEE</th>
<td>0.0000%</td>
<td>0.0057%</td>
</tr>
<tr>
<th>T</th>
<td>0.0000%</td>
<td>0.0126%</td>
</tr>
<tr>
<th>TGT</th>
<td>6.7741%</td>
<td>6.7077%</td>
</tr>
<tr>
<th>TMO</th>
<td>0.0002%</td>
<td>0.0011%</td>
</tr>
<tr>
<th>TXT</th>
<td>0.0000%</td>
<td>0.0028%</td>
</tr>
<tr>
<th>VZ</th>
<td>0.0001%</td>
<td>0.0117%</td>
</tr>
<tr>
<th>ZION</th>
<td>0.0001%</td>
<td>-0.0002%</td>
</tr>
</tbody>
</table>
</div>
The small negative values also appear when we use CVXPY's __quad_form__ in constraints.
```python
# Calculating Annualized Portfolio Stats
var = weights * (Y.cov() @ weights) * 252
var = var.sum().to_frame().T
std = np.sqrt(var)
ret = Y.mean().to_frame().T @ weights * 252
stats = pd.concat([ret, std, var], axis=0)
stats.index = ['Return', 'Std. Dev.', 'Variance']
display(stats)
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>ECOS</th>
<th>SCS</th>
</tr>
</thead>
<tbody>
<tr>
<th>Return</th>
<td>26.0352%</td>
<td>26.1001%</td>
</tr>
<tr>
<th>Std. Dev.</th>
<td>15.0000%</td>
<td>15.0672%</td>
</tr>
<tr>
<th>Variance</th>
<td>2.2500%</td>
<td>2.2702%</td>
</tr>
</tbody>
</table>
</div>
## 2 Standard Deviation Optimization
### 2.1 Standard Deviation Minimization
An alternative problem is to minimize the standard deviation (square root of variance). To do this we can use the SOC constraint. The minimization of portfolio standard deviation can be posed as:
$$
\begin{equation}
\begin{aligned}
& \underset{x}{\text{min}} & & g \\
& \text{s.t.} & & \mu x^{\tau} \geq \bar{\mu} \\
& & & \sum_{i=1}^{N} x_i = 1 \\
& & & \left\|\Sigma^{1/2} x\right\| \leq g \\
& & & x_i \geq 0 \; ; \; \forall \; i =1, \ldots, N \\
\end{aligned}
\end{equation}
$$
Where $\left\|\Sigma^{1/2} x\right\| \leq g$ is the SOC constraint, $x$ are the weights of assets, $\mu$ is the mean vector of expected returns, $\bar{\mu}$ the minimum expected return of portfolio and $r$ is the matrix of observed returns.
__Note:__ the SOC constraint can be expressed as $(g,\Sigma^{1/2} x) \in Q^{n+1}$, this notation is used to model the __SOC constraint__ in CVXPY.
```python
#########################################
# Minimizing Portfolio Standard Deviation
#########################################
from scipy.linalg import sqrtm
# Defining initial inputs
mu = Y.mean().to_numpy().reshape(1,-1)
sigma = Y.cov().to_numpy()
G = sqrtm(sigma)
# Defining initial variables
x = cp.Variable((mu.shape[1], 1))
g = cp.Variable(nonneg=True)
# Budget and weights constraints
constraints = [cp.sum(x) == 1,
x >= 0]
# Defining risk objective
risk = g
constraints += [cp.SOC(g, G @ x)] # SOC constraint
constraints += [risk <= sigma_hat] # variance constraint
objective = cp.Minimize(risk)
weights = pd.DataFrame([])
# Solving the problem with several solvers
prob = cp.Problem(objective, constraints)
solvers = ['ECOS', 'SCS']
for i in solvers:
prob.solve(solver=i)
# Showing Optimal Weights
weights_1 = pd.DataFrame(x.value, index=assets, columns=[i])
weights = pd.concat([weights, weights_1], axis=1)
display(weights)
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>ECOS</th>
<th>SCS</th>
</tr>
</thead>
<tbody>
<tr>
<th>APA</th>
<td>0.0000%</td>
<td>0.0000%</td>
</tr>
<tr>
<th>BA</th>
<td>0.0000%</td>
<td>0.0001%</td>
</tr>
<tr>
<th>BAX</th>
<td>5.2634%</td>
<td>5.2632%</td>
</tr>
<tr>
<th>BMY</th>
<td>4.3887%</td>
<td>4.3886%</td>
</tr>
<tr>
<th>CMCSA</th>
<td>2.1705%</td>
<td>2.1705%</td>
</tr>
<tr>
<th>CNP</th>
<td>6.9872%</td>
<td>6.9870%</td>
</tr>
<tr>
<th>CPB</th>
<td>3.2390%</td>
<td>3.2391%</td>
</tr>
<tr>
<th>DE</th>
<td>0.0789%</td>
<td>0.0791%</td>
</tr>
<tr>
<th>HPQ</th>
<td>0.0000%</td>
<td>0.0002%</td>
</tr>
<tr>
<th>JCI</th>
<td>2.8376%</td>
<td>2.8375%</td>
</tr>
<tr>
<th>JPM</th>
<td>6.9842%</td>
<td>6.9839%</td>
</tr>
<tr>
<th>LUV</th>
<td>2.8523%</td>
<td>2.8522%</td>
</tr>
<tr>
<th>MMC</th>
<td>12.5805%</td>
<td>12.5803%</td>
</tr>
<tr>
<th>MO</th>
<td>7.2314%</td>
<td>7.2313%</td>
</tr>
<tr>
<th>MSFT</th>
<td>0.0000%</td>
<td>0.0003%</td>
</tr>
<tr>
<th>NI</th>
<td>11.4509%</td>
<td>11.4508%</td>
</tr>
<tr>
<th>PCAR</th>
<td>0.0000%</td>
<td>0.0001%</td>
</tr>
<tr>
<th>PSA</th>
<td>14.9186%</td>
<td>14.9183%</td>
</tr>
<tr>
<th>SEE</th>
<td>0.1621%</td>
<td>0.1628%</td>
</tr>
<tr>
<th>T</th>
<td>6.4196%</td>
<td>6.4196%</td>
</tr>
<tr>
<th>TGT</th>
<td>4.0904%</td>
<td>4.0904%</td>
</tr>
<tr>
<th>TMO</th>
<td>0.0000%</td>
<td>0.0002%</td>
</tr>
<tr>
<th>TXT</th>
<td>0.0000%</td>
<td>0.0001%</td>
</tr>
<tr>
<th>VZ</th>
<td>8.3447%</td>
<td>8.3446%</td>
</tr>
<tr>
<th>ZION</th>
<td>0.0000%</td>
<td>0.0001%</td>
</tr>
</tbody>
</table>
</div>
As we can see the use of CVXPY's __SOC constraint__ in portfolio optimization solves the error that we see when we use __quad_form__.
```python
# Calculating Annualized Portfolio Stats
var = weights * (Y.cov() @ weights) * 252
var = var.sum().to_frame().T
std = np.sqrt(var)
ret = Y.mean().to_frame().T @ weights * 252
stats = pd.concat([ret, std, var], axis=0)
stats.index = ['Return', 'Std. Dev.', 'Variance']
display(stats)
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>ECOS</th>
<th>SCS</th>
</tr>
</thead>
<tbody>
<tr>
<th>Return</th>
<td>12.8508%</td>
<td>12.8509%</td>
</tr>
<tr>
<th>Std. Dev.</th>
<td>10.3737%</td>
<td>10.3737%</td>
</tr>
<tr>
<th>Variance</th>
<td>1.0761%</td>
<td>1.0761%</td>
</tr>
</tbody>
</table>
</div>
### 2.2 Return Maximization with Standard Deviation Constraint
The maximization of portfolio return using SOC constraints can be posed as:
$$
\begin{equation}
\begin{aligned}
& \underset{x}{\text{max}} & & \mu x^{\tau} \\
& \text{s.t.} & & g \leq \bar{\sigma} \\
& & & \left\|\Sigma^{1/2} x\right\| \leq g \\
& & & \sum_{i=1}^{N} x_i = 1 \\
& & & x_i \geq 0 \; ; \; \forall \; i =1, \ldots, N \\
\end{aligned}
\end{equation}
$$
```python
#########################################
# Maximizing Portfolio Return with
# Standard Deviation Constraint
#########################################
from scipy.linalg import sqrtm
# Defining initial inputs
mu = Y.mean().to_numpy().reshape(1,-1)
sigma = Y.cov().to_numpy()
G = sqrtm(sigma)
# Defining initial variables
x = cp.Variable((mu.shape[1], 1))
g = cp.Variable(nonneg=True)
sigma_hat = 15 / (252**0.5 * 100)
ret = mu @ x
# Budget and weights constraints
constraints = [cp.sum(x) == 1,
x <= 1,
x >= 0]
# Defining risk constraint and objective
risk = g
constraints += [cp.SOC(g, G @ x)] # SOC constraint
constraints += [risk <= sigma_hat] # standard deviation constraint
objective = cp.Maximize(ret)
weights = pd.DataFrame([])
# Solving the problem with several solvers
prob = cp.Problem(objective, constraints)
solvers = ['ECOS', 'SCS']
for i in solvers:
prob.solve(solver=i)
# Showing Optimal Weights
weights_1 = pd.DataFrame(x.value, index=assets, columns=[i])
weights = pd.concat([weights, weights_1], axis=1)
display(weights)
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>ECOS</th>
<th>SCS</th>
</tr>
</thead>
<tbody>
<tr>
<th>APA</th>
<td>0.0000%</td>
<td>0.0003%</td>
</tr>
<tr>
<th>BA</th>
<td>9.5885%</td>
<td>9.5835%</td>
</tr>
<tr>
<th>BAX</th>
<td>12.6190%</td>
<td>12.6236%</td>
</tr>
<tr>
<th>BMY</th>
<td>0.0000%</td>
<td>-0.0011%</td>
</tr>
<tr>
<th>CMCSA</th>
<td>0.0000%</td>
<td>-0.0010%</td>
</tr>
<tr>
<th>CNP</th>
<td>3.7154%</td>
<td>3.7281%</td>
</tr>
<tr>
<th>CPB</th>
<td>0.0000%</td>
<td>-0.0014%</td>
</tr>
<tr>
<th>DE</th>
<td>6.2555%</td>
<td>6.2519%</td>
</tr>
<tr>
<th>HPQ</th>
<td>0.0000%</td>
<td>0.0006%</td>
</tr>
<tr>
<th>JCI</th>
<td>0.0000%</td>
<td>-0.0006%</td>
</tr>
<tr>
<th>JPM</th>
<td>6.5725%</td>
<td>6.5909%</td>
</tr>
<tr>
<th>LUV</th>
<td>0.0000%</td>
<td>-0.0008%</td>
</tr>
<tr>
<th>MMC</th>
<td>18.7512%</td>
<td>18.7542%</td>
</tr>
<tr>
<th>MO</th>
<td>0.0000%</td>
<td>-0.0017%</td>
</tr>
<tr>
<th>MSFT</th>
<td>35.7087%</td>
<td>35.6702%</td>
</tr>
<tr>
<th>NI</th>
<td>0.0135%</td>
<td>0.0331%</td>
</tr>
<tr>
<th>PCAR</th>
<td>0.0000%</td>
<td>-0.0001%</td>
</tr>
<tr>
<th>PSA</th>
<td>0.0000%</td>
<td>-0.0018%</td>
</tr>
<tr>
<th>SEE</th>
<td>0.0000%</td>
<td>-0.0007%</td>
</tr>
<tr>
<th>T</th>
<td>0.0000%</td>
<td>-0.0015%</td>
</tr>
<tr>
<th>TGT</th>
<td>6.7755%</td>
<td>6.7784%</td>
</tr>
<tr>
<th>TMO</th>
<td>0.0001%</td>
<td>0.0001%</td>
</tr>
<tr>
<th>TXT</th>
<td>0.0000%</td>
<td>0.0001%</td>
</tr>
<tr>
<th>VZ</th>
<td>0.0000%</td>
<td>-0.0013%</td>
</tr>
<tr>
<th>ZION</th>
<td>0.0000%</td>
<td>0.0009%</td>
</tr>
</tbody>
</table>
</div>
CVXPY's __SOC constraint__ also solves the error that we see when we use __quad_form__ in constraints.
```python
# Calculating Annualized Portfolio Stats
var = weights * (Y.cov() @ weights) * 252
var = var.sum().to_frame().T
std = np.sqrt(var)
ret = Y.mean().to_frame().T @ weights * 252
stats = pd.concat([ret, std, var], axis=0)
stats.index = ['Return', 'Std. Dev.', 'Variance']
display(stats)
```
<div>
<style scoped>
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>ECOS</th>
<th>SCS</th>
</tr>
</thead>
<tbody>
<tr>
<th>Return</th>
<td>26.0352%</td>
<td>26.0316%</td>
</tr>
<tr>
<th>Std. Dev.</th>
<td>15.0000%</td>
<td>14.9958%</td>
</tr>
<tr>
<th>Variance</th>
<td>2.2500%</td>
<td>2.2487%</td>
</tr>
</tbody>
</table>
</div>
For more portfolio optimization models and applications, you can see the CVXPY based library __[Riskfolio-Lib](https://github.com/dcajasn/Riskfolio-Lib)__.
|
module System.File.Meta
import System.File.Handle
import System.File.Support
import public System.File.Types
import System.FFI
%default total
fileClass : String
fileClass = "io/github/mmhelloworld/idrisjvm/runtime/ChannelIo"
%foreign support "idris2_fileSize"
"node:lambda:fp=>require('fs').fstatSync(fp.fd).size"
jvm' fileClass "size" fileClass "int"
prim__fileSize : FilePtr -> PrimIO Int
%foreign support "idris2_fileSize"
jvm' fileClass "size" fileClass "int"
prim__fPoll : FilePtr -> PrimIO Int
%foreign support "idris2_fileAccessTime"
jvm' fileClass "getAccessTime" fileClass "int"
prim__fileAccessTime : FilePtr -> PrimIO Int
%foreign support "idris2_fileModifiedTime"
"node:lambda:fp=>require('fs').fstatSync(fp.fd).mtimeMs / 1000"
jvm' fileClass "getModifiedTime" fileClass "int"
prim__fileModifiedTime : FilePtr -> PrimIO Int
%foreign support "idris2_fileStatusTime"
jvm' fileClass "getStatusTime" fileClass "int"
prim__fileStatusTime : FilePtr -> PrimIO Int
%foreign support "idris2_fileIsTTY"
"node:lambda:fp=>Number(require('tty').isatty(fp.fd))"
prim__fileIsTTY : FilePtr -> PrimIO Int
||| Check if a file exists for reading.
export
exists : HasIO io => String -> io Bool
exists f
= do Right ok <- openFile f Read
| Left err => pure False
closeFile ok
pure True
||| Pick the first existing file
export
firstExists : HasIO io => List String -> io (Maybe String)
firstExists [] = pure Nothing
firstExists (x :: xs) = if !(exists x) then pure (Just x) else firstExists xs
export
fileAccessTime : HasIO io => (h : File) -> io (Either FileError Int)
fileAccessTime (FHandle f)
= do res <- primIO (prim__fileAccessTime f)
if res > 0
then ok res
else returnError
export
fileModifiedTime : HasIO io => (h : File) -> io (Either FileError Int)
fileModifiedTime (FHandle f)
= do res <- primIO (prim__fileModifiedTime f)
if res > 0
then ok res
else returnError
export
fileStatusTime : HasIO io => (h : File) -> io (Either FileError Int)
fileStatusTime (FHandle f)
= do res <- primIO (prim__fileStatusTime f)
if res > 0
then ok res
else returnError
export
fileSize : HasIO io => (h : File) -> io (Either FileError Int)
fileSize (FHandle f)
= do res <- primIO (prim__fileSize f)
if res >= 0
then ok res
else returnError
export
fPoll : HasIO io => File -> io Bool
fPoll (FHandle f)
= do p <- primIO (prim__fPoll f)
pure (p > 0)
||| Check whether the given File is a terminal device.
export
isTTY : HasIO io => (h : File) -> io Bool
isTTY (FHandle f) = (/= 0) <$> primIO (prim__fileIsTTY f)
|
After finding out where the Ning @-@ Po unloaded , Bond flies over the area in a heavily armed autogyro created by Q. Near a volcano , Bond is attacked by helicopters , which he defeats , confirming his suspicions that the enemy 's base is nearby . A Soviet spacecraft is then captured in orbit by another unidentified craft , heightening tensions between Russia and the US . The mysterious spaceship lands in an extensive base hidden inside the volcano . It is revealed that the true mastermind behind this is Ernst Stavro Blofeld and SPECTRE . Blofeld seems to forgive Brandt for her failure to kill Bond , but as she leaves , he activates a mechanism that drops her into a pool of piranha . Blofeld instructs Osato to kill Bond .
|
// Copyright (C) 2020 T. Zachary Laine
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Warning! This file is autogenerated.
#include <boost/text/normalize_string.hpp>
#include <boost/text/transcode_view.hpp>
#include <boost/text/string_utility.hpp>
#include <gtest/gtest.h>
#include <algorithm>
TEST(normalization, nfd_039_000)
{
// C108;C108;1109 1164 11AF;C108;1109 1164 11AF;
// (섈; 섈; 섈; 섈; 섈; ) HANGUL SYLLABLE SYAEL
{
std::array<uint32_t, 1> const c1 = {{ 0xC108 }};
std::array<uint32_t, 1> const c2 = {{ 0xC108 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11AF }};
std::array<uint32_t, 1> const c4 = {{ 0xC108 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11AF }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_001)
{
// C109;C109;1109 1164 11B0;C109;1109 1164 11B0;
// (섉; 섉; 섉; 섉; 섉; ) HANGUL SYLLABLE SYAELG
{
std::array<uint32_t, 1> const c1 = {{ 0xC109 }};
std::array<uint32_t, 1> const c2 = {{ 0xC109 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11B0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC109 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11B0 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_002)
{
// C10A;C10A;1109 1164 11B1;C10A;1109 1164 11B1;
// (섊; 섊; 섊; 섊; 섊; ) HANGUL SYLLABLE SYAELM
{
std::array<uint32_t, 1> const c1 = {{ 0xC10A }};
std::array<uint32_t, 1> const c2 = {{ 0xC10A }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11B1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC10A }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11B1 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_003)
{
// C10B;C10B;1109 1164 11B2;C10B;1109 1164 11B2;
// (섋; 섋; 섋; 섋; 섋; ) HANGUL SYLLABLE SYAELB
{
std::array<uint32_t, 1> const c1 = {{ 0xC10B }};
std::array<uint32_t, 1> const c2 = {{ 0xC10B }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11B2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC10B }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11B2 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_004)
{
// C10C;C10C;1109 1164 11B3;C10C;1109 1164 11B3;
// (섌; 섌; 섌; 섌; 섌; ) HANGUL SYLLABLE SYAELS
{
std::array<uint32_t, 1> const c1 = {{ 0xC10C }};
std::array<uint32_t, 1> const c2 = {{ 0xC10C }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11B3 }};
std::array<uint32_t, 1> const c4 = {{ 0xC10C }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11B3 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_005)
{
// C10D;C10D;1109 1164 11B4;C10D;1109 1164 11B4;
// (섍; 섍; 섍; 섍; 섍; ) HANGUL SYLLABLE SYAELT
{
std::array<uint32_t, 1> const c1 = {{ 0xC10D }};
std::array<uint32_t, 1> const c2 = {{ 0xC10D }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11B4 }};
std::array<uint32_t, 1> const c4 = {{ 0xC10D }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11B4 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_006)
{
// C10E;C10E;1109 1164 11B5;C10E;1109 1164 11B5;
// (섎; 섎; 섎; 섎; 섎; ) HANGUL SYLLABLE SYAELP
{
std::array<uint32_t, 1> const c1 = {{ 0xC10E }};
std::array<uint32_t, 1> const c2 = {{ 0xC10E }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11B5 }};
std::array<uint32_t, 1> const c4 = {{ 0xC10E }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11B5 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_007)
{
// C10F;C10F;1109 1164 11B6;C10F;1109 1164 11B6;
// (섏; 섏; 섏; 섏; 섏; ) HANGUL SYLLABLE SYAELH
{
std::array<uint32_t, 1> const c1 = {{ 0xC10F }};
std::array<uint32_t, 1> const c2 = {{ 0xC10F }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11B6 }};
std::array<uint32_t, 1> const c4 = {{ 0xC10F }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11B6 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_008)
{
// C110;C110;1109 1164 11B7;C110;1109 1164 11B7;
// (섐; 섐; 섐; 섐; 섐; ) HANGUL SYLLABLE SYAEM
{
std::array<uint32_t, 1> const c1 = {{ 0xC110 }};
std::array<uint32_t, 1> const c2 = {{ 0xC110 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11B7 }};
std::array<uint32_t, 1> const c4 = {{ 0xC110 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11B7 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_009)
{
// C111;C111;1109 1164 11B8;C111;1109 1164 11B8;
// (섑; 섑; 섑; 섑; 섑; ) HANGUL SYLLABLE SYAEB
{
std::array<uint32_t, 1> const c1 = {{ 0xC111 }};
std::array<uint32_t, 1> const c2 = {{ 0xC111 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11B8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC111 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11B8 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_010)
{
// C112;C112;1109 1164 11B9;C112;1109 1164 11B9;
// (섒; 섒; 섒; 섒; 섒; ) HANGUL SYLLABLE SYAEBS
{
std::array<uint32_t, 1> const c1 = {{ 0xC112 }};
std::array<uint32_t, 1> const c2 = {{ 0xC112 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11B9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC112 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11B9 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_011)
{
// C113;C113;1109 1164 11BA;C113;1109 1164 11BA;
// (섓; 섓; 섓; 섓; 섓; ) HANGUL SYLLABLE SYAES
{
std::array<uint32_t, 1> const c1 = {{ 0xC113 }};
std::array<uint32_t, 1> const c2 = {{ 0xC113 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11BA }};
std::array<uint32_t, 1> const c4 = {{ 0xC113 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11BA }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_012)
{
// C114;C114;1109 1164 11BB;C114;1109 1164 11BB;
// (섔; 섔; 섔; 섔; 섔; ) HANGUL SYLLABLE SYAESS
{
std::array<uint32_t, 1> const c1 = {{ 0xC114 }};
std::array<uint32_t, 1> const c2 = {{ 0xC114 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11BB }};
std::array<uint32_t, 1> const c4 = {{ 0xC114 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11BB }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_013)
{
// C115;C115;1109 1164 11BC;C115;1109 1164 11BC;
// (섕; 섕; 섕; 섕; 섕; ) HANGUL SYLLABLE SYAENG
{
std::array<uint32_t, 1> const c1 = {{ 0xC115 }};
std::array<uint32_t, 1> const c2 = {{ 0xC115 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11BC }};
std::array<uint32_t, 1> const c4 = {{ 0xC115 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11BC }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_014)
{
// C116;C116;1109 1164 11BD;C116;1109 1164 11BD;
// (섖; 섖; 섖; 섖; 섖; ) HANGUL SYLLABLE SYAEJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC116 }};
std::array<uint32_t, 1> const c2 = {{ 0xC116 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11BD }};
std::array<uint32_t, 1> const c4 = {{ 0xC116 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11BD }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_015)
{
// C117;C117;1109 1164 11BE;C117;1109 1164 11BE;
// (섗; 섗; 섗; 섗; 섗; ) HANGUL SYLLABLE SYAEC
{
std::array<uint32_t, 1> const c1 = {{ 0xC117 }};
std::array<uint32_t, 1> const c2 = {{ 0xC117 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11BE }};
std::array<uint32_t, 1> const c4 = {{ 0xC117 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11BE }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_016)
{
// C118;C118;1109 1164 11BF;C118;1109 1164 11BF;
// (섘; 섘; 섘; 섘; 섘; ) HANGUL SYLLABLE SYAEK
{
std::array<uint32_t, 1> const c1 = {{ 0xC118 }};
std::array<uint32_t, 1> const c2 = {{ 0xC118 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11BF }};
std::array<uint32_t, 1> const c4 = {{ 0xC118 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11BF }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_017)
{
// C119;C119;1109 1164 11C0;C119;1109 1164 11C0;
// (섙; 섙; 섙; 섙; 섙; ) HANGUL SYLLABLE SYAET
{
std::array<uint32_t, 1> const c1 = {{ 0xC119 }};
std::array<uint32_t, 1> const c2 = {{ 0xC119 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11C0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC119 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11C0 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_018)
{
// C11A;C11A;1109 1164 11C1;C11A;1109 1164 11C1;
// (섚; 섚; 섚; 섚; 섚; ) HANGUL SYLLABLE SYAEP
{
std::array<uint32_t, 1> const c1 = {{ 0xC11A }};
std::array<uint32_t, 1> const c2 = {{ 0xC11A }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11C1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC11A }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11C1 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_019)
{
// C11B;C11B;1109 1164 11C2;C11B;1109 1164 11C2;
// (섛; 섛; 섛; 섛; 섛; ) HANGUL SYLLABLE SYAEH
{
std::array<uint32_t, 1> const c1 = {{ 0xC11B }};
std::array<uint32_t, 1> const c2 = {{ 0xC11B }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1164, 0x11C2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC11B }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1164, 0x11C2 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_020)
{
// C11C;C11C;1109 1165;C11C;1109 1165;
// (서; 서; 서; 서; 서; ) HANGUL SYLLABLE SEO
{
std::array<uint32_t, 1> const c1 = {{ 0xC11C }};
std::array<uint32_t, 1> const c2 = {{ 0xC11C }};
std::array<uint32_t, 2> const c3 = {{ 0x1109, 0x1165 }};
std::array<uint32_t, 1> const c4 = {{ 0xC11C }};
std::array<uint32_t, 2> const c5 = {{ 0x1109, 0x1165 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_021)
{
// C11D;C11D;1109 1165 11A8;C11D;1109 1165 11A8;
// (석; 석; 석; 석; 석; ) HANGUL SYLLABLE SEOG
{
std::array<uint32_t, 1> const c1 = {{ 0xC11D }};
std::array<uint32_t, 1> const c2 = {{ 0xC11D }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11A8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC11D }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11A8 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_022)
{
// C11E;C11E;1109 1165 11A9;C11E;1109 1165 11A9;
// (섞; 섞; 섞; 섞; 섞; ) HANGUL SYLLABLE SEOGG
{
std::array<uint32_t, 1> const c1 = {{ 0xC11E }};
std::array<uint32_t, 1> const c2 = {{ 0xC11E }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11A9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC11E }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11A9 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_023)
{
// C11F;C11F;1109 1165 11AA;C11F;1109 1165 11AA;
// (섟; 섟; 섟; 섟; 섟; ) HANGUL SYLLABLE SEOGS
{
std::array<uint32_t, 1> const c1 = {{ 0xC11F }};
std::array<uint32_t, 1> const c2 = {{ 0xC11F }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11AA }};
std::array<uint32_t, 1> const c4 = {{ 0xC11F }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11AA }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_024)
{
// C120;C120;1109 1165 11AB;C120;1109 1165 11AB;
// (선; 선; 선; 선; 선; ) HANGUL SYLLABLE SEON
{
std::array<uint32_t, 1> const c1 = {{ 0xC120 }};
std::array<uint32_t, 1> const c2 = {{ 0xC120 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11AB }};
std::array<uint32_t, 1> const c4 = {{ 0xC120 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11AB }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_025)
{
// C121;C121;1109 1165 11AC;C121;1109 1165 11AC;
// (섡; 섡; 섡; 섡; 섡; ) HANGUL SYLLABLE SEONJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC121 }};
std::array<uint32_t, 1> const c2 = {{ 0xC121 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11AC }};
std::array<uint32_t, 1> const c4 = {{ 0xC121 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11AC }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_026)
{
// C122;C122;1109 1165 11AD;C122;1109 1165 11AD;
// (섢; 섢; 섢; 섢; 섢; ) HANGUL SYLLABLE SEONH
{
std::array<uint32_t, 1> const c1 = {{ 0xC122 }};
std::array<uint32_t, 1> const c2 = {{ 0xC122 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11AD }};
std::array<uint32_t, 1> const c4 = {{ 0xC122 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11AD }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_027)
{
// C123;C123;1109 1165 11AE;C123;1109 1165 11AE;
// (섣; 섣; 섣; 섣; 섣; ) HANGUL SYLLABLE SEOD
{
std::array<uint32_t, 1> const c1 = {{ 0xC123 }};
std::array<uint32_t, 1> const c2 = {{ 0xC123 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11AE }};
std::array<uint32_t, 1> const c4 = {{ 0xC123 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11AE }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_028)
{
// C124;C124;1109 1165 11AF;C124;1109 1165 11AF;
// (설; 설; 설; 설; 설; ) HANGUL SYLLABLE SEOL
{
std::array<uint32_t, 1> const c1 = {{ 0xC124 }};
std::array<uint32_t, 1> const c2 = {{ 0xC124 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11AF }};
std::array<uint32_t, 1> const c4 = {{ 0xC124 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11AF }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_029)
{
// C125;C125;1109 1165 11B0;C125;1109 1165 11B0;
// (섥; 섥; 섥; 섥; 섥; ) HANGUL SYLLABLE SEOLG
{
std::array<uint32_t, 1> const c1 = {{ 0xC125 }};
std::array<uint32_t, 1> const c2 = {{ 0xC125 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11B0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC125 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11B0 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_030)
{
// C126;C126;1109 1165 11B1;C126;1109 1165 11B1;
// (섦; 섦; 섦; 섦; 섦; ) HANGUL SYLLABLE SEOLM
{
std::array<uint32_t, 1> const c1 = {{ 0xC126 }};
std::array<uint32_t, 1> const c2 = {{ 0xC126 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11B1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC126 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11B1 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_031)
{
// C127;C127;1109 1165 11B2;C127;1109 1165 11B2;
// (섧; 섧; 섧; 섧; 섧; ) HANGUL SYLLABLE SEOLB
{
std::array<uint32_t, 1> const c1 = {{ 0xC127 }};
std::array<uint32_t, 1> const c2 = {{ 0xC127 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11B2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC127 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11B2 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_032)
{
// C128;C128;1109 1165 11B3;C128;1109 1165 11B3;
// (섨; 섨; 섨; 섨; 섨; ) HANGUL SYLLABLE SEOLS
{
std::array<uint32_t, 1> const c1 = {{ 0xC128 }};
std::array<uint32_t, 1> const c2 = {{ 0xC128 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11B3 }};
std::array<uint32_t, 1> const c4 = {{ 0xC128 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11B3 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_033)
{
// C129;C129;1109 1165 11B4;C129;1109 1165 11B4;
// (섩; 섩; 섩; 섩; 섩; ) HANGUL SYLLABLE SEOLT
{
std::array<uint32_t, 1> const c1 = {{ 0xC129 }};
std::array<uint32_t, 1> const c2 = {{ 0xC129 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11B4 }};
std::array<uint32_t, 1> const c4 = {{ 0xC129 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11B4 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_034)
{
// C12A;C12A;1109 1165 11B5;C12A;1109 1165 11B5;
// (섪; 섪; 섪; 섪; 섪; ) HANGUL SYLLABLE SEOLP
{
std::array<uint32_t, 1> const c1 = {{ 0xC12A }};
std::array<uint32_t, 1> const c2 = {{ 0xC12A }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11B5 }};
std::array<uint32_t, 1> const c4 = {{ 0xC12A }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11B5 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_035)
{
// C12B;C12B;1109 1165 11B6;C12B;1109 1165 11B6;
// (섫; 섫; 섫; 섫; 섫; ) HANGUL SYLLABLE SEOLH
{
std::array<uint32_t, 1> const c1 = {{ 0xC12B }};
std::array<uint32_t, 1> const c2 = {{ 0xC12B }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11B6 }};
std::array<uint32_t, 1> const c4 = {{ 0xC12B }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11B6 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_036)
{
// C12C;C12C;1109 1165 11B7;C12C;1109 1165 11B7;
// (섬; 섬; 섬; 섬; 섬; ) HANGUL SYLLABLE SEOM
{
std::array<uint32_t, 1> const c1 = {{ 0xC12C }};
std::array<uint32_t, 1> const c2 = {{ 0xC12C }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11B7 }};
std::array<uint32_t, 1> const c4 = {{ 0xC12C }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11B7 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_037)
{
// C12D;C12D;1109 1165 11B8;C12D;1109 1165 11B8;
// (섭; 섭; 섭; 섭; 섭; ) HANGUL SYLLABLE SEOB
{
std::array<uint32_t, 1> const c1 = {{ 0xC12D }};
std::array<uint32_t, 1> const c2 = {{ 0xC12D }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11B8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC12D }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11B8 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_038)
{
// C12E;C12E;1109 1165 11B9;C12E;1109 1165 11B9;
// (섮; 섮; 섮; 섮; 섮; ) HANGUL SYLLABLE SEOBS
{
std::array<uint32_t, 1> const c1 = {{ 0xC12E }};
std::array<uint32_t, 1> const c2 = {{ 0xC12E }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11B9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC12E }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11B9 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_039)
{
// C12F;C12F;1109 1165 11BA;C12F;1109 1165 11BA;
// (섯; 섯; 섯; 섯; 섯; ) HANGUL SYLLABLE SEOS
{
std::array<uint32_t, 1> const c1 = {{ 0xC12F }};
std::array<uint32_t, 1> const c2 = {{ 0xC12F }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11BA }};
std::array<uint32_t, 1> const c4 = {{ 0xC12F }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11BA }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_040)
{
// C130;C130;1109 1165 11BB;C130;1109 1165 11BB;
// (섰; 섰; 섰; 섰; 섰; ) HANGUL SYLLABLE SEOSS
{
std::array<uint32_t, 1> const c1 = {{ 0xC130 }};
std::array<uint32_t, 1> const c2 = {{ 0xC130 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11BB }};
std::array<uint32_t, 1> const c4 = {{ 0xC130 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11BB }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_041)
{
// C131;C131;1109 1165 11BC;C131;1109 1165 11BC;
// (성; 성; 성; 성; 성; ) HANGUL SYLLABLE SEONG
{
std::array<uint32_t, 1> const c1 = {{ 0xC131 }};
std::array<uint32_t, 1> const c2 = {{ 0xC131 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11BC }};
std::array<uint32_t, 1> const c4 = {{ 0xC131 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11BC }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_042)
{
// C132;C132;1109 1165 11BD;C132;1109 1165 11BD;
// (섲; 섲; 섲; 섲; 섲; ) HANGUL SYLLABLE SEOJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC132 }};
std::array<uint32_t, 1> const c2 = {{ 0xC132 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11BD }};
std::array<uint32_t, 1> const c4 = {{ 0xC132 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11BD }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_043)
{
// C133;C133;1109 1165 11BE;C133;1109 1165 11BE;
// (섳; 섳; 섳; 섳; 섳; ) HANGUL SYLLABLE SEOC
{
std::array<uint32_t, 1> const c1 = {{ 0xC133 }};
std::array<uint32_t, 1> const c2 = {{ 0xC133 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11BE }};
std::array<uint32_t, 1> const c4 = {{ 0xC133 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11BE }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_044)
{
// C134;C134;1109 1165 11BF;C134;1109 1165 11BF;
// (섴; 섴; 섴; 섴; 섴; ) HANGUL SYLLABLE SEOK
{
std::array<uint32_t, 1> const c1 = {{ 0xC134 }};
std::array<uint32_t, 1> const c2 = {{ 0xC134 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11BF }};
std::array<uint32_t, 1> const c4 = {{ 0xC134 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11BF }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_045)
{
// C135;C135;1109 1165 11C0;C135;1109 1165 11C0;
// (섵; 섵; 섵; 섵; 섵; ) HANGUL SYLLABLE SEOT
{
std::array<uint32_t, 1> const c1 = {{ 0xC135 }};
std::array<uint32_t, 1> const c2 = {{ 0xC135 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11C0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC135 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11C0 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_046)
{
// C136;C136;1109 1165 11C1;C136;1109 1165 11C1;
// (섶; 섶; 섶; 섶; 섶; ) HANGUL SYLLABLE SEOP
{
std::array<uint32_t, 1> const c1 = {{ 0xC136 }};
std::array<uint32_t, 1> const c2 = {{ 0xC136 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11C1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC136 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11C1 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_047)
{
// C137;C137;1109 1165 11C2;C137;1109 1165 11C2;
// (섷; 섷; 섷; 섷; 섷; ) HANGUL SYLLABLE SEOH
{
std::array<uint32_t, 1> const c1 = {{ 0xC137 }};
std::array<uint32_t, 1> const c2 = {{ 0xC137 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1165, 0x11C2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC137 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1165, 0x11C2 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_048)
{
// C138;C138;1109 1166;C138;1109 1166;
// (세; 세; 세; 세; 세; ) HANGUL SYLLABLE SE
{
std::array<uint32_t, 1> const c1 = {{ 0xC138 }};
std::array<uint32_t, 1> const c2 = {{ 0xC138 }};
std::array<uint32_t, 2> const c3 = {{ 0x1109, 0x1166 }};
std::array<uint32_t, 1> const c4 = {{ 0xC138 }};
std::array<uint32_t, 2> const c5 = {{ 0x1109, 0x1166 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_049)
{
// C139;C139;1109 1166 11A8;C139;1109 1166 11A8;
// (섹; 섹; 섹; 섹; 섹; ) HANGUL SYLLABLE SEG
{
std::array<uint32_t, 1> const c1 = {{ 0xC139 }};
std::array<uint32_t, 1> const c2 = {{ 0xC139 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11A8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC139 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11A8 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_050)
{
// C13A;C13A;1109 1166 11A9;C13A;1109 1166 11A9;
// (섺; 섺; 섺; 섺; 섺; ) HANGUL SYLLABLE SEGG
{
std::array<uint32_t, 1> const c1 = {{ 0xC13A }};
std::array<uint32_t, 1> const c2 = {{ 0xC13A }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11A9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC13A }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11A9 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_051)
{
// C13B;C13B;1109 1166 11AA;C13B;1109 1166 11AA;
// (섻; 섻; 섻; 섻; 섻; ) HANGUL SYLLABLE SEGS
{
std::array<uint32_t, 1> const c1 = {{ 0xC13B }};
std::array<uint32_t, 1> const c2 = {{ 0xC13B }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11AA }};
std::array<uint32_t, 1> const c4 = {{ 0xC13B }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11AA }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_052)
{
// C13C;C13C;1109 1166 11AB;C13C;1109 1166 11AB;
// (센; 센; 센; 센; 센; ) HANGUL SYLLABLE SEN
{
std::array<uint32_t, 1> const c1 = {{ 0xC13C }};
std::array<uint32_t, 1> const c2 = {{ 0xC13C }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11AB }};
std::array<uint32_t, 1> const c4 = {{ 0xC13C }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11AB }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_053)
{
// C13D;C13D;1109 1166 11AC;C13D;1109 1166 11AC;
// (섽; 섽; 섽; 섽; 섽; ) HANGUL SYLLABLE SENJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC13D }};
std::array<uint32_t, 1> const c2 = {{ 0xC13D }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11AC }};
std::array<uint32_t, 1> const c4 = {{ 0xC13D }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11AC }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_054)
{
// C13E;C13E;1109 1166 11AD;C13E;1109 1166 11AD;
// (섾; 섾; 섾; 섾; 섾; ) HANGUL SYLLABLE SENH
{
std::array<uint32_t, 1> const c1 = {{ 0xC13E }};
std::array<uint32_t, 1> const c2 = {{ 0xC13E }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11AD }};
std::array<uint32_t, 1> const c4 = {{ 0xC13E }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11AD }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_055)
{
// C13F;C13F;1109 1166 11AE;C13F;1109 1166 11AE;
// (섿; 섿; 섿; 섿; 섿; ) HANGUL SYLLABLE SED
{
std::array<uint32_t, 1> const c1 = {{ 0xC13F }};
std::array<uint32_t, 1> const c2 = {{ 0xC13F }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11AE }};
std::array<uint32_t, 1> const c4 = {{ 0xC13F }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11AE }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_056)
{
// C140;C140;1109 1166 11AF;C140;1109 1166 11AF;
// (셀; 셀; 셀; 셀; 셀; ) HANGUL SYLLABLE SEL
{
std::array<uint32_t, 1> const c1 = {{ 0xC140 }};
std::array<uint32_t, 1> const c2 = {{ 0xC140 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11AF }};
std::array<uint32_t, 1> const c4 = {{ 0xC140 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11AF }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_057)
{
// C141;C141;1109 1166 11B0;C141;1109 1166 11B0;
// (셁; 셁; 셁; 셁; 셁; ) HANGUL SYLLABLE SELG
{
std::array<uint32_t, 1> const c1 = {{ 0xC141 }};
std::array<uint32_t, 1> const c2 = {{ 0xC141 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11B0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC141 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11B0 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_058)
{
// C142;C142;1109 1166 11B1;C142;1109 1166 11B1;
// (셂; 셂; 셂; 셂; 셂; ) HANGUL SYLLABLE SELM
{
std::array<uint32_t, 1> const c1 = {{ 0xC142 }};
std::array<uint32_t, 1> const c2 = {{ 0xC142 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11B1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC142 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11B1 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_059)
{
// C143;C143;1109 1166 11B2;C143;1109 1166 11B2;
// (셃; 셃; 셃; 셃; 셃; ) HANGUL SYLLABLE SELB
{
std::array<uint32_t, 1> const c1 = {{ 0xC143 }};
std::array<uint32_t, 1> const c2 = {{ 0xC143 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11B2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC143 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11B2 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_060)
{
// C144;C144;1109 1166 11B3;C144;1109 1166 11B3;
// (셄; 셄; 셄; 셄; 셄; ) HANGUL SYLLABLE SELS
{
std::array<uint32_t, 1> const c1 = {{ 0xC144 }};
std::array<uint32_t, 1> const c2 = {{ 0xC144 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11B3 }};
std::array<uint32_t, 1> const c4 = {{ 0xC144 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11B3 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_061)
{
// C145;C145;1109 1166 11B4;C145;1109 1166 11B4;
// (셅; 셅; 셅; 셅; 셅; ) HANGUL SYLLABLE SELT
{
std::array<uint32_t, 1> const c1 = {{ 0xC145 }};
std::array<uint32_t, 1> const c2 = {{ 0xC145 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11B4 }};
std::array<uint32_t, 1> const c4 = {{ 0xC145 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11B4 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_062)
{
// C146;C146;1109 1166 11B5;C146;1109 1166 11B5;
// (셆; 셆; 셆; 셆; 셆; ) HANGUL SYLLABLE SELP
{
std::array<uint32_t, 1> const c1 = {{ 0xC146 }};
std::array<uint32_t, 1> const c2 = {{ 0xC146 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11B5 }};
std::array<uint32_t, 1> const c4 = {{ 0xC146 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11B5 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_063)
{
// C147;C147;1109 1166 11B6;C147;1109 1166 11B6;
// (셇; 셇; 셇; 셇; 셇; ) HANGUL SYLLABLE SELH
{
std::array<uint32_t, 1> const c1 = {{ 0xC147 }};
std::array<uint32_t, 1> const c2 = {{ 0xC147 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11B6 }};
std::array<uint32_t, 1> const c4 = {{ 0xC147 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11B6 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_064)
{
// C148;C148;1109 1166 11B7;C148;1109 1166 11B7;
// (셈; 셈; 셈; 셈; 셈; ) HANGUL SYLLABLE SEM
{
std::array<uint32_t, 1> const c1 = {{ 0xC148 }};
std::array<uint32_t, 1> const c2 = {{ 0xC148 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11B7 }};
std::array<uint32_t, 1> const c4 = {{ 0xC148 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11B7 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_065)
{
// C149;C149;1109 1166 11B8;C149;1109 1166 11B8;
// (셉; 셉; 셉; 셉; 셉; ) HANGUL SYLLABLE SEB
{
std::array<uint32_t, 1> const c1 = {{ 0xC149 }};
std::array<uint32_t, 1> const c2 = {{ 0xC149 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11B8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC149 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11B8 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_066)
{
// C14A;C14A;1109 1166 11B9;C14A;1109 1166 11B9;
// (셊; 셊; 셊; 셊; 셊; ) HANGUL SYLLABLE SEBS
{
std::array<uint32_t, 1> const c1 = {{ 0xC14A }};
std::array<uint32_t, 1> const c2 = {{ 0xC14A }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11B9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC14A }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11B9 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_067)
{
// C14B;C14B;1109 1166 11BA;C14B;1109 1166 11BA;
// (셋; 셋; 셋; 셋; 셋; ) HANGUL SYLLABLE SES
{
std::array<uint32_t, 1> const c1 = {{ 0xC14B }};
std::array<uint32_t, 1> const c2 = {{ 0xC14B }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11BA }};
std::array<uint32_t, 1> const c4 = {{ 0xC14B }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11BA }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_068)
{
// C14C;C14C;1109 1166 11BB;C14C;1109 1166 11BB;
// (셌; 셌; 셌; 셌; 셌; ) HANGUL SYLLABLE SESS
{
std::array<uint32_t, 1> const c1 = {{ 0xC14C }};
std::array<uint32_t, 1> const c2 = {{ 0xC14C }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11BB }};
std::array<uint32_t, 1> const c4 = {{ 0xC14C }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11BB }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_069)
{
// C14D;C14D;1109 1166 11BC;C14D;1109 1166 11BC;
// (셍; 셍; 셍; 셍; 셍; ) HANGUL SYLLABLE SENG
{
std::array<uint32_t, 1> const c1 = {{ 0xC14D }};
std::array<uint32_t, 1> const c2 = {{ 0xC14D }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11BC }};
std::array<uint32_t, 1> const c4 = {{ 0xC14D }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11BC }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_070)
{
// C14E;C14E;1109 1166 11BD;C14E;1109 1166 11BD;
// (셎; 셎; 셎; 셎; 셎; ) HANGUL SYLLABLE SEJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC14E }};
std::array<uint32_t, 1> const c2 = {{ 0xC14E }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11BD }};
std::array<uint32_t, 1> const c4 = {{ 0xC14E }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11BD }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_071)
{
// C14F;C14F;1109 1166 11BE;C14F;1109 1166 11BE;
// (셏; 셏; 셏; 셏; 셏; ) HANGUL SYLLABLE SEC
{
std::array<uint32_t, 1> const c1 = {{ 0xC14F }};
std::array<uint32_t, 1> const c2 = {{ 0xC14F }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11BE }};
std::array<uint32_t, 1> const c4 = {{ 0xC14F }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11BE }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_072)
{
// C150;C150;1109 1166 11BF;C150;1109 1166 11BF;
// (셐; 셐; 셐; 셐; 셐; ) HANGUL SYLLABLE SEK
{
std::array<uint32_t, 1> const c1 = {{ 0xC150 }};
std::array<uint32_t, 1> const c2 = {{ 0xC150 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11BF }};
std::array<uint32_t, 1> const c4 = {{ 0xC150 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11BF }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_073)
{
// C151;C151;1109 1166 11C0;C151;1109 1166 11C0;
// (셑; 셑; 셑; 셑; 셑; ) HANGUL SYLLABLE SET
{
std::array<uint32_t, 1> const c1 = {{ 0xC151 }};
std::array<uint32_t, 1> const c2 = {{ 0xC151 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11C0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC151 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11C0 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_074)
{
// C152;C152;1109 1166 11C1;C152;1109 1166 11C1;
// (셒; 셒; 셒; 셒; 셒; ) HANGUL SYLLABLE SEP
{
std::array<uint32_t, 1> const c1 = {{ 0xC152 }};
std::array<uint32_t, 1> const c2 = {{ 0xC152 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11C1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC152 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11C1 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_075)
{
// C153;C153;1109 1166 11C2;C153;1109 1166 11C2;
// (셓; 셓; 셓; 셓; 셓; ) HANGUL SYLLABLE SEH
{
std::array<uint32_t, 1> const c1 = {{ 0xC153 }};
std::array<uint32_t, 1> const c2 = {{ 0xC153 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1166, 0x11C2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC153 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1166, 0x11C2 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_076)
{
// C154;C154;1109 1167;C154;1109 1167;
// (셔; 셔; 셔; 셔; 셔; ) HANGUL SYLLABLE SYEO
{
std::array<uint32_t, 1> const c1 = {{ 0xC154 }};
std::array<uint32_t, 1> const c2 = {{ 0xC154 }};
std::array<uint32_t, 2> const c3 = {{ 0x1109, 0x1167 }};
std::array<uint32_t, 1> const c4 = {{ 0xC154 }};
std::array<uint32_t, 2> const c5 = {{ 0x1109, 0x1167 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_077)
{
// C155;C155;1109 1167 11A8;C155;1109 1167 11A8;
// (셕; 셕; 셕; 셕; 셕; ) HANGUL SYLLABLE SYEOG
{
std::array<uint32_t, 1> const c1 = {{ 0xC155 }};
std::array<uint32_t, 1> const c2 = {{ 0xC155 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11A8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC155 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11A8 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_078)
{
// C156;C156;1109 1167 11A9;C156;1109 1167 11A9;
// (셖; 셖; 셖; 셖; 셖; ) HANGUL SYLLABLE SYEOGG
{
std::array<uint32_t, 1> const c1 = {{ 0xC156 }};
std::array<uint32_t, 1> const c2 = {{ 0xC156 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11A9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC156 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11A9 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_079)
{
// C157;C157;1109 1167 11AA;C157;1109 1167 11AA;
// (셗; 셗; 셗; 셗; 셗; ) HANGUL SYLLABLE SYEOGS
{
std::array<uint32_t, 1> const c1 = {{ 0xC157 }};
std::array<uint32_t, 1> const c2 = {{ 0xC157 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11AA }};
std::array<uint32_t, 1> const c4 = {{ 0xC157 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11AA }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_080)
{
// C158;C158;1109 1167 11AB;C158;1109 1167 11AB;
// (션; 션; 션; 션; 션; ) HANGUL SYLLABLE SYEON
{
std::array<uint32_t, 1> const c1 = {{ 0xC158 }};
std::array<uint32_t, 1> const c2 = {{ 0xC158 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11AB }};
std::array<uint32_t, 1> const c4 = {{ 0xC158 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11AB }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_081)
{
// C159;C159;1109 1167 11AC;C159;1109 1167 11AC;
// (셙; 셙; 셙; 셙; 셙; ) HANGUL SYLLABLE SYEONJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC159 }};
std::array<uint32_t, 1> const c2 = {{ 0xC159 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11AC }};
std::array<uint32_t, 1> const c4 = {{ 0xC159 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11AC }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_082)
{
// C15A;C15A;1109 1167 11AD;C15A;1109 1167 11AD;
// (셚; 셚; 셚; 셚; 셚; ) HANGUL SYLLABLE SYEONH
{
std::array<uint32_t, 1> const c1 = {{ 0xC15A }};
std::array<uint32_t, 1> const c2 = {{ 0xC15A }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11AD }};
std::array<uint32_t, 1> const c4 = {{ 0xC15A }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11AD }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_083)
{
// C15B;C15B;1109 1167 11AE;C15B;1109 1167 11AE;
// (셛; 셛; 셛; 셛; 셛; ) HANGUL SYLLABLE SYEOD
{
std::array<uint32_t, 1> const c1 = {{ 0xC15B }};
std::array<uint32_t, 1> const c2 = {{ 0xC15B }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11AE }};
std::array<uint32_t, 1> const c4 = {{ 0xC15B }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11AE }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_084)
{
// C15C;C15C;1109 1167 11AF;C15C;1109 1167 11AF;
// (셜; 셜; 셜; 셜; 셜; ) HANGUL SYLLABLE SYEOL
{
std::array<uint32_t, 1> const c1 = {{ 0xC15C }};
std::array<uint32_t, 1> const c2 = {{ 0xC15C }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11AF }};
std::array<uint32_t, 1> const c4 = {{ 0xC15C }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11AF }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_085)
{
// C15D;C15D;1109 1167 11B0;C15D;1109 1167 11B0;
// (셝; 셝; 셝; 셝; 셝; ) HANGUL SYLLABLE SYEOLG
{
std::array<uint32_t, 1> const c1 = {{ 0xC15D }};
std::array<uint32_t, 1> const c2 = {{ 0xC15D }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11B0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC15D }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11B0 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_086)
{
// C15E;C15E;1109 1167 11B1;C15E;1109 1167 11B1;
// (셞; 셞; 셞; 셞; 셞; ) HANGUL SYLLABLE SYEOLM
{
std::array<uint32_t, 1> const c1 = {{ 0xC15E }};
std::array<uint32_t, 1> const c2 = {{ 0xC15E }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11B1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC15E }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11B1 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_087)
{
// C15F;C15F;1109 1167 11B2;C15F;1109 1167 11B2;
// (셟; 셟; 셟; 셟; 셟; ) HANGUL SYLLABLE SYEOLB
{
std::array<uint32_t, 1> const c1 = {{ 0xC15F }};
std::array<uint32_t, 1> const c2 = {{ 0xC15F }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11B2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC15F }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11B2 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_088)
{
// C160;C160;1109 1167 11B3;C160;1109 1167 11B3;
// (셠; 셠; 셠; 셠; 셠; ) HANGUL SYLLABLE SYEOLS
{
std::array<uint32_t, 1> const c1 = {{ 0xC160 }};
std::array<uint32_t, 1> const c2 = {{ 0xC160 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11B3 }};
std::array<uint32_t, 1> const c4 = {{ 0xC160 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11B3 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_089)
{
// C161;C161;1109 1167 11B4;C161;1109 1167 11B4;
// (셡; 셡; 셡; 셡; 셡; ) HANGUL SYLLABLE SYEOLT
{
std::array<uint32_t, 1> const c1 = {{ 0xC161 }};
std::array<uint32_t, 1> const c2 = {{ 0xC161 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11B4 }};
std::array<uint32_t, 1> const c4 = {{ 0xC161 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11B4 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_090)
{
// C162;C162;1109 1167 11B5;C162;1109 1167 11B5;
// (셢; 셢; 셢; 셢; 셢; ) HANGUL SYLLABLE SYEOLP
{
std::array<uint32_t, 1> const c1 = {{ 0xC162 }};
std::array<uint32_t, 1> const c2 = {{ 0xC162 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11B5 }};
std::array<uint32_t, 1> const c4 = {{ 0xC162 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11B5 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_091)
{
// C163;C163;1109 1167 11B6;C163;1109 1167 11B6;
// (셣; 셣; 셣; 셣; 셣; ) HANGUL SYLLABLE SYEOLH
{
std::array<uint32_t, 1> const c1 = {{ 0xC163 }};
std::array<uint32_t, 1> const c2 = {{ 0xC163 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11B6 }};
std::array<uint32_t, 1> const c4 = {{ 0xC163 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11B6 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_092)
{
// C164;C164;1109 1167 11B7;C164;1109 1167 11B7;
// (셤; 셤; 셤; 셤; 셤; ) HANGUL SYLLABLE SYEOM
{
std::array<uint32_t, 1> const c1 = {{ 0xC164 }};
std::array<uint32_t, 1> const c2 = {{ 0xC164 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11B7 }};
std::array<uint32_t, 1> const c4 = {{ 0xC164 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11B7 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_093)
{
// C165;C165;1109 1167 11B8;C165;1109 1167 11B8;
// (셥; 셥; 셥; 셥; 셥; ) HANGUL SYLLABLE SYEOB
{
std::array<uint32_t, 1> const c1 = {{ 0xC165 }};
std::array<uint32_t, 1> const c2 = {{ 0xC165 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11B8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC165 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11B8 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_094)
{
// C166;C166;1109 1167 11B9;C166;1109 1167 11B9;
// (셦; 셦; 셦; 셦; 셦; ) HANGUL SYLLABLE SYEOBS
{
std::array<uint32_t, 1> const c1 = {{ 0xC166 }};
std::array<uint32_t, 1> const c2 = {{ 0xC166 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11B9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC166 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11B9 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_095)
{
// C167;C167;1109 1167 11BA;C167;1109 1167 11BA;
// (셧; 셧; 셧; 셧; 셧; ) HANGUL SYLLABLE SYEOS
{
std::array<uint32_t, 1> const c1 = {{ 0xC167 }};
std::array<uint32_t, 1> const c2 = {{ 0xC167 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11BA }};
std::array<uint32_t, 1> const c4 = {{ 0xC167 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11BA }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_096)
{
// C168;C168;1109 1167 11BB;C168;1109 1167 11BB;
// (셨; 셨; 셨; 셨; 셨; ) HANGUL SYLLABLE SYEOSS
{
std::array<uint32_t, 1> const c1 = {{ 0xC168 }};
std::array<uint32_t, 1> const c2 = {{ 0xC168 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11BB }};
std::array<uint32_t, 1> const c4 = {{ 0xC168 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11BB }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_097)
{
// C169;C169;1109 1167 11BC;C169;1109 1167 11BC;
// (셩; 셩; 셩; 셩; 셩; ) HANGUL SYLLABLE SYEONG
{
std::array<uint32_t, 1> const c1 = {{ 0xC169 }};
std::array<uint32_t, 1> const c2 = {{ 0xC169 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11BC }};
std::array<uint32_t, 1> const c4 = {{ 0xC169 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11BC }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_098)
{
// C16A;C16A;1109 1167 11BD;C16A;1109 1167 11BD;
// (셪; 셪; 셪; 셪; 셪; ) HANGUL SYLLABLE SYEOJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC16A }};
std::array<uint32_t, 1> const c2 = {{ 0xC16A }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11BD }};
std::array<uint32_t, 1> const c4 = {{ 0xC16A }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11BD }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_099)
{
// C16B;C16B;1109 1167 11BE;C16B;1109 1167 11BE;
// (셫; 셫; 셫; 셫; 셫; ) HANGUL SYLLABLE SYEOC
{
std::array<uint32_t, 1> const c1 = {{ 0xC16B }};
std::array<uint32_t, 1> const c2 = {{ 0xC16B }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11BE }};
std::array<uint32_t, 1> const c4 = {{ 0xC16B }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11BE }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_100)
{
// C16C;C16C;1109 1167 11BF;C16C;1109 1167 11BF;
// (셬; 셬; 셬; 셬; 셬; ) HANGUL SYLLABLE SYEOK
{
std::array<uint32_t, 1> const c1 = {{ 0xC16C }};
std::array<uint32_t, 1> const c2 = {{ 0xC16C }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11BF }};
std::array<uint32_t, 1> const c4 = {{ 0xC16C }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11BF }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_101)
{
// C16D;C16D;1109 1167 11C0;C16D;1109 1167 11C0;
// (셭; 셭; 셭; 셭; 셭; ) HANGUL SYLLABLE SYEOT
{
std::array<uint32_t, 1> const c1 = {{ 0xC16D }};
std::array<uint32_t, 1> const c2 = {{ 0xC16D }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11C0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC16D }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11C0 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_102)
{
// C16E;C16E;1109 1167 11C1;C16E;1109 1167 11C1;
// (셮; 셮; 셮; 셮; 셮; ) HANGUL SYLLABLE SYEOP
{
std::array<uint32_t, 1> const c1 = {{ 0xC16E }};
std::array<uint32_t, 1> const c2 = {{ 0xC16E }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11C1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC16E }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11C1 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_103)
{
// C16F;C16F;1109 1167 11C2;C16F;1109 1167 11C2;
// (셯; 셯; 셯; 셯; 셯; ) HANGUL SYLLABLE SYEOH
{
std::array<uint32_t, 1> const c1 = {{ 0xC16F }};
std::array<uint32_t, 1> const c2 = {{ 0xC16F }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1167, 0x11C2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC16F }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1167, 0x11C2 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_104)
{
// C170;C170;1109 1168;C170;1109 1168;
// (셰; 셰; 셰; 셰; 셰; ) HANGUL SYLLABLE SYE
{
std::array<uint32_t, 1> const c1 = {{ 0xC170 }};
std::array<uint32_t, 1> const c2 = {{ 0xC170 }};
std::array<uint32_t, 2> const c3 = {{ 0x1109, 0x1168 }};
std::array<uint32_t, 1> const c4 = {{ 0xC170 }};
std::array<uint32_t, 2> const c5 = {{ 0x1109, 0x1168 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_105)
{
// C171;C171;1109 1168 11A8;C171;1109 1168 11A8;
// (셱; 셱; 셱; 셱; 셱; ) HANGUL SYLLABLE SYEG
{
std::array<uint32_t, 1> const c1 = {{ 0xC171 }};
std::array<uint32_t, 1> const c2 = {{ 0xC171 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11A8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC171 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11A8 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_106)
{
// C172;C172;1109 1168 11A9;C172;1109 1168 11A9;
// (셲; 셲; 셲; 셲; 셲; ) HANGUL SYLLABLE SYEGG
{
std::array<uint32_t, 1> const c1 = {{ 0xC172 }};
std::array<uint32_t, 1> const c2 = {{ 0xC172 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11A9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC172 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11A9 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_107)
{
// C173;C173;1109 1168 11AA;C173;1109 1168 11AA;
// (셳; 셳; 셳; 셳; 셳; ) HANGUL SYLLABLE SYEGS
{
std::array<uint32_t, 1> const c1 = {{ 0xC173 }};
std::array<uint32_t, 1> const c2 = {{ 0xC173 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11AA }};
std::array<uint32_t, 1> const c4 = {{ 0xC173 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11AA }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_108)
{
// C174;C174;1109 1168 11AB;C174;1109 1168 11AB;
// (셴; 셴; 셴; 셴; 셴; ) HANGUL SYLLABLE SYEN
{
std::array<uint32_t, 1> const c1 = {{ 0xC174 }};
std::array<uint32_t, 1> const c2 = {{ 0xC174 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11AB }};
std::array<uint32_t, 1> const c4 = {{ 0xC174 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11AB }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_109)
{
// C175;C175;1109 1168 11AC;C175;1109 1168 11AC;
// (셵; 셵; 셵; 셵; 셵; ) HANGUL SYLLABLE SYENJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC175 }};
std::array<uint32_t, 1> const c2 = {{ 0xC175 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11AC }};
std::array<uint32_t, 1> const c4 = {{ 0xC175 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11AC }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_110)
{
// C176;C176;1109 1168 11AD;C176;1109 1168 11AD;
// (셶; 셶; 셶; 셶; 셶; ) HANGUL SYLLABLE SYENH
{
std::array<uint32_t, 1> const c1 = {{ 0xC176 }};
std::array<uint32_t, 1> const c2 = {{ 0xC176 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11AD }};
std::array<uint32_t, 1> const c4 = {{ 0xC176 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11AD }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_111)
{
// C177;C177;1109 1168 11AE;C177;1109 1168 11AE;
// (셷; 셷; 셷; 셷; 셷; ) HANGUL SYLLABLE SYED
{
std::array<uint32_t, 1> const c1 = {{ 0xC177 }};
std::array<uint32_t, 1> const c2 = {{ 0xC177 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11AE }};
std::array<uint32_t, 1> const c4 = {{ 0xC177 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11AE }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_112)
{
// C178;C178;1109 1168 11AF;C178;1109 1168 11AF;
// (셸; 셸; 셸; 셸; 셸; ) HANGUL SYLLABLE SYEL
{
std::array<uint32_t, 1> const c1 = {{ 0xC178 }};
std::array<uint32_t, 1> const c2 = {{ 0xC178 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11AF }};
std::array<uint32_t, 1> const c4 = {{ 0xC178 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11AF }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_113)
{
// C179;C179;1109 1168 11B0;C179;1109 1168 11B0;
// (셹; 셹; 셹; 셹; 셹; ) HANGUL SYLLABLE SYELG
{
std::array<uint32_t, 1> const c1 = {{ 0xC179 }};
std::array<uint32_t, 1> const c2 = {{ 0xC179 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11B0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC179 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11B0 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_114)
{
// C17A;C17A;1109 1168 11B1;C17A;1109 1168 11B1;
// (셺; 셺; 셺; 셺; 셺; ) HANGUL SYLLABLE SYELM
{
std::array<uint32_t, 1> const c1 = {{ 0xC17A }};
std::array<uint32_t, 1> const c2 = {{ 0xC17A }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11B1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC17A }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11B1 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_115)
{
// C17B;C17B;1109 1168 11B2;C17B;1109 1168 11B2;
// (셻; 셻; 셻; 셻; 셻; ) HANGUL SYLLABLE SYELB
{
std::array<uint32_t, 1> const c1 = {{ 0xC17B }};
std::array<uint32_t, 1> const c2 = {{ 0xC17B }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11B2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC17B }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11B2 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_116)
{
// C17C;C17C;1109 1168 11B3;C17C;1109 1168 11B3;
// (셼; 셼; 셼; 셼; 셼; ) HANGUL SYLLABLE SYELS
{
std::array<uint32_t, 1> const c1 = {{ 0xC17C }};
std::array<uint32_t, 1> const c2 = {{ 0xC17C }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11B3 }};
std::array<uint32_t, 1> const c4 = {{ 0xC17C }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11B3 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_117)
{
// C17D;C17D;1109 1168 11B4;C17D;1109 1168 11B4;
// (셽; 셽; 셽; 셽; 셽; ) HANGUL SYLLABLE SYELT
{
std::array<uint32_t, 1> const c1 = {{ 0xC17D }};
std::array<uint32_t, 1> const c2 = {{ 0xC17D }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11B4 }};
std::array<uint32_t, 1> const c4 = {{ 0xC17D }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11B4 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_118)
{
// C17E;C17E;1109 1168 11B5;C17E;1109 1168 11B5;
// (셾; 셾; 셾; 셾; 셾; ) HANGUL SYLLABLE SYELP
{
std::array<uint32_t, 1> const c1 = {{ 0xC17E }};
std::array<uint32_t, 1> const c2 = {{ 0xC17E }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11B5 }};
std::array<uint32_t, 1> const c4 = {{ 0xC17E }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11B5 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_119)
{
// C17F;C17F;1109 1168 11B6;C17F;1109 1168 11B6;
// (셿; 셿; 셿; 셿; 셿; ) HANGUL SYLLABLE SYELH
{
std::array<uint32_t, 1> const c1 = {{ 0xC17F }};
std::array<uint32_t, 1> const c2 = {{ 0xC17F }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11B6 }};
std::array<uint32_t, 1> const c4 = {{ 0xC17F }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11B6 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_120)
{
// C180;C180;1109 1168 11B7;C180;1109 1168 11B7;
// (솀; 솀; 솀; 솀; 솀; ) HANGUL SYLLABLE SYEM
{
std::array<uint32_t, 1> const c1 = {{ 0xC180 }};
std::array<uint32_t, 1> const c2 = {{ 0xC180 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11B7 }};
std::array<uint32_t, 1> const c4 = {{ 0xC180 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11B7 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_121)
{
// C181;C181;1109 1168 11B8;C181;1109 1168 11B8;
// (솁; 솁; 솁; 솁; 솁; ) HANGUL SYLLABLE SYEB
{
std::array<uint32_t, 1> const c1 = {{ 0xC181 }};
std::array<uint32_t, 1> const c2 = {{ 0xC181 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11B8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC181 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11B8 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_122)
{
// C182;C182;1109 1168 11B9;C182;1109 1168 11B9;
// (솂; 솂; 솂; 솂; 솂; ) HANGUL SYLLABLE SYEBS
{
std::array<uint32_t, 1> const c1 = {{ 0xC182 }};
std::array<uint32_t, 1> const c2 = {{ 0xC182 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11B9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC182 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11B9 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_123)
{
// C183;C183;1109 1168 11BA;C183;1109 1168 11BA;
// (솃; 솃; 솃; 솃; 솃; ) HANGUL SYLLABLE SYES
{
std::array<uint32_t, 1> const c1 = {{ 0xC183 }};
std::array<uint32_t, 1> const c2 = {{ 0xC183 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11BA }};
std::array<uint32_t, 1> const c4 = {{ 0xC183 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11BA }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_124)
{
// C184;C184;1109 1168 11BB;C184;1109 1168 11BB;
// (솄; 솄; 솄; 솄; 솄; ) HANGUL SYLLABLE SYESS
{
std::array<uint32_t, 1> const c1 = {{ 0xC184 }};
std::array<uint32_t, 1> const c2 = {{ 0xC184 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11BB }};
std::array<uint32_t, 1> const c4 = {{ 0xC184 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11BB }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_125)
{
// C185;C185;1109 1168 11BC;C185;1109 1168 11BC;
// (솅; 솅; 솅; 솅; 솅; ) HANGUL SYLLABLE SYENG
{
std::array<uint32_t, 1> const c1 = {{ 0xC185 }};
std::array<uint32_t, 1> const c2 = {{ 0xC185 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11BC }};
std::array<uint32_t, 1> const c4 = {{ 0xC185 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11BC }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_126)
{
// C186;C186;1109 1168 11BD;C186;1109 1168 11BD;
// (솆; 솆; 솆; 솆; 솆; ) HANGUL SYLLABLE SYEJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC186 }};
std::array<uint32_t, 1> const c2 = {{ 0xC186 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11BD }};
std::array<uint32_t, 1> const c4 = {{ 0xC186 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11BD }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_127)
{
// C187;C187;1109 1168 11BE;C187;1109 1168 11BE;
// (솇; 솇; 솇; 솇; 솇; ) HANGUL SYLLABLE SYEC
{
std::array<uint32_t, 1> const c1 = {{ 0xC187 }};
std::array<uint32_t, 1> const c2 = {{ 0xC187 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11BE }};
std::array<uint32_t, 1> const c4 = {{ 0xC187 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11BE }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_128)
{
// C188;C188;1109 1168 11BF;C188;1109 1168 11BF;
// (솈; 솈; 솈; 솈; 솈; ) HANGUL SYLLABLE SYEK
{
std::array<uint32_t, 1> const c1 = {{ 0xC188 }};
std::array<uint32_t, 1> const c2 = {{ 0xC188 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11BF }};
std::array<uint32_t, 1> const c4 = {{ 0xC188 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11BF }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_129)
{
// C189;C189;1109 1168 11C0;C189;1109 1168 11C0;
// (솉; 솉; 솉; 솉; 솉; ) HANGUL SYLLABLE SYET
{
std::array<uint32_t, 1> const c1 = {{ 0xC189 }};
std::array<uint32_t, 1> const c2 = {{ 0xC189 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11C0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC189 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11C0 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_130)
{
// C18A;C18A;1109 1168 11C1;C18A;1109 1168 11C1;
// (솊; 솊; 솊; 솊; 솊; ) HANGUL SYLLABLE SYEP
{
std::array<uint32_t, 1> const c1 = {{ 0xC18A }};
std::array<uint32_t, 1> const c2 = {{ 0xC18A }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11C1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC18A }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11C1 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_131)
{
// C18B;C18B;1109 1168 11C2;C18B;1109 1168 11C2;
// (솋; 솋; 솋; 솋; 솋; ) HANGUL SYLLABLE SYEH
{
std::array<uint32_t, 1> const c1 = {{ 0xC18B }};
std::array<uint32_t, 1> const c2 = {{ 0xC18B }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1168, 0x11C2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC18B }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1168, 0x11C2 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_132)
{
// C18C;C18C;1109 1169;C18C;1109 1169;
// (소; 소; 소; 소; 소; ) HANGUL SYLLABLE SO
{
std::array<uint32_t, 1> const c1 = {{ 0xC18C }};
std::array<uint32_t, 1> const c2 = {{ 0xC18C }};
std::array<uint32_t, 2> const c3 = {{ 0x1109, 0x1169 }};
std::array<uint32_t, 1> const c4 = {{ 0xC18C }};
std::array<uint32_t, 2> const c5 = {{ 0x1109, 0x1169 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_133)
{
// C18D;C18D;1109 1169 11A8;C18D;1109 1169 11A8;
// (속; 속; 속; 속; 속; ) HANGUL SYLLABLE SOG
{
std::array<uint32_t, 1> const c1 = {{ 0xC18D }};
std::array<uint32_t, 1> const c2 = {{ 0xC18D }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11A8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC18D }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11A8 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_134)
{
// C18E;C18E;1109 1169 11A9;C18E;1109 1169 11A9;
// (솎; 솎; 솎; 솎; 솎; ) HANGUL SYLLABLE SOGG
{
std::array<uint32_t, 1> const c1 = {{ 0xC18E }};
std::array<uint32_t, 1> const c2 = {{ 0xC18E }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11A9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC18E }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11A9 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_135)
{
// C18F;C18F;1109 1169 11AA;C18F;1109 1169 11AA;
// (솏; 솏; 솏; 솏; 솏; ) HANGUL SYLLABLE SOGS
{
std::array<uint32_t, 1> const c1 = {{ 0xC18F }};
std::array<uint32_t, 1> const c2 = {{ 0xC18F }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11AA }};
std::array<uint32_t, 1> const c4 = {{ 0xC18F }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11AA }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_136)
{
// C190;C190;1109 1169 11AB;C190;1109 1169 11AB;
// (손; 손; 손; 손; 손; ) HANGUL SYLLABLE SON
{
std::array<uint32_t, 1> const c1 = {{ 0xC190 }};
std::array<uint32_t, 1> const c2 = {{ 0xC190 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11AB }};
std::array<uint32_t, 1> const c4 = {{ 0xC190 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11AB }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_137)
{
// C191;C191;1109 1169 11AC;C191;1109 1169 11AC;
// (솑; 솑; 솑; 솑; 솑; ) HANGUL SYLLABLE SONJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC191 }};
std::array<uint32_t, 1> const c2 = {{ 0xC191 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11AC }};
std::array<uint32_t, 1> const c4 = {{ 0xC191 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11AC }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_138)
{
// C192;C192;1109 1169 11AD;C192;1109 1169 11AD;
// (솒; 솒; 솒; 솒; 솒; ) HANGUL SYLLABLE SONH
{
std::array<uint32_t, 1> const c1 = {{ 0xC192 }};
std::array<uint32_t, 1> const c2 = {{ 0xC192 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11AD }};
std::array<uint32_t, 1> const c4 = {{ 0xC192 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11AD }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_139)
{
// C193;C193;1109 1169 11AE;C193;1109 1169 11AE;
// (솓; 솓; 솓; 솓; 솓; ) HANGUL SYLLABLE SOD
{
std::array<uint32_t, 1> const c1 = {{ 0xC193 }};
std::array<uint32_t, 1> const c2 = {{ 0xC193 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11AE }};
std::array<uint32_t, 1> const c4 = {{ 0xC193 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11AE }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_140)
{
// C194;C194;1109 1169 11AF;C194;1109 1169 11AF;
// (솔; 솔; 솔; 솔; 솔; ) HANGUL SYLLABLE SOL
{
std::array<uint32_t, 1> const c1 = {{ 0xC194 }};
std::array<uint32_t, 1> const c2 = {{ 0xC194 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11AF }};
std::array<uint32_t, 1> const c4 = {{ 0xC194 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11AF }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_141)
{
// C195;C195;1109 1169 11B0;C195;1109 1169 11B0;
// (솕; 솕; 솕; 솕; 솕; ) HANGUL SYLLABLE SOLG
{
std::array<uint32_t, 1> const c1 = {{ 0xC195 }};
std::array<uint32_t, 1> const c2 = {{ 0xC195 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11B0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC195 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11B0 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_142)
{
// C196;C196;1109 1169 11B1;C196;1109 1169 11B1;
// (솖; 솖; 솖; 솖; 솖; ) HANGUL SYLLABLE SOLM
{
std::array<uint32_t, 1> const c1 = {{ 0xC196 }};
std::array<uint32_t, 1> const c2 = {{ 0xC196 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11B1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC196 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11B1 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_143)
{
// C197;C197;1109 1169 11B2;C197;1109 1169 11B2;
// (솗; 솗; 솗; 솗; 솗; ) HANGUL SYLLABLE SOLB
{
std::array<uint32_t, 1> const c1 = {{ 0xC197 }};
std::array<uint32_t, 1> const c2 = {{ 0xC197 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11B2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC197 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11B2 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_144)
{
// C198;C198;1109 1169 11B3;C198;1109 1169 11B3;
// (솘; 솘; 솘; 솘; 솘; ) HANGUL SYLLABLE SOLS
{
std::array<uint32_t, 1> const c1 = {{ 0xC198 }};
std::array<uint32_t, 1> const c2 = {{ 0xC198 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11B3 }};
std::array<uint32_t, 1> const c4 = {{ 0xC198 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11B3 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_145)
{
// C199;C199;1109 1169 11B4;C199;1109 1169 11B4;
// (솙; 솙; 솙; 솙; 솙; ) HANGUL SYLLABLE SOLT
{
std::array<uint32_t, 1> const c1 = {{ 0xC199 }};
std::array<uint32_t, 1> const c2 = {{ 0xC199 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11B4 }};
std::array<uint32_t, 1> const c4 = {{ 0xC199 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11B4 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_146)
{
// C19A;C19A;1109 1169 11B5;C19A;1109 1169 11B5;
// (솚; 솚; 솚; 솚; 솚; ) HANGUL SYLLABLE SOLP
{
std::array<uint32_t, 1> const c1 = {{ 0xC19A }};
std::array<uint32_t, 1> const c2 = {{ 0xC19A }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11B5 }};
std::array<uint32_t, 1> const c4 = {{ 0xC19A }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11B5 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_147)
{
// C19B;C19B;1109 1169 11B6;C19B;1109 1169 11B6;
// (솛; 솛; 솛; 솛; 솛; ) HANGUL SYLLABLE SOLH
{
std::array<uint32_t, 1> const c1 = {{ 0xC19B }};
std::array<uint32_t, 1> const c2 = {{ 0xC19B }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11B6 }};
std::array<uint32_t, 1> const c4 = {{ 0xC19B }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11B6 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_148)
{
// C19C;C19C;1109 1169 11B7;C19C;1109 1169 11B7;
// (솜; 솜; 솜; 솜; 솜; ) HANGUL SYLLABLE SOM
{
std::array<uint32_t, 1> const c1 = {{ 0xC19C }};
std::array<uint32_t, 1> const c2 = {{ 0xC19C }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11B7 }};
std::array<uint32_t, 1> const c4 = {{ 0xC19C }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11B7 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_149)
{
// C19D;C19D;1109 1169 11B8;C19D;1109 1169 11B8;
// (솝; 솝; 솝; 솝; 솝; ) HANGUL SYLLABLE SOB
{
std::array<uint32_t, 1> const c1 = {{ 0xC19D }};
std::array<uint32_t, 1> const c2 = {{ 0xC19D }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11B8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC19D }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11B8 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_150)
{
// C19E;C19E;1109 1169 11B9;C19E;1109 1169 11B9;
// (솞; 솞; 솞; 솞; 솞; ) HANGUL SYLLABLE SOBS
{
std::array<uint32_t, 1> const c1 = {{ 0xC19E }};
std::array<uint32_t, 1> const c2 = {{ 0xC19E }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11B9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC19E }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11B9 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_151)
{
// C19F;C19F;1109 1169 11BA;C19F;1109 1169 11BA;
// (솟; 솟; 솟; 솟; 솟; ) HANGUL SYLLABLE SOS
{
std::array<uint32_t, 1> const c1 = {{ 0xC19F }};
std::array<uint32_t, 1> const c2 = {{ 0xC19F }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11BA }};
std::array<uint32_t, 1> const c4 = {{ 0xC19F }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11BA }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_152)
{
// C1A0;C1A0;1109 1169 11BB;C1A0;1109 1169 11BB;
// (솠; 솠; 솠; 솠; 솠; ) HANGUL SYLLABLE SOSS
{
std::array<uint32_t, 1> const c1 = {{ 0xC1A0 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1A0 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11BB }};
std::array<uint32_t, 1> const c4 = {{ 0xC1A0 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11BB }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_153)
{
// C1A1;C1A1;1109 1169 11BC;C1A1;1109 1169 11BC;
// (송; 송; 송; 송; 송; ) HANGUL SYLLABLE SONG
{
std::array<uint32_t, 1> const c1 = {{ 0xC1A1 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1A1 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11BC }};
std::array<uint32_t, 1> const c4 = {{ 0xC1A1 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11BC }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_154)
{
// C1A2;C1A2;1109 1169 11BD;C1A2;1109 1169 11BD;
// (솢; 솢; 솢; 솢; 솢; ) HANGUL SYLLABLE SOJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC1A2 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1A2 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11BD }};
std::array<uint32_t, 1> const c4 = {{ 0xC1A2 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11BD }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_155)
{
// C1A3;C1A3;1109 1169 11BE;C1A3;1109 1169 11BE;
// (솣; 솣; 솣; 솣; 솣; ) HANGUL SYLLABLE SOC
{
std::array<uint32_t, 1> const c1 = {{ 0xC1A3 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1A3 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11BE }};
std::array<uint32_t, 1> const c4 = {{ 0xC1A3 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11BE }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_156)
{
// C1A4;C1A4;1109 1169 11BF;C1A4;1109 1169 11BF;
// (솤; 솤; 솤; 솤; 솤; ) HANGUL SYLLABLE SOK
{
std::array<uint32_t, 1> const c1 = {{ 0xC1A4 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1A4 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11BF }};
std::array<uint32_t, 1> const c4 = {{ 0xC1A4 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11BF }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_157)
{
// C1A5;C1A5;1109 1169 11C0;C1A5;1109 1169 11C0;
// (솥; 솥; 솥; 솥; 솥; ) HANGUL SYLLABLE SOT
{
std::array<uint32_t, 1> const c1 = {{ 0xC1A5 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1A5 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11C0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1A5 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11C0 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_158)
{
// C1A6;C1A6;1109 1169 11C1;C1A6;1109 1169 11C1;
// (솦; 솦; 솦; 솦; 솦; ) HANGUL SYLLABLE SOP
{
std::array<uint32_t, 1> const c1 = {{ 0xC1A6 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1A6 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11C1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1A6 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11C1 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_159)
{
// C1A7;C1A7;1109 1169 11C2;C1A7;1109 1169 11C2;
// (솧; 솧; 솧; 솧; 솧; ) HANGUL SYLLABLE SOH
{
std::array<uint32_t, 1> const c1 = {{ 0xC1A7 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1A7 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x1169, 0x11C2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1A7 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x1169, 0x11C2 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_160)
{
// C1A8;C1A8;1109 116A;C1A8;1109 116A;
// (솨; 솨; 솨; 솨; 솨; ) HANGUL SYLLABLE SWA
{
std::array<uint32_t, 1> const c1 = {{ 0xC1A8 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1A8 }};
std::array<uint32_t, 2> const c3 = {{ 0x1109, 0x116A }};
std::array<uint32_t, 1> const c4 = {{ 0xC1A8 }};
std::array<uint32_t, 2> const c5 = {{ 0x1109, 0x116A }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_161)
{
// C1A9;C1A9;1109 116A 11A8;C1A9;1109 116A 11A8;
// (솩; 솩; 솩; 솩; 솩; ) HANGUL SYLLABLE SWAG
{
std::array<uint32_t, 1> const c1 = {{ 0xC1A9 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1A9 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11A8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1A9 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11A8 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_162)
{
// C1AA;C1AA;1109 116A 11A9;C1AA;1109 116A 11A9;
// (솪; 솪; 솪; 솪; 솪; ) HANGUL SYLLABLE SWAGG
{
std::array<uint32_t, 1> const c1 = {{ 0xC1AA }};
std::array<uint32_t, 1> const c2 = {{ 0xC1AA }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11A9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1AA }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11A9 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_163)
{
// C1AB;C1AB;1109 116A 11AA;C1AB;1109 116A 11AA;
// (솫; 솫; 솫; 솫; 솫; ) HANGUL SYLLABLE SWAGS
{
std::array<uint32_t, 1> const c1 = {{ 0xC1AB }};
std::array<uint32_t, 1> const c2 = {{ 0xC1AB }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11AA }};
std::array<uint32_t, 1> const c4 = {{ 0xC1AB }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11AA }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_164)
{
// C1AC;C1AC;1109 116A 11AB;C1AC;1109 116A 11AB;
// (솬; 솬; 솬; 솬; 솬; ) HANGUL SYLLABLE SWAN
{
std::array<uint32_t, 1> const c1 = {{ 0xC1AC }};
std::array<uint32_t, 1> const c2 = {{ 0xC1AC }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11AB }};
std::array<uint32_t, 1> const c4 = {{ 0xC1AC }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11AB }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_165)
{
// C1AD;C1AD;1109 116A 11AC;C1AD;1109 116A 11AC;
// (솭; 솭; 솭; 솭; 솭; ) HANGUL SYLLABLE SWANJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC1AD }};
std::array<uint32_t, 1> const c2 = {{ 0xC1AD }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11AC }};
std::array<uint32_t, 1> const c4 = {{ 0xC1AD }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11AC }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_166)
{
// C1AE;C1AE;1109 116A 11AD;C1AE;1109 116A 11AD;
// (솮; 솮; 솮; 솮; 솮; ) HANGUL SYLLABLE SWANH
{
std::array<uint32_t, 1> const c1 = {{ 0xC1AE }};
std::array<uint32_t, 1> const c2 = {{ 0xC1AE }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11AD }};
std::array<uint32_t, 1> const c4 = {{ 0xC1AE }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11AD }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_167)
{
// C1AF;C1AF;1109 116A 11AE;C1AF;1109 116A 11AE;
// (솯; 솯; 솯; 솯; 솯; ) HANGUL SYLLABLE SWAD
{
std::array<uint32_t, 1> const c1 = {{ 0xC1AF }};
std::array<uint32_t, 1> const c2 = {{ 0xC1AF }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11AE }};
std::array<uint32_t, 1> const c4 = {{ 0xC1AF }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11AE }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_168)
{
// C1B0;C1B0;1109 116A 11AF;C1B0;1109 116A 11AF;
// (솰; 솰; 솰; 솰; 솰; ) HANGUL SYLLABLE SWAL
{
std::array<uint32_t, 1> const c1 = {{ 0xC1B0 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1B0 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11AF }};
std::array<uint32_t, 1> const c4 = {{ 0xC1B0 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11AF }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_169)
{
// C1B1;C1B1;1109 116A 11B0;C1B1;1109 116A 11B0;
// (솱; 솱; 솱; 솱; 솱; ) HANGUL SYLLABLE SWALG
{
std::array<uint32_t, 1> const c1 = {{ 0xC1B1 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1B1 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11B0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1B1 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11B0 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_170)
{
// C1B2;C1B2;1109 116A 11B1;C1B2;1109 116A 11B1;
// (솲; 솲; 솲; 솲; 솲; ) HANGUL SYLLABLE SWALM
{
std::array<uint32_t, 1> const c1 = {{ 0xC1B2 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1B2 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11B1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1B2 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11B1 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_171)
{
// C1B3;C1B3;1109 116A 11B2;C1B3;1109 116A 11B2;
// (솳; 솳; 솳; 솳; 솳; ) HANGUL SYLLABLE SWALB
{
std::array<uint32_t, 1> const c1 = {{ 0xC1B3 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1B3 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11B2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1B3 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11B2 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_172)
{
// C1B4;C1B4;1109 116A 11B3;C1B4;1109 116A 11B3;
// (솴; 솴; 솴; 솴; 솴; ) HANGUL SYLLABLE SWALS
{
std::array<uint32_t, 1> const c1 = {{ 0xC1B4 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1B4 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11B3 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1B4 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11B3 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_173)
{
// C1B5;C1B5;1109 116A 11B4;C1B5;1109 116A 11B4;
// (솵; 솵; 솵; 솵; 솵; ) HANGUL SYLLABLE SWALT
{
std::array<uint32_t, 1> const c1 = {{ 0xC1B5 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1B5 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11B4 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1B5 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11B4 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_174)
{
// C1B6;C1B6;1109 116A 11B5;C1B6;1109 116A 11B5;
// (솶; 솶; 솶; 솶; 솶; ) HANGUL SYLLABLE SWALP
{
std::array<uint32_t, 1> const c1 = {{ 0xC1B6 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1B6 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11B5 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1B6 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11B5 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_175)
{
// C1B7;C1B7;1109 116A 11B6;C1B7;1109 116A 11B6;
// (솷; 솷; 솷; 솷; 솷; ) HANGUL SYLLABLE SWALH
{
std::array<uint32_t, 1> const c1 = {{ 0xC1B7 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1B7 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11B6 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1B7 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11B6 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_176)
{
// C1B8;C1B8;1109 116A 11B7;C1B8;1109 116A 11B7;
// (솸; 솸; 솸; 솸; 솸; ) HANGUL SYLLABLE SWAM
{
std::array<uint32_t, 1> const c1 = {{ 0xC1B8 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1B8 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11B7 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1B8 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11B7 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_177)
{
// C1B9;C1B9;1109 116A 11B8;C1B9;1109 116A 11B8;
// (솹; 솹; 솹; 솹; 솹; ) HANGUL SYLLABLE SWAB
{
std::array<uint32_t, 1> const c1 = {{ 0xC1B9 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1B9 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11B8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1B9 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11B8 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_178)
{
// C1BA;C1BA;1109 116A 11B9;C1BA;1109 116A 11B9;
// (솺; 솺; 솺; 솺; 솺; ) HANGUL SYLLABLE SWABS
{
std::array<uint32_t, 1> const c1 = {{ 0xC1BA }};
std::array<uint32_t, 1> const c2 = {{ 0xC1BA }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11B9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1BA }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11B9 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_179)
{
// C1BB;C1BB;1109 116A 11BA;C1BB;1109 116A 11BA;
// (솻; 솻; 솻; 솻; 솻; ) HANGUL SYLLABLE SWAS
{
std::array<uint32_t, 1> const c1 = {{ 0xC1BB }};
std::array<uint32_t, 1> const c2 = {{ 0xC1BB }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11BA }};
std::array<uint32_t, 1> const c4 = {{ 0xC1BB }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11BA }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_180)
{
// C1BC;C1BC;1109 116A 11BB;C1BC;1109 116A 11BB;
// (솼; 솼; 솼; 솼; 솼; ) HANGUL SYLLABLE SWASS
{
std::array<uint32_t, 1> const c1 = {{ 0xC1BC }};
std::array<uint32_t, 1> const c2 = {{ 0xC1BC }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11BB }};
std::array<uint32_t, 1> const c4 = {{ 0xC1BC }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11BB }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_181)
{
// C1BD;C1BD;1109 116A 11BC;C1BD;1109 116A 11BC;
// (솽; 솽; 솽; 솽; 솽; ) HANGUL SYLLABLE SWANG
{
std::array<uint32_t, 1> const c1 = {{ 0xC1BD }};
std::array<uint32_t, 1> const c2 = {{ 0xC1BD }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11BC }};
std::array<uint32_t, 1> const c4 = {{ 0xC1BD }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11BC }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_182)
{
// C1BE;C1BE;1109 116A 11BD;C1BE;1109 116A 11BD;
// (솾; 솾; 솾; 솾; 솾; ) HANGUL SYLLABLE SWAJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC1BE }};
std::array<uint32_t, 1> const c2 = {{ 0xC1BE }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11BD }};
std::array<uint32_t, 1> const c4 = {{ 0xC1BE }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11BD }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_183)
{
// C1BF;C1BF;1109 116A 11BE;C1BF;1109 116A 11BE;
// (솿; 솿; 솿; 솿; 솿; ) HANGUL SYLLABLE SWAC
{
std::array<uint32_t, 1> const c1 = {{ 0xC1BF }};
std::array<uint32_t, 1> const c2 = {{ 0xC1BF }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11BE }};
std::array<uint32_t, 1> const c4 = {{ 0xC1BF }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11BE }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_184)
{
// C1C0;C1C0;1109 116A 11BF;C1C0;1109 116A 11BF;
// (쇀; 쇀; 쇀; 쇀; 쇀; ) HANGUL SYLLABLE SWAK
{
std::array<uint32_t, 1> const c1 = {{ 0xC1C0 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1C0 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11BF }};
std::array<uint32_t, 1> const c4 = {{ 0xC1C0 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11BF }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_185)
{
// C1C1;C1C1;1109 116A 11C0;C1C1;1109 116A 11C0;
// (쇁; 쇁; 쇁; 쇁; 쇁; ) HANGUL SYLLABLE SWAT
{
std::array<uint32_t, 1> const c1 = {{ 0xC1C1 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1C1 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11C0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1C1 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11C0 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_186)
{
// C1C2;C1C2;1109 116A 11C1;C1C2;1109 116A 11C1;
// (쇂; 쇂; 쇂; 쇂; 쇂; ) HANGUL SYLLABLE SWAP
{
std::array<uint32_t, 1> const c1 = {{ 0xC1C2 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1C2 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11C1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1C2 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11C1 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_187)
{
// C1C3;C1C3;1109 116A 11C2;C1C3;1109 116A 11C2;
// (쇃; 쇃; 쇃; 쇃; 쇃; ) HANGUL SYLLABLE SWAH
{
std::array<uint32_t, 1> const c1 = {{ 0xC1C3 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1C3 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116A, 0x11C2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1C3 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116A, 0x11C2 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_188)
{
// C1C4;C1C4;1109 116B;C1C4;1109 116B;
// (쇄; 쇄; 쇄; 쇄; 쇄; ) HANGUL SYLLABLE SWAE
{
std::array<uint32_t, 1> const c1 = {{ 0xC1C4 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1C4 }};
std::array<uint32_t, 2> const c3 = {{ 0x1109, 0x116B }};
std::array<uint32_t, 1> const c4 = {{ 0xC1C4 }};
std::array<uint32_t, 2> const c5 = {{ 0x1109, 0x116B }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_189)
{
// C1C5;C1C5;1109 116B 11A8;C1C5;1109 116B 11A8;
// (쇅; 쇅; 쇅; 쇅; 쇅; ) HANGUL SYLLABLE SWAEG
{
std::array<uint32_t, 1> const c1 = {{ 0xC1C5 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1C5 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116B, 0x11A8 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1C5 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116B, 0x11A8 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_190)
{
// C1C6;C1C6;1109 116B 11A9;C1C6;1109 116B 11A9;
// (쇆; 쇆; 쇆; 쇆; 쇆; ) HANGUL SYLLABLE SWAEGG
{
std::array<uint32_t, 1> const c1 = {{ 0xC1C6 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1C6 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116B, 0x11A9 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1C6 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116B, 0x11A9 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_191)
{
// C1C7;C1C7;1109 116B 11AA;C1C7;1109 116B 11AA;
// (쇇; 쇇; 쇇; 쇇; 쇇; ) HANGUL SYLLABLE SWAEGS
{
std::array<uint32_t, 1> const c1 = {{ 0xC1C7 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1C7 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116B, 0x11AA }};
std::array<uint32_t, 1> const c4 = {{ 0xC1C7 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116B, 0x11AA }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_192)
{
// C1C8;C1C8;1109 116B 11AB;C1C8;1109 116B 11AB;
// (쇈; 쇈; 쇈; 쇈; 쇈; ) HANGUL SYLLABLE SWAEN
{
std::array<uint32_t, 1> const c1 = {{ 0xC1C8 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1C8 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116B, 0x11AB }};
std::array<uint32_t, 1> const c4 = {{ 0xC1C8 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116B, 0x11AB }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_193)
{
// C1C9;C1C9;1109 116B 11AC;C1C9;1109 116B 11AC;
// (쇉; 쇉; 쇉; 쇉; 쇉; ) HANGUL SYLLABLE SWAENJ
{
std::array<uint32_t, 1> const c1 = {{ 0xC1C9 }};
std::array<uint32_t, 1> const c2 = {{ 0xC1C9 }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116B, 0x11AC }};
std::array<uint32_t, 1> const c4 = {{ 0xC1C9 }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116B, 0x11AC }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_194)
{
// C1CA;C1CA;1109 116B 11AD;C1CA;1109 116B 11AD;
// (쇊; 쇊; 쇊; 쇊; 쇊; ) HANGUL SYLLABLE SWAENH
{
std::array<uint32_t, 1> const c1 = {{ 0xC1CA }};
std::array<uint32_t, 1> const c2 = {{ 0xC1CA }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116B, 0x11AD }};
std::array<uint32_t, 1> const c4 = {{ 0xC1CA }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116B, 0x11AD }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_195)
{
// C1CB;C1CB;1109 116B 11AE;C1CB;1109 116B 11AE;
// (쇋; 쇋; 쇋; 쇋; 쇋; ) HANGUL SYLLABLE SWAED
{
std::array<uint32_t, 1> const c1 = {{ 0xC1CB }};
std::array<uint32_t, 1> const c2 = {{ 0xC1CB }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116B, 0x11AE }};
std::array<uint32_t, 1> const c4 = {{ 0xC1CB }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116B, 0x11AE }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_196)
{
// C1CC;C1CC;1109 116B 11AF;C1CC;1109 116B 11AF;
// (쇌; 쇌; 쇌; 쇌; 쇌; ) HANGUL SYLLABLE SWAEL
{
std::array<uint32_t, 1> const c1 = {{ 0xC1CC }};
std::array<uint32_t, 1> const c2 = {{ 0xC1CC }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116B, 0x11AF }};
std::array<uint32_t, 1> const c4 = {{ 0xC1CC }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116B, 0x11AF }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_197)
{
// C1CD;C1CD;1109 116B 11B0;C1CD;1109 116B 11B0;
// (쇍; 쇍; 쇍; 쇍; 쇍; ) HANGUL SYLLABLE SWAELG
{
std::array<uint32_t, 1> const c1 = {{ 0xC1CD }};
std::array<uint32_t, 1> const c2 = {{ 0xC1CD }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116B, 0x11B0 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1CD }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116B, 0x11B0 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_198)
{
// C1CE;C1CE;1109 116B 11B1;C1CE;1109 116B 11B1;
// (쇎; 쇎; 쇎; 쇎; 쇎; ) HANGUL SYLLABLE SWAELM
{
std::array<uint32_t, 1> const c1 = {{ 0xC1CE }};
std::array<uint32_t, 1> const c2 = {{ 0xC1CE }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116B, 0x11B1 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1CE }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116B, 0x11B1 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
TEST(normalization, nfd_039_199)
{
// C1CF;C1CF;1109 116B 11B2;C1CF;1109 116B 11B2;
// (쇏; 쇏; 쇏; 쇏; 쇏; ) HANGUL SYLLABLE SWAELB
{
std::array<uint32_t, 1> const c1 = {{ 0xC1CF }};
std::array<uint32_t, 1> const c2 = {{ 0xC1CF }};
std::array<uint32_t, 3> const c3 = {{ 0x1109, 0x116B, 0x11B2 }};
std::array<uint32_t, 1> const c4 = {{ 0xC1CF }};
std::array<uint32_t, 3> const c5 = {{ 0x1109, 0x116B, 0x11B2 }};
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c2.begin(), c2.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c3.begin(), c3.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::c>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kc>(c4.begin(), c4.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::d>(c5.begin(), c5.end()));
EXPECT_TRUE(boost::text::normalized<boost::text::nf::kd>(c5.begin(), c5.end()));
{
std::string str = boost::text::to_string(c1.begin(), c1.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c2.begin(), c2.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c3.begin(), c3.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c3.size());
auto c3_it = c3.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c3_it) << "iteration " << i;
++c3_it;
++i;
}
}
{
std::string str = boost::text::to_string(c4.begin(), c4.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
{
std::string str = boost::text::to_string(c5.begin(), c5.end());
boost::text::normalize<boost::text::nf::d>(str);
auto const r = boost::text::as_utf32(str);
EXPECT_EQ(std::distance(r.begin(), r.end()), (std::ptrdiff_t)c5.size());
auto c5_it = c5.begin();
int i = 0;
for (auto x : r) {
EXPECT_EQ(x, *c5_it) << "iteration " << i;
++c5_it;
++i;
}
}
}
}
|
Food critics from Time Out visited the restaurant in 2009 , and were " disappointed " compared to their previous visit . They thought that Bosi 's food combinations just did not work , but still said that some of his desserts were " faultless " .
|
= = = Early life = = =
|
State Before: α : Type ua
β : Type ub
γ : Type uc
δ : Type ud
ι : Sort ?u.55168
inst✝ : UniformSpace α
V : Set (β × β)
hV : SymmetricRel V
x : β
⊢ ball x V = {y | (y, x) ∈ V} State After: case h
α : Type ua
β : Type ub
γ : Type uc
δ : Type ud
ι : Sort ?u.55168
inst✝ : UniformSpace α
V : Set (β × β)
hV : SymmetricRel V
x y : β
⊢ y ∈ ball x V ↔ y ∈ {y | (y, x) ∈ V} Tactic: ext y State Before: case h
α : Type ua
β : Type ub
γ : Type uc
δ : Type ud
ι : Sort ?u.55168
inst✝ : UniformSpace α
V : Set (β × β)
hV : SymmetricRel V
x y : β
⊢ y ∈ ball x V ↔ y ∈ {y | (y, x) ∈ V} State After: case h
α : Type ua
β : Type ub
γ : Type uc
δ : Type ud
ι : Sort ?u.55168
inst✝ : UniformSpace α
V : Set (β × β)
hV : SymmetricRel V
x y : β
⊢ x ∈ ball y V ↔ y ∈ {y | (y, x) ∈ V} Tactic: rw [mem_ball_symmetry hV] State Before: case h
α : Type ua
β : Type ub
γ : Type uc
δ : Type ud
ι : Sort ?u.55168
inst✝ : UniformSpace α
V : Set (β × β)
hV : SymmetricRel V
x y : β
⊢ x ∈ ball y V ↔ y ∈ {y | (y, x) ∈ V} State After: no goals Tactic: exact Iff.rfl
|
{-# OPTIONS --safe #-}
module Definition.Conversion.EqRelInstance where
open import Definition.Untyped
open import Definition.Untyped.Properties using (wkSingleSubstId)
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Typed.Weakening using (_∷_⊆_; wkEq; step; id)
open import Definition.Conversion
open import Definition.Conversion.Reduction
open import Definition.Conversion.Universe
open import Definition.Conversion.Stability
open import Definition.Conversion.Soundness
open import Definition.Conversion.Lift
open import Definition.Conversion.Conversion
open import Definition.Conversion.Transitivity
open import Definition.Conversion.Weakening
open import Definition.Conversion.Whnf
open import Definition.Typed.EqualityRelation
open import Definition.Typed.Consequences.Syntactic
open import Definition.Typed.Consequences.Substitution
open import Definition.Typed.Consequences.Injectivity
open import Definition.Typed.Consequences.Equality
open import Definition.Typed.Consequences.Reduction
open import Definition.Conversion.Symmetry
open import Tools.Nat
open import Tools.Product
import Tools.PropositionalEquality as PE
open import Tools.Function
-- Algorithmic equality of neutrals with injected conversion.
data _⊢_~_∷_^_ (Γ : Con Term) (k l A : Term) (r : TypeInfo) : Set where
↑ : ∀ {B} → Γ ⊢ A ≡ B ^ r → Γ ⊢ k ~ l ↑ B ^ r → Γ ⊢ k ~ l ∷ A ^ r
-- Properties of algorithmic equality of neutrals with injected conversion.
~-var : ∀ {x A r Γ} → Γ ⊢ var x ∷ A ^ r → Γ ⊢ var x ~ var x ∷ A ^ r
~-var x =
let ⊢A = syntacticTerm x
in ↑ (refl ⊢A) (var-refl′ x)
~-app : ∀ {f g a b F G Γ rF lF lG lΠ}
→ Γ ⊢ f ~ g ∷ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ ! , ι lΠ ]
→ Γ ⊢ a [genconv↑] b ∷ F ^ [ rF , ι lF ]
→ Γ ⊢ f ∘ a ^ lΠ ~ g ∘ b ^ lΠ ∷ G [ a ] ^ [ ! , ι lG ]
~-app {rF = !} (↑ A≡B (~↑! x)) x₁ =
let _ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
ΠFG≡B′ = trans A≡B (subset* (red D))
H , E , B≡ΠHE = Π≡A ΠFG≡B′ whnfB′
F≡H , _ , _ , _ , G≡E = injectivity (PE.subst (λ x → _ ⊢ _ ≡ x ^ _) B≡ΠHE ΠFG≡B′)
_ , ⊢f , _ = syntacticEqTerm (soundnessConv↑Term x₁)
in ↑ (substTypeEq G≡E (refl ⊢f))
(app-cong′ (PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _)
B≡ΠHE ([~] _ (red D) whnfB′ x))
(convConvTerm x₁ F≡H))
~-app {rF = %} (↑ A≡B (~↑! x)) x₁ =
let _ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
ΠFG≡B′ = trans A≡B (subset* (red D))
H , E , B≡ΠHE = Π≡A ΠFG≡B′ whnfB′
F≡H , _ , _ , _ , G≡E = injectivity (PE.subst (λ x → _ ⊢ _ ≡ x ^ _) B≡ΠHE ΠFG≡B′)
_ , ⊢f , _ = syntacticEqTerm (proj₂ (proj₂ (soundness~↑% x₁)))
in ↑ (substTypeEq G≡E (genRefl ⊢f))
(app-cong′ (PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _)
B≡ΠHE ([~] _ (red D) whnfB′ x))
(conv~↑% x₁ F≡H))
~-natrec : ∀ {z z′ s s′ n n′ F F′ Γ lF}
→ (Γ ∙ ℕ ^ [ ! , ι ⁰ ]) ⊢ F [conv↑] F′ ^ [ ! , ι lF ] →
Γ ⊢ z [conv↑] z′ ∷ (F [ zero ]) ^ ι lF →
Γ ⊢ s [conv↑] s′ ∷ (Π ℕ ^ ! ° ⁰ ▹ (F ^ ! ° lF ▹▹ F [ suc (var 0) ]↑ ° lF ° lF) ° lF ° lF) ^ ι lF →
Γ ⊢ n ~ n′ ∷ ℕ ^ [ ! , ι ⁰ ] →
Γ ⊢ natrec lF F z s n ~ natrec lF F′ z′ s′ n′ ∷ (F [ n ]) ^ [ ! , ι lF ]
~-natrec {n = n} {n′ = n′} x x₁ x₂ (↑ A≡B (~↑! x₄)) =
let _ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
ℕ≡B′ = trans A≡B (subset* (red D))
B≡ℕ = ℕ≡A ℕ≡B′ whnfB′
k~l′ = PE.subst (λ x → _ ⊢ n ~ n′ ↓! x ^ _) B≡ℕ
([~] _ (red D) whnfB′ x₄)
⊢F , _ = syntacticEq (soundnessConv↑ x)
_ , ⊢n , _ = syntacticEqTerm (soundness~↓! k~l′)
in ↑ (refl (substType ⊢F ⊢n)) (natrec-cong′ x x₁ x₂ k~l′)
~-Emptyrec : ∀ {e e' F F′ Γ l lEmpty}
→ Γ ⊢ F [conv↑] F′ ^ [ ! , ι l ] →
Γ ⊢ e ∷ Empty lEmpty ^ [ % , ι lEmpty ] →
Γ ⊢ e' ∷ Empty lEmpty ^ [ % , ι lEmpty ] →
Γ ⊢ Emptyrec l lEmpty F e ~ Emptyrec l lEmpty F′ e' ∷ F ^ [ ! , ι l ]
~-Emptyrec {e = e} {e' = e'} x ⊢e ⊢e' =
let k~l′ = %~↑ ⊢e ⊢e'
⊢F , _ = syntacticEq (soundnessConv↑ x)
in ↑ (refl ⊢F) (Emptyrec-cong′ x k~l′)
~-IdCong : ∀ {A A' : Term} {l : Level} {t t' u u' : Term} {Γ : Con Term} →
Γ ⊢ A ~ A' ∷ Univ ! l ^ [ ! , next l ] →
Γ ⊢ t [conv↑] t' ∷ A ^ ι l →
Γ ⊢ u [conv↑] u' ∷ A ^ ι l →
Γ ⊢ Id A t u ~ Id A' t' u' ∷ SProp l ^ [ ! , next l ]
~-IdCong (↑ A≡B (~↑! x)) t~t' u~u' =
let ⊢Γ = wfEqTerm (soundnessConv↑Term t~t')
_ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
U≡B′ = trans A≡B (subset* (red D))
B≡U = U≡A-whnf U≡B′ whnfB′
A~A′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U
([~] _ (red D) whnfB′ x)
in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-cong A~A′ t~t' u~u'))
~-Idℕ : ∀ {t t' u u' : Term} {Γ : Con Term} →
⊢ Γ →
Γ ⊢ t ~ t' ∷ ℕ ^ [ ! , ι ⁰ ] →
Γ ⊢ u [genconv↑] u' ∷ ℕ ^ [ ! , ι ⁰ ] →
Γ ⊢ Id ℕ t u ~ Id ℕ t' u' ∷ SProp ⁰ ^ [ ! , next ⁰ ]
~-Idℕ ⊢Γ (↑ A≡B (~↑! x)) u~u' =
let _ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
ℕ≡B′ = trans A≡B (subset* (red D))
B≡ℕ = ℕ≡A ℕ≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡ℕ
([~] _ (red D) whnfB′ x)
in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-ℕ t~t′ u~u'))
~-Idℕ0 : ∀ {u u' : Term} {Γ : Con Term} →
⊢ Γ →
Γ ⊢ u ~ u' ∷ ℕ ^ [ ! , ι ⁰ ] →
Γ ⊢ Id ℕ zero u ~ Id ℕ zero u' ∷ SProp ⁰ ^ [ ! , next ⁰ ]
~-Idℕ0 ⊢Γ (↑ A≡B (~↑! x)) =
let _ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
ℕ≡B′ = trans A≡B (subset* (red D))
B≡ℕ = ℕ≡A ℕ≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡ℕ
([~] _ (red D) whnfB′ x)
in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-ℕ0 t~t′))
~-IdℕS : ∀ {t t' u u' : Term} {Γ : Con Term} →
⊢ Γ →
Γ ⊢ t [genconv↑] t' ∷ ℕ ^ [ ! , ι ⁰ ] →
Γ ⊢ u ~ u' ∷ ℕ ^ [ ! , ι ⁰ ] →
Γ ⊢ Id ℕ (suc t) u ~ Id ℕ (suc t') u' ∷ SProp ⁰ ^ [ ! , next ⁰ ]
~-IdℕS ⊢Γ X (↑ A≡B (~↑! x)) =
let _ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
ℕ≡B′ = trans A≡B (subset* (red D))
B≡ℕ = ℕ≡A ℕ≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡ℕ
([~] _ (red D) whnfB′ x)
in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-ℕS X t~t′))
~-IdU : ∀ {t t' u u' : Term} {Γ : Con Term} →
⊢ Γ →
Γ ⊢ t ~ t' ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ u [genconv↑] u' ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ Id (U ⁰) t u ~ Id (U ⁰) t' u' ∷ SProp ¹ ^ [ ! , next ¹ ]
~-IdU ⊢Γ (↑ A≡B (~↑! x)) X =
let _ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
U≡B′ = trans A≡B (subset* (red D))
B≡U = U≡A-whnf U≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U
([~] _ (red D) whnfB′ x)
in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-U t~t′ X))
~-IdUℕ : ∀ {u u' : Term} {Γ : Con Term} →
⊢ Γ →
Γ ⊢ u ~ u' ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ Id (U ⁰) ℕ u ~ Id (U ⁰) ℕ u' ∷ SProp ¹ ^ [ ! , next ¹ ]
~-IdUℕ ⊢Γ (↑ A≡B (~↑! x)) =
let _ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
U≡B′ = trans A≡B (subset* (red D))
B≡U = U≡A-whnf U≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U
([~] _ (red D) whnfB′ x)
in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-Uℕ t~t′))
~-IdUΠ : ∀ {A : Term} {rA : Relevance} {B A' B' u u' : Term}
{Γ : Con Term} →
Γ ⊢ Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰ [genconv↑] Π A' ^ rA ° ⁰ ▹ B' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ u ~ u' ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) u ~
Id (U ⁰) (Π A' ^ rA ° ⁰ ▹ B' ° ⁰ ° ⁰) u' ∷ SProp ¹ ^ [ ! , next ¹ ]
~-IdUΠ X (↑ A≡B (~↑! x)) =
let ⊢Γ = wfEqTerm (soundnessConv↑Term X)
_ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B
U≡B′ = trans A≡B (subset* (red D))
B≡U = U≡A-whnf U≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U
([~] _ (red D) whnfB′ x)
in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-UΠ X t~t′))
~-castcong : ∀ {A A' B B' e e' t t' : Term} {Γ : Con Term} →
Γ ⊢ A ~ A' ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ B [genconv↑] B' ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ t [genconv↑] t' ∷ A ^ [ ! , ι ⁰ ] →
Γ ⊢ e ∷ Id (U ⁰) A B ^ [ % , next ⁰ ] →
Γ ⊢ e' ∷ Id (U ⁰) A' B' ^ [ % , next ⁰ ] →
Γ ⊢ cast ⁰ A B e t ~ cast ⁰ A' B' e' t' ∷ B ^ [ ! , ι ⁰ ]
~-castcong (↑ A≡B (~↑! x)) X Y ⊢e ⊢e' =
let _ , ⊢B , _ = syntacticEqTerm (soundnessConv↑Term X)
_ , ⊢B' = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B'
U≡B′ = trans A≡B (subset* (red D))
B≡U = U≡A-whnf U≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U
([~] _ (red D) whnfB′ x)
in ↑ (refl (univ ⊢B)) (~↑! (cast-cong t~t′ X Y ⊢e ⊢e'))
~-castℕ : ∀ {B B' e e' t t' : Term} {Γ : Con Term} →
⊢ Γ →
Γ ⊢ B ~ B' ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ t [genconv↑] t' ∷ ℕ ^ [ ! , ι ⁰ ] →
Γ ⊢ e ∷ Id (U ⁰) ℕ B ^ [ % , next ⁰ ] →
Γ ⊢ e' ∷ Id (U ⁰) ℕ B' ^ [ % , next ⁰ ] →
Γ ⊢ cast ⁰ ℕ B e t ~ cast ⁰ ℕ B' e' t' ∷ B ^ [ ! , ι ⁰ ]
~-castℕ ⊢Γ (↑ A≡B (~↑! x)) X ⊢e ⊢e' =
let _ , ⊢B' = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B'
U≡B′ = trans A≡B (subset* (red D))
B≡U = U≡A-whnf U≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U
([~] _ (red D) whnfB′ x)
_ , ⊢B , _ = syntacticEqTerm (soundness~↓! t~t′)
in ↑ (refl (univ ⊢B)) (~↑! (cast-ℕ t~t′ X ⊢e ⊢e'))
~-castℕℕ : ∀ {e e' t t' : Term} {Γ : Con Term} →
⊢ Γ →
Γ ⊢ t ~ t' ∷ ℕ ^ [ ! , ι ⁰ ] →
Γ ⊢ e ∷ Id (U ⁰) ℕ ℕ ^ [ % , next ⁰ ] →
Γ ⊢ e' ∷ Id (U ⁰) ℕ ℕ ^ [ % , next ⁰ ] →
Γ ⊢ cast ⁰ ℕ ℕ e t ~ cast ⁰ ℕ ℕ e' t' ∷ ℕ ^ [ ! , ι ⁰ ]
~-castℕℕ ⊢Γ (↑ A≡B (~↑! x)) ⊢e ⊢e' =
let _ , ⊢B' = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B'
ℕ≡B′ = trans A≡B (subset* (red D))
B≡ℕ = ℕ≡A ℕ≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡ℕ
([~] _ (red D) whnfB′ x)
_ , ⊢B , _ = syntacticEqTerm (soundness~↓! t~t′)
in ↑ (refl (univ (ℕⱼ ⊢Γ))) (~↑! (cast-ℕℕ t~t′ ⊢e ⊢e'))
~-castΠ : ∀ {A A' : Term} {rA : Relevance} {P P' B B' e e' t t' : Term}
{Γ : Con Term} →
Γ ⊢ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ [genconv↑] Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ B ~ B' ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ t [genconv↑] t' ∷ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ] →
Γ ⊢ e ∷ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) B ^ [ % , next ⁰ ] →
Γ ⊢ e' ∷ Id (U ⁰) (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) B' ^ [ % , next ⁰ ] →
Γ ⊢ cast ⁰ (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) B e t ~ cast ⁰ (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) B' e' t' ∷ B ^ [ ! , ι ⁰ ]
~-castΠ X (↑ A≡B (~↑! x)) Y ⊢e ⊢e' =
let _ , ⊢B' = syntacticEq A≡B
B′ , whnfB′ , D = whNorm ⊢B'
U≡B′ = trans A≡B (subset* (red D))
B≡U = U≡A-whnf U≡B′ whnfB′
t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U
([~] _ (red D) whnfB′ x)
_ , ⊢B , _ = syntacticEqTerm (soundness~↓! t~t′)
in ↑ (refl (univ ⊢B)) (~↑! (cast-Π X t~t′ Y ⊢e ⊢e'))
~-castℕΠ : ∀ {A A' : Term} {rA : Relevance} {P P' e e' t t' : Term}
{Γ : Con Term} →
Γ ⊢ A ∷ Univ rA ⁰ ^ [ ! , next ⁰ ] →
(Γ ∙ A ^ [ rA , ι ⁰ ]) ⊢ P ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ [genconv↑] Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ t [genconv↑] t' ∷ ℕ ^ [ ! , ι ⁰ ] →
Γ ⊢ e ∷ Id (U ⁰) ℕ (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) ^ [ % , next ⁰ ] →
Γ ⊢ e' ∷ Id (U ⁰) ℕ (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) ^ [ % , next ⁰ ] →
Γ ⊢ cast ⁰ ℕ (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) e t ~ cast ⁰ ℕ (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) e' t' ∷
Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ]
~-castℕΠ ⊢A ⊢P X Y ⊢e ⊢e' = ↑ (refl (univ (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ ⊢A ▹ ⊢P))) (~↑! (cast-ℕΠ X Y ⊢e ⊢e'))
~-castΠℕ : ∀ {A A' : Term} {rA : Relevance} {P P' e e' t t' : Term}
{Γ : Con Term} →
Γ ⊢ A ∷ Univ rA ⁰ ^ [ ! , next ⁰ ] →
(Γ ∙ A ^ [ rA , ι ⁰ ]) ⊢ P ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ [genconv↑] Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰
∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ t [genconv↑] t' ∷ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ] →
Γ ⊢ e ∷ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) ℕ ^ [ % , next ⁰ ] →
Γ ⊢ e' ∷ Id (U ⁰) (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) ℕ ^ [ % , next ⁰ ] →
Γ ⊢ cast ⁰ (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) ℕ e t ~
cast ⁰ (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) ℕ e' t' ∷ ℕ ^ [ ! , ι ⁰ ]
~-castΠℕ ⊢A ⊢P X Y ⊢e ⊢e' = ↑ (refl (univ (ℕⱼ (wfTerm ⊢A)))) (~↑! (cast-Πℕ X Y ⊢e ⊢e'))
~-castΠΠ%! : ∀ {A A' P P' B B' Q Q' e e' t t' : Term} {Γ : Con Term} →
Γ ⊢ A ∷ Univ % ⁰ ^ [ ! , next ⁰ ] →
(Γ ∙ A ^ [ % , ι ⁰ ]) ⊢ P ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ Π A ^ % ° ⁰ ▹ P ° ⁰ ° ⁰ [genconv↑] Π A' ^ % ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ B ∷ Univ ! ⁰ ^ [ ! , next ⁰ ] →
(Γ ∙ B ^ [ ! , ι ⁰ ]) ⊢ Q ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ Π B ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰ [genconv↑] Π B' ^ ! ° ⁰ ▹ Q' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ t [genconv↑] t' ∷ Π A ^ % ° ⁰ ▹ P ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ] →
Γ ⊢ e ∷ Id (U ⁰) (Π A ^ % ° ⁰ ▹ P ° ⁰ ° ⁰) (Π B ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰) ^ [ % , next ⁰ ] →
Γ ⊢ e' ∷ Id (U ⁰) (Π A' ^ % ° ⁰ ▹ P' ° ⁰ ° ⁰) (Π B' ^ ! ° ⁰ ▹ Q' ° ⁰ ° ⁰) ^ [ % , next ⁰ ] →
Γ ⊢ cast ⁰ (Π A ^ % ° ⁰ ▹ P ° ⁰ ° ⁰) (Π B ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰) e t ~
cast ⁰ (Π A' ^ % ° ⁰ ▹ P' ° ⁰ ° ⁰) (Π B' ^ ! ° ⁰ ▹ Q' ° ⁰ ° ⁰) e' t' ∷ Π B ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ]
~-castΠΠ%! ⊢A ⊢P X ⊢B ⊢Q Y t~t' ⊢e ⊢e' = ↑ (refl (univ (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ ⊢B ▹ ⊢Q)))
(~↑! (cast-ΠΠ%! X Y t~t' ⊢e ⊢e'))
~-castΠΠ!% : ∀ {A A' P P' B B' Q Q' e e' t t' : Term} {Γ : Con Term} →
Γ ⊢ A ∷ Univ ! ⁰ ^ [ ! , next ⁰ ] →
(Γ ∙ A ^ [ ! , ι ⁰ ]) ⊢ P ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ Π A ^ ! ° ⁰ ▹ P ° ⁰ ° ⁰ [genconv↑] Π A' ^ ! ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ B ∷ Univ % ⁰ ^ [ ! , next ⁰ ] →
(Γ ∙ B ^ [ % , ι ⁰ ]) ⊢ Q ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ Π B ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰ [genconv↑] Π B' ^ % ° ⁰ ▹ Q' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →
Γ ⊢ t [genconv↑] t' ∷ Π A ^ ! ° ⁰ ▹ P ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ] →
Γ ⊢ e ∷ Id (U ⁰) (Π A ^ ! ° ⁰ ▹ P ° ⁰ ° ⁰) (Π B ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰) ^ [ % , next ⁰ ] →
Γ ⊢ e' ∷ Id (U ⁰) (Π A' ^ ! ° ⁰ ▹ P' ° ⁰ ° ⁰) (Π B' ^ % ° ⁰ ▹ Q' ° ⁰ ° ⁰) ^ [ % , next ⁰ ] →
Γ ⊢ cast ⁰ (Π A ^ ! ° ⁰ ▹ P ° ⁰ ° ⁰) (Π B ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰) e t ~
cast ⁰ (Π A' ^ ! ° ⁰ ▹ P' ° ⁰ ° ⁰) (Π B' ^ % ° ⁰ ▹ Q' ° ⁰ ° ⁰) e' t' ∷ Π B ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ]
~-castΠΠ!% ⊢A ⊢P X ⊢B ⊢Q Y t~t' ⊢e ⊢e' = ↑ (refl (univ (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ ⊢B ▹ ⊢Q)))
(~↑! (cast-ΠΠ!% X Y t~t' ⊢e ⊢e'))
~-sym : {k l A : Term} {r : TypeInfo} {Γ : Con Term} → Γ ⊢ k ~ l ∷ A ^ r → Γ ⊢ l ~ k ∷ A ^ r
~-sym (↑ A≡B x) =
let ⊢Γ = wfEq A≡B
B , A≡B′ , l~k = sym~↑ (reflConEq ⊢Γ) x
in ↑ (trans A≡B A≡B′) l~k
~-trans : {k l m A : Term} {r : TypeInfo} {Γ : Con Term}
→ Γ ⊢ k ~ l ∷ A ^ r → Γ ⊢ l ~ m ∷ A ^ r
→ Γ ⊢ k ~ m ∷ A ^ r
~-trans (↑ x (~↑! x₁)) (↑ x₂ (~↑! x₃)) =
let ⊢Γ = wfEq x
k~m , _ = trans~↑! PE.refl (reflConEq ⊢Γ) x₁ x₃
in ↑ x (~↑! k~m)
~-trans (↑ x (~↑% x₁)) (↑ x₂ (~↑% x₃)) =
let ⊢Γ = wfEq x
k~m = trans~↑% (reflConEq ⊢Γ) x₁ (conv~↑% x₃ (trans (sym x₂) x))
in ↑ x (~↑% k~m)
~-wk : {k l A : Term} {r : TypeInfo} {ρ : Wk} {Γ Δ : Con Term} →
ρ ∷ Δ ⊆ Γ →
⊢ Δ → Γ ⊢ k ~ l ∷ A ^ r → Δ ⊢ wk ρ k ~ wk ρ l ∷ wk ρ A ^ r
~-wk x x₁ (↑ x₂ x₃) = ↑ (wkEq x x₁ x₂) (wk~↑ x x₁ x₃)
~-conv : {k l A B : Term} {r : TypeInfo} {Γ : Con Term} →
Γ ⊢ k ~ l ∷ A ^ r → Γ ⊢ A ≡ B ^ r → Γ ⊢ k ~ l ∷ B ^ r
~-conv (↑ x x₁) x₂ = ↑ (trans (sym x₂) x) x₁
~-to-conv : {k l A : Term} {Γ : Con Term} {r : TypeInfo} →
Γ ⊢ k ~ l ∷ A ^ r → Γ ⊢ k [genconv↑] l ∷ A ^ r
~-to-conv {r = [ ! , ll ]} (↑ x x₁) = convConvTerm (lift~toConv↑ x₁) (sym x)
~-to-conv {r = [ % , ll ]} (↑ x (~↑% x₁)) = conv~↑% x₁ (sym x)
un-univConv : ∀ {A B : Term} {r : Relevance} {l : Level} {Γ : Con Term} →
Γ ⊢ A [conv↑] B ^ [ r , ι l ] →
Γ ⊢ A [conv↑] B ∷ Univ r l ^ next l
un-univConv {A} {B} {r} {l} ([↑] A′ B′ D D′ whnfA′ whnfB′ (univ x)) =
let ⊢Γ = wfEqTerm (soundnessConv↓Term x)
in [↑]ₜ (Univ r l) A′ B′ (id (Ugenⱼ ⊢Γ)) (un-univ⇒* D) (un-univ⇒* D′) Uₙ whnfA′ whnfB′ x
Πₜ-cong : ∀ {F G H E rF rG lF lG lΠ Γ}
→ lF ≤ lΠ
→ lG ≤ lΠ
→ Γ ⊢ F ^ [ rF , ι lF ]
→ Γ ⊢ F [conv↑] H ∷ Univ rF lF ^ next lF
→ Γ ∙ F ^ [ rF , ι lF ] ⊢ G [conv↑] E ∷ Univ rG lG ^ next lG
→ Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° lΠ [conv↑] Π H ^ rF ° lF ▹ E ° lG ° lΠ ∷ Univ rG lΠ ^ next lΠ
Πₜ-cong lF< lG< x x₁ x₂ = liftConvTerm (Π-cong PE.refl PE.refl PE.refl PE.refl lF< lG< x x₁ x₂)
~-irrelevance : {k l A : Term} {Γ : Con Term} {ll : TypeLevel}
→ Γ ⊢ k ∷ A ^ [ % , ll ]
→ Γ ⊢ l ∷ A ^ [ % , ll ]
→ Γ ⊢ k ~ l ∷ A ^ [ % , ll ]
~-irrelevance ⊢k ⊢l =
let X = ~↑% (%~↑ ⊢k ⊢l)
⊢A = syntacticTerm ⊢k
in ↑ (refl ⊢A) X
soundnessgenConv : ∀ {a b A r Γ} → Γ ⊢ a [genconv↑] b ∷ A ^ r → Γ ⊢ a ≡ b ∷ A ^ r
soundnessgenConv {r = [ ! , l ]} = soundnessConv↑Term
soundnessgenConv {r = [ % , l ]} x = proj₂ (proj₂ (soundness~↑% x))
symgenConv : ∀ {t u A r Γ} → Γ ⊢ t [genconv↑] u ∷ A ^ r → Γ ⊢ u [genconv↑] t ∷ A ^ r
symgenConv {r = [ ! , l ]} = symConvTerm
symgenConv {r = [ % , l ]} t<>u = let ⊢Γ = wfEqTerm (proj₂ (proj₂ (soundness~↑% t<>u)))
in sym~↑% (reflConEq ⊢Γ) t<>u
wkgenConv↑Term : ∀ {ρ t u A Γ r Δ} ([ρ] : ρ ∷ Δ ⊆ Γ) → ⊢ Δ
→ Γ ⊢ t [genconv↑] u ∷ A ^ r
→ Δ ⊢ wk ρ t [genconv↑] wk ρ u ∷ wk ρ A ^ r
wkgenConv↑Term {r = [ ! , l ]} = wkConv↑Term
wkgenConv↑Term {r = [ % , l ]} = wk~↑%
convgenconv : ∀ {t u A B : Term} {r : TypeInfo} {Γ : Con Term} →
Γ ⊢ t [genconv↑] u ∷ A ^ r →
Γ ⊢ A ≡ B ^ r → Γ ⊢ t [genconv↑] u ∷ B ^ r
convgenconv {r = [ ! , l ]} = convConvTerm
convgenconv {r = [ % , l ]} = conv~↑%
transgenConv : ∀ {t u v A : Term} {r : TypeInfo} {Γ : Con Term} →
Γ ⊢ t [genconv↑] u ∷ A ^ r →
Γ ⊢ u [genconv↑] v ∷ A ^ r → Γ ⊢ t [genconv↑] v ∷ A ^ r
transgenConv {r = [ ! , l ]} = transConvTerm
transgenConv {r = [ % , l ]} = trans~↑!Term
-- Algorithmic equality instance of the generic equality relation.
instance eqRelInstance : EqRelSet
eqRelInstance = eqRel _⊢_[conv↑]_^_ _⊢_[genconv↑]_∷_^_ _⊢_~_∷_^_
~-to-conv soundnessConv↑ soundnessgenConv
univConv↑ un-univConv
symConv symgenConv ~-sym
transConv transgenConv ~-trans
convgenconv ~-conv
wkConv↑ wkgenConv↑Term ~-wk
reductionConv↑ reductionConv↑Term
(liftConv ∘ᶠ (U-refl PE.refl)) ( liftConvTerm ∘ᶠ (U-refl PE.refl))
(liftConvTerm ∘ᶠ ℕ-refl)
(liftConvTerm ∘ᶠ (Empty-refl PE.refl))
Πₜ-cong
(λ x x₁ x₂ → liftConvTerm (∃-cong PE.refl x x₁ x₂))
(liftConvTerm ∘ᶠ zero-refl)
(liftConvTerm ∘ᶠ suc-cong)
(λ l< l<' x x₁ x₂ x₃ x₄ x₅ → liftConvTerm (η-eq l< l<' x x₁ x₂ x₃ x₄ x₅))
~-var ~-app ~-natrec ~-Emptyrec
~-IdCong ~-Idℕ ~-Idℕ0 ~-IdℕS ~-IdU ~-IdUℕ ~-IdUΠ
~-castcong ~-castℕ ~-castℕℕ ~-castΠ ~-castℕΠ ~-castΠℕ ~-castΠΠ%! ~-castΠΠ!%
~-irrelevance
|
# Lista de Exercício 7
### Introdução à Visão Computacional (SEL0339/SEL5886)
**Instruções:**
1. Esta lista consiste de 3 exercícios.
1. Deve-se colocar comentários nos códigos desenvolvidos.
1. As perguntas devem ser respondidas também como comentários no arquivo.
1. Colocar seu nome e número USP abaixo.
1. Quaisquer problemas na execução das listas, entrar em contato com os monitores.
1. Depois de terminado os exercícios, deve ser gerado um arquivo **extensão .ipynb** para ser enviado ao professor pelo E-DISCIPLINAS da disciplina até a data máxima de entrega.
1. Caso não seja enviado, o aluno ficará sem nota.
---
<table class="tfo-notebook-buttons" align="left">
<td>
<a target="_blank" href="https://colab.research.google.com/github/LAVI-USP/SEL0339-SEL5886_2021/blob/main/praticas/Lista_de_Exercicio_7.ipynb">Executar no Google Colab</a>
</td>
<td>
<a target="_blank" href="https://github.com/LAVI-USP/SEL0339-SEL5886_2021/blob/main/praticas/Lista_de_Exercicio_7.ipynb">Ver codigo fonte no GitHub</a>
</td>
</table>
`Nome: Murilo Henrique Pasini Trevisan `
`Número USP: 9796078 `
### Introdução:
Vamos importar as bibliotecas que iremos utilizar:
```
import numpy as np
import matplotlib.pyplot as plt
import cv2 as cv
from skimage.transform import hough_circle, hough_circle_peaks
```
#### **Atenção**: os códigos abaixo são para fazer o download das imagens (EXECUTE-OS). Os mesmos não fazem parte dessa prática.
```
import urllib.request
try:
urllib.request.urlretrieve("https://github.com/LAVI-USP/SEL0339-SEL5886_2021/raw/main/imagens/pratica_07/test_01.png", "test_01.png")
except:
print("[ERRO] Não foi possível fazer o download das imagens dessa prática. Entre em contato com o monitor")
try:
urllib.request.urlretrieve("https://github.com/LAVI-USP/SEL0339-SEL5886_2021/raw/main/imagens/pratica_07/house.tif", "house.tif")
except:
print("[ERRO] Não foi possível fazer o download das imagens dessa prática. Entre em contato com o monitor")
try:
urllib.request.urlretrieve("https://github.com/LAVI-USP/SEL0339-SEL5886_2021/raw/main/imagens/pratica_07/wirebond_mask.tif", "wirebond_mask.tif")
except:
print("[ERRO] Não foi possível fazer o download das imagens dessa prática. Entre em contato com o monitor")
try:
urllib.request.urlretrieve("https://github.com/LAVI-USP/SEL0339-SEL5886_2021/raw/main/imagens/pratica_07/notas_functions.py", "notas_functions.py")
except:
print("[ERRO] Não foi possível fazer o download das imagens dessa prática. Entre em contato com o monitor")
```
### 1) Filtros derivativos de $1^a$ e $2^a$ ordem
A equação para o cálculo da $1^a$ derivada em relação a $y$ é dada por:
\begin{equation}
\frac{\partial f(x,y)}{\partial y} = f(x,y+1) - f(x,y)
\end{equation}
Já a equação para o cálculo da $2^a$ derivada em relação a $y$ é dada por:
\begin{equation}
\frac{\partial^2 f(x,y)}{\partial y^2} = f(x,y+1) - 2f(x,y) + f(x,y-1)
\end{equation}
**Exercício:**
1. Crie um *kernel* para o filtro derivativo de $1^a$ ordem e um *kernel* para o de $2^a$ ordem.
2. Aplique os *kernels* para detectar as bordas na vertical, ou seja, no eixo $y$. A imagem já está criada no código.
3. Mostre a imagem original e ambos os resultados utilizando `subplot`.
4. Utilize a função `plt.plot` para mostrar o perfil das bordas detectadas em ambos os casos. Isso pode ser feito através de qualquer linha da imagem resultante. Utilize um `subplot` com 3 linhas e 1 coluna, sendo a primeira linha para o perfil da imagem original, a segunda para o filtro de $1^a$ ordem e a terceira para o filtro de $2^a$ ordem.
<details>
<summary>
<font size="3" color="darkblue"><b>Dicas:</b></font>
</summary>
* Você pode utilizar a função [cv.filter2D](https://docs.opencv.org/3.4/d4/d86/group__imgproc__filter.html#ga27c049795ce870216ddfb366086b5a04) para fazer a filtragem.
* Você pode utilizar a função [plt.plot](https://matplotlib.org/3.3.2/api/_as_gen/matplotlib.pyplot.plot.html) para mostrar os gráficos na tela. Você pode fazer a leitura de qualquer linha da imagem para mostrar o gráfico.
*Ex:*
``` python
plt.plot(x,y)
plt.plot(y) # Dessa maneira a função cria um range para o x
cv.filter2D(myImg, -1, myKernel)
```
```
img = np.zeros((100,100),np.float32)
img[:,25:75] = 255
img = cv.blur(img,(3,3))
## -- Seu código começa AQUI -- ##
Kernel_1 = np.array(((-1, 0, 1),
(-1, 0, 1),
(-1, 0, 1)))
Kernel_2 = np.array(((-1, -1, -1),
(-1, 8, -1),
(-1, -1, -1)))
img_filter_1 = cv.filter2D(img, -1, Kernel_1)
img_filter_2 = cv.filter2D(img, -1, Kernel_2)
plt.figure(figsize = (7,7))
plt.subplot(1,3,1)
plt.imshow(img)
plt.title("Original")
plt.subplot(1,3,2)
plt.imshow(img_filter_1)
plt.title("1 ordem")
plt.subplot(1,3,3)
plt.imshow(img_filter_2)
plt.title("2 ordem")
## -- Seu código termina AQUI -- ##
```
### 2) Detector de bordas (Prewitt e Sobel)
**Exercício:**
1. Aplicar o detector de bordas de Prewitt e Sobel na imagem ```wirebond_mask.tif``` para detectar as bordas horizontais e depois as verticais. Note que vários *kernels* foram fornecidos abaixo. Alguns serão utilizados no próximo exercício também.
2. Mostre as 4 imagens resultantes e comente os resultados encontrados.
<details>
<summary>
<font size="3" color="darkblue"><b>Dicas:</b></font>
</summary>
* Nós criamos uma lista contendo os *kernels* de cada método. Você pode criar um laço de repetição para pegar cada kernel da lista. Segue abaixo um exemplo de um `for loop` em uma lista.
*Ex:*
``` python
kernel_lista = [kernel1,kernel2,kernel3]
for kernel in kernel_lista:
print(kernel)
# Resultado do print:
# kernel1
# kernel2
# kernel3
```
```
# Prewitt
p1 = np.array(((-1,-1,-1),
( 0, 0, 0),
( 1, 1, 1)))
p2 = np.array(((-1, 0, 1),
(-1, 0, 1),
(-1, 0, 1)))
# Lista com todos os kernels (Prewitt)
prewitt = [p1,p2]
# Sobel
s1 = np.array(((-1,-2,-1),
( 0, 0, 0),
( 1, 2, 1)))
s2 = np.array(((-1, 0, 1),
(-2, 0, 2),
(-1, 0, 1)))
s3 = np.array(((-2,-1, 0),
(-1, 0, 1),
( 0, 1, 2)))
s4 = np.array((( 0, 1, 2),
(-1, 0, 1),
(-2,-1, 0)))
s5 = np.array((( 2, 1, 0),
( 1, 0,-1),
( 0,-1,-2)))
s6 = np.array((( 0,-1,-2),
( 1, 0,-1),
( 2, 1, 0)))
# Lista com todos os kernels (Sobel)
sobel = [s1,s2,s3,s4,s5,s6]
# Laplaciano
laplaciano = np.array(((-1,-1,-1),
(-1, 8,-1),
(-1,-1,-1)))
## -- Seu código termina AQUI -- ##
wire = cv.imread("wirebond_mask.tif")
wire_filter_yp = cv.filter2D(wire, -1, p1)
wire_filter_xp = cv.filter2D(wire, -1, p2)
wire_filter_ys = cv.filter2D(wire, -1, s1)
wire_filter_xs = cv.filter2D(wire, -1, s2)
plt.figure(figsize = (10,10))
plt.subplot(1,5,1)
plt.imshow(wire)
plt.title("original")
plt.subplot(1,5,2)
plt.imshow(wire_filter_yp)
plt.title("prewitt x")
plt.subplot(1,5,3)
plt.imshow(wire_filter_xp)
plt.title("prewitt y")
plt.subplot(1,5,4)
plt.imshow(wire_filter_ys)
plt.title("Sobel x")
plt.subplot(1,5,5)
plt.imshow(wire_filter_xs)
plt.title("Sobel y")
#Nota-se que para os kernels em y somente as linhas que possuem variação em y
#foram mantidas, assim como em x somente as que variam em x, além disso notou-se
#que para estes exemplos a diferença entre prewitt e sobel não é tão expressiva
#visto que as imagens já possuem bordas bem destacadas, porém nota-se que para os
#kernels em sobel, houve maior destaque na borda, comparado a prewitt, como 7
#esperado pela teoria dos kernels de prewitt e sobel
## -- Seu código termina AQUI -- ##
```
### 3) Detector de bordas (Sobel e Laplaciano)
**Exercício:**
1. Aplicar o detector de bordas de Sobel na imagem ```house.tif``` para detectar todas as bordas. Os *kernels* foram definidos no exercício anterior.
* Para cada *kernel*, aplique um *threshold* no resultado do filtro a fim de tentar manter somente as bordas que aquele filtro foi desenvolvido para detectar. Nas dicas deixamos um valor sugerido;
* Some o resultado obtido por cada *kernel* em uma variável chamada `sobel_sum`.
2. Mostre os 6 resultados anteriores e um `subplot`;
3. Aplique o detector de bordas Laplaciano na imagem ```house.tif```. Criei um `sobplot` para mostrar a imagem original, a soma de todos os resultados de Sobel (`sobel_sum`) e por fim o resultado do Laplaciano. O que se pode concluir?
<details>
<summary>
<font size="3" color="darkblue"><b>Dicas:</b></font>
</summary>
* O valor de *threshold* sugerido é 220. Esse não é um valor ótimo para cada *kernel*, mas sim um valor médio para todos os *kernels* no geral.
* Faça um `for loop` para aplicar os filtros de Sobel. Isso simplifica o código
*Ex:*
``` python
kernel_lista = [kernel1,kernel2,kernel3]
for kernel in kernel_lista:
print(kernel)
# Resultado do print:
# kernel1
# kernel2
# kernel3
```
```
## -- Seu código começa AQUI -- ##
house = cv.imread("house.tif", cv.IMREAD_GRAYSCALE)
house_filter = cv.filter2D(house, -1, s1)
(thresh, house_1) = cv.threshold(house_filter, 220, 255, cv.THRESH_BINARY)
house_filter = cv.filter2D(house, -1, s2)
(thresh, house_2) = cv.threshold(house_filter, 220, 255, cv.THRESH_BINARY)
house_filter = cv.filter2D(house, -1, s3)
(thresh, house_3) = cv.threshold(house_filter, 220, 255, cv.THRESH_BINARY)
house_filter = cv.filter2D(house, -1, s4)
(thresh, house_4) = cv.threshold(house_filter, 220, 255, cv.THRESH_BINARY)
house_filter = cv.filter2D(house, -1, s5)
(thresh, house_5) = cv.threshold(house_filter, 220, 255, cv.THRESH_BINARY)
house_filter = cv.filter2D(house, -1, s6)
(thresh, house_6) = cv.threshold(house_filter, 220, 255, cv.THRESH_BINARY)
Sobel_sum = house_1 + house_2 + house_3 + house_4 + house_5 + house_6
house_filter = cv.filter2D(house, -1, laplaciano)
(thresh, house_lap) = cv.threshold(house_filter, 40, 255, cv.THRESH_BINARY)
plt.figure(figsize = (20,20))
plt.subplot(1,7,1)
plt.imshow(house, cmap="gray")
plt.title("original")
plt.subplot(1,7,2)
plt.imshow(house_1, cmap="gray")
plt.title("Sobel 1")
plt.subplot(1,7,3)
plt.imshow(house_2, cmap= "gray")
plt.title("Sobel 2")
plt.subplot(1,7,4)
plt.imshow(house_3, cmap= "gray")
plt.title("Sobel 3")
plt.subplot(1,7,5)
plt.imshow(house_4, cmap= "gray")
plt.title("Sobel 4")
plt.subplot(1,7,6)
plt.imshow(house_5, cmap= "gray")
plt.title("Sobel 5")
plt.subplot(1,7,7)
plt.imshow(house_6, cmap= "gray")
plt.title("Sobel 6")
plt.figure(figsize = (15,15))
plt.subplot(1,3,1)
plt.imshow(house, cmap="gray")
plt.title("original")
plt.subplot(1,3,2)
plt.imshow(Sobel_sum, cmap="gray")
plt.title("Sobel soma")
plt.subplot(1,3,3)
plt.imshow(house_lap, cmap= "gray")
plt.title("Laplaciano")
#Conclui-se que cada sobel obteve em cada direção o filtro, a partir da direção
#do kernel, como esperado, e assim como previsto pela teoria, caso realize a
#filtragem da primeira derivada em todas as direções, o resultado é um filtro
#semelhante a um de segunda ordem, como pode ser visto pela comparação entre a
#soma dos filtros de sobel e do laplaciano, porém, nota-se que o threshold do
#filtro laplaciano teve que ser menor que o da soma dos filtros de sobel, devido
#a forma como é feita a filtragem em segunda ordem e primeira ordem, porém
#ajustando-se os thresholds, obteve-se imagens semelhantes
## -- Seu código termina AQUI -- ##
```
|
x <- c(10.4, 5.6, 3.1, 6.4, 21.7) # c means 'combine', basically create an array?
cat("x: ", x, "\n")
y <- mean(x) # average
cat("mean of x: ", y, "\n")
z <- sd(x) # standard deviation
cat("std dev of x: ", z, "\n")
|
-- Subgrupos
-- =====================================================================
-- ---------------------------------------------------------------------
-- Ejercicio. Importar la teoría de grupos de la sesión anterior.
-- ---------------------------------------------------------------------
import .Grupos
-- ---------------------------------------------------------------------
-- Ejercicio. Abrir el espacio de nombre `oculto`.
-- ---------------------------------------------------------------------
namespace oculto
-- ---------------------------------------------------------------------
-- Ejercicio. Un subgrupo de un grupo G es un subconjunto de G que
-- contiene al elemento neutro y es cerrado por la multiplicación y el
-- inverso. Definir la estructura `subgroup` tal que `subgroup G` es el
-- tipo de los subgrupos de G.
-- ---------------------------------------------------------------------
structure subgroup (G : Type) [group G] :=
(carrier : set G)
(one_mem' : (1 : G) ∈ carrier)
(mul_mem' {x y} : x ∈ carrier → y ∈ carrier → x * y ∈ carrier)
(inv_mem' {x} : x ∈ carrier → x⁻¹ ∈ carrier)
/-
Pdte. Traducir carrier por elementos.
Pdte. Usar notación funcional en lugar de la de punto.
At this point, here's what we have.
A term `H` of type `subgroup G`, written `H : subgroup G`, is a
*quadruple*. To give a term `H : subgroup G` is to give the following four things:
1) `H.carrier` (a subset of `G`),
2) `H.one_mem'` (a proof that `1 ∈ H.carrier`),
3) `H.mul_mem'` (a proof that `H` is closed under multiplication)
4) `H.inv_mem'` (a proof that `H` is closed under inverses).
Note in particular that Lean, being super-pedantic, *distinguishes* between
the subgroup `H` and the subset `H.carrier`. One is a subgroup, one is
a subset. When we get going we will start by setting up some infrastructure
so that this difference will be hard to notice.
Note also that if `x` is in the subgroup `H` of `H` then the _type_ of `x` is still `G`,
and `x ∈ carrier` is a Proposition. Note also that `x : carrier` doesn't
make sense (`carrier` is a term, not a type, rather counterintuitively).
-/
-- ---------------------------------------------------------------------
-- Ejercicio. Iniciar el espacio de nombres subgroup.
-- ---------------------------------------------------------------------
namespace subgroup
-- ---------------------------------------------------------------------
-- Ejercicio. Abrir el espacio de nombres `oculto.group`
-- ---------------------------------------------------------------------
open oculto.group
-- ---------------------------------------------------------------------
-- Ejercicio. Definir las siguientes variables
-- + G para grupos y
-- + H, J y K para subgrupos de G.
-- ---------------------------------------------------------------------
variables {G : Type} [group G]
variables (H J K : subgroup G)
-- La notación `h ∈ H.carrier` no es correcta. Además, no quiero
-- escribir "H.carrier" en todas partes; lo que quiero es poder
-- identificar el subgrupo `H` con el conjunto de sus elementos
-- (`H.carrier`).
--
-- Hay que tener en cuenta que estas cosas no son iguales, en primer
-- lugar porque `H` contiene la prueba de que `H.carrier` es un
-- subgrupo, y en segundo lugar, porque tienen diferentes tipos: `H`
-- tiene el tipo `supgroup G` y `H.carrier` tiene el tipo `set G`.
-- ---------------------------------------------------------------------
-- Ejercicio. Sean `x : G` y `H : subgroup G`. Definir la notación
-- `x ∈ H` para denotar `x ∈ H.carrier`.
-- ---------------------------------------------------------------------
instance : has_mem G (subgroup G) := ⟨λ y H, y ∈ H.carrier⟩
-- ---------------------------------------------------------------------
-- Ejercicio. Sean `x : G` y `H : subgroup G`. Definir la notación
-- `↑H` para denotar `H.carrier`.
-- ---------------------------------------------------------------------
instance : has_coe (subgroup G) (set G) := ⟨λ H, H.carrier⟩
-- ---------------------------------------------------------------------
-- Ejercicio. Sea `g : G`. Demostrar que
-- g ∈ H.carrier ↔ g ∈ H
-- ---------------------------------------------------------------------
@[simp] lemma mem_carrier
{g : G}
: g ∈ H.carrier ↔ g ∈ H :=
by refl
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que `g` está en `H` considerado como un
-- subconjunto de `G` syss` g` está en `H` considerado como subgrupo de
-- `G`.
-- ---------------------------------------------------------------------
@[simp] lemma mem_coe
{g : G}
: g ∈ (↑H : set G) ↔ g ∈ H :=
by refl
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que
-- 1 ∈ H
-- ---------------------------------------------------------------------
theorem one_mem :
(1 : G) ∈ H :=
one_mem' H
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que los subgrupos son cerrados respecto de las
-- multiplicaciones.
-- ---------------------------------------------------------------------
theorem mul_mem
{x y : G}
: x ∈ H → y ∈ H → x * y ∈ H :=
mul_mem' H
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que los subgrupos son cerrados respecto de los
-- inversos.
-- ---------------------------------------------------------------------
theorem inv_mem {x : G} : x ∈ H → x⁻¹ ∈ H :=
inv_mem' H
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que
-- x⁻¹ ∈ H ↔ x ∈ H
-- ---------------------------------------------------------------------
@[simp] theorem inv_mem_iff
{x : G}
: x⁻¹ ∈ H ↔ x ∈ H :=
begin
split,
{ intro h,
rw ← oculto.group.inv_inv x,
exact inv_mem H h, },
{ exact inv_mem H, },
end
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que si `x` y `xy` están en `H`, entonces `y`
-- también lo está.
-- ---------------------------------------------------------------------
-- 1ª demostración
example
{x y : G}
(hx : x ∈ H)
(hxy : x * y ∈ H)
: y ∈ H :=
begin
replace hx : x⁻¹ ∈ H := inv_mem H hx,
have hy : x⁻¹ * (x * y) ∈ H := mul_mem H hx hxy,
simp at hy,
exact hy,
end
-- 2ª demostración
theorem mem_of_mem_mul_mem
{x y : G}
(hx : x ∈ H)
(hxy : x * y ∈ H)
: y ∈ H :=
begin
rw ← inv_mem_iff at hx,
convert mul_mem H hx hxy,
simp,
end
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que si dos subgrupos de G tienen los mismos
-- elementos, entonces son iguales.
-- ---------------------------------------------------------------------
-- 1ª demostración
example
{H K : subgroup G}
(h : H.carrier = K.carrier)
: H = K :=
begin
cases H,
cases K,
simp at h,
simp,
exact h,
end
-- 2ª demostración
theorem ext'
{H K : subgroup G}
(h : H.carrier = K.carrier)
: H = K :=
begin
cases H,
cases K,
simp * at *,
end
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que dos subgrupos son iguales syss tienen los
-- mismos elementos.
-- ---------------------------------------------------------------------
theorem ext'_iff
{H K : subgroup G}
: H.carrier = K.carrier ↔ H = K :=
begin
split,
{ exact ext', },
{ intro h,
rw h, }
end
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que si dos subgrupos tienen los mismos
-- elementos, entonces son iguales.
-- ---------------------------------------------------------------------
@[ext] theorem ext
{H K : subgroup G}
(h : ∀ x, x ∈ H ↔ x ∈ K)
: H = K :=
begin
apply ext',
ext,
apply h,
end
-- Etiquetamos ese teorema con `ext` para que la táctica `ext` funcione
-- en subgrupos; es decir, para demostrar que dos subgrupos son iguales
-- se puede usar la táctica `ext` para reducirlo a demostrar que tienen
-- los mismos elementos.
-- =====================================================================
-- § La estructura de retículo de subgrupos --
-- =====================================================================
-- Los subgrupos de un grupo forman lo que se conoce como un retículo;
-- es decir, es un conjunto parcialmente ordenado con una las funciones
-- max y min.
--
-- Se ordenan parcialmente los subgrupos diciendo `H ≤ K` si
-- `H.carrier ⊆ K.carrier`.
--
-- Los subgrupos incluso tienen las funciones Sup e Inf (el Inf de de
-- los subgrupos de un grupo es su intersección; su Sup es el subgrupo
-- generado por su unión).
--
-- Esta estructura (un conjunto parcialmente ordenado con Sup e Inf) se
-- denomina "retículo completo", y Lean tiene esta estructura
-- definida
--
-- Nosotros construiremos una estructura de retículo completo en los
-- subgrupos del grupo G. Comenzamos por definiendo una relación ≤ sobre
-- el tipo de los subgrupos de un grupo: Decimos `H ≤ K` si
-- `H.carrier ⊆ K.carrier`.
-- ---------------------------------------------------------------------
-- Ejercicio. Definir la relación ≤ sobre el tipo de los subgrupos del
-- grupo G de forma que `H ≤ K` si `H.carrier ⊆ K.carrier`.
-- ---------------------------------------------------------------------
instance : has_le (subgroup G) := ⟨λ H K, H.carrier ⊆ K.carrier⟩
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que
-- H ≤ K ↔ H.carrier ⊆ K.carrier
-- ---------------------------------------------------------------------
lemma le_def :
H ≤ K ↔ H.carrier ⊆ K.carrier :=
by refl
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que
-- H ≤ K ↔ ∀ g, g ∈ H → g ∈ K
-- ---------------------------------------------------------------------
lemma le_iff :
H ≤ K ↔ ∀ g, g ∈ H → g ∈ K :=
by refl
-- Nota: En los siguientes ejercicios se demostrará que ≤ es un orden
-- parcial.
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que
-- H ≤ H
-- ---------------------------------------------------------------------
@[refl] lemma le_refl :
H ≤ H :=
by rw le_def
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que
-- H ≤ K → K ≤ H → H = K
-- ---------------------------------------------------------------------
lemma le_antisymm :
H ≤ K → K ≤ H → H = K :=
begin
rw [le_def, le_def, ← ext'_iff],
exact set.subset.antisymm,
end
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que
-- H ≤ J → J ≤ K → H ≤ K
-- ---------------------------------------------------------------------
@[trans] lemma le_trans :
H ≤ J → J ≤ K → H ≤ K :=
begin
rw [le_def, le_def, le_def],
exact set.subset.trans,
end
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que los subgrupos de G con la relación ≤ es un
-- orden parcial.
-- ---------------------------------------------------------------------
instance : partial_order (subgroup G) :=
{ le := (≤),
le_refl := le_refl,
le_antisymm := le_antisymm,
le_trans := le_trans }
-- =====================================================================
-- § Intersecciones --
-- =====================================================================
-- Demostremos que la intersección de dos subgrupos es un subgrupo. En
-- Lean esta es su definición: dados dos subgrupos, definimos un nuevo
-- subgrupo cuyo subconjunto subyacente es la intersección de los
-- subconjuntos, y luego probamos los axiomas.
-- ---------------------------------------------------------------------
-- Ejercicio. Definir la función
-- inf : subgroup G → subgroup G → subgroup G
-- tal que (inf H K) es el subgrupo intersección de H y de K.
-- ---------------------------------------------------------------------
-- 1ª solución
def inf (H K : subgroup G) : subgroup G :=
{ carrier := H.carrier ∩ K.carrier,
one_mem' :=
begin
split,
{ exact one_mem H, },
{ exact one_mem K, },
end,
mul_mem' :=
begin
intros x y hx hy,
cases hx with hxH hxK,
cases hy with hyH hyK,
split,
{ exact mul_mem H hxH hyH },
{ exact mul_mem K hxK hyK },
end,
inv_mem' :=
begin
rintro x ⟨hxH, hxK⟩,
exact ⟨inv_mem H hxH, inv_mem K hxK⟩,
end }
-- 2ª solución
def inf_term_mode (H K : subgroup G) : subgroup G :=
{ carrier := carrier H ∩ carrier K,
one_mem' := ⟨one_mem H,
one_mem K⟩,
mul_mem' := λ _ _ ⟨hhx, hkx⟩ ⟨hhy, hky⟩,
⟨mul_mem H hhx hhy,
mul_mem K hkx hky⟩,
inv_mem' := λ x ⟨hhx, hhy⟩,
⟨inv_mem H hhx,
inv_mem K hhy⟩}
-- ---------------------------------------------------------------------
-- Ejercicio. Asignar el símbolo ⊓ a la operación inf.
-- ---------------------------------------------------------------------
instance : has_inf (subgroup G) := ⟨inf⟩
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que el conjunto subyacente de la intersección de
-- dos subgrupos es la intersección de los conjuntos subyacentes.
-- ---------------------------------------------------------------------
lemma inf_def
(H K : subgroup G)
: (H ⊓ K : set G) = (H : set G) ∩ K :=
by refl
-- =====================================================================
-- § Subgrupo generado por un subconjunto --
-- =====================================================================
-- Definir el sup de dos subgrupos es más difícil, porque no solo
-- tomamos la unión, tenemos que mirar el subgrupo generado por esta
-- unión. Así que necesitamos definir el subgrupo de `G` generado por un
-- subconjunto `S: set G`. Hay dos formas completamente diferentes de
-- hacer esto. La primera es "de arriba hacia abajo" (podríamos definir
-- el subgrupo generado por `S` como la intersección de todos los
-- subgrupos de `G` que contienen a `S`. La segunda es "de abajo hacia
-- arriba" (podríamos definir el subgrupo generado por `S` por inducción
-- diciendo que `S` está en el subgrupo, 1 está en el subgrupo, el
-- producto de dos cosas en el subgrupo está en el subgrupo, el inverso
-- de algo en el subgrupo está en el subgrupo, y eso es todo). Ambos
-- métodos funcionan bastante bien en Lean. Vamos a utilizar el primero.
-- ---------------------------------------------------------------------
-- Ejercicio. Abrir el espacio de nombres `set`.
-- ---------------------------------------------------------------------
open set
/-
Here is the API for `set.bInter` (or `bInter`, as we can now call it):
Notation: `⋂` (type with `\I`)
If `X : set (subgroup G)`, i.e. if `X` is a set of subgroups of `G`, then
`⋂ K ∈ X, (K : set G)` means "take the intersection of the underlying subsets".
-- mem_bInter_iff says you're in the intersection iff you're in
-- all the things you're intersecting. Very useful for rewriting.
`mem_bInter_iff : (g ∈ ⋂ (K ∈ S), f K) ↔ (∀ K, K ∈ s → g ∈ f K)`
-- mem_bInter is just the one way implication. Very useful for `apply`ing.
`mem_bInter : (∀ K, K ∈ s → g ∈ f K) → (g ∈ ⋂ (K ∈ S), f K)`
-/
/-
We will consider the closure of a set as the intersect of all subgroups
containing the set
-/
#check mem_bInter_iff
#check mem_bInter
-- Se usarán las siguientes propiedades de la intersección de familias
-- de conjuntos: Sean s : set α, t : α → set β, y : β. Entonces
-- mem_bInter_iff : y ∈ (⋂ x ∈ s, t x) ↔ ∀ x ∈ s, y ∈ t x
-- mem_bInter : (∀ x ∈ s, y ∈ t x) → y ∈ ⋂ x ∈ s, t x
-- ---------------------------------------------------------------------
-- Ejercicio. Definir la función
-- Inf : set (subgroup G) → subgroup G
-- tal que (Inf X) es la intersección de conjunto X de sugrupos de G.
-- ---------------------------------------------------------------------
-- 1ª solución:
def Inf (X : set (subgroup G)) : subgroup G :=
{ carrier := ⋂ K ∈ X, (K : set G),
one_mem' :=
begin
apply mem_bInter,
intros H hH,
apply one_mem H,
end,
mul_mem' :=
begin
intros x y hx hy,
rw mem_bInter_iff at *,
intros H hH,
apply mul_mem H,
{ apply hx,
exact hH },
{ exact hy H hH }
end,
inv_mem' :=
begin
intros x hX,
rw mem_bInter_iff at *,
intros H hH,
exact inv_mem H (hX H hH),
end,
}
-- 2ª solución
def Inf' (X : set (subgroup G)) : subgroup G :=
{ carrier := ⋂ t ∈ X, (t : set G),
one_mem' := mem_bInter (λ i h, one_mem i),
mul_mem' := λ x y hx hy,
mem_bInter (λ i h, mul_mem i (by apply mem_bInter_iff.1 hx i h)
(by apply mem_bInter_iff.1 hy i h)),
inv_mem' := λ x hx,
mem_bInter (λ i h, inv_mem i (by apply mem_bInter_iff.1 hx i h)) }
-- ---------------------------------------------------------------------
-- Ejercicio. Definir la función
-- closure : set G → subgroup G
-- tal que (closure S) es la clausura de S; es decir, el menor subgrupo
-- de G que contiene a S.
-- ---------------------------------------------------------------------
def closure (S : set G) : subgroup G :=
Inf {H : subgroup G | S ⊆ H}
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que
-- x ∈ closure S ↔ ∀ H : subgroup G, S ⊆ H → x ∈ H
-- ---------------------------------------------------------------------
lemma mem_closure_iff
{S : set G}
{x : G}
: x ∈ closure S ↔ ∀ H : subgroup G, S ⊆ H → x ∈ H :=
mem_bInter_iff
-- Un operador de clausura en un conjunto S es una función cl del
-- conjunto potencia de S en sí mismo que satisface las siguientes
-- condiciones para todos los subconjuntos X, Y de S:
-- 1) X ⊆ cl X
-- 2) X ⊆ Y → cl X ⊆ cl Y
-- 3) cl (cl X) = cl X
--
-- Vamos a demostrar que closure es un operador de clausura.
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que
-- S ⊆ ↑(closure S)
-- ---------------------------------------------------------------------
-- 1ª demostración
lemma subset_closure
(S : set G)
: S ⊆ ↑(closure S) :=
begin
intro g,
intro hgS,
rw [mem_coe, mem_closure_iff],
intros H hH,
apply hH,
exact hgS,
end
-- 2ª demostración
lemma subset_closure'
(S : set G)
: S ⊆ closure S :=
λ s hs H ⟨y, hy⟩, by {rw [←hy, mem_Inter], exact λ hS, hS hs}
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que si S ⊆ T, entonces closure S ≤ closure T.
-- ---------------------------------------------------------------------
lemma closure_mono
{S T : set G}
(hST : S ⊆ T)
: closure S ≤ closure T :=
begin
intros x hx,
rw [mem_carrier, mem_closure_iff] at *,
intros H hTH,
apply hx,
exact subset.trans hST hTH,
end
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que
-- closure S ≤ H ↔ S ⊆ ↑H
-- ---------------------------------------------------------------------
lemma closure_le
(S : set G)
(H : subgroup G)
: closure S ≤ H ↔ S ⊆ ↑H :=
begin
split,
{ intro hSH,
exact subset.trans (subset_closure S) hSH },
{ intros hSH g hg,
rw [mem_carrier, mem_closure_iff] at hg,
exact hg _ hSH }
end
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que
-- closure S = closure (closure S)
-- ---------------------------------------------------------------------
lemma closure_closure
(S : set G)
: closure S = closure (closure S) :=
begin
apply le_antisymm,
{ apply subset_closure, },
{ rw closure_le,
intros x hx,
exact hx },
end
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que
-- closure ↑H = H
-- ---------------------------------------------------------------------
lemma closure_self
{H : subgroup G}
: closure ↑H = H :=
begin
apply le_antisymm,
{ rw le_iff,
intro g,
rw mem_closure_iff,
intro h,
apply h,
refl },
{ exact subset_closure H }
end
-- ---------------------------------------------------------------------
-- Ejercicio. Sean G un grupo, S ⊆ G y p una propiedad sobre
-- G. Demostrar que si
-- ∀ x ∈ S, p x
-- p 1
-- ∀ x y, p x → p y → p (x * y)
-- ∀ x, p x → p x⁻¹
-- entonces
-- ∀ x, x ∈ closure S → p x
-- ---------------------------------------------------------------------
-- 1ª demostración
lemma closure_induction
{p : G → Prop}
{S : set G}
(HS : ∀ x ∈ S, p x)
(H1 : p 1)
(Hmul : ∀ x y, p x → p y → p (x * y))
(Hinv : ∀ x, p x → p x⁻¹)
: ∀ x, x ∈ closure S → p x :=
begin
let H : subgroup G :=
{ carrier := p,
one_mem' := H1,
mul_mem' := Hmul,
inv_mem' := Hinv },
change closure S ≤ H,
change S ⊆ ↑H at HS,
rw closure_le,
exact HS,
end
-- 2ª demostración
lemma closure_induction'
{p : G → Prop}
{S : set G}
(HS : ∀ x ∈ S, p x)
(H1 : p 1)
(Hmul : ∀ x y, p x → p y → p (x * y))
(Hinv : ∀ x, p x → p x⁻¹)
: ∀ x, x ∈ closure S → p x :=
λ x h, (@closure_le _ _ _ ⟨p, H1, Hmul, Hinv⟩).2 HS h
-- Una conexión de Galois https://bit.ly/3vfzFSS entre un par de tipos α
-- y β, parcialmente ordenados, es un par de funciones `l : α → β` y
-- `u : β → α` tales que `∀a b, l a ≤ b ↔ a ≤ u b`. Su definición en
-- Lean es
-- def galois_connection [preorder α] [preorder β] (l : α → β) (u : β → α) :=
-- ∀a b, l a ≤ b ↔ a ≤ u b
--
-- A inserción de Galois insertion es una conexión de Galois connection
-- tal que `l ∘ u = id`. También contiene una función de elección. Su
-- definición en Lean es
-- structure galois_insertion {α β : Type*} [preorder α] [preorder β] (l : α → β) (u : β → α) :=
-- (choice : Πx:α, u (l x) ≤ x → β)
-- (gc : galois_connection l u)
-- (le_l_u : ∀x, x ≤ l (u x))
-- (choice_eq : ∀a h, choice a h = l a)
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que `closure : set G → subgroup G` y
-- `coe : subgroup G → set G` forman una conexión de Galois entre los
-- subgrupos de G.
-- ---------------------------------------------------------------------
lemma gc :
galois_connection (closure : set G → subgroup G) (coe : subgroup G → set G) :=
closure_le
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que `closure : set G → subgroup G` y
-- `coe : subgroup G → set G` forman una inserción de Galois entre los
-- subgrupos de G.
-- ---------------------------------------------------------------------
def gi : galois_insertion (closure : set G → subgroup G) (coe : subgroup G → set G) :=
{ choice := λ S _, closure S,
gc := gc,
le_l_u := λ H, subset_closure (H : set G),
choice_eq := λ _ _, rfl }
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que los subgrupos son un retículo completo.
-- ---------------------------------------------------------------------
instance : complete_lattice (subgroup G) :=
{.. galois_insertion.lift_complete_lattice gi}
end subgroup
end oculto
-- =====================================================================
-- § Referencias --
-- =====================================================================
-- + Kevin Buzzard. "Formalising mathematics : workshop 2 — groups and
-- subgroups. https://bit.ly/3iaYdqM
-- + Kevin Buzzard. formalising-mathematics: week 2, Part_B_subgroups.lean
-- https://bit.ly/3oWT9ux
-- + Kevin Buzzard. formalising-mathematics: week 2, Part_B_subgroups_solutions.lean
-- https://bit.ly/3iR1z2z
|
Formal statement is: lemma algebraicI: "(\<And>i. coeff p i \<in> \<int>) \<Longrightarrow> p \<noteq> 0 \<Longrightarrow> poly p x = 0 \<Longrightarrow> algebraic x" Informal statement is: If $p$ is a polynomial with integer coefficients, $p$ is not the zero polynomial, and $p(x) = 0$, then $x$ is algebraic.
|
/-
Copyright (c) 2020 Thomas Browning, Patrick Lutz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning, Patrick Lutz
-/
import group_theory.perm.cycle_type
import analysis.complex.polynomial
import field_theory.galois
/-!
# Galois Groups of Polynomials
In this file, we introduce the Galois group of a polynomial `p` over a field `F`,
defined as the automorphism group of its splitting field. We also provide
some results about some extension `E` above `p.splitting_field`, and some specific
results about the Galois groups of ℚ-polynomials with specific numbers of non-real roots.
## Main definitions
- `polynomial.gal p`: the Galois group of a polynomial p.
- `polynomial.gal.restrict p E`: the restriction homomorphism `(E ≃ₐ[F] E) → gal p`.
- `polynomial.gal.gal_action p E`: the action of `gal p` on the roots of `p` in `E`.
## Main results
- `polynomial.gal.restrict_smul`: `restrict p E` is compatible with `gal_action p E`.
- `polynomial.gal.gal_action_hom_injective`: `gal p` acting on the roots of `p` in `E` is faithful.
- `polynomial.gal.restrict_prod_injective`: `gal (p * q)` embeds as a subgroup of `gal p × gal q`.
- `polynomial.gal.card_of_separable`: For a separable polynomial, its Galois group has cardinality
equal to the dimension of its splitting field over `F`.
- `polynomial.gal.gal_action_hom_bijective_of_prime_degree`:
An irreducible polynomial of prime degree with two non-real roots has full Galois group.
## Other results
- `polynomial.gal.card_complex_roots_eq_card_real_add_card_not_gal_inv`: The number of complex roots
equals the number of real roots plus the number of roots not fixed by complex conjugation
(i.e. with some imaginary component).
-/
noncomputable theory
open_locale classical
open finite_dimensional
namespace polynomial
variables {F : Type*} [field F] (p q : polynomial F) (E : Type*) [field E] [algebra F E]
/-- The Galois group of a polynomial. -/
@[derive [group, fintype]]
def gal := p.splitting_field ≃ₐ[F] p.splitting_field
namespace gal
instance : has_coe_to_fun p.gal (λ _, p.splitting_field → p.splitting_field) :=
alg_equiv.has_coe_to_fun
@[ext] lemma ext {σ τ : p.gal} (h : ∀ x ∈ p.root_set p.splitting_field, σ x = τ x) : σ = τ :=
begin
refine alg_equiv.ext (λ x, (alg_hom.mem_equalizer σ.to_alg_hom τ.to_alg_hom x).mp
((set_like.ext_iff.mp _ x).mpr algebra.mem_top)),
rwa [eq_top_iff, ←splitting_field.adjoin_roots, algebra.adjoin_le_iff],
end
/-- If `p` splits in `F` then the `p.gal` is trivial. -/
def unique_gal_of_splits (h : p.splits (ring_hom.id F)) : unique p.gal :=
{ default := 1,
uniq := λ f, alg_equiv.ext (λ x, by { obtain ⟨y, rfl⟩ := algebra.mem_bot.mp
((set_like.ext_iff.mp ((is_splitting_field.splits_iff _ p).mp h) x).mp algebra.mem_top),
rw [alg_equiv.commutes, alg_equiv.commutes] }) }
instance [h : fact (p.splits (ring_hom.id F))] : unique p.gal :=
unique_gal_of_splits _ (h.1)
instance unique_gal_zero : unique (0 : polynomial F).gal :=
unique_gal_of_splits _ (splits_zero _)
instance unique_gal_one : unique (1 : polynomial F).gal :=
unique_gal_of_splits _ (splits_one _)
instance unique_gal_C (x : F) : unique (C x).gal :=
unique_gal_of_splits _ (splits_C _ _)
instance unique_gal_X : unique (X : polynomial F).gal :=
unique_gal_of_splits _ (splits_X _)
instance unique_gal_X_sub_C (x : F) : unique (X - C x).gal :=
unique_gal_of_splits _ (splits_X_sub_C _)
instance unique_gal_X_pow (n : ℕ) : unique (X ^ n : polynomial F).gal :=
unique_gal_of_splits _ (splits_X_pow _ _)
instance [h : fact (p.splits (algebra_map F E))] : algebra p.splitting_field E :=
(is_splitting_field.lift p.splitting_field p h.1).to_ring_hom.to_algebra
instance [h : fact (p.splits (algebra_map F E))] : is_scalar_tower F p.splitting_field E :=
is_scalar_tower.of_algebra_map_eq
(λ x, ((is_splitting_field.lift p.splitting_field p h.1).commutes x).symm)
-- The `algebra p.splitting_field E` instance above behaves badly when
-- `E := p.splitting_field`, since it may result in a unification problem
-- `is_splitting_field.lift.to_ring_hom.to_algebra =?= algebra.id`,
-- which takes an extremely long time to resolve, causing timeouts.
-- Since we don't really care about this definition, marking it as irreducible
-- causes that unification to error out early.
attribute [irreducible] gal.algebra
/-- Restrict from a superfield automorphism into a member of `gal p`. -/
def restrict [fact (p.splits (algebra_map F E))] : (E ≃ₐ[F] E) →* p.gal :=
alg_equiv.restrict_normal_hom p.splitting_field
lemma restrict_surjective [fact (p.splits (algebra_map F E))] [normal F E] :
function.surjective (restrict p E) :=
alg_equiv.restrict_normal_hom_surjective E
section roots_action
/-- The function taking `roots p p.splitting_field` to `roots p E`. This is actually a bijection,
see `polynomial.gal.map_roots_bijective`. -/
def map_roots [fact (p.splits (algebra_map F E))] :
root_set p p.splitting_field → root_set p E :=
λ x, ⟨is_scalar_tower.to_alg_hom F p.splitting_field E x, begin
have key := subtype.mem x,
by_cases p = 0,
{ simp only [h, root_set_zero] at key,
exact false.rec _ key },
{ rw [mem_root_set h, aeval_alg_hom_apply, (mem_root_set h).mp key, alg_hom.map_zero] } end⟩
lemma map_roots_bijective [h : fact (p.splits (algebra_map F E))] :
function.bijective (map_roots p E) :=
begin
split,
{ exact λ _ _ h, subtype.ext (ring_hom.injective _ (subtype.ext_iff.mp h)) },
{ intro y,
-- this is just an equality of two different ways to write the roots of `p` as an `E`-polynomial
have key := roots_map
(is_scalar_tower.to_alg_hom F p.splitting_field E : p.splitting_field →+* E)
((splits_id_iff_splits _).mpr (is_splitting_field.splits p.splitting_field p)),
rw [map_map, alg_hom.comp_algebra_map] at key,
have hy := subtype.mem y,
simp only [root_set, finset.mem_coe, multiset.mem_to_finset, key, multiset.mem_map] at hy,
rcases hy with ⟨x, hx1, hx2⟩,
exact ⟨⟨x, multiset.mem_to_finset.mpr hx1⟩, subtype.ext hx2⟩ }
end
/-- The bijection between `root_set p p.splitting_field` and `root_set p E`. -/
def roots_equiv_roots [fact (p.splits (algebra_map F E))] :
(root_set p p.splitting_field) ≃ (root_set p E) :=
equiv.of_bijective (map_roots p E) (map_roots_bijective p E)
instance gal_action_aux : mul_action p.gal (root_set p p.splitting_field) :=
{ smul := λ ϕ x, ⟨ϕ x, begin
have key := subtype.mem x,
--simp only [root_set, finset.mem_coe, multiset.mem_to_finset] at *,
by_cases p = 0,
{ simp only [h, root_set_zero] at key,
exact false.rec _ key },
{ rw mem_root_set h,
change aeval (ϕ.to_alg_hom x) p = 0,
rw [aeval_alg_hom_apply, (mem_root_set h).mp key, alg_hom.map_zero] } end⟩,
one_smul := λ _, by { ext, refl },
mul_smul := λ _ _ _, by { ext, refl } }
/-- The action of `gal p` on the roots of `p` in `E`. -/
instance gal_action [fact (p.splits (algebra_map F E))] : mul_action p.gal (root_set p E) :=
{ smul := λ ϕ x, roots_equiv_roots p E (ϕ • ((roots_equiv_roots p E).symm x)),
one_smul := λ _, by simp only [equiv.apply_symm_apply, one_smul],
mul_smul := λ _ _ _, by simp only [equiv.apply_symm_apply, equiv.symm_apply_apply, mul_smul] }
variables {p E}
/-- `polynomial.gal.restrict p E` is compatible with `polynomial.gal.gal_action p E`. -/
@[simp] lemma restrict_smul [fact (p.splits (algebra_map F E))]
(ϕ : E ≃ₐ[F] E) (x : root_set p E) : ↑((restrict p E ϕ) • x) = ϕ x :=
begin
let ψ := alg_equiv.of_injective_field (is_scalar_tower.to_alg_hom F p.splitting_field E),
change ↑(ψ (ψ.symm _)) = ϕ x,
rw alg_equiv.apply_symm_apply ψ,
change ϕ (roots_equiv_roots p E ((roots_equiv_roots p E).symm x)) = ϕ x,
rw equiv.apply_symm_apply (roots_equiv_roots p E),
end
variables (p E)
/-- `polynomial.gal.gal_action` as a permutation representation -/
def gal_action_hom [fact (p.splits (algebra_map F E))] : p.gal →* equiv.perm (root_set p E) :=
{ to_fun := λ ϕ, equiv.mk (λ x, ϕ • x) (λ x, ϕ⁻¹ • x)
(λ x, inv_smul_smul ϕ x) (λ x, smul_inv_smul ϕ x),
map_one' := by { ext1 x, exact mul_action.one_smul x },
map_mul' := λ x y, by { ext1 z, exact mul_action.mul_smul x y z } }
lemma gal_action_hom_restrict [fact (p.splits (algebra_map F E))]
(ϕ : E ≃ₐ[F] E) (x : root_set p E) : ↑(gal_action_hom p E (restrict p E ϕ) x) = ϕ x :=
restrict_smul ϕ x
/-- `gal p` embeds as a subgroup of permutations of the roots of `p` in `E`. -/
lemma gal_action_hom_injective [fact (p.splits (algebra_map F E))] :
function.injective (gal_action_hom p E) :=
begin
rw monoid_hom.injective_iff,
intros ϕ hϕ,
ext x hx,
have key := equiv.perm.ext_iff.mp hϕ (roots_equiv_roots p E ⟨x, hx⟩),
change roots_equiv_roots p E (ϕ • (roots_equiv_roots p E).symm
(roots_equiv_roots p E ⟨x, hx⟩)) = roots_equiv_roots p E ⟨x, hx⟩ at key,
rw equiv.symm_apply_apply at key,
exact subtype.ext_iff.mp (equiv.injective (roots_equiv_roots p E) key),
end
end roots_action
variables {p q}
/-- `polynomial.gal.restrict`, when both fields are splitting fields of polynomials. -/
def restrict_dvd (hpq : p ∣ q) : q.gal →* p.gal :=
if hq : q = 0 then 1 else @restrict F _ p _ _ _
⟨splits_of_splits_of_dvd (algebra_map F q.splitting_field) hq (splitting_field.splits q) hpq⟩
lemma restrict_dvd_surjective (hpq : p ∣ q) (hq : q ≠ 0) :
function.surjective (restrict_dvd hpq) :=
by simp only [restrict_dvd, dif_neg hq, restrict_surjective]
variables (p q)
/-- The Galois group of a product maps into the product of the Galois groups. -/
def restrict_prod : (p * q).gal →* p.gal × q.gal :=
monoid_hom.prod (restrict_dvd (dvd_mul_right p q)) (restrict_dvd (dvd_mul_left q p))
/-- `polynomial.gal.restrict_prod` is actually a subgroup embedding. -/
lemma restrict_prod_injective : function.injective (restrict_prod p q) :=
begin
by_cases hpq : (p * q) = 0,
{ haveI : unique (p * q).gal, { rw hpq, apply_instance },
exact λ f g h, eq.trans (unique.eq_default f) (unique.eq_default g).symm },
intros f g hfg,
dsimp only [restrict_prod, restrict_dvd] at hfg,
simp only [dif_neg hpq, monoid_hom.prod_apply, prod.mk.inj_iff] at hfg,
ext x hx,
rw [root_set, map_mul, polynomial.roots_mul] at hx,
cases multiset.mem_add.mp (multiset.mem_to_finset.mp hx) with h h,
{ haveI : fact (p.splits (algebra_map F (p * q).splitting_field)) :=
⟨splits_of_splits_of_dvd _ hpq (splitting_field.splits (p * q)) (dvd_mul_right p q)⟩,
have key : x = algebra_map (p.splitting_field) (p * q).splitting_field
((roots_equiv_roots p _).inv_fun ⟨x, multiset.mem_to_finset.mpr h⟩) :=
subtype.ext_iff.mp (equiv.apply_symm_apply (roots_equiv_roots p _) ⟨x, _⟩).symm,
rw [key, ←alg_equiv.restrict_normal_commutes, ←alg_equiv.restrict_normal_commutes],
exact congr_arg _ (alg_equiv.ext_iff.mp hfg.1 _) },
{ haveI : fact (q.splits (algebra_map F (p * q).splitting_field)) :=
⟨splits_of_splits_of_dvd _ hpq (splitting_field.splits (p * q)) (dvd_mul_left q p)⟩,
have key : x = algebra_map (q.splitting_field) (p * q).splitting_field
((roots_equiv_roots q _).inv_fun ⟨x, multiset.mem_to_finset.mpr h⟩) :=
subtype.ext_iff.mp (equiv.apply_symm_apply (roots_equiv_roots q _) ⟨x, _⟩).symm,
rw [key, ←alg_equiv.restrict_normal_commutes, ←alg_equiv.restrict_normal_commutes],
exact congr_arg _ (alg_equiv.ext_iff.mp hfg.2 _) },
{ rwa [ne.def, mul_eq_zero, map_eq_zero, map_eq_zero, ←mul_eq_zero] }
end
/-- `p` splits in the splitting field of `p ∘ q`, for `q` non-constant. -/
lemma splits_in_splitting_field_of_comp (hq : q.nat_degree ≠ 0) :
p.splits (algebra_map F (p.comp q).splitting_field) :=
begin
let P : polynomial F → Prop := λ r, r.splits (algebra_map F (r.comp q).splitting_field),
have key1 : ∀ {r : polynomial F}, irreducible r → P r,
{ intros r hr,
by_cases hr' : nat_degree r = 0,
{ exact splits_of_nat_degree_le_one _ (le_trans (le_of_eq hr') zero_le_one) },
obtain ⟨x, hx⟩ := exists_root_of_splits _ (splitting_field.splits (r.comp q))
(λ h, hr' ((mul_eq_zero.mp (nat_degree_comp.symm.trans
(nat_degree_eq_of_degree_eq_some h))).resolve_right hq)),
rw [←aeval_def, aeval_comp] at hx,
have h_normal : normal F (r.comp q).splitting_field := splitting_field.normal (r.comp q),
have qx_int := normal.is_integral h_normal (aeval x q),
exact splits_of_splits_of_dvd _
(minpoly.ne_zero qx_int)
(normal.splits h_normal _)
((minpoly.irreducible qx_int).dvd_symm hr (minpoly.dvd F _ hx)) },
have key2 : ∀ {p₁ p₂ : polynomial F}, P p₁ → P p₂ → P (p₁ * p₂),
{ intros p₁ p₂ hp₁ hp₂,
by_cases h₁ : p₁.comp q = 0,
{ cases comp_eq_zero_iff.mp h₁ with h h,
{ rw [h, zero_mul],
exact splits_zero _ },
{ exact false.rec _ (hq (by rw [h.2, nat_degree_C])) } },
by_cases h₂ : p₂.comp q = 0,
{ cases comp_eq_zero_iff.mp h₂ with h h,
{ rw [h, mul_zero],
exact splits_zero _ },
{ exact false.rec _ (hq (by rw [h.2, nat_degree_C])) } },
have key := mul_splits_in_splitting_field_of_mul h₁ h₂ hp₁ hp₂,
rwa ← mul_comp at key },
exact wf_dvd_monoid.induction_on_irreducible p (splits_zero _)
(λ _, splits_of_is_unit _) (λ _ _ _ h, key2 (key1 h)),
end
/-- `polynomial.gal.restrict` for the composition of polynomials. -/
def restrict_comp (hq : q.nat_degree ≠ 0) : (p.comp q).gal →* p.gal :=
@restrict F _ p _ _ _ ⟨splits_in_splitting_field_of_comp p q hq⟩
lemma restrict_comp_surjective (hq : q.nat_degree ≠ 0) :
function.surjective (restrict_comp p q hq) :=
by simp only [restrict_comp, restrict_surjective]
variables {p q}
/-- For a separable polynomial, its Galois group has cardinality
equal to the dimension of its splitting field over `F`. -/
lemma card_of_separable (hp : p.separable) :
fintype.card p.gal = finrank F p.splitting_field :=
begin
haveI : is_galois F p.splitting_field := is_galois.of_separable_splitting_field hp,
exact is_galois.card_aut_eq_finrank F p.splitting_field,
end
lemma prime_degree_dvd_card [char_zero F] (p_irr : irreducible p) (p_deg : p.nat_degree.prime) :
p.nat_degree ∣ fintype.card p.gal :=
begin
rw gal.card_of_separable p_irr.separable,
have hp : p.degree ≠ 0 :=
λ h, nat.prime.ne_zero p_deg (nat_degree_eq_zero_iff_degree_le_zero.mpr (le_of_eq h)),
let α : p.splitting_field := root_of_splits (algebra_map F p.splitting_field)
(splitting_field.splits p) hp,
have hα : is_integral F α :=
(is_algebraic_iff_is_integral F).mp (algebra.is_algebraic_of_finite α),
use finite_dimensional.finrank F⟮α⟯ p.splitting_field,
suffices : (minpoly F α).nat_degree = p.nat_degree,
{ rw [←finite_dimensional.finrank_mul_finrank F F⟮α⟯ p.splitting_field,
intermediate_field.adjoin.finrank hα, this] },
suffices : minpoly F α ∣ p,
{ have key := (minpoly.irreducible hα).dvd_symm p_irr this,
apply le_antisymm,
{ exact nat_degree_le_of_dvd this p_irr.ne_zero },
{ exact nat_degree_le_of_dvd key (minpoly.ne_zero hα) } },
apply minpoly.dvd F α,
rw [aeval_def, map_root_of_splits _ (splitting_field.splits p) hp],
end
section rationals
lemma splits_ℚ_ℂ {p : polynomial ℚ} : fact (p.splits (algebra_map ℚ ℂ)) :=
⟨is_alg_closed.splits_codomain p⟩
local attribute [instance] splits_ℚ_ℂ
/-- The number of complex roots equals the number of real roots plus
the number of roots not fixed by complex conjugation (i.e. with some imaginary component). -/
lemma card_complex_roots_eq_card_real_add_card_not_gal_inv (p : polynomial ℚ) :
(p.root_set ℂ).to_finset.card = (p.root_set ℝ).to_finset.card +
(gal_action_hom p ℂ (restrict p ℂ (complex.conj_ae.restrict_scalars ℚ))).support.card :=
begin
by_cases hp : p = 0,
{ simp_rw [hp, root_set_zero, set.to_finset_eq_empty_iff.mpr rfl, finset.card_empty, zero_add],
refine eq.symm (nat.le_zero_iff.mp ((finset.card_le_univ _).trans (le_of_eq _))),
simp_rw [hp, root_set_zero, fintype.card_eq_zero_iff],
apply_instance },
have inj : function.injective (is_scalar_tower.to_alg_hom ℚ ℝ ℂ) := (algebra_map ℝ ℂ).injective,
rw [←finset.card_image_of_injective _ subtype.coe_injective,
←finset.card_image_of_injective _ inj],
let a : finset ℂ := _,
let b : finset ℂ := _,
let c : finset ℂ := _,
change a.card = b.card + c.card,
have ha : ∀ z : ℂ, z ∈ a ↔ aeval z p = 0 :=
λ z, by rw [set.mem_to_finset, mem_root_set hp],
have hb : ∀ z : ℂ, z ∈ b ↔ aeval z p = 0 ∧ z.im = 0,
{ intro z,
simp_rw [finset.mem_image, exists_prop, set.mem_to_finset, mem_root_set hp],
split,
{ rintros ⟨w, hw, rfl⟩,
exact ⟨by rw [aeval_alg_hom_apply, hw, alg_hom.map_zero], rfl⟩ },
{ rintros ⟨hz1, hz2⟩,
have key : is_scalar_tower.to_alg_hom ℚ ℝ ℂ z.re = z := by { ext, refl, rw hz2, refl },
exact ⟨z.re, inj (by rwa [←aeval_alg_hom_apply, key, alg_hom.map_zero]), key⟩ } },
have hc0 : ∀ w : p.root_set ℂ, gal_action_hom p ℂ
(restrict p ℂ (complex.conj_ae.restrict_scalars ℚ)) w = w ↔ w.val.im = 0,
{ intro w,
rw [subtype.ext_iff, gal_action_hom_restrict],
exact complex.eq_conj_iff_im },
have hc : ∀ z : ℂ, z ∈ c ↔ aeval z p = 0 ∧ z.im ≠ 0,
{ intro z,
simp_rw [finset.mem_image, exists_prop],
split,
{ rintros ⟨w, hw, rfl⟩,
exact ⟨(mem_root_set hp).mp w.2, mt (hc0 w).mpr (equiv.perm.mem_support.mp hw)⟩ },
{ rintros ⟨hz1, hz2⟩,
exact ⟨⟨z, (mem_root_set hp).mpr hz1⟩,
equiv.perm.mem_support.mpr (mt (hc0 _).mp hz2), rfl⟩ } },
rw ← finset.card_disjoint_union,
{ apply congr_arg finset.card,
simp_rw [finset.ext_iff, finset.mem_union, ha, hb, hc],
tauto },
{ intro z,
rw [finset.inf_eq_inter, finset.mem_inter, hb, hc],
tauto },
{ apply_instance },
end
/-- An irreducible polynomial of prime degree with two non-real roots has full Galois group. -/
lemma gal_action_hom_bijective_of_prime_degree
{p : polynomial ℚ} (p_irr : irreducible p) (p_deg : p.nat_degree.prime)
(p_roots : fintype.card (p.root_set ℂ) = fintype.card (p.root_set ℝ) + 2) :
function.bijective (gal_action_hom p ℂ) :=
begin
have h1 : fintype.card (p.root_set ℂ) = p.nat_degree,
{ simp_rw [root_set_def, finset.coe_sort_coe, fintype.card_coe],
rw [multiset.to_finset_card_of_nodup, ←nat_degree_eq_card_roots],
{ exact is_alg_closed.splits_codomain p },
{ exact nodup_roots ((separable_map (algebra_map ℚ ℂ)).mpr p_irr.separable) } },
have h2 : fintype.card p.gal = fintype.card (gal_action_hom p ℂ).range :=
fintype.card_congr (monoid_hom.of_injective (gal_action_hom_injective p ℂ)).to_equiv,
let conj := restrict p ℂ (complex.conj_ae.restrict_scalars ℚ),
refine ⟨gal_action_hom_injective p ℂ, λ x, (congr_arg (has_mem.mem x)
(show (gal_action_hom p ℂ).range = ⊤, from _)).mpr (subgroup.mem_top x)⟩,
apply equiv.perm.subgroup_eq_top_of_swap_mem,
{ rwa h1 },
{ rw h1,
convert prime_degree_dvd_card p_irr p_deg using 1,
convert h2.symm },
{ exact ⟨conj, rfl⟩ },
{ rw ← equiv.perm.card_support_eq_two,
apply nat.add_left_cancel,
rw [←p_roots, ←set.to_finset_card (root_set p ℝ), ←set.to_finset_card (root_set p ℂ)],
exact (card_complex_roots_eq_card_real_add_card_not_gal_inv p).symm },
end
/-- An irreducible polynomial of prime degree with 1-3 non-real roots has full Galois group. -/
lemma gal_action_hom_bijective_of_prime_degree'
{p : polynomial ℚ} (p_irr : irreducible p) (p_deg : p.nat_degree.prime)
(p_roots1 : fintype.card (p.root_set ℝ) + 1 ≤ fintype.card (p.root_set ℂ))
(p_roots2 : fintype.card (p.root_set ℂ) ≤ fintype.card (p.root_set ℝ) + 3) :
function.bijective (gal_action_hom p ℂ) :=
begin
apply gal_action_hom_bijective_of_prime_degree p_irr p_deg,
let n := (gal_action_hom p ℂ (restrict p ℂ
(complex.conj_ae.restrict_scalars ℚ))).support.card,
have hn : 2 ∣ n :=
equiv.perm.two_dvd_card_support (by rw [←monoid_hom.map_pow, ←monoid_hom.map_pow,
show alg_equiv.restrict_scalars ℚ complex.conj_ae ^ 2 = 1,
from alg_equiv.ext complex.conj_conj, monoid_hom.map_one, monoid_hom.map_one]),
have key := card_complex_roots_eq_card_real_add_card_not_gal_inv p,
simp_rw [set.to_finset_card] at key,
rw [key, add_le_add_iff_left] at p_roots1 p_roots2,
rw [key, add_right_inj],
suffices : ∀ m : ℕ, 2 ∣ m → 1 ≤ m → m ≤ 3 → m = 2,
{ exact this n hn p_roots1 p_roots2 },
rintros m ⟨k, rfl⟩ h2 h3,
exact le_antisymm (nat.lt_succ_iff.mp (lt_of_le_of_ne h3 (show 2 * k ≠ 2 * 1 + 1,
from nat.two_mul_ne_two_mul_add_one))) (nat.succ_le_iff.mpr (lt_of_le_of_ne h2
(show 2 * 0 + 1 ≠ 2 * k, from nat.two_mul_ne_two_mul_add_one.symm))),
end
end rationals
end gal
end polynomial
|
= Chris Turner ( American football ) =
|
theory Substitution
imports Terms
begin
text \<open>Defining a substitution function on terms turned out to be slightly tricky.\<close>
fun
subst_var :: "var \<Rightarrow> var \<Rightarrow> var \<Rightarrow> var" ("_[_::v=_]" [1000,100,100] 1000)
where "x[y ::v= z] = (if x = y then z else x)"
nominal_function (default "case_sum (\<lambda>x. Inl undefined) (\<lambda>x. Inr undefined)",
invariant "\<lambda> a r . (\<forall> \<Gamma> y z . ((a = Inr (\<Gamma>, y, z) \<and> atom ` domA \<Gamma> \<sharp>* (y, z)) \<longrightarrow> map (\<lambda>x . atom (fst x)) (Sum_Type.projr r) = map (\<lambda>x . atom (fst x)) \<Gamma>))")
subst :: "exp \<Rightarrow> var \<Rightarrow> var \<Rightarrow> exp" ("_[_::=_]" [1000,100,100] 1000)
and
subst_heap :: "heap \<Rightarrow> var \<Rightarrow> var \<Rightarrow> heap" ("_[_::h=_]" [1000,100,100] 1000)
where
"(Var x)[y ::= z] = Var (x[y ::v= z])"
| "(App e v)[y ::= z] = App (e[y ::= z]) (v[y ::v= z])"
| "atom ` domA \<Gamma> \<sharp>* (y,z) \<Longrightarrow>
(Let \<Gamma> body)[y ::= z] = Let (\<Gamma>[y ::h= z]) (body[y ::= z])"
| "atom x \<sharp> (y,z) \<Longrightarrow> (Lam [x].e)[y ::= z] = Lam [x].(e[y::=z])"
| "(Bool b)[y ::= z] = Bool b"
| "(scrut ? e1 : e2)[y ::= z] = (scrut[y ::= z] ? e1[y ::= z] : e2[y ::= z])"
| "[][y ::h= z] = []"
| "((v,e)# \<Gamma>)[y ::h= z] = (v, e[y ::= z])# (\<Gamma>[y ::h= z])"
proof goal_cases
have eqvt_at_subst: "\<And> e y z . eqvt_at subst_subst_heap_sumC (Inl (e, y, z)) \<Longrightarrow> eqvt_at (\<lambda>(a, b, c). subst a b c) (e, y, z)"
apply(simp add: eqvt_at_def subst_def)
apply(rule)
apply(subst Projl_permute)
apply(thin_tac _)+
apply (simp add: subst_subst_heap_sumC_def)
apply (simp add: THE_default_def)
apply (case_tac "Ex1 (subst_subst_heap_graph (Inl (e, y, z)))")
apply(simp)
apply(auto)[1]
apply (erule_tac x="x" in allE)
apply simp
apply(cases rule: subst_subst_heap_graph.cases)
apply(assumption)
apply(rule_tac x="Sum_Type.projl x" in exI)
apply(clarify)
apply (rule the1_equality)
apply blast
apply(simp (no_asm) only: sum.sel)
apply(rule_tac x="Sum_Type.projl x" in exI)
apply(clarify)
apply (rule the1_equality)
apply blast
apply(simp (no_asm) only: sum.sel)
apply(rule_tac x="Sum_Type.projl x" in exI)
apply(clarify)
apply (rule the1_equality)
apply blast
apply(simp (no_asm) only: sum.sel)
apply(rule_tac x="Sum_Type.projl x" in exI)
apply(clarify)
apply (rule the1_equality)
apply blast
apply(simp (no_asm) only: sum.sel)
apply(rule_tac x="Sum_Type.projl x" in exI)
apply(clarify)
apply (rule the1_equality)
apply blast
apply(simp (no_asm) only: sum.sel)
apply(rule_tac x="Sum_Type.projl x" in exI)
apply(clarify)
apply (rule the1_equality)
apply blast
apply(simp (no_asm) only: sum.sel)
apply (metis Inr_not_Inl)
apply (metis Inr_not_Inl)
apply(simp)
apply(perm_simp)
apply(simp)
done
have eqvt_at_subst_heap: "\<And> \<Gamma> y z . eqvt_at subst_subst_heap_sumC (Inr (\<Gamma>, y, z)) \<Longrightarrow> eqvt_at (\<lambda>(a, b, c). subst_heap a b c) (\<Gamma>, y, z)"
apply(simp add: eqvt_at_def subst_heap_def)
apply(rule)
apply(subst Projr_permute)
apply(thin_tac _)+
apply (simp add: subst_subst_heap_sumC_def)
apply (simp add: THE_default_def)
apply (case_tac "Ex1 (subst_subst_heap_graph (Inr (\<Gamma>, y, z)))")
apply(simp)
apply(auto)[1]
apply (erule_tac x="x" in allE)
apply simp
apply(cases rule: subst_subst_heap_graph.cases)
apply(assumption)
apply (metis (mono_tags) Inr_not_Inl)+
apply(rule_tac x="Sum_Type.projr x" in exI)
apply(clarify)
apply (rule the1_equality)
apply auto[1]
apply(simp (no_asm) only: sum.sel)
apply(rule_tac x="Sum_Type.projr x" in exI)
apply(clarify)
apply (rule the1_equality)
apply auto[1]
apply(simp (no_asm) only: sum.sel)
apply(simp)
apply(perm_simp)
apply(simp)
done
{
(* Equivariance of the graph *)
case 1 thus ?case
unfolding eqvt_def subst_subst_heap_graph_aux_def
by simp
(* The invariant *)
next case 2 thus ?case
by (induct rule: subst_subst_heap_graph.induct)(auto simp add: exp_assn.bn_defs fresh_star_insert)
(* Exhaustiveness *)
next case prems: (3 P x) show ?case
proof(cases x)
case (Inl a) thus P
proof(cases a)
case (fields a1 a2 a3)
thus P using Inl prems
apply (rule_tac y ="a1" and c ="(a2, a3)" in exp_strong_exhaust)
apply (auto simp add: fresh_star_def)
done
qed
next
case (Inr a) thus P
proof (cases a)
case (fields a1 a2 a3)
thus P using Inr prems
by (metis heapToAssn.cases)
qed
qed
next case (19 e y2 z2 \<Gamma> e2 y z as2) thus ?case
apply -
apply (drule eqvt_at_subst)+
apply (drule eqvt_at_subst_heap)+
apply (simp only: meta_eq_to_obj_eq[OF subst_def, symmetric, unfolded fun_eq_iff]
meta_eq_to_obj_eq[OF subst_heap_def, symmetric, unfolded fun_eq_iff])
(* No _sum any more at this point! *)
apply (auto simp add: Abs_fresh_iff)
apply (drule_tac
c = "(y, z)" and
as = "(map (\<lambda>x. atom (fst x)) e)" and
bs = "(map (\<lambda>x. atom (fst x)) e2)" and
f = "\<lambda> a b c . [a]lst. (subst (fst b) y z, subst_heap (snd b) y z )" in Abs_lst_fcb2)
apply (simp add: perm_supp_eq fresh_Pair fresh_star_def Abs_fresh_iff)
apply (metis domA_def image_image image_set)
apply (metis domA_def image_image image_set)
apply (simp add: eqvt_at_def, simp add: fresh_star_Pair perm_supp_eq)
apply (simp add: eqvt_at_def, simp add: fresh_star_Pair perm_supp_eq)
apply (simp add: eqvt_at_def)
done
next case (25 x2 y2 z2 e2 x y z e) thus ?case
apply -
apply (drule eqvt_at_subst)+
apply (simp only: Abs_fresh_iff meta_eq_to_obj_eq[OF subst_def, symmetric, unfolded fun_eq_iff])
(* No _sum any more at this point! *)
apply (simp add: eqvt_at_def)
apply rule
apply (erule_tac x = "(x2 \<leftrightarrow> c)" in allE)
apply (erule_tac x = "(x \<leftrightarrow> c)" in allE)
apply auto
done
}
qed(auto)
nominal_termination (eqvt) by lexicographic_order
lemma shows
True and bn_subst[simp]: "domA (subst_heap \<Gamma> y z) = domA \<Gamma>"
by(induct rule:subst_subst_heap.induct)
(auto simp add: exp_assn.bn_defs fresh_star_insert)
lemma subst_noop[simp]:
shows "e[y ::= y] = e" and "\<Gamma>[y::h=y]= \<Gamma>"
by(induct e y y and \<Gamma> y y rule:subst_subst_heap.induct)
(auto simp add:fresh_star_Pair exp_assn.bn_defs)
lemma subst_is_fresh[simp]:
assumes "atom y \<sharp> z"
shows
"atom y \<sharp> e[y ::= z]"
and
"atom ` domA \<Gamma> \<sharp>* y \<Longrightarrow> atom y \<sharp> \<Gamma>[y::h=z]"
using assms
by(induct e y z and \<Gamma> y z rule:subst_subst_heap.induct)
(auto simp add:fresh_at_base fresh_star_Pair fresh_star_insert fresh_Nil fresh_Cons pure_fresh)
lemma
subst_pres_fresh: "atom x \<sharp> e \<or> x = y \<Longrightarrow> atom x \<sharp> z \<Longrightarrow> atom x \<sharp> e[y ::= z]"
and
"atom x \<sharp> \<Gamma> \<or> x = y \<Longrightarrow> atom x \<sharp> z \<Longrightarrow> x \<notin> domA \<Gamma> \<Longrightarrow> atom x \<sharp> (\<Gamma>[y ::h= z])"
by(induct e y z and \<Gamma> y z rule:subst_subst_heap.induct)
(auto simp add:fresh_star_Pair exp_assn.bn_defs fresh_Cons fresh_Nil pure_fresh)
lemma subst_fresh_noop: "atom x \<sharp> e \<Longrightarrow> e[x ::= y] = e"
and subst_heap_fresh_noop: "atom x \<sharp> \<Gamma> \<Longrightarrow> \<Gamma>[x ::h= y] = \<Gamma>"
by (nominal_induct e and \<Gamma> avoiding: x y rule:exp_heap_strong_induct)
(auto simp add: fresh_star_def fresh_Pair fresh_at_base fresh_Cons simp del: exp_assn.eq_iff)
lemma supp_subst_eq: "supp (e[y::=x]) = (supp e - {atom y}) \<union> (if atom y \<in> supp e then {atom x} else {})"
and "atom ` domA \<Gamma> \<sharp>* y \<Longrightarrow> supp (\<Gamma>[y::h=x]) = (supp \<Gamma> - {atom y}) \<union> (if atom y \<in> supp \<Gamma> then {atom x} else {})"
by (nominal_induct e and \<Gamma> avoiding: x y rule:exp_heap_strong_induct)
(auto simp add: fresh_star_def fresh_Pair supp_Nil supp_Cons supp_Pair fresh_Cons exp_assn.supp Let_supp supp_at_base pure_supp simp del: exp_assn.eq_iff)
lemma supp_subst: "supp (e[y::=x]) \<subseteq> (supp e - {atom y}) \<union> {atom x}"
using supp_subst_eq by auto
lemma fv_subst_eq: "fv (e[y::=x]) = (fv e - {y}) \<union> (if y \<in> fv e then {x} else {})"
and "atom ` domA \<Gamma> \<sharp>* y \<Longrightarrow> fv (\<Gamma>[y::h=x]) = (fv \<Gamma> - {y}) \<union> (if y \<in> fv \<Gamma> then {x} else {})"
by (nominal_induct e and \<Gamma> avoiding: x y rule:exp_heap_strong_induct)
(auto simp add: fresh_star_def fresh_Pair supp_Nil supp_Cons supp_Pair fresh_Cons exp_assn.supp Let_supp supp_at_base simp del: exp_assn.eq_iff)
lemma fv_subst_subset: "fv (e[y ::= x]) \<subseteq> (fv e - {y}) \<union> {x}"
using fv_subst_eq by auto
lemma fv_subst_int: "x \<notin> S \<Longrightarrow> y \<notin> S \<Longrightarrow> fv (e[y ::= x]) \<inter> S = fv e \<inter> S"
by (auto simp add: fv_subst_eq)
lemma fv_subst_int2: "x \<notin> S \<Longrightarrow> y \<notin> S \<Longrightarrow> S \<inter> fv (e[y ::= x]) = S \<inter> fv e"
by (auto simp add: fv_subst_eq)
lemma subst_swap_same: "atom x \<sharp> e \<Longrightarrow> (x \<leftrightarrow> y) \<bullet> e = e[y ::=x]"
and "atom x \<sharp> \<Gamma> \<Longrightarrow> atom `domA \<Gamma> \<sharp>* y \<Longrightarrow> (x \<leftrightarrow> y) \<bullet> \<Gamma> = \<Gamma>[y ::h= x]"
by (nominal_induct e and \<Gamma> avoiding: x y rule:exp_heap_strong_induct)
(auto simp add: fresh_star_Pair fresh_star_at_base fresh_Cons pure_fresh permute_pure simp del: exp_assn.eq_iff)
lemma subst_subst_back: "atom x \<sharp> e \<Longrightarrow> e[y::=x][x::=y] = e"
and "atom x \<sharp> \<Gamma> \<Longrightarrow> atom `domA \<Gamma> \<sharp>* y \<Longrightarrow> \<Gamma>[y::h=x][x::h=y] = \<Gamma>"
by(nominal_induct e and \<Gamma> avoiding: x y rule:exp_heap_strong_induct)
(auto simp add: fresh_star_Pair fresh_star_at_base fresh_star_Cons fresh_Cons exp_assn.bn_defs simp del: exp_assn.eq_iff)
lemma subst_heap_delete[simp]: "(delete x \<Gamma>)[y ::h= z] = delete x (\<Gamma>[y ::h= z])"
by (induction \<Gamma>) auto
lemma subst_nil_iff[simp]: "\<Gamma>[x ::h= z] = [] \<longleftrightarrow> \<Gamma> = []"
by (cases \<Gamma>) auto
lemma subst_SmartLet[simp]:
"atom ` domA \<Gamma> \<sharp>* (y,z) \<Longrightarrow> (SmartLet \<Gamma> body)[y ::= z] = SmartLet (\<Gamma>[y ::h= z]) (body[y ::= z])"
unfolding SmartLet_def by auto
lemma subst_let_be[simp]:
"atom x' \<sharp> y \<Longrightarrow> atom x' \<sharp> x \<Longrightarrow> (let x' be e in exp )[y::=x] = (let x' be e[y::=x] in exp[y::=x])"
by (simp add: fresh_star_def fresh_Pair)
lemma isLam_subst[simp]: "isLam e[x::=y] = isLam e"
by (nominal_induct e avoiding: x y rule: exp_strong_induct)
(auto simp add: fresh_star_Pair)
lemma isVal_subst[simp]: "isVal e[x::=y] = isVal e"
by (nominal_induct e avoiding: x y rule: exp_strong_induct)
(auto simp add: fresh_star_Pair)
lemma thunks_subst[simp]:
"thunks \<Gamma>[y::h=x] = thunks \<Gamma>"
by (induction \<Gamma>) (auto simp add: thunks_Cons)
lemma map_of_subst:
"map_of (\<Gamma>[x::h=y]) k = map_option (\<lambda> e . e[x::=y]) (map_of \<Gamma> k)"
by (induction \<Gamma> ) auto
lemma mapCollect_subst[simp]:
"{e k v | k\<mapsto>v\<in>map_of \<Gamma>[x::h=y]} = {e k v[x::=y] | k\<mapsto>v\<in>map_of \<Gamma>}"
by (auto simp add: map_of_subst)
lemma subst_eq_Cons:
"\<Gamma>[x::h=y] = (x', e)#\<Delta> \<longleftrightarrow> (\<exists> e' \<Gamma>'. \<Gamma> = (x',e')#\<Gamma>' \<and> e'[x::=y] = e \<and> \<Gamma>'[x::h=y] = \<Delta>)"
by (cases \<Gamma>) auto
lemma nonrec_subst:
"atom ` domA \<Gamma> \<sharp>* x \<Longrightarrow> atom ` domA \<Gamma> \<sharp>* y \<Longrightarrow> nonrec \<Gamma>[x::h=y] \<longleftrightarrow> nonrec \<Gamma>"
by (auto simp add: nonrec_def fresh_star_def subst_eq_Cons fv_subst_eq)
end
|
(*
Authors:
Anthony Bordg, University of Cambridge, [email protected];
Yijun He, University of Cambridge, [email protected]
*)
theory Quantum_Teleportation
imports
More_Tensor
Basics
Measurement
begin
definition alice:: "complex Matrix.mat \<Rightarrow> complex Matrix.mat" where
"alice \<phi> \<equiv> (H \<Otimes> Id 2) * ((CNOT \<Otimes> Id 1) * (\<phi> \<Otimes> |\<beta>\<^sub>0\<^sub>0\<rangle>))"
abbreviation M1:: "complex Matrix.mat" where
"M1 \<equiv> mat_of_cols_list 8 [[1, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0]]"
lemma tensor_prod_of_cnot_id_1:
shows "(CNOT \<Otimes> Id 1) = M1"
proof
show "dim_col (CNOT \<Otimes> Id 1) = dim_col M1"
by(simp add: CNOT_def Id_def mat_of_cols_list_def)
show "dim_row (CNOT \<Otimes> Id 1) = dim_row M1"
by(simp add: CNOT_def Id_def mat_of_cols_list_def)
fix i j::nat assume "i < dim_row M1" and "j < dim_col M1"
then have "i \<in> {0..<8} \<and> j \<in> {0..<8}"
by (auto simp add: mat_of_cols_list_def)
then show "(CNOT \<Otimes> Id 1) $$ (i, j) = M1 $$ (i, j)"
by (auto simp add: Id_def CNOT_def mat_of_cols_list_def)
qed
abbreviation M2:: "complex Matrix.mat" where
"M2 \<equiv> mat_of_cols_list 8 [[1/sqrt(2), 0, 0, 0, 1/sqrt(2), 0, 0, 0],
[0, 1/sqrt(2), 0, 0, 0, 1/sqrt(2), 0, 0],
[0, 0, 1/sqrt(2), 0, 0, 0, 1/sqrt(2), 0],
[0, 0, 0, 1/sqrt(2), 0, 0, 0, 1/sqrt(2)],
[1/sqrt(2), 0, 0, 0, -1/sqrt(2), 0, 0, 0],
[0, 1/sqrt(2), 0, 0, 0, -1/sqrt(2), 0, 0],
[0, 0, 1/sqrt(2), 0, 0, 0, -1/sqrt(2), 0],
[0, 0, 0, 1/sqrt(2), 0, 0, 0, -1/sqrt(2)]]"
lemma tensor_prod_of_h_id_2:
shows "(H \<Otimes> Id 2) = M2"
proof
show "dim_col (H \<Otimes> Id 2) = dim_col M2"
by(simp add: H_def Id_def mat_of_cols_list_def)
show "dim_row (H \<Otimes> Id 2) = dim_row M2"
by(simp add: H_def Id_def mat_of_cols_list_def)
fix i j::nat assume "i < dim_row M2" and "j < dim_col M2"
then have "i \<in> {0..<8} \<and> j \<in> {0..<8}"
by (auto simp add: mat_of_cols_list_def)
then show "(H \<Otimes> Id 2) $$ (i, j) = M2 $$ (i, j)"
by (auto simp add: Id_def H_def mat_of_cols_list_def)
qed
lemma alice_step_1_state [simp]:
assumes "state 1 \<phi>"
shows "state 3 (\<phi> \<Otimes> |\<beta>\<^sub>0\<^sub>0\<rangle>)"
using assms bell00_is_state tensor_state by(metis One_nat_def Suc_1 numeral_3_eq_3 plus_1_eq_Suc)
lemma alice_step_2_state:
assumes "state 1 \<phi>"
shows "state 3 ((CNOT \<Otimes> Id 1) * (\<phi> \<Otimes> |\<beta>\<^sub>0\<^sub>0\<rangle>))"
proof-
have "gate 3 (CNOT \<Otimes> Id 1)"
using CNOT_is_gate id_is_gate tensor_gate by (metis numeral_plus_one semiring_norm(5))
then show "state 3 ((CNOT \<Otimes> Id 1) * (\<phi> \<Otimes> |\<beta>\<^sub>0\<^sub>0\<rangle>))" using assms by simp
qed
lemma alice_state [simp]:
assumes "state 1 \<phi>"
shows "state 3 (alice \<phi>) "
proof-
have "gate 3 (H \<Otimes> Id 2)"
using tensor_gate id_is_gate H_is_gate by(metis eval_nat_numeral(3) plus_1_eq_Suc)
then show ?thesis
using assms alice_step_2_state by(simp add: alice_def)
qed
lemma alice_step_1:
assumes "state 1 \<phi>" and "\<alpha> = \<phi> $$ (0,0)" and "\<beta> = \<phi> $$ (1,0)"
shows "(\<phi> \<Otimes> |\<beta>\<^sub>0\<^sub>0\<rangle>) = mat_of_cols_list 8 [[\<alpha>/sqrt(2),0,0,\<alpha>/sqrt(2),\<beta>/sqrt(2),0,0,\<beta>/sqrt(2)]]"
proof
define v where asm:"v = mat_of_cols_list 8 [[\<alpha>/sqrt(2),0,0,\<alpha>/sqrt(2),\<beta>/sqrt(2),0,0,\<beta>/sqrt(2)]]"
then show "dim_row (\<phi> \<Otimes> |\<beta>\<^sub>0\<^sub>0\<rangle>) = dim_row v"
using assms(1) alice_step_1_state state.dim_row mat_of_cols_list_def by fastforce
show "dim_col (\<phi> \<Otimes> |\<beta>\<^sub>0\<^sub>0\<rangle>) = dim_col v"
using assms(1) alice_step_1_state state.is_column asm mat_of_cols_list_def by fastforce
show "\<And>i j. i < dim_row v \<Longrightarrow> j < dim_col v \<Longrightarrow> (\<phi> \<Otimes> |\<beta>\<^sub>0\<^sub>0\<rangle>) $$ (i,j) = v $$ (i,j)"
proof-
fix i j assume "i < dim_row v" and "j < dim_col v"
then have "i \<in> {0..<8} \<and> j = 0"
using asm by (auto simp add: mat_of_cols_list_def)
moreover have "dim_row |\<beta>\<^sub>0\<^sub>0\<rangle> = 4"
using bell00_is_state state_def by simp
moreover have "dim_col |\<beta>\<^sub>0\<^sub>0\<rangle> = 1"
using bell00_is_state state_def by simp
ultimately show "(\<phi> \<Otimes> |\<beta>\<^sub>0\<^sub>0\<rangle>) $$ (i, j) = v $$ (i,j)"
using state_def assms asm by (auto simp add: bell00_def)
qed
qed
lemma alice_step_2:
assumes "state 1 \<phi>" and "\<alpha> = \<phi> $$ (0,0)" and "\<beta> = \<phi> $$ (1,0)"
shows "(CNOT \<Otimes> Id 1) * (\<phi> \<Otimes> |\<beta>\<^sub>0\<^sub>0\<rangle>) = mat_of_cols_list 8 [[\<alpha>/sqrt(2),0,0,\<alpha>/sqrt(2),0,\<beta>/sqrt(2),\<beta>/sqrt(2),0]]"
proof
have f0:"(\<phi> \<Otimes> |\<beta>\<^sub>0\<^sub>0\<rangle>) = mat_of_cols_list 8 [[\<alpha>/sqrt(2),0,0,\<alpha>/sqrt(2),\<beta>/sqrt(2),0,0,\<beta>/sqrt(2)]]"
using assms alice_step_1 by simp
define v where asm:"v = mat_of_cols_list 8 [[\<alpha>/sqrt(2),0,0,\<alpha>/sqrt(2),0,\<beta>/sqrt(2),\<beta>/sqrt(2),0]]"
then show "dim_row ((CNOT \<Otimes> Id 1) * (\<phi> \<Otimes> |\<beta>\<^sub>0\<^sub>0\<rangle>)) = dim_row v"
using assms(1) alice_step_2_state state.dim_row mat_of_cols_list_def by fastforce
show "dim_col ((CNOT \<Otimes> Id 1) * (\<phi> \<Otimes> |\<beta>\<^sub>0\<^sub>0\<rangle>)) = dim_col v"
using assms(1) alice_step_2_state state.is_column asm mat_of_cols_list_def by fastforce
show "\<And>i j. i<dim_row v \<Longrightarrow> j<dim_col v \<Longrightarrow> ((CNOT \<Otimes> Id 1) * (\<phi> \<Otimes> |\<beta>\<^sub>0\<^sub>0\<rangle>)) $$ (i,j) = v $$ (i,j)"
proof-
fix i j assume "i < dim_row v" and "j < dim_col v"
then have "i \<in> {0..<8::nat} \<and> j = 0"
using asm by (auto simp add: mat_of_cols_list_def)
then have "(M1 * (\<phi> \<Otimes> |\<beta>\<^sub>0\<^sub>0\<rangle>)) $$ (i,j) = v $$ (i,j)"
by (auto simp add: f0 asm mat_of_cols_list_def times_mat_def scalar_prod_def)
then show "((CNOT \<Otimes> Id 1) * (\<phi> \<Otimes> |\<beta>\<^sub>0\<^sub>0\<rangle>)) $$ (i,j) = v $$ (i,j)"
using tensor_prod_of_cnot_id_1 by simp
qed
qed
lemma alice_result:
assumes "state 1 \<phi>" and "\<alpha> = \<phi> $$ (0,0)" and "\<beta> = \<phi> $$ (1,0)"
shows "alice \<phi> = mat_of_cols_list 8 [[\<alpha>/2, \<beta>/2, \<beta>/2, \<alpha>/2, \<alpha>/2, -\<beta>/2, -\<beta>/2, \<alpha>/2]]"
proof
define v where a0:"v = mat_of_cols_list 8 [[\<alpha>/2, \<beta>/2, \<beta>/2, \<alpha>/2, \<alpha>/2, -\<beta>/2, -\<beta>/2, \<alpha>/2]]"
define w where a1:"w = (CNOT \<Otimes> Id 1) * (\<phi> \<Otimes> |\<beta>\<^sub>0\<^sub>0\<rangle>)"
then have f0:"w = mat_of_cols_list 8 [[\<alpha>/sqrt(2), 0, 0, \<alpha>/sqrt(2), 0, \<beta>/sqrt(2), \<beta>/sqrt(2), 0]]"
using assms alice_step_2 by simp
show "dim_row (alice \<phi>) = dim_row v"
using assms(1) alice_state state_def a0 by (simp add: mat_of_cols_list_def)
show "dim_col (alice \<phi>) = dim_col v"
using assms(1) alice_state state_def a0 by (simp add: mat_of_cols_list_def)
show "\<And>i j. i < dim_row v \<Longrightarrow> j < dim_col v \<Longrightarrow> alice \<phi> $$ (i,j) = v $$ (i,j)"
proof-
fix i j assume "i < dim_row v" and "j < dim_col v"
then have "i \<in> {0..<8} \<and> j = 0"
using a0 by (auto simp add: Tensor.mat_of_cols_list_def)
then have "(M2 * w) $$ (i,j) = v $$ (i,j)"
by (auto simp add: f0 a0 mat_of_cols_list_def times_mat_def scalar_prod_def)
then show "alice \<phi> $$ (i,j) = v $$ (i,j)"
by (simp add: tensor_prod_of_h_id_2 alice_def a1)
qed
qed
text \<open>
An application of function @{term alice} to a state \<phi> of a 1-qubit system results in the following cases.
\<close>
definition alice_meas:: "complex Matrix.mat \<Rightarrow> _list" where
"alice_meas \<phi> = [
((prob0 3 (alice \<phi>) 0) * (prob0 3 (post_meas0 3 (alice \<phi>) 0) 1), post_meas0 3 (post_meas0 3 (alice \<phi>) 0) 1)
, ((prob0 3 (alice \<phi>) 0) * (prob1 3 (post_meas0 3 (alice \<phi>) 0) 1), post_meas1 3 (post_meas0 3 (alice \<phi>) 0) 1)
, ((prob1 3 (alice \<phi>) 0) * (prob0 3 (post_meas1 3 (alice \<phi>) 0) 1), post_meas0 3 (post_meas1 3 (alice \<phi>) 0) 1)
, ((prob1 3 (alice \<phi>) 0) * (prob1 3 (post_meas1 3 (alice \<phi>) 0) 1), post_meas1 3 (post_meas1 3 (alice \<phi>) 0) 1)
]"
definition alice_pos:: "complex Matrix.mat \<Rightarrow> complex Matrix.mat \<Rightarrow> bool" where
"alice_pos \<phi> q \<equiv> q = mat_of_cols_list 8 [[\<phi> $$ (0,0), \<phi> $$ (1,0), 0, 0, 0, 0, 0, 0]] \<or>
q = mat_of_cols_list 8 [[0, 0, \<phi> $$ (1,0), \<phi> $$ (0,0), 0, 0, 0, 0]] \<or>
q = mat_of_cols_list 8 [[0, 0, 0, 0, \<phi> $$ (0,0), - \<phi> $$ (1,0), 0, 0]] \<or>
q = mat_of_cols_list 8 [[0, 0, 0, 0, 0, 0, - \<phi> $$ (1,0), \<phi> $$ (0,0)]]"
lemma phi_vec_length:
assumes "state 1 \<phi>"
shows "cmod(\<phi> $$ (0,0))^2 + cmod(\<phi> $$ (Suc 0,0))^2 = 1"
using set_2 assms state_def Matrix.col_def cpx_vec_length_def by(auto simp add: atLeast0LessThan)
lemma select_index_3_subsets [simp]:
shows "{j::nat. select_index 3 0 j} = {4,5,6,7} \<and>
{j::nat. j < 8 \<and> \<not> select_index 3 0 j} = {0,1,2,3} \<and>
{j::nat. select_index 3 1 j} = {2,3,6,7} \<and>
{j::nat. j < 8 \<and> \<not> select_index 3 1 j} = {0,1,4,5}"
proof-
have "{j::nat. select_index 3 0 j} = {4,5,6,7}" by (auto simp add: select_index_def)
moreover have "{j::nat. j < 8 \<and> \<not> select_index 3 0 j} = {0,1,2,3}" by(auto simp add: select_index_def)
moreover have f1:"{j::nat. select_index 3 1 j} = {2,3,6,7}"
proof
show "{j. select_index 3 1 j} \<subseteq> {2,3,6,7}"
proof
fix j::nat assume "j \<in> {j. select_index 3 1 j}"
then have "j \<in> {0..<8} \<and> j mod 4 \<in> {2,3}" by (auto simp add: select_index_def)
then show "j \<in> {2,3,6,7}" by auto
qed
show "{2,3,6,7} \<subseteq> {j. select_index 3 1 j}" by (auto simp add: select_index_def)
qed
moreover have "{j::nat. j < 8 \<and> \<not> select_index 3 1 j} = {0,1,4,5}"
proof-
have "{j::nat. j < 8 \<and> j \<notin> {2,3,6,7}} = {0,1,4,5}" by auto
then show ?thesis using f1 by blast
qed
ultimately show ?thesis by simp
qed
lemma prob_index_0_alice:
assumes "state 1 \<phi>"
shows "prob0 3 (alice \<phi>) 0 = 1/2 \<and> prob1 3 (alice \<phi>) 0 = 1/2"
proof
show "prob0 3 (alice \<phi>) 0 = 1/2"
using alice_result assms prob0_def alice_state
apply auto by (metis (no_types, hide_lams) One_nat_def phi_vec_length four_x_squared mult.commute
nonzero_mult_div_cancel_right times_divide_eq_right zero_neq_numeral)
then show"prob1 3 (alice \<phi>) 0 = 1/2"
using prob_sum_is_one[of "3" "alice \<phi>" "0"] alice_state[of "\<phi>"] assms by linarith
qed
lemma post_meas0_index_0_alice:
assumes "state 1 \<phi>" and "\<alpha> = \<phi> $$ (0,0)" and "\<beta> = \<phi> $$ (1,0)"
shows "post_meas0 3 (alice \<phi>) 0 =
mat_of_cols_list 8 [[\<alpha>/sqrt(2), \<beta>/sqrt(2), \<beta>/sqrt(2), \<alpha>/sqrt(2), 0, 0, 0, 0]]"
proof
define v where asm:"v = mat_of_cols_list 8 [[\<alpha>/sqrt(2),\<beta>/sqrt(2),\<beta>/sqrt(2),\<alpha>/sqrt(2),0,0,0,0]]"
then show "dim_row (post_meas0 3 (alice \<phi>) 0) = dim_row v"
using mat_of_cols_list_def post_meas0_def assms(1) alice_state ket_vec_def by simp
show "dim_col (post_meas0 3 (alice \<phi>) 0) = dim_col v"
using mat_of_cols_list_def post_meas0_def assms(1) alice_state ket_vec_def asm by simp
show "\<And>i j. i<dim_row v \<Longrightarrow> j<dim_col v \<Longrightarrow> post_meas0 3 (alice \<phi>) 0 $$ (i,j) = v $$ (i,j)"
proof-
fix i j assume "i < dim_row v" and "j < dim_col v"
then have "i \<in> {0..<8} \<and> j = 0"
using asm set_8_atLeast0 mat_of_cols_list_def by auto
then show "post_meas0 3 (alice \<phi>) 0 $$ (i, j) = v $$ (i, j)"
using post_meas0_def assms asm mat_of_cols_list_def ket_vec_def
apply (auto simp add: prob_index_0_alice)
using assms(1) alice_result select_index_def by auto
qed
qed
lemma post_meas1_index_0_alice:
assumes "state 1 \<phi>" and "\<alpha> = \<phi> $$ (0,0)" and "\<beta> = \<phi> $$ (1,0)"
shows "post_meas1 3 (alice \<phi>) 0 = mat_of_cols_list 8 [[0,0,0,0,\<alpha>/sqrt(2),-\<beta>/sqrt(2),-\<beta>/sqrt(2),\<alpha>/sqrt(2)]]"
proof
define v where asm:"v = mat_of_cols_list 8 [[0,0,0,0,\<alpha>/sqrt(2),-\<beta>/sqrt(2),-\<beta>/sqrt(2),\<alpha>/sqrt(2)]]"
then show "dim_row (post_meas1 3 (alice \<phi>) 0) = dim_row v"
using mat_of_cols_list_def post_meas1_def assms(1) alice_state ket_vec_def by simp
show "dim_col (post_meas1 3 (alice \<phi>) 0) = dim_col v"
using mat_of_cols_list_def post_meas1_def assms(1) alice_state ket_vec_def asm by simp
show "\<And>i j. i<dim_row v \<Longrightarrow> j<dim_col v \<Longrightarrow> post_meas1 3 (alice \<phi>) 0 $$ (i,j) = v $$ (i,j)"
proof-
fix i j assume "i < dim_row v" and "j < dim_col v"
then have "i \<in> {0..<8} \<and> j = 0"
using asm set_8_atLeast0 mat_of_cols_list_def by auto
then show "post_meas1 3 (alice \<phi>) 0 $$ (i,j) = v $$ (i,j)"
using post_meas1_def assms asm mat_of_cols_list_def ket_vec_def
apply (auto simp add: prob_index_0_alice)
using assms(1) alice_result select_index_def by auto
qed
qed
lemma post_meas0_index_0_alice_state [simp]:
assumes "state 1 \<phi>"
shows "state 3 (post_meas0 3 (alice \<phi>) 0)"
using assms by (simp add: prob_index_0_alice)
lemma post_meas1_index_0_alice_state [simp]:
assumes "state 1 \<phi>"
shows "state 3 (post_meas1 3 (alice \<phi>) 0)"
using assms by (simp add: prob_index_0_alice)
lemma Alice_case [simp]:
assumes "state 1 \<phi>" and "state 3 q" and "List.member (alice_meas \<phi>) (p, q)"
shows "alice_pos \<phi> q"
proof-
define \<alpha> \<beta> where a0:"\<alpha> = \<phi> $$ (0,0)" and a1:"\<beta> = \<phi> $$ (1,0)"
have f0:"prob0 3 (Matrix.mat 8 (Suc 0) (\<lambda>(i,j). [[\<phi> $$ (0,0)/sqrt 2, \<phi> $$ (Suc 0,0)/sqrt 2,
\<phi> $$ (Suc 0,0)/sqrt 2, \<phi> $$ (0,0)/sqrt 2,0,0,0,0]]!j!i)) (Suc 0) = 1/2"
using post_meas0_index_0_alice prob0_def mat_of_cols_list_def post_meas0_index_0_alice_state
assms(1) a0 a1 select_index_3_subsets by (auto simp add: norm_divide power_divide phi_vec_length)
have f1:"prob1 3 (Matrix.mat 8 (Suc 0) (\<lambda>(i,j). [[\<phi> $$ (0,0)/sqrt 2, \<phi> $$ (Suc 0,0)/sqrt 2,
\<phi> $$ (Suc 0,0)/sqrt 2, \<phi> $$ (0,0)/sqrt 2, 0, 0, 0, 0]] ! j ! i)) (Suc 0) = 1/2"
using post_meas0_index_0_alice prob1_def mat_of_cols_list_def post_meas0_index_0_alice_state
assms(1) a0 a1 select_index_3_subsets by(auto simp add: norm_divide power_divide phi_vec_length algebra_simps)
have f2:"prob0 3 (Matrix.mat 8 (Suc 0)
(\<lambda>(i,j). [[0,0,0,0,\<phi> $$ (0,0)/complex_of_real (sqrt 2),-(\<phi> $$ (Suc 0,0)/complex_of_real (sqrt 2)),
-(\<phi> $$ (Suc 0,0)/complex_of_real (sqrt 2)),\<phi> $$ (0,0)/complex_of_real (sqrt 2)]] ! j ! i)) (Suc 0) = 1/2"
using post_meas1_index_0_alice prob0_def mat_of_cols_list_def post_meas1_index_0_alice_state
assms(1) a0 a1 select_index_3_subsets by(auto simp add: norm_divide power_divide phi_vec_length)
have f3:"prob1 3 (Matrix.mat 8 (Suc 0)
(\<lambda>(i,j). [[0,0,0,0,\<phi> $$ (0,0)/complex_of_real (sqrt 2),-(\<phi> $$ (Suc 0,0)/complex_of_real (sqrt 2)),
-(\<phi> $$ (Suc 0,0)/complex_of_real (sqrt 2)), \<phi> $$ (0,0)/complex_of_real (sqrt 2)]] ! j ! i)) (Suc 0) = 1/2"
using post_meas1_index_0_alice prob1_def mat_of_cols_list_def post_meas1_index_0_alice_state
assms(1) a0 a1 select_index_3_subsets by(auto simp add: norm_divide power_divide phi_vec_length algebra_simps)
have "(p, q) = ((prob0 3 (alice \<phi>) 0) * (prob0 3 (post_meas0 3 (alice \<phi>) 0) 1), post_meas0 3 (post_meas0 3 (alice \<phi>) 0) 1) \<or>
(p, q) = ((prob0 3 (alice \<phi>) 0) * (prob1 3 (post_meas0 3 (alice \<phi>) 0) 1), post_meas1 3 (post_meas0 3 (alice \<phi>) 0) 1) \<or>
(p, q) = ((prob1 3 (alice \<phi>) 0) * (prob0 3 (post_meas1 3 (alice \<phi>) 0) 1), post_meas0 3 (post_meas1 3 (alice \<phi>) 0) 1) \<or>
(p, q) = ((prob1 3 (alice \<phi>) 0) * (prob1 3 (post_meas1 3 (alice \<phi>) 0) 1), post_meas1 3 (post_meas1 3 (alice \<phi>) 0) 1)"
using assms(3) alice_meas_def List.member_def by(smt list.distinct(1) list.exhaust list.inject member_rec(1) member_rec(2))
then have "q = post_meas0 3 (post_meas0 3 (alice \<phi>) 0) 1 \<or> q = post_meas1 3 (post_meas0 3 (alice \<phi>) 0) 1 \<or>
q = post_meas0 3 (post_meas1 3 (alice \<phi>) 0) 1 \<or> q = post_meas1 3 (post_meas1 3 (alice \<phi>) 0) 1"
by auto
moreover have "post_meas0 3 (post_meas0 3 (alice \<phi>) 0) 1 = mat_of_cols_list 8 [[\<alpha>,\<beta>,0,0,0,0,0,0]]"
proof
define v where asm:"v = mat_of_cols_list 8 [[\<alpha>, \<beta>, 0, 0, 0, 0, 0, 0]]"
then show "dim_row (post_meas0 3 (post_meas0 3 (alice \<phi>) 0) 1) = dim_row v"
using mat_of_cols_list_def post_meas0_def ket_vec_def by simp
show "dim_col (post_meas0 3 (post_meas0 3 (alice \<phi>) 0) 1) = dim_col v"
using mat_of_cols_list_def post_meas0_def ket_vec_def asm by simp
show "\<And>i j. i<dim_row v \<Longrightarrow> j<dim_col v \<Longrightarrow> post_meas0 3 (post_meas0 3 (alice \<phi>) 0) 1 $$ (i,j) = v $$ (i,j)"
proof-
fix i j assume "i < dim_row v" and "j < dim_col v"
then have "i \<in> {0..<8} \<and> j = 0"
using asm mat_of_cols_list_def by auto
then show "post_meas0 3 (post_meas0 3 (alice \<phi>) 0) 1 $$ (i,j) = v $$ (i,j)"
using post_meas0_index_0_alice assms(1) a0 a1
apply (auto)
using post_meas0_def asm mat_of_cols_list_def ket_vec_def select_index_def
by (auto simp add: f0 real_sqrt_divide)
qed
qed
moreover have "post_meas1 3 (post_meas0 3 (alice \<phi>) 0) 1 = mat_of_cols_list 8 [[0,0,\<beta>,\<alpha>,0,0,0,0]]"
proof
define v where asm:"v = mat_of_cols_list 8 [[0,0,\<beta>,\<alpha>,0,0,0,0]]"
then show "dim_row (post_meas1 3 (post_meas0 3 (alice \<phi>) 0) 1) = dim_row v"
using mat_of_cols_list_def post_meas1_def ket_vec_def asm by auto
show "dim_col (post_meas1 3 (post_meas0 3 (alice \<phi>) 0) 1) = dim_col v"
using mat_of_cols_list_def post_meas1_def ket_vec_def asm by auto
show "\<And>i j. i<dim_row v \<Longrightarrow> j<dim_col v \<Longrightarrow> post_meas1 3 (post_meas0 3 (alice \<phi>) 0) 1 $$ (i,j) = v $$ (i,j)"
proof-
fix i j assume "i < dim_row v" and "j < dim_col v"
then have "i \<in> {0..<8} \<and> j = 0"
using asm mat_of_cols_list_def by auto
then show "post_meas1 3 (post_meas0 3 (alice \<phi>) 0) 1 $$ (i,j) = v $$ (i,j)"
using post_meas0_index_0_alice assms(1) a0 a1
apply (auto)
using post_meas1_def asm mat_of_cols_list_def ket_vec_def select_index_def
by (auto simp add: f1 real_sqrt_divide)
qed
qed
moreover have "post_meas0 3 (post_meas1 3 (alice \<phi>) 0) 1 = mat_of_cols_list 8 [[0,0,0,0,\<alpha>,-\<beta>,0,0]]"
proof
define v where asm:"v = mat_of_cols_list 8 [[0, 0, 0, 0, \<alpha>, -\<beta>, 0, 0]]"
then show "dim_row (post_meas0 3 (post_meas1 3 (alice \<phi>) 0) 1) = dim_row v"
using mat_of_cols_list_def post_meas0_def ket_vec_def by simp
show "dim_col (post_meas0 3 (post_meas1 3 (alice \<phi>) 0) 1) = dim_col v"
using mat_of_cols_list_def post_meas0_def ket_vec_def asm by simp
show "\<And>i j. i<dim_row v \<Longrightarrow> j<dim_col v \<Longrightarrow> post_meas0 3 (post_meas1 3 (alice \<phi>) 0) 1 $$ (i,j) = v $$ (i,j)"
proof-
fix i j assume "i < dim_row v" and "j < dim_col v"
then have "i \<in> {0..<8} \<and> j = 0"
using asm mat_of_cols_list_def by auto
then show "post_meas0 3 (post_meas1 3 (alice \<phi>) 0) 1 $$ (i,j) = v $$ (i,j)"
using post_meas1_index_0_alice assms(1) a0 a1
apply (auto)
using post_meas0_def asm mat_of_cols_list_def ket_vec_def select_index_def
by (auto simp add: f2 real_sqrt_divide)
qed
qed
moreover have "post_meas1 3 (post_meas1 3 (alice \<phi>) 0) 1 = mat_of_cols_list 8 [[0,0,0,0,0,0,-\<beta>,\<alpha>]]"
proof
define v where asm:"v = mat_of_cols_list 8 [[0,0,0,0,0,0,-\<beta>,\<alpha>]]"
then show "dim_row (post_meas1 3 (post_meas1 3 (alice \<phi>) 0) 1) = dim_row v"
using mat_of_cols_list_def post_meas1_def ket_vec_def by simp
show "dim_col (post_meas1 3 (post_meas1 3 (alice \<phi>) 0) 1) = dim_col v"
using mat_of_cols_list_def post_meas1_def ket_vec_def asm by simp
show "\<And>i j. i<dim_row v \<Longrightarrow> j<dim_col v \<Longrightarrow> post_meas1 3 (post_meas1 3 (alice \<phi>) 0) 1 $$ (i,j) = v $$ (i,j)"
proof-
fix i j assume "i < dim_row v" and "j < dim_col v"
then have "i \<in> {0..<8} \<and> j = 0"
using asm mat_of_cols_list_def by auto
then show "post_meas1 3 (post_meas1 3 (alice \<phi>) 0) 1 $$ (i,j) = v $$ (i,j)"
using post_meas1_index_0_alice assms(1) a0 a1
apply (auto)
using post_meas1_def asm mat_of_cols_list_def ket_vec_def select_index_def
by (auto simp add: f3 real_sqrt_divide)
qed
qed
ultimately show ?thesis using alice_pos_def a0 a1 by simp
qed
datatype bit = zero | one
definition alice_out:: "complex Matrix.mat => complex Matrix.mat => bit \<times> bit" where
"alice_out \<phi> q \<equiv>
if q = mat_of_cols_list 8 [[\<phi> $$ (0,0), \<phi> $$ (1,0), 0, 0, 0, 0, 0, 0]] then (zero, zero) else
if q = mat_of_cols_list 8 [[0, 0, \<phi> $$ (1,0), \<phi> $$ (0,0), 0, 0, 0, 0]] then (zero, one) else
if q = mat_of_cols_list 8 [[0, 0, 0, 0, \<phi> $$ (0,0), - \<phi> $$ (1,0), 0, 0]] then (one, zero) else
if q = mat_of_cols_list 8 [[0, 0, 0, 0, 0, 0, - \<phi> $$ (1,0), \<phi> $$ (0,0)]] then (one, one) else
undefined"
definition bob:: "complex Matrix.mat => bit \<times> bit \<Rightarrow> complex Matrix.mat" where
"bob q b \<equiv>
if (fst b, snd b) = (zero, zero) then q else
if (fst b, snd b) = (zero, one) then (Id 2 \<Otimes> X) * q else
if (fst b, snd b) = (one, zero) then (Id 2 \<Otimes> Z) * q else
if (fst b, snd b) = (one, one) then (Id 2 \<Otimes> Z * X) * q else
undefined"
lemma alice_out_unique [simp]:
assumes "state 1 \<phi>"
shows "Matrix.mat 8 (Suc 0) (\<lambda>(i,j). [[0, 0, \<phi> $$ (Suc 0, 0), \<phi> $$ (0, 0), 0, 0, 0, 0]]!j!i) \<noteq>
Matrix.mat 8 (Suc 0) (\<lambda>(i,j). [[\<phi> $$ (0, 0), \<phi> $$ (Suc 0, 0), 0, 0, 0, 0, 0, 0]]!j!i) \<and>
Matrix.mat 8 (Suc 0) (\<lambda>(i,j). [[0, 0, 0, 0, \<phi> $$ (0, 0), -\<phi> $$ (Suc 0, 0), 0, 0]]!j!i) \<noteq>
Matrix.mat 8 (Suc 0) (\<lambda>(i,j). [[\<phi> $$ (0, 0), \<phi> $$ (Suc 0, 0), 0, 0, 0, 0, 0, 0]]!j!i) \<and>
Matrix.mat 8 (Suc 0) (\<lambda>(i,j). [[0, 0, 0, 0, 0, 0, -\<phi> $$ (Suc 0, 0), \<phi> $$ (0, 0)]]!j!i) \<noteq>
Matrix.mat 8 (Suc 0) (\<lambda>(i,j). [[\<phi> $$ (0, 0), \<phi> $$ (Suc 0, 0), 0, 0, 0, 0, 0, 0]]!j!i) \<and>
Matrix.mat 8 (Suc 0) (\<lambda>(i,j). [[0, 0, 0, 0, \<phi> $$ (0, 0), -\<phi> $$ (Suc 0, 0), 0, 0]]!j!i) \<noteq>
Matrix.mat 8 (Suc 0) (\<lambda>(i,j). [[0, 0, \<phi> $$ (Suc 0, 0), \<phi> $$ (0, 0), 0, 0, 0, 0]]!j!i) \<and>
Matrix.mat 8 (Suc 0) (\<lambda>(i,j). [[0, 0, 0, 0, 0, 0, -\<phi> $$ (Suc 0, 0), \<phi> $$ (0, 0)]]!j!i) \<noteq>
Matrix.mat 8 (Suc 0) (\<lambda>(i,j). [[0, 0, \<phi> $$ (Suc 0, 0), \<phi> $$ (0, 0), 0, 0, 0, 0]]!j!i) \<and>
Matrix.mat 8 (Suc 0) (\<lambda>(i,j). [[0, 0, 0, 0, 0, 0, -\<phi> $$ (Suc 0, 0), \<phi> $$ (0, 0)]]!j!i) \<noteq>
Matrix.mat 8 (Suc 0) (\<lambda>(i,j). [[0, 0, 0, 0, \<phi> $$ (0, 0), -\<phi> $$ (Suc 0, 0), 0, 0]]!j!i)"
proof-
have f0:"\<phi> $$ (0,0) \<noteq> 0 \<or> \<phi> $$ (1,0) \<noteq> 0"
using assms state_def Matrix.col_def cpx_vec_length_def set_2 by(auto simp add: atLeast0LessThan)
define v1 v2 v3 v4 where d0:"v1 = Matrix.mat 8 1 (\<lambda>(i,j). [[\<phi> $$ (0,0),\<phi> $$ (1,0),0,0,0,0,0,0]]!j!i)"
and d1:"v2 = Matrix.mat 8 1 (\<lambda>(i,j). [[0,0,\<phi> $$ (1,0), \<phi> $$ (0,0),0,0,0,0]]!j!i)"
and d2:"v3 = Matrix.mat 8 1 (\<lambda>(i,j). [[0,0,0,0,\<phi> $$ (0,0),-\<phi> $$ (1,0),0,0]]!j!i)"
and d3:"v4 = Matrix.mat 8 1 (\<lambda>(i,j). [[0,0,0,0,0,0,-\<phi> $$ (1,0),\<phi> $$ (0,0)]]!j!i)"
then have "(v1 $$ (0,0) \<noteq> v2 $$ (0,0) \<or> v1 $$ (1,0) \<noteq> v2 $$ (1,0)) \<and>
(v1 $$ (0,0) \<noteq> v3 $$ (0,0) \<or> v1 $$ (1,0) \<noteq> v3 $$ (1,0)) \<and>
(v1 $$ (0,0) \<noteq> v4 $$ (0,0) \<or> v1 $$ (1,0) \<noteq> v4 $$ (1,0)) \<and>
(v2 $$ (2,0) \<noteq> v3 $$ (2,0) \<or> v2 $$ (3,0) \<noteq> v3 $$ (3,0)) \<and>
(v2 $$ (2,0) \<noteq> v4 $$ (2,0) \<or> v2 $$ (3,0) \<noteq> v4 $$ (3,0)) \<and>
(v3 $$ (4,0) \<noteq> v4 $$ (4,0) \<or> v3 $$ (5,0) \<noteq> v4 $$ (5,0))" using f0 by auto
then have "v1 \<noteq> v2 \<and> v1 \<noteq> v3 \<and> v1 \<noteq> v4 \<and> v2 \<noteq> v3 \<and> v2 \<noteq> v4 \<and> v3 \<noteq> v4" by auto
thus ?thesis by (auto simp add: d0 d1 d2 d3)
qed
abbreviation M3:: "complex Matrix.mat" where
"M3 \<equiv> mat_of_cols_list 8 [[0, 1, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 1, 0]]"
lemma tensor_prod_of_id_2_x:
shows "(Id 2 \<Otimes> X) = M3"
proof
have f0:"gate 3 (Id 2 \<Otimes> X)"
using X_is_gate tensor_gate[of "2" "Id 2" "1" "X"] by simp
then show "dim_row (Id 2 \<Otimes> X) = dim_row M3"
using gate_def by (simp add: mat_of_cols_list_def)
show "dim_col (Id 2 \<Otimes> X) = dim_col M3"
using f0 gate_def by (simp add: mat_of_cols_list_def)
show "\<And>i j. i < dim_row M3 \<Longrightarrow> j < dim_col M3 \<Longrightarrow> (Id 2 \<Otimes> X) $$ (i,j) = M3 $$ (i,j)"
proof-
fix i j assume "i < dim_row M3" and "j < dim_col M3"
then have "i \<in> {0..<8} \<and> j \<in> {0..<8}" by (auto simp add: mat_of_cols_list_def)
then show "(Id 2 \<Otimes> X) $$ (i,j) = M3 $$ (i,j)"
using Id_def X_def index_tensor_mat[of "Id 2" "4" "4" "X" "2" "2" "i" "j"] gate_def X_is_gate
id_is_gate Id_def by (auto simp add: mat_of_cols_list_def X_def)
qed
qed
abbreviation M4:: "complex Matrix.mat" where
"M4 \<equiv> mat_of_cols_list 8 [[0, -1, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, -1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, -1, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, -1],
[0, 0, 0, 0, 0, 0, 1, 0]]"
abbreviation ZX:: "complex Matrix.mat" where
"ZX \<equiv> mat_of_cols_list 2 [[0, -1], [1, 0]]"
lemma l_inv_of_ZX:
shows "ZX\<^sup>\<dagger> * ZX = 1\<^sub>m 2"
proof
show "dim_row (ZX\<^sup>\<dagger> * ZX) = dim_row (1\<^sub>m 2)" using dagger_def mat_of_cols_list_def by simp
show "dim_col (ZX\<^sup>\<dagger> * ZX) = dim_col (1\<^sub>m 2)" using dagger_def mat_of_cols_list_def by simp
show "\<And>i j. i < dim_row (1\<^sub>m 2) \<Longrightarrow> j < dim_col (1\<^sub>m 2) \<Longrightarrow> (ZX\<^sup>\<dagger> * ZX) $$ (i, j) = 1\<^sub>m 2 $$ (i, j)"
proof-
fix i j assume "i < dim_row (1\<^sub>m 2)" and "j < dim_col (1\<^sub>m 2)"
then have "i \<in> {0..<2} \<and> j \<in> {0..<2}" by auto
then show "(ZX\<^sup>\<dagger> * ZX) $$ (i, j) = 1\<^sub>m 2 $$ (i, j)"
using mat_of_cols_list_def dagger_def by (auto simp add: set_2)
qed
qed
lemma r_inv_of_ZX:
shows "ZX * (ZX\<^sup>\<dagger>) = 1\<^sub>m 2"
proof
show "dim_row (ZX * (ZX\<^sup>\<dagger>)) = dim_row (1\<^sub>m 2)" using dagger_def mat_of_cols_list_def by simp
show "dim_col (ZX * (ZX\<^sup>\<dagger>)) = dim_col (1\<^sub>m 2)" using dagger_def mat_of_cols_list_def by simp
show "\<And>i j. i < dim_row (1\<^sub>m 2) \<Longrightarrow> j < dim_col (1\<^sub>m 2) \<Longrightarrow> (ZX * (ZX\<^sup>\<dagger>)) $$ (i, j) = 1\<^sub>m 2 $$ (i, j)"
proof-
fix i j assume "i < dim_row (1\<^sub>m 2)" and "j < dim_col (1\<^sub>m 2)"
then have "i \<in> {0..<2} \<and> j \<in> {0..<2}" by auto
then show "(ZX * (ZX\<^sup>\<dagger>)) $$ (i, j) = 1\<^sub>m 2 $$ (i, j)"
using mat_of_cols_list_def dagger_def by (auto simp add: set_2)
qed
qed
lemma ZX_is_gate [simp]:
shows "gate 1 ZX"
proof
show "dim_row ZX = 2 ^ 1" using mat_of_cols_list_def by simp
show "square_mat ZX" using mat_of_cols_list_def by simp
show "unitary ZX" using unitary_def l_inv_of_ZX r_inv_of_ZX mat_of_cols_list_def by auto
qed
lemma prod_of_ZX:
shows "Z * X = ZX"
proof
show "dim_row (Z * X) = dim_row ZX"
using Z_is_gate mat_of_cols_list_def gate_def by auto
show "dim_col (Z * X) = dim_col ZX"
using X_is_gate mat_of_cols_list_def gate_def by auto
show "\<And>i j. i < dim_row ZX \<Longrightarrow> j < dim_col ZX \<Longrightarrow> (Z * X) $$ (i, j) = ZX $$ (i, j)"
proof-
fix i j assume "i < dim_row ZX" and "j < dim_col ZX"
then have "i \<in> {0..<2} \<and> j \<in> {0..<2}" by (auto simp add: mat_of_cols_list_def)
then show "(Z * X) $$ (i, j) = ZX $$ (i, j)" by (auto simp add: set_2 Z_def X_def)
qed
qed
lemma tensor_prod_of_id_2_y:
shows "(Id 2 \<Otimes> Z * X) = M4"
proof
have f0:"gate 3 (Id 2 \<Otimes> Z * X)"
using prod_of_ZX ZX_is_gate tensor_gate[of "2" "Id 2" "1" "Z * X"] by simp
then show "dim_row (Id 2 \<Otimes> Z * X) = dim_row M4"
using gate_def by (simp add: mat_of_cols_list_def)
show "dim_col (Id 2 \<Otimes> Z * X) = dim_col M4"
using f0 gate_def by (simp add: mat_of_cols_list_def)
show "\<And>i j. i < dim_row M4 \<Longrightarrow> j < dim_col M4 \<Longrightarrow> (Id 2 \<Otimes> Z * X) $$ (i,j) = M4 $$ (i,j)"
proof-
fix i j assume "i < dim_row M4" and "j < dim_col M4"
then have "i \<in> {0..<8} \<and> j \<in> {0..<8}" by (auto simp add: mat_of_cols_list_def)
then have "(Id 2 \<Otimes> ZX) $$ (i, j) = M4 $$ (i,j)"
using Id_def mat_of_cols_list_def index_tensor_mat[of "Id 2" "4" "4" "ZX" "2" "2" "i" "j"]
gate_def ZX_is_gate id_is_gate
by (auto simp add: mat_of_cols_list_def)
then show "(Id 2 \<Otimes> Z * X) $$ (i, j) = M4 $$ (i,j)"
using prod_of_ZX by simp
qed
qed
abbreviation M5:: "complex Matrix.mat" where
"M5 \<equiv> mat_of_cols_list 8 [[1, 0, 0, 0, 0, 0, 0, 0],
[0, -1, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, -1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, -1, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, -1]]"
lemma tensor_prod_of_id_2_z:
shows "(Id 2 \<Otimes> Z) = M5"
proof
have f0:"gate 3 (Id 2 \<Otimes> Z)"
using Z_is_gate tensor_gate[of "2" "Id 2" "1" "Z"] by simp
then show "dim_row (Id 2 \<Otimes> Z) = dim_row M5"
using gate_def by (simp add: mat_of_cols_list_def)
show "dim_col (Id 2 \<Otimes> Z) = dim_col M5"
using f0 gate_def by (simp add: mat_of_cols_list_def)
show "\<And>i j. i < dim_row M5 \<Longrightarrow> j < dim_col M5 \<Longrightarrow> (Id 2 \<Otimes> Z) $$ (i,j) = M5 $$ (i,j)"
proof-
fix i j assume "i < dim_row M5" and "j < dim_col M5"
then have "i \<in> {0..<8} \<and> j \<in> {0..<8}" by (auto simp add: mat_of_cols_list_def)
then show "(Id 2 \<Otimes> Z) $$ (i, j) = M5 $$ (i,j)"
using Id_def Z_def index_tensor_mat[of "Id 2" "4" "4" "Z" "2" "2" "i" "j"] gate_def Z_is_gate
id_is_gate Id_def by (auto simp add: mat_of_cols_list_def Z_def)
qed
qed
lemma teleportation:
assumes "state 1 \<phi>" and "state 3 q" and "List.member (alice_meas \<phi>) (p, q)"
shows "\<exists>r. state 2 r \<and> bob q (alice_out \<phi> q) = r \<Otimes> \<phi>"
proof-
define \<alpha> \<beta> where a0:"\<alpha> = \<phi> $$ (0,0)" and a1:"\<beta> = \<phi> $$ (1,0)"
then have "q = mat_of_cols_list 8 [[\<alpha>, \<beta>, 0, 0, 0, 0, 0, 0]] \<or>
q = mat_of_cols_list 8 [[0, 0, \<beta>, \<alpha>, 0, 0, 0, 0]] \<or>
q = mat_of_cols_list 8 [[0, 0, 0, 0, \<alpha>, -\<beta>, 0, 0]] \<or>
q = mat_of_cols_list 8 [[0, 0, 0, 0, 0, 0, -\<beta>, \<alpha>]]"
using assms Alice_case alice_pos_def by simp
moreover have "q = mat_of_cols_list 8 [[\<alpha>,\<beta>,0,0,0,0,0,0]] \<Longrightarrow> bob q (alice_out \<phi> q) =
mat_of_cols_list 4 [[1, 0, 0, 0]] \<Otimes> \<phi>"
proof
assume asm:"q = Tensor.mat_of_cols_list 8 [[\<alpha>, \<beta>, 0, 0, 0, 0, 0, 0]]"
show "dim_row (bob q (alice_out \<phi> q)) = dim_row (Tensor.mat_of_cols_list 4 [[1,0,0,0]] \<Otimes> \<phi>)"
using mat_of_cols_list_def a0 a1 assms(1) state_def bob_def alice_out_def asm by simp
show "dim_col (bob q (alice_out \<phi> q)) = dim_col (Tensor.mat_of_cols_list 4 [[1,0,0,0]] \<Otimes> \<phi>)"
using mat_of_cols_list_def a0 a1 assms(1) state_def bob_def alice_out_def asm by simp
show "\<And>i j. i < dim_row (Tensor.mat_of_cols_list 4 [[1,0,0,0]] \<Otimes> \<phi>) \<Longrightarrow>
j < dim_col (Tensor.mat_of_cols_list 4 [[1,0,0,0]] \<Otimes> \<phi>) \<Longrightarrow>
bob q (alice_out \<phi> q) $$ (i, j) = (Tensor.mat_of_cols_list 4 [[1,0,0,0]] \<Otimes> \<phi>) $$ (i,j)"
proof-
fix i j assume "i < dim_row (Tensor.mat_of_cols_list 4 [[1,0,0,0]] \<Otimes> \<phi>)" and
"j < dim_col (Tensor.mat_of_cols_list 4 [[1,0,0,0]] \<Otimes> \<phi>)"
then have "i \<in> {0..<8} \<and> j = 0"
using asm mat_of_cols_list_def assms state_def by auto
then show "bob q (alice_out \<phi> q) $$ (i,j) = (Tensor.mat_of_cols_list 4 [[1,0,0,0]] \<Otimes> \<phi>) $$ (i,j)"
using bob_def alice_out_def asm mat_of_cols_list_def a0 a1 assms state_def by auto
qed
qed
moreover have "q = mat_of_cols_list 8 [[0,0,\<beta>,\<alpha>,0,0,0,0]] \<Longrightarrow> bob q (alice_out \<phi> q) =
mat_of_cols_list 4 [[0,1,0,0]] \<Otimes> \<phi>"
proof
assume asm:"q = Tensor.mat_of_cols_list 8 [[0,0,\<beta>,\<alpha>,0,0,0,0]]"
show "dim_row (bob q (alice_out \<phi> q)) = dim_row (Tensor.mat_of_cols_list 4 [[0,1,0,0]] \<Otimes> \<phi>)"
using mat_of_cols_list_def a0 a1 assms(1) state_def bob_def alice_out_def asm tensor_prod_of_id_2_x by simp
show "dim_col (bob q (alice_out \<phi> q)) = dim_col (Tensor.mat_of_cols_list 4 [[0,1,0,0]] \<Otimes> \<phi>)"
using mat_of_cols_list_def a0 a1 assms(1) state_def bob_def alice_out_def asm by simp
show "\<And>i j. i < dim_row (Tensor.mat_of_cols_list 4 [[0,1,0,0]] \<Otimes> \<phi>) \<Longrightarrow>
j < dim_col (Tensor.mat_of_cols_list 4 [[0,1,0,0]] \<Otimes> \<phi>) \<Longrightarrow>
bob q (alice_out \<phi> q) $$ (i,j) = (Tensor.mat_of_cols_list 4 [[0,1,0,0]] \<Otimes> \<phi>) $$ (i,j)"
proof-
fix i j assume "i < dim_row (Tensor.mat_of_cols_list 4 [[0,1,0,0]] \<Otimes> \<phi>)" and
"j < dim_col (Tensor.mat_of_cols_list 4 [[0,1,0,0]] \<Otimes> \<phi>)"
then have c1:"i \<in> {0..<8} \<and> j = 0"
using asm mat_of_cols_list_def assms(1) state_def by auto
then have "(M3 * (Matrix.mat 8 1 (\<lambda>(i,j). [[0,0,\<phi> $$ (1,0),\<phi> $$ (0,0),0,0,0,0]]!j!i))) $$ (i,j) =
(Tensor.mat_of_cols_list 4 [[0,1,0,0]] \<Otimes> \<phi>) $$ (i,j)"
using state_def assms(1) by(auto simp add: a0 a1 mat_of_cols_list_def times_mat_def scalar_prod_def)
then show "bob q (alice_out \<phi> q) $$ (i,j) = (Tensor.mat_of_cols_list 4 [[0,1,0,0]] \<Otimes> \<phi>) $$ (i,j)"
using bob_def alice_out_def asm c1 a0 a1 mat_of_cols_list_def tensor_prod_of_id_2_x assms(1) by simp
qed
qed
moreover have "q = mat_of_cols_list 8 [[0,0,0,0,\<alpha>,-\<beta>,0,0]] \<Longrightarrow> bob q (alice_out \<phi> q) =
mat_of_cols_list 4 [[0,0,1,0]] \<Otimes> \<phi>"
proof
assume asm:"q = Tensor.mat_of_cols_list 8 [[0,0,0,0,\<alpha>,-\<beta>,0,0]]"
show "dim_row (bob q (alice_out \<phi> q)) = dim_row (Tensor.mat_of_cols_list 4 [[0,0,1,0]] \<Otimes> \<phi>)"
using mat_of_cols_list_def a0 a1 assms(1) state_def bob_def alice_out_def asm tensor_prod_of_id_2_z by simp
show "dim_col (bob q (alice_out \<phi> q)) = dim_col (Tensor.mat_of_cols_list 4 [[0,0,1,0]] \<Otimes> \<phi>)"
using mat_of_cols_list_def a0 a1 assms(1) state_def bob_def alice_out_def asm by simp
show "\<And>i j. i < dim_row (Tensor.mat_of_cols_list 4 [[0,0,1,0]] \<Otimes> \<phi>) \<Longrightarrow>
j < dim_col (Tensor.mat_of_cols_list 4 [[0,0,1,0]] \<Otimes> \<phi>) \<Longrightarrow>
bob q (alice_out \<phi> q) $$ (i,j) = (Tensor.mat_of_cols_list 4 [[0,0,1,0]] \<Otimes> \<phi>) $$ (i,j)"
proof-
fix i j assume "i < dim_row (Tensor.mat_of_cols_list 4 [[0,0,1,0]] \<Otimes> \<phi>)" and
"j < dim_col (Tensor.mat_of_cols_list 4 [[0,0,1,0]] \<Otimes> \<phi>)"
then have c1:"i \<in> {0..<8} \<and> j = 0"
using asm mat_of_cols_list_def assms state_def by auto
then have "(M5 * (Matrix.mat 8 (Suc 0) (\<lambda>(i,j). [[0,0,0,0,\<phi> $$ (0,0),-\<phi> $$ (Suc 0,0),0,0]]!j!i))) $$ (i,j) =
(Tensor.mat_of_cols_list 4 [[0,0,1,0]] \<Otimes> \<phi>) $$ (i,j)"
using state_def assms(1) by(auto simp add: a0 a1 mat_of_cols_list_def times_mat_def scalar_prod_def)
then show "bob q (alice_out \<phi> q) $$ (i,j) = (Tensor.mat_of_cols_list 4 [[0,0,1,0]] \<Otimes> \<phi>) $$ (i,j)"
using bob_def alice_out_def asm c1 a0 a1 mat_of_cols_list_def tensor_prod_of_id_2_z assms(1) by simp
qed
qed
moreover have "q = mat_of_cols_list 8 [[0, 0, 0, 0, 0, 0, -\<beta>, \<alpha>]] \<Longrightarrow> bob q (alice_out \<phi> q) =
mat_of_cols_list 4 [[0, 0, 0, 1]] \<Otimes> \<phi>"
proof
assume asm:"q = Tensor.mat_of_cols_list 8 [[0, 0, 0, 0, 0, 0, -\<beta>, \<alpha>]]"
show "dim_row (bob q (alice_out \<phi> q)) = dim_row (Tensor.mat_of_cols_list 4 [[0,0,0,1]] \<Otimes> \<phi>)"
using mat_of_cols_list_def a0 a1 assms(1) state_def bob_def alice_out_def asm tensor_prod_of_id_2_y by simp
show "dim_col (bob q (alice_out \<phi> q)) = dim_col (Tensor.mat_of_cols_list 4 [[0,0,0,1]] \<Otimes> \<phi>)"
using mat_of_cols_list_def a0 a1 assms(1) state_def bob_def alice_out_def asm by simp
show "\<And>i j. i < dim_row (Tensor.mat_of_cols_list 4 [[0,0,0,1]] \<Otimes> \<phi>) \<Longrightarrow>
j < dim_col (Tensor.mat_of_cols_list 4 [[0,0,0,1]] \<Otimes> \<phi>) \<Longrightarrow>
bob q (alice_out \<phi> q) $$ (i,j) = (Tensor.mat_of_cols_list 4 [[0,0,0,1]] \<Otimes> \<phi>) $$ (i,j)"
proof-
fix i j assume "i < dim_row (Tensor.mat_of_cols_list 4 [[0,0,0,1]] \<Otimes> \<phi>)" and
"j < dim_col (Tensor.mat_of_cols_list 4 [[0,0,0,1]] \<Otimes> \<phi>)"
then have c1:"i \<in> {0..<8} \<and> j = 0"
using asm mat_of_cols_list_def assms state_def by auto
then have "(M4 * (Matrix.mat 8 (Suc 0) (\<lambda>(i, j). [[0,0,0,0,0,0,-\<phi> $$ (Suc 0,0),\<phi> $$ (0,0)]]!j!i))) $$ (i,j) =
(Tensor.mat_of_cols_list 4 [[0,0,0,1]] \<Otimes> \<phi>) $$ (i,j)"
using state_def assms(1) by(auto simp add: a0 a1 mat_of_cols_list_def times_mat_def scalar_prod_def)
then show "bob q (alice_out \<phi> q) $$ (i,j) = (Tensor.mat_of_cols_list 4 [[0,0,0,1]] \<Otimes> \<phi>) $$ (i,j)"
using bob_def alice_out_def asm c1 a0 a1 mat_of_cols_list_def tensor_prod_of_id_2_y assms(1) by simp
qed
qed
moreover have "state 2 (mat_of_cols_list 4 [[1, 0, 0, 0]])"
using state_def mat_of_cols_list_def cpx_vec_length_def lessThan_atLeast0 by simp
moreover have "state 2 (mat_of_cols_list 4 [[0, 1, 0, 0]])"
using state_def mat_of_cols_list_def cpx_vec_length_def lessThan_atLeast0 by simp
moreover have "state 2 (mat_of_cols_list 4 [[0, 0, 1, 0]])"
using state_def mat_of_cols_list_def cpx_vec_length_def lessThan_atLeast0 by simp
moreover have "state 2 (mat_of_cols_list 4 [[0, 0, 0, 1]])"
using state_def mat_of_cols_list_def cpx_vec_length_def lessThan_atLeast0 by simp
ultimately show ?thesis by auto
qed
(*
Biblio:
@inproceedings{Boender2015FormalizationOQ,
title={Formalization of Quantum Protocols using Coq},
author={Jaap Boender and Florian Kamm{\"u}ller and Rajagopal Nagarajan},
booktitle={QPL},
year={2015}
}
*)
end
|
{-
This second-order term syntax was created from the following second-order syntax description:
syntax Prod | P
type
_⊗_ : 2-ary | l40
term
pair : α β -> α ⊗ β | ⟨_,_⟩
fst : α ⊗ β -> α
snd : α ⊗ β -> β
theory
(fβ) a : α b : β |> fst (pair(a, b)) = a
(sβ) a : α b : β |> snd (pair(a, b)) = b
(pη) p : α ⊗ β |> pair (fst(p), snd(p)) = p
-}
module Prod.Syntax where
open import SOAS.Common
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Families.Core
open import SOAS.Construction.Structure
open import SOAS.ContextMaps.Inductive
open import SOAS.Metatheory.Syntax
open import Prod.Signature
private
variable
Γ Δ Π : Ctx
α β : PT
𝔛 : Familyₛ
-- Inductive term declaration
module P:Terms (𝔛 : Familyₛ) where
data P : Familyₛ where
var : ℐ ⇾̣ P
mvar : 𝔛 α Π → Sub P Π Γ → P α Γ
⟨_,_⟩ : P α Γ → P β Γ → P (α ⊗ β) Γ
fst : P (α ⊗ β) Γ → P α Γ
snd : P (α ⊗ β) Γ → P β Γ
open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛
Pᵃ : MetaAlg P
Pᵃ = record
{ 𝑎𝑙𝑔 = λ where
(pairₒ ⋮ a , b) → ⟨_,_⟩ a b
(fstₒ ⋮ a) → fst a
(sndₒ ⋮ a) → snd a
; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) }
module Pᵃ = MetaAlg Pᵃ
module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where
open MetaAlg 𝒜ᵃ
𝕤𝕖𝕞 : P ⇾̣ 𝒜
𝕊 : Sub P Π Γ → Π ~[ 𝒜 ]↝ Γ
𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t
𝕊 (t ◂ σ) (old v) = 𝕊 σ v
𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε)
𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v
𝕤𝕖𝕞 (⟨_,_⟩ a b) = 𝑎𝑙𝑔 (pairₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)
𝕤𝕖𝕞 (fst a) = 𝑎𝑙𝑔 (fstₒ ⋮ 𝕤𝕖𝕞 a)
𝕤𝕖𝕞 (snd a) = 𝑎𝑙𝑔 (sndₒ ⋮ 𝕤𝕖𝕞 a)
𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ Pᵃ 𝒜ᵃ 𝕤𝕖𝕞
𝕤𝕖𝕞ᵃ⇒ = record
{ ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t }
; ⟨𝑣𝑎𝑟⟩ = refl
; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } }
where
open ≡-Reasoning
⟨𝑎𝑙𝑔⟩ : (t : ⅀ P α Γ) → 𝕤𝕖𝕞 (Pᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t)
⟨𝑎𝑙𝑔⟩ (pairₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (fstₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (sndₒ ⋮ _) = refl
𝕊-tab : (mε : Π ~[ P ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v)
𝕊-tab mε new = refl
𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v
module _ (g : P ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ Pᵃ 𝒜ᵃ g) where
open MetaAlg⇒ gᵃ⇒
𝕤𝕖𝕞! : (t : P α Γ) → 𝕤𝕖𝕞 t ≡ g t
𝕊-ix : (mε : Sub P Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v)
𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x
𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v
𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε))
= trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε))
𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩
𝕤𝕖𝕞! (⟨_,_⟩ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (fst a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (snd a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩
-- Syntax instance for the signature
P:Syn : Syntax
P:Syn = record
{ ⅀F = ⅀F
; ⅀:CS = ⅀:CompatStr
; mvarᵢ = P:Terms.mvar
; 𝕋:Init = λ 𝔛 → let open P:Terms 𝔛 in record
{ ⊥ = P ⋉ Pᵃ
; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }
; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } }
-- Instantiation of the syntax and metatheory
open Syntax P:Syn public
open P:Terms public
open import SOAS.Families.Build public
open import SOAS.Syntax.Shorthands Pᵃ public
open import SOAS.Metatheory P:Syn public
|
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
! This file was ported from Lean 3 source module linear_algebra.adic_completion
! leanprover-community/mathlib commit 2bbc7e3884ba234309d2a43b19144105a753292e
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathbin.Algebra.GeomSum
import Mathbin.LinearAlgebra.Smodeq
import Mathbin.RingTheory.JacobsonIdeal
/-!
# Completion of a module with respect to an ideal.
In this file we define the notions of Hausdorff, precomplete, and complete for an `R`-module `M`
with respect to an ideal `I`:
## Main definitions
- `is_Hausdorff I M`: this says that the intersection of `I^n M` is `0`.
- `is_precomplete I M`: this says that every Cauchy sequence converges.
- `is_adic_complete I M`: this says that `M` is Hausdorff and precomplete.
- `Hausdorffification I M`: this is the universal Hausdorff module with a map from `M`.
- `completion I M`: if `I` is finitely generated, then this is the universal complete module (TODO)
with a map from `M`. This map is injective iff `M` is Hausdorff and surjective iff `M` is
precomplete.
-/
open Submodule
variable {R : Type _} [CommRing R] (I : Ideal R)
variable (M : Type _) [AddCommGroup M] [Module R M]
variable {N : Type _} [AddCommGroup N] [Module R N]
/-- A module `M` is Hausdorff with respect to an ideal `I` if `⋂ I^n M = 0`. -/
class IsHausdorff : Prop where
haus' : ∀ x : M, (∀ n : ℕ, x ≡ 0 [SMOD (I ^ n • ⊤ : Submodule R M)]) → x = 0
#align is_Hausdorff IsHausdorff
/-- A module `M` is precomplete with respect to an ideal `I` if every Cauchy sequence converges. -/
class IsPrecomplete : Prop where
prec' :
∀ f : ℕ → M,
(∀ {m n}, m ≤ n → f m ≡ f n [SMOD (I ^ m • ⊤ : Submodule R M)]) →
∃ L : M, ∀ n, f n ≡ L [SMOD (I ^ n • ⊤ : Submodule R M)]
#align is_precomplete IsPrecomplete
/-- A module `M` is `I`-adically complete if it is Hausdorff and precomplete. -/
class IsAdicComplete extends IsHausdorff I M, IsPrecomplete I M : Prop
#align is_adic_complete IsAdicComplete
variable {I M}
theorem IsHausdorff.haus (h : IsHausdorff I M) :
∀ x : M, (∀ n : ℕ, x ≡ 0 [SMOD (I ^ n • ⊤ : Submodule R M)]) → x = 0 :=
IsHausdorff.haus'
#align is_Hausdorff.haus IsHausdorff.haus
theorem isHausdorff_iff :
IsHausdorff I M ↔ ∀ x : M, (∀ n : ℕ, x ≡ 0 [SMOD (I ^ n • ⊤ : Submodule R M)]) → x = 0 :=
⟨IsHausdorff.haus, fun h => ⟨h⟩⟩
#align is_Hausdorff_iff isHausdorff_iff
theorem IsPrecomplete.prec (h : IsPrecomplete I M) {f : ℕ → M} :
(∀ {m n}, m ≤ n → f m ≡ f n [SMOD (I ^ m • ⊤ : Submodule R M)]) →
∃ L : M, ∀ n, f n ≡ L [SMOD (I ^ n • ⊤ : Submodule R M)] :=
IsPrecomplete.prec' _
#align is_precomplete.prec IsPrecomplete.prec
theorem isPrecomplete_iff :
IsPrecomplete I M ↔
∀ f : ℕ → M,
(∀ {m n}, m ≤ n → f m ≡ f n [SMOD (I ^ m • ⊤ : Submodule R M)]) →
∃ L : M, ∀ n, f n ≡ L [SMOD (I ^ n • ⊤ : Submodule R M)] :=
⟨fun h => h.1, fun h => ⟨h⟩⟩
#align is_precomplete_iff isPrecomplete_iff
variable (I M)
/-- The Hausdorffification of a module with respect to an ideal. -/
@[reducible]
def Hausdorffification : Type _ :=
M ⧸ (⨅ n : ℕ, I ^ n • ⊤ : Submodule R M)
#align Hausdorffification Hausdorffification
/-- The completion of a module with respect to an ideal. This is not necessarily Hausdorff.
In fact, this is only complete if the ideal is finitely generated. -/
def adicCompletion : Submodule R (∀ n : ℕ, M ⧸ (I ^ n • ⊤ : Submodule R M))
where
carrier :=
{ f |
∀ {m n} (h : m ≤ n),
liftQ _ (mkQ _)
(by
rw [ker_mkq]
exact smul_mono (Ideal.pow_le_pow h) le_rfl)
(f n) =
f m }
zero_mem' m n hmn := by rw [Pi.zero_apply, Pi.zero_apply, LinearMap.map_zero]
add_mem' f g hf hg m n hmn := by
rw [Pi.add_apply, Pi.add_apply, LinearMap.map_add, hf hmn, hg hmn]
smul_mem' c f hf m n hmn := by rw [Pi.smul_apply, Pi.smul_apply, LinearMap.map_smul, hf hmn]
#align adic_completion adicCompletion
namespace IsHausdorff
instance bot : IsHausdorff (⊥ : Ideal R) M :=
⟨fun x hx => by simpa only [pow_one ⊥, bot_smul, SModEq.bot] using hx 1⟩
#align is_Hausdorff.bot IsHausdorff.bot
variable {M}
protected theorem subsingleton (h : IsHausdorff (⊤ : Ideal R) M) : Subsingleton M :=
⟨fun x y =>
eq_of_sub_eq_zero <|
h.haus (x - y) fun n => by
rw [Ideal.top_pow, top_smul]
exact SModEq.top⟩
#align is_Hausdorff.subsingleton IsHausdorff.subsingleton
variable (M)
instance (priority := 100) of_subsingleton [Subsingleton M] : IsHausdorff I M :=
⟨fun x _ => Subsingleton.elim _ _⟩
#align is_Hausdorff.of_subsingleton IsHausdorff.of_subsingleton
variable {I M}
theorem infᵢ_pow_smul (h : IsHausdorff I M) : (⨅ n : ℕ, I ^ n • ⊤ : Submodule R M) = ⊥ :=
eq_bot_iff.2 fun x hx =>
(mem_bot _).2 <| h.haus x fun n => SModEq.zero.2 <| (mem_infᵢ fun n : ℕ => I ^ n • ⊤).1 hx n
#align is_Hausdorff.infi_pow_smul IsHausdorff.infᵢ_pow_smul
end IsHausdorff
namespace Hausdorffification
/-- The canonical linear map to the Hausdorffification. -/
def of : M →ₗ[R] Hausdorffification I M :=
mkQ _
#align Hausdorffification.of Hausdorffification.of
variable {I M}
@[elab_as_elim]
theorem induction_on {C : Hausdorffification I M → Prop} (x : Hausdorffification I M)
(ih : ∀ x, C (of I M x)) : C x :=
Quotient.inductionOn' x ih
#align Hausdorffification.induction_on Hausdorffification.induction_on
variable (I M)
instance : IsHausdorff I (Hausdorffification I M) :=
⟨fun x =>
Quotient.inductionOn' x fun x hx =>
(Quotient.mk_eq_zero _).2 <|
(mem_infᵢ _).2 fun n =>
by
have := comap_map_mkq (⨅ n : ℕ, I ^ n • ⊤ : Submodule R M) (I ^ n • ⊤)
simp only [sup_of_le_right (infᵢ_le (fun n => (I ^ n • ⊤ : Submodule R M)) n)] at this
rw [← this, map_smul'', mem_comap, Submodule.map_top, range_mkq, ← SModEq.zero];
exact hx n⟩
variable {M} [h : IsHausdorff I N]
include h
/-- universal property of Hausdorffification: any linear map to a Hausdorff module extends to a
unique map from the Hausdorffification. -/
def lift (f : M →ₗ[R] N) : Hausdorffification I M →ₗ[R] N :=
liftQ _ f <|
map_le_iff_le_comap.1 <|
h.infᵢ_pow_smul ▸
le_infᵢ fun n =>
le_trans (map_mono <| infᵢ_le _ n) <|
by
rw [map_smul'']
exact smul_mono le_rfl le_top
#align Hausdorffification.lift Hausdorffification.lift
theorem lift_of (f : M →ₗ[R] N) (x : M) : lift I f (of I M x) = f x :=
rfl
#align Hausdorffification.lift_of Hausdorffification.lift_of
theorem lift_comp_of (f : M →ₗ[R] N) : (lift I f).comp (of I M) = f :=
LinearMap.ext fun _ => rfl
#align Hausdorffification.lift_comp_of Hausdorffification.lift_comp_of
/-- Uniqueness of lift. -/
theorem lift_eq (f : M →ₗ[R] N) (g : Hausdorffification I M →ₗ[R] N) (hg : g.comp (of I M) = f) :
g = lift I f :=
LinearMap.ext fun x => induction_on x fun x => by rw [lift_of, ← hg, LinearMap.comp_apply]
#align Hausdorffification.lift_eq Hausdorffification.lift_eq
end Hausdorffification
namespace IsPrecomplete
instance bot : IsPrecomplete (⊥ : Ideal R) M :=
by
refine' ⟨fun f hf => ⟨f 1, fun n => _⟩⟩; cases n
· rw [pow_zero, Ideal.one_eq_top, top_smul]
exact SModEq.top
specialize hf (Nat.le_add_left 1 n)
rw [pow_one, bot_smul, SModEq.bot] at hf; rw [hf]
#align is_precomplete.bot IsPrecomplete.bot
instance top : IsPrecomplete (⊤ : Ideal R) M :=
⟨fun f hf =>
⟨0, fun n => by
rw [Ideal.top_pow, top_smul]
exact SModEq.top⟩⟩
#align is_precomplete.top IsPrecomplete.top
instance (priority := 100) of_subsingleton [Subsingleton M] : IsPrecomplete I M :=
⟨fun f hf => ⟨0, fun n => by rw [Subsingleton.elim (f n) 0]⟩⟩
#align is_precomplete.of_subsingleton IsPrecomplete.of_subsingleton
end IsPrecomplete
namespace adicCompletion
/-- The canonical linear map to the completion. -/
def of : M →ₗ[R] adicCompletion I M
where
toFun x := ⟨fun n => mkQ _ x, fun m n hmn => rfl⟩
map_add' x y := rfl
map_smul' c x := rfl
#align adic_completion.of adicCompletion.of
@[simp]
theorem of_apply (x : M) (n : ℕ) : (of I M x).1 n = mkQ _ x :=
rfl
#align adic_completion.of_apply adicCompletion.of_apply
/-- Linearly evaluating a sequence in the completion at a given input. -/
def eval (n : ℕ) : adicCompletion I M →ₗ[R] M ⧸ (I ^ n • ⊤ : Submodule R M)
where
toFun f := f.1 n
map_add' f g := rfl
map_smul' c f := rfl
#align adic_completion.eval adicCompletion.eval
@[simp]
theorem coe_eval (n : ℕ) :
(eval I M n : adicCompletion I M → M ⧸ (I ^ n • ⊤ : Submodule R M)) = fun f => f.1 n :=
rfl
#align adic_completion.coe_eval adicCompletion.coe_eval
theorem eval_apply (n : ℕ) (f : adicCompletion I M) : eval I M n f = f.1 n :=
rfl
#align adic_completion.eval_apply adicCompletion.eval_apply
theorem eval_of (n : ℕ) (x : M) : eval I M n (of I M x) = mkQ _ x :=
rfl
#align adic_completion.eval_of adicCompletion.eval_of
@[simp]
theorem eval_comp_of (n : ℕ) : (eval I M n).comp (of I M) = mkQ _ :=
rfl
#align adic_completion.eval_comp_of adicCompletion.eval_comp_of
@[simp]
theorem range_eval (n : ℕ) : (eval I M n).range = ⊤ :=
LinearMap.range_eq_top.2 fun x => Quotient.inductionOn' x fun x => ⟨of I M x, rfl⟩
#align adic_completion.range_eval adicCompletion.range_eval
variable {I M}
@[ext]
theorem ext {x y : adicCompletion I M} (h : ∀ n, eval I M n x = eval I M n y) : x = y :=
Subtype.eq <| funext h
#align adic_completion.ext adicCompletion.ext
variable (I M)
instance : IsHausdorff I (adicCompletion I M) :=
⟨fun x hx =>
ext fun n =>
smul_induction_on (SModEq.zero.1 <| hx n)
(fun r hr x _ =>
((eval I M n).map_smul r x).symm ▸
Quotient.inductionOn' (eval I M n x) fun x => SModEq.zero.2 <| smul_mem_smul hr mem_top)
fun _ _ ih1 ih2 => by rw [LinearMap.map_add, ih1, ih2, LinearMap.map_zero, add_zero]⟩
end adicCompletion
namespace IsAdicComplete
instance bot : IsAdicComplete (⊥ : Ideal R) M where
#align is_adic_complete.bot IsAdicComplete.bot
protected theorem subsingleton (h : IsAdicComplete (⊤ : Ideal R) M) : Subsingleton M :=
h.1.Subsingleton
#align is_adic_complete.subsingleton IsAdicComplete.subsingleton
instance (priority := 100) of_subsingleton [Subsingleton M] : IsAdicComplete I M where
#align is_adic_complete.of_subsingleton IsAdicComplete.of_subsingleton
open BigOperators
open Finset
theorem le_jacobson_bot [IsAdicComplete I R] : I ≤ (⊥ : Ideal R).jacobson :=
by
intro x hx
rw [← Ideal.neg_mem_iff, Ideal.mem_jacobson_bot]
intro y
rw [add_comm]
let f : ℕ → R := fun n => ∑ i in range n, (x * y) ^ i
have hf : ∀ m n, m ≤ n → f m ≡ f n [SMOD I ^ m • (⊤ : Submodule R R)] :=
by
intro m n h
simp only [f, Algebra.id.smul_eq_mul, Ideal.mul_top, SModEq.sub_mem]
rw [← add_tsub_cancel_of_le h, Finset.sum_range_add, ← sub_sub, sub_self, zero_sub, neg_mem_iff]
apply Submodule.sum_mem
intro n hn
rw [mul_pow, pow_add, mul_assoc]
exact Ideal.mul_mem_right _ (I ^ m) (Ideal.pow_mem_pow hx m)
obtain ⟨L, hL⟩ := IsPrecomplete.prec to_is_precomplete hf
· rw [isUnit_iff_exists_inv]
use L
rw [← sub_eq_zero, neg_mul]
apply IsHausdorff.haus (to_is_Hausdorff : IsHausdorff I R)
intro n
specialize hL n
rw [SModEq.sub_mem, Algebra.id.smul_eq_mul, Ideal.mul_top] at hL⊢
rw [sub_zero]
suffices (1 - x * y) * f n - 1 ∈ I ^ n
by
convert Ideal.sub_mem _ this (Ideal.mul_mem_left _ (1 + -(x * y)) hL) using 1
ring
cases n
· simp only [Ideal.one_eq_top, pow_zero]
· dsimp [f]
rw [← neg_sub _ (1 : R), neg_mul, mul_geom_sum, neg_sub, sub_sub, add_comm, ← sub_sub,
sub_self, zero_sub, neg_mem_iff, mul_pow]
exact Ideal.mul_mem_right _ (I ^ _) (Ideal.pow_mem_pow hx _)
#align is_adic_complete.le_jacobson_bot IsAdicComplete.le_jacobson_bot
end IsAdicComplete
|
------------------------------------------------------------------------
-- Higher lenses with erased proofs
------------------------------------------------------------------------
-- At the time of writing there are counterparts in this file of more
-- or less everything in Lens.Non-dependent.Higher, except for parts
-- of the section called "A category". There is also a counterpart to
-- one of the properties related to higher lenses from
-- Lens.Non-dependent.Equivalent-preimages
-- (higher-lens-preserves-h-level-of-domain).
{-# OPTIONS --cubical --safe #-}
import Equality.Path as P
module Lens.Non-dependent.Higher.Erased
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
import Bi-invertibility.Erased
open import Logical-equivalence using (_⇔_)
open import Prelude as P hiding (id; [_,_]) renaming (_∘_ to _⊚_)
open import Bijection equality-with-J as Bijection using (_↔_)
open import Circle eq using (𝕊¹)
open import Equality.Decidable-UIP equality-with-J
open import Equality.Decision-procedures equality-with-J
open import Equality.Path.Isomorphisms eq hiding (univ)
open import Equivalence equality-with-J as Eq
using (_≃_; Is-equivalence)
open import Equivalence.Erased equality-with-J as EEq
using (_≃ᴱ_; Is-equivalenceᴱ; Contractibleᴱ; _⁻¹ᴱ_)
open import Erased.Cubical eq
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional eq as PT
open import Preimage equality-with-J using (_⁻¹_)
open import Surjection equality-with-J using (_↠_)
open import Univalence-axiom equality-with-J
open import Lens.Non-dependent eq as Non-dependent
hiding (no-first-projection-lens)
import Lens.Non-dependent.Equivalent-preimages eq as EP
import Lens.Non-dependent.Higher eq as H
import Lens.Non-dependent.Traditional eq as T
import Lens.Non-dependent.Traditional.Erased eq as Traditionalᴱ
private
variable
a b c d p r : Level
A A₁ A₂ B B₁ B₂ : Set a
P : A → Set p
n : ℕ
------------------------------------------------------------------------
-- Higher lenses
private
module Temporarily-private where
-- Higher lenses with erased "proofs".
record Lens (A : Set a) (B : Set b) : Set (lsuc (a ⊔ b)) where
constructor ⟨_,_,_⟩
pattern
no-eta-equality
field
-- Remainder type.
R : Set (a ⊔ b)
-- Equivalence (with erased proofs).
equiv : A ≃ᴱ (R × B)
-- The proof of (mere) inhabitance.
@0 inhabited : R → ∥ B ∥
open Temporarily-private public hiding (module Lens)
-- Lens can be expressed as a nested Σ-type.
Lens-as-Σ :
{A : Set a} {B : Set b} →
Lens A B ≃
∃ λ (R : Set (a ⊔ b)) →
(A ≃ᴱ (R × B)) ×
Erased (R → ∥ B ∥)
Lens-as-Σ = Eq.↔→≃
(λ l → R l , equiv l , [ inhabited l ])
(λ (R , equiv , [ inhabited ]) → record
{ R = R
; equiv = equiv
; inhabited = inhabited
})
refl
(λ { ⟨ _ , _ , _ ⟩ → refl _ })
where
open Temporarily-private.Lens
-- Lenses without erased proofs can be turned into lenses with erased
-- proofs.
Higher-lens→Lens : H.Lens A B → Lens A B
Higher-lens→Lens {A = A} {B = B} l@(H.⟨ _ , _ , _ ⟩) = $⟨ l ⟩
H.Lens A B ↔⟨ H.Lens-as-Σ ⟩
(∃ λ (R : Set _) → (A ≃ (R × B)) × (R → ∥ B ∥)) ↝⟨ Σ-map P.id (Σ-map EEq.≃→≃ᴱ [_]→) ⟩
(∃ λ (R : Set _) → (A ≃ᴱ (R × B)) × Erased (R → ∥ B ∥)) ↔⟨ inverse Lens-as-Σ ⟩□
Lens A B □
-- In erased contexts Lens A B is equivalent to H.Lens A B.
@0 Lens≃Higher-lens : Lens A B ≃ H.Lens A B
Lens≃Higher-lens {A = A} {B = B} =
Eq.with-other-inverse
(Lens A B ↝⟨ Lens-as-Σ ⟩
(∃ λ (R : Set _) → (A ≃ᴱ (R × B)) × Erased (R → ∥ B ∥)) ↝⟨ (∃-cong λ _ →
inverse (EEq.≃≃≃ᴱ ext) ×-cong Eq.↔⇒≃ (erased Erased↔)) ⟩
(∃ λ (R : Set _) → (A ≃ (R × B)) × (R → ∥ B ∥)) ↔⟨ inverse H.Lens-as-Σ ⟩□
H.Lens A B □)
Higher-lens→Lens
(λ { H.⟨ _ , _ , _ ⟩ → refl _ })
private
-- The forward direction of Lens≃Higher-lens.
@0 high : Lens A B → H.Lens A B
high = _≃_.to Lens≃Higher-lens
-- Some derived definitions.
module Lens (l : Lens A B) where
open Temporarily-private.Lens l public
-- Remainder.
remainder : A → R
remainder a = proj₁ (_≃ᴱ_.to equiv a)
-- Getter.
get : A → B
get a = proj₂ (_≃ᴱ_.to equiv a)
-- Setter.
set : A → B → A
set a b = _≃ᴱ_.from equiv (remainder a , b)
-- A combination of get and set.
modify : (B → B) → A → A
modify f x = set x (f (get x))
-- Lens laws.
@0 get-set : ∀ a b → get (set a b) ≡ b
get-set a b =
proj₂ (_≃ᴱ_.to equiv (_≃ᴱ_.from equiv (remainder a , b))) ≡⟨ cong proj₂ (_≃ᴱ_.right-inverse-of equiv _) ⟩∎
proj₂ (remainder a , b) ∎
@0 set-get : ∀ a → set a (get a) ≡ a
set-get a =
_≃ᴱ_.from equiv (_≃ᴱ_.to equiv a) ≡⟨ _≃ᴱ_.left-inverse-of equiv _ ⟩∎
a ∎
@0 set-set : ∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂
set-set a b₁ b₂ =
let r = remainder a in
_≃ᴱ_.from equiv (remainder (_≃ᴱ_.from equiv (r , b₁)) , b₂) ≡⟨⟩
_≃ᴱ_.from equiv
(proj₁ (_≃ᴱ_.to equiv (_≃ᴱ_.from equiv (r , b₁))) , b₂) ≡⟨ cong (λ p → _≃ᴱ_.from equiv (proj₁ p , b₂)) $
_≃ᴱ_.right-inverse-of equiv _ ⟩∎
_≃ᴱ_.from equiv (r , b₂) ∎
-- Another law.
@0 remainder-set : ∀ a b → remainder (set a b) ≡ remainder a
remainder-set = H.Lens.remainder-set (high l)
-- The remainder function is surjective (in erased contexts).
@0 remainder-surjective : Surjective remainder
remainder-surjective =
H.Lens.remainder-surjective (high l)
-- A traditional lens with erased proofs.
traditional-lens : Traditionalᴱ.Lens A B
traditional-lens = record
{ get = get
; set = set
; get-set = get-set
; set-get = set-get
; set-set = set-set
}
-- The following two coherence laws, which do not necessarily hold
-- for traditional lenses with erased proofs (see
-- Traditionalᴱ.getter-equivalence-but-not-coherent), hold
-- unconditionally for higher lenses (in erased contexts).
@0 get-set-get : ∀ a → cong get (set-get a) ≡ get-set a (get a)
get-set-get a =
cong (proj₂ ⊚ _≃ᴱ_.to equiv) (_≃ᴱ_.left-inverse-of equiv _) ≡⟨ sym $ cong-∘ _ _ (_≃ᴱ_.left-inverse-of equiv _) ⟩
cong proj₂ (cong (_≃ᴱ_.to equiv) (_≃ᴱ_.left-inverse-of equiv _)) ≡⟨ cong (cong proj₂) $ _≃ᴱ_.left-right-lemma equiv _ ⟩∎
cong proj₂ (_≃ᴱ_.right-inverse-of equiv _) ∎
@0 get-set-set :
∀ a b₁ b₂ →
cong get (set-set a b₁ b₂) ≡
trans (get-set (set a b₁) b₂) (sym (get-set a b₂))
get-set-set a b₁ b₂ = elim₁
(λ eq →
cong (proj₂ ⊚ _≃ᴱ_.to equiv)
(cong (λ p → _≃ᴱ_.from equiv (proj₁ p , _)) eq) ≡
trans (cong proj₂ (_≃ᴱ_.right-inverse-of equiv _))
(sym (cong proj₂ (_≃ᴱ_.right-inverse-of equiv _))))
(cong (proj₂ ⊚ _≃ᴱ_.to equiv)
(cong (λ p → _≃ᴱ_.from equiv (proj₁ p , b₂))
(refl (proj₁ (_≃ᴱ_.to equiv a) , b₁))) ≡⟨ cong (cong (proj₂ ⊚ _≃ᴱ_.to equiv)) $ cong-refl _ ⟩
cong (proj₂ ⊚ _≃ᴱ_.to equiv) (refl _) ≡⟨ cong-refl _ ⟩
refl _ ≡⟨ sym $ trans-symʳ _ ⟩∎
trans (cong proj₂ (_≃ᴱ_.right-inverse-of equiv _))
(sym (cong proj₂ (_≃ᴱ_.right-inverse-of equiv _))) ∎)
(_≃ᴱ_.right-inverse-of equiv _)
-- A somewhat coherent lens with erased proofs.
coherent-lens : Traditionalᴱ.Coherent-lens A B
coherent-lens = record
{ lens = traditional-lens
; get-set-get = get-set-get
; get-set-set = get-set-set
}
instance
-- Higher lenses have getters and setters.
has-getter-and-setter :
Has-getter-and-setter (Lens {a = a} {b = b})
has-getter-and-setter = record
{ get = Lens.get
; set = Lens.set
}
------------------------------------------------------------------------
-- Equivalences with erased proofs can be converted to lenses
-- Converts equivalences between a domain and the cartesian product of
-- a type and a codomain to lenses.
≃ᴱ×→Lens :
{A : Set a} {B : Set b} {R : Set (a ⊔ b)} →
A ≃ᴱ (R × B) → Lens A B
≃ᴱ×→Lens {A = A} {B = B} {R = R} A≃R×B = record
{ R = R × Erased ∥ B ∥
; equiv = A ↝⟨ A≃R×B ⟩
R × B ↔⟨ F.id ×-cong inverse Erased-∥∥×≃ ⟩
R × Erased ∥ B ∥ × B ↔⟨ ×-assoc ⟩□
(R × Erased ∥ B ∥) × B □
; inhabited = erased ⊚ proj₂
}
-- Converts equivalences to lenses.
≃ᴱ→Lens :
{A : Set a} {B : Set b} →
A ≃ᴱ B → Lens A B
≃ᴱ→Lens {a = a} {A = A} {B = B} A≃B = record
{ R = Erased ∥ ↑ a B ∥
; equiv = A ↝⟨ A≃B ⟩
B ↔⟨ inverse Erased-∥∥×≃ ⟩
Erased ∥ B ∥ × B ↔⟨ Erased-cong (∥∥-cong (inverse Bijection.↑↔)) ×-cong F.id ⟩□
Erased ∥ ↑ a B ∥ × B □
; inhabited = ∥∥-map lower ⊚ erased
}
-- Converts equivalences between types with the same universe level to
-- lenses.
≃ᴱ→Lens′ :
{A B : Set a} →
A ≃ᴱ B → Lens A B
≃ᴱ→Lens′ {a = a} {A = A} {B = B} A≃B = record
{ R = Erased ∥ B ∥
; equiv = A ↝⟨ A≃B ⟩
B ↔⟨ inverse Erased-∥∥×≃ ⟩□
Erased ∥ B ∥ × B □
; inhabited = erased
}
------------------------------------------------------------------------
-- Equality characterisation lemmas for lenses
-- An equality characterisation lemma.
equality-characterisation₀ :
{l₁ l₂ : Lens A B} →
let open Lens in
l₁ ≡ l₂
↔
∃ λ (eq : R l₁ ≡ R l₂) →
subst (λ R → A ≃ᴱ (R × B)) eq (equiv l₁) ≡ equiv l₂
equality-characterisation₀ {A = A} {B = B} {l₁ = l₁} {l₂ = l₂} =
l₁ ≡ l₂ ↔⟨ inverse $ Eq.≃-≡ Lens-as-Σ ⟩
l₁′ ≡ l₂′ ↝⟨ inverse Bijection.Σ-≡,≡↔≡ ⟩
(∃ λ (eq : R l₁ ≡ R l₂) →
subst (λ R → A ≃ᴱ (R × B) × Erased (R → ∥ B ∥)) eq (proj₂ l₁′) ≡
proj₂ l₂′) ↝⟨ (∃-cong λ _ → inverse $
ignore-propositional-component
(H-level-Erased 1 (
Π-closure ext 1 λ _ →
truncation-is-proposition))) ⟩
(∃ λ (eq : R l₁ ≡ R l₂) →
proj₁ (subst (λ R → A ≃ᴱ (R × B) × Erased (R → ∥ B ∥))
eq (proj₂ l₁′)) ≡
equiv l₂) ↝⟨ (∃-cong λ eq → ≡⇒↝ _ $
cong (λ p → proj₁ p ≡ _) (push-subst-, {y≡z = eq} _ _)) ⟩□
(∃ λ (eq : R l₁ ≡ R l₂) →
subst (λ R → A ≃ᴱ (R × B)) eq (equiv l₁) ≡ equiv l₂) □
where
open Lens
l₁′ = _≃_.to Lens-as-Σ l₁
l₂′ = _≃_.to Lens-as-Σ l₂
-- Another equality characterisation lemma.
@0 equality-characterisation₁ :
{A : Set a} {B : Set b} {l₁ l₂ : Lens A B} →
let open Lens in
Univalence (a ⊔ b) →
l₁ ≡ l₂
↔
∃ λ (eq : R l₁ ≃ R l₂) →
from-equivalence (eq ×-cong F.id) F.∘ equiv l₁ ≡ equiv l₂
equality-characterisation₁ {A = A} {B = B} {l₁ = l₁} {l₂ = l₂} univ =
l₁ ≡ l₂ ↔⟨ inverse $ Eq.≃-≡ Lens≃Higher-lens ⟩
high l₁ ≡ high l₂ ↝⟨ H.equality-characterisation₁ univ ⟩
(∃ λ (eq : R l₁ ≃ R l₂) →
(eq ×-cong F.id) F.∘ H.Lens.equiv (high l₁) ≡
H.Lens.equiv (high l₂)) ↔⟨ (∃-cong λ eq → inverse $ Eq.≃-≡ $ EEq.≃≃≃ᴱ ext) ⟩
(∃ λ (eq : R l₁ ≃ R l₂) →
EEq.≃→≃ᴱ ((eq ×-cong F.id) F.∘ H.Lens.equiv (high l₁)) ≡
EEq.≃→≃ᴱ (H.Lens.equiv (high l₂))) ↝⟨ (∃-cong λ _ → ≡⇒↝ _ $ cong₂ _≡_
(EEq.to≡to→≡ ext (refl _))
(EEq.to≡to→≡ ext (refl _))) ⟩□
(∃ λ (eq : R l₁ ≃ R l₂) →
from-equivalence (eq ×-cong F.id) F.∘ equiv l₁ ≡ equiv l₂) □
where
open Lens
-- Yet another equality characterisation lemma.
@0 equality-characterisation₂ :
{A : Set a} {B : Set b} {l₁ l₂ : Lens A B} →
let open Lens in
Univalence (a ⊔ b) →
l₁ ≡ l₂
↔
∃ λ (eq : R l₁ ≃ R l₂) →
∀ x → (_≃_.to eq (remainder l₁ x) , get l₁ x) ≡
_≃ᴱ_.to (equiv l₂) x
equality-characterisation₂ {l₁ = l₁} {l₂ = l₂} univ =
l₁ ≡ l₂ ↔⟨ inverse $ Eq.≃-≡ Lens≃Higher-lens ⟩
high l₁ ≡ high l₂ ↝⟨ H.equality-characterisation₂ univ ⟩□
(∃ λ (eq : R l₁ ≃ R l₂) →
∀ x → (_≃_.to eq (remainder l₁ x) , get l₁ x) ≡
_≃ᴱ_.to (equiv l₂) x) □
where
open Lens
-- And another one.
@0 equality-characterisation₃ :
{A : Set a} {B : Set b} {l₁ l₂ : Lens A B} →
let open Lens in
Univalence (a ⊔ b) →
l₁ ≡ l₂
↔
∃ λ (eq : R l₁ ≃ R l₂) →
(∀ x → _≃_.to eq (remainder l₁ x) ≡ remainder l₂ x)
×
(∀ x → get l₁ x ≡ get l₂ x)
equality-characterisation₃ {l₁ = l₁} {l₂ = l₂} univ =
l₁ ≡ l₂ ↔⟨ inverse $ Eq.≃-≡ Lens≃Higher-lens ⟩
high l₁ ≡ high l₂ ↝⟨ H.equality-characterisation₃ univ ⟩□
(∃ λ (eq : R l₁ ≃ R l₂) →
(∀ x → _≃_.to eq (remainder l₁ x) ≡ remainder l₂ x)
×
(∀ x → get l₁ x ≡ get l₂ x)) □
where
open Lens
-- And a final one.
@0 equality-characterisation₄ :
{A : Set a} {B : Set b} {l₁ l₂ : Lens A B} →
let open Lens in
Univalence (a ⊔ b) →
l₁ ≡ l₂
↔
∃ λ (eq : R l₁ ≃ R l₂) →
∀ p → _≃ᴱ_.from (equiv l₁) (_≃_.from eq (proj₁ p) , proj₂ p) ≡
_≃ᴱ_.from (equiv l₂) p
equality-characterisation₄ {l₁ = l₁} {l₂} univ =
l₁ ≡ l₂ ↔⟨ inverse $ Eq.≃-≡ Lens≃Higher-lens ⟩
high l₁ ≡ high l₂ ↝⟨ H.equality-characterisation₄ univ ⟩□
(∃ λ (eq : R l₁ ≃ R l₂) →
∀ p → _≃ᴱ_.from (equiv l₁) (_≃_.from eq (proj₁ p) , proj₂ p) ≡
_≃ᴱ_.from (equiv l₂) p) □
where
open Lens
-- ------------------------------------------------------------------------
-- -- More lens equalities
-- If the forward direction of an equivalence with erased proofs is
-- Lens.get l, then the setter of l can be expressed using the other
-- direction of the equivalence (in erased contexts).
@0 from≡set :
∀ (l : Lens A B) is-equiv →
let open Lens
A≃B = EEq.⟨ get l , is-equiv ⟩
in
∀ a b → _≃ᴱ_.from A≃B b ≡ set l a b
from≡set l is-equiv =
H.from≡set (high l) (EEq.Is-equivalenceᴱ→Is-equivalence is-equiv)
-- If two lenses have equal setters, then they also have equal
-- getters (in erased contexts).
@0 getters-equal-if-setters-equal :
let open Lens in
(l₁ l₂ : Lens A B) →
set l₁ ≡ set l₂ →
get l₁ ≡ get l₂
getters-equal-if-setters-equal l₁ l₂ =
Lens.set l₁ ≡ Lens.set l₂ ↔⟨⟩
H.Lens.set (high l₁) ≡ H.Lens.set (high l₂) ↝⟨ H.getters-equal-if-setters-equal (high l₁) (high l₂) ⟩
H.Lens.get (high l₁) ≡ H.Lens.get (high l₂) ↔⟨⟩
Lens.get l₁ ≡ Lens.get l₂ □
-- A generalisation of lenses-equal-if-setters-equal (which is defined
-- below).
@0 lenses-equal-if-setters-equal′ :
let open Lens in
{A : Set a} {B : Set b}
(univ : Univalence (a ⊔ b))
(l₁ l₂ : Lens A B)
(f : R l₁ → R l₂) →
(B → ∀ r →
∃ λ b′ → remainder l₂ (_≃ᴱ_.from (equiv l₁) (r , b′)) ≡ f r) →
(∀ a → f (remainder l₁ a) ≡ remainder l₂ a) →
Lens.set l₁ ≡ Lens.set l₂ →
l₁ ≡ l₂
lenses-equal-if-setters-equal′
univ l₁ l₂ f ∃≡f f-remainder≡remainder setters-equal =
$⟨ H.lenses-equal-if-setters-equal′
univ (high l₁) (high l₂) f ∃≡f
f-remainder≡remainder setters-equal ⟩
high l₁ ≡ high l₂ ↝⟨ Eq.≃-≡ Lens≃Higher-lens {x = l₁} {y = l₂} ⟩□
l₁ ≡ l₂ □
-- If the codomain of a lens is inhabited when it is merely inhabited
-- and the remainder type is inhabited, then this lens is equal to
-- another lens if their setters are equal (in erased contexts,
-- assuming univalence).
@0 lenses-equal-if-setters-equal :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
(l₁ l₂ : Lens A B) →
(Lens.R l₁ → ∥ B ∥ → B) →
Lens.set l₁ ≡ Lens.set l₂ →
l₁ ≡ l₂
lenses-equal-if-setters-equal univ l₁ l₂ inh′ setters-equal =
$⟨ H.lenses-equal-if-setters-equal
univ (high l₁) (high l₂) inh′ setters-equal ⟩
high l₁ ≡ high l₂ ↝⟨ Eq.≃-≡ Lens≃Higher-lens {x = l₁} {y = l₂} ⟩□
l₁ ≡ l₂ □
-- If a lens has a propositional remainder type, then this lens is
-- equal to another lens if their setters are equal (in erased
-- contexts, assuming univalence).
@0 lenses-equal-if-setters-equal-and-remainder-propositional :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
(l₁ l₂ : Lens A B) →
Is-proposition (Lens.R l₂) →
Lens.set l₁ ≡ Lens.set l₂ →
l₁ ≡ l₂
lenses-equal-if-setters-equal-and-remainder-propositional
univ l₁ l₂ R₂-prop setters-equal =
$⟨ H.lenses-equal-if-setters-equal-and-remainder-propositional
univ (high l₁) (high l₂) R₂-prop setters-equal ⟩
high l₁ ≡ high l₂ ↝⟨ Eq.≃-≡ Lens≃Higher-lens {x = l₁} {y = l₂} ⟩□
l₁ ≡ l₂ □
-- The functions ≃ᴱ→Lens and ≃ᴱ→Lens′ are pointwise equal (when
-- applicable, in erased contexts, assuming univalence).
@0 ≃ᴱ→Lens≡≃ᴱ→Lens′ :
{A B : Set a} →
Univalence a →
(A≃B : A ≃ᴱ B) → ≃ᴱ→Lens A≃B ≡ ≃ᴱ→Lens′ A≃B
≃ᴱ→Lens≡≃ᴱ→Lens′ {B = B} univ A≃B =
_↔_.from (equality-characterisation₃ univ)
( (Erased ∥ ↑ _ B ∥ ↔⟨ Erased-cong (∥∥-cong Bijection.↑↔) ⟩□
Erased ∥ B ∥ □)
, (λ _ → refl _)
, (λ _ → refl _)
)
-- If the getter of a lens is an equivalence with erased proofs, then
-- the lens formed using the equivalence (using ≃ᴱ→Lens) is equal to
-- the lens (in erased contexts, assuming univalence).
@0 get-equivalence→≡≃ᴱ→Lens :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
(l : Lens A B) →
(eq : Is-equivalenceᴱ (Lens.get l)) →
l ≡ ≃ᴱ→Lens EEq.⟨ Lens.get l , eq ⟩
get-equivalence→≡≃ᴱ→Lens {A = A} {B = B} univ l eq =
lenses-equal-if-setters-equal-and-remainder-propositional
univ l (≃ᴱ→Lens EEq.⟨ Lens.get l , eq ⟩)
(H-level-Erased 1 truncation-is-proposition)
(⟨ext⟩ λ a → ⟨ext⟩ λ b →
set l a b ≡⟨ sym $ from≡set l eq a b ⟩
_≃ᴱ_.from A≃B b ≡⟨⟩
set (≃ᴱ→Lens A≃B) a b ∎)
where
open Lens
A≃B : A ≃ᴱ B
A≃B = EEq.⟨ _ , eq ⟩
-- A variant of get-equivalence→≡≃ᴱ→Lens.
@0 get-equivalence→≡≃ᴱ→Lens′ :
{A B : Set a} →
Univalence a →
(l : Lens A B) →
(eq : Is-equivalenceᴱ (Lens.get l)) →
l ≡ ≃ᴱ→Lens′ EEq.⟨ Lens.get l , eq ⟩
get-equivalence→≡≃ᴱ→Lens′ {A = A} {B = B} univ l eq =
l ≡⟨ get-equivalence→≡≃ᴱ→Lens univ l eq ⟩
≃ᴱ→Lens A≃B ≡⟨ ≃ᴱ→Lens≡≃ᴱ→Lens′ univ A≃B ⟩∎
≃ᴱ→Lens′ A≃B ∎
where
A≃B = EEq.⟨ Lens.get l , eq ⟩
------------------------------------------------------------------------
-- Some lens isomorphisms
-- A generalised variant of Lens preserves equivalences with erased
-- proofs.
Lens-cong′ :
A₁ ≃ᴱ A₂ → B₁ ≃ᴱ B₂ →
(∃ λ (R : Set r) → A₁ ≃ᴱ (R × B₁) × Erased (R → ∥ B₁ ∥)) ≃ᴱ
(∃ λ (R : Set r) → A₂ ≃ᴱ (R × B₂) × Erased (R → ∥ B₂ ∥))
Lens-cong′ A₁≃A₂ B₁≃B₂ =
∃-cong λ _ →
EEq.≃ᴱ-cong ext A₁≃A₂ (F.id ×-cong B₁≃B₂)
×-cong
Erased-cong (→-cong ext F.id (∥∥-cong B₁≃B₂))
-- Lens preserves level-preserving equivalences with erased proofs.
Lens-cong :
{A₁ A₂ : Set a} {B₁ B₂ : Set b} →
A₁ ≃ᴱ A₂ → B₁ ≃ᴱ B₂ →
Lens A₁ B₁ ≃ᴱ Lens A₂ B₂
Lens-cong {A₁ = A₁} {A₂ = A₂} {B₁ = B₁} {B₂ = B₂} A₁≃A₂ B₁≃B₂ =
Lens A₁ B₁ ↔⟨ Lens-as-Σ ⟩
(∃ λ R → A₁ ≃ᴱ (R × B₁) × Erased (R → ∥ B₁ ∥)) ↝⟨ Lens-cong′ A₁≃A₂ B₁≃B₂ ⟩
(∃ λ R → A₂ ≃ᴱ (R × B₂) × Erased (R → ∥ B₂ ∥)) ↔⟨ inverse Lens-as-Σ ⟩□
Lens A₂ B₂ □
-- If B is a proposition, then Lens A B is equivalent (with erased
-- proofs) to A → B (assuming univalence).
lens-to-proposition≃ᴱget :
{A : Set a} {B : Set b} →
@0 Univalence (a ⊔ b) →
@0 Is-proposition B →
Lens A B ≃ᴱ (A → B)
lens-to-proposition≃ᴱget {b = b} {A = A} {B = B} univ prop = EEq.↔→≃ᴱ
get
from
refl
(λ l →
let lemma =
↑ b A ↔⟨ Bijection.↑↔ ⟩
A ↝⟨ EEq.≃ᴱ→≃ (equiv l) ⟩
R l × B ↝⟨ (EEq.≃ᴱ→≃ $ drop-⊤-right λ r → _⇔_.to EEq.Contractibleᴱ⇔≃ᴱ⊤ $
PT.rec
(EEq.Contractibleᴱ-propositional ext)
(λ b → EEq.inhabited→Is-proposition→Contractibleᴱ b prop)
(inhabited l r)) ⟩□
R l □
in
_↔_.from (equality-characterisation₂ univ)
(lemma , λ _ → refl _))
where
open Lens
from = λ get → record
{ R = ↑ b A
; equiv = A ↔⟨ inverse Bijection.↑↔ ⟩
↑ b A ↝⟨ (inverse $ drop-⊤-right λ (lift a) →
EEq.inhabited→Is-proposition→≃ᴱ⊤ (get a) prop) ⟩□
↑ b A × B □
; inhabited = ∣_∣ ⊚ get ⊚ lower
}
_ :
{A : Set a} {B : Set b}
(@0 univ : Univalence (a ⊔ b))
(@0 prop : Is-proposition B)
(l : Lens A B) →
_≃ᴱ_.to (lens-to-proposition≃ᴱget univ prop) l ≡ Lens.get l
_ = λ _ _ _ → refl _
-- If B is contractible (with an erased proof), then Lens A B is
-- equivalent (with erased proofs) to ⊤ (assuming univalence).
lens-to-contractible≃ᴱ⊤ :
{A : Set a} {B : Set b} →
@0 Univalence (a ⊔ b) →
Contractibleᴱ B →
Lens A B ≃ᴱ ⊤
lens-to-contractible≃ᴱ⊤ {A = A} {B} univ cB =
Lens A B ↝⟨ lens-to-proposition≃ᴱget univ (mono₁ 0 (EEq.Contractibleᴱ→Contractible cB)) ⟩
(A → B) ↝⟨ →-cong ext F.id $ _⇔_.to EEq.Contractibleᴱ⇔≃ᴱ⊤ cB ⟩
(A → ⊤) ↔⟨ →-right-zero ⟩□
⊤ □
-- Lens A ⊥ is equivalent (with erased proofs) to ¬ A (assuming
-- univalence).
lens-to-⊥≃ᴱ¬ :
{A : Set a} →
@0 Univalence (a ⊔ b) →
Lens A (⊥ {ℓ = b}) ≃ᴱ (¬ A)
lens-to-⊥≃ᴱ¬ {A = A} univ =
Lens A ⊥ ↝⟨ lens-to-proposition≃ᴱget univ ⊥-propositional ⟩
(A → ⊥) ↝⟨ inverse $ ¬↔→⊥ ext ⟩□
¬ A □
-- If A is contractible (with an erased proof), then Lens A B is
-- equivalent (with erased proofs) to Contractibleᴱ B (assuming
-- univalence).
lens-from-contractible≃ᴱcodomain-contractible :
{A : Set a} {B : Set b} →
@0 Univalence (a ⊔ b) →
Contractibleᴱ A →
Lens A B ≃ᴱ Contractibleᴱ B
lens-from-contractible≃ᴱcodomain-contractible {A = A} {B} univ cA =
Lens A B ↔⟨ Lens-as-Σ ⟩
(∃ λ R → A ≃ᴱ (R × B) × Erased (R → ∥ B ∥)) ↝⟨ (∃-cong λ _ → ×-cong₁ λ _ →
EEq.≃ᴱ-cong ext (_⇔_.to EEq.Contractibleᴱ⇔≃ᴱ⊤ cA) F.id) ⟩
(∃ λ R → ⊤ ≃ᴱ (R × B) × Erased (R → ∥ B ∥)) ↝⟨ (∃-cong λ _ → ×-cong₁ λ _ → EEq.inverse-equivalence ext) ⟩
(∃ λ R → (R × B) ≃ᴱ ⊤ × Erased (R → ∥ B ∥)) ↝⟨ (∃-cong λ _ → ×-cong₁ λ _ → inverse $ EEq.Contractibleᴱ≃ᴱ≃ᴱ⊤ ext) ⟩
(∃ λ R → Contractibleᴱ (R × B) × Erased (R → ∥ B ∥)) ↝⟨ (∃-cong λ _ → ×-cong₁ λ _ → EEq.Contractibleᴱ-commutes-with-× ext) ⟩
(∃ λ R → (Contractibleᴱ R × Contractibleᴱ B) × Erased (R → ∥ B ∥)) ↔⟨ (∃-cong λ _ → inverse ×-assoc) ⟩
(∃ λ R → Contractibleᴱ R × Contractibleᴱ B × Erased (R → ∥ B ∥)) ↝⟨ (∃-cong λ _ → ∃-cong λ cR → ∃-cong λ _ → Erased-cong (
→-cong ext (_⇔_.to EEq.Contractibleᴱ⇔≃ᴱ⊤ cR) F.id)) ⟩
(∃ λ R → Contractibleᴱ R × Contractibleᴱ B × Erased (⊤ → ∥ B ∥)) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → Erased-cong Π-left-identity) ⟩
(∃ λ R → Contractibleᴱ R × Contractibleᴱ B × Erased ∥ B ∥) ↔⟨ (∃-cong λ _ → ×-comm) ⟩
(∃ λ R → (Contractibleᴱ B × Erased ∥ B ∥) × Contractibleᴱ R) ↔⟨ ∃-comm ⟩
(Contractibleᴱ B × Erased ∥ B ∥) × (∃ λ R → Contractibleᴱ R) ↝⟨ (drop-⊤-right λ _ → EEq.∃Contractibleᴱ≃ᴱ⊤ ext univ) ⟩
Contractibleᴱ B × Erased ∥ B ∥ ↔⟨ (∃-cong λ cB → Erased-cong (inhabited⇒∥∥↔⊤ ∣ proj₁ cB ∣)) ⟩
Contractibleᴱ B × Erased ⊤ ↔⟨ (drop-⊤-right λ _ → Erased-⊤↔⊤) ⟩□
Contractibleᴱ B □
-- Lens ⊥ B is equivalent (with erased proofs) to the unit type
-- (assuming univalence).
lens-from-⊥↔⊤ :
{B : Set b} →
Univalence (a ⊔ b) →
Lens (⊥ {ℓ = a}) B ≃ᴱ ⊤
lens-from-⊥↔⊤ {B = B} univ =
_⇔_.to EEq.Contractibleᴱ⇔≃ᴱ⊤ $
≃ᴱ×→Lens
(⊥ ↔⟨ inverse ×-left-zero ⟩□
⊥ × B □)
, [ (λ l → _↔_.from (equality-characterisation₂ univ)
( (⊥ × Erased ∥ B ∥ ↔⟨ ×-left-zero ⟩
⊥₀ ↝⟨ lemma l ⟩□
R l □)
, λ x → ⊥-elim x
))
]
where
open Lens
@0 lemma : (l : Lens ⊥ B) → ⊥₀ ≃ R l
lemma l = Eq.↔→≃ ⊥-elim whatever whatever (λ x → ⊥-elim x)
where
whatever : (r : R l) → P r
whatever r = ⊥-elim {ℓ = lzero} $ PT.rec
⊥-propositional
(λ b → ⊥-elim (_≃ᴱ_.from (equiv l) (r , b)))
(inhabited l r)
-- There is an equivalence with erased proofs between A ≃ᴱ B and
-- ∃ λ (l : Lens A B) → Is-equivalenceᴱ (Lens.get l) (assuming
-- univalence).
--
-- See also ≃≃≊ below.
≃ᴱ-≃ᴱ-Σ-Lens-Is-equivalenceᴱ-get :
{A : Set a} {B : Set b} →
@0 Univalence (a ⊔ b) →
(A ≃ᴱ B) ≃ᴱ (∃ λ (l : Lens A B) → Is-equivalenceᴱ (Lens.get l))
≃ᴱ-≃ᴱ-Σ-Lens-Is-equivalenceᴱ-get univ = EEq.↔→≃ᴱ
(λ A≃B → ≃ᴱ→Lens A≃B , _≃ᴱ_.is-equivalence A≃B)
(λ (l , eq) → EEq.⟨ Lens.get l , eq ⟩)
(λ (l , eq) → Σ-≡,≡→≡
(sym $ get-equivalence→≡≃ᴱ→Lens univ l eq)
(EEq.Is-equivalenceᴱ-propositional ext _ _ _))
(λ _ → EEq.to≡to→≡ ext (refl _))
-- The right-to-left direction of ≃ᴱ-≃ᴱ-Σ-Lens-Is-equivalenceᴱ-get
-- returns the lens's getter (and some proof).
to-from-≃ᴱ-≃ᴱ-Σ-Lens-Is-equivalenceᴱ-get≡get :
{A : Set a} {B : Set b} →
(@0 univ : Univalence (a ⊔ b))
(p@(l , _) : ∃ λ (l : Lens A B) → Is-equivalenceᴱ (Lens.get l)) →
_≃ᴱ_.to (_≃ᴱ_.from (≃ᴱ-≃ᴱ-Σ-Lens-Is-equivalenceᴱ-get univ) p) ≡
Lens.get l
to-from-≃ᴱ-≃ᴱ-Σ-Lens-Is-equivalenceᴱ-get≡get _ _ = refl _
------------------------------------------------------------------------
-- Results relating different kinds of lenses
-- In general there is no split surjection from Lens A B to
-- Traditionalᴱ.Lens A B (assuming univalence).
¬Lens↠Traditional-lens :
@0 Univalence lzero →
@0 Univalence a →
∃ λ (A : Set a) → ¬ (Lens A ⊤ ↠ Traditionalᴱ.Lens A ⊤)
¬Lens↠Traditional-lens {a = a} univ₀ univ =
A′
, Stable-¬ _
[ (Lens A′ ⊤ ↠ Traditionalᴱ.Lens A′ ⊤) ↝⟨ (λ f → from-equivalence Traditionalᴱ.Lens≃Traditional-lens F.∘
f F.∘
from-equivalence (inverse Lens≃Higher-lens)) ⟩
(H.Lens A′ ⊤ ↠ T.Lens A′ ⊤) ↝⟨ proj₂ $ H.¬Lens↠Traditional-lens univ₀ univ ⟩□
⊥ □
]
where
A′ = _
-- In general there is no equivalence with erased proofs between
-- Lens A B and Traditionalᴱ.Lens A B (assuming univalence).
¬Lens≃ᴱTraditional-lens :
@0 Univalence lzero →
@0 Univalence a →
∃ λ (A : Set a) →
¬ (Lens A ⊤ ≃ᴱ Traditionalᴱ.Lens A ⊤)
¬Lens≃ᴱTraditional-lens univ₀ univ =
A′
, Stable-¬ _
[ (Lens A′ ⊤ ≃ᴱ Traditionalᴱ.Lens A′ ⊤) ↝⟨ from-equivalence ⊚ EEq.≃ᴱ→≃ ⟩
(Lens A′ ⊤ ↠ Traditionalᴱ.Lens A′ ⊤) ↝⟨ proj₂ $ ¬Lens↠Traditional-lens univ₀ univ ⟩□
⊥ □
]
where
A′ = _
-- Some lemmas used in Lens↠Traditional-lens and
-- Lens≃ᴱTraditional-lens below.
private
module Lens≃ᴱTraditional-lens
{A : Set a} {B : Set b}
(@0 A-set : Is-set A)
where
from : Block "conversion" → Traditionalᴱ.Lens A B → Lens A B
from ⊠ l = ≃ᴱ×→Lens
{R = ∃ λ (f : B → A) → Erased (∀ b b′ → set (f b) b′ ≡ f b′)}
(EEq.↔→≃ᴱ
(λ a → (set a , [ set-set a ]) , get a)
(λ ((f , _) , b) → f b)
(λ ((f , [ h ]) , b) →
let
irr = {p q : Erased (∀ b b′ → set (f b) b′ ≡ f b′)} →
p ≡ q
irr =
(H-level-Erased 1 (
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
A-set)) _ _
lemma =
get (f b) ≡⟨ cong get (sym (h b b)) ⟩
get (set (f b) b) ≡⟨ get-set (f b) b ⟩∎
b ∎
in
(set (f b) , [ set-set (f b) ]) , get (f b) ≡⟨ cong₂ _,_ (Σ-≡,≡→≡ (⟨ext⟩ (h b)) irr) lemma ⟩∎
(f , [ h ]) , b ∎)
(λ a →
set a (get a) ≡⟨ set-get a ⟩∎
a ∎))
where
open Traditionalᴱ.Lens l
to∘from : ∀ bc l → Lens.traditional-lens (from bc l) ≡ l
to∘from ⊠ l = _↔_.from Traditionalᴱ.equality-characterisation₁
( refl _
, refl _
, [ (λ a _ → B-set a _ _)
, (λ _ → A-set _ _)
, (λ _ _ _ → A-set _ _)
]
)
where
open Traditionalᴱ.Lens l
@0 B-set : A → Is-set B
B-set a =
Traditionalᴱ.h-level-respects-lens-from-inhabited 2 l a A-set
@0 from∘to :
Univalence (a ⊔ b) →
∀ bc l → from bc (Lens.traditional-lens l) ≡ l
from∘to univ ⊠ l′ =
_↔_.from (equality-characterisation₄ univ)
( lemma
, λ p →
_≃ᴱ_.from l (subst (λ _ → R) (refl _) (proj₁ p) , proj₂ p) ≡⟨ cong (λ r → _≃ᴱ_.from l (r , proj₂ p)) $ subst-refl _ _ ⟩∎
_≃ᴱ_.from l p ∎
)
where
open Lens l′ renaming (equiv to l)
B-set : (B → R) → ∥ B ∥ → Is-set B
B-set f = PT.rec
(H-level-propositional ext 2)
(λ b → $⟨ (λ {_ _} → A-set) ⟩
Is-set A ↝⟨ H-level-cong _ 2 (EEq.≃ᴱ→≃ l) ⟩
Is-set (R × B) ↝⟨ proj₂-closure (f b) 2 ⟩□
Is-set B □)
R-set : ∥ B ∥ → Is-set R
R-set = PT.rec
(H-level-propositional ext 2)
(λ b → $⟨ (λ {_ _} → A-set) ⟩
Is-set A ↝⟨ H-level-cong _ 2 (EEq.≃ᴱ→≃ l) ⟩
Is-set (R × B) ↝⟨ proj₁-closure (const b) 2 ⟩□
Is-set R □)
lemma′ : (∥ B ∥ × (∥ B ∥ → R)) ≃ R
lemma′ = Eq.↔→≃
(λ (b , f) → f b)
(λ r → inhabited r , λ _ → r)
refl
(λ (b , f) → curry (_↔_.to ≡×≡↔≡)
(PT.truncation-is-proposition _ _)
(⟨ext⟩ λ b′ →
f b ≡⟨ cong f (PT.truncation-is-proposition _ _) ⟩∎
f b′ ∎))
lemma =
(∃ λ (f : B → A) →
Erased (∀ b b′ →
_≃ᴱ_.from l (proj₁ (_≃ᴱ_.to l (f b)) , b′) ≡
f b′)) ×
Erased ∥ B ∥ ↔⟨ (∃-cong λ _ → erased Erased↔) ×-cong erased Erased↔ ⟩
(∃ λ (f : B → A) → ∀ b b′ →
_≃ᴱ_.from l (proj₁ (_≃ᴱ_.to l (f b)) , b′) ≡ f b′) ×
∥ B ∥ ↔⟨ ×-comm ⟩
(∥ B ∥ ×
∃ λ (f : B → A) → ∀ b b′ →
_≃ᴱ_.from l (proj₁ (_≃ᴱ_.to l (f b)) , b′) ≡ f b′) ↝⟨ (∃-cong λ _ →
Σ-cong (→-cong ext F.id (EEq.≃ᴱ→≃ l)) λ f →
∀-cong ext λ b → ∀-cong ext λ b′ →
≡⇒↝ _ $ cong (_≃ᴱ_.from l (proj₁ (_≃ᴱ_.to l (f b)) , b′) ≡_) $ sym $
_≃ᴱ_.left-inverse-of l _) ⟩
(∥ B ∥ ×
∃ λ (f : B → R × B) → ∀ b b′ →
_≃ᴱ_.from l (proj₁ (f b) , b′) ≡ _≃ᴱ_.from l (f b′)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ →
Eq.≃-≡ (inverse (EEq.≃ᴱ→≃ l))) ⟩
(∥ B ∥ ×
∃ λ (f : B → R × B) → ∀ b b′ → (proj₁ (f b) , b′) ≡ f b′) ↔⟨ (∃-cong λ _ → Σ-cong ΠΣ-comm λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ →
inverse $ ≡×≡↔≡) ⟩
(∥ B ∥ ×
∃ λ (p : (B → R) × (B → B)) →
∀ b b′ → proj₁ p b ≡ proj₁ p b′ × b′ ≡ proj₂ p b′) ↔⟨ (∃-cong λ _ → inverse Σ-assoc) ⟩
(∥ B ∥ ×
∃ λ (f : B → R) → ∃ λ (g : B → B) →
∀ b b′ → f b ≡ f b′ × b′ ≡ g b′) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ →
ΠΣ-comm) ⟩
(∥ B ∥ ×
∃ λ (f : B → R) → ∃ λ (g : B → B) →
∀ b → (∀ b′ → f b ≡ f b′) × (∀ b′ → b′ ≡ g b′)) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ΠΣ-comm) ⟩
(∥ B ∥ ×
∃ λ (f : B → R) → ∃ λ (g : B → B) →
Constant f × (B → ∀ b → b ≡ g b)) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩
(∥ B ∥ ×
∃ λ (f : B → R) → Constant f ×
∃ λ (g : B → B) → B → ∀ b → b ≡ g b) ↔⟨ (∃-cong λ _ → Σ-assoc) ⟩
(∥ B ∥ ×
(∃ λ (f : B → R) → Constant f) ×
(∃ λ (g : B → B) → B → ∀ b → b ≡ g b)) ↔⟨ (∃-cong λ ∥b∥ → ∃-cong $ uncurry λ f _ → ∃-cong λ _ → inverse $
→-intro ext (λ _ → B-set f ∥b∥)) ⟩
(∥ B ∥ ×
(∃ λ (f : B → R) → Constant f) ×
(∃ λ (g : B → B) → ∀ b → b ≡ g b)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ →
Eq.extensionality-isomorphism ext) ⟩
(∥ B ∥ ×
(∃ λ (f : B → R) → Constant f) ×
(∃ λ (g : B → B) → F.id ≡ g)) ↔⟨ (∃-cong λ _ → drop-⊤-right λ _ →
_⇔_.to contractible⇔↔⊤ $
other-singleton-contractible _) ⟩
(∥ B ∥ × ∃ λ (f : B → R) → Constant f) ↝⟨ (∃-cong λ ∥b∥ → PT.constant-function≃∥inhabited∥⇒inhabited (R-set ∥b∥)) ⟩
(∥ B ∥ × (∥ B ∥ → R)) ↔⟨ lemma′ ⟩□
R □
equiv :
Block "conversion" →
@0 Univalence (a ⊔ b) →
Lens A B ≃ᴱ Traditionalᴱ.Lens A B
equiv bc univ = EEq.↔→≃ᴱ
_
(from bc)
(to∘from bc)
(from∘to univ bc)
-- If the domain A is a set, then there is a split surjection from
-- Lens A B to Traditionalᴱ.Lens A B.
Lens↠Traditional-lens :
Block "conversion" →
@0 Is-set A →
Lens A B ↠ Traditionalᴱ.Lens A B
Lens↠Traditional-lens {A = A} {B = B} bc A-set = record
{ logical-equivalence = record
{ to = Lens.traditional-lens
; from = Lens≃ᴱTraditional-lens.from A-set bc
}
; right-inverse-of = Lens≃ᴱTraditional-lens.to∘from A-set bc
}
-- The split surjection above preserves getters and setters.
Lens↠Traditional-lens-preserves-getters-and-setters :
{A : Set a}
(b : Block "conversion")
(@0 s : Is-set A) →
Preserves-getters-and-setters-⇔ A B
(_↠_.logical-equivalence (Lens↠Traditional-lens b s))
Lens↠Traditional-lens-preserves-getters-and-setters ⊠ _ =
(λ _ → refl _ , refl _) , (λ _ → refl _ , refl _)
-- If the domain A is a set, then there is an equivalence with erased
-- proofs between Traditionalᴱ.Lens A B and Lens A B (assuming
-- univalence).
Lens≃ᴱTraditional-lens :
{A : Set a} {B : Set b} →
Block "conversion" →
@0 Univalence (a ⊔ b) →
@0 Is-set A →
Lens A B ≃ᴱ Traditionalᴱ.Lens A B
Lens≃ᴱTraditional-lens bc univ A-set =
Lens≃ᴱTraditional-lens.equiv A-set bc univ
-- The equivalence preserves getters and setters.
Lens≃ᴱTraditional-lens-preserves-getters-and-setters :
{A : Set a} {B : Set b}
(bc : Block "conversion")
(@0 univ : Univalence (a ⊔ b))
(@0 s : Is-set A) →
Preserves-getters-and-setters-⇔ A B
(_≃ᴱ_.logical-equivalence (Lens≃ᴱTraditional-lens bc univ s))
Lens≃ᴱTraditional-lens-preserves-getters-and-setters bc _ =
Lens↠Traditional-lens-preserves-getters-and-setters bc
-- If the codomain B is an inhabited set, then Lens A B and
-- Traditionalᴱ.Lens A B are logically equivalent.
--
-- This definition is inspired by the statement of Corollary 13 from
-- "Algebras and Update Strategies" by Johnson, Rosebrugh and Wood.
Lens⇔Traditional-lens :
@0 Is-set B →
B →
Lens A B ⇔ Traditionalᴱ.Lens A B
Lens⇔Traditional-lens {B = B} {A = A} B-set b₀ = record
{ to = Lens.traditional-lens
; from = from
}
where
from : Traditionalᴱ.Lens A B → Lens A B
from l = ≃ᴱ×→Lens
{R = ∃ λ (a : A) → Erased (get a ≡ b₀)}
(EEq.↔→≃ᴱ
(λ a → (set a b₀ , [ get-set a b₀ ]) , get a)
(λ ((a , _) , b) → set a b)
(λ ((a , [ h ]) , b) →
let lemma =
set (set a b) b₀ ≡⟨ set-set a b b₀ ⟩
set a b₀ ≡⟨ cong (set a) (sym h) ⟩
set a (get a) ≡⟨ set-get a ⟩∎
a ∎
in
( (set (set a b) b₀ , [ get-set (set a b) b₀ ])
, get (set a b)
) ≡⟨ cong₂ _,_ (Σ-≡,≡→≡ lemma (H-level-Erased 1 B-set _ _)) (get-set a b) ⟩∎
((a , [ h ]) , b) ∎)
(λ a →
set (set a b₀) (get a) ≡⟨ set-set a b₀ (get a) ⟩
set a (get a) ≡⟨ set-get a ⟩∎
a ∎))
where
open Traditionalᴱ.Lens l
-- The logical equivalence preserves getters and setters (in an erased
-- context).
@0 Lens⇔Traditional-lens-preserves-getters-and-setters :
{B : Set b}
(s : Is-set B)
(b₀ : B) →
Preserves-getters-and-setters-⇔ A B (Lens⇔Traditional-lens s b₀)
Lens⇔Traditional-lens-preserves-getters-and-setters _ b₀ =
(λ _ → refl _ , refl _)
, (λ l → refl _
, ⟨ext⟩ λ a → ⟨ext⟩ λ b →
set l (set l a b₀) b ≡⟨ set-set l _ _ _ ⟩∎
set l a b ∎)
where
open Traditionalᴱ.Lens
------------------------------------------------------------------------
-- Some results related to h-levels
-- If the domain of a lens is inhabited and has h-level n, then the
-- codomain also has h-level n (in erased contexts).
@0 h-level-respects-lens-from-inhabited :
Lens A B → A → H-level n A → H-level n B
h-level-respects-lens-from-inhabited l =
H.h-level-respects-lens-from-inhabited (high l)
-- This is not necessarily true for arbitrary domains (assuming
-- univalence).
¬-h-level-respects-lens :
@0 Univalence (a ⊔ b) →
¬ (∀ n {A : Set a} {B : Set b} →
Lens A B → H-level n A → H-level n B)
¬-h-level-respects-lens univ =
Stable-¬ _
[ (∀ n {A B} → Lens A B → H-level n A → H-level n B) ↝⟨ (λ hyp n l → hyp n (Higher-lens→Lens l)) ⟩
(∀ n {A B} → H.Lens A B → H-level n A → H-level n B) ↝⟨ H.¬-h-level-respects-lens univ ⟩□
⊥ □
]
-- In fact, there is a lens with a proposition as its domain and a
-- non-set as its codomain (assuming univalence).
lens-from-proposition-to-non-set :
@0 Univalence (# 0) →
∃ λ (A : Set a) → ∃ λ (B : Set b) →
Lens A B × Is-proposition A × ¬ Is-set B
lens-from-proposition-to-non-set {a = a} {b = b} univ =
⊥
, ↑ b 𝕊¹
, record
{ R = ⊥
; equiv = ⊥ ↔⟨ inverse ×-left-zero ⟩□
⊥ × ↑ _ 𝕊¹ □
; inhabited = ⊥-elim
}
, ⊥-propositional
, Stable-¬ _
[ Is-set (↑ b 𝕊¹) ↝⟨ proj₂ $ proj₂ $ proj₂ $ proj₂ $ H.lens-from-proposition-to-non-set {a = a} univ ⟩□
⊥₀ □
]
-- Lenses with contractible domains have contractible codomains (in
-- erased contexts).
@0 contractible-to-contractible :
Lens A B → Contractible A → Contractible B
contractible-to-contractible l =
H.contractible-to-contractible (high l)
-- A variant for Contractibleᴱ.
Contractibleᴱ→Contractibleᴱ :
Lens A B → Contractibleᴱ A → Contractibleᴱ B
Contractibleᴱ→Contractibleᴱ =
Traditionalᴱ.Contractibleᴱ→Contractibleᴱ ⊚
Lens.traditional-lens
-- If the domain type of a lens is contractible, then the remainder
-- type is also contractible (in erased contexts).
@0 domain-contractible⇒remainder-contractible :
(l : Lens A B) → Contractible A → Contractible (Lens.R l)
domain-contractible⇒remainder-contractible =
H.domain-contractible⇒remainder-contractible ⊚ high
-- A variant for Contractibleᴱ.
domain-Contractibleᴱ⇒remainder-Contractibleᴱ :
(l : Lens A B) → Contractibleᴱ A → Contractibleᴱ (Lens.R l)
domain-Contractibleᴱ⇒remainder-Contractibleᴱ {A = A} {B = B} l =
Contractibleᴱ A ↝⟨ EEq.Contractibleᴱ-respects-surjection
(_≃ᴱ_.to equiv) (_≃_.split-surjective (EEq.≃ᴱ→≃ equiv)) ⟩
Contractibleᴱ (R × B) ↝⟨ _≃ᴱ_.to (EEq.Contractibleᴱ-commutes-with-× ext) ⟩
Contractibleᴱ R × Contractibleᴱ B ↝⟨ proj₁ ⟩□
Contractibleᴱ R □
where
open Lens l
-- If the domain type of a lens has h-level n, then the remainder type
-- also has h-level n (in erased contexts).
@0 remainder-has-same-h-level-as-domain :
(l : Lens A B) → ∀ n → H-level n A → H-level n (Lens.R l)
remainder-has-same-h-level-as-domain l n =
H.remainder-has-same-h-level-as-domain (high l) n
-- If the getter function is an equivalence, then the remainder type
-- is propositional (in erased contexts).
@0 get-equivalence→remainder-propositional :
(l : Lens A B) →
Is-equivalence (Lens.get l) →
Is-proposition (Lens.R l)
get-equivalence→remainder-propositional =
H.get-equivalence→remainder-propositional ⊚ high
-- If the getter function is pointwise equal to the identity function,
-- then the remainder type is propositional (in erased contexts).
@0 get≡id→remainder-propositional :
(l : Lens A A) →
(∀ a → Lens.get l a ≡ a) →
Is-proposition (Lens.R l)
get≡id→remainder-propositional =
H.get≡id→remainder-propositional ⊚ high
-- It is not necessarily the case that contractibility of A implies
-- contractibility of Lens A B (assuming univalence).
¬-Contractible-closed-domain :
∀ {a b} →
@0 Univalence (a ⊔ b) →
¬ ({A : Set a} {B : Set b} →
Contractible A → Contractible (Lens A B))
¬-Contractible-closed-domain univ =
Stable-¬ _
[ (∀ {A B} → Contractible A → Contractible (Lens A B)) ↝⟨ (λ hyp c → H-level-cong _ 0 Lens≃Higher-lens (hyp c)) ⟩
(∀ {A B} → Contractible A → Contractible (H.Lens A B)) ↝⟨ H.¬-Contractible-closed-domain univ ⟩□
⊥ □
]
-- Contractibleᴱ is closed under Lens A (assuming univalence).
Contractibleᴱ-closed-codomain :
{A : Set a} {B : Set b} →
@0 Univalence (a ⊔ b) →
Contractibleᴱ B → Contractibleᴱ (Lens A B)
Contractibleᴱ-closed-codomain {A = A} {B} univ cB =
$⟨ lens-to-contractible≃ᴱ⊤ univ cB ⟩
Lens A B ≃ᴱ ⊤ ↝⟨ _⇔_.from EEq.Contractibleᴱ⇔≃ᴱ⊤ ⟩□
Contractibleᴱ (Lens A B) □
-- If B is a proposition, then Lens A B is also a proposition
-- (in erased contexts, assuming univalence).
@0 Is-proposition-closed-codomain :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
Is-proposition B → Is-proposition (Lens A B)
Is-proposition-closed-codomain {A = A} {B = B} univ =
Is-proposition B ↝⟨ H.Is-proposition-closed-codomain univ ⟩
Is-proposition (H.Lens A B) ↝⟨ H-level-cong _ 1 (inverse Lens≃Higher-lens) ⟩□
Is-proposition (Lens A B) □
-- If A is a proposition, then Lens A B is also a proposition
-- (in erased contexts, assuming univalence).
@0 Is-proposition-closed-domain :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
Is-proposition A → Is-proposition (Lens A B)
Is-proposition-closed-domain {A = A} {B = B} univ =
Is-proposition A ↝⟨ H.Is-proposition-closed-domain univ ⟩
Is-proposition (H.Lens A B) ↝⟨ H-level-cong _ 1 (inverse Lens≃Higher-lens) ⟩□
Is-proposition (Lens A B) □
-- If A is a set, then Lens A B is also a set (in erased contexts,
-- assuming univalence).
@0 Is-set-closed-domain :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
Is-set A → Is-set (Lens A B)
Is-set-closed-domain {A = A} {B = B} univ =
Is-set A ↝⟨ H.Is-set-closed-domain univ ⟩
Is-set (H.Lens A B) ↝⟨ H-level-cong _ 2 (inverse Lens≃Higher-lens) ⟩□
Is-set (Lens A B) □
-- If A has h-level n, then Lens A B has h-level 1 + n (in erased
-- contexts, assuming univalence).
@0 domain-0+⇒lens-1+ :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
∀ n → H-level n A → H-level (1 + n) (Lens A B)
domain-0+⇒lens-1+ {A = A} {B = B} univ n =
H-level n A ↝⟨ H.domain-0+⇒lens-1+ univ n ⟩
H-level (1 + n) (H.Lens A B) ↝⟨ H-level-cong _ (1 + n) (inverse Lens≃Higher-lens) ⟩□
H-level (1 + n) (Lens A B) □
-- If B is inhabited when it is merely inhabited and A has positive
-- h-level n, then Lens A B also has h-level n (in erased contexts,
-- assuming univalence).
@0 lens-preserves-h-level-of-domain :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
(∥ B ∥ → B) →
∀ n → H-level (1 + n) A → H-level (1 + n) (Lens A B)
lens-preserves-h-level-of-domain {A = A} {B = B} univ ∥B∥→B n =
H-level (1 + n) A ↝⟨ EP.higher-lens-preserves-h-level-of-domain univ ∥B∥→B n ⟩
H-level (1 + n) (H.Lens A B) ↝⟨ H-level-cong _ (1 + n) (inverse Lens≃Higher-lens) ⟩□
H-level (1 + n) (Lens A B) □
------------------------------------------------------------------------
-- An existence result
-- There is, in general, no lens for the first projection from a
-- Σ-type.
no-first-projection-lens :
∃ λ (A : Set a) → ∃ λ (B : A → Set b) →
¬ Lens (Σ A B) A
no-first-projection-lens =
Non-dependent.no-first-projection-lens
Lens contractible-to-contractible
------------------------------------------------------------------------
-- Some results related to the remainder type
-- The remainder type of a lens l : Lens A B is, for every b : B,
-- equivalent (with erased proofs) to the preimage (with an erased
-- proof) of the getter with respect to b.
--
-- The corresponding result in Lens.Non-dependent.Higher was pointed
-- out to me by Andrea Vezzosi.
remainder≃ᴱget⁻¹ᴱ :
(l : Lens A B) (b : B) → Lens.R l ≃ᴱ Lens.get l ⁻¹ᴱ b
remainder≃ᴱget⁻¹ᴱ l b = EEq.↔→≃ᴱ
(λ r → _≃ᴱ_.from equiv (r , b)
, [ get (_≃ᴱ_.from equiv (r , b)) ≡⟨⟩
proj₂ (_≃ᴱ_.to equiv (_≃ᴱ_.from equiv (r , b))) ≡⟨ cong proj₂ $ _≃ᴱ_.right-inverse-of equiv _ ⟩∎
b ∎
])
(λ (a , _) → remainder a)
(λ (a , [ get-a≡b ]) →
let lemma₁ =
cong get
(trans (cong (set a) (sym get-a≡b))
(_≃ᴱ_.left-inverse-of equiv _)) ≡⟨ cong-trans _ _ (_≃ᴱ_.left-inverse-of equiv _) ⟩
trans (cong get (cong (set a) (sym get-a≡b)))
(cong get (_≃ᴱ_.left-inverse-of equiv _)) ≡⟨ cong₂ trans
(cong-∘ _ _ (sym get-a≡b))
(sym $ cong-∘ _ _ (_≃ᴱ_.left-inverse-of equiv _)) ⟩
trans (cong (get ⊚ set a) (sym get-a≡b))
(cong proj₂ (cong (_≃ᴱ_.to equiv)
(_≃ᴱ_.left-inverse-of equiv _))) ≡⟨ cong₂ (λ p q → trans p (cong proj₂ q))
(cong-sym _ get-a≡b)
(_≃ᴱ_.left-right-lemma equiv _) ⟩
trans (sym (cong (get ⊚ set a) get-a≡b))
(cong proj₂ (_≃ᴱ_.right-inverse-of equiv _)) ≡⟨ sym $ sym-sym _ ⟩
sym (sym (trans (sym (cong (get ⊚ set a) get-a≡b))
(cong proj₂ (_≃ᴱ_.right-inverse-of equiv _)))) ≡⟨ cong sym $
sym-trans _ (cong proj₂ (_≃ᴱ_.right-inverse-of equiv _)) ⟩
sym (trans (sym (cong proj₂ (_≃ᴱ_.right-inverse-of equiv _)))
(sym (sym (cong (get ⊚ set a) get-a≡b)))) ≡⟨ cong (λ eq → sym (trans (sym (cong proj₂
(_≃ᴱ_.right-inverse-of equiv _)))
eq)) $
sym-sym (cong (get ⊚ set a) get-a≡b) ⟩∎
sym (trans (sym (cong proj₂ (_≃ᴱ_.right-inverse-of equiv _)))
(cong (get ⊚ set a) get-a≡b)) ∎
lemma₂ =
subst (λ a → get a ≡ b)
(trans (cong (set a) (sym get-a≡b)) (set-get a))
(cong proj₂ $ _≃ᴱ_.right-inverse-of equiv (remainder a , b)) ≡⟨⟩
subst (λ a → get a ≡ b)
(trans (cong (set a) (sym get-a≡b))
(_≃ᴱ_.left-inverse-of equiv _))
(cong proj₂ $ _≃ᴱ_.right-inverse-of equiv _) ≡⟨ subst-∘ _ _ (trans _ (_≃ᴱ_.left-inverse-of equiv _)) ⟩
subst (_≡ b)
(cong get
(trans (cong (set a) (sym get-a≡b))
(_≃ᴱ_.left-inverse-of equiv _)))
(cong proj₂ $ _≃ᴱ_.right-inverse-of equiv _) ≡⟨ cong (λ eq → subst (_≡ b) eq
(cong proj₂ $ _≃ᴱ_.right-inverse-of equiv _))
lemma₁ ⟩
subst (_≡ b)
(sym (trans (sym (cong proj₂ (_≃ᴱ_.right-inverse-of equiv _)))
(cong (get ⊚ set a) get-a≡b)))
(cong proj₂ $ _≃ᴱ_.right-inverse-of equiv _) ≡⟨ subst-trans (trans _ (cong (get ⊚ set a) get-a≡b)) ⟩
trans
(trans (sym (cong proj₂ (_≃ᴱ_.right-inverse-of equiv _)))
(cong (get ⊚ set a) get-a≡b))
(cong proj₂ $ _≃ᴱ_.right-inverse-of equiv _) ≡⟨ elim¹
(λ eq →
trans
(trans (sym (cong proj₂ (_≃ᴱ_.right-inverse-of equiv _)))
(cong (get ⊚ set a) eq))
(cong proj₂ $ _≃ᴱ_.right-inverse-of equiv _) ≡
eq)
(
trans
(trans (sym (cong proj₂ (_≃ᴱ_.right-inverse-of equiv _)))
(cong (get ⊚ set a) (refl _)))
(cong proj₂ $ _≃ᴱ_.right-inverse-of equiv _) ≡⟨ cong
(λ eq → trans
(trans (sym (cong proj₂
(_≃ᴱ_.right-inverse-of equiv _)))
eq)
(cong proj₂ $ _≃ᴱ_.right-inverse-of equiv _)) $
cong-refl _ ⟩
trans
(trans (sym (cong proj₂ (_≃ᴱ_.right-inverse-of equiv _)))
(refl _))
(cong proj₂ $ _≃ᴱ_.right-inverse-of equiv _) ≡⟨ cong (flip trans _) $ trans-reflʳ _ ⟩
trans (sym (cong proj₂ (_≃ᴱ_.right-inverse-of equiv _)))
(cong proj₂ $ _≃ᴱ_.right-inverse-of equiv _) ≡⟨ trans-symˡ (cong proj₂ (_≃ᴱ_.right-inverse-of equiv _)) ⟩∎
refl _ ∎)
get-a≡b ⟩∎
get-a≡b ∎
in
Σ-≡,≡→≡
(_≃ᴱ_.from equiv (remainder a , b) ≡⟨⟩
set a b ≡⟨ cong (set a) (sym get-a≡b) ⟩
set a (get a) ≡⟨ set-get a ⟩∎
a ∎)
(subst (λ a → Erased (get a ≡ b))
(trans (cong (set a) (sym get-a≡b)) (set-get a))
[ cong proj₂ $ _≃ᴱ_.right-inverse-of equiv (remainder a , b) ] ≡⟨ push-subst-[] ⟩
[ subst (λ a → get a ≡ b)
(trans (cong (set a) (sym get-a≡b)) (set-get a))
(cong proj₂ $ _≃ᴱ_.right-inverse-of equiv (remainder a , b))
] ≡⟨ []-cong [ lemma₂ ] ⟩∎
[ get-a≡b ] ∎))
(λ r →
remainder (_≃ᴱ_.from equiv (r , b)) ≡⟨⟩
proj₁ (_≃ᴱ_.to equiv (_≃ᴱ_.from equiv (r , b))) ≡⟨ cong proj₁ $ _≃ᴱ_.right-inverse-of equiv _ ⟩∎
r ∎)
where
open Lens l
-- A corollary: Lens.get l ⁻¹ᴱ_ is constant (up to _≃ᴱ_).
--
-- Paolo Capriotti discusses this kind of property
-- (http://homotopytypetheory.org/2014/04/29/higher-lenses/).
get⁻¹ᴱ-constant :
(l : Lens A B) (b₁ b₂ : B) → Lens.get l ⁻¹ᴱ b₁ ≃ᴱ Lens.get l ⁻¹ᴱ b₂
get⁻¹ᴱ-constant l b₁ b₂ =
Lens.get l ⁻¹ᴱ b₁ ↝⟨ inverse $ remainder≃ᴱget⁻¹ᴱ l b₁ ⟩
Lens.R l ↝⟨ remainder≃ᴱget⁻¹ᴱ l b₂ ⟩□
Lens.get l ⁻¹ᴱ b₂ □
-- The set function can be expressed using get⁻¹ᴱ-constant and get.
--
-- Paolo Capriotti defines set in a similar way
-- (http://homotopytypetheory.org/2014/04/29/higher-lenses/).
set-in-terms-of-get⁻¹ᴱ-constant :
(l : Lens A B) →
Lens.set l ≡
λ a b → proj₁ (_≃ᴱ_.to (get⁻¹ᴱ-constant l (Lens.get l a) b)
(a , [ refl _ ]))
set-in-terms-of-get⁻¹ᴱ-constant l = refl _
-- The remainder function can be expressed using remainder≃ᴱget⁻¹ᴱ and
-- get.
remainder-in-terms-of-remainder≃ᴱget⁻¹ᴱ :
(l : Lens A B) →
Lens.remainder l ≡
λ a → _≃ᴱ_.from (remainder≃ᴱget⁻¹ᴱ l (Lens.get l a)) (a , [ refl _ ])
remainder-in-terms-of-remainder≃ᴱget⁻¹ᴱ l = refl _
-- The lemma get⁻¹ᴱ-constant satisfies some coherence properties.
--
-- The first and third properties are discussed by Paolo Capriotti
-- (http://homotopytypetheory.org/2014/04/29/higher-lenses/).
@0 get⁻¹ᴱ-constant-∘ :
(l : Lens A B) (b₁ b₂ b₃ : B) (p : Lens.get l ⁻¹ᴱ b₁) →
_≃ᴱ_.to (get⁻¹ᴱ-constant l b₂ b₃)
(_≃ᴱ_.to (get⁻¹ᴱ-constant l b₁ b₂) p) ≡
_≃ᴱ_.to (get⁻¹ᴱ-constant l b₁ b₃) p
get⁻¹ᴱ-constant-∘ l _ b₂ b₃ p =
from (r₂ , b₃) , [ cong proj₂ (right-inverse-of (r₂ , b₃)) ] ≡⟨ cong (λ r → from (r , b₃) , [ cong proj₂ (right-inverse-of (r , b₃)) ]) $
cong proj₁ $ right-inverse-of _ ⟩∎
from (r₁ , b₃) , [ cong proj₂ (right-inverse-of (r₁ , b₃)) ] ∎
where
open Lens l
open _≃ᴱ_ equiv
r₁ r₂ : R
r₁ = proj₁ (to (proj₁ p))
r₂ = proj₁ (to (from (r₁ , b₂)))
get⁻¹ᴱ-constant-inverse :
(l : Lens A B) (b₁ b₂ : B) (p : Lens.get l ⁻¹ᴱ b₁) →
_≃ᴱ_.to (get⁻¹ᴱ-constant l b₁ b₂) p ≡
_≃ᴱ_.from (get⁻¹ᴱ-constant l b₂ b₁) p
get⁻¹ᴱ-constant-inverse _ _ _ _ = refl _
@0 get⁻¹ᴱ-constant-id :
(l : Lens A B) (b : B) (p : Lens.get l ⁻¹ᴱ b) →
_≃ᴱ_.to (get⁻¹ᴱ-constant l b b) p ≡ p
get⁻¹ᴱ-constant-id l b p =
_≃ᴱ_.to (get⁻¹ᴱ-constant l b b) p ≡⟨ sym $ get⁻¹ᴱ-constant-∘ l b _ _ p ⟩
_≃ᴱ_.to (get⁻¹ᴱ-constant l b b) (_≃ᴱ_.to (get⁻¹ᴱ-constant l b b) p) ≡⟨⟩
_≃ᴱ_.from (get⁻¹ᴱ-constant l b b) (_≃ᴱ_.to (get⁻¹ᴱ-constant l b b) p) ≡⟨ _≃ᴱ_.left-inverse-of (get⁻¹ᴱ-constant l b b) _ ⟩∎
p ∎
-- Another kind of coherence property does not hold for
-- get⁻¹ᴱ-constant.
--
-- This kind of property came up in a discussion with Andrea Vezzosi.
get⁻¹ᴱ-constant-not-coherent :
¬ ({A B : Set} (l : Lens A B) (b₁ b₂ : B)
(f : ∀ b → Lens.get l ⁻¹ᴱ b) →
_≃ᴱ_.to (get⁻¹ᴱ-constant l b₁ b₂) (f b₁) ≡ f b₂)
get⁻¹ᴱ-constant-not-coherent =
({A B : Set} (l : Lens A B) (b₁ b₂ : B)
(f : ∀ b → Lens.get l ⁻¹ᴱ b) →
_≃ᴱ_.to (get⁻¹ᴱ-constant l b₁ b₂) (f b₁) ≡ f b₂) ↝⟨ (λ hyp → hyp l true false f) ⟩
_≃ᴱ_.to (get⁻¹ᴱ-constant l true false) (f true) ≡ f false ↝⟨ cong (proj₁ ⊚ proj₁) ⟩
true ≡ false ↝⟨ Bool.true≢false ⟩□
⊥ □
where
l : Lens (Bool × Bool) Bool
l = record
{ R = Bool
; equiv = F.id
; inhabited = ∣_∣
}
f : ∀ b → Lens.get l ⁻¹ᴱ b
f b = (b , b) , [ refl _ ]
-- If B is inhabited whenever it is merely inhabited, then the
-- remainder type of a lens of type Lens A B can be expressed in terms
-- of preimages of the lens's getter (in erased contexts).
--
-- TODO: Perhaps a non-erased variant of this result could be proved
-- if the inhabited field were made non-erased, possibly with ∥_∥
-- replaced by ∥_∥ᴱ.
@0 remainder≃∃get⁻¹ :
(l : Lens A B) (∥B∥→B : ∥ B ∥ → B) →
Lens.R l ≃ ∃ λ (b : ∥ B ∥) → Lens.get l ⁻¹ (∥B∥→B b)
remainder≃∃get⁻¹ = H.remainder≃∃get⁻¹ ⊚ high
------------------------------------------------------------------------
-- Lens combinators
private
module HLC = H.Lens-combinators
module Lens-combinators where
-- The definition of the identity lens is unique (in erased
-- contexts), if the get function is required to be the identity
-- (assuming univalence).
@0 id-unique :
{A : Set a} →
Univalence a →
((l₁ , _) (l₂ , _) :
∃ λ (l : Lens A A) → ∀ a → Lens.get l a ≡ a) →
l₁ ≡ l₂
id-unique {A = A} univ (l₁ , g₁) (l₂ , g₂) =
$⟨ HLC.id-unique univ (high l₁ , g₁) (high l₂ , g₂) ⟩
high l₁ ≡ high l₂ ↝⟨ Eq.≃-≡ Lens≃Higher-lens {x = l₁} {y = l₂} ⟩□
l₁ ≡ l₂ □
-- The result of composing two lenses is unique (in erased contexts)
-- if the codomain type is inhabited whenever it is merely
-- inhabited, and we require that the resulting setter function is
-- defined in a certain way (assuming univalence).
@0 ∘-unique :
let open Lens in
{A : Set a} {C : Set c} →
Univalence (a ⊔ c) →
(∥ C ∥ → C) →
((comp₁ , _) (comp₂ , _) :
∃ λ (comp : Lens B C → Lens A B → Lens A C) →
∀ l₁ l₂ a c →
set (comp l₁ l₂) a c ≡ set l₂ a (set l₁ (get l₂ a) c)) →
comp₁ ≡ comp₂
∘-unique {A = A} {C = C} univ ∥C∥→C
(comp₁ , set₁) (comp₂ , set₂) =
⟨ext⟩ λ l₁ → ⟨ext⟩ λ l₂ →
lenses-equal-if-setters-equal univ
(comp₁ l₁ l₂) (comp₂ l₁ l₂) (λ _ → ∥C∥→C) $
⟨ext⟩ λ a → ⟨ext⟩ λ c →
set (comp₁ l₁ l₂) a c ≡⟨ set₁ _ _ _ _ ⟩
set l₂ a (set l₁ (get l₂ a) c) ≡⟨ sym $ set₂ _ _ _ _ ⟩∎
set (comp₂ l₁ l₂) a c ∎
where
open Lens
-- Identity lens.
id : Block "id" → Lens A A
id {A = A} ⊠ = record
{ R = Erased ∥ A ∥
; equiv = A ↔⟨ inverse Erased-∥∥×≃ ⟩□
Erased ∥ A ∥ × A □
; inhabited = erased
}
-- The identity lens is equal to the one obtained from the identity
-- lens for higher lenses without erased proofs (in erased
-- contexts, assuming univalence).
@0 Higher-lens-id≡id :
{A : Set a}
(b : Block "id")
(univ : Univalence a) →
Higher-lens→Lens (HLC.id b) ≡ id {A = A} b
Higher-lens-id≡id {A = A} ⊠ univ =
_↔_.from (equality-characterisation₂ univ)
( (∥ A ∥ ↔⟨ inverse $ erased Erased↔ ⟩□
Erased ∥ A ∥ □)
, λ _ → refl _
)
-- Composition of lenses.
--
-- Note that the domains are required to be at least as large as the
-- codomains.
--
-- The composition operation matches on the lenses to ensure that it
-- does not unfold when applied to neutral lenses.
infix 9 ⟨_,_⟩_∘_
⟨_,_⟩_∘_ :
∀ a b {A : Set (a ⊔ b ⊔ c)} {B : Set (b ⊔ c)} {C : Set c} →
Lens B C → Lens A B → Lens A C
⟨_,_⟩_∘_ _ _ {A = A} {B} {C} l₁@(⟨ _ , _ , _ ⟩) l₂@(⟨ _ , _ , _ ⟩) =
record
{ R = R l₂ × R l₁
; equiv = A ↝⟨ equiv l₂ ⟩
R l₂ × B ↝⟨ F.id ×-cong equiv l₁ ⟩
R l₂ × (R l₁ × C) ↔⟨ ×-assoc ⟩□
(R l₂ × R l₁) × C □
; inhabited = ∥∥-map (get l₁) ⊚ inhabited l₂ ⊚ proj₁
}
where
open Lens
-- Higher-lens→Lens commutes with composition (in erased contexts,
-- assuming univalence).
@0 Higher-lens-∘≡∘ :
∀ a b {A : Set (a ⊔ b ⊔ c)} {B : Set (b ⊔ c)} {C : Set c} →
Univalence (a ⊔ b ⊔ c) →
(l₁ : H.Lens B C) (l₂ : H.Lens A B) →
Higher-lens→Lens (HLC.⟨ a , b ⟩ l₁ ∘ l₂) ≡
⟨ a , b ⟩ Higher-lens→Lens l₁ ∘ Higher-lens→Lens l₂
Higher-lens-∘≡∘ _ _ univ (H.⟨ _ , _ , _ ⟩) (H.⟨ _ , _ , _ ⟩) =
_↔_.from (equality-characterisation₂ univ)
( F.id
, λ _ → refl _
)
-- A variant of composition for lenses between types with the same
-- universe level.
infixr 9 _∘_
_∘_ :
{A B C : Set a} →
Lens B C → Lens A B → Lens A C
l₁ ∘ l₂ = ⟨ lzero , lzero ⟩ l₁ ∘ l₂
-- Other definitions of composition match ⟨_,_⟩_∘_ (in erased
-- contexts), if the codomain type is inhabited whenever it is
-- merely inhabited, and the resulting setter function is defined in
-- a certain way (assuming univalence).
@0 composition≡∘ :
let open Lens in
{A : Set (a ⊔ b ⊔ c)} {B : Set (b ⊔ c)} {C : Set c} →
Univalence (a ⊔ b ⊔ c) →
(∥ C ∥ → C) →
(comp : Lens B C → Lens A B → Lens A C) →
(∀ l₁ l₂ a c →
set (comp l₁ l₂) a c ≡ set l₂ a (set l₁ (get l₂ a) c)) →
comp ≡ ⟨ a , b ⟩_∘_
composition≡∘ univ ∥C∥→C comp set-comp =
∘-unique univ ∥C∥→C (comp , set-comp)
(_ , λ { ⟨ _ , _ , _ ⟩ ⟨ _ , _ , _ ⟩ _ _ → refl _ })
-- Identity and composition form a kind of precategory (in erased
-- contexts, assuming univalence).
@0 associativity :
∀ a b c
{A : Set (a ⊔ b ⊔ c ⊔ d)} {B : Set (b ⊔ c ⊔ d)}
{C : Set (c ⊔ d)} {D : Set d} →
Univalence (a ⊔ b ⊔ c ⊔ d) →
(l₁ : Lens C D) (l₂ : Lens B C) (l₃ : Lens A B) →
⟨ a ⊔ b , c ⟩ l₁ ∘ (⟨ a , b ⟩ l₂ ∘ l₃) ≡
⟨ a , b ⊔ c ⟩ (⟨ b , c ⟩ l₁ ∘ l₂) ∘ l₃
associativity _ _ _ univ ⟨ _ , _ , _ ⟩ ⟨ _ , _ , _ ⟩ ⟨ _ , _ , _ ⟩ =
_↔_.from (equality-characterisation₂ univ)
(Eq.↔⇒≃ (inverse ×-assoc) , λ _ → refl _)
@0 left-identity :
∀ bi a {A : Set (a ⊔ b)} {B : Set b} →
Univalence (a ⊔ b) →
(l : Lens A B) →
⟨ a , lzero ⟩ id bi ∘ l ≡ l
left-identity ⊠ _ {B = B} univ l@(⟨ _ , _ , _ ⟩) =
_↔_.from (equality-characterisation₂ univ)
( (R × Erased ∥ B ∥ ↔⟨ lemma ⟩□
R □)
, λ _ → refl _
)
where
open Lens l
lemma : R × Erased ∥ B ∥ ↔ R
lemma = record
{ surjection = record
{ logical-equivalence = record
{ to = proj₁
; from = λ r → r , [ inhabited r ]
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = λ (r , _) →
cong (r ,_) $ []-cong [ truncation-is-proposition _ _ ]
}
@0 right-identity :
∀ bi a {A : Set (a ⊔ b)} {B : Set b} →
Univalence (a ⊔ b) →
(l : Lens A B) →
⟨ lzero , a ⟩ l ∘ id bi ≡ l
right-identity ⊠ _ {A = A} univ l@(⟨ _ , _ , _ ⟩) =
_↔_.from (equality-characterisation₂ univ)
( (Erased ∥ A ∥ × R ↔⟨ lemma ⟩□
R □)
, λ _ → refl _
)
where
open Lens l
lemma : Erased ∥ A ∥ × R ↔ R
lemma = record
{ surjection = record
{ logical-equivalence = record
{ to = proj₂
; from = λ r → [ ∥∥-map (λ b → _≃ᴱ_.from equiv (r , b))
(inhabited r)
]
, r
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = λ (_ , r) →
cong (_, r) $ []-cong [ truncation-is-proposition _ _ ]
}
open Lens-combinators
------------------------------------------------------------------------
-- Isomorphisms expressed using lens quasi-inverses
private
module B {a} (b : Block "id") =
Bi-invertibility.Erased equality-with-J (Set a) Lens (id b) _∘_
module BM {a} (b : Block "id") (@0 univ : Univalence a) = B.More
b
(left-identity b _ univ)
(right-identity b _ univ)
(associativity _ _ _ univ)
-- A form of isomorphism between types, expressed using lenses.
open B public renaming (_≅ᴱ_ to [_]_≅ᴱ_) using (Has-quasi-inverseᴱ)
private
-- Some lemmas used below.
@0 ∘≡id→∘≡id :
{A B : Set a}
(b : Block "id") →
Univalence a →
(l₁ : H.Lens B A) (l₂ : H.Lens A B) →
l₁ HLC.∘ l₂ ≡ HLC.id b →
Higher-lens→Lens l₁ ∘ Higher-lens→Lens l₂ ≡ id b
∘≡id→∘≡id b univ l₁ l₂ hyp =
Higher-lens→Lens l₁ ∘ Higher-lens→Lens l₂ ≡⟨ sym $ Higher-lens-∘≡∘ lzero lzero univ l₁ l₂ ⟩
Higher-lens→Lens (l₁ HLC.∘ l₂) ≡⟨ cong Higher-lens→Lens hyp ⟩
Higher-lens→Lens (HLC.id b) ≡⟨ Higher-lens-id≡id b univ ⟩∎
id b ∎
@0 l∘l⁻¹≡l∘l⁻¹ :
{A B : Set a} →
Univalence a →
(l : H.Lens B A) (l⁻¹ : Lens A B) →
Higher-lens→Lens (l HLC.∘ high l⁻¹) ≡ Higher-lens→Lens l ∘ l⁻¹
l∘l⁻¹≡l∘l⁻¹ univ l l⁻¹ =
Higher-lens→Lens (l HLC.∘ high l⁻¹) ≡⟨ Higher-lens-∘≡∘ lzero lzero univ l (high l⁻¹) ⟩
Higher-lens→Lens l ∘ Higher-lens→Lens (high l⁻¹) ≡⟨ cong (Higher-lens→Lens l ∘_) $
_≃_.left-inverse-of Lens≃Higher-lens l⁻¹ ⟩∎
Higher-lens→Lens l ∘ l⁻¹ ∎
@0 l⁻¹∘l≡l⁻¹∘l :
{A B : Set a} →
Univalence a →
(l⁻¹ : Lens B A) (l : H.Lens A B) →
Higher-lens→Lens (high l⁻¹ HLC.∘ l) ≡ l⁻¹ ∘ Higher-lens→Lens l
l⁻¹∘l≡l⁻¹∘l univ l⁻¹ l =
Higher-lens→Lens (high l⁻¹ HLC.∘ l) ≡⟨ Higher-lens-∘≡∘ lzero lzero univ (high l⁻¹) l ⟩
Higher-lens→Lens (high l⁻¹) ∘ Higher-lens→Lens l ≡⟨ cong (_∘ Higher-lens→Lens l) $
_≃_.left-inverse-of Lens≃Higher-lens l⁻¹ ⟩∎
l⁻¹ ∘ Higher-lens→Lens l ∎
-- H.Has-quasi-inverse b l implies
-- Has-quasi-inverseᴱ b (Higher-lens→Lens l) (assuming univalence).
Has-quasi-inverse→Has-quasi-inverseᴱ :
{A B : Set a}
(b : Block "id") →
@0 Univalence a →
(l : H.Lens A B) →
H.Has-quasi-inverse b l → Has-quasi-inverseᴱ b (Higher-lens→Lens l)
Has-quasi-inverse→Has-quasi-inverseᴱ {a = a} b univ l =
(∃ λ l⁻¹ → l HLC.∘ l⁻¹ ≡ HLC.id b × l⁻¹ HLC.∘ l ≡ HLC.id b ) ↝⟨ (Σ-map Higher-lens→Lens λ {l⁻¹} (p , q) →
[ ∘≡id→∘≡id b univ l l⁻¹ p
, ∘≡id→∘≡id b univ l⁻¹ l q
]) ⟩
(∃ λ l⁻¹ → Erased (l′ ∘ l⁻¹ ≡ id b × l⁻¹ ∘ l′ ≡ id b)) □
where
l′ = Higher-lens→Lens l
-- In erased contexts Has-quasi-inverseᴱ b (Higher-lens→Lens l) is
-- equivalent to H.Has-quasi-inverse b l (assuming univalence).
@0 Has-quasi-inverseᴱ≃Has-quasi-inverse :
{A B : Set a}
(b : Block "id") →
Univalence a →
(l : H.Lens A B) →
Has-quasi-inverseᴱ b (Higher-lens→Lens l) ≃ H.Has-quasi-inverse b l
Has-quasi-inverseᴱ≃Has-quasi-inverse b univ l =
(∃ λ l⁻¹ → Erased (l′ ∘ l⁻¹ ≡ id b × l⁻¹ ∘ l′ ≡ id b)) ↔⟨ (∃-cong λ _ → erased Erased↔) ⟩
(∃ λ l⁻¹ → l′ ∘ l⁻¹ ≡ id b × l⁻¹ ∘ l′ ≡ id b ) ↝⟨ (inverse $
Σ-cong-contra Lens≃Higher-lens λ l⁻¹ →
(≡⇒↝ _ (cong₂ _≡_ (l∘l⁻¹≡l∘l⁻¹ univ l l⁻¹)
(Higher-lens-id≡id b univ)) F.∘
inverse (Eq.≃-≡ $ inverse Lens≃Higher-lens))
×-cong
(≡⇒↝ _ (cong₂ _≡_ (l⁻¹∘l≡l⁻¹∘l univ l⁻¹ l)
(Higher-lens-id≡id b univ)) F.∘
inverse (Eq.≃-≡ $ inverse Lens≃Higher-lens))) ⟩□
(∃ λ l⁻¹ → l HLC.∘ l⁻¹ ≡ HLC.id b × l⁻¹ HLC.∘ l ≡ HLC.id b ) □
where
l′ = Higher-lens→Lens l
-- H.[ b ] A ≅ B implies [ b ] A ≅ᴱ B (assuming univalence).
≅→≅ᴱ :
{A B : Set a}
(b : Block "id") →
@0 Univalence a →
H.[ b ] A ≅ B → [ b ] A ≅ᴱ B
≅→≅ᴱ {A = A} {B = B} b univ =
(∃ λ (l : H.Lens A B) → H.Has-quasi-inverse b l) ↝⟨ (Σ-map Higher-lens→Lens λ {l} →
Has-quasi-inverse→Has-quasi-inverseᴱ b univ l) ⟩□
(∃ λ (l : Lens A B) → Has-quasi-inverseᴱ b l) □
-- In erased contexts [ b ] A ≅ᴱ B is equivalent to H.[ b ] A ≅ B
-- (assuming univalence).
@0 ≅ᴱ≃≅ :
{A B : Set a}
(b : Block "id") →
Univalence a →
([ b ] A ≅ᴱ B) ≃ (H.[ b ] A ≅ B)
≅ᴱ≃≅ {A = A} {B = B} b univ =
(∃ λ (l : Lens A B) → Has-quasi-inverseᴱ b l) ↝⟨ Σ-cong-contra (inverse Lens≃Higher-lens) $
Has-quasi-inverseᴱ≃Has-quasi-inverse b univ ⟩□
(∃ λ (l : H.Lens A B) → H.Has-quasi-inverse b l) □
-- Lenses with quasi-inverses can be converted to equivalences with
-- erased proofs.
≅ᴱ→≃ᴱ : ∀ b → [ b ] A ≅ᴱ B → A ≃ᴱ B
≅ᴱ→≃ᴱ
⊠
(l@(⟨ _ , _ , _ ⟩) , l⁻¹@(⟨ _ , _ , _ ⟩) , [ l∘l⁻¹≡id , l⁻¹∘l≡id ]) =
EEq.↔→≃ᴱ
(get l)
(get l⁻¹)
(λ b → cong (λ l → get l b) l∘l⁻¹≡id)
(λ a → cong (λ l → get l a) l⁻¹∘l≡id)
where
open Lens
-- There is a logical equivalence between [ b ] A ≅ᴱ B and A ≃ᴱ B
-- (assuming univalence).
≅ᴱ⇔≃ᴱ :
{A B : Set a}
(b : Block "id") →
@0 Univalence a →
([ b ] A ≅ᴱ B) ⇔ (A ≃ᴱ B)
≅ᴱ⇔≃ᴱ {A = A} {B = B} b univ = record
{ to = ≅ᴱ→≃ᴱ b
; from = from b
}
where
from : ∀ b → A ≃ᴱ B → [ b ] A ≅ᴱ B
from b A≃B = l , l⁻¹ , [ l∘l⁻¹≡id b , l⁻¹∘l≡id b ]
where
l = ≃ᴱ→Lens′ A≃B
l⁻¹ = ≃ᴱ→Lens′ (inverse A≃B)
@0 l∘l⁻¹≡id : ∀ b → l ∘ l⁻¹ ≡ id b
l∘l⁻¹≡id ⊠ = _↔_.from (equality-characterisation₂ univ)
( (Erased ∥ A ∥ × Erased ∥ B ∥ ↔⟨ inverse Erased-Σ↔Σ ⟩
Erased (∥ A ∥ × ∥ B ∥) ↔⟨ Erased-cong (
drop-⊤-left-× λ b →
inhabited⇒∥∥↔⊤ (∥∥-map (_≃ᴱ_.from A≃B) b)) ⟩□
Erased ∥ B ∥ □)
, λ _ → cong₂ _,_
([]-cong [ truncation-is-proposition _ _ ])
(_≃ᴱ_.right-inverse-of A≃B _)
)
@0 l⁻¹∘l≡id : ∀ b → l⁻¹ ∘ l ≡ id b
l⁻¹∘l≡id ⊠ = _↔_.from (equality-characterisation₂ univ)
( (Erased ∥ B ∥ × Erased ∥ A ∥ ↔⟨ inverse Erased-Σ↔Σ ⟩
Erased (∥ B ∥ × ∥ A ∥) ↔⟨ Erased-cong (
drop-⊤-left-× λ a →
inhabited⇒∥∥↔⊤ (∥∥-map (_≃ᴱ_.to A≃B) a)) ⟩
Erased ∥ A ∥ □)
, λ _ → cong₂ _,_
([]-cong [ truncation-is-proposition _ _ ])
(_≃ᴱ_.left-inverse-of A≃B _)
)
-- In erased contexts the right-to-left direction of ≅ᴱ⇔≃ᴱ is a right
-- inverse of the left-to-right direction.
@0 ≅ᴱ⇔≃ᴱ∘≅ᴱ⇔≃ᴱ :
{A B : Set a}
(b : Block "id")
(@0 univ : Univalence a)
(A≃B : A ≃ᴱ B) →
_⇔_.to (≅ᴱ⇔≃ᴱ b univ) (_⇔_.from (≅ᴱ⇔≃ᴱ b univ) A≃B) ≡ A≃B
≅ᴱ⇔≃ᴱ∘≅ᴱ⇔≃ᴱ ⊠ _ _ = EEq.to≡to→≡ ext (refl _)
-- There is not necessarily a split surjection from
-- Is-equivalenceᴱ (Lens.get l) to Has-quasi-inverseᴱ l, if l is a
-- lens between types in the same universe (assuming univalence).
¬Is-equivalenceᴱ-get↠Has-quasi-inverseᴱ :
(b : Block "id") →
Univalence a →
¬ ({A B : Set a}
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) ↠ Has-quasi-inverseᴱ b l)
¬Is-equivalenceᴱ-get↠Has-quasi-inverseᴱ {a = a} b univ =
Stable-¬ _
[ ({A B : Set a}
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) ↠ Has-quasi-inverseᴱ b l) ↝⟨ (λ hyp → lemma hyp) ⟩
({A B : Set a}
(l : H.Lens A B) →
Is-equivalence (H.Lens.get l) ↠ H.Has-quasi-inverse b l) ↝⟨ H.¬Is-equivalence-get↠Has-quasi-inverse b univ ⟩□
⊥ □
]
where
@0 lemma : ∀ {A B : Set a} _ (l : H.Lens A B) → _
lemma hyp l@(H.⟨ _ , _ , _ ⟩) =
Is-equivalence (Lens.get (Higher-lens→Lens l)) ↝⟨ EEq.Is-equivalence≃Is-equivalenceᴱ ext ⟩
Is-equivalenceᴱ (Lens.get (Higher-lens→Lens l)) ↝⟨ hyp (Higher-lens→Lens l) ⟩
Has-quasi-inverseᴱ b (Higher-lens→Lens l) ↔⟨ Has-quasi-inverseᴱ≃Has-quasi-inverse b univ l ⟩□
H.Has-quasi-inverse b l □
-- There is not necessarily an equivalence with erased proofs from
-- Is-equivalenceᴱ (Lens.get l) to Has-quasi-inverseᴱ l, if l is a
-- lens between types in the same universe (assuming univalence).
¬Is-equivalenceᴱ-get≃ᴱHas-quasi-inverseᴱ :
(b : Block "id") →
Univalence a →
¬ ({A B : Set a}
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) ≃ᴱ Has-quasi-inverseᴱ b l)
¬Is-equivalenceᴱ-get≃ᴱHas-quasi-inverseᴱ {a = a} b univ =
Stable-¬ _
[ ({A B : Set a}
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) ≃ᴱ Has-quasi-inverseᴱ b l) ↝⟨ (λ hyp l → _≃_.surjection $ EEq.≃ᴱ→≃ $ hyp l) ⟩
({A B : Set a}
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) ↠ Has-quasi-inverseᴱ b l) ↝⟨ ¬Is-equivalenceᴱ-get↠Has-quasi-inverseᴱ b univ ⟩□
⊥ □
]
-- See also ≃ᴱ≃ᴱ≅ᴱ below.
------------------------------------------------------------------------
-- Equivalences expressed using bi-invertibility for lenses
-- A form of equivalence between types, expressed using lenses.
open B public
renaming (_≊ᴱ_ to [_]_≊ᴱ_)
using (Has-left-inverseᴱ; Has-right-inverseᴱ; Is-bi-invertibleᴱ)
open BM public using (equality-characterisation-≊ᴱ)
-- H.Has-left-inverse b l implies
-- Has-left-inverseᴱ b (Higher-lens→Lens l) (assuming univalence).
Has-left-inverse→Has-left-inverseᴱ :
{A B : Set a}
(b : Block "id") →
@0 Univalence a →
(l : H.Lens A B) →
H.Has-left-inverse b l → Has-left-inverseᴱ b (Higher-lens→Lens l)
Has-left-inverse→Has-left-inverseᴱ b univ l =
(∃ λ l⁻¹ → l⁻¹ HLC.∘ l ≡ HLC.id b ) ↝⟨ (Σ-map Higher-lens→Lens λ {l⁻¹} eq →
[ ∘≡id→∘≡id b univ l⁻¹ l eq ]) ⟩□
(∃ λ l⁻¹ → Erased (l⁻¹ ∘ l′ ≡ id b)) □
where
l′ = Higher-lens→Lens l
-- In erased contexts Has-left-inverseᴱ b (Higher-lens→Lens l) is
-- equivalent to H.Has-left-inverse b l (assuming univalence).
@0 Has-left-inverseᴱ≃Has-left-inverse :
{A B : Set a}
(b : Block "id") →
Univalence a →
(l : H.Lens A B) →
Has-left-inverseᴱ b (Higher-lens→Lens l) ≃ H.Has-left-inverse b l
Has-left-inverseᴱ≃Has-left-inverse b univ l =
(∃ λ l⁻¹ → Erased (l⁻¹ ∘ l′ ≡ id b)) ↔⟨ (∃-cong λ _ → erased Erased↔) ⟩
(∃ λ l⁻¹ → l⁻¹ ∘ l′ ≡ id b ) ↝⟨ (inverse $
Σ-cong-contra Lens≃Higher-lens λ l⁻¹ →
≡⇒↝ _ (cong₂ _≡_ (l⁻¹∘l≡l⁻¹∘l univ l⁻¹ l)
(Higher-lens-id≡id b univ)) F.∘
inverse (Eq.≃-≡ $ inverse Lens≃Higher-lens)) ⟩□
(∃ λ l⁻¹ → l⁻¹ HLC.∘ l ≡ HLC.id b ) □
where
l′ = Higher-lens→Lens l
-- H.Has-right-inverse b l implies
-- Has-right-inverseᴱ b (Higher-lens→Lens l) (assuming univalence).
Has-right-inverse→Has-right-inverseᴱ :
{A B : Set a}
(b : Block "id") →
@0 Univalence a →
(l : H.Lens A B) →
H.Has-right-inverse b l → Has-right-inverseᴱ b (Higher-lens→Lens l)
Has-right-inverse→Has-right-inverseᴱ b univ l =
(∃ λ l⁻¹ → l HLC.∘ l⁻¹ ≡ HLC.id b ) ↝⟨ (Σ-map Higher-lens→Lens λ {l⁻¹} eq →
[ ∘≡id→∘≡id b univ l l⁻¹ eq ]) ⟩□
(∃ λ l⁻¹ → Erased (l′ ∘ l⁻¹ ≡ id b)) □
where
l′ = Higher-lens→Lens l
-- In erased contexts Has-right-inverseᴱ b (Higher-lens→Lens l) is
-- equivalent to H.Has-right-inverse b l (assuming univalence).
@0 Has-right-inverseᴱ≃Has-right-inverse :
{A B : Set a}
(b : Block "id") →
Univalence a →
(l : H.Lens A B) →
Has-right-inverseᴱ b (Higher-lens→Lens l) ≃ H.Has-right-inverse b l
Has-right-inverseᴱ≃Has-right-inverse b univ l =
(∃ λ l⁻¹ → Erased (l′ ∘ l⁻¹ ≡ id b)) ↔⟨ (∃-cong λ _ → erased Erased↔) ⟩
(∃ λ l⁻¹ → l′ ∘ l⁻¹ ≡ id b ) ↝⟨ (inverse $
Σ-cong-contra Lens≃Higher-lens λ l⁻¹ →
≡⇒↝ _ (cong₂ _≡_ (l∘l⁻¹≡l∘l⁻¹ univ l l⁻¹)
(Higher-lens-id≡id b univ)) F.∘
inverse (Eq.≃-≡ $ inverse Lens≃Higher-lens)) ⟩□
(∃ λ l⁻¹ → l HLC.∘ l⁻¹ ≡ HLC.id b ) □
where
l′ = Higher-lens→Lens l
-- H.Is-bi-invertible b l implies
-- Is-bi-invertibleᴱ b (Higher-lens→Lens l) (assuming univalence).
Is-bi-invertible→Is-bi-invertibleᴱ :
{A B : Set a}
(b : Block "id") →
@0 Univalence a →
(l : H.Lens A B) →
H.Is-bi-invertible b l → Is-bi-invertibleᴱ b (Higher-lens→Lens l)
Is-bi-invertible→Is-bi-invertibleᴱ b univ l =
H.Is-bi-invertible b l ↔⟨⟩
H.Has-left-inverse b l × H.Has-right-inverse b l ↝⟨ Σ-map (Has-left-inverse→Has-left-inverseᴱ b univ l)
(Has-right-inverse→Has-right-inverseᴱ b univ l) ⟩
Has-left-inverseᴱ b l′ × Has-right-inverseᴱ b l′ ↔⟨⟩
Is-bi-invertibleᴱ b l′ □
where
l′ = Higher-lens→Lens l
-- In erased contexts Is-bi-invertibleᴱ b (Higher-lens→Lens l) is
-- equivalent to H.Is-bi-invertible b l (assuming univalence).
@0 Is-bi-invertibleᴱ≃Is-bi-invertible :
{A B : Set a}
(b : Block "id") →
Univalence a →
(l : H.Lens A B) →
Is-bi-invertibleᴱ b (Higher-lens→Lens l) ≃ H.Is-bi-invertible b l
Is-bi-invertibleᴱ≃Is-bi-invertible b univ l =
Is-bi-invertibleᴱ b l′ ↔⟨⟩
Has-left-inverseᴱ b l′ × Has-right-inverseᴱ b l′ ↝⟨ Has-left-inverseᴱ≃Has-left-inverse b univ l
×-cong
Has-right-inverseᴱ≃Has-right-inverse b univ l ⟩
H.Has-left-inverse b l × H.Has-right-inverse b l ↔⟨⟩
H.Is-bi-invertible b l □
where
l′ = Higher-lens→Lens l
-- H.[ b ] A ≊ B implies [ b ] A ≊ᴱ B (assuming univalence).
≊→≊ᴱ :
{A B : Set a}
(b : Block "id") →
@0 Univalence a →
H.[ b ] A ≊ B → [ b ] A ≊ᴱ B
≊→≊ᴱ {A = A} {B = B} b univ =
(∃ λ (l : H.Lens A B) → H.Is-bi-invertible b l) ↝⟨ (Σ-map Higher-lens→Lens λ {l} →
Is-bi-invertible→Is-bi-invertibleᴱ b univ l) ⟩□
(∃ λ (l : Lens A B) → Is-bi-invertibleᴱ b l) □
-- In erased contexts [ b ] A ≊ᴱ B is equivalent to H.[ b ] A ≊ B
-- (assuming univalence).
@0 ≊ᴱ≃≊ :
{A B : Set a}
(b : Block "id") →
Univalence a →
([ b ] A ≊ᴱ B) ≃ (H.[ b ] A ≊ B)
≊ᴱ≃≊ {A = A} {B = B} b univ =
(∃ λ (l : Lens A B) → Is-bi-invertibleᴱ b l) ↝⟨ Σ-cong-contra (inverse Lens≃Higher-lens) $
Is-bi-invertibleᴱ≃Is-bi-invertible b univ ⟩□
(∃ λ (l : H.Lens A B) → H.Is-bi-invertible b l) □
-- Lenses with left inverses have propositional remainder types (in
-- erased contexts).
@0 Has-left-inverseᴱ→remainder-propositional :
(b : Block "id")
(l : Lens A B) →
Has-left-inverseᴱ b l →
Is-proposition (Lens.R l)
Has-left-inverseᴱ→remainder-propositional
⊠ l@(⟨ _ , _ , _ ⟩) (l⁻¹@(⟨ _ , _ , _ ⟩) , [ l⁻¹∘l≡id ]) =
$⟨ get≡id→remainder-propositional
(l⁻¹ ∘ l)
(λ a → cong (flip get a) l⁻¹∘l≡id) ⟩
Is-proposition (R (l⁻¹ ∘ l)) ↔⟨⟩
Is-proposition (R l × R l⁻¹) ↝⟨ H-level-×₁ (∥∥-map (remainder l⁻¹) ⊚ inhabited l) 1 ⟩□
Is-proposition (R l) □
where
open Lens
-- Lenses with right inverses have propositional remainder types (in
-- erased contexts).
@0 Has-right-inverseᴱ→remainder-propositional :
(b : Block "id")
(l : Lens A B) →
Has-right-inverseᴱ b l →
Is-proposition (Lens.R l)
Has-right-inverseᴱ→remainder-propositional
⊠ l@(⟨ _ , _ , _ ⟩) (l⁻¹@(⟨ _ , _ , _ ⟩) , [ l∘l⁻¹≡id ]) =
$⟨ get≡id→remainder-propositional
(l ∘ l⁻¹)
(λ a → cong (flip get a) l∘l⁻¹≡id) ⟩
Is-proposition (R (l ∘ l⁻¹)) ↔⟨⟩
Is-proposition (R l⁻¹ × R l) ↝⟨ H-level-×₂ (∥∥-map (remainder l⁻¹) ⊚ inhabited l) 1 ⟩□
Is-proposition (R l) □
where
open Lens
-- There is an equivalence with erased proofs between A ≃ᴱ B and
-- [ b ] A ≊ᴱ B (assuming univalence).
≃ᴱ≃ᴱ≊ᴱ :
{A B : Set a}
(b : Block "id") →
@0 Univalence a →
(A ≃ᴱ B) ≃ᴱ ([ b ] A ≊ᴱ B)
≃ᴱ≃ᴱ≊ᴱ {A = A} {B = B} b univ =
EEq.↔→≃ᴱ (to b) (from b) (to∘from b) (from∘to b)
where
open Lens
to : ∀ b → A ≃ᴱ B → [ b ] A ≊ᴱ B
to b = B.≅ᴱ→≊ᴱ b ⊚ _⇔_.from (≅ᴱ⇔≃ᴱ b univ)
from : ∀ b → [ b ] A ≊ᴱ B → A ≃ᴱ B
from b = _⇔_.to (≅ᴱ⇔≃ᴱ b univ) ⊚ _⇔_.from (BM.≅ᴱ⇔≊ᴱ b univ)
@0 to∘from : ∀ b A≊ᴱB → to b (from b A≊ᴱB) ≡ A≊ᴱB
to∘from b A≊ᴱB =
_≃_.from (equality-characterisation-≊ᴱ b univ _ _) $
_↔_.from (equality-characterisation₃ univ)
( ∥B∥≃R b A≊ᴱB
, lemma₁ b A≊ᴱB
, lemma₂ b A≊ᴱB
)
where
l′ : ∀ b (A≊ᴱB : [ b ] A ≊ᴱ B) → Lens A B
l′ b A≊ᴱB = proj₁ (to b (from b A≊ᴱB))
∥B∥≃R : ∀ b (A≊ᴱB@(l , _) : [ b ] A ≊ᴱ B) → Erased ∥ B ∥ ≃ R l
∥B∥≃R b (l , (l-inv@(l⁻¹ , _) , _)) = Eq.⇔→≃
(H-level-Erased 1 truncation-is-proposition)
R-prop
(PT.rec R-prop (remainder l ⊚ get l⁻¹) ⊚ erased)
(λ r → [ inhabited l r ])
where
R-prop = Has-left-inverseᴱ→remainder-propositional b l l-inv
lemma₁ :
∀ b (A≊ᴱB@(l , _) : [ b ] A ≊ᴱ B) a →
_≃_.to (∥B∥≃R b A≊ᴱB) (remainder (l′ b A≊ᴱB) a) ≡ remainder l a
lemma₁
⊠
( l@(⟨ _ , _ , _ ⟩)
, (l⁻¹@(⟨ _ , _ , _ ⟩) , [ l⁻¹∘l≡id ])
, (⟨ _ , _ , _ ⟩ , _)
) a =
remainder l (get l⁻¹ (get l a)) ≡⟨⟩
remainder l (get (l⁻¹ ∘ l) a) ≡⟨ cong (λ l′ → remainder l (get l′ a)) l⁻¹∘l≡id ⟩
remainder l (get (id ⊠) a) ≡⟨⟩
remainder l a ∎
lemma₂ :
∀ b (A≊ᴱB@(l , _) : [ b ] A ≊ᴱ B) a →
get (l′ b A≊ᴱB) a ≡ get l a
lemma₂ ⊠
(⟨ _ , _ , _ ⟩ , (⟨ _ , _ , _ ⟩ , _) , (⟨ _ , _ , _ ⟩ , _)) _ =
refl _
@0 from∘to :
∀ b A≃B →
_⇔_.to (≅ᴱ⇔≃ᴱ b univ) (_⇔_.from (BM.≅ᴱ⇔≊ᴱ b univ)
(B.≅ᴱ→≊ᴱ b (_⇔_.from (≅ᴱ⇔≃ᴱ b univ) A≃B))) ≡
A≃B
from∘to ⊠ _ = EEq.to≡to→≡ ext (refl _)
-- The right-to-left direction of ≃ᴱ≃ᴱ≊ᴱ maps bi-invertible lenses to
-- their getter functions.
to-from-≃ᴱ≃ᴱ≊ᴱ≡get :
(b : Block "id")
(@0 univ : Univalence a)
(A≊ᴱB@(l , _) : [ b ] A ≊ᴱ B) →
_≃ᴱ_.to (_≃ᴱ_.from (≃ᴱ≃ᴱ≊ᴱ b univ) A≊ᴱB) ≡ Lens.get l
to-from-≃ᴱ≃ᴱ≊ᴱ≡get
⊠ _ (⟨ _ , _ , _ ⟩ , (⟨ _ , _ , _ ⟩ , _) , (⟨ _ , _ , _ ⟩ , _)) =
refl _
-- A variant of ≃ᴱ≃ᴱ≊ᴱ that works even if A and B live in different
-- universes.
--
-- This kind of variant came up in a discussion with Andrea Vezzosi.
≃ᴱ≃ᴱ≊ᴱ′ :
{A : Set a} {B : Set b}
(b-id : Block "id") →
@0 Univalence (a ⊔ b) →
(A ≃ᴱ B) ≃ᴱ ([ b-id ] ↑ b A ≊ᴱ ↑ a B)
≃ᴱ≃ᴱ≊ᴱ′ {a = a} {b = b} {A = A} {B = B} b-id univ =
A ≃ᴱ B ↝⟨ inverse $ EEq.≃ᴱ-cong ext (from-isomorphism Bijection.↑↔)
(from-isomorphism Bijection.↑↔) ⟩
↑ b A ≃ᴱ ↑ a B ↝⟨ ≃ᴱ≃ᴱ≊ᴱ b-id univ ⟩□
[ b-id ] ↑ b A ≊ᴱ ↑ a B □
-- The right-to-left direction of ≃ᴱ≃ᴱ≊ᴱ′ maps bi-invertible lenses to a
-- variant of their getter functions.
to-from-≃ᴱ≃ᴱ≊ᴱ′≡get :
{A : Set a} {B : Set b}
(b-id : Block "id")
(univ : Univalence (a ⊔ b)) →
(A≊ᴱB@(l , _) : [ b-id ] ↑ b A ≊ᴱ ↑ a B) →
_≃ᴱ_.to (_≃ᴱ_.from (≃ᴱ≃ᴱ≊ᴱ′ b-id univ) A≊ᴱB) ≡
lower ⊚ Lens.get l ⊚ lift
to-from-≃ᴱ≃ᴱ≊ᴱ′≡get
⊠ _ (⟨ _ , _ , _ ⟩ , (⟨ _ , _ , _ ⟩ , _) , (⟨ _ , _ , _ ⟩ , _)) =
refl _
-- The getter function of a bi-invertible lens is an equivalence with
-- erased proofs (assuming univalence).
Is-bi-invertibleᴱ→Is-equivalenceᴱ-get :
{A : Set a}
(b : Block "id") →
@0 Univalence a →
(l : Lens A B) →
Is-bi-invertibleᴱ b l → Is-equivalenceᴱ (Lens.get l)
Is-bi-invertibleᴱ→Is-equivalenceᴱ-get
b@⊠ univ l@(⟨ _ , _ , _ ⟩)
is-bi-inv@((⟨ _ , _ , _ ⟩ , _) , (⟨ _ , _ , _ ⟩ , _)) =
_≃ᴱ_.is-equivalence (_≃ᴱ_.from (≃ᴱ≃ᴱ≊ᴱ b univ) (l , is-bi-inv))
-- If l is a lens between types in the same universe, then there is an
-- equivalence with erased proofs between "l is bi-invertible (with
-- erased proofs)" and "the getter of l is an equivalence (with erased
-- proofs)" (assuming univalence).
Is-bi-invertible≃Is-equivalence-get :
{A B : Set a}
(b : Block "id") →
@0 Univalence a →
(l : Lens A B) →
Is-bi-invertibleᴱ b l ≃ᴱ Is-equivalenceᴱ (Lens.get l)
Is-bi-invertible≃Is-equivalence-get b univ l = EEq.⇔→≃ᴱ
(BM.Is-bi-invertibleᴱ-propositional b univ l)
(EEq.Is-equivalenceᴱ-propositional ext _)
(Is-bi-invertibleᴱ→Is-equivalenceᴱ-get b univ l)
(λ is-equiv →
let l′ = ≃ᴱ→Lens′ EEq.⟨ get l , is-equiv ⟩ in
$⟨ proj₂ (_≃ᴱ_.to (≃ᴱ≃ᴱ≊ᴱ b univ) EEq.⟨ _ , is-equiv ⟩) ⟩
Is-bi-invertibleᴱ b l′ ↝⟨ subst (λ ([ l ]) → Is-bi-invertibleᴱ b l) $ sym $
[]-cong [ get-equivalence→≡≃ᴱ→Lens′ univ l is-equiv ] ⟩□
Is-bi-invertibleᴱ b l □)
where
open Lens
-- If A is a set, then there is an equivalence with erased proofs
-- between [ b ] A ≊ᴱ B and [ b ] A ≅ᴱ B (assuming univalence).
≊ᴱ≃ᴱ≅ᴱ :
{A B : Set a}
(b : Block "id") →
@0 Univalence a →
@0 Is-set A →
([ b ] A ≊ᴱ B) ≃ᴱ ([ b ] A ≅ᴱ B)
≊ᴱ≃ᴱ≅ᴱ b univ A-set =
∃-cong λ _ →
BM.Is-bi-invertibleᴱ≃ᴱHas-quasi-inverseᴱ-domain
b univ
(Is-set-closed-domain univ A-set)
-- If A is a set, then there is an equivalence with erased proofs between A ≃ᴱ B and
-- [ b ] A ≅ᴱ B (assuming univalence).
≃ᴱ≃ᴱ≅ᴱ :
{A B : Set a}
(b : Block "≃ᴱ≃ᴱ≅ᴱ") →
@0 Univalence a →
@0 Is-set A →
(A ≃ᴱ B) ≃ᴱ ([ b ] A ≅ᴱ B)
≃ᴱ≃ᴱ≅ᴱ {A = A} {B = B} b@⊠ univ A-set =
A ≃ᴱ B ↝⟨ ≃ᴱ≃ᴱ≊ᴱ b univ ⟩
[ b ] A ≊ᴱ B ↝⟨ ≊ᴱ≃ᴱ≅ᴱ b univ A-set ⟩□
[ b ] A ≅ᴱ B □
-- In erased contexts one can prove that ≃ᴱ≃ᴱ≅ᴱ maps identity to
-- identity.
@0 ≃ᴱ≃ᴱ≅ᴱ-id≡id :
{A : Set a}
(b : Block "≃ᴱ≃ᴱ≅ᴱ")
(univ : Univalence a)
(A-set : Is-set A) →
proj₁ (_≃ᴱ_.to (≃ᴱ≃ᴱ≅ᴱ b univ A-set) F.id) ≡ id b
≃ᴱ≃ᴱ≅ᴱ-id≡id ⊠ univ _ =
_↔_.from (equality-characterisation₂ univ)
(F.id , λ _ → refl _)
|
"""Create a `storage` array for [`propagate`](@ref).
```julia
storage = init_storage(state, tlist)
```
creates a storage array suitable for storing a `state` for each point in
`tlist`.
```julia
storage = init_storage(state, tlist, observables))
```
creates a storage array suitable for the data generated by the `observables`
applied to `state`, see [`map_observables`](@ref), for each point in `tlist`.
```julia
storage = init_storage(data, nt))
```
creates a storage arrays suitable for storing `data` nt times, where
`nt=length(tlist)`. By default, this will be a vector of `typeof(data)` and
length `nt`, or a `n × nt` Matrix with the same `eltype` as `data` if `data` is
a Vector of length `n`.
"""
function init_storage(state, tlist::AbstractVector)
nt = length(tlist)
return init_storage(state, nt)
end
function init_storage(state, tlist, observables)
data = map_observables(observables, state)
nt = length(tlist)
return init_storage(data, nt)
end
init_storage(data, nt::Integer) = Vector{typeof(data)}(undef, nt)
init_storage(data::Vector, nt::Integer) = Matrix{eltype(data)}(undef, length(data), nt)
"""Obtain "observable" data from `state`.
```julia
data = map_observables(observables, state)
```
calculates the data for a tuple of `observables` applied to `state`.
For a single observable (tuple of length 1), simply return the result of
[`map_observable`](@ref).
For multiple observables, return the tuple resulting from applying
[`map_observable`](@ref) for each observable. If the tuple is "uniform" (all
elements are of the same type, e.g. if each observable calculates the
expectation value of a Hermitian operator), it is converted to a Vector. This
allows for compact storage in a storage array, see [`init_storage`](@ref).
"""
function map_observables(observables, state)
if length(observables) == 1
return map_observable(observables[1], state)
else
val_tuple = Tuple(map_observable(O, state) for O in observables)
uniform_type = typeof(val_tuple[1])
is_uniform = all(typeof(v) == uniform_type for v in val_tuple[2:end])
if is_uniform
return collect(val_tuple) # convert to Vector
else
return val_tuple
end
end
end
"""Apply a single `observable` to `state`.
```julia
data = map_observable(observable, state)
```
By default, `observable` is assumed to be callable, and the above is equivalent
to `data = observable(state)`.
If `observable` is a matrix and `state` is a vector evaluate the expectation
value of the observable as `dot(state, observable, state)`.
"""
function map_observable(observable, state)
return observable(state)
end
function map_observable(observable::AbstractMatrix, state::AbstractVector)
return dot(state, observable, state)
end
"""Place data into `storage` for time slot `i`.
```julia
write_to_storage!(storage, i, state, observables)
```
For a `storage` array created by [`init_storage`](@ref), store the data obtains
from [`map_observables`](@ref) into the `storage` for time slot `i`. This
delegates to the more general
```julia
write_to_storage!(storage, i, data)
```
Conceptually, this corresponds roughly to `storage[i] = data`, but `storage`
may have its own idea on how to store data for a specific time slot. For
example, with the default [`init_storage`](@ref) Vector data will be stored in
a matrix, and `write_to_storage!` will in this case write data to the i'th
column of the matrix.
For a given type of `storage` and `data`, it is the developer's responsibility
that `init_storage` and `write_to_storage!` are compatible.
"""
function write_to_storage!(storage, i::Integer, state, observables)
data = map_observables(observables, state)
write_to_storage!(storage, i, data)
end
function write_to_storage!(storage::AbstractVector, i::Integer, data)
storage[i] = data
end
function write_to_storage!(storage::Matrix{T}, i::Integer, data::Vector{T}) where T
storage[:, i] .= data
end
"""Obtain data from storage
```julia
get_from_storage!(state, storage, i)
```
extracts data from the `storage` for the i'th time slot. Invese of
[`write_to_storage!`](@ref)
"""
get_from_storage!(state, storage::AbstractVector, i) = copyto!(state, storage[i])
get_from_storage!(state, storage::Matrix, i) = copyto!(state, storage[:, i])
|
\name{subset_matrix_by_row}
\alias{subset_matrix_by_row}
\title{
Subset the Matrix by Rows
}
\description{
Subset the Matrix by Rows
}
\usage{
subset_matrix_by_row(x, i)
}
\arguments{
\item{x}{A matrix.}
\item{i}{The row indices.}
}
\details{
Mainly used for constructing the \code{\link{AnnotationFunction-class}} object.
}
\examples{
# There is no example
NULL
}
|
function [rtk,sat_,stat]=estpos(rtk,obs,nav,sv,opt)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%estimate reciever position and clock bias
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
global glc
NX=3+glc.NSYS; MAXITER=10; iter=1;
time=obs(1).time; xr0=[rtk.sol.pos';zeros(glc.NSYS,1)];
while iter<=MAXITER
% compute residual,measurement model,weight matrix
[v,H,P,vsat,azel,resp,nv,ns]=rescode(iter,obs,nav,sv,xr0,opt);
sat_.vsat=vsat;
sat_.azel=azel;
sat_.resp=resp;
if nv<NX, stat=0;return;end
% least square algrithm
[dx,Q]=least_square(v,H,P);
xr0=xr0+dx;
iter=iter+1;
if dot(dx,dx)<1e-4
rtk.sol.time=timeadd(obs(1).time,-xr0(4)/glc.CLIGHT);
rtk.sol.ns =ns;
rtk.sol.ratio=0;
rtk.sol.pos =xr0(1:3)';
rtk.sol.vel =zeros(1,3);
rtk.sol.posP(1)=Q(1,1);rtk.sol.posP(2)=Q(2,2);rtk.sol.posP(3)=Q(3,3);
rtk.sol.posP(4)=Q(1,2);rtk.sol.posP(5)=Q(2,3);rtk.sol.posP(6)=Q(1,3);
rtk.sol.dtr(1) =xr0(4)/glc.CLIGHT;
rtk.sol.dtr(2) =xr0(5)/glc.CLIGHT;
rtk.sol.dtr(3) =xr0(6)/glc.CLIGHT;
rtk.sol.dtr(4) =xr0(7)/glc.CLIGHT;
rtk.sol.dtr(5) =xr0(8)/glc.CLIGHT;
% validate solution
stat=valsol(time,v,P,vsat,azel,opt);
if stat==1
rtk.sol.stat=glc.SOLQ_SPP; return;
end
return;
end
end
if iter>MAXITER
stat=0;
[week,sow]=time2gpst(time);
fprintf('Warning:GPS week = %d sow = %.3f,SPP iteration divergent!\n',week,sow);
return;
end
return
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.