
(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 8 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 (fma x y (fma a b (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(x, y, fma(a, b, (z * t)));
}
function code(x, y, z, t, a, b) return fma(x, y, fma(a, b, Float64(z * t))) end
code[x_, y_, z_, t_, a_, b_] := N[(x * y + N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, z \cdot t\right)\right)
\end{array}
Initial program 99.2%
associate-+l+99.2%
fma-def99.2%
+-commutative99.2%
fma-def99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x y z t a b) :precision binary64 (+ (fma x y (* z t)) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
return fma(x, y, (z * t)) + (a * b);
}
function code(x, y, z, t, a, b) return Float64(fma(x, y, Float64(z * t)) + Float64(a * b)) end
code[x_, y_, z_, t_, a_, b_] := N[(N[(x * y + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, z \cdot t\right) + a \cdot b
\end{array}
Initial program 99.2%
fma-def99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* x y) -2.7e+115)
(* x y)
(if (<= (* x y) -9.2e+20)
(* a b)
(if (<= (* x y) -1.65e-39)
(* z t)
(if (<= (* x y) -4.1e-69)
(* a b)
(if (<= (* x y) -4.45e-116)
(* z t)
(if (<= (* x y) -4e-320)
(* a b)
(if (<= (* x y) 2.4e+24) (* z t) (* x y)))))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -2.7e+115) {
tmp = x * y;
} else if ((x * y) <= -9.2e+20) {
tmp = a * b;
} else if ((x * y) <= -1.65e-39) {
tmp = z * t;
} else if ((x * y) <= -4.1e-69) {
tmp = a * b;
} else if ((x * y) <= -4.45e-116) {
tmp = z * t;
} else if ((x * y) <= -4e-320) {
tmp = a * b;
} else if ((x * y) <= 2.4e+24) {
tmp = z * t;
} else {
tmp = x * y;
}
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.7d+115)) then
tmp = x * y
else if ((x * y) <= (-9.2d+20)) then
tmp = a * b
else if ((x * y) <= (-1.65d-39)) then
tmp = z * t
else if ((x * y) <= (-4.1d-69)) then
tmp = a * b
else if ((x * y) <= (-4.45d-116)) then
tmp = z * t
else if ((x * y) <= (-4d-320)) then
tmp = a * b
else if ((x * y) <= 2.4d+24) then
tmp = z * t
else
tmp = x * y
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.7e+115) {
tmp = x * y;
} else if ((x * y) <= -9.2e+20) {
tmp = a * b;
} else if ((x * y) <= -1.65e-39) {
tmp = z * t;
} else if ((x * y) <= -4.1e-69) {
tmp = a * b;
} else if ((x * y) <= -4.45e-116) {
tmp = z * t;
} else if ((x * y) <= -4e-320) {
tmp = a * b;
} else if ((x * y) <= 2.4e+24) {
tmp = z * t;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -2.7e+115: tmp = x * y elif (x * y) <= -9.2e+20: tmp = a * b elif (x * y) <= -1.65e-39: tmp = z * t elif (x * y) <= -4.1e-69: tmp = a * b elif (x * y) <= -4.45e-116: tmp = z * t elif (x * y) <= -4e-320: tmp = a * b elif (x * y) <= 2.4e+24: tmp = z * t else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -2.7e+115) tmp = Float64(x * y); elseif (Float64(x * y) <= -9.2e+20) tmp = Float64(a * b); elseif (Float64(x * y) <= -1.65e-39) tmp = Float64(z * t); elseif (Float64(x * y) <= -4.1e-69) tmp = Float64(a * b); elseif (Float64(x * y) <= -4.45e-116) tmp = Float64(z * t); elseif (Float64(x * y) <= -4e-320) tmp = Float64(a * b); elseif (Float64(x * y) <= 2.4e+24) tmp = Float64(z * t); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((x * y) <= -2.7e+115) tmp = x * y; elseif ((x * y) <= -9.2e+20) tmp = a * b; elseif ((x * y) <= -1.65e-39) tmp = z * t; elseif ((x * y) <= -4.1e-69) tmp = a * b; elseif ((x * y) <= -4.45e-116) tmp = z * t; elseif ((x * y) <= -4e-320) tmp = a * b; elseif ((x * y) <= 2.4e+24) tmp = z * t; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -2.7e+115], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -9.2e+20], N[(a * b), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -1.65e-39], N[(z * t), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -4.1e-69], N[(a * b), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -4.45e-116], N[(z * t), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -4e-320], N[(a * b), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 2.4e+24], N[(z * t), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2.7 \cdot 10^{+115}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq -9.2 \cdot 10^{+20}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;x \cdot y \leq -1.65 \cdot 10^{-39}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;x \cdot y \leq -4.1 \cdot 10^{-69}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;x \cdot y \leq -4.45 \cdot 10^{-116}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;x \cdot y \leq -4 \cdot 10^{-320}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;x \cdot y \leq 2.4 \cdot 10^{+24}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -2.70000000000000004e115 or 2.4000000000000001e24 < (*.f64 x y) Initial program 97.5%
Taylor expanded in x around inf 89.1%
Taylor expanded in x around inf 70.6%
if -2.70000000000000004e115 < (*.f64 x y) < -9.2e20 or -1.64999999999999992e-39 < (*.f64 x y) < -4.0999999999999999e-69 or -4.45000000000000016e-116 < (*.f64 x y) < -3.99996e-320Initial program 100.0%
Taylor expanded in a around inf 60.7%
if -9.2e20 < (*.f64 x y) < -1.64999999999999992e-39 or -4.0999999999999999e-69 < (*.f64 x y) < -4.45000000000000016e-116 or -3.99996e-320 < (*.f64 x y) < 2.4000000000000001e24Initial program 100.0%
Taylor expanded in x around 0 90.0%
Taylor expanded in t around inf 62.2%
Final simplification64.6%
(FPCore (x y z t a b)
:precision binary64
(if (or (<= (* a b) -4.6e+60)
(not
(or (<= (* a b) 3.05e+28)
(and (not (<= (* a b) 6.5e+69)) (<= (* a b) 6e+95)))))
(* a b)
(* z t)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((a * b) <= -4.6e+60) || !(((a * b) <= 3.05e+28) || (!((a * b) <= 6.5e+69) && ((a * b) <= 6e+95)))) {
tmp = a * b;
} else {
tmp = 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 (((a * b) <= (-4.6d+60)) .or. (.not. ((a * b) <= 3.05d+28) .or. (.not. ((a * b) <= 6.5d+69)) .and. ((a * b) <= 6d+95))) then
tmp = a * b
else
tmp = 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 (((a * b) <= -4.6e+60) || !(((a * b) <= 3.05e+28) || (!((a * b) <= 6.5e+69) && ((a * b) <= 6e+95)))) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((a * b) <= -4.6e+60) or not (((a * b) <= 3.05e+28) or (not ((a * b) <= 6.5e+69) and ((a * b) <= 6e+95))): tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(a * b) <= -4.6e+60) || !((Float64(a * b) <= 3.05e+28) || (!(Float64(a * b) <= 6.5e+69) && (Float64(a * b) <= 6e+95)))) tmp = Float64(a * b); else tmp = Float64(z * t); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (((a * b) <= -4.6e+60) || ~((((a * b) <= 3.05e+28) || (~(((a * b) <= 6.5e+69)) && ((a * b) <= 6e+95))))) tmp = a * b; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(a * b), $MachinePrecision], -4.6e+60], N[Not[Or[LessEqual[N[(a * b), $MachinePrecision], 3.05e+28], And[N[Not[LessEqual[N[(a * b), $MachinePrecision], 6.5e+69]], $MachinePrecision], LessEqual[N[(a * b), $MachinePrecision], 6e+95]]]], $MachinePrecision]], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -4.6 \cdot 10^{+60} \lor \neg \left(a \cdot b \leq 3.05 \cdot 10^{+28} \lor \neg \left(a \cdot b \leq 6.5 \cdot 10^{+69}\right) \land a \cdot b \leq 6 \cdot 10^{+95}\right):\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 a b) < -4.60000000000000034e60 or 3.0500000000000001e28 < (*.f64 a b) < 6.5000000000000001e69 or 5.99999999999999982e95 < (*.f64 a b) Initial program 99.0%
Taylor expanded in a around inf 70.8%
if -4.60000000000000034e60 < (*.f64 a b) < 3.0500000000000001e28 or 6.5000000000000001e69 < (*.f64 a b) < 5.99999999999999982e95Initial program 99.3%
Taylor expanded in x around 0 58.6%
Taylor expanded in t around inf 49.3%
Final simplification57.8%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -3.4e+116) (not (<= (* x y) 7.5e+174))) (* x y) (+ (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((x * y) <= -3.4e+116) || !((x * y) <= 7.5e+174)) {
tmp = x * y;
} 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) <= (-3.4d+116)) .or. (.not. ((x * y) <= 7.5d+174))) then
tmp = x * y
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) <= -3.4e+116) || !((x * y) <= 7.5e+174)) {
tmp = x * y;
} else {
tmp = (a * b) + (z * t);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((x * y) <= -3.4e+116) or not ((x * y) <= 7.5e+174): tmp = x * y else: tmp = (a * b) + (z * t) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(x * y) <= -3.4e+116) || !(Float64(x * y) <= 7.5e+174)) tmp = Float64(x * y); 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) <= -3.4e+116) || ~(((x * y) <= 7.5e+174))) tmp = x * y; 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], -3.4e+116], N[Not[LessEqual[N[(x * y), $MachinePrecision], 7.5e+174]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -3.4 \cdot 10^{+116} \lor \neg \left(x \cdot y \leq 7.5 \cdot 10^{+174}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -3.40000000000000023e116 or 7.5000000000000004e174 < (*.f64 x y) Initial program 96.7%
Taylor expanded in x around inf 91.5%
Taylor expanded in x around inf 82.7%
if -3.40000000000000023e116 < (*.f64 x y) < 7.5000000000000004e174Initial program 100.0%
Taylor expanded in x around 0 84.3%
Final simplification83.9%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -1.55e+25) (not (<= (* x y) 1.65e+24))) (+ (* a b) (* x y)) (+ (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((x * y) <= -1.55e+25) || !((x * y) <= 1.65e+24)) {
tmp = (a * b) + (x * y);
} 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) <= (-1.55d+25)) .or. (.not. ((x * y) <= 1.65d+24))) then
tmp = (a * b) + (x * y)
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) <= -1.55e+25) || !((x * y) <= 1.65e+24)) {
tmp = (a * b) + (x * y);
} else {
tmp = (a * b) + (z * t);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((x * y) <= -1.55e+25) or not ((x * y) <= 1.65e+24): tmp = (a * b) + (x * y) else: tmp = (a * b) + (z * t) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(x * y) <= -1.55e+25) || !(Float64(x * y) <= 1.65e+24)) tmp = Float64(Float64(a * b) + Float64(x * y)); 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) <= -1.55e+25) || ~(((x * y) <= 1.65e+24))) tmp = (a * b) + (x * y); 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], -1.55e+25], N[Not[LessEqual[N[(x * y), $MachinePrecision], 1.65e+24]], $MachinePrecision]], N[(N[(a * b), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1.55 \cdot 10^{+25} \lor \neg \left(x \cdot y \leq 1.65 \cdot 10^{+24}\right):\\
\;\;\;\;a \cdot b + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -1.5499999999999999e25 or 1.6499999999999999e24 < (*.f64 x y) Initial program 97.9%
Taylor expanded in x around inf 89.8%
if -1.5499999999999999e25 < (*.f64 x y) < 1.6499999999999999e24Initial program 100.0%
Taylor expanded in x around 0 89.7%
Final simplification89.8%
(FPCore (x y z t a b) :precision binary64 (+ (* a b) (+ (* x y) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
return (a * b) + ((x * y) + (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) + ((x * y) + (z * t))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return (a * b) + ((x * y) + (z * t));
}
def code(x, y, z, t, a, b): return (a * b) + ((x * y) + (z * t))
function code(x, y, z, t, a, b) return Float64(Float64(a * b) + Float64(Float64(x * y) + Float64(z * t))) end
function tmp = code(x, y, z, t, a, b) tmp = (a * b) + ((x * y) + (z * t)); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(a * b), $MachinePrecision] + N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot b + \left(x \cdot y + z \cdot t\right)
\end{array}
Initial program 99.2%
Final simplification99.2%
(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 99.2%
Taylor expanded in a around inf 34.9%
Final simplification34.9%
herbie shell --seed 2023322
(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)))