home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / BASIC / UBAS821.ZIP / UBHELP.XXX < prev    next >
Encoding:
Text File  |  1991-01-31  |  120.7 KB  |  4,343 lines

  1. ;
  2. ; * UBASIC for IBM-PC version 8.21
  3. ;    User's manual for UBHELP system
  4.  
  5.  
  6. UBASIC is a BASIC with ultra-fast multi-precision arithmetic.
  7. It runs on IBM PC/AT and compatibles with at least 512K of RAM.
  8.  
  9.  
  10. ~~RunningUB
  11. Running UBASIC
  12.  
  13. Insert the UBASIC distribution diskette, then type
  14.  
  15.     UBIBM<Enter>
  16.  
  17. on the DOS command line.  (<Enter> is the large key engraved
  18. "Enter" or "Return" or a bent arrow.)  If your machine's
  19. processor is 80386, type
  20.  
  21.     UBIBM32<Enter>
  22.  
  23. instead for better performance.  To run the example program
  24. "PI.UB" on the distribution diskette, type
  25.  
  26.     LOAD "PI"<Enter>
  27.     RUN<Enter>
  28.  
  29. The program will prompt you to enter how many places you want
  30. pi to be displayed (10-2500).  Type for example
  31.  
  32.     1000<Enter>
  33.  
  34. Wait a few seconds.  Your screen will display 3.14159...
  35. to 1000 decimal places.  Type
  36.  
  37.     LIST<Enter>
  38.  
  39. to examine the program.  Finally, type
  40.  
  41.     SYSTEM<Enter>
  42.  
  43. to exit to the DOS.
  44.  
  45.  
  46. ~~NUMBERS
  47. NUMBERS
  48.  
  49.   UBASIC supports integers, rational numbers, real numbers
  50. and complex numbers.
  51.  
  52. 1-1. Integers
  53.   UBASIC supports a wide range of integers from -65536^542 to
  54. 65536^542 which is a number in a little more than 2600 figures
  55. in decimal expression.
  56. Results out of this range create an overflow.
  57. Hexadecimal integers can be entered as  '0x..' (not '&h..').
  58.  
  59. 1-2. Rational numbers
  60.   UBASIC allows calculations with rational numbers, only the
  61. type of value is limited to integer / integer. Numerator and
  62. denominator are marked off by '//'.
  63.  
  64. Ex:    a=2//3
  65.     a=3:b=5:c=a//b
  66.  
  67.   Expression may differ from the input, as rational numbers
  68. are memorized as an irreducible fraction.
  69.  
  70.   Since // has the same precedence as *, /, \, or @, the
  71. order of operations may not be the same as you expected.
  72. Use parentheses to avoid this.
  73.  
  74. Ex:    2\6//3 = 0
  75.     2\(6//3) = 1
  76.  
  77.   When a rational number is mixed with real or complex
  78. numbers, it is automatically converted to a real.  This also
  79. happens when it is the real part or the imaginary part of a
  80. complex number.
  81.   Rational arguments are automatically converted to reals in
  82. functions like SIN, EXP, etc.
  83.  
  84. 1-3. Real numbers
  85.   Real numbers are expressed as fixed point numbers.  The
  86. maximum amount of memory occupied by the integer part and the
  87. decimal part is fixed at 542 words.  The size of the decimal
  88. part is specified by the POINT statement.  The default value
  89. is 4, that is, 4 words are assigned to the decimal part and
  90. 538 words to the integer part.  The smallest positive real
  91. number is 65536^(-4), since 1 word is 65536.
  92.  
  93. 1-4. Complex numbers
  94.   UBASIC allows calculations with complex numbers as well as
  95. those with real numbers.  The maximum allowed size of a
  96. complex number is 541 words including both the real part and
  97. the imaginary part.  As the real part is usually about as
  98. large as the imaginary part, the maximum size of each part is
  99. 270 words, that is, 1300 digits in decimal notation.
  100.   Read the following examples carefully, since the expression
  101. of complex numbers in UBASIC is a little peculiar.
  102.  
  103.   The imaginary unit is represented by "#i".  Complex numbers
  104. are expressed as follows:-
  105.  
  106. numbers        1+#i, 1.23+2.34#i, 12345+23456.789#i
  107.             * is not necessary.
  108.         1.23+#i*2.34, 12345+#i*23456.789
  109.             * is necessary.
  110. variables, etc.    A+B*#i, Abc+#i*sin(x)
  111.             * is necessary.
  112.  
  113. Notes:
  114.   1/2#i is interpreted as 1/(2#i).  So the result is -0.5#i.
  115.   1/2*#i is interpreted as (1/2)*#i.  So the result is 0.5#i.
  116.   Similarly, 2^3#i is 2^(3#i) while 2^3*#i is (2^3)*#i.
  117.  
  118.   When complex numbers are used, set the WORD value to more
  119. than 4 * POINT(for example, if POINT = 10, then WORD must be
  120. more than 40).  Otherwise, overflow can easily occur for
  121. reasons of internal structure when a complex number is
  122. assigned to a long variable.
  123.  
  124.   There are 3 functions that return absolute values: ABS,
  125. ABSMAX, ABSADD.
  126.  
  127.     abs(z)    = sqrt(Re(z)^2+Im(z)^2)
  128.     absmax(z) = max{abs(Re(z)),abs(Im(z))}
  129.     absadd(z) = abs(Re(z))+abs(Im(z))
  130.  
  131.   ABS returns the ordinary absolute value, but it takes more
  132. time.  ABSMAX and ABSADD are recommended to check errors quickly.
  133.  
  134.   ARG(x) returns the argument of x.  The value returned is A,
  135. where -pi < A <= pi.
  136.  
  137.   UBASIC has the complex number versions of the following functions:
  138. EXP, LOG, SIN, COS, TAN, ATAN, SINH, COSH, SQRT, BESSELI, BESSELJ.
  139.  
  140.  
  141. << Notes for mixed types expressions >>
  142.   Different types of numbers can be used together in one
  143. expression.  Result type may vary with the order of the
  144. operations.
  145.  
  146. Ex:    1.0+1-1.0 = 1.0 (real)
  147.     1.0-1.0+1 = 1    (integer)
  148.  
  149.   This is because when a result of the calculation of reals
  150. and/or complex numbers is 0, it is converted to an integer.
  151.  
  152.   There are round-off errors caused by conversions from
  153. internal binary expression to decimal output.  These errors
  154. are typically seen in the expressions of '0'.  If the output
  155. is '0' it really is '0', while '0.0' and '-0.0' are nonzero
  156. values that are too small to be expressed.  Note that this
  157. occurs only for 0.  '1.0' may be equal to '1' or a little
  158. larger or smaller.  To know which, subtract 1 from it.  As a
  159. result of calculation, there is no essential difference
  160. between '1'(integer) and exact '1.0' (real), though the size
  161. of the internal memory required is different.  Naturally, '1'
  162. (integer) needs smaller memory and can be calculated faster.
  163.  
  164.  
  165. ~~VARIABLES
  166. VARIABLES
  167.  
  168.   UBASIC has three types of variables:-
  169.  
  170. 1) Short variables, such as A%, Foo_bah% (and arrays)
  171.   A short variable holds a one-word (16-bit) integer
  172. (-32767, ..., 32767).  Rational numbers, complex numbers, and
  173. strings cannot be assigned to a short variable.
  174.  
  175. 2) Long variables,  such as  A, Foo_bah (and arrays)
  176.   The size of long variables is specified by WORD statement.
  177.   It cannot be specified individually.
  178.  
  179. 3) EXTRA variables, such as  A#, Foo_bah# (and arrays)
  180.   Variables whose size is fixed at 542 words.
  181.  
  182.   A variable name is a letter, possibly followed by at most
  183. 15 letters, digits, and underscores(_).  Short and EXTRA
  184. variable names have a final "%" and "#" character, respectively.
  185. A variable name may not coincide with UBASIC statements/functions
  186. and it may not start with "fn" (which is the mark of user defined
  187. functions).
  188.   The first character is automatically converted to uppercase
  189. while the rest is left as it is.  Uppercase and lowercase
  190. letters are not distinguished.
  191.  
  192. Ex:    A, BC, MaximumElement, Maxscore%, Minscore(10)
  193.     Abcdefghi and ABCDEFGHIJ are regarded as the same.
  194.     NextOne, Step1, etc. are distinguished from  the
  195.     statements NEXT, STEP, etc.
  196.  
  197.   A simple variable and an array with the same name are
  198. distinguished.
  199.  
  200.   Arrays of up to three dimensions can be declared.  Array
  201. indices may be as large as 65534.  So the size of an array of
  202. short variables of one dimension is up to 128 KB.  The size of
  203. an array of two dimensions can be as large as the available
  204. memory.
  205.  
  206.   There is no need of EXTRA variables if the length of long
  207. variables is specified as 542 words.  EXTRA variables are used
  208. when a few large numbers occur among many relatively short long
  209. variables.
  210.  
  211.   Long variables and EXTRA variables can be assigned
  212. integers, rationals, reals, complex numbers, character strings
  213. and polynomials.
  214.   See appendix A for the internal expressions of numbers,
  215. strings and polynomials.
  216.  
  217.   An overflow occurs when the length of variable exceeds 542
  218. words in the process of calculation, or when a result
  219. exceeding the limit of the variable is assigned.
  220. In particular, in multiplication and division of real numbers,
  221. the intermediate results very often exceed 542 words.  This is
  222. because UBASIC executes the operation using all the
  223. significant figures and discards the lesssignificant ones
  224. afterwards.
  225.  
  226.   No more than 180 variables and arrays may be used
  227. simultaneously.
  228.  
  229.  
  230. ~~OPERATIONS
  231. OPERATIONS
  232.  
  233. 3-1. Operators
  234.  
  235.   Comparisons            =, >, <, <>, <=, >=
  236.   Addition, Subtraction        +, -
  237.   Multiplication, Division    *, /
  238.   Integer Division        \
  239.   Rational Division        //
  240.   Remainder            @
  241.   Power                ^
  242.  
  243. 3-2. Value of logical expression
  244.   In UBASIC, the value of logical expression is 1 when it is
  245. TRUE 0 when it is FALSE.  In conditional expressions, a
  246. nonzero value is regarded as TRUE.
  247. So:-
  248.     if A<>0 then ...
  249.         is equivalent to:
  250.     if A then ...
  251.  
  252.   This is valid also when A contains a real number.
  253. However, this short form is not recommended.
  254.  
  255. 3-3. Division of real numbers (/) and integers (\)
  256.  
  257.   Usual division is calculated up to the decimal place
  258. specified by POINT.  The digits beyond it are omitted.
  259. Integer division returns an integer quotient when both of
  260. the arguments are integers.  A real or complex argument
  261. creates an error. 
  262.   Remainder of integer division is contained by the system
  263. variable RES while remainder of real division is undefined.
  264.  
  265. Ex:    12345/100 is 123.45 (actually 123.449999...)
  266.     12345\100 is 123. Remainder is 45.
  267.  
  268.   If the remainder is 0, the result varies with "/" and "\".
  269.  
  270. Ex:    123/3 is 41.0, while 123\3 is 41.
  271.  
  272.   In the process of integer division A\B, the quotient is
  273. determined in such a way that the remainder is non-negative
  274. and numerically less than ABS(B).
  275.   This seems natural in division by positive numbers, but
  276. rather strange if a negative divisor is involved.  For
  277. instance, (-1)/100 is -1 and the remainder is 99.  So -1
  278. never becomes 0 by repeated integer division.  Take care when
  279. you check the conclusion of a loop.
  280.  
  281. 3-4. Division of rational numbers (//)
  282.  
  283.   Division of rationals returns a rational when both of the
  284. arguments are rationals.  Otherwise, it is the same as real
  285. division (/).
  286.  
  287. Ex:    (2//3)//3 is 2//9
  288.     (2//3)/3 is 0.2222...
  289.     0.5//2 is 0.25
  290.  
  291. 3-5. Calclulation of a remainder
  292.  
  293.   @ is the remainder of integer division.
  294.  
  295.   It is different from MOD in some languages since it is
  296. determined as above (Section 3-3.) if a negative number is
  297. involved.
  298.  
  299. The remainder of
  300.     integer \ integer
  301.     complex number with integer coefficient \ integer
  302.     polynomial \ polynomial
  303. just calculated is held by the system variable RES so that you
  304. do not need to use @.  @ is used when only the remainder is
  305. needed and the quotient is not needed.
  306.   Note that the value of RES must be used just after the
  307. calculation, as it is destroyed by other calculations.
  308.  
  309. 3-6. Power X^Y.
  310.  
  311.   Powers of integers, reals, complex numbers, rationals, and
  312. polynomials.
  313.   If Y is positive, the result is X to the Y .
  314.   The return value is exact if X is an integer, while it is
  315. an approximate value if X is a real.
  316.   If Y is 0, the result is 1 as a polynomial of degree 0 when
  317.  X is a polynomial, otherwise 1 as an integer regardless of
  318. the type of X.  0^0 is 1.
  319.   If Y is not zero and X is zero, the result is 0.
  320.   See appendix B for the algorithm in the case where Y is a
  321. real or a complex number.
  322.   X^Y^Z is usually interpleted as X^(Y^Z), but it is (X^Y)^Z
  323. in UBASIC.
  324.  
  325. 3-7. Combined operators
  326.  
  327.   Combined operators are borrowed from the C language.
  328.  
  329.     A+=B is equivalent to A=A+B.
  330.  
  331. This can save you the trouble of typing long variable names.
  332.  Use of the combined operator can also speed up a program,
  333. since the calculation of the internal address of an array is
  334. executed only once.  The right hand side is evaluated before
  335. the combined operation:-
  336.  
  337.     A*=B+C means A=A*(B+C), not A=A*B+C.
  338.  
  339.  
  340. ~~STRINGS
  341. CHARACTER STRINGS
  342.  
  343.   Like ordinary BASIC, UBASIC allows character strings.
  344. However, UBASIC has no string variables.  Use long variables
  345. or extra variables to assign character strings.  Since one
  346. character occupies 1 byte, a variable can contain twice as
  347. many characters as the WORD value: for example, 20 characters
  348. when the WORD value is 10.
  349.   Character strings are compared by ASCII code in
  350. lexicographic order.
  351.  
  352.  
  353. ~~POLYNOMIAL
  354. POLYNOMIALS
  355.  
  356.   UBASIC allows polynomials in one variable.
  357. There are two types of polynomials: polynomials with
  358. coefficients in integers modulo a prime (<= 65536) (we call
  359. them "modulo polynomials"), and normal polynomials.  In the
  360. former type we can handle polynomials up to about the 1000th
  361. degree, but in the latter type we can handle only polynomials
  362. of relatively lower degree (e.g. up to (1+X)^95).
  363.  
  364. 5-1. Entering of polynomials
  365.  
  366.   The variable of a polynomial is represented by "_X".
  367.  
  368. Ex:    A=1+2*_X+3*_X^2
  369.  
  370. However, the result is displayed with "X".
  371.  
  372. Ex:    A=1+2*_X+3*_X^2:print A
  373.         displays "3*X^2 + 2*X + 1".
  374.  
  375.   You may also use the function POLY to specify the coeffi-
  376. cients in order starting with the coefficient of degree 0.
  377.  
  378. Ex:    A=poly(1,2,3) is equivalent to the above example.
  379.  
  380.   To specify the coefficient of each degree, use COEFF.
  381.  
  382. Ex:    A=0:coeff(A,0)=1:coeff(A,1)=2:coeff(A,2)=3
  383.         is equivalent to the above examples.
  384.  
  385.   Note that the variables specified by COEFF have to contain
  386. a polynomial (or 0).
  387.   The value of the system variable MODULUS determines whether
  388. a polynomial is a modulo polynomial or a normal one.  If
  389. MODULUS is 0, it is a normal one and if MODULUS is a prime, it
  390. is a modulo polynomial.
  391.  
  392. 5-2. Calculation with polynomials
  393.  
  394.   The following caluculation are allowed with polynomials:-
  395.     Addition    +
  396.     Subtraction    -
  397.     Multiplication  *
  398.     Division    \
  399.     Remainder    @
  400.     Power        ^
  401.     Differential    diff
  402.     Value ( A(Y) )  val(A,Y)
  403. Note that the division is "\".
  404.  
  405.   The system variable RES contains the remainder after the
  406. division of polynomials.
  407.   Calculations with a normal polynomial and a modulo
  408. polynomial are not allowed.  Calculations with modulo
  409. polynomials create an error if the value of MODULUS is not as
  410. it was when the polynomials were entered.  In particular,
  411. calculations containing polynomials created under different
  412. values of MODULUS are not allowed.
  413.   VAL returns the value of the polynomial as evaluated for
  414. the given n.
  415.  
  416. Ex:    A=poly(1,1):print val(A,2)
  417.         displays "3".  (when MODULUS=0)
  418.  
  419.   A number and a polynomial of degree 0 are distinguished in
  420. the following cases:
  421.  
  422. polynomial / number
  423.             Each coefficient / number.
  424. polynomial / polynomial of degree 0
  425.             Error.
  426. polynomial \ number
  427.             Each coefficient \ number.
  428.             The value of RES is not valid.
  429. polynomial \ polynomial
  430.             of degree 0
  431.             Division of polynomials.
  432. polynomial @ number
  433.             Each coefficient @ number.
  434.             The value of RES is not valid.
  435. polynomial @ polynomial of degree 0
  436.             Remainder of division of polynomials.
  437. polynomial // number
  438.             Each coefficient // number.
  439. polynomial // polynomial of degree 0
  440.             Error.
  441.  
  442. Ex:    When A=_X^2+2*_X+3,
  443.     A\2  is  _X+1 and the value of RES is not valid.
  444.     A\poly(2) is (1//2)*_X^2+_X+(3//2) and the remainder is 0.
  445.  
  446. modulo polynomial / number
  447.             Each coefficient * inverse of number.
  448. modulo polynomial / polynomial of degree 0
  449.             Error.
  450. modulo polynomial \ number
  451.             Error.
  452. modulo polynomial \ polynomial of degree 0
  453.             Division of modulo polynomials.
  454. modulo polynomial @ number
  455.             Error.
  456. modulo polynomial @ polynomial of degree 0
  457.             Remainder of division of polynomials.
  458. modulo polynomial // number
  459.             Same as modulo polynomial / number.
  460. modulo polynomial // polynomial of degree 0
  461.             Error.
  462.  
  463. ~~PACKETS
  464. PACKETS
  465.  
  466.   Sometimes you may prefer to handle multiple data as one.
  467. UBASIC allows assigning multiple values to one variable.  We
  468. call this "a packet" (this is usually called "a list" , but
  469. UBASIC's "list" is too poor to call "a list").
  470.   It is recommended to assign a packet to an EXTRA variable
  471. so that the limit of its length is not modified by the WORD
  472. statement.  A long variable can be used if the WORD value is
  473. correctly set.
  474.  
  475.     A#=pack(23,"abc",1+3#i)
  476.       assigns an integer 23, a string "abc" and a complex
  477.       number 1+3#i to A#.
  478.  
  479.   To know the number of members PACKed in a packet, use LEN.
  480.  
  481.     When A#=pack(23,"abc",1+3#i), len(A#) is 3.
  482.  
  483.   To get a PACKed member, use MEMBER.
  484.  
  485.     When A#=pack(23,"abc",1+3#i), member(A#,1) is 23.
  486.  
  487.   Use MEMBER also to replace specified data.
  488.  
  489.     member(A#,3)="abc"
  490.       replaces the third member 1+3#i with a character
  491.       string "abc".
  492.  
  493.   A packet can be edited using LEFT, RIGHT, MID as well as a
  494. character string.  Consider 1 member as 1 character.  Note
  495. that the return value in this case is a packet.
  496.  
  497. Ex:    left(pack(2,4,6),1)  is  pack(2),
  498.     not 2 itself.  To get 2 itself, use MEMBER mentioned above.
  499.  
  500.   mid( ,2,*) is equivalent to "cdr" in LISP.
  501.   To add data to a packet, use "+".
  502.  
  503.     A#=A#+1000
  504.     or
  505.     A#+=1000
  506.       adds a new member 1000 to A#.  "+" is used also to
  507.       join 2 packets.
  508.  
  509.   The word length required by a packet is the sum of the word
  510. length of all the member + 1.
  511.  
  512.   In the case of A#=pack(23,"abc",1+3#i),
  513.  
  514. Integer 23:        data 1 word + attribute 1 word
  515. String "abc":        data 1 word + attribute 1 word
  516. Real part of complex number 1+3#i:
  517.             data 1 word + attribute 1 word
  518. Imaginary part of complex number 1+3#i:
  519.             data 1 word + attribute 1 word
  520. Complex number 1+3#i:    attribute 1 word
  521. Number of members (3 in this case):
  522.             1 word
  523. Total:            11 words
  524.  
  525.   (Actually, "attribute 1 word" of the packet itself is
  526. required.)
  527.  
  528.   So if a WORD value larger than 11 is specified, the packet
  529.  can be assigned to a long variable.
  530.  
  531.  
  532. ~~LABELS
  533. LABELS
  534.  
  535.   "Label" is a name given to the destination of GOTO and
  536. GOSUB.  It is recommended that labels be used instead of line
  537. numbers whenever convenient.
  538.  
  539.   The following two examples are equivalent:
  540. ....            ....
  541. 110 gosub 1000        110 gosub *ABCD
  542. ....            ....
  543. 1000 ....        1000 *ABCD:....
  544. ....            ....
  545. 1100 return        1100 return
  546.  
  547.   A label is a * followed by no more than 23 characters
  548. (letters, digits, ".", "_" and "?").  Upper and lower case are
  549. not distinguished.
  550.   Labels (such as *ABCD on line 1000 in the example above)
  551. must head their lines.  At most 100 labels may be used; the
  552. use of many labels slows the execution down.
  553.  
  554.   The RUN statement forms the list of labels.  So if the
  555. program is executed by GOTO, the results are unpredictable.
  556.  
  557.  
  558. ~~KEYS
  559.  
  560. 1. The function of special keys
  561.  
  562. DEL        Deletes the character under the cursor.
  563. BS        Deletes the character to the left of the
  564.         cursor.
  565. INS        Toggles insert mode on/off.  An underline
  566.         cursor is displayed in insert mode.
  567.  
  568. HOME        Moves the cursor to the home position
  569. CLR        Clears the screen
  570.  
  571. ESC        Cancels the listing of file choices in
  572.         commands such as LOAD, RUN, etc.
  573.  
  574. Arrow keys    Move cursor
  575.  
  576. 2. Editing Control Keys
  577.  
  578.   "Control-X" means to hit "X" while pressing the control key
  579.  at the left end of the keyboard.
  580.  
  581. Control-E:  Cursor up
  582. Control-X:  Cursor down
  583. Control-S:  Cursor left
  584. Control-D:  Cursor right
  585.  
  586. Control-Z:  Scroll up
  587. Control-W:  Scroll down
  588.  
  589. Control-R:  Page down
  590. Control-C:  Page up
  591.  
  592. Control-A:  Cursor leftmost
  593. Control-F:  Cursor rightmost
  594. Control-Q:  Cursor home(=HOME)
  595.  
  596. Control-L:  Clear the screen(=CLR)
  597. Control-B:  Delete lines below cursor
  598. Control-T:  Delete left of cursor
  599. Control-Y:  Delete right of cursor
  600. Control-G:  Delete character at cursor (=DEL)
  601. Control-H:  Delete character left of cursor (=BS)
  602. Control-O:  Insert a line
  603.  
  604. Control-V:  Insert/Overwrite toggle(=INS)
  605.         Underline cursor is displayed in the insert mode.
  606.  
  607. Control-C:  Halt execution, LIST, VXREF, etc. 
  608.         (Control-BREAK is recommended)
  609. Control-S:  Halt/Restart display
  610.  
  611. Control-BREAK:
  612.   The execution cannot be halted by Control-C in the
  613. following cases:
  614.  
  615.   In the middle of calculation of built-in functions.
  616.  
  617.   When there is a loop such as FOR-NEXT and WHILE-WEND
  618. that has few statements and is repeated many times.
  619.  
  620.   In these cases, use Control-STOP to halt the execution
  621. forcibly.  Note that a program halted by Control-STOP cannot
  622. be CONTinued.
  623.  
  624. Control-N: In some versions of MS-DOS, this means "printer
  625. line feed" and in some cases, (especially when the printer is
  626. ON and off-line) the execution is halted and key inputs are
  627. not accepted.  To cancel this, turn off the printer or
  628. make it on-line.
  629.  
  630.  
  631. 3. Function Keys
  632.  
  633.   You may modify the settings of function keys using KEY.
  634.   Default settings are as follows:
  635.  
  636. f1    load "        f6    save "
  637. f2    dir "*.UB"    f7    xref
  638. f3    auto        f8    append "
  639. f4    list        f9    edit
  640. f5    run        f10    cont
  641.  
  642.  
  643. ~~SUBROUTINE
  644. SUBROUTINES AND FUNCTIONS
  645.  
  646.   The biggest defect of normal BASIC is the difficulty of
  647. making a program independent.  For example, if you are going
  648. to use a FOR-NEXT loop in a subroutine, you may find it
  649. difficult to choose the name of the loop variable.
  650. Because of this problem, it is almost impossible to make a
  651. useful program into a module.  UBASIC offers some ways to
  652. solve this problem.
  653.  
  654. Passing Arguments
  655.  
  656.   Arguments can be passed to subroutines.
  657.  
  658.      10    A=1:B=2:C=0
  659.      20    gosub *MAX(A,B,&C)
  660.      30    print C
  661.      40    end
  662.     100    *MAX(X,Y,&Z)
  663.      110      if X>=Y then Z=X else Z=Y
  664.     120    return
  665.  
  666.   At the beginning of the subroutine MAX, the values of
  667. variables A and B are passed to the different variables X and
  668. Y (call by value).  As X and Y are variables valid only in the
  669. subroutine MAX (local variables), changing of their values
  670. does not affect the main routine.  The variable C with "&" is
  671. regarded as the same as Z in the subroutine MAX (call by
  672. reference).  So if you change the value of Z in the subroutine
  673. MAX, the value of C also changes so that you can return the
  674. result to the main routine.  This condition is initialized by
  675. the RETURN in line 120.
  676.  
  677.   The format is different from those in QUICK BASIC and TURBO
  678. BASIC.
  679.  
  680. Limitations:
  681.     A simple short variable cannot be passed by reference.
  682.     That is, gosub *ABC(&A%) is not allowed.
  683.     A member of an array cannot be passed by reference.
  684.     That is, gosub *ABC(&A(1)) is not allowed.
  685.  
  686. User defined functions
  687.  
  688.   A function that extends to multiple lines can be defined.
  689.  
  690.      10    A=1:B=2
  691.      20    C=fnMAX(A,B)
  692.      30    print C
  693.      40    end
  694.     100    fnMAX(X,Y)
  695.     110      if X<Y then X=Y
  696.     120    return(X)
  697.  
  698.   As above, "fn" is required before the function name.  The
  699. return value of the function is placed between "()" after
  700.  "return".  The return value can be an expression.  In the
  701. above example, the function changes the value of X.  Note that
  702. this does not affect the main routine.
  703.  
  704.   You may call functions and subroutines LOADed into memory
  705. in direct mode without RUNning the program.  For example, if
  706. you LOAD the program "GENSHI" and type "? .genshi(13)", "2" is
  707. displayed ("?" and "." are abbreviations of "print" and "fn"
  708. respectively.)
  709.  
  710.   So if you collect frequently used subroutines/functions and
  711. make them into one program, you have only to LOAD it to use
  712. the subroutines/functions as you like in direct mode.  This
  713. will serve you as an electronic calculator.
  714.  
  715.   A user defined function itself can be passed to subroutine/
  716. function as an argument.  See the "Guide" or the sample program
  717. "Simpson" for an example.
  718.  
  719. Local Variables
  720.  
  721.   Local variables are variables valid only in a subroutine/
  722. function.
  723.  
  724.      10    for I=1 to 10
  725.      20      gosub *ABC(I)
  726.      30    next
  727.      40    end
  728.     100    *ABC(X)
  729.     110      local I
  730.     120      for I=1 to X
  731.     130        print X;
  732.     140      next
  733.     150      print
  734.     160    return
  735.  
  736.   I is declared as a local variable in line 110.  This I is
  737. distinguished from I in the main routine until RETURN.  The
  738. value is initialized to 0 by the LOCAL declaration.  The
  739. arguments of a subroutine/function mentioned above are also
  740. regarded as local variables.
  741.  
  742.   The beginning of a subroutine/function must be in the
  743. following format:
  744.  
  745.     Declaration of the subroutine/function.
  746.     Declarations of local variables beginning with LOCAL.
  747.     (Multiple lines are allowed.)
  748.     Declarations of local arrays beginning with DIM.
  749.     (Multiple lines are allowed.)
  750.  
  751.   The latter two may be placed in reverse order or
  752. alternately.  Other statements other than comments are not
  753. allowed in the middle of these declarations.
  754.  
  755. Limitations:
  756.     The maximum depth of recursive calls is up to 40.
  757.     Local labels are not available.  So when several
  758.     user defined functions are APPENDed, an error occurs
  759.     if these functions have the same label.
  760.  
  761.  
  762. ~~EMA-arrays
  763. EMA-array
  764.  
  765.   Extended memory for 386DX/SX-CPU machines are usable for
  766. optional arrays on UBIBM32.
  767.   On the other hand, disk files for 86/286-CPU machines are
  768. usable for optional arrays on UBIBM.
  769.  
  770.   Their names are ema(0;i,j), ema(1;i,j),..., ema(15;i,j) only.
  771. 0; can be omitted.
  772.  
  773. Limitation:
  774.     1 or 2 dimensional.
  775.     cannot be passed to subroutines as parameters.
  776.     cannot be declared as local variables.
  777.     cannot be preserved by freeze command.
  778.     cannot be erased.
  779.     cannot be handled by vlist, vxref, vchg.
  780.  
  781. WARNING :
  782.     For the 386DX/SX machines, it is very dagerous to use
  783.     Extended Memory Array(EMA) when you use the extended memory
  784.     for other use.  We only check through INT 15H and any other
  785.     specification is NOT supported.
  786.     If MS-DOS is running on the virtual 86 mode, the machine will
  787.     be reset as soon as you use this command.
  788.     We recommend you not to use any utility programs.
  789.     In particular RAM disks and/or disk caches.
  790.     EMA starts from 110000H to skip HighMemoryArea for the future
  791.     extension of MS-DOS.  But we have NOT checked whether EMA runs
  792.     well on the MS-DOS version 5.
  793.     Access to the extended memory is done through GS register.  You
  794.     must keep GS unchanged.
  795.  
  796.   The usage is somewhat complicated to avoid the misuse.
  797.  
  798. 1) Declare the start of use.
  799.   * 386DX/SX machines
  800.     useema
  801.   only possible on the direct mode.
  802.  
  803.   * 86/286 machines
  804.     useema "file name"
  805.   only possible on the direct mode.
  806.   This file must be made beforehand.  The quick way is to
  807.   execute:
  808.     open "file name" as file1(10000) word 100
  809.     close file1
  810.   Then this file can be used for EMA file.  For this example,
  811.   the file will be about 2Mbytes large.  Note the file made
  812.   in this way has automatically the extension name .UBD.  Do
  813.   not forget to add .UBD to the filename after useema.
  814.   Of course, you must not change the diskette including the
  815.   file for EMA.
  816.  
  817. 2) Decide the size of an element.
  818.   Default size is same as that of extra variables, namely
  819.   542 words.
  820.   To change the size do:
  821.     emaword 100
  822.   each element of EMA is 100 words long.
  823.   Also this is the only way to erase EMA-arrays.
  824. (* 86/286 machines: emaword 0  stops the use of EMA-arrays.)
  825.  
  826. 3) Decide the size of an array
  827.     dim ema(0;9,99)
  828.   2 dimensional, 1st indices are from 0 to 9, 2nd indices
  829.   are from 0 to 99.
  830.  
  831. Sample:
  832.      10    emaword 10
  833.      20    read N
  834.      30    dim ema(0;N-1,N-1)
  835.      40    dim ema(1;N-1,N-1)
  836.      50    gosub *ReadEma(0)
  837.      60    gosub *ReadEma(1)
  838.      70    data 3
  839.      80    data 1,2,3,4,5,6,7,8,9
  840.      90    data 3,4,5,6,7,2,3,4,5
  841.     100    '
  842.     110    gosub *DispEma(0):print
  843.     120    gosub *DispEma(1):print
  844.     130    gosub *AddEma(0,1)
  845.     140    gosub *DispEma(0)
  846.     150    end
  847.     160    '
  848.     170    *ReadEma(A)
  849.     180      local I,J
  850.     190      for I=0 to N-1
  851.     200        for J=0 to N-1
  852.     210          read ema(A;I,J)
  853.     220        next
  854.     230      next
  855.     240    return
  856.     250    '
  857.     260    *AddEma(A,B)
  858.     270      local I,J
  859.     280      for I=0 to N-1
  860.     290        for J=0 to N-1
  861.     300          ema(A;I,J)+=ema(B;I,J)
  862.     310        next
  863.     320      next
  864.     330    return
  865.     340    '
  866.     350    *DispEma(A)
  867.     360      local I,J
  868.     370      for I=0 to N-1
  869.     380        for J=0 to N-1
  870.     390          print ema(A;I,J);
  871.     400        next:print
  872.     410      next
  873.     420    return
  874.  
  875. Note:    Some of block commands are usable:
  876. Ex:    block ema(0;1,*)=123
  877.     block ema(0;*,*)+=block ema(1;*,*)
  878.     clr, neg, swap block ema( ) are also usable.
  879.  
  880. Note:    We recommend you to use normal arrays at first and
  881.     compute for small parameters.  After debugging the
  882.     program, you save the program in the ASCII mode(use
  883.     asave) and replace the names of normal arrays by
  884.     ema(?;  using a text-editor.
  885.       And then enlarge the size of parameters.  We think
  886.     you will be confused if you will use EMA-arrays from
  887.     the beginning.
  888.  
  889.  
  890. ~~RandomFile
  891. Random Files
  892.  
  893.   Disk files are usable for optional arrays.
  894. Their names are file1, file2, file3 only.
  895.  
  896. Limitation:
  897.   1 dimensional.
  898.  
  899. 1) make a new file
  900.     open "ABC" as file1(1000) word 100
  901. uses file "ABC" for the array named file1.  The indices
  902. are from 0 to 1000.  Size of each element is 100 words.
  903.  
  904. 2) read/write
  905.     file1(10)=123
  906.     print file1(5)
  907.  
  908. 3) close file
  909.     close file1
  910.  
  911. 4) use again
  912.     open "ABC" as file1
  913.  
  914. Sample:
  915.      10    'GENWRITE version 2.0
  916.      20    open "GENTBL" as file1(6542) word 1
  917.      30    file1(0)=0:file1(1)=1
  918.      40    for I=2 to 6542
  919.      50      print I,
  920.      60      P=prm(I)
  921.      70      file1(I)=fnGenshi(P)
  922.      80    next
  923.      90    end
  924.     100    '
  925.     110    fnGenshi(P)
  926.     120      local Gen=1,N=P-1,Nw,Div,Sw%
  927.     130      if P=2 then return(1)
  928.     140      if or{P<3,len(P)>32,prmdiv(P)<P} then return(0)
  929.     150      repeat
  930.     160        inc Gen:Nw=N:Sw%=1
  931.     170        repeat
  932.     180          Div=prmdiv(Nw)
  933.     190          repeat:Nw=Nw\Div:until res:Nw=Nw*Div+res
  934.     200          if modpow(Gen,N\Div,P)=1 then Sw%=0:Nw=1
  935.     210        until Nw=1
  936.     220      until Sw%
  937.     230    return(Gen)
  938.  
  939.  
  940. ~~UserProg.
  941. User Program
  942.  
  943.   Machine language programs can be put in predeclared arrays of
  944. Short variables and called by array names.  The program starts
  945. at 0100H on the array's segment.  It must be of .COM type with
  946. extension .UBB.  Arguments are passed via either variables or
  947. the first 28 elements of the array.  The memory map, after the
  948. program is BLOADed and the arguments set (by BLOAD or CALL),
  949. is as follows:
  950.  
  951. 0000H-001FH    Size of the array etc.  Do not rewrite this area.
  952. 0020H-003FH    0th through 15th elements of an array, which can
  953.         be used to pass arguments.
  954. 0040H-0041H    Byte size of Long Variables
  955.         ((value specified by WORD) * 2 + 2)
  956. 0042H-0043H    Byte size of EXTRA Variables
  957. 0044H-0045H    Offset of the work area that holds the current
  958.         position of the calculation stack.  Segment is SS.
  959. 0080H-00FFH    Offset and segment of 1st argument, offset and
  960.         segment of 2nd argument, ...(addresses of at most
  961.         32 arguments, each 4 bytes long)
  962.  
  963.   The segment:offset pairs for the arguments may be omitted if
  964. the values are unchanged.  If you omit them, either use empty
  965. parentheses or successive commas.  When the routine is called,
  966. the registers are such that DS = ES = SS <> CS.  Use far
  967. returns.  Do not change DS, ES, SS, BP, and the string
  968. direction flag.
  969.  
  970. Ex1:
  971.  
  972.   This example clears the 0th through 9th elements of an array.
  973. The program name is CLR10, say.  The main program contains the
  974. three lines,
  975.  
  976.     DIM CL%(150)
  977.     BLOAD "CLR10", CL%()
  978.     CALL CL%(X%(0))
  979.  
  980. When the user program is called, the address of the 0th
  981. element of the array is in CS:0080H.  The source program would
  982. be as follows.  MAKEUBB CLR10 makes an executable program.
  983. MASM and LINK are needed.
  984.  
  985. ;SAMPLE FOR MAKING USER PROGRAM
  986. CODE    SEGMENT
  987.     ASSUME  CS:CODE,DS:CODE
  988.  
  989.     ORG    100H
  990. START:
  991.  
  992. CLR10    PROC    FAR        ;make it a PROC FAR to generate
  993.                 ;RETF code
  994.     MOV    BX,80H
  995.     LES    DI,CS:[BX]    ;get segment:offset of 0th element
  996.                 ;of the array
  997.     MOV    CX,10
  998.     XOR    AX,AX
  999.     REP    STOSW
  1000.     MOV    AX,SS        ;recover DS,ES,BP.
  1001.     MOV    ES,AX        ;DS,ES may be set equal to SS
  1002.     RET
  1003.  
  1004. CLR10    ENDP
  1005.  
  1006. CODE    ENDS
  1007. END    START
  1008.  
  1009. Ex2:
  1010.  
  1011.   To call UBASIC86's calculation routine from user programs,
  1012. put necessary arguments onto the calculation stack; see UB.MAC
  1013. macro definition file.
  1014.  
  1015.   PUSH(@PUSH) and POP(@POP) do not allow Short Variables.
  1016.  
  1017.   ECMSTEP2.UBB in ECMX corresponds to the following UBASIC lines:-
  1018.     M#=(WD-X3(0)*WC+X2(0)*WB-X1(0)*WA+X0(0))@N
  1019.     for J%=1 to 11
  1020.       M#=(WD-X3(J%)*WC+X2(J%)*WB-X1(J%)*WA+X0(J%))@N*M#@N
  1021.     next
  1022.  
  1023.   See ECMSTEP2.ASM.  MAKEUBB ECMSTEP2 does the necessary
  1024. assemble and link.
  1025.  
  1026.  
  1027. ~~Redirect
  1028. Output Redirection
  1029.  
  1030.   Output of PRINT/LPRINT statements can be redirected and
  1031. pluralized.
  1032.  
  1033. Ex:    PRINT = PRINT + LPRINT + "ABC".
  1034.  
  1035.    This makes PRINT statements to output to the screen, printer,
  1036. and file "ABC" until another such command or NEW or LOAD is
  1037. executed.  The PRINT#1 outputs are binary whereas the command
  1038. above outputs to "ABC" in the text (ASCII) mode.  Use SPC or
  1039. TAB rather than LOCATE and LLOCATE when redirecting to files.
  1040. The right-hand sides of "PRINT =" and "LPRINT =" must be
  1041. distinct.
  1042.  
  1043.  
  1044. ~~AutoExec.
  1045. Automatic Execution
  1046.  
  1047.   To automatically LOAD ECMX and factorize 3^33 + 1 and 6^66 + 1,
  1048. make the file "TEST":
  1049.  
  1050.     LOAD "ECMX"
  1051.     PRINT=PRINT+"MEMO"
  1052.     RUN
  1053.     3^33+1
  1054.     6^66+1
  1055.     0
  1056.     SYSTEM
  1057.  
  1058.   Then type UBIBM <TEST on the DOS command line.  Note that the
  1059. keyboard is disabled.
  1060.  
  1061. UBASIC86's output cannot be redirected by UBIBM >TEST1.
  1062.  
  1063.  
  1064. ~~ASC<->BIN
  1065. ASCII <-> BINARY data conversion
  1066.  
  1067.   ASCII from/to BINARY data conversion is done by input/output
  1068. redirection.
  1069.  
  1070. ABC(=BINARY) -> XYZ(=ASCII)
  1071.     10    open"ABC" for input as #1
  1072.     20    print=print+"XYZ"
  1073.     30    while not eof(1)
  1074.     40      input #1,A
  1075.     50      print A
  1076.     60    wend
  1077.     70    close #1
  1078.     80    print=print
  1079.     90    end
  1080.  
  1081. XYZ(=ASCII) -> ABC(=BINARY)
  1082.     10    open"ABC" for output as #1
  1083.     20    input="XYZ"
  1084.     30    loop
  1085.     40      input A
  1086.     50      print #1,A
  1087.     60    endloop
  1088.   This stops at the line 40 when this encounts the file end.
  1089. But don't care.
  1090.  
  1091. Type:
  1092.     close #1:input=input:end
  1093. to finish the conversion safely.
  1094.  
  1095.  
  1096. ~~Codes
  1097. Code of Numbers.
  1098.  
  1099. Short Variables -- The most significant bit represents the
  1100. sign, and the remaining 15 bits represent the absolute value.
  1101. There is no -32768.
  1102.  
  1103. Long and EXTRA Variables -- the least significant 13 bits
  1104. (currently only 9 bits) of the least significant word
  1105. represent the number of effective word, the next bit is the
  1106. complex flag and the next if the fraction flag,and the most
  1107. significant bit is the sign.  The absolute value begins with
  1108. the next word.
  1109.   The actual length is one plus the length specified by WORD;
  1110. thus an EXTRA Variable occupies 543 words.
  1111.  
  1112.   For example, 1.5 is represented as follows when POINT = 2.
  1113. 4003H, 0000H, 8000H, 0001H
  1114. <- less significant    more significant ->
  1115.  
  1116. Also , 1.5+2#i is represented as follows.
  1117. 2006h,4003H, 0000H, 8000H, 0001H, 0001H, 0002H
  1118. (1)(2) (3)             (4)
  1119. (1) complex flg on(sign flg and fraction flag must be off)
  1120. (2) effective words
  1121. (3) start of real part
  1122. (4) start of imaginary part
  1123.  
  1124. Files -- Numbers in files are formatted as Long and EXTRA
  1125. Variables represented as above.
  1126. The first 8 words of a file contains various information.
  1127.  
  1128. Arrays --
  1129. 0000H(WORD)    Dimension.
  1130. 0002H(WORD)    Not Used.
  1131. 0004H(WORD)    Size of the 1st dimension.
  1132. 0006H(WORD)    Number of elements per each 1st index.
  1133. 0008H(WORD)    Size of the 2nd dimension.
  1134. 000AH(WORD)    Number of elements per each combination of 1st
  1135.         & 2nd indices
  1136. ...
  1137. 001CH(WORD)    Size of the 7th dimension.
  1138. 001EH(WORD)    Must be 1.
  1139.  
  1140.   The current version supports only 3 dimensons.
  1141.  
  1142.  
  1143. ~~Functions
  1144. Built-In Functions
  1145.  
  1146.   Note that divisions are truncated, not rounded.
  1147.  
  1148. POWER -- X^Y
  1149. If Y=0 then answer=1. Otherwise if X=0 then answer=0.
  1150. If Y is a positive integer, the repeated squaring method is
  1151. used.
  1152. If Y is a negative integer, (1/X)^(-Y) is calculated as above.
  1153. If Y is a real number, it is done as above for the integer
  1154. part and for the rest is done by the combination of EXP and
  1155. LOG.
  1156. If Y is a complex number, EXP(LOG(X)*Y) is calculated.
  1157.  
  1158. ISQRT -- Uses Newton's algorithm:  Set t to the argument x.
  1159. Then repeat replacing t with (t + x \ t) \ 2 until t does not
  1160. decrease.  This gives the integer part of the square root of
  1161. x.
  1162.  
  1163. SQRT -- Same as above, with \ replaced by /.
  1164. If X is negative then calculates the square root of -x and
  1165. multiplies #i.
  1166. If X is complex(X=A+B*#i) then
  1167.   if A>=0 then
  1168.     Real part =sqrt{(abs(X)+A)/2}
  1169.     Imag part = B/(2*Real part)
  1170.   else
  1171.     Imag part =sqrt{(abs(X)-A)/2}
  1172.     Real part = B/(2*Imag part)
  1173.  
  1174. SIN, COS  -- Adds the Taylor series until the summand
  1175. vanishes.
  1176. The parameter X is reduced in 0<=x<#pi/4 before calculating
  1177. the series.
  1178. If X is complex(X=A+B*#i) then
  1179.     sin(X)=sin(A)*cosh(B)+cos(A)*sinh(b)*#i
  1180.     cos(X)=cos(A)*cosh(B)+sin(A)*sinh(b)*#i
  1181.  
  1182. TAN = SIN/COS
  1183.  
  1184. ATAN -- sum of {(-1)^n}X^(2n+1)/(2n+1)
  1185. The parameter X is reduced to less than 1/8 by using following
  1186. formulas:
  1187.     pi/2-atan(1/X)
  1188.     atan(X)=atan(1/2)+atan(2X-1/X+2)
  1189.     atan(X)=atan(1/4)+atan(4X-1/X+4)
  1190.     atan(X)=atan(1/4)-atan(1-4X/X+4)
  1191.   UBASIC has atan(1/2) and atan(1/4) as system constants.
  1192. If X is complex then use
  1193.     atan(X)=log{(#i-X)/(#i+X)}/2#i
  1194.  
  1195. COSH -- (exp(x)+1/exp(x))/2
  1196.  
  1197. SINH -- (exp(x)-1/exp(x))/2
  1198.  
  1199. EXP -- Adds the Taylor series until the summand vanishes for
  1200. 0<= x <log(2)/2.
  1201. Generally, when x = n*log(2) +- y, (0<=y<log(2)/2), exp(+-y)
  1202. is calculated as above and is shifted by n bits.
  1203. If X is complex(X=A+B*#i) then
  1204. exp(X)=exp(A)*(cos(B)+#i*sin(B)).
  1205.  
  1206. LOG -- For 1 <= x < 2, let y = (x-1) / (x+1); repeat adding
  1207. (2 / (2n+1)) * y ^ (2n+1) to y until the summand vanishes.
  1208. For other values of x, first multiply or divide x by 2
  1209. repeatedly, then follow the algorithm above, then subtract or
  1210. add the suitable multiple of log(2).
  1211. If X is complex(X=A+B*#i) then
  1212. log(X)=log(abs(X))+#i*atan(B,A).
  1213. Where,
  1214.   atan(B,A)    = sgn(B)*pi/2    if A=0
  1215.         = atan(B/A)    if A>0
  1216.         = atan(B/A)+pi    if B>=0>A
  1217.         = atan(B/A)-pi    if A,B<0 .
  1218. Thus atan(B,A) takes its value larger than -pi less or equal
  1219. to pi.
  1220.  
  1221. ABS --- Absolute value of the complex number  z  is by
  1222. definition
  1223.     sqrt(Re(z)^2+Im(z)^2).
  1224. To minimize error, we shift-up  z  by POINT words and shift-
  1225. down the result when Re(z) and Im(z) are both less than 1,
  1226.  
  1227. BESSEL --- using simply their power series:
  1228.     BesselI(k,x)=sum of (x/2)^(2*n+k)/(n!*(n+k)!)
  1229.     BesselJ(k,x)=sum of (-1)^n*(x/2)^(2*n+k)/(n!*(n+k)!)
  1230.  
  1231. ~~!
  1232. !(n)
  1233. See:    Factorial.
  1234.  
  1235. ~~_X
  1236. _X
  1237.     Represents the variable when a polynomial is entered.
  1238.     This is used to distinguish a polynomial from other
  1239.     expressions.
  1240. Ex:    1+2*_X+3*_x^2
  1241.  
  1242.         The following piece of code will convert a polynomial
  1243.         entered using "X" to the necessary form using "_X" in 
  1244.         a program in which a polynomial is to be entered:
  1245.  
  1246.     100    X=_X
  1247.     110    strinput "f(x)=";W#
  1248.  
  1249. ~~#E
  1250. #E
  1251.     The base of natural logarithms, #e = exp(1).
  1252.     The precision is specified by the POINT command and is no
  1253.     more than 541 words.
  1254.     Assign it to a variable, rather than evaluating it many
  1255.     times.
  1256. Out:    real.
  1257. Ex:    print #E    result: 2.7182...
  1258.  
  1259. ~~#EPS
  1260. #EPS
  1261.     The smallest positive number that can be represented under
  1262.     the current POINT setting.  Use 10 or more times #eps for
  1263.     the convergence limit of Newton's method.
  1264. Out:    real.
  1265.  
  1266. ~~#EULER
  1267. #EULER
  1268.     Euler's constant, #euler = 0.5772...
  1269. Out:    real.
  1270.  
  1271. ~~#PI
  1272. #PI
  1273.     #pi = 3.14....
  1274.     The precision is specified by the POINT command and is no
  1275.     more than 541 words.  Assign it to a variable, rather than
  1276.     evaluating it many times.
  1277. Note:    Use PI(x) to get a multiple of #PI.
  1278. See:    PI.
  1279.  
  1280. ~~ABS
  1281. ABS(x)
  1282.     Absolute value of x.
  1283. Inp:    number.
  1284. Out:    integer, rational, real.
  1285. Ex:    print abs(1+2#i)    result: 2.2360...
  1286.  
  1287. ~~ABSADD
  1288. ABSADD(x)
  1289.     abs(Re(x)) + abs(Im(x)).
  1290. Inp:    number.
  1291. Out:    integer, rational, real.
  1292. Ex:    print absadd(1+2#i)    result: 3
  1293.  
  1294. ~~ABSMAX
  1295. ABSMAX(x)
  1296.     max{abs(Re(x)), abs(Im(x))}.
  1297. Inp:    number.
  1298. Out:    integer, rational, real.
  1299. Ex:    print absmax(1+2#i)    result: 2
  1300.  
  1301. ~~ALEN
  1302. ALEN(x)
  1303.     Number of decimal digits in the integer part of abs(x).
  1304. Note:    Use it with LOCATE, SPC, TAB to format output.
  1305. Inp:    integer.
  1306. Out:    integer.
  1307. Ex:    alen(0) = alen(9) = 1,  alen(-123/10) = 2.
  1308.  
  1309. ~~AND
  1310. AND{expression1,expression2, ...}
  1311.     Logical product.
  1312.     1 if all the expressions are nonzero, 0 otherwise.
  1313. Inp:    expressions.
  1314. Out:    integer(0 or 1).
  1315. Ex:    if and{A,B,...} then
  1316.         when the part between {} is long, use ':' like this:
  1317.     if and{A,
  1318.       :B,
  1319.       :...}
  1320.     :then
  1321.  
  1322. ~~APPEND
  1323. APPEND "program_name"
  1324.     Reads a program and appends it at the end of the current
  1325.     program.  The appended program is automatically renumbered.
  1326.     You cannot insert a program in the middle of the current
  1327.     program.
  1328.     A list of programs is displayed if no program name is given.
  1329.     Choose a program with the arrow keys and <ENTER>.
  1330. See:    LOAD, SAVE, VCHG, VLIST, VXREF.
  1331.  
  1332. Ex:    open "file_name" for APPEND as #n
  1333. See:    OPEN.
  1334.  
  1335. ~~ARG
  1336. ARG(x)
  1337.     Argument of x.
  1338. Inp:    number.
  1339. Out:    real y (-pi < y <= pi).
  1340. Ex:    print arg(1+2#i)    result: 1.1071...
  1341.  
  1342. ~~AS
  1343. AS
  1344. See:    OPEN.
  1345.  
  1346. ~~ASAVE
  1347. ASAVE "filename"
  1348.     Saves the current program on to a disk in the standard
  1349.     DOS text-file form(=ASCII form).
  1350. Note:    A program in ASCII form can be exchanged between UBASIC
  1351.     and your favorite editor which is more convenient for
  1352.     writing a large program.
  1353.     As intermediate code may vary with versions, ASCII form
  1354.     is recommended if you want to keep a program for a long
  1355.     time.
  1356.     If no file name is give, the current date and time are
  1357.     used as the program name.
  1358. See:    SAVE.
  1359.  
  1360. ~~ASC
  1361. ASC(character/string )
  1362.     ASCII code of a character/string.
  1363. Note:    Conversion from internal code(s) of a character/string
  1364.     to a value.
  1365.     It is the same as in BASIC if the argument is one
  1366.     character.
  1367. Out:    integer.
  1368. Ex:    print asc("A")    result: 65
  1369. See:    CHR.
  1370.  
  1371. ~~ATAN
  1372. ATAN(x)
  1373.     Arctangent of x.
  1374.     If x is real, the value is larger than -pi/2 and less than
  1375.     or equal to pi/2.
  1376. Out:    real, complex number.
  1377. Ex:    print atan(1)    result: 0.7853...
  1378. See:    appendix B for the algorithm.
  1379.  
  1380. ~~ATTRIB
  1381. ATTRIB(x)
  1382.     Attribute word of x.
  1383. Note:    In ordinary cases, TYPE is recommended.
  1384. Inp:    any data.
  1385. Out:    string (hexadecimal conversion of the
  1386.     attribute word).
  1387. See:    TYPE.
  1388.  
  1389. ~~AUTO
  1390. AUTO [start_line_number]
  1391.     Generates line numbers.
  1392. Note:    Starts from largest_line_number+10 if no line number is
  1393.     given.
  1394.  
  1395. ~~BEEP
  1396. BEEP
  1397.     Rings the bell.
  1398.  
  1399. ~~BESSELI
  1400. BESSELI(k,x)
  1401.     k-th Bessel_I function of x.
  1402. Inp:    k is an integer larger than 0. x is a number.
  1403. Out:    number.
  1404. Ex:    print besseli(1,2.3)    result: 2.0978...
  1405. See:    appendix B for the algorithm.
  1406.  
  1407. ~~BESSELJ
  1408. BESSELJ(k,x)
  1409.     k-th Bessel_J function of x.
  1410. Inp:    k is an integer larger than 0. x is a number.
  1411. Out:    number.
  1412. Ex:    print besselj(1,2.3)    result: 0.5398...
  1413. See:    appendix B for the algorithm.
  1414.  
  1415. ~~BIT
  1416. BIT(n,x)
  1417.     n-th bit of x.
  1418. Inp:    n is an integer. x is any data.
  1419. Out:    integer (0 or 1).
  1420. Ex:    BIT(0, 5) = 1, BIT(1, 5) = 0, BIT(2, 5) = 1,
  1421.     BIT(3, 5) = 0.
  1422. Note:    Result has almost no meaning when x is a decimal.
  1423. See:    LEN.
  1424.  
  1425. ~~BLOAD
  1426. BLOAD "machine_language_program", short_var([arg1, arg2, ...])
  1427. See:    the "Machine Language Programs" section.
  1428.     Arguments must be simple variables.
  1429.  
  1430. ~~BLOCK
  1431. BLOCK array(index,index...)
  1432.     Assigns values to the specified array members.
  1433. Ex:    block A(2..4, 3..6) = X
  1434.         assigns X to each A(i, j) for i=2,3,4 and j= 3,4,5,6.
  1435.  
  1436.     block A(*,*) = X
  1437.         assigns X to all the elements.
  1438.  
  1439.     block B(0..2) = block A(2, 1..3)
  1440.         assigns A(2, 1) to B(0), etc.
  1441.  
  1442.     swap block B(0..2), block A(2, 1..3)
  1443.         swaps the values.
  1444.  
  1445.         Note that a double exchange occurs when overlapping parts
  1446.         of one array are specified. In this case, results are 
  1447.         unpredictable.
  1448.  
  1449.     clr block A(2..3,4..5)
  1450.         sets to zero (same as block A(2..3,4..5)=0).
  1451.  
  1452.     neg block B%(0..5)
  1453.         changes signs.
  1454.  
  1455.     You can also use expressions such as
  1456.  
  1457.     block A(2..4) += expression
  1458.     block A(2..4) += block B(3..5)
  1459.  
  1460.     and these with + replaced by -, *, /, \, and @.
  1461.     The first of these is the same as
  1462.     A(2)=A(2)+(expression):A(3)=A(3)+(expression)
  1463.     :A(4)=A(4)+(expression)
  1464.     Note the parenthesis in the right hand side.
  1465.     In the second, you cannot add any term to the right hand
  1466.     side.
  1467.  
  1468. Note:    When a user-defined function is called in the middle of
  1469.     the calculation of an index or an expression, BLOCK
  1470.     used in this function creates an error.
  1471.     When BLOCK is used on both sides of an expression, the
  1472.     number of the indices must be the same though the
  1473.     composition may vary.
  1474.  
  1475. See:    CLR, NEG, SWAP.
  1476.  
  1477. ~~CALL
  1478. CALL short_array_name([arg1,arg2,...])
  1479.     Calls a user machine language program after the arguments
  1480.     are set.
  1481. See:    the "Machine Language Programs" section.
  1482.  
  1483. ~~CANCEL
  1484. CANCEL for<,for,for,...>
  1485.     Cancels the current for-next loop before jumping out of it.
  1486. Ex:    cancel for
  1487. Note:    Use GOTO to specify where to jump.
  1488.     GOTO is necessary, unlike 'break' or 'cancel' statements
  1489.     in other languages.
  1490. See:    FOR.
  1491.  
  1492. ~~CHR
  1493. CHR(ASCII code)
  1494. Inp:    integer. Signs are neglected.
  1495. Out:    character/string.
  1496. Ex:    print chr(65)    result:A
  1497. See:    ASC.
  1498. Note:    The format of hexadecimal expression is not '&h..' but
  1499.     '0x..'.
  1500.  
  1501. ~~CLOSE
  1502. CLOSE
  1503. CLOSE [#n]
  1504. CLOSE file1[,file2,...]
  1505.     Closes the open files.  If no file name (or file number) is
  1506.     given, then it closes all the open files.
  1507. See:    EOF, OPEN.
  1508.  
  1509. ~~CLR
  1510. CLR variable1[,variable2,...]
  1511.     Sets the variables to zero.  "CLR A" is faster than "A = 0".
  1512. Ex:    clr A,B,C
  1513.         sets A, B, C to 0.
  1514. See:    DEC, INC, NEG.
  1515.  
  1516. CLR BLOCK arrayname(index)
  1517.     Sets the specified members of an array to 0.
  1518. Ex:    clr block A(0..10)
  1519.         sets from A(0) to A(10) to 0.
  1520.     clr block A(2,1..3)
  1521.         sets A(2,1),A(2,2),A(2,3) to 0.
  1522. See:    BLOCK for details.
  1523.  
  1524. CLR TIME
  1525.     Sets the clock to "00:00:00".  Effective only inside UBASIC.
  1526.     It does not initialize the system clock, so there may be an
  1527.     error of up to one second.
  1528.  
  1529. ~~CLS
  1530. CLS [n]
  1531.     Clears the screen.
  1532. Inp:    none or integer 1.
  1533. Note:    Clears the text screen.
  1534. Ex:    10    console 0,25:cls
  1535.  
  1536. ~~CCOEFF
  1537. CCOEFF(polynomial)
  1538.     Constant term of polynomial.
  1539. Ex:    A=poly(1,3,5):print ccoeff(A)    result: 1
  1540. See:    COEFF, LCOEFF.
  1541.  
  1542. ~~COEFF
  1543. COEFF(polynomial,degree)
  1544.     Coefficient of the term of specified degree of polynomial.
  1545. COEFF(polynomial, degree)=expression
  1546.     Assigns a value to the coefficient of the term of specified
  1547.     degree of polynomial.
  1548. Inp:    argument1 is a polynomial or 0.
  1549.     argument2 is an integer (>= 0).
  1550. Ex:    A=poly(1,3,5):print coeff(A,2)    result: 3
  1551.     A=0:coeff(A,3)=2:coeff(A,0)=5:print A    result: 2*X^3 + 5.
  1552. See:    CCOEFF, LCOEFF, POLY.
  1553.  
  1554. ~~COLOR
  1555. COLOR(n)
  1556.     Specifies text color. (0 =< n =< 7)
  1557.  
  1558. ~~COMBI
  1559. COMBI(n,r)
  1560.     Number of combinations extracting r elements from n elements.
  1561. Inp:    integer n (0 <= n < 65536).
  1562. Out:    integer.
  1563. Ex:    print combi(4,2)    result: 6
  1564.  
  1565. ~~CONJ
  1566. CONJ(x)
  1567.     Complex conjugate of x.
  1568. Inp:    number.
  1569. Out:    number.
  1570. Ex:    print conj(1+2#i)    result: 1-2#i
  1571. See:    IM, RE.
  1572.  
  1573. ~~CONT
  1574. CONT
  1575. See:    STOP.
  1576.  
  1577. ~~CONSOLE
  1578. CONSOLE start line,lines in console area[, function key display
  1579.     switch(0/1)]
  1580.     Declares the console window area.
  1581. Note:    When the second argument is '*',the number of lines is
  1582.     set to the maximum.
  1583.     Settings are initialized when no argument is given.
  1584. Inp:    Start_line is from 0 to 24.
  1585.     Lines_in_console_area is from 5 to 25.
  1586.     Function_key_display_switch is 1 (displays) or 0
  1587.     (not displays).
  1588. Ex:    console 0,20,0
  1589.         sets the console area to 20 lines starting from
  1590.     line 0 (to line 19), and displays no function keys.
  1591.  
  1592. ~~COS
  1593. COS(x)
  1594.     Cosine of x.
  1595. Inp:    number.
  1596. Out:    number.
  1597. Ex:    print cos(1.23)    result: 0.3342...
  1598. See:    SIN,TAN
  1599.     Appendix B for the algorithm.
  1600.  
  1601. ~~COSH
  1602. COSH(x)
  1603.     Hyperbolic cosine of x.
  1604. Note:    (exp(x)+exp(-x))/2
  1605. Inp:    number.
  1606. Out:    number.
  1607. Ex:    print cosh(1.23)    result: 1.8567...
  1608. See:    SINH.
  1609.     appendix B for the algorithm.
  1610.  
  1611. ~~CUTLSPC
  1612. CUTLSPC(string)
  1613.     Cuts off the spaces in the left end of a string.
  1614. Inp:    string.
  1615. Out:    string.
  1616. Ex:    print "A":cutlspc("    B C")    result:AB C
  1617.  
  1618. ~~CUTSPC
  1619. CUTSPC(string)
  1620.     Cuts off all the spaces in a string.
  1621. Inp:    string.
  1622. Out:    string.
  1623. Ex:    print "A":cutspc("    B C")    result:ABC
  1624.  
  1625. ~~CVR
  1626. CVR(x)
  1627.     Decimal expression of the numerator of rational divided by
  1628.     the denominator.
  1629. Inp:    integer, decimal, rational.
  1630. Out:    real.  argument ifself if it is not rational.
  1631. Ex:    print cvr(1//3)    result: 0.3333...
  1632.  
  1633. ~~DATA
  1634. DATA expression1[,expression2,...]
  1635.     Data for READ statements.
  1636. Note:    A string must be put in " ".
  1637.     Commands placed after DATA in the same line are
  1638.     neglected.
  1639. See:    READ, RESTORE.
  1640.  
  1641. ~~DATE
  1642. DATE
  1643.     String containing current date and time.
  1644. Ex:    print date
  1645.         displays current year, month, day, hour, minute and
  1646.         second.
  1647. Out:    string.
  1648. Note:    CLR TIME does not affect the time represented by DATE.
  1649.  
  1650. ~~DEC
  1651. DEC variable1[,variable2,...]
  1652.     Decrements the variables.  "DEC A" is faster than
  1653.     "A = A - 1."
  1654.     The variable must currently hold integer values.
  1655. Ex:    A=100:dec A:print A    result: 99
  1656. See:    CLR, INC, NEG.
  1657.  
  1658. ~~DECODE
  1659. DECODE(ENCODEd_string)
  1660.     Original string of an ENCODEd string.  Tokens are marked
  1661.     off by a space.
  1662. Ex:    print decode(encode("x+sin(abc)")    result: X + sin( Abc )
  1663. See:    ENCODE.
  1664.  
  1665. ~~DEFSEG
  1666. DEFSEG = segment
  1667.     Specifies the segment to be accessed by PEEK and POKE.
  1668. Note:     Do not put a space between DEF and SEG.
  1669. See:    PEEK, PEEKW, PEEKS, POKE, POKEW, POKES, VARPTR.
  1670.  
  1671. ~~DEG
  1672. DEG(polynomial)
  1673.     Degree of polynomial.
  1674. Note:    Degree of 0 is defined to be -1.
  1675. Ex:    A=poly(0,0,1):print deg(A)    result: 2
  1676. See:    LEN.
  1677.  
  1678. ~~DELETE
  1679. DELETE linenumber1 - linenumber2
  1680.     Deletes the portion of the program.
  1681.  
  1682. ~~DEN
  1683. DEN(rational)
  1684.     Denominator of the argument.
  1685. Inp:    integer, rational.
  1686. Ex:    print den(2//3)    result: 3
  1687. See:    NUM.
  1688.  
  1689. ~~DIFF
  1690. DIFF(polynomial)
  1691.     Differential of polynomial.
  1692. Ex:    A=poly(1,1,1):print diff(A)    result: 2*X + 1
  1693.  
  1694. ~~DIM
  1695. DIM arrayname(bound1[,bound2[,bound3]])
  1696.     Declares arrays, specifies the number of indices and sets
  1697.     all the members of the arrays to 0.
  1698. Note:    The indices start at 0.
  1699.     The bounds are nonnegative integers such that
  1700.     bound1 <= 65534,  (bound2 + 1) * (bound3 + 1) <= 65535.
  1701.  
  1702.     In subroutines and functions, declarations of arrays
  1703.     must be placed at the beginning, not in the middle.
  1704.     The arrays declared in a subroutine or function are
  1705.     valid only in that subroutine or function and is are
  1706.     erased by RETURN.
  1707.  
  1708.     EMA-arrays are NOT automatically erased by RUN.  So it is
  1709.     recommended to place EMAWORD just before DIM EMA().
  1710. See:    ERASE.
  1711.  
  1712. ~~DIR
  1713. DIR ["pathname"]
  1714.     Displays the names of the programs on a disk.
  1715.     The path can contain wildcard match characters.
  1716. Ex:    dir "a:\bin\a*.*"
  1717.         displays the file names beginning with 'a' in the
  1718.     \bin directory of drive A.
  1719.  
  1720.     Note the following symbols:
  1721.     +    data file
  1722.     *    machine-language program
  1723.     p    write protected
  1724.     Sizes are given in 100 bytes.
  1725.  
  1726. DIR="path"
  1727.     Changes the current directory.
  1728. Ex:    dir="b:"
  1729.         Changes the object of LOAD and SAVE to drive B.
  1730. Note:    Do not put '\' at the end of path name.
  1731.  
  1732. ~~DOSCMD
  1733. DOSCMD string
  1734.     Invokes the command.com file to execute a DOS command.
  1735. Ex:    DOSCMD "dir b:"
  1736.         temporally transfers control to MS-DOS to execute
  1737.     'dir b:'.  But the display is cleard at once and
  1738.     control is returned to UBASIC.
  1739.     In this case, it is recommended that command.com is
  1740.     re-invoked by DOSCMD "a:\command".
  1741.     DOSCMD "program name" runs the specified program.
  1742. Note:    A program using graphic areas may destroy the work area
  1743.     of UBASIC.
  1744.     You may destroy the screen #1 of graphic RAM.
  1745.  
  1746. ~~EDIT
  1747. EDIT [line_number or label]
  1748.     Displays a screenful of the current program including the
  1749.     specified line.
  1750.     The default line is the previously specified or edited
  1751.     line, or the line on which the most recent error occurred.
  1752.  
  1753. ~~ELSE
  1754. ELSE
  1755. See:    IF.
  1756.  
  1757. ~~ELSEIF
  1758. ELSEIF
  1759. See:    IF.
  1760. Note:    Do not put a space between ELSE and IF.
  1761.  
  1762. ~~EMA
  1763. EMA([extended_array_number];index1,index2)
  1764.     Specified member of an EMA-array.
  1765. Ex:    print ema(1;2,3)
  1766.         displays the member(2,3) of EMA #1.
  1767. See:    EMA-array.
  1768.  
  1769. ~~EMAWORD
  1770. EMAWORD expression
  1771.     Specifies the size of a member of an EMA-array.
  1772.     Default size is 542 words.
  1773. Note:    EMA-arrays are NOT automatically erased by RUN.  This is
  1774.     the only way to erase them.
  1775.     Do not put a space between EMA and WORD.
  1776. See:    EMA-array.
  1777.  
  1778. ~~ENCODE
  1779. ENCODE(string)
  1780.     Converts a string containing an expression or command to
  1781.     internal codes.
  1782. Note:    This makes VAL faster.
  1783. See:    VAL, DECODE.
  1784.  
  1785. ~~END
  1786. END
  1787.     Closes all files and ends program execution,
  1788.     sends a newline character to the printer if necessary,
  1789.     and cancels unterminated loops.
  1790.  
  1791. ~~ENDIF
  1792. ENDIF
  1793. See:    IF.
  1794. Note:    Do not put a space between END and IF.
  1795.  
  1796. ~~ENDLOOP
  1797. ENDLOOP
  1798. See:    LOOP.
  1799. Note:    Do not put a space between END and LOOP.
  1800.  
  1801. ~~EOF
  1802. EOF(n)
  1803.     1 if the content of file #n is exhausted, 0 otherwise.
  1804. Inp:    integer.
  1805. Out:    integer (0 or 1).
  1806. Ex:    10    open "abc" for input as #1
  1807.     20    while not eof(1)
  1808.     30      input #1,a
  1809.     40      print a
  1810.     50    wend
  1811.     60    close
  1812.         Continues to read until the data are exhausted.
  1813.     If EOF is not checked, an error occurs when the data
  1814.     are exhausted.
  1815.  
  1816. ~~ERASE
  1817. ERASE array1 [,array2,... ]
  1818.     Erases arrays.  Array names must be followed by parentheses, 
  1819.     e.g. "erase a()".  If the arrays a(m) and b(n) are 
  1820.     DIMensioned in this order, then it is faster to erase b(), 
  1821.     then a().  ERASE should not be used in subroutines and 
  1822.     functions.  Arrays created in subroutines and functions are 
  1823.     erased automatically by RETURN.
  1824. See:    DIM.
  1825.  
  1826. ~~ERROR
  1827. ERROR GOTO [line_number or label]
  1828. Note:    Usually, a program stops if an error occurs.  However,
  1829.     if a routine to handle errors has been specified by
  1830.     ON ERROR GOTO, the execution proceeds to that routine.
  1831. Ex:    10    on error goto *ErrorTrap
  1832.     20    print 1/0
  1833.     30    end
  1834.     40    *ErrorTrap
  1835.     50    print "error"
  1836.     60    end
  1837.         A "division by zero" error occurs in line 20.  Then the
  1838.     execution continues from line 40 as specified in line 10.
  1839. Note:    This statement does not work well. There is no "resume
  1840.     statement".  And this clears all the work areas
  1841.     concerning control of execution, so a program will not
  1842.     be executed normally if the error handling routine is
  1843.     designed to jump back to the subroutine where error has
  1844.     occurred.  This statement is recommendded only in
  1845.     programs which have a main menu and branches out of it.
  1846. See:    GOTO.
  1847.  
  1848. ~~EUL
  1849. EUL(n)
  1850.     Euler's function of n.
  1851. Inp:    integer n (1 <= n <= 4294967295).
  1852. Out:    integer.
  1853. Ex:    print eul(100)    result: 40
  1854.  
  1855. ~~EVAL
  1856. EVAL(string)
  1857.     Interprets a string as a command and executes it.
  1858. Note:    It is recommended to ENCODE the string if you want to
  1859.         evaluate it often.
  1860. Ex:    eval("list "+str(x))
  1861.         lists the lines specified by x.
  1862. See:    VAL.
  1863.  
  1864. ~~EVEN
  1865. EVEN(n)
  1866.     1 if n is even, 0 if odd.
  1867. Ex:    print even(10),even(11)    result: 1    0
  1868. See:    ODD.
  1869.  
  1870. ~~EXIST
  1871. EXIST("filename")
  1872.     1 if the file specified by "filename" exists, 0 otherwise.
  1873. Out:    integer (0 or 1).
  1874. Note:    An error occurs if you try to OPEN a file which does
  1875.     not exist.  The purpose of  the EXIST function is to
  1876.     avoid that error.
  1877. Note:    Extension of filename cannot be ommited.
  1878. Ex:    if exist("abc.ubd") then open "abc" for input as #1
  1879.  
  1880. ~~EXP
  1881. EXP(x)
  1882.     e to the x.  
  1883. Ex:    print exp(1.23)    result: 3.4212...
  1884. See:    Appendix B for the algorithm.
  1885.  
  1886. ~~FACTORIAL
  1887. FACTORIAL(n)
  1888.     Factorial of n.
  1889. Inp:    integer n (0 <= n <= 1014).
  1890. Out:    integer.
  1891. Ex:    print factorial(12)    result: 479001600
  1892.  
  1893. ~~FILE
  1894. FILE
  1895. See:    OPEN.
  1896.  
  1897. ~~FILE1
  1898. FILE1(n), FILE2(n), FILE3(n)
  1899.     Random files declared by OPEN statements.
  1900.     Special elements:
  1901.     FILEi(-1) = number of elements
  1902.     FILEi(-2) = element word size
  1903.     FILEi(-3) = POINT WORD length
  1904. See:    Random files.
  1905.  
  1906. ~~FILE2
  1907. FILE2
  1908. See:    FILE1
  1909.  
  1910.  
  1911. ~~FILE3
  1912. FILE3
  1913. See:    FILE1
  1914.  
  1915.  
  1916. ~~FIND
  1917. FIND(x,a(i),n)
  1918.     (Index - i) of the first occurrence of x in  a(i), ...,
  1919.     a(i+n-1).
  1920.     A negative value is returned if none is equal to x.  The
  1921.     array must be sorted in ascending or descending order.
  1922.     Binary search is used.
  1923. Inp:    x and a(i) are integer or real. n is an integer.
  1924. Out:    integer.
  1925. Ex:    find(3,A(2),10)
  1926.         if the return value is 4, a(6) is 3 (not a(4)).
  1927.  
  1928. ~~FIX
  1929. FIX(x)
  1930.     Integer part of x, truncating towards zero.
  1931. Inp:    integer, real, rational.
  1932. Out:    integer.
  1933. Note:    The result may differ from that of INT(x) when x is
  1934.     negative.
  1935. Ex:    print fix(12345/100)     result: 123
  1936.     print fix(-12345/100)    result:-123
  1937. See:    INT, ROUND.
  1938.  
  1939. ~~FN
  1940. FN function name (arg1, arg2, ...)
  1941.     Begins a user-defined function name.
  1942. Ex:    100    a=fnMAX(A,B)            'Calls function
  1943.     ...
  1944.     200    fnMAX(X,Y)            'Declaration of
  1945.                         function
  1946.     210      local Z            'Definition of a
  1947.                         local variable
  1948.     220      if X>=Y then Z=X else Z=Y
  1949.     230    return(Z)            'Returns a value
  1950. Note:    You may type '.' for 'fn'.
  1951. See:    "Subroutines and Functions" for details.
  1952.  
  1953. ~~FOR
  1954. FOR variable = initial_value TO final_value [STEP increment]
  1955. NEXT [variable]
  1956.     All the values must be integers.  The number of iterations
  1957.     is determined at the beginning of the loop as
  1958.  
  1959.     (final_value - initial_value) \ increment + 1
  1960.  
  1961.     which may not exceed 4294967295.  If it is zero or negative,
  1962.     the loop is not executed.
  1963.     The loop cannot be terminated by changing the value of the
  1964.     loop variable in it.  When the loop is terminated normally,
  1965.     the value of the loop variable is
  1966.     initial_value+number_of_iterations*increment.
  1967.     To jump out of the for-next loop, use CANCEL FOR.
  1968. Ex:    10    S=0
  1969.     20    for I=1 to 100
  1970.     30      S=S+I:if S>100 then cancel for:goto 50
  1971.     40    next I
  1972.     50    print I;S
  1973.     60    end
  1974.  
  1975. ~~FREE
  1976. FREE
  1977.     Displays the size of the available program area and stack
  1978.     area.
  1979. Note:    The available text area (=program area) shows how many
  1980.     more bytes of program codes you may write.
  1981.     The available stack area shows how many words in the
  1982.     256 words of system stack have never been used (not
  1983.     "are not being used now").  This is to monitor the
  1984.     system and can usually be ignored.
  1985.  
  1986. ~~FREEZE
  1987. FREEZE ["filename"]
  1988.     Writes the current program, variables, and other
  1989.     information on to a disk.  If you HALT and FREEZE the
  1990.     program execution, you can MELT and CONTinue it later.
  1991.     The size of the frozen file is 100k-300k bytes.
  1992. Note:    You can MELT the frozen information.  The filename should
  1993.     not contain an extension since ".ice" is automatically
  1994.     added.  "UB.ICE" in the current drive is used if the
  1995.     filename is not given.
  1996.     The disk must have 200k-500k bytes of free area.  The
  1997.     latter half of UBASIC and variable areas are frozen.
  1998.     FREEZE does not save the area of memory used by a
  1999.     machine-language program that is not in a UBASIC array.
  2000.     MELT does not work if the arrangement of memory has
  2001.     been changed.  This occurs when CONFIG.SYS is modified
  2002.     or memory resident programs are loaded.
  2003.  
  2004.     In ordinary BASIC, when you want to do another job
  2005.     while running a program which takes a lot of time, you
  2006.     have no choice but to abort the running program or to
  2007.     give up the new job.  There is no satisfactory solution
  2008.     as DOS does not currently support multi-tasking.
  2009.     However, to FREEZE the running program is an effective
  2010.     solution.
  2011. Ex:    1) Stop the running program by ctrl+BREAK or ctrl+c.
  2012.     2) FREEZE the current status of memory on to a disk.
  2013.     3) Start and finish another job.
  2014.     4) MELT the frozen memory.
  2015.     5) Continue the program by CONT.
  2016.  
  2017. See:    MELT.
  2018.  
  2019. ~~GCD
  2020. GCD(m,n)
  2021.     Greatest common divisor of m and n.
  2022. Inp:    integer or rational polynomial.
  2023. Out:    integer(>=0) or rational polynomial.
  2024. Ex:    print gcd(49,63)    result: 7
  2025.     print gcd(_x^2-1, _x^2+2*_x+1)    result: 2*x + 2
  2026.  
  2027. ~~GOSUB
  2028. GOSUB line_number or label
  2029.     Calls the subroutine.
  2030. GOSUB label(parameter1,parameter2,...)
  2031.     Calls the subroutine with parameters.
  2032. Note:    The subroutine called must have the same format of
  2033.     arguments.
  2034.     If an argument is a variable or an expression, the
  2035.     current value of it is assigned to the corresponding
  2036.     variable.  The previous value of the variable is pushed
  2037.     on to the stack and restored by the corresponding
  2038.     RETURN.
  2039.     Variables can be passed by address (use &).
  2040.     The corresponding variables share the same memory area.
  2041.     Array names must be followed by "()".
  2042.  
  2043. Ex:    10    A=1:B=2:C=0
  2044.     20    gosub *MAX(A,B,&C)    :'A,B are passed by value
  2045.     30    print C            :'&C is passed by address
  2046.     40    end            :'thus in *MAX, Z is
  2047.                      identified with C
  2048.     100    *MAX(X,Y,&Z)        :'X and Y are local variables
  2049.                      in *MAX
  2050.     110      if X>=Y then Z=X else Z=Y  :'they do not change X
  2051.                     and Y in the
  2052.     120    return            :'main routine if valiables
  2053.                      of the same name exist.
  2054. Note:    A simple short variable cannot be passed by address,
  2055.     i.e.  gosub *ABC(&A%) is not allowed.
  2056.     An array can be passed by address,
  2057.     i.e.  gosub *ABC(&A()) is allowed,
  2058.     but a member of an array cannot be passed by address,
  2059.     i.e.  gosub *ABC(&A(1)) is not allowed.
  2060.     An array can be passed by value also.
  2061.     i.e. gosub *ABC(A()) passes all the members by value.
  2062.  
  2063. ~~GOTO
  2064. GOTO line_number or label
  2065.     Goes to the specified line.
  2066.  
  2067. ~~HEX
  2068. HEX(n)
  2069.     Hexadecimal conversion of n.
  2070. Note:    Converts the internal expresson of n to a string. If
  2071.     n is an integer or a decimal, the string begins with
  2072.     highest byte. Otherwise, it begins with lowest byte.
  2073.     Take care with rationals and complex numbers, since one
  2074.     byte has 2 digits and there is no separator between
  2075.     bytes.
  2076. Ex:    print hex(65534)    result:fffe
  2077.     print hex("abc")    result:616263
  2078. Note:    The format of a hexadecimal expression is not '&h..'
  2079.     but '0x..'.
  2080.  
  2081. ~~IF
  2082. IF
  2083.     1)IF expression THEN statements [ENDIF]
  2084.     If the value of the expression is not zero, then the
  2085.     statements after THEN are executed.
  2086.  
  2087.     2)IF expression THEN statements ELSE statements [ENDIF]
  2088.     If the value of the expression is not zero, then the
  2089.     statements after THEN are executed; otherwise the
  2090.     statements after ELSE are executed.
  2091.  
  2092.     3)IF expression THEN statements ELSEIF expression THEN
  2093.     statements  ELSEIF ...    ... ELSE statements [ENDIF]
  2094.     This form is used for multiple branching.
  2095.     The expressions are evaluated in order and the
  2096.     statements after THEN after the first nonzero
  2097.     expression are executed.
  2098.     When all the expressions are zero, the statements after
  2099.     ELSE are executed.
  2100.  
  2101. Note:    ENDIF may be omitted if the next line is not
  2102.     a continuation.  ELSE and ENDIF correspond to the
  2103.     nearest IF before them.
  2104.     A ":" between statements can be omitted before and after
  2105.     IF, THEN, ELSEIF, ELSE, and ENDIF.
  2106.  
  2107.     Continuation of a line:
  2108.     The statements can be written in multiple lines.
  2109.     A line beginning with a colon (:) is a continuation of
  2110.     the previous line.
  2111.  
  2112.     Thus, the program portion
  2113.  
  2114.         10    if A<>1 then *ABC
  2115.         20    B=1:BB=10
  2116.         30    C=11:CC=110
  2117.         40    *ABC
  2118.  
  2119.     is equivalent to
  2120.  
  2121.         10    if A=1 then
  2122.         20      :B=1:BB=10
  2123.         30      :C=11:CC=110
  2124.  
  2125.     Note that statements after REM (or ' ) may be regarded
  2126.     differently.  In the following line, "B=1" is not
  2127.     executed as it is regarded as a comment:
  2128.         10    A=1:'TEST:B=1
  2129.  
  2130.     But in the following lines, "B=1" is executed:
  2131.         10    A=1:'TEST
  2132.         20    :B=1
  2133.  
  2134.     The ENDIF in
  2135.  
  2136.         10    if A then B else C: D endif
  2137.  
  2138.     may be omitted, but not in
  2139.  
  2140.         10    if A then B else C endif D
  2141.  
  2142.     which is equivalent to
  2143.  
  2144.         10    if A then B else C
  2145.         20    D
  2146.  
  2147.     "If then else" may be nested.  The line
  2148.  
  2149.         10    if A then if D then E else F: C
  2150.  
  2151.     is equivalent to
  2152.  
  2153.         10    if A then
  2154.         20    :if D then E else F
  2155.         30    :C
  2156.  
  2157.     whereas the line
  2158.  
  2159.         10    if A then if D then E else F endif C
  2160.  
  2161.     is equivalent to
  2162.  
  2163.         10    if A then
  2164.         20    :if D then E else F endif
  2165.         30    :C
  2166.  
  2167.     Multiple IF:
  2168.         10    if A then B:C
  2169.     If you want to replace B by the construction "if D then
  2170.     E else F", do not simply insert it thus:
  2171.         10    if A then if D then E else F:C
  2172.     because C would then be regarded as a continuation of
  2173.     the ELSE statement F and would be executed only when A
  2174.     is nonzero and D is zero.    So in this example ENDIF,
  2175.     which was omitted in the original line, must be
  2176.     restored in this way:-
  2177.  
  2178.         10    if A then if D then E else F endif C
  2179.  
  2180.     The line continuation (:) makes the above complicated
  2181.     line plain:
  2182.  
  2183.         10    if A then
  2184.         20    :if D then E else F endif
  2185.         30    :C
  2186.  
  2187.     The following lines have a different meaning, as
  2188.     mentioned above:
  2189.  
  2190.         10    if A then
  2191.         20    :if D then E else F
  2192.         30    :C
  2193.  
  2194.     Multiple branching:
  2195.     Multiple branching is realized by continuation of lines
  2196.     and ELSEIF.
  2197.  
  2198.         10    input A
  2199.         20    if A<=10 then print 1
  2200.         30    :elseif A<=20 then print 2
  2201.         40    :elseif A<=30 then print 3
  2202.         50    :elseif A<=40 then print 4
  2203.         60    :else print 5
  2204.  
  2205.     displays 1, 2, 3, 4 when A<=10, 10<A<=20, 20<A<=30,
  2206.     30<A<=40 respectively. It displays 5 otherwise.
  2207.  
  2208.     Note the following case in which another IF is used in
  2209.     a branch.
  2210.  
  2211.     If "print 2" in the above list is replaced by
  2212.     "if A=25 then print 2.5 else print 2", line 30 becomes
  2213.     like this:
  2214.  
  2215.         30    :elseif A<=20 then if A=25 then print 2.5
  2216.             else print 2 endif
  2217.  
  2218.     Note that ENDIF must not be omitted.  IF - ENDIF should
  2219.     be regarded as one block separate from other IF
  2220.     statements.
  2221.  
  2222.     However it may be proper to arrange it like this:
  2223.  
  2224.         30    :elseif A<=20 then
  2225.         35    :if A=25 then print 2.5 else print 2 endif
  2226.  
  2227.     or like this:
  2228.  
  2229.         30    :elseif A<=20 then
  2230.         32    :if A=25 then print 2.5
  2231.         34    :else print 2
  2232.         36    :endif
  2233.  
  2234.     The difference between ELSEIF and ELSE IF:
  2235.  
  2236.         if a=1 then x=80 elseif a=2 then x=90 else x=100
  2237.  
  2238.     is equivalent to
  2239.  
  2240.         if a=1 then x=80 else if a=2 then x=90 else x=100
  2241.  
  2242.     But when ENDIF is needed in relation to another IF
  2243.     statement, a difference of structure appears.
  2244.  
  2245.     In the first case, you just add it at the end:
  2246.  
  2247.         if a=1 then x=80 elseif a=2 then x=90 else x=100
  2248.         endif
  2249.  
  2250.     In the second case, as there are two statements put
  2251.     together, ENDIF is needed for each of the statement:
  2252.  
  2253.         if a=1 then x=80 else if a=2 then x=90 else x=100
  2254.         endif endif
  2255.  
  2256.     ELSE can end an IF statement.  For example:
  2257.  
  2258.         if A then if B then C else D else E
  2259.  
  2260.     In this case, the "if B" statement ends before
  2261.     "else E".
  2262.  
  2263.     The use of ENDIF as in the following line is
  2264.     preferable:
  2265.  
  2266.         if A then if B then C else D endif else E
  2267.  
  2268. ~~IM
  2269. IM(x)
  2270.     Imaginary part of x.
  2271. Inp:    number.
  2272. Out:    number.
  2273. Ex:    print im(123+456#i)    result: 456
  2274. See:    CONJ, RE.
  2275.  
  2276. ~~INC
  2277. INC variable1 [,variable2,... ]
  2278.     Increments the variables.  "INC A" is faster than "A = A + 1".
  2279.     The current value of the variable must be an integer.
  2280. Ex:    A=100:inc A:print A    result: 101
  2281. See:    CLR, DEC, NEG.
  2282.  
  2283. ~~INKEY
  2284. INKEY
  2285.     Checks keyboard buffer.
  2286. Note:    Character in the keyboard buffer if there is any, null
  2287.     string otherwise.
  2288. Out:    character.
  2289. Ex:    10    while not inkey
  2290.     20      gosub 100
  2291.     30    wend
  2292.         repeats the subroutine beginning at line 100 until
  2293.     any key is pressed.
  2294.  
  2295. ~~INP
  2296. INP(port#)
  2297.     Inputs from the input port specified by port#.
  2298. Inp:    integer.
  2299. Out:    integer.
  2300. See:    OUT.
  2301.  
  2302. ~~INPUT
  2303. INPUT
  2304. 1) INPUT ["prompt";] variable1 [, variable2, ... ]
  2305.     Waits for a number or an expression and assigns its
  2306.     value to the variable.  If more than one variable is
  2307.     specified, separate the input numbers/expressions by
  2308.     commas.
  2309. Note:    UBASIC looks for the first "?" on the cursor line
  2310.     and takes everything after it as input.  UBASIC
  2311.     supplies a prompting "?", so do not include one in
  2312.     your "prompt".  You can input anything on screen by
  2313.     moving the cursor to it and preceding it by a "?".
  2314.     Input is passed through the UBASIC interpreter, so
  2315.     it can include formulae and variable names.
  2316. Ex:    10    input "Enter a number:";A
  2317.     20    print A
  2318. See:    STRINPUT.
  2319.  
  2320. 2) INPUT = "filename"
  2321.     Redirects the input to the specified ASCII file.
  2322.     Characters other than numerals and periods are
  2323.     interpreted as delimiters.  Note that UBASIC adds an
  2324.     extension of ".UBD".  The DIR and KILL commands require
  2325.     this extension explicitly.
  2326.     INPUT = INPUT cancels the redirection.
  2327.  
  2328. 3) open "filename" for INPUT as #n
  2329. See:    OPEN.
  2330.  
  2331. ~~INPUT$
  2332. INPUT$(n)
  2333.     Waits for n keystrokes, then returns them as a string.
  2334. Note:    If n > 0 , the cursor is displayed.
  2335.     If n < 0 , the cursor is not displayed.
  2336. Inp:    integer.
  2337. Out:    string.
  2338. Ex:    10    A=input$(-1)
  2339.         waits for a keystroke without displaying the cursor.
  2340. Note:    Note that "$" is needed, unlike other string functions
  2341.     in UBASIC.
  2342.     This function repeats the function 0ch(7) of MS-DOS
  2343.     INT21H.
  2344.  
  2345. ~~INPUT #
  2346. INPUT #n, var1 [,var2,...]
  2347.     Reads the  value(s) of the variable(s) from file #n (n = 1
  2348.     , 2, ...).
  2349. Note:    Multiple values can be read with one INPUT # statement.
  2350.     Variables must be marked off with ",".
  2351. See:    CLOSE, EOF, OPEN.
  2352.  
  2353. ~~INSTR
  2354. INSTR([n],string1,string2)
  2355.     Scans string1 starting from n-th character of string1 for
  2356.     the occurence of string2 and returns the location of the
  2357.     first character of string2.
  2358.     Returns 0 if string2 does not occur.
  2359. Inp:    n is an integer.
  2360. Out:    integer.
  2361. Ex:    print instr("abcbcacab","ca")    result: 5
  2362. See:    INSTR2.
  2363.  
  2364. ~~INSTR2
  2365. INSTR2([n],string1,string2)
  2366.     Scans string1 starting from n-th character of string1 for
  2367.     the first occurence of any character contained IN string2
  2368.     and returns the location of the character.  Returns 0 if
  2369.     none of the characters occur.
  2370. Inp:    n is an integer.
  2371. Out:    integer.
  2372. Ex:    print instr2("abcbcacab","ca")    result: 1
  2373. See:    INSTR.
  2374.  
  2375. ~~INT
  2376. INT(x)
  2377.     The greatest integer not exceeding x.
  2378. Inp:    integer, real, rational.
  2379. Out:    integer.
  2380. Ex:    INT(12345/100) = 123,INT(-12345/100) = -124.
  2381. See:    FIX(x) and ROUND(x).
  2382.  
  2383. ~~IRND
  2384. IRND
  2385.     Integer valued random number from -32767 to 32767.
  2386. Note:    -32768 does not occur. In return, 0 appears twice as
  2387.     often as others.
  2388. Out:    integer i (-32767 <= i <= 32767).
  2389. Ex:    10    randomize
  2390.     20    for I=1 to 100
  2391.     30      print irnd;
  2392.     40    next
  2393.         displays 100 integer valued random numbers.
  2394. See:    RANDOMIZE, RND.
  2395.     appendix B for the algorithm.
  2396.  
  2397. ~~ISQRT
  2398. ISQRT(x)
  2399.     Integer part of the square root of x.
  2400. Note:    Returns precisely the largest integer not exceeding the
  2401.     theoretical value.
  2402. Inp:    integer.
  2403. Out:    integer.
  2404. Ex:    print isqrt(10)    result: 3
  2405. See:    SQRT.
  2406.  
  2407. ~~JUMP
  2408. JUMP
  2409.     Goes to the next "**", as in
  2410.     10    if a=1 then jump
  2411.     20    b=1
  2412.     30 **: c=1
  2413.  
  2414. Note:    It is easy to find where to jump unlike GOTO.
  2415.  
  2416. ~~KEY
  2417. KEY key_number,string
  2418.     Modifies the settings of function keys, etc.
  2419.     Key number is as follows:
  2420.     1  - 10 f1 - f10
  2421. Ex:    key 1,"run "+chr(0x22)+"pi"+chr(0x22)+chr(0x0d)
  2422.         assigns 'run "pi"<cr>' to function key #1.
  2423.  
  2424. ~~KILL
  2425. KILL "filename"
  2426.     Kills a program or a data file.  In the latter case, append
  2427.     a + just after the filename.
  2428. Note:    If the filename is without extension, the file is
  2429.     regarded as a program with ".UB".
  2430.     If "+" is added in place of extension, the file is
  2431.     regarded as data with ".UBD".
  2432.     To specify a file without extension, add "." to the
  2433.     filename.
  2434. See:    SET.
  2435.  
  2436. ~~KRO
  2437. KRO(m,n)
  2438.     Extended Kronecker's symbol for m and n.  Equivalent to
  2439.     Legendre's symbol (for quadratic residue) for odd prime n:-
  2440.     That is, 1 if m is quadratic residue modulo n, -1 if m is
  2441.     a non-quadratic residue, 0 if m can be divided by n.
  2442.     Also equivalent to Jacobi's symbol for odd composite n.
  2443.  
  2444. Inp:    integer.
  2445. Out:    integer (0, 1, or -1).
  2446. Ex:    print kro(3,5)    result:-1.
  2447.  
  2448.  
  2449. ~~LCOEFF
  2450. LCOEFF(polynomial)
  2451.     Coefficient of the term of highest degree of polynomial.
  2452. Ex:    A=poly(1,3,5):print lcoeff(A)    result: 5
  2453. See:    CCOEFF, COEFF.
  2454.  
  2455. ~~LDIR
  2456. LDIR "pathname"
  2457.     Outputs a list of files to the printer.
  2458.     Usually the pathname is simply the drive name (a:, b:,
  2459.     etc.).
  2460.     A wild card is allowed.
  2461. See:    the MS-DOS manual for detailed information.
  2462.     DIR.
  2463.  
  2464. ~~LEFT
  2465. LEFT(string[,n])
  2466.     n characters at the left end of a string.
  2467.     It returns one character when n is not given.
  2468. Ex:    print left("abcdefgh",3)    result:abc
  2469. See:    MID, RIGHT.
  2470.  
  2471. LEFT(packet[,n])
  2472.     The packet which contains the n members at the left end of
  2473.     the specified packet.
  2474. Note:    It returns a packet with one member when n is not given.
  2475.     Use MEMBER to get a member itself.
  2476. Ex:    print left(pack(1,2,3,4,5),3)    result:( 1, 2, 3)
  2477. See:    MEMBER, MID, RIGHT, PACK.
  2478.  
  2479. ~~LEN
  2480. LEN(x)
  2481.     Bit length of x.  LEN(0) = 0, LEN(1) = 1, LEN(5) = 3,
  2482. Note:    It returns byte length when argument is a string,
  2483.     number of data when argument is a packet, and number of
  2484.     terms (degree+1) when argument is a polynomial.
  2485. Inp:    any data.
  2486. Out:    integer.
  2487. Ex:    len(0)=0, len(1)=1, len(5)=3, len(65535)=16,
  2488.     len(65536)=17, len("abc")=3
  2489.     A=pack(1,2,3):print len(A)    result: 3
  2490.     A=poly(1,2,3):print len(A)    result: 3 (note deg(A)=2).
  2491.  
  2492. ~~LIST
  2493. LIST [linenumber1 or label1] [ - linenumber2 or label2]
  2494.     Displays the specified portion of the current program.
  2495.     To halt, press Control-S.  To quit, press Control-C.
  2496. Note:    To edit a program, EDIT, <ROLL_UP> and <ROLL_DOWN> are
  2497.     recommended.
  2498. See:    EDIT.
  2499.  
  2500. ~~LLIST
  2501. LLIST [linenumber1 or label1] [ - linenumber2 or label2]
  2502.     Same as LIST, but outputs to both the printer and the
  2503.     screen.
  2504. Note:    To halt, press Control-S.  To quit, press Control-C.
  2505.     Note that a printer with a buffer does not stop at
  2506.     once.
  2507.  
  2508. ~~LLOCATE
  2509. LLOCATE n
  2510.     Sends a carriage return (but not line feed) and n blanks to
  2511.     the printer.
  2512. See:    LOCATE.
  2513.  
  2514. ~~LOAD
  2515. LOAD "program_name"
  2516.     Reads the program into memory.  LOADing a programs from
  2517.     standard (ASCII) text files is slower because they need to
  2518.     be converted to the internal code.
  2519.     If you do not give the program_name, the list of programs
  2520.     is displayed so that you may select a program using the
  2521.     arrow keys and
  2522.     and <ENTER>.  (hit <ESC> to quit)
  2523. See:    APPEND, SAVE.
  2524.  
  2525. ~~LOCAL
  2526. LOCAL variable1[=value],variable2[=value], ...
  2527.     Defines local variables and initializes them (default = 0).
  2528. Note:    Local variables must be defined just after the
  2529.     subroutine/function definition.
  2530.     Variables defined by LOCAL are valid until the
  2531.     subroutine/function RETURNs.  They are distinguished
  2532.     from variables of the same name in the main program.
  2533.     Local variables are initialized to zero if the value is
  2534.     not specified.
  2535.     Do not LOCAL the arguments of the subroutine/function,
  2536.     since arguments are automatically defined as local
  2537.     variables.
  2538.         100    fnABC(X,Y,Z)
  2539.         110    local I,J,K,Z
  2540.     sets to 0  the value of Z passed by the main program.
  2541. Ex:     10    for I=1 to 10
  2542.      20      gosub *ABC(I)
  2543.      30     next
  2544.      40     end
  2545.     100     *ABC(X)
  2546.     110      local I    :' This 'I' is not the 'I' in the main
  2547.                 routine.
  2548.     120      for I=1 to X
  2549.     130        print X;
  2550.     140      next
  2551.     150      print
  2552.     160    return
  2553.  
  2554.     The variable I is used in both the main routine and the
  2555.     subroutine.
  2556.     The value assigned by LOCAL in line 110 does not affect
  2557.     the value of I in the main routine.
  2558. Note:    Variables already passed by address using "&" cannot be
  2559.     initialized by LOCAL.
  2560.  
  2561. ~~LOCATE
  2562. LOCATE x, y
  2563. LOCATE x
  2564. LOCATE , y
  2565.     Specifies the cursor position on the screen.
  2566. Note:    Locate X changes the x-coordinate.  The y-coordinate
  2567.     remains as it was.
  2568.     Locate ,Y changes the y-coordinate.  The x-coordinate
  2569.     remains as it was.
  2570. See:    LLOCATE.
  2571.  
  2572. ~~LOG
  2573. LOG(x)
  2574.     Natural logarithm of x.
  2575. Inp:    number.
  2576. Out:    real, complex number.
  2577. Ex:    print log(1.23)    result: 0.2070...
  2578. See:    appendix B for the algorithm.
  2579.  
  2580. ~~LOOP
  2581. LOOP - ENDLOOP
  2582.     Constructs an infinite loop.
  2583. Note:    You may jump out of the loop using GOTO.
  2584. Ex:    10    loop
  2585.     20    ...
  2586.     30    ...
  2587.     40    endloop
  2588.  
  2589.     is equivalent to:
  2590.  
  2591.     10    '
  2592.     20    ...
  2593.     30    ...
  2594.     40    goto 10
  2595.  
  2596.     However, the loop structure is emphasized in the former
  2597.     case.
  2598. See:    ENDLOOP.
  2599.  
  2600. ~~LOWER
  2601. LOWER(string)
  2602.     Translates characters to lowercase.
  2603. Inp:    string.
  2604. Out:    string.
  2605. Ex:    print lower("BecauseIt'sTime.")
  2606.         result:becauseit'stime.
  2607. See:    UPPER.
  2608.  
  2609. ~~LPRINT
  2610. LPRINT
  2611. 1) LPRINT expression
  2612.     LPRINT USING(x, y), expression
  2613.     LPRINT "string"
  2614.     LPRINT CHR(n)
  2615.     Outputs to the printer.
  2616. Note:    Multiple expressions can be output with one LPRINT
  2617.     statement.
  2618.     Expressions must be marked off with ";" or ",".
  2619.     "LPRINT A;B" prints the values without spaces in
  2620.     between.
  2621.     "LPRINT A,B" prints the value of B on the next
  2622.     8-character field.
  2623. See:    LLOCATE, ALEN, USING.
  2624. Note:    LPRINT may not function when the use of print.sys is 
  2625.     not declared in config.sys in MS-DOS version 3.1 and 
  2626.     later versions.
  2627.     Place the "print.sys" in the system disket of MS-DOS 
  2628.     and add the "config.sys" the following line (See MS-DOS
  2629.     manual for details.):
  2630.     device = print.sys
  2631. See:    MS-DOS manual for details.
  2632.  
  2633.  
  2634. 2) LPRINT = PRINT + LPRINT + "filename.UBD"
  2635.      Redirects the outputs of LPRINT statements to the
  2636.      screen (PRINT), the printer (LPRINT), a file
  2637.      ("filename.UBD"), or any combination of these.  No
  2638.      more than one file is allowed on the right-hand side.
  2639.      The file must be distinct from the one specified by
  2640.      the "PRINT = ..." construct.  The extension ".UBD" is
  2641.      needed by UBASIC's DIR and KILL commands.
  2642.      The outputs are redirected to NULL if nothing is on
  2643.      the right-hand side.
  2644.  
  2645. ~~LVLIST
  2646. LVLIST [line_number1 or label1][-line_number2 or label2]
  2647.     Outputs to the printer the list of variables used in the
  2648.     program.
  2649. See:    VLIST.
  2650.  
  2651. ~~LVXREF
  2652. LVXREF [variable]
  2653.     Outputs to the printer the cross-reference list for all (or
  2654.     the specified) varialbes.  Array names must be followed by
  2655.     a (.
  2656. See:    VXREF.
  2657.  
  2658. ~~LXREF
  2659. LXREF [line_number or label_1] [-line_number or label_2]
  2660.     Displays/prints the line numbers of the lines that
  2661.     reference the specified lines. Press Control-S to halt,
  2662.     Control-C to quit.
  2663. Note:    If line_number or label is not specified, all the line
  2664.     numbers and labels are regarded as the arguments.
  2665. See:    XREF.
  2666.  
  2667. ~~MAX
  2668. MAX(arg1,arg2,...)
  2669.     Returns the largest of the arguments.
  2670. Ex:    print max(1,3,2)    result: 3
  2671.     print max("d","abc","ef")    result:ef
  2672.         In string comparisons, the ASCII codes of the
  2673.     characters are compared in order.
  2674. See:    MIN.
  2675.  
  2676. ~~MELT
  2677. MELT ["filename"]
  2678.     Melts a FREEZEd program.
  2679. Note:    Filename should not have an extension as ".ICE" is 
  2680.     automatically added.
  2681.     If no filename is given, "UB.ICE" in the current 
  2682.     directory is used.
  2683.     The MELTed program cannot be CONTinued after a fatal
  2684.     error has occurred.  In that case, MELT it once again.
  2685.     Results are unpredictable if a file is modified after
  2686.     FREEZing the program in which it is OPENed.
  2687. See:    FREEZE.
  2688.  
  2689. ~~MEMBER
  2690. MEMBER
  2691.  
  2692. 1) MEMBER(string,n)
  2693.     n-th member of the specified string.
  2694.     The members of the string are marked off by "," or a
  2695.     space.  However, ","s or spaces between () are
  2696.     neglected.
  2697. Ex:    A="123,abcdefg,mid(B,1,2)"
  2698.     print member(A,1)    result:123
  2699.     print member(A,2)    result:abcdefg
  2700.     print member(A,3)    result:mid(B,1,2)
  2701. Note:    Use CUTSPC to delete the spaces if you do not want
  2702.     them to be regarded as delimiters.
  2703.     The return value is a string.  Use VAL to convert
  2704.     it to a number.
  2705.  
  2706. 2) MEMBER(packet,n)
  2707.     n-th member of the specified packet.
  2708. Ex:    print member(pack(11,22,33,44),3)    result: 33
  2709. See:    PACK.
  2710.  
  2711. 3) MEMBER(packet,n)=expression
  2712.     Replaces the n-th member of the specified packet.
  2713. Note:    If n is more than the current number of members,
  2714.     0 is assigned to the n-th member and all the
  2715.     members between the n-th and current members.
  2716. Ex:    A=pack(11,22,33,44):member(A,3)=55:print member(A,3)
  2717.         result: 55
  2718. See:    PACK.
  2719.  
  2720. ~~MID
  2721. MID
  2722. 1) MID(string,x,n)
  2723.     Substring which starts with the x-th character of the
  2724.     specified string and contains n characters.
  2725. Note:    To specify all the characters starting with the
  2726.     x-th, use "*" as n or specify a larger n than the
  2727.     length of the string.
  2728.     It returns one character if n is not given.
  2729. Ex:    A="abcdefg"
  2730.     print mid(A,2,3)    result:bcd
  2731.     print mid(A,2,100)    result:bcdefg
  2732.     print mid(A,2,*)    result:bcdefg
  2733.     print mid(A,2)        result:b
  2734. See:    LEFT, RIGHT.
  2735.  
  2736. 2) MID(packet,x,n)
  2737.     The portion of the specified packet which starts with
  2738.     the x-th member and contains n members.
  2739. Note:    Returns a packet with one member when n is not
  2740.     given.
  2741.     Use MEMBER to get a member itself.
  2742. Ex:    print mid(pack(11,22,33,44),2,2)    result: ( 22, 33)
  2743. See:    MEMBER, LEFT, RIGHT, PACK.
  2744.  
  2745. 3) MID(String_variable, x, n)=string
  2746.     Replaces n characters starting with the x-th character
  2747.     of the specified string_variable by specified string.
  2748. Note:    If the string is shorter then n characters, the
  2749.     rest of the characters are not replaced.
  2750.     If the string is longer, the rest of the string is
  2751.     neglected.
  2752. Ex:    A="abcdefg":mid(A,3,2)="xy":print A
  2753.         result:abxyefg
  2754. Note:    There is no MID statement which replaces the
  2755.     members of a packet.  Replace them one by one using
  2756.     MEMBER.
  2757.  
  2758. ~~MIN
  2759. MIN(arg1,arg2,...)
  2760.     Returns the smallest of the arguments.
  2761. Ex:    print min(1,3,2)    result: 1
  2762.     print min("d","abc","ef")    result:abc
  2763.         In string comparisons, the ASCII codes of the
  2764.     characters are compared in order.
  2765. See:    MAX.
  2766.  
  2767. ~~MOB
  2768. MOB(n)
  2769. See:    MOEB
  2770.  
  2771. ~~MODPOW
  2772. MODPOW(a,b,n)
  2773.     (a to the b) mod n.  Mod is taken each time a is raised in
  2774.     order not to overflow.  b >= 0, n > 0.
  2775. Note:    If b = 0, it returns 1 neglecting the value of a.
  2776. Inp:    integer (b >= 0, n > 0).
  2777. Out:    integer
  2778. Ex:    print modpow(12,34,56)    result: 16
  2779.  
  2780. ~~MODINV
  2781. MODINV(a,n)
  2782.     Gives x such that a * x mod n = 1,  0 < x < n.
  2783.     It returns 0 if no such x exists, i.e. if a and n are not
  2784.     coprime.
  2785. Inp:    integer (n > 0).
  2786. Out:    integer.
  2787. Ex:    print modinv(23,45)    result: 2
  2788.  
  2789. ~~MODULUS
  2790. MODULUS = expression
  2791.     Sets the modulus (which must be prime, =< 65535) used in
  2792.     the calculation of polynomials.
  2793.  
  2794.     Set modulus = 0 (default value) when calculating normal
  2795.     polynomials (with integral, rational or complex
  2796.     coefficients).
  2797. Note:    UBASIC allows polynomials whose coefficients are
  2798.     integers taken modulo a prime number.
  2799. Ex:    modulus=2:A=5*_X^2+6*_X+7:print A    result: 1*X^2 + 1
  2800. Note:    Do not change the modulus during calculation with
  2801.     polynomials.
  2802.  
  2803. MODULOUS
  2804.     Current value of modulus.
  2805.  
  2806. ~~MOEB
  2807. MOEB(n)
  2808.     Moebius' function.
  2809.     0 if n has a square factor.
  2810.     If n has no square factor, 1 if n has an even number of
  2811.     prime factors, -1 if n has an odd number of prime factors.
  2812. Inp:    integer n (1 <= n <= 65536^2-1 = 4294967295).
  2813. Out:    integer.
  2814. Ex:    print mob(105)    result: -1
  2815.  
  2816. ~~MONIC
  2817. MONIC(polynomial)
  2818.     Monic polynomial obtained by dividing the argument by the
  2819.     coefficient of the highest degree.
  2820. Ex:    A=2*_x+1:print monic(A)
  2821.         result:    X + 1//2    if modulus = 0
  2822.             X + 2        if modulus = 3
  2823.             X + 3        if modulus = 5.
  2824.  
  2825. ~~NEG
  2826. NEG variable1 [,variable2,... ]
  2827.     "NEG A" is equivalent to "A = -A", but faster.
  2828. Ex:    neg A,B,C
  2829.         changes signs of A, B, C.
  2830. See:    CLR, DEC, INC.
  2831.  
  2832. NEG BLOCK array(index,index...)
  2833.     Changes the signs of the specified array members.
  2834. Ex:    neg block A(0..10)
  2835.         changes signs of the members from A(0) to A(10)
  2836.     neg block A(2,1..2)
  2837.         changes signs of A(2,1) and A(2,2)
  2838. See:    BLOCK for details.
  2839.  
  2840. ~~NEW
  2841. NEW
  2842.     Deletes the current program and variables.
  2843. Note:    A program NEWed by mistake can be REVIVEd.
  2844. See:    REVIVE.
  2845.  
  2846. ~~NOP
  2847. NOP
  2848.     No operation.  When the TRON command does not function
  2849.     properly (e.g. in the case of multi-statements), put an NOP
  2850.     just before the statement to be traced.
  2851. See:    TRON, TROFF.
  2852.  
  2853. ~~NOT
  2854. NOT
  2855.     IF NOT
  2856.     WHILE NOT
  2857.     UNTIL NOT
  2858.     Changes logical values.
  2859. Note:    This is to emphasize "If .... is not true".
  2860. Ex:    while not eof(1)
  2861.       input #1,A:print A
  2862.     wend
  2863.  
  2864.         is easier to understand than:
  2865.  
  2866.     while eof(1)=0
  2867.       input #1,A:print A
  2868.     wend
  2869.  
  2870. ~~NUM
  2871. NUM(argument)
  2872.     Numerator of the argument.
  2873. Inp:    integer, rational.
  2874. Ex:    print num(2//3)    result: 2
  2875. See:    DEN.
  2876.  
  2877. ~~NXTPRM
  2878. NXTPRM(x)
  2879.     The smallest prime greater than x.  It returns 0 if either
  2880.     x < 0 or the result is greater than 2 to the 32nd.  x may
  2881.     be a noninteger.
  2882. Inp:    integer, real.
  2883. Out:    integer.
  2884. Ex:    print nxtprm(123.45)    result: 127
  2885.  
  2886. ~~NEXT
  2887. NEXT
  2888. See:    FOR.
  2889.  
  2890. ~~ODD
  2891. ODD(x)
  2892.     1 if x is odd, 0 if even.  x must be an integer.
  2893. Inp:    integer.
  2894. Out:    integer (0 or 1).
  2895. Ex:    print odd(10),odd(11)    result: 0    1
  2896. See:    EVEN.
  2897.  
  2898. ~~ON
  2899. ON
  2900. See:    ERROR.
  2901.  
  2902. ~~OPEN
  2903. OPEN
  2904. 1) OPEN "filename" FOR INPUT (or OUTPUT or APPEND) AS #n
  2905.     Opens a sequential data file to be written and read by
  2906.     "PRINT #n, ..." and "INPUT #n, ..." commands,
  2907.     where n = 1, 2, 3, 4.
  2908.     Do not add a + after the filename.  If the POINT value
  2909.     is changed after the file was written, truncating or
  2910.     padding with zeros can occur.
  2911.     If the file specified in "OPEN...FOR APPEND" is not
  2912.     found, a new file named "file_name" is created.
  2913. Note:    10 files (#1 ... #10) can be OPENed at the same
  2914.     time.  When you cannot open 10 files, increase the
  2915.     number of open files declared in "config.sys".
  2916.     "files = 20" is recommended.
  2917.     Filename does not contain an extension.  Do not add
  2918.     "+" to the filename even if it is a data file.
  2919. See:    CLOSE, EOF, INPUT #, PRINT #.
  2920.  
  2921. 2) OPEN "filename(with extension)" FOR INPUT (or OUTPUT or
  2922. APPEND) AS #n
  2923.     Opens a file in text-file form(=ASCII form).
  2924. Note:    10 files can be OPENed at the same time.
  2925.     Add "." to specify a filename without extension.
  2926. See:    CLOSE, EOF, INPUT #, PRINT #.
  2927.  
  2928. 3) OPEN "filename" AS FILEn(m1) [WORD m2]
  2929.     Uses files as an external array, where n = 1, 2, 3.
  2930.     The upper bound for the array index, m1, may be greater
  2931.     than 65535.  The word size of each array element is
  2932.     m2 (or 8 if not specified).  Protected files can be
  2933.     read, but not written.
  2934.  
  2935. Ex:    open "filename" as file1(n) [word x]
  2936.         makes a new file.
  2937.     open "filename" as file1
  2938.         opens an existing file.
  2939. Note:    Filename does not contain an extension as ".ubd" is
  2940.     automatically added.
  2941. See:    CLOSE.
  2942.     "External arrays" for details.
  2943.  
  2944. ~~OR
  2945. OR{expression1,expression2,...}
  2946.     0 if all the expressions are zero, 1 otherwise.
  2947.     If one of the argument is nonzero, it returns 1 at once
  2948.     without evaluating the following expressions.
  2949. Inp:    expressions.
  2950. Out:    integer (0 or 1).
  2951. Ex:    if or{A,B,...} then
  2952.  
  2953.     When the expressions between {} are long,
  2954.     continuation of lines (:) is allowed as follows:
  2955.  
  2956.     if or{A,
  2957.       :B,
  2958.       :...}
  2959.     :then
  2960.  
  2961. ~~OUT
  2962. OUT port#,expression
  2963.     Outputs a value to the specified port.
  2964.  
  2965. ~~PACK
  2966. PACK(arg1,arg2,...)
  2967.     Makes data a packet.
  2968. Note:    It assigns multiple data to a variable.
  2969.     Use MEMBER to get a member of a packet.
  2970. Ex:    A=pack(1,2,3):print A    result: ( 1, 2, 3)
  2971. See:    MEMBER, LEFT, MID, RIGHT.
  2972.  
  2973. ~~PEEK
  2974. PEEK(address)
  2975.     The byte at the specified address.
  2976. Note:    Segment must be specified by DEFSEG.
  2977. See:    DEFSEG, PEEKW, PEEKS, POKE, VARPTR.
  2978.  
  2979. ~~PEEKW
  2980. PEEKW(address)
  2981.     The word at the specified address.
  2982. Note:    Segment must be specified by DEFSEG.
  2983. See:    DEFSEG, PEEK, PEEKS, POKEW, VARPTR.
  2984.  
  2985. ~~PEEKS
  2986. PEEKS(address,n)
  2987.     n bytes at the specified address.
  2988. Note:    Segment must be specified by DEFSEG.
  2989. Out:    string.
  2990. See:    DEFSEG, PEEK, PEEKW, POKES, VARPTR.
  2991.  
  2992. ~~PI
  2993. PI(x)
  2994.     PI times x.  This is more precise for large x.
  2995.     ex. 10000*#pi contains an error in the least significant
  2996.     4 digits, but pi(10000) does not.
  2997.     The precision depends on the current value of POINT.
  2998.     (maximum:541 words)
  2999. Inp:    number.
  3000. Out:    real, complex number.
  3001. Ex:    print pi(100)    result: 314.1592...
  3002. See:    #pi.
  3003.  
  3004. ~~POINT
  3005. POINT expression
  3006. POINT *
  3007.     Specifies the number of words, n (= 2, 3, ..., 525), for
  3008.     the decimal part of the variables.  One word is about 4.8
  3009.     decimal places;  100 decimal places are 21 words;
  3010.     1000 decimal places are 208 words.  "POINT *" sets the
  3011.     largest allowed value.  When multiplications, divisions, or
  3012.     function calls are involved, n must be no more than 260,
  3013.     otherwise overflow can occur.  When complex numbers are
  3014.     involved, n must be no more than 130.
  3015.     This statement closes all the files, so it must be placed
  3016.     at the beginning of the program.  Do not use this statement
  3017.     inside a subroutine or a function, or when variables are
  3018.     already assigned non-integer values.
  3019.     No message is displayed if negative n is specified.
  3020.     PRINT POINT displays the current POINT value.
  3021.  
  3022. ~~POKE
  3023. POKE address,expression
  3024.     Stores a byte value at the specified address.
  3025. Note:    The segment must be specified by DEFSEG.
  3026. See:    DEFSEG, PEEK, POKEW, POKES, VARPTR.
  3027.  
  3028. ~~POKEW
  3029. POKEW address,expression
  3030.     Stores a word value at the specified address.
  3031. Note:    The segment must be specified by DEFSEG.
  3032. See:    DEFSEG, PEEK, POKEW, POKES, VARPTR.
  3033.  
  3034. ~~POKES
  3035. POKES address,string
  3036.     Stores a string at the specified address.
  3037. Note:    The segment must be specified by DEFSEG.
  3038. Ex:    defseg=0x8000:A="ABC":pokes 0,A
  3039.         stores 0x41,0x42,0x43 at the addresses 8000:0001,
  3040.     0002,0003, respectively, where '0x...' indicates a
  3041.     hexadecimal number.
  3042. See:    DEFSEG, PEEK, POKEW, POKES, VARPTR.
  3043.  
  3044. ~~POLY
  3045. POLY(coeff0,coeff1,coeff2,...)
  3046.     A polynomial with the arguments as coefficients.
  3047. Ex:    A=poly(1,2,3):print A    result: 3*X^2 + 2*X + 1
  3048. See:    COEFF.
  3049.  
  3050. ~~POSX
  3051. POSX
  3052.     The x-coordinate of the current cursor position.
  3053.     (0 <= POSX <= 79)
  3054. Ex:    locate posx-1
  3055.         moves the cursor 1 column to the left.
  3056.  
  3057. ~~POSY
  3058. POSY
  3059.     The y-coordinate of the current cursor position.
  3060.     (0 <= POSY <= 24)
  3061. Ex:    locate posy-1
  3062.         moves the cursor up 1 line.
  3063.  
  3064. ~~PRINT
  3065. PRINT expression or "string" or CHR(n) or etc.
  3066.     Outputs the value of the expression, the string, the
  3067.     character whose ASCII code is n, or the current time to the
  3068.     screen. "PRINT A;B" prints the values without spaces in
  3069.     between.  "PRINT A,B" prints the value of B on the next
  3070.     8-character field.  Press Control-S for halt/restart
  3071.     toggle.
  3072. See:    LOCATE, ALEN, USING.
  3073.  
  3074. PRINT = PRINT + LPRINT + "filename"
  3075.     Redirects the output of PRINT statements.
  3076.     "PRINT = PRINT" cancels the redirection.
  3077. Note:    No more than one file is allowed on the right-hand side.
  3078.     The file must be distinct from the one specified by the
  3079.     "LPRINT = ..." construct.
  3080.     The output is redirected to NUL if nothing is on the
  3081.     right-hand side.
  3082. See:    LPRINT =
  3083.  
  3084. ~~PRINT #
  3085. PRINT #n,expression
  3086.     PRINTs to file #n.
  3087. Note:    Multiple expressions can be output with one PRINT #
  3088.     statement.
  3089.     Expressions must be marked off with ";" or ",".
  3090. See:    OPEN.
  3091.  
  3092. ~~PRM
  3093. PRM(n)
  3094.     n-th prime number.  PRM(12251) is the greatest prime less
  3095.     than (2 to the 17th).
  3096. Inp:    integer n (0 <= n <= 12251).
  3097. Out:    integer.
  3098. Ex:    (prm(0)=1), prm(1)=2, prm(2)=3, ... prm(12251)=131071
  3099.  
  3100. ~~PRMDIV
  3101. PRMDIV(n)
  3102.     The least prime divisor of n.  It returns 0 if no integer
  3103.     smaller than (2 to the 17th) divides n.
  3104. Inp:    integer.
  3105. Out:    integer.
  3106. Ex:    print prmdiv(105)    result: 3
  3107.  
  3108. ~~RANDOMIZE
  3109. RANDOMIZE [n]
  3110.     Initializes the random number generator with n.
  3111.     (0 <= n <= 65535)
  3112. Note:    To get a random number, use RND or IRND.
  3113.     The current time is used if no n is given.
  3114. See:    RND, IRND.
  3115.  
  3116. ~~RE
  3117. RE(x)
  3118.     Real part of x.
  3119. Inp:    number.
  3120. Out:    number.
  3121. Ex:    print re(123+456#i)    result: 123
  3122. See:    CONJ, IM.
  3123.  
  3124. ~~READ
  3125. READ var1 [,var2,...]
  3126.     Reads from the DATA statements.
  3127. Ex:     10    restore 100
  3128.      20    read a,b,c
  3129.      30    print a;b;c
  3130.      40    end
  3131.     100    data 11,22,33
  3132.         result: 11 22 33
  3133. See:    DATA, RESTORE.
  3134.  
  3135. ~~REDUCE
  3136. REDUCE variable1,variable2
  3137.     Divides two integer variables by their greatest common
  3138.     divisor.
  3139. Note:    The numerator and denominator of a rational number can
  3140.     be REDUCEd.
  3141.     Variable2 becomes positive.
  3142. Inp:    integer.
  3143. See:    GCD.
  3144.  
  3145. ~~REM
  3146. REM or '
  3147.     Causes the rest of the line to be ignored.
  3148. Note:    REM can be replaced by "'".
  3149.     Note that a continued line is not ignored.
  3150. Ex:    10    print 1:'test:print 2
  3151.  
  3152.     In the above line "print 2" is not executed.
  3153.     However in the following lines it is executed:
  3154.  
  3155.     10    print 1:'test
  3156.     20    :print 2
  3157.  
  3158. ~~RENAME
  3159. RENAME "old filename" to "new filename"
  3160.     Changes filename.
  3161.     If the extension is not specified, it is regarded as ".UB".
  3162.  
  3163. ~~RENUM
  3164. RENUM [start_of_new_line_numbers] [,start_of_old_line_numbers]
  3165.     Renumbers the lines with increments of 10.  The new line
  3166.     numbers start with 10 if not specified.
  3167.  
  3168. ~~REPEAT
  3169. REPEAT statements UNTIL expression
  3170.     Repeats <statements> until <expression> is nonzero.
  3171. Note:    ":" between REPEAT and statements can be omitted.
  3172.     It can be omitted alsobetween statements and UNTIL.
  3173.     You may jump out of the loop using GOTO.
  3174.  
  3175. ~~RES
  3176. RES
  3177.     Residue (remainder) of the most recent integer division
  3178.     including division of complex numbers with integer
  3179.     components and division of polynomials.
  3180. Note:    Noninteger divisions and function evaluations can
  3181.     destroy RES.
  3182.     Assign it to a variable if you do not use it
  3183.     immediately after the integer division.
  3184.     Evaluation of ISQRT(x) (when x is an integer) sets RES
  3185.     to x - ISQRT(x)^2, which is zero if x is a square
  3186.     number.
  3187. Ex:    A=35:A1=A\10:A0=res
  3188.         assigns 3 to A1 and 5 to A0.
  3189. Out:    integer, complex number, polynomial.
  3190.  
  3191. ~~RESTORE
  3192. RESTORE line_number or label
  3193.     The next READ statement reads from the first DATA
  3194.     statements below the specified line.
  3195. See:    DATA, READ.
  3196.  
  3197. ~~RESTORE #
  3198. RESTORE #n
  3199.     Equivalent to "CLOSE #n: OPEN #n".
  3200. See:    EOF, OPEN.
  3201.  
  3202. ~~RETURN
  3203. RETURN
  3204.     Returns from the subroutine.
  3205. See:    GOSUB.
  3206.  
  3207. ~~RETURN
  3208. RETURN(return_value)
  3209.     Returns from the subroutine with a return value.
  3210. See:    FN.
  3211.  
  3212. ~~REVIVE
  3213. REVIVE
  3214.     Undeletes the program just NEWed.
  3215. See:    NEW.
  3216.  
  3217. ~~RIGHT
  3218. RIGHT(string[,n])
  3219.     n characters at the rignt end of a string.
  3220.     It returns one character when n is not given.
  3221. See:    LEFT, MID.
  3222.  
  3223. ~~RIGHT
  3224. RIGHT(packet[,n])
  3225.     Packet which contains n members at the right end of
  3226.     specified packet.
  3227. Note:    Returns a packet with one member when n is not given.
  3228.     Use MEMBER to get a member itself.
  3229. See:    MEMBER, LEFT, MID, PACK.
  3230.  
  3231. ~~RND
  3232. RND
  3233.     Real-valued random number between 0 and 1.  The precision is
  3234.     determined by the current POINT.  To change the sequence,
  3235.     use RANDOMIZE.
  3236. Out:    decimal number x (0 <= x < 1).
  3237. Ex:    10    randomize
  3238.     20    for I=1 to 100
  3239.     30      print rnd;
  3240.     40    next
  3241.         displays 100 random numbers.
  3242. See:    RANDOMIZE, IRND.
  3243.     appendix B for the algorithm.
  3244.  
  3245. ~~ROUND
  3246. ROUND(x)
  3247.     Integer nearest to x.
  3248. Inp:    integer, real, rational.
  3249. Out:    integer.
  3250. Ex:    round(1.3)=1,round(-1.7)=-2,round(0.5)=1,round(-0.5)=-1
  3251. See:    FIX, INT.
  3252.  
  3253. ~~RUN
  3254. RUN ["program_name"]
  3255.     [Loads and] runs the program.
  3256.     When a program name is not given, a list of programs is
  3257.     displayed so that you may select a program using arrow keys
  3258.     and <ENTER>.
  3259.  
  3260. ~~SAVE
  3261. SAVE "program_name"
  3262.     Stores the current program on to a disk in intermediate-
  3263.     code form.
  3264. Note:    If no file name is given, the current date and time are
  3265.     used as the program name.
  3266.     Use ASAVE to save a program in text-file form.
  3267. See:    APPEND, ASAVE, LOAD.
  3268.  
  3269. ~~SET
  3270. SET "filename","P"
  3271. SET "filename"," "
  3272.     Sets and resets the write protection flag of the file,
  3273.     respectively.
  3274.     A data file's filename requires a "+" after it.
  3275. Note:    The extension is regarded as ".UB" if not given
  3276.     (".UBD" when "+" is added).
  3277.     To specify a file with no extension, add "." to the
  3278.     filename.
  3279. See:    DIR, KILL.
  3280.  
  3281. ~~SFT
  3282. SFT(x,b)
  3283.     x is shifted left (or right if b < 0) by b bits.
  3284.     SFT(x, 1) = x * 2,  SFT(1, -1) = 0,  SFT(1.0, -1) = 0.5.
  3285. Inp:    x is an integer or a real, b is an integer.
  3286. Out:    same type as x.
  3287. Ex:    print sft(123,1)    result: 246
  3288.     print sft(123.0,1)    result: 246.0
  3289.     print sft(123,-1)    result: 61
  3290.     print sft(123.0,-1)    result: 61.5
  3291.  
  3292. ~~SGN
  3293. SGN(x)
  3294.     1, 0, -1 for x > 0, x = 0, x < 0, respectively.
  3295. Inp:    integer, real, rational.
  3296. Out:    integer (-1, 0, 1).
  3297.  
  3298. ~~SIN
  3299. SIN(x)
  3300.     Sine of x.
  3301. Inp:    number.
  3302. Out:    number.
  3303. Ex:    print sin(1.23)    result: 0.9424...
  3304. See:    COS, TAN.
  3305.     appendix B for the algorithm.
  3306.  
  3307. ~~SINH
  3308. SINH(x)
  3309.     Hyperbolic sine of x.
  3310.     (exp(x)-exp(-x))/2.
  3311. Inp:    number.
  3312. Out:    number.
  3313. Ex:    print sinh(1.23)    result: 1.5644...
  3314. See:    COSH.
  3315.     appendix B for the algorithm.
  3316.  
  3317. ~~SKIP
  3318. SKIP
  3319. See:    TRON
  3320.  
  3321. ~~SPC
  3322. SPC(n)
  3323.     Equivalent to n blanks.  Use with PRINT or LPRINT.
  3324. Inp:    integer.
  3325. Out:    string.
  3326. Ex:    print spc(20);
  3327.         displays 20 blanks.
  3328. See:    LOCATE, LLOCATE, TAB.
  3329.  
  3330. ~~SQRT
  3331. SQRT(x)
  3332.     Square root of x.  SQRT(2) = SQRT(2.0) = 1.4142....
  3333.     If x is not a nonnegative real number then the solution
  3334.     which has nonnegative real part is given.
  3335.     SQRT(4) is 2.0 not 2 (same value but different type).
  3336. Inp:    number.
  3337. Out:    number.
  3338. Ex:    Both sqrt(2) and sqrt(2.0) are 1.4142....
  3339. See:    ISQRT.
  3340.     appendix B for the algorithm.
  3341.  
  3342. ~~STEP
  3343. STEP
  3344. See:    FOR.
  3345.  
  3346. ~~STOP
  3347. STOP
  3348. 1) Stops running.
  3349. Note:    Program halts at a STOP statement.  Control-C also
  3350.     halts the execution.  The execution can be continued by
  3351.     CONT.
  3352.     However, CONT may not work if non-syntax errors have
  3353.     occurred while the program is halted.  Changing the
  3354.     values of variables affects the results after the
  3355.     execution is CONTinued.
  3356.     Be careful alsoabout the value of RES.
  3357.  
  3358. 2) Stops tracing.
  3359. Note:    When STOP is used with TRON, the program halts before
  3360.     the execution of each line.
  3361. See:    TRON.
  3362.  
  3363. ~~STR
  3364. STR(n)
  3365.     Decimal expression of n.
  3366. Inp:    number.
  3367. Out:    string.
  3368. Ex:    A=1+#i:print right(str(A),3)    result:+#i
  3369.  
  3370. ~~STRINPUT
  3371. STRINPUT ["message"] variable
  3372.     Inputs a string from the keyboard to the specified
  3373.     variable.
  3374. Note:    Unlike INPUT, the string must not be put between "".
  3375.     Do not delete the prompt "?".  If it is deleted,
  3376.     add "?" at the beginning of the string.
  3377.     When only <ENTER> is hit, INPUT prompts you to
  3378.     re-enter, but STRINPUT assigns a null string.
  3379. See:    INPUT.
  3380.  
  3381. ~~SWAP
  3382. SWAP var1,var2
  3383.     Swaps the contents of the two variables of the same type.
  3384. Ex:    A=1:B=2:swap A,B:print A;B    result: 2 1
  3385.  
  3386. SWAP BLOCK array1(index, index, ...), [BLOCK] array2(index,
  3387. index, ...)
  3388.     Swaps the contents of the two arrays of the same type.
  3389. Note:    It swaps all the members if the indices are not
  3390.     specifed.
  3391.     The number of specified members must be the same but
  3392.     the composition may vary.
  3393.     If overlapping areas of one array are specified, double
  3394.     exchanging occurs and results are unpredictable.
  3395. Ex:    swap block A(0..9),block B(1..10)
  3396.         swaps A(0) ... A(9) with B(1) ... B(10).
  3397.     swap block A(2,1..3),block B(2..4)
  3398.         swaps A(2,1),A(2,2),A(2,3) with B(2),B(3),B(4).
  3399. See:    BLOCK.
  3400.  
  3401. ~~SYSTEM
  3402. SYSTEM
  3403.     Returns to DOS.
  3404.  
  3405. ~~TAB
  3406. TAB(n)
  3407.     Specifies the column for PRINT and LPRINT.  It is ignored
  3408.     when n is less than the current column position on the
  3409.     screen.
  3410. Note:    It outputs blanks between the current cursor position
  3411.     and the specified x-coordinate.  It just moves the
  3412.     cursor if n is negative.
  3413. Inp:    integer.
  3414. Out:    none.
  3415. See:    LOCATE, LLOCATE.
  3416.  
  3417. ~~TAN
  3418. TAN(x)
  3419.     Tangent of x.
  3420. Inp:    number.
  3421. Out:    number.
  3422. Ex:    print tan(1.23)    result: 2.8198...
  3423. See:    COS, SIN.
  3424.     appendix B for the algorithm.
  3425.  
  3426. ~~THEN
  3427. THEN
  3428. See:    IF.
  3429.  
  3430. ~~TIME
  3431. TIME
  3432.     CLR TIME sets the time to 00:00:00.  PRINT TIME displays
  3433.     the time.
  3434.  
  3435. ~~TO
  3436. TO
  3437. See:    FOR.
  3438.  
  3439. ~~TROFF
  3440. TROFF
  3441.     Cancels TRON.
  3442.     You may restart the program by CONT or TRON.
  3443.  
  3444. ~~TRON
  3445. TRON [STOP] [SKIP]
  3446.     Displays each line number before execution.  If STOP is
  3447.     specified, the line number is displayed, and the program is
  3448.     halted until <Enter> is pressed.  If SKIP is specified,
  3449.     deeper subroutine calls are not traced.
  3450.     TRONs and TROFFs may be specified in the program to debug a
  3451.     portion of the program.  Tracing may be hindered by a GOTO,
  3452.     GOSUB or a preceding FOR, WHILE or REPEAT.  For example,
  3453.     line 20 of the following program may not be traced.
  3454.  
  3455.     10    for I=0 to 10
  3456.     20      print I
  3457.     30    next
  3458.  
  3459.     If line 20 is not traced, rewrite it as
  3460.  
  3461.     20 nop: print I
  3462.  
  3463. Note:    Any statement which does not modify the program may be
  3464.     executed while the program is halted.
  3465.     You may place TRON and TROFF in the middle of the
  3466.     program to check the specified part.
  3467. Ex:    10    gosub *A
  3468.     20    end
  3469.     30    *A
  3470.     40      tron skip
  3471.     50      gosub *B
  3472.     60    return
  3473.     70    *B
  3474.     80      print "now in line 80"
  3475.     90    return
  3476.         result:
  3477.         $    50 now in line 80
  3478.         $    60 $    20
  3479.         OK
  3480.         (*B is not traced.)
  3481.  
  3482. ~~TYPE
  3483. TYPE(argument)
  3484.     Type of the argument.
  3485.     Integer=1, rational=2, real=3, complex number=4, string=5,
  3486.     packet=6, polynomial=7, mod polynomial=8.
  3487. See:    ATTRIB.
  3488.  
  3489. ~~UNTIL
  3490. UNTIL
  3491. See:    REPEAT.
  3492.  
  3493. ~~UPPER
  3494. UPPER(string)
  3495.     Translates characters to uppercase.
  3496. Inp:    string.
  3497. Out:    string.
  3498. Ex:    print upper("This is a pen.")    result:THIS IS A PEN.
  3499. See:    LOWER.
  3500.  
  3501. ~~USEEMA
  3502. USEEMA
  3503.     Declares the use of EMA-arrays.
  3504. Note:    Do not put a space between USE and EMA.
  3505.     This statement must be executed in direct mode.
  3506. See:    EMA-array.
  3507.  
  3508. ~~USING
  3509. USING
  3510.     PRINT USING(x, y), expression
  3511.     LPRINT USING(x, y), expression
  3512.     The parameters x and y specify the numbers of digits for
  3513.     the integer and fractional parts to be output, respectively.
  3514.     The output is rounded.
  3515.     Sign is included in the integer part.
  3516. Ex:    print using(3, 2), 9.999
  3517.         result: 10.00
  3518.     print using(3, 5),1.234567
  3519.         result: 1.23457
  3520. Note:    Do not put a space between "using" and "(", or
  3521.     "using" will be regarded as the name of variable.
  3522.  
  3523. ~~VAL
  3524. VAL(string)
  3525.     Value expressed by the specified string.
  3526. Note:    The argument may be a function or a variable.
  3527.     It is recommended that the string should be ENCODEd
  3528.     when the same string is being specified several times.
  3529. Inp:    string.
  3530. Out:    number, string.
  3531. Ex:    X=2:print val("X+X^2")    result: 6
  3532. See:    DECODE, ENCODE, EVAL.
  3533.  
  3534. VAL(polynomial,x)
  3535.     Value of the polynomial as evaluated for the given x.
  3536. Inp:    x is a number or a polynomial.
  3537. Out:    number, polynomial.
  3538. Ex:    A=poly(0,1,1):print val(A,2)    result: 6
  3539.  
  3540. VAL(modpolynomial,x)
  3541.     Value of the polynomial modulo a prime as evaluated for
  3542.     the given x.
  3543. Inp:    x is an integer.
  3544. Out:    integer.
  3545. Ex:    modulus=5:A=poly(0,1,1):print val(A,2)    result: 1
  3546.  
  3547. ~~VARPTR
  3548. VARPTR(variable)
  3549.     Address of the specified variable.
  3550. Note:    It returns a 32 bit value.  The upper 16 bits are the
  3551.     segment address while the lower 16 bits are the offset
  3552.     address.
  3553. See:    DEFSEG, PEEK, POKE.
  3554.  
  3555. ~~VCHG
  3556. VCHG [start_line_number or label ,] old_var_name to new_var_name
  3557.     Replaces variable or array names from the specified line to
  3558.     the end of the program.
  3559. Note:    Ordinary variables cannot be changed into arrays, or
  3560.     vice versa.
  3561.     Arrays cannot be specified with indices.
  3562.     "vchg ABCD to ABcd" does not change the name as "ABCD"
  3563.     and "Abcd" are regarded as the same.  In this case,
  3564.     execute "vchg ABCD to AAAA" and "vchg AAAA to ABcd" for
  3565.     example.
  3566. Ex:    VCHG A,A#    VCHG A%,B#    VCHG A(),B#()
  3567.         The following usages are invalid:
  3568.     VCHG A,A()  VCHG A(),A    VCHG A(1),B(1)
  3569.  
  3570. ~~VLIST
  3571. VLIST [line_number1 or label1][-line_number2 or label2]
  3572.     Displays/prints the list of variables.
  3573. See:    LVLIST.
  3574.  
  3575. ~~VXREF
  3576. VXREF [variable]
  3577.     Displays/prints the cross-reference list for all (or the
  3578.     specified) variables.  Array names must be followed by a (.
  3579.     APPEND, VLIST, VXREF and VCHG are introduced to facilitate
  3580.     modular coding in the framework of BASIC.  LOAD the first
  3581.     module and APPEND the next.
  3582.     Then use VXREF to see if variable names coincide, in which
  3583.     case use VCHG to change the names.
  3584. See:    LVXREF.
  3585.  
  3586. ~~WEND
  3587. WEND
  3588. See:    WHILE.
  3589.  
  3590. ~~WHILE
  3591. WHILE expression statements WEND
  3592.     Executes <statements> while <expression> is nonzero.
  3593. Note:    You may jump out of the loop using GOTO.
  3594. Ex:    10    A=input$(1)
  3595.     20    while and{A<>"N",A<>"n"}
  3596.     30      print A;
  3597.     40      A=input$(1)
  3598.     50    wend
  3599.         inputs a character from the keyboard and displays it
  3600.     until "N" or "n" is entered.
  3601.  
  3602. ~~WIDTH
  3603. WIDTH 80,number_of_lines
  3604.     Specifies the number of lines displayed in the text screen.
  3605. Note:    The number_of_lines must be 20 or 25.
  3606.     The number of characters in one line is fixed at 80.
  3607.  
  3608. ~~WORD
  3609. WORD expression
  3610. WORD *
  3611.     Specifies the length (in words) of a long variable.
  3612. Note:    The maximum length is 542 words unless the system
  3613.     notifies otherwise (when the memory is scarce).  WORD
  3614.     alsocloses all open files and clears the variables
  3615.     except simple short ones.  WORD does not change
  3616.     execution speed because calculations are always done in
  3617.     542 words.
  3618.     WORD must be placed at the beginning of the program.
  3619.     "WORD *" specifies the maximum length allowed.
  3620.     No message is displayed if a negative value is
  3621.     specified.
  3622.     PRINT WORD displays the current value set by WORD.
  3623.     WORD cannot be used in subroutines/functions.
  3624.  
  3625. open ...  as ... WORD
  3626.     Specifies the length (in words) of a member of an external
  3627.     array.
  3628. See:    OPEN.
  3629.  
  3630. ~~XREF
  3631. XREF [line_number or label_1] [-line_number or label_2]
  3632.     Displays/prints the line numbers of the lines that
  3633.     reference the specified lines (or all the lines).
  3634.     Press Control-S to halt, Control-C to quit.
  3635. See:    LXREF.
  3636.  
  3637. ~~Lesson 1.
  3638. Lesson 1.
  3639.  
  3640.   To display message, write
  3641. print "test"<cr>
  3642.   Here <cr> means 'hit RETURN key'
  3643.   Then it will be displayed that
  3644. test
  3645. OK
  3646.   Next, try a calculation
  3647. print 123*456<cr>
  3648.   will induce
  3649.  56088
  3650. OK
  3651.  
  3652.   Now let's make a program.  The easiest program may be
  3653. 10   print "This is the 1st ptrogram."<cr>
  3654.   It is stored and is waiting for the execution command.
  3655.   Write
  3656. run<cr>
  3657.   then the program will run and it will be displayed that
  3658. This is the 1st program.
  3659. OK
  3660.  
  3661. ~~Lesson 2.
  3662. Lesson 2.
  3663.  
  3664.   We will make a longer program.
  3665.   Compute the sum from 1 to 100.
  3666.  
  3667.    10   Sum=0<cr>
  3668.    20   for I=1 to 100<cr>
  3669.    30     Sum=Sum+I<cr>
  3670.    40   next I<cr>
  3671.    50   print Sum<cr>
  3672.  
  3673.   The 'for' in the line 20 and the 'next' in line 40 are 
  3674. connected and is forcing to repeat the commands between them.
  3675.   Let's write
  3676. run<cr>
  3677.   then it will be appeared that
  3678.  5050
  3679. OK
  3680.  
  3681. ~~Lesson 3.
  3682. Lesson 3.    Big Number Arithmetic
  3683.  
  3684.   Lessons 1 and 2  can be done by any other computer languages.  
  3685. UBASIC can handle very big numbers.  For example, let's compute
  3686.  the product from 1 to 100.
  3687.  
  3688. 10   Product=1
  3689. 20   for I=1 to 100
  3690. 30     Product=Product*I
  3691. 40   next
  3692. 50   print Product
  3693. run
  3694.  93326215443944152681699238856266700490715968264381621468592963
  3695. 895217599993229915608941463976156518286253697920827223758251185
  3696. 210916864000000000000000000000000
  3697. OK
  3698.   If one wants to calculate this by usual BASIC language, he 
  3699. must make a long and complicated program.
  3700.  
  3701. ~~Lesson 4.
  3702. Lesson 4.    User Defined Functions
  3703.  
  3704.   This time compute a sum of powers, namely 
  3705.   1^3+2^3+...+100^3 or 11^4+12^4+...+50^4  etc.
  3706.   Write the power by 'Power', the start number by 'Start' and 
  3707. the final number by 'Final', then the program may be
  3708.  
  3709. 10   Power=3:Start=1:Final=20
  3710. 20   Sum=0
  3711. 30   for I=Start to Final
  3712. 40     Sum=Sum+I^Power
  3713. 50   next
  3714. 60   print Sum
  3715.   Let's execute this.  Then 1^3 + 2^3 + ... + 20^3 will be 
  3716. computed and the result will be displayed:
  3717. run
  3718.  44100
  3719. OK
  3720.   We remake it to a function to use again.
  3721.  
  3722.  5   fnPowerSum(Power,Start,Final)
  3723. 10     local Sum,I
  3724. 20     Sum=0
  3725. 30     for I=Start to Final
  3726. 40       Sum=Sum+I^Power
  3727. 50     next
  3728. 60   return(Sum)
  3729.   Rewrite the lines 10 and 60, and add the line 5.  The 
  3730. returning value is assigned by writing in () after RETURN.
  3731.  
  3732.   Now we got our function PowerSum.
  3733.   To try it, write
  3734. print fnPowerSum(22,1,100)
  3735.   then  1^22 + 2^22 + ... + 100^22  will be computed and the 
  3736. result is
  3737.  
  3738.  486614659739941950597622922368810419475443850
  3739. OK
  3740.   We can use user_functions from the direct mode if it is in 
  3741. the memory.
  3742.   Store this to the disk.
  3743. save "PowerSum"
  3744. OK
  3745.   Let's exit from UBASIC once.
  3746. system
  3747.   will return us to MS-DOS.
  3748.  
  3749.   Imagine some days after, you need to compute the sum of the 
  3750. 1-st, 2-nd,... 10-th powers of from 1 to 100.  Since you 
  3751. already have the function PowerSum, you can easily complete the
  3752.  work like this:
  3753.   Write the main program as follows:
  3754.  
  3755. 10   for I=1 to 10
  3756. 20     print I,fnPowerSum(I,1,100)
  3757. 30   next
  3758. 40   end
  3759.   Now we use the 'append' command.
  3760. append "PowerSum"
  3761. OK
  3762.   Then the 'PowerSum' function is loaded from the disk and 
  3763. linked to the last of the main program like this:
  3764.  
  3765. list
  3766.    10   for I=1 to 10
  3767.    20     print I,fnPowerSum(I,1,100)
  3768.    30   next
  3769.    40   end
  3770.  1040   fnPowerSum(Power,Start,Final)
  3771.  1050     local Sum,I
  3772.  1060     Sum=0
  3773.  1070     for I=Start to Final
  3774.  1080       Sum=Sum+I^Power
  3775.  1090     next
  3776.  1100   return(Sum)
  3777. OK
  3778.   Please note the line numbers automatically renumbered.  You 
  3779. need not care about the line numbers.
  3780.  
  3781. run
  3782.  1       5050
  3783.  2       338350
  3784.  3       25502500
  3785.  4       2050333330
  3786.  5       171708332500
  3787.  6       14790714119050
  3788.  7       1300583304167500
  3789.  8       116177773111333330
  3790.  9       10507499300049998500
  3791.  10      959924142434241924250
  3792. OK
  3793. <point>
  3794.   One who is familiar with normal BASIC languages will be 
  3795. confused by the usage of the variable 'I'.  Usual BASIC will 
  3796. run abnormally by such a program.  But UBASIC has local 
  3797. variables, the 'local' command in line 1050 preserves the value
  3798.  of 'I' in the main program and generate the new 'I' and 
  3799. initialize to 0.  The 'return' command will reset the original 
  3800. value to 'I'.
  3801.  
  3802. ~~Lesson 5.
  3803. Lesson 5.    Calculation of Real number
  3804.  
  3805.   To use the real numbers, one must set the precison by the 
  3806. 'point' command.
  3807.     point numerical_expression
  3808.   is the command format.  About 4.8 times the assigned value is
  3809.  the decimal digits.
  3810.  
  3811. point 10
  3812.   will set to 48 decimal digits.
  3813. OK
  3814. print 11/12
  3815.  0.916666666666666666666666666666666666666666666666
  3816. OK
  3817.  
  3818.  Calculate sin(X) from  X=1degree,...,45degrees by 20 decimals.
  3819.  Let's take POINT to be 5.
  3820.  
  3821.    10   point 5
  3822.    20   for I=0 to 45
  3823.    30     X=pi(I/180):'                     pi(I/180)=#pi*I/180
  3824.    40     print using(3),I;using(2,20),sin(X)
  3825.    50   next
  3826.  
  3827. run
  3828.   0  0
  3829.   1  0.01745240643728351282
  3830.   2  0.03489949670250097165
  3831.   3  0.05233595624294383272
  3832.   4  0.06975647374412530078
  3833.   5  0.08715574274765817356
  3834.   6  0.10452846326765347140
  3835.   7  0.12186934340514748111
  3836.   8  0.13917310096006544411
  3837.   9  0.15643446504023086901
  3838.  10  0.17364817766693034885
  3839. ...
  3840. OK
  3841.  Here 'print using(p1,p2)' assigns the display length of 
  3842. integer and fractional parts.
  3843.  
  3844. ~~Lesson 6.
  3845. Lesson 6.    High Precision Arithmetic
  3846.  
  3847.   Theoretically, (1+1/N)^N  converges to  'e'  as  N goes to 
  3848. infinity.  Let's see this numerically.
  3849.  
  3850.    10   point 20
  3851.    20   N=100:print (1+1/N)^N
  3852.    30   N=10^10:print (1+1/N)^N
  3853.    40   N=10^50:print (1+1/N)^N
  3854.  
  3855. run
  3856.  2.704813829421526093267194710807530833677938382781002776890201
  3857. 049117101514306739279439456014346584
  3858.  2.718281828323131143949794001297229499885179933883965470815866
  3859. 244433899270751441490494848853547347
  3860.  2.718281828459045235360287471352662497757247093625082984984087
  3861. 392709574135039719662542902843924865
  3862. OK
  3863.   The exact value of 'e' is
  3864. ? #e
  3865.  2.718281828459045235360287471352662497757247093699959574966967
  3866. 627724076630353547594571382178525165
  3867. OK
  3868.  Thus we can see that this sequence converges very slow but 
  3869. steadily to 'e'.  Note when you try with larger N's, set the 
  3870. point to be larger than 1/3 of the decimal digits of  N.
  3871.  
  3872. ~~Lesson 7.
  3873. Lesson 7.    Output Redirection
  3874.  
  3875. ü@There are two ways to store the calculation results to the 
  3876. disk.
  3877.   Here we use one of them, 'output redirection'.
  3878.  
  3879. ü@print=print+"file name"
  3880.  
  3881.   assigns the output device of the print command to CRT and the
  3882.  file.  For example, let's use the program in the Lesson5.
  3883.   Write before 'run'
  3884. print=print+"sin"
  3885. OK
  3886. run
  3887. OK
  3888.  Note this time the disk will work.
  3889.  
  3890. print=print
  3891. OK
  3892.   sets to the normal mode.
  3893.   Let's return to MS-DOS.
  3894.  
  3895. system
  3896. A>dir
  3897.   You will find the file 'sin', you will be able to edit it 
  3898. with your editor and print it beautifully.
  3899.   The variation:
  3900.   print=lprint
  3901.   print=print+lprint+"xyz"
  3902.   lprint=print
  3903.   etc.
  3904.  
  3905. ~~Lesson 8.
  3906. Lesson 8.    Arithmetic of Complex Numbers
  3907.  
  3908.   UBASIC version 8 can treat complex numbers like as real 
  3909. numbers.
  3910.   The unit of the imaginary number(square root of -1) is 
  3911. denoted by  #i.
  3912.   Let's make a function which answers one of the solutions of 
  3913. a quadratic equation.
  3914.   The well-known formula tells:
  3915.  
  3916. 10   fnQuadraEq(A,B,C)
  3917. 20     local D,Sol
  3918. 30     D=B^2-4*A*C
  3919. 40     Sol=(-B+sqrt(D))/(2*A)
  3920. 50   return(Sol)
  3921.  
  3922. ? .QuadraEq(1,2,3)
  3923. -1.0+1.4142135623730950487#i
  3924. OK
  3925.  Here  ?  is the shortened form of 'print' and  .  is that of 
  3926. 'fn'.
  3927.  
  3928.   Complex numbers can be used for the power arithmetic.  Let's 
  3929. think what is 'i' to the 'i'-th power?
  3930.  
  3931. ? #i^#i
  3932.  0.2078795763507619085
  3933. OK
  3934. is the answer. Since 'i' is the 'e' to the 'pi'/2*'i'-th power,
  3935.  'i' to the 'i'-th power must be the 'e' to the  -'pi'/2-th 
  3936. power.
  3937.  
  3938. ? exp(-pi(1/2))
  3939.  0.2078795763507619085
  3940. OK
  3941. Surely!
  3942. (You can use other expressions for exp(-pi(1/2)) such as 
  3943. exp(-#pi/2), #e^(-pi(1/2)) or #e^(-#pi/2), but I recommend 
  3944. exp(-pi(1/2)) most.)
  3945. Since a power function is multivalued, we must determine what 
  3946. branch UBASIC uses.  First UBASIC interprets #i^#i = 
  3947. exp(log(#i)*#i). And log(#i) = atan(1,0)*#i.  Finally two 
  3948. valiable arctangent takes its value larger than -pi less or 
  3949. equal to pi.
  3950.  
  3951. ~~Lesson 9.
  3952. Lesson 9.    Passing functions as parameters
  3953.  
  3954.   Suppose you are making a function or a subroutine which is 
  3955. applicable to various functions or subroutines.  You cannot use
  3956.  the exact function name in the program.  It may be convenient 
  3957. to use an abstract function name in your subroutine and get the
  3958.  exact function name as a parameter from the main routine.
  3959.   See the following example.  The function fnSimpson defined in
  3960.  the lines 140-230 gives an integration of the function fnF 
  3961. from A to B by N steps.
  3962. Lines 10-20 show the usage.
  3963.   You can do this only for the user defined functions.  The 
  3964. built_in functions cannot be passed directly.
  3965.  
  3966.    10   print fnSimpson(&fnA,0,1,1/10^6)
  3967.    20   print fnSimpson(&fnB,0,1,1/10^6)
  3968.    30   end
  3969.    40   '
  3970.    50   fnA(X)
  3971.    60   return(1/(1+X^2))
  3972.    70   '
  3973.    80   fnB(X)
  3974.    90   return(sqrt(1-X^2))
  3975.   100   '
  3976.   110   'Simpson's Rule (Numerical Integration)
  3977.   120   ' program from the book:
  3978.   125   ' S.Moriguchi Suuchi Keisan Jutu (Kyoritu Syuppan)
  3979.   130   '
  3980.   140   fnSimpson(&fnF(),X1,X2,E1)
  3981.   150     local Dy,H,M,N,S0,S1,S2,Y1,Y2
  3982.   160     N=2:H=(X2-X1)/N
  3983.   170     S0=fnF(X1)+fnF(X2):S1=fnF(X1+H):S2=0
  3984.   180     Y1=(S0+4*S1)*H/3
  3985.   190     repeat
  3986.   200       N=N*2:H=H/2:S2=S1+S2:S1=0
  3987.   210       for M=1 to N step 2:S1=S1+fnF(X1+M*H):next
  3988.   220       Y2=(S0+4*S1+2*S2)*H/3:Dy=Y2-Y1:Y1=Y2
  3989.   230     until absmax(Dy)<E1
  3990.   240   return(Y2)
  3991.  
  3992. run
  3993.  0.7853981628062055473
  3994.  0.7853977254182970949
  3995. OK
  3996.  
  3997.   Also subroutines can be passed as parameters.
  3998.  
  3999.    10   gosub *Test(&*A)
  4000.    20   gosub *Test(&*B)
  4001.    30   end
  4002.    40   '
  4003.    50   *A
  4004.    60     print "Now in A."
  4005.    70   return
  4006.    80   '
  4007.    90   *B
  4008.   100     print "Now in B."
  4009.   110   return
  4010.   120   '
  4011.   130   *Test(&*X)
  4012.   140     gosub *X
  4013.   150   return
  4014.  
  4015. run
  4016. Now in A.
  4017. Now in B.
  4018. OK
  4019.  
  4020. ~~Lesson 10.
  4021. Lesson 10.    Arithmetic of Rational Numbers
  4022.   UBASIC version 8 can treat rational numbers.  Write the 
  4023. numerator 1st, next the operator // and the denominator.  For 
  4024. example, 2//3 denotes '2 over 3'.
  4025. The rational number is stored in the reduced form. For example,
  4026.  2//4 is stored as 1//2, 3//1 is stored as 3(=integer).
  4027.   The following program will give the rational approximation of
  4028.  'e', the error will be smaller than 655536^(-21).
  4029.  
  4030.    10   'rational calculation of E
  4031.    20   point 21
  4032.    30   E#=0:I=1:W#=1
  4033.    40   while cvr(W#)
  4034.    50     E#=E#+W#:W#=W#//I:I=I+1
  4035.    60   wend
  4036.    70   print num(E#)
  4037.    80   print "/"
  4038.    90   print den(E#)
  4039.   100   print
  4040.   110   print cvr(E#)
  4041.   120   end
  4042.  
  4043. ~~Lesson 11.
  4044. Lesson 11.    Arithmetic of 1 variable polynomials
  4045.   UBASIC version 8 can treat polynomials of 1 valiable.
  4046. For example the polynomial 1+x+2*x^3 is denoted in UBASIC by  
  4047.   F#=poly(1,1,0,2)  or  
  4048.   F#=1+_x+2*_x^3    or  
  4049.   F#=poly(1):coeff(F#,1)=1:coeff(F#,3)=2
  4050. Either will produce the same result.
  4051.  
  4052.   The following program will give the differential of the 
  4053. polynomial.
  4054.  
  4055.    10   'differential
  4056.    20   input F#
  4057.    30   DF#=0
  4058.    40   for I=1 to deg(F#)
  4059.    50     coeff(DF#,I-1)=I*coeff(F#,I)
  4060.    60   next
  4061.    70   print DF#
  4062.    80   end
  4063.  
  4064. ~~Lesson 12.
  4065. Lesson 12.    Packing multiple data
  4066.   When you treat the data which consists of multiple sub_data, 
  4067. what do you do?
  4068. If you are a user of Pascal, you can use the 'record type' but 
  4069. you cannot make a function which returns such data.  If you are
  4070.  a user of an ANSI C, you can define a function which returns 
  4071. the 'struct'ured data.  UBASIC has no such data structure but 
  4072. can treat a set of data usually called a 'list'(in UBASIC 
  4073. called a 'pack') and can return that as the value of the 
  4074. functions.
  4075.   The following program will give the prime factorization of 
  4076. natural numbers.
  4077.  
  4078.    10   'prime factorization
  4079.    20   input "Integer <= 100000 =";N
  4080.    30   if N>100000 then beep:goto 20
  4081.    40   W#=fnFactor(N)
  4082.    50   for I=1 to len(W#)
  4083.    60     Ww#=member(W#,I)
  4084.    70     print member(Ww#,1);
  4085.    80     Power=member(Ww#,2)
  4086.    90     if Power>1 then print "^";Power;
  4087.   100     if I<len(W#) then print " * ";
  4088.   110   next
  4089.   120   print
  4090.   130   end
  4091.   140   '
  4092.   150   fnFactor(N)
  4093.   160     local P,Pold,E:W#=pack()
  4094.   170     Pold=prmdiv(N):N=N\Pold:E=1
  4095.   180     repeat
  4096.   190       P=prmdiv(N):N=N\P
  4097.   200       if P=Pold then E=E+1:goto 190
  4098.   210       W#=W#+pack(pack(Pold,E))
  4099.   220       Pold=P:E=1
  4100.   230     until P=1
  4101.   240   return(W#)
  4102.  
  4103. ~~Lesson 13.
  4104. Lesson 13.   Manipulation of strings
  4105.   You can use almost all commands and functions which are 
  4106. equipped by the usual BASIC languages such as RIGHT(),MID(),
  4107. LEFT(),...
  4108.   One advantage was added for UBASIC version 8.  That is, you 
  4109. can compute the string if it represents a mathematical formula.
  4110.   Moreover, you can execute the string if it represents a 
  4111. UBASIC command.
  4112.   The following program will make a table of the function which
  4113.  you assigned from the keybord.
  4114.  
  4115.    10   'table of a function
  4116.    20   print "Input a function using x as a variable (ex. 
  4117.         sin(x), x+cos(x),...)"
  4118.    30   strinput F#
  4119.    40   F#=encode(F#)
  4120.    50   for I=0 to 20
  4121.    60     X=I/20
  4122.    70     print using(4,4),X,using(4,6),val(F#)
  4123.    80   next
  4124.    90   end
  4125.  
  4126. ~~PrimeTests
  4127. Primality tests and factorization of integers are discussed,
  4128. e.g., in
  4129.  
  4130.     S. S. Wagstaff, Jr. and J. W. Smith:  Methods of Factoring
  4131.     Large Integers.  Springer Lecture Notes in Mathematics, No.
  4132.     1240, pp. 281-303
  4133.  
  4134.     Hideo Wada: Suugaku 38 (1986), pp. 345-350 (in Japanese).
  4135.  
  4136. PRTEST1 is an implementation of Lenstra's version of the
  4137. Adleman-Pomerance-Rumely primality test algorithm.  It is
  4138. faster than simple-minded ones for integers of more than 12 to
  4139. 13 figures.  A 70-figure number can be tested in an hour.  A
  4140. present implementation can handle integers of up to 137 figures.
  4141. See
  4142.  
  4143.     L. M. Adleman, C.Pomerance and R. S. Rumely:
  4144.     On Distinguishing Prime Numbers from Composite Numbers.
  4145.     Ann. of Math. 117(1983), pp.173-206.
  4146.  
  4147.     H. W. Lenstra, Jr.: Primality Testing Algorithm.
  4148.     Springer Lecture Notes in Mathematics No. 901, pp. 243-257.
  4149.  
  4150.     Hideo Wada:  Kousoku Jousan Hou to Sosuu Hantei Hou.
  4151.     Sophia University Mathematics Lecture Note No. 15,
  4152.     pp. 131-153 (in Japanese).
  4153.  
  4154. PRTEST1 follows Wada's presentation (but does not replace his
  4155. Condition 2 by Condition 7).
  4156.  
  4157. Cohen and Lenstra have improved the algorithm by using Jacobi
  4158. sums:
  4159.  
  4160.     H. Cohen and H. W. Lenstra, Jr.:  Primality Testing and
  4161.     Jacobi Sums.  Mathematics of Computation 42 (1984), 297-330.
  4162.  
  4163.     H. Cohen and A. K. Lenstra:  Implementation of a New
  4164.     Primality Test.  Mathematics of Computation 48 (1987),
  4165.     103-121.
  4166.  
  4167. APRT-CL implements their algorithm.  It is faster than PRTEST1
  4168. and can test numbers of up to 300 figures.
  4169.  
  4170. ~~Factorize
  4171. ECM, ECMX -- ECM factors integers using the Elliptic Curve
  4172. Method.  In a reasonable time, it can handle integers of more
  4173. than 200 figures, but with a factor of at most 20 figures.
  4174. ECMX, which uses a machine language routine, is faster by a few
  4175. per cent.  The original account of the algorithm is given by
  4176.  
  4177.     H. W. Lenstra, Jr.:  Factoring Integers with Elliptic
  4178.     Curves.  Annals of Mathematics 126 (1987), 649-673.
  4179.  
  4180. The following is handy when implementing the method.
  4181.  
  4182.     P. L. Montgomery:  Speeding the Pollard and Elliptic Curve
  4183.     Methods of Factorization.  Mathematics of Computation 48
  4184.     (1987), 243-264.
  4185.  
  4186. MPQSX uses the Multiple Polynomial Quadratic Sieve method.  It
  4187. can factor integers of up to about 45 figures.  Increase the
  4188. multiple of 16 on line 880 as far as the memory allows:
  4189.  
  4190.     16*30: 40 figures can be factored
  4191.     16*50: 45 figures can be factored
  4192.  
  4193. A 30-figure number takes 4 minutes; 35-figure, 9 minutes;
  4194. 40-figure, 20 minutes; 45-figure, an hour.
  4195.  
  4196. This routine uses machine language.  Its source listing is in
  4197. the MPQS#10.ASM file.
  4198.  
  4199. See:
  4200.  
  4201.     R. D. Silverman:  The Multiple Polynomial Quadratic Sieve.
  4202.     Mathematics of Computation 48 (1987), 329-339.
  4203.  
  4204. If you have 32-bit machines(CPU=386DX,386SX,486) with more than
  4205. 1MBytes extended memories and 10-100MBytes Hard Disk free area,
  4206. try MPQSHD in the MPQS32-subdirectory, which will decompose up
  4207. to 80 digits(it will take more than 1000hours).
  4208.  
  4209. MPQS and ECM are the newest and fastest integer factoring
  4210. methods.  But they work quite differently.  MPQS is more
  4211. predictable but cannot handle large numbers.  It would take
  4212. several months to factor a 100-figure number even with a
  4213. supercomputer.  ECM is quite fast when the number has a small
  4214. factor:  A 100-figure number with factors of no more than 20
  4215. figures can be factored in a reasonable time.
  4216.  
  4217. If the number has more than 55 figures, use ECM and hope for
  4218. luck! There's no way to tell beforehand how long it will take.
  4219. For smaller numbers, use MPQS.
  4220.  
  4221. Recently a new factorization method was invented, which was
  4222. named the Number Field Sieve method.  This method can be applied
  4223. only for the special kind of integers until now.
  4224.   A.K.Lenstra, H.W.Lenstra,Jr., M.S.Manasse and J.M.Pollard:
  4225.   The number field sieve (preprint).
  4226. They decomposed C148 of 2^(2^9)+1 into P49*P99.
  4227.  
  4228. POLFACT -- Factorize one variable polynomial in rational
  4229. numbers.
  4230.  
  4231. POLFACT1, POLFACT2 -- Both decompose a one-variable polynomial
  4232. into a product of irreducible ones modulo a prime number.
  4233. POLFACT1 reports only the decomposition type and the number of
  4234. factors with multiplicities for each degree.  POLFACT2 finds a
  4235. complete set of irreducible factors but runs slower.
  4236.  
  4237. ~~NumTheory
  4238. UNITR2, REALQF, REALQF2 -- UNITR2 computes fundamental units of
  4239. real quadratic fields, i.e., solutions of Pell equations.  It
  4240. will suffice if class numbers are not needed.  REALQF is a
  4241. straightforward implementation of the flowchart in
  4242.  
  4243.     H. Wada:  Table of Class Numbers of Real Quadratic Fields.
  4244.     Sophia University Mathematics Lecture Note No. 10
  4245.  
  4246. with an added routine to compute fundamental units.  It is much
  4247. faster and more reliable than REALQF2.
  4248.  
  4249. REALQF2 determines class numbers by an analytic formula.  It is
  4250. only approximate; the results are rounded to the nearest
  4251. integer.  When the discriminant is large, increase the POINT
  4252. value to cope with error.
  4253.  
  4254. IMAGQF, IMQF -- IMAGQF finds the class numbers of imaginary
  4255. quadratic fields analytically as character sums:
  4256.  
  4257.   110   D=4*N:if N@4=3 then D=D\4
  4258.   115   H=0
  4259.   120   for X=1 to D\2
  4260.   130     H=H+kro(-D,X)
  4261.   140   next X
  4262.   150   H=H\(2-kro(-D,2))
  4263.   160   print "Class Number is  ";H
  4264.  
  4265. IMQF counts points in the fundamental region on the complex
  4266. plane. It is much faster than IMAGQF.
  4267.  
  4268. GENSHI, GENSHIP -- These compute minimum primitive roots and
  4269. minimum prime primitive roots modulo P.
  4270.  
  4271.    10   'GENSHI version 1.2
  4272.    20   print "Primitive Root modulo P"
  4273.    30   input "Prime = ";P
  4274.    40   if P<3 then print "Too small":goto 30
  4275.    50   if P>=65536^2 then print "Too big":goto 30
  4276.    60   if prmdiv(P)<P then print "Not prime":goto 30
  4277.    70   G=2:N=P-1
  4278.    80   NW=N
  4279.    90   D=prmdiv(NW)
  4280.   100   repeat:NW=NW\D:until res:NW=NW*D+res
  4281.   110   if modpow(G,N\D,P)=1 then inc G:goto 80
  4282.   120   if NW>1 then goto 90
  4283.   130   print G;"is the smallest primitive root MOD";P
  4284.   140   end
  4285.  
  4286. KAIJOU (factorial) -- An example program to illustrate UBASIC86's
  4287. output formatting.
  4288.  
  4289.    10   'KAIJOU version 1.1
  4290.    20   word 510
  4291.    30   print "Factorials"
  4292.    40   F=1
  4293.    50   for N=1 to 20
  4294.    60     F=F*N
  4295.    70     print using(5),N;"! =";using(25),F
  4296.    80   next N
  4297.    90   end
  4298.  
  4299. ~~aboutUB
  4300. about UBASIC
  4301.  
  4302. UBASIC is written by
  4303.     Prof. Yuji Kida
  4304.     Department of Mathematics
  4305.     Faculty of Science
  4306.     Kanazawa University
  4307.     1-1 Marunouchi, Kanazawa 920, JAPAN.
  4308.  (until March 31, 1991)
  4309.  (from April 1, 1991)
  4310.     Department of Mathematics
  4311.     Rikkyo University
  4312.     Nishi-Ikebukuro, Tokyo 171, JAPAN.
  4313.  
  4314.   If you find any bug, please inform me at the address above.
  4315. Application programs written in UBASIC are alsowelcome.
  4316.  
  4317.   I welcome your copying and distributing this software,
  4318. magnetically or otherwise.
  4319.  
  4320.   This software is distributed as is.  I disclaim all
  4321. warranties, expressed or implied.  I assume no liability for
  4322. damages, direct or consequential, which may result from the
  4323. use of this software.
  4324.  
  4325.   Here I express my hearty thanks to the users who told me the
  4326. bugs and suggested me the improvements, especially,
  4327. Prof.s Shigeki Egami, Mituo Morimoto in Japan, Dr. Frank O'Hara
  4328. in England and Prof. Walter Neumann in USA.
  4329.  
  4330.   This manual is written, translated and revised by
  4331.     Prof. Yuji Kida,
  4332.     Mr. Haruhiko Okumura, 
  4333.     Mrs. Yoko Iwase in Japan,
  4334.     Dr. Frank O'Hara in England and
  4335.     Prof. Walter Neumann in USA.
  4336.  
  4337.   This on-line manual system is created by
  4338.     Prof. Yoichi Koyama in Japan.
  4339.  
  4340.  Version 8.21.  February 1, 1991.
  4341. --------------------------------------------------------------
  4342. 
  4343.