<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">"""Module for linear algebra operations.

Vectors are represented by lists.
For example,
  x = [1.0, 3.0]  # this would be a 2D vector

Matrices are represented by lists inside lists.
For example,
  A = [ [2,3],
        [4,5] ]  # this would be a 2x2 matrix

-&gt; Multiplication Matrix Vector
-&gt; Multiplication Dot product (i.e., Vector Vector)
-&gt; Multiplication Matrix Matrix
-&gt; Vector addition (subtraction)
(Vector norm)
(Cross product between vectors)
(Matrix inverse)
"""
from typing import List


def vector_add_2d(x: list, y: list) -&gt; list:
    """Add two 2D vectors.

    :param x: The first vector.
    :param y: The second vector.
    :return: The sum of the two vectors.
    """
    sum = [x[0] + y[0], x[1] + y[1]]
    return sum


def vector_dot_2d(x: list, y: list) -&gt; float:
    """Compute dot product of two 2D vectors.

    :param x: The first vector.
    :param y: The second vector.
    :return: The dot product of the two vectors.
    """
    return x[0] * y[0] + x[1] * y[1]


def matrix_vector_2d(matrix: list, vector: List[float]) -&gt; list:
    """Compute 2D matrix vector product.

    :param matrix: The 2x2 matrix.
    :param vector: The 2D vector.
    :return: Matrix vector product. (2D vector)
    """
    result = [
        matrix[0][0] * vector[0] + matrix[0][1] * vector[1],
        matrix[1][0] * vector[1] + matrix[1][1] * vector[1],
    ]
    return result


if __name__ == "__main__":
    a = [2, 3]
    b = [4, 5]

    print(vector_add_2d(a, b))
    print(vector_dot_2d(a, b))
    print(matrix_vector_2d(a, b))
</pre></body></html>