## Boolean factors

This page lists the built-in methods and operators for creating random variables of type `bool`

. For both static methods and operators, you can often pass in random variables as arguments e.g. `Variable<bool>`

instead of `bool`

. For compactness, this is not shown in the syntax below.

These methods provide a convenient short alternative to using `Variable<T>.Factor`

and passing in the factor method, as described on this page.

#### Distribution Factors

A distribution factor creates a random variable from a parameterised distribution.

Distribution |
Syntax |
Description |
---|---|---|

Bernoulli | `Variable.Bernoulli(double probTrue)` |
Creates a boolean random variable from the probability of being true P(true). |

Bernoulli | `Variable.BernoulliFromLogOdds(double logOdds)` |
Creates a boolean random variable from the log odds i.e. log P(true)/P(false). Equivalent to `Variable.Bernoulli(Variable.Logistic(logOdds))` . |

#### Logical Operations

Logical operations are supported via operator overloads or static methods.

Operation |
Syntax |
Description |
---|---|---|

And |
a & b | Creates a boolean random variable which is true if both and `a` are true.`b` |

Or |
a `or` b |
Creates a boolean random variable which is true if either or `a` are true.`b` |

Not |
!a | Creates a boolean random variable which is true if is false.`a` |

AllTrue |
`Variable.AllTrue(bool[] array) Variable.AllTrue(IList<bool> array)` |
Creates a boolean random variable which is true if all the elements of array are true. In other words, this is a N-valued AND. Where the array has length two, & should be used instead. |

#### Comparison Operations

Comparison operations are supported via operator overloads or static methods.

Operation |
Syntax |
Description |
---|---|---|

Equals |
a==b | Creates a boolean random variable which is true if and `a` are equal.`b` |

Not equals |
a!=b | Creates a boolean random variable which is true if and `a` are not equal.`b` |

Greater than / less than |
a>b, a<b, a>=b, a<=b Note: a and b must be both double or both int | Creates a boolean random variable which is true if is greater than/less than/greater than or equal to/less than or equal to `a` .`b` |

IsPositive |
`Variable.IsPositive(double x)` |
Creates a boolean random variable which is true if is positive.`x` |

IsBetween |
`Variable.IsBetween(double x, double lowerBound, double upperBound)` |
Creates a boolean random variable which is true if lowerBound <= x < upperBound. |