<commit_before>
type Time = Float
type Position = Float
type Velocity = Float
type Energy = Float
type Force = Float
type Mass = Float
type SpringConstant = Float
type Momentum = Float
type PositionPath      = Time -> Position
type ConfigurationPath = Time -> Position -> Velocity

-- pp2cp :: PositionPath -> ConfigurationPath

-- https://en.wikipedia.org/wiki/Harmonic_oscillator
springForce :: SpringConstant -> Position -> Force
springForce k x | k > 0 = - k * x

springEnergy :: SpringConstant -> Position -> Energy
springEnergy k x = -1 * integrate (springForce k) 0 x

-- integrate takes a function f(x) (Float -> Float)
-- two integration bounds, and returns the integral
integrate :: (Float -> Float) -> Float -> Float -> Float
integrate :: f min max = snd . integrateQNGSource f min max

-- http://www.lecture-notes.co.uk/susskind/classical-mechanics/lecture-5/harmonic-oscillator/
springLagrangian :: Mass -> Configuration -> Energy
springLagrangian m (x, v) = 0.5 * m * v * v - 0.5 * k * x * x

springHamiltonian :: Mass -> Configuration -> Energy
springHamiltonian m (x, v) = conjugateMomentum * v - springLagrangian m (x, v)

--conjugateMomentum = del_v L
conjugateMomentum :: (Mass -> Configuration -> Energy) -> (Mass -> Configuration -> Momentum)
conjugateMomentum L = D . L (v, x) v





<commit_msg>Working.<commit_after>
-- todo: dimensions?
-- kinematics
type Time = Double
type TimeInterval = Double
type Position = Double
type Velocity = Double
type Momentum = Double
type Configuration  = (Position, Velocity)
type State          = (Time, Position, Velocity)
type PositionF      = Time -> Position
type VelocityF      = Time -> Velocity
type ConfigurationF = Time -> Configuration
-- dynamics
type Energy = Double
type Force = Double
type Mass = Double
type SpringConstant = Double
type LagrangianF    = Mass -> SpringConstant -> Configuration -> Energy
type ForceF         = SpringConstant -> Time -> Force

pf2vf :: PositionF -> TimeInterval -> VelocityF
pf2vf x dt = (\t -> v(t))
    where v(t) = (x(t + dt) - x(t)) / dt

pf2cf :: PositionF -> TimeInterval -> ConfigurationF
pf2cf x dt = (\t -> (x t, pf2vf x dt $ t))

-- http://www.lecture-notes.co.uk/susskind/classical-mechanics/lecture-5/harmonic-oscillator/
lagrangian :: LagrangianF
lagrangian m k (x, v) = 0.5 * m * v * v - 0.5 * k * x * x

force :: LagrangianF -> ForceF
force l = (l(v + dv) - l(v)) / dv

main = do
    print $ config 5
    where
        x  = (\t -> t * t)
        dt = 0.00001
        config = pf2cf x dt

-- https://en.wikipedia.org/wiki/Harmonic_oscillator
-- springForce :: SpringConstant -> Position -> Force
-- springForce k x | k > 0 = - k * x

-- springEnergy :: SpringConstant -> Position -> Energy
-- springEnergy k x = -1 * integrate (springForce k) 0 x

-- integrate takes a function f(x) (Double -> Double)
-- two integration bounds, and returns the integral
-- integrate :: (Double -> Double) -> Double -> Double -> Double
-- integrate :: f min max = snd . integrateQNGSource f min max

-- springHamiltonian :: Mass -> Configuration -> Energy
-- springHamiltonian m (x, v) = conjugateMomentum * v - springLagrangian m (x, v)

--conjugateMomentum = del_v L
-- conjugateMomentum :: (Mass -> Configuration -> Energy) -> (Mass -> Configuration -> Momentum)
-- conjugateMomentum L = D . L (v, x) v
{'fraction_non_alphanumeric': 0.12877871825876663, 'fraction_numerical': 0.009068923821039904, 'mean_word_length': 3.12079701120797, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 59, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7351620', 'n_tokens_mistral': 1069, 'n_tokens_neox': 988, 'n_words': 358}