### Quaternion Product Example Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/InterfacingOtherMathSystems.ipynb.txt Performs a quaternion product of two quaternions, q1 and q2. ```python q1 = q2S(1, 2, 3, 4) q2 = q2S(5, 6, 7, 8) # quaternion product q1*q2 ``` -------------------------------- ### Install Clifford via PyPI Source: https://clifford.readthedocs.io/en/latest/_sources/installation.rst.txt Use this command to install the latest stable version of Clifford from the Python Package Index. ```bash pip3 install clifford ``` -------------------------------- ### Quaternion Conjugation Example Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/InterfacingOtherMathSystems.ipynb.txt Demonstrates quaternion conjugation using the reversion operator '~'. ```python ~q1 ``` -------------------------------- ### Editable Installation of Clifford Source: https://clifford.readthedocs.io/en/latest/_sources/installation.rst.txt Clone the Clifford repository and install it in editable mode for development. ```bash git clone https://github.com/pygae/clifford.git ``` ```bash pip3 install -e ./clifford ``` -------------------------------- ### Install Development Version of Clifford Source: https://clifford.readthedocs.io/en/latest/_sources/installation.rst.txt Install the latest development version of Clifford directly from the master branch on GitHub. ```bash pip3 install git+https://github.com/pygae/clifford.git@master ``` -------------------------------- ### Initialize 3D Euclidean Space in Conformal Framework (Cl(4,1)) Source: https://clifford.readthedocs.io/en/latest/tutorials/PerformanceCliffordTutorial.html Set up a 3D Euclidean space within the conformal framework (Cl(4,1) algebra) and import specific blades and constants for use in calculations. This example uses notation from Lasenby et al. ```python from clifford import g3c # Get the layout in our local namespace etc etc layout = g3c.layout locals().update(g3c.blades) ep, en, up, down, homo, E0, ninf, no = (g3c.stuff["ep"], g3c.stuff["en"], g3c.stuff["up"], g3c.stuff["down"], g3c.stuff["homo"], g3c.stuff["E0"], g3c.stuff["einf"], -g3c.stuff["eo"]) # Define a few useful terms E = ninf^(no) I5 = e12345 I3 = e123 ``` -------------------------------- ### Initialize 2D Geometric Algebra and Conversion Functions Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/InterfacingOtherMathSystems.ipynb.txt Sets up a 2D geometric algebra environment and defines functions to convert between complex numbers and 2D spinors, and vice-versa. Ensure `clifford` is installed. ```python import clifford as cf layout, blades = cf.Cl(2) # instantiate a 2D- GA locals().update(blades) # put all blades into local namespace def c2s(z): '''convert a complex number to a spinor''' return z.real + z.imag*e12 def s2c(S): '''convert a spinor to a complex number''' S0 = float(S(0)) S2 = float(-S|e12) return S0 + S2*1j ``` -------------------------------- ### Install Clifford with Specific Numba and Sparse Versions Source: https://clifford.readthedocs.io/en/latest/_sources/installation.rst.txt Install Clifford version 1.3 or older with compatible versions of numba and sparse to avoid warnings. ```bash pip3 install clifford "numba~=0.48.0" "sparse~=0.9.0" ``` -------------------------------- ### CGA Example: Translating a Sphere Source: https://clifford.readthedocs.io/en/latest/api/cga.html Demonstrates creating a Conformal Geometric Algebra layout, defining a sphere, creating a translation, and applying the translation to the sphere. Shows how to compute the center of the translated sphere. ```python >>> from clifford import Cl >>> from clifford.cga import CGA >>> g3, blades = Cl(3) >>> locals().update(blades) >>> g3c = CGA(g3) >>> C = g3c.round(3) # create random sphere >>> T = g3c.translation(e1+e2) # create translation >>> C_ = T(C) # translate the sphere >>> C_.center # compute center of sphere -(1.0^e4) - (1.0^e5) ``` -------------------------------- ### Perform Quaternion Computations Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/InterfacingOtherMathSystems.ipynb.txt Example of creating a quaternion spinor and accessing its scalar and bivector parts. ```python q1 = q2S(1,2,3,4) q1 ``` ```python # 'scalar' part q1(0) ``` ```python # 'vector' part (more like bivector part!) q1(2) ``` -------------------------------- ### Apply Spinor Conversions Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/InterfacingOtherMathSystems.ipynb.txt Examples of mapping complex numbers to specific bivector planes. ```python c2s(1+2j, e23) ``` ```python c2s(3+4j, e13) ``` -------------------------------- ### Import and Use Predefined Algebra g2 Source: https://clifford.readthedocs.io/en/latest/predefined-algebras.html Demonstrates importing the g2 algebra and performing a basic operation with its basis vectors. This is useful for quick setup and experimentation with 2D Euclidean geometric algebra. ```python from clifford import g2 g2.e1 * g2.e2 ``` -------------------------------- ### Set up 3D Euclidean Space in Conformal Framework Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/PerformanceCliffordTutorial.ipynb.txt Configure the Clifford algebra for 3D Euclidean space within the conformal framework (Cl(4,1)). This setup includes importing specific blades and defining useful terms like the pseudoscalar. ```python from clifford import g3c # Get the layout in our local namespace etc etc layout = g3c.layout locals().update(g3c.blades) ep, en, up, down, homo, E0, ninf, no = (g3c.stuff["ep"], g3c.stuff["en"], g3c.stuff["up"], g3c.stuff["down"], g3c.stuff["homo"], g3c.stuff["E0"], g3c.stuff["einf"], -g3c.stuff["eo"]) # Define a few useful terms E = ninf^(no) I5 = e12345 I3 = e123 ``` -------------------------------- ### Initialize 3D Layout Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/apollonius-cga-augmented.ipynb.txt Initializes a custom 3D layout and extracts basis vectors. This is the setup for solving Apollonius' problem with spheres in 3D. ```python l3 = OurCustomLayout(ndims=3) e1, e2, e3 = l3.basis_vectors_lst[:3] ``` -------------------------------- ### Constructing a Rotor Multivector Source: https://clifford.readthedocs.io/en/latest/tutorials/g3-algebra-of-space.html Example of constructing a rotor as a sum of a scalar and a bivector using trigonometric functions and basis blades. ```python import math theta = math.pi/4 R = math.cos(theta) - math.sin(theta)*e23 R ``` -------------------------------- ### Map Complex Number to Spinor in e13 Plane (3D) Source: https://clifford.readthedocs.io/en/latest/tutorials/InterfacingOtherMathSystems.html Example of converting a complex number to a spinor using the `e13` bivector in a 3D geometric algebra. ```python c2s(3+4j, e13) ``` -------------------------------- ### Map Complex Number to Spinor in e23 Plane (3D) Source: https://clifford.readthedocs.io/en/latest/tutorials/InterfacingOtherMathSystems.html Example of converting a complex number to a spinor using the `e23` bivector in a 3D geometric algebra. ```python c2s(1+2j, e23) ``` -------------------------------- ### Initialize Quaternion Algebra Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/InterfacingOtherMathSystems.ipynb.txt Setting up a 3D geometric algebra with custom names for quaternion components. ```python import clifford as cf # the vector/bivector order is reversed because Hamilton defined quaternions using a # left-handed frame. wtf. names = ['', 'z', 'y', 'x', 'k', 'j', 'i', 'I'] layout, blades = cf.Cl(3, names=names) locals().update(blades) ``` -------------------------------- ### Initialize Clifford Algebra and Variables Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/euler-angles.ipynb.txt Sets up a 3-dimensional Clifford algebra and imports necessary functions. Use this to begin working with geometric algebra in 3D. ```python from numpy import e,pi from clifford import Cl layout, blades = Cl(3) # create a 3-dimensional clifford algebra locals().update(blades) # lazy way to put entire basis in the namespace ``` -------------------------------- ### Instantiating a Conformal Geometric Algebra Source: https://clifford.readthedocs.io/en/latest/tutorials/cga/index.html Demonstrates creating a CGA instance using the Cl class or the conformalize helper function. ```python Cl(3,1) ``` ```python conformalize() ``` -------------------------------- ### Initialize Dirac and Pauli Algebras Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/space-time-algebra.ipynb.txt Instantiate the Dirac and Pauli algebras and populate the local namespace with their respective blades. ```python from clifford import Cl, pretty pretty(precision=1) # Dirac Algebra `D` D, D_blades = Cl(1,3, firstIdx=0, names='d') # Pauli Algebra `P` P, P_blades = Cl(3, names='p') # put elements of each in namespace locals().update(D_blades) locals().update(P_blades) ``` -------------------------------- ### GET clifford.tools.g3c.get_nearest_plane_point Source: https://clifford.readthedocs.io/en/latest/api/generated/generated/clifford.tools.g3c.get_nearest_plane_point.html Calculates the nearest point to the origin on a specified plane using 3DCGA tools. ```APIDOC ## clifford.tools.g3c.get_nearest_plane_point ### Description Get the nearest point to the origin on the plane. ### Parameters #### Arguments - **plane** (object) - Required - The plane object from which to calculate the nearest point to the origin. ``` -------------------------------- ### Define Vectors for Operations Source: https://clifford.readthedocs.io/en/latest/tutorials/cga/index.html Defines two vectors, 'a' and 'b', in G2 for use in subsequent conformal transformation examples. ```python a= 1*e1 + 2*e2 b= 3*e1 + 4*e2 ``` -------------------------------- ### Get Grade from Index Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/PerformanceCliffordTutorial.ipynb.txt Determines the grade of a multivector component based on its index. This is a helper function for sparse multiplication. ```python def get_grade_from_index(index_in): if index_in == 0: return 0 elif index_in < 6: return 1 elif index_in < 16: return 2 elif index_in < 26: return 3 elif index_in < 31: return 4 elif index_in == 31: return 5 else: raise ValueError('Index is out of multivector bounds') ``` -------------------------------- ### Instantiate 3D Geometric Algebra Source: https://clifford.readthedocs.io/en/latest/tutorials/g3-algebra-of-space.html Import the clifford library and create a 3-dimensional geometric algebra instance. This returns the layout and basis blades. ```python import clifford as cf layout, blades = cf.Cl(3) # creates a 3-dimensional clifford algebra ``` -------------------------------- ### Instantiate and Display a Quaternion Source: https://clifford.readthedocs.io/en/latest/tutorials/InterfacingOtherMathSystems.html Creates a quaternion using the q2S function and displays its representation in the Clifford algebra. ```python q1 = q2S(1,2,3,4) q1 ``` -------------------------------- ### clifford.BladeMap Class Source: https://clifford.readthedocs.io/en/latest/api/clifford.BladeMap.html Documentation for the BladeMap class, which relates blades in two different algebras. Includes properties and usage examples. ```APIDOC ## clifford.BladeMap Class ### Description A Map Relating Blades in two different algebras. ### Class Definition `class clifford.BladeMap(_blades_map_, _map_scalars=True)` ### Properties - **_b1** - Property - **_b2** - Property - **_layout1** - Property - **_layout2** - Property ### Examples ```python from clifford import Cl # Dirac Algebra `D` D, D_blades = Cl(1, 3, firstIdx=0, names='d') locals().update(D_blades) # Pauli Algebra `P` P, P_blades = Cl(3, names='p') locals().update(P_blades) sta_split = BladeMap([ (d01, p1), (d02, p2), (d03, p3), (d12, p12), (d23, p23), (d13, p13) ]) ``` ``` -------------------------------- ### Initialize R3 Layout Source: https://clifford.readthedocs.io/en/latest/tutorials/apollonius-cga-augmented.html Creates a custom layout for 3D space and extracts the first three basis vectors. ```python l3 = OurCustomLayout(ndims=3) e1, e2, e3 = l3.basis_vectors_lst[:3] ``` -------------------------------- ### Initialize 3D Geometric Algebra for Custom Bivectors Source: https://clifford.readthedocs.io/en/latest/tutorials/InterfacingOtherMathSystems.html Sets up a 3-dimensional geometric algebra and makes its blades available. This is used to demonstrate complex number mapping onto different bivector planes in 3D. ```python import clifford as cf layout, blades = cf.Cl(3) locals().update(blades) ``` -------------------------------- ### Importing All from g2 Algebra Source: https://clifford.readthedocs.io/en/latest/_sources/predefined-algebras.rst.txt Illustrates using `import *` for interactive use with the g2 algebra, making basis vectors and blades directly accessible. ```python from clifford.g2 import * e1, e2, e12 ``` -------------------------------- ### Initialize Dirac Algebra for BladeMap Source: https://clifford.readthedocs.io/en/latest/api/clifford.BladeMap.html Sets up the Dirac algebra environment required for mapping operations. ```python >>> from clifford import Cl >>> # Dirac Algebra `D` >>> D, D_blades = Cl(1, 3, firstIdx=0, names='d') >>> locals().update(D_blades) ``` -------------------------------- ### Toggle Pretty Printing and Get Eval-able String Source: https://clifford.readthedocs.io/en/latest/tutorials/g3-algebra-of-space.html Switches between pretty printing and an 'ugly' format using cf.ugly(). The 'ugly' format returns an eval-able string representation of the multivector. ```python cf.ugly() A.inv() ``` -------------------------------- ### Initialize 2D Geometric Algebra Source: https://clifford.readthedocs.io/en/latest/tutorials/InterfacingOtherMathSystems.html Sets up a 2-dimensional geometric algebra and makes its blades available in the local namespace. This is a prerequisite for complex number operations in 2D. ```python import clifford as cf layout, blades = cf.Cl(2) # instantiate a 2D- GA locals().update(blades) # put all blades into local namespace ``` -------------------------------- ### Import Clifford, NumPy, and Numba Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/PerformanceCliffordTutorial.ipynb.txt Import the necessary libraries for working with Clifford algebra, numerical operations, and JIT compilation. ```python import clifford as cf import numpy as np import numba ``` -------------------------------- ### Initialize R2 Layout Source: https://clifford.readthedocs.io/en/latest/tutorials/apollonius-cga-augmented.html Creates a custom layout for 2D space and extracts the first two basis vectors. ```python l2 = OurCustomLayout(ndims=2) e1, e2 = l2.basis_vectors_lst[:2] ``` -------------------------------- ### Import All from Predefined Algebra g2 Source: https://clifford.readthedocs.io/en/latest/predefined-algebras.html Demonstrates using `import *` to bring all members of a predefined algebra, like g2, into the current namespace. This is convenient for interactive use, allowing direct access to basis vectors and blades. ```python from clifford.g2 import * e1, e2, e12 ``` -------------------------------- ### Initialize G2 Algebra Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/g2-quick-start.ipynb.txt Import the clifford module and instantiate a two-dimensional geometric algebra. ```python import clifford as cf layout, blades = cf.Cl(2) # creates a 2-dimensional clifford algebra ``` -------------------------------- ### Project Vector from GA to CGA using up() Source: https://clifford.readthedocs.io/en/latest/tutorials/cga/index.html Demonstrates projecting a vector from the base geometric algebra (GA) into the conformal geometric algebra (CGA) using the 'up()' function. ```python x = e1+e2 X = up(x) X ``` -------------------------------- ### Clifford API - Global Configuration and Miscellaneous Source: https://clifford.readthedocs.io/en/latest/api/clifford.Layout.html Details on global configuration functions and miscellaneous classes/functions within the Clifford library. ```APIDOC ## Global Configuration and Miscellaneous This section covers global configuration options and other utility classes and functions provided by the Clifford library. ### Global Configuration Functions - **`clifford.global_config`**: (Details on specific functions would be listed here if provided in the source text) ### Miscellaneous Classes - **(Details on specific classes would be listed here if provided in the source text)** ### Miscellaneous Functions - **(Details on specific functions would be listed here if provided in the source text)** ``` -------------------------------- ### Initialize 3D Clifford Algebra Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/InterfacingOtherMathSystems.ipynb.txt Imports the clifford library and initializes a 3D Clifford algebra, making its blades available in the local namespace. ```python import clifford as cf layout, blades = cf.Cl(3) locals().update(blades) blades ``` -------------------------------- ### Accessing Predefined Algebras Source: https://clifford.readthedocs.io/en/latest/predefined-algebras.html Describes how to import and use predefined algebra modules like g2, g3, and g3c to access basis blades and layout properties. ```APIDOC ## Predefined Algebra Modules ### Description Access pre-configured geometric algebra modules to simplify calculations and improve startup performance compared to calling `Cl()` directly. ### Available Modules - **g2**: 2D Euclidean, Cl(2) - **g3**: 3D Euclidean, Cl(3) - **g4**: 4D Euclidean, Cl(4) - **g2c**: Conformal space for G2, Cl(3, 1) - **g3c**: Conformal space for G3, Cl(4, 1) - **pga**: Projective space for G3, Cl(3, 0, 1) - **pga2d**: Projective space for G2, Cl(2, 0, 1) - **gac**: Geometric Algebra for Conics, Cl(5, 3) - **dpga**: Double PGA, Cl(4, 4) - **dg3c**: Double Conformal Geometric Algebra, Cl(8, 2) ### Attributes - **layout**: Returns the associated `clifford.Layout` object. - **blades**: A dictionary shorthand for `Layout.blades()` containing basis blade mappings. - **e**: Basis blades exposed as attributes for direct algebraic operations. ### Usage Example ```python from clifford import g2 # Accessing layout print(g2.layout) # Accessing blades print(g2.blades) # Algebraic operation result = g2.e1 * g2.e2 ``` ``` -------------------------------- ### Clifford API - Constructing Algebras Source: https://clifford.readthedocs.io/en/latest/api/clifford.Layout.html This section details the core components for constructing algebras within the Clifford library. ```APIDOC ## Constructing Algebras This section covers the fundamental classes and functions used to define and construct geometric algebras with the Clifford library. ### Classes - **`clifford.Cl`**: The primary class for constructing and working with geometric algebras. - **`clifford.conformalize`**: Function to conformalize an existing algebra. - **`clifford.MultiVector`**: Represents a multivector in a geometric algebra. - **`clifford.Layout`**: Defines the structure and properties of an algebra's basis. - **`Layout.dims`**: The dimensions of the algebra. - **`Layout.sig`**: The signature of the algebra. - **`Layout.gaDims`**: Dimensions of the geometric algebra. - **`Layout.names`**: Names of the basis vectors. - **`Layout.gradeList`**: List of grades present in the algebra. - **`Layout.gmt`**: Metric tensor. - **`Layout.omt`**: Orthogonal metric tensor. - **`Layout.imt`**: Inverse metric tensor. - **`Layout.lcmt`**: Inverse orthogonal metric tensor. - **`Layout.bladeTupList`**: List of blade tuples. - **`Layout.firstIdx`**: Index of the first basis vector. - **`Layout.dual_func`**: Function for duality operation. - **`Layout.vee_func`**: Function for the vee product. - **`Layout.parse_multivector()`**: Parses a multivector string. - **`Layout.gmt_func_generator()`**: Generator for metric tensor functions. - **`Layout.imt_func_generator()`**: Generator for inverse metric tensor functions. - **`Layout.omt_func_generator()`**: Generator for orthogonal metric tensor functions. - **`Layout.lcmt_func_generator()`**: Generator for inverse orthogonal metric tensor functions. - **`Layout.get_grade_projection_matrix()`**: Gets the grade projection matrix. - **`Layout.gmt_func`**: Metric tensor function. - **`Layout.imt_func`**: Inverse metric tensor function. - **`Layout.omt_func`**: Orthogonal metric tensor function. - **`Layout.lcmt_func`**: Inverse orthogonal metric tensor function. - **`Layout.left_complement_func`**: Function for left complement. - **`Layout.right_complement_func`**: Function for right complement. - **`Layout.adjoint_func`**: Function for adjoint operation. - **`Layout.inv_func`**: Function for inverse operation. - **`Layout.get_left_gmt_matrix()`**: Gets the left metric tensor matrix. - **`Layout.get_right_gmt_matrix()`**: Gets the right metric tensor matrix. - **`Layout.load_ga_file()`**: Loads algebra from a file. - **`Layout.grade_mask()`**: Returns a mask for a given grade. - **`Layout.rotor_mask`**: Mask for rotors. - **`Layout.metric`**: The metric of the algebra. - **`Layout.scalar`**: Represents a scalar value. - **`Layout.pseudoScalar`**: Represents the pseudoscalar. - **`Layout.I`**: The pseudoscalar. - **`Layout.randomMV()`**: Generates a random multivector. - **`Layout.randomV()`**: Generates a random vector. - **`Layout.randomRotor()`**: Generates a random rotor. - **`Layout.basis_vectors`**: The basis vectors of the algebra. - **`Layout.basis_names`**: The names of the basis vectors. - **`Layout.basis_vectors_lst`**: List of basis vectors. - **`Layout.blades_of_grade()`**: Returns blades of a specific grade. - **`Layout.blades_list`**: List of all blades. - **`Layout.blades`**: All blades in the algebra. - **`Layout.bases()`**: Returns the basis vectors. - **`Layout.MultiVector()`**: Constructor for `MultiVector`. - **`clifford.ConformalLayout`**: A specific layout for conformal geometric algebra. ### Functions - **`clifford.Cl`**: Constructor for creating an algebra instance. - **`clifford.conformalize`**: Function to conformalize an existing algebra. ``` -------------------------------- ### Perform 3D Rotation with Geometric Algebra Source: https://clifford.readthedocs.io/en/latest/_sources/index.rst.txt Demonstrates importing 3D space algebra, defining a vector, creating a rotor, and applying the rotation. ```python from clifford.g3 import * # import GA for 3D space import math a = e1 + 2*e2 + 3*e3 # vector R = math.e**(math.pi/4*e12) # rotor R*a*~R # rotate the vector ``` -------------------------------- ### Initialize Clifford Algebra for Quaternions Source: https://clifford.readthedocs.io/en/latest/tutorials/InterfacingOtherMathSystems.html Sets up a 3D geometric algebra with custom names for bivectors to represent quaternion components. Note the reversed order due to Hamilton's convention. ```python import clifford as cf # the vector/bivector order is reversed because Hamilton defined quaternions using a # left-handed frame. wtf. names = ['', 'z', 'y', 'x', 'k', 'j', 'i', 'I'] layout, blades = cf.Cl(3, names=names) locals().update(blades) ``` -------------------------------- ### Perform simple combination of operations Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/cga/index.ipynb.txt Demonstrates combining translation, scaling, and inversion operations on a geometric object. ```python A = up(a) V = T(e1)*E0*D(2) B = V*A*~V assert(down(B) == (-2*a)+e1 ) ``` -------------------------------- ### Verify Inversion using ep Source: https://clifford.readthedocs.io/en/latest/tutorials/cga/index.html Verifies that reflecting a vector 'a' through 'ep' in CGA and then projecting back down to GA results in the inverse of 'a'. This demonstrates the inversion operation. ```python assert(down(ep*up(a)*ep) == a.inv()) ``` -------------------------------- ### clifford.Cl Constructor Source: https://clifford.readthedocs.io/en/latest/api/clifford.Cl.html Constructs a geometric algebra layout and provides basis blades. ```APIDOC ## clifford.Cl Constructor ### Description Returns a `Layout` and basis blade `MultiVector`s for the geometric algebra Clp,q,r. The notation Clp,q,r means that the algebra is p+q+r-dimensional, with the first p vectors with positive signature, the next q vectors negative, and the final r vectors with null signature. ### Method `clifford.Cl()` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from clifford import Cl # Example usage (replace with actual parameters if known) layout, blades = Cl(p=3, q=0, r=0) ``` ### Response #### Success Response (200) - **layout** (Layout) - The resulting layout. - **blades** (Dict[str, MultiVector]) - The blades of the returned layout, equivalent to `layout.blades`. #### Response Example ```json { "layout": "", "blades": { "1": "", "e1": "", "e2": "", "e3": "", "e12": "", "e13": "", "e23": "", "e123": "" } } ``` ``` -------------------------------- ### Initialize G2 Algebra Source: https://clifford.readthedocs.io/en/latest/tutorials/cga/index.html Initializes a 2-dimensional geometric algebra (G2) and inspects its blades. This is a prerequisite for conformalizing. ```python from numpy import pi,e from clifford import Cl, conformalize G2, blades_g2 = Cl(2) blades_g2 # inspect the G2 blades ``` -------------------------------- ### JIT-Optimized Rotor Application Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/PerformanceCliffordTutorial.ipynb.txt Using @numba.njit to compile functions that operate on raw multivector values. ```python @numba.njit def apply_rotor_val_numba(R_val,mv_val): return gmt_func(R_val,gmt_func(mv_val,adjoint_func(R_val))) def apply_rotor_wrapped_numba(R,mv): return cf.MultiVector(layout,apply_rotor_val_numba(R.value,mv.value)) ``` -------------------------------- ### Implement a transversion Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/cga/index.ipynb.txt Builds a transversion using a sequence of inversion, translation, and inversion operations. ```python A = up(a) V = ep*T(b)*ep C = V*A*~V assert(down(C) ==1/(1/a +b)) ``` -------------------------------- ### Initialize Clifford Algebra with Custom Basis Names Source: https://clifford.readthedocs.io/en/latest/tutorials/g3-algebra-of-space.html Use the `names` argument in `Cl()` to provide custom names for basis vectors. This is useful for creating more readable algebra representations. ```python layout, blades = cf.Cl(2, names=['','x','y','i']) blades ``` -------------------------------- ### Perform Basic Geometric Operations Source: https://clifford.readthedocs.io/en/latest/tutorials/g2-quick-start.html Demonstrate geometric, inner, and outer products using the defined basis vectors. ```python e1*e2 # geometric product ``` ```python e1|e2 # inner product ``` ```python e1^e2 # outer product ``` -------------------------------- ### Geometric, Inner, and Outer Products Source: https://clifford.readthedocs.io/en/latest/tutorials/g3-algebra-of-space.html Demonstrates the geometric product (e1*e2), inner product (e1|e2), and outer product (e1^e2) between basis vectors. ```python e1*e2 # geometric product ``` ```python e1|e2 # inner product ``` ```python e1^e2 # outer product ``` ```python e1^e2^e3 # even more outer products ``` -------------------------------- ### Correct Outer Product Evaluation with Parentheses Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/g3-algebra-of-space.ipynb.txt Shows the correct way to combine outer products with addition by using parentheses to enforce the desired evaluation order. This ensures outer products are calculated before addition. ```python (e1^e2) + (e2^e3) # correct ``` -------------------------------- ### Initialize 2D Layout Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/apollonius-cga-augmented.ipynb.txt Initializes a custom 2D layout and extracts basis vectors. Used for setting up geometric algebra operations in 2D. ```python l2 = OurCustomLayout(ndims=2) e1, e2 = l2.basis_vectors_lst[:2] ``` -------------------------------- ### Construct Round Objects Source: https://clifford.readthedocs.io/en/latest/api/generated/clifford.tools.classify.html Shows how to construct Round objects directly to obtain grade-specific geometric interpretations. ```python >>> from clifford.g3c import * >>> Round(location=e1, direction=e1^e2, radius=1) Circle(direction=(1^e12), location=(1^e1), radius=1) >>> Round(direction=e1^e2^e3, location=e1, radius=1) Sphere(direction=(1^e123), location=(1^e1), radius=1) ``` -------------------------------- ### Operator Precedence with Outer Products Source: https://clifford.readthedocs.io/en/latest/tutorials/g3-algebra-of-space.html Illustrates Python's operator precedence issues with outer products and addition. Parentheses are required for correct evaluation. ```python e1^e2 + e2^e3 # fail, evaluates as ``` ```python (e1^e2) + (e2^e3) # correct ``` -------------------------------- ### Transversion Construction Source: https://clifford.readthedocs.io/en/latest/tutorials/cga/index.html Constructs a transversion using inversion, translation, and inversion steps. ```python A = up(a) V = ep*T(b)*ep C = V*A*~V assert(down(C) ==1/(1/a +b)) ``` -------------------------------- ### Cascade Rotations using Factory Functions Source: https://clifford.readthedocs.io/en/latest/tutorials/g3-algebra-of-space.html Demonstrates cascading multiple rotation functions created by `R_factory` to apply a sequence of rotations to a vector. ```python R12 = R_factory(math.pi/3*e12) R23 = R_factory(math.pi/3*e23) R13 = R_factory(math.pi/3*e13) R12(R23(R13(a))) ``` -------------------------------- ### Perform 3D Geometric Algebra operations Source: https://clifford.readthedocs.io/en/latest Demonstrates importing a 3D algebra, defining a vector, creating a rotor, and rotating the vector. ```python In [1]: from clifford.g3 import * # import GA for 3D space In [2]: import math In [3]: a = e1 + 2*e2 + 3*e3 # vector In [4]: R = math.e**(math.pi/4*e12) # rotor In [5]: R*a*~R # rotate the vector Out[5]: (2.0^e1) - (1.0^e2) + (3.0^e3) ``` -------------------------------- ### Conformalize a Geometric Algebra Layout Source: https://clifford.readthedocs.io/en/latest/api/clifford.conformalize.html Use this snippet to convert a GA layout to a CGA layout. It requires importing `Cl` and `conformalize`. The `locals().update()` calls are used to make the CGA blades and utility functions available in the current scope. ```python >>> from clifford import Cl, conformalize >>> G2, blades = Cl(2) >>> G2c, bladesc, stuff = conformalize(G2) >>> locals().update(bladesc) >>> locals().update(stuff) ``` -------------------------------- ### Create an outermorphism matrix Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/linear-transformations.ipynb.txt Initializes an OutermorphismMatrix to extend linear transformations to higher-order blades. ```python from clifford import transformations rot_and_scale_x_ga = transformations.OutermorphismMatrix(rot_and_scale_x, layout) ``` -------------------------------- ### Global Configuration Functions Source: https://clifford.readthedocs.io/en/latest/api/clifford.html Functions to manage global behavior of the Clifford library, including float comparison epsilon and output formatting. ```APIDOC ## clifford.eps(_newEps=None_) ### Description Get or set the epsilon value used for float comparisons within the library. ### Parameters #### Request Body - **newEps** (float) - Optional - The new epsilon value to set. --- ## clifford.pretty(_precision=None_) ### Description Configures the library to use pretty-printing for `repr(MultiVector)` objects. ### Parameters #### Request Body - **precision** (int) - Optional - Number of significant figures to print past the decimal. --- ## clifford.ugly() ### Description Resets the `repr(MultiVector)` output to the default eval-able representation. --- ## clifford.print_precision(_newVal_) ### Description Sets the global precision for printing multivector components. ### Parameters #### Request Body - **newVal** (int) - Required - Number of significant figures to print. ``` -------------------------------- ### Basic Blade Multiplication in g2 Source: https://clifford.readthedocs.io/en/latest/_sources/predefined-algebras.rst.txt Demonstrates the multiplication of basis vectors e1 and e2 in the g2 algebra. ```python from clifford import g2 g2.e1 * g2.e2 ``` -------------------------------- ### Implement Ups and Downs Functions for Custom Layout Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/apollonius-cga-augmented.ipynb.txt Adds `ups` and `downs` methods to `OurCustomLayout` for mapping conformal dual-spheres into the custom algebra and applying the correct sign. ```python def ups(self, s): return s + self.enp1*abs(s) OurCustomLayout.ups = ups; del ups def downs(self, mv): if (mv | self.enp1)[()] > 0: mv = -mv return mv OurCustomLayout.downs = downs; del downs ``` -------------------------------- ### clifford.Layout Constructor Source: https://clifford.readthedocs.io/en/latest/api/clifford.Layout.html Initializes a Layout object, defining the geometric algebra's structure. ```APIDOC ## Layout Constructor ### Description Initializes a Layout object, defining the geometric algebra's structure. ### Method __init__ ### Parameters #### Path Parameters - **sig** (List[int]) - Required - The signature of the vector space. This should be a list of positive and negative numbers where the sign determines the sign of the inner product of the corresponding vector with itself. The values are irrelevant except for sign. This list also determines the dimensionality of the vectors. - **ids** (Optional[BasisVectorIds[Any]]) - Optional - A list of ids to associate with each basis vector. These ids are used to generate names (if not passed explicitly), and also used when using tuple-notation to access elements, such as `mv[(1, 3)] = 1`. Defaults to `BasisVectorIds.ordered_integers(len(sig))`; that is, integers starting at 1. This supersedes the old firstIdx argument. - **order** (Optional[BasisBladeOrder]) - Optional - A specification of the memory order to use when storing the basis blades. Defaults to `BasisBladeOrder.shortlex(len(sig))`. This supersedes the old bladeTupList argument. - **bladeTupList** (List[Tuple[int, ...]]) - Optional - List of tuples corresponding to the blades in the whole algebra. This list determines the order of coefficients in the internal representation of multivectors. The entry for the scalar must be an empty tuple, and the entries for grade-1 vectors must be singleton tuples. Remember, the length of the list will be `2**dims`. - **firstIdx** (int) - Optional - The index of the first vector. That is, some systems number the base vectors starting with 0, some with 1. - **names** (List[str]) - Optional - List of names of each blade. When pretty-printing multivectors, use these symbols for the blades. names should be in the same order as order. You may use an empty string for scalars. By default, the name for each non-scalar blade is ‘e’ plus the ids of the blade as given in ids. ### Request Example ```python # Example for sig sig=[+1, -1, -1, -1] # Hestenes', et al. Space-Time Algebra sig=[+1, +1, +1] # 3-D Euclidean signature # Example for ids ids=BasisVectorIds.ordered_integers(2, first_index=1) ids=BasisVectorIds([10, 20, 30]) # Example for bladeTupList bladeTupList = [(), (0,), (1,), (0, 1)] # 2-D # Example for names names=['', 's0', 's1', 'i'] # 2-D # Full constructor example layout = Layout(sig=[+1, +1, +1], ids=BasisVectorIds([1, 2, 3]), names=['', 'x', 'y', 'z']) ``` ### Deprecated - `bladeTupList`: Use the new `order` and `ids` arguments instead. - `firstIdx`: Use the new `ids` argument instead. ``` -------------------------------- ### Implement and Test Transversion Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/cga/index.ipynb.txt Implements a transversion operation using a combination of reflection and translation. Asserts the correctness of the operation. ```python V = ep * T(a) * ep assert ( V == 1+(eo*a)) K = lambda x: 1+(eo*a) B= up(b) assert( down(K(a)*B*~K(a)) == 1/(a+1/b) ) ``` -------------------------------- ### Populate Namespace with Blades Source: https://clifford.readthedocs.io/en/latest/api/clifford.Layout.html Use this to populate the local namespace with variables corresponding to the blades of a given layout. ```python >>> locals().update(layout.blades()) ``` -------------------------------- ### Generate Standard Line at Origin Source: https://clifford.readthedocs.io/en/latest/api/generated/clifford.tools.g3c.html Creates a standard line at the origin. ```python standard_line_at_origin() ``` -------------------------------- ### Inspect Blades Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/g2-quick-start.ipynb.txt Display the available blades in the current algebra. ```python blades ``` -------------------------------- ### Display Formatting Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/g3-algebra-of-space.ipynb.txt Toggling pretty printing and display precision for multivectors. ```python cf.ugly() A.inv() ``` -------------------------------- ### Display Metric Table Source: https://clifford.readthedocs.io/en/latest/tutorials/apollonius-cga-augmented.html Uses pandas to display the metric of the layout as a table. ```python import pandas as pd # convenient but somewhat slow trick for showing tables pd.DataFrame(l2.metric, index=l2.basis_names, columns=l2.basis_names) ``` -------------------------------- ### Inspect CGA 'stuff' dictionary Source: https://clifford.readthedocs.io/en/latest/tutorials/cga/index.html Inspects the 'stuff' dictionary returned by conformalize(), which contains essential components like projection functions (up, down, homo) and special basis vectors (ep, en, eo, einf, E0). ```python stuff ``` -------------------------------- ### Project Vector from CGA to GA using down() Source: https://clifford.readthedocs.io/en/latest/tutorials/cga/index.html Demonstrates projecting a vector from the conformal geometric algebra (CGA) back to the base geometric algebra (GA) using the 'down()' function. ```python down(X) ``` -------------------------------- ### clifford.ConformalLayout Source: https://clifford.readthedocs.io/en/latest/api/clifford.ConformalLayout.html Documentation for the ConformalLayout class, which provides a layout for conformal geometric algebra and includes helper attributes and methods. ```APIDOC ## class clifford.ConformalLayout ### Description A layout for a conformal algebra, which adds extra constants and helpers. Typically these should be constructed via `clifford.conformalize()`. Added in version 1.2.0. ### Method __init__ ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **args** (*) - **layout** (Layout) - Optional - **kwargs** (_**) ### Request Example ```json { "example": "Not applicable for class constructor" } ``` ### Response #### Success Response (200) None #### Response Example ```json { "example": "Not applicable for class constructor" } ``` ## Attributes ### ep The first added basis element, e+, usually with e+^2=+1 - **Type**: MultiVector ### en The first added basis element, e-, usually with e-^2=-1 - **Type**: MultiVector ### eo The null basis vector at the origin, eo=0.5(e- - e+) - **Type**: MultiVector ### einf The null vector at infinity, e∞=e- + e+ - **Type**: MultiVector ### E0 The minkowski subspace bivector, e∞∧eo - **Type**: MultiVector ### I_base The pseudoscalar of the base ga, in cga layout - **Type**: MultiVector ## Methods ### up up-project a vector from GA to CGA #### Parameters - **x** (MultiVector) - Required ### homo homogenize a CGA vector #### Parameters - **x** (MultiVector) - Required ### down down-project a vector from CGA to GA #### Parameters - **x** (MultiVector) - Required ``` -------------------------------- ### Transversion Operation Source: https://clifford.readthedocs.io/en/latest/tutorials/cga/index.html Demonstrates the construction of a transversion versor and its application to a conformal vector. ```python V = ep * T(a) * ep assert ( V == 1+(eo*a)) K = lambda x: 1+(eo*a) B= up(b) assert( down(K(a)*B*~K(a)) == 1/(a+1/b) ) ``` -------------------------------- ### Accessing Blades in g2 Algebra Source: https://clifford.readthedocs.io/en/latest/_sources/predefined-algebras.rst.txt Demonstrates accessing the blades of the g2 algebra, providing a mapping from blade names to their corresponding values. ```python from clifford import g2 g2.blades ``` -------------------------------- ### Object Fitting Submodule Source: https://clifford.readthedocs.io/en/latest/api/generated/clifford.tools.g3c.html Tools for fitting geometric primitives to point clouds. ```APIDOC ### Submodule: object_fitting #### Description Tools for fitting geometric primitives to point clouds. ``` -------------------------------- ### Transform multivectors manually Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/linear-transformations.ipynb.txt Demonstrates unpacking and repacking coefficients to apply a matrix transformation to a multivector. ```python from clifford.g3 import * v = 2*e1 + 3*e2 v_trans = layout.MultiVector() v_trans[1,], v_trans[2,], v_trans[3,] = rot_and_scale_x @ [v[1,], v[2,], v[3,]] v_trans ``` -------------------------------- ### Clifford API - Submodules Source: https://clifford.readthedocs.io/en/latest/api/clifford.Layout.html Overview of the different submodules available in the Clifford library. ```APIDOC ## Submodules The Clifford library is organized into several submodules for specific functionalities: - **`cga` (`clifford.cga`)**: Conformal Geometric Algebra specific functions and classes. - **`tools` (`clifford.tools`)**: Utility functions and tools. - **`operator` (`clifford.operator`)**: Operator functions for geometric algebra operations. - **`transformations` (`clifford.transformations`)**: Functions for geometric transformations. - **`taylor_expansions` (`clifford.taylor_expansions`)**: Support for Taylor expansions. - **`numba` (`clifford.numba`)**: Numba extension support for performance optimization. ``` -------------------------------- ### Define a custom ConformalLayout Source: https://clifford.readthedocs.io/en/latest/tutorials/apollonius-cga-augmented.html Creates a custom algebra layout by extending ConformalLayout and defining a base conformal layout for compatibility with pyganja. ```python from clifford import ConformalLayout, BasisVectorIds, MultiVector, transformations class OurCustomLayout(ConformalLayout): def __init__(self, ndims): self.ndims = ndims euclidean_vectors = [str(i + 1) for i in range(ndims)] conformal_vectors = ['m2', 'm1'] # Construct our custom algebra. Note that ConformalLayout requires the e- and e+ basis vectors to be last. ConformalLayout.__init__( self, [1]*ndims + [-1] + [1, -1], ids=BasisVectorIds(euclidean_vectors + ['np1'] + conformal_vectors) ) self.enp1 = self.basis_vectors_lst[ndims] # Construct a base algebra without the extra `enp1`, which would not be understood by pyganja. self.conformal_base = ConformalLayout( [1]*ndims + [1, -1], ids=BasisVectorIds(euclidean_vectors + conformal_vectors) ) # this lets us convert between the two layouts self.to_conformal = transformations.between_basis_vectors(self, self.conformal_base) ``` -------------------------------- ### Verify Quaternion Commutation Relations Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/InterfacingOtherMathSystems.ipynb.txt Iterating through quaternion basis elements to display their products. ```python for m in [i, j, k]: for n in [i, j, k]: print ('{}*{}={}'.format(m, n, m*n)) ``` -------------------------------- ### Define Rotor and Test Application Source: https://clifford.readthedocs.io/en/latest/_sources/tutorials/PerformanceCliffordTutorial.ipynb.txt Create a specific rotor that transforms one line to another and test its application. This involves defining lines using geometric algebra constructs and then applying the rotor. ```python line_one = (up(0)^up(e1)^ninf).normal() line_two = (up(0)^up(e2)^ninf).normal() R = 1 + line_two*line_one ``` ```python print(line_two) print(apply_rotor(R,line_one).normal()) ``` -------------------------------- ### Algebra Construction and Core Classes Source: https://clifford.readthedocs.io/en/latest/api/clifford.html Core classes and functions for defining geometric algebras and working with multivectors. ```APIDOC ## clifford.Cl(p, q, r, sig, names, firstIdx, mvClass) ### Description Constructs a geometric algebra Cl(p,q,r) and returns the corresponding Layout and basis blade MultiVectors. --- ## clifford.MultiVector(layout, value, string) ### Description Represents an element of the geometric algebra defined by the provided layout. --- ## clifford.Layout(sig, ids, order, names) ### Description Stores information regarding the geometric algebra structure and the internal representation of multivectors. ```