
(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))))))
double code(double x, double y, double z, double t) {
return ((x * 0.5) - y) * sqrt(((z * 2.0) * 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(((z * 2.0d0) * exp((t * t))))
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))));
}
def code(x, y, z, t): return ((x * 0.5) - y) * math.sqrt(((z * 2.0) * math.exp((t * t))))
function code(x, y, z, t) return Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(Float64(z * 2.0) * exp(Float64(t * t))))) end
function tmp = code(x, y, z, t) tmp = ((x * 0.5) - y) * sqrt(((z * 2.0) * exp((t * t)))); end
code[x_, y_, z_, t_] := N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(N[(z * 2.0), $MachinePrecision] * N[Exp[N[(t * t), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 0.5 - y\right) \cdot \sqrt{\left(z \cdot 2\right) \cdot e^{t \cdot t}}
\end{array}
Initial program 99.0%
associate-*l*99.8%
remove-double-neg99.8%
remove-double-neg99.8%
exp-sqrt99.5%
exp-prod99.5%
Simplified99.5%
pow199.5%
sqrt-unprod99.5%
associate-*l*99.5%
pow-exp99.5%
pow299.5%
Applied egg-rr99.5%
unpow199.5%
associate-*r*99.5%
Simplified99.5%
pow299.5%
Applied egg-rr99.5%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (* x 0.5) y)))
(if (<= t 600.0)
(* t_1 (sqrt (* z 2.0)))
(sqrt (* z (* 2.0 (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 <= 600.0) {
tmp = t_1 * sqrt((z * 2.0));
} else {
tmp = sqrt((z * (2.0 * 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 <= 600.0d0) then
tmp = t_1 * sqrt((z * 2.0d0))
else
tmp = sqrt((z * (2.0d0 * (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 <= 600.0) {
tmp = t_1 * Math.sqrt((z * 2.0));
} else {
tmp = Math.sqrt((z * (2.0 * Math.pow(t_1, 2.0))));
}
return tmp;
}
def code(x, y, z, t): t_1 = (x * 0.5) - y tmp = 0 if t <= 600.0: tmp = t_1 * math.sqrt((z * 2.0)) else: tmp = math.sqrt((z * (2.0 * 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 <= 600.0) tmp = Float64(t_1 * sqrt(Float64(z * 2.0))); else tmp = sqrt(Float64(z * Float64(2.0 * (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 <= 600.0) tmp = t_1 * sqrt((z * 2.0)); else tmp = sqrt((z * (2.0 * (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, 600.0], N[(t$95$1 * N[Sqrt[N[(z * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(z * N[(2.0 * N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot 0.5 - y\\
\mathbf{if}\;t \leq 600:\\
\;\;\;\;t\_1 \cdot \sqrt{z \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{z \cdot \left(2 \cdot {t\_1}^{2}\right)}\\
\end{array}
\end{array}
if t < 600Initial program 98.7%
associate-*l*99.8%
remove-double-neg99.8%
remove-double-neg99.8%
exp-sqrt99.3%
exp-prod99.3%
Simplified99.3%
pow199.3%
sqrt-unprod99.3%
associate-*l*99.3%
pow-exp99.3%
pow299.3%
Applied egg-rr99.3%
unpow199.3%
associate-*r*99.3%
Simplified99.3%
Taylor expanded in t around 0 69.2%
*-commutative69.2%
Simplified69.2%
if 600 < t Initial program 100.0%
associate-*l*100.0%
remove-double-neg100.0%
remove-double-neg100.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%
associate-*r*100.0%
Simplified100.0%
Taylor expanded in t around 0 8.9%
*-commutative8.9%
Simplified8.9%
add-sqr-sqrt7.2%
sqrt-unprod22.7%
*-commutative22.7%
*-commutative22.7%
swap-sqr29.0%
add-sqr-sqrt29.0%
pow229.0%
fmm-def29.0%
Applied egg-rr29.0%
associate-*l*29.0%
fmm-undef29.0%
*-commutative29.0%
Simplified29.0%
Final simplification59.6%
(FPCore (x y z t) :precision binary64 (if (<= t 920000.0) (* (- (* x 0.5) y) (sqrt (* z 2.0))) (* 0.5 (sqrt (* (* z 2.0) (pow x 2.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= 920000.0) {
tmp = ((x * 0.5) - y) * sqrt((z * 2.0));
} else {
tmp = 0.5 * sqrt(((z * 2.0) * 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 (t <= 920000.0d0) then
tmp = ((x * 0.5d0) - y) * sqrt((z * 2.0d0))
else
tmp = 0.5d0 * sqrt(((z * 2.0d0) * (x ** 2.0d0)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= 920000.0) {
tmp = ((x * 0.5) - y) * Math.sqrt((z * 2.0));
} else {
tmp = 0.5 * Math.sqrt(((z * 2.0) * Math.pow(x, 2.0)));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= 920000.0: tmp = ((x * 0.5) - y) * math.sqrt((z * 2.0)) else: tmp = 0.5 * math.sqrt(((z * 2.0) * math.pow(x, 2.0))) return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= 920000.0) tmp = Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(z * 2.0))); else tmp = Float64(0.5 * sqrt(Float64(Float64(z * 2.0) * (x ^ 2.0)))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= 920000.0) tmp = ((x * 0.5) - y) * sqrt((z * 2.0)); else tmp = 0.5 * sqrt(((z * 2.0) * (x ^ 2.0))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, 920000.0], N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(z * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(N[(z * 2.0), $MachinePrecision] * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq 920000:\\
\;\;\;\;\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{\left(z \cdot 2\right) \cdot {x}^{2}}\\
\end{array}
\end{array}
if t < 9.2e5Initial program 98.7%
associate-*l*99.8%
remove-double-neg99.8%
remove-double-neg99.8%
exp-sqrt99.3%
exp-prod99.3%
Simplified99.3%
pow199.3%
sqrt-unprod99.3%
associate-*l*99.3%
pow-exp99.3%
pow299.3%
Applied egg-rr99.3%
unpow199.3%
associate-*r*99.3%
Simplified99.3%
Taylor expanded in t around 0 69.2%
*-commutative69.2%
Simplified69.2%
if 9.2e5 < t Initial program 100.0%
Taylor expanded in t around 0 8.9%
Taylor expanded in x around inf 4.6%
associate-*l*4.6%
Simplified4.6%
add-sqr-sqrt3.4%
sqrt-unprod11.6%
*-commutative11.6%
*-commutative11.6%
swap-sqr16.3%
sqrt-unprod16.3%
sqrt-unprod16.3%
add-sqr-sqrt16.3%
*-commutative16.3%
pow216.3%
Applied egg-rr16.3%
(FPCore (x y z t) :precision binary64 (* (- (* x 0.5) y) (sqrt (* z 2.0))))
double code(double x, double y, double z, double t) {
return ((x * 0.5) - y) * sqrt((z * 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))
end function
public static double code(double x, double y, double z, double t) {
return ((x * 0.5) - y) * Math.sqrt((z * 2.0));
}
def code(x, y, z, t): return ((x * 0.5) - y) * math.sqrt((z * 2.0))
function code(x, y, z, t) return Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(z * 2.0))) end
function tmp = code(x, y, z, t) tmp = ((x * 0.5) - y) * sqrt((z * 2.0)); end
code[x_, y_, z_, t_] := N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(z * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}
\end{array}
Initial program 99.0%
associate-*l*99.8%
remove-double-neg99.8%
remove-double-neg99.8%
exp-sqrt99.5%
exp-prod99.5%
Simplified99.5%
pow199.5%
sqrt-unprod99.5%
associate-*l*99.5%
pow-exp99.5%
pow299.5%
Applied egg-rr99.5%
unpow199.5%
associate-*r*99.5%
Simplified99.5%
Taylor expanded in t around 0 54.9%
*-commutative54.9%
Simplified54.9%
(FPCore (x y z t) :precision binary64 (* 0.5 (* x (sqrt (* z 2.0)))))
double code(double x, double y, double z, double t) {
return 0.5 * (x * sqrt((z * 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 = 0.5d0 * (x * sqrt((z * 2.0d0)))
end function
public static double code(double x, double y, double z, double t) {
return 0.5 * (x * Math.sqrt((z * 2.0)));
}
def code(x, y, z, t): return 0.5 * (x * math.sqrt((z * 2.0)))
function code(x, y, z, t) return Float64(0.5 * Float64(x * sqrt(Float64(z * 2.0)))) end
function tmp = code(x, y, z, t) tmp = 0.5 * (x * sqrt((z * 2.0))); end
code[x_, y_, z_, t_] := N[(0.5 * N[(x * N[Sqrt[N[(z * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(x \cdot \sqrt{z \cdot 2}\right)
\end{array}
Initial program 99.0%
Taylor expanded in t around 0 54.9%
Taylor expanded in x around inf 26.7%
associate-*l*26.6%
Simplified26.6%
sqrt-unprod26.7%
*-commutative26.7%
Applied egg-rr26.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 2024172
(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))))