
(FPCore (x y z t a b) :precision binary64 (+ (+ (* x y) (* z t)) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((x * y) + (z * t)) + (a * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
def code(x, y, z, t, a, b): return ((x * y) + (z * t)) + (a * b)
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) end
function tmp = code(x, y, z, t, a, b) tmp = ((x * y) + (z * t)) + (a * b); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + z \cdot t\right) + a \cdot b
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a b) :precision binary64 (+ (+ (* x y) (* z t)) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((x * y) + (z * t)) + (a * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
def code(x, y, z, t, a, b): return ((x * y) + (z * t)) + (a * b)
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) end
function tmp = code(x, y, z, t, a, b) tmp = ((x * y) + (z * t)) + (a * b); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + z \cdot t\right) + a \cdot b
\end{array}
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (+ (* a b) (+ (* x y) (* z t))))) (if (<= t_1 INFINITY) t_1 (+ (* x y) (* a b)))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (a * b) + ((x * y) + (z * t));
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = (x * y) + (a * b);
}
return tmp;
}
public static double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (a * b) + ((x * y) + (z * t));
double tmp;
if (t_1 <= Double.POSITIVE_INFINITY) {
tmp = t_1;
} else {
tmp = (x * y) + (a * b);
}
return tmp;
}
def code(x, y, z, t, a, b): t_1 = (a * b) + ((x * y) + (z * t)) tmp = 0 if t_1 <= math.inf: tmp = t_1 else: tmp = (x * y) + (a * b) return tmp
function code(x, y, z, t, a, b) t_1 = Float64(Float64(a * b) + Float64(Float64(x * y) + Float64(z * t))) tmp = 0.0 if (t_1 <= Inf) tmp = t_1; else tmp = Float64(Float64(x * y) + Float64(a * b)); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) t_1 = (a * b) + ((x * y) + (z * t)); tmp = 0.0; if (t_1 <= Inf) tmp = t_1; else tmp = (x * y) + (a * b); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(a * b), $MachinePrecision] + N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(N[(x * y), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := a \cdot b + \left(x \cdot y + z \cdot t\right)\\
\mathbf{if}\;t_1 \leq \infty:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;x \cdot y + a \cdot b\\
\end{array}
\end{array}
if (+.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (*.f64 a b)) < +inf.0Initial program 100.0%
if +inf.0 < (+.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (*.f64 a b)) Initial program 0.0%
Taylor expanded in x around inf 80.0%
Final simplification99.6%
(FPCore (x y z t a b) :precision binary64 (+ (fma z t (* x y)) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
return fma(z, t, (x * y)) + (a * b);
}
function code(x, y, z, t, a, b) return Float64(fma(z, t, Float64(x * y)) + Float64(a * b)) end
code[x_, y_, z_, t_, a_, b_] := N[(N[(z * t + N[(x * y), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, t, x \cdot y\right) + a \cdot b
\end{array}
Initial program 98.0%
+-commutative98.0%
fma-def99.2%
Applied egg-rr99.2%
Final simplification99.2%
(FPCore (x y z t a b) :precision binary64 (+ (* a b) (fma x y (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
return (a * b) + fma(x, y, (z * t));
}
function code(x, y, z, t, a, b) return Float64(Float64(a * b) + fma(x, y, Float64(z * t))) end
code[x_, y_, z_, t_, a_, b_] := N[(N[(a * b), $MachinePrecision] + N[(x * y + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot b + \mathsf{fma}\left(x, y, z \cdot t\right)
\end{array}
Initial program 98.0%
fma-def98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (x y z t a b)
:precision binary64
(if (or (<= (* x y) -2.6e+78)
(not
(or (<= (* x y) -1.2e+16)
(and (not (<= (* x y) -5.8e-5)) (<= (* x y) 1.3e-46)))))
(+ (* x y) (* a b))
(+ (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((x * y) <= -2.6e+78) || !(((x * y) <= -1.2e+16) || (!((x * y) <= -5.8e-5) && ((x * y) <= 1.3e-46)))) {
tmp = (x * y) + (a * b);
} else {
tmp = (a * b) + (z * t);
}
return tmp;
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (((x * y) <= (-2.6d+78)) .or. (.not. ((x * y) <= (-1.2d+16)) .or. (.not. ((x * y) <= (-5.8d-5))) .and. ((x * y) <= 1.3d-46))) then
tmp = (x * y) + (a * b)
else
tmp = (a * b) + (z * t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((x * y) <= -2.6e+78) || !(((x * y) <= -1.2e+16) || (!((x * y) <= -5.8e-5) && ((x * y) <= 1.3e-46)))) {
tmp = (x * y) + (a * b);
} else {
tmp = (a * b) + (z * t);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((x * y) <= -2.6e+78) or not (((x * y) <= -1.2e+16) or (not ((x * y) <= -5.8e-5) and ((x * y) <= 1.3e-46))): tmp = (x * y) + (a * b) else: tmp = (a * b) + (z * t) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(x * y) <= -2.6e+78) || !((Float64(x * y) <= -1.2e+16) || (!(Float64(x * y) <= -5.8e-5) && (Float64(x * y) <= 1.3e-46)))) tmp = Float64(Float64(x * y) + Float64(a * b)); else tmp = Float64(Float64(a * b) + Float64(z * t)); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (((x * y) <= -2.6e+78) || ~((((x * y) <= -1.2e+16) || (~(((x * y) <= -5.8e-5)) && ((x * y) <= 1.3e-46))))) tmp = (x * y) + (a * b); else tmp = (a * b) + (z * t); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -2.6e+78], N[Not[Or[LessEqual[N[(x * y), $MachinePrecision], -1.2e+16], And[N[Not[LessEqual[N[(x * y), $MachinePrecision], -5.8e-5]], $MachinePrecision], LessEqual[N[(x * y), $MachinePrecision], 1.3e-46]]]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2.6 \cdot 10^{+78} \lor \neg \left(x \cdot y \leq -1.2 \cdot 10^{+16} \lor \neg \left(x \cdot y \leq -5.8 \cdot 10^{-5}\right) \land x \cdot y \leq 1.3 \cdot 10^{-46}\right):\\
\;\;\;\;x \cdot y + a \cdot b\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -2.6e78 or -1.2e16 < (*.f64 x y) < -5.8e-5 or 1.3000000000000001e-46 < (*.f64 x y) Initial program 96.2%
Taylor expanded in x around inf 82.3%
if -2.6e78 < (*.f64 x y) < -1.2e16 or -5.8e-5 < (*.f64 x y) < 1.3000000000000001e-46Initial program 100.0%
Taylor expanded in x around 0 93.1%
Final simplification87.5%
(FPCore (x y z t a b) :precision binary64 (+ (* a b) (* z t)))
double code(double x, double y, double z, double t, double a, double b) {
return (a * b) + (z * t);
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (a * b) + (z * t)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return (a * b) + (z * t);
}
def code(x, y, z, t, a, b): return (a * b) + (z * t)
function code(x, y, z, t, a, b) return Float64(Float64(a * b) + Float64(z * t)) end
function tmp = code(x, y, z, t, a, b) tmp = (a * b) + (z * t); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot b + z \cdot t
\end{array}
Initial program 98.0%
Taylor expanded in x around 0 61.7%
Final simplification61.7%
(FPCore (x y z t a b) :precision binary64 (* a b))
double code(double x, double y, double z, double t, double a, double b) {
return a * b;
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = a * b
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return a * b;
}
def code(x, y, z, t, a, b): return a * b
function code(x, y, z, t, a, b) return Float64(a * b) end
function tmp = code(x, y, z, t, a, b) tmp = a * b; end
code[x_, y_, z_, t_, a_, b_] := N[(a * b), $MachinePrecision]
\begin{array}{l}
\\
a \cdot b
\end{array}
Initial program 98.0%
Taylor expanded in a around inf 30.9%
Final simplification30.9%
herbie shell --seed 2024019
(FPCore (x y z t a b)
:name "Linear.V3:$cdot from linear-1.19.1.3, B"
:precision binary64
(+ (+ (* x y) (* z t)) (* a b)))