mirror of
https://github.com/blackboxprogramming/lucidia.git
synced 2026-03-16 23:57:09 -05:00
Synced from BlackRoad-OS-Inc/blackroad-operator/orgs/personal/lucidia BlackRoad OS — Pave Tomorrow. RoadChain-SHA2048: fe729062952871e7 RoadChain-Identity: alexa@sovereign RoadChain-Full: fe729062952871e77147cf6d938b799096e87d9024d7005a14c9e209e12e8ad0c825b624c7bc649fc7eeb4c284fdcab8231af77980065cc04d9f36fca479ffc2346ed3c1b73de6f240d8f9485f47c995ad5b81142f7179b84932c67914dff1c08db039349ba28fca36cb57688093bf0199268dd1c2f3448c9383000bc77cc9663066ff57b834370afc8838b18466ea9029908018b961555cccaabf2ce21649cf3cabc7f64bdcc4abdf2da259b210c342835a2cecf92bdd3b4e109b4d6e622f6934e13b2b123607bd61ce3d0f20454c9ab594f9284cffe18716619c52db57ce5f4ee2856cb96e1fa3748fe1fe65435bec297c5ab3ab58d570ec1064aea29931dd
114 lines
3.0 KiB
Python
114 lines
3.0 KiB
Python
"""
|
|
mirror_mechanics.py
|
|
|
|
This module implements the mirror operator \u03a8' and breath operator \u2102
|
|
for the harmonic oscillator. It provides a basic demonstration of
|
|
oscillator dynamics and how positive and negative frequency components
|
|
are defined.
|
|
|
|
Functions:
|
|
mirror_split(signal) -> (pos, neg)
|
|
breath_step(q, p, omega=1.0, dt=0.01) -> (q_new, p_new)
|
|
run_oscillator(steps=1000, dt=0.01, omega=1.0) -> (qs, ps)
|
|
|
|
Example:
|
|
if __name__ == "__main__":
|
|
qs, ps = run_oscillator()
|
|
pos, neg = mirror_split(qs)
|
|
"""
|
|
import numpy as np
|
|
try:
|
|
from scipy.signal import hilbert
|
|
except ImportError:
|
|
hilbert = None
|
|
|
|
def mirror_split(signal: np.ndarray):
|
|
"""
|
|
Split a real-valued signal into its positive and negative frequency components.
|
|
|
|
Parameters
|
|
----------
|
|
signal : np.ndarray
|
|
Real-valued time series.
|
|
|
|
Returns
|
|
-------
|
|
pos : np.ndarray
|
|
The positive frequency component (analytic signal divided by 2).
|
|
neg : np.ndarray
|
|
The negative frequency component.
|
|
"""
|
|
if hilbert is None:
|
|
raise ImportError(
|
|
"scipy is required for mirror_split; install scipy to use this function"
|
|
)
|
|
analytic = hilbert(signal)
|
|
pos = analytic / 2.0
|
|
neg = np.conj(analytic) - pos
|
|
return pos, neg
|
|
|
|
def breath_step(q: float, p: float, omega: float = 1.0, dt: float = 0.01):
|
|
"""
|
|
Perform a single leap-frog (symplectic) update for a harmonic oscillator.
|
|
|
|
Parameters
|
|
----------
|
|
q : float
|
|
Position.
|
|
p : float
|
|
Momentum.
|
|
omega : float, optional
|
|
Oscillator frequency (default 1.0).
|
|
dt : float, optional
|
|
Time step (default 0.01).
|
|
|
|
Returns
|
|
-------
|
|
q_new : float
|
|
Updated position.
|
|
p_new : float
|
|
Updated momentum.
|
|
"""
|
|
p_half = p - 0.5 * dt * (omega ** 2) * q
|
|
q_new = q + dt * p_half
|
|
p_new = p_half - 0.5 * dt * (omega ** 2) * q_new
|
|
return q_new, p_new
|
|
|
|
def run_oscillator(steps: int = 1000, dt: float = 0.01, omega: float = 1.0):
|
|
"""
|
|
Run a harmonic oscillator using the breath operator.
|
|
|
|
Parameters
|
|
----------
|
|
steps : int, optional
|
|
Number of time steps (default 1000).
|
|
dt : float, optional
|
|
Time step (default 0.01).
|
|
omega : float, optional
|
|
Oscillator frequency (default 1.0).
|
|
|
|
Returns
|
|
-------
|
|
qs : np.ndarray
|
|
Array of positions over time.
|
|
ps : np.ndarray
|
|
Array of momenta over time.
|
|
"""
|
|
q, p = 1.0, 0.0
|
|
qs, ps = [], []
|
|
for _ in range(steps):
|
|
qs.append(q)
|
|
ps.append(p)
|
|
q, p = breath_step(q, p, omega, dt)
|
|
return np.array(qs), np.array(ps)
|
|
|
|
if __name__ == "__main__":
|
|
# Simple demonstration: simulate and split into mirror components
|
|
qs, ps = run_oscillator(steps=1024, dt=0.01, omega=1.0)
|
|
if hilbert is not None:
|
|
pos, neg = mirror_split(qs)
|
|
print(f"First few positive components: {pos[:5]}")
|
|
print(f"First few negative components: {neg[:5]}")
|
|
else:
|
|
print("Scipy not installed; cannot compute mirror components.")
|