Saturday, September 2, 2017

High performance [mathematical] computing

When talking about supercomputers, there is a temptation to define things in terms of either of the following:
  1. massive simulations 
  2. they mean maths
Here is a phrase used in a recent discussion about high performance computing (hpc) that points to the first definition for my mind ...
The term number-crunching refers to large-scale numerical simulations
Now simulations of spacecraft flight or the effects of adding a dam to a major river really are typical uses of hpc

However, thinking about (2 ... they mean maths), you have many uses of hpc where the Mathematics itself is the outcome.

For people who are learners of hpc, I can see why the 'massive simulations' message is preferred as a way of presenting the utility of hpc

However as a Mathematician I naturally think also of many scenarios where the Mathematics is the outcome.

Not all of those outcomes will be moved onto a powerful workstation in the next decade.

There is also another major use of hpc which is not really [in my opinion] a good fit for the word simulation. Natural language processing at very high speed is one of the prerequisites of AI.

In such a context you are not simulating the process of adding meaning to raw words, you are actually doing it when you task a hpc with such processing.

Tuesday, February 14, 2017

shifting from m1q 898739...000591

Here is a fun loop for you to code up in Pari/GP and examine the output


for(k=9000,10000,n=m1q+2+3*k;n6=n%6;prim=0;if(0==n6,prim=isprime(n/6));print("k=",k," gives ",prim,"=isprime(n/6)");if(prim>0,break))

Sample output for loop starting k=9000

k=9000 gives 0=isprime(n/6)
k=9001 gives 0=isprime(n/6)
k=9250 gives 0=isprime(n/6)
k=9251 gives 1=isprime(n/6)

Here is a slightly improved loop:

for(k=9000,10000,n=m1q+2+3*k;n6=n%6;prim=0;if(0==n6,print("k=",k," 0==n/6");prim=isprime(n/6));print(" gives ",prim,"=isprime(n/6)");if(prim>0,break))

 gives 0=isprime(n/6)
 gives 0=isprime(n/6)
k=9251 0==n/6
 gives 1=isprime(n/6)

m1q is prime and has the following construction:


Monday, February 8, 2016

primes and quadratic involving deduction of 2

Take a prime p and double it then deduct 5 to obtain 2p5

candidate = -2+p*2p5

Is candidate prime?

Example p=53 so 2p5 =101

5351 is prime

Next try p=47 so 2p5 = 89


Next try p=59 so 2p5 = 113


Next try p=61 so 2p5 = 117


Next try 67 so 2p5 = 129

8641 is prime

Now algebraically we might say -2+p*(2p-5) which is rewritten 2p^2-5p-2

Next try 71 so 2p5 = 137


Next try 73 so 2p5 = 141


Next try 79 so 2p5 = 153


Next try 83 so 2p5 = 161


Next try 89 so 2p5 = 173


Next try 97 so 2p5 = 189


Next try 101 so 2p5 = 197


Next try 103 so 2p5 = 201

20701=127*163 is composite

Next try 107 so 2p5 = 209

22361=59*379 is composite

Next try 109 so 2p5 = 213

23215=5*4643 is 5 divisible

Next try 113 so 2p5 = 221

24971 is prime

Answer will be divisible by 5 when -2+2p^2 is divisible by 5
( or written another way answer cannot be divisible by 5 when -2+2p^2 is not divisible by 5 )

Now we redo the above example but with slightly different assignment for p

Set the prime 113 then deduct a 100 and use that figure as p

13 is prime


221 = p*(p+4)


prime 24971==-2+113*221            ( 221 is 13*17 )






p=1053 so p+100 is 1053

prime 1283313211==-2+1153*(1053*1057)

( 1283313213==(3^4)*7*13*151*1153 )

Now let us vary things slightly by defining p2=p+100 and having our answer derived as -2+(p2^2)*(p2+4)

p=953 which is prime and then p+100 is 1053

prime 1172011111==-2+1053*(1053*1057)

( 1172011113==(3^8)*7*(13^2)*151 )

Tuesday, September 10, 2013

sagemath terminal colours - green > blue

Sagemath includes an embedded version of ipython and any changes you make to terminal colours need to happen in in the correct place.

After doing a sage install there is a directory on my computer at location:

The goal of this short set of hints is to assist you in creating a suitable profile_sage/ file.

That file should look like this:

# Configuration file for ipython.

c = get_config()

# Set the color scheme (NoColor, Linux, or LightBG).                                                                    
c.TerminalInteractiveShell.colors = 'Linux'

What that will achieve is to make your prompt green instead of blue.
The default (blue) seems a little bright on the eyes, so by setting colors = 'Linux' you get the less garish green prompt instead.

You can just run ahead and use geany or another editor to create with content detailed above.

If you prefer to look at what iPython itself generates then you might wish to know of these two commands:
  • ipython profile list
  • ipython profile create justcreatedbyme
However be aware that you want to be running the embedded ipython version when doing 'profile create' in order to be sure a a fully compatible profile is created.
( Manual copy / rename things to get file to proper location of
profile_sage/ )

An example of the output from profile list is shown below:

List of profiles available to iPython

Thursday, June 27, 2013

Power of negative number - pari gp

Do use parentheses () to wrap your negative where necessary.

Because exponentiation has priority over +/- you should wrap your -1 in parentheses (), or, if just squaring, use the sqr() function.

The priority of operators in Pari/GP is detailed in Section 2.4 of the User Guide and titled "2.4 GP Operators"

Sunday, January 20, 2013

number of digits function - sage - sagemath

If you work with Sage a lot, then these two points will help you remember how to get a digit count:
  • Sage uses Objects to represent mathematical constructs
  • Sage is written in Python

Answer: 1067

There are 1067 digits in the number formed when 11 is raised to 1024

Pari/GP and number of digits:

In Pari/GP the length() function can be used in a similar way to len() in Sage. In Pari try length(Str(11^1024))

You can still access Pari/GP directly through sage.

Try this in Sagemath:


The very large - two examples using Pari:

( click on the image above for optimal font sizing )

Notes and further reading:

You can check the 11^1024 digit count yourself by following this wolfram alpha link:

Python note: Although sage allow you to use ^ to indicate raising to power, when writing in Python directly you should use the correct ** operator.
Pari/GP is designed particular for number theory, and does not have a real need to store mathematical constructs as api friendly Objects [by default] in the same way as Sage does.

Tuesday, May 1, 2012

ipython - Better Feedback for Beginners

Having worked with Python through Sage Mathematics, and directly through Emacs, I never really took the time to understand what IPython offers.

For beginners or Intermediates who want to try something to see if it adds to their productivity, IPython is worth a look.

who and whos:

%who lists names of all objects, but %whos shows the list with type and contents summary.

Depending on your system IPython setup, you may be able to omit the % at the front and just type who and similar 

'run' and variable inspection:

The run command executes your python [script] and brings the variable into the interactive namespace.

There are many more features of IPython like tab completion, history, and logging.

Do take a look and see if it can add anything to your productivity in Python.

There is an interactive test site here if you want to get started now: