
(FPCore (u1 u2) :precision binary64 (+ (* (* (/ 1.0 6.0) (pow (* -2.0 (log u1)) 0.5)) (cos (* (* 2.0 PI) u2))) 0.5))
double code(double u1, double u2) {
return (((1.0 / 6.0) * pow((-2.0 * log(u1)), 0.5)) * cos(((2.0 * ((double) M_PI)) * u2))) + 0.5;
}
public static double code(double u1, double u2) {
return (((1.0 / 6.0) * Math.pow((-2.0 * Math.log(u1)), 0.5)) * Math.cos(((2.0 * Math.PI) * u2))) + 0.5;
}
def code(u1, u2): return (((1.0 / 6.0) * math.pow((-2.0 * math.log(u1)), 0.5)) * math.cos(((2.0 * math.pi) * u2))) + 0.5
function code(u1, u2) return Float64(Float64(Float64(Float64(1.0 / 6.0) * (Float64(-2.0 * log(u1)) ^ 0.5)) * cos(Float64(Float64(2.0 * pi) * u2))) + 0.5) end
function tmp = code(u1, u2) tmp = (((1.0 / 6.0) * ((-2.0 * log(u1)) ^ 0.5)) * cos(((2.0 * pi) * u2))) + 0.5; end
code[u1_, u2_] := N[(N[(N[(N[(1.0 / 6.0), $MachinePrecision] * N[Power[N[(-2.0 * N[Log[u1], $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(N[(2.0 * Pi), $MachinePrecision] * u2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5
\end{array}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (u1 u2) :precision binary64 (+ (* (* (/ 1.0 6.0) (pow (* -2.0 (log u1)) 0.5)) (cos (* (* 2.0 PI) u2))) 0.5))
double code(double u1, double u2) {
return (((1.0 / 6.0) * pow((-2.0 * log(u1)), 0.5)) * cos(((2.0 * ((double) M_PI)) * u2))) + 0.5;
}
public static double code(double u1, double u2) {
return (((1.0 / 6.0) * Math.pow((-2.0 * Math.log(u1)), 0.5)) * Math.cos(((2.0 * Math.PI) * u2))) + 0.5;
}
def code(u1, u2): return (((1.0 / 6.0) * math.pow((-2.0 * math.log(u1)), 0.5)) * math.cos(((2.0 * math.pi) * u2))) + 0.5
function code(u1, u2) return Float64(Float64(Float64(Float64(1.0 / 6.0) * (Float64(-2.0 * log(u1)) ^ 0.5)) * cos(Float64(Float64(2.0 * pi) * u2))) + 0.5) end
function tmp = code(u1, u2) tmp = (((1.0 / 6.0) * ((-2.0 * log(u1)) ^ 0.5)) * cos(((2.0 * pi) * u2))) + 0.5; end
code[u1_, u2_] := N[(N[(N[(N[(1.0 / 6.0), $MachinePrecision] * N[Power[N[(-2.0 * N[Log[u1], $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(N[(2.0 * Pi), $MachinePrecision] * u2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5
\end{array}
(FPCore (u1 u2) :precision binary64 (+ (* 0.16666666666666666 (* (cos (* 2.0 (* u2 PI))) (sqrt (* -2.0 (log u1))))) 0.5))
double code(double u1, double u2) {
return (0.16666666666666666 * (cos((2.0 * (u2 * ((double) M_PI)))) * sqrt((-2.0 * log(u1))))) + 0.5;
}
public static double code(double u1, double u2) {
return (0.16666666666666666 * (Math.cos((2.0 * (u2 * Math.PI))) * Math.sqrt((-2.0 * Math.log(u1))))) + 0.5;
}
def code(u1, u2): return (0.16666666666666666 * (math.cos((2.0 * (u2 * math.pi))) * math.sqrt((-2.0 * math.log(u1))))) + 0.5
function code(u1, u2) return Float64(Float64(0.16666666666666666 * Float64(cos(Float64(2.0 * Float64(u2 * pi))) * sqrt(Float64(-2.0 * log(u1))))) + 0.5) end
function tmp = code(u1, u2) tmp = (0.16666666666666666 * (cos((2.0 * (u2 * pi))) * sqrt((-2.0 * log(u1))))) + 0.5; end
code[u1_, u2_] := N[(N[(0.16666666666666666 * N[(N[Cos[N[(2.0 * N[(u2 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(-2.0 * N[Log[u1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]
\begin{array}{l}
\\
0.16666666666666666 \cdot \left(\cos \left(2 \cdot \left(u2 \cdot \pi\right)\right) \cdot \sqrt{-2 \cdot \log u1}\right) + 0.5
\end{array}
Initial program 99.4%
Taylor expanded in u1 around 0
Applied rewrites99.4%
(FPCore (u1 u2) :precision binary64 (+ (* (/ (sqrt (* -2.0 (log u1))) 6.0) (+ 1.0 (* -2.0 (pow u2 2.0)))) 0.5))
double code(double u1, double u2) {
return ((sqrt((-2.0 * log(u1))) / 6.0) * (1.0 + (-2.0 * pow(u2, 2.0)))) + 0.5;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(u1, u2)
use fmin_fmax_functions
real(8), intent (in) :: u1
real(8), intent (in) :: u2
code = ((sqrt(((-2.0d0) * log(u1))) / 6.0d0) * (1.0d0 + ((-2.0d0) * (u2 ** 2.0d0)))) + 0.5d0
end function
public static double code(double u1, double u2) {
return ((Math.sqrt((-2.0 * Math.log(u1))) / 6.0) * (1.0 + (-2.0 * Math.pow(u2, 2.0)))) + 0.5;
}
def code(u1, u2): return ((math.sqrt((-2.0 * math.log(u1))) / 6.0) * (1.0 + (-2.0 * math.pow(u2, 2.0)))) + 0.5
function code(u1, u2) return Float64(Float64(Float64(sqrt(Float64(-2.0 * log(u1))) / 6.0) * Float64(1.0 + Float64(-2.0 * (u2 ^ 2.0)))) + 0.5) end
function tmp = code(u1, u2) tmp = ((sqrt((-2.0 * log(u1))) / 6.0) * (1.0 + (-2.0 * (u2 ^ 2.0)))) + 0.5; end
code[u1_, u2_] := N[(N[(N[(N[Sqrt[N[(-2.0 * N[Log[u1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / 6.0), $MachinePrecision] * N[(1.0 + N[(-2.0 * N[Power[u2, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{-2 \cdot \log u1}}{6} \cdot \left(1 + -2 \cdot {u2}^{2}\right) + 0.5
\end{array}
Initial program 99.4%
Applied rewrites98.1%
Taylor expanded in u2 around 0
Applied rewrites98.1%
(FPCore (u1 u2) :precision binary64 (+ (* (/ (sqrt (* -2.0 (log u1))) 6.0) 1.0) 0.5))
double code(double u1, double u2) {
return ((sqrt((-2.0 * log(u1))) / 6.0) * 1.0) + 0.5;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(u1, u2)
use fmin_fmax_functions
real(8), intent (in) :: u1
real(8), intent (in) :: u2
code = ((sqrt(((-2.0d0) * log(u1))) / 6.0d0) * 1.0d0) + 0.5d0
end function
public static double code(double u1, double u2) {
return ((Math.sqrt((-2.0 * Math.log(u1))) / 6.0) * 1.0) + 0.5;
}
def code(u1, u2): return ((math.sqrt((-2.0 * math.log(u1))) / 6.0) * 1.0) + 0.5
function code(u1, u2) return Float64(Float64(Float64(sqrt(Float64(-2.0 * log(u1))) / 6.0) * 1.0) + 0.5) end
function tmp = code(u1, u2) tmp = ((sqrt((-2.0 * log(u1))) / 6.0) * 1.0) + 0.5; end
code[u1_, u2_] := N[(N[(N[(N[Sqrt[N[(-2.0 * N[Log[u1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / 6.0), $MachinePrecision] * 1.0), $MachinePrecision] + 0.5), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{-2 \cdot \log u1}}{6} \cdot 1 + 0.5
\end{array}
Initial program 99.4%
Applied rewrites98.1%
Taylor expanded in u2 around 0
Applied rewrites98.1%
(FPCore (u1 u2) :precision binary64 (+ 0.5 (* 0.16666666666666666 (sqrt (* -2.0 (log u1))))))
double code(double u1, double u2) {
return 0.5 + (0.16666666666666666 * sqrt((-2.0 * log(u1))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(u1, u2)
use fmin_fmax_functions
real(8), intent (in) :: u1
real(8), intent (in) :: u2
code = 0.5d0 + (0.16666666666666666d0 * sqrt(((-2.0d0) * log(u1))))
end function
public static double code(double u1, double u2) {
return 0.5 + (0.16666666666666666 * Math.sqrt((-2.0 * Math.log(u1))));
}
def code(u1, u2): return 0.5 + (0.16666666666666666 * math.sqrt((-2.0 * math.log(u1))))
function code(u1, u2) return Float64(0.5 + Float64(0.16666666666666666 * sqrt(Float64(-2.0 * log(u1))))) end
function tmp = code(u1, u2) tmp = 0.5 + (0.16666666666666666 * sqrt((-2.0 * log(u1)))); end
code[u1_, u2_] := N[(0.5 + N[(0.16666666666666666 * N[Sqrt[N[(-2.0 * N[Log[u1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 + 0.16666666666666666 \cdot \sqrt{-2 \cdot \log u1}
\end{array}
Initial program 99.4%
Taylor expanded in u2 around 0
Applied rewrites98.0%
(FPCore (u1 u2) :precision binary64 PI)
double code(double u1, double u2) {
return (double) M_PI;
}
public static double code(double u1, double u2) {
return Math.PI;
}
def code(u1, u2): return math.pi
function code(u1, u2) return pi end
function tmp = code(u1, u2) tmp = pi; end
code[u1_, u2_] := Pi
\begin{array}{l}
\\
\pi
\end{array}
Initial program 99.4%
Applied rewrites98.1%
Applied rewrites20.1%
(FPCore (u1 u2) :precision binary64 2.0)
double code(double u1, double u2) {
return 2.0;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(u1, u2)
use fmin_fmax_functions
real(8), intent (in) :: u1
real(8), intent (in) :: u2
code = 2.0d0
end function
public static double code(double u1, double u2) {
return 2.0;
}
def code(u1, u2): return 2.0
function code(u1, u2) return 2.0 end
function tmp = code(u1, u2) tmp = 2.0; end
code[u1_, u2_] := 2.0
\begin{array}{l}
\\
2
\end{array}
Initial program 99.4%
Applied rewrites98.1%
Applied rewrites18.9%
(FPCore (u1 u2) :precision binary64 1.0)
double code(double u1, double u2) {
return 1.0;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(u1, u2)
use fmin_fmax_functions
real(8), intent (in) :: u1
real(8), intent (in) :: u2
code = 1.0d0
end function
public static double code(double u1, double u2) {
return 1.0;
}
def code(u1, u2): return 1.0
function code(u1, u2) return 1.0 end
function tmp = code(u1, u2) tmp = 1.0; end
code[u1_, u2_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 99.4%
Applied rewrites98.1%
Applied rewrites17.2%
herbie shell --seed 2025159
(FPCore (u1 u2)
:name "normal distribution"
:precision binary64
:pre (and (and (<= 0.0 u1) (<= u1 1.0)) (and (<= 0.0 u2) (<= u2 1.0)))
(+ (* (* (/ 1.0 6.0) (pow (* -2.0 (log u1)) 0.5)) (cos (* (* 2.0 PI) u2))) 0.5))