BRUIN

BRUWN UNIVERSITY INTERPRETER

for the,"CAMBRIDGE MONITOR SYSTEM

CMS
• I

written by
The ComputIng laboratory
Brown University
Providence, Rhode Island'I

a~aPtedIB~

to CMS by

Cambridge Scientific Center
CP-67/CMS Support Group
Cambridge, Massachusetts
'Ii
"

I

June 1, 1969

I

I

TABLE OF CONTENTS

~'

BRUIN
syntax notat ion•
system proceduresEntering BRUIN
Exiting from BRUIN.
input conventions•
data elements
Constants
Variables
operators and expressions
Arithmetic !Expressions and Functions
Boolean Expressions
Character String Expl"'essioris and Functions
direct and indirect mode
assignment statement.
SET statement
simp 1e console input-output
OUTPUT stai.ements
LJ NE statements•
INPUT statements'.
control statements
CALL statement
GO statement
TO statement
I F statement
FOR statement
STOP statement
DONE statement
program changes•
DELETE statement
storage request
ALLOCATE statement
file maintenance
SAVE statement
LOAD statement
other features
Keywords Operands
Comment Statements'
Stopping Program Loops
matrix statements
Matrix Input statements
Matrix Output statements
Matrix Expressions
Matrix Assignment Statements.
summary
appendix al. Table of Instructions
2. Sample Program and Output
appendix b
1- BRUIN Character Set
2. Built-In Mathematical Functions

..

1

2
4
4
4
5
6

6
7
9
9

11

14
16
19

19·
21

•

.

21
23
24
26
26
27
28

.

()

29

.

31
33
33
35
35
37
37
38
38
39

.

,

.

40
40

.

,r -"l

,

.

I

41

r

41
42

42
44
45

.

'"

;;

48
49
50

.,

50
51

52
52
53
• !

J

I
I
j

,I
i
1

I

INTRODUCTION

, 1
1

.~ I

,!

":'.

This manual describes the facili~ies of the Brown University
Interpreter (BRUIN) as it is implemented within the Cambridge
Monitor System.
The BRUIN language is modeled after the University of Pittsburgh
Interpretive Language (PIL). PIL was chosen as a model because
it contains features which are highly desirable in a console
language. Unlike a batch processing language, BRUIN (and PILl
provide the user with direct man-machine interaction capabilities.
This feature is most noticeable in error-recovery procedures.
After BRUIN reports an error in either syntax or program logic,
it allows the user to make corrections and continue without a news ta rt. Another commendab 1e BRU I N fea tu re is the lack of proces sor­oriented statements such as array dimensions and variable types.

.i

I!

f
l

:1

:I

!I
:' I

I
I

The major goal of the BRUIN designers is that BRUIN be a language
which will allow a neophyte as well as an experienced programmer
to expend his energies on problem-solving ra~her than on "program­ming". Towards this goal t-he syntax has been kept simple, themeaning of each statement clear and unambiguous. BRUIN can best
be utilized as either a program development tool or as a small
numeric problem-solving tool.

I

I

r

I

i

____

~

I
_____________1 _.J

SYNTAX NOTATION
Throughout
thismanual, wherever a BRUIN statement is described thatstatement will be illustrated with a uniform system of notation.
ThQ~~Y!QE~2(special
BRUIN words) will be in upper case.
This is not drequirement of the language; i t is merely adevice to denotetheliteral occurrence of thatword.
Keywords, in fact, may appear in
combinations of upper-case and lower-case letters.
Bracesarenot an element of the language but are used to denote a position in astatement where the user must make a replacement.

«»

Every BRUIN statement begins with akeyword orpart ands~ep
number. (See thesection "Direct and Indirect Mode", page 19, for a
description of the form of the the part and step number.)A statement
is at most 80 characters in length.
Each statement begins onanewline and cannot be continued on a second line.
A statement may, butneed not end with a period.
Keywords,
part-step numbers
and user-defined elements(suchasvariables) must not be immediately adjacent to one another.
They must
be separated by asingle symbol operator (e.g.
+ I *), specif~ed
punctuation ( , :;), an assignment symbol ( = ) or a
blank.
There
must notbe blank spaces
withinkeywords, part numbers and user­
defined elements.
~~~~£1!_1~

The syntax of a form of theconditionalst~tement

is

If <Boolean expression), THEN <command>; ELSE <command>.
A correct BRUIN command then could be
IF a =b, Then TO STep 1.5;Etse to step 1.6.
EY1_!!Q~

IFa=b, Then TOSTep 1.5;ELse to step 1.6.~

The above statement is in error because there is no.t a
blankbetweenthe
F in the keyword IF and the variable a, and between the keywords
TO and Step.
Notice that the keywords IF, THEN and ELSE appear in a
combination of upper-case and lower-case letters.

2

~.

I F a= 5.

11,THEN TO STEP 1.5;RLSE TO STEP l.b.

This statemp.nt is incorrect because thp.re is a blank in the~nd in the ~onstant 5.11.

k~'yw0rd

IF

I.

i
• I

I

0

<

!

i·
I

1
j

1

"j
i

i

····1

!

I,

!
j

.
, J
.. ,

3

,I
I
-I
I

.J

SYSTEM PROCEDURESEntering BRUIN

II

After logging into CP and IPL' Ing CMS, type "BRUIN".
will respond with the message "BRUIN READY".

The console'I

Exiting from BRUlN
When you are finished using BRUIN, you should dismiss the BRUIN
interpreter with the BRUIN command:
CANCELCANCEL does not log you off.
In order to log off from the terminal,
thereby preventing a se~ond party from accessing the system under
your number and password, type:
CP LOGOUT·I~

To use the terminal system again,. you must repeat the CP LOGIN
procedure.

.,,

J.

!

iNPUT

CONVENTIONSeMS Input c6nventions are used for the character delete andline delete functionso
However, input characters~re not converted to upper case o

,;,

DATA

ELE~ENTS

There areth ree types of constants:
real arithmetic constant,cqnstant and character string constant.

BooleanAn 2..£!!h~~l'!'£_£Qn§ta!!.! is written with at most 7 decimal
digitsWLthan optional decimal point.
The constant may be immediately followeJ
by the letter E (must be upper case) and a one or two digit signed Ol
unsigned integer specifying an integral
paver of ten (scientilLc
nota tion).
In ei ther form of the constant there must not be embedJ.ed
blanks.
Some examples of 'proper arithmetic constants appear below:,

12.34567
(\.

3567

0['

3567.

56.5E-5

meaning 56.5 x 10- 5

125E4

meaning 125 x 10·

A constant(and resultsof alloperations)canhave a maxilLlUiU
magnitude of 7 x 10 'S ann a minimum non-zero magnitude of 5.4 x 10- 79 •T he f!QQJ:.~2.!L£Qnsl2.nl:! are T :iE Tau E an d TH E FALSE wit te nlower case letters.

in

upper

0l

£.h~£~£l~I __ §!£i!Lg_£Q.!!§l~!ll§consist of a string of characters encloo:i~J
in double quotes.
The double quote character may not
occur
in d
str-ing constant.
Some proper- character str-ing constants are:"$1,,3.
5" and "BRUIN".
The maximum length of a character- string constant Lo:ilimited by the size of the line.

".

6----------------------------------------------------~--~--------------------------------------~

I

t

,!

The

ndille of a variable must be constrU~ted according to the fallowing

rules:

,.

rh~

2.

The first chdrdctelC lllust be one

J~

The remaining

Ilpper-cdse
varinbl~total number ofcharac~ers

cha~actersmust not exceed eight (8)_ore· the alphabetic character'::';Q:!.

may be letters or nu~erals.

letters are distinguishednames; therefore the variable

from
na~e

lower-case letters 1U
DET is different from tne

name Det.
I

I.jnames:DATANA19E@

B,

FXY~

I

812cn

r
drldition to the scalar vacldble which denotes one ite~, there L~
the subscripted vd~iable whicb denotes a collection of items.
Asubscriptedvariable is written 35 a variable name followed by a lLst
ot subscripts enclosel LD parentheses. The subscripts a~e sepa~atejby commas.
For exa,aple o Fl (1,2) couLl l.."epr.-esent the f.ll.I:st row, ::ieCOJrl.l
colu~n of a table c~112d Fl.
InI
1

The r~les for subscripted vdriables are summarizei below:

Each su~script. m~y be dn arithmetic constant, C].rithmetLCor an arith~etic expression.
2.
An array may have up to four subscripts.
3.
A subscript mcqr have any value between -)2767 and 32767,. l!ut
only the int~ger part is us~d to reference an element of the ar~ayQ·
1.

vaLL~~le,

iI
'j

e

I

\

I
z (i, j,2*j), TAJL=: (Z (I"J,J), I+-J)

In Example 3, assume i is 1.7 and j is 2.4; because only the inte~~~part of the subscript is used, the element referred to in the z arcdY
is z(1,2,4).

7

."

Storage is allocated dynamically for variables <both scalarvariables and arrays) at the time that the variable is defined<i.e., assigned a value). Therefore, sparse arrays are kept
in a reduced space. In no BRUIN statement is is possible toreference the whole array by using only the name; both nameand subscript must be specified.
To use a variable which has no associated value is an error.
The interpreter wi11 notify the user that this type of error
has occurred.
In addition to having a value, a variable has an associated data
type. The data type may be arithmetic, Boolean, or character
string, depending on the type of value assigned to it. To change
the data type of a variable by assigning to It a value of a different
data type is an error. The Interpreter will notify the user that'
this sort of error has occurred.

8~~~--------------------------------------------~--~--------------------------~--~)

...
OPERATORS AND .EXPRESSIONS

The arithmetic operators of addition, subtraction, multiplication,
division and exponentiation are represented symbolically by +,,*,I, and ** respectively.
(The vertical bar~
Ig also indicates
exponentiation.)'Jr--------·-------------------------------------,
Im~~ni~g~!~!El~
I
I
I
I +
I
I
I -

addition

a+b

J

I

I
I
i

1t.

J
subtraction• I

multiplicationIdillisioIk

albexporJ.entiation

a**b

Table

1~

Arithmetic Operators

Arithmetic constants and variable's are combined by the' arithmetic
operators to form ~rithmitic expressions.
Arithmetic expressions, iu
turn, ~an be bracketed by parentheses to form other arithmetic
expressions.
The order in which expressions are evaluated is governedbythe following rules of precedence with operations of a higher
precedence performed before those of a lower precedence.
Except for
exponentiation,
unary- and unary+,
where operators of the samepriority appear in an expression, there is a left-to-right evalaationof the expression.
Therefore AlBIC produces th~ same result as(A/B)/C.
If two or more of the op~rators of exponentiation,
unary-,
unary+ appear in an arithmetic expression, the order of evaluation isfrom right to left. Thus A**-2 produces the same result as A**(-2).

9

.j

,

r
~.

highestlowestfunctions

SQRT (x)exponentiation,
unary _., unary +AIBI-2

multiplicationand division

a*N/yaddition andsubtraction

z

+ p -

1

.J

If an expression is enclosed in parentheses, it is evaluated before
its associated operation is performed.
For example, in the expression
c*(a + b),
a is added to b and this sum is multiplied by c.
Thusparentheses modify the normal precedence rules.
Parentheses can beused where there is a possibility of ambiguity~
Another
way that arithmetic expressions can be formed is by taking
functions of other arithmetic expressions.
The set of predefinedarithmetic functions is shown in Table 2 of Appendix B.
The function
name is fixed but may be written with upper-case or lower-caseletters.
Each of the functions has one argument and returns one
value.
The argument must be enclosed in parentheses and may be anarithmetic expression.
The expression is evaluated before the func­tion is called.
Thus, if it is necessary to compute sin 2x, the BRUIN
expression would be written SIN (2*x)
Examples:

c+a**8/b+5.El0

c + a 8 /b + 5xl0 10

TAN (LN (a*c)) 12

tan 2 (In (ac) )-2**2*b(-2) **2*b(- 2) 2 b

10

•i

.<

There are six relational operators and four Boolean operators definedin BRUIN~
The symbolic representations of these operators and theirdefinitions are found in Table 2 and Table 3.

----------------,~~~!£l~Irl§hQ£t_,{Q!:.!
I
I
I
I
I
I
I
I
I
I

<

$LT

a less than b

a

< b

I
I
I

I

=

$LE

a less than or equal to b

a $LE b$EQa,equal b

a = b

(Ji

a not equal b$NE
a $NE b!
!
I
$GT
a $GT ba·greater than b
>
I
I
I
$GE
a greater than or equal to b a $GE b
I
I
I
la and b ar~ arithmetic expressions
IL ___________________•___________________
Table 2.

~

Relational Operators

The relational operators have two arithmetic expressions as operands~
the result of such operations is a Boolean value (i.e., either true or
false.)
Thus, the expression B**2 - 4*A*C SGT 0 is an assertion thatis either or false, or in BRUIN notation the result will be either THE
TRUE or THE FALSE.

11..

Boolean values oroperators or the
Boolean value.

expressions may be combined with the Boolean$NE to produce a
two relational operators $EQ,

r----------------­
l§hQ!t_fQ£~
lQQg_f2£m~--.--------------------------,

g!~~E!~

I

I

J

I
I
I

I
I

I
I
I
I
I

,
I
I
I
I

&

$AND

a<b liAND c<dlogical product

J

J

$OR

logical sum or inclusive ora<b $OR c<d$NOTcomplement

$NOT

$XOR

.
exclusive orIII(a <b)JI
J

a<b liOR c<dJII.
la, b, c and d are arithmeti~ expressions
IL___· ________· ______________ ' _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _JI,~

Table 3.

:,

Boolean Operators

The Boolean operators (sometimes called logical operators) have theirusual meaning. Thus, if P and Q are Boolean values the expression
P $AND.Q has the value THE TRUE, if and only if both P and Q have thevalue THE TRUE. The expression P $OR Q has the value THE TRUE if
either P or Q or both P and Q have the value THE TRUE.
Whereas, P$XOR Q has the value THE TRUE if either P or Q but nQi both have the.value"THE TRUE.
Finally, $NOT P has the value THE TRUE if and only if
P has the value THE FALSE.
I

'j

!

I

I
I

12
,

,

-------.---~~~---.-----------.~. --~..

The prio~ities of operations for arithmetic, Boolean and relational
operations are now given by the following list:---------------------------- '----------,
arithmetic function

highest**, unary +, unary -, $NOT
lit

/

. ­
relational operations
SAND
lowest$OR, $XOa

L ____________ ~ _________--------'The priorities for arithmetic, Boolean and relational operators issimilar to the priority of such operators in the PL/1 language but not
the Foa~RAN language.
The one difference is in the operator $NOT.
This differenc~ becomes apparent in the expression $NOT a<b, where aand b have arithmetic values. Since $NOT has higher priority than theo~er~tor<, ·an attem~t to evaluate $NOT a in this expression will bemade. BRUIN will then stop with the error message "WRONG KIND OFOPERAND".
simply enclosing the expression a<b in parentheses, as in
Table 3, will result in the Boolean expression ~<b being the operandof SNOT.
The following example illustrates the evaluation of an expression
according to the priority of the operators.
-a**b

< c+2

$AND a+c=zThis expression is evaluated as if the various parts were enclosed
parentheses.
- (a**b)(c+ 2)(a +c)in(z)(- (a**b, ) < (c+2)(a+c) =(z)( (- (a**b) ) < (c+2) )SAND «a+c) = (z) )'.

13

There are three special operators $FC, $LC and $CON for manipulating
character string data.
An expression of the two operators $FC and $LC
is evaluated fromright to left.
In addition to these special
operators the relational operators are valid for comparing character
string data.
The comparison will be made according to the 360
collating sequence.
(i.e.
blank <punctuation < a < b ••• <z<A<B •••<Z<O.<9).
the strings are compared character by character from left
to right.
If the strings are of different lengths the shorter string
will be compared as if it were extended on the right with blanks.
Notice that this implies that the character string "ab" will compare
equal to the character string "ab ".
Table 4 summarizes the validcharacter string operators: The concatenation operator, $CON, may be
written _ (underline symbol) or II (two vertical bars).

r--------------­~!~ll!£lg§
N $FC S

Qgf!n!!:i2n

The N first characters of string 5------,
ResultIa string of lengthl
NI
I"

N' $LC S

The N last characters of string 5

a string of lengthl
N
I

,

.\

S

$CON P string Sand P are joined in such aor
way that the first character of P
immediately
follows the last
SI I P
character of S

S $LT P
$LE P
compare Sand P character$EQ P
by character from left to right
S $NE P
IS $GT P
IS $GE PII
IN has an arithmetic value
IS and P are character strings.
I _________________
L
5
5

Table 4.

Ia string with the Ilength = length S I+ length P
I
I
I
I
I
I
a Boolean valuel
I
I
I
I
I
I
I
I

character String Operators
14

• I

I
1

i'

I
1

~Thereare four special functions whichhave a character stringargument.
They are UPPR, LOWR, LEN, AND CHAR.
The function ~PPR(S)produces a character string with alphabetic characters the upper caseequivalent of the alphabetic characters of S.
LOWR(S) produces acharacte~ string with alphabetic characters the lower case
eqUivalentof the alphabetic characters of S.
LEN(S) returns an arithmetic value
which is the number of characters in string S.
CHAR(X) returns thecharacter representation of the arithmetic value X.
In a mixed expression of string operators,
binary operators
Boolean operators the usual rules of priority as well as
conventions regarding left to right evaluation are observed.
string operators are placed in the priority table as follows:

and
the
The

r

,
I

,I

(~'i

,

,

I
I
i
I
I
I
i

highestfunctions** unary + unary -

$NOT

*1
+­

lOh\'est$FC $LC$CONSEQ SGE $LE$NE $GT $LT SEQ
SAND$OR $XOR'---_.

The following
example will serve to illustrate the use of the string
operators and the priority rules for string operators:

I

·1

I

I
I

Assume that D is a character string variable which is equal
to "PROVIDENCE, R.I." and one wishes to make every letter except P in
Providence a lower case letter.
This could be don~ with
theexpression

,1
I
~

'j

II

1 SFC D SCON LOWR(9 SLC 10 SFC D)SCON 6 $LC D
This expression results in a character string of length
equivalent to "providence, R.I.".

i

16

which

is

iI
,

I
J

In
building character strings by concatenation one must observe a
If this length is exceeded BRUIN will issue anmaximum length of 252.
error message to that effect.

15

DIRECT AND INDIRECT MODE
To facilitatS~an-machineinteraction~
BRUIN provides two modes ot
operation, the desk calculator or direct mode and the stored
progrdm
or indirect mode.

Inthe diract mode the console can b~ thought of as a desk calculatolin;that the statement is ~xecuted i~mediately andthetext oftne
statement is notretained in memorYe
This mode of operation allow~
the user to evaluate expressions, store
results ofexpressions to~latet use, and direct the interpreter to execute a stored program.
The user merely
Errots ace reported immeoiately in the direct moneenot
The statement in error isretypes the correct statement.
retained.
For eXample,;.,

TYPE SIN(8*3.141.160, .
\II 0 u 1 Ii

a BRUI N res ron s e "1'1 r S FOR MED -E XPRE S S ION It be c a use 0 fright parenthesis.
The uset retypes

t e suI t i n

missin~the

TYPE SIN (8*3.14) /16

and the res~lt of the caiculation would appear ass rl (8 * 3 • 1 4) /1 6

= ­ O. 7 q h 6093 E- UJ

The assignment statement in the jirect mode
SET

L=AI2-4*A*C-!

is li~e~ise executed immediately, causing the variable L to be given awhich could be used either in the direct mode or stored progra~
mode.
Notica here that the statement itself is not retdinedbuttheresult of the calculation is retained in L.
~alue

16

I
\

1

mode, statements are sto~edand executed unde~ prog~dm
in a. sequence oefined by pa~t and step nUlllbe~s.
In otneewoeds, indirect statements make up a stored p~ogram.
The user may goback and forth
betweenthe two modes.
The m~nner by which this 1~
accomplished will be seen in later examples.
In theindi~ectccnt~olA statement in the indirect mode is always preceded by a part anl ste~number.
It is this number ~hich tells BRUIN that this is astatementof the indLrect m;)de.
The part and step numbel:' are each .at most 3
diq1tS in length and arp separated by a period.
A blank must
follo~
thisnumber but ~ust not be imbedded in the pd~t-step number.
rhe
above TYPE statement, written in the indirect mode with
part
numcer11, step numbel:' 01, would appear as
11.01 TYPE SIN(8*3.14)/16

This

statem~nt

is stored without being execute! immediately.

par t i s a call e c t ion 0 f 0 I. C' 0 r mor e s t e p s wit h the ide n tic d 1 pd L t.
Sincp steps rt["P drran-jed ill
ascen,tin'J
step number bytH~
intecpreter,itisnot necessary to type- !:>teps in se.juentidl ord~L.
DU[,1nq the execution phase of
that
part,
the st.dteUlenL; will De
executed in the sorted order of step numbers in that part.
A

number.

Step numbe~s are treatedas decLmal
fractions an.1
may have dRy
increment between them.
Par example, a part 1 could be written w~t~
steps 0, 1 iind 999 (written with part !lumbers 1s1.·0, 1.1 and 1.99:1).
This would be executed by the interpreter in the order
1.0,
1.1
dua
1.999.
If it
is necessary
to make an insertion,say
betw~ens tat em en t s 1. 0 d n d 1. 1, .s imp 1 y c h 00 sea n y n urn be r(e • 91 • 05)
bet wee n
1.0
ano
1.1.
Then
part 1 woul~ consist of statements withnumbeLs
1.0, 1.GS, 1.1, 1.9<,}9 and would be executed in thdt orjer~
For S~Ctl
progrd~ changes it ~s ~Lse to have ~aps 1n the step 3equence.
Duriny the execution ofap~oJrd~in the stored pr0~ram mode, dsequence of BRUIN stdt~ment3 with the same partnumbe~
are executed
sequentially(assumin.,J ther:-e is no transfer:- out of that part). 'Tl1~Smeans that a statement with the number 2.000 is not executed after thestatement wl,th the number 1.999,
ullle~:;sthese
part::; dre logiGalq.
connected hy the user.
This can be accomplished in d vdliety of ways.
To give just onp example, statement 1.g99 could be the instruct~on

1.999 TO STEP 2.000

17

"

I

I

ASSIGNMENT STATEMENTSET <variable name>= <expr~ssion>,<variable name> = <elpression>,etc.

The E'xpcession on the right-hand side of the assi-jnment symbol (=) 1IidY
be 3.0 drithm8tic Expression, Boolean expression or str-in-j expressiuilo
The
type
of
expression will deter-mine the .lata type assigned to tue
variable.
The keyword
SET· is 2£tkQn~1 and may be omitted;
tor­clarity, every example in the manual will use the keyword.
Thp SET statement CJI1 hdve a list of assiqnments of tne fOLlI <va[iaDL~
name> ::: <ex.)n~ssion); each ds!:)ignment in the list must he sepdr-dted Di
com~dS.
J~
thecp
lS o~ly one assigument in the stdtem~nt, omit tue
comma.
The 1.nt2rpretp[ will mall.e a:::;.3iqnments in d list beqillIll.ng wlotn
the leftmo~t plementin the list dni proceeding to the right.

:.>E':'w= SI'l(x+y) ,c=w*x,w=w*y

rJSl.n J the most ['ecently (:\:,siyneLi vdlues of x aol y, the vdriable w 1.0.;,lssiilledthevdlul"' of the drl.thmetic eXt>ress.ion sin(x~y).
ThE"n C .l~dssi j08-1 the v,llu(-> of w*x, 'tIher" thl' v~lue ot
WI
l.S
tat>
l!'reviou..;lrc em t' ute d
vd 1 u e ,~ in (x +y) •Fin ,d 1 Y '01 1 S 'J 1. V (-> n t It (-> new lye 0 mp U te.lv d 1 u t~ W * Y•Va r i il b 11"'::> WI , i 111 C Ice 1L 1. t h mc: tic V :i l- i d h 10 :,;J .., C a uset 11 e iwerp jivpn drithmetic vdlue~~.

SET ROJL= The Trul"'

vdriabl....
:l')OL
1.S dS'3i,)nf:>li ttl'~ COTlst jut :1,)010dn
thprpfore the vdciable dOOL is d Jool~an vdrlablp.

Thp

1/ liue'

The True;0

SET ray(1,1)===$NOT(2 :: 2)
The first === symbol on the left is the assignment symbol.
The second =symbol istherelational operator.
Therefore the value "Lll;e ll ..LS
assigned to the subscripted variable ray (1, 1).
raytherefore
i~~' aboolean array.

101.98 SET, Num = "1234567890"
The double quotes around 1234567890 cause Num to be a string variaole.
ThereforeNum
can be combined by string operations with other str~ng
operands.
The number 101.98 designates part 101, step 98.

20

SET ray (1,1) "=$NOT (2 = 2)
The first = symbol on the left is the assignment symbol.
The second ~symbolistherelational operator.
Therefore the value "filL;e" ..LS
assigned to the subscripted variable ray (1, 1).
raytherefore
i~~' aboolean array.

101.98 SET' Num = "1234567890"
The double quotes around 1234567890 cause Num to be a string varianle.
Therefore Num can be combined by string operations with other str~ng
operands.
The number 101.98 designates part 101, step 98.

20

(\.

SIMPLE CONSOLE INPUT-OUTPUT

PUT <list of items separated by commas>*or
PUT LIST <list of items separated by commas>**(The keyword TYPE may be used in place of PUT).
An item in the output list of' thefour types of elements:
1.

(~

2.
3.
4.

fi!:§1 PUT statement may be one ofa variable name whose associated value isoto be written,
an expression to be evaluated and written out,a character string enclosed in double quotes (")
the special keywords, ALL, ALL VALUES, ALL PARTS, PART,STEP.

The PUT LIST form of the output statement diff~rs from the simple
put
form
in
that,
the list of items of the PUT LIST may not contain thespecial keywords described in 4 above.
In addition,
the PUT LIST
writes the items in columns of 5 per line until the list is exhausted;asimple PUT
writes the items one per line until
the list is
exhausted.
Character strings in the PUT LIST form should nothavemore than
15 characters; only the leftmost 15 characters of a str1nj
are written.

PUT "The value of A is" , A
Example 8 illustrates the tirst type of PUT statement.
Each 1tem on
the list will be written on a separate line.
Assuming A has the value
2, this statement will cause the two lines to be written,
The value of A is
A= 2.000000( \ The interpreter always writes the variable name followed by the value
in this PUT form.

21

01

PUT LIST "The value of An ,A
Example 9 illustrates the second form of thestatement will cause the line to be written
The value of A

PUT

This

statement.

2.000000

PUT 3*SIN(3.14159/16 + SQRT(35.9»
This statement will result in the line
3*sin(3.14159/16 + sqrt.(35 .. 9»The

special~purpose1.

= -.2850968

forms and their use are described below:

To write out a copy of special parts sorted instep order,
PUTPART <part number>

PUT PART 5, PART 6

2.

To write out a copy of the entire program,
PUT. ALL PARTS

3.

To
PUT

4.

list all defined variables and their current values,
ALL VALUES.

To list the entire program and all
PUTvariab~es,.

in storage,

ALL.

22

----------------------------------------~----~--~--~---------------------------------~

5.

To write out a step,

PUT STEP (part and step number>

Ixamole:PUT STEP 1.3~ STEP 50.1
Since the typewriter is a relatively slow device, these features
should be used sparingly.

UNE statement

The line statement causes the console typewriter to space one line
down the page.
Examp] e 11.

1.1 Put (EXP(l.5)+EXP(-1.5})/2
1. 2 Li ne
1.3 Put (EXP(l.S}-EXP(-1.5»/2

CALL PART 1

In examp 1e ll~ the command 1I NE wi 11 produce a blank 1 i ne be tween
the two output 1ines. The output therefore will be(EXP(1.5)+EXP(-1.5»/2=. 2.352406(EXP(1.5)~EXP(-1.5»/2=2.12927823

<part and step number) GET <list of variables separated by commas).
or<part andcommas)·stepnu~bet)

GET

LIST

<list

of variables separated by* (The keyword DEMAND may be used in place of GET)On e~ecution of the GET statement, BRUIN requests the user to prov~devalues for the variables in the list following the keywords GET or GET
LIST. The response by the 'user way be one of four types of data:
1.
2.
3.
4.

constants,
an expression i~ terms of previously defined variables,
function I
any combination of the above.

In the simple GET statement BRUIN prompts the user on each variable ~nthe list by writing the variable name followed by =); it then wa1ts
for a response from the user.

1 .. 5 GET a,b,c

To the command GET a,b,c, the interpreter will respond witha=)

The user may then type.a number (e.g.
the interpreter types

4.0)

after the> symbol.

Then

b=)

Again the user may type 3.5*a.
The value of a has already been
defined; therefore the value of the product of 1.5 and a vill ~eassigned to b.
Finally the interpreter typesc=)

The user may respond with SQRT(a+b).
24

n
'"

Assume that the value of i
3.11 DEMAND B(i,i+j)~!~~£le_1J~

is 1 and j is 3.

,

BRUIN will retuen the value of the subsceipts with the array nameB(l,4)=>On execution of the GET LIST statement, BRUIN will peompt only witb ~greater than (» symbol. The user may then enter any number of d4ta
items on a line;
the data item::; must be separated by commas.
Auy
number- of blanks may surround the commas.
If the list is uot
satisfied after the transmission of one line of data, BRUIN willprompt the user for more data.
If(n+3)
numbee of data items 1::0
teansmitted and the list of varables only requests n items, the last jdata items will be i~nored.
~!~m£l~ __ l~~Assume that A should have the value 5.1, 9 tne
value 4.3, C the value -8x.O- s , and J the value 1.

81005 GET LIST A,B,C,Jn

On this comrrand BROIN
t hell pnter- on a Linewill peompt once with the symbol>.

5",'1,4.3, -8 .. E5,

The

user

indY

1.

Notice that the values are assigned tothevariables

from

left

td·

r 19 ht.

In exaL'lples 12,
1,1,
and 14 the varia hies in the list were giveu
ar-ithwetic values but this need not be the case.
3001ean values orchar-~ctee
strinqs may also be eead in dS values.
Example 1~ is dll
illu::;tration of 4 GET LIST ~tdtement with vdriable A beinJ.given dnarithm8tic·value, B a Boole,ln vdlue dnd C a chaeactH.[ strin,} va.lue.

80.4 GET LIST A,B,C

On execution of statement 80.4, BRUIN transmits the symbol >.
4.125*SQRT (3.14159),

THE Til !lE,

Entec

"STRING"A ~ariable is assignAd a lata type througn the GET statement as welLas thp SET statement.
In example 15 then, the variable A is dU
aeithmetic vari:lble,
B is a Boolean variable.,- and C is a strJ..fl':jv ari able.·

25

,

j

CONTROL STATEMENTS
In the preceeding sections you were shown bow to refer to variable andconstant quantities, process input and output and assign values tovariables.
In most cases a
problem cannot be solved by a simple
sequence of assignment statements and input/output statements.
State­
ments to permit decision making are oft~n required.
These decis~onprocessing statements permit the programmer to vary the order in wh~c~statements are executed.
Sucb statements which provide the program~~rwith the ability to alter program flow are here called CONTduL
statements.

CALL PART <part number>
The CALL statement causes a part tolowest step number.

beexecuted

starting

with

~ts

~!~~E!~_-1~~
Assume that the following proceJure to calcul­
ate an expression involving input parameters X, Y 6 DELTAX,DELTAY LS
stored in the indirect mode.

15e11 SET X = X + DELTAX, Y = Y + DELTAY
15.15 SET FlY = X*SIND(Y)/COSD(X) +3*X:
In order to execute the two-step procedure beginning with its firststep (here 11) and terminating with its last step (here 15), enter thestatetnent
CALL PART 15
Since the CALL statement is in the direct mode,
it willcaus~
execution of part 15 to take place immediately.
Assuming that th~variables X, Y, DELTAX and DELTAY have been defined,X,
Y,
and .r:u
will
be assigned nelf values.
Following the execution of d part (h~u~part 15) invoked by a direct command, BRUIN will halt execution WLth
the statement"EXECUTION HALTED AT END OF PART 1'5"
In the indirect mode,at the termination of the specified pact,
control passes to tbe statement following the CALL.
26

Example 17.

Assume part 25 of example 16.

2.51 CALL PART 15
2.91 PUT X,y,FXY...

On entering a CALL PART 2 in the direct mode, the order of execution
he~e will be 2.51, 15.11, 15.15 and 2.91.
The point to observe hereis that control of execution is returned to the statement following
the CALL statement (here 2.91). If no errors have been encountered,execution will halt with the statement
IIEXECUTION HALTED AT END OF PART 2."

GO statement,

It ,was stated earlier that BRUIN will stop execution of a stored
program when an ~rror is encountered. The user may correct his
error and continue execution at the point of error. This is doneby typing in the correctlori and then issuing the direct command GO.
Assume that in ExampJ~ 16 X is initially 0, DELTAX is 1, DELTAY is 1
but that Y was not given an Initial val.ue~ When the statement ofstep 15.11 is executed, BRUIN will issue the error statement"ERROR AT STEP 15.11:

UNDEFINED SYMBOL"Entering the statements
SET Y = 1
GO

I\

Will cause execution to resume by executing step 15.11 again. A
word of caution is necessary here. Because X was already evaluatedas 1 before BRUIN discovered the error, X will take on the value
2 when execution resumes at step 15.11

i-I"' ··,··..-<-iI

The GO command will not ca~~~ execution to resume when BRUIN
interrupts because of ~ infinite loop.

II

~I

1i

i'

I

, I
I
I

I
I

------------~,---

27

I

•I
I

There ace two forms of the TO statement.

One foem is<part and step nuaber> TO PART <pact number> **(In place of TO, GO TO may be used)
This TO statement causes control to be transferredto the fic~tstatement in the specified part. To illustrate the difference betw~ena TO statement and CALL statement Example 11 is rewritten replac1.n~statement 2.51 with a TO statement.

15.11 SET X=X+DELTAX,Y=Y+DELTAY
15.15 SET FXY=X*SIND (Y)/COSD (X) +3*X
2.51 To part 15:
2.91 Put x, Y, FXY
On a CALL PART 2, the order of execution will be 2.51,
15.11,
15.1~.
Centrol of execution is not eeturned to the statement following the TJ
part 15 statement (here 2.91) as it is with a CALL.

Another form of the TO statement is<part and step numbee> TO STEP <pact and step number>** (In place of TO, GO TO may be used)
This TO statement causes conteol to be transferred to the statementwith the specified part and step namber.

15.11 SET X=X.DELTAX,Y=Y+DELTA~
15.15 SET FXY=X*SIND(Y}/COSD(X) +3*X
2.51 TO STEP 15.15
2.91 PUT X,Y,FXY
On a CALL PART 2, the order of execu tion vi'll be ~. 51,
foem of TO permits teansfee of control within a part.

15. 15.

T1L1.SThe TO statement is valid only in the indirect mode.

28______________________________~________________~~_ _ _ _ _ _ _ _ _ _ _ _ _~JI

The IF statement causes BRUIN to test a value and proceed in one ot
two possible paths. The Boolean expression in the IF statement is toe
valun that is t~sted. The clauses THEN and ELSE describe the L~O
possible actions. The simplest form is

IF <Boolean expression>, THEN <command>
If
the Boolean expression here has the value true, the THEN clause i~
executed.
If the expression is false the THEN clause is ~Qt executcQ.
EXPcltion proceeds with the statement following the IF ~tatement.
fue
iiord THEN may be omitted but not the punctuation (,).

1.5 If bI2-4*a*c<O, TYPE "ROOTS COMPLEX"
1.0

If the expression bZ -4ac is less than zero, the TYPE command ~~executed followed by '~xecution of statement 1.6. It the express~~ub 2 -Qac is greater than or equal to zero, control passes directly tostatement 1.6.

The 0ther form of If has an ELSE clause as well as a THEN clause.
IF<Boolean expression>, TIIEN <command>; ELSE <commilllc1>

If
the Roolean expression has the value true, the T:IEN clause J.;:;
executed.
If the expression is false, the ELSE clause J.S executclu.
The words THEN and ELSE may be omitted but not the punctuation (,;).

3.9
J.91

SET A = x<3 ioa X>5
IF A, TO STEP 4.0; ELSE TO STEP 4.3

In this example A is a Boolean variable. If A has the value TRUL,
transfer is made to step 4.0.
If A has the value FALSE,
transfer ~:;;
made to step 4.3.

29

I

I

~.!~!!LE!~_~~.!...
Assume . that the user wished to accomplish athree-way branch depending on whether x is less than,equal. to or
grea ter than y and then' wished to return to the statement following
the IF statement.

1.998 IF x<y, CALL P RT 3;
ELSE CALL PART 5
1.999
....
3.1

· · ·

3.999

SET FXY = SIN(x-y)/x

4.6"4.999·· ··· = f.
SET FXY

5.998
5.999

SET FlY .= xl (-xI2-y /2)

ELSE IF x=y, CALL PART 4;

·· ·
0

0

· ·

h
In Example 22 the interpreter compares ~. and y.
If the less thanrelationship is true, part 3 is executed beginning with step 3.1 a~dending with 3e999; control then returns to statement 1.999 by virtueof the interpretation of a CALL c6mmand.
If x is not less than y, the
ELSE clause causes x to be compared with y again in an equality
relationship.
If x is equal to y, part 4 is done; otherwise part5.
~ollowing both part 4 and part 5, step 1.999 is executed.
interpreter will take any BRUIN command in the"THEN, ELSE clauses
but care must be exercised in using another IF in the THEN clause.
If
the expression is false,th~interpreter looks forthe command
following the first semicolon.
Por example,
Th~

1.1 IF a>b, THEN IF c>d, THEN TO STEP 1.4; ELSE TO STEP 4.2;
ELSE TO" STEP 4.3
is interpreted as if the statement were

writte~1.1 IF a>b,. THEN IF c>d, THEN TO STEP 1.4; ELSE TO STEP '4.2 .
In other words, if both a is greater than band c is greater than d,branch to step 1.4; otherwise"branch to step 4.2.
AnotheF way ofwriting this statement is,
1.1 IF a>b $ANDcc>d, THEN TO STEP 1.4; ELSE TO STEP 4.2
30... ,i

The FOR statement specifies that a command is to be repeatedly
executed until a specified criterion is satisfied. The forms oftheFOR statement vary in the stopping- conditions and vary in the mannerin which the values of a control variable are stated.
All forms willtake any BRUIN command except \ a TO command.
The simplest form

re~eats

an object command for a list of values:· .I

FOR <control variable> = <list of arithmetic expressions
separated by commas>:command>**(The keyword
equivalent).

DO

may

101.5 FOR SUB

be

used

in

place

of

FOR;

DO and FOR are= J/~*J,4~J,8*J: GET A(SUB)

This statement will cause the GET command to be executed four times.
Assuming J
is 1, the interpreter will request values for A(1., A(2),A(4), A(8).
This statement could have been written
101.5 FOR SUB= 1,2,4,8: GET A{SUB)·,i

Another form of the FOR statement specifies an initial value,
increment and final value for the control variable.
The general form
is:

:

· I

I

I

FOR (control variable> = <initial value> BY <increment> TO<final value>.,<command>l.

'101.5 FOR sub= 1 BY i

TO 3*i: GET A(sub)Assuming i is 2, the variable sub will take on 'the values 1, 3, .5.
Inthis form of t he FOR statement, the command GET A (sub) is executed forthe initial value.
Then the control variable(here " sub)is incre­mented(here by i) and compared to the final value (here 3*i).
When

31

I"

~.

the value of the control variable is greater than the final value, theloop is terminated.
If no increment is specified, an increment of one(1) is used.
If the final value specified is less than the initialvalue, the command is executed once.
An infinite loop can occur if anincrement is chosen which wilL cause the limit never to be Leached.
(e.g.
initial value =1, increment = -2 and final value 2).

The BY,TO form of the FOR statement may be combined with the list form
as in the following example:

L 1 FOR ID =0,

1, 2 BY 2 TO 8,9: CALL PART 8

ID here takes OD the values 0,1,2,4,6,8 and 9.
Any number of BY,TO
combinations may be used in the list.
If BY is omitted the increment
is assumed to be one (1) until
the TO limit is reached.
,
There exist two additional FOR list forMs.

They are

FOR <variable>=<initial value> BY <increment> UNTIL <Boolean
expression>:<command>

FOR <waLiable>=<initial value> BY (increment) WHILE <Boolean
expression>~<command>-~1£~.!!!:el!L~1.!.

FOR

a~b

Sf 2 UNTIL a>z:

DELETE X(a)The to~.aDd DELETE X(a) will be repeated for successive values
until a is greater than z.

1.6 FORa~b

BY 1 WHILE R<S:

of

a,

I
I
l
1

CALL PART 14

The command, CALL PART 14, will be repeated for a = b, b+l, ••• as longas R is less thanS.
In the UNTIL and WHILE forms, if no increment is
specified the control variabl~ (here a) is not incremented. tare must
be taken that the Boolean expression (R<S) in example 26 is not alwaystrue.
The value of R must at some time in part 14 be set greater than
5 or anfinite loop will result.

32

If the user wishes to stop the execution of his program and perhaps
check some values before continuing, he may use a STOP statement in
the indirect mode.
Assume that the following part is stored:
1.66 SET DIS = BI2 - 4.*A*C
1.67 Stop
1.68 SET D = SQRT(DIS)
1.67 TYPE (-B+D)/{2.*A).

On the command CALL Part 1, statement 1~66 followed by statement
1.67
will be ex~cuted.
The message "STOP AT srEP 1.67" will ~e issued by
BRUIN.
BRUIN will then wait for further instructions.
At th1s point
the user may' make changes or look at D to see if it is negative bytyping in the direct mode •.
PUTDA GO would cause the program to resume execution at statement 1.68.
.1<part and step number>

DONE

The DONE statement causes the interpreter t6 halt execution of apart
by signalling a logical end.
It differs from the STOP in that
execution of the stored program does not stop.
Execution continues a's
it would at the physical end of a part.
The DONE statement is valid only in the indirect mode.

33
I
I

I

p.

1.5
3.3
3.~

FOR I = 1 TO 8:
CALL PART' 3
SET B (I) =0
IF A (I) $LE 0, DONE
SET B(I) ::: A(I)3.5
3.6 DONECALL PART 1

In Example 21 the values of A(1) through A(8) will be compared with O.
If the value of A(I), wher~ I = 1,2, ••• 8, is greater than 0, step
3.5
will be executed.
If A(I) is less than or equal to 0 steps 3.5 and3.6 will not be executed.
An equivalent process could be accomplisbed
by replacing step 3.4 with"

3.4

IF A(I)$LE 0,· TO STEP 3.6

.j
~J

. I

34

PROGRAM CHANGES

When BRUIN is waiting for a command~the usermay enter either adirect br indirect statement.
If a statement with a new step isentered, that statement will be inserted in proper sequence in a parto
If a statement is entered using an old step number, the old statement
will be removed and the new statement will replace it.

If
in further execution
longer needed these may
requirementso

certain variables,
parts or steps are no
be deleted,
therebyreducing
storage

Steps, parts and variables mar be deleted selectively by statements ofthe form:
DELETE STEP <part ~nd step number>
DELETE PART <part number>
DELETE <list of variables separated by commas>

5.7

D~LETE

STEP 5.1

DELETE PART 4
DELETE X"Z(6) ,Z (1}After the execution of a DELETE comman1, for example DELETE A, thevariable X is no longer defined and reference to it ~ill
generate anerror report.

'.

35

All values or parts may be deleted by the following statements:

DELETE ALL VALUESDELETE ALL PARTS
The first statement will leave the defined parts and delete all
variables.
The second statement will leave the definp.d variables anddelete all parts.
To deletestatement

everything

belongingtothe user(parts and values)

the

DELETE ALL
is used.

I36-------------------------------- ~--~--~------------~----------~--~--~/..

STORAGE REQUESTWhen a user makes a request to run a BRUIN job he is initiallyallocat~d
a f~xed amount of core.
If more space than has been
allocated is rieeded at some point in a job, the interpreter will senda message"NEED MORE SPACE"The user may free part of the fixed space allocated to him by issuing
a form of the delete command.
If this is not feasible he may request
more space with the ALLOCATE command.

ALLOCATE <number of.blocks(1 to 9»

ALLOCATE 3
ALLOCATE 3 requests 3 blocks of storage, each of which will hold about
120 values.
If there is insufficient core to fulfill this request,
BRUIN will issue the messageo/"LAST NNOT ALLOCATED"For example, if BRUIN were unable to allocate one of the three~equested, the messag. would be

blOCKS"LAST 1 NOT ALLOCATED"The user may continue with the 2 blocks allocated.
If BRUIN wereunable·fo allocate any of the 3 blocks the. message issued would be"LAST 3·NOT ALLOCATED"The user should request space at a later time.
ALLOCATE may be used in the direct or indirect mode.

,

(\

37

0

FilE MAINTENANCE

SAVE Statement
The SAVE statement enables the user to save BRUIN programs and/or
values as a file which can be loaded into core at a later time.
The list of Items to be saved may contain:
1.
2.
3.
4.
S.

names of variables,
the keywords All PARTS,
the keywQrds All VALUES,
the keyword All,the keyword PART followed by a part number.

The filename is a name pf from one to eight alphabetic or numericcharacters, the first o~ which is alphabetic. If the alphabetic
characters in the filename are not upper case, BRUIN makes themupper case. This change in name prevents a user from creating files
which cannot be accessed or manipulated by CMS commands.
SAVE as <filename><list of items

s~parat~dby commas>

Example 28:
V (1) = 0

FOR I = 1 BY 1 WHilE 1(10: SET A(I)V 0) + .1= EXP (V(I) ), V (I + 1) =SAVE AS EXPTBl All VALUESIn example 28, the SAVE command causes the variable names and valuesof A (1) through A (9)0 V (1) through V (10) and the final value of
1 to be saved 1" a file called EXPTBl BRUIN.
In order to use thefile at a later time$ you must use the same filename in a lOAD
statement.
lOAD EXPTBL
The SAVE command will replace with the new file if a previously'saved'
file exists with the same name.
SAVE is valid in both the direct and indirect mode.
All files created by BRUIN have a filetYr>~ of "8RUIN".

38

LOAD Statement
LOAD <filename)
The LOAD command causes a file to be ]oa~ed into thp users
core area. If the user has defined parts or variables before
issuing the LOAD command, the parts and variables will be mergedwith the file being loaded. Merging is done in the following
manner:1.

If a part or step defined in core has the same number
as a part or step in the file, that part or step incore will be replaced by the part or step in the file;otherwise both parts and steps will be retained in core.

2.

If a variable defined in core has the same name as avariable defined in a file, the value of the variablein core will be replaced by the value of the variablefrom the f i 1e. ,.

Example 29:

x (1) = .1

FOR 1=1 BY 1 WHILE I <10: SET A{ I )=-SI N (X(I», X(I+1)=X(I )+.4
LOAD EXPTBL

Assume that EXPTBl refers to the file in Example 28. Due to thenature of the LOAD merge, A{ 1) through A( 9) in core wi 11 be re­placed by ACl) through A(9) from the data set EXPTBl. In addition,
the variables V(I) through V(10), XCI) through XCIO) and I will bedefined in core.
LOAD is valid in the direct and indirect mode.

39

. OTHER FEATURES

Various keyword operands such as ALL, ALL PARTS, ALL VALUES, STEP andPART are valid in the DELETE statement, simple PUT statement and SAVE
statement.
In addition to the above operands there are three operands
which are acceptable in either the PUT statements or as operands in
expressions.
They are THE SIZE, THE TIME, and THE DATE.
THE SIZE is a floating point number whichis the number of free elements left inusers c6re area.
It is approximately the
number of new values that users core area
can still hold.
THE TIME is a floating point number
which gives the tim~ since midnightin hundredths of a second.
THE DATE is a character string valueof the form 11000.
II is thetens and units digit of the year and
ODD is number of the day with January 1-as day 1.
~~~!El~~The statement

PUT THE TIME, THE DATE
produces two lines of output as follows:
THE TIME= O.5391414E+07
THE DATE="68220"

40

Comment Statements
A statement beginning with a C followed by one or more blanks
is accepted by BRUIN as a user ~omment line. To place such acomment in a part, write the part-step number followed by a blankfollowed by the letter C. Comment statements can be used anywherein the program. (See samp1e program, Appendix A).

Stopping Program Loops
The SPACE key in addi"tion to producing blanks serves another
Important function an BRUIN. If a user program appears to BRUIN
to be doing too much computing without writing or reading, BRUIN
will stop computing and interrogate you simply with a question
mark:

"

?

If the user wishes to'continue at the point where BRUIN stopped
the pro~ram, he must enter at least one blank (press the space
bar at least once) and then press carriage return. If the user
does not wish to continue at the point where BRUIN stopped theprogram, he may type any command. SRU 11~ VIIi 11 process that command.

.

41

.

MATRII STATEMENTS
In order to treat doubly subscripted variables in a notation simiLar
to a mathematical matrix notation~-a set of matrix statements has been
included in the BaUIN language. The matrix statements begin with the
keyword MAT and may be used in either the direct or indirect mode.
An mxn dimensional
BRUIN matrix A is a subscripted variable A(M,N)
which is defined for all combinations of the first subscript vary1n~
frorn
1 to M and the second subscript from 1 to N. A column vector
which is the result of a
MAT instruction has an explicit second
dimension of 1; a row vector has an explicit first dimension of 1. A
matrix or scalar which appears in a MAT instruction ma~ appear in non
MAT instructions as a doubly subscripted variable or in the case or
the scalar as a simple variable.
The interpreter makes no attempt tokeep the dimensions of a matrix fixed to the original dimension~.
Therefore a matrix which was input with row size 3, column size 2 mayas the resultant matrix bf an arithmetic operation have a different
row and column size.

There are two matrix input statements comparable to the ordinary BrU1U
input statements:
MAT GET <matrix name>( <row size> , <column size> ) *or
MAT GET LIST <matrix name>( <row size> , <column ,size> ) **(The keyword DEMAND mdY be used in place of GET)The expr.ession for row size and column size must be an arithmet1c
expression or arithmetic ~onstant greater than or equal to 1.
If toe~xpression is not an integer, it is truncated to the nearest
integer.
The !AT GET statement prompts the user for all elements -of the matr~x.
Let m be the row size and n be the column size of matrix a; then tne
MAT GET statement is equivalent to the non matrix saUIN statement: .
FOR i=l TO Ill:

FOR j=1 TO n:

GET a(i,j»

The MAT GET list statement behaves as its non-mat~ix counterpart 1nthat the input may be in the form of a list of elements separated OJ
commas ..

42

:I
, I

'I

; I

The elements of the matrix must be listed row-major
the value for a must be listed in the order

order;~S,thata (1, 1) , a (1 , 2) , ••• a (1, n) , a (2 , 1) , ••• a (m ,n)In both forms of the MAT GET statements the matrix, if previou~~ydefined, must specify a subscripted variable.
The subscriptedvar~­able will be redefined as a matrix where the dimension of the matrix
will be changed to the row size and column size specified.

MAT GET a(2,2)
The interpreter vill prompt witha(1,1)=>The user then types the value he wishes
element.
Then the interpreter types

to

enter

for

this

mat~~xa (1,2) =>The user responds again
with a value.
Similarly, the interpretcl
prompts for a(2,1) and a(2,2).
Just as in a non
MAT statement,
tbe
user response may be an arithmetic expression involving a previou~ly
defined variable. For example, the response for a (1,2)
could h3ve
bee n a (1 , 1 ) * * 2.

!g.mEle_1LL

Assume that matrix B= 1112 13
21 22 23
To input this in a list for~ the command isfiAT GET LIST B(2,3)
The interpreter responds with a >.

The user may then input

43

I
-)

~Ar

PUT

<matrix name> ( <row size> , <column size> ) •or

MAr PUT

LIST <matrix name) «row size> , <column size> ) •*(the keyword TYPE may be used in place of PUT)
The

expressionsforrow size and column size, give the dimension ot
This need not be the full dimensions of toe

thp matrix to be printed.

matJ:ix.
Let
PUT

a be a matrix with row size m and column size n.
1S

The

simple

~,r

along

with

~ts

equivalent to the BRUEN statement:
FO R i = 1 TO m; Fa R j = 1 TO n:

One· elementofidentification ..

pe~

B

line

will

PUT B (i, j)bep~intedThe MAT PUT LIST closely resembles its PUT LIST counterpart in tUdL
the output will be in columns with a maximum of 5 colu~ns per line.
I: o.. . e v~r, on1 y one matrix r ow is wr i t ten per line.
Thus, a ] x 3 ma tcJ..x
is written as 3 lines with 3 entries per line. If a matrix has rnu..:eth~n 5 columns the remaining elements ot therow are printed on dfollo .... inq line or lines, indentl::!li to the second column.

t!1.!!!Ed&_l£l_following statement:

To Olltput the matrix of example 31, execute theMAT PU T B ( 2, 3)

ThA

interpreter
B(1,1)=
8(1,2)=

re~ponds

with

11.0
12.0

B(1,3)=
13 .. 08(2,1)=21.0b(2,2)=
B(2,3)=

22.0
23.0

44

f\
"

.§ll.l!El~-D....:

MAT PUT LIST B(2,3)
The output will be
11.0
21.0

12.0
22.0

13.0
23.0

It is permissable to speci~y a smaller row size, j, or column size, K,in either MAT PUT statement than is defined forthe matrix.
BRUIN
WI illsi mply ou tput the upper right hand jxk partition of the ma trJ.x.
Assuming the matrix B of example 34, the statement
MA T PU T L.I S T B (1 , 2)will produce the line
11.0

12 •. 0A BR ur Nma tr i x expression consists of at
most 2!l~ operation.
rne
operation may be addition,
subtraction Or multiplication of two
matrices, multiplication of a matrix and a scalar, multipli~ation ot amatrix and a vector (singly subscribed variable), or the evaluation ot
special BRUIN matrix functions.
In some cases the dimensions of tn~
matrix operands are required to fulfill certain constraints sucn as J.~
requiredin conventional
matrix algebra.
In the case of the binaryo~erations the two matrix operands are examin~dto insure that tae
operation 1S conformable.
In some of the matrix functions such asdeterminant evaluation the matrix must be squa,ce.
Table 5 describes in detail the permissable matcix expressions:
6 describes the available SqOIN matrix functions.

Tanle

45

_ - . . n_ _ _,

r--­

!.,.

.. IJ
I ~!~~§si2a
I
I
I

,

Q!!!,!ni!io!l!

l!

matrix add

mxn

mxn

A-B

matrix subtract

mx:n

mxn

A·B

matrix multiply

mxn

nxk

A*s

multiplication

I
I
I
I
I
I
I
I
I
I

s·A

J
I

V·A

of a

mxn
,

scalar an.d ma tril{

A·V
I
I Function (A)J
I
I
I~!!2!21!_2!

A+B

I
I

(\

Qimensi2!L2!

A=B

I
I
Qi!!~!!2!Q!!_2t IJI!!~2g!1
I
mxn
I
J
mxn
I
I
mxk
I
I
I
J
mxn
J
I

mxn

1xn

nxm

nx1

J
I
I
I
I

mxn

I
I
I
I

assignment

mxn

)

I

I A and B are Bruin matrices; s is a constan t or simple variable;I

IV is a singly subscripted variable of dimension
I-'----­

Tabl'e 5.

~atrix

~

.

I

..

I

I
I

_________________ J

Expression

"

46

,

-------------------------------1

r------------------------

I.. 1I Fu~tio!l llgy!lU.
OET (·A,

determinant

nxn matrix A

I
I~!!~B§iQn_of_~2Y!~

Result(1)>

Jsimple scalarI

IN V (A)nxn matrix A

inverse of A

nxn

J
J

TRA (A)nxn matrix A

trace of A

simple scalarI•

TRS(A)

nxm matrix A

transpose of A

ION (5'

J
~xn

I
J

positive constantidentify

pxp

or variablematrixwhere p is the intege~ •

a

I

J

part of s
A is a Druin matrix; s is a constant or simple variable.
L_______________________

Table 6.

~__________ __ _~.~=_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _Matrix Functions

47

J

...

MAT SET <variable
expression),ete.

nallle>=<lIIatrixexpression>, <variable name>=<ma tI:1.Jt

The MAT assignment statement assigns the value of the matrix expre~­sion on the right hand side of the equal symbol to the variable on tae
left.
Not only does the matrix expression give the variable a value
but defines its type (e.g. simple scalar, matrix). If the· variaolaon the left h~s already been defined as an arithmetic subseripte~
variable, it can be redefined as a matrix. No attempt is made in tu'r
instruction to keep the dimension of a matrix fixed. Example 37 .1.~
given as an i11ust ra tion of changing dimension· sizes. The keyword SEl
is optional.

~~trix,!~a~E!~-1~
Assume that matrix S is a 3x2 matrix, G is a 2x2
and R is a 2x2 matrix. The Qbject is to compute GR-1S'.

I·

,
!

MAT SET B=TRS(B),RI=INV(R),B=RI*S
MAT B=G*S·1i

In example 37, according to the rule of m~trix expressions, only one
matrix operation per assignment is made~ The first statement is amultiple SET statement with the assignm~nts being performed from left
to right.
First the transpose of B is·stored into B. The dilllens1.onof B is now 2x3. Secondly, the inverse of R is stored into RI and the
product of HI ~nd S transpose is computed.
Pinally, RI*S is
premultiplied by G'and the result stored in B.

"

\

II

i

48

.• ji

SUMMARY

For a summary of the BRUIN instruction set, see Appendix A,part 1.
A complete sample program as typed on the 2741 console appears
as part 2 of Appendix A.
Anycomments about the organization or content of thh> flliWi.Jal
th~ language will be appreciatedr

or improvements. to49

APPENDIX A_...- - - - - - - - - - ­1.

Table of Instructions

ALLOCATE

direct/indirect

CANCEL

direct·DELETE

direct/indirect

GET

indirect(DEftAND)'CALL

direct/indirect

DONE

indirect

FOR· (DO,direct/indirectGO

directIF

direct/indirectLINE

direct/indirect

LOAD

direct/ind irect

ft1 T GET

direct/indirect

I'IAT PUT

direct/indirect

rn T SET

direct/indirect

SAVE

direct/indirect

SET

direct/indirect

STOP

indirectTO

indirect

PUT(TYPE)

ditect/ind irect50

> 1. 0 C sample program to solve giJadra tic eq ua.tions>1.1 put "Program to Solve Quadratic Equations">1.2 put"
a*x*x+b*x+c=O">1.3 for i=l to 3: line
> 1.4 put tfEnter· Coefficients"">1.5 get a,b,c>1.6 set discrim=b*b-4*a*c>1.7 if discrim(O, then call part 2; else call part 3>1.8 line>1.9 put "Enter 0 to terminate, 1 to continue">1.91 get aDS.
>1.92 if ans=1,then to step 1,.3; else if ans=O, done; to step 1.9>2.1 put."roots are complex">3.1 set rootl=(-b+sqrt(discrim»/(2*a)>3.2 set root2=(-b~sqrt(discrim»/(2*a,>3. 3 t YPe " 1t, n " , roo t 1 ; r 0'0 t 2 ­>CALL part 1.
Program to solve Quadratic Equations
a*x*x+b*x+c=O

Enter.Coefficients
a=>l.
b=>10.
c=>-40.
r 00 t 1-= 3 • 0 62 i 5 5root 2=-1 J. 06225
Enter 0 to terminate, 1 to contans=>l.

•Enter Coefficients
a=>l.
b=>O.
c=>1.
Roots are complex
Enter 0 to terminate@, f \ ans=>O.

1 to continue, / EXECUTION HALTED AT END OF PART 1.

51

i

j

I
1
i

r

I
I

lPPENDIX B

blank (space bar aD console)
equalplus sign
minus sign
asterisk
slash_left parenthesis
right parentbesis
commapoint or period
semicolon
colon"NOT" symbol"AND" symbol

vertical- ba-r
"greater than"v'less than t •double quotatioi'i
apostrophe
dollar sign
cent sign
excla rna tion point
percent signunderscorequestion-markpound signa t sign

*

/

(
)

......
&

I
)

<

"e

?

52

,,::.

0

. !

"

'

,
!

~.

b.-_l!yilt-In l'lathellati£a1 Funct~Q!!§!!1ue _!~s.!!!:!l ed!Y!l£SiQ!!
ABS

G,

,

~!IQ!.:.£Qndi t!Q!!

~!A.!!.E!~
Abs (x)Ix I

LN

log (x) base e

tOG2

log

x~O

Ln (3*zl

base 2x~O1092 (3*z+ 5)

LOG

log Ix) base 10

x~O

LOG (x)EIPe to the pover l:x>174.6131(x)

EXP (5. 1)

SQRT

square ,root of

SIN

sin (X) ,in radians

IXi~21.

x pi

sin (a*b)

COS

cos (x, • x in ra:d ians

IXI~21.

x pi

cos (3. 1/B)

SIND

sin td) • d in degrees

IxJ~218

x ,lBOsind (360/4)

COSO

cos (d) ,d in degrees

Jxl~218

x 180

COS D (36 O/B)

TAN

tan (x) ,x in radians

Ix!S2 te x pi

TAN(J.14/4)

TAND

tan (d) ,. d in degrees

ixl~211·TAND (a*b)

ATA N'

ac['ctan (x) in radians"=pi/2<ATAN(X) <pi/2

ATAN(z)

ATND

arctan (xl in degrees,-90<ATAN (x) <90

ATND(Z)

ERF

'"

x

x

x < 0

sqrt (3. 14/5)

x 180

"

.

ERF(.B,

2Air SEXF (-U Z ) du0

ERFC

, - ERFSINH

sin h (x)(xt

ERFC (2. *x)
x>114.67Jl

SINH (3.1*x)

S3

I

"­
\

COSH

cosh (x)TANHtanh (x)integer part of a number x
sign of x times largest integer ~IxiFPfractional part of a number

GAPIA

tiniformly distributed random
numbers between 0 and 1.

r

u --.-'EX P (-u) - du•atnh (x)ABS(x)SlIP

RAND -

IP(3.15679)

FP (x*z)x S 0

X~2-2S Z

RAND­

x>57.5744**FACT~!where

(X)

or

o

0.

COSH (x)TANH (z)inverse hyperbolic
tangent of x

ATNH

*

x> 174.6731

x!=x(x-1)(x-2) ... ~XS2,..Z52

GAMA(3*X)
FACT

(3)

or

j

x>57.5744

-I

I
1

I
I

*For the first entry, x should be an odd integer.
After the fi~~tentry x should be set - equal to the previous result of the RAND
function ••• x!

is computed using the relationship X!=GAMA~x.l)54