home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / calculat / sm30a.zip / SYMBMATH.H09 < prev    next >
Text File  |  1993-11-07  |  7KB  |  151 lines

  1.             3.2.   Expressions
  2.     Expressions (i.e. expr) are made up of operators and operands.
  3. Most operator are binary, that is, they take two operands; the rest
  4. are unary and take only one operand. Binary operators use the usal
  5. algebraic form, e.g. a+b.
  6.     There are two kinds of expressions: numeric and Boolean. The
  7. numeric expression is combination of data and algebraic operators while
  8. the Boolean expression is combination of data and relational operators
  9. and logic operators. These two kinds of expressions can be mixed, but
  10. the numeric expression has higher priority than Boolean operators.
  11. x*(x>0) is different from x*x>0. x*x>0 is the same as (x*x)>0.
  12.  
  13. e.g.
  14. a+b+3           numeric expression,
  15. a>0             Boolean expression
  16. a>0 and b>0     Boolean expression
  17. (x>0)*x         mixed numeric and Boolean expression
  18.  
  19.                         3.2.1   Operators
  20.  
  21.     Table 3.2.1       Operators
  22. -----------------------------------------------------------------
  23. Operation               Operators       Examples        Order
  24.  
  25. comma                   ,               a:=2, b:=3      1
  26. assignment              :=              p:=2+3          2
  27. and                     and             a>2 and a<8     2
  28. or                      or              a>2 or b>2      2
  29. equation                =               x^2+x+1 = 0     3
  30. equal                   ==              a==2            3
  31. larger than             >               a>2             3
  32. larger and equal        >=              a>=2            3
  33. less than               <               a<2             3
  34. less and equal          <=              a<=2            3
  35. unequal                 <>              a<>2            3
  36. plus                    +               a+b             4
  37. minus                   -               a-b             4
  38. mutilation              *               a*b             5
  39. division                /               a/b             5
  40. power                   ^               a^b             6
  41. power                   **              a**b            6
  42. factorial               !               n!              6
  43. positive                +               +a              7
  44. negative                -               -a              7
  45. function                f()             sin(x)          7
  46. list index              f[]             f[1]            7
  47. parentheses             ()              (a+b)*c         7
  48. list                    []              [a,b]           7
  49. --------------------------------------------------------------------
  50.  
  51.     All functions have the same 7th order.
  52.     Operations with higher order precede, otherwise operations with
  53. equal precedence are performed from left to right.  These are the usual
  54. algebraic conventions.
  55.     a^b^c is the same as (a^b)^c.
  56.         You can get operators by type(x).
  57.  
  58.                 3.2.1.1  Arithmetic operators
  59.  
  60. --------------------------------------------------------------------
  61. plus                    +               a+b             4
  62. minus                   -               a-b             4
  63. mutilation              *               a*b             5
  64. division                /               a/b             5
  65. power                   ^               a^b             6
  66. power                   **              a**b            6
  67. positive                +               +a              7
  68. negative                -               -a              7
  69. --------------------------------------------------------------------
  70.  
  71.         3.2.1.2  Relational Operators
  72.       Before you can write loops, you must be able to write 
  73. statements that evaluate to 1 or 0, and before you can do that, you
  74. must be able to write useful statements with logical values.  In
  75. mathematics, these are relational statements.
  76.     SymbMath allows you to compare numbers six ways:
  77.  
  78.                a < b              less than
  79.                a <= b             less than or equal to
  80.                a > b              greater than
  81.                a >= b             greater than or equal to
  82.                a == b             equal to
  83.                a <> b             not equals
  84.  
  85.       SymbMath uses the double equals sign == (like C language) for
  86.  "is equal to" to distinguish this operator from the equation =.
  87.       The result of a comparison of two real numbers is either 1 or 0. 
  88. If the comparsion is not both real numbers, it left unevaluated.
  89.  
  90.  
  91.         3.2.1.3    Logical operators
  92.       SymbMath uses the logical operators:  AND, and OR.  You can
  93. combine comparison operators with them to any level of complexity.
  94. In contrast to Pascal, logical operators in SymbMath have a lower
  95. order or precedence than the comparisons, so  a < b  and  c > d
  96. works as expected.  The result of combining logical values with
  97. logical operators is another logical value (1 or 0).  Bit operations 
  98. on integers can be performed using the same operations, but result is
  99. integers.
  100.       SymbMath uses the "short-circuit" definition of AND and OR 
  101. when the arguments are boolean.  Here are tables that show how AND 
  102. and OR are defined:
  103.  
  104.              a AND b
  105. --------------------------------------------------------
  106.             b       1       0
  107.         a
  108.         1               1       0
  109.         0               0       0
  110. ------------------------------------------------------
  111.  
  112.              a OR b
  113. --------------------------------------------------------
  114.             b       1       0
  115.         a
  116.         1               1       1
  117.         0               1       0
  118. ------------------------------------------------------
  119.  
  120.     Short-circuit evaluation is used because often one condition
  121. must be tested before another is meaningful.
  122.     The result of Boolean expression with logic operators is either
  123. 1 or 0. Boolean expression like (1 < 3 or 1 > 4) return a real value 1
  124. or 0.  Numeric expressions can replace Boolean ones, provided
  125. they evaluate to 1 or 0.  The advantage here is that you can
  126. define the step function that is 0 for x < a and 1 for x > a by
  127. entering:
  128.  
  129.             step(x_, a_) := x > a
  130.  
  131.     To define the function:
  132.  
  133.             f(x) = x-1    if x < 1
  134.                  = x^2-x  if x >= 1
  135.  
  136.     enter:
  137.            f(x_) := (x-1)*(x < 1) + (x^2-x)*(x >= 1)
  138.  
  139.     These functions can be differentiated and integrated symbolically.
  140.  
  141.                         3.2.2  Function calls
  142.         A function call activates the function specified by the function
  143. name. The function call must have a list of actual parameters if the
  144. corresponding function decalaration contains a list of formal parameters.
  145. Each parameter takes the place of the corresponding formal parameter.
  146. If the function is external, the function call will automatically load
  147. the library specified by its function name plus extension .fun when needed.
  148.        Some examples of function calls follow:
  149.             sin(x)            # will load the library sin.fun when needed
  150.             inte(x^2, x)      # will load the library inte.fun when needed
  151.