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"
Thursday, June 27, 2013
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:
Answer: 1067
There are 1067 digits in the number formed when 11 is raised to 1024
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:
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.
- 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))
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:
gp("length(Str(11^1024))")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: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:
Depending on your system IPython setup, you may be able to omit the
'run' and variable inspection:
The
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:
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?
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).
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.
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.
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).
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,000What 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:
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):
( 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.
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.
- Biography of Heaviside [ www.gap-system.org ]
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.
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:
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:
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.
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.
- Laws of Logarithms worksheet - websearch
- C2 Core 2 Mathematics Book - Pledger & Wilkins [ amazon.co.uk ]
Subscribe to:
Posts (Atom)





