arith_theorem_producer.h

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  * \file arith_theorem_producer.h
00004  * \brief TRUSTED implementation of arithmetic proof rules
00005  * 
00006  * Author: Vijay Ganesh, Sergey Berezin
00007  * 
00008  * Created: Dec 13 02:09:04 GMT 2002
00009  *
00010  * <hr>
00011  * Copyright (C) 2003 by the Board of Trustees of Leland Stanford
00012  * Junior University and by New York University. 
00013  *
00014  * License to use, copy, modify, sell and/or distribute this software
00015  * and its documentation for any purpose is hereby granted without
00016  * royalty, subject to the terms and conditions defined in the \ref
00017  * LICENSE file provided with this distribution.  In particular:
00018  *
00019  * - The above copyright notice and this permission notice must appear
00020  * in all copies of the software and related documentation.
00021  *
00022  * - THE SOFTWARE IS PROVIDED "AS-IS", WITHOUT ANY WARRANTIES,
00023  * EXPRESSED OR IMPLIED.  USE IT AT YOUR OWN RISK.
00024  * 
00025  * <hr>
00026  * 
00027  */
00028 /*****************************************************************************/
00029 
00030 #ifndef _CVC_lite__arith_theorem_producer_h_
00031 #define _CVC_lite__arith_theorem_producer_h_
00032 
00033 #include "arith_proof_rules.h"
00034 #include "theorem_producer.h"
00035 #include "theory_arith.h"
00036 
00037 namespace CVCL {
00038   class TheoryArith;
00039   
00040   class ArithTheoremProducer: public ArithProofRules, public TheoremProducer {
00041     TheoryArith* d_theoryArith;
00042   private:
00043     /*! \name Auxiliary functions for eqElimIntRule()
00044      * Methods that compute the subterms used in eqElimIntRule()
00045      *@{
00046      */
00047     //! Compute the special modulus: i - m*floor(i/m+1/2)
00048     Rational modEq(const Rational& i, const Rational& m);
00049     //! Create the term 't'.  See eqElimIntRule().
00050     Expr create_t(const Expr& eqn);
00051     //! Create the term 't2'.  See eqElimIntRule().
00052     Expr create_t2(const Expr& lhs, const Expr& rhs, const Expr& t);
00053     //! Create the term 't3'.  See eqElimIntRule().
00054     Expr create_t3(const Expr& lhs, const Expr& rhs, const Expr& t);
00055     /*! @brief Takes sum = a_0 + a_1*x_1+...+a_n*x_n and returns the
00056      * vector of similar monomials (in 'summands') with coefficients
00057      * mod(a_i, m).  If divide flag is true, the coefficients will be
00058      * mod(a_i,m)/m.
00059      */
00060     void sumModM(std::vector<Expr>& summands, const Expr& sum,
00061                  const Rational& m, const Rational& divisor);
00062     Expr monomialModM(const Expr& e,
00063                       const Rational& m, const Rational& divisor);
00064     void sumMulF(std::vector<Expr>& summands, const Expr& sum,
00065                  const Rational& m, const Rational& divisor);
00066     Expr monomialMulF(const Expr& e,
00067                       const Rational& m, const Rational& divisor);
00068     //! Compute floor(i/m+1/2) + mod(i,m)
00069     Rational f(const Rational& i, const Rational& m);
00070     Expr substitute(const Expr& term, ExprMap<Expr>& eMap);
00071     /*@}*/
00072   public:
00073     //! Constructor
00074     ArithTheoremProducer(TheoremManager* tm, TheoryArith* theoryArith):
00075       TheoremProducer(tm), d_theoryArith(theoryArith) { }
00076 
00077     //! Create Expr from Rational (for convenience)
00078     Expr rat(Rational r) { return d_em->newRatExpr(r); }
00079     Type realType() { return d_theoryArith->realType(); }
00080     Type intType() { return d_theoryArith->intType(); }
00081     //! Construct the dark shadow expression representing lhs <= rhs
00082     Expr darkShadow(const Expr& lhs, const Expr& rhs) {
00083       return d_theoryArith->darkShadow(lhs, rhs);
00084     }
00085     //! Construct the gray shadow expression representing c1 <= v - e <= c2
00086     /*! Alternatively, v = e + i for some i s.t. c1 <= i <= c2
00087      */
00088     Expr grayShadow(const Expr& v, const Expr& e,
00089                     const Rational& c1, const Rational& c2) {
00090       return d_theoryArith->grayShadow(v, e, c1, c2);
00091     }
00092 
00093     ////////////////////////////////////////////////////////////////////
00094     // Canonization rules
00095     ////////////////////////////////////////////////////////////////////
00096 
00097     // ==> -(e) = (-1) * e
00098     virtual Theorem uMinusToMult(const Expr& e);
00099 
00100     // ==> x - y = x + (-1) * y
00101     virtual Theorem minusToPlus(const Expr& x, const Expr& y);
00102 
00103     // Rule for unary minus: it just converts it to division by -1,
00104     virtual Theorem canonUMinusToDivide(const Expr& e);
00105 
00106     // Rules for division by constant 'd'
00107     // (c) / d ==> (c/d), takes c and d
00108     virtual Theorem canonDivideConst(const Expr& c, const Expr& d);
00109     // (c * x) / d ==> (c/d) * x, takes (c*x) and d
00110     virtual Theorem canonDivideMult(const Expr& cx, const Expr& d);
00111     // (+ c ...)/d ==> push division to all the coefficients.
00112     // The result is not canonical, but canonizing the summands will
00113     // make it canonical.
00114     // Takes (+ c ...) and d
00115     virtual Theorem canonDividePlus(const Expr& e, const Expr& d);
00116     // x / d ==> (1/d) * x, takes x and d
00117     virtual Theorem canonDivideVar(const Expr& e, const Expr& e);
00118 
00119     // Canon Rules for multiplication
00120 
00121     // TODO Deepak:
00122     // t1 * t2 where t1 and t2 are canonized expressions, i.e. it can be a
00123     // 1) Rational constant
00124     // 2) Arithmetic Leaf (var or term from another theory)
00125     // 3) (POW rational leaf)
00126     // 4) (MULT rational mterm'_1 ...) where each mterm' is of type (2) or (3)
00127     // 5) (PLUS rational sterm_1 sterm_2 ...) where each sterm is of 
00128     //     type (2) or (3) or (4) 
00129 
00130     static bool greaterthan(const Expr &, const Expr &);
00131     virtual Expr simplifiedMultExpr(std::vector<Expr> & mulKids);
00132     virtual Expr canonMultConstMult(const Expr & c, const Expr & e);
00133     virtual Expr canonMultConstPlus(const Expr & e1, const Expr & e2);
00134     virtual Expr canonMultPowPow(const Expr & e1, const Expr & e2);
00135     virtual Expr canonMultPowLeaf(const Expr & e1, const Expr & e2);
00136     virtual Expr canonMultLeafLeaf(const Expr & e1, const Expr & e2);
00137     virtual Expr canonMultLeafOrPowMult(const Expr & e1, const Expr & e2);
00138     virtual Expr canonCombineLikeTerms(const std::vector<Expr> & sumExprs);
00139     virtual Expr 
00140         canonMultLeafOrPowOrMultPlus(const Expr & e1, const Expr & e2);
00141     virtual Expr canonMultPlusPlus(const Expr & e1, const Expr & e2);
00142     virtual Theorem canonMultMtermMterm(const Expr& e);
00143     virtual Theorem canonPlus(const Expr & e);
00144     virtual Theorem canonMult(const Expr & e);
00145     virtual Theorem canonInvertConst(const Expr & e);
00146     virtual Theorem canonInvertLeaf(const Expr & e);
00147     virtual Theorem canonInvertPow(const Expr & e);
00148     virtual Theorem canonInvertMult(const Expr & e);
00149     virtual Theorem canonInvert(const Expr & e);
00150     virtual Theorem canonDivide(const Expr & e);
00151     
00152 
00153     // t*c ==> c*t, takes constant c and term t
00154     virtual Theorem canonMultTermConst(const Expr& c, const Expr& t);
00155     // t1*t2 ==> Error, takes t1 and t2 where both are non-constants
00156     virtual Theorem canonMultTerm1Term2(const Expr& t1, const Expr& t2);
00157     // 0*t ==> 0, takes 0*t
00158     virtual Theorem canonMultZero(const Expr& e);
00159     // 1*t ==> t, takes 1*t
00160     virtual Theorem canonMultOne(const Expr& e);
00161     // c1*c2 ==> c', takes constant c1*c2 
00162     virtual Theorem canonMultConstConst(const Expr& c1, const Expr& c2);
00163     // c1*(c2*t) ==> c'*t, takes c1 and c2 and t
00164     virtual Theorem 
00165       canonMultConstTerm(const Expr& c1, const Expr& c2, const Expr&t);
00166     // c1*(+ c2 v1 ...) ==> (+ c' c1v1 ...), takes c1 and the sum
00167     virtual Theorem canonMultConstSum(const Expr& c1, const Expr& sum);
00168     // c^n = c' (compute the constant power expression)
00169     virtual Theorem canonPowConst(const Expr& pow);
00170 
00171     // Rules for addition
00172     // flattens the input. accepts a PLUS expr
00173     virtual Theorem canonFlattenSum(const Expr& e);
00174     
00175     // Rules for addition
00176     // combine like terms. accepts a flattened PLUS expr
00177     virtual Theorem canonComboLikeTerms(const Expr& e);
00178     
00179     // e[0] kind e[1] <==> true when e[0] kind e[1],
00180     // false when e[0] !kind e[1], for constants only
00181     virtual Theorem constPredicate(const Expr& e);
00182 
00183     // e[0] kind e[1] <==> 0 kind e[1] - e[0]
00184     virtual Theorem rightMinusLeft(const Expr& e);
00185 
00186     // x kind y <==> x + z kind y + z
00187     virtual Theorem plusPredicate(const Expr& x, 
00188                                   const Expr& y, 
00189                                   const Expr& z, int kind);
00190 
00191     // x = y <==> x * z = y * z
00192     virtual Theorem multEqn(const Expr& x, const Expr& y, const Expr& z);
00193 
00194     // if z is +ve, return e[0] LT|LE|GT|GE e[1] <==> e[0]*z LT|LE|GT|GE e[1]*z
00195     // if z is -ve, return e[0] LT|LE|GT|GE e[1] <==> e[1]*z LT|LE|GT|GE e[0]*z
00196     virtual Theorem multIneqn(const Expr& e, const Expr& z);
00197 
00198     // "op1 GE|GT op2" <==> op2 LE|LT op1
00199     virtual Theorem flipInequality(const Expr& e);
00200     
00201     // NOT (op1 LT op2)  <==> (op1 GE op2)
00202     // NOT (op1 LE op2)  <==> (op1 GT op2)
00203     // NOT (op1 GT op2)  <==> (op1 LE op2)
00204     // NOT (op1 GE op2)  <==> (op1 LT op2)
00205     Theorem negatedInequality(const Expr& e);
00206 
00207     Theorem realShadow(const Theorem& alphaLTt, const Theorem& tLTbeta);
00208     Theorem realShadowEq(const Theorem& alphaLEt, const Theorem& tLEalpha);
00209     Theorem finiteInterval(const Theorem& aLEt, const Theorem& tLEac,
00210                            const Theorem& isInta, const Theorem& isIntt);
00211     
00212     Theorem darkGrayShadow2ab(const Theorem& betaLEbx, 
00213                               const Theorem& axLEalpha,
00214                               const Theorem& isIntAlpha,
00215                               const Theorem& isIntBeta,
00216                               const Theorem& isIntx);
00217       
00218     Theorem darkGrayShadow2ba(const Theorem& betaLEbx, 
00219                               const Theorem& axLEalpha,
00220                               const Theorem& isIntAlpha,
00221                               const Theorem& isIntBeta,
00222                               const Theorem& isIntx);
00223         
00224     Theorem expandDarkShadow(const Theorem& darkShadow);
00225     Theorem expandGrayShadow0(const Theorem& grayShadow);
00226     Theorem splitGrayShadow(const Theorem& grayShadow);
00227     Theorem expandGrayShadow(const Theorem& grayShadow);
00228     Theorem expandGrayShadowConst(const Theorem& grayShadow);
00229     Theorem grayShadowConst(const Theorem& g);
00230 
00231     //! Implements j(c,b,a)
00232     /*! accepts 3 integers a,b,c and returns
00233      *  (b > 0)? (c+b) mod a :  (a - (c+b)) mod a
00234      */
00235     Rational constRHSGrayShadow(const Rational& c,
00236                                 const Rational& b,
00237                                 const Rational& a);
00238 
00239     Theorem lessThanToLE(const Theorem& less, const Theorem& isIntLHS,
00240                          const Theorem& isIntRHS, bool changeRight);
00241     
00242     Theorem intVarEqnConst(const Expr& eqn, const Theorem& isIntx);
00243 
00244     Theorem eqElimIntRule(const Theorem& eqn, const Theorem& isIntx,
00245                           const std::vector<Theorem>& isIntVars);
00246 
00247     Theorem isIntConst(const Expr& e);
00248 
00249     Theorem equalLeaves1(const Theorem& e);
00250     Theorem equalLeaves2(const Theorem& e);
00251     Theorem equalLeaves3(const Theorem& e);
00252     Theorem equalLeaves4(const Theorem& e);
00253 
00254     Theorem diseqToIneq(const Theorem& diseq);
00255   }; // end of class ArithTheoremProducer
00256 
00257 } // end of namespace CVCL
00258 
00259 #endif

Generated on Thu Apr 13 16:57:28 2006 for CVC Lite by  doxygen 1.4.4