
(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 (+ (* y (fma y x z)) t))
double code(double x, double y, double z, double t) {
return (y * fma(y, x, z)) + t;
}
function code(x, y, z, t) return Float64(Float64(y * fma(y, x, z)) + t) end
code[x_, y_, z_, t_] := N[(N[(y * N[(y * x + z), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \mathsf{fma}\left(y, x, z\right) + t
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
*-commutative100.0%
fma-udef100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* y x))))
(if (<= y -1.12e+105)
t_1
(if (<= y -4.6e+73)
(* y z)
(if (or (<= y -1.25e+41) (not (<= y 4.8e-21))) t_1 t)))))
double code(double x, double y, double z, double t) {
double t_1 = y * (y * x);
double tmp;
if (y <= -1.12e+105) {
tmp = t_1;
} else if (y <= -4.6e+73) {
tmp = y * z;
} else if ((y <= -1.25e+41) || !(y <= 4.8e-21)) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_1 = y * (y * x)
if (y <= (-1.12d+105)) then
tmp = t_1
else if (y <= (-4.6d+73)) then
tmp = y * z
else if ((y <= (-1.25d+41)) .or. (.not. (y <= 4.8d-21))) then
tmp = t_1
else
tmp = t
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 <= -1.12e+105) {
tmp = t_1;
} else if (y <= -4.6e+73) {
tmp = y * z;
} else if ((y <= -1.25e+41) || !(y <= 4.8e-21)) {
tmp = t_1;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (y * x) tmp = 0 if y <= -1.12e+105: tmp = t_1 elif y <= -4.6e+73: tmp = y * z elif (y <= -1.25e+41) or not (y <= 4.8e-21): tmp = t_1 else: tmp = t return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(y * x)) tmp = 0.0 if (y <= -1.12e+105) tmp = t_1; elseif (y <= -4.6e+73) tmp = Float64(y * z); elseif ((y <= -1.25e+41) || !(y <= 4.8e-21)) tmp = t_1; else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (y * x); tmp = 0.0; if (y <= -1.12e+105) tmp = t_1; elseif (y <= -4.6e+73) tmp = y * z; elseif ((y <= -1.25e+41) || ~((y <= 4.8e-21))) tmp = t_1; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.12e+105], t$95$1, If[LessEqual[y, -4.6e+73], N[(y * z), $MachinePrecision], If[Or[LessEqual[y, -1.25e+41], N[Not[LessEqual[y, 4.8e-21]], $MachinePrecision]], t$95$1, t]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(y \cdot x\right)\\
\mathbf{if}\;y \leq -1.12 \cdot 10^{+105}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -4.6 \cdot 10^{+73}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1.25 \cdot 10^{+41} \lor \neg \left(y \leq 4.8 \cdot 10^{-21}\right):\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -1.12e105 or -4.6e73 < y < -1.25000000000000006e41 or 4.7999999999999999e-21 < y Initial program 100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in t around 0 94.9%
Taylor expanded in z around 0 78.3%
*-commutative78.3%
Simplified78.3%
if -1.12e105 < y < -4.6e73Initial program 100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in t around 0 90.7%
Taylor expanded in z around inf 70.7%
if -1.25000000000000006e41 < y < 4.7999999999999999e-21Initial program 100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 71.8%
Final simplification74.2%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.15e+41) (not (<= y 2.7e-44))) (* y (+ z (* y x))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.15e+41) || !(y <= 2.7e-44)) {
tmp = y * (z + (y * x));
} 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.15d+41)) .or. (.not. (y <= 2.7d-44))) then
tmp = y * (z + (y * x))
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.15e+41) || !(y <= 2.7e-44)) {
tmp = y * (z + (y * x));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.15e+41) or not (y <= 2.7e-44): tmp = y * (z + (y * x)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.15e+41) || !(y <= 2.7e-44)) tmp = Float64(y * Float64(z + Float64(y * x))); 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.15e+41) || ~((y <= 2.7e-44))) tmp = y * (z + (y * x)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.15e+41], N[Not[LessEqual[y, 2.7e-44]], $MachinePrecision]], N[(y * N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.15 \cdot 10^{+41} \lor \neg \left(y \leq 2.7 \cdot 10^{-44}\right):\\
\;\;\;\;y \cdot \left(z + y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.1499999999999999e41 or 2.6999999999999999e-44 < y Initial program 100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in t around 0 94.6%
if -1.1499999999999999e41 < y < 2.6999999999999999e-44Initial program 100.0%
Taylor expanded in x around 0 95.1%
Final simplification94.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -5.8e+105) (not (<= y 5e+124))) (* y (* y x)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -5.8e+105) || !(y <= 5e+124)) {
tmp = y * (y * x);
} 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 <= (-5.8d+105)) .or. (.not. (y <= 5d+124))) then
tmp = y * (y * x)
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 <= -5.8e+105) || !(y <= 5e+124)) {
tmp = y * (y * x);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -5.8e+105) or not (y <= 5e+124): tmp = y * (y * x) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -5.8e+105) || !(y <= 5e+124)) tmp = Float64(y * Float64(y * x)); else tmp = Float64(t + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -5.8e+105) || ~((y <= 5e+124))) tmp = y * (y * x); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -5.8e+105], N[Not[LessEqual[y, 5e+124]], $MachinePrecision]], N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{+105} \lor \neg \left(y \leq 5 \cdot 10^{+124}\right):\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -5.8000000000000002e105 or 4.9999999999999996e124 < y Initial program 100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in t around 0 98.6%
Taylor expanded in z around 0 88.4%
*-commutative88.4%
Simplified88.4%
if -5.8000000000000002e105 < y < 4.9999999999999996e124Initial program 100.0%
Taylor expanded in x around 0 88.7%
Final simplification88.6%
(FPCore (x y z t) :precision binary64 (if (or (<= z -3.8e+201) (not (<= z 6.8e+159))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.8e+201) || !(z <= 6.8e+159)) {
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.8d+201)) .or. (.not. (z <= 6.8d+159))) 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.8e+201) || !(z <= 6.8e+159)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3.8e+201) or not (z <= 6.8e+159): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.8e+201) || !(z <= 6.8e+159)) 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.8e+201) || ~((z <= 6.8e+159))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.8e+201], N[Not[LessEqual[z, 6.8e+159]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{+201} \lor \neg \left(z \leq 6.8 \cdot 10^{+159}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -3.79999999999999995e201 or 6.79999999999999983e159 < z Initial program 100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in t around 0 84.3%
Taylor expanded in z around inf 74.0%
if -3.79999999999999995e201 < z < 6.79999999999999983e159Initial program 100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 55.3%
Final simplification60.2%
(FPCore (x y z t) :precision binary64 (+ t (* y (+ z (* y x)))))
double code(double x, double y, double z, double t) {
return t + (y * (z + (y * x)));
}
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 + (y * x)))
end function
public static double code(double x, double y, double z, double t) {
return t + (y * (z + (y * x)));
}
def code(x, y, z, t): return t + (y * (z + (y * x)))
function code(x, y, z, t) return Float64(t + Float64(y * Float64(z + Float64(y * x)))) end
function tmp = code(x, y, z, t) tmp = t + (y * (z + (y * x))); end
code[x_, y_, z_, t_] := N[(t + N[(y * N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + y \cdot \left(z + y \cdot x\right)
\end{array}
Initial program 100.0%
Final simplification100.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%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 45.2%
Final simplification45.2%
herbie shell --seed 2024020
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))