
(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 8 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 (* 2.0 (- (+ c (+ (+ d a) (* 2.0 b))) b)))
double code(double a, double b, double c, double d) {
return 2.0 * ((c + ((d + a) + (2.0 * b))) - 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 + ((d + a) + (2.0d0 * b))) - b)
end function
public static double code(double a, double b, double c, double d) {
return 2.0 * ((c + ((d + a) + (2.0 * b))) - b);
}
def code(a, b, c, d): return 2.0 * ((c + ((d + a) + (2.0 * b))) - b)
function code(a, b, c, d) return Float64(2.0 * Float64(Float64(c + Float64(Float64(d + a) + Float64(2.0 * b))) - b)) end
function tmp = code(a, b, c, d) tmp = 2.0 * ((c + ((d + a) + (2.0 * b))) - b); end
code[a_, b_, c_, d_] := N[(2.0 * N[(N[(c + N[(N[(d + a), $MachinePrecision] + N[(2.0 * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(\left(c + \left(\left(d + a\right) + 2 \cdot b\right)\right) - b\right)
\end{array}
Initial program 94.2%
+-commutative94.2%
+-commutative94.2%
associate-+r+95.2%
+-commutative95.2%
associate-+r+95.2%
+-commutative95.2%
flip-+94.2%
fma-neg94.3%
+-commutative94.3%
+-commutative94.3%
pow294.3%
+-commutative94.3%
Applied egg-rr94.3%
+-commutative94.3%
+-commutative94.3%
+-commutative94.3%
associate--r+94.3%
+-commutative94.3%
associate--l+94.3%
Simplified94.3%
Taylor expanded in d around inf 98.6%
*-un-lft-identity98.6%
Applied egg-rr98.6%
*-lft-identity98.6%
associate-+r+100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b c d) :precision binary64 (if (<= b -2.605) (* (+ d a) 2.0) (* 2.0 (+ a (+ c d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (b <= -2.605) {
tmp = (d + a) * 2.0;
} else {
tmp = 2.0 * (a + (c + d));
}
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 (b <= (-2.605d0)) then
tmp = (d + a) * 2.0d0
else
tmp = 2.0d0 * (a + (c + d))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (b <= -2.605) {
tmp = (d + a) * 2.0;
} else {
tmp = 2.0 * (a + (c + d));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if b <= -2.605: tmp = (d + a) * 2.0 else: tmp = 2.0 * (a + (c + d)) return tmp
function code(a, b, c, d) tmp = 0.0 if (b <= -2.605) tmp = Float64(Float64(d + a) * 2.0); else tmp = Float64(2.0 * Float64(a + Float64(c + d))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (b <= -2.605) tmp = (d + a) * 2.0; else tmp = 2.0 * (a + (c + d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[b, -2.605], N[(N[(d + a), $MachinePrecision] * 2.0), $MachinePrecision], N[(2.0 * N[(a + N[(c + d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.605:\\
\;\;\;\;\left(d + a\right) \cdot 2\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(a + \left(c + d\right)\right)\\
\end{array}
\end{array}
if b < -2.60499999999999998Initial program 93.8%
Taylor expanded in b around 0 7.0%
Taylor expanded in c around 0 13.6%
+-commutative13.6%
Simplified13.6%
if -2.60499999999999998 < b Initial program 94.5%
Taylor expanded in b around 0 14.1%
Final simplification13.9%
(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 (+ a (+ d (+ c b)))))
double code(double a, double b, double c, double d) {
return 2.0 * (a + (d + (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 * (a + (d + (c + b)))
end function
public static double code(double a, double b, double c, double d) {
return 2.0 * (a + (d + (c + b)));
}
def code(a, b, c, d): return 2.0 * (a + (d + (c + b)))
function code(a, b, c, d) return Float64(2.0 * Float64(a + Float64(d + Float64(c + b)))) end
function tmp = code(a, b, c, d) tmp = 2.0 * (a + (d + (c + b))); end
code[a_, b_, c_, d_] := N[(2.0 * N[(a + N[(d + N[(c + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(a + \left(d + \left(c + b\right)\right)\right)
\end{array}
Initial program 94.2%
*-commutative94.2%
associate-+r+93.9%
distribute-lft-in93.9%
distribute-lft-in93.9%
associate-+r+94.7%
distribute-lft-in94.7%
+-commutative94.7%
associate-+r+95.2%
+-commutative95.2%
distribute-lft-in95.2%
+-commutative95.2%
*-commutative95.2%
+-commutative95.2%
Simplified95.2%
*-un-lft-identity95.2%
*-commutative95.2%
+-commutative95.2%
associate-+l+95.8%
+-commutative95.8%
Applied egg-rr95.8%
*-rgt-identity95.8%
flip-+94.6%
Applied egg-rr94.6%
Taylor expanded in d around 0 95.4%
associate-+r+95.2%
+-commutative95.2%
Simplified95.2%
Taylor expanded in a around 0 95.4%
associate-+r+95.2%
+-commutative95.2%
associate-+r+95.2%
+-commutative95.2%
associate-+l+95.8%
Simplified95.8%
Final simplification95.8%
(FPCore (a b c d) :precision binary64 (* 2.0 (+ c (+ (+ d a) b))))
double code(double a, double b, double c, double d) {
return 2.0 * (c + ((d + a) + 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 + ((d + a) + b))
end function
public static double code(double a, double b, double c, double d) {
return 2.0 * (c + ((d + a) + b));
}
def code(a, b, c, d): return 2.0 * (c + ((d + a) + b))
function code(a, b, c, d) return Float64(2.0 * Float64(c + Float64(Float64(d + a) + b))) end
function tmp = code(a, b, c, d) tmp = 2.0 * (c + ((d + a) + b)); end
code[a_, b_, c_, d_] := N[(2.0 * N[(c + N[(N[(d + a), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(c + \left(\left(d + a\right) + b\right)\right)
\end{array}
Initial program 94.2%
*-commutative94.2%
associate-+r+93.9%
distribute-lft-in93.9%
distribute-lft-in93.9%
associate-+r+94.7%
distribute-lft-in94.7%
+-commutative94.7%
associate-+r+95.2%
+-commutative95.2%
distribute-lft-in95.2%
+-commutative95.2%
*-commutative95.2%
+-commutative95.2%
Simplified95.2%
*-un-lft-identity95.2%
*-commutative95.2%
+-commutative95.2%
associate-+l+95.8%
+-commutative95.8%
Applied egg-rr95.8%
*-rgt-identity95.8%
flip-+94.6%
Applied egg-rr94.6%
Taylor expanded in d around 0 95.4%
associate-+r+95.2%
+-commutative95.2%
Simplified95.2%
*-un-lft-identity95.2%
*-commutative95.2%
associate-+r+95.3%
+-commutative95.3%
associate-+l+100.0%
associate-+l+100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (a b c d) :precision binary64 (if (<= b -2.605) (* (+ d a) 2.0) (* c 2.0)))
double code(double a, double b, double c, double d) {
double tmp;
if (b <= -2.605) {
tmp = (d + a) * 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 (b <= (-2.605d0)) then
tmp = (d + a) * 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 (b <= -2.605) {
tmp = (d + a) * 2.0;
} else {
tmp = c * 2.0;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if b <= -2.605: tmp = (d + a) * 2.0 else: tmp = c * 2.0 return tmp
function code(a, b, c, d) tmp = 0.0 if (b <= -2.605) tmp = Float64(Float64(d + a) * 2.0); else tmp = Float64(c * 2.0); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (b <= -2.605) tmp = (d + a) * 2.0; else tmp = c * 2.0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[b, -2.605], N[(N[(d + a), $MachinePrecision] * 2.0), $MachinePrecision], N[(c * 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.605:\\
\;\;\;\;\left(d + a\right) \cdot 2\\
\mathbf{else}:\\
\;\;\;\;c \cdot 2\\
\end{array}
\end{array}
if b < -2.60499999999999998Initial program 93.8%
Taylor expanded in b around 0 7.0%
Taylor expanded in c around 0 13.6%
+-commutative13.6%
Simplified13.6%
if -2.60499999999999998 < b Initial program 94.5%
Taylor expanded in c around inf 14.0%
Final simplification13.8%
(FPCore (a b c d) :precision binary64 (if (<= d 12.7) (* 2.0 b) (* c 2.0)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= 12.7) {
tmp = 2.0 * b;
} 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 (d <= 12.7d0) then
tmp = 2.0d0 * b
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 (d <= 12.7) {
tmp = 2.0 * b;
} else {
tmp = c * 2.0;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= 12.7: tmp = 2.0 * b else: tmp = c * 2.0 return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= 12.7) tmp = Float64(2.0 * b); else tmp = Float64(c * 2.0); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= 12.7) tmp = 2.0 * b; else tmp = c * 2.0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, 12.7], N[(2.0 * b), $MachinePrecision], N[(c * 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq 12.7:\\
\;\;\;\;2 \cdot b\\
\mathbf{else}:\\
\;\;\;\;c \cdot 2\\
\end{array}
\end{array}
if d < 12.699999999999999Initial program 95.4%
Taylor expanded in b around inf 12.6%
if 12.699999999999999 < d Initial program 93.8%
Taylor expanded in c around inf 12.6%
Final simplification12.6%
(FPCore (a b c d) :precision binary64 (* 2.0 b))
double code(double a, double b, double c, double d) {
return 2.0 * 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 * b
end function
public static double code(double a, double b, double c, double d) {
return 2.0 * b;
}
def code(a, b, c, d): return 2.0 * b
function code(a, b, c, d) return Float64(2.0 * b) end
function tmp = code(a, b, c, d) tmp = 2.0 * b; end
code[a_, b_, c_, d_] := N[(2.0 * b), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot b
\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 2023274
(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))