Runtime x86 assembling graphing calc

http://www.rikarends.com/source/arcalc.exe (220k).
ARCalc including source and examples (400k).
Check the Pouet.net entry here
I wrote this program when i was 17, which is now more than 9 years ago. As it was so much fun back to play with, i decided to dig it up and recompile it for everybody to enjoy. Back then in math class we were learning trigonometry functions. Basic stuff like sin(a*x+b)+c. We were taught with pictures showing what the effect of the coefficients a b and c is on the behaviour of the function.
This was before we had fancy graphing calculators (it was pentium 166 era) so we visualised by drawing the graphs ourselves. However, with programming computer software one thing i learned is to feel out the dynamics of an algorithm by varying the variables it depends on. And drawing by hand, doesnt quite cut it.When you do it interactively with a computer, for me it creates a deeper understanding of the properties because you start understand what each component does in terms of impact on the behavior. If i change n from 1 to 10, the algorithm will take 10 times as long to execute, or the output will change shape like this, or the ‘cumulative error’ wil behave like that. All these concepts are taught in the basic sciences, and most are very important to really grasp how changes to the input variables impact the output.
To me the trigonometric functions were no exception. Its something you push a value in, and you plot the output. So whilest not paying attention to my math class, i tried to find a way to parse and execute the function definitions we were working with. The problems to solve in order to parse and execute them were ‘operator precedence’ and ‘nesting’. It took me a few iterations, but the best solution appears to be recursively parsing an equation into a tree, with at each node an operand to apply to its children to create an outcome.
Lets take the simple sin(ax*+b)*c. The tree that can be generated from this function:
*
|- sin
| \- +
| |- *
| | |- a
| | \- x
| |- b
\- c
As you can see, each node point has an operator and it uses its children as input values for that operation. So the processing can be done recursively. This method extends to any ‘basic’ mathematical function and is really efficient to execute. So when combined with a few nice plotting mechanisms (the calc has many, 2D/3D/image/sound plotting modes) one can really start to ‘feel’ out the effect of coefficients and changes to your equation on mathematical function behaviour as everything is compiled and in real-time per keypress. Personally i think that is a very useful thing to learn, and besides the calculator that comes with OSX (which is less nice for playing with parameter dynamics, but is more advanced mathematically), i have yet to find a nicer math playtoy than this.
The calculator also does numerical derivation and integrals, so you can observe the effects of coefficients very nicely(good for understanding derivation)
The original calculator was fast enough on a p166 to do realtime 3D and image function plotting, because of a dynamic compiler generating real assembler-code from your mathematical formula. So now with our fancy fast pc’s its even more fun and fast to play around with (it runs 400×300 picture animations nicely on my 2ghz p4). I also included the source for the application, so feel free to change anything. It builds using visual studio 2005.
The binary:
http://www.rikarends.com/source/arcalc.exe (220k).
The source is available at:
http://www.rikarends.com/source/arcalc_source.zip (160k)
Check out some equations in this example package: http://www.rikarends.com/source/arcalc_demofiles.zip
Short explanation of avialable functions and notations:
Normal number: 1.3424
Hex number: $15f2b
Binary number: #110101
Fractional number: 1,1,3 (one one third)
Special numbers: e*p (E times PI)
Animation variable: n
example: 2p^1,4e (2*PI to the power of 1/4th times E)
Operations
Standard operations: a+-/*b
Power: a^b
a-th root of b a~b
a in steps of b a@b
alogb a_b
sqr(a^2+b^2) a;b
atan(a/b) a?b
abs(a) |a|
sine of x sin(x)
cosine of x cos(x)
tangent of x tan(x)
arcsine of x asin(x)
arccos of x acos(x)
arctan of x atan(x)
integer value of x int(x)
10 base logarithm of x log(x)
natural logarithm of x ln(x)
square root of x sqr(x)
random with seed x rnd(x)
seedless random ran()
radians to degrees deg(rads)
degrees to radians rad(degs)
Sum of 0 to x sum(x)
Factorial of 1 to x fac(x)
Sawtooth of x saw(x)
Blockwave of x blk(x)
(x+2)*0.5 two(x)
fractional part of x frac(x)









March 22nd, 2009 at 5:42 am
for example, for the function cos(sin(x:y-2n)-sin(|x+(8sin(n)+10)|:(y+5sin(2n))+5n))
there are a lot of variables like x,y,n . where are they set on the program?
how does animate button work, for example what ftime:xxxx’-2 means?
thanks!
April 11th, 2009 at 10:21 pm
Something is wrong with you formula evaluation. In “calculator” mode try this simple statement: 2.0/2.0/2.0
It will be evaluated like 2.0/(2.0/2.0) but I think it should be evaluated like (2.0/2.0)/2.0
January 23rd, 2010 at 7:43 am
Really like this post, thanks for writing.