?

Average Error: 34.52% → 0.54%
Time: 9.4s
Precision: binary64
Cost: 8072

?

\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1} \]
\[\begin{array}{l} \mathbf{if}\;y \leq -5.4 \cdot 10^{+21}:\\ \;\;\;\;x + \frac{1}{y}\\ \mathbf{elif}\;y \leq 11600:\\ \;\;\;\;1 + y \cdot \frac{x + -1}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{x + -1}{y \cdot y} - \left(\frac{x + -1}{{y}^{3}} - x\right)\right) + \frac{1 - x}{y}\\ \end{array} \]
(FPCore (x y) :precision binary64 (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))
(FPCore (x y)
 :precision binary64
 (if (<= y -5.4e+21)
   (+ x (/ 1.0 y))
   (if (<= y 11600.0)
     (+ 1.0 (* y (/ (+ x -1.0) (+ y 1.0))))
     (+
      (- (/ (+ x -1.0) (* y y)) (- (/ (+ x -1.0) (pow y 3.0)) x))
      (/ (- 1.0 x) y)))))
double code(double x, double y) {
	return 1.0 - (((1.0 - x) * y) / (y + 1.0));
}
double code(double x, double y) {
	double tmp;
	if (y <= -5.4e+21) {
		tmp = x + (1.0 / y);
	} else if (y <= 11600.0) {
		tmp = 1.0 + (y * ((x + -1.0) / (y + 1.0)));
	} else {
		tmp = (((x + -1.0) / (y * y)) - (((x + -1.0) / pow(y, 3.0)) - x)) + ((1.0 - x) / y);
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = 1.0d0 - (((1.0d0 - x) * y) / (y + 1.0d0))
end function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= (-5.4d+21)) then
        tmp = x + (1.0d0 / y)
    else if (y <= 11600.0d0) then
        tmp = 1.0d0 + (y * ((x + (-1.0d0)) / (y + 1.0d0)))
    else
        tmp = (((x + (-1.0d0)) / (y * y)) - (((x + (-1.0d0)) / (y ** 3.0d0)) - x)) + ((1.0d0 - x) / y)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	return 1.0 - (((1.0 - x) * y) / (y + 1.0));
}
public static double code(double x, double y) {
	double tmp;
	if (y <= -5.4e+21) {
		tmp = x + (1.0 / y);
	} else if (y <= 11600.0) {
		tmp = 1.0 + (y * ((x + -1.0) / (y + 1.0)));
	} else {
		tmp = (((x + -1.0) / (y * y)) - (((x + -1.0) / Math.pow(y, 3.0)) - x)) + ((1.0 - x) / y);
	}
	return tmp;
}
def code(x, y):
	return 1.0 - (((1.0 - x) * y) / (y + 1.0))
def code(x, y):
	tmp = 0
	if y <= -5.4e+21:
		tmp = x + (1.0 / y)
	elif y <= 11600.0:
		tmp = 1.0 + (y * ((x + -1.0) / (y + 1.0)))
	else:
		tmp = (((x + -1.0) / (y * y)) - (((x + -1.0) / math.pow(y, 3.0)) - x)) + ((1.0 - x) / y)
	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)
	tmp = 0.0
	if (y <= -5.4e+21)
		tmp = Float64(x + Float64(1.0 / y));
	elseif (y <= 11600.0)
		tmp = Float64(1.0 + Float64(y * Float64(Float64(x + -1.0) / Float64(y + 1.0))));
	else
		tmp = Float64(Float64(Float64(Float64(x + -1.0) / Float64(y * y)) - Float64(Float64(Float64(x + -1.0) / (y ^ 3.0)) - x)) + Float64(Float64(1.0 - x) / y));
	end
	return tmp
end
function tmp = code(x, y)
	tmp = 1.0 - (((1.0 - x) * y) / (y + 1.0));
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -5.4e+21)
		tmp = x + (1.0 / y);
	elseif (y <= 11600.0)
		tmp = 1.0 + (y * ((x + -1.0) / (y + 1.0)));
	else
		tmp = (((x + -1.0) / (y * y)) - (((x + -1.0) / (y ^ 3.0)) - x)) + ((1.0 - x) / y);
	end
	tmp_2 = 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_] := If[LessEqual[y, -5.4e+21], N[(x + N[(1.0 / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 11600.0], N[(1.0 + N[(y * N[(N[(x + -1.0), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(x + -1.0), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(N[(N[(x + -1.0), $MachinePrecision] / N[Power[y, 3.0], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \leq -5.4 \cdot 10^{+21}:\\
\;\;\;\;x + \frac{1}{y}\\

\mathbf{elif}\;y \leq 11600:\\
\;\;\;\;1 + y \cdot \frac{x + -1}{y + 1}\\

\mathbf{else}:\\
\;\;\;\;\left(\frac{x + -1}{y \cdot y} - \left(\frac{x + -1}{{y}^{3}} - x\right)\right) + \frac{1 - x}{y}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original34.52%
Target0.31%
Herbie0.54%
\[\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 < -5.4e21

    1. Initial program 73.43

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

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

      [Start]73.43

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

      remove-double-neg [<=]73.43

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

      neg-mul-1 [=>]73.43

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

      associate-*l/ [<=]46.58

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

      associate-*r* [=>]46.58

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

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

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

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

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

      metadata-eval [=>]46.58

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

      *-lft-identity [=>]46.58

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

      +-commutative [=>]46.58

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

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

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

      [Start]0.02

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

      +-commutative [=>]0.02

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

      associate--l+ [=>]0.02

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

      div-sub [<=]0.02

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

      sub-neg [=>]0.02

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

      mul-1-neg [<=]0.02

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

      +-commutative [=>]0.02

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

      metadata-eval [<=]0.02

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

      distribute-lft-in [<=]0.02

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

      metadata-eval [<=]0.02

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

      sub-neg [<=]0.02

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

      associate-*r/ [<=]0.02

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

      mul-1-neg [=>]0.02

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

      unsub-neg [=>]0.02

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

      sub-neg [=>]0.02

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

      metadata-eval [=>]0.02

      \[ x - \frac{x + \color{blue}{-1}}{y} \]
    5. Taylor expanded in x around 0 0.02

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

    if -5.4e21 < y < 11600

    1. Initial program 1.07

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

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

      [Start]1.07

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

      remove-double-neg [<=]1.07

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

      neg-mul-1 [=>]1.07

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

      associate-*l/ [<=]1

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

      associate-*r* [=>]1

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

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

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

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

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

      metadata-eval [=>]1

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

      *-lft-identity [=>]1

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

      +-commutative [=>]1

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

    if 11600 < y

    1. Initial program 70.81

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

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

      [Start]70.81

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

      sub-neg [=>]70.81

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

      +-commutative [=>]70.81

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

      neg-mul-1 [=>]70.81

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

      associate-*l/ [<=]45.43

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

      associate-*r* [=>]45.43

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

      fma-def [=>]45.49

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

      associate-*r/ [=>]45.49

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

      neg-mul-1 [<=]45.49

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

      neg-sub0 [=>]45.49

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

      associate--r- [=>]45.49

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

      metadata-eval [=>]45.49

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

      +-commutative [<=]45.49

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

      +-commutative [=>]45.49

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

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

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

      [Start]0.03

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

      associate--l+ [=>]0.03

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

      +-commutative [=>]0.03

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

      associate--r+ [=>]0.03

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

      associate-+l- [=>]0.03

      \[ \color{blue}{\left(\left(\frac{1}{{y}^{3}} + \left(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right)\right) - \frac{x}{{y}^{3}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.54

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5.4 \cdot 10^{+21}:\\ \;\;\;\;x + \frac{1}{y}\\ \mathbf{elif}\;y \leq 11600:\\ \;\;\;\;1 + y \cdot \frac{x + -1}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{x + -1}{y \cdot y} - \left(\frac{x + -1}{{y}^{3}} - x\right)\right) + \frac{1 - x}{y}\\ \end{array} \]

Alternatives

Alternative 1
Error0.55%
Cost7240
\[\begin{array}{l} \mathbf{if}\;y \leq -5.4 \cdot 10^{+21}:\\ \;\;\;\;x + \frac{1}{y}\\ \mathbf{elif}\;y \leq 650000:\\ \;\;\;\;\mathsf{fma}\left(\frac{x + -1}{y + 1}, y, 1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + \frac{x + -1}{y \cdot y}\right) + \frac{1 - x}{y}\\ \end{array} \]
Alternative 2
Error0.56%
Cost1224
\[\begin{array}{l} \mathbf{if}\;y \leq -5.4 \cdot 10^{+21}:\\ \;\;\;\;x + \frac{1}{y}\\ \mathbf{elif}\;y \leq 390000:\\ \;\;\;\;1 + y \cdot \frac{x + -1}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;\left(x + \frac{x + -1}{y \cdot y}\right) + \frac{1 - x}{y}\\ \end{array} \]
Alternative 3
Error0.62%
Cost968
\[\begin{array}{l} \mathbf{if}\;y \leq -5.4 \cdot 10^{+21}:\\ \;\;\;\;x + \frac{1}{y}\\ \mathbf{elif}\;y \leq 150000000:\\ \;\;\;\;1 + y \cdot \frac{x + -1}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{1 - x}{y}\\ \end{array} \]
Alternative 4
Error1.94%
Cost840
\[\begin{array}{l} \mathbf{if}\;y \leq -5.4 \cdot 10^{+21}:\\ \;\;\;\;x + \frac{1}{y}\\ \mathbf{elif}\;y \leq 85000:\\ \;\;\;\;1 + y \cdot \frac{x}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{1 - x}{y}\\ \end{array} \]
Alternative 5
Error2.2%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 0.8\right):\\ \;\;\;\;x + \frac{1}{y}\\ \mathbf{else}:\\ \;\;\;\;1 + y \cdot \left(x + -1\right)\\ \end{array} \]
Alternative 6
Error1.92%
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
Error14.53%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 0.155\right):\\ \;\;\;\;x + \frac{1}{y}\\ \mathbf{else}:\\ \;\;\;\;1 - y\\ \end{array} \]
Alternative 8
Error2.49%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;x + \frac{1}{y}\\ \mathbf{else}:\\ \;\;\;\;1 + y \cdot x\\ \end{array} \]
Alternative 9
Error26%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 0.26:\\ \;\;\;\;1 - y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error26.28%
Cost328
\[\begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 0.21:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error61.28%
Cost64
\[1 \]

Error

Reproduce?

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