
(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 (+ (+ (* x y) (* z t)) (* a b)))) (if (<= t_1 INFINITY) t_1 (fma t z (* x y)))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = ((x * y) + (z * t)) + (a * b);
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = fma(t, z, (x * y));
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) tmp = 0.0 if (t_1 <= Inf) tmp = t_1; else tmp = fma(t, z, Float64(x * y)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(x \cdot y + z \cdot t\right) + a \cdot b\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, z, x \cdot y\right)\\
\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 a around 0
accelerator-lowering-fma.f64N/A
*-lowering-*.f6480.0
Simplified80.0%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma t z (* x y))))
(if (<= (* z t) -5e+138)
t_1
(if (<= (* z t) 2e-7)
(fma a b (* x y))
(if (<= (* z t) 1e+108) t_1 (fma a b (* z t)))))))
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 ((z * t) <= -5e+138) {
tmp = t_1;
} else if ((z * t) <= 2e-7) {
tmp = fma(a, b, (x * y));
} else if ((z * t) <= 1e+108) {
tmp = t_1;
} else {
tmp = fma(a, b, (z * t));
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(t, z, Float64(x * y)) tmp = 0.0 if (Float64(z * t) <= -5e+138) tmp = t_1; elseif (Float64(z * t) <= 2e-7) tmp = fma(a, b, Float64(x * y)); elseif (Float64(z * t) <= 1e+108) tmp = t_1; else tmp = fma(a, b, Float64(z * t)); 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[(z * t), $MachinePrecision], -5e+138], t$95$1, If[LessEqual[N[(z * t), $MachinePrecision], 2e-7], N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 1e+108], t$95$1, N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(t, z, x \cdot y\right)\\
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+138}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(a, b, x \cdot y\right)\\
\mathbf{elif}\;z \cdot t \leq 10^{+108}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\end{array}
\end{array}
if (*.f64 z t) < -5.00000000000000016e138 or 1.9999999999999999e-7 < (*.f64 z t) < 1e108Initial program 96.4%
Taylor expanded in a around 0
accelerator-lowering-fma.f64N/A
*-lowering-*.f6490.4
Simplified90.4%
if -5.00000000000000016e138 < (*.f64 z t) < 1.9999999999999999e-7Initial program 99.4%
Taylor expanded in z around 0
accelerator-lowering-fma.f64N/A
*-lowering-*.f6493.1
Simplified93.1%
if 1e108 < (*.f64 z t) Initial program 95.6%
Taylor expanded in x around 0
accelerator-lowering-fma.f64N/A
*-lowering-*.f6493.8
Simplified93.8%
Final simplification92.6%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (fma a b (* z t)))) (if (<= (* z t) -2e+82) t_1 (if (<= (* z t) 5e-8) (fma a b (* x y)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(a, b, (z * t));
double tmp;
if ((z * t) <= -2e+82) {
tmp = t_1;
} else if ((z * t) <= 5e-8) {
tmp = fma(a, b, (x * y));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(a, b, Float64(z * t)) tmp = 0.0 if (Float64(z * t) <= -2e+82) tmp = t_1; elseif (Float64(z * t) <= 5e-8) tmp = fma(a, b, Float64(x * y)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * t), $MachinePrecision], -2e+82], t$95$1, If[LessEqual[N[(z * t), $MachinePrecision], 5e-8], N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+82}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{-8}:\\
\;\;\;\;\mathsf{fma}\left(a, b, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 z t) < -1.9999999999999999e82 or 4.9999999999999998e-8 < (*.f64 z t) Initial program 96.3%
Taylor expanded in x around 0
accelerator-lowering-fma.f64N/A
*-lowering-*.f6485.0
Simplified85.0%
if -1.9999999999999999e82 < (*.f64 z t) < 4.9999999999999998e-8Initial program 99.3%
Taylor expanded in z around 0
accelerator-lowering-fma.f64N/A
*-lowering-*.f6495.1
Simplified95.1%
Final simplification90.7%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -1.7e+229) (* x y) (if (<= (* x y) 1.7e+104) (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) <= -1.7e+229) {
tmp = x * y;
} else if ((x * y) <= 1.7e+104) {
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) <= -1.7e+229) tmp = Float64(x * y); elseif (Float64(x * y) <= 1.7e+104) 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], -1.7e+229], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 1.7e+104], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1.7 \cdot 10^{+229}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 1.7 \cdot 10^{+104}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -1.7e229 or 1.6999999999999998e104 < (*.f64 x y) Initial program 93.5%
Taylor expanded in x around inf
*-lowering-*.f6484.4
Simplified84.4%
if -1.7e229 < (*.f64 x y) < 1.6999999999999998e104Initial program 99.5%
Taylor expanded in x around 0
accelerator-lowering-fma.f64N/A
*-lowering-*.f6486.9
Simplified86.9%
Final simplification86.3%
(FPCore (x y z t a b) :precision binary64 (if (<= (* z t) -5e+138) (* z t) (if (<= (* z t) 2e-7) (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -5e+138) {
tmp = z * t;
} else if ((z * t) <= 2e-7) {
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 ((z * t) <= (-5d+138)) then
tmp = z * t
else if ((z * t) <= 2d-7) 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 ((z * t) <= -5e+138) {
tmp = z * t;
} else if ((z * t) <= 2e-7) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (z * t) <= -5e+138: tmp = z * t elif (z * t) <= 2e-7: tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -5e+138) tmp = Float64(z * t); elseif (Float64(z * t) <= 2e-7) 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 ((z * t) <= -5e+138) tmp = z * t; elseif ((z * t) <= 2e-7) tmp = a * b; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(z * t), $MachinePrecision], -5e+138], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 2e-7], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+138}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{-7}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -5.00000000000000016e138 or 1.9999999999999999e-7 < (*.f64 z t) Initial program 96.0%
Taylor expanded in z around inf
*-lowering-*.f6469.3
Simplified69.3%
if -5.00000000000000016e138 < (*.f64 z t) < 1.9999999999999999e-7Initial program 99.4%
Taylor expanded in a around inf
*-lowering-*.f6456.3
Simplified56.3%
Final simplification61.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 98.0%
Taylor expanded in a around inf
*-lowering-*.f6442.2
Simplified42.2%
herbie shell --seed 2024199
(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)))