Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, A

?

Percentage Accurate: 89.0% → 98.6%
Time: 16.6s
Precision: binary64
Cost: 8964

?

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

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


\end{array}

Local Percentage Accuracy?

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 13 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each of Herbie's proposed alternatives. Up and to the right is better. Each dot represents an alternative program; the red square represents the initial program.

Bogosity?

Bogosity

Target

Original89.0%
Target99.4%
Herbie98.6%
\[\frac{x + \left(\frac{y}{t - \frac{x}{z}} - \frac{x}{t \cdot z - x}\right)}{x + 1} \]

Derivation?

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

    1. Initial program 91.8%

      \[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
    2. Simplified91.8%

      \[\leadsto \color{blue}{\frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1}} \]
      Step-by-step derivation

      [Start]91.8

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

      *-commutative [=>]91.8

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

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

      [Start]91.8

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

      div-sub [=>]91.8

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

      *-un-lft-identity [=>]91.8

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

      times-frac [=>]98.7

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

      fma-neg [=>]98.7

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

    if +inf.0 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x 1))

    1. Initial program 0.0%

      \[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
    2. Simplified0.0%

      \[\leadsto \color{blue}{\frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1}} \]
      Step-by-step derivation

      [Start]0.0

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

      *-commutative [=>]0.0

      \[ \frac{x + \frac{y \cdot z - x}{\color{blue}{z \cdot t} - x}}{x + 1} \]
    3. Taylor expanded in t around inf 100.0%

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

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

Alternatives

Alternative 1
Accuracy94.5%
Cost2628
\[\begin{array}{l} t_1 := \frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1}\\ \mathbf{if}\;t_1 \leq 4 \cdot 10^{+272}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{y}{t \cdot \left(x + 1\right)} + \frac{x}{x + 1}\right) - \frac{x}{\left(z \cdot t\right) \cdot \left(x + 1\right)}\\ \end{array} \]
Alternative 2
Accuracy94.4%
Cost2244
\[\begin{array}{l} t_1 := \frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1}\\ \mathbf{if}\;t_1 \leq 4 \cdot 10^{+272}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \end{array} \]
Alternative 3
Accuracy67.4%
Cost1112
\[\begin{array}{l} \mathbf{if}\;x \leq -1.9 \cdot 10^{-33}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -1.15 \cdot 10^{-93}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{elif}\;x \leq -7.2 \cdot 10^{-98}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-121}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{-119}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{elif}\;x \leq 0.01:\\ \;\;\;\;x - x \cdot x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 4
Accuracy79.8%
Cost1097
\[\begin{array}{l} \mathbf{if}\;t \leq -260000000000 \lor \neg \left(t \leq 5.4 \cdot 10^{-203}\right):\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + \left(1 - \frac{y}{\frac{x}{z}}\right)}{x + 1}\\ \end{array} \]
Alternative 5
Accuracy67.5%
Cost981
\[\begin{array}{l} \mathbf{if}\;x \leq -2.4 \cdot 10^{-35}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -9.8 \cdot 10^{-89}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{elif}\;x \leq -5 \cdot 10^{-97}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -5.2 \cdot 10^{-120} \lor \neg \left(x \leq 1.35 \cdot 10^{-117}\right):\\ \;\;\;\;\frac{x}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{t}\\ \end{array} \]
Alternative 6
Accuracy79.7%
Cost969
\[\begin{array}{l} \mathbf{if}\;t \leq -8.8 \cdot 10^{-60} \lor \neg \left(t \leq 5.5 \cdot 10^{-196}\right):\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{y}{x} \cdot \frac{z}{x + 1}\\ \end{array} \]
Alternative 7
Accuracy80.0%
Cost969
\[\begin{array}{l} \mathbf{if}\;t \leq -4.5 \cdot 10^{+15} \lor \neg \left(t \leq 5.5 \cdot 10^{-196}\right):\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{\frac{y}{\frac{x}{z}}}{x + 1}\\ \end{array} \]
Alternative 8
Accuracy67.3%
Cost856
\[\begin{array}{l} \mathbf{if}\;x \leq -1.9 \cdot 10^{-35}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -1.65 \cdot 10^{-92}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-99}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -5.2 \cdot 10^{-120}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{-117}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{elif}\;x \leq 0.01:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 9
Accuracy77.4%
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -2.3 \cdot 10^{-32} \lor \neg \left(x \leq 190000\right):\\ \;\;\;\;1 - \frac{y}{x \cdot \frac{x}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \end{array} \]
Alternative 10
Accuracy67.8%
Cost708
\[\begin{array}{l} \mathbf{if}\;x \leq -2.9 \cdot 10^{-33}:\\ \;\;\;\;1 - \frac{y}{x \cdot \frac{x}{z}}\\ \mathbf{elif}\;x \leq 2.15 \cdot 10^{-118}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{x + 1}\\ \end{array} \]
Alternative 11
Accuracy55.4%
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-99}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 0.01:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 12
Accuracy53.4%
Cost64
\[1 \]

Reproduce?

herbie shell --seed 2023163 
(FPCore (x y z t)
  :name "Diagrams.Trail:splitAtParam  from diagrams-lib-1.3.0.3, A"
  :precision binary64

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

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