src/HOL/Tools/refute.ML
changeset 33055 5a733f325939
parent 33054 dd1192a96968
parent 33042 ddf1f03a9ad9
child 33063 4d462963a7db
equal deleted inserted replaced
33054:dd1192a96968 33055:5a733f325939
  1079       (* we've reached the last list element, so there's no shift possible *)
  1079       (* we've reached the last list element, so there's no shift possible *)
  1080       make_first max (len+1) (sum+x+1)  (* increment 'sum' by 1 *)
  1080       make_first max (len+1) (sum+x+1)  (* increment 'sum' by 1 *)
  1081       | next max len sum (x1::x2::xs) =
  1081       | next max len sum (x1::x2::xs) =
  1082       if x1>0 andalso (x2<max orelse max<0) then
  1082       if x1>0 andalso (x2<max orelse max<0) then
  1083         (* we can shift *)
  1083         (* we can shift *)
  1084         SOME (valOf (make_first max (len+1) (sum+x1-1)) @ (x2+1) :: xs)
  1084         SOME (the (make_first max (len+1) (sum+x1-1)) @ (x2+1) :: xs)
  1085       else
  1085       else
  1086         (* continue search *)
  1086         (* continue search *)
  1087         next max (len+1) (sum+x1) (x2::xs)
  1087         next max (len+1) (sum+x1) (x2::xs)
  1088     (* only consider those types for which the size is not fixed *)
  1088     (* only consider those types for which the size is not fixed *)
  1089     val mutables = List.filter
  1089     val mutables = List.filter
  1156       val u      = unfold_defs thy t
  1156       val u      = unfold_defs thy t
  1157       val _      = tracing ("Unfolded term: " ^ Syntax.string_of_term_global thy u)
  1157       val _      = tracing ("Unfolded term: " ^ Syntax.string_of_term_global thy u)
  1158       val axioms = collect_axioms thy u
  1158       val axioms = collect_axioms thy u
  1159       (* Term.typ list *)
  1159       (* Term.typ list *)
  1160       val types = Library.foldl (fn (acc, t') =>
  1160       val types = Library.foldl (fn (acc, t') =>
  1161         acc union (ground_types thy t')) ([], u :: axioms)
  1161         uncurry (union (op =)) (acc, (ground_types thy t'))) ([], u :: axioms)
  1162       val _     = tracing ("Ground types: "
  1162       val _     = tracing ("Ground types: "
  1163         ^ (if null types then "none."
  1163         ^ (if null types then "none."
  1164            else commas (map (Syntax.string_of_typ_global thy) types)))
  1164            else commas (map (Syntax.string_of_typ_global thy) types)))
  1165       (* we can only consider fragments of recursive IDTs, so we issue a  *)
  1165       (* we can only consider fragments of recursive IDTs, so we issue a  *)
  1166       (* warning if the formula contains a recursive IDT                  *)
  1166       (* warning if the formula contains a recursive IDT                  *)
  1618     List.foldr (fn (T, term) => Abs ("<eta_expand>", T, term))
  1618     List.foldr (fn (T, term) => Abs ("<eta_expand>", T, term))
  1619       (Term.list_comb (t', map Bound (i-1 downto 0))) (List.take (Ts, i))
  1619       (Term.list_comb (t', map Bound (i-1 downto 0))) (List.take (Ts, i))
  1620   end;
  1620   end;
  1621 
  1621 
  1622 (* ------------------------------------------------------------------------- *)
  1622 (* ------------------------------------------------------------------------- *)
  1623 (* sum: returns the sum of a list 'xs' of integers                           *)
       
  1624 (* ------------------------------------------------------------------------- *)
       
  1625 
       
  1626   (* int list -> int *)
       
  1627 
       
  1628   fun sum xs = List.foldl op+ 0 xs;
       
  1629 
       
  1630 (* ------------------------------------------------------------------------- *)
       
  1631 (* product: returns the product of a list 'xs' of integers                   *)
       
  1632 (* ------------------------------------------------------------------------- *)
       
  1633 
       
  1634   (* int list -> int *)
       
  1635 
       
  1636   fun product xs = List.foldl op* 1 xs;
       
  1637 
       
  1638 (* ------------------------------------------------------------------------- *)
       
  1639 (* size_of_dtyp: the size of (an initial fragment of) an inductive data type *)
  1623 (* size_of_dtyp: the size of (an initial fragment of) an inductive data type *)
  1640 (*               is the sum (over its constructors) of the product (over     *)
  1624 (*               is the sum (over its constructors) of the product (over     *)
  1641 (*               their arguments) of the size of the argument types          *)
  1625 (*               their arguments) of the size of the argument types          *)
  1642 (* ------------------------------------------------------------------------- *)
  1626 (* ------------------------------------------------------------------------- *)
  1643 
  1627 
  1644   fun size_of_dtyp thy typ_sizes descr typ_assoc constructors =
  1628   fun size_of_dtyp thy typ_sizes descr typ_assoc constructors =
  1645     sum (map (fn (_, dtyps) =>
  1629     Integer.sum (map (fn (_, dtyps) =>
  1646       product (map (size_of_type thy (typ_sizes, []) o
  1630       Integer.prod (map (size_of_type thy (typ_sizes, []) o
  1647         (typ_of_dtyp descr typ_assoc)) dtyps))
  1631         (typ_of_dtyp descr typ_assoc)) dtyps))
  1648           constructors);
  1632           constructors);
  1649 
  1633 
  1650 
  1634 
  1651 (* ------------------------------------------------------------------------- *)
  1635 (* ------------------------------------------------------------------------- *)
  2328             (* we do have a recursion operator of one of the (mutually *)
  2312             (* we do have a recursion operator of one of the (mutually *)
  2329             (* recursive) datatypes given by 'info'                    *)
  2313             (* recursive) datatypes given by 'info'                    *)
  2330             let
  2314             let
  2331               (* number of all constructors, including those of different  *)
  2315               (* number of all constructors, including those of different  *)
  2332               (* (mutually recursive) datatypes within the same descriptor *)
  2316               (* (mutually recursive) datatypes within the same descriptor *)
  2333               val mconstrs_count = sum (map (fn (_, (_, _, cs)) => length cs)
  2317               val mconstrs_count =
  2334                 (#descr info))
  2318                 Integer.sum (map (fn (_, (_, _, cs)) => length cs) (#descr info))
  2335             in
  2319             in
  2336               if mconstrs_count < length params then
  2320               if mconstrs_count < length params then
  2337                 (* too many actual parameters; for now we'll use the *)
  2321                 (* too many actual parameters; for now we'll use the *)
  2338                 (* 'stlc_interpreter' to strip off one application   *)
  2322                 (* 'stlc_interpreter' to strip off one application   *)
  2339                 NONE
  2323                 NONE
  2433                     (fn (DatatypeAux.DtTFree _, _) => true | (_, _) => false)
  2417                     (fn (DatatypeAux.DtTFree _, _) => true | (_, _) => false)
  2434                     (rec_typ_assoc []
  2418                     (rec_typ_assoc []
  2435                       (#2 (the (AList.lookup (op =) descr idt_index)) ~~ (snd o dest_Type) IDT))
  2419                       (#2 (the (AList.lookup (op =) descr idt_index)) ~~ (snd o dest_Type) IDT))
  2436                   (* sanity check: typ_assoc must associate types to the   *)
  2420                   (* sanity check: typ_assoc must associate types to the   *)
  2437                   (*               elements of 'dtyps' (and only to those) *)
  2421                   (*               elements of 'dtyps' (and only to those) *)
  2438                   val _ = if not (Library.eq_set (dtyps, map fst typ_assoc))
  2422                   val _ = if not (eq_set (op =) (dtyps, map fst typ_assoc))
  2439                     then
  2423                     then
  2440                       raise REFUTE ("IDT_recursion_interpreter",
  2424                       raise REFUTE ("IDT_recursion_interpreter",
  2441                         "type association has extra/missing elements")
  2425                         "type association has extra/missing elements")
  2442                     else ()
  2426                     else ()
  2443                   (* interpret each constructor in the descriptor (including *)
  2427                   (* interpret each constructor in the descriptor (including *)
  3025     case t of
  3009     case t of
  3026       Const (@{const_name gfp}, Type ("fun", [Type ("fun",
  3010       Const (@{const_name gfp}, Type ("fun", [Type ("fun",
  3027         [Type ("fun", [T, Type ("bool", [])]),
  3011         [Type ("fun", [T, Type ("bool", [])]),
  3028          Type ("fun", [_, Type ("bool", [])])]),
  3012          Type ("fun", [_, Type ("bool", [])])]),
  3029          Type ("fun", [_, Type ("bool", [])])])) =>
  3013          Type ("fun", [_, Type ("bool", [])])])) =>
  3030       let nonfix union (* because "union" is used below *)
  3014       let
  3031         val size_elem = size_of_type thy model T
  3015         val size_elem = size_of_type thy model T
  3032         (* the universe (i.e. the set that contains every element) *)
  3016         (* the universe (i.e. the set that contains every element) *)
  3033         val i_univ = Node (replicate size_elem TT)
  3017         val i_univ = Node (replicate size_elem TT)
  3034         (* all sets with elements from type 'T' *)
  3018         (* all sets with elements from type 'T' *)
  3035         val i_sets =
  3019         val i_sets =