
(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 100.0%
Final simplification100.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z -6.5e+20) (not (<= z 2e+64))) (+ t (* y z)) (+ t (* y (* x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -6.5e+20) || !(z <= 2e+64)) {
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 <= (-6.5d+20)) .or. (.not. (z <= 2d+64))) 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 <= -6.5e+20) || !(z <= 2e+64)) {
tmp = t + (y * z);
} else {
tmp = t + (y * (x * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -6.5e+20) or not (z <= 2e+64): tmp = t + (y * z) else: tmp = t + (y * (x * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -6.5e+20) || !(z <= 2e+64)) 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 <= -6.5e+20) || ~((z <= 2e+64))) tmp = t + (y * z); else tmp = t + (y * (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -6.5e+20], N[Not[LessEqual[z, 2e+64]], $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 -6.5 \cdot 10^{+20} \lor \neg \left(z \leq 2 \cdot 10^{+64}\right):\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -6.5e20 or 2.00000000000000004e64 < z Initial program 100.0%
Taylor expanded in x around 0 86.5%
if -6.5e20 < z < 2.00000000000000004e64Initial program 99.9%
Taylor expanded in x around inf 98.6%
*-commutative98.6%
Simplified98.6%
Final simplification93.2%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.2e+21) (not (<= z 1.95e+64))) (+ t (* y z)) (+ t (* x (* y y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.2e+21) || !(z <= 1.95e+64)) {
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 <= (-2.2d+21)) .or. (.not. (z <= 1.95d+64))) 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 <= -2.2e+21) || !(z <= 1.95e+64)) {
tmp = t + (y * z);
} else {
tmp = t + (x * (y * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.2e+21) or not (z <= 1.95e+64): tmp = t + (y * z) else: tmp = t + (x * (y * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.2e+21) || !(z <= 1.95e+64)) 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 <= -2.2e+21) || ~((z <= 1.95e+64))) tmp = t + (y * z); else tmp = t + (x * (y * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.2e+21], N[Not[LessEqual[z, 1.95e+64]], $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 -2.2 \cdot 10^{+21} \lor \neg \left(z \leq 1.95 \cdot 10^{+64}\right):\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t + x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if z < -2.2e21 or 1.9499999999999999e64 < z Initial program 100.0%
Taylor expanded in x around 0 86.5%
if -2.2e21 < z < 1.9499999999999999e64Initial program 99.9%
Taylor expanded in x around inf 92.8%
+-commutative92.8%
unpow292.8%
associate-/l*93.5%
distribute-lft-out95.6%
Simplified95.6%
Taylor expanded in y around inf 94.9%
Final simplification91.2%
(FPCore (x y z t) :precision binary64 (if (or (<= y -7.4e+31) (not (<= y 1.25e+78))) (* y (+ (* x y) z)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -7.4e+31) || !(y <= 1.25e+78)) {
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 <= (-7.4d+31)) .or. (.not. (y <= 1.25d+78))) 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 <= -7.4e+31) || !(y <= 1.25e+78)) {
tmp = y * ((x * y) + z);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -7.4e+31) or not (y <= 1.25e+78): tmp = y * ((x * y) + z) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -7.4e+31) || !(y <= 1.25e+78)) 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 <= -7.4e+31) || ~((y <= 1.25e+78))) tmp = y * ((x * y) + z); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -7.4e+31], N[Not[LessEqual[y, 1.25e+78]], $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 -7.4 \cdot 10^{+31} \lor \neg \left(y \leq 1.25 \cdot 10^{+78}\right):\\
\;\;\;\;y \cdot \left(x \cdot y + z\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -7.3999999999999996e31 or 1.24999999999999996e78 < y Initial program 99.9%
Taylor expanded in t around inf 93.1%
associate-/l*93.1%
+-commutative93.1%
*-commutative93.1%
fma-undefine93.1%
Simplified93.1%
Taylor expanded in t around 0 93.8%
if -7.3999999999999996e31 < y < 1.24999999999999996e78Initial program 100.0%
Taylor expanded in x around 0 88.0%
Final simplification90.5%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.48e+110) (not (<= y 4.8e+79))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.48e+110) || !(y <= 4.8e+79)) {
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.48d+110)) .or. (.not. (y <= 4.8d+79))) 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.48e+110) || !(y <= 4.8e+79)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.48e+110) or not (y <= 4.8e+79): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.48e+110) || !(y <= 4.8e+79)) 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.48e+110) || ~((y <= 4.8e+79))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.48e+110], N[Not[LessEqual[y, 4.8e+79]], $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.48 \cdot 10^{+110} \lor \neg \left(y \leq 4.8 \cdot 10^{+79}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.48000000000000008e110 or 4.79999999999999971e79 < y Initial program 100.0%
Taylor expanded in t around inf 96.0%
associate-/l*96.0%
+-commutative96.0%
*-commutative96.0%
fma-undefine96.0%
Simplified96.0%
Taylor expanded in t around 0 96.9%
Taylor expanded in z around 0 79.9%
if -1.48000000000000008e110 < y < 4.79999999999999971e79Initial program 99.9%
Taylor expanded in x around 0 85.0%
Final simplification83.1%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3.9e+32) (not (<= y 1.2e+40))) (* y (* x y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.9e+32) || !(y <= 1.2e+40)) {
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 <= (-3.9d+32)) .or. (.not. (y <= 1.2d+40))) 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 <= -3.9e+32) || !(y <= 1.2e+40)) {
tmp = y * (x * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -3.9e+32) or not (y <= 1.2e+40): tmp = y * (x * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -3.9e+32) || !(y <= 1.2e+40)) 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 <= -3.9e+32) || ~((y <= 1.2e+40))) tmp = y * (x * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3.9e+32], N[Not[LessEqual[y, 1.2e+40]], $MachinePrecision]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.9 \cdot 10^{+32} \lor \neg \left(y \leq 1.2 \cdot 10^{+40}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -3.8999999999999999e32 or 1.2e40 < y Initial program 99.9%
Taylor expanded in t around inf 93.5%
associate-/l*93.5%
+-commutative93.5%
*-commutative93.5%
fma-undefine93.5%
Simplified93.5%
Taylor expanded in t around 0 92.4%
Taylor expanded in z around 0 72.7%
if -3.8999999999999999e32 < y < 1.2e40Initial program 100.0%
Taylor expanded in y around 0 64.5%
Final simplification68.2%
(FPCore (x y z t) :precision binary64 (if (or (<= z -5e+44) (not (<= z 1.02e+63))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -5e+44) || !(z <= 1.02e+63)) {
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 <= (-5d+44)) .or. (.not. (z <= 1.02d+63))) 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 <= -5e+44) || !(z <= 1.02e+63)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -5e+44) or not (z <= 1.02e+63): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -5e+44) || !(z <= 1.02e+63)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -5e+44) || ~((z <= 1.02e+63))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -5e+44], N[Not[LessEqual[z, 1.02e+63]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{+44} \lor \neg \left(z \leq 1.02 \cdot 10^{+63}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -4.9999999999999996e44 or 1.02e63 < z Initial program 100.0%
Taylor expanded in t around inf 88.2%
associate-/l*81.2%
+-commutative81.2%
*-commutative81.2%
fma-undefine81.2%
Simplified81.2%
Taylor expanded in z around inf 61.1%
if -4.9999999999999996e44 < z < 1.02e63Initial program 99.9%
Taylor expanded in y around 0 50.4%
Final simplification55.0%
(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 100.0%
Taylor expanded in y around 0 39.8%
herbie shell --seed 2024135
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))