?

Average Accuracy: 75.9% → 98.7%
Time: 4.7s
Precision: binary64
Cost: 7112

?

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

\mathbf{elif}\;x \leq 9.5 \cdot 10^{-17}:\\
\;\;\;\;\frac{\frac{x}{\frac{x}{y} + -1}}{0.5}\\

\mathbf{else}:\\
\;\;\;\;\frac{y}{\mathsf{fma}\left(\frac{y}{x}, -0.5, 0.5\right)}\\


\end{array}

Error?

Target

Original75.9%
Target99.4%
Herbie98.7%
\[\begin{array}{l} \mathbf{if}\;x < -1.7210442634149447 \cdot 10^{+81}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x < 83645045635564430:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if x < -5.7999999999999998e130

    1. Initial program 64.1%

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
    2. Simplified99.8%

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

      [Start]64.1

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

      associate-*l/ [<=]99.8

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

    if -5.7999999999999998e130 < x < 9.50000000000000029e-17

    1. Initial program 78.7%

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
    2. Simplified81.4%

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

      [Start]78.7

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

      associate-*l/ [<=]81.4

      \[ \color{blue}{\frac{x \cdot 2}{x - y} \cdot y} \]
    3. Applied egg-rr81.4%

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

      [Start]81.4

      \[ \frac{x \cdot 2}{x - y} \cdot y \]

      add-log-exp [=>]6.6

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

      *-un-lft-identity [=>]6.6

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

      log-prod [=>]6.6

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

      metadata-eval [=>]6.6

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

      add-log-exp [<=]81.4

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

      *-commutative [=>]81.4

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

      *-commutative [=>]81.4

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

      *-un-lft-identity [=>]81.4

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

      times-frac [=>]81.4

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

      metadata-eval [=>]81.4

      \[ 0 + y \cdot \left(\color{blue}{2} \cdot \frac{x}{x - y}\right) \]
    4. Simplified97.9%

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

      [Start]81.4

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

      +-lft-identity [=>]81.4

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

      *-commutative [=>]81.4

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

      *-commutative [<=]81.4

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

      metadata-eval [<=]81.4

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

      times-frac [<=]81.4

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

      *-rgt-identity [=>]81.4

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

      associate-/r/ [<=]97.9

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

      associate-/l* [<=]78.7

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

      associate-/r* [=>]78.7

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

      associate-/l* [=>]97.9

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

      div-sub [=>]97.9

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

      sub-neg [=>]97.9

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

      *-inverses [=>]97.9

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

      metadata-eval [=>]97.9

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

    if 9.50000000000000029e-17 < x

    1. Initial program 76.0%

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
    2. Simplified99.9%

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

      [Start]76.0

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

      *-commutative [=>]76.0

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

      associate-/l* [=>]99.7

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

      div-sub [=>]99.7

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

      sub-neg [=>]99.7

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

      +-commutative [=>]99.7

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

      distribute-neg-frac [=>]99.7

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

      neg-mul-1 [=>]99.7

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

      *-commutative [=>]99.7

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

      times-frac [=>]99.7

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

      metadata-eval [=>]99.7

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

      metadata-eval [<=]99.7

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

      metadata-eval [<=]99.7

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

      *-inverses [<=]99.7

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

      associate-/r* [<=]99.7

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

      *-commutative [<=]99.7

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

      associate-/r* [=>]99.8

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

      *-inverses [=>]99.8

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

      *-inverses [<=]99.8

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

      associate-/r* [<=]99.8

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

      *-commutative [<=]99.8

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

      fma-def [=>]99.8

      \[ \frac{y}{\color{blue}{\mathsf{fma}\left(\frac{y}{x}, -\frac{y}{2 \cdot y}, \frac{y}{2 \cdot y}\right)}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification98.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.8 \cdot 10^{+130}:\\ \;\;\;\;y \cdot \frac{x \cdot 2}{x - y}\\ \mathbf{elif}\;x \leq 9.5 \cdot 10^{-17}:\\ \;\;\;\;\frac{\frac{x}{\frac{x}{y} + -1}}{0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\mathsf{fma}\left(\frac{y}{x}, -0.5, 0.5\right)}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy74.0%
Cost1236
\[\begin{array}{l} t_0 := 2 \cdot \left(y + \frac{y}{\frac{x}{y}}\right)\\ \mathbf{if}\;y \leq -3.6 \cdot 10^{+27}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq -3.3 \cdot 10^{-21}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.05 \cdot 10^{-37}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{-219}:\\ \;\;\;\;2 \cdot y\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{+86}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x \cdot -2\\ \end{array} \]
Alternative 2
Accuracy70.9%
Cost986
\[\begin{array}{l} \mathbf{if}\;x \leq -1.95 \cdot 10^{+107}:\\ \;\;\;\;2 \cdot y\\ \mathbf{elif}\;x \leq -1.35 \lor \neg \left(x \leq -1.95 \cdot 10^{-81}\right) \land \left(x \leq 5.9 \cdot 10^{-15} \lor \neg \left(x \leq 55000000000\right) \land x \leq 2.8 \cdot 10^{+75}\right):\\ \;\;\;\;x \cdot -2\\ \mathbf{else}:\\ \;\;\;\;2 \cdot y\\ \end{array} \]
Alternative 3
Accuracy93.6%
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -8.5 \cdot 10^{-183} \lor \neg \left(x \leq 4.1 \cdot 10^{-150}\right):\\ \;\;\;\;y \cdot \frac{x \cdot 2}{x - y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot -2\\ \end{array} \]
Alternative 4
Accuracy99.5%
Cost841
\[\begin{array}{l} \mathbf{if}\;y \leq -1.55 \cdot 10^{-78} \lor \neg \left(y \leq 4.5 \cdot 10^{+51}\right):\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x \cdot 2}{x - y}\\ \end{array} \]
Alternative 5
Accuracy98.7%
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -3.85 \cdot 10^{+130} \lor \neg \left(x \leq 2 \cdot 10^{-18}\right):\\ \;\;\;\;y \cdot \frac{x \cdot 2}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{\frac{x}{y} + -1}}{0.5}\\ \end{array} \]
Alternative 6
Accuracy51.5%
Cost192
\[2 \cdot y \]

Error

Reproduce?

herbie shell --seed 2023151 
(FPCore (x y)
  :name "Linear.Projection:perspective from linear-1.19.1.3, B"
  :precision binary64

  :herbie-target
  (if (< x -1.7210442634149447e+81) (* (/ (* 2.0 x) (- x y)) y) (if (< x 83645045635564430.0) (/ (* x 2.0) (/ (- x y) y)) (* (/ (* 2.0 x) (- x y)) y)))

  (/ (* (* x 2.0) y) (- x y)))