dwave.optimization.mathematical.mod#

mod(x1: ArraySymbol, x2: ArraySymbol) Modulus[source]#

Return an element-wise modulus of the given symbols.

Parameters:
  • x1 – Input array symbol.

  • x2 – Input array symbol.

Returns:

A symbol that is the element-wise modulus of the given symbols.

Examples

This example demonstrates the behavior of the modulus of two integer symbols \(i \mod{j}\) with different combinations of positive and negative values. Equivalently, you can use the % operator (e.g., i % j).

>>> from dwave.optimization import Model
>>> from dwave.optimization.mathematical import mod
...
>>> model = Model()
>>> i = model.integer(4, lower_bound=-5)
>>> j = model.integer(4, lower_bound=-3)
>>> k = mod(i, j) # alternatively: k = i % j
>>> with model.lock():
...     model.states.resize(1)
...     i.set_state(0, [5, -5, 5, -5])
...     j.set_state(0, [3, 3, -3, -3])
...     print(k.state(0))
[ 2.  1. -1. -2.]

This example demonstrates the modulus of a scalar float value and a binary symbol.

>>> from dwave.optimization import Model
>>> from dwave.optimization.mathematical import mod
...
>>> model = Model()
>>> i = model.constant(0.33)
>>> j = model.binary(2)
>>> k = mod(i, j) # alternatively: k = i % j
>>> with model.lock():
...     model.states.resize(1)
...     j.set_state(0, [0, 1])
...     print(k.state(0))
[0.   0.33]