Average Error: 9.9 → 0.2
Time: 1.3m
Precision: 64
Internal Precision: 384
\[\frac{x \cdot \left(\left(y - z\right) + 1.0\right)}{z}\]
↓
\[\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(\left(y - z\right) + 1.0\right)}{z} \le -1.293154407109218 \cdot 10^{+92}:\\
\;\;\;\;\frac{x}{z} \cdot \left(y + 1.0\right) - x\\
\mathbf{if}\;\frac{x \cdot \left(\left(y - z\right) + 1.0\right)}{z} \le 4.04716974457547 \cdot 10^{-37}:\\
\;\;\;\;\frac{x}{\frac{z}{\left(y - z\right) + 1.0}}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} \cdot \left(y + 1.0\right) - x\\
\end{array}\]
Target
| Original | 9.9 |
|---|
| Target | 0.5 |
|---|
| Herbie | 0.2 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \lt -2.71483106713436 \cdot 10^{-162}:\\
\;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\
\mathbf{if}\;x \lt 3.874108816439546 \cdot 10^{-197}:\\
\;\;\;\;\left(x \cdot \left(\left(y - z\right) + 1.0\right)\right) \cdot \frac{1}{z}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\
\end{array}\]
Derivation
- Split input into 2 regimes
if (/ (* x (+ (- y z) 1.0)) z) < -1.293154407109218e+92 or 4.04716974457547e-37 < (/ (* x (+ (- y z) 1.0)) z)
Initial program 17.5
\[\frac{x \cdot \left(\left(y - z\right) + 1.0\right)}{z}\]
Taylor expanded around 0 6.0
\[\leadsto \color{blue}{\left(\frac{y \cdot x}{z} + 1.0 \cdot \frac{x}{z}\right) - x}\]
Applied simplify0.1
\[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + 1.0\right) - x}\]
if -1.293154407109218e+92 < (/ (* x (+ (- y z) 1.0)) z) < 4.04716974457547e-37
Initial program 0.1
\[\frac{x \cdot \left(\left(y - z\right) + 1.0\right)}{z}\]
- Using strategy
rm Applied associate-/l*0.4
\[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1.0}}}\]
- Recombined 2 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1567391828 2030694642 2833800258 828025724 3004380912 3532991858)' +o setup:early-exit +o reduce:binary-search
(FPCore (x y z)
:name "Diagrams.TwoD.Segment.Bernstein:evaluateBernstein from diagrams-lib-1.3.0.3"
:herbie-target
(if (< x -2.71483106713436e-162) (- (* (+ 1 y) (/ x z)) x) (if (< x 3.874108816439546e-197) (* (* x (+ (- y z) 1.0)) (/ 1 z)) (- (* (+ 1 y) (/ x z)) x)))
(/ (* x (+ (- y z) 1.0)) z))