VandenBroeck and Keller, Equation (6)

?

Percentage Accurate: 76.6% → 99.2%
Time: 16.4s
Precision: binary64
Cost: 32969

?

\[\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^{+18} \lor \neg \left(\pi \cdot \ell \leq 1000000000000\right):\\ \;\;\;\;\pi \cdot \ell\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot \ell - \frac{\frac{\tan \left(\pi \cdot \ell\right)}{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+18) (not (<= (* PI l) 1000000000000.0)))
   (* PI l)
   (- (* PI l) (/ (/ (tan (* PI l)) 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+18) || !((((double) M_PI) * l) <= 1000000000000.0)) {
		tmp = ((double) M_PI) * l;
	} else {
		tmp = (((double) M_PI) * l) - ((tan((((double) M_PI) * l)) / 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+18) || !((Math.PI * l) <= 1000000000000.0)) {
		tmp = Math.PI * l;
	} else {
		tmp = (Math.PI * l) - ((Math.tan((Math.PI * l)) / 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+18) or not ((math.pi * l) <= 1000000000000.0):
		tmp = math.pi * l
	else:
		tmp = (math.pi * l) - ((math.tan((math.pi * l)) / 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+18) || !(Float64(pi * l) <= 1000000000000.0))
		tmp = Float64(pi * l);
	else
		tmp = Float64(Float64(pi * l) - Float64(Float64(tan(Float64(pi * l)) / 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+18) || ~(((pi * l) <= 1000000000000.0)))
		tmp = pi * l;
	else
		tmp = (pi * l) - ((tan((pi * l)) / 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+18], N[Not[LessEqual[N[(Pi * l), $MachinePrecision], 1000000000000.0]], $MachinePrecision]], N[(Pi * l), $MachinePrecision], N[(N[(Pi * l), $MachinePrecision] - N[(N[(N[Tan[N[(Pi * l), $MachinePrecision]], $MachinePrecision] / F), $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^{+18} \lor \neg \left(\pi \cdot \ell \leq 1000000000000\right):\\
\;\;\;\;\pi \cdot \ell\\

\mathbf{else}:\\
\;\;\;\;\pi \cdot \ell - \frac{\frac{\tan \left(\pi \cdot \ell\right)}{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.

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) < -5e18 or 1e12 < (*.f64 (PI.f64) l)

    1. Initial program 68.2%

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

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

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

      [Start]52.8

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

      associate-/l* [=>]52.8

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

      associate-/r/ [=>]52.8

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

      unpow2 [=>]52.8

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

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

    if -5e18 < (*.f64 (PI.f64) l) < 1e12

    1. Initial program 87.8%

      \[\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{\tan \left(\pi \cdot \ell\right)}{F}}{F}} \]
      Step-by-step derivation

      [Start]87.8

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

      associate-*l/ [=>]89.2

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

      *-un-lft-identity [<=]89.2

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

      associate-/r* [=>]99.5

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

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

Alternatives

Alternative 1
Accuracy98.4%
Cost26568
\[\begin{array}{l} \mathbf{if}\;\pi \cdot \ell \leq -0.6:\\ \;\;\;\;1 + \left(\pi \cdot \ell + -1\right)\\ \mathbf{elif}\;\pi \cdot \ell \leq 1000000000000:\\ \;\;\;\;\pi \cdot \ell - \frac{\frac{\pi \cdot \ell}{F}}{F}\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot \ell\\ \end{array} \]
Alternative 2
Accuracy98.4%
Cost13640
\[\begin{array}{l} \mathbf{if}\;\ell \leq -0.28:\\ \;\;\;\;1 + \left(\pi \cdot \ell + -1\right)\\ \mathbf{elif}\;\ell \leq 5 \cdot 10^{+14}:\\ \;\;\;\;\pi \cdot \ell - \frac{\ell \cdot \frac{\pi}{F}}{F}\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot \ell\\ \end{array} \]
Alternative 3
Accuracy74.5%
Cost7640
\[\begin{array}{l} t_0 := 1 + \left(\pi \cdot \ell + -1\right)\\ t_1 := \frac{\ell}{F} \cdot \frac{\pi}{-F}\\ \mathbf{if}\;F \leq -2 \cdot 10^{-138}:\\ \;\;\;\;\pi \cdot \ell\\ \mathbf{elif}\;F \leq -3.5 \cdot 10^{-255}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;F \leq -4.9 \cdot 10^{-290}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;F \leq 1.7 \cdot 10^{-136}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;F \leq 4.1 \cdot 10^{-75}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;F \leq 3.65 \cdot 10^{-9}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot \ell\\ \end{array} \]
Alternative 4
Accuracy74.3%
Cost7640
\[\begin{array}{l} t_0 := 1 + \left(\pi \cdot \ell + -1\right)\\ t_1 := \frac{\ell}{F} \cdot \frac{\pi}{-F}\\ \mathbf{if}\;F \leq -1.9 \cdot 10^{-138}:\\ \;\;\;\;\pi \cdot \ell\\ \mathbf{elif}\;F \leq -6.5 \cdot 10^{-248}:\\ \;\;\;\;\pi \cdot \left(-\frac{\frac{\ell}{F}}{F}\right)\\ \mathbf{elif}\;F \leq -3.05 \cdot 10^{-291}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;F \leq 4.2 \cdot 10^{-137}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;F \leq 4.5 \cdot 10^{-68}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;F \leq 1.02 \cdot 10^{-9}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot \ell\\ \end{array} \]
Alternative 5
Accuracy98.4%
Cost7176
\[\begin{array}{l} \mathbf{if}\;\ell \leq -0.28:\\ \;\;\;\;1 + \left(\pi \cdot \ell + -1\right)\\ \mathbf{elif}\;\ell \leq 5 \cdot 10^{+14}:\\ \;\;\;\;\pi \cdot \left(\ell - \frac{\frac{\ell}{F}}{F}\right)\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot \ell\\ \end{array} \]
Alternative 6
Accuracy73.0%
Cost6528
\[\pi \cdot \ell \]

Error

Reproduce?

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