| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 320 |
\[t \cdot \left(t \cdot 4 \cdot 10^{-32}\right)
\]

(FPCore (t) :precision binary64 (+ (* (+ 1.0 (* t 2e-16)) (+ 1.0 (* t 2e-16))) (- -1.0 (* 2.0 (* t 2e-16)))))
(FPCore (t) :precision binary64 (* t (* t 4e-32)))
double code(double t) {
return ((1.0 + (t * 2e-16)) * (1.0 + (t * 2e-16))) + (-1.0 - (2.0 * (t * 2e-16)));
}
double code(double t) {
return t * (t * 4e-32);
}
real(8) function code(t)
real(8), intent (in) :: t
code = ((1.0d0 + (t * 2d-16)) * (1.0d0 + (t * 2d-16))) + ((-1.0d0) - (2.0d0 * (t * 2d-16)))
end function
real(8) function code(t)
real(8), intent (in) :: t
code = t * (t * 4d-32)
end function
public static double code(double t) {
return ((1.0 + (t * 2e-16)) * (1.0 + (t * 2e-16))) + (-1.0 - (2.0 * (t * 2e-16)));
}
public static double code(double t) {
return t * (t * 4e-32);
}
def code(t): return ((1.0 + (t * 2e-16)) * (1.0 + (t * 2e-16))) + (-1.0 - (2.0 * (t * 2e-16)))
def code(t): return t * (t * 4e-32)
function code(t) return Float64(Float64(Float64(1.0 + Float64(t * 2e-16)) * Float64(1.0 + Float64(t * 2e-16))) + Float64(-1.0 - Float64(2.0 * Float64(t * 2e-16)))) end
function code(t) return Float64(t * Float64(t * 4e-32)) end
function tmp = code(t) tmp = ((1.0 + (t * 2e-16)) * (1.0 + (t * 2e-16))) + (-1.0 - (2.0 * (t * 2e-16))); end
function tmp = code(t) tmp = t * (t * 4e-32); end
code[t_] := N[(N[(N[(1.0 + N[(t * 2e-16), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(t * 2e-16), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 - N[(2.0 * N[(t * 2e-16), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[t_] := N[(t * N[(t * 4e-32), $MachinePrecision]), $MachinePrecision]
\left(1 + t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + \left(-1 - 2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right)
t \cdot \left(t \cdot 4 \cdot 10^{-32}\right)
Herbie found 2 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 3.4% |
|---|---|
| Target | 21.0% |
| Herbie | 99.4% |
Initial program 3.4%
Simplified99.5%
[Start]3.4% | \[ \left(1 + t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + \left(-1 - 2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right)
\] |
|---|---|
associate-+r- [=>]9.9% | \[ \color{blue}{\left(\left(1 + t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + -1\right) - 2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)}
\] |
sub-neg [=>]9.9% | \[ \color{blue}{\left(\left(1 + t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + -1\right) + \left(-2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right)}
\] |
+-commutative [=>]9.9% | \[ \color{blue}{\left(-2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right) + \left(\left(1 + t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + -1\right)}
\] |
difference-of-sqr--1 [=>]9.9% | \[ \left(-2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right) + \color{blue}{\left(\left(1 + t \cdot 2 \cdot 10^{-16}\right) + 1\right) \cdot \left(\left(1 + t \cdot 2 \cdot 10^{-16}\right) - 1\right)}
\] |
+-commutative [=>]9.9% | \[ \left(-2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right) + \left(\left(1 + t \cdot 2 \cdot 10^{-16}\right) + 1\right) \cdot \left(\color{blue}{\left(t \cdot 2 \cdot 10^{-16} + 1\right)} - 1\right)
\] |
associate--l+ [=>]3.4% | \[ \left(-2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right) + \left(\left(1 + t \cdot 2 \cdot 10^{-16}\right) + 1\right) \cdot \color{blue}{\left(t \cdot 2 \cdot 10^{-16} + \left(1 - 1\right)\right)}
\] |
metadata-eval [=>]3.4% | \[ \left(-2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right) + \left(\left(1 + t \cdot 2 \cdot 10^{-16}\right) + 1\right) \cdot \left(t \cdot 2 \cdot 10^{-16} + \color{blue}{0}\right)
\] |
+-rgt-identity [=>]3.4% | \[ \left(-2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right) + \left(\left(1 + t \cdot 2 \cdot 10^{-16}\right) + 1\right) \cdot \color{blue}{\left(t \cdot 2 \cdot 10^{-16}\right)}
\] |
distribute-lft1-in [<=]20.8% | \[ \left(-2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right) + \color{blue}{\left(\left(1 + t \cdot 2 \cdot 10^{-16}\right) \cdot \left(t \cdot 2 \cdot 10^{-16}\right) + t \cdot 2 \cdot 10^{-16}\right)}
\] |
*-commutative [<=]20.8% | \[ \left(-2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right) + \left(\color{blue}{\left(t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right)} + t \cdot 2 \cdot 10^{-16}\right)
\] |
associate-+r+ [=>]20.8% | \[ \color{blue}{\left(\left(-2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right) + \left(t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right)\right) + t \cdot 2 \cdot 10^{-16}}
\] |
+-commutative [<=]20.8% | \[ \color{blue}{\left(\left(t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + \left(-2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right)\right)} + t \cdot 2 \cdot 10^{-16}
\] |
+-commutative [=>]20.8% | \[ \color{blue}{t \cdot 2 \cdot 10^{-16} + \left(\left(t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + \left(-2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right)\right)}
\] |
*-rgt-identity [<=]20.8% | \[ \color{blue}{\left(t \cdot 2 \cdot 10^{-16}\right) \cdot 1} + \left(\left(t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + \left(-2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right)\right)
\] |
Final simplification99.5%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 320 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 320 |
herbie shell --seed 2023178
(FPCore (t)
:name "fma_test1"
:precision binary64
:pre (and (<= 0.9 t) (<= t 1.1))
:herbie-target
(fma (+ 1.0 (* t 2e-16)) (+ 1.0 (* t 2e-16)) (- -1.0 (* 2.0 (* t 2e-16))))
(+ (* (+ 1.0 (* t 2e-16)) (+ 1.0 (* t 2e-16))) (- -1.0 (* 2.0 (* t 2e-16)))))