| Alternative 1 | |
|---|---|
| Accuracy | 75.7% |
| Cost | 969 |
(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) (+ t_0 (* x x)))))
(if (<= t_0 2e-165)
(+ 1.0 (/ (* (/ y (/ x y)) -4.0) x))
(if (<= t_0 1e-112)
t_1
(if (<= t_0 2e-63)
1.0
(if (<= t_0 1e+31)
t_1
(if (<= t_0 2e+82)
(+ 1.0 (* -4.0 (/ (* y y) (* x x))))
(if (<= t_0 2e+153)
t_1
(+ (* (/ (/ x y) (/ y x)) 0.5) -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) / (t_0 + (x * x));
double tmp;
if (t_0 <= 2e-165) {
tmp = 1.0 + (((y / (x / y)) * -4.0) / x);
} else if (t_0 <= 1e-112) {
tmp = t_1;
} else if (t_0 <= 2e-63) {
tmp = 1.0;
} else if (t_0 <= 1e+31) {
tmp = t_1;
} else if (t_0 <= 2e+82) {
tmp = 1.0 + (-4.0 * ((y * y) / (x * x)));
} else if (t_0 <= 2e+153) {
tmp = t_1;
} else {
tmp = (((x / y) / (y / x)) * 0.5) + -1.0;
}
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 = y * (y * 4.0d0)
t_1 = ((x * x) - t_0) / (t_0 + (x * x))
if (t_0 <= 2d-165) then
tmp = 1.0d0 + (((y / (x / y)) * (-4.0d0)) / x)
else if (t_0 <= 1d-112) then
tmp = t_1
else if (t_0 <= 2d-63) then
tmp = 1.0d0
else if (t_0 <= 1d+31) then
tmp = t_1
else if (t_0 <= 2d+82) then
tmp = 1.0d0 + ((-4.0d0) * ((y * y) / (x * x)))
else if (t_0 <= 2d+153) then
tmp = t_1
else
tmp = (((x / y) / (y / x)) * 0.5d0) + (-1.0d0)
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 = y * (y * 4.0);
double t_1 = ((x * x) - t_0) / (t_0 + (x * x));
double tmp;
if (t_0 <= 2e-165) {
tmp = 1.0 + (((y / (x / y)) * -4.0) / x);
} else if (t_0 <= 1e-112) {
tmp = t_1;
} else if (t_0 <= 2e-63) {
tmp = 1.0;
} else if (t_0 <= 1e+31) {
tmp = t_1;
} else if (t_0 <= 2e+82) {
tmp = 1.0 + (-4.0 * ((y * y) / (x * x)));
} else if (t_0 <= 2e+153) {
tmp = t_1;
} else {
tmp = (((x / y) / (y / x)) * 0.5) + -1.0;
}
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 = y * (y * 4.0) t_1 = ((x * x) - t_0) / (t_0 + (x * x)) tmp = 0 if t_0 <= 2e-165: tmp = 1.0 + (((y / (x / y)) * -4.0) / x) elif t_0 <= 1e-112: tmp = t_1 elif t_0 <= 2e-63: tmp = 1.0 elif t_0 <= 1e+31: tmp = t_1 elif t_0 <= 2e+82: tmp = 1.0 + (-4.0 * ((y * y) / (x * x))) elif t_0 <= 2e+153: tmp = t_1 else: tmp = (((x / y) / (y / x)) * 0.5) + -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(t_0 + Float64(x * x))) tmp = 0.0 if (t_0 <= 2e-165) tmp = Float64(1.0 + Float64(Float64(Float64(y / Float64(x / y)) * -4.0) / x)); elseif (t_0 <= 1e-112) tmp = t_1; elseif (t_0 <= 2e-63) tmp = 1.0; elseif (t_0 <= 1e+31) tmp = t_1; elseif (t_0 <= 2e+82) tmp = Float64(1.0 + Float64(-4.0 * Float64(Float64(y * y) / Float64(x * x)))); elseif (t_0 <= 2e+153) tmp = t_1; else tmp = Float64(Float64(Float64(Float64(x / y) / Float64(y / x)) * 0.5) + -1.0); 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 = y * (y * 4.0); t_1 = ((x * x) - t_0) / (t_0 + (x * x)); tmp = 0.0; if (t_0 <= 2e-165) tmp = 1.0 + (((y / (x / y)) * -4.0) / x); elseif (t_0 <= 1e-112) tmp = t_1; elseif (t_0 <= 2e-63) tmp = 1.0; elseif (t_0 <= 1e+31) tmp = t_1; elseif (t_0 <= 2e+82) tmp = 1.0 + (-4.0 * ((y * y) / (x * x))); elseif (t_0 <= 2e+153) tmp = t_1; else tmp = (((x / y) / (y / x)) * 0.5) + -1.0; 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[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(t$95$0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e-165], N[(1.0 + N[(N[(N[(y / N[(x / y), $MachinePrecision]), $MachinePrecision] * -4.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e-112], t$95$1, If[LessEqual[t$95$0, 2e-63], 1.0, If[LessEqual[t$95$0, 1e+31], t$95$1, If[LessEqual[t$95$0, 2e+82], N[(1.0 + N[(-4.0 * N[(N[(y * y), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e+153], t$95$1, N[(N[(N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision] + -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}{t_0 + x \cdot x}\\
\mathbf{if}\;t_0 \leq 2 \cdot 10^{-165}:\\
\;\;\;\;1 + \frac{\frac{y}{\frac{x}{y}} \cdot -4}{x}\\
\mathbf{elif}\;t_0 \leq 10^{-112}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{-63}:\\
\;\;\;\;1\\
\mathbf{elif}\;t_0 \leq 10^{+31}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+82}:\\
\;\;\;\;1 + -4 \cdot \frac{y \cdot y}{x \cdot x}\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+153}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{y}}{\frac{y}{x}} \cdot 0.5 + -1\\
\end{array}
Results
| Original | 51.4% |
|---|---|
| Target | 51.9% |
| Herbie | 79.0% |
if (*.f64 (*.f64 y 4) y) < 2e-165Initial program 59.5%
Taylor expanded in x around inf 49.5%
Simplified49.5%
[Start]49.5 | \[ \frac{{x}^{2}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
unpow2 [=>]49.5 | \[ \frac{\color{blue}{x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
Taylor expanded in x around inf 75.2%
Simplified75.2%
[Start]75.2 | \[ 1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
|---|---|
unpow2 [=>]75.2 | \[ 1 + -4 \cdot \frac{\color{blue}{y \cdot y}}{{x}^{2}}
\] |
unpow2 [=>]75.2 | \[ 1 + -4 \cdot \frac{y \cdot y}{\color{blue}{x \cdot x}}
\] |
Applied egg-rr82.9%
[Start]75.2 | \[ 1 + -4 \cdot \frac{y \cdot y}{x \cdot x}
\] |
|---|---|
*-commutative [=>]75.2 | \[ 1 + \color{blue}{\frac{y \cdot y}{x \cdot x} \cdot -4}
\] |
associate-/r* [=>]82.5 | \[ 1 + \color{blue}{\frac{\frac{y \cdot y}{x}}{x}} \cdot -4
\] |
associate-*l/ [=>]82.5 | \[ 1 + \color{blue}{\frac{\frac{y \cdot y}{x} \cdot -4}{x}}
\] |
associate-/l* [=>]82.9 | \[ 1 + \frac{\color{blue}{\frac{y}{\frac{x}{y}}} \cdot -4}{x}
\] |
if 2e-165 < (*.f64 (*.f64 y 4) y) < 9.9999999999999995e-113 or 2.00000000000000013e-63 < (*.f64 (*.f64 y 4) y) < 9.9999999999999996e30 or 1.9999999999999999e82 < (*.f64 (*.f64 y 4) y) < 2e153Initial program 76.5%
if 9.9999999999999995e-113 < (*.f64 (*.f64 y 4) y) < 2.00000000000000013e-63Initial program 77.2%
Taylor expanded in x around inf 53.5%
if 9.9999999999999996e30 < (*.f64 (*.f64 y 4) y) < 1.9999999999999999e82Initial program 75.0%
Taylor expanded in x around inf 16.3%
Simplified16.3%
[Start]16.3 | \[ \frac{{x}^{2}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
unpow2 [=>]16.3 | \[ \frac{\color{blue}{x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
Taylor expanded in x around inf 41.1%
Simplified41.1%
[Start]41.1 | \[ 1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}
\] |
|---|---|
unpow2 [=>]41.1 | \[ 1 + -4 \cdot \frac{\color{blue}{y \cdot y}}{{x}^{2}}
\] |
unpow2 [=>]41.1 | \[ 1 + -4 \cdot \frac{y \cdot y}{\color{blue}{x \cdot x}}
\] |
if 2e153 < (*.f64 (*.f64 y 4) y) Initial program 26.3%
Taylor expanded in x around 0 73.8%
Simplified83.1%
[Start]73.8 | \[ 0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1
\] |
|---|---|
fma-neg [=>]73.8 | \[ \color{blue}{\mathsf{fma}\left(0.5, \frac{{x}^{2}}{{y}^{2}}, -1\right)}
\] |
unpow2 [=>]73.8 | \[ \mathsf{fma}\left(0.5, \frac{\color{blue}{x \cdot x}}{{y}^{2}}, -1\right)
\] |
unpow2 [=>]73.8 | \[ \mathsf{fma}\left(0.5, \frac{x \cdot x}{\color{blue}{y \cdot y}}, -1\right)
\] |
times-frac [=>]83.1 | \[ \mathsf{fma}\left(0.5, \color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, -1\right)
\] |
metadata-eval [=>]83.1 | \[ \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, \color{blue}{-1}\right)
\] |
Applied egg-rr83.1%
[Start]83.1 | \[ \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)
\] |
|---|---|
fma-udef [=>]83.1 | \[ \color{blue}{0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right) + -1}
\] |
*-commutative [=>]83.1 | \[ \color{blue}{\left(\frac{x}{y} \cdot \frac{x}{y}\right) \cdot 0.5} + -1
\] |
pow2 [=>]83.1 | \[ \color{blue}{{\left(\frac{x}{y}\right)}^{2}} \cdot 0.5 + -1
\] |
Applied egg-rr83.1%
[Start]83.1 | \[ {\left(\frac{x}{y}\right)}^{2} \cdot 0.5 + -1
\] |
|---|---|
unpow2 [=>]83.1 | \[ \color{blue}{\left(\frac{x}{y} \cdot \frac{x}{y}\right)} \cdot 0.5 + -1
\] |
clear-num [=>]83.1 | \[ \left(\frac{x}{y} \cdot \color{blue}{\frac{1}{\frac{y}{x}}}\right) \cdot 0.5 + -1
\] |
un-div-inv [=>]83.1 | \[ \color{blue}{\frac{\frac{x}{y}}{\frac{y}{x}}} \cdot 0.5 + -1
\] |
Final simplification79.0%
| Alternative 1 | |
|---|---|
| Accuracy | 75.7% |
| Cost | 969 |
| Alternative 2 | |
|---|---|
| Accuracy | 75.3% |
| Cost | 968 |
| Alternative 3 | |
|---|---|
| Accuracy | 75.1% |
| Cost | 328 |
| Alternative 4 | |
|---|---|
| Accuracy | 50.7% |
| Cost | 64 |
herbie shell --seed 2023136
(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))))