247 iters_assigns bitss bisim_depths T = |
247 iters_assigns bitss bisim_depths T = |
248 if T = @{typ unsigned_bit} then |
248 if T = @{typ unsigned_bit} then |
249 [(Card T, map (Integer.min max_bits o Integer.max 1) bitss)] |
249 [(Card T, map (Integer.min max_bits o Integer.max 1) bitss)] |
250 else if T = @{typ signed_bit} then |
250 else if T = @{typ signed_bit} then |
251 [(Card T, map (Integer.add 1 o Integer.min max_bits o Integer.max 1) bitss)] |
251 [(Card T, map (Integer.add 1 o Integer.min max_bits o Integer.max 1) bitss)] |
|
252 else if T = @{typ "unsigned_bit word"} then |
|
253 [(Card T, lookup_type_ints_assign thy cards_assigns nat_T)] |
|
254 else if T = @{typ "signed_bit word"} then |
|
255 [(Card T, lookup_type_ints_assign thy cards_assigns int_T)] |
252 else if T = @{typ bisim_iterator} then |
256 else if T = @{typ bisim_iterator} then |
253 [(Card T, map (Integer.add 1 o Integer.max 0) bisim_depths)] |
257 [(Card T, map (Integer.add 1 o Integer.max 0) bisim_depths)] |
254 else if is_fp_iterator_type T then |
258 else if is_fp_iterator_type T then |
255 [(Card T, map (Integer.add 1 o Integer.max 0) |
259 [(Card T, map (Integer.add 1 o Integer.max 0) |
256 (lookup_const_ints_assign thy iters_assigns |
260 (lookup_const_ints_assign thy iters_assigns |
314 (T, k) = |
318 (T, k) = |
315 case datatype_constrs ext_ctxt T of |
319 case datatype_constrs ext_ctxt T of |
316 [] => false |
320 [] => false |
317 | xs => |
321 | xs => |
318 let |
322 let |
319 val exact_cards = |
323 val dom_cards = |
320 map (Integer.prod |
324 map (Integer.prod o map (bounded_card_of_type k ~1 card_assigns) |
321 o map (bounded_exact_card_of_type ext_ctxt k 0 card_assigns) |
|
322 o binder_types o snd) xs |
325 o binder_types o snd) xs |
323 val maxes = map (constr_max max_assigns) xs |
326 val maxes = map (constr_max max_assigns) xs |
324 (* int -> int -> int *) |
327 (* int -> int -> int *) |
325 fun effective_max 0 ~1 = k |
328 fun effective_max card ~1 = card |
326 | effective_max 0 max = max |
|
327 | effective_max card ~1 = card |
|
328 | effective_max card max = Int.min (card, max) |
329 | effective_max card max = Int.min (card, max) |
329 val max = map2 effective_max exact_cards maxes |> Integer.sum |
330 val max = map2 effective_max dom_cards maxes |> Integer.sum |
330 (* unit -> int *) |
331 in max < k end |
331 fun doms_card () = |
332 (* extended_context -> (typ * int) list -> (typ * int) list |
332 xs |> map (Integer.prod o map (bounded_card_of_type k ~1 card_assigns) |
333 -> (styp * int) list -> bool *) |
333 o binder_types o snd) |
334 fun is_surely_inconsistent_scope_description ext_ctxt seen rest max_assigns = |
334 |> Integer.sum |
335 exists (is_surely_inconsistent_card_assign ext_ctxt |
335 in |
336 (seen @ rest, max_assigns)) seen |
336 max < k |
|
337 orelse (forall (not_equal 0) exact_cards andalso doms_card () < k) |
|
338 end |
|
339 handle TYPE ("Nitpick_HOL.card_of_type", _, _) => false |
|
340 |
|
341 (* extended_context -> scope_desc -> bool *) |
|
342 fun is_surely_inconsistent_scope_description ext_ctxt |
|
343 (desc as (card_assigns, _)) = |
|
344 exists (is_surely_inconsistent_card_assign ext_ctxt desc) card_assigns |
|
345 |
337 |
346 (* extended_context -> scope_desc -> (typ * int) list option *) |
338 (* extended_context -> scope_desc -> (typ * int) list option *) |
347 fun repair_card_assigns ext_ctxt (card_assigns, max_assigns) = |
339 fun repair_card_assigns ext_ctxt (card_assigns, max_assigns) = |
348 let |
340 let |
349 (* (typ * int) list -> (typ * int) list -> (typ * int) list option *) |
341 (* (typ * int) list -> (typ * int) list -> (typ * int) list option *) |
350 fun aux seen [] = SOME seen |
342 fun aux seen [] = SOME seen |
351 | aux seen ((T, 0) :: _) = NONE |
343 | aux seen ((T, 0) :: _) = NONE |
352 | aux seen ((T, k) :: assigns) = |
344 | aux seen ((T, k) :: rest) = |
353 (if is_surely_inconsistent_scope_description ext_ctxt |
345 (if is_surely_inconsistent_scope_description ext_ctxt ((T, k) :: seen) |
354 ((T, k) :: seen, max_assigns) then |
346 rest max_assigns then |
355 raise SAME () |
347 raise SAME () |
356 else |
348 else |
357 case aux ((T, k) :: seen) assigns of |
349 case aux ((T, k) :: seen) rest of |
358 SOME assigns => SOME assigns |
350 SOME assigns => SOME assigns |
359 | NONE => raise SAME ()) |
351 | NONE => raise SAME ()) |
360 handle SAME () => aux seen ((T, k - 1) :: assigns) |
352 handle SAME () => aux seen ((T, k - 1) :: rest) |
361 in aux [] (rev card_assigns) end |
353 in aux [] (rev card_assigns) end |
362 |
354 |
363 (* theory -> (typ * int) list -> typ * int -> typ * int *) |
355 (* theory -> (typ * int) list -> typ * int -> typ * int *) |
364 fun repair_iterator_assign thy assigns (T as Type (s, Ts), k) = |
356 fun repair_iterator_assign thy assigns (T as Type (s, Ts), k) = |
365 (T, if T = @{typ bisim_iterator} then |
357 (T, if T = @{typ bisim_iterator} then |