Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

Monomial.h

Go to the documentation of this file.
00001 
00002 // MathCore = a WYSIWYG equation editor + a powerful math engine     //
00003 // Copyright (C) 2003 by Francesco Montorsi                          //
00004 //                                                                   //
00005 // This library is free software; you can redistribute it and/or     //
00006 // modify it under the terms of the GNU Lesser General Public        //
00007 // License as published by the Free Software Foundation; either      //
00008 // version 2.1 of the License, or (at your option) any later         //
00009 // version.                                                          //
00010 //                                                                   //
00011 // This library is distributed in the hope that it will be useful,   //
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of    //
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the      //
00014 // GNU Lesser General Public License for more details.               //
00015 //                                                                   //
00016 // You should have received a copy of the GNU Lesser General Public  //
00017 // License along with this program; if not, write to the Free        //
00018 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,   //
00019 // MA 02111-1307, USA.                                               //
00020 //                                                                   //
00021 // For any comment, suggestion or feature request, please contact    //
00022 // the administrator of the project at frm@users.sourceforge.net     //
00023 //                                                                   //
00030 
00031 
00032 
00033 
00034 #ifndef MONOMIAL_H
00035 #define MONOMIAL_H
00036 
00037 // optimization for GCC compiler
00038 #ifdef __GNUG__
00039 #pragma interface "Monomial.h"
00040 #endif
00041 
00042 // required includes
00043 #include "mc/ElementArray.h"
00044 
00045 
00046 // defined later
00047 class mcExpElement;
00048 class mcRadical;
00049 class mcBracket;
00050 class mcSymbol;
00051 
00052 mcDEFINE_HELPER_CLASSES(mcMonomial)
00053 extern mcMonomial mcEmptyMonomial;
00054 
00055 
00056 
00060 class mcMonomialHelpers : public mcElementArrayHelpers
00061 {
00062  mcDEFINE_REFERENCE_DATA(mcMonomial, mcET_MONOMIAL);
00063 
00064 #ifdef mcENABLE_GUI
00065 public:    // customizable variables
00066 
00071  static bool sgui_bEmptyBoxReplacing;
00072 
00079  static bool sgui_bFunctionScanEnabled;
00080 
00085  static bool sgui_bTransformDivInFractions;
00086 
00089  static int sgui_nSpaceBetween;
00090 
00092  int gui_GetSpaceBetweenRatio() const { return sgui_nSpaceBetween; }
00093 
00094 #endif
00095 
00096 
00097 #ifdef mcENABLE_MATH
00098 public:   // customizable variables
00099 
00100  static mcMonomial *smath_pZero;
00101  static mcMonomial *smath_pOne;
00102 
00103 #endif
00104 
00105 
00106 #ifdef mcENABLE_IO
00107 public:   // customizable variables
00108 
00112  static bool sio_bAutoConvertDivOpToFractions;
00113 
00114 #endif
00115 
00116 
00117 
00118 public:
00119 
00120  mcMonomialHelpers() { data_Init(); }
00121  virtual ~mcMonomialHelpers() {}
00122 
00123 
00124 
00125 #ifdef mcENABLE_DATA
00126 protected:
00127 
00128  int data_GetIdxFromEntry(const mcArrayEntry *p) const
00129  { return p->mdata_idx; }
00130 
00131  mcElement &data_GetRefFromEntry(const mcArrayEntry *p)
00132  { return data_Get(p->mdata_idx); }
00133 
00134 public:
00135 
00136 #ifdef __MCDEBUG__
00137 
00141  void data_Check() const;
00142 
00143 #endif
00144 
00154  void data_Repair();
00155 
00163  void data_TransformDivOp();
00164 
00165 #endif  // mcENABLE_DATA
00166 
00167 
00168 
00169 #ifdef mcENABLE_GUI
00170 public:
00171 
00172 
00176 
00177  int gui_AddNewElement(mcElementType type, const mcKey &key, int pos = -1);
00178 
00181  void gui_CheckCursorPos() const;
00182  
00184  void gui_ScanArrayForFunctions();
00185 
00189  void gui_ReplaceSymbolsWithFunction(int idx, int fnc);
00190  
00192 
00193 
00194 
00198 
00201  bool gui_isBeginKey(const mcKey &) const  { return FALSE;  }
00202 
00204  bool gui_isArrEndKey(const mcKey &key) const { 
00205   mcElementType m = mcElementHelpers::gui_isKeyBeginKey(key);
00206 
00207   if (m == mcET_ADDOP || m == mcET_SUBOP)
00208    return TRUE;
00209   return FALSE;
00210  }
00211 
00219  int gui_Draw(wxDC &dc, int x, int y, long flags, const wxPoint &pt, int cl) const;
00220 
00224  int gui_DeleteFirstOp();
00225 
00226  mcInputRes gui_Input(const mcKey &ev, mcElement *newelem);
00227  mcInputRes gui_BackInput(const mcKey &key, mcElement *pnewelem, int n);
00228 
00229  mcInsertRes gui_Insert(const mcElement *toinsert, int n);
00230  mcInsertRes gui_Insert(const mcElement &toinsert, mcElement *);
00231 
00232  void gui_Replace(mcElement *);
00233 
00234  bool gui_Split(mcElement *);
00235  void gui_DoSplit(mcElementType type, const mcKey &key);
00236  bool gui_MergeWith(const mcElement &);
00237 
00238  int gui_Draw(wxDC &dc, int x, int y, long flags, const wxPoint &pt) const {
00239   // call the overloaded version
00240   return gui_Draw(dc, x, y, flags, pt, -1);
00241  }
00242 
00244 
00245 #endif  // mcENABLE_GUI
00246 
00247 
00248 
00249 
00250 #ifdef mcENABLE_MATH
00251 protected:
00252 
00254  virtual mcExpSimRes math_HandleExpSimFlag(mcExpSimRes r, mcElement *newelem, int i);
00255  
00267  mcExpSimRes math_Reorder();
00268 
00271  //void ReorderSymbols(mcSymbol **arr, int nsymbols);
00272 
00274  virtual mcExpSimRes math_BeginSimSteps();
00275 
00277  virtual void math_EndSimSteps();
00278 
00279 public:
00280 
00281 
00285 
00286  int math_MathToDataIdx(int dataindex) const;
00287  int math_DataToMathIdx(int mathindex) const;
00288  
00289  void math_PrepareForComparison(mcElementArray &p) const;
00290 
00291  mcElementType math_GetNeutralOpType() const  { return mcET_MULTOP; }
00292  double math_GetNeutralValue() const    { return 1.0; }
00293  
00294  mcPolynomial math_GetPolynomialWrapper() const;
00295  mcArrayEntry math_WrapMonomial(const mcMonomial &);
00296  mcArrayEntry math_WrapSimple(const mcElement &);
00297  //void math_GetFactors();
00298 
00299 // void math_FactoreOut();
00300 /* const mcElement &math_Get(int n) const 
00301   { return (const mcElement &)mcElementArrayHelpers::math_Get(n); }
00302  mcElement &math_Get(int n) 
00303   { return (mcElement &)mcElementArrayHelpers::math_Get(n); }
00304 */
00305  //void math_RaiseChildrenTo(const mcRealValue &n);
00306  mcBasicOpRes math_RaiseTo(const mcPolynomial &p);
00307  
00309 
00310 
00311 
00315  
00320  void math_Abs();
00321 
00324  //bool SetSign(int n);
00325 
00329  //bool ChangeSign();
00330 
00333  //int GetSign() const;
00334 
00339  //bool GetParentPos(const mcPolynomial &*pol = NULL, int *idx = NULL) const;
00340  //bool GetParentPos(mcPolynomial &*pol = NULL, int *idx = NULL);
00341 
00345  bool math_isSimilarTo(const mcMonomial &) const;
00346 
00350  void math_TransformDivOp();
00351 
00354  void math_RemoveAllOp(); 
00355  
00358  mcMonomial math_DetachNonCommonFactors(const mcMonomial &);
00359 
00365  mcIntegerValue math_GetMaxDegreeFor(const mcSymbolProperties *) const;
00366 
00369  mcIntegerValue math_GetMaxDegreeForSymbolArray(const mcSymbolArray *p) const;
00370 
00372 
00373  
00374 
00375 
00379   
00380  void math_SimplifyCoeff();
00381  void math_RemoveCoeff();
00382  void math_SetCoeff(const mcNumber &);
00383  void math_ChangeCoeffSign();
00384  mcRealValue math_GetCoeff() const;
00385 
00387 
00388 
00389 
00393 
00394  bool math_CanBeAddedWith(const mcElement &p) const;
00395 
00396  mcBasicOpRes math_Add(const mcElement &, mcElement *p, bool add);
00397  mcBasicOpRes math_MultiplyBy(const mcElement &, mcElement *p);
00398  mcBasicOpRes math_DivideBy(const mcElement &, mcElement *p);
00399 
00401  int math_GetOrderPos() const;
00402 
00403  mcMonomial math_GetLCM(const mcElement &) const;
00404  mcMonomial math_GetGCD(const mcElement &) const;
00405 
00407 
00408 #endif  // mcENABLE_MATH
00409 
00410 
00411 
00412 #ifdef mcENABLE_IO
00413 public:
00414 
00415  wxXml2Node io_GetMathML(bool bGetPresentation) const;
00416 
00417  bool io_ImportPresentationMathML(wxXml2Node tag, wxString &pErr);
00418  bool io_ImportInlinedExpr(const wxString &, int *, wxString &pErr);
00419 
00423  void io_PostProcess();
00424 
00425 #endif  // mcENABLE_IO
00426 };
00427 
00428 
00441 class mcMonomial : public mcElementArray 
00442 {
00443  friend class mcPolynomial;
00444  mcDEFINE_MAIN_CLASS(Monomial, mcElementArray);
00445 
00446 public:
00447 
00448  mcMonomial(const mcSymbol &towrap); 
00449  mcMonomial(const mcNumber &towrap);
00450  mcMonomial(const mcRadical &towrap);
00451  mcMonomial(const mcBracket &towrap);
00452  mcMonomial(const mcFraction &towrap);
00453 
00454 
00455  mcMonomial operator*(const mcMonomial &m) const
00456  { mcMonomial ret(*this); ret.math_SimpleMultiplyBy(m); return ret; }
00457  mcMonomial operator/(const mcMonomial &m) const
00458  { mcMonomial ret(*this); ret.math_SimpleDivideBy(m); return ret; }
00459  mcMonomial operator-(const mcMonomial &m) const
00460  { mcMonomial ret(*this); ret.math_SimpleSubtract(m); return ret; }
00461  mcMonomial operator+(const mcMonomial &m) const
00462  { mcMonomial ret(*this); ret.math_SimpleAdd(m); return ret; }
00463 
00464  mcMonomial operator+=(const mcMonomial &m)  { *this = *this+m;return *this; }
00465  mcMonomial operator-=(const mcMonomial &m)  { *this = *this-m;return *this; }
00466  mcMonomial operator*=(const mcMonomial &m)  { *this = *this*m;return *this; }
00467  mcMonomial operator/=(const mcMonomial &m)  { *this = *this/m;return *this; }
00468 
00469 
00470 
00471  bool data_isValidContainerFor(mcElementType t) const
00472   { return t == mcET_MONOMIAL; }
00473 
00474  mcWRAPPER void math_RemoveAllOp()
00475   { hlp()->math_RemoveAllOp(); }
00476 
00477 
00478  mcWRAPPER void math_Abs()
00479   { hlp()->math_Abs(); }
00480 /* mcWRAPPER bool math_isSimilarTo(const mcMonomial &) const;
00481  mcWRAPPER void math_TransformDivOp();
00482 
00483  mcWRAPPER mcMonomial math_DetachNonCommonFactors(const mcMonomial &);*/
00484 /*
00485  mcWRAPPER const mcElement &math_Get(int n) const
00486   { return hlp()->math_Get(n); }
00487  mcWRAPPER mcElement &math_Get(int n)
00488   { return hlp()->math_Get(n); }*/
00489 
00490  mcWRAPPER mcIntegerValue math_GetMaxDegreeFor(const mcSymbolProperties *p) const
00491   { return hlp()->math_GetMaxDegreeFor(p); }
00492  mcWRAPPER mcIntegerValue math_GetMaxDegreeForSymbolArray(const mcSymbolArray *p) const
00493   { return hlp()->math_GetMaxDegreeForSymbolArray(p); }
00494 
00495  mcWRAPPER void math_SimplifyCoeff()
00496   { hlp()->math_SimplifyCoeff(); }
00497  mcWRAPPER void math_SetCoeff(const mcNumber &n)
00498   { hlp()->math_SetCoeff(n); }
00499  mcWRAPPER void math_RemoveCoeff()
00500   { hlp()->math_RemoveCoeff(); }
00501  mcWRAPPER mcRealValue math_GetCoeff() const
00502   { return hlp()->math_GetCoeff(); }
00503 
00504  mcWRAPPER void math_ChangeCoeffSign()
00505   { hlp()->math_ChangeCoeffSign(); }
00506 };
00507 
00508 
00509 #endif // MONOMIAL_H
00510 


Documentation generated with Doxygen on Sun Feb 6 17:10:48 2005
Visit MathStudio home page for more info

[ Top ]