Average Error: 31.7 → 0.1
Time: 15.2s
Precision: binary64
Cost: 39488
\[\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 := \mathsf{hypot}\left(x, y \cdot 2\right)\\ \log \left(e^{{\left(\frac{x}{t_0}\right)}^{2} - {\left(2 \cdot \frac{y}{t_0}\right)}^{2}}\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 (hypot x (* y 2.0))))
   (log (exp (- (pow (/ x t_0) 2.0) (pow (* 2.0 (/ y t_0)) 2.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 = hypot(x, (y * 2.0));
	return log(exp((pow((x / t_0), 2.0) - pow((2.0 * (y / t_0)), 2.0))));
}
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 = Math.hypot(x, (y * 2.0));
	return Math.log(Math.exp((Math.pow((x / t_0), 2.0) - Math.pow((2.0 * (y / t_0)), 2.0))));
}
def code(x, y):
	return ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y))
def code(x, y):
	t_0 = math.hypot(x, (y * 2.0))
	return math.log(math.exp((math.pow((x / t_0), 2.0) - math.pow((2.0 * (y / t_0)), 2.0))))
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 = hypot(x, Float64(y * 2.0))
	return log(exp(Float64((Float64(x / t_0) ^ 2.0) - (Float64(2.0 * Float64(y / t_0)) ^ 2.0))))
end
function tmp = code(x, y)
	tmp = ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y));
end
function tmp = code(x, y)
	t_0 = hypot(x, (y * 2.0));
	tmp = log(exp((((x / t_0) ^ 2.0) - ((2.0 * (y / t_0)) ^ 2.0))));
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[Sqrt[x ^ 2 + N[(y * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]}, N[Log[N[Exp[N[(N[Power[N[(x / t$95$0), $MachinePrecision], 2.0], $MachinePrecision] - N[Power[N[(2.0 * N[(y / t$95$0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $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 := \mathsf{hypot}\left(x, y \cdot 2\right)\\
\log \left(e^{{\left(\frac{x}{t_0}\right)}^{2} - {\left(2 \cdot \frac{y}{t_0}\right)}^{2}}\right)
\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original31.7
Target31.4
Herbie0.1
\[\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. Initial program 31.7

    \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
  2. Applied egg-rr31.4

    \[\leadsto \color{blue}{\frac{x \cdot x}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} + \left(-\frac{y \cdot 4}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} \cdot y\right)} \]
  3. Simplified31.4

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

    [Start]31.4

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

    sub-neg [<=]31.4

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

    associate-/l* [=>]31.0

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

    associate-*l/ [=>]31.4

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

    *-commutative [<=]31.4

    \[ \frac{x}{\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{x}} - \frac{\color{blue}{y \cdot \left(y \cdot 4\right)}}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} \]
  4. Applied egg-rr32.5

    \[\leadsto \color{blue}{\left(\frac{\sqrt{x}}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot \sqrt{x} + \frac{y \cdot 2}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right) \cdot \left(\frac{\sqrt{x}}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot \sqrt{x} - \frac{y \cdot 2}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)} \]
  5. Applied egg-rr0.1

    \[\leadsto \color{blue}{\log \left(e^{{\left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2} - {\left(2 \cdot \frac{y}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2}}\right)} \]
  6. Final simplification0.1

    \[\leadsto \log \left(e^{{\left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2} - {\left(2 \cdot \frac{y}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2}}\right) \]

Alternatives

Alternative 1
Error0.2
Cost20864
\[\begin{array}{l} t_0 := \mathsf{hypot}\left(x, y \cdot 2\right)\\ \frac{x + y \cdot -2}{t_0} \cdot \left(\frac{x}{t_0} + y \cdot \frac{2}{t_0}\right) \end{array} \]
Alternative 2
Error3.7
Cost8776
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;t_0 \leq 0:\\ \;\;\;\;1 + \left(\frac{y \cdot -4}{\frac{x}{\frac{y}{x}}} + \frac{y}{x} \cdot \frac{y \cdot -4}{x}\right)\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+300}:\\ \;\;\;\;\frac{x}{x + \frac{t_0}{x}} + \frac{y \cdot \left(y \cdot -4\right)}{\mathsf{fma}\left(x, x, t_0\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{\frac{y}{\frac{x}{y}}}, -1\right)\\ \end{array} \]
Alternative 3
Error12.4
Cost7236
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 10^{-170}:\\ \;\;\;\;\mathsf{fma}\left(0.25, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+228}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{y \cdot \left(y \cdot 4\right) + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;1 + \left(\frac{y \cdot -4}{\frac{x}{\frac{y}{x}}} + \frac{y}{x} \cdot \frac{y \cdot -4}{x}\right)\\ \end{array} \]
Alternative 4
Error12.4
Cost7236
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 10^{-170}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{\frac{y}{\frac{x}{y}}}, -1\right)\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+228}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{y \cdot \left(y \cdot 4\right) + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;1 + \left(\frac{y \cdot -4}{\frac{x}{\frac{y}{x}}} + \frac{y}{x} \cdot \frac{y \cdot -4}{x}\right)\\ \end{array} \]
Alternative 5
Error12.6
Cost1864
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 10^{-170}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+228}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{y \cdot \left(y \cdot 4\right) + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;1 + \left(\frac{y \cdot -4}{\frac{x}{\frac{y}{x}}} + \frac{y}{x} \cdot \frac{y \cdot -4}{x}\right)\\ \end{array} \]
Alternative 6
Error12.6
Cost1736
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 10^{-170}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+228}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{y \cdot \left(y \cdot 4\right) + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;-1 + \left(2 + \frac{y}{x} \cdot \left(-4 \cdot \frac{y}{x}\right)\right)\\ \end{array} \]
Alternative 7
Error17.5
Cost1360
\[\begin{array}{l} t_0 := 1 + y \cdot \left(\frac{y}{x} \cdot \frac{-4}{x}\right)\\ \mathbf{if}\;x \leq -1.55 \cdot 10^{+131}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{+86}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq -1.55 \cdot 10^{-86}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{-18}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;-1 + \left(2 + \frac{y}{x} \cdot \left(-4 \cdot \frac{y}{x}\right)\right)\\ \end{array} \]
Alternative 8
Error17.5
Cost1234
\[\begin{array}{l} \mathbf{if}\;x \leq -1.5 \cdot 10^{+131} \lor \neg \left(x \leq -1.4 \cdot 10^{+86}\right) \land \left(x \leq -2.05 \cdot 10^{-86} \lor \neg \left(x \leq 1.45 \cdot 10^{-16}\right)\right):\\ \;\;\;\;1 + y \cdot \left(\frac{y}{x} \cdot \frac{-4}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 9
Error18.0
Cost1100
\[\begin{array}{l} \mathbf{if}\;x \leq -3.1 \cdot 10^{+147}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{+86}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq -8 \cdot 10^{-85}:\\ \;\;\;\;1 + \frac{-4 \cdot \left(y \cdot y\right)}{x \cdot x}\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-18}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 10
Error18.0
Cost592
\[\begin{array}{l} \mathbf{if}\;x \leq -3.1 \cdot 10^{+147}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -4 \cdot 10^{+85}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq -5 \cdot 10^{-85}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{-17}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 11
Error32.1
Cost64
\[-1 \]

Error

Reproduce

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