/print {dup ==} def % /f /df x0 N /newton { 4 dict begin /N exch def /x0 exch def /df exch cvx def /f exch cvx def (a) == x0 N { (b) == % x on stack dup dup % x x x print f % x x fx print ( x, fx --------------------) == exch df % x fx dfx div sub % x - fx/dfx } repeat dup f exch % fx x on stack end } def % testing ------------------------------------- % x*x - 2 /square {dup mul 2 sub} def /dsquare {2 mul} def /E 2.718281828 def % x - exp(-x), 1 + exp(-x) /F { dup neg % x -x E exch exp % x e^-x sub } def /dF { neg E exch exp % e^-x 1 exch % 1 e^-x add } def /F /dF 1 10 newton