| Alternative 1 | |
|---|---|
| Accuracy | 74.0% |
| Cost | 1236 |
(FPCore (x y) :precision binary64 (/ (* (* x 2.0) y) (- x y)))
(FPCore (x y)
:precision binary64
(if (<= x -5.8e+130)
(* y (/ (* x 2.0) (- x y)))
(if (<= x 9.5e-17)
(/ (/ x (+ (/ x y) -1.0)) 0.5)
(/ y (fma (/ y x) -0.5 0.5)))))double code(double x, double y) {
return ((x * 2.0) * y) / (x - y);
}
double code(double x, double y) {
double tmp;
if (x <= -5.8e+130) {
tmp = y * ((x * 2.0) / (x - y));
} else if (x <= 9.5e-17) {
tmp = (x / ((x / y) + -1.0)) / 0.5;
} else {
tmp = y / fma((y / x), -0.5, 0.5);
}
return tmp;
}
function code(x, y) return Float64(Float64(Float64(x * 2.0) * y) / Float64(x - y)) end
function code(x, y) tmp = 0.0 if (x <= -5.8e+130) tmp = Float64(y * Float64(Float64(x * 2.0) / Float64(x - y))); elseif (x <= 9.5e-17) tmp = Float64(Float64(x / Float64(Float64(x / y) + -1.0)) / 0.5); else tmp = Float64(y / fma(Float64(y / x), -0.5, 0.5)); end return tmp end
code[x_, y_] := N[(N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[LessEqual[x, -5.8e+130], N[(y * N[(N[(x * 2.0), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 9.5e-17], N[(N[(x / N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] / 0.5), $MachinePrecision], N[(y / N[(N[(y / x), $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision]]]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{+130}:\\
\;\;\;\;y \cdot \frac{x \cdot 2}{x - y}\\
\mathbf{elif}\;x \leq 9.5 \cdot 10^{-17}:\\
\;\;\;\;\frac{\frac{x}{\frac{x}{y} + -1}}{0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\mathsf{fma}\left(\frac{y}{x}, -0.5, 0.5\right)}\\
\end{array}
| Original | 75.9% |
|---|---|
| Target | 99.4% |
| Herbie | 98.7% |
if x < -5.7999999999999998e130Initial program 64.1%
Simplified99.8%
[Start]64.1 | \[ \frac{\left(x \cdot 2\right) \cdot y}{x - y}
\] |
|---|---|
associate-*l/ [<=]99.8 | \[ \color{blue}{\frac{x \cdot 2}{x - y} \cdot y}
\] |
if -5.7999999999999998e130 < x < 9.50000000000000029e-17Initial program 78.7%
Simplified81.4%
[Start]78.7 | \[ \frac{\left(x \cdot 2\right) \cdot y}{x - y}
\] |
|---|---|
associate-*l/ [<=]81.4 | \[ \color{blue}{\frac{x \cdot 2}{x - y} \cdot y}
\] |
Applied egg-rr81.4%
[Start]81.4 | \[ \frac{x \cdot 2}{x - y} \cdot y
\] |
|---|---|
add-log-exp [=>]6.6 | \[ \color{blue}{\log \left(e^{\frac{x \cdot 2}{x - y} \cdot y}\right)}
\] |
*-un-lft-identity [=>]6.6 | \[ \log \color{blue}{\left(1 \cdot e^{\frac{x \cdot 2}{x - y} \cdot y}\right)}
\] |
log-prod [=>]6.6 | \[ \color{blue}{\log 1 + \log \left(e^{\frac{x \cdot 2}{x - y} \cdot y}\right)}
\] |
metadata-eval [=>]6.6 | \[ \color{blue}{0} + \log \left(e^{\frac{x \cdot 2}{x - y} \cdot y}\right)
\] |
add-log-exp [<=]81.4 | \[ 0 + \color{blue}{\frac{x \cdot 2}{x - y} \cdot y}
\] |
*-commutative [=>]81.4 | \[ 0 + \color{blue}{y \cdot \frac{x \cdot 2}{x - y}}
\] |
*-commutative [=>]81.4 | \[ 0 + y \cdot \frac{\color{blue}{2 \cdot x}}{x - y}
\] |
*-un-lft-identity [=>]81.4 | \[ 0 + y \cdot \frac{2 \cdot x}{\color{blue}{1 \cdot \left(x - y\right)}}
\] |
times-frac [=>]81.4 | \[ 0 + y \cdot \color{blue}{\left(\frac{2}{1} \cdot \frac{x}{x - y}\right)}
\] |
metadata-eval [=>]81.4 | \[ 0 + y \cdot \left(\color{blue}{2} \cdot \frac{x}{x - y}\right)
\] |
Simplified97.9%
[Start]81.4 | \[ 0 + y \cdot \left(2 \cdot \frac{x}{x - y}\right)
\] |
|---|---|
+-lft-identity [=>]81.4 | \[ \color{blue}{y \cdot \left(2 \cdot \frac{x}{x - y}\right)}
\] |
*-commutative [=>]81.4 | \[ \color{blue}{\left(2 \cdot \frac{x}{x - y}\right) \cdot y}
\] |
*-commutative [<=]81.4 | \[ \color{blue}{\left(\frac{x}{x - y} \cdot 2\right)} \cdot y
\] |
metadata-eval [<=]81.4 | \[ \left(\frac{x}{x - y} \cdot \color{blue}{\frac{1}{0.5}}\right) \cdot y
\] |
times-frac [<=]81.4 | \[ \color{blue}{\frac{x \cdot 1}{\left(x - y\right) \cdot 0.5}} \cdot y
\] |
*-rgt-identity [=>]81.4 | \[ \frac{\color{blue}{x}}{\left(x - y\right) \cdot 0.5} \cdot y
\] |
associate-/r/ [<=]97.9 | \[ \color{blue}{\frac{x}{\frac{\left(x - y\right) \cdot 0.5}{y}}}
\] |
associate-/l* [<=]78.7 | \[ \color{blue}{\frac{x \cdot y}{\left(x - y\right) \cdot 0.5}}
\] |
associate-/r* [=>]78.7 | \[ \color{blue}{\frac{\frac{x \cdot y}{x - y}}{0.5}}
\] |
associate-/l* [=>]97.9 | \[ \frac{\color{blue}{\frac{x}{\frac{x - y}{y}}}}{0.5}
\] |
div-sub [=>]97.9 | \[ \frac{\frac{x}{\color{blue}{\frac{x}{y} - \frac{y}{y}}}}{0.5}
\] |
sub-neg [=>]97.9 | \[ \frac{\frac{x}{\color{blue}{\frac{x}{y} + \left(-\frac{y}{y}\right)}}}{0.5}
\] |
*-inverses [=>]97.9 | \[ \frac{\frac{x}{\frac{x}{y} + \left(-\color{blue}{1}\right)}}{0.5}
\] |
metadata-eval [=>]97.9 | \[ \frac{\frac{x}{\frac{x}{y} + \color{blue}{-1}}}{0.5}
\] |
if 9.50000000000000029e-17 < x Initial program 76.0%
Simplified99.9%
[Start]76.0 | \[ \frac{\left(x \cdot 2\right) \cdot y}{x - y}
\] |
|---|---|
*-commutative [=>]76.0 | \[ \frac{\color{blue}{y \cdot \left(x \cdot 2\right)}}{x - y}
\] |
associate-/l* [=>]99.7 | \[ \color{blue}{\frac{y}{\frac{x - y}{x \cdot 2}}}
\] |
div-sub [=>]99.7 | \[ \frac{y}{\color{blue}{\frac{x}{x \cdot 2} - \frac{y}{x \cdot 2}}}
\] |
sub-neg [=>]99.7 | \[ \frac{y}{\color{blue}{\frac{x}{x \cdot 2} + \left(-\frac{y}{x \cdot 2}\right)}}
\] |
+-commutative [=>]99.7 | \[ \frac{y}{\color{blue}{\left(-\frac{y}{x \cdot 2}\right) + \frac{x}{x \cdot 2}}}
\] |
distribute-neg-frac [=>]99.7 | \[ \frac{y}{\color{blue}{\frac{-y}{x \cdot 2}} + \frac{x}{x \cdot 2}}
\] |
neg-mul-1 [=>]99.7 | \[ \frac{y}{\frac{\color{blue}{-1 \cdot y}}{x \cdot 2} + \frac{x}{x \cdot 2}}
\] |
*-commutative [=>]99.7 | \[ \frac{y}{\frac{\color{blue}{y \cdot -1}}{x \cdot 2} + \frac{x}{x \cdot 2}}
\] |
times-frac [=>]99.7 | \[ \frac{y}{\color{blue}{\frac{y}{x} \cdot \frac{-1}{2}} + \frac{x}{x \cdot 2}}
\] |
metadata-eval [=>]99.7 | \[ \frac{y}{\frac{y}{x} \cdot \color{blue}{-0.5} + \frac{x}{x \cdot 2}}
\] |
metadata-eval [<=]99.7 | \[ \frac{y}{\frac{y}{x} \cdot \color{blue}{\left(-0.5\right)} + \frac{x}{x \cdot 2}}
\] |
metadata-eval [<=]99.7 | \[ \frac{y}{\frac{y}{x} \cdot \left(-\color{blue}{\frac{1}{2}}\right) + \frac{x}{x \cdot 2}}
\] |
*-inverses [<=]99.7 | \[ \frac{y}{\frac{y}{x} \cdot \left(-\frac{\color{blue}{\frac{y}{y}}}{2}\right) + \frac{x}{x \cdot 2}}
\] |
associate-/r* [<=]99.7 | \[ \frac{y}{\frac{y}{x} \cdot \left(-\color{blue}{\frac{y}{y \cdot 2}}\right) + \frac{x}{x \cdot 2}}
\] |
*-commutative [<=]99.7 | \[ \frac{y}{\frac{y}{x} \cdot \left(-\frac{y}{\color{blue}{2 \cdot y}}\right) + \frac{x}{x \cdot 2}}
\] |
associate-/r* [=>]99.8 | \[ \frac{y}{\frac{y}{x} \cdot \left(-\frac{y}{2 \cdot y}\right) + \color{blue}{\frac{\frac{x}{x}}{2}}}
\] |
*-inverses [=>]99.8 | \[ \frac{y}{\frac{y}{x} \cdot \left(-\frac{y}{2 \cdot y}\right) + \frac{\color{blue}{1}}{2}}
\] |
*-inverses [<=]99.8 | \[ \frac{y}{\frac{y}{x} \cdot \left(-\frac{y}{2 \cdot y}\right) + \frac{\color{blue}{\frac{y}{y}}}{2}}
\] |
associate-/r* [<=]99.8 | \[ \frac{y}{\frac{y}{x} \cdot \left(-\frac{y}{2 \cdot y}\right) + \color{blue}{\frac{y}{y \cdot 2}}}
\] |
*-commutative [<=]99.8 | \[ \frac{y}{\frac{y}{x} \cdot \left(-\frac{y}{2 \cdot y}\right) + \frac{y}{\color{blue}{2 \cdot y}}}
\] |
fma-def [=>]99.8 | \[ \frac{y}{\color{blue}{\mathsf{fma}\left(\frac{y}{x}, -\frac{y}{2 \cdot y}, \frac{y}{2 \cdot y}\right)}}
\] |
Final simplification98.7%
| Alternative 1 | |
|---|---|
| Accuracy | 74.0% |
| Cost | 1236 |
| Alternative 2 | |
|---|---|
| Accuracy | 70.9% |
| Cost | 986 |
| Alternative 3 | |
|---|---|
| Accuracy | 93.6% |
| Cost | 841 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 841 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 841 |
| Alternative 6 | |
|---|---|
| Accuracy | 51.5% |
| Cost | 192 |
herbie shell --seed 2023151
(FPCore (x y)
:name "Linear.Projection:perspective from linear-1.19.1.3, B"
:precision binary64
:herbie-target
(if (< x -1.7210442634149447e+81) (* (/ (* 2.0 x) (- x y)) y) (if (< x 83645045635564430.0) (/ (* x 2.0) (/ (- x y) y)) (* (/ (* 2.0 x) (- x y)) y)))
(/ (* (* x 2.0) y) (- x y)))