| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 836 |
\[\begin{array}{l}
\mathbf{if}\;y \leq 9.2 \cdot 10^{+131}:\\
\;\;\;\;y \cdot y + x \cdot \left(x + y \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\]

(FPCore (x y) :precision binary64 (+ (+ (* x x) (* (* x 2.0) y)) (* y y)))
(FPCore (x y) :precision binary64 (if (<= y 9.2e+131) (+ (* y y) (* x (+ x (* y 2.0)))) (* y y)))
double code(double x, double y) {
return ((x * x) + ((x * 2.0) * y)) + (y * y);
}
double code(double x, double y) {
double tmp;
if (y <= 9.2e+131) {
tmp = (y * y) + (x * (x + (y * 2.0)));
} else {
tmp = y * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * x) + ((x * 2.0d0) * y)) + (y * y)
end function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 9.2d+131) then
tmp = (y * y) + (x * (x + (y * 2.0d0)))
else
tmp = y * y
end if
code = tmp
end function
public static double code(double x, double y) {
return ((x * x) + ((x * 2.0) * y)) + (y * y);
}
public static double code(double x, double y) {
double tmp;
if (y <= 9.2e+131) {
tmp = (y * y) + (x * (x + (y * 2.0)));
} else {
tmp = y * y;
}
return tmp;
}
def code(x, y): return ((x * x) + ((x * 2.0) * y)) + (y * y)
def code(x, y): tmp = 0 if y <= 9.2e+131: tmp = (y * y) + (x * (x + (y * 2.0))) else: tmp = y * y return tmp
function code(x, y) return Float64(Float64(Float64(x * x) + Float64(Float64(x * 2.0) * y)) + Float64(y * y)) end
function code(x, y) tmp = 0.0 if (y <= 9.2e+131) tmp = Float64(Float64(y * y) + Float64(x * Float64(x + Float64(y * 2.0)))); else tmp = Float64(y * y); end return tmp end
function tmp = code(x, y) tmp = ((x * x) + ((x * 2.0) * y)) + (y * y); end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 9.2e+131) tmp = (y * y) + (x * (x + (y * 2.0))); else tmp = y * y; end tmp_2 = tmp; end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[LessEqual[y, 9.2e+131], N[(N[(y * y), $MachinePrecision] + N[(x * N[(x + N[(y * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * y), $MachinePrecision]]
\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y
\begin{array}{l}
\mathbf{if}\;y \leq 9.2 \cdot 10^{+131}:\\
\;\;\;\;y \cdot y + x \cdot \left(x + y \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 93.4% |
|---|---|
| Target | 93.5% |
| Herbie | 99.4% |
if y < 9.19999999999999966e131Initial program 97.7%
Simplified98.2%
[Start]97.7% | \[ \left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y
\] |
|---|---|
associate-+l+ [=>]97.7% | \[ \color{blue}{x \cdot x + \left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)}
\] |
fma-def [=>]97.7% | \[ \color{blue}{\mathsf{fma}\left(x, x, \left(x \cdot 2\right) \cdot y + y \cdot y\right)}
\] |
distribute-rgt-out [=>]98.2% | \[ \mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(x \cdot 2 + y\right)}\right)
\] |
Applied egg-rr99.5%
[Start]98.2% | \[ \mathsf{fma}\left(x, x, y \cdot \left(x \cdot 2 + y\right)\right)
\] |
|---|---|
fma-udef [=>]98.2% | \[ \color{blue}{x \cdot x + y \cdot \left(x \cdot 2 + y\right)}
\] |
distribute-rgt-in [=>]97.7% | \[ x \cdot x + \color{blue}{\left(\left(x \cdot 2\right) \cdot y + y \cdot y\right)}
\] |
associate-+l+ [<=]97.7% | \[ \color{blue}{\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y}
\] |
+-commutative [=>]97.7% | \[ \color{blue}{y \cdot y + \left(x \cdot x + \left(x \cdot 2\right) \cdot y\right)}
\] |
associate-*l* [=>]97.7% | \[ y \cdot y + \left(x \cdot x + \color{blue}{x \cdot \left(2 \cdot y\right)}\right)
\] |
distribute-lft-out [=>]99.5% | \[ y \cdot y + \color{blue}{x \cdot \left(x + 2 \cdot y\right)}
\] |
if 9.19999999999999966e131 < y Initial program 75.0%
Taylor expanded in x around 0 97.5%
Simplified97.5%
[Start]97.5% | \[ {y}^{2}
\] |
|---|---|
unpow2 [=>]97.5% | \[ \color{blue}{y \cdot y}
\] |
Final simplification99.2%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 836 |
| Alternative 2 | |
|---|---|
| Accuracy | 96.5% |
| Cost | 6976 |
| Alternative 3 | |
|---|---|
| Accuracy | 87.5% |
| Cost | 708 |
| Alternative 4 | |
|---|---|
| Accuracy | 87.5% |
| Cost | 580 |
| Alternative 5 | |
|---|---|
| Accuracy | 87.3% |
| Cost | 324 |
| Alternative 6 | |
|---|---|
| Accuracy | 58.0% |
| Cost | 192 |
herbie shell --seed 2023165
(FPCore (x y)
:name "Examples.Basics.ProofTests:f4 from sbv-4.4"
:precision binary64
:herbie-target
(+ (* x x) (+ (* y y) (* (* x y) 2.0)))
(+ (+ (* x x) (* (* x 2.0) y)) (* y y)))