Author Topic: Advanced Math in Output( and Text( ?  (Read 8551 times)

0 Members and 1 Guest are viewing this topic.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Advanced Math in Output( and Text( ?
« Reply #15 on: April 28, 2011, 08:44:34 pm »
Btw, slightly off topic, but thanks Runer112 for reminding me of using the stack to help out with this
Oh I bet that is how Axe does it... I use a completely different method which is why ReCode does math right to left...

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Advanced Math in Output( and Text( ?
« Reply #16 on: April 28, 2011, 08:46:42 pm »
What's infix and what's postfix?

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: Advanced Math in Output( and Text( ?
« Reply #17 on: April 28, 2011, 08:48:21 pm »
Btw, slightly off topic, but thanks Runer112 for reminding me of using the stack to help out with this
Oh I bet that is how Axe does it... I use a completely different method which is why ReCode does math right to left...

I think Axe only does that for parentheses (and implied parentheses).

What's infix and what's postfix?

Infix is your familiar 1*2+3 notation (disregarding order of operations); postfix is basically RPN (reverse polish notation), described here: http://en.wikipedia.org/wiki/Reverse_Polish_notation
« Last Edit: April 28, 2011, 08:48:33 pm by Deep Thought »




Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Advanced Math in Output( and Text( ?
« Reply #18 on: April 28, 2011, 08:52:26 pm »
Yeah, I think I'll stick with left-to-right.   Postfix is a little bit tricky for someone at my level ;)

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: Advanced Math in Output( and Text( ?
« Reply #19 on: April 28, 2011, 08:53:03 pm »
prefix (a.k.a Polish Notation): + 1 2
infix: 1 + 2
postfix (a.k.a Reverse Polish Notation): 1 2 +

with infix you have to worry about order of operations, whereas with postfix and prefix you don't.

While we're on the subject...
http://xkcd.com/645/
There's something about Tuesday...


Pushpins 'n' stuff...


Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Advanced Math in Output( and Text( ?
« Reply #20 on: April 28, 2011, 08:56:32 pm »

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Advanced Math in Output( and Text( ?
« Reply #21 on: April 28, 2011, 08:58:10 pm »
prefix (a.k.a Polish Notation): + 1 2
infix: 1 + 2
postfix (a.k.a Reverse Polish Notation): 1 2 +

with infix you have to worry about order of operations, whereas with postfix and prefix you don't.

While we're on the subject...
http://xkcd.com/645/
Lovely :P
And now I know what those terms mean, so I am happy... I think it would be slower to use those methods, anyway, in my experience.

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: Advanced Math in Output( and Text( ?
« Reply #22 on: April 28, 2011, 08:59:24 pm »
Well, the slow part would be converting from infix to prefix/postfix. Parsing prefix/postfix is actually much easier to write as long as you have sufficient access to a stack/queue
There's something about Tuesday...


Pushpins 'n' stuff...


Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Advanced Math in Output( and Text( ?
« Reply #23 on: April 28, 2011, 09:01:30 pm »
Wow, ZippyDee, you wouldn't by any chance be willing to contribute to Correlation by writing this parser, would you?

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: Advanced Math in Output( and Text( ?
« Reply #24 on: April 28, 2011, 09:03:00 pm »
Well, the only issue is that my ASM is a bit on the completely awful side. But I could give it a go. At the very least I could write a low-level pseudocode for implementation.
There's something about Tuesday...


Pushpins 'n' stuff...


Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Advanced Math in Output( and Text( ?
« Reply #25 on: April 28, 2011, 09:05:35 pm »
So, would we code in order of operations, left to right, right to left, or RPN?

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: Advanced Math in Output( and Text( ?
« Reply #26 on: April 28, 2011, 09:07:52 pm »
I think the easiest for general users (albeit the slowest) would be to parse from infix to postfix, and then parse the postfix.

That would allow them to still use regular order of operations and not get all confused about left-to-right order of operations or right to left or RPN or anything else like that.
« Last Edit: April 28, 2011, 09:09:23 pm by ZippyDee »
There's something about Tuesday...


Pushpins 'n' stuff...


Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Advanced Math in Output( and Text( ?
« Reply #27 on: April 28, 2011, 09:08:08 pm »
Well, the only issue is that my ASM is a bit on the completely awful side. But I could give it a go. At the very least I could write a low-level pseudocode for implementation.

You know what, if you could write some pseudocode -- any level, it doesn't have to be low-level -- that would actually help tremendously.  I could actually take it from there.  The main headache for me is the planning part, and then the coding is not so hard from there.

So, would we code in order of operations, left to right, right to left, or RPN?

Left to right.  Again, if you absolutely need order of operations, the Ti-Basic parser can do it instead of my parser.



EDIT:  I agree that regular order-of-operations is easier, but then Axe parser uses left-to-right, so it's not like it's impossible
« Last Edit: April 28, 2011, 09:13:32 pm by Hot_Dog »

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Advanced Math in Output( and Text( ?
« Reply #28 on: April 29, 2011, 12:54:30 am »
I forgot...to make math faster and more efficient, Correlation converts all numbers to 16-bit binary, instead of BCD.  So for log(, you will only be able to supply variables (like real numbers or list elements) with absolutely no math.  Log( will then safely calculate the number of digits in your number.
« Last Edit: April 29, 2011, 12:57:21 am by Hot_Dog »

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Advanced Math in Output( and Text( ?
« Reply #29 on: April 29, 2011, 11:20:02 am »
A base 10 logarithm routine should be a piece of cake. This takes 57 cycles in the best case scenario (result=4) and 143 cycles in the worst case scenario (result=1). It's 32 bytes.

Code: [Select]
Log10:
ld de,4
ld bc,-10000
add hl,bc
jr c,Log10End
dec e
ld bc,-1000-(-10000)
add hl,bc
jr c,Log10End
dec e
ld bc,-100-(-1000)
add hl,bc
jr c,Log10End
dec e
ld a,l
add -10-(-100)
jr c,Log10End
dec e
Log10End:
ex de,hl
ret
« Last Edit: April 29, 2011, 11:22:02 am by Runer112 »