Author Topic: Calcalca  (Read 27450 times)

0 Members and 1 Guest are viewing this topic.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Calcalca
« on: May 28, 2010, 06:36:25 pm »
I'm pretty sure this hasn't really been done before, at least in TI-BASIC, but if something similar exists, please notify me.

Last year, I was absolutely amazed by the simplicity and ingenuity of Google Calculator, especially where you can type in any expression using any units (and an optional unit to convert to), and I decided that that was something someone needed to code for TI calculators. Thus I went on a coding rage, and actually got much of it done within a month, to the point where you could type in something like 7 M * IN INTO CM CM and it would display 1778. Unfortunately, I couldn't figure out division, parentheses, or exponents, so I set it aside and continued with other projects. One day, I really needed to clear some ARC space, so I deleted the group where I had saved it (I called it CALCALCA). I finally started regretting this decision, and will start coding it again, but I really need help with the issues I mentioned above.

This is what I've decided for the program so far:
1. It will use a blank input (Input "",Str1) to input a continuous expression.
2. The resultant string will searched through first for illegal characters.
3. The string is checked a second time, this time for the characters " INTO " (which specifies that the following units say what unit the user wants)
4. First, "(" is added to the beginning, and ")" to the end, just for padding (i.e., "("+Str1+")"→Str1)
5. The string is then evaluated, one character at a time.
    a. Whenever it hits a space, it tests to see whether * follows it.
        i. If there is one, the space is deleted by using sub('s for the two sides of the string.
        ii. If there is not, the space is replaced with )(, which assumes the space meant implied multiplication.

    b. Whenever it hits a letter, a subloop gets the entire combination of letters, which is saved to another string for checking.
        i. The second string is checked against a database of all the units to be supported (see note below).
        ii. If there is a match, that entire section of the main string is replaced with the numerical value of the unit, surrounded by "(" and ")", and the unit's base units are added to a list (see second note below). matrix.
    c. Whenever it hits a number, ".", "*", or "E", it it added directly.
    d. Whenever it hits a "(", the matrix is widened by one, and base units added from then on are added to the new column.
    e. Whenever it hits a ")", it stored the rightmost column into L1 and checks the following character.
        i. If it is a "-1", L1 is inverted.
        ii. If it is a "2", L1 is doubled.
        iii. If it is a "^", another subloop is used to get the entire number following it, and L1 is multiplied accordingly.
        iv. L1 is integrated into the next-rightmost column of the matrix.

6. When this is all done, the program will evaluate the string (with an exp() and (theoretically) appends the final unit.

Note:
The database consists of a huge (literally, huge, and might even be larger than the program itself) string containing each supported unit in the format:
Code: [Select]
"   2            Pa           -1    01    00    -2             1.00000000           ..."
    ^            ^            |                  |                  ^                ^
    |            |            +------------------+                  |                |
    |            |                     |                            |                |
Length of     Unit name.    These four numbers are the       How many of the      Continue
unit name.                  base units for the unit, in      unit fit into        onto next
                            the order {length, mass,         the base unit.       unit.
                            current, time}. For example,     Since pascals are
                                Pa=N/(m^2)                   the base for
                                =(kg*m/(s^2))/(m^2)          pressure, this
                                =kg/(s^2)/m                  would be a one
                            so is mass (the positive         (the zeroes are
                            one) divided by time squared     because it needs
                            (the negative two) divided by    to have exactly
                            length (the negative one).       ten characters).

Anyone willing to help me with this program? I currently have several programs in development simulataneously, and I can't finish this myself.
By the way, if anyone can't read the above code, I attached it as a .txt:
« Last Edit: July 17, 2010, 10:24:11 pm by Deep Thought »




Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Calcalca
« Reply #1 on: May 28, 2010, 07:07:19 pm »
I can probably help some, or can try. I'm not exactly for sure what you are trying to do for sure though.

One thing I noticed though is you can just have Input Str1 instead of Input "",Str1.

Actually scratch that. I forgot that it puts a ? there, which I don't see as in issue but ya, I'm not you.
« Last Edit: May 28, 2010, 07:09:13 pm by meishe91 »
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline jsj795

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1105
  • Rating: +84/-3
    • View Profile
Re: Calcalca
« Reply #2 on: May 28, 2010, 07:15:39 pm »
I'll try to help. I tried to make the BASIC program that gives the derivative using string. Although I didn't finish it, developing it helped me understand a lot about strings and doing math stuff with the string.
But I don't have my calc atm, and will be able to help you after around mid-June.


Spoiler For funny life mathematics:
1. ROMANCE MATHEMATICS
Smart man + smart woman = romance
Smart man + dumb woman = affair
Dumb man + smart woman = marriage
Dumb man + dumb woman = pregnancy
2. OFFICE ARITHMETIC
Smart boss + smart employee = profit
Smart boss + dumb employee = production
Dumb boss + smart employee = promotion
Dumb boss + dumb employee = overtime
3. SHOPPING MATH
A man will pay $2 for a $1 item he needs.
A woman will pay $1 for a $2 item that she doesn't need.
4. GENERAL EQUATIONS & STATISTICS
A woman worries about the future until she gets a husband.
A man never worries about the future until he gets a wife.
A successful man is one who makes more money than his wife can spend.
A successful woman is one who can find such a man.
5. HAPPINESS
To be happy with a man, you must understand him a lot and love him a little.
To be happy with a woman, you must love her a lot and not try to understand her at all.
6. LONGEVITY
Married men live longer than single men do, but married men are a lot more willing to die.
7. PROPENSITY TO CHANGE
A woman marries a man expecting he will change, but he doesn't.
A man marries a woman expecting that she won't change, and she does.
8. DISCUSSION TECHNIQUE
A woman has the last word in any argument.
Anything a man says after that is the beginning of a new argument.

Girls = Time * Money (Girls are a combination of time and money)
Time = Money (Time is money)
Girls = Money squared (So, girls are money squared)
Money = sqrt(Evil) (Money is also the root of all evil)
Girls = sqrt(Evil) squared (So, girls are the root of all evil squared)
Girls = Evil (Thus, girls are evil)
*Girls=Evil credit goes to Compynerd255*

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Calcalca
« Reply #3 on: May 28, 2010, 07:28:45 pm »
I can probably help some, or can try. I'm not exactly for sure what you are trying to do for sure though.

One thing I noticed though is you can just have Input Str1 instead of Input "",Str1.

Actually scratch that. I forgot that it puts a ? there, which I don't see as in issue but ya, I'm not you.

Basically, this will be a program, written in pure BASIC, that will do complex unit conversion/calculations. By the time this program is done, I'm hoping that it will accept input such as 5 kg*m2/s2 INTO cal and display the answer as 1.19502868.

Yeah, I will use Input "", Str1 simply because I want it to look as natural as possible, and without the "?", it looks exactly like the main TI-OS homescreen.

I'll try to help. I tried to make the BASIC program that gives the derivative using string. Although I didn't finish it, developing it helped me understand a lot about strings and doing math stuff with the string.
But I don't have my calc atm, and will be able to help you after around mid-June.

Well, that's unfortunate. I can only upload files until mid-June.

Doesn't matter, though. I'll post updates in other ways.

EDIT: Just thought of something: The newest version of WabbitEmu supports exporting variables, right?

EDIT2: Wow, there's a lot more traffic on Omnimaga.
« Last Edit: May 28, 2010, 11:43:04 pm by Deep Thought »




Offline jsj795

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1105
  • Rating: +84/-3
    • View Profile
Re: Calcalca
« Reply #4 on: May 28, 2010, 07:31:20 pm »
EDIT: Just thought of something: The newest version of WabbitEmu supports exporting variables, right?
Well, I never used that feature so, I don't know for sure :/
You can post whatever you have until the time you'll be able to upload and I'll try to pick it up from there
« Last Edit: July 10, 2012, 03:58:04 pm by Deep Thought »


Spoiler For funny life mathematics:
1. ROMANCE MATHEMATICS
Smart man + smart woman = romance
Smart man + dumb woman = affair
Dumb man + smart woman = marriage
Dumb man + dumb woman = pregnancy
2. OFFICE ARITHMETIC
Smart boss + smart employee = profit
Smart boss + dumb employee = production
Dumb boss + smart employee = promotion
Dumb boss + dumb employee = overtime
3. SHOPPING MATH
A man will pay $2 for a $1 item he needs.
A woman will pay $1 for a $2 item that she doesn't need.
4. GENERAL EQUATIONS & STATISTICS
A woman worries about the future until she gets a husband.
A man never worries about the future until he gets a wife.
A successful man is one who makes more money than his wife can spend.
A successful woman is one who can find such a man.
5. HAPPINESS
To be happy with a man, you must understand him a lot and love him a little.
To be happy with a woman, you must love her a lot and not try to understand her at all.
6. LONGEVITY
Married men live longer than single men do, but married men are a lot more willing to die.
7. PROPENSITY TO CHANGE
A woman marries a man expecting he will change, but he doesn't.
A man marries a woman expecting that she won't change, and she does.
8. DISCUSSION TECHNIQUE
A woman has the last word in any argument.
Anything a man says after that is the beginning of a new argument.

Girls = Time * Money (Girls are a combination of time and money)
Time = Money (Time is money)
Girls = Money squared (So, girls are money squared)
Money = sqrt(Evil) (Money is also the root of all evil)
Girls = sqrt(Evil) squared (So, girls are the root of all evil squared)
Girls = Evil (Thus, girls are evil)
*Girls=Evil credit goes to Compynerd255*

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Calcalca
« Reply #5 on: May 28, 2010, 07:44:07 pm »
And I'll try to help however I can too.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Calcalca
« Reply #6 on: May 28, 2010, 11:50:52 pm »
Thanks!

Anyway, I'm currently working on the data string. Here's an example for the length functions I've included so far:

:"1m  010000001.000000002in 0100000039.37007872ft 010000003.280839902yd 010000001.093613302mi 010000006.21371E-4...

The problem I'm already seeing now is that I have to include 8 characters for the unit combination every time I add another unit, even if it's exactly the same as for the previous few units (in this case, 01000000). If I could get rid of most of them, it would free up a lot of memory, but then it'd be somewhat hard to access the unit type of an individual unit. Can anyone think of better way to do this?

EDIT: Biblical cubits are now supported for the fun of it. :)
« Last Edit: June 07, 2010, 09:35:17 am by Deep Thought »




Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Calcalca
« Reply #7 on: May 29, 2010, 12:02:40 am »
Seems interesting, altough I've been out of hi school (the last time I ever had math classes) since 2003, so I am not into math stuff anymore, so I doubt I would be able to help much. I can't wait what you will come up with this, though, and I hope people can help.

Quote
Well, that's unfortunate. I can only upload files until mid-June.
Do you mean you do not have internet access at home, only at school? I remember when I was in that situation. Very hectic x.x (altough I generally got a lot of free time for programming :P).

Quote
EDIT: Just thought of something: The newest version of WabbitEmu supports exporting variables, right?

Yup. Actually, I heard it did since forever, but it was not documented well. Press F7 while Wabbitemu is not in busy mode. For newer versions of wabbitemu, that menu can be accessed through Right-click->Calculator->Variables, too. Just drag and drop what you want on the computer somewhere.

Quote
EDIT2: Wow, there's a lot more traffic on Omnimaga.
Yeah, activity increased a lot since November, altough it was much higher 6-10 weeks ago, post-wise (I still remember those two 300+ post days). (shortly after Ndless and gbc4nspire came out) It seems traffic increased again, though, because we get a lot of 500 Internal Server Errors lately
« Last Edit: May 29, 2010, 12:40:02 am by DJ Omnimaga »

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Calcalca
« Reply #8 on: May 29, 2010, 12:19:56 am »
If you're still working on this over at UTI and such I'm sure Goose or Thornahawk could help over there. They seem to be very math savvy (10 point word of the day :P).
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Calcalca
« Reply #9 on: May 29, 2010, 01:03:20 am »
I'm not going to get to the math portion in a few weeks (or months), because I still need to finish a unit database first.

Here's a list of the units I'm definitely going to include (not counting prefixes such as centi- or operations such as 3):

Length: m, in, ft, yd, mi
Area: are, acr
Volume/Capacity: cc, L, foz, gal, bus
Velocity: kn
Mass: g, T, oz, lb, sT, lT
Time: s, min, hr, day, yr
Frequency: Hz
Force: N
Work/Energy: J, cal, Cal
Power: W, hp
Current: A
Charge: C
Voltage: V
Resistance: ohm
Pressure: Pa

What do you think? What else should I include?
« Last Edit: May 29, 2010, 01:03:51 am by Deep Thought »




Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Calcalca
« Reply #10 on: May 29, 2010, 01:05:53 am »
For mass I would change g to kg, well that's just me since I'm a physics guy.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Calcalca
« Reply #11 on: May 29, 2010, 01:13:34 am »
For mass I would change g to kg, well that's just me since I'm a physics guy.

I'm documenting only the base values because prefixes like kilo- will be dealt with in a different way.




Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Calcalca
« Reply #12 on: May 29, 2010, 01:17:57 am »
Oh ok, sorry I missed that from earlier. I'm very tired.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Calcalca
« Reply #13 on: May 29, 2010, 01:22:05 am »
Isn't there also m3 for volume? (cube meter)

That's what we often used in physics classes over here besides liters

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Calcalca
« Reply #14 on: May 29, 2010, 01:25:03 am »
Isn't there also m3 for volume? (cube meter)

That's what we often used in physics classes over here besides liters

I'm also treating operations (all operations, not just exponents) separately.

Actually, that's the part that stumped me when I first made this program a year ago. I could get multiplication and implied multiplication working fine, but not division, exponents, or parentheses. Do you think I should just simplify things by including squares and cubes as units on their own?