
(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(Float64(b + 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[(N[(b + c), $MachinePrecision] + N[(a + d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(\left(b + c\right) + \left(a + d\right)\right)
\end{array}
Initial program 94.3%
lift-+.f64N/A
+-commutativeN/A
lift-+.f64N/A
lift-+.f64N/A
associate-+r+N/A
associate-+l+N/A
+-commutativeN/A
lower-+.f64N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (a b c d) :precision binary64 (if (<= (+ (+ (+ c d) b) a) -0.002) (* (+ a d) 2.0) (* (+ (+ c a) d) 2.0)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((c + d) + b) + a) <= -0.002) {
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) + b) + a) <= (-0.002d0)) 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) + b) + a) <= -0.002) {
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) + b) + a) <= -0.002: 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(Float64(Float64(c + d) + b) + a) <= -0.002) tmp = Float64(Float64(a + d) * 2.0); else tmp = Float64(Float64(Float64(c + a) + d) * 2.0); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((((c + d) + b) + a) <= -0.002) 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[(N[(N[(c + d), $MachinePrecision] + b), $MachinePrecision] + a), $MachinePrecision], -0.002], N[(N[(a + d), $MachinePrecision] * 2.0), $MachinePrecision], N[(N[(N[(c + a), $MachinePrecision] + d), $MachinePrecision] * 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(\left(c + d\right) + b\right) + a \leq -0.002:\\
\;\;\;\;\left(a + d\right) \cdot 2\\
\mathbf{else}:\\
\;\;\;\;\left(\left(c + a\right) + d\right) \cdot 2\\
\end{array}
\end{array}
if (+.f64 a (+.f64 b (+.f64 c d))) < -2e-3Initial program 93.7%
Taylor expanded in b around 0
+-commutativeN/A
lower-+.f641.6
Applied rewrites1.6%
Taylor expanded in b around 0
+-commutativeN/A
associate-+r+N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f641.6
Applied rewrites1.6%
Applied rewrites1.6%
Taylor expanded in c around 0
Applied rewrites17.9%
if -2e-3 < (+.f64 a (+.f64 b (+.f64 c d))) Initial program 94.5%
Taylor expanded in b around 0
+-commutativeN/A
lower-+.f6416.6
Applied rewrites16.6%
Taylor expanded in b around 0
+-commutativeN/A
associate-+r+N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6416.6
Applied rewrites16.6%
Applied rewrites16.6%
Final simplification17.0%
(FPCore (a b c d) :precision binary64 (if (<= (+ (+ (+ c d) b) a) -0.002) (* (+ a d) 2.0) (* 2.0 c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((c + d) + b) + a) <= -0.002) {
tmp = (a + d) * 2.0;
} 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 ((((c + d) + b) + a) <= (-0.002d0)) then
tmp = (a + d) * 2.0d0
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 ((((c + d) + b) + a) <= -0.002) {
tmp = (a + d) * 2.0;
} else {
tmp = 2.0 * c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (((c + d) + b) + a) <= -0.002: tmp = (a + d) * 2.0 else: tmp = 2.0 * c return tmp
function code(a, b, c, d) tmp = 0.0 if (Float64(Float64(Float64(c + d) + b) + a) <= -0.002) tmp = Float64(Float64(a + d) * 2.0); else tmp = Float64(2.0 * c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((((c + d) + b) + a) <= -0.002) tmp = (a + d) * 2.0; else tmp = 2.0 * c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(c + d), $MachinePrecision] + b), $MachinePrecision] + a), $MachinePrecision], -0.002], N[(N[(a + d), $MachinePrecision] * 2.0), $MachinePrecision], N[(2.0 * c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(\left(c + d\right) + b\right) + a \leq -0.002:\\
\;\;\;\;\left(a + d\right) \cdot 2\\
\mathbf{else}:\\
\;\;\;\;2 \cdot c\\
\end{array}
\end{array}
if (+.f64 a (+.f64 b (+.f64 c d))) < -2e-3Initial program 93.7%
Taylor expanded in b around 0
+-commutativeN/A
lower-+.f641.6
Applied rewrites1.6%
Taylor expanded in b around 0
+-commutativeN/A
associate-+r+N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f641.6
Applied rewrites1.6%
Applied rewrites1.6%
Taylor expanded in c around 0
Applied rewrites17.9%
if -2e-3 < (+.f64 a (+.f64 b (+.f64 c d))) Initial program 94.5%
Taylor expanded in c around inf
lower-*.f6416.5
Applied rewrites16.5%
Final simplification16.9%
(FPCore (a b c d) :precision binary64 (if (<= (+ (+ (+ c d) b) a) -0.002) (* 2.0 b) (* 2.0 c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((c + d) + b) + a) <= -0.002) {
tmp = 2.0 * b;
} 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 ((((c + d) + b) + a) <= (-0.002d0)) then
tmp = 2.0d0 * b
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 ((((c + d) + b) + a) <= -0.002) {
tmp = 2.0 * b;
} else {
tmp = 2.0 * c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (((c + d) + b) + a) <= -0.002: tmp = 2.0 * b else: tmp = 2.0 * c return tmp
function code(a, b, c, d) tmp = 0.0 if (Float64(Float64(Float64(c + d) + b) + a) <= -0.002) tmp = Float64(2.0 * b); else tmp = Float64(2.0 * c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((((c + d) + b) + a) <= -0.002) tmp = 2.0 * b; else tmp = 2.0 * c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(c + d), $MachinePrecision] + b), $MachinePrecision] + a), $MachinePrecision], -0.002], N[(2.0 * b), $MachinePrecision], N[(2.0 * c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(\left(c + d\right) + b\right) + a \leq -0.002:\\
\;\;\;\;2 \cdot b\\
\mathbf{else}:\\
\;\;\;\;2 \cdot c\\
\end{array}
\end{array}
if (+.f64 a (+.f64 b (+.f64 c d))) < -2e-3Initial program 93.7%
Taylor expanded in b around inf
lower-*.f6416.0
Applied rewrites16.0%
if -2e-3 < (+.f64 a (+.f64 b (+.f64 c d))) Initial program 94.5%
Taylor expanded in c around inf
lower-*.f6416.5
Applied rewrites16.5%
Final simplification16.3%
(FPCore (a b c d) :precision binary64 (* (+ (+ (+ c d) b) a) 2.0))
double code(double a, double b, double c, double d) {
return (((c + d) + b) + 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 = (((c + d) + b) + a) * 2.0d0
end function
public static double code(double a, double b, double c, double d) {
return (((c + d) + b) + a) * 2.0;
}
def code(a, b, c, d): return (((c + d) + b) + a) * 2.0
function code(a, b, c, d) return Float64(Float64(Float64(Float64(c + d) + b) + a) * 2.0) end
function tmp = code(a, b, c, d) tmp = (((c + d) + b) + a) * 2.0; end
code[a_, b_, c_, d_] := N[(N[(N[(N[(c + d), $MachinePrecision] + b), $MachinePrecision] + a), $MachinePrecision] * 2.0), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(c + d\right) + b\right) + a\right) \cdot 2
\end{array}
Initial program 94.3%
Final simplification94.3%
(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%
Taylor expanded in b around inf
lower-*.f646.0
Applied rewrites6.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 2024284
(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
(! :herbie-platform default (let ((e 2)) (+ (* (+ a b) e) (* (+ c d) e))))
(* (+ a (+ b (+ c d))) 2.0))