
(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 (* (+ b (+ c (+ d a))) 2.0))
double code(double a, double b, double c, double d) {
return (b + (c + (d + a))) * 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 + (c + (d + a))) * 2.0d0
end function
public static double code(double a, double b, double c, double d) {
return (b + (c + (d + a))) * 2.0;
}
def code(a, b, c, d): return (b + (c + (d + a))) * 2.0
function code(a, b, c, d) return Float64(Float64(b + Float64(c + Float64(d + a))) * 2.0) end
function tmp = code(a, b, c, d) tmp = (b + (c + (d + a))) * 2.0; end
code[a_, b_, c_, d_] := N[(N[(b + N[(c + N[(d + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]
\begin{array}{l}
\\
\left(b + \left(c + \left(d + a\right)\right)\right) \cdot 2
\end{array}
Initial program 94.2%
+-commutative94.2%
associate-+r+95.1%
+-commutative95.1%
Simplified95.1%
Taylor expanded in a around 0 94.2%
+-commutative94.2%
associate-+l+94.2%
associate-+l+100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b c d) :precision binary64 (if (<= b -2.6132) (* 2.0 (+ d a)) (* (+ c (+ d a)) 2.0)))
double code(double a, double b, double c, double d) {
double tmp;
if (b <= -2.6132) {
tmp = 2.0 * (d + a);
} else {
tmp = (c + (d + a)) * 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.6132d0)) then
tmp = 2.0d0 * (d + a)
else
tmp = (c + (d + a)) * 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.6132) {
tmp = 2.0 * (d + a);
} else {
tmp = (c + (d + a)) * 2.0;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if b <= -2.6132: tmp = 2.0 * (d + a) else: tmp = (c + (d + a)) * 2.0 return tmp
function code(a, b, c, d) tmp = 0.0 if (b <= -2.6132) tmp = Float64(2.0 * Float64(d + a)); else tmp = Float64(Float64(c + Float64(d + a)) * 2.0); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (b <= -2.6132) tmp = 2.0 * (d + a); else tmp = (c + (d + a)) * 2.0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[b, -2.6132], N[(2.0 * N[(d + a), $MachinePrecision]), $MachinePrecision], N[(N[(c + N[(d + a), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.6132:\\
\;\;\;\;2 \cdot \left(d + a\right)\\
\mathbf{else}:\\
\;\;\;\;\left(c + \left(d + a\right)\right) \cdot 2\\
\end{array}
\end{array}
if b < -2.6132Initial program 93.9%
Taylor expanded in b around 0 7.4%
+-commutative7.4%
Simplified7.4%
Taylor expanded in c around 0 14.0%
if -2.6132 < b Initial program 94.4%
Taylor expanded in b around 0 14.3%
+-commutative14.3%
associate-+l+14.3%
Simplified14.3%
Final simplification14.2%
(FPCore (a b c d) :precision binary64 (if (<= b -2.6132) (* 2.0 (+ d a)) (* c 2.0)))
double code(double a, double b, double c, double d) {
double tmp;
if (b <= -2.6132) {
tmp = 2.0 * (d + a);
} 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.6132d0)) then
tmp = 2.0d0 * (d + a)
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.6132) {
tmp = 2.0 * (d + a);
} else {
tmp = c * 2.0;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if b <= -2.6132: tmp = 2.0 * (d + a) else: tmp = c * 2.0 return tmp
function code(a, b, c, d) tmp = 0.0 if (b <= -2.6132) tmp = Float64(2.0 * Float64(d + a)); else tmp = Float64(c * 2.0); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (b <= -2.6132) tmp = 2.0 * (d + a); else tmp = c * 2.0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[b, -2.6132], N[(2.0 * N[(d + a), $MachinePrecision]), $MachinePrecision], N[(c * 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.6132:\\
\;\;\;\;2 \cdot \left(d + a\right)\\
\mathbf{else}:\\
\;\;\;\;c \cdot 2\\
\end{array}
\end{array}
if b < -2.6132Initial program 93.9%
Taylor expanded in b around 0 7.4%
+-commutative7.4%
Simplified7.4%
Taylor expanded in c around 0 14.0%
if -2.6132 < b Initial program 94.4%
Taylor expanded in c around inf 14.2%
Final simplification14.1%
(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 (+ 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.2%
+-commutative94.2%
associate-+r+95.1%
+-commutative95.1%
Simplified95.1%
Final simplification95.1%
(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.4%
Final simplification6.4%
(FPCore (a b c d) :precision binary64 (* c 2.0))
double code(double a, double b, double c, double d) {
return c * 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 * 2.0d0
end function
public static double code(double a, double b, double c, double d) {
return c * 2.0;
}
def code(a, b, c, d): return c * 2.0
function code(a, b, c, d) return Float64(c * 2.0) end
function tmp = code(a, b, c, d) tmp = c * 2.0; end
code[a_, b_, c_, d_] := N[(c * 2.0), $MachinePrecision]
\begin{array}{l}
\\
c \cdot 2
\end{array}
Initial program 94.2%
Taylor expanded in c around inf 11.4%
Final simplification11.4%
(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 2024041
(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))