Advertisement
DarkDevourer

5 & 6

May 13th, 2021
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. (defun abs (x)
  2. (if (< x 0) (* x -1) x)
  3. )
  4. ABS
  5.  
  6. (defun inf_fact ()
  7. (let ((pprev 0) (pcur 0))
  8. (loop (setq pprev pcur) (setq pcur (+ 2 (/ 3.0 (+ 2.0 pcur))))
  9. (when (< (abs (- pcur pprev)) 0.000001) (return pcur)))
  10. )
  11. )
  12. ABS
  13. INF_FACT
  14.  
  15. (inf_fact)
  16. 2.645752
  17.  
  18.  
  19. (defun inf_fact ()
  20. (let ((pprev 0) (pcur 0))
  21. (loop (setq pprev pcur) (setq pcur (+ 2 (/ 3.0 (+ 2.0 pcur))))
  22. (when (< (abs (- pcur pprev)) 0.000001) (return pcur)))
  23. )
  24. )
  25.  
  26. (defun cycle_sqrt23 (n)
  27. (let ((pcur 0) (i 0))
  28. (loop (setq pcur (/ 22.0 (+ 2.0 pcur))) (setq i (1+ i))
  29. (when (= i n) (return (1+ pcur))))
  30. )
  31. )
  32. CYCLE_SQRT23
  33.  
  34. (cycle_sqrt23 40)
  35. 4.795831
  36.  
  37. (defun rec_sqrt23 (w n)
  38. (cond ((= n 0) (/ (+ w (/ 23.0 w)) 2))
  39. (T (rec_sqrt23 (/ (+ w (/ 23.0 w)) 2) (1- n)))
  40. )
  41. )
  42. REC_SQRT23
  43.  
  44. (rec_sqrt23 23 8)
  45. 4.795832
  46.  
  47. (defun cycle_sqrt7 ()
  48. (let ((i 7)(pprev 1) (pcur (/ (* 2 4 6)(* 1 3 5))))
  49. (loop (setq pprev pcur) (setq pcur (/ (* (+ i 2.0) (+ i 4) (+ i 6))(* (+ i 1) (+ i 3) (+ i 5)))) (setq i (+ i 7))
  50. (when (< (abs (- pcur pprev)) 0.000001) (return pcur)))
  51. )
  52. )
  53. CYCLE_SQRT7
  54.  
  55. (cycle_sqrt7)
  56. 1.00073
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement