# 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 [1]: fig, axes = plt.subplots(ncols=2, figsize=(7,3), tight_layout=True)
In [2]: sf.plot(ax=axes[0], arrows=True);
In [3]: axes[0].set_title("sf");
In [4]: (sf > 2).plot(ax=axes[1], arrows=True);
In [5]: axes[1].set_title("sf > 2");
```

```
In [6]: fig, axes = plt.subplots(ncols=2, figsize=(7,3), tight_layout=True)
In [7]: sf.plot(ax=axes[0], arrows=True);
In [8]: axes[0].set_title("sf");
In [9]: (sf == -sf).plot(ax=axes[1], arrows=True);
In [10]: axes[1].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 [11]: fig, axes = plt.subplots(ncols=2, figsize=(7,3), tight_layout=True)
In [12]: sf.plot(ax=axes[0], arrows=True);
In [13]: axes[0].set_title("sf");
In [14]: (sf & sf).plot(ax=axes[1], arrows=True);
In [15]: axes[1].set_title("sf & sf");
```

```
In [16]: fig, axes = plt.subplots(ncols=2, figsize=(7,3), tight_layout=True)
In [17]: sf.plot(ax=axes[0], arrows=True);
In [18]: axes[0].set_title("sf");
In [19]: (sf ^ 1).plot(ax=axes[1], arrows=True);
In [20]: axes[1].set_title("sf ^ 1");
```