Detected error in file toDiffAlgebraic.py (see todo)
authorAntonio Jimenez Pastor <antonio@ebook.dk-compmath.jku.at>
Thu, 27 Sep 2018 15:50:27 +0000 (17:50 +0200)
committerAntonio Jimenez Pastor <antonio@ebook.dk-compmath.jku.at>
Thu, 27 Sep 2018 15:50:27 +0000 (17:50 +0200)
Check webpage http://functions.wolfram.com/EllipticFunctions/DedekindEta/13/01/

ajpastor/dd_functions/ddExamples.py
ajpastor/dd_functions/toDiffAlgebraic.py
ajpastor/misc/ring_w_sequence.py
ajpastor/operator/oreOperator.py
ajpastor/tests/dd_functions/base_test.py [new file with mode: 0644]
releases/diff_defined_functions__0.6.zip
releases/old/diff_defined_functions__0.6__18.09.27_17:50:27.zip [new file with mode: 0644]

index 990c203..611cf38 100644 (file)
@@ -1572,27 +1572,28 @@ def __decide_parent(input, parent = None, depth = 1):
             - If 'input' is a polynomial, then the first generator will be consider as the variable of a DDRing and the others as parameters. Then we create the corresponding ParametrizedDDRing with the depth given.
             - Otherwise, we create the DDRing of the parent of 'input' of the given depth and try to work with that ring.
     '''
-    if(parent is None):
+    dR = parent;
+    if(dR is None):
         R = input.parent();
         if(isinstance(R, sage.symbolic.ring.SymbolicRing)):
             parameters = set([str(el) for el in input.variables()])-set(['x']);
             if(len(parameters) > 0 ):
-                parent = ParametrizedDDRing(DDRing(DFinite, depth=depth), parameters);
+                dR = ParametrizedDDRing(DDRing(DFinite, depth=depth), parameters);
             else:
-                parent = DDRing(PolynomialRing(QQ,x), depth=depth);
+                dR = DDRing(PolynomialRing(QQ,x), depth=depth);
         elif(is_MPolynomialRing(R) or is_PolynomialRing(R)):
             parameters = [str(gen) for gen in R.gens()[1:]];
             if(len(parameters) > 0):
-                parent = ParametrizedDDRing(DDRing(PolynomialRing(QQ,R.gens()[0]), depth=depth), parameters);
+                dR = ParametrizedDDRing(DDRing(PolynomialRing(R.base(),R.gens()[0]), depth=depth), parameters);
             else:
-                parent = DDRing(PolynomialRing(QQ,R.gens()[0]), depth = depth);
+                dR = DDRing(PolynomialRing(R.base(),R.gens()[0]), depth = depth);
         else:
             try:
-                parent = DDRing(R, depth = depth);
+                dR = DDRing(R, depth = depth);
             except Exception:
                 raise TypeError("The object provided is not in a valid Parent", e);
     
-    return parent.base()(input), parent;
+    return dR.base()(input), dR;
 
 def __check_list(list_of_elements, invalid_vars=[]):
     '''
@@ -1612,19 +1613,21 @@ def __check_list(list_of_elements, invalid_vars=[]):
     '''
     invalid_vars = [str(el) for el in invalid_vars];
     all_vars = [];
+    parent = QQ;
     for i in range(len(list_of_elements)):
         el = list_of_elements[i];
-        if(el not in QQ):
-            if(isinstance(el, str)):
-                all_vars += [el];
+        if(el in QQ):
+            pass;
+        elif(isinstance(el, str)):
+            all_vars += [el];
+        else:
+            from sage.rings.fraction_field import is_FractionField;
+            if(is_FractionField(el.parent())):
+                all_vars += [str(v) for v in el.numerator().variables()];
+                all_vars += [str(v) for v in el.denominator().variables()];
             else:
-                from sage.rings.fraction_field import is_FractionField;
-                if(is_FractionField(el.parent())):
-                    all_vars += [str(v) for v in el.numerator().variables()];
-                    all_vars += [str(v) for v in el.denominator().variables()];
-                else:
-                    all_vars += [str(v) for v in el.variables()];
-                list_of_elements[i] = str(el);
+                all_vars += [str(v) for v in el.variables()];
+            list_of_elements[i] = str(el);
     
     if(any(el in all_vars for el in invalid_vars)):
         raise ValueError("An invalid variable detected in the list.\n\t- Got: %s\n\t- Invalid: %s" %(list_of_elements, invalid_vars));
index e901bda..56f42fd 100644 (file)
@@ -33,6 +33,7 @@ def get_InfinitePolynomialRingGen(parent, var, with_number = False):
 def get_InfinitePolynomialRingVaribale(parent, gen, number):
     return parent(repr(gen).replace("*", str(number)));
     
+#### TODO: Review this function
 def infinite_derivative(element, times=1, var=x):
     if(times in ZZ and times > 1):
         return infinite_derivative(infinite_derivative(element, times-1))
@@ -51,15 +52,17 @@ def infinite_derivative(element, times=1, var=x):
             return parent.zero();
     if(element.is_monomial()):
         if(len(element.variables()) == 1 and element.degree() == 1):
-            return parent(repr(parent.gen()).replace("*", str(int(str(element).split("_")[-1])+1)));
+            g,n = get_InfinitePolynomialRingGen(parent, element, True);
+            return get_InfinitePolynomialRingVaribale(parent, g,n+1);
         else:
             degrees = element.degrees();
-            variables = [parent("y_%d" %i) for i in range(len(degrees))]; variables.reverse();
+            variables = element.variables();
+            degrees = [element.degree(v) for v in variables];
             ## Computing the common factor
             com_factor = prod([variables[i]**(degrees[i]-1) for i in range(len(degrees)) if degrees[i] > 0]);
             ## Computing the derivative for each variable
             each_sum = [
-                degrees[i]*infinite_derivative(variables[i])*prod(
+                degrees[i]*infinite_derivative(parent(variables[i]))*prod(
                     variables[j] for j in range(len(variables)) if ((i != j) and (degrees[j] > 0)))
                 for i in range(len(variables)) if degrees[i] > 0];
             
@@ -67,7 +70,7 @@ def infinite_derivative(element, times=1, var=x):
     else:
         coefficients = element.coefficients();
         monomials = element.monomials();
-        return sum([infinite_derivative(coefficients[i])*monomials[i] + coefficients[i]*infinite_derivative(parent(monomials[i])) for i in range(len(monomials))]);
+        return sum([infinite_derivative(coefficients[i])*monomials[i] + parent(coefficients[i])*infinite_derivative(parent(monomials[i])) for i in range(len(monomials))]);
     
 def fromInfinityPolynomial_toFinitePolynomial(poly):
     if(not is_InfinitePolynomialRing(poly.parent())):
index 1d5bb7e..00ecb9e 100644 (file)
@@ -91,10 +91,19 @@ class Wrap_w_Sequence_Ring (Ring_w_Sequence):
             raise TypeError("Element not in `self` to compute the sequence.");
 #####################################################################
 
-def sequence(el, n):
+def sequence(el, n, x_required=True):
     R = el.parent();
     if(sage.symbolic.ring.is_SymbolicExpressionRing(R)):
-        variable = el.variables()[0];
+        variables = [str(v) for v in el.variables()];
+        if('x' in variables):
+            variable = el.variables()[variables.index('x')];
+        elif(not x_required):
+            variable = el.variables()[0];
+        else:
+            if(n > 0):
+                return 0;
+            else:
+                return el;
         return el.derivative(variable,n)(**{str(variable):0})/factorial(n);
     if(not isinstance(R, Ring_w_Sequence)):
         R = Wrap_w_Sequence_Ring(R);
index 16cc5f4..08b15c2 100644 (file)
@@ -200,7 +200,7 @@ class w_OreOperator(Operator):
     ### MAGIC PYTHON METHODS
     ####################################################### 
     def __call__(self, obj):
-        return self.operator(obj);
+        return self.operator(obj, action=lambda p : p.derivative(x));
         
     def __repr__(self):
         return ("Wrapped_OreOperator(%s)"%(self.operator.__repr__()));
diff --git a/ajpastor/tests/dd_functions/base_test.py b/ajpastor/tests/dd_functions/base_test.py
new file mode 100644 (file)
index 0000000..bf018d6
--- /dev/null
@@ -0,0 +1,89 @@
+
+# This file was *autogenerated* from the file ./dd_functions/identities.sage
+from sage.all_cmdline import *   # import sage library
+
+_sage_const_3 = Integer(3); _sage_const_2 = Integer(2); _sage_const_1 = Integer(1); _sage_const_10 = Integer(10); _sage_const_0 = Integer(0)
+import sys, traceback;
+from timeit import default_timer as timer;
+
+from ajpastor.misc.verbose import *;
+from ajpastor.dd_functions import *;
+
+
+def run():
+    ## Loop variables
+    __MIN_N = _sage_const_2 ;
+    __MAX_N = _sage_const_10 ;
+    __DIFF = __MAX_N - __MIN_N;
+
+    ## Verbose control
+    __LEVEL = -_sage_const_2 ; ## Verbose level (-2 print loops, -1 print test, 0 print global data, greater print nothing
+    __PREV_LEVEL = sverbose.get_level();
+
+    ## Extra private functions
+    #def assert_initial(func, symbolic, size, name):
+    #    for i in range(size):
+    #        func_val = func.getInitialValue(i);
+    #        real_val = symbolic.derivative(i)(x=_sage_const_0 );
+    #        assert (func_val == real_val), "Error in the %d initial value of the function %s: expected %s but got %s"%(i,name,real_val,func_val);
+            
+    #def random_polynomial(min=-_sage_const_10 ,max=_sage_const_10 ,degree=_sage_const_3 ):
+    #    R = PolynomialRing(QQ,x);
+    #    p = R(_sage_const_1 );
+    #    while(p.degree() == _sage_const_0 ):
+    #        p = R([randint(min,max) for i in range(degree+_sage_const_1 )])
+    #    
+    #    return p;
+
+    ####################################################################################
+    ## Setting up the tests
+    sverbose.set_level(__LEVEL);
+    __deep_wrap = sverbose.get_deep_wrapper();
+    sverbose.set_deep_wrapper(-__LEVEL);
+    sverbose("Running tests over identities of DDFunctions"); ## HEAD LINE
+    sverbose("");
+    sverbose("Author: Antonio Jimenez-Pastor"); ## AUTHOR LINE
+    sverbose("Date: 27-09-2018"); ## DATE LINE
+    sverbose("");
+    sverbose.increase_depth();
+              
+
+    ##Starting execution
+    t = timer();
+    #########################################
+    ### TESTS FOR STRUCTURES DDRing and DDFunction
+    #########################################
+    try:
+        ## How to Start a section
+        #sverbose("Checking trigonometric equalities");
+        #sverbose.increase_depth();
+        # ...
+        #sverbose.decrease_depth();
+        
+        ## How to test an identity
+        #sverbose("sin^2(x)+cos^2(x) = 1");
+        #assert Sin(x)**_sage_const_2 +Cos(x)**_sage_const_2  == _sage_const_1 , "Error with sin^2(x)+cos^2(x) = 1";
+        
+        ## How to test a loop
+        #sverbose("Testing pushouts for parameters with D(QQ[x])");
+        #sverbose.increase_depth();
+        #sverbose.start_iteration(_sage_const_9 , True, True);
+        # ... code with 'sverbose.next_iteration();'
+        #sverbose.decrease_depth();
+        #sverbose("Finished tests");
+        
+        
+    except (Exception, KeyboardInterrupt) as e:
+        sverbose.reset_depth();
+        sverbose.set_level(__PREV_LEVEL);
+        print "Error found during tests: %s" %(e);
+        raise e;
+        
+    sverbose.decrease_depth();
+    sverbose("Finished all the tests on the examples");
+    t = timer() - t;
+    sverbose("Example tests finished successfully --> %s" %(t));
+    sverbose.set_deep_wrapper(__deep_wrap);
+    sverbose.set_level(__PREV_LEVEL);
+
+
index cd41160..53eb465 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.09.27_17:50:27.zip b/releases/old/diff_defined_functions__0.6__18.09.27_17:50:27.zip
new file mode 100644 (file)
index 0000000..53eb465
Binary files /dev/null and b/releases/old/diff_defined_functions__0.6__18.09.27_17:50:27.zip differ