| Alternative 1 | |
|---|---|
| Error | 85.23% |
| Cost | 580 |
\[\begin{array}{l}
\mathbf{if}\;c + d \leq 15.946:\\
\;\;\;\;b \cdot 2\\
\mathbf{else}:\\
\;\;\;\;\left(c + b\right) \cdot 2\\
\end{array}
\]
(FPCore (a b c d) :precision binary64 (* (+ a (+ b (+ c d))) 2.0))
(FPCore (a b c d) :precision binary64 (* (+ (+ c b) (+ a d)) 2.0))
double code(double a, double b, double c, double d) {
return (a + (b + (c + d))) * 2.0;
}
double code(double a, double b, double c, double d) {
return ((c + b) + (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 = (a + (b + (c + d))) * 2.0d0
end 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) + (a + d)) * 2.0d0
end function
public static double code(double a, double b, double c, double d) {
return (a + (b + (c + d))) * 2.0;
}
public static double code(double a, double b, double c, double d) {
return ((c + b) + (a + d)) * 2.0;
}
def code(a, b, c, d): return (a + (b + (c + d))) * 2.0
def code(a, b, c, d): return ((c + b) + (a + d)) * 2.0
function code(a, b, c, d) return Float64(Float64(a + Float64(b + Float64(c + d))) * 2.0) end
function code(a, b, c, d) return Float64(Float64(Float64(c + b) + Float64(a + d)) * 2.0) end
function tmp = code(a, b, c, d) tmp = (a + (b + (c + d))) * 2.0; end
function tmp = code(a, b, c, d) tmp = ((c + b) + (a + d)) * 2.0; end
code[a_, b_, c_, d_] := N[(N[(a + N[(b + N[(c + d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]
code[a_, b_, c_, d_] := N[(N[(N[(c + b), $MachinePrecision] + N[(a + d), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]
\left(a + \left(b + \left(c + d\right)\right)\right) \cdot 2
\left(\left(c + b\right) + \left(a + d\right)\right) \cdot 2
Results
| Original | 5.64% |
|---|---|
| Target | 5.93% |
| Herbie | 0% |
Initial program 5.64
Applied egg-rr4.49
Simplified4.43
[Start]4.49 | \[ \left(\left(\left(a + \left(b + d\right)\right) + e^{\mathsf{log1p}\left(c\right)}\right) - 1\right) \cdot 2
\] |
|---|---|
associate--l+ [=>]4.49 | \[ \color{blue}{\left(\left(a + \left(b + d\right)\right) + \left(e^{\mathsf{log1p}\left(c\right)} - 1\right)\right)} \cdot 2
\] |
associate-+l+ [=>]5.18 | \[ \color{blue}{\left(a + \left(\left(b + d\right) + \left(e^{\mathsf{log1p}\left(c\right)} - 1\right)\right)\right)} \cdot 2
\] |
+-commutative [<=]5.18 | \[ \left(a + \left(\color{blue}{\left(d + b\right)} + \left(e^{\mathsf{log1p}\left(c\right)} - 1\right)\right)\right) \cdot 2
\] |
associate-+l+ [=>]4.47 | \[ \left(a + \color{blue}{\left(d + \left(b + \left(e^{\mathsf{log1p}\left(c\right)} - 1\right)\right)\right)}\right) \cdot 2
\] |
expm1-def [=>]4.43 | \[ \left(a + \left(d + \left(b + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(c\right)\right)}\right)\right)\right) \cdot 2
\] |
Applied egg-rr2.66
Applied egg-rr0
Final simplification0
| Alternative 1 | |
|---|---|
| Error | 85.23% |
| Cost | 580 |
| Alternative 2 | |
|---|---|
| Error | 83.95% |
| Cost | 580 |
| Alternative 3 | |
|---|---|
| Error | 5.64% |
| Cost | 576 |
| Alternative 4 | |
|---|---|
| Error | 4.31% |
| Cost | 576 |
| Alternative 5 | |
|---|---|
| Error | 0.04% |
| Cost | 576 |
| Alternative 6 | |
|---|---|
| Error | 87.62% |
| Cost | 324 |
| Alternative 7 | |
|---|---|
| Error | 93.79% |
| Cost | 192 |
herbie shell --seed 2023102
(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))