?

Average Error: 2.3 → 1.5
Time: 1.7min
Precision: binary64
Cost: 7108

?

\[x + \left(y - x\right) \cdot \frac{z}{t} \]
\[\begin{array}{l} \mathbf{if}\;\frac{z}{t} \leq -5 \cdot 10^{+280}:\\ \;\;\;\;\frac{z \cdot \left(y - x\right)}{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 (<= (/ z t) -5e+280) (/ (* z (- 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 ((z / t) <= -5e+280) {
		tmp = (z * (y - x)) / t;
	} else {
		tmp = fma((y - x), (z / t), x);
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y - x) * Float64(z / t)))
end
function code(x, y, z, t)
	tmp = 0.0
	if (Float64(z / t) <= -5e+280)
		tmp = Float64(Float64(z * 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[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[N[(z / t), $MachinePrecision], -5e+280], N[(N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision], N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision] + x), $MachinePrecision]]
x + \left(y - x\right) \cdot \frac{z}{t}
\begin{array}{l}
\mathbf{if}\;\frac{z}{t} \leq -5 \cdot 10^{+280}:\\
\;\;\;\;\frac{z \cdot \left(y - x\right)}{t}\\

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


\end{array}

Error?

Target

Original2.3
Target2.5
Herbie1.5
\[\begin{array}{l} \mathbf{if}\;\left(y - x\right) \cdot \frac{z}{t} < -1013646692435.8867:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{elif}\;\left(y - x\right) \cdot \frac{z}{t} < 0:\\ \;\;\;\;x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if (/.f64 z t) < -5.0000000000000002e280

    1. Initial program 47.3

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)} \]
      Proof
    3. Taylor expanded in z around -inf 0.3

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

    if -5.0000000000000002e280 < (/.f64 z t)

    1. Initial program 1.5

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)} \]
      Proof
  3. Recombined 2 regimes into one program.

Alternatives

Alternative 1
Error21.9
Cost1684
\[\begin{array}{l} t_1 := \frac{-z}{t} \cdot x\\ t_2 := \frac{z}{t} \cdot y\\ \mathbf{if}\;\frac{z}{t} \leq -5 \cdot 10^{+190}:\\ \;\;\;\;\frac{y}{t} \cdot z\\ \mathbf{elif}\;\frac{z}{t} \leq -50000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{z}{t} \leq -5 \cdot 10^{-59}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\frac{z}{t} \leq 5 \cdot 10^{-25}:\\ \;\;\;\;x\\ \mathbf{elif}\;\frac{z}{t} \leq 10^{+151}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error21.7
Cost1684
\[\begin{array}{l} t_1 := \frac{z}{t} \cdot y\\ \mathbf{if}\;\frac{z}{t} \leq -5 \cdot 10^{+190}:\\ \;\;\;\;\frac{y}{t} \cdot z\\ \mathbf{elif}\;\frac{z}{t} \leq -50000000000:\\ \;\;\;\;\frac{-z}{t} \cdot x\\ \mathbf{elif}\;\frac{z}{t} \leq -5 \cdot 10^{-59}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{z}{t} \leq 5 \cdot 10^{-25}:\\ \;\;\;\;x\\ \mathbf{elif}\;\frac{z}{t} \leq 10^{+151}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot z}{-t}\\ \end{array} \]
Alternative 3
Error22.1
Cost1164
\[\begin{array}{l} t_1 := \frac{z}{t} \cdot y\\ \mathbf{if}\;\frac{z}{t} \leq -5 \cdot 10^{-59}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{z}{t} \leq 5 \cdot 10^{-25}:\\ \;\;\;\;x\\ \mathbf{elif}\;\frac{z}{t} \leq 10^{+151}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{-t} \cdot z\\ \end{array} \]
Alternative 4
Error14.9
Cost968
\[\begin{array}{l} t_1 := z \cdot \frac{y - x}{t}\\ \mathbf{if}\;\frac{z}{t} \leq -2 \cdot 10^{-52}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{z}{t} \leq 2 \cdot 10^{-11}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error5.8
Cost968
\[\begin{array}{l} t_1 := z \cdot \frac{y - x}{t}\\ \mathbf{if}\;\frac{z}{t} \leq -200:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{z}{t} \leq 0.002:\\ \;\;\;\;x + \frac{y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error6.1
Cost968
\[\begin{array}{l} \mathbf{if}\;\frac{z}{t} \leq -5 \cdot 10^{+18}:\\ \;\;\;\;\frac{z \cdot \left(y - x\right)}{t}\\ \mathbf{elif}\;\frac{z}{t} \leq 0.002:\\ \;\;\;\;x + \frac{y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{y - x}{t}\\ \end{array} \]
Alternative 7
Error22.4
Cost840
\[\begin{array}{l} t_1 := \frac{z}{t} \cdot y\\ \mathbf{if}\;\frac{z}{t} \leq -5 \cdot 10^{-59}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{z}{t} \leq 5 \cdot 10^{-25}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error1.5
Cost836
\[\begin{array}{l} \mathbf{if}\;\frac{z}{t} \leq -5 \cdot 10^{+280}:\\ \;\;\;\;\frac{z \cdot \left(y - x\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \left(y - x\right) \cdot \frac{z}{t}\\ \end{array} \]
Alternative 9
Error16.1
Cost712
\[\begin{array}{l} t_1 := \frac{t - z}{t} \cdot x\\ \mathbf{if}\;x \leq -8.5 \cdot 10^{-121}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.9 \cdot 10^{-111}:\\ \;\;\;\;z \cdot \frac{y - x}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error26.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -9.8 \cdot 10^{-121}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-121}:\\ \;\;\;\;\frac{y}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error31.8
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023033 
(FPCore (x y z t)
  :name "Graphics.Rendering.Plot.Render.Plot.Axis:tickPosition from plot-0.2.3.4"
  :precision binary64

  :herbie-target
  (if (< (* (- y x) (/ z t)) -1013646692435.8867) (+ x (/ (- y x) (/ t z))) (if (< (* (- y x) (/ z t)) 0.0) (+ x (/ (* (- y x) z) t)) (+ x (/ (- y x) (/ t z)))))

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