Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisLine from plot-0.2.3.4, B

?

Percentage Accurate: 97.6% → 98.6%
Time: 26.3s
Precision: binary64
Cost: 7492

?

\[x + y \cdot \frac{z - t}{a - t} \]
\[\begin{array}{l} t_1 := \frac{z - t}{a - t}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;x + \frac{\left(z - t\right) \cdot y}{a - t}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, t_1, x\right)\\ \end{array} \]
(FPCore (x y z t a) :precision binary64 (+ x (* y (/ (- z t) (- a t)))))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (/ (- z t) (- a t))))
   (if (<= t_1 (- INFINITY)) (+ x (/ (* (- z t) y) (- a t))) (fma y t_1 x))))
double code(double x, double y, double z, double t, double a) {
	return x + (y * ((z - t) / (a - t)));
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = (z - t) / (a - t);
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = x + (((z - t) * y) / (a - t));
	} else {
		tmp = fma(y, t_1, x);
	}
	return tmp;
}
function code(x, y, z, t, a)
	return Float64(x + Float64(y * Float64(Float64(z - t) / Float64(a - t))))
end
function code(x, y, z, t, a)
	t_1 = Float64(Float64(z - t) / Float64(a - t))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(x + Float64(Float64(Float64(z - t) * y) / Float64(a - t)));
	else
		tmp = fma(y, t_1, x);
	end
	return tmp
end
code[x_, y_, z_, t_, a_] := N[(x + N[(y * N[(N[(z - t), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(z - t), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(x + N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * t$95$1 + x), $MachinePrecision]]]
x + y \cdot \frac{z - t}{a - t}
\begin{array}{l}
t_1 := \frac{z - t}{a - t}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;x + \frac{\left(z - t\right) \cdot y}{a - t}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, t_1, x\right)\\


\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 12 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Target

Original97.6%
Target99.1%
Herbie98.6%
\[\begin{array}{l} \mathbf{if}\;y < -8.508084860551241 \cdot 10^{-17}:\\ \;\;\;\;x + y \cdot \frac{z - t}{a - t}\\ \mathbf{elif}\;y < 2.894426862792089 \cdot 10^{-49}:\\ \;\;\;\;x + \left(y \cdot \left(z - t\right)\right) \cdot \frac{1}{a - t}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z - t}{a - t}\\ \end{array} \]

Derivation?

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

    1. Initial program 39.3%

      \[x + y \cdot \frac{z - t}{a - t} \]
    2. Simplified99.9%

      \[\leadsto \color{blue}{x + \frac{y \cdot \left(z - t\right)}{a - t}} \]
      Step-by-step derivation

      [Start]39.3%

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

      associate-*r/ [=>]99.9%

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

    if -inf.0 < (/.f64 (-.f64 z t) (-.f64 a t))

    1. Initial program 99.2%

      \[x + y \cdot \frac{z - t}{a - t} \]
    2. Simplified99.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{z - t}{a - t}, x\right)} \]
      Step-by-step derivation

      [Start]99.2%

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

      +-commutative [=>]99.2%

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

      fma-def [=>]99.2%

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

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

Alternatives

Alternative 1
Accuracy98.6%
Cost7492
\[\begin{array}{l} t_1 := \frac{z - t}{a - t}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;x + \frac{\left(z - t\right) \cdot y}{a - t}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, t_1, x\right)\\ \end{array} \]
Alternative 2
Accuracy97.6%
Cost1220
\[\begin{array}{l} t_1 := \frac{z - t}{a - t}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;x - \frac{z \cdot y}{t}\\ \mathbf{else}:\\ \;\;\;\;x + t_1 \cdot y\\ \end{array} \]
Alternative 3
Accuracy98.6%
Cost1220
\[\begin{array}{l} t_1 := \frac{z - t}{a - t}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;x + \frac{\left(z - t\right) \cdot y}{a - t}\\ \mathbf{else}:\\ \;\;\;\;x + t_1 \cdot y\\ \end{array} \]
Alternative 4
Accuracy76.8%
Cost1040
\[\begin{array}{l} t_1 := x + \frac{y}{\frac{-t}{z}}\\ \mathbf{if}\;t \leq -1.9 \cdot 10^{+136}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;t \leq -6.2 \cdot 10^{-52}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.5 \cdot 10^{-142}:\\ \;\;\;\;x + y \cdot \frac{z}{a}\\ \mathbf{elif}\;t \leq 1.3 \cdot 10^{+52}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 5
Accuracy77.0%
Cost976
\[\begin{array}{l} \mathbf{if}\;t \leq -1.06 \cdot 10^{+136}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;t \leq -4.2 \cdot 10^{-52}:\\ \;\;\;\;x + \frac{y}{\frac{-t}{z}}\\ \mathbf{elif}\;t \leq 2.6 \cdot 10^{-146}:\\ \;\;\;\;x + y \cdot \frac{z}{a}\\ \mathbf{elif}\;t \leq 9.5 \cdot 10^{+59}:\\ \;\;\;\;x - \frac{z \cdot y}{t}\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 6
Accuracy79.5%
Cost844
\[\begin{array}{l} \mathbf{if}\;t \leq -2.9 \cdot 10^{+31}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;t \leq 8 \cdot 10^{-106}:\\ \;\;\;\;x + y \cdot \frac{z - t}{a}\\ \mathbf{elif}\;t \leq 2.9 \cdot 10^{+54}:\\ \;\;\;\;x - \frac{z \cdot y}{t}\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 7
Accuracy86.8%
Cost841
\[\begin{array}{l} \mathbf{if}\;t \leq -1.15 \cdot 10^{+136} \lor \neg \left(t \leq 7.2 \cdot 10^{+53}\right):\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{\frac{a - t}{z}}\\ \end{array} \]
Alternative 8
Accuracy88.0%
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -3.7 \cdot 10^{-117} \lor \neg \left(z \leq 1.5 \cdot 10^{-32}\right):\\ \;\;\;\;x + \frac{y}{\frac{a - t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{y}{\frac{a}{t} + -1}\\ \end{array} \]
Alternative 9
Accuracy78.8%
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -2.9 \cdot 10^{+31}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;t \leq 3.1 \cdot 10^{+14}:\\ \;\;\;\;x + y \cdot \frac{z}{a}\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 10
Accuracy78.8%
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -2.9 \cdot 10^{+31}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;t \leq 5 \cdot 10^{+14}:\\ \;\;\;\;x + z \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 11
Accuracy62.6%
Cost456
\[\begin{array}{l} \mathbf{if}\;a \leq -2.5 \cdot 10^{+63}:\\ \;\;\;\;x\\ \mathbf{elif}\;a \leq 9.2 \cdot 10^{-11}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Accuracy49.4%
Cost64
\[x \]

Reproduce?

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

  :herbie-target
  (if (< y -8.508084860551241e-17) (+ x (* y (/ (- z t) (- a t)))) (if (< y 2.894426862792089e-49) (+ x (* (* y (- z t)) (/ 1.0 (- a t)))) (+ x (* y (/ (- z t) (- a t))))))

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