# Math, Logic, Compare

There are several elements that can be defined in simulations to update signals using mathematical operations. These blocks are:

gain: Multiplies a scalar or vector signal by the value of the gain. Supports both element-wise and matrix multiplication, set using the mode attribute.

product: Finds the product of the inputs to the block, or any subsystems provided. Includes a reciprocality attribute to set the reciprocality of each element being multiplied (* or /).

divide: Computes the division of its two inputs.

sum: Finds the sum of the inputs specified. If only one input is provided, it finds the sum of the elements in a vector.

subtract: Finds the difference between two inputs.

## Math Block

There is also a math block, which performs common mathematical operations such as trigonometric and exponential functions. Set the operation using the op attribute when defining the block:

`<math op="degToRad" />`

The different operations that are available are:

abs
A unary operation which computes the absolute value of each element of the input signal.

acos
A unary operation which computes the inverse cosine of each element of the input signal.

acosh
A unary operation which computes the inverse hyperbolic cosine of each element of the input signal.

acot
A unary operation which computes the inverse cotangent of each element of the input signal.

acoth
A unary operation which computes the inverse hyperbolic cotangent of each element of the input signal.

acsc
A unary operation which computes the inverse cosecant of each element of the input signal.

acsch
A unary operation which computes the inverse hyperbolic cosecant of each element of the input signal.

asec
A unary operation which computes the inverse secant of each element of the input signal.

asech
A unary operation which computes the inverse hyperbolic secant of each element of the input signal.

asin
A unary operation which computes the inverse sine of each element of the input signal.

asinh
A unary operation which computes the inverse hyperbolic sine of each element of the input signal.

atan
A unary operation which computes the inverse tangent of each element of the input signal.

atan2
A binary operation which computes the arctangent of each element of the first input signal with the corresponding element of the second input signal. If either input is a scalar, then the scalar is applied for each element of the other signal.

atanh
A unary operation which computes the inverse hyperbolic tangent of each element of the input signal.

ceil
A unary operation which computes the ceiling of each element of the input signal.

cos
A unary operation which computes the cosine of each element of the input signal.

cosh
A unary operation which computes the hyperbolic cosine of each element of the input signal.

cot
A unary operation which computes the cotangent of each element of the input signal.

coth
A unary operation which computes the hyperbolic cotangent of each element of the input signal.

csc
A unary operation which computes the cosecant of each element of the input signal.

csch
A unary operation which computes the hyperbolic cosecant of each element of the input signal.

degToRad
Converts each element of the input signal from degrees to radians.

exp
A unary operation which computes the exponential of each element of the input signal.

floor
A unary operation which computes the floor of each element of the input signal.

ln
A unary operation which computes the natural logarithm of each element of the input signal.

log
A binary operation which computes the logarithm of each element of the first input signal using the corresponding element of the second input signal as the base. If either input is a scalar, then the scalar is applied for each element of the other signal.

log10
A unary operation which computes the base-10 logarithm of each element of the input signal.

log2
A unary operation which computes the base-2 logarithm of each element of the input signal.

mod
A binary operation which computes the modulus of each element of the first input signal with respect to the corresponding element of the second input signal. If either input is a scalar, then the scalar is applied for each element of the other signal.

pow
A binary operation which computes the power of each element of the first input signal to the corresponding element of the second input signal. If either input is a scalar, then the scalar is applied for each element of the other signal.

pow10
A unary operation which computes ten to the power of each element of the input signal.

pow2
A unary operation which computes two to the power of each element of the input signal.

radToDeg
Converts each element of the input signal from radians to degrees.

reciprocal
A unary operation which computes the reciprocal of each element of the input signal.

rem
A binary operation which computes the IEEE remainder of each element of the first input signal with respect to the corresponding element of the second input signal. If either input is a scalar, then the scalar is applied for each element of the other signal.

round
A unary operation which computes the rounded value of each element of the input signal.

sec
A unary operation which computes the secant of each element of the input signal.

sech
A unary operation which computes the hyperbolic secant of each element of the input signal.

sign
A unary operation which computes the sign of each element of the input signal.

sin
A unary operation which computes the sine of each element of the input signal.

sinh
A unary operation which computes the hyperbolic sine of each element of the input signal.

sqrt
A unary operation which computes the square root of each element of the input signal.

square
A unary operation which computes the square of each element of the input signal.

tan
A unary operation which computes the tangent of each element of the input signal.

tanh
A unary operation which computes the hyperbolic tangent of each element of the input signal.

trunc
A unary operation which computes the truncation of each element of the input signal.

## Logic

The logic block can be used to apply a logical operation to each element of the input signal(s). Specify the operation using the op attribute.

`<logic op="and"/>`

Inputs can be specified before the logic block, or inside of it.

```<stack>
<constant value="5" />
<constant value="0" />
</stack>
<logic op="or" />```
```<logic op="nor">
<constant value="5" />
<constant value="1" />
</logic>```

The different operations that are available are:

and
A binary operation which outputs one if both inputs are non-zero and outputs zero otherwise.

bitand
A binary operation which outputs the bitwise AND of its two inputs.

bitimp
A binary operation which outputs the bitwise implication of its two inputs.

bitnand
A binary operation which outputs the bitwise NAND of its two inputs.

bitnimp
A binary operation which outputs the ones complement of the bitwise implication of its two inputs.

bitnor
A binary operation which outputs the bitwise NOR of its two inputs.

bitnot
A unary operation which outputs the ones complement of its input.

bitor
A binary operation which outputs the bitwise OR of its two inputs.

bitxnor
A binary operation which outputs the bitwise XNOR of its two inputs.

bitxor
A binary operation which outputs the bitwise XOR of its two inputs.

imp
A binary operation which outputs zero if its first input is non-zero and its second input is zero, and outputs one otherwise. The operation is known as material implication.

nand
A binary operation which outputs zero if both inputs are non-zero and outputs one otherwise.

nimp
A binary operation which outputs one if its first input is non-zero and its second input is zero, and outputs zero otherwise. The operation is the logical negation of material implication.

nor
A binary operation which outputs one if both inputs are zero and outputs zero otherwise.

not
A unary operation which outputs one if the input is zero and outputs zero otherwise.

or
A binary operation which outputs one if either input is non-zero and outputs zero otherwise.

xor
A binary operation which outputs one if one input is non-zero and the other input is zero, and outputs zero otherwise. The operation is known as the exclusive OR.

xnor
A binary operation which outputs zero if one input is non-zero and the other input is zero, and outputs one otherwise. The operation is known as the exclusive NOR.

## Compare

The compare block can be used to compare its input signal(s). Specify the type of comparison using the op attribute. The comparison mode can also be set using the mode attribute.

```<stack>
<constant value="2 3 0 -9" />
<constant value="1 5 0 -7" />
</stack>
<compare op="greaterOrEqual" mode="elements" />```
```<compare op="greaterOrEqual" mode="elements">
<constant value="2 3 0 -9" />
<constant value="1 5 0 -7" />
</compare>```

The different comparison modes are:

The different operations that are available are:

less
A binary operation which outputs one if the first input is less than the second input and outputs zero otherwise.

lessZero
A unary operation which outputs one if the input is less than zero and outputs zero otherwise.

lessOrEqual
A binary operation which outputs one if the first input is less than or equal to the second input and outputs zero otherwise.

lessOrEqualZero
A unary operation which outputs one if the input is less than or equal to zero and outputs zero otherwise.

equal
A binary operation which outputs one if the first input is equal to the second input and outputs zero otherwise.

equalZero
A unary operation which outputs one if the input is equal to zero and outputs zero otherwise.

notEqual
A binary operation which outputs one if the first input is not equal to the second input and outputs zero otherwise.

notEqualZero
A unary operation which outputs one if the input is not equal to zero and outputs zero otherwise.

greaterOrEqual
A binary operation which outputs one if the first input is greater than or equal to the second input and outputs zero otherwise.

greaterOrEqualZero
A unary operation which outputs one if the input is greater than or equal to zero and outputs zero otherwise.

greater
A binary operation which outputs one if the first input is greater than the second input and outputs zero otherwise.

greaterZero
A unary operation which outputs one if the input is greater than zero and outputs zero otherwise.