Algebraic Operations¶
TriadicGPT provides eight algebraic operations over prime-factor signatures. All are O(1) via bitwise arithmetic.
Cosine Similarity vs Prime Algebra¶
| Operation | Cosine Similarity | Prime Algebra |
|---|---|---|
| "Does A contain all features of B?" | Approximate | phi(A) % phi(B) == 0 |
| "What features do A and B share?" | Not possible | gcd(phi(A), phi(B)) |
| "Combine features of A and B" | Not possible | lcm(phi(A), phi(B)) |
| "A is to B as C is to ?" | Approximate | Exact factor transfer |
| Explainability | Black box | Full factor decomposition |
The Eight Operations¶
Subsumption¶
Does concept A contain all semantic features of concept B?
\[A \subseteq B \iff \Phi(A) \bmod \Phi(B) = 0\]
from triadic_head.algebra import TriadicValidator
validator = TriadicValidator()
print(validator.subsumes(phi_dog, phi_animal))
# --> True (dog contains all features of animal)
Composition¶
Create a new concept with all features of both A and B:
\[A \cup B = \text{lcm}(\Phi(A), \Phi(B))\]
composed = validator.compose(phi_king, phi_female)
# --> Integer containing all factors of king AND female
Intersection¶
Find the features shared by A and B:
\[A \cap B = \gcd(\Phi(A), \Phi(B))\]
shared = validator.intersection(phi_king, phi_queen)
# --> Integer whose factors are the features they share
Difference¶
Features present in A but not in B:
\[A \setminus B = \Phi(A) / \gcd(\Phi(A), \Phi(B))\]
unique_to_king = validator.difference(phi_king, phi_queen)
# --> Factors that king has but queen lacks
Symmetric Difference¶
Features present in exactly one of A or B:
\[A \triangle B\]
sym_diff = validator.symmetric_difference(phi_king, phi_queen)
# --> Factors unique to either king or queen (but not both)
Gap Analysis¶
Complete breakdown of shared and unique features:
gap = validator.gap_analysis(phi_king, phi_queen)
# --> {
# 'shared': gcd,
# 'only_in_a': factors unique to king,
# 'only_in_b': factors unique to queen,
# 'a_contains_b': bool,
# 'b_contains_a': bool
# }
Analogy Prediction¶
Solve A:B :: C:? via algebraic factor transfer:
predicted = validator.analogy_predict(phi_king, phi_queen, phi_man)
# --> Predicted prime composite for "woman"
Analogy Verification¶
Verify whether D is a valid solution to A:B :: C:D:
is_valid = validator.analogy_verify(phi_king, phi_queen, phi_man, phi_woman)
# --> True/False
Using with TriadicWrapper¶
The compare method on TriadicWrapper provides a high-level interface:
from triadic_head import TriadicWrapper
model = TriadicWrapper("gpt2", n_bits=64, align_mode="infonce")
sigs = model.encode(["king", "queen", "man", "woman"])
# Compare returns similarity + shared factors + subsumption
result = model.compare("king", "queen")
print(result)
# {'similarity': 0.89, 'shared_factors': [2, 3, 5, ...],
# 'subsumes': False, 'subsumed_by': False}
Performance¶
All operations are implemented via bitwise arithmetic, achieving 5--78x speedup over naive prime factorization:
| Operation | Bitwise | Prime arithmetic |
|---|---|---|
| Subsumption | AND + compare | mod |
| Composition | OR | lcm |
| Intersection | AND | gcd |
| Difference | AND NOT | div + gcd |