
(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 -6.8e+35)
t_1
(if (<= y -3.4e-143)
(* y z)
(if (<= y 6.5e-55) t (if (<= y 9.2e+111) (* y z) t_1))))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -6.8e+35) {
tmp = t_1;
} else if (y <= -3.4e-143) {
tmp = y * z;
} else if (y <= 6.5e-55) {
tmp = t;
} else if (y <= 9.2e+111) {
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 <= (-6.8d+35)) then
tmp = t_1
else if (y <= (-3.4d-143)) then
tmp = y * z
else if (y <= 6.5d-55) then
tmp = t
else if (y <= 9.2d+111) 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 <= -6.8e+35) {
tmp = t_1;
} else if (y <= -3.4e-143) {
tmp = y * z;
} else if (y <= 6.5e-55) {
tmp = t;
} else if (y <= 9.2e+111) {
tmp = y * z;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -6.8e+35: tmp = t_1 elif y <= -3.4e-143: tmp = y * z elif y <= 6.5e-55: tmp = t elif y <= 9.2e+111: 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 <= -6.8e+35) tmp = t_1; elseif (y <= -3.4e-143) tmp = Float64(y * z); elseif (y <= 6.5e-55) tmp = t; elseif (y <= 9.2e+111) 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 <= -6.8e+35) tmp = t_1; elseif (y <= -3.4e-143) tmp = y * z; elseif (y <= 6.5e-55) tmp = t; elseif (y <= 9.2e+111) 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, -6.8e+35], t$95$1, If[LessEqual[y, -3.4e-143], N[(y * z), $MachinePrecision], If[LessEqual[y, 6.5e-55], t, If[LessEqual[y, 9.2e+111], 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 -6.8 \cdot 10^{+35}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -3.4 \cdot 10^{-143}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-55}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 9.2 \cdot 10^{+111}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -6.8000000000000002e35 or 9.20000000000000008e111 < y Initial program 100.0%
Taylor expanded in t around inf 94.2%
associate-/l*94.2%
+-commutative94.2%
*-commutative94.2%
fma-undefine94.2%
Simplified94.2%
Taylor expanded in t around 0 93.0%
Taylor expanded in z around 0 80.4%
*-commutative80.4%
Simplified80.4%
if -6.8000000000000002e35 < y < -3.39999999999999983e-143 or 6.50000000000000006e-55 < y < 9.20000000000000008e111Initial program 99.9%
Taylor expanded in t around inf 87.9%
associate-/l*85.4%
+-commutative85.4%
*-commutative85.4%
fma-undefine85.4%
Simplified85.4%
Taylor expanded in z around inf 50.5%
if -3.39999999999999983e-143 < y < 6.50000000000000006e-55Initial program 99.9%
Taylor expanded in y around 0 70.9%
Final simplification68.2%
(FPCore (x y z t) :precision binary64 (if (or (<= z -8e+113) (not (<= z 1.35e+66))) (+ t (* y z)) (+ t (* y (* x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -8e+113) || !(z <= 1.35e+66)) {
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 <= (-8d+113)) .or. (.not. (z <= 1.35d+66))) 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 <= -8e+113) || !(z <= 1.35e+66)) {
tmp = t + (y * z);
} else {
tmp = t + (y * (x * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -8e+113) or not (z <= 1.35e+66): tmp = t + (y * z) else: tmp = t + (y * (x * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -8e+113) || !(z <= 1.35e+66)) 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 <= -8e+113) || ~((z <= 1.35e+66))) tmp = t + (y * z); else tmp = t + (y * (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -8e+113], N[Not[LessEqual[z, 1.35e+66]], $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 -8 \cdot 10^{+113} \lor \neg \left(z \leq 1.35 \cdot 10^{+66}\right):\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -8e113 or 1.35e66 < z Initial program 100.0%
Taylor expanded in x around 0 93.9%
if -8e113 < z < 1.35e66Initial program 99.9%
Taylor expanded in x around inf 90.0%
*-commutative90.0%
Simplified90.0%
Final simplification91.4%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.85e-25) (not (<= y 6e+99))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.85e-25) || !(y <= 6e+99)) {
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.85d-25)) .or. (.not. (y <= 6d+99))) 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.85e-25) || !(y <= 6e+99)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.85e-25) or not (y <= 6e+99): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.85e-25) || !(y <= 6e+99)) 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.85e-25) || ~((y <= 6e+99))) 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.85e-25], N[Not[LessEqual[y, 6e+99]], $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.85 \cdot 10^{-25} \lor \neg \left(y \leq 6 \cdot 10^{+99}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.85000000000000004e-25 or 6.00000000000000029e99 < y Initial program 99.9%
Taylor expanded in t around inf 92.0%
associate-/l*92.0%
+-commutative92.0%
*-commutative92.0%
fma-undefine92.0%
Simplified92.0%
Taylor expanded in t around 0 91.8%
if -1.85000000000000004e-25 < y < 6.00000000000000029e99Initial program 99.9%
Taylor expanded in x around 0 87.3%
Final simplification89.4%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3.6e+111) (not (<= y 7e+111))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.6e+111) || !(y <= 7e+111)) {
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 <= (-3.6d+111)) .or. (.not. (y <= 7d+111))) 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 <= -3.6e+111) || !(y <= 7e+111)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -3.6e+111) or not (y <= 7e+111): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -3.6e+111) || !(y <= 7e+111)) 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 <= -3.6e+111) || ~((y <= 7e+111))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3.6e+111], N[Not[LessEqual[y, 7e+111]], $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 -3.6 \cdot 10^{+111} \lor \neg \left(y \leq 7 \cdot 10^{+111}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -3.6000000000000002e111 or 7.0000000000000004e111 < y Initial program 100.0%
Taylor expanded in t around inf 95.4%
associate-/l*95.4%
+-commutative95.4%
*-commutative95.4%
fma-undefine95.4%
Simplified95.4%
Taylor expanded in t around 0 100.0%
Taylor expanded in z around 0 88.5%
*-commutative88.5%
Simplified88.5%
if -3.6000000000000002e111 < y < 7.0000000000000004e111Initial program 99.9%
Taylor expanded in x around 0 83.3%
Final simplification85.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z -22.0) (not (<= z 7.5e+54))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -22.0) || !(z <= 7.5e+54)) {
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 <= (-22.0d0)) .or. (.not. (z <= 7.5d+54))) 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 <= -22.0) || !(z <= 7.5e+54)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -22.0) or not (z <= 7.5e+54): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -22.0) || !(z <= 7.5e+54)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -22.0) || ~((z <= 7.5e+54))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -22.0], N[Not[LessEqual[z, 7.5e+54]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -22 \lor \neg \left(z \leq 7.5 \cdot 10^{+54}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -22 or 7.50000000000000042e54 < z Initial program 99.9%
Taylor expanded in t around inf 89.9%
associate-/l*81.9%
+-commutative81.9%
*-commutative81.9%
fma-undefine81.9%
Simplified81.9%
Taylor expanded in z around inf 63.4%
if -22 < z < 7.50000000000000042e54Initial program 99.9%
Taylor expanded in y around 0 45.5%
Final simplification54.0%
(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 34.9%
herbie shell --seed 2024116
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))