Modelica.Math.BooleanVectors

Library of functions operating on Boolean vectors

Information

This library provides functions operating on vectors that have a Boolean vector as input argument.

Extends from Modelica.Icons.Package (Icon for standard packages).

Package Content

Name Description
Modelica.Math.BooleanVectors.allTrue allTrue Returns true, if all elements of the Boolean input vector are true ('and')
Modelica.Math.BooleanVectors.andTrue andTrue Returns true, if all elements of the Boolean input vector are true ('and')
Modelica.Math.BooleanVectors.anyTrue anyTrue Returns true, if at least one element of the Boolean input vector is true ('or')
Modelica.Math.BooleanVectors.countTrue countTrue Returns the number of true elements in a Boolean vector
Modelica.Math.BooleanVectors.enumerate enumerate Enumerates the true elements in a Boolean vector (0 for false elements)
Modelica.Math.BooleanVectors.firstTrueIndex firstTrueIndex Returns the index of the first true element of a Boolean vector
Modelica.Math.BooleanVectors.index index Returns the indices of the true elements of a Boolean vector
Modelica.Math.BooleanVectors.oneTrue oneTrue Returns true, if exactly one element of the Boolean input vector is true ("xor")

Modelica.Math.BooleanVectors.allTrue Modelica.Math.BooleanVectors.allTrue

Returns true, if all elements of the Boolean input vector are true ('and')

Information

Syntax

allTrue(b);

Description

Returns true if all elements of the Boolean input vector b are true. Otherwise the function returns false. If b is an empty vector, i.e., size(b,1)=0, the function returns false (as opposed to andTrue returning true).

Example

  Boolean b1[3] = {true, true, true};
  Boolean b2[3] = {false, true, false};
  Boolean r1, r2;
algorithm
  r1 = allTrue(b1);  // r1 = true
  r2 = allTrue(b2);  // r2 = false

See also

andTrue, anyTrue, countTrue, enumerate, firstTrueIndex, index, and oneTrue.

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

NameDescription
b[:]Boolean vector

Outputs

NameDescription
result= true, if all elements of b are true

Modelica.Math.BooleanVectors.andTrue Modelica.Math.BooleanVectors.andTrue

Returns true, if all elements of the Boolean input vector are true ('and')

Information

Syntax

andTrue(b);

Description

Returns true if all elements of the Boolean input vector b are true. Otherwise the function returns false. If b is an empty vector, i.e., size(b,1)=0, the function returns true (as opposed to allTrue returning false).

Example

  Boolean b1[3] = {true, true, true};
  Boolean b2[3] = {false, true, false};
  Boolean r1, r2;
algorithm
  r1 = andTrue(b1);  // r1 = true
  r2 = andTrue(b2);  // r2 = false

See also

allTrue, anyTrue, countTrue, enumerate, firstTrueIndex, index, and oneTrue.

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

NameDescription
b[:]Boolean vector

Outputs

NameDescription
result= true, if all elements of b are true

Modelica.Math.BooleanVectors.anyTrue Modelica.Math.BooleanVectors.anyTrue

Returns true, if at least one element of the Boolean input vector is true ('or')

Information

Syntax

anyTrue(b);

Description

Returns true if at least one element of the input Boolean vector b is true. Otherwise the function returns false. If b is an empty vector, i.e., size(b,1)=0, the function returns false.

Example

  Boolean b1[3] = {false, false, false};
  Boolean b2[3] = {false, true, false};
  Boolean r1, r2;
algorithm
  r1 = anyTrue(b1);  // r1 = false
  r2 = anyTrue(b2);  // r2 = true

See also

allTrue, andTrue, countTrue, enumerate, firstTrueIndex, index, and oneTrue.

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

NameDescription
b[:]Boolean vector

Outputs

NameDescription
result= true, if at least one element of b is true

Modelica.Math.BooleanVectors.countTrue Modelica.Math.BooleanVectors.countTrue

Returns the number of true elements in a Boolean vector

Information

Syntax

countTrue(b);

Description

This function returns the number of true elements in a Boolean vector b.

Example

countTrue({false, true, false, true}) returns 2.

See also

allTrue, andTrue, anyTrue, enumerate, firstTrueIndex, index, and oneTrue.

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

NameDescription
b[:]Boolean vector

Outputs

NameDescription
nNumber of true elements in b

Modelica.Math.BooleanVectors.enumerate Modelica.Math.BooleanVectors.enumerate

Enumerates the true elements in a Boolean vector (0 for false elements)

Information

Syntax

enumerate(b);

Description

This function returns an integer vector that consecutively numbers the true elements in a Boolean vector b. The false elements are indicated by 0.

Example

enumerate({false, true, false, true}) returns {0,1,0,2}.

See also

allTrue, andTrue, anyTrue, countTrue, firstTrueIndex, index, and oneTrue.

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

NameDescription
b[:]Boolean vector

Outputs

NameDescription
enumerated[size(b, 1)]Indices of the true elements in b (increasing order; 0 for false elements)

Modelica.Math.BooleanVectors.firstTrueIndex Modelica.Math.BooleanVectors.firstTrueIndex

Returns the index of the first true element of a Boolean vector

Information

Syntax

firstTrueIndex(b);

Description

Returns the index of the first true element of the Boolean vector b. If no element is true or b is an empty vector (i.e., size(b,1)=0) the function returns 0.

Example

  Boolean b1[3] = {false, false, false};
  Boolean b2[3] = {false, true, false};
  Boolean b3[4] = {false, true, false, true};
  Integer r1, r2, r3;
algorithm
  r1 = firstTrueIndex(b1);  // r1 = 0
  r2 = firstTrueIndex(b2);  // r2 = 2
  r3 = firstTrueIndex(b3);  // r3 = 2

See also

allTrue, andTrue, anyTrue, countTrue, enumerate, index, and oneTrue.

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

NameDescription
b[:]Boolean vector

Outputs

NameDescription
indexIndex of the first true element of b

Modelica.Math.BooleanVectors.index Modelica.Math.BooleanVectors.index

Returns the indices of the true elements of a Boolean vector

Information

Syntax

index(b);

Description

This function returns an integer vector that contains indices to the true elements in a Boolean vector b. The number of elements in the integer vector is the number of true elements in b.

Example

index({false, true, false, true}) returns {2,4}.

See also

allTrue, andTrue, anyTrue, countTrue, enumerate, firstTrueIndex, and oneTrue.

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

NameDescription
b[:]Boolean vector

Outputs

NameDescription
indices[countTrue(b)]Indices of the true elements of b

Modelica.Math.BooleanVectors.oneTrue Modelica.Math.BooleanVectors.oneTrue

Returns true, if exactly one element of the Boolean input vector is true ("xor")

Information

Syntax

oneTrue(b);

Description

Returns true if exactly one element of the input Boolean vector b is true. Otherwise the function returns false. If b is an empty vector, i.e., size(b,1)=0, the function returns false.

Example

  Boolean b1[3] = {false, false, false};
  Boolean b2[3] = {false, true, false};
  Boolean b3[3] = {false, true, true};
  Boolean r1, r2, r3;
algorithm
  r1 = oneTrue(b1);  // r1 = false
  r2 = oneTrue(b2);  // r2 = true
  r3 = oneTrue(b3);  // r3 = false

See also

allTrue, andTrue, anyTrue, countTrue, enumerate, firstTrueIndex, and index.

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

NameDescription
b[:]Boolean vector

Outputs

NameDescription
result= true, if exactly one element of b is true
Automatically generated Thu Oct 1 16:08:15 2020.