SundanceStdSumTransformations.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
00030 
00031 #ifndef SUNDANCE_STDSUMTRANSFORMATION_H
00032 #define SUNDANCE_STDSUMTRANSFORMATION_H
00033 
00034 #include "SundanceDefs.hpp"
00035 #include "SundanceSumTransformationSequence.hpp"
00036 
00037 namespace Sundance
00038 {
00039 using namespace Sundance;
00040 using namespace Teuchos;
00041 using namespace Sundance;
00042 
00043 
00044 
00045 
00046 /**
00047  * Apply a standard set of transformations
00048  */
00049 class StdSumTransformations : public SumTransformationSequence
00050 {
00051 public:
00052   StdSumTransformations();
00053 
00054   virtual ~StdSumTransformations(){;}
00055 };
00056 
00057 /** 
00058  * Rewrite a sum as a polynomial object, if possible.
00059  */
00060 class IdentifyPolynomialSum : public SumTransformation
00061 {
00062 public:
00063   /** */
00064   IdentifyPolynomialSum() : SumTransformation() {;}
00065 
00066   /** */
00067   virtual ~IdentifyPolynomialSum(){;}
00068 
00069   /** */
00070   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00071     const RCP<ScalarExpr>& right,
00072     int sign, RCP<ScalarExpr>& rtn) const ;
00073 };
00074 
00075 /** 
00076  * Put terms in a standard order
00077  */
00078 class ReorderSum : public SumTransformation
00079 {
00080 public:
00081   /** */
00082   ReorderSum() : SumTransformation() {;}
00083 
00084   /** */
00085   virtual ~ReorderSum(){;}
00086 
00087   /** */
00088   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00089     const RCP<ScalarExpr>& right,
00090     int sign, RCP<ScalarExpr>& rtn) const ;
00091 };
00092     
00093 
00094 /** 
00095  * Simplify sums involving unary minuses
00096  * \f[
00097  * x + (-y) \rightarrow x-y. 
00098  * \f]
00099  * \f[
00100  * (-x) + (-y) \rightarrow -(x+y). 
00101  * \f]
00102  * \f[
00103  * (-x) + y \rightarrow y-x. 
00104  * \f]
00105  */
00106 class RemoveUnaryMinusFromSum : public SumTransformation
00107 {
00108 public:
00109   /** */
00110   RemoveUnaryMinusFromSum() : SumTransformation() {;}
00111 
00112   /** */
00113   virtual ~RemoveUnaryMinusFromSum(){;}
00114 
00115   /** */
00116   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00117     const RCP<ScalarExpr>& right,
00118     int sign, RCP<ScalarExpr>& rtn) const ;
00119 };
00120     
00121 /** 
00122  * Transform a sum by removing a zero term: 
00123  * \f[
00124  * x + 0 \rightarrow x. 
00125  * \f]
00126  */
00127 class RemoveZeroFromSum : public SumTransformation
00128 {
00129 public:
00130   /** */
00131   RemoveZeroFromSum() : SumTransformation() {;}
00132 
00133   /** */
00134   virtual ~RemoveZeroFromSum(){;}
00135 
00136   /** */
00137   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00138     const RCP<ScalarExpr>& right,
00139     int sign, RCP<ScalarExpr>& rtn) const ;
00140 };
00141 
00142 /** 
00143  * Sum two constant exprs without transformation 
00144  */
00145 class SumConstants : public SumTransformation
00146 {
00147 public:
00148   /** */
00149   SumConstants() : SumTransformation() {;}
00150 
00151   /** */
00152   virtual ~SumConstants(){;}
00153 
00154   /** */
00155   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00156     const RCP<ScalarExpr>& right,
00157     int sign, RCP<ScalarExpr>& rtn) const ;
00158 };
00159 
00160 /** 
00161  * Transform a sum by moving any constants to the left:
00162  * \f[
00163  * x + a \rightarrow a + x
00164  * \f]
00165  **/
00166 class MoveConstantsToLeftOfSum : public SumTransformation
00167 {
00168 public:
00169   /** */
00170   MoveConstantsToLeftOfSum() : SumTransformation() {;}
00171 
00172   /** */
00173   virtual ~MoveConstantsToLeftOfSum(){;}
00174 
00175   /** */
00176   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00177     const RCP<ScalarExpr>& right,
00178     int sign, RCP<ScalarExpr>& rtn) const ;
00179 };
00180 
00181 
00182 /** 
00183  * Rearrange a sum whose right operand is a sum including a constant
00184  * such that constants are grouped on the left:
00185  * \f[
00186  * \alpha + s_1 (\beta + s_2 u) \rightarrow (\alpha + s_1 \beta) + s_1 s_2 u
00187  * \f]
00188  * \f[
00189  * u + s_1 (\alpha + s_2 v) \rightarrow s_1 \alpha + (u + s_1 s_2 v)
00190  * \f]
00191  **/
00192 class RearrangeRightSumWithConstant : public SumTransformation
00193 {
00194 public:
00195   /** */
00196   RearrangeRightSumWithConstant() : SumTransformation() {;}
00197 
00198   /** */
00199   virtual ~RearrangeRightSumWithConstant(){;}
00200 
00201   /** */
00202   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00203     const RCP<ScalarExpr>& right,
00204     int sign, RCP<ScalarExpr>& rtn) const ;
00205 };
00206 
00207 /** 
00208  * Rearrange a sum whose left operand is a sum including a constant
00209  * such that constants are grouped on the left:
00210  * \f[
00211  * (\alpha + s_1 u) + s_2 \beta \rightarrow (\alpha + s_2 \beta) + s_1 u 
00212  * \f]
00213  * \f[
00214  * (\alpha + s_1 u) + s_2 v \rightarrow \alpha + (s_1 u + s_2 v)
00215  * \f]
00216  **/
00217 class RearrangeLeftSumWithConstant : public SumTransformation
00218 {
00219 public:
00220   /** */
00221   RearrangeLeftSumWithConstant() : SumTransformation() {;}
00222 
00223   /** */
00224   virtual ~RearrangeLeftSumWithConstant(){;}
00225 
00226   /** */
00227   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00228     const RCP<ScalarExpr>& right,
00229     int sign, RCP<ScalarExpr>& rtn) const ;
00230 };
00231 
00232 
00233 /** 
00234  * Transform sum of integrals to SumOfIntegral objects
00235  **/
00236 class SumIntegrals : public SumTransformation
00237 {
00238 public:
00239   /** */
00240   SumIntegrals() : SumTransformation() {;}
00241 
00242   /** */
00243   virtual ~SumIntegrals(){;}
00244 
00245   /** */
00246   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00247     const RCP<ScalarExpr>& right,
00248     int sign, RCP<ScalarExpr>& rtn) const ;
00249 };
00250 }
00251 
00252 
00253 #endif

Site Contact