Skip to main content

Infer.NET user guide : Factors and Constraints

Boolean and Comparison Operations

This page lists the built-in methods and operators for applying Boolean operations like AND and OR, or for performing comparisons like greater-than or equality. 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.

Boolean Operations

Boolean 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 a and b are true.  
Or a b Creates a boolean random variable which is true if either a or b are true.
Not !a Creates a boolean random variable which is true if a is false.  
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 a and b are equal.
Not equals a!=b Creates a boolean random variable which is true if a and b are not equal.
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 a is greater than/less than/greater than or equal to/less than or equal to b.
IsPositive Variable.IsPositive(double x) Creates a boolean random variable which is true if x is positive.
IsBetween Variable.IsBetween(double x, double lowerBound, double upperBound) Creates a boolean random variable which is true if lowerBound <= x < upperBound.