Author Topic: [Axiom] Floating Point Math (and other stuff)  (Read 23162 times)

0 Members and 1 Guest are viewing this topic.

Offline jacobly

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 205
  • Rating: +161/-1
    • View Profile
[Axiom] Floating Point Math (and other stuff)
« on: October 25, 2011, 07:18:09 pm »
This axiom allows you to access the os variables and do floating point math with them!
Feel free to ask questions instead of trying to read and understand this entire post.

Did you ever want to store the value of the real/complex variable A into the real/complex variable B inside of an axe program? Now it is easier than ever!
Code: [Select]
:A→B
Code: [Select]
:#Axiom(CPLXMATH) .varA could be complex
:Select("varA")→Select("varB") .Select( is in the 2nd List Ops menu
:solve() .optional but suggested, frees used memory

But maybe you wanted to store A + B to C.  Well that is almost as simple.
Code: [Select]
:A+B→C
Code: [Select]
:#Axiom(CPLXMATH) .varA or varB could be complex
:solve(ᵀ+,Select("varA"),Select("varB"))→Select("varC") .solve( is on the Math Math menu
:solve() .optional, but suggested - frees used memory
In general, solve(ᵀ<op>,<args>) applies <op> to <args>. <op> can be be almost anything from ^, dim( to inString(!
Note: even though Axe changes inString( to inData(, it still does its original function when used in this command. Also, don't close the ( in <op>!

Well that's cool, but can I use Lists you ask? Of course!
Code: [Select]
:L₁∗A→L₂
Code: [Select]
:#Axiom(CPLXMATH) .L₁ or L₂ could be complex lists
:solve(ᵀ∗,Select("L₁"),Select("varA"))→Select("L₂")
:solve() .optional but suggested, frees used memory

But I only wanted to used the 42nd number in L₁ you ask? Well, why not!
Code: [Select]
:L₁(42)‒A→L₂(42)
Code: [Select]
:#Axiom(CPLXMATH) ... see above
:solve(ᵀ‒,Select("L₁",42),Select("varA"))→Select("L₂",42)
:solve() ... see above
Notice how Select( loads or saves to a variable, and solve( applies an operation to loaded variables.

The above code doesn't work if L₁ is too small, you say? Well why don't we resize L₁.
Code: [Select]
:42→dim(L₁)
Code: [Select]
:#Axiom(CPLXMATH) ...you know
:dim("L₁",42) .notice the slight difference in syntax
Note that solve() is unnecessary because dim does not currently use any memory.

I'll bet you forgot about matricies, you say... Nope!
Code: [Select]
:{5,5}→dim([A])
:For(A,1,5)
:For(B,1,5)
:10A+B→[A](A,B)
:End
:End
Code: [Select]
:#Axiom(REALMATH) .only real numbers used AND no arbitrary variable access
:Buff(9)→GDB1 .a temp floating point - they are 9 bytes large
:dim("[A]",5,5)
:For(A,1,5) .remember, A and B are still Axe variables
:For(B,1,5)
:A∗10+B→float{GDB1} .load temp with A∗10+B converted to a floating point
:GDB1→Select("[A]",A,B) .see, I didn't forget matrix support
:solve() .especially important inside loops
:End
:End
Or, if you are familiar with the format of floating point numbers:
Code: [Select]
:#Axiom(REALMATH) .see above
:"[A]"→Str1
:[008100000000000000]→GDB1 .floating point zero, prepared for 2 digit numbers
:dim(Str1,5,5)
:For(A,1,5)
:For(B,1,5)
:A∗16+B→{GDB1+2} .A and B are between 0 and 10 exclusive, treat as bcd digits
:GDB1→Select(Str1,A,B)
:End
:solve() .delete temp memory at least moderately often (~100 bytes at this point!)
:End

Now for an example that actually does something useful.
Code: [Select]
:(-B+√(B²‒4AC))/(2A)→C
:(-B‒√(B²‒4AC))/(2A)→D
Code: [Select]
:#Axiom(CPLXMATH) .obviously
:Buff(9)→GDB2 .declare constants
:Buff(9)→GDB4
:2→float{GDB2} .initialize constants
:4→float{GDB4}
:solve(ᵀ/,solve(ᵀ+,solve(ᵀ-,Select("varB")),solve(ᵀ√(,solve(ᵀ‒,solve(ᵀ²,Select("varB")),solve(ᵀ∗,GDB4,solve(ᵀ∗,Select("varA"),Select("varB")))))),solve(ᵀ∗,GDB2,Select("varA")))→Select("varC")
:solve()
:solve(ᵀ/,solve(ᵀ‒,solve(ᵀ-,Select("varB")),solve(ᵀ√(,solve(ᵀ‒,solve(ᵀ²,Select("varB")),solve(ᵀ∗,GDB4,solve(ᵀ∗,Select("varA"),Select("varB")))))),solve(ᵀ∗,GDB2,Select("varA")))→Select("varC")
:solve()
JK, it doesn't have to be that unreadable. I just wanted to show what you could do if you really wanted to. (Yes, that means you can nest as much as you want, limited only by the amount of memory available.) A normal person might do something more like this:
Code: [Select]
:#Axiom(CPLXMATH) .obviously
:Buff(9)→GDB2 .declare constants
:Buff(9)→GDB4
:2→float{GDB2} .initialize constants
:4→float{GDB4}
:Select("varA")→A .yes you can do that
:Select("varB")→B
:Select("varC")→C
:solve(ᵀ√(,solve(ᵀ‒,solve(ᵀ²,B),solve(ᵀ∗,GDB4,solve(ᵀ∗,A,C))))→D
:solve(ᵀ-,B)→B .pre-calculate stuff
:solve(ᵀ∗,GDB2,A)→A
:solve(ᵀ/,solve(ᵀ+,B,D),A)→Select("varD")
:solve(ᵀ/,solve(ᵀ‒,B,D),A)→Select("varE")
:solve()

Let's return the result in Ans instead of D and E.
Code: [Select]
:(-B+{1,-1}√(B²+i²4AC))/(2A)
i²=-1, but it allows the result to be complex regardless of mode. Similarly, complex constants are used below, with no i component, in order to allow complex answers in any mode.
Code: [Select]
:#Axiom(CPLXMATH)
:[015D]"TEMP"→Str1LT .[015D] must be used instead of the ᴸ before a list in the current version of Axe
:[0C80200000000000000C8000000000000000]→GDB2 .still 2, but complex
:[0C80400000000000000C8000000000000000]→GDB4 .complex floating point 4
:Select("varA")→A
:Select("varB")→B
:Select("varC")→C
:solve(ᵀ√(,solve(ᵀ‒,solve(ᵀ²,B),solve(ᵀ∗,GDB4,solve(ᵀ∗,A,C))))→C .we don't need C anymore
:solve(ᵀ-,B)→B .pre-calculate stuff
:solve(ᵀ∗,GDB2,A)→A
:DelVar Str1LT .Delete ᴸTemp in case it already exists
:solve(ᵀ/,solve(ᵀ+,B,C),A)→Select(Str1LT,1)
:solve(ᵀ/,solve(ᵀ‒,B,C),A)→Select(Str1LT,2)
:Select(Str1LT)→Select("varAns") .yep, that's right
:DelVar Str1LT .no one needs ᴸTemp anymore
:solve() .we are done

Strange OP codes (used instead of ᵀ<token>)
ECEECFED0ED1ED2ED3ED4ED5ED6ED7ED8ED9EDAEDB
npv(irr(bal(∑Prn(∑Int➤Nom(➤Eff(dbd(lcm(gcd(randInt(randBin(sub(stdDev(
EDCEDDEDEEDFEE0EE1EE2EE3EE4EE5EE6EE7EE8EE9
variance(inString(normalcdf(invNorm(tcdf(Χ²cdf(Ϝcdf(binompdf(binomcdf(poissonpdf(poissoncdf(geometpdf(geometcdf(normalpdf(
EEAEEBEECEEDE89E8AE8BE8CE8DE8EE8FE90E91E92E93
tpdf(Χ²pdf(Ϝpdf(randNorm(conj(real(imag(angle(cumSum(expr(length(ΔList(ref(rref(Fill(

Update 0.1: Tutorial added.
Update 0.2: Major bugfix.
Update 0.3: Select( is replaced with get(. Key: seq(

*Warning: Please do not use RealMath unless you are absolutely sure that your code will never see anything that could posibly be complex. (unless you want corrupted mem, etc.) However, use it if you can, since it is smaller and faster.
« Last Edit: August 02, 2012, 03:44:34 am by jacobly »

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: [Axiom] Floating Point Math (and other stuff)
« Reply #1 on: October 25, 2011, 07:19:45 pm »
I personally haven't had a use for it yet, but good work :) Using T to grab operations is genius!




Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: [Axiom] Floating Point Math (and other stuff)
« Reply #2 on: October 25, 2011, 07:21:51 pm »
it looks awesome!
So Quad solver in Axe finally? :D
Sig wipe!

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: [Axiom] Floating Point Math (and other stuff)
« Reply #3 on: October 25, 2011, 07:22:09 pm »
Oh, I have a suggestion. Not sure how this would work, but why not merge Select() with float{} somehow, seeing as the latter's already used natively by Axe? Again, I have no idea how that would work, but if it could work that'd be awesome. It would mean one fewer token used up by an Axiom.

yeong, oh dear D:
« Last Edit: October 25, 2011, 07:22:32 pm by Deep Thought »




Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: [Axiom] Floating Point Math (and other stuff)
« Reply #4 on: October 25, 2011, 07:23:24 pm »
did we already had one?
Sig wipe!

Offline jacobly

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 205
  • Rating: +161/-1
    • View Profile
Re: [Axiom] Floating Point Math (and other stuff)
« Reply #5 on: October 25, 2011, 07:25:36 pm »
According the the almighty Quigibo ;), that doesn't work yet.
Quote from: Quigibo
Unfortunately, you cannot re-define current Axe tokens in Axioms which is why you're getting that error, you can only overwrite unused tokens.

EDIT:
Oh, and I originally did use solve( for everything instead of Select(. The code may have been slightly unreadable. D:
Besides, Select( takes a string and float{ takes a pointer...
« Last Edit: October 25, 2011, 07:31:34 pm by jacobly »

Offline FinaleTI

  • Believe in the pony that believes in you!
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1830
  • Rating: +121/-2
  • Believe in the pony that believes in you!
    • View Profile
    • dmuckerman.tumblr.com
Re: [Axiom] Floating Point Math (and other stuff)
« Reply #6 on: October 25, 2011, 07:51:21 pm »
Intriguing. Now, people really can write a CAS in Axe. ;)

Perhaps I should release the routine I made to convert a string to a real and store it in a real var, so it would make this even easier to use this library, as it doesn't require knowledge of the FP format.
« Last Edit: October 25, 2011, 07:56:42 pm by FinaleTI »


Spoiler For Projects:

My projects haven't been worked on in a while, so they're all on hiatus for the time being. I do hope to eventually return to them in some form or another...

Spoiler For Pokemon TI:
Axe port of Pokemon Red/Blue to the 83+/84+ family. On hold.

Spoiler For Nostalgia:
My big personal project, an original RPG about dimensional travel and a few heroes tasked with saving the world.
Coding-wise, on hold, but I am re-working the story.

Spoiler For Finale's Super Insane Tunnel Pack of Doom:
I will be combining Blur and Collision Course into a single gamepack. On hold.

Spoiler For Nostalgia Origins: Sky's Story:
Prequel to Nostalgia. On hold, especially while the story is re-worked.

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: [Axiom] Floating Point Math (and other stuff)
« Reply #7 on: October 25, 2011, 08:12:07 pm »
Perhaps I should release the routine I made to convert a string to a real and store it in a real var, so it would make this even easier to use this library, as it doesn't require knowledge of the FP format.
This Axiom doesn't either, does it? ???




Offline FinaleTI

  • Believe in the pony that believes in you!
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1830
  • Rating: +121/-2
  • Believe in the pony that believes in you!
    • View Profile
    • dmuckerman.tumblr.com
Re: [Axiom] Floating Point Math (and other stuff)
« Reply #8 on: October 25, 2011, 08:16:22 pm »
Perhaps I should release the routine I made to convert a string to a real and store it in a real var, so it would make this even easier to use this library, as it doesn't require knowledge of the FP format.
This Axiom doesn't either, does it? ???
If you want to create an FP number like -0.145 in the program, I believe you have to create it using hex.
I believe the Axiom only adds math functions, not creating or displaying non-integer FP numbers.


Spoiler For Projects:

My projects haven't been worked on in a while, so they're all on hiatus for the time being. I do hope to eventually return to them in some form or another...

Spoiler For Pokemon TI:
Axe port of Pokemon Red/Blue to the 83+/84+ family. On hold.

Spoiler For Nostalgia:
My big personal project, an original RPG about dimensional travel and a few heroes tasked with saving the world.
Coding-wise, on hold, but I am re-working the story.

Spoiler For Finale's Super Insane Tunnel Pack of Doom:
I will be combining Blur and Collision Course into a single gamepack. On hold.

Spoiler For Nostalgia Origins: Sky's Story:
Prequel to Nostalgia. On hold, especially while the story is re-worked.

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: [Axiom] Floating Point Math (and other stuff)
« Reply #9 on: October 25, 2011, 08:41:22 pm »
This is really awesome!  Thanks for making this wonderful library. :D

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: [Axiom] Floating Point Math (and other stuff)
« Reply #10 on: October 25, 2011, 08:49:58 pm »
* Qwerty.55 checks the posting date

O.O

I was planning on asking for help with floating point in Axe tonight. Awesome timing.
« Last Edit: October 25, 2011, 08:50:27 pm by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline alberthrocks

  • Moderator
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 876
  • Rating: +103/-10
    • View Profile
Re: [Axiom] Floating Point Math (and other stuff)
« Reply #11 on: October 25, 2011, 09:39:53 pm »
That is.... AMAZING! O_O The impossible is now done! :D (Well, not impossible, just hard.)
I guess this is a good time to revive the Z80 CAS topic? :D

Also, I agree with the above suggestions of making the numbers easy to parse - we should use relatively simple syntax to make it work.

Before a CAS could be made, the following needs to occur:
1) String -> FP number
2) FP number -> String
3) Display FP number on arbitrary display buffer at certain position (pref. #2)
4) ???

I might still have code to print FP numbers, but it's in BASIC and requires... FP functions? :P (Specifically, log, int(), fPart(), and iPart().) If you would like to use it, tell me and I'll try to dig it out of a calc backup that is in a dead HDD backup... :P
Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/


Proud member of ClrHome!

Miss my old signature? Here it is!
Spoiler For Signature:
Alternate "New" IRC post notification bot (Newy) down? Go here to reset it! http://withg.org/albert/cpuhero/

Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/

Activity remains limited due to busyness from school et al. Sorry! :( Feel free to PM, email, or if you know me well enough, FB me if you have a question/concern. :)

Don't expect me to be online 24/7 until summer. Contact me via FB if you feel it's urgent.


Proud member of ClrHome!

Spoiler For "My Projects! :D":
Projects:

Computer/Web/IRC Projects:
C______c: 0% done (Doing planning and trying to not forget it :P)
A_____m: 40% done (Need to develop a sophisticated process queue, and a pretty web GUI)
AtomBot v3.0: 0% done (Planning stage, may do a litmus test of developer wants in the future)
IdeaFrenzy: 0% done (Planning and trying to not forget it :P)
wxWabbitemu: 40% done (NEED MOAR FEATURES :P)

Calculator Projects:
M__ C_____ (an A____ _____ clone): 0% done (Need to figure out physics and Axe)
C2I: 0% done (planning, checking the demand for it, and dreaming :P)

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: [Axiom] Floating Point Math (and other stuff)
« Reply #12 on: October 26, 2011, 09:39:29 am »
* Qwerty.55 checks the posting date

O.O

I was planning on asking for help with floating point in Axe tonight. Awesome timing.
Maybe he learned how to make axioms elsewhere? Maybe he has another account?
« Last Edit: October 26, 2011, 09:39:51 am by Keoni29 »
If you like my work: why not give me an internet?








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: [Axiom] Floating Point Math (and other stuff)
« Reply #13 on: October 26, 2011, 09:45:49 am »
Some assembly code can be whipped up to convert between string and FP, but I am not going to commit myself to that task XD

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: [Axiom] Floating Point Math (and other stuff)
« Reply #14 on: October 26, 2011, 09:53:21 am »
I have seen some AXE programmes using strings to export images or tilemaps. How is that possible?
If you like my work: why not give me an internet?