
(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 7 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 (fma y x z)) t))
double code(double x, double y, double z, double t) {
return (y * fma(y, x, z)) + t;
}
function code(x, y, z, t) return Float64(Float64(y * fma(y, x, z)) + t) end
code[x_, y_, z_, t_] := N[(N[(y * N[(y * x + z), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \mathsf{fma}\left(y, x, z\right) + t
\end{array}
Initial program 99.9%
Taylor expanded in x around 0 99.9%
+-commutative99.9%
*-commutative99.9%
fma-undefine99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* y x))))
(if (<= y -4200000000.0)
t_1
(if (<= y -9.5e-80)
(* y z)
(if (<= y 2.2e-31) t (if (<= y 9.2e+50) (* y z) t_1))))))
double code(double x, double y, double z, double t) {
double t_1 = y * (y * x);
double tmp;
if (y <= -4200000000.0) {
tmp = t_1;
} else if (y <= -9.5e-80) {
tmp = y * z;
} else if (y <= 2.2e-31) {
tmp = t;
} else if (y <= 9.2e+50) {
tmp = y * z;
} else {
tmp = 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) :: tmp
t_1 = y * (y * x)
if (y <= (-4200000000.0d0)) then
tmp = t_1
else if (y <= (-9.5d-80)) then
tmp = y * z
else if (y <= 2.2d-31) then
tmp = t
else if (y <= 9.2d+50) then
tmp = y * z
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = y * (y * x);
double tmp;
if (y <= -4200000000.0) {
tmp = t_1;
} else if (y <= -9.5e-80) {
tmp = y * z;
} else if (y <= 2.2e-31) {
tmp = t;
} else if (y <= 9.2e+50) {
tmp = y * z;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (y * x) tmp = 0 if y <= -4200000000.0: tmp = t_1 elif y <= -9.5e-80: tmp = y * z elif y <= 2.2e-31: tmp = t elif y <= 9.2e+50: tmp = y * z else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(y * x)) tmp = 0.0 if (y <= -4200000000.0) tmp = t_1; elseif (y <= -9.5e-80) tmp = Float64(y * z); elseif (y <= 2.2e-31) tmp = t; elseif (y <= 9.2e+50) tmp = Float64(y * z); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (y * x); tmp = 0.0; if (y <= -4200000000.0) tmp = t_1; elseif (y <= -9.5e-80) tmp = y * z; elseif (y <= 2.2e-31) tmp = t; elseif (y <= 9.2e+50) tmp = y * z; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4200000000.0], t$95$1, If[LessEqual[y, -9.5e-80], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.2e-31], t, If[LessEqual[y, 9.2e+50], N[(y * z), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(y \cdot x\right)\\
\mathbf{if}\;y \leq -4200000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -9.5 \cdot 10^{-80}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{-31}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 9.2 \cdot 10^{+50}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -4.2e9 or 9.19999999999999987e50 < y Initial program 99.9%
Taylor expanded in t around inf 86.5%
associate-/l*86.5%
+-commutative86.5%
*-commutative86.5%
fma-undefine86.5%
Simplified86.5%
Taylor expanded in t around 0 92.5%
Taylor expanded in z around 0 69.8%
if -4.2e9 < y < -9.5000000000000003e-80 or 2.2000000000000001e-31 < y < 9.19999999999999987e50Initial program 100.0%
Taylor expanded in t around inf 82.8%
associate-/l*80.1%
+-commutative80.1%
*-commutative80.1%
fma-undefine80.1%
Simplified80.1%
Taylor expanded in t around 0 76.6%
Taylor expanded in y around 0 58.6%
if -9.5000000000000003e-80 < y < 2.2000000000000001e-31Initial program 99.9%
Taylor expanded in y around 0 66.9%
Final simplification66.7%
(FPCore (x y z t) :precision binary64 (if (or (<= y -6.5e-40) (not (<= y 1.56e-18))) (* y (+ z (* y x))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -6.5e-40) || !(y <= 1.56e-18)) {
tmp = y * (z + (y * x));
} else {
tmp = t + (y * 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) :: tmp
if ((y <= (-6.5d-40)) .or. (.not. (y <= 1.56d-18))) then
tmp = y * (z + (y * x))
else
tmp = t + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -6.5e-40) || !(y <= 1.56e-18)) {
tmp = y * (z + (y * x));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -6.5e-40) or not (y <= 1.56e-18): tmp = y * (z + (y * x)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -6.5e-40) || !(y <= 1.56e-18)) tmp = Float64(y * Float64(z + Float64(y * x))); else tmp = Float64(t + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -6.5e-40) || ~((y <= 1.56e-18))) tmp = y * (z + (y * x)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -6.5e-40], N[Not[LessEqual[y, 1.56e-18]], $MachinePrecision]], N[(y * N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{-40} \lor \neg \left(y \leq 1.56 \cdot 10^{-18}\right):\\
\;\;\;\;y \cdot \left(z + y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -6.4999999999999999e-40 or 1.55999999999999998e-18 < y Initial program 99.9%
Taylor expanded in t around inf 85.7%
associate-/l*85.6%
+-commutative85.6%
*-commutative85.6%
fma-undefine85.6%
Simplified85.6%
Taylor expanded in t around 0 89.9%
if -6.4999999999999999e-40 < y < 1.55999999999999998e-18Initial program 99.9%
Taylor expanded in x around 0 91.8%
Final simplification90.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -7000000000.0) (not (<= y 9e+84))) (* y (* y x)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -7000000000.0) || !(y <= 9e+84)) {
tmp = y * (y * x);
} else {
tmp = t + (y * 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) :: tmp
if ((y <= (-7000000000.0d0)) .or. (.not. (y <= 9d+84))) then
tmp = y * (y * x)
else
tmp = t + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -7000000000.0) || !(y <= 9e+84)) {
tmp = y * (y * x);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -7000000000.0) or not (y <= 9e+84): tmp = y * (y * x) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -7000000000.0) || !(y <= 9e+84)) tmp = Float64(y * Float64(y * x)); else tmp = Float64(t + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -7000000000.0) || ~((y <= 9e+84))) tmp = y * (y * x); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -7000000000.0], N[Not[LessEqual[y, 9e+84]], $MachinePrecision]], N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7000000000 \lor \neg \left(y \leq 9 \cdot 10^{+84}\right):\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -7e9 or 8.9999999999999994e84 < y Initial program 99.9%
Taylor expanded in t around inf 88.0%
associate-/l*88.0%
+-commutative88.0%
*-commutative88.0%
fma-undefine88.0%
Simplified88.0%
Taylor expanded in t around 0 93.8%
Taylor expanded in z around 0 73.9%
if -7e9 < y < 8.9999999999999994e84Initial program 99.9%
Taylor expanded in x around 0 86.7%
Final simplification82.8%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.1e+189) (not (<= z 1.05e-29))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.1e+189) || !(z <= 1.05e-29)) {
tmp = y * z;
} else {
tmp = 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) :: tmp
if ((z <= (-2.1d+189)) .or. (.not. (z <= 1.05d-29))) then
tmp = y * z
else
tmp = t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.1e+189) || !(z <= 1.05e-29)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.1e+189) or not (z <= 1.05e-29): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.1e+189) || !(z <= 1.05e-29)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -2.1e+189) || ~((z <= 1.05e-29))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.1e+189], N[Not[LessEqual[z, 1.05e-29]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.1 \cdot 10^{+189} \lor \neg \left(z \leq 1.05 \cdot 10^{-29}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -2.09999999999999992e189 or 1.04999999999999995e-29 < z Initial program 99.9%
Taylor expanded in t around inf 89.1%
associate-/l*78.7%
+-commutative78.7%
*-commutative78.7%
fma-undefine78.7%
Simplified78.7%
Taylor expanded in t around 0 78.4%
Taylor expanded in y around 0 62.4%
if -2.09999999999999992e189 < z < 1.04999999999999995e-29Initial program 99.9%
Taylor expanded in y around 0 52.4%
Final simplification56.5%
(FPCore (x y z t) :precision binary64 (+ t (* y (+ z (* y x)))))
double code(double x, double y, double z, double t) {
return t + (y * (z + (y * x)));
}
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 + (y * x)))
end function
public static double code(double x, double y, double z, double t) {
return t + (y * (z + (y * x)));
}
def code(x, y, z, t): return t + (y * (z + (y * x)))
function code(x, y, z, t) return Float64(t + Float64(y * Float64(z + Float64(y * x)))) end
function tmp = code(x, y, z, t) tmp = t + (y * (z + (y * x))); end
code[x_, y_, z_, t_] := N[(t + N[(y * N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + y \cdot \left(z + y \cdot x\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z t) :precision binary64 t)
double code(double x, double y, double z, double t) {
return 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 = t
end function
public static double code(double x, double y, double z, double t) {
return t;
}
def code(x, y, z, t): return t
function code(x, y, z, t) return t end
function tmp = code(x, y, z, t) tmp = t; end
code[x_, y_, z_, t_] := t
\begin{array}{l}
\\
t
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 40.6%
herbie shell --seed 2024157
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))