1 // Copyright: Matra-Datavision 1991
2 // File: Expr_UnaryFunction.cxx
3 // Created: Tue May 28 14:40:33 1991
4 // Author: Arnaud BOUZY
8 #define No_Standard_RangeError
9 #define No_Standard_OutOfRange
12 #include <Expr_UnaryFunction.ixx>
13 #include <Expr_InvalidFunction.hxx>
14 #include <Expr_Array1OfNamedUnknown.hxx>
15 #include <Expr_Array1OfGeneralExpression.hxx>
16 #include <Expr_FunctionDerivative.hxx>
17 #include <Expr_Product.hxx>
18 #include <Expr_Operators.hxx>
21 Expr_UnaryFunction::Expr_UnaryFunction (const Handle(Expr_GeneralFunction)& func, const Handle(Expr_GeneralExpression)& exp)
23 if (func->NbOfVariables() != 1) {
24 Expr_InvalidFunction::Raise();
30 Handle(Expr_GeneralFunction) Expr_UnaryFunction::Function () const
35 Handle(Expr_GeneralExpression) Expr_UnaryFunction::ShallowSimplified () const
37 Handle(Expr_GeneralExpression) op = Operand();
38 if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
39 Handle(Expr_NumericValue) nval = Handle(Expr_NumericValue)::DownCast(op);
40 TColStd_Array1OfReal tabval(1,1);
41 tabval(1) = nval->GetValue();
42 Expr_Array1OfNamedUnknown vars(1,1);
43 vars(1) = myFunction->Variable(1);
44 Standard_Real res = myFunction->Evaluate(vars,tabval);
45 return new Expr_NumericValue(res);
47 Handle(Expr_UnaryFunction) me = this;
51 Handle(Expr_GeneralExpression) Expr_UnaryFunction::Copy () const
53 return new Expr_UnaryFunction(myFunction,Expr::CopyShare(Operand()));
56 Standard_Boolean Expr_UnaryFunction::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
58 if (!Other->IsKind(STANDARD_TYPE(Expr_UnaryFunction))) {
59 return Standard_False;
61 Handle(Expr_UnaryFunction) fother = Handle(Expr_UnaryFunction)::DownCast(Other);
62 Handle(Expr_GeneralExpression) otherexp = fother->Operand();
63 if (otherexp->IsIdentical(Operand())) {
64 if (myFunction->IsIdentical(fother->Function())) {
68 return Standard_False;
71 Standard_Boolean Expr_UnaryFunction::IsLinear () const
73 if (!ContainsUnknowns()) {
76 if (!Operand()->IsLinear()) {
77 return Standard_False;
79 return myFunction->IsLinearOnVariable(1);
82 Handle(Expr_GeneralExpression) Expr_UnaryFunction::Derivative (const Handle(Expr_NamedUnknown)& X) const
84 Handle(Expr_NamedUnknown) myvar = myFunction->Variable(1);
85 Handle(Expr_GeneralExpression) myop = Operand();
86 Handle(Expr_GeneralExpression) myexpder = myop->Derivative(X);
87 Handle(Expr_GeneralFunction) myfuncder = myFunction->Derivative(myvar);
88 Handle(Expr_UnaryFunction) firstpart = new Expr_UnaryFunction(myfuncder,Expr::CopyShare(myop));
89 Handle(Expr_Product) resu = firstpart->ShallowSimplified() * myexpder;
90 return resu->ShallowSimplified();
93 Standard_Real Expr_UnaryFunction::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
95 Expr_Array1OfNamedUnknown varsfunc(1,1);
96 varsfunc(1) = myFunction->Variable(1);
97 TColStd_Array1OfReal valsfunc(1,1);
98 valsfunc(1) = Operand()->Evaluate(vars,vals);
99 return myFunction->Evaluate(varsfunc,valsfunc);
102 TCollection_AsciiString Expr_UnaryFunction::String() const
104 TCollection_AsciiString res = myFunction->GetStringName();
106 res += Operand()->String();