
(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 (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 -9.2e+30)
(and (not (<= y -15500.0))
(or (<= y -15000.0)
(not
(or (<= y 4e+47)
(and (not (<= y 8e+69)) (<= y 5.2e+160)))))))
(* x (* y y))
(+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -9.2e+30) || (!(y <= -15500.0) && ((y <= -15000.0) || !((y <= 4e+47) || (!(y <= 8e+69) && (y <= 5.2e+160)))))) {
tmp = x * (y * 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 <= (-9.2d+30)) .or. (.not. (y <= (-15500.0d0))) .and. (y <= (-15000.0d0)) .or. (.not. (y <= 4d+47) .or. (.not. (y <= 8d+69)) .and. (y <= 5.2d+160))) then
tmp = x * (y * 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 <= -9.2e+30) || (!(y <= -15500.0) && ((y <= -15000.0) || !((y <= 4e+47) || (!(y <= 8e+69) && (y <= 5.2e+160)))))) {
tmp = x * (y * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -9.2e+30) or (not (y <= -15500.0) and ((y <= -15000.0) or not ((y <= 4e+47) or (not (y <= 8e+69) and (y <= 5.2e+160))))): tmp = x * (y * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -9.2e+30) || (!(y <= -15500.0) && ((y <= -15000.0) || !((y <= 4e+47) || (!(y <= 8e+69) && (y <= 5.2e+160)))))) tmp = Float64(x * Float64(y * 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 <= -9.2e+30) || (~((y <= -15500.0)) && ((y <= -15000.0) || ~(((y <= 4e+47) || (~((y <= 8e+69)) && (y <= 5.2e+160))))))) tmp = x * (y * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -9.2e+30], And[N[Not[LessEqual[y, -15500.0]], $MachinePrecision], Or[LessEqual[y, -15000.0], N[Not[Or[LessEqual[y, 4e+47], And[N[Not[LessEqual[y, 8e+69]], $MachinePrecision], LessEqual[y, 5.2e+160]]]], $MachinePrecision]]]], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.2 \cdot 10^{+30} \lor \neg \left(y \leq -15500\right) \land \left(y \leq -15000 \lor \neg \left(y \leq 4 \cdot 10^{+47} \lor \neg \left(y \leq 8 \cdot 10^{+69}\right) \land y \leq 5.2 \cdot 10^{+160}\right)\right):\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -9.2e30 or -15500 < y < -15000 or 4.0000000000000002e47 < y < 8.0000000000000006e69 or 5.2000000000000001e160 < y Initial program 99.9%
Taylor expanded in x around inf 71.2%
+-commutative71.2%
distribute-lft-in71.2%
unpow271.2%
associate-*l*81.2%
associate-/l*81.2%
associate-*r*72.3%
distribute-lft-out99.0%
*-commutative99.0%
Simplified99.0%
Taylor expanded in t around 0 84.3%
Taylor expanded in y around inf 75.3%
if -9.2e30 < y < -15500 or -15000 < y < 4.0000000000000002e47 or 8.0000000000000006e69 < y < 5.2000000000000001e160Initial program 99.9%
Taylor expanded in x around 0 82.6%
Final simplification79.6%
(FPCore (x y z t)
:precision binary64
(if (or (<= z -6.8e+120)
(and (not (<= z 4.8e+45)) (or (<= z 2.4e+116) (not (<= z 1.4e+139)))))
(+ t (* y z))
(+ t (* y (* x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -6.8e+120) || (!(z <= 4.8e+45) && ((z <= 2.4e+116) || !(z <= 1.4e+139)))) {
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 <= (-6.8d+120)) .or. (.not. (z <= 4.8d+45)) .and. (z <= 2.4d+116) .or. (.not. (z <= 1.4d+139))) 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 <= -6.8e+120) || (!(z <= 4.8e+45) && ((z <= 2.4e+116) || !(z <= 1.4e+139)))) {
tmp = t + (y * z);
} else {
tmp = t + (y * (x * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -6.8e+120) or (not (z <= 4.8e+45) and ((z <= 2.4e+116) or not (z <= 1.4e+139))): tmp = t + (y * z) else: tmp = t + (y * (x * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -6.8e+120) || (!(z <= 4.8e+45) && ((z <= 2.4e+116) || !(z <= 1.4e+139)))) 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 <= -6.8e+120) || (~((z <= 4.8e+45)) && ((z <= 2.4e+116) || ~((z <= 1.4e+139))))) tmp = t + (y * z); else tmp = t + (y * (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -6.8e+120], And[N[Not[LessEqual[z, 4.8e+45]], $MachinePrecision], Or[LessEqual[z, 2.4e+116], N[Not[LessEqual[z, 1.4e+139]], $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 -6.8 \cdot 10^{+120} \lor \neg \left(z \leq 4.8 \cdot 10^{+45}\right) \land \left(z \leq 2.4 \cdot 10^{+116} \lor \neg \left(z \leq 1.4 \cdot 10^{+139}\right)\right):\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -6.79999999999999998e120 or 4.79999999999999979e45 < z < 2.4e116 or 1.3999999999999999e139 < z Initial program 100.0%
Taylor expanded in x around 0 84.7%
if -6.79999999999999998e120 < z < 4.79999999999999979e45 or 2.4e116 < z < 1.3999999999999999e139Initial program 99.9%
Taylor expanded in x around inf 90.1%
*-commutative90.1%
Simplified90.1%
Final simplification88.4%
(FPCore (x y z t) :precision binary64 (if (or (<= y -9.5e+28) (not (<= y 2e-48))) (* x (* y y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -9.5e+28) || !(y <= 2e-48)) {
tmp = x * (y * 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 <= (-9.5d+28)) .or. (.not. (y <= 2d-48))) then
tmp = x * (y * 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 <= -9.5e+28) || !(y <= 2e-48)) {
tmp = x * (y * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -9.5e+28) or not (y <= 2e-48): tmp = x * (y * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -9.5e+28) || !(y <= 2e-48)) tmp = Float64(x * Float64(y * y)); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -9.5e+28) || ~((y <= 2e-48))) tmp = x * (y * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -9.5e+28], N[Not[LessEqual[y, 2e-48]], $MachinePrecision]], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{+28} \lor \neg \left(y \leq 2 \cdot 10^{-48}\right):\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -9.49999999999999927e28 or 1.9999999999999999e-48 < y Initial program 99.9%
Taylor expanded in x around inf 73.9%
+-commutative73.9%
distribute-lft-in73.3%
unpow273.3%
associate-*l*80.9%
associate-/l*80.9%
associate-*r*78.5%
distribute-lft-out97.9%
*-commutative97.9%
Simplified97.9%
Taylor expanded in t around 0 77.3%
Taylor expanded in y around inf 64.1%
if -9.49999999999999927e28 < y < 1.9999999999999999e-48Initial program 100.0%
Taylor expanded in y around 0 66.5%
Final simplification65.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%
Taylor expanded in y around 0 34.4%
herbie shell --seed 2024107
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))