?

Average Error: 35.34% → 0.18%
Time: 9.7s
Precision: binary64
Cost: 7240

?

\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
\[\begin{array}{l} t_0 := \frac{1 - x}{y}\\ \mathbf{if}\;y \leq -2450000:\\ \;\;\;\;\left(x + \frac{-1}{y \cdot y}\right) + t_0\\ \mathbf{elif}\;y \leq 205000000:\\ \;\;\;\;\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)))
   (if (<= y -2450000.0)
     (+ (+ x (/ -1.0 (* y y))) t_0)
     (if (<= y 205000000.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 tmp;
	if (y <= -2450000.0) {
		tmp = (x + (-1.0 / (y * y))) + t_0;
	} else if (y <= 205000000.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)
	tmp = 0.0
	if (y <= -2450000.0)
		tmp = Float64(Float64(x + Float64(-1.0 / Float64(y * y))) + t_0);
	elseif (y <= 205000000.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]}, If[LessEqual[y, -2450000.0], N[(N[(x + N[(-1.0 / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision], If[LessEqual[y, 205000000.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}\\
\mathbf{if}\;y \leq -2450000:\\
\;\;\;\;\left(x + \frac{-1}{y \cdot y}\right) + t_0\\

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

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


\end{array}

Error?

Target

Original35.34%
Target0.38%
Herbie0.18%
\[\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.45e6

    1. Initial program 71.31

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

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

      [Start]71.31

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

      remove-double-neg [<=]71.31

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

      distribute-neg-frac [=>]71.31

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

      distribute-rgt-neg-in [=>]71.31

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

      associate-/l* [=>]44.56

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

      distribute-frac-neg [<=]44.56

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

      /-rgt-identity [<=]44.56

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

      neg-mul-1 [=>]44.56

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

      *-commutative [=>]44.56

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

      associate-/l* [=>]44.56

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

      metadata-eval [=>]44.56

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

      associate-/r* [<=]44.56

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

      mul-1-neg [=>]44.56

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

      *-rgt-identity [<=]44.56

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

      mul-1-neg [<=]44.56

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

      associate-*l/ [=>]44.56

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

      *-commutative [=>]44.56

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

      times-frac [=>]44.56

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

      metadata-eval [=>]44.56

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

      mul-1-neg [=>]44.56

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

      remove-double-neg [=>]44.56

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

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

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

      [Start]0.03

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

      associate--l+ [=>]0.03

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

      +-commutative [=>]0.03

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

      associate-+l- [=>]0.03

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

      +-commutative [=>]0.03

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

      mul-1-neg [=>]0.03

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

      unsub-neg [=>]0.03

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

      mul-1-neg [=>]0.03

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

      sub-neg [<=]0.03

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

      unpow2 [=>]0.03

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

      div-sub [<=]0.03

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

      sub-neg [=>]0.03

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

      metadata-eval [=>]0.03

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

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

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

      [Start]0.04

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

      unpow2 [=>]0.04

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

    if -2.45e6 < y < 2.05e8

    1. Initial program 0.23

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

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

      [Start]0.23

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

      sub-neg [=>]0.23

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

      +-commutative [=>]0.23

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

      neg-mul-1 [=>]0.23

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

      associate-*l/ [<=]0.24

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

      associate-*r* [=>]0.24

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

      fma-def [=>]0.22

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

      associate-*r/ [=>]0.22

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

      neg-mul-1 [<=]0.22

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

      neg-sub0 [=>]0.22

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

      associate--r- [=>]0.22

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

      metadata-eval [=>]0.22

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

      +-commutative [<=]0.22

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

      +-commutative [=>]0.22

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

    if 2.05e8 < y

    1. Initial program 72.75

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

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

      [Start]72.75

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

      remove-double-neg [<=]72.75

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

      neg-mul-1 [=>]72.75

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

      associate-*l/ [<=]46.02

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

      associate-*r* [=>]46.02

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

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

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

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

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

      metadata-eval [=>]46.02

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

      *-lft-identity [=>]46.02

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

      +-commutative [=>]46.02

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

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

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

      [Start]0.23

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

      associate--l+ [=>]0.23

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

      +-commutative [=>]0.23

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

      associate-+l- [=>]0.23

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

      div-sub [<=]0.23

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

      unsub-neg [<=]0.23

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

      mul-1-neg [<=]0.23

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

      associate-*r/ [=>]0.23

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

      sub-neg [=>]0.23

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

      metadata-eval [=>]0.23

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

      distribute-lft-in [=>]0.23

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

      metadata-eval [=>]0.23

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

      +-commutative [<=]0.23

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

      mul-1-neg [=>]0.23

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

      sub-neg [<=]0.23

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

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

Alternatives

Alternative 1
Error0.27%
Cost969
\[\begin{array}{l} \mathbf{if}\;y \leq -110000000 \lor \neg \left(y \leq 150000000\right):\\ \;\;\;\;x + \frac{1 - x}{y}\\ \mathbf{else}:\\ \;\;\;\;1 + y \cdot \frac{x + -1}{y + 1}\\ \end{array} \]
Alternative 2
Error0.19%
Cost968
\[\begin{array}{l} t_0 := \frac{1 - x}{y}\\ \mathbf{if}\;y \leq -5000000:\\ \;\;\;\;\left(x + \frac{-1}{y \cdot y}\right) + t_0\\ \mathbf{elif}\;y \leq 150000000:\\ \;\;\;\;1 + y \cdot \frac{x + -1}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;x + t_0\\ \end{array} \]
Alternative 3
Error26.13%
Cost844
\[\begin{array}{l} \mathbf{if}\;y \leq -5.6 \cdot 10^{+69}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.7 \cdot 10^{-14}:\\ \;\;\;\;\frac{1}{y}\\ \mathbf{elif}\;y \leq 6.4 \cdot 10^{-24}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y}{y + 1}\\ \end{array} \]
Alternative 4
Error26.36%
Cost716
\[\begin{array}{l} \mathbf{if}\;y \leq -5.5 \cdot 10^{+69}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.7 \cdot 10^{-14}:\\ \;\;\;\;\frac{1}{y}\\ \mathbf{elif}\;y \leq 9.5:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{y}\\ \end{array} \]
Alternative 5
Error13.77%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;x + \frac{1 - x}{y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 6
Error1.49%
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 7
Error26.51%
Cost460
\[\begin{array}{l} \mathbf{if}\;y \leq -5.5 \cdot 10^{+69}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.7 \cdot 10^{-14}:\\ \;\;\;\;\frac{1}{y}\\ \mathbf{elif}\;y \leq 0.28:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error25.73%
Cost328
\[\begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 0.25:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error61.3%
Cost64
\[1 \]

Error

Reproduce?

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