"""Original hypothetical iid Normal model; known population sigma, unknown mean.
No external packages. Run: python3 prediction-confidence-interval.py
Does not fit a model, submit orders, or establish real-world coverage.
"""
from math import sqrt
from statistics import NormalDist

center = 50.0
sigma = 10.0  # stipulated known population SD, NOT an estimated sample SD
z = NormalDist().inv_cdf(0.975)
print(f"Normal 97.5th percentile: {z:.12f}")
for n in (25, 100):
    mean_variance = sigma**2 / n
    new_observation_variance = sigma**2 + mean_variance
    mean_half_width = z * sqrt(mean_variance)
    prediction_half_width = z * sqrt(new_observation_variance)
    print(f"n={n}; mean variance={mean_variance}; "
          f"new-minus-mean variance={new_observation_variance}")
    print(f"Mean CI: [{center-mean_half_width:.8f}, "
          f"{center+mean_half_width:.8f}]")
    print(f"New observation PI: [{center-prediction_half_width:.8f}, "
          f"{center+prediction_half_width:.8f}]")
n = m = 25
future_average_half_width = z * sigma * sqrt(1/n + 1/m)
print(f"Future mean of m={m}, based on n={n}: "
      f"[{center-future_average_half_width:.8f}, "
      f"{center+future_average_half_width:.8f}]")
print("These are known-sigma Normal calculations, not estimated-sigma t intervals.")
