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

?

Percentage Accurate: 89.1% → 95.6%
Time: 10.5s
Precision: binary64
Cost: 3400

?

\[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
\[\begin{array}{l} \\ \begin{array}{l} t_1 := x + \frac{y}{t}\\ t_2 := \frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1}\\ \mathbf{if}\;t_2 \leq -5 \cdot 10^{+223}:\\ \;\;\;\;\frac{t_1}{x + 1}\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{+292}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1 - \frac{x}{z \cdot t}}{x + 1}\\ \end{array} \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 (+ x (/ y t)))
        (t_2 (/ (+ x (/ (- (* y z) x) (- (* z t) x))) (+ x 1.0))))
   (if (<= t_2 -5e+223)
     (/ t_1 (+ x 1.0))
     (if (<= t_2 2e+292) t_2 (/ (- t_1 (/ 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 = x + (y / t);
	double t_2 = (x + (((y * z) - x) / ((z * t) - x))) / (x + 1.0);
	double tmp;
	if (t_2 <= -5e+223) {
		tmp = t_1 / (x + 1.0);
	} else if (t_2 <= 2e+292) {
		tmp = t_2;
	} else {
		tmp = (t_1 - (x / (z * t))) / (x + 1.0);
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (x + (((y * z) - x) / ((t * z) - x))) / (x + 1.0d0)
end function
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = x + (y / t)
    t_2 = (x + (((y * z) - x) / ((z * t) - x))) / (x + 1.0d0)
    if (t_2 <= (-5d+223)) then
        tmp = t_1 / (x + 1.0d0)
    else if (t_2 <= 2d+292) then
        tmp = t_2
    else
        tmp = (t_1 - (x / (z * t))) / (x + 1.0d0)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	return (x + (((y * z) - x) / ((t * z) - x))) / (x + 1.0);
}
public static double code(double x, double y, double z, double t) {
	double t_1 = x + (y / t);
	double t_2 = (x + (((y * z) - x) / ((z * t) - x))) / (x + 1.0);
	double tmp;
	if (t_2 <= -5e+223) {
		tmp = t_1 / (x + 1.0);
	} else if (t_2 <= 2e+292) {
		tmp = t_2;
	} else {
		tmp = (t_1 - (x / (z * t))) / (x + 1.0);
	}
	return tmp;
}
def code(x, y, z, t):
	return (x + (((y * z) - x) / ((t * z) - x))) / (x + 1.0)
def code(x, y, z, t):
	t_1 = x + (y / t)
	t_2 = (x + (((y * z) - x) / ((z * t) - x))) / (x + 1.0)
	tmp = 0
	if t_2 <= -5e+223:
		tmp = t_1 / (x + 1.0)
	elif t_2 <= 2e+292:
		tmp = t_2
	else:
		tmp = (t_1 - (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(x + Float64(y / t))
	t_2 = Float64(Float64(x + Float64(Float64(Float64(y * z) - x) / Float64(Float64(z * t) - x))) / Float64(x + 1.0))
	tmp = 0.0
	if (t_2 <= -5e+223)
		tmp = Float64(t_1 / Float64(x + 1.0));
	elseif (t_2 <= 2e+292)
		tmp = t_2;
	else
		tmp = Float64(Float64(t_1 - Float64(x / Float64(z * t))) / Float64(x + 1.0));
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = (x + (((y * z) - x) / ((t * z) - x))) / (x + 1.0);
end
function tmp_2 = code(x, y, z, t)
	t_1 = x + (y / t);
	t_2 = (x + (((y * z) - x) / ((z * t) - x))) / (x + 1.0);
	tmp = 0.0;
	if (t_2 <= -5e+223)
		tmp = t_1 / (x + 1.0);
	elseif (t_2 <= 2e+292)
		tmp = t_2;
	else
		tmp = (t_1 - (x / (z * t))) / (x + 1.0);
	end
	tmp_2 = 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[(x + N[(y / t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x + N[(N[(N[(y * z), $MachinePrecision] - x), $MachinePrecision] / N[(N[(z * t), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -5e+223], N[(t$95$1 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 2e+292], t$95$2, N[(N[(t$95$1 - N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]]]]
\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1}
\begin{array}{l}

\\
\begin{array}{l}
t_1 := x + \frac{y}{t}\\
t_2 := \frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1}\\
\mathbf{if}\;t_2 \leq -5 \cdot 10^{+223}:\\
\;\;\;\;\frac{t_1}{x + 1}\\

\mathbf{elif}\;t_2 \leq 2 \cdot 10^{+292}:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;\frac{t_1 - \frac{x}{z \cdot t}}{x + 1}\\


\end{array}
\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

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation?

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

    1. Initial program 48.0%

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

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

      [Start]48.0%

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

      *-commutative [=>]48.0%

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

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

    if -4.99999999999999985e223 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x 1)) < 2e292

    1. Initial program 99.8%

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

    if 2e292 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x 1))

    1. Initial program 20.0%

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

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

      [Start]20.0%

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

      *-commutative [=>]20.0%

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

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

      [Start]20.0%

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

      fma-neg [=>]20.0%

      \[ \frac{x + \frac{y \cdot z - x}{\color{blue}{\mathsf{fma}\left(z, t, -x\right)}}}{x + 1} \]
    4. Taylor expanded in t around inf 86.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1} \leq -5 \cdot 10^{+223}:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{elif}\;\frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1} \leq 2 \cdot 10^{+292}:\\ \;\;\;\;\frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x + \frac{y}{t}\right) - \frac{x}{z \cdot t}}{x + 1}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy95.6%
Cost3400
\[\begin{array}{l} t_1 := x + \frac{y}{t}\\ t_2 := \frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1}\\ \mathbf{if}\;t_2 \leq -5 \cdot 10^{+223}:\\ \;\;\;\;\frac{t_1}{x + 1}\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{+292}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1 - \frac{x}{z \cdot t}}{x + 1}\\ \end{array} \]
Alternative 2
Accuracy77.4%
Cost1104
\[\begin{array}{l} t_1 := \frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{if}\;x \leq -15000000:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -7.6 \cdot 10^{-93}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.25 \cdot 10^{-108}:\\ \;\;\;\;y \cdot z + \left(1 - z \cdot \frac{y}{x}\right)\\ \mathbf{elif}\;x \leq 0.00086:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{y}{\frac{x \cdot x}{z}}\\ \end{array} \]
Alternative 3
Accuracy67.1%
Cost976
\[\begin{array}{l} \mathbf{if}\;x \leq -1.7 \cdot 10^{-71}:\\ \;\;\;\;\frac{x}{x + 1}\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{-186}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-82}:\\ \;\;\;\;x \cdot \left(1 + \frac{-1}{z \cdot t}\right)\\ \mathbf{elif}\;x \leq 1.15 \cdot 10^{-27}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x + 1}{x}}\\ \end{array} \]
Alternative 4
Accuracy82.3%
Cost969
\[\begin{array}{l} \mathbf{if}\;t \leq -0.225 \lor \neg \left(t \leq 4.8 \cdot 10^{-107}\right):\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{z}{x} \cdot \frac{y}{x + 1}\\ \end{array} \]
Alternative 5
Accuracy63.2%
Cost841
\[\begin{array}{l} \mathbf{if}\;t \leq -10 \lor \neg \left(t \leq 7.8 \cdot 10^{+43}\right):\\ \;\;\;\;\frac{x}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{z}{x} \cdot \frac{y}{x}\\ \end{array} \]
Alternative 6
Accuracy77.6%
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -230000000:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 8 \cdot 10^{-5}:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{z}{x} \cdot \frac{y}{x}\\ \end{array} \]
Alternative 7
Accuracy77.6%
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -255000000:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-6}:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{y}{\frac{x \cdot x}{z}}\\ \end{array} \]
Alternative 8
Accuracy67.9%
Cost716
\[\begin{array}{l} \mathbf{if}\;x \leq -4.6 \cdot 10^{-52}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 7.8 \cdot 10^{-128}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{-6}:\\ \;\;\;\;x - x \cdot x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 9
Accuracy67.9%
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -1.85 \cdot 10^{-73}:\\ \;\;\;\;\frac{x}{x + 1}\\ \mathbf{elif}\;x \leq 7.8 \cdot 10^{-128}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x + 1}{x}}\\ \end{array} \]
Alternative 10
Accuracy67.8%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -2.3 \cdot 10^{-74} \lor \neg \left(x \leq 4.7 \cdot 10^{-127}\right):\\ \;\;\;\;\frac{x}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{t}\\ \end{array} \]
Alternative 11
Accuracy67.7%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -5.1 \cdot 10^{-51}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2.05 \cdot 10^{-126}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 12
Accuracy53.0%
Cost64
\[1 \]

Reproduce?

herbie shell --seed 2023167 
(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)))