c# - Extracting common terms with MathNet Symbolics -


i'm using mathnet symbolics handle symbolic algebra portion of program i'm working on. general use create pair of symbolic formulas, , divide 2 formulas. works quite of time. however, sometimes, not want more complex simplification. example:

                       (512*r*t*w + 2048*r*t^2*w) ----------------------------------------------------------------------- (512*r*t*w + 512*r^2*t*w + 3072*r*t^2*w + 3072*r^2*t^2*w + 1024*r*t^3*w) 

with work, i've been able have eliminate w equation, in terms top , bottom:

                    (512*r*t + 2048*r*t^2) -------------------------------------------------------------- (512*r*t + 512*r^2*t + 3072*r*t^2 + 3072*r^2*t^2 + 1024*r*t^3) 

however, cannot figure out how make find common terms:

         (512*r*t)*(1 + 4*t) -------------------------------------- (512*r*t)(1 + r + 6*t + 6*r*t + 2*t^2) 

and eliminate these terms:

         (1 + 4*t) ----------------------------- (1 + r + 6*t + 6*r*t + 2*t^2) 

i've been using wolfram alpha gold standard checking work. code linqpad i've been working on of afternoon, gets elimination of w:

var h1 = mathnet.symbolics.infix.parseorundefined("(1/8)*r*t*w + (1/2)*r*t^2*w"); var h2 = mathnet.symbolics.infix.parseorundefined("(1/8)*r*t*w + (1/8)*r^2*t*w + (3/4)*r*t^2*w + (3/4)*r^2*t^2*w + (1/4)*r*t^3*w");  infix.print(rational.expand(h1/h2)).dump();  //prints (512*r*t*w + 2048*r*t^2*w)/(512*r*t*w + 512*r^2*t*w + 3072*r*t^2*w + 3072*r^2*t^2*w + 1024*r*t^3*w) var tot = rational.expand(h1 / h2);  var simplified = true; {     simplified=false;     foreach (var v in rational.variables(tot))     {         var result = polynomial.divide(v, h1, h2);         if (!result.item1.equals(mathnet.symbolics.expression.zero))         {             simplified = true;             tot = result.item1;             break;         }     } }while(simplified); tot = rational.expand(tot);  infix.print(tot).dump();  //prints (512*r*t + 2048*r*t^2)/(512*r*t + 512*r^2*t + 3072*r*t^2 + 3072*r^2*t^2 + 1024*r*t^3) 

can give me pointers how proceed mathnet? i've tried various combinations of functions rational , polynomial, , have not been able move past point.

i've published new math.net symbolics release v0.6.0 includes new rational.reduce routine removes such common simple factors (also executed part of rational.expand):

var h1 = infix.parseorthrow("(1/8)*r*t*w + (1/2)*r*t^2*w"); var h2 = infix.parseorthrow("(1/8)*r*t*w + (1/8)*r^2*t*w + (3/4)*r*t^2*w + (3/4)*r^2*t^2*w + (1/4)*r*t^3*w");  var q1 = h1/h2; infix.print(q1); // returns: ((1/8)*r*t*w + (1/2)*r*t^2*w)/((1/8)*r*t*w + (1/8)*r^2*t*w + (3/4)*r*t^2*w + (3/4)*r^2*t^2*w + (1/4)*r*t^3*w)  var q2 = rational.expand(q1); infix.print(q2); // returns: (1 + 4*t)/(1 + r + 6*t + 6*r*t + 2*t^2) 

unfortunately quite few of univariate polynomial , rational routines new square-free factorization not have multivariate counterpart yet. univariate routines expect 1 symbol parameter, while multivariate ones expect symbol set.


Comments