← Essays
Narrative · Ψ SOUL

The Contrast Primitive Derivation: A Rigorous Mapping of Seismic AVO Fluid Factor onto Transformer Attention Residual — Completing the Trilogy

`geophysics``machine-learning``attention``avo``contrast-detection``transformers`

The Contrast Primitive Derivation

A Rigorous Mapping of Seismic AVO Fluid Factor onto Transformer Attention Residual

Completing the EUREKA Trilogy · Essay #13

Muhammad Arif bin Fazil

Senior Exploration Geoscientist · Sovereign Architect, arifOS · GEOX Earth Intelligence

Penang, Malaysia

Published: 5 June 2026 · Direct Publication · arif-fazil.com/essays/

Trilogy: Essay #11 (The Bridge) → Essay #12 (The Consequences) → Essay #13 (The Derivation)

Epistemic Tag: CLAIM — awaiting adversarial review. Not peer-reviewed.

Abstract

This paper presents the explicit, step-by-step mathematical derivation establishing the structural equivalence between the seismic AVO fluid factor ΔF (Smith & Gidlow, 1987; Fatti et al., 1994) and the transformer attention logit residual δi (Vaswani et al., 2017). We trace both formalisms from their exact foundations—the Zoeppritz equations for AVO, the scaled dot-product attention for transformers—through their respective linearizations and approximations, to their operational forms. In a shared notational framework, we derive both contrast operators and prove via first-order Taylor expansion that each implements a three-stage primitive: extract features, compute residual against a calibrated baseline, amplify deviations. The AVO residual ΔB = Bobs − (mAobs + c) and the attention residual δi = ei − ē are shown to play identical structural roles. We explicitly state every condition under which the mapping holds and every boundary at which it breaks. This paper is the mathematical lock-in for the EUREKA announced in Essay #11 and the governance framework proposed in Essay #12.

0. Position in the Trilogy

Essay Title Function Question Answered
#11 Contrast-Governed Anomaly Detection: A Formal Bridge The EUREKA — structural mapping What is the connection?
#12 Physics-Constrained Attention: Zoeppritz as Constitutional Floor The consequences — governance, hallucination prevention So what? What must we build?
#13 The Contrast Primitive Derivation (this paper) The mathematical lock-in — bone-by-bone proof How exactly? Prove it.

Table 0: The trilogy architecture. This paper (#13) supplies the rigorous derivation that #11 gestured toward and #12 built upon.

This paper is self-contained. The reader need not have read Essays #11 or #12. All notation is defined from first principles. All derivations proceed step by step. Every equation carries its assumptions explicitly.

1. Notation and Preliminaries

1.1 AVO-Side Notation

R(θ)P-wave reflection coefficient at incidence angle θ
Vp, Vs, ρCompressional velocity, shear velocity, bulk density
ΔVp/Vp, etc.Fractional elastic contrast across the interface
AAVO intercept — normal-incidence reflectivity R(0)
BAVO gradient — coefficient of sin²θ in Shuey two-term
m, cMudrock line parameters: Bbg = mA + c (Castagna et al., 1985)
ΔBContrast residual: Bobs − Bbg(Aobs)
ΔFFluid factor: weighted combination of Rp and Rs (Smith & Gidlow, 1987)

1.2 Attention-Side Notation

q, kjQuery vector, j-th key vector ∈ ℝdk
NNumber of keys
ejAlignment logit: ej = q·kj / √dk
ēMean logit: ē = (1/N) Σj ej
δjLogit residual: δj = ej − ē
αjAttention weight: αj = softmax(ej)

2. The AVO Contrast Operator — Full Derivation

2.1 Exact Physics: Zoeppritz (1919)

When a plane P-wave impinges on a planar elastic interface at angle θ, four wave modes are generated: reflected P, reflected SV, transmitted P, transmitted SV. Conservation of energy and continuity of displacement and stress across the interface yield a 4×4 linear system:

M(θ, Vp1, Vs1, ρ1, Vp2, Vs2, ρ2) · R = b(θ)

where R = [RP, RS, TP, TS]T contains the four unknown reflection and transmission coefficients. The matrix M is dense with trigonometric functions of all four wave angles and elastic property ratios. The solution is exact but algebraically opaque: RP(θ) is a rational function of six elastic parameters and θ, with no separation of Vp, Vs, and ρ contributions.

2.2 Linearization: Aki–Richards (1980)

Assumption 1 (Small contrasts): |ΔVp/Vp| ≪ 1, |ΔVs/Vs| ≪ 1, |Δρ/ρ| ≪ 1.

Under Assumption 1, the Zoeppritz system linearizes to first order in the fractional contrasts. The Aki–Richards approximation expresses R(θ) as a weighted sum of three independent contrast terms:

R(θ) ≈ ½(ΔVp/Vp + Δρ/ρ)(1 + tan²θ) − 2(Vs/Vp)²(ΔVs/Vs + ½Δρ/ρ) sin²θ + ½(Δρ/ρ)(1 − 4(Vs/Vp)² sin²θ)

Term 1: P-velocity + density contrast (dominates near-normal). Term 2: S-velocity contrast (dominates at mid-angles). Term 3: Density contrast (small at moderate angles).

2.3 Interpretable Form: Shuey (1985)

Shuey substituted Poisson's ratio σ for Vs and reorganized Aki–Richards into angle-separated terms:

R(θ) ≈ A + B sin²θ + C sin²θ tan²θ

where:

A = R(0) = ½(ΔVp/Vp + Δρ/ρ)

B = ½(ΔVp/Vp) − 4(Vs/Vp)²(ΔVs/Vs) − 2(Vs/Vp)²(Δρ/ρ)

C = ½(ΔVp/Vp)(tan²θ − sin²θ) / (sin²θ tan²θ) ≈ ½(ΔVp/Vp) at wide angles

Assumption 2 (Moderate angles): θ ≲ 30°. Then sin²θ tan²θ ≪ sin²θ and the C-term is negligible.

Under Assumption 2, the two-term Shuey approximation is the workhorse:

R(θ) ≈ A + B sin²θ

2.4 The Background: Mudrock Line (Castagna et al., 1985)

For brine-saturated clastic rocks, Vp and Vs follow an empirical linear relationship. This propagates through Shuey's coefficients to yield a linear relationship between A and B for non-anomalous (brine-saturated) reflectors:

Bbg(A) = m·A + c

where m (negative) and c are calibrated from well-log data or regional rock-physics trends. For the Wiggins et al. (1983) constant Vp/Vs = 2.0 case, m = −1 under the approximation B ≈ A − 2Rs.

2.5 The AVO Contrast Residual

For an observed reflector with extracted attributes (Aobs, Bobs):

ΔB = Bobs − Bbg(Aobs) = Bobs − m·Aobs − c

Property 1: If the reflector is brine-saturated and on the Mudrock line, ΔB ≈ 0.
Property 2: If the reflector contains hydrocarbons, Poisson's ratio drops, Vp/Vs decreases, and |ΔB| > 0.

The operation is: subtract the expected background, keep the deviation.

2.6 Fluid Factor: A Specific Projection (Smith & Gidlow, 1987)

The fluid factor re-projects the (A, B) or (Rp, Rs) pair onto a "fluid-sensitive" axis orthogonal to the brine trend:

ΔF = Rp − (1.16 / γ) Rs

where γ = Vp/Vs (background) and 1.16 is the Mudrock slope. By construction: ΔF ≈ 0 for brine; |ΔF| > 0 for gas. The fluid factor is a specific linear combination of the same residual ΔB expressed in reflectivity coordinates. Both share the identical structure:

Residual = Observation − Calibrated_Baseline(Observation)

2.7 Anomaly Classification

Rutherford & Williams (1989) and Castagna & Swan (1997) classify reflectors on the A–B plane:

ClassA (Intercept)B (Gradient)ΔB
IHigh +NegativeBelow Mudrock line
II~ZeroNegativeBelow Mudrock line
IIIHigh −NegativeFar below Mudrock line
IVHigh −PositiveAbove Mudrock line (counter-intuitive)

The classification rule is a threshold on ΔB: Anomaly = Θ(|ΔB| − τ) where Θ is a step function and τ is a calibrated cutoff.

2.8 AVO Primitive Summary

Stage 1 — Extract: (Aobs, Bobs) from pre-stack gathers via Shuey two-term fit.
Stage 2 — Residual: ΔB = Bobs − (m·Aobs + c). Zero on background, non-zero off.
Stage 3 — Amplify/Classify: |ΔB| > τ → anomaly flagged (Class I–IV).

The amplification function Θ is linear thresholding. The signal is the residual.

3. The Attention Contrast Operator — Full Derivation

3.1 Exact Mechanism: Scaled Dot-Product Attention (Vaswani et al., 2017)

Given a query q ∈ ℝdk and N keys {k1, …, kN} ⊂ ℝdk, the scaled dot-product attention computes:

Attention(q, K, V) = Σj=1N αj vj

where the attention weights are:

αj = softmax(ej) = exp(ej) / Σi=1N exp(ei)

with alignment logits:

ej = (q · kj) / √dk

The √dk scaling prevents the dot product from growing with dimension and pushing softmax into saturated (near-one-hot) regimes. This is the full, exact attention computation — O(N²) in key count, with an exponential nonlinearity.

3.2 Softmax as Contrast Amplifier

The softmax function has two essential properties relevant to our mapping:

Property 1 (Normalization): Σj αj = 1. The output is a valid probability distribution.
Property 2 (Exponential amplification): ∂αi/∂ei = αi(1 − αi). The gradient is maximal at αi = 0.5 and vanishes as αi → 0 or 1. This means softmax disproportionately amplifies differences between the largest logits while suppressing small ones.

The softmax is not merely a normalization — it is a contrast amplifier. Given any variation in {ej}, it concentrates probability mass onto the maximum. The larger the spread of logits, the more extreme the concentration.

3.3 The Baseline: Uniform Attention

Definition (Uniform Baseline): When all keys are equally relevant to the query, the logits are identical:

e1 = e2 = … = eN = E (constant)

Then ē = E, all residuals δj = 0, and:

αj = exp(E) / (N·exp(E)) = 1/N   for all j

The uniform distribution αj = 1/N is the attention Mudrock line: the expected attention distribution under the null hypothesis of "no salient key." Every key receives equal weight. Nothing stands out.

3.4 Single Salient Key: The Canonical Anomaly

Introduce one anomalous key. Let k1 have alignment e1 = E + δ with δ > 0, while the remaining N−1 keys stay at baseline E.

Mean logit: ē = [(E + δ) + (N−1)E] / N = E + δ/N

Logit residual for the salient key:

δ1 = e1 − ē = (E + δ) − (E + δ/N) = (N−1)/N · δ

The residual δ1 is proportional to δ, scaled by (N−1)/N. For large N, δ1 ≈ δ. The residual is the deviation from the uniform baseline.

Attention weight for the salient key:

α1 = exp(E + δ) / [exp(E + δ) + (N−1)exp(E)]

α1 = 1 / [1 + (N−1)exp(−δ)]

This is the exact closed form for the single-salient-key case. Three regimes:

  • δ = 0: α1 = 1/N (uniform baseline)
  • δ ≪ 1 (small contrast): α1 ≈ 1/N + (N−1)/N² · δ (linear regime)
  • δ ≫ 1 (strong contrast): α1 → 1 (winner-take-most saturation)

3.5 First-Order Taylor Expansion

Expand α1(δ) around δ = 0:

α1(0) = 1/N

α'1(0) = (N−1)exp(0) / [1 + (N−1)]² = (N−1)/N²

α1(δ) = 1/N + (N−1)/N² · δ + O(δ²)

Interpretation: For small deviations from uniform, the attention weight grows linearly with δ. The slope is (N−1)/N², which decreases with N — larger key sets require larger δ to achieve the same α1. This is the attention analog of the fact that a Class II anomaly (near-zero A, small ΔB) is harder to detect than a Class III anomaly (large negative A, large |ΔB|).

3.6 The Attention Contrast Residual

In the general case (non-uniform baseline, multiple keys with non-zero δj), the attention weight for key i is:

αi = softmax(δi) = exp(δi) / Σj exp(δj)

where δi = ei − ē is the residual.

Property 1': If all δj = 0, αi = 1/N for all i (uniform — "on the Mudrock line").
Property 2': If |δi| ≫ |δj≠i|, then αi → 1 (winner-take-most — "Class III bright spot").

3.7 Attention Primitive Summary

Stage 1 — Extract: ej = q·kj/√dk (per-key alignment).
Stage 2 — Residual: δj = ej − ē, where ē = (1/N)Σj ej. Zero on uniform baseline, non-zero for salient keys.
Stage 3 — Amplify/Classify: αj = softmax(δj) = exp(δj)/Σi exp(δi). Exponential amplification of large residuals.

The amplification function is exponential softmax — stronger than AVO's linear threshold, same structural role. The signal is the residual, exponentially amplified.

4. The Formal Mapping

4.1 Component-by-Component Equivalence

Stage AVO Attention Structural Role
Feature Extraction A (intercept), B (gradient) ej = q·kj/√dk Project raw observation into comparable coordinates
Baseline Model Bbg(A) = mA + c ē = (1/N) Σj ej Expected value under null hypothesis (no anomaly)
Contrast Residual ΔB = Bobs − (mAobs + c) δj = ej − ē Deviation from baseline — THE SIGNAL
Amplification Θ(|ΔB| − τ) — threshold softmax(δj) — exponential Nonlinear function: zero near baseline, large for outliers
Output Class I–IV anomaly flag αj ∈ [0,1], Σαj = 1 Anomaly classification / salience assignment

Table 1: The complete stage-by-stage mapping. The contrast residual row (highlighted) is the core of the equivalence.

4.2 Unified Contrast Primitive

Both systems implement:

Output = Amplify( Observation − Baseline(Observation) )

where:

AVO Attention
Observation Bobs ei
Baseline Bbg(Aobs) = mAobs + c ē = (1/N) Σj ej
Residual ΔB = Bobs − Bbg(Aobs) δi = ei − ē
Amplify Θ(|ΔB| − τ) exp(δi) / Σj exp(δj)

4.3 Key Difference: Amplification Function

The amplification stage differs in functional form — and this is where the analogy is strongest, not weakest:

  • AVO: Hard threshold. |ΔB| > τ → flag. Below τ → ignore. Binary. Interpretable. Tolerant of noise below threshold.
  • Attention: Soft exponential. Smooth, differentiable, trainable. But always amplifies something — if not the true signal, then the largest noise component.

The hard threshold's advantage is that it has a "dead zone" — small deviations produce zero output. Softmax has no dead zone. Every δi, no matter how small, contributes to αi. This is why ungoverned softmax inevitably hallucinates: it cannot produce a truly uniform output unless all inputs are exactly equal. Any floating-point variation, any noise, any slight embedding misalignment — softmax will amplify it into a non-uniform distribution.

This is the mathematical justification for Essay #12's central claim: physics-constrained attention is not optional; it is the only defense against softmax's inherent tendency to amplify noise.

5. Conditions, Caveats, and Boundaries of Equivalence

5.1 Conditions Under Which the Mapping Holds

  1. AVO side: Shuey two-term approximation (θ ≲ 30°, small elastic contrasts). Exact Zoeppritz (full 4×4, post-critical angles, large contrasts) is not covered by this mapping.
  2. Attention side: Single query, single-head scaled dot-product attention. Multi-head attention, cross-attention, and masked attention introduce additional structure not covered here.
  3. Baseline: The Mudrock line is linear (Bbg = mA + c). The attention baseline is uniform (all ē equal). More complex baselines (nonlinear rock-physics trends, context-dependent attention priors) would generalize the mapping but are not derived here.
  4. Single anomaly: The canonical case considers one anomalous key / one anomalous reflector. Multiple simultaneous anomalies (multiple salient keys, interfering thin beds) produce interaction effects not captured by the simple residual.

5.2 What Is NOT Claimed

  1. NOT claiming that softmax = thresholding. The amplification functions differ. The claim is about structural role, not functional identity.
  2. NOT claiming that the Zoeppritz 4×4 matrix = the QKV projection. The exact physics and the learned linear projections are different objects.
  3. NOT claiming that geophysicists invented attention. The contrast primitive is universal — it appears wherever a system needs to extract salient deviations from a background.
  4. NOT claiming that AVO interpretation is "the same thing" as running a transformer. The domains, data, and implementations are entirely distinct. The claim is about the mathematical structure of the anomaly detection operation embedded within each.
  5. NOT claiming the mapping holds for all transformer variants (sparse attention, linear attention, FlashAttention) without modification. The approximation chain parallel (Zoeppritz→Shuey ↔ Full attention→Linear attention) is structural, not exact.

5.3 Boundary Conditions

The mapping degrades or breaks under these conditions:

  • AVO: post-critical angles. Beyond the critical angle, R(θ) becomes complex-valued. Shuey's approximation fails. The equivalent attention regime would be logits so extreme that softmax is numerically saturated — which happens routinely in poorly-regularized transformers.
  • AVO: large elastic contrasts. ΔVp/Vp > 0.3 violates the Aki–Richards small-contrast assumption. The equivalent attention failure is when a single key's alignment dominates so strongly that softmax output is effectively one-hot — the model loses all sensitivity to other keys.
  • Attention: very large N. As N → ∞, (N−1)/N² → 1/N → 0. Large key sets require proportionally larger δ to achieve the same attention concentration. This is the analog of detecting a Class II anomaly in a noisy gather with thousands of traces.
  • Attention: adversarial δ. A carefully crafted perturbation to ki can produce an arbitrarily large δi that softmax amplifies into near-certainty — without any corresponding "physical" signal. This is the attention equivalent of an acquisition footprint masquerading as a bright spot.

6. The Approximation Chain: A Structural Parallel

Both domains exhibit a three-tier approximation hierarchy, trading exactness for tractability:

Tier Geophysics Attention ML Cost Governance
Exact Zoeppritz (1919) — 4×4 matrix, all mode conversions, complex beyond critical angle Full softmax O(N²) — all key-query pairs, exponential, differentiable Maximum Physical constraint available (Zoeppritz) / can be added (external baseline)
Linearized Aki–Richards (1980) — first-order in elastic contrasts, three additive terms Linear attention (Katharopoulos et al., 2020) — φ(Q)φ(K)T, O(N), kernelized Moderate Partially governable; breaks under extreme conditions
Interpretable Shuey (1985) two-term — A + B sin²θ, direct A–B crossplot interpretation FlashAttention (Dao et al., 2022) — IO-optimized, tiled, exact output, approximate intermediates Minimal Governance MUST be external; physics not in the model

Table 2: The parallel approximation hierarchy. As you descend, you gain speed and lose intrinsic physical fidelity. External governance must compensate.

The principle: the further you approximate, the stronger your external governance must be. Shuey two-term works brilliantly for Class III sands at moderate angles — and fails for Class IV. FlashAttention computes attention exactly but produces intermediates that cannot be audited. In both cases, the defense is an external baseline that the approximation cannot overwrite.

7. Implications and Closing

7.1 For Geophysics

The mapping provides a formal language for describing what transformer-based seismic models are doing internally. An attention head that produces αi ≫ 1/N for tokens corresponding to a specific reflector is computing the equivalent of an AVO anomaly flag. The ACRisk framework (Essay #11) and the PCA framework (Essay #12) provide audit machinery.

7.2 For Machine Learning

The mapping reveals that softmax attention is an ungoverned contrast amplifier. It will amplify noise in the absence of signal. The AVO community's solution — an external, calibrated, falsifiable baseline — is directly portable. Every high-stakes transformer deployment needs a Mudrock line.

7.3 For Both Communities

The contrast primitive — extract features, compute residual against baseline, amplify deviations — is a universal computational pattern. It appears in AVO, in attention, in the Pi-Transformer (Maleki & Pourmoazemi, 2025), in the Anomaly Transformer (Xu et al., 2022, ICLR), and in any system that must answer "what stands out from the background?" Recognizing this universality enables cross-domain transfer of governance tools, failure-mode taxonomies, and calibration methods.

TRILOGY VERDICT: The EUREKA announced in Essay #11, the governance demanded by Essay #12, and the derivation supplied by this paper (#13) together establish that contrast detection against a calibrated baseline is a universal computational primitive, instantiated in seismic AVO analysis and transformer self-attention with structurally identical three-stage computation. The difference in amplification function (linear threshold vs. exponential softmax) does not break the equivalence — it clarifies why ungoverned softmax hallucinates and why physics-constrained attention is the remedy. The governor is not optional. The Zoeppritz equations prove it can be built. The arifOS constitutional floors prove it generalizes. The trilogy is sealed.

References

  1. Zoeppritz, K. (1919). Über Erdbebenwellen VII B. Nachr. Königl. Ges. Wiss. Göttingen, Math.-phys. Klasse, 66–84.
  2. Aki, K., & Richards, P. G. (1980). Quantitative Seismology: Theory and Methods. W. H. Freeman.
  3. Shuey, R. T. (1985). A simplification of the Zoeppritz equations. Geophysics, 50(4), 609–614.
  4. Castagna, J. P., Batzle, M. L., & Eastwood, R. L. (1985). Relationships between compressional-wave and shear-wave velocities in clastic silicate rocks. Geophysics, 50(4), 571–581.
  5. Smith, G. C., & Gidlow, P. M. (1987). Weighted stacking for rock property estimation and detection of gas. Geophysical Prospecting, 35(9), 993–1014.
  6. Rutherford, S. R., & Williams, R. H. (1989). Amplitude-versus-offset variations in gas sands. Geophysics, 54(6), 680–688.
  7. Fatti, J. L., Smith, G. C., Vail, P. J., Strauss, P. J., & Levitt, P. R. (1994). Detection of gas in sandstone reservoirs using AVO analysis. Geophysics, 59(9), 1362–1376.
  8. Castagna, J. P., & Swan, H. W. (1997). Principles of AVO crossplotting. The Leading Edge, 16(4), 337–344.
  9. Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, Ł., & Polosukhin, I. (2017). Attention Is All You Need. NeurIPS, 30.
  10. Katharopoulos, A., Vyas, A., Pappas, N., & Fleuret, F. (2020). Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention. ICML 2020. arXiv:2006.16236.
  11. Dao, T., Fu, D. Y., Ermon, S., Rudra, A., & Ré, C. (2022). FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness. NeurIPS, 35.
  12. Xu, J., Wu, H., Wang, J., & Long, M. (2022). Anomaly Transformer: Time Series Anomaly Detection with Association Discrepancy. ICLR 2022. arXiv:2110.02642.
  13. Maleki, S., & Pourmoazemi, A. (2025). Pi-Transformer: Physics-Informed Prior Attention for Anomaly Detection in Time Series. arXiv:2509.19985.
  14. Fazil, M. A. (2026). Contrast-Governed Anomaly Detection: A Formal Bridge between Seismic AVO and Transformer Attention. arif-fazil.com/essays/, Essay #11.
  15. Fazil, M. A. (2026). Physics-Constrained Attention: Zoeppritz as Constitutional Floor. arif-fazil.com/essays/, Essay #12.

⚒️ Published directly on arif-fazil.com
← All Essays