I am in the middle of making a factoring program right now on a TI-84 Plus. I was wondering if there is any code out there that will take two variables (numerator & denominator) and give me the same two variable back, simplified? (ex. A=3 B=9 would give A=1 B=3)

You could do this:

`A/B▶Frac`

This will display the most simplified fraction, if available.

:)

that creates a domain error if you place it in code normally

It doesn't create a domain error for me. ▶Frac only works by itself, or with a Disp or Pause command. If you are using Output(, then that would be the source of your domain error. If you need to use Output(, then I would recommend Xeda Elnara's method.

No, it doesn't…are you using the ▶Frac command (found in the MATH Menu)? This will take both positive and negative numbers and simplify the given fraction if possible. Double check to make sure you are using this correctly.

EDIT: Building on Myle's comment, the error would be a syntax error, not domain. It is still possible to use the method I outlined and use Disp, through slight modifications.

```
"A/B▶Frac"→Str1
Disp expr(Str1
```

or…

```
"A/B▶Frac"→Str1
Output(1,1,expr(Str1
```

:)

But that doesn't solve the problem of storing the numerator and denominator. Also, what if its an improper fraction?

Modified my code, I had put in test numbers instead of the variables :P

Since noahcavanaugh has a TI 84 Plus, any improper fractions will be simplified (if possible) and be displayed in MATHPRINT mode (which is usually enabled by default).

Assuming A and B are integers:

```
gcd(A,B→C
A/C→A
B/C→B
```

Z80 Assembly>English>TI-BASIC>Python>French>C>0

I finished the factoring program, and was wondering if anyone would notice any code I could clean up. Probably lots on this one, I didn't try very hard to keep it concise, I was just focused on getting it to work:

```
Lbl S
ClrHome
ClrDraw
AxesOff
Input "A:",A
Input "B:",B
Input "C:",C
gcd(abs(B),gcd(abs(A),abs(C))→P
A/P→A
B/P→B
C/P→C
If A≠1
Then
Goto 5
Else
abs(C)→J
Goto 1
Lbl 1
Repeat J+K=B
J-1→J
If J=0
Then
J-1→J
End
If abs(J)>abs(C)
Then
Goto 3
Else
C/J→K
End
End
If P≠1
Then
Goto 2
Else
Goto 4
Lbl 2
ClrHome
ClrDraw
Text(0,0,P,"(X+",J,")(X+",K,")"
Pause
Goto Q
Lbl 3
AxesOn
ClrHome
Disp "NOT FACTORABLE"
Disp J,K
Pause
Goto Q
Lbl 4
ClrHome
ClrDraw
AxesOff
Text(0,0,"(X+",J,")(X+",K,")"
Pause
Goto Q
Lbl 5
abs(AC)→J
Repeat J+K=B
J-1→J
If J=0
Then
J-1→J
End
If abs(J)>abs(AC
Then
Goto 3
Else
AC/J→K
End
End
Goto 8
Lbl 8
If fPart(J/A)≠0
Then
A→S
Else
1→S:(J/A)→U
End
If fPart(K/A)≠0
Then
A→T
Else
1→T:(K/A)→V
End
Goto 9
Lbl 9
gcd(abs(J),abs(K)→W
If fPart(J/A)=0
Then
1→S
U→J
Else
gcd(abs(J),abs(A))→Q
J/Q→J
A/Q→S
End
If fPart(K/A)=0
Then
1→T
V→K
Else
gcd(abs(K),abs(A))→R
K/R→K
A/R→T
End
Text(0,0,"(",S,"X+",J,")(",T,"X+",K,")"
Pause
Goto Q
Lbl Q
ClrHome
ClrDraw
Menu("SOLVE ANOTHER?","YES",Y,"NO",N
Lbl Y
ClrHome
Goto S
Lbl N
ClrHome
AxesOn
Stop
```

This is all my own original code. Thanks for the help dudes

I optimized a little, and commented where I thought things could be improved further.

```
Lbl S
ClrHome
ClrDraw
AxesOff
Input "A:",A
Input "B:",B
Input "C:",C
gcd(abs(B),gcd(abs(A),abs(C→P // Not sure why a gcd( is nested inside another gcd(
A/P→A
B/P→B
C/P→C
If A≠1
Then
Goto 5
Else
abs(C→J
Repeat J+K=B
J-1→J
If J=0
Then
J-1→J // The Repeat loop is already repeating J-1→J, so this seems kind of pointless to me.
End
If abs(J)>abs(C)
Then
Goto 3
Else
C/J→K
End
End
If P≠1
Then
Goto 2
Else
Goto 4
Lbl 2
ClrHome
ClrDraw
Text(0,0,P,"(X+",J,")(X+",K,")"
Pause
Goto Q
Lbl 3
AxesOn
ClrHome
Disp "NOT FACTORABLE
Disp J,K
Pause
Goto Q
Lbl 4
ClrHome
ClrDraw
AxesOff
Text(0,0,"(X+",J,")(X+",K,")"
Pause
Goto Q
Lbl 5
abs(AC→J
Repeat J+K=B
J-1→J
If J=0
Then
J-1→J // Again, this seems redundant
End
If abs(J)>abs(AC
Then
Goto 3
Else
AC/J→K
End
End
If fPart(J/A)≠0
Then
A→S
Else
1→S:(J/A)→U
End
If fPart(K/A)≠0
Then
A→T
Else
1→T:(K/A→V
End
gcd(abs(J),abs(K→W
If fPart(J/A)=0
Then
1→S
U→J
Else
gcd(abs(J),abs(A→Q
J/Q→J
A/Q→S
End
If fPart(K/A)=0
Then
1→T
V→K
Else
gcd(abs(K),abs(A→R
K/R→K
A/R→T
End
Text(0,0,"(",S,"X+",J,")(",T,"X+",K,")"
Pause
ClrHome
ClrDraw
Menu("SOLVE ANOTHER?","YES",Y,"NO",N
Lbl Y
ClrHome
Goto S
Lbl N
ClrHome
AxesOn
Stop
```

gcd( can be nested inside other gcd( commands to compare up to four numbers. By itself, gcd cannot accept more than two numbers, so adding gcd as an argument allows you to do that.

Thanks for your help. Yeah I nested gcd( inside another cause I needed to compare more than 2 numbers. Also, the code "J-1 stores J" is in the repeat loop twice on purpose. The first time is to minus 1 and get the next number that I am testing to see if it is a factor of C that adds to B. The second one is just so that the program skips 0, because it will attempt to divide by zero and cause the code to break.

I have not tested my optimizations as I don't have my calculator on me, but I am sure somebody else could. You have a few issues.

- Memory Leaks
- At the end you don't need to include Lbl Y, since Lbl S already has a clrhome, just have the menu jump to S
- Many places where you have memory leaks you also have unnecessary goto's. The code will continue without the goto's
- Repeated Commands; You had a pause every time before you had a Goto Q. I moved the pause into Goto Q so that it eliminates redundancies
- At the ending, you don't need a stop since that is the end of the program.
- At the ending, change the order of AxesOn and ClrHome to ensure it ends on the homescreen
- Removed some of the extra " and ) from the code
- If A=0 can be If not(A which is shorter
- If A≠0 can be If A which is shorter
- Another issue with your code that I cannot fix. To fix it would require changing your algorithm. $4x^2-9$ factors to $(2x+3)(2x−3)$ yet your program says it is unfactorable.

My Version:

```
Lbl S
ClrHome
ClrDraw
AxesOff
Input "A:",A
Input "B:",B
Input "C:",C
gcd(abs(B),gcd(abs(A),abs(C→P
A/P→A
B/P→B
C/P→C
If A≠1:Goto 5
abs(C)→J
Repeat J+K=B
J-1→J
If not(J
J-1→J
If abs(J)>abs(C):Goto 3
C/J→K
End
If P=1:Goto 4
Text(0,0,P,"(X+",J,")(X+",K,")
Pause
Goto Q
Lbl 3
ClrHome
Disp "NOT FACTORABLE
Disp J,K
Goto Q
Lbl 4
Text(0,0,"(X+",J,")(X+",K,")
Goto Q
Lbl 5
abs(AC)→J
Repeat J+K=B
J-1→J
If not(J:J-1→J
If abs(J)>abs(AC:Goto 3
AC/J→K
End
If fPart(J/A
Then
A→S
Else
1→S:(J/A→U
End
If fPart(K/A
Then
A→T
Else
1→T:(K/A→V
End
gcd(abs(J),abs(K→W
If not(fPart(J/A
Then
1→S
U→J
Else
gcd(abs(J),abs(A→Q
J/Q→J
A/Q→S
End
If not(fPart(K/A)
Then
1→T
V→K
Else
gcd(abs(K),abs(A)→R
K/R→K
A/R→T
End
Text(0,0,"(",S,"X+",J,")(",T,"X+",K,")
Lbl Q
Pause
Menu("SOLVE ANOTHER?","YES",S,"NO",N
Lbl N
AxesOn
ClrHome
```

Thanks for the help! I have pauses in there on purpose. The program displays the answer, then after the pause it asks if you want to solve another. The pause is to allow me to view the answer as long as I need to without it jumping immediately to Lbl Q. And regarding #10, that is because it didn't write it to factor binomials quite yet. As of now, it's only written to factor triomials.

I understand why you have the pauses, and If you run my code (now that I have tested it) it does pause before asking if you want to factor another. I simply moved the Pause to after the label statement. It still will pause every time, but it just takes less code to do it.

Ohh yeah your right

In order to fix Memory Leaks, I changed the code:

```
Repeat J+K=B
J-1→J
If not(J
J-1→J
If abs(J)>abs(C):Goto 3
C/J→K
End
```

to:

```
Repeat J+K=B or abs(J)>abs(C)
J-1→J
If not(J
J-1→J
C/J→K
End
if abs(J)>abs(C):Goto 3
```

This still produces the correct answer. Does this fix memory leaks effectively?

My code eliminated all memory leaks, it is hard to say if code will cause memory leaks without having the full code. Right now, it would appear like that snippet would not cause memory leaks

I didn't think your code did, because a goto still caused the code to jump out of the repeat early ?