Skip to main content

affine_operator

Function affine_operator 

Source
pub fn affine_operator(
    r: usize,
    params: &AffineParams,
    bc: &[BoundaryCondition],
) -> Result<LinearOperator<TensorDynLen, usize>>
Expand description

Create the operator that realizes the coordinate map y = A * x + b.

This is the forward affine operator. It maps a quantics tensor train representing an N-variable state x to the quantics tensor train of the M-variable state y = A * x + b.

To build the pullback (f(y) = g(A * y + b)), call .transpose() on the returned operator; the pullback is exactly the transpose of the forward operator.

§Arguments

  • r — bits per variable (number of sites in the output MPO).
  • params — rational M × N matrix A and M-vector b describing the affine map.
  • bc — length M array of boundary conditions for each output variable. Periodic wraps output coordinates modulo 2^r; Open zeroes the out-of-range contributions.

§Errors

Returns an error if r == 0 or if bc.len() != params.m.

§Examples

use tensor4all_quanticstransform::{affine_operator, AffineParams, BoundaryCondition};
use num_rational::Rational64;

// Transform g(x, y) -> g(x + y, x - y) (rotation by 45 degrees, scaled)
let a = vec![
    Rational64::from_integer(1), Rational64::from_integer(1),  // row 0: x + y
    Rational64::from_integer(1), Rational64::from_integer(-1), // row 1: x - y
];
let b = vec![Rational64::from_integer(0), Rational64::from_integer(0)];
let params = AffineParams::new(a, b, 2, 2).unwrap();
let bc = vec![BoundaryCondition::Periodic; 2];
let op = affine_operator(4, &params, &bc).unwrap();
assert_eq!(op.mpo.node_count(), 4);

Using integer convenience constructor:

use tensor4all_quanticstransform::{affine_operator, AffineParams, BoundaryCondition};

// Identity transform: y = x (1D)
let params = AffineParams::from_integers(vec![1], vec![0], 1, 1).unwrap();
let bc = vec![BoundaryCondition::Periodic];
let op = affine_operator(4, &params, &bc).unwrap();
assert_eq!(op.mpo.node_count(), 4);