
(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 6 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 (+ b (+ c (+ a d)))))
double code(double a, double b, double c, double d) {
return 2.0 * (b + (c + (a + 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 * (b + (c + (a + d)))
end function
public static double code(double a, double b, double c, double d) {
return 2.0 * (b + (c + (a + d)));
}
def code(a, b, c, d): return 2.0 * (b + (c + (a + d)))
function code(a, b, c, d) return Float64(2.0 * Float64(b + Float64(c + Float64(a + d)))) end
function tmp = code(a, b, c, d) tmp = 2.0 * (b + (c + (a + d))); end
code[a_, b_, c_, d_] := N[(2.0 * N[(b + N[(c + N[(a + d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(b + \left(c + \left(a + d\right)\right)\right)
\end{array}
Initial program 94.3%
*-commutative94.3%
+-commutative94.3%
+-commutative94.3%
associate-+r+95.6%
+-commutative95.6%
associate-+r+95.0%
Simplified95.0%
Taylor expanded in a around 0 94.3%
associate-+r+93.9%
+-commutative93.9%
associate-+l+94.2%
associate-+r+95.1%
+-commutative95.1%
associate-+l+100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b c d) :precision binary64 (if (<= (+ c d) 16.05805) (* 2.0 (+ a d)) (* 2.0 (+ c (+ a d)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c + d) <= 16.05805) {
tmp = 2.0 * (a + d);
} else {
tmp = 2.0 * (c + (a + 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 ((c + d) <= 16.05805d0) then
tmp = 2.0d0 * (a + d)
else
tmp = 2.0d0 * (c + (a + d))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c + d) <= 16.05805) {
tmp = 2.0 * (a + d);
} else {
tmp = 2.0 * (c + (a + d));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c + d) <= 16.05805: tmp = 2.0 * (a + d) else: tmp = 2.0 * (c + (a + d)) return tmp
function code(a, b, c, d) tmp = 0.0 if (Float64(c + d) <= 16.05805) tmp = Float64(2.0 * Float64(a + d)); else tmp = Float64(2.0 * Float64(c + Float64(a + d))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c + d) <= 16.05805) tmp = 2.0 * (a + d); else tmp = 2.0 * (c + (a + d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[N[(c + d), $MachinePrecision], 16.05805], N[(2.0 * N[(a + d), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(c + N[(a + d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c + d \leq 16.05805:\\
\;\;\;\;2 \cdot \left(a + d\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(c + \left(a + d\right)\right)\\
\end{array}
\end{array}
if (+.f64 c d) < 16.058050000000001Initial program 94.7%
*-commutative94.7%
+-commutative94.7%
+-commutative94.7%
associate-+r+95.4%
+-commutative95.4%
associate-+r+94.7%
Simplified94.7%
Taylor expanded in b around 0 6.3%
+-commutative6.3%
Simplified6.3%
Taylor expanded in c around 0 12.5%
if 16.058050000000001 < (+.f64 c d) Initial program 94.1%
*-commutative94.1%
+-commutative94.1%
+-commutative94.1%
associate-+r+95.7%
+-commutative95.7%
associate-+r+95.1%
Simplified95.1%
Taylor expanded in b around 0 14.2%
associate-+r+14.2%
+-commutative14.2%
associate-+l+14.2%
Simplified14.2%
Final simplification13.7%
(FPCore (a b c d) :precision binary64 (* 2.0 (+ a (+ c (+ b d)))))
double code(double a, double b, double c, double d) {
return 2.0 * (a + (c + (b + 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 + (c + (b + d)))
end function
public static double code(double a, double b, double c, double d) {
return 2.0 * (a + (c + (b + d)));
}
def code(a, b, c, d): return 2.0 * (a + (c + (b + d)))
function code(a, b, c, d) return Float64(2.0 * Float64(a + Float64(c + Float64(b + d)))) end
function tmp = code(a, b, c, d) tmp = 2.0 * (a + (c + (b + d))); end
code[a_, b_, c_, d_] := N[(2.0 * N[(a + N[(c + N[(b + d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(a + \left(c + \left(b + d\right)\right)\right)
\end{array}
Initial program 94.3%
*-commutative94.3%
+-commutative94.3%
+-commutative94.3%
associate-+r+95.6%
+-commutative95.6%
associate-+r+95.0%
Simplified95.0%
Final simplification95.0%
(FPCore (a b c d) :precision binary64 (if (<= d 12.82) (* 2.0 (+ a d)) (* 2.0 c)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= 12.82) {
tmp = 2.0 * (a + d);
} else {
tmp = 2.0 * c;
}
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.82d0) then
tmp = 2.0d0 * (a + d)
else
tmp = 2.0d0 * c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= 12.82) {
tmp = 2.0 * (a + d);
} else {
tmp = 2.0 * c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= 12.82: tmp = 2.0 * (a + d) else: tmp = 2.0 * c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= 12.82) tmp = Float64(2.0 * Float64(a + d)); else tmp = Float64(2.0 * c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= 12.82) tmp = 2.0 * (a + d); else tmp = 2.0 * c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, 12.82], N[(2.0 * N[(a + d), $MachinePrecision]), $MachinePrecision], N[(2.0 * c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq 12.82:\\
\;\;\;\;2 \cdot \left(a + d\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot c\\
\end{array}
\end{array}
if d < 12.82Initial program 94.8%
*-commutative94.8%
+-commutative94.8%
+-commutative94.8%
associate-+r+95.6%
+-commutative95.6%
associate-+r+95.1%
Simplified95.1%
Taylor expanded in b around 0 6.6%
+-commutative6.6%
Simplified6.6%
Taylor expanded in c around 0 12.1%
if 12.82 < d Initial program 94.0%
*-commutative94.0%
+-commutative94.0%
+-commutative94.0%
associate-+r+95.6%
+-commutative95.6%
associate-+r+95.0%
Simplified95.0%
Taylor expanded in c around inf 14.2%
Final simplification13.5%
(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.3%
*-commutative94.3%
+-commutative94.3%
+-commutative94.3%
associate-+r+95.6%
+-commutative95.6%
associate-+r+95.0%
Simplified95.0%
Taylor expanded in b around inf 6.1%
Final simplification6.1%
(FPCore (a b c d) :precision binary64 (* 2.0 c))
double code(double a, double b, double c, double d) {
return 2.0 * c;
}
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
end function
public static double code(double a, double b, double c, double d) {
return 2.0 * c;
}
def code(a, b, c, d): return 2.0 * c
function code(a, b, c, d) return Float64(2.0 * c) end
function tmp = code(a, b, c, d) tmp = 2.0 * c; end
code[a_, b_, c_, d_] := N[(2.0 * c), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot c
\end{array}
Initial program 94.3%
*-commutative94.3%
+-commutative94.3%
+-commutative94.3%
associate-+r+95.6%
+-commutative95.6%
associate-+r+95.0%
Simplified95.0%
Taylor expanded in c around inf 11.7%
Final simplification11.7%
(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 2023314
(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))