
(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 (+ (* x y) z) y t))
double code(double x, double y, double z, double t) {
return fma(((x * y) + z), y, t);
}
function code(x, y, z, t) return fma(Float64(Float64(x * y) + z), y, t) end
code[x_, y_, z_, t_] := N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot y + z, y, t\right)
\end{array}
Initial program 99.9%
fma-define99.9%
fma-define99.9%
Simplified99.9%
fma-define99.9%
Applied egg-rr99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* x y))))
(if (<= y -7.8e+58)
t_1
(if (<= y -0.48)
(* y z)
(if (<= y 6.2e-51) t (if (<= y 1.1e+142) (* y z) t_1))))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -7.8e+58) {
tmp = t_1;
} else if (y <= -0.48) {
tmp = y * z;
} else if (y <= 6.2e-51) {
tmp = t;
} else if (y <= 1.1e+142) {
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 <= (-7.8d+58)) then
tmp = t_1
else if (y <= (-0.48d0)) then
tmp = y * z
else if (y <= 6.2d-51) then
tmp = t
else if (y <= 1.1d+142) 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 <= -7.8e+58) {
tmp = t_1;
} else if (y <= -0.48) {
tmp = y * z;
} else if (y <= 6.2e-51) {
tmp = t;
} else if (y <= 1.1e+142) {
tmp = y * z;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -7.8e+58: tmp = t_1 elif y <= -0.48: tmp = y * z elif y <= 6.2e-51: tmp = t elif y <= 1.1e+142: 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 <= -7.8e+58) tmp = t_1; elseif (y <= -0.48) tmp = Float64(y * z); elseif (y <= 6.2e-51) tmp = t; elseif (y <= 1.1e+142) 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 <= -7.8e+58) tmp = t_1; elseif (y <= -0.48) tmp = y * z; elseif (y <= 6.2e-51) tmp = t; elseif (y <= 1.1e+142) 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, -7.8e+58], t$95$1, If[LessEqual[y, -0.48], N[(y * z), $MachinePrecision], If[LessEqual[y, 6.2e-51], t, If[LessEqual[y, 1.1e+142], 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 -7.8 \cdot 10^{+58}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -0.48:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{-51}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{+142}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -7.8000000000000002e58 or 1.09999999999999993e142 < y Initial program 99.9%
fma-define99.9%
fma-define99.9%
Simplified99.9%
fma-define99.9%
Applied egg-rr99.9%
Taylor expanded in t around 0 97.8%
Taylor expanded in z around 0 81.4%
*-commutative81.4%
Simplified81.4%
if -7.8000000000000002e58 < y < -0.47999999999999998 or 6.1999999999999995e-51 < y < 1.09999999999999993e142Initial program 99.9%
fma-define99.9%
fma-define99.9%
Simplified99.9%
fma-define99.9%
Applied egg-rr99.9%
Taylor expanded in z around inf 53.1%
if -0.47999999999999998 < y < 6.1999999999999995e-51Initial program 99.9%
Taylor expanded in y around 0 64.0%
Final simplification68.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* x (* y y))))
(if (<= y -3.5e+58)
t_1
(if (<= y -23000000.0)
(* y z)
(if (<= y 2.7e-51) t (if (<= y 1.1e+142) (* y z) t_1))))))
double code(double x, double y, double z, double t) {
double t_1 = x * (y * y);
double tmp;
if (y <= -3.5e+58) {
tmp = t_1;
} else if (y <= -23000000.0) {
tmp = y * z;
} else if (y <= 2.7e-51) {
tmp = t;
} else if (y <= 1.1e+142) {
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 = x * (y * y)
if (y <= (-3.5d+58)) then
tmp = t_1
else if (y <= (-23000000.0d0)) then
tmp = y * z
else if (y <= 2.7d-51) then
tmp = t
else if (y <= 1.1d+142) 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 = x * (y * y);
double tmp;
if (y <= -3.5e+58) {
tmp = t_1;
} else if (y <= -23000000.0) {
tmp = y * z;
} else if (y <= 2.7e-51) {
tmp = t;
} else if (y <= 1.1e+142) {
tmp = y * z;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x * (y * y) tmp = 0 if y <= -3.5e+58: tmp = t_1 elif y <= -23000000.0: tmp = y * z elif y <= 2.7e-51: tmp = t elif y <= 1.1e+142: tmp = y * z else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(x * Float64(y * y)) tmp = 0.0 if (y <= -3.5e+58) tmp = t_1; elseif (y <= -23000000.0) tmp = Float64(y * z); elseif (y <= 2.7e-51) tmp = t; elseif (y <= 1.1e+142) tmp = Float64(y * z); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x * (y * y); tmp = 0.0; if (y <= -3.5e+58) tmp = t_1; elseif (y <= -23000000.0) tmp = y * z; elseif (y <= 2.7e-51) tmp = t; elseif (y <= 1.1e+142) tmp = y * z; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.5e+58], t$95$1, If[LessEqual[y, -23000000.0], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.7e-51], t, If[LessEqual[y, 1.1e+142], N[(y * z), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \left(y \cdot y\right)\\
\mathbf{if}\;y \leq -3.5 \cdot 10^{+58}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -23000000:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{-51}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{+142}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -3.4999999999999997e58 or 1.09999999999999993e142 < y Initial program 99.9%
Taylor expanded in x around inf 63.8%
+-commutative63.8%
unpow263.8%
associate-/l*72.7%
distribute-lft-out90.6%
Simplified90.6%
Taylor expanded in t around 0 88.5%
Taylor expanded in y around inf 77.3%
if -3.4999999999999997e58 < y < -2.3e7 or 2.6999999999999997e-51 < y < 1.09999999999999993e142Initial program 99.9%
fma-define99.9%
fma-define99.9%
Simplified99.9%
fma-define99.9%
Applied egg-rr99.9%
Taylor expanded in z around inf 53.1%
if -2.3e7 < y < 2.6999999999999997e-51Initial program 99.9%
Taylor expanded in y around 0 64.0%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3.8e+23) (not (<= y 3.2e-41))) (* y (+ (* x y) z)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.8e+23) || !(y <= 3.2e-41)) {
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 <= (-3.8d+23)) .or. (.not. (y <= 3.2d-41))) 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 <= -3.8e+23) || !(y <= 3.2e-41)) {
tmp = y * ((x * y) + z);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -3.8e+23) or not (y <= 3.2e-41): tmp = y * ((x * y) + z) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -3.8e+23) || !(y <= 3.2e-41)) 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 <= -3.8e+23) || ~((y <= 3.2e-41))) tmp = y * ((x * y) + z); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3.8e+23], N[Not[LessEqual[y, 3.2e-41]], $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 -3.8 \cdot 10^{+23} \lor \neg \left(y \leq 3.2 \cdot 10^{-41}\right):\\
\;\;\;\;y \cdot \left(x \cdot y + z\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -3.79999999999999975e23 or 3.20000000000000012e-41 < y Initial program 99.9%
fma-define99.9%
fma-define99.9%
Simplified99.9%
fma-define99.9%
Applied egg-rr99.9%
Taylor expanded in t around 0 92.9%
if -3.79999999999999975e23 < y < 3.20000000000000012e-41Initial program 99.9%
Taylor expanded in x around 0 90.0%
Final simplification91.5%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3.5e+105) (not (<= y 4.5e+149))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.5e+105) || !(y <= 4.5e+149)) {
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.5d+105)) .or. (.not. (y <= 4.5d+149))) 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.5e+105) || !(y <= 4.5e+149)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -3.5e+105) or not (y <= 4.5e+149): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -3.5e+105) || !(y <= 4.5e+149)) 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.5e+105) || ~((y <= 4.5e+149))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3.5e+105], N[Not[LessEqual[y, 4.5e+149]], $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.5 \cdot 10^{+105} \lor \neg \left(y \leq 4.5 \cdot 10^{+149}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -3.49999999999999991e105 or 4.49999999999999982e149 < y Initial program 100.0%
fma-define100.0%
fma-define100.0%
Simplified100.0%
fma-define100.0%
Applied egg-rr100.0%
Taylor expanded in t around 0 100.0%
Taylor expanded in z around 0 87.3%
*-commutative87.3%
Simplified87.3%
if -3.49999999999999991e105 < y < 4.49999999999999982e149Initial program 99.9%
Taylor expanded in x around 0 82.5%
Final simplification84.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.35e+29) (not (<= z 1.1e-20))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.35e+29) || !(z <= 1.1e-20)) {
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 <= (-1.35d+29)) .or. (.not. (z <= 1.1d-20))) 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 <= -1.35e+29) || !(z <= 1.1e-20)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.35e+29) or not (z <= 1.1e-20): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.35e+29) || !(z <= 1.1e-20)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -1.35e+29) || ~((z <= 1.1e-20))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.35e+29], N[Not[LessEqual[z, 1.1e-20]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.35 \cdot 10^{+29} \lor \neg \left(z \leq 1.1 \cdot 10^{-20}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -1.35e29 or 1.09999999999999995e-20 < z Initial program 99.9%
fma-define100.0%
fma-define100.0%
Simplified100.0%
fma-define100.0%
Applied egg-rr100.0%
Taylor expanded in z around inf 53.2%
if -1.35e29 < z < 1.09999999999999995e-20Initial program 99.9%
Taylor expanded in y around 0 47.9%
Final simplification50.6%
(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 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.8%
herbie shell --seed 2024170
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))