Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts

    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
    Last edited by jkd; 08-16-2003 at 04:23 AM.

  • #2
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i get this:
    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.

  • #4
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I also needed a symbolic parser in javascript so I decided to roll my own. It can use some polishing and maybe some more testing. At present it parses symbolically and can do derivatives. You can get an idea of how it works at http://www.nerdamer.com/demo and the code can be found at https://github.com/nerdamer/nerdamer...ifferentiation. The math is rendered with mathquill. Hope this helps.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •