• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

Analitza

  • sources
  • kde-4.14
  • kdeedu
  • analitza
  • analitza
analyzer.h
Go to the documentation of this file.
1 /*************************************************************************************
2  * Copyright (C) 2007-2010 by Aleix Pol <aleixpol@kde.org> *
3  * *
4  * This program is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU General Public License *
6  * as published by the Free Software Foundation; either version 2 *
7  * of the License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License *
15  * along with this program; if not, write to the Free Software *
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
17  *************************************************************************************/
18 
19 
20 #ifndef ANALYZER_H
21 #define ANALYZER_H
22 
23 #include <QStringList>
24 
25 #include "expression.h"
26 #include "analitzaexport.h"
27 #include "expressiontype.h"
28 #include "builtinmethods.h"
29 #include <QStack>
30 #include <analitza/analitzautils.h>
31 
32 namespace Analitza
33 {
34 class Polynomial;
35 class Monomial;
36 class Apply;
37 class BoundingIterator;
38 class BuiltinMethods;
39 class Object;
40 class Variables;
41 class Container;
42 class Operator;
43 class Ci;
44 
59 class ANALITZA_EXPORT Analyzer
60 {
61  public:
63  Analyzer();
64 
68  Analyzer(Variables* v);
69 
71  Analyzer(const Analyzer& a);
72 
74  ~Analyzer();
75 
77  void setExpression(const Expression &e);
78 
80  const Expression& expression() const { return m_exp; }
81 
83  Expression calculate();
84 
89  Expression calculateLambda();
90 
92  Expression evaluate();
93 
95  Expression derivative(const QString& var);
96 
98  double derivative(const QVector<Object*>& values );
99 
101  bool isCorrect() const { return m_err.isEmpty() && m_exp.isCorrect(); }
102 
104  void flushErrors() { m_err.clear(); }
105 
107  void simplify(); //FIXME: Should return an Expression
108 
110  QStringList errors() const { return m_exp.error() + m_err; }
111 
113  Variables *variables() const { return m_vars; }
114 
120  bool insertVariable(const QString& name, const Expression& value);
121 
127  bool insertVariable(const QString& name, const Object* value);
128 
133  Cn* insertValueVariable(const QString& name, double value);
134 
136  bool hasDependencies() const { return m_hasdeps; }
137 
143  Expression dependenciesToLambda() const;
144 
148  ExpressionType type() const { return m_currentType; }
149 
150  void setStack(const QVector<Object*>& stack) { m_runStack = stack; }
151 
152  QVector<Object*> runStack() const { return m_runStack; }
153 
154  BuiltinMethods* builtinMethods();
155 
157  void importScript(QTextStream* stream);
158 
160  QMap<QString, ExpressionType> variableTypes() const { return m_variablesTypes; }
161  private:
162  typedef Object* (Analyzer::*funcContainer)(const Container*);
163  static funcContainer operateContainer[];
164 
165  Expression m_exp;
166  Variables *m_vars;
167  QStringList m_err;
168  QVector<Object*> m_runStack;
169  int m_runStackTop;
170  BuiltinMethods m_builtin;
171 
172  const bool m_varsOwned;
173  bool m_hasdeps;
174  ExpressionType m_currentType;
175  QMap<QString, ExpressionType> m_variablesTypes;
176 
177  Object* calc(const Object* e);
178  Object* operate(const Container*);
179  Object* operate(const Apply*);
180  Object* eval(const Object* e, bool vars, const QSet<QString>& unscoped);
181 
182  Object* sum(const Apply& c);
183  Object* product(const Apply& c);
184  Object* exists(const Apply& c);
185  Object* forall(const Apply& c);
186  Object* func(const Apply& c);
187  Object* calcDiff(const Apply* c);
188  Object* calcMap(const Apply* c);
189  Object* calcFilter(const Apply* c);
190 
191  Object* calcPiecewise(const Container* c);
192  Object* calcDeclare(const Container* c);
193  Object* calcMath(const Container* c);
194  Object* calcLambda(const Container* c);
195  Object* calcCallFunction(Analitza::Container* function, const QVector<Analitza::Object* >& args, const Analitza::Object* op);
196 
197  Object* simp(Object* root);
198  Object* simpPolynomials(Apply* c);
199  Object* simpSum(Apply* c);
200  Object* simpApply(Apply* c);
201  Object* simpPiecewise(Container* c);
202 
203  QList<Object*> findRoots(const QString& dep, const Analitza::Object* o);
204  QList<Object*> findRootsApply(const QString& dep, const Analitza::Apply* a);
205 
206  Object* derivative(const QString &var, const Object*);
207  Object* boundedOperation(const Apply & n, const Operator & t, Object* initial);
208 
209  BoundingIterator* initializeBVars(const Apply* n, int base);
210  BoundingIterator* initBVarsContainer(const Apply* n, int base, Object* domain);
211  BoundingIterator* initBVarsRange(const Apply* n, int base, Object* dlimit, Object* ulimit);
212 
213  template <class T, class Tit>
214  void iterateAndSimp(T* v);
215 
216  Object* variableValue(Ci* var);
217  Object* testResult(const Analitza::Object* o, const QString& var, const Analitza::Object* val);
218 
219  template <class T, class Tit>
220  void alphaConversion(T* o, int min);
221  void alphaConversion(Apply* a, int min);
222  void alphaConversion(Container* a, int min);
223  Object* applyAlpha(Analitza::Object* o, int min);
224 
225  template<class T, class Tit>
226  Object* calcElements(const Analitza::Object* root, T* nv);
227 };
228 
229 }
230 #endif
Analitza::Analyzer
The parser: Evaluates and calculates math expressions.
Definition: analyzer.h:59
QMap
Analitza::Cn
Cn is a value in MathML.
Definition: value.h:42
Analitza::Operator
Is the operator representation in the trees.
Definition: operator.h:36
Analitza::Analyzer::errors
QStringList errors() const
Definition: analyzer.h:110
QTextStream
Analitza::Analyzer::hasDependencies
bool hasDependencies() const
Returns whether the current expression has all data it needs to be calculated.
Definition: analyzer.h:136
Analitza::Ci
A variable object, name refers to MathML standard.
Definition: variable.h:34
expressiontype.h
Analitza::ExpressionType
Definition: expressiontype.h:30
Analitza::Analyzer::expression
const Expression & expression() const
Returns the expression in display.
Definition: analyzer.h:80
Analitza::Analyzer::flushErrors
void flushErrors()
Empties the error list.
Definition: analyzer.h:104
Analitza::Analyzer::setStack
void setStack(const QVector< Object * > &stack)
Definition: analyzer.h:150
expression.h
Analitza::Analyzer::variables
Variables * variables() const
Definition: analyzer.h:113
Analitza::Analyzer::runStack
QVector< Object * > runStack() const
Definition: analyzer.h:152
QSet< QString >
QString
QList
builtinmethods.h
QStringList
Analitza::BuiltinMethods
Definition: builtinmethods.h:59
analitzautils.h
Analitza::Variables
Stores the variables in a hash map and make them available.
Definition: variables.h:42
analitzaexport.h
Analitza::Container
Container represents special tags of MathML called containers.
Definition: container.h:44
Analitza::Object
Definition: object.h:38
Analitza::Analyzer::variableTypes
QMap< QString, ExpressionType > variableTypes() const
Definition: analyzer.h:160
QVector
ANALITZA_EXPORT
#define ANALITZA_EXPORT
Definition: analitzaexport.h:31
Analitza::Analyzer::type
ExpressionType type() const
This method lets you retrieve the current type in use.
Definition: analyzer.h:148
Analitza::Expression
Represents a mathematical expression.
Definition: expression.h:45
Analitza::Analyzer::isCorrect
bool isCorrect() const
Returns whether there has been a problem in the last calculation.
Definition: analyzer.h:101
Analitza::Apply
This class is the one that will correspond to MathML apply tags.
Definition: apply.h:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:11:37 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Analitza

Skip menu "Analitza"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal