?

Average Accuracy: 51.5% → 79.6%
Time: 8.4s
Precision: binary64
Cost: 20624

?

\[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\ t_2 := \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-304}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{-247}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{-31}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot x \leq 10^{+274}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{log1p}\left({\left(\frac{y}{x}\right)}^{2}\right), -8, 1\right)\\ \end{array} \]
(FPCore (x y)
 :precision binary64
 (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* y (* y 4.0)))
        (t_1 (/ (- (* x x) t_0) (+ (* x x) t_0)))
        (t_2 (fma 0.5 (* (/ x y) (/ x y)) -1.0)))
   (if (<= (* x x) 2e-304)
     t_2
     (if (<= (* x x) 5e-247)
       t_1
       (if (<= (* x x) 5e-31)
         t_2
         (if (<= (* x x) 1e+274)
           t_1
           (fma (log1p (pow (/ y x) 2.0)) -8.0 1.0)))))))
double code(double x, double y) {
	return ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y));
}
double code(double x, double y) {
	double t_0 = y * (y * 4.0);
	double t_1 = ((x * x) - t_0) / ((x * x) + t_0);
	double t_2 = fma(0.5, ((x / y) * (x / y)), -1.0);
	double tmp;
	if ((x * x) <= 2e-304) {
		tmp = t_2;
	} else if ((x * x) <= 5e-247) {
		tmp = t_1;
	} else if ((x * x) <= 5e-31) {
		tmp = t_2;
	} else if ((x * x) <= 1e+274) {
		tmp = t_1;
	} else {
		tmp = fma(log1p(pow((y / x), 2.0)), -8.0, 1.0);
	}
	return tmp;
}
function code(x, y)
	return Float64(Float64(Float64(x * x) - Float64(Float64(y * 4.0) * y)) / Float64(Float64(x * x) + Float64(Float64(y * 4.0) * y)))
end
function code(x, y)
	t_0 = Float64(y * Float64(y * 4.0))
	t_1 = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0))
	t_2 = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0)
	tmp = 0.0
	if (Float64(x * x) <= 2e-304)
		tmp = t_2;
	elseif (Float64(x * x) <= 5e-247)
		tmp = t_1;
	elseif (Float64(x * x) <= 5e-31)
		tmp = t_2;
	elseif (Float64(x * x) <= 1e+274)
		tmp = t_1;
	else
		tmp = fma(log1p((Float64(y / x) ^ 2.0)), -8.0, 1.0);
	end
	return tmp
end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 2e-304], t$95$2, If[LessEqual[N[(x * x), $MachinePrecision], 5e-247], t$95$1, If[LessEqual[N[(x * x), $MachinePrecision], 5e-31], t$95$2, If[LessEqual[N[(x * x), $MachinePrecision], 1e+274], t$95$1, N[(N[Log[1 + N[Power[N[(y / x), $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision] * -8.0 + 1.0), $MachinePrecision]]]]]]]]
\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\
t_2 := \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-304}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{-247}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{-31}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;x \cdot x \leq 10^{+274}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{log1p}\left({\left(\frac{y}{x}\right)}^{2}\right), -8, 1\right)\\


\end{array}

Error?

Target

Original51.5%
Target51.9%
Herbie79.6%
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} < 0.9743233849626781:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot y\right) \cdot 4} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{\sqrt{x \cdot x + \left(y \cdot y\right) \cdot 4}}\right)}^{2} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if (*.f64 x x) < 1.99999999999999994e-304 or 4.99999999999999978e-247 < (*.f64 x x) < 5e-31

    1. Initial program 63.2%

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Taylor expanded in x around 0 71.1%

      \[\leadsto \color{blue}{0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1} \]
    3. Simplified78.1%

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

      [Start]71.1

      \[ 0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1 \]

      fma-neg [=>]71.1

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

      unpow2 [=>]71.1

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

      unpow2 [=>]71.1

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

      times-frac [=>]78.1

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

      metadata-eval [=>]78.1

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

    if 1.99999999999999994e-304 < (*.f64 x x) < 4.99999999999999978e-247 or 5e-31 < (*.f64 x x) < 9.99999999999999921e273

    1. Initial program 75.0%

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

    if 9.99999999999999921e273 < (*.f64 x x)

    1. Initial program 7.8%

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Taylor expanded in x around inf 74.2%

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

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

      [Start]74.2

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

      associate--l+ [=>]74.2

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

      distribute-rgt-out-- [=>]74.2

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

      metadata-eval [=>]74.2

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

      *-commutative [<=]74.2

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

      +-commutative [<=]74.2

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

      *-commutative [=>]74.2

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

      fma-def [=>]74.2

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

      unpow2 [=>]74.2

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

      unpow2 [=>]74.2

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

      times-frac [=>]85.9

      \[ \mathsf{fma}\left(\color{blue}{\frac{y}{x} \cdot \frac{y}{x}}, -8, 1\right) \]
    4. Applied egg-rr85.0%

      \[\leadsto \mathsf{fma}\left(\color{blue}{\log \left(e^{{\left(\frac{y}{x}\right)}^{2}}\right)}, -8, 1\right) \]
      Proof

      [Start]85.9

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

      add-log-exp [=>]85.0

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

      pow2 [=>]85.0

      \[ \mathsf{fma}\left(\log \left(e^{\color{blue}{{\left(\frac{y}{x}\right)}^{2}}}\right), -8, 1\right) \]
    5. Taylor expanded in y around 0 74.2%

      \[\leadsto \mathsf{fma}\left(\log \color{blue}{\left(1 + \frac{{y}^{2}}{{x}^{2}}\right)}, -8, 1\right) \]
    6. Simplified86.9%

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

      [Start]74.2

      \[ \mathsf{fma}\left(\log \left(1 + \frac{{y}^{2}}{{x}^{2}}\right), -8, 1\right) \]

      unpow2 [=>]74.2

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

      unpow2 [=>]74.2

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

      times-frac [=>]86.9

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

      unpow2 [<=]86.9

      \[ \mathsf{fma}\left(\log \left(1 + \color{blue}{{\left(\frac{y}{x}\right)}^{2}}\right), -8, 1\right) \]
    7. Applied egg-rr86.9%

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

      [Start]86.9

      \[ \mathsf{fma}\left(\log \left(1 + {\left(\frac{y}{x}\right)}^{2}\right), -8, 1\right) \]

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

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

      *-commutative [=>]86.9

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

      log-prod [=>]86.9

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

      log1p-def [=>]86.9

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

      metadata-eval [=>]86.9

      \[ \mathsf{fma}\left(\mathsf{log1p}\left({\left(\frac{y}{x}\right)}^{2}\right) + \color{blue}{0}, -8, 1\right) \]
    8. Simplified86.9%

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

      [Start]86.9

      \[ \mathsf{fma}\left(\mathsf{log1p}\left({\left(\frac{y}{x}\right)}^{2}\right) + 0, -8, 1\right) \]

      +-rgt-identity [=>]86.9

      \[ \mathsf{fma}\left(\color{blue}{\mathsf{log1p}\left({\left(\frac{y}{x}\right)}^{2}\right)}, -8, 1\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification79.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-304}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{-247}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{-31}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{elif}\;x \cdot x \leq 10^{+274}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{log1p}\left({\left(\frac{y}{x}\right)}^{2}\right), -8, 1\right)\\ \end{array} \]

Alternatives

Alternative 1
Accuracy79.3%
Cost8016
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\ t_2 := \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-304}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{-247}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{-31}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot x \leq 10^{+274}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\ \end{array} \]
Alternative 2
Accuracy79.2%
Cost7756
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\ t_2 := \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-304}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{-247}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{-31}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot x \leq 10^{+274}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{\frac{y}{\frac{x}{y}} \cdot -4}{x}\\ \end{array} \]
Alternative 3
Accuracy78.8%
Cost2256
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\ \mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-304}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{-247}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{-31}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 10^{+274}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{\frac{y}{\frac{x}{y}} \cdot -4}{x}\\ \end{array} \]
Alternative 4
Accuracy74.9%
Cost969
\[\begin{array}{l} \mathbf{if}\;x \leq -8.6 \cdot 10^{+16} \lor \neg \left(x \leq 3.7 \cdot 10^{-20}\right):\\ \;\;\;\;1 + \frac{\frac{y}{\frac{x}{y}} \cdot -4}{x}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 5
Accuracy74.7%
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+18}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2 \cdot 10^{-25}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 6
Accuracy50.9%
Cost64
\[-1 \]

Error

Reproduce?

herbie shell --seed 2023146 
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4.0))) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4.0)))) 2.0) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))

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