@@ -47,8 +47,12 @@ val _ = new_theory "profiling_proof";
4747
4848val _ = type_abbrev(" distrub_st" , ``:( (string, (num list) option) alist # num list # num list)``);
4949
50- Definition eliminable_def:
51- eliminable ((r,edges,labels):('a,'b)BDD) n =
50+
51+
52+ (*
53+
54+ Definition eliminable_new_def:
55+ eliminable_new ((r,edges,labels):('a,'b)BDD) n =
5256 case ALOOKUP edges n of
5357 |SOME (n1, n2) =>
5458 if n1 = n2 ∧
@@ -59,8 +63,28 @@ Definition eliminable_def:
5963 | NONE => NONE
6064End
6165
62-
63- val _ = type_abbrev(" distrub_st" , ``:( (string, (num list) option) alist # num list # num list)``);
66+
67+
68+ Definition eliminable_projection_def:
69+ eliminable_projection edges_proj n =
70+ case ALOOKUP edges_proj n of
71+ |SOME (n1, n2) =>
72+ if n1 = n2 ∧
73+ n1 ≠ n ∧
74+ n ≠ 0n ∧
75+ has_parent edges_proj n1 n
76+ then SOME n1
77+ else NONE
78+ | NONE => NONE
79+ End
80+
81+
82+ Definition mergable_projection_def:
83+ mergable_projection edges_proj labels_proj n n' =
84+ (n≠n' ∧ ALOOKUP edges_proj n = ALOOKUP edges_proj n' ∧
85+ eq_vars_in_labels labels_proj n n' ∧ ALOOKUP labels_proj n' ≠ NONE )
86+ End
87+
6488
6589
6690Definition update_internals_def:
@@ -107,50 +131,72 @@ End
107131Definition merge_safe_def:
108132 merge_safe (BDD:('a,'b) BDD) n n' =
109133 if mergable BDD n n' then
110- merge BDD n' n
134+ (T, merge BDD n n')
111135 else
112- BDD
136+ (F, BDD)
113137End
114138
115139
116140Definition eliminate_safe_def:
117141 eliminate_safe (BDD:('a,'b) BDD) n =
118- case eliminable BDD n of
119- | SOME n' => merge BDD n' n
120- | NONE => BDD
142+ case eliminable_new BDD n of
143+ | SOME n' => (T, merge BDD n' n)
144+ | NONE => (F, BDD)
121145End
122146
123147
124148
125149
126- (* can be improved more *)
127- Definition optimize_node_def:
128- (optimize_node (BDD:('a,'b) BDD) n [] = eliminate_safe BDD n) ∧
129150
130- (optimize_node BDD n (n'::nl) =
131- case eliminable BDD n of
132- | SOME n' => eliminate_safe (BDD:('a,'b) BDD) n
133- | NONE => optimize_node (merge_safe BDD n n') n nl)
151+ Definition optimize_node_def:
152+ (optimize_node edges_proj labels_proj (BDD:('a,'b) BDD) n [] = SND (eliminate_safe BDD n)) ∧
153+
154+ (optimize_node edges_proj labels_proj BDD n (n'::nl) =
155+ case eliminable_projection edges_proj n of
156+ | SOME n' => SND (eliminate_safe BDD n)
157+ | NONE => (
158+ case mergable_projection edges_proj labels_proj n' n of
159+ | T => ( case merge_safe BDD n' n of
160+ | (T, BDD') => BDD'
161+ | (F, BDD') => optimize_node edges_proj labels_proj BDD n nl
162+ )
163+
164+ | F => optimize_node edges_proj labels_proj BDD n nl)
165+ )
134166End
135167
136168
137169
138170
139171Definition optimize_layer_def:
140- (optimize_layer (BDD:('a,'b) BDD) [] = BDD) /\
141- (optimize_layer BDD (n::nl)=
142- optimize_layer (optimize_node BDD n nl) nl
172+ (optimize_layer edges_proj labels_proj (BDD:('a,'b) BDD) [] = BDD) /\
173+ (optimize_layer edges_proj labels_proj BDD (n::nl)=
174+ optimize_layer edges_proj labels_proj (optimize_node edges_proj labels_proj BDD n nl) nl
143175 )
144176End
145177
146-
178+
179+ Definition project_edges_to_def:
180+ project_edges_to ((r, edges,labels):('a,'b) BDD) nl =
181+ MAP (\n. (n,THE(ALOOKUP edges n))) nl
182+ End
183+
184+ Definition project_labels_to_def:
185+ project_labels_to ((r, edges,labels):('a,'b) BDD) nl =
186+ MAP (\n. (n,THE(ALOOKUP labels n))) nl
187+ End
188+
189+
190+
147191Definition optimize_internals_def:
148192 (optimize_internals (BDD:('a,'b) BDD) [] = BDD) /\
149193 (optimize_internals BDD ((var,NONE)::l) = optimize_internals BDD l) /\
150194
151195 (optimize_internals BDD ((var,SOME nl)::l)=
152- let BDD' = optimize_layer BDD nl in
153- optimize_internals BDD' l
196+ let edges_proj = project_edges_to BDD nl in
197+ let labels_proj = project_labels_to BDD nl in
198+ let BDD' = optimize_layer edges_proj labels_proj BDD nl in
199+ optimize_internals BDD' l
154200 )
155201End
156202
160206Definition optimize_bdd_def:
161207 optimize_bdd (BDD:('a,'b) BDD) order =
162208 let (internals,ntl,tl) = bdd_distribute (BDD:('a,'b) BDD) order in
163- let BDD1 = optimize_layer BDD tl in
164- let BDD2 = optimize_layer BDD1 ntl in
165- optimize_internals BDD2 internals
209+ let labels_proj_tl = project_labels_to BDD tl in (* for terminals *)
210+ let labels_proj_ntl = project_labels_to BDD ntl in (* for terminals *)
211+ let BDD1 = optimize_layer [] labels_proj_tl BDD tl in
212+ let BDD2 = optimize_layer [] labels_proj_ntl BDD1 ntl in
213+ optimize_internals BDD2 internals
166214End
167215
168216
@@ -178,6 +226,9 @@ Definition mk_BDDPred_opt_new_def:
178226End
179227
180228
229+
230+
231+
181232
182233
183234
@@ -210,12 +261,6 @@ val eval_table_full_opt_auto_new = EVAL “mk_BDDPred_opt_new table_structure_ne
210261
211262
212263
213-
214-
215-
216-
217- val _ = type_abbrev(" single_rule" , “:((string# num list) action_expr) arith_rule”);
218-
219264val test_pd_type = “[("ip", type_record [("priority", type_length 3);
220265 ("size", type_length 16);
221266 ("age", type_length 8);
@@ -224,11 +269,8 @@ val test_pd_type = “[("ip", type_record [("priority", type_length 3);
224269val is_high_priority = “(arithm_le (lv_acc (lv_x "ip") "priority") ^(bdd_utilsLib.make_bv 2 3))”;
225270val is_medium_priority = “(arithm_ge (lv_acc (lv_x "ip") "priority") ^(bdd_utilsLib.make_bv 4 3))”;
226271
227- val is_size_packet1 = “(arithm_ge (lv_acc (lv_x " ip" ) " size" ) ^(bdd_utilsLib.make_bv 30000 16 ))”;
228- val is_size_packet2 = “(arithm_ge (lv_acc (lv_x " ip" ) " size" ) ^(bdd_utilsLib.make_bv 27000 16 ))”;
229- val is_size_packet3 = “(arithm_ge (lv_acc (lv_x " ip" ) " size" ) ^(bdd_utilsLib.make_bv 25000 16 ))”;
230- val is_size_packet4 = “(arithm_ge (lv_acc (lv_x " ip" ) " size" ) ^(bdd_utilsLib.make_bv 23000 16 ))”;
231-
272+ val is_small_packet1 = “(arithm_le (lv_acc (lv_x "ip") "size") ^(bdd_utilsLib.make_bv 500 16))”;
273+ val is_small_packet2 = “(arithm_le (lv_acc (lv_x "ip") "size") ^(bdd_utilsLib.make_bv 400 16))”;
232274
233275val is_young_packet = “(arithm_ge (lv_acc (lv_x "ip") "age") ^(bdd_utilsLib.make_bv 200 8))”;
234276
@@ -237,42 +279,38 @@ val is_data_type = “(arithm_ge (lv_acc (lv_x "ip") "type") ^(bdd_utilsLib.make
237279
238280
239281
240- val policy_me = “[(" x1" , ^is_high_priority);
241- (" x2" , ^is_medium_priority);
282+ val policy_me = “[("x", ^is_high_priority);
283+ ("y", ^is_medium_priority);
284+ ("z1", ^is_small_packet1);
285+ ("z2", ^is_small_packet2);
286+ ("w", ^is_young_packet);
287+ ("q", ^is_control_type);
288+ ("r", ^is_data_type)]”;
242289
243- ( " z1 " , ^is_size_packet1 );
244- ( " z2 " , ^is_size_packet2 );
245- ( " z3 " , ^is_size_packet3 );
246- ( " z4 " , ^is_size_packet4) ;
290+ val policy_full_order = “[("a",["x";"y"] );
291+ ("b",["z1";"z2"] );
292+ ("c",["w"] );
293+ ("d",["q";"r"])]” ;
247294
248- (" q1" , ^is_control_type);
249- (" q2" , ^is_data_type)]”;
250-
251- val policy_full_order = “[(" a" ,[" x1" ;" x2" ]);
252- (" b" ,[" z1" ;" z2" ;" z3" ;" z4" ]);
253- (" d" ,[" q1" ;" q2" ])]”;
254-
255- val policy_order = “[" x1" ;" x2" ;" z1" ;" z2" ;" z3" ;" z4" ;" q1" ;" q2" ]”;
295+ val policy_order = “["x";"y";"z1";"z2";"w";"q";"r"]”;
256296
297+ (* Rule 1: High priority small control packets - expedited forwarding *)
257298val arith_policy_rule1 = “(arith_and (arith_a ^is_high_priority)
258- (arith_and (arith_a ^is_size_packet1 ) (arith_a ^is_control_type)),
299+ (arith_and (arith_a ^is_small_packet1 ) (arith_a ^is_control_type)),
259300 action ("fwd_priority",[1; 255])):single_rule”;
260301
261- val arith_policy_rule2 = “(arith_and (arith_a ^is_high_priority) (arith_a ^is_size_packet2),
302+ (* Rule 2: High priority data packets *)
303+ val arith_policy_rule2 = “(arith_and (arith_a ^is_high_priority) (arith_a ^is_data_type),
262304 action ("fwd",[1])):single_rule”;
263305
264- val arith_policy_rule3 = “(arith_and (arith_a ^is_high_priority) (arith_a ^is_size_packet3),
306+ (* Rule 3: Medium priority young packets *)
307+ val arith_policy_rule3 = “(arith_and (arith_a ^is_medium_priority) (arith_a ^is_young_packet),
265308 action ("fwd",[2])):single_rule”;
266309
267- val arith_policy_rule4 = “(arith_and (arith_a ^is_high_priority) (arith_a ^is_size_packet4),
310+ (* Rule 3: Medium priority young packets *)
311+ val arith_policy_rule4 = “((arith_a ^is_small_packet2),
268312 action ("fwd",[3])):single_rule”;
269313
270- val arith_policy_rule5 = “(arith_and (arith_a ^is_medium_priority)
271- (arith_and (arith_a ^is_size_packet1) (arith_a ^is_data_type)),
272- action (" fwd_priority" ,[1 ; 4 ])):single_rule”;
273-
274-
275-
276314
277315(* Default forward rule *)
278316val arith_policy_rule_default = “(arith_a a_True,
@@ -282,9 +320,10 @@ val arith_policy = “[^arith_policy_rule1;
282320 ^arith_policy_rule2;
283321 ^arith_policy_rule3;
284322 ^arith_policy_rule4;
285- ^arith_policy_rule5;
286323 ^arith_policy_rule_default]:single_rule list”;
287324
325+
326+
288327(* *************************************************)
289328
290329
@@ -293,7 +332,7 @@ val arith_policy = “[^arith_policy_rule1;
293332
294333
295334
296-
335+ *)
297336
298337
299338
0 commit comments