Average Error: 7.6 → 6.1
Time: 16.2s
Precision: binary64
Cost: 2564
\[\frac{x + y}{1 - \frac{y}{z}}\]
↓
\[\begin{array}{l}
\mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \leq -7.571671828713221 \cdot 10^{-294} \lor \neg \left(\frac{x + y}{1 - \frac{y}{z}} \leq 0\right):\\
\;\;\;\;-\frac{x + y}{\frac{y}{z} - 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x + y}{1 + \frac{\sqrt{y}}{\sqrt{z}}}}{1 - \frac{\sqrt{y}}{\sqrt{z}}}\\
\end{array}\]
\frac{x + y}{1 - \frac{y}{z}}↓
\begin{array}{l}
\mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \leq -7.571671828713221 \cdot 10^{-294} \lor \neg \left(\frac{x + y}{1 - \frac{y}{z}} \leq 0\right):\\
\;\;\;\;-\frac{x + y}{\frac{y}{z} - 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x + y}{1 + \frac{\sqrt{y}}{\sqrt{z}}}}{1 - \frac{\sqrt{y}}{\sqrt{z}}}\\
\end{array}(FPCore (x y z) :precision binary64 (/ (+ x y) (- 1.0 (/ y z))))
↓
(FPCore (x y z)
:precision binary64
(if (or (<= (/ (+ x y) (- 1.0 (/ y z))) -7.571671828713221e-294)
(not (<= (/ (+ x y) (- 1.0 (/ y z))) 0.0)))
(- (/ (+ x y) (- (/ y z) 1.0)))
(/
(/ (+ x y) (+ 1.0 (/ (sqrt y) (sqrt z))))
(- 1.0 (/ (sqrt y) (sqrt z))))))double code(double x, double y, double z) {
return (x + y) / (1.0 - (y / z));
}
↓
double code(double x, double y, double z) {
double tmp;
if ((((x + y) / (1.0 - (y / z))) <= -7.571671828713221e-294) || !(((x + y) / (1.0 - (y / z))) <= 0.0)) {
tmp = -((x + y) / ((y / z) - 1.0));
} else {
tmp = ((x + y) / (1.0 + (sqrt(y) / sqrt(z)))) / (1.0 - (sqrt(y) / sqrt(z)));
}
return tmp;
}
Try it out
Enter valid numbers for all inputs
Target
| Original | 7.6 |
|---|
| Target | 4.0 |
|---|
| Herbie | 6.1 |
|---|
\[\begin{array}{l}
\mathbf{if}\;y < -3.7429310762689856 \cdot 10^{+171}:\\
\;\;\;\;\frac{y + x}{-y} \cdot z\\
\mathbf{elif}\;y < 3.5534662456086734 \cdot 10^{+168}:\\
\;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\
\mathbf{else}:\\
\;\;\;\;\frac{y + x}{-y} \cdot z\\
\end{array}\]
Alternatives
| Alternative 1 |
|---|
| Accuracy | 6.1 |
|---|
| Cost | 2692 |
|---|
\[\begin{array}{l}
\mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \leq -7.571671828713221 \cdot 10^{-294} \lor \neg \left(\frac{x + y}{1 - \frac{y}{z}} \leq 0\right):\\
\;\;\;\;-\frac{x + y}{\frac{y}{z} - 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y}{\frac{\sqrt{y}}{\sqrt{z}} - 1} \cdot \frac{-1}{1 + \frac{\sqrt{y}}{\sqrt{z}}}\\
\end{array}\]
| Alternative 2 |
|---|
| Accuracy | 6.1 |
|---|
| Cost | 3268 |
|---|
\[\begin{array}{l}
\mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \leq -7.571671828713221 \cdot 10^{-294} \lor \neg \left(\frac{x + y}{1 - \frac{y}{z}} \leq 0\right):\\
\;\;\;\;-\frac{x + y}{\frac{y}{z} - 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt[3]{x + y} \cdot \sqrt[3]{x + y}}{1 + \frac{\sqrt{y}}{\sqrt{z}}} \cdot \frac{\sqrt[3]{x + y}}{1 - \frac{\sqrt{y}}{\sqrt{z}}}\\
\end{array}\]
| Alternative 3 |
|---|
| Accuracy | 7.6 |
|---|
| Cost | 640 |
|---|
\[-\frac{x + y}{\frac{y}{z} - 1}\]
| Alternative 4 |
|---|
| Accuracy | 8.7 |
|---|
| Cost | 1280 |
|---|
\[\left(\sqrt[3]{x + y} \cdot \sqrt[3]{x + y}\right) \cdot \frac{\sqrt[3]{x + y}}{1 - \frac{y}{z}}\]
| Alternative 5 |
|---|
| Accuracy | 28.0 |
|---|
| Cost | 3078 |
|---|
\[\begin{array}{l}
\mathbf{if}\;y \leq -1.0272793344604454 \cdot 10^{+65}:\\
\;\;\;\;\frac{\sqrt[3]{y + x} \cdot \sqrt[3]{y + x}}{1 + \sqrt{\frac{y}{z}}} \cdot \frac{\sqrt[3]{y + x}}{1 - \sqrt{\frac{y}{z}}}\\
\mathbf{elif}\;y \leq -6.710582596235068 \cdot 10^{-160}:\\
\;\;\;\;\frac{-\left({x}^{3} + {y}^{3}\right)}{\left(\frac{y}{z} - 1\right) \cdot \left(x \cdot x + y \cdot \left(y - x\right)\right)}\\
\mathbf{elif}\;y \leq -1.2546136822733546 \cdot 10^{-304}:\\
\;\;\;\;\frac{\sqrt[3]{y + x} \cdot \sqrt[3]{y + x}}{1 + \sqrt{\frac{y}{z}}} \cdot \frac{\sqrt[3]{y + x}}{1 - \sqrt{\frac{y}{z}}}\\
\mathbf{elif}\;y \leq 2.8653198895621734 \cdot 10^{-76}:\\
\;\;\;\;\sqrt{y + x} \cdot \frac{\sqrt{y + x}}{1 - \frac{y}{z}}\\
\mathbf{elif}\;y \leq 2.061110669294841 \cdot 10^{-18}:\\
\;\;\;\;\frac{-\left({x}^{3} + {y}^{3}\right)}{\left(\frac{y}{z} - 1\right) \cdot \left(x \cdot x + y \cdot \left(y - x\right)\right)}\\
\mathbf{elif}\;y \leq 3.583161077537527 \cdot 10^{+264}:\\
\;\;\;\;\sqrt{y + x} \cdot \frac{\sqrt{y + x}}{1 - \frac{y}{z}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt[3]{y + x} \cdot \sqrt[3]{y + x}}{1 + \frac{\sqrt{y}}{\sqrt{z}}} \cdot \frac{\sqrt[3]{y + x}}{1 - \frac{\sqrt{y}}{\sqrt{z}}}\\
\end{array}\]
| Alternative 6 |
|---|
| Accuracy | 30.0 |
|---|
| Cost | 2113 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -3.6442018354467086 \cdot 10^{+120}:\\
\;\;\;\;\frac{\sqrt[3]{x + y} \cdot \sqrt[3]{x + y}}{1 + \frac{\sqrt{y}}{\sqrt{z}}} \cdot \frac{\sqrt[3]{x + y}}{1 - \frac{\sqrt{y}}{\sqrt{z}}}\\
\mathbf{elif}\;x \leq -1.6568013336058352 \cdot 10^{-147}:\\
\;\;\;\;\frac{-\left({x}^{3} + {y}^{3}\right)}{\left(\frac{y}{z} - 1\right) \cdot \left(x \cdot x + y \cdot \left(y - x\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x + y} \cdot \frac{\sqrt{x + y}}{1 - \frac{y}{z}}\\
\end{array}\]
| Alternative 7 |
|---|
| Accuracy | 32.3 |
|---|
| Cost | 1729 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.633228493482142 \cdot 10^{-138}:\\
\;\;\;\;\frac{-\left({x}^{3} + {y}^{3}\right)}{\left(\frac{y}{z} - 1\right) \cdot \left(x \cdot x + y \cdot \left(y - x\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x + y} \cdot \frac{\sqrt{x + y}}{1 - \frac{y}{z}}\\
\end{array}\]
| Alternative 8 |
|---|
| Accuracy | 36.6 |
|---|
| Cost | 1793 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -6.948620035425153 \cdot 10^{+22}:\\
\;\;\;\;\frac{\sqrt{x + y}}{1 + \frac{\sqrt{y}}{\sqrt{z}}} \cdot \frac{\sqrt{x + y}}{1 - \frac{\sqrt{y}}{\sqrt{z}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x + y} \cdot \frac{\sqrt{x + y}}{1 - \frac{y}{z}}\\
\end{array}\]
| Alternative 9 |
|---|
| Accuracy | 47.1 |
|---|
| Cost | 1793 |
|---|
\[\begin{array}{l}
\mathbf{if}\;y \leq 8.207175237586665 \cdot 10^{+147}:\\
\;\;\;\;\frac{\sqrt{y + x}}{1 + \sqrt{\frac{y}{z}}} \cdot \frac{\sqrt{y + x}}{1 - \sqrt{\frac{y}{z}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{y + x}}{1 + \frac{\sqrt{y}}{\sqrt{z}}} \cdot \frac{\sqrt{y + x}}{1 - \frac{\sqrt{y}}{\sqrt{z}}}\\
\end{array}\]
| Alternative 10 |
|---|
| Accuracy | 52.3 |
|---|
| Cost | 1600 |
|---|
\[\frac{\sqrt{x + y}}{1 + \frac{\sqrt{y}}{\sqrt{z}}} \cdot \frac{\sqrt{x + y}}{1 - \frac{\sqrt{y}}{\sqrt{z}}}\]
Derivation
- Split input into 2 regimes
if (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < -7.5716718287132213e-294 or -0.0 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z)))
Initial program 0.1
\[\frac{x + y}{1 - \frac{y}{z}}\]
- Using strategy
rm Applied *-un-lft-identity_binary64_236070.1
\[\leadsto \frac{x + y}{\color{blue}{1 \cdot \left(1 - \frac{y}{z}\right)}}\]
Applied *-un-lft-identity_binary64_236070.1
\[\leadsto \frac{\color{blue}{1 \cdot \left(x + y\right)}}{1 \cdot \left(1 - \frac{y}{z}\right)}\]
Applied times-frac_binary64_236130.1
\[\leadsto \color{blue}{\frac{1}{1} \cdot \frac{x + y}{1 - \frac{y}{z}}}\]
Simplified0.1
\[\leadsto \color{blue}{1} \cdot \frac{x + y}{1 - \frac{y}{z}}\]
- Using strategy
rm Applied *-un-lft-identity_binary64_236070.1
\[\leadsto 1 \cdot \frac{x + y}{\color{blue}{1 \cdot \left(1 - \frac{y}{z}\right)}}\]
Applied *-un-lft-identity_binary64_236070.1
\[\leadsto 1 \cdot \frac{\color{blue}{1 \cdot \left(x + y\right)}}{1 \cdot \left(1 - \frac{y}{z}\right)}\]
Applied times-frac_binary64_236130.1
\[\leadsto 1 \cdot \color{blue}{\left(\frac{1}{1} \cdot \frac{x + y}{1 - \frac{y}{z}}\right)}\]
Simplified0.1
\[\leadsto 1 \cdot \left(\color{blue}{1} \cdot \frac{x + y}{1 - \frac{y}{z}}\right)\]
- Using strategy
rm Applied frac-2neg_binary64_236180.1
\[\leadsto 1 \cdot \left(1 \cdot \color{blue}{\frac{-\left(x + y\right)}{-\left(1 - \frac{y}{z}\right)}}\right)\]
Simplified0.1
\[\leadsto 1 \cdot \left(1 \cdot \frac{-\left(x + y\right)}{\color{blue}{\frac{y}{z} - 1}}\right)\]
- Using strategy
rm Applied distribute-frac-neg_binary64_235700.1
\[\leadsto 1 \cdot \left(1 \cdot \color{blue}{\left(-\frac{x + y}{\frac{y}{z} - 1}\right)}\right)\]
if -7.5716718287132213e-294 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < -0.0
Initial program 59.1
\[\frac{x + y}{1 - \frac{y}{z}}\]
- Using strategy
rm Applied add-sqr-sqrt_binary64_2362960.9
\[\leadsto \frac{x + y}{1 - \frac{y}{\color{blue}{\sqrt{z} \cdot \sqrt{z}}}}\]
Applied add-sqr-sqrt_binary64_2362962.6
\[\leadsto \frac{x + y}{1 - \frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{\sqrt{z} \cdot \sqrt{z}}}\]
Applied times-frac_binary64_2361362.6
\[\leadsto \frac{x + y}{1 - \color{blue}{\frac{\sqrt{y}}{\sqrt{z}} \cdot \frac{\sqrt{y}}{\sqrt{z}}}}\]
Applied *-un-lft-identity_binary64_2360762.6
\[\leadsto \frac{x + y}{\color{blue}{1 \cdot 1} - \frac{\sqrt{y}}{\sqrt{z}} \cdot \frac{\sqrt{y}}{\sqrt{z}}}\]
Applied difference-of-squares_binary64_2357662.6
\[\leadsto \frac{x + y}{\color{blue}{\left(1 + \frac{\sqrt{y}}{\sqrt{z}}\right) \cdot \left(1 - \frac{\sqrt{y}}{\sqrt{z}}\right)}}\]
Applied associate-/r*_binary64_2355147.2
\[\leadsto \color{blue}{\frac{\frac{x + y}{1 + \frac{\sqrt{y}}{\sqrt{z}}}}{1 - \frac{\sqrt{y}}{\sqrt{z}}}}\]
- Recombined 2 regimes into one program.
Final simplification6.1
\[\leadsto \begin{array}{l}
\mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \leq -7.571671828713221 \cdot 10^{-294} \lor \neg \left(\frac{x + y}{1 - \frac{y}{z}} \leq 0\right):\\
\;\;\;\;-\frac{x + y}{\frac{y}{z} - 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x + y}{1 + \frac{\sqrt{y}}{\sqrt{z}}}}{1 - \frac{\sqrt{y}}{\sqrt{z}}}\\
\end{array}\]
Reproduce
herbie shell --seed 2020338
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Backend.Diagrams:calcFontMetrics from Chart-diagrams-1.5.1, A"
:precision binary64
:herbie-target
(if (< y -3.7429310762689856e+171) (* (/ (+ y x) (- y)) z) (if (< y 3.5534662456086734e+168) (/ (+ x y) (- 1.0 (/ y z))) (* (/ (+ y x) (- y)) z)))
(/ (+ x y) (- 1.0 (/ y z))))