1 | initial version |

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)
```

2 | responded to OP comment |

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))
```

3 | No.3 Revision |

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

. When ~~f~~f(x)

is the exponential funciton, Sage knows that ~~f~~f(x)`exp(x)`

is always positive, and hence `h`

returns `1`

. When

is the sine function, neither of the conditions is met and so ~~f~~f(x)`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))
```

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.