function plus
plus(
x: number,
y: number,
): number

Addition X + Y.

Adds two numbers, arrays, or matrices element-wise. Handles mixed inputs of scalars, arrays, and matrices.

Examples

Add two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus(5, 6), 11);

Add two arrays element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([5, 6, 4], [3, -1, 0]), [8, 5, 4]);

Add a number to each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([5, 6, 4], 10), [15, 16, 14]);

Add a number to each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus(10, [[5, 6], [3, 4]]), [[15, 16], [13, 14]]);

Add two matrices element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([[5, 6], [3, 4]], [[2, 3], [1, 2]]), [[7, 9], [4, 6]]);

Parameters

x: number

The first operand, can be a number, array, or matrix.

y: number

The second operand, can be a number, array, or matrix.

Return Type

number

The result of adding x and y.

Throws

If the input dimensions do not agree or if no arguments are provided.

plus(
x: number,
y: array,
): array

Addition X + Y.

Adds two numbers, arrays, or matrices element-wise. Handles mixed inputs of scalars, arrays, and matrices.

Examples

Add two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus(5, 6), 11);

Add two arrays element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([5, 6, 4], [3, -1, 0]), [8, 5, 4]);

Add a number to each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([5, 6, 4], 10), [15, 16, 14]);

Add a number to each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus(10, [[5, 6], [3, 4]]), [[15, 16], [13, 14]]);

Add two matrices element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([[5, 6], [3, 4]], [[2, 3], [1, 2]]), [[7, 9], [4, 6]]);

Parameters

x: number

The first operand, can be a number, array, or matrix.

The second operand, can be a number, array, or matrix.

Return Type

The result of adding x and y.

Throws

If the input dimensions do not agree or if no arguments are provided.

plus(
x: array,
y: number,
): array

Addition X + Y.

Adds two numbers, arrays, or matrices element-wise. Handles mixed inputs of scalars, arrays, and matrices.

Examples

Add two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus(5, 6), 11);

Add two arrays element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([5, 6, 4], [3, -1, 0]), [8, 5, 4]);

Add a number to each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([5, 6, 4], 10), [15, 16, 14]);

Add a number to each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus(10, [[5, 6], [3, 4]]), [[15, 16], [13, 14]]);

Add two matrices element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([[5, 6], [3, 4]], [[2, 3], [1, 2]]), [[7, 9], [4, 6]]);

Parameters

The first operand, can be a number, array, or matrix.

y: number

The second operand, can be a number, array, or matrix.

Return Type

The result of adding x and y.

Throws

If the input dimensions do not agree or if no arguments are provided.

plus(
x: array,
y: array,
): array

Addition X + Y.

Adds two numbers, arrays, or matrices element-wise. Handles mixed inputs of scalars, arrays, and matrices.

Examples

Add two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus(5, 6), 11);

Add two arrays element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([5, 6, 4], [3, -1, 0]), [8, 5, 4]);

Add a number to each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([5, 6, 4], 10), [15, 16, 14]);

Add a number to each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus(10, [[5, 6], [3, 4]]), [[15, 16], [13, 14]]);

Add two matrices element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([[5, 6], [3, 4]], [[2, 3], [1, 2]]), [[7, 9], [4, 6]]);

Parameters

The first operand, can be a number, array, or matrix.

The second operand, can be a number, array, or matrix.

Return Type

The result of adding x and y.

Throws

If the input dimensions do not agree or if no arguments are provided.

plus(
x: number,
y: matrix,
): matrix

Addition X + Y.

Adds two numbers, arrays, or matrices element-wise. Handles mixed inputs of scalars, arrays, and matrices.

Examples

Add two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus(5, 6), 11);

Add two arrays element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([5, 6, 4], [3, -1, 0]), [8, 5, 4]);

Add a number to each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([5, 6, 4], 10), [15, 16, 14]);

Add a number to each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus(10, [[5, 6], [3, 4]]), [[15, 16], [13, 14]]);

Add two matrices element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([[5, 6], [3, 4]], [[2, 3], [1, 2]]), [[7, 9], [4, 6]]);

Parameters

x: number

The first operand, can be a number, array, or matrix.

The second operand, can be a number, array, or matrix.

Return Type

The result of adding x and y.

Throws

If the input dimensions do not agree or if no arguments are provided.

plus(
x: matrix,
y: number,
): matrix

Addition X + Y.

Adds two numbers, arrays, or matrices element-wise. Handles mixed inputs of scalars, arrays, and matrices.

Examples

Add two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus(5, 6), 11);

Add two arrays element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([5, 6, 4], [3, -1, 0]), [8, 5, 4]);

Add a number to each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([5, 6, 4], 10), [15, 16, 14]);

Add a number to each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus(10, [[5, 6], [3, 4]]), [[15, 16], [13, 14]]);

Add two matrices element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([[5, 6], [3, 4]], [[2, 3], [1, 2]]), [[7, 9], [4, 6]]);

Parameters

The first operand, can be a number, array, or matrix.

y: number

The second operand, can be a number, array, or matrix.

Return Type

The result of adding x and y.

Throws

If the input dimensions do not agree or if no arguments are provided.

plus(
x: matrix,
y: matrix,
): matrix

Addition X + Y.

Adds two numbers, arrays, or matrices element-wise. Handles mixed inputs of scalars, arrays, and matrices.

Examples

Add two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus(5, 6), 11);

Add two arrays element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([5, 6, 4], [3, -1, 0]), [8, 5, 4]);

Add a number to each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([5, 6, 4], 10), [15, 16, 14]);

Add a number to each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus(10, [[5, 6], [3, 4]]), [[15, 16], [13, 14]]);

Add two matrices element-wise

import { assertEquals } from "jsr:@std/assert";

assertEquals(plus([[5, 6], [3, 4]], [[2, 3], [1, 2]]), [[7, 9], [4, 6]]);

Parameters

The first operand, can be a number, array, or matrix.

The second operand, can be a number, array, or matrix.

Return Type

The result of adding x and y.

Throws

If the input dimensions do not agree or if no arguments are provided.