
(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 16 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 (* (sqrt (* (* 2.0 z) (exp (* t t)))) (fma 0.5 x (- y))))
double code(double x, double y, double z, double t) {
return sqrt(((2.0 * z) * exp((t * t)))) * fma(0.5, x, -y);
}
function code(x, y, z, t) return Float64(sqrt(Float64(Float64(2.0 * z) * exp(Float64(t * t)))) * fma(0.5, x, Float64(-y))) end
code[x_, y_, z_, t_] := N[(N[Sqrt[N[(N[(2.0 * z), $MachinePrecision] * N[Exp[N[(t * t), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(0.5 * x + (-y)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\left(2 \cdot z\right) \cdot e^{t \cdot t}} \cdot \mathsf{fma}\left(0.5, x, -y\right)
\end{array}
Initial program 99.5%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f64N/A
lift-sqrt.f64N/A
lift-exp.f64N/A
lift-/.f64N/A
exp-sqrtN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-exp.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (sqrt (* 2.0 z))) (t_2 (fma 0.5 x (- y))))
(if (<= (* t t) 2e-16)
(* t_1 t_2)
(if (<= (* t t) 5e+77)
(* (* x 0.5) (sqrt (* (* 2.0 z) (exp (* t t)))))
(*
(*
t_1
(fma
(fma (fma (* t t) 0.020833333333333332 0.125) (* t t) 0.5)
(* t t)
1.0))
t_2)))))
double code(double x, double y, double z, double t) {
double t_1 = sqrt((2.0 * z));
double t_2 = fma(0.5, x, -y);
double tmp;
if ((t * t) <= 2e-16) {
tmp = t_1 * t_2;
} else if ((t * t) <= 5e+77) {
tmp = (x * 0.5) * sqrt(((2.0 * z) * exp((t * t))));
} else {
tmp = (t_1 * fma(fma(fma((t * t), 0.020833333333333332, 0.125), (t * t), 0.5), (t * t), 1.0)) * t_2;
}
return tmp;
}
function code(x, y, z, t) t_1 = sqrt(Float64(2.0 * z)) t_2 = fma(0.5, x, Float64(-y)) tmp = 0.0 if (Float64(t * t) <= 2e-16) tmp = Float64(t_1 * t_2); elseif (Float64(t * t) <= 5e+77) tmp = Float64(Float64(x * 0.5) * sqrt(Float64(Float64(2.0 * z) * exp(Float64(t * t))))); else tmp = Float64(Float64(t_1 * fma(fma(fma(Float64(t * t), 0.020833333333333332, 0.125), Float64(t * t), 0.5), Float64(t * t), 1.0)) * t_2); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Sqrt[N[(2.0 * z), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(0.5 * x + (-y)), $MachinePrecision]}, If[LessEqual[N[(t * t), $MachinePrecision], 2e-16], N[(t$95$1 * t$95$2), $MachinePrecision], If[LessEqual[N[(t * t), $MachinePrecision], 5e+77], N[(N[(x * 0.5), $MachinePrecision] * N[Sqrt[N[(N[(2.0 * z), $MachinePrecision] * N[Exp[N[(t * t), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 * N[(N[(N[(N[(t * t), $MachinePrecision] * 0.020833333333333332 + 0.125), $MachinePrecision] * N[(t * t), $MachinePrecision] + 0.5), $MachinePrecision] * N[(t * t), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \sqrt{2 \cdot z}\\
t_2 := \mathsf{fma}\left(0.5, x, -y\right)\\
\mathbf{if}\;t \cdot t \leq 2 \cdot 10^{-16}:\\
\;\;\;\;t\_1 \cdot t\_2\\
\mathbf{elif}\;t \cdot t \leq 5 \cdot 10^{+77}:\\
\;\;\;\;\left(x \cdot 0.5\right) \cdot \sqrt{\left(2 \cdot z\right) \cdot e^{t \cdot t}}\\
\mathbf{else}:\\
\;\;\;\;\left(t\_1 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(t \cdot t, 0.020833333333333332, 0.125\right), t \cdot t, 0.5\right), t \cdot t, 1\right)\right) \cdot t\_2\\
\end{array}
\end{array}
if (*.f64 t t) < 2e-16Initial program 99.6%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f64N/A
lift-sqrt.f64N/A
lift-exp.f64N/A
lift-/.f64N/A
exp-sqrtN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-exp.f6499.6
Applied rewrites99.6%
Taylor expanded in t around 0
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
if 2e-16 < (*.f64 t t) < 5.00000000000000004e77Initial program 99.2%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f64N/A
lift-sqrt.f64N/A
lift-exp.f64N/A
lift-/.f64N/A
exp-sqrtN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-exp.f6499.6
Applied rewrites99.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6469.7
Applied rewrites69.7%
if 5.00000000000000004e77 < (*.f64 t t) Initial program 99.1%
Taylor expanded in t around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6497.4
Applied rewrites97.4%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lift--.f64N/A
sub-negN/A
lift-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-fma.f64N/A
*-commutativeN/A
lower-*.f6498.7
Applied rewrites98.7%
Final simplification97.0%
(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 2024230
(FPCore (x y z t)
:name "Data.Number.Erf:$cinvnormcdf from erf-2.0.0.0, A"
:precision binary64
:alt
(! :herbie-platform default (* (* (- (* x 1/2) y) (sqrt (* z 2))) (pow (exp 1) (/ (* t t) 2))))
(* (* (- (* x 0.5) y) (sqrt (* z 2.0))) (exp (/ (* t t) 2.0))))