Average Error: 33.8 → 0.4
Time: 18.8s
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.8
Target0.4
Herbie0.4
\[{\left(\frac{x}{y}\right)}^{2} + {\left(\frac{z}{t}\right)}^{2} \]

Derivation

  1. Initial program 33.8

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

    \[\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)))): 91 points increase in error, 21 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))): 71 points increase in error, 8 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
Error7.5
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^{+221}:\\ \;\;\;\;t_1 + \frac{z \cdot \frac{z}{t}}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{y}}{\frac{y}{x}}\\ \end{array} \]
Alternative 2
Error24.5
Cost1504
\[\begin{array}{l} t_1 := \frac{z}{t} \cdot \frac{z}{t}\\ t_2 := \frac{x}{y \cdot \frac{y}{x}}\\ \mathbf{if}\;y \leq -3.1299268829670175 \cdot 10^{+230}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -7.20890920024799 \cdot 10^{+126}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -3.3 \cdot 10^{+75}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -4.1 \cdot 10^{+33}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -2.1 \cdot 10^{-14}:\\ \;\;\;\;\frac{z \cdot \frac{z}{t}}{t}\\ \mathbf{elif}\;y \leq 9.8 \cdot 10^{-112}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 48000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.798011401203343 \cdot 10^{+100}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error21.9
Cost1504
\[\begin{array}{l} t_1 := \frac{z}{t} \cdot \frac{z}{t}\\ t_2 := \frac{\frac{x}{y}}{\frac{y}{x}}\\ \mathbf{if}\;y \leq -3.1299268829670175 \cdot 10^{+230}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -7.20890920024799 \cdot 10^{+126}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -3.3 \cdot 10^{+75}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -4.1 \cdot 10^{+33}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -2.1 \cdot 10^{-14}:\\ \;\;\;\;\frac{z \cdot \frac{z}{t}}{t}\\ \mathbf{elif}\;y \leq 1.55 \cdot 10^{-85}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 48000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.798011401203343 \cdot 10^{+100}:\\ \;\;\;\;\frac{x}{y \cdot \frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error4.6
Cost1480
\[\begin{array}{l} t_1 := \frac{\frac{z}{t}}{\frac{t}{z}} + x \cdot \frac{1}{\frac{y}{\frac{x}{y}}}\\ \mathbf{if}\;z \leq -4.056651195839092 \cdot 10^{-170}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.721322142395674 \cdot 10^{-234}:\\ \;\;\;\;\frac{x}{\frac{y}{x}} \cdot \frac{1}{y} + \frac{z}{\frac{t}{z}} \cdot \frac{1}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error6.8
Cost1476
\[\begin{array}{l} t_1 := \frac{x \cdot x}{y \cdot y}\\ \mathbf{if}\;t_1 \leq 2 \cdot 10^{+221}:\\ \;\;\;\;\frac{\frac{z}{t}}{\frac{t}{z}} + t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{y}}{\frac{y}{x}}\\ \end{array} \]
Alternative 6
Error2.9
Cost1352
\[\begin{array}{l} t_1 := \frac{\frac{z}{t}}{\frac{t}{z}} + x \cdot \frac{1}{\frac{y}{\frac{x}{y}}}\\ \mathbf{if}\;y \leq -1 \cdot 10^{-230}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 10^{-212}:\\ \;\;\;\;\frac{\frac{x}{y}}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error23.3
Cost1228
\[\begin{array}{l} t_1 := \frac{x \cdot \frac{x}{y}}{y}\\ \mathbf{if}\;z \cdot z \leq 2 \cdot 10^{-287}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot z \leq 2 \cdot 10^{+191}:\\ \;\;\;\;\frac{z \cdot \frac{z}{t}}{t}\\ \mathbf{elif}\;z \cdot z \leq 2 \cdot 10^{+284}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{t} \cdot \frac{z}{t}\\ \end{array} \]
Alternative 8
Error24.4
Cost712
\[\begin{array}{l} t_1 := \frac{z \cdot \frac{z}{t}}{t}\\ \mathbf{if}\;z \leq -4.577703476846155 \cdot 10^{-142}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.466177562187315 \cdot 10^{-129}:\\ \;\;\;\;\frac{x \cdot \frac{x}{y}}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error30.0
Cost448
\[\frac{x \cdot \frac{x}{y}}{y} \]

Error

Reproduce

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