src/HOL/ex/coopereif.ML
changeset 23693 d92637b15a45
parent 23515 3e7f62e68fe4
child 23808 4e4b92e76219
equal deleted inserted replaced
23692:b784849811fc 23693:d92637b15a45
     7 
     7 
     8 structure Coopereif =
     8 structure Coopereif =
     9 struct
     9 struct
    10 
    10 
    11 open GeneratedCooper;
    11 open GeneratedCooper;
    12 open Reflected_Presburger;
       
    13 
    12 
    14 fun i_of_term vs t = case t
    13 fun i_of_term vs t = case t
    15  of Free(xn,xT) => (case AList.lookup (op aconv) vs t
    14  of Free(xn,xT) => (case AList.lookup (op aconv) vs t
    16    of NONE   => error "Variable not found in the list!"
    15    of NONE   => error "Variable not found in the list!"
    17     | SOME n => Bound n)
    16     | SOME n => Bound n)
    18     | @{term "0::int"} => C 0
    17     | @{term "0::int"} => C 0
    19     | @{term "1::int"} => C 1
    18     | @{term "1::int"} => C 1
    20     | Term.Bound i => Bound (Integer.nat i)
    19     | Term.Bound i => Bound (nat i)
    21     | Const(@{const_name "HOL.uminus"},_)$t' => Neg (i_of_term vs t')
    20     | Const(@{const_name "HOL.uminus"},_)$t' => Neg (i_of_term vs t')
    22     | Const(@{const_name "HOL.plus"},_)$t1$t2 => Add (i_of_term vs t1,i_of_term vs t2)
    21     | Const(@{const_name "HOL.plus"},_)$t1$t2 => Add (i_of_term vs t1,i_of_term vs t2)
    23     | Const(@{const_name "HOL.minus"},_)$t1$t2 => Sub (i_of_term vs t1,i_of_term vs t2)
    22     | Const(@{const_name "HOL.minus"},_)$t1$t2 => Sub (i_of_term vs t1,i_of_term vs t2)
    24     | Const(@{const_name "HOL.times"},_)$t1$t2 => (Mul (HOLogic.dest_number t1 |> snd,i_of_term vs t2)
    23     | Const(@{const_name "HOL.times"},_)$t1$t2 => (Mul (HOLogic.dest_number t1 |> snd,i_of_term vs t2)
    25         handle TERM _ => 
    24         handle TERM _ => 
    41       | Const("op |",_)$t1$t2 => Or(qf_of_term ps vs t1,qf_of_term ps vs t2)
    40       | Const("op |",_)$t1$t2 => Or(qf_of_term ps vs t1,qf_of_term ps vs t2)
    42       | Const("op -->",_)$t1$t2 => Impa(qf_of_term ps vs t1,qf_of_term ps vs t2)
    41       | Const("op -->",_)$t1$t2 => Impa(qf_of_term ps vs t1,qf_of_term ps vs t2)
    43       | Const("Not",_)$t' => Nota(qf_of_term ps vs t')
    42       | Const("Not",_)$t' => Nota(qf_of_term ps vs t')
    44       | Const("Ex",_)$Abs(xn,xT,p) => 
    43       | Const("Ex",_)$Abs(xn,xT,p) => 
    45          let val (xn',p') = variant_abs (xn,xT,p)
    44          let val (xn',p') = variant_abs (xn,xT,p)
    46              val vs' = (Free (xn',xT), Integer.nat 0) :: (map (fn(v,n) => (v,1 + n)) vs)
    45              val vs' = (Free (xn',xT), nat 0) :: (map (fn(v,n) => (v,1 + n)) vs)
    47          in E (qf_of_term ps vs' p')
    46          in E (qf_of_term ps vs' p')
    48          end
    47          end
    49       | Const("All",_)$Abs(xn,xT,p) => 
    48       | Const("All",_)$Abs(xn,xT,p) => 
    50          let val (xn',p') = variant_abs (xn,xT,p)
    49          let val (xn',p') = variant_abs (xn,xT,p)
    51              val vs' = (Free (xn',xT), Integer.nat 0) :: (map (fn(v,n) => (v,1 + n)) vs)
    50              val vs' = (Free (xn',xT), nat 0) :: (map (fn(v,n) => (v,1 + n)) vs)
    52          in A (qf_of_term ps vs' p')
    51          in A (qf_of_term ps vs' p')
    53          end
    52          end
    54       | _ =>(case AList.lookup (op aconv) ps t of 
    53       | _ =>(case AList.lookup (op aconv) ps t of 
    55                NONE => error "qf_of_term ps : unknown term!"
    54                NONE => error "qf_of_term ps : unknown term!"
    56              | SOME n => Closed n);
    55              | SOME n => Closed n);
    76 fun start_vs t =
    75 fun start_vs t =
    77   let
    76   let
    78     val fs = term_frees t
    77     val fs = term_frees t
    79     val ps = term_bools [] t
    78     val ps = term_bools [] t
    80   in
    79   in
    81     (fs ~~ (map Integer.nat (0 upto  (length fs - 1))),
    80     (fs ~~ (map nat (0 upto  (length fs - 1))),
    82       ps ~~ (map Integer.nat (0 upto  (length ps - 1))))
    81       ps ~~ (map nat (0 upto  (length ps - 1))))
    83   end;
    82   end;
    84 
    83 
    85 fun term_of_i vs t = case t
    84 fun term_of_i vs t = case t
    86  of C i => HOLogic.mk_number HOLogic.intT i
    85  of C i => HOLogic.mk_number HOLogic.intT i
    87   | Bound n => (fst o the) (find_first (fn (_, m) => m = n) vs)
    86   | Bound n => (fst o the) (find_first (fn (_, m) => m = n) vs)
    89   | Add (t1, t2) => @{term "op +:: int => _"} $ term_of_i vs t1 $ term_of_i vs t2
    88   | Add (t1, t2) => @{term "op +:: int => _"} $ term_of_i vs t1 $ term_of_i vs t2
    90   | Sub (t1, t2) => Const (@{const_name "HOL.minus"}, HOLogic.intT --> HOLogic.intT --> HOLogic.intT) $
    89   | Sub (t1, t2) => Const (@{const_name "HOL.minus"}, HOLogic.intT --> HOLogic.intT --> HOLogic.intT) $
    91       term_of_i vs t1 $ term_of_i vs t2
    90       term_of_i vs t1 $ term_of_i vs t2
    92   | Mul (i, t2) => Const (@{const_name "HOL.times"}, HOLogic.intT --> HOLogic.intT --> HOLogic.intT) $
    91   | Mul (i, t2) => Const (@{const_name "HOL.times"}, HOLogic.intT --> HOLogic.intT --> HOLogic.intT) $
    93       HOLogic.mk_number HOLogic.intT i $ term_of_i vs t2
    92       HOLogic.mk_number HOLogic.intT i $ term_of_i vs t2
    94   | Cx (i, t') => term_of_i vs (Add (Mul (i, Bound (Integer.nat 0)), t'));
    93   | Cx (i, t') => term_of_i vs (Add (Mul (i, Bound (nat 0)), t'));
    95 
    94 
    96 fun term_of_qf ps vs t = case t
    95 fun term_of_qf ps vs t = case t
    97  of T => HOLogic.true_const 
    96  of T => HOLogic.true_const 
    98   | F => HOLogic.false_const
    97   | F => HOLogic.false_const
    99   | Lt t' => @{term "op < :: int => _ "}$ term_of_i vs t'$ @{term "0::int"}
    98   | Lt t' => @{term "op < :: int => _ "}$ term_of_i vs t'$ @{term "0::int"}