DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T c

⟦8a0ec9678⟧ TextFile

    Length: 7956 (0x1f14)
    Types: TextFile
    Names: »calc.doc«

Derivation

└─⟦87ddcff64⟧ Bits:30001253 CPHDIST85 Tape, 1985 Autumn Conference Copenhagen
    └─ ⟦this⟧ »cph85dist/stat/doc/calc.doc« 

TextFile

.CW "Gary Perlman
.ds AU "Gary Perlman
.ds DT March 1985
.TC 10
.de EG
.(D
\\$1
.)D
..
.(T "CALC: A Calculator Program" "Tutorial Introduction and Manual"
Gary Perlman
Cognitive Science Laboratory
University of California, San Diego
.)T "CALC Tutorial & Manual
.bp 1
.ls 1
.!T
.P
.T calc
is a program for mathematical calculations for which you might use a
hand held calculator.
.T calc
supplies most of the operations common to programming languages
and variables with properties much like those in Visicalc.
.P
The arithmetical operators
.T calc
offers are
.(D
+	addition
-	subtraction and change-sign
*	multiplication
/	division
%	modulo division
^	exponentiation
.)D
Arithmetical expressions can be arbitrarily complex
and are generally evaluated left to right.
That is,
.EG "a + b - c
is the same as
.EG "(a + b) - c.
Exponentiation is evaluated before multiplication and division
which are evaluated before addition and subtraction.
For example, the expression
.EG "a + b - c * d / e ^ 2
is parsed as
.EG "(a + b) - ((c * d) / (e ^ 2))
This default order of operations can be overridden by using parentheses.
.P
.T calc
supplies some transcendental functions:
.T sqrt ,
.T log ,
.T exp ,
and
.T abs ,
and the following trigonometric functions:
.T sin ,
.T asin,
.T cos ,
.T acos ,
.T tan ,
and
.T atan ,
for which
degrees are measured in radians.
.LH "Using CALC"
.P
To use
.T calc ,
begin by typing
.(D
calc
.)D
at the UNIX command level, and
.T calc
will prompt you with
.(D
CALC:
.)D
You can supply inputs to
.T calc
from files specified by command line arguments.
For example, typing
.(D
calc foo
.)D
will read from
.T foo
and then ask for input from you.
Type in each of your expressions followed by RETURN
and
.T calc
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
.T calc
prompt
.(D
CALC:
.)D
and what
.T calc
responds with is immediately after.
A simple calculation is:
.(D
CALC: sqrt (12^2 + 5^2)
sqrt(((12 ^ 2) + (5 ^ 2)))     = 13
.)D
.P
Expressions can be stored by assigning variables to them.
For example you could type:
.(D
CALC: pi = 22/7
(22 / 7)      = 3.14286
CALC: pi
pi          = 3.14286
.)D
Variables can be used in expressions.
.(D
CALC: area = pi * r^2
(pi * (r ^ 2))      = UNDEFINED
CALC: area
area     = UNDEFINED
.)D
.T area
is undefined because
.T r
has not been set.
Once
.T r
is set,
.T area
will have a value because
.T 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.
.(D
CALC: ^V
pi       =      3.14286 = (22 / 7)
area     =    UNDEFINED = (pi * (r ^ 2))
r        =    UNDEFINED =
.)D
The variable table is formatted so that each variable's name is
on the left, followed by its current value, followed by its
current definition.
If
.T r
is set to 5, the value of
.T area
is now defined.
.(D
CALC: r = 5
5        = 5
CALC: ^V
pi       =      3.14286 = (22 / 7)
area     =      78.5714 = (pi * (r ^ 2))
r        =            5 = 5
.)D
The effect of changing
.T r
on
.T area
can be easily observed because of the way
.T area
is defined.
.(D
CALC: r = 2
2         = 2
CALC: area
area      = 12.5714
.)D
.LH "Setting Constant Values
.P
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
.T # .
For example,
.(D
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
.)D
.T area2
does not depend on the variable to which it was set because
the number operator
.T #
only lets numbers through it rather than
expressions.
If
.T area2
was set without the
.T #
operator,
it would be subject to any changes in
.T area
or to any changes in variables on which
.T area
depends.
.(D
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
.)D
.LH "Testing Conditions
.P
Variables can be set based on a tested condition.
For example, you may want a variable
.T max
to always be the maximum of
.T a
and
.T b .
.(D
CALC: max = if a > b then a else b
(if (a > b) then a else b)    = UNDEFINED
.)D
.T max
is undefined because
.T a
and
.T b
have not been set.
.(D
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
.)D
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 operators available with
.T calc
are:
.(D
==	test equality
!=	test inequality
>=	greater than or equal
<=	less than or equal
>	greater than
<	less than
.)D
while the logical operators are:
.(D
&	and
|	or
!	not
.)D
A more complicated expression involving these is:
.EG "if a > b & b > c then b
The
.T else
part of the conditional is optional, and if not present
and the condition is false, the conditional is undefined.
.LH "Undefined Variables
.P
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 operation.
.(D
CALC: 1/0
(1 / 0)     = UNDEFINED
.)D
You can be confident that no operations will result in
.T calc
blowing up.
Thus you could write the equation for the roots of a quadratic formula
with the following definitions and always get reasonable answers.
.(D
x = 0
a = b = 1
c = -1
radical = sqrt (b^2 - 4*a*c)
equation = a*x^2 + b*x + c
derivative = 2*a*x + b
root1 = (-b + radical) / (2 * a)
root2 = (-b - radical) / (2 * a)
.)D
.LH "Control Characters
.P
Non-mathematical operations are accomplished with control characters.
To type a control character, say CTRL-p, while you hold down the
key labeled CTRL you type a
.T p .
This will appear as
.T ^P .
Some control characters have very special meanings, such as
"stop the program" so you must be careful with them.
In general, you can avoid any problems with control characters
by typing a
.T ^V
(CTRL-v) before them.
This character removes any special meaning associated with the
character immediately following it.
So to type
.T ^P
you could be extra safe and type
.T ^V^P .
To type a CTRL-v, you may have to type it twice.
Unfortunately, these conventions are not universal.
.P
The following control operations are available with
.T calc .
.(D
.ft R
^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)
.)D
If you forget any of these commands,
you can type a
.T ?
to get
.T calc
to remind you.
.bp
.LH "Table of Operations
.(D
.ft R
.ta .5iC +.75iC +.75iC +.5i
	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
	sin(a)	12	none	sine of a in radians (cos & tan)
	asin(a)	12	none	arc sine of a (acos & atan)
.)D
.TC