UBASIC
Encyclopedia
UBASIC is a freeware
BASIC
interpreter
written by Yuji Kida at Rikkyo University
in Japan
, specialized for mathematical computing.
or in a DOS box under DOS shell
, Microsoft Windows
, etc. It is specialized for number theory
, primality testing, factoring
, and large integers (up to 2600 digits). 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 has 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 (to 884 digits) (it is best to run this under UBASIC version 8.8F or later): 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 to low-20's digits fairly easily, mid-20's somewhat less easily, and upper-20's with (s)lower chance of success. It has found a 30-digit factor. (Finding factors with the elliptic curve method is always chancy for larger factors. The greater the number of curves that are tested the greater the chances of success, but the number needed (on average, one can sometimes get lucky or unlucky) 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 (using GOTO) 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 (perhaps they didn't expect to find any and were trying to prove it)). 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 (as long as the lower memory configuration is the same).
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" (as might be inferred by a reader of articles that confuse indentation with structure and don't favor line numbers). 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 (up to 2600 digits) 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 (read UBHELP.DOC for information). 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(
There is a new command from version 8.8C POLYCONV(
that converts polynomials between modulus=0 and modulus=prime.
There are no formatting specifications.
WARNING: Never test out any of these when while anything
important is (or might be) running or suspended somewhere else,
as lockups may be expected, particularly for KEYSCAN.
See: FREEZE, ROLL, MELT. (for similar warning)
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 (ECMX does this), but you must know assembly language to even understand the instructions - just being able to write TSR's in DEBUG is not enough.
UBASIC can be used to process almost any kind of data. For example: .WAV files.
It can process text files to convert tabs to spaces or spaces to tabs. Some programs can't generate tabs and some actually choke on them.
Variable types include:
1: integer
2: rational
3: real
4: complex number
5: string
6: packet (mixed from any types including other packets)
7: polynomial
8: mod polynomial (coefficients integers modulo a prime)
An early 2005 Internet search turned up versions 8.74(32), 8.74(16), 8.71(4000(16)), 9.0ZE, 9.0ZC, 9.0E, 8.8F(32), 8.8F(16), 8.8F(C), 8.7E(32), 8.7E(16), 8.30(32), 8.30(16), 7.25(32), 7.25(16), 8.8A(32), 8,8A(16), 8.8A(C), 8.8C(32), 8.8C(16), 8.8C(C), 8.8E(32), 8.8E(16), 8.8E(C). 12 versions out of 52 known numbers. Many of these are not directly identified. (The (16) and (32) refer to the number of bits in the multiplication engine. (4000) refers to special versions that can go up to over 4000 digits (some users may need one of these, such as to generate the first 792 Bernoulli numbers to double index 1584: the latest version can only get 540/1080). The (C) is for CGA machines. The versions in italics are not recommended.)
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 (8.8F). Some programs (fancy display, for example) 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 (even the one in 8.8F) 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.
(e-mail: kida@rkmath.rikkyo.ac.jp)
10 console:console 1,24,0:locate 1,0
20 print chr(2);"n","p(n)","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(sqrt(24*N-1)/6)
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 ((3*L^2+L)\2)@K=(-N)@K
140 :C+=(-1)^L*cos(pi((6*L+1)/(6*K)))
150 next
160 'to get A(K,N), multiply C by sqrt(K/3)
170 U=exp(Mu/K)
180 R=(Mu+K)/U:'Rademacher's convergence term
190 S+=((Mu-K)*U+R)*C
200 next
210 S=round(abs(S*2/(Mu*(24*N-1))))
220 print cutspc(str(N));
230 locate 38-alen(S):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%
UBASIC can calculate the partition function to over p(1330521). (In 8.74 up to p(1361911) and the 4000 digit versions should get many more.)
Freeware
Freeware is computer software that is available for use at no cost or for an optional fee, but usually with one or more restricted usage rights. Freeware is in contrast to commercial software, which is typically sold for profit, but might be distributed for a business or commercial purpose in the...
BASIC
BASIC
BASIC is a family of general-purpose, high-level programming languages whose design philosophy emphasizes ease of use - the name is an acronym from Beginner's All-purpose Symbolic Instruction Code....
interpreter
Interpreter (computing)
In computer science, an interpreter normally means a computer program that executes, i.e. performs, instructions written in a programming language...
written by Yuji Kida at Rikkyo University
Rikkyo University
, also known as Saint Paul's University, is a private university, based on Christian precepts, in Ikebukuro, Tokyo. There is a suburban campus in Niiza in nearby Saitama.It is known for its liberal climate symbolized by the motto -History:...
in Japan
Japan
Japan is an island nation in East Asia. Located in the Pacific Ocean, it lies to the east of the Sea of Japan, China, North Korea, South Korea and Russia, stretching from the Sea of Okhotsk in the north to the East China Sea and Taiwan in the south...
, 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 DOSDOS
DOS, short for "Disk Operating System", is an acronym for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions 95, 98, and Millennium Edition.Related...
or in a DOS box under DOS shell
DOS Shell
The DOS Shell is a file manager, debuted in MS-DOS and IBM DOS 4.0 . It was discontinued after version 6.0, but retained as part of the "Supplemental Disk" until 6.22 for MS-DOS; as such, it was not a core part of the operating system throughout its evolution, but rather an add-on...
, Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
, etc. It is specialized for number theory
Number theory
Number theory is a branch of pure mathematics devoted primarily to the study of the integers. Number theorists study prime numbers as well...
, primality testing, factoring
Integer factorization
In number theory, integer factorization or prime factorization is the decomposition of a composite number into smaller non-trivial divisors, which when multiplied together equal the original integer....
, and large integers (up to 2600 digits). 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 has 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
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...
. Documents may be added to or modified in UBHELP.HLP.
Primality testing with APRT-CLE (to 884 digits) (it is best to run this under UBASIC version 8.8F or later): 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 to low-20's digits fairly easily, mid-20's somewhat less easily, and upper-20's with (s)lower chance of success. It has found a 30-digit factor. (Finding factors with the elliptic curve method is always chancy for larger factors. The greater the number of curves that are tested the greater the chances of success, but the number needed (on average, one can sometimes get lucky or unlucky) 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 (using GOTO) 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 (perhaps they didn't expect to find any and were trying to prove it)). 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 (as long as the lower memory configuration is the same).
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
Spaghetti code
Spaghetti code is a pejorative term for source code that has a complex and tangled control structure, especially one using many GOTOs, exceptions, threads, or other "unstructured" branching constructs. It is named such because program flow tends to look like a bowl of spaghetti, i.e. twisted and...
. It is a mistake to consider UBASIC as "not modern" (as might be inferred by a reader of articles that confuse indentation with structure and don't favor line numbers). 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 (up to 2600 digits) 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 (read UBHELP.DOC for information). 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(
There is a new command from version 8.8C POLYCONV(
that converts polynomials between modulus=0 and modulus=prime.
There are no formatting specifications.
WARNING: Never test out any of these when while anything
important is (or might be) running or suspended somewhere else,
as lockups may be expected, particularly for KEYSCAN.
See: FREEZE, ROLL, MELT. (for similar warning)
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 (ECMX does this), 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.
UBASIC can be used to process almost any kind of data. For example: .WAV files.
It can process text files to convert tabs to spaces or spaces to tabs. Some programs can't generate tabs and some actually choke on them.
Variable types include:
1: integer
2: rational
3: real
4: complex number
5: string
6: packet (mixed from any types including other packets)
7: polynomial
8: mod polynomial (coefficients integers modulo a prime)
An early 2005 Internet search turned up versions 8.74(32), 8.74(16), 8.71(4000(16)), 9.0ZE, 9.0ZC, 9.0E, 8.8F(32), 8.8F(16), 8.8F(C), 8.7E(32), 8.7E(16), 8.30(32), 8.30(16), 7.25(32), 7.25(16), 8.8A(32), 8,8A(16), 8.8A(C), 8.8C(32), 8.8C(16), 8.8C(C), 8.8E(32), 8.8E(16), 8.8E(C). 12 versions out of 52 known numbers. Many of these are not directly identified. (The (16) and (32) refer to the number of bits in the multiplication engine. (4000) refers to special versions that can go up to over 4000 digits (some users may need one of these, such as to generate the first 792 Bernoulli numbers to double index 1584: the latest version can only get 540/1080). The (C) is for CGA machines. The versions in italics are not recommended.)
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 (8.8F). Some programs (fancy display, for example) 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 (even the one in 8.8F) 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.
(e-mail: kida@rkmath.rikkyo.ac.jp)
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(0) to p(1000) in about ½ second. Contrast that to over ½ century the first time through. To save the result to a file, uncomment line 40 (remove leading apostrophe).10 console:console 1,24,0:locate 1,0
20 print chr(2);"n","p(n)","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(sqrt(24*N-1)/6)
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 ((3*L^2+L)\2)@K=(-N)@K
140 :C+=(-1)^L*cos(pi((6*L+1)/(6*K)))
150 next
160 'to get A(K,N), multiply C by sqrt(K/3)
170 U=exp(Mu/K)
180 R=(Mu+K)/U:'Rademacher's convergence term
190 S+=((Mu-K)*U+R)*C
200 next
210 S=round(abs(S*2/(Mu*(24*N-1))))
220 print cutspc(str(N));
230 locate 38-alen(S):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 (term times the base ten logarithm of the term). 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 (at least 1 word). Then when the two calculations do not give identical terms, stop at the previous term.UBASIC can calculate the partition function to over p(1330521). (In 8.74 up to p(1361911) and the 4000 digit versions should get many more.)
Main traits
- Strong emphasis on number theoryNumber theoryNumber theory is a branch of pure mathematics devoted primarily to the study of the integers. Number theorists study prime numbers as well...
- Has ready-made application programs such as primality testPrimality testA primality test is an algorithm for determining whether an input number is prime. Amongst other fields of mathematics, it is used for cryptography. Unlike integer factorization, primality tests do not generally give prime factors, only stating whether the input number is prime or not...
, factoringInteger factorizationIn number theory, integer factorization or prime factorization is the decomposition of a composite number into smaller non-trivial divisors, which when multiplied together equal the original integer....
, Bernoulli numbers, zeta function, etc. - Versions from 8.74 have graphics
- Can work with numbers up to 2600 digits (bignums), but with functions and complex numbers the digit limit is less
- Has on-line context-sensitive help
See also
- BASICBASICBASIC is a family of general-purpose, high-level programming languages whose design philosophy emphasizes ease of use - the name is an acronym from Beginner's All-purpose Symbolic Instruction Code....
- List of BASIC dialects by platform
- Lenstra elliptic curve factorizationLenstra elliptic curve factorizationThe Lenstra elliptic curve factorization or the elliptic curve factorization method is a fast, sub-exponential running time algorithm for integer factorization which employs elliptic curves. For general purpose factoring, ECM is the third-fastest known factoring method...
- complex numbers
- Prime numberPrime numberA prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. A natural number greater than 1 that is not a prime number is called a composite number. For example 5 is prime, as only 1 and 5 divide it, whereas 6 is composite, since it has the divisors 2...
- Jørgen Pedersen GramJørgen Pedersen GramJørgen Pedersen Gram was a Danish actuary and mathematician who was born in Nustrup, Duchy of Schleswig, Denmark and died in Copenhagen, Denmark....
- Logarithmic integral functionLogarithmic integral functionIn mathematics, the logarithmic integral function or integral logarithm li is a special function. It occurs in problems of physics and has number theoretic significance, occurring in the prime number theorem as an estimate of the number of prime numbers less than a given value.-Integral...
- Prime gaps
- Integrated development environmentIntegrated development environmentAn integrated development environment is a software application that provides comprehensive facilities to computer programmers for software development...
External links
- UBASIC 9.0w homepage (French)
- UBASIC86 catalogue (Vector) (Japanese)
- UBASIC Homepage (Japanese)
- English UBASIC homepage
- Non-defective version 8.74