### Install Clifford via pip Source: https://github.com/pygae/clifford/blob/master/docs/installation.md Standard installation command for the latest stable version from PyPI. ```bash pip3 install clifford ``` -------------------------------- ### Install Clifford development version Source: https://github.com/pygae/clifford/blob/master/docs/installation.md Installs the latest master branch directly from the GitHub repository. ```bash pip3 install git+https://github.com/pygae/clifford.git@master ``` -------------------------------- ### Example Profile Output Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/PerformanceCliffordTutorial.ipynb An example of the performance profile output, highlighting time spent in multiplication and internal checks. ```text ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 66.290 66.290 {built-in method builtins.exec} 1 0.757 0.757 66.290 66.290 :2() 1000000 3.818 0.000 65.534 0.000 :1(apply_rotor) 2000000 9.269 0.000 55.641 0.000 __init__.py:751(__mul__) 2000000 3.167 0.000 29.900 0.000 __init__.py:717(_checkOther) 2000000 1.371 0.000 19.906 0.000 __init__.py:420(__ne__) 2000000 6.000 0.000 18.535 0.000 numeric.py:2565(array_equal) 2000000 10.505 0.000 10.505 0.000 __init__.py:260(mv_mult) ``` -------------------------------- ### Install Clifford in editable mode Source: https://github.com/pygae/clifford/blob/master/docs/installation.md Clones the repository and installs it in editable mode for local development and modification. ```bash git clone https://github.com/pygae/clifford.git pip3 install -e ./clifford ``` -------------------------------- ### Initialize Clifford Layout Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/InterfacingOtherMathSystems.ipynb Setup the Clifford layout for 3D space and update the local namespace with basis blades. ```python import clifford as cf layout, blades = cf.Cl(3) locals().update(blades) blades ``` -------------------------------- ### Install Clifford via Package Managers Source: https://github.com/pygae/clifford/blob/master/README.md Commands to install the library using conda or pip. ```bash conda install clifford -c conda-forge ``` ```bash pip3 install clifford ``` -------------------------------- ### Construct Layout with Deprecated Arguments Source: https://github.com/pygae/clifford/blob/master/docs/api/clifford.Layout.md Example showing how to achieve the same layout as the deprecated bladeTupList argument using the newer ids and order arguments. ```python ids = BasisVectorIds([.ordered_integers(2, first_index=0)]) order = ids.order_from_tuples([(), (0,), (1,), (0, 1)]) Layout(sig, ids=ids, order=order) ``` -------------------------------- ### Mathematical Syntax Example in Python Source: https://github.com/pygae/clifford/wiki/Geometric-Algebra-in-Python Illustrates the desired mathematical syntax for operations like rotation, which aims to resemble mathematical notation rather than traditional code. ```python v = R*v*~R ``` -------------------------------- ### Setup Matplotlib for Clifford Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/cga/visualization-tools.ipynb Configures matplotlib and imports the clifford plotting toolkit. ```python from matplotlib import pyplot as plt plt.ioff() # we'll ask for plotting when we want it # if you're editing this locally, you'll get an interactive UI if you uncomment the following # # %matplotlib notebook from mpl_toolkits.clifford import plot import mpl_toolkits.clifford; mpl_toolkits.clifford.__version__ ``` -------------------------------- ### Install Clifford with specific dependency versions Source: https://github.com/pygae/clifford/blob/master/docs/installation.md Use this command to avoid compatibility warnings with Numba 0.50.0 and 0.49.0. ```bash pip3 install clifford "numba~=0.48.0" "sparse~=0.9.0" ``` -------------------------------- ### Check Clifford Version Source: https://github.com/pygae/clifford/blob/master/CITATION.md Commands to identify the installed version of the clifford library for citation purposes. ```bash python -m pip show clifford ``` ```python print(clifford.__version__) ``` -------------------------------- ### Perform 3D Geometric Algebra Operations Source: https://github.com/pygae/clifford/blob/master/README.md Example demonstrating vector definition and rotation using the G3 algebra module. ```python from clifford.g3 import * # import GA for 3D space from math import e, pi a = e1 + 2*e2 + 3*e3 # vector R = e**(pi/4*e12) # rotor R*a*~R # rotate the vector ``` -------------------------------- ### Constructing a Rotor Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/g3-algebra-of-space.ipynb Example of constructing a rotor as a sum of a scalar and a bivector using trigonometric functions. ```python import math theta = math.pi/4 R = math.cos(theta) - math.sin(theta)*e23 R ``` -------------------------------- ### Clifford Algebra Operations Example Source: https://github.com/pygae/clifford/blob/master/examples/g2.ipynb Illustrates various Clifford algebra operations including vector definition, projection, outer product, inner product, and left contraction. Requires prior import of necessary functions. ```python # Example a = (2 + 5.7*e2)*e1 b = 5*e2 - 3.5*e1 print(a) print(b) # Projection print(a(2)) # Outer product print(a^b) # Inner product print(a|b) # Left contraction print(a.lc(b)) ``` -------------------------------- ### Import PGA Module Source: https://github.com/pygae/clifford/blob/master/examples/pga.ipynb Imports all necessary components from the clifford.pga module. This is a common starting point for using the library. ```python from clifford.pga import * ``` -------------------------------- ### Setup Matplotlib 3D Plots Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/cga/visualization-tools.ipynb Construct empty side-by-side 3D plots using matplotlib and set their axis limits. ```python # standard matplotlib stuff - construct empty plots side-by-side, and set the scaling fig, (ax_before, ax_both) = plt.subplots(1, 2, subplot_kw=dict(projection='3d'), figsize=(8, 4)) ax_before.set(xlim=[-4, 4], ylim=[-4, 4], zlim=[-4, 4]) ax_both.set(xlim=[-4, 4], ylim=[-4, 4], zlim=[-4, 4]) ``` -------------------------------- ### Translate a Sphere Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/cga/object-oriented.ipynb Demonstrates how to create a translation operator and then apply it to a sphere object to get a translated sphere. The center of the translated sphere can then be computed. ```python T = cga.translation(e1+e2) # make a translation C_ = T(C) # translate the sphere cga.down(C_.center) # compute center again ``` -------------------------------- ### Define Jitted CGA up() Function with Numba Source: https://github.com/pygae/clifford/blob/master/docs/api/numba.md Example of defining a vectorized 'up()' function for CGA using Numba's njit decorator. Ensure necessary imports are present. ```python from clifford.g3c import * @numba.njit def jit_up(x): return eo + x + 0.5*abs(x)**2*einf assert up(e1) == jit_up(e1) ``` -------------------------------- ### Performance Considerations Source: https://github.com/pygae/clifford/blob/master/docs/api/numba.md Discusses startup time for JIT compilation and overhead associated with Numba's dispatch loop, along with strategies to mitigate them. ```APIDOC ## Performance Considerations ### Startup Time The initial compilation time for `@jit` can be substantial. Using `cache=True` can help alleviate this. ### Dispatch Overhead Numba's dispatch loop can add overhead to calls. `clifford` attempts to reduce this by using `_numba_type_` and an internal cache. ### Example of Overhead ```default from clifford.g3c import * import numba @numba.njit def mul(a, b): return a * b # Significant overhead observed here due to repeated calls within the loop x = e1 for i in range(10000): x = mul(x, x + e2) ``` ### Avoiding Overhead Jitting the entire loop can avoid the per-call overhead. ```default from clifford.g3c import * import numba @numba.njit def mul(a, b): return a * b @numba.njit def the_loop(x): for i in range(1000): x = mul(x, x + e1) return x # Significantly faster when the loop is jitted x = the_loop(eq) ``` ``` -------------------------------- ### Initialize CGA Environment Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/cga/interpolation.ipynb Imports the necessary basis blades for (4,1) conformal geometric algebra. ```python from clifford.g3c import * blades ``` -------------------------------- ### Initialize Dirac and Pauli Algebras Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/space-time-algebra.ipynb Sets up the Dirac and Pauli algebras and populates 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) ``` -------------------------------- ### Initialize Dirac and Pauli Algebras Source: https://github.com/pygae/clifford/blob/master/docs/api/clifford.BladeMap.md Sets up the Dirac and Pauli algebras using the Cl constructor and updates the local namespace with blade definitions. ```python >>> from clifford import Cl >>> # Dirac Algebra `D` >>> D, D_blades = Cl(1, 3, firstIdx=0, names='d') >>> locals().update(D_blades) ``` ```python >>> # 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)]) ``` -------------------------------- ### Import G3C Algebra Source: https://github.com/pygae/clifford/blob/master/examples/g3c.ipynb Initializes the conformal geometric algebra environment. ```python from clifford.g3c import * ``` -------------------------------- ### Get Inverse Pseudoscalar Source: https://github.com/pygae/clifford/blob/master/docs/api/clifford.MultiVector.md Calculate the inverse of the pseudoscalar for the algebra. ```python M.invPS() ``` -------------------------------- ### Get Pseudoscalar of Algebra Source: https://github.com/pygae/clifford/blob/master/docs/api/clifford.MultiVector.md Access the pseudoscalar of the algebra associated with the MultiVector. ```python M.pseudoScalar ``` -------------------------------- ### Initialize 3D Geometric Algebra Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/g3-algebra-of-space.ipynb Import the clifford library and create a 3-dimensional geometric algebra layout and blades. ```python import clifford as cf layout, blades = cf.Cl(3) # creates a 3-dimensional clifford algebra ``` -------------------------------- ### Get Coefficient by Blade Object Source: https://github.com/pygae/clifford/blob/master/docs/api/clifford.MultiVector.md Retrieve the coefficient of a specific blade object. ```python self[e12] ``` -------------------------------- ### Initialize Clifford Algebra Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/euler-angles.ipynb Sets up the 3D Clifford algebra and imports necessary basis elements into the local namespace. ```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 ``` -------------------------------- ### Initialize 2D Geometric Algebra Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/InterfacingOtherMathSystems.ipynb Sets up a 2D geometric algebra environment and imports blades into the local namespace. ```python import clifford as cf layout, blades = cf.Cl(2) # instantiate a 2D- GA locals().update(blades) # put all blades into local namespace ``` -------------------------------- ### Initialize Clifford G3 Environment Source: https://github.com/pygae/clifford/blob/master/examples/g3.ipynb Imports the geometric algebra environment for 3D space. ```python from clifford.g3 import * ``` -------------------------------- ### Get Coefficient by Blade Tuple Source: https://github.com/pygae/clifford/blob/master/docs/api/clifford.MultiVector.md Retrieve the coefficient of a specific blade identified by a tuple of its indices. ```python self[(0, 1)] ``` -------------------------------- ### GET/SET clifford.eps Source: https://github.com/pygae/clifford/blob/master/docs/api/clifford.md Get or set the epsilon value used for float comparisons within the library. ```APIDOC ## GET/SET clifford.eps ### Description Get or set the epsilon value used for float comparisons. ### Method GET/SET ### Endpoint clifford.eps(newEps=None) ### Parameters #### Request Body - **newEps** (float) - Optional - The new epsilon value to set. ``` -------------------------------- ### Perform Complex Number and Spinor Operations Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/InterfacingOtherMathSystems.ipynb Examples of converting, round-tripping, and rotating vectors using complex-spinor mappings. ```python c2s(1+2j) ``` ```python s2c(1+2*e12) ``` ```python s2c(c2s(1+2j)) == 1+2j ``` ```python s = 1+2*e12 e1*s ``` -------------------------------- ### Import G3,1 module Source: https://github.com/pygae/clifford/blob/master/examples/g3_1.ipynb Initializes the geometric algebra environment for the G3,1 space. ```python from clifford.g3_1 import * ``` -------------------------------- ### clifford.Cl Source: https://github.com/pygae/clifford/blob/master/docs/api/clifford.Cl.md Initializes a geometric algebra layout based on signature parameters. ```APIDOC ## clifford.Cl ### Description Returns a Layout and basis blade MultiVectors for the geometric algebra Cl(p,q,r). ### Parameters - **p** (int) - Optional - Number of positive-signature basis vectors. - **q** (int) - Optional - Number of negative-signature basis vectors. - **r** (int) - Optional - Number of zero-signature basis vectors. - **sig** (any) - Optional - Signature configuration; if passed, p, q, and r are ignored. - **names** (any) - Optional - Names for the basis blades. - **firstIdx** (any) - Optional - Starting index for basis blades. ### Response - **layout** (Layout) - The resulting geometric algebra layout. - **blades** (Dict[str, MultiVector]) - The blades of the returned layout. ``` -------------------------------- ### Initialize 2D Clifford Algebra Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/g2-quick-start.ipynb Import the clifford module and instantiate a 2-dimensional algebra layout. ```python import clifford as cf layout, blades = cf.Cl(2) # creates a 2-dimensional clifford algebra ``` -------------------------------- ### Conformalize a Geometric Algebra Source: https://github.com/pygae/clifford/blob/master/docs/api/clifford.conformalize.md Demonstrates how to initialize a base layout, apply conformalization, and unpack the resulting blades and basis vectors into the local namespace. ```pycon >>> from clifford import Cl, conformalize >>> G2, blades = Cl(2) >>> G2c, bladesc, stuff = conformalize(G2) >>> locals().update(bladesc) >>> locals().update(stuff) ``` -------------------------------- ### Construct and apply an OutermorphismMatrix Source: https://github.com/pygae/clifford/blob/master/docs/api/transformations.md Demonstrates creating a transformation matrix that permutes and scales basis vectors, then applying it to multivectors. ```python >>> from clifford import transformations, Layout >>> layout = Layout([1, 1, 1]) >>> e1, e2, e3 = layout.basis_vectors_lst >>> layout_new = Layout([1, 1, 1], names='f') >>> m = np.array([[0, 1, 0], ... [0, 0, 2], ... [3, 0, 0]]) >>> lt = transformations.OutermorphismMatrix(m, layout, layout_new) ``` ```python >>> # the transformation we specified >>> lt(e1), lt(e2), lt(e3) ((3^f3), (1^f1), (2^f2)) >>> # the one deduced by outermorphism >>> lt(e1^e2), lt(e2^e3), lt(e1^e3) (-(3^f13), (2^f12), -(6^f23)) >>> # and by distributivity >>> lt(1 + (e1^e2^e3)) 1 + (6^f123) ``` -------------------------------- ### Get Coefficient by Index (Deprecated) Source: https://github.com/pygae/clifford/blob/master/docs/api/clifford.MultiVector.md Access the coefficient at a specific index in the multivector's value array. This method is deprecated; use `self.value[i]` directly. ```python self[i] ``` -------------------------------- ### Build GanjaScene Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/cga/visualization-tools.ipynb Constructs scenes with geometric objects, colors, and labels. ```python sc = GanjaScene() sc.add_object(point, color=(255, 0, 0), label='point') sc.add_object(line, color=(0, 255, 0), label='line') sc.add_object(circle, color=(0, 0, 255), label='circle') ``` ```python sc_refl = GanjaScene() sc_refl.add_object(point_refl, color=(128, 0, 0), label='point_refl') sc_refl.add_object(line_refl, color=(0, 128, 0), label='line_refl') ``` -------------------------------- ### Create and Translate a Sphere in CGA Source: https://github.com/pygae/clifford/blob/master/docs/api/cga.md Demonstrates creating a conformal geometric algebra space, defining a sphere, and translating it. Requires importing Cl and CGA from clifford. ```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) ``` -------------------------------- ### Initialize 3D Geometric Algebra for Quaternions Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/InterfacingOtherMathSystems.ipynb Configures a 3D geometric algebra with custom names to match standard quaternion notation. ```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) ``` -------------------------------- ### Generate Ordered Integer IDs for Basis Vectors Source: https://github.com/pygae/clifford/blob/master/docs/api/clifford.Layout.md Create a sequence of integer IDs for basis vectors, starting from a specified index. This is used for naming and accessing basis vectors. ```python ids=BasisVectorIds.ordered_integers(2, first_index=1) ``` -------------------------------- ### Conditional Print Statement Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/cga/object-oriented.ipynb A simple conditional statement that checks if '1' is present in a mapped list of integers and prints '3' if true. This snippet is a basic Python control flow example. ```python if 1 in map(int, [1,2]): print(3) ``` -------------------------------- ### Initialize GA with Custom Names Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/g3-algebra-of-space.ipynb Initialize a 2D geometric algebra using `cf.Cl()` and provide custom names for the basis blades. ```python layout, blades = cf.Cl(2, names=['','x','y','i']) blades ``` ```python locals().update(blades) ``` -------------------------------- ### Rotations with Rotors in Clifford Source: https://context7.com/pygae/clifford/llms.txt Use rotors, the GA equivalent of rotation matrices or quaternions, to perform rotations via the sandwich product R*x*~R. This example demonstrates creating a rotor from the exponential of a bivector. ```python from clifford.g3 import * import numpy as np from math import pi ``` -------------------------------- ### Perform geometric algebra operations Source: https://github.com/pygae/clifford/blob/master/examples/g3_1.ipynb Demonstrates multivector creation, projection, and various product operations. ```python # Example a = (2 + 5.7*e2)*(e1 + e4) b = 5*e2 - 3.5*e1 print(a) print(b) # Projection print(a(2)) # Outer product print(a^b) # Inner product print(a|b) # Left contraction print(a.lc(b)) ``` -------------------------------- ### Import Clifford G4 Module Source: https://github.com/pygae/clifford/blob/master/examples/g4.ipynb Initializes the geometric algebra environment for the G4 space. ```python from clifford.g4 import * ``` -------------------------------- ### Import Libraries for Clifford and Numba Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/PerformanceCliffordTutorial.ipynb Import the necessary Clifford, NumPy, and Numba libraries to begin. ```python import clifford as cf import numpy as np import numba ``` -------------------------------- ### Basic Geometric Algebra Products Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/g3-algebra-of-space.ipynb Demonstrates the geometric, inner, and outer products 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 ``` -------------------------------- ### Set Up 3D Euclidean Space in Conformal Framework Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/PerformanceCliffordTutorial.ipynb Configure the Clifford layout for a 3D Euclidean space within the conformal framework (Cl(4,1) algebra). This sets up local variables and defines essential geometric elements. ```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 ``` -------------------------------- ### Create and use rotors for rotations Source: https://context7.com/pygae/clifford/llms.txt Demonstrates creating rotors for rotations in geometric algebra and applying them to vectors. Uses the exponential map for rotor creation and the sandwich product for rotation. ```python from clifford.g3 import * theta = pi / 2 # 90 degrees R = np.exp(-theta/2 * e12) # Note: half-angle print(R) # 0.707 - (0.707^e12) v = e1 v_rotated = R * v * ~R print(v_rotated) # Returns e2 R1 = np.exp(-pi/4 * e12) # 90 deg in xy-plane R2 = np.exp(-pi/4 * e23) # 90 deg in yz-plane R_combined = R2 * R1 # Apply R1 first, then R2 result = R_combined * e1 * ~R_combined print(result) # Rotated vector a = e1 b = e2 R_ab = (1 + b*a).normal() # Rotor rotating a to b print((R_ab * a * ~R_ab).normal()) # Should equal e2 ``` -------------------------------- ### Create Geometric Algebras with Cl Source: https://context7.com/pygae/clifford/llms.txt Use the `Cl` function to create geometric algebras with specified signatures (p,q,r). It returns a Layout object and a dictionary of basis blades. You can also construct custom algebras using a signature list. ```python import clifford as cf # Create a 3D Euclidean algebra Cl(3,0,0) layout, blades = cf.Cl(3) # Access basis vectors and blades e1 = blades['e1'] e2 = blades['e2'] e3 = blades['e3'] e12 = blades['e12'] e123 = blades['e123'] # Or update namespace with all blades at once locals().update(blades) # Create spacetime algebra Cl(1,3) - Minkowski signature sta_layout, sta_blades = cf.Cl(1, 3) # Create algebra with custom signature layout_custom, blades_custom = cf.Cl(sig=[1, 1, -1]) # Output: blades dictionary contains {'': 1, 'e1': e1, 'e2': e2, 'e3': e3, # 'e12': e12, 'e13': e13, 'e23': e23, 'e123': e123} ``` -------------------------------- ### Create Sphere from Points Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/cga/object-oriented.ipynb Demonstrates creating spheres, circles, and point pairs from sets of points using the `cga.round()` method. It also shows how to create random spheres of different dimensions. ```python C = cga.round(e1, e2, -e1, e3) # generates sphere from points C = cga.round(e1, e2, -e1) # generates circle from points C = cga.round(e1, e2) # generates point-pair from points #or C2 = cga.round(2) # random 2-sphere (sphere) C1 = cga.round(1) # random 1-sphere, (circle) C0 = cga.round(0) # random 0-sphere, (point pair) C1.mv # access the multivector ``` -------------------------------- ### Initialize Custom Layout for 2D Space Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/apollonius-cga-augmented.ipynb Creates an instance of the custom layout for 2D Euclidean space. ```python l2 = OurCustomLayout(ndims=2) e1, e2 = l2.basis_vectors_lst[:2] ``` -------------------------------- ### Populate Namespace with Layout Blades Source: https://github.com/pygae/clifford/blob/master/docs/api/clifford.Layout.md Use this to quickly populate the local namespace with variables corresponding to the blades of a given layout. ```pycon >>> locals().update(layout.blades()) ``` -------------------------------- ### Operator Precedence with Outer Products Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/g3-algebra-of-space.ipynb Illustrates the correct usage of parentheses with outer products to ensure proper evaluation order. ```python e1^e2 + e2^e3 # fail, evaluates as ``` ```python (e1^e2) + (e2^e3) # correct ``` -------------------------------- ### Instantiate SerialRobot Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/cga/robotic-manipulators.ipynb Create an instance of the SerialRobot class with specified parameters. This is the first step in defining and manipulating a robot model. ```python serial_robot = SerialRobot(rho=1, l=0.5) ``` -------------------------------- ### Plot Circles and Handle Colinear Cases Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/apollonius-cga-augmented.ipynb Visualizes the computed circles and demonstrates robustness with colinear inputs. ```python plot_rounds([c1, c2, c3], [l2.downs(c4u), l2.downs(c5u)], scale=0.75) ``` ```python c1 = dual_round(-1.5*e1, 0.5) c2 = dual_round(e1*0, 0.5) c3 = dual_round(1.5*e1, 0.5) c4u, c5u = pp_ends((l2.ups(c1) ^ l2.ups(c2) ^ l2.ups(c3)).dual()) plot_rounds([c1, c2, c3], [l2.downs(c4u), l2.downs(c5u)]) ``` ```python c1 = dual_round(-3*e1, 1.5) c2 = dual_round(-2*e1, 1) c3 = -dual_round(2*e1, 1) c4u, c5u = pp_ends((l2.ups(c1) ^ l2.ups(c2) ^ l2.ups(c3)).dual()) plot_rounds([c1, c2, c3], [l2.downs(c4u), l2.downs(c5u)]) ``` -------------------------------- ### Conformalize a Geometric Algebra Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/cga/index.ipynb Initializes a CGA layout from an existing GA layout and inspects the resulting blades and auxiliary structures. ```python from numpy import pi,e from clifford import Cl, conformalize G2, blades_g2 = Cl(2) blades_g2 # inspect the G2 blades ``` ```python G2c, blades_g2c, stuff = conformalize(G2) blades_g2c #inspect the CGA blades ``` ```python stuff ``` -------------------------------- ### Perform reflections using geometric algebra Source: https://context7.com/pygae/clifford/llms.txt Shows how to perform reflections in geometric algebra using the sandwich product with a vector. Reflections are performed across hyperplanes defined by normal vectors. ```python from clifford.g3 import * # Vector to reflect c = e1 + e2 + e3 # Reflect in hyperplane normal to e1 (yz-plane) n = e1 c_reflected = -n * c * n.inv() print(c_reflected) # (-1^e1) + (1^e2) + (1^e3) # Reflect through normalized vector (simpler form) n_unit = e1 # already normalized c_reflected = -n_unit * c * n_unit print(c_reflected) # Reflect in arbitrary plane (defined by normal vector) normal = (e1 + e2).normal() c_reflected = -normal * c * normal print(c_reflected) # Multiple reflections create rotations # Two reflections = rotation by twice the angle between mirrors m1 = e1 m2 = (e1 + e2).normal() R = m2 * m1 # Rotor from two reflections print(R * e1 * ~R) # Rotated vector ``` -------------------------------- ### Combine Conformal Operations Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/cga/index.ipynb Demonstrates chaining translation, scaling, and inversion operations. ```python A = up(a) V = T(e1)*E0*D(2) B = V*A*~V assert(down(B) == (-2*a)+e1 ) ``` ```python A = up(a) V = ep*T(b)*ep C = V*A*~V assert(down(C) ==1/(1/a +b)) ``` -------------------------------- ### Create LinearMatrix from Function Source: https://github.com/pygae/clifford/blob/master/docs/api/transformations.md Build a linear transformation by applying a function to each basis blade. The function should take a basis blade from the source layout and return a multivector in the destination layout. Ensure the layout is correctly defined for the algebra. ```python from clifford import transformations, Layout l = Layout([1, 1]) e1, e2 = l.basis_vectors_lst rot_90 = transformations.LinearMatrix.from_function(lambda x: (1 + e1*e2)*x*(1 - e1*e2)/2, l) rot_90(e1) rot_90(e2) rot_90(e1*e2) ``` -------------------------------- ### Constructor: clifford.Layout Source: https://github.com/pygae/clifford/blob/master/docs/api/clifford.Layout.md Initializes a new Layout object to define the geometric algebra space. ```APIDOC ## class clifford.Layout ### Description Stores information regarding the geometric algebra itself and the internal representation of multivectors. ### Parameters - **sig** (List[int]) - Required - The signature of the vector space (e.g., [+1, -1, -1, -1]). - **ids** (Optional[BasisVectorIds]) - Optional - A list of ids to associate with each basis vector. - **order** (Optional[BasisBladeOrder]) - Optional - A specification of the memory order to use when storing the basis blades. - **names** (List[str]) - Optional - List of names of each blade for pretty-printing. ``` -------------------------------- ### Compare Rotor and Matrix Transformations Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/euler-angles.ipynb Demonstrates applying a rotation to a vector using both a rotor and a matrix. ```python X = e1+2*e2 R*X*~R ``` ```python Xv = np.array([1, 2, 0]) M @ Xv ``` -------------------------------- ### CGA Object Creation Methods Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/cga/object-oriented.ipynb Demonstrates various methods for creating geometric objects like spheres (`round`) and flats, and operations like dilation, translation, and rotation using the CGA object. ```python ## Objects cga.round() # from None cga.round(3) # from dim of space cga.round(e1,e2,e3,-e2) # from points cga.round(e1,e2,e3) # from points cga.round(e1,e2) # from points cga.round((e1,3)) # from center, radius cga.round(cga.round().mv)# from existing multivector cga.flat() # from None cga.flat(2) # from dim of space cga.flat(e1,e2) # from points cga.flat(cga.flat().mv) # from existing multivector ## Operations cga.dilation() # from from None cga.dilation(.4) # from int cga.translation() # from None cga.translation(e1+e2) # from vector cga.translation(cga.down(cga.null_vector())) cga.rotation() # from None cga.rotation(e12+e23) # from bivector cga.transversion(e1+e2).mv ``` -------------------------------- ### Perform Algebraic Operations Source: https://github.com/pygae/clifford/blob/master/examples/g3c.ipynb Demonstrates multivector construction, projection, and various products including outer, inner, and left contraction. ```python # Example a = (2 + 5.7*e2)*(e1 + e3*e4) b = 5*e2 - 3.5*e1 print(a) print(b) # Projection print(a(2)) # Outer product print(a^b) # Inner product print(a|b) # Left contraction print(a.lc(b)) ``` -------------------------------- ### Taylor Expansion Functions Source: https://github.com/pygae/clifford/blob/master/docs/api/taylor_expansions.md API documentation for the mathematical functions implemented via Taylor series expansions in the clifford.taylor_expansions module. ```APIDOC ## clifford.taylor_expansions.exp(x, max_order=15) ### Description Implements the series expansion of exp(x) where x is a multivector. ### Parameters #### Request Body - **x** (multivector) - Required - The multivector input. - **max_order** (int) - Optional - The maximum order of the taylor series to use (default: 15). ## clifford.taylor_expansions.sin(X, max_order=30) ### Description A taylor series expansion for sin. ### Parameters #### Request Body - **X** (multivector) - Required - The multivector input. - **max_order** (int) - Optional - The maximum order of the taylor series to use (default: 30). ## clifford.taylor_expansions.cos(X, max_order=30) ### Description A taylor series expansion for cos. ### Parameters #### Request Body - **X** (multivector) - Required - The multivector input. - **max_order** (int) - Optional - The maximum order of the taylor series to use (default: 30). ## clifford.taylor_expansions.tan(X, max_order=30) ### Description The tan function as the ratio of sin and cos. ### Parameters #### Request Body - **X** (multivector) - Required - The multivector input. - **max_order** (int) - Optional - The maximum order of the taylor series to use (default: 30). ## clifford.taylor_expansions.sinh(X, max_order=30) ### Description A taylor series expansion for sinh. ### Parameters #### Request Body - **X** (multivector) - Required - The multivector input. - **max_order** (int) - Optional - The maximum order of the taylor series to use (default: 30). ## clifford.taylor_expansions.cosh(X, max_order=30) ### Description A taylor series expansion for cosh. ### Parameters #### Request Body - **X** (multivector) - Required - The multivector input. - **max_order** (int) - Optional - The maximum order of the taylor series to use (default: 30). ## clifford.taylor_expansions.tanh(X, max_order=30) ### Description The tanh function as the ratio of sinh and cosh. ### Parameters #### Request Body - **X** (multivector) - Required - The multivector input. - **max_order** (int) - Optional - The maximum order of the taylor series to use (default: 30). ``` -------------------------------- ### Perform Geometric Algebra Operations Source: https://github.com/pygae/clifford/blob/master/examples/g3.ipynb Demonstrates multivector creation, projection, and various product operations including outer, inner, and left contraction. ```python # Example a = (2 + 5.7*e2)*(e1 + e3) b = 5*e2 - 3.5*e1 print(a) print(b) # Projection print(a(2)) # Outer product print(a^b) # Inner product print(a|b) # Left contraction print(a.lc(b)) ``` -------------------------------- ### Profile Rotor Application (Commented Out) Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/PerformanceCliffordTutorial.ipynb A commented-out section for profiling the performance of the `apply_rotor` function using `%prun`. ```python #%%prun -s cumtime #for i in range(1000000): # apply_rotor(R,line_one) ``` -------------------------------- ### Composing Larger Functions with JIT Compilation Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/PerformanceCliffordTutorial.ipynb This section demonstrates composing larger functions by chaining together optimized operations that operate on value arrays. It includes JIT-compiled functions for dual and meet operations. ```python I5_val = I5.value omt_func = layout.omt_func def dual_mv(mv): return -I5*mv def meet_unwrapped(mv_a,mv_b): return -dual_mv(dual_mv(mv_a)^dual_mv(mv_b)) @numba.njit def dual_val(mv_val): return -gmt_func(I5_val,mv_val) @numba.njit def meet_val(mv_a_val,mv_b_val): return -dual_val( omt_func( dual_val(mv_a_val) , dual_val(mv_b_val)) ) def meet_wrapped(mv_a,mv_b): return cf.layout.MultiVector(meet_val(mv_a.value, mv_b.value)) ``` ```python sphere = (up(0)^up(e1)^up(e2)^up(e3)).normal() print(sphere.meet(line_one).normal().normal()) print(meet_unwrapped(sphere,line_one).normal()) print(meet_wrapped(line_one,sphere).normal()) ``` -------------------------------- ### Perform and Print Sparse Meet Operations Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/PerformanceCliffordTutorial.ipynb Demonstrates performing and printing the results of sparse meet operations using both the library's built-in method and the custom Numba-optimized function. Ensure sphere and line_one are defined. ```python print(sphere.meet(line_one).normal().normal()) print(meet_sparse_3_4(line_one,sphere).normal()) ``` -------------------------------- ### BibTeX Citation for All Versions Source: https://github.com/pygae/clifford/blob/master/CITATION.md BibTeX entry for citing all versions of the pygae/clifford library. ```BibTeX @software{python_clifford, author = {Hugo Hadfield and Eric Wieser and Alex Arsenovic and Robert Kern and {The Pygae Team}}, title = {pygae/clifford}, publisher = {Zenodo}, doi = {10.5281/zenodo.1453978}, url = {https://doi.org/10.5281/zenodo.1453978} } ``` -------------------------------- ### JIT-Compiled Rotor Application with Numba Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/PerformanceCliffordTutorial.ipynb Applying Numba's JIT compiler to the value-based rotor application function further improves performance and enables JIT compilation of larger functions that utilize it. ```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)) ``` -------------------------------- ### Create Sphere from Center and Radius Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/cga/object-oriented.ipynb Creates a new sphere object using the `from_center_radius` method, providing the center and radius obtained from an existing sphere. The properties of the new sphere are then displayed. ```python C_ = cga.round().from_center_radius(C.center,C.radius) C_.center,C_.radius ``` -------------------------------- ### Display Settings and Pretty Printing Source: https://context7.com/pygae/clifford/llms.txt Configures multivector output formatting, including precision and floating-point tolerance. ```python import clifford as cf from clifford.g3 import * A = 1.23456789 + 2.3456789*e1 + 0.00001*e2 # Pretty printing (default, human readable) cf.pretty() print(A) # 1.23457 + (2.34568^e1) + (0.0^e2) # Set display precision cf.print_precision(3) print(A) # 1.235 + (2.346^e1) + (0.0^e2) # Ugly mode (eval-able representation) cf.ugly() print(A) # layout.MultiVector([1.23456789, 2.3456789, 0.00001, ...]) # Set floating point comparison tolerance cf.eps(1e-6) # Values smaller than this treated as zero ``` -------------------------------- ### Euclidean to Conformal Mapping in Clifford Algebra Source: https://github.com/pygae/clifford/blob/master/examples/g2c.ipynb Shows how to map points from Euclidean space to conformal space using the 'up' function and then back to Euclidean space using the 'down' function. ```python # Mapping points from euclidean to conformal b_up = up(5*e2 - 3.5*e1) print(b_up) # And back again print( down(b_up) ) ``` -------------------------------- ### Visualize Transformation Matrix with Labeled Axes Source: https://github.com/pygae/clifford/blob/master/docs/tutorials/linear-transformations.ipynb Uses the show_table function to display the `rot_and_scale_x` matrix with input and output axes labeled. This helps in understanding the matrix's effect on vector components. ```python show_table(rot_and_scale_x, ["$\\mathit{in}_%s$" % c for c in "xyz"], ["$\\mathit{out}_%s$" % c for c in "xyz"]) ``` -------------------------------- ### Initialize MultiVector Source: https://github.com/pygae/clifford/blob/master/docs/api/clifford.MultiVector.md Instantiate a MultiVector with a given layout and coefficients. Coefficients can be provided as a sequence or derived from a string representation. The dtype can be specified for numerical precision. ```python from clifford.g2 import * M = 1 + 2*e1 + 3*e12 ``` -------------------------------- ### Multivector Inversion Methods Comparison Source: https://github.com/pygae/clifford/blob/master/docs/issues.md Compares the results of `laInv` (linear algebra based) and `normalInv` (analytic) methods for multivector inversion. `laInv` is generally reliable, while `normalInv` only works when `M*~M` is a scalar. Note that `laInv` can be order-dependent. ```python # M.laInv() * M == 1.0 # M * M.laInv() != 1.0 ``` -------------------------------- ### Taylor Expansions for Transcendental Functions Source: https://context7.com/pygae/clifford/llms.txt Implements Taylor series for exponential, trigonometric, and hyperbolic functions on multivectors. ```python from clifford.g3 import * import clifford.taylor_expansions as te import numpy as np # Exponential of multivector B = np.pi/4 * e12 R = te.exp(B) print(R) # Rotor: cos(pi/4) + sin(pi/4)*e12 # Can also use np.exp or method syntax R2 = np.exp(B) R3 = B.exp() # Trigonometric functions angle = np.pi/6 * e12 print(te.sin(angle)) # sin of bivector print(te.cos(angle)) # cos of bivector print(te.tan(angle)) # tan of bivector # Hyperbolic functions print(te.sinh(e12)) print(te.cosh(e12)) print(te.tanh(e12)) # Method syntax also works print((np.pi/3 * e12).sin()) print((np.pi/3 * e12).cos()) # Specify precision with max_order parameter precise_exp = te.exp(e12, max_order=30) ```