UBASIC
AN EFFECTIVE TOOL IN A NUMBER THEORY COURSE


UBASIC is a modified version of BASIC which can do
exact integer arithmetic and has additional built-in
functions suitable for investigations relating to properties
of integers. This software was written by Yuji Kida of
Kanazawa University in Japan and is distributed free.
 

Special Operators

Integer Division and Remainder
If x and y are integers and x = qy + r then x\y = q and x@y = r

Power
If x and y are positive integers then x^y gives the exact result
For example 2^100 = 126 765 060 022 822 940 149 670 320 537 6

Comb(n,r)
Gives the number of combinations of r elements from n
elements

Even(n)
Equals 1 if n is even and 0 if n is odd

Factorial(n)
Factorial of n

Int(x)
The greatest integer not exceeding x

Kro(m,n)
Extended Kronecker symbol for m and n. quivalent to
Legendre's symbol for qudratic residue for odd prime and to
Jacobi's symbol for odd composite n

Max(x,y) and Min(x,y)
Give the larger and smaller of x and y respectively

Mob(n)
The Mobius function: =1 if n=1, =(-1)s if n is squarefree
and has s prime factors, =0 if n is not squarefree

Modpow(a,b,n)
Gives the remainder when a raised to b is divided by n

Modinv(a,n)
Returns x such that ax(modn) = 1 if there is such x;
otherwise returns 0

Nxtprm(x)
Gives the smallest prime greater than x

Odd(x)
Gives 1 if x is odd and 0 if x is even

Prm(n)
Returns the nth prime number

Prmdiv(n)
Gives the least prime divisor of n

Res
Returns the remainder of the most recent integer division

Some programs used in teaching

Please note that these programs are kept as simple as
possible purposely so that the student may not get lost in
the intricacies of the programming or get intimidated and
lose sight of the number theoretic processes which the
program is implementing.

Euclidean Algorithm Program
Prints out each step of the division process until the
remainder is zero
10 Input number1
20 Input number2
30 spare=0
40 Repeat
50 spare=number1
60 number1=number2
70 number2=spare@number1
80 print spare, number1, spare\number1, number2
90 Until number2=0
 

Prime Factorization Program
Lists all the prime divisors of the given number
10 Input number
15 prime=2
20 Repeat
30 prime=primdiv(x)
40 quotient=number\prime
50 number=quotient
55 print prime
60 Until quotient=1
 

Solving linear diophantine equations
This program solves the linear congruence ax = 1(mod b)
where(a,b)=1. It is assumed that the Euclidean Algorithm has
been applied on a and b and the quotient q at each step has been listed.
20 c1=1:c2=0
30 d1=0:d2=1
40 input q: if q=0 then print d1,d2:stop else
50 i1=c1-q*d1:i2=c2-q*d2
60 c1=d1:c2=d2:d1=i1:d2=i2
70 goto 40