Average Error: 33.7 → 0.4
Time: 21.3s
Precision: binary64
Cost: 7232
\[\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t} \]
\[\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{\frac{z}{t}}{\frac{t}{z}}\right) \]
(FPCore (x y z t)
 :precision binary64
 (+ (/ (* x x) (* y y)) (/ (* z z) (* t t))))
(FPCore (x y z t)
 :precision binary64
 (fma (/ x y) (/ x y) (/ (/ z t) (/ t z))))
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) {
	return fma((x / y), (x / y), ((z / t) / (t / z)));
}
function code(x, y, z, t)
	return Float64(Float64(Float64(x * x) / Float64(y * y)) + Float64(Float64(z * z) / Float64(t * t)))
end
function code(x, y, z, t)
	return fma(Float64(x / y), Float64(x / y), Float64(Float64(z / t) / Float64(t / z)))
end
code[x_, y_, z_, t_] := N[(N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] / N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision] + N[(N[(z / t), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}
\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{\frac{z}{t}}{\frac{t}{z}}\right)

Error

Target

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

Derivation

  1. Initial program 33.7

    \[\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t} \]
  2. Taylor expanded in x around 0 33.7

    \[\leadsto \color{blue}{\frac{{x}^{2}}{{y}^{2}} + \frac{{z}^{2}}{{t}^{2}}} \]
  3. Simplified0.4

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{z}{t} \cdot \frac{z}{t}\right)} \]
    Proof
    (fma.f64 (/.f64 x y) (/.f64 x y) (*.f64 (/.f64 z t) (/.f64 z t))): 0 points increase in error, 0 points decrease in error
    (fma.f64 (/.f64 x y) (/.f64 x y) (Rewrite<= times-frac_binary64 (/.f64 (*.f64 z z) (*.f64 t t)))): 82 points increase in error, 15 points decrease in error
    (fma.f64 (/.f64 x y) (/.f64 x y) (/.f64 (Rewrite<= unpow2_binary64 (pow.f64 z 2)) (*.f64 t t))): 0 points increase in error, 0 points decrease in error
    (fma.f64 (/.f64 x y) (/.f64 x y) (/.f64 (pow.f64 z 2) (Rewrite<= unpow2_binary64 (pow.f64 t 2)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (/.f64 x y) (/.f64 x y)) (/.f64 (pow.f64 z 2) (pow.f64 t 2)))): 1 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= times-frac_binary64 (/.f64 (*.f64 x x) (*.f64 y y))) (/.f64 (pow.f64 z 2) (pow.f64 t 2))): 74 points increase in error, 11 points decrease in error
    (+.f64 (/.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) (*.f64 y y)) (/.f64 (pow.f64 z 2) (pow.f64 t 2))): 0 points increase in error, 0 points decrease in error
    (+.f64 (/.f64 (pow.f64 x 2) (Rewrite<= unpow2_binary64 (pow.f64 y 2))) (/.f64 (pow.f64 z 2) (pow.f64 t 2))): 0 points increase in error, 0 points decrease in error
  4. Applied egg-rr0.4

    \[\leadsto \mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \color{blue}{\frac{\frac{z}{t}}{\frac{t}{z}}}\right) \]
  5. Final simplification0.4

    \[\leadsto \mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, \frac{\frac{z}{t}}{\frac{t}{z}}\right) \]

Alternatives

Alternative 1
Error4.9
Cost2120
\[\begin{array}{l} t_1 := \frac{z \cdot z}{t \cdot t}\\ \mathbf{if}\;t_1 \leq 5 \cdot 10^{+134}:\\ \;\;\;\;\frac{\frac{x}{y}}{\frac{y}{x}} + \frac{\frac{z \cdot z}{t}}{t}\\ \mathbf{elif}\;t_1 \leq \infty:\\ \;\;\;\;\frac{z}{t} \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{y}{x}} \cdot \frac{1}{y} + \frac{\frac{z}{\frac{t}{z}}}{t}\\ \end{array} \]
Alternative 2
Error6.7
Cost1992
\[\begin{array}{l} t_1 := \frac{x \cdot x}{y \cdot y}\\ \mathbf{if}\;t_1 \leq 0:\\ \;\;\;\;\frac{z}{t} \cdot \frac{z}{t}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+263}:\\ \;\;\;\;t_1 + \frac{z \cdot \frac{z}{t}}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{y}}{\frac{y}{x}} + \frac{\frac{z \cdot z}{t}}{t}\\ \end{array} \]
Alternative 3
Error6.4
Cost1732
\[\begin{array}{l} t_1 := \frac{\frac{x}{y}}{\frac{y}{x}} + \frac{\frac{z \cdot z}{t}}{t}\\ t_2 := \frac{t}{z} \cdot \frac{t}{z}\\ t_3 := \frac{x}{\frac{y}{x}}\\ \mathbf{if}\;z \leq -1 \cdot 10^{+150}:\\ \;\;\;\;\frac{y + t_2 \cdot t_3}{y \cdot t_2}\\ \mathbf{elif}\;z \leq 6.958533605066625 \cdot 10^{-240}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.287922602065692 \cdot 10^{-174}:\\ \;\;\;\;t_3 \cdot \frac{1}{y} + \frac{\frac{z}{\frac{t}{z}}}{t}\\ \mathbf{elif}\;z \leq 10^{+150}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x}{y \cdot y} + \frac{z}{t} \cdot \frac{z}{t}\\ \end{array} \]
Alternative 4
Error8.3
Cost1488
\[\begin{array}{l} t_1 := \frac{\frac{x}{y}}{\frac{y}{x}} + \frac{\frac{z \cdot z}{t}}{t}\\ t_2 := \frac{x \cdot x}{y \cdot y} + \frac{z}{t} \cdot \frac{z}{t}\\ \mathbf{if}\;z \leq -1 \cdot 10^{+80}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.427386963685256 \cdot 10^{-237}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.287922602065692 \cdot 10^{-174}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 10^{+150}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error8.0
Cost1224
\[\begin{array}{l} t_1 := \frac{z}{t} \cdot \frac{z}{t}\\ \mathbf{if}\;z \leq -1 \cdot 10^{+81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 10^{+140}:\\ \;\;\;\;\frac{\frac{x}{y}}{\frac{y}{x}} + \frac{\frac{z \cdot z}{t}}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error22.5
Cost976
\[\begin{array}{l} t_1 := \frac{z \cdot \frac{z}{t}}{t}\\ t_2 := \frac{\frac{x}{y}}{\frac{y}{x}}\\ \mathbf{if}\;t \leq -1.446793024792414 \cdot 10^{+108}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 7 \cdot 10^{-233}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.95 \cdot 10^{-106}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.15 \cdot 10^{+39}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error21.2
Cost844
\[\begin{array}{l} t_1 := \frac{\frac{x}{y}}{\frac{y}{x}}\\ \mathbf{if}\;t \leq -1.446793024792414 \cdot 10^{+108}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 10^{-200}:\\ \;\;\;\;\frac{z \cdot \frac{z}{t}}{t}\\ \mathbf{elif}\;t \leq 3.687272057016655 \cdot 10^{+109}:\\ \;\;\;\;\frac{z}{t \cdot \frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error21.2
Cost844
\[\begin{array}{l} \mathbf{if}\;t \leq -1.446793024792414 \cdot 10^{+108}:\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{y}\\ \mathbf{elif}\;t \leq 10^{-200}:\\ \;\;\;\;\frac{z \cdot \frac{z}{t}}{t}\\ \mathbf{elif}\;t \leq 3.687272057016655 \cdot 10^{+109}:\\ \;\;\;\;\frac{z}{t \cdot \frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{y}}{\frac{y}{x}}\\ \end{array} \]
Alternative 9
Error20.1
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -1.9688386529149737 \cdot 10^{+117}:\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{y}\\ \mathbf{elif}\;t \leq 3.687272057016655 \cdot 10^{+109}:\\ \;\;\;\;\frac{z}{t} \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{y}}{\frac{y}{x}}\\ \end{array} \]
Alternative 10
Error26.3
Cost448
\[\frac{\frac{x}{y}}{\frac{y}{x}} \]

Error

Reproduce

herbie shell --seed 2022318 
(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))))