Average Error: 3.2 → 1.8
Time: 1.1m
Precision: 64
Internal Precision: 384
\[x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)\]
\[x \cdot 1.0 - \left(z \cdot x\right) \cdot \left(1.0 - y\right)\]

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.2
Target0.2
Herbie1.8
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right) \lt -1.618195973607049 \cdot 10^{+50}:\\ \;\;\;\;x + \left(1.0 - y\right) \cdot \left(\left(-z\right) \cdot x\right)\\ \mathbf{if}\;x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right) \lt 3.892237649663903 \cdot 10^{+134}:\\ \;\;\;\;\left(x \cdot y\right) \cdot z - \left(x \cdot z - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(1.0 - y\right) \cdot \left(\left(-z\right) \cdot x\right)\\ \end{array}\]

Derivation

  1. Initial program 3.2

    \[x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)\]
  2. Taylor expanded around inf 3.4

    \[\leadsto \color{blue}{\left(z \cdot \left(y \cdot x\right) + 1.0 \cdot x\right) - 1.0 \cdot \left(z \cdot x\right)}\]
  3. Applied simplify1.8

    \[\leadsto \color{blue}{x \cdot 1.0 - \left(z \cdot x\right) \cdot \left(1.0 - y\right)}\]
  4. Removed slow pow expressions.

Runtime

Time bar (total: 1.1m)Debug log

herbie shell --seed '#(1567391828 2030694642 2833800258 828025724 3004380912 3532991858)' +o setup:early-exit +o reduce:binary-search
(FPCore (x y z)
  :name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, J"

  :herbie-target
  (if (< (* x (- 1.0 (* (- 1.0 y) z))) -1.618195973607049e+50) (+ x (* (- 1.0 y) (* (- z) x))) (if (< (* x (- 1.0 (* (- 1.0 y) z))) 3.892237649663903e+134) (- (* (* x y) z) (- (* x z) x)) (+ x (* (- 1.0 y) (* (- z) x)))))

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