Header menu logo Encodings

TypeExtensions Module

General-purpose utility functions and type extensions used throughout the encoding library.

This module provides:

  • Currying and uncurrying combinators for function transformation
  • Extensions to for quantum coefficient manipulation
  • Extensions to for convenient key/value access
These utilities simplify the implementation of encoding logic and coefficient arithmetic.

Functions and values

Function or value Description

curry f x y

Full Usage: curry f x y

Parameters:
    f : 'x * 'y -> 'r - A function of type ('x * 'y) -> 'r.
    x : 'x
    y : 'y

Returns: 'r A curried function of type 'x -> 'y -> 'r.

Converts a function that takes a tuple into a curried two-argument function.

f : 'x * 'y -> 'r

A function of type ('x * 'y) -> 'r.

x : 'x
y : 'y
Returns: 'r

A curried function of type 'x -> 'y -> 'r.

Example

 let addTuple (x, y) = x + y
 let add = curry addTuple
 add 2 3 // returns 5
val addTuple: x: int * y: int -> int
val x: int
val y: int
val add: (int -> int -> obj)

uncurry f (x, y)

Full Usage: uncurry f (x, y)

Parameters:
    f : 'x -> 'y -> 'r - A curried function of type 'x -> 'y -> 'r.
    x : 'x
    y : 'y

Returns: 'r A function that takes a tuple ('x * 'y) and returns 'r.

Converts a curried two-argument function into a function that takes a tuple.

f : 'x -> 'y -> 'r

A curried function of type 'x -> 'y -> 'r.

x : 'x
y : 'y
Returns: 'r

A function that takes a tuple ('x * 'y) and returns 'r.

Example

 let add x y = x + y
 let addTuple = uncurry add
 addTuple (2, 3) // returns 5
val add: x: int -> y: int -> int
val x: int
val y: int
val addTuple: (int * int -> obj)

Type extensions

Type extension Description

this.IsFinite

Full Usage: this.IsFinite

Parameters:
    () : unit

Returns: bool true if both components are finite; otherwise false.

Checks whether the complex number has finite (non-NaN, non-infinite) real and imaginary parts.

Extended Type: Complex

() : unit
Returns: bool

true if both components are finite; otherwise false.

this.IsNonZero

Full Usage: this.IsNonZero

Parameters:
    () : unit

Returns: bool true if the number is finite and non-zero; otherwise false.

Checks whether the complex number is finite and not equal to zero.

Extended Type: Complex

() : unit
Returns: bool

true if the number is finite and non-zero; otherwise false.

this.IsZero

Full Usage: this.IsZero

Parameters:
    () : unit

Returns: bool true if the number is zero or non-finite; otherwise false.

Checks whether the complex number is zero or non-finite (NaN/Infinity).

This is the logical negation of Complex.IsNonZero. Non-finite values are treated as zero for numerical safety.

Extended Type: Complex

() : unit
Returns: bool

true if the number is zero or non-finite; otherwise false.

this.Keys

Full Usage: this.Keys

Parameters:
    () : unit

Returns: 'Key array An array containing all keys in the map.

Gets all keys in the map as an array.

Extended Type: Map

() : unit
Returns: 'Key array

An array containing all keys in the map.

Complex.MinusOne()

Full Usage: Complex.MinusOne()

Parameters:
    () : unit

Returns: Complex

Returns the complex number -1 + 0i.

Extended Type: Complex

() : unit
Returns: Complex

this.Reduce

Full Usage: this.Reduce

Parameters:
    () : unit

Returns: Complex The original value if finite; otherwise zero.

Returns the complex number if finite, or Complex.Zero if non-finite.

Used to sanitize coefficients after arithmetic operations that might produce NaN or Infinity, ensuring numerical stability in subsequent computations.

Extended Type: Complex

() : unit
Returns: Complex

The original value if finite; otherwise zero.

Complex.SwapSignMultiple(n) (c)

Full Usage: Complex.SwapSignMultiple(n) (c)

Parameters:
    n : int - The number of sign swaps to apply.
    c : Complex - The complex number to transform.

Returns: Complex The complex number with sign swapped n times: (-1)^n × c.

Negates a complex number n times, effectively multiplying by (-1)^n.

Used in fermionic encodings where anti-commutation relations introduce sign factors based on the number of operator swaps.

Extended Type: Complex

n : int

The number of sign swaps to apply.

c : Complex

The complex number to transform.

Returns: Complex

The complex number with sign swapped n times: (-1)^n × c.

this.TimesI

Full Usage: this.TimesI

Parameters:
    () : unit

Returns: Complex A new complex number equal to i × this = (-Im, +Re).

Multiplies the complex number by the imaginary unit i.

Useful for phase transformations in quantum mechanics where multiplication by i corresponds to a π/2 phase shift.

Extended Type: Complex

() : unit
Returns: Complex

A new complex number equal to i × this = (-Im, +Re).

this.ToPhaseConjunction

Full Usage: this.ToPhaseConjunction

Parameters:
    () : unit

Returns: string A string like " + ", " - ", " + i ", " - i ", or " + value " / " - value " suitable for joining terms in a sum expression.

Formats the complex number as a conjunction operator (+ or -) with coefficient for display.

Extended Type: Complex

() : unit
Returns: string

A string like " + ", " - ", " + i ", " - i ", or " + value " / " - value " suitable for joining terms in a sum expression.

this.ToPhasePrefix

Full Usage: this.ToPhasePrefix

Parameters:
    () : unit

Returns: string A string representation suitable for prefixing an operator term: "" for +1, " -" for -1, "( i) " for +i, "(-i) " for -i, or the numeric value.

Formats the complex number as a coefficient prefix for display.

Extended Type: Complex

() : unit
Returns: string

A string representation suitable for prefixing an operator term: "" for +1, " -" for -1, "( i) " for +i, "(-i) " for -i, or the numeric value.

this.Values

Full Usage: this.Values

Parameters:
    () : unit

Returns: 'Value array An array containing all values in the map.

Gets all values in the map as an array.

Extended Type: Map

() : unit
Returns: 'Value array

An array containing all values in the map.

Type something to start searching.