Average Error: 6.4 → 0.4
Time: 11.2s
Precision: binary64
Cost: 7624
\[x + \frac{y \cdot \left(z - t\right)}{a} \]
\[\begin{array}{l} t_1 := y \cdot \left(z - t\right)\\ t_2 := \mathsf{fma}\left(y, \frac{z - t}{a}, x\right)\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+238}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+276}:\\ \;\;\;\;x + \frac{t_1}{a}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) a)))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (* y (- z t))) (t_2 (fma y (/ (- z t) a) x)))
   (if (<= t_1 -5e+238) t_2 (if (<= t_1 2e+276) (+ x (/ t_1 a)) t_2))))
double code(double x, double y, double z, double t, double a) {
	return x + ((y * (z - t)) / a);
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = y * (z - t);
	double t_2 = fma(y, ((z - t) / a), x);
	double tmp;
	if (t_1 <= -5e+238) {
		tmp = t_2;
	} else if (t_1 <= 2e+276) {
		tmp = x + (t_1 / a);
	} else {
		tmp = t_2;
	}
	return tmp;
}
function code(x, y, z, t, a)
	return Float64(x + Float64(Float64(y * Float64(z - t)) / a))
end
function code(x, y, z, t, a)
	t_1 = Float64(y * Float64(z - t))
	t_2 = fma(y, Float64(Float64(z - t) / a), x)
	tmp = 0.0
	if (t_1 <= -5e+238)
		tmp = t_2;
	elseif (t_1 <= 2e+276)
		tmp = Float64(x + Float64(t_1 / a));
	else
		tmp = t_2;
	end
	return tmp
end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(y * N[(N[(z - t), $MachinePrecision] / a), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+238], t$95$2, If[LessEqual[t$95$1, 2e+276], N[(x + N[(t$95$1 / a), $MachinePrecision]), $MachinePrecision], t$95$2]]]]
x + \frac{y \cdot \left(z - t\right)}{a}
\begin{array}{l}
t_1 := y \cdot \left(z - t\right)\\
t_2 := \mathsf{fma}\left(y, \frac{z - t}{a}, x\right)\\
\mathbf{if}\;t_1 \leq -5 \cdot 10^{+238}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+276}:\\
\;\;\;\;x + \frac{t_1}{a}\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}

Error

Target

Original6.4
Target0.7
Herbie0.4
\[\begin{array}{l} \mathbf{if}\;y < -1.0761266216389975 \cdot 10^{-10}:\\ \;\;\;\;x + \frac{1}{\frac{\frac{a}{z - t}}{y}}\\ \mathbf{elif}\;y < 2.894426862792089 \cdot 10^{-49}:\\ \;\;\;\;x + \frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{\frac{a}{z - t}}\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if (*.f64 y (-.f64 z t)) < -4.99999999999999995e238 or 2.0000000000000001e276 < (*.f64 y (-.f64 z t))

    1. Initial program 42.3

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{z - t}{a}, x\right)} \]
      Proof
      (fma.f64 y (/.f64 (-.f64 z t) a) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (/.f64 (-.f64 z t) a)) x)): 1 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 y (-.f64 z t)) a)) x): 35 points increase in error, 45 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 x (/.f64 (*.f64 y (-.f64 z t)) a))): 0 points increase in error, 0 points decrease in error

    if -4.99999999999999995e238 < (*.f64 y (-.f64 z t)) < 2.0000000000000001e276

    1. Initial program 0.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(z - t\right) \leq -5 \cdot 10^{+238}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z - t}{a}, x\right)\\ \mathbf{elif}\;y \cdot \left(z - t\right) \leq 2 \cdot 10^{+276}:\\ \;\;\;\;x + \frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z - t}{a}, x\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.8
Cost1736
\[\begin{array}{l} t_1 := x + y \cdot \frac{1}{\frac{a}{z - t}}\\ t_2 := \frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{+278}:\\ \;\;\;\;x + t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error2.0
Cost1608
\[\begin{array}{l} t_1 := y \cdot \frac{z - t}{a}\\ t_2 := \frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{+278}:\\ \;\;\;\;x + t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error15.2
Cost1240
\[\begin{array}{l} t_1 := x - t \cdot \frac{y}{a}\\ t_2 := y \cdot \frac{z - t}{a}\\ \mathbf{if}\;x \leq -6.972351419917256 \cdot 10^{+31}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -8.209184303742617 \cdot 10^{-20}:\\ \;\;\;\;x + \frac{y \cdot z}{a}\\ \mathbf{elif}\;x \leq -4.000023177869111 \cdot 10^{-85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.576734043654447 \cdot 10^{-193}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.1820108716512606 \cdot 10^{-81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.964073095505046 \cdot 10^{-22}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error15.4
Cost1240
\[\begin{array}{l} t_1 := x - t \cdot \frac{y}{a}\\ t_2 := y \cdot \frac{z - t}{a}\\ \mathbf{if}\;x \leq -6.972351419917256 \cdot 10^{+31}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -8.209184303742617 \cdot 10^{-20}:\\ \;\;\;\;x + \frac{y \cdot z}{a}\\ \mathbf{elif}\;x \leq -1.5287953406515005 \cdot 10^{-167}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 7.883316662747508 \cdot 10^{-112}:\\ \;\;\;\;\frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{elif}\;x \leq 1.1820108716512606 \cdot 10^{-81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.964073095505046 \cdot 10^{-22}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error17.0
Cost976
\[\begin{array}{l} t_1 := y \cdot \frac{z - t}{a}\\ t_2 := x + \frac{y \cdot z}{a}\\ \mathbf{if}\;x \leq -2.6835423382954547 \cdot 10^{-39}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.704362937307584 \cdot 10^{-171}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.449135792196382 \cdot 10^{-111}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 7.964073095505046 \cdot 10^{-22}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error28.5
Cost848
\[\begin{array}{l} t_1 := \frac{z}{\frac{a}{y}}\\ \mathbf{if}\;x \leq -1.4907642598393738 \cdot 10^{-101}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.616852343531724 \cdot 10^{-268}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.704362937307584 \cdot 10^{-171}:\\ \;\;\;\;\frac{t \cdot \left(-y\right)}{a}\\ \mathbf{elif}\;x \leq 7.964073095505046 \cdot 10^{-22}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error19.7
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -2.7169776021808523 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 7.964073095505046 \cdot 10^{-22}:\\ \;\;\;\;y \cdot \frac{z - t}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error15.9
Cost712
\[\begin{array}{l} t_1 := x + y \cdot \frac{z}{a}\\ \mathbf{if}\;x \leq -2.6835423382954547 \cdot 10^{-39}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.704362937307584 \cdot 10^{-171}:\\ \;\;\;\;y \cdot \frac{z - t}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error28.2
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.4907642598393738 \cdot 10^{-101}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 7.964073095505046 \cdot 10^{-22}:\\ \;\;\;\;\frac{z}{\frac{a}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error30.7
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022291 
(FPCore (x y z t a)
  :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, E"
  :precision binary64

  :herbie-target
  (if (< y -1.0761266216389975e-10) (+ x (/ 1.0 (/ (/ a (- z t)) y))) (if (< y 2.894426862792089e-49) (+ x (/ (* y (- z t)) a)) (+ x (/ y (/ a (- z t))))))

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