
(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%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(if (or (<= y -1.05e-17)
(and (not (<= y 4.9e-91))
(or (<= y 17000000000000.0) (not (<= y 1.3e+45)))))
(* y (+ z (* x y)))
(+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.05e-17) || (!(y <= 4.9e-91) && ((y <= 17000000000000.0) || !(y <= 1.3e+45)))) {
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 <= (-1.05d-17)) .or. (.not. (y <= 4.9d-91)) .and. (y <= 17000000000000.0d0) .or. (.not. (y <= 1.3d+45))) 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 <= -1.05e-17) || (!(y <= 4.9e-91) && ((y <= 17000000000000.0) || !(y <= 1.3e+45)))) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.05e-17) or (not (y <= 4.9e-91) and ((y <= 17000000000000.0) or not (y <= 1.3e+45))): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.05e-17) || (!(y <= 4.9e-91) && ((y <= 17000000000000.0) || !(y <= 1.3e+45)))) 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 <= -1.05e-17) || (~((y <= 4.9e-91)) && ((y <= 17000000000000.0) || ~((y <= 1.3e+45))))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.05e-17], And[N[Not[LessEqual[y, 4.9e-91]], $MachinePrecision], Or[LessEqual[y, 17000000000000.0], N[Not[LessEqual[y, 1.3e+45]], $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 -1.05 \cdot 10^{-17} \lor \neg \left(y \leq 4.9 \cdot 10^{-91}\right) \land \left(y \leq 17000000000000 \lor \neg \left(y \leq 1.3 \cdot 10^{+45}\right)\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.04999999999999996e-17 or 4.8999999999999998e-91 < y < 1.7e13 or 1.30000000000000004e45 < y Initial program 99.8%
Taylor expanded in z around inf 94.9%
associate-/l*90.4%
Simplified90.4%
Taylor expanded in t around 0 87.8%
Taylor expanded in z around 0 92.1%
*-commutative92.1%
Simplified92.1%
if -1.04999999999999996e-17 < y < 4.8999999999999998e-91 or 1.7e13 < y < 1.30000000000000004e45Initial program 100.0%
Taylor expanded in x around 0 95.7%
Final simplification93.6%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (+ z (* x y)))))
(if (<= y -1.05e-17)
t_1
(if (<= y 4.9e-91)
(+ t (* y z))
(if (or (<= y 2.1e-25) (not (<= y 1.6e+46)))
t_1
(+ t (* y (* x y))))))))
double code(double x, double y, double z, double t) {
double t_1 = y * (z + (x * y));
double tmp;
if (y <= -1.05e-17) {
tmp = t_1;
} else if (y <= 4.9e-91) {
tmp = t + (y * z);
} else if ((y <= 2.1e-25) || !(y <= 1.6e+46)) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_1 = y * (z + (x * y))
if (y <= (-1.05d-17)) then
tmp = t_1
else if (y <= 4.9d-91) then
tmp = t + (y * z)
else if ((y <= 2.1d-25) .or. (.not. (y <= 1.6d+46))) then
tmp = t_1
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 t_1 = y * (z + (x * y));
double tmp;
if (y <= -1.05e-17) {
tmp = t_1;
} else if (y <= 4.9e-91) {
tmp = t + (y * z);
} else if ((y <= 2.1e-25) || !(y <= 1.6e+46)) {
tmp = t_1;
} else {
tmp = t + (y * (x * y));
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (z + (x * y)) tmp = 0 if y <= -1.05e-17: tmp = t_1 elif y <= 4.9e-91: tmp = t + (y * z) elif (y <= 2.1e-25) or not (y <= 1.6e+46): tmp = t_1 else: tmp = t + (y * (x * y)) return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(z + Float64(x * y))) tmp = 0.0 if (y <= -1.05e-17) tmp = t_1; elseif (y <= 4.9e-91) tmp = Float64(t + Float64(y * z)); elseif ((y <= 2.1e-25) || !(y <= 1.6e+46)) tmp = t_1; else tmp = Float64(t + Float64(y * Float64(x * y))); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (z + (x * y)); tmp = 0.0; if (y <= -1.05e-17) tmp = t_1; elseif (y <= 4.9e-91) tmp = t + (y * z); elseif ((y <= 2.1e-25) || ~((y <= 1.6e+46))) tmp = t_1; else tmp = t + (y * (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.05e-17], t$95$1, If[LessEqual[y, 4.9e-91], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 2.1e-25], N[Not[LessEqual[y, 1.6e+46]], $MachinePrecision]], t$95$1, N[(t + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(z + x \cdot y\right)\\
\mathbf{if}\;y \leq -1.05 \cdot 10^{-17}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 4.9 \cdot 10^{-91}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{-25} \lor \neg \left(y \leq 1.6 \cdot 10^{+46}\right):\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if y < -1.04999999999999996e-17 or 4.8999999999999998e-91 < y < 2.10000000000000002e-25 or 1.5999999999999999e46 < y Initial program 99.9%
Taylor expanded in z around inf 95.2%
associate-/l*90.4%
Simplified90.4%
Taylor expanded in t around 0 89.7%
Taylor expanded in z around 0 93.6%
*-commutative93.6%
Simplified93.6%
if -1.04999999999999996e-17 < y < 4.8999999999999998e-91Initial program 100.0%
Taylor expanded in x around 0 96.3%
if 2.10000000000000002e-25 < y < 1.5999999999999999e46Initial program 99.8%
Taylor expanded in x around inf 80.7%
*-commutative80.7%
Simplified80.7%
Final simplification93.6%
(FPCore (x y z t)
:precision binary64
(if (or (<= y -6.5e-26)
(not (or (<= y 4.7e-91) (and (not (<= y 8.5e+18)) (<= y 1.1e+42)))))
(* y (* x y))
t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -6.5e-26) || !((y <= 4.7e-91) || (!(y <= 8.5e+18) && (y <= 1.1e+42)))) {
tmp = y * (x * y);
} 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 ((y <= (-6.5d-26)) .or. (.not. (y <= 4.7d-91) .or. (.not. (y <= 8.5d+18)) .and. (y <= 1.1d+42))) then
tmp = y * (x * y)
else
tmp = t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -6.5e-26) || !((y <= 4.7e-91) || (!(y <= 8.5e+18) && (y <= 1.1e+42)))) {
tmp = y * (x * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -6.5e-26) or not ((y <= 4.7e-91) or (not (y <= 8.5e+18) and (y <= 1.1e+42))): tmp = y * (x * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -6.5e-26) || !((y <= 4.7e-91) || (!(y <= 8.5e+18) && (y <= 1.1e+42)))) tmp = Float64(y * Float64(x * y)); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -6.5e-26) || ~(((y <= 4.7e-91) || (~((y <= 8.5e+18)) && (y <= 1.1e+42))))) tmp = y * (x * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -6.5e-26], N[Not[Or[LessEqual[y, 4.7e-91], And[N[Not[LessEqual[y, 8.5e+18]], $MachinePrecision], LessEqual[y, 1.1e+42]]]], $MachinePrecision]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{-26} \lor \neg \left(y \leq 4.7 \cdot 10^{-91} \lor \neg \left(y \leq 8.5 \cdot 10^{+18}\right) \land y \leq 1.1 \cdot 10^{+42}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -6.5e-26 or 4.70000000000000006e-91 < y < 8.5e18 or 1.1000000000000001e42 < y Initial program 99.8%
Taylor expanded in z around inf 95.0%
associate-/l*90.6%
Simplified90.6%
Taylor expanded in t around 0 87.4%
Taylor expanded in z around 0 67.1%
*-commutative67.1%
Simplified67.1%
if -6.5e-26 < y < 4.70000000000000006e-91 or 8.5e18 < y < 1.1000000000000001e42Initial program 100.0%
Taylor expanded in y around 0 66.5%
Final simplification66.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.25e+91) (not (<= y 8.2e+48))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.25e+91) || !(y <= 8.2e+48)) {
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.25d+91)) .or. (.not. (y <= 8.2d+48))) 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.25e+91) || !(y <= 8.2e+48)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.25e+91) or not (y <= 8.2e+48): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.25e+91) || !(y <= 8.2e+48)) 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.25e+91) || ~((y <= 8.2e+48))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.25e+91], N[Not[LessEqual[y, 8.2e+48]], $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.25 \cdot 10^{+91} \lor \neg \left(y \leq 8.2 \cdot 10^{+48}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.2500000000000001e91 or 8.2000000000000005e48 < y Initial program 99.9%
Taylor expanded in z around inf 98.9%
associate-/l*93.1%
Simplified93.1%
Taylor expanded in t around 0 94.9%
Taylor expanded in z around 0 78.8%
*-commutative78.8%
Simplified78.8%
if -1.2500000000000001e91 < y < 8.2000000000000005e48Initial program 99.9%
Taylor expanded in x around 0 82.0%
Final simplification80.8%
(FPCore (x y z t) :precision binary64 (if (or (<= z -4.7e+89) (not (<= z 1.4e-5))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4.7e+89) || !(z <= 1.4e-5)) {
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 <= (-4.7d+89)) .or. (.not. (z <= 1.4d-5))) 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 <= -4.7e+89) || !(z <= 1.4e-5)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -4.7e+89) or not (z <= 1.4e-5): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -4.7e+89) || !(z <= 1.4e-5)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -4.7e+89) || ~((z <= 1.4e-5))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -4.7e+89], N[Not[LessEqual[z, 1.4e-5]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.7 \cdot 10^{+89} \lor \neg \left(z \leq 1.4 \cdot 10^{-5}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -4.70000000000000022e89 or 1.39999999999999998e-5 < z Initial program 99.9%
Taylor expanded in x around inf 66.5%
+-commutative66.5%
+-commutative66.5%
unpow266.5%
associate-/l*65.1%
distribute-lft-out69.4%
Simplified69.4%
Taylor expanded in t around -inf 69.4%
mul-1-neg69.4%
distribute-rgt-neg-in69.4%
fma-neg69.4%
associate-/l*67.9%
associate-/l*65.9%
associate-*r*68.6%
*-commutative68.6%
metadata-eval68.6%
Simplified68.6%
Taylor expanded in z around inf 57.6%
if -4.70000000000000022e89 < z < 1.39999999999999998e-5Initial program 99.9%
Taylor expanded in y around 0 42.5%
Final simplification49.8%
(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 33.2%
Final simplification33.2%
herbie shell --seed 2024066
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))