
(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 7 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 b a (fma t z (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(b, a, fma(t, z, (x * y)));
}
function code(x, y, z, t, a, b) return fma(b, a, fma(t, z, Float64(x * y))) end
code[x_, y_, z_, t_, a_, b_] := N[(b * a + N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(b, a, \mathsf{fma}\left(t, z, x \cdot y\right)\right)
\end{array}
Initial program 95.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6497.3
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6498.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.4
Applied rewrites98.4%
Final simplification98.4%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* z t) -1.25e+71)
(* z t)
(if (<= (* z t) 4.6e-60)
(* x y)
(if (<= (* z t) 5.5e+126) (* a b) (* z t)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -1.25e+71) {
tmp = z * t;
} else if ((z * t) <= 4.6e-60) {
tmp = x * y;
} else if ((z * t) <= 5.5e+126) {
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) <= (-1.25d+71)) then
tmp = z * t
else if ((z * t) <= 4.6d-60) then
tmp = x * y
else if ((z * t) <= 5.5d+126) 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) <= -1.25e+71) {
tmp = z * t;
} else if ((z * t) <= 4.6e-60) {
tmp = x * y;
} else if ((z * t) <= 5.5e+126) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (z * t) <= -1.25e+71: tmp = z * t elif (z * t) <= 4.6e-60: tmp = x * y elif (z * t) <= 5.5e+126: tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -1.25e+71) tmp = Float64(z * t); elseif (Float64(z * t) <= 4.6e-60) tmp = Float64(x * y); elseif (Float64(z * t) <= 5.5e+126) 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) <= -1.25e+71) tmp = z * t; elseif ((z * t) <= 4.6e-60) tmp = x * y; elseif ((z * t) <= 5.5e+126) 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], -1.25e+71], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 4.6e-60], N[(x * y), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 5.5e+126], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -1.25 \cdot 10^{+71}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq 4.6 \cdot 10^{-60}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;z \cdot t \leq 5.5 \cdot 10^{+126}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -1.24999999999999993e71 or 5.5000000000000004e126 < (*.f64 z t) Initial program 91.8%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f6472.1
Applied rewrites72.1%
if -1.24999999999999993e71 < (*.f64 z t) < 4.6000000000000003e-60Initial program 97.6%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6456.2
Applied rewrites56.2%
if 4.6000000000000003e-60 < (*.f64 z t) < 5.5000000000000004e126Initial program 99.9%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6457.7
Applied rewrites57.7%
Final simplification62.4%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -1e+134) (fma b a (* x y)) (if (<= (* a b) 2e+116) (fma y x (* z t)) (fma b a (* z t)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -1e+134) {
tmp = fma(b, a, (x * y));
} else if ((a * b) <= 2e+116) {
tmp = fma(y, x, (z * t));
} else {
tmp = fma(b, a, (z * t));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -1e+134) tmp = fma(b, a, Float64(x * y)); elseif (Float64(a * b) <= 2e+116) tmp = fma(y, x, Float64(z * t)); else tmp = fma(b, a, Float64(z * t)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -1e+134], N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2e+116], N[(y * x + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(b * a + N[(z * t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1 \cdot 10^{+134}:\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\
\mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{+116}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, z \cdot t\right)\\
\end{array}
\end{array}
if (*.f64 a b) < -9.99999999999999921e133Initial program 89.3%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6493.0
Applied rewrites93.0%
if -9.99999999999999921e133 < (*.f64 a b) < 2.00000000000000003e116Initial program 98.9%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6488.4
Applied rewrites88.4%
if 2.00000000000000003e116 < (*.f64 a b) Initial program 88.2%
Taylor expanded in y around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6490.2
Applied rewrites90.2%
Final simplification89.3%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma b a (* z t))))
(if (<= (* z t) -1.15e+71)
t_1
(if (<= (* z t) 1.45e-5) (fma b a (* x y)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(b, a, (z * t));
double tmp;
if ((z * t) <= -1.15e+71) {
tmp = t_1;
} else if ((z * t) <= 1.45e-5) {
tmp = fma(b, a, (x * y));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(b, a, Float64(z * t)) tmp = 0.0 if (Float64(z * t) <= -1.15e+71) tmp = t_1; elseif (Float64(z * t) <= 1.45e-5) tmp = fma(b, a, Float64(x * y)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(b * a + N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * t), $MachinePrecision], -1.15e+71], t$95$1, If[LessEqual[N[(z * t), $MachinePrecision], 1.45e-5], N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(b, a, z \cdot t\right)\\
\mathbf{if}\;z \cdot t \leq -1.15 \cdot 10^{+71}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \cdot t \leq 1.45 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 z t) < -1.1500000000000001e71 or 1.45e-5 < (*.f64 z t) Initial program 93.4%
Taylor expanded in y around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6487.8
Applied rewrites87.8%
if -1.1500000000000001e71 < (*.f64 z t) < 1.45e-5Initial program 97.8%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6489.5
Applied rewrites89.5%
Final simplification88.7%
(FPCore (x y z t a b) :precision binary64 (if (<= (* z t) -3.15e+128) (* z t) (if (<= (* z t) 1.06e+127) (fma b a (* x y)) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -3.15e+128) {
tmp = z * t;
} else if ((z * t) <= 1.06e+127) {
tmp = fma(b, a, (x * y));
} else {
tmp = z * t;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -3.15e+128) tmp = Float64(z * t); elseif (Float64(z * t) <= 1.06e+127) tmp = fma(b, a, Float64(x * y)); else tmp = Float64(z * t); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(z * t), $MachinePrecision], -3.15e+128], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 1.06e+127], N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(z * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -3.15 \cdot 10^{+128}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq 1.06 \cdot 10^{+127}:\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -3.1499999999999999e128 or 1.06000000000000006e127 < (*.f64 z t) Initial program 90.5%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f6477.1
Applied rewrites77.1%
if -3.1499999999999999e128 < (*.f64 z t) < 1.06000000000000006e127Initial program 98.2%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6484.4
Applied rewrites84.4%
Final simplification82.0%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -5e+27) (* x y) (if (<= (* x y) 4e+50) (* a b) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -5e+27) {
tmp = x * y;
} else if ((x * y) <= 4e+50) {
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) <= (-5d+27)) then
tmp = x * y
else if ((x * y) <= 4d+50) 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) <= -5e+27) {
tmp = x * y;
} else if ((x * y) <= 4e+50) {
tmp = a * b;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -5e+27: tmp = x * y elif (x * y) <= 4e+50: tmp = a * b else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -5e+27) tmp = Float64(x * y); elseif (Float64(x * y) <= 4e+50) 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) <= -5e+27) tmp = x * y; elseif ((x * y) <= 4e+50) 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], -5e+27], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 4e+50], N[(a * b), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+27}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 4 \cdot 10^{+50}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -4.99999999999999979e27 or 4.0000000000000003e50 < (*.f64 x y) Initial program 92.2%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6467.0
Applied rewrites67.0%
if -4.99999999999999979e27 < (*.f64 x y) < 4.0000000000000003e50Initial program 98.6%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6444.4
Applied rewrites44.4%
Final simplification54.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 95.7%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6432.0
Applied rewrites32.0%
Final simplification32.0%
herbie shell --seed 2024236
(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)))