# How can I compare my step function?#

Comparisons with step functions can be done via relational or logical operators, all of which have associated operator symbols. Both classes of (binary) operators allow comparisons between two operands, either `staircase.Stairs` and `staircase.Stairs`, or `staircase.Stairs` and floats. As was the case for arithmetic operators (in the previous tutorial), a float x, is equivalent to `sc.Stairs(initial_value=x)` when used as an operand.

The result of these comparisons is always an instance of `staircase.Stairs` which at any point has value 0 (false), 1 (true) or is undefined. A step function resulting from the comparison of two step functions will be undefined whenever any one of them is undefined.

## Relational#

The intuition behind these operators is straightforward and derives from the corresponding operators between floats. Let’s see some examples:

```In : fig, axes = plt.subplots(ncols=2, figsize=(7,3), tight_layout=True)

In : sf.plot(ax=axes, arrows=True);

In : axes.set_title("sf");

In : (sf > 2).plot(ax=axes, arrows=True);

In : axes.set_title("sf > 2");
``` ```In : fig, axes = plt.subplots(ncols=2, figsize=(7,3), tight_layout=True)

In : sf.plot(ax=axes, arrows=True);

In : axes.set_title("sf");

In : (sf == -sf).plot(ax=axes, arrows=True);

In : axes.set_title("sf == -sf");
``` ## Logical#

Under the assumption that the value 1 is equivalent to true, and a value of 0 is equivalent to false, then a logical comparison between two boolean step functions (ones whose values are either 0, or 1) is intuitively derived from standard logical comparisons.

To answer the question of “what if the step function is not boolean valued” we appeal to the boolean definition that Python applies to numbers: anything not zero is considered true, and consequently only zero is false.

Let’s see some examples:

```In : fig, axes = plt.subplots(ncols=2, figsize=(7,3), tight_layout=True)

In : sf.plot(ax=axes, arrows=True);

In : axes.set_title("sf");

In : (sf & sf).plot(ax=axes, arrows=True);

In : axes.set_title("sf & sf");
``` ```In : fig, axes = plt.subplots(ncols=2, figsize=(7,3), tight_layout=True)

In : sf.plot(ax=axes, arrows=True);

In : axes.set_title("sf");

In : (sf ^ 1).plot(ax=axes, arrows=True);

In : axes.set_title("sf ^ 1");
``` 