
(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 6 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 (+ z (* x y))))) (if (<= y -6.8e+51) t_1 (if (<= y 30000000000000.0) (+ 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 <= -6.8e+51) {
tmp = t_1;
} else if (y <= 30000000000000.0) {
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 <= (-6.8d+51)) then
tmp = t_1
else if (y <= 30000000000000.0d0) 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 <= -6.8e+51) {
tmp = t_1;
} else if (y <= 30000000000000.0) {
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 <= -6.8e+51: tmp = t_1 elif y <= 30000000000000.0: 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 <= -6.8e+51) tmp = t_1; elseif (y <= 30000000000000.0) 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 <= -6.8e+51) tmp = t_1; elseif (y <= 30000000000000.0) 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, -6.8e+51], t$95$1, If[LessEqual[y, 30000000000000.0], 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.8 \cdot 10^{+51}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 30000000000000:\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -6.79999999999999969e51 or 3e13 < 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
unpow2N/A
associate-*r*N/A
*-commutativeN/A
fma-defineN/A
*-commutativeN/A
distribute-lft-inN/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6494.1%
Simplified94.1%
if -6.79999999999999969e51 < y < 3e13Initial program 99.9%
Taylor expanded in x around 0
Simplified90.9%
Final simplification92.4%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (* x y)))) (if (<= y -1e+52) t_1 (if (<= y 1.25e+82) (+ 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 <= -1e+52) {
tmp = t_1;
} else if (y <= 1.25e+82) {
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 <= (-1d+52)) then
tmp = t_1
else if (y <= 1.25d+82) 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 <= -1e+52) {
tmp = t_1;
} else if (y <= 1.25e+82) {
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 <= -1e+52: tmp = t_1 elif y <= 1.25e+82: 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 <= -1e+52) tmp = t_1; elseif (y <= 1.25e+82) 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 <= -1e+52) tmp = t_1; elseif (y <= 1.25e+82) 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, -1e+52], t$95$1, If[LessEqual[y, 1.25e+82], 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 -1 \cdot 10^{+52}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{+82}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -9.9999999999999999e51 or 1.25000000000000004e82 < 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-*.f6480.4%
Simplified80.4%
if -9.9999999999999999e51 < y < 1.25000000000000004e82Initial program 99.9%
Taylor expanded in x around 0
Simplified87.3%
Final simplification84.5%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (* x y)))) (if (<= y -8.5e+51) t_1 (if (<= y 1.6e+16) t t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -8.5e+51) {
tmp = t_1;
} else if (y <= 1.6e+16) {
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 * (x * y)
if (y <= (-8.5d+51)) then
tmp = t_1
else if (y <= 1.6d+16) 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 * (x * y);
double tmp;
if (y <= -8.5e+51) {
tmp = t_1;
} else if (y <= 1.6e+16) {
tmp = t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -8.5e+51: tmp = t_1 elif y <= 1.6e+16: tmp = t else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(x * y)) tmp = 0.0 if (y <= -8.5e+51) tmp = t_1; elseif (y <= 1.6e+16) tmp = t; 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 <= -8.5e+51) tmp = t_1; elseif (y <= 1.6e+16) tmp = t; 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, -8.5e+51], t$95$1, If[LessEqual[y, 1.6e+16], t, t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \leq -8.5 \cdot 10^{+51}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 1.6 \cdot 10^{+16}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -8.4999999999999999e51 or 1.6e16 < 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-*.f6476.6%
Simplified76.6%
if -8.4999999999999999e51 < y < 1.6e16Initial program 99.9%
Taylor expanded in y around 0
Simplified62.0%
Final simplification68.8%
(FPCore (x y z t) :precision binary64 (if (<= z -1.85e+117) (* y z) (if (<= z 8.6e+40) t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.85e+117) {
tmp = y * z;
} else if (z <= 8.6e+40) {
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 <= (-1.85d+117)) then
tmp = y * z
else if (z <= 8.6d+40) 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 <= -1.85e+117) {
tmp = y * z;
} else if (z <= 8.6e+40) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.85e+117: tmp = y * z elif z <= 8.6e+40: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -1.85e+117) tmp = Float64(y * z); elseif (z <= 8.6e+40) tmp = t; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -1.85e+117) tmp = y * z; elseif (z <= 8.6e+40) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.85e+117], N[(y * z), $MachinePrecision], If[LessEqual[z, 8.6e+40], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.85 \cdot 10^{+117}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 8.6 \cdot 10^{+40}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.8499999999999999e117 or 8.6000000000000005e40 < z Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6470.8%
Simplified70.8%
if -1.8499999999999999e117 < z < 8.6000000000000005e40Initial program 99.9%
Taylor expanded in y around 0
Simplified48.5%
(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.1%
herbie shell --seed 2024138
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))