
(FPCore (x y z t) :precision binary64 (+ (* (+ (* x y) z) y) t))
double code(double x, double y, double z, double t) {
return (((x * y) + z) * y) + 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 * y) + z) * y) + t
end function
public static double code(double x, double y, double z, double t) {
return (((x * y) + z) * y) + t;
}
def code(x, y, z, t): return (((x * y) + z) * y) + t
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x * y) + z) * y) + t) end
function tmp = code(x, y, z, t) tmp = (((x * y) + z) * y) + t; end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + z\right) \cdot y + t
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ (* (+ (* x y) z) y) t))
double code(double x, double y, double z, double t) {
return (((x * y) + z) * y) + 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 * y) + z) * y) + t
end function
public static double code(double x, double y, double z, double t) {
return (((x * y) + z) * y) + t;
}
def code(x, y, z, t): return (((x * y) + z) * y) + t
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x * y) + z) * y) + t) end
function tmp = code(x, y, z, t) tmp = (((x * y) + z) * y) + t; end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + z\right) \cdot y + t
\end{array}
(FPCore (x y z t) :precision binary64 (+ (* y (+ (* x y) z)) t))
double code(double x, double y, double z, double t) {
return (y * ((x * y) + z)) + 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 = (y * ((x * y) + z)) + t
end function
public static double code(double x, double y, double z, double t) {
return (y * ((x * y) + z)) + t;
}
def code(x, y, z, t): return (y * ((x * y) + z)) + t
function code(x, y, z, t) return Float64(Float64(y * Float64(Float64(x * y) + z)) + t) end
function tmp = code(x, y, z, t) tmp = (y * ((x * y) + z)) + t; end
code[x_, y_, z_, t_] := N[(N[(y * N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(x \cdot y + z\right) + t
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z t) :precision binary64 (if (or (<= z -3.6e-23) (not (<= z 4.8e+113))) (+ t (* y z)) (+ t (* x (* y y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.6e-23) || !(z <= 4.8e+113)) {
tmp = t + (y * z);
} else {
tmp = t + (x * (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 ((z <= (-3.6d-23)) .or. (.not. (z <= 4.8d+113))) then
tmp = t + (y * z)
else
tmp = t + (x * (y * y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.6e-23) || !(z <= 4.8e+113)) {
tmp = t + (y * z);
} else {
tmp = t + (x * (y * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3.6e-23) or not (z <= 4.8e+113): tmp = t + (y * z) else: tmp = t + (x * (y * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.6e-23) || !(z <= 4.8e+113)) tmp = Float64(t + Float64(y * z)); else tmp = Float64(t + Float64(x * Float64(y * y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -3.6e-23) || ~((z <= 4.8e+113))) tmp = t + (y * z); else tmp = t + (x * (y * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.6e-23], N[Not[LessEqual[z, 4.8e+113]], $MachinePrecision]], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(t + N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.6 \cdot 10^{-23} \lor \neg \left(z \leq 4.8 \cdot 10^{+113}\right):\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t + x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if z < -3.5999999999999998e-23 or 4.79999999999999966e113 < z Initial program 100.0%
Taylor expanded in x around 0 87.8%
if -3.5999999999999998e-23 < z < 4.79999999999999966e113Initial program 99.9%
add-cbrt-cube87.0%
pow387.0%
fma-define87.0%
Applied egg-rr87.0%
Taylor expanded in x around inf 89.8%
+-commutative89.8%
unpow289.8%
associate-/l*88.5%
distribute-lft-out90.6%
Simplified90.6%
Taylor expanded in y around inf 88.6%
Final simplification88.3%
(FPCore (x y z t) :precision binary64 (if (or (<= z -3.6e-23) (not (<= z 4.8e+112))) (+ t (* y z)) (+ t (* y (* x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.6e-23) || !(z <= 4.8e+112)) {
tmp = t + (y * z);
} else {
tmp = t + (y * (x * 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 ((z <= (-3.6d-23)) .or. (.not. (z <= 4.8d+112))) then
tmp = t + (y * z)
else
tmp = t + (y * (x * y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.6e-23) || !(z <= 4.8e+112)) {
tmp = t + (y * z);
} else {
tmp = t + (y * (x * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3.6e-23) or not (z <= 4.8e+112): tmp = t + (y * z) else: tmp = t + (y * (x * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.6e-23) || !(z <= 4.8e+112)) tmp = Float64(t + Float64(y * z)); else tmp = Float64(t + Float64(y * Float64(x * y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -3.6e-23) || ~((z <= 4.8e+112))) tmp = t + (y * z); else tmp = t + (y * (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.6e-23], N[Not[LessEqual[z, 4.8e+112]], $MachinePrecision]], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.6 \cdot 10^{-23} \lor \neg \left(z \leq 4.8 \cdot 10^{+112}\right):\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -3.5999999999999998e-23 or 4.8e112 < z Initial program 100.0%
Taylor expanded in x around 0 87.8%
if -3.5999999999999998e-23 < z < 4.8e112Initial program 99.9%
Taylor expanded in x around inf 94.0%
*-commutative94.0%
Simplified94.0%
Final simplification91.5%
(FPCore (x y z t) :precision binary64 (+ t (* y z)))
double code(double x, double y, double z, double t) {
return t + (y * 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 = t + (y * z)
end function
public static double code(double x, double y, double z, double t) {
return t + (y * z);
}
def code(x, y, z, t): return t + (y * z)
function code(x, y, z, t) return Float64(t + Float64(y * z)) end
function tmp = code(x, y, z, t) tmp = t + (y * z); end
code[x_, y_, z_, t_] := N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + y \cdot z
\end{array}
Initial program 99.9%
Taylor expanded in x around 0 65.9%
Final simplification65.9%
herbie shell --seed 2024082
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))