|
| 1 | +open HolKernel boolLib liteLib simpLib Parse bossLib; |
| 2 | +open arithmeticTheory stringTheory containerTheory pred_setTheory |
| 3 | + listTheory finite_mapTheory; |
| 4 | + |
| 5 | +open bitstringTheory; |
| 6 | +open wordsTheory; |
| 7 | +open optionTheory; |
| 8 | +open sumTheory; |
| 9 | +open stringTheory; |
| 10 | +open ottTheory; |
| 11 | +open pairTheory; |
| 12 | +open rich_listTheory; |
| 13 | +open arithmeticTheory; |
| 14 | +open alistTheory; |
| 15 | +open numeralTheory; |
| 16 | +open alistTheory; |
| 17 | + |
| 18 | + |
| 19 | +open p4Lib; |
| 20 | +open blastLib bitstringLib; |
| 21 | +open p4Theory; |
| 22 | +open p4_auxTheory; |
| 23 | +open p4_coreTheory; |
| 24 | + |
| 25 | +open bdd_genTheory; |
| 26 | +open pred_specTheory; |
| 27 | +open policy_specTheory; |
| 28 | +open tables_specTheory; |
| 29 | +open bdd_isomorphTheory; |
| 30 | +open bdd_end_to_endTheory; |
| 31 | + |
| 32 | +open policy_arith_to_varTheory; |
| 33 | +open table_var_to_arithTheory; |
| 34 | +open table_arith_to_intervalTheory; |
| 35 | + |
| 36 | +open bdd_auxTheory; |
| 37 | +open table_bs_propertiesTheory; |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +val _ = load "bdd_utils"; |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +(* a few types abbreviations *) |
| 46 | +(* |
| 47 | +val _ = type_abbrev("BDD_tbl_type", “:(( (string# num list) var_table_list, (string# num list) action_expr) BDD)”); |
| 48 | +
|
| 49 | +val _ = type_abbrev("struc_tbl_type", “:((( atom_var list # num # (string# num list) action_expr) list list # num, |
| 50 | + (string# num list) action_expr) decision_structure)”); |
| 51 | +
|
| 52 | +val _ = type_abbrev("action_rule_type", “:((string# num list) action_expr) rule”); |
| 53 | +val _ = type_abbrev("action_policy_type", “:((string# num list) action_expr) policy”); |
| 54 | +*) |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | +structure mk_fwd_proof = struct |
| 59 | + |
| 60 | + |
| 61 | + fun convert_arith_policy_to_interval_tables (arith_policy, policy_me, test_pd_type, policy_full_order, policy_order) = |
| 62 | + |
| 63 | + let |
| 64 | + |
| 65 | + (***********************) |
| 66 | + (* STAGE 1 *) |
| 67 | + (***********************) |
| 68 | + |
| 69 | + (*convert arith policy to var policy*) |
| 70 | + val arith_policy_eval = EVAL “convert_arith_to_var_policy ^arith_policy ^policy_me”; |
| 71 | + val var_policy = optionSyntax.dest_some (rhs (concl arith_policy_eval)); |
| 72 | + |
| 73 | + |
| 74 | + (* first establish distinction of domain and range of me*) |
| 75 | + val policy_me_fst_distinct = EVAL “ALL_DISTINCT (MAP FST ^policy_me)”; |
| 76 | + val policy_me_snd_distinct = EVAL “ALL_DISTINCT (MAP SND ^policy_me)”; |
| 77 | + |
| 78 | + val all_distinct_conj = CONJ policy_me_fst_distinct policy_me_snd_distinct; |
| 79 | + |
| 80 | + |
| 81 | + (* Theorem of correctness for conversion from arith policy to var policy *) |
| 82 | + val arith_policy_var_policy_thm = REWRITE_RULE[all_distinct_conj, arith_policy_eval] |
| 83 | + (ISPECL[arith_policy, var_policy, policy_me] policy_airth_to_var_sem_conversion_correct); |
| 84 | + |
| 85 | + |
| 86 | + (***********************) |
| 87 | + (* STAGE 2 *) |
| 88 | + (***********************) |
| 89 | + |
| 90 | + (* create BDD of var policy *) |
| 91 | + val eval_policy_full_opt = EVAL “mk_BDDPred_opt policy_structure (0,[],[(0, non_termn (NONE, ^var_policy))]) [] ^policy_order 1”; |
| 92 | + val eval_policy_full_opt_rhs = optionSyntax.dest_some (rhs (concl eval_policy_full_opt)); |
| 93 | + |
| 94 | + |
| 95 | + (* automatically generate a var table from the var policy's BDD via sml*) |
| 96 | + val test_groupings = rhs(concl(EVAL policy_full_order)); |
| 97 | + val gen_var_table_auto = BDDUtils.bdd_to_tables_iterative eval_policy_full_opt_rhs test_groupings; |
| 98 | + |
| 99 | + |
| 100 | + (* now create a BDD for the table*) |
| 101 | + val eval_table_full_opt_auto = EVAL “mk_BDDPred_opt table_structure (0,[],[(0, non_termn (NONE, ^gen_var_table_auto))]) [] ^policy_order 1”; |
| 102 | + val eval_table_full_opt_auto_rhs = optionSyntax.dest_some (rhs (concl eval_table_full_opt_auto)); |
| 103 | + |
| 104 | + |
| 105 | + (* get I (pairs isomorphic in the graph), and check if isisIsomorph *) |
| 106 | + val get_i_policy = BDDUtils.pairBDDs (eval_policy_full_opt_rhs, eval_table_full_opt_auto_rhs); |
| 107 | + (*val is_tbl_policy1_iso = EVAL “isIsomorph_exec ^get_i_policy ^eval_policy_full_opt_rhs |
| 108 | + ^eval_table_full_opt_auto_rhs”; |
| 109 | + *) |
| 110 | + |
| 111 | + |
| 112 | + (* Theorem of correctness for conversion from var policy to var table *) |
| 113 | + |
| 114 | + (* method 1 *) |
| 115 | + val policy_thm_init = computeLib.RESTR_EVAL_CONV [“sem_tables”,“sem_policy”, “mv_dom_vars”] “correct_var_policy_var_tables_exec ^var_policy ^gen_var_table_auto ^policy_order ^get_i_policy ”; |
| 116 | + val var_policy_var_table_thm = SIMP_RULE bool_ss [correct_var_policy_var_tables_exec_thm1] policy_thm_init; |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + (***********************) |
| 121 | + (* STAGE 3 *) |
| 122 | + (***********************) |
| 123 | + |
| 124 | + (* covert var table to interval table *) |
| 125 | + val only_var_table = fst (dest_pair gen_var_table_auto); |
| 126 | + val convert_to_interval = EVAL “convert_var_to_sinterval_tables ^only_var_table ^policy_me ^test_pd_type”; |
| 127 | + val only_interval_table1 = optionSyntax.dest_some(rhs (concl convert_to_interval)); |
| 128 | + |
| 129 | + |
| 130 | + (* Theorem of correctness for conversion from var table to inteval table *) |
| 131 | + val var_table_sinterval_tbl_thm = |
| 132 | + REWRITE_RULE [convert_to_interval] (ISPECL[only_var_table, only_interval_table1, “0:num”, policy_me, test_pd_type ] correct_tables_from_var_to_sinterval_thm); |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | + (* to glue the theorems we need to take care of the conditions/ assumptions *) |
| 137 | + |
| 138 | + (* condition1 *) |
| 139 | + val every_lval_in_me_in_type_thm = EVAL “every_lval_in_me_in_type ^test_pd_type ^policy_me”; |
| 140 | + val cond1_thm = REWRITE_RULE [every_lval_in_me_in_type_thm, policy_me_fst_distinct] (ISPECL[policy_me, test_pd_type ] lval_in_me_distinct_imp_cond1); |
| 141 | + |
| 142 | + |
| 143 | + (* condition2 *) |
| 144 | + val in_order_then_in_me_thm = EVAL “in_order_then_in_me ^policy_order ^policy_me”; |
| 145 | + val ops_in_me_length_format_thm = EVAL “ops_in_me_length_format ^test_pd_type ^policy_me”; |
| 146 | + |
| 147 | + val cond2_thm = REWRITE_RULE [every_lval_in_me_in_type_thm, policy_me_fst_distinct, |
| 148 | + in_order_then_in_me_thm, ops_in_me_length_format_thm] |
| 149 | + (ISPECL[policy_me, test_pd_type, policy_order ] |
| 150 | + wf_format_imp_cond2); |
| 151 | + |
| 152 | + (* condition3 *) |
| 153 | + val cond3_thm = REWRITE_RULE [every_lval_in_me_in_type_thm, policy_me_fst_distinct, |
| 154 | + in_order_then_in_me_thm, ops_in_me_length_format_thm] |
| 155 | + (ISPECL[policy_me, test_pd_type] |
| 156 | + wf_format_imp_cond3); |
| 157 | + |
| 158 | + |
| 159 | + val final_thm = prove( |
| 160 | + “! packet_input . |
| 161 | + wf_packet ^test_pd_type packet_input ⇒ |
| 162 | + sem_arith_policy ^arith_policy packet_input = |
| 163 | + sem_sinterval_tables (^only_interval_table1,0) packet_input” |
| 164 | + , |
| 165 | + |
| 166 | + rpt strip_tac >> |
| 167 | + |
| 168 | + assume_tac arith_policy_var_policy_thm >> |
| 169 | + first_x_assum (strip_assume_tac o (Q.SPECL [‘packet_input’,‘(create_mv ^policy_me packet_input)’])) >> |
| 170 | + |
| 171 | + assume_tac var_policy_var_table_thm >> |
| 172 | + first_x_assum (strip_assume_tac o (Q.SPECL [‘(create_mv ^policy_me packet_input)’])) >> |
| 173 | + |
| 174 | + |
| 175 | + assume_tac var_table_sinterval_tbl_thm >> |
| 176 | + first_x_assum (strip_assume_tac o (Q.SPECL [‘packet_input’,‘(create_mv ^policy_me packet_input)’])) >> |
| 177 | + |
| 178 | + fs[cond1_thm, cond2_thm, cond3_thm] |
| 179 | + ); |
| 180 | + |
| 181 | + in |
| 182 | + final_thm |
| 183 | + end; |
| 184 | + |
| 185 | +end; |
| 186 | + |
| 187 | + |
| 188 | + |
0 commit comments