KermMartian wrote:
SirCmpwn wrote:
On x86, a double is only 8 bytes. How good of precision are you getting on z80 with less?
How did you determine that he's using 64-bit doubles instead of 32-bit floats, or even 24-bit floats? (although those would have horrible precision).

Just a guess. On x86 I would use 64 bit floats. Perhaps AHelper can clarify, is it just that the makeup of the tree (not necessarily the numbers) that is smaller?
(Going back) The structs are smaller on the z80 since pointers are smaller. Also, gCAS only uses floats (32 bit) as that's the only common datatype on PC's and for SDCC. The floats don't loose too much precision, so the first 3 decimal numbers are usually accurate.

The tree itself is just a cloud of structs, which contain ~13 bytes per struct (in the past, 7 per node and 8 bytes per number). The true malloc'd size is about 22 bytes (malloc header included). Right now, as you enter in more lengthy expressions, the tree is larger. For small things, the parser's temp space is larger (storing the string segments, pointers to nodes, types, etc.).

(I am rewriting gCAS from scratch in order to get the saner node layout (see past posts) so the memory usage will drop)
AHelper wrote:
(I am rewriting gCAS from scratch in order to get the saner node layout (see past posts) so the memory usage will drop)

Good to hear, thanks for the explanation. Perhaps a more exhaustive study of memory usage is in order when it is done? It could be a good excuse to make some nice memory usage tracking software.
If I feel like going insane, I may add in a graphical tree renderer and memory viewer on-calc Smile

The heap fir the RAM and flash are the same, so my temporary flash viewer will work for the RAM, too.
I'll eventually be using a custom emulator to test KnightOS, and was planning on adding diagnostics specific to KOS, including memory tracking. Perhaps you could do something similar?
Well, each malloc just writes an index. I will just walk the indexes and add up the sizes.
TheStorm wrote:
I think he means the pointers, and structs will be smaller. The actual float types I'm sure are of adequate precision.
Yeah, I tend to think that that would make a lot more sense as well. And it looks like AHelper confirmed that it is indeed 8-byte doubles that he uses.
Quote:
gCAS only uses floats (32 bit)

You can't have an 8-byte datatype on the calc as that would require bc de hl iy. SDCC will have a fit

<edit>

Anyone have a wishlist of functions for the gCAS backend? (Math functions, not like sin(, cos(, but like nPr or lcm) I plan to have the newer version have an exact/approx. mode like other CAS's.


  • Expanding an expression with expand(x)
  • Graphing? Plot with plot(x) and setting variables xmin, xmax, ymin, ymax
  • Factoring of expressions matching a certain form with factor(. This will be picky and will search out certain conditions in order to work. x+2x will not become x*(1+2), but 2*x^2+5*x-12 will factor to (2x-3)*(x+4)
  • Solving... no idea on how to get the zeros of expressions... ideas?
How about graphing any equation? Like I could put in:
3x+4y-7=15-x
And get a graph. Also - convert equations to various forms, so it could convert this to slope-intercept form.
This would require me to handle the '=' differently. right now, the CAS has no concept of it except that it is used for assignments. Because all that a=b is really 0=b-a (1). Do you think that the OS should do this, or should I go ahead and make the '=' a feature (2) of the OS?
(1) 2x-4=4y -> 4y-2x+4
(2) 2x-4=4y -> x-2=2y
AHelper wrote:
This would require me to handle the '=' differently. right now, the CAS has no concept of it except that it is used for assignments. Because all that a=b is really 0=b-a (1). Do you think that the OS should do this, or should I go ahead and make the '=' a feature (2) of the OS?
(1) 2x-4=4y -> 4y-2x+4
(2) 2x-4=4y -> x-2=2y

Seeing as the → key is built into the keyboard, I'd suggest using it for storage.
Right. This will mean that I will have to make my own key input, not getc as it doesn't handle non-standard keys... Remember that gCAS is cross-platform... Maybe a #ifdef for a TI84 to have → store and a PC will use (xcas style) := ?
AHelper wrote:
Right. This will mean that I will have to make my own key input, not getc as it doesn't handle non-standard keys... Remember that gCAS is cross-platform... Maybe a #ifdef for a TI84 to have → store and a PC will use (xcas style) := ?

That's a pretty good way of doing it, I approve.
But how about solving? I don't know on that...
AHelper wrote:
But how about solving? I don't know on that...

Well, the goal is just to get a variable alone on one side and a number alone on the other. This would probably be a lot easier with a tree system like you have. Just remember - what you do to one term, you must do to every term.
2x=6 would look like this in tree form:

So just find the term you want to solve for (in this case, x), and look at the node above it. If it is an equal sign, you're done for that side. Otherwise, look at the node above and find it's opposite (in this case, division). See what it connects to - 2. Apply /2 to each other term in the whole statement (excluding 2 and x). Then remove the 2 node, and shift the x up a level, so it looks like this:

Once you simplify the side with your term in in (the left side, in this case), you should simplify the opposite side. In our example, this is already simplified, so you're done. You can now successfully say that x=3. However, let's back up and say that the original equation was "2x=6+2". The initial tree would look like this:

Again, you would divide the left side by 2, and apply the division to every other term:

Now that you have the variable side complete, you can simplify the other side:

And there you have it, x=4.
I realized that a minute after I posted XD

Now, the rule is "replace, reverse, and flip". Take (2a-3)/2 + 5 = 2
You solve it by doing a = (((2-5)*2)+3)/2

Here are the trees

Before a solve


After a solve

This gets the right answer. I will experiment more with this method and improve it, but this method is something that can be done in C with pointers and such Smile
Could you clarify more on what happens between the images? Also, what if the tree is more complex, and doesn't just lie in a nice downward slope, or what if the variable is somewhere in the middle, as opposed to the bottom?
Still testing and experimenting...
it seems like that method works for one variable... It didn't seem to have issues on placement, so long that there is only one of it.

Now, a function suggestion: step(x,y)
Steps through solving x, display the output of each tree manipulation up to y iterations.

It would be able to show its work for (x+2)^50 so it makes your brain require one less feature: mental math. Eh? Should I, or not?
You should show your work Smile
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
» Goto page Previous  1, 2, 3, 4 ... 10, 11, 12  Next
» View previous topic :: View next topic  
Page 3 of 12
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement