
(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 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 98.8%
associate-+l+98.8%
fma-def99.6%
fma-def99.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 98.8%
fma-def99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* a b) -8e-133)
(* a b)
(if (or (<= (* a b) 4e-22)
(and (not (<= (* a b) 1.9e+69)) (<= (* a b) 8.8e+175)))
(* z t)
(* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -8e-133) {
tmp = a * b;
} else if (((a * b) <= 4e-22) || (!((a * b) <= 1.9e+69) && ((a * b) <= 8.8e+175))) {
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) <= (-8d-133)) then
tmp = a * b
else if (((a * b) <= 4d-22) .or. (.not. ((a * b) <= 1.9d+69)) .and. ((a * b) <= 8.8d+175)) 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) <= -8e-133) {
tmp = a * b;
} else if (((a * b) <= 4e-22) || (!((a * b) <= 1.9e+69) && ((a * b) <= 8.8e+175))) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -8e-133: tmp = a * b elif ((a * b) <= 4e-22) or (not ((a * b) <= 1.9e+69) and ((a * b) <= 8.8e+175)): tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -8e-133) tmp = Float64(a * b); elseif ((Float64(a * b) <= 4e-22) || (!(Float64(a * b) <= 1.9e+69) && (Float64(a * b) <= 8.8e+175))) 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) <= -8e-133) tmp = a * b; elseif (((a * b) <= 4e-22) || (~(((a * b) <= 1.9e+69)) && ((a * b) <= 8.8e+175))) 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], -8e-133], N[(a * b), $MachinePrecision], If[Or[LessEqual[N[(a * b), $MachinePrecision], 4e-22], And[N[Not[LessEqual[N[(a * b), $MachinePrecision], 1.9e+69]], $MachinePrecision], LessEqual[N[(a * b), $MachinePrecision], 8.8e+175]]], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -8 \cdot 10^{-133}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 4 \cdot 10^{-22} \lor \neg \left(a \cdot b \leq 1.9 \cdot 10^{+69}\right) \land a \cdot b \leq 8.8 \cdot 10^{+175}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -8.0000000000000005e-133 or 4.0000000000000002e-22 < (*.f64 a b) < 1.90000000000000014e69 or 8.7999999999999997e175 < (*.f64 a b) Initial program 97.9%
Taylor expanded in a around inf 62.4%
if -8.0000000000000005e-133 < (*.f64 a b) < 4.0000000000000002e-22 or 1.90000000000000014e69 < (*.f64 a b) < 8.7999999999999997e175Initial program 100.0%
Taylor expanded in z around inf 43.2%
Final simplification54.2%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* a b) -5.4e+38)
(* a b)
(if (<= (* a b) -1.15e-196)
(* x y)
(if (<= (* a b) -1e-315)
(* z t)
(if (<= (* a b) 8.8e+175) (* x y) (* a b))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -5.4e+38) {
tmp = a * b;
} else if ((a * b) <= -1.15e-196) {
tmp = x * y;
} else if ((a * b) <= -1e-315) {
tmp = z * t;
} else if ((a * b) <= 8.8e+175) {
tmp = x * y;
} 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) <= (-5.4d+38)) then
tmp = a * b
else if ((a * b) <= (-1.15d-196)) then
tmp = x * y
else if ((a * b) <= (-1d-315)) then
tmp = z * t
else if ((a * b) <= 8.8d+175) then
tmp = x * y
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) <= -5.4e+38) {
tmp = a * b;
} else if ((a * b) <= -1.15e-196) {
tmp = x * y;
} else if ((a * b) <= -1e-315) {
tmp = z * t;
} else if ((a * b) <= 8.8e+175) {
tmp = x * y;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -5.4e+38: tmp = a * b elif (a * b) <= -1.15e-196: tmp = x * y elif (a * b) <= -1e-315: tmp = z * t elif (a * b) <= 8.8e+175: tmp = x * y else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -5.4e+38) tmp = Float64(a * b); elseif (Float64(a * b) <= -1.15e-196) tmp = Float64(x * y); elseif (Float64(a * b) <= -1e-315) tmp = Float64(z * t); elseif (Float64(a * b) <= 8.8e+175) tmp = Float64(x * y); 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) <= -5.4e+38) tmp = a * b; elseif ((a * b) <= -1.15e-196) tmp = x * y; elseif ((a * b) <= -1e-315) tmp = z * t; elseif ((a * b) <= 8.8e+175) tmp = x * y; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -5.4e+38], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -1.15e-196], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -1e-315], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 8.8e+175], N[(x * y), $MachinePrecision], N[(a * b), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -5.4 \cdot 10^{+38}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq -1.15 \cdot 10^{-196}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;a \cdot b \leq -1 \cdot 10^{-315}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;a \cdot b \leq 8.8 \cdot 10^{+175}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -5.39999999999999992e38 or 8.7999999999999997e175 < (*.f64 a b) Initial program 96.7%
Taylor expanded in a around inf 78.8%
if -5.39999999999999992e38 < (*.f64 a b) < -1.1500000000000001e-196 or -9.999999985e-316 < (*.f64 a b) < 8.7999999999999997e175Initial program 100.0%
Taylor expanded in x around inf 55.6%
if -1.1500000000000001e-196 < (*.f64 a b) < -9.999999985e-316Initial program 100.0%
Taylor expanded in z around inf 72.4%
Final simplification64.7%
(FPCore (x y z t a b) :precision binary64 (if (or (<= y -6.4e-34) (not (<= y 1.05e+176))) (* x y) (+ (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((y <= -6.4e-34) || !(y <= 1.05e+176)) {
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 ((y <= (-6.4d-34)) .or. (.not. (y <= 1.05d+176))) 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 ((y <= -6.4e-34) || !(y <= 1.05e+176)) {
tmp = x * y;
} else {
tmp = (a * b) + (z * t);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (y <= -6.4e-34) or not (y <= 1.05e+176): tmp = x * y else: tmp = (a * b) + (z * t) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((y <= -6.4e-34) || !(y <= 1.05e+176)) 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 ((y <= -6.4e-34) || ~((y <= 1.05e+176))) tmp = x * y; else tmp = (a * b) + (z * t); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[y, -6.4e-34], N[Not[LessEqual[y, 1.05e+176]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.4 \cdot 10^{-34} \lor \neg \left(y \leq 1.05 \cdot 10^{+176}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if y < -6.40000000000000005e-34 or 1.05e176 < y Initial program 97.1%
Taylor expanded in x around inf 65.2%
if -6.40000000000000005e-34 < y < 1.05e176Initial program 100.0%
Taylor expanded in x around 0 79.6%
Final simplification73.7%
(FPCore (x y z t a b) :precision binary64 (if (or (<= x -660000.0) (not (<= x 1.95e-62))) (+ (* 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 <= -660000.0) || !(x <= 1.95e-62)) {
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 <= (-660000.0d0)) .or. (.not. (x <= 1.95d-62))) 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 <= -660000.0) || !(x <= 1.95e-62)) {
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 <= -660000.0) or not (x <= 1.95e-62): 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 ((x <= -660000.0) || !(x <= 1.95e-62)) 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 <= -660000.0) || ~((x <= 1.95e-62))) 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[x, -660000.0], N[Not[LessEqual[x, 1.95e-62]], $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 \leq -660000 \lor \neg \left(x \leq 1.95 \cdot 10^{-62}\right):\\
\;\;\;\;a \cdot b + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if x < -6.6e5 or 1.9500000000000002e-62 < x Initial program 97.8%
Taylor expanded in z around 0 80.9%
if -6.6e5 < x < 1.9500000000000002e-62Initial program 100.0%
Taylor expanded in x around 0 86.2%
Final simplification83.4%
(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.8%
Final simplification98.8%
(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.8%
Taylor expanded in a around inf 38.5%
Final simplification38.5%
herbie shell --seed 2023200
(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)))