105 case List.find (curry (op =) (s, body_type T) o (apsnd body_type o #const)) |
105 case List.find (curry (op =) (s, body_type T) o (apsnd body_type o #const)) |
106 constrs of |
106 constrs of |
107 SOME c => c |
107 SOME c => c |
108 | NONE => constr_spec dtypes x |
108 | NONE => constr_spec dtypes x |
109 |
109 |
110 fun is_complete_type dtypes facto (Type (@{type_name fun}, [T1, T2])) = |
110 fun is_complete_type dtypes facto (Type (\<^type_name>\<open>fun\<close>, [T1, T2])) = |
111 is_concrete_type dtypes facto T1 andalso is_complete_type dtypes facto T2 |
111 is_concrete_type dtypes facto T1 andalso is_complete_type dtypes facto T2 |
112 | is_complete_type dtypes facto (Type (@{type_name prod}, Ts)) = |
112 | is_complete_type dtypes facto (Type (\<^type_name>\<open>prod\<close>, Ts)) = |
113 forall (is_complete_type dtypes facto) Ts |
113 forall (is_complete_type dtypes facto) Ts |
114 | is_complete_type dtypes facto (Type (@{type_name set}, [T'])) = |
114 | is_complete_type dtypes facto (Type (\<^type_name>\<open>set\<close>, [T'])) = |
115 is_concrete_type dtypes facto T' |
115 is_concrete_type dtypes facto T' |
116 | is_complete_type dtypes facto T = |
116 | is_complete_type dtypes facto T = |
117 not (is_integer_like_type T) andalso not (is_bit_type T) andalso |
117 not (is_integer_like_type T) andalso not (is_bit_type T) andalso |
118 fun_from_pair (#complete (the (data_type_spec dtypes T))) facto |
118 fun_from_pair (#complete (the (data_type_spec dtypes T))) facto |
119 handle Option.Option => true |
119 handle Option.Option => true |
120 and is_concrete_type dtypes facto (Type (@{type_name fun}, [T1, T2])) = |
120 and is_concrete_type dtypes facto (Type (\<^type_name>\<open>fun\<close>, [T1, T2])) = |
121 is_complete_type dtypes facto T1 andalso is_concrete_type dtypes facto T2 |
121 is_complete_type dtypes facto T1 andalso is_concrete_type dtypes facto T2 |
122 | is_concrete_type dtypes facto (Type (@{type_name prod}, Ts)) = |
122 | is_concrete_type dtypes facto (Type (\<^type_name>\<open>prod\<close>, Ts)) = |
123 forall (is_concrete_type dtypes facto) Ts |
123 forall (is_concrete_type dtypes facto) Ts |
124 | is_concrete_type dtypes facto (Type (@{type_name set}, [T'])) = |
124 | is_concrete_type dtypes facto (Type (\<^type_name>\<open>set\<close>, [T'])) = |
125 is_complete_type dtypes facto T' |
125 is_complete_type dtypes facto T' |
126 | is_concrete_type dtypes facto T = |
126 | is_concrete_type dtypes facto T = |
127 fun_from_pair (#concrete (the (data_type_spec dtypes T))) facto |
127 fun_from_pair (#concrete (the (data_type_spec dtypes T))) facto |
128 handle Option.Option => true |
128 handle Option.Option => true |
129 and is_exact_type dtypes facto = |
129 and is_exact_type dtypes facto = |
140 |
140 |
141 fun quintuple_for_scope code_type code_term code_string |
141 fun quintuple_for_scope code_type code_term code_string |
142 ({hol_ctxt = {ctxt, ...}, card_assigns, bits, bisim_depth, |
142 ({hol_ctxt = {ctxt, ...}, card_assigns, bits, bisim_depth, |
143 data_types, ...} : scope) = |
143 data_types, ...} : scope) = |
144 let |
144 let |
145 val boring_Ts = [@{typ unsigned_bit}, @{typ signed_bit}, |
145 val boring_Ts = [\<^typ>\<open>unsigned_bit\<close>, \<^typ>\<open>signed_bit\<close>, |
146 @{typ bisim_iterator}] |
146 \<^typ>\<open>bisim_iterator\<close>] |
147 val (iter_assigns, card_assigns) = |
147 val (iter_assigns, card_assigns) = |
148 card_assigns |> filter_out (member (op =) boring_Ts o fst) |
148 card_assigns |> filter_out (member (op =) boring_Ts o fst) |
149 |> List.partition (is_fp_iterator_type o fst) |
149 |> List.partition (is_fp_iterator_type o fst) |
150 val (secondary_card_assigns, primary_card_assigns) = |
150 val (secondary_card_assigns, primary_card_assigns) = |
151 card_assigns |
151 card_assigns |
247 val max_bits = 31 (* Kodkod limit *) |
247 val max_bits = 31 (* Kodkod limit *) |
248 |
248 |
249 fun block_for_type (hol_ctxt as {thy, ...}) binarize cards_assigns maxes_assigns |
249 fun block_for_type (hol_ctxt as {thy, ...}) binarize cards_assigns maxes_assigns |
250 iters_assigns bitss bisim_depths T = |
250 iters_assigns bitss bisim_depths T = |
251 case T of |
251 case T of |
252 @{typ unsigned_bit} => |
252 \<^typ>\<open>unsigned_bit\<close> => |
253 [(Card T, map (Integer.min max_bits o Integer.max 1) bitss)] |
253 [(Card T, map (Integer.min max_bits o Integer.max 1) bitss)] |
254 | @{typ signed_bit} => |
254 | \<^typ>\<open>signed_bit\<close> => |
255 [(Card T, map (Integer.add 1 o Integer.min max_bits o Integer.max 1) bitss)] |
255 [(Card T, map (Integer.add 1 o Integer.min max_bits o Integer.max 1) bitss)] |
256 | @{typ "unsigned_bit word"} => |
256 | \<^typ>\<open>unsigned_bit word\<close> => |
257 [(Card T, lookup_type_ints_assign thy cards_assigns nat_T)] |
257 [(Card T, lookup_type_ints_assign thy cards_assigns nat_T)] |
258 | @{typ "signed_bit word"} => |
258 | \<^typ>\<open>signed_bit word\<close> => |
259 [(Card T, lookup_type_ints_assign thy cards_assigns int_T)] |
259 [(Card T, lookup_type_ints_assign thy cards_assigns int_T)] |
260 | @{typ bisim_iterator} => |
260 | \<^typ>\<open>bisim_iterator\<close> => |
261 [(Card T, map (Integer.add 1 o Integer.max 0) bisim_depths)] |
261 [(Card T, map (Integer.add 1 o Integer.max 0) bisim_depths)] |
262 | _ => |
262 | _ => |
263 if is_fp_iterator_type T then |
263 if is_fp_iterator_type T then |
264 [(Card T, map (Integer.add 1 o Integer.max 0) |
264 [(Card T, map (Integer.add 1 o Integer.max 0) |
265 (lookup_const_ints_assign thy iters_assigns |
265 (lookup_const_ints_assign thy iters_assigns |
337 | NONE => raise SAME ()) |
337 | NONE => raise SAME ()) |
338 handle SAME () => aux seen ((T, k - 1) :: rest) |
338 handle SAME () => aux seen ((T, k - 1) :: rest) |
339 in aux [] (rev card_assigns) end |
339 in aux [] (rev card_assigns) end |
340 |
340 |
341 fun repair_iterator_assign ctxt assigns (T as Type (_, Ts), k) = |
341 fun repair_iterator_assign ctxt assigns (T as Type (_, Ts), k) = |
342 (T, if T = @{typ bisim_iterator} then |
342 (T, if T = \<^typ>\<open>bisim_iterator\<close> then |
343 let |
343 let |
344 val co_cards = map snd (filter (is_codatatype ctxt o fst) assigns) |
344 val co_cards = map snd (filter (is_codatatype ctxt o fst) assigns) |
345 in Int.min (k, Integer.sum co_cards) end |
345 in Int.min (k, Integer.sum co_cards) end |
346 else if is_fp_iterator_type T then |
346 else if is_fp_iterator_type T then |
347 case Ts of |
347 case Ts of |
478 let |
478 let |
479 val data_types = |
479 val data_types = |
480 map (data_type_spec_from_scope_descriptor hol_ctxt binarize deep_dataTs |
480 map (data_type_spec_from_scope_descriptor hol_ctxt binarize deep_dataTs |
481 finitizable_dataTs desc) |
481 finitizable_dataTs desc) |
482 (filter (is_data_type ctxt o fst) card_assigns) |
482 (filter (is_data_type ctxt o fst) card_assigns) |
483 val bits = card_of_type card_assigns @{typ signed_bit} - 1 |
483 val bits = card_of_type card_assigns \<^typ>\<open>signed_bit\<close> - 1 |
484 handle TYPE ("Nitpick_HOL.card_of_type", _, _) => |
484 handle TYPE ("Nitpick_HOL.card_of_type", _, _) => |
485 card_of_type card_assigns @{typ unsigned_bit} |
485 card_of_type card_assigns \<^typ>\<open>unsigned_bit\<close> |
486 handle TYPE ("Nitpick_HOL.card_of_type", _, _) => 0 |
486 handle TYPE ("Nitpick_HOL.card_of_type", _, _) => 0 |
487 val bisim_depth = card_of_type card_assigns @{typ bisim_iterator} - 1 |
487 val bisim_depth = card_of_type card_assigns \<^typ>\<open>bisim_iterator\<close> - 1 |
488 in |
488 in |
489 {hol_ctxt = hol_ctxt, binarize = binarize, card_assigns = card_assigns, |
489 {hol_ctxt = hol_ctxt, binarize = binarize, card_assigns = card_assigns, |
490 data_types = data_types, bits = bits, bisim_depth = bisim_depth, |
490 data_types = data_types, bits = bits, bisim_depth = bisim_depth, |
491 ofs = offset_table_for_card_assigns data_types card_assigns} |
491 ofs = offset_table_for_card_assigns data_types card_assigns} |
492 end |
492 end |