
(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 (+ a d))) 2.0))
double code(double a, double b, double c, double d) {
return (b + (c + (a + 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 = (b + (c + (a + d))) * 2.0d0
end function
public static double code(double a, double b, double c, double d) {
return (b + (c + (a + d))) * 2.0;
}
def code(a, b, c, d): return (b + (c + (a + d))) * 2.0
function code(a, b, c, d) return Float64(Float64(b + Float64(c + Float64(a + d))) * 2.0) end
function tmp = code(a, b, c, d) tmp = (b + (c + (a + d))) * 2.0; end
code[a_, b_, c_, d_] := N[(N[(b + N[(c + N[(a + d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]
\begin{array}{l}
\\
\left(b + \left(c + \left(a + d\right)\right)\right) \cdot 2
\end{array}
Initial program 94.4%
associate-+r+95.7%
+-commutative95.7%
associate-+r+95.3%
Simplified95.3%
Taylor expanded in a around 0 94.4%
+-commutative94.4%
associate-+r+95.7%
associate-+l+100.0%
+-commutative100.0%
associate-+r+100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b c d) :precision binary64 (if (<= (+ c d) 16.03) (* (+ a d) 2.0) (* (+ c (+ a d)) 2.0)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c + d) <= 16.03) {
tmp = (a + d) * 2.0;
} else {
tmp = (c + (a + d)) * 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 ((c + d) <= 16.03d0) then
tmp = (a + d) * 2.0d0
else
tmp = (c + (a + d)) * 2.0d0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c + d) <= 16.03) {
tmp = (a + d) * 2.0;
} else {
tmp = (c + (a + d)) * 2.0;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c + d) <= 16.03: tmp = (a + d) * 2.0 else: tmp = (c + (a + d)) * 2.0 return tmp
function code(a, b, c, d) tmp = 0.0 if (Float64(c + d) <= 16.03) tmp = Float64(Float64(a + d) * 2.0); else tmp = Float64(Float64(c + Float64(a + d)) * 2.0); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c + d) <= 16.03) tmp = (a + d) * 2.0; else tmp = (c + (a + d)) * 2.0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[N[(c + d), $MachinePrecision], 16.03], N[(N[(a + d), $MachinePrecision] * 2.0), $MachinePrecision], N[(N[(c + N[(a + d), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c + d \leq 16.03:\\
\;\;\;\;\left(a + d\right) \cdot 2\\
\mathbf{else}:\\
\;\;\;\;\left(c + \left(a + d\right)\right) \cdot 2\\
\end{array}
\end{array}
if (+.f64 c d) < 16.030000000000001Initial program 95.1%
Taylor expanded in b around 0 5.7%
+-commutative5.7%
+-commutative5.7%
associate-+r+5.7%
Simplified5.7%
Taylor expanded in c around 0 13.3%
if 16.030000000000001 < (+.f64 c d) Initial program 94.2%
Taylor expanded in b around 0 14.7%
associate-+r+14.7%
+-commutative14.7%
associate-+l+14.7%
Simplified14.7%
Final simplification14.2%
(FPCore (a b c d) :precision binary64 (if (<= d 12.68) (* (+ a d) 2.0) (* c 2.0)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= 12.68) {
tmp = (a + d) * 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 (d <= 12.68d0) then
tmp = (a + d) * 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 (d <= 12.68) {
tmp = (a + d) * 2.0;
} else {
tmp = c * 2.0;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= 12.68: tmp = (a + d) * 2.0 else: tmp = c * 2.0 return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= 12.68) tmp = Float64(Float64(a + d) * 2.0); else tmp = Float64(c * 2.0); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= 12.68) tmp = (a + d) * 2.0; else tmp = c * 2.0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, 12.68], N[(N[(a + d), $MachinePrecision] * 2.0), $MachinePrecision], N[(c * 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq 12.68:\\
\;\;\;\;\left(a + d\right) \cdot 2\\
\mathbf{else}:\\
\;\;\;\;c \cdot 2\\
\end{array}
\end{array}
if d < 12.68Initial program 95.4%
Taylor expanded in b around 0 4.4%
+-commutative4.4%
+-commutative4.4%
associate-+r+4.4%
Simplified4.4%
Taylor expanded in c around 0 14.9%
if 12.68 < d Initial program 94.2%
Taylor expanded in c around inf 13.6%
Final simplification13.8%
(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.4%
Final simplification94.4%
(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.4%
associate-+r+95.7%
+-commutative95.7%
associate-+r+95.3%
Simplified95.3%
Final simplification95.3%
(FPCore (a b c d) :precision binary64 (if (<= d 12.68) (* b 2.0) (* c 2.0)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= 12.68) {
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 (d <= 12.68d0) 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 (d <= 12.68) {
tmp = b * 2.0;
} else {
tmp = c * 2.0;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= 12.68: tmp = b * 2.0 else: tmp = c * 2.0 return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= 12.68) 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 (d <= 12.68) tmp = b * 2.0; else tmp = c * 2.0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, 12.68], N[(b * 2.0), $MachinePrecision], N[(c * 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq 12.68:\\
\;\;\;\;b \cdot 2\\
\mathbf{else}:\\
\;\;\;\;c \cdot 2\\
\end{array}
\end{array}
if d < 12.68Initial program 95.4%
Taylor expanded in b around inf 13.5%
if 12.68 < d Initial program 94.2%
Taylor expanded in c around inf 13.6%
Final simplification13.6%
(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.4%
Taylor expanded in b around inf 6.0%
Final simplification6.0%
(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 2024048
(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)))
:alt
(+ (* (+ a b) 2.0) (* (+ c d) 2.0))
(* (+ a (+ b (+ c d))) 2.0))