69 if for_auto then |
71 if for_auto then |
70 Free (atom_name (hd (space_explode "." nitpick_prefix)) T j, T) |
72 Free (atom_name (hd (space_explode "." nitpick_prefix)) T j, T) |
71 else |
73 else |
72 Const (atom_name "" T j, T) |
74 Const (atom_name "" T j, T) |
73 |
75 |
|
76 (* term -> real *) |
|
77 fun extract_real_number (Const (@{const_name HOL.divide}, _) $ t1 $ t2) = |
|
78 real (snd (HOLogic.dest_number t1)) / real (snd (HOLogic.dest_number t2)) |
|
79 | extract_real_number t = real (snd (HOLogic.dest_number t)) |
74 (* term * term -> order *) |
80 (* term * term -> order *) |
75 fun nice_term_ord (Abs (_, _, t1), Abs (_, _, t2)) = nice_term_ord (t1, t2) |
81 fun nice_term_ord (Abs (_, _, t1), Abs (_, _, t2)) = nice_term_ord (t1, t2) |
76 | nice_term_ord (t1, t2) = |
82 | nice_term_ord tp = Real.compare (pairself extract_real_number tp) |
77 int_ord (snd (HOLogic.dest_number t1), snd (HOLogic.dest_number t2)) |
|
78 handle TERM ("dest_number", _) => |
83 handle TERM ("dest_number", _) => |
79 case (t1, t2) of |
84 case tp of |
80 (t11 $ t12, t21 $ t22) => |
85 (t11 $ t12, t21 $ t22) => |
81 (case nice_term_ord (t11, t21) of |
86 (case nice_term_ord (t11, t21) of |
82 EQUAL => nice_term_ord (t12, t22) |
87 EQUAL => nice_term_ord (t12, t22) |
83 | ord => ord) |
88 | ord => ord) |
84 | _ => TermOrd.term_ord (t1, t2) |
89 | _ => TermOrd.fast_term_ord tp |
85 |
90 |
86 (* nut NameTable.table -> Kodkod.raw_bound list -> nut -> int list list *) |
91 (* nut NameTable.table -> KK.raw_bound list -> nut -> int list list *) |
87 fun tuple_list_for_name rel_table bounds name = |
92 fun tuple_list_for_name rel_table bounds name = |
88 the (AList.lookup (op =) bounds (the_rel rel_table name)) handle NUT _ => [[]] |
93 the (AList.lookup (op =) bounds (the_rel rel_table name)) handle NUT _ => [[]] |
89 |
94 |
90 (* term -> term *) |
95 (* term -> term *) |
91 fun unbit_and_unbox_term (Const (@{const_name FunBox}, _) $ t1) = |
96 fun unbit_and_unbox_term (Const (@{const_name FunBox}, _) $ t1) = |
238 mk_tuple T2 (List.drop (ts, length (HOLogic.flatten_tupleT T1)))) |
243 mk_tuple T2 (List.drop (ts, length (HOLogic.flatten_tupleT T1)))) |
239 | mk_tuple _ (t :: _) = t |
244 | mk_tuple _ (t :: _) = t |
240 | mk_tuple T [] = raise TYPE ("Nitpick_Model.mk_tuple", [T], []) |
245 | mk_tuple T [] = raise TYPE ("Nitpick_Model.mk_tuple", [T], []) |
241 |
246 |
242 (* string * string * string * string -> scope -> nut list -> nut list |
247 (* string * string * string * string -> scope -> nut list -> nut list |
243 -> nut list -> nut NameTable.table -> Kodkod.raw_bound list -> typ -> typ |
248 -> nut list -> nut NameTable.table -> KK.raw_bound list -> typ -> typ -> rep |
244 -> rep -> int list list -> term *) |
249 -> int list list -> term *) |
245 fun reconstruct_term (maybe_name, base_name, step_name, abs_name) |
250 fun reconstruct_term (maybe_name, base_name, step_name, abs_name) |
246 ({ext_ctxt as {thy, ctxt, ...}, card_assigns, bits, datatypes, ofs, ...} |
251 ({ext_ctxt as {thy, ctxt, ...}, card_assigns, bits, datatypes, ofs, ...} |
247 : scope) sel_names rel_table bounds = |
252 : scope) sel_names rel_table bounds = |
248 let |
253 let |
249 val for_auto = (maybe_name = "") |
254 val for_auto = (maybe_name = "") |
322 t1 $ t2 => setify_mapify_funs Ts t1 $ setify_mapify_funs Ts t2 |
327 t1 $ t2 => setify_mapify_funs Ts t1 $ setify_mapify_funs Ts t2 |
323 | Abs (s, T, t') => Abs (s, T, setify_mapify_funs (T :: Ts) t') |
328 | Abs (s, T, t') => Abs (s, T, setify_mapify_funs (T :: Ts) t') |
324 | _ => t |
329 | _ => t |
325 (* bool -> typ -> typ -> typ -> term list -> term list -> term *) |
330 (* bool -> typ -> typ -> typ -> term list -> term list -> term *) |
326 fun make_fun maybe_opt T1 T2 T' ts1 ts2 = |
331 fun make_fun maybe_opt T1 T2 T' ts1 ts2 = |
327 ts1 ~~ ts2 |> T1 = @{typ bisim_iterator} ? rev |
332 ts1 ~~ ts2 |> sort (nice_term_ord o pairself fst) |
328 |> make_plain_fun (maybe_opt andalso not for_auto) T1 T2 |
333 |> make_plain_fun (maybe_opt andalso not for_auto) T1 T2 |
329 |> unbit_and_unbox_term |
334 |> unbit_and_unbox_term |
330 |> typecast_fun (unbit_and_unbox_type T') |
335 |> typecast_fun (unbit_and_unbox_type T') |
331 (unbit_and_unbox_type T1) |
336 (unbit_and_unbox_type T1) |
332 (unbit_and_unbox_type T2) |
337 (unbit_and_unbox_type T2) |
504 in |
509 in |
505 (not for_auto ? setify_mapify_funs []) o unbit_and_unbox_term |
510 (not for_auto ? setify_mapify_funs []) o unbit_and_unbox_term |
506 oooo term_for_rep [] |
511 oooo term_for_rep [] |
507 end |
512 end |
508 |
513 |
509 (* scope -> nut list -> nut NameTable.table -> Kodkod.raw_bound list -> nut |
514 (* scope -> nut list -> nut NameTable.table -> KK.raw_bound list -> nut |
510 -> term *) |
515 -> term *) |
511 fun term_for_name scope sel_names rel_table bounds name = |
516 fun term_for_name scope sel_names rel_table bounds name = |
512 let val T = type_of name in |
517 let val T = type_of name in |
513 tuple_list_for_name rel_table bounds name |
518 tuple_list_for_name rel_table bounds name |
514 |> reconstruct_term ("", "", "", "") scope sel_names rel_table bounds T T |
519 |> reconstruct_term ("", "", "", "") scope sel_names rel_table bounds T T |
561 else |
566 else |
562 t1 = t2 |
567 t1 = t2 |
563 end |
568 end |
564 |
569 |
565 (* params -> scope -> (term option * int list) list -> styp list -> nut list |
570 (* params -> scope -> (term option * int list) list -> styp list -> nut list |
566 -> nut list -> nut list -> nut NameTable.table -> Kodkod.raw_bound list |
571 -> nut list -> nut list -> nut NameTable.table -> KK.raw_bound list |
567 -> Pretty.T * bool *) |
572 -> Pretty.T * bool *) |
568 fun reconstruct_hol_model {show_skolems, show_datatypes, show_consts} |
573 fun reconstruct_hol_model {show_skolems, show_datatypes, show_consts} |
569 ({ext_ctxt as {thy, ctxt, max_bisim_depth, boxes, wfs, user_axioms, |
574 ({ext_ctxt as {thy, ctxt, max_bisim_depth, boxes, wfs, user_axioms, |
570 debug, binary_ints, destroy_constrs, specialize, |
575 debug, binary_ints, destroy_constrs, specialize, |
571 skolemize, star_linear_preds, uncurry, fast_descrs, |
576 skolemize, star_linear_preds, uncurry, fast_descrs, |
702 bisim_depth >= 0 |
707 bisim_depth >= 0 |
703 orelse forall (is_codatatype_wellformed codatatypes) codatatypes) |
708 orelse forall (is_codatatype_wellformed codatatypes) codatatypes) |
704 end |
709 end |
705 |
710 |
706 (* scope -> Time.time option -> nut list -> nut list -> nut NameTable.table |
711 (* scope -> Time.time option -> nut list -> nut list -> nut NameTable.table |
707 -> Kodkod.raw_bound list -> term -> bool option *) |
712 -> KK.raw_bound list -> term -> bool option *) |
708 fun prove_hol_model (scope as {ext_ctxt as {thy, ctxt, ...}, card_assigns, ...}) |
713 fun prove_hol_model (scope as {ext_ctxt as {thy, ctxt, ...}, card_assigns, ...}) |
709 auto_timeout free_names sel_names rel_table bounds prop = |
714 auto_timeout free_names sel_names rel_table bounds prop = |
710 let |
715 let |
711 (* typ * int -> term *) |
716 (* typ * int -> term *) |
712 fun free_type_assm (T, k) = |
717 fun free_type_assm (T, k) = |