?

Average Error: 49.9% → 20.04%
Time: 5.9s
Precision: binary64
Cost: 1744

?

\[\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 := \frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ t_1 := -1 + \frac{0.5}{\frac{\frac{y}{x}}{\frac{x}{y}}}\\ \mathbf{if}\;y \leq -1.1 \cdot 10^{+98}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -5.9 \cdot 10^{-125}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 10^{-156}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{+18}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{+69}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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 (/ (+ (* x x) (* y (* y -4.0))) (+ (* x x) (* y (* y 4.0)))))
        (t_1 (+ -1.0 (/ 0.5 (/ (/ y x) (/ x y))))))
   (if (<= y -1.1e+98)
     t_1
     (if (<= y -5.9e-125)
       t_0
       (if (<= y 1e-156)
         1.0
         (if (<= y 7.5e+18) t_0 (if (<= y 1.15e+69) 1.0 t_1)))))))
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 = ((x * x) + (y * (y * -4.0))) / ((x * x) + (y * (y * 4.0)));
	double t_1 = -1.0 + (0.5 / ((y / x) / (x / y)));
	double tmp;
	if (y <= -1.1e+98) {
		tmp = t_1;
	} else if (y <= -5.9e-125) {
		tmp = t_0;
	} else if (y <= 1e-156) {
		tmp = 1.0;
	} else if (y <= 7.5e+18) {
		tmp = t_0;
	} else if (y <= 1.15e+69) {
		tmp = 1.0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = ((x * x) - ((y * 4.0d0) * y)) / ((x * x) + ((y * 4.0d0) * y))
end function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((x * x) + (y * (y * (-4.0d0)))) / ((x * x) + (y * (y * 4.0d0)))
    t_1 = (-1.0d0) + (0.5d0 / ((y / x) / (x / y)))
    if (y <= (-1.1d+98)) then
        tmp = t_1
    else if (y <= (-5.9d-125)) then
        tmp = t_0
    else if (y <= 1d-156) then
        tmp = 1.0d0
    else if (y <= 7.5d+18) then
        tmp = t_0
    else if (y <= 1.15d+69) then
        tmp = 1.0d0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y) {
	return ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y));
}
public static double code(double x, double y) {
	double t_0 = ((x * x) + (y * (y * -4.0))) / ((x * x) + (y * (y * 4.0)));
	double t_1 = -1.0 + (0.5 / ((y / x) / (x / y)));
	double tmp;
	if (y <= -1.1e+98) {
		tmp = t_1;
	} else if (y <= -5.9e-125) {
		tmp = t_0;
	} else if (y <= 1e-156) {
		tmp = 1.0;
	} else if (y <= 7.5e+18) {
		tmp = t_0;
	} else if (y <= 1.15e+69) {
		tmp = 1.0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y):
	return ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y))
def code(x, y):
	t_0 = ((x * x) + (y * (y * -4.0))) / ((x * x) + (y * (y * 4.0)))
	t_1 = -1.0 + (0.5 / ((y / x) / (x / y)))
	tmp = 0
	if y <= -1.1e+98:
		tmp = t_1
	elif y <= -5.9e-125:
		tmp = t_0
	elif y <= 1e-156:
		tmp = 1.0
	elif y <= 7.5e+18:
		tmp = t_0
	elif y <= 1.15e+69:
		tmp = 1.0
	else:
		tmp = t_1
	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(Float64(Float64(x * x) + Float64(y * Float64(y * -4.0))) / Float64(Float64(x * x) + Float64(y * Float64(y * 4.0))))
	t_1 = Float64(-1.0 + Float64(0.5 / Float64(Float64(y / x) / Float64(x / y))))
	tmp = 0.0
	if (y <= -1.1e+98)
		tmp = t_1;
	elseif (y <= -5.9e-125)
		tmp = t_0;
	elseif (y <= 1e-156)
		tmp = 1.0;
	elseif (y <= 7.5e+18)
		tmp = t_0;
	elseif (y <= 1.15e+69)
		tmp = 1.0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp = code(x, y)
	tmp = ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y));
end
function tmp_2 = code(x, y)
	t_0 = ((x * x) + (y * (y * -4.0))) / ((x * x) + (y * (y * 4.0)));
	t_1 = -1.0 + (0.5 / ((y / x) / (x / y)));
	tmp = 0.0;
	if (y <= -1.1e+98)
		tmp = t_1;
	elseif (y <= -5.9e-125)
		tmp = t_0;
	elseif (y <= 1e-156)
		tmp = 1.0;
	elseif (y <= 7.5e+18)
		tmp = t_0;
	elseif (y <= 1.15e+69)
		tmp = 1.0;
	else
		tmp = t_1;
	end
	tmp_2 = 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[(N[(N[(x * x), $MachinePrecision] + N[(y * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-1.0 + N[(0.5 / N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.1e+98], t$95$1, If[LessEqual[y, -5.9e-125], t$95$0, If[LessEqual[y, 1e-156], 1.0, If[LessEqual[y, 7.5e+18], t$95$0, If[LessEqual[y, 1.15e+69], 1.0, t$95$1]]]]]]]
\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 := \frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\
t_1 := -1 + \frac{0.5}{\frac{\frac{y}{x}}{\frac{x}{y}}}\\
\mathbf{if}\;y \leq -1.1 \cdot 10^{+98}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq -5.9 \cdot 10^{-125}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 10^{-156}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 7.5 \cdot 10^{+18}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 1.15 \cdot 10^{+69}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original49.9%
Target49.49%
Herbie20.04%
\[\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 y < -1.10000000000000004e98 or 1.15000000000000008e69 < y

    1. Initial program 77.23

      \[\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 36.04

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

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

      [Start]36.04

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

      sub-neg [=>]36.04

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

      metadata-eval [=>]36.04

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

      +-commutative [=>]36.04

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

      fma-def [=>]36.04

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

      unpow2 [=>]36.04

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

      associate-*r/ [=>]36.04

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

      associate-/l* [=>]36.04

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

      unpow2 [=>]36.04

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

      associate-/l* [=>]36.04

      \[ -1 + \mathsf{fma}\left(-0.125, \frac{{x}^{4}}{{y}^{4}}, \frac{0.5}{\color{blue}{\frac{y}{\frac{x \cdot x}{y}}}}\right) \]
    4. Taylor expanded in x around 0 26.66

      \[\leadsto -1 + \color{blue}{0.5 \cdot \frac{{x}^{2}}{{y}^{2}}} \]
    5. Simplified17.18

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

      [Start]26.66

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

      associate-*r/ [=>]26.66

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

      unpow2 [=>]26.66

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

      unpow2 [=>]26.66

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

      associate-/l* [=>]26.66

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

      times-frac [=>]17.18

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

      unpow2 [<=]17.18

      \[ -1 + \frac{0.5}{\color{blue}{{\left(\frac{y}{x}\right)}^{2}}} \]
    6. Applied egg-rr17.18

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

    if -1.10000000000000004e98 < y < -5.89999999999999959e-125 or 1.00000000000000004e-156 < y < 7.5e18

    1. Initial program 24.23

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

    if -5.89999999999999959e-125 < y < 1.00000000000000004e-156 or 7.5e18 < y < 1.15000000000000008e69

    1. Initial program 43.45

      \[\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 19.17

      \[\leadsto \color{blue}{1} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification20.04

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.1 \cdot 10^{+98}:\\ \;\;\;\;-1 + \frac{0.5}{\frac{\frac{y}{x}}{\frac{x}{y}}}\\ \mathbf{elif}\;y \leq -5.9 \cdot 10^{-125}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;y \leq 10^{-156}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{+18}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{+69}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1 + \frac{0.5}{\frac{\frac{y}{x}}{\frac{x}{y}}}\\ \end{array} \]

Alternatives

Alternative 1
Error24.9%
Cost1869
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;t_0 \leq 2 \cdot 10^{-55}:\\ \;\;\;\;1\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+38} \lor \neg \left(t_0 \leq 10^{+107}\right):\\ \;\;\;\;-1 + \frac{0.5}{\frac{\frac{y}{x}}{\frac{x}{y}}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 2
Error25.44%
Cost328
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-20}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{+68}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 3
Error49.67%
Cost64
\[-1 \]

Error

Reproduce?

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