<commit_before>proc verlet(pos_in, acc, dt: float): float =
  var
    pos: float = pos_in
    prevPos: float = pos
    time: float = 0.0
    tempPos: float

  while pos > 0.0:
    time += dt
    tempPos = pos
    pos = pos * 2 - prevPos + acc * dt * dt
    prevPos = tempPos

  return time

proc stormerVerlet(pos_in, acc, dt: float): (float, float) =
  var
    pos: float = pos_in
    prevPos: float = pos
    time: float = 0.0
    vel: float = 0.0
    tempPos: float

  while pos > 0.0:
    time += dt
    tempPos = pos
    pos = pos * 2 - prevPos + acc * dt * dt
    prevPos = tempPos

    vel += acc * dt

  return (time, vel)

proc velocityVerlet(pos_in, acc, dt: float): (float, float) =
  var
    pos: float = pos_in
    time: float = 0.0
    vel: float = 0.0

  while pos > 0.0:
    time += dt
    pos += vel * dt + 0.5 * acc * dt * dt
    vel += acc * dt

  return (time, vel)

let timeV = verlet(5.0, -10.0, 0.01)
echo "Time for Verlet integration is: ", timeV

let (timeSV, velSV) = stormerVerlet(5.0, -10.0, 0.01)
echo "Time for Stormer Verlet integration is: ", timeSV
echo "Velocity for Stormer Verlet integration is: ", velSV

let (timeVV, velVV) = velocityVerlet(5.0, -10.0, 0.01)
echo "Time for velocity Verlet integration is: ", timeVV
echo "Velocity for velocity Verlet integration is: ", velVV<commit_msg>Make Verlet integration in Nim more idiomatic (#782)<commit_after>func verlet(pos_in, acc, dt: float): float =
  var
    pos: float = pos_in
    prevPos: float = pos
    time: float = 0.0
    tempPos: float

  while pos > 0.0:
    time += dt
    tempPos = pos
    pos = pos * 2 - prevPos + acc * dt * dt
    prevPos = tempPos

  time

func stormerVerlet(pos_in, acc, dt: float): (float, float) =
  var
    pos: float = pos_in
    prevPos: float = pos
    time: float = 0.0
    vel: float = 0.0
    tempPos: float

  while pos > 0.0:
    time += dt
    tempPos = pos
    pos = pos * 2 - prevPos + acc * dt * dt
    prevPos = tempPos

    vel += acc * dt

  (time, vel)

func velocityVerlet(pos_in, acc, dt: float): (float, float) =
  var
    pos: float = pos_in
    time: float = 0.0
    vel: float = 0.0

  while pos > 0.0:
    time += dt
    pos += vel * dt + 0.5 * acc * dt * dt
    vel += acc * dt

  (time, vel)

when isMainModule:
  let timeV = verlet(5.0, -10.0, 0.01)
  echo "Time for Verlet integration is: ", timeV

  let (timeSV, velSV) = stormerVerlet(5.0, -10.0, 0.01)
  echo "Time for Stormer Verlet integration is: ", timeSV
  echo "Velocity for Stormer Verlet integration is: ", velSV

  let (timeVV, velVV) = velocityVerlet(5.0, -10.0, 0.01)
  echo "Time for velocity Verlet integration is: ", timeVV
  echo "Velocity for velocity Verlet integration is: ", velVV
{'fraction_non_alphanumeric': 0.12060673325934147, 'fraction_numerical': 0.03366629670736219, 'mean_word_length': 2.5254237288135593, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1553973', 'n_tokens_mistral': 1056, 'n_tokens_neox': 985, 'n_words': 347}