1 // Created on: 1991-05-27
2 // Created by: Arnaud BOUZY
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <Expr_ArgTanh.ixx>
23 #include <Expr_NumericValue.hxx>
24 #include <Expr_Tanh.hxx>
25 #include <Expr_Division.hxx>
26 #include <Expr_Square.hxx>
27 #include <Expr_Difference.hxx>
28 #include <Expr_Operators.hxx>
31 Expr_ArgTanh::Expr_ArgTanh (const Handle(Expr_GeneralExpression)& exp)
36 Handle(Expr_GeneralExpression) Expr_ArgTanh::ShallowSimplified () const
38 Handle(Expr_GeneralExpression) op = Operand();
39 if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
40 Handle(Expr_NumericValue) valop = Handle(Expr_NumericValue)::DownCast(op);
41 return new Expr_NumericValue(ATanh(valop->GetValue()));
43 if (op->IsKind(STANDARD_TYPE(Expr_Tanh))) {
44 return op->SubExpression(1);
46 Handle(Expr_ArgTanh) me = this;
50 Handle(Expr_GeneralExpression) Expr_ArgTanh::Copy () const
52 return new Expr_ArgTanh(Expr::CopyShare(Operand()));
55 Standard_Boolean Expr_ArgTanh::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
57 if (!Other->IsKind(STANDARD_TYPE(Expr_ArgTanh))) {
58 return Standard_False;
60 Handle(Expr_GeneralExpression) op = Operand();
61 return op->IsIdentical(Other->SubExpression(1));
64 Standard_Boolean Expr_ArgTanh::IsLinear () const
66 if (ContainsUnknowns()) {
67 return Standard_False;
72 Handle(Expr_GeneralExpression) Expr_ArgTanh::Derivative (const Handle(Expr_NamedUnknown)& X) const
75 return new Expr_NumericValue(0.0);
77 Handle(Expr_GeneralExpression) op = Operand();
78 Handle(Expr_GeneralExpression) derop = op->Derivative(X);
80 Handle(Expr_Square) sq = new Expr_Square(Expr::CopyShare(op));
84 Handle(Expr_Difference) thedif = 1.0 - sq->ShallowSimplified();
86 // ArgTanh'(F(X)) = F'(X)/(1 - F(X)2)
87 Handle(Expr_Division) thediv = derop / thedif->ShallowSimplified();
89 return thediv->ShallowSimplified();
92 Standard_Real Expr_ArgTanh::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
94 Standard_Real val = Operand()->Evaluate(vars,vals);
95 return ::Log((1.0+val)/(1.0-val))/2.0;
98 TCollection_AsciiString Expr_ArgTanh::String() const
100 TCollection_AsciiString str("ATanh(");
101 str += Operand()->String();