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

\mathbf{elif}\;t_2 \leq 10^{+277}:\\
\;\;\;\;t_2 + x\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Target

Original10.8
Target0.5
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;t < -1.0682974490174067 \cdot 10^{-39}:\\ \;\;\;\;x + \frac{y - z}{a - z} \cdot t\\ \mathbf{elif}\;t < 3.9110949887586375 \cdot 10^{-141}:\\ \;\;\;\;x + \frac{\left(y - z\right) \cdot t}{a - z}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - z}{a - z} \cdot t\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 (-.f64 y z) t) (-.f64 a z)) < -inf.0 or 1e277 < (/.f64 (*.f64 (-.f64 y z) t) (-.f64 a z))

    1. Initial program 61.9

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

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

    if -inf.0 < (/.f64 (*.f64 (-.f64 y z) t) (-.f64 a z)) < 1e277

    1. Initial program 0.2

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

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

Alternatives

Alternative 1
Error0.3
Cost2120
\[\begin{array}{l} t_1 := \frac{\left(y - z\right) \cdot t}{a - z}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;x - t \cdot \frac{z - y}{a - z}\\ \mathbf{elif}\;t_1 \leq 10^{+277}:\\ \;\;\;\;t_1 + x\\ \mathbf{else}:\\ \;\;\;\;x + \left(y - z\right) \cdot \left(t \cdot \frac{1}{a - z}\right)\\ \end{array} \]
Alternative 2
Error0.2
Cost1992
\[\begin{array}{l} t_1 := x - t \cdot \frac{z - y}{a - z}\\ t_2 := \frac{\left(y - z\right) \cdot t}{a - z}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{+304}:\\ \;\;\;\;t_2 + x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error20.7
Cost1504
\[\begin{array}{l} t_1 := x - t \cdot \frac{y}{z}\\ t_2 := x - \frac{z \cdot t}{a}\\ \mathbf{if}\;z \leq -8.559746006100946 \cdot 10^{+21}:\\ \;\;\;\;t + x\\ \mathbf{elif}\;z \leq -9.40764539623202 \cdot 10^{-82}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.0708631452953272 \cdot 10^{-125}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -8.1054294126133 \cdot 10^{-168}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -5.8 \cdot 10^{-196}:\\ \;\;\;\;\frac{y}{\frac{a - z}{t}}\\ \mathbf{elif}\;z \leq 677357.3634670442:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.387512516555814 \cdot 10^{+126}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.8122070596461913 \cdot 10^{+139}:\\ \;\;\;\;x - z \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;t + x\\ \end{array} \]
Alternative 4
Error20.3
Cost1240
\[\begin{array}{l} t_1 := x - t \cdot \frac{y}{z}\\ t_2 := x - \frac{z \cdot t}{a}\\ \mathbf{if}\;z \leq -8.559746006100946 \cdot 10^{+21}:\\ \;\;\;\;t + x\\ \mathbf{elif}\;z \leq -9.40764539623202 \cdot 10^{-82}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.0708631452953272 \cdot 10^{-125}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 677357.3634670442:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.387512516555814 \cdot 10^{+126}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.8122070596461913 \cdot 10^{+139}:\\ \;\;\;\;x - z \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;t + x\\ \end{array} \]
Alternative 5
Error11.5
Cost1236
\[\begin{array}{l} t_1 := x - z \cdot \frac{t}{a - z}\\ t_2 := x + t \cdot \frac{y - z}{a}\\ \mathbf{if}\;a \leq -1.5569026410538364 \cdot 10^{+109}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -118.6588077926554:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -2.0893384732103347 \cdot 10^{-49}:\\ \;\;\;\;x + y \cdot \frac{t}{a}\\ \mathbf{elif}\;a \leq 4.543612885205765 \cdot 10^{-61}:\\ \;\;\;\;x + \frac{z - y}{\frac{z}{t}}\\ \mathbf{elif}\;a \leq 2.5367155722615748 \cdot 10^{+137}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error13.5
Cost1104
\[\begin{array}{l} t_1 := x + \frac{z - y}{\frac{z}{t}}\\ \mathbf{if}\;z \leq -9.796644944149417 \cdot 10^{+20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -9.40764539623202 \cdot 10^{-82}:\\ \;\;\;\;x - \frac{z \cdot t}{a}\\ \mathbf{elif}\;z \leq -1.1586160669273554 \cdot 10^{-91}:\\ \;\;\;\;x - t \cdot \frac{y}{z}\\ \mathbf{elif}\;z \leq 0.0004997994754050088:\\ \;\;\;\;x + y \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error12.1
Cost1104
\[\begin{array}{l} t_1 := x + t \cdot \frac{y - z}{a}\\ t_2 := x + \frac{z - y}{\frac{z}{t}}\\ \mathbf{if}\;z \leq -9.796644944149417 \cdot 10^{+20}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -9.40764539623202 \cdot 10^{-82}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.1586160669273554 \cdot 10^{-91}:\\ \;\;\;\;x - t \cdot \frac{y}{z}\\ \mathbf{elif}\;z \leq 0.0004997994754050088:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 8
Error10.7
Cost1104
\[\begin{array}{l} t_1 := x - t \cdot \frac{z}{a - z}\\ t_2 := x + t \cdot \frac{y - z}{a}\\ \mathbf{if}\;a \leq -2.467697426628604 \cdot 10^{+131}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -3.7888353011347326 \cdot 10^{-91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 4.543612885205765 \cdot 10^{-61}:\\ \;\;\;\;x + \frac{z - y}{\frac{z}{t}}\\ \mathbf{elif}\;a \leq 2.5367155722615748 \cdot 10^{+137}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 9
Error10.7
Cost1104
\[\begin{array}{l} t_1 := x - t \cdot \frac{z}{a - z}\\ t_2 := x + t \cdot \frac{y - z}{a}\\ \mathbf{if}\;a \leq -2.467697426628604 \cdot 10^{+131}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -3.7888353011347326 \cdot 10^{-91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 4.543612885205765 \cdot 10^{-61}:\\ \;\;\;\;x + \frac{t}{z} \cdot \left(z - y\right)\\ \mathbf{elif}\;a \leq 2.5367155722615748 \cdot 10^{+137}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 10
Error19.6
Cost976
\[\begin{array}{l} t_1 := x - \frac{z \cdot t}{a}\\ \mathbf{if}\;z \leq -8.559746006100946 \cdot 10^{+21}:\\ \;\;\;\;t + x\\ \mathbf{elif}\;z \leq -9.40764539623202 \cdot 10^{-82}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.0708631452953272 \cdot 10^{-125}:\\ \;\;\;\;x - t \cdot \frac{y}{z}\\ \mathbf{elif}\;z \leq 0.0004997994754050088:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t + x\\ \end{array} \]
Alternative 11
Error14.1
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -8.559746006100946 \cdot 10^{+21}:\\ \;\;\;\;t + x\\ \mathbf{elif}\;z \leq 0.0004997994754050088:\\ \;\;\;\;x + y \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;t + x\\ \end{array} \]
Alternative 12
Error1.3
Cost704
\[x - t \cdot \frac{z - y}{a - z} \]
Alternative 13
Error19.8
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -2.227533796114572 \cdot 10^{-11}:\\ \;\;\;\;t + x\\ \mathbf{elif}\;z \leq 0.0004997994754050088:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t + x\\ \end{array} \]
Alternative 14
Error26.7
Cost328
\[\begin{array}{l} \mathbf{if}\;t \leq -3.6 \cdot 10^{+137}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq 1.6 \cdot 10^{+180}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
Alternative 15
Error28.7
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022317 
(FPCore (x y z t a)
  :name "Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisTick from plot-0.2.3.4, A"
  :precision binary64

  :herbie-target
  (if (< t -1.0682974490174067e-39) (+ x (* (/ (- y z) (- a z)) t)) (if (< t 3.9110949887586375e-141) (+ x (/ (* (- y z) t) (- a z))) (+ x (* (/ (- y z) (- a z)) t))))

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