VandenBroeck and Keller, Equation (6)

?

Percentage Accurate: 76.5% → 98.8%
Time: 14.7s
Precision: binary64
Cost: 33097

?

\[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
\[\begin{array}{l} \mathbf{if}\;\pi \cdot \ell \leq -5 \cdot 10^{+16} \lor \neg \left(\pi \cdot \ell \leq 2 \cdot 10^{-5}\right):\\ \;\;\;\;\pi \cdot \ell\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot \ell + \frac{\tan \left(\pi \cdot \ell\right) \cdot \frac{-1}{F}}{F}\\ \end{array} \]
(FPCore (F l)
 :precision binary64
 (- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))
(FPCore (F l)
 :precision binary64
 (if (or (<= (* PI l) -5e+16) (not (<= (* PI l) 2e-5)))
   (* PI l)
   (+ (* PI l) (/ (* (tan (* PI l)) (/ -1.0 F)) F))))
double code(double F, double l) {
	return (((double) M_PI) * l) - ((1.0 / (F * F)) * tan((((double) M_PI) * l)));
}
double code(double F, double l) {
	double tmp;
	if (((((double) M_PI) * l) <= -5e+16) || !((((double) M_PI) * l) <= 2e-5)) {
		tmp = ((double) M_PI) * l;
	} else {
		tmp = (((double) M_PI) * l) + ((tan((((double) M_PI) * l)) * (-1.0 / F)) / F);
	}
	return tmp;
}
public static double code(double F, double l) {
	return (Math.PI * l) - ((1.0 / (F * F)) * Math.tan((Math.PI * l)));
}
public static double code(double F, double l) {
	double tmp;
	if (((Math.PI * l) <= -5e+16) || !((Math.PI * l) <= 2e-5)) {
		tmp = Math.PI * l;
	} else {
		tmp = (Math.PI * l) + ((Math.tan((Math.PI * l)) * (-1.0 / F)) / F);
	}
	return tmp;
}
def code(F, l):
	return (math.pi * l) - ((1.0 / (F * F)) * math.tan((math.pi * l)))
def code(F, l):
	tmp = 0
	if ((math.pi * l) <= -5e+16) or not ((math.pi * l) <= 2e-5):
		tmp = math.pi * l
	else:
		tmp = (math.pi * l) + ((math.tan((math.pi * l)) * (-1.0 / F)) / F)
	return tmp
function code(F, l)
	return Float64(Float64(pi * l) - Float64(Float64(1.0 / Float64(F * F)) * tan(Float64(pi * l))))
end
function code(F, l)
	tmp = 0.0
	if ((Float64(pi * l) <= -5e+16) || !(Float64(pi * l) <= 2e-5))
		tmp = Float64(pi * l);
	else
		tmp = Float64(Float64(pi * l) + Float64(Float64(tan(Float64(pi * l)) * Float64(-1.0 / F)) / F));
	end
	return tmp
end
function tmp = code(F, l)
	tmp = (pi * l) - ((1.0 / (F * F)) * tan((pi * l)));
end
function tmp_2 = code(F, l)
	tmp = 0.0;
	if (((pi * l) <= -5e+16) || ~(((pi * l) <= 2e-5)))
		tmp = pi * l;
	else
		tmp = (pi * l) + ((tan((pi * l)) * (-1.0 / F)) / F);
	end
	tmp_2 = tmp;
end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(N[(1.0 / N[(F * F), $MachinePrecision]), $MachinePrecision] * N[Tan[N[(Pi * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[F_, l_] := If[Or[LessEqual[N[(Pi * l), $MachinePrecision], -5e+16], N[Not[LessEqual[N[(Pi * l), $MachinePrecision], 2e-5]], $MachinePrecision]], N[(Pi * l), $MachinePrecision], N[(N[(Pi * l), $MachinePrecision] + N[(N[(N[Tan[N[(Pi * l), $MachinePrecision]], $MachinePrecision] * N[(-1.0 / F), $MachinePrecision]), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision]]
\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)
\begin{array}{l}
\mathbf{if}\;\pi \cdot \ell \leq -5 \cdot 10^{+16} \lor \neg \left(\pi \cdot \ell \leq 2 \cdot 10^{-5}\right):\\
\;\;\;\;\pi \cdot \ell\\

\mathbf{else}:\\
\;\;\;\;\pi \cdot \ell + \frac{\tan \left(\pi \cdot \ell\right) \cdot \frac{-1}{F}}{F}\\


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

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 2 regimes
  2. if (*.f64 (PI.f64) l) < -5e16 or 2.00000000000000016e-5 < (*.f64 (PI.f64) l)

    1. Initial program 62.0%

      \[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
    2. Taylor expanded in l around 0 48.7%

      \[\leadsto \pi \cdot \ell - \color{blue}{\frac{\ell \cdot \pi}{{F}^{2}}} \]
    3. Simplified48.7%

      \[\leadsto \pi \cdot \ell - \color{blue}{\frac{\ell}{F \cdot F} \cdot \pi} \]
      Step-by-step derivation

      [Start]48.7

      \[ \pi \cdot \ell - \frac{\ell \cdot \pi}{{F}^{2}} \]

      associate-/l* [=>]48.7

      \[ \pi \cdot \ell - \color{blue}{\frac{\ell}{\frac{{F}^{2}}{\pi}}} \]

      associate-/r/ [=>]48.7

      \[ \pi \cdot \ell - \color{blue}{\frac{\ell}{{F}^{2}} \cdot \pi} \]

      unpow2 [=>]48.7

      \[ \pi \cdot \ell - \frac{\ell}{\color{blue}{F \cdot F}} \cdot \pi \]
    4. Taylor expanded in F around inf 99.5%

      \[\leadsto \color{blue}{\ell \cdot \pi} \]

    if -5e16 < (*.f64 (PI.f64) l) < 2.00000000000000016e-5

    1. Initial program 91.1%

      \[\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]
    2. Applied egg-rr99.5%

      \[\leadsto \pi \cdot \ell - \color{blue}{\frac{\frac{1}{F} \cdot \tan \left(\pi \cdot \ell\right)}{F}} \]
      Step-by-step derivation

      [Start]91.1

      \[ \pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \]

      associate-/r* [=>]91.2

      \[ \pi \cdot \ell - \color{blue}{\frac{\frac{1}{F}}{F}} \cdot \tan \left(\pi \cdot \ell\right) \]

      metadata-eval [<=]91.2

      \[ \pi \cdot \ell - \frac{\frac{\color{blue}{\sqrt{1}}}{F}}{F} \cdot \tan \left(\pi \cdot \ell\right) \]

      add-sqr-sqrt [=>]45.9

      \[ \pi \cdot \ell - \frac{\frac{\sqrt{1}}{\color{blue}{\sqrt{F} \cdot \sqrt{F}}}}{F} \cdot \tan \left(\pi \cdot \ell\right) \]

      sqrt-prod [<=]70.1

      \[ \pi \cdot \ell - \frac{\frac{\sqrt{1}}{\color{blue}{\sqrt{F \cdot F}}}}{F} \cdot \tan \left(\pi \cdot \ell\right) \]

      sqrt-div [<=]70.1

      \[ \pi \cdot \ell - \frac{\color{blue}{\sqrt{\frac{1}{F \cdot F}}}}{F} \cdot \tan \left(\pi \cdot \ell\right) \]

      associate-*l/ [=>]70.1

      \[ \pi \cdot \ell - \color{blue}{\frac{\sqrt{\frac{1}{F \cdot F}} \cdot \tan \left(\pi \cdot \ell\right)}{F}} \]

      sqrt-div [=>]70.3

      \[ \pi \cdot \ell - \frac{\color{blue}{\frac{\sqrt{1}}{\sqrt{F \cdot F}}} \cdot \tan \left(\pi \cdot \ell\right)}{F} \]

      metadata-eval [=>]70.3

      \[ \pi \cdot \ell - \frac{\frac{\color{blue}{1}}{\sqrt{F \cdot F}} \cdot \tan \left(\pi \cdot \ell\right)}{F} \]

      sqrt-prod [=>]49.4

      \[ \pi \cdot \ell - \frac{\frac{1}{\color{blue}{\sqrt{F} \cdot \sqrt{F}}} \cdot \tan \left(\pi \cdot \ell\right)}{F} \]

      add-sqr-sqrt [<=]99.5

      \[ \pi \cdot \ell - \frac{\frac{1}{\color{blue}{F}} \cdot \tan \left(\pi \cdot \ell\right)}{F} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\pi \cdot \ell \leq -5 \cdot 10^{+16} \lor \neg \left(\pi \cdot \ell \leq 2 \cdot 10^{-5}\right):\\ \;\;\;\;\pi \cdot \ell\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot \ell + \frac{\tan \left(\pi \cdot \ell\right) \cdot \frac{-1}{F}}{F}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy98.8%
Cost32969
\[\begin{array}{l} \mathbf{if}\;\pi \cdot \ell \leq -5 \cdot 10^{+16} \lor \neg \left(\pi \cdot \ell \leq 2 \cdot 10^{-5}\right):\\ \;\;\;\;\pi \cdot \ell\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot \ell - \frac{\frac{\tan \left(\pi \cdot \ell\right)}{F}}{F}\\ \end{array} \]
Alternative 2
Accuracy98.5%
Cost26569
\[\begin{array}{l} \mathbf{if}\;\pi \cdot \ell \leq -5 \cdot 10^{+16} \lor \neg \left(\pi \cdot \ell \leq 2 \cdot 10^{-5}\right):\\ \;\;\;\;\pi \cdot \ell\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot \ell - \frac{\pi}{F} \cdot \frac{\ell}{F}\\ \end{array} \]
Alternative 3
Accuracy74.1%
Cost7888
\[\begin{array}{l} t_0 := \pi \cdot \frac{-\ell}{F \cdot F}\\ t_1 := 1 + \left(\pi \cdot \ell + -1\right)\\ \mathbf{if}\;F \cdot F \leq 5 \cdot 10^{-318}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;F \cdot F \leq 6.9 \cdot 10^{-216}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;F \cdot F \leq 2.5 \cdot 10^{-184}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;F \cdot F \leq 5.3 \cdot 10^{-126}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot \ell\\ \end{array} \]
Alternative 4
Accuracy74.9%
Cost7378
\[\begin{array}{l} \mathbf{if}\;\ell \leq -4.8 \cdot 10^{-18} \lor \neg \left(\ell \leq -3 \cdot 10^{-162}\right) \land \left(\ell \leq 6.2 \cdot 10^{-217} \lor \neg \left(\ell \leq 0.0065\right)\right):\\ \;\;\;\;\pi \cdot \ell\\ \mathbf{else}:\\ \;\;\;\;\frac{\pi}{F} \cdot \frac{-\ell}{F}\\ \end{array} \]
Alternative 5
Accuracy98.6%
Cost7177
\[\begin{array}{l} \mathbf{if}\;\ell \leq -1450000000000 \lor \neg \left(\ell \leq 115000\right):\\ \;\;\;\;\pi \cdot \ell\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot \left(\ell - \frac{\frac{\ell}{F}}{F}\right)\\ \end{array} \]
Alternative 6
Accuracy74.0%
Cost6528
\[\pi \cdot \ell \]

Reproduce?

herbie shell --seed 2023161 
(FPCore (F l)
  :name "VandenBroeck and Keller, Equation (6)"
  :precision binary64
  (- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))