Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #9303

Re: How to count

From danl@wolfram.com
Newsgroups comp.soft-sys.math.mathematica
Subject Re: How to count
Date 2012-03-30 09:38 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jl3uuf$3kp$1@smc.vnet.net> (permalink)
References <jl14ig$l5e$1@smc.vnet.net>

Show all headers | View raw


On Thursday, March 29, 2012 2:56:00 AM UTC-5, Artur wrote:
> Dear Mathematica Gurus!
>
> I have seriously problem with counting distances between smallest square
> bigger than n! (for big n) e.g.
>
> aa = {}; Do[k = 1 + Floor[Sqrt[n!]]; kk = k^2 - n!; Print[kk];
>   kkk = N[Log[kk], 100]; Print[kkk];
>   AppendTo[aa, kkk], {n, 1, 10000000, 1000000}]; aa
>
> Who have idea how to count this on Mathematica?
>
> Best wishes
> Artur

It is likely to be slow no matter what you do. Here are a couple of approaches though I've not attempted to verify results and so I cannot be sure precision is sufficiently high. I show with numbers a factor of 10 smaller than yours, so expect your examples to be correspondingly slower.

bottom = 100000;
Timing[bb = Table[Ceiling[Exp[LogGamma[N[n+1,n]]/2]],
  {n,bottom,10*bottom,bottom}];]

Out[16]= {671.196962, Null}

Around 30% faster:

sqrtFactorial[n_] := Module[
  {start, x},
  start = Ceiling[Exp[LogGamma[N[n+1]]/2]];
  Ceiling[Exp[x] /. FindRoot[x==LogGamma[n+1]/2, {x,start},
    WorkingPrecision->3*n, AccuracyGoal->n, PrecisionGoal->n]]
  ]
Timing[dd = Table[sqrtFactorial[n],  {n,bottom,10*bottom,bottom}];]

Out[26]= {463.363558, Null}

In[27]:= dd===bb
Out[27]= True

I will check that at least the last one is correct.

In[28]:= dd[[-1]]^2 > (10*bottom)!
Out[28]= True

In[29]:= (dd[[-1]]-1)^2 < (10*bottom)!
Out[29]= True


Daniel Lichtblau
Wolfram Research

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to count Artur <grafix@csl.pl> - 2012-03-29 07:56 +0000
  Re: How to count Costa Bravo <q13a27tt@aol.com> - 2012-03-30 09:37 +0000
  Re: How to count danl@wolfram.com - 2012-03-30 09:38 +0000
    Re: How to count Costa Bravo <q13a27tt@aol.com> - 2012-04-01 07:38 +0000
      Re: How to count danl@wolfram.com - 2012-04-03 08:55 +0000

csiph-web