
(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 100.0%
Applied egg-rr0
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (+ z (* y x))))) (if (<= y -1.26e+17) t_1 (if (<= y 2.5e+47) (+ (* z y) t) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * (z + (y * x));
double tmp;
if (y <= -1.26e+17) {
tmp = t_1;
} else if (y <= 2.5e+47) {
tmp = (z * y) + t;
} 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 * (z + (y * x))
if (y <= (-1.26d+17)) then
tmp = t_1
else if (y <= 2.5d+47) then
tmp = (z * y) + t
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 * (z + (y * x));
double tmp;
if (y <= -1.26e+17) {
tmp = t_1;
} else if (y <= 2.5e+47) {
tmp = (z * y) + t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (z + (y * x)) tmp = 0 if y <= -1.26e+17: tmp = t_1 elif y <= 2.5e+47: tmp = (z * y) + t else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(z + Float64(y * x))) tmp = 0.0 if (y <= -1.26e+17) tmp = t_1; elseif (y <= 2.5e+47) tmp = Float64(Float64(z * y) + t); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (z + (y * x)); tmp = 0.0; if (y <= -1.26e+17) tmp = t_1; elseif (y <= 2.5e+47) tmp = (z * y) + t; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.26e+17], t$95$1, If[LessEqual[y, 2.5e+47], N[(N[(z * y), $MachinePrecision] + t), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(z + y \cdot x\right)\\
\mathbf{if}\;y \leq -1.26 \cdot 10^{+17}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 2.5 \cdot 10^{+47}:\\
\;\;\;\;z \cdot y + t\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.26e17 or 2.50000000000000011e47 < y Initial program 100.0%
Taylor expanded in y around inf 0
Simplified0
if -1.26e17 < y < 2.50000000000000011e47Initial program 100.0%
Taylor expanded in x around 0 0
Simplified0
(FPCore (x y z t) :precision binary64 (if (<= y -8.2e+19) (* (* y y) x) (if (<= y 2.3e+85) (+ (* z y) t) (* y (* y x)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -8.2e+19) {
tmp = (y * y) * x;
} else if (y <= 2.3e+85) {
tmp = (z * y) + t;
} else {
tmp = y * (y * x);
}
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 <= (-8.2d+19)) then
tmp = (y * y) * x
else if (y <= 2.3d+85) then
tmp = (z * y) + t
else
tmp = y * (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -8.2e+19) {
tmp = (y * y) * x;
} else if (y <= 2.3e+85) {
tmp = (z * y) + t;
} else {
tmp = y * (y * x);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -8.2e+19: tmp = (y * y) * x elif y <= 2.3e+85: tmp = (z * y) + t else: tmp = y * (y * x) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -8.2e+19) tmp = Float64(Float64(y * y) * x); elseif (y <= 2.3e+85) tmp = Float64(Float64(z * y) + t); else tmp = Float64(y * Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -8.2e+19) tmp = (y * y) * x; elseif (y <= 2.3e+85) tmp = (z * y) + t; else tmp = y * (y * x); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -8.2e+19], N[(N[(y * y), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[y, 2.3e+85], N[(N[(z * y), $MachinePrecision] + t), $MachinePrecision], N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.2 \cdot 10^{+19}:\\
\;\;\;\;\left(y \cdot y\right) \cdot x\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{+85}:\\
\;\;\;\;z \cdot y + t\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if y < -8.2e19Initial program 100.0%
Taylor expanded in x around inf 0
Simplified0
Applied egg-rr0
if -8.2e19 < y < 2.2999999999999999e85Initial program 100.0%
Taylor expanded in x around 0 0
Simplified0
if 2.2999999999999999e85 < y Initial program 99.9%
Taylor expanded in x around inf 0
Simplified0
(FPCore (x y z t) :precision binary64 (if (<= y -1.9e+18) (* (* y y) x) (if (<= y 6.8e+47) t (* y (* y x)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.9e+18) {
tmp = (y * y) * x;
} else if (y <= 6.8e+47) {
tmp = t;
} else {
tmp = y * (y * x);
}
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.9d+18)) then
tmp = (y * y) * x
else if (y <= 6.8d+47) then
tmp = t
else
tmp = y * (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.9e+18) {
tmp = (y * y) * x;
} else if (y <= 6.8e+47) {
tmp = t;
} else {
tmp = y * (y * x);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -1.9e+18: tmp = (y * y) * x elif y <= 6.8e+47: tmp = t else: tmp = y * (y * x) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -1.9e+18) tmp = Float64(Float64(y * y) * x); elseif (y <= 6.8e+47) tmp = t; else tmp = Float64(y * Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -1.9e+18) tmp = (y * y) * x; elseif (y <= 6.8e+47) tmp = t; else tmp = y * (y * x); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -1.9e+18], N[(N[(y * y), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[y, 6.8e+47], t, N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{+18}:\\
\;\;\;\;\left(y \cdot y\right) \cdot x\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{+47}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if y < -1.9e18Initial program 100.0%
Taylor expanded in x around inf 0
Simplified0
Applied egg-rr0
if -1.9e18 < y < 6.7999999999999996e47Initial program 100.0%
Taylor expanded in y around 0 0
Simplified0
if 6.7999999999999996e47 < y Initial program 100.0%
Taylor expanded in x around inf 0
Simplified0
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (* y x)))) (if (<= y -3.5e-45) t_1 (if (<= y 6.8e+47) t t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * (y * x);
double tmp;
if (y <= -3.5e-45) {
tmp = t_1;
} else if (y <= 6.8e+47) {
tmp = t;
} 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 * (y * x)
if (y <= (-3.5d-45)) then
tmp = t_1
else if (y <= 6.8d+47) then
tmp = t
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 * (y * x);
double tmp;
if (y <= -3.5e-45) {
tmp = t_1;
} else if (y <= 6.8e+47) {
tmp = t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (y * x) tmp = 0 if y <= -3.5e-45: tmp = t_1 elif y <= 6.8e+47: tmp = t else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(y * x)) tmp = 0.0 if (y <= -3.5e-45) tmp = t_1; elseif (y <= 6.8e+47) tmp = t; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (y * x); tmp = 0.0; if (y <= -3.5e-45) tmp = t_1; elseif (y <= 6.8e+47) tmp = t; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.5e-45], t$95$1, If[LessEqual[y, 6.8e+47], t, t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(y \cdot x\right)\\
\mathbf{if}\;y \leq -3.5 \cdot 10^{-45}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{+47}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -3.5e-45 or 6.7999999999999996e47 < y Initial program 100.0%
Taylor expanded in x around inf 0
Simplified0
if -3.5e-45 < y < 6.7999999999999996e47Initial program 100.0%
Taylor expanded in y around 0 0
Simplified0
(FPCore (x y z t) :precision binary64 (if (<= y -5.6e-48) (* y z) (if (<= y 2.2e+65) t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -5.6e-48) {
tmp = y * z;
} else if (y <= 2.2e+65) {
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 (y <= (-5.6d-48)) then
tmp = y * z
else if (y <= 2.2d+65) 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 (y <= -5.6e-48) {
tmp = y * z;
} else if (y <= 2.2e+65) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -5.6e-48: tmp = y * z elif y <= 2.2e+65: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -5.6e-48) tmp = Float64(y * z); elseif (y <= 2.2e+65) tmp = t; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -5.6e-48) tmp = y * z; elseif (y <= 2.2e+65) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -5.6e-48], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.2e+65], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.6 \cdot 10^{-48}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{+65}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -5.6000000000000001e-48 or 2.1999999999999998e65 < y Initial program 100.0%
Taylor expanded in z around inf 0
Simplified0
if -5.6000000000000001e-48 < y < 2.1999999999999998e65Initial program 100.0%
Taylor expanded in y around 0 0
Simplified0
(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}
Initial program 100.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 0
Simplified0
herbie shell --seed 2024110
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))