
(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 99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (+ (* x y) z))))
(if (<= y -5.5e+84)
t_1
(if (<= y -2.4e-81)
(+ t (* x (* y y)))
(if (<= y 6.1e-6) (+ t (* y z)) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = y * ((x * y) + z);
double tmp;
if (y <= -5.5e+84) {
tmp = t_1;
} else if (y <= -2.4e-81) {
tmp = t + (x * (y * y));
} else if (y <= 6.1e-6) {
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) + z)
if (y <= (-5.5d+84)) then
tmp = t_1
else if (y <= (-2.4d-81)) then
tmp = t + (x * (y * y))
else if (y <= 6.1d-6) 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) + z);
double tmp;
if (y <= -5.5e+84) {
tmp = t_1;
} else if (y <= -2.4e-81) {
tmp = t + (x * (y * y));
} else if (y <= 6.1e-6) {
tmp = t + (y * z);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * ((x * y) + z) tmp = 0 if y <= -5.5e+84: tmp = t_1 elif y <= -2.4e-81: tmp = t + (x * (y * y)) elif y <= 6.1e-6: tmp = t + (y * z) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(Float64(x * y) + z)) tmp = 0.0 if (y <= -5.5e+84) tmp = t_1; elseif (y <= -2.4e-81) tmp = Float64(t + Float64(x * Float64(y * y))); elseif (y <= 6.1e-6) 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) + z); tmp = 0.0; if (y <= -5.5e+84) tmp = t_1; elseif (y <= -2.4e-81) tmp = t + (x * (y * y)); elseif (y <= 6.1e-6) 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[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5.5e+84], t$95$1, If[LessEqual[y, -2.4e-81], N[(t + N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6.1e-6], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y + z\right)\\
\mathbf{if}\;y \leq -5.5 \cdot 10^{+84}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -2.4 \cdot 10^{-81}:\\
\;\;\;\;t + x \cdot \left(y \cdot y\right)\\
\mathbf{elif}\;y \leq 6.1 \cdot 10^{-6}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -5.5000000000000004e84 or 6.10000000000000004e-6 < y Initial program 99.9%
Taylor expanded in t around inf 91.8%
associate-/l*91.7%
+-commutative91.7%
*-commutative91.7%
fma-undefine91.7%
Simplified91.7%
Taylor expanded in t around 0 91.3%
if -5.5000000000000004e84 < y < -2.3999999999999999e-81Initial program 100.0%
Taylor expanded in x around inf 91.8%
+-commutative91.8%
unpow291.8%
associate-/l*89.1%
distribute-lft-out89.1%
Simplified89.1%
Taylor expanded in y around inf 84.6%
if -2.3999999999999999e-81 < y < 6.10000000000000004e-6Initial program 100.0%
Taylor expanded in x around 0 90.8%
Final simplification90.2%
(FPCore (x y z t) :precision binary64 (if (or (<= z -8e+150) (not (<= z 2.55e+123))) (+ t (* y z)) (+ t (* y (* x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -8e+150) || !(z <= 2.55e+123)) {
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 <= (-8d+150)) .or. (.not. (z <= 2.55d+123))) 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 <= -8e+150) || !(z <= 2.55e+123)) {
tmp = t + (y * z);
} else {
tmp = t + (y * (x * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -8e+150) or not (z <= 2.55e+123): tmp = t + (y * z) else: tmp = t + (y * (x * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -8e+150) || !(z <= 2.55e+123)) 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 <= -8e+150) || ~((z <= 2.55e+123))) tmp = t + (y * z); else tmp = t + (y * (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -8e+150], N[Not[LessEqual[z, 2.55e+123]], $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 -8 \cdot 10^{+150} \lor \neg \left(z \leq 2.55 \cdot 10^{+123}\right):\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -7.99999999999999985e150 or 2.54999999999999986e123 < z Initial program 100.0%
Taylor expanded in x around 0 89.2%
if -7.99999999999999985e150 < z < 2.54999999999999986e123Initial program 99.9%
Taylor expanded in x around inf 93.0%
*-commutative93.0%
Simplified93.0%
Final simplification91.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3.5e+27) (not (<= y 2.45e-9))) (* y (+ (* x y) z)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.5e+27) || !(y <= 2.45e-9)) {
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.5d+27)) .or. (.not. (y <= 2.45d-9))) 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.5e+27) || !(y <= 2.45e-9)) {
tmp = y * ((x * y) + z);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -3.5e+27) or not (y <= 2.45e-9): tmp = y * ((x * y) + z) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -3.5e+27) || !(y <= 2.45e-9)) 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.5e+27) || ~((y <= 2.45e-9))) 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.5e+27], N[Not[LessEqual[y, 2.45e-9]], $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.5 \cdot 10^{+27} \lor \neg \left(y \leq 2.45 \cdot 10^{-9}\right):\\
\;\;\;\;y \cdot \left(x \cdot y + z\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -3.5000000000000002e27 or 2.45000000000000002e-9 < y Initial program 99.9%
Taylor expanded in t around inf 91.4%
associate-/l*91.3%
+-commutative91.3%
*-commutative91.3%
fma-undefine91.3%
Simplified91.3%
Taylor expanded in t around 0 90.1%
if -3.5000000000000002e27 < y < 2.45000000000000002e-9Initial program 100.0%
Taylor expanded in x around 0 86.7%
Final simplification88.4%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.7e+29) (not (<= y 3.6e+114))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.7e+29) || !(y <= 3.6e+114)) {
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.7d+29)) .or. (.not. (y <= 3.6d+114))) 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.7e+29) || !(y <= 3.6e+114)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.7e+29) or not (y <= 3.6e+114): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.7e+29) || !(y <= 3.6e+114)) 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.7e+29) || ~((y <= 3.6e+114))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.7e+29], N[Not[LessEqual[y, 3.6e+114]], $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.7 \cdot 10^{+29} \lor \neg \left(y \leq 3.6 \cdot 10^{+114}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.69999999999999991e29 or 3.6000000000000001e114 < y Initial program 99.9%
Taylor expanded in z around inf 97.0%
Taylor expanded in t around 0 91.6%
Taylor expanded in z around 0 80.0%
if -1.69999999999999991e29 < y < 3.6000000000000001e114Initial program 100.0%
Taylor expanded in x around 0 81.4%
Final simplification80.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.8e+22) (not (<= y 1.4e-8))) (* y (* x y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.8e+22) || !(y <= 1.4e-8)) {
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 <= (-1.8d+22)) .or. (.not. (y <= 1.4d-8))) 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 <= -1.8e+22) || !(y <= 1.4e-8)) {
tmp = y * (x * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.8e+22) or not (y <= 1.4e-8): tmp = y * (x * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.8e+22) || !(y <= 1.4e-8)) 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 <= -1.8e+22) || ~((y <= 1.4e-8))) tmp = y * (x * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.8e+22], N[Not[LessEqual[y, 1.4e-8]], $MachinePrecision]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{+22} \lor \neg \left(y \leq 1.4 \cdot 10^{-8}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -1.8e22 or 1.4e-8 < y Initial program 99.9%
Taylor expanded in z around inf 95.6%
Taylor expanded in t around 0 86.5%
Taylor expanded in z around 0 71.0%
if -1.8e22 < y < 1.4e-8Initial program 100.0%
Taylor expanded in y around 0 69.6%
Final simplification70.3%
(FPCore (x y z t) :precision binary64 (if (or (<= z -9.5e+48) (not (<= z 1.4e+180))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -9.5e+48) || !(z <= 1.4e+180)) {
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 <= (-9.5d+48)) .or. (.not. (z <= 1.4d+180))) 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 <= -9.5e+48) || !(z <= 1.4e+180)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -9.5e+48) or not (z <= 1.4e+180): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -9.5e+48) || !(z <= 1.4e+180)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -9.5e+48) || ~((z <= 1.4e+180))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -9.5e+48], N[Not[LessEqual[z, 1.4e+180]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.5 \cdot 10^{+48} \lor \neg \left(z \leq 1.4 \cdot 10^{+180}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -9.4999999999999997e48 or 1.40000000000000006e180 < z Initial program 100.0%
Taylor expanded in t around inf 91.2%
associate-/l*85.4%
+-commutative85.4%
*-commutative85.4%
fma-undefine85.4%
Simplified85.4%
Taylor expanded in z around inf 59.5%
if -9.4999999999999997e48 < z < 1.40000000000000006e180Initial program 99.9%
Taylor expanded in y around 0 47.8%
Final simplification51.7%
(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 39.4%
herbie shell --seed 2024137
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))