src/HOL/Tools/refute.ML
changeset 19346 c4c003abd830
parent 19277 f7602e74d948
child 19642 ea7162f84677
equal deleted inserted replaced
19345:73439b467e75 19346:c4c003abd830
   552 						end
   552 						end
   553 						handle ERROR _         => get_typedefn axms
   553 						handle ERROR _         => get_typedefn axms
   554 						     | MATCH           => get_typedefn axms
   554 						     | MATCH           => get_typedefn axms
   555 						     | Type.TYPE_MATCH => get_typedefn axms)
   555 						     | Type.TYPE_MATCH => get_typedefn axms)
   556 				in
   556 				in
   557 					case DatatypePackage.datatype_info thy s of
   557 					case DatatypePackage.get_datatype thy s of
   558 					  SOME info =>  (* inductive datatype *)
   558 					  SOME info =>  (* inductive datatype *)
   559 							(* only collect relevant type axioms for the argument types *)
   559 							(* only collect relevant type axioms for the argument types *)
   560 							Library.foldl collect_type_axioms (axs, Ts)
   560 							Library.foldl collect_type_axioms (axs, Ts)
   561 					| NONE =>
   561 					| NONE =>
   562 						(case get_typedefn axioms of
   562 						(case get_typedefn axioms of
   662 					(* inductive data types *)
   662 					(* inductive data types *)
   663 					(* unit -> bool *)
   663 					(* unit -> bool *)
   664 					fun is_IDT_constructor () =
   664 					fun is_IDT_constructor () =
   665 						(case body_type T of
   665 						(case body_type T of
   666 						  Type (s', _) =>
   666 						  Type (s', _) =>
   667 							(case DatatypePackage.constrs_of thy s' of
   667 							(case DatatypePackage.get_datatype_constrs thy s' of
   668 							  SOME constrs =>
   668 							  SOME constrs =>
   669 								Library.exists (fn c =>
   669 								Library.exists (fn (cname, cty) =>
   670 									(case c of
   670 								cname = s andalso Sign.typ_instance thy (T, cty))
   671 									  Const (cname, ctype) =>
       
   672 										cname = s andalso Sign.typ_instance thy (T, ctype)
       
   673 									| _ =>
       
   674 										raise REFUTE ("collect_axioms", "IDT constructor is not a constant")))
       
   675 									constrs
   671 									constrs
   676 							| NONE =>
   672 							| NONE =>
   677 								false)
   673 								false)
   678 						| _  =>
   674 						| _  =>
   679 							false)
   675 							false)
   771 				(case T of
   767 				(case T of
   772 				  Type ("fun", [T1, T2]) => collect_types (T1, collect_types (T2, acc))
   768 				  Type ("fun", [T1, T2]) => collect_types (T1, collect_types (T2, acc))
   773 				| Type ("prop", [])      => acc
   769 				| Type ("prop", [])      => acc
   774 				| Type ("set", [T1])     => collect_types (T1, acc)
   770 				| Type ("set", [T1])     => collect_types (T1, acc)
   775 				| Type (s, Ts)           =>
   771 				| Type (s, Ts)           =>
   776 					(case DatatypePackage.datatype_info thy s of
   772 					(case DatatypePackage.get_datatype thy s of
   777 					  SOME info =>  (* inductive datatype *)
   773 					  SOME info =>  (* inductive datatype *)
   778 						let
   774 						let
   779 							val index               = #index info
   775 							val index               = #index info
   780 							val descr               = #descr info
   776 							val descr               = #descr info
   781 							val (_, dtyps, constrs) = (the o AList.lookup (op =) descr) index
   777 							val (_, dtyps, constrs) = (the o AList.lookup (op =) descr) index
   942 			(* we can only consider fragments of recursive IDTs, so we issue a  *)
   938 			(* we can only consider fragments of recursive IDTs, so we issue a  *)
   943 			(* warning if the formula contains a recursive IDT                  *)
   939 			(* warning if the formula contains a recursive IDT                  *)
   944 			(* TODO: no warning needed for /positive/ occurrences of IDTs       *)
   940 			(* TODO: no warning needed for /positive/ occurrences of IDTs       *)
   945 			val _ = if Library.exists (fn
   941 			val _ = if Library.exists (fn
   946 				  Type (s, _) =>
   942 				  Type (s, _) =>
   947 					(case DatatypePackage.datatype_info thy s of
   943 					(case DatatypePackage.get_datatype thy s of
   948 					  SOME info =>  (* inductive datatype *)
   944 					  SOME info =>  (* inductive datatype *)
   949 						let
   945 						let
   950 							val index           = #index info
   946 							val index           = #index info
   951 							val descr           = #descr info
   947 							val descr           = #descr info
   952 							val (_, _, constrs) = (the o AList.lookup (op =) descr) index
   948 							val (_, _, constrs) = (the o AList.lookup (op =) descr) index
  1645 	fun IDT_interpreter thy model args t =
  1641 	fun IDT_interpreter thy model args t =
  1646 	let
  1642 	let
  1647 		val (typs, terms) = model
  1643 		val (typs, terms) = model
  1648 		(* Term.typ -> (interpretation * model * arguments) option *)
  1644 		(* Term.typ -> (interpretation * model * arguments) option *)
  1649 		fun interpret_term (Type (s, Ts)) =
  1645 		fun interpret_term (Type (s, Ts)) =
  1650 			(case DatatypePackage.datatype_info thy s of
  1646 			(case DatatypePackage.get_datatype thy s of
  1651 			  SOME info =>  (* inductive datatype *)
  1647 			  SOME info =>  (* inductive datatype *)
  1652 				let
  1648 				let
  1653 					(* int option -- only recursive IDTs have an associated depth *)
  1649 					(* int option -- only recursive IDTs have an associated depth *)
  1654 					val depth = AList.lookup (op =) typs (Type (s, Ts))
  1650 					val depth = AList.lookup (op =) typs (Type (s, Ts))
  1655 				in
  1651 				in
  1721 		| NONE =>
  1717 		| NONE =>
  1722 			(case t of
  1718 			(case t of
  1723 			  Const (s, T) =>
  1719 			  Const (s, T) =>
  1724 				(case body_type T of
  1720 				(case body_type T of
  1725 				  Type (s', Ts') =>
  1721 				  Type (s', Ts') =>
  1726 					(case DatatypePackage.datatype_info thy s' of
  1722 					(case DatatypePackage.get_datatype thy s' of
  1727 					  SOME info =>  (* body type is an inductive datatype *)
  1723 					  SOME info =>  (* body type is an inductive datatype *)
  1728 						let
  1724 						let
  1729 							val index               = #index info
  1725 							val index               = #index info
  1730 							val descr               = #descr info
  1726 							val descr               = #descr info
  1731 							val (_, dtyps, constrs) = (the o AList.lookup (op =) descr) index
  1727 							val (_, dtyps, constrs) = (the o AList.lookup (op =) descr) index
  2509 		  | typeof (Const (_, T)) = SOME T
  2505 		  | typeof (Const (_, T)) = SOME T
  2510 		  | typeof _              = NONE
  2506 		  | typeof _              = NONE
  2511 	in
  2507 	in
  2512 		case typeof t of
  2508 		case typeof t of
  2513 		  SOME (Type (s, Ts)) =>
  2509 		  SOME (Type (s, Ts)) =>
  2514 			(case DatatypePackage.datatype_info thy s of
  2510 			(case DatatypePackage.get_datatype thy s of
  2515 			  SOME info =>  (* inductive datatype *)
  2511 			  SOME info =>  (* inductive datatype *)
  2516 				let
  2512 				let
  2517 					val (typs, _)           = model
  2513 					val (typs, _)           = model
  2518 					val index               = #index info
  2514 					val index               = #index info
  2519 					val descr               = #descr info
  2515 					val descr               = #descr info