Modified the _element_constructor_ method of DDFunction to allow elements in
authorAntonio Jimenez Pastor <antonio@ebook.dk-compmath.jku.at>
Thu, 20 Sep 2018 15:21:47 +0000 (17:21 +0200)
committerAntonio Jimenez Pastor <antonio@ebook.dk-compmath.jku.at>
Thu, 20 Sep 2018 15:21:47 +0000 (17:21 +0200)
the FractionField of the base domain.

Added combinatorial examples: Fibonacci (with option to two parameters) and Catalan numbers

ajpastor/dd_functions/ddExamples.py
ajpastor/dd_functions/ddFunction.py
releases/diff_defined_functions__0.5.zip
releases/old/diff_defined_functions__0.5__18.09.20_17:21:47.zip [new file with mode: 0644]

index 69079ee..990c203 100644 (file)
@@ -67,6 +67,10 @@ def ddExamples(functions = False, names=False):
             - HeunD
         ** COULOMB WAVE FUNCTION (see chapter 33 in https://dlmf.nist.gov)
             - CoulombF
+            
+        ** COMBINATORIAL FUNCTIONS
+            - Catalan
+            - Fibonacci
     '''
     if(not functions):
         print ddExamples.__doc__;
@@ -1367,6 +1371,41 @@ def CoulombF(m='m', l='l'):
             
     return destiny_ring.element([x**2-2*rm*x-rl*(rl+1), 0, x**2], init=init, name=DinamicString("CoulombF(_1;_2)(_3)", [repr(rm), repr(rl), "x"]));
 
+##################################################################################
+##################################################################################
+###
+### Combinatorial functions
+###
+##################################################################################
+################################################################################## 
+@cached_function
+def Catalan():
+    return DFinite.element([2, 10*x-2, 4*x**2-x], [1,1]);
+
+@cached_function
+def Fibonacci(init=(1,1)):
+    parent, rinit = __check_list([el for el in init], [str(el) for el in DFinite.variables()]);
+    params = [str(v) for v in parent.gens()];
+    pos = ord('a');
+    if(len(init) < 2):
+        if(len(init) < 1):
+            while(chr(pos) in params):
+                pos += 1;
+            rinit = [chr(pos)];
+        if(len(init) == 1):
+            while(chr(pos) in params):
+                pos += 1;
+            rinit += [chr(pos)];
+        return Fibonacci(tuple(rinit));
+    
+    if(parent is QQ):
+        destiny_ring = DFinite;
+    else:
+        destiny_ring = ParametrizedDDRing(DFinite, params);
+    
+    x = destiny_ring.variables()[0];
+    
+    return destiny_ring(((rinit[1]-rinit[0])*x + rinit[0])/(1-x-x**2));
             
 ##################################################################################
 ##################################################################################
index d90ecf1..aa3dbc6 100644 (file)
@@ -481,13 +481,24 @@ class DDRing (Ring_w_Sequence, IntegralDomain):
             else:
                 try:
                     try:
-                        X = self.base()(X);
+                        num = self.base()(X); den = self.base().one();
                     except TypeError as e:
                         try:
-                            X = self.base()(str(X));
+                            num = self.base()(str(X)); den = self.base().one();
                         except:
-                            raise e;
-                    el = self.element([-self.base_derivation(X), X]);
+                            ## Trying the fraction field
+                            try:
+                                X = self.base().fraction_field()(X);
+                                num = self.base()(X.numerator()); den = self.base()(X.denominator());
+                            except:
+                                try:
+                                    X = self.base().fraction_field()(str(X));
+                                    num = self.base()(X.numerator()); den = self.base()(X.denominator());
+                                except:
+                                    raise e;
+                                
+                    dnum = self.base_derivation(num); dden = self.base_derivation(den);
+                    el = self.element([dden*num - dnum*den, num*den]);
                     name = str(X);
                     try:
                         name = X._DDFunction__name;
index 914736f..221e173 100644 (file)
Binary files a/releases/diff_defined_functions__0.5.zip and b/releases/diff_defined_functions__0.5.zip differ
diff --git a/releases/old/diff_defined_functions__0.5__18.09.20_17:21:47.zip b/releases/old/diff_defined_functions__0.5__18.09.20_17:21:47.zip
new file mode 100644 (file)
index 0000000..221e173
Binary files /dev/null and b/releases/old/diff_defined_functions__0.5__18.09.20_17:21:47.zip differ