?

Average Error: 22.0 → 0.1
Time: 13.8s
Precision: binary64
Cost: 7240

?

\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
\[\begin{array}{l} t_0 := \frac{1 - x}{y}\\ t_1 := \frac{-1}{y \cdot y}\\ \mathbf{if}\;y \leq -290000:\\ \;\;\;\;t_0 \cdot \left(1 - t_1\right) + \left(x + t_1\right)\\ \mathbf{elif}\;y \leq 116000000:\\ \;\;\;\;\mathsf{fma}\left(\frac{x + -1}{y + 1}, y, 1\right)\\ \mathbf{else}:\\ \;\;\;\;x + t_0\\ \end{array} \]
(FPCore (x y) :precision binary64 (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (- 1.0 x) y)) (t_1 (/ -1.0 (* y y))))
   (if (<= y -290000.0)
     (+ (* t_0 (- 1.0 t_1)) (+ x t_1))
     (if (<= y 116000000.0) (fma (/ (+ x -1.0) (+ y 1.0)) y 1.0) (+ x t_0)))))
double code(double x, double y) {
	return 1.0 - (((1.0 - x) * y) / (y + 1.0));
}
double code(double x, double y) {
	double t_0 = (1.0 - x) / y;
	double t_1 = -1.0 / (y * y);
	double tmp;
	if (y <= -290000.0) {
		tmp = (t_0 * (1.0 - t_1)) + (x + t_1);
	} else if (y <= 116000000.0) {
		tmp = fma(((x + -1.0) / (y + 1.0)), y, 1.0);
	} else {
		tmp = x + t_0;
	}
	return tmp;
}
function code(x, y)
	return Float64(1.0 - Float64(Float64(Float64(1.0 - x) * y) / Float64(y + 1.0)))
end
function code(x, y)
	t_0 = Float64(Float64(1.0 - x) / y)
	t_1 = Float64(-1.0 / Float64(y * y))
	tmp = 0.0
	if (y <= -290000.0)
		tmp = Float64(Float64(t_0 * Float64(1.0 - t_1)) + Float64(x + t_1));
	elseif (y <= 116000000.0)
		tmp = fma(Float64(Float64(x + -1.0) / Float64(y + 1.0)), y, 1.0);
	else
		tmp = Float64(x + t_0);
	end
	return tmp
end
code[x_, y_] := N[(1.0 - N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := Block[{t$95$0 = N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]}, Block[{t$95$1 = N[(-1.0 / N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -290000.0], N[(N[(t$95$0 * N[(1.0 - t$95$1), $MachinePrecision]), $MachinePrecision] + N[(x + t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 116000000.0], N[(N[(N[(x + -1.0), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision] * y + 1.0), $MachinePrecision], N[(x + t$95$0), $MachinePrecision]]]]]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
t_0 := \frac{1 - x}{y}\\
t_1 := \frac{-1}{y \cdot y}\\
\mathbf{if}\;y \leq -290000:\\
\;\;\;\;t_0 \cdot \left(1 - t_1\right) + \left(x + t_1\right)\\

\mathbf{elif}\;y \leq 116000000:\\
\;\;\;\;\mathsf{fma}\left(\frac{x + -1}{y + 1}, y, 1\right)\\

\mathbf{else}:\\
\;\;\;\;x + t_0\\


\end{array}

Error?

Target

Original22.0
Target0.2
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;y < -3693.8482788297247:\\ \;\;\;\;\frac{1}{y} - \left(\frac{x}{y} - x\right)\\ \mathbf{elif}\;y < 6799310503.41891:\\ \;\;\;\;1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y} - \left(\frac{x}{y} - x\right)\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if y < -2.9e5

    1. Initial program 45.7

      \[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
    2. Simplified30.7

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

      [Start]45.7

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

      sub-neg [=>]45.7

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

      +-commutative [=>]45.7

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

      *-lft-identity [<=]45.7

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

      associate-/l* [=>]30.7

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

      distribute-neg-frac [=>]30.7

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

      associate-*r/ [=>]30.7

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

      associate-*l/ [<=]30.7

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

      fma-def [=>]30.7

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

      associate-/l* [<=]30.7

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

      *-lft-identity [=>]30.7

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

      +-commutative [=>]30.7

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

      neg-sub0 [=>]30.7

      \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{0 - \left(1 - x\right)}, 1\right) \]

      associate--r- [=>]30.7

      \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{\left(0 - 1\right) + x}, 1\right) \]

      metadata-eval [=>]30.7

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

      +-commutative [<=]30.7

      \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{x + -1}, 1\right) \]
    3. Taylor expanded in y around inf 0.0

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

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

      [Start]0.0

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

      sub-neg [=>]0.0

      \[ \color{blue}{\left(\frac{x}{{y}^{2}} + \left(-1 \cdot \frac{x - 1}{y} + \left(-1 \cdot \frac{x - 1}{{y}^{3}} + x\right)\right)\right) + \left(-\frac{1}{{y}^{2}}\right)} \]

      +-commutative [=>]0.0

      \[ \color{blue}{\left(\left(-1 \cdot \frac{x - 1}{y} + \left(-1 \cdot \frac{x - 1}{{y}^{3}} + x\right)\right) + \frac{x}{{y}^{2}}\right)} + \left(-\frac{1}{{y}^{2}}\right) \]

      associate-+l+ [=>]0.0

      \[ \color{blue}{\left(-1 \cdot \frac{x - 1}{y} + \left(-1 \cdot \frac{x - 1}{{y}^{3}} + x\right)\right) + \left(\frac{x}{{y}^{2}} + \left(-\frac{1}{{y}^{2}}\right)\right)} \]

      associate-+r+ [=>]0.0

      \[ \color{blue}{\left(\left(-1 \cdot \frac{x - 1}{y} + -1 \cdot \frac{x - 1}{{y}^{3}}\right) + x\right)} + \left(\frac{x}{{y}^{2}} + \left(-\frac{1}{{y}^{2}}\right)\right) \]

      associate-+l+ [=>]0.0

      \[ \color{blue}{\left(-1 \cdot \frac{x - 1}{y} + -1 \cdot \frac{x - 1}{{y}^{3}}\right) + \left(x + \left(\frac{x}{{y}^{2}} + \left(-\frac{1}{{y}^{2}}\right)\right)\right)} \]
    5. Taylor expanded in x around 0 0.1

      \[\leadsto \frac{x + -1}{y} \cdot \left(-1 + \frac{-1}{y \cdot y}\right) + \left(x + \color{blue}{\frac{-1}{{y}^{2}}}\right) \]
    6. Simplified0.1

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

      [Start]0.1

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

      unpow2 [=>]0.1

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

    if -2.9e5 < y < 1.16e8

    1. Initial program 0.1

      \[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
    2. Simplified0.1

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

      [Start]0.1

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

      sub-neg [=>]0.1

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

      +-commutative [=>]0.1

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

      neg-mul-1 [=>]0.1

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

      associate-*l/ [<=]0.1

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

      associate-*r* [=>]0.1

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

      fma-def [=>]0.1

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

      associate-*r/ [=>]0.1

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

      neg-mul-1 [<=]0.1

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

      neg-sub0 [=>]0.1

      \[ \mathsf{fma}\left(\frac{\color{blue}{0 - \left(1 - x\right)}}{y + 1}, y, 1\right) \]

      associate--r- [=>]0.1

      \[ \mathsf{fma}\left(\frac{\color{blue}{\left(0 - 1\right) + x}}{y + 1}, y, 1\right) \]

      metadata-eval [=>]0.1

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

      +-commutative [<=]0.1

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

      +-commutative [=>]0.1

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

    if 1.16e8 < y

    1. Initial program 45.5

      \[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
    2. Simplified29.5

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

      [Start]45.5

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

      remove-double-neg [<=]45.5

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

      neg-mul-1 [=>]45.5

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

      associate-*l/ [<=]29.5

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

      associate-*r* [=>]29.5

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

      distribute-lft-neg-in [=>]29.5

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

      distribute-lft-neg-in [=>]29.5

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

      metadata-eval [=>]29.5

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

      *-lft-identity [=>]29.5

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

      +-commutative [=>]29.5

      \[ 1 - \frac{1 - x}{\color{blue}{1 + y}} \cdot y \]
    3. Taylor expanded in y around inf 0.2

      \[\leadsto \color{blue}{\left(\frac{1}{y} + x\right) - \frac{x}{y}} \]
    4. Simplified0.2

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

      [Start]0.2

      \[ \left(\frac{1}{y} + x\right) - \frac{x}{y} \]

      +-commutative [=>]0.2

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

      associate--l+ [=>]0.2

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

      div-sub [<=]0.2

      \[ x + \color{blue}{\frac{1 - x}{y}} \]

      sub-neg [=>]0.2

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

      mul-1-neg [<=]0.2

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

      +-commutative [=>]0.2

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

      metadata-eval [<=]0.2

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

      distribute-lft-in [<=]0.2

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

      metadata-eval [<=]0.2

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

      sub-neg [<=]0.2

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

      associate-*r/ [<=]0.2

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

      mul-1-neg [=>]0.2

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

      unsub-neg [=>]0.2

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

      sub-neg [=>]0.2

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

      metadata-eval [=>]0.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -290000:\\ \;\;\;\;\frac{1 - x}{y} \cdot \left(1 - \frac{-1}{y \cdot y}\right) + \left(x + \frac{-1}{y \cdot y}\right)\\ \mathbf{elif}\;y \leq 116000000:\\ \;\;\;\;\mathsf{fma}\left(\frac{x + -1}{y + 1}, y, 1\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{1 - x}{y}\\ \end{array} \]

Alternatives

Alternative 1
Error0.3
Cost7620
\[\begin{array}{l} t_0 := \frac{y \cdot \left(1 - x\right)}{y + 1}\\ t_1 := \frac{-1}{y \cdot y}\\ t_2 := \frac{y}{y + 1}\\ \mathbf{if}\;t_0 \leq 0.9995:\\ \;\;\;\;\mathsf{fma}\left(t_2, x + -1, 1\right)\\ \mathbf{elif}\;t_0 \leq 1.00005:\\ \;\;\;\;\frac{1 - x}{y} \cdot \left(1 - t_1\right) + \left(x + t_1\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot t_2\\ \end{array} \]
Alternative 2
Error0.1
Cost1476
\[\begin{array}{l} t_0 := \frac{1 - x}{y}\\ t_1 := \frac{-1}{y \cdot y}\\ \mathbf{if}\;y \leq -3200000:\\ \;\;\;\;t_0 \cdot \left(1 - t_1\right) + \left(x + t_1\right)\\ \mathbf{elif}\;y \leq 190000000:\\ \;\;\;\;1 - \frac{y \cdot \left(1 - x\right)}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;x + t_0\\ \end{array} \]
Alternative 3
Error0.1
Cost1092
\[\begin{array}{l} t_0 := \frac{1 - x}{y}\\ \mathbf{if}\;y \leq -245000:\\ \;\;\;\;\left(x - \frac{1 - x}{y \cdot y}\right) + t_0\\ \mathbf{elif}\;y \leq 57000000:\\ \;\;\;\;1 - \frac{y \cdot \left(1 - x\right)}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;x + t_0\\ \end{array} \]
Alternative 4
Error0.1
Cost969
\[\begin{array}{l} \mathbf{if}\;y \leq -108000000 \lor \neg \left(y \leq 230000000\right):\\ \;\;\;\;x + \frac{1 - x}{y}\\ \mathbf{else}:\\ \;\;\;\;1 - y \cdot \frac{1 - x}{y + 1}\\ \end{array} \]
Alternative 5
Error0.2
Cost969
\[\begin{array}{l} \mathbf{if}\;y \leq -68000000 \lor \neg \left(y \leq 230000000\right):\\ \;\;\;\;x + \frac{1 - x}{y}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{y \cdot \left(1 - x\right)}{y + 1}\\ \end{array} \]
Alternative 6
Error8.4
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -5.5 \cdot 10^{-9} \lor \neg \left(y \leq 0.027\right):\\ \;\;\;\;x \cdot \frac{y}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;1 + y \cdot x\\ \end{array} \]
Alternative 7
Error8.3
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1.1 \cdot 10^{-6} \lor \neg \left(y \leq 0.027\right):\\ \;\;\;\;x \cdot \frac{y}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;1 + y \cdot \left(x + -1\right)\\ \end{array} \]
Alternative 8
Error1.0
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;x + \frac{1 - x}{y}\\ \mathbf{else}:\\ \;\;\;\;1 + y \cdot \left(x + -1\right)\\ \end{array} \]
Alternative 9
Error16.1
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;x - \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;1 - y\\ \end{array} \]
Alternative 10
Error8.6
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 5\right):\\ \;\;\;\;x - \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;1 + y \cdot x\\ \end{array} \]
Alternative 11
Error16.3
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 0.035:\\ \;\;\;\;1 - y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error16.5
Cost328
\[\begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 0.032:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error38.6
Cost64
\[1 \]

Error

Reproduce?

herbie shell --seed 2023054 
(FPCore (x y)
  :name "Diagrams.Trail:splitAtParam  from diagrams-lib-1.3.0.3, D"
  :precision binary64

  :herbie-target
  (if (< y -3693.8482788297247) (- (/ 1.0 y) (- (/ x y) x)) (if (< y 6799310503.41891) (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))) (- (/ 1.0 y) (- (/ x y) x))))

  (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))