Math Symbolic Class

Public Function InfixToBasic( _ ByVal vExpr As Variant _ ) As Variant

"Infix Expression To Basic Language Expression"

We used this function to help implement some of the more complicated solutions within Geometric calculator functions. This program turns the Derive-compatible algebraic expressions into a series of sub-calculations. Most repetitive sub-expressions are replaced by 1) a single calculations and variable assignment, and 2) two or more references to the value of that variable.

? InfixToBasic("2*SQRT(b^2-3*a*c)*COS(ATAN(SQRT(3)*(27*a^2*d-9*a*b*c+2*b^3)/(9*a*(b^2-3*a*c)^(3/2)*SQRT((27*a^2*d^2+2*a*c*(2*c^2-9*b*d)+b^2*(4*b*d-c^2))/(3*a*c-b^2)^3)))/3+pi/6)/(3*ABS(a))-b/(3*a)") Dim N() As Variant ReDim N(1 To 54) N(1) = Square(b) N(2) = Mult(3,a) N(3) = Mult(N(2),c) N(4) = Subtract(N(1),N(3)) N(8) = Square(a) N(9) = Mult(27,N(8)) N(11) = Mult(9,a) N(26) = Square(c) Subtract(Div(Mult(Mult(2,Sqrt(N(4))),Cosine(Addit(Div(ATan(Div(Mult(Sqrt(3),Addit(Subtract(Mult(N(9),d),Mult(Mult(N(11),b),c)),Mult(2,Power(b,3)))),Mult(Mult(N(11),Power(N(4),Div(3,2))),Sqrt(Div(Addit(Addit(Mult(N(9),Square(d)),Mult(Mult(Mult(2,a),c),Subtract(Mult(2,N(26)),Mult(Mult(9,b),d)))),Mult(N(1),Subtract(Mult(Mult(4,b),d),N(26)))),Power(Subtract(N(3),N(1)),3)))))),3),Div(pi,6)))),Mult(3,Absolute(a))),Div(b,N(2)))

InfixToPrefix Function InfixToPostfix Function BreakParentheses Function RationalComplexToVBExpr Function

**Note:** This translation task is necessarily complicated, and the implementation of this function is not the best. **Note:** Function has a basic problem in that some unused variables within the calculation sequence are not reused. For example, after several "assignment calculation to variable" code lines, one or more of those variables may no longer be needed for future calculations, but they are no reused. **Note:** This algorithm has a basic problem in that it does not produce an optimized set of calculations. It produces an accurate translation (as far as we know), but that translation does not represent the absolute minimum number of calculations required to evaluate the expression. **Note:** Function will return an error in the form of a string like "Error: Expected one operand." if the algebraic (infix) expression is ill-formed. The possible errors include: **Error:** Expected one operand. (Function has encountered a function call so it needs an operand but the operand stack is empty.) **Error:** Expected two operands. (Function has encountered a binary operator so it needs two operands but the operand stack has less than two operands.) **Error:** Expected end of expression. (Function has encountered the end of the input expression but there are still operands on the stack.)

**Note:** This function creates a one-dimensional array of Variant values (within the result string) which it uses to store the intermediate values (the results of the redundant sub-expression calculations).

**Translations:** As well as attempting to break-out the repeated sub-expressions, this function performs some other translations on various Derive constants, operators, and functions. These translations are detailed in the following tables.

**Constants:**

From To -------------- PI Pi #e e #i "0|1"

From To -------------- + Addit - Subtract * Mult / Div ^ Power

From To -------------- ABS( Absolute( ASIN( ASin( ATAN( ATan( COS( Cosine( LN( Logarithm( SIGN( Sign( SINE( Sine( SQRT( Sqrt( TAN( Tangent(

Copyright 1996-1999 Entisoft

Entisoft Tools is a trademark of Entisoft.