- 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=[]):
'''
'''
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));
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))
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];
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())):
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);
### 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__()));
--- /dev/null
+
+# 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);
+
+