
(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 3 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 (* z 2.0)) (- (* x 0.5) y)) (exp (/ (* t t) 2.0))))
double code(double x, double y, double z, double t) {
return (sqrt((z * 2.0)) * ((x * 0.5) - y)) * 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 = (sqrt((z * 2.0d0)) * ((x * 0.5d0) - y)) * exp(((t * t) / 2.0d0))
end function
public static double code(double x, double y, double z, double t) {
return (Math.sqrt((z * 2.0)) * ((x * 0.5) - y)) * Math.exp(((t * t) / 2.0));
}
def code(x, y, z, t): return (math.sqrt((z * 2.0)) * ((x * 0.5) - y)) * math.exp(((t * t) / 2.0))
function code(x, y, z, t) return Float64(Float64(sqrt(Float64(z * 2.0)) * Float64(Float64(x * 0.5) - y)) * exp(Float64(Float64(t * t) / 2.0))) end
function tmp = code(x, y, z, t) tmp = (sqrt((z * 2.0)) * ((x * 0.5) - y)) * exp(((t * t) / 2.0)); end
code[x_, y_, z_, t_] := N[(N[(N[Sqrt[N[(z * 2.0), $MachinePrecision]], $MachinePrecision] * N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(t * t), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\sqrt{z \cdot 2} \cdot \left(x \cdot 0.5 - y\right)\right) \cdot e^{\frac{t \cdot t}{2}}
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (- (* x 0.5) y))) (if (<= t 37.0) (* t_1 (sqrt (+ z z))) (* t_1 (cbrt (pow (+ z z) 1.5))))))
double code(double x, double y, double z, double t) {
double t_1 = (x * 0.5) - y;
double tmp;
if (t <= 37.0) {
tmp = t_1 * sqrt((z + z));
} else {
tmp = t_1 * cbrt(pow((z + z), 1.5));
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double t_1 = (x * 0.5) - y;
double tmp;
if (t <= 37.0) {
tmp = t_1 * Math.sqrt((z + z));
} else {
tmp = t_1 * Math.cbrt(Math.pow((z + z), 1.5));
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(x * 0.5) - y) tmp = 0.0 if (t <= 37.0) tmp = Float64(t_1 * sqrt(Float64(z + z))); else tmp = Float64(t_1 * cbrt((Float64(z + z) ^ 1.5))); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision]}, If[LessEqual[t, 37.0], N[(t$95$1 * N[Sqrt[N[(z + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(t$95$1 * N[Power[N[Power[N[(z + z), $MachinePrecision], 1.5], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot 0.5 - y\\
\mathbf{if}\;t \leq 37:\\
\;\;\;\;t_1 \cdot \sqrt{z + z}\\
\mathbf{else}:\\
\;\;\;\;t_1 \cdot \sqrt[3]{{\left(z + z\right)}^{1.5}}\\
\end{array}
\end{array}
if t < 37Initial program 99.9%
Taylor expanded in t around inf 99.4%
*-commutative99.4%
associate-*l*99.6%
unpow299.6%
*-commutative99.6%
associate-*r*99.6%
*-commutative99.6%
exp-prod99.6%
exp-prod99.6%
unpow1/299.6%
Simplified99.6%
Taylor expanded in t around 0 71.9%
sqrt-unprod72.2%
count-272.2%
expm1-log1p-u70.3%
expm1-udef41.4%
Applied egg-rr41.4%
expm1-def70.3%
expm1-log1p72.2%
Simplified72.2%
if 37 < t Initial program 100.0%
Taylor expanded in t around inf 100.0%
*-commutative100.0%
associate-*l*100.0%
unpow2100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
exp-prod100.0%
exp-prod100.0%
unpow1/2100.0%
Simplified100.0%
Taylor expanded in t around 0 15.7%
add-cbrt-cube27.0%
sqrt-unprod27.0%
count-227.0%
sqrt-unprod27.0%
count-227.0%
add-sqr-sqrt27.0%
sqrt-unprod27.0%
count-227.0%
Applied egg-rr27.0%
*-commutative27.0%
unpow1/227.0%
pow-plus27.0%
metadata-eval27.0%
Simplified27.0%
Final simplification58.9%
(FPCore (x y z t) :precision binary64 (* (- (* x 0.5) y) (sqrt (+ z z))))
double code(double x, double y, double z, double t) {
return ((x * 0.5) - y) * sqrt((z + 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((z + z))
end function
public static double code(double x, double y, double z, double t) {
return ((x * 0.5) - y) * Math.sqrt((z + z));
}
def code(x, y, z, t): return ((x * 0.5) - y) * math.sqrt((z + z))
function code(x, y, z, t) return Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(z + z))) end
function tmp = code(x, y, z, t) tmp = ((x * 0.5) - y) * sqrt((z + z)); end
code[x_, y_, z_, t_] := N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(z + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 0.5 - y\right) \cdot \sqrt{z + z}
\end{array}
Initial program 99.9%
Taylor expanded in t around inf 99.6%
*-commutative99.6%
associate-*l*99.7%
unpow299.7%
*-commutative99.7%
associate-*r*99.7%
*-commutative99.7%
exp-prod99.7%
exp-prod99.7%
unpow1/299.7%
Simplified99.7%
Taylor expanded in t around 0 55.5%
sqrt-unprod55.7%
count-255.7%
expm1-log1p-u54.3%
expm1-udef33.6%
Applied egg-rr33.6%
expm1-def54.3%
expm1-log1p55.7%
Simplified55.7%
Final simplification55.7%
(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 2023268
(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))))