
(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 (fma (fma x y z) y t))
double code(double x, double y, double z, double t) {
return fma(fma(x, y, z), y, t);
}
function code(x, y, z, t) return fma(fma(x, y, z), y, t) end
code[x_, y_, z_, t_] := N[(N[(x * y + z), $MachinePrecision] * y + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, t\right)
\end{array}
Initial program 99.9%
fma-define99.9%
fma-define99.9%
Simplified99.9%
(FPCore (x y z t)
:precision binary64
(if (or (<= y -7.6e+97)
(not
(or (<= y -4.9e+61)
(and (not (<= y -4.05e+27)) (<= y 245000000000.0)))))
(* y (* x y))
(+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -7.6e+97) || !((y <= -4.9e+61) || (!(y <= -4.05e+27) && (y <= 245000000000.0)))) {
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 <= (-7.6d+97)) .or. (.not. (y <= (-4.9d+61)) .or. (.not. (y <= (-4.05d+27))) .and. (y <= 245000000000.0d0))) 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 <= -7.6e+97) || !((y <= -4.9e+61) || (!(y <= -4.05e+27) && (y <= 245000000000.0)))) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -7.6e+97) or not ((y <= -4.9e+61) or (not (y <= -4.05e+27) and (y <= 245000000000.0))): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -7.6e+97) || !((y <= -4.9e+61) || (!(y <= -4.05e+27) && (y <= 245000000000.0)))) 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 <= -7.6e+97) || ~(((y <= -4.9e+61) || (~((y <= -4.05e+27)) && (y <= 245000000000.0))))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -7.6e+97], N[Not[Or[LessEqual[y, -4.9e+61], And[N[Not[LessEqual[y, -4.05e+27]], $MachinePrecision], LessEqual[y, 245000000000.0]]]], $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 -7.6 \cdot 10^{+97} \lor \neg \left(y \leq -4.9 \cdot 10^{+61} \lor \neg \left(y \leq -4.05 \cdot 10^{+27}\right) \land y \leq 245000000000\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -7.60000000000000071e97 or -4.90000000000000025e61 < y < -4.05000000000000015e27 or 2.45e11 < y Initial program 99.9%
fma-define99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in t around inf 88.8%
+-commutative88.8%
+-commutative88.8%
fma-undefine88.8%
*-commutative88.8%
associate-/l*88.9%
fma-define88.9%
fma-undefine88.9%
*-commutative88.9%
fma-undefine88.9%
Simplified88.9%
Taylor expanded in t around 0 94.7%
Taylor expanded in z around 0 78.8%
*-commutative78.8%
Simplified78.8%
if -7.60000000000000071e97 < y < -4.90000000000000025e61 or -4.05000000000000015e27 < y < 2.45e11Initial program 99.9%
Taylor expanded in x around 0 90.1%
Final simplification85.0%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.75e-13) (not (<= y 1.14e-69))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.75e-13) || !(y <= 1.14e-69)) {
tmp = y * (z + (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.75d-13)) .or. (.not. (y <= 1.14d-69))) then
tmp = y * (z + (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.75e-13) || !(y <= 1.14e-69)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.75e-13) or not (y <= 1.14e-69): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.75e-13) || !(y <= 1.14e-69)) tmp = Float64(y * Float64(z + 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.75e-13) || ~((y <= 1.14e-69))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.75e-13], N[Not[LessEqual[y, 1.14e-69]], $MachinePrecision]], N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.75 \cdot 10^{-13} \lor \neg \left(y \leq 1.14 \cdot 10^{-69}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.7500000000000001e-13 or 1.14000000000000006e-69 < y Initial program 99.9%
fma-define99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in t around inf 89.6%
+-commutative89.6%
+-commutative89.6%
fma-undefine89.6%
*-commutative89.6%
associate-/l*88.9%
fma-define88.9%
fma-undefine88.9%
*-commutative88.9%
fma-undefine88.9%
Simplified88.9%
Taylor expanded in t around 0 89.5%
if -1.7500000000000001e-13 < y < 1.14000000000000006e-69Initial program 100.0%
Taylor expanded in x around 0 95.8%
Final simplification92.3%
(FPCore (x y z t) :precision binary64 (if (or (<= y -5.4e-12) (not (<= y 1.14e-69))) (* y (* x y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -5.4e-12) || !(y <= 1.14e-69)) {
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 <= (-5.4d-12)) .or. (.not. (y <= 1.14d-69))) 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 <= -5.4e-12) || !(y <= 1.14e-69)) {
tmp = y * (x * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -5.4e-12) or not (y <= 1.14e-69): tmp = y * (x * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -5.4e-12) || !(y <= 1.14e-69)) 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 <= -5.4e-12) || ~((y <= 1.14e-69))) tmp = y * (x * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -5.4e-12], N[Not[LessEqual[y, 1.14e-69]], $MachinePrecision]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.4 \cdot 10^{-12} \lor \neg \left(y \leq 1.14 \cdot 10^{-69}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -5.39999999999999961e-12 or 1.14000000000000006e-69 < y Initial program 99.9%
fma-define99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in t around inf 89.6%
+-commutative89.6%
+-commutative89.6%
fma-undefine89.6%
*-commutative89.6%
associate-/l*88.9%
fma-define88.9%
fma-undefine88.9%
*-commutative88.9%
fma-undefine88.9%
Simplified88.9%
Taylor expanded in t around 0 89.5%
Taylor expanded in z around 0 70.4%
*-commutative70.4%
Simplified70.4%
if -5.39999999999999961e-12 < y < 1.14000000000000006e-69Initial program 100.0%
fma-define100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 68.1%
Final simplification69.4%
(FPCore (x y z t) :precision binary64 (if (or (<= z -3.7e+102) (not (<= z 7e+84))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.7e+102) || !(z <= 7e+84)) {
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 <= (-3.7d+102)) .or. (.not. (z <= 7d+84))) 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 <= -3.7e+102) || !(z <= 7e+84)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3.7e+102) or not (z <= 7e+84): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.7e+102) || !(z <= 7e+84)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -3.7e+102) || ~((z <= 7e+84))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.7e+102], N[Not[LessEqual[z, 7e+84]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.7 \cdot 10^{+102} \lor \neg \left(z \leq 7 \cdot 10^{+84}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -3.70000000000000023e102 or 6.9999999999999998e84 < z Initial program 100.0%
fma-define100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in t around inf 84.8%
+-commutative84.8%
+-commutative84.8%
fma-undefine84.8%
*-commutative84.8%
associate-/l*84.6%
fma-define84.6%
fma-undefine84.6%
*-commutative84.6%
fma-undefine84.6%
Simplified84.6%
Taylor expanded in z around inf 67.8%
if -3.70000000000000023e102 < z < 6.9999999999999998e84Initial program 99.9%
fma-define99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around 0 45.0%
Final simplification52.1%
(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 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%
fma-define99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around 0 36.2%
herbie shell --seed 2024103
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))