UBASIC

Last updated
UBASIC
Original author(s) Yuji Kida
Initial releasebefore 2005
Operating system DOS, Microsoft Windows
Type BASIC
License Freeware / Public domain (without source code)

UBASIC is a freeware (public domain software without source code) BASIC interpreter written by Yuji Kida at Rikkyo University in Japan, specialized for mathematical computing.

Contents

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 (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 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 (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 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 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 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 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, four 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 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 (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.

Sample program

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,020PRINTCHR(2);"N","P(N)","PARTITION COUNT"30WORD-19:POINT-8:H%=11:'FOR N UP TO ~120040'PRINT=PRINT+"PARTN5.TXT":'output redirect50N=0:'INPUT N60CLRTIME70Mu=PI(SQRT(24*N-1)/6)80CLRS90FORK=1TOH%100'110 to 160 is selberg formula110CLRC120FORL=0TO2*K-1130IF((3*L^2+L)\2)@K=(-N)@K140:C+=(-1)^L*COS(PI((6*L+1)/(6*K)))150NEXT160'to get A(K,N), multiply C by SQRT(K/3)170U=EXP(Mu/K)180R=(Mu+K)/U:'Rademacher's convergence term190S+=((Mu-K)*U+R)*C200NEXT210S=ROUND(ABS(S*2/(MU*(24*N-1))))220PRINTCUTSPC(STR(N));230LOCATE38-ALEN(S):PRINTS240IFN<1000:INCN:GOTO70250Tt=TIME1000:PRINT=PRINT:PRINTTt/1000260'~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

See also

Related Research Articles

<span class="mw-page-title-main">Hash function</span> Mapping arbitrary data to fixed-size values

A hash function is any function that can be used to map data of arbitrary size to fixed-size values, though there are some hash functions that support variable length output. The values returned by a hash function are called hash values, hash codes, hash digests, digests, or simply hashes. The values are usually used to index a fixed-size table called a hash table. Use of a hash function to index a hash table is called hashing or scatter storage addressing.

In number theory, integer factorization is the decomposition of a positive integer into a product of integers. Every positive integer greater than 1 is either the product of two or more integer factors, in which case it is called a composite number, or it is not, in which case it is called a prime number. For example, 15 is a composite number because 15 = 3 · 5, but 7 is a prime number because it cannot be decomposed in this way. If one of the factors is composite, it can in turn be written as a product of smaller factors, for example 60 = 3 · 20 = 3 · (5 · 4). Continuing this process until every factor is prime is called prime factorization; the result is always unique up to the order of the factors by the prime factorization theorem.

In mathematics, a polynomial is a mathematical expression consisting of indeterminates and coefficients, that involves only the operations of addition, subtraction, multiplication, and positive-integer powers of variables. An example of a polynomial of a single indeterminate x is x2 − 4x + 7. An example with three indeterminates is x3 + 2xyz2yz + 1.

<span class="mw-page-title-main">Prime number</span> Number divisible only by 1 or itself

A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1, involve 5 itself. However, 4 is composite because it is a product (2 × 2) in which both numbers are smaller than 4. Primes are central in number theory because of the fundamental theorem of arithmetic: every natural number greater than 1 is either a prime itself or can be factorized as a product of primes that is unique up to their order.

<span class="mw-page-title-main">Linear programming</span> Method to solve optimization problems

Linear programming (LP), also called linear optimization, is a method to achieve the best outcome in a mathematical model whose requirements and objective are represented by linear relationships. Linear programming is a special case of mathematical programming.

<span class="mw-page-title-main">Atari BASIC</span> Dialect of the BASIC programming language

Atari BASIC is an interpreter for the BASIC programming language that shipped with the Atari 8-bit family of 6502-based home computers. Unlike most American BASICs of the home computer era, Atari BASIC is not a derivative of Microsoft BASIC and differs in significant ways. It includes keywords for Atari-specific features and lacks support for string arrays, for example.

Microsoft BASIC is the foundation software product of the Microsoft company and evolved into a line of BASIC interpreters and compiler(s) adapted for many different microcomputers. It first appeared in 1975 as Altair BASIC, which was the first version of BASIC published by Microsoft as well as the first high-level programming language available for the Altair 8800 microcomputer.

The Riemann hypothesis is one of the most important conjectures in mathematics. It is a statement about the zeros of the Riemann zeta function. Various geometrical and arithmetical objects can be described by so-called global L-functions, which are formally similar to the Riemann zeta-function. One can then ask the same question about the zeros of these L-functions, yielding various generalizations of the Riemann hypothesis. Many mathematicians believe these generalizations of the Riemann hypothesis to be true. The only cases of these conjectures which have been proven occur in the algebraic function field case.

Commodore BASIC, also known as PET BASIC or CBM-BASIC, is the dialect of the BASIC programming language used in Commodore International's 8-bit home computer line, stretching from the PET (1977) to the Commodore 128 (1985).

The AKS primality test is a deterministic primality-proving algorithm created and published by Manindra Agrawal, Neeraj Kayal, and Nitin Saxena, computer scientists at the Indian Institute of Technology Kanpur, on August 6, 2002, in an article titled "PRIMES is in P". The algorithm was the first one which is able to determine in polynomial time, whether a given number is prime or composite and this without relying on mathematical conjectures such as the generalized Riemann hypothesis. The proof is also notable for not relying on the field of analysis. In 2006 the authors received both the Gödel Prize and Fulkerson Prize for their work.

In computing, fixed-point is a method of representing fractional (non-integer) numbers by storing a fixed number of digits of their fractional part. Dollar amounts, for example, are often stored with exactly two fractional digits, representing the cents. More generally, the term may refer to representing fractional values as integer multiples of some fixed small unit, e.g. a fractional amount of hours as an integer multiple of ten-minute intervals. Fixed-point number representation is often contrasted to the more complicated and computationally demanding floating-point representation.

The On-Line Encyclopedia of Integer Sequences (OEIS) is an online database of integer sequences. It was created and maintained by Neil Sloane while researching at AT&T Labs. He transferred the intellectual property and hosting of the OEIS to the OEIS Foundation in 2009. Sloane is the chairman of the OEIS Foundation.

<span class="mw-page-title-main">Interior-point method</span> Algorithms for solving convex optimization problems

Interior-point methods are algorithms for solving linear and non-linear convex optimization problems. IPMs combine two advantages of previously-known algorithms:

In mathematics and computer science, a primality certificate or primality proof is a succinct, formal proof that a number is prime. Primality certificates allow the primality of a number to be rapidly checked without having to run an expensive or unreliable primality test. "Succinct" usually means that the proof should be at most polynomially larger than the number of digits in the number itself.

<span class="mw-page-title-main">Sharp EL-5120</span>

The Sharp EL-5120 is a scientific programmable calculator. It has about 1 KB of total RAM available to the user, and has 4 basic operational modes:

In mathematical optimization, the ellipsoid method is an iterative method for minimizing convex functions over convex sets. The ellipsoid method generates a sequence of ellipsoids whose volume uniformly decreases at every step, thus enclosing a minimizer of a convex function.

Fermat is a program developed by Prof. Robert H. Lewis of Fordham University. It is a computer algebra system, in which items being computed can be integers, rational numbers, real numbers, complex numbers, modular numbers, finite field elements, multivariable polynomials, rational functions, or polynomials modulo other polynomials. The main areas of application are multivariate rational function arithmetic and matrix algebra over rings of multivariate polynomials or rational functions. Fermat does not do simplification of transcendental functions or symbolic integration.

<span class="mw-page-title-main">Rexx</span> Command/scripting/programming language

Rexx is a programming language that can be interpreted or compiled. It was developed at IBM by Mike Cowlishaw. It is a structured, high-level programming language designed for ease of learning and reading. Proprietary and open source Rexx interpreters exist for a wide range of computing platforms; compilers exist for IBM mainframe computers.

Proteus is a fully functional, procedural programming language created in 1998 by Simone Zanella. Proteus incorporates many functions derived from several other languages: C, BASIC, Assembly, Clipper/dBase; it is especially versatile in dealing with strings, having hundreds of dedicated functions; this makes it one of the richest languages for text manipulation.

SUPER BASIC, sometimes SBASIC for short, is an advanced dialect of the BASIC programming language offered on Tymshare's SDS 940 systems starting in 1968 and available well into the 1970s.

References

    Notes

    Essential features consists of the following: