
(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 (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-def100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z t)
:precision binary64
(if (<= y -1e+171)
(* y (* x y))
(if (or (<= y -2.5e-14) (and (not (<= y -7e-41)) (<= y 1.05e+50)))
(+ t (* y z))
(* x (* y y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1e+171) {
tmp = y * (x * y);
} else if ((y <= -2.5e-14) || (!(y <= -7e-41) && (y <= 1.05e+50))) {
tmp = t + (y * z);
} else {
tmp = x * (y * 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 (y <= (-1d+171)) then
tmp = y * (x * y)
else if ((y <= (-2.5d-14)) .or. (.not. (y <= (-7d-41))) .and. (y <= 1.05d+50)) then
tmp = t + (y * z)
else
tmp = x * (y * y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1e+171) {
tmp = y * (x * y);
} else if ((y <= -2.5e-14) || (!(y <= -7e-41) && (y <= 1.05e+50))) {
tmp = t + (y * z);
} else {
tmp = x * (y * y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -1e+171: tmp = y * (x * y) elif (y <= -2.5e-14) or (not (y <= -7e-41) and (y <= 1.05e+50)): tmp = t + (y * z) else: tmp = x * (y * y) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -1e+171) tmp = Float64(y * Float64(x * y)); elseif ((y <= -2.5e-14) || (!(y <= -7e-41) && (y <= 1.05e+50))) tmp = Float64(t + Float64(y * z)); else tmp = Float64(x * Float64(y * y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -1e+171) tmp = y * (x * y); elseif ((y <= -2.5e-14) || (~((y <= -7e-41)) && (y <= 1.05e+50))) tmp = t + (y * z); else tmp = x * (y * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -1e+171], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, -2.5e-14], And[N[Not[LessEqual[y, -7e-41]], $MachinePrecision], LessEqual[y, 1.05e+50]]], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{+171}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;y \leq -2.5 \cdot 10^{-14} \lor \neg \left(y \leq -7 \cdot 10^{-41}\right) \land y \leq 1.05 \cdot 10^{+50}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if y < -9.99999999999999954e170Initial program 99.9%
Taylor expanded in t around 0 95.8%
Taylor expanded in y around inf 90.9%
if -9.99999999999999954e170 < y < -2.5000000000000001e-14 or -6.9999999999999999e-41 < y < 1.05e50Initial program 100.0%
Taylor expanded in x around 0 89.9%
if -2.5000000000000001e-14 < y < -6.9999999999999999e-41 or 1.05e50 < y Initial program 99.8%
Taylor expanded in x around inf 82.4%
Taylor expanded in y around 0 82.7%
+-commutative82.7%
*-commutative82.7%
unpow282.7%
associate-*r*82.4%
*-commutative82.4%
fma-udef82.4%
Simplified82.4%
Taylor expanded in y around inf 76.2%
unpow276.2%
*-commutative76.2%
Simplified76.2%
Final simplification86.7%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* x (* y y))))
(if (<= y -9.2e+162)
t_1
(if (<= y -5.9e+53) (* y z) (if (<= y 4.0) t t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = x * (y * y);
double tmp;
if (y <= -9.2e+162) {
tmp = t_1;
} else if (y <= -5.9e+53) {
tmp = y * z;
} else if (y <= 4.0) {
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 = x * (y * y)
if (y <= (-9.2d+162)) then
tmp = t_1
else if (y <= (-5.9d+53)) then
tmp = y * z
else if (y <= 4.0d0) 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 = x * (y * y);
double tmp;
if (y <= -9.2e+162) {
tmp = t_1;
} else if (y <= -5.9e+53) {
tmp = y * z;
} else if (y <= 4.0) {
tmp = t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x * (y * y) tmp = 0 if y <= -9.2e+162: tmp = t_1 elif y <= -5.9e+53: tmp = y * z elif y <= 4.0: tmp = t else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(x * Float64(y * y)) tmp = 0.0 if (y <= -9.2e+162) tmp = t_1; elseif (y <= -5.9e+53) tmp = Float64(y * z); elseif (y <= 4.0) tmp = t; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x * (y * y); tmp = 0.0; if (y <= -9.2e+162) tmp = t_1; elseif (y <= -5.9e+53) tmp = y * z; elseif (y <= 4.0) tmp = t; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -9.2e+162], t$95$1, If[LessEqual[y, -5.9e+53], N[(y * z), $MachinePrecision], If[LessEqual[y, 4.0], t, t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \left(y \cdot y\right)\\
\mathbf{if}\;y \leq -9.2 \cdot 10^{+162}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -5.9 \cdot 10^{+53}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 4:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -9.19999999999999975e162 or 4 < y Initial program 99.9%
Taylor expanded in x around inf 83.9%
Taylor expanded in y around 0 81.3%
+-commutative81.3%
*-commutative81.3%
unpow281.3%
associate-*r*83.9%
*-commutative83.9%
fma-udef83.9%
Simplified83.9%
Taylor expanded in y around inf 72.9%
unpow272.9%
*-commutative72.9%
Simplified72.9%
if -9.19999999999999975e162 < y < -5.8999999999999997e53Initial program 99.9%
Taylor expanded in x around 0 74.4%
Taylor expanded in z around inf 61.6%
if -5.8999999999999997e53 < y < 4Initial program 100.0%
Taylor expanded in y around 0 69.0%
Final simplification69.9%
(FPCore (x y z t) :precision binary64 (if (<= y -4e+157) (* y (* x y)) (if (<= y -1.1e+54) (* y z) (if (<= y 175.0) t (* x (* y y))))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -4e+157) {
tmp = y * (x * y);
} else if (y <= -1.1e+54) {
tmp = y * z;
} else if (y <= 175.0) {
tmp = t;
} else {
tmp = x * (y * 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 (y <= (-4d+157)) then
tmp = y * (x * y)
else if (y <= (-1.1d+54)) then
tmp = y * z
else if (y <= 175.0d0) then
tmp = t
else
tmp = x * (y * y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -4e+157) {
tmp = y * (x * y);
} else if (y <= -1.1e+54) {
tmp = y * z;
} else if (y <= 175.0) {
tmp = t;
} else {
tmp = x * (y * y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -4e+157: tmp = y * (x * y) elif y <= -1.1e+54: tmp = y * z elif y <= 175.0: tmp = t else: tmp = x * (y * y) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -4e+157) tmp = Float64(y * Float64(x * y)); elseif (y <= -1.1e+54) tmp = Float64(y * z); elseif (y <= 175.0) tmp = t; else tmp = Float64(x * Float64(y * y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -4e+157) tmp = y * (x * y); elseif (y <= -1.1e+54) tmp = y * z; elseif (y <= 175.0) tmp = t; else tmp = x * (y * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -4e+157], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -1.1e+54], N[(y * z), $MachinePrecision], If[LessEqual[y, 175.0], t, N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+157}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;y \leq -1.1 \cdot 10^{+54}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 175:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if y < -3.99999999999999993e157Initial program 99.9%
Taylor expanded in t around 0 93.3%
Taylor expanded in y around inf 82.5%
if -3.99999999999999993e157 < y < -1.09999999999999995e54Initial program 99.9%
Taylor expanded in x around 0 77.1%
Taylor expanded in z around inf 62.8%
if -1.09999999999999995e54 < y < 175Initial program 100.0%
Taylor expanded in y around 0 69.0%
if 175 < y Initial program 99.9%
Taylor expanded in x around inf 80.9%
Taylor expanded in y around 0 81.2%
+-commutative81.2%
*-commutative81.2%
unpow281.2%
associate-*r*80.9%
*-commutative80.9%
fma-udef80.9%
Simplified80.9%
Taylor expanded in y around inf 69.6%
unpow269.6%
*-commutative69.6%
Simplified69.6%
Final simplification70.2%
(FPCore (x y z t) :precision binary64 (if (or (<= y -6e-41) (not (<= y 11.5))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -6e-41) || !(y <= 11.5)) {
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 <= (-6d-41)) .or. (.not. (y <= 11.5d0))) 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 <= -6e-41) || !(y <= 11.5)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -6e-41) or not (y <= 11.5): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -6e-41) || !(y <= 11.5)) 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 <= -6e-41) || ~((y <= 11.5))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -6e-41], N[Not[LessEqual[y, 11.5]], $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 -6 \cdot 10^{-41} \lor \neg \left(y \leq 11.5\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -5.99999999999999978e-41 or 11.5 < y Initial program 99.9%
Taylor expanded in t around 0 85.7%
if -5.99999999999999978e-41 < y < 11.5Initial program 100.0%
Taylor expanded in x around 0 97.7%
Final simplification91.5%
(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 (if (<= z -3e+76) (* y z) (if (<= z 7e+129) t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -3e+76) {
tmp = y * z;
} else if (z <= 7e+129) {
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 <= (-3d+76)) then
tmp = y * z
else if (z <= 7d+129) 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 <= -3e+76) {
tmp = y * z;
} else if (z <= 7e+129) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -3e+76: tmp = y * z elif z <= 7e+129: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -3e+76) tmp = Float64(y * z); elseif (z <= 7e+129) tmp = t; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -3e+76) tmp = y * z; elseif (z <= 7e+129) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -3e+76], N[(y * z), $MachinePrecision], If[LessEqual[z, 7e+129], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3 \cdot 10^{+76}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 7 \cdot 10^{+129}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -2.9999999999999998e76 or 6.9999999999999997e129 < z Initial program 99.9%
Taylor expanded in x around 0 85.8%
Taylor expanded in z around inf 64.1%
if -2.9999999999999998e76 < z < 6.9999999999999997e129Initial program 99.9%
Taylor expanded in y around 0 55.1%
Final simplification58.2%
(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 43.6%
Final simplification43.6%
herbie shell --seed 2023199
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))