Systematic dimensional analysis audit on all equations in a derivation or phase
Codex shell compatibility:
gpd on PATH.GPD_ACTIVE_RUNTIME=codex uv run gpd ....
</codex_runtime_notes><codex_questioning>
Dimensional analysis is the cheapest and most powerful diagnostic in physics. It catches ~30% of errors at near-zero cost. This command applies it systematically rather than ad hoc.
Why a dedicated command: Dimensional analysis is often done informally -- "looks right" -- but rigorous tracking through multi-step derivations catches errors that informal checks miss. A factor of hbar dropped on line 12 of a derivation propagates silently until the final answer is off by orders of magnitude. </objective>
<context> Target: $ARGUMENTS </context> <!-- [included: dimensional-analysis.md] --> <purpose> Perform a systematic dimensional analysis audit on every equation in a derivation, computation, or phase. Track dimensions through all algebraic steps, verify consistency, and flag any dimensional anomalies. <process>Interpretation:
Load unit system:
cat .gpd/research-map/FORMALISM.md 2>/dev/null | grep -A 10 "Unit System"
cat .gpd/research-map/FORMALISM.md 2>/dev/null | grep -A 20 "Notation and Conventions"
<execution_context>
Called from $gpd-dimensional-analysis command. Produces DIMENSIONAL-ANALYSIS.md report.
Dimensional analysis is the cheapest and most powerful diagnostic in physics. It catches ~30% of errors at near-zero cost. This workflow applies it systematically rather than ad hoc. </purpose>
Load project state and conventions to determine the unit system:
INIT=$(/home/qol/.gpd/venv/bin/python -m gpd.runtime_cli --runtime codex --config-dir ./.codex --install-scope local init phase-op --include state,config)
if [ $? -ne 0 ]; then
echo "ERROR: gpd initialization failed: $INIT"
# STOP — display the error to the user and do not proceed.
fi
state_exists: true): Extract convention_lock, especially units and natural_units settings. Extract active approximations for context on what dimensions are independent.state_exists is false (standalone usage): Proceed — the unit system will be established explicitly in Step 1 via ask_user.The convention_lock unit system setting (natural units, SI, CGS, etc.) directly determines which dimensions are independent and what the dimensional assignments table looks like.
Convention verification (if project exists):
CONV_CHECK=$(/home/qol/.gpd/venv/bin/python -m gpd.runtime_cli --runtime codex --config-dir ./.codex --install-scope local --raw convention check 2>/dev/null)
if [ $? -ne 0 ]; then
echo "WARNING: Convention verification failed — unit system may be inconsistent"
echo "$CONV_CHECK"
fi
Dimensional analysis results depend critically on the unit system. In natural units (hbar=c=1), energy and mass have the same dimension; in SI they don't. A convention mismatch here invalidates the entire analysis.
Before checking any equations, establish the unit system in use.
Ask the user once using a single compact prompt block if not found in project files:
Build dimensional lookup table:
## Dimensional Assignments
| Quantity | Symbol | Dimensions (natural) | Dimensions (SI) |
| ------------------ | ------ | -------------------- | ----------------- |
| Energy | E | [E] | [M L^2 T^{-2}] |
| Momentum | p | [E] | [M L T^{-1}] |
| Position | x | [E^{-1}] | [L] |
| Time | t | [E^{-1}] | [T] |
| Mass | m | [E] | [M] |
| Wavefunction (3D) | psi | [E^{3/2}] | [L^{-3/2}] |
| Action | S | [1] | [M L^2 T^{-1}] |
| Lagrangian density | L | [E^4] | [M L^{-1} T^{-2}] |
| {project-specific} | ... | ... | ... |
Scan target for all equations:
# LaTeX equations
grep -n "\\\\begin{equation\|\\\\begin{align\|\\\\begin{eqnarray\|\\$\\$\|\\\\\\[" "$TARGET_FILE" 2>/dev/null
# Python expressions with physics content
grep -n "=.*\(np\.\|scipy\.\|sympy\.\|integrate\|solve\|eigenval\)" "$TARGET_FILE" 2>/dev/null
# Mathematica expressions
grep -n "=.*\(Integrate\|Solve\|DSolve\|Eigenvalues\)" "$TARGET_FILE" 2>/dev/null
Number each equation for tracking.
For every equation, perform the following checks:
For each term in each equation:
For every transcendental function (exp, log, sin, cos, erf, Bessel, etc.):
For every power law (x^n where n is not integer):
For every integral:
For every derivative:
Dirac delta function delta(x) has dimensions [x]^{-1}:
Verify everywhere delta functions appear.
For tensor equations:
For multi-step derivations, track dimensions through the chain:
Step 1: [LHS] = [A] + [B] Check: [A] == [B]
Step 2: [LHS'] = [f(LHS)] Check: dimensions propagate correctly through f
Step 3: [Result] = [LHS'] * [C] Check: [Result] has expected final dimensions
Flag the first step where dimensions become inconsistent -- this is likely where the error was introduced.
If working in natural units, restore factors of hbar, c, k_B explicitly for at least the final result:
The action S must be dimensionless in natural units (or have dimensions [M L^2 T^{-1}] = [hbar] in SI):
The partition function Z = Tr(e^{-beta H}) must be dimensionless:
Probabilities and probability densities:
Write DIMENSIONAL-ANALYSIS.md:
---