Git Product home page Git Product logo

Comments (4)

diluculo avatar diluculo commented on May 24, 2024

This results from the precedence of unary minus is higher than power operator. I think the list below may be right for us.

Precedence of operators, from highest to lowest.

  1. parentheses
  2. pow: a^b
  3. unary minus and plus: -a, +a
  4. multiply, divide : a*b, a/b
  5. add, subtract: a+b, a-b

from mathnet-symbolics.

cdrnet avatar cdrnet commented on May 24, 2024

I'm actually not entirely sure we can control this (at least when using F# as dsl), since prefix operators have a higher precedence in F# than the power operator (docs). What happens in the Infix parser is a different story (and would also need to be verified).

from mathnet-symbolics.

diluculo avatar diluculo commented on May 24, 2024

Yes, I can get right expression by changing the precedence of operators in the Infix parser.

Infix.parseOrUndefined "a*exp(-(x-b)^2/(2*c^2))";; // Gaussian function
val it : Expression = a*exp(-(-b + x)^2/(2*c^2))

a*exp(-(x-b)**2/(2*c**2));;
val it : Expression = a*exp((b - x)^2/(2*c^2))

Workaround we can select now is using "-1*" or "0 - " instead of "-" to get right answer, is it right?

from mathnet-symbolics.

diluculo avatar diluculo commented on May 24, 2024

Unlike F#, it is clear that exponentiation has higher precedence than unary minus in the mathematics, and in fact, it is already reflected in Infix.format. However, it is not easy to change the order of operators of F# now. So how about intentionally setting the precedence of operators of F# and the Infix parser differently? If we know this and can use parentheses properly when in doubt, I think it is not a bad idea.

from mathnet-symbolics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.