Average Error: 5.9 → 1.5
Time: 21.6s
Precision: 64
Internal precision: 128
\[x + \frac{y \cdot \left(z - t\right)}{a}\]
⬇
\[\begin{array}{l}
\mathbf{if}\;y \le -2.930244047323321 \cdot 10^{+18}:\\
\;\;\;\;x + y \cdot \frac{z - t}{a}\\
\mathbf{if}\;y \le 8.166728288538418 \cdot 10^{-294}:\\
\;\;\;\;x + \frac{1}{\frac{a}{y \cdot \left(z - t\right)}}\\
\mathbf{else}:\\
\;\;\;\;\left(z - t\right) \cdot \frac{y}{a} + x\\
\end{array}\]
Target
| Original | 5.9 |
| Comparison | 0.7 |
| Herbie | 1.5 |
\[ \begin{array}{l}
\mathbf{if}\;y \lt -1.0761266216389975 \cdot 10^{-10}:\\
\;\;\;\;x + \frac{1}{\frac{\frac{a}{z - t}}{y}}\\
\mathbf{if}\;y \lt 2.894426862792089 \cdot 10^{-49}:\\
\;\;\;\;x + \frac{y \cdot \left(z - t\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{\frac{a}{z - t}}\\
\end{array} \]
Derivation
- Split input into 3 regimes.
-
if y < -2.930244047323321e+18
Initial program 16.2
\[x + \frac{y \cdot \left(z - t\right)}{a}\]
- Using strategy
rm
Applied associate-/l* 0.8
\[\leadsto x + \color{blue}{\frac{y}{\frac{a}{z - t}}}\]
- Using strategy
rm
Applied div-inv 0.9
\[\leadsto x + \color{blue}{y \cdot \frac{1}{\frac{a}{z - t}}}\]
Applied simplify 0.7
\[\leadsto x + y \cdot \color{blue}{\frac{z - t}{a}}\]
if -2.930244047323321e+18 < y < 8.166728288538418e-294
Initial program 0.5
\[x + \frac{y \cdot \left(z - t\right)}{a}\]
- Using strategy
rm
Applied clear-num 0.5
\[\leadsto x + \color{blue}{\frac{1}{\frac{a}{y \cdot \left(z - t\right)}}}\]
if 8.166728288538418e-294 < y
Initial program 5.9
\[x + \frac{y \cdot \left(z - t\right)}{a}\]
Applied taylor 5.9
\[\leadsto x + \left(\frac{z \cdot y}{a} - \frac{y \cdot t}{a}\right)\]
Taylor expanded around 0 5.9
\[\leadsto x + \color{blue}{\left(\frac{z \cdot y}{a} - \frac{y \cdot t}{a}\right)}\]
Applied simplify 2.5
\[\leadsto \color{blue}{\left(z - t\right) \cdot \frac{y}{a} + x}\]
- Recombined 3 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie --seed '#(135602787 3184856799 782155709 2163984879 918053591 2666361788)'
(FPCore (x y z t a)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, E"
:target
(if (< y -1.0761266216389975e-10) (+ x (/ 1 (/ (/ a (- z t)) y))) (if (< y 2.894426862792089e-49) (+ x (/ (* y (- z t)) a)) (+ x (/ y (/ a (- z t))))))
(+ x (/ (* y (- z t)) a)))