UBASIC
![]() | This article has multiple issues.Please helpimprove itor discuss these issues on thetalk page.(Learn how and when to remove these template messages)
|
![]() UBASIC 32-bit (English Version) | |
Original author(s) | Yuji Kida |
---|---|
Initial release | before 2005 |
Operating system | DOS,Microsoft Windows |
Type | BASIC |
License | Freeware/Public domain(withoutsource code) |
UBASICis afreeware(public domain softwarewithoutsource code)BASIC interpreterwritten by Yuji Kida atRikkyo UniversityinJapan,specialized formathematicalcomputing.
Features
[edit]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 inDOSor in aDOS boxunderDOS shell,Microsoft Windows,etc. It is specialized fornumber theory,primality testing,factoring,and largeintegers(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 ordinaryalgebra.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 bymillisecondsto 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 anddouble-byte character set,but to have much use for this, the host computer would likely need an awareoperating system.Documents may be added to or modified inUBHELP.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 thealgorithmof 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. (Finding factors with theelliptic curve methodis 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 (usingGOTO
) 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 did not 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 canFREEZE
the current program to a file and laterMELT
it (as long as the lower memory configuration is the same).
UBASIC hasline numbers.It does not use indentation to control structure. It hassubroutinesand 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 orspaghetti 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-variablepolynomialswith complex, rational, ormodulo p coefficients,as well asstring handlingand limited list handling abilities. In also has context-sensitive on-line documentation (readUBHELP.DOCfor information). The file that this uses isASCIIand 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.8CPOLYCONV
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 forKEYSCAN
.
See:FREEZE
,ROLL
,MELT
.(for similar warning)
UBASIC has several types ofarrays,logical operators,bit operators,four standard loop structures, and combined operators. It can callmachine languageroutines for increased speed (ECMX does this), but you must knowassembly languageto even understand the instructions - just being able to writeTSR'sin 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:.WAVfiles. 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:
- integer
- rational
- real
- complex number
- string
- packet (mixed from any types including other packets)
- polynomial
- 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 792Bernoulli numbersto double index 1584: the latest version can only get 540/1080). The (C) is forCGAmachines. 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 arestronglyadvised 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 stripcarriage returns/line feedsfrom 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-polynomialquadratic sieveneeds 8.8F and Windows.
Some versions of UBASIC came with a defectiveUBCONST7.DATfile. You should check yours against the one supplied in 8.8F. If it is not identical then you should switch.
UBASIC is available for
- IBM PC/ATand compatibles
- NEC PC-9801
- NEC PC-H98
- Fujitsu FM-R
- Toshiba J-3100
- AX
- 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.
Sample program
[edit]The following is a short simple program for the partition count function. Although it does not 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).
10CONSOLE:CONSOLE1,24,0:LOCATE1,0
20PRINTCHR(2);"N","P(N)","PARTITION COUNT"
30WORD-19:POINT-8:H%=11:'FOR N UP TO ~1200
40'PRINT=PRINT+ "PARTN5.TXT":'output redirect
50N=0:'INPUT N
60CLRTIME
70Mu=PI(SQRT(24*N-1)/6)
80CLRS
90FORK=1TOH%
100'110 to 160 is selberg formula
110CLRC
120FORL=0TO2*K-1
130IF((3*L^2+L)\2)@K=(-N)@K
140:C+=(-1)^L*COS(PI((6*L+1)/(6*K)))
150NEXT
160'to get A(K,N), multiply C by SQRT(K/3)
170U=EXP(Mu/K)
180R=(Mu+K)/U:'Rademacher's convergence term
190S+=((Mu-K)*U+R)*C
200NEXT
210S=ROUND(ABS(S*2/(MU*(24*N-1))))
220PRINTCUTSPC(STR(N));
230LOCATE38-ALEN(S):PRINTS
240IFN<1000:INCN:GOTO70
250Tt=TIME1000:PRINT=PRINT:PRINTTt/1000
260'~1.7% faster if N,K,L changed to N%,K%,L%
Accuracy
[edit]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 thebase ten logarithmof 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 thepartition functionto over p(1330521). (In 8.74 up to p(1361911) and the 4000 digit versions should get many more.)
Main traits
[edit]- Strong emphasis onnumber theory
- Has ready-made application programs such asprimality test,factoring,Bernoulli numbers,zeta function,etc.
- Versions from 8.74 have graphics
- Can work with numbers up to 2600 digits (bignums), but with functions andcomplex numbersthe digit limit is less
- Has on-line context-sensitive help
See also
[edit]- BASIC
- List of BASIC dialects by platform
- Lenstra elliptic curve factorization
- complex numbers
- Prime number
- Jørgen Pedersen Gram
- Logarithmic integral function
- Prime gaps
- Integrated development environment
References
[edit]- Notes
Essential features consists of the following:
- The Near Repdigit Primes, A(n)B, AB(n), and UBASIC; Caldwell, Chris K.; Journal of RECREATIONAL MATHEMATICS, Vol. 22(2) 101-109, 1990
- UBASIC: a Public-Domain BASIC for Mathematics; Neumann, Walter D.; Notices of the American Mathematical Society, May/June 1989, volume 36, number 5, p. 557-559
- UBASIC Update; Neumann, Walter D.; Notices of the American Mathematical Society, March 1991, volume 38, number 3, p. 196-197
- 2 and 3 are somewhat old, and Mr. Neumann says "public domain" when he should say "freeware" (without source code).
External links
[edit]- (in French)UBASIC 9.0w homepage
- (in Japanese)UBASIC86 catalogue by ykida (Vector)
- (in Japanese)UBASIC Homepage: 3.3.2014
- English UBASIC homepage: 18.2.2009
- UBASIC - Simtelnet (Last update: 25.06.1998)
- Non-defective version 8.74
- Professor Yuji Kida (Last updated: Apr 4, 2014 at 09:58)
- UBASIC 7 October 2000 - The Final Version 8.8F - in English (Link Retrieved on 17 September 2017)
- UBASIC Manual - PDF with Copy Enabled - Last Correction on 22 July 2006 - in Japanese - Last WayBackMachine Archived Page on 22 July 2011 (Link Retrieved on 17 September 2017)
- [1]Source code for UBASIC 9