Optex.Aff (Optex v0.1.0)

Copy Markdown View Source

Affine-plus-quadratic expression a^T x + x^T C x + b, sparse over variable ids. terms holds the linear part; qterms holds quadratic coefficients keyed by normalized {lo_id, hi_id} pairs (so x*y and y*x sum into one cell, and x*x lives at {i, i}). Coefficients are literal: the qterm coefficient of {i, j} is exactly the coefficient of x_i * x_j as written. Products of degree greater than two raise Optex.NonlinearError.

Summary

Functions

Add two expressions; coefficients of shared cells sum.

The affine expression 1.0 * var.

Multiply two normalized leaves. Numbers and constant-only expressions scale; the product of two linear expressions yields quadratic terms; any product whose degree would exceed two raises Optex.NonlinearError.

Whether the expression carries any quadratic terms.

Multiply every coefficient and the constant by a number.

Normalize a leaf (variable, number, or Aff) to an Aff.

Types

t()

@type t() :: %Optex.Aff{
  constant: float(),
  qterms: %{required({non_neg_integer(), non_neg_integer()}) => float()},
  terms: %{required(non_neg_integer()) => float()}
}

Functions

add(a, b)

Add two expressions; coefficients of shared cells sum.

from_var(var)

The affine expression 1.0 * var.

mul(aff, k)

Multiply two normalized leaves. Numbers and constant-only expressions scale; the product of two linear expressions yields quadratic terms; any product whose degree would exceed two raises Optex.NonlinearError.

quadratic?(aff)

Whether the expression carries any quadratic terms.

scale(a, k)

Multiply every coefficient and the constant by a number.

to_aff(a)

Normalize a leaf (variable, number, or Aff) to an Aff.