
(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 (+ (* 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.4%
Final simplification98.4%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -2.4e+110) (+ (* a b) (* z t)) (if (<= (* a b) 6.4e+91) (+ (* x y) (* z t)) (+ (* x y) (* a b)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -2.4e+110) {
tmp = (a * b) + (z * t);
} else if ((a * b) <= 6.4e+91) {
tmp = (x * y) + (z * t);
} else {
tmp = (x * y) + (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) <= (-2.4d+110)) then
tmp = (a * b) + (z * t)
else if ((a * b) <= 6.4d+91) then
tmp = (x * y) + (z * t)
else
tmp = (x * y) + (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) <= -2.4e+110) {
tmp = (a * b) + (z * t);
} else if ((a * b) <= 6.4e+91) {
tmp = (x * y) + (z * t);
} else {
tmp = (x * y) + (a * b);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -2.4e+110: tmp = (a * b) + (z * t) elif (a * b) <= 6.4e+91: tmp = (x * y) + (z * t) else: tmp = (x * y) + (a * b) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -2.4e+110) tmp = Float64(Float64(a * b) + Float64(z * t)); elseif (Float64(a * b) <= 6.4e+91) tmp = Float64(Float64(x * y) + Float64(z * t)); else tmp = Float64(Float64(x * y) + Float64(a * b)); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((a * b) <= -2.4e+110) tmp = (a * b) + (z * t); elseif ((a * b) <= 6.4e+91) tmp = (x * y) + (z * t); else tmp = (x * y) + (a * b); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -2.4e+110], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 6.4e+91], N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -2.4 \cdot 10^{+110}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{elif}\;a \cdot b \leq 6.4 \cdot 10^{+91}:\\
\;\;\;\;x \cdot y + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;x \cdot y + a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -2.40000000000000012e110Initial program 92.1%
Taylor expanded in x around 0
*-lowering-*.f6487.0%
Simplified87.0%
if -2.40000000000000012e110 < (*.f64 a b) < 6.39999999999999979e91Initial program 100.0%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6492.2%
Simplified92.2%
if 6.39999999999999979e91 < (*.f64 a b) Initial program 97.9%
Taylor expanded in x around inf
*-lowering-*.f6492.0%
Simplified92.0%
Final simplification91.4%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (+ (* a b) (* z t))))
(if (<= (* a b) -3.5e+117)
t_1
(if (<= (* a b) 5e+29) (+ (* x y) (* z t)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (a * b) + (z * t);
double tmp;
if ((a * b) <= -3.5e+117) {
tmp = t_1;
} else if ((a * b) <= 5e+29) {
tmp = (x * y) + (z * t);
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_1 = (a * b) + (z * t)
if ((a * b) <= (-3.5d+117)) then
tmp = t_1
else if ((a * b) <= 5d+29) then
tmp = (x * y) + (z * t)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (a * b) + (z * t);
double tmp;
if ((a * b) <= -3.5e+117) {
tmp = t_1;
} else if ((a * b) <= 5e+29) {
tmp = (x * y) + (z * t);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t, a, b): t_1 = (a * b) + (z * t) tmp = 0 if (a * b) <= -3.5e+117: tmp = t_1 elif (a * b) <= 5e+29: tmp = (x * y) + (z * t) else: tmp = t_1 return tmp
function code(x, y, z, t, a, b) t_1 = Float64(Float64(a * b) + Float64(z * t)) tmp = 0.0 if (Float64(a * b) <= -3.5e+117) tmp = t_1; elseif (Float64(a * b) <= 5e+29) tmp = Float64(Float64(x * y) + Float64(z * t)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t, a, b) t_1 = (a * b) + (z * t); tmp = 0.0; if ((a * b) <= -3.5e+117) tmp = t_1; elseif ((a * b) <= 5e+29) tmp = (x * y) + (z * t); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(a * b), $MachinePrecision], -3.5e+117], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], 5e+29], N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := a \cdot b + z \cdot t\\
\mathbf{if}\;a \cdot b \leq -3.5 \cdot 10^{+117}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \cdot b \leq 5 \cdot 10^{+29}:\\
\;\;\;\;x \cdot y + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 a b) < -3.49999999999999983e117 or 5.0000000000000001e29 < (*.f64 a b) Initial program 95.8%
Taylor expanded in x around 0
*-lowering-*.f6483.5%
Simplified83.5%
if -3.49999999999999983e117 < (*.f64 a b) < 5.0000000000000001e29Initial program 100.0%
Taylor expanded in a around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6492.6%
Simplified92.6%
Final simplification89.2%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -3.8e+127) (* x y) (if (<= (* x y) 1.5e+213) (+ (* 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.8e+127) {
tmp = x * y;
} else if ((x * y) <= 1.5e+213) {
tmp = (a * b) + (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) <= (-3.8d+127)) then
tmp = x * y
else if ((x * y) <= 1.5d+213) then
tmp = (a * b) + (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) <= -3.8e+127) {
tmp = x * y;
} else if ((x * y) <= 1.5e+213) {
tmp = (a * b) + (z * t);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -3.8e+127: tmp = x * y elif (x * y) <= 1.5e+213: tmp = (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.8e+127) tmp = Float64(x * y); elseif (Float64(x * y) <= 1.5e+213) tmp = Float64(Float64(a * b) + 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) <= -3.8e+127) tmp = x * y; elseif ((x * y) <= 1.5e+213) tmp = (a * b) + (z * t); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -3.8e+127], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 1.5e+213], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -3.8 \cdot 10^{+127}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 1.5 \cdot 10^{+213}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -3.7999999999999998e127 or 1.5000000000000001e213 < (*.f64 x y) Initial program 96.2%
Taylor expanded in x around inf
*-lowering-*.f6481.5%
Simplified81.5%
if -3.7999999999999998e127 < (*.f64 x y) < 1.5000000000000001e213Initial program 99.4%
Taylor expanded in x around 0
*-lowering-*.f6482.5%
Simplified82.5%
Final simplification82.2%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -1.22e+82) (* x y) (if (<= (* x y) 23500.0) (* z t) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -1.22e+82) {
tmp = x * y;
} else if ((x * y) <= 23500.0) {
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) <= (-1.22d+82)) then
tmp = x * y
else if ((x * y) <= 23500.0d0) 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) <= -1.22e+82) {
tmp = x * y;
} else if ((x * y) <= 23500.0) {
tmp = z * t;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -1.22e+82: tmp = x * y elif (x * y) <= 23500.0: tmp = z * t else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -1.22e+82) tmp = Float64(x * y); elseif (Float64(x * y) <= 23500.0) 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) <= -1.22e+82) tmp = x * y; elseif ((x * y) <= 23500.0) 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], -1.22e+82], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 23500.0], N[(z * t), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1.22 \cdot 10^{+82}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 23500:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -1.22000000000000008e82 or 23500 < (*.f64 x y) Initial program 97.4%
Taylor expanded in x around inf
*-lowering-*.f6470.0%
Simplified70.0%
if -1.22000000000000008e82 < (*.f64 x y) < 23500Initial program 99.2%
Taylor expanded in z around inf
*-lowering-*.f6453.7%
Simplified53.7%
Final simplification61.1%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -1.25e+20) (* a b) (if (<= (* a b) 5e+91) (* z t) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -1.25e+20) {
tmp = a * b;
} else if ((a * b) <= 5e+91) {
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.25d+20)) then
tmp = a * b
else if ((a * b) <= 5d+91) 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.25e+20) {
tmp = a * b;
} else if ((a * b) <= 5e+91) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -1.25e+20: tmp = a * b elif (a * b) <= 5e+91: 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.25e+20) tmp = Float64(a * b); elseif (Float64(a * b) <= 5e+91) 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.25e+20) tmp = a * b; elseif ((a * b) <= 5e+91) 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.25e+20], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 5e+91], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1.25 \cdot 10^{+20}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 5 \cdot 10^{+91}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -1.25e20 or 5.0000000000000002e91 < (*.f64 a b) Initial program 96.2%
Taylor expanded in a around inf
*-lowering-*.f6465.6%
Simplified65.6%
if -1.25e20 < (*.f64 a b) < 5.0000000000000002e91Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6453.9%
Simplified53.9%
Final simplification58.6%
(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.4%
Taylor expanded in a around inf
*-lowering-*.f6431.7%
Simplified31.7%
herbie shell --seed 2024192
(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)))