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

Vectors are represented by lists.

For example,
    x = [3, 6]  # define a 2-d vector

Matrices are represented by lists of lists, where each row corresponds to an inner list.
    A = [[3,6], [1,2]]  # define a 2x2 matrix

    a[1][1]  # -&gt; 2 access the second row, second column element
"""
from typing import List

def add_vectors_2d(vector_1: List[float], vector_2: List[float]) -&gt; List[float]:
    """Compute the sum of two 2D vectors.

    :param vector_1: The first 2D vector.
    :param vector_2: The second 2D vector.
    :return: The sum of the two vectors.
    """
    sum_vector = [
        vector_1[0] + vector_2[0],
        vector_1[1] + vector_2[1],
    ]
    return sum_vector

def scalar_product_2d(vector_1: List[float], vector_2: List[float]) -&gt; float:
    """Compute the scalar product of two 2D vectors.

    :param vector_1: The first 2D vector.
    :param vector_2: The second 2D vector.
    :return: The scalar product of the two vectors.
    """
    return vector_1[0] * vector_2[0] + vector_1[1] * vector_2[1]

def matrix_vector_multiplication_2d(matrix: List[List[float]], vector: List[float]) -&gt; List[float]:
    """Compute the product Ax of a matrix A and a vector x

    :param vector_1: The 2x2 matrix A.
    :param vector_2: The 2D vector x.
    :return: The vector computed by multiplying the matrix A with the vector x.
    """
    # result_vector = [
    #     matrix[0][0] * vector[0] + matrix[0][1] * vector[1],
    #     matrix[1][0] * vector[0] + matrix[1][1] * vector[1],
    # ]
    result_vector = [
        scalar_product_2d(matrix[0], vector),
        scalar_product_2d(matrix[1], vector),
    ]
    return result_vector

x_1 = [1, 2]
x_2 = [3, 5]

mat = [[1, 0], [0, 1]]

print( add_vectors_2d(x_1, x_2) )
print( scalar_product_2d(x_1, x_2) )
print( matrix_vector_multiplication_2d(mat, x_1) )</pre></body></html>