
(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 (+ 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 -1.4e-28)
(not (or (<= y 1.1e-63) (and (not (<= y 4.5)) (<= y 2.9e+81)))))
(* y (+ (* x y) z))
(+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.4e-28) || !((y <= 1.1e-63) || (!(y <= 4.5) && (y <= 2.9e+81)))) {
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 <= (-1.4d-28)) .or. (.not. (y <= 1.1d-63) .or. (.not. (y <= 4.5d0)) .and. (y <= 2.9d+81))) 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 <= -1.4e-28) || !((y <= 1.1e-63) || (!(y <= 4.5) && (y <= 2.9e+81)))) {
tmp = y * ((x * y) + z);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.4e-28) or not ((y <= 1.1e-63) or (not (y <= 4.5) and (y <= 2.9e+81))): tmp = y * ((x * y) + z) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.4e-28) || !((y <= 1.1e-63) || (!(y <= 4.5) && (y <= 2.9e+81)))) 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 <= -1.4e-28) || ~(((y <= 1.1e-63) || (~((y <= 4.5)) && (y <= 2.9e+81))))) tmp = y * ((x * y) + z); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.4e-28], N[Not[Or[LessEqual[y, 1.1e-63], And[N[Not[LessEqual[y, 4.5]], $MachinePrecision], LessEqual[y, 2.9e+81]]]], $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 -1.4 \cdot 10^{-28} \lor \neg \left(y \leq 1.1 \cdot 10^{-63} \lor \neg \left(y \leq 4.5\right) \land y \leq 2.9 \cdot 10^{+81}\right):\\
\;\;\;\;y \cdot \left(x \cdot y + z\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.3999999999999999e-28 or 1.1e-63 < y < 4.5 or 2.9e81 < y Initial program 99.9%
Taylor expanded in t around 0 93.5%
if -1.3999999999999999e-28 < y < 1.1e-63 or 4.5 < y < 2.9e81Initial program 100.0%
Taylor expanded in x around 0 90.8%
Final simplification92.2%
(FPCore (x y z t)
:precision binary64
(if (or (<= y -1.7e-28)
(and (not (<= y 9.6e-63)) (or (<= y 1.12) (not (<= y 6.1e+65)))))
(* y (* x y))
t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.7e-28) || (!(y <= 9.6e-63) && ((y <= 1.12) || !(y <= 6.1e+65)))) {
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 <= (-1.7d-28)) .or. (.not. (y <= 9.6d-63)) .and. (y <= 1.12d0) .or. (.not. (y <= 6.1d+65))) 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 <= -1.7e-28) || (!(y <= 9.6e-63) && ((y <= 1.12) || !(y <= 6.1e+65)))) {
tmp = y * (x * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.7e-28) or (not (y <= 9.6e-63) and ((y <= 1.12) or not (y <= 6.1e+65))): tmp = y * (x * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.7e-28) || (!(y <= 9.6e-63) && ((y <= 1.12) || !(y <= 6.1e+65)))) 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 <= -1.7e-28) || (~((y <= 9.6e-63)) && ((y <= 1.12) || ~((y <= 6.1e+65))))) tmp = y * (x * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.7e-28], And[N[Not[LessEqual[y, 9.6e-63]], $MachinePrecision], Or[LessEqual[y, 1.12], N[Not[LessEqual[y, 6.1e+65]], $MachinePrecision]]]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{-28} \lor \neg \left(y \leq 9.6 \cdot 10^{-63}\right) \land \left(y \leq 1.12 \lor \neg \left(y \leq 6.1 \cdot 10^{+65}\right)\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -1.7e-28 or 9.6000000000000002e-63 < y < 1.1200000000000001 or 6.09999999999999965e65 < y Initial program 99.9%
Taylor expanded in t around 0 92.9%
Taylor expanded in z around 0 74.4%
if -1.7e-28 < y < 9.6000000000000002e-63 or 1.1200000000000001 < y < 6.09999999999999965e65Initial program 100.0%
Taylor expanded in y around 0 67.6%
Final simplification71.2%
(FPCore (x y z t) :precision binary64 (if (<= z -2.7e+63) (* y (+ (* x y) z)) (if (<= z 1.5e+108) (+ t (* y (* x y))) (+ t (* y z)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -2.7e+63) {
tmp = y * ((x * y) + z);
} else if (z <= 1.5e+108) {
tmp = t + (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 (z <= (-2.7d+63)) then
tmp = y * ((x * y) + z)
else if (z <= 1.5d+108) then
tmp = t + (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 (z <= -2.7e+63) {
tmp = y * ((x * y) + z);
} else if (z <= 1.5e+108) {
tmp = t + (y * (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -2.7e+63: tmp = y * ((x * y) + z) elif z <= 1.5e+108: tmp = t + (y * (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -2.7e+63) tmp = Float64(y * Float64(Float64(x * y) + z)); elseif (z <= 1.5e+108) tmp = Float64(t + 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 (z <= -2.7e+63) tmp = y * ((x * y) + z); elseif (z <= 1.5e+108) tmp = t + (y * (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -2.7e+63], N[(y * N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.5e+108], N[(t + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.7 \cdot 10^{+63}:\\
\;\;\;\;y \cdot \left(x \cdot y + z\right)\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{+108}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if z < -2.70000000000000017e63Initial program 100.0%
Taylor expanded in t around 0 86.2%
if -2.70000000000000017e63 < z < 1.49999999999999992e108Initial program 99.9%
Taylor expanded in x around inf 93.6%
*-commutative93.6%
Simplified93.6%
if 1.49999999999999992e108 < z Initial program 100.0%
Taylor expanded in x around 0 88.1%
Final simplification91.5%
(FPCore (x y z t) :precision binary64 (if (or (<= y -7.5e+49) (not (<= y 5.5e+88))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -7.5e+49) || !(y <= 5.5e+88)) {
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+49)) .or. (.not. (y <= 5.5d+88))) 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+49) || !(y <= 5.5e+88)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -7.5e+49) or not (y <= 5.5e+88): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -7.5e+49) || !(y <= 5.5e+88)) 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+49) || ~((y <= 5.5e+88))) 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+49], N[Not[LessEqual[y, 5.5e+88]], $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^{+49} \lor \neg \left(y \leq 5.5 \cdot 10^{+88}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -7.4999999999999995e49 or 5.5e88 < y Initial program 100.0%
Taylor expanded in t around 0 94.7%
Taylor expanded in z around 0 80.2%
if -7.4999999999999995e49 < y < 5.5e88Initial program 99.9%
Taylor expanded in x around 0 86.1%
Final simplification83.5%
(FPCore (x y z t) :precision binary64 (if (<= z -2.2e+58) (* y z) (if (<= z 4e+101) t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -2.2e+58) {
tmp = y * z;
} else if (z <= 4e+101) {
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 <= (-2.2d+58)) then
tmp = y * z
else if (z <= 4d+101) 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 <= -2.2e+58) {
tmp = y * z;
} else if (z <= 4e+101) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -2.2e+58: tmp = y * z elif z <= 4e+101: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -2.2e+58) tmp = Float64(y * z); elseif (z <= 4e+101) tmp = t; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -2.2e+58) tmp = y * z; elseif (z <= 4e+101) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -2.2e+58], N[(y * z), $MachinePrecision], If[LessEqual[z, 4e+101], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{+58}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 4 \cdot 10^{+101}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -2.2000000000000001e58 or 3.9999999999999999e101 < z Initial program 100.0%
Taylor expanded in t around 0 84.3%
Taylor expanded in z around inf 64.9%
if -2.2000000000000001e58 < z < 3.9999999999999999e101Initial program 99.9%
Taylor expanded in y around 0 46.5%
Final simplification52.7%
(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 36.5%
Final simplification36.5%
herbie shell --seed 2023271
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))