feynlag 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. feynlag/__init__.py +138 -0
  2. feynlag/anomalies.py +247 -0
  3. feynlag/charges.py +528 -0
  4. feynlag/conventions.py +35 -0
  5. feynlag/dirac.py +640 -0
  6. feynlag/export/__init__.py +3 -0
  7. feynlag/export/latex.py +88 -0
  8. feynlag/export/ufo/__init__.py +9 -0
  9. feynlag/export/ufo/legs.py +146 -0
  10. feynlag/export/ufo/lorentz_map.py +62 -0
  11. feynlag/export/ufo/pycode.py +73 -0
  12. feynlag/export/ufo/static.py +325 -0
  13. feynlag/export/ufo/vvvv.py +238 -0
  14. feynlag/export/ufo/writer.py +643 -0
  15. feynlag/fields.py +358 -0
  16. feynlag/flavor.py +100 -0
  17. feynlag/gauge_basis.py +196 -0
  18. feynlag/groups/__init__.py +6 -0
  19. feynlag/groups/base.py +67 -0
  20. feynlag/groups/discrete.py +239 -0
  21. feynlag/groups/gauge.py +103 -0
  22. feynlag/groups/sun.py +394 -0
  23. feynlag/invariance.py +345 -0
  24. feynlag/lagrangian.py +560 -0
  25. feynlag/models.py +307 -0
  26. feynlag/operators.py +154 -0
  27. feynlag/parameters.py +241 -0
  28. feynlag/pheno/__init__.py +77 -0
  29. feynlag/pheno/amplitudes.py +181 -0
  30. feynlag/pheno/calculator.py +410 -0
  31. feynlag/pheno/diagrams.py +446 -0
  32. feynlag/pheno/epsilon.py +230 -0
  33. feynlag/pheno/integrate.py +78 -0
  34. feynlag/pheno/kinematics.py +361 -0
  35. feynlag/pheno/loop.py +175 -0
  36. feynlag/pheno/lorentz.py +214 -0
  37. feynlag/pheno/offshell.py +165 -0
  38. feynlag/pheno/particles.py +184 -0
  39. feynlag/pheno/propagator.py +90 -0
  40. feynlag/pheno/scattering.py +173 -0
  41. feynlag/pheno/trace.py +105 -0
  42. feynlag/pheno/vertices.py +220 -0
  43. feynlag/suggest.py +714 -0
  44. feynlag/vacuum/__init__.py +20 -0
  45. feynlag/vacuum/diagonalize.py +356 -0
  46. feynlag/vacuum/ewsb.py +79 -0
  47. feynlag/vacuum/masses.py +145 -0
  48. feynlag/vacuum/tadpoles.py +64 -0
  49. feynlag/verify/__init__.py +18 -0
  50. feynlag/verify/checks.py +134 -0
  51. feynlag/verify/ufo_roundtrip.py +146 -0
  52. feynlag/vertices/__init__.py +11 -0
  53. feynlag/vertices/bilinear.py +584 -0
  54. feynlag/vertices/extract.py +136 -0
  55. feynlag/vertices/vertex.py +168 -0
  56. feynlag/vertices/yangmills.py +144 -0
  57. feynlag-0.1.0.dist-info/METADATA +183 -0
  58. feynlag-0.1.0.dist-info/RECORD +61 -0
  59. feynlag-0.1.0.dist-info/WHEEL +5 -0
  60. feynlag-0.1.0.dist-info/licenses/LICENSE +21 -0
  61. feynlag-0.1.0.dist-info/top_level.txt +1 -0
feynlag/__init__.py ADDED
@@ -0,0 +1,138 @@
1
+ """feynlag — tree-level Feynman rules from BSM Lagrangians in pure SymPy."""
2
+
3
+ __version__ = "0.1.0"
4
+
5
+ from .conventions import METRIC_SIGNATURE, SQRT2, tidy
6
+ from .dirac import (
7
+ DiracC, DiracGamma, DiracGammaLower, MetricTensor, dirac0, diracC, diracI,
8
+ diracPL, diracPR, dirac_conjugate, gamma_simplify, majorana_symmetry_sign,
9
+ minkowski_metric,
10
+ )
11
+ from .operators import (
12
+ D_linear, Dmu, PartialMu, expand_derivatives, momentum, to_momentum_space,
13
+ )
14
+ from .vertices import (
15
+ extract_interaction_coefficients, feynman_rule, vertex_multiplicity,
16
+ )
17
+ from .vertices.vertex import LORENTZ_CATALOG, Vertex, classify_spins
18
+ from .vertices.yangmills import (
19
+ cubic_couplings, quartic_couplings, structure_constants,
20
+ )
21
+ from .vacuum.masses import gauge_mass_matrix
22
+ from .verify import (
23
+ UFORoundTripReport, check_dimension, is_hermitian, is_symmetric,
24
+ numeric_equal, round_trip_reconstruct, seesaw_light_mass,
25
+ verify_ufo_numeric,
26
+ )
27
+ from .export import latex_feynman_table
28
+ from .parameters import (
29
+ ExternalParameter, InternalParameter, Parameter, ParameterSet,
30
+ )
31
+ from .groups import SU2, SU3, SUN, U1, S3, ZN, DiscreteSymmetry, GaugeGroup
32
+ from .fields import (
33
+ DiracFermion, Field, Fermion, GaugeBoson, MajoranaFermion, Scalar,
34
+ WeylFermion, bar_partner, conjugate_pair, dag, hc,
35
+ )
36
+ from .vacuum import (
37
+ MajoranaRotation, Rotation, Vacuum, build_mass_matrix, charged_mass_matrix,
38
+ diagonalize_orthogonal_2x2, diagonalize_svd, diagonalize_svd_2x2,
39
+ diagonalize_takagi,
40
+ rotation_2x2, scalar_mass_matrix, seesaw_mass_matrix, seesaw_light_mass,
41
+ solve_mixing_angle_2x2,
42
+ )
43
+ from .vertices.bilinear import (
44
+ Bilinear, MajoranaBilinear, expand_bilinear, extract_fermion_vertices,
45
+ extract_majorana_vertices, fermion_feynman_rule, fermion_gauge_current,
46
+ fermion_mass_matrix, four_fermion_feynman_rule, majorana_feynman_rule,
47
+ majorana_mass_matrix,
48
+ )
49
+ from .invariance import (
50
+ check_discrete_invariance, check_gauge_invariance, check_hermiticity,
51
+ check_mass_dimension, gauge_variation,
52
+ )
53
+ from .lagrangian import (
54
+ InvarianceReport, Lagrangian, LagrangianTerm, Model, ValidationReport,
55
+ )
56
+ from .anomalies import (
57
+ AnomalyReport, anomaly_coefficients, check_anomaly_free,
58
+ )
59
+ from .charges import (
60
+ ChargeConservationReport, ChargeConsistencyReport, ChargeRegistry,
61
+ HermiticityPairingReport, check_charge_conservation,
62
+ check_charge_consistency, check_hermiticity_pairing,
63
+ derive_charge_operator, physical_charges,
64
+ )
65
+ from .flavor import CKM_ELEMENT_NAMES, cabibbo_2x2, standard_ckm
66
+ from .gauge_basis import (
67
+ adjoint_rotation, gauge_self_couplings, physical_vector_basis,
68
+ )
69
+ from .export.ufo.legs import ufo_leg_sign
70
+ from .models import (
71
+ ElectroweakScaffold, PhysicalBasis, StandardModel,
72
+ charged_current_rotation, electroweak_gauge, electroweak_scaffold,
73
+ higgs_doublet, standard_model, to_physical_basis, weinberg_rotation,
74
+ )
75
+ from .suggest import (
76
+ SuggestedTerm, build_lagrangian, suggest_kinetic, suggest_potential,
77
+ suggest_yukawa,
78
+ )
79
+
80
+ __all__ = [
81
+ "Parameter", "ExternalParameter", "InternalParameter", "ParameterSet",
82
+ "GaugeGroup", "U1", "SUN", "SU2", "SU3", "DiscreteSymmetry", "ZN", "S3",
83
+ "Field", "Scalar", "Fermion", "WeylFermion", "DiracFermion",
84
+ "MajoranaFermion", "GaugeBoson", "dag", "hc", "conjugate_pair",
85
+ "bar_partner",
86
+ "Vacuum", "Rotation", "MajoranaRotation", "rotation_2x2",
87
+ "solve_mixing_angle_2x2",
88
+ "diagonalize_orthogonal_2x2", "diagonalize_svd", "diagonalize_svd_2x2",
89
+ "diagonalize_takagi",
90
+ "build_mass_matrix", "scalar_mass_matrix", "charged_mass_matrix",
91
+ "seesaw_mass_matrix", "seesaw_light_mass",
92
+ "Bilinear", "MajoranaBilinear", "expand_bilinear",
93
+ "extract_fermion_vertices", "extract_majorana_vertices",
94
+ "fermion_feynman_rule", "fermion_gauge_current", "fermion_mass_matrix",
95
+ "four_fermion_feynman_rule", "majorana_mass_matrix",
96
+ "majorana_feynman_rule",
97
+ "gauge_variation", "check_gauge_invariance", "check_discrete_invariance",
98
+ "check_hermiticity", "check_mass_dimension",
99
+ "Lagrangian", "LagrangianTerm", "Model", "InvarianceReport",
100
+ "ValidationReport",
101
+ "METRIC_SIGNATURE", "SQRT2", "tidy",
102
+ "DiracGamma", "DiracGammaLower", "DiracC", "MetricTensor", "dirac0",
103
+ "diracI", "diracPL", "diracPR", "diracC", "dirac_conjugate",
104
+ "gamma_simplify", "majorana_symmetry_sign", "minkowski_metric",
105
+ "D_linear", "Dmu", "PartialMu", "expand_derivatives", "momentum",
106
+ "to_momentum_space",
107
+ "Vertex", "classify_spins", "LORENTZ_CATALOG",
108
+ "structure_constants", "cubic_couplings", "quartic_couplings",
109
+ "gauge_mass_matrix",
110
+ "extract_interaction_coefficients", "feynman_rule", "vertex_multiplicity",
111
+ "check_dimension", "is_hermitian", "is_symmetric", "numeric_equal",
112
+ "round_trip_reconstruct", "seesaw_light_mass",
113
+ "UFORoundTripReport", "verify_ufo_numeric",
114
+ "latex_feynman_table",
115
+ "SuggestedTerm", "suggest_potential", "suggest_yukawa", "suggest_kinetic",
116
+ "build_lagrangian",
117
+ "AnomalyReport", "anomaly_coefficients", "check_anomaly_free",
118
+ "ChargeRegistry", "ChargeConservationReport", "ChargeConsistencyReport",
119
+ "HermiticityPairingReport", "check_charge_conservation",
120
+ "check_charge_consistency", "check_hermiticity_pairing",
121
+ "derive_charge_operator", "physical_charges",
122
+ "standard_ckm", "cabibbo_2x2", "CKM_ELEMENT_NAMES",
123
+ "adjoint_rotation", "gauge_self_couplings", "physical_vector_basis",
124
+ "ufo_leg_sign",
125
+ "ElectroweakScaffold", "PhysicalBasis", "StandardModel",
126
+ "electroweak_gauge", "higgs_doublet", "weinberg_rotation",
127
+ "charged_current_rotation", "electroweak_scaffold", "to_physical_basis",
128
+ "standard_model",
129
+ ]
130
+
131
+
132
+ def __getattr__(name):
133
+ # ``feynlag.pheno`` is imported on first access, so ``import feynlag``
134
+ # stays free of the numeric/phenomenology stack.
135
+ if name == "pheno":
136
+ import importlib
137
+ return importlib.import_module(".pheno", __name__)
138
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
feynlag/anomalies.py ADDED
@@ -0,0 +1,247 @@
1
+ """Gauge-anomaly cancellation from the declared fermion content.
2
+
3
+ A chiral gauge theory is only consistent if its triangle anomalies cancel.
4
+ This module computes every anomaly coefficient symbolically from the fermion
5
+ representations already declared for a :class:`~feynlag.lagrangian.Model`, so
6
+ it works even when U(1) charges are kept symbolic (e.g. the ``X = aY + b(B−L)``
7
+ assignment of ``examples/sm_u1x.py``) — the coefficients come out as
8
+ polynomials in the charge symbols that must vanish, which can then be solved
9
+ for the anomaly-free charge assignments.
10
+
11
+ Conventions
12
+ -----------
13
+ Everything is reduced to **left-handed Weyl** fermions. A field declared with
14
+ ``chirality='R'`` is the conjugate of a left-handed field, so under the
15
+ reduction all of its U(1) charges flip sign and every non-abelian
16
+ representation goes to its conjugate. Since the Dynkin index ``T(R)=T(R̄)`` is
17
+ conjugation-invariant, only the cubic ``[SU(N)]³`` anomaly (odd under
18
+ conjugation, ``A(R̄)=−A(R)``) and the charge signs actually feel the flip.
19
+
20
+ Coefficients returned (each must vanish for consistency):
21
+
22
+ - ``[U(1)_a U(1)_b U(1)_c]`` — every multiset of three abelian factors,
23
+ - ``grav^2-U(1)_a`` — the mixed gravitational–gauge anomaly,
24
+ - ``[G]^2-U(1)_a`` — non-abelian squared times each abelian factor,
25
+ - ``[G]^3`` — the pure cubic non-abelian anomaly (non-zero only for complex
26
+ representations; among the supported reps that is the SU(3) fundamental),
27
+ - ``Witten-G`` — the SU(2) global anomaly: the number of doublets, which must
28
+ be even (reported as an integer count, not a coefficient that vanishes).
29
+ """
30
+
31
+ from itertools import combinations_with_replacement
32
+
33
+ import sympy as sp
34
+
35
+ from .fields import Fermion
36
+
37
+ __all__ = [
38
+ "anomaly_coefficients", "AnomalyReport", "check_anomaly_free",
39
+ ]
40
+
41
+
42
+ def _dynkin_index(group, rep):
43
+ """Dynkin index ``T(R)`` from ``Tr(T^a T^b) = T(R) δ^{ab}``.
44
+
45
+ Computed as ``T = (1/dim G) Σ_a Tr(T^a T^a)`` so it is robust for any
46
+ representation whose generators the group can build (singlet → 0).
47
+ """
48
+ gens = group.generators(rep)
49
+ n = len(gens)
50
+ if n == 0:
51
+ return sp.S.Zero
52
+ total = sum(((T * T).trace() for T in gens), sp.S.Zero)
53
+ return sp.simplify(total / n)
54
+
55
+
56
+ _ANOM_REF_CACHE = {}
57
+
58
+
59
+ def _anomaly_triples(group):
60
+ """Up to two symmetric index triples ``(a, b, c)`` for which the
61
+ fundamental trace ``t_F = Tr(T^a{T^b, T^c})`` is non-zero, with their
62
+ ``t_F`` values (cached per group N). Empty for SU(2) (all reps real)."""
63
+ N = getattr(group, "N", None)
64
+ if N in _ANOM_REF_CACHE:
65
+ return _ANOM_REF_CACHE[N]
66
+ TF = group.generators(N)
67
+ n = len(TF)
68
+ triples = []
69
+ for a in range(n):
70
+ for b in range(a, n):
71
+ for c in range(b, n):
72
+ anti = TF[b] * TF[c] + TF[c] * TF[b]
73
+ val = sp.nsimplify(sp.expand(sp.trace(TF[a] * anti)))
74
+ if val != 0:
75
+ triples.append((a, b, c, val))
76
+ if len(triples) >= 2:
77
+ _ANOM_REF_CACHE[N] = triples
78
+ return triples
79
+ _ANOM_REF_CACHE[N] = triples
80
+ return triples
81
+
82
+
83
+ def _cubic_index(group, rep):
84
+ """Cubic-anomaly index ``A(R)`` of an SU(N) representation.
85
+
86
+ Computed from the fully symmetric trace ``Tr_R(T^a{T^b,T^c})`` normalised
87
+ to the fundamental (``A(fund)=1``); real/pseudoreal reps (all SU(2) reps,
88
+ every adjoint, singlets) come out ``0`` and a conjugate rep gives
89
+ ``A(R̄)=−A(R)`` automatically (its generators are ``−(T^a)^*``). Dual
90
+ verification: the ratio is checked at a second independent triple.
91
+ """
92
+ N = getattr(group, "N", None)
93
+ if not N or N < 3:
94
+ return sp.S.Zero
95
+ triples = _anomaly_triples(group)
96
+ if not triples:
97
+ return sp.S.Zero
98
+ T = group.generators(rep)
99
+ if not T or all(m.is_zero_matrix for m in T):
100
+ return sp.S.Zero
101
+
102
+ def A_from(triple):
103
+ a, b, c, t_F = triple
104
+ num = sp.nsimplify(sp.expand(sp.trace(T[a] * (T[b] * T[c] + T[c] * T[b]))))
105
+ return sp.simplify(num / t_F)
106
+
107
+ A = A_from(triples[0])
108
+ if len(triples) > 1:
109
+ assert sp.simplify(A - A_from(triples[1])) == 0, \
110
+ f"cubic-anomaly index inconsistent across triples for {group!r} {rep}"
111
+ return sp.nsimplify(A)
112
+
113
+
114
+ def _is_fundamental(group, rep):
115
+ """Whether ``rep`` of ``group`` is the (2-dim) fundamental — robust to the
116
+ label form (int ``2`` or the Dynkin tuple ``(1,)``)."""
117
+ N = getattr(group, "N", None)
118
+ if N is None:
119
+ return False
120
+ try:
121
+ return group.rep_dim(rep) == N and N == 2
122
+ except (ValueError, TypeError):
123
+ return False
124
+
125
+
126
+ def _nonabelian_dim(field, groups):
127
+ """Product of representation dimensions over ``groups`` for ``field``."""
128
+ dim = sp.S.One
129
+ for g in groups:
130
+ if g in field.reps:
131
+ dim *= g.rep_dim(field.reps[g])
132
+ return dim
133
+
134
+
135
+ def anomaly_coefficients(model):
136
+ """All gauge-anomaly coefficients of a model's fermion content.
137
+
138
+ Args:
139
+ model: a :class:`~feynlag.lagrangian.Model` (its ``gauge_groups`` and
140
+ the :class:`~feynlag.fields.Fermion` members of ``fields`` are
141
+ used).
142
+
143
+ Returns:
144
+ ``dict`` mapping an anomaly name to its (possibly symbolic)
145
+ coefficient. ``Witten-<group>`` entries hold the integer doublet
146
+ count instead of a vanishing coefficient.
147
+ """
148
+ fermions = [f for f in model.fields if isinstance(f, Fermion)]
149
+ abelian = [g for g in model.gauge_groups if g.abelian]
150
+ nonabelian = [g for g in model.gauge_groups if not g.abelian]
151
+
152
+ # Pre-reduce every fermion to left-handed data.
153
+ reduced = []
154
+ for f in fermions:
155
+ sign = 1 if f.chirality != "R" else -1 # charge/cubic flip
156
+ nf = getattr(f, "nflavors", 1)
157
+ charges = {g: sign * sp.sympify(f.reps[g]) for g in abelian
158
+ if g in f.reps}
159
+ full_dim = nf * _nonabelian_dim(f, nonabelian)
160
+ reduced.append((f, sign, nf, charges, full_dim))
161
+
162
+ coeffs = {}
163
+
164
+ def q(entry, group):
165
+ return entry[3].get(group, sp.S.Zero)
166
+
167
+ # [U(1)_a U(1)_b U(1)_c] — cubic abelian (all multisets of three)
168
+ for triple in combinations_with_replacement(abelian, 3):
169
+ a, b, c = triple
170
+ name = f"[{a.name}][{b.name}][{c.name}]"
171
+ coeffs[name] = sp.expand(sum(
172
+ e[4] * q(e, a) * q(e, b) * q(e, c) for e in reduced))
173
+
174
+ # grav^2-U(1)_a
175
+ for a in abelian:
176
+ coeffs[f"grav^2-{a.name}"] = sp.expand(sum(
177
+ e[4] * q(e, a) for e in reduced))
178
+
179
+ # [G]^2-U(1)_a and [G]^3
180
+ for G in nonabelian:
181
+ spectators = [g for g in nonabelian if g is not G]
182
+ for a in abelian:
183
+ total = sp.S.Zero
184
+ for f, sign, nf, charges, full_dim in reduced:
185
+ if G not in f.reps:
186
+ continue
187
+ spec_dim = nf * _nonabelian_dim(f, spectators)
188
+ total += spec_dim * _dynkin_index(G, f.reps[G]) \
189
+ * charges.get(a, sp.S.Zero)
190
+ coeffs[f"[{G.name}]^2-{a.name}"] = sp.expand(total)
191
+
192
+ cubic = sp.S.Zero
193
+ for f, sign, nf, charges, full_dim in reduced:
194
+ if G not in f.reps:
195
+ continue
196
+ spec_dim = nf * _nonabelian_dim(f, spectators)
197
+ cubic += spec_dim * sign * _cubic_index(G, f.reps[G])
198
+ coeffs[f"[{G.name}]^3"] = sp.expand(cubic)
199
+
200
+ # Witten global anomaly: doublet count for an SU(2)-type group
201
+ if getattr(G, "n_generators", 0) == 3:
202
+ doublets = sp.S.Zero
203
+ for f, sign, nf, charges, full_dim in reduced:
204
+ if G in f.reps and _is_fundamental(G, f.reps[G]):
205
+ doublets += nf * _nonabelian_dim(f, spectators)
206
+ coeffs[f"Witten-{G.name}"] = sp.expand(doublets)
207
+
208
+ return coeffs
209
+
210
+
211
+ class AnomalyReport:
212
+ """Result of :func:`check_anomaly_free`.
213
+
214
+ Attributes:
215
+ coefficients: the full ``{name: coefficient}`` map.
216
+ nonzero: the subset that does not vanish (Witten entries that are odd
217
+ are reported here as ``"<count> (odd)"``).
218
+ """
219
+
220
+ def __init__(self, coefficients):
221
+ self.coefficients = coefficients
222
+ self.nonzero = {}
223
+ for name, value in coefficients.items():
224
+ if name.startswith("Witten-"):
225
+ if int(value) % 2 != 0:
226
+ self.nonzero[name] = f"{value} (odd)"
227
+ elif sp.simplify(value) != 0:
228
+ self.nonzero[name] = sp.simplify(value)
229
+
230
+ @property
231
+ def ok(self):
232
+ return not self.nonzero
233
+
234
+ def raise_on_failure(self):
235
+ if not self.ok:
236
+ lines = "\n".join(f" {n} = {v}" for n, v in self.nonzero.items())
237
+ raise ValueError(f"gauge anomalies do not cancel:\n{lines}")
238
+ return self
239
+
240
+ def __repr__(self):
241
+ status = "anomaly-free" if self.ok else f"{len(self.nonzero)} nonzero"
242
+ return f"AnomalyReport({len(self.coefficients)} coefficients, {status})"
243
+
244
+
245
+ def check_anomaly_free(model):
246
+ """Convenience: build coefficients and wrap them in an :class:`AnomalyReport`."""
247
+ return AnomalyReport(anomaly_coefficients(model))