
(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 9 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 z t (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(x, y, fma(z, t, (a * b)));
}
function code(x, y, z, t, a, b) return fma(x, y, fma(z, t, Float64(a * b))) end
code[x_, y_, z_, t_, a_, b_] := N[(x * y + N[(z * t + N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, \mathsf{fma}\left(z, t, a \cdot b\right)\right)
\end{array}
Initial program 99.2%
associate-+l+99.2%
fma-define100.0%
fma-define100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z t a b) :precision binary64 (fma a b (fma x y (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(a, b, fma(x, y, (z * t)));
}
function code(x, y, z, t, a, b) return fma(a, b, fma(x, y, Float64(z * t))) end
code[x_, y_, z_, t_, a_, b_] := N[(a * b + N[(x * y + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(a, b, \mathsf{fma}\left(x, y, z \cdot t\right)\right)
\end{array}
Initial program 99.2%
+-commutative99.2%
fma-define99.2%
fma-define99.6%
Simplified99.6%
Final simplification99.6%
(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 99.2%
fma-define99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x y z t a b)
:precision binary64
(if (or (<= (* a b) -1050000000000.0)
(and (not (<= (* a b) 5.5e+42))
(or (<= (* a b) 2.9e+90) (not (<= (* a b) 4.2e+183)))))
(* a b)
(* z t)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((a * b) <= -1050000000000.0) || (!((a * b) <= 5.5e+42) && (((a * b) <= 2.9e+90) || !((a * b) <= 4.2e+183)))) {
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) <= (-1050000000000.0d0)) .or. (.not. ((a * b) <= 5.5d+42)) .and. ((a * b) <= 2.9d+90) .or. (.not. ((a * b) <= 4.2d+183))) 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) <= -1050000000000.0) || (!((a * b) <= 5.5e+42) && (((a * b) <= 2.9e+90) || !((a * b) <= 4.2e+183)))) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((a * b) <= -1050000000000.0) or (not ((a * b) <= 5.5e+42) and (((a * b) <= 2.9e+90) or not ((a * b) <= 4.2e+183))): tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(a * b) <= -1050000000000.0) || (!(Float64(a * b) <= 5.5e+42) && ((Float64(a * b) <= 2.9e+90) || !(Float64(a * b) <= 4.2e+183)))) 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) <= -1050000000000.0) || (~(((a * b) <= 5.5e+42)) && (((a * b) <= 2.9e+90) || ~(((a * b) <= 4.2e+183))))) 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], -1050000000000.0], And[N[Not[LessEqual[N[(a * b), $MachinePrecision], 5.5e+42]], $MachinePrecision], Or[LessEqual[N[(a * b), $MachinePrecision], 2.9e+90], N[Not[LessEqual[N[(a * b), $MachinePrecision], 4.2e+183]], $MachinePrecision]]]], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1050000000000 \lor \neg \left(a \cdot b \leq 5.5 \cdot 10^{+42}\right) \land \left(a \cdot b \leq 2.9 \cdot 10^{+90} \lor \neg \left(a \cdot b \leq 4.2 \cdot 10^{+183}\right)\right):\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 a b) < -1.05e12 or 5.50000000000000001e42 < (*.f64 a b) < 2.9000000000000001e90 or 4.2e183 < (*.f64 a b) Initial program 99.1%
Taylor expanded in a around inf 68.4%
if -1.05e12 < (*.f64 a b) < 5.50000000000000001e42 or 2.9000000000000001e90 < (*.f64 a b) < 4.2e183Initial program 99.3%
Taylor expanded in z around inf 52.8%
Final simplification59.7%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* x y) -1.9e+220)
(* x y)
(if (<= (* x y) -2.8e+143)
(* a b)
(if (<= (* x y) 4.5e-150)
(* z t)
(if (<= (* x y) 2.05e+104) (* a b) (* x y))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -1.9e+220) {
tmp = x * y;
} else if ((x * y) <= -2.8e+143) {
tmp = a * b;
} else if ((x * y) <= 4.5e-150) {
tmp = z * t;
} else if ((x * y) <= 2.05e+104) {
tmp = a * b;
} 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) <= (-1.9d+220)) then
tmp = x * y
else if ((x * y) <= (-2.8d+143)) then
tmp = a * b
else if ((x * y) <= 4.5d-150) then
tmp = z * t
else if ((x * y) <= 2.05d+104) then
tmp = a * b
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) <= -1.9e+220) {
tmp = x * y;
} else if ((x * y) <= -2.8e+143) {
tmp = a * b;
} else if ((x * y) <= 4.5e-150) {
tmp = z * t;
} else if ((x * y) <= 2.05e+104) {
tmp = a * b;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -1.9e+220: tmp = x * y elif (x * y) <= -2.8e+143: tmp = a * b elif (x * y) <= 4.5e-150: tmp = z * t elif (x * y) <= 2.05e+104: tmp = a * b else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -1.9e+220) tmp = Float64(x * y); elseif (Float64(x * y) <= -2.8e+143) tmp = Float64(a * b); elseif (Float64(x * y) <= 4.5e-150) tmp = Float64(z * t); elseif (Float64(x * y) <= 2.05e+104) tmp = Float64(a * b); 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) <= -1.9e+220) tmp = x * y; elseif ((x * y) <= -2.8e+143) tmp = a * b; elseif ((x * y) <= 4.5e-150) tmp = z * t; elseif ((x * y) <= 2.05e+104) tmp = a * b; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -1.9e+220], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -2.8e+143], N[(a * b), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 4.5e-150], N[(z * t), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 2.05e+104], N[(a * b), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1.9 \cdot 10^{+220}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq -2.8 \cdot 10^{+143}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;x \cdot y \leq 4.5 \cdot 10^{-150}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;x \cdot y \leq 2.05 \cdot 10^{+104}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -1.89999999999999992e220 or 2.04999999999999992e104 < (*.f64 x y) Initial program 96.8%
Taylor expanded in x around inf 82.7%
if -1.89999999999999992e220 < (*.f64 x y) < -2.79999999999999998e143 or 4.5000000000000002e-150 < (*.f64 x y) < 2.04999999999999992e104Initial program 100.0%
Taylor expanded in a around inf 56.5%
if -2.79999999999999998e143 < (*.f64 x y) < 4.5000000000000002e-150Initial program 100.0%
Taylor expanded in z around inf 54.6%
Final simplification62.0%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -1.7e+224) (not (<= (* x y) 5.5e+105))) (* 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.7e+224) || !((x * y) <= 5.5e+105)) {
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) <= (-1.7d+224)) .or. (.not. ((x * y) <= 5.5d+105))) 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) <= -1.7e+224) || !((x * y) <= 5.5e+105)) {
tmp = x * y;
} else {
tmp = (a * b) + (z * t);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((x * y) <= -1.7e+224) or not ((x * y) <= 5.5e+105): 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) <= -1.7e+224) || !(Float64(x * y) <= 5.5e+105)) 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) <= -1.7e+224) || ~(((x * y) <= 5.5e+105))) 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], -1.7e+224], N[Not[LessEqual[N[(x * y), $MachinePrecision], 5.5e+105]], $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 -1.7 \cdot 10^{+224} \lor \neg \left(x \cdot y \leq 5.5 \cdot 10^{+105}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -1.7000000000000001e224 or 5.49999999999999979e105 < (*.f64 x y) Initial program 96.8%
Taylor expanded in x around inf 82.7%
if -1.7000000000000001e224 < (*.f64 x y) < 5.49999999999999979e105Initial program 100.0%
Taylor expanded in x around 0 84.8%
Final simplification84.3%
(FPCore (x y z t a b) :precision binary64 (if (or (<= t -5.8e-168) (not (<= t 8.8e-11))) (+ (* a b) (* z t)) (+ (* a b) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((t <= -5.8e-168) || !(t <= 8.8e-11)) {
tmp = (a * b) + (z * t);
} else {
tmp = (a * b) + (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 ((t <= (-5.8d-168)) .or. (.not. (t <= 8.8d-11))) then
tmp = (a * b) + (z * t)
else
tmp = (a * b) + (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 ((t <= -5.8e-168) || !(t <= 8.8e-11)) {
tmp = (a * b) + (z * t);
} else {
tmp = (a * b) + (x * y);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (t <= -5.8e-168) or not (t <= 8.8e-11): tmp = (a * b) + (z * t) else: tmp = (a * b) + (x * y) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((t <= -5.8e-168) || !(t <= 8.8e-11)) tmp = Float64(Float64(a * b) + Float64(z * t)); else tmp = Float64(Float64(a * b) + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((t <= -5.8e-168) || ~((t <= 8.8e-11))) tmp = (a * b) + (z * t); else tmp = (a * b) + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[t, -5.8e-168], N[Not[LessEqual[t, 8.8e-11]], $MachinePrecision]], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(N[(a * b), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -5.8 \cdot 10^{-168} \lor \neg \left(t \leq 8.8 \cdot 10^{-11}\right):\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + x \cdot y\\
\end{array}
\end{array}
if t < -5.7999999999999997e-168 or 8.8000000000000006e-11 < t Initial program 99.4%
Taylor expanded in x around 0 78.6%
if -5.7999999999999997e-168 < t < 8.8000000000000006e-11Initial program 99.0%
Taylor expanded in z around 0 90.0%
Final simplification82.9%
(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 36.3%
Final simplification36.3%
herbie shell --seed 2024044
(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)))