Statistics.Math.RootFinding:ridders from math-functions-0.1.5.2

?

Percentage Accurate: 61.8% → 89.7%
Time: 24.5s
Precision: binary64
Cost: 7496

?

\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ \end{array} \]
\[\frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}} \]
\[\begin{array}{l} t_1 := \frac{a}{\frac{z \cdot z}{t}}\\ \mathbf{if}\;z \leq -7.3 \cdot 10^{+87}:\\ \;\;\;\;\frac{x \cdot y}{\mathsf{fma}\left(0.5, t_1, -1\right)}\\ \mathbf{elif}\;z \leq 1.32 \cdot 10^{+31}:\\ \;\;\;\;\frac{x}{\frac{\sqrt{z \cdot z - a \cdot t}}{z \cdot y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y}{1 + t_1 \cdot -0.5}\\ \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (/ (* (* x y) z) (sqrt (- (* z z) (* t a)))))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (/ a (/ (* z z) t))))
   (if (<= z -7.3e+87)
     (/ (* x y) (fma 0.5 t_1 -1.0))
     (if (<= z 1.32e+31)
       (/ x (/ (sqrt (- (* z z) (* a t))) (* z y)))
       (/ (* x y) (+ 1.0 (* t_1 -0.5)))))))
double code(double x, double y, double z, double t, double a) {
	return ((x * y) * z) / sqrt(((z * z) - (t * a)));
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = a / ((z * z) / t);
	double tmp;
	if (z <= -7.3e+87) {
		tmp = (x * y) / fma(0.5, t_1, -1.0);
	} else if (z <= 1.32e+31) {
		tmp = x / (sqrt(((z * z) - (a * t))) / (z * y));
	} else {
		tmp = (x * y) / (1.0 + (t_1 * -0.5));
	}
	return tmp;
}
function code(x, y, z, t, a)
	return Float64(Float64(Float64(x * y) * z) / sqrt(Float64(Float64(z * z) - Float64(t * a))))
end
function code(x, y, z, t, a)
	t_1 = Float64(a / Float64(Float64(z * z) / t))
	tmp = 0.0
	if (z <= -7.3e+87)
		tmp = Float64(Float64(x * y) / fma(0.5, t_1, -1.0));
	elseif (z <= 1.32e+31)
		tmp = Float64(x / Float64(sqrt(Float64(Float64(z * z) - Float64(a * t))) / Float64(z * y)));
	else
		tmp = Float64(Float64(x * y) / Float64(1.0 + Float64(t_1 * -0.5)));
	end
	return tmp
end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] * z), $MachinePrecision] / N[Sqrt[N[(N[(z * z), $MachinePrecision] - N[(t * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(a / N[(N[(z * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -7.3e+87], N[(N[(x * y), $MachinePrecision] / N[(0.5 * t$95$1 + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.32e+31], N[(x / N[(N[Sqrt[N[(N[(z * z), $MachinePrecision] - N[(a * t), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] / N[(1.0 + N[(t$95$1 * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}}
\begin{array}{l}
t_1 := \frac{a}{\frac{z \cdot z}{t}}\\
\mathbf{if}\;z \leq -7.3 \cdot 10^{+87}:\\
\;\;\;\;\frac{x \cdot y}{\mathsf{fma}\left(0.5, t_1, -1\right)}\\

\mathbf{elif}\;z \leq 1.32 \cdot 10^{+31}:\\
\;\;\;\;\frac{x}{\frac{\sqrt{z \cdot z - a \cdot t}}{z \cdot y}}\\

\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{1 + t_1 \cdot -0.5}\\


\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 19 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

Original61.8%
Target88.9%
Herbie89.7%
\[\begin{array}{l} \mathbf{if}\;z < -3.1921305903852764 \cdot 10^{+46}:\\ \;\;\;\;-y \cdot x\\ \mathbf{elif}\;z < 5.976268120920894 \cdot 10^{+90}:\\ \;\;\;\;\frac{x \cdot z}{\frac{\sqrt{z \cdot z - a \cdot t}}{y}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if z < -7.29999999999999997e87

    1. Initial program 22.7%

      \[\frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}} \]
    2. Simplified25.1%

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

      [Start]22.7%

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

      associate-/l* [=>]25.1%

      \[ \color{blue}{\frac{x \cdot y}{\frac{\sqrt{z \cdot z - t \cdot a}}{z}}} \]
    3. Taylor expanded in z around -inf 85.3%

      \[\leadsto \frac{x \cdot y}{\color{blue}{0.5 \cdot \frac{a \cdot t}{{z}^{2}} - 1}} \]
    4. Simplified95.9%

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

      [Start]85.3%

      \[ \frac{x \cdot y}{0.5 \cdot \frac{a \cdot t}{{z}^{2}} - 1} \]

      fma-neg [=>]85.3%

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

      unpow2 [=>]85.3%

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

      associate-/l* [=>]95.9%

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

      metadata-eval [=>]95.9%

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

    if -7.29999999999999997e87 < z < 1.32000000000000011e31

    1. Initial program 82.8%

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

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

      [Start]82.8%

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

      *-commutative [=>]82.8%

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

      associate-*l* [=>]83.1%

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

      associate-*r/ [<=]82.9%

      \[ \color{blue}{y \cdot \frac{x \cdot z}{\sqrt{z \cdot z - t \cdot a}}} \]
    3. Applied egg-rr82.2%

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

      [Start]82.9%

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

      *-commutative [=>]82.9%

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

      associate-/l* [=>]82.2%

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

      associate-/r/ [<=]82.2%

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

      associate-/l/ [=>]82.2%

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

      *-commutative [=>]82.2%

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

    if 1.32000000000000011e31 < z

    1. Initial program 30.0%

      \[\frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}} \]
    2. Simplified32.8%

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

      [Start]30.0%

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

      associate-/l* [=>]32.8%

      \[ \color{blue}{\frac{x \cdot y}{\frac{\sqrt{z \cdot z - t \cdot a}}{z}}} \]
    3. Taylor expanded in z around inf 93.8%

      \[\leadsto \frac{x \cdot y}{\color{blue}{1 + -0.5 \cdot \frac{a \cdot t}{{z}^{2}}}} \]
    4. Simplified97.7%

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

      [Start]93.8%

      \[ \frac{x \cdot y}{1 + -0.5 \cdot \frac{a \cdot t}{{z}^{2}}} \]

      unpow2 [=>]93.8%

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

      associate-/l* [=>]97.7%

      \[ \frac{x \cdot y}{1 + -0.5 \cdot \color{blue}{\frac{a}{\frac{z \cdot z}{t}}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification89.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -7.3 \cdot 10^{+87}:\\ \;\;\;\;\frac{x \cdot y}{\mathsf{fma}\left(0.5, \frac{a}{\frac{z \cdot z}{t}}, -1\right)}\\ \mathbf{elif}\;z \leq 1.32 \cdot 10^{+31}:\\ \;\;\;\;\frac{x}{\frac{\sqrt{z \cdot z - a \cdot t}}{z \cdot y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y}{1 + \frac{a}{\frac{z \cdot z}{t}} \cdot -0.5}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy89.7%
Cost7496
\[\begin{array}{l} t_1 := \frac{a}{\frac{z \cdot z}{t}}\\ \mathbf{if}\;z \leq -7.3 \cdot 10^{+87}:\\ \;\;\;\;\frac{x \cdot y}{\mathsf{fma}\left(0.5, t_1, -1\right)}\\ \mathbf{elif}\;z \leq 1.32 \cdot 10^{+31}:\\ \;\;\;\;\frac{x}{\frac{\sqrt{z \cdot z - a \cdot t}}{z \cdot y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y}{1 + t_1 \cdot -0.5}\\ \end{array} \]
Alternative 2
Accuracy89.5%
Cost7496
\[\begin{array}{l} \mathbf{if}\;z \leq -8.5 \cdot 10^{+112}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq 3 \cdot 10^{+112}:\\ \;\;\;\;y \cdot \frac{z \cdot x}{\sqrt{z \cdot z - a \cdot t}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 3
Accuracy89.8%
Cost7496
\[\begin{array}{l} \mathbf{if}\;z \leq -1.4 \cdot 10^{+92}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{+110}:\\ \;\;\;\;z \cdot \frac{x \cdot y}{\sqrt{z \cdot z - a \cdot t}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 4
Accuracy89.6%
Cost7496
\[\begin{array}{l} \mathbf{if}\;z \leq -8.5 \cdot 10^{+98}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{+31}:\\ \;\;\;\;\frac{x}{\frac{\sqrt{z \cdot z - a \cdot t}}{z \cdot y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y}{1 + \frac{a}{\frac{z \cdot z}{t}} \cdot -0.5}\\ \end{array} \]
Alternative 5
Accuracy82.5%
Cost7304
\[\begin{array}{l} \mathbf{if}\;z \leq -2.5 \cdot 10^{-60}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{-149}:\\ \;\;\;\;y \cdot \frac{z \cdot x}{\sqrt{a \cdot \left(-t\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y}{1 + \frac{a}{\frac{z \cdot z}{t}} \cdot -0.5}\\ \end{array} \]
Alternative 6
Accuracy82.8%
Cost7304
\[\begin{array}{l} \mathbf{if}\;z \leq -3.8 \cdot 10^{-60}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-143}:\\ \;\;\;\;\frac{z \cdot x}{\frac{\sqrt{a \cdot \left(-t\right)}}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y}{1 + \frac{a}{\frac{z \cdot z}{t}} \cdot -0.5}\\ \end{array} \]
Alternative 7
Accuracy82.8%
Cost7304
\[\begin{array}{l} \mathbf{if}\;z \leq -5.4 \cdot 10^{-63}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{-139}:\\ \;\;\;\;\frac{x \cdot \left(z \cdot y\right)}{\sqrt{a \cdot \left(-t\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y}{1 + \frac{a}{\frac{z \cdot z}{t}} \cdot -0.5}\\ \end{array} \]
Alternative 8
Accuracy77.1%
Cost1356
\[\begin{array}{l} t_1 := \frac{a \cdot t}{z}\\ \mathbf{if}\;z \leq -1.3 \cdot 10^{+92}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq -1.25 \cdot 10^{-286}:\\ \;\;\;\;z \cdot \frac{x \cdot y}{0.5 \cdot t_1 - z}\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{+105}:\\ \;\;\;\;\frac{z \cdot \left(x \cdot y\right)}{z + -0.5 \cdot t_1}\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 9
Accuracy76.3%
Cost1224
\[\begin{array}{l} \mathbf{if}\;z \leq -6.3 \cdot 10^{+131}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq -1.25 \cdot 10^{-286}:\\ \;\;\;\;\frac{z \cdot \left(x \cdot y\right)}{0.5 \cdot \frac{a \cdot t}{z} - z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y}{1 + \frac{a \cdot \left(0.5 \cdot \frac{t}{z}\right)}{z}}\\ \end{array} \]
Alternative 10
Accuracy73.3%
Cost1096
\[\begin{array}{l} \mathbf{if}\;z \leq -1.95 \cdot 10^{-286}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{-206}:\\ \;\;\;\;-2 \cdot \left(\frac{y}{a} \cdot \frac{x \cdot \left(z \cdot z\right)}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 11
Accuracy73.7%
Cost1096
\[\begin{array}{l} \mathbf{if}\;z \leq -1.1 \cdot 10^{-277}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq 1.08 \cdot 10^{-181}:\\ \;\;\;\;\frac{z \cdot y}{0.5} \cdot \frac{x}{a \cdot \frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 12
Accuracy73.8%
Cost1096
\[\begin{array}{l} \mathbf{if}\;z \leq -3.2 \cdot 10^{-63}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq 5.6 \cdot 10^{-181}:\\ \;\;\;\;\frac{x \cdot y}{\frac{a \cdot \left(0.5 \cdot \frac{t}{z}\right)}{z}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 13
Accuracy74.7%
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \leq -1.95 \cdot 10^{-286}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y}{1 + \frac{a}{\frac{z \cdot z}{t}} \cdot -0.5}\\ \end{array} \]
Alternative 14
Accuracy74.7%
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \leq -3.6 \cdot 10^{-75}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y}{1 + \frac{a \cdot \left(0.5 \cdot \frac{t}{z}\right)}{z}}\\ \end{array} \]
Alternative 15
Accuracy74.5%
Cost776
\[\begin{array}{l} \mathbf{if}\;z \leq -2.8 \cdot 10^{-29}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq 1.75 \cdot 10^{-213}:\\ \;\;\;\;\frac{x \cdot \left(z \cdot \left(-y\right)\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 16
Accuracy72.2%
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq 2.25 \cdot 10^{-302}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{-149}:\\ \;\;\;\;\frac{z \cdot y}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 17
Accuracy73.6%
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -1.95 \cdot 10^{-286}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq 5.7 \cdot 10^{-83}:\\ \;\;\;\;\frac{z \cdot \left(x \cdot y\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 18
Accuracy71.7%
Cost388
\[\begin{array}{l} \mathbf{if}\;z \leq -1.25 \cdot 10^{-286}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 19
Accuracy42.8%
Cost192
\[x \cdot y \]

Reproduce?

herbie shell --seed 2023272 
(FPCore (x y z t a)
  :name "Statistics.Math.RootFinding:ridders from math-functions-0.1.5.2"
  :precision binary64

  :herbie-target
  (if (< z -3.1921305903852764e+46) (- (* y x)) (if (< z 5.976268120920894e+90) (/ (* x z) (/ (sqrt (- (* z z) (* a t))) y)) (* y x)))

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