### Install hypercomplex Package Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Use pip to install the hypercomplex library. This command is for installation via the Python Package Index. ```text pip install hypercomplex ``` -------------------------------- ### Get Hypercomplex Dimension using len() Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Illustrates how the `len()` function returns the hypercomplex dimension (number of coefficients) of a number. ```python print(len(R())) # -> 1 print(len(C(7, 7))) # -> 2 print(len(U())) # -> 128 ``` -------------------------------- ### Copy Hypercomplex Number and Get Base Type Source: https://context7.com/discretegames/hypercomplex/llms.txt Create a duplicate of a hypercomplex number using `copy()`. The `base()` class method returns the underlying numeric type used for coefficients. ```python from hypercomplex import R, V, O, cayley_dickson_algebra # Copy a number x = O(9, 8, 7) y = x.copy() print(x == y) # -> True print(x is y) # -> False ``` ```python # Get base type print(R.base()) # -> print(V.base()) # -> ``` ```python # Custom base type A = cayley_dickson_algebra(20, int) print(A.base()) # -> ``` -------------------------------- ### Get Norm and Squared Norm of Hypercomplex Number Source: https://context7.com/discretegames/hypercomplex/llms.txt Calculate the norm and squared norm of a hypercomplex number. The norm is the square root of the sum of the squares of its coefficients. ```python print(Q(1, 2, 3, 4).norm()) # -> 5.477225575051661 print(Q(1, 2, 3, 4).norm_squared()) # -> 30.0 ``` -------------------------------- ### Get Dimension of Hypercomplex Number Source: https://context7.com/discretegames/hypercomplex/llms.txt Determine the dimension (number of coefficients) of a hypercomplex number using `len()` or the `dimensions` class attribute. ```python from hypercomplex import R, C, Q, O, U, V print(len(R())) # -> 1 print(len(C(7, 7))) # -> 2 print(len(Q())) # -> 4 print(len(O())) # -> 8 print(len(U())) # -> 128 print(len(V())) # -> 256 ``` ```python # Class attribute print(Q.dimensions) # -> 4 ``` -------------------------------- ### Initialize Hypercomplex Numbers Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Demonstrates various ways to instantiate hypercomplex numbers, including using Python's built-in complex numbers. ```python print(R(-1.5)) # -> (-1.5) print(C(2, 3)) # -> (2 3) print(C(2 + 3j)) # -> (2 3) print(Q(4, 5, 6, 7)) # -> (4 5 6 7) print(Q(4 + 5j, C(6, 7), pair=True)) # -> (4 5 6 7) print(P()) # -> (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) ``` -------------------------------- ### Core Functions Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Explains the three core functions: reals, cayley_dickson_construction, and cayley_dickson_algebra. ```APIDOC ## Core Functions ### `reals(base)` **Description**: Generates a class representing numbers with 1 hypercomplex dimension (real numbers) based on a given `base` type (defaults to `float`). **Parameters**: - **base** (type): The base numeric type to use (e.g., `float`, `decimal.Decimal`). Optional, defaults to `float`. **Usage**: Instances of the returned class behave like the `base` type for usual math operations, but retain their hypercomplex type. They are printed with the `g` format-spec and surrounded by parentheses. ### `cayley_dickson_construction(basis)` **Description**: Generates a new class of hypercomplex numbers with twice the dimension of the provided `basis` using the Cayley-Dickson construction. **Parameters**: - **basis** (class): Another hypercomplex number class or a class returned from `reals`. **Usage**: Allows for recursive construction of hypercomplex number types (e.g., complex from real, quaternion from complex). Supports normal math operations with instances of other numeric types. ### `cayley_dickson_algebra(level, base)` **Description**: A helper function that repeatedly applies `cayley_dickson_construction` to a `base` type for a specified `level` of recursion. **Parameters**: - **level** (int): The number of times to apply the construction. The resulting dimension will be 2**level. - **base** (type): The base numeric type (defaults to `float`). Optional. **Usage**: Returns the class for a Cayley-Dickson algebra with `2**level` dimensions. ``` -------------------------------- ### Raise to Integer Powers Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Integer exponentiation acts as a shortcut for repeated multiplication or division. ```python q = Q(0, 3, 4, 0) print(q**5) # -> (0 1875 2500 0) print(q * q * q * q * q) # -> (0 1875 2500 0) print(q**-1) # -> (0 -0.12 -0.16 0) print(1 / q) # -> (0 -0.12 -0.16 0) print(q**0) # -> (1 0 0 0) ``` -------------------------------- ### Demonstrate Zero Divisors in Sedenions Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Illustrates a key property of higher-dimensional hypercomplex numbers (sedenions and beyond): the existence of zero divisors. Multiplying two non-zero numbers can result in zero, which can lead to division by zero errors. ```python s1 = S.e(5) + S.e(10) s2 = S.e(6) + S.e(9) print(s1) # -> (0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0) print(s2) # -> (0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0) print(s1 * s2) # -> (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) print((1 / s1) * (1 / s2)) # -> (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) # print(1/(s1 * s2)) <- zero division error ``` -------------------------------- ### Zero Divisors in Higher Algebras Source: https://context7.com/discretegames/hypercomplex/llms.txt Illustrates the existence of zero divisors in algebras like Sedenions (16D) and higher, where non-zero numbers can multiply to produce zero. ```python from hypercomplex import S # Sedenions (16D) and higher algebras contain zero divisors. ``` -------------------------------- ### Initialize Hypercomplex Numbers with pair=True Source: https://context7.com/discretegames/hypercomplex/llms.txt Construct hypercomplex numbers using pairs of lower-dimensional numbers by setting `pair=True`. This follows the recursive Cayley-Dickson structure. ```python from hypercomplex import C, Q, O # Standard initialization print(Q(4, 5, 6, 7)) # -> (4 5 6 7) # Pair initialization: construct from two lower-dimension numbers print(Q(4 + 5j, C(6, 7), pair=True)) # -> (4 5 6 7) print(Q(C(4, 5), C(6, 7), pair=True)) # -> (4 5 6 7) # Construct octonion from two quaternions q1 = Q(1, 2, 3, 4) q2 = Q(5, 6, 7, 8) o = O(q1, q2, pair=True) print(o) # -> (1 2 3 4 5 6 7 8) ``` -------------------------------- ### Compare Equality Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Equality is determined by matching coefficients, with non-existent coefficients treated as 0. ```python print(R(999) == V(999)) # -> True print(C(1, 2) == Q(1, 2)) # -> True print(C(1, 2) == Q(1, 2, 0.1)) # -> False ``` -------------------------------- ### Duplicate Hypercomplex Numbers with copy() Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Demonstrates the use of the `copy()` method to create a duplicate of a hypercomplex number. Note that operations on hypercomplex numbers typically return new instances, making explicit copying often unnecessary. ```python x = O(9, 8, 7) y = x.copy() print(x == y) # -> True print(x is y) # -> False ``` -------------------------------- ### Retrieve Base Type of Hypercomplex Algebra Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Shows how to use the `base()` class method to determine the underlying numeric type (e.g., float, int) upon which a hypercomplex algebra is built. ```python print(R.base()) # -> print(V.base()) # -> A = cayley_dickson_algebra(20, int) print(A.base()) # -> ``` -------------------------------- ### Basic Hypercomplex Number Usage in Python Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Demonstrates creating and manipulating Complex, Quaternion, and Octonion objects. Includes scalar multiplication and addition. Note that Octonion addition with a Quaternion results in an Octonion. ```python from hypercomplex import Complex, Quaternion, Octonion, Voudon, cayley_dickson_construction c = Complex(0, 7) print(c) # -> (0 7) print(c == 7j) # -> True q = Quaternion(1.1, 2.2, 3.3, 4.4) print(2 * q) # -> (2.2 4.4 6.6 8.8) print(Quaternion.e_matrix()) # -> e0 e1 e2 e3 # e1 -e0 e3 -e2 # e2 -e3 -e0 e1 # e3 e2 -e1 -e0 o = Octonion(0, 0, 0, 0, 8, 8, 9, 9) print(o + q) # -> (1.1 2.2 3.3 4.4 8 8 9 9) v = Voudon() print(v == 0) # -> True print(len(v)) # -> 256 BeyondVoudon = cayley_dickson_construction(Voudon) print(len(BeyondVoudon())) # -> 512 ``` -------------------------------- ### Generate Unit Hypercomplex Numbers (Basis Elements) Source: https://context7.com/discretegames/hypercomplex/llms.txt Create unit hypercomplex numbers where only one coefficient is 1 and others are 0. These form the basis of the algebra. Use `e(index)` class method. ```python from hypercomplex import C, Q, O, S # Unit elements print(C.e(0)) # -> (1 0) print(C.e(1)) # -> (0 1) print(Q.e(2)) # -> (0 0 1 0) print(O.e(3)) # -> (0 0 0 1 0 0 0 0) ``` ```python # Build numbers from unit elements s1 = S.e(5) + S.e(10) print(s1) # -> (0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0) ``` -------------------------------- ### copy() and base() Source: https://context7.com/discretegames/hypercomplex/llms.txt The `copy()` method creates a duplicate of a hypercomplex number. The `base()` class method returns the underlying numeric type used for coefficients. ```APIDOC ## copy() and base() ### Description The `copy()` method creates a duplicate of a hypercomplex number. The `base()` class method returns the underlying numeric type (float by default). ### Method Instance method `copy()`, Class method `base()` ### Parameters None ### Request Example ```python from hypercomplex import R, V, O, cayley_dickson_algebra # Copy a number x = O(9, 8, 7) y = x.copy() print(x == y) # -> True print(x is y) # -> False # Get base type print(R.base()) # -> print(V.base()) # -> # Custom base type A = cayley_dickson_algebra(20, int) print(A.base()) # -> ``` ### Response Example ```json { "copy_result": "a new hypercomplex number instance identical to the original", "base_type": "the underlying numeric type used for coefficients" } ``` ``` -------------------------------- ### Calculate zero-product sedenions Source: https://context7.com/discretegames/hypercomplex/llms.txt Defines two non-zero sedenions that result in a zero product. Note that attempting to divide by the product of these zero divisors will raise a ZeroDivisionError. ```python s1 = S.e(5) + S.e(10) s2 = S.e(6) + S.e(9) print(s1) # -> (0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0) print(s2) # -> (0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0) print(s1 * s2) # -> (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) <- zero! # Their inverses also multiply to zero print((1 / s1) * (1 / s2)) # -> (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) # Warning: Cannot divide by zero divisor products # 1/(s1 * s2) <- ZeroDivisionError ``` -------------------------------- ### Using Pre-defined Hypercomplex Number Types Source: https://github.com/discretegames/hypercomplex/blob/main/README.md The package provides convenient pre-defined types like `Real`, `Complex`, `Quaternion`, and `Octonion`, accessible directly or via aliases like `R`, `C`, `Q`, `O`, `CDn`, and `CD[n]`. ```python from hypercomplex import * print(Real(4)) # -> (4) print(C(3-7j)) # -> (3 -7) print(CD4(.1, -2.2, 3.3e3)) # -> (0.1 -2.2 3300 0) print(CD[3](1, 0, 2, 0, 3)) # -> (1 0 2 0 3 0 0 0) ``` -------------------------------- ### Access Coefficients Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Retrieves components as a tuple or via properties like real and imag. ```python print(R(100).coefficients()) # -> (100.0,) q = Q(2, 3, 4, 5) print(q.coefficients()) # -> (2.0, 3.0, 4.0, 5.0) print(q.real, q.imag) # -> 2.0 3.0 print(q[0], q[1], q[2], q[3]) # -> 2.0 3.0 4.0 5.0 ``` -------------------------------- ### Zero Divisors in Higher Algebras Source: https://context7.com/discretegames/hypercomplex/llms.txt Explains the concept of zero divisors in algebras like Sedenions (16D) and higher, where non-zero numbers can multiply to produce zero. ```APIDOC ## Zero Divisors in Higher Algebras ### Description Sedenions (16D) and higher algebras contain zero divisors - non-zero numbers that multiply to give zero. This is a fundamental mathematical property of these algebras. ### Method Conceptual explanation, no specific method call. ### Parameters None ### Request Example ```python from hypercomplex import S # Example demonstrating zero divisors would require specific non-zero numbers # that multiply to zero in Sedenions or higher algebras. # This is a mathematical property rather than a direct code operation. ``` ### Response Example ```json { "explanation": "Description of zero divisors in hypercomplex algebras" } ``` ``` -------------------------------- ### e_matrix() Class Method Source: https://context7.com/discretegames/hypercomplex/llms.txt Generates the multiplication table for unit elements (e(i) * e(j)), useful for understanding algebraic structure. ```APIDOC ## e_matrix() Class Method ### Description Generates the multiplication table for unit elements (e(i) * e(j)). This is useful for understanding the algebraic structure and verifying properties like non-commutativity. ### Method Class method ### Parameters - **string** (bool) - Optional - If True, returns a string representation. Defaults to True. - **raw** (bool) - Optional - If True, returns raw hypercomplex numbers instead of string representations. Defaults to False. ### Request Example ```python from hypercomplex import C, Q, O # String representation (default) print(Q.e_matrix()) # Output: # e0 e1 e2 e3 # e1 -e0 e3 -e2 # e2 -e3 -e0 e1 # e3 e2 -e1 -e0 print(O.e_matrix()) # Output shows 8x8 octonion multiplication table # Get as 2D list instead of string matrix = C.e_matrix(string=False) print(matrix) # -> [['e0', 'e1'], ['e1', '-e0']] # Get raw hypercomplex numbers raw = C.e_matrix(string=False, raw=True) print(raw) # -> [[(1 0), (0 1)], [(0 1), (-1 0)]] ``` ### Response Example ```json { "multiplication_table": "string or 2D list of unit elements" } ``` ``` -------------------------------- ### Format Hypercomplex Numbers with f-strings Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Shows how to use f-strings for custom formatting of hypercomplex numbers, including specifying precision and padding. The format specifier applies to each coefficient individually. ```python o = O(0.001, 1, -2, 3.3333, 4e5) print(f"{o:.2f}") # -> (0.00 1.00 -2.00 3.33 400000.00 0.00 0.00 0.00) print(f"{R(23.9):04.0f}") # -> (0024) ``` -------------------------------- ### e(index) Class Method Source: https://context7.com/discretegames/hypercomplex/llms.txt Generates the unit hypercomplex number for a given index, which has a coefficient of 1 at that index and 0 elsewhere. These form the basis of the algebra. ```APIDOC ## e(index) Class Method ### Description Returns the unit hypercomplex number where the coefficient at the given index is 1 and all others are 0. These unit elements form the basis of the hypercomplex algebra. ### Method Class method ### Parameters - **index** (int) - Required - The index of the unit element to generate. ### Request Example ```python from hypercomplex import C, Q, O, S # Unit elements print(C.e(0)) # -> (1 0) print(C.e(1)) # -> (0 1) print(Q.e(2)) # -> (0 0 1 0) print(O.e(3)) # -> (0 0 0 1 0 0 0 0) # Build numbers from unit elements s1 = S.e(5) + S.e(10) print(s1) # -> (0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0) ``` ### Response Example ```json { "unit_hypercomplex": "hypercomplex number with 1 at index and 0 elsewhere" } ``` ``` -------------------------------- ### Generate Hypercomplex Multiplication Tables Source: https://context7.com/discretegames/hypercomplex/llms.txt Obtain the multiplication table for unit elements using the `e_matrix()` class method. This helps understand algebraic structure, including non-commutativity. ```python from hypercomplex import C, Q, O # String representation (default) print(Q.e_matrix()) # Output: # e0 e1 e2 e3 # e1 -e0 e3 -e2 # e2 -e3 -e0 e1 # e3 e2 -e1 -e0 print(O.e_matrix()) # Output shows 8x8 octonion multiplication table ``` ```python # Get as 2D list instead of string matrix = C.e_matrix(string=False) print(matrix) # -> [['e0', 'e1'], ['e1', '-e0']] ``` ```python # Get raw hypercomplex numbers raw = C.e_matrix(string=False, raw=True) print(raw) # -> [[(1 0), (0 1)], [(0 1), (-1 0)]] ``` -------------------------------- ### Formatting Source: https://context7.com/discretegames/hypercomplex/llms.txt Hypercomplex numbers support Python's format specification for controlling output, such as fixed-point, zero-padded, and scientific notation. ```APIDOC ## Formatting ### Description Hypercomplex numbers support Python's format specification for controlling output. By default, coefficients use 'g' format. ### Method Instance method (using f-strings or `format()`) ### Parameters Format specifiers as per Python's standard string formatting. ### Request Example ```python from hypercomplex import R, O o = O(0.001, 1, -2, 3.3333, 4e5) # Fixed-point formatting print(f"{o:.2f}") # -> (0.00 1.00 -2.00 3.33 400000.00 0.00 0.00 0.00) # Zero-padded formatting print(f"{R(23.9):04.0f}") # -> (0024) # Scientific notation print(f"{o:.2e}") # -> (1.00e-03 1.00e+00 -2.00e+00 3.33e+00 4.00e+05 0.00e+00 0.00e+00 0.00e+00) ``` ### Response Example ```json { "formatted_string": "string representation of the hypercomplex number with specified formatting" } ``` ``` -------------------------------- ### Perform Division and Inversion Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Division and multiplicative inverse operations for hypercomplex numbers. ```python print(100 / C(0, 2)) # -> (0 -50) print(C(2, 2) / Q(1, 2, 3, 4)) # -> (0.2 -0.0666667 0.0666667 -0.466667) print(C(2, 2) * Q(1, 2, 3, 4).inverse()) # -> (0.2 -0.0666667 0.0666667 -0.466667) print(R(2).inverse(), 1 / R(2)) # -> (0.5) (0.5) ``` -------------------------------- ### Generate Multiplication Tables Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Retrieves the multiplication table for unit hypercomplex numbers. ```python print(O.e_matrix()) # -> e1 e2 e3 e4 e5 e6 e7 # -e0 e3 -e2 e5 -e4 -e7 e6 # -e3 -e0 e1 e6 e7 -e4 -e5 # e2 -e1 -e0 e7 -e6 e5 -e4 # -e5 -e6 -e7 -e0 e1 e2 e3 # e4 -e7 e6 -e1 -e0 -e3 e2 # e7 e4 -e5 -e2 e3 -e0 -e1 # -e6 e5 e4 -e3 -e2 e1 -e0 # print(C.e_matrix(string=False, raw=True)) # -> [[(1 0), (0 1)], [(0 1), (-1 0)]] ``` -------------------------------- ### Generate Hypercomplex Algebra Class by Level Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Use `cayley_dickson_algebra` to repeatedly apply the Cayley-Dickson construction to a base type for a specified number of levels, creating algebras with `2**level` dimensions. ```python from hypercomplex import * OctonionNum = cayley_dickson_algebra(3) o = OctonionNum(8, 7, 6, 5, 4, 3, 2, 1) print(o) # -> (8 7 6 5 4 3 2 1) print(2 * o) # -> (16 14 12 10 8 6 4 2) print(o.conjugate()) # -> (8 -7 -6 -5 -4 -3 -2 -1) ``` -------------------------------- ### Using Pre-defined Hypercomplex Number Types Source: https://context7.com/discretegames/hypercomplex/llms.txt The library provides convenient aliases for common hypercomplex number types like Real (R, CD1), Complex (C, CD2), Quaternion (Q, CD4), and up to Voudon (V, CD256). These aliases function identically to classes created with `reals` or `cayley_dickson_algebra`. ```python from hypercomplex import Real, Complex, Quaternion, Octonion, Sedenion from hypercomplex import R, C, Q, O, S, P, X, U, V from hypercomplex import CD1, CD2, CD4, CD8, CD16, CD # All aliases work identically print(Real(4)) # -> (4) print(R(-1.5)) # -> (-1.5) print(CD1(2.5)) # -> (2.5) ``` -------------------------------- ### Cayley-Dickson Construction for Higher Dimensions Source: https://github.com/discretegames/hypercomplex/blob/main/README.md The `cayley_dickson_construction` function generates a new hypercomplex number class with double the dimension of the provided basis. This allows for recursive construction of complex numbers, quaternions, and beyond. ```python from hypercomplex import * RealNum = reals() ComplexNum = cayley_dickson_construction(RealNum) QuaternionNum = cayley_dickson_construction(ComplexNum) q = QuaternionNum(1, 2, 3, 4) print(q) # -> (1 2 3 4) print(1 / q) # -> (0.0333333 -0.0666667 -0.1 -0.133333) print(q + 1+2j) # -> (2 4 3 4) ``` -------------------------------- ### Create Hypercomplex Algebras with cayley_dickson_algebra() Source: https://context7.com/discretegames/hypercomplex/llms.txt The `cayley_dickson_algebra` function (or its alias `cd_algebra`) is a helper to create hypercomplex number classes at a specified level using repeated Cayley-Dickson constructions. Level 0 yields reals (1D), level 1 yields complex (2D), level 2 yields quaternions (4D), and so on. It can also use a specified base type, such as `int`, for the algebra. ```python from hypercomplex import cayley_dickson_algebra, cd_algebra # Create specific algebra levels RealNum = cayley_dickson_algebra(0) # 2^0 = 1 dimension ComplexNum = cayley_dickson_algebra(1) # 2^1 = 2 dimensions QuaternionNum = cayley_dickson_algebra(2) # 2^2 = 4 dimensions OctonionNum = cd_algebra(3) # 2^3 = 8 dimensions o = OctonionNum(8, 7, 6, 5, 4, 3, 2, 1) print(o) # -> (8 7 6 5 4 3 2 1) print(2 * o) # -> (16 14 12 10 8 6 4 2) print(o.conjugate()) # -> (8 -7 -6 -5 -4 -3 -2 -1) # Create very high dimensional algebras HighDim = cayley_dickson_algebra(10) # 2^10 = 1024 dimensions print(len(HighDim())) # -> 1024 # Use integer base type instead of float IntQuaternion = cayley_dickson_algebra(2, int) print(IntQuaternion.base()) # -> ``` -------------------------------- ### cayley_dickson_construction(basis) Source: https://context7.com/discretegames/hypercomplex/llms.txt Creates a new class of hypercomplex numbers with twice the dimension of the given basis. ```APIDOC ## cayley_dickson_construction(basis) ### Description Creates a new class of hypercomplex numbers with twice the dimension of the given basis. This implements the Cayley-Dickson construction algorithm. ### Parameters #### Request Body - **basis** (class) - Required - The existing hypercomplex number class to extend. ``` -------------------------------- ### Check Truthiness and Convert Hypercomplex Numbers Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Demonstrates how to check if a hypercomplex number is truthy and how to convert them to standard numeric types like complex, int, and float. Conversion is only valid if coefficients beyond the target type's dimension are zero. ```python print(bool(Q())) # -> False print(bool(Q(0, 0, 0.01, 0))) # -> True print(complex(Q(5, 5))) # -> (5+5j) print(int(V(9.9))) # -> 9 # print(float(C(1, 2))) <- invalid ``` -------------------------------- ### coefficients() Source: https://context7.com/discretegames/hypercomplex/llms.txt Retrieves all coefficients of a hypercomplex number as a tuple. Provides access to individual coefficients via properties like `real`, `imag`, and indexing. ```APIDOC ## coefficients() ### Description Returns a tuple containing all coefficients of the hypercomplex number in their base type. The `real` and `imag` properties provide shortcuts for the first two coefficients. Indexing with `[]` is also supported. ### Method Instance method ### Parameters None ### Request Example ```python from hypercomplex import Q q = Q(2, 3, 4, 5) print(q.coefficients()) # -> (2.0, 3.0, 4.0, 5.0) print(q.real, q.imag) # -> 2.0 3.0 print(q[0], q[1], q[2], q[3]) # -> 2.0 3.0 4.0 5.0 # Check if coefficient exists print(3 in Q(1, 2, 3, 4)) # -> True print(5 in Q(1, 2, 3, 4)) # -> False ``` ### Response Example ```json { "coefficients": "tuple of coefficients", "real": "first coefficient", "imag": "second coefficient" } ``` ``` -------------------------------- ### Division and Inverse of Hypercomplex Numbers Source: https://context7.com/discretegames/hypercomplex/llms.txt Division is performed by multiplying with the multiplicative inverse. The `inverse()` method computes this inverse for any non-zero hypercomplex number. ```python from hypercomplex import R, C, Q # Division print(100 / C(0, 2)) # -> (0 -50) print(C(2, 2) / Q(1, 2, 3, 4)) # -> (0.2 -0.0666667 0.0666667 -0.466667) # Using inverse() directly print(C(2, 2) * Q(1, 2, 3, 4).inverse()) # -> (0.2 -0.0666667 0.0666667 -0.466667) # Real number inverse print(R(2).inverse()) # -> (0.5) print(1 / R(2)) # -> (0.5) ``` -------------------------------- ### Create Real Number Class with reals() Source: https://context7.com/discretegames/hypercomplex/llms.txt Use the `reals` function to create a class for real numbers. It can be based on `float` (default) or other numeric types like `decimal.Decimal` for higher precision. Real numbers support standard operations like inverse, conjugate, and norm. ```python from hypercomplex import reals from decimal import Decimal # Create real number class based on float (default) R = reals() print(R(4)) # -> (4) print(R(-1.5)) # -> (-1.5) # Create real number class based on Decimal for high precision D = reals(Decimal) print(D(10) / 4) # -> (2.5) print(D(3) * D(9)) # -> (27) # Real numbers support all standard operations r = R(2) print(r.inverse()) # -> (0.5) print(r.conjugate()) # -> (2) print(r.norm()) # -> 2.0 print(r.coefficients()) # -> (2.0,) ``` -------------------------------- ### cayley_dickson_algebra(level, base) Source: https://context7.com/discretegames/hypercomplex/llms.txt A helper function that repeatedly applies the Cayley-Dickson construction to create hypercomplex number classes at any level. ```APIDOC ## cayley_dickson_algebra(level, base) ### Description Repeatedly applies the Cayley-Dickson construction to create hypercomplex number classes at any level. ### Parameters #### Request Body - **level** (int) - Required - The level of construction (0 for reals, 1 for complex, 2 for quaternions, etc.). - **base** (type) - Optional - The numeric type to use as the base (default is float). ``` -------------------------------- ### Pre-defined Number Types Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Lists and describes the nine internal hypercomplex number types provided by the package. ```APIDOC ## Pre-defined Number Types The package provides nine internal number types, built upon each other: | Name | Aliases | Description | |--------------|-----------------------|-------------------------------------------------------------------------------------------------------------------| | `Real` | `R`, `CD1`, `CD[0]` | Real numbers with 1 hypercomplex dimension based on `float`. | | `Complex` | `C`, `CD2`, `CD[1]` | Complex numbers with 2 hypercomplex dimensions based on `Real`. | | `Quaternion` | `Q`, `CD4`, `CD[2]` | Quaternion numbers with 4 hypercomplex dimensions based on `Complex`. | | `Octonion` | `O`, `CD8`, `CD[3]` | Octonion numbers with 8 hypercomplex dimensions based on `Quaternion`. | | `Sedenion` | `S`, `CD16`, `CD[4]` | Sedenion numbers with 16 hypercomplex dimensions based on `Octonion`. | | `Pathion` | `P`, `CD32`, `CD[5]` | Pathion numbers with 32 hypercomplex dimensions based on `Sedenion`. | | `Chingon` | `X`, `CD64`, `CD[6]` | Chingon numbers with 64 hypercomplex dimensions based on `Pathion`. | | `Routon` | `U`, `CD128`, `CD[7]` | Routon numbers with 128 hypercomplex dimensions based on `Chingon`. | | `Voudon` | `V`, `CD256`, `CD[8]` | Voudon numbers with 256 hypercomplex dimensions based on `Routon`. | These types can be instantiated and used directly for mathematical operations. ``` -------------------------------- ### reals(base) Source: https://context7.com/discretegames/hypercomplex/llms.txt Creates a class representing real numbers (1 hypercomplex dimension) based on a specified numeric type. ```APIDOC ## reals(base) ### Description Creates a class representing real numbers (1 hypercomplex dimension) based on any numeric type. This is the foundation for building higher-dimensional hypercomplex algebras. ### Parameters #### Request Body - **base** (type) - Optional - The numeric type to use as the base (default is float, e.g., decimal.Decimal). ``` -------------------------------- ### Calculate Conjugates Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Retrieves the conjugate of a hypercomplex number. ```python print(R(9).conjugate()) # -> (9) print(C(9, 8).conjugate()) # -> (9 -8) print(Q(9, 8, 7, 6).conjugate()) # -> (9 -8 -7 -6) ``` -------------------------------- ### Integer Powers of Hypercomplex Numbers Source: https://context7.com/discretegames/hypercomplex/llms.txt Raise hypercomplex numbers to integer powers, which serves as a shortcut for repeated multiplication (positive powers) or division (negative powers). The zero power yields the multiplicative identity. ```python from hypercomplex import Q q = Q(0, 3, 4, 0) # Positive powers (repeated multiplication) print(q**5) # -> (0 1875 2500 0) print(q * q * q * q * q) # -> (0 1875 2500 0) # Negative powers (repeated division) print(q**-1) # -> (0 -0.12 -0.16 0) print(1 / q) # -> (0 -0.12 -0.16 0) # Zero power gives multiplicative identity print(q**0) # -> (1 0 0 0) ``` -------------------------------- ### Generate Unit Hypercomplex Numbers Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Creates a unit hypercomplex number for a given index. ```python print(C.e(0)) # -> (1 0) print(C.e(1)) # -> (0 1) print(O.e(3)) # -> (0 0 0 1 0 0 0 0) ``` -------------------------------- ### Perform Addition and Subtraction Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Arithmetic operations result in the type with the higher number of dimensions. ```python print(Q(0, 1, 2, 2) + C(9, -1)) # -> (9 0 2 2) print(100.1 - O(0, 0, 0, 0, 1.1, 2.2, 3.3, 4.4)) # -> (100.1 0 0 0 -1.1 -2.2 -3.3 -4.4) ``` -------------------------------- ### Generate Real Numbers Class with Custom Base Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Use `reals` to create a class for real numbers with a specified base type, such as `Decimal`. Operations on instances of this class maintain the base type while retaining the real number type. ```python from hypercomplex import reals from decimal import Decimal D = reals(Decimal) print(D(10) / 4) # -> (2.5) print(D(3) * D(9)) # -> (27) ``` -------------------------------- ### Check Membership using 'in' Operator Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Explains that the `in` operator checks for the presence of a value within the coefficients of a hypercomplex number, similar to checking membership in a tuple. ```python print(3 in Q(1, 2, 3, 4)) # -> True print(5 in Q(1, 2, 3, 4)) # -> False ``` -------------------------------- ### Norm and Norm Squared of Hypercomplex Numbers Source: https://context7.com/discretegames/hypercomplex/llms.txt The `norm()` method returns the absolute value (magnitude) as a float. `norm_squared()` returns the square of the norm, which is more efficient if the exact norm is not required. The built-in `abs()` function is also supported. ```python from hypercomplex import O, Q # Norm (absolute value) print(O(3, 4).norm()) # -> 5.0 print(type(O(3, 4).norm())) # -> print(abs(O(3, 4))) # -> 5.0 # Norm squared (avoids sqrt calculation) print(O(3, 4).norm_squared()) # -> 25.0 ``` -------------------------------- ### Type Conversion Source: https://context7.com/discretegames/hypercomplex/llms.txt Hypercomplex numbers can be converted to `int`, `float`, or `complex` if higher-order coefficients are zero. Boolean conversion checks for any non-zero coefficient. ```APIDOC ## Type Conversion ### Description Hypercomplex numbers can be converted to `int`, `float`, or `complex` when the coefficients beyond those dimensions are all zero. Boolean conversion checks if any coefficient is non-zero. ### Method Instance methods (`int()`, `float()`, `complex()`, `bool()`) ### Parameters None ### Request Example ```python from hypercomplex import Q, V # Boolean conversion (truthy if any non-zero coefficient) print(bool(Q())) # -> False print(bool(Q(0, 0, 0.01, 0))) # -> True # Convert to Python types (only valid when higher coefficients are 0) print(complex(Q(5, 5))) # -> (5+5j) print(int(V(9.9))) # -> 9 print(float(Q(3.14))) # -> 3.14 # Invalid conversion raises TypeError # float(C(1, 2)) <- TypeError: non-zero imaginary coefficient ``` ### Response Example ```json { "converted_value": "int, float, complex, or boolean" } ``` ``` -------------------------------- ### Access Coefficients of Hypercomplex Number Source: https://context7.com/discretegames/hypercomplex/llms.txt Retrieve all coefficients of a hypercomplex number as a tuple. Access individual coefficients using the `real` and `imag` properties or by indexing. ```python print(R(100).coefficients()) # -> (100.0,) q = Q(2, 3, 4, 5) print(q.coefficients()) # -> (2.0, 3.0, 4.0, 5.0) print(q.real, q.imag) # -> 2.0 3.0 print(q[0], q[1], q[2], q[3]) # -> 2.0 3.0 4.0 5.0 ``` ```python # Check if coefficient exists print(3 in Q(1, 2, 3, 4)) # -> True print(5 in Q(1, 2, 3, 4)) # -> False ``` -------------------------------- ### Perform Multiplication Source: https://github.com/discretegames/hypercomplex/blob/main/README.md Multiplication results in the type with more dimensions. Note that quaternions are non-commutative. ```python print(10 * S(1, 2, 3)) # -> (10 20 30 0 0 0 0 0 0 0 0 0 0 0 0 0) print(Q(1.5, 2.0) * O(0, -1)) # -> (2 -1.5 0 0 0 0 0 0) # notice quaternions are non-commutative print(Q(1, 2, 3, 4) * Q(1, 0, 0, 1)) # -> (-3 5 1 5) print(Q(1, 0, 0, 1) * Q(1, 2, 3, 4)) # -> (-3 -1 5 5) ``` -------------------------------- ### Equality and Comparison Source: https://context7.com/discretegames/hypercomplex/llms.txt Hypercomplex numbers are equal if all their coefficients match. Missing coefficients are treated as 0, allowing comparison between different dimension types and Python numeric types. ```APIDOC ## Equality and Comparison ### Description Hypercomplex numbers are equal if all their coefficients match. Missing coefficients are treated as 0, allowing comparison between different dimension types. ### Method Instance method (equality check using `==`) ### Parameters None ### Request Example ```python from hypercomplex import R, C, Q, V # Cross-dimension equality print(R(999) == V(999)) # -> True print(C(1, 2) == Q(1, 2)) # -> True print(C(1, 2) == Q(1, 2, 0.1)) # -> False # Comparison with Python types print(C(0, 7) == 7j) # -> True print(R(5) == 5.0) # -> True ``` ### Response Example ```json { "equality_result": "boolean (True if equal, False otherwise)" } ``` ```