src/HOL/Tools/Nitpick/nitpick_preproc.ML
changeset 38795 848be46708dc
parent 38786 e46e7a9cb622
child 38864 4abe644fcea5
equal deleted inserted replaced
38794:2d638e963357 38795:848be46708dc
   209         do_quantifier new_Ts old_Ts polar s0 T0 s1 T1 t1
   209         do_quantifier new_Ts old_Ts polar s0 T0 s1 T1 t1
   210       | Const (s0 as @{const_name Ex}, T0) $ Abs (s1, T1, t1) =>
   210       | Const (s0 as @{const_name Ex}, T0) $ Abs (s1, T1, t1) =>
   211         do_quantifier new_Ts old_Ts polar s0 T0 s1 T1 t1
   211         do_quantifier new_Ts old_Ts polar s0 T0 s1 T1 t1
   212       | Const (s0 as @{const_name "op ="}, T0) $ t1 $ t2 =>
   212       | Const (s0 as @{const_name "op ="}, T0) $ t1 $ t2 =>
   213         do_equals new_Ts old_Ts s0 T0 t1 t2
   213         do_equals new_Ts old_Ts s0 T0 t1 t2
   214       | @{const "op &"} $ t1 $ t2 =>
   214       | @{const HOL.conj} $ t1 $ t2 =>
   215         @{const "op &"} $ do_term new_Ts old_Ts polar t1
   215         @{const HOL.conj} $ do_term new_Ts old_Ts polar t1
   216         $ do_term new_Ts old_Ts polar t2
   216         $ do_term new_Ts old_Ts polar t2
   217       | @{const "op |"} $ t1 $ t2 =>
   217       | @{const HOL.disj} $ t1 $ t2 =>
   218         @{const "op |"} $ do_term new_Ts old_Ts polar t1
   218         @{const HOL.disj} $ do_term new_Ts old_Ts polar t1
   219         $ do_term new_Ts old_Ts polar t2
   219         $ do_term new_Ts old_Ts polar t2
   220       | @{const HOL.implies} $ t1 $ t2 =>
   220       | @{const HOL.implies} $ t1 $ t2 =>
   221         @{const HOL.implies} $ do_term new_Ts old_Ts (flip_polarity polar) t1
   221         @{const HOL.implies} $ do_term new_Ts old_Ts (flip_polarity polar) t1
   222         $ do_term new_Ts old_Ts polar t2
   222         $ do_term new_Ts old_Ts polar t2
   223       | Const (x as (s, T)) =>
   223       | Const (x as (s, T)) =>
   447   in aux axiom t end
   447   in aux axiom t end
   448 
   448 
   449 (** Destruction of universal and existential equalities **)
   449 (** Destruction of universal and existential equalities **)
   450 
   450 
   451 fun curry_assms (@{const "==>"} $ (@{const Trueprop}
   451 fun curry_assms (@{const "==>"} $ (@{const Trueprop}
   452                                    $ (@{const "op &"} $ t1 $ t2)) $ t3) =
   452                                    $ (@{const HOL.conj} $ t1 $ t2)) $ t3) =
   453     curry_assms (Logic.list_implies ([t1, t2] |> map HOLogic.mk_Trueprop, t3))
   453     curry_assms (Logic.list_implies ([t1, t2] |> map HOLogic.mk_Trueprop, t3))
   454   | curry_assms (@{const "==>"} $ t1 $ t2) =
   454   | curry_assms (@{const "==>"} $ t1 $ t2) =
   455     @{const "==>"} $ curry_assms t1 $ curry_assms t2
   455     @{const "==>"} $ curry_assms t1 $ curry_assms t2
   456   | curry_assms t = t
   456   | curry_assms t = t
   457 
   457 
   602           @{const Not} $ aux ss Ts js skolemizable (flip_polarity polar) t1
   602           @{const Not} $ aux ss Ts js skolemizable (flip_polarity polar) t1
   603         | Const (s0 as @{const_name All}, T0) $ Abs (s1, T1, t1) =>
   603         | Const (s0 as @{const_name All}, T0) $ Abs (s1, T1, t1) =>
   604           do_quantifier s0 T0 s1 T1 t1
   604           do_quantifier s0 T0 s1 T1 t1
   605         | Const (s0 as @{const_name Ex}, T0) $ Abs (s1, T1, t1) =>
   605         | Const (s0 as @{const_name Ex}, T0) $ Abs (s1, T1, t1) =>
   606           do_quantifier s0 T0 s1 T1 t1
   606           do_quantifier s0 T0 s1 T1 t1
   607         | @{const "op &"} $ t1 $ t2 =>
   607         | @{const HOL.conj} $ t1 $ t2 =>
   608           s_conj (pairself (aux ss Ts js skolemizable polar) (t1, t2))
   608           s_conj (pairself (aux ss Ts js skolemizable polar) (t1, t2))
   609         | @{const "op |"} $ t1 $ t2 =>
   609         | @{const HOL.disj} $ t1 $ t2 =>
   610           s_disj (pairself (aux ss Ts js skolemizable polar) (t1, t2))
   610           s_disj (pairself (aux ss Ts js skolemizable polar) (t1, t2))
   611         | @{const HOL.implies} $ t1 $ t2 =>
   611         | @{const HOL.implies} $ t1 $ t2 =>
   612           @{const HOL.implies} $ aux ss Ts js skolemizable (flip_polarity polar) t1
   612           @{const HOL.implies} $ aux ss Ts js skolemizable (flip_polarity polar) t1
   613           $ aux ss Ts js skolemizable polar t2
   613           $ aux ss Ts js skolemizable polar t2
   614         | (t0 as Const (@{const_name Let}, _)) $ t1 $ t2 =>
   614         | (t0 as Const (@{const_name Let}, _)) $ t1 $ t2 =>
   618              not (is_real_equational_fun hol_ctxt x) andalso
   618              not (is_real_equational_fun hol_ctxt x) andalso
   619              not (is_well_founded_inductive_pred hol_ctxt x) then
   619              not (is_well_founded_inductive_pred hol_ctxt x) then
   620             let
   620             let
   621               val gfp = (fixpoint_kind_of_const thy def_table x = Gfp)
   621               val gfp = (fixpoint_kind_of_const thy def_table x = Gfp)
   622               val (pref, connective) =
   622               val (pref, connective) =
   623                 if gfp then (lbfp_prefix, @{const "op |"})
   623                 if gfp then (lbfp_prefix, @{const HOL.disj})
   624                 else (ubfp_prefix, @{const "op &"})
   624                 else (ubfp_prefix, @{const HOL.conj})
   625               fun pos () = unrolled_inductive_pred_const hol_ctxt gfp x
   625               fun pos () = unrolled_inductive_pred_const hol_ctxt gfp x
   626                            |> aux ss Ts js skolemizable polar
   626                            |> aux ss Ts js skolemizable polar
   627               fun neg () = Const (pref ^ s, T)
   627               fun neg () = Const (pref ^ s, T)
   628             in
   628             in
   629               case polar |> gfp ? flip_polarity of
   629               case polar |> gfp ? flip_polarity of
  1103 
  1103 
  1104 fun distribute_quantifiers t =
  1104 fun distribute_quantifiers t =
  1105   case t of
  1105   case t of
  1106     (t0 as Const (@{const_name All}, T0)) $ Abs (s, T1, t1) =>
  1106     (t0 as Const (@{const_name All}, T0)) $ Abs (s, T1, t1) =>
  1107     (case t1 of
  1107     (case t1 of
  1108        (t10 as @{const "op &"}) $ t11 $ t12 =>
  1108        (t10 as @{const HOL.conj}) $ t11 $ t12 =>
  1109        t10 $ distribute_quantifiers (t0 $ Abs (s, T1, t11))
  1109        t10 $ distribute_quantifiers (t0 $ Abs (s, T1, t11))
  1110            $ distribute_quantifiers (t0 $ Abs (s, T1, t12))
  1110            $ distribute_quantifiers (t0 $ Abs (s, T1, t12))
  1111      | (t10 as @{const Not}) $ t11 =>
  1111      | (t10 as @{const Not}) $ t11 =>
  1112        t10 $ distribute_quantifiers (Const (@{const_name Ex}, T0)
  1112        t10 $ distribute_quantifiers (Const (@{const_name Ex}, T0)
  1113                                      $ Abs (s, T1, t11))
  1113                                      $ Abs (s, T1, t11))
  1116          distribute_quantifiers (incr_boundvars ~1 t1)
  1116          distribute_quantifiers (incr_boundvars ~1 t1)
  1117        else
  1117        else
  1118          t0 $ Abs (s, T1, distribute_quantifiers t1))
  1118          t0 $ Abs (s, T1, distribute_quantifiers t1))
  1119   | (t0 as Const (@{const_name Ex}, T0)) $ Abs (s, T1, t1) =>
  1119   | (t0 as Const (@{const_name Ex}, T0)) $ Abs (s, T1, t1) =>
  1120     (case distribute_quantifiers t1 of
  1120     (case distribute_quantifiers t1 of
  1121        (t10 as @{const "op |"}) $ t11 $ t12 =>
  1121        (t10 as @{const HOL.disj}) $ t11 $ t12 =>
  1122        t10 $ distribute_quantifiers (t0 $ Abs (s, T1, t11))
  1122        t10 $ distribute_quantifiers (t0 $ Abs (s, T1, t11))
  1123            $ distribute_quantifiers (t0 $ Abs (s, T1, t12))
  1123            $ distribute_quantifiers (t0 $ Abs (s, T1, t12))
  1124      | (t10 as @{const HOL.implies}) $ t11 $ t12 =>
  1124      | (t10 as @{const HOL.implies}) $ t11 $ t12 =>
  1125        t10 $ distribute_quantifiers (Const (@{const_name All}, T0)
  1125        t10 $ distribute_quantifiers (Const (@{const_name All}, T0)
  1126                                      $ Abs (s, T1, t11))
  1126                                      $ Abs (s, T1, t11))