| 21 | |

| 22 | |

| 23 | |

| 24 | ---- |

| 25 | |

| 26 | |

| 27 | From #11842, the list of what does/doesn't work: |

| 28 | {{{ |

| 29 | from sage.all import * |

| 30 | |

| 31 | |

| 32 | # 1. Fails. |

| 33 | x = var('x') |

| 34 | f = function('f', x) |

| 35 | g = function('g', x) |

| 36 | p = f |

| 37 | print p.substitute_function(f, g) # Outputs "f(x)" |

| 38 | |

| 39 | |

| 40 | |

| 41 | # 2. Fails. |

| 42 | x = var('x') |

| 43 | f = function('f') |

| 44 | g = function('g') |

| 45 | p = f(x) |

| 46 | print p.substitute_function(f(x), g(x)) # Outputs "f(x)" |

| 47 | |

| 48 | |

| 49 | |

| 50 | # 3. Works. |

| 51 | x = var('x') |

| 52 | f = function('f') |

| 53 | g = function('g') |

| 54 | p = f(x) |

| 55 | print p.substitute_function(f, g) # Outputs "g(x)" |

| 56 | |

| 57 | |

| 58 | |

| 59 | # 4. Fails. |

| 60 | x = var('x') |

| 61 | f = function('f') |

| 62 | g = function('g') |

| 63 | p = f(1) |

| 64 | print p.substitute_function(f(1), g(1)) # Outputs "f(1)" |

| 65 | |

| 66 | |

| 67 | |

| 68 | # 5. Works. |

| 69 | x = var('x') |

| 70 | f = function('f') |

| 71 | g = function('g') |

| 72 | p = f(1) |

| 73 | print p.substitute_function(f, g) # Outputs "g(1)" |

| 74 | |

| 75 | |

| 76 | |

| 77 | # 6. Fails. |

| 78 | x = var('x') |

| 79 | f = function('f', x) |

| 80 | g = function('g', x) |

| 81 | p = f.diff() |

| 82 | print p.substitute_function(f, g) # Outputs "D[0](f)(x)" |

| 83 | |

| 84 | |

| 85 | |

| 86 | # 7. Fails. |

| 87 | x = var('x') |

| 88 | f = function('f', x) |

| 89 | g = function('g', x) |

| 90 | p = f.diff() |

| 91 | print p.substitute_function(f(x), g(x)) # Outputs "D[0](f)(x)" |

| 92 | |

| 93 | |

| 94 | |

| 95 | # 8. Works. |

| 96 | x = var('x') |

| 97 | f = function('f') |

| 98 | g = function('g') |

| 99 | p = f(x).diff() |

| 100 | print p.substitute_function(f, g) # Outputs "D[0](g)(x)" |

| 101 | |

| 102 | |

| 103 | |

| 104 | # 9. Fails. |

| 105 | x = var('x') |

| 106 | f = function('f') |

| 107 | g = function('g') |

| 108 | p = f(x).diff()(1) |

| 109 | print p.substitute_function(f(x).diff(), g(x).diff()) # Outputs "D[0](f)(1)" |

| 110 | |

| 111 | |

| 112 | |

| 113 | # 10. Works.. |

| 114 | x = var('x') |

| 115 | f = function('f') |

| 116 | g = function('g') |

| 117 | p = f(x).diff()(1) |

| 118 | print p.substitute_function(f, g) # Prints D[0](g)(1). |

| 119 | }}} |