include "ASM/ASMCostsSplit.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 (cm: ?) (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status cm) (final_status: Status cm) (the_trace: trace_label_label (ASM_abstract_status cm 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 (cm: ?) (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status cm) (final_status: Status cm) (the_trace: trace_any_label (ASM_abstract_status cm 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 cm the_status | tal_base_return the_status _ _ _ ⇒ current_instruction_cost cm the_status | tal_base_call pre_fun_call start_fun_call final _ _ _ call_trace _ ⇒ let current_instruction_cost ≝ current_instruction_cost cm pre_fun_call in let call_trace_cost ≝ compute_max_trace_label_return_cost … call_trace in call_trace_cost + current_instruction_cost | 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 cm 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 cm 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 cm status_pre in let tail_trace_cost ≝ compute_max_trace_any_label_cost cm cost_labels end_flag status_init status_end tail_trace in current_instruction_cost + tail_trace_cost ] and compute_max_trace_label_return_cost (cm: ?) (cost_labels: BitVectorTrie costlabel 16) (start_status: Status cm) (final_status: Status cm) (the_trace: trace_label_return (ASM_abstract_status cm 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 ]. include alias "arithmetics/nat.ma". let rec compute_max_trace_label_label_cost_is_ok (cm: ?) (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status cm) (final_status: Status cm) (the_trace: trace_label_label (ASM_abstract_status cm cost_labels) trace_ends_flag start_status final_status) on the_trace: clock … cm … final_status = (compute_max_trace_label_label_cost cm cost_labels trace_ends_flag start_status final_status the_trace) + (clock … cm … start_status) ≝ ? and compute_max_trace_any_label_cost_is_ok (cm: ?) (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status cm) (final_status: Status cm) (the_trace: trace_any_label (ASM_abstract_status cm cost_labels) trace_ends_flag start_status final_status) on the_trace: clock … cm … final_status = (compute_max_trace_any_label_cost cm cost_labels trace_ends_flag start_status final_status the_trace) + (clock … cm … start_status) ≝ ? and compute_max_trace_label_return_cost_is_ok (cm: ?) (cost_labels: BitVectorTrie costlabel 16) (start_status: Status cm) (final_status: Status cm) (the_trace: trace_label_return (ASM_abstract_status cm cost_labels) start_status final_status) on the_trace: clock … cm … final_status = (compute_max_trace_label_return_cost cm cost_labels start_status final_status the_trace) + clock … cm … 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 cm start_status) in ⊢ (???(?%?)); cases(is_next) @execute_1_ok_clock |3: #status_pre_fun_call #status_start_fun_call #status_final #is_next #classifier_assm #after_return_assm #call_trace #costed_assm whd in match (compute_max_trace_any_label_cost … (tal_base_call …)); >(compute_max_trace_label_return_cost_is_ok … call_trace) >associative_plus @eq_f cases(is_next) @execute_1_ok_clock |4: #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 #not_costed #final_trace change with ( let current_instruction_cost ≝ current_instruction_cost cm status_pre_fun_call in let call_trace_cost ≝ compute_max_trace_label_return_cost cm … call_trace in let final_trace_cost ≝ compute_max_trace_any_label_cost cm 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 … cm status_start_fun_call); >(execute_1_ok_clock cm status_pre_fun_call) associative_plus in ⊢ (??%?); >associative_plus in ⊢ (???%); >associative_plus in ⊢ (???%); @eq_f >commutative_plus in ⊢ (??%?); >associative_plus in ⊢ (??%?); @eq_f @commutative_plus |5: #end_flag #status_pre #status_init #status_end #is_next #trace_any_label #is_other #is_not_costed change with ( let current_instruction_cost ≝ current_instruction_cost cm status_pre in let tail_trace_cost ≝ compute_max_trace_any_label_cost cm cost_labels end_flag status_init status_end trace_any_label in current_instruction_cost + tail_trace_cost) in ⊢ (???(?%?)); normalize nodelta; >(compute_max_trace_any_label_cost_is_ok cm cost_labels end_flag status_init status_end trace_any_label) cases(is_next) in match (clock … cm status_init); >(execute_1_ok_clock … 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 cm cost_labels status_labelled status_final ret_trace); >(compute_max_trace_label_label_cost_is_ok cm cost_labels doesnt_end_with_ret status_initial status_labelled labelled_trace); commutative_plus in match ( compute_max_trace_label_return_cost cm cost_labels status_labelled status_final ret_trace + compute_max_trace_label_label_cost cm cost_labels doesnt_end_with_ret status_initial status_labelled labelled_trace); % ] ] qed. let rec compute_trace_label_label_cost_using_paid (cm: ?) (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status cm) (final_status: Status cm) (the_trace: trace_label_label (ASM_abstract_status cm 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 cm cost_labels … the_trace + compute_trace_any_label_cost_using_paid … given_trace ] and compute_trace_any_label_cost_using_paid (cm: ?) (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status cm) (final_status: Status cm) (the_trace: trace_any_label (ASM_abstract_status cm 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_base_call pre_fun_call start_fun_call final _ _ _ call_trace _ ⇒ compute_trace_label_return_cost_using_paid … call_trace | 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 cm 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 cm cost_labels end_flag status_init status_end tail_trace ] and compute_trace_label_return_cost_using_paid (cm: ?) (cost_labels: BitVectorTrie costlabel 16) (start_status: Status cm) (final_status: Status cm) (the_trace: trace_label_return (ASM_abstract_status cm 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 (cm: ?) (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status cm) (final_status: Status cm) (the_trace: trace_label_label (ASM_abstract_status cm cost_labels) trace_ends_flag start_status final_status) on the_trace: compute_trace_label_label_cost_using_paid cm cost_labels … the_trace = compute_max_trace_label_label_cost … the_trace ≝ ? and compute_trace_any_label_cost_using_paid_ok (cm: ?) (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status cm) (final_status: Status cm) (the_trace: trace_any_label (ASM_abstract_status cm cost_labels) trace_ends_flag start_status final_status) on the_trace: compute_paid_trace_any_label cm cost_labels trace_ends_flag … the_trace +compute_trace_any_label_cost_using_paid cm cost_labels trace_ends_flag … the_trace =compute_max_trace_any_label_cost cm cost_labels trace_ends_flag … the_trace ≝ ? and compute_trace_label_return_cost_using_paid_ok (cm: ?) (cost_labels: BitVectorTrie costlabel 16) (start_status: Status cm) (final_status: Status cm) (the_trace: trace_label_return (ASM_abstract_status cm cost_labels) start_status final_status) on the_trace: compute_trace_label_return_cost_using_paid cm cost_labels … the_trace = compute_max_trace_label_return_cost cm 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 ⊢ (??(?%%)%); compute_trace_label_return_cost_using_paid_ok in ⊢ (??%?); >commutative_plus in ⊢ (??%?); @eq_f % | #ef #spfc #ssfc #safc #sf #H1 #H2 #H3 #tr1 #H4 #tr2 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. include alias "ASM/BitVectorTrie.ma". (* let rec compute_cost_trace_label_label (cm: BitVectorTrie Byte 16) (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status cm) (final_status: Status cm) (the_trace: trace_label_label (ASM_abstract_status cm cost_labels) trace_ends_flag start_status final_status) on the_trace: list (Σk:costlabel. ∃pc: Word. 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 ? cm initial in let label ≝ match lookup_opt … pc cost_labels return λx: option ?. x ≠ None … → costlabel with [ None ⇒ λabs. ⊥ | Some l ⇒ λ_. l ] labelled_proof in (mk_Sig ?? label ?)::compute_cost_trace_any_label cm cost_labels ends_flag initial final … given_trace ] and compute_cost_trace_any_label (cm: BitVectorTrie Byte 16) (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (start_status: Status cm) (final_status: Status cm) (the_trace: trace_any_label (ASM_abstract_status cm 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_call pre_fun_call start_fun_call final _ _ _ call_trace _ ⇒ compute_cost_trace_label_return … call_trace | 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 cm 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 cm cost_labels end_flag status_init status_end tail_trace ] and compute_cost_trace_label_return (cm: BitVectorTrie Byte 16) (cost_labels: BitVectorTrie costlabel 16) (start_status: Status cm) (final_status: Status cm) (the_trace: trace_label_return (ASM_abstract_status cm 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 cm … trace_to_lift | tlr_step initial labelled final labelled_trace ret_trace ⇒ let labelled_cost ≝ compute_cost_trace_label_label cm … labelled_trace in let return_cost ≝ compute_cost_trace_label_return cm … ret_trace in labelled_cost @ return_cost ]. [1: %{pc} whd in match label; generalize in match labelled_proof; whd in ⊢ (% → ?); whd in match (as_costed ??); whd in match (as_label ??); normalize nodelta cases (lookup_opt costlabel … (program_counter … initial) cost_labels) normalize [ #abs cases abs #absurd @⊥ @absurd % | // ] | cases abs #absurd @absurd % ] qed. *) include alias "arithmetics/nat.ma". include alias "basics/logic.ma". include alias "arithmetics/bigops.ma". (* 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)}. 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.∃b.lookup_opt … b 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.∃b.lookup_opt … b 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 tech_cost_of_label_shift: ∀cost_labels,cost_map,codom_dom,l1,l2,i. i < |l2| → tech_cost_of_label cost_labels cost_map codom_dom l2 i = tech_cost_of_label cost_labels cost_map codom_dom (l1@l2) (i+|l1|). #cost_labels #cost_Map #codom_dom #l1 #l2 #i #H whd in match tech_cost_of_label; normalize nodelta @same_ltb_rect [ @(ltb_rect ? i (|l2|)) @(ltb_rect ? (i+|l1|) (|l1@l2|)) #K1 #K2 whd in match ltb; normalize nodelta [1: >le_to_leb_true try assumption applyS le_to_leb_true / by / |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|)) / by / >length_append applyS (monotonic_lt_plus_r … (|l1|)) / by / |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 % | / by / ] qed. lemma tech_cost_of_label_prefix: ∀cost_labels,cost_map,codom_dom,l1,l2,i. i < |l1| → tech_cost_of_label cost_labels cost_map codom_dom l1 i = tech_cost_of_label cost_labels cost_map codom_dom (l1@l2) i. #cost_labels #cost_map #codom_dom #l1 #l2 #i #H whd in match tech_cost_of_label; normalize nodelta @same_ltb_rect [1: whd in match ltb; normalize nodelta >(le_to_leb_true … H) applyS le_to_leb_true >length_append whd in H; >commutative_plus @le_plus_a assumption |2: #K1 #K2 generalize in match (tech_cost_of_label0 ??? (l1@l2) ??); <(shift_nth_prefix … l1 i l2 K1 K2) // |3: #_ #_ % ] qed. let rec compute_trace_label_return_using_paid_ok_with_trace (cm: ?) (cost_labels: BitVectorTrie costlabel 16) (cost_map: identifier_map CostTag nat) (initial: Status cm) (final: Status cm) (trace: trace_label_return (ASM_abstract_status cm cost_labels) initial final) (codom_dom: (∀pc,k. lookup_opt … pc cost_labels = Some … k → present … cost_map k)) on trace: ∀unrepeating_witness: tlr_unrepeating … trace. ∀dom_codom:(∀k. ∀k_pres:present … cost_map k. ∀pc. lookup_opt … pc cost_labels = Some … k → pi1 … (block_cost cm pc cost_labels) = lookup_present … k_pres). let ctrace ≝ flatten_trace_label_return (ASM_abstract_status cm cost_labels) … trace in compute_trace_label_return_cost_using_paid cm … trace = (Σ_{i < |ctrace|} (tech_cost_of_label cost_labels cost_map codom_dom ctrace i)) ≝ ? and compute_trace_any_label_using_paid_ok_with_trace (cm: ?) (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (cost_map: identifier_map CostTag nat) (initial: Status cm) (final: Status cm) (trace: trace_any_label (ASM_abstract_status cm 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 → pi1 … (block_cost cm pc cost_labels) = lookup_present … k_pres)) on trace: ∀unrepeating_witness: tal_unrepeating … trace. let ctrace ≝ flatten_trace_any_label (ASM_abstract_status cm cost_labels) … trace_ends_flag … trace in compute_trace_any_label_cost_using_paid … trace = (Σ_{i < |ctrace|} (tech_cost_of_label cost_labels cost_map codom_dom ctrace i)) ≝ ? and compute_trace_label_label_using_paid_ok_with_trace (cm: ?) (cost_labels: BitVectorTrie costlabel 16) (trace_ends_flag: trace_ends_with_ret) (cost_map: identifier_map CostTag nat) (initial: Status cm) (final: Status cm) (trace: trace_label_label (ASM_abstract_status cm cost_labels) trace_ends_flag initial final) (unrepeating_witness: tll_unrepeating … trace) (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 → pi1 … (block_cost cm pc cost_labels) = lookup_present … k_pres)) on trace: ∀unrepeating_witness: tll_unrepeating … trace. let ctrace ≝ flatten_trace_label_label (ASM_abstract_status cm cost_labels) … trace in compute_trace_label_label_cost_using_paid … trace = (Σ_{i < |ctrace|} (tech_cost_of_label cost_labels cost_map codom_dom ctrace i)) ≝ ?. cases trace normalize nodelta [ #sb #sa #tr #unrepeating_witness #dom_codom whd in ⊢ (??%?); whd in match (flatten_trace_label_return ????); @compute_trace_label_label_using_paid_ok_with_trace assumption | #si #sl #sf #tr1 #tr2 #unrepeating_witness #dom_codom whd in ⊢ (??%?); whd in match (flatten_trace_label_return ????); >append_length >bigop_sum_rev >commutative_plus @eq_f2 [ >(compute_trace_label_return_using_paid_ok_with_trace … cost_map … codom_dom ? dom_codom) -compute_trace_label_return_using_paid_ok_with_trace [1: @same_bigop [//] #i #H #_ -dom_codom @tech_cost_of_label_shift // |2: inversion unrepeating_witness #tll_unrepeating #tlr_unrepeating #_ assumption ] | >(compute_trace_label_label_using_paid_ok_with_trace … cost_map … codom_dom … dom_codom) -compute_trace_label_label_using_paid_ok_with_trace [1: @same_bigop [//] #i #H #_ @(tech_cost_of_label_prefix … H) |2,3: inversion unrepeating_witness #tll_unrepeating #tlr_unrepeating #_ assumption ] ] |8: #end_flag #start_status #end_status #trace_any_label #costed_assm #unrepeating_witness' whd in ⊢ (??%?); whd in ⊢ (??(?%?)?); >(compute_trace_any_label_using_paid_ok_with_trace … cost_map … codom_dom … dom_codom) [1: whd in match (flatten_trace_label_label ?????); >bigop_0 in ⊢ (???%); >commutative_plus @eq_f2 [1: @same_bigop [//] #i #H #_ -dom_codom >(plus_n_O i) >plus_n_Sm <(tech_cost_of_label_shift ??? [?] ? i) try assumption <(plus_n_O i) % |2: change with (? = lookup_present ? ? ? ? ?) generalize in match (tech_cost_of_label0 ? ? ? ? ? ?); normalize in match (nth_safe ? ? ? ?); whd in costed_assm; lapply costed_assm whd in match (as_label ??); inversion (lookup_opt ? ? (program_counter … cm start_status) cost_labels) [1: #_ #absurd @⊥ cases absurd #absurd @absurd % |2: normalize nodelta #cost_label #Some_assm #_ #p cases (dom_codom ? p ? Some_assm) cases (block_cost ???) #cost #block_cost_assm cases (block_cost_assm ??? trace_any_label ??) try @refl assumption ] ] |2: assumption ] |3: #start_status #final_status #execute_assm #classifier_assm #costed_assm #unrepeating_witness % |4: #start_status #final_status #execute_assm #classifier_assm #unrepeating_witness % |5: #status_pre_fun_call #status_start_fun_call #status_final #execute_assm #classifier_assm #after_return_assm #trace_label_return #costed_assm #unrepeating_witness whd in ⊢ (??%?); @(compute_trace_label_return_using_paid_ok_with_trace … cost_map … codom_dom ? dom_codom) assumption |6: #end_flag #status_pre_fun_call #status_start_fun_call #status_after_fun_call #status_final #execute_assm #classifier_assm #after_return_assm #trace_label_return #costed_assm #trace_any_label #unrepeating_witness whd in ⊢ (??%?); >(compute_trace_label_return_using_paid_ok_with_trace … cost_map … codom_dom ? dom_codom) [1: >(compute_trace_any_label_using_paid_ok_with_trace … cost_map … codom_dom … dom_codom) [1: >length_append >bigop_sum_rev >commutative_plus @eq_f2 [ @same_bigop [2: #i #H #_ -dom_codom @tech_cost_of_label_shift assumption |1: #i #H % ] | @same_bigop [#i #H %] #i #H #_ @(tech_cost_of_label_prefix … H) ] |2: inversion unrepeating_witness * #memb_1 #tal_unrepeating #tlr_unrepeating #_ assumption ] |2: inversion unrepeating_witness * #memb_1 #tal_unrepeating #tlr_unrepeating #_ assumption ] |7: #end_flag #status_pre_fun_call #status_start_fun_call #status_final #execute_assm #trace_any_label #classifier_assm #costed_assm #unrepeating_witness whd in ⊢ (??%?); @(compute_trace_any_label_using_paid_ok_with_trace … cost_map … codom_dom … dom_codom) inversion unrepeating_witness #memb_1 #tal_unrepeating #_ assumption ] qed. lemma compute_max_trace_label_return_cost_ok_with_trace_aux: ∀code_memory: BitVectorTrie Byte 16. ∀cost_labels: BitVectorTrie costlabel 16. ∀cost_map: identifier_map CostTag nat. ∀initial: Status code_memory. ∀final: Status code_memory. ∀trace: trace_label_return (ASM_abstract_status code_memory cost_labels) initial final. ∀unrepeating_witness: tlr_unrepeating … trace. ∀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 → pi1 … (block_cost code_memory pc cost_labels) = lookup_present … k_pres). let ctrace ≝ flatten_trace_label_return … trace in clock … code_memory … final = clock … code_memory … initial + (Σ_{i < |ctrace|} (tech_cost_of_label cost_labels cost_map codom_dom ctrace i)). #code_memory #cost_labels #cost_map #initial #final #trace #unrepeating_witness #codom_dom #dom_codom normalize nodelta commutative_plus >compute_trace_label_return_cost_using_paid_ok // qed. theorem compute_max_trace_label_return_cost_ok_with_trace: ∀code_memory: BitVectorTrie Byte 16. ∀cost_labels: BitVectorTrie costlabel 16. ∀cost_labels_injective: (∀pc,pc',l. lookup_opt costlabel 16 pc cost_labels=Some costlabel l →lookup_opt costlabel 16 pc' cost_labels=Some costlabel l→pc=pc'). ∀initial: Status code_memory. ∀final: Status code_memory. ∀trace: trace_label_return (ASM_abstract_status code_memory cost_labels) initial final. ∀unrepeating_witness: tlr_unrepeating … trace. let cost_map ≝ traverse_code code_memory cost_labels cost_labels_injective in let ctrace ≝ flatten_trace_label_return … trace in clock … code_memory … final = clock … code_memory … initial + (Σ_{i < |ctrace|} (tech_cost_of_label cost_labels cost_map ? ctrace i)). [1: #code_memory #cost_labels #cost_labels_injective #initial #final #trace #unrepeating_witness @compute_max_trace_label_return_cost_ok_with_trace_aux try assumption |2: skip ] normalize nodelta cases (traverse_code ???) #cost_map * #dom_codom #codom_dom try assumption #pc #k #lookup_opt_assm @(dom_codom … lookup_opt_assm) lapply (sym_eq ? ? ? lookup_opt_assm) -lookup_opt_assm #lookup_opt_assm @nat_of_bitvector_lt_bound qed. include "utilities/permutations.ma". lemma tech_cost_sum_eq_as_cost : ∀code_memory: BitVectorTrie Byte 16. ∀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). ∀trace. (Σ_{i < |trace|}(tech_cost_of_label cost_labels cost_map codom_dom trace i)) = (Σ_{l ∈ trace}(ASM_cost_map code_memory … codom_dom l)). #cmem #clab #cmap #codom_dom #trace @(list_elim_left … trace) [ % | #tl #hd #IH >append_length >commutative_plus >(fold_permute … (hd@[tl]) (tl::hd)) [2: @perm_swap_append ] whd in ⊢ (??%%);