Data.HashTable.ST.Basic:computeOverhead from hashtables-1.2.0.2

?

Percentage Accurate: 86.2% → 99.6%
Time: 15.2s
Precision: binary64
Cost: 1988

?

\[\frac{x}{y} + \frac{2 + \left(z \cdot 2\right) \cdot \left(1 - t\right)}{t \cdot z} \]
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} + \frac{2 + \left(2 \cdot z\right) \cdot \left(1 - t\right)}{z \cdot t} \leq \infty:\\ \;\;\;\;\frac{x}{y} + \left(-2 + \frac{2 + \frac{2}{z}}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} - 2\\ \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (+ (/ x y) (/ (+ 2.0 (* (* z 2.0) (- 1.0 t))) (* t z))))
(FPCore (x y z t)
 :precision binary64
 (if (<= (+ (/ x y) (/ (+ 2.0 (* (* 2.0 z) (- 1.0 t))) (* z t))) INFINITY)
   (+ (/ x y) (+ -2.0 (/ (+ 2.0 (/ 2.0 z)) t)))
   (- (/ x y) 2.0)))
double code(double x, double y, double z, double t) {
	return (x / y) + ((2.0 + ((z * 2.0) * (1.0 - t))) / (t * z));
}
double code(double x, double y, double z, double t) {
	double tmp;
	if (((x / y) + ((2.0 + ((2.0 * z) * (1.0 - t))) / (z * t))) <= ((double) INFINITY)) {
		tmp = (x / y) + (-2.0 + ((2.0 + (2.0 / z)) / t));
	} else {
		tmp = (x / y) - 2.0;
	}
	return tmp;
}
public static double code(double x, double y, double z, double t) {
	return (x / y) + ((2.0 + ((z * 2.0) * (1.0 - t))) / (t * z));
}
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (((x / y) + ((2.0 + ((2.0 * z) * (1.0 - t))) / (z * t))) <= Double.POSITIVE_INFINITY) {
		tmp = (x / y) + (-2.0 + ((2.0 + (2.0 / z)) / t));
	} else {
		tmp = (x / y) - 2.0;
	}
	return tmp;
}
def code(x, y, z, t):
	return (x / y) + ((2.0 + ((z * 2.0) * (1.0 - t))) / (t * z))
def code(x, y, z, t):
	tmp = 0
	if ((x / y) + ((2.0 + ((2.0 * z) * (1.0 - t))) / (z * t))) <= math.inf:
		tmp = (x / y) + (-2.0 + ((2.0 + (2.0 / z)) / t))
	else:
		tmp = (x / y) - 2.0
	return tmp
function code(x, y, z, t)
	return Float64(Float64(x / y) + Float64(Float64(2.0 + Float64(Float64(z * 2.0) * Float64(1.0 - t))) / Float64(t * z)))
end
function code(x, y, z, t)
	tmp = 0.0
	if (Float64(Float64(x / y) + Float64(Float64(2.0 + Float64(Float64(2.0 * z) * Float64(1.0 - t))) / Float64(z * t))) <= Inf)
		tmp = Float64(Float64(x / y) + Float64(-2.0 + Float64(Float64(2.0 + Float64(2.0 / z)) / t)));
	else
		tmp = Float64(Float64(x / y) - 2.0);
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = (x / y) + ((2.0 + ((z * 2.0) * (1.0 - t))) / (t * z));
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (((x / y) + ((2.0 + ((2.0 * z) * (1.0 - t))) / (z * t))) <= Inf)
		tmp = (x / y) + (-2.0 + ((2.0 + (2.0 / z)) / t));
	else
		tmp = (x / y) - 2.0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := N[(N[(x / y), $MachinePrecision] + N[(N[(2.0 + N[(N[(z * 2.0), $MachinePrecision] * N[(1.0 - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(x / y), $MachinePrecision] + N[(N[(2.0 + N[(N[(2.0 * z), $MachinePrecision] * N[(1.0 - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(x / y), $MachinePrecision] + N[(-2.0 + N[(N[(2.0 + N[(2.0 / z), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / y), $MachinePrecision] - 2.0), $MachinePrecision]]
\frac{x}{y} + \frac{2 + \left(z \cdot 2\right) \cdot \left(1 - t\right)}{t \cdot z}
\begin{array}{l}
\mathbf{if}\;\frac{x}{y} + \frac{2 + \left(2 \cdot z\right) \cdot \left(1 - t\right)}{z \cdot t} \leq \infty:\\
\;\;\;\;\frac{x}{y} + \left(-2 + \frac{2 + \frac{2}{z}}{t}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{y} - 2\\


\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

Original86.2%
Target99.3%
Herbie99.6%
\[\frac{\frac{2}{z} + 2}{t} - \left(2 - \frac{x}{y}\right) \]

Derivation?

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

    1. Initial program 99.9%

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

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

      [Start]99.9%

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

      sub-neg [=>]99.9%

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

      distribute-rgt-in [=>]99.9%

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

      *-lft-identity [=>]99.9%

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

      associate-+r+ [=>]99.9%

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

      cancel-sign-sub-inv [<=]99.9%

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

      div-sub [=>]87.0%

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

      associate-*r* [=>]87.0%

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

      associate-*l/ [<=]87.0%

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

      *-inverses [=>]99.9%

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

      metadata-eval [=>]99.9%

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

      sub-neg [=>]99.9%

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

      metadata-eval [=>]99.9%

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

      metadata-eval [<=]99.9%

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

      +-commutative [<=]99.9%

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

      metadata-eval [=>]99.9%

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

      associate-/l/ [<=]99.9%

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

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

    1. Initial program 0.0%

      \[\frac{x}{y} + \frac{2 + \left(z \cdot 2\right) \cdot \left(1 - t\right)}{t \cdot z} \]
    2. Simplified84.6%

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

      [Start]0.0%

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

      sub-neg [=>]0.0%

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

      distribute-rgt-in [=>]0.0%

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

      *-lft-identity [=>]0.0%

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

      associate-+r+ [=>]0.0%

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

      cancel-sign-sub-inv [<=]0.0%

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

      div-sub [=>]0.0%

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

      associate-*r* [=>]0.0%

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

      associate-*l/ [<=]0.0%

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

      *-inverses [=>]84.6%

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

      metadata-eval [=>]84.6%

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

      sub-neg [=>]84.6%

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

      metadata-eval [=>]84.6%

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

      metadata-eval [<=]84.6%

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

      +-commutative [<=]84.6%

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

      metadata-eval [=>]84.6%

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

      associate-/l/ [<=]84.6%

      \[ \frac{x}{y} + \left(-2 + \color{blue}{\frac{\frac{2 + z \cdot 2}{z}}{t}}\right) \]
    3. Taylor expanded in t around inf 97.4%

      \[\leadsto \color{blue}{\frac{x}{y} - 2} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.5%

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

Alternatives

Alternative 1
Accuracy99.6%
Cost1988
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} + \frac{2 + \left(2 \cdot z\right) \cdot \left(1 - t\right)}{z \cdot t} \leq \infty:\\ \;\;\;\;\frac{x}{y} + \left(-2 + \frac{2 + \frac{2}{z}}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} - 2\\ \end{array} \]
Alternative 2
Accuracy88.4%
Cost1225
\[\begin{array}{l} t_1 := \frac{2}{t} - 2\\ \mathbf{if}\;\frac{x}{y} \leq -2.15 \cdot 10^{+98} \lor \neg \left(\frac{x}{y} \leq 2.9 \cdot 10^{+23}\right):\\ \;\;\;\;\frac{x}{y} + t_1\\ \mathbf{else}:\\ \;\;\;\;t_1 + \frac{2}{z \cdot t}\\ \end{array} \]
Alternative 3
Accuracy61.8%
Cost1114
\[\begin{array}{l} t_1 := \frac{x}{y} - 2\\ \mathbf{if}\;z \leq -6 \cdot 10^{+204}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.5 \cdot 10^{+43}:\\ \;\;\;\;-2 + \frac{2}{t}\\ \mathbf{elif}\;z \leq -2.2 \cdot 10^{-113} \lor \neg \left(z \leq 6.2 \cdot 10^{-169}\right) \land \left(z \leq 2.15 \cdot 10^{-92} \lor \neg \left(z \leq 1.6 \cdot 10^{-9}\right)\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{z \cdot t}\\ \end{array} \]
Alternative 4
Accuracy61.7%
Cost1113
\[\begin{array}{l} t_1 := \frac{x}{y} - 2\\ \mathbf{if}\;z \leq -2.7 \cdot 10^{+203}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.32 \cdot 10^{+43}:\\ \;\;\;\;-2 + \frac{2}{t}\\ \mathbf{elif}\;z \leq -3 \cdot 10^{-112}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{-169}:\\ \;\;\;\;\frac{\frac{2}{t}}{z}\\ \mathbf{elif}\;z \leq 1.85 \cdot 10^{-91} \lor \neg \left(z \leq 6.8 \cdot 10^{-9}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{z \cdot t}\\ \end{array} \]
Alternative 5
Accuracy80.5%
Cost1105
\[\begin{array}{l} t_1 := \frac{x}{y} + \left(\frac{2}{t} - 2\right)\\ \mathbf{if}\;z \leq -1.05 \cdot 10^{-111}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{-169}:\\ \;\;\;\;\frac{\frac{2}{t}}{z}\\ \mathbf{elif}\;z \leq 6.1 \cdot 10^{-93} \lor \neg \left(z \leq 6.8 \cdot 10^{-9}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{2 + \frac{2}{z}}{t}\\ \end{array} \]
Alternative 6
Accuracy79.6%
Cost976
\[\begin{array}{l} t_1 := \frac{2 + \frac{2}{z}}{t}\\ t_2 := \frac{x}{y} - 2\\ \mathbf{if}\;t \leq -68000000000000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -2.7 \cdot 10^{-64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -5.1 \cdot 10^{-114}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;t \leq 1.4 \cdot 10^{-12}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Accuracy51.4%
Cost972
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -2.1 \cdot 10^{+89}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq -2.7 \cdot 10^{-30}:\\ \;\;\;\;\frac{2}{t}\\ \mathbf{elif}\;\frac{x}{y} \leq 1.35 \cdot 10^{-14}:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 8
Accuracy85.0%
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -2.4 \cdot 10^{-111} \lor \neg \left(z \leq 5.4 \cdot 10^{-7}\right):\\ \;\;\;\;\frac{x}{y} + \left(\frac{2}{t} - 2\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{\frac{1}{t}}{z} - 2\\ \end{array} \]
Alternative 9
Accuracy64.1%
Cost840
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -1.4 \cdot 10^{+89}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 2.6 \cdot 10^{+27}:\\ \;\;\;\;-2 + \frac{2}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 10
Accuracy64.3%
Cost840
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -1.6 \cdot 10^{+89}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 450:\\ \;\;\;\;-2 + \frac{2}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} - 2\\ \end{array} \]
Alternative 11
Accuracy37.5%
Cost456
\[\begin{array}{l} \mathbf{if}\;t \leq -0.0075:\\ \;\;\;\;-2\\ \mathbf{elif}\;t \leq 1:\\ \;\;\;\;\frac{2}{t}\\ \mathbf{else}:\\ \;\;\;\;-2\\ \end{array} \]
Alternative 12
Accuracy20.1%
Cost64
\[-2 \]

Reproduce?

herbie shell --seed 2023263 
(FPCore (x y z t)
  :name "Data.HashTable.ST.Basic:computeOverhead from hashtables-1.2.0.2"
  :precision binary64

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

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