Average Error: 0.1 → 0.1
Time: 4.1s
Precision: binary64
Cost: 576
\[\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y \]
\[x \cdot x + y \cdot \left(y \cdot 3\right) \]
(FPCore (x y) :precision binary64 (+ (+ (+ (* x x) (* y y)) (* y y)) (* y y)))
(FPCore (x y) :precision binary64 (+ (* x x) (* y (* y 3.0))))
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 * 3.0));
}
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 * 3.0d0))
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 * 3.0));
}
def code(x, y):
	return (((x * x) + (y * y)) + (y * y)) + (y * y)
def code(x, y):
	return (x * x) + (y * (y * 3.0))
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(y * 3.0)))
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 * 3.0));
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[(y * 3.0), $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(y \cdot 3\right)

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original0.1
Target0.1
Herbie0.1
\[x \cdot x + y \cdot \left(y + \left(y + y\right)\right) \]

Derivation

  1. Initial program 0.1

    \[\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y \]
  2. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, y \cdot 3, x \cdot x\right)} \]
  3. Applied egg-rr0.1

    \[\leadsto \color{blue}{x \cdot x + y \cdot \left(y \cdot 3\right)} \]
  4. Final simplification0.1

    \[\leadsto x \cdot x + y \cdot \left(y \cdot 3\right) \]

Alternatives

Alternative 1
Error12.2
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -5.549769124776599 \cdot 10^{-47}:\\ \;\;\;\;y \cdot \left(y \cdot 3\right)\\ \mathbf{elif}\;y \leq 1.6841103331661773 \cdot 10^{-84}:\\ \;\;\;\;x \cdot x + y \cdot y\\ \mathbf{else}:\\ \;\;\;\;3 \cdot \left(y \cdot y\right)\\ \end{array} \]
Alternative 2
Error12.8
Cost584
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 3\right)\\ \mathbf{if}\;y \leq -5.549769124776599 \cdot 10^{-47}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.6841103331661773 \cdot 10^{-84}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error12.8
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -5.549769124776599 \cdot 10^{-47}:\\ \;\;\;\;y \cdot \left(y \cdot 3\right)\\ \mathbf{elif}\;y \leq 1.6841103331661773 \cdot 10^{-84}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;3 \cdot \left(y \cdot y\right)\\ \end{array} \]
Alternative 4
Error25.4
Cost452
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 4.333696481422957 \cdot 10^{-301}:\\ \;\;\;\;y \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 5
Error51.0
Cost192
\[y \cdot y \]

Error

Reproduce

herbie shell --seed 2022325 
(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)))