Abstract

This notebook extends the Relativity Toolkit (v1.11.0) to basic Abelian scalar gauge theory. We implement a generalized covariant derivative operator that simultaneously processes spacetime geometry and internal phase geometry. We demonstrate this implementation through four automated computational proofs:
◼
  • Metric Compatibility: the Levi-Civita connection uniquely nulls the gradient of the metric (
    ∇g=0
    )
  • ◼
  • U(1)
    Gauge Covariance: the covariant derivative of a scalar field transforms covariantly under local phase rotation.
  • ◼
  • Field Strength Invariance: the electromagnetic tensor
    F
    μν
    ​ is invariant under local gauge transformations.
  • ◼
  • Charged Vector Field Covariance: the covariance of a generic charged vector field
    α
    V
    transforms covariantly under simultaneous spacetime coordinate changes and internal
    U(1)
    phase rotations.
  • Finally, we apply the updated engine to re-derive the Riemann curvature tensor from the torsion-free commutator of covariant derivatives.

    Initialize the Relativity Toolkit

    Optional: Quit for a Fresh Kernel

    ◼
  • Note, if you call Quit in a notebook, evaluation may hang. If you want to “Evaluate Notebook,” mark the following two cells “Evaluatable” in the Cell
    ->
    Property menu, call Quit and FrontEndTokenExecute once each, then comment out the cells, or mark them unevaluatable again. Alternatively, you can quit the kernel via the Evaluation menu (last item). At that point, you can “Evaluate Notebook” in a clean environment, or evaluate cells individually.
  • Quit[];
    In[]:=
    FrontEndTokenExecute["DeleteGeneratedCells"]

    Download the Code

    In[]:=
    RTbranch="v1.11.0";​​RTbase="https://raw.githubusercontent.com/rebcabin/RelativityToolkit/"<>RTbranch<>"/";​​RTbust="?t="<>ToString[Round[AbsoluteTime[]]];(*Forcefreshdownload*)​​RTrules=RTbase<>"RelativityToolkit.wl"<>RTbust;​​RTtests=RTbase<>"RelativityToolkit_RegressionTests.wl"<>RTbust;​​RTviz=RTbase<>"RelativityToolkit_VisualShowcase.wl"<>RTbust;​​Get[RTrules];
    »
    Relativity Toolkit version :1.11.0
    »
    Relativity Connection Symbol :Γ

    Optional: See all Tests and Results from Prior Works

    Make any of the following cells evaluatable if you wish. They’re unevaluatable by default to keep this notebook trim.
    In[]:=
    Get[RTtests];
    In[]:=
    Get[RTviz](*nosemicolon,onpurpose*)
    In[]:=
    Get[RTbase<>"covariant_derivative.wl"]
    In[]:=
    Get[RTbase<>"law_of_gamma.wl"]
    In[]:=
    Get[RTbase<>"connections_to_christoffels.wl"]
    Get[RTbase<>"schwarzschild_from_scratch.wl"]

    Introduction

    In physics, choosing a coordinate system or a phase reference is “setting a gauge.” Changing this choice—whether transforming spacetime coordinates or shifting the phase of a field—often introduces inhomogeneous terms when taking partial derivatives.
    Connection fields arise to maintain covariance of the physics under such transformations. In general relativity, the Levi-Civita connection (Christoffel symbols) corrects for the curvature of spacetime coordinates. In electrodynamics, the vector potential
    μ
    A
    ​ acts as the connection, correcting for local variations in the phase reference.
    While apparent forces (like centrifugal and Coriolis) can be eliminated globally by choosing a specific inertial gauge, fundamental forces (like tidal gravity and electromagnetism) arise from the intrinsic curvature of these connections and cannot be globally gauged away.

    Covariance and Internal Gauge

    To see how a connection restores covariance, consider a scalar matter field ψ subjected to a local
    U(1)
    phase change
    Λ(
    μ
    x
    )
    :
    ψ
    =
    qΛ
    
    ψ
    (
    1
    )
    where
    q
    is a constant charge. The ordinary partial derivative produces an inhomogeneous term via the product and rules:
    ∂
    μ
    ψ
    =
    qΛ
    
    (
    ∂
    μ
    ψ+q(
    ∂
    μ
    Λ)ψ)
    (
    2
    )
    The inhomogeneous term
    q(
    ∂
    μ
    Λ)ψ
    breaks covariance. To restore it, introduce a gauge covariant derivative. As with general relativity, add a correction to the partial derivative
    D
    μ
    ψ≡
    ∂
    μ
    ψ-q
    A
    μ
    ψ
    (
    3
    )
    Requiring the connection to transform as
    A
    μ
    =
    A
    μ
    +
    ∂
    μ
    Λ
    (
    4
    )
    gives us an operator
    D
    μ
    that transforms covariantly with gauge, just as
    ∇
    μ
    transforms covariantly with coordinates in relativity:
    D
    μ
    ψ
    =
    ∂
    μ
    ψ
    -q
    A
    μ
    ψ
    =​​
    qΛ
    
    (
    ∂
    μ
    ψ+q(
    ∂
    μ
    Λ)ψ)-q(
    A
    μ
    +
    ∂
    μ
    Λ)
    qΛ
    
    ψ=​​
    qΛ
    
    (
    ∂
    μ
    ψ-q
    A
    μ
    ψ)=​​
    qΛ
    
    D
    μ
    ψ
    (
    5
    )

    Internal Gauge Spaces in the  Calculus

    In general relativity, we take covariant derivatives of tensors inhabiting the tangent spaces of a curved manifold. The connection Γ accounts for the twisting of basis vectors.
    In gauge theories like electrodynamics, the connections operate on internal spaces (such as the U(1) phase) attached, extrinsically to the spacetime itself, to each point in spacetime. The objective of this notebook is to update the  calculus to compute derivatives for objects that possess both spacetime indices and internal gauge charges simultaneously.

    Covariant Derivatives, Revisited

    In GR, the canonical example is the covariant derivative of an arbitrary contravariant vector
    μ
    A
    with respect geometrical coordinates:
    In[]:=
    With[{example=HoldForm[CD[A[[μ]],x[[ν]]]]},​​Echo[TensorForm@@example,example""]];
    »
    
    A
    μ
    ​
    ;ν
    
    A
    μ
    ​
    ,ν
    +(A
    λ
    ​
    )
    μ
    Γ
    νλ
    The connection coefficients Γ account for twisting and turning of basis vectors in the tangent spaces as the vector
    μ
    A
    is parallel-transported geometrically. In GR, this twisting and turning causes geodesics to converge or diverge, thus causing tidal forces. Twisting and turning also drives single geodesics, giving rise to orbits, gravitational lensing, gravitational waves, and so on.
    ◼
  • Emphasis: Geodesic deviation is indistinguishable from tidal force. It’s not an apparent force: its numerical values may depend on gauge choice, but we can’t get rid of it globally by gauge choice.
  • The derivative above transforms like a tensor, ensuring physics is locally Lorentz invariant. This invariance invites Noether’s theorem again, implying a conserved quantity. In GR, this conserved quantity is spin current, from symmetries of non-coordinate bases or tetrads (see the Appendix).

    A New CD

    The following new overload of CD computes covariant derivatives for Abelian (commutative) gauges like scalar phase. We’ll get to non-Abelian gauges like
    SO(3)
    and
    SU(2)
    in future notebooks.

    Gauge Covariant Derivative

    Inputs

    1
    .
    expr: The field being differentiated, scalar or tensor
    2
    .
    var: the coordinate function, e.g., x[[μ]], the differentiation variable
    3
    .
    q: the coupling constant or “charge”
    4
    .
    A: the gauge-field connection symbol. Γ is kept implicitly as the spacetime connection for all theories.
    In[]:=
    CD[expr_,var_,q_,A_]:=​​Module[{gravitationalPart,gaugeCorrection,idx},​​(*GetcoordinatecovariantderivativeviaexistingCDoverloads.*)​​(*∂+Christoffels(ifexprisatensor)*)​​(*Ifexprisascalar,justreturn∂.*)​​gravitationalPart=CD[expr,var];​​(*Extracttheindexfromthedifferentiationvariable.*)​​(*varissomex[[μ]];weneedμ*)​​idx=var[[1,1]];​​(*Constructthegaugecorrection,e.g.,-iq
    A
    μ
    *expr*)​​(*Note:ThisAhasaDOWN(Covariant)indexmatchingthederivative*)​​gaugeCorrection=-I*q*A[[idx]]*expr;​​(*Add*)​​gravitationalPart+gaugeCorrection];

    Electrodynamics Demos

    Covariance of the Covariant Derivative

    Above, we subjected ψ to gauge transformation manually. Automat that calculation:
    In[]:=
    (cde=CD[ψ,x[[μ]],q,A])
    Out[]=
    -qψ(A
    ​
    μ
    )+
    ψ
    ,μ
    Starting with the gauge transformations
    ψ
    =
    iqΛ
    
    ψand
    A
    μ
    =
    A
    μ
    +
    ∂
    μ
    Λ
    In[]:=
    gaugeTransforms=​​ψ->
    qΛ
    
    ψ,​​A[[μ_]]:>A[[μ]]+Partials[Λ,x[[μ]]]
    Out[]=
    ψ
    qΛ
    
    ψ,A
    ​
    μ_
    A
    ​
    μ
    +
    Λ
    ,μ
    
    prove that the covariant derivative
    D
    μ
    ψ≡
    ∂
    μ
    ψ-iq
    A
    μ
    ψ
    transforms exactly as does ψ
    D
    μ
    ψ
    =
    iqΛ
    
    D
    μ
    ψ
    Need one rule for the charge constant. Everything else is already in the toolkit’s differentiationRules:
    In[]:=
    constantRules={Partials[q,x[[μ_]]]:>0}
    Out[]=
    {
    q
    ,μ_
    0}
    In[]:=
    transformedCde=(cde/.gaugeTransforms//.differentiationRules/.constantRules)//Expand//Simplify
    Out[]=
    qΛ
    
    (-qψ(A
    ​
    μ
    )+
    ψ
    ,μ
    )
    In[]:=
    transformedCde===
    qΛ
    
    cde
    Out[]=
    True
    QED ■

    Invariance of the Field-Strength Tensor

    The field-strength tensor,
    F
    μν
    , aka Faraday, is defined as follows
    In[]:=
    F[μ,ν]=Partials[A[[ν]],x[[μ]]]-Partials[A[[μ]],x[[ν]]]
    Out[]=
    -
    A
    ​
    μ
    ,ν
    +
    A
    ​
    ν
    ,μ
    Now, subject it to the gauge transform:
    See that it doesn’t change by invoking the toolkit’s ExpandDerivatives:
    QED ■

    Charged Vector Field Covariance Demo

    Proceed just as above:
    QED ■

    Geometrical GR Demos

    Geometrical Covariant Derivative of a Scalar Function Λ

    equal to its ordinary partial derivative, rendered in comma notation
    equal to its partial derivative plus the correction proportional to the geometrical connection Γ
    now we get two corrections, one for each index
    ditto, with a sign change

    Geometrical Covariant Derivative of the Covariant Metric

    Two negative signs, one for each covariant index
    ◼
  • Christoffel symbols were derived in Covariant Derivatives and Connections in the  Calculus, assuming both torsion freedom (symmetry in lower two indices of Γ), and metric compatibility.
  • We do not develop this case further in this notebook.
    For pedagogy, clear the definitions loaded from the toolkit:
    Start with the covariant derivative of the metric, cdg, from above
    Fetch the Levi-Civita connection via a new ruleLeviCivita, added to Relativity Toolkit v1.9.0:
    In cdg, replace Γ with its definition via this rule, then Expand to expose terms to further processing
    Now consider the following new metricDifferentiationRules in the toolkit:
    They include
    QED ■

    Riemann Revisited

    Here is a concise derivation of the Fundamental Theorem of Riemannian Geometry, shorter than the derivation in our earlier notebooks
    Simplification Pipeline
    QED ■

    Appendix: Spin Connection as Gravitational Gauge

    To formulate gravitation as a strict gauge theory functionally equivalent to the Standard Model forces, one must identify the conserved currents corresponding to local gauge symmetries. The definitive literature demonstrates how this is achieved:
    ◼
  • Friedrich W. Hehl et al., General Relativity with Spin and Torsion: Foundations and Prospects (Rev. Mod. Phys. 48, 393, 1976)
  • which shows that:
    ◼
  • Invariance under general transformations (diffeomorphisms), implies conservation of the energy-momentum tensor.
  • ◼
  • Invariance under local Lorentz transformations implies conservation of the spin angular momentum tensor (the spin current).
  • ◼
  • Standard Einstein GR with vanishing torsion, which we assumed in this series of notebooks, collapses the two symmetries and hides the independent spin current.
  • Some other references are
    ◼
  • Sean Carroll, Spacetime and Geometry: An Introduction to General Relativity
  • ◼
  • Also see Hehl above, Equation 3.8 and Sections III.B and III.C. In other references, this may be called Belinfante-Rosenfeld symmetrization.
  • ◼
  • T. W. B. Kibble, Lorentz Invariance and the Gravitational Field (J. Math. Phys. 2, 212, 1961)
  • ◼
  • Foundational paper deriving gravitation as the gauge theory of the Poincaré group, i.e., translations + Lorentz
  • Kibble shows that (1) gauging translations in Poincaré yields the tetrad field, defining the metric and conserving energy-momentum, and that (2) gauging the Lorentz boost+rotation subgroup yields the spin connection, permitting transformation of spinors, otherwise impossible.

    Conclusion

    References

    1
    .
    Beckman, Brian. From the steam age to quantum fields: a unified approach via UD tensorial calculus. Wolfram Community post.
    2
    .
    Beckman, Brian. General relativity in the UD calculus. Wolfram Community post.
    3
    .
    Beckman, Brian. Formal Differential Geometry in the UD Calculus: Part 1. Wolfram Community post.
    4
    .
    Beckman, Brian. Covariant Derivatives and Connections in the  Calculus. Wolfram Community post.
    5
    .
    Beckman, Brian. Riemann Curvature in  + Compiler POC. Wolfram Community post.
    6
    .
    Beckman, Brian. Schwarzschild Orbits in the  Calculus. Wolfram Community post.
    7
    .
    Beckman, Brian. Schwarzschild Metric from Scratch via  Compilation. Wolfram Community post (to appear).
    8
    .
    Wolfram Function Repository. MetricTensor. For component-based calculations.
    9
    .
    Wolfram Function Repository. ChristoffelSymbol. For component-based calculations.
    10
    .
    [MTW] Misner, Charles W.; Thorne, Kip S.; Wheeler, John Archibald. Gravitation. Princeton University Press, 2017.
    11
    .
    Sean Carroll, Spacetime and Geometry: An Introduction to General Relativity. Cambridge University Press, 2019.
    12
    .
    Friedrich W. Hehl et al., General Relativity with Spin and Torsion: Foundations and Prospects (Rev. Mod. Phys. 48, 393, 1976)
    13
    .
    T. W. B. Kibble, Lorentz Invariance and the Gravitational Field (J. Math. Phys. 2, 212, 1961)
    14
    .
    Sciama, D. W., On the analogy between charge and spin in general relativity. In: Recent Developments in General Relativity, p. 415. Pergamon, New York, 1962.

    CITE THIS NOTEBOOK

    Gauge theory in 
    by Brian Beckman​
    Wolfram Community, STAFF PICKS, February 23, 2026
    https://community.wolfram.com/groups/-/m/t/3643786