Average Error: 7.6 → 0.4
Time: 4.0s
Precision: binary64
\[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
\[\begin{array}{l} \mathbf{if}\;y \le -2.15725848043232726 \cdot 10^{-19}:\\ \;\;\;\;\frac{\frac{1}{2} \cdot \left(e^{-1 \cdot x} + e^{x}\right)}{\left(z \cdot x\right) \cdot \frac{1}{y}}\\ \mathbf{elif}\;y \le 1.9336417089000438 \cdot 10^{-7}:\\ \;\;\;\;\left(\cosh x \cdot \frac{y}{x}\right) \cdot \frac{1}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(e^{x} + e^{-x}\right) \cdot y}{z}}{2 \cdot x}\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original7.6
Target0.4
Herbie0.4
\[\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 3 regimes
  2. if y < -2.15725848043232726e-19

    1. Initial program 19.8

      \[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
    2. Taylor expanded around inf 0.4

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

      \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \left(e^{-1 \cdot x} + e^{x}\right)}{\frac{z \cdot x}{y}}}\]
    4. Using strategy rm
    5. Applied div-inv0.4

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

    if -2.15725848043232726e-19 < y < 1.9336417089000438e-7

    1. Initial program 0.3

      \[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
    2. Using strategy rm
    3. Applied div-inv0.4

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

    if 1.9336417089000438e-7 < y

    1. Initial program 20.4

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

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

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

      \[\leadsto \color{blue}{\frac{\left(e^{x} + e^{-x}\right) \cdot y}{z \cdot \left(2 \cdot x\right)}}\]
    6. Using strategy rm
    7. Applied associate-/r*0.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.15725848043232726 \cdot 10^{-19}:\\ \;\;\;\;\frac{\frac{1}{2} \cdot \left(e^{-1 \cdot x} + e^{x}\right)}{\left(z \cdot x\right) \cdot \frac{1}{y}}\\ \mathbf{elif}\;y \le 1.9336417089000438 \cdot 10^{-7}:\\ \;\;\;\;\left(\cosh x \cdot \frac{y}{x}\right) \cdot \frac{1}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(e^{x} + e^{-x}\right) \cdot y}{z}}{2 \cdot x}\\ \end{array}\]

Reproduce

herbie shell --seed 2020161 
(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))