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
Functions and values
| Function or value |
Description
|
Full Usage:
curry f x y
Parameters:
'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.
Example
val addTuple: x: int * y: int -> int
val x: int
val y: int
val add: (int -> int -> obj)
|
Full Usage:
uncurry f (x, y)
Parameters:
'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.
Example
val add: x: int -> y: int -> int
val x: int
val y: int
val addTuple: (int * int -> obj)
|
Type extensions
| Type extension |
Description
|
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:
|
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:
|
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:
|
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:
|
|
|
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:
|
|
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:
|
Full Usage:
this.TimesI
Parameters:
unit
Returns: Complex
A new complex number equal to i × this = (-Im, +Re).
|
|
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:
|
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:
|
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:
|