Use of Polynomial.TotalDegree

(Tyetis) #1

string eqn = “x / (x + 5) = 7”;
string[] expString = eqn.Split(’=’);
Expression aleft = MathNet.Symbolics.Infix.ParseOrThrow(expString[0]);

Expression result = Polynomial.TotalDegree(aleft);

the degree of the equation above is 1 but “result” variable get the 2 value ? and Polynomial.Degree(“x”, aleft) returns “undefined” ?
I’m guessing that is like this “x*(x + 5)^-1” but it’s still not right

(Christoph Rüegg) #2

It looks to me like the result is consistent, although maybe not intuitive.

The problem is that the expressions is not actually a polynomial in x, but a rational in x (Polynomial.isPolynomial returns false).

However, the polynomial module understands it as a multivariate polynomial in the two algebraic variables x and 1/(5+x). This is confirmed by Polynomial.variables. The provided expression x/(x+5) is thus a multivariate monomial in the form of the product of the two variables and has therefore degree 2. The total degree is therefore also 2.

Does this help?
What do you need the total degree for?

(Tyetis) #3

reasonable, i using TotalDegree for achieve degree of equation.
actually I’m developing an algorithm for solving equation systems step-by-step as wolfram alpha. you can call some kind of artificial intelligence
I want to solve logic problems, number fraction problems, pool problems using library

so I’m going to ask a question from time to time here.

(Christoph Rüegg) #4

Great, I’d be very interested in your work and implementation.

Btw, this is a simplistic routine I’ve used as example code that can solve such simple degree-1 equations (F#):

let solve x a b =

    let a' = Rational.simplify x a
    let an = Rational.numerator a'
    let ad = Rational.denominator a'
    let b' = Rational.simplify x b
    let bn = Rational.numerator b'
    let bd = Rational.denominator b'
    let expr = an*bd - bn*ad |> Algebraic.expand
    if Polynomial.isPolynomial x expr then
        match Polynomial.coefficients x expr with
        | [||] -> Undefined
        | [| a |] -> x
        | [| a; b |] -> -a/b
        | _ -> failwith "higher polynomials not supported"

    else failwith "only general polynomial expressions supported for now"
solve x (x/(x + 5)) (number 7) // -35/6

(Tyetis) #5

My project official site
for now, just “Equation Parser” link works. it parsing and converting equation to xml document. I was working xml before i see F# and actually, that’s not a bad idea

equation solving not ready yet in home page