Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: ACagliano on December 02, 2012, 12:15:09 pm

Title: PROGRAM: Polynomial Math Utility
Post by: ACagliano on December 02, 2012, 12:15:09 pm
Works on :  TI-83+, TI-83+ SE, TI-84+, TI-84+ SE, TI-84+ emulator on the TI-Nspire.

At the bequest of an old friend of mine, I fished out my really old Synthetic Division program. I was intending to fix it up and ship it off, but when I saw the code, I realized how much of a mess it was. So I started over. This program started off as a Polynomial Division Utility, but it evolved into a suite for doing all four standard operations with polynomials. The algorithms are brand new, and optimized with help from an old high school friend.

This program can theoretically handle polynomials of infinite size, but, of course, bounded by your memory. See the speed test information at the bottom. It can also handle fractional coefficients. The input occurs in descending exponent order, where the calculator will first prompt you for the number of terms in the polynomial, so for x^3+x-1, you say '4' (without the single quotes  ;) ). You will then be prompted for the coefficients. You would input 1 for exponent 3, 0 for exponent 2, 1 for exponent 1, and -1 for exponent 0. Repeat this procedure for the second operand. Alternatively, for either operand, you may enter a value of '-1', '-2', or '-3' (without the single quotes  ;) ). '-1' loads the last Operand 1 you used, '-2' loads the last Operand 2, and '-3' loads the last result. You may supply either of these three arguments at either operand prompt without issue.

Speed Test

DISCLAIMER: This speed test was conducted on my own hardware, a TI-84+ SE, running OS 2.43. While you may experience results close to this, no two pieces of hardware are exactly alike.

for Multiplication
a 19-term times a 19-term: done in 3.35 seconds.
a 37-term times a 37-term: done in 7.52 seconds.
a 73-term times a 73-term: done in 16.94 seconds.

for Division:
a 73-term divided by a 37-term: done in 7.39 seconds.
a 37-term divided by a 19 term: done in 3.21 seconds.
a 19-term divided by a 9-term: done in 1.88 seconds.
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Xeda112358 on December 03, 2012, 06:25:24 pm
I don't have much actual need for this (for a little while, anyways), but this should prove useful to many others :D
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Sorunome on December 03, 2012, 06:27:56 pm
ha, sounds nice! is it for the 84+?
Title: Re: PROGRAM: Polynomial Math Utility
Post by: ACagliano on December 03, 2012, 08:41:12 pm
Yes. Let me actually add a compatability list.
Title: Re: PROGRAM: Polynomial Math Utility
Post by: ACagliano on December 05, 2012, 10:14:09 am
Update: I just finished an update to this program that adds an input parser to the polynomial inputs. Gone is the system where you input the number of terms, then input the coefficients one-by-one. In its place, you simply input the polynomial...as a string. The program parses it and builds the lists.

Also, instead of rendering as a list, I created a list parser that converts the result back into a string, containing the polynomial. Currently testing the heck out of it. Will upload when I get my computer back from the apple store.
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Xeda112358 on December 05, 2012, 04:53:41 pm
Wooh, that will be great for regular users who may or may not understand how to input a list!
Title: Re: PROGRAM: Polynomial Math Utility
Post by: ACagliano on December 07, 2012, 03:40:03 pm
UPDATED PROGRAM

As of this version, you may input polynomials directly as you see them, not by lists or by inputting coefficients one-by-one. For instance, you may type in x^2+2x+1 as operand 1 and x+1 as operand 2 and the program will function as it did in the prior version. The output has been similarly changed. Please note, however, that negative exponents and fractional exponents are not supported.
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Xeda112358 on December 07, 2012, 03:53:23 pm
Hmm, division at least appears to be broken. For example, try X^4-1 divided by x-1. It should be x3+x2+x+1, but it outputs x3+x3+x+1.
Title: Re: PROGRAM: Polynomial Math Utility
Post by: ACagliano on December 07, 2012, 04:04:18 pm
I successfully reproduced it. Currently fixing.


Edit: Fixed.
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Xeda112358 on December 07, 2012, 04:13:15 pm
The input is nice, though, and I am glad that you support the use of 2 and 3 :) I remember I wrote a synthetic division program a few years ago, but it only took list inputs.
Title: Re: PROGRAM: Polynomial Math Utility
Post by: ACagliano on December 07, 2012, 04:26:15 pm
Thanks. Better yet, I'm trying to design an asm version. Can someone help me out with routines for all 4 operations... multiplying, adding, dividing, and subtracting 16.8 fixed point numbers...?
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Xeda112358 on December 07, 2012, 04:28:14 pm
Hmm, so it is going to support non-integers?
Title: Re: PROGRAM: Polynomial Math Utility
Post by: ACagliano on December 07, 2012, 04:49:42 pm
Yes, that's why im looking for 16.8 numbers (where 16-bits are the integer part and 8-bits are the decimal part).
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Xeda112358 on December 07, 2012, 04:57:07 pm
Basically, for division, it would be the same as 24-bit division by a 24-bit number (think about it, 11.8/22.3 = 118/223). You would need to adjust the algorithm a little to bring in the extra 8 bits of precision, though. For multiplication, you would do the same thing as 24-bit multiplication , but remember that the bottom 16 bits will be the decimal part and the upper 32 bits will be the integer part. If the upper 16 bits are not 0 or -1 (-1 is in case you have signed numbers), then there was an overflow, and if the lower 8 bits have bit 7 set, then you will need to round up the number (if you want rounding done). Addition and subtraction are also straightforward and is just like adding or subtracting 24-bit numbers.

Keep in mind that for division and multiplication, you will want to keep track of sign. I also think that there is a problem with how I described multiplication, but hopefully calc84maniac or Runer112 will be able to tell you how to do that properly.
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Sorunome on December 08, 2012, 02:20:40 am
Would you make the program have some hook then and call at some function on the homescreen (like symbolic)? That would be epic! :D
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Hayleia on December 08, 2012, 07:26:47 am
Would you make the program have some hook then and call at some function on the homescreen (like symbolic)? That would be epic! :D
That would be hard for a basic program to install hooks :P

Great program anyway :D
I have a request though. Instead of doing "operand 1", "operand 2", "operation", couldn't it just input the calculation then look for an operation sign and guess alone what the operation is and what are the operands ?
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Xeda112358 on December 08, 2012, 07:34:06 am
Wow, that would actually be cool if you managed to make a way to parse a function like that. It would be rather tough, though XD
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Hayleia on December 08, 2012, 07:52:39 am
Well in ugly basic (it's been a while since I last programmed with that :P) it can be done like that:

ClrHome
Input Str1
For(A,1,length(Str1))
If sub(Str1,A,1)="+"
Then
sub(Str1,1,A-1)->Str2
sub(Str1,A+1,length(Str1)-A)->Str3
End
End
Disp Str2
Disp Str3
Pause

Of course, this code only supports "+" but "*" and "-" can easily be added ;)
Here is a screenshot below to show what that code produces
The problem I see with "+" is that there are a lot of "+" already in the two operands so the program could not see the difference between those and the operator one :P
But anyway, that would be great for * and / :)
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Xeda112358 on December 08, 2012, 07:57:31 am
Yes, but I was thinking of nested stuff like ((x+1)(x+2)(x+3)+1)/(x^2+1)

Also, to optimise your code:
Code: [Select]
ClrHome
Input Str1
InString(Str1,"+→A
sub(Str1,1,A-1->Str2
sub(Str1,A+1,length(Str1)-A->Str3
Disp Str2
Pause Str3
:D

hmmm.../me ponders
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Sorunome on December 08, 2012, 12:53:51 pm
Would you make the program have some hook then and call at some function on the homescreen (like symbolic)? That would be epic! :D
That would be hard for a basic program to install hooks :P

Thanks. Better yet, I'm trying to design an asm version. Can someone help me out with routines for all 4 operations... multiplying, adding, dividing, and subtracting 16.8 fixed point numbers...?
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Hayleia on December 08, 2012, 01:04:41 pm
Would you make the program have some hook then and call at some function on the homescreen (like symbolic)? That would be epic! :D
That would be hard for a basic program to install hooks :P

Thanks. Better yet, I'm trying to design an asm version. Can someone help me out with routines for all 4 operations... multiplying, adding, dividing, and subtracting 16.8 fixed point numbers...?
Ah yeah, sorry, didn't see that one -.-°
Then, a hook would be great :D

Yes, but I was thinking of nested stuff like ((x+1)(x+2)(x+3)+1)/(x^2+1)

Also, to optimise your code:
Code: [Select]
ClrHome
Input Str1
InString(Str1,"+→A
sub(Str1,1,A-1->Str2
sub(Str1,A+1,length(Str1)-A->Str3
Disp Str2
Pause Str3
:D

hmmm.../me ponders
Yeah, I knew it could be optimized, I really never code in Basic :P
But nested stuff would be pretty hard in Basic since it has to keep trace of everything O.O
Title: Re: PROGRAM: Polynomial Math Utility
Post by: ACagliano on December 09, 2012, 09:08:30 am
Guys I think I am done with the TI-Basic version. There will be no further updates, beyond bug-fixes. My goal is to get an assembly version up and running, and to phase out the TI-Basic version.

On the assembly version:

- It will indeed be hook activated!
- It will support polynomial addition, subtraction, multiplication, and division, as well as integrals and derivates. It will also support solving equations with multiple variables in terms of any one variable. It will also support solving systems of equations for all variables, and solving equations with a single variable for that variable.
- In effect, my goal is to create a symbol interpreter for the TI-83+/84+.

I know this is a massive undertaking, and I don't have all the time in the world, so any assembly programmers with spare time who want to jump in on some stuff and help that would be great.
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Xeda112358 on December 09, 2012, 09:20:53 am
So it will be like Symbolic, but maybe more stuff?
Title: Re: PROGRAM: Polynomial Math Utility
Post by: ACagliano on December 09, 2012, 09:29:26 am
In a way. What features does Symbolic have?
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Xeda112358 on December 09, 2012, 09:30:36 am
Hmm, I can't remember, but I know it can find derivatives and do some symbolic math among other things.

EDIT: If you are going to make a symbolic parser, you will probably need some arbitrary precision routines, or you can just use the OSes FP routines.
Title: Re: PROGRAM: Polynomial Math Utility
Post by: ACagliano on December 09, 2012, 01:07:13 pm
Yeah. I'm thinking 16.8 Fixed Point.

Anyway, this project is being made universal. If you are a Z80 assembly programmer with some spare time, hop over to the link below (Google Docs), check out what is needed and write a routine or two, post it into the google doc, then add your name or screen name to the very bottom of the document, along with what routines you should be credited for. I'll be working on it regularly myself as well, time providing.

Also, I seem to have lost my resources on the appropriate headers for a TI Application file, so someone can edit that in to the Doc as well.

When it is done, we can publish this as a community project, rather than a project done by a single author. That allows us to make it a large, feature-dynamic project, very quickly. This will be cross posted to cemetech as well.

Link to Google Doc:
https://docs.google.com/document/d/1R5MgUPEO1muFVD_8rArb5MsTiMA5M7KATDqquwZ3wKE/edit

For a better description, head over to http://www.cemetech.net/forum/viewtopic.php?p=196685#196685
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Sorunome on December 09, 2012, 04:41:43 pm
In a way. What features does Symbolic have?
csc, sec, arcscs, arcsec, cot, arccot, csch, sech, coth, arcscsh, arcsech, arccoth, deriving, simplifiing, strtonum.
That's about it i think, but IMO symbolic anyways needs a remake as it is slow, no nice token hook and it makes graph3 crach :P
Title: Re: PROGRAM: Polynomial Math Utility
Post by: ACagliano on December 09, 2012, 04:57:24 pm
Well, my hope is to not need to use tokens at all. If you use the proper invocation string at the beginning of the input, it is automatic.
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Sorunome on December 09, 2012, 04:58:41 pm
i mean that it looks the the end user as if he has new commands on his calc like csc(
Title: Re: PROGRAM: Polynomial Math Utility
Post by: Sorunome on December 30, 2012, 03:25:58 am
So, have you made any more progress on this awesome project?