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

```m1q=89873960570712084732829528260849073549900665278240478747684257744366000579315782083148000591 ```

```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)) ```

k=9249
0==n/6
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:

```t=193;m1=((-1+(3^(t))*37));m1q=m1/50 ```

## 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=-2+53*101
5351 is prime

Next try p=47 so 2p5 = 89

4181=-2+47*89
4181=37*113

Next try p=59 so 2p5 = 113

6665=-2+59*113
6665=5*31*43

Next try p=61 so 2p5 = 117

7135=-2+61*117
7135=5*1427

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

9725=-2+71*137
9725=5*5*389

Next try 73 so 2p5 = 141

10291=-2+73*141
10291=41*251

Next try 79 so 2p5 = 153

12085=-2+79*153
12085=5*2417

Next try 83 so 2p5 = 161

13361=-2+83*161
13361=31*431

Next try 89 so 2p5 = 173

15395=-2+89*173
15395=5*3079

Next try 97 so 2p5 = 189

18331=-2+97*189
18331=23*797

Next try 101 so 2p5 = 197

=-2+101*197
=5*23*173

Next try 103 so 2p5 = 201

20701=-2+103*201
20701=127*163 is composite

Next try 107 so 2p5 = 209

22361=-2+107*209
22361=59*379 is composite

Next try 109 so 2p5 = 213

23215=-2+109*213
23215=5*4643 is 5 divisible

Next try 113 so 2p5 = 221

24971=-2+113*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
p=13

113=p+10^2

221 = p*(p+4)

-2+(p+(2*5)^2)*p*(p+4)

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

p=17

-2+(p+(2*5)^2)*p*(p+4)

41767=-2+117*17*21
41767=11*3797

p=19

-2+(p+(2*5)^2)*p*(p+4)
51201=-2+(7*17)*(19*23)
51201=149*349

p=1053 so p+100 is 1053
p2=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
p2=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 ipython_config.py in the correct place.

After doing a sage install there is a directory on my computer at location:
~/.sage/ipython-0.12/

The goal of this short set of hints is to assist you in creating a suitable profile_sage/ipython_config.py 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 ipython_config.py 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/ipython_config.py )

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

## 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
```   two_to_ten=2^10
a_to_power=11^two_to_ten
len(str(a_to_power))
```

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:

`gp("length(Str(11^1024))")`

### The very large - two examples using Pari:

( click on the image above for optimal font sizing )

You can check the 11^1024 digit count yourself by following this wolfram alpha link:
http://www.wolframalpha.com/input/?i=11%5E1024

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:

## Sunday, November 20, 2011

### Ex student? How much for £300 per week take home?

How much Salary does a graduate have to earn to take home £300 a week?

Rough estimate - including Student Loans Company (slc):

Assuming a nice round 60% net (tax + NI is approx 40%), we see...

£300 x 52 gives £15,600

Divide by .6 to gross up that figure gives you the higher gross of £26,000

£15,600 / 0.6 = £26,000

£90 * 12 = £1,080 (annual slc repayment on £26,000)

Estimate: £27,080

But 40% for tax & NI is wrong? But £90 per month slc is wrong?

These figures are a bit rough and ready. Feel free to substitute your own percentages.

A spreadsheet to help with the monthly repayment to slc can be found here

Note: Spreadsheet is in Open Document format (.ods).

You can view it directly in Googledocs here

Below is a preview image:

The Tax and National Insurance rate estimates are local to the United Kingdom, please adjust as appropriate for your local situation.

#### UK Zero Percent Tax threshold in 2014:

From April 2014 the personal tax threshold (level below which no income tax is payable) is estimated at £10,000

What this means for somebody earning £27,000 is that 17,000 of their salary is taxed at entry level tax rate of 20%.
Making Annual income tax liability of £3,400 (Monthly £283.33)

The earlier statement "tax + NI is approx 40%" overstates things a little. Being an employee on that sort of salary means paying 12% National Insurance (NI).

Update the spreadsheet to reflect the current picture and get a more accurate estimate.

The £90 monthly payment to your Student Loan is still payable, and is not affected by changes in Tax or NI rates.