# QuatE and DualE Mathematical Formulations

## QuatE (Quaternion Knowledge Graph Embeddings)

### Mathematical Formulation

QuatE represents entities and relations as quaternions in 4D space. For a given triplet (h,r,t):

1. Head entity h and tail entity t are represented as quaternions:
   - Qh = ah + bhi + chj + dhk
   - Qt = at + bti + ctj + dtk

2. Relation r is represented as a quaternion:
   - Wr = ar + bri + crj + drk

3. The scoring function is defined as:
   ```
   φ(h,r,t) = Q'h · Qt
   ```
   where Q'h is the result of Hamilton product between Qh and normalized Wr:
   ```
   Q'h = Qh ⊗ W̄r
   ```

4. The Hamilton product expands to:
   ```
   Q'h = (ah ◦ p - bh ◦ q - ch ◦ u - dh ◦ v) +
        (ah ◦ q + bh ◦ p + ch ◦ v - dh ◦ u)i +
        (ah ◦ u - bh ◦ v + ch ◦ p + dh ◦ q)j +
        (ah ◦ v + bh ◦ u - ch ◦ q + dh ◦ p)k
   ```

## DualE (Dual Quaternion Knowledge Graph Embeddings)

### Mathematical Formulation

DualE extends QuatE by using dual quaternions, combining both rotation and translation in a unified framework.

1. Entities and relations are represented as dual quaternions:
   ```
   Q = a + bε
   ```
   where:
   - a = a0 + a1i + a2j + a3k (real quaternion)
   - b = b0 + b1i + b2j + b3k (dual quaternion)
   - ε is the dual unit where ε² = 0

2. For a triplet (h,r,t), the scoring function is:
   ```
   φ(h,r,t) = ⟨Q'h, Qt⟩
   ```
   where:
   - Q'h is the result of dual quaternion multiplication between Qh and normalized Wr
   - ⟨·,·⟩ denotes the dual quaternion inner product

3. The normalized relation dual quaternion W̄r is computed as:
   ```
   W̄r = (c', d̄)
   c' = c/||c||
   d̄ = d - ((d,c)/(c,c))c
   ```
