Built with Alectryon, running Coq+SerAPI v8.13.0+0.13.0. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑Ctrl+↓ to navigate, Ctrl+🖱️ to focus. On Mac, use ⌘ instead of Ctrl.
Notation"[ rel _ _ | _ ]" was already used in scope
fun_scope. [notation-overridden,parsing]
Notation"[ rel _ _ : _ | _ ]" was already used in
scope fun_scope. [notation-overridden,parsing]
Notation"[ rel _ _ in _ & _ | _ ]" was already used
in scope fun_scope. [notation-overridden,parsing]
Notation"[ rel _ _ in _ & _ ]" was already used in
scope fun_scope. [notation-overridden,parsing]
Notation"[ rel _ _ in _ | _ ]" was already used in
scope fun_scope. [notation-overridden,parsing]
Notation"[ rel _ _ in _ ]" was already used in scope
fun_scope. [notation-overridden,parsing]
Notation"_ + _" was already used in scope nat_scope.
[notation-overridden,parsing]
Notation"_ - _" was already used in scope nat_scope.
[notation-overridden,parsing]
Notation"_ <= _" was already used in scope nat_scope.
[notation-overridden,parsing]
Notation"_ < _" was already used in scope nat_scope.
[notation-overridden,parsing]
Notation"_ >= _" was already used in scope nat_scope.
[notation-overridden,parsing]
Notation"_ > _" was already used in scope nat_scope.
[notation-overridden,parsing]
Notation"_ <= _ <= _" was already used in scope
nat_scope. [notation-overridden,parsing]
Notation"_ < _ <= _" was already used in scope
nat_scope. [notation-overridden,parsing]
Notation"_ <= _ < _" was already used in scope
nat_scope. [notation-overridden,parsing]
Notation"_ < _ < _" was already used in scope
nat_scope. [notation-overridden,parsing]
Notation"_ * _" was already used in scope nat_scope.
[notation-overridden,parsing]
Set Implicit Arguments.Unset Strict Implicit.(******************************************************************************)(* *)(* Extra theorems and definitions *)(* *)(******************************************************************************)(******************************************************************************)(* *)(* Extra theorems about lists *)(* *)(******************************************************************************)
A:Type
a:seq A
injective (rcons a)
2
byelim: a => /= [s1 s2 /= [] | b l IH s1 s2 [] /IH].Qed.
5
a:A
injective (rcons^~ a)
a
5
a, b:A
s1:seq A
IH:forallx2 : seq A,
rcons s1 a = rcons x2 a -> s1 = x2
IH:a \in l ->
existsl1l2 : seq A, l = l1 ++ a :: l2
existsl1l2 : seq A, a :: l = l1 ++ a :: l2
2f142737
aIl:a \in l
existsl1l2 : seq A, b :: l = l1 ++ a :: l2
3b3d
2f1427373c
l1, l2:seq A
lE:l = l1 ++ a :: l2
3d
byexists (b :: l1); existsl2; rewrite /= lE.Qed.
2f27
P:pred A
~~ all [predC P] l ->
{bl1l2 : A * seq A * seq A
| [/\ all [predC P] bl1l2.1.2, P bl1l2.1.1
& l = bl1l2.1.2 ++ bl1l2.1.1 :: bl1l2.2]}
48
2f4b2627
IH:~~ all [predC P] l ->
{bl1l2 : A * seq A * seq A
| [/\ all [predC P] bl1l2.1.2, P bl1l2.1.1
& l = bl1l2.1.2 ++ bl1l2.1.1 :: bl1l2.2]}
~~ ((b \notin P) && all [predC P] l) ->
{bl1l2 : A * seq A * seq A
| [/\ all [predC P] bl1l2.1.2, P bl1l2.1.1
& b :: l = bl1l2.1.2 ++ bl1l2.1.1 :: bl1l2.2]}
2f4b262752
bIP:b \in P
{bl1l2 : A * seq A * seq A
| [/\ all [predC P] bl1l2.1.2, P bl1l2.1.1
& b :: l = bl1l2.1.2 ++ bl1l2.1.1 :: bl1l2.2]}
2f4b262752
bNIP:b \notin P
c:A
45
H1:all [predC P] (c, l1, l2).1.2
H2:P (c, l1, l2).1.1
{bl1l2 : A * seq A * seq A
| [/\ all [predC P] bl1l2.1.2, P bl1l2.1.1
& b
:: (c, l1, l2).1.2 ++
(c, l1, l2).1.1 :: (c, l1, l2).2 =
bl1l2.1.2 ++ bl1l2.1.1 :: bl1l2.2]}
5c61
byexists (c, b :: l1, l2); split; rewrite /= ?bNIP.Qed.
4a
~~ all [predC P] l ->
{bl1l2 : A * seq A * seq A
| [/\ P bl1l2.1.1, all [predC P] bl1l2.2
& l = bl1l2.1.2 ++ bl1l2.1.1 :: bl1l2.2]}
66
2f274b
lA:~~ all [predC P] l
{bl1l2 : A * seq A * seq A
| [/\ P bl1l2.1.1, all [predC P] bl1l2.2
& l = bl1l2.1.2 ++ bl1l2.1.1 :: bl1l2.2]}
6d
forallx : A * seq A * seq A,
[/\ all [predC P] x.1.2, P x.1.1
& rev l = x.1.2 ++ x.1.1 :: x.2] ->
{bl1l2 : A * seq A * seq A
| [/\ P bl1l2.1.1, all [predC P] bl1l2.2
& l = bl1l2.1.2 ++ bl1l2.1.1 :: bl1l2.2]}
l1 ++ a :: l2 = l3 ++ b :: l4 ->
[\/ [/\ l1 = l3, a = b & l2 = l4],
existsl5 : seq A, l3 = l1 ++ a :: l5
| existsl5 : seq A, l1 = l3 ++ b :: l5]
80
2f14
l2, l4:seq A
[\/ [/\ [::] = [::], a = a & l2 = l2],
existsl5 : seq A, [::] = a :: l5
| existsl5 : seq A, [::] = a :: l5]
2f148a5e
l3:seq A
[\/ [/\ [::] = a :: l3, a = b & l3 ++ b :: l4 = l4],
existsl5 : seq A, a :: l3 = a :: l5
| existsl5 : seq A, [::] = a :: l3 ++ b :: l5]
2f148a5e
l1:seq A
IH:foralll3 : seq A,
l1 ++ a :: l2 = l3 ++ b :: l4 ->
[\/ [/\ l1 = l3, a = b & l2 = l4],
existsl5 : seq A, l3 = l1 ++ a :: l5
| existsl5 : seq A, l1 = l3 ++ b :: l5]
[\/ [/\ c :: l1 = [::], a = c & l2 = l1 ++ a :: l2],
existsl5 : seq A, [::] = c :: l1 ++ a :: l5
| existsl5 : seq A, c :: l1 = [::] ++ c :: l5]
2f148a5e9394
d:A
8f
l1 ++ a :: l2 = l3 ++ b :: l4 ->
[\/ [/\ c :: l1 = c :: l3, a = b & l2 = l4],
existsl5 : seq A, c :: l3 = c :: l1 ++ a :: l5
| existsl5 : seq A, c :: l1 = c :: l3 ++ b :: l5]
87
8e90
9196
9c
9295
96
a1
9799
97
[\/ [/\ c :: l1 = c :: l1, a = a & l2 = l2],
existsl5 : seq A, c :: l1 = c :: l1 ++ a :: l5
| existsl5 : seq A, c :: l1 = c :: l1 ++ a :: l5]
2f148a5e939498
l3, l5:seq A
[\/ [/\ c :: l1 = c :: l1 ++ a :: l5, a = b & l2 = l4],
existsl6 : seq A,
c :: l1 ++ a :: l5 = c :: l1 ++ a :: l6
| existsl6 : seq A,
c :: l1 = c :: (l1 ++ a :: l5) ++ b :: l6]
97
(existsl5 : seq A, l1 = l3 ++ b :: l5) ->
[\/ [/\ c :: l1 = c :: l3, a = b & l2 = l4],
existsl5 : seq A, c :: l3 = c :: l1 ++ a :: l5
| existsl5 : seq A, c :: l1 = c :: l3 ++ b :: l5]
a9
aeb0
b1
b5
97b2
bycase=> l5 ->; apply: Or33; existsl5.Qed.
82
l1 ++ a :: l2 = l3 ++ b :: l4 ->
[\/ [/\ l1 = l3, a = b & l2 = l4],
existsl5 : seq A, l4 = l5 ++ a :: l2
| existsl5 : seq A, l2 = l5 ++ b :: l4]
bd
2f14
l1, l3, l4:seq A
l1 ++ [:: a] = l3 ++ b :: l4 ->
[\/ [/\ l1 = l3, a = b & [::] = l4],
existsl5 : seq A, l4 = l5 ++ [:: a]
| existsl5 : seq A, [::] = l5 ++ b :: l4]
2f14
l1, l3, l2:seq A
5e
IH:foralll4 : seq A,
l1 ++ a :: l2 = l3 ++ b :: l4 ->
[\/ [/\ l1 = l3, a = b & l2 = l4],
existsl5 : seq A, l4 = l5 ++ a :: l2
| existsl5 : seq A, l2 = l5 ++ b :: l4]
l4:seq A
l1 ++ a :: rcons l2 c = l3 ++ b :: l4 ->
[\/ [/\ l1 = l3, a = b & rcons l2 c = l4],
existsl5 : seq A, l4 = l5 ++ a :: rcons l2 c
| existsl5 : seq A, rcons l2 c = l5 ++ b :: l4]
l1 ++ [:: a] = l3 ++ b :: rcons l5 c ->
[\/ [/\ l1 = l3, a = b & [::] = rcons l5 c],
existsl6 : seq A, rcons l5 c = l6 ++ [:: a]
| existsl6 : seq A, [::] = l6 ++ b :: rcons l5 c]
c8
c4
[\/ [/\ l1 = l1, a = a & [::] = [::]],
existsl5 : seq A, [::] = l5 ++ [:: a]
| existsl5 : seq A, [::] = l5 ++ [:: a]]
d2
d4d6
c7
d4
[\/ [/\ l3 ++ b :: l5 = l3, a = b & [::] = rcons l5 a],
existsl6 : seq A, rcons l5 a = l6 ++ [:: a]
| existsl6 : seq A, [::] = l6 ++ rcons (b :: l5) a]
c7
c9cd
c9
l1 ++ a :: rcons l2 c = l3 ++ [:: b] ->
[\/ [/\ l1 = l3, a = b & rcons l2 c = [::]],
existsl5 : seq A, [::] = l5 ++ a :: rcons l2 c
| existsl5 : seq A, rcons l2 c = l5 ++ [:: b]]
2f14ca5ecb
l4, l5:seq A
98
l1 ++ a :: rcons l2 c = l3 ++ b :: rcons l5 d ->
[\/ [/\ l1 = l3, a = b & rcons l2 c = rcons l5 d],
existsl6 : seq A,
rcons l5 d = l6 ++ a :: rcons l2 c
| existsl6 : seq A,
rcons l2 c = l6 ++ b :: rcons l5 d]
c9
[\/ [/\ l1 = l1 ++ a :: l2, a = b & rcons l2 b = [::]],
existsl5 : seq A, [::] = l5 ++ rcons (a :: l2) b
| existsl5 : seq A, rcons l2 b = l5 ++ [:: b]]
e9
ebed
eb
[\/ [/\ l1 = l1, a = a & rcons l2 c = rcons l2 c],
existsl5 : seq A,
rcons l2 c = l5 ++ rcons (a :: l2) c
| existsl5 : seq A,
rcons l2 c = l5 ++ rcons (a :: l2) c]
2f14ca5ecbec98
l6:seq A
[\/ [/\ l1 = l3, a = b
& rcons l2 c = rcons (l6 ++ a :: l2) c],
existsl5 : seq A,
rcons (l6 ++ a :: l2) c =
l5 ++ rcons (a :: l2) c
| existsl5 : seq A,
rcons l2 c = l5 ++ rcons (b :: l6 ++ a :: l2) c]
fb
[\/ [/\ l1 = l3, a = b
& rcons (l6 ++ b :: l5) c = rcons l5 c],
existsl7 : seq A,
rcons l5 c = l7 ++ rcons (a :: l6 ++ b :: l5) c
| existsl7 : seq A,
rcons (l6 ++ b :: l5) c =
l7 ++ rcons (b :: l5) c]
f6
fbfd
fe
102
fbff
byapply: Or33; existsl6; rewrite -rcons_cat.Qed.(******************************************************************************)(* We develop a twisted version of split that fills 'I_{m + n} with *)(* first the element of 'I_n (x -> x) then the element of m (x -> x + n) *)(* This is mostly motivated to naturally get an element of 'I_n from 'I_n.+1 *)(* by removing max_ord *)(******************************************************************************)
m, n:nat
i:'I_m
i + n < m + n
10a
byrewrite ltn_add2r.Qed.
10d
i:'I_n
i < m + n
112
byapply: leq_trans (valP i) _; apply: leq_addl.Qed.Definitiontlshiftmn (i : 'I_m) := Ordinal (tlshift_subproof n i).Definitiontrshiftmn (i : 'I_n) := Ordinal (trshift_subproof m i).
bymove/subSn <-; rewrite leq_subLR [n + m]addnC.Qed.Definitiontsplit {mn} (i : 'I_(m + n)) : 'I_m + 'I_n :=
match ltnP (i) n with
| LtnNotGeq lt_i_n => inr _ (Ordinal lt_i_n)
| GeqNotLtn ge_i_n => inl _ (Ordinal (tsplit_subproof ge_i_n))
end.Varianttsplit_specmn (i : 'I_(m + n)) : 'I_m + 'I_n -> bool -> Type :=
| TSplitLo (j : 'I_n) of i = j :> nat : tsplit_spec i (inr _ j) true
| TSplitHi (k : 'I_m) of i = k + n :> nat : tsplit_spec i (inl _ k) false.
12d
tsplit_spec i (tsplit i) (i < n)
132
10d12e
lt_i_n:=i < n:bool
tsplit_spec i
match ltnP i n with
| LtnNotGeq lt_i_n =>
inr (Ordinal (n:=n) (m:=i) lt_i_n)
| GeqNotLtn ge_i_n =>
inl
(Ordinal (n:=m) (m:=i - n)
(tsplit_subproof (m:=m) (n:=n) (i:=i)
ge_i_n))
end lt_i_n
bycase: {-}_ lt_i_n / ltnP; [left |right; rewrite subnK].Qed.Definitiontunsplit {mn} (jk : 'I_m + 'I_n) :=
match jk with inl j => tlshift n j | inr k => trshift m k end.
10d
jk:('I_m + 'I_n)%type
(n <= tunsplit jk) = jk
13d
bycase: jk => [j|k]; rewrite /= ?ltn_ord?leq_addl // leqNgt ltn_ord.Qed.
11b
cancel tsplit tunsplit
144
bymove=> i; apply: val_inj; case: tsplitP.Qed.
11b
cancel tunsplit tsplit
149
13f
~~ (tunsplit jk < n) = jk -> tsplit (tunsplit jk) = jk
bydo [case: tsplitP; case: jk => //= i j] => [|/addIn] => /ord_inj->.Qed.(******************************************************************************)(* *)(* Extra theorems about fset *)(* *)(******************************************************************************)Open Scope fset_scope.Definitionsintab : {fset nat} :=
[fset @nat_of_ord _ i | i in 'I_b & a <= i].
a, b:nat
i:nat_choiceType
(i \in sint a b) = (a <= i < b)
152
155156
j:ordinal_choiceType b
aLj:j \in [pred x | a <= x]
a <= j < b
155156
aLi:a <= i
iLb:i < b
exists2 x : ordinal_choiceType b,
in_mem x
(mem_fin
(subfinset_finpred (T:=ordinal_choiceType b)
(mem_fin
(fin_finpred
(pT:=pred_finpredType
(ordinal_finType b)) 'I_b))
(funi : 'I_b => a <= i))) & i = x
162165
byexists (OrdinaliLb).Qed.
a, b, c:nat
a <= c -> [fset i in sint a b | c <= i] = sint c b
16a
16d
aLc:a <= c
[fset i in sint a b | c <= i] = sint c b
16d174156
(i \in [fset i | i in sint a b & c <= i]) =
(i \in sint c b)
179
(i \in [fset i | i in sint a b & c <= i]) =
(c <= i < b)
16d174
i, j:nat_choiceType
j
\in [pred x in [eta mem_seq (T:=nat_choiceType)
(sint a b)] |
c <= x] -> i = j -> c <= i < b
16d174156
cLi:c <= i
164
exists2 x : nat_choiceType,
in_mem x
(mem_fin
(subfinset_finpred (T:=nat_choiceType)
(mem_fin (fset_finpred (sint a b))) (leq c))) &
i = x
16d174183
aLj:a <= j
jLb:j < b
cLj:c <= j
c <= j < b
185
187189
byexistsi; rewrite //= inE mem_sint cLi iLb (leq_trans aLc).Qed.
(if m < p then m else p) <= (if n < p then n else p)
3de412
pLm:p <= m
n < p -> p <= n
3de412
pLm:m < p
p <= n -> m <= p
41c41e
bymove=> _; rewrite ltnW.Qed.
40b
m <= n -> minn p m <= minn p n
423
411
(if p < m then p else m) <= (if p < n then p else n)
3de412
pLm:p < m
n <= p -> p <= n
bymove=> _; rewrite (leq_trans (ltnW pLm)).Qed.(******************************************************************************)(* Definiion of discrete convex and concave version *)(* it contains just what is needed for shanoi4 *)(******************************************************************************)SectionConvex.Definitionincreasing (f : nat -> nat) := foralln, f n <= f n.+1.Definitiondecreasing (f : nat -> nat) := foralln, f n.+1 <= f n.
f1, f2:nat -> nat
f1 =1 f2 -> increasing f1 -> increasing f2
432
bymove=> fE fI i; rewrite -!fE.Qed.
37910d
increasing f -> m <= n -> f m <= f n
439
37910d
fI:increasing f
412
f m <= f (n - m + m)
37910d442412
d:nat
fL:f m <= f (d + m)
f m <= f (d.+1 + m)
byapply: leq_trans (fI (d + m)).Qed.
43b
decreasing f -> m <= n -> f n <= f m
44c
37910d
fI:decreasing f
412
f (n - m + m) <= f m
37910d454412448
fL:f (d + m) <= f m
f (d.+1 + m) <= f m
byapply: leq_trans (fI _) fL.Qed.Definitiondelta (f : nat -> nat) n := f n.+1 - f n.
434
f1 =1 f2 -> delta f1 =1 delta f2
45d
bymove=> fE i; rewrite /delta !fE.Qed.Definitionfnorm (f : nat -> nat) n := f n - f 0.
increasing f ->
fnorm f n = \sum_(i < n) delta (fnorm f) i
46e
379127
iF:increasing f
fnorm f n = \sum_(i < n) delta (fnorm f) i
379476127
IH:fnorm f n = \sum_(i < n) delta (fnorm f) i
fnorm f n.+1 = \sum_(i < n.+1) delta (fnorm f) i
byrewrite big_ord_recr /= -IH addnC subnK // increasing_fnorm.Qed.(* we restrict this to increasing function because of the behavior -*)Definitionconvexf :=
increasing f /\ increasing (delta f).(* we restrict this to increasing function because of the behavior -*)Definitionconcavef :=
increasing f /\ decreasing (delta f).
464
increasing f ->
(foralli : nat, f i + f i.+2 <= (f i.+1).*2) ->
concave f
47f
379442
fH:foralli : nat, f i + f i.+2 <= (f i.+1).*2
i:nat
delta f i.+1 <= delta f i
486
f i.+2 - f i.+1 <= f i.+1 - f i
486
f i.+2 + f i <= f i.+1 + f i.+1
byrewrite addnn addnC.Qed.
379
i, k:nat
concave f ->
k <= i -> f (i - k) + f (i + k) <= (f i).*2
493
379496442
dfD:decreasing (delta f)
k <= i -> f (i - k) + f (i + k) <= (f i).*2
37948844249d
k:nat
IH:k <= i -> f (i - k) + f (i + k) <= (f i).*2
kLi:k < i
f (i - k.+1) + f (i + k.+1) <= (f i).*2
4a2
i - k.+1 <= i + k
37948844249d4a34a44a5
H:i - k.+1 <= i + k
4a6
4ad4a6
4ad
f (i - k.+1) <= f (i - k)
37948844249d4a34a44a54ae
fk1Lfk:f (i - k.+1) <= f (i - k)
4a6
4b84a6
4b8
delta f (i + k) + (f (i - k) + f (i + k)) <=
delta f (i - k.+1) + (f i).*2 ->
f (i - k.+1) + f (i + k.+1) <= (f i).*2
4b8
f (i - k) + f (i + k).+1 <=
f (i - k.+1).+1 - f (i - k.+1) + (f i).*2 ->
f (i - k.+1) + f (i + k.+1) <= (f i).*2
4b8
f (i - k.+1) + (f (i - k) + f (i + k).+1) <=
f (i - k) + (f i).*2 ->
f (i - k.+1) + f (i + k.+1) <= (f i).*2
4b8
f (i - k.+1) <= f (i - k) + (f i).*2
4b84cb
byapply: leq_trans fk1Lfk (leq_addr _ _).Qed.
379
i, k1, k2:nat
concave f ->
f (i + k1 + k2) + f i <= f (i + k2) + f (i + k1)
4d0
3794d3
fC:concave f
44249d
f (i + k1 + k2) + f i <= f (i + k2) + f (i + k1)
3794da44249d
k2:nat
IHH:forallk1i : nat, f (i + k1 + k2) + f i <= f (i + k2) + f (i + k1)
k1, i:nat
f (i + k1 + k2.+1) + f i <= f (i + k2.+1) + f (i + k1)
4df
f (i + k1 + k2).+1 - f (i + k1 + k2) + f (i + k1 + k2) +
f i <=
f (i + k2).+1 - f (i + k2) + f (i + k2) + f (i + k1)
4df
f (i + k1 + k2).+1 - f (i + k1 + k2) <=
f (i + k2).+1 - f (i + k2)
increasing f ->
(foralli : nat, (f i.+1).*2 <= f i + f i.+2) ->
convex f
4ed
379442
fH:foralli : nat, (f i.+1).*2 <= f i + f i.+2
488
delta f i <= delta f i.+1
4f4
f i.+1 - f i <= f i.+2 - f i.+1
4f4
f i.+1 + f i.+1 <= f i.+2 - f i.+1 + (f i + f i.+1)
byrewrite addnn [f i + _]addnC addnA subnK // addnC.Qed.
495
convex f ->
k <= i -> (f i).*2 <= f (i - k) + f (i + k)
500
379496442
dfI:increasing (delta f)
k <= i -> (f i).*2 <= f (i - k) + f (i + k)
3794884425084a3
IH:k <= i -> (f i).*2 <= f (i - k) + f (i + k)
4a5
(f i).*2 <= f (i - k.+1) + f (i + k.+1)
50d4aa
3794884425084a350e4a54ae
50f
51550f
5154b5
3794884425084a350e4a54ae4b9
50f
51e50f
51e
delta f (i - k.+1) + (f i).*2 <=
delta f (i + k) + (f (i - k) + f (i + k)) ->
(f i).*2 <= f (i - k.+1) + f (i + k.+1)
51e
(f i).*2 + (f (i - k.+1).+1 - f (i - k.+1)) <=
f (i + k).+1 + f (i - k) ->
(f i).*2 <= f (i - k.+1) + f (i + k.+1)
byrewrite -subSn // subSS addnS addnBA // leq_subLR addnA leq_add2r.Qed.(* Ad-hoc bigmin operator *)Fixpointbigminfn :=
if n is n1.+1then minn (f n) (bigmin f n1)
else f 0.Notation"\min_ ( i <= n ) F" := (bigmin (funi => F) n)
(at level41, F at level41, i, n at level50,
format"\min_ ( i <= n ) F").
379354
\min_(i <= n) (f i + k) = \min_(i <= n) f i + k
52b
byelim: n => //= n ->; rewrite addn_minl.Qed.
52d
\min_(i <= n) (f i - k) = \min_(i <= n) f i - k
531
byelim: n => //= n ->; rewrite subn_minr.Qed.
46a
{i0 : 'I_n.+1 | \min_(i <= n) f i = f i0}
536
379127
i:'I_n.+1
{i0 : 'I_n.+2 | minn (f n.+1) (f i) = f i0}
37912753e
H:f i <= f n.+1
{i0 : 'I_n.+2 | f i = f i0}
37912753e
H:f n.+1 < f i
{i0 : 'I_n.+2 | f n.+1 = f i0}
54854a
byexistsord_max.Qed.
3792a3
reflect (foralli : nat, i <= n -> m <= f i)
(m <= \min_(i <= n) f i)
54f
379
m:nat
reflect (foralli : nat, i <= 0 -> m <= f i)
(m <= f 0)
37910d
IH:reflect (foralli : nat, i <= n -> m <= f i)
(m <= \min_(i <= n) f i)
reflect (foralli : nat, i <= n.+1 -> m <= f i)
(m <= minn (f n.+1) (\min_(i <= n) f i))
55c55e
55c
m <= minn (f n.+1) (\min_(i <= n) f i) ->
foralli : nat, i <= n.+1 -> m <= f i
37910d55d
H:foralli : nat, i <= n.+1 -> m <= f i
m <= minn (f n.+1) (\min_(i <= n) f i)
37910d55d
mLf:m <= f n.+1
mLmin:m <= \min_(i <= n) f i
488
i <= n.+1 -> m <= f i
566
37910d55d56f570488
iLn:i < n.+1
m <= f i
566
56856a
568
m <= \min_(i <= n) f i
byapply/IH => i iLn; rewrite H // (leq_trans iLn).Qed.
379
n, i0, m:nat
i0 <= n -> f i0 <= m -> \min_(i <= n) f i <= m
580
379583
i0Ln:i0 <= n
\min_(i <= n) f i <= f i0
379
i0, m, n:nat
IH:i0 <= n -> \min_(i <= n) f i <= f i0
i0 <= n.+1 ->
minn (f n.+1) (\min_(i <= n) f i) <= f i0
bymove=> fE gE i; apply: bigmin_ext => j; rewrite fE gE.Qed.
5ad
conv f g =1 conv g f
5d3
5ae127
\min_(i <= n) (f i + g (n - i)) <=
\min_(i <= n) (g i + f (n - i))
5da
\min_(i <= n) (g i + f (n - i)) <=
\min_(i <= n) (f i + g (n - i))
5ae
n, i:nat
iLn:i <= n
\min_(i <= n) (f i + g (n - i)) <= g i + f (n - i)
5dc
5e2
\min_(i <= n) (f i + g (n - i)) <=
f (n - i) + g (n - (n - i))
5dc
5da5de
5e2
\min_(i <= n) (g i + f (n - i)) <= f i + g (n - i)
5e2
\min_(i <= n) (g i + f (n - i)) <=
g (n - i) + f (n - (n - i))
byapply: bigmin_inf (leq_subr _ _) (leqnn _).Qed.
5ad
increasing f -> increasing g -> increasing (conv f g)
5f6
5be
conv f g i <= conv f g i.+1
5c8
j <= i.+1 -> conv f g i <= f j + g (i.+1 - j)
5ae4425bf5c9
jLi:j < i.+1
conv f g i <= f j + g (i.+1 - j)
5c8
conv f g i <= f i.+1 + g (i.+1 - i.+1)
5c860a
5c8
conv f g i <= f i.+1 + g 0
byapply: bigmin_inf (leqnn i) _; rewrite subnn leq_add2r.Qed.(* merging increasing functions *)Fixpointfmerge_aux (fg : nat -> nat) ijn :=
if n is n1.+1thenif f i < g j then fmerge_aux f g i.+1 j n1
else fmerge_aux f g i j.+1 n1
else minn (f i) (g j).Definitionfmergefgn := fmerge_aux f g 00 n.
f1, f2, g1, g2:nat -> nat
5c9
f1 =1 f2 ->
g1 =1 g2 ->
fmerge_aux f1 g1 i j =1 fmerge_aux f2 g2 i j
613
616
fE:f1 =1 f2
gE:g1 =1 g2
127
IH:forallij : nat,
fmerge_aux f1 g1 i j n = fmerge_aux f2 g2 i j n
5c9
(if f1 i < g1 j
then fmerge_aux f1 g1 i.+1 j n
else fmerge_aux f1 g1 i j.+1 n) =
(if f2 i < g2 j
then fmerge_aux f2 g2 i.+1 j n
else fmerge_aux f2 g2 i j.+1 n)
byrewrite !(fE, gE, IH).Qed.
616
f1 =1 f2 -> g1 =1 g2 -> fmerge f1 g1 =1 fmerge f2 g2
622
bymove=> fE gE n; apply: fmerge_aux_ext.Qed.
5ae
i, j, n:nat
increasing f ->
increasing g ->
forallk : nat,
k <= n ->
minn (f (i + k)) (g (j + (n - k))) <=
fmerge_aux f g i j n
628
5ae62b4425bf
forallk : nat,
k <= n ->
minn (f (i + k)) (g (j + (n - k))) <=
fmerge_aux f g i j n
5c8
minn (f (i + 0)) (g (j + (0 - 0))) <= minn (f i) (g j)
5ae4425bf127
IH:forallijk : nat,
k <= n ->
minn (f (i + k)) (g (j + (n - k))) <=
fmerge_aux f g i j n
i, j, k:nat
kLn:k <= n.+1
minn (f (i + k)) (g (j + (n.+1 - k))) <=
(if f i < g j
then fmerge_aux f g i.+1 j n
else fmerge_aux f g i j.+1 n)
63963d
5ae4425bf12763a63b63c
gLf:g j <= f i
minn (f (i + k)) (g (j + (n.+1 - k))) <=
fmerge_aux f g i j.+1 n
5ae4425bf12763a63b63c
fLg:f i < g j
minn (f (i + k)) (g (j + (n.+1 - k))) <=
fmerge_aux f g i.+1 j n
5ae4425bf12763a63b645
minn (f (i + n.+1)) (g (j + (n.+1 - n.+1))) <=
fmerge_aux f g i j.+1 n
5ae4425bf12763a63b645
kLn:k < n.+1
646
648
64f
g j <= f (i + n.+1)
64f
g j <= fmerge_aux f g i j.+1 n
652648
64f65b
651
64f
g j <= minn (f (i + n)) (g (j.+1 + (n - n)))
651
64f
f i <= f (i + n)
651
653646
647
64964b
5ae4425bf12763a5c964a
minn (f (i + 0)) (g (j + (n.+1 - 0))) <=
fmerge_aux f g i.+1 j n
5ae4425bf12763a5c964a4a3654
minn (f (i + k.+1)) (g (j + (n.+1 - k.+1))) <=
fmerge_aux f g i.+1 j n
670
f i <= g (j + n.+1)
670
f i <= fmerge_aux f g i.+1 j n
673
67067c
672
670
f i <= minn (f (i.+1 + 0)) (g (j + (n - 0)))
672
670
g j <= g (j + (n - 0))
672
674675
byrewrite subSS -addSnnS IH.Qed.
62a
exists2 k : nat,
k <= n &
fmerge_aux f g i j n =
minn (f (i + k)) (g (j + (n - k)))
68c
5ae127
IH:forallij : nat,
exists2 k : nat,
k <= n &
fmerge_aux f g i j n =
minn (f (i + k)) (g (j + (n - k)))
5c9
exists2 k : nat,
k <= n.+1 &
(if f i < g j
then fmerge_aux f g i.+1 j n
else fmerge_aux f g i j.+1 n) =
minn (f (i + k)) (g (j + (n.+1 - k)))
5ae1276945c964a
exists2 k : nat,
k <= n.+1 &
fmerge_aux f g i.+1 j n =
minn (f (i + k)) (g (j + (n.+1 - k)))
5ae1276945c9645
exists2 k : nat,
k <= n.+1 &
fmerge_aux f g i j.+1 n =
minn (f (i + k)) (g (j + (n.+1 - k)))
69d69e
5ae1276945c9645
kLn:0 <= n
exists2 k : nat,
k <= n.+1 &
minn (f (i + 0)) (g (j.+1 + (n - 0))) =
minn (f (i + k)) (g (j + (n.+1 - k)))
5ae1276945c96454a3
kLn:k < n
ex2 (funk : nat => k <= n.+1)
(funk0 : nat =>
minn (f (i + k.+1)) (g (j.+1 + (n - k.+1))) =
minn (f (i + k0)) (g (j + (n.+1 - k0))))
minn (f i) (g (n - i)) <=
\max_(i < n.+2) minn (f i) (g (n.+1 - i))
6dd
minn (f i) (g (n - i)) <=
minn (f (inord i)) (g (n.+1 - inord i))
6dd
minn (f i) (g (n - i)) <= minn (f i) (g (n.+1 - i))
6dd
g (n - i) <= g (n.+1 - i)
5ae44212753e
n - i <= n.+1 - i
byrewrite leq_sub2r.Qed.
5ad
fmerge f g 0 = minn (f 0) (g 0)
6f1
by [].Qed.Fixpointsum_fmerge_aux (fg : nat -> nat) ijn :=
if n is n1.+1thenif f i < g j then f i + sum_fmerge_aux f g i.+1 j n1
else g j + sum_fmerge_aux f g i j.+1 n1
else minn (f i) (g j).Definitionsum_fmergefgn := sum_fmerge_aux f g 00 n.
5ae
n, i, j:nat
sum_fmerge_aux f g i j n =
\sum_(k < n.+1) fmerge_aux f g i j k
6f6
5ae127
IH:forallij : nat,
sum_fmerge_aux f g i j n =
\sum_(k < n.+1) fmerge_aux f g i j k
5c9
(if f i < g j
then f i + sum_fmerge_aux f g i.+1 j n
else g j + sum_fmerge_aux f g i j.+1 n) =
\sum_(k < n.+2) fmerge_aux f g i j k
increasing f ->
increasing g ->
forallk : nat,
k <= n.+1 ->
sum_fmerge_aux f g i j n <=
\sum_(l < k) f (i + l) + \sum_(l < n.+1 - k) g (j + l)
708
631
forallk : nat,
k <= n.+1 ->
sum_fmerge_aux f g i j n <=
\sum_(l < k) f (i + l) + \sum_(l < n.+1 - k) g (j + l)
5c8
minn (f i) (g j) <=
\sum_(l < 0) f (i + l) + \sum_(l < 1 - 0) g (j + l)
5c8
minn (f i) (g j) <=
\sum_(l < 1) f (i + l) + \sum_(l < 1 - 1) g (j + l)
5ae4425bf127
IH:forallijk : nat,
k <= n.+1 ->
sum_fmerge_aux f g i j n <=
\sum_(l < k) f (i + l) +
\sum_(l < n.+1 - k) g (j + l)
63b
kLn:k <= n.+2
(if f i < g j
then f i + sum_fmerge_aux f g i.+1 j n
else g j + sum_fmerge_aux f g i j.+1 n) <=
\sum_(l < k) f (i + l) + \sum_(l < n.+2 - k) g (j + l)
711
5c8716
717
71e
71871b
5ae4425bf12771963b71a645
g j + sum_fmerge_aux f g i j.+1 n <=
\sum_(l < k) f (i + l) + \sum_(l < n.+2 - k) g (j + l)
5ae4425bf12771963b71a64a
f i + sum_fmerge_aux f g i.+1 j n <=
\sum_(l < k) f (i + l) + \sum_(l < n.+2 - k) g (j + l)
5ae4425bf12771963b645
g j + sum_fmerge_aux f g i j.+1 n <=
\sum_(l < n.+2) f (i + l) +
\sum_(l < n.+2 - n.+2) g (j + l)
5ae4425bf12771963b645
kLn:k < n.+2
729
72b
731
g j + sum_fmerge_aux f g i j.+1 n <=
f i + \sum_(i0 < n.+1) f (i + bump 0 i0)
733
731
sum_fmerge_aux f g i j.+1 n <=
\sum_(i0 < n.+1) f (i + bump 0 i0)
733
731
sum_fmerge_aux f g i j.+1 n <=
\sum_(i0 < n.+1) f (i + (1 + i0))
733
731
\sum_(l < n.+1) f (i + l) +
\sum_(l < n.+1 - n.+1) g (j.+1 + l) <=
\sum_(i0 < n.+1) f (i + (1 + i0))
733
5ae4425bf12771963b645
l:'I_n.+1
f (i + l) <= f (i + (1 + l))
733
735729
72a
735
sum_fmerge_aux f g i j.+1 n <=
\sum_(l < k) f (i + l) +
\sum_(i < n.+1 - k) g (j + lift ord0 i)
72a
735
\sum_(l < k) f (i + l) +
\sum_(l < n.+1 - k) g (j.+1 + l) <=
\sum_(l < k) f (i + l) +
\sum_(i < n.+1 - k) g (j + lift ord0 i)
72a
5ae4425bf12771963b645736
l:'I_(n.+1 - k)
g (j.+1 + l) <= g (j + lift ord0 l)
72a
72c72d
5ae4425bf12771963b64a
f i + sum_fmerge_aux f g i.+1 j n <=
\sum_(l < n.+2) f (i + l) +
\sum_(l < n.+2 - n.+2) g (j + l)
5ae4425bf12771963b64a736
72d
764
sum_fmerge_aux f g i.+1 j n <=
\sum_(i0 < n.+1) f (i + (1 + i0))
766
764
\sum_(l < n.+1) f (i.+1 + l) +
\sum_(l < n.+1 - n.+1) g (j + l) <=
\sum_(i0 < n.+1) f (i + (1 + i0))
766
5ae4425bf12771963b64a74b
f (i.+1 + l) <= f (i + (1 + l))
766
76872d
5ae4425bf1277195c964a4a3
kLn:k.+1 < n.+2
f i + sum_fmerge_aux f g i.+1 j n <=
\sum_(l < k.+1) f (i + l) +
\sum_(l < n.+2 - k.+1) g (j + l)
5ae4425bf1277195c964a
f i + sum_fmerge_aux f g i.+1 j n <=
\sum_(l < 0) f (i + l) + \sum_(l < n.+2 - 0) g (j + l)
77c
f i + sum_fmerge_aux f g i.+1 j n <=
\sum_(l < k.+1) f (i + l) +
\sum_(l < n.+1 - k) g (j + l)
77f
77c
k <= n.+1
77c
f i +
(\sum_(l < k) f (i.+1 + l) +
\sum_(l < n.+1 - k) g (j + l)) <=
\sum_(l < k.+1) f (i + l) +
\sum_(l < n.+1 - k) g (j + l)
780
77c78d
77f
5ae4425bf1277195c964a4a377d
l:'I_k
f (i.+1 + l) <= f (i + lift ord0 l)
77f
781782
781
f i + sum_fmerge_aux f g i.+1 j n <=
\sum_(l < n.+2) g (j + l)
781
f i +
(\sum_(l < 0) f (i.+1 + l) +
\sum_(l < n.+1 - 0) g (j + l)) <=
\sum_(l < n.+2) g (j + l)
781
f i <= g (j + ord_max)
781
g j <= g (j + ord_max)
byrewrite increasingE // leq_addr.Qed.
5ae
k, n:nat
increasing f ->
increasing g ->
k <= n ->
\sum_(i < n) fmerge f g i <=
\sum_(i < k) f i + \sum_(i < n - k) g i
7ab
5ae4a34425bf
k <= 0 ->
\sum_(i < 0) fmerge f g i <=
\sum_(i < k) f i + \sum_(i < 0 - k) g i
5ae4a34425bf12763c
\sum_(i < n.+1) fmerge f g i <=
\sum_(i < k) f i + \sum_(i < n.+1 - k) g i
7b87b9
7b8
sum_fmerge f g n <=
\sum_(i < k) f i + \sum_(i < n.+1 - k) g i
exact: (sum_fmerge_aux_conv_correct 00 fI gI kLn).Qed.
62a
exists2 k : nat,
k <= n.+1 &
sum_fmerge_aux f g i j n =
\sum_(l < k) f (i + l) +
\sum_(l < n.+1 - k) g (j + l)
7c2
5ae5c9
exists2 k : nat,
k <= 1 &
minn (f i) (g j) =
\sum_(l < k) f (i + l) + \sum_(l < 1 - k) g (j + l)
5ae127
IH:forallij : nat,
exists2 k : nat,
k <= n.+1 &
sum_fmerge_aux f g i j n =
\sum_(l < k) f (i + l) +
\sum_(l < n.+1 - k) g (j + l)
5c9
exists2 k : nat,
k <= n.+2 &
(if f i < g j
then f i + sum_fmerge_aux f g i.+1 j n
else g j + sum_fmerge_aux f g i j.+1 n) =
\sum_(l < k) f (i + l) +
\sum_(l < n.+2 - k) g (j + l)
5ae5c9645
exists2 k : nat,
k <= 1 &
g j =
\sum_(l < k) f (i + l) + \sum_(l < 1 - k) g (j + l)
5ae5c964a
exists2 k : nat,
k <= 1 &
f i =
\sum_(l < k) f (i + l) + \sum_(l < 1 - k) g (j + l)
7cc
7d77d8
7cb
7cd7cf
5ae1277ce5c9645
exists2 k : nat,
k <= n.+2 &
g j + sum_fmerge_aux f g i j.+1 n =
\sum_(l < k) f (i + l) +
\sum_(l < n.+2 - k) g (j + l)
5ae1277ce5c964a
exists2 k : nat,
k <= n.+2 &
f i + sum_fmerge_aux f g i.+1 j n =
\sum_(l < k) f (i + l) +
\sum_(l < n.+2 - k) g (j + l)
5ae1277ce5c96454a363c
ex2 (funk : nat => k <= n.+2)
(funk0 : nat =>
g j +
(\sum_(l < k) f (i + l) +
\sum_(l < n.+1 - k) g (j.+1 + l)) =
\sum_(l < k0) f (i + l) +
\sum_(l < n.+2 - k0) g (j + l))
7e4
7eb
g j +
(\sum_(l < k) f (i + l) +
\sum_(l < n.+1 - k) g (j.+1 + l)) =
\sum_(l < k) f (i + l) + \sum_(l < n.+2 - k) g (j + l)
7e4
7eb
\sum_(l < k) f (i + l) +
(g j + \sum_(l < n.+1 - k) g (j.+1 + l)) =
\sum_(l < k) f (i + l) +
(g j + \sum_(i < n.+1 - k) g (j + lift ord0 i))
7e4
7e67e7
5ae1277ce5c964a4a363c
f i +
(\sum_(l < k) f (i.+1 + l) +
\sum_(l < n.+1 - k) g (j + l)) =
\sum_(l < k.+1) f (i + l) +
\sum_(l < n.+2 - k.+1) g (j + l)
7fb
f i +
(\sum_(l < k) f (i.+1 + l) +
\sum_(l < n.+1 - k) g (j + l)) =
f i +
(\sum_(i0 < k) f (i + lift ord0 i0) +
\sum_(l < n.+1 - k) g (j + l))
fmerge (funn : nat => fnorm f n.+1 - fnorm f n)
(funn : nat => fnorm g n.+1 - fnorm g n) n =
fmerge (funn : nat => f n.+1 - f n)
(funn : nat => g n.+1 - g n) n