Skip to content

A real $.push over

How do we add an element to an array in JavaScript? If arr is an array, then arr.push(element) adds the element to the array. Nice and simple.

But what if we have obj.arr? Well, then obj.arr.push(element) works.

But what if arr might not exist? If we do the above and arr does not exist, then we get an error. Of course arr will exist; we initialize it.

This might generally be the case for stand alone arrays. But what if this is part of a process that is grabbing a bunch of input and creating a variety of arrays in this big object and we want to create arrays when adding the first element to a category. So we need to test the existence of an array and then add the element if it exists or create the array and then add the element.

Example code:

if (!(obj.arr)) {obj.arr = []};
obj.arr.push(element); 

or we could

if (obj.arr) {
   obj.arr.push(element); 
} else {
   obj.arr = [element];
}

Both of these are fine constructions, but they seem to obscure the point just like the for loops do.
There are a couple of cryptic solutions:

(obj.arr) ? obj.arr.push(element) : (obj.arr = [element]);

Here we are compactifying the if statement into a one-liner using the ternary operator. I don’t like the ternary operator. Notice the parentheses around the assignment.

Another way is with the short-circuit operators. I enjoy using them, but admit that they really obscure what is going on:

(obj.arr) &&  (obj.arr.push(element)) || (obj.arr = [element]);

Notice if the obj.arr exists, then the && operator proceeds to the next, doing the operation and giving a result of true. With true, the or || is done evaluating. If obj.arr does not exist, we get a false value. This short circuits and we never get to the second term. Instead, we now move onto the or|| term and create the array.

As I said, I like this conceptually because it is fun. But for programming style, I would have to say it is poor. I bet the ternary operator was invented just to avoid people using this construct.

Now none of this pleases me. Why? Well, it is the same convoluted mental construct each time. One has to keep asking why am I doing this. And of course it is easy enough to forget to check for existence and have an error pop up on debugging (easy enough to fix, but …)

My solution? Invent a function that can do this. So the syntax I would like to use is something like
$.push(obj, “arr”, element)
So we have the object and the property name that corresponds to the array. This function would check existence, create if necessary, and push the value if not. Notice the dollar sign. Yes, I like to extend jQuery with my utility functions. It is convenient conceptually to put them all there.
So a simple implementation:

$.push = function (obj, propName, element) {
                if (obj[propName]) {
                    obj[propName].push(element);
                } else {
                    obj[propName] = [element];
                }
}; 

This does the same thing as done before, but now abstracts it away. Which also allows me to optimize it if I find out that this construct is very bad.
I have no error code in here; considering what we are doing is dealing with something of a dodgy nature, it would be good to add that. We could also do something similar for objects.

For an object, the analog would be obj.top.key = value where we need to know the top object exists. So the syntax of interest would be
$.push(obj, top, value, key)
Why do I have the value first? Because that aligns with the array and the presence of key tells us that we are dealing with an object.
So my push function:

$.push = function (obj, propName, element, key)  {
        try {
            if (key){
                if (!(obj[propName])) {obj[propName] = {};}
                obj[propName][key] = element;
            } else {
                if (obj[propName]) {
                    obj[propName].push(element);
                } else {
                    obj[propName] = [element];
                }
            }
        } catch (e) {
            throw "error in $.push"+e; 
        }
    };

Why the not and object creation that way with the assignment below it, but nor for arrays? Because {key:element} would have the property name be “key”, not the string value stored in key. It is equivalent to obj.key = element. What we want is obj[key] = element as the property should be the string in key, not the literal “key”.

Another thing of interest for me is a deeper protection against creation. For example, if traversing file hierarchies, we might be 5 folders deep and need to construct all the intervening objects. I call this $.deepPush(obj, propNames, propName, element, key) where propNames is all the intervening middle objects before we get to the final object that will contain element/key (or the element array):

    $.push = function (obj, propName, element, key)  {
        try {
            if (key){
                if (!(obj[propName])) {obj[propName] = {};}
                obj[propName][key] = element;
            } else {
                 if (obj[propName]) {
                    obj[propName].push(element);
                } else {
                    obj[propName] = [element];
                }
            }
        } catch (e) {
            throw "error in $.push"+e; 
        }
    };
    $.deepPush = function (obj, propNames, propName, element, key) {
        try {
            $.each(propNames, function(ind, propName){
                        if (!(obj[propName])) {
                            obj[propName] = {};
                        }
                        obj = obj[propName];
            });
            $.push(obj, propName, element, key);
        } catch (e) {
            throw "error in $.deepPush"+e; 
        }
    };

Note I would recommend that one use a try{ full path} catch (e) {$.deepPush} kind of construct if one was doing something with repeated very deep construction. caching it/memoizing it might be useful as an alternative. That is, attach a hash to the $.deepPush function that keeps the propNames for look up value. But profile first. I imagine by the time this is needed, a total redesign of the approach might be needed.

And yes, this passes JSLint. In fact, JSLint frowned on my obscure solutions which is what forced me to think about this and write a better solution.

Enjoy this free to use code and the freedom of JavaScript!

Tagged ,

I see dead code

So I am trying to improve my approach to parsing. So I was adding this to a property called ledHelp:

'+':function(left, right){
    this.value = left.value + right.value;
    this.instructions = 'Take '+left.value+' and ADD to '+right.value+' to get '+this.value;
    out('+:', this.instructions);
},
'*':function(left, right){
    this.value = left.value * right.value;
    this.instructions = 'Take '+left.value+' and MULTIPLY by '+right.value+' to get '+this.value;
    out('*:', this.instructions);
},
'/':function(left, right){
    this.value = left.value / right.value;
    this.instructions = 'Take '+left.value+' and DIVIDE by '+right.value+' to get '+this.value;
    out('/:', this.instructions);
},
'-':function(left, right){
    this.value = left.value - right.value;
    this.instructions = 'Take '+left.value+' and SUBTRACT to '+right.value+' to get '+this.value;
    out('-:', this.instructions);},
'**':function(left, right){
    this.value =  Math.pow(left.value, right.value);
    this.instructions = 'Take '+left.value+' and RAISE IT to the POWER '+right.value+' to get '+this.value;
    out('**:', this.instructions);
},
'^':function(left, right){
    this.value =  Math.pow(left.value, right.value);
    this.instructions = 'Take '+left.value+' and RAISE IT to the POWER '+right.value+' to get '+this.value;
    out('^:', this.instructions)
}

And I see the incredible similarity (it was copied and pasted) and that irritated me. As it should all good programmers. But I was having a hard time coming up with how to manage this. And then it hit me: iterate over an array with the different stuff and plug-n-play. Notice in the code below how I use functions as data and also rely upon closures:

var ops = [
    ['+', function(l,r) {return l+r}, 'ADD to '],
    ['-', function(l,r) {return l-r}, 'SUBTRACT '],
    ['*', function(l,r) {return l*r}, 'MULTIPLY by '],
    ['/', function(l,r) {return l/r}, 'DIVIDE by '],
    ['^', function(l,r) {return Math.pow(l,r)}, 'RAISE it to the POWER '],
    ['**', function(l,r) {return Math.pow(l,r);}, 'ADD to '],
    ];
$.each(ops, function(index, op) {
    var id = op[0];
    var operator = op[1];
    var description = op[2];
    instructions.ledHelp[id] = function(left, right) { //overwrites above if needed
        this.value = operator(left.value, right.value);
        this.instructions = 'Take '+left.value+' and '+description+right.value+' to get '+this.value;
        out(id+':', this.instructions);
    };
});

Which would you prefer to maintain? And notice that if I want to comment out the instructions bit, I do it once, not once for each operation. And to add more, I write some more code in the template and add an extra bit on the array. I could even assemble the array from various bits if I wanted to.

To $.each his own

In JavaScript, there is no iterator over arrays or objects. One has to do a for construct such as the one below. Notice how one has to declare all the variables with var to prevent global namespace pollution. And there is a lot of verbiage just to iterate over these objects.

var row, cell, type, matRow, symbolRow, rl, ml, symChar, ch;
ml = mat.length;
for (row=0; row <=ml, row++){
     matRow = mat[row];
     for (type in matRow) {
         symbolRow = matRow[type];
         rl = symbolRow.length;
         for (cell=0; cell <= rl; rl++){
             symChar = symbolRow[cell];
             ch = symChar[0];

A better way can be done with jQuery (or write one’s own custom iterator–not hard to do in this language):

$.each(mat, function(row, matRow){
    $.each(matRow, function(type, symbolRow){
        $.each(symbolRow, function (cell, symChar) {
            var ch = symChar[0];

It is iterating over the same stuff applying the function to each item (arrays pass in index, value and objects pass in key, value). This allows one to automatically encapsulate the index, value kinds of variables. With closures, one can easily access variables on the outside of the function.

Good to keep in mind.

P.S. Thanks parkov for pointing me towards syntax highlighting.

Tagged ,

Parsing

See a primitive working parser at http://mythiclogos.com/parsing/version01 Does arithmetic, does not handle ill-formed errors (missing “)” ) gracefully (does nothing actually–if you check in firebug, just gives warning).

So I have spent the past week or so creating the foundations for a parser. And reacquainting myself with Javascript and jQuery. I love both the language and the library. I hope to write more on the joys of javascripting.

But for now, I am writing about parsers. First, let me say that I have always just wanted to master the art of parsing. And that most parsing and grammar specifications and so forth have just left me scratching my head. Not that I tried to hard. For some reason, most computer science speak nauseates me. I suppose like most abstract math presentations. In both cases, the subjects of interest are incredibly useful and beautiful and wondrous, but the presentations and formulations leave much to be desired.

Alright, I have very little patience with other people’s stuff. I like to do stuff myself.

So that is why parsers have always held a flame in my eye. To make languages for whatever I am doing, that is power. Language and thought are entwined in each other. To think it, one must be able to express it. Or it is lost, just another emotion floating in the vast mental sea. But language is like a boat, nay,  an arc, that carries thoughts and communities around the mental landscape. Not every thought works with every language, or at least not easily. So the ability to build a variety of small boats to carry domains of thought, that is power.

And that is parsing. I have been studying Pratt’s Parsing technique, mainly from Douglas Crockford’s site: http://javascript.crockford.com/tdop/tdop.html

He[Pratt] claimed the technique is simple to understand, trivial to implement, easy to use, extremely efficient, and very flexible. It is dynamic, providing support for truly extensible languages.

So I have been working on creating a general framework where I can just plug in some syntax and get some results. Yesterday, I achieved arithmetic. Parentheses are partially done. But I think I need to refactor.

I was looking at a book on Domain Specific Languages (that’s it title), and it makes the good point of decoupling the behavior from the parsing of the language. So I want to see if I can accomplish that better since right now, I feel that I am to close to the parsing level. But I am having a hard time seeing how I am not just doing the same thing again. I think I need to dig deeper into understanding and see how each kind of behavior could be established.

But at least I was successful with creating an arithmetic parser.

With luck, I will soon create versions to parse simplified javascript, css, html, tex, asciimath, a variety of drawing languages (using canvas to draw), a gamebook language, wikicreole and other markups, and anything else I have a mind for. Creating languages I hope will become very easy. And one thing I want to make sure these all can do is to interoperate with each other. In particular, being able to markup a page for regular text with places to run math and code would be very powerful.

One dream project is to also have a web version of textmate, to an extent. I like syntax highlighting, brace matching, code folding, line numbering, find/replace with regular expressions, and a nice save/check/run system would be nice. All keyboard.

Another use for parsing might be voice dictation. I am still waiting to get the new dragon dictate for mac, but if it works as I hope, then maybe I can dictate this material. Having a parser will enable all of that to be translated fairly easily.

But of course the main target is my own version of GeoGebra. There is a lot of potential to make something utterly incredible and useful. That is my dream. It is getting closer.

HTML5

A new world is upon us. Already the web seems nearly magical in its many different uses, but within a year, this might look like the dark ages.

As HTML5 takes hold, everything seems like it will be simpler. And Flash free!

I have been reading HTML5 web programming on SafariOnline on my iPad. It is a good book; came out a week or so ago and is probably out of date already. I have already read about Canvas which is an old technology, but still exciting. More exciting is Websockets, a two way communication mechanism between server and browser. This makes a whole host of things possible that, I think, will not run into security problems and need for plugins.

So I wanted to experiment with it. I was all set to just use GoogleAppEngine. It uses Python and avoids SQL, which are two facts that I love. And it works and scales and is free until you have enough hits to pay the bills. Seems great. But there is no Websockets as far as I can tell and the infrastructure (no persistent program) suggests that perhaps it won’t.

So then I needed to choose something else. There are toy websockets which I will probably end up using, but what I really wanted was something that could function in production and I could play with. So what to use? Well, I want Python (though node.js is tempting out of a desire to just use one language, but I dunno know). So I looked at them, not too impressed. Then I come across Cyclone and Twisted. They look nice. So then I need to learn Twisted on top of learning Python and I need to choose a database now which should be no SQL cause I don’t like SQL. So then one needs to choose between mongoDB and redis for plug-n-play Twisted modules that are already out there.

Do you see where I am going? There is this promise of something wonderful out there, but one needs to learn so much: HTML5, CSS3, JavaScript, jQuery+Mobile, Python, Twisted, Cyclone, MongoDB, and the interface of all of that to your server’s system. And the choices. Ouch. And if one wants to also still use GoogleAppEngine for the bulk of the work and just have this one separate server for the chatty apps, then there is that suite of stuff to learn (Python again, Django-esque templating and structuring, Memcache/Datastore, YAML)

The whole thing makes one’s head swim a little.  But nevertheless, I am excited. The possibilities are amazing and now is the time to finally make something awesome. This I vow to do, along with losing 20-30 pounds, becoming fit, and writing 2-3 books all before a baby comes along. Oh, and producing an amazing math idea so I can still squeak in under the age limit and get a Fields medal.

It will be a busy 7 months.

Tagged

Junk

Here is something mythic: getting rid of 300 books (goodbye Perl).

How to:

  1. Wake up.
  2. Go “Ugh”.
  3. Be merciless in putting books in piles to remove.No breathing, no reflecting, and when in doubt, chuck it.
  4. Have an iPad, a PDF reader (iAnnotate is my favorite at the moment), an ebook app, and a SafariOnline book subscription.
  5. “Gift” some books to others.
  6. Break your back loading car with heavy book loads.
  7. Drive to Book Thing in Baltimore and watch grown man weep with joy at seeing new book quality high-tech books come in.
  8. Drive away and never look back.

Repeat variations of this for childhood memories (goodbye Infocom manuals and their 5 1/4 floppies), DVDs (goodbye B5),  CDs (goodbye Weird Al+hits from the 80s), VCRs (goodbye Star Wars) and PCs (good riddance Windows).

Thrift store might work for some, garbage for others, bugbears for the rest.

All I have to say is that it felt incredible to get rid of all that crap. I still have 300 books to do away with, but it is a significant decrease from the 1000 that I started with a long time ago. There are also two crates of notes/papers from my younger days of indiscretion (ah the joys of PhDing); these I find hard to part with just yet. But one ton at a time.

With the internet, Netflix, Amazon, and Apple, we might just one day arrive at the promised land of no stuff, just a flask, a pan, a knife, a pair of chopsticks, an iPad, and, if you insist, some clothes.

Tagged

Video done; I want good defaults

I have finished my video lectures. They consist of ten weeks of videos with 2-4 hours of videos each week, probably 30 hours in total. It took me 2 months to accomplish that and I still have the encoding and uploading to do. But at least the recording is done.

It is exhausting. An hour of recording is utterly draining. And while my students seem to be profiting from them and perhaps even enjoying them somewhat, I am always cringing at what I did. I felt that it was best to demonstrate stream of thought and process then to make it smooth, but that does introduce a certain level of pain while watching.

I am pretty sure that it is at least as good as my lecturing, but that may not be saying much.

I should be celebrating but today is grading day. And here is a gripe. The default for grades seem to be to not include in the course grade. Each time I grade an assignment, it looks like I have to go into the item and change it to be included in the course grade. This seems weird to me. So I just noticed that a few items from the past few weeks were not being included in the course grade. Yet another thing to need to pay attention to.

I want good defaults that do want you want them to do in 95% of the cases.

ffmpeg

Okay this is a short summary of lessons learned in my ffmpeg journey to encoding and compressing my files.

I use a 27in iMac (called ScarMac due to its beautiful left-side scar that came with it) and record videos using the built in camera and Screenflow. The default export to h264 gave a compression that led to say 100 mb while the lossless export would be for that size about 1 gb. Because I wanted to export it to both a web view and for iPhone, I wanted to encode twice. I am a command line kind of guy so I looked up how to do ffmpeg.

My first stop was installing for mac It explained the need to install lame, faac, and faad before ffmpeg. I would also recommend installing libx264 (source, commands)though I feel like it should have already been there, but things worked after I did that.

So after compiling from source and installing (usual config and make steps),  then one needs to encode the videos. I found this site to be helpful: Perfecting h264 conversion with ffmpeg I will paste the commands I use below. Here is a site of cheatsheet codec stuff and some more commands

Now running the encoding on each file takes awhile and so I setup a python script to run through them. I have other scripts that compile my tex documents and organize them and create the html code to upload it all–I work hard at being lazy.

So then I have a bunch of .mp4 videos. The full size ones would be say 20 mb while the iPhone ones would be 40mb in relation to the sizes above.  (1.36gb became 46mb for full, became 103mb for iphone   vs. 169 mb for screenflow default; this is for a 31 minute screencast with slides/geogebra demo and my talking head in the corner) Quality is the same or better for the most compressed one. These compressions vary, of course, but in general these compression rates seem to hold. Pretty nice.

I used jwplayer to play the videos and found their article on compression to be quite useful. The codecs vs. formats confused me. One thing that I had to figure out was that .flv files are not to be used. Just use .mp4 files as they work in the flash player and should work in html5 too. I still have not figured out the full story on getting things to work on the iPhone, but someday I may understand it. Or just upload to YouTube and let them worry about it.

My python script:

import os
import re
from os.path import join
import subprocess
import shutil
import glob

num = "04"

src = "~/Desktop/"

destf = "~/videos/compiled/W%s/W%s_full/"%(num,num)

desti = "~/videos/compiled/W%s/W%s_iPhone/"%(num,num)

files = glob.glob(src+'*.mov')

print files

for fili in files:
    fil = (fili.split("/")[-1]).partition('.')[0]
    print fil

    #ipodTouch compatible?
    p = subprocess.Popen("ffmpeg -i %s.mov -b 1200kb -mbd 2   -cmp 2 -subcmp 2 -s 480x320 %s_i.mp4"%(src+fil, desti+fil), shell=True)
    p.communicate()

    #main file, small and good
    p = subprocess.Popen("ffmpeg  -i %s.mov -acodec libfaac -ar 44100 -ab 96k -vcodec libx264 -vpre slow -level 41 -crf 20 -bufsize 20000k -maxrate 25000k -g 250 -r 30 -coder 1 -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -flags2 +dct8x8+bpyramid -me_method umh -subq 7 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq 'blurCplx^(1-qComp)' -bf 16 -b_strategy 1 -bidir_refine 1 -refs 6 -deblockalpha 0 -deblockbeta 0 %s.mp4"%(src+fil, destf+fil), shell=True)
    p.communicate()

And that is what I know about ffmpeg encoding. It works for me and does a beautiful job. To do file transfers, I am currently using forklift.

Enjoy!

Update:

I augmented the audio volume levels by using

-vol 1024

which augments it by 400%, I believe. The setup is that 256 represents 100%, 512 200%, and so on.

A response to “Quick Impressions of Bohmian Mechanics”

This is written as a response to:

Quick Impressions of Bohmian Mechanics

—-Addressed to the author of that blog.

I applaud you for taking the time to read about Bohmian Mechanics. Just as a word of warning,  Shelly Goldstein was my PhD advisor and  I consider myself to be very lucky to have worked with him.

To be clear, his chip (and mine) is about realism and clarity of theories, not Bohmian mechanics. For example, he and his group have formulated realist theories of GRW [flashes or mass-densities on space-time] and many worlds [matter densities on space-time whose time evolution is needed to distinguish the different realities, like channel interference on TV]. See Many-Worlds and Schrödinger’s First Quantum Theory and The Quantum Formalism and the GRW Formalism

One of the key questions that we realists pursue is, what is the theory about and what in the theory corresponds to reality? For Bohmian mechanics, it is about particles with positions that change over time. The correspondence to reality is a simple mapping of positions of stuff.

When you look around you, what is the stuff you see in your story of the world? Is your dog a bunch of eigenvalues? a wave function on configuration space?  How is a dog represented in QM? In BM, a dog is a bunch of particles moving around according to some dynamical equations. Pretty simple-minded and it works. Nothing magical at that point. But in QM, the magic is generally at that point. There is something called collapse which somehow makes a dog. Though collapse to what (and when), I am not sure, perhaps a sharply peaked wave function whose substantial region of support gives the blurred region of dogness?

For a bit of suggested introspection, ask yourself whether you would enjoy talking about quantum mechanics as much if it was not so mysterious. If a particle always traveled through one slit, would it not be a little less fun to talk about quantum mechanics? I looked through your recently posted slides and it struck me that you enjoy the fact that the cat is both dead and alive until someone looks (“ridiculous but true”). To me, I want a story of physics that has what I see being as close to the theory’s description as possible. I only ever see a cat that is either dead or alive. So is it not the case that a theory, such as BM, that reflects that reality is better than one that has to explain away the discrepancy with collapse or splitting or magic? All other things being equal, of course.

And as to the chipness, imagine working with people who asserted that 4=1. And they did stuff, got correct answers, and were generally very happy that the magic 4=1 equation solved their problems. Now you come along and explain about modular arithmetic and this is a different number system and that 4=1 is nonsense in the usual arithmetic, but not in modular arithmetic. And their response is, “Bah! You don’t get the new stuff. Why should we care about that stuff when we have our computations.” Imagine your frustration. You state something simple and obvious and get nothing but insulted. And you see people still telling the public that, “Yeah, just take 4=1 when you need to and it works. It is ridiculous, but true.” Argh. Also pause to think about how modular arithmetic would be illuminating and allow further informed extensions while “4=1” may be a misleading basis to start from that people have to blindly accept.

And the unholy union? Well, the measurement stuff is there to make contact with physics labs. Obviously the theory itself does not care about measurement situations. Stuff just evolves. It just happens that when analyzing physics experiments, one needs to take into account the actual details of the experiment. A measurement of the position observable need not give the position of the particle. It will only do so if the experiment is setup correctly.

I do not think the article claimed to explain spin, but rather to state that the mystery non-classical stuff of spin is handled just fine. But there is a derivation of sorts for spin using Bohmian notions. In my  thesis, chapter 3 ends with deriving Dirac spinors and the Dirac equation from a Bohmian pursuit of a mapping from the value space of wave functions to the velocities of the particles. Clifford algebras and the spin stuff are exactly what is needed to do so.

In general BM, gives explanatory power and allows for clear-minded extensions. For example, BM easily extends to manifolds and vector bundles while QM is less easy due to the loss of global position and/or momentum observables. BM can be used on these spaces to put QM with modified observable notions on them as a computational formalism.

By focusing on what needs to be evolved (particle positions), all else follows. Identical particles, for example, require the proper unlabeled configuration space and that immediately gives the choice of boson vs. fermion. Focusing on the configurations leads to that choice. In QM, one can do the same, but then someone might ask, why can we change the configuration space and, actually, configurations of what?

Check out the work of Roderich Tumulka One particular nice set of papers is his work relating to black holes where BM leads to some interesting findings:

Space-Time Singularities and BM, part 1

Space-Time Singularities and BM, part 2

On the job mathematics

So last night, I ended the spring semester teaching. Two of my four students remarked as they were leaving, “This was a great semester” which is nice to hear.

The last student to leave was the one on my side of the video camera. So we sat and talked for awhile. He loved the guesstimation stuff in the course, which is something that I love too. I feel like that is something that is just so incredibly useful everywhere. The ability to understand the magnitude of a problem or issue is amazing.

Example: How much money does the Baltimore City School System cost per year? My wife and I talked about this one morning as she teaches for that system. We estimated about 1 billion dollars; I think we computed it to 1.2 billion and rounded down. We looked online and got the budget from 2007-2008 and it was 1.178 billion dollars. Not too shabby. I put the question on the last exam.

Anyway, this fellow tells me that he has already used what he has learned on his job. Largely about how he views things. And the guesstimation. Stuff is making sense to him that did not use to make sense. At the same time, he was joking about “when was the last time derivatives were ever used on the job” to his fellow workers. Fair enough. And I do not pretend that post-arithmetic is useful on the job. I like to think of it as a mindset, not a toolkit.

I remarked to the fellow that he does not need to do derivatives because someone else did that stuff. He does environmental policy compliance stuff. So I remarked that I would hope science was in there somewhere. And he said, yes, but that it had all been worked out already. They have regulations that say that parts per million of emissions of something should not be more than such and such when such and such is being produced. And so he just checks the numbers. He does not set the thresholds which is where the science and math is.

And I said that it might even be better that he does not know the stuff. And he replied with the fact that sometimes some stuff gets kicked out to engineers that do know this stuff. And they then start getting aggravated as to why the regulations are such and such instead of so and so. He just measures and gets on with things. He actually quipped that someone did the math and converted it into a series of extremely legalistic terms and writings that he needs to interpret. I thought that was funny to convert math/science into legalese. Still complicated, just different. Prevents the engineers from getting involved, I suppose.

Sort of like when I do taxes. I keep looking for the formula, the overall picture. Instead, I get a lot of “put this in line 23. take 20 and add it to line 23 to put in line 24.” Percentages, and if-thens, and all the rest are written abstrusely to me in this step procedure. Give me an equation, please! (sort of like GUIs are great and all, but give me command lines and APIs when I need to do some real work)

But he was very happy with the course and learned a lot. He thanked me for understanding that the course was set at a level of overview, not detailed mastery. Though I do think they all learned a great deal. But only time and other courses will tell.

Then I read What is Mathematics For? today and it was right on. So many people talk about putting applications in mathematics and the usefulness of algebra or what-not on the job. This fellow, Underwood Dudley, patron skeptic of math cranks, argues that few use algebra or post-arithmetic mathematics. Everything has already been done for the vast majority of employees. He even gave an example as to when he had to compute a rate that was not in the rate books and his boss noted of his work “that is not how we do it”; and so he redid it using the long way, presumably to the same answer.

It is a great article and should be read. The main conclusion is that we teach mathematics for the ability to reason. And that is pure beauty. I like that reason and believe in it. Though I do think for useful math stuff, guesstimation should be taught, over and over again (still arithmetic, though). And learning about the lies told by pictures and data. Very important.

Final paragraph of the article; I love the steward bit:

What mathematics education is for is not for jobs. It is to teach the race to reason. It does not, heaven knows, always succeed, but it is the best method that we have. It is not the only road to the goal, but there is none better. Furthermore, it is worth teaching. Were I given to hyperbole I would say that mathematics is the most glorious creation of the human intellect, but I am not given to hyperbole so I will not say that. However, when I am before a bar of judgment, heavenly or otherwise, and asked to justify my life, I will draw myself up proudly and say, “I was one of the stewards of mathematics, and it came to no harm in my care.” I will not say, “I helped people get jobs.”