Average Error: 14.7 → 1.1
Time: 4.8s
Precision: binary64
\[[x, y] = \mathsf{sort}([x, y]) \\]
\[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
\[\begin{array}{l} t_1 := \frac{y}{z} \cdot x\\ t_2 := \frac{y}{\frac{z}{x}}\\ \mathbf{if}\;\frac{y}{z} \leq -1.768045311118471 \cdot 10^{+144}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\frac{y}{z} \leq -1.0602978721814878 \cdot 10^{-215}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{y}{z} \leq 4.435953205233472 \cdot 10^{-95}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\frac{y}{z} \leq 2.6259892455976272 \cdot 10^{+203}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]
x \cdot \frac{\frac{y}{z} \cdot t}{t}
\begin{array}{l}
t_1 := \frac{y}{z} \cdot x\\
t_2 := \frac{y}{\frac{z}{x}}\\
\mathbf{if}\;\frac{y}{z} \leq -1.768045311118471 \cdot 10^{+144}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;\frac{y}{z} \leq -1.0602978721814878 \cdot 10^{-215}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\frac{y}{z} \leq 4.435953205233472 \cdot 10^{-95}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;\frac{y}{z} \leq 2.6259892455976272 \cdot 10^{+203}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z}\\


\end{array}
(FPCore (x y z t) :precision binary64 (* x (/ (* (/ y z) t) t)))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* (/ y z) x)) (t_2 (/ y (/ z x))))
   (if (<= (/ y z) -1.768045311118471e+144)
     t_2
     (if (<= (/ y z) -1.0602978721814878e-215)
       t_1
       (if (<= (/ y z) 4.435953205233472e-95)
         t_2
         (if (<= (/ y z) 2.6259892455976272e+203) t_1 (* y (/ x z))))))))
double code(double x, double y, double z, double t) {
	return x * (((y / z) * t) / t);
}
double code(double x, double y, double z, double t) {
	double t_1 = (y / z) * x;
	double t_2 = y / (z / x);
	double tmp;
	if ((y / z) <= -1.768045311118471e+144) {
		tmp = t_2;
	} else if ((y / z) <= -1.0602978721814878e-215) {
		tmp = t_1;
	} else if ((y / z) <= 4.435953205233472e-95) {
		tmp = t_2;
	} else if ((y / z) <= 2.6259892455976272e+203) {
		tmp = t_1;
	} else {
		tmp = y * (x / z);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original14.7
Target1.5
Herbie1.1
\[\begin{array}{l} \mathbf{if}\;\frac{\frac{y}{z} \cdot t}{t} < -1.20672205123045 \cdot 10^{+245}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;\frac{\frac{y}{z} \cdot t}{t} < -5.907522236933906 \cdot 10^{-275}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{elif}\;\frac{\frac{y}{z} \cdot t}{t} < 5.658954423153415 \cdot 10^{-65}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;\frac{\frac{y}{z} \cdot t}{t} < 2.0087180502407133 \cdot 10^{+217}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 y z) < -1.768045311118471e144 or -1.0602978721814878e-215 < (/.f64 y z) < 4.43595320523347225e-95

    1. Initial program 19.3

      \[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
    2. Simplified10.7

      \[\leadsto \color{blue}{x \cdot \frac{y}{z}} \]
    3. Taylor expanded in x around 0 1.8

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} \]
    4. Applied associate-/l*_binary642.1

      \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} \]

    if -1.768045311118471e144 < (/.f64 y z) < -1.0602978721814878e-215 or 4.43595320523347225e-95 < (/.f64 y z) < 2.62598924559762723e203

    1. Initial program 7.4

      \[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
    2. Simplified0.3

      \[\leadsto \color{blue}{x \cdot \frac{y}{z}} \]

    if 2.62598924559762723e203 < (/.f64 y z)

    1. Initial program 42.6

      \[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
    2. Simplified27.3

      \[\leadsto \color{blue}{x \cdot \frac{y}{z}} \]
    3. Taylor expanded in x around 0 0.8

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} \]
    4. Applied *-un-lft-identity_binary640.8

      \[\leadsto \frac{y \cdot x}{\color{blue}{1 \cdot z}} \]
    5. Applied times-frac_binary640.8

      \[\leadsto \color{blue}{\frac{y}{1} \cdot \frac{x}{z}} \]
    6. Simplified0.8

      \[\leadsto \color{blue}{y} \cdot \frac{x}{z} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{y}{z} \leq -1.768045311118471 \cdot 10^{+144}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;\frac{y}{z} \leq -1.0602978721814878 \cdot 10^{-215}:\\ \;\;\;\;\frac{y}{z} \cdot x\\ \mathbf{elif}\;\frac{y}{z} \leq 4.435953205233472 \cdot 10^{-95}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;\frac{y}{z} \leq 2.6259892455976272 \cdot 10^{+203}:\\ \;\;\;\;\frac{y}{z} \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]

Reproduce

herbie shell --seed 2022125 
(FPCore (x y z t)
  :name "Graphics.Rendering.Chart.Backend.Diagrams:calcFontMetrics from Chart-diagrams-1.5.1, B"
  :precision binary64

  :herbie-target
  (if (< (/ (* (/ y z) t) t) -1.20672205123045e+245) (/ y (/ z x)) (if (< (/ (* (/ y z) t) t) -5.907522236933906e-275) (* x (/ y z)) (if (< (/ (* (/ y z) t) t) 5.658954423153415e-65) (/ y (/ z x)) (if (< (/ (* (/ y z) t) t) 2.0087180502407133e+217) (* x (/ y z)) (/ (* y x) z)))))

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