dwave.optimization.mathematical.add#

add(x1: ArraySymbol, x2: ArraySymbol, *xi: ArraySymbol) Add | NaryAdd[source]#

Return an element-wise addition on the given symbols.

In the underlying directed acyclic expression graph, produces an Add node if two array nodes are provided and a NaryAdd node otherwise.

Parameters:
  • x1 – Input array symbol to be added.

  • x2 – Input array symbol to be added.

  • *xi – Additional input array symbols to be added.

Returns:

A symbol that sums the given symbols element-wise. Adding two symbols returns a Add. Adding three or more symbols returns a NaryAdd.

Examples

This example adds two integer symbols of size \(1 \times 2\). Equivalently, you can use the + operator (e.g., i + j).

>>> from dwave.optimization import Model
>>> from dwave.optimization.mathematical import add
...
>>> model = Model()
>>> i = model.integer(2)
>>> j = model.integer(2)
>>> i_plus_j = add(i, j)    # alternatively: i_plus_j = i + j
>>> with model.lock():
...     model.states.resize(1)
...     i.set_state(0, [3, 5])
...     j.set_state(0, [7, 5])
...     print(i_plus_j.state(0))
[10. 10.]