# Revision history [back]

Can you tell us more about what you're trying to do? I have no trouble with the following:

sage: plot(unit_step(sin(x)), -2*pi,2*pi) Can you tell us more about what you're trying to do? I have no trouble with the following:

sage: plot(unit_step(sin(x)), -2*pi,2*pi) UPDATE:

I see; the problem you're running into is that h is a python function, while things like sin(x) and exp(x) are symbolic expressions. When you type h(f(x)), Sage is actually evaluating the function h on the entire symbolic expression f. When f is the exponential funciton, Sage knows that exp(x) is always positive, and hence h returns 1. When f is the sine function, neither of the conditions is met and so h returns nothing, hence giving the error you saw. Here is some code demonstrating these things:

sage: def h(x):
...    if x > 0: return 1
...    if x <= 0: return 0
...
sage: h(sin(x))
sage: h(exp(x))
1
sage: h(exp(x)-100)
sage: bool(exp(x) > 0)
True
sage: bool(sin(x) > 0)
False

sage: def h2(x):
...    if x > 0: return 1
...    if x <= 0: return 0
...    return 'Hello World!'
...
sage: h2(exp(x))
1
sage: h2(sin(x))
'Hello World!'


And lastly, here's a solution if you really do want to use a Python function: just make the whole function a Python function:

sage: def c(x):
...     return h(sin(x))
...
sage: plot(c, (x,-10,10))


Can you tell us more about what you're trying to do? I have no trouble with the following:

sage: plot(unit_step(sin(x)), -2*pi,2*pi) UPDATE:

I see; the problem you're running into is that h is a python function, while things like sin(x) and exp(x) are symbolic expressions. When you type h(f(x)), Sage is actually evaluating the function h on the entire symbolic expression ff(x). When ff(x) is the exponential funciton, Sage knows that exp(x) is always positive, and hence h returns 1. When ff(x) is the sine function, neither of the conditions is met and so h returns nothing, hence giving the error you saw. Here is some code demonstrating these things:

sage: def h(x):
...    if x > 0: return 1
...    if x <= 0: return 0
...
sage: h(sin(x))
sage: h(exp(x))
1
sage: h(exp(x)-100)
sage: bool(exp(x) > 0)
True
sage: bool(sin(x) > 0)
False

sage: def h2(x):
...    if x > 0: return 1
...    if x <= 0: return 0
...    return 'Hello World!'
...
sage: h2(exp(x))
1
sage: h2(sin(x))
'Hello World!'


And lastly, here's a solution if you really do want to use a Python function: just make the whole function a Python function:

sage: def c(x):
...     return h(sin(x))
...
sage: plot(c, (x,-10,10))