Diagrams.TwoD.Layout.CirclePacking:approxRadius from diagrams-contrib-1.3.0.5

?

Percentage Accurate: 43.7% → 56.5%
Time: 14.7s
Precision: binary64
Cost: 39876

?

\[\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)} \]
\[\begin{array}{l} t_0 := \frac{x}{y \cdot 2}\\ \mathbf{if}\;\frac{\tan t_0}{\sin t_0} \leq 4.1:\\ \;\;\;\;{\left(\frac{1}{\sqrt[3]{\cos \left(\frac{1}{\frac{2}{\frac{x}{y}}}\right)}}\right)}^{3}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{1}{\mathsf{expm1}\left(\log 2 + {\left(\frac{x}{y}\right)}^{2} \cdot -0.020833333333333332\right)}\right)}^{3}\\ \end{array} \]
(FPCore (x y)
 :precision binary64
 (/ (tan (/ x (* y 2.0))) (sin (/ x (* y 2.0)))))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ x (* y 2.0))))
   (if (<= (/ (tan t_0) (sin t_0)) 4.1)
     (pow (/ 1.0 (cbrt (cos (/ 1.0 (/ 2.0 (/ x y)))))) 3.0)
     (pow
      (/ 1.0 (expm1 (+ (log 2.0) (* (pow (/ x y) 2.0) -0.020833333333333332))))
      3.0))))
double code(double x, double y) {
	return tan((x / (y * 2.0))) / sin((x / (y * 2.0)));
}
double code(double x, double y) {
	double t_0 = x / (y * 2.0);
	double tmp;
	if ((tan(t_0) / sin(t_0)) <= 4.1) {
		tmp = pow((1.0 / cbrt(cos((1.0 / (2.0 / (x / y)))))), 3.0);
	} else {
		tmp = pow((1.0 / expm1((log(2.0) + (pow((x / y), 2.0) * -0.020833333333333332)))), 3.0);
	}
	return tmp;
}
public static double code(double x, double y) {
	return Math.tan((x / (y * 2.0))) / Math.sin((x / (y * 2.0)));
}
public static double code(double x, double y) {
	double t_0 = x / (y * 2.0);
	double tmp;
	if ((Math.tan(t_0) / Math.sin(t_0)) <= 4.1) {
		tmp = Math.pow((1.0 / Math.cbrt(Math.cos((1.0 / (2.0 / (x / y)))))), 3.0);
	} else {
		tmp = Math.pow((1.0 / Math.expm1((Math.log(2.0) + (Math.pow((x / y), 2.0) * -0.020833333333333332)))), 3.0);
	}
	return tmp;
}
function code(x, y)
	return Float64(tan(Float64(x / Float64(y * 2.0))) / sin(Float64(x / Float64(y * 2.0))))
end
function code(x, y)
	t_0 = Float64(x / Float64(y * 2.0))
	tmp = 0.0
	if (Float64(tan(t_0) / sin(t_0)) <= 4.1)
		tmp = Float64(1.0 / cbrt(cos(Float64(1.0 / Float64(2.0 / Float64(x / y)))))) ^ 3.0;
	else
		tmp = Float64(1.0 / expm1(Float64(log(2.0) + Float64((Float64(x / y) ^ 2.0) * -0.020833333333333332)))) ^ 3.0;
	end
	return tmp
end
code[x_, y_] := N[(N[Tan[N[(x / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sin[N[(x / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_, y_] := Block[{t$95$0 = N[(x / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[Tan[t$95$0], $MachinePrecision] / N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 4.1], N[Power[N[(1.0 / N[Power[N[Cos[N[(1.0 / N[(2.0 / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], N[Power[N[(1.0 / N[(Exp[N[(N[Log[2.0], $MachinePrecision] + N[(N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision] * -0.020833333333333332), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision]]]
\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)}
\begin{array}{l}
t_0 := \frac{x}{y \cdot 2}\\
\mathbf{if}\;\frac{\tan t_0}{\sin t_0} \leq 4.1:\\
\;\;\;\;{\left(\frac{1}{\sqrt[3]{\cos \left(\frac{1}{\frac{2}{\frac{x}{y}}}\right)}}\right)}^{3}\\

\mathbf{else}:\\
\;\;\;\;{\left(\frac{1}{\mathsf{expm1}\left(\log 2 + {\left(\frac{x}{y}\right)}^{2} \cdot -0.020833333333333332\right)}\right)}^{3}\\


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

Original43.7%
Target54.7%
Herbie56.5%
\[\begin{array}{l} \mathbf{if}\;y < -1.2303690911306994 \cdot 10^{+114}:\\ \;\;\;\;1\\ \mathbf{elif}\;y < -9.102852406811914 \cdot 10^{-222}:\\ \;\;\;\;\frac{\sin \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right) \cdot \log \left(e^{\cos \left(\frac{x}{y \cdot 2}\right)}\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if (/.f64 (tan.f64 (/.f64 x (*.f64 y 2))) (sin.f64 (/.f64 x (*.f64 y 2)))) < 4.0999999999999996

    1. Initial program 61.5%

      \[\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)} \]
    2. Applied egg-rr61.3%

      \[\leadsto \color{blue}{{\left(\frac{1}{\sqrt[3]{\cos \left(x \cdot \frac{0.5}{y}\right)}}\right)}^{3}} \]
      Step-by-step derivation

      [Start]61.5%

      \[ \frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)} \]

      add-cube-cbrt [=>]61.5%

      \[ \color{blue}{\left(\sqrt[3]{\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)}} \cdot \sqrt[3]{\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)}}\right) \cdot \sqrt[3]{\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)}}} \]

      pow3 [=>]61.5%

      \[ \color{blue}{{\left(\sqrt[3]{\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)}}\right)}^{3}} \]
    3. Applied egg-rr61.9%

      \[\leadsto {\left(\frac{1}{\sqrt[3]{\cos \color{blue}{\left(\frac{1}{\frac{2}{\frac{x}{y}}}\right)}}}\right)}^{3} \]
      Step-by-step derivation

      [Start]61.3%

      \[ {\left(\frac{1}{\sqrt[3]{\cos \left(x \cdot \frac{0.5}{y}\right)}}\right)}^{3} \]

      clear-num [=>]61.3%

      \[ {\left(\frac{1}{\sqrt[3]{\cos \left(x \cdot \color{blue}{\frac{1}{\frac{y}{0.5}}}\right)}}\right)}^{3} \]

      div-inv [=>]61.3%

      \[ {\left(\frac{1}{\sqrt[3]{\cos \left(x \cdot \frac{1}{\color{blue}{y \cdot \frac{1}{0.5}}}\right)}}\right)}^{3} \]

      metadata-eval [=>]61.3%

      \[ {\left(\frac{1}{\sqrt[3]{\cos \left(x \cdot \frac{1}{y \cdot \color{blue}{2}}\right)}}\right)}^{3} \]

      div-inv [<=]61.5%

      \[ {\left(\frac{1}{\sqrt[3]{\cos \color{blue}{\left(\frac{x}{y \cdot 2}\right)}}}\right)}^{3} \]

      associate-/r* [=>]61.5%

      \[ {\left(\frac{1}{\sqrt[3]{\cos \color{blue}{\left(\frac{\frac{x}{y}}{2}\right)}}}\right)}^{3} \]

      clear-num [=>]61.9%

      \[ {\left(\frac{1}{\sqrt[3]{\cos \color{blue}{\left(\frac{1}{\frac{2}{\frac{x}{y}}}\right)}}}\right)}^{3} \]

    if 4.0999999999999996 < (/.f64 (tan.f64 (/.f64 x (*.f64 y 2))) (sin.f64 (/.f64 x (*.f64 y 2))))

    1. Initial program 0.9%

      \[\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)} \]
    2. Applied egg-rr53.4%

      \[\leadsto \color{blue}{{\left(\frac{1}{\sqrt[3]{\cos \left(x \cdot \frac{0.5}{y}\right)}}\right)}^{3}} \]
      Step-by-step derivation

      [Start]0.9%

      \[ \frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)} \]

      add-cube-cbrt [=>]0.9%

      \[ \color{blue}{\left(\sqrt[3]{\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)}} \cdot \sqrt[3]{\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)}}\right) \cdot \sqrt[3]{\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)}}} \]

      pow3 [=>]0.9%

      \[ \color{blue}{{\left(\sqrt[3]{\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)}}\right)}^{3}} \]
    3. Applied egg-rr53.4%

      \[\leadsto {\left(\frac{1}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt[3]{\cos \left(0.5 \cdot \frac{x}{y}\right)}\right)\right)}}\right)}^{3} \]
      Step-by-step derivation

      [Start]53.4%

      \[ {\left(\frac{1}{\sqrt[3]{\cos \left(x \cdot \frac{0.5}{y}\right)}}\right)}^{3} \]

      clear-num [=>]53.4%

      \[ {\left(\frac{1}{\sqrt[3]{\cos \left(x \cdot \color{blue}{\frac{1}{\frac{y}{0.5}}}\right)}}\right)}^{3} \]

      div-inv [=>]53.4%

      \[ {\left(\frac{1}{\sqrt[3]{\cos \left(x \cdot \frac{1}{\color{blue}{y \cdot \frac{1}{0.5}}}\right)}}\right)}^{3} \]

      metadata-eval [=>]53.4%

      \[ {\left(\frac{1}{\sqrt[3]{\cos \left(x \cdot \frac{1}{y \cdot \color{blue}{2}}\right)}}\right)}^{3} \]

      div-inv [<=]53.4%

      \[ {\left(\frac{1}{\sqrt[3]{\cos \color{blue}{\left(\frac{x}{y \cdot 2}\right)}}}\right)}^{3} \]

      *-un-lft-identity [=>]53.4%

      \[ {\left(\frac{1}{\sqrt[3]{\cos \left(\frac{\color{blue}{1 \cdot x}}{y \cdot 2}\right)}}\right)}^{3} \]

      *-commutative [=>]53.4%

      \[ {\left(\frac{1}{\sqrt[3]{\cos \left(\frac{1 \cdot x}{\color{blue}{2 \cdot y}}\right)}}\right)}^{3} \]

      times-frac [=>]53.4%

      \[ {\left(\frac{1}{\sqrt[3]{\cos \color{blue}{\left(\frac{1}{2} \cdot \frac{x}{y}\right)}}}\right)}^{3} \]

      metadata-eval [=>]53.4%

      \[ {\left(\frac{1}{\sqrt[3]{\cos \left(\color{blue}{0.5} \cdot \frac{x}{y}\right)}}\right)}^{3} \]

      expm1-log1p-u [=>]53.4%

      \[ {\left(\frac{1}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt[3]{\cos \left(0.5 \cdot \frac{x}{y}\right)}\right)\right)}}\right)}^{3} \]
    4. Taylor expanded in x around 0 58.8%

      \[\leadsto {\left(\frac{1}{\mathsf{expm1}\left(\color{blue}{\log 2 + -0.020833333333333332 \cdot \frac{{x}^{2}}{{y}^{2}}}\right)}\right)}^{3} \]
    5. Simplified59.2%

      \[\leadsto {\left(\frac{1}{\mathsf{expm1}\left(\color{blue}{\log 2 + {\left(\frac{x}{y}\right)}^{2} \cdot -0.020833333333333332}\right)}\right)}^{3} \]
      Step-by-step derivation

      [Start]58.8%

      \[ {\left(\frac{1}{\mathsf{expm1}\left(\log 2 + -0.020833333333333332 \cdot \frac{{x}^{2}}{{y}^{2}}\right)}\right)}^{3} \]

      *-commutative [=>]58.8%

      \[ {\left(\frac{1}{\mathsf{expm1}\left(\log 2 + \color{blue}{\frac{{x}^{2}}{{y}^{2}} \cdot -0.020833333333333332}\right)}\right)}^{3} \]

      unpow2 [=>]58.8%

      \[ {\left(\frac{1}{\mathsf{expm1}\left(\log 2 + \frac{\color{blue}{x \cdot x}}{{y}^{2}} \cdot -0.020833333333333332\right)}\right)}^{3} \]

      unpow2 [=>]58.8%

      \[ {\left(\frac{1}{\mathsf{expm1}\left(\log 2 + \frac{x \cdot x}{\color{blue}{y \cdot y}} \cdot -0.020833333333333332\right)}\right)}^{3} \]

      times-frac [=>]59.2%

      \[ {\left(\frac{1}{\mathsf{expm1}\left(\log 2 + \color{blue}{\left(\frac{x}{y} \cdot \frac{x}{y}\right)} \cdot -0.020833333333333332\right)}\right)}^{3} \]

      unpow2 [<=]59.2%

      \[ {\left(\frac{1}{\mathsf{expm1}\left(\log 2 + \color{blue}{{\left(\frac{x}{y}\right)}^{2}} \cdot -0.020833333333333332\right)}\right)}^{3} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification61.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\tan \left(\frac{x}{y \cdot 2}\right)}{\sin \left(\frac{x}{y \cdot 2}\right)} \leq 4.1:\\ \;\;\;\;{\left(\frac{1}{\sqrt[3]{\cos \left(\frac{1}{\frac{2}{\frac{x}{y}}}\right)}}\right)}^{3}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{1}{\mathsf{expm1}\left(\log 2 + {\left(\frac{x}{y}\right)}^{2} \cdot -0.020833333333333332\right)}\right)}^{3}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy56.5%
Cost39876
\[\begin{array}{l} t_0 := \frac{x}{y \cdot 2}\\ \mathbf{if}\;\frac{\tan t_0}{\sin t_0} \leq 4.1:\\ \;\;\;\;{\left(\frac{1}{\sqrt[3]{\cos \left(\frac{1}{\frac{2}{\frac{x}{y}}}\right)}}\right)}^{3}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{1}{\mathsf{expm1}\left(\log 2 + {\left(\frac{x}{y}\right)}^{2} \cdot -0.020833333333333332\right)}\right)}^{3}\\ \end{array} \]
Alternative 2
Accuracy55.1%
Cost19840
\[{\left(\frac{1}{\sqrt[3]{\cos \left(\frac{1}{\frac{2}{\frac{x}{y}}}\right)}}\right)}^{3} \]
Alternative 3
Accuracy55.1%
Cost6976
\[\frac{1}{\cos \left(\frac{1}{\frac{2}{\frac{x}{y}}}\right)} \]
Alternative 4
Accuracy55.2%
Cost6848
\[\frac{1}{\cos \left(\frac{x}{y} \cdot 0.5\right)} \]
Alternative 5
Accuracy55.2%
Cost64
\[1 \]

Reproduce?

herbie shell --seed 2023229 
(FPCore (x y)
  :name "Diagrams.TwoD.Layout.CirclePacking:approxRadius from diagrams-contrib-1.3.0.5"
  :precision binary64

  :herbie-target
  (if (< y -1.2303690911306994e+114) 1.0 (if (< y -9.102852406811914e-222) (/ (sin (/ x (* y 2.0))) (* (sin (/ x (* y 2.0))) (log (exp (cos (/ x (* y 2.0))))))) 1.0))

  (/ (tan (/ x (* y 2.0))) (sin (/ x (* y 2.0)))))