
(FPCore (x y z t) :precision binary64 (* (* (- (* x 0.5) y) (sqrt (* z 2.0))) (exp (/ (* t t) 2.0))))
double code(double x, double y, double z, double t) {
return (((x * 0.5) - y) * sqrt((z * 2.0))) * exp(((t * t) / 2.0));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((x * 0.5d0) - y) * sqrt((z * 2.0d0))) * exp(((t * t) / 2.0d0))
end function
public static double code(double x, double y, double z, double t) {
return (((x * 0.5) - y) * Math.sqrt((z * 2.0))) * Math.exp(((t * t) / 2.0));
}
def code(x, y, z, t): return (((x * 0.5) - y) * math.sqrt((z * 2.0))) * math.exp(((t * t) / 2.0))
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(z * 2.0))) * exp(Float64(Float64(t * t) / 2.0))) end
function tmp = code(x, y, z, t) tmp = (((x * 0.5) - y) * sqrt((z * 2.0))) * exp(((t * t) / 2.0)); end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(z * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(t * t), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot e^{\frac{t \cdot t}{2}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (* (* (- (* x 0.5) y) (sqrt (* z 2.0))) (exp (/ (* t t) 2.0))))
double code(double x, double y, double z, double t) {
return (((x * 0.5) - y) * sqrt((z * 2.0))) * exp(((t * t) / 2.0));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((x * 0.5d0) - y) * sqrt((z * 2.0d0))) * exp(((t * t) / 2.0d0))
end function
public static double code(double x, double y, double z, double t) {
return (((x * 0.5) - y) * Math.sqrt((z * 2.0))) * Math.exp(((t * t) / 2.0));
}
def code(x, y, z, t): return (((x * 0.5) - y) * math.sqrt((z * 2.0))) * math.exp(((t * t) / 2.0))
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(z * 2.0))) * exp(Float64(Float64(t * t) / 2.0))) end
function tmp = code(x, y, z, t) tmp = (((x * 0.5) - y) * sqrt((z * 2.0))) * exp(((t * t) / 2.0)); end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(z * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(t * t), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot e^{\frac{t \cdot t}{2}}
\end{array}
(FPCore (x y z t) :precision binary64 (* (* (- (* x 0.5) y) (sqrt (* z 2.0))) (exp (/ (* t t) 2.0))))
double code(double x, double y, double z, double t) {
return (((x * 0.5) - y) * sqrt((z * 2.0))) * exp(((t * t) / 2.0));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((x * 0.5d0) - y) * sqrt((z * 2.0d0))) * exp(((t * t) / 2.0d0))
end function
public static double code(double x, double y, double z, double t) {
return (((x * 0.5) - y) * Math.sqrt((z * 2.0))) * Math.exp(((t * t) / 2.0));
}
def code(x, y, z, t): return (((x * 0.5) - y) * math.sqrt((z * 2.0))) * math.exp(((t * t) / 2.0))
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(z * 2.0))) * exp(Float64(Float64(t * t) / 2.0))) end
function tmp = code(x, y, z, t) tmp = (((x * 0.5) - y) * sqrt((z * 2.0))) * exp(((t * t) / 2.0)); end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(z * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(t * t), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot e^{\frac{t \cdot t}{2}}
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (exp (/ (* t t) 2.0))))
(if (or (<= x -4.2e-21) (not (<= x 1.08e-13)))
(* t_1 (* x (sqrt (* 0.5 z))))
(* t_1 (- (* y (sqrt (* z 2.0))))))))
double code(double x, double y, double z, double t) {
double t_1 = exp(((t * t) / 2.0));
double tmp;
if ((x <= -4.2e-21) || !(x <= 1.08e-13)) {
tmp = t_1 * (x * sqrt((0.5 * z)));
} else {
tmp = t_1 * -(y * sqrt((z * 2.0)));
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = exp(((t * t) / 2.0d0))
if ((x <= (-4.2d-21)) .or. (.not. (x <= 1.08d-13))) then
tmp = t_1 * (x * sqrt((0.5d0 * z)))
else
tmp = t_1 * -(y * sqrt((z * 2.0d0)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = Math.exp(((t * t) / 2.0));
double tmp;
if ((x <= -4.2e-21) || !(x <= 1.08e-13)) {
tmp = t_1 * (x * Math.sqrt((0.5 * z)));
} else {
tmp = t_1 * -(y * Math.sqrt((z * 2.0)));
}
return tmp;
}
def code(x, y, z, t): t_1 = math.exp(((t * t) / 2.0)) tmp = 0 if (x <= -4.2e-21) or not (x <= 1.08e-13): tmp = t_1 * (x * math.sqrt((0.5 * z))) else: tmp = t_1 * -(y * math.sqrt((z * 2.0))) return tmp
function code(x, y, z, t) t_1 = exp(Float64(Float64(t * t) / 2.0)) tmp = 0.0 if ((x <= -4.2e-21) || !(x <= 1.08e-13)) tmp = Float64(t_1 * Float64(x * sqrt(Float64(0.5 * z)))); else tmp = Float64(t_1 * Float64(-Float64(y * sqrt(Float64(z * 2.0))))); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = exp(((t * t) / 2.0)); tmp = 0.0; if ((x <= -4.2e-21) || ~((x <= 1.08e-13))) tmp = t_1 * (x * sqrt((0.5 * z))); else tmp = t_1 * -(y * sqrt((z * 2.0))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Exp[N[(N[(t * t), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -4.2e-21], N[Not[LessEqual[x, 1.08e-13]], $MachinePrecision]], N[(t$95$1 * N[(x * N[Sqrt[N[(0.5 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 * (-N[(y * N[Sqrt[N[(z * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision])), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := e^{\frac{t \cdot t}{2}}\\
\mathbf{if}\;x \leq -4.2 \cdot 10^{-21} \lor \neg \left(x \leq 1.08 \cdot 10^{-13}\right):\\
\;\;\;\;t_1 \cdot \left(x \cdot \sqrt{0.5 \cdot z}\right)\\
\mathbf{else}:\\
\;\;\;\;t_1 \cdot \left(-y \cdot \sqrt{z \cdot 2}\right)\\
\end{array}
\end{array}
if x < -4.20000000000000025e-21 or 1.0799999999999999e-13 < x Initial program 99.8%
add-sqr-sqrt52.8%
sqrt-unprod41.1%
*-commutative41.1%
*-commutative41.1%
swap-sqr40.3%
add-sqr-sqrt40.3%
pow240.3%
fma-neg40.3%
Applied egg-rr40.3%
associate-*l*40.3%
fma-neg40.3%
*-commutative40.3%
Simplified40.3%
Taylor expanded in x around inf 39.6%
associate-*r*39.6%
Simplified39.6%
Taylor expanded in x around 0 84.0%
expm1-log1p-u50.7%
expm1-udef40.5%
associate-*l*40.5%
sqrt-unprod40.5%
Applied egg-rr40.5%
expm1-def50.7%
expm1-log1p84.1%
Simplified84.1%
if -4.20000000000000025e-21 < x < 1.0799999999999999e-13Initial program 99.9%
Taylor expanded in x around 0 86.0%
mul-1-neg86.0%
associate-*l*85.9%
Simplified85.9%
*-commutative85.9%
sqrt-prod86.2%
Applied egg-rr86.2%
Final simplification85.2%
(FPCore (x y z t) :precision binary64 (* (exp (/ (* t t) 2.0)) (* x (sqrt (* 0.5 z)))))
double code(double x, double y, double z, double t) {
return exp(((t * t) / 2.0)) * (x * sqrt((0.5 * z)));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = exp(((t * t) / 2.0d0)) * (x * sqrt((0.5d0 * z)))
end function
public static double code(double x, double y, double z, double t) {
return Math.exp(((t * t) / 2.0)) * (x * Math.sqrt((0.5 * z)));
}
def code(x, y, z, t): return math.exp(((t * t) / 2.0)) * (x * math.sqrt((0.5 * z)))
function code(x, y, z, t) return Float64(exp(Float64(Float64(t * t) / 2.0)) * Float64(x * sqrt(Float64(0.5 * z)))) end
function tmp = code(x, y, z, t) tmp = exp(((t * t) / 2.0)) * (x * sqrt((0.5 * z))); end
code[x_, y_, z_, t_] := N[(N[Exp[N[(N[(t * t), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] * N[(x * N[Sqrt[N[(0.5 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{\frac{t \cdot t}{2}} \cdot \left(x \cdot \sqrt{0.5 \cdot z}\right)
\end{array}
Initial program 99.8%
add-sqr-sqrt49.8%
sqrt-unprod37.3%
*-commutative37.3%
*-commutative37.3%
swap-sqr35.2%
add-sqr-sqrt35.2%
pow235.2%
fma-neg35.2%
Applied egg-rr35.2%
associate-*l*35.2%
fma-neg35.2%
*-commutative35.2%
Simplified35.2%
Taylor expanded in x around inf 25.1%
associate-*r*25.1%
Simplified25.1%
Taylor expanded in x around 0 55.8%
expm1-log1p-u39.4%
expm1-udef21.1%
associate-*l*21.1%
sqrt-unprod21.1%
Applied egg-rr21.1%
expm1-def39.4%
expm1-log1p55.9%
Simplified55.9%
Final simplification55.9%
(FPCore (x y z t) :precision binary64 (* x (* (sqrt 0.5) (sqrt z))))
double code(double x, double y, double z, double t) {
return x * (sqrt(0.5) * sqrt(z));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x * (sqrt(0.5d0) * sqrt(z))
end function
public static double code(double x, double y, double z, double t) {
return x * (Math.sqrt(0.5) * Math.sqrt(z));
}
def code(x, y, z, t): return x * (math.sqrt(0.5) * math.sqrt(z))
function code(x, y, z, t) return Float64(x * Float64(sqrt(0.5) * sqrt(z))) end
function tmp = code(x, y, z, t) tmp = x * (sqrt(0.5) * sqrt(z)); end
code[x_, y_, z_, t_] := N[(x * N[(N[Sqrt[0.5], $MachinePrecision] * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(\sqrt{0.5} \cdot \sqrt{z}\right)
\end{array}
Initial program 99.8%
add-sqr-sqrt49.8%
sqrt-unprod37.3%
*-commutative37.3%
*-commutative37.3%
swap-sqr35.2%
add-sqr-sqrt35.2%
pow235.2%
fma-neg35.2%
Applied egg-rr35.2%
associate-*l*35.2%
fma-neg35.2%
*-commutative35.2%
Simplified35.2%
Taylor expanded in x around inf 25.1%
associate-*r*25.1%
Simplified25.1%
Taylor expanded in x around 0 55.8%
Taylor expanded in t around 0 26.8%
associate-*l*26.7%
*-commutative26.7%
Simplified26.7%
Final simplification26.7%
(FPCore (x y z t) :precision binary64 (* (* x (sqrt 0.5)) (sqrt z)))
double code(double x, double y, double z, double t) {
return (x * sqrt(0.5)) * sqrt(z);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x * sqrt(0.5d0)) * sqrt(z)
end function
public static double code(double x, double y, double z, double t) {
return (x * Math.sqrt(0.5)) * Math.sqrt(z);
}
def code(x, y, z, t): return (x * math.sqrt(0.5)) * math.sqrt(z)
function code(x, y, z, t) return Float64(Float64(x * sqrt(0.5)) * sqrt(z)) end
function tmp = code(x, y, z, t) tmp = (x * sqrt(0.5)) * sqrt(z); end
code[x_, y_, z_, t_] := N[(N[(x * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision] * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \sqrt{0.5}\right) \cdot \sqrt{z}
\end{array}
Initial program 99.8%
add-sqr-sqrt49.8%
sqrt-unprod37.3%
*-commutative37.3%
*-commutative37.3%
swap-sqr35.2%
add-sqr-sqrt35.2%
pow235.2%
fma-neg35.2%
Applied egg-rr35.2%
associate-*l*35.2%
fma-neg35.2%
*-commutative35.2%
Simplified35.2%
Taylor expanded in x around inf 25.1%
associate-*r*25.1%
Simplified25.1%
Taylor expanded in x around 0 55.8%
Taylor expanded in t around 0 26.8%
Final simplification26.8%
(FPCore (x y z t) :precision binary64 (* (* (- (* x 0.5) y) (sqrt (* z 2.0))) (pow (exp 1.0) (/ (* t t) 2.0))))
double code(double x, double y, double z, double t) {
return (((x * 0.5) - y) * sqrt((z * 2.0))) * pow(exp(1.0), ((t * t) / 2.0));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((x * 0.5d0) - y) * sqrt((z * 2.0d0))) * (exp(1.0d0) ** ((t * t) / 2.0d0))
end function
public static double code(double x, double y, double z, double t) {
return (((x * 0.5) - y) * Math.sqrt((z * 2.0))) * Math.pow(Math.exp(1.0), ((t * t) / 2.0));
}
def code(x, y, z, t): return (((x * 0.5) - y) * math.sqrt((z * 2.0))) * math.pow(math.exp(1.0), ((t * t) / 2.0))
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(z * 2.0))) * (exp(1.0) ^ Float64(Float64(t * t) / 2.0))) end
function tmp = code(x, y, z, t) tmp = (((x * 0.5) - y) * sqrt((z * 2.0))) * (exp(1.0) ^ ((t * t) / 2.0)); end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(z * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Power[N[Exp[1.0], $MachinePrecision], N[(N[(t * t), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot {\left(e^{1}\right)}^{\left(\frac{t \cdot t}{2}\right)}
\end{array}
herbie shell --seed 2024019
(FPCore (x y z t)
:name "Data.Number.Erf:$cinvnormcdf from erf-2.0.0.0, A"
:precision binary64
:herbie-target
(* (* (- (* x 0.5) y) (sqrt (* z 2.0))) (pow (exp 1.0) (/ (* t t) 2.0)))
(* (* (- (* x 0.5) y) (sqrt (* z 2.0))) (exp (/ (* t t) 2.0))))