# Desktop Python teaching example. Numerical inputs are illustrative.
def correct_x(x_est, landmark_x, alpha, expected, fresh, gate_m=0.08):
    if not 0 <= alpha <= 1:
        raise ValueError("alpha outside [0, 1]")
    residual = landmark_x - x_est
    if not expected or not fresh or abs(residual) > gate_m:
        return x_est, "rejected"
    return x_est + alpha * residual, "accepted"

for case in [(0.54, True, True), (0.8, True, True), (0.54, False, True)]:
    x, expected, fresh = case
    print(correct_x(x, 0.5, 0.5, expected, fresh))
