Average Error: 6.1 → 0.5
Time: 14.5s
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 -2 \cdot 10^{+185}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{+272}:\\ \;\;\;\;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 -2e+185) t_2 (if (<= t_1 1e+272) (+ 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 <= -2e+185) {
		tmp = t_2;
	} else if (t_1 <= 1e+272) {
		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 <= -2e+185)
		tmp = t_2;
	elseif (t_1 <= 1e+272)
		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, -2e+185], t$95$2, If[LessEqual[t$95$1, 1e+272], 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 -2 \cdot 10^{+185}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 10^{+272}:\\
\;\;\;\;x + \frac{t_1}{a}\\

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


\end{array}

Error

Target

Original6.1
Target0.7
Herbie0.5
\[\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)) < -2e185 or 1.0000000000000001e272 < (*.f64 y (-.f64 z t))

    1. Initial program 32.7

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

      \[\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, 2 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 y (-.f64 z t)) a)) x): 39 points increase in error, 35 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 -2e185 < (*.f64 y (-.f64 z t)) < 1.0000000000000001e272

    1. Initial program 0.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(z - t\right) \leq -2 \cdot 10^{+185}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z - t}{a}, x\right)\\ \mathbf{elif}\;y \cdot \left(z - t\right) \leq 10^{+272}:\\ \;\;\;\;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
Error2.3
Cost1608
\[\begin{array}{l} t_1 := \frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{if}\;t_1 \leq -4 \cdot 10^{+275}:\\ \;\;\;\;\left(z - t\right) \cdot \frac{y}{a}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+303}:\\ \;\;\;\;x + t_1\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z}{a}\\ \end{array} \]
Alternative 2
Error27.8
Cost1044
\[\begin{array}{l} t_1 := \frac{y}{a} \cdot \left(-t\right)\\ t_2 := z \cdot \frac{y}{a}\\ \mathbf{if}\;x \leq -5.879079768867322 \cdot 10^{-93}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.048676419712637 \cdot 10^{-270}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.0926703519016563 \cdot 10^{-289}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.5438105646444514 \cdot 10^{-207}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.9500516842530273 \cdot 10^{-60}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error28.0
Cost1044
\[\begin{array}{l} t_1 := z \cdot \frac{y}{a}\\ \mathbf{if}\;x \leq -5.879079768867322 \cdot 10^{-93}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.048676419712637 \cdot 10^{-270}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.0926703519016563 \cdot 10^{-289}:\\ \;\;\;\;\frac{y}{a} \cdot \left(-t\right)\\ \mathbf{elif}\;x \leq 5.5438105646444514 \cdot 10^{-207}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.9500516842530273 \cdot 10^{-60}:\\ \;\;\;\;\frac{-y}{\frac{a}{t}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error28.1
Cost1044
\[\begin{array}{l} t_1 := z \cdot \frac{y}{a}\\ \mathbf{if}\;x \leq -5.879079768867322 \cdot 10^{-93}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.048676419712637 \cdot 10^{-270}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.0926703519016563 \cdot 10^{-289}:\\ \;\;\;\;\frac{y}{a} \cdot \left(-t\right)\\ \mathbf{elif}\;x \leq 5.5438105646444514 \cdot 10^{-207}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.9500516842530273 \cdot 10^{-60}:\\ \;\;\;\;\frac{y \cdot \left(-t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error21.5
Cost976
\[\begin{array}{l} t_1 := z \cdot \frac{y}{a}\\ t_2 := x - y \cdot \frac{t}{a}\\ \mathbf{if}\;x \leq -6.735527098115393 \cdot 10^{-110}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.048676419712637 \cdot 10^{-270}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.0926703519016563 \cdot 10^{-289}:\\ \;\;\;\;\frac{y}{a} \cdot \left(-t\right)\\ \mathbf{elif}\;x \leq 5.5438105646444514 \cdot 10^{-207}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error20.6
Cost976
\[\begin{array}{l} t_1 := z \cdot \frac{y}{a}\\ \mathbf{if}\;x \leq -6.735527098115393 \cdot 10^{-110}:\\ \;\;\;\;x - y \cdot \frac{t}{a}\\ \mathbf{elif}\;x \leq -1.048676419712637 \cdot 10^{-270}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.0926703519016563 \cdot 10^{-289}:\\ \;\;\;\;\frac{y}{a} \cdot \left(-t\right)\\ \mathbf{elif}\;x \leq 5.5438105646444514 \cdot 10^{-207}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x - \frac{t}{\frac{a}{y}}\\ \end{array} \]
Alternative 7
Error11.7
Cost976
\[\begin{array}{l} t_1 := x - y \cdot \frac{t}{a}\\ \mathbf{if}\;t \leq -6779177025630763:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.3206117117532275 \cdot 10^{-9}:\\ \;\;\;\;\left(z - t\right) \cdot \frac{y}{a}\\ \mathbf{elif}\;t \leq -5.695107693073861 \cdot 10^{-41}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 3.8457291437549576 \cdot 10^{-12}:\\ \;\;\;\;x + y \cdot \frac{z}{a}\\ \mathbf{else}:\\ \;\;\;\;x - t \cdot \frac{y}{a}\\ \end{array} \]
Alternative 8
Error15.8
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -6.735527098115393 \cdot 10^{-110}:\\ \;\;\;\;x - y \cdot \frac{t}{a}\\ \mathbf{elif}\;x \leq 4.9757664424750855 \cdot 10^{-25}:\\ \;\;\;\;y \cdot \frac{z - t}{a}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{t}{\frac{a}{y}}\\ \end{array} \]
Alternative 9
Error14.8
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -5.879079768867322 \cdot 10^{-93}:\\ \;\;\;\;x - y \cdot \frac{t}{a}\\ \mathbf{elif}\;x \leq 9.015438986797766 \cdot 10^{-17}:\\ \;\;\;\;\left(z - t\right) \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{t}{\frac{a}{y}}\\ \end{array} \]
Alternative 10
Error14.8
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -5.879079768867322 \cdot 10^{-93}:\\ \;\;\;\;x - y \cdot \frac{t}{a}\\ \mathbf{elif}\;x \leq 9.015438986797766 \cdot 10^{-17}:\\ \;\;\;\;\left(z - t\right) \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;x - t \cdot \frac{y}{a}\\ \end{array} \]
Alternative 11
Error28.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -6.735527098115393 \cdot 10^{-110}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.9500516842530273 \cdot 10^{-60}:\\ \;\;\;\;\frac{y}{\frac{a}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error28.4
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -5.879079768867322 \cdot 10^{-93}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 9.015438986797766 \cdot 10^{-17}:\\ \;\;\;\;\frac{y \cdot z}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error27.7
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -5.879079768867322 \cdot 10^{-93}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.9500516842530273 \cdot 10^{-60}:\\ \;\;\;\;\frac{z}{\frac{a}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 14
Error27.7
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -5.879079768867322 \cdot 10^{-93}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.9500516842530273 \cdot 10^{-60}:\\ \;\;\;\;z \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 15
Error31.1
Cost64
\[x \]

Error

Reproduce

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