
(FPCore (a b c d) :precision binary64 (* (+ a (+ b (+ c d))) 2.0))
double code(double a, double b, double c, double d) {
return (a + (b + (c + d))) * 2.0;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = (a + (b + (c + d))) * 2.0d0
end function
public static double code(double a, double b, double c, double d) {
return (a + (b + (c + d))) * 2.0;
}
def code(a, b, c, d): return (a + (b + (c + d))) * 2.0
function code(a, b, c, d) return Float64(Float64(a + Float64(b + Float64(c + d))) * 2.0) end
function tmp = code(a, b, c, d) tmp = (a + (b + (c + d))) * 2.0; end
code[a_, b_, c_, d_] := N[(N[(a + N[(b + N[(c + d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]
\begin{array}{l}
\\
\left(a + \left(b + \left(c + d\right)\right)\right) \cdot 2
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (* (+ a (+ b (+ c d))) 2.0))
double code(double a, double b, double c, double d) {
return (a + (b + (c + d))) * 2.0;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = (a + (b + (c + d))) * 2.0d0
end function
public static double code(double a, double b, double c, double d) {
return (a + (b + (c + d))) * 2.0;
}
def code(a, b, c, d): return (a + (b + (c + d))) * 2.0
function code(a, b, c, d) return Float64(Float64(a + Float64(b + Float64(c + d))) * 2.0) end
function tmp = code(a, b, c, d) tmp = (a + (b + (c + d))) * 2.0; end
code[a_, b_, c_, d_] := N[(N[(a + N[(b + N[(c + d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]
\begin{array}{l}
\\
\left(a + \left(b + \left(c + d\right)\right)\right) \cdot 2
\end{array}
(FPCore (a b c d) :precision binary64 (* (+ c (+ (+ a d) b)) 2.0))
double code(double a, double b, double c, double d) {
return (c + ((a + d) + b)) * 2.0;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = (c + ((a + d) + b)) * 2.0d0
end function
public static double code(double a, double b, double c, double d) {
return (c + ((a + d) + b)) * 2.0;
}
def code(a, b, c, d): return (c + ((a + d) + b)) * 2.0
function code(a, b, c, d) return Float64(Float64(c + Float64(Float64(a + d) + b)) * 2.0) end
function tmp = code(a, b, c, d) tmp = (c + ((a + d) + b)) * 2.0; end
code[a_, b_, c_, d_] := N[(N[(c + N[(N[(a + d), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]
\begin{array}{l}
\\
\left(c + \left(\left(a + d\right) + b\right)\right) \cdot 2
\end{array}
Initial program 94.2%
Taylor expanded in a around 0 95.6%
associate-+r+100.0%
flip-+98.2%
+-commutative98.2%
+-commutative98.2%
fma-neg98.1%
+-commutative98.1%
+-commutative98.1%
Applied egg-rr98.1%
fma-neg98.2%
difference-of-squares99.3%
+-commutative99.3%
associate-+r+94.8%
associate--l+94.1%
+-commutative94.1%
associate-+l-93.8%
associate--l+94.5%
+-commutative94.5%
associate-+l-95.0%
Simplified95.0%
associate-/l*95.0%
*-inverses95.0%
flip3-+95.2%
associate-/l/95.2%
*-un-lft-identity95.2%
flip3-+95.0%
associate-+r+100.0%
+-commutative100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (a b c d) :precision binary64 (* 2.0 (+ a (+ b (+ c d)))))
double code(double a, double b, double c, double d) {
return 2.0 * (a + (b + (c + d)));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = 2.0d0 * (a + (b + (c + d)))
end function
public static double code(double a, double b, double c, double d) {
return 2.0 * (a + (b + (c + d)));
}
def code(a, b, c, d): return 2.0 * (a + (b + (c + d)))
function code(a, b, c, d) return Float64(2.0 * Float64(a + Float64(b + Float64(c + d)))) end
function tmp = code(a, b, c, d) tmp = 2.0 * (a + (b + (c + d))); end
code[a_, b_, c_, d_] := N[(2.0 * N[(a + N[(b + N[(c + d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(a + \left(b + \left(c + d\right)\right)\right)
\end{array}
Initial program 94.2%
Final simplification94.2%
(FPCore (a b c d) :precision binary64 (* 2.0 (+ c (+ a (+ d b)))))
double code(double a, double b, double c, double d) {
return 2.0 * (c + (a + (d + b)));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = 2.0d0 * (c + (a + (d + b)))
end function
public static double code(double a, double b, double c, double d) {
return 2.0 * (c + (a + (d + b)));
}
def code(a, b, c, d): return 2.0 * (c + (a + (d + b)))
function code(a, b, c, d) return Float64(2.0 * Float64(c + Float64(a + Float64(d + b)))) end
function tmp = code(a, b, c, d) tmp = 2.0 * (c + (a + (d + b))); end
code[a_, b_, c_, d_] := N[(2.0 * N[(c + N[(a + N[(d + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(c + \left(a + \left(d + b\right)\right)\right)
\end{array}
Initial program 94.2%
Taylor expanded in a around 0 95.6%
Final simplification95.6%
(FPCore (a b c d) :precision binary64 (if (<= a -13.67) (* (+ a d) 2.0) (* 2.0 (+ c b))))
double code(double a, double b, double c, double d) {
double tmp;
if (a <= -13.67) {
tmp = (a + d) * 2.0;
} else {
tmp = 2.0 * (c + b);
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (a <= (-13.67d0)) then
tmp = (a + d) * 2.0d0
else
tmp = 2.0d0 * (c + b)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (a <= -13.67) {
tmp = (a + d) * 2.0;
} else {
tmp = 2.0 * (c + b);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if a <= -13.67: tmp = (a + d) * 2.0 else: tmp = 2.0 * (c + b) return tmp
function code(a, b, c, d) tmp = 0.0 if (a <= -13.67) tmp = Float64(Float64(a + d) * 2.0); else tmp = Float64(2.0 * Float64(c + b)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (a <= -13.67) tmp = (a + d) * 2.0; else tmp = 2.0 * (c + b); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[a, -13.67], N[(N[(a + d), $MachinePrecision] * 2.0), $MachinePrecision], N[(2.0 * N[(c + b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -13.67:\\
\;\;\;\;\left(a + d\right) \cdot 2\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(c + b\right)\\
\end{array}
\end{array}
if a < -13.6699999999999999Initial program 93.4%
Taylor expanded in b around 0 6.3%
Taylor expanded in c around 0 12.6%
+-commutative12.6%
Simplified12.6%
if -13.6699999999999999 < a Initial program 94.6%
Taylor expanded in a around 0 95.6%
Taylor expanded in b around inf 15.8%
Final simplification14.8%
(FPCore (a b c d) :precision binary64 (if (<= a -13.66) (* b 2.0) (* c 2.0)))
double code(double a, double b, double c, double d) {
double tmp;
if (a <= -13.66) {
tmp = b * 2.0;
} else {
tmp = c * 2.0;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (a <= (-13.66d0)) then
tmp = b * 2.0d0
else
tmp = c * 2.0d0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (a <= -13.66) {
tmp = b * 2.0;
} else {
tmp = c * 2.0;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if a <= -13.66: tmp = b * 2.0 else: tmp = c * 2.0 return tmp
function code(a, b, c, d) tmp = 0.0 if (a <= -13.66) tmp = Float64(b * 2.0); else tmp = Float64(c * 2.0); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (a <= -13.66) tmp = b * 2.0; else tmp = c * 2.0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[a, -13.66], N[(b * 2.0), $MachinePrecision], N[(c * 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -13.66:\\
\;\;\;\;b \cdot 2\\
\mathbf{else}:\\
\;\;\;\;c \cdot 2\\
\end{array}
\end{array}
if a < -13.66Initial program 93.5%
Taylor expanded in b around inf 11.4%
if -13.66 < a Initial program 94.6%
Taylor expanded in c around inf 13.2%
Final simplification12.6%
(FPCore (a b c d) :precision binary64 (* 2.0 (+ c b)))
double code(double a, double b, double c, double d) {
return 2.0 * (c + b);
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = 2.0d0 * (c + b)
end function
public static double code(double a, double b, double c, double d) {
return 2.0 * (c + b);
}
def code(a, b, c, d): return 2.0 * (c + b)
function code(a, b, c, d) return Float64(2.0 * Float64(c + b)) end
function tmp = code(a, b, c, d) tmp = 2.0 * (c + b); end
code[a_, b_, c_, d_] := N[(2.0 * N[(c + b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(c + b\right)
\end{array}
Initial program 94.2%
Taylor expanded in a around 0 95.6%
Taylor expanded in b around inf 12.9%
Final simplification12.9%
(FPCore (a b c d) :precision binary64 (* b 2.0))
double code(double a, double b, double c, double d) {
return b * 2.0;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = b * 2.0d0
end function
public static double code(double a, double b, double c, double d) {
return b * 2.0;
}
def code(a, b, c, d): return b * 2.0
function code(a, b, c, d) return Float64(b * 2.0) end
function tmp = code(a, b, c, d) tmp = b * 2.0; end
code[a_, b_, c_, d_] := N[(b * 2.0), $MachinePrecision]
\begin{array}{l}
\\
b \cdot 2
\end{array}
Initial program 94.2%
Taylor expanded in b around inf 6.9%
Final simplification6.9%
(FPCore (a b c d) :precision binary64 (+ (* (+ a b) 2.0) (* (+ c d) 2.0)))
double code(double a, double b, double c, double d) {
return ((a + b) * 2.0) + ((c + d) * 2.0);
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a + b) * 2.0d0) + ((c + d) * 2.0d0)
end function
public static double code(double a, double b, double c, double d) {
return ((a + b) * 2.0) + ((c + d) * 2.0);
}
def code(a, b, c, d): return ((a + b) * 2.0) + ((c + d) * 2.0)
function code(a, b, c, d) return Float64(Float64(Float64(a + b) * 2.0) + Float64(Float64(c + d) * 2.0)) end
function tmp = code(a, b, c, d) tmp = ((a + b) * 2.0) + ((c + d) * 2.0); end
code[a_, b_, c_, d_] := N[(N[(N[(a + b), $MachinePrecision] * 2.0), $MachinePrecision] + N[(N[(c + d), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(a + b\right) \cdot 2 + \left(c + d\right) \cdot 2
\end{array}
herbie shell --seed 2023178
(FPCore (a b c d)
:name "Expression, p6"
:precision binary64
:pre (and (and (and (and (<= -14.0 a) (<= a -13.0)) (and (<= -3.0 b) (<= b -2.0))) (and (<= 3.0 c) (<= c 3.5))) (and (<= 12.5 d) (<= d 13.5)))
:herbie-target
(+ (* (+ a b) 2.0) (* (+ c d) 2.0))
(* (+ a (+ b (+ c d))) 2.0))