
(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 (* 2.0 (* z (exp (* t t)))))))
double code(double x, double y, double z, double t) {
return ((x * 0.5) - y) * sqrt((2.0 * (z * exp((t * t)))));
}
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((2.0d0 * (z * exp((t * t)))))
end function
public static double code(double x, double y, double z, double t) {
return ((x * 0.5) - y) * Math.sqrt((2.0 * (z * Math.exp((t * t)))));
}
def code(x, y, z, t): return ((x * 0.5) - y) * math.sqrt((2.0 * (z * math.exp((t * t)))))
function code(x, y, z, t) return Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(2.0 * Float64(z * exp(Float64(t * t)))))) end
function tmp = code(x, y, z, t) tmp = ((x * 0.5) - y) * sqrt((2.0 * (z * exp((t * t))))); end
code[x_, y_, z_, t_] := N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(2.0 * N[(z * N[Exp[N[(t * t), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot \left(z \cdot e^{t \cdot t}\right)}
\end{array}
Initial program 99.5%
associate-*l*99.9%
exp-sqrt99.9%
Simplified99.9%
expm1-log1p-u98.5%
expm1-udef78.4%
sqrt-unprod78.4%
associate-*l*78.4%
exp-prod78.4%
Applied egg-rr78.4%
expm1-def98.5%
expm1-log1p99.9%
*-commutative99.9%
associate-*l*99.9%
*-commutative99.9%
exp-prod99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (* x 0.5) y)))
(if (<= (* t t) 1e-16)
(* t_1 (sqrt (* 2.0 z)))
(if (<= (* t t) 1e+229)
(* y (- (sqrt (* (exp (* t t)) (* 2.0 z)))))
(* t_1 (sqrt (* 2.0 (+ z (* z (* t t))))))))))
double code(double x, double y, double z, double t) {
double t_1 = (x * 0.5) - y;
double tmp;
if ((t * t) <= 1e-16) {
tmp = t_1 * sqrt((2.0 * z));
} else if ((t * t) <= 1e+229) {
tmp = y * -sqrt((exp((t * t)) * (2.0 * z)));
} else {
tmp = t_1 * sqrt((2.0 * (z + (z * (t * t)))));
}
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 = (x * 0.5d0) - y
if ((t * t) <= 1d-16) then
tmp = t_1 * sqrt((2.0d0 * z))
else if ((t * t) <= 1d+229) then
tmp = y * -sqrt((exp((t * t)) * (2.0d0 * z)))
else
tmp = t_1 * sqrt((2.0d0 * (z + (z * (t * t)))))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = (x * 0.5) - y;
double tmp;
if ((t * t) <= 1e-16) {
tmp = t_1 * Math.sqrt((2.0 * z));
} else if ((t * t) <= 1e+229) {
tmp = y * -Math.sqrt((Math.exp((t * t)) * (2.0 * z)));
} else {
tmp = t_1 * Math.sqrt((2.0 * (z + (z * (t * t)))));
}
return tmp;
}
def code(x, y, z, t): t_1 = (x * 0.5) - y tmp = 0 if (t * t) <= 1e-16: tmp = t_1 * math.sqrt((2.0 * z)) elif (t * t) <= 1e+229: tmp = y * -math.sqrt((math.exp((t * t)) * (2.0 * z))) else: tmp = t_1 * math.sqrt((2.0 * (z + (z * (t * t))))) return tmp
function code(x, y, z, t) t_1 = Float64(Float64(x * 0.5) - y) tmp = 0.0 if (Float64(t * t) <= 1e-16) tmp = Float64(t_1 * sqrt(Float64(2.0 * z))); elseif (Float64(t * t) <= 1e+229) tmp = Float64(y * Float64(-sqrt(Float64(exp(Float64(t * t)) * Float64(2.0 * z))))); else tmp = Float64(t_1 * sqrt(Float64(2.0 * Float64(z + Float64(z * Float64(t * t)))))); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (x * 0.5) - y; tmp = 0.0; if ((t * t) <= 1e-16) tmp = t_1 * sqrt((2.0 * z)); elseif ((t * t) <= 1e+229) tmp = y * -sqrt((exp((t * t)) * (2.0 * z))); else tmp = t_1 * sqrt((2.0 * (z + (z * (t * t))))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision]}, If[LessEqual[N[(t * t), $MachinePrecision], 1e-16], N[(t$95$1 * N[Sqrt[N[(2.0 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(t * t), $MachinePrecision], 1e+229], N[(y * (-N[Sqrt[N[(N[Exp[N[(t * t), $MachinePrecision]], $MachinePrecision] * N[(2.0 * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], N[(t$95$1 * N[Sqrt[N[(2.0 * N[(z + N[(z * N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot 0.5 - y\\
\mathbf{if}\;t \cdot t \leq 10^{-16}:\\
\;\;\;\;t_1 \cdot \sqrt{2 \cdot z}\\
\mathbf{elif}\;t \cdot t \leq 10^{+229}:\\
\;\;\;\;y \cdot \left(-\sqrt{e^{t \cdot t} \cdot \left(2 \cdot z\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;t_1 \cdot \sqrt{2 \cdot \left(z + z \cdot \left(t \cdot t\right)\right)}\\
\end{array}
\end{array}
if (*.f64 t t) < 9.9999999999999998e-17Initial program 99.7%
associate-*l*99.7%
exp-sqrt99.7%
Simplified99.7%
expm1-log1p-u96.9%
expm1-udef54.0%
sqrt-unprod54.0%
associate-*l*54.0%
exp-prod54.0%
Applied egg-rr54.0%
expm1-def96.9%
expm1-log1p99.7%
*-commutative99.7%
associate-*l*99.7%
*-commutative99.7%
exp-prod99.7%
Simplified99.7%
Taylor expanded in t around 0 99.7%
if 9.9999999999999998e-17 < (*.f64 t t) < 9.9999999999999999e228Initial program 100.0%
associate-*r*100.0%
exp-sqrt100.0%
*-commutative100.0%
flip--90.5%
associate-*r/90.5%
Applied egg-rr90.5%
associate-/l*90.5%
associate-*l*90.5%
Simplified90.5%
Taylor expanded in x around 0 75.4%
associate-/r/75.4%
div-inv75.4%
associate-*r*75.4%
*-commutative75.4%
pow-exp75.4%
metadata-eval75.4%
Applied egg-rr75.4%
if 9.9999999999999999e228 < (*.f64 t t) Initial program 98.8%
associate-*l*100.0%
exp-sqrt100.0%
Simplified100.0%
expm1-log1p-u100.0%
expm1-udef100.0%
sqrt-unprod100.0%
associate-*l*100.0%
exp-prod100.0%
Applied egg-rr100.0%
expm1-def100.0%
expm1-log1p100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
exp-prod100.0%
Simplified100.0%
Taylor expanded in t around 0 93.1%
*-commutative93.1%
unpow293.1%
Simplified93.1%
Final simplification92.5%
(FPCore (x y z t) :precision binary64 (* (- (* x 0.5) y) (sqrt (* 2.0 (+ z (* z (* t t)))))))
double code(double x, double y, double z, double t) {
return ((x * 0.5) - y) * sqrt((2.0 * (z + (z * (t * t)))));
}
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((2.0d0 * (z + (z * (t * t)))))
end function
public static double code(double x, double y, double z, double t) {
return ((x * 0.5) - y) * Math.sqrt((2.0 * (z + (z * (t * t)))));
}
def code(x, y, z, t): return ((x * 0.5) - y) * math.sqrt((2.0 * (z + (z * (t * t)))))
function code(x, y, z, t) return Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(2.0 * Float64(z + Float64(z * Float64(t * t)))))) end
function tmp = code(x, y, z, t) tmp = ((x * 0.5) - y) * sqrt((2.0 * (z + (z * (t * t))))); end
code[x_, y_, z_, t_] := N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(2.0 * N[(z + N[(z * N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot \left(z + z \cdot \left(t \cdot t\right)\right)}
\end{array}
Initial program 99.5%
associate-*l*99.9%
exp-sqrt99.9%
Simplified99.9%
expm1-log1p-u98.5%
expm1-udef78.4%
sqrt-unprod78.4%
associate-*l*78.4%
exp-prod78.4%
Applied egg-rr78.4%
expm1-def98.5%
expm1-log1p99.9%
*-commutative99.9%
associate-*l*99.9%
*-commutative99.9%
exp-prod99.9%
Simplified99.9%
Taylor expanded in t around 0 83.3%
*-commutative83.3%
unpow283.3%
Simplified83.3%
Final simplification83.3%
(FPCore (x y z t) :precision binary64 (* (- (* x 0.5) y) (sqrt (* 2.0 z))))
double code(double x, double y, double z, double t) {
return ((x * 0.5) - y) * sqrt((2.0 * 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 * 0.5d0) - y) * sqrt((2.0d0 * z))
end function
public static double code(double x, double y, double z, double t) {
return ((x * 0.5) - y) * Math.sqrt((2.0 * z));
}
def code(x, y, z, t): return ((x * 0.5) - y) * math.sqrt((2.0 * z))
function code(x, y, z, t) return Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(2.0 * z))) end
function tmp = code(x, y, z, t) tmp = ((x * 0.5) - y) * sqrt((2.0 * z)); end
code[x_, y_, z_, t_] := N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(2.0 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot z}
\end{array}
Initial program 99.5%
associate-*l*99.9%
exp-sqrt99.9%
Simplified99.9%
expm1-log1p-u98.5%
expm1-udef78.4%
sqrt-unprod78.4%
associate-*l*78.4%
exp-prod78.4%
Applied egg-rr78.4%
expm1-def98.5%
expm1-log1p99.9%
*-commutative99.9%
associate-*l*99.9%
*-commutative99.9%
exp-prod99.9%
Simplified99.9%
Taylor expanded in t around 0 52.4%
Final simplification52.4%
(FPCore (x y z t) :precision binary64 (* (sqrt (+ z z)) (- y)))
double code(double x, double y, double z, double t) {
return sqrt((z + z)) * -y;
}
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 = sqrt((z + z)) * -y
end function
public static double code(double x, double y, double z, double t) {
return Math.sqrt((z + z)) * -y;
}
def code(x, y, z, t): return math.sqrt((z + z)) * -y
function code(x, y, z, t) return Float64(sqrt(Float64(z + z)) * Float64(-y)) end
function tmp = code(x, y, z, t) tmp = sqrt((z + z)) * -y; end
code[x_, y_, z_, t_] := N[(N[Sqrt[N[(z + z), $MachinePrecision]], $MachinePrecision] * (-y)), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{z + z} \cdot \left(-y\right)
\end{array}
Initial program 99.5%
associate-*r*99.9%
exp-sqrt99.9%
*-commutative99.9%
flip--74.0%
associate-*r/71.2%
Applied egg-rr71.2%
associate-/l*74.0%
associate-*l*74.0%
Simplified74.0%
Taylor expanded in x around 0 61.8%
Taylor expanded in t around 0 25.1%
rem-log-exp25.9%
log-pow25.9%
unpow225.9%
prod-exp25.9%
rem-log-exp25.1%
Simplified25.1%
expm1-log1p-u15.4%
expm1-udef11.9%
associate-/r/11.9%
Applied egg-rr11.9%
expm1-def15.5%
expm1-log1p25.1%
associate-/r/25.1%
*-rgt-identity25.1%
associate-*r/25.1%
associate-/r/25.1%
metadata-eval25.1%
neg-mul-125.1%
Simplified25.1%
Final simplification25.1%
(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 2023199
(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))))