?

Average Accuracy: 90.3% → 96.7%
Time: 12.7s
Precision: binary64
Cost: 7112

?

\[x + \frac{y \cdot \left(z - x\right)}{t} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-213}:\\ \;\;\;\;x + \frac{z - x}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{-115}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(z - x\right) \cdot \frac{y}{t}\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
(FPCore (x y z t)
 :precision binary64
 (if (<= x -1e-213)
   (+ x (/ (- z x) (/ t y)))
   (if (<= x 2.1e-115) (fma y (/ (- z x) t) x) (+ x (* (- z x) (/ y t))))))
double code(double x, double y, double z, double t) {
	return x + ((y * (z - x)) / t);
}
double code(double x, double y, double z, double t) {
	double tmp;
	if (x <= -1e-213) {
		tmp = x + ((z - x) / (t / y));
	} else if (x <= 2.1e-115) {
		tmp = fma(y, ((z - x) / t), x);
	} else {
		tmp = x + ((z - x) * (y / t));
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y * Float64(z - x)) / t))
end
function code(x, y, z, t)
	tmp = 0.0
	if (x <= -1e-213)
		tmp = Float64(x + Float64(Float64(z - x) / Float64(t / y)));
	elseif (x <= 2.1e-115)
		tmp = fma(y, Float64(Float64(z - x) / t), x);
	else
		tmp = Float64(x + Float64(Float64(z - x) * Float64(y / t)));
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[x, -1e-213], N[(x + N[(N[(z - x), $MachinePrecision] / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.1e-115], N[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision] + x), $MachinePrecision], N[(x + N[(N[(z - x), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
x + \frac{y \cdot \left(z - x\right)}{t}
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-213}:\\
\;\;\;\;x + \frac{z - x}{\frac{t}{y}}\\

\mathbf{elif}\;x \leq 2.1 \cdot 10^{-115}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\

\mathbf{else}:\\
\;\;\;\;x + \left(z - x\right) \cdot \frac{y}{t}\\


\end{array}

Error?

Target

Original90.3%
Target97.0%
Herbie96.7%
\[x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right) \]

Derivation?

  1. Split input into 3 regimes
  2. if x < -9.9999999999999995e-214

    1. Initial program 90.2%

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Simplified98.1%

      \[\leadsto \color{blue}{x + \frac{y}{t} \cdot \left(z - x\right)} \]
      Proof

      [Start]90.2

      \[ x + \frac{y \cdot \left(z - x\right)}{t} \]

      associate-*l/ [<=]98.1

      \[ x + \color{blue}{\frac{y}{t} \cdot \left(z - x\right)} \]
    3. Applied egg-rr98.1%

      \[\leadsto x + \color{blue}{\frac{z - x}{\frac{t}{y}}} \]
      Proof

      [Start]98.1

      \[ x + \frac{y}{t} \cdot \left(z - x\right) \]

      clear-num [=>]98.0

      \[ x + \color{blue}{\frac{1}{\frac{t}{y}}} \cdot \left(z - x\right) \]

      associate-*l/ [=>]98.1

      \[ x + \color{blue}{\frac{1 \cdot \left(z - x\right)}{\frac{t}{y}}} \]

      *-un-lft-identity [<=]98.1

      \[ x + \frac{\color{blue}{z - x}}{\frac{t}{y}} \]

    if -9.9999999999999995e-214 < x < 2.10000000000000002e-115

    1. Initial program 91.9%

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Simplified91.3%

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

      [Start]91.9

      \[ x + \frac{y \cdot \left(z - x\right)}{t} \]

      +-commutative [=>]91.9

      \[ \color{blue}{\frac{y \cdot \left(z - x\right)}{t} + x} \]

      associate-*r/ [<=]91.3

      \[ \color{blue}{y \cdot \frac{z - x}{t}} + x \]

      fma-def [=>]91.3

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

    if 2.10000000000000002e-115 < x

    1. Initial program 89.0%

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Simplified99.1%

      \[\leadsto \color{blue}{x + \frac{y}{t} \cdot \left(z - x\right)} \]
      Proof

      [Start]89.0

      \[ x + \frac{y \cdot \left(z - x\right)}{t} \]

      associate-*l/ [<=]99.1

      \[ x + \color{blue}{\frac{y}{t} \cdot \left(z - x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification96.7%

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

Alternatives

Alternative 1
Accuracy98.3%
Cost1864
\[\begin{array}{l} t_1 := x + \frac{\left(z - x\right) \cdot y}{t}\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+297}:\\ \;\;\;\;x + \frac{y}{\frac{t}{z - x}}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+303}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + \left(z - x\right) \cdot \frac{y}{t}\\ \end{array} \]
Alternative 2
Accuracy58.1%
Cost1770
\[\begin{array}{l} t_1 := y \cdot \frac{z - x}{t}\\ \mathbf{if}\;t \leq -2.8 \cdot 10^{+101}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -5.25 \cdot 10^{-17}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.8 \cdot 10^{-59}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 2.2 \cdot 10^{-300}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.6 \cdot 10^{-235}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;t \leq 4 \cdot 10^{-106} \lor \neg \left(t \leq 3.05 \cdot 10^{-43}\right) \land \left(t \leq 2.9 \cdot 10^{+36} \lor \neg \left(t \leq 2.9 \cdot 10^{+76}\right) \land t \leq 8.2 \cdot 10^{+139}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Accuracy82.2%
Cost1240
\[\begin{array}{l} t_1 := x + z \cdot \frac{y}{t}\\ t_2 := \frac{\left(z - x\right) \cdot y}{t}\\ t_3 := x \cdot \left(1 - \frac{y}{t}\right)\\ \mathbf{if}\;x \leq -2.6 \cdot 10^{+20}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.65 \cdot 10^{-136}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.16 \cdot 10^{-229}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -3.6 \cdot 10^{-269}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.1 \cdot 10^{-264}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{+76}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 4
Accuracy53.7%
Cost1112
\[\begin{array}{l} \mathbf{if}\;t \leq -7.8 \cdot 10^{+76}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -6 \cdot 10^{-16}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{elif}\;t \leq -2.1 \cdot 10^{-65}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -7 \cdot 10^{-130}:\\ \;\;\;\;\frac{-y}{\frac{t}{x}}\\ \mathbf{elif}\;t \leq -4.3 \cdot 10^{-152}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 3.15 \cdot 10^{-77}:\\ \;\;\;\;\frac{z \cdot y}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Accuracy74.4%
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -5.4 \cdot 10^{-107} \lor \neg \left(x \leq 2.6 \cdot 10^{-56}\right):\\ \;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{z - x}{t}\\ \end{array} \]
Alternative 6
Accuracy87.6%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -3.8 \cdot 10^{-129} \lor \neg \left(z \leq 4 \cdot 10^{-140}\right):\\ \;\;\;\;x + z \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\ \end{array} \]
Alternative 7
Accuracy87.7%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -5.1 \cdot 10^{-127} \lor \neg \left(z \leq 4.8 \cdot 10^{-139}\right):\\ \;\;\;\;x + z \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;x - x \cdot \frac{y}{t}\\ \end{array} \]
Alternative 8
Accuracy58.7%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -7.5 \cdot 10^{-107}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{-56}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Accuracy59.6%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -4.7 \cdot 10^{-106}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{-56}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Accuracy59.6%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -4.1 \cdot 10^{-106}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{-56}:\\ \;\;\;\;\frac{z}{\frac{t}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Accuracy58.7%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.65 \cdot 10^{-106}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4 \cdot 10^{-56}:\\ \;\;\;\;\frac{z \cdot y}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Accuracy97.0%
Cost576
\[x + \left(z - x\right) \cdot \frac{y}{t} \]
Alternative 13
Accuracy50.9%
Cost64
\[x \]

Error

Reproduce?

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

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

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