1 // Created on: 1991-05-28
2 // Created by: Arnaud BOUZY
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
19 #include <Expr_Division.hxx>
20 #include <Expr_GeneralExpression.hxx>
21 #include <Expr_NamedUnknown.hxx>
22 #include <Expr_NotEvaluable.hxx>
23 #include <Expr_NumericValue.hxx>
24 #include <Expr_Operators.hxx>
25 #include <Expr_Product.hxx>
26 #include <Expr_Square.hxx>
27 #include <Expr_SquareRoot.hxx>
28 #include <Standard_NumericError.hxx>
29 #include <Standard_Type.hxx>
30 #include <TCollection_AsciiString.hxx>
32 IMPLEMENT_STANDARD_RTTIEXT(Expr_SquareRoot,Expr_UnaryExpression)
34 Expr_SquareRoot::Expr_SquareRoot (const Handle(Expr_GeneralExpression)& exp)
39 Handle(Expr_GeneralExpression) Expr_SquareRoot::ShallowSimplified () const
41 Handle(Expr_GeneralExpression) myexp = Operand();
42 if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
43 Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp);
44 return new Expr_NumericValue(Sqrt(myNVexp->GetValue()));
46 if (myexp->IsKind(STANDARD_TYPE(Expr_Square))) {
47 return myexp->SubExpression(1);
49 Handle(Expr_SquareRoot) me = this;
53 Handle(Expr_GeneralExpression) Expr_SquareRoot::Copy () const
55 return new Expr_SquareRoot(Expr::CopyShare(Operand()));
58 Standard_Boolean Expr_SquareRoot::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
60 if (Other->IsKind(STANDARD_TYPE(Expr_SquareRoot))) {
61 return Operand()->IsIdentical(Other->SubExpression(1));
63 return Standard_False;
66 Standard_Boolean Expr_SquareRoot::IsLinear () const
68 return !ContainsUnknowns();
71 Handle(Expr_GeneralExpression) Expr_SquareRoot::Derivative (const Handle(Expr_NamedUnknown)& X) const
74 return new Expr_NumericValue(0.0);
76 Handle(Expr_GeneralExpression) myexp = Operand();
77 Handle(Expr_GeneralExpression) myder = myexp->Derivative(X);
78 Handle(Expr_SquareRoot) sq = new Expr_SquareRoot(Expr::CopyShare(myexp));
79 Handle(Expr_Product) theprod = 2.0 * sq;
80 Handle(Expr_Division) resu = myder / theprod->ShallowSimplified();
81 return resu->ShallowSimplified();
85 Standard_Real Expr_SquareRoot::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
87 return ::Sqrt(Operand()->Evaluate(vars,vals));
90 TCollection_AsciiString Expr_SquareRoot::String() const
92 TCollection_AsciiString str("Sqrt(");
93 str += Operand()->String();