
(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 (+ t (* y (+ (* x y) z))))
double code(double x, double y, double z, double t) {
return t + (y * ((x * 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 * ((x * y) + z))
end function
public static double code(double x, double y, double z, double t) {
return t + (y * ((x * y) + z));
}
def code(x, y, z, t): return t + (y * ((x * y) + z))
function code(x, y, z, t) return Float64(t + Float64(y * Float64(Float64(x * y) + z))) end
function tmp = code(x, y, z, t) tmp = t + (y * ((x * y) + z)); end
code[x_, y_, z_, t_] := N[(t + N[(y * N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + y \cdot \left(x \cdot y + z\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(if (or (<= y -7.5e+146)
(not
(or (<= y -9.2e+78) (and (not (<= y -8.8e+46)) (<= y 1.1e+112)))))
(* y (* x y))
(+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -7.5e+146) || !((y <= -9.2e+78) || (!(y <= -8.8e+46) && (y <= 1.1e+112)))) {
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 <= (-7.5d+146)) .or. (.not. (y <= (-9.2d+78)) .or. (.not. (y <= (-8.8d+46))) .and. (y <= 1.1d+112))) 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 <= -7.5e+146) || !((y <= -9.2e+78) || (!(y <= -8.8e+46) && (y <= 1.1e+112)))) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -7.5e+146) or not ((y <= -9.2e+78) or (not (y <= -8.8e+46) and (y <= 1.1e+112))): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -7.5e+146) || !((y <= -9.2e+78) || (!(y <= -8.8e+46) && (y <= 1.1e+112)))) 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 <= -7.5e+146) || ~(((y <= -9.2e+78) || (~((y <= -8.8e+46)) && (y <= 1.1e+112))))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -7.5e+146], N[Not[Or[LessEqual[y, -9.2e+78], And[N[Not[LessEqual[y, -8.8e+46]], $MachinePrecision], LessEqual[y, 1.1e+112]]]], $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 -7.5 \cdot 10^{+146} \lor \neg \left(y \leq -9.2 \cdot 10^{+78} \lor \neg \left(y \leq -8.8 \cdot 10^{+46}\right) \land y \leq 1.1 \cdot 10^{+112}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -7.49999999999999983e146 or -9.2000000000000008e78 < y < -8.8000000000000001e46 or 1.1e112 < y Initial program 100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in t around 0 97.9%
Taylor expanded in z around 0 77.4%
*-commutative77.4%
Simplified77.4%
if -7.49999999999999983e146 < y < -9.2000000000000008e78 or -8.8000000000000001e46 < y < 1.1e112Initial program 99.9%
Taylor expanded in x around 0 81.8%
Final simplification80.2%
(FPCore (x y z t)
:precision binary64
(if (<= z -1.02e+47)
(* y z)
(if (<= z 7.5e+72)
t
(if (<= z 1.6e+126) (* y z) (if (<= z 4.5e+207) t (* y z))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.02e+47) {
tmp = y * z;
} else if (z <= 7.5e+72) {
tmp = t;
} else if (z <= 1.6e+126) {
tmp = y * z;
} else if (z <= 4.5e+207) {
tmp = t;
} else {
tmp = 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 (z <= (-1.02d+47)) then
tmp = y * z
else if (z <= 7.5d+72) then
tmp = t
else if (z <= 1.6d+126) then
tmp = y * z
else if (z <= 4.5d+207) then
tmp = t
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.02e+47) {
tmp = y * z;
} else if (z <= 7.5e+72) {
tmp = t;
} else if (z <= 1.6e+126) {
tmp = y * z;
} else if (z <= 4.5e+207) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.02e+47: tmp = y * z elif z <= 7.5e+72: tmp = t elif z <= 1.6e+126: tmp = y * z elif z <= 4.5e+207: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -1.02e+47) tmp = Float64(y * z); elseif (z <= 7.5e+72) tmp = t; elseif (z <= 1.6e+126) tmp = Float64(y * z); elseif (z <= 4.5e+207) tmp = t; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -1.02e+47) tmp = y * z; elseif (z <= 7.5e+72) tmp = t; elseif (z <= 1.6e+126) tmp = y * z; elseif (z <= 4.5e+207) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.02e+47], N[(y * z), $MachinePrecision], If[LessEqual[z, 7.5e+72], t, If[LessEqual[z, 1.6e+126], N[(y * z), $MachinePrecision], If[LessEqual[z, 4.5e+207], t, N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.02 \cdot 10^{+47}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 7.5 \cdot 10^{+72}:\\
\;\;\;\;t\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{+126}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 4.5 \cdot 10^{+207}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.0199999999999999e47 or 7.50000000000000027e72 < z < 1.5999999999999999e126 or 4.50000000000000003e207 < z Initial program 100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in t around 0 75.4%
Taylor expanded in z around inf 63.5%
if -1.0199999999999999e47 < z < 7.50000000000000027e72 or 1.5999999999999999e126 < z < 4.50000000000000003e207Initial program 99.9%
fma-def99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in y around 0 48.6%
Final simplification54.1%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.9e-14) (not (<= y 4.5e+59))) (* y (+ (* x y) z)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.9e-14) || !(y <= 4.5e+59)) {
tmp = y * ((x * y) + z);
} 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 <= (-2.9d-14)) .or. (.not. (y <= 4.5d+59))) then
tmp = y * ((x * y) + z)
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 <= -2.9e-14) || !(y <= 4.5e+59)) {
tmp = y * ((x * y) + z);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -2.9e-14) or not (y <= 4.5e+59): tmp = y * ((x * y) + z) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.9e-14) || !(y <= 4.5e+59)) tmp = Float64(y * Float64(Float64(x * y) + z)); else tmp = Float64(t + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -2.9e-14) || ~((y <= 4.5e+59))) tmp = y * ((x * y) + z); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.9e-14], N[Not[LessEqual[y, 4.5e+59]], $MachinePrecision]], N[(y * N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{-14} \lor \neg \left(y \leq 4.5 \cdot 10^{+59}\right):\\
\;\;\;\;y \cdot \left(x \cdot y + z\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -2.9000000000000003e-14 or 4.49999999999999959e59 < y Initial program 100.0%
fma-def99.9%
fma-def100.0%
Simplified100.0%
Taylor expanded in t around 0 88.5%
if -2.9000000000000003e-14 < y < 4.49999999999999959e59Initial program 99.9%
Taylor expanded in x around 0 88.5%
Final simplification88.5%
(FPCore (x y z t) :precision binary64 (if (or (<= z -3.1e+70) (not (<= z 3.9e+79))) (+ t (* y z)) (+ t (* x (* y y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.1e+70) || !(z <= 3.9e+79)) {
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.1d+70)) .or. (.not. (z <= 3.9d+79))) 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.1e+70) || !(z <= 3.9e+79)) {
tmp = t + (y * z);
} else {
tmp = t + (x * (y * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3.1e+70) or not (z <= 3.9e+79): tmp = t + (y * z) else: tmp = t + (x * (y * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.1e+70) || !(z <= 3.9e+79)) 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.1e+70) || ~((z <= 3.9e+79))) 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.1e+70], N[Not[LessEqual[z, 3.9e+79]], $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.1 \cdot 10^{+70} \lor \neg \left(z \leq 3.9 \cdot 10^{+79}\right):\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t + x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if z < -3.1000000000000003e70 or 3.8999999999999997e79 < z Initial program 100.0%
Taylor expanded in x around 0 88.6%
if -3.1000000000000003e70 < z < 3.8999999999999997e79Initial program 99.9%
*-commutative99.9%
distribute-rgt-in98.6%
Applied egg-rr98.6%
Taylor expanded in x around inf 92.0%
unpow292.0%
Simplified92.0%
Final simplification90.6%
(FPCore (x y z t) :precision binary64 (if (or (<= z -4.1e+72) (not (<= z 2.95e+79))) (+ t (* y z)) (+ t (* y (* x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4.1e+72) || !(z <= 2.95e+79)) {
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 <= (-4.1d+72)) .or. (.not. (z <= 2.95d+79))) 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 <= -4.1e+72) || !(z <= 2.95e+79)) {
tmp = t + (y * z);
} else {
tmp = t + (y * (x * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -4.1e+72) or not (z <= 2.95e+79): tmp = t + (y * z) else: tmp = t + (y * (x * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -4.1e+72) || !(z <= 2.95e+79)) 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 <= -4.1e+72) || ~((z <= 2.95e+79))) tmp = t + (y * z); else tmp = t + (y * (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -4.1e+72], N[Not[LessEqual[z, 2.95e+79]], $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 -4.1 \cdot 10^{+72} \lor \neg \left(z \leq 2.95 \cdot 10^{+79}\right):\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -4.09999999999999963e72 or 2.95e79 < z Initial program 100.0%
Taylor expanded in x around 0 88.6%
if -4.09999999999999963e72 < z < 2.95e79Initial program 99.9%
Taylor expanded in x around inf 96.8%
*-commutative96.8%
Simplified96.8%
Final simplification93.6%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.15e-20) (not (<= y 1.3e+71))) (* y (* x y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.15e-20) || !(y <= 1.3e+71)) {
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 <= (-2.15d-20)) .or. (.not. (y <= 1.3d+71))) 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 <= -2.15e-20) || !(y <= 1.3e+71)) {
tmp = y * (x * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -2.15e-20) or not (y <= 1.3e+71): tmp = y * (x * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.15e-20) || !(y <= 1.3e+71)) 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 <= -2.15e-20) || ~((y <= 1.3e+71))) tmp = y * (x * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.15e-20], N[Not[LessEqual[y, 1.3e+71]], $MachinePrecision]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.15 \cdot 10^{-20} \lor \neg \left(y \leq 1.3 \cdot 10^{+71}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -2.15000000000000006e-20 or 1.29999999999999996e71 < y Initial program 100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in t around 0 89.7%
Taylor expanded in z around 0 67.7%
*-commutative67.7%
Simplified67.7%
if -2.15000000000000006e-20 < y < 1.29999999999999996e71Initial program 99.9%
fma-def99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in y around 0 67.3%
Final simplification67.5%
(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%
fma-def99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in y around 0 40.2%
Final simplification40.2%
herbie shell --seed 2023290
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))