Options
All
  • Public
  • Public/Protected
  • All
Menu

Vector class. A complex number sparse vector aware of dimensions and tensor structure.

see

Complex and Dimension

Hierarchy

  • Vector

Index

Constructors

Properties

dimensions: Dimension[]
entries: VectorEntry[]

Accessors

  • get coordNames(): string[][]
  • get names(): string[]
  • get norm(): number
  • Vector norm (vector length). In quantum physics, it is probability of a quantum state.

    note

    Would be equivalent to inner product with itself, but we use a more straightforward implementation (plus, to make sure we get a real number).

    Returns number

    sqrt⟨v|v⟩

  • get size(): number[]
  • get totalSize(): number
  • Returns number

    The total size (the total array length). FIXME: size and totalSize is confusing, rename to length or size, sizes?

Methods

  • Complex conjugation. Note that that for quantum states it is essentially ket <-> bra, i.e. |psi⟩^† = ⟨psi|

    Returns Vector

    Complex conjugation for a vector.

  • Create a copy of the vector.

    todo

    Make it more lightweight than using lodash.

    Returns Vector

  • Dot product for all dimensions of v1 and some for v2.

    Parameters

    • coordIndices: number[]

      Indices of dimensions for v2.

    • v: Vector

      The other vector

    Returns Vector

    sum_i v1_i v2_ij

  • isCloseToZero(eps?: number): boolean
  • Is it close to zero?

    Parameters

    • eps: number = 1e-6

      Euclidean distance tolerance.

    Returns boolean

    Checks v ~= 0

  • Multiplies vector by a real number.

    Parameters

    • x: number

      A factor.

    Returns Vector

    x v

  • normSquared(): number
  • Vector norm (vector length) squared. In quantum physics, it is probability of a quantum state.

    note

    Would be equivalent to inner product with itself, but we use a more straightforward implementation (plus, to make sure we get a real number).

    Returns number

    ⟨v|v⟩ FIXME: Feels it should be a getter

  • Creates a normalized vector (i.e. with norm 1).

    Returns Vector

    A normalized vector: |v⟩ / √⟨v|v⟩

  • permute(order: number[]): Vector
  • Changing order of dimensions for a vector, from [0, 1, 2, ...] to something else.

    Parameters

    • order: number[]

      E.g. [2, 0, 1]

    Returns Vector

  • randomOnPartialSubspace(coordIndices: number[]): Vector
  • A normalized vector, from uniform distribution of U(n), restricted only to indices of vector, on a tensor component. Think of it as Vector.random optimized for partial inner products with the vector, on a selected subspace.

    Parameters

    • coordIndices: number[]

      coordinates we want to keep

    Returns Vector

  • A normalized vector, from uniform distribution of U(n), restricted only to indices of vector. Think of it as Vector.random optimized for inner products with the vector.

    Returns Vector

  • toBasisAll(dimName: string, basisStr: string): Vector
  • toGroupedByCoords(coordIndices: readonly number[]): IColumnOrRow[]
  • Groups some of vector coordinates. Mostly for intrnal use, e.g. partial inner product, Schmidt decomposition, etc.

    Parameters

    • coordIndices: readonly number[]

      Sorted indices of dimensions for vectors. Complementary ones are used for grouping.

    Returns IColumnOrRow[]

  • Export entires into a flatten, sparse list.

    Returns IEntryIndexValue[]

    E.g. [{i: 2, v: Cx(2, 4)}, {i: 5, v: Cx(-1, 0)}, ...]

  • Exports a form suitable for visualization, with fixed basis.

    Parameters

    • probThreshold: number = 1e-4

      Minimal probability to emit an entry.

    Returns IKetComponent[]

    An array of elements like {amplitude: Cx(0.1, -0.5), coordStrings: ['3', 'H', 'V' '>', 'u']}

  • toKetString(complexFormat?: ComplexFormat, precision?: number): string
  • Generates a string for kets. See Vector.toString for formatting options.

    Parameters

    • complexFormat: ComplexFormat = 'polarTau'

      .

    • precision: number = 2

      Float precision.

    Returns string

    A ket string, e.g. 0.71 exp(0.00τi) |3,1,>,V⟩ + 0.71 exp(1.00τi) |2,2,v,V⟩.

  • toString(complexFormat?: ComplexFormat, precision?: number, separator?: string, intro?: boolean): string
  • String description of a vector.

    see

    Complex.toString for formating options.

    Parameters

    • complexFormat: ComplexFormat = 'cartesian'

      Complex number format - a choice between ["cartesian", "polar", "polarTau"].

    • precision: number = 2

      Float display precision.

    • separator: string = ' + '

      Entry separator.

    • intro: boolean = true

      If to show dimensions and sized.

    Returns string

    A string, e.g.:

    Vector with 3 entries of max size [2,2] with dimensions [spin,polarization] (0.00 +2.00i) |u,H⟩ + (-1.00 -1.00i) |d,H⟩ + (0.50 +2.50i) |d,V⟩

  • As sum of many vectors with compatible dimensions.

    see

    Vector.add for the actual implementation.

    todo

    Can be optimized if needed.

    Parameters

    Returns Vector

    v1 + v2 + ...

  • Creates a a vector from a dense array of complex numbers. It needs dimensions to create the complex structure.

    example

    const vec = Vector.fromArray([Cx(1), Cx(0), Cx(2, 1), Cx(0, -1)], [Dimension.spin(), Dimension.spin()])

    Parameters

    • denseArray: Complex[]

      A 1-d array of complex numbers.

    • dimensions: Dimension[]

      Dimensions.

    • removeZeros: boolean = true

      If to remove zero value.

    Returns Vector

  • example

    const singletState = Vector.fromSparseCoordNames([ ['ud', Cx(1)], ['du', Cx(-1)], ], [Dimension.spin(), Dimension.spin()])

    Parameters

    • stringedEntries: [string, Complex][]

      A list of entries, using symbols. ['Hu', C(0.5, -1)] -> (0.50 - 1.00i) |H,u⟩

    • dimensions: Dimension[]

    Returns Vector

    A vector, as desired.

  • Creates a vector with a single 1 value and all zeros, e.g. |H,u⟩.

    example

    Vector.indicator([Dimensions.polarization(), Dimensions.spin()], 'Hu')

    note

    Consider changing arg order, to conform with other parts of this library.

    Parameters

    • dimensions: Dimension[]
    • coordNames: string | string[]

      Symbols for each ordinate. For symbols with more than one letter you need to use an array of strings.

    Returns Vector

  • Outer product (vectors product) between two or more vectors.

    see

    Vector.outer for the actual implementation.

    todo

    Can be optimized if needed.

    Parameters

    Returns Vector

    ⨂[v1, v2, ...]

  • A normalized vector, from uniform distribution of U(n). Completely dense!

    Parameters

    Returns Vector

Generated using TypeDoc