finding.my.name

eternal ramblings of an empty mind

Month: August, 2012

All Star

So I went looking for a few open source projects that I used to use, and found out that, not only were two of them long abandoned (3 years, no updates), but that third one (which was last updated in February) won’t run on my computer because I’ve got a 64-bit operating system. And I believe x64 has been relatively common for some time now. Therefore, I have added updates to these programs to my project list. Relating to one of these, I need to give myself a refresher course in finite field arithmetic, but that shouldn’t be a strain.

Some of you may know of my fondness for music. Perhaps better described as a hopeless addiction, though not one that naltrexone would affect. My tastes remain as eclectic as ever, but my choice of medium is shifting. I’m finally seeing the advantages of joining the Internet age when it comes to music. I have purchased my video games electronically for seven years. In that same period of time, I’ve purchased perhaps half a dozen songs on iTunes. My primary concern was always quality: iTunes’ AAC format versus a CD, I always considered the CD to be of higher quality. I have purchased a handful of albums with which a digital version (MP3, or, preferably, FLAC) was available in addition to the physical media, and most recently took advantage of the Humble Bundle when it went musical: again, all FLAC albums. But what’s the first thing I do with a CD? I rip it to VBR MP3 q=5 and play it from my phone through my car stereo. So what’s the advantage? Even if I did use the CD, would I ever notice a difference in the car? With that road noise? Not a chance. And despite what I consider to be a relatively discerning ear, I doubt I could tell a significant difference without a sound system far beyond my price range. Anyway, now that alternatives to iTunes exist, I may begin purchasing my music sans the physical media in the future. Unless, of course, I’m at a show. Purchased movies and television will remain hard-copies for the time being, however; if and when I resume my Netflix subscription, it’ll be the discs, not streaming.

Rounding

There are several approaches to rounding. What I was taught in school is this: round to the appropriate number of significant figures (given such information). If the current number is halfway between two numbers, round away from zero. In other words, a result gives 22.5 N, but I only have 2 significant figures, the answer will be 23 N.

In programming, I learned about the “half-to-even” approach. For the same result, the answer would round to 22 N. Whichever integer (in this case; the last significant figure is the determining factor) is even, above or below, that is what the half gets rounded to.

Some other approaches are half-up, half-down, half away from zero, half-to-odd, stochastic, and alternating. I’m not going to go into detail about how each method works, but I would like to point out a few mathematical formulas that come in handy for rounding.

Say you’re writing a program to calculate the tip to leave your waiter or waitress. 18% is fairly standard. The program on my Android will, with the selection of a check box, round the tip amount to the nearest dollar, or the total to the nearest dollar. Sometimes, however, this method winds up cheating either you or the wait staff, especially relating to small sums. Let’s use a mathematical approach to round instead to the nearest denomination d where d\in(0.05,0.10,0.25,0.50). Honestly, you could round to any number you wish; a multiple of 17¢, but that’s inconvenient for American currency, so we’ll stick with the above set for examples.

Scenario: Your bill is $7.53 (maybe a slice of pie a la mode and a drink). But you were waited on, so the staff gets a tip, as is customary (the ethics of this are a discussion for another time). 18% of $7.53 is $1.3554. Rounding up to the nearest penny gives $1.36, which is roughly 18.06%; rounding down is about $17.93%. That certainly won’t cheat either party. But if you like your tip to come out to an even dollar amount, for ease of balancing your checkbook or because you prefer to leave cash on the table, rounding up is $2.00, or about 26.53%, while rounding down is about 13.28%. If, on the other hand, you want your total to come out to an even dollar amount, rounding up gives $1.47 while rounding down gives just 47¢: either 19.52% or 6.24%, the latter of which will certainly earn you a reputation of being a cheapskate.

Solution: choose a smaller denomination to round to, either the tip or the total, doesn’t matter. We’ll leave a discussion of tax out of it for now. Let’s call the tip multiplier s, typically 18%, but adjustable in our hypothetical program. The bill is a, so as=t, and a+t=a+as=a(1+s)=v. To round the tip t to the denomination d, d\lceil{{t}\over{d}}\rceil. Same formula for the total: d\lceil{{v}\over{d}}\rceil-a (subtracting the bill amount a to get the tip amount). So let’s round the tip to the nearest 25¢. 0.25\lceil{{1.3554}\over{0.25}}\rceil=1.50. Likewise with the total: $latex 0.25\lceil{{8.8854}\over{0.25}}\rceil-a=1.47$. These work out to 19.92% and 19.52% tips, respectively. Say your waitress was…less than adequate, but still deserving of something (simply because she makes $2/hr without tips, there’s tip sharing and others are busting their butts to cover her problems, she was trying her best and just having a bad day, or any number of other reasons). Replace the “ceiling” operator with “floor”. $latex 0.25\lfloor{{1.3554}\over{0.25}}\rfloor=1.25$ and $latex 0.25\lfloor{{8.8854}\over{0.25}}\rfloor-a=1.22$. This is much more subtle than a 47¢ or 1¢ tip, generating 16.60% and 16.20% amounts, respectively, and may not impact the staff’s performance or attitude, but you did only spend $7.53.

If you wish to allow calculations of the tip with and without tax, and the tax amount is x, your values will be skewed a bit: v=as+ax+a=a(s+x+1), yet you would still use v to calculate a rounded total. as would be the amount for a rounded tip without tax included in that total, and a(1+x)s would be the value of the tip calculated including tax.

A related issue is floating point binary representation. Say you’re working with a microprocessor, and have a mere 16-bits to define a number between 0 and 14, and you want the highest possible resolution. One solution is to call the entire field floating point and multiply the stored value by 14. Thus a value of 0x0001 equates to precisely 0.000213623046875, and 0xFFFF is 13.999786376953125 (we’ll pretend that’s close enough to 14 for our purposes). That’s all well and good. Now say we want to store the value 3.3 in the memory location. This cannot be represented exactly in multiples of {{14}\over{65536}}. So what can you store, exactly, if 3.3 is out? One way to solve this is essentially the same as the above formulae. Value to store v=3.3, scaling factor d={{14}\over{65536}}. Then t=d\lfloor{{v}\over{d}}\rfloor. Or ceiling, whichever is appropriate to the application. The result will tell you the actual value being stored. If you have an offset of at=d\lfloor{{v}\over{d}}\rfloor-a

There’s one more issue I’d like to touch. Say you want to programmatically round to n significant figures in base b, whatever the input v. What we’re doing here is finding d=b^{\lfloor{(\log_b{v})-(n-1)}\rfloor}. This plugs into the formula given for tip calculation—proving its value beyond that small application.

Anything Goes

While the math in my previous post was correct, some of the assumptions I made were not. Definitely not. For instance, one of the initial equations I derived from the WAI document was wrong.

299|r_1-r_2|+587|g_1-g_2|+114|b_1-b_2|\ge125000

should have been

299(r_1-r_2)+587(g_1-g_2)+114(b_1-b_2)\ge125000

And in this case it makes an enormous difference. So it turns out that neither set of equations I presented before actually works. If you use those equations, the contrast difference will be correct (the equation I did have right) but the brightness? Not so much. So, back to the scratch paper…

My gnomic warlock (is that the correct…er…ethnonym?) is finally a member of the guild, so I won’t be bugged by other guild requests anymore. All I’ll say about this tonight is that I hate escort quests. Failed one twice in a row, gained a couple of levels, then finally managed to complete it, but then only just. I’m beginning to think that power-leveling is best done with a partner. So I’m going to spend a bit of time working on professions before going back to leveling. 31 is sufficient for now, seeing as my skills in cooking, fishing, herbalism, and inscription are 1/75.

Got the symphony chorus schedule in the mail today! I’m going to use an old stamp to send this postcard. 32¢…”I remember when…”, I won’t go there, but I have some old 37¢ first class stamps that should do the trick. The interesting thing this year is that we’re doing three concerts instead of the typical two. Friday evening we’re doing just Carmina Burana, with the Singing Quakers and the Wichita Community Children’s Choir. Saturday we’ve got Haydn’s Symphony no. 90 (yes, ninety) as well as the Orff, with the same chorus. Sunday again is the full concert, this time with Bethel College Concert Choir in place of the Singing Quakers. This means a really crazy schedule there at the end. Rehearsals on the 13th, 14th, and 15th, concerts on the 16th, 17th, and 18th. And somehow those rehearsals we’ll have to fit all four chorus groups on stage at once. Fun. But anyway, I’m looking forward to it!

I have a new idea for a sort of social application. One creates tasks which they may or may not be otherwise inclined to complete, validates them with a friend (so they’re less inclined to cheat and put down silly stuff like “walk to the car” or “pet the dog”), and they compete with friends on who can have either the longest streak of completing these chores or who can complete the biggest percentage in a day, a week, a month. Say I put down “trim ear hairs” as a daily chore. I complete it, I get a gold star (for instance)! I don’t, it’s reflected in the score. That’s not something I struggle with, but someone might. More apt for me might be “do the dishes” or “top off fishtank water”. The advantage of making it social is the motivation of friends or family. At the same time, events or tasks might be private, and posting all over Facebook that you won your game by not [insert inappropriate behavior here] all week may be a bad thing. So, no autoposting of accomplishments. On the other hand, if you’re trying to quit smoking, you might be eager to say, “Smoke free for 7 days!”. Or for your kids, it’s a 21st century replacement to the gold star charts I had in school classrooms growing up. Set rewards for completing milestones, for picking up a good habit or breaking a bad one. Kids brush their teeth and eat their vegetables: maybe by competing with their siblings (or cousins, or friends) in a little friendly rivalry, they’ll both do better. Just an idea for the pile. Someday I’m going to have to start working on that, and I could make it one of my items on the list!

Smell The Color 9

Musing about colors, and colorblindness. I’m not colorblind, but 14.5% of the human race is, along with many (but certainly not all) of our robot overlords. Anyway, by the W3C’s current recommendations, I need to meet the following criteria for color contrast. Note that I am aware these considerations may not immediately provide a solution to dealing with the various types of colorblindness, but it’s a start.

Consider colors as a typical rgb tuple, (r,g,b), where r,g,b\subset\mathbb{Z} and r,g,b\in[0,255] (there’s probably a better way to define that mathematically, but that’s what I came up with). After some fiddling with the recommendations, the gist of it boils down to the following:

299|r_1-r_2|+587|g_1-g_2|+114|b_1-b_2|\ge125000
|r_1-r_2|+|g_1-g_2|+|b_1-b_2|\ge500

The second equation is equivalent to the recommendation, provided |x_1-x_2|=\max(x_1,x_2)-\min(x_1,x_2) (a result that appears intuitive, but it’s not something I’ve proven as of yet).

Unfortunately, that’s two equations and three unknowns (assuming I pick one color arbitrarily). And to solve the equations I have to deal with the absolute values. The inequality is comparatively simple to handle. The added difficulty is that I am dealing with five colors, and each pair must meet this criteria. Granted, white and black are two of them, but that means that each of those need to be easily distinguishable from the others.

However, because, let’s call it color 0, is black, that simplifies the equations drastically:

299r+587g+114b\ge125000
r+g+b\ge500

I’ll save a great deal of the math, but here’s the result when r is chosen arbitrarily.

r\ge165
g\ge\lceil{{68000-185r}\over{473}}\rceil
b\ge{{\max(125000-299r-587g,57000-114r-114g)}\over{114}}

Not yet sure if there’s a way to yank the “max” function out of that, for instance, if one of those will always be greater than the other (doesn’t look like it). Mathematically speaking, it would be extremely nice, but a spreadsheet can easily handle stuff like that.

The reason I wound up with r\ge165, even though initially r was chosen arbitrarily, is that r255, which isn’t allowed.

Okay, time for white, the second “easy” color. I won’t go through all the steps here, just note my discoveries. I start with

299(255-r)+587(255-g)+114(255-b)\ge125000
(255-r)+(255-g)+(255-b)\ge500

And wind up with

r\le90
g\le\lfloor{{99790-185r}\over{473}}\rfloor
b\le{{\max(130000-299r-587g,30210-114r-114g)}\over{114}}

Note the change in direction of the inequality. Likewise, values of r>90 causes b<0, also not allowed.

Thing is, to be complete, I’d have to come up with four more sets of equations, for arbitrary choices of green and blue, just for white and black as the contrasting colors. And, by my calculations, as many as 48 sets for the generic cases (symmetry probably brings that to 24). And that’s just to comply with the W3C recommendations, assuming they don’t change. Colorblindness is more subtle than that, and with 8 “major” types of colorblindness (covering roughly 18.7% of the world population), this very well be insufficient. The simplest solution would be to find a bunch of colorblind people to provide their opinions. Just like when designing my website/application, I need to enlist the aid of blind folks to make sure screen readers parse the pages in a coherent manner.

So Curiosity made it to Mars without a hitch. Lots of exploration for it to do. It was slated for 2 years of operation. Let’s hope that it can exceed its expected lifetime by 3000%+ like Spirit and Opportunity. I think it’d be awesome if it were still completely operational by the time geologists make it there in person.

Meh, I always feel like I need to write more, that there’s something else I need to say, even though my readership rarely exceeds the single digits. In binary. I’ll just leave it at this. If I come up with the rest of the equations, I’ll probably post them.

You Probably Get That A Lot

Sheesh, people! Does everything have to be one? It’d almost be a relief to see a movie that had a definitive ending. Prometheus is at least getting a sequel, which is bad enough. But it has now been confirmed: The Hobbit will be a trilogy. Despite my rant mere sentences ago, this doesn’t dampen my excitement at the films. I will be at the theatre with everyone else to follow Bilbo’s unexpected journey.

And the IOC is waving its big stick again. Not only could I get in trouble (fined, sued, something like that) for using the phrases “Olympics”, “London 2012”, “Olympian” (the name of a newspaper in Washington, which has been operating since seven years prior to the first modern games), showing five interlocking rings, or symbols that in any way resemble the rings in any color, taking a photo of a venue, heck, the IOC has even claimed to own trademarks on the names of the athletes! However, they reluctantly allowed certain radio broadcasts from the BBC which were coming from the Olympic village to be available worldwide, because the majority of those broadcasts were not dedicated to coverage of the games themselves. Friggin’ ridiculous.

The fragmentation of the Android ecosystem is not exactly news. My current phone has Ice Cream Sandwich, and I’m pondering upgrading to Jellybean over the weekend. But the last phone I had officially got nothing more than Froyo (I eventually installed Gingerbread on it myself), and it had Eclair when I bought it. Especially due to Verizon’s locking of the bootloader, my phone will likely be among the last of the Galaxy S III devices to see an official Jellybean build. And it’s doubtful I’ll see an official build of Key Lime Pie for my phone, though as soon as CM11 has a stable build for me, I’m sure I’ll be installing it. But for most Android customers, the latest build that exists when your device comes out will be the latest build you ever get. Apple customers, on the other hand, will get every update to their operating system. If that update slows their device to a crawl, they have the option of downgrading and turning off updates (as I understand), but they don’t suffer from a carrier’s choke-hold quite like the rest of us.