[2286] | 1 | include "joint/TranslateUtils.ma". |
---|
[2473] | 2 | include "common/extraGlobalenvs.ma". |
---|
[2200] | 3 | include "utilities/hide.ma". |
---|
[2182] | 4 | |
---|
| 5 | definition graph_to_lin_statement : |
---|
| 6 | ∀p : unserialized_params.∀globals. |
---|
| 7 | joint_statement (mk_graph_params p) globals → joint_statement (mk_lin_params p) globals ≝ |
---|
| 8 | λp,globals,stmt.match stmt return λ_.joint_statement (mk_lin_params ?) ? with |
---|
| 9 | [ sequential c _ ⇒ sequential … c it |
---|
| 10 | | final c ⇒ final … c |
---|
| 11 | ]. |
---|
| 12 | |
---|
| 13 | lemma graph_to_lin_labels : |
---|
| 14 | ∀p : unserialized_params.∀globals,s. |
---|
| 15 | stmt_labels … (graph_to_lin_statement p globals s) = |
---|
| 16 | stmt_explicit_labels … s. |
---|
| 17 | #p#globals * [//] * // |
---|
| 18 | qed. |
---|
| 19 | |
---|
| 20 | (* discard all elements passing test, return first element failing it *) |
---|
| 21 | (* and the rest of the list, if any. *) |
---|
| 22 | let rec chop A (test : A → bool) (l : list A) on l : option (A × (list A)) ≝ |
---|
| 23 | match l with |
---|
| 24 | [ nil ⇒ None ? |
---|
| 25 | | cons x l' ⇒ if test x then chop A test l' else return 〈x, l'〉 |
---|
| 26 | ]. |
---|
| 27 | |
---|
| 28 | lemma chop_ok : ∀A,f,l. |
---|
| 29 | match chop A f l with |
---|
| 30 | [ Some pr ⇒ |
---|
| 31 | let x ≝ \fst pr in |
---|
| 32 | let post ≝ \snd pr in |
---|
| 33 | ∃pre.All ? (λx.bool_to_Prop (f x)) pre ∧ |
---|
| 34 | l = pre @ x :: post ∧ ¬bool_to_Prop (f x) |
---|
| 35 | | None ⇒ All A (λx.bool_to_Prop (f x)) l |
---|
| 36 | ]. |
---|
| 37 | #A #f #l elim l |
---|
| 38 | [ % |
---|
| 39 | | #hd #tl #IH whd in match (chop ???); |
---|
| 40 | elim (true_or_false_Prop (f hd)) #H >H normalize nodelta |
---|
| 41 | [ lapply IH elim (chop ???) normalize nodelta |
---|
| 42 | [ #G %{H G} |
---|
| 43 | | #pr * #pre ** #H1 #H2 #H3 %{(hd :: pre)} %{H3} % |
---|
| 44 | [ %{H H1} |
---|
| 45 | | >H2 % |
---|
| 46 | ] |
---|
| 47 | ] |
---|
| 48 | | %{[ ]} %{H} %% |
---|
| 49 | ] |
---|
| 50 | ] |
---|
| 51 | qed. |
---|
| 52 | |
---|
| 53 | unification hint 0 ≔ p, globals; |
---|
| 54 | lp ≟ lin_params_to_params p, |
---|
| 55 | sp ≟ stmt_pars lp, |
---|
| 56 | js ≟ joint_statement sp globals, |
---|
| 57 | lo ≟ labelled_obj LabelTag js |
---|
| 58 | (*----------------------------*)⊢ |
---|
| 59 | list lo ≡ codeT lp globals. |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | definition graph_visit_ret_type ≝ λp,globals.λg : codeT (mk_graph_params p) globals. |
---|
| 63 | λentry : label. |
---|
| 64 | (Σ〈visited' : identifier_map LabelTag ℕ, |
---|
| 65 | required' : identifier_set LabelTag, |
---|
| 66 | generated' : codeT (mk_lin_params p) globals〉.'hide ( |
---|
| 67 | And (And (And (And |
---|
| 68 | (lookup ?? visited' entry = Some ? 0) |
---|
| 69 | (required' ⊆ visited')) |
---|
| 70 | (∃last.stmt_at … generated' 0 = Some ? (final … last))) |
---|
| 71 | (code_forall_labels … (λl.bool_to_Prop (l∈required')) (rev … generated'))) |
---|
| 72 | (∀l,n.lookup ?? visited' l = Some ? n → |
---|
| 73 | And (bool_to_Prop (code_has_label … (rev ? generated') l)) |
---|
| 74 | (∃s.And (And |
---|
| 75 | (lookup … g l = Some ? s) |
---|
| 76 | (nth_opt … n (rev … generated') = Some ? 〈Some ? l, graph_to_lin_statement … s〉)) |
---|
| 77 | (opt_All ? |
---|
| 78 | (λnext.Or (lookup … visited' next = Some ? (S n)) |
---|
| 79 | (nth_opt … (S n) (rev … generated') = Some ? 〈None ?, GOTO … next〉)) |
---|
| 80 | (stmt_implicit_label … s)))))). |
---|
| 81 | |
---|
| 82 | unification hint 0 ≔ tag ⊢ identifier_set tag ≡ identifier_map tag unit. |
---|
| 83 | |
---|
| 84 | include alias "common/Identifiers.ma". |
---|
| 85 | |
---|
| 86 | lemma lookup_safe_elim : ∀tag,A.∀P : A → Prop.∀m,i,prf. |
---|
| 87 | (∀x.lookup tag A m i = Some ? x → P x) → P (lookup_safe tag A m i prf). |
---|
| 88 | #tag #A #P #m #i #prf #H @H @lookup_eq_safe qed. |
---|
| 89 | |
---|
| 90 | let rec graph_visit |
---|
| 91 | (p : unserialized_params) |
---|
| 92 | (globals: list ident) |
---|
| 93 | (g : codeT (mk_graph_params p) globals) |
---|
| 94 | (* = graph (joint_statement (mk_graph_params p) globals *) |
---|
| 95 | (required: identifier_set LabelTag) |
---|
| 96 | (visited: identifier_map LabelTag ℕ) (* the reversed index of labels in the new code *) |
---|
| 97 | (generated: codeT (mk_lin_params p) globals) |
---|
| 98 | (* ≝ list ((option label)×(joint_statement (mk_lin_params p) globals)) *) |
---|
| 99 | (visiting: list label) |
---|
| 100 | (gen_length : ℕ) |
---|
| 101 | (n: nat) |
---|
| 102 | (entry : label) |
---|
| 103 | (g_prf : code_closed … g) |
---|
| 104 | (required_prf1 : ∀i.i∈required → Or (In ? visiting i) (bool_to_Prop (i∈visited))) |
---|
| 105 | (required_prf2 : code_forall_labels … (λl.bool_to_Prop (l ∈ required)) (rev … generated)) |
---|
| 106 | (generated_prf1 : ∀l,n.lookup … visited l = Some ? n → hide_Prop ( |
---|
| 107 | And (bool_to_Prop (code_has_label … (rev ? generated) l)) |
---|
| 108 | (∃s.And (And |
---|
| 109 | (lookup … g l = Some ? s) |
---|
| 110 | (nth_opt ? n (rev … generated) = Some ? 〈Some ? l, graph_to_lin_statement … s〉)) |
---|
| 111 | (opt_All ? (λnext.match lookup … visited next with |
---|
| 112 | [ Some n' ⇒ Or (n' = S n) (nth_opt ? (S n) (rev ? generated) = Some ? 〈None ?, GOTO … next〉) |
---|
| 113 | | None ⇒ And (nth_opt ? 0 visiting = Some ? next) (S n = gen_length) ]) (stmt_implicit_label … s))))) |
---|
| 114 | (generated_prf2 : ∀l.lookup … visited l = None ? → does_not_occur … l (rev ? generated)) |
---|
| 115 | (generated_prf3 : (∃last.stmt_at … generated 0 = Some ? (final … last)) ∨ |
---|
| 116 | (¬All ? (λx.bool_to_Prop (x∈visited)) visiting)) |
---|
| 117 | (visiting_prf : All … (λl.bool_to_Prop (l∈g)) visiting) |
---|
| 118 | (gen_length_prf : gen_length = length ? generated) |
---|
| 119 | (entry_prf : Or (And (And (visiting = [entry]) (gen_length = 0)) (Not (bool_to_Prop (entry∈visited)))) |
---|
| 120 | (lookup … visited entry = Some ? 0)) |
---|
| 121 | (n_prf : le (id_map_size … g) (plus n (id_map_size … visited))) |
---|
| 122 | on n |
---|
| 123 | : graph_visit_ret_type … g entry ≝ |
---|
| 124 | match chop ? (λx.x∈visited) visiting |
---|
| 125 | return λx.? → graph_visit_ret_type … g entry with |
---|
| 126 | [ None ⇒ λH. |
---|
| 127 | «〈visited, required, generated〉, ?» |
---|
| 128 | | Some pr ⇒ λH. |
---|
| 129 | let vis_hd ≝ \fst pr in |
---|
| 130 | let vis_tl ≝ \snd pr in |
---|
| 131 | match n return λx.? → graph_visit_ret_type … g entry with |
---|
| 132 | [ O ⇒ λn_prf'.⊥ |
---|
| 133 | | S n' ⇒ λn_prf'. |
---|
| 134 | (* add the label to the visited ones *) |
---|
| 135 | let visited' ≝ add … visited vis_hd gen_length in |
---|
| 136 | (* take l's statement *) |
---|
| 137 | let hd_vis_in_g ≝ (hide_prf ? ?) in |
---|
| 138 | let statement ≝ lookup_safe ?? g vis_hd hd_vis_in_g in |
---|
| 139 | (* translate it to its linear version *) |
---|
| 140 | let translated_statement ≝ graph_to_lin_statement p globals statement in |
---|
| 141 | (* add the translated statement to the code (which will be reversed later) *) |
---|
| 142 | let generated' ≝ 〈Some … vis_hd, translated_statement〉 :: generated in |
---|
| 143 | let required' ≝ union_set ??? (set_from_list … (stmt_explicit_labels … statement)) required in |
---|
| 144 | (* put successors in the visiting worklist *) |
---|
| 145 | let visiting' ≝ stmt_labels … statement @ vis_tl in |
---|
| 146 | (* finally, check the implicit successor *) |
---|
| 147 | (* if it has been already visited, we need to add a GOTO *) |
---|
| 148 | let add_req_gen ≝ |
---|
| 149 | match stmt_implicit_label … statement |
---|
| 150 | with |
---|
| 151 | [ Some next ⇒ |
---|
| 152 | if next ∈ visited' then |
---|
| 153 | 〈1, {(next)}, [〈None label, (GOTO … next : joint_statement ??)〉]〉 |
---|
| 154 | else 〈0, ∅, [ ]〉 |
---|
| 155 | | None ⇒ 〈0, ∅, [ ]〉 |
---|
| 156 | ] in |
---|
| 157 | (* prepare a common utility to deal with add_req_gen *) |
---|
| 158 | let add_req_gen_prf : |
---|
| 159 | ∀P : (ℕ × (identifier_set LabelTag) × (codeT (mk_lin_params p) globals)) → Prop. |
---|
| 160 | (opt_All ? (λnext.¬bool_to_Prop (next ∈ visited')) (stmt_implicit_label … statement) → |
---|
| 161 | P 〈0,∅,[ ]〉) → |
---|
| 162 | (∀next.stmt_implicit_label … statement = Some ? next → |
---|
| 163 | next ∈ visited' → |
---|
| 164 | P 〈1, {(next)}, [〈None ?, GOTO (mk_lin_params p) next〉]〉) → |
---|
| 165 | P add_req_gen ≝ hide_prf ?? in |
---|
| 166 | graph_visit ??? |
---|
| 167 | (union_set ??? (\snd (\fst add_req_gen)) required') |
---|
| 168 | visited' |
---|
| 169 | (\snd add_req_gen @ generated') |
---|
| 170 | visiting' |
---|
| 171 | (plus (\fst (\fst add_req_gen)) (S gen_length)) |
---|
| 172 | n' entry g_prf ????????? |
---|
| 173 | ] n_prf |
---|
| 174 | ] (chop_ok ? (λx.x∈visited) visiting). |
---|
[2529] | 175 | (* cases daemon qed. *) |
---|
[2182] | 176 | whd |
---|
| 177 | [ (* base case, visiting is all visited *) |
---|
| 178 | %[%[%[%]]] |
---|
| 179 | [ elim entry_prf |
---|
| 180 | [ ** #eq_visiting #gen_length_O #entry_vis >eq_visiting in H; * >entry_vis * |
---|
| 181 | | // |
---|
| 182 | ] |
---|
| 183 | | #l #l_req |
---|
| 184 | elim (required_prf1 … l_req) #G |
---|
| 185 | [ @(All_In … H G) |
---|
| 186 | | assumption |
---|
| 187 | ] |
---|
| 188 | | cases generated_prf3 [//] |
---|
| 189 | * #ABS @⊥ @ABS assumption |
---|
| 190 | | assumption |
---|
| 191 | | #l #n #H elim (generated_prf1 … H) |
---|
| 192 | #H1 * #s ** #H2 #H3 #H4 |
---|
| 193 | % [assumption] %{s} % |
---|
| 194 | [% assumption |
---|
| 195 | | @(opt_All_mp … H4) -l #l |
---|
| 196 | lapply (in_map_domain … visited l) |
---|
| 197 | elim (true_or_false_Prop (l∈visited)) #l_vis >l_vis |
---|
| 198 | normalize nodelta [ * #n' ] #EQlookup >EQlookup |
---|
| 199 | normalize nodelta * |
---|
| 200 | [ #EQn' % >EQn' % |
---|
| 201 | | #H %2{H} |
---|
| 202 | | #H' lapply (All_nth … H … H') >l_vis * |
---|
| 203 | ] |
---|
| 204 | ] |
---|
| 205 | ] |
---|
| 206 | (* first, close goals where add_gen_req plays no role *) |
---|
| 207 | |13: (* vis_hd is in g *) |
---|
| 208 | elim H #pre ** #_ #H2 #_ |
---|
| 209 | @(All_split … visiting_prf … H2) |
---|
| 210 | |2: (* n = 0 absrud *) |
---|
| 211 | elim H #pre ** #_ #H2 #H3 |
---|
| 212 | @(absurd … n_prf') |
---|
| 213 | @lt_to_not_le |
---|
| 214 | lapply (add_size … visited vis_hd 0 (* dummy value *)) |
---|
| 215 | >H3 normalize nodelta |
---|
| 216 | whd in match (lt ? ?); |
---|
| 217 | whd in match (1 + ?); |
---|
| 218 | #EQ <EQ @subset_card @add_subset |
---|
| 219 | [ @(All_split ? (λx.bool_to_Prop (x∈g)) ????? H2) @(All_mp … visiting_prf) |
---|
| 220 | #a elim g #gm whd in ⊢ (?→?%); #H >(lookup_eq_safe … H) % |
---|
| 221 | | #l #H |
---|
| 222 | elim (generated_prf1 … (lookup_eq_safe … H)) #_ * #s ** #s_in_g #_ #_ |
---|
| 223 | whd in ⊢ (?%); >s_in_g % |
---|
| 224 | ] |
---|
| 225 | |8: |
---|
| 226 | elim H #pre ** #_ #H2 #_ |
---|
| 227 | @All_append |
---|
| 228 | [ elim(g_prf … vis_hd statement ?) [2:@lookup_eq_safe] #G1 #G2 |
---|
| 229 | @(All_append … G1) |
---|
| 230 | whd in G2; lapply G2 elim statement normalize nodelta #s [2: #_ %] |
---|
| 231 | #l #G' %{G'} % |
---|
| 232 | | >H2 in visiting_prf; |
---|
| 233 | #H' lapply (All_append_r … H') -H' * #_ // |
---|
| 234 | ] |
---|
| 235 | |10: |
---|
| 236 | elim H #pre ** #_ #H2 #H3 -add_req_gen_prf |
---|
| 237 | %2 elim entry_prf |
---|
| 238 | [ ** >H2 cases pre |
---|
| 239 | [2: #x' #pre' #ABS normalize in ABS; destruct(ABS) |
---|
| 240 | cases pre' in e0; [2: #x'' #pre''] #ABS' normalize in ABS'; destruct(ABS') |
---|
| 241 | |1: #EQ normalize in EQ; destruct(EQ) |
---|
| 242 | #eq_gen_length #_ |
---|
| 243 | >lookup_add_hit >eq_gen_length % |
---|
| 244 | ] |
---|
| 245 | | #lookup_entry cut (entry ≠ vis_hd) |
---|
| 246 | [ % whd in match vis_hd; #entry_vis_hd <entry_vis_hd in H3; |
---|
| 247 | whd in ⊢ (?(?%)→?); >lookup_entry * #ABS @ABS % ] |
---|
| 248 | #entry_not_vis_hd >(lookup_add_miss ?????? entry_not_vis_hd) assumption |
---|
| 249 | ] |
---|
| 250 | |11: |
---|
| 251 | elim H #pre ** #_ #_ #H3 |
---|
| 252 | >commutative_plus |
---|
| 253 | >add_size >H3 normalize nodelta |
---|
| 254 | whd in match (1 + ?); |
---|
| 255 | >commutative_plus |
---|
| 256 | assumption |
---|
| 257 | |12: (* add_req_gen utility *) |
---|
| 258 | #P whd in match add_req_gen; |
---|
| 259 | elim (stmt_implicit_label ???) |
---|
| 260 | [ #H #_ @H % ] |
---|
| 261 | #next normalize nodelta elim (true_or_false_Prop (next ∈ visited')) #next_vis |
---|
| 262 | >next_vis normalize nodelta |
---|
| 263 | [ #_ #H @H [% | assumption] |
---|
| 264 | | #H #_ @H whd >next_vis % * |
---|
| 265 | ] |
---|
| 266 | | elim H #pre ** #H1 #H2 #_ |
---|
| 267 | #i >mem_set_union |
---|
| 268 | #H elim (orb_Prop_true … H) -H |
---|
| 269 | [ @add_req_gen_prf [ #_ >mem_set_empty * ] |
---|
| 270 | #next #_ #next_vis #H >(mem_set_singl_to_eq … H) %2 assumption |
---|
| 271 | | >mem_set_union |
---|
| 272 | #H elim (orb_Prop_true … H) -H |
---|
| 273 | [ #i_expl %1 @Exists_append_l @Exists_append_r |
---|
| 274 | @mem_list_as_set |
---|
| 275 | @i_expl |
---|
| 276 | | (* i was already required *) |
---|
| 277 | #i_req |
---|
| 278 | elim (required_prf1 … i_req) |
---|
| 279 | [ >H2 #H elim (Exists_append … H) -H |
---|
| 280 | [ (* i in preamble → i∈visited *) |
---|
| 281 | #i_pre %2 >mem_set_add @orb_Prop_r |
---|
| 282 | lapply (All_In … H1 i_pre) #H @H |
---|
| 283 | | * |
---|
| 284 | [ (* i is vis_hd *) |
---|
| 285 | #eq_i >eq_i %2 @mem_set_add_id |
---|
| 286 | | (* i in vis_tl → i∈visiting' *) |
---|
| 287 | #i_post % @Exists_append_r assumption |
---|
| 288 | ] |
---|
| 289 | ] |
---|
| 290 | | (* i in visited *) |
---|
| 291 | #i_vis %2 >mem_set_add @orb_Prop_r assumption |
---|
| 292 | ] |
---|
| 293 | ] |
---|
| 294 | ] |
---|
| 295 | |4,5,6: change with reverse in match rev; |
---|
| 296 | >reverse_append whd in match (reverse ??); >rev_append_def |
---|
| 297 | >associative_append |
---|
| 298 | [ #pt #s |
---|
| 299 | @(leb_elim (S pt) (|generated|)) #cmp |
---|
| 300 | whd in match (stmt_at ????); |
---|
| 301 | [ >nth_opt_append_l [2: >length_reverse assumption ] |
---|
| 302 | change with (stmt_at ???? = ? → ?) |
---|
| 303 | #EQ lapply(required_prf2 … EQ) @All_mp |
---|
| 304 | #l #l_req >mem_set_union @orb_Prop_r |
---|
| 305 | >mem_set_union @orb_Prop_r @l_req |
---|
| 306 | | >nth_opt_append_r [2: >length_reverse @not_lt_to_le assumption ] |
---|
| 307 | cases (pt - ?) |
---|
| 308 | [ whd in match (nth_opt ???); whd in ⊢ (??%?→?); |
---|
| 309 | #EQ destruct(EQ) whd |
---|
| 310 | >graph_to_lin_labels in ⊢ (???%); |
---|
| 311 | whd in match required'; |
---|
| 312 | generalize in match (stmt_explicit_labels … statement); |
---|
| 313 | #l @list_as_set_All |
---|
| 314 | #i >mem_set_union >mem_set_union |
---|
| 315 | #i_l @orb_Prop_r @orb_Prop_l @i_l |
---|
| 316 | | @add_req_gen_prf |
---|
| 317 | [ #_ | #next #_ #next_vis * |
---|
| 318 | [ whd in ⊢ (??%?→?); |
---|
| 319 | #EQ' destruct(EQ') whd %{I} >mem_set_union |
---|
| 320 | @orb_Prop_l @mem_set_add_id ]] |
---|
| 321 | #n whd in ⊢ (??%?→?); #ABS destruct(ABS) |
---|
| 322 | ] |
---|
| 323 | ] |
---|
| 324 | | elim H #pre ** #H1 #H2 #H3 |
---|
| 325 | #i whd in match visited'; |
---|
| 326 | @(eq_identifier_elim … i vis_hd) |
---|
| 327 | [ #EQi >EQi -i #pos |
---|
| 328 | >lookup_add_hit #EQpos (* too slow: destruct(EQpos) *) |
---|
| 329 | cut (gen_length = pos) |
---|
| 330 | [1,3,5: (* BUG: -graph_visit *) -visited destruct(EQpos) %] |
---|
| 331 | -EQpos #EQpos <EQpos -pos |
---|
| 332 | % |
---|
| 333 | [ >lin_code_has_label |
---|
| 334 | @add_req_gen_prf |
---|
| 335 | [ #_ |
---|
| 336 | | #next #_ #next_vis |
---|
| 337 | change with (? @ ([?] @ [?])) in match (? @ [? ; ?]); |
---|
| 338 | <associative_append >occurs_exactly_once_None |
---|
| 339 | ] |
---|
| 340 | >occurs_exactly_once_Some_eq >eq_identifier_refl |
---|
| 341 | normalize nodelta |
---|
| 342 | @generated_prf2 |
---|
| 343 | lapply (in_map_domain … visited vis_hd) |
---|
| 344 | >H3 normalize nodelta // |
---|
| 345 | | %{statement} |
---|
| 346 | % [ % ] |
---|
| 347 | [ @lookup_eq_safe |
---|
| 348 | | <associative_append @nth_opt_append_hit_l |
---|
| 349 | >nth_opt_append_r |
---|
| 350 | >rev_length |
---|
| 351 | <gen_length_prf |
---|
| 352 | [<minus_n_n] % |
---|
| 353 | | @add_req_gen_prf |
---|
| 354 | [ lapply (refl … (stmt_implicit_label ?? statement)) |
---|
| 355 | cases (stmt_implicit_label ???) in ⊢ (???%→%); |
---|
| 356 | [#_ #_ %] |
---|
| 357 | #next #K change with (¬bool_to_Prop (?∈?)→?) #next_vis |
---|
| 358 | | #next #K >K #next_vis |
---|
| 359 | ] whd |
---|
| 360 | >mem_set_add in next_vis; |
---|
| 361 | @eq_identifier_elim |
---|
| 362 | [1,3: #EQnext >EQnext * [#ABS elim(ABS I)] |
---|
| 363 | >lookup_add_hit |
---|
| 364 | |*: #NEQ >(lookup_add_miss … visited … NEQ) |
---|
| 365 | change with (?∈?) in match (false∨?); |
---|
| 366 | #next_vis lapply(in_map_domain … visited next) >next_vis |
---|
| 367 | whd in ⊢ (% → ?); [2: * #s ] |
---|
| 368 | #EQlookup >EQlookup |
---|
| 369 | ] whd |
---|
| 370 | [1,2: %2 <associative_append |
---|
| 371 | >nth_opt_append_r >append_length >rev_length >commutative_plus |
---|
| 372 | <gen_length_prf |
---|
| 373 | [1,3: <minus_n_n ] % |
---|
| 374 | | % [2: %] @nth_opt_append_hit_l whd in match (stmt_labels … statement); |
---|
| 375 | >K % |
---|
| 376 | ] |
---|
| 377 | ] |
---|
| 378 | ] |
---|
| 379 | | #NEQ #n_i >(lookup_add_miss … visited … NEQ) |
---|
| 380 | #Hlookup elim (generated_prf1 … Hlookup) |
---|
| 381 | #G1 * #s ** #G2 #G3 #G4 |
---|
| 382 | % |
---|
| 383 | [ >lin_code_has_label <associative_append |
---|
| 384 | >occurs_exactly_once_append |
---|
| 385 | @orb_Prop_l @andb_Prop |
---|
| 386 | [ >occurs_exactly_once_Some_eq |
---|
| 387 | >eq_identifier_false [2: % #ABS >ABS in NEQ; * #ABS' @ABS' % ] |
---|
| 388 | normalize nodelta >lin_code_has_label in G1; #K @K |
---|
| 389 | | @add_req_gen_prf |
---|
| 390 | [ #_ % | #next #_ #_ % ] |
---|
| 391 | ] |
---|
| 392 | | %{s} |
---|
| 393 | % [ % ] |
---|
| 394 | [ assumption |
---|
| 395 | | @nth_opt_append_hit_l assumption |
---|
| 396 | | @(opt_All_mp … G4) |
---|
| 397 | #x |
---|
| 398 | @(eq_identifier_elim … x vis_hd) #Heq |
---|
| 399 | [ >Heq |
---|
| 400 | lapply (in_map_domain … visited vis_hd) |
---|
| 401 | >H3 normalize nodelta in ⊢ (%→?); |
---|
| 402 | #EQlookup >EQlookup * #nth_opt_visiting #gen_length_eq |
---|
| 403 | >lookup_add_hit %1 >gen_length_eq % |
---|
| 404 | | >(lookup_add_miss ?????? Heq) |
---|
| 405 | lapply (in_map_domain … visited x) |
---|
| 406 | elim (true_or_false_Prop (x∈visited)) #x_vis >x_vis |
---|
| 407 | normalize nodelta in ⊢ (%→?); [ * #n' ] |
---|
| 408 | #EQlookupx >EQlookupx whd in ⊢ (%→%); * |
---|
| 409 | [ #G %1{G} |
---|
| 410 | | #G %2 @nth_opt_append_hit_l |
---|
| 411 | assumption |
---|
| 412 | | #G elim(absurd ?? Heq) |
---|
| 413 | (* BUG (but useless): -required -g -generated *) |
---|
| 414 | >H2 in G; lapply H1 cases pre |
---|
| 415 | [ #_ |
---|
| 416 | | #hd #tl * #hd_vis #_ |
---|
| 417 | ] normalize #EQ' destruct(EQ') |
---|
| 418 | [ % |
---|
| 419 | | >x_vis in hd_vis; * |
---|
| 420 | ] |
---|
| 421 | ] |
---|
| 422 | ] |
---|
| 423 | ] |
---|
| 424 | ] |
---|
| 425 | ] |
---|
| 426 | | #i whd in match visited'; |
---|
| 427 | @(eq_identifier_elim … i vis_hd) #Heq |
---|
| 428 | [ >Heq >lookup_add_hit #ABS destruct(ABS) ] |
---|
| 429 | >(lookup_add_miss ?????? Heq) |
---|
| 430 | #i_n_vis |
---|
| 431 | >does_not_occur_append @andb_Prop |
---|
| 432 | [ @generated_prf2 assumption |
---|
| 433 | | change with (bool_to_Prop (¬eq_identifier ??? ∧ ?)) |
---|
| 434 | >eq_identifier_false [2: % #ABS <ABS in Heq; * #ABS' @ABS' % ] |
---|
| 435 | @add_req_gen_prf [ #_ | #next #_ #_ ] % |
---|
| 436 | ] |
---|
| 437 | ] |
---|
| 438 | | @add_req_gen_prf |
---|
| 439 | [ #K | #next #K #next_vis %1 %{(GOTO … next)} % ] |
---|
| 440 | whd in match generated'; whd in match translated_statement; |
---|
| 441 | lapply K whd in match visiting'; |
---|
| 442 | whd in match (stmt_labels ???); cases statement #last |
---|
| 443 | [2: #_ %1 %{last} % ] #next whd in ⊢ (%→?); #next_vis |
---|
| 444 | %2 % * >next_vis * |
---|
| 445 | | whd in match generated'; |
---|
| 446 | @add_req_gen_prf [ #_ | #next #_ #_ ] normalize >gen_length_prf % |
---|
| 447 | ] |
---|
| 448 | qed. |
---|
| 449 | |
---|
| 450 | (* CSC: The branch compression (aka tunneling) optimization is not implemented |
---|
| 451 | in Matita *) |
---|
| 452 | definition branch_compress |
---|
| 453 | ≝ λp: graph_params.λglobals.λg:codeT p globals. |
---|
| 454 | λentry : Σl.bool_to_Prop (code_has_label … g l).g. |
---|
| 455 | |
---|
| 456 | lemma branch_compress_closed : ∀p,globals,g,l.code_closed ?? g → |
---|
| 457 | code_closed … (branch_compress p globals g l). |
---|
| 458 | #p#globals#g#l#H @H qed. |
---|
| 459 | |
---|
| 460 | lemma branch_compress_has_entry : ∀p,globals,g,l. |
---|
| 461 | code_has_label … (branch_compress p globals g l) l. |
---|
| 462 | #p#globals#g*#l#l_prf @l_prf qed. |
---|
| 463 | |
---|
| 464 | definition filter_labels ≝ λtag,A.λtest : identifier tag → bool.λc : list (labelled_obj tag A). |
---|
| 465 | map ?? |
---|
| 466 | (λs. let 〈l_opt,x〉 ≝ s in |
---|
| 467 | 〈! l ← l_opt ; if test l then return l else None ?, x〉) c. |
---|
| 468 | |
---|
| 469 | lemma does_not_occur_filter_labels : |
---|
| 470 | ∀tag,A,test,id,c. |
---|
| 471 | does_not_occur ?? id (filter_labels tag A test c) = |
---|
| 472 | (does_not_occur ?? id c ∨ ¬ test id). |
---|
| 473 | #tag #A #test #id #c elim c |
---|
| 474 | [ // |
---|
| 475 | | ** [2: #lbl] #s #tl #IH |
---|
| 476 | whd in match (filter_labels ????); normalize nodelta |
---|
| 477 | whd in match (does_not_occur ????) in ⊢ (??%%); |
---|
| 478 | [2: @IH] |
---|
| 479 | normalize in match (! l ← ? ; ?); >IH |
---|
| 480 | @(eq_identifier_elim ?? lbl id) #Heq [<Heq] |
---|
| 481 | elim (test lbl) normalize nodelta |
---|
| 482 | change with (eq_identifier ???) in match (instruction_matches_identifier ????); |
---|
| 483 | [1,2: >eq_identifier_refl [2: >commutative_orb] normalize % |
---|
| 484 | |*: >(eq_identifier_false ??? Heq) normalize nodelta % |
---|
| 485 | ] |
---|
| 486 | ] |
---|
| 487 | qed. |
---|
| 488 | |
---|
| 489 | lemma occurs_exactly_once_filter_labels : |
---|
| 490 | ∀tag,A,test,id,c. |
---|
| 491 | occurs_exactly_once ?? id (filter_labels tag A test c) = |
---|
| 492 | (occurs_exactly_once ?? id c ∧ test id). |
---|
| 493 | #tag #A #test #id #c elim c |
---|
| 494 | [ // |
---|
| 495 | | ** [2: #lbl] #s #tl #IH |
---|
| 496 | whd in match (filter_labels ????); normalize nodelta |
---|
| 497 | whd in match (occurs_exactly_once ????) in ⊢ (??%%); |
---|
| 498 | [2: @IH] |
---|
| 499 | normalize in match (! l ← ? ; ?); >IH |
---|
| 500 | >does_not_occur_filter_labels |
---|
| 501 | @(eq_identifier_elim ?? lbl id) #Heq [<Heq] |
---|
| 502 | elim (test lbl) normalize nodelta |
---|
| 503 | change with (eq_identifier ???) in match (instruction_matches_identifier ????); |
---|
| 504 | [1,2: >eq_identifier_refl >commutative_andb [ >(commutative_andb ? true) >commutative_orb | >(commutative_andb ? false)] normalize % |
---|
| 505 | |*: >(eq_identifier_false ??? Heq) normalize nodelta % |
---|
| 506 | ] |
---|
| 507 | ] |
---|
| 508 | qed. |
---|
| 509 | |
---|
| 510 | lemma nth_opt_filter_labels : ∀tag,A,test,instrs,n. |
---|
| 511 | nth_opt ? n (filter_labels tag A test instrs) = |
---|
| 512 | ! 〈lopt, s〉 ← nth_opt ? n instrs ; |
---|
| 513 | return 〈 ! lbl ← lopt; if test lbl then return lbl else None ?, s〉. |
---|
| 514 | #tag #A #test #instrs elim instrs |
---|
| 515 | [ * [2: #n'] % |
---|
| 516 | | * #lopt #s #tl #IH * [2: #n'] |
---|
| 517 | whd in match (filter_labels ????); normalize nodelta |
---|
| 518 | whd in match (nth_opt ???) in ⊢ (??%%); [>IH] % |
---|
| 519 | ] |
---|
| 520 | qed. |
---|
| 521 | |
---|
| 522 | lemma stmt_at_filter_labels : ∀p : lin_params.∀globals,test.∀c : codeT p globals. |
---|
| 523 | ∀i.stmt_at p globals (filter_labels ?? test c) i = stmt_at p globals c i. |
---|
| 524 | #p#globals#test #c#i |
---|
| 525 | whd in ⊢ (??%%); >nth_opt_filter_labels |
---|
| 526 | elim (nth_opt ???); // |
---|
| 527 | qed. |
---|
| 528 | |
---|
| 529 | lemma option_bind_inverse : ∀A,B.∀m : option A.∀f : A → option B.∀r. |
---|
| 530 | ! x ← m ; f x = return r → |
---|
| 531 | ∃x.m = return x ∧ f x = return r. |
---|
| 532 | #A #B * normalize [2:#x] #f #r #EQ destruct |
---|
| 533 | %{x} %{EQ} % |
---|
| 534 | qed. |
---|
| 535 | |
---|
| 536 | lemma nth_opt_reverse_hit : |
---|
| 537 | ∀A,l,n.n < |l| → nth_opt A n (reverse ? l) = nth_opt A (|l| - (S n)) l. |
---|
| 538 | #A #l elim l |
---|
| 539 | [ #n #ABS normalize in ABS; @⊥ -A /2 by absurd/ |
---|
| 540 | | #hd #tl #IH #n #lim whd in match (reverse ??); >rev_append_def |
---|
| 541 | @(leb_elim (S n) (|tl|)) #H |
---|
| 542 | [ >nth_opt_append_l [2: >length_reverse @H ] |
---|
| 543 | >(IH … H) >(minus_Sn_m … H) % |
---|
| 544 | | >(le_to_le_to_eq … (le_S_S_to_le … lim) (not_lt_to_le … H)) |
---|
| 545 | >nth_opt_append_r >length_reverse [2: % ] |
---|
| 546 | <minus_n_n <minus_n_n % |
---|
| 547 | ] |
---|
| 548 | ] |
---|
| 549 | qed. |
---|
| 550 | |
---|
| 551 | lemma nth_opt_reverse_hit_inv : |
---|
| 552 | ∀A,l,n.n < |l| → nth_opt A (|l| - (S n)) (reverse ? l) = nth_opt A n l. |
---|
| 553 | #A #l #n #H <(reverse_reverse ? l) in ⊢ (???%); @sym_eq |
---|
| 554 | <length_reverse @nth_opt_reverse_hit >length_reverse @H |
---|
| 555 | qed. |
---|
| 556 | |
---|
[2473] | 557 | definition good_local_sigma : |
---|
| 558 | ∀p:unserialized_params. |
---|
| 559 | ∀globals. |
---|
| 560 | ∀g:codeT (mk_graph_params p) globals. |
---|
| 561 | (Σl.bool_to_Prop (code_has_label … g l)) → |
---|
| 562 | codeT (mk_lin_params p) globals → |
---|
| 563 | (label → option ℕ) → Prop ≝ |
---|
| 564 | λp,globals,g,entry,c,sigma. |
---|
| 565 | sigma entry = Some ? 0 ∧ |
---|
[2529] | 566 | (∀l,n.point_of_label … c l = Some ? n → sigma l = Some ? n) ∧ |
---|
[2473] | 567 | ∀l,n.sigma l = Some ? n → |
---|
[2529] | 568 | ∃s. stmt_at … g l = Some ? s ∧ |
---|
| 569 | All ? (λl.sigma l ≠ None ?) (stmt_labels … s) ∧ |
---|
| 570 | opt_All ? |
---|
| 571 | (λnext.Or (sigma next = Some ? (S n)) |
---|
| 572 | (stmt_at … c (S n) = Some ? (GOTO … next))) |
---|
| 573 | (stmt_implicit_label … s) ∧ |
---|
| 574 | stmt_at … c n = Some ? (graph_to_lin_statement … s). |
---|
[2473] | 575 | |
---|
[2182] | 576 | definition linearise_code: |
---|
| 577 | ∀p : unserialized_params.∀globals. |
---|
| 578 | ∀g : codeT (mk_graph_params p) globals.code_closed … g → |
---|
[2473] | 579 | ∀entry : (Σl.bool_to_Prop (code_has_label … g l)) |
---|
| 580 | .Σ〈c, sigma〉. |
---|
| 581 | good_local_sigma … g entry c sigma ∧ |
---|
| 582 | code_closed … c |
---|
| 583 | (* ∧ |
---|
[2182] | 584 | ∃ sigma : identifier_map LabelTag ℕ. |
---|
| 585 | lookup … sigma entry = Some ? 0 ∧ |
---|
| 586 | ∀l,n.lookup … sigma l = Some ? n → |
---|
| 587 | ∃s. lookup … g l = Some ? s ∧ |
---|
| 588 | opt_Exists ? |
---|
| 589 | (λls.let 〈lopt, ts〉 ≝ ls in |
---|
| 590 | opt_All ? (eq ? l) lopt ∧ |
---|
| 591 | ts = graph_to_lin_statement … s ∧ |
---|
| 592 | opt_All ? |
---|
| 593 | (λnext.Or (lookup … sigma next = Some ? (S n)) |
---|
| 594 | (nth_opt … (S n) c = Some ? 〈None ?, GOTO … next〉)) |
---|
[2473] | 595 | (stmt_implicit_label … s)) (nth_opt … n c)*) |
---|
[2182] | 596 | ≝ |
---|
| 597 | λp,globals,g,g_prf,entry_sig. |
---|
| 598 | let g ≝ branch_compress (mk_graph_params p) ? g entry_sig in |
---|
| 599 | let g_prf ≝ branch_compress_closed … g entry_sig g_prf in |
---|
| 600 | match graph_visit p globals g ∅ (empty_map …) [ ] [entry_sig] 0 (|g|) |
---|
| 601 | (entry_sig) g_prf ????????? |
---|
| 602 | with |
---|
| 603 | [ mk_Sig triple H ⇒ |
---|
| 604 | let sigma ≝ \fst (\fst triple) in |
---|
| 605 | let required ≝ \snd (\fst triple) in |
---|
| 606 | let crev ≝ \snd triple in |
---|
| 607 | let lbld_code ≝ rev ? crev in |
---|
[2473] | 608 | 〈filter_labels … (λl.l∈required) lbld_code, lookup … sigma〉 ]. |
---|
| 609 | [ cases (graph_visit ????????????????????) |
---|
| 610 | (* done later *) |
---|
[2182] | 611 | | #i >mem_set_empty * |
---|
| 612 | |3,4: #a #b whd in ⊢ (??%?→?); #ABS destruct(ABS) |
---|
| 613 | | #l #_ % |
---|
| 614 | | %2 % * >mem_set_empty * |
---|
| 615 | | % [2: %] @(branch_compress_has_entry … g entry_sig) |
---|
| 616 | | % |
---|
| 617 | | % % [% %] cases (pi1 … entry_sig) normalize #_ % // |
---|
| 618 | | >commutative_plus change with (? ≤ |g|) % |
---|
| 619 | ] |
---|
[2473] | 620 | ** |
---|
| 621 | #visited #required #generated normalize nodelta **** |
---|
[2182] | 622 | #entry_O #req_vis #last_fin #labels_in_req #sigma_prop |
---|
[2473] | 623 | % |
---|
[2529] | 624 | [ % [ % [assumption]] |
---|
| 625 | #lbl #n |
---|
| 626 | [ change with (If ? then with prf do ? else ? = ? → ?) |
---|
| 627 | @If_elim [2: #_ #ABS destruct(ABS) ] |
---|
| 628 | #H lapply H |
---|
| 629 | >occurs_exactly_once_filter_labels |
---|
| 630 | elim (true_or_false_Prop … (occurs_exactly_once ?? lbl ?)) |
---|
| 631 | [1,2: #H1 >H1 |*:] [2: * ] |
---|
| 632 | elim (true_or_false_Prop … (lbl ∈ required)) #H2 >H2 * |
---|
| 633 | lapply (in_map_domain … visited lbl) >(req_vis … H2) |
---|
| 634 | * #n_lbl #EQsigma |
---|
| 635 | elim (sigma_prop … EQsigma) #_ * #stmt ** #_ #EQnth_opt #_ |
---|
| 636 | >(nth_opt_index_of_label ???? n_lbl (graph_to_lin_statement … stmt) H) |
---|
| 637 | [ normalize in ⊢ (% → ?); #EQ destruct(EQ) assumption |
---|
| 638 | | >nth_opt_filter_labels >EQnth_opt >m_return_bind >m_return_bind |
---|
| 639 | >H2 % |
---|
| 640 | ] |
---|
| 641 | | #eq_lookup elim (sigma_prop ?? eq_lookup) |
---|
| 642 | #lbl_in_gen * #stmt ** #stmt_in_g #nth_opt_is_stmt #succ_is_in |
---|
| 643 | % [2: % [ % [ % [ assumption ]]] |] |
---|
| 644 | [ @All_append |
---|
| 645 | [ lapply succ_is_in elim (stmt_implicit_label ???) [ * % ] |
---|
| 646 | #nxt #nxt_spec % [2: %] cases nxt_spec -nxt_spec |
---|
| 647 | [ #EQ >EQ % #ABS destruct(ABS) |
---|
| 648 | | #goto_in lapply (in_map_domain … visited nxt) |
---|
| 649 | >req_vis [ * #n #EQ >EQ % #ABS destruct(ABS) ] |
---|
| 650 | @(proj1 … (labels_in_req (S n) (GOTO … nxt) …)) |
---|
| 651 | whd in ⊢ (??%?); >goto_in % |
---|
| 652 | ] |
---|
| 653 | | <graph_to_lin_labels @(All_mp … (labels_in_req …)) |
---|
| 654 | [ #lbl #H |
---|
| 655 | lapply (in_map_domain … visited lbl) >(req_vis … H) * #n #EQ >EQ % #ABS destruct(ABS) |
---|
| 656 | | whd in ⊢ (??%?); >nth_opt_is_stmt % | |
---|
| 657 | ] |
---|
| 658 | ] |
---|
| 659 | | lapply succ_is_in |
---|
| 660 | cases (stmt_implicit_label … stmt) [#_ %] |
---|
| 661 | #next * |
---|
| 662 | [ #H %1{H} ] |
---|
| 663 | #H %2 |
---|
| 664 | >stmt_at_filter_labels whd in ⊢ (??%?); >H % |
---|
| 665 | | >stmt_at_filter_labels whd in ⊢ (??%?); >nth_opt_is_stmt % |
---|
| 666 | ] |
---|
[2473] | 667 | ] |
---|
| 668 | | #i #s |
---|
[2182] | 669 | >stmt_at_filter_labels #EQ |
---|
| 670 | % |
---|
| 671 | [ @stmt_forall_labels_explicit |
---|
| 672 | @(All_mp … (labels_in_req … EQ)) |
---|
| 673 | #l #l_req >lin_code_has_label |
---|
| 674 | >occurs_exactly_once_filter_labels >l_req |
---|
| 675 | >commutative_andb whd in ⊢ (?%); |
---|
| 676 | elim (sigma_prop ?? (lookup_eq_safe … (req_vis … l_req))) |
---|
| 677 | >lin_code_has_label #H #_ @H |
---|
| 678 | | lapply EQ cases s #s' [2: #_ % ] |
---|
| 679 | * -EQ #EQ change with (bool_to_Prop (code_has_point ????)) |
---|
| 680 | whd in match (point_of_succ ???); |
---|
| 681 | >lin_code_has_point @leb_elim [ #_ % ] >length_map >length_reverse |
---|
| 682 | #INEQ |
---|
| 683 | cut (|generated| = S i) |
---|
| 684 | [ @(le_to_le_to_eq … (not_lt_to_le … INEQ) ) |
---|
| 685 | elim (option_bind_inverse ????? EQ) #x * #EQ1 #EQ2 |
---|
| 686 | <length_reverse |
---|
| 687 | @(nth_opt_hit_length … EQ1) |
---|
| 688 | ] #EQ_length |
---|
| 689 | elim last_fin #fin #EQ' |
---|
| 690 | lapply EQ whd in match (stmt_at ????); |
---|
| 691 | >nth_opt_reverse_hit >EQ_length [2: % ] <minus_n_n |
---|
| 692 | change with (stmt_at ???? = ? → ?) |
---|
| 693 | >EQ' #ABS destruct(ABS) |
---|
| 694 | ] |
---|
| 695 | ] |
---|
| 696 | qed. |
---|
| 697 | |
---|
| 698 | definition linearise_int_fun : |
---|
| 699 | ∀p : unserialized_params. |
---|
| 700 | ∀globals. |
---|
[2473] | 701 | ∀fn_in : joint_closed_internal_function (mk_graph_params p) globals |
---|
| 702 | .Σ〈fn_out : joint_closed_internal_function (mk_lin_params p) globals, |
---|
| 703 | sigma : ?〉. |
---|
| 704 | good_local_sigma … (joint_if_code … fn_in) (joint_if_entry … fn_in) |
---|
| 705 | (joint_if_code … fn_out) sigma |
---|
[2182] | 706 | (* ∃sigma : identifier_map LabelTag ℕ. |
---|
| 707 | let g ≝ joint_if_code ?? (pi1 … fin) in |
---|
| 708 | let c ≝ joint_if_code ?? (pi1 … fout) in |
---|
| 709 | let entry ≝ joint_if_entry ?? (pi1 … fin) in |
---|
| 710 | lookup … sigma entry = Some ? 0 ∧ |
---|
| 711 | ∀l,n.lookup … sigma l = Some ? n → |
---|
| 712 | ∃s. lookup … g l = Some ? s ∧ |
---|
| 713 | opt_Exists ? |
---|
| 714 | (λls.let 〈lopt, ts〉 ≝ ls in |
---|
| 715 | opt_All ? (eq ? l) lopt ∧ |
---|
| 716 | ts = graph_to_lin_statement … s ∧ |
---|
| 717 | opt_All ? |
---|
| 718 | (λnext.Or (lookup … sigma next = Some ? (S n)) |
---|
| 719 | (nth_opt … (S n) c = Some ? 〈None ?, GOTO … next〉)) |
---|
| 720 | (stmt_implicit_label … s)) (nth_opt … n c)*) ≝ |
---|
[2473] | 721 | λp,globals,f_sig. |
---|
| 722 | let code_sigma ≝ linearise_code … |
---|
| 723 | (joint_if_code … f_sig) |
---|
| 724 | (pi2 … f_sig) |
---|
| 725 | (joint_if_entry … f_sig) in |
---|
| 726 | let code ≝ \fst code_sigma in |
---|
| 727 | let sigma ≝ \snd code_sigma in |
---|
| 728 | let entry : Σpt.bool_to_Prop (code_has_point … code pt) ≝ «0, hide_prf ??» in |
---|
| 729 | 〈«mk_joint_internal_function (mk_lin_params p) globals |
---|
| 730 | (joint_if_luniverse ?? f_sig) (joint_if_runiverse ?? f_sig) |
---|
| 731 | (joint_if_result ?? f_sig) (joint_if_params ?? f_sig) (joint_if_locals ?? f_sig) |
---|
| 732 | (joint_if_stacksize ?? f_sig) code entry entry (* exit is dummy! *), ?», |
---|
| 733 | sigma〉. |
---|
| 734 | normalize nodelta |
---|
| 735 | cases (linearise_code ?????) * #code #sigma normalize nodelta * #H1 #H2 |
---|
| 736 | [ @H2 |
---|
| 737 | | @H1 |
---|
[2529] | 738 | | cases H1 * #H3 #H4 #H5 elim (H5 … H3) |
---|
| 739 | #s *** #_ #_ #_ >lin_code_has_point cases code |
---|
| 740 | [ #ABS normalize in ABS; destruct(ABS) | #hd #tl #_ % ] |
---|
[2182] | 741 | ] |
---|
| 742 | qed. |
---|
[2422] | 743 | |
---|
| 744 | definition linearise : ∀p : unserialized_params. |
---|
| 745 | program (joint_function (mk_graph_params p)) ℕ → |
---|
[2473] | 746 | program (joint_function (mk_lin_params p)) ℕ |
---|
| 747 | ≝ |
---|
[2422] | 748 | λp,pr.transform_program ??? pr |
---|
[2473] | 749 | (λglobals.transf_fundef ?? (λf_in.\fst (linearise_int_fun p globals f_in))). |
---|
| 750 | |
---|
[2529] | 751 | (* |
---|
[2473] | 752 | definition good_sigma : |
---|
| 753 | ∀p:unserialized_params. |
---|
| 754 | ∀prog_in : joint_program (mk_graph_params p). |
---|
| 755 | ((Σi.is_internal_function_of_program … prog_in i) → label → option ℕ) → Prop ≝ |
---|
| 756 | λp,prog_in,sigma. |
---|
| 757 | let prog_out ≝ linearise … prog_in in |
---|
[2481] | 758 | ∀i : Σi.is_internal_function_of_program … prog_in i.∀prf. |
---|
| 759 | let fn_in ≝ if_of_function … i in |
---|
| 760 | let i' : Σi.is_internal_function_of_program … prog_out i ≝ «pi1 ?? i, prf» in |
---|
| 761 | let fn_out ≝ if_of_function … i' in |
---|
[2473] | 762 | let sigma_local ≝ sigma i in |
---|
| 763 | good_local_sigma ?? (joint_if_code ?? fn_in) (joint_if_entry … fn_in) |
---|
| 764 | (joint_if_code ?? fn_out) sigma_local. |
---|
| 765 | |
---|
| 766 | lemma linearise_spec : ∀p,prog.∃sigma.good_sigma p prog sigma. |
---|
| 767 | #p #prog |
---|
| 768 | letin sigma ≝ |
---|
[2529] | 769 | (λi : Σi.is_internal_function_of_program … prog i. let fn_in ≝ if_of_function … i in |
---|
[2473] | 770 | \snd (linearise_int_fun … fn_in)) |
---|
| 771 | %{sigma} |
---|
[2481] | 772 | #i #prf >(prog_if_of_function_transform … i) [2: % ] |
---|
[2473] | 773 | normalize nodelta |
---|
| 774 | cases (linearise_int_fun ???) * #fn_out #sigma_loc |
---|
| 775 | normalize nodelta #prf @prf |
---|
| 776 | qed. |
---|
[2529] | 777 | *) |
---|