# mrmustard.math¶

## The math module¶

A class to manage the different backends supported by Mr Mustard.

### Functions¶

 Categorical(name) Categorical distribution over integers. Default optimizer for the Euclidean parameters. J(num_modes) Symplectic form. MultivariateNormalTriL(scale_tril) Multivariate normal distribution on R^k and parameterized by a (batch of) length-k loc vector (aka "mu") and a (batch of) k x k scale matrix; covariance = scale @ scale.T where @ denotes matrix-multiplication. Xmat(num_modes) The matrix $$X_n = \begin{bmatrix}0 & I_n\\ I_n & 0\end{bmatrix}.$$ Zmat(num_modes) The matrix $$Z_n = \begin{bmatrix}I_n & 0\\ 0 & -I_n\end{bmatrix}.$$ The absolute value of array. add_at_modes(new, modes) Adds two phase-space tensors (cov matrices, displacement vectors, etc..) on the specified modes. all_diagonals(real) Returns all the diagonals of a density matrix. allclose(array2[, atol]) Whether two arrays are equal within tolerance. Returns True if any element of array is True, False otherwise. arange([limit, delta, dtype]) Returns an array of evenly spaced values within a given interval. Converts an array to a numpy array. assign(value) Assigns value to tensor. astensor([dtype]) Converts a numpy array to a tensor. atleast_1d([dtype]) Returns an array with at least one dimension. atleast_2d([dtype]) Returns an array with at least two dimensions. atleast_3d([dtype]) Returns an array with at least three dimensions by eventually inserting new axes at the beginning. binomial_conditional_prob(dim_out, dim_in) $$P(out|in) = binom(in, out) * (1-success_prob)**(in-out) * success_prob**out$$. block([axes]) Returns a matrix made from the given blocks. block_diag(mat2) Returns a block diagonal matrix from the given matrices. boolean_mask(mask) Returns a tensor based on the truth value of the boolean mask. cast([dtype]) Casts array to dtype. Changes the backend to a different one. Computes the Cholesky decomposition of square matrices. clip(a_min, a_max) Clips array to the interval [a_min, a_max]. concat(axis) Concatenates values along the given axis. The complex conjugate of array. Returns a constraint function for the given bounds. convolution(filters[, padding, data_format]) Performs a convolution on array with filters. convolve_probs(other) Convolve two probability distributions (up to 3D) with the same shape. convolve_probs_1d(other_probs) Convolution of a joint probability with a list of single-index probabilities. The cosine of an array. The hyperbolic cosine of array. A decorator to define a function with a custom gradient. The adjoint of array. The determinant of matrix. diag([k]) The array made by inserting the given array along the $$k$$-th diagonal. diag_part([k]) The array of the main diagonal of array. The eigenvalues and eigenvectors of a matrix. The eigenvalues of a tensor. einsum(*tensors) The result of the Einstein summation convention on the tensors. euclidean_to_symplectic(dS_euclidean) Convert the Euclidean gradient to a Riemannian gradient on the tangent bundle of the symplectic manifold. euclidean_to_unitary(dU_euclidean) Convert the Euclidean gradient to a Riemannian gradient on the tangent bundle of the unitary manifold. The exponential of array element-wise. expand_dims(axis) The array with an additional dimension inserted at the given axis. The matrix exponential of matrix. eye([dtype]) The identity matrix of size. The identity matrix of the same shape and dtype as array. Whether the given tensor is a tensor of the concrete backend. gather(indices[, axis]) The values of the array at the given indices. hermite_renormalized(B, C, shape) Renormalized multidimensional Hermite polynomial given by the "exponential" Taylor series of $$exp(C + Bx + 1/2*Ax^2)$$ at zero, where the series has $$sqrt(n!)$$ at the denominator rather than $$n!$$. hermite_renormalized_1leftoverMode(B, C, cutoffs) First, reorder A and B parameters of Bargmann representation to match conventions in mrmustard.math.compactFock~ Then, calculate the required renormalized multidimensional Hermite polynomial. Renormalized multidimensional Hermite polynomial given by the "exponential" Taylor series of $$exp(C + Bx - Ax^2)$$ at zero, where the series has $$sqrt(n!)$$ at the denominator rather than $$n!$$. hermite_renormalized_batch(B, C, shape) Renormalized multidimensional Hermite polynomial given by the "exponential" Taylor series of $$exp(C + Bx + 1/2*Ax^2)$$ at zero, where the series has $$sqrt(n!)$$ at the denominator rather than $$n!$$. hermite_renormalized_binomial(B, C, shape, ...) Renormalized multidimensional Hermite polynomial given by the "exponential" Taylor series of $$exp(C + Bx + 1/2*Ax^2)$$ at zero, where the series has $$sqrt(n!)$$ at the denominator rather than $$n!$$. hermite_renormalized_diagonal(B, C, cutoffs) Firsts, reorder A and B parameters of Bargmann representation to match conventions in mrmustard.math.compactFock~ Then, calculates the required renormalized multidimensional Hermite polynomial. First, reorder A and B parameters of Bargmann representation to match conventions in mrmustard.math.compactFock~ Then, calculates the required renormalized multidimensional Hermite polynomial. Renormalized multidimensional Hermite polynomial given by the "exponential" Taylor series of $$exp(C + Bx - Ax^2)$$ at zero, where the series has $$sqrt(n!)$$ at the denominator rather than $$n!$$. The imaginary part of array. The inverse of tensor. Whether the given tensor is trainable. kron(tensor2) The Kroenecker product of the given tensors. left_matmul_at_modes(b_full, modes) Left matrix multiplication of a partial matrix and a full matrix. The natural logarithm of the gamma function of x. The natural logarithm of x. make_complex(imag) Given two real tensors representing the real and imaginary part of a complex number, this operation returns a complex tensor. map_fn(elements) Transforms elems by applying fn to each element unstacked on axis 0. The matrix product of the given matrices. The matrix vector product of a (matrix) and b (vector). matvec_at_modes(vec, modes) Matrix-vector multiplication between a phase-space matrix and a vector in the specified modes. The element-wise maximum of a and b. The element-wise minimum of a and b. new_constant(name[, dtype]) Returns a new constant with the given value. new_variable(bounds, name[, dtype]) Returns a new variable with the given value and bounds. The norm of array. ones([dtype]) Returns an array of ones with the given shape and dtype. Returns an array of ones with the same shape and dtype as array. outer(array2) The outer product of array1 and array2. pad(paddings[, mode, constant_values]) The padded array. The pseudo-inverse of matrix. poisson(rate) Poisson distribution up to max_k. Returns $$x^y$$. prod([axis]) The product of all elements in array. A random orthogonal matrix in $$O(N)$$. random_symplectic([max_r]) A random symplectic matrix in Sp(2*num_modes). a random unitary matrix in $$U(N)$$ The real part of array. reshape(shape) The reshaped array. right_matmul_at_modes(b_partial, modes) Right matrix multiplication of a full matrix and a partial matrix. rotmat(num_modes) Rotation matrix from quadratures to complex amplitudes. round(decimals) The array rounded to the nearest integer. set_diag(diag, k) The array with the diagonal set to diag. The sine of array. single_mode_to_multimode_mat(num_modes) Apply the same $$2\times 2$$ matrix (i.e. single-mode) to a larger number of modes. single_mode_to_multimode_vec(num_modes) Apply the same 2-vector (i.e. single-mode) to a larger number of modes. The hyperbolic sine of array. solve(rhs) The solution of the linear system $$Ax = b$$. sqrt([dtype]) The square root of x. sqrtm([dtype]) The matrix square root. squeeze(axis) Removes dimensions of size 1 from the shape of a tensor. sum([axes]) The sum of array. tensordot(b, axes) The tensordot product of a and b. tile(repeats) The tiled array. trace([dtype]) The trace of array. transpose([perm]) The transposed arrays. Unitary to orthogonal mapping. update_add_tensor(indices, values) Updates a tensor in place by adding the given values. update_tensor(indices, values) Updates a tensor in place with the given values. value_and_gradients(parameters) The loss and gradients of the given cost function. Returns 0 if x == 0 elementwise and x * log(y) otherwise. zeros([dtype]) Returns an array of zeros with the given shape and dtype. Returns an array of zeros with the same shape and dtype as array.