Saturday, December 1, 2012

Numeric CAS Part 1: Simplifying Square Roots

Simplifying Square Roots

Goal: Simplify square roots of integers. For example, √180 = 6 √5, √80 = 4 √5

General Algorithm: Start with integer N and C=1. Starting with k=2, divide N by k². If N divides k² evenly, N is adjusted, C is multiplied by k, and the division is test is repeated. If N does not not divide k², k increases by 1 and the division test repeats. The division tests repeat until k² > N.

The program for the Casio Prizm, TI-84+, and HP 39gii are presented below:


Casio Prizm:

SQFACTOR
11/19/2012
Simplifies √N where N is an integer (i.e. √180 = 6 √5, √364 = 2 √91)
156 bytes

"√N="? → N
N → M
1 → C
2 → K
Do
Lbl 1
If Frac(N ÷ K²)=0
Then
N ÷ K² → N
C × K → C
Goto 1
IfEnd
K + 1 → K
LpWhile K²
ClrText
Locate 1,1,"√"
Locate 2,1,M
Locate 1,3,C
Locate 10,3,"×√"
Locate 12,3,N


TI-84+:

SQFACTOR
Square Root Simplification
(I.E. √180 = 6 √5 , √364 = 2 √91)
11/19/2012
133 bytes

Input "√(", N
N → M
1 → C
2 → K
Lbl 0
If fPart(N/K²)=0
Goto 1
1 + K → K
If K² < N
Goto 0
ClrHome
Output(1,1,"√(")
Output(1,3,M)
Output(3,1,C)
Output(3,7,"√(")
Output(3,9,N)
Stop
Lbl 1
N/K² → N
C*K → C
Goto 0


HP 39gii:

SQFACTOR
11/23/2012
Simplifies √N where N is an integer (i.e. √180 = 6 √5, √364 = 2 √91)

Input: SQFACTOR(N)

EXPORT SQFACTOR(N)
BEGIN
LOCAL C,K;
1 → C;
2 → K;
WHILE K² < N DO
WHILE FRAC(N/K²) == 0 DO
N/K² → N;
C*K→ C;
END;
K+1→K;
END;
RETURN string(C)+"√"+string(N);
END;




This blog is property of Edward Shore. 2012

Spotlight: Sharp EL-5200

  Spotlight: Sharp EL-5200 As we come on the 13 th (April 16) anniversary of this blog, I want to thank you. Blogging about mathematic...