Average Error: 6.5 → 1.6
Time: 11.8s
Precision: binary64
Cost: 7112
\[x + \frac{\left(y - x\right) \cdot z}{t} \]
\[\begin{array}{l} \mathbf{if}\;t \leq -7.8 \cdot 10^{+24}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{elif}\;t \leq 9.5 \cdot 10^{-123}:\\ \;\;\;\;x + \frac{\frac{z}{\frac{1}{y - x}}}{t}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* (- y x) z) t)))
(FPCore (x y z t)
 :precision binary64
 (if (<= t -7.8e+24)
   (+ x (/ (- y x) (/ t z)))
   (if (<= t 9.5e-123)
     (+ x (/ (/ z (/ 1.0 (- y x))) t))
     (fma (- y x) (/ z t) x))))
double code(double x, double y, double z, double t) {
	return x + (((y - x) * z) / t);
}
double code(double x, double y, double z, double t) {
	double tmp;
	if (t <= -7.8e+24) {
		tmp = x + ((y - x) / (t / z));
	} else if (t <= 9.5e-123) {
		tmp = x + ((z / (1.0 / (y - x))) / t);
	} else {
		tmp = fma((y - x), (z / t), x);
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(x + Float64(Float64(Float64(y - x) * z) / t))
end
function code(x, y, z, t)
	tmp = 0.0
	if (t <= -7.8e+24)
		tmp = Float64(x + Float64(Float64(y - x) / Float64(t / z)));
	elseif (t <= 9.5e-123)
		tmp = Float64(x + Float64(Float64(z / Float64(1.0 / Float64(y - x))) / t));
	else
		tmp = fma(Float64(y - x), Float64(z / t), x);
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[t, -7.8e+24], N[(x + N[(N[(y - x), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 9.5e-123], N[(x + N[(N[(z / N[(1.0 / N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision] + x), $MachinePrecision]]]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
\mathbf{if}\;t \leq -7.8 \cdot 10^{+24}:\\
\;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\

\mathbf{elif}\;t \leq 9.5 \cdot 10^{-123}:\\
\;\;\;\;x + \frac{\frac{z}{\frac{1}{y - x}}}{t}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\


\end{array}

Error

Target

Original6.5
Target2.0
Herbie1.6
\[\begin{array}{l} \mathbf{if}\;x < -9.025511195533005 \cdot 10^{-135}:\\ \;\;\;\;x - \frac{z}{t} \cdot \left(x - y\right)\\ \mathbf{elif}\;x < 4.275032163700715 \cdot 10^{-250}:\\ \;\;\;\;x + \frac{y - x}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if t < -7.7999999999999995e24

    1. Initial program 10.0

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

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

      [Start]10.0

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

      associate-/l* [=>]1.4

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

    if -7.7999999999999995e24 < t < 9.5000000000000002e-123

    1. Initial program 2.2

      \[x + \frac{\left(y - x\right) \cdot z}{t} \]
    2. Applied egg-rr2.2

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

    if 9.5000000000000002e-123 < t

    1. Initial program 7.3

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

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

      [Start]7.3

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

      +-commutative [=>]7.3

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

      associate-*r/ [<=]1.2

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

      fma-def [=>]1.2

      \[ \color{blue}{\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.6

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

Alternatives

Alternative 1
Error0.8
Cost1865
\[\begin{array}{l} t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 2 \cdot 10^{+303}\right):\\ \;\;\;\;x + z \cdot \frac{y - x}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error0.8
Cost1864
\[\begin{array}{l} t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;x + z \cdot \frac{y - x}{t}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+283}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array} \]
Alternative 3
Error29.1
Cost1376
\[\begin{array}{l} t_1 := \frac{-x}{\frac{t}{z}}\\ \mathbf{if}\;x \leq -6.6 \cdot 10^{+111}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.35 \cdot 10^{+35}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -9.5 \cdot 10^{-90}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.25 \cdot 10^{-93}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \mathbf{elif}\;x \leq 6.6 \cdot 10^{-36}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.15 \cdot 10^{+21}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{+75}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.95 \cdot 10^{+96}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error29.1
Cost1376
\[\begin{array}{l} \mathbf{if}\;x \leq -4.2 \cdot 10^{+111}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.8 \cdot 10^{+35}:\\ \;\;\;\;\frac{-x}{\frac{t}{z}}\\ \mathbf{elif}\;x \leq -1.3 \cdot 10^{-89}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6 \cdot 10^{-88}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-33}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{+19}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;x \leq 2.35 \cdot 10^{+79}:\\ \;\;\;\;\frac{x \cdot \left(-z\right)}{t}\\ \mathbf{elif}\;x \leq 2.95 \cdot 10^{+96}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error29.1
Cost1376
\[\begin{array}{l} \mathbf{if}\;x \leq -4.2 \cdot 10^{+111}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.45 \cdot 10^{+35}:\\ \;\;\;\;\frac{-x}{\frac{t}{z}}\\ \mathbf{elif}\;x \leq -1.15 \cdot 10^{-89}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{-93}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{-35}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{+20}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;x \leq 1.05 \cdot 10^{+76}:\\ \;\;\;\;\frac{z}{t} \cdot \left(-x\right)\\ \mathbf{elif}\;x \leq 2.95 \cdot 10^{+96}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error17.9
Cost977
\[\begin{array}{l} t_1 := x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{if}\;x \leq -8.6 \cdot 10^{-90}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-235}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \mathbf{elif}\;x \leq 2.15 \cdot 10^{-220} \lor \neg \left(x \leq 2.7 \cdot 10^{-93}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \end{array} \]
Alternative 7
Error18.8
Cost976
\[\begin{array}{l} t_1 := x \cdot \left(1 - \frac{z}{t}\right)\\ t_2 := z \cdot \frac{y - x}{t}\\ \mathbf{if}\;z \leq -4.3 \cdot 10^{-8}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 5.4 \cdot 10^{-104}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{-88}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{+14}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 8
Error29.2
Cost850
\[\begin{array}{l} \mathbf{if}\;z \leq -4 \cdot 10^{-14} \lor \neg \left(z \leq 5.4 \cdot 10^{-104} \lor \neg \left(z \leq 3.1 \cdot 10^{-86}\right) \land z \leq 31000000000000\right):\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error29.0
Cost849
\[\begin{array}{l} \mathbf{if}\;z \leq -2.65 \cdot 10^{-14}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{-106}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 10^{-84} \lor \neg \left(z \leq 3.35 \cdot 10^{+16}\right):\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error29.0
Cost848
\[\begin{array}{l} \mathbf{if}\;z \leq -9 \cdot 10^{-14}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-104}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{-88}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{elif}\;z \leq 3.3 \cdot 10^{+15}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 11
Error4.1
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -4.6 \cdot 10^{-148} \lor \neg \left(z \leq 2 \cdot 10^{-51}\right):\\ \;\;\;\;x + z \cdot \frac{y - x}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y \cdot z}{t}\\ \end{array} \]
Alternative 12
Error9.1
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -9.6 \cdot 10^{+34} \lor \neg \left(x \leq 3.7 \cdot 10^{+19}\right):\\ \;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 13
Error9.1
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -2.1 \cdot 10^{+35}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{+20}:\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x - x \cdot \frac{z}{t}\\ \end{array} \]
Alternative 14
Error31.9
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2023012 
(FPCore (x y z t)
  :name "Numeric.Histogram:binBounds from Chart-1.5.3"
  :precision binary64

  :herbie-target
  (if (< x -9.025511195533005e-135) (- x (* (/ z t) (- x y))) (if (< x 4.275032163700715e-250) (+ x (* (/ (- y x) t) z)) (+ x (/ (- y x) (/ t z)))))

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