
(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 8 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 (fma (fma x y z) y t))
double code(double x, double y, double z, double t) {
return fma(fma(x, y, z), y, t);
}
function code(x, y, z, t) return fma(fma(x, y, z), y, t) end
code[x_, y_, z_, t_] := N[(N[(x * y + z), $MachinePrecision] * y + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, t\right)
\end{array}
Initial program 99.9%
fma-define99.9%
fma-define99.9%
Simplified99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* x y))))
(if (<= y -6300000000.0)
t_1
(if (<= y 12500.0) t (if (<= y 7.2e+105) (* y z) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -6300000000.0) {
tmp = t_1;
} else if (y <= 12500.0) {
tmp = t;
} else if (y <= 7.2e+105) {
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 * (x * y)
if (y <= (-6300000000.0d0)) then
tmp = t_1
else if (y <= 12500.0d0) then
tmp = t
else if (y <= 7.2d+105) 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 * (x * y);
double tmp;
if (y <= -6300000000.0) {
tmp = t_1;
} else if (y <= 12500.0) {
tmp = t;
} else if (y <= 7.2e+105) {
tmp = y * z;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -6300000000.0: tmp = t_1 elif y <= 12500.0: tmp = t elif y <= 7.2e+105: tmp = y * z else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(x * y)) tmp = 0.0 if (y <= -6300000000.0) tmp = t_1; elseif (y <= 12500.0) tmp = t; elseif (y <= 7.2e+105) tmp = Float64(y * z); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (x * y); tmp = 0.0; if (y <= -6300000000.0) tmp = t_1; elseif (y <= 12500.0) tmp = t; elseif (y <= 7.2e+105) tmp = y * z; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -6300000000.0], t$95$1, If[LessEqual[y, 12500.0], t, If[LessEqual[y, 7.2e+105], N[(y * z), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \leq -6300000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 12500:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 7.2 \cdot 10^{+105}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -6.3e9 or 7.1999999999999998e105 < y Initial program 99.9%
Taylor expanded in z around inf 98.2%
*-commutative98.2%
Simplified98.2%
Taylor expanded in t around 0 93.7%
Taylor expanded in z around 0 76.6%
if -6.3e9 < y < 12500Initial program 99.9%
Taylor expanded in y around 0 67.8%
if 12500 < y < 7.1999999999999998e105Initial program 99.9%
Taylor expanded in x around 0 79.6%
Taylor expanded in z around inf 73.1%
Taylor expanded in y around inf 66.4%
Final simplification71.4%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* x (* y y))))
(if (<= y -8200000000.0)
t_1
(if (<= y 27000.0) t (if (<= y 2.1e+101) (* y z) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = x * (y * y);
double tmp;
if (y <= -8200000000.0) {
tmp = t_1;
} else if (y <= 27000.0) {
tmp = t;
} else if (y <= 2.1e+101) {
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 = x * (y * y)
if (y <= (-8200000000.0d0)) then
tmp = t_1
else if (y <= 27000.0d0) then
tmp = t
else if (y <= 2.1d+101) 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 = x * (y * y);
double tmp;
if (y <= -8200000000.0) {
tmp = t_1;
} else if (y <= 27000.0) {
tmp = t;
} else if (y <= 2.1e+101) {
tmp = y * z;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x * (y * y) tmp = 0 if y <= -8200000000.0: tmp = t_1 elif y <= 27000.0: tmp = t elif y <= 2.1e+101: tmp = y * z else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(x * Float64(y * y)) tmp = 0.0 if (y <= -8200000000.0) tmp = t_1; elseif (y <= 27000.0) tmp = t; elseif (y <= 2.1e+101) tmp = Float64(y * z); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x * (y * y); tmp = 0.0; if (y <= -8200000000.0) tmp = t_1; elseif (y <= 27000.0) tmp = t; elseif (y <= 2.1e+101) tmp = y * z; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8200000000.0], t$95$1, If[LessEqual[y, 27000.0], t, If[LessEqual[y, 2.1e+101], N[(y * z), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \left(y \cdot y\right)\\
\mathbf{if}\;y \leq -8200000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 27000:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{+101}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -8.2e9 or 2.1e101 < y Initial program 99.9%
Taylor expanded in x around inf 75.9%
+-commutative75.9%
distribute-lft-in75.0%
unpow275.0%
associate-*l*79.5%
associate-/l*79.5%
associate-*r*71.8%
distribute-lft-out96.6%
*-commutative96.6%
Simplified96.6%
Taylor expanded in t around 0 84.5%
Taylor expanded in y around inf 71.5%
if -8.2e9 < y < 27000Initial program 99.9%
Taylor expanded in y around 0 67.8%
if 27000 < y < 2.1e101Initial program 99.9%
Taylor expanded in x around 0 79.6%
Taylor expanded in z around inf 73.1%
Taylor expanded in y around inf 66.4%
Final simplification69.3%
(FPCore (x y z t) :precision binary64 (if (or (<= y -92000000000.0) (not (<= y 1900.0))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -92000000000.0) || !(y <= 1900.0)) {
tmp = y * (z + (x * y));
} 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 <= (-92000000000.0d0)) .or. (.not. (y <= 1900.0d0))) then
tmp = y * (z + (x * y))
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 <= -92000000000.0) || !(y <= 1900.0)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -92000000000.0) or not (y <= 1900.0): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -92000000000.0) || !(y <= 1900.0)) tmp = Float64(y * Float64(z + Float64(x * y))); else tmp = Float64(t + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -92000000000.0) || ~((y <= 1900.0))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -92000000000.0], N[Not[LessEqual[y, 1900.0]], $MachinePrecision]], N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -92000000000 \lor \neg \left(y \leq 1900\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -9.2e10 or 1900 < y Initial program 99.9%
Taylor expanded in x around inf 74.3%
+-commutative74.3%
distribute-lft-in72.7%
unpow272.7%
associate-*l*76.7%
associate-/l*76.7%
associate-*r*71.4%
distribute-lft-out94.0%
*-commutative94.0%
Simplified94.0%
Taylor expanded in t around 0 81.1%
Taylor expanded in x around 0 77.1%
*-commutative77.1%
unpow277.1%
associate-*r*84.7%
distribute-lft-in94.4%
*-commutative94.4%
+-commutative94.4%
Simplified94.4%
if -9.2e10 < y < 1900Initial program 99.9%
Taylor expanded in x around 0 90.8%
Final simplification92.5%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.4e+83) (not (<= y 9e+101))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.4e+83) || !(y <= 9e+101)) {
tmp = y * (x * y);
} 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 <= (-1.4d+83)) .or. (.not. (y <= 9d+101))) then
tmp = y * (x * y)
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 <= -1.4e+83) || !(y <= 9e+101)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.4e+83) or not (y <= 9e+101): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.4e+83) || !(y <= 9e+101)) tmp = Float64(y * Float64(x * y)); else tmp = Float64(t + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -1.4e+83) || ~((y <= 9e+101))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.4e+83], N[Not[LessEqual[y, 9e+101]], $MachinePrecision]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{+83} \lor \neg \left(y \leq 9 \cdot 10^{+101}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.4e83 or 9.0000000000000004e101 < y Initial program 99.9%
Taylor expanded in z around inf 99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in t around 0 98.9%
Taylor expanded in z around 0 83.1%
if -1.4e83 < y < 9.0000000000000004e101Initial program 99.9%
Taylor expanded in x around 0 87.0%
Final simplification85.6%
(FPCore (x y z t) :precision binary64 (if (or (<= z -9.6e+89) (not (<= z 2.6e+71))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -9.6e+89) || !(z <= 2.6e+71)) {
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 <= (-9.6d+89)) .or. (.not. (z <= 2.6d+71))) 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 <= -9.6e+89) || !(z <= 2.6e+71)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -9.6e+89) or not (z <= 2.6e+71): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -9.6e+89) || !(z <= 2.6e+71)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -9.6e+89) || ~((z <= 2.6e+71))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -9.6e+89], N[Not[LessEqual[z, 2.6e+71]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.6 \cdot 10^{+89} \lor \neg \left(z \leq 2.6 \cdot 10^{+71}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -9.60000000000000018e89 or 2.59999999999999991e71 < z Initial program 100.0%
Taylor expanded in x around 0 88.4%
Taylor expanded in z around inf 88.3%
Taylor expanded in y around inf 67.5%
if -9.60000000000000018e89 < z < 2.59999999999999991e71Initial program 99.9%
Taylor expanded in y around 0 47.3%
Final simplification54.1%
(FPCore (x y z t) :precision binary64 (+ t (* y (+ z (* x y)))))
double code(double x, double y, double z, double t) {
return t + (y * (z + (x * y)));
}
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 + (x * y)))
end function
public static double code(double x, double y, double z, double t) {
return t + (y * (z + (x * y)));
}
def code(x, y, z, t): return t + (y * (z + (x * y)))
function code(x, y, z, t) return Float64(t + Float64(y * Float64(z + Float64(x * y)))) end
function tmp = code(x, y, z, t) tmp = t + (y * (z + (x * y))); end
code[x_, y_, z_, t_] := N[(t + N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + y \cdot \left(z + x \cdot y\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 38.5%
herbie shell --seed 2024132
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))