Science/Math Archives

Caught up, finally

Hello again Perl world!

After a wonderful vacation, I came back to discover that I had far more work to do than I had realized. I have only just started to claw out of the heap and arrive at a place where I have had some time for Perl-ing.

First of all I need to apologize. I missed my Grant Report this month. While this is no excuse, there also was nothing to report. I do hope to keep honing in on the few remaining problems that Alien::Base has developed, but I am increasingly believing that a few of my initial assumptions may have been too flawed, possibly requiring a little bit of rewrite. That said, what I really need is someone who has a longer beard than I (metaphorically) to help me understand some Makefile/linking stuff to help me over the hump.

That brings me to some more interesting things. I had almost gotten my additions to vti’s PerlTuts running before my vacation, and now they have finally hit; thats right, live science tutorials in Perl are coming! For now its only a few pages on my plotting extension and PDL constructors, but believe me, that was the hard part.

Finally, this weekend I added up a few more features to Galileo, these include such novel features as deleting pages and easy links to adding users and pages. For those of you who don’t know (many I’m sure), Galileo is my attempt at a fully CPAN installable content management system (website). Its runs on Mojolicious and uses websockets for real-time updating wherever possible. Please take a look and let me know if you have any issues; especially if you use the (still untested, sorry) environment variables for controlling file locations.


Welcome all scientists and friends to

This week has been an exciting week for the small but dedicated group of scientists in the Perl community. This is because this week we saw the roll-out of two science related Perl sites:

As gizmo_mathboy has already announced his group, I though I should make my site official too!

I wish we could say we had a big roll-out plan, but not so. We had discussed these things, decided we liked both ideas, and should keep them both, and somehow, this week, they both went live.

A little bit about the Perl4Science site: Its hosted on GitHub pages, mostly because its free, but it also fosters that GitHub feel of “lets share our code” which is a major part of using open source for science. Futher it uses Jekyll for a rendering engine and a cool project called Octopress to manage the Jekyll stuff. The details are in the site, including details on how you can contribute.

For now it contains some links to a few Perl science-related modules, and some links to the science related talks at YAPC::NA 2012. I want to see both lists grow. If you know of good modules or good talks please fork the site repo or mention in the comments here. I also hope to share some useful code snippets, but I don’t have a place for that just yet.

Finally, and I wish I didn’t have to mention this, but we are working on a set of standards for inclusion in both sites. For now, lets just say, if you are going to contribute, lets keep it professional and Perl/Science related, and the site owners will make final ruling on what is added. Hopefully we don’t have to use that power often.

So that bit of legaleese aside, please come and enjoy both sites. I hope people learn and people teach others. Lets make Perl (good Perl) relevant in the science community again!

Response to "Scientific papers and softwares"

Recently leprevost posted a comment on requiring better software in science. Its a good plea, read it! In response I started a comment, which got a bit too long, here it is:

A few of us have been talking about how to increase the use of Perl in the scientific community. While our efforts are in their infancy, we hope to fight this very problem. Some new sites are

  • Perl4Science, my stub site/org, to be expanded
  • The Quantified Onion, Joe Kline’s brand new Google Group, not sure if it’s been announced, guess it has now :-)

In the meantime, all I can do is contribute that good code, and put it on GitHub and CPAN for people to see and use.

There are many more projects, both written by me and others for this purpose. PDL, BioPerl etc. I really would like to reclaim some of the scientific computing that has been going to Python by default. It makes me very sad to read that when someone does choose Perl, that they would use that opportunity not to show off new modern Perl, but that old Perl that scares people away.

If you are a Scientist, you are more than welcome to contact me, David Mertens and others about how to interact with the scientific community in Perl. Even if you don’t want to do this, however, please, write Perl code that shows off the language we love.

My full YAPC::NA 2012 materials

Now that the official YAPC::NA 2012 talks are making their way online I wanted to post links to all of the relevant material for each talk.

Thanks again to all of you who attended my talks and asked great questions. To those of you watching for the first time, please ask me questions, I will be happy to help (if I can) or discuss my methods/paradigms/simulations.

Baby XS to get you started

A primer for writing XS for people who know Perl and a least a little C.

Modeling Physical Systems Using Modern Object-Oriented Perl

In which I show off my object-oriented paradigms for simulating physical systems; forces and physical objects are just objects, interactions are mediated by coderefs. I also give a simple example and show off some of my real-world simulations.

Further, the source of these talks serve as a decent example of using LaTeX/Beamer for making presentations. So check that out too. :-)

Announcing Math::Mathematica

After coming home from YAPC::NA I have a renewed vigor for coding. Because of that, I decided to brush up one of my modules that I haven’t released, document it and release it to CPAN.

Schwern and others talked about how to bring new people into Perl. For many this means making sure to include women and minorities in events and projects. For science however, I think part of the problem is the inertia of commonly used software. People don’t want to use Perl, because Mathematica makes math easy. True, but it makes programming hard IMO.

So here it is, another in my line of Perl-for-Science modules: Math::Mathematica hopes to make doing science easier in Perl. It basically starts a command-line instance of Mathematica in a PTY and controls the IO to and from it. This allows for easy writing of scripts those people that want the power of Mathematica’s math engine with the power of Perl’s language (something that Mathematica distinctly lacks).

Here is a simple example.

use Math::Mathematica;
my $math = Math::Mathematica->new;
my $result = $math->evaluate('Integrate[Sin[x],{x,0,Pi}]');

returns 2, as expected.

Of course I would prefer that you scientists/mathematicians look into my PerlGSL modules or PDL, however if you need to make a slower transition from Mathematica to Perl, this should help ease you in.

For completeness, the equivalent PerlGSL code would be

use PerlGSL qw/:integration/;
my $pi = 4*atan2(1,1);
my $result = int_1d( sub{ sin(shift) }, 0, $pi );

Why full closure support makes Perl great for science

Part of the reason I love Perl is that it has full closures. It makes it really easy for my scientist brain to think of code references as equations. This is why I try to make my scientific software think this way too; PerlGSL is built on this concept. Its especially fun when this allows me to nest functionality to get even more complex behavior.

In this following example I find the Gaussian width needed so that the integral over it on a certain range has a particular value. Yes this is an easier example, but if the function f were more complex, this code would be no worse.

Hopefully this shows some of that power, and some of the reason I am working on PerlGSL.

I will be going into more detail on similar concepts at one of my talks at YAPC::NA later this month. See some of you there?

TeXlipse for LaTeX development

I know that this is a Perl blog, so I will just post a quick link to my other blog. If you are writing any LaTeX, you should look at TeXlipse; look again if you have already tried it in the past. Read more on my other blog.

Announcing: PerlGSL - A Collection of Perlish Interfaces to the Gnu Scientific Library

With this post I am happy to announce the release of my new distribution: PerlGSL. This accompanies several other releases I’ve made in the past few days, I’ll get to those in a moment.

A few days ago I asked what I should call my new multidimensional integration module. The discussion centered on whether it was more important that it required the GSL library, or whether it was a set of bindings for the GSL (was that set complete)? Was it a dist in its own right needing a toplevel name, or that it was mathematical and should be under Math::?

After discussion and reflection, I have decided that I wanted a toplevel namespce for this project, mostly because the need to satisfy the external dependency on the GSL separates these modules from others. To make it worthy of that honor, I have made it into a dist in its own right, not unlike other named dists like Mojolicious or Catalyst, though more modular.

Unlike those projects I am not reserving the entire namespace for myself; I want people to contribute to the PerlGSL namespace. Is it a set of bindings to the GSL? No, but close. I’m calling the namespace a ‘collection of interfaces’. Can there can be more than one interface to the same library? I’m OK with that. Does any need to span an entire library? No. Can a library pull several functions from different places to create one useful Perl module? By all means!

So what does the dist named PerlGSL do? First it serves to define the namespace. Second, if you install it, it will install what I am calling the “standard modules”. So far I am the only author of these “standard” modules, but I would love to add yours, though I reserve the right no to. I want the individual modules to live on their own, but be installable together; a modular, bottom-up collection, but one that can be installed together for convenience. PDL, for example, is a great dist, but it’s huge and mostly monolithic; I can’t just install what I need. I hope that PerlGSL finds a nice balance between monolithic and separate dists.

Ok on to the technical stuff. So far I have uploaded two new modules, and rechristened another. The new ones are PerlGSL::Integration::SingleDim and PerlGSL::Integration::MultiDim, I think their names give away their tasks :-). I have rechristened Math::GSLx::ODEIV2 as PerlGSL::DiffEq. These are all part of the “standard” modules, though you only get PerlGSL::DiffEq if you have GSL >= 1.15. I have also released a new version of Math::GSLx::ODEIV2 which announces its deprecation, though it does still provide the ode_solver function via PerlGSL::DiffEq for now.

I hope to add more functionality as I need them. I hope you might do the same. The GSL is too big to ask one person to wrap it all; very few people will ever need all of it. It is really good software though, and it works really well with Perl. I hope you enjoy it.

(Sorry, this has been a bit stream of consciousness, I have been working on this a little too much in the past few days to compose something concise it would seem.)

Announcing Physics::RayTransfer

While I am still working out the bugs from Alien::Base I have released a little scientific side project named Physics::RayTransfer.

Calling all laser physicists! Does modeling your cavity using Ray Transfer (ABCD) matrices bore you? Do you regularly forget to include one of the matrices on the reversed arm on the round trip? Do you hate using that symbolic mathematical language? Try Physics::RayTranser!

It slices, dices, makes julienne fries and of course is a totally object oriented way to model your laser cavities (or other optical systems). No round trip matrices needed!

use Physics::RayTransfer;

# build the system using helper constructors
my $sys = Physics::RayTransfer->new();

# parameter for for cavity length
# from 0 to 10 in 0.1 (cm) increments
my $d = [ map { $_ / 10 } (0..100) ];

# spot size at right mirror (OC) at 1063 nm 
# for each cavity length!
my @data = 
  map { $_->[1]->w(1063e-7) }

Finally, some of you might complain that the whole thing is written in MooseX::Declare and so you have to install that whole monstrosity just to use it. Oh well, its really fast to write, and I find writing OO scientific code very intuitive using it, so get over it. :-)

Perl Data Language (PDL) 2.4.10 Release

Since the Perl Data Language (PDL) does not have a large presence in the Perl Blogosphere, I have the honor of reposting Pumpking Chris Marshall’s announcement of PDL 2.4.10.

For those of you who don’t know, PDL gives standard Perl the ability to compactly store and speedily manipulate the large N-dimensional data arrays which are the bread and butter of scientific computing. For more information on PDL please visit its website at

Chris’ release message is reposted below, the full text can be seen on the mailing list archive.

PDL-2.4.10 released

The PDL Development Team is pleased to announce the PDL-2.4.10 release of the Perl Data Language and the first PDF release of the PDL Book.

PDL-2.4.10 is the latest point release with more functionality, portability, and robustness than ever before, including:

  • POSIX threads support for all platforms
  • Auto parallelization of PDL threadloops
  • Support for PDLs larger than 2GiB
  • PDL Book draft release (PDF format)
  • Much, much, more…

As always, the source distribution will be available at a CPAN mirror near you within a couple of days. Our site has the source distribution and the PDL Book:

Windows binary PPM are available in the usual site, see “Get PDL” in the sidebar at (the PDL website for links, documentation and info for all things PDL).

The SciPDL-2.4.10 release for MacOS X systems will be announced when it is available.

Enjoy and Happy PDL-ing!

Chris Marshall for the PDL Development Team

About Joel Berger

user-pic As I delve into the deeper Perl magic I like to share what I can.