# HG changeset patch
# User Karl-Dieter Crisman <kcrisman@gmail.com>
# Date 1274975156 14400
# Node ID 9bb80f99660c983fe1708d152382bafbd6155af8
# Parent 27c18494b6cb25ffdad2749fbea6a09efc363916
Trac 8568 - implement derivative for erf and ensure only legal symbolic derivatives are converted to Maxima
diff -r 27c18494b6cb -r 9bb80f99660c sage/functions/other.py
a
|
b
|
|
79 | 79 | raise NotImplementedError, "erf not implemented for precision higher than 53" |
80 | 80 | return parent(1 - pari(float(x)).erfc()) |
81 | 81 | |
| 82 | def _derivative_(self, x, diff_param=None): |
| 83 | """ |
| 84 | Derivative of erf function |
| 85 | |
| 86 | EXAMPLES:: |
| 87 | |
| 88 | sage: erf(x).diff(x) |
| 89 | 2*e^(-x^2)/sqrt(pi) |
| 90 | |
| 91 | TESTS:: |
| 92 | |
| 93 | Check if #8568 is fixed:: |
| 94 | |
| 95 | sage: var('c,x') |
| 96 | (c, x) |
| 97 | sage: derivative(erf(c*x),x) |
| 98 | 2*c*e^(-c^2*x^2)/sqrt(pi) |
| 99 | sage: erf(c*x).diff(x)._maxima_init_() |
| 100 | '((%pi)^(-1/2))*(c)*(exp(((c)^(2))*((x)^(2))*(-1)))*(2)' |
| 101 | """ |
| 102 | return 2*exp(-x**2)/sqrt(pi) |
| 103 | |
| 104 | |
82 | 105 | erf = Function_erf() |
83 | 106 | |
84 | 107 | class Function_abs(GinacFunction): |
diff -r 27c18494b6cb -r 9bb80f99660c sage/symbolic/expression_conversions.py
a
|
b
|
|
463 | 463 | """ |
464 | 464 | EXAMPLES:: |
465 | 465 | |
466 | | sage: import operator |
467 | 466 | sage: from sage.symbolic.expression_conversions import InterfaceInit |
468 | 467 | sage: m = InterfaceInit(maxima) |
469 | | sage: a = function('f', x).diff(x); a |
| 468 | sage: f = function('f') |
| 469 | sage: a = f(x).diff(x); a |
470 | 470 | D[0](f)(x) |
471 | 471 | sage: print m.derivative(a, a.operator()) |
472 | 472 | diff('f(x), x, 1) |
473 | | sage: b = function('f', x).diff(x).diff(x) |
| 473 | sage: b = f(x).diff(x, x) |
474 | 474 | sage: print m.derivative(b, b.operator()) |
475 | 475 | diff('f(x), x, 2) |
| 476 | |
| 477 | We can only convert to Maxima derivatives if the corresponding operand |
| 478 | of the function is a variable:: |
| 479 | |
| 480 | sage: y = var('y') |
| 481 | sage: t = f(x*y).diff(x) |
| 482 | sage: m.derivative(t, t.operator()) |
| 483 | Traceback (most recent call last): |
| 484 | ... |
| 485 | NotImplementedError: arguments must be distinct variables |
476 | 486 | """ |
477 | 487 | #This code should probably be moved into the interface |
478 | 488 | #object in a nice way. |
479 | 489 | from sage.symbolic.ring import is_SymbolicVariable |
480 | 490 | if self.name_init != "_maxima_init_": |
481 | 491 | raise NotImplementedError |
482 | | args = ex.args() |
| 492 | args = ex.operands() |
483 | 493 | if (not all(is_SymbolicVariable(v) for v in args) or |
484 | 494 | len(args) != len(set(args))): |
485 | 495 | raise NotImplementedError, "arguments must be distinct variables" |