(- (/ x0 (- 1 x1)) x0)

Percentage Accurate: 88.4% → 100.0%
Time: 5.0s
Alternatives: 6
Speedup: 1.0×

Specification

?
\[x0 = 1.855 \land x1 = 0.000209 \lor x0 = 2.985 \land x1 = 0.0186\]
\[\begin{array}{l} \\ \frac{x0}{1 - x1} - x0 \end{array} \]
(FPCore (x0 x1) :precision binary64 (- (/ x0 (- 1.0 x1)) x0))
double code(double x0, double x1) {
	return (x0 / (1.0 - x1)) - x0;
}
real(8) function code(x0, x1)
    real(8), intent (in) :: x0
    real(8), intent (in) :: x1
    code = (x0 / (1.0d0 - x1)) - x0
end function
public static double code(double x0, double x1) {
	return (x0 / (1.0 - x1)) - x0;
}
def code(x0, x1):
	return (x0 / (1.0 - x1)) - x0
function code(x0, x1)
	return Float64(Float64(x0 / Float64(1.0 - x1)) - x0)
end
function tmp = code(x0, x1)
	tmp = (x0 / (1.0 - x1)) - x0;
end
code[x0_, x1_] := N[(N[(x0 / N[(1.0 - x1), $MachinePrecision]), $MachinePrecision] - x0), $MachinePrecision]
\begin{array}{l}

\\
\frac{x0}{1 - x1} - x0
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 88.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x0}{1 - x1} - x0 \end{array} \]
(FPCore (x0 x1) :precision binary64 (- (/ x0 (- 1.0 x1)) x0))
double code(double x0, double x1) {
	return (x0 / (1.0 - x1)) - x0;
}
real(8) function code(x0, x1)
    real(8), intent (in) :: x0
    real(8), intent (in) :: x1
    code = (x0 / (1.0d0 - x1)) - x0
end function
public static double code(double x0, double x1) {
	return (x0 / (1.0 - x1)) - x0;
}
def code(x0, x1):
	return (x0 / (1.0 - x1)) - x0
function code(x0, x1)
	return Float64(Float64(x0 / Float64(1.0 - x1)) - x0)
end
function tmp = code(x0, x1)
	tmp = (x0 / (1.0 - x1)) - x0;
end
code[x0_, x1_] := N[(N[(x0 / N[(1.0 - x1), $MachinePrecision]), $MachinePrecision] - x0), $MachinePrecision]
\begin{array}{l}

\\
\frac{x0}{1 - x1} - x0
\end{array}

Alternative 1: 100.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ x1 \cdot \left(x0 + x1 \cdot \left(x0 + x1 \cdot \frac{x0}{1 - x1}\right)\right) \end{array} \]
(FPCore (x0 x1)
 :precision binary64
 (* x1 (+ x0 (* x1 (+ x0 (* x1 (/ x0 (- 1.0 x1))))))))
double code(double x0, double x1) {
	return x1 * (x0 + (x1 * (x0 + (x1 * (x0 / (1.0 - x1))))));
}
real(8) function code(x0, x1)
    real(8), intent (in) :: x0
    real(8), intent (in) :: x1
    code = x1 * (x0 + (x1 * (x0 + (x1 * (x0 / (1.0d0 - x1))))))
end function
public static double code(double x0, double x1) {
	return x1 * (x0 + (x1 * (x0 + (x1 * (x0 / (1.0 - x1))))));
}
def code(x0, x1):
	return x1 * (x0 + (x1 * (x0 + (x1 * (x0 / (1.0 - x1))))))
function code(x0, x1)
	return Float64(x1 * Float64(x0 + Float64(x1 * Float64(x0 + Float64(x1 * Float64(x0 / Float64(1.0 - x1)))))))
end
function tmp = code(x0, x1)
	tmp = x1 * (x0 + (x1 * (x0 + (x1 * (x0 / (1.0 - x1))))));
end
code[x0_, x1_] := N[(x1 * N[(x0 + N[(x1 * N[(x0 + N[(x1 * N[(x0 / N[(1.0 - x1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x1 \cdot \left(x0 + x1 \cdot \left(x0 + x1 \cdot \frac{x0}{1 - x1}\right)\right)
\end{array}
Derivation
  1. Initial program 88.9%

    \[\frac{x0}{1 - x1} - x0 \]
  2. Add Preprocessing
  3. Taylor expanded in x0 around 0 89.4%

    \[\leadsto \color{blue}{x0 \cdot \left(\frac{1}{1 - x1} - 1\right)} \]
  4. Taylor expanded in x1 around 0 73.2%

    \[\leadsto \color{blue}{x1 \cdot \left(x0 + x1 \cdot \left(x0 + x1 \cdot \left(x0 + x0 \cdot x1\right)\right)\right)} \]
  5. Applied egg-rr100.0%

    \[\leadsto x1 \cdot \left(x0 + x1 \cdot \left(x0 + x1 \cdot \color{blue}{\frac{x0}{-\left(-1 + x1\right)}}\right)\right) \]
  6. Step-by-step derivation
    1. distribute-neg-in100.0%

      \[\leadsto x1 \cdot \left(x0 + x1 \cdot \left(x0 + x1 \cdot \frac{x0}{\color{blue}{\left(--1\right) + \left(-x1\right)}}\right)\right) \]
    2. metadata-eval100.0%

      \[\leadsto x1 \cdot \left(x0 + x1 \cdot \left(x0 + x1 \cdot \frac{x0}{\color{blue}{1} + \left(-x1\right)}\right)\right) \]
    3. sub-neg100.0%

      \[\leadsto x1 \cdot \left(x0 + x1 \cdot \left(x0 + x1 \cdot \frac{x0}{\color{blue}{1 - x1}}\right)\right) \]
  7. Simplified100.0%

    \[\leadsto x1 \cdot \left(x0 + x1 \cdot \left(x0 + x1 \cdot \color{blue}{\frac{x0}{1 - x1}}\right)\right) \]
  8. Add Preprocessing

Alternative 2: 94.4% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;1 - x1 \leq 0.99:\\ \;\;\;\;\frac{x0}{1 - x1} - x0\\ \mathbf{else}:\\ \;\;\;\;x1 \cdot \left(x0 + x1 \cdot \left(x0 + x1 \cdot \left(x0 + x1 \cdot x0\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (x0 x1)
 :precision binary64
 (if (<= (- 1.0 x1) 0.99)
   (- (/ x0 (- 1.0 x1)) x0)
   (* x1 (+ x0 (* x1 (+ x0 (* x1 (+ x0 (* x1 x0)))))))))
double code(double x0, double x1) {
	double tmp;
	if ((1.0 - x1) <= 0.99) {
		tmp = (x0 / (1.0 - x1)) - x0;
	} else {
		tmp = x1 * (x0 + (x1 * (x0 + (x1 * (x0 + (x1 * x0))))));
	}
	return tmp;
}
real(8) function code(x0, x1)
    real(8), intent (in) :: x0
    real(8), intent (in) :: x1
    real(8) :: tmp
    if ((1.0d0 - x1) <= 0.99d0) then
        tmp = (x0 / (1.0d0 - x1)) - x0
    else
        tmp = x1 * (x0 + (x1 * (x0 + (x1 * (x0 + (x1 * x0))))))
    end if
    code = tmp
end function
public static double code(double x0, double x1) {
	double tmp;
	if ((1.0 - x1) <= 0.99) {
		tmp = (x0 / (1.0 - x1)) - x0;
	} else {
		tmp = x1 * (x0 + (x1 * (x0 + (x1 * (x0 + (x1 * x0))))));
	}
	return tmp;
}
def code(x0, x1):
	tmp = 0
	if (1.0 - x1) <= 0.99:
		tmp = (x0 / (1.0 - x1)) - x0
	else:
		tmp = x1 * (x0 + (x1 * (x0 + (x1 * (x0 + (x1 * x0))))))
	return tmp
function code(x0, x1)
	tmp = 0.0
	if (Float64(1.0 - x1) <= 0.99)
		tmp = Float64(Float64(x0 / Float64(1.0 - x1)) - x0);
	else
		tmp = Float64(x1 * Float64(x0 + Float64(x1 * Float64(x0 + Float64(x1 * Float64(x0 + Float64(x1 * x0)))))));
	end
	return tmp
end
function tmp_2 = code(x0, x1)
	tmp = 0.0;
	if ((1.0 - x1) <= 0.99)
		tmp = (x0 / (1.0 - x1)) - x0;
	else
		tmp = x1 * (x0 + (x1 * (x0 + (x1 * (x0 + (x1 * x0))))));
	end
	tmp_2 = tmp;
end
code[x0_, x1_] := If[LessEqual[N[(1.0 - x1), $MachinePrecision], 0.99], N[(N[(x0 / N[(1.0 - x1), $MachinePrecision]), $MachinePrecision] - x0), $MachinePrecision], N[(x1 * N[(x0 + N[(x1 * N[(x0 + N[(x1 * N[(x0 + N[(x1 * x0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;1 - x1 \leq 0.99:\\
\;\;\;\;\frac{x0}{1 - x1} - x0\\

\mathbf{else}:\\
\;\;\;\;x1 \cdot \left(x0 + x1 \cdot \left(x0 + x1 \cdot \left(x0 + x1 \cdot x0\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 #s(literal 1 binary64) x1) < 0.98999999999999999

    1. Initial program 94.4%

      \[\frac{x0}{1 - x1} - x0 \]
    2. Add Preprocessing

    if 0.98999999999999999 < (-.f64 #s(literal 1 binary64) x1)

    1. Initial program 82.6%

      \[\frac{x0}{1 - x1} - x0 \]
    2. Add Preprocessing
    3. Taylor expanded in x0 around 0 84.0%

      \[\leadsto \color{blue}{x0 \cdot \left(\frac{1}{1 - x1} - 1\right)} \]
    4. Taylor expanded in x1 around 0 94.4%

      \[\leadsto \color{blue}{x1 \cdot \left(x0 + x1 \cdot \left(x0 + x1 \cdot \left(x0 + x0 \cdot x1\right)\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification94.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;1 - x1 \leq 0.99:\\ \;\;\;\;\frac{x0}{1 - x1} - x0\\ \mathbf{else}:\\ \;\;\;\;x1 \cdot \left(x0 + x1 \cdot \left(x0 + x1 \cdot \left(x0 + x1 \cdot x0\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 89.1% accurate, 0.8× speedup?

\[\begin{array}{l} \\ x0 \cdot \left(\frac{1}{1 - x1} + -1\right) \end{array} \]
(FPCore (x0 x1) :precision binary64 (* x0 (+ (/ 1.0 (- 1.0 x1)) -1.0)))
double code(double x0, double x1) {
	return x0 * ((1.0 / (1.0 - x1)) + -1.0);
}
real(8) function code(x0, x1)
    real(8), intent (in) :: x0
    real(8), intent (in) :: x1
    code = x0 * ((1.0d0 / (1.0d0 - x1)) + (-1.0d0))
end function
public static double code(double x0, double x1) {
	return x0 * ((1.0 / (1.0 - x1)) + -1.0);
}
def code(x0, x1):
	return x0 * ((1.0 / (1.0 - x1)) + -1.0)
function code(x0, x1)
	return Float64(x0 * Float64(Float64(1.0 / Float64(1.0 - x1)) + -1.0))
end
function tmp = code(x0, x1)
	tmp = x0 * ((1.0 / (1.0 - x1)) + -1.0);
end
code[x0_, x1_] := N[(x0 * N[(N[(1.0 / N[(1.0 - x1), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x0 \cdot \left(\frac{1}{1 - x1} + -1\right)
\end{array}
Derivation
  1. Initial program 88.9%

    \[\frac{x0}{1 - x1} - x0 \]
  2. Add Preprocessing
  3. Taylor expanded in x0 around 0 89.4%

    \[\leadsto \color{blue}{x0 \cdot \left(\frac{1}{1 - x1} - 1\right)} \]
  4. Final simplification89.4%

    \[\leadsto x0 \cdot \left(\frac{1}{1 - x1} + -1\right) \]
  5. Add Preprocessing

Alternative 4: 88.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x0}{1 - x1} - x0 \end{array} \]
(FPCore (x0 x1) :precision binary64 (- (/ x0 (- 1.0 x1)) x0))
double code(double x0, double x1) {
	return (x0 / (1.0 - x1)) - x0;
}
real(8) function code(x0, x1)
    real(8), intent (in) :: x0
    real(8), intent (in) :: x1
    code = (x0 / (1.0d0 - x1)) - x0
end function
public static double code(double x0, double x1) {
	return (x0 / (1.0 - x1)) - x0;
}
def code(x0, x1):
	return (x0 / (1.0 - x1)) - x0
function code(x0, x1)
	return Float64(Float64(x0 / Float64(1.0 - x1)) - x0)
end
function tmp = code(x0, x1)
	tmp = (x0 / (1.0 - x1)) - x0;
end
code[x0_, x1_] := N[(N[(x0 / N[(1.0 - x1), $MachinePrecision]), $MachinePrecision] - x0), $MachinePrecision]
\begin{array}{l}

\\
\frac{x0}{1 - x1} - x0
\end{array}
Derivation
  1. Initial program 88.9%

    \[\frac{x0}{1 - x1} - x0 \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 5: 32.4% accurate, 2.3× speedup?

\[\begin{array}{l} \\ x1 \cdot x0 \end{array} \]
(FPCore (x0 x1) :precision binary64 (* x1 x0))
double code(double x0, double x1) {
	return x1 * x0;
}
real(8) function code(x0, x1)
    real(8), intent (in) :: x0
    real(8), intent (in) :: x1
    code = x1 * x0
end function
public static double code(double x0, double x1) {
	return x1 * x0;
}
def code(x0, x1):
	return x1 * x0
function code(x0, x1)
	return Float64(x1 * x0)
end
function tmp = code(x0, x1)
	tmp = x1 * x0;
end
code[x0_, x1_] := N[(x1 * x0), $MachinePrecision]
\begin{array}{l}

\\
x1 \cdot x0
\end{array}
Derivation
  1. Initial program 88.9%

    \[\frac{x0}{1 - x1} - x0 \]
  2. Add Preprocessing
  3. Taylor expanded in x1 around 0 32.1%

    \[\leadsto \color{blue}{x0 \cdot x1} \]
  4. Final simplification32.1%

    \[\leadsto x1 \cdot x0 \]
  5. Add Preprocessing

Alternative 6: 3.1% accurate, 7.0× speedup?

\[\begin{array}{l} \\ 0 \end{array} \]
(FPCore (x0 x1) :precision binary64 0.0)
double code(double x0, double x1) {
	return 0.0;
}
real(8) function code(x0, x1)
    real(8), intent (in) :: x0
    real(8), intent (in) :: x1
    code = 0.0d0
end function
public static double code(double x0, double x1) {
	return 0.0;
}
def code(x0, x1):
	return 0.0
function code(x0, x1)
	return 0.0
end
function tmp = code(x0, x1)
	tmp = 0.0;
end
code[x0_, x1_] := 0.0
\begin{array}{l}

\\
0
\end{array}
Derivation
  1. Initial program 88.9%

    \[\frac{x0}{1 - x1} - x0 \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. sub-neg88.9%

      \[\leadsto \color{blue}{\frac{x0}{1 - x1} + \left(-x0\right)} \]
    2. +-commutative88.9%

      \[\leadsto \color{blue}{\left(-x0\right) + \frac{x0}{1 - x1}} \]
    3. add-sqr-sqrt88.9%

      \[\leadsto \left(-\color{blue}{\sqrt{x0} \cdot \sqrt{x0}}\right) + \frac{x0}{1 - x1} \]
    4. distribute-rgt-neg-in88.9%

      \[\leadsto \color{blue}{\sqrt{x0} \cdot \left(-\sqrt{x0}\right)} + \frac{x0}{1 - x1} \]
    5. fma-define91.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{x0}, -\sqrt{x0}, \frac{x0}{1 - x1}\right)} \]
  4. Applied egg-rr91.5%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{x0}, -\sqrt{x0}, \frac{x0}{1 - x1}\right)} \]
  5. Taylor expanded in x1 around 0 3.1%

    \[\leadsto \color{blue}{x0 + -1 \cdot x0} \]
  6. Step-by-step derivation
    1. distribute-rgt1-in3.1%

      \[\leadsto \color{blue}{\left(-1 + 1\right) \cdot x0} \]
    2. metadata-eval3.1%

      \[\leadsto \color{blue}{0} \cdot x0 \]
    3. mul0-lft3.1%

      \[\leadsto \color{blue}{0} \]
  7. Simplified3.1%

    \[\leadsto \color{blue}{0} \]
  8. Add Preprocessing

Developer Target 1: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x0 \cdot x1}{1 - x1} \end{array} \]
(FPCore (x0 x1) :precision binary64 (/ (* x0 x1) (- 1.0 x1)))
double code(double x0, double x1) {
	return (x0 * x1) / (1.0 - x1);
}
real(8) function code(x0, x1)
    real(8), intent (in) :: x0
    real(8), intent (in) :: x1
    code = (x0 * x1) / (1.0d0 - x1)
end function
public static double code(double x0, double x1) {
	return (x0 * x1) / (1.0 - x1);
}
def code(x0, x1):
	return (x0 * x1) / (1.0 - x1)
function code(x0, x1)
	return Float64(Float64(x0 * x1) / Float64(1.0 - x1))
end
function tmp = code(x0, x1)
	tmp = (x0 * x1) / (1.0 - x1);
end
code[x0_, x1_] := N[(N[(x0 * x1), $MachinePrecision] / N[(1.0 - x1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x0 \cdot x1}{1 - x1}
\end{array}

Reproduce

?
herbie shell --seed 2024169 
(FPCore (x0 x1)
  :name "(- (/ x0 (- 1 x1)) x0)"
  :precision binary64
  :pre (or (and (== x0 1.855) (== x1 0.000209)) (and (== x0 2.985) (== x1 0.0186)))

  :alt
  (! :herbie-platform default (/ (* x0 x1) (- 1 x1)))

  (- (/ x0 (- 1.0 x1)) x0))