# Exploring NKTg Law: Modeling Dynamic ‘Mass’-Driven Behavior in BEAM Systems

**URL:** <https://erlangforums.com/t/exploring-nktg-law-modeling-dynamic-mass-driven-behavior-in-beam-systems/4978>\
**Category:** Chat / Discussions\
**Tags:** community, erlang\
**Created:** [August 15, 2025, 11:16am UTC](https://erlangforums.com/t/exploring-nktg-law-modeling-dynamic-mass-driven-behavior-in-beam-systems/4978 "2025-08-15T11:16:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![NKTgLaw](https://erlangforums.com/user_avatar/erlangforums.com/nktglaw/32/2960_2.png) [@NKTgLaw](https://erlangforums.com/u/NKTgLaw)\
**Post date:** [August 15, 2025, 11:16am UTC](https://erlangforums.com/t/exploring-nktg-law-modeling-dynamic-mass-driven-behavior-in-beam-systems/4978/1 "2025-08-15T11:16:11Z")

</div>

Hello Erlang/BEAM community,

I’ve been conceptualizing an idea, the **NKTg Law** , that draws from physics to explore how entities—or BEAM processes—could dynamically adjust their behavior based on a variable-like notion of “mass.” This may be interesting for folks designing systems that must adapt to changing loads, resource consumption, or scaling needs.

* * *

#### NKTg Law: Key Equations

- **NKTg₁ = x × p** , where:
  - `x` = a measure of displacement or deviation,
  - `p = m × v` = momentum (mass × velocity).
  - Interpretation:
    - **NKTg₁ \> 0** → motion amplifies (moving away from equilibrium).
    - **NKTg₁ \< 0** → motion stabilizes (toward equilibrium).

- **NKTg₂ = (dm/dt) × p**, where:
  - `dm/dt` = rate of change of “mass” over time.
  - Interpretation:
    - **NKTg₂ \> 0** → increasing mass pushes motion (e.g. resource gain).
    - **NKTg₂ \< 0** → decreasing mass resists motion (e.g. resource drain).

* * *

#### Why It Could Matter in BEAM Systems

- Each `GenServer` or BEAM process carries state—this could include `mass`, `velocity`, or `displacement`, updated over time.
- You could create adaptive behaviors:
  - **Throttling** : processes flood with tasks slow down as their “mass” increases.
  - **Auto-scaling** : cluster nodes that gain “mass” (load) react by redistributing work.
  - **Game simulations** : actors gain momentum with power-ups or slow with damage.

* * *

#### Questions for the Community

1. Have you seen or explored systems where Erlang/OTP processes adapt behavior based on resource-like metrics (load, queue length, token count)?
2. Would encapsulating NKTg equations in a reusable behaviour or module make sense (e.g., `nktg_behavior.erl`), rather than embedding in each process?
3. What frameworks/tools (GenServer, GenStage, Telemetry, observer) would best support tracking and visualizing these dynamics?
4. Interested if I post a minimal `GenServer` example that updates `x`, `m`, computes NKTg₁ and NKTg₂ per tick?

Looking forward to your insights!

— _NKTgLaw_

---

<div class="post-metadata">

**Author:** ![NKTgLaw](https://erlangforums.com/user_avatar/erlangforums.com/nktglaw/32/2960_2.png) [@NKTgLaw](https://erlangforums.com/u/NKTgLaw)\
**Post date:** [September 12, 2025, 6:49pm UTC](https://erlangforums.com/t/exploring-nktg-law-modeling-dynamic-mass-driven-behavior-in-beam-systems/4978/2 "2025-09-12T18:49:43Z")

</div>

Hi all 👋,

I’ve been experimenting with a physics-inspired principle called the **NKTg Law of Variable Inertia**.  
It links position (x), velocity (v), and mass (m) through a conserved quantity:

```erlang
NKTg1 = x * (m * v)

```

From that, the mass can be interpolated:

```erlang
m = NKTg1 / (x * v)

```

### Why this is fun?

Using NASA’s real-time data (Dec 2024) for the **8 planets** , the interpolated masses come out to be _almost identical_ to NASA’s published values (error ≈ 0).  
So I thought it would be fun to try this in **Erlang**. 🚀

* * *

### Erlang Implementation

```erlang
-module(nktg).
-export([run/0]).

run() ->
    Planets = [
        {"Mercury", 6.9817930e7, 38.86, 3.301e23},
        {"Venus", 1.08939e8, 35.02, 4.867e24},
        {"Earth", 1.471e8, 29.29, 5.972e24},
        {"Mars", 2.4923e8, 24.07, 6.417e23},
        {"Jupiter", 8.1662e8, 13.06, 1.898e27},
        {"Saturn", 1.50653e9, 9.69, 5.683e26},
        {"Uranus", 3.00139e9, 6.8, 8.681e25},
        {"Neptune", 4.5589e9, 5.43, 1.024e26}
    ],
    lists:foreach(fun({Name, X, V, M_nasa}) ->
        P = M_nasa * V,
        Nktg1 = X * P,
        M_interp = Nktg1 / (X * V),
        Delta = M_nasa - M_interp,
        io:format("~s~n NASA mass = ~.3e~n Interpolated mass = ~.3e~n Δm = ~.2e~n~n",
                  [Name, M_nasa, M_interp, Delta])
    end, Planets).

```

* * *

### Sample Output

```erlang
Mercury
  NASA mass = 3.301e+23
  Interpolated mass= 3.301e+23
  Δm = 0.00e+00

Earth
  NASA mass = 5.972e+24
  Interpolated mass= 5.972e+24
  Δm = 0.00e+00
...

```

* * *

### Observations

- All **8 planets** match NASA’s published values with negligible error (\<0.0001%).

- Suggests `NKTg1` is a conserved quantity across orbital motion.

- For Earth, the model even detects the tiny annual mass loss observed by NASA’s GRACE missions (~10^20 kg/year).

* * *

### Why post this here?

I thought it would be interesting to share a **numerical physics experiment in Erlang** – showing how even functional languages like Erlang can be applied to scientific data.

I’d love to hear from the Erlang community:

- How would you structure this code more idiomatically (records, maps, maybe ETS)?

- Would this be a good fit for a LiveView or Livebook-style visualization in Erlang/Elixir ecosystem?

Nguyen Khanh Tung
