Average Error: 10.2 → 0.3
Time: 2.8s
Precision: binary64
\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
\[\begin{array}{l} t_0 := \frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\\ t_1 := \left(y + 1\right) \cdot \frac{x}{z} - x\\ \mathbf{if}\;t_0 \leq -592411.9347081907:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 5.646592632431666 \cdot 10^{-97}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} + \frac{1}{z}\right) - x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
t_0 := \frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\\
t_1 := \left(y + 1\right) \cdot \frac{x}{z} - x\\
\mathbf{if}\;t_0 \leq -592411.9347081907:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 5.646592632431666 \cdot 10^{-97}:\\
\;\;\;\;x \cdot \left(\frac{y}{z} + \frac{1}{z}\right) - x\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
(FPCore (x y z) :precision binary64 (/ (* x (+ (- y z) 1.0)) z))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (* x (+ (- y z) 1.0)) z)) (t_1 (- (* (+ y 1.0) (/ x z)) x)))
   (if (<= t_0 -592411.9347081907)
     t_1
     (if (<= t_0 5.646592632431666e-97)
       (- (* x (+ (/ y z) (/ 1.0 z))) x)
       t_1))))
double code(double x, double y, double z) {
	return (x * ((y - z) + 1.0)) / z;
}
double code(double x, double y, double z) {
	double t_0 = (x * ((y - z) + 1.0)) / z;
	double t_1 = ((y + 1.0) * (x / z)) - x;
	double tmp;
	if (t_0 <= -592411.9347081907) {
		tmp = t_1;
	} else if (t_0 <= 5.646592632431666e-97) {
		tmp = (x * ((y / z) + (1.0 / z))) - x;
	} else {
		tmp = t_1;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original10.2
Target0.5
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;x < -2.71483106713436 \cdot 10^{-162}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \mathbf{elif}\;x < 3.874108816439546 \cdot 10^{-197}:\\ \;\;\;\;\left(x \cdot \left(\left(y - z\right) + 1\right)\right) \cdot \frac{1}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) < -592411.934708190733 or 5.6465926324316664e-97 < (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z)

    1. Initial program 15.0

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Simplified15.0

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y - z, x\right)}{z}} \]
    3. Taylor expanded in y around 0 5.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{z}, y, \frac{x}{z}\right) - x} \]
    5. Taylor expanded in x around 0 5.1

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

      \[\leadsto \left(\color{blue}{y \cdot \frac{1}{z}} + \frac{1}{z}\right) \cdot x - x \]
    7. Applied distribute-lft1-in_binary645.1

      \[\leadsto \color{blue}{\left(\left(y + 1\right) \cdot \frac{1}{z}\right)} \cdot x - x \]
    8. Applied associate-*l*_binary640.4

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

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

    if -592411.934708190733 < (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) < 5.6465926324316664e-97

    1. Initial program 0.2

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Simplified0.2

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y - z, x\right)}{z}} \]
    3. Taylor expanded in y around 0 0.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{z}, y, \frac{x}{z}\right) - x} \]
    5. Taylor expanded in x around 0 0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \leq -592411.9347081907:\\ \;\;\;\;\left(y + 1\right) \cdot \frac{x}{z} - x\\ \mathbf{elif}\;\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \leq 5.646592632431666 \cdot 10^{-97}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} + \frac{1}{z}\right) - x\\ \mathbf{else}:\\ \;\;\;\;\left(y + 1\right) \cdot \frac{x}{z} - x\\ \end{array} \]

Reproduce

herbie shell --seed 2022125 
(FPCore (x y z)
  :name "Diagrams.TwoD.Segment.Bernstein:evaluateBernstein from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< x -2.71483106713436e-162) (- (* (+ 1.0 y) (/ x z)) x) (if (< x 3.874108816439546e-197) (* (* x (+ (- y z) 1.0)) (/ 1.0 z)) (- (* (+ 1.0 y) (/ x z)) x)))

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