Use when working with SageMath for mathematical computations, algebraic geometry, or number theory
Work with canonical mathematical objects, not manual constructions. SageMath provides rich algebraic structures—use them.
Never construct objects manually when canonical alternatives exist:
# ❌ BAD: Manual matrix/vector construction
M = matrix([[2, -1], [-1, 2]])
v = vector([1, 2, 3])
# ✅ GOOD: Use canonical objects from algebraic structures
R = RootSystem(['A', 2])
L = R.weight_lattice()
alpha = L.simple_roots()
Never test against hardcoded values:
# ❌ BAD: Testing specific values
assert result == 42
if gram[0][1] == -1:
...
# ✅ GOOD: Test mathematical properties
assert alpha[1].inner_product(alpha[2]) == -1
assert M.is_positive_definite()
Principle: Manual constructions hide mathematical meaning. Canonical objects encode structure, enable verification, and make code self-documenting.
NEVER create matrices like matrix([[1,2],[3,4]]). Always use SageMath's built-in objects:
# ❌ BAD: Manual construction
M = matrix([[2, -1, 0], [-1, 2, -1], [0, -1, 2]])
# ✅ GOOD: Canonical objects
R = RootSystem(['A', 3]) # Root system
W = WeylGroup(['B', 4]) # Weyl group
C = CartanMatrix(['E', 8]) # Cartan matrix
L = R.root_lattice() # Lattice from SageMath
Use well-known mathematical objects from literature. Reference standard sources:
# ✅ GOOD: Canonical objects with citations
R = RootSystem(['E', 8])
L = R.root_lattice()
assert len(L.roots()) == 240 # E8 has exactly 240 roots (Conway & Sloane)
# ✅ GOOD: Cite the mathematical fact
W = WeylGroup(['A', 2])
assert W.order() == 6 # |W(A2)| = 3! = 6 (Humphreys)
References: Conway & Sloane, Humphreys, Bourbaki, etc.
Every assertion must be mathematically verifiable with clear documentation:
# Mathematical assertion: [What property is being tested]
# sage: R = RootSystem(['E', 8])
# sage: L = R.root_lattice()
# sage: len(L.roots())
# 240 # E8 has exactly 240 roots (Conway & Sloane)
Format: