Average Error: 7.3 → 0.5
Time: 3.6s
Precision: binary64
\[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -249440.402053816972 \lor \neg \left(z \le 3.71476213272403721 \cdot 10^{-50}\right):\\ \;\;\;\;\frac{\left(e^{x} + e^{-x}\right) \cdot y}{x \cdot \left(z \cdot 2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cosh x}{x \cdot \frac{z}{y}}\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original7.3
Target0.4
Herbie0.5
\[\begin{array}{l} \mathbf{if}\;y \lt -4.618902267687042 \cdot 10^{-52}:\\ \;\;\;\;\frac{\frac{y}{z}}{x} \cdot \cosh x\\ \mathbf{elif}\;y \lt 1.0385305359351529 \cdot 10^{-39}:\\ \;\;\;\;\frac{\frac{\cosh x \cdot y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{z}}{x} \cdot \cosh x\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if z < -249440.402053816972 or 3.71476213272403721e-50 < z

    1. Initial program 10.7

      \[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
    2. Using strategy rm
    3. Applied cosh-def10.7

      \[\leadsto \frac{\color{blue}{\frac{e^{x} + e^{-x}}{2}} \cdot \frac{y}{x}}{z}\]
    4. Applied frac-times10.7

      \[\leadsto \frac{\color{blue}{\frac{\left(e^{x} + e^{-x}\right) \cdot y}{2 \cdot x}}}{z}\]
    5. Applied associate-/l/0.5

      \[\leadsto \color{blue}{\frac{\left(e^{x} + e^{-x}\right) \cdot y}{z \cdot \left(2 \cdot x\right)}}\]
    6. Simplified0.5

      \[\leadsto \frac{\left(e^{x} + e^{-x}\right) \cdot y}{\color{blue}{x \cdot \left(z \cdot 2\right)}}\]

    if -249440.402053816972 < z < 3.71476213272403721e-50

    1. Initial program 0.3

      \[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
    2. Using strategy rm
    3. Applied associate-/l*0.4

      \[\leadsto \color{blue}{\frac{\cosh x}{\frac{z}{\frac{y}{x}}}}\]
    4. Simplified0.3

      \[\leadsto \frac{\cosh x}{\color{blue}{x \cdot \frac{z}{y}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -249440.402053816972 \lor \neg \left(z \le 3.71476213272403721 \cdot 10^{-50}\right):\\ \;\;\;\;\frac{\left(e^{x} + e^{-x}\right) \cdot y}{x \cdot \left(z \cdot 2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cosh x}{x \cdot \frac{z}{y}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020185 
(FPCore (x y z)
  :name "Linear.Quaternion:$ctan from linear-1.19.1.3"
  :precision binary64

  :herbie-target
  (if (< y -4.618902267687042e-52) (* (/ (/ y z) x) (cosh x)) (if (< y 1.0385305359351529e-39) (/ (/ (* (cosh x) y) x) z) (* (/ (/ y z) x) (cosh x))))

  (/ (* (cosh x) (/ y x)) z))