
(FPCore (a b c d e) :precision binary64 (+ (+ (+ (+ e d) c) b) a))
double code(double a, double b, double c, double d, double e) {
return (((e + d) + c) + b) + a;
}
real(8) function code(a, b, c, d, e)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8), intent (in) :: e
code = (((e + d) + c) + b) + a
end function
public static double code(double a, double b, double c, double d, double e) {
return (((e + d) + c) + b) + a;
}
def code(a, b, c, d, e): return (((e + d) + c) + b) + a
function code(a, b, c, d, e) return Float64(Float64(Float64(Float64(e + d) + c) + b) + a) end
function tmp = code(a, b, c, d, e) tmp = (((e + d) + c) + b) + a; end
code[a_, b_, c_, d_, e_] := N[(N[(N[(N[(e + d), $MachinePrecision] + c), $MachinePrecision] + b), $MachinePrecision] + a), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(e + d\right) + c\right) + b\right) + a
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d e) :precision binary64 (+ (+ (+ (+ e d) c) b) a))
double code(double a, double b, double c, double d, double e) {
return (((e + d) + c) + b) + a;
}
real(8) function code(a, b, c, d, e)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8), intent (in) :: e
code = (((e + d) + c) + b) + a
end function
public static double code(double a, double b, double c, double d, double e) {
return (((e + d) + c) + b) + a;
}
def code(a, b, c, d, e): return (((e + d) + c) + b) + a
function code(a, b, c, d, e) return Float64(Float64(Float64(Float64(e + d) + c) + b) + a) end
function tmp = code(a, b, c, d, e) tmp = (((e + d) + c) + b) + a; end
code[a_, b_, c_, d_, e_] := N[(N[(N[(N[(e + d), $MachinePrecision] + c), $MachinePrecision] + b), $MachinePrecision] + a), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(e + d\right) + c\right) + b\right) + a
\end{array}
(FPCore (a b c d e) :precision binary64 (+ (+ d (+ c e)) (+ b a)))
double code(double a, double b, double c, double d, double e) {
return (d + (c + e)) + (b + a);
}
real(8) function code(a, b, c, d, e)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8), intent (in) :: e
code = (d + (c + e)) + (b + a)
end function
public static double code(double a, double b, double c, double d, double e) {
return (d + (c + e)) + (b + a);
}
def code(a, b, c, d, e): return (d + (c + e)) + (b + a)
function code(a, b, c, d, e) return Float64(Float64(d + Float64(c + e)) + Float64(b + a)) end
function tmp = code(a, b, c, d, e) tmp = (d + (c + e)) + (b + a); end
code[a_, b_, c_, d_, e_] := N[(N[(d + N[(c + e), $MachinePrecision]), $MachinePrecision] + N[(b + a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(d + \left(c + e\right)\right) + \left(b + a\right)
\end{array}
Initial program 99.5%
associate-+l+99.6%
associate-+l+99.5%
Simplified99.5%
Taylor expanded in e around 0 99.6%
+-commutative99.6%
associate-+r+99.6%
+-commutative99.6%
Simplified99.6%
(FPCore (a b c d e) :precision binary64 (+ d (+ (+ c e) (+ b a))))
double code(double a, double b, double c, double d, double e) {
return d + ((c + e) + (b + a));
}
real(8) function code(a, b, c, d, e)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8), intent (in) :: e
code = d + ((c + e) + (b + a))
end function
public static double code(double a, double b, double c, double d, double e) {
return d + ((c + e) + (b + a));
}
def code(a, b, c, d, e): return d + ((c + e) + (b + a))
function code(a, b, c, d, e) return Float64(d + Float64(Float64(c + e) + Float64(b + a))) end
function tmp = code(a, b, c, d, e) tmp = d + ((c + e) + (b + a)); end
code[a_, b_, c_, d_, e_] := N[(d + N[(N[(c + e), $MachinePrecision] + N[(b + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
d + \left(\left(c + e\right) + \left(b + a\right)\right)
\end{array}
Initial program 99.5%
associate-+l+99.6%
+-commutative99.6%
associate-+l+99.6%
associate-+l+99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (a b c d e) :precision binary64 (+ a (+ (+ c e) (+ d b))))
double code(double a, double b, double c, double d, double e) {
return a + ((c + e) + (d + b));
}
real(8) function code(a, b, c, d, e)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8), intent (in) :: e
code = a + ((c + e) + (d + b))
end function
public static double code(double a, double b, double c, double d, double e) {
return a + ((c + e) + (d + b));
}
def code(a, b, c, d, e): return a + ((c + e) + (d + b))
function code(a, b, c, d, e) return Float64(a + Float64(Float64(c + e) + Float64(d + b))) end
function tmp = code(a, b, c, d, e) tmp = a + ((c + e) + (d + b)); end
code[a_, b_, c_, d_, e_] := N[(a + N[(N[(c + e), $MachinePrecision] + N[(d + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a + \left(\left(c + e\right) + \left(d + b\right)\right)
\end{array}
Initial program 99.5%
associate-+l+99.6%
associate-+l+99.5%
Simplified99.5%
Taylor expanded in e around inf 99.5%
Taylor expanded in e around 0 99.5%
+-commutative99.5%
associate-+r+99.5%
associate-+r+99.4%
+-commutative99.4%
associate-+r+99.5%
+-commutative99.5%
associate-+r+99.5%
+-commutative99.5%
+-commutative99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (a b c d e) :precision binary64 (+ b (+ c (+ d e))))
double code(double a, double b, double c, double d, double e) {
return b + (c + (d + e));
}
real(8) function code(a, b, c, d, e)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8), intent (in) :: e
code = b + (c + (d + e))
end function
public static double code(double a, double b, double c, double d, double e) {
return b + (c + (d + e));
}
def code(a, b, c, d, e): return b + (c + (d + e))
function code(a, b, c, d, e) return Float64(b + Float64(c + Float64(d + e))) end
function tmp = code(a, b, c, d, e) tmp = b + (c + (d + e)); end
code[a_, b_, c_, d_, e_] := N[(b + N[(c + N[(d + e), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
b + \left(c + \left(d + e\right)\right)
\end{array}
Initial program 99.5%
associate-+l+99.6%
+-commutative99.6%
associate-+l+99.6%
associate-+l+99.6%
Simplified99.6%
Taylor expanded in a around 0 25.7%
(FPCore (a b c d e) :precision binary64 (+ c (+ d e)))
double code(double a, double b, double c, double d, double e) {
return c + (d + e);
}
real(8) function code(a, b, c, d, e)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8), intent (in) :: e
code = c + (d + e)
end function
public static double code(double a, double b, double c, double d, double e) {
return c + (d + e);
}
def code(a, b, c, d, e): return c + (d + e)
function code(a, b, c, d, e) return Float64(c + Float64(d + e)) end
function tmp = code(a, b, c, d, e) tmp = c + (d + e); end
code[a_, b_, c_, d_, e_] := N[(c + N[(d + e), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
c + \left(d + e\right)
\end{array}
Initial program 99.5%
associate-+l+99.6%
associate-+l+99.5%
Simplified99.5%
Taylor expanded in e around 0 99.6%
+-commutative99.6%
associate-+r+99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in a around 0 25.7%
+-commutative25.7%
Simplified25.7%
Taylor expanded in b around 0 25.7%
+-commutative25.7%
associate-+r+25.7%
associate-+r+25.7%
+-commutative25.7%
associate-+r+25.7%
+-commutative25.7%
associate-+r+25.7%
+-commutative25.7%
+-commutative25.7%
Simplified25.7%
Taylor expanded in b around 0 23.2%
(FPCore (a b c d e) :precision binary64 (+ b (+ d e)))
double code(double a, double b, double c, double d, double e) {
return b + (d + e);
}
real(8) function code(a, b, c, d, e)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8), intent (in) :: e
code = b + (d + e)
end function
public static double code(double a, double b, double c, double d, double e) {
return b + (d + e);
}
def code(a, b, c, d, e): return b + (d + e)
function code(a, b, c, d, e) return Float64(b + Float64(d + e)) end
function tmp = code(a, b, c, d, e) tmp = b + (d + e); end
code[a_, b_, c_, d_, e_] := N[(b + N[(d + e), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
b + \left(d + e\right)
\end{array}
Initial program 99.5%
associate-+l+99.6%
+-commutative99.6%
associate-+l+99.6%
associate-+l+99.6%
Simplified99.6%
Taylor expanded in a around 0 25.7%
+-commutative25.7%
associate-+r+25.7%
+-commutative25.7%
Simplified25.7%
Taylor expanded in c around 0 22.0%
+-commutative22.0%
Simplified22.0%
Final simplification22.0%
(FPCore (a b c d e) :precision binary64 (+ d e))
double code(double a, double b, double c, double d, double e) {
return d + e;
}
real(8) function code(a, b, c, d, e)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8), intent (in) :: e
code = d + e
end function
public static double code(double a, double b, double c, double d, double e) {
return d + e;
}
def code(a, b, c, d, e): return d + e
function code(a, b, c, d, e) return Float64(d + e) end
function tmp = code(a, b, c, d, e) tmp = d + e; end
code[a_, b_, c_, d_, e_] := N[(d + e), $MachinePrecision]
\begin{array}{l}
\\
d + e
\end{array}
Initial program 99.5%
associate-+l+99.6%
+-commutative99.6%
associate-+l+99.6%
associate-+l+99.6%
Simplified99.6%
Taylor expanded in a around 0 25.7%
+-commutative25.7%
associate-+r+25.7%
+-commutative25.7%
Simplified25.7%
Taylor expanded in c around 0 22.0%
+-commutative22.0%
Simplified22.0%
Taylor expanded in b around 0 21.1%
(FPCore (a b c d e) :precision binary64 e)
double code(double a, double b, double c, double d, double e) {
return e;
}
real(8) function code(a, b, c, d, e)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8), intent (in) :: e
code = e
end function
public static double code(double a, double b, double c, double d, double e) {
return e;
}
def code(a, b, c, d, e): return e
function code(a, b, c, d, e) return e end
function tmp = code(a, b, c, d, e) tmp = e; end
code[a_, b_, c_, d_, e_] := e
\begin{array}{l}
\\
e
\end{array}
Initial program 99.5%
associate-+l+99.6%
+-commutative99.6%
associate-+l+99.6%
associate-+l+99.6%
Simplified99.6%
Taylor expanded in e around inf 18.8%
(FPCore (a b c d e) :precision binary64 (+ (+ d (+ c (+ a b))) e))
double code(double a, double b, double c, double d, double e) {
return (d + (c + (a + b))) + e;
}
real(8) function code(a, b, c, d, e)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8), intent (in) :: e
code = (d + (c + (a + b))) + e
end function
public static double code(double a, double b, double c, double d, double e) {
return (d + (c + (a + b))) + e;
}
def code(a, b, c, d, e): return (d + (c + (a + b))) + e
function code(a, b, c, d, e) return Float64(Float64(d + Float64(c + Float64(a + b))) + e) end
function tmp = code(a, b, c, d, e) tmp = (d + (c + (a + b))) + e; end
code[a_, b_, c_, d_, e_] := N[(N[(d + N[(c + N[(a + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + e), $MachinePrecision]
\begin{array}{l}
\\
\left(d + \left(c + \left(a + b\right)\right)\right) + e
\end{array}
herbie shell --seed 2024160
(FPCore (a b c d e)
:name "Expression 1, p15"
:precision binary64
:pre (and (and (and (and (and (and (and (and (and (<= 1.0 a) (<= a 2.0)) (<= 2.0 b)) (<= b 4.0)) (<= 4.0 c)) (<= c 8.0)) (<= 8.0 d)) (<= d 16.0)) (<= 16.0 e)) (<= e 32.0))
:alt
(! :herbie-platform default (+ (+ d (+ c (+ a b))) e))
(+ (+ (+ (+ e d) c) b) a))