src/HOL/Tools/refute.ML
changeset 42364 8c674b3b8e44
parent 42361 23f352990944
child 42680 b6c27cf04fe9
equal deleted inserted replaced
42363:e52e3f697510 42364:8c674b3b8e44
  1626     | NONE =>
  1626     | NONE =>
  1627         (case t of
  1627         (case t of
  1628           Const (_, T) => interpret_groundterm T
  1628           Const (_, T) => interpret_groundterm T
  1629         | Free (_, T) => interpret_groundterm T
  1629         | Free (_, T) => interpret_groundterm T
  1630         | Var (_, T) => interpret_groundterm T
  1630         | Var (_, T) => interpret_groundterm T
  1631         | Bound i => SOME (List.nth (#bounds args, i), model, args)
  1631         | Bound i => SOME (nth (#bounds args) i, model, args)
  1632         | Abs (x, T, body) =>
  1632         | Abs (x, T, body) =>
  1633             let
  1633             let
  1634               (* create all constants of type 'T' *)
  1634               (* create all constants of type 'T' *)
  1635               val constants = make_constants ctxt model T
  1635               val constants = make_constants ctxt model T
  1636               (* interpret the 'body' separately for each constant *)
  1636               (* interpret the 'body' separately for each constant *)
  2269                           raise REFUTE ("IDT_recursion_interpreter",
  2269                           raise REFUTE ("IDT_recursion_interpreter",
  2270                             "datatype argument is not a variable")
  2270                             "datatype argument is not a variable")
  2271                         else ()
  2271                         else ()
  2272                       (* the type of a recursion operator is *)
  2272                       (* the type of a recursion operator is *)
  2273                       (* [T1, ..., Tn, IDT] ---> Tresult     *)
  2273                       (* [T1, ..., Tn, IDT] ---> Tresult     *)
  2274                       val IDT = List.nth (binder_types T, mconstrs_count)
  2274                       val IDT = nth (binder_types T) mconstrs_count
  2275                       (* by our assumption on the order of recursion operators *)
  2275                       (* by our assumption on the order of recursion operators *)
  2276                       (* and datatypes, this is the index of the datatype      *)
  2276                       (* and datatypes, this is the index of the datatype      *)
  2277                       (* corresponding to the given recursion operator         *)
  2277                       (* corresponding to the given recursion operator         *)
  2278                       val idt_index = find_index (fn s' => s' = s) (#rec_names info)
  2278                       val idt_index = find_index (fn s' => s' = s) (#rec_names info)
  2279                       (* mutually recursive types must have the same type   *)
  2279                       (* mutually recursive types must have the same type   *)
  2461                               (* int * int list *)
  2461                               (* int * int list *)
  2462                               val (c, args) = get_cargs idx elem
  2462                               val (c, args) = get_cargs idx elem
  2463                               (* find the indices of the constructor's /recursive/ *)
  2463                               (* find the indices of the constructor's /recursive/ *)
  2464                               (* arguments                                         *)
  2464                               (* arguments                                         *)
  2465                               val (_, _, constrs) = the (AList.lookup (op =) descr idx)
  2465                               val (_, _, constrs) = the (AList.lookup (op =) descr idx)
  2466                               val (_, dtyps)      = List.nth (constrs, c)
  2466                               val (_, dtyps) = nth constrs c
  2467                               val rec_dtyps_args  = filter
  2467                               val rec_dtyps_args = filter
  2468                                 (Datatype_Aux.is_rec_type o fst) (dtyps ~~ args)
  2468                                 (Datatype_Aux.is_rec_type o fst) (dtyps ~~ args)
  2469                               (* map those indices to interpretations *)
  2469                               (* map those indices to interpretations *)
  2470                               val rec_dtyps_intrs = map (fn (dtyp, arg) =>
  2470                               val rec_dtyps_intrs = map (fn (dtyp, arg) =>
  2471                                 let
  2471                                 let
  2472                                   val dT     = typ_of_dtyp descr typ_assoc dtyp
  2472                                   val dT = typ_of_dtyp descr typ_assoc dtyp
  2473                                   val consts = make_constants ctxt (typs, []) dT
  2473                                   val consts = make_constants ctxt (typs, []) dT
  2474                                   val arg_i  = List.nth (consts, arg)
  2474                                   val arg_i = nth consts arg
  2475                                 in
  2475                                 in
  2476                                   (dtyp, arg_i)
  2476                                   (dtyp, arg_i)
  2477                                 end) rec_dtyps_args
  2477                                 end) rec_dtyps_args
  2478                               (* takes the dtyp and interpretation of an element, *)
  2478                               (* takes the dtyp and interpretation of an element, *)
  2479                               (* and computes the interpretation for the          *)
  2479                               (* and computes the interpretation for the          *)
  3102                       (* we only need the n-th element of this list, so there   *)
  3102                       (* we only need the n-th element of this list, so there   *)
  3103                       (* might be a more efficient implementation that does not *)
  3103                       (* might be a more efficient implementation that does not *)
  3104                       (* generate all constants                                 *)
  3104                       (* generate all constants                                 *)
  3105                       val consts = make_constants ctxt (typs, []) dT
  3105                       val consts = make_constants ctxt (typs, []) dT
  3106                     in
  3106                     in
  3107                       print ctxt (typs, []) dT (List.nth (consts, n)) assignment
  3107                       print ctxt (typs, []) dT (nth consts n) assignment
  3108                     end) (cargs ~~ args)
  3108                     end) (cargs ~~ args)
  3109                 in
  3109                 in
  3110                   SOME (list_comb (cTerm, argsTerms))
  3110                   SOME (list_comb (cTerm, argsTerms))
  3111                 end
  3111                 end
  3112             end
  3112             end