src/HOL/Tools/Nitpick/nitpick_kodkod.ML
changeset 41996 1d7735ae4273
parent 41995 03c2d29ec790
child 41997 33b7d118e9dc
equal deleted inserted replaced
41995:03c2d29ec790 41996:1d7735ae4273
   311       val need_vals =
   311       val need_vals =
   312         AList.lookup (op =) need_vals T1 |> the_default NONE |> these
   312         AList.lookup (op =) need_vals T1 |> the_default NONE |> these
   313     in
   313     in
   314       ([(x, bound_comment ctxt debug nick T R)],
   314       ([(x, bound_comment ctxt debug nick T R)],
   315        let
   315        let
   316          val ts = KK.TupleAtomSeq (epsilon - delta, delta + j0)
       
   317          val complete_need_vals = (length need_vals = card)
   316          val complete_need_vals = (length need_vals = card)
   318          val (my_need_vals, other_need_vals) =
   317          val (my_need_vals, other_need_vals) =
   319            need_vals
   318            need_vals
   320            |> List.partition
   319            |> List.partition
   321                   (fn (Construct (sel_us, _, _, _), _) =>
   320                   (fn (Construct (sel_us, _, _, _), _) =>
   322                       exists (fn FreeRel (x', _, _, _) => x = x'
   321                       exists (fn FreeRel (x', _, _, _) => x = x'
   323                                | _ => false) sel_us
   322                                | _ => false) sel_us
   324                     | _ => false)
   323                     | _ => false)
       
   324          fun upper_bound_ts () =
       
   325            if complete_need_vals then
       
   326              my_need_vals |> map (KK.Tuple o single o snd) |> KK.TupleSet
       
   327            else if not (null other_need_vals) then
       
   328              index_seq (delta + j0) (epsilon - delta)
       
   329              |> filter_out (member (op = o apsnd snd) other_need_vals)
       
   330              |> map (KK.Tuple o single) |> KK.TupleSet
       
   331            else
       
   332              KK.TupleAtomSeq (epsilon - delta, delta + j0)
   325        in
   333        in
   326          if explicit_max = 0 orelse
   334          if explicit_max = 0 orelse
   327             (complete_need_vals andalso null my_need_vals) then
   335             (complete_need_vals andalso null my_need_vals) (* ### needed? *) then
   328            [KK.TupleSet []]
   336            [KK.TupleSet []]
   329          else
   337          else
   330            if R2 = Formula Neut then
   338            if R2 = Formula Neut then
   331              [ts] |> not exclusive ? cons (KK.TupleSet [])
   339              [upper_bound_ts ()] |> not exclusive ? cons (KK.TupleSet [])
   332            else
   340            else
   333              [KK.TupleSet [],
   341              [KK.TupleSet [],
   334               if T1 = T2 andalso epsilon > delta andalso
   342               if T1 = T2 andalso epsilon > delta andalso
   335                  is_datatype_acyclic dtype then
   343                  is_datatype_acyclic dtype then
   336                 index_seq delta (epsilon - delta)
   344                 index_seq delta (epsilon - delta)
   337                 |> map (fn j =>
   345                 |> map (fn j =>
   338                            KK.TupleProduct (KK.TupleSet [KK.Tuple [j + j0]],
   346                            KK.TupleProduct (KK.TupleSet [KK.Tuple [j + j0]],
   339                                             KK.TupleAtomSeq (j, j0)))
   347                                             KK.TupleAtomSeq (j, j0)))
   340                 |> foldl1 KK.TupleUnion
   348                 |> foldl1 KK.TupleUnion
   341               else
   349               else
   342                 KK.TupleProduct (ts, upper_bound_for_rep R2)]
   350                 KK.TupleProduct (upper_bound_ts (), upper_bound_for_rep R2)]
   343          end)
   351          end)
   344     end
   352     end
   345   | bound_for_sel_rel _ _ _ _ u =
   353   | bound_for_sel_rel _ _ _ _ u =
   346     raise NUT ("Nitpick_Kodkod.bound_for_sel_rel", [u])
   354     raise NUT ("Nitpick_Kodkod.bound_for_sel_rel", [u])
   347 
   355 
  1523                        | NONE => NONE
  1531                        | NONE => NONE
  1524                      end
  1532                      end
  1525                  else
  1533                  else
  1526                    accum)
  1534                    accum)
  1527         | aux _ = I
  1535         | aux _ = I
  1528     in SOME (index_seq 0 card, []) |> fold aux need_us |> Option.map snd end
  1536     in
       
  1537       SOME (index_seq 0 card, []) |> fold aux need_us |> Option.map (rev o snd)
       
  1538     end
  1529 
  1539 
  1530 fun needed_value_axioms_for_datatype _ _ NONE = [KK.False]
  1540 fun needed_value_axioms_for_datatype _ _ NONE = [KK.False]
  1531   | needed_value_axioms_for_datatype ofs kk (SOME fixed) =
  1541   | needed_value_axioms_for_datatype ofs kk (SOME fixed) =
  1532     fixed |> map (atom_equation_for_nut ofs kk)
  1542     fixed |> map (atom_equation_for_nut ofs kk)
  1533 
  1543