Est. 1988 Beginner

UBASIC

The multiple-precision BASIC that Yuji Kida wrote in x86 assembly as a mathematician at Kanazawa University in the mid-1980s: an MS-DOS interpreter with thousands of digits of exact integer and fixed-point arithmetic built into the language, which for a decade was how working number theorists factored, proved primes and computed class numbers on a personal computer

Created by Yuji Kida (木田祐司, born 1951), a number theorist known in his field for work on Iwasawa invariants and later on the number field sieve. He was at Kanazawa University when UBASIC was written and first published - the 1988 Sugaku article gives his affiliation as Kanazawa University, Faculty of Science - and moved to Rikkyo University in Tokyo in 1991, where he was an associate professor and, from 1997, a professor. He wrote UBASIC - interpreter, arbitrary-precision arithmetic engine, editor and all - by himself, in x86 assembly language, and gave it away free. The 1994 textbook Computer Number Theory with UBASIC was written with Kiyoo Makino

Paradigm Procedural, line-numbered BASIC, with a multiple-precision numeric tower welded into the language rather than bolted on as a library. Ordinary BASIC control flow and an interactive line editor sit on top of exact integer, fixed-point, rational, complex and single-variable polynomial arithmetic, plus number-theoretic primitives (gcd, Kronecker symbol, Moebius function, Euler totient, trial division) available as ordinary built-in functions
Typing Dynamic and BASIC-flavoured, with size chosen by declaration rather than inferred. The 1988 language distinguished 16-bit short variables, long variables of a length the programmer sets, and fixed-maximum special variables, each with array forms; later versions add strings, rationals, complex numbers, polynomials and polynomials over Z/pZ. Precision is a program-level setting: the WORD and POINT commands set how many words an integer and the fractional part of a fixed-point number may occupy
First Appeared Publicly, late 1988, when Kida described the language in the Mathematical Society of Japan journal Sugaku (vol. 40 no. 4, issue date 14 November 1988). Privately it was older - that same article says the interpreter had by then been working for about two years, which places the first version around 1986. It was originally called UBASIC86, for the NEC PC-9801 and compatibles, and the name is the one that appears on every published manual
Latest Version 8.8f, dated 8 October 2000 on Kida's own download page, in the seven machine-specific builds his download page had listed since 8.8c (DOS/V 16- and 32-bit, Fujitsu FMR 16- and 32-bit, NEC PC-98 16- and 32-bit, and a CGA build the page labels for the HP 200LX). An experimental version 9 existed - some add-ons, notably the number field sieve program, required it - and the assembly sources that survive on GitHub carry file dates as late as 3 October 2004, but no version 9 was ever released as a finished product

UBASIC is what happens when a working number theorist decides that the computer on his desk should be able to do arithmetic properly, and writes the whole interpreter in assembly language himself. It is a line-numbered, thoroughly ordinary-looking BASIC for MS-DOS in which PRINT 23^45 prints all sixty-two digits, POINT 21 sets the fractional part of every fixed-point number to a hundred-odd decimal places, and PRMDIV, KRO, MOB and EUL are built-in functions rather than a library you have to find. Between the late 1980s and the late 1990s it was, for a large number of mathematicians, simply how you computed on a personal computer.

The catalogue entry that brings most people here spells it “UBasic” and dates it to 1988. The spelling the author used is UBASIC, and originally UBASIC86 - the “86” for the Intel 8086 family in the NEC PC-9801 it was born on. The year needs a footnote too, and the footnote is in Kida’s own hand.

Origins: two years before anyone heard of it

Yuji Kida is a number theorist known for work on Iwasawa invariants of algebraic number fields and later for factoring cyclotomic numbers with the number field sieve. He is usually described as a Rikkyo University man, and by the time UBASIC had a home page that is what he was - but he only moved to Rikkyo in 1991. Through the years UBASIC was actually written he was at Kanazawa University, and Kanazawa is the affiliation printed on the article that first announced it. In late 1988 he published a five-page article in Sugaku, the journal of the Mathematical Society of Japan, under the title “UBASIC, a personal-computer programming language for calculating with large numbers easily” (vol. 40 no. 4, pages 344-348; J-STAGE records the issue date as 14 November 1988). It is the earliest datable record of the language, and it is also the best account of why it exists.

Kida’s complaint, in the opening section, is that mathematicians had by then acquired personal computers and stopped using them to compute. Word processing, yes; arithmetic, no. Part of the reason was that mathematics had less need of computation than it once had, but the larger part, he argued, was that the machines and their software did not fit what mathematicians actually wanted. The concrete example he gives is exactly the one his language solves: current software approximates numbers to a precision assumed to be enough, which is useless for integer work where the last digit has to be right, and hopeless if you want a thousand digits of pi. Anyone who has written a 1,000-digit pi program from a BASIC primer, he notes drily, will remember how tiresome it was.

The available alternatives he dismisses one by one. Computer algebra on a mainframe is a high threshold for people who only came to computing because personal computers made it approachable, and you lose the thing that makes BASIC comfortable - moving the cursor to a line, changing it, running it again. Systems like REDUCE had begun to run on personal computers, but on the machines people actually owned the memory was far too tight and the price too high to recommend to anyone. Using a computer algebra system purely for numerical work felt, he wrote, like overkill. And bignum arithmetic in LISP raised the obvious objection: why should someone who wants to do arithmetic have to learn all those incomprehensible parentheses first?

What was wanted was a compact, fast language that did nothing but numbers, and that is what UBASIC was. By the time of the article the interpreter had been running for a full two years - which puts its first working version at around 1986 - and already had users in the United States, Britain and Germany. The first commercially published manual, two years later still, is for version 8.1.

He was aware of one precedent. In France, he notes, a system of this kind had been built as early as 1979 as a project of the CNRS, elegantly named ISABELLE, introduced to Japanese readers by Kenji Nagasaka in bit magazine in July 1982. He mentions it as something that existed, not as a model; the United States, Britain and Germany, he adds, had nothing of the sort, probably because American networks put a terminal everywhere and made mainframe computer algebra easy to reach.

Design philosophy: BASIC because BASIC

Kida’s own introductory blurb for the language, reproduced in 1996 on a page maintained by Aiichi Yamasaki at Kyoto University, is unusually candid about why the syntax is what it is:

UBASIC86 is a language made out of that requirement. Its form conforms to ordinary BASIC so that anyone can use it. BASIC is, as the specialists point out, a language with bad habits and real problems, but for non-specialists the fact that it is easy to learn and, once learnt, never forgotten - is there enough in it to forget? - is worth more than anything. And for those of us who only write short programs, its defects do not come up much. Of course there is also my own convenience: it is easy to build a language like this.

That is the whole philosophy. The novelty is not in the language; it is in the number system underneath it, and in the decision to make that number system the default rather than an add-on. Three consequences follow.

No floating point, on purpose. The 1988 language had fixed-point decimals only. Kida’s stated reasons: floating point is a nuisance to implement; his own calculations never produce exponents like Planck’s constant or Avogadro’s number, so fixed point suffices; and convergence tests and error estimates in series computations are simpler without it. He then asks the question that settles it - what would you actually use a floating-point number with a 1,000-digit mantissa for?

Exactness where BASIC was sloppy. He singles out the square root SQR, which in UBASIC returns exactly the nearest value from below, against ordinary BASICs where the square root of the square of a number in the hundreds might not come back as the number you started with. Integer powers are likewise exact, where a conventional BASIC implements ^ through EXP and LOG and cannot avoid error.

The remainder is free. Alongside the four arithmetic operations, UBASIC provides remainder and exact integer power, and after an integer division the remainder is already sitting in a system variable - no need to compute it again. As Kida notes, this is used constantly in number theory.

The language

In the 1988 version, the numeric ceiling was a little over 5,500 decimal digits, for both integers and the fractional parts of fixed-point numbers, the latter set by the POINT command. Variables came in three flavours - 16-bit short variables, long variables whose length the programmer specifies up to the maximum, and fixed-maximum special variables - each with an array form, with no 64 KB limit on a single array. Number-theoretic functions were in the box: gcd, the Kronecker symbol KRO, the Moebius function MOB, Euler’s totient EUL, and PRMDIV for trial division.

The article is equally frank about what was wrong, closing with a list of things that had to be improved: only two characters allowed in a variable name (“two generations behind the state of the art even in the personal computer world”), no local variables, no function subroutines, no way to pass arguments to a subroutine. All of these were fixed in the version 8 line, which is the UBASIC most people encountered: local variables and parameters passed by value or by name, subroutines and user functions passable as parameters themselves, exact rational arithmetic, complex numbers, strings, and single-variable polynomials with complex, rational or mod-p coefficients. By 1993 the practical limits, as quoted by chemists at Kida’s own university, were 2,600 digits for integers and reals and 1,300 for complex and rational numbers; Kida’s own download page described the language as suited to integers up to 2,700 digits.

Here is the flavour, taken from the 1988 article - a naive series for e, summing 1/n! until the term underflows the declared precision:

1
2
3
4
5
6
20 E=0:W=1:N=0
30 E=E+W
40 N=N+1
50 W=W/N
60 if W>0 then goto 30
70 print E

With POINT set to 21 words - 101 decimal digits - this printed e to a hundred places. Kida records the run as taking 0.07 seconds including the time to display the result, on an 80286 at 16 MHz, and then points out that you did not need the program anyway, because EXP is built in.

The interactive side was as important as the language. UBASIC’s editor could cross-reference the lines that call a given line or mention a given variable, renumber, rename variables, append programs, trace, single-step and time sections to the millisecond, and redefine function keys. FREEZE wrote a running program and its data to a file and MELT brought it back, which for computations measured in days mattered a great deal - as did the plain fact that in an interpreter you can edit a program mid-run and resume it with GOTO without losing what you have accumulated.

Under the hood: assembly, all of it

The version 9 sources, released to the public domain on GitHub in December 2022 by a user who had asked Kida for them in 2014, settle the question of how UBASIC was built. There are 41 files and about 1.14 MB of them, and they are x86 assembly without exception: FLOAT.ASM, POLYNOMI.ASM, RATIONAL.ASM, COMPLEX.ASM for the numeric tower, MAINLP.ASM, JUMP.ASM, COMPILE.ASM, FORMULIN.ASM for the interpreter, EMA32.ASM for extended memory, vga16.asm and graph.asm for graphics, FREZMELT.ASM for freeze and melt. The person who published them adds a note that Kida had been planning a newer version in C or C++, but that he had never seen it.

This is also why UBASIC exists in so many builds. Each release came in seven flavours - DOS/V in 16- and 32-bit, Fujitsu FMR in 16- and 32-bit, NEC PC-98 in 16- and 32-bit, and a CGA build for the HP 200LX palmtop - and the 16 and 32 in those labels refer to the width of the multiplication engine, not to the host processor. The download page listed each of them at between about 103 KB and 111 KB, depending on build and release.

Release history and the long decline

Kida’s download page, preserved in the Wayback Machine, is the release log: version 8.8c on 15 April 1998, 8.8e on 14 December 1999, and 8.8f on 8 October 2000, which turned out to be the end. Between the last two came the add-ons the factoring crowd wanted - PPMP, a multiple-polynomial quadratic sieve, v3.6 on 24 December 1999, and a number field sieve program v1.8 on 31 January 2000, the latter requiring the never-released version 9.

The site’s own bug notices give a sense of the maintenance rhythm: a FOR-NEXT bug documented on 13 July 1997, a page on running under Windows NT 3.51 and 4.0 dated 20 October 1996, and a cheerful admission on 1 January 2000 that the language everyone had assumed was immune to the millennium problem in fact printed the date as “20 0/ 1/ 1”, a missing zero, fixed nine months later in 8.8f. There was also a benchmark page comparing UBASIC across the processors of the day, whose title grew with each revision - “P5, P6, K6, PII, Celeron and K6-2” in November 1998, “P5, P6, Celeron, K6-2, MII, K6-III, PIII and Athlon” a year later, and “PIII, K7, Coppermine and Thunderbird” by November 2000 - which is the kind of thing an author only does when people are running his software on everything.

The last sign of life is a short page of 5 April 2010 on running UBASIC under Windows Vista and 7: add kb16 jp,932,key01.sys to the end of windows\system32\autoexec.nt to get the Japanese keyboard layout back, prefix the command with command/c to keep the display in Japanese, and, for 64-bit Windows, install a virtualisation layer - because 64-bit editions of Windows dropped the 16-bit subsystem UBASIC depends on. That is the wall UBASIC hit, and it is a hardware-and-OS wall rather than a mathematical one.

Reception outside Japan

UBASIC travelled early. The 1988 article already reports confirmed users in the United States, Britain and Germany. Distribution abroad was by anonymous FTP, with separate Japanese and international (IBM PC) builds, and the international builds were picked up by the general MS-DOS mirrors - Simtel carried a ubasic directory for years. In May/June 1989 Walter D. Neumann reviewed it for the Notices of the American Mathematical Society under the title “UBASIC: A public-domain Basic for mathematics” (volume 36, number 5, pages 557-559), returning to it with “UBASIC Update” in the March 1991 Notices (volume 38, number 3, pages 196-197) - the kind of notice that put a Japanese freeware interpreter on the desk of number theorists worldwide.

Its most visible legacy outside Japan is APRT-CLE. Implementing the Adleman-Pomerance-Rumely primality test in the Cohen-Lenstra formulation published in Mathematics of Computation in 1987, it made rigorous primality proofs of several-hundred-digit numbers a thing you did on a PC while doing something else. Dubner and Granlund’s 2000 survey is a fair snapshot of how it was used in practice: everything below about 800 digits proved with APRT-CLE, whose upper test limit they give as about 830 digits, and everything above it handed to Tony Forbes’s VFYPR, itself an extension of the UBASIC program. VFYPR, they report on Forbes’s own authority, ran about twice as fast and could reach 1600 digits; a 1200-digit test cost roughly 40 hours on a Pentium/500, and 1200 digits is where they stopped, for want of machine time rather than headroom.

Running UBASIC today

There is no Docker image, and a container would not help: UBASIC is a real-mode MS-DOS program. The realistic routes are DOSBox or a DOS virtual machine, or a 32-bit Windows installation, where it still runs in a command prompt with the workarounds from Kida’s 2010 page. Kida’s own site stopped answering years ago, but the Japanese software archive Vector still carries DOS/V and English IBM-PC builds, in 16- and 32-bit, along with the help file and the sample programs - uploaded by Kida himself, under the handle ykida, and dated in Vector’s listing to 7 January 1999 - and the version 9 assembly sources are on GitHub in the public domain for anyone who wants to see how it was done, or to finish the C rewrite Kida never shipped.

Modern practice has, in fairness, moved on. PARI/GP, which arrived from Bordeaux in the same era and did not stop, occupies the niche UBASIC was built for, and Primo and open-source APR-CL and ECPP implementations long ago passed the ranges APRT-CLE could reach. UBASIC’s presence in today’s code-sharing culture is correspondingly thin: Rosetta Code has a UBASIC category with exactly one task in it, the Haversine formula.

Why it matters

UBASIC is the strongest counter-example to the assumption that a domain-specific computing environment has to be a new language. Kida changed nothing about BASIC that a 1980s hobbyist would notice, and changed everything about the numbers underneath it, and the result was a tool that people who had never programmed at all could use “with roughly the ease of a calculator” - his phrase - to compute class numbers and Hecke polynomials. Familiar syntax was the delivery mechanism; exact arithmetic was the product.

It is also a reminder of how much one person could still build alone in that era, and how completely a platform can take a language down with it. A single mathematician wrote a multiple-precision arithmetic engine, an interpreter, a full-screen editor and a graphics library in x86 assembly, gave them away, and supported them for the better part of two decades. What ended UBASIC was not a better BASIC or a lost argument about language design. It was Microsoft removing the 16-bit subsystem from 64-bit Windows.

Timeline

1986
Approximate date of the first working interpreter. Kida gives no exact date, but in October 1988 he writes that UBASIC had by then been running for a full two years. The motivation he describes is a practical one: a mathematician who wants a thousand digits of a constant, or the fundamental unit of a real quadratic field, has to choose between a computer algebra system on a mainframe and writing multiple-precision routines by hand in BASIC, and neither is convenient on the personal computer that is actually on the desk
1988
Kida publishes a five-page description of UBASIC86 in Sugaku 40(4), 344-348, the journal of the Mathematical Society of Japan, under a Kanazawa University affiliation; J-STAGE gives the issue date as 14 November 1988. It is the earliest document that can be dated. The language at that point handles integers and fixed-point decimals of just over 5,500 digits, has no floating point at all by deliberate choice, is limited to two-character variable names, and has neither local variables nor parameters to subroutines. It already has users in the United States, Britain and Germany
1989
UBASIC reaches the wider mathematical world: in the May/June issue of the Notices of the American Mathematical Society, Walter D. Neumann publishes "UBASIC: A public-domain Basic for mathematics" (vol. 36 no. 5, 557-559), following it with "UBASIC Update" in the March 1991 Notices (vol. 38 no. 3, 196-197). Distribution outside Japan is by anonymous FTP and, later, by mirrors such as SimTel; separate Japanese and international (IBM PC) builds are maintained throughout
1990
The first commercially published manual appears: UBASIC86 Ver. 8.1 User's Manual - Multiple-Precision BASIC, for the NEC PC-9801 and Compatibles, from Nippon Hyoron Sha. That the very first published manual is for version 8.1 is the clearest evidence of how much development had already happened in private. Manuals for 8.2 (1991), 8.3 (1992) and 8.7 (1994, ISBN 4-535-60012-0) follow
1992
Mitsuo Morimoto publishes Introduction to Analysis with UBASIC (Nippon Hyoron Sha), the first of the textbooks that use the language as a teaching vehicle rather than a research tool. By this point the version 8 line has grown the features the 1988 article listed as missing - local variables, subroutine parameters, longer names - and added exact rational arithmetic, complex numbers, strings and single-variable polynomials with complex, rational or mod-p coefficients
1994
Kida and Kiyoo Makino publish Computer Number Theory with UBASIC (Nippon Hyoron Sha), the book that fixes the language's reputation as the number theorist's pocket laboratory. Kida maintains an errata and addenda page for it on his site for years afterwards, last updated 9 July 1999
1996
20 October: Kida posts a note on running UBASIC under Windows NT 3.51 and NT 4.0. This is the beginning of a long second life in which a DOS program survives inside successive Windows command shells - the download page for years advises that UBASIC runs in the Windows 95 and NT DOS window "except for special cases"
1998
15 April: version 8.8c, offered as seven separate downloads - DOS/V 16-bit and 32-bit, FMR 16-bit and 32-bit, NEC PC-98 16-bit and 32-bit, and a CGA build the page labels for the HP 200LX palmtop - listed at between 103 KB and 109 KB apiece. The (16) and (32) in the version labels refer to the width of the multiplication engine, not the host processor
1999
14 December: version 8.8e. Two weeks later Kida posts the PPMP multiple-polynomial quadratic sieve factoring program v3.6 (24 December 1999), and on 31 January 2000 a number field sieve factoring program v1.8 - at 205 KB, the largest add-on he ever shipped, and one that required the unreleased version 9
2000
8 October: version 8.8f, the last release, which among other things fixes the Y2K bug Kida had reported on his own front page on 1 January 2000 - PRINT DATE had been showing "20 0/ 1/ 1", dropping a zero. In the same year Harvey Dubner and Torbjorn Granlund report using UBASIC's APRT-CLE to prove primality of numbers up to about 800 digits in their survey of primes of the form (b^n+1)/(b+1)
2004
3 October: the date on the newest files (UB.H and FUNC.ASM) in the version 9 assembly source tree that survives today. Version 9 was used for the heaviest add-ons but never became a finished, published release, and after this the tree goes quiet
2010
5 April: Kida's last recorded note on the language, a page explaining how to run UBASIC on Windows Vista and 7 - add a kb16 line to autoexec.nt to get the Japanese keyboard layout back, prefix the command with command/c to stop the display reverting to English - and stating plainly that on 64-bit Windows it will not run at all without a virtualisation layer, those editions having dropped the 16-bit subsystem
2022
14 December: the version 9 sources - 41 x86 assembly and header files, about 1.14 MB - are published on GitHub by a former user who had asked Kida for them in 2014 and received them by e-mail, and are dedicated to the public domain under the Unlicense. They confirm what the manuals only implied: the whole system, arithmetic engine, interpreter, editor and VGA graphics included, is hand-written assembly

Notable Uses & Legacy

Number-theory research in Japan

By 1988 Kida could already list what colleagues were doing with it: computing class numbers of real quadratic fields and of abelian fields, experiments with Dedekind sums, and calculations of Hecke polynomials. His point about why it caught on is worth repeating - for number theory, if the language supplies a handful of number-theoretic functions, the rest of the program is usually easy, so people who had never written a program at all could use it with roughly the ease of a calculator

Prime proving with APRT-CLE

UBASIC shipped an implementation of the Adleman-Pomerance-Rumely primality test in the Cohen-Lenstra formulation (Mathematics of Computation 48, 1987), known as APRT-CLE, and for years it was the practical tool of choice in its range. Harvey Dubner and Torbjorn Granlund, surveying primes of the form (b^n+1)/(b+1) in the Journal of Integer Sequences in 2000, state that probable primes up to about 800 digits were proved with "the prime proving program, APRT-CLE of UBASIC", which they give an upper test limit of about 830 digits; above that they switched to Tony Forbes's VFYPR, "an extended version of the UBASIC program", which they report (citing a personal communication from Forbes) can test up to 1600 digits and is about twice as fast as UBASIC, a 1200-digit test taking about 40 hours on a Pentium/500. Their own runs stopped at 1200 digits, a limit they say was chosen arbitrarily on grounds of available computer time

High-precision curve fitting in chemistry

Yoshio Narisawa and Yuichi Miyamae used UBASIC for least-squares polynomial fitting of water-density data (0 to 30.5 degrees C in half-degree steps) in the Journal of Chemical Software, vol. 1 no. 2 (1993), p. 99 - explicitly because the arithmetic was exact enough to survive the ill-conditioning of a high-degree fit. They are careful to say they are not proposing UBASIC as a replacement for FORTRAN, only showing where very high precision pays; running the same fits in BASIC, in MS-FORTRAN and in FORTRAN on a Sun, they report that MS-FORTRAN's double-precision sums of squared error stopped improving and scattered badly at high degree where UBASIC's did not. Their opening description of the language gives its capacity as 2,600-digit integer arithmetic

University teaching and courseware

The National Diet Library catalogue records a steady trickle of Japanese teaching papers built on UBASIC through the 1990s: a linear-algebra CAI system by Makoto Kojima at Toyohashi Junior College (1995), a construction of the RSA public-key cryptosystem by Teruo Asanuma and Akiko Ueda in the science series of the bulletin of the University of Toyama's Faculty of Education (issue 50; the catalogue record carries no year, and the run spans 1993-1998), papers on using UBASIC in secondary and university mathematics teaching (1992, 1993), and lecture pages maintained by staff at Kyoto, Aichi University of Education and Shimane

Two published textbooks

Mitsuo Morimoto's Introduction to Analysis with UBASIC (1992) and Kida and Kiyoo Makino's Computer Number Theory with UBASIC (1994), both from Nippon Hyoron Sha, alongside four editions of the official user manual (8.1, 8.2, 8.3 and 8.7) from the same publisher between 1990 and 1994. Few freeware interpreters of the era acquired a shelf of trade books

Factoring add-ons: ECMX, PPMP and NFS

Kida distributed his own factoring programs written in and around UBASIC, and considered them the selling point: the 1988 article says the practicality of the language was proved by making the factorisation programs fast enough. The published add-ons include the PPMP multiple-polynomial quadratic sieve (v3.6, 24 December 1999) and a number field sieve implementation (v1.8, 31 January 2000) that needed the experimental version 9; the elliptic-curve program ECMX, which drops into machine code for speed, circulated widely among hobbyist factorers

Language Influence

Influenced By

Running Today

Run examples using the official Docker image:

docker pull
Last updated: