flo.fun 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #import std
  2. #import nat
  3. #comment -[
  4. This module contains some floating point functions and constants.
  5. Copyright (C) 2007-2010 Dennis Furey]-
  6. #library+
  7. eps = 5e-16
  8. inf = -{wgfzg]ftVjBk=hTZd@L\}-
  9. nan = -{wgfzg]ftVjBk=hTY<PP<}-
  10. ninf = -{wgfzg]ftVjBk=hT[<AA<}-
  11. pi = 3.14159265358979323846
  12. #optimize+
  13. abs = math..fabs
  14. ari = ~&?\0!! "n". ("l","h"). plus/*"l" times^(~&l,float@r)* -*iota"n" div(minus/"h" "l",float predecessor "n")
  15. acos = math..acos
  16. asin = math..asin
  17. atan = math..atan
  18. atanh = math..atanh
  19. bus = math..bus
  20. correlation = div^/covariance times+ stdev~~
  21. cos = math..cos
  22. covariance = mean+ (* times+ minus~~)^DbbIS/mean~~ ~&p
  23. cu_prod = :/1.; ~&ar^& ^rlfPrlart3XRC/~& times+~&alrhPX
  24. cu_sum = :/0.; ~&ar^& ^rlfPrlart3XRC/~& plus+~&alrhPX
  25. derivative = // gsldif..central
  26. div = math..div
  27. eudist = sqrt+ iprod+ ~&iiX+ minus*p
  28. exp = math..exp
  29. fleq = math..islessequal
  30. float = ~&/(0.,1.); ~&r->ll ^\~&rt ^\-+times/2.,~&lr+- ~&rh?/plus+~&l ~&ll
  31. floatz = ~&?\0.! ~&z?(~&NiX,~&NNXyX); (~&l?\~&r negative@r)^|/~& float
  32. geo = exp*++ ln~~;+ ari
  33. integral = "f". ("a","b"). gslint..qagx ("f","a","b")
  34. iprod = plus:-0.+ times*p
  35. levin_sum = ~&l+ gslevu..utrunc
  36. levin_limit = plus^/~&h levin_sum+ minus*typ
  37. ln = math..log
  38. max = fleq?/~&r ~&l
  39. mean = div^/plus:-0. float+ length
  40. min = fleq?/~&l ~&r
  41. minus = math..sub
  42. N = rmath..pnorm\(0.,1.,&,0)
  43. negative = minus/0.
  44. nth_deriv = "n". -++- (* "t". // gsldif..t_central\"t") (times/2.)|\x (pow/1.0e-8 div/1. float "n")!* iota "n"
  45. nth_diff = "n". rep"n" minus*typ
  46. oprod = @pbaatPahPfatPRDCaqPO minus*lihBPrrlXPrQS+ num+ iprod~~+* ~&lyPrtPXltPryPXX
  47. plus = math..add
  48. pow = math..pow
  49. printf = math..asprintf
  50. Q = rmath..qnorm\(0.,1.,&,0)
  51. rand = mtwist..u_cont+ 0!
  52. sgn = 0.?=/~& fleq/0.?/1.! -1.!
  53. sin = math..sin
  54. sqr = times+ ~&iiX
  55. sqrt = math..sqrt
  56. stdev = sqrt+ variance
  57. strtod = math..strtod
  58. tan = math..tan
  59. tanh = math..tanh
  60. times = math..mul
  61. variance = mean+ (sqr+ minus)^*D/mean ~&
  62. vid = math..vid
  63. Z = rand; rmath..qnorm\(0.,1.,&,0)
  64. zeroid = math..iszero
  65. root_finder = # takes ((lower bound,upper bound),function,tolerance)
  66. ^(^bbI/~&l ~&H~~+~&rlPlG,~&r); (fleq^/~&rr abs+ minus+ ~&lbl)->lll ^\~&r -+
  67. (==+ sgn~~)?rrPlllr3X/~&rllr2X ~&lll2rX,
  68. ^/~& ^rlrHX/~&rl div\2.+ plus+ ~&lbl+-