| 1 | initial version |
In 2*f(n) you are not multiplying 2 with f and then applying it to n,
but you are evaluating f(n) and then multiplying 2 with f(n).
| 2 | No.2 Revision |
In Symbolic functions can be multiplied by two, Python functions cannot.
sage: f(n) = n
sage: g = lambda n: n
sage: 2 * f
n |--> 2*n
sage: 2 * g
...
TypeError: unsupported operand parent(s) for '*': 'Integer Ring' and '<type 'function'>'
Note also that in 2*f(n) you are is not multiplying 2 with times f and then applying it applied to n,
, but you are evaluating f(n) and then multiplying 2 with times f(n).
| 3 | No.3 Revision |
Symbolic functions can be multiplied by two, Python functions cannot.
sage: f(n) = n
sage: g = lambda n: n
sage: 2 * f
n |--> 2*n
sage: 2 * g
...
TypeError: unsupported operand parent(s) for '*': 'Integer Ring' and '<type 'function'>'
Note also that in 2*f(n) is not 2 times f applied to n, but 2 times f(n).
Related: some common issues with functions.
| 4 | No.4 Revision |
Symbolic functions can be multiplied by two, Python functions cannot.
sage: f(n) = n
sage: g = lambda n: n
sage: 2 * f
n |--> 2*n
sage: 2 * g
...
TypeError: unsupported operand parent(s) for '*': 'Integer Ring' and '<type 'function'>'
Note also that in 2*f(n) is not 2 times f applied to n, but 2 times f(n).
Related: some common issues with functions.
Edit.
The equivalent of Maple's f := n -> n in Sage would be f(n) = n.
sage: two(n) = 2
sage: f(n) = n
sage: (two*f)(x)
sage: (2*f)(x)
sage: 2 * (f(x))
| 5 | No.5 Revision |
Symbolic functions can be multiplied by two, Python functions cannot.
sage: f(n) = n
sage: g = lambda n: n
sage: 2 * f
n |--> 2*n
sage: 2 * g
...
TypeError: unsupported operand parent(s) for '*': 'Integer Ring' and '<type 'function'>'
Note also that in 2*f(n) is not 2 times f applied to n, but 2 times f(n).
Related: some common issues with functions.
Edit.
The equivalent of Maple's f := n -> n in Sage would be f(n) = n.
Let us define
sage: two(n) = 2
sage: f(n) = n
sage: (two*f)(x)
sage: (2*f)(x)
sage: 2 * (f(x))
Then:
sage: [(two*f)(n) for n in (0 .. 4)]
[0, 2, 4, 6, 8]
sage: [(2*f)(n) for n in (0 .. 4)]
[0, 2, 4, 6, 8]
sage: [2*f(n) for n in (0 .. 4)]
[0, 2, 4, 6, 8]
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.