PHP Bcmath Factorial Tutorial

PHP Bcmath Factorial Tutorial

PHP Bcmath Factorial Tutorial

Today we’ve had great guidance from this webpage’s contributors, thanks, writing a Factorial Calculator, using PHP and its Bcmath extension, revisiting concepts we last talked about when we presented PHP Bcmath Primer Tutorial.

Are you like me with maps and sometimes with long numbers … just staring at a long integer trying to find patterns?

Well, you need to let …

Factorials

… into your life … the bigger the better! Wonder at all those zeroes at the end? Carve a long factorial into a piece of soap? They say the Lord’s Prayer was written on a pinhead … what are you waiting for?!

Or just avail yourself of today’s use_bcmath.php first draft PHP Factorial Calculator

… therapy.


Previous relevant PHP Bcmath Primer Tutorial is shown below.

PHP Bcmath Primer Tutorial

PHP Bcmath Primer Tutorial

Today we have an unusual linkage of tutorials, where we link our tutorial here, today, called “PHP Bcmath Primer Tutorial” with one from some time back (and I.T. historically speaking, a really long way back) called Lisp Primer Tutorial as shown below.

The link is the way the languages handle some arithmetic on very large numbers, and today we present a web application that is like a calculator for some of those very large number calculations. Am not certain Lisp does the work this way, but the “bcmath” module in PHP, that we use for the purpose here today, uses “strings” to achieve the affect, so that I don’t believe there are any times during the calculations, necessarily, with the CPU register, that there are any great huge numbers being handled, but piece by piece, the CPU register is helping piece together that string that represents the answer we are after, not using any scientific notation in the process.

We throw into the mix a bit of fun and games … just imagine you are on Central (train) Station in Sydney, or loads of other train stations in the world where it is pretty obvious the station announcements are pieced together bits of audio, and today we make use of the wonderful Google Translate functionality in order for you to, optionally (and not always … no go with Firefox for instance), hear the results in those great mellifluous tones (in English, as default).

Hope you really give some curly questions out there to the live run. Here is the PHP source code using the “bcmath” module you could call got_big_numbers.php


Previous relevant Lisp Primer Tutorial is shown below.

Lisp Primer Tutorial

Lisp Primer Tutorial

Have you heard of Lisp, the programming language? Do you remember how incredible Hewlett Packard calculators were back in the 1970’s (we did as Land Surveyors … they were the bee’s knees, especially to program for those Land Surveying calculations). And do you (older users) remember the excitement regarding reverse Polish notation? Well, Lisp, the second oldest high-level language (after Fortran) uses this reverse Polish notation and thinking.

Am no expert with Lisp, as you’ll see, and we’ll defer to code available on the net and contributed by others, but have to mention its incredible mathematical scope, for instance, with its functionality for huge numbers (integers). You will notice with languages like C++ it is not at all easy doing a calculation like the factorial of 1000 … or 1000! … or 1000 x 999 x 998 x —> x 2 x 1 … but Lisp does it with considerable ease. As a matter of interest, as far as this type of big integer in Java, you may want to check on the BigO data type.

Today’s tutorial introduces you to Lisp we install using LispWorks Personal on a Mac laptop, and execute a Hello World and some large factorial calculations. Lisp, being the old language it is, is a very functional language, and although global variables are allowed, the Lisp “way” is not to resort to such approaches.

Below are some links regarding Lisp you may want to peruse:

Will leave you with some downloadable programming Lisp source code you could call helloworld.lisp and some factorial code called factorial.lisp

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Tutorials and tagged , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *