src/HOL/Tools/Presburger/cooper_dec.ML
changeset 16389 48832eba5b1e
parent 16299 872ad146bb14
child 16398 7f0faa30f602
equal deleted inserted replaced
16388:1ff571813848 16389:48832eba5b1e
    10 signature COOPER_DEC = 
    10 signature COOPER_DEC = 
    11 sig
    11 sig
    12   exception COOPER
    12   exception COOPER
    13   exception COOPER_ORACLE of term
    13   exception COOPER_ORACLE of term
    14   val is_arith_rel : term -> bool
    14   val is_arith_rel : term -> bool
    15   val mk_numeral : int -> term
    15   val mk_numeral : IntInf.int -> term
    16   val dest_numeral : term -> int
    16   val dest_numeral : term -> IntInf.int
    17   val is_numeral : term -> bool
    17   val is_numeral : term -> bool
    18   val zero : term
    18   val zero : term
    19   val one : term
    19   val one : term
    20   val linear_cmul : int -> term -> term
    20   val linear_cmul : IntInf.int -> term -> term
    21   val linear_add : string list -> term -> term -> term 
    21   val linear_add : string list -> term -> term -> term 
    22   val linear_sub : string list -> term -> term -> term 
    22   val linear_sub : string list -> term -> term -> term 
    23   val linear_neg : term -> term
    23   val linear_neg : term -> term
    24   val lint : string list -> term -> term
    24   val lint : string list -> term -> term
    25   val linform : string list -> term -> term
    25   val linform : string list -> term -> term
    26   val formlcm : term -> term -> int
    26   val formlcm : term -> term -> IntInf.int
    27   val adjustcoeff : term -> int -> term -> term
    27   val adjustcoeff : term -> IntInf.int -> term -> term
    28   val unitycoeff : term -> term -> term
    28   val unitycoeff : term -> term -> term
    29   val divlcm : term -> term -> int
    29   val divlcm : term -> term -> IntInf.int
    30   val bset : term -> term -> term list
    30   val bset : term -> term -> term list
    31   val aset : term -> term -> term list
    31   val aset : term -> term -> term list
    32   val linrep : string list -> term -> term -> term -> term
    32   val linrep : string list -> term -> term -> term -> term
    33   val list_disj : term list -> term
    33   val list_disj : term list -> term
    34   val list_conj : term list -> term
    34   val list_conj : term list -> term
    35   val simpl : term -> term
    35   val simpl : term -> term
    36   val fv : term -> string list
    36   val fv : term -> string list
    37   val negate : term -> term
    37   val negate : term -> term
    38   val operations : (string * (int * int -> bool)) list
    38   val operations : (string * (IntInf.int * IntInf.int -> bool)) list
    39   val conjuncts : term -> term list
    39   val conjuncts : term -> term list
    40   val disjuncts : term -> term list
    40   val disjuncts : term -> term list
    41   val has_bound : term -> bool
    41   val has_bound : term -> bool
    42   val minusinf : term -> term -> term
    42   val minusinf : term -> term -> term
    43   val plusinf : term -> term -> term
    43   val plusinf : term -> term -> term
    63 (* ------------------------------------------------------------------------- *) 
    63 (* ------------------------------------------------------------------------- *) 
    64 (* Lift operations up to numerals.                                           *) 
    64 (* Lift operations up to numerals.                                           *) 
    65 (* ------------------------------------------------------------------------- *) 
    65 (* ------------------------------------------------------------------------- *) 
    66  
    66  
    67 (*Assumption : The construction of atomar formulas in linearl arithmetic is based on 
    67 (*Assumption : The construction of atomar formulas in linearl arithmetic is based on 
    68 relation operations of Type : [int,int]---> bool *) 
    68 relation operations of Type : [IntInf.int,IntInf.int]---> bool *) 
    69  
    69  
    70 (* ------------------------------------------------------------------------- *) 
    70 (* ------------------------------------------------------------------------- *) 
    71  
    71  
    72 (*Function is_arith_rel returns true if and only if the term is an atomar presburger 
    72 (*Function is_arith_rel returns true if and only if the term is an atomar presburger 
    73 formula *) 
    73 formula *) 
    83  
    83  
    84 (*Transform a natural number to a term*) 
    84 (*Transform a natural number to a term*) 
    85  
    85  
    86 fun mk_numeral 0 = Const("0",HOLogic.intT)
    86 fun mk_numeral 0 = Const("0",HOLogic.intT)
    87    |mk_numeral 1 = Const("1",HOLogic.intT)
    87    |mk_numeral 1 = Const("1",HOLogic.intT)
    88    |mk_numeral n = (HOLogic.number_of_const HOLogic.intT) $ (HOLogic.mk_bin (IntInf.fromInt n)); 
    88    |mk_numeral n = (HOLogic.number_of_const HOLogic.intT) $ (HOLogic.mk_bin n); 
    89  
    89  
    90 (*Transform an Term to an natural number*)	  
    90 (*Transform an Term to an natural number*)	  
    91 	  
    91 	  
    92 fun dest_numeral (Const("0",Type ("IntDef.int", []))) = 0
    92 fun dest_numeral (Const("0",Type ("IntDef.int", []))) = 0
    93    |dest_numeral (Const("1",Type ("IntDef.int", []))) = 1
    93    |dest_numeral (Const("1",Type ("IntDef.int", []))) = 1
    94    |dest_numeral (Const ("Numeral.number_of",_) $ n) = 
    94    |dest_numeral (Const ("Numeral.number_of",_) $ n) = 
    95        IntInf.toInt (HOLogic.dest_binum n);
    95        HOLogic.dest_binum n;
    96 (*Some terms often used for pattern matching*) 
    96 (*Some terms often used for pattern matching*) 
    97  
    97  
    98 val zero = mk_numeral 0; 
    98 val zero = mk_numeral 0; 
    99 val one = mk_numeral 1; 
    99 val one = mk_numeral 1; 
   100  
   100  
   114 (* Operations on canonical linear terms c1 * x1 + ... + cn * xn + k          *) 
   114 (* Operations on canonical linear terms c1 * x1 + ... + cn * xn + k          *) 
   115 (*                                                                           *) 
   115 (*                                                                           *) 
   116 (* Note that we're quite strict: the ci must be present even if 1            *) 
   116 (* Note that we're quite strict: the ci must be present even if 1            *) 
   117 (* (but if 0 we expect the monomial to be omitted) and k must be there       *) 
   117 (* (but if 0 we expect the monomial to be omitted) and k must be there       *) 
   118 (* even if it's zero. Thus, it's a constant iff not an addition term.        *) 
   118 (* even if it's zero. Thus, it's a constant iff not an addition term.        *) 
   119 (* ------------------------------------------------------------------------- *) 
   119 (* ------------------------------------------------------------------------- *)  
   120  
   120  
   121  
   121  
   122 fun linear_cmul n tm =  if n = 0 then zero else let fun times n k = n*k in  
   122 fun linear_cmul n tm =  if n = 0 then zero else let fun times n k = n*k in  
   123   ( case tm of  
   123   ( case tm of  
   124      (Const("op +",T)  $  (Const ("op *",T1 ) $c1 $  x1) $ rest) => 
   124      (Const("op +",T)  $  (Const ("op *",T1 ) $c1 $  x1) $ rest) =>