
(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 9 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 97.6%
associate-+l+97.6%
fma-def97.7%
fma-def98.4%
Simplified98.4%
Final simplification98.4%
(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 97.6%
fma-def97.6%
Simplified97.6%
Final simplification97.6%
(FPCore (x y z t a b)
:precision binary64
(if (<= z -4e-19)
(* z t)
(if (<= z -1.3e-295)
(* x y)
(if (<= z 2.1e-271)
(* a b)
(if (<= z 9e-180)
(* x y)
(if (<= z 2.3e-130)
(* a b)
(if (<= z 7.5e-50)
(* x y)
(if (<= z 1.8e+20) (* a b) (* z t)))))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (z <= -4e-19) {
tmp = z * t;
} else if (z <= -1.3e-295) {
tmp = x * y;
} else if (z <= 2.1e-271) {
tmp = a * b;
} else if (z <= 9e-180) {
tmp = x * y;
} else if (z <= 2.3e-130) {
tmp = a * b;
} else if (z <= 7.5e-50) {
tmp = x * y;
} else if (z <= 1.8e+20) {
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 <= (-4d-19)) then
tmp = z * t
else if (z <= (-1.3d-295)) then
tmp = x * y
else if (z <= 2.1d-271) then
tmp = a * b
else if (z <= 9d-180) then
tmp = x * y
else if (z <= 2.3d-130) then
tmp = a * b
else if (z <= 7.5d-50) then
tmp = x * y
else if (z <= 1.8d+20) 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 <= -4e-19) {
tmp = z * t;
} else if (z <= -1.3e-295) {
tmp = x * y;
} else if (z <= 2.1e-271) {
tmp = a * b;
} else if (z <= 9e-180) {
tmp = x * y;
} else if (z <= 2.3e-130) {
tmp = a * b;
} else if (z <= 7.5e-50) {
tmp = x * y;
} else if (z <= 1.8e+20) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if z <= -4e-19: tmp = z * t elif z <= -1.3e-295: tmp = x * y elif z <= 2.1e-271: tmp = a * b elif z <= 9e-180: tmp = x * y elif z <= 2.3e-130: tmp = a * b elif z <= 7.5e-50: tmp = x * y elif z <= 1.8e+20: tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (z <= -4e-19) tmp = Float64(z * t); elseif (z <= -1.3e-295) tmp = Float64(x * y); elseif (z <= 2.1e-271) tmp = Float64(a * b); elseif (z <= 9e-180) tmp = Float64(x * y); elseif (z <= 2.3e-130) tmp = Float64(a * b); elseif (z <= 7.5e-50) tmp = Float64(x * y); elseif (z <= 1.8e+20) 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 <= -4e-19) tmp = z * t; elseif (z <= -1.3e-295) tmp = x * y; elseif (z <= 2.1e-271) tmp = a * b; elseif (z <= 9e-180) tmp = x * y; elseif (z <= 2.3e-130) tmp = a * b; elseif (z <= 7.5e-50) tmp = x * y; elseif (z <= 1.8e+20) tmp = a * b; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[z, -4e-19], N[(z * t), $MachinePrecision], If[LessEqual[z, -1.3e-295], N[(x * y), $MachinePrecision], If[LessEqual[z, 2.1e-271], N[(a * b), $MachinePrecision], If[LessEqual[z, 9e-180], N[(x * y), $MachinePrecision], If[LessEqual[z, 2.3e-130], N[(a * b), $MachinePrecision], If[LessEqual[z, 7.5e-50], N[(x * y), $MachinePrecision], If[LessEqual[z, 1.8e+20], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{-19}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \leq -1.3 \cdot 10^{-295}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{-271}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;z \leq 9 \cdot 10^{-180}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{-130}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;z \leq 7.5 \cdot 10^{-50}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{+20}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if z < -3.9999999999999999e-19 or 1.8e20 < z Initial program 95.4%
Taylor expanded in z around inf 60.5%
if -3.9999999999999999e-19 < z < -1.29999999999999993e-295 or 2.1000000000000001e-271 < z < 9.00000000000000019e-180 or 2.3000000000000001e-130 < z < 7.5e-50Initial program 100.0%
Taylor expanded in x around inf 52.4%
if -1.29999999999999993e-295 < z < 2.1000000000000001e-271 or 9.00000000000000019e-180 < z < 2.3000000000000001e-130 or 7.5e-50 < z < 1.8e20Initial program 100.0%
Taylor expanded in a around inf 63.4%
Final simplification57.9%
(FPCore (x y z t a b) :precision binary64 (if (or (<= y -4e+15) (not (<= y 2.2e+135))) (* x y) (+ (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((y <= -4e+15) || !(y <= 2.2e+135)) {
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 <= (-4d+15)) .or. (.not. (y <= 2.2d+135))) 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 <= -4e+15) || !(y <= 2.2e+135)) {
tmp = x * y;
} else {
tmp = (a * b) + (z * t);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (y <= -4e+15) or not (y <= 2.2e+135): tmp = x * y else: tmp = (a * b) + (z * t) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((y <= -4e+15) || !(y <= 2.2e+135)) 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 <= -4e+15) || ~((y <= 2.2e+135))) 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, -4e+15], N[Not[LessEqual[y, 2.2e+135]], $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 -4 \cdot 10^{+15} \lor \neg \left(y \leq 2.2 \cdot 10^{+135}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if y < -4e15 or 2.1999999999999999e135 < y Initial program 97.7%
Taylor expanded in x around inf 57.1%
if -4e15 < y < 2.1999999999999999e135Initial program 97.6%
Taylor expanded in x around 0 74.8%
Final simplification68.7%
(FPCore (x y z t a b) :precision binary64 (if (or (<= z -1.75e+28) (not (<= z 9.2e+24))) (+ (* x y) (* z t)) (+ (* a b) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z <= -1.75e+28) || !(z <= 9.2e+24)) {
tmp = (x * y) + (z * t);
} else {
tmp = (a * b) + (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 ((z <= (-1.75d+28)) .or. (.not. (z <= 9.2d+24))) then
tmp = (x * y) + (z * t)
else
tmp = (a * b) + (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 ((z <= -1.75e+28) || !(z <= 9.2e+24)) {
tmp = (x * y) + (z * t);
} else {
tmp = (a * b) + (x * y);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (z <= -1.75e+28) or not (z <= 9.2e+24): tmp = (x * y) + (z * t) else: tmp = (a * b) + (x * y) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((z <= -1.75e+28) || !(z <= 9.2e+24)) tmp = Float64(Float64(x * y) + Float64(z * t)); else tmp = Float64(Float64(a * b) + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((z <= -1.75e+28) || ~((z <= 9.2e+24))) tmp = (x * y) + (z * t); else tmp = (a * b) + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[z, -1.75e+28], N[Not[LessEqual[z, 9.2e+24]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(N[(a * b), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.75 \cdot 10^{+28} \lor \neg \left(z \leq 9.2 \cdot 10^{+24}\right):\\
\;\;\;\;x \cdot y + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + x \cdot y\\
\end{array}
\end{array}
if z < -1.75e28 or 9.1999999999999996e24 < z Initial program 95.1%
Taylor expanded in a around 0 82.8%
if -1.75e28 < z < 9.1999999999999996e24Initial program 100.0%
Taylor expanded in z around 0 83.3%
Final simplification83.0%
(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 97.6%
Final simplification97.6%
(FPCore (x y z t a b) :precision binary64 (if (<= z -2000000000000.0) (+ (* a b) (* z t)) (+ (* a b) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (z <= -2000000000000.0) {
tmp = (a * b) + (z * t);
} else {
tmp = (a * b) + (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 (z <= (-2000000000000.0d0)) then
tmp = (a * b) + (z * t)
else
tmp = (a * b) + (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 (z <= -2000000000000.0) {
tmp = (a * b) + (z * t);
} else {
tmp = (a * b) + (x * y);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if z <= -2000000000000.0: tmp = (a * b) + (z * t) else: tmp = (a * b) + (x * y) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (z <= -2000000000000.0) tmp = Float64(Float64(a * b) + Float64(z * t)); else tmp = Float64(Float64(a * b) + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (z <= -2000000000000.0) tmp = (a * b) + (z * t); else tmp = (a * b) + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[z, -2000000000000.0], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(N[(a * b), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2000000000000:\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + x \cdot y\\
\end{array}
\end{array}
if z < -2e12Initial program 96.6%
Taylor expanded in x around 0 80.4%
if -2e12 < z Initial program 98.0%
Taylor expanded in z around 0 76.3%
Final simplification77.2%
(FPCore (x y z t a b) :precision binary64 (if (or (<= z -2.9e+35) (not (<= z 1.8e+16))) (* z t) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z <= -2.9e+35) || !(z <= 1.8e+16)) {
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 ((z <= (-2.9d+35)) .or. (.not. (z <= 1.8d+16))) 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 ((z <= -2.9e+35) || !(z <= 1.8e+16)) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (z <= -2.9e+35) or not (z <= 1.8e+16): tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((z <= -2.9e+35) || !(z <= 1.8e+16)) 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 ((z <= -2.9e+35) || ~((z <= 1.8e+16))) tmp = z * t; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[z, -2.9e+35], N[Not[LessEqual[z, 1.8e+16]], $MachinePrecision]], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.9 \cdot 10^{+35} \lor \neg \left(z \leq 1.8 \cdot 10^{+16}\right):\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if z < -2.89999999999999995e35 or 1.8e16 < z Initial program 95.1%
Taylor expanded in z around inf 61.5%
if -2.89999999999999995e35 < z < 1.8e16Initial program 100.0%
Taylor expanded in a around inf 41.6%
Final simplification51.2%
(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 97.6%
Taylor expanded in a around inf 32.1%
Final simplification32.1%
herbie shell --seed 2023242
(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)))