| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 20544 |
\[\begin{array}{l}
t_0 := \mathsf{hypot}\left(x, 2 \cdot y\right)\\
\frac{\left(x + y \cdot -2\right) \cdot \frac{1}{\frac{t_0}{\mathsf{fma}\left(y, 2, x\right)}}}{t_0}
\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 (* 2.0 y)))) (* (/ (+ x (* 2.0 y)) t_0) (+ (/ x t_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, (2.0 * y));
return ((x + (2.0 * y)) / t_0) * ((x / t_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, (2.0 * y));
return ((x + (2.0 * y)) / t_0) * ((x / t_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, (2.0 * y)) return ((x + (2.0 * y)) / t_0) * ((x / t_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(2.0 * y)) return Float64(Float64(Float64(x + Float64(2.0 * y)) / t_0) * Float64(Float64(x / t_0) + Float64(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, (2.0 * y)); tmp = ((x + (2.0 * y)) / t_0) * ((x / t_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[(2.0 * y), $MachinePrecision] ^ 2], $MachinePrecision]}, N[(N[(N[(x + N[(2.0 * y), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] * N[(N[(x / t$95$0), $MachinePrecision] + N[(N[(y / t$95$0), $MachinePrecision] * -2.0), $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, 2 \cdot y\right)\\
\frac{x + 2 \cdot y}{t_0} \cdot \left(\frac{x}{t_0} + \frac{y}{t_0} \cdot -2\right)
\end{array}
Results
| Original | 50.2% |
|---|---|
| Target | 50.7% |
| Herbie | 99.9% |
Initial program 50.2%
Applied egg-rr50.6%
Applied egg-rr99.9%
Applied egg-rr99.6%
Simplified99.9%
[Start]99.6 | \[ \left(\frac{1}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot \left(x + y \cdot 2\right)\right) \cdot \frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)} + \left(\frac{1}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot \left(x + y \cdot 2\right)\right) \cdot \frac{y \cdot -2}{\mathsf{hypot}\left(x, y \cdot 2\right)}
\] |
|---|---|
distribute-lft-out [=>]99.6 | \[ \color{blue}{\left(\frac{1}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot \left(x + y \cdot 2\right)\right) \cdot \left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)} + \frac{y \cdot -2}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}
\] |
*-rgt-identity [<=]99.6 | \[ \left(\frac{1}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot \left(x + y \cdot 2\right)\right) \cdot \left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)} + \color{blue}{\frac{y \cdot -2}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot 1}\right)
\] |
associate-*l/ [=>]99.9 | \[ \color{blue}{\frac{1 \cdot \left(x + y \cdot 2\right)}{\mathsf{hypot}\left(x, y \cdot 2\right)}} \cdot \left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)} + \frac{y \cdot -2}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot 1\right)
\] |
+-commutative [=>]99.9 | \[ \frac{1 \cdot \color{blue}{\left(y \cdot 2 + x\right)}}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot \left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)} + \frac{y \cdot -2}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot 1\right)
\] |
distribute-lft-in [=>]99.9 | \[ \frac{\color{blue}{1 \cdot \left(y \cdot 2\right) + 1 \cdot x}}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot \left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)} + \frac{y \cdot -2}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot 1\right)
\] |
*-commutative [=>]99.9 | \[ \frac{1 \cdot \color{blue}{\left(2 \cdot y\right)} + 1 \cdot x}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot \left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)} + \frac{y \cdot -2}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot 1\right)
\] |
associate-*r* [=>]99.9 | \[ \frac{\color{blue}{\left(1 \cdot 2\right) \cdot y} + 1 \cdot x}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot \left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)} + \frac{y \cdot -2}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot 1\right)
\] |
metadata-eval [=>]99.9 | \[ \frac{\color{blue}{2} \cdot y + 1 \cdot x}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot \left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)} + \frac{y \cdot -2}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot 1\right)
\] |
*-commutative [<=]99.9 | \[ \frac{2 \cdot y + \color{blue}{x \cdot 1}}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot \left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)} + \frac{y \cdot -2}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot 1\right)
\] |
*-commutative [=>]99.9 | \[ \frac{2 \cdot y + x \cdot 1}{\mathsf{hypot}\left(x, \color{blue}{2 \cdot y}\right)} \cdot \left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)} + \frac{y \cdot -2}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot 1\right)
\] |
*-commutative [=>]99.9 | \[ \frac{2 \cdot y + x \cdot 1}{\mathsf{hypot}\left(x, 2 \cdot y\right)} \cdot \left(\frac{x}{\mathsf{hypot}\left(x, \color{blue}{2 \cdot y}\right)} + \frac{y \cdot -2}{\mathsf{hypot}\left(x, y \cdot 2\right)} \cdot 1\right)
\] |
*-rgt-identity [=>]99.9 | \[ \frac{2 \cdot y + x \cdot 1}{\mathsf{hypot}\left(x, 2 \cdot y\right)} \cdot \left(\frac{x}{\mathsf{hypot}\left(x, 2 \cdot y\right)} + \color{blue}{\frac{y \cdot -2}{\mathsf{hypot}\left(x, y \cdot 2\right)}}\right)
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 20544 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 14272 |
| Alternative 3 | |
|---|---|
| Accuracy | 79.4% |
| Cost | 9048 |
| Alternative 4 | |
|---|---|
| Accuracy | 79.3% |
| Cost | 8536 |
| Alternative 5 | |
|---|---|
| Accuracy | 79.4% |
| Cost | 8536 |
| Alternative 6 | |
|---|---|
| Accuracy | 79.3% |
| Cost | 3288 |
| Alternative 7 | |
|---|---|
| Accuracy | 79.2% |
| Cost | 2776 |
| Alternative 8 | |
|---|---|
| Accuracy | 74.8% |
| Cost | 1485 |
| Alternative 9 | |
|---|---|
| Accuracy | 75.2% |
| Cost | 1485 |
| Alternative 10 | |
|---|---|
| Accuracy | 74.9% |
| Cost | 1484 |
| Alternative 11 | |
|---|---|
| Accuracy | 74.3% |
| Cost | 328 |
| Alternative 12 | |
|---|---|
| Accuracy | 50.1% |
| Cost | 64 |
herbie shell --seed 2023122
(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))))