Average Error: 0.0 → 0.0
Time: 5.4s
Precision: binary64
Cost: 6848
\[\left(x \cdot 2 + x \cdot x\right) + y \cdot y \]
\[\mathsf{fma}\left(x, x + 2, y \cdot y\right) \]
(FPCore (x y) :precision binary64 (+ (+ (* x 2.0) (* x x)) (* y y)))
(FPCore (x y) :precision binary64 (fma x (+ x 2.0) (* y y)))
double code(double x, double y) {
	return ((x * 2.0) + (x * x)) + (y * y);
}
double code(double x, double y) {
	return fma(x, (x + 2.0), (y * y));
}
function code(x, y)
	return Float64(Float64(Float64(x * 2.0) + Float64(x * x)) + Float64(y * y))
end
function code(x, y)
	return fma(x, Float64(x + 2.0), Float64(y * y))
end
code[x_, y_] := N[(N[(N[(x * 2.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(x * N[(x + 2.0), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\left(x \cdot 2 + x \cdot x\right) + y \cdot y
\mathsf{fma}\left(x, x + 2, y \cdot y\right)

Error

Target

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

Derivation

  1. Initial program 0.0

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, x + 2, y \cdot y\right)} \]
    Proof
    (fma.f64 x (+.f64 x 2) (*.f64 y y)): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= +-commutative_binary64 (+.f64 2 x)) (*.f64 y y)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (+.f64 2 x)) (*.f64 y y))): 1 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 x 2) (*.f64 x x))) (*.f64 y y)): 2 points increase in error, 2 points decrease in error
  3. Final simplification0.0

    \[\leadsto \mathsf{fma}\left(x, x + 2, y \cdot y\right) \]

Alternatives

Alternative 1
Error22.3
Cost984
\[\begin{array}{l} \mathbf{if}\;y \leq -215985320980887.78:\\ \;\;\;\;y \cdot y\\ \mathbf{elif}\;y \leq -4.242225852482202 \cdot 10^{-12}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;y \leq -1.1593907907873194 \cdot 10^{-53}:\\ \;\;\;\;y \cdot y\\ \mathbf{elif}\;y \leq -4.390927486027955 \cdot 10^{-94}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;y \leq 4.617822764299996 \cdot 10^{-140}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;y \leq 1.7831774463707052 \cdot 10^{-78}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot y\\ \end{array} \]
Alternative 2
Error10.4
Cost976
\[\begin{array}{l} \mathbf{if}\;y \leq -215985320980887.78:\\ \;\;\;\;y \cdot y\\ \mathbf{elif}\;y \leq -4.242225852482202 \cdot 10^{-12}:\\ \;\;\;\;x \cdot \left(x + 2\right)\\ \mathbf{elif}\;y \leq -1.1593907907873194 \cdot 10^{-53}:\\ \;\;\;\;y \cdot y\\ \mathbf{elif}\;y \leq 1.0909908214281765 \cdot 10^{-48}:\\ \;\;\;\;x \cdot x + x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;y \cdot y\\ \end{array} \]
Alternative 3
Error10.4
Cost848
\[\begin{array}{l} t_0 := x \cdot \left(x + 2\right)\\ \mathbf{if}\;y \leq -215985320980887.78:\\ \;\;\;\;y \cdot y\\ \mathbf{elif}\;y \leq -4.242225852482202 \cdot 10^{-12}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.1593907907873194 \cdot 10^{-53}:\\ \;\;\;\;y \cdot y\\ \mathbf{elif}\;y \leq 1.0909908214281765 \cdot 10^{-48}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot y\\ \end{array} \]
Alternative 4
Error3.8
Cost712
\[\begin{array}{l} t_0 := y \cdot y + x \cdot x\\ \mathbf{if}\;y \leq -1.1593907907873194 \cdot 10^{-53}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.4999802173120513 \cdot 10^{-87}:\\ \;\;\;\;x \cdot x + x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error1.4
Cost712
\[\begin{array}{l} t_0 := y \cdot y + x \cdot x\\ \mathbf{if}\;x \leq -7798.089763353559:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.653666071327896 \cdot 10^{-11}:\\ \;\;\;\;y \cdot y + x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error0.0
Cost704
\[y \cdot y + \left(x \cdot x + x \cdot 2\right) \]
Alternative 7
Error21.2
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -7.778144112658781 \cdot 10^{-92}:\\ \;\;\;\;y \cdot y\\ \mathbf{elif}\;y \leq 1.8827211628113101 \cdot 10^{-81}:\\ \;\;\;\;x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;y \cdot y\\ \end{array} \]
Alternative 8
Error42.1
Cost192
\[x \cdot 2 \]

Error

Reproduce

herbie shell --seed 2022295 
(FPCore (x y)
  :name "Numeric.Log:$clog1p from log-domain-0.10.2.1, A"
  :precision binary64

  :herbie-target
  (+ (* y y) (+ (* 2.0 x) (* x x)))

  (+ (+ (* x 2.0) (* x x)) (* y y)))