
(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 4 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) 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}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (* x 0.5) y)))
(if (<= t 1.05e+35)
(* 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 <= 1.05e+35) {
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 <= 1.05d+35) 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 <= 1.05e+35) {
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 <= 1.05e+35: 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 <= 1.05e+35) tmp = Float64(t_1 * sqrt(Float64(z * 2.0))); else tmp = sqrt(Float64(Float64(z * 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 <= 1.05e+35) 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, 1.05e+35], N[(t$95$1 * N[Sqrt[N[(z * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[(z * 2.0), $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 1.05 \cdot 10^{+35}:\\
\;\;\;\;t_1 \cdot \sqrt{z \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(z \cdot 2\right) \cdot {t_1}^{2}}\\
\end{array}
\end{array}
if t < 1.0499999999999999e35Initial program 99.8%
Taylor expanded in t around 0 67.1%
if 1.0499999999999999e35 < t Initial program 100.0%
add-sqr-sqrt52.0%
sqrt-unprod46.7%
*-commutative46.7%
*-commutative46.7%
swap-sqr45.3%
add-sqr-sqrt45.3%
pow245.3%
Applied egg-rr45.3%
Taylor expanded in t around 0 24.9%
Final simplification54.7%
(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.9%
Taylor expanded in t around 0 52.1%
Final simplification52.1%
(FPCore (x y z t) :precision binary64 (* y (sqrt (* z -2.0))))
double code(double x, double y, double z, double t) {
return 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 = y * sqrt((z * (-2.0d0)))
end function
public static double code(double x, double y, double z, double t) {
return y * Math.sqrt((z * -2.0));
}
def code(x, y, z, t): return y * math.sqrt((z * -2.0))
function code(x, y, z, t) return Float64(y * sqrt(Float64(z * -2.0))) end
function tmp = code(x, y, z, t) tmp = y * sqrt((z * -2.0)); end
code[x_, y_, z_, t_] := N[(y * N[Sqrt[N[(z * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \sqrt{z \cdot -2}
\end{array}
Initial program 99.9%
Taylor expanded in t around 0 52.1%
Taylor expanded in x around 0 27.6%
mul-1-neg27.6%
associate-*l*27.6%
distribute-rgt-neg-in27.6%
*-commutative27.6%
distribute-rgt-neg-in27.6%
Simplified27.6%
Applied egg-rr0.0%
expm1-def0.0%
expm1-log1p0.0%
Simplified0.0%
Final simplification0.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 2023298
(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))))