Average Error: 33.7 → 5.9
Time: 10.2s
Precision: binary64
\[\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t} \]
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x}{y \cdot y} \leq 1.023725945855721 \cdot 10^{+177}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, \frac{x}{y \cdot y}, {\left(\frac{z}{t}\right)}^{2}\right)}{1}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{y}\right)}^{2}\\ \end{array} \]
\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot x}{y \cdot y} \leq 1.023725945855721 \cdot 10^{+177}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, \frac{x}{y \cdot y}, {\left(\frac{z}{t}\right)}^{2}\right)}{1}\\

\mathbf{else}:\\
\;\;\;\;{\left(\frac{x}{y}\right)}^{2}\\


\end{array}
(FPCore (x y z t)
 :precision binary64
 (+ (/ (* x x) (* y y)) (/ (* z z) (* t t))))
(FPCore (x y z t)
 :precision binary64
 (if (<= (/ (* x x) (* y y)) 1.023725945855721e+177)
   (/ (fma x (/ x (* y y)) (pow (/ z t) 2.0)) 1.0)
   (pow (/ x y) 2.0)))
double code(double x, double y, double z, double t) {
	return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
double code(double x, double y, double z, double t) {
	double tmp;
	if (((x * x) / (y * y)) <= 1.023725945855721e+177) {
		tmp = fma(x, (x / (y * y)), pow((z / t), 2.0)) / 1.0;
	} else {
		tmp = pow((x / y), 2.0);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original33.7
Target0.4
Herbie5.9
\[{\left(\frac{x}{y}\right)}^{2} + {\left(\frac{z}{t}\right)}^{2} \]

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 x x) (*.f64 y y)) < 1.02372594585572098e177

    1. Initial program 23.8

      \[\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t} \]
    2. Simplified22.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{x}{y \cdot y}, \frac{z \cdot z}{t \cdot t}\right)} \]
    3. Applied egg-rr2.4

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, \frac{x}{y \cdot y}, {\left(\frac{z}{t}\right)}^{2}\right)}{1}} \]

    if 1.02372594585572098e177 < (/.f64 (*.f64 x x) (*.f64 y y))

    1. Initial program 56.8

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{x}{y \cdot y}, \frac{z \cdot z}{t \cdot t}\right)} \]
    3. Applied egg-rr38.0

      \[\leadsto \color{blue}{{\left(\sqrt{\mathsf{fma}\left(x, \frac{x}{y \cdot y}, {\left(\frac{z}{t}\right)}^{2}\right)}\right)}^{2}} \]
    4. Taylor expanded in x around inf 14.1

      \[\leadsto {\color{blue}{\left(\frac{x}{y}\right)}}^{2} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification5.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot x}{y \cdot y} \leq 1.023725945855721 \cdot 10^{+177}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, \frac{x}{y \cdot y}, {\left(\frac{z}{t}\right)}^{2}\right)}{1}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{y}\right)}^{2}\\ \end{array} \]

Reproduce

herbie shell --seed 2022127 
(FPCore (x y z t)
  :name "Graphics.Rasterific.Svg.PathConverter:arcToSegments from rasterific-svg-0.2.3.1"
  :precision binary64

  :herbie-target
  (+ (pow (/ x y) 2.0) (pow (/ z t) 2.0))

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