| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 26688 |
\[\begin{array}{l}
t_0 := \mathsf{hypot}\left(x, 2 \cdot y\right)\\
{\left(\frac{x}{t_0}\right)}^{4} - {\left(\frac{2 \cdot y}{t_0}\right)}^{4}
\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)))) (- (pow (/ x t_0) 4.0) (pow (/ (* 2.0 y) t_0) 4.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 pow((x / t_0), 4.0) - pow(((2.0 * y) / t_0), 4.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 Math.pow((x / t_0), 4.0) - Math.pow(((2.0 * y) / t_0), 4.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 math.pow((x / t_0), 4.0) - math.pow(((2.0 * y) / t_0), 4.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(x / t_0) ^ 4.0) - (Float64(Float64(2.0 * y) / t_0) ^ 4.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 / t_0) ^ 4.0) - (((2.0 * y) / t_0) ^ 4.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[Power[N[(x / t$95$0), $MachinePrecision], 4.0], $MachinePrecision] - N[Power[N[(N[(2.0 * y), $MachinePrecision] / t$95$0), $MachinePrecision], 4.0], $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)\\
{\left(\frac{x}{t_0}\right)}^{4} - {\left(\frac{2 \cdot y}{t_0}\right)}^{4}
\end{array}
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 50.9% |
|---|---|
| Target | 51.4% |
| Herbie | 99.9% |
Initial program 54.3%
Applied egg-rr54.3%
[Start]54.3% | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
div-sub [=>]54.3% | \[ \color{blue}{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}
\] |
fma-def [=>]54.3% | \[ \frac{x \cdot x}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
*-commutative [=>]54.3% | \[ \frac{x \cdot x}{\mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y \cdot 4\right)}\right)} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
*-commutative [=>]54.3% | \[ \frac{x \cdot x}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} - \frac{\color{blue}{y \cdot \left(y \cdot 4\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
fma-def [=>]54.3% | \[ \frac{x \cdot x}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} - \frac{y \cdot \left(y \cdot 4\right)}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}
\] |
*-commutative [=>]54.3% | \[ \frac{x \cdot x}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} - \frac{y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y \cdot 4\right)}\right)}
\] |
Applied egg-rr99.6%
[Start]54.3% | \[ \frac{x \cdot x}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} - \frac{y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}
\] |
|---|---|
add-sqr-sqrt [=>]28.5% | \[ \color{blue}{\sqrt{\frac{x \cdot x}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} - \frac{y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}} \cdot \sqrt{\frac{x \cdot x}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} - \frac{y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}}}
\] |
pow2 [=>]28.5% | \[ \color{blue}{{\left(\sqrt{\frac{x \cdot x}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} - \frac{y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}}\right)}^{2}}
\] |
Simplified99.6%
[Start]99.6% | \[ {\left({\left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2}\right)}^{2} + \left(-{\left({\left(\frac{y \cdot 2}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2}\right)}^{2}\right)
\] |
|---|---|
unsub-neg [=>]99.6% | \[ \color{blue}{{\left({\left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2}\right)}^{2} - {\left({\left(\frac{y \cdot 2}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2}\right)}^{2}}
\] |
unpow2 [=>]99.6% | \[ \color{blue}{{\left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2} \cdot {\left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2}} - {\left({\left(\frac{y \cdot 2}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2}\right)}^{2}
\] |
pow-sqr [=>]99.6% | \[ \color{blue}{{\left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{\left(2 \cdot 2\right)}} - {\left({\left(\frac{y \cdot 2}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2}\right)}^{2}
\] |
*-commutative [=>]99.6% | \[ {\left(\frac{x}{\mathsf{hypot}\left(x, \color{blue}{2 \cdot y}\right)}\right)}^{\left(2 \cdot 2\right)} - {\left({\left(\frac{y \cdot 2}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2}\right)}^{2}
\] |
metadata-eval [=>]99.6% | \[ {\left(\frac{x}{\mathsf{hypot}\left(x, 2 \cdot y\right)}\right)}^{\color{blue}{4}} - {\left({\left(\frac{y \cdot 2}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2}\right)}^{2}
\] |
unpow2 [=>]99.6% | \[ {\left(\frac{x}{\mathsf{hypot}\left(x, 2 \cdot y\right)}\right)}^{4} - \color{blue}{{\left(\frac{y \cdot 2}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2} \cdot {\left(\frac{y \cdot 2}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2}}
\] |
pow-sqr [=>]99.6% | \[ {\left(\frac{x}{\mathsf{hypot}\left(x, 2 \cdot y\right)}\right)}^{4} - \color{blue}{{\left(\frac{y \cdot 2}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{\left(2 \cdot 2\right)}}
\] |
*-commutative [=>]99.6% | \[ {\left(\frac{x}{\mathsf{hypot}\left(x, 2 \cdot y\right)}\right)}^{4} - {\left(\frac{\color{blue}{2 \cdot y}}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{\left(2 \cdot 2\right)}
\] |
*-commutative [=>]99.6% | \[ {\left(\frac{x}{\mathsf{hypot}\left(x, 2 \cdot y\right)}\right)}^{4} - {\left(\frac{2 \cdot y}{\mathsf{hypot}\left(x, \color{blue}{2 \cdot y}\right)}\right)}^{\left(2 \cdot 2\right)}
\] |
metadata-eval [=>]99.6% | \[ {\left(\frac{x}{\mathsf{hypot}\left(x, 2 \cdot y\right)}\right)}^{4} - {\left(\frac{2 \cdot y}{\mathsf{hypot}\left(x, 2 \cdot y\right)}\right)}^{\color{blue}{4}}
\] |
Final simplification99.6%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 26688 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 20864 |
| Alternative 3 | |
|---|---|
| Accuracy | 81.3% |
| Cost | 20616 |
| Alternative 4 | |
|---|---|
| Accuracy | 81.3% |
| Cost | 14920 |
| Alternative 5 | |
|---|---|
| Accuracy | 81.3% |
| Cost | 13960 |
| Alternative 6 | |
|---|---|
| Accuracy | 81.3% |
| Cost | 7496 |
| Alternative 7 | |
|---|---|
| Accuracy | 81.0% |
| Cost | 7236 |
| Alternative 8 | |
|---|---|
| Accuracy | 78.4% |
| Cost | 1744 |
| Alternative 9 | |
|---|---|
| Accuracy | 71.5% |
| Cost | 328 |
| Alternative 10 | |
|---|---|
| Accuracy | 50.6% |
| Cost | 64 |
herbie shell --seed 2023271
(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))))