1 //static const char* sccsid = "@(#)Expr_Division.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
2 // Copyright: Matra-Datavision 1991
3 // File: Expr_Division.cxx
4 // Created: Wed Apr 17 14:14:22 1991
5 // Author: Arnaud BOUZY
8 #include <Expr_Division.ixx>
9 #include <Expr_Product.hxx>
10 #include <Expr_Square.hxx>
11 #include <Expr_UnaryMinus.hxx>
12 #include <Expr_Difference.hxx>
13 #include <Expr_NumericValue.hxx>
14 #include <Expr_Operators.hxx>
17 Expr_Division::Expr_Division (const Handle(Expr_GeneralExpression)& exp1, const Handle(Expr_GeneralExpression)& exp2)
19 CreateFirstOperand(exp1);
20 CreateSecondOperand(exp2);
23 Handle(Expr_GeneralExpression) Expr_Division::Copy () const
25 return Expr::CopyShare(FirstOperand()) / Expr::CopyShare(SecondOperand());
28 Standard_Boolean Expr_Division::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
30 Standard_Boolean ident = Standard_False;
31 if (Other->IsKind(STANDARD_TYPE(Expr_Division))) {
32 Handle(Expr_GeneralExpression) myfirst = FirstOperand();
33 Handle(Expr_GeneralExpression) mysecond = SecondOperand();
34 Handle(Expr_Division) DOther = Handle(Expr_Division)::DownCast(Other);
35 Handle(Expr_GeneralExpression) fother = DOther->FirstOperand();
36 Handle(Expr_GeneralExpression) sother = DOther->SecondOperand();
37 if (myfirst->IsIdentical(fother) &&
38 mysecond->IsIdentical(sother)) {
39 ident = Standard_True;
45 Standard_Boolean Expr_Division::IsLinear () const
47 Handle(Expr_GeneralExpression) myfirst = FirstOperand();
48 Handle(Expr_GeneralExpression) mysecond = SecondOperand();
49 if (mysecond->IsKind(STANDARD_TYPE(Expr_NamedUnknown)) || mysecond->ContainsUnknowns()) {
50 return Standard_False;
52 return (myfirst->IsLinear() && mysecond->IsLinear());
55 Handle(Expr_GeneralExpression) Expr_Division::Derivative (const Handle(Expr_NamedUnknown)& X) const
58 return new Expr_NumericValue(0.0);
60 Handle(Expr_GeneralExpression) myfirst = FirstOperand();
61 Handle(Expr_GeneralExpression) mysecond = SecondOperand();
62 Handle(Expr_GeneralExpression) myfder = myfirst->Derivative(X);
63 Handle(Expr_GeneralExpression) mysder = mysecond->Derivative(X);
66 Handle(Expr_Product) firstprod = myfder * Expr::CopyShare(mysecond);
68 Handle(Expr_GeneralExpression) firstsimp = firstprod->ShallowSimplified();
70 Handle(Expr_Product) secondprod = Expr::CopyShare(myfirst) * mysder;
71 Handle(Expr_GeneralExpression) secondsimp = secondprod->ShallowSimplified();
73 Handle(Expr_Difference) mynumer = firstsimp - secondsimp;
76 Handle(Expr_Square) mydenom = new Expr_Square(Expr::CopyShare(mysecond));
78 // result = "u'v-uv' / v2"
80 Handle(Expr_GeneralExpression) snumer = mynumer->ShallowSimplified();
81 Handle(Expr_GeneralExpression) sdenom = mydenom->ShallowSimplified();
82 Handle(Expr_Division) result = snumer / sdenom;
84 return result->ShallowSimplified();
87 Handle(Expr_GeneralExpression) Expr_Division::ShallowSimplified () const
89 Handle(Expr_GeneralExpression) myfirst = FirstOperand();
90 Handle(Expr_GeneralExpression) mysecond = SecondOperand();
92 if (myfirst->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
93 Handle(Expr_NumericValue) myNVfirst = Handle(Expr_NumericValue)::DownCast(myfirst);
94 if (myNVfirst->GetValue() == 0.0) {
96 return new Expr_NumericValue(0.0);
98 if (mysecond->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
100 Handle(Expr_NumericValue) myNVsecond = Handle(Expr_NumericValue)::DownCast(mysecond);
101 return new Expr_NumericValue(myNVfirst->GetValue()/myNVsecond->GetValue());
105 if (mysecond->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
107 Handle(Expr_NumericValue) myNVsecond = Handle(Expr_NumericValue)::DownCast(mysecond);
108 if (myNVsecond->GetValue() == 1.0) {
114 Handle(Expr_Division) me = this;
118 Standard_Real Expr_Division::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
120 Standard_Real res = FirstOperand()->Evaluate(vars,vals);
121 return res / SecondOperand()->Evaluate(vars,vals);
124 TCollection_AsciiString Expr_Division::String() const
126 Handle(Expr_GeneralExpression) op1 = FirstOperand();
127 Handle(Expr_GeneralExpression) op2 = SecondOperand();
128 TCollection_AsciiString str;
129 if (op1->NbSubExpressions() > 1) {
131 str += op1->String();
138 if (op2->NbSubExpressions() > 1) {
140 str += op2->String();
144 str += op2->String();