src/HOL/Tools/Nitpick/nitpick_preproc.ML
changeset 38864 4abe644fcea5
parent 38795 848be46708dc
child 39345 062c10ff848c
equal deleted inserted replaced
38859:053c69cb4a0e 38864:4abe644fcea5
    39 val may_use_binary_ints =
    39 val may_use_binary_ints =
    40   let
    40   let
    41     fun aux def (Const (@{const_name "=="}, _) $ t1 $ t2) =
    41     fun aux def (Const (@{const_name "=="}, _) $ t1 $ t2) =
    42         aux def t1 andalso aux false t2
    42         aux def t1 andalso aux false t2
    43       | aux def (@{const "==>"} $ t1 $ t2) = aux false t1 andalso aux def t2
    43       | aux def (@{const "==>"} $ t1 $ t2) = aux false t1 andalso aux def t2
    44       | aux def (Const (@{const_name "op ="}, _) $ t1 $ t2) =
    44       | aux def (Const (@{const_name HOL.eq}, _) $ t1 $ t2) =
    45         aux def t1 andalso aux false t2
    45         aux def t1 andalso aux false t2
    46       | aux def (@{const HOL.implies} $ t1 $ t2) = aux false t1 andalso aux def t2
    46       | aux def (@{const HOL.implies} $ t1 $ t2) = aux false t1 andalso aux def t2
    47       | aux def (t1 $ t2) = aux def t1 andalso aux def t2
    47       | aux def (t1 $ t2) = aux def t1 andalso aux def t2
    48       | aux def (t as Const (s, _)) =
    48       | aux def (t as Const (s, _)) =
    49         (not def orelse t <> @{const Suc}) andalso
    49         (not def orelse t <> @{const Suc}) andalso
   147       | _ => exists_subterm (curry (op =) (Var z)) t' ? insert (op =) T
   147       | _ => exists_subterm (curry (op =) (Var z)) t' ? insert (op =) T
   148     fun box_var_in_def new_Ts old_Ts t (z as (_, T)) =
   148     fun box_var_in_def new_Ts old_Ts t (z as (_, T)) =
   149       case t of
   149       case t of
   150         @{const Trueprop} $ t1 => box_var_in_def new_Ts old_Ts t1 z
   150         @{const Trueprop} $ t1 => box_var_in_def new_Ts old_Ts t1 z
   151       | Const (s0, _) $ t1 $ _ =>
   151       | Const (s0, _) $ t1 $ _ =>
   152         if s0 = @{const_name "=="} orelse s0 = @{const_name "op ="} then
   152         if s0 = @{const_name "=="} orelse s0 = @{const_name HOL.eq} then
   153           let
   153           let
   154             val (t', args) = strip_comb t1
   154             val (t', args) = strip_comb t1
   155             val T' = fastype_of1 (new_Ts, do_term new_Ts old_Ts Neut t')
   155             val T' = fastype_of1 (new_Ts, do_term new_Ts old_Ts Neut t')
   156           in
   156           in
   157             case fold (add_boxed_types_for_var z)
   157             case fold (add_boxed_types_for_var z)
   207         @{const Not} $ do_term new_Ts old_Ts (flip_polarity polar) t1
   207         @{const Not} $ do_term new_Ts old_Ts (flip_polarity polar) t1
   208       | Const (s0 as @{const_name All}, T0) $ Abs (s1, T1, t1) =>
   208       | Const (s0 as @{const_name All}, T0) $ Abs (s1, T1, t1) =>
   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 HOL.eq}, 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 HOL.conj} $ t1 $ t2 =>
   214       | @{const HOL.conj} $ t1 $ t2 =>
   215         @{const HOL.conj} $ 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 HOL.disj} $ t1 $ t2 =>
   217       | @{const HOL.disj} $ t1 $ t2 =>
   330       case t of
   330       case t of
   331         (t0 as Const (@{const_name "=="}, _)) $ t1 $ t2 =>
   331         (t0 as Const (@{const_name "=="}, _)) $ t1 $ t2 =>
   332         do_eq_or_imp Ts true def t0 t1 t2 seen
   332         do_eq_or_imp Ts true def t0 t1 t2 seen
   333       | (t0 as @{const "==>"}) $ t1 $ t2 =>
   333       | (t0 as @{const "==>"}) $ t1 $ t2 =>
   334         if def then (t, []) else do_eq_or_imp Ts false def t0 t1 t2 seen
   334         if def then (t, []) else do_eq_or_imp Ts false def t0 t1 t2 seen
   335       | (t0 as Const (@{const_name "op ="}, _)) $ t1 $ t2 =>
   335       | (t0 as Const (@{const_name HOL.eq}, _)) $ t1 $ t2 =>
   336         do_eq_or_imp Ts true def t0 t1 t2 seen
   336         do_eq_or_imp Ts true def t0 t1 t2 seen
   337       | (t0 as @{const HOL.implies}) $ t1 $ t2 =>
   337       | (t0 as @{const HOL.implies}) $ t1 $ t2 =>
   338         do_eq_or_imp Ts false def t0 t1 t2 seen
   338         do_eq_or_imp Ts false def t0 t1 t2 seen
   339       | Abs (s, T, t') =>
   339       | Abs (s, T, t') =>
   340         let val (t', seen) = do_term (T :: Ts) def t' [] seen in
   340         let val (t', seen) = do_term (T :: Ts) def t' [] seen in
   397                     | _ => I) t (K 0)
   397                     | _ => I) t (K 0)
   398     fun aux careful ((t0 as Const (@{const_name "=="}, _)) $ t1 $ t2) =
   398     fun aux careful ((t0 as Const (@{const_name "=="}, _)) $ t1 $ t2) =
   399         aux_eq careful true t0 t1 t2
   399         aux_eq careful true t0 t1 t2
   400       | aux careful ((t0 as @{const "==>"}) $ t1 $ t2) =
   400       | aux careful ((t0 as @{const "==>"}) $ t1 $ t2) =
   401         t0 $ aux false t1 $ aux careful t2
   401         t0 $ aux false t1 $ aux careful t2
   402       | aux careful ((t0 as Const (@{const_name "op ="}, _)) $ t1 $ t2) =
   402       | aux careful ((t0 as Const (@{const_name HOL.eq}, _)) $ t1 $ t2) =
   403         aux_eq careful true t0 t1 t2
   403         aux_eq careful true t0 t1 t2
   404       | aux careful ((t0 as @{const HOL.implies}) $ t1 $ t2) =
   404       | aux careful ((t0 as @{const HOL.implies}) $ t1 $ t2) =
   405         t0 $ aux false t1 $ aux careful t2
   405         t0 $ aux false t1 $ aux careful t2
   406       | aux careful (Abs (s, T, t')) = Abs (s, T, aux careful t')
   406       | aux careful (Abs (s, T, t')) = Abs (s, T, aux careful t')
   407       | aux careful (t1 $ t2) = aux careful t1 $ aux careful t2
   407       | aux careful (t1 $ t2) = aux careful t1 $ aux careful t2
   462         @{const "==>"} $ t1 $ t2 => aux_implies prems zs t1 t2
   462         @{const "==>"} $ t1 $ t2 => aux_implies prems zs t1 t2
   463       | _ => Logic.list_implies (rev prems, t)
   463       | _ => Logic.list_implies (rev prems, t)
   464     and aux_implies prems zs t1 t2 =
   464     and aux_implies prems zs t1 t2 =
   465       case t1 of
   465       case t1 of
   466         Const (@{const_name "=="}, _) $ Var z $ t' => aux_eq prems zs z t' t1 t2
   466         Const (@{const_name "=="}, _) $ Var z $ t' => aux_eq prems zs z t' t1 t2
   467       | @{const Trueprop} $ (Const (@{const_name "op ="}, _) $ Var z $ t') =>
   467       | @{const Trueprop} $ (Const (@{const_name HOL.eq}, _) $ Var z $ t') =>
   468         aux_eq prems zs z t' t1 t2
   468         aux_eq prems zs z t' t1 t2
   469       | @{const Trueprop} $ (Const (@{const_name "op ="}, _) $ t' $ Var z) =>
   469       | @{const Trueprop} $ (Const (@{const_name HOL.eq}, _) $ t' $ Var z) =>
   470         aux_eq prems zs z t' t1 t2
   470         aux_eq prems zs z t' t1 t2
   471       | _ => aux (t1 :: prems) (Term.add_vars t1 zs) t2
   471       | _ => aux (t1 :: prems) (Term.add_vars t1 zs) t2
   472     and aux_eq prems zs z t' t1 t2 =
   472     and aux_eq prems zs z t' t1 t2 =
   473       if not (member (op =) zs z) andalso
   473       if not (member (op =) zs z) andalso
   474          not (exists_subterm (curry (op =) (Var z)) t') then
   474          not (exists_subterm (curry (op =) (Var z)) t') then
   497                  raise SAME ()
   497                  raise SAME ()
   498              | _ => raise SAME ())
   498              | _ => raise SAME ())
   499             handle SAME () => do_term (t :: seen) ts
   499             handle SAME () => do_term (t :: seen) ts
   500         in
   500         in
   501           case t of
   501           case t of
   502             Const (@{const_name "op ="}, _) $ t1 $ t2 => do_eq true t1 t2
   502             Const (@{const_name HOL.eq}, _) $ t1 $ t2 => do_eq true t1 t2
   503           | _ => do_term (t :: seen) ts
   503           | _ => do_term (t :: seen) ts
   504         end
   504         end
   505   in do_term end
   505   in do_term end
   506 
   506 
   507 fun subst_one_bound j arg t =
   507 fun subst_one_bound j arg t =
   651 
   651 
   652 (** Function specialization **)
   652 (** Function specialization **)
   653 
   653 
   654 fun params_in_equation (@{const "==>"} $ _ $ t2) = params_in_equation t2
   654 fun params_in_equation (@{const "==>"} $ _ $ t2) = params_in_equation t2
   655   | params_in_equation (@{const Trueprop} $ t1) = params_in_equation t1
   655   | params_in_equation (@{const Trueprop} $ t1) = params_in_equation t1
   656   | params_in_equation (Const (@{const_name "op ="}, _) $ t1 $ _) =
   656   | params_in_equation (Const (@{const_name HOL.eq}, _) $ t1 $ _) =
   657     snd (strip_comb t1)
   657     snd (strip_comb t1)
   658   | params_in_equation _ = []
   658   | params_in_equation _ = []
   659 
   659 
   660 fun specialize_fun_axiom x x' fixed_js fixed_args extra_args t =
   660 fun specialize_fun_axiom x x' fixed_js fixed_args extra_args t =
   661   let
   661   let