
(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 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 98.4%
+-commutative98.4%
fma-define99.2%
fma-define99.2%
Simplified99.2%
(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 98.4%
fma-define98.4%
Simplified98.4%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* a b) -1.35e+179)
(* a b)
(if (<= (* a b) -3e+30)
(* z t)
(if (<= (* a b) 4.1e-32)
(* x y)
(if (<= (* a b) 1.65e+68) (* z t) (* a b))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -1.35e+179) {
tmp = a * b;
} else if ((a * b) <= -3e+30) {
tmp = z * t;
} else if ((a * b) <= 4.1e-32) {
tmp = x * y;
} else if ((a * b) <= 1.65e+68) {
tmp = z * t;
} else {
tmp = a * b;
}
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) <= (-1.35d+179)) then
tmp = a * b
else if ((a * b) <= (-3d+30)) then
tmp = z * t
else if ((a * b) <= 4.1d-32) then
tmp = x * y
else if ((a * b) <= 1.65d+68) then
tmp = z * t
else
tmp = a * b
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) <= -1.35e+179) {
tmp = a * b;
} else if ((a * b) <= -3e+30) {
tmp = z * t;
} else if ((a * b) <= 4.1e-32) {
tmp = x * y;
} else if ((a * b) <= 1.65e+68) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -1.35e+179: tmp = a * b elif (a * b) <= -3e+30: tmp = z * t elif (a * b) <= 4.1e-32: tmp = x * y elif (a * b) <= 1.65e+68: tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -1.35e+179) tmp = Float64(a * b); elseif (Float64(a * b) <= -3e+30) tmp = Float64(z * t); elseif (Float64(a * b) <= 4.1e-32) tmp = Float64(x * y); elseif (Float64(a * b) <= 1.65e+68) tmp = Float64(z * t); else tmp = Float64(a * b); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((a * b) <= -1.35e+179) tmp = a * b; elseif ((a * b) <= -3e+30) tmp = z * t; elseif ((a * b) <= 4.1e-32) tmp = x * y; elseif ((a * b) <= 1.65e+68) tmp = z * t; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -1.35e+179], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -3e+30], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 4.1e-32], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1.65e+68], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1.35 \cdot 10^{+179}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq -3 \cdot 10^{+30}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;a \cdot b \leq 4.1 \cdot 10^{-32}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;a \cdot b \leq 1.65 \cdot 10^{+68}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -1.34999999999999991e179 or 1.65e68 < (*.f64 a b) Initial program 96.5%
fma-define96.5%
Simplified96.5%
Taylor expanded in a around inf 79.3%
if -1.34999999999999991e179 < (*.f64 a b) < -2.99999999999999978e30 or 4.09999999999999975e-32 < (*.f64 a b) < 1.65e68Initial program 97.4%
fma-define97.4%
Simplified97.4%
Taylor expanded in x around 0 79.1%
Taylor expanded in a around 0 69.2%
if -2.99999999999999978e30 < (*.f64 a b) < 4.09999999999999975e-32Initial program 100.0%
Taylor expanded in x around inf 62.0%
Taylor expanded in x around inf 54.9%
Final simplification65.4%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -4e-12) (not (<= (* x y) 5e+88))) (+ (* 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) <= -4e-12) || !((x * y) <= 5e+88)) {
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) <= (-4d-12)) .or. (.not. ((x * y) <= 5d+88))) 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) <= -4e-12) || !((x * y) <= 5e+88)) {
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) <= -4e-12) or not ((x * y) <= 5e+88): 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) <= -4e-12) || !(Float64(x * y) <= 5e+88)) 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) <= -4e-12) || ~(((x * y) <= 5e+88))) 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], -4e-12], N[Not[LessEqual[N[(x * y), $MachinePrecision], 5e+88]], $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 -4 \cdot 10^{-12} \lor \neg \left(x \cdot y \leq 5 \cdot 10^{+88}\right):\\
\;\;\;\;a \cdot b + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -3.99999999999999992e-12 or 4.99999999999999997e88 < (*.f64 x y) Initial program 99.0%
Taylor expanded in x around inf 85.5%
if -3.99999999999999992e-12 < (*.f64 x y) < 4.99999999999999997e88Initial program 97.9%
fma-define97.9%
Simplified97.9%
Taylor expanded in x around 0 87.7%
Final simplification86.8%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -8.2e+49) (not (<= (* x y) 6.5e+98))) (* 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) <= -8.2e+49) || !((x * y) <= 6.5e+98)) {
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) <= (-8.2d+49)) .or. (.not. ((x * y) <= 6.5d+98))) 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) <= -8.2e+49) || !((x * y) <= 6.5e+98)) {
tmp = x * y;
} else {
tmp = (a * b) + (z * t);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((x * y) <= -8.2e+49) or not ((x * y) <= 6.5e+98): 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) <= -8.2e+49) || !(Float64(x * y) <= 6.5e+98)) 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) <= -8.2e+49) || ~(((x * y) <= 6.5e+98))) 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], -8.2e+49], N[Not[LessEqual[N[(x * y), $MachinePrecision], 6.5e+98]], $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 -8.2 \cdot 10^{+49} \lor \neg \left(x \cdot y \leq 6.5 \cdot 10^{+98}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -8.2e49 or 6.4999999999999999e98 < (*.f64 x y) Initial program 98.8%
Taylor expanded in x around inf 87.9%
Taylor expanded in x around inf 78.1%
if -8.2e49 < (*.f64 x y) < 6.4999999999999999e98Initial program 98.2%
fma-define98.2%
Simplified98.2%
Taylor expanded in x around 0 84.5%
Final simplification82.3%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* a b) -1.35e+179) (not (<= (* a b) 6.2e+71))) (* a b) (* z t)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((a * b) <= -1.35e+179) || !((a * b) <= 6.2e+71)) {
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) <= (-1.35d+179)) .or. (.not. ((a * b) <= 6.2d+71))) 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) <= -1.35e+179) || !((a * b) <= 6.2e+71)) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((a * b) <= -1.35e+179) or not ((a * b) <= 6.2e+71): tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(a * b) <= -1.35e+179) || !(Float64(a * b) <= 6.2e+71)) 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) <= -1.35e+179) || ~(((a * b) <= 6.2e+71))) 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], -1.35e+179], N[Not[LessEqual[N[(a * b), $MachinePrecision], 6.2e+71]], $MachinePrecision]], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1.35 \cdot 10^{+179} \lor \neg \left(a \cdot b \leq 6.2 \cdot 10^{+71}\right):\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 a b) < -1.34999999999999991e179 or 6.20000000000000036e71 < (*.f64 a b) Initial program 96.5%
fma-define96.5%
Simplified96.5%
Taylor expanded in a around inf 79.3%
if -1.34999999999999991e179 < (*.f64 a b) < 6.20000000000000036e71Initial program 99.4%
fma-define99.4%
Simplified99.4%
Taylor expanded in x around 0 56.0%
Taylor expanded in a around 0 49.0%
Final simplification59.2%
(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 98.4%
Final simplification98.4%
(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.4%
fma-define98.4%
Simplified98.4%
Taylor expanded in a around inf 33.2%
herbie shell --seed 2024129
(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)))