include "ASM/ASMCosts.ma". include "ASM/WellLabeled.ma". include "ASM/Status.ma". include "common/StructuredTraces.ma". include "arithmetics/bigops.ma". include alias "arithmetics/nat.ma". include alias "basics/logic.ma". let rec compute_max_trace_label_label_cost (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status) (final_status: Status) (the_trace: trace_label_label (ASM_abstract_status cost_labels) trace_ends_flag start_status final_status) on the_trace: nat ≝ match the_trace with [ tll_base ends_flag initial final given_trace labelled_proof ⇒ compute_max_trace_any_label_cost … given_trace ] and compute_max_trace_any_label_cost (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status) (final_status: Status) (the_trace: trace_any_label (ASM_abstract_status cost_labels) trace_ends_flag start_status final_status) on the_trace: nat ≝ match the_trace with [ tal_base_not_return the_status _ _ _ _ ⇒ current_instruction_cost the_status | tal_base_return the_status _ _ _ ⇒ current_instruction_cost the_status | tal_step_call end_flag pre_fun_call start_fun_call after_fun_call final _ _ _ call_trace final_trace ⇒ let current_instruction_cost ≝ current_instruction_cost pre_fun_call in let call_trace_cost ≝ compute_max_trace_label_return_cost … call_trace in let final_trace_cost ≝ compute_max_trace_any_label_cost cost_labels end_flag … final_trace in call_trace_cost + current_instruction_cost + final_trace_cost | tal_step_default end_flag status_pre status_init status_end _ tail_trace _ _ ⇒ let current_instruction_cost ≝ current_instruction_cost status_pre in let tail_trace_cost ≝ compute_max_trace_any_label_cost cost_labels end_flag status_init status_end tail_trace in current_instruction_cost + tail_trace_cost ] and compute_max_trace_label_return_cost (cost_labels: BitVectorTrie costlabel 16) (start_status: Status) (final_status: Status) (the_trace: trace_label_return (ASM_abstract_status cost_labels) start_status final_status) on the_trace: nat ≝ match the_trace with [ tlr_base before after trace_to_lift ⇒ compute_max_trace_label_label_cost … trace_to_lift | tlr_step initial labelled final labelled_trace ret_trace ⇒ let labelled_cost ≝ compute_max_trace_label_label_cost … labelled_trace in let return_cost ≝ compute_max_trace_label_return_cost … ret_trace in labelled_cost + return_cost ]. (*Useless now? (* To be moved *) lemma pred_minus_1: ∀m, n: nat. ∀proof: n < m. pred (m - n) = m - n - 1. #m #n cases m [ #proof cases(lt_to_not_zero … proof) | #m' #proof normalize in ⊢ (???%); cases n [ normalize // | #n' normalize cases(m' - n') [ % | #Sm_n' normalize // ] ] ] qed. lemma succ_m_plus_one: ∀m: nat. S m = m + 1. // qed.*) include alias "arithmetics/nat.ma". (* lemma minus_m_n_minus_minus_plus_1: ∀m, n: nat. ∀proof: n < m. m - n = (m - n - 1) + 1. /3 by lt_plus_to_minus_r, plus_minus/ qed. lemma plus_minus_rearrangement_1: ∀m, n, o: nat. ∀proof_n_m: n ≤ m. ∀proof_m_o: m ≤ o. (m - n) + (o - m) = o - n. #m #n #o #H1 #H2 lapply (minus_to_plus … H1 (refl …)) #K1 >K1 lapply (minus_to_plus … H2 (refl …)) #K2 >K2 /2 by plus_minus/ qed. lemma plus_minus_rearrangement_2: ∀m, n, o: nat. n ≤ m → o ≤ n → (m - n) + (n - o) = m - o. /2 by plus_minus_rearrangement_1/ qed. lemma m_le_plus_n_m: ∀m, n: nat. m ≤ n + m. #m #n // qed. lemma n_plus_m_le_o_to_m_le_o: ∀m, n, o: nat. n + m ≤ o → m ≤ o. #m #n #o #assm /2 by le_plus_b/ qed. lemma m_minus_n_plus_o_m_minus_n_minus_o: ∀m, n, o: nat. m - (n + o) = m - n - o. #m #n #o /2 by / qed. *) let rec compute_max_trace_label_label_cost_is_ok (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status) (final_status: Status) (the_trace: trace_label_label (ASM_abstract_status cost_labels) trace_ends_flag start_status final_status) on the_trace: clock … final_status = (compute_max_trace_label_label_cost cost_labels trace_ends_flag start_status final_status the_trace) + (clock … start_status) ≝ ? and compute_max_trace_any_label_cost_is_ok (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status) (final_status: Status) (the_trace: trace_any_label (ASM_abstract_status cost_labels) trace_ends_flag start_status final_status) on the_trace: clock … final_status = (compute_max_trace_any_label_cost cost_labels trace_ends_flag start_status final_status the_trace) + (clock … start_status) ≝ ? and compute_max_trace_label_return_cost_is_ok (cost_labels: BitVectorTrie costlabel 16) (start_status: Status) (final_status: Status) (the_trace: trace_label_return (ASM_abstract_status cost_labels) start_status final_status) on the_trace: clock … final_status = (compute_max_trace_label_return_cost cost_labels start_status final_status the_trace) + clock … start_status ≝ ?. [1: cases the_trace #ends_flag #start_status #end_status #any_label_trace #is_costed normalize @compute_max_trace_any_label_cost_is_ok |2: cases the_trace [1,2: #start_status #final_status #is_next #is_not_return try (#is_costed) change with (current_instruction_cost start_status) in ⊢ (???(?%?)); cases(is_next) @execute_1_ok |3: #end_flag #status_pre_fun_call #status_start_fun_call #status_after_fun_call #status_final #is_next #is_call #is_after_return #call_trace #final_trace change with ( let current_instruction_cost ≝ current_instruction_cost status_pre_fun_call in let call_trace_cost ≝ compute_max_trace_label_return_cost … call_trace in let final_trace_cost ≝ compute_max_trace_any_label_cost cost_labels end_flag … final_trace in call_trace_cost + current_instruction_cost + final_trace_cost) in ⊢ (???(?%?)); normalize nodelta; >(compute_max_trace_any_label_cost_is_ok cost_labels end_flag status_after_fun_call status_final final_trace) >(compute_max_trace_label_return_cost_is_ok cost_labels status_start_fun_call status_after_fun_call call_trace) cases(is_next) in match (clock … status_start_fun_call); >(execute_1_ok status_pre_fun_call) associative_plus in ⊢ (??%?); associative_plus in ⊢ (??%?); (compute_max_trace_any_label_cost_is_ok cost_labels end_flag status_init status_end trace_any_label) cases(is_next) in match (clock … status_init); >(execute_1_ok status_pre) >commutative_plus >associative_plus >associative_plus @eq_f @commutative_plus ] |3: cases the_trace [1: #status_before #status_after #trace_to_lift normalize @compute_max_trace_label_label_cost_is_ok |2: #status_initial #status_labelled #status_final #labelled_trace #ret_trace normalize >(compute_max_trace_label_return_cost_is_ok cost_labels status_labelled status_final ret_trace); >(compute_max_trace_label_label_cost_is_ok cost_labels doesnt_end_with_ret status_initial status_labelled labelled_trace); commutative_plus in match ( compute_max_trace_label_return_cost cost_labels status_labelled status_final ret_trace + compute_max_trace_label_label_cost cost_labels doesnt_end_with_ret status_initial status_labelled labelled_trace); % ] ]. qed. (* XXX: work below here: *) let rec compute_paid_trace_any_label (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status) (final_status: Status) (the_trace: trace_any_label (ASM_abstract_status cost_labels) trace_ends_flag start_status final_status) on the_trace: nat ≝ match the_trace with [ tal_base_not_return the_status _ _ _ _ ⇒ current_instruction_cost the_status | tal_base_return the_status _ _ _ ⇒ current_instruction_cost the_status | tal_step_call end_flag pre_fun_call start_fun_call after_fun_call final _ _ _ call_trace final_trace ⇒ let current_instruction_cost ≝ current_instruction_cost pre_fun_call in let final_trace_cost ≝ compute_paid_trace_any_label cost_labels end_flag … final_trace in current_instruction_cost + final_trace_cost | tal_step_default end_flag status_pre status_init status_end _ tail_trace _ _ ⇒ let current_instruction_cost ≝ current_instruction_cost status_pre in let tail_trace_cost ≝ compute_paid_trace_any_label cost_labels end_flag status_init status_end tail_trace in current_instruction_cost + tail_trace_cost ]. definition compute_paid_trace_label_label ≝ λcost_labels: BitVectorTrie costlabel 16. λtrace_ends_flag: trace_ends_with_ret. λstart_status: Status. λfinal_status: Status. λthe_trace: trace_label_label (ASM_abstract_status cost_labels) trace_ends_flag start_status final_status. match the_trace with [ tll_base ends_flag initial final given_trace labelled_proof ⇒ compute_paid_trace_any_label … given_trace ]. let rec compute_trace_label_label_cost_using_paid (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status) (final_status: Status) (the_trace: trace_label_label (ASM_abstract_status cost_labels) trace_ends_flag start_status final_status) on the_trace: nat ≝ match the_trace with [ tll_base ends_flag initial final given_trace labelled_proof ⇒ compute_paid_trace_label_label cost_labels … the_trace + compute_trace_any_label_cost_using_paid … given_trace ] and compute_trace_any_label_cost_using_paid (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status) (final_status: Status) (the_trace: trace_any_label (ASM_abstract_status cost_labels) trace_ends_flag start_status final_status) on the_trace: nat ≝ match the_trace with [ tal_base_not_return the_status _ _ _ _ ⇒ 0 | tal_base_return the_status _ _ _ ⇒ 0 | tal_step_call end_flag pre_fun_call start_fun_call after_fun_call final _ _ _ call_trace final_trace ⇒ let call_trace_cost ≝ compute_trace_label_return_cost_using_paid … call_trace in let final_trace_cost ≝ compute_trace_any_label_cost_using_paid cost_labels end_flag … final_trace in call_trace_cost + final_trace_cost | tal_step_default end_flag status_pre status_init status_end _ tail_trace _ _ ⇒ compute_trace_any_label_cost_using_paid cost_labels end_flag status_init status_end tail_trace ] and compute_trace_label_return_cost_using_paid (cost_labels: BitVectorTrie costlabel 16) (start_status: Status) (final_status: Status) (the_trace: trace_label_return (ASM_abstract_status cost_labels) start_status final_status) on the_trace: nat ≝ match the_trace with [ tlr_base before after trace_to_lift ⇒ compute_trace_label_label_cost_using_paid … trace_to_lift | tlr_step initial labelled final labelled_trace ret_trace ⇒ let labelled_cost ≝ compute_trace_label_label_cost_using_paid … labelled_trace in let return_cost ≝ compute_trace_label_return_cost_using_paid … ret_trace in labelled_cost + return_cost ]. let rec compute_trace_label_label_cost_using_paid_ok (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status) (final_status: Status) (the_trace: trace_label_label (ASM_abstract_status cost_labels) trace_ends_flag start_status final_status) on the_trace: compute_trace_label_label_cost_using_paid cost_labels … the_trace = compute_max_trace_label_label_cost … the_trace ≝ ? and compute_trace_any_label_cost_using_paid_ok (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status) (final_status: Status) (the_trace: trace_any_label (ASM_abstract_status cost_labels) trace_ends_flag start_status final_status) on the_trace: compute_paid_trace_any_label cost_labels trace_ends_flag … the_trace +compute_trace_any_label_cost_using_paid cost_labels trace_ends_flag … the_trace =compute_max_trace_any_label_cost cost_labels trace_ends_flag … the_trace ≝ ? and compute_trace_label_return_cost_using_paid_ok (cost_labels: BitVectorTrie costlabel 16) (start_status: Status) (final_status: Status) (the_trace: trace_label_return (ASM_abstract_status cost_labels) start_status final_status) on the_trace: compute_trace_label_return_cost_using_paid cost_labels … the_trace = compute_max_trace_label_return_cost cost_labels … the_trace ≝ ?. [ cases the_trace #endsf #ss #es #tr #H normalize @compute_trace_any_label_cost_using_paid_ok | cases the_trace [ #ss #fs #H1 #H2 #H3 whd in ⊢ (??(?%%)%); commutative_plus in ⊢ (???(?%?)); >commutative_plus in ⊢ (??(??%)?); >associative_plus >associative_plus in ⊢ (???%); @eq_f2 try % associative_plus @eq_f2 [ % | @compute_trace_any_label_cost_using_paid_ok ] ] | cases the_trace [ #sb #sa #tr normalize @compute_trace_label_label_cost_using_paid_ok | #si #sl #sf #tr1 #tr2 normalize @eq_f2 [ @compute_trace_label_label_cost_using_paid_ok | @compute_trace_label_return_cost_using_paid_ok ]]] qed. (* let rec compute_paid_trace_label_return (cost_labels: BitVectorTrie costlabel 16) (start_status: Status) (final_status: Status) (the_trace: trace_label_return (ASM_abstract_status cost_labels) start_status final_status) on the_trace: nat ≝ match the_trace with [ tlr_base before after trace_to_lift ⇒ compute_paid_trace_label_label … trace_to_lift | tlr_step initial labelled final labelled_trace ret_trace ⇒ let labelled_cost ≝ compute_paid_trace_label_label … labelled_trace in let return_cost ≝ compute_paid_trace_label_return … ret_trace in labelled_cost + return_cost ]. *) let rec compute_cost_trace_label_label (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status) (final_status: Status) (the_trace: trace_label_label (ASM_abstract_status cost_labels) trace_ends_flag start_status final_status) on the_trace: list (Σk:costlabel. ∃pc. lookup_opt … pc cost_labels = Some … k) ≝ match the_trace with [ tll_base ends_flag initial final given_trace labelled_proof ⇒ let pc ≝ program_counter … initial in let label ≝ match lookup_opt … pc cost_labels return λx. match x with [None ⇒ False | Some _ ⇒ True] → costlabel with [ None ⇒ λabs. ⊥ | Some l ⇒ λ_. l ] labelled_proof in (mk_Sig … label ?)::compute_cost_trace_any_label … given_trace ] and compute_cost_trace_any_label (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status) (final_status: Status) (the_trace: trace_any_label (ASM_abstract_status cost_labels) trace_ends_flag start_status final_status) on the_trace: list (Σk:costlabel. ∃pc. lookup_opt … pc cost_labels = Some … k) ≝ match the_trace with [ tal_base_not_return the_status _ _ _ _ ⇒ [] | tal_base_return the_status _ _ _ ⇒ [] | tal_step_call end_flag pre_fun_call start_fun_call after_fun_call final _ _ _ call_trace final_trace ⇒ let call_cost_trace ≝ compute_cost_trace_label_return … call_trace in let final_cost_trace ≝ compute_cost_trace_any_label cost_labels end_flag … final_trace in call_cost_trace @ final_cost_trace | tal_step_default end_flag status_pre status_init status_end _ tail_trace _ _ ⇒ compute_cost_trace_any_label cost_labels end_flag status_init status_end tail_trace ] and compute_cost_trace_label_return (cost_labels: BitVectorTrie costlabel 16) (start_status: Status) (final_status: Status) (the_trace: trace_label_return (ASM_abstract_status cost_labels) start_status final_status) on the_trace: list (Σk:costlabel. ∃pc. lookup_opt … pc cost_labels = Some … k) ≝ match the_trace with [ tlr_base before after trace_to_lift ⇒ compute_cost_trace_label_label … trace_to_lift | tlr_step initial labelled final labelled_trace ret_trace ⇒ let labelled_cost ≝ compute_cost_trace_label_label … labelled_trace in let return_cost ≝ compute_cost_trace_label_return … ret_trace in labelled_cost @ return_cost ]. [ %{pc} whd in match label; generalize in match labelled_proof; whd in ⊢ (% → ?); cases (lookup_opt costlabel … pc cost_labels) normalize [ #abs cases abs | // ] | // ] qed. (* ??????????????????????? *) axiom block_cost_static_dynamic_ok: ∀cost_labels: BitVectorTrie costlabel 16. ∀trace_ends_flag. ∀start_status: Status. ∀final_status: Status. ∀the_trace: trace_label_label (ASM_abstract_status cost_labels) trace_ends_flag start_status final_status. let mem ≝ code_memory … start_status in let pc ≝ program_counter … start_status in let program_size ≝ 2^16 in block_cost mem cost_labels pc program_size = compute_paid_trace_label_label cost_labels trace_ends_flag start_status final_status the_trace. (* (* To be moved elsewhere*) lemma le_S_n_m_to_le_n_m: ∀n,m. S n ≤ m → n ≤ m. #n #m #H change with (pred (S n) ≤ m) @(transitive_le ? (S n)) // qed. *) (* This shoudl go in bigops! *) theorem bigop_sum_rev: ∀k1,k2,p,B,nil.∀op:Aop B nil.∀f:nat→B. \big[op,nil]_{ibigop_sum >commutative_plus @same_bigop #i @leb_elim normalize [2,4: // | #H1 #H2 "Σ_{ ident i < n } f" with precedence 20 for @{'bigop $n plus 0 (λ${ident i}.true) (λ${ident i}. $f)}. notation < "Σ_{ ident i < n } f" with precedence 20 for @{'bigop $n plus 0 (λ${ident i}:$X.true) (λ${ident i}:$Y. $f)}. axiom code_memory_ro_label_label: ∀cost_labels. ∀ends_flag. ∀initial,final. trace_label_label (ASM_abstract_status cost_labels) ends_flag initial final → code_memory … initial = code_memory … final. (* axiom code_memory_ro_label_return: ∀cost_labels. ∀initial,final. trace_label_return (ASM_abstract_status cost_labels) initial final → code_memory … initial = code_memory … final. *) definition tech_cost_of_label0: ∀cost_labels: BitVectorTrie costlabel 16. ∀cost_map: identifier_map CostTag nat. ∀codom_dom: (∀pc,k. lookup_opt … pc cost_labels = Some … k → present … cost_map k). ∀ctrace:list (Σk:costlabel.∃pc. lookup_opt costlabel 16 pc cost_labels = Some ? k). ∀i,p. present … cost_map (nth_safe ? i ctrace p). #cost_labels #cost_map #codom_dom #ctrace #i #p cases (nth_safe … i ctrace ?) normalize #id * #id_pc #K lapply (codom_dom … K) #k_pres >(lookup_lookup_present … k_pres) % #abs destruct (abs) qed. include alias "arithmetics/nat.ma". include alias "basics/logic.ma". lemma ltb_rect: ∀P:Type[0].∀n,m. (n < m → P) → (¬ n < m → P) → P. #P #n #m lapply (refl … (ltb n m)) cases (ltb n m) in ⊢ (???% → %); #E #H1 #H2 [ @H1 @leb_true_to_le @E | @H2 @leb_false_to_not_le @E ] qed. lemma same_ltb_rect: ∀P,n,m,H1,H2,n',m',H1',H2'. ltb n m = ltb n' m' → (∀x,y. H1 x = H1' y) → (∀x,y. H2 x = H2' y) → ltb_rect P n m H1 H2 = ltb_rect P n' m' H1' H2'. #P #n #m #H1 #H2 #n' #m' #H1' #H2' #E #K1 #K2 whd in ⊢ (??%?); cut (∀xxx,yyy,xxx',yyy'. match ltb n m return λx:bool. eq bool (ltb n m) x → (lt n m → P) → (Not (lt n m) → P) → P with [ true ⇒ λE0:eq bool (ltb n m) true. λH10:lt n m → P. λH20:Not (lt n m) → P. H10 (xxx E0) | false ⇒ λE0:eq bool (ltb n m) false. λH10:lt n m → P. λH20:Not (lt n m) → P. H20 (yyy E0)] (refl … (ltb n m)) H1 H2 = match ltb n' m' return λx:bool. eq bool (ltb n' m') x → (lt n' m' → P) → (Not (lt n' m') → P) → P with [ true ⇒ λE0:eq bool (ltb n' m') true. λH10:lt n' m' → P. λH20:Not (lt n' m') → P. H10 (xxx' E0) | false ⇒ λE0:eq bool (ltb n' m') false. λH10:lt n' m' → P. λH20:Not (lt n' m') → P. H20 (yyy' E0)] (refl … (ltb n' m')) H1' H2' ) [2: #X @X] >E cases (ltb n' m') #xxx #yyy #xxx' #yyy' normalize [ @K1 | @K2 ] qed. definition tech_cost_of_label: ∀cost_labels: BitVectorTrie costlabel 16. ∀cost_map: identifier_map CostTag nat. ∀codom_dom: (∀pc,k. lookup_opt … pc cost_labels = Some … k → present … cost_map k). list (Σk:costlabel.∃pc. lookup_opt costlabel 16 pc cost_labels = Some ? k) → nat → nat ≝ λcost_labels,cost_map,codom_dom,ctrace,i. ltb_rect ? i (|ctrace|) (λH. lookup_present ?? cost_map (nth_safe ? i ctrace H) ?) (λ_.0). @tech_cost_of_label0 @codom_dom qed. lemma shift_nth_safe: ∀T,i,l2,l1,K1,K2. nth_safe T i l1 K1 = nth_safe T (i+|l2|) (l2@l1) K2. #T #i #l2 elim l2 normalize [ #l1 #K1 le_to_leb_true try assumption applyS le_to_leb_true // |4: >not_le_to_leb_false try assumption applyS not_le_to_leb_false change with (¬ ? ≤ ?) in K1; applyS K1 |2: @⊥ @(absurd (i+|l1| < |l1@l2|)) // >length_append applyS (monotonic_lt_plus_r … (|l1|)) // |3: @⊥ @(absurd ?? K2) >length_append in K1; #K1 /2 by lt_plus_to_lt_l/ ] | #H1 #H2 generalize in match (tech_cost_of_label0 ??? (l1@l2) ??); <(shift_nth_safe … H1) #p % | // ] qed. let rec compute_max_trace_label_return_cost_ok_with_trace (cost_labels: BitVectorTrie costlabel 16) (cost_map: identifier_map CostTag nat) (initial: Status) (final: Status) (trace: trace_label_return (ASM_abstract_status cost_labels) initial final) (codom_dom: (∀pc,k. lookup_opt … pc cost_labels = Some … k → present … cost_map k)) on trace: ∀dom_codom:(∀k. ∀k_pres:present … cost_map k. ∃pc. lookup_opt … pc cost_labels = Some … k → block_cost (code_memory … initial) cost_labels pc 2^16 = lookup_present … k_pres). let ctrace ≝ compute_cost_trace_label_return … trace in compute_max_trace_label_return_cost … trace = (Σ_{i < |ctrace|} (tech_cost_of_label cost_labels cost_map codom_dom ctrace i)) ≝ ? and compute_max_trace_label_label_cost_ok_with_trace (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (cost_map: identifier_map CostTag nat) (initial: Status) (final: Status) (trace: trace_label_label (ASM_abstract_status cost_labels) trace_ends_flag initial final) (codom_dom: (∀pc,k. lookup_opt … pc cost_labels = Some … k → present … cost_map k)) (dom_codom:(∀k. ∀k_pres:present … cost_map k. ∃pc. lookup_opt … pc cost_labels = Some … k → block_cost (code_memory … initial) cost_labels pc 2^16 = lookup_present … k_pres)) on trace: let ctrace ≝ compute_cost_trace_label_label … trace in compute_max_trace_label_label_cost … trace = (Σ_{i < |ctrace|} (tech_cost_of_label cost_labels cost_map codom_dom ctrace i)) ≝ ?. cases trace [ #sb #sa #tr #dom_codom @compute_max_trace_label_label_cost_ok_with_trace @dom_codom | #si #sl #sf #tr1 #tr2 #dom_codom whd in ⊢ (let ctrace ≝ % in ??%?); change with (let ctrace ≝ ? in ? = bigop (|? @ ?|) ?????) >append_length in ⊢ (let ctrace ≝ ? in ???(?%?????)); change with (?=?) >bigop_sum_rev >commutative_plus @eq_f2 [ >(compute_max_trace_label_return_cost_ok_with_trace … cost_map … codom_dom) -compute_max_trace_label_return_cost_ok_with_trace [2:lapply (code_memory_ro_label_label … tr1) #E2 (compute_max_trace_label_label_cost_ok_with_trace … cost_map … codom_dom … dom_codom) @same_bigop [//] #i #H #_ ] (* lemma compute_max_trace_any_label_cost cost_label trace_ends_flag start_status final_status the_trace = let rec compute_paid_trace_label_label_cost (cost_labels: BitVectorTrie Byte 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status) (final_status: Status) (the_trace: trace_label_label (ASM_abstract_status cost_labels) trace_ends_flag start_status final_status) on the_trace: nat ≝ match the_trace with [ tll_base _ _ _ given_trace _ ⇒ compute_paid_trace_any_label_cost … given_trace ] and compute_paid_trace_any_label_cost (cost_labels: BitVectorTrie Byte 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status) (final_status: Status) (the_trace: trace_any_label (ASM_abstract_status cost_labels) trace_ends_flag start_status final_status) on the_trace: nat ≝ match the_trace with [ tal_base_not_return the_status _ _ _ _ ⇒ current_instruction_cost the_status | tal_base_return the_status _ _ _ ⇒ current_instruction_cost the_status | tal_step_call end_flag pre_fun_call start_fun_call after_fun_call final _ _ _ call_trace final_trace ⇒ let current_instruction_cost ≝ current_instruction_cost pre_fun_call in let final_trace_cost ≝ compute_paid_trace_any_label_cost cost_labels end_flag … final_trace in current_instruction_cost + final_trace_cost | tal_step_default end_flag status_pre status_init status_end _ tail_trace _ _ ⇒ let current_instruction_cost ≝ current_instruction_cost status_pre in let tail_trace_cost ≝ compute_paid_trace_any_label_cost cost_labels end_flag status_init status_end tail_trace in current_instruction_cost + tail_trace_cost ] and compute_paid_trace_label_return_cost (cost_labels: BitVectorTrie Byte 16) (start_status: Status) (final_status: Status) (the_trace: trace_label_return (ASM_abstract_status cost_labels) start_status final_status) on the_trace: nat ≝ match the_trace with [ tlr_base before after trace_to_lift ⇒ compute_paid_trace_label_label_cost … trace_to_lift | tlr_step initial labelled final labelled_trace ret_trace ⇒ let labelled_cost ≝ compute_paid_trace_label_label_cost … labelled_trace in let return_cost ≝ compute_paid_trace_label_return_cost … ret_trace in labelled_cost + return_cost ]. let rec trace_lab_rec_cost' (p: trace_lab_ret) : nat. | (call b bf tr af tl) as self ⇒ trace_lab_lab_cost_nocall self + trace_lab_ret_cost' tr + trace_lab_rec_cost' tl theorem main_lemma: ∀p. trace_lab_rec_cost p = trace_lab_rec_cost' p. axiom lemma1: ∀p: simple_path. traverse_cost_internal (pc (hd p)) … = trace_lab_lab_cost_nocall p. axiom lemma2: ∀s,l,cost_map. is_labelled l s → traverse_cost_internal s = cost_map l. axiom main_statement: ∀s. ∀cost_map. let p ≝ compute_simple_path0 s in ∑ (cost_trace p) cost_map = trace_lab_rec_cost' p. axiom main_statement: ∀s. ∀cost_map. let p ≝ compute_simple_path0 s in execute' (path_length p) s = 〈s',τ〉 → Timer s' - Timer s = ∑ τ cost_map. *)