- General
- Basic Operations
- GCD
- Exponentiation - PowMod
- Finding Primes - The Sieve of Eratosthenes
- Factoring - Pollard Rho
- Computing the Order of Integers

Texas Instruments sells a line of programmable hand calculators with a simple programming language which is, at a simple level, compatible between calculator models. These programs have been written on a TI-86 and will be tested on models back to the TI-82 when I get the chance.

The TI series of calculators runs on a variant of the old Zilog
Z80 processor and supports computations with integers as large as
2^{46}. (The display will not display integers this large,
converting them to floating point for display, but some simple
experiments seems to show that the internal representation is still
faithful.) This means that the largest numbers which can be
used in these algorithms is 2^{23}=8388608.

A more thorough description of the TI8x and its use in basic number theory is here.

The basic arithmetic operations, `+, -, /`

, are
available from the keyboard. The factorial operation, `n!`

,
is available from the `[PROB]`

submenu of the
`[MATH]`

menu.

The modular reduction operator can either be typed in
directly from the keyboard: `MOD(37,5)`

(case is
not important), or found in the `[NUM]`

submenu of the
`[MATH]`

menu.

GCD is a built-in function and can either be typed in
directly from the keyboard: `GCD(37,5)`

(case is
not important), or found in the `[MISC]`

submenu of
the `[MATH]`

menu.

An extended GCD algorithm can be implemented with the following program.

```
Input "N ",N
```

Input "M ",M

[1,0]->L1

[0,1]->L2

Repeat (N==0)

int(M/N)->QUOT

mod(M,N)->M

L2-QUOT*L1->L2

If (M==0)

Goto XGCDEnd

int (N/M)->QUOT
mod(N,M)->N

L1-QUOT*L2->L1

End

M->N

L2->L1

Lbl XGCDEnd

Disp N,L1

The Russian Peasant method for modular exponentiation can be implemented with the following program:

```
Input "Modulus ",MD
```

Input "Element ",ELT

Input "Power ",POW

1->ACC

Repeat (POW==0)

If (mod(POW,2)==1)

mod(ELT*ACC,MD)->ACC

mod(ELT^2,MD)->ELT

iPart (POW/2)->POW

End

Disp ACC

The Sieve of Eratosthenes for finding successive primes can be implemented with the following program. The program sieves over the first 255 odd numbers, printing out the primes.

```
255 -> LNSV
```

LNSV -> dim(SEIV)

For(I,1,LNSV)

If (SEIV(I)==0)

Then

Disp 2*I+1

For(J,K,LNSV,2*I+1)

1 -> SEIV(J)

End

End

End

DelVar(SEIV)

The Pollard Rho method for factorization can be implemented with the following program:

```
Input "Number ",MD
```

2->R1

5->R2

1->FACT

Repeat (FACT!=1)

mod(R1^2+1,MD)->R1

mod(R2^2+1,MD)->R2

mod(R2^2+1,MD)->R2

gcd(abs(R1-R2),MD)->FACT

End

Disp FACT

The order of an integer in the group of units mod some
other integer (ie the smallest exponent `e` such
that `b`^{e}(mod `N`)=1)
can be computed with the following program:

```
Input "Modulus ",MD
```

Input "Element ",ELT

1 -> ORD

ELT -> ACC

Repeat (ACC==1)

mod(ELT*ACC,MD) -> ACC

ORD+1 -> ORD

End

Disp ORD

Robert Campbell Last modified: Dec 20, 1997