Average Error: 7.1 → 4.4
Time: 20.7s
Precision: 64
Internal precision: 128
\[\frac{x \cdot 2.0}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot 2.0}{y \cdot z - t \cdot z} \le -0.0:\\ \;\;\;\;\frac{1}{\frac{y - t}{\frac{x}{z}}} \cdot 2.0\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\left(y - t\right) \cdot z} \cdot 2.0\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original7.1
Comparison2.4
Herbie4.4
\[ \begin{array}{l} \mathbf{if}\;\frac{x \cdot 2.0}{y \cdot z - t \cdot z} \lt -2.559141628295061 \cdot 10^{-13}:\\ \;\;\;\;\frac{x}{\left(y - t\right) \cdot z} \cdot 2.0\\ \mathbf{if}\;\frac{x \cdot 2.0}{y \cdot z - t \cdot z} \lt 1.045027827330126 \cdot 10^{-269}:\\ \;\;\;\;\frac{\frac{x}{z} \cdot 2.0}{y - t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\left(y - t\right) \cdot z} \cdot 2.0\\ \end{array} \]

Derivation

  1. Split input into 2 regimes.
  2. if (/ (* x 2.0) (- (* y z) (* t z))) < -0.0

    1. Initial program 7.6

      \[\frac{x \cdot 2.0}{y \cdot z - t \cdot z}\]
    2. Applied simplify 4.4

      \[\leadsto \color{blue}{\frac{\frac{x}{z}}{y - t} \cdot 2.0}\]
    3. Using strategy rm
    4. Applied clear-num 4.9

      \[\leadsto \color{blue}{\frac{1}{\frac{y - t}{\frac{x}{z}}}} \cdot 2.0\]

    if -0.0 < (/ (* x 2.0) (- (* y z) (* t z)))

    1. Initial program 6.0

      \[\frac{x \cdot 2.0}{y \cdot z - t \cdot z}\]
    2. Applied simplify 8.2

      \[\leadsto \color{blue}{\frac{\frac{x}{z}}{y - t} \cdot 2.0}\]
    3. Using strategy rm
    4. Applied associate-/l/ 3.4

      \[\leadsto \color{blue}{\frac{x}{\left(y - t\right) \cdot z}} \cdot 2.0\]
  3. Recombined 2 regimes into one program.
  4. Removed slow pow expressions

Runtime

Time bar (total: 20.7s) Debug log

Please include this information when filing a bug report:

herbie --seed '#(1445915184 1441980852 4276603271 1303467849 3945581563 4230502465)'
(FPCore (x y z t)
  :name "Linear.Projection:infinitePerspective from linear-1.19.1.3, A"

  :target
  (if (< (/ (* x 2.0) (- (* y z) (* t z))) -2.559141628295061e-13) (* (/ x (* (- y t) z)) 2.0) (if (< (/ (* x 2.0) (- (* y z) (* t z))) 1.045027827330126e-269) (/ (* (/ x z) 2.0) (- y t)) (* (/ x (* (- y t) z)) 2.0)))

  (/ (* x 2.0) (- (* y z) (* t z))))