From 946abd88fa24966751555193b0fe0d52e50722f2 Mon Sep 17 00:00:00 2001 From: Andrea Asperti <andrea.asperti@unibo.it> Date: Tue, 28 Jan 2014 12:34:47 +0000 Subject: [PATCH] Almost there --- .../lib/reverse_complexity/speed_clean.ma | 113 ++++++++++++------ 1 file changed, 75 insertions(+), 38 deletions(-) diff --git a/matita/matita/lib/reverse_complexity/speed_clean.ma b/matita/matita/lib/reverse_complexity/speed_clean.ma index 7c04bfd76..46eb10751 100644 --- a/matita/matita/lib/reverse_complexity/speed_clean.ma +++ b/matita/matita/lib/reverse_complexity/speed_clean.ma @@ -490,6 +490,16 @@ axiom CF_mu: âa,b.âf:nat âbool.âsa,sb,sf,s. definition constructible â λs. CF s s. +lemma constr_comp : âs1,s2. constructible s1 â constructible s2 â + (âx. x ⤠s2 x) â constructible (s2 â s1). +#s1 #s2 #Hs1 #Hs2 #Hle @(CF_comp ⦠Hs1 Hs2) @O_plus @le_to_O #x [@Hle | //] +qed. + +lemma ext_constr: âs1,s2. (âx.s1 x = s2 x) â + constructible s1 â constructible s2. +#s1 #s2 #Hext #Hs1 @(ext_CF ⦠Hext) @(monotonic_CF ⦠Hs1) #x >Hext // +qed. + (********************************* simulation *********************************) axiom sU : nat â nat. @@ -676,13 +686,12 @@ axiom compl_g6: âh. *) lemma compl_g6: âh. - (âx.MSC xâ¤h (S (fst (snd x))) (fst x)) â constructible (λx. h (fst x) (snd x)) â - (CF (λx. sU â©fst (snd x),â©fst x,h (S (fst (snd x))) (fst x)âªâª) + (CF (λx. sU â©max (fst (snd x)) (snd (snd x)),â©fst x,h (S (fst (snd x))) (fst x)âªâª) (λp.termb (fst (snd p)) (fst p) (h (S (fst (snd p))) (fst p)))). -#h #hle #hconstr @(ext_CF (termb_aux h)) +#h #hconstr @(ext_CF (termb_aux h)) [#n normalize >fst_pair >snd_pair >fst_pair >snd_pair // ] -@(CF_comp ⦠(λx.h (S (fst (snd x))) (fst x)) ⦠CF_termb) +@(CF_comp ⦠(λx.MSC x + h (S (fst (snd x))) (fst x)) ⦠CF_termb) [@CF_comp_pair [@CF_comp_fst @(monotonic_CF ⦠CF_snd) #x // |@CF_comp_pair @@ -695,12 +704,27 @@ lemma compl_g6: âh. ] ] ] - |@O_plus [@le_to_O #n @sU_le | // ] + |@O_plus + [@O_plus + [@(O_trans ⦠(λx.MSC (fst x) + MSC (max (fst (snd x)) (snd (snd x))))) + [%{2} %{0} #x #_ cases (surj_pair x) #a * #b #eqx >eqx + >fst_pair >snd_pair @(transitive_le ⦠(MSC_pair â¦)) + >distributive_times_plus @le_plus [//] + cases (surj_pair b) #c * #d #eqb >eqb + >fst_pair >snd_pair @(transitive_le ⦠(MSC_pair â¦)) + whd in ⢠(??%); @le_plus + [@monotonic_MSC @(le_maxl ⦠(le_n â¦)) + |>commutative_times <times_n_1 @monotonic_MSC @(le_maxr ⦠(le_n â¦)) + ] + |@O_plus [@le_to_O #x @sU_le_x |@le_to_O #x @sU_le_i] + ] + |@le_to_O #n @sU_le + ] + |@le_to_O #x @monotonic_sU // @(le_maxl ⦠(le_n â¦)) ] ] qed. - - -definition faux1 â λh. + +(* definition faux1 â λh. (λx.MSC x + (snd (snd x)-fst x)*(λx.sU â©fst (snd x),â©fst x,h (S (fst (snd x))) (fst x)âªâª) â©snd (snd x),xâª). (* complexity of min_input *) @@ -712,9 +736,9 @@ lemma compl_g7: âh. (λp:â.min_input h (fst p) (snd (snd p))). #h #hle #hcostr #hmono @(monotonic_CF ⦠(faux1 h)) [#n normalize >fst_pair >snd_pair //] -@compl_g5 [2:@(compl_g6 h hle hcostr)] #n #x #y #lexy >fst_pair >snd_pair +@compl_g5 [2:@(compl_g6 h hcostr)] #n #x #y #lexy >fst_pair >snd_pair >fst_pair >snd_pair @monotonic_sU // @hmono @lexy -qed. +qed.*) definition big : nat ânat â λx. let m â max (fst x) (snd x) in â©m,mâª. @@ -727,17 +751,32 @@ lemma le_big : âx. x ⤠big x. [@(le_maxl ⦠(le_n â¦)) | @(le_maxr ⦠(le_n â¦))] qed. +definition faux2 â λh. + (λx.MSC x + (snd (snd x)-fst x)* + (λx.sU â©max (fst(snd x)) (snd(snd x)),â©fst x,h (S (fst (snd x))) (fst x)âªâª) â©snd (snd x),xâª). + +(* proviamo con x *) +lemma compl_g7: âh. + constructible (λx. h (fst x) (snd x)) â + (ân. monotonic ? le (h n)) â + CF (λx.MSC x + (snd (snd x)-fst x)*sU â©max (fst x) (snd x),â©snd (snd x),h (S (fst x)) (snd (snd x))âªâª) + (λp:â.min_input h (fst p) (snd (snd p))). +#h #hcostr #hmono @(monotonic_CF ⦠(faux2 h)) + [#n normalize >fst_pair >snd_pair //] +@compl_g5 [2:@(compl_g6 h hcostr)] #n #x #y #lexy >fst_pair >snd_pair +>fst_pair >snd_pair @monotonic_sU // @hmono @lexy +qed. + (* proviamo con x *) lemma compl_g71: âh. - (âx.MSC xâ¤h (S (fst (snd x))) (fst x)) â constructible (λx. h (fst x) (snd x)) â (ân. monotonic ? le (h n)) â CF (λx.MSC (big x) + (snd (snd x)-fst x)*sU â©max (fst x) (snd x),â©snd (snd x),h (S (fst x)) (snd (snd x))âªâª) (λp:â.min_input h (fst p) (snd (snd p))). -#h #hle #hcostr #hmono @(monotonic_CF ⦠(compl_g7 h hle hcostr hmono)) #x +#h #hcostr #hmono @(monotonic_CF ⦠(compl_g7 h hcostr hmono)) #x @le_plus [@monotonic_MSC //] cases (decidable_le (fst x) (snd(snd x))) - [#Hle @le_times // @monotonic_sU // @(le_maxl ⦠(le_n ⦠)) + [#Hle @le_times // @monotonic_sU |#Hlt >(minus_to_0 ⦠(lt_to_le ⦠)) [// | @not_le_to_lt @Hlt] ] qed. @@ -798,16 +837,14 @@ qed. *) (* axiom daemon : False. *) lemma compl_g9 : âh. - (âx.MSC xâ¤h (S (fst (snd x))) (fst x)) â - (âx.MSC xâ¤h (S (fst x)) (snd(snd x))) â constructible (λx. h (fst x) (snd x)) â (ân. monotonic ? le (h n)) â (ân,a,b. a ⤠b â b ⤠n â h b n ⤠h a n) â CF (λx. (S (snd x-fst x))*MSC â©x,x⪠+ (snd x-fst x)*(S(snd x-fst x))*sU â©x,â©snd x,h (S (fst x)) (snd x)âªâª) (auxg h). -#h #hle #hle1 #hconstr #hmono #hantimono -@(compl_g2 h ??? (compl_g3 ⦠(compl_g71 h hle hconstr hmono)) (compl_g81 h hle1 hconstr)) +#h #hconstr #hmono #hantimono +@(compl_g2 h ??? (compl_g3 ⦠(compl_g71 h hconstr hmono)) (compl_g8 h hconstr)) @O_plus [@O_plus_l @le_to_O #x >(times_n_1 (MSC x)) >commutative_times @le_times [// | @monotonic_MSC // ]] @@ -842,13 +879,11 @@ lemma sg_def : âh,a,b. qed. lemma compl_g11 : âh. - (âx.MSC xâ¤h (S (fst (snd x))) (fst x)) â - (âx.MSC xâ¤h (S (fst x)) (snd(snd x))) â constructible (λx. h (fst x) (snd x)) â (ân. monotonic ? le (h n)) â (ân,a,b. a ⤠b â b ⤠n â h b n ⤠h a n) â CF (sg h) (unary_g h). -#h #hle #hle1 #hconstr #Hm #Ham @compl_g1 @(compl_g9 h hle hle1 hconstr Hm Ham) +#h #hconstr #Hm #Ham @compl_g1 @(compl_g9 h hconstr Hm Ham) qed. (**************************** closing the argument ****************************) @@ -860,7 +895,7 @@ let rec h_of_aux (r:nat ânat) (c,d,b:nat) on d : nat â d*(S d)*sU â©â©b-d,bâª,â©b,r (h_of_aux r c d1 b)âªâª]. lemma h_of_aux_O: âr,c,b. - h_of_aux r c O b = c (* MSC â©â©b,bâª,â©b,bâªâª*) . + h_of_aux r c O b = c. // qed. lemma h_of_aux_S : âr,c,d,b. @@ -883,11 +918,6 @@ lemma h_of_def: âr,a,b.h_of r â©a,b⪠= h_of_aux r (MSC â©â©m,mâª,â©m,mâªâª) (b - a) b. #r #a #b normalize >fst_pair >snd_pair // qed. - -lemma h_le1 : âr.(âx. x ⤠r x) â monotonic ? le r â -(âx:â.MSC xâ¤r (h_of r â©S (fst x),snd (snd x)âª)). -#r #Hr #Hmono #x @(transitive_le ???? (Hr â¦)) ->h_of_def (* (âx.MSC xâ¤h (S (fst x)) (snd(snd x))) â *) @@ -923,10 +953,14 @@ cut (max i a ⤠max i b) [@monotonic_MSC @le_pair @le_pair @Hmax |/2 by monotonic_le_minus_l/ |@leab] qed. +axiom h_of_constr : âr:nat ânat. + (âx. x ⤠r x) â monotonic ? le r â constructible r â + constructible (h_of r). + lemma speed_compl: âr:nat ânat. - (âx. x ⤠r x) â monotonic ? le r â + (âx. x ⤠r x) â monotonic ? le r â constructible r â CF (h_of r) (unary_g (λi,x. r(h_of r â©i,xâª))). -#r #Hr #Hmono @(monotonic_CF ⦠(compl_g11 â¦)) +#r #Hr #Hmono #Hconstr @(monotonic_CF ⦠(compl_g11 â¦)) [#x cases (surj_pair x) #a * #b #eqx >eqx >sg_def cases (decidable_le b a) [#leba >(minus_to_0 ⦠leba) normalize in ⢠(?%?); @@ -959,7 +993,10 @@ lemma speed_compl: âr:nat ânat. cut (max b n = n) [normalize >(le_to_leb_true ⦠lebn) %] #Hmaxb >Hmaxa >Hmaxb @Hmono @(mono_h_of_aux r ⦠Hr Hmono) // /2 by monotonic_le_minus_r/ - |#n #a #b #leab @Hmono @(mono_h_of2 ⦠Hr Hmono ⦠leab) + |#n #a #b #leab @Hmono @(mono_h_of2 ⦠Hr Hmono ⦠leab) + |@(constr_comp ⦠Hconstr Hr) @(ext_constr (h_of r)) + [#x cases (surj_pair x) #a * #b #eqx >eqx >fst_pair >snd_pair //] + @(h_of_constr r Hr Hmono Hconstr) ] qed. @@ -972,19 +1009,19 @@ qed. *) axiom smn: âf,s. CF s f â âx. CF (λy.s â©x,yâª) (λy.f â©x,yâª). lemma speed_compl_i: âr:nat ânat. - (âx. x ⤠r x) â monotonic ? le r â + (âx. x ⤠r x) â monotonic ? le r â constructible r â âi. CF (λx.h_of r â©i,xâª) (λx.g (λi,x. r(h_of r â©i,xâª)) i x). -#r #Hr #Hmono #i +#r #Hr #Hmono #Hconstr #i @(ext_CF (λx.unary_g (λi,x. r(h_of r â©i,xâª)) â©i,xâª)) [#n whd in ⢠(??%%); @eq_f @sym_eq >fst_pair >snd_pair %] -@smn @(ext_CF ⦠(speed_compl r Hr Hmono)) #n // +@smn @(ext_CF ⦠(speed_compl r Hr Hmono Hconstr)) #n // qed. theorem pseudo_speedup: - âr:nat ânat. (âx. x ⤠r x) â monotonic ? le r â + âr:nat ânat. (âx. x ⤠r x) â monotonic ? le r â constructible r â âf.âsf. CF sf f â âg,sg. f â g ⧠CF sg g ⧠O sf (r â sg). (* âm,a.ân. aâ¤n â r(sg a) < m * sf n. *) -#r #Hr #Hmono +#r #Hr #Hmono #Hconstr (* f is (g (λi,x. r(h_of r â©i,xâª)) 0) *) %{(g (λi,x. r(h_of r â©i,xâª)) 0)} #sf * #H * #i * #Hcodei #HCi @@ -992,7 +1029,7 @@ theorem pseudo_speedup: %{(g (λi,x. r(h_of r â©i,xâª)) (S i))} (* sg is (λx.h_of r â©i,xâª) *) %{(λx. h_of r â©S i,xâª)} -lapply (speed_compl_i ⦠Hr Hmono (S i)) #Hg +lapply (speed_compl_i ⦠Hr Hmono Hconstr (S i)) #Hg %[%[@condition_1 |@Hg] |cases Hg #H1 * #j * #Hcodej #HCj lapply (condition_2 ⦠Hcodei) #Hcond2 (* @not_to_not *) @@ -1005,11 +1042,11 @@ lapply (speed_compl_i ⦠Hr Hmono (S i)) #Hg qed. theorem pseudo_speedup': - âr:nat ânat. (âx. x ⤠r x) â monotonic ? le r â + âr:nat ânat. (âx. x ⤠r x) â monotonic ? le r â constructible r â âf.âsf. CF sf f â âg,sg. f â g ⧠CF sg g ⧠(* ¬ O (r â sg) sf. *) âm,a.ân. aâ¤n â r(sg a) < m * sf n. -#r #Hr #Hmono +#r #Hr #Hmono #Hconstr (* f is (g (λi,x. r(h_of r â©i,xâª)) 0) *) %{(g (λi,x. r(h_of r â©i,xâª)) 0)} #sf * #H * #i * #Hcodei #HCi @@ -1017,7 +1054,7 @@ theorem pseudo_speedup': %{(g (λi,x. r(h_of r â©i,xâª)) (S i))} (* sg is (λx.h_of r â©i,xâª) *) %{(λx. h_of r â©S i,xâª)} -lapply (speed_compl_i ⦠Hr Hmono (S i)) #Hg +lapply (speed_compl_i ⦠Hr Hmono Hconstr (S i)) #Hg %[%[@condition_1 |@Hg] |cases Hg #H1 * #j * #Hcodej #HCj lapply (condition_2 ⦠Hcodei) #Hcond2 (* @not_to_not *) -- 2.39.2