Average Error: 10.0 → 0.1
Time: 2.3s
Precision: binary64
\[\frac{x + y \cdot \left(z - x\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -1.3417794474143735 \cdot 10^{-16} \lor \neg \left(z \le 9.86972381747270371 \cdot 10^{-55}\right):\\ \;\;\;\;\left(\frac{x}{z} + y\right) - x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + \left(y \cdot z + y \cdot \left(-x\right)\right)}{z}\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original10.0
Target0.0
Herbie0.1
\[\left(y + \frac{x}{z}\right) - \frac{y}{\frac{z}{x}}\]

Derivation

  1. Split input into 2 regimes
  2. if z < -1.3417794474143735e-16 or 9.86972381747270371e-55 < z

    1. Initial program 15.2

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

      \[\leadsto \color{blue}{\left(\frac{x}{z} + y\right) - \frac{x \cdot y}{z}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity5.2

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

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

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

    if -1.3417794474143735e-16 < z < 9.86972381747270371e-55

    1. Initial program 0.1

      \[\frac{x + y \cdot \left(z - x\right)}{z}\]
    2. Using strategy rm
    3. Applied sub-neg0.1

      \[\leadsto \frac{x + y \cdot \color{blue}{\left(z + \left(-x\right)\right)}}{z}\]
    4. Applied distribute-lft-in0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -1.3417794474143735 \cdot 10^{-16} \lor \neg \left(z \le 9.86972381747270371 \cdot 10^{-55}\right):\\ \;\;\;\;\left(\frac{x}{z} + y\right) - x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + \left(y \cdot z + y \cdot \left(-x\right)\right)}{z}\\ \end{array}\]

Reproduce

herbie shell --seed 2020155 
(FPCore (x y z)
  :name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
  :precision binary64

  :herbie-target
  (- (+ y (/ x z)) (/ y (/ z x)))

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