
(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 (+ z (* x y)))))
double code(double x, double y, double z, double t) {
return t + (y * (z + (x * y)));
}
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 * (z + (x * y)))
end function
public static double code(double x, double y, double z, double t) {
return t + (y * (z + (x * y)));
}
def code(x, y, z, t): return t + (y * (z + (x * y)))
function code(x, y, z, t) return Float64(t + Float64(y * Float64(z + Float64(x * y)))) end
function tmp = code(x, y, z, t) tmp = t + (y * (z + (x * y))); end
code[x_, y_, z_, t_] := N[(t + N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + y \cdot \left(z + x \cdot y\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* x y))))
(if (<= y -1.25e+54)
t_1
(if (<= y 1e-33) t (if (<= y 2.05e+121) (* y z) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -1.25e+54) {
tmp = t_1;
} else if (y <= 1e-33) {
tmp = t;
} else if (y <= 2.05e+121) {
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 <= (-1.25d+54)) then
tmp = t_1
else if (y <= 1d-33) then
tmp = t
else if (y <= 2.05d+121) 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 <= -1.25e+54) {
tmp = t_1;
} else if (y <= 1e-33) {
tmp = t;
} else if (y <= 2.05e+121) {
tmp = y * z;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -1.25e+54: tmp = t_1 elif y <= 1e-33: tmp = t elif y <= 2.05e+121: 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 <= -1.25e+54) tmp = t_1; elseif (y <= 1e-33) tmp = t; elseif (y <= 2.05e+121) 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 <= -1.25e+54) tmp = t_1; elseif (y <= 1e-33) tmp = t; elseif (y <= 2.05e+121) 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, -1.25e+54], t$95$1, If[LessEqual[y, 1e-33], t, If[LessEqual[y, 2.05e+121], 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 -1.25 \cdot 10^{+54}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 10^{-33}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 2.05 \cdot 10^{+121}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.25000000000000001e54 or 2.05e121 < y Initial program 99.9%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6468.7%
Simplified68.7%
if -1.25000000000000001e54 < y < 1.0000000000000001e-33Initial program 99.9%
Taylor expanded in y around 0
Simplified63.3%
if 1.0000000000000001e-33 < y < 2.05e121Initial program 99.8%
Taylor expanded in z around inf
*-lowering-*.f6451.7%
Simplified51.7%
Final simplification63.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (+ t (* y z)))) (if (<= z -9.2e+107) t_1 (if (<= z 4e+67) (+ t (* y (* x y))) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = t + (y * z);
double tmp;
if (z <= -9.2e+107) {
tmp = t_1;
} else if (z <= 4e+67) {
tmp = t + (y * (x * y));
} 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 = t + (y * z)
if (z <= (-9.2d+107)) then
tmp = t_1
else if (z <= 4d+67) then
tmp = t + (y * (x * y))
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 = t + (y * z);
double tmp;
if (z <= -9.2e+107) {
tmp = t_1;
} else if (z <= 4e+67) {
tmp = t + (y * (x * y));
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = t + (y * z) tmp = 0 if z <= -9.2e+107: tmp = t_1 elif z <= 4e+67: tmp = t + (y * (x * y)) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(t + Float64(y * z)) tmp = 0.0 if (z <= -9.2e+107) tmp = t_1; elseif (z <= 4e+67) tmp = Float64(t + Float64(y * Float64(x * y))); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = t + (y * z); tmp = 0.0; if (z <= -9.2e+107) tmp = t_1; elseif (z <= 4e+67) tmp = t + (y * (x * y)); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -9.2e+107], t$95$1, If[LessEqual[z, 4e+67], N[(t + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := t + y \cdot z\\
\mathbf{if}\;z \leq -9.2 \cdot 10^{+107}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 4 \cdot 10^{+67}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -9.2000000000000001e107 or 3.99999999999999993e67 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified94.1%
if -9.2000000000000001e107 < z < 3.99999999999999993e67Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6490.4%
Simplified90.4%
Final simplification91.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (+ z (* x y))))) (if (<= y -6e+55) t_1 (if (<= y 1.02e-30) (+ t (* y z)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * (z + (x * y));
double tmp;
if (y <= -6e+55) {
tmp = t_1;
} else if (y <= 1.02e-30) {
tmp = t + (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 * (z + (x * y))
if (y <= (-6d+55)) then
tmp = t_1
else if (y <= 1.02d-30) then
tmp = t + (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 * (z + (x * y));
double tmp;
if (y <= -6e+55) {
tmp = t_1;
} else if (y <= 1.02e-30) {
tmp = t + (y * z);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (z + (x * y)) tmp = 0 if y <= -6e+55: tmp = t_1 elif y <= 1.02e-30: tmp = t + (y * z) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(z + Float64(x * y))) tmp = 0.0 if (y <= -6e+55) tmp = t_1; elseif (y <= 1.02e-30) tmp = Float64(t + Float64(y * z)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (z + (x * y)); tmp = 0.0; if (y <= -6e+55) tmp = t_1; elseif (y <= 1.02e-30) tmp = t + (y * z); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -6e+55], t$95$1, If[LessEqual[y, 1.02e-30], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(z + x \cdot y\right)\\
\mathbf{if}\;y \leq -6 \cdot 10^{+55}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 1.02 \cdot 10^{-30}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -6.00000000000000033e55 or 1.0199999999999999e-30 < y Initial program 99.9%
Taylor expanded in y around inf
distribute-rgt-inN/A
+-commutativeN/A
unpow2N/A
associate-*r*N/A
fma-defineN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
fma-defineN/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
distribute-lft-inN/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6493.0%
Simplified93.0%
if -6.00000000000000033e55 < y < 1.0199999999999999e-30Initial program 99.9%
Taylor expanded in x around 0
Simplified87.2%
Final simplification89.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (* x y)))) (if (<= y -3.4e+75) t_1 (if (<= y 8.5e+121) (+ t (* y z)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -3.4e+75) {
tmp = t_1;
} else if (y <= 8.5e+121) {
tmp = t + (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 <= (-3.4d+75)) then
tmp = t_1
else if (y <= 8.5d+121) then
tmp = t + (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 <= -3.4e+75) {
tmp = t_1;
} else if (y <= 8.5e+121) {
tmp = t + (y * z);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -3.4e+75: tmp = t_1 elif y <= 8.5e+121: tmp = t + (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 <= -3.4e+75) tmp = t_1; elseif (y <= 8.5e+121) tmp = Float64(t + 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 <= -3.4e+75) tmp = t_1; elseif (y <= 8.5e+121) tmp = t + (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, -3.4e+75], t$95$1, If[LessEqual[y, 8.5e+121], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \leq -3.4 \cdot 10^{+75}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{+121}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -3.40000000000000011e75 or 8.5e121 < y Initial program 99.9%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6470.6%
Simplified70.6%
if -3.40000000000000011e75 < y < 8.5e121Initial program 99.9%
Taylor expanded in x around 0
Simplified83.8%
Final simplification79.3%
(FPCore (x y z t) :precision binary64 (if (<= y -1.5e+55) (* y z) (if (<= y 3.8e-37) t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.5e+55) {
tmp = y * z;
} else if (y <= 3.8e-37) {
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 <= (-1.5d+55)) then
tmp = y * z
else if (y <= 3.8d-37) 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 <= -1.5e+55) {
tmp = y * z;
} else if (y <= 3.8e-37) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -1.5e+55: tmp = y * z elif y <= 3.8e-37: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -1.5e+55) tmp = Float64(y * z); elseif (y <= 3.8e-37) tmp = t; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -1.5e+55) tmp = y * z; elseif (y <= 3.8e-37) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -1.5e+55], N[(y * z), $MachinePrecision], If[LessEqual[y, 3.8e-37], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{+55}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-37}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -1.50000000000000008e55 or 3.8000000000000004e-37 < y Initial program 99.9%
Taylor expanded in z around inf
*-lowering-*.f6440.5%
Simplified40.5%
if -1.50000000000000008e55 < y < 3.8000000000000004e-37Initial program 99.9%
Taylor expanded in y around 0
Simplified63.3%
(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
Simplified37.9%
herbie shell --seed 2024160
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))