The UACalculators, Guide and Tutorial
The UACalculators are designed to perform various operations
on signatures and algebras that are of use in the application of universal
algebra to the semantics of programming languages. The UAcalculator
can also serve other uses such as the evaluation
of arithmetic expressions, trigonometric and logarithmic expressions, and
JavaScript expressions.
General Description of, and directions for, UACalculators
UACalculators appear throughout the text, as intext UAcalculators,
and it is also an option to have an independent UAcalculator displayed
on the left side of the main frame with the book text appearing on the
right side of the frame. You can toggle between having, and not having,
a calculator in left side of the main frame by clicking on the UACalculator
button in the upper frame.
The intext UACalculators and the independent UAcalculator
are almost the same. The have in common that:

They have two textareas, one labeled INPUT,
and one labeled DISPLAY

They have buttons labeled "perform", "clear input", "clear
display" and "help"

the perform button is used to perform the computation given in the
INPUT, the result, preceded by ""<<" should appear in
the DISPLAY and be followed by the contents
of INPUT preceded by ">>"

the clear input button erases the contents of the
INPUT textarea

the clear display button erases the contents of the DISPLAY
textarea

the help button will cause this Guide and Tutorial to be displayed
in the main frame.

They can be used to execute any of the functions described herein.
The differences are that:

The intext UACalculators will generally have an initial expression
in their INPUT text area  generally an first example of whatever is under
discussion

The intext UACalculators have an additional button, labeled "reset"
or just "set", this button is used to reset, or set, the calculator
to its initial expression

The intext UACalculators come in a variety of sizes, while the independent
UACalculator is of fixed size (but the dividing line between it
and the text frame can be moved).
If the independent UACalculator is not on the left side of
the left side of the main frame, you can make it appear by clicking on
the UACalculator button in the top frame. If it is already there then
you can make it disappear by clicking on the UAcalculator button in the
top frame.
Here is an intext UACalculator for you to experiment with:

Here the initial expression is "3 + 99"

Click on perform to see the result appear in the DISPLAY

Edit the expression in the INPUT (e.g., change the numbers or add
some more text such as "* 2") and click perform again. Note that
the DISPLAY keeps earlier results and input.

Try the clear input and clear display buttons

Use the reset button to get back to where you started

experiment (but first read the following warnings)
WARNING
Do not press the enter key!
Pressing the enter key rather than the perform button may cause everything
in the INPUT and DISPLAY to be erased.
WARNING:
Avoid entering syntactically incorrect expressions!
The UAcalculators will only evaluate expressions (perform computations
) which are syntactically correct as determined by the rules for arguments
for the JavaScript eval function. Attempts to evaluate syntactically
incorrect expressions may result in JavaScript errors. It may
or may not be possible to recover from such an error. There are at
least three possibilities:

The error is of no consequence and can be fixed by correcting the
syntax of the expression in the INPUT textarea

The error is more serious but can be corrected by "Reloading" the
page

The error is very serious and will leaving, and subsequently
reentering, the site, or even rebooting the computer.

If you think there is an error caused by a programming error on our part
then please let us know.
It is possible to copy expressions from the book, or the DISPLAY, into
the INPUT and then perform them. However, multiline expressions
copied from the book text will contain extraneous, but invisible,
endofline formatting symbols that will make the expression impossible
to evaluate (will cause a JavaScript error). These symbols can be
edited out, once the expression is copied into the INPUT, by using
the Delete key at the end of each line. Fortunately,
there is no problem copying most multiline expressions from the DISPLAY
and this makes it possible to reuse earlier input and output expressions
as new inputs.
Short Description ofSpecial UACalculator Operations
for Signatures and Algebras
While signatures and algebras are represented within the computer as JavaScript
Objects, the interface only displays part of the information and general
operates on strings rather than on variables. The reasons
for this and the details of the programming are discussed elsewhere.

Operations for displaying signatures:

Operations for constructing signatures:

Operations for displaying algebras:

Operations for constructing algebras:

Operations for "applying" algebras:
Other uses of the UACalculator
The UAcalculators can be used to evaluate many different forms of expressions
in addition to the special universal algebra expressions for which it was
designed. For example, one can evaluate:
To evaluate an expression type it, or copy it, into the INPUT
area (after first clearing the INPUT by clicking on the CLEAR INPUT button),
then press the PERFORM button. The expression, preceded by ">>",
will appear at the top of the DISPLAY area, followed by the result of the
evaluation, preceded by "<<".
Ill formed expressions will cause error messages to appear in alert
windows:
Note, to copy an expression to the calculator (using a twobutton
mouse in Netscape):

highlight the expression (using the left mouse button)

click the right mouse button (a window should appear with a menu) select
COPY from the menu.

go to the calculator and click on the INPUT (or, if there is text in the
INPUT, first click on the "CLEAR INPUT" button)

click on the right mouse button and select PASTE from the menu.
that should do it.
Here are the details for various kinds of expressions:

Arithmetic expressions: An arithmetic
expression such as ((17.2 * 34)+8.7)/3.1
can be evaluated by typing it (or copying it) onto the INPUT and then clicking
on the PERFORM button.

Expressions employing trigonometric functions
and/or logarithms can be evaluated if they are written using the methods
given by the MATH object. For example to find the natural
logarithm of the tangent of 3.2PI radians type the expression
Math.log(Math.tan(3.2*Math.PI))
into
the INPUT and click on the PERFORM button. The available operations
include the following:

Math.E  Euler's constant, given as 2.718281828459045

Math.PI  PI, given as 3.141592653589793

Math.abs(num)  absolute value of num

Math.acos(num)  arccosine of num in radians

Math.asin(num)  arcsine of num in radians

Math.atan(num)  arctangent of num in radians

Math.ceil(num)  round up num to nearest integer

Math.cos(num)  cosine of num (as the number of radians)

Math.sin(num)  sine of num (as the number of radians)

Math.tan(num)  tangent of num (as the number of radians)

Math.exp(num)  value of E raised to the power num

Math.floor(num)  round down to the nearest integer

Math.log(num)  natural logarith of num

Math.pow(num1, num2)  returns num1 to the power num2

Math.random()  returns a random number between 0 and 1

Math.sqrt(num)  square root of num

Math.round(num)  rounds num to nearest integer

Math.max(num1, num2)  returns the max of num1 and num2

Math.min(num1, num2)  returns the min of num1 and num2
Return to top

JavaScript expressions can be evaluated.
For example the JavaScript expression (program)
n=6; i=1; p=1; while (i<=n)
{p=i*p; i++};p
can be typed (or copied) into the INPUT line.
Then clicking on the PERFORM button will cause the expression to be evaluated
(to yield 6! = 720). The expression is a JavaScript program for calculating
the factorial of 6. By editing the expression you can calculate the
factorial of any desired positive integer  just replace the
6 by the number whose factorial you wish to compute and then click on the
PERFORM button.
Note: what is returned as the result of
the evaluation of a Java Script expressions is the value of the last subexpression.
For example, if we change the above expression by removing the final ";p"
and inserting "j=3" into the curlybracketed expression getting n=6;
i=1; p=1; while (i<=n) {p=i*p; i++, j=3}the
result of the evaluation will be 3, the value of the variable j.
Return to
top
The UACalculator Algebraic Operations
In Detail
MSigPrint(name)
displays the signature with name name in Mathematical form, where

name is a string (i.e., a sequence of characters enclosed
in quotation marks). For example: "sig1"or
"prim".
PSigPrint(name)
displays the signature with name name in Programming form, where
showSig(name)
displays the signature with name name in Internal form, where

name is a string (i.e., a sequence of characters enclosed
in quotation marks). For example: "sig1"or
"prim".
showObj(name)
displays the signature with name name in Object form, where

name is a string (i.e., a sequence of characters enclosed
in quotation marks). For example: "sig1"or
"prim".
makeSig(sigame, sorts, operations)
makes a new signature with the given name, sorts and operations, where

sigame is a string (i.e., a sequence
of characters enclosed in quotation marks) that is to be the name of the
signature. For example: "sig1" or
"prim".

sorts is an array of strings (i.e.,
a sequence of strings enclosed in square brackets). For example:
["nat", "bool", "char"].

operations is an array of binary arrays
(i.e., two element arrays) of strings where

the first element of each binary array is a string of form "n1.n2...np,n0"
with p>0, or of the form "n0", where each ni is a sort
name (without quotation marks).

the second element of each binary array is an array of strings (operation
names).

Examples of suitable binary arrays include
["nat", ["zero"]], ["bool", ["true",
"false"]], or ["nat.nat,nat",
["add", "mult", "subt"]]

An example of a suitable array of binary arrays is then
[ ["nat", ["zero"]], ["bool", ["true", "false"]], ["nat.nat,nat",
["add", "mult", "subt"]] ]

The resulting signature will only be temporary, that is, will only exist
until the end of the computing session (and will be destroyed
by any editing or reloading of the page or frame).
algDisplay(algname)
displays the algebra with name algname where

algname is a string (i.e., a
sequence of characters enclosed in quotation marks). For example:
"alg_A"or
"alg_B".
makeAlg(algname, signame, carriers,
operationslist) creates a new algebra with the given name,
signature, carriers and operations where

algname is a string (i.e., a sequence
of characters enclosed in quotation marks). For example: "alg_A"or
"alg_B".

signame is a string (i.e., a sequence
of characters enclosed in quotation marks). For example: "sigP"or
"sig01".

carriers is an array of binary arrays
(i.e., two element arrays) of strings where

the first element of each binary array is the name of a sort
given as a string

the second element of each binary array is a string which evaluates a characteristic
function for the desired carrier

It is permitted to give just an empty array, [ ].

operationslist is an array of binary
arrays (i.e., two element arrays) where either

the first element of each binary array is the name of an operator
given as a string

the second element of each binary array is a string which evaluates to
the desired function for the operation named by the operator. Sometimes
the function will be given explicitly (e.g., "arg[1]*arg[2]" or "'('+arg[1]+'
+ '+arg[2]+')'") in JavaScript or it may employ a special function name
known to the UACalculators (e.g., "addout(arg[1], arg[2])")
OR

the first element will be a function name given without quotes, where the
function is the characteristic function of a set of constant operators

the second element will be a function name given without quotes where the
function, w when applied to an operator accepted by the characteristic
function, will gives the value of the constant operation corresponding
to the operator.

Examples of binary pairs of this kind are [numQ, parseInt] and
[strQ, id].
Algebra(signame, carrierlist,
operationslist) similar to makeAlg but produces an object
of type Algebra  can only be used by preceding it by the reserved word
"new".
algeval(algname, opname,
arglist ) evaluates the operation, opname, applied to
the arguments given in the list, arglist, in accordance with the algebra
with name, algname, where

algname is a string (i.e., a sequence
of characters enclosed in quotation marks) that is the name of an algebra.
For example: "alg_A"or
"alg_B".

opname is a string that is the name
of an operator in the signature of the algebra with name algname

arglist is a list of the form
arg_{1}, arg_{2},... arg_{n} where arg_{i}
is an element of the i^{th} carrier
of the algebra with name algname.
aitch(algname, expr)
evaluates the (variablefree) expression, expr, in accordance with
the algebra with name algname, where

algname is a string (i.e., a sequence
of characters enclosed in quotation marks) that is the name of an algebra.
For example: "alg_A"or
"alg01".

expr is a string representation of
a (variablefree or ground) term written using the signature of the algebra
with name algname. Note: constants in terms must be followed by a
pair of parentheses. An example of a term for alg_A (with signature
"SigP") would be "succ(add(zero( ), succ(zero( )))" and example of
a term for the algebra "alg02" (with signature
"sig02")
would be "concat('aaa'( ), 'bbb'( ))"
aitchfree(algname, argarray,
expr ) evaluates the (possibly variable containing) expression
expr in accordance with algebra named algname where the variables are assigned
values as given in argarray where:

algname is a string (i.e., a sequence
of characters enclosed in quotation marks) that is the name of an algebra.
For example: "alg_A"or
"alg01".

argarray is an array of the form [
["x1", arg_{1}], ["x2", arg_{2}],
... ] where arg_{i}_{ }is
an element of the appropriate carrier enclosed in quotes.

expr is a string representation of
a term written using the signature of the algebra with name algname and
variables x1, x2,.... Note: constants and variables in terms must
be followed by a pair of parentheses. An example of a term for alg_A
(with signature "SigP") would be "add(pred(x2(
)), succ(succ(x1( ))))" and example of a term for the algebra
"alg02"
(with signature "sig02") would be "concat(x1(
), 'bbb'( ))"

aitchFree("alg_E", [["x1", "11"], ["x2","22"], ["x3",
"33"]], "add(pred(x2( )), succ(succ(x1( ))))")