| Alternative 1 | |
|---|---|
| Accuracy | 73.8% |
| Cost | 2645 |
(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))))))
(if (<= y -3e+109)
(+ (* (pow (/ x y) 2.0) 0.5) -1.0)
(if (<= y -2e-73)
t_0
(if (<= y 7.8e-47)
1.0
(if (<= y 2.2e+71) t_0 (+ -1.0 (* (/ x y) (/ x (* y 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 = ((x * x) + (y * (y * -4.0))) / ((x * x) + (y * (y * 4.0)));
double tmp;
if (y <= -3e+109) {
tmp = (pow((x / y), 2.0) * 0.5) + -1.0;
} else if (y <= -2e-73) {
tmp = t_0;
} else if (y <= 7.8e-47) {
tmp = 1.0;
} else if (y <= 2.2e+71) {
tmp = t_0;
} else {
tmp = -1.0 + ((x / y) * (x / (y * 4.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) :: tmp
t_0 = ((x * x) + (y * (y * (-4.0d0)))) / ((x * x) + (y * (y * 4.0d0)))
if (y <= (-3d+109)) then
tmp = (((x / y) ** 2.0d0) * 0.5d0) + (-1.0d0)
else if (y <= (-2d-73)) then
tmp = t_0
else if (y <= 7.8d-47) then
tmp = 1.0d0
else if (y <= 2.2d+71) then
tmp = t_0
else
tmp = (-1.0d0) + ((x / y) * (x / (y * 4.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 = ((x * x) + (y * (y * -4.0))) / ((x * x) + (y * (y * 4.0)));
double tmp;
if (y <= -3e+109) {
tmp = (Math.pow((x / y), 2.0) * 0.5) + -1.0;
} else if (y <= -2e-73) {
tmp = t_0;
} else if (y <= 7.8e-47) {
tmp = 1.0;
} else if (y <= 2.2e+71) {
tmp = t_0;
} else {
tmp = -1.0 + ((x / y) * (x / (y * 4.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 = ((x * x) + (y * (y * -4.0))) / ((x * x) + (y * (y * 4.0))) tmp = 0 if y <= -3e+109: tmp = (math.pow((x / y), 2.0) * 0.5) + -1.0 elif y <= -2e-73: tmp = t_0 elif y <= 7.8e-47: tmp = 1.0 elif y <= 2.2e+71: tmp = t_0 else: tmp = -1.0 + ((x / y) * (x / (y * 4.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(Float64(Float64(x * x) + Float64(y * Float64(y * -4.0))) / Float64(Float64(x * x) + Float64(y * Float64(y * 4.0)))) tmp = 0.0 if (y <= -3e+109) tmp = Float64(Float64((Float64(x / y) ^ 2.0) * 0.5) + -1.0); elseif (y <= -2e-73) tmp = t_0; elseif (y <= 7.8e-47) tmp = 1.0; elseif (y <= 2.2e+71) tmp = t_0; else tmp = Float64(-1.0 + Float64(Float64(x / y) * Float64(x / Float64(y * 4.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 = ((x * x) + (y * (y * -4.0))) / ((x * x) + (y * (y * 4.0))); tmp = 0.0; if (y <= -3e+109) tmp = (((x / y) ^ 2.0) * 0.5) + -1.0; elseif (y <= -2e-73) tmp = t_0; elseif (y <= 7.8e-47) tmp = 1.0; elseif (y <= 2.2e+71) tmp = t_0; else tmp = -1.0 + ((x / y) * (x / (y * 4.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[(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]}, If[LessEqual[y, -3e+109], N[(N[(N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision] * 0.5), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[y, -2e-73], t$95$0, If[LessEqual[y, 7.8e-47], 1.0, If[LessEqual[y, 2.2e+71], t$95$0, N[(-1.0 + N[(N[(x / y), $MachinePrecision] * N[(x / N[(y * 4.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 := \frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\
\mathbf{if}\;y \leq -3 \cdot 10^{+109}:\\
\;\;\;\;{\left(\frac{x}{y}\right)}^{2} \cdot 0.5 + -1\\
\mathbf{elif}\;y \leq -2 \cdot 10^{-73}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{-47}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{+71}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;-1 + \frac{x}{y} \cdot \frac{x}{y \cdot 4}\\
\end{array}
Results
| Original | 50.1% |
|---|---|
| Target | 50.5% |
| Herbie | 79.6% |
if y < -3.00000000000000015e109Initial program 16.1%
Simplified16.1%
[Start]16.1 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
|---|---|
fma-neg [=>]16.1 | \[ \frac{\color{blue}{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot y\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
*-commutative [=>]16.1 | \[ \frac{\mathsf{fma}\left(x, x, -\color{blue}{y \cdot \left(y \cdot 4\right)}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
associate-*r* [=>]16.1 | \[ \frac{\mathsf{fma}\left(x, x, -\color{blue}{\left(y \cdot y\right) \cdot 4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
distribute-rgt-neg-in [=>]16.1 | \[ \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y \cdot y\right) \cdot \left(-4\right)}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
metadata-eval [=>]16.1 | \[ \frac{\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot \color{blue}{-4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\] |
fma-def [=>]16.1 | \[ \frac{\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot -4\right)}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}
\] |
*-commutative [=>]16.1 | \[ \frac{\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot -4\right)}{\mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y \cdot 4\right)}\right)}
\] |
Taylor expanded in x around 0 74.0%
Simplified84.1%
[Start]74.0 | \[ 0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1
\] |
|---|---|
fma-neg [=>]74.0 | \[ \color{blue}{\mathsf{fma}\left(0.5, \frac{{x}^{2}}{{y}^{2}}, -1\right)}
\] |
unpow2 [=>]74.0 | \[ \mathsf{fma}\left(0.5, \frac{\color{blue}{x \cdot x}}{{y}^{2}}, -1\right)
\] |
unpow2 [=>]74.0 | \[ \mathsf{fma}\left(0.5, \frac{x \cdot x}{\color{blue}{y \cdot y}}, -1\right)
\] |
times-frac [=>]84.1 | \[ \mathsf{fma}\left(0.5, \color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, -1\right)
\] |
metadata-eval [=>]84.1 | \[ \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, \color{blue}{-1}\right)
\] |
Applied egg-rr84.1%
[Start]84.1 | \[ \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)
\] |
|---|---|
fma-udef [=>]84.1 | \[ \color{blue}{0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right) + -1}
\] |
*-commutative [=>]84.1 | \[ \color{blue}{\left(\frac{x}{y} \cdot \frac{x}{y}\right) \cdot 0.5} + -1
\] |
pow2 [=>]84.1 | \[ \color{blue}{{\left(\frac{x}{y}\right)}^{2}} \cdot 0.5 + -1
\] |
if -3.00000000000000015e109 < y < -1.99999999999999999e-73 or 7.79999999999999956e-47 < y < 2.19999999999999995e71Initial program 74.8%
if -1.99999999999999999e-73 < y < 7.79999999999999956e-47Initial program 61.2%
Taylor expanded in x around inf 80.0%
if 2.19999999999999995e71 < y Initial program 24.9%
Taylor expanded in x around 0 22.9%
Simplified22.9%
[Start]22.9 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{4 \cdot {y}^{2}}
\] |
|---|---|
*-commutative [=>]22.9 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{{y}^{2} \cdot 4}}
\] |
unpow2 [=>]22.9 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{\left(y \cdot y\right)} \cdot 4}
\] |
associate-*r* [<=]22.9 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{y \cdot \left(y \cdot 4\right)}}
\] |
Applied egg-rr81.0%
[Start]22.9 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{y \cdot \left(y \cdot 4\right)}
\] |
|---|---|
*-commutative [<=]22.9 | \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{\left(y \cdot 4\right) \cdot y}}
\] |
div-sub [=>]22.9 | \[ \color{blue}{\frac{x \cdot x}{\left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{\left(y \cdot 4\right) \cdot y}}
\] |
*-commutative [=>]22.9 | \[ \frac{x \cdot x}{\color{blue}{y \cdot \left(y \cdot 4\right)}} - \frac{\left(y \cdot 4\right) \cdot y}{\left(y \cdot 4\right) \cdot y}
\] |
times-frac [=>]23.2 | \[ \color{blue}{\frac{x}{y} \cdot \frac{x}{y \cdot 4}} - \frac{\left(y \cdot 4\right) \cdot y}{\left(y \cdot 4\right) \cdot y}
\] |
*-inverses [=>]81.0 | \[ \frac{x}{y} \cdot \frac{x}{y \cdot 4} - \color{blue}{1}
\] |
Final simplification79.6%
| Alternative 1 | |
|---|---|
| Accuracy | 73.8% |
| Cost | 2645 |
| Alternative 2 | |
|---|---|
| Accuracy | 79.6% |
| Cost | 1744 |
| Alternative 3 | |
|---|---|
| Accuracy | 74.0% |
| Cost | 1233 |
| Alternative 4 | |
|---|---|
| Accuracy | 73.6% |
| Cost | 968 |
| Alternative 5 | |
|---|---|
| Accuracy | 73.5% |
| Cost | 592 |
| Alternative 6 | |
|---|---|
| Accuracy | 50.4% |
| Cost | 64 |
herbie shell --seed 2023133
(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))))