
(FPCore (a b c d) :precision binary64 (* a (+ (+ b c) d)))
double code(double a, double b, double c, double d) {
return 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 = a * ((b + c) + d)
end function
public static double code(double a, double b, double c, double d) {
return a * ((b + c) + d);
}
def code(a, b, c, d): return a * ((b + c) + d)
function code(a, b, c, d) return Float64(a * Float64(Float64(b + c) + d)) end
function tmp = code(a, b, c, d) tmp = a * ((b + c) + d); end
code[a_, b_, c_, d_] := N[(a * N[(N[(b + c), $MachinePrecision] + d), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot \left(\left(b + c\right) + d\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (* a (+ (+ b c) d)))
double code(double a, double b, double c, double d) {
return 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 = a * ((b + c) + d)
end function
public static double code(double a, double b, double c, double d) {
return a * ((b + c) + d);
}
def code(a, b, c, d): return a * ((b + c) + d)
function code(a, b, c, d) return Float64(a * Float64(Float64(b + c) + d)) end
function tmp = code(a, b, c, d) tmp = a * ((b + c) + d); end
code[a_, b_, c_, d_] := N[(a * N[(N[(b + c), $MachinePrecision] + d), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot \left(\left(b + c\right) + d\right)
\end{array}
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. (FPCore (a b c d) :precision binary64 (fma (+ b d) a (* c a)))
assert(a < b && b < c && c < d);
double code(double a, double b, double c, double d) {
return fma((b + d), a, (c * a));
}
a, b, c, d = sort([a, b, c, d]) function code(a, b, c, d) return fma(Float64(b + d), a, Float64(c * a)) end
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. code[a_, b_, c_, d_] := N[(N[(b + d), $MachinePrecision] * a + N[(c * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b, c, d] = \mathsf{sort}([a, b, c, d])\\
\\
\mathsf{fma}\left(b + d, a, c \cdot a\right)
\end{array}
Initial program 100.0%
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-+.f64N/A
associate-+r+N/A
distribute-rgt-inN/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
Final simplification100.0%
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. (FPCore (a b c d) :precision binary64 (* (+ (+ c d) b) a))
assert(a < b && b < c && c < d);
double code(double a, double b, double c, double d) {
return ((c + d) + b) * a;
}
NOTE: a, b, c, and d should be sorted in increasing order before calling this function.
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
end function
assert a < b && b < c && c < d;
public static double code(double a, double b, double c, double d) {
return ((c + d) + b) * a;
}
[a, b, c, d] = sort([a, b, c, d]) def code(a, b, c, d): return ((c + d) + b) * a
a, b, c, d = sort([a, b, c, d]) function code(a, b, c, d) return Float64(Float64(Float64(c + d) + b) * a) end
a, b, c, d = num2cell(sort([a, b, c, d])){:}
function tmp = code(a, b, c, d)
tmp = ((c + d) + b) * a;
end
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. code[a_, b_, c_, d_] := N[(N[(N[(c + d), $MachinePrecision] + b), $MachinePrecision] * a), $MachinePrecision]
\begin{array}{l}
[a, b, c, d] = \mathsf{sort}([a, b, c, d])\\
\\
\left(\left(c + d\right) + b\right) \cdot a
\end{array}
Initial program 100.0%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Final simplification100.0%
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. (FPCore (a b c d) :precision binary64 (* (+ (+ c b) d) a))
assert(a < b && b < c && c < d);
double code(double a, double b, double c, double d) {
return ((c + b) + d) * a;
}
NOTE: a, b, c, and d should be sorted in increasing order before calling this function.
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 + b) + d) * a
end function
assert a < b && b < c && c < d;
public static double code(double a, double b, double c, double d) {
return ((c + b) + d) * a;
}
[a, b, c, d] = sort([a, b, c, d]) def code(a, b, c, d): return ((c + b) + d) * a
a, b, c, d = sort([a, b, c, d]) function code(a, b, c, d) return Float64(Float64(Float64(c + b) + d) * a) end
a, b, c, d = num2cell(sort([a, b, c, d])){:}
function tmp = code(a, b, c, d)
tmp = ((c + b) + d) * a;
end
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. code[a_, b_, c_, d_] := N[(N[(N[(c + b), $MachinePrecision] + d), $MachinePrecision] * a), $MachinePrecision]
\begin{array}{l}
[a, b, c, d] = \mathsf{sort}([a, b, c, d])\\
\\
\left(\left(c + b\right) + d\right) \cdot a
\end{array}
Initial program 100.0%
Final simplification100.0%
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. (FPCore (a b c d) :precision binary64 (* (+ c d) a))
assert(a < b && b < c && c < d);
double code(double a, double b, double c, double d) {
return (c + d) * a;
}
NOTE: a, b, c, and d should be sorted in increasing order before calling this function.
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) * a
end function
assert a < b && b < c && c < d;
public static double code(double a, double b, double c, double d) {
return (c + d) * a;
}
[a, b, c, d] = sort([a, b, c, d]) def code(a, b, c, d): return (c + d) * a
a, b, c, d = sort([a, b, c, d]) function code(a, b, c, d) return Float64(Float64(c + d) * a) end
a, b, c, d = num2cell(sort([a, b, c, d])){:}
function tmp = code(a, b, c, d)
tmp = (c + d) * a;
end
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. code[a_, b_, c_, d_] := N[(N[(c + d), $MachinePrecision] * a), $MachinePrecision]
\begin{array}{l}
[a, b, c, d] = \mathsf{sort}([a, b, c, d])\\
\\
\left(c + d\right) \cdot a
\end{array}
Initial program 100.0%
Taylor expanded in b around 0
+-commutativeN/A
lower-+.f6465.7
Applied rewrites65.7%
Final simplification65.7%
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. (FPCore (a b c d) :precision binary64 (* a d))
assert(a < b && b < c && c < d);
double code(double a, double b, double c, double d) {
return a * d;
}
NOTE: a, b, c, and d should be sorted in increasing order before calling this function.
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 * d
end function
assert a < b && b < c && c < d;
public static double code(double a, double b, double c, double d) {
return a * d;
}
[a, b, c, d] = sort([a, b, c, d]) def code(a, b, c, d): return a * d
a, b, c, d = sort([a, b, c, d]) function code(a, b, c, d) return Float64(a * d) end
a, b, c, d = num2cell(sort([a, b, c, d])){:}
function tmp = code(a, b, c, d)
tmp = a * d;
end
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. code[a_, b_, c_, d_] := N[(a * d), $MachinePrecision]
\begin{array}{l}
[a, b, c, d] = \mathsf{sort}([a, b, c, d])\\
\\
a \cdot d
\end{array}
Initial program 100.0%
Taylor expanded in d around inf
*-commutativeN/A
lower-*.f6434.0
Applied rewrites34.0%
Final simplification34.0%
(FPCore (a b c d) :precision binary64 (+ (* a b) (* a (+ c d))))
double code(double a, double b, double c, double d) {
return (a * b) + (a * (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 = (a * b) + (a * (c + d))
end function
public static double code(double a, double b, double c, double d) {
return (a * b) + (a * (c + d));
}
def code(a, b, c, d): return (a * b) + (a * (c + d))
function code(a, b, c, d) return Float64(Float64(a * b) + Float64(a * Float64(c + d))) end
function tmp = code(a, b, c, d) tmp = (a * b) + (a * (c + d)); end
code[a_, b_, c_, d_] := N[(N[(a * b), $MachinePrecision] + N[(a * N[(c + d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot b + a \cdot \left(c + d\right)
\end{array}
herbie shell --seed 2024295
(FPCore (a b c d)
:name "Expression, p14"
:precision binary64
:pre (and (and (and (and (<= 56789.0 a) (<= a 98765.0)) (and (<= 0.0 b) (<= b 1.0))) (and (<= 0.0 c) (<= c 0.0016773))) (and (<= 0.0 d) (<= d 0.0016773)))
:alt
(! :herbie-platform default (+ (* a b) (* a (+ c d))))
(* a (+ (+ b c) d)))