# L-7 MCS 507 Wed 6 Sep 2023 : intvalnewton.py

"""
First we show a naive use of interval arithmetic in Newton's method.
with the mpmath package.  Then we do it in proper manner.
"""

from mpmath import iv
iv.dps = 15
print('naive interval Newton :')
X = iv.mpf(['1.4', '1.5'])
for i in range(5):
    X = X - (X**2 - 2)/(2*X)
    print(X)
print('proper interval Newton :')
X = iv.mpf(['1.4', '1.5'])
for i in range(5):
    X = X.mid
    X = X - (X**2 - 2)/(2*X)
    print(X)
