
(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 z t (fma x y (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(z, t, fma(x, y, (a * b)));
}
function code(x, y, z, t, a, b) return fma(z, t, fma(x, y, Float64(a * b))) end
code[x_, y_, z_, t_, a_, b_] := N[(z * t + N[(x * y + N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, t, \mathsf{fma}\left(x, y, a \cdot b\right)\right)
\end{array}
Initial program 96.9%
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
lower-fma.f6498.4
Applied egg-rr98.4%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* x y) -2.2e+44)
(* x y)
(if (<= (* x y) -2.8e-229)
(* a b)
(if (<= (* x y) 3.8e+82) (* z t) (* x y)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -2.2e+44) {
tmp = x * y;
} else if ((x * y) <= -2.8e-229) {
tmp = a * b;
} else if ((x * y) <= 3.8e+82) {
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.2d+44)) then
tmp = x * y
else if ((x * y) <= (-2.8d-229)) then
tmp = a * b
else if ((x * y) <= 3.8d+82) 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.2e+44) {
tmp = x * y;
} else if ((x * y) <= -2.8e-229) {
tmp = a * b;
} else if ((x * y) <= 3.8e+82) {
tmp = z * t;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -2.2e+44: tmp = x * y elif (x * y) <= -2.8e-229: tmp = a * b elif (x * y) <= 3.8e+82: 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.2e+44) tmp = Float64(x * y); elseif (Float64(x * y) <= -2.8e-229) tmp = Float64(a * b); elseif (Float64(x * y) <= 3.8e+82) 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.2e+44) tmp = x * y; elseif ((x * y) <= -2.8e-229) tmp = a * b; elseif ((x * y) <= 3.8e+82) 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.2e+44], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -2.8e-229], N[(a * b), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 3.8e+82], N[(z * t), $MachinePrecision], N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2.2 \cdot 10^{+44}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq -2.8 \cdot 10^{-229}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;x \cdot y \leq 3.8 \cdot 10^{+82}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -2.19999999999999996e44 or 3.80000000000000033e82 < (*.f64 x y) Initial program 94.0%
Taylor expanded in x around inf
lower-*.f6469.7
Simplified69.7%
if -2.19999999999999996e44 < (*.f64 x y) < -2.7999999999999999e-229Initial program 100.0%
Taylor expanded in a around inf
lower-*.f6455.3
Simplified55.3%
if -2.7999999999999999e-229 < (*.f64 x y) < 3.80000000000000033e82Initial program 98.1%
Taylor expanded in z around inf
lower-*.f6459.5
Simplified59.5%
Final simplification62.7%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -1e+38) (fma y x (* a b)) (if (<= (* a b) 2e+50) (fma t z (* x y)) (fma a b (* z t)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -1e+38) {
tmp = fma(y, x, (a * b));
} else if ((a * b) <= 2e+50) {
tmp = fma(t, z, (x * y));
} else {
tmp = fma(a, b, (z * t));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -1e+38) tmp = fma(y, x, Float64(a * b)); elseif (Float64(a * b) <= 2e+50) tmp = fma(t, z, Float64(x * y)); else tmp = fma(a, b, Float64(z * t)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -1e+38], N[(y * x + N[(a * b), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2e+50], N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1 \cdot 10^{+38}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{+50}:\\
\;\;\;\;\mathsf{fma}\left(t, z, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\end{array}
\end{array}
if (*.f64 a b) < -9.99999999999999977e37Initial program 90.7%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6484.3
Simplified84.3%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6489.0
Applied egg-rr89.0%
if -9.99999999999999977e37 < (*.f64 a b) < 2.0000000000000002e50Initial program 99.3%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-*.f6491.7
Simplified91.7%
if 2.0000000000000002e50 < (*.f64 a b) Initial program 95.5%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6489.9
Simplified89.9%
Final simplification90.7%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma t z (* x y))))
(if (<= (* x y) -2.2e+44)
t_1
(if (<= (* x y) 40000000000.0) (fma a b (* z t)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(t, z, (x * y));
double tmp;
if ((x * y) <= -2.2e+44) {
tmp = t_1;
} else if ((x * y) <= 40000000000.0) {
tmp = fma(a, b, (z * t));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(t, z, Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -2.2e+44) tmp = t_1; elseif (Float64(x * y) <= 40000000000.0) tmp = fma(a, b, Float64(z * t)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -2.2e+44], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 40000000000.0], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(t, z, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -2.2 \cdot 10^{+44}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 40000000000:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -2.19999999999999996e44 or 4e10 < (*.f64 x y) Initial program 94.2%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-*.f6485.0
Simplified85.0%
if -2.19999999999999996e44 < (*.f64 x y) < 4e10Initial program 99.2%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6494.6
Simplified94.6%
Final simplification90.0%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -3.4e+178) (* x y) (if (<= (* x y) 3.8e+82) (fma a b (* z t)) (fma a b (* x y)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -3.4e+178) {
tmp = x * y;
} else if ((x * y) <= 3.8e+82) {
tmp = fma(a, b, (z * t));
} else {
tmp = fma(a, b, (x * y));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -3.4e+178) tmp = Float64(x * y); elseif (Float64(x * y) <= 3.8e+82) tmp = fma(a, b, Float64(z * t)); else tmp = fma(a, b, Float64(x * y)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -3.4e+178], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 3.8e+82], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -3.4 \cdot 10^{+178}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 3.8 \cdot 10^{+82}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, b, x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -3.4000000000000003e178Initial program 90.9%
Taylor expanded in x around inf
lower-*.f6488.3
Simplified88.3%
if -3.4000000000000003e178 < (*.f64 x y) < 3.80000000000000033e82Initial program 98.8%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6489.9
Simplified89.9%
if 3.80000000000000033e82 < (*.f64 x y) Initial program 93.6%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6483.6
Simplified83.6%
Final simplification88.5%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -3.4e+178) (* x y) (if (<= (* x y) 6e+195) (fma a b (* z t)) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -3.4e+178) {
tmp = x * y;
} else if ((x * y) <= 6e+195) {
tmp = fma(a, b, (z * t));
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -3.4e+178) tmp = Float64(x * y); elseif (Float64(x * y) <= 6e+195) tmp = fma(a, b, Float64(z * t)); else tmp = Float64(x * y); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -3.4e+178], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 6e+195], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -3.4 \cdot 10^{+178}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 6 \cdot 10^{+195}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -3.4000000000000003e178 or 6.0000000000000001e195 < (*.f64 x y) Initial program 91.3%
Taylor expanded in x around inf
lower-*.f6484.7
Simplified84.7%
if -3.4000000000000003e178 < (*.f64 x y) < 6.0000000000000001e195Initial program 98.9%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6487.9
Simplified87.9%
Final simplification87.0%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -1.4e+28) (* a b) (if (<= (* a b) 1.9e+99) (* z t) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -1.4e+28) {
tmp = a * b;
} else if ((a * b) <= 1.9e+99) {
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.4d+28)) then
tmp = a * b
else if ((a * b) <= 1.9d+99) 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.4e+28) {
tmp = a * b;
} else if ((a * b) <= 1.9e+99) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -1.4e+28: tmp = a * b elif (a * b) <= 1.9e+99: 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.4e+28) tmp = Float64(a * b); elseif (Float64(a * b) <= 1.9e+99) 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.4e+28) tmp = a * b; elseif ((a * b) <= 1.9e+99) 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.4e+28], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1.9e+99], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1.4 \cdot 10^{+28}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 1.9 \cdot 10^{+99}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -1.4000000000000001e28 or 1.9e99 < (*.f64 a b) Initial program 92.8%
Taylor expanded in a around inf
lower-*.f6470.6
Simplified70.6%
if -1.4000000000000001e28 < (*.f64 a b) < 1.9e99Initial program 99.3%
Taylor expanded in z around inf
lower-*.f6454.2
Simplified54.2%
Final simplification60.5%
(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 96.9%
Taylor expanded in a around inf
lower-*.f6434.0
Simplified34.0%
herbie shell --seed 2024208
(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)))