Open the context
Choose the project folder and name the files or behavior involved.
Multiply two four-component Hamilton quaternions in scalar-first order with finite components bounded by ±10^6. Test identity and reversed basis products, rejecting Boolean components without silently normalizing inputs or claiming unit rotations.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
import math
def quaternion_product(a, b):
for q in (a, b):
if type(q) not in (list, tuple) or len(q) != 4:
raise ValueError("quaternion.shape")
if any(type(x) not in (int, float) or not -10**6 <= x <= 10**6 or not math.isfinite(x) for x in q):
raise ValueError("quaternion.value")
w, x, y, z = a
v, i, j, k = b
return (w*v-x*i-y*j-z*k, w*i+x*v+y*k-z*j,
w*j-x*k+y*v+z*i, w*k+x*j-y*i+z*v)
The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.