
(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 6 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.4%
associate-*l*99.8%
exp-sqrt99.8%
Simplified99.8%
expm1-log1p-u98.6%
expm1-udef74.6%
sqrt-unprod74.6%
associate-*l*74.6%
exp-prod74.6%
Applied egg-rr74.6%
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 -1.0) (not (<= t 1.0)))
(* t_1 (sqrt (* 2.0 (* t (* z t)))))
(* t_1 (sqrt (* 2.0 z))))))
double code(double x, double y, double z, double t) {
double t_1 = (x * 0.5) - y;
double tmp;
if ((t <= -1.0) || !(t <= 1.0)) {
tmp = t_1 * sqrt((2.0 * (t * (z * t))));
} else {
tmp = t_1 * sqrt((2.0 * z));
}
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.0d0)) .or. (.not. (t <= 1.0d0))) then
tmp = t_1 * sqrt((2.0d0 * (t * (z * t))))
else
tmp = t_1 * sqrt((2.0d0 * z))
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.0) || !(t <= 1.0)) {
tmp = t_1 * Math.sqrt((2.0 * (t * (z * t))));
} else {
tmp = t_1 * Math.sqrt((2.0 * z));
}
return tmp;
}
def code(x, y, z, t): t_1 = (x * 0.5) - y tmp = 0 if (t <= -1.0) or not (t <= 1.0): tmp = t_1 * math.sqrt((2.0 * (t * (z * t)))) else: tmp = t_1 * math.sqrt((2.0 * z)) return tmp
function code(x, y, z, t) t_1 = Float64(Float64(x * 0.5) - y) tmp = 0.0 if ((t <= -1.0) || !(t <= 1.0)) tmp = Float64(t_1 * sqrt(Float64(2.0 * Float64(t * Float64(z * t))))); else tmp = Float64(t_1 * sqrt(Float64(2.0 * z))); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (x * 0.5) - y; tmp = 0.0; if ((t <= -1.0) || ~((t <= 1.0))) tmp = t_1 * sqrt((2.0 * (t * (z * t)))); else tmp = t_1 * sqrt((2.0 * z)); 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, -1.0], N[Not[LessEqual[t, 1.0]], $MachinePrecision]], N[(t$95$1 * N[Sqrt[N[(2.0 * N[(t * N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(t$95$1 * N[Sqrt[N[(2.0 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot 0.5 - y\\
\mathbf{if}\;t \leq -1 \lor \neg \left(t \leq 1\right):\\
\;\;\;\;t_1 \cdot \sqrt{2 \cdot \left(t \cdot \left(z \cdot t\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;t_1 \cdot \sqrt{2 \cdot z}\\
\end{array}
\end{array}
if t < -1 or 1 < t Initial program 99.2%
associate-*l*100.0%
exp-sqrt100.0%
Simplified100.0%
expm1-log1p-u100.0%
expm1-udef100.0%
sqrt-unprod100.0%
associate-*l*100.0%
exp-prod100.0%
Applied egg-rr100.0%
expm1-def100.0%
expm1-log1p100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
exp-prod100.0%
Simplified100.0%
Taylor expanded in t around 0 72.1%
distribute-rgt1-in72.1%
unpow272.1%
Simplified72.1%
Taylor expanded in t around inf 72.1%
unpow272.1%
associate-*l*61.6%
Simplified61.6%
if -1 < t < 1Initial program 99.6%
associate-*l*99.6%
exp-sqrt99.5%
Simplified99.5%
expm1-log1p-u97.3%
expm1-udef49.5%
sqrt-unprod49.5%
associate-*l*49.5%
exp-prod49.5%
Applied egg-rr49.5%
expm1-def97.3%
expm1-log1p99.6%
*-commutative99.6%
associate-*l*99.6%
*-commutative99.6%
exp-prod99.6%
Simplified99.6%
Taylor expanded in t around 0 98.0%
Final simplification79.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (* x 0.5) y)))
(if (<= (* t t) 1.0)
(* t_1 (sqrt (* 2.0 z)))
(* t_1 (sqrt (* 2.0 (* z (* t t))))))))
double code(double x, double y, double z, double t) {
double t_1 = (x * 0.5) - y;
double tmp;
if ((t * t) <= 1.0) {
tmp = t_1 * sqrt((2.0 * z));
} else {
tmp = t_1 * sqrt((2.0 * (z * (t * t))));
}
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 * t) <= 1.0d0) then
tmp = t_1 * sqrt((2.0d0 * z))
else
tmp = t_1 * sqrt((2.0d0 * (z * (t * t))))
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 * t) <= 1.0) {
tmp = t_1 * Math.sqrt((2.0 * z));
} else {
tmp = t_1 * Math.sqrt((2.0 * (z * (t * t))));
}
return tmp;
}
def code(x, y, z, t): t_1 = (x * 0.5) - y tmp = 0 if (t * t) <= 1.0: tmp = t_1 * math.sqrt((2.0 * z)) else: tmp = t_1 * math.sqrt((2.0 * (z * (t * t)))) return tmp
function code(x, y, z, t) t_1 = Float64(Float64(x * 0.5) - y) tmp = 0.0 if (Float64(t * t) <= 1.0) tmp = Float64(t_1 * sqrt(Float64(2.0 * z))); else tmp = Float64(t_1 * sqrt(Float64(2.0 * Float64(z * Float64(t * t))))); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (x * 0.5) - y; tmp = 0.0; if ((t * t) <= 1.0) tmp = t_1 * sqrt((2.0 * z)); else tmp = t_1 * sqrt((2.0 * (z * (t * t)))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision]}, If[LessEqual[N[(t * t), $MachinePrecision], 1.0], N[(t$95$1 * N[Sqrt[N[(2.0 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(t$95$1 * N[Sqrt[N[(2.0 * N[(z * N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot 0.5 - y\\
\mathbf{if}\;t \cdot t \leq 1:\\
\;\;\;\;t_1 \cdot \sqrt{2 \cdot z}\\
\mathbf{else}:\\
\;\;\;\;t_1 \cdot \sqrt{2 \cdot \left(z \cdot \left(t \cdot t\right)\right)}\\
\end{array}
\end{array}
if (*.f64 t t) < 1Initial program 99.6%
associate-*l*99.6%
exp-sqrt99.5%
Simplified99.5%
expm1-log1p-u97.3%
expm1-udef49.5%
sqrt-unprod49.5%
associate-*l*49.5%
exp-prod49.5%
Applied egg-rr49.5%
expm1-def97.3%
expm1-log1p99.6%
*-commutative99.6%
associate-*l*99.6%
*-commutative99.6%
exp-prod99.6%
Simplified99.6%
Taylor expanded in t around 0 98.0%
if 1 < (*.f64 t t) Initial program 99.2%
associate-*l*100.0%
exp-sqrt100.0%
Simplified100.0%
expm1-log1p-u100.0%
expm1-udef100.0%
sqrt-unprod100.0%
associate-*l*100.0%
exp-prod100.0%
Applied egg-rr100.0%
expm1-def100.0%
expm1-log1p100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
exp-prod100.0%
Simplified100.0%
Taylor expanded in t around 0 72.1%
distribute-rgt1-in72.1%
unpow272.1%
Simplified72.1%
Taylor expanded in t around inf 72.1%
*-commutative72.1%
unpow272.1%
Simplified72.1%
Final simplification85.2%
(FPCore (x y z t) :precision binary64 (* (- (* x 0.5) y) (* (sqrt (* 2.0 z)) (+ 1.0 (* 0.5 (* t t))))))
double code(double x, double y, double z, double t) {
return ((x * 0.5) - y) * (sqrt((2.0 * z)) * (1.0 + (0.5 * (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)) * (1.0d0 + (0.5d0 * (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)) * (1.0 + (0.5 * (t * t))));
}
def code(x, y, z, t): return ((x * 0.5) - y) * (math.sqrt((2.0 * z)) * (1.0 + (0.5 * (t * t))))
function code(x, y, z, t) return Float64(Float64(Float64(x * 0.5) - y) * Float64(sqrt(Float64(2.0 * z)) * Float64(1.0 + Float64(0.5 * Float64(t * t))))) end
function tmp = code(x, y, z, t) tmp = ((x * 0.5) - y) * (sqrt((2.0 * z)) * (1.0 + (0.5 * (t * t)))); end
code[x_, y_, z_, t_] := N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[(N[Sqrt[N[(2.0 * z), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(0.5 * N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{2 \cdot z} \cdot \left(1 + 0.5 \cdot \left(t \cdot t\right)\right)\right)
\end{array}
Initial program 99.4%
associate-*l*99.8%
exp-sqrt99.8%
Simplified99.8%
Taylor expanded in t around 0 86.0%
unpow286.0%
Simplified86.0%
Final simplification86.0%
(FPCore (x y z t) :precision binary64 (* (- (* x 0.5) y) (sqrt (* 2.0 (* z (+ (* t t) 1.0))))))
double code(double x, double y, double z, double t) {
return ((x * 0.5) - y) * sqrt((2.0 * (z * ((t * t) + 1.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((2.0d0 * (z * ((t * t) + 1.0d0))))
end function
public static double code(double x, double y, double z, double t) {
return ((x * 0.5) - y) * Math.sqrt((2.0 * (z * ((t * t) + 1.0))));
}
def code(x, y, z, t): return ((x * 0.5) - y) * math.sqrt((2.0 * (z * ((t * t) + 1.0))))
function code(x, y, z, t) return Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(2.0 * Float64(z * Float64(Float64(t * t) + 1.0))))) end
function tmp = code(x, y, z, t) tmp = ((x * 0.5) - y) * sqrt((2.0 * (z * ((t * t) + 1.0)))); end
code[x_, y_, z_, t_] := N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(2.0 * N[(z * N[(N[(t * t), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot \left(z \cdot \left(t \cdot t + 1\right)\right)}
\end{array}
Initial program 99.4%
associate-*l*99.8%
exp-sqrt99.8%
Simplified99.8%
expm1-log1p-u98.6%
expm1-udef74.6%
sqrt-unprod74.6%
associate-*l*74.6%
exp-prod74.6%
Applied egg-rr74.6%
expm1-def98.6%
expm1-log1p99.8%
*-commutative99.8%
associate-*l*99.8%
*-commutative99.8%
exp-prod99.8%
Simplified99.8%
Taylor expanded in t around 0 85.5%
distribute-rgt1-in85.5%
unpow285.5%
Simplified85.5%
Final simplification85.5%
(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%
Simplified99.8%
expm1-log1p-u98.6%
expm1-udef74.6%
sqrt-unprod74.6%
associate-*l*74.6%
exp-prod74.6%
Applied egg-rr74.6%
expm1-def98.6%
expm1-log1p99.8%
*-commutative99.8%
associate-*l*99.8%
*-commutative99.8%
exp-prod99.8%
Simplified99.8%
Taylor expanded in t around 0 56.0%
Final simplification56.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 2023174
(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))))