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?

Answer: Around £27,000 per annum


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).
Download LibreOffice to edit or view locally

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.

Saturday, November 5, 2011

Science - who should have a voice? is silence Scientific?

I am not anti-vax, I am not pro-vax, and I am no more comfortable with the ex actor becomes science voice, than I am with ex actor becomes president.

One thing that I would say, is that whilst I am no fan of Mr Celebritee, or Ms Ex Baywatch, it would also not be entirely wise, to smack down completely, all voices from outside the Scientific establishment.

It maybe in 15 or 20 years that Science (the community) has more of your faith, or less of your faith, but whatever, it might not be the same level as today.

If I could turn down the volume level on the non-science stuff/people then that would be great, but be careful of pursuing a policy of Science (establishment) or strict silence.

Here is an illustration:

Science - Non-science celeb
.       -  A
a       -  A
A       -  A
A       -  a
A       -  .

The final option above is the 'Scientific establishment only' viewpoint - where you might advocate nothing else having a voice.
This option is not what I would choose.
Neither would I choose the first or second lines above.

I have been on the receiving end of some difficult reading in the past.
Reading journalists using pseudo-science to build a following around a view, that serves corporate lobbyists, but also their own profile, is painful.

I do not have a total solution.

The Internet has created a great way of building a community around celebrity messages.
Sometimes those celebrities are not in it for the good of that community, and may even be part-funded by a company that stands to make a good profit, from debunking the current Scientific view in a particular area [ allegedly ]

One solution is to give all citizens at least some introductory experience in critique, and researching of funding/sponsorship.
In the UK we have school leavers well versed in Facebook likes and shares, but who have no idea how to critique or spot a 'sponsored' report.

The very fact that political lobbying is so successful in the West, is testament to how lacking, in even basic critique, some countries citizens really are.


Celebrity bloggers do science - Is this the return of Quackery?

Possibly.

However listening (entirely) to the Science establishment reaction to this, might see too strong a response.

I watched a TV programme in 2011 where the President of the Royal Society, Sir Paul Nurse talked about the state of Science, and the rise of the celebrity blogger.

I agreed with much of what was said in that programme, however [ going back to the critique :) ], there is a billion pound Science industry in the UK, and most of what was said is, what you might expect of somebody seen as a figurehead for the Science establishment.

One thing that I seem to recall was the message that Science is on trial because of recent events / debates.

In order to have a trial, you need a jury, even though that jury may include types who you personally cannot stand :)

The Science establishment cannot be it's own jury*. Perhaps our job might be to ensure that, where practical, we enhance (and share) our personal critique skills, and be aware of how to spot the quackery.

jury* here does not mean peer review. Peer review is very important and I respect that, however if an 'alternative view' is growing stronger because of celebrity bloggers, then perhaps it is unwise to ignore how the 'lay person' feels about Science. Just how are you going to address this Scientists?

To avoid any confusion: I am an advocate of peer review, and appreciate how important this is - recent example - the reexamination of the 'faster than speed of light' speculation of European Physicists in 2011 - stimulated by CERN / observations between Switzerland and Italy.

I am not a Physicist, and have no clue about relativity.
However as a lay person (in the area of Physics), it is helping my faith in that area of Science, when I see such a 'peer review' process in action.

However the Scientific establishment is not infallible (see link below)
Science is not the only voice I want to listen to.
My (personal) choice is to listen closely when Scientists speak, but also, not to assign zero weight to other voices.

Whilst I appreciate the importance of established Scientific Journals, I also appreciate the need for arxiv


Notes and Further Reading:

Extract from Heaviside (from link below):
Heaviside was not interested in rigour...
Whist rigour and proof are very important, there are very occasionally folks, who despite resisting rigour and process, manage to discover and apply something magnificent.
( Just to be crystal clear here I am thinking about Heaviside, and not any celebrity bloggers that I have read to date )

Heaviside did eventually get the recognition that he deserved, however the people who he did not 'get on with' entirely, managed to delay that recognition by several years.

The Scientific Establishment is a people system, and just like any people system (or computer system), is likely chock full of imperfections.

However my personal view, it that the Scientific Establishment (currently) does a pretty good job, so I will keep listening.

There have been at least two major Science debates in the last decade, where public opinion has really entered into the debate. In neither case, have I personally seen anything, that had me thinking, on those particular issues, that Science was wrong.
However I do not rule out in the future, the possibility, that I might find myself disagreeing with Science on a particular issue either.

For me it is an issue by issue thing. On individual topics, I try to critique where I can.

Want to help make Science more open? Read the manifesto and consider endorsing.

Note: I have no personal affiliation to Nick Barnes or that manifesto, read and critique what is said for yourself.

Friday, October 28, 2011

unknown question - random answer - probability via trial

If you choose an answer to this question at random, what is the chance that you will be correct?
a) 25%
b) 50%
c) 60%
d) 25%

Here are my musing - maybe correct - maybe not.

Assume (correctly?) that you do not know enough about the question and answer to know which is the correct answer.

But assume that one of the answers is correct.


There are four possibilities required* - (a) is correct, (b) is correct, (c) is correct, (d) is correct

( *this statement is a little naïve, but a full analysis using methods of probability would I think give you a similar 6/16 conclusion ... although it might produce a more satisfactory explanation )

Count the ticks (6) and the total cells (16) and here is your answer   37.5%   (longhand 6/16)

But does this feel right?

Well if there were just 3 choices (a), (b), (c) and no two answers were the same then you would think 33% (approx)

Note: That assumes that one of the answers is correct - an important assumption.


Preliminary Musings:

Answer is 37.5% providing that the original question is extended to say "...and one of the answers is correct"

Without assuming one of the answers is correct, my reasoning would be different (see below)

But 'Possibility 1' and 'Possibility 4' are the same I hear you cry?
'At random' in this case makes me think 4 trials...

To elaborate:- In my table layout, "(a) is correct" is different to "(d) is correct"

Here I have still ignored the actual text listed in the answers written.


Preliminary Musings 2:

Some reasoning and context: Assuming my answer 37.5% is correct, then going back to the original context ....

...we might say that "...none of the answers is correct" as only options available are 25%, 50%, and 60%

So "what is the chance that you will be correct" could only be answered with NO CHANCE (zero percent)


Conclusion:

Looking at the actual answers and reasoning using logic.

25% being the correct answer would mean that (a) is correct answer and (d) is correct answer, but that would indicate 50% success of probability => (a) and (d) are wrong.

(b) being correct would give 25% probability of success, but answer lists 50% => (b) is wrong

(c) being correct would give 25% probability of success, but answer lists 60% => (c) is wrong

Therefore you must conclude that (a) is wrong, (b) is wrong, (c) is wrong, (d) is wrong

So "what is the chance that you will be correct" could only be answered with NO CHANCE (zero percent)


Why is this exercise so hard? Because it is a mixture of probability, logic, abstraction, intuition, counter-intuition, all of which are hard skills.

Saturday, October 8, 2011

Pure Mathematics and the horror of numbers

He was a pure mathematician who used to work entirely with abstract symbols, but had now sunk so low that his latest report contained actual numbers, indeed numbers with decimal points; that (he pretended) was the ultimate disgrace!

The above extract is from the excellent "The Man Who Loved Only Numbers"

I laughed quite hard when I read this :)

Saturday, October 1, 2011

logarithm of large number - it is not about computation!

Computer programmers who have not studied Mathematics beyond elementary level, often trip over this one.

Perhaps you asked yourself one of these questions:
Why does Gnu Gmp library not have a logarithm function?

What is the natural log of a large number such as 6775471000000000?


Rules of logs - product and powers:

For calculating logarithms of gigantic numbers - the standard ANSI C library is probably all that you need.

That computational tool, needs to be supplemented, with two pieces of Mathematical knowledge as illustrated here:




Images courtesy of Wikipedia (Creative Commons Licensed)

The number I mentioned above 6775471000000000 is too large for entry into a school standard calculator. Ten digits or so is the most you can enter.

Rewrite the number as 6775471 times 'a thousand million' and go that way.

Using the product of logs rule (graphic above) and doing the two calculations we see that:

log(6775471) = 15.728819  to 6 decimal places

...and...

log(1,000,000,000) = 20.723266 to 6 decimal places

Add the two answers together gives 36.452085 to 6 decimal places

Alternatively for the second piece of the addition you could have used 9log(10) by utilising the second rule - power of logs.


But my number is huge and does not contain a long stream of zeros?

This is all about precision. Do you really need more than say 6 or 8 decimal places?

Avoid creating artificial conditions. Unless you are working with numerical methods and/or in Engineering, then you will probably answer NO to what I just asked.

So your number is 6775471 followed by another 75 digits (some zero some not)

If you only need 6 digits of precision in your answer, then it matters not what those 75 digits contain, simply pretend they are zero, and either adapt my method shown or...

...use the 2nd log rule from the image above.
( hint: You might want to use 75log(10) as part of your workings. )

Answer Guess: Around 187.nnnnnn sounds about right.


Prime number searching should not be limited to just Mathematicians

Agreed.

However looking up some rules of logarithms by reading this page or looking on Wikipedia is not hard.

So quit moaning that 'such and such a library' does not have a function for logarithms of huge integers, and take five minutes to do a little addition and subtraction.

Often Ansi C coders first go searching for log() of huge integer functions, when they are writing prime number search programs, which is why I mention it.


Notes and Further Reading:

Laws of Logarithms is part of the "Core 2 (C2)" Curriculum for post compulsory education in the UK (A level) .

If you studied Engineering at University, then you will have encountered Laws of Logarithms twice - once as part of 'A Level' Mathematics, and once as part of your Engineering course.

All the Logarithms in this article are 'Natural Log'. Your calculator might show that as 'ln' depending on the brand.

The Laws of Logarithms apply similarly to base 10 logs - but you would obtain different decimal answers, than those tabulated above.

The Index page for that C2 book shows pages 43 and 44 cover 'multiplication law' & 'power law' for Logarithms.

Friday, September 23, 2011

log theory reminder - pari / gp useful

When working with a scientific calculator that has log to base e and log to base 10 only, employ 'Change of Base' theory.

Change of Base - Wikipedia


Source: http://www.wikipedia.org/wiki/Logarithm#Change_of_base


Change of Base - questions rewritten:

If you know even a little about logs then you should be able to answer the following question:

What is log to base 10 of 1000?
The blindingly obvious answer is three.

Here are two additional ways of phrasing things to get an answer:
  • To what power do we raise 10 so as to obtain 1000
  • How many zeros in 1000

Assuming your calculator only does natural log (log to base e) use Change of base:

log to base 10 of 1000 is (log to base e (1000))/(log to base e (10)) = 3


Pari / GP - an example using x=1+1365*2^15

Pari / GP is a number theory program. It is designed for working Mathematicians / Number theorists, and is most useful to folks comfortable with Mathematical theory.

It is not designed, primarily, as a 'user friendly calculator replacement' for lay folks.

Now using x as given above - what is log to base 2 of x?

     Answer:






If you want that Answer as a continued fraction then Wolfram Alpha can do that.

Wednesday, September 21, 2011

Introduce a little Geometry into your life - morning

What is not to like about Geometry ... it surrounds us, so why not embrace it?

Patios & Pools to Steps & Walkways and beyond.

Have fun and introduce a bit of Geometry into your day!

Wednesday, August 31, 2011

Counter examples as Mnemonics - Remainders

When refreshing my memory about a Mathematical subject - I find counter examples can be a useful way of getting active. Here is an example about mod() / Congruences.

Working mod 4 with two numbers a=5 and b=7

...and writing in computing function form we say...

mod(a,4) = 1

  and

mod(b,4) = 3

Now apply a scaling (k) to both numbers ... say ... scaling by 11

mod(ka,4) = 3                       (ka is 55)

  and

mod(kb,4) = 1                       (kb is 77)


And what we observe is that the results seem to have exchanged places :)

This counter example is a good reminder that applying the same scaling to two different numbers does not always preserve the mod result.

There is much theory to access regarding congruences / modulo, and counter examples like this, can be a good way of stimulating a refresher of that theory.

Sunday, August 21, 2011

The death of week numbers - and browser help

Used to be a time when workers in offices had week numbers marked at the bottom of the page, of a desktop paper diary.

Managers and others with budget responsibilities found these particularly useful

Now folks are using smartphone calendars, Google calendars, or Lightning to help with their planning.


Marathon preparation - 12 weeks or so right?

Question: When do I need to start my running preparation if my Marathon is 1st December?

The simple answer is 48-12 = week commencing 5th September .... but some images make it clearer.


...and for folks who live in a web browser rather than at the command line ...




Wednesday, August 17, 2011

gmp mpz gotchas - part 1

The GNU mp (gmp) library is a fast and stable library for working with large integers.

As with all software, when you begin using it, you find out things that you should and shouldn't do.


NULL arguments to functions - check for each function:

mpz_get_str() is a function which seems to handle a NULL first argument just fine.

Example function call:

outM = mpz_get_str(NULL,10,M);

(outM above is a char pointer and gets the decimal representation of mpz M)

In the documentation, the function signature for mpz_get_str() is given as:

char * mpz_get_str (char *str, int base, mpz_t op )

Second example - be careful what you assume!

if (mpz_mod_ui(NULL,C,6) == 0) { /* do something */ }

The above throws a runtime error - not surprising when you consult the documentation for the function signature.

unsigned long int mpz_mod_ui (mpz_t r, mpz_t n, unsigned long int d ) 

mpz_mod_ui() is quite clear that the first argument should be an mpz type, so don't disappoint it :)

When working with gmp, you are effectively working in two type spaces - C and native gmp types. Functions such as mpz_mod_ui() are really flexible, in that they give you the mod() result in two different type spaces.

Libraries are not mind readers, and cannot know in which type space your next line of code will be working. By giving you the result as both an unsigned long int and the mpz_t labeled here as r, the function is doing it's damnedest to help you out!

The downside is that you may well see little point in retaining the result in the other type space.

My runtime error was caused by me attempting to throw away the mpz_t result as it felt redundant.

Here is my new preferred way - use an mpz_t you set up particularly for transient results.

if (mpz_mod_ui(MOD_NULL,C,6) == 0) {
 /* flag as six multiple */
}

Just create your own mpz_t MOD_NULL and use it where you are not interested in keeping the result. You will need to run mpz_init(MOD_NULL) before executing the if statement illustrated.



Transient variables - bad coding practices to avoid:

In the past, I have been tempted to reuse spare variables - example:
    if (mpz_mod_ui(BSQR,C,6) == 0) {

It is bad coding practice to use a seemingly proper variable, as a holder for transient data / as a dump.

Using dump variables generally is not without issue, however naming the thing correctly is at least a step in the right direction :)


The important thing to remember is that whatever you call your transient variable, that it is not used to hold values that really are used in your logic.

Avoid the temptation to reuse a label wherever possible - it rarely leads to good things.


NULL as the first argument to mpz_get_str - probably going wrong here:

Earlier I used mpz_get_str() as an example of a function that worked with NULL as a first argument.

outBSQRM4AC = mpz_get_str(NULL,10,BSQRM4AC);

Knowing the function signature, and looking at the above line of code, you should be thinking char pointer for outBSQRM4AC.

Assigning the result of mpz_get_str() using an equals symbol is okay, and you are asking the gmp library to do your allocation for you.

If however, you known the maximum size of the MPZ / character array that you require, then you may prefer to predefine your character array, and tell mpz_get_str() to use it. In that case the the first argument of mpz_get_str() will not be NULL.

If you have predefined your character array (including size, then you might instead be using a call of this form:

mpz_get_str(outBSQRM4AC,10,BSQRM4AC);


Notes and Further Reading:

The publisher SAMS have a book "Teach yourself C in 24 hours"

In the Chapter "Hour 17 - Allocating Memory" there is a discussion about malloc() and free() and how to use them in conjunction with character pointers.







A more indepth volume is titled "Teach yourself C in 21 days", but it really depends on how far you want to take your C skills, as to which is the better option.













Neither of these books are particularly 'new', however that is one of the plus points of C, it has a stable api and a body of literature that never goes out of date.

Neither of these books will teach you C++, however I have not and probably never will have, any interest in learning C++

If you do, then the 'in 24 hours', probably does not come near to describing, the time that you will have to devote to becoming skilled in C++.

Better C++ literature is available, if you decide ANSI C is not where you wish to spend your time.

Saturday, August 13, 2011

Cython - notes and gotchas - part 1

Experimenting with Cython, as bringing together many variants of the same .c file, has me yearning to find a better Python / C balance.

Working through tutorials and experiments, I will note anything tricky, or any easy to fall into traps.


TypeError: 'NoneType' object is not callable:

Because Python is flexible, and does not insist on you declaring variables ahead of time, you may be tempted to do the same in Cython.


Better to declare the variable 'primes' explicitly, or to avoid name clashes.


So in the second example the result of the function call ends up in 'primes_list_strings' and we work on it from there.

To clarify the original error: Calling the variable that holds the result 'primes', and making a function call to primes() in the same line, might lead to confusion.


Notes and Further Reading:

If you want completion features when working with Python, then one solution is to invoke iPython and use that.

There are several full IDEs for Python including Idle and Eric, but if you just need a little completion (and syntax highlighting), then iPython is okay also.


Screenshot of Eric from screenshots.debian.net:


Sunday, June 26, 2011

how many bits - are you 32 bit or 64 bit

My laptop usually has a 32 bit GNU / Linux install and a 64 bit install also.

It pays to remember which you are logged into when using openpfgw

-su: ./pfgw64: cannot execute binary file

The answer as to why you might get that response is simple, however it is easy to mistake the symptom.

Running off and websearching 'cannot execute binary file', was the wrong thing to do, and assuming that 'su' was somehow broken was a red herring.

Logging into a console as root and running ./pfgw64 gives a more meaningful:

-bash: ./pfgw64: cannot execute binary file

...which should be enough to tell you that the problem is not 'su', which in my case is just sitting in front of bash and relaying the message.

I hinted at the real cause earlier. Running ./pfgw32 will see a better result, because you are logged into a 32 bit system!

It is great that openpfgw provide optimised binaries for 32 bit and 64 bit, and it is up to you, as the user, to select the correct one!

Remember that openpfgw will also needs some libgmp libraries in order to run, otherwise expect a complaint about a missing .so file.

Wednesday, April 20, 2011

making primes - fun with niece and nephew

You cannot make a prime by multiplying other numbers together

Whichever naïve definition* you choose to give, some examples always help.

Once the students have an idea of what is and is not a prime, a fun exercise can be to pick a significant year (Man on the moon), and work some addition and subtraction.

Using just the individual digits of 1969, challenge the student to see, how many primes they can construct, using addition and subtraction.

This exercise is a reinforcing mechanism in that instead of focusing on multiplication, you are working a secondary construction method.

  • 2 = 9 - 6 - 1
  • 3 = 9 - 6
  • 5 = 6 - 1
  • 7 = 6 + 1
  • 11 = 9 + 9 - 1 - 6
  • 13 = 9 + 9 + 1 - 6
  • 17 = 9 + 9 - 1
  • 19 = 9 + 9 + 1

Doing this with a group of students, it is more likely that at least one will spot that a +1 in the construction, can be switched to -1 in the construction, and often obtain a new prime.

Obviously this is not a general rule, however it does introduce the student to the fact that sometimes when you have a prime, another can be found, just two away.

Now use another significant year, say 1989 (Fall of the Berlin Wall), and repeat the exercise.
( Not so easy with the 1989 example )

And use the year of birth for some of the students, see how many constructions can be made.

A useful follow up discussion can be to examine why 1969 is a better specimen than 1989, for this particular exercise.

How about 1979? Better? Worse?

*Note: I used the phrase naïve definition at the beginning. With younger learners it is sometimes a useful exercise, to refine a definition, rather than give a rigorous definition at the outset.
If the student asks but what about 1, I can make 7 from 1*7, then you have an interaction, and have stimulated some thought.

Sunday, February 20, 2011

pari GP terminal colours - readable darkbg

After 3 years or more of using Pari/GP, the default highlighting (in terminal), bothered me enough, to read up how to change it.

default(colors,darkbg)

Here is a comparison of the effects of the highlighting change:


The lines prefixed %7 and %8 and in between, show the output is now in grey, and input highlighting is now greenish.

The original "1, 6, 3, 4, 5, 2, 3" profile known as lightbg is reactivated briefly, so it can be compared again.

Making the change permanent on Debian by:

emacs /etc/gprc

and changing which lines are commented out, results in the top of my /etc/gprc file looking like this:



So now when I start up Pari/GP my highlighting is set okay from the outset:




Notes and further reading:
On Ubuntu you will want to use the keyword sudo at the front of the command for editing /etc/gprc

If you want a lighter alternative to emacs on your system, then zile is a lightweight alternative that supports basic editing. Alternatively your system default editor is probably already chosen and use that.

The pari/GP command ...

default(colors,d)

... can be used interactively if you do not wish to make the change permanent.
darkbg abbreviated to just 'd' should work.

Friday, January 7, 2011

r-project / r-cran and install.packages()

My version of the excellent statistics and mathematics package from r-project.org, is now 2.11, having updated to Debian Squeeze.

( The major work from Google Summer of code 2010 is probably in 2.12 released December 2010 )

I tend to install just the minimal r-project packages and then immediately add rgl for pretty plot3d.

But before rushing into install.packages("rgl"), perhaps I should check where exactly the install code will end up.



looks to me as if /usr/local/lib/R/site-library might be the destination (set in R_LIBS_SITE), so let us see...

install.packages("rgl") pops up a country ordered list, for you to select a mirror for the install


Interesting to see the number of mirrors, 5 for Germany, and 5 for Canada, and I should scroll down to below Taiwan to pick my country.


( Above confirms my guesswork that any install.packages on my system defaults to /usr/local/lib/R/site-library )

Now what happens next, really changes the course of this article...so read on.

The install.packages() command failed as it could not locate GL/gl.h or GL/glu.h, and here I consulted my laptop.
The laptop already has rgl installed and working, so I used find and dpkg, and discovered my silly mistake.

There is already a debian package in squeeze named 'r-cran-rgl' which will do all the hard work for me :)

apt-get install r-cran-rgl 

will replace the manual install.packages() method and get you into plot3d() in no time at all :)

( for those who are interested in where GL/glu.h lives, try libglu1-mesa-dev in support of manual install of rgl )


The plot3d() function in rgl allows you 'drag to spin' functionality so you can rotate, and examine the points from any angle you choose.

In the above I have dragged the back round to the front so zero is away from you, and hopefully, you can just make out the points curving up towards point (5,5,60) which is the end of the curve.

Some further illustrations of what rgl can do can be found on statmethods.net in section 'Spinning 3D Scatterplots'.


Further reading and links:
For technical folks you really want more packages and are interested in install.packages(), here is the function definition with arguments: