UBASIC
UBASIC is a freeware BASIC interpreter written by Yuji Kida at Rikkyo University in Japan, specialized for mathematical computing.
Features
UBASIC is a ready-to-run language that does not need to be set up with another advanced language, which is a common problem with multi-digit math languages. It runs in DOS or in a DOS box under DOS shell, Microsoft Windows, etc. It is specialized for number theory, primality testing, factoring, and large integers. Being an implementation of BASIC makes it easy to read programs without having to do extensive study, as BASIC is a language that has a structure and syntax close to ordinary algebra. The help files have articles and lessons for beginners.UBASIC has a built-in on-line editor with several aids for debugging. It can show cross references to calling lines, lines containing a variable, and lists of variables/arrays. It can renumber lines, change variable names, and append additional programs. It can trace, single step, and time by milliseconds to help determine the fastest way to do highly repetitive sections. It can redefine function keys, either to provide an easy one-keypress function or to prevent a standard function from being accidentally used when it shouldn't. It can shell to DOS or execute a DOS command. It can convert between single-byte character set and double-byte character set, but to have much use for this, the host computer would likely need an aware operating system. Documents may be added to or modified in UBHELP.HLP.
Primality testing with APRT-CLE : 500 digits said to take 5 hours on a PP-200, 150 digits takes about 16 minutes on a 486-100, about 2¼ minutes on a K6@233; 250 digits takes about 13½ minutes on a K6@233. Recent machines can be up to 10 times faster. APRT-CLE is often the algorithm of choice for testing primality of integers within its range.
Factoring with programs such as ECMX is quite fast. It can find factors with the number of digits in the low-20s fairly easily, mid-20s somewhat less easily, and upper-20s with lower chance of success. It has found a 30-digit factor. increases rapidly with the size of factors. It is always best to use the fastest machine available. ECMX uses the accepted standards for limits of when to stop working with one curve and switch to the next. It has preliminary primality testing, finding small factors, and powers.
Being interpreted allows modifying programs and then restarting in the middle of a run, even multi-day, without losing accumulated data. Stopping is not recommended unless a program has been saving the data safely somewhere, or if users forgot to write any way to save data when quitting. When doing anything that might lose valuable data, or if you need to do something else for a time, then you can FREEZE the current program to a file and later MELT it.
UBASIC has line numbers. It does not use indentation to control structure. It has subroutines and user functions with passed parameters and local variables. Parameters can be passed by value or by name. User functions and subroutines may be passed as parameters. It has limited labels. It has various options for conditional functions. Users can indent as much as needed or not at all, and can have as much structure as wanted or spaghetti code. It is a mistake to consider UBASIC as "not modern". Having line numbers allows easy jumping to an intermediate point in a routine, which can sometimes save duplicating lines.
UBASIC version 8 has the high-precision real and complex arithmetic of prior versions, and adds exact rational arithmetic and arithmetic of single-variable polynomials with complex, rational, or modulo p coefficients, as well as string handling and limited list handling abilities. In also has context-sensitive on-line documentation. The file that this uses is ASCII and can be printed for a paper document.
As of 2005, the help file had many errors. A ten-year project to rewrite/correct was nearly ready for publication probably by late summer 2005. The new help file has a new extension '.hlp', and eventually package name u3d748f*. A list of updates is available, but many changes remain unreported.
Version 8.8 has different precision than 8.74
There are still some commands that have no documentation:
SCHOOL
KEYSCAN
MODMUL running or suspended somewhere else, as lockups may be expected, particularly for KEYSCAN.
See: FREEZE, ROLL, MELT.
UBASIC has several types of arrays, logical operators, bit operators, 4 standard loop structures, and combined operators. It can call machine language routines for increased speed, but you must know assembly language to even understand the instructions - just being able to write TSR's in DEBUG is not enough.
- String values can be computed if it represents a math formula.
- Strings can usually be executed if it represents a UBASIC command.
- Variables holding strings may usually be substituted for the strings.
- Strings can be alphabetized using MIN or MAX.
It can process text files to convert tabs to spaces or spaces to tabs. Some programs can not generate tabs and some actually choke on them.
Variable types include:
1: integer
2: rational
3: real
4: complex number
5: string
6: packet
7: polynomial
8: mod polynomial
An early 2005 Internet search turned up versions 8.74, 8.74, 8.71, 9.0ZE, 9.0ZC, 9.0E, 8.8F, 8.8F, 8.8F, 8.7E, 8.7E, 8.30, 8.30, 7.25, 7.25, 8.8A, 8,8A, 8.8A, 8.8C, 8.8C, 8.8C, 8.8E, 8.8E, 8.8E. 12 versions out of 52 known numbers. Many of these are not directly identified. and refer to the number of bits in the multiplication engine. refers to special versions that can go up to over 4000 digits. The
Most users would only need 8.8F.
If you are already using a version later than 8.74 and especially if you are using a version later than 8.7E then you are strongly advised to switch to the latest version. Some programs written for 8.74 may not work in 8.8F without considerable rewriting. The latest versions do not strip carriage returns/line feeds from ASCII files, and programs such as UBH need added lines to strip them. Any program written for one version should not be used in another version without checking.
Certain programs such as NFS will only run on experimental version 9.**.
The ppmpx36e version of the multi-polynomial quadratic sieve needs 8.8F and Windows.
Some versions of UBASIC came with a defective UBCONST7.DAT file. You should check yours against the one supplied in 8.8F. If it is not identical then you should switch.
UBASIC is available for
1: IBM-PC/AT and compatibles
2: NEC PC-9801
3: NEC PC-H98
4: Fujitsu FM-R
5: Toshiba J-3100
6: AX
7: DOS/V
For obtaining the latest version of UBASIC, see external links sections. Many internet math pages have the language/packages on their own sites.
UBASIC was written by:
Prof. Yuji Kida
Department of Mathematics
Rikkyo University
Nishi-Ikebukuro 3, Tokyo 171, JAPAN.
Sample program
The following is a short simple program for the partition count function. Although it doesn't have many of the fancier structures, it is a real program, not invented for this article. On a modern fast Athlon it should calculate the partition counts from p to p in about ½ second. Contrast that to over ½ century the first time through. To save the result to a file, uncomment line 40.10 CONSOLE:CONSOLE 1,24,0:LOCATE 1,0
20 PRINT CHR;"N","P","PARTITION COUNT"
30 WORD -19:POINT -8:H%=11:'FOR N UP TO ~1200
40 'PRINT=PRINT+"PARTN5.TXT":'output redirect
50 N=0:'INPUT N
60 CLR TIME
70 Mu=PI
80 CLR S
90 FOR K=1 TO H%
100 '110 to 160 is selberg formula
110 CLR C
120 FOR L=0 TO 2*K-1
130 IF @K=@K
140 :C+=^L*COS/))
150 NEXT
160 'to get A, multiply C by SQRT
170 U=EXP
180 R=/U:'Rademacher's convergence term
190 S+=*C
200 NEXT
210 S=ROUND)
220 PRINT CUTSPC;
230 LOCATE 38-ALEN:PRINT S
240 IF N<1000:INC N:GOTO 70
250 Tt=TIME1000:PRINT=PRINT:PRINT Tt/1000
260 '~1.7% faster if N,K,L changed to N%,K%,L%
Accuracy
When working with continued fractions, the number of terms is limited by the available accuracy and by the size of each term. An approximate formula is 2 decimal fraction digit accuracy for each. The only way to do such work safely is to do it twice, in parallel, with the initial input to one dithered in the final several digits. Then when the two calculations do not give identical terms, stop at the previous term.UBASIC can calculate the partition function to over p.
Main traits
- Strong emphasis on number theory
- Has ready-made application programs such as primality test, factoring, Bernoulli numbers, zeta function, etc.
- Versions from 8.74 have graphics
- Can work with numbers up to 2600 digits, but with functions and complex numbers the digit limit is less
- Has on-line context-sensitive help