7fd59977 |
1 | // Copyright: Matra-Datavision 1991 |
2 | // File: Expr_Cosh.cxx |
3 | // Created: Mon May 27 15:43:41 1991 |
4 | // Author: Arnaud BOUZY |
5 | // <adn> |
6 | |
7 | #include <Expr_Cosh.ixx> |
8 | #include <Expr_NumericValue.hxx> |
9 | #include <Expr_ArgCosh.hxx> |
10 | #include <Expr_Sinh.hxx> |
11 | #include <Expr_Product.hxx> |
12 | #include <Expr_Operators.hxx> |
13 | #include <Expr.hxx> |
14 | |
15 | Expr_Cosh::Expr_Cosh(const Handle(Expr_GeneralExpression)& exp) |
16 | { |
17 | CreateOperand(exp); |
18 | } |
19 | |
20 | Handle(Expr_GeneralExpression) Expr_Cosh::ShallowSimplified () const |
21 | { |
22 | Handle(Expr_GeneralExpression) myexp = Operand(); |
23 | if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) { |
24 | Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp); |
25 | return new Expr_NumericValue(Cosh(myNVexp->GetValue())); |
26 | } |
27 | if (myexp->IsKind(STANDARD_TYPE(Expr_ArgCosh))) { |
28 | return myexp->SubExpression(1); |
29 | } |
30 | Handle(Expr_Cosh) me = this; |
31 | return me; |
32 | } |
33 | |
34 | Handle(Expr_GeneralExpression) Expr_Cosh::Copy () const |
35 | { |
36 | return new Expr_Cosh(Expr::CopyShare(Operand())); |
37 | } |
38 | |
39 | Standard_Boolean Expr_Cosh::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const |
40 | { |
41 | if (Other->IsKind(STANDARD_TYPE(Expr_Cosh))) { |
42 | Handle(Expr_GeneralExpression) myexp = Operand(); |
43 | return myexp->IsIdentical(Other->SubExpression(1)); |
44 | } |
45 | return Standard_False; |
46 | } |
47 | |
48 | Standard_Boolean Expr_Cosh::IsLinear () const |
49 | { |
50 | return !ContainsUnknowns(); |
51 | } |
52 | |
53 | Handle(Expr_GeneralExpression) Expr_Cosh::Derivative (const Handle(Expr_NamedUnknown)& X) const |
54 | { |
55 | if (!Contains(X)) { |
56 | return new Expr_NumericValue(0.0); |
57 | } |
58 | Handle(Expr_GeneralExpression) myexp = Operand(); |
59 | Handle(Expr_GeneralExpression) myder = myexp->Derivative(X); |
60 | Handle(Expr_Sinh) firstder = new Expr_Sinh(Expr::CopyShare(myexp)); |
61 | |
62 | Handle(Expr_Product) resu = firstder->ShallowSimplified() * myder; |
63 | return resu->ShallowSimplified(); |
64 | } |
65 | |
66 | Standard_Real Expr_Cosh::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const |
67 | { |
68 | Standard_Real val = Operand()->Evaluate(vars,vals); |
69 | return (::Exp(val)+::Exp(-val))/2.0; |
70 | } |
71 | |
72 | TCollection_AsciiString Expr_Cosh::String() const |
73 | { |
74 | TCollection_AsciiString str("Cosh("); |
75 | str += Operand()->String(); |
76 | str += ")"; |
77 | return str; |
78 | } |