






                           CCCCAAAALLLLCCCC: A Calculator Program
                        Tutorial Introduction and Manual

                                  Gary Perlman
                          Cognitive Science Laboratory
                      University of California, San Diego


               CCCCAAAALLLLCCCC is a program  for  mathematical  calculations  for
          which  you  might use a hand held calculator.  CCCCAAAALLLLCCCC supplies
          most of the operations common to programming  languages  and
          variables with properties much like those in Visicalc.

               The arithmetical operators CCCCAAAALLLLCCCC offers are

               +       addition
               -       subtraction and change-sign
               *       multiplication
               /       division
               %       modulo division
               ^       exponentiation

          Arithmetical expressions can be arbitrarily complex and  are
          generally evaluated left to right.  That is,

                                   a + b - c

          is the same as

                                  (a + b) - c.

          Exponentiation is evaluated before multiplication and  divi-
          sion  which  are  evaluated before addition and subtraction.
          For example, the expression

                             a + b - c * d / e ^ 2

          is parsed as

                         (a + b) - ((c * d) / (e ^ 2))

          This default order of operations can be overridden by  using
          parentheses.

               CCCCAAAALLLLCCCC supplies some transcendental functions: sqrtsqrtsqrtsqrt, loglogloglog,
          expexpexpexp, and absabsabsabs.

          _1.  _U_s_i_n_g CCCCAAAALLLLCCCC

                  To use CCCCAAAALLLLCCCC, begin by typing "CCCCAAAALLLLCCCC" at the UNIX com-
             mand  level, and CCCCAAAALLLLCCCC will prompt you with "CALC: ".  You
             can supply inputs to CCCCAAAALLLLCCCC from files specified by command
             line arguments.  For example, typing "calc foo" will read










          CCCCAAAALLLLCCCC: A Calculator Program               Tutorial and Manual


             from foo and then ask for input from you.  Type  in  each
             of  your  expressions  followed  by  RETURN and CCCCAAAALLLLCCCC will
             respond with how it parsed your  expression  followed  by
             the  result.   In  all following examples, what you would
             type in is preceded by the CCCCAAAALLLLCCCC prompt "CALC: ", and what
             CCCCAAAALLLLCCCC responds with is immediately after.  A simple calcu-
             lation is:

                  CALC: sqrt (12^2 + 5^2)
                  sqrt(((12 ^ 2) + (5 ^ 2)))     = 13


                  Expressions can be stored by assigning variables  to
             them.  For example you could type:

                  CALC: pi = 22/7
                  (22 / 7)      = 3.14286
                  CALC: pi
                  pi          = 3.14286

             Variables can be used in expressions.

                  CALC: area = pi * r^2
                  (pi * (r ^ 2))      = UNDEFINED
                  CALC: area
                  area     = UNDEFINED

             areaareaareaarea is undefined because rrrr has not been set.  Once rrrr  is
             set,  areaareaareaarea  will  have  a value because areaareaareaarea is set to an
             equation rather than a particular  value.   This  can  be
             observed  by printing all the variables so far introduced
             with ^V (CTRL-v), which may have to be typed twice as  ^V
             is used in some UNIX versions to quote characters.

                  CALC: ^V
                  pi       =      3.14286 = (22 / 7)
                  area     =    UNDEFINED = (pi * (r ^ 2))
                  r        =    UNDEFINED =

             The variable table is formatted so that  each  variable's
             name  is on the left, followed by its current value, fol-
             lowed by its current definition.  If rrrr is set to  5,  the
             value of areaareaareaarea is now defined.

                  CALC: r = 5
                  5        = 5
                  CALC: ^V
                  pi       =      3.14286 = (22 / 7)
                  area     =      78.5714 = (pi * (r ^ 2))
                  r        =            5 = 5

             The effect of changing rrrr on areaareaareaarea can be  easily  observed
             because of the way areaareaareaarea is defined.


                                     ---- 2222 ----







          CCCCAAAALLLLCCCC: A Calculator Program               Tutorial and Manual


                  CALC: r = 2
                  2         = 2
                  CALC: area
                  area      = 12.5714


          _2.  _S_e_t_t_i_n_g _C_o_n_s_t_a_n_t _V_a_l_u_e_s

                  Of course, there are times when you want  to  set  a
             variable  to a value and not have it depend on the values
             of variables at a later time.  To do this, you precede an
             expression with the number operator #.  For example,

                  CALC: area2 = # area
                  12.5716      = 12.5716
                  CALC: ^V
                  pi       =      3.14286 = (22 / 7)
                  area     =      12.5716 = (pi * (r ^ 2))
                  r        =            2 = 2
                  area2    =      12.5716 = 12.5716

             area2area2area2area2 does not depend on the variable to which it was set
             because  the  number operator # only lets numbers through
             it rather than expressions.  If area2area2area2area2 was set without the
             # operator, it would be subject to any changes in areaareaareaarea or
             to any changes in variables on which areaareaareaarea depends.

                  CALC: area2 = area
                  area      = 12.5716
                  CALC: ^V
                  pi       =      3.14286 = (22 / 7)
                  area     =      12.5716 = (pi * (r ^ 2))
                  r        =            2 = 2
                  area2    =      12.5716 = area


          _3.  _T_e_s_t_i_n_g _C_o_n_d_i_t_i_o_n_s

                  Variables can be set based on  a  tested  condition.
             For example, you may want a variable maxmaxmaxmax to always be the
             maximum of aaaa and bbbb.

                  CALC: max = if a > b then a else b
                  (if (a > b) then a else b)    = UNDEFINED

             maxmaxmaxmax is undefined because aaaa and bbbb have not been set.






9

9                                     ---- 3333 ----







          CCCCAAAALLLLCCCC: A Calculator Program               Tutorial and Manual


                  CALC: a = 21
                  21     = 21
                  CALC: b = 3^3
                  (3 ^ 3)    = 27
                  CALC: max
                  max      = 27
                  CALC: a = 50
                  50   = 50
                  CALC: max
                  max      = 50

             The if-then-else expression allows variables  to  be  set
             based  on conditions.  This condition can be made up with
             relational and logical operators.  The relational  opera-
             tors available with CCCCAAAALLLLCCCC are:

                  ==      test equality
                  !=      test inequality
                  >=      greater than or equal
                  <=      less than or equal
                  >       greater than
                  <       less than

             while the logical operators are:

                  &       and
                  |       or
                  !       not

             A more complicated expression involving these is:

                              if a > b & b > c then b

             The elseelseelseelse part of the conditional is optional, and if  not
             present  and  the  condition is false, the conditional is
             undefined.

          _4.  _U_n_d_e_f_i_n_e_d _V_a_r_i_a_b_l_e_s

                  Variables are undefined if they have not  been  set,
             if  they  depend  on  variables that are undefined, or if
             they are set to an expression involving an illegal opera-
             tion.

                  CALC: 1/0
                  (1 / 0)     = UNDEFINED

             You can be confident that no operations  will  result  in
             CCCCAAAALLLLCCCC  blowing  up.   (The exception to this is writing an
             expression  that  indirectly  depends  on  itself,  which
             causes  big  problems.) Thus you could write the equation
             for the roots of a quadratic formula with  the  following
             definitions and always get reasonable answers.


                                     ---- 4444 ----







          CCCCAAAALLLLCCCC: A Calculator Program               Tutorial and Manual


                  CALC: x = 0
                  CALC: a = b = 1
                  CALC: c = -1
                  CALC: radical = sqrt (b^2 - 4*a*c)
                  CALC: equation = a*x^2 + b*x + c
                  CALC: derivative = 2*a*x + b
                  CALC: root1 = (-b + radical) / (2 * a)
                  CALC: root2 = (-b - radical) / (2 * a)


          _5.  _C_o_n_t_r_o_l _C_h_a_r_a_c_t_e_r_s

                  Non-mathematical operations  are  accomplished  with
             control  characters.   To  type  a control character, say
             control-p, while you hold down the key labeled  CTRL  you
             type  a "p".  This will appear as ^P.  Some control char-
             acters have very special meanings, such as "stop the pro-
             gram"  so you must be careful with them.  In general, you
             can avoid any problems with control characters by  typing
             a ^V (control-v) before them.  This character removes any
             special meaning associated with the character immediately
             following  it.  So to type ^P you could be extra safe and
             type ^V^P.  To type a control-v, you may have to type  it
             twice.   Unfortunately, these conventions are not univer-
             sal.

                  The following control operations are available  with
             CCCCAAAALLLLCCCC.

                  ^P      change the printing option
                  ^Rf     read the input from file f and return to current state
                  ^V      print the variable table
                  ^Wf     write the variable table to file f
                          (actually, ^W is a synonym for ^V)

             If you forget any of these commands, you can type a ?  to
             get CCCCAAAALLLLCCCC to remind you.















9

9                                     ---- 5555 ----







          CCCCAAAALLLLCCCC: A Calculator Program               Tutorial and Manual


          _6.  _T_a_b_l_e _o_f _O_p_e_r_a_t_i_o_n_s


                OPERATOR         ASSOCIATIVITY
                         PRECEDENCE               DESCRIPTION

                   #a        1        none        numerical value of a
                  a=b        2       right        a is set to expression b
              if a then b    3        left        if a != 0 then b else UNDEFINED
                  else       4        left
                  a|b        5        left        true if a or b is true
                  a&b        6        left        true is a and b are true
                   !a        7        none        true is a is false
                  a==b       8        none        true if #a equals #b
                  a!=b       8        none        true if #a is not equal #b
                  a<b        8        none        true if #a is less than #b
                  a>b        8        none        true if #a greater than #b
                  a>=b       8        none        true if #a > #b | #a == b
                  a<=b       8        none        true if #a < #b | #a == b
                  a+b        9        left        a plus b
                  a-b        9        left        a minus b
                  a*b        10       left        a times b
                  a/b        10       left        a divided by b
                  a%b        10       left        a modulo b
                  a^b        11      right        a to the b
                   -a        12       none        change sign
                 abs(a)      12       none        absolute value
                 exp(a)      12       none        e to the a
                 log(a)      12       none        natural logarithm of a
                sqrt(a)      12       none        square root of a






















9

9                                     ---- 6666 ----

















                            CCCCAAAALLLLCCCC: A Calculator Program
                         Tutorial Introduction and Manual

                                   Gary Perlman
                           Cognitive Science Laboratory
                        University of California, San Diego




                                 TABLE OF CONTENTS

             (1) Using CCCCAAAALLLLCCCC .....................................    1
             (2) Setting Constant Values ........................    3
             (3) Testing Conditions .............................    3
             (4) Undefined Variables ............................    4
             (5) Control Characters .............................    5
             (6) Table of Operations ............................    6



























9

9



