| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 576 |
\[x \cdot x + 3 \cdot \left(y \cdot y\right)
\]
(FPCore (x y) :precision binary64 (+ (+ (+ (* x x) (* y y)) (* y y)) (* y y)))
(FPCore (x y) :precision binary64 (+ (* x x) (* y (+ (+ y y) y))))
double code(double x, double y) {
return (((x * x) + (y * y)) + (y * y)) + (y * y);
}
double code(double x, double y) {
return (x * x) + (y * ((y + y) + y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (((x * x) + (y * y)) + (y * y)) + (y * y)
end function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * x) + (y * ((y + y) + y))
end function
public static double code(double x, double y) {
return (((x * x) + (y * y)) + (y * y)) + (y * y);
}
public static double code(double x, double y) {
return (x * x) + (y * ((y + y) + y));
}
def code(x, y): return (((x * x) + (y * y)) + (y * y)) + (y * y)
def code(x, y): return (x * x) + (y * ((y + y) + y))
function code(x, y) return Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(y * y)) + Float64(y * y)) end
function code(x, y) return Float64(Float64(x * x) + Float64(y * Float64(Float64(y + y) + y))) end
function tmp = code(x, y) tmp = (((x * x) + (y * y)) + (y * y)) + (y * y); end
function tmp = code(x, y) tmp = (x * x) + (y * ((y + y) + y)); end
code[x_, y_] := N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(N[(x * x), $MachinePrecision] + N[(y * N[(N[(y + y), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y
x \cdot x + y \cdot \left(\left(y + y\right) + y\right)
Results
| Original | 0.1 |
|---|---|
| Target | 0.1 |
| Herbie | 0.1 |
Initial program 0.1
Simplified0.1
[Start]0.1 | \[ \left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y
\] |
|---|---|
rational_best-simplify-1 [=>]0.1 | \[ \color{blue}{y \cdot y + \left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right)}
\] |
rational_best-simplify-1 [=>]0.1 | \[ y \cdot y + \color{blue}{\left(y \cdot y + \left(x \cdot x + y \cdot y\right)\right)}
\] |
rational_best-simplify-43 [=>]0.1 | \[ \color{blue}{\left(x \cdot x + y \cdot y\right) + \left(y \cdot y + y \cdot y\right)}
\] |
rational_best-simplify-1 [=>]0.1 | \[ \color{blue}{\left(y \cdot y + y \cdot y\right) + \left(x \cdot x + y \cdot y\right)}
\] |
rational_best-simplify-1 [=>]0.1 | \[ \left(y \cdot y + y \cdot y\right) + \color{blue}{\left(y \cdot y + x \cdot x\right)}
\] |
rational_best-simplify-43 [=>]0.1 | \[ \color{blue}{x \cdot x + \left(y \cdot y + \left(y \cdot y + y \cdot y\right)\right)}
\] |
rational_best-simplify-47 [=>]0.1 | \[ x \cdot x + \left(y \cdot y + \color{blue}{y \cdot \left(y + y\right)}\right)
\] |
rational_best-simplify-47 [=>]0.1 | \[ x \cdot x + \color{blue}{y \cdot \left(\left(y + y\right) + y\right)}
\] |
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 576 |
| Alternative 2 | |
|---|---|
| Error | 28.1 |
| Cost | 320 |
| Alternative 3 | |
|---|---|
| Error | 28.0 |
| Cost | 320 |
herbie shell --seed 2023094
(FPCore (x y)
:name "Linear.Quaternion:$c/ from linear-1.19.1.3, E"
:precision binary64
:herbie-target
(+ (* x x) (* y (+ y (+ y y))))
(+ (+ (+ (* x x) (* y y)) (* y y)) (* y y)))