Changed the basic examples to compute the differential equation directly instead...
authorAntonio Jimenez Pastor <antonio@ebook.dk-compmath.jku.at>
Tue, 2 Oct 2018 14:30:51 +0000 (16:30 +0200)
committerAntonio Jimenez Pastor <antonio@ebook.dk-compmath.jku.at>
Tue, 2 Oct 2018 14:30:51 +0000 (16:30 +0200)
Fixed a small bug that threw errors in the LazyRing with DD-finite functions and over.

Added a method (not completed) to_simpler that reduces the basic ring. The part for order 1 D-finite functions works properly.

ajpastor/dd_functions/ddExamples.py
ajpastor/dd_functions/ddFunction.py
ajpastor/lazy/lazyRing.py
releases/diff_defined_functions__0.6.zip
releases/old/diff_defined_functions__0.6__18.10.02_16:30:51.zip [new file with mode: 0644]

index 14b6b86..9fe0262 100644 (file)
@@ -104,9 +104,8 @@ def Sin(input, ddR = None):
             
         This function can be converted into symbolic expressions.
     '''
-    
-    if(is_DDFunction(input)):
-        return Sin(x)(input);
+    #if(is_DDFunction(input)):
+    #    return Sin(x)(input);
     f,dR = __decide_parent(input, ddR);
     
     evaluate = lambda p : dR.getSequenceElement(p,_sage_const_0 );
@@ -138,8 +137,8 @@ def Cos(input, ddR = None):
             
         This function can be converted into symbolic expressions.
     '''
-    if(is_DDFunction(input)):
-        return Cos(x)(input);
+    #if(is_DDFunction(input)):
+    #    return Cos(x)(input);
     f,dR = __decide_parent(input, ddR);
     
     evaluate = lambda p : dR.getSequenceElement(p,_sage_const_0 );
@@ -171,8 +170,8 @@ def Tan(input, ddR = None):
             
         This function can be converted into symbolic expressions.
     '''
-    if(is_DDFunction(input)):
-        return Tan(x)(input);
+    #if(is_DDFunction(input)):
+    #    return Tan(x)(input);
     if(input == x):
         return DDFinite.element([-_sage_const_2,0,Cos(x)**2],[0,1]);
     g, dR = __decide_parent(input, ddR,_sage_const_2 );
@@ -221,8 +220,8 @@ def Sinh(input, ddR = None):
             
         This function can be converted into symbolic expressions.
     '''
-    if(is_DDFunction(input)):
-        return Sinh(x)(input);
+    #if(is_DDFunction(input)):
+    #    return Sinh(x)(input);
     f,dR = __decide_parent(input, ddR);
     
     evaluate = lambda p : dR.getSequenceElement(p,_sage_const_0 );
@@ -254,8 +253,8 @@ def Cosh(input, ddR = None):
             
         This function can be converted into symbolic expressions.
     '''
-    if(is_DDFunction(input)):
-        return Cosh(x)(input);
+    #if(is_DDFunction(input)):
+    #    return Cosh(x)(input);
     f,dR = __decide_parent(input, ddR);
     
     evaluate = lambda p : dR.getSequenceElement(p,_sage_const_0 );
@@ -294,8 +293,8 @@ def Log(input, ddR = None):
             
         This function can be converted into symbolic expressions.
     '''
-    if(is_DDFunction(input)):
-        return Log(x+_sage_const_1 )(input-1);
+    #if(is_DDFunction(input)):
+    #    return Log(x+_sage_const_1 )(input-1);
     f,dR = __decide_parent(input, ddR);
     
     evaluate = lambda p : dR.getSequenceElement(p,_sage_const_0 );
@@ -327,8 +326,8 @@ def Log1(input, ddR = None):
             
         This function can be converted into symbolic expressions.
     '''
-    if(is_DDFunction(input)):
-        return Log1(x)(input);
+    #if(is_DDFunction(input)):
+    #    return Log1(x)(input);
     f,dR = __decide_parent(input, ddR);
     
     evaluate = lambda p : dR.getSequenceElement(p,_sage_const_0 );
@@ -362,8 +361,8 @@ def Exp(input, ddR = None):
             
         This function can be converted into symbolic expressions.
     '''
-    if(is_DDFunction(input)):
-        return Exp(x)(input);
+    #if(is_DDFunction(input)):
+    #    return Exp(x)(input);
     f,dR = __decide_parent(input, ddR);
     
     evaluate = lambda p : dR.getSequenceElement(p,_sage_const_0 );
@@ -958,7 +957,7 @@ def HillD(a='a',q='q',init=()):
             - init: a TUPLE with the initial values for the function. Each element can be a string to create a variable, any rational number or any polynomial expression which variables will be considered as parameters (so 'x' is not allowed).
     '''
     if(is_DDFunction(q)):
-        destiny_ring = DDRing(q.parent());
+        destiny_ring = q.parent().to_depth(q.parent().depth());
         parent, new_all = __check_list([a] + list(init), [str(el) for el in DFinite.variables()]);
         
         if(not (parent is QQ)):
index bc66494..75054c7 100644 (file)
@@ -674,7 +674,7 @@ class DDRing (Ring_w_Sequence, IntegralDomain):
         elif(len(input) == 0 ):
             return element;
         
-        raise NotImplementedError("Not implemented evaluation of an element of this ring (%s) with the parameters %s and %s" %(self,rx,input));
+        raise NotImplementedError("Not implemented evaluation of an element of this ring (%s) with the parameters %s and %s" %(self,repr(rx),input));
         
     def get_recurrence(self, *args, **kwds):
         if(self.__get_recurrence is None):
@@ -1531,13 +1531,24 @@ class DDFunction (IntegralDomainElement):
     #####################################
     ### Differential methods
     #####################################
-    def derivative(self, *args):
+    def derivative(self, *args, **kwds):
         '''
         Method to get a DDFunction `g` that satisfies `D(self) = g`.
         
         INPUT:
             - ``args``: ignored input
-        '''
+            - ''kwds'': if times is included, we compute the times-th derivative
+        '''
+        if('times' in kwds):
+            if(kwds['times'] in ZZ):
+                times = kwds['times'];
+                if(times < 0):
+                    raise ValueError("Negative derivatives can not be computed");
+                elif(times == 0):
+                    return self;
+                elif(times > 1):
+                    return self.derivative(times=times-1).derivative();
+                
         if(self.__derivative is None):
             if(self.is_constant):
                 ### Special case: is a constant
@@ -1838,12 +1849,29 @@ class DDFunction (IntegralDomainElement):
             to_mult *= value;
         return float(res),float(abs(to_sum));
         
+    @cached_method
     def to_symbolic(self):
         evaluation = sage_eval(str(self.__name).replace("'", ".derivative()").replace("^", "**"), locals=globals());
         if(isinstance(evaluation, sage.symbolic.expression.Expression)):
             evaluation = evaluation.simplify_full();
             
         return evaluation;
+    
+    @cached_method
+    def to_simpler(self):
+        try:
+            R = self.parent().base();
+            if(is_DDRing(R)):
+                return R(self).to_simpler();
+            elif(is_PolynomialRing(R)):
+                if(self.getOrder() == 1):
+                    degree = abs(self[0].lc());
+                    if(self.derivative(times=degree+1).is_null):
+                        x = self.parent().variables()[0];
+                        return sum(self.getSequenceElement(i)*x**i for i in range(degree+1));
+        except:
+            pass;
+        return self;
             
     def quick_equals(self,other): ### TO REVIEW
         '''
index d1e162d..6f2e32d 100644 (file)
@@ -210,7 +210,7 @@ class _LazyElement(IntegralDomainElement):
         
     def is_zero(self):
         result = (self.poly() == _sage_const_0 );
-        if((not result) and (self(**{str(self.parent().base().variables()[_sage_const_0 ]):_sage_const_0 }) == _sage_const_0 )):
+        if((not result) and (self(**{repr(self.parent().base().variables()[_sage_const_0 ]):_sage_const_0 }) == _sage_const_0 )):
             if(not (self.__raw is None)):
                 result = self.raw() == _sage_const_0 ;
             else:
index e156066..ab45241 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.10.02_16:30:51.zip b/releases/old/diff_defined_functions__0.6__18.10.02_16:30:51.zip
new file mode 100644 (file)
index 0000000..ab45241
Binary files /dev/null and b/releases/old/diff_defined_functions__0.6__18.10.02_16:30:51.zip differ