home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 600-699 / ff695.lha / ICalc / Docs / UserGuide < prev    next >
Text File  |  1992-07-13  |  36KB  |  1,057 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.                                ›3micalc ›0m›1mversion 2›0m.›1m0 
  16.  
  17.  
  18.  
  19.                       ›0mA complex-number expression parser 
  20.  
  21.                          (C) Martin W.Scott 1991, 1992 
  22.  
  23.  
  24.  
  25.                                   User Guide 
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.      icalc                         User Guide                         icalc
  69.  
  70.  
  71.      ›1mIntroduction 
  72.  
  73.           ›0m›3micalc  ›0mis  a  terminal-based  calculator;  the  ›1mi ›0mstands for
  74.           ›1mimaginary›0m, denoting the fact that the calculator works  with
  75.           complex numbers.  There are many calculator programs for the
  76.           Amiga, but  to  my knowledge, none with this ability.  ›3micalc
  77.           ›0malso performs real (normal) calculations too,  and  you  can
  78.           completely ignore the complex number facility if you wish.  
  79.  
  80.           Version 2.0 of icalc introduces major additions, effectively
  81.           making ›3micalc  ›0ma  C-like  programming language.  However, you
  82.           can completely ignore these extensions if you shy away  from
  83.           programming  -  this  version  is  (almost)  entirely upward
  84.           compatible with previous versions.  In light  of  this,  the
  85.           more  advanced  (programming) documentation is kept separate
  86.           from the simple instructions, in the 'Advanced Guide'.  
  87.  
  88.  
  89.      ›1mComplex Numbers 
  90.  
  91.           ›0mA complex number is made up of two components: a real  part,
  92.           and an  imaginary  part.   The imaginary part is just a real
  93.           number multiplied by the special number i, which is  defined
  94.           to be  the  square root of -1.  Thus, i*i = -1. This may all
  95.           seem very artificial, but it's not; complex numbers exist as
  96.           surely as real numbers  do  (or  don't,  depending  on  your
  97.           mathematical philosophy).    However, real numbers seem more
  98.           tangible to us, since we  use  them  (or  approximations  to
  99.           them) in  our  everyday life.  It is not the purpose of this
  100.           guide to teach you anything about complex numbers -  if  you
  101.           don't  know  about  them, you probably don't need to, but if
  102.           you do any numerical work,  you  will  probably  still  find
  103.           ›3micalc  ›0museful,  because real numbers are a subset of complex
  104.           numbers, and can thus be manipulated by this program  as  in
  105.           an ordinary  calculator-type  program.  Don't be put off - I
  106.           hardly ever need to use complex numbers - I  just  like  the
  107.           facility  to  be  there  for  the odd occasion when I do use
  108.           them.  
  109.  
  110.           In what follows, examples are indented.  Things you type are
  111.           preceded by a '>' prompt sign,  and  output  from  ›3micalc  ›0mis
  112.           further indented.  
  113.  
  114.  
  115.      ›1mExpressions 
  116.  
  117.           ›0m›3micalc  ›0maccepts  expressions  in  the usual form for computer
  118.           expressions, i.e.  multiplication must be  explicitly  shown
  119.           by  '*', and function arguments enclosed within parentheses.
  120.           The exception to this is the method  of  inputing  imaginary
  121.           parts of complex numbers.  If you want to enter the number 3
  122.           + 4i, you can type either 
  123.  
  124.                   >  3+4i
  125.  
  126.           or 
  127.  
  128.                   >  3+4*i
  129.  
  130.  
  131.      icalc                            -2-                       version 2.0
  132.  
  133.  
  134.      icalc                         User Guide                         icalc
  135.  
  136.  
  137.  
  138.           but ›3mnot 
  139.  
  140.                   ›0m>  3+i4        # this won't do...
  141.  
  142.           since  this  would  give an ambiguous grammar - is it i*4 or
  143.           the variable "i4"?  
  144.  
  145.           In  almost  all  circumstances,  the   algebraic   "4i"   is
  146.           preferred, but there is one exception, exponentation "^". If
  147.           you want 3*i^3, you must type 
  148.  
  149.                   >  3*i^3
  150.  
  151.           and not 
  152.  
  153.                   >  3i^3
  154.  
  155.           The  former gives the correct result, -3i, whilst the latter
  156.           gives -27i. This is because  the  grammar  sees  "3i"  as  a
  157.           number   in   its   own   right,   and   not   an   implicit
  158.           multiplication.  
  159.  
  160.           NB: Implicit multiplication (leaving out '*' sign)  is  only
  161.           recognised in the case of a numerical multiple of i.  
  162.  
  163.           See  the  appendices  for  the  complete  list  of commands,
  164.           operators,  constants  and  builtin  functions  that   ›3micalc
  165.           ›0msupports.  
  166.  
  167.           Expressions  are  separated  by newlines or semi-colons ';'.
  168.           You may also split an expression over multiple lines using a
  169.           backslash '\' to indicate continuation  to  the  next  input
  170.           line.   Comments  are introduced by '#', and the rest of the
  171.           input line is ignored.  You may also  place  comments  after
  172.           backslashes.  
  173.  
  174.  
  175.      ›1mSample Expressions 
  176.  
  177.           ›0mBelow are a few examples of what ›3micalc ›0mwill accept.  
  178.  
  179.                   >  x=4     # an assignment statement
  180.  
  181.           assigns to variable x the value 4.  
  182.  
  183.                   >  # and now, two statements separated by a semi-colon
  184.                   >  sqr(x); x*sqr(x);
  185.  
  186.           displays the  values  16  and  64 (sqr(x) returns x*x).  The
  187.           next example demonstrates  a  problem  inherent  in  machine
  188.           calculations: 
  189.  
  190.                   >  2*sin(x)*cos(x) - sin(2*x)
  191.  
  192.           displays  the  value  -2.220446e-16. The answer should be 0,
  193.           and indeed is very close to that.   The  inaccuracy  results
  194.           because  each  term has a value as close to the actual value
  195.  
  196.  
  197.      icalc                            -3-                       version 2.0
  198.  
  199.  
  200.      icalc                         User Guide                         icalc
  201.  
  202.  
  203.           as the computer's internal  representation  of  numbers  can
  204.           hold.  
  205.  
  206.  
  207.      ›1mStarting icalc 
  208.  
  209.           ›0m›3micalc ›0mmay be started from either the CLI or Workbench.  Once
  210.           started, ›3micalc ›0mwill process the file whose name is contained
  211.           in  the  environment  variable  ICALCINIT, defaulting to the
  212.           file "s:icalc.init" if no environment variable is  declared.
  213.           This initialization file may be used to extend the functions
  214.           available in  ›3micalc.    ›0mA  sample  file  is  given  in the S
  215.           directory of this distribution.  If running  under  AmigaDOS
  216.           1.3,  it  is  recommended  that you use NEWCON: or ConMan to
  217.           provide editing  and  history  facilities.    For  users  of
  218.           AmigaDOS  2.0,  the  normal CON: window has these facilities
  219.           built-in.  
  220.  
  221.        CLI Usage 
  222.  
  223.           The synopsis for icalc is 
  224.  
  225.                   icalc [file-list]
  226.  
  227.           where file-list is a list of input files.  ›3micalc  ›0mwill  read
  228.           (process) the files in the list and exit.  If a file-list is
  229.           specified, ›3micalc ›0mwill assume that you do not wish to use the
  230.           program interactively.  If you do, you should specify one of
  231.           the files as a dash "-"; this is taken to mean "use standard
  232.           input".    If   no  file-list  is  given,  ›3micalc  ›0mstarts  an
  233.           interactive session.  You can obviously redirect output to a
  234.           file if you wish (and redirect input from a file,  but  this
  235.           is generally  unnecessary).    For example, if you wanted to
  236.           use definitions contained in a file  called  "stat.ic",  and
  237.           then type some expressions in at the terminal, you would use 
  238.  
  239.                   icalc stat.ic -
  240.  
  241.           to start  the  program.  Because the program makes extensive
  242.           use of recursion, I recommend you use a stack size of  about
  243.           20K when running ›3micalc.  
  244.  
  245.        ›0mWorkbench Usage 
  246.  
  247.           To  start  ›3micalc ›0mfrom the Workbench, simply double-click its
  248.           icon.   You  may  also  pass  arguments  (definition/command
  249.           files)  to ›3micalc ›0min the usual Workbench manner (shift-select
  250.           etc.).  ›3micalc ›0mwill then  open  a  window  on  the  Workbench
  251.           screen for  an  interactive  session.    You can specify the
  252.           window to be opened by modifying the WINDOW tooltype  (click
  253.           once on the ›3micalc ›0micon, and select "Info" from the Workbench
  254.           menu).  By default, this is a CON: window.  (As noted above,
  255.           AmigaDOS 1.3 users could alter this to a NEWCON: window).  
  256.  
  257.           You  may  also  set  the default tool of a definition file's
  258.           project icon to be ›3micalc.  ›0mThen simply double  clicking  the
  259.           project  icon  will  launch  ›3micalc  ›0mand  read the definition
  260.           file.  Remember, however, to set the project icon's stack to
  261.  
  262.  
  263.      icalc                            -4-                       version 2.0
  264.  
  265.  
  266.      icalc                         User Guide                         icalc
  267.  
  268.  
  269.           20000, or you may get a stack overflow error.  
  270.  
  271.        Exiting icalc 
  272.  
  273.           To end an interactive session of ›3micalc ›0m(from either  CLI  or
  274.           Workbench) use  the  command "quit" or "exit".  You can also
  275.           type ^\ (press the control key and '\' simultaneously).   If
  276.           running  under  AmigaDOS  2.0,  you  can  use  the  window's
  277.           close-gadget.  
  278.  
  279.  
  280.      ›1mVariables 
  281.  
  282.           ›0mVariables in ›3micalc ›0mcan be named arbitrarily, as long  as  no
  283.           name  conflicts  with a pre-defined symbol name, such as sin
  284.           or PI. The standard conventions apply: the  first  character
  285.           must  be  a  letter  or  underscore, followed by a string of
  286.           letters, digits and underscores.  Case IS significant.  
  287.  
  288.           Variables are introduced by using them;  If  a  variable  is
  289.           used  before  it  has been initialized (i.e. has had a value
  290.           assigned to it), ›3micalc ›0mwill warn the user and use the  value
  291.           zero.  Assignments can appear anywhere in an expression, and
  292.           are  in  fact  expressions  in  their  own  right (as in the
  293.           programming language C).  So, you can do things like 
  294.  
  295.                   >  apple = banana = apricot = 34
  296.  
  297.           to assign the value  34  to  all  these  variables.    Since
  298.           assignments   are   expressions,   their   value  being  the
  299.           assignment value, you can also do 
  300.  
  301.                   >  apple = sqr(banana = 12)
  302.  
  303.           which assigns the value 12 to "banana", and 144 to  "apple".
  304.           You can of course assign new values to existing variables.  
  305.  
  306.  
  307.      ›1mConstants and ans 
  308.  
  309.           ›0m›3micalc ›0mcomes  with  several  predefined  constants, e.g.  PI,
  310.           GAMMA etc, which by convention are all in upper-case.    You
  311.           cannot assign a new value to a constant.  There is a special
  312.           constant,  "ans",  which isn't really a constant at all, but
  313.           is made so to prevent assignments to it.  "ans" contains the
  314.           value of the previously  evaluated  expression,  and  so  is
  315.           useful when splitting a calculation up into smaller chunks.  
  316.  
  317.                   >  1 + 2 + 3
  318.                           6
  319.                   >  ans * 12
  320.                           72
  321.  
  322.           You can  also  use  it for recursive formulas.  For example,
  323.           the logistic equation xnext = rx(1-x) for parameter r = 3.5,
  324.           initial x = 0.4 could be iterated as follows: 
  325.  
  326.                   >  r = 3.5; 0.4          # initialize r and ans
  327.  
  328.  
  329.      icalc                            -5-                       version 2.0
  330.  
  331.  
  332.      icalc                         User Guide                         icalc
  333.  
  334.  
  335.                           3.5
  336.                           0.4
  337.                   >  r*ans*(1-ans)
  338.                           0.84
  339.                   >  r*ans*(1-ans)
  340.                           0.4704
  341.                   >  r*ans*(1-ans)
  342.                           0.87193344
  343.                   >  r*ans*(1-ans)
  344.                           0.39082931
  345.  
  346.           and so on.  Of course, you needn't use "ans" here; you could
  347.           just use assignments to "x", but it illustrates  the  point.
  348.           Note   that   once   the   necessary   variables  have  been
  349.           initialised, the same expression  is  evaluated  repeatedly.
  350.           Thus,  if  you  are using a window with history capabilities
  351.           you can save a lot of typing by pressing the up-arrow.  
  352.  
  353.           There are other ways to  perform  repeated  calculations  in
  354.           ›3micalc.   ›0mYou  can use so-called Special functions (explained
  355.           below), or the C-style looping constructs described  in  the
  356.           'Advanced Guide'.  
  357.  
  358.  
  359.      ›1mBuiltin Functions 
  360.  
  361.           ›0m›3micalc  ›0mcomes  with  many builtin functions, for example sin,
  362.           cos, sqrt, exp, ln etc.  There are  some  special  functions
  363.           for complex  numbers  too,  namely  Im,  Re, arg, norm.  All
  364.           functions take real or complex arguments, which can  be  any
  365.           expression,  although  in  some  cases,  the complex part is
  366.           discarded.  Consider 
  367.  
  368.                   >  sin(12-3i)
  369.                           -5.40203477 - 8.45362342 i
  370.                   >  asin(ans)
  371.                           -0.56637061 - 3 i
  372.                   >  sin(ans)
  373.                           -5.40203477 - 8.45362342 i
  374.  
  375.           Here we see a property of inverse  trigonometric  functions,
  376.           their  many-valuedness, due to their periodicity on the real
  377.           line.   The  function  asin  returns  a  value  in  its  PVR
  378.           (principal  value  range) as do all many-valued functions in
  379.           ›3micalc.  ›0mSee the 'Advanced Guide' for  exact  definitions  of
  380.           PVRs of the inverse trigonometric functions used in ›3micalc.  
  381.  
  382.           ›0mOther  functions  owe their many-valuedness to the fact that
  383.           the argument of a complex number is 2*PI-periodic. In  ›3micalc
  384.           ›0mthe argument always falls in the range -PI < arg <= PI.  
  385.  
  386.           Another  thing  to  bear in mind if you're not using complex
  387.           numbers is that expressions like 
  388.  
  389.                   >  ln(-1)
  390.  
  391.           return a value, 3.14159265359*i (PI*i) in this case.    (The
  392.           natural  logarithm  onto  the real line is defined for range
  393.  
  394.  
  395.      icalc                            -6-                       version 2.0
  396.  
  397.  
  398.      icalc                         User Guide                         icalc
  399.  
  400.  
  401.           (0, +infinity)).  
  402.  
  403.  
  404.      ›1mUser›0m-›1mdefined Functions 
  405.  
  406.           ›0mUser-defined  functions  give  ›3micalc  ›0mits  flexibility   and
  407.           power.   Any  function  that  can  be  stated  as  a  normal
  408.           expression (or list of expressions) may  easily  be  defined
  409.           and used  like  a  builtin function.  In this document, only
  410.           very simple function definitions are explained.    Functions
  411.           more  akin  to  those in a computer program are described in
  412.           the 'Advanced Guide'.  
  413.  
  414.           Functions are defined  using  the  'func'  keyword,  in  the
  415.           following manner: 
  416.  
  417.                   func <name> ( <parameter-list> ) = <expr>
  418.  
  419.           so to define the function f(z) = sin(sqrt(z)), simply type 
  420.  
  421.                   >  func f(z) = sin(sqrt(z))
  422.  
  423.           Note  that  z  is  ›3mlocal  ›0mto  the  function,  not  a  global
  424.           variable.  Thus, if z has been defined as a variable  before
  425.           defining f(z),  it  is  unaltered  when  you call f(z).  The
  426.           standard initiation file 'icalc.init' contains  many  simple
  427.           function  definitions,  and  you  may find it instructive to
  428.           examine it.  
  429.  
  430.           Multi-parameter functions may also be defined.  For example,
  431.           the volume of a right-circular cone is given by the formula 
  432.  
  433.                   volume = 1/3*PI*sqr(r)*h
  434.  
  435.           where r is the radius of the base, and h is  the  height  of
  436.           the cone.  We can define a function to compute the volume as
  437.           follows: 
  438.  
  439.                   >  func conevol(r,h) = 1/3*PI*sqr(r)*h
  440.                   >  conevol(1,3)
  441.                           3.14159265
  442.  
  443.           It  is  also  possible  (though  of  limited use) to declare
  444.           functions that   take   no   parameters.      Examples    of
  445.           multi-parameter functions are given in the sample definition
  446.           files.  
  447.  
  448.           NB: As with most programming languages, don't write circular
  449.           definitions;  ›3micalc  ›0mdoes  not detect them, and will swiftly
  450.           run out of stack space.  
  451.  
  452.  
  453.      ›1mSpecial Functions 
  454.  
  455.           ›0mCertain  builtin  functions  in  ›3micalc  ›0mare  called  ›3mspecial
  456.           ›0mbecause of the way they use their arguments.  Normally, when
  457.           you `call' a function, its arguments are first evaluated and
  458.           then the   function  is  called.    With  special  functions
  459.  
  460.  
  461.      icalc                            -7-                       version 2.0
  462.  
  463.  
  464.      icalc                         User Guide                         icalc
  465.  
  466.  
  467.           however, the arguments are not evaluated;  this  means  that
  468.           the  expressions  themselves (and not just their values) can
  469.           be used by the function in a number of ways.  
  470.  
  471.           Special functions were introduced in version 1.1  of  ›3micalc.
  472.           ›0mbut  since  version  2.0, they have become largely redundant
  473.           (with one or two exceptions) due to the C-style  programming
  474.           constructs added.    However,  for non-programmers or people
  475.           who don't wish to use ›3micalc ›0mas a programming language,  they
  476.           do  provide a means for performing several common operations
  477.           which would otherwise prove difficult.  
  478.  
  479.           Some special functions take integers as  arguments;  if  you
  480.           supply  an  expression with a non-integral value, this value
  481.           will  be  stripped  of  its  imaginary  component,  and  the
  482.           remaining  real  number  rounded  to  the  nearest  integer.
  483.           Currently, the special functions are as follows.  
  484.  
  485.        Sum(var,upto,expr) 
  486.  
  487.           This command calculates finite sums.  The variable `var'  is
  488.           the index  of summation, with an optional assignment.  While
  489.           the value of the index is less than or equal to the value of
  490.           the upto argument, the value of expr is added to an internal
  491.           summation variable, which is initially zero.  Examples  will
  492.           help to clarify usage.  
  493.  
  494.           To  evaluate  the  sum  of  the  first  100  natural numbers
  495.           (naively) we could do 
  496.  
  497.                   >  Sum(n=1,100,n)
  498.  
  499.           which gives the answer as  5050  (which  is  100/2*(100+1)).
  500.           Note the  initial assignment of 1 to n.  If no initial value
  501.           is specified, a value of zero is assumed (and  the  user  is
  502.           notified of  this).  When a summation is complete, the index
  503.           variable holds a value 1 greater than the value of upto.  We
  504.           can also use Sum() to  provide  approximations  to  infinite
  505.           sums.  
  506.  
  507.                   >  Sum(n=1, 100, 1/sqr(n)) 
  508.                           1.6349839
  509.  
  510.           Using  the  fact  that n will now hold the value 101, we can
  511.           continue the summation to 200 by the following: 
  512.  
  513.                   >  ans + Sum(n, n+99, 1/sqr(n))
  514.                           1.63994655
  515.  
  516.           and continue to obtain closer answers by repeating the  last
  517.           line, 
  518.  
  519.                   >  ans + Sum(n, n+99, 1/sqr(n))
  520.                           1.64160628
  521.  
  522.           which is getting there (the infinite series sums to PI^2/6 =
  523.           1.64493407).   One  last example, to evaluate the sum of the
  524.           all even numbers upto 100.  
  525.  
  526.  
  527.      icalc                            -8-                       version 2.0
  528.  
  529.  
  530.      icalc                         User Guide                         icalc
  531.  
  532.  
  533.  
  534.                   >  Sum(n=1, 50, 2*n)
  535.                           2550
  536.  
  537.  
  538.        Prod(var,upto,expr) 
  539.  
  540.           This command calculates finite products, in an analogous way
  541.           to the Sum() special function.   Examples  will  demonstrate
  542.           its use.  
  543.  
  544.                   >  Prod(n=1, 10, n)
  545.  
  546.           calculates  10!, which is 3628800. We can also use Prod() to
  547.           investigate  infinite  products,  although  care  should  be
  548.           taken.  Consider Wallis's product for PI/2: 
  549.  
  550.                   PI   2×2×4×4×6×6×...
  551.                   -- = ---------------
  552.                   2    1×3×3×5×5×7×...
  553.  
  554.           Here  the  product  is 2/1 * 2/3 * 4/3 * 4/5 * ... and so we
  555.           must  find  a  method  of  producing  the   numerators   and
  556.           denominators from  an  index.  It is easiest to evaluate the
  557.           product in  pairs  of  terms.    Thus,  for  each  term  our
  558.           numerator  will  be  sqr(2*n),  and  our denominator will be
  559.           (2*n-1)*(2*n+1) = sqr(2*n)-1.  Note that sqr(2*n) appears in
  560.           both the  numerator  and  denominator.    We  can  therefore
  561.           optimise  the  calculation  by using a temporary variable to
  562.           hold this value.  We proceed as follows: 
  563.  
  564.                   >  Prod(n=1, 100, (t = sqr(2*n))/(t-1))
  565.                           1.56689375
  566.                   >  ans * Prod(n, n+99, (t = sqr(2*n))/(t-1))
  567.                           1.56883895
  568.                   >  ans * Prod(n, n+99, (t = sqr(2*n))/(t-1))
  569.                           1.56949005
  570.  
  571.  
  572.        every(var,upto,expr) and vevery(var,upto,expr) 
  573.  
  574.           These functions preform more general iterations  than  Sum()
  575.           and Prod().    They  return the value of the last expression
  576.           evaluated, ie.   expr  evaluated  when  var  =  upto.    The
  577.           difference  between  every() and vevery() is that the latter
  578.           produces verbose output - it prints the value of  the  index
  579.           and the result of the expression for every iteration.  
  580.  
  581.           Example:   evaluate   sin(sin(...(sin(z))...))   with  sin()
  582.           applied 10 times.  Here we'll take z to be 1-i.  
  583.  
  584.                   >  last = 1-i; every(n=1, 10, last = sin(last))
  585.                           0.51856952 - 0.01039404 i
  586.  
  587.           Although every() and vevery() are useful in some situations,
  588.           most iterations are more easily performed by using Sum() and
  589.           Prod(). 
  590.  
  591.  
  592.  
  593.      icalc                            -9-                       version 2.0
  594.  
  595.  
  596.      icalc                         User Guide                         icalc
  597.  
  598.  
  599.        multi(expr1, expr2, ... , exprN) 
  600.  
  601.           This special function still exists for upward compatability,
  602.           but it is syntactically  equivalent  to  the  C-style  block
  603.           introduced with version 2.0: 
  604.  
  605.                   { expr1 ; expr2 ; ... ; exprN; }
  606.  
  607.           (In  fact,  the semicolons can be omitted and new-lines used
  608.           instead - see the 'Advanced Guide').  
  609.  
  610.           The value of a call to multi or a block expression  is  that
  611.           of the  last  expression evaluated, namely exprN.  If output
  612.           has not been switched off with the 'silent' command, use  of
  613.           a block  will  print  the  result of it's last argument.  In
  614.           order to print the results of other expressions, the builtin
  615.           function print() is supplied.  print() takes  one  argument,
  616.           prints  it  to  the  display,  and returns its argument as a
  617.           result.  In this way, expressions can appear to return  more
  618.           than one result.  
  619.  
  620.           An   example:  write  a  function  that  converts  Cartesian
  621.           coordinates into polar form, returning the radius and  angle
  622.           in  degrees,  and setting the variables r and theta to these
  623.           values.  
  624.  
  625.  
  626.                   >  func rec2pol(x,y) = {
  627.                   >       r=print(sqrt(x*x+y*y))
  628.                   >       theta=DEG*arg(x+i*y)
  629.                   >  }
  630.  
  631.                   >  rec2pol(3,4)
  632.                           5
  633.                           53.13010235
  634.  
  635.  
  636.           Note the use of  complex  argument  to  obtain  the  correct
  637.           quadrant.  
  638.  
  639.  
  640.      ›1mOther features 
  641.  
  642.           ›0m›3micalc  ›0mnow  has  a  full  complement  of  common programming
  643.           constructs (C-style) such as if-else, for-loops etc.    This
  644.           necessitated  the  addition  of  relational  operators >=, >
  645.           etc.  and logical operators &&, !  etc.  
  646.  
  647.           In  order  to  make  the  range   of   applications   wider,
  648.           single-dimensional  arrays may also be used in a very simple
  649.           manner.  
  650.  
  651.           User-function arguments may be arrays, pointers to variables
  652.           and  even  expressions  (in  the  sense  of  expressions  to
  653.           'special'  functions)  although in this area, syntax differs
  654.           considerably from the C programming language.  
  655.  
  656.           All these and other extensions are very  useful  facilities,
  657.  
  658.  
  659.      icalc                            -10-                      version 2.0
  660.  
  661.  
  662.      icalc                         User Guide                         icalc
  663.  
  664.  
  665.           but non-essential  for  simple  work.  They are described in
  666.           detail in the 'Advanced Guide'.  
  667.  
  668.  
  669.      ›1mCommands 
  670.  
  671.           ›0m›3micalc ›0mhas a few commands to make life easier.   One  or  two
  672.           commands take  a string as an argument.  This string must be
  673.           enclosed in double-quotes, e.g.   "hello".    It  should  be
  674.           noted that commands may NOT be used within function or block
  675.           declarations.  
  676.  
  677.        quit 
  678.        exit 
  679.           not surprisingly, these commands terminate ›3micalc.  
  680.  
  681.        ›0msilent 
  682.           stops generation of any further output.  However, errors and
  683.           warnings are   still   displayed.      It   is   useful  for
  684.           initialization files containing lots of definitions.  
  685.  
  686.        verbose 
  687.           restores generation of output.  
  688.  
  689.        help 
  690.           reminds you what other commands are available.  
  691.  
  692.        vars 
  693.           lists all currently defined variables and their values,  and
  694.           allocated arrays.  
  695.  
  696.        consts 
  697.           lists all predefined constants and their values.  
  698.  
  699.        builtins 
  700.           lists  all  built-in  functions available, including special
  701.           functions.  
  702.  
  703.        functions 
  704.           lists  all  user-defined  functions,  with  their  parameter
  705.           lists.  
  706.  
  707.        echo <string> 
  708.           simply prints given string (like Shell echo command).  
  709.  
  710.        pwd 
  711.           prints the current directory of ›3micalc.  
  712.  
  713.        ›0mcd <new-directory> 
  714.           changes current directory of ›3micalc.  ›0mEg. cd "s:" 
  715.  
  716.        exec <command-string> 
  717.           executes command  as  if  it had been typed in a Shell.  Eg.
  718.           exec "ed s:icalc.init".    If  ›3micalc  ›0mis  started  from  the
  719.           Workbench, output from exec'd commands will not be displayed
  720.           (this is a compiler/OS bug).  
  721.  
  722.  
  723.  
  724.  
  725.      icalc                            -11-                      version 2.0
  726.  
  727.  
  728.      icalc                         User Guide                         icalc
  729.  
  730.  
  731.        read <file> 
  732.           reads  and  evaluates contents of named file (in same manner
  733.           as if passed on command-line to  ›3micalc  ›0mor  as  a  Workbench
  734.           argument.  
  735.  
  736.        writevars <file> 
  737.           dumps  all  variables  defined in current session (including
  738.           arrays) to specified file, for subsequent  restoration  with
  739.           the read   command   at   another   session.     At  present
  740.           user-function definitions  are  NOT  saved  (and  are  never
  741.           likely to   be   in  future  versions).    The  file  is  in
  742.           human-readable form.  
  743.  
  744.           There are  a  couple  of  other  commands  detailed  in  the
  745.           'Advanced Guide'.  
  746.  
  747.  
  748.      ›1mBugs 
  749.  
  750.           ›0mOne major bug was fixed in release 1.1a - the sqrt() builtin
  751.           was   not   returning   values   in  the  correct  quadrant.
  752.           Consequently, the inverse trigonometric functions, which are
  753.           defined using sqrt(), broke.  This has now  been  corrected.
  754.           Thanks to Pierre Ardichvili for pointing this out.  (Version
  755.           1.1a  fixed  this bug, but wasn't widely distributed because
  756.           version 2.0 was (supposedly) imminent.) 
  757.  
  758.           I hope that's all the major bugs ironed out, but  there  may
  759.           be the odd little bug in there somewhere -- if you find any,
  760.           PLEASE let me know and I'll try to fix them.  
  761.  
  762.           If  there's  something  you  hate about ›3micalc ›0mand would like
  763.           changed, or something you'd love that's not in,  drop  me  a
  764.           line (at the address below), or email me.  
  765.  
  766.  
  767.      ›1mSource 
  768.  
  769.           ›0m›3micalc ›0mwas written in C, and compiled with Lattice C (version
  770.           5.10a). Berkeley  Yacc was used to generate the parser.  The
  771.           source to version 2.0 of ›3micalc ›0mis available on request,  for
  772.           a small  fee.    See the 'ReadMe.First' document for further
  773.           details.  
  774.  
  775.  
  776.      ›1mCredits 
  777.  
  778.           ›0mThanks to the authors  of  Berkeley  Yacc  (it  makes  these
  779.           things  so  much  easier to write and modify) and to Lattice
  780.           for a (fairly) stable compiler.  
  781.  
  782.           Thanks also to Steve Koren for Sksh, and Mike  Meyer  et  al
  783.           for   Mg3;   together   they   make   a   great  development
  784.           environment.  
  785.  
  786.           This was my first yacc-based project, and  I  learnt  a  lot
  787.           from  "The  Unix Programming Environment" by Brian Kernighan
  788.           and Rob Pike. Their "hoc" taught me a lot about using Yacc.  
  789.  
  790.  
  791.      icalc                            -12-                      version 2.0
  792.  
  793.  
  794.      icalc                         User Guide                         icalc
  795.  
  796.  
  797.           Most of all, thanks to those people who have written  to  me
  798.           regarding icalc, for their comments and contributions.  
  799.  
  800.  
  801.      ›1mDistribution 
  802.  
  803.           ›0m›3micalc ›0mis  freeware,  copyrighted  software.   This copyright
  804.           applies to all files in the ›3micalc  ›0mdistribution.    You  are
  805.           permitted to distribute it at only a nominal charge to cover
  806.           costs.  All  files  should be included unmodified.  Under no
  807.           circumstances should ›3micalc ›0mbe sold for profit.  
  808.  
  809.  
  810.      ›1mThe Bottom Line 
  811.  
  812.           ›0mAlthough ›3micalc ›0mis NOT shareware, contributions would be most
  813.           welcome, as I'm a poor student, and have put a lot  of  work
  814.           into this  project.  But they're NOT required - bug reports,
  815.           praise, suggestions, neat programs etc.   are  welcome  (and
  816.           indeed encouraged)  with or without contribution.  Thanks to
  817.           those kind people (small in number) who have written to me.  
  818.  
  819.           I can be contacted via snail mail at: 
  820.  
  821.                   Martin W. Scott,
  822.                   23 Drum Brae North,
  823.                   Edinburgh, EH4 8AT
  824.                   United Kingdom.
  825.  
  826.           or you can email me; my address is mws@castle.ed.ac.uk 
  827.  
  828.           Thanks for reading this far.  The  appendices  follow;  some
  829.           details in them will not have been covered in this document,
  830.           but are explained in the 'Advanced Guide'.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.      icalc                            -13-                      version 2.0
  858.  
  859.  
  860.      icalc                         User Guide                         icalc
  861.  
  862.  
  863.      ›1mAppendix 1 ›0m- ›1mOperators ›0m(›1min increasing order of precedence›0m) 
  864.  
  865.  
  866.           =  +=  -=  *=  /=   assignment
  867.           ?:                  ternary operator 
  868.           ||                  logical or
  869.           &&                  logical and
  870.           ==  !=              equal, not equal
  871.           >  >=  <  <=        greater-than etc.
  872.           +  -                addition, subtraction
  873.           *  /                multiplication, division
  874.           -  !                unary minus, logical not
  875.           ^                   exponentation
  876.           '                   conjugate operator
  877.  
  878.  
  879.      ›1mAppendix 2 ›0m- ›1mConstants 
  880.  
  881.  
  882.           ›0mPI                  4*atan(1) (that's one definition)
  883.           E                   exp(1)
  884.           GAMMA               Euler's constant, 0.57721566...
  885.           DEG                 Number of degrees in one radian
  886.           PHI                 Golden ratio 1.61803398...
  887.           LOG10               ln(10)
  888.           LOG2                ln(2)
  889.           TRUE                1
  890.           FALSE               0
  891.           INFINITY            largest real number possible 
  892.  
  893.  
  894.      ›1mAppendix 3 ›0m- ›1mKeywords 
  895.  
  896.  
  897.           ›0mfunc                function declaration
  898.           array               (external) array definition
  899.           local               local variable definition
  900.           return              return from function
  901.  
  902.           if-else             control-flow constructs
  903.           while-do
  904.           do-while                
  905.           for                     
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.      icalc                            -14-                      version 2.0
  924.  
  925.  
  926.      icalc                         User Guide                         icalc
  927.  
  928.  
  929.      ›1mAppendix 4 ›0m- ›1mBuiltin functions 
  930.  
  931.  
  932.           ›0mParameters are evaluated from left to write.
  933.           Parameters shown:
  934.  
  935.                   z implies complex number expected,
  936.                   x implies real number expected,
  937.                   n implies integer expected.
  938.                   a implies array identifier expected.
  939.  
  940.           Conversions will be made if required.
  941.  
  942.           Functions you think missing below may well be defined in one of
  943.           the support scripts.
  944.  
  945.  
  946.           ›1mSingle›0m-›1margument functions›0m:        
  947.  
  948.           sin(z)              trigonometric functions
  949.           cos(z)
  950.           tan(z)
  951.  
  952.           asin(z)             inverse trigonometric functions
  953.           acos(z)
  954.           atan(z)
  955.  
  956.           sinh(z)             hyperbolic trigonometric functions
  957.           cosh(z)
  958.           tanh(z)
  959.  
  960.           exp(z)              exponential function
  961.           ln(z)               natural logarithm
  962.           sqr(z)              square
  963.           sqrt(z)             square root
  964.  
  965.           conj(z)             conjugate (see also ' operator)
  966.           abs(z)              absolute value (sqrt(norm(z))
  967.           norm(z)             not really norm; if z=x+iy, norm(z) = x²+y²
  968.           arg(z)              principal argument (in (-PI,PI])
  969.           Re(z)               real part of complex number
  970.           Im(z)               imaginary part of complex number
  971.  
  972.           ceil(x)             ceil of real part (eg. ceil(1.2) = 2)
  973.           floor(x)            floor of real part (eg. floor(1.2) = 1)
  974.           int(x)              return real part rounded to nearest integer
  975.           sgn(x)              sign of real part (eg. sgn(-1.6) = -1)
  976.  
  977.           time(x)             system time in seconds, less its argument
  978.           print(z)            prints and returns value of its argument
  979.           prec(n)             adjust number of decimal places displayed
  980.           error(n)            abort evaluation with error n
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.      icalc                            -15-                      version 2.0
  990.  
  991.  
  992.      icalc                         User Guide                         icalc
  993.  
  994.  
  995.           ›1mArray functions›0m:        
  996.  
  997.           display(a)          display contents of an array
  998.           sizeof(a)           returns number of elements in array
  999.           resize(a,n)         changes dimension of array to new size n
  1000.  
  1001.  
  1002.           ›1mSpecial functions›0m:        
  1003.  
  1004.           Sum                 calculate a finite sum
  1005.           Prod                calculate a finite product
  1006.           every               perform a general iteration quietly
  1007.           vevery              perform a general iteration verbosely
  1008.           multi               evaluate many expressions (defunct)
  1009.           min                 returns minimum real part in parameters
  1010.           max                 returns maximum real part in parameters
  1011.  
  1012.           min and max take an arbitrary number of arguments.
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.      icalc                            -16-                      version 2.0
  1056.  
  1057.