Skip to content

Commit 9077ca4

Browse files
changed the strategy for the last part of the pipeline, now it is 3 stages instead of one shot
1 parent 92a525b commit 9077ca4

7 files changed

+2498
-1722
lines changed

hol/bdd_end_to_endScript.sml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ Theorem table_mk_bdd_correct_thm:
171171
correct_sem table_structure BDD (REVERSE vars)
172172
Proof
173173
rpt strip_tac >>
174-
assume_tac (INST_TYPE [“:'a” |-> “: (('a table) list # num)”, “:'b” |-> “: 'a action_expr”] correct_sem_translation) >>
174+
assume_tac (INST_TYPE [“:'a” |-> “: (('a var_table) list # num)”, “:'b” |-> “: 'a action_expr”] correct_sem_translation) >>
175175
first_x_assum (strip_assume_tac o (Q.SPECL [‘vars’, ‘[]’,
176176
‘(0,[],[(0,non_termn (NONE,(var_table)))])’,
177177
‘BDD’, ‘table_structure’, ‘1’])) >>
@@ -530,7 +530,7 @@ Theorem table_mk_bdd_correct_valid_opt_thm:
530530
Proof
531531

532532
rpt strip_tac >>
533-
assume_tac (INST_TYPE [“:'a” |-> “: (('a table) list # num)”, “:'b” |-> “: 'a action_expr”]
533+
assume_tac (INST_TYPE [“:'a” |-> “: (('a var_table) list # num)”, “:'b” |-> “: 'a action_expr”]
534534
correct_sem_valid_translation_opt) >>
535535

536536
first_x_assum (strip_assume_tac o (Q.SPECL [‘vars’, ‘[]’,

hol/bdd_test_casesScript.sml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ val _ = load "bdd_utils";
3232

3333
val _ = new_theory "bdd_test_cases";
3434

35-
35+
(* TODO: update the sml definition that takes a var bdd and generates var table, now the var_table has new syntax. Var x | True | False | Not atom -->
36+
Var x | Not x | Not True | Not False | True | False
3637
3738
3839
(* a few types abbreviations *)
39-
val _ = type_abbrev("BDD_tbl_type", “:(( (string# num list) table_list, (string# num list) action_expr) BDD)”);
40+
val _ = type_abbrev("BDD_tbl_type", “:(( (string# num list) var_table_list, (string# num list) action_expr) BDD)”);
4041
4142
val _ = type_abbrev("struc_tbl_type", “:((( atom_var list # num # (string# num list) action_expr) list list # num,
4243
(string# num list) action_expr) decision_structure)”);
@@ -113,8 +114,8 @@ val var_tbl3_line2 = ``([True] , 7, action ("fwd",[2])): (string# num list) line
113114
val var_tbl3_line3 = ``([True] , 8, action ("drop",[])): (string# num list) line``;
114115
val var_tbl3 = ``[^var_tbl3_line1; ^var_tbl3_line2; ^var_tbl3_line3] : (string# num list) table``;
115116
116-
val var_tbls1 = ``[^var_tbl1; ^var_tbl2; ^var_tbl3] : ((string# num list) table_list) ``;
117-
val var_tbls1_start = ``([^var_tbl1; ^var_tbl2; ^var_tbl3] : ((string# num list) table_list),(0:num)) ``;
117+
val var_tbls1 = ``[^var_tbl1; ^var_tbl2; ^var_tbl3] : ((string# num list) var_table_list) ``;
118+
val var_tbls1_start = ``([^var_tbl1; ^var_tbl2; ^var_tbl3] : ((string# num list) var_table_list),(0:num)) ``;
118119
119120
120121
val eval_table1_full_opt = EVAL “mk_BDDPred_opt table_structure (0,[],[(0, non_termn (NONE, ^var_tbls1_start))]) [] ["x";"y";"z"] 1”;
@@ -219,8 +220,8 @@ val var_tbl3_line6 = ``([True] , 10, action ("drop",[])): (string# num list) lin
219220
val var_tbl3 = ``[^var_tbl3_line1; ^var_tbl3_line2; ^var_tbl3_line3;
220221
^var_tbl3_line4; ^var_tbl3_line5; ^var_tbl3_line6] : (string# num list) table``;
221222
222-
val var_tbls2 = ``[^var_tbl1; ^var_tbl2; ^var_tbl3] : ((string# num list) table_list) ``;
223-
val var_tbls2_start = ``([^var_tbl1; ^var_tbl2; ^var_tbl3] : ((string# num list) table_list),(0:num)) ``;
223+
val var_tbls2 = ``[^var_tbl1; ^var_tbl2; ^var_tbl3] : ((string# num list) var_table_list) ``;
224+
val var_tbls2_start = ``([^var_tbl1; ^var_tbl2; ^var_tbl3] : ((string# num list) var_table_list),(0:num)) ``;
224225
225226
226227
val eval_table2_full_opt = EVAL “mk_BDDPred_opt table_structure (0,[],[(0, non_termn (NONE, ^var_tbls2_start))]) [] ["x";"y";"z";"w"] 1”;
@@ -280,7 +281,7 @@ val arith_policy3 = “[ ^arith_policy3_rule1 ;
280281
^arith_policy3_rule3]:((string# num list) action_expr) arith_policy”;
281282
282283
283-
val arith_policy3_eval = EVAL “convert ^arith_policy3 ^policy3_me1”;
284+
val arith_policy3_eval = EVAL convert_arith_to_var_policy ^arith_policy3 ^policy3_me1”;
284285
285286
val var_policy3 = optionSyntax.dest_some (rhs (concl arith_policy3_eval));
286287
@@ -300,6 +301,6 @@ val arith_policy3_var_policy3_thm = REWRITE_RULE[all_distinct_conj, arith_policy
300301
301302
*)
302303
303-
304+
*)
304305
val _ = export_theory ();
305306

hol/policy_arith_to_varScript.sml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ val _ = Hol_datatype `
4646
arithm_atom =
4747
a_True (* T *)
4848
| a_False (* F *)
49-
| arithm_gt of arith_lv => bitv (* lval > v *)
50-
| arithm_lt of arith_lv => bitv (* lval < v *)
49+
| arithm_ge of arith_lv => bitv (* lval v *)
50+
| arithm_le of arith_lv => bitv (* lval v *)
5151
(*| arithm_eq of arith_lv => num (* lval = v *)*) (* this will be added to input policy *)
5252
`;
5353

@@ -93,13 +93,13 @@ End
9393
Definition eval_arithm_atom_def:
9494
(eval_arithm_atom pd a_True = SOME T) ∧
9595
(eval_arithm_atom pd a_False = SOME F) ∧
96-
(eval_arithm_atom pd (arithm_gt lval bv) =
96+
(eval_arithm_atom pd (arithm_ge lval bv) =
9797
case resolve_lval pd lval of
98-
| SOME (val_bs bv') => bitv_binpred binop_gt bv' bv
98+
| SOME (val_bs bv') => bitv_binpred binop_ge bv' bv
9999
| _ => NONE) ∧
100-
(eval_arithm_atom pd (arithm_lt lval bv) =
100+
(eval_arithm_atom pd (arithm_le lval bv) =
101101
case resolve_lval pd lval of
102-
SOME (val_bs bv') => bitv_binpred binop_lt bv' bv
102+
SOME (val_bs bv') => bitv_binpred binop_le bv' bv
103103
| _ => NONE)
104104
End
105105

@@ -271,15 +271,15 @@ End
271271

272272

273273

274-
Definition all_convertable_def:
275-
all_convertable m_e policy =
274+
Definition all_convertable_to_var_def:
275+
all_convertable_to_var m_e policy =
276276
EVERY (λ(pred,_). pred_a2v m_e pred ≠ NONE) policy
277277
End
278278

279279

280-
Definition convert_def:
281-
convert policy m_e =
282-
if all_convertable m_e policy then
280+
Definition convert_arith_to_var_policy_def:
281+
convert_arith_to_var_policy policy m_e =
282+
if all_convertable_to_var m_e policy then
283283
SOME (MAP (λ(pred,act). (THE (pred_a2v m_e pred), act)) policy)
284284
else
285285
NONE
@@ -295,7 +295,7 @@ val test_me = ``[
295295
296296
(* Sample policies *)
297297
val empty_policy = ``[] : (arith_pred # string) list``;
298-
val all_convertable_policy = ``[
298+
val all_convertable_to_var_policy = ``[
299299
(arith_a (arithm_gt (lv_x "x") 5), "allow");
300300
(arith_a (arithm_lt (lv_x "y") 2), "deny")
301301
]``;
@@ -304,18 +304,18 @@ val partially_convertable_policy = ``[
304304
(arith_a (arithm_eq (lv_x "z") 1), "log") (* Unmapped *)
305305
]``;
306306
307-
EVAL ``convert ^empty_policy ^test_me``;
307+
EVAL ``convert_arith_to_var_policy ^empty_policy ^test_me``;
308308
(*SOME []*)
309-
EVAL ``convert ^all_convertable_policy ^test_me``;
309+
EVAL ``convert_arith_to_var_policy ^all_convertable_to_var_policy ^test_me``;
310310
(*[(Var "x_gt_5", "allow"); (Var "y_lt_2", "deny")]*)
311-
EVAL ``convert ^partially_convertable_policy ^test_me``;
311+
EVAL ``convert_arith_to_var_policy ^partially_convertable_policy ^test_me``;
312312
(*NONE*)
313313
314314
val complex_policy = ``[
315315
(arith_not (arith_a (arithm_gt (lv_x "x") 5)), "reject");
316316
(arith_and (arith_a a_True) (arith_a (arithm_lt (lv_x "y") 2)), "special")
317317
]``;
318-
EVAL ``convert ^complex_policy ^test_me``;
318+
EVAL ``convert_arith_to_var_policy ^complex_policy ^test_me``;
319319
320320
(*
321321
SOME [
@@ -413,7 +413,7 @@ Theorem policy_airth_to_var_sem_conversion_correct:
413413
(∀var atom.
414414
ALOOKUP m_e var = SOME atom ⇒
415415
ALOOKUP m_v var = eval_arithm_atom packet_input atom) ∧
416-
(convert arith_policy m_e = SOME var_policy)
416+
(convert_arith_to_var_policy arith_policy m_e = SOME var_policy)
417417
418418
sem_arith_policy arith_policy packet_input =
419419
sem_policy var_policy m_v
@@ -423,7 +423,7 @@ Proof
423423
‘check_arith_pred_sem arith_policy packet_input = check_sem_pred var_policy m_v’
424424
suffices_by rw[] >>
425425

426-
fs[convert_def] >>
426+
fs[convert_arith_to_var_policy_def] >>
427427
rw[check_arith_pred_sem_def, check_sem_pred_def] >>
428428

429429
rw[MAP_MAP_o] >>
@@ -433,9 +433,9 @@ Proof
433433
Cases_on ‘x’ >> rw[] >>
434434
rename1 ‘(pred, act)’ >>
435435

436-
(* Since all_convertable holds, pred_a2v m_e pred ≠ NONE *)
436+
(* Since all_convertable_to_var holds, pred_a2v m_e pred ≠ NONE *)
437437
‘pred_a2v m_e pred ≠ NONE’ by (
438-
fs[all_convertable_def, EVERY_MEM] >>
438+
fs[all_convertable_to_var_def, EVERY_MEM] >>
439439
rgs[ELIM_UNCURRY] >>
440440
res_tac >>
441441
fs[FST]

0 commit comments

Comments
 (0)