Go Back   CodingForums.com > :: Client side development > JavaScript programming > Post a JavaScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-16-2003, 12:33 AM   PM User | #1
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
Symbolic mathematics in Javascript

Alright. Resident moderator Alex Vincent has been after a "toMathML()" method for a while now it seems. So I told him, "Alright, no biggie." . Now I gotta deliver.

Content MathML 2.0 is essentially Polish Notation, but in XML. You can directly convert infix expressions (Algebraic notation) to prefix (Polish), however I decided to take a different route and implemented my own algorithm for directly converting an infix expression into an expression tree. And from the tree, I can dynamically evaluate it recursively, pre-order traverse it, post-order traverse it, in-order traverse it, and generate MathML like nothing.

So, if you're using Mozilla, check it out here:
http://www.jasonkarldavis.com/math/test.xhtml

The algorithm works fine in any JS-capable browser, however I use DOM2 namespaced node-creation methods that only Mozilla supports for MathML generation. Presentation MathML output will come as soon as I hook up the XSLT stylesheet. Also, support for unary operators and functions (like sin, cos, log), etc will come as soon as I replace the binary tree data structure with an n-ary tree data structure.

You can try this simple example to type in the algebraic input box:
y = 5*x + 2

It's all part of a much bigger plan, so the lack of a UI right now isn't a concern. (The "test.xhtml" filename implies that it is a test page.) I just thought the script might be educational to anyone interested in real computer science and using Javascript to implement and utilize abstract data types.

Oh, and I noticed that I didn't explain the reason why I included "symbolic" in the title... by creating an expression tree, it becomes trivial to perform operations symbolically on it. Differentiation of an expression tree, for example, is exceedingly easy.

Alright - to please Mr. Vincent, here is a zip with everything:
www.jasonkarldavis.com/math/math.zip
__________________
jasonkarldavis.com

Last edited by jkd; 08-16-2003 at 03:23 AM..
jkd is offline   Reply With Quote
Old 09-23-2011, 03:29 PM   PM User | #2
james.mclellan
New to the CF scene

 
Join Date: Sep 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
james.mclellan is an unknown quantity at this point
I get a 404 error when attempting to connect to the links above.

I had searched here, first, for a few libraries, and not finding anything I felt I could use started my own.

It's located here on GitHub:

https://github.com/jamesmclellan/Sym...for-Javascript

And, hopefully, will not be going anywhere as long as GitHub is around.

Presently, it handles: addition, subtraction, multiplication, division, exponents, parentheticals, simple differentials (with and without product rule).

I would be very grateful for contributions to the baseline, if anyone would be so inclined.
james.mclellan is offline   Reply With Quote
Old 10-03-2011, 12:34 PM   PM User | #3
sela
New to the CF scene

 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
sela is an unknown quantity at this point
i get this:
Quote:
Not Found

The requested URL /math/test.xhtml was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
sela is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:20 PM.


Advertisement
Log in to turn off these ads.