
(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 (* (exp (* t t)) (* 2.0 z)))))
double code(double x, double y, double z, double t) {
return ((x * 0.5) - y) * sqrt((exp((t * t)) * (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((exp((t * t)) * (2.0d0 * z)))
end function
public static double code(double x, double y, double z, double t) {
return ((x * 0.5) - y) * Math.sqrt((Math.exp((t * t)) * (2.0 * z)));
}
def code(x, y, z, t): return ((x * 0.5) - y) * math.sqrt((math.exp((t * t)) * (2.0 * z)))
function code(x, y, z, t) return Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(exp(Float64(t * t)) * Float64(2.0 * z)))) end
function tmp = code(x, y, z, t) tmp = ((x * 0.5) - y) * sqrt((exp((t * t)) * (2.0 * z))); end
code[x_, y_, z_, t_] := N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(N[Exp[N[(t * t), $MachinePrecision]], $MachinePrecision] * N[(2.0 * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 0.5 - y\right) \cdot \sqrt{e^{t \cdot t} \cdot \left(2 \cdot z\right)}
\end{array}
Initial program 99.4%
associate-*l*99.8%
exp-sqrt99.8%
exp-prod99.8%
Simplified99.8%
pow199.8%
sqrt-unprod99.8%
associate-*l*99.8%
pow-exp99.8%
pow299.8%
Applied egg-rr99.8%
unpow199.8%
*-commutative99.8%
*-commutative99.8%
associate-*l*99.8%
Simplified99.8%
pow299.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (* x 0.5) y)))
(if (<= t 11200000000000.0)
(* t_1 (sqrt (* 2.0 z)))
(sqrt (* (* 2.0 z) (pow t_1 2.0))))))
double code(double x, double y, double z, double t) {
double t_1 = (x * 0.5) - y;
double tmp;
if (t <= 11200000000000.0) {
tmp = t_1 * sqrt((2.0 * z));
} else {
tmp = sqrt(((2.0 * z) * pow(t_1, 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 = (x * 0.5d0) - y
if (t <= 11200000000000.0d0) then
tmp = t_1 * sqrt((2.0d0 * z))
else
tmp = sqrt(((2.0d0 * z) * (t_1 ** 2.0d0)))
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 <= 11200000000000.0) {
tmp = t_1 * Math.sqrt((2.0 * z));
} else {
tmp = Math.sqrt(((2.0 * z) * Math.pow(t_1, 2.0)));
}
return tmp;
}
def code(x, y, z, t): t_1 = (x * 0.5) - y tmp = 0 if t <= 11200000000000.0: tmp = t_1 * math.sqrt((2.0 * z)) else: tmp = math.sqrt(((2.0 * z) * math.pow(t_1, 2.0))) return tmp
function code(x, y, z, t) t_1 = Float64(Float64(x * 0.5) - y) tmp = 0.0 if (t <= 11200000000000.0) tmp = Float64(t_1 * sqrt(Float64(2.0 * z))); else tmp = sqrt(Float64(Float64(2.0 * z) * (t_1 ^ 2.0))); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (x * 0.5) - y; tmp = 0.0; if (t <= 11200000000000.0) tmp = t_1 * sqrt((2.0 * z)); else tmp = sqrt(((2.0 * z) * (t_1 ^ 2.0))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision]}, If[LessEqual[t, 11200000000000.0], N[(t$95$1 * N[Sqrt[N[(2.0 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[(2.0 * z), $MachinePrecision] * N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot 0.5 - y\\
\mathbf{if}\;t \leq 11200000000000:\\
\;\;\;\;t\_1 \cdot \sqrt{2 \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(2 \cdot z\right) \cdot {t\_1}^{2}}\\
\end{array}
\end{array}
if t < 1.12e13Initial program 99.2%
associate-*l*99.7%
exp-sqrt99.7%
exp-prod99.7%
Simplified99.7%
pow199.7%
sqrt-unprod99.7%
associate-*l*99.7%
pow-exp99.7%
pow299.7%
Applied egg-rr99.7%
unpow199.7%
*-commutative99.7%
*-commutative99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in t around 0 69.9%
if 1.12e13 < t Initial program 100.0%
associate-*l*100.0%
exp-sqrt100.0%
exp-prod100.0%
Simplified100.0%
pow1100.0%
sqrt-unprod100.0%
associate-*l*100.0%
pow-exp100.0%
pow2100.0%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in t around 0 18.4%
add-sqr-sqrt9.7%
sqrt-unprod33.4%
*-commutative33.4%
*-commutative33.4%
swap-sqr36.3%
add-sqr-sqrt36.3%
pow236.3%
fma-neg36.3%
Applied egg-rr36.3%
fma-neg36.3%
*-commutative36.3%
Simplified36.3%
Final simplification61.0%
(FPCore (x y z t) :precision binary64 (if (<= (* x 0.5) 5e+208) (* (- (* x 0.5) y) (sqrt (* 2.0 z))) (sqrt (* 0.5 (* z (pow x 2.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * 0.5) <= 5e+208) {
tmp = ((x * 0.5) - y) * sqrt((2.0 * z));
} else {
tmp = sqrt((0.5 * (z * pow(x, 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) :: tmp
if ((x * 0.5d0) <= 5d+208) then
tmp = ((x * 0.5d0) - y) * sqrt((2.0d0 * z))
else
tmp = sqrt((0.5d0 * (z * (x ** 2.0d0))))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x * 0.5) <= 5e+208) {
tmp = ((x * 0.5) - y) * Math.sqrt((2.0 * z));
} else {
tmp = Math.sqrt((0.5 * (z * Math.pow(x, 2.0))));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x * 0.5) <= 5e+208: tmp = ((x * 0.5) - y) * math.sqrt((2.0 * z)) else: tmp = math.sqrt((0.5 * (z * math.pow(x, 2.0)))) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(x * 0.5) <= 5e+208) tmp = Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(2.0 * z))); else tmp = sqrt(Float64(0.5 * Float64(z * (x ^ 2.0)))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x * 0.5) <= 5e+208) tmp = ((x * 0.5) - y) * sqrt((2.0 * z)); else tmp = sqrt((0.5 * (z * (x ^ 2.0)))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * 0.5), $MachinePrecision], 5e+208], N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(2.0 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(z * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot 0.5 \leq 5 \cdot 10^{+208}:\\
\;\;\;\;\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(z \cdot {x}^{2}\right)}\\
\end{array}
\end{array}
if (*.f64 x 1/2) < 5.0000000000000004e208Initial program 99.4%
associate-*l*99.8%
exp-sqrt99.8%
exp-prod99.8%
Simplified99.8%
pow199.8%
sqrt-unprod99.8%
associate-*l*99.8%
pow-exp99.8%
pow299.8%
Applied egg-rr99.8%
unpow199.8%
*-commutative99.8%
*-commutative99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in t around 0 57.4%
if 5.0000000000000004e208 < (*.f64 x 1/2) Initial program 99.9%
associate-*l*99.9%
exp-sqrt99.9%
exp-prod99.9%
Simplified99.9%
Taylor expanded in t around 0 45.2%
Taylor expanded in x around inf 38.5%
pow138.5%
associate-*l*38.5%
sqrt-prod38.6%
Applied egg-rr38.6%
unpow138.6%
Simplified38.6%
add-sqr-sqrt38.5%
sqrt-unprod76.2%
*-commutative76.2%
*-commutative76.2%
swap-sqr76.2%
*-commutative76.2%
*-commutative76.2%
swap-sqr84.1%
add-sqr-sqrt84.1%
pow284.1%
metadata-eval84.1%
Applied egg-rr84.1%
*-commutative84.1%
associate-*l*84.1%
associate-*r*84.1%
metadata-eval84.1%
Simplified84.1%
Final simplification59.9%
(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.4%
associate-*l*99.8%
exp-sqrt99.8%
exp-prod99.8%
Simplified99.8%
pow199.8%
sqrt-unprod99.8%
associate-*l*99.8%
pow-exp99.8%
pow299.8%
Applied egg-rr99.8%
unpow199.8%
*-commutative99.8%
*-commutative99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in t around 0 56.2%
Final simplification56.2%
(FPCore (x y z t) :precision binary64 (* x (sqrt (* 0.5 z))))
double code(double x, double y, double z, double t) {
return 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 = x * sqrt((0.5d0 * z))
end function
public static double code(double x, double y, double z, double t) {
return x * Math.sqrt((0.5 * z));
}
def code(x, y, z, t): return x * math.sqrt((0.5 * z))
function code(x, y, z, t) return Float64(x * sqrt(Float64(0.5 * z))) end
function tmp = code(x, y, z, t) tmp = x * sqrt((0.5 * z)); end
code[x_, y_, z_, t_] := N[(x * N[Sqrt[N[(0.5 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sqrt{0.5 \cdot z}
\end{array}
Initial program 99.4%
associate-*l*99.8%
exp-sqrt99.8%
exp-prod99.8%
Simplified99.8%
Taylor expanded in t around 0 56.1%
Taylor expanded in x around inf 28.8%
pow128.8%
associate-*l*28.8%
sqrt-prod28.9%
Applied egg-rr28.9%
unpow128.9%
Simplified28.9%
pow128.9%
*-commutative28.9%
associate-*l*28.9%
*-commutative28.9%
add-sqr-sqrt28.8%
sqrt-unprod28.9%
*-commutative28.9%
*-commutative28.9%
swap-sqr28.9%
add-sqr-sqrt28.9%
metadata-eval28.9%
Applied egg-rr28.9%
unpow128.9%
*-commutative28.9%
associate-*l*28.9%
metadata-eval28.9%
Simplified28.9%
Final simplification28.9%
(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 2024053
(FPCore (x y z t)
:name "Data.Number.Erf:$cinvnormcdf from erf-2.0.0.0, A"
:precision binary64
:alt
(* (* (- (* 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))))