
(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 (* 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.0%
associate-*l*99.8%
exp-sqrt99.8%
Simplified99.8%
expm1-log1p-u98.6%
expm1-udef76.5%
sqrt-unprod76.5%
associate-*l*76.5%
exp-prod76.5%
Applied egg-rr76.5%
expm1-def98.6%
expm1-log1p99.8%
*-commutative99.8%
associate-*l*99.8%
*-commutative99.8%
exp-prod99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (* x 0.5) y)))
(if (or (<= t 33.0) (and (not (<= t 1.05e+233)) (<= t 1.32e+250)))
(* 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 <= 33.0) || (!(t <= 1.05e+233) && (t <= 1.32e+250))) {
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 <= 33.0d0) .or. (.not. (t <= 1.05d+233)) .and. (t <= 1.32d+250)) 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 <= 33.0) || (!(t <= 1.05e+233) && (t <= 1.32e+250))) {
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 <= 33.0) or (not (t <= 1.05e+233) and (t <= 1.32e+250)): 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 <= 33.0) || (!(t <= 1.05e+233) && (t <= 1.32e+250))) 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 <= 33.0) || (~((t <= 1.05e+233)) && (t <= 1.32e+250))) 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[Or[LessEqual[t, 33.0], And[N[Not[LessEqual[t, 1.05e+233]], $MachinePrecision], LessEqual[t, 1.32e+250]]], 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 33 \lor \neg \left(t \leq 1.05 \cdot 10^{+233}\right) \land t \leq 1.32 \cdot 10^{+250}:\\
\;\;\;\;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 < 33 or 1.04999999999999998e233 < t < 1.32000000000000005e250Initial program 99.8%
associate-*l*99.7%
exp-sqrt99.7%
Simplified99.7%
Taylor expanded in t around 0 69.8%
expm1-log1p-u68.4%
expm1-udef39.6%
sqrt-unprod39.6%
Applied egg-rr39.6%
expm1-def68.4%
expm1-log1p70.0%
Simplified70.0%
if 33 < t < 1.04999999999999998e233 or 1.32000000000000005e250 < t Initial program 96.6%
associate-*l*100.0%
exp-sqrt100.0%
Simplified100.0%
Taylor expanded in t around 0 16.1%
expm1-log1p-u16.1%
expm1-udef14.9%
sqrt-unprod14.9%
Applied egg-rr14.9%
expm1-def16.1%
expm1-log1p16.1%
Simplified16.1%
add-sqr-sqrt8.7%
sqrt-unprod20.1%
*-commutative20.1%
*-commutative20.1%
swap-sqr25.0%
add-sqr-sqrt25.0%
pow225.0%
Applied egg-rr25.0%
Final simplification59.8%
(FPCore (x y z t) :precision binary64 (if (<= (* t t) 2.5) (* (- (* x 0.5) y) (sqrt (* 2.0 z))) (sqrt (* (exp (* t t)) (* 2.0 (* z (* y y)))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((t * t) <= 2.5) {
tmp = ((x * 0.5) - y) * sqrt((2.0 * z));
} else {
tmp = sqrt((exp((t * t)) * (2.0 * (z * (y * y)))));
}
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 * t) <= 2.5d0) then
tmp = ((x * 0.5d0) - y) * sqrt((2.0d0 * z))
else
tmp = sqrt((exp((t * t)) * (2.0d0 * (z * (y * y)))))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((t * t) <= 2.5) {
tmp = ((x * 0.5) - y) * Math.sqrt((2.0 * z));
} else {
tmp = Math.sqrt((Math.exp((t * t)) * (2.0 * (z * (y * y)))));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t * t) <= 2.5: tmp = ((x * 0.5) - y) * math.sqrt((2.0 * z)) else: tmp = math.sqrt((math.exp((t * t)) * (2.0 * (z * (y * y))))) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(t * t) <= 2.5) tmp = Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(2.0 * z))); else tmp = sqrt(Float64(exp(Float64(t * t)) * Float64(2.0 * Float64(z * Float64(y * y))))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((t * t) <= 2.5) tmp = ((x * 0.5) - y) * sqrt((2.0 * z)); else tmp = sqrt((exp((t * t)) * (2.0 * (z * (y * y))))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(t * t), $MachinePrecision], 2.5], N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(2.0 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Exp[N[(t * t), $MachinePrecision]], $MachinePrecision] * N[(2.0 * N[(z * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \cdot t \leq 2.5:\\
\;\;\;\;\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{e^{t \cdot t} \cdot \left(2 \cdot \left(z \cdot \left(y \cdot y\right)\right)\right)}\\
\end{array}
\end{array}
if (*.f64 t t) < 2.5Initial program 99.6%
associate-*l*99.6%
exp-sqrt99.6%
Simplified99.6%
Taylor expanded in t around 0 98.8%
expm1-log1p-u96.5%
expm1-udef52.5%
sqrt-unprod52.5%
Applied egg-rr52.5%
expm1-def96.6%
expm1-log1p99.1%
Simplified99.1%
if 2.5 < (*.f64 t t) Initial program 98.4%
add-sqr-sqrt50.0%
sqrt-unprod45.3%
*-commutative45.3%
*-commutative45.3%
swap-sqr45.3%
add-sqr-sqrt45.3%
pow245.3%
Applied egg-rr45.3%
Taylor expanded in x around 0 36.7%
associate-*r*36.7%
unpow236.7%
Simplified36.7%
*-commutative36.7%
exp-sqrt36.7%
pow-exp36.7%
sqrt-unprod36.7%
pow-exp36.7%
associate-*l*36.7%
Applied egg-rr36.7%
Final simplification67.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.0%
associate-*l*99.8%
exp-sqrt99.8%
Simplified99.8%
Taylor expanded in t around 0 57.7%
expm1-log1p-u56.5%
expm1-udef34.0%
sqrt-unprod34.0%
Applied egg-rr34.0%
expm1-def56.6%
expm1-log1p57.8%
Simplified57.8%
Final simplification57.8%
(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 2023228
(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))))