1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

Integration of OCCT 6.5.0 from SVN

This commit is contained in:
bugmaster
2011-03-16 07:30:28 +00:00
committed by bugmaster
parent 4903637061
commit 7fd59977df
16375 changed files with 3882564 additions and 0 deletions

115
src/Expr/Expr.cdl Executable file
View File

@@ -0,0 +1,115 @@
-- File: Expr.cdl
-- Created: Mon Jan 14 15:54:23 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
package Expr
---Purpose: This package describes the data structure of any
-- expression, relation or function used in mathematics.
-- It also describes the assignment of variables. Standard
-- mathematical functions are implemented such as
-- trigonometrics, hyperbolics, and log functions.
uses TColStd,TCollection,MMgt,Standard
is
deferred class GeneralExpression;
class NumericValue;
deferred class NamedExpression;
class NamedConstant;
class NamedUnknown;
deferred class UnaryExpression;
class Absolute;
class ArcCosine;
class ArcSine;
class ArcTangent;
class ArgCosh;
class ArgSinh;
class ArgTanh;
class Cosh;
class Cosine;
class Exponential;
class LogOf10;
class LogOfe;
class Sign;
class Sine;
class Sinh;
class Square;
class SquareRoot;
class Tangent;
class Tanh;
class UnaryFunction;
class UnaryMinus;
deferred class BinaryExpression;
class BinaryFunction;
class Difference;
class Division;
class Exponentiate;
deferred class PolyExpression;
class PolyFunction;
class Product;
class Sum;
class UnknownIterator;
deferred class GeneralRelation;
deferred class SingleRelation;
class Different;
class Equal;
class GreaterThan;
class GreaterThanOrEqual;
class LessThan;
class LessThanOrEqual;
class SystemRelation;
class RelationIterator;
class RUIterator;
deferred class GeneralFunction;
class NamedFunction;
class FunctionDerivative;
exception ExprFailure inherits Failure;
exception NotAssigned inherits ExprFailure ;
exception InvalidAssignment inherits ExprFailure;
exception InvalidFunction inherits ExprFailure;
exception InvalidOperand inherits ExprFailure;
exception NotEvaluable inherits ExprFailure;
class SequenceOfGeneralExpression instantiates
Sequence from TCollection(GeneralExpression);
class Array1OfGeneralExpression instantiates
Array1 from TCollection(GeneralExpression);
class Array1OfNamedUnknown instantiates
Array1 from TCollection(NamedUnknown);
class MapOfNamedUnknown instantiates
IndexedMap from TCollection(NamedUnknown,
MapTransientHasher from TColStd);
class Array1OfSingleRelation instantiates
Array1 from TCollection(SingleRelation);
class SequenceOfGeneralRelation instantiates
Sequence from TCollection(GeneralRelation);
CopyShare(exp : GeneralExpression)
---Level : Internal
returns GeneralExpression;
NbOfFreeVariables(exp : GeneralExpression from Expr)
---Level : Internal
returns Integer;
NbOfFreeVariables(exp : GeneralRelation from Expr)
---Level : Internal
returns Integer;
Sign(val : Real from Standard)
---Level : Internal
returns Real from Standard;
end Expr;

52
src/Expr/Expr.cxx Executable file
View File

@@ -0,0 +1,52 @@
//static const char* sccsid = "@(#)Expr.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr.cxx
// Created: Fri Sep 20 11:23:07 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr.hxx>
#include <Expr_NamedUnknown.hxx>
#include <Expr_GeneralExpression.hxx>
#include <Expr_GeneralRelation.hxx>
#include <Expr_UnknownIterator.hxx>
#include <Expr_RUIterator.hxx>
Handle(Expr_GeneralExpression) Expr::CopyShare(const Handle(Expr_GeneralExpression)& exp)
{
if (exp->IsShareable()) {
return exp;
}
return exp->Copy();
}
Standard_Integer Expr::NbOfFreeVariables(const Handle(Expr_GeneralRelation)& rel)
{
Standard_Integer nbvar = 0;
Expr_RUIterator rit(rel);
while (rit.More()) {
if (!rit.Value()->IsAssigned()) {
nbvar++;
}
rit.Next();
}
return nbvar;
}
Standard_Integer Expr::NbOfFreeVariables(const Handle(Expr_GeneralExpression)& exp)
{
Standard_Integer nbvar = 0;
Expr_UnknownIterator uit(exp);
while (uit.More()) {
if (!uit.Value()->IsAssigned()) {
nbvar++;
}
uit.Next();
}
return nbvar;
}
Standard_Real Expr::Sign(const Standard_Real val)
{
return ::Sign(1.0,val);
}

61
src/Expr/Expr_Absolute.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: Absolute.cdl
-- Created: Mon Jan 14 16:14:52 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class Absolute from Expr
inherits UnaryExpression from Expr
uses GeneralExpression from Expr,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
AsciiString from TCollection,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp : GeneralExpression)
---Purpose: Creates the Abs of <exp>
returns mutable Absolute;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end Absolute;

76
src/Expr/Expr_Absolute.cxx Executable file
View File

@@ -0,0 +1,76 @@
//static const char* sccsid = "@(#)Expr_Absolute.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_Absolute.cxx
// Created: Mon May 27 10:13:50 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_Absolute.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_UnaryMinus.hxx>
#include <Expr_Sign.hxx>
#include <Expr_Product.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_Absolute::Expr_Absolute (const Handle(Expr_GeneralExpression)& exp)
{
CreateOperand(exp);
}
Handle(Expr_GeneralExpression) Expr_Absolute::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) op = Operand();
if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) valop = Handle(Expr_NumericValue)::DownCast(op);
return new Expr_NumericValue(Abs(valop->GetValue()));
}
if (op->IsKind(STANDARD_TYPE(Expr_UnaryMinus))) {
return new Expr_Absolute(op->SubExpression(1));
}
Handle(Expr_Absolute) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_Absolute::Copy () const
{
return new Expr_Absolute(Expr::CopyShare(Operand()));
}
Standard_Boolean Expr_Absolute::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (!Other->IsKind(STANDARD_TYPE(Expr_Absolute))) {
return Standard_False;
}
Handle(Expr_GeneralExpression) op = Operand();
return op->IsIdentical(Other->SubExpression(1));
}
Standard_Boolean Expr_Absolute::IsLinear () const
{
return !ContainsUnknowns();
}
Handle(Expr_GeneralExpression) Expr_Absolute::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
Handle(Expr_GeneralExpression) op = Operand();
Handle(Expr_GeneralExpression) derop = op->Derivative(X);
Handle(Expr_Sign) myder = new Expr_Sign(Expr::CopyShare(op));
Handle(Expr_Product) resul = myder->ShallowSimplified() * derop;
return resul->ShallowSimplified();
}
Standard_Real Expr_Absolute::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
return ::Abs(Operand()->Evaluate(vars,vals));
}
TCollection_AsciiString Expr_Absolute::String() const
{
TCollection_AsciiString str("Abs(");
str += Operand()->String();
str += ")";
return str;
}

61
src/Expr/Expr_ArcCosine.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: ArcCosine.cdl
-- Created: Mon Jan 14 16:16:04 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class ArcCosine from Expr
inherits UnaryExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp : GeneralExpression)
---Purpose: Creates the Arccos of <exp>
returns mutable ArcCosine;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>.
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end ArcCosine;

96
src/Expr/Expr_ArcCosine.cxx Executable file
View File

@@ -0,0 +1,96 @@
//static const char* sccsid = "@(#)Expr_ArcCosine.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_ArcCosine.cxx
// Created: Mon May 27 10:39:35 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_ArcCosine.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_Cosine.hxx>
#include <Expr_Division.hxx>
#include <Expr_Square.hxx>
#include <Expr_Difference.hxx>
#include <Expr_SquareRoot.hxx>
#include <Expr_UnaryMinus.hxx>
#include <Expr_Product.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_ArcCosine::Expr_ArcCosine (const Handle(Expr_GeneralExpression)& exp)
{
CreateOperand(exp);
}
Handle(Expr_GeneralExpression) Expr_ArcCosine::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) op = Operand();
if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) valop = Handle(Expr_NumericValue)::DownCast(op);
return new Expr_NumericValue(ACos(valop->GetValue()));
}
if (op->IsKind(STANDARD_TYPE(Expr_Cosine))) {
return op->SubExpression(1);
}
Handle(Expr_ArcCosine) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_ArcCosine::Copy () const
{
return new Expr_ArcCosine(Expr::CopyShare(Operand()));
}
Standard_Boolean Expr_ArcCosine::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (!Other->IsKind(STANDARD_TYPE(Expr_ArcCosine))) {
return Standard_False;
}
Handle(Expr_GeneralExpression) op = Operand();
return op->IsIdentical(Other->SubExpression(1));
}
Standard_Boolean Expr_ArcCosine::IsLinear () const
{
if (ContainsUnknowns()) {
return Standard_False;
}
return Standard_True;
}
Handle(Expr_GeneralExpression) Expr_ArcCosine::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) op = Operand();
Handle(Expr_GeneralExpression) derop = op->Derivative(X);
Handle(Expr_Square) sq = new Expr_Square(Expr::CopyShare(op));
// 1 - X2
Handle(Expr_Difference) thedif = 1.0 - sq->ShallowSimplified();
Handle(Expr_SquareRoot) theroot = new Expr_SquareRoot(thedif->ShallowSimplified());
// 1/ sqrt(1-X2)
Handle(Expr_UnaryMinus) theder = - (1.0 / theroot->ShallowSimplified());
// ArcCosine'(F(X)) = -1/sqrt(1-F(X)2) * F'(X)
Handle(Expr_Product) result = theder->ShallowSimplified() * derop;
return result->ShallowSimplified();
}
Standard_Real Expr_ArcCosine::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
return ::ACos(Operand()->Evaluate(vars,vals));
}
TCollection_AsciiString Expr_ArcCosine::String() const
{
TCollection_AsciiString str("ACos(");
str += Operand()->String();
str += ")";
return str;
}

61
src/Expr/Expr_ArcSine.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: ArcSine.cdl
-- Created: Mon Jan 14 16:16:14 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class ArcSine from Expr
inherits UnaryExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp : GeneralExpression)
---Purpose: Creates the Arcsin of <exp>
returns mutable ArcSine;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>.
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end ArcSine;

91
src/Expr/Expr_ArcSine.cxx Executable file
View File

@@ -0,0 +1,91 @@
//static const char* sccsid = "@(#)Expr_ArcSine.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_ArcSine.cxx
// Created: Mon May 27 11:31:25 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_ArcSine.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_Sine.hxx>
#include <Expr_Division.hxx>
#include <Expr_Square.hxx>
#include <Expr_Difference.hxx>
#include <Expr_SquareRoot.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_ArcSine::Expr_ArcSine (const Handle(Expr_GeneralExpression)& exp)
{
CreateOperand(exp);
}
Handle(Expr_GeneralExpression) Expr_ArcSine::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) op = Operand();
if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) valop = Handle(Expr_NumericValue)::DownCast(op);
return new Expr_NumericValue(ASin(valop->GetValue()));
}
if (op->IsKind(STANDARD_TYPE(Expr_Sine))) {
return op->SubExpression(1);
}
Handle(Expr_ArcSine) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_ArcSine::Copy () const
{
return new Expr_ArcSine(Expr::CopyShare(Operand()));
}
Standard_Boolean Expr_ArcSine::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (!Other->IsKind(STANDARD_TYPE(Expr_ArcSine))) {
return Standard_False;
}
Handle(Expr_GeneralExpression) op = Operand();
return op->IsIdentical(Other->SubExpression(1));
}
Standard_Boolean Expr_ArcSine::IsLinear () const
{
if (ContainsUnknowns()) {
return Standard_False;
}
return Standard_True;
}
Handle(Expr_GeneralExpression) Expr_ArcSine::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) op = Operand();
Handle(Expr_GeneralExpression) derop = op->Derivative(X);
Handle(Expr_Square) sq = new Expr_Square(Expr::CopyShare(op));
// 1 - X2
Handle(Expr_Difference) thedif = 1.0 - sq->ShallowSimplified();
// sqrt(1-X2)
Handle(Expr_SquareRoot) theroot = new Expr_SquareRoot(thedif->ShallowSimplified());
// ArcSine'(F(X)) = F'(X)/sqrt(1-F(X)2)
Handle(Expr_Division) thediv = derop / theroot->ShallowSimplified();
return thediv->ShallowSimplified();
}
Standard_Real Expr_ArcSine::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
return ::ASin(Operand()->Evaluate(vars,vals));
}
TCollection_AsciiString Expr_ArcSine::String() const
{
TCollection_AsciiString str("ASin(");
str += Operand()->String();
str += ")";
return str;
}

61
src/Expr/Expr_ArcTangent.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: ArcTangent.cdl
-- Created: Mon Jan 14 16:16:25 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class ArcTangent from Expr
inherits UnaryExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp : GeneralExpression)
---Purpose: Creates the Arctan of <exp>.
returns mutable ArcTangent;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>.
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end ArcTangent;

88
src/Expr/Expr_ArcTangent.cxx Executable file
View File

@@ -0,0 +1,88 @@
//static const char* sccsid = "@(#)Expr_ArcTangent.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_ArcTangent.cxx
// Created: Mon May 27 11:44:23 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_ArcTangent.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_Tangent.hxx>
#include <Expr_Division.hxx>
#include <Expr_Square.hxx>
#include <Expr_Sum.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_ArcTangent::Expr_ArcTangent (const Handle(Expr_GeneralExpression)& exp)
{
CreateOperand(exp);
}
Handle(Expr_GeneralExpression) Expr_ArcTangent::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) op = Operand();
if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) valop = Handle(Expr_NumericValue)::DownCast(op);
return new Expr_NumericValue(ATan(valop->GetValue()));
}
if (op->IsKind(STANDARD_TYPE(Expr_Tangent))) {
return op->SubExpression(1);
}
Handle(Expr_ArcTangent) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_ArcTangent::Copy () const
{
return new Expr_ArcTangent(Expr::CopyShare(Operand()));
}
Standard_Boolean Expr_ArcTangent::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (!Other->IsKind(STANDARD_TYPE(Expr_ArcTangent))) {
return Standard_False;
}
Handle(Expr_GeneralExpression) op = Operand();
return op->IsIdentical(Other->SubExpression(1));
}
Standard_Boolean Expr_ArcTangent::IsLinear () const
{
if (ContainsUnknowns()) {
return Standard_False;
}
return Standard_True;
}
Handle(Expr_GeneralExpression) Expr_ArcTangent::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) op = Operand();
Handle(Expr_GeneralExpression) derop = op->Derivative(X);
Handle(Expr_Square) sq = new Expr_Square(Expr::CopyShare(op));
// 1 + X2
Handle(Expr_Sum) thesum = 1.0 + sq->ShallowSimplified();
// ArcTangent'(F(X)) = F'(X)/(1+F(X)2)
Handle(Expr_Division) thediv = derop / thesum->ShallowSimplified();
return thediv->ShallowSimplified();
}
Standard_Real Expr_ArcTangent::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
return ::ATan(Operand()->Evaluate(vars,vals));
}
TCollection_AsciiString Expr_ArcTangent::String() const
{
TCollection_AsciiString str("ATan(");
str += Operand()->String();
str += ")";
return str;
}

61
src/Expr/Expr_ArgCosh.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: ArgCosh.cdl
-- Created: Mon Jan 14 16:16:34 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class ArgCosh from Expr
inherits UnaryExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp : GeneralExpression)
---Purpose: Creates the ArgCosh of <exp>
returns mutable ArgCosh;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>.
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end ArgCosh;

92
src/Expr/Expr_ArgCosh.cxx Executable file
View File

@@ -0,0 +1,92 @@
//static const char* sccsid = "@(#)Expr_ArgCosh.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_ArgCosh.cxx
// Created: Mon May 27 11:59:06 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_ArgCosh.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_Cosh.hxx>
#include <Expr_Division.hxx>
#include <Expr_Square.hxx>
#include <Expr_Difference.hxx>
#include <Expr_SquareRoot.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_ArgCosh::Expr_ArgCosh (const Handle(Expr_GeneralExpression)& exp)
{
CreateOperand(exp);
}
Handle(Expr_GeneralExpression) Expr_ArgCosh::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) op = Operand();
if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) valop = Handle(Expr_NumericValue)::DownCast(op);
return new Expr_NumericValue(ACosh(valop->GetValue()));
}
if (op->IsKind(STANDARD_TYPE(Expr_Cosh))) {
return op->SubExpression(1);
}
Handle(Expr_ArgCosh) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_ArgCosh::Copy () const
{
return new Expr_ArgCosh(Expr::CopyShare(Operand()));
}
Standard_Boolean Expr_ArgCosh::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (!Other->IsKind(STANDARD_TYPE(Expr_ArgCosh))) {
return Standard_False;
}
Handle(Expr_GeneralExpression) op = Operand();
return op->IsIdentical(Other->SubExpression(1));
}
Standard_Boolean Expr_ArgCosh::IsLinear () const
{
if (ContainsUnknowns()) {
return Standard_False;
}
return Standard_True;
}
Handle(Expr_GeneralExpression) Expr_ArgCosh::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) op = Operand();
Handle(Expr_GeneralExpression) derop = op->Derivative(X);
Handle(Expr_Square) sq = new Expr_Square(Expr::CopyShare(op));
// X2 - 1
Handle(Expr_Difference) thedif = sq->ShallowSimplified() - 1.0;
// sqrt(X2 - 1)
Handle(Expr_SquareRoot) theroot = new Expr_SquareRoot(thedif->ShallowSimplified());
// ArgCosh'(F(X)) = F'(X)/sqrt(F(X)2-1)
Handle(Expr_Division) thediv = derop / theroot->ShallowSimplified();
return thediv->ShallowSimplified();
}
Standard_Real Expr_ArgCosh::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
Standard_Real val = Operand()->Evaluate(vars,vals);
return ::Log(val + ::Sqrt(::Square(val)-1.0));
}
TCollection_AsciiString Expr_ArgCosh::String() const
{
TCollection_AsciiString str("ACosh(");
str += Operand()->String();
str += ")";
return str;
}

61
src/Expr/Expr_ArgSinh.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: ArgSinh.cdl
-- Created: Mon Jan 14 16:16:44 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class ArgSinh from Expr
inherits UnaryExpression from Expr
uses GeneralExpression from Expr,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
AsciiString from TCollection,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp : GeneralExpression)
---Purpose: Creates the ArgSinh of <exp>.
returns mutable ArgSinh;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>.
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end ArgSinh;

92
src/Expr/Expr_ArgSinh.cxx Executable file
View File

@@ -0,0 +1,92 @@
//static const char* sccsid = "@(#)Expr_ArgSinh.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_ArgSinh.cxx
// Created: Mon May 27 12:10:02 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_ArgSinh.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_Sinh.hxx>
#include <Expr_Division.hxx>
#include <Expr_Square.hxx>
#include <Expr_Sum.hxx>
#include <Expr_SquareRoot.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_ArgSinh::Expr_ArgSinh (const Handle(Expr_GeneralExpression)& exp)
{
CreateOperand(exp);
}
Handle(Expr_GeneralExpression) Expr_ArgSinh::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) op = Operand();
if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) valop = Handle(Expr_NumericValue)::DownCast(op);
return new Expr_NumericValue(ASinh(valop->GetValue()));
}
if (op->IsKind(STANDARD_TYPE(Expr_Sinh))) {
return op->SubExpression(1);
}
Handle(Expr_ArgSinh) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_ArgSinh::Copy () const
{
return new Expr_ArgSinh(Expr::CopyShare(Operand()));
}
Standard_Boolean Expr_ArgSinh::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (!Other->IsKind(STANDARD_TYPE(Expr_ArgSinh))) {
return Standard_False;
}
Handle(Expr_GeneralExpression) op = Operand();
return op->IsIdentical(Other->SubExpression(1));
}
Standard_Boolean Expr_ArgSinh::IsLinear () const
{
if (ContainsUnknowns()) {
return Standard_False;
}
return Standard_True;
}
Handle(Expr_GeneralExpression) Expr_ArgSinh::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) op = Operand();
Handle(Expr_GeneralExpression) derop = op->Derivative(X);
Handle(Expr_Square) sq = new Expr_Square(Expr::CopyShare(op));
// X2 + 1
Handle(Expr_Sum) thesum = sq->ShallowSimplified() + 1.0;
// sqrt(X2 + 1)
Handle(Expr_SquareRoot) theroot = new Expr_SquareRoot(thesum->ShallowSimplified());
// ArgSinh'(F(X)) = F'(X)/sqrt(F(X)2+1)
Handle(Expr_Division) thediv = derop / theroot->ShallowSimplified();
return thediv->ShallowSimplified();
}
Standard_Real Expr_ArgSinh::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
Standard_Real val = Operand()->Evaluate(vars,vals);
return ::Log(val + ::Sqrt(::Square(val)+1.0));
}
TCollection_AsciiString Expr_ArgSinh::String() const
{
TCollection_AsciiString str("ASinh(");
str += Operand()->String();
str += ")";
return str;
}

62
src/Expr/Expr_ArgTanh.cdl Executable file
View File

@@ -0,0 +1,62 @@
-- File: ArgTanh.cdl
-- Created: Mon Jan 14 16:16:25 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class ArgTanh from Expr
inherits UnaryExpression from Expr
uses GeneralExpression from Expr,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
AsciiString from TCollection,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp : GeneralExpression)
---Purpose: Creates the Argtanh of <exp>.
returns mutable ArgTanh;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>.
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end ArgTanh;

90
src/Expr/Expr_ArgTanh.cxx Executable file
View File

@@ -0,0 +1,90 @@
//static const char* sccsid = "@(#)Expr_ArgTanh.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_ArgTanh.cxx
// Created: Mon May 27 14:02:51 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_ArgTanh.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_Tanh.hxx>
#include <Expr_Division.hxx>
#include <Expr_Square.hxx>
#include <Expr_Difference.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_ArgTanh::Expr_ArgTanh (const Handle(Expr_GeneralExpression)& exp)
{
CreateOperand(exp);
}
Handle(Expr_GeneralExpression) Expr_ArgTanh::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) op = Operand();
if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) valop = Handle(Expr_NumericValue)::DownCast(op);
return new Expr_NumericValue(ATanh(valop->GetValue()));
}
if (op->IsKind(STANDARD_TYPE(Expr_Tanh))) {
return op->SubExpression(1);
}
Handle(Expr_ArgTanh) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_ArgTanh::Copy () const
{
return new Expr_ArgTanh(Expr::CopyShare(Operand()));
}
Standard_Boolean Expr_ArgTanh::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (!Other->IsKind(STANDARD_TYPE(Expr_ArgTanh))) {
return Standard_False;
}
Handle(Expr_GeneralExpression) op = Operand();
return op->IsIdentical(Other->SubExpression(1));
}
Standard_Boolean Expr_ArgTanh::IsLinear () const
{
if (ContainsUnknowns()) {
return Standard_False;
}
return Standard_True;
}
Handle(Expr_GeneralExpression) Expr_ArgTanh::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) op = Operand();
Handle(Expr_GeneralExpression) derop = op->Derivative(X);
Handle(Expr_Square) sq = new Expr_Square(Expr::CopyShare(op));
// 1 - X2
Handle(Expr_Difference) thedif = 1.0 - sq->ShallowSimplified();
// ArgTanh'(F(X)) = F'(X)/(1 - F(X)2)
Handle(Expr_Division) thediv = derop / thedif->ShallowSimplified();
return thediv->ShallowSimplified();
}
Standard_Real Expr_ArgTanh::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
Standard_Real val = Operand()->Evaluate(vars,vals);
return ::Log((1.0+val)/(1.0-val))/2.0;
}
TCollection_AsciiString Expr_ArgTanh::String() const
{
TCollection_AsciiString str("ATanh(");
str += Operand()->String();
str += ")";
return str;
}

View File

@@ -0,0 +1,102 @@
-- File: BinaryExpression.cdl
-- Created: Thu Jan 10 12:27:32 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
deferred class BinaryExpression from Expr
inherits GeneralExpression from Expr
---Purpose: Defines all binary expressions. The order of the two
-- operands is significant.
uses NamedUnknown from Expr
raises OutOfRange from Standard,
NumericError from Standard,
InvalidOperand from Expr
is
FirstOperand(me)
---C++: inline
---C++: return const &
---Level : Internal
returns any GeneralExpression
is static;
SecondOperand(me)
---C++: inline
---C++: return const &
---Level : Internal
returns any GeneralExpression
is static;
SetFirstOperand(me : mutable; exp : GeneralExpression)
---Purpose: Sets first operand of <me>
-- Raises InvalidOperand if exp = me
---Level : Internal
raises InvalidOperand
is static;
SetSecondOperand(me : mutable; exp : GeneralExpression)
---Purpose: Sets second operand of <me>
-- Raises InvalidOperand if <exp> contains <me>.
---Level : Internal
raises InvalidOperand
is static;
CreateFirstOperand(me : mutable; exp : GeneralExpression)
---Purpose: Sets first operand of <me>
---Level : Internal
is static protected;
CreateSecondOperand(me : mutable; exp : GeneralExpression)
---Purpose: Sets second operand of <me>
-- Raises InvalidOperand if <exp> contains <me>.
---Level : Internal
is static protected;
NbSubExpressions(me)
---Purpose: returns the number of sub-expressions contained
-- in <me> ( >= 0)
returns Integer
is static;
SubExpression(me; I : Integer)
---Purpose: returns the <I>-th sub-expression of <me>
-- raises OutOfRange if <I> > NbSubExpressions(me)
---C++: return const &
returns any GeneralExpression
raises OutOfRange
is static;
ContainsUnknowns(me)
---Purpose: Does <me> contain NamedUnknown ?
returns Boolean
is static;
Contains(me; exp : GeneralExpression)
---Purpose: Tests if <me> contains <exp>.
returns Boolean
is static;
Replace(me : mutable ; var : NamedUnknown ; with : GeneralExpression)
---Purpose: Replaces all occurences of <var> with <with> in <me>.
-- Raises InvalidOperand if <with> contains <me>.
raises InvalidOperand
is static;
Simplified(me)
---Purpose: Returns a GeneralExpression after replacement of
-- NamedUnknowns by an associated expression and after
-- values computation.
returns any GeneralExpression
raises NumericError;
fields
myFirstOperand : GeneralExpression;
mySecondOperand : GeneralExpression;
end BinaryExpression;

View File

@@ -0,0 +1,136 @@
//static const char* sccsid = "@(#)Expr_BinaryExpression.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_BinaryExpression.cxx
// Created: Fri Apr 12 10:41:21 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_BinaryExpression.ixx>
#include <Expr_NamedUnknown.hxx>
#include <Expr_InvalidOperand.hxx>
#include <Standard_OutOfRange.hxx>
void Expr_BinaryExpression::SetFirstOperand (const Handle(Expr_GeneralExpression)& exp)
{
Handle(Expr_BinaryExpression) me;
me = this;
if (exp == me) {
Expr_InvalidOperand::Raise();
}
if (exp->Contains(me)) {
Expr_InvalidOperand::Raise();
}
myFirstOperand = exp;
}
void Expr_BinaryExpression::SetSecondOperand (const Handle(Expr_GeneralExpression)& exp)
{
Handle(Expr_BinaryExpression) me;
me = this;
if (exp == me) {
Expr_InvalidOperand::Raise();
}
if (exp->Contains(me)) {
Expr_InvalidOperand::Raise();
}
mySecondOperand = exp;
}
void Expr_BinaryExpression::CreateFirstOperand (const Handle(Expr_GeneralExpression)& exp)
{
myFirstOperand = exp;
}
void Expr_BinaryExpression::CreateSecondOperand (const Handle(Expr_GeneralExpression)& exp)
{
mySecondOperand = exp;
}
Standard_Integer Expr_BinaryExpression::NbSubExpressions () const
{
return 2;
}
const Handle(Expr_GeneralExpression)& Expr_BinaryExpression::SubExpression (const Standard_Integer I) const
{
if (I == 1) {
return myFirstOperand;
}
else {
if (I == 2) {
return mySecondOperand;
}
else {
Standard_OutOfRange::Raise();
}
}
#if defined (WNT) || !defined (DEB)
return *( ( Handle_Expr_GeneralExpression* )NULL );
#endif // WNT || !DEB
}
Standard_Boolean Expr_BinaryExpression::ContainsUnknowns () const
{
if (myFirstOperand->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
return Standard_True;
}
if (mySecondOperand->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
return Standard_True;
}
if (myFirstOperand->ContainsUnknowns()) {
return Standard_True;
}
if (mySecondOperand->ContainsUnknowns()) {
return Standard_True;
}
return Standard_False;
}
Standard_Boolean Expr_BinaryExpression::Contains (const Handle(Expr_GeneralExpression)& exp) const
{
if (myFirstOperand == exp) {
return Standard_True;
}
if (mySecondOperand == exp) {
return Standard_True;
}
if (myFirstOperand->Contains(exp)) {
return Standard_True;
}
if (mySecondOperand->Contains(exp)) {
return Standard_True;
}
return Standard_False;
}
void Expr_BinaryExpression::Replace (const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with)
{
if (myFirstOperand == var) {
SetFirstOperand(with);
}
else {
if (myFirstOperand->Contains(var)) {
myFirstOperand->Replace(var,with);
}
}
if (mySecondOperand == var) {
SetSecondOperand(with);
}
else {
if (mySecondOperand->Contains(var)) {
mySecondOperand->Replace(var,with);
}
}
}
Handle(Expr_GeneralExpression) Expr_BinaryExpression::Simplified() const
{
Handle(Expr_BinaryExpression) cop = Handle(Expr_BinaryExpression)::DownCast(Copy());
Handle(Expr_GeneralExpression) op1 = cop->FirstOperand();
Handle(Expr_GeneralExpression) op2 = cop->SecondOperand();
cop->SetFirstOperand(op1->Simplified());
cop->SetSecondOperand(op2->Simplified());
return cop->ShallowSimplified();
}

View File

@@ -0,0 +1,16 @@
// Copyright: Matra-Datavision 1994
// File: Expr_BinaryExpression.lxx
// Created: Wed Jan 5 15:28:12 1994
// Author: Arnaud BOUZY
// <adn>
inline const Handle(Expr_GeneralExpression)& Expr_BinaryExpression::FirstOperand() const
{
return myFirstOperand;
}
inline const Handle(Expr_GeneralExpression)& Expr_BinaryExpression::SecondOperand () const
{
return mySecondOperand;
}

View File

@@ -0,0 +1,76 @@
-- File: BinaryFunction.cdl
-- Created: Mon Jan 14 16:20:04 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class BinaryFunction from Expr
inherits BinaryExpression from Expr
---Purpose: Defines the use of a binary function in an expression
-- with given arguments.
uses GeneralFunction from Expr,
AsciiString from TCollection,
GeneralExpression from Expr,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises InvalidFunction from Expr,
NumericError from Standard,
NotEvaluable from Expr
is
Create(func : GeneralFunction; exp1,exp2 : GeneralExpression)
---Purpose: Creates <me> as <func> (<exp1>,<exp2>).
-- Raises exception if <func> is not binary.
returns mutable BinaryFunction
raises InvalidFunction;
Function(me)
---Purpose: Returns the function defining <me>.
returns GeneralFunction;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
fields
myFunction : GeneralFunction;
end BinaryFunction;

148
src/Expr/Expr_BinaryFunction.cxx Executable file
View File

@@ -0,0 +1,148 @@
//static const char* sccsid = "@(#)Expr_BinaryFunction.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_BinaryFunction.cxx
// Created: Thu May 30 09:15:26 1991
// Author: Arnaud BOUZY
// <adn>
#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#endif
#include <Expr_BinaryFunction.ixx>
#include <Expr_InvalidFunction.hxx>
#include <Expr_Array1OfNamedUnknown.hxx>
#include <Expr_Array1OfGeneralExpression.hxx>
#include <Expr_FunctionDerivative.hxx>
#include <Expr_Product.hxx>
#include <Expr_Sum.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_BinaryFunction::Expr_BinaryFunction (const Handle(Expr_GeneralFunction)& func, const Handle(Expr_GeneralExpression)& exp1, const Handle(Expr_GeneralExpression)& exp2)
{
if (func->NbOfVariables() != 2) {
Expr_InvalidFunction::Raise();
}
myFunction = func;
CreateFirstOperand(exp1);
CreateSecondOperand(exp2);
}
Handle(Expr_GeneralExpression) Expr_BinaryFunction::ShallowSimplified () const
{
if (FirstOperand()->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
if (SecondOperand()->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
TColStd_Array1OfReal tabval(1,2);
tabval(1) = Handle(Expr_NumericValue)::DownCast(FirstOperand())->GetValue();
tabval(2) = Handle(Expr_NumericValue)::DownCast(SecondOperand())->GetValue();
Expr_Array1OfNamedUnknown vars(1,2);
vars(1) = myFunction->Variable(1);
vars(2) = myFunction->Variable(2);
Standard_Real res = myFunction->Evaluate(vars,tabval);
return new Expr_NumericValue(res);
}
}
Handle(Expr_BinaryFunction) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_BinaryFunction::Copy () const
{
return new Expr_BinaryFunction(myFunction,
Expr::CopyShare(FirstOperand()),
Expr::CopyShare(SecondOperand()));
}
Standard_Boolean Expr_BinaryFunction::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (!Other->IsKind(STANDARD_TYPE(Expr_BinaryFunction))) {
return Standard_False;
}
Handle(Expr_BinaryFunction) fother = Handle(Expr_BinaryFunction)::DownCast(Other);
Handle(Expr_GeneralExpression) otherexp = fother->FirstOperand();
if (otherexp->IsIdentical(FirstOperand())) {
otherexp = fother->SecondOperand();
if (otherexp->IsIdentical(SecondOperand())) {
if (myFunction->IsIdentical(fother->Function())) {
return Standard_True;
}
}
}
return Standard_False;
}
Standard_Boolean Expr_BinaryFunction::IsLinear () const
{
if (!ContainsUnknowns()) {
return Standard_True;
}
if (!FirstOperand()->IsLinear()) {
return Standard_False;
}
if (!SecondOperand()->IsLinear()) {
return Standard_False;
}
if (!myFunction->IsLinearOnVariable(1)) {
return Standard_False;
}
return myFunction->IsLinearOnVariable(2);
}
Handle(Expr_GeneralExpression) Expr_BinaryFunction::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
Handle(Expr_NamedUnknown) myvar1 = myFunction->Variable(1);
Handle(Expr_NamedUnknown) myvar2 = myFunction->Variable(2);
Handle(Expr_GeneralExpression) myfop = FirstOperand();
Handle(Expr_GeneralExpression) mysop = SecondOperand();
Handle(Expr_GeneralExpression) myexpder1 = myfop->Derivative(X);
Handle(Expr_GeneralExpression) myexpder2 = mysop->Derivative(X);
Handle(Expr_GeneralFunction) myfuncder1 = myFunction->Derivative(myvar1);
Handle(Expr_BinaryFunction) firstpart
= new Expr_BinaryFunction(myfuncder1,
Expr::CopyShare(myfop),
Expr::CopyShare(mysop));
Handle(Expr_GeneralExpression) fpart = firstpart->ShallowSimplified() * myexpder1;
Handle(Expr_GeneralFunction) myfuncder2 = myFunction->Derivative(myvar2);
Handle(Expr_BinaryFunction) secondpart
= new Expr_BinaryFunction(myfuncder2,
Expr::CopyShare(myfop),
Expr::CopyShare(mysop));
Handle(Expr_GeneralExpression) spart = secondpart->ShallowSimplified() * myexpder2;
fpart = fpart->ShallowSimplified();
spart = spart->ShallowSimplified();
return (fpart + spart)->ShallowSimplified();
}
Handle(Expr_GeneralFunction) Expr_BinaryFunction::Function () const
{
return myFunction;
}
Standard_Real Expr_BinaryFunction::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
Expr_Array1OfNamedUnknown varsfunc(1,2);
varsfunc(1) = myFunction->Variable(1);
varsfunc(2) = myFunction->Variable(2);
TColStd_Array1OfReal valsfunc(1,2);
valsfunc(1) = FirstOperand()->Evaluate(vars,vals);
valsfunc(2) = SecondOperand()->Evaluate(vars,vals);
return myFunction->Evaluate(varsfunc,valsfunc);
}
TCollection_AsciiString Expr_BinaryFunction::String() const
{
TCollection_AsciiString res = myFunction->GetStringName();
res += TCollection_AsciiString('(');
res += FirstOperand()->String();
res += ",";
res += SecondOperand()->String();
res += ")";
return res;
}

61
src/Expr/Expr_Cosh.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: Cosh.cdl
-- Created: Mon Jan 14 16:16:54 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class Cosh from Expr
inherits UnaryExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp : GeneralExpression)
---Purpose: Creates the Cosh of <exp>
returns mutable Cosh;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>.
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end Cosh;

79
src/Expr/Expr_Cosh.cxx Executable file
View File

@@ -0,0 +1,79 @@
//static const char* sccsid = "@(#)Expr_Cosh.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_Cosh.cxx
// Created: Mon May 27 15:43:41 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_Cosh.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_ArgCosh.hxx>
#include <Expr_Sinh.hxx>
#include <Expr_Product.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_Cosh::Expr_Cosh(const Handle(Expr_GeneralExpression)& exp)
{
CreateOperand(exp);
}
Handle(Expr_GeneralExpression) Expr_Cosh::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) myexp = Operand();
if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp);
return new Expr_NumericValue(Cosh(myNVexp->GetValue()));
}
if (myexp->IsKind(STANDARD_TYPE(Expr_ArgCosh))) {
return myexp->SubExpression(1);
}
Handle(Expr_Cosh) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_Cosh::Copy () const
{
return new Expr_Cosh(Expr::CopyShare(Operand()));
}
Standard_Boolean Expr_Cosh::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (Other->IsKind(STANDARD_TYPE(Expr_Cosh))) {
Handle(Expr_GeneralExpression) myexp = Operand();
return myexp->IsIdentical(Other->SubExpression(1));
}
return Standard_False;
}
Standard_Boolean Expr_Cosh::IsLinear () const
{
return !ContainsUnknowns();
}
Handle(Expr_GeneralExpression) Expr_Cosh::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) myexp = Operand();
Handle(Expr_GeneralExpression) myder = myexp->Derivative(X);
Handle(Expr_Sinh) firstder = new Expr_Sinh(Expr::CopyShare(myexp));
Handle(Expr_Product) resu = firstder->ShallowSimplified() * myder;
return resu->ShallowSimplified();
}
Standard_Real Expr_Cosh::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
Standard_Real val = Operand()->Evaluate(vars,vals);
return (::Exp(val)+::Exp(-val))/2.0;
}
TCollection_AsciiString Expr_Cosh::String() const
{
TCollection_AsciiString str("Cosh(");
str += Operand()->String();
str += ")";
return str;
}

61
src/Expr/Expr_Cosine.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: Cosine.cdl
-- Created: Mon Jan 14 16:17:02 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class Cosine from Expr
inherits UnaryExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(Exp : GeneralExpression)
---Purpose: Creates the cosine of Exp
returns mutable Cosine;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end Cosine;

79
src/Expr/Expr_Cosine.cxx Executable file
View File

@@ -0,0 +1,79 @@
//static const char* sccsid = "@(#)Expr_Cosine.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_Cosine.cxx
// Created: Mon May 27 17:24:38 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_Cosine.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_ArcCosine.hxx>
#include <Expr_Sine.hxx>
#include <Expr_UnaryMinus.hxx>
#include <Expr_Product.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_Cosine::Expr_Cosine(const Handle(Expr_GeneralExpression)& exp)
{
CreateOperand(exp);
}
Handle(Expr_GeneralExpression) Expr_Cosine::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) myexp = Operand();
if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp);
return new Expr_NumericValue(Cos(myNVexp->GetValue()));
}
if (myexp->IsKind(STANDARD_TYPE(Expr_ArcCosine))) {
return myexp->SubExpression(1);
}
Handle(Expr_Cosine) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_Cosine::Copy () const
{
return new Expr_Cosine(Expr::CopyShare(Operand()));
}
Standard_Boolean Expr_Cosine::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (Other->IsKind(STANDARD_TYPE(Expr_Cosine))) {
Handle(Expr_GeneralExpression) myexp = Operand();
return myexp->IsIdentical(Other->SubExpression(1));
}
return Standard_False;
}
Standard_Boolean Expr_Cosine::IsLinear () const
{
return !ContainsUnknowns();
}
Handle(Expr_GeneralExpression) Expr_Cosine::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) myexp = Operand();
Handle(Expr_GeneralExpression) myder = myexp->Derivative(X);
Handle(Expr_Sine) firstder = new Expr_Sine(Expr::CopyShare(myexp));
Handle(Expr_UnaryMinus) fder = - (firstder->ShallowSimplified());
Handle(Expr_Product) resu = fder->ShallowSimplified() * myder;
return resu->ShallowSimplified();
}
Standard_Real Expr_Cosine::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
return ::Cos(Operand()->Evaluate(vars,vals));
}
TCollection_AsciiString Expr_Cosine::String() const
{
TCollection_AsciiString str("Cos(");
str += Operand()->String();
str += ")";
return str;
}

69
src/Expr/Expr_Difference.cdl Executable file
View File

@@ -0,0 +1,69 @@
-- File: Difference.cdl
-- Created: Mon Jan 14 16:20:15 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class Difference from Expr
inherits BinaryExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises OutOfRange from Standard,
NumericError from Standard,
NotEvaluable from Expr
is
Create(exp1,exp2 : GeneralExpression)
---Purpose: Creates the difference <exp1> - <exp2>.
returns mutable Difference;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>
returns any GeneralExpression;
NDerivative(me; X : NamedUnknown; N : Integer)
---Purpose: Returns the <N>-th derivative on <X> unknown of <me>.
-- Raises OutOfRange if <N> <= 0
returns any GeneralExpression
raises OutOfRange
is redefined;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end Difference;

166
src/Expr/Expr_Difference.cxx Executable file
View File

@@ -0,0 +1,166 @@
//static const char* sccsid = "@(#)Expr_Difference.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_Difference.cxx
// Created: Wed Apr 17 09:32:02 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_Difference.ixx>
#include <Expr_UnaryMinus.hxx>
#include <Expr_NumericValue.hxx>
#include <Expr_Sum.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
#include <Standard_OutOfRange.hxx>
Expr_Difference::Expr_Difference (const Handle(Expr_GeneralExpression)& exp1, const Handle(Expr_GeneralExpression)& exp2)
{
CreateFirstOperand(exp1);
CreateSecondOperand(exp2);
}
Handle(Expr_GeneralExpression) Expr_Difference::ShallowSimplified() const
{
Handle(Expr_GeneralExpression) myfirst = FirstOperand();
Handle(Expr_GeneralExpression) mysecond = SecondOperand();
Standard_Boolean nvfirst = myfirst->IsKind(STANDARD_TYPE(Expr_NumericValue));
Standard_Boolean nvsecond = mysecond->IsKind(STANDARD_TYPE(Expr_NumericValue));
if (nvfirst && nvsecond) {
// case num1 - num2
Handle(Expr_NumericValue) myNVfirst = Handle(Expr_NumericValue)::DownCast(myfirst);
Handle(Expr_NumericValue) myNVsecond = Handle(Expr_NumericValue)::DownCast(mysecond);
return new Expr_NumericValue(myNVfirst->GetValue()-myNVsecond->GetValue());
}
if (nvfirst && !nvsecond) {
// case num1 - X2
Handle(Expr_NumericValue) myNVfirst = Handle(Expr_NumericValue)::DownCast(myfirst);
if (myNVfirst->GetValue() == 0.0) {
// case 0 - X2
return - mysecond;
}
}
if (!nvfirst && nvsecond) {
// case X1 - num2
Handle(Expr_NumericValue) myNVsecond = Handle(Expr_NumericValue)::DownCast(mysecond);
if (myNVsecond->GetValue() == 0.0) {
// case X1 - 0
return myfirst;
}
}
// Treat UnaryMinus case
Standard_Boolean unfirst = myfirst->IsKind(STANDARD_TYPE(Expr_UnaryMinus));
Standard_Boolean unsecond = mysecond->IsKind(STANDARD_TYPE(Expr_UnaryMinus));
if (unfirst && unsecond) {
// case (-ssX1) - (-ssX2) = ssX2 - ssX1
Handle(Expr_GeneralExpression) ssop1 = myfirst->SubExpression(1);
Handle(Expr_GeneralExpression) ssop2 = mysecond->SubExpression(1);
return ssop2 - ssop1;
}
if (unfirst && !unsecond) {
// case (-ssX1) - X2 = -( ssX1 + X2)
Handle(Expr_GeneralExpression) ssop1 = myfirst->SubExpression(1);
return -(ssop1 + mysecond);
}
if (!unfirst && unsecond) {
// case X1 - (-ssX2) = X1 + ssX2
Handle(Expr_GeneralExpression) ssop2 = mysecond->SubExpression(1);
return myfirst + ssop2;
}
Handle(Expr_Difference) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_Difference::Copy () const
{
return Expr::CopyShare(FirstOperand()) - Expr::CopyShare(SecondOperand());
}
Standard_Boolean Expr_Difference::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
Standard_Boolean ident = Standard_False;
if (Other->IsKind(STANDARD_TYPE(Expr_Difference))) {
Handle(Expr_GeneralExpression) myfirst = FirstOperand();
Handle(Expr_GeneralExpression) mysecond = SecondOperand();
Handle(Expr_Difference) DOther = Handle(Expr_Difference)::DownCast(Other);
Handle(Expr_GeneralExpression) fother = DOther->FirstOperand();
Handle(Expr_GeneralExpression) sother = DOther->SecondOperand();
if ((myfirst->IsIdentical(fother)) &&
(mysecond->IsIdentical(sother))) {
ident = Standard_True;
}
}
return ident;
}
Standard_Boolean Expr_Difference::IsLinear () const
{
Handle(Expr_GeneralExpression) myfirst = FirstOperand();
Handle(Expr_GeneralExpression) mysecond = SecondOperand();
return (myfirst->IsLinear() && mysecond->IsLinear());
}
Handle(Expr_GeneralExpression) Expr_Difference::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) myfirst = FirstOperand();
Handle(Expr_GeneralExpression) mysecond = SecondOperand();
myfirst = myfirst->Derivative(X);
mysecond = mysecond->Derivative(X);
Handle(Expr_Difference) der = myfirst - mysecond;
return der->ShallowSimplified();
}
Handle(Expr_GeneralExpression) Expr_Difference::NDerivative (const Handle(Expr_NamedUnknown)& X, const Standard_Integer N) const
{
if (N <= 0) {
Standard_OutOfRange::Raise();
}
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) myfirst = FirstOperand();
Handle(Expr_GeneralExpression) mysecond = SecondOperand();
myfirst = myfirst->NDerivative(X,N);
mysecond = mysecond->NDerivative(X,N);
Handle(Expr_Difference) der = myfirst - mysecond;
return der->ShallowSimplified();
}
Standard_Real Expr_Difference::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
Standard_Real res = FirstOperand()->Evaluate(vars,vals);
return res - SecondOperand()->Evaluate(vars,vals);
}
TCollection_AsciiString Expr_Difference::String() const
{
Handle(Expr_GeneralExpression) op1 = FirstOperand();
Handle(Expr_GeneralExpression) op2 = SecondOperand();
TCollection_AsciiString str;
if (op1->NbSubExpressions() > 1) {
str += "(";
str += op1->String();
str += ")";
}
else {
str = op1->String();
}
str += "-";
if (op2->NbSubExpressions() > 1) {
str += "(";
str += op2->String();
str += ")";
}
else {
str += op2->String();
}
return str;
}

47
src/Expr/Expr_Different.cdl Executable file
View File

@@ -0,0 +1,47 @@
-- File: Different.cdl
-- Created: Mon Jan 14 09:58:05 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class Different from Expr
inherits SingleRelation from Expr
uses GeneralExpression from Expr,
GeneralRelation from Expr,
AsciiString from TCollection
raises NumericError from Standard
is
Create(exp1 : GeneralExpression ; exp2 : GeneralExpression)
---Purpose: Creates the relation <exp1> # <exp2>.
returns mutable Different;
IsSatisfied(me)
returns Boolean;
Simplified(me)
---Purpose: Returns a GeneralRelation after replacement of
-- NamedUnknowns by an associated expression, and after
-- values computation.
returns mutable GeneralRelation
raises NumericError;
Simplify(me : mutable)
---Purpose: Replaces NamedUnknowns by associated expressions,
-- and computes values in <me>.
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and
-- functions.
returns mutable like me;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end Different;

52
src/Expr/Expr_Different.cxx Executable file
View File

@@ -0,0 +1,52 @@
//static const char* sccsid = "@(#)Expr_Different.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_Different.cxx
// Created: Mon Jun 10 17:50:47 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_Different.ixx>
#include <Expr.hxx>
#include <Expr_GeneralExpression.hxx>
Expr_Different::Expr_Different (const Handle(Expr_GeneralExpression)& exp1, const Handle(Expr_GeneralExpression)& exp2)
{
SetFirstMember(exp1);
SetSecondMember(exp2);
}
Standard_Boolean Expr_Different::IsSatisfied () const
{
Handle(Expr_GeneralExpression) fm = FirstMember();
Handle(Expr_GeneralExpression) sm = SecondMember();
fm = fm->Simplified();
sm = sm->Simplified();
return (!fm->IsIdentical(sm));
}
Handle(Expr_GeneralRelation) Expr_Different::Simplified () const
{
Handle(Expr_GeneralExpression) fm = FirstMember();
Handle(Expr_GeneralExpression) sm = SecondMember();
return new Expr_Different(fm->Simplified(),sm->Simplified());
}
void Expr_Different::Simplify ()
{
Handle(Expr_GeneralExpression) fm = FirstMember();
Handle(Expr_GeneralExpression) sm = SecondMember();
SetFirstMember(fm->Simplified());
SetSecondMember(sm->Simplified());
}
Handle(Expr_GeneralRelation) Expr_Different::Copy () const
{
return new Expr_Different(Expr::CopyShare(FirstMember()),
Expr::CopyShare(SecondMember()));
}
TCollection_AsciiString Expr_Different::String() const
{
return FirstMember()->String() + " <> " + SecondMember()->String();
}

61
src/Expr/Expr_Division.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: Division.cdl
-- Created: Mon Jan 14 16:20:23 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class Division from Expr
inherits BinaryExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp1,exp2 : GeneralExpression)
---Purpose: Creates the division <exp1>/<exp2>
returns mutable Division;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>.
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end Division;

147
src/Expr/Expr_Division.cxx Executable file
View File

@@ -0,0 +1,147 @@
//static const char* sccsid = "@(#)Expr_Division.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_Division.cxx
// Created: Wed Apr 17 14:14:22 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_Division.ixx>
#include <Expr_Product.hxx>
#include <Expr_Square.hxx>
#include <Expr_UnaryMinus.hxx>
#include <Expr_Difference.hxx>
#include <Expr_NumericValue.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_Division::Expr_Division (const Handle(Expr_GeneralExpression)& exp1, const Handle(Expr_GeneralExpression)& exp2)
{
CreateFirstOperand(exp1);
CreateSecondOperand(exp2);
}
Handle(Expr_GeneralExpression) Expr_Division::Copy () const
{
return Expr::CopyShare(FirstOperand()) / Expr::CopyShare(SecondOperand());
}
Standard_Boolean Expr_Division::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
Standard_Boolean ident = Standard_False;
if (Other->IsKind(STANDARD_TYPE(Expr_Division))) {
Handle(Expr_GeneralExpression) myfirst = FirstOperand();
Handle(Expr_GeneralExpression) mysecond = SecondOperand();
Handle(Expr_Division) DOther = Handle(Expr_Division)::DownCast(Other);
Handle(Expr_GeneralExpression) fother = DOther->FirstOperand();
Handle(Expr_GeneralExpression) sother = DOther->SecondOperand();
if (myfirst->IsIdentical(fother) &&
mysecond->IsIdentical(sother)) {
ident = Standard_True;
}
}
return ident;
}
Standard_Boolean Expr_Division::IsLinear () const
{
Handle(Expr_GeneralExpression) myfirst = FirstOperand();
Handle(Expr_GeneralExpression) mysecond = SecondOperand();
if (mysecond->IsKind(STANDARD_TYPE(Expr_NamedUnknown)) || mysecond->ContainsUnknowns()) {
return Standard_False;
}
return (myfirst->IsLinear() && mysecond->IsLinear());
}
Handle(Expr_GeneralExpression) Expr_Division::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) myfirst = FirstOperand();
Handle(Expr_GeneralExpression) mysecond = SecondOperand();
Handle(Expr_GeneralExpression) myfder = myfirst->Derivative(X);
Handle(Expr_GeneralExpression) mysder = mysecond->Derivative(X);
// "u'v"
Handle(Expr_Product) firstprod = myfder * Expr::CopyShare(mysecond);
Handle(Expr_GeneralExpression) firstsimp = firstprod->ShallowSimplified();
// "uv'"
Handle(Expr_Product) secondprod = Expr::CopyShare(myfirst) * mysder;
Handle(Expr_GeneralExpression) secondsimp = secondprod->ShallowSimplified();
// "u'v - uv'"
Handle(Expr_Difference) mynumer = firstsimp - secondsimp;
// " v2"
Handle(Expr_Square) mydenom = new Expr_Square(Expr::CopyShare(mysecond));
// result = "u'v-uv' / v2"
Handle(Expr_GeneralExpression) snumer = mynumer->ShallowSimplified();
Handle(Expr_GeneralExpression) sdenom = mydenom->ShallowSimplified();
Handle(Expr_Division) result = snumer / sdenom;
return result->ShallowSimplified();
}
Handle(Expr_GeneralExpression) Expr_Division::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) myfirst = FirstOperand();
Handle(Expr_GeneralExpression) mysecond = SecondOperand();
if (myfirst->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) myNVfirst = Handle(Expr_NumericValue)::DownCast(myfirst);
if (myNVfirst->GetValue() == 0.0) {
// case 0/X2
return new Expr_NumericValue(0.0);
}
if (mysecond->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
// case num1/num2
Handle(Expr_NumericValue) myNVsecond = Handle(Expr_NumericValue)::DownCast(mysecond);
return new Expr_NumericValue(myNVfirst->GetValue()/myNVsecond->GetValue());
}
}
else {
if (mysecond->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
// case X1/num2
Handle(Expr_NumericValue) myNVsecond = Handle(Expr_NumericValue)::DownCast(mysecond);
if (myNVsecond->GetValue() == 1.0) {
// case X1/1
return myfirst;
}
}
}
Handle(Expr_Division) me = this;
return me;
}
Standard_Real Expr_Division::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
Standard_Real res = FirstOperand()->Evaluate(vars,vals);
return res / SecondOperand()->Evaluate(vars,vals);
}
TCollection_AsciiString Expr_Division::String() const
{
Handle(Expr_GeneralExpression) op1 = FirstOperand();
Handle(Expr_GeneralExpression) op2 = SecondOperand();
TCollection_AsciiString str;
if (op1->NbSubExpressions() > 1) {
str = "(";
str += op1->String();
str += ")";
}
else {
str = op1->String();
}
str += "/";
if (op2->NbSubExpressions() > 1) {
str += "(";
str += op2->String();
str += ")";
}
else {
str += op2->String();
}
return str;
}

46
src/Expr/Expr_Equal.cdl Executable file
View File

@@ -0,0 +1,46 @@
-- File: Equal.cdl
-- Created: Mon Jan 14 09:54:44 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class Equal from Expr
inherits SingleRelation from Expr
uses GeneralExpression from Expr,
GeneralRelation from Expr,
AsciiString from TCollection
raises NumericError from Standard
is
Create(exp1 : GeneralExpression ; exp2 : GeneralExpression)
---Purpose: Creates the relation <exp1> = <exp2>.
returns mutable Equal;
IsSatisfied(me)
returns Boolean;
Simplified(me)
---Purpose: returns a GeneralRelation after replacement of
-- NamedUnknowns by an associated expression and after
-- values computation.
returns mutable GeneralRelation
raises NumericError;
Simplify(me : mutable)
---Purpose: Replaces NamedUnknowns by an associated expressions
-- and computes values in <me>.
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end Equal;

51
src/Expr/Expr_Equal.cxx Executable file
View File

@@ -0,0 +1,51 @@
//static const char* sccsid = "@(#)Expr_Equal.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_Equal.cxx
// Created: Mon Jun 10 18:02:49 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_Equal.ixx>
#include <Expr.hxx>
#include <Expr_GeneralExpression.hxx>
Expr_Equal::Expr_Equal (const Handle(Expr_GeneralExpression)& exp1, const Handle(Expr_GeneralExpression)& exp2)
{
SetFirstMember(exp1);
SetSecondMember(exp2);
}
Standard_Boolean Expr_Equal::IsSatisfied () const
{
Handle(Expr_GeneralExpression) fm = FirstMember();
Handle(Expr_GeneralExpression) sm = SecondMember();
fm = fm->Simplified();
sm = sm->Simplified();
return (fm->IsIdentical(sm));
}
Handle(Expr_GeneralRelation) Expr_Equal::Simplified () const
{
Handle(Expr_GeneralExpression) fm = FirstMember();
Handle(Expr_GeneralExpression) sm = SecondMember();
return new Expr_Equal(fm->Simplified(),sm->Simplified());
}
void Expr_Equal::Simplify ()
{
Handle(Expr_GeneralExpression) fm = FirstMember();
Handle(Expr_GeneralExpression) sm = SecondMember();
SetFirstMember(fm->Simplified());
SetSecondMember(sm->Simplified());
}
Handle(Expr_GeneralRelation) Expr_Equal::Copy () const
{
return new Expr_Equal(Expr::CopyShare(FirstMember()),
Expr::CopyShare(SecondMember()));
}
TCollection_AsciiString Expr_Equal::String() const
{
return FirstMember()->String() + " = " + SecondMember()->String();
}

61
src/Expr/Expr_Exponential.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: Exponential.cdl
-- Created: Mon Jan 14 16:17:22 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class Exponential from Expr
inherits UnaryExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp : GeneralExpression)
---Purpose: Creates the exponential of <exp>
returns mutable Exponential;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>.
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end Exponential;

75
src/Expr/Expr_Exponential.cxx Executable file
View File

@@ -0,0 +1,75 @@
//static const char* sccsid = "@(#)Expr_Exponential.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_Exponential.cxx
// Created: Mon May 27 17:30:32 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_Exponential.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_LogOfe.hxx>
#include <Expr_Product.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_Exponential::Expr_Exponential(const Handle(Expr_GeneralExpression)& exp)
{
CreateOperand(exp);
}
Handle(Expr_GeneralExpression) Expr_Exponential::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) myexp = Operand();
if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp);
return new Expr_NumericValue(Exp(myNVexp->GetValue()));
}
if (myexp->IsKind(STANDARD_TYPE(Expr_LogOfe))) {
return myexp->SubExpression(1);
}
Handle(Expr_Exponential) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_Exponential::Copy () const
{
return new Expr_Exponential(Expr::CopyShare(Operand()));
}
Standard_Boolean Expr_Exponential::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (Other->IsKind(STANDARD_TYPE(Expr_Exponential))) {
Handle(Expr_GeneralExpression) myexp = Operand();
return myexp->IsIdentical(Other->SubExpression(1));
}
return Standard_False;
}
Standard_Boolean Expr_Exponential::IsLinear () const
{
return !ContainsUnknowns();
}
Handle(Expr_GeneralExpression) Expr_Exponential::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) myexp = Operand();
Handle(Expr_GeneralExpression) myder = myexp->Derivative(X);
Handle(Expr_Product) resu = Expr::CopyShare(this) * myder;
return resu->ShallowSimplified();
}
Standard_Real Expr_Exponential::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
return ::Exp(Operand()->Evaluate(vars,vals));
}
TCollection_AsciiString Expr_Exponential::String() const
{
TCollection_AsciiString str("Exp(");
str += Operand()->String();
str += ")";
return str;
}

61
src/Expr/Expr_Exponentiate.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: Exponentiate.cdl
-- Created: Mon Jan 14 16:19:26 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class Exponentiate from Expr
inherits BinaryExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp1,exp2 : GeneralExpression)
---Purpose: Creates the exponential <exp1> ^ <exp2>
returns mutable Exponentiate;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>.
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end Exponentiate;

154
src/Expr/Expr_Exponentiate.cxx Executable file
View File

@@ -0,0 +1,154 @@
//static const char* sccsid = "@(#)Expr_Exponentiate.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_Exponentiate.cxx
// Created: Thu May 30 16:44:30 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_Exponentiate.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_SequenceOfGeneralExpression.hxx>
#include <Expr_Difference.hxx>
#include <Expr_Product.hxx>
#include <Expr_LogOfe.hxx>
#include <Expr_Sum.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_Exponentiate::Expr_Exponentiate (const Handle(Expr_GeneralExpression)& exp1, const Handle(Expr_GeneralExpression)& exp2)
{
CreateFirstOperand(exp1);
CreateSecondOperand(exp2);
}
Handle(Expr_GeneralExpression) Expr_Exponentiate::ShallowSimplified() const
{
Handle(Expr_GeneralExpression) myfirst = FirstOperand();
Handle(Expr_GeneralExpression) mysecond = SecondOperand();
if (mysecond->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) myNVs = Handle(Expr_NumericValue)::DownCast(mysecond);
Standard_Real myvals = myNVs->GetValue();
if (myvals == 0.0) {
// case X ** 0
return new Expr_NumericValue(1.0);
}
if (myvals == 1.0) {
// case X ** 1
return myfirst;
}
if (myfirst->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) myNVf = Handle(Expr_NumericValue)::DownCast(myfirst);
return new Expr_NumericValue(Pow(myNVf->GetValue(),myvals));
}
}
if (myfirst->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) myNVf = Handle(Expr_NumericValue)::DownCast(myfirst);
Standard_Real myValf = myNVf->GetValue();
if (myValf == 1.0) {
return myNVf;
}
}
Handle(Expr_Exponentiate) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_Exponentiate::Copy () const
{
return new Expr_Exponentiate(Expr::CopyShare(FirstOperand()),
Expr::CopyShare(SecondOperand()));
}
Standard_Boolean Expr_Exponentiate::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
Standard_Boolean ident = Standard_False;
if (Other->IsKind(STANDARD_TYPE(Expr_Exponentiate))) {
Handle(Expr_GeneralExpression) myfirst = FirstOperand();
Handle(Expr_GeneralExpression) mysecond = SecondOperand();
if (myfirst->IsIdentical(Other->SubExpression(1))) {
if (mysecond->IsIdentical(Other->SubExpression(2))) {
ident = Standard_True;
}
}
}
return ident;
}
Standard_Boolean Expr_Exponentiate::IsLinear () const
{
return !ContainsUnknowns();
}
Handle(Expr_GeneralExpression) Expr_Exponentiate::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
// Derivate of h(X) ** g(X) is :
// h(X) * (g(X) ** (h(X)-1)) * g'(X) +
// (g(X) ** h(X)) * Log(g(X)) * h'(X)
Handle(Expr_GeneralExpression) myfirst = FirstOperand();
Handle(Expr_GeneralExpression) mysecond = SecondOperand();
Handle(Expr_GeneralExpression) myfder = myfirst->Derivative(X);
Handle(Expr_GeneralExpression) mysder = mysecond->Derivative(X);
Expr_SequenceOfGeneralExpression prod1;
prod1.Append(Expr::CopyShare(mysecond)); // h(X)
Handle(Expr_Difference) difh1 = Expr::CopyShare(mysecond) - 1.0; // h(X)-1
Handle(Expr_Exponentiate) exp1 = new Expr_Exponentiate(Expr::CopyShare(myfirst),difh1->ShallowSimplified());
prod1.Append(exp1->ShallowSimplified()); // g(X) ** (h(X)-1)
prod1.Append(myfder); // g'(X)
Handle(Expr_Product) firstmember = new Expr_Product(prod1);
Expr_SequenceOfGeneralExpression prod2;
Handle(Expr_Exponentiate) exp2 = new Expr_Exponentiate(Expr::CopyShare(myfirst),Expr::CopyShare(mysecond));
prod2.Append(exp2->ShallowSimplified()); // g(X) ** h(X)
Handle(Expr_LogOfe) log = new Expr_LogOfe(Expr::CopyShare(myfirst));
prod2.Append(log->ShallowSimplified()); // Log(g(X))
prod2.Append(mysder); // h'(X)
Handle(Expr_Product) secondmember = new Expr_Product(prod2);
Handle(Expr_Sum) resu = firstmember->ShallowSimplified() + secondmember->ShallowSimplified();
return resu->ShallowSimplified();
}
Standard_Real Expr_Exponentiate::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
Standard_Real res = FirstOperand()->Evaluate(vars,vals);
return ::Pow(res,SecondOperand()->Evaluate(vars,vals));
}
TCollection_AsciiString Expr_Exponentiate::String() const
{
Handle(Expr_GeneralExpression) op1 = FirstOperand();
Handle(Expr_GeneralExpression) op2 = SecondOperand();
TCollection_AsciiString str;
if (op1->NbSubExpressions() > 1) {
str = "(";
str += op1->String();
str += ")";
}
else {
str = op1->String();
}
str += "^";
if (op2->NbSubExpressions() > 1) {
str += "(";
str += op2->String();
str += ")";
}
else {
str += op2->String();
}
return str;
}

View File

@@ -0,0 +1,115 @@
-- File: FunctionDerivative.cdl
-- Created: Mon Jan 14 10:53:24 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991, 1992
class FunctionDerivative from Expr
inherits GeneralFunction from Expr
uses NamedUnknown from Expr,
GeneralExpression from Expr,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
AsciiString from TCollection
raises OutOfRange from Standard,
DimensionMismatch from Standard,
NumericError from Standard,
NotEvaluable from Expr
is
Create(func : GeneralFunction; withX : NamedUnknown; deg : Integer)
---Purpose: Creates a FunctionDerivative of degree <deg> relative
-- to the <withX> variable.
-- Raises OutOfRange if <deg> lower or equal to zero.
---Level : Advanced
returns mutable FunctionDerivative
raises OutOfRange;
NbOfVariables(me)
---Purpose: Returns the number of variables of <me>.
returns Integer;
Variable(me; index : Integer)
---Purpose: Returns the variable denoted by <index> in <me>.
-- Raises OutOfRange if <index> greater than
-- NbOfVariables of <me>.
returns NamedUnknown
raises OutOfRange;
Evaluate(me; vars : Array1OfNamedUnknown;
values : Array1OfReal)
---Purpose: Computes the value of <me> with the given variables.
-- Raises DimensionMismatch if Length(vars) is different from
-- Length(values).
returns Real
raises DimensionMismatch, NumericError,NotEvaluable;
Copy(me)
---Purpose: Returns a copy of <me> with the same form.
returns mutable like me;
Derivative(me; var : NamedUnknown)
---Purpose: Returns Derivative of <me> for variable <var>.
returns GeneralFunction;
Derivative(me; var : NamedUnknown; deg : Integer)
---Purpose: Returns Derivative of <me> for variable <var> with
-- degree <deg>.
returns GeneralFunction;
IsIdentical(me; func : GeneralFunction)
---Purpose: Tests if <me> and <func> are similar functions (same
-- name and same used expression).
returns Boolean;
IsLinearOnVariable(me; index : Integer)
---Purpose: Tests if <me> is linear on variable on range <index>
returns Boolean;
Function(me)
---Purpose: Returns the function of which <me> is the derivative.
---Level : Internal
returns GeneralFunction
is static;
Degree(me)
---Purpose: Returns the degree of derivation of <me>.
---Level : Internal
returns Integer
is static;
DerivVariable(me)
---Purpose: Returns the derivation variable of <me>.
---Level : Internal
returns NamedUnknown
is static;
GetStringName(me)
returns AsciiString;
Expression(me)
returns GeneralExpression
---Level : Internal
is static;
UpdateExpression(me: mutable);
---Level : Internal
fields
myFunction : GeneralFunction;
myExp : GeneralExpression;
myDerivate : NamedUnknown;
myDegree : Integer;
friends
class NamedFunction from Expr
end FunctionDerivative;

View File

@@ -0,0 +1,150 @@
//static const char* sccsid = "@(#)Expr_FunctionDerivative.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_FunctionDerivative.cxx
// Created: Thu Jun 27 09:40:36 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_FunctionDerivative.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_NamedFunction.hxx>
#include <Standard_OutOfRange.hxx>
#include <Standard_NotImplemented.hxx>
Expr_FunctionDerivative::Expr_FunctionDerivative (const Handle(Expr_GeneralFunction)& func, const Handle(Expr_NamedUnknown)& withX, const Standard_Integer deg)
{
myFunction = func;
myDerivate = withX;
if (deg <= 0) {
Standard_OutOfRange::Raise();
}
myDegree = deg;
UpdateExpression();
}
Standard_Integer Expr_FunctionDerivative::NbOfVariables () const
{
return myFunction->NbOfVariables();
}
Handle(Expr_NamedUnknown) Expr_FunctionDerivative::Variable (const Standard_Integer index) const
{
return myFunction->Variable(index);
}
Standard_Real Expr_FunctionDerivative::Evaluate (const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& values) const
{
if (vars.Length() != values.Length()) {
Standard_OutOfRange::Raise();
}
return myExp->Evaluate(vars,values);
}
Handle(Expr_GeneralFunction) Expr_FunctionDerivative::Copy () const
{
return new Expr_FunctionDerivative(myFunction->Copy(),myDerivate,myDegree);
}
Handle(Expr_GeneralFunction) Expr_FunctionDerivative::Derivative(const Handle(Expr_NamedUnknown)& var) const
{
return Derivative(var,1);
}
Handle(Expr_GeneralFunction) Expr_FunctionDerivative::Derivative(const Handle(Expr_NamedUnknown)& var, const Standard_Integer deg) const
{
if (var == myDerivate) {
return new Expr_FunctionDerivative(myFunction,var,myDegree+deg);
}
Handle(Expr_FunctionDerivative) me = this;
return new Expr_FunctionDerivative(me,var,deg);
}
Standard_Boolean Expr_FunctionDerivative::IsIdentical (const Handle(Expr_GeneralFunction)& func) const
{
if (!func->IsKind(STANDARD_TYPE(Expr_FunctionDerivative))) {
return Standard_False;
}
Handle(Expr_FunctionDerivative) dfunc = Handle(Expr_FunctionDerivative)::DownCast(func);
if (myDegree != dfunc->Degree()) {
return Standard_False;
}
if (!myDerivate->IsIdentical(dfunc->DerivVariable())) {
return Standard_False;
}
if (!myFunction->IsIdentical(dfunc->Function())) {
return Standard_False;
}
return Standard_True;
}
Standard_Boolean Expr_FunctionDerivative::IsLinearOnVariable(const Standard_Integer) const
{
// should be improved
return myExp->IsLinear();
}
Handle(Expr_GeneralFunction) Expr_FunctionDerivative::Function () const
{
return myFunction;
}
Standard_Integer Expr_FunctionDerivative::Degree () const
{
return myDegree;
}
Handle(Expr_NamedUnknown) Expr_FunctionDerivative::DerivVariable () const
{
return myDerivate;
}
TCollection_AsciiString Expr_FunctionDerivative::GetStringName() const
{
TCollection_AsciiString res;
if (NbOfVariables() ==1) {
res = myFunction->GetStringName();
char c = 39;
TCollection_AsciiString diff(myDegree,c);
res += diff;
return res;
}
TCollection_AsciiString diff("@");
if (myDegree > 1) {
TCollection_AsciiString deg(myDegree);
diff += deg;
}
res = diff;
res += myFunction->GetStringName();
res += "/";
Standard_Integer index=0;
for (Standard_Integer i=1; (i<= NbOfVariables()) && (index ==0) ; i++) {
if (Variable(i) == myDerivate) {
index =i;
}
}
res += diff;
res += "X";
TCollection_AsciiString rank(index);
res += rank;
return res;
}
Handle(Expr_GeneralExpression) Expr_FunctionDerivative::Expression() const
{
return myExp;
}
void Expr_FunctionDerivative::UpdateExpression()
{
if (myFunction->IsKind(STANDARD_TYPE(Expr_FunctionDerivative))) {
Handle(Expr_FunctionDerivative) defunc = Handle(Expr_FunctionDerivative)::DownCast(myFunction);
defunc->UpdateExpression();
myExp = defunc->Expression()->NDerivative(myDerivate,myDegree);
}
else {
Handle(Expr_NamedFunction) nafunc = Handle(Expr_NamedFunction)::DownCast(myFunction);
myExp = nafunc->Expression()->NDerivative(myDerivate,myDegree);
}
}

View File

@@ -0,0 +1,148 @@
-- File: GeneralExpression.cdl
-- Created: Thu Jan 10 11:57:22 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
deferred class GeneralExpression from Expr
inherits TShared from MMgt
---Purpose: Defines the general purposes of any expression.
uses NamedUnknown from Expr,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
AsciiString from TCollection
raises OutOfRange from Standard,
NumericError from Standard,
NotEvaluable from Expr,
InvalidOperand from Expr
is
NbSubExpressions(me)
---Purpose: Returns the number of sub-expressions contained
-- in <me> ( >= 0)
---Level: Internal
returns Integer
is deferred;
SubExpression(me; I : Integer)
---Purpose: Returns the <I>-th sub-expression of <me>
-- raises OutOfRange if <I> > NbSubExpressions(me)
---C++: return const &
---Level: Internal
returns any GeneralExpression
raises OutOfRange
is deferred;
Simplified(me)
---Purpose: Returns a GeneralExpression after replacement of
-- NamedUnknowns by an associated expression and after
-- values computation.
---Level: Advanced
returns any GeneralExpression
raises NumericError
is deferred;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
---Level: Internal
returns any GeneralExpression
raises NumericError
is deferred;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and
-- functions.
---Level: Advanced
returns mutable like me
is deferred;
ContainsUnknowns(me)
---Purpose: Tests if <me> contains NamedUnknowns.
---Level: Advanced
returns Boolean
is deferred;
Contains(me; exp : GeneralExpression)
---Purpose: Tests if <exp> is contained in <me>.
---Level: Advanced
returns Boolean
is deferred;
IsLinear(me)
---Purpose: Tests if <me> is linear on every NamedUnknown it
-- contains.
---Level: Internal
returns Boolean
is deferred;
IsShareable(me)
---Purpose: Tests if <me> can be shared by one or more expressions
-- or must be copied. This method returns False as a
-- default value. To be redefined ( especially for
-- NamedUnknown).
---Level: Internal
returns Boolean is virtual;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- Warning: This method does not include any simplification before
-- testing. It could also be very slow; to be used
-- carefully.
---Level: Internal
returns Boolean
is deferred;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>
---Level: Advanced
returns any GeneralExpression
is deferred;
NDerivative(me; X : NamedUnknown; N : Integer)
---Purpose: Returns the <N>-th derivative on <X> unknown of <me>.
-- Raise OutOfRange if N <= 0
---Level: Advanced
returns any GeneralExpression
raises OutOfRange is virtual;
Replace(me : mutable ; var : NamedUnknown ; with : GeneralExpression)
---Purpose: Replaces all occurences of <var> with copies of <with>
-- in <me>. Copies of <with> are made with the Copy() method.
-- Raises InvalidOperand if <with> contains <me>.
---Level: Internal
raises InvalidOperand
is deferred;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
---Level: Advanced
returns Real
raises NotEvaluable,NumericError
is deferred;
EvaluateNumeric(me)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
---Level: Internal
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
---Level: Public
returns AsciiString
is deferred;
end GeneralExpression;

View File

@@ -0,0 +1,39 @@
//static const char* sccsid = "@(#)Expr_GeneralExpression.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_GeneralExpression.cxx
// Created: Wed Mar 6 11:04:58 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_GeneralExpression.ixx>
#include <Expr_NotEvaluable.hxx>
#include <Standard_OutOfRange.hxx>
Standard_Boolean Expr_GeneralExpression::IsShareable() const
{
return Standard_False;
}
Handle(Expr_GeneralExpression) Expr_GeneralExpression::NDerivative (const Handle(Expr_NamedUnknown)& X, const Standard_Integer N) const
{
if (N <= 0) {
Standard_OutOfRange::Raise();
}
Handle(Expr_GeneralExpression) first = Derivative(X);
if (N > 1) {
return first->NDerivative(X,N-1);
}
return first;
}
Standard_Real Expr_GeneralExpression::EvaluateNumeric() const
{
if (ContainsUnknowns()) {
Expr_NotEvaluable::Raise();
}
Expr_Array1OfNamedUnknown tabvr(1,1);
TColStd_Array1OfReal tabvl(1,1);
return Evaluate(tabvr,tabvl);
}

View File

@@ -0,0 +1,88 @@
-- File: GeneralFunction.cdl
-- Created: Mon Jan 14 10:48:27 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
deferred class GeneralFunction from Expr
inherits TShared from MMgt
---Purpose: Defines the general purposes of any function.
uses NamedUnknown from Expr,
GeneralExpression from Expr,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
AsciiString from TCollection
raises OutOfRange from Standard,
DimensionMismatch from Standard,
NumericError from Standard,
NotEvaluable from Expr
is
NbOfVariables(me)
---Purpose: Returns the number of variables of <me>.
---Level: Advanced
returns Integer
is deferred;
Variable(me ; index : Integer)
---Purpose: Returns the variable denoted by <index> in <me>.
-- Raises OutOfRange if index > NbOfVariables.
---Level: Advanced
returns NamedUnknown
raises OutOfRange
is deferred;
Copy(me)
---Purpose: Returns a copy of <me> with the same form.
---Level: Advanced
returns mutable like me
is deferred;
Derivative(me; var : NamedUnknown)
---Purpose: Returns Derivative of <me> for variable <var>.
---Level: Advanced
returns GeneralFunction
is deferred;
Derivative(me; var : NamedUnknown; deg : Integer)
---Purpose: Returns Derivative of <me> for variable <var> with
-- degree <deg>.
---Level: Advanced
returns GeneralFunction
is deferred;
Evaluate(me; vars : Array1OfNamedUnknown;
vals : Array1OfReal)
---Purpose: Computes the value of <me> with the given variables.
-- Raises NotEvaluable if <vars> does not match all variables
-- of <me>.
---Level: Advanced
returns Real
raises NotEvaluable,NumericError,DimensionMismatch
is deferred;
IsIdentical(me; func : GeneralFunction)
---Purpose: Tests if <me> and <func> are similar functions (same
-- name and same used expression).
---Level: Internal
returns Boolean
is deferred;
IsLinearOnVariable(me; index : Integer)
---Purpose: Tests if <me> is linear on variable on range <index>
---Level: Internal
returns Boolean
is deferred;
GetStringName(me)
---Level: Internal
returns AsciiString
is deferred;
end GeneralFunction;

View File

@@ -0,0 +1,9 @@
//static const char* sccsid = "@(#)Expr_GeneralFunction.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_GeneralFunction.cxx
// Created: Wed Jun 26 11:43:26 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_GeneralFunction.ixx>

View File

@@ -0,0 +1,97 @@
-- File: GeneralRelation.cdl
-- Created: Mon Jan 14 09:44:03 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
deferred class GeneralRelation from Expr
inherits TShared from MMgt
---Purpose: Defines the general purposes of any relation between
-- expressions.
uses GeneralExpression from Expr,
NamedUnknown from Expr,
AsciiString from TCollection
raises OutOfRange from Standard,
NumericError from Standard
is
IsSatisfied(me)
---Purpose: Returns the current status of the relation
---Level: Advanced
returns Boolean
is deferred;
IsLinear(me)
---Purpose: Tests if <me> is linear between its NamedUnknowns.
---Level: Advanced
returns Boolean
is deferred;
Simplified(me)
---Purpose: Returns a GeneralRelation after replacement of
-- NamedUnknowns by an associated expression, and after
-- values computation.
---Level: Advanced
returns mutable GeneralRelation
raises NumericError
is deferred;
Simplify(me : mutable)
---Purpose: Replaces NamedUnknowns by associated expressions,
-- and computes values in <me>.
---Level: Advanced
raises NumericError
is deferred;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and
-- functions.
---Level: Advanced
returns mutable like me
is deferred;
NbOfSubRelations(me)
---Purpose: Returns the number of relations contained in <me>.
---Level: Internal
returns Integer
is deferred;
NbOfSingleRelations(me)
---Purpose: Returns the number of SingleRelations contained in
-- <me>.
---Level: Internal
returns Integer
is deferred;
SubRelation(me; index : Integer)
---Purpose: Returns the relation denoted by <index> in <me>.
-- An exception is raised if <index> is out of range.
---Level: Internal
returns any GeneralRelation
raises OutOfRange
is deferred;
Contains(me; exp : GeneralExpression)
---Purpose: Tests if <exp> contains <var>.
---Level: Internal
returns Boolean
is deferred;
Replace(me : mutable ; var : NamedUnknown ; with : GeneralExpression)
---Purpose: Replaces all occurences of <var> with <with> in <me>.
---Level: Internal
is deferred;
String(me)
---Purpose: returns a string representing <me> in a readable way.
---Level: Public
returns AsciiString
is deferred;
end GeneralRelation;

View File

@@ -0,0 +1,9 @@
//static const char* sccsid = "@(#)Expr_GeneralRelation.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_GeneralRelation.cxx
// Created: Mon Jun 10 17:09:09 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_GeneralRelation.ixx>

46
src/Expr/Expr_GreaterThan.cdl Executable file
View File

@@ -0,0 +1,46 @@
-- File: GreaterThan.cdl
-- Created: Mon Jan 14 09:56:16 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class GreaterThan from Expr
inherits SingleRelation from Expr
uses GeneralExpression from Expr,
GeneralRelation from Expr,
AsciiString from TCollection
raises NumericError from Standard
is
Create(exp1 : GeneralExpression ; exp2 : GeneralExpression)
---Purpose: Creates the relation <exp1> > <exp2>.
returns mutable GreaterThan;
IsSatisfied(me)
returns Boolean;
Simplified(me)
---Purpose: Returns a GeneralRelation after replacement of
-- NamedUnknowns by an associated expression, and after
-- values computation.
returns mutable GeneralRelation
raises NumericError;
Simplify(me : mutable)
---Purpose: Replaces NamedUnknowns by associated expressions,
-- and computes values in <me>.
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end GreaterThan;

58
src/Expr/Expr_GreaterThan.cxx Executable file
View File

@@ -0,0 +1,58 @@
//static const char* sccsid = "@(#)Expr_GreaterThan.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_GreaterThan.cxx
// Created: Thu Jun 13 10:20:34 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_GreaterThan.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr.hxx>
Expr_GreaterThan::Expr_GreaterThan (const Handle(Expr_GeneralExpression)& exp1, const Handle(Expr_GeneralExpression)& exp2)
{
SetFirstMember(exp1);
SetSecondMember(exp2);
}
Standard_Boolean Expr_GreaterThan::IsSatisfied () const
{
Handle(Expr_GeneralExpression) fm = FirstMember();
Handle(Expr_GeneralExpression) sm = SecondMember();
fm = fm->Simplified();
sm = sm->Simplified();
if (fm->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
if (sm->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) nfm = Handle(Expr_NumericValue)::DownCast(fm);
Handle(Expr_NumericValue) nsm = Handle(Expr_NumericValue)::DownCast(sm);
return (nfm->GetValue() > nsm->GetValue());
}
}
return Standard_False;
}
Handle(Expr_GeneralRelation) Expr_GreaterThan::Simplified () const
{
Handle(Expr_GeneralExpression) fm = FirstMember();
Handle(Expr_GeneralExpression) sm = SecondMember();
return new Expr_GreaterThan(fm->Simplified(),sm->Simplified());
}
void Expr_GreaterThan::Simplify ()
{
Handle(Expr_GeneralExpression) fm = FirstMember();
Handle(Expr_GeneralExpression) sm = SecondMember();
SetFirstMember(fm->Simplified());
SetSecondMember(sm->Simplified());
}
Handle(Expr_GeneralRelation) Expr_GreaterThan::Copy () const
{
return new Expr_GreaterThan(Expr::CopyShare(FirstMember()),
Expr::CopyShare(SecondMember()));
}
TCollection_AsciiString Expr_GreaterThan::String() const
{
return FirstMember()->String() + " > " + SecondMember()->String();
}

View File

@@ -0,0 +1,46 @@
-- File: GreaterThanOrEqual.cdl
-- Created: Wed Jan 30 09:55:51 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class GreaterThanOrEqual from Expr
inherits SingleRelation from Expr
uses GeneralExpression from Expr,
GeneralRelation from Expr,
AsciiString from TCollection
raises NumericError from Standard
is
Create(exp1 : GeneralExpression ; exp2 : GeneralExpression)
---Purpose: Creates the relation <exp1> >= <exp2>.
returns mutable GreaterThanOrEqual;
IsSatisfied(me)
returns Boolean;
Simplified(me)
---Purpose: Returns a GeneralRelation after replacement of
-- NamedUnknowns by an associated expression, and after
-- values computation.
returns mutable GeneralRelation
raises NumericError;
Simplify(me : mutable)
---Purpose: Replaces NamedUnknowns by associated expressions,
-- and computes values in <me>.
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end GreaterThanOrEqual;

View File

@@ -0,0 +1,58 @@
//static const char* sccsid = "@(#)Expr_GreaterThanOrEqual.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_GreaterThanOrEqual.cxx
// Created: Thu Jun 13 13:48:41 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_GreaterThanOrEqual.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr.hxx>
Expr_GreaterThanOrEqual::Expr_GreaterThanOrEqual (const Handle(Expr_GeneralExpression)& exp1, const Handle(Expr_GeneralExpression)& exp2)
{
SetFirstMember(exp1);
SetSecondMember(exp2);
}
Standard_Boolean Expr_GreaterThanOrEqual::IsSatisfied () const
{
Handle(Expr_GeneralExpression) fm = FirstMember();
Handle(Expr_GeneralExpression) sm = SecondMember();
fm = fm->Simplified();
sm = sm->Simplified();
if (fm->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
if (sm->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) nfm = Handle(Expr_NumericValue)::DownCast(fm);
Handle(Expr_NumericValue) nsm = Handle(Expr_NumericValue)::DownCast(sm);
return (nfm->GetValue() >= nsm->GetValue());
}
}
return Standard_False;
}
Handle(Expr_GeneralRelation) Expr_GreaterThanOrEqual::Simplified () const
{
Handle(Expr_GeneralExpression) fm = FirstMember();
Handle(Expr_GeneralExpression) sm = SecondMember();
return new Expr_GreaterThanOrEqual(fm->Simplified(),sm->Simplified());
}
void Expr_GreaterThanOrEqual::Simplify ()
{
Handle(Expr_GeneralExpression) fm = FirstMember();
Handle(Expr_GeneralExpression) sm = SecondMember();
SetFirstMember(fm->Simplified());
SetSecondMember(sm->Simplified());
}
Handle(Expr_GeneralRelation) Expr_GreaterThanOrEqual::Copy () const
{
return new Expr_GreaterThanOrEqual(Expr::CopyShare(FirstMember()),
Expr::CopyShare(SecondMember()));
}
TCollection_AsciiString Expr_GreaterThanOrEqual::String() const
{
return FirstMember()->String() + " >= " + SecondMember()->String();
}

46
src/Expr/Expr_LessThan.cdl Executable file
View File

@@ -0,0 +1,46 @@
-- File: LessThan.cdl
-- Created: Wed Jan 30 09:56:59 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class LessThan from Expr
inherits SingleRelation from Expr
uses GeneralExpression from Expr,
GeneralRelation from Expr,
AsciiString from TCollection
raises NumericError from Standard
is
Create(exp1 : GeneralExpression ; exp2 : GeneralExpression)
---Purpose: Creates the relation <exp1> < <exp2>.
returns mutable LessThan;
IsSatisfied(me)
returns Boolean;
Simplified(me)
---Purpose: Returns a GeneralRelation after replacement of
-- NamedUnknowns by an associated expression, and after
-- values computation.
returns mutable GeneralRelation
raises NumericError;
Simplify(me : mutable)
---Purpose: Replaces NamedUnknowns by associated expressions,
-- and computes values in <me>.
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end LessThan;

58
src/Expr/Expr_LessThan.cxx Executable file
View File

@@ -0,0 +1,58 @@
//static const char* sccsid = "@(#)Expr_LessThan.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_LessThan.cxx
// Created: Thu Jun 13 13:50:04 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_LessThan.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr.hxx>
Expr_LessThan::Expr_LessThan (const Handle(Expr_GeneralExpression)& exp1, const Handle(Expr_GeneralExpression)& exp2)
{
SetFirstMember(exp1);
SetSecondMember(exp2);
}
Standard_Boolean Expr_LessThan::IsSatisfied () const
{
Handle(Expr_GeneralExpression) fm = FirstMember();
Handle(Expr_GeneralExpression) sm = SecondMember();
fm = fm->Simplified();
sm = sm->Simplified();
if (fm->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
if (sm->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) nfm = Handle(Expr_NumericValue)::DownCast(fm);
Handle(Expr_NumericValue) nsm = Handle(Expr_NumericValue)::DownCast(sm);
return (nfm->GetValue() < nsm->GetValue());
}
}
return Standard_False;
}
Handle(Expr_GeneralRelation) Expr_LessThan::Simplified () const
{
Handle(Expr_GeneralExpression) fm = FirstMember();
Handle(Expr_GeneralExpression) sm = SecondMember();
return new Expr_LessThan(fm->Simplified(),sm->Simplified());
}
void Expr_LessThan::Simplify ()
{
Handle(Expr_GeneralExpression) fm = FirstMember();
Handle(Expr_GeneralExpression) sm = SecondMember();
SetFirstMember(fm->Simplified());
SetSecondMember(sm->Simplified());
}
Handle(Expr_GeneralRelation) Expr_LessThan::Copy () const
{
return new Expr_LessThan(Expr::CopyShare(FirstMember()),
Expr::CopyShare(SecondMember()));
}
TCollection_AsciiString Expr_LessThan::String() const
{
return FirstMember()->String() + " < " + SecondMember()->String();
}

View File

@@ -0,0 +1,46 @@
-- File: LessThanOrEqual.cdl
-- Created: Mon Jan 14 09:58:31 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class LessThanOrEqual from Expr
inherits SingleRelation from Expr
uses GeneralExpression from Expr,
GeneralRelation from Expr,
AsciiString from TCollection
raises NumericError from Standard
is
Create(exp1 : GeneralExpression ; exp2 : GeneralExpression)
---Purpose: Creates the relation <exp1> <= <exp2>.
returns mutable LessThanOrEqual;
IsSatisfied(me)
returns Boolean;
Simplified(me)
---Purpose: Returns a GeneralRelation after replacement of
-- NamedUnknowns by an associated expression, and after
-- values computation.
returns mutable GeneralRelation
raises NumericError;
Simplify(me : mutable)
---Purpose: Replaces NamedUnknowns by associated expressions,
-- and computes values in <me>.
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end LessThanOrEqual;

View File

@@ -0,0 +1,58 @@
//static const char* sccsid = "@(#)Expr_LessThanOrEqual.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_LessThanOrEqual.cxx
// Created: Thu Jun 13 13:51:12 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_LessThanOrEqual.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr.hxx>
Expr_LessThanOrEqual::Expr_LessThanOrEqual (const Handle(Expr_GeneralExpression)& exp1, const Handle(Expr_GeneralExpression)& exp2)
{
SetFirstMember(exp1);
SetSecondMember(exp2);
}
Standard_Boolean Expr_LessThanOrEqual::IsSatisfied () const
{
Handle(Expr_GeneralExpression) fm = FirstMember();
Handle(Expr_GeneralExpression) sm = SecondMember();
fm = fm->Simplified();
sm = sm->Simplified();
if (fm->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
if (sm->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) nfm = Handle(Expr_NumericValue)::DownCast(fm);
Handle(Expr_NumericValue) nsm = Handle(Expr_NumericValue)::DownCast(sm);
return (nfm->GetValue() <= nsm->GetValue());
}
}
return Standard_False;
}
Handle(Expr_GeneralRelation) Expr_LessThanOrEqual::Simplified () const
{
Handle(Expr_GeneralExpression) fm = FirstMember();
Handle(Expr_GeneralExpression) sm = SecondMember();
return new Expr_LessThanOrEqual(fm->Simplified(),sm->Simplified());
}
void Expr_LessThanOrEqual::Simplify ()
{
Handle(Expr_GeneralExpression) fm = FirstMember();
Handle(Expr_GeneralExpression) sm = SecondMember();
SetFirstMember(fm->Simplified());
SetSecondMember(sm->Simplified());
}
Handle(Expr_GeneralRelation) Expr_LessThanOrEqual::Copy () const
{
return new Expr_LessThanOrEqual(Expr::CopyShare(FirstMember()),
Expr::CopyShare(SecondMember()));
}
TCollection_AsciiString Expr_LessThanOrEqual::String() const
{
return FirstMember()->String() + " <= " + SecondMember()->String();
}

61
src/Expr/Expr_LogOf10.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: LogOf10.cdl
-- Created: Mon Jan 14 16:17:31 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class LogOf10 from Expr
inherits UnaryExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp : GeneralExpression)
---Purpose: Creates the base 10 logarithm of <exp>
returns mutable LogOf10;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>.
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end LogOf10;

75
src/Expr/Expr_LogOf10.cxx Executable file
View File

@@ -0,0 +1,75 @@
//static const char* sccsid = "@(#)Expr_LogOf10.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_LogOf10.cxx
// Created: Mon May 27 17:48:44 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_LogOf10.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_Division.hxx>
#include <Expr_Product.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_LogOf10::Expr_LogOf10(const Handle(Expr_GeneralExpression)& exp)
{
CreateOperand(exp);
}
Handle(Expr_GeneralExpression) Expr_LogOf10::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) myexp = Operand();
if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp);
return new Expr_NumericValue(Log10(myNVexp->GetValue()));
}
Handle(Expr_LogOf10) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_LogOf10::Copy () const
{
return new Expr_LogOf10(Expr::CopyShare(Operand()));
}
Standard_Boolean Expr_LogOf10::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (Other->IsKind(STANDARD_TYPE(Expr_LogOf10))) {
Handle(Expr_GeneralExpression) myexp = Operand();
return myexp->IsIdentical(Other->SubExpression(1));
}
return Standard_False;
}
Standard_Boolean Expr_LogOf10::IsLinear () const
{
return !ContainsUnknowns();
}
Handle(Expr_GeneralExpression) Expr_LogOf10::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) myexp = Operand();
Handle(Expr_GeneralExpression) myder = myexp->Derivative(X);
Standard_Real vlog = Log(10.0);
Handle(Expr_NumericValue) vallog = new Expr_NumericValue(vlog);
Handle(Expr_Product) theprod = Expr::CopyShare(myexp) * vallog;
Handle(Expr_Division) thediv = myder / theprod->ShallowSimplified();
return thediv->ShallowSimplified();
}
Standard_Real Expr_LogOf10::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
return ::Log10(Operand()->Evaluate(vars,vals));
}
TCollection_AsciiString Expr_LogOf10::String() const
{
TCollection_AsciiString str("log(");
str += Operand()->String();
str += ")";
return str;
}

61
src/Expr/Expr_LogOfe.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: LogOfe.cdl
-- Created: Mon Jan 14 16:17:41 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class LogOfe from Expr
inherits UnaryExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp : GeneralExpression)
---Purpose: Creates the natural logarithm of <exp>
returns mutable LogOfe;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>.
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end LogOfe;

75
src/Expr/Expr_LogOfe.cxx Executable file
View File

@@ -0,0 +1,75 @@
//static const char* sccsid = "@(#)Expr_LogOfe.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_LogOfe.cxx
// Created: Tue May 28 12:33:48 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_LogOfe.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_Division.hxx>
#include <Expr_Exponential.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_LogOfe::Expr_LogOfe(const Handle(Expr_GeneralExpression)& exp)
{
CreateOperand(exp);
}
Handle(Expr_GeneralExpression) Expr_LogOfe::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) myexp = Operand();
if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp);
return new Expr_NumericValue(Log(myNVexp->GetValue()));
}
if (myexp->IsKind(STANDARD_TYPE(Expr_Exponential))) {
return myexp->SubExpression(1);
}
Handle(Expr_LogOfe) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_LogOfe::Copy () const
{
return new Expr_LogOfe(Expr::CopyShare(Operand()));
}
Standard_Boolean Expr_LogOfe::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (Other->IsKind(STANDARD_TYPE(Expr_LogOfe))) {
Handle(Expr_GeneralExpression) myexp = Operand();
return myexp->IsIdentical(Other->SubExpression(1));
}
return Standard_False;
}
Standard_Boolean Expr_LogOfe::IsLinear () const
{
return !ContainsUnknowns();
}
Handle(Expr_GeneralExpression) Expr_LogOfe::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) myexp = Operand();
Handle(Expr_GeneralExpression) myder = myexp->Derivative(X);
Handle(Expr_Division) thediv = myder / Expr::CopyShare(myexp);
return thediv->ShallowSimplified();
}
Standard_Real Expr_LogOfe::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
return ::Log(Operand()->Evaluate(vars,vals));
}
TCollection_AsciiString Expr_LogOfe::String() const
{
TCollection_AsciiString str("Ln(");
str += Operand()->String();
str += ")";
return str;
}

99
src/Expr/Expr_NamedConstant.cdl Executable file
View File

@@ -0,0 +1,99 @@
-- File: NamedConstant.cdl
-- Created: Thu Jan 10 12:07:34 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991, 1992
class NamedConstant from Expr
inherits NamedExpression from Expr
---Purpose: Describes any numeric constant known by a special name
-- (as PI, e,...).
uses NamedUnknown from Expr,
GeneralExpression from Expr,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
AsciiString from TCollection
raises OutOfRange from Standard
is
Create(name : AsciiString; value : Real)
---Purpose: Creates a constant value of name <name> and value <value>.
returns mutable NamedConstant;
GetValue(me)
---C++: inline
returns Real
is static;
NbSubExpressions(me)
---Purpose: returns the number of sub-expressions contained
-- in <me> (always returns zero)
returns Integer
is static;
SubExpression(me; I : Integer)
---Purpose: returns the <I>-th sub-expression of <me>
-- raises OutOfRange
---C++: return const &
returns any GeneralExpression
raises OutOfRange
is static;
Simplified(me)
---Purpose: returns a GeneralExpression after replacement of
-- NamedUnknowns by an associated expression and after
-- values computation.
returns any GeneralExpression ;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
ContainsUnknowns(me)
---Purpose: Tests if <me> contains NamedUnknown.
-- (returns always False)
returns Boolean;
Contains(me; exp : GeneralExpression)
---Purpose: Tests if <exp> is contained in <me>.
returns Boolean
is static;
IsLinear(me)
returns Boolean
is static;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>
returns any GeneralExpression;
NDerivative(me; X : NamedUnknown; N : Integer)
---Purpose: Returns the <N>-th derivative on <X> unknown of <me>.
-- Raises OutOfRange if <N> <= 0
returns any GeneralExpression
raises OutOfRange
is redefined;
Replace(me : mutable ; var : NamedUnknown ; with : GeneralExpression);
---Purpose: Replaces all occurences of <var> with <with> in <me>
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
returns Real;
fields
myValue : Real;
end NamedConstant;

81
src/Expr/Expr_NamedConstant.cxx Executable file
View File

@@ -0,0 +1,81 @@
//static const char* sccsid = "@(#)Expr_NamedConstant.cxx 3.3 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_NamedConstant.cxx
// Created: Fri Apr 12 10:41:21 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_NamedConstant.ixx>
#include <Expr_NumericValue.hxx>
#include <Standard_OutOfRange.hxx>
Expr_NamedConstant::Expr_NamedConstant(const TCollection_AsciiString& name, const Standard_Real value)
{
SetName(name);
myValue = value;
}
const Handle(Expr_GeneralExpression)& Expr_NamedConstant::SubExpression (const Standard_Integer ) const
{
Standard_OutOfRange::Raise();
Handle(Expr_GeneralExpression)* bid = new Handle(Expr_GeneralExpression);
return *bid;
}
Handle(Expr_GeneralExpression) Expr_NamedConstant::Simplified () const
{
Handle(Expr_GeneralExpression) res = new Expr_NumericValue(myValue);
return res;
}
Handle(Expr_GeneralExpression) Expr_NamedConstant::Copy () const
{
return new Expr_NamedConstant(GetName(),myValue);
}
Handle(Expr_GeneralExpression) Expr_NamedConstant::Derivative (const Handle(Expr_NamedUnknown)& ) const
{
Handle(Expr_GeneralExpression) aNumVal = new Expr_NumericValue(0.0);
return aNumVal;
}
Handle(Expr_GeneralExpression) Expr_NamedConstant::NDerivative (const Handle(Expr_NamedUnknown)& , const Standard_Integer ) const
{
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) Expr_NamedConstant::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) res = new Expr_NumericValue(myValue);
return res;
}
Standard_Real Expr_NamedConstant::Evaluate(const Expr_Array1OfNamedUnknown&, const TColStd_Array1OfReal&) const
{
return myValue;
}
Standard_Integer Expr_NamedConstant::NbSubExpressions () const
{
return 0;
}
Standard_Boolean Expr_NamedConstant::ContainsUnknowns () const
{
return Standard_False;
}
Standard_Boolean Expr_NamedConstant::Contains (const Handle(Expr_GeneralExpression)& ) const
{
return Standard_False;
}
Standard_Boolean Expr_NamedConstant::IsLinear () const
{
return Standard_True;
}
void Expr_NamedConstant::Replace (const Handle(Expr_NamedUnknown)& , const Handle(Expr_GeneralExpression)& )
{
}

12
src/Expr/Expr_NamedConstant.lxx Executable file
View File

@@ -0,0 +1,12 @@
// Copyright: Matra-Datavision 1991
// File: Expr_NamedConstant.lxx
// Created: Mon Dec 2 14:28:46 1991
// Author: Arnaud BOUZY
// <adn>
inline Standard_Real Expr_NamedConstant::GetValue () const
{
return myValue;
}

View File

@@ -0,0 +1,52 @@
-- File: NamedExpression.cdl
-- Created: Thu Jan 10 14:50:02 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
deferred class NamedExpression from Expr
inherits GeneralExpression from Expr
---Purpose: Describe an expression used by its name (as constants
-- or variables). A single reference is made to a
-- NamedExpression in every Expression (i.e. a
-- NamedExpression is shared).
uses AsciiString from TCollection
is
GetName(me)
returns AsciiString
---C++: return const &
---Level: Advanced
is static;
SetName(me : mutable; name : AsciiString)
---Level: Internal
is static;
IsShareable(me)
---Purpose: Tests if <me> can be shared by one or more expressions
-- or must be copied. This method redefines to a True
-- value the GeneralExpression method.
returns Boolean
is redefined;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString from TCollection;
fields
myName : AsciiString;
end NamedExpression;

View File

@@ -0,0 +1,38 @@
//static const char* sccsid = "@(#)Expr_NamedExpression.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_NamedExpression.cxx
// Created: Thu Apr 11 12:16:08 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_NamedExpression.ixx>
const TCollection_AsciiString& Expr_NamedExpression::GetName() const
{
return myName;
}
void Expr_NamedExpression::SetName(const TCollection_AsciiString& name)
{
myName = name;
}
Standard_Boolean Expr_NamedExpression::IsShareable () const
{
return Standard_True;
}
Standard_Boolean Expr_NamedExpression::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (!Other->IsKind(STANDARD_TYPE(Expr_NamedExpression))) {
return Standard_False;
}
Handle(Expr_NamedExpression) me = this;
Handle(Expr_NamedExpression) NEOther = Handle(Expr_NamedExpression)::DownCast(Other);
return (me == NEOther);
}
TCollection_AsciiString Expr_NamedExpression::String() const
{
return GetName();
}

111
src/Expr/Expr_NamedFunction.cdl Executable file
View File

@@ -0,0 +1,111 @@
-- File: NamedFunction.cdl
-- Created: Mon Jan 14 10:52:08 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class NamedFunction from Expr
inherits GeneralFunction from Expr
uses GeneralExpression from Expr,
NamedUnknown from Expr,
Array1OfReal from TColStd,
Array1OfNamedUnknown from Expr,
AsciiString from TCollection
raises OutOfRange from Standard,
DimensionMismatch from Standard,
NumericError from Standard,
NotEvaluable from Expr
is
Create( name : AsciiString;
exp : GeneralExpression;
vars : Array1OfNamedUnknown)
---Purpose: Creates a function of given variables <vars> with name
-- <name> defined by the expression <exp>.
---Level : Advanced
returns mutable NamedFunction;
SetName(me : mutable; newname : AsciiString)
---Purpose: Sets the name <newname> to <me>.
---Level : Internal
is static;
GetName(me)
---Purpose: Returns the name assigned to <me>
---Level : Internal
returns AsciiString
is static;
NbOfVariables(me)
---Purpose: Returns the number of variables of <me>.
returns Integer
is static;
Variable(me ; index : Integer)
---Purpose: Returns the variable denoted by <index> in <me>.
-- Raises OutOfRange if <index> is greater than
-- NbOfVariables of <me>, or less than or equal to zero.
returns NamedUnknown
raises OutOfRange
is static;
Evaluate(me; vars : Array1OfNamedUnknown;
values : Array1OfReal)
---Purpose: Computes the value of <me> with the given variables.
-- Raises DimensionMismatch if Length(vars) is different from
-- Length(values).
returns Real
raises DimensionMismatch,NumericError,NotEvaluable;
Copy(me)
---Purpose: Returns a copy of <me> with the same form.
returns mutable like me;
Derivative(me; var : NamedUnknown)
---Purpose: Returns Derivative of <me> for variable <var>.
returns GeneralFunction;
Derivative(me; var : NamedUnknown; deg : Integer)
---Purpose: Returns Derivative of <me> for variable <var> with
-- degree <deg>.
returns GeneralFunction;
IsIdentical(me; func : GeneralFunction)
---Purpose: Tests if <me> and <func> are similar functions (same
-- name and same used expression).
returns Boolean;
IsLinearOnVariable(me; index : Integer)
---Purpose: Tests if <me> is linear on variable on range <index>
returns Boolean;
GetStringName(me)
returns AsciiString from TCollection;
Expression(me)
---Purpose: Returns equivalent expression of <me>.
---Level : Internal
returns GeneralExpression
is static;
SetExpression(me : mutable; exp : GeneralExpression);
---Purpose: Modifies expression of <me>.
-- Warning: Beware of derivatives. See FunctionDerivative
---Level : Internal
fields
myName : AsciiString;
myExp : GeneralExpression;
myVariables : Array1OfNamedUnknown;
end NamedFunction;

113
src/Expr/Expr_NamedFunction.cxx Executable file
View File

@@ -0,0 +1,113 @@
//static const char* sccsid = "@(#)Expr_NamedFunction.cxx 3.4 95/02/02"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_NamedFunction.cxx
// Created: Wed Jun 26 11:44:52 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_NamedFunction.ixx>
#include <Expr_NamedConstant.hxx>
#include <Standard_OutOfRange.hxx>
#include <Expr_FunctionDerivative.hxx>
#include <Expr_NumericValue.hxx>
#include <Expr.hxx>
Expr_NamedFunction::Expr_NamedFunction (const TCollection_AsciiString& name, const Handle(Expr_GeneralExpression)& exp, const Expr_Array1OfNamedUnknown& vars) :
myVariables(vars.Lower(),vars.Upper())
{
myVariables=vars;
myName = name;
myExp = exp;
}
void Expr_NamedFunction::SetName(const TCollection_AsciiString& newname)
{
myName = newname;
}
TCollection_AsciiString Expr_NamedFunction::GetName () const
{
return myName;
}
Standard_Integer Expr_NamedFunction::NbOfVariables () const
{
return myVariables.Length();
}
Handle(Expr_NamedUnknown) Expr_NamedFunction::Variable (const Standard_Integer index) const
{
return myVariables(index);
}
Standard_Real Expr_NamedFunction::Evaluate (const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& values) const
{
if (vars.Length() != values.Length()) {
Standard_OutOfRange::Raise();
}
return myExp->Evaluate(vars,values);
}
Handle(Expr_GeneralFunction) Expr_NamedFunction::Copy () const
{
return new Expr_NamedFunction(myName,Expr::CopyShare(Expression()),myVariables);
}
Handle(Expr_GeneralFunction) Expr_NamedFunction::Derivative(const Handle(Expr_NamedUnknown)& var) const
{
Handle(Expr_NamedFunction) me = this;
return new Expr_FunctionDerivative(me,var,1);
}
Handle(Expr_GeneralFunction) Expr_NamedFunction::Derivative(const Handle(Expr_NamedUnknown)& var, const Standard_Integer deg) const
{
Handle(Expr_NamedFunction) me = this;
return new Expr_FunctionDerivative(me,var,deg);
}
Standard_Boolean Expr_NamedFunction::IsIdentical (const Handle(Expr_GeneralFunction)& func) const
{
if (!func->IsKind(STANDARD_TYPE(Expr_NamedFunction))) {
return Standard_False;
}
if (myName != Handle(Expr_NamedFunction)::DownCast(func)->GetName()) {
return Standard_False;
}
Standard_Integer nbvars = NbOfVariables();
if (nbvars != func->NbOfVariables()) {
return Standard_False;
}
Handle(Expr_NamedUnknown) thisvar;
for (Standard_Integer i =1; i<=nbvars; i++) {
thisvar = Variable(i);
if (!thisvar->IsIdentical(func->Variable(i))) {
return Standard_False;
}
}
if (!Expression()->IsIdentical(Handle(Expr_NamedFunction)::DownCast(func)->Expression())) {
return Standard_False;
}
return Standard_True;
}
Standard_Boolean Expr_NamedFunction::IsLinearOnVariable(const Standard_Integer) const
{
// bad implementation, should be improved
return myExp->IsLinear();
}
TCollection_AsciiString Expr_NamedFunction::GetStringName() const
{
return myName;
}
Handle(Expr_GeneralExpression) Expr_NamedFunction::Expression() const
{
return myExp;
}
void Expr_NamedFunction::SetExpression(const Handle(Expr_GeneralExpression)& anexp)
{
myExp = anexp;
}

123
src/Expr/Expr_NamedUnknown.cdl Executable file
View File

@@ -0,0 +1,123 @@
-- File: NamedUnknown.cdl
-- Created: Thu Jan 10 12:16:44 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class NamedUnknown from Expr
inherits NamedExpression from Expr
---Purpose: This class describes any variable of an expression.
-- Assignment is treated directly in this class.
uses GeneralExpression from Expr,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
AsciiString from TCollection
raises NotAssigned from Expr,
OutOfRange from Standard,
NumericError from Standard,
InvalidAssignment from Expr,
InvalidOperand from Expr,
NotEvaluable from Expr
is
Create(name : AsciiString)
returns mutable NamedUnknown;
IsAssigned(me)
---Purpose: Tests if an expression is assigned to <me>.
---C++: inline
returns Boolean
is static;
AssignedExpression(me)
---Purpose: If exists, returns the assigned expression.
-- An exception is raised if the expression does not exist.
---C++: return const &
returns any GeneralExpression
raises NotAssigned
is static;
Assign(me : mutable; exp: GeneralExpression)
---Purpose: Assigns <me> to <exp> expression.
-- Raises exception if <exp> refers to <me>.
raises InvalidAssignment
is static;
Deassign(me : mutable)
---Purpose: Supresses the assigned expression
---C++: inline
is static;
NbSubExpressions(me)
---Purpose: Returns the number of sub-expressions contained
-- in <me> ( >= 0)
returns Integer
is static;
SubExpression(me; I : Integer)
---Purpose: Returns the <I>-th sub-expression of <me>
-- raises OutOfRange if <I> > NbSubExpressions(me)
---C++: return const &
returns any GeneralExpression
raises OutOfRange
is static;
Simplified(me)
---Purpose: Returns a GeneralExpression after replacement of
-- NamedUnknowns by an associated expression and after
-- values computation.
returns any GeneralExpression
raises NumericError
is static;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError
is static;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
ContainsUnknowns(me)
---Purpose: Tests if <me> contains NamedUnknown.
returns Boolean
is static;
Contains(me; exp : GeneralExpression)
---Purpose: Tests if <exp> is contained in <me>.
returns Boolean
is static;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>
returns any GeneralExpression;
Replace(me : mutable ; var : NamedUnknown ; with : GeneralExpression)
---Purpose: Replaces all occurences of <var> with <with> in <me>
-- Raises InvalidOperand if <with> contains <me>.
raises InvalidOperand;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
fields
myExpression : GeneralExpression;
end NamedUnknown;

175
src/Expr/Expr_NamedUnknown.cxx Executable file
View File

@@ -0,0 +1,175 @@
//static const char* sccsid = "@(#)Expr_NamedUnknown.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_NamedUnknown.cxx
// Created: Thu Apr 11 12:24:13 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_NamedUnknown.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr.hxx>
#include <Expr_NotAssigned.hxx>
#include <Expr_NotEvaluable.hxx>
#include <Expr_InvalidOperand.hxx>
#include <Expr_InvalidAssignment.hxx>
#include <Standard_OutOfRange.hxx>
Expr_NamedUnknown::Expr_NamedUnknown(const TCollection_AsciiString& name)
{
SetName(name);
myExpression.Nullify();
}
const Handle(Expr_GeneralExpression)& Expr_NamedUnknown::AssignedExpression () const
{
if (!IsAssigned()) {
Expr_NotAssigned::Raise();
}
return myExpression;
}
void Expr_NamedUnknown::Assign (const Handle(Expr_GeneralExpression)& exp)
{
Handle(Expr_NamedUnknown) me = this;
if (exp->Contains(me)) {
Expr_InvalidAssignment::Raise();
}
myExpression = exp;
}
const Handle(Expr_GeneralExpression)& Expr_NamedUnknown::SubExpression (const Standard_Integer I) const
{
if (!IsAssigned()) {
Standard_OutOfRange::Raise();
}
if (I != 1) {
Standard_OutOfRange::Raise();
}
return AssignedExpression();
}
Handle(Expr_GeneralExpression) Expr_NamedUnknown::Simplified () const
{
if (!IsAssigned()) {
Handle(Expr_NamedUnknown) me = this;
return me;
}
else {
return myExpression->Simplified();
}
}
Handle(Expr_GeneralExpression) Expr_NamedUnknown::Copy () const
{
Handle(Expr_NamedUnknown) cop = new Expr_NamedUnknown(GetName());
if (IsAssigned()) {
cop->Assign(Expr::CopyShare(myExpression));
}
return cop;
}
Standard_Boolean Expr_NamedUnknown::ContainsUnknowns () const
{
if (IsAssigned()) {
if (myExpression->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
return Standard_True;
}
return myExpression->ContainsUnknowns();
}
else {
return Standard_False;
}
}
Standard_Boolean Expr_NamedUnknown::Contains (const Handle(Expr_GeneralExpression)& exp) const
{
if (!IsAssigned()) {
return Standard_False;
}
if (myExpression == exp) {
return Standard_True;
}
return myExpression->Contains(exp);
}
Standard_Boolean Expr_NamedUnknown::IsLinear () const
{
if (IsAssigned()) {
return myExpression->IsLinear();
}
else {
return Standard_True;
}
}
Handle(Expr_GeneralExpression) Expr_NamedUnknown::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
Handle(Expr_NamedUnknown) me = this;
if (me != X) {
if (IsAssigned()) {
return myExpression->Derivative(X);
}
else {
return new Expr_NumericValue(0.0);
}
}
else {
return new Expr_NumericValue(1.0);
}
}
void Expr_NamedUnknown::Replace (const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with)
{
if (IsAssigned()) {
if (myExpression == var) {
Handle(Expr_NamedUnknown) me = this;
if (with->Contains(me)) {
Expr_InvalidOperand::Raise();
}
Assign(with);
}
else {
if (myExpression->Contains(var)) {
myExpression->Replace(var,with);
}
}
}
}
Handle(Expr_GeneralExpression) Expr_NamedUnknown::ShallowSimplified () const
{
if (IsAssigned()) {
return myExpression;
}
Handle(Expr_NamedUnknown) me = this;
return me;
}
Standard_Real Expr_NamedUnknown::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
if (!IsAssigned()) {
Handle(Expr_NamedUnknown) me = this;
for (Standard_Integer i=vars.Lower();i<=vars.Upper();i++) {
if (me->GetName() == vars(i)->GetName()) {
return vals(i-vars.Lower()+vals.Lower());
}
}
Expr_NotEvaluable::Raise();
}
return myExpression->Evaluate(vars,vals);
}
Standard_Integer Expr_NamedUnknown::NbSubExpressions () const
{
if (IsAssigned()) {
return 1;
}
else {
return 0;
}
}

17
src/Expr/Expr_NamedUnknown.lxx Executable file
View File

@@ -0,0 +1,17 @@
// Copyright: Matra-Datavision 1991
// File: Expr_NamedUnknown.lxx
// Created: Mon Dec 2 14:30:57 1991
// Author: Arnaud BOUZY
// <adn>
inline Standard_Boolean Expr_NamedUnknown::IsAssigned() const
{
return !(myExpression.IsNull());
}
inline void Expr_NamedUnknown::Deassign ()
{
myExpression.Nullify();
}

111
src/Expr/Expr_NumericValue.cdl Executable file
View File

@@ -0,0 +1,111 @@
-- File: NumericValue.cdl
-- Created: Thu Jan 10 12:20:27 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class NumericValue from Expr
inherits GeneralExpression from Expr
---Purpose: This class describes any reel value defined in an
-- expression.
uses AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises OutOfRange from Standard
is
Create(val : Real)
---Level: Advanced
returns mutable NumericValue;
GetValue(me)
---Level: Advanced
returns Real;
SetValue(me : mutable; val : Real);
---Level: Internal
NbSubExpressions(me)
---Purpose: Returns the number of sub-expressions contained
-- in <me> ( >= 0)
returns Integer
is static;
SubExpression(me; I : Integer)
---Purpose: Returns the <I>-th sub-expression of <me>
-- raises OutOfRange if <I> > NbSubExpressions(me)
---C++: return const &
returns any GeneralExpression
raises OutOfRange
is static;
Simplified(me)
---Purpose: Returns a GeneralExpression after replacement of
-- NamedUnknowns by an associated expression and after
-- values computation.
returns any GeneralExpression;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
ContainsUnknowns(me)
---Purpose: Tests if <me> contains NamedUnknown.
returns Boolean
is static;
Contains(me; exp : GeneralExpression)
---Purpose: Tests if <exp> is contained in <me>.
returns Boolean
is static;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean
is static;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>
returns any GeneralExpression;
NDerivative(me; X : NamedUnknown; N : Integer)
---Purpose: Returns the <N>-th derivative on <X> unknown of <me>.
-- Raises OutOfRange if <N> <= 0
returns any GeneralExpression
raises OutOfRange
is redefined;
Replace(me : mutable ; var : NamedUnknown ; with : GeneralExpression);
---Purpose: Replaces all occurences of <var> with <with> in <me>
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
returns Real;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
fields
myValue : Real;
end NumericValue;

107
src/Expr/Expr_NumericValue.cxx Executable file
View File

@@ -0,0 +1,107 @@
//static const char* sccsid = "@(#)Expr_NumericValue.cxx 3.3 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_NumericValue.cxx
// Created: Wed Mar 6 11:06:16 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_NumericValue.ixx>
#include <Standard_OutOfRange.hxx>
//#if defined (WNT) || !defined (DEB)
# include <stdio.h>
//#endif // WNT || !DEB
Expr_NumericValue::Expr_NumericValue(const Standard_Real val)
{
myValue = val;
}
Standard_Real Expr_NumericValue::GetValue() const
{
return myValue;
}
void Expr_NumericValue::SetValue(const Standard_Real val)
{
myValue = val;
}
Standard_Integer Expr_NumericValue::NbSubExpressions() const
{
return 0;
}
const Handle(Expr_GeneralExpression)& Expr_NumericValue::SubExpression(const Standard_Integer) const
{
Standard_OutOfRange::Raise();
Handle(Expr_GeneralExpression)* bid=NULL;
return *bid;
}
Handle(Expr_GeneralExpression) Expr_NumericValue::Simplified() const
{
return Copy();
}
Handle(Expr_GeneralExpression) Expr_NumericValue::Copy() const
{
return new Expr_NumericValue(myValue);
}
Standard_Boolean Expr_NumericValue::ContainsUnknowns () const
{
return Standard_False;
}
Standard_Boolean Expr_NumericValue::Contains (const Handle(Expr_GeneralExpression)& ) const
{
return Standard_False;
}
Standard_Boolean Expr_NumericValue::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (!Other->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
return Standard_False;
}
Handle(Expr_NumericValue) NVOther = Handle(Expr_NumericValue)::DownCast(Other);
return (myValue == NVOther->GetValue());
}
Standard_Boolean Expr_NumericValue::IsLinear () const
{
return Standard_True;
}
Handle(Expr_GeneralExpression) Expr_NumericValue::Derivative (const Handle(Expr_NamedUnknown)& ) const
{
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) Expr_NumericValue::NDerivative (const Handle(Expr_NamedUnknown)& , const Standard_Integer) const
{
return new Expr_NumericValue(0.0);
}
void Expr_NumericValue::Replace (const Handle(Expr_NamedUnknown)& , const Handle(Expr_GeneralExpression)& )
{
}
Handle(Expr_GeneralExpression) Expr_NumericValue::ShallowSimplified () const
{
Handle(Expr_NumericValue) me = this;
return me;
}
Standard_Real Expr_NumericValue::Evaluate(const Expr_Array1OfNamedUnknown&, const TColStd_Array1OfReal&) const
{
return myValue;
}
TCollection_AsciiString Expr_NumericValue::String() const
{
char val[100];
sprintf(val,"%g",myValue);
return TCollection_AsciiString(val);
}

80
src/Expr/Expr_Operators.cxx Executable file
View File

@@ -0,0 +1,80 @@
//static const char* sccsid = "@(#)Expr_Operators.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1992
// File: Expr_Operators.cxx
// Created: Fri Jul 10 10:49:40 1992
// Author: Arnaud BOUZY
// <adn>
#include <Expr_Operators.hxx>
Handle(Expr_Sum) operator+(const Handle(Expr_GeneralExpression)& x,const Handle(Expr_GeneralExpression)& y)
{
return new Expr_Sum(x,y);
}
Handle(Expr_Sum) operator+(const Standard_Real x,const Handle(Expr_GeneralExpression)& y)
{
Handle(Expr_NumericValue) nv = new Expr_NumericValue(x);
return new Expr_Sum(nv,y);
}
Handle(Expr_Sum) operator+(const Handle(Expr_GeneralExpression)& x, const Standard_Real y)
{
return y+x;
}
Handle(Expr_Difference) operator-(const Handle(Expr_GeneralExpression)& x, const Handle(Expr_GeneralExpression)& y)
{
return new Expr_Difference(x,y);
}
Handle(Expr_Difference) operator-(const Standard_Real x, const Handle(Expr_GeneralExpression)& y)
{
Handle(Expr_NumericValue) nv = new Expr_NumericValue(x);
return new Expr_Difference(nv,y);
}
Handle(Expr_Difference) operator-(const Handle(Expr_GeneralExpression)& x, const Standard_Real y)
{
Handle(Expr_NumericValue) nv = new Expr_NumericValue(y);
return new Expr_Difference(x,nv);
}
Handle(Expr_UnaryMinus) operator-(const Handle(Expr_GeneralExpression)& x)
{
return new Expr_UnaryMinus(x);
}
Handle(Expr_Product) operator*(const Handle(Expr_GeneralExpression)& x, const Handle(Expr_GeneralExpression)& y)
{
return new Expr_Product(x,y);
}
Handle(Expr_Product) operator*(const Standard_Real x, const Handle(Expr_GeneralExpression)& y)
{
Handle(Expr_NumericValue) nv = new Expr_NumericValue(x);
return new Expr_Product(nv,y);
}
Handle(Expr_Product) operator*(const Handle(Expr_GeneralExpression)& x, const Standard_Real y)
{
return y*x;
}
Handle(Expr_Division) operator/(const Handle(Expr_GeneralExpression)& x, const Handle(Expr_GeneralExpression)& y)
{
return new Expr_Division(x,y);
}
Handle(Expr_Division) operator/(const Standard_Real x, const Handle(Expr_GeneralExpression)& y)
{
Handle(Expr_NumericValue) nv = new Expr_NumericValue(x);
return new Expr_Division(nv,y);
}
Handle(Expr_Division) operator/(const Handle(Expr_GeneralExpression)& x, const Standard_Real y)
{
Handle(Expr_NumericValue) nv = new Expr_NumericValue(y);
return new Expr_Division(x,nv);
}

71
src/Expr/Expr_Operators.hxx Executable file
View File

@@ -0,0 +1,71 @@
// Copyright: Matra-Datavision 1991
// File: Expr_Operators.hxx
// Created: Tue Sep 17 14:45:15 1991
// Author: Arnaud BOUZY
// <adn>
#ifndef Expr_Operators_HeaderFile
#define Expr_Operators_HeaderFile
#include <Expr_GeneralExpression.hxx>
#include <Expr_NumericValue.hxx>
#include <Expr_Sum.hxx>
#include <Expr_UnaryMinus.hxx>
#include <Expr_Difference.hxx>
#include <Expr_Product.hxx>
#include <Expr_Division.hxx>
#ifndef __Expr_API
# if defined(WNT) && !defined(HAVE_NO_DLL)
# ifdef __Expr_DLL
# define __Expr_API __declspec( dllexport )
# else
# define __Expr_API __declspec( dllimport )
# endif // __Expr_DLL
# else
# define __Expr_API
# endif // WNT
#endif // __Expr_API
//__Expr_API Handle(Expr_Sum) operator+(const Handle(Expr_GeneralExpression)& x,const Handle(Expr_GeneralExpression)& y);
Standard_EXPORT Handle(Expr_Sum) operator+(const Handle(Expr_GeneralExpression)& x,const Handle(Expr_GeneralExpression)& y);
//__Expr_API Handle(Expr_Sum) operator+(const Standard_Real x,const Handle(Expr_GeneralExpression)& y);
Standard_EXPORT Handle(Expr_Sum) operator+(const Standard_Real x,const Handle(Expr_GeneralExpression)& y);
//__Expr_API Handle(Expr_Sum) operator+(const Handle(Expr_GeneralExpression)& x, const Standard_Real y);
Standard_EXPORT Handle(Expr_Sum) operator+(const Handle(Expr_GeneralExpression)& x, const Standard_Real y);
//__Expr_API Handle(Expr_Difference) operator-(const Handle(Expr_GeneralExpression)& x, const Handle(Expr_GeneralExpression)& y);
Standard_EXPORT Handle(Expr_Difference) operator-(const Handle(Expr_GeneralExpression)& x, const Handle(Expr_GeneralExpression)& y);
//__Expr_API Handle(Expr_Difference) operator-(const Standard_Real x, const Handle(Expr_GeneralExpression)& y);
Standard_EXPORT Handle(Expr_Difference) operator-(const Standard_Real x, const Handle(Expr_GeneralExpression)& y);
//__Expr_API Handle(Expr_Difference) operator-(const Handle(Expr_GeneralExpression)& x, const Standard_Real y);
Standard_EXPORT Handle(Expr_Difference) operator-(const Handle(Expr_GeneralExpression)& x, const Standard_Real y);
//__Expr_API Handle(Expr_UnaryMinus) operator-(const Handle(Expr_GeneralExpression)& x);
Standard_EXPORT Handle(Expr_UnaryMinus) operator-(const Handle(Expr_GeneralExpression)& x);
//__Expr_API Handle(Expr_Product) operator*(const Handle(Expr_GeneralExpression)& x, const Handle(Expr_GeneralExpression)& y);
Standard_EXPORT Handle(Expr_Product) operator*(const Handle(Expr_GeneralExpression)& x, const Handle(Expr_GeneralExpression)& y);
//__Expr_API Handle(Expr_Product) operator*(const Standard_Real x, const Handle(Expr_GeneralExpression)& y);
Standard_EXPORT Handle(Expr_Product) operator*(const Standard_Real x, const Handle(Expr_GeneralExpression)& y);
//__Expr_API Handle(Expr_Product) operator*(const Handle(Expr_GeneralExpression)& x, const Standard_Real y);
Standard_EXPORT Handle(Expr_Product) operator*(const Handle(Expr_GeneralExpression)& x, const Standard_Real y);
//__Expr_API Handle(Expr_Division) operator/(const Handle(Expr_GeneralExpression)& x, const Handle(Expr_GeneralExpression)& y);
Standard_EXPORT Handle(Expr_Division) operator/(const Handle(Expr_GeneralExpression)& x, const Handle(Expr_GeneralExpression)& y);
//__Expr_API Handle(Expr_Division) operator/(const Standard_Real x, const Handle(Expr_GeneralExpression)& y);
Standard_EXPORT Handle(Expr_Division) operator/(const Standard_Real x, const Handle(Expr_GeneralExpression)& y);
//__Expr_API Handle(Expr_Division) operator/(const Handle(Expr_GeneralExpression)& x, const Standard_Real y);
Standard_EXPORT Handle(Expr_Division) operator/(const Handle(Expr_GeneralExpression)& x, const Standard_Real y);
#endif

103
src/Expr/Expr_PolyExpression.cdl Executable file
View File

@@ -0,0 +1,103 @@
-- File: PolyExpression.cdl
-- Created: Thu Jan 10 14:28:48 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
deferred class PolyExpression from Expr
inherits GeneralExpression from Expr
uses SequenceOfGeneralExpression from Expr,
NamedUnknown from Expr
raises OutOfRange from Standard,
NumericError from Standard,
InvalidOperand from Expr
is
Initialize;
---Purpose: initialize an empty list of operands.
NbOperands(me)
---Purpose: returns the number of operands contained in <me>
---Level : Internal
returns Integer
is static;
Operand(me; index : Integer)
---Purpose: Returns the <index>-th operand used in <me>.
-- An exception is raised if index is out of range
---C++: inline
---C++: return const &
---Level : Internal
returns any GeneralExpression
raises OutOfRange
is static;
SetOperand(me : mutable; exp : GeneralExpression; index : Integer)
---Purpose: Sets the <index>-th operand used in <me>.
-- An exception is raised if <index> is out of range
-- Raises InvalidOperand if <exp> contains <me>.
---Level : Internal
raises OutOfRange,InvalidOperand
is static;
AddOperand(me : mutable; exp : GeneralExpression)
---Purpose: Adds an operand to the list of <me>.
---Level : Internal
is static protected;
RemoveOperand(me : mutable; index : Integer)
---Purpose: Remove the operand denoted by <index> from the list of
-- <me>.
-- Raises exception if <index> is out of range or if
-- removing operand intend to leave only one or no
-- operand.
---Level : Internal
raises OutOfRange
is static protected;
NbSubExpressions(me)
---Purpose: returns the number of sub-expressions contained
-- in <me> ( >= 2)
returns Integer
is static;
SubExpression(me; I : Integer)
---Purpose: Returns the sub-expression denoted by <I> in <me>
-- Raises OutOfRange if <I> > NbSubExpressions(me)
---C++: return const &
returns any GeneralExpression
raises OutOfRange
is static;
ContainsUnknowns(me)
---Purpose: Does <me> contains NamedUnknown ?
returns Boolean
is static;
Contains(me; exp : GeneralExpression)
---Purpose: Tests if <exp> is contained in <me>.
returns Boolean
is static;
Replace(me : mutable ; var : NamedUnknown ; with : GeneralExpression)
---Purpose: Replaces all occurences of <var> with <with> in <me>
-- Raises InvalidOperand if <with> contains <me>.
raises InvalidOperand
is static;
Simplified(me)
---Purpose: Returns a GeneralExpression after replacement of
-- NamedUnknowns by an associated expression and after
-- values computation.
returns any GeneralExpression
raises NumericError;
fields
myOperands : SequenceOfGeneralExpression;
end PolyExpression;

132
src/Expr/Expr_PolyExpression.cxx Executable file
View File

@@ -0,0 +1,132 @@
//static const char* sccsid = "@(#)Expr_PolyExpression.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_PolyExpression.cxx
// Created: Tue Apr 16 09:55:23 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_PolyExpression.ixx>
#include <Expr_NamedUnknown.hxx>
#include <Expr_InvalidOperand.hxx>
#include <Standard_OutOfRange.hxx>
#include <Standard_DimensionMismatch.hxx>
Expr_PolyExpression::Expr_PolyExpression()
{
}
Standard_Integer Expr_PolyExpression::NbOperands () const
{
return myOperands.Length();
}
void Expr_PolyExpression::SetOperand (const Handle(Expr_GeneralExpression)& exp, const Standard_Integer index)
{
Handle(Expr_PolyExpression) me = this;
if (exp == me) {
Expr_InvalidOperand::Raise();
}
if (exp->Contains(me)) {
Expr_InvalidOperand::Raise();
}
myOperands(index) = exp;
}
void Expr_PolyExpression::AddOperand (const Handle(Expr_GeneralExpression)& exp)
{
myOperands.Append(exp);
}
void Expr_PolyExpression::RemoveOperand (const Standard_Integer index)
{
if (myOperands.Length() <= 2) {
Standard_DimensionMismatch::Raise();
}
myOperands.Remove(index);
}
Standard_Integer Expr_PolyExpression::NbSubExpressions () const
{
return NbOperands();
}
const Handle(Expr_GeneralExpression)& Expr_PolyExpression::SubExpression (const Standard_Integer I) const
{
return Operand(I);
}
Standard_Boolean Expr_PolyExpression::ContainsUnknowns () const
{
Standard_Boolean found = Standard_False;
Standard_Integer nbop = NbOperands();
Standard_Integer i = 1;
Handle(Expr_GeneralExpression) expop;
while ((!found) && (i <= nbop)) {
expop = Operand(i);
found = expop->IsKind(STANDARD_TYPE(Expr_NamedUnknown));
i++;
}
i = 1;
while ((!found) && (i <= nbop)) {
expop = Operand(i);
found = expop->ContainsUnknowns();
i++;
}
return found;
}
Standard_Boolean Expr_PolyExpression::Contains (const Handle(Expr_GeneralExpression)& exp) const
{
Standard_Boolean found = Standard_False;
Standard_Integer nbop = NbOperands();
Standard_Integer i = 1;
Handle(Expr_GeneralExpression) expop;
while ((!found) && (i <= nbop)) {
expop = Operand(i);
found = (expop == exp);
i++;
}
i = 1;
while ((!found) && (i <= nbop)) {
expop = Operand(i);
found = expop->Contains(exp);
i++;
}
return found;
}
void Expr_PolyExpression::Replace (const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with)
{
Standard_Integer nbop = NbOperands();
Standard_Integer i;
Handle(Expr_GeneralExpression) expop;
for(i=1;i <= nbop; i++) {
expop = Operand(i);
if (expop == var) {
SetOperand(with,i);
}
else {
if (expop->Contains(var)) {
expop->Replace(var,with);
}
}
}
}
Handle(Expr_GeneralExpression) Expr_PolyExpression::Simplified() const
{
Handle(Expr_PolyExpression) cop = Handle(Expr_PolyExpression)::DownCast(Copy());
Standard_Integer i;
Standard_Integer max = cop->NbOperands();
Handle(Expr_GeneralExpression) op;
for (i=1; i<= max; i++) {
op = cop->Operand(i);
cop->SetOperand(op->Simplified(),i);
}
return cop->ShallowSimplified();
}

View File

@@ -0,0 +1,11 @@
// Copyright: Matra-Datavision 1994
// File: Expr_PolyExpression.lxx
// Created: Wed Jan 5 15:28:45 1994
// Author: Arnaud BOUZY
// <adn>
inline const Handle(Expr_GeneralExpression)& Expr_PolyExpression::Operand (const Standard_Integer index) const
{
return myOperands(index);
}

75
src/Expr/Expr_PolyFunction.cdl Executable file
View File

@@ -0,0 +1,75 @@
-- File: PolyFunction.cdl
-- Created: Mon Jan 14 16:20:47 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class PolyFunction from Expr
inherits PolyExpression from Expr
---Purpose: Defines the use of an n-ary function in an expression
-- with given arguments.
uses GeneralFunction from Expr,
AsciiString from TCollection,
GeneralExpression from Expr,
NamedUnknown from Expr,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
Array1OfGeneralExpression from Expr
raises NumericError from Standard,
OutOfRange from Standard,
NotEvaluable from Expr
is
Create(func : GeneralFunction;exps : Array1OfGeneralExpression)
---Purpose: Creates <me> as <func>(<exps_1>,<exps_2>,...,<exps_n>)
returns mutable PolyFunction;
Function(me)
---Purpose: Returns the function defining <me>.
returns GeneralFunction;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
fields
myFunction : GeneralFunction;
end PolyFunction;

158
src/Expr/Expr_PolyFunction.cxx Executable file
View File

@@ -0,0 +1,158 @@
//static const char* sccsid = "@(#)Expr_PolyFunction.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_PolyFunction.cxx
// Created: Tue Jul 2 11:11:43 1991
// Author: Arnaud BOUZY
// <adn>
#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#endif
#include <Expr_PolyFunction.ixx>
#include <Expr_Array1OfNamedUnknown.hxx>
#include <Expr_FunctionDerivative.hxx>
#include <Expr_Product.hxx>
#include <Expr_Sum.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
#include <Standard_DimensionError.hxx>
Expr_PolyFunction::Expr_PolyFunction (const Handle(Expr_GeneralFunction)& func, const Expr_Array1OfGeneralExpression& exps)
{
for (Standard_Integer i=exps.Lower();i <= exps.Upper(); i++) {
AddOperand(exps(i));
}
myFunction = func;
}
Handle(Expr_GeneralFunction) Expr_PolyFunction::Function () const
{
return myFunction;
}
Handle(Expr_GeneralExpression) Expr_PolyFunction::ShallowSimplified () const
{
Standard_Boolean allval = Standard_True;
Standard_Integer max = NbSubExpressions();
Standard_Integer i;
for (i = 1; (i <= max) && allval ; i++) {
allval = SubExpression(i)->IsKind(STANDARD_TYPE(Expr_NumericValue));
}
if (allval) {
TColStd_Array1OfReal tabval(1,max);
Expr_Array1OfNamedUnknown tabvar(1,max);
for (i=1; i<=max;i++) {
tabval(i) = Handle(Expr_NumericValue)::DownCast(SubExpression(i))->GetValue();
tabvar(i) = myFunction->Variable(i);
}
Standard_Real res = myFunction->Evaluate(tabvar,tabval);
return new Expr_NumericValue(res);
}
Handle(Expr_PolyFunction) me =this;
return me;
}
Handle(Expr_GeneralExpression) Expr_PolyFunction::Copy () const
{
Standard_Integer max = NbSubExpressions();
Expr_Array1OfGeneralExpression vars(1,max);
for (Standard_Integer i = 1; i <= max; i++) {
vars(i) = Expr::CopyShare(SubExpression(i));
}
return new Expr_PolyFunction(myFunction,vars);
}
Standard_Boolean Expr_PolyFunction::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (!Other->IsKind(STANDARD_TYPE(Expr_PolyFunction))) {
return Standard_False;
}
if (Other->NbSubExpressions() != NbSubExpressions()) {
return Standard_False;
}
Handle(Expr_PolyFunction) pother = Handle(Expr_PolyFunction)::DownCast(Other);
Handle(Expr_GeneralFunction) fother = pother->Function();
if (!fother->IsIdentical(Function())) {
return Standard_False;
}
Standard_Integer max = NbSubExpressions();
Handle(Expr_GeneralExpression) opother;
for (Standard_Integer i = 1; i<=max;i++) {
opother = pother->SubExpression(i);
if (!opother->IsIdentical(SubExpression(i))) {
return Standard_False;
}
}
return Standard_True;
}
Standard_Boolean Expr_PolyFunction::IsLinear () const
{
if (!ContainsUnknowns()) {
return Standard_True;
}
for (Standard_Integer i=1; i<= NbOperands(); i++) {
if (!Operand(i)->IsLinear()) {
return Standard_False;
}
if (!myFunction->IsLinearOnVariable(i)) {
return Standard_False;
}
}
return Standard_True;
}
Handle(Expr_GeneralExpression) Expr_PolyFunction::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
Handle(Expr_GeneralExpression) myop;
Handle(Expr_NamedUnknown) thevar;
Handle(Expr_GeneralFunction) partderfunc;
Handle(Expr_PolyFunction) partder;
Handle(Expr_Product) partprod;
Standard_Integer max = NbSubExpressions();
Expr_Array1OfGeneralExpression theops(1,max);
for (Standard_Integer k=1; k<= max; k++) {
theops(k) = Operand(k);
}
Expr_SequenceOfGeneralExpression thesum;
for (Standard_Integer i = 1; i <= max; i++) {
thevar = myFunction->Variable(i);
myop = SubExpression(i);
partderfunc = myFunction->Derivative(thevar);
partder = new Expr_PolyFunction(partderfunc,theops);
partprod = partder->ShallowSimplified() * myop->Derivative(X);
thesum.Append(partprod->ShallowSimplified());
}
Handle(Expr_Sum) res = new Expr_Sum(thesum);
return res->ShallowSimplified();
}
Standard_Real Expr_PolyFunction::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
Standard_Integer max = NbSubExpressions();
Expr_Array1OfNamedUnknown varsfunc(1,max);
TColStd_Array1OfReal valsfunc(1,max);
for (Standard_Integer i = 1; i <= max ; i++) {
varsfunc(i) = myFunction->Variable(i);
valsfunc(i) = SubExpression(i)->Evaluate(vars,vals);
}
return myFunction->Evaluate(varsfunc,valsfunc);
}
TCollection_AsciiString Expr_PolyFunction::String() const
{
TCollection_AsciiString res = myFunction->GetStringName();
res += "(";
Standard_Integer max = NbOperands();
for (Standard_Integer i=1; i<= max; i++) {
res += Operand(i)->String();
if (i != max) {
res += ",";
}
}
res += ")";
return res;
}

66
src/Expr/Expr_Product.cdl Executable file
View File

@@ -0,0 +1,66 @@
-- File: Product.cdl
-- Created: Mon Jan 14 16:20:57 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class Product from Expr
inherits PolyExpression from Expr
uses SequenceOfGeneralExpression from Expr,
AsciiString from TCollection,
GeneralExpression from Expr,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exps : SequenceOfGeneralExpression)
---Purpose: Creates the product of all members of sequence <exps>
returns mutable Product;
Create(exp1,exp2 : GeneralExpression)
---Purpose: Creates the product of <exp1> and <exp2>.
returns mutable Product;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end Product;

276
src/Expr/Expr_Product.cxx Executable file
View File

@@ -0,0 +1,276 @@
//static const char* sccsid = "@(#)Expr_Product.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_Product.cxx
// Created: Wed Apr 17 17:10:05 1991
// Author: Arnaud BOUZY
// <adn>
#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#endif
#include <Expr_Product.ixx>
#include <TColStd_Array1OfInteger.hxx>
#include <Expr_Sum.hxx>
#include <Expr_UnaryMinus.hxx>
#include <Expr_NumericValue.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_Product::Expr_Product (const Expr_SequenceOfGeneralExpression& exps)
{
Standard_Integer i;
Standard_Integer max = exps.Length();
for (i=1; i<= max; i++) {
AddOperand(exps(i));
}
}
Expr_Product::Expr_Product (const Handle(Expr_GeneralExpression)& exp1, const Handle(Expr_GeneralExpression)& exp2)
{
AddOperand(exp1);
AddOperand(exp2);
}
Handle(Expr_GeneralExpression) Expr_Product::Copy () const
{
Standard_Integer i;
Standard_Integer max = NbOperands();
Expr_SequenceOfGeneralExpression simps;
for (i=1; i<= max; i++) {
simps.Append(Expr::CopyShare(Operand(i)));
}
return new Expr_Product(simps);
}
Standard_Boolean Expr_Product::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (!Other->IsKind(STANDARD_TYPE(Expr_Product))) {
return Standard_False;
}
Handle(Expr_Product) me = this;
Handle(Expr_Product) POther = Handle(Expr_Product)::DownCast(Other);
Standard_Integer max = NbOperands();
if (POther->NbOperands() != max) {
return Standard_False;
}
Handle(Expr_GeneralExpression) myop;
Handle(Expr_GeneralExpression) hisop;
Standard_Integer i=1;
TColStd_Array1OfInteger tab(1,max);
for (Standard_Integer k=1; k<=max;k++) {
tab(k)=0;
}
Standard_Boolean ident = Standard_True;
while ((i<=max) && (ident)) {
Standard_Integer j=1;
Standard_Boolean found = Standard_False;
myop = Operand(i);
while ((j<=max) && (!found)) {
hisop = POther->Operand(j);
found = myop->IsIdentical(hisop);
if (found) {
found = (tab(j) == 0);
tab(j)=i;
}
j++;
}
ident = found;
i++;
}
return ident;
}
Standard_Boolean Expr_Product::IsLinear () const
{
Standard_Integer i;
Standard_Integer max = NbOperands();
Standard_Boolean lin = Standard_True;
Standard_Boolean res = Standard_True;
Handle(Expr_GeneralExpression) asimp;
for (i=1; (i <= max) && res ; i++) {
asimp = Operand(i);
if (asimp->IsKind(STANDARD_TYPE(Expr_NamedUnknown)) || asimp->ContainsUnknowns()) {
if (lin) {
lin = Standard_False;
if (!asimp->IsLinear()) {
res = Standard_False;
}
}
else {
res = Standard_False;
}
}
}
return res;
}
Handle(Expr_GeneralExpression) Expr_Product::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) firstop = Expr::CopyShare(Operand(1)); // U
Handle(Expr_GeneralExpression) tailop; // V
Standard_Integer nbop = NbOperands();
if (nbop == 2) {
tailop = Expr::CopyShare(Operand(2));
}
else {
Handle(Expr_Product) prodop = Expr::CopyShare(Operand(2))*Expr::CopyShare(Operand(3));
for (Standard_Integer i=4; i<= nbop; i++) {
prodop->AddOperand(Expr::CopyShare(Operand(i)));
}
tailop = prodop;
}
Handle(Expr_GeneralExpression) firstder = firstop->Derivative(X); // U'
Handle(Expr_GeneralExpression) tailder = tailop->Derivative(X); // V'
Handle(Expr_Product) firstmember = firstop * tailder; // U*V'
Handle(Expr_Product) secondmember = firstder * tailop; // U'*V
Handle(Expr_Sum) resu = firstmember->ShallowSimplified() + secondmember->ShallowSimplified();
// U*V' + U'*V
return resu->ShallowSimplified();
}
Handle(Expr_GeneralExpression) Expr_Product::ShallowSimplified () const
{
Standard_Integer i;
Standard_Integer max = NbOperands();
Handle(Expr_GeneralExpression) op;
Expr_SequenceOfGeneralExpression newops;
#ifndef DEB
Standard_Real vals = 0.;
#else
Standard_Real vals;
#endif
Standard_Integer nbvals = 0;
Standard_Boolean subprod = Standard_False;
for (i=1; (i<= max) && !subprod; i++) {
op = Operand(i);
subprod = op->IsKind(STANDARD_TYPE(Expr_Product));
}
if (subprod) {
Handle(Expr_GeneralExpression) other;
Handle(Expr_Product) prodop;
Standard_Integer nbsprodop;
for (i=1; i<= max; i++) {
op = Operand(i);
if (op->IsKind(STANDARD_TYPE(Expr_Product))) {
prodop = Handle(Expr_Product)::DownCast(op);
nbsprodop = prodop->NbOperands();
for (Standard_Integer j=1; j<= nbsprodop; j++) {
other = prodop->Operand(j);
newops.Append(other);
}
}
else {
newops.Append(op);
}
}
prodop = new Expr_Product(newops);
return prodop->ShallowSimplified();
}
Standard_Boolean noone = Standard_True;
for (i = 1; i <= max ; i++) {
op = Operand(i);
if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
// numeric operands are cumulated separetly
Handle(Expr_NumericValue) NVop = Handle(Expr_NumericValue)::DownCast(op);
if (nbvals == 0) {
noone = Standard_False;
vals = NVop->GetValue();
nbvals =1;
}
else {
nbvals++;
vals = vals * NVop->GetValue();
}
}
else {
newops.Append(op);
}
}
if (!noone) {
// numeric operands encountered
if (newops.IsEmpty()) { // result is only numericvalue (even zero)
// only numerics
return new Expr_NumericValue(vals);
}
if (vals != 0.0) {
if (vals == 1.0) {
if (newops.Length() == 1) {
return newops(1);
}
return new Expr_Product(newops);
}
if (vals == -1.0) {
Handle(Expr_GeneralExpression) thefact;
if (newops.Length() == 1) {
thefact = newops(1);
}
else {
thefact = new Expr_Product(newops);
}
return -(thefact);
}
if (nbvals == 1) {
Handle(Expr_Product) me = this;
return me;
}
Handle(Expr_NumericValue) thevals = new Expr_NumericValue(vals);
newops.Append(thevals); // non-zero value added
return new Expr_Product(newops);
}
else {
return new Expr_NumericValue(vals); // zero absorb
}
}
Handle(Expr_Product) me = this;
return me;
}
Standard_Real Expr_Product::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
Standard_Integer max = NbOperands();
Standard_Real res = 1.0;
for (Standard_Integer i=1;i<=max;i++) {
res = res * Operand(i)->Evaluate(vars,vals);
}
return res;
}
TCollection_AsciiString Expr_Product::String() const
{
Handle(Expr_GeneralExpression) op;
Standard_Integer nbop = NbOperands();
op = Operand(1);
TCollection_AsciiString str;
if (op->NbSubExpressions() > 1) {
str = "(";
str += op->String();
str += ")";
}
else {
str = op->String();
}
for (Standard_Integer i=2; i<=nbop; i++) {
str += "*";
op = Operand(i);
if (op->NbSubExpressions() > 1) {
str += "(";
str += op->String();
str += ")";
}
else {
str += op->String();
}
}
return str;
}

48
src/Expr/Expr_RUIterator.cdl Executable file
View File

@@ -0,0 +1,48 @@
-- File: RUIterator.cdl
-- Created: Wed Feb 6 16:39:20 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class RUIterator from Expr
---Purpose: Iterates on NamedUnknowns in a GeneralRelation.
---Level : Internal
uses GeneralRelation from Expr,
NamedUnknown from Expr,
MapOfNamedUnknown from Expr
raises NoMoreObject from Standard,
NoSuchObject from Standard
is
Create(rel : GeneralRelation)
---Purpose: Creates an iterator on every NamedUnknown contained in
-- <rel>.
returns RUIterator;
More(me)
---Purpose: Returns False if on other unknown remains.
returns Boolean
is static;
Next(me : in out)
raises NoMoreObject
is static;
Value(me)
---Purpose: Returns current NamedUnknown.
-- Raises exception if no more unknowns remain.
returns NamedUnknown
raises NoSuchObject
is static;
fields
myMap : MapOfNamedUnknown;
myCurrent : Integer;
end RUIterator;

61
src/Expr/Expr_RUIterator.cxx Executable file
View File

@@ -0,0 +1,61 @@
//static const char* sccsid = "@(#)Expr_RUIterator.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_RUIterator.cxx
// Created: Thu Jun 13 17:17:50 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_RUIterator.ixx>
#include <Standard_NoMoreObject.hxx>
#include <Standard_NoSuchObject.hxx>
#include <Expr_RelationIterator.hxx>
#include <Expr_UnknownIterator.hxx>
#include <Expr_SingleRelation.hxx>
#include <Expr.hxx>
Expr_RUIterator::Expr_RUIterator (const Handle(Expr_GeneralRelation)& rel)
{
Expr_RelationIterator ri(rel);
Handle(Expr_SingleRelation) srel;
Handle(Expr_NamedUnknown) var;
myCurrent =1;
while (ri.More()) {
srel = ri.Value();
ri.Next();
Expr_UnknownIterator ui1(srel->FirstMember());
while (ui1.More()) {
var = ui1.Value();
ui1.Next();
if (!myMap.Contains(var)) {
myMap.Add(var);
}
}
Expr_UnknownIterator ui2(srel->SecondMember());
while (ui2.More()) {
var = ui2.Value();
ui2.Next();
if (!myMap.Contains(var)) {
myMap.Add(var);
}
}
}
}
Standard_Boolean Expr_RUIterator::More () const
{
return (myCurrent <= myMap.Extent());
}
void Expr_RUIterator::Next ()
{
if (!More()) {
Standard_NoMoreObject::Raise();
}
myCurrent++;
}
Handle(Expr_NamedUnknown) Expr_RUIterator::Value () const
{
return myMap(myCurrent);
}

View File

@@ -0,0 +1,47 @@
-- File: RelationIterator.cdl
-- Created: Mon Jan 14 10:02:45 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class RelationIterator from Expr
---Purpose: Iterates on every basic relation contained in
-- a GeneralRelation.
---Level : Internal
uses GeneralRelation from Expr,
SingleRelation from Expr,
Array1OfSingleRelation from Expr
raises NoMoreObject from Standard,
NoSuchObject from Standard
is
Create(rel : GeneralRelation)
returns RelationIterator;
More(me)
---Purpose: Returns False if no other relation remains.
returns Boolean
is static;
Next(me : in out)
raises NoMoreObject
is static;
Value(me)
---Purpose: Returns current basic relation.
-- Exception is raised if no more relation remains.
returns SingleRelation
raises NoSuchObject
is static;
fields
myRelation : Array1OfSingleRelation;
current : Integer;
end RelationIterator;

View File

@@ -0,0 +1,60 @@
//static const char* sccsid = "@(#)Expr_RelationIterator.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_RelationIterator.cxx
// Created: Thu Jun 13 16:57:35 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_RelationIterator.ixx>
#include <Standard_NoMoreObject.hxx>
#include <Standard_NoSuchObject.hxx>
#include <Expr_SystemRelation.hxx>
Expr_RelationIterator::Expr_RelationIterator (const Handle(Expr_GeneralRelation)& rel):myRelation(1,rel->NbOfSingleRelations())
{
if (rel->IsKind(STANDARD_TYPE(Expr_SingleRelation))) {
myRelation(1) = Handle(Expr_SingleRelation)::DownCast(rel);
}
else {
Standard_Integer nbcur = 1;
Handle(Expr_GeneralRelation) currel;
for (Standard_Integer i =1; i<= rel->NbOfSubRelations(); i++) {
currel = rel->SubRelation(i);
if (currel->IsKind(STANDARD_TYPE(Expr_SingleRelation))) {
myRelation(nbcur) = Handle(Expr_SingleRelation)::DownCast(currel);
nbcur++;
}
else {
Expr_RelationIterator subit(currel);
while (subit.More()) {
myRelation(nbcur) = subit.Value();
subit.Next();
nbcur++;
}
}
}
}
current = 1;
}
Standard_Boolean Expr_RelationIterator::More () const
{
return (current <= myRelation.Length());
}
void Expr_RelationIterator::Next ()
{
if (!More()) {
Standard_NoMoreObject::Raise();
}
current++;
}
Handle(Expr_SingleRelation) Expr_RelationIterator::Value () const
{
if (!More()) {
Standard_NoSuchObject::Raise();
}
return myRelation(current);
}

61
src/Expr/Expr_Sign.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: Sign.cdl
-- Created: Mon Jan 14 16:17:57 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class Sign from Expr
inherits UnaryExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp : GeneralExpression)
---Purpose: Creates the sign of <exp>.
returns mutable Sign;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end Sign;

64
src/Expr/Expr_Sign.cxx Executable file
View File

@@ -0,0 +1,64 @@
//static const char* sccsid = "@(#)Expr_Sign.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_Sign.cxx
// Created: Tue May 28 12:54:14 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_Sign.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr.hxx>
Expr_Sign::Expr_Sign (const Handle(Expr_GeneralExpression)& exp)
{
CreateOperand(exp);
}
Handle(Expr_GeneralExpression) Expr_Sign::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) op = Operand();
if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) valop = Handle(Expr_NumericValue)::DownCast(op);
return new Expr_NumericValue(Expr::Sign(valop->GetValue()));
}
Handle(Expr_Sign) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_Sign::Copy () const
{
return new Expr_Sign(Expr::CopyShare(Operand()));
}
Standard_Boolean Expr_Sign::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (!Other->IsKind(STANDARD_TYPE(Expr_Sign))) {
return Standard_False;
}
Handle(Expr_GeneralExpression) op = Operand();
return op->IsIdentical(Other->SubExpression(1));
}
Standard_Boolean Expr_Sign::IsLinear () const
{
return !ContainsUnknowns();
}
Handle(Expr_GeneralExpression) Expr_Sign::Derivative (const Handle(Expr_NamedUnknown)& ) const
{
return new Expr_NumericValue(0.0);
}
Standard_Real Expr_Sign::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
Standard_Real res = Operand()->Evaluate(vars,vals);
return Expr::Sign(res);
}
TCollection_AsciiString Expr_Sign::String() const
{
TCollection_AsciiString str("Sign(");
str += Operand()->String();
str += ")";
return str;
}

61
src/Expr/Expr_Sine.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: Sine.cdl
-- Created: Mon Jan 14 16:18:06 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class Sine from Expr
inherits UnaryExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp : GeneralExpression)
---Purpose: Creates the sine of <exp>.
returns mutable Sine;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end Sine;

77
src/Expr/Expr_Sine.cxx Executable file
View File

@@ -0,0 +1,77 @@
//static const char* sccsid = "@(#)Expr_Sine.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_Sine.cxx
// Created: Tue May 28 13:00:09 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_Sine.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_ArcSine.hxx>
#include <Expr_Cosine.hxx>
#include <Expr_Product.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_Sine::Expr_Sine(const Handle(Expr_GeneralExpression)& exp)
{
CreateOperand(exp);
}
Handle(Expr_GeneralExpression) Expr_Sine::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) myexp = Operand();
if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp);
return new Expr_NumericValue(Sin(myNVexp->GetValue()));
}
if (myexp->IsKind(STANDARD_TYPE(Expr_ArcSine))) {
return myexp->SubExpression(1);
}
Handle(Expr_Sine) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_Sine::Copy () const
{
return new Expr_Sine(Expr::CopyShare(Operand()));
}
Standard_Boolean Expr_Sine::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (Other->IsKind(STANDARD_TYPE(Expr_Sine))) {
Handle(Expr_GeneralExpression) myexp = Operand();
return myexp->IsIdentical(Other->SubExpression(1));
}
return Standard_False;
}
Standard_Boolean Expr_Sine::IsLinear () const
{
return !ContainsUnknowns();
}
Handle(Expr_GeneralExpression) Expr_Sine::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) myexp = Operand();
Handle(Expr_GeneralExpression) myder = myexp->Derivative(X);
Handle(Expr_Cosine) firstder = new Expr_Cosine(Expr::CopyShare(myexp));
Handle(Expr_Product) resu = firstder->ShallowSimplified() * myder;
return resu->ShallowSimplified();
}
Standard_Real Expr_Sine::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
return ::Sin(Operand()->Evaluate(vars,vals));
}
TCollection_AsciiString Expr_Sine::String() const
{
TCollection_AsciiString str("Sin(");
str += Operand()->String();
str += ")";
return str;
}

View File

@@ -0,0 +1,76 @@
-- File: SingleRelation.cdl
-- Created: Mon Jan 14 09:47:16 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
deferred class SingleRelation from Expr
inherits GeneralRelation from Expr
uses GeneralExpression from Expr,
NamedUnknown from Expr,
AsciiString from TCollection
raises OutOfRange
is
SetFirstMember(me :mutable; exp : GeneralExpression)
---Purpose: Defines the first member of the relation
---Level : Internal
is static;
SetSecondMember(me :mutable; exp : GeneralExpression)
---Purpose: Defines the second member of the relation
---Level : Internal
is static;
FirstMember(me)
---Purpose: Returns the first member of the relation
---Level : Internal
returns GeneralExpression
is static;
SecondMember(me)
---Purpose: Returns the second member of the relation
---Level : Internal
returns GeneralExpression
is static;
IsLinear(me)
---Purpose: Tests if <me> is linear between its NamedUnknowns.
returns Boolean
is static;
NbOfSubRelations(me)
---Purpose: Returns the number of relations contained in <me>.
returns Integer
is static;
NbOfSingleRelations(me)
---Purpose: Returns the number of SingleRelations contained in
-- <me> (Always 1).
returns Integer
is static;
SubRelation(me; index : Integer)
---Purpose: Returns the relation denoted by <index> in <me>.
-- An exception is raised if index is out of range.
returns any GeneralRelation
raises OutOfRange
is static;
Contains(me; exp : GeneralExpression)
---Purpose: Tests if <me> contains <exp>.
returns Boolean;
Replace(me : mutable ; var : NamedUnknown ; with : GeneralExpression);
---Purpose: Replaces all occurences of <var> with <with> in <me>.
fields
myFirstMember : GeneralExpression;
mySecondMember : GeneralExpression;
end SingleRelation;

View File

@@ -0,0 +1,91 @@
//static const char* sccsid = "@(#)Expr_SingleRelation.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_SingleRelation.cxx
// Created: Mon Jun 10 17:41:30 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_SingleRelation.ixx>
#include <Standard_OutOfRange.hxx>
void Expr_SingleRelation::SetFirstMember (const Handle(Expr_GeneralExpression)& exp)
{
myFirstMember = exp;
}
void Expr_SingleRelation::SetSecondMember (const Handle(Expr_GeneralExpression)& exp)
{
mySecondMember = exp;
}
Handle(Expr_GeneralExpression) Expr_SingleRelation::FirstMember () const
{
return myFirstMember;
}
Handle(Expr_GeneralExpression) Expr_SingleRelation::SecondMember () const
{
return mySecondMember;
}
Standard_Boolean Expr_SingleRelation::IsLinear () const
{
if (!myFirstMember->IsLinear()) {
return Standard_False;
}
if (!mySecondMember->IsLinear()) {
return Standard_False;
}
return Standard_True;
}
Standard_Boolean Expr_SingleRelation::Contains(const Handle(Expr_GeneralExpression)& exp) const
{
if (myFirstMember == exp) {
return Standard_True;
}
if (mySecondMember == exp) {
return Standard_True;
}
if (myFirstMember->Contains(exp)) {
return Standard_True;
}
return mySecondMember->Contains(exp);
}
void Expr_SingleRelation::Replace(const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with)
{
if (myFirstMember == var) {
SetFirstMember(with);
}
else {
if (myFirstMember->Contains(var)) {
myFirstMember->Replace(var,with);
}
}
if (mySecondMember == var) {
SetSecondMember(with);
}
else {
if (mySecondMember->Contains(var)) {
mySecondMember->Replace(var,with);
}
}
}
Standard_Integer Expr_SingleRelation::NbOfSubRelations () const
{
return 0;
}
Handle(Expr_GeneralRelation) Expr_SingleRelation::SubRelation (const Standard_Integer ) const
{
Standard_OutOfRange::Raise();
Handle(Expr_GeneralRelation) bid;
return bid;
}
Standard_Integer Expr_SingleRelation::NbOfSingleRelations() const
{
return 1;
}

61
src/Expr/Expr_Sinh.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: Sinh.cdl
-- Created: Mon Jan 14 16:18:16 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class Sinh from Expr
inherits UnaryExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp : GeneralExpression)
---Purpose: Creates the sinh of <exp>.
returns mutable Sinh;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end Sinh;

78
src/Expr/Expr_Sinh.cxx Executable file
View File

@@ -0,0 +1,78 @@
//static const char* sccsid = "@(#)Expr_Sinh.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_Sinh.cxx
// Created: Tue May 28 13:05:53 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_Sinh.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_ArgSinh.hxx>
#include <Expr_Cosh.hxx>
#include <Expr_Product.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_Sinh::Expr_Sinh(const Handle(Expr_GeneralExpression)& exp)
{
CreateOperand(exp);
}
Handle(Expr_GeneralExpression) Expr_Sinh::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) myexp = Operand();
if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp);
return new Expr_NumericValue(Sinh(myNVexp->GetValue()));
}
if (myexp->IsKind(STANDARD_TYPE(Expr_ArgSinh))) {
return myexp->SubExpression(1);
}
Handle(Expr_Sinh) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_Sinh::Copy () const
{
return new Expr_Sinh(Expr::CopyShare(Operand()));
}
Standard_Boolean Expr_Sinh::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (Other->IsKind(STANDARD_TYPE(Expr_Sinh))) {
Handle(Expr_GeneralExpression) myexp = Operand();
return myexp->IsIdentical(Other->SubExpression(1));
}
return Standard_False;
}
Standard_Boolean Expr_Sinh::IsLinear () const
{
return !ContainsUnknowns();
}
Handle(Expr_GeneralExpression) Expr_Sinh::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) myexp = Operand();
Handle(Expr_GeneralExpression) myder = myexp->Derivative(X);
Handle(Expr_Cosh) firstder = new Expr_Cosh(Expr::CopyShare(myexp));
Handle(Expr_Product) resu = firstder->ShallowSimplified() * myder;
return resu->ShallowSimplified();
}
Standard_Real Expr_Sinh::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
Standard_Real val = Operand()->Evaluate(vars,vals);
return (::Exp(val)-::Exp(-val))/2.0;
}
TCollection_AsciiString Expr_Sinh::String() const
{
TCollection_AsciiString str("Sinh(");
str += Operand()->String();
str += ")";
return str;
}

61
src/Expr/Expr_Square.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: Square.cdl
-- Created: Mon Jan 14 15:19:06 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class Square from Expr
inherits UnaryExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp : GeneralExpression)
---Purpose: Creates the square of <exp>.
returns mutable Square;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>.
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end Square;

103
src/Expr/Expr_Square.cxx Executable file
View File

@@ -0,0 +1,103 @@
//static const char* sccsid = "@(#)Expr_Square.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_Square.cxx
// Created: Fri Apr 19 10:05:26 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_Square.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_SquareRoot.hxx>
#include <Expr_SequenceOfGeneralExpression.hxx>
#include <Expr_Product.hxx>
#include <Expr_Exponentiate.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_Square::Expr_Square (const Handle(Expr_GeneralExpression)& exp)
{
CreateOperand(exp);
}
Handle(Expr_GeneralExpression) Expr_Square::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) myexp = Operand();
if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp);
return new Expr_NumericValue(Square(myNVexp->GetValue()));
}
if (myexp->IsKind(STANDARD_TYPE(Expr_SquareRoot))) {
return myexp->SubExpression(1);
}
if (myexp->IsKind(STANDARD_TYPE(Expr_Square))) {
Handle(Expr_GeneralExpression) op = myexp->SubExpression(1);
Handle(Expr_NumericValue) val4 = new Expr_NumericValue(4.0);
return new Expr_Exponentiate(op,val4);
}
if (myexp->IsKind(STANDARD_TYPE(Expr_Exponentiate))) {
Handle(Expr_GeneralExpression) op = myexp->SubExpression(1);
Handle(Expr_GeneralExpression) puis = myexp->SubExpression(2);
Handle(Expr_Product) newpuis = 2.0 * puis;
Handle(Expr_Exponentiate) res = new Expr_Exponentiate(op,newpuis->ShallowSimplified());
return res->ShallowSimplified();
}
Handle(Expr_Square) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_Square::Copy () const
{
return new Expr_Square(Expr::CopyShare(Operand()));
}
Standard_Boolean Expr_Square::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (Other->IsKind(STANDARD_TYPE(Expr_Square))) {
return Operand()->IsIdentical(Other->SubExpression(1));
}
return Standard_False;
}
Standard_Boolean Expr_Square::IsLinear () const
{
return !ContainsUnknowns();
}
Handle(Expr_GeneralExpression) Expr_Square::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) myder = Operand();
myder = myder->Derivative(X);
Handle(Expr_NumericValue) coef = new Expr_NumericValue(2.0);
Expr_SequenceOfGeneralExpression ops;
ops.Append(coef);
ops.Append(myder);
Handle(Expr_GeneralExpression) usedop = Expr::CopyShare(Operand());
ops.Append(usedop);
Handle(Expr_Product) resu = new Expr_Product(ops);
return resu->ShallowSimplified();
}
Standard_Real Expr_Square::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
Standard_Real val = Operand()->Evaluate(vars,vals);
return val*val;
}
TCollection_AsciiString Expr_Square::String() const
{
TCollection_AsciiString str;
Handle(Expr_GeneralExpression) op = Operand();
if (op->NbSubExpressions() > 1) {
str = "(";
str += op->String();
str += ")^2";
}
else {
str = op->String();
str += "^2";
}
return str;
}

61
src/Expr/Expr_SquareRoot.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: SquareRoot.cdl
-- Created: Mon Jan 14 16:17:49 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class SquareRoot from Expr
inherits UnaryExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp : GeneralExpression)
---Purpose: Creates the square root of <exp>
returns mutable SquareRoot;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>.
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end SquareRoot;

78
src/Expr/Expr_SquareRoot.cxx Executable file
View File

@@ -0,0 +1,78 @@
//static const char* sccsid = "@(#)Expr_SquareRoot.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_Root.cxx
// Created: Tue May 28 12:39:37 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_SquareRoot.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_Square.hxx>
#include <Expr_Product.hxx>
#include <Expr_Division.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_SquareRoot::Expr_SquareRoot (const Handle(Expr_GeneralExpression)& exp)
{
CreateOperand(exp);
}
Handle(Expr_GeneralExpression) Expr_SquareRoot::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) myexp = Operand();
if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp);
return new Expr_NumericValue(Sqrt(myNVexp->GetValue()));
}
if (myexp->IsKind(STANDARD_TYPE(Expr_Square))) {
return myexp->SubExpression(1);
}
Handle(Expr_SquareRoot) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_SquareRoot::Copy () const
{
return new Expr_SquareRoot(Expr::CopyShare(Operand()));
}
Standard_Boolean Expr_SquareRoot::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (Other->IsKind(STANDARD_TYPE(Expr_SquareRoot))) {
return Operand()->IsIdentical(Other->SubExpression(1));
}
return Standard_False;
}
Standard_Boolean Expr_SquareRoot::IsLinear () const
{
return !ContainsUnknowns();
}
Handle(Expr_GeneralExpression) Expr_SquareRoot::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) myexp = Operand();
Handle(Expr_GeneralExpression) myder = myexp->Derivative(X);
Handle(Expr_SquareRoot) sq = new Expr_SquareRoot(Expr::CopyShare(myexp));
Handle(Expr_Product) theprod = 2.0 * sq;
Handle(Expr_Division) resu = myder / theprod->ShallowSimplified();
return resu->ShallowSimplified();
}
Standard_Real Expr_SquareRoot::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
return ::Sqrt(Operand()->Evaluate(vars,vals));
}
TCollection_AsciiString Expr_SquareRoot::String() const
{
TCollection_AsciiString str("Sqrt(");
str += Operand()->String();
str += ")";
return str;
}

74
src/Expr/Expr_Sum.cdl Executable file
View File

@@ -0,0 +1,74 @@
-- File: Sum.cdl
-- Created: Mon Jan 14 16:20:37 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class Sum from Expr
inherits PolyExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
NamedUnknown from Expr,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
SequenceOfGeneralExpression from Expr
raises OutOfRange from Standard,
NumericError from Standard,
NotEvaluable from Expr
is
Create(exps : SequenceOfGeneralExpression)
---Purpose: Creates the sum of all the members of sequence <exps>.
returns mutable Sum;
Create(exp1,exp2 : GeneralExpression)
---Purpose: Creates the sum of <exp1> and <exp2>.
returns mutable Sum;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>.
returns any GeneralExpression;
NDerivative(me; X : NamedUnknown; N : Integer)
---Purpose: Returns the <N>-th derivative on <X> unknown of <me>.
-- Raises OutOfRange if <N> <= 0
returns any GeneralExpression
raises OutOfRange
is redefined;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end Sum;

240
src/Expr/Expr_Sum.cxx Executable file
View File

@@ -0,0 +1,240 @@
//static const char* sccsid = "@(#)Expr_Sum.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_Sum.cxx
// Created: Fri Apr 19 09:34:35 1991
// Author: Arnaud BOUZY
// <adn>
#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#endif
#include <Expr_Sum.ixx>
#include <Standard_OutOfRange.hxx>
#include <TColStd_Array1OfInteger.hxx>
#include <Expr_NumericValue.hxx>
#include <Expr.hxx>
Expr_Sum::Expr_Sum (const Expr_SequenceOfGeneralExpression& exps)
{
Standard_Integer i;
Standard_Integer max = exps.Length();
for (i=1; i<= max; i++) {
AddOperand(exps(i));
}
}
Expr_Sum::Expr_Sum (const Handle(Expr_GeneralExpression)& exp1, const Handle(Expr_GeneralExpression)& exp2)
{
AddOperand(exp1);
AddOperand(exp2);
}
Handle(Expr_GeneralExpression) Expr_Sum::Copy () const
{
Expr_SequenceOfGeneralExpression ops;
Standard_Integer i;
Standard_Integer max = NbOperands();
for (i=1; i <= max; i++) {
ops.Append(Expr::CopyShare(Operand(i)));
}
return new Expr_Sum(ops);
}
Standard_Boolean Expr_Sum::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (!Other->IsKind(STANDARD_TYPE(Expr_Sum))) {
return Standard_False;
}
Handle(Expr_Sum) me = this;
Handle(Expr_Sum) SOther = Handle(Expr_Sum)::DownCast(Other);
Standard_Integer max = NbOperands();
if (SOther->NbOperands() != max) {
return Standard_False;
}
Handle(Expr_GeneralExpression) myop;
Handle(Expr_GeneralExpression) hisop;
Standard_Integer i=1;
TColStd_Array1OfInteger tab(1,max);
for (Standard_Integer k=1; k<=max;k++) {
tab(k)=0;
}
Standard_Boolean ident = Standard_True;
while ((i<=max) && (ident)) {
Standard_Integer j=1;
Standard_Boolean found = Standard_False;
myop = Operand(i);
while ((j<=max) && (!found)) {
hisop = SOther->Operand(j);
found = myop->IsIdentical(hisop);
if (found) {
found = (tab(j) == 0);
tab(j)=i;
}
j++;
}
ident = found;
i++;
}
return ident;
}
Standard_Boolean Expr_Sum::IsLinear () const
{
Standard_Boolean result = Standard_True;
Standard_Integer i=1;
Standard_Integer max = NbOperands();
while ((i <= max) && result) {
result = Operand(i)->IsLinear();
i++;
}
return result;
}
Handle(Expr_GeneralExpression) Expr_Sum::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
Expr_SequenceOfGeneralExpression opsder;
Standard_Integer i;
Standard_Integer max = NbOperands();
for (i=1; i<= max; i++) {
opsder.Append(Operand(i)->Derivative(X));
}
Handle(Expr_Sum) deriv = new Expr_Sum(opsder);
return deriv->ShallowSimplified();
}
Handle(Expr_GeneralExpression) Expr_Sum::NDerivative (const Handle(Expr_NamedUnknown)& X, const Standard_Integer N) const
{
if (N <= 0) {
Standard_OutOfRange::Raise();
}
Expr_SequenceOfGeneralExpression opsder;
Standard_Integer i;
Standard_Integer max = NbOperands();
for (i=1; i<= max; i++) {
opsder.Append(Operand(i)->NDerivative(X,N));
}
Handle(Expr_Sum) deriv = new Expr_Sum(opsder);
return deriv->ShallowSimplified();
}
Handle(Expr_GeneralExpression) Expr_Sum::ShallowSimplified () const
{
Standard_Integer i;
Standard_Integer max = NbOperands();
Standard_Integer nbvals =0;
Handle(Expr_GeneralExpression) op;
Expr_SequenceOfGeneralExpression newops;
Standard_Boolean subsum = Standard_False;
for (i=1; (i<= max) && !subsum; i++) {
op = Operand(i);
subsum = op->IsKind(STANDARD_TYPE(Expr_Sum));
}
if (subsum) {
Handle(Expr_GeneralExpression) other;
Handle(Expr_Sum) sumop;
Standard_Integer nbssumop;
for (i=1; i<= max; i++) {
op = Operand(i);
if (op->IsKind(STANDARD_TYPE(Expr_Sum))) {
sumop = Handle(Expr_Sum)::DownCast(op);
nbssumop = sumop->NbOperands();
for (Standard_Integer j=1; j<= nbssumop; j++) {
other = sumop->Operand(j);
newops.Append(other);
}
}
else {
newops.Append(op);
}
}
sumop = new Expr_Sum(newops);
return sumop->ShallowSimplified();
}
#ifndef DEB
Standard_Real vals = 0.;
#else
Standard_Real vals;
#endif
Standard_Boolean noone = Standard_True;
for (i = 1; i <= max ; i++) {
op = Operand(i);
if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) NVop = Handle(Expr_NumericValue)::DownCast(op);
if (nbvals == 0) {
noone = Standard_False;
vals = NVop->GetValue();
nbvals = 1;
}
else {
vals = vals + NVop->GetValue();
nbvals++;
}
}
else {
newops.Append(op);
}
}
if (!noone) {
if (newops.IsEmpty()) { // result is only numericvalue (even zero)
return new Expr_NumericValue(vals);
}
if (vals != 0.0) {
if (nbvals == 1) {
Handle(Expr_Sum) me = this;
return me;
}
Handle(Expr_NumericValue) thevals = new Expr_NumericValue(vals);
newops.Append(thevals); // non-zero value added
return new Expr_Sum(newops);
}
if (newops.Length() == 1) {
// case X + 0
return newops(1);
}
return new Expr_Sum(newops);
}
Handle(Expr_Sum) me = this;
return me;
}
Standard_Real Expr_Sum::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
Standard_Integer max = NbOperands();
Standard_Real res = 0.0;
for (Standard_Integer i=1; i<= max; i++) {
res = res + Operand(i)->Evaluate(vars,vals);
}
return res;
}
TCollection_AsciiString Expr_Sum::String() const
{
Handle(Expr_GeneralExpression) op;
Standard_Integer nbop = NbOperands();
op = Operand(1);
TCollection_AsciiString str;
if (op->NbSubExpressions() > 1) {
str = "(";
str += op->String();
str += ")";;
}
else {
str = op->String();
}
for (Standard_Integer i=2; i<=nbop; i++) {
str += "+";
op = Operand(i);
if (op->NbSubExpressions() > 1) {
str += "(";
str += op->String();
str += ")";;
}
else {
str += op->String();
}
}
return str;
}

View File

@@ -0,0 +1,93 @@
-- File: SystemRelation.cdl
-- Created: Mon Jan 14 09:50:50 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class SystemRelation from Expr
inherits GeneralRelation from Expr
uses SequenceOfGeneralRelation from Expr,
GeneralExpression from Expr,
NamedUnknown from Expr,
AsciiString from TCollection
raises OutOfRange,NoSuchObject,DimensionMismatch,NumericError
is
Create(relation : GeneralRelation)
---Purpose: Creates a system with one relation
---Level : Advanced
returns mutable SystemRelation;
Add(me : mutable; relation : GeneralRelation)
---Purpose: Appends <relation> in the list of components of <me>.
---Level : Advanced
is static;
Remove(me : mutable; relation : GeneralRelation)
---Level : Internal
raises NoSuchObject,DimensionMismatch
is static;
IsLinear(me)
---Purpose: Tests if <me> is linear between its NamedUnknowns.
returns Boolean
is static;
NbOfSubRelations(me)
---Purpose: Returns the number of relations contained in <me>.
returns Integer
is static;
NbOfSingleRelations(me)
---Purpose: Returns the number of SingleRelations contained in
-- <me>.
returns Integer
is static;
SubRelation(me; index : Integer)
---Purpose: Returns the relation denoted by <index> in <me>.
-- An exception is raised if <index> is out of range.
returns any GeneralRelation
raises OutOfRange
is static;
IsSatisfied(me)
returns Boolean;
Simplified(me)
---Purpose: Returns a GeneralRelation after replacement of
-- NamedUnknowns by an associated expression, and after
-- values computation.
returns mutable GeneralRelation
raises NumericError;
Simplify(me : mutable)
---Purpose: Replaces NamedUnknowns by associated expressions,
-- and computes values in <me>.
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
Contains(me; exp : GeneralExpression)
---Purpose: Tests if <me> contains <exp>.
returns Boolean;
Replace(me : mutable ; var : NamedUnknown ; with : GeneralExpression);
---Purpose: Replaces all occurences of <var> with <with> in <me>.
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
fields
myRelations : SequenceOfGeneralRelation;
end SystemRelation;

154
src/Expr/Expr_SystemRelation.cxx Executable file
View File

@@ -0,0 +1,154 @@
//static const char* sccsid = "@(#)Expr_SystemRelation.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_SystemRelation.cxx
// Created: Thu Jun 13 14:01:02 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_SystemRelation.ixx>
#include <Standard_NoSuchObject.hxx>
#include <Standard_OutOfRange.hxx>
#include <Standard_DimensionMismatch.hxx>
Expr_SystemRelation::Expr_SystemRelation (const Handle(Expr_GeneralRelation)& relation)
{
myRelations.Append(relation);
}
void Expr_SystemRelation::Add (const Handle(Expr_GeneralRelation)& relation)
{
myRelations.Append(relation);
}
void Expr_SystemRelation::Remove (const Handle(Expr_GeneralRelation)& relation)
{
Standard_Integer position = 0;
Standard_Boolean alreadyHere = Standard_False;
for (Standard_Integer i = 1; i <= myRelations.Length() && !alreadyHere; i++) {
if (myRelations.Value(i) == relation) {
alreadyHere = Standard_True;
position = i;
}
}
if (alreadyHere) {
Standard_NoSuchObject::Raise();
}
if (myRelations.Length() <= 1) {
Standard_DimensionMismatch::Raise();
}
myRelations.Remove(position);
}
Standard_Boolean Expr_SystemRelation::IsLinear () const
{
Standard_Integer len = myRelations.Length();
for (Standard_Integer i = 1; i<= len; i++) {
if (!myRelations(i)->IsLinear()) {
return Standard_False;
}
}
return Standard_True;
}
Standard_Boolean Expr_SystemRelation::Contains(const Handle(Expr_GeneralExpression)& exp) const
{
for (Standard_Integer i=1; i<= myRelations.Length(); i++) {
if (myRelations(i)->Contains(exp)) {
return Standard_True;
}
}
return Standard_False;
}
void Expr_SystemRelation::Replace(const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with)
{
for (Standard_Integer i=1; i<= myRelations.Length(); i++) {
myRelations(i)->Replace(var,with);
}
}
Standard_Integer Expr_SystemRelation::NbOfSubRelations () const
{
return myRelations.Length();
}
Handle(Expr_GeneralRelation) Expr_SystemRelation::SubRelation (const Standard_Integer index) const
{
return myRelations(index);
}
Standard_Boolean Expr_SystemRelation::IsSatisfied () const
{
Standard_Integer len = myRelations.Length();
for (Standard_Integer i = 1; i<= len; i++) {
if (!myRelations(i)->IsSatisfied()) {
return Standard_False;
}
}
return Standard_True;
}
Handle(Expr_GeneralRelation) Expr_SystemRelation::Simplified () const
{
Standard_Integer len = myRelations.Length();
Handle(Expr_GeneralRelation) rel;
rel = myRelations(1);
Handle(Expr_SystemRelation) result = new Expr_SystemRelation(rel->Simplified());
for (Standard_Integer i = 2; i<= len; i++) {
rel = myRelations(i);
rel = rel->Simplified();
result->Add(rel);
}
return result;
}
void Expr_SystemRelation::Simplify ()
{
Standard_Integer len = myRelations.Length();
Handle(Expr_GeneralRelation) rel;
for (Standard_Integer i = 1; i<= len; i++) {
rel = myRelations(i);
rel->Simplify();
}
}
Handle(Expr_GeneralRelation) Expr_SystemRelation::Copy () const
{
Handle(Expr_SystemRelation) cop = new Expr_SystemRelation(myRelations(1)->Copy());
Standard_Integer len = myRelations.Length();
for (Standard_Integer i = 2; i<= len; i++) {
cop->Add(myRelations(i)->Copy());
}
return cop;
}
Standard_Integer Expr_SystemRelation::NbOfSingleRelations() const
{
Standard_Integer nbsing = 0;
Standard_Integer nbrel = myRelations.Length();
Handle(Expr_GeneralRelation) subrel;
for (Standard_Integer i = 1; i<= nbrel ; i++) {
subrel = myRelations(i);
nbsing = nbsing + subrel->NbOfSingleRelations();
}
return nbsing;
}
TCollection_AsciiString Expr_SystemRelation::String() const
{
Standard_Integer nbrel = myRelations.Length();
Handle(Expr_GeneralRelation) subrel;
TCollection_AsciiString res;
for (Standard_Integer i = 1; i<= nbrel ; i++) {
res += myRelations(i)->String();
if (i != nbrel) {
res += TCollection_AsciiString('\n');
}
}
return res;
}

61
src/Expr/Expr_Tangent.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: Tangent.cdl
-- Created: Mon Jan 14 16:18:27 1991
-- Author: Arnaud BOUZY
-- <adn@topsn3>
---Copyright: Matra Datavision 1991
class Tangent from Expr
inherits UnaryExpression from Expr
uses GeneralExpression from Expr,
AsciiString from TCollection,
Array1OfNamedUnknown from Expr,
Array1OfReal from TColStd,
NamedUnknown from Expr
raises NumericError from Standard,
NotEvaluable from Expr
is
Create(exp : GeneralExpression)
---Purpose: Creates the tangent of <exp>.
returns mutable Tangent;
ShallowSimplified(me)
---Purpose: Returns a GeneralExpression after a simplification
-- of the arguments of <me>.
returns any GeneralExpression
raises NumericError;
Copy(me)
---Purpose: Returns a copy of <me> having the same unknowns and functions.
returns mutable like me;
IsIdentical(me; Other : GeneralExpression)
---Purpose: Tests if <me> and <Other> define the same expression.
-- This method does not include any simplification before
-- testing.
returns Boolean;
IsLinear(me)
returns Boolean;
Derivative(me; X : NamedUnknown)
---Purpose: Returns the derivative on <X> unknown of <me>
returns any GeneralExpression;
Evaluate(me; vars : Array1OfNamedUnknown; vals : Array1OfReal)
---Purpose: Returns the value of <me> (as a Real) by
-- replacement of <vars> by <vals>.
-- Raises NotEvaluable if <me> contains NamedUnknown not
-- in <vars> or NumericError if result cannot be computed.
returns Real
raises NotEvaluable,NumericError;
String(me)
---Purpose: returns a string representing <me> in a readable way.
returns AsciiString;
end Tangent;

79
src/Expr/Expr_Tangent.cxx Executable file
View File

@@ -0,0 +1,79 @@
//static const char* sccsid = "@(#)Expr_Tangent.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_Tangent.cxx
// Created: Tue May 28 14:30:09 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_Tangent.ixx>
#include <Expr_NumericValue.hxx>
#include <Expr_ArcTangent.hxx>
#include <Expr_Cosine.hxx>
#include <Expr_Square.hxx>
#include <Expr_Division.hxx>
#include <Expr_Operators.hxx>
#include <Expr.hxx>
Expr_Tangent::Expr_Tangent(const Handle(Expr_GeneralExpression)& exp)
{
CreateOperand(exp);
}
Handle(Expr_GeneralExpression) Expr_Tangent::ShallowSimplified () const
{
Handle(Expr_GeneralExpression) myexp = Operand();
if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp);
return new Expr_NumericValue(Tan(myNVexp->GetValue()));
}
if (myexp->IsKind(STANDARD_TYPE(Expr_ArcTangent))) {
return myexp->SubExpression(1);
}
Handle(Expr_Tangent) me = this;
return me;
}
Handle(Expr_GeneralExpression) Expr_Tangent::Copy () const
{
return new Expr_Tangent(Expr::CopyShare(Operand()));
}
Standard_Boolean Expr_Tangent::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
{
if (Other->IsKind(STANDARD_TYPE(Expr_Tangent))) {
Handle(Expr_GeneralExpression) myexp = Operand();
return myexp->IsIdentical(Other->SubExpression(1));
}
return Standard_False;
}
Standard_Boolean Expr_Tangent::IsLinear () const
{
return !ContainsUnknowns();
}
Handle(Expr_GeneralExpression) Expr_Tangent::Derivative (const Handle(Expr_NamedUnknown)& X) const
{
if (!Contains(X)) {
return new Expr_NumericValue(0.0);
}
Handle(Expr_GeneralExpression) myexp = Operand();
Handle(Expr_GeneralExpression) myder = myexp->Derivative(X);
Handle(Expr_Cosine) firstder = new Expr_Cosine(Expr::CopyShare(myexp));
Handle(Expr_Square) sq = new Expr_Square(firstder->ShallowSimplified());
Handle(Expr_Division) resu = myder / sq->ShallowSimplified();
return resu->ShallowSimplified();
}
Standard_Real Expr_Tangent::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
{
return ::Tan(Operand()->Evaluate(vars,vals));
}
TCollection_AsciiString Expr_Tangent::String() const
{
TCollection_AsciiString str("Tan(");
str += Operand()->String();
str +=")";
return str;
}

Some files were not shown because too many files have changed in this diff Show More