Average Error: 10.4 → 0.4
Time: 15.6s
Precision: 64
\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -4.313852520271656563709718265853465906161 \cdot 10^{-45}:\\ \;\;\;\;\frac{x}{\frac{z}{y - \left(z - 1\right)}}\\ \mathbf{elif}\;z \le 1.449695680811044084592089274592529344583 \cdot 10^{-119}:\\ \;\;\;\;\left(\frac{x}{z} \cdot 1 + \frac{y \cdot x}{z}\right) - x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{y - \left(z - 1\right)}}\\ \end{array}\]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
\mathbf{if}\;z \le -4.313852520271656563709718265853465906161 \cdot 10^{-45}:\\
\;\;\;\;\frac{x}{\frac{z}{y - \left(z - 1\right)}}\\

\mathbf{elif}\;z \le 1.449695680811044084592089274592529344583 \cdot 10^{-119}:\\
\;\;\;\;\left(\frac{x}{z} \cdot 1 + \frac{y \cdot x}{z}\right) - x\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{y - \left(z - 1\right)}}\\

\end{array}
double f(double x, double y, double z) {
        double r30702840 = x;
        double r30702841 = y;
        double r30702842 = z;
        double r30702843 = r30702841 - r30702842;
        double r30702844 = 1.0;
        double r30702845 = r30702843 + r30702844;
        double r30702846 = r30702840 * r30702845;
        double r30702847 = r30702846 / r30702842;
        return r30702847;
}

double f(double x, double y, double z) {
        double r30702848 = z;
        double r30702849 = -4.3138525202716566e-45;
        bool r30702850 = r30702848 <= r30702849;
        double r30702851 = x;
        double r30702852 = y;
        double r30702853 = 1.0;
        double r30702854 = r30702848 - r30702853;
        double r30702855 = r30702852 - r30702854;
        double r30702856 = r30702848 / r30702855;
        double r30702857 = r30702851 / r30702856;
        double r30702858 = 1.449695680811044e-119;
        bool r30702859 = r30702848 <= r30702858;
        double r30702860 = r30702851 / r30702848;
        double r30702861 = r30702860 * r30702853;
        double r30702862 = r30702852 * r30702851;
        double r30702863 = r30702862 / r30702848;
        double r30702864 = r30702861 + r30702863;
        double r30702865 = r30702864 - r30702851;
        double r30702866 = r30702859 ? r30702865 : r30702857;
        double r30702867 = r30702850 ? r30702857 : r30702866;
        return r30702867;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original10.4
Target0.5
Herbie0.4
\[\begin{array}{l} \mathbf{if}\;x \lt -2.714831067134359919650240696134672137284 \cdot 10^{-162}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \mathbf{elif}\;x \lt 3.874108816439546156869494499878029491333 \cdot 10^{-197}:\\ \;\;\;\;\left(x \cdot \left(\left(y - z\right) + 1\right)\right) \cdot \frac{1}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if z < -4.3138525202716566e-45 or 1.449695680811044e-119 < z

    1. Initial program 14.0

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
    2. Using strategy rm
    3. Applied associate-/l*0.5

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}}\]
    4. Using strategy rm
    5. Applied clear-num0.6

      \[\leadsto \color{blue}{\frac{1}{\frac{\frac{z}{\left(y - z\right) + 1}}{x}}}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity0.6

      \[\leadsto \frac{1}{\frac{\frac{z}{\left(y - z\right) + 1}}{\color{blue}{1 \cdot x}}}\]
    8. Applied *-un-lft-identity0.6

      \[\leadsto \frac{1}{\frac{\frac{z}{\color{blue}{1 \cdot \left(\left(y - z\right) + 1\right)}}}{1 \cdot x}}\]
    9. Applied *-un-lft-identity0.6

      \[\leadsto \frac{1}{\frac{\frac{\color{blue}{1 \cdot z}}{1 \cdot \left(\left(y - z\right) + 1\right)}}{1 \cdot x}}\]
    10. Applied times-frac0.6

      \[\leadsto \frac{1}{\frac{\color{blue}{\frac{1}{1} \cdot \frac{z}{\left(y - z\right) + 1}}}{1 \cdot x}}\]
    11. Applied times-frac0.6

      \[\leadsto \frac{1}{\color{blue}{\frac{\frac{1}{1}}{1} \cdot \frac{\frac{z}{\left(y - z\right) + 1}}{x}}}\]
    12. Applied add-cube-cbrt0.6

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{\frac{1}{1}}{1} \cdot \frac{\frac{z}{\left(y - z\right) + 1}}{x}}\]
    13. Applied times-frac0.6

      \[\leadsto \color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{\frac{1}{1}}{1}} \cdot \frac{\sqrt[3]{1}}{\frac{\frac{z}{\left(y - z\right) + 1}}{x}}}\]
    14. Simplified0.6

      \[\leadsto \color{blue}{1} \cdot \frac{\sqrt[3]{1}}{\frac{\frac{z}{\left(y - z\right) + 1}}{x}}\]
    15. Simplified0.5

      \[\leadsto 1 \cdot \color{blue}{\frac{1 \cdot x}{\frac{z}{y - \left(z - 1\right)}}}\]

    if -4.3138525202716566e-45 < z < 1.449695680811044e-119

    1. Initial program 0.1

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
    2. Taylor expanded around 0 0.1

      \[\leadsto \color{blue}{\left(\frac{x \cdot y}{z} + 1 \cdot \frac{x}{z}\right) - x}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -4.313852520271656563709718265853465906161 \cdot 10^{-45}:\\ \;\;\;\;\frac{x}{\frac{z}{y - \left(z - 1\right)}}\\ \mathbf{elif}\;z \le 1.449695680811044084592089274592529344583 \cdot 10^{-119}:\\ \;\;\;\;\left(\frac{x}{z} \cdot 1 + \frac{y \cdot x}{z}\right) - x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{y - \left(z - 1\right)}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019170 
(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.0 y) (/ x z)) x) (if (< x 3.874108816439546e-197) (* (* x (+ (- y z) 1.0)) (/ 1.0 z)) (- (* (+ 1.0 y) (/ x z)) x)))

  (/ (* x (+ (- y z) 1.0)) z))