
(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.8%
Final simplification99.8%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (sqrt (* z 2.0))) (t_2 (exp (/ (* t t) 2.0))))
(if (or (<= y -1.32e-42) (not (<= y 3.7e+87)))
(* t_2 (* t_1 (- y)))
(* t_2 (* (* x 0.5) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = sqrt((z * 2.0));
double t_2 = exp(((t * t) / 2.0));
double tmp;
if ((y <= -1.32e-42) || !(y <= 3.7e+87)) {
tmp = t_2 * (t_1 * -y);
} else {
tmp = t_2 * ((x * 0.5) * t_1);
}
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) :: t_2
real(8) :: tmp
t_1 = sqrt((z * 2.0d0))
t_2 = exp(((t * t) / 2.0d0))
if ((y <= (-1.32d-42)) .or. (.not. (y <= 3.7d+87))) then
tmp = t_2 * (t_1 * -y)
else
tmp = t_2 * ((x * 0.5d0) * t_1)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = Math.sqrt((z * 2.0));
double t_2 = Math.exp(((t * t) / 2.0));
double tmp;
if ((y <= -1.32e-42) || !(y <= 3.7e+87)) {
tmp = t_2 * (t_1 * -y);
} else {
tmp = t_2 * ((x * 0.5) * t_1);
}
return tmp;
}
def code(x, y, z, t): t_1 = math.sqrt((z * 2.0)) t_2 = math.exp(((t * t) / 2.0)) tmp = 0 if (y <= -1.32e-42) or not (y <= 3.7e+87): tmp = t_2 * (t_1 * -y) else: tmp = t_2 * ((x * 0.5) * t_1) return tmp
function code(x, y, z, t) t_1 = sqrt(Float64(z * 2.0)) t_2 = exp(Float64(Float64(t * t) / 2.0)) tmp = 0.0 if ((y <= -1.32e-42) || !(y <= 3.7e+87)) tmp = Float64(t_2 * Float64(t_1 * Float64(-y))); else tmp = Float64(t_2 * Float64(Float64(x * 0.5) * t_1)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = sqrt((z * 2.0)); t_2 = exp(((t * t) / 2.0)); tmp = 0.0; if ((y <= -1.32e-42) || ~((y <= 3.7e+87))) tmp = t_2 * (t_1 * -y); else tmp = t_2 * ((x * 0.5) * t_1); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Sqrt[N[(z * 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Exp[N[(N[(t * t), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[y, -1.32e-42], N[Not[LessEqual[y, 3.7e+87]], $MachinePrecision]], N[(t$95$2 * N[(t$95$1 * (-y)), $MachinePrecision]), $MachinePrecision], N[(t$95$2 * N[(N[(x * 0.5), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \sqrt{z \cdot 2}\\
t_2 := e^{\frac{t \cdot t}{2}}\\
\mathbf{if}\;y \leq -1.32 \cdot 10^{-42} \lor \neg \left(y \leq 3.7 \cdot 10^{+87}\right):\\
\;\;\;\;t\_2 \cdot \left(t\_1 \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2 \cdot \left(\left(x \cdot 0.5\right) \cdot t\_1\right)\\
\end{array}
\end{array}
if y < -1.32000000000000006e-42 or 3.70000000000000003e87 < y Initial program 99.9%
Taylor expanded in x around 0 88.0%
mul-1-neg88.0%
associate-*l*87.9%
Simplified87.9%
pow187.9%
sqrt-unprod88.1%
Applied egg-rr88.1%
unpow188.1%
*-commutative88.1%
Simplified88.1%
if -1.32000000000000006e-42 < y < 3.70000000000000003e87Initial program 99.8%
Taylor expanded in x around inf 81.8%
*-commutative81.8%
associate-*l*81.8%
*-commutative81.8%
associate-*r*81.8%
associate-*l*81.8%
*-commutative81.8%
Simplified81.8%
expm1-log1p-u53.0%
expm1-undefine28.9%
associate-*r*28.9%
sqrt-unprod28.9%
Applied egg-rr28.9%
sub-neg28.9%
metadata-eval28.9%
+-commutative28.9%
log1p-undefine28.9%
rem-exp-log57.8%
associate-+r+81.9%
metadata-eval81.9%
+-lft-identity81.9%
*-commutative81.9%
*-commutative81.9%
Simplified81.9%
Final simplification84.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (exp (/ (* t t) 2.0))) (t_2 (sqrt (* z 2.0)))) (if (<= x 9.5e+211) (* t_1 (* t_2 (- y))) (* t_1 (* y t_2)))))
double code(double x, double y, double z, double t) {
double t_1 = exp(((t * t) / 2.0));
double t_2 = sqrt((z * 2.0));
double tmp;
if (x <= 9.5e+211) {
tmp = t_1 * (t_2 * -y);
} else {
tmp = t_1 * (y * t_2);
}
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) :: t_2
real(8) :: tmp
t_1 = exp(((t * t) / 2.0d0))
t_2 = sqrt((z * 2.0d0))
if (x <= 9.5d+211) then
tmp = t_1 * (t_2 * -y)
else
tmp = t_1 * (y * t_2)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = Math.exp(((t * t) / 2.0));
double t_2 = Math.sqrt((z * 2.0));
double tmp;
if (x <= 9.5e+211) {
tmp = t_1 * (t_2 * -y);
} else {
tmp = t_1 * (y * t_2);
}
return tmp;
}
def code(x, y, z, t): t_1 = math.exp(((t * t) / 2.0)) t_2 = math.sqrt((z * 2.0)) tmp = 0 if x <= 9.5e+211: tmp = t_1 * (t_2 * -y) else: tmp = t_1 * (y * t_2) return tmp
function code(x, y, z, t) t_1 = exp(Float64(Float64(t * t) / 2.0)) t_2 = sqrt(Float64(z * 2.0)) tmp = 0.0 if (x <= 9.5e+211) tmp = Float64(t_1 * Float64(t_2 * Float64(-y))); else tmp = Float64(t_1 * Float64(y * t_2)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = exp(((t * t) / 2.0)); t_2 = sqrt((z * 2.0)); tmp = 0.0; if (x <= 9.5e+211) tmp = t_1 * (t_2 * -y); else tmp = t_1 * (y * t_2); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Exp[N[(N[(t * t), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(z * 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 9.5e+211], N[(t$95$1 * N[(t$95$2 * (-y)), $MachinePrecision]), $MachinePrecision], N[(t$95$1 * N[(y * t$95$2), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := e^{\frac{t \cdot t}{2}}\\
t_2 := \sqrt{z \cdot 2}\\
\mathbf{if}\;x \leq 9.5 \cdot 10^{+211}:\\
\;\;\;\;t\_1 \cdot \left(t\_2 \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \left(y \cdot t\_2\right)\\
\end{array}
\end{array}
if x < 9.4999999999999997e211Initial program 99.8%
Taylor expanded in x around 0 66.4%
mul-1-neg66.4%
associate-*l*66.4%
Simplified66.4%
pow166.4%
sqrt-unprod66.5%
Applied egg-rr66.5%
unpow166.5%
*-commutative66.5%
Simplified66.5%
if 9.4999999999999997e211 < x Initial program 99.9%
add-sqr-sqrt99.9%
sqrt-unprod71.5%
*-commutative71.5%
*-commutative71.5%
swap-sqr71.5%
add-sqr-sqrt71.5%
pow271.5%
Applied egg-rr71.5%
sqrt-prod71.5%
sqrt-prod71.5%
*-commutative71.5%
add-sqr-sqrt71.5%
*-commutative71.5%
sqrt-pow199.8%
metadata-eval99.8%
pow199.8%
associate-*l*99.7%
*-commutative99.7%
sqrt-prod99.7%
pow1/299.7%
sqrt-pow199.7%
*-commutative99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 18.5%
mul-1-neg18.5%
*-commutative18.5%
distribute-rgt-neg-in18.5%
Simplified18.5%
pow118.5%
Applied egg-rr40.5%
unpow140.5%
*-commutative40.5%
Simplified40.5%
Final simplification64.2%
(FPCore (x y z t) :precision binary64 (* (exp (/ (* t t) 2.0)) (* y (sqrt (* z 2.0)))))
double code(double x, double y, double z, double t) {
return exp(((t * t) / 2.0)) * (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 = exp(((t * t) / 2.0d0)) * (y * sqrt((z * 2.0d0)))
end function
public static double code(double x, double y, double z, double t) {
return Math.exp(((t * t) / 2.0)) * (y * Math.sqrt((z * 2.0)));
}
def code(x, y, z, t): return math.exp(((t * t) / 2.0)) * (y * math.sqrt((z * 2.0)))
function code(x, y, z, t) return Float64(exp(Float64(Float64(t * t) / 2.0)) * Float64(y * sqrt(Float64(z * 2.0)))) end
function tmp = code(x, y, z, t) tmp = exp(((t * t) / 2.0)) * (y * sqrt((z * 2.0))); end
code[x_, y_, z_, t_] := N[(N[Exp[N[(N[(t * t), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] * N[(y * N[Sqrt[N[(z * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{\frac{t \cdot t}{2}} \cdot \left(y \cdot \sqrt{z \cdot 2}\right)
\end{array}
Initial program 99.8%
add-sqr-sqrt51.0%
sqrt-unprod40.3%
*-commutative40.3%
*-commutative40.3%
swap-sqr36.1%
add-sqr-sqrt36.2%
pow236.2%
Applied egg-rr36.2%
sqrt-prod38.7%
sqrt-prod38.7%
*-commutative38.7%
add-sqr-sqrt38.7%
*-commutative38.7%
sqrt-pow199.6%
metadata-eval99.6%
pow199.6%
associate-*l*99.6%
*-commutative99.6%
sqrt-prod99.7%
pow1/299.7%
sqrt-pow199.7%
*-commutative99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 62.1%
mul-1-neg62.1%
*-commutative62.1%
distribute-rgt-neg-in62.1%
Simplified62.1%
pow162.1%
Applied egg-rr12.1%
unpow112.1%
*-commutative12.1%
Simplified12.1%
Final simplification12.1%
(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 2024046
(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))))