@@ -145,8 +145,6 @@ val _ = Hol_datatype `
145145
146146
147147
148-
149-
150148Definition arth_indic_in_lval_def:
151149 arth_indic_in_lval isTrue = F ∧
152150 arth_indic_in_lval isFalse = F ∧
327325
328326
329327Definition match_interval_table_def:
330- match_interval_table st_in (interval_table:'a intvl_table) pd =
328+ match_interval_table (interval_table:'a intvl_table) pd st_in =
331329 case check_interval_table_sem st_in interval_table pd of
332330 | SOME res =>
333331 (case min_idx_till res T of
@@ -359,9 +357,9 @@ val example_interval_table=
359357 ([Single ([F; F; F; F; F; F; F; F],8) ([T; T; T; T; T; T; T; T],8)],
360358 1,action "drop")]): string intvl_table”;
361359
362- EVAL “match_interval_table (1:num)
360+ EVAL “match_interval_table
363361 ^example_interval_table
364- ^example_pd ”;
362+ ^example_pd (1:num) ”;
365363
366364*)
367365
@@ -758,8 +756,8 @@ Theorem full_table_arith_interval_correct:
758756 ∀ arith_table interval_table packet_input packet_type st_in.
759757 wf_packet packet_type packet_input ∧
760758 (convert_arith_to_interval_table arith_table packet_type = SOME interval_table) ⇒
761- (match_interval_table st_in interval_table packet_input =
762- match_arith_table st_in arith_table packet_input)
759+ (match_interval_table interval_table packet_input st_in =
760+ match_arith_table arith_table packet_input st_in )
763761Proof
764762 rw[match_interval_table_def, match_arith_table_def] >>
765763
@@ -1032,7 +1030,7 @@ End
10321030
10331031
10341032Definition match_sinterval_table_def:
1035- match_sinterval_table st_in (sinterval_table:'a sintvl_table) pd =
1033+ match_sinterval_table (sinterval_table:'a sintvl_table) pd st_in =
10361034 case check_sinterval_table_sem st_in sinterval_table pd of
10371035 | SOME res =>
10381036 (case min_idx_till res T of
@@ -1045,7 +1043,10 @@ End
10451043
10461044
10471045
1048- (* *****************************)
1046+
1047+ (* ==================================================*)
1048+ (* Proof correctness interval to sinterval *)
1049+ (* ==================================================*)
10491050
10501051
10511052Theorem wfness_type_of_lval_thm:
@@ -1760,10 +1761,6 @@ QED
17601761
17611762
17621763
1763-
1764-
1765-
1766-
17671764
17681765
17691766Theorem check_sinterval_table_sem_table_correct:
@@ -1913,18 +1910,197 @@ Theorem match_sinterval_table_correct:
19131910 ∀ interval_table sinterval_table packet_input packet_type st_in.
19141911 wf_packet packet_type packet_input ∧
19151912 (convert_interval_to_sinterval_table interval_table packet_type = SOME sinterval_table) ⇒
1916- ( match_sinterval_table st_in sinterval_table packet_input =
1917- match_interval_table st_in interval_table packet_input)
1913+ ( match_sinterval_table sinterval_table packet_input st_in =
1914+ match_interval_table interval_table packet_input st_in )
19181915Proof
1916+ rw[match_sinterval_table_def, match_interval_table_def] >>
1917+ ‘check_sinterval_table_sem st_in sinterval_table packet_input =
1918+ check_interval_table_sem st_in interval_table packet_input’ by metis_tac[check_sinterval_table_sem_table_correct] >>
1919+ gvs[]
1920+ QED
1921+
1922+
1923+
1924+
1925+
1926+ (* ======================================================*)
1927+ (* now we merge the last three steps in one stage *)
1928+ (* from variables to arith table *)
1929+ (* then from arith to many intervals table *)
1930+ (* then from intervals to single sinterval table *)
1931+ (* ======================================================*)
1932+
1933+
1934+
1935+ Definition convert_var_to_sinterval_table_def:
1936+ convert_var_to_sinterval_table var_table me pd_type=
1937+ (case convert_var_to_arith_table var_table me of
1938+ | SOME arith_table =>
1939+ ( case convert_arith_to_interval_table arith_table pd_type of
1940+ | SOME interval_table => convert_interval_to_sinterval_table interval_table pd_type
1941+ | NONE => NONE
1942+ )
1943+ | NONE => NONE )
1944+ End
1945+
1946+
1947+
1948+
1949+
1950+ (*
1951+
1952+
1953+ val test_pd = ``[("ttl", type_length 5);
1954+ ("src", type_length 5)]``;
1955+
1956+ val test_me = ``[("x1", arithm_ge (lv_x "ttl") (fixwidth 5 (n2v 0), 5));
1957+ ("x2", arithm_le (lv_x "ttl") (fixwidth 5 (n2v 10), 5))]``;
1958+
1959+
1960+ val test_var_table = ``[
1961+ ([True; Var "x1"; Var "x2"], 1n, action "fwd1");
1962+ ([Var "x1"; Not "x2"], 1n, action "fwd2");
1963+ ([Var "x2"; Not "x2"], 1n, action "fwd3");
1964+ ([True], 1n, action "drop")
1965+ ]``;
1966+
1967+
1968+ val test_final_table =
1969+ EVAL ``convert_var_to_sinterval_table ^test_var_table ^test_me ^test_pd``;
1970+
1971+
1972+
1973+ val test_var_table2 = ``[
1974+ ([True; True], 1n, action "fwd1");
1975+ ([False], 1n, action "fwd2");
1976+ ([Var "x2"; Not "x2"], 1n, action "fwd3");
1977+ ([True], 1n, action "drop")
1978+ ]``;
1979+
1980+
1981+ val test_final_table2 =
1982+ EVAL ``convert_var_to_sinterval_table ^test_var_table2 ^test_me ^test_pd``;
1983+
1984+
1985+
1986+
1987+
1988+
1989+ val test_var_table3 = ``[
1990+ ([True; True], 1n, action "fwd1");
1991+ ([False], 1n, action "fwd2");
1992+ ([True], 1n, action "fwd3");
1993+ ([True], 1n, action "drop")
1994+ ]``;
1995+
1996+
1997+ val test_final_table3 =
1998+ EVAL ``convert_var_to_sinterval_table ^test_var_table2 ^test_me ^test_pd``;
1999+
2000+ *)
2001+
2002+
2003+
2004+
2005+ Definition convert_var_to_sinterval_tables_def:
2006+ convert_var_to_sinterval_tables [] me pd_type= NONE ∧
2007+ convert_var_to_sinterval_tables var_tables me pd_type=
2008+ let converted_list = MAP (λvar_table. convert_var_to_sinterval_table var_table me pd_type) var_tables in
2009+ if EVERY IS_SOME converted_list then
2010+ SOME (MAP THE converted_list)
2011+ else
2012+ NONE
2013+ End
2014+
2015+
2016+
2017+ (* semantics of last stage's full tables chain of the three steps var-arith-intervals-sinterval*)
2018+
2019+
2020+ (* Process table list with state propagation *)
2021+ Definition match_sinterval_tbll_def:
2022+ match_sinterval_tbll [] packet_input st_in = NONE ∧
2023+ match_sinterval_tbll [sinterval_table] packet_input st_in =
2024+ ( case match_sinterval_table sinterval_table packet_input st_in of
2025+ | SOME (action a) => SOME (action a)
2026+ | _ => NONE
2027+ )∧
2028+ match_sinterval_tbll (sinterval_table::tbls) packet_input st_in =
2029+ ( case match_sinterval_table sinterval_table packet_input st_in of
2030+ | SOME (state n) => match_sinterval_tbll tbls packet_input n
2031+ | _ => NONE
2032+ )
2033+ End
2034+
2035+
2036+ (* Top-level table semantics, return the starting state as well*)
2037+ Definition sem_sinterval_tables_def:
2038+ sem_sinterval_tables (sinterval_tbll,st_in) packet_input =
2039+ match_sinterval_tbll sinterval_tbll packet_input st_in
2040+ End
2041+
2042+
19192043
1920- rw[match_sinterval_table_def, match_interval_table_def] >>
1921- ‘check_sinterval_table_sem st_in sinterval_table packet_input =
1922- check_interval_table_sem st_in interval_table packet_input’ by metis_tac[check_sinterval_table_sem_table_correct] >>
1923- gvs[]
2044+
2045+ (* final tables translation *)
2046+
2047+ Theorem correct_tables_from_var_to_sinterval_thm:
2048+ ∀var_tables sinterval_tables st_in .
2049+ ∀ mv me packet_type packet_input.
2050+
2051+ (∀var. lookup_is_some mv var ⇔ lookup_is_some me var) ∧
2052+ (∀var atom.
2053+ ALOOKUP me var = SOME atom ⇒
2054+ ALOOKUP mv var = eval_arithm_atom packet_input atom) ∧
2055+ wf_packet packet_type packet_input ∧
2056+ convert_var_to_sinterval_tables var_tables me packet_type = SOME sinterval_tables ⇒
2057+
2058+ ( sem_tables ((var_tables: 'a var_table_list),st_in) mv =
2059+ sem_sinterval_tables ((sinterval_tables: 'a sintvl_table_list),st_in) packet_input )
2060+ Proof
2061+ Induct_on ‘var_tables’ >>
2062+ rw[sem_tables_def, sem_sinterval_tables_def] >-
2063+ gvs[convert_var_to_sinterval_tables_def] >>
2064+
2065+ rgs[convert_var_to_sinterval_tables_def] >>
2066+ Cases_on ‘convert_var_to_sinterval_table h me packet_type’ >> gvs[] >>
2067+ rgs[Once convert_var_to_sinterval_table_def] >>
2068+ rpt (BasicProvers.full_case_tac >> gvs[]) >>
2069+
2070+ simp[match_tbll_def, match_sinterval_tbll_def] >>
2071+
2072+ imp_res_tac table_var_arith_correct >>
2073+ first_x_assum (strip_assume_tac o (Q.SPECL [‘st_in’])) >>
2074+
2075+ imp_res_tac full_table_arith_interval_correct >>
2076+ first_x_assum (strip_assume_tac o (Q.SPECL [‘st_in’])) >>
2077+
2078+ imp_res_tac match_sinterval_table_correct >>
2079+ first_x_assum (strip_assume_tac o (Q.SPECL [‘st_in’])) >>
2080+
2081+ Cases_on ‘var_tables’ >| [
2082+ simp[match_tbll_def, match_sinterval_tbll_def]
2083+ ,
2084+
2085+ simp[match_tbll_def, match_sinterval_tbll_def] >>
2086+ rpt (BasicProvers.full_case_tac >> gvs[]) >>
2087+
2088+ gvs[Once convert_var_to_sinterval_tables_def] >>
2089+ res_tac >>
2090+ first_x_assum (strip_assume_tac o (Q.SPECL [‘n’])) >>
2091+ metis_tac[sem_tables_def, sem_sinterval_tables_def]
2092+ ]
19242093QED
19252094
19262095
19272096
2097+
2098+
2099+
2100+
2101+
2102+
2103+
19282104
19292105val _ = export_theory ();
19302106
0 commit comments