On 11/07/11 21:03, kcrisman wrote: > > So are you saying that Python and Piecewise functions will no longer > behave correctly if this behavior goes from warning to error? It > would be great if you had a "toy" example with full code; maybe there > is a workaround that needs to become standard practice here... > > - kcrisman >
Here's an example of the warning on a python function. It's just showing the warning in the wrong place. I've commented the point in the function where the warning really gets thrown, but I can't figure out a way to get rid of the warning and make the function work at the same time. I'm aware that my entire approach here is stupid; I'm willing to accept any replacements that work as well or better =) $ cat python_function_test.py #!/home/mjo/bin/sage from sage.all import * def please_substitute_function(max_degree, points, expr, func1, func2): """ Sage can't substitute_function on an expression with (evaluated) derivatives. """ for degree in range(0, max_degree+1): for point_idx in range(0, len(points)): var1, var2 = var('whatever1,whatever2') deriv1 = SR(0) if len(func1.variables()) > 0: var1 = func1.variables()[0] deriv1 = derivative(func1, var1, degree) deriv2 = SR(0) if len(func1.variables()) > 0: var2 = func2.variables()[0] deriv2 = derivative(func2, var2, degree) target = SR(0) if len(deriv1.variables()) > 0: # Works, but throws a warning. target = deriv1(points[point_idx]) # No error, but doesn't work. # target = deriv1(var1=points[point_idx]) replacement = SR(0) if len(deriv2.variables()) > 0: # Works, but throws a warning. replacement = deriv2(points[point_idx]) # No error, but doesn't work. # replacement = deriv2(var2=points[point_idx]) expr = expr.substitute_expression(target == replacement) return expr x = SR.symbol('x', domain='real') f = function('f', x) p1 = f.diff(x)(x = -1)*x**2 + f(x = 1)*x**3 g = function('g', x) p2 = please_substitute_function(1, [-1,1], p1, f, g) print "p1:" print p1 print "" print "p2:" print p2 print "" -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org