?

Average Error: 5.4 → 0.1
Time: 5.6s
Precision: binary64
Cost: 6984

?

\[x \cdot \left(1 + y \cdot y\right) \]
\[\begin{array}{l} \mathbf{if}\;y \leq -8 \cdot 10^{+52}:\\ \;\;\;\;y \cdot \left(y \cdot x\right)\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{+133}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(y, y, 1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{\frac{1}{y}}\\ \end{array} \]
(FPCore (x y) :precision binary64 (* x (+ 1.0 (* y y))))
(FPCore (x y)
 :precision binary64
 (if (<= y -8e+52)
   (* y (* y x))
   (if (<= y 3.2e+133) (* x (fma y y 1.0)) (/ (* y x) (/ 1.0 y)))))
double code(double x, double y) {
	return x * (1.0 + (y * y));
}
double code(double x, double y) {
	double tmp;
	if (y <= -8e+52) {
		tmp = y * (y * x);
	} else if (y <= 3.2e+133) {
		tmp = x * fma(y, y, 1.0);
	} else {
		tmp = (y * x) / (1.0 / y);
	}
	return tmp;
}
function code(x, y)
	return Float64(x * Float64(1.0 + Float64(y * y)))
end
function code(x, y)
	tmp = 0.0
	if (y <= -8e+52)
		tmp = Float64(y * Float64(y * x));
	elseif (y <= 3.2e+133)
		tmp = Float64(x * fma(y, y, 1.0));
	else
		tmp = Float64(Float64(y * x) / Float64(1.0 / y));
	end
	return tmp
end
code[x_, y_] := N[(x * N[(1.0 + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[LessEqual[y, -8e+52], N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.2e+133], N[(x * N[(y * y + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(y * x), $MachinePrecision] / N[(1.0 / y), $MachinePrecision]), $MachinePrecision]]]
x \cdot \left(1 + y \cdot y\right)
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{+52}:\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\

\mathbf{elif}\;y \leq 3.2 \cdot 10^{+133}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(y, y, 1\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{y \cdot x}{\frac{1}{y}}\\


\end{array}

Error?

Target

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

Derivation?

  1. Split input into 3 regimes
  2. if y < -7.9999999999999999e52

    1. Initial program 23.2

      \[x \cdot \left(1 + y \cdot y\right) \]
    2. Taylor expanded in y around inf 23.2

      \[\leadsto \color{blue}{{y}^{2} \cdot x} \]
    3. Simplified0.3

      \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot y} \]
      Proof

      [Start]23.2

      \[ {y}^{2} \cdot x \]

      *-commutative [=>]23.2

      \[ \color{blue}{x \cdot {y}^{2}} \]

      unpow2 [=>]23.2

      \[ x \cdot \color{blue}{\left(y \cdot y\right)} \]

      associate-*r* [=>]0.3

      \[ \color{blue}{\left(x \cdot y\right) \cdot y} \]

    if -7.9999999999999999e52 < y < 3.19999999999999997e133

    1. Initial program 0.1

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

      \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(y, y, 1\right)} \]
      Proof

      [Start]0.1

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

      +-commutative [=>]0.1

      \[ x \cdot \color{blue}{\left(y \cdot y + 1\right)} \]

      fma-def [=>]0.1

      \[ x \cdot \color{blue}{\mathsf{fma}\left(y, y, 1\right)} \]

    if 3.19999999999999997e133 < y

    1. Initial program 51.4

      \[x \cdot \left(1 + y \cdot y\right) \]
    2. Applied egg-rr64.0

      \[\leadsto \color{blue}{\frac{x \cdot \left(1 - {y}^{4}\right)}{1 - y \cdot y}} \]
    3. Simplified64.0

      \[\leadsto \color{blue}{\frac{x}{\frac{1 - y \cdot y}{1 - {y}^{4}}}} \]
      Proof

      [Start]64.0

      \[ \frac{x \cdot \left(1 - {y}^{4}\right)}{1 - y \cdot y} \]

      associate-/l* [=>]64.0

      \[ \color{blue}{\frac{x}{\frac{1 - y \cdot y}{1 - {y}^{4}}}} \]
    4. Taylor expanded in y around inf 51.4

      \[\leadsto \frac{x}{\color{blue}{\frac{1}{{y}^{2}}}} \]
    5. Simplified48.7

      \[\leadsto \frac{x}{\color{blue}{\frac{\frac{1}{y}}{y}}} \]
      Proof

      [Start]51.4

      \[ \frac{x}{\frac{1}{{y}^{2}}} \]

      unpow2 [=>]51.4

      \[ \frac{x}{\frac{1}{\color{blue}{y \cdot y}}} \]

      associate-/r* [=>]48.7

      \[ \frac{x}{\color{blue}{\frac{\frac{1}{y}}{y}}} \]
    6. Applied egg-rr0.4

      \[\leadsto \color{blue}{\frac{x}{\frac{-1}{y}} \cdot \left(-y\right)} \]
    7. Applied egg-rr0.4

      \[\leadsto \color{blue}{\frac{x \cdot y}{\frac{1}{y}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -8 \cdot 10^{+52}:\\ \;\;\;\;y \cdot \left(y \cdot x\right)\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{+133}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(y, y, 1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{\frac{1}{y}}\\ \end{array} \]

Alternatives

Alternative 1
Error0.1
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -98000000 \lor \neg \left(y \leq 1.6 \cdot 10^{+19}\right):\\ \;\;\;\;y \cdot \left(y \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 + y \cdot y\right)\\ \end{array} \]
Alternative 2
Error0.1
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -95000000 \lor \neg \left(y \leq 10^{+19}\right):\\ \;\;\;\;y \cdot \left(y \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \left(y \cdot y\right)\\ \end{array} \]
Alternative 3
Error0.1
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -126000000:\\ \;\;\;\;y \cdot \left(y \cdot x\right)\\ \mathbf{elif}\;y \leq 10^{+132}:\\ \;\;\;\;x + x \cdot \left(y \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{\frac{1}{y}}\\ \end{array} \]
Alternative 4
Error1.0
Cost580
\[\begin{array}{l} \mathbf{if}\;y \cdot y \leq 0.005:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(y \cdot x\right)\\ \end{array} \]
Alternative 5
Error20.8
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023060 
(FPCore (x y)
  :name "Numeric.Integration.TanhSinh:everywhere from integration-0.2.1"
  :precision binary64

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

  (* x (+ 1.0 (* y y))))