Fixed a bug in the computation of algebraic equation for functional inverses.
authorAntonio Jimenez Pastor <antonio@ebook.dk-compmath.jku.at>
Tue, 4 Dec 2018 17:03:50 +0000 (18:03 +0100)
committerAntonio Jimenez Pastor <antonio@ebook.dk-compmath.jku.at>
Tue, 4 Dec 2018 17:03:50 +0000 (18:03 +0100)
ajpastor/dd_functions/toDiffAlgebraic.py
releases/diff_defined_functions__0.6.zip
releases/old/diff_defined_functions__0.6__18.12.04_18:03:50.zip [new file with mode: 0644]

index ec4d207..92cb654 100644 (file)
@@ -118,6 +118,22 @@ def fromInfinityPolynomial_toFinitePolynomial(poly):
     
     parent = PolynomialRing(base, gens);
     return parent(str(poly));
+
+def fromFinitePolynomial_toInfinitePolynomial(poly):
+    parent = poly.parent();
+    if(is_InfinitePolynomialRing(poly) and (not is_MPolynomialRing(parent))):
+        return poly;
+    
+    
+    names = [str(el) for el in poly.parent().gens()];
+    pos = names[0].rfind("_");
+    if(pos == -1):
+        return poly;
+    prefix = names[0][:pos];
+    if(not all(el.find(prefix) == 0 for el in names)):
+        return poly;
+    R = InfinitePolynomialRing(parent.base(), prefix);
+    return R(str(poly));
     
 def toDifferentiallyAlgebraic_Below(poly, _debug=False):
     '''
@@ -274,7 +290,7 @@ def inverse_DA(poly, vars=None):
     return poly(**{str(g[i]): derivatives[i] for i in range(len(g))}).numerator();
 
 def func_inverse_DA(func, _debug=False):
-    equation = diff_to_diffalg(func, _debug=_debug);
+    equation = fromFinitePolynomial_toInfinitePolynomial(diff_to_diffalg(func, _debug=_debug));
     
     if(_debug): print equation;
     
@@ -285,9 +301,15 @@ def func_inverse_DA(func, _debug=False):
         
     quot = [FaaDiBruno_polynomials(i, parent)[0]/FaaDiBruno_polynomials(i,parent)[1] for i in range(n)];
     coeffs = [el(**{str(parent.base().gens()[0]) : y[0]}) for el in equation.coefficients()];
-    monomials = equation.monomials();
+    monomials = [el(**{str(y[j]) : quot[j] for j in range(n)}) for el in equation.monomials()];
+    
+    if(_debug):
+        print monomials;
+        print coeffs;
+    
+    sol = sum(monomials[i]*coeffs[i] for i in range(len(monomials)));
     
-    sol = sum(monomials[i](**{str(y[j]) : quot[j] for j in range(n)})*coeffs[i] for i in range(len(monomials)));
+    if(_debug): print sol;
     if(hasattr(sol, "numerator")):
         return parent(sol.numerator());
     return parent(sol);
index bed74e0..eb70b33 100644 (file)
Binary files a/releases/diff_defined_functions__0.6.zip and b/releases/diff_defined_functions__0.6.zip differ
diff --git a/releases/old/diff_defined_functions__0.6__18.12.04_18:03:50.zip b/releases/old/diff_defined_functions__0.6__18.12.04_18:03:50.zip
new file mode 100644 (file)
index 0000000..eb70b33
Binary files /dev/null and b/releases/old/diff_defined_functions__0.6__18.12.04_18:03:50.zip differ