SundanceStdSumTransformations.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                             Sundance
00005 //                 Copyright 2011 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
00041 
00042 #ifndef SUNDANCE_STDSUMTRANSFORMATION_H
00043 #define SUNDANCE_STDSUMTRANSFORMATION_H
00044 
00045 #include "SundanceDefs.hpp"
00046 #include "SundanceSumTransformationSequence.hpp"
00047 
00048 namespace Sundance
00049 {
00050 using namespace Sundance;
00051 using namespace Teuchos;
00052 using namespace Sundance;
00053 
00054 
00055 
00056 
00057 /**
00058  * Apply a standard set of transformations
00059  */
00060 class StdSumTransformations : public SumTransformationSequence
00061 {
00062 public:
00063   StdSumTransformations();
00064 
00065   virtual ~StdSumTransformations(){;}
00066 };
00067 
00068 /** 
00069  * Rewrite a sum as a polynomial object, if possible.
00070  */
00071 class IdentifyPolynomialSum : public SumTransformation
00072 {
00073 public:
00074   /** */
00075   IdentifyPolynomialSum() : SumTransformation() {;}
00076 
00077   /** */
00078   virtual ~IdentifyPolynomialSum(){;}
00079 
00080   /** */
00081   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00082     const RCP<ScalarExpr>& right,
00083     int sign, RCP<ScalarExpr>& rtn) const ;
00084 };
00085 
00086 /** 
00087  * Put terms in a standard order
00088  */
00089 class ReorderSum : public SumTransformation
00090 {
00091 public:
00092   /** */
00093   ReorderSum() : SumTransformation() {;}
00094 
00095   /** */
00096   virtual ~ReorderSum(){;}
00097 
00098   /** */
00099   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00100     const RCP<ScalarExpr>& right,
00101     int sign, RCP<ScalarExpr>& rtn) const ;
00102 };
00103     
00104 
00105 /** 
00106  * Simplify sums involving unary minuses
00107  * \f[
00108  * x + (-y) \rightarrow x-y. 
00109  * \f]
00110  * \f[
00111  * (-x) + (-y) \rightarrow -(x+y). 
00112  * \f]
00113  * \f[
00114  * (-x) + y \rightarrow y-x. 
00115  * \f]
00116  */
00117 class RemoveUnaryMinusFromSum : public SumTransformation
00118 {
00119 public:
00120   /** */
00121   RemoveUnaryMinusFromSum() : SumTransformation() {;}
00122 
00123   /** */
00124   virtual ~RemoveUnaryMinusFromSum(){;}
00125 
00126   /** */
00127   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00128     const RCP<ScalarExpr>& right,
00129     int sign, RCP<ScalarExpr>& rtn) const ;
00130 };
00131     
00132 /** 
00133  * Transform a sum by removing a zero term: 
00134  * \f[
00135  * x + 0 \rightarrow x. 
00136  * \f]
00137  */
00138 class RemoveZeroFromSum : public SumTransformation
00139 {
00140 public:
00141   /** */
00142   RemoveZeroFromSum() : SumTransformation() {;}
00143 
00144   /** */
00145   virtual ~RemoveZeroFromSum(){;}
00146 
00147   /** */
00148   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00149     const RCP<ScalarExpr>& right,
00150     int sign, RCP<ScalarExpr>& rtn) const ;
00151 };
00152 
00153 /** 
00154  * Sum two constant exprs without transformation 
00155  */
00156 class SumConstants : public SumTransformation
00157 {
00158 public:
00159   /** */
00160   SumConstants() : SumTransformation() {;}
00161 
00162   /** */
00163   virtual ~SumConstants(){;}
00164 
00165   /** */
00166   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00167     const RCP<ScalarExpr>& right,
00168     int sign, RCP<ScalarExpr>& rtn) const ;
00169 };
00170 
00171 /** 
00172  * Transform a sum by moving any constants to the left:
00173  * \f[
00174  * x + a \rightarrow a + x
00175  * \f]
00176  **/
00177 class MoveConstantsToLeftOfSum : public SumTransformation
00178 {
00179 public:
00180   /** */
00181   MoveConstantsToLeftOfSum() : SumTransformation() {;}
00182 
00183   /** */
00184   virtual ~MoveConstantsToLeftOfSum(){;}
00185 
00186   /** */
00187   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00188     const RCP<ScalarExpr>& right,
00189     int sign, RCP<ScalarExpr>& rtn) const ;
00190 };
00191 
00192 
00193 /** 
00194  * Rearrange a sum whose right operand is a sum including a constant
00195  * such that constants are grouped on the left:
00196  * \f[
00197  * \alpha + s_1 (\beta + s_2 u) \rightarrow (\alpha + s_1 \beta) + s_1 s_2 u
00198  * \f]
00199  * \f[
00200  * u + s_1 (\alpha + s_2 v) \rightarrow s_1 \alpha + (u + s_1 s_2 v)
00201  * \f]
00202  **/
00203 class RearrangeRightSumWithConstant : public SumTransformation
00204 {
00205 public:
00206   /** */
00207   RearrangeRightSumWithConstant() : SumTransformation() {;}
00208 
00209   /** */
00210   virtual ~RearrangeRightSumWithConstant(){;}
00211 
00212   /** */
00213   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00214     const RCP<ScalarExpr>& right,
00215     int sign, RCP<ScalarExpr>& rtn) const ;
00216 };
00217 
00218 /** 
00219  * Rearrange a sum whose left operand is a sum including a constant
00220  * such that constants are grouped on the left:
00221  * \f[
00222  * (\alpha + s_1 u) + s_2 \beta \rightarrow (\alpha + s_2 \beta) + s_1 u 
00223  * \f]
00224  * \f[
00225  * (\alpha + s_1 u) + s_2 v \rightarrow \alpha + (s_1 u + s_2 v)
00226  * \f]
00227  **/
00228 class RearrangeLeftSumWithConstant : public SumTransformation
00229 {
00230 public:
00231   /** */
00232   RearrangeLeftSumWithConstant() : SumTransformation() {;}
00233 
00234   /** */
00235   virtual ~RearrangeLeftSumWithConstant(){;}
00236 
00237   /** */
00238   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00239     const RCP<ScalarExpr>& right,
00240     int sign, RCP<ScalarExpr>& rtn) const ;
00241 };
00242 
00243 
00244 /** 
00245  * Transform sum of integrals to SumOfIntegral objects
00246  **/
00247 class SumIntegrals : public SumTransformation
00248 {
00249 public:
00250   /** */
00251   SumIntegrals() : SumTransformation() {;}
00252 
00253   /** */
00254   virtual ~SumIntegrals(){;}
00255 
00256   /** */
00257   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00258     const RCP<ScalarExpr>& right,
00259     int sign, RCP<ScalarExpr>& rtn) const ;
00260 };
00261 }
00262 
00263 
00264 #endif

Site Contact