# Question about the error: Variables do not support boolean operations

**URL:** https://discourse.pymc.io/t/question-about-the-error-variables-do-not-support-boolean-operations/13053
**Category:** General
**Created:** [October 5, 2023, 7:18am UTC](https://discourse.pymc.io/t/question-about-the-error-variables-do-not-support-boolean-operations/13053 "2023-10-05T07:18:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Sherry](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@Sherry](https://discourse.pymc.io/u/Sherry)
#### Post date: [October 5, 2023, 7:18am UTC](https://discourse.pymc.io/t/question-about-the-error-variables-do-not-support-boolean-operations/13053/1 "2023-10-05T07:18:08Z")

</div>

I want to use boolean operations on variable. Here is the code:

```auto
with pm.Model() as hierarchical_model:
    tau = pm.Uniform('tau', lower=1, upper=100)
    for t in range(ntrials):
        if t < tau:
            ......
        else:
            ......

```

while I receive the error:  
TypeError: Variables do not support boolean operations.

I try to use `if tau.gt(t)` to replace `if t < tau`, but receive the error:  
AttributeError: ‘TensorVariable’ object has no attribute ‘gt’

I have also update NumPy to 1.22

Thanks for any help!

---

<div class="post-metadata">

### Author: ![jessegrabowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jessegrabowski/32/5010_2.png) [@jessegrabowski](https://discourse.pymc.io/u/jessegrabowski)
#### Post date: [October 5, 2023, 11:56am UTC](https://discourse.pymc.io/t/question-about-the-error-variables-do-not-support-boolean-operations/13053/2 "2023-10-05T11:56:13Z")

</div>

As you’ve discovered, you’re not allowed to use normal Python control flow operators (`if`, `else`, `for`, `while`, `try`, etc) inside a PyMC model. These need special implementations that allow them to be represented on a computation graph (so that we can do reverse-mode autodiff).

The special function for conditions is `pm.math.switch`. The API docs for it aren’t very helpful, so [here’s an example model](https://www.pymc.io/projects/docs/en/latest/learn/core_notebooks/pymc_overview.html#case-study-2-coal-mining-disasters) that uses a switch to find a change point on discrete data. It should give you a pattern to follow for your own model.
