Rational Math

Back when I was a C++ newbie, I decided to write a rational number class because I thought it would be a good exercise.  I revised it and added features over the years as I learned new stuff (I/O manipulators, for example).  I looked around my computer for it this morning and found a version that I wrote over a decade ago when I still didn’t have even a C++11 compiler to work with.

About 11 or 12 years ago, WG21’s numerics study group was thinking about publishing a Technical Specification (TS, a kind of warning about possible future standardization) that would propose some new number types (fixed-point types, an unbounded integer, things like that).  I confidently raised my hand and said that I had a rational number that I could add and proposed what would eventually morph into this*.  That “Numbers TS” is no longer in the works, so my rational number died.

I think I’ll revisit that to bring it at least to the C++20 level and implement it using the bigint class that I mentioned in the last post to avoid overflow.  I also want to put the I/O manipulators back just because I think they’re Really Cool. ๐Ÿ˜Ž

That should keep my brain working for a little while longer.


*Starting with the “[rational.math] Rational math” section, that’s what much of the C++ standard reads like.  It’s most definitely not a tutorial. ๐Ÿ˜Ž

Big Numbers

The code that I’ve posted about so far has been pretty light-weight.  Here are a couple of open-source classes that I hope could be useful in actual production code.

I have an unbounded integer and a big decimal that are intended to be C++ equivalents of SQL’s NUMERIC and DECIMAL types for use in a database access library that I’m working on.  They’re basically for storing big numbers and maybe doing a little bit of arithmetic.  The efficiency of my implementation might not be good enough for serious numerical work.

That’s particularly true for division.  I’m not as competent as I’d like to be in numerics; and when I tried to read about multi-word division in Knuth Vol. 2*, my eyes glazed over; and I had to revert to the good old “long division” routine that I learned in fourth grade.  I get a first trial divisor for each new digit of the quotient reasonably quickly; but if I guess wrong, which is likely, it takes linear time to get from that point to the right value.  If there’s a numerics expert out there who knows of a good way to do multi-word division, and if it turns out that I can comprehend it, I’d love to hear about it.

The two documentation papers, all the source code for both classes, and the open-source license are zipped up here.


*Knuth, Donald E., The Art of Computer Programming, Volume 2: Seminumerical Algorithms, Third Edition

The Amtrak-Related Code

Here’s the post about the three programs I mentioned the other day about Amtrak timetables and on-time performance.  They’re programs I wrote mostly for myself to use, not to create pretty output, but to be quick and dirty ways to get me information for planning trips.

All are pretty clunky.  You first have to load raw data from the Web into your browser, then save the data in a file on your machine, then use that file as the input to a program that you run from a command line.

Most folks reading this blog probably aren’t programmers; so if they’re interested in this at all, they probably don’t want to have to compile the code for themselves.  I’ve compiled them for both Linux and Windows; the Linux version should run on a Mac.


The timetable generator

Before you worry about my code at all, check out Christopher Juckins’ timetables.  He has both current and historical timetables that are pretty PDF files of the sort that Amtrak used to publish and might be much more to your liking.

My code generates timetables that look like (but bigger):

29-30 timetable

or:

2150 timetable

One advantage is that you can create timetables with different trains for each leg of a round trip:

321-302 timetable

but that takes a bit more work on your part.  Also with a bit more work, you can create timetables for trains 421 & 422, the Texas Eagle through cars to Los Angeles, and for the Portland section of the Empire Builder or the Boston section of the Lake Shore Limited, where Dixieland Software doesn’t provide the raw data in a single file.

The documentation is here; the open-source code, if you want to play with it, is here.

If you want to just run the program, the two executables are here.  The file without any extension on the filename is for Linux; the one that ends in “.exe” is for Windows.  Just unzip the one that you want and stick it in some directory on your hard drive that’s in your PATH environment variable; then in the documentation, click on “Instructions for use” in the table of contents.

The raw data for this comes from Dixieland Software.  If you’re only creating one or two timetables, it’s probably easier to just type the URL in your browser; if you might want to generate timetables for lots of trains, I’ve put my little HTML form at https://www.cstdbill.com/train/atksked.html so that you can just load that once into your browser and bookmark it.  (Dixieland Software uses just HTTP, not HTTPS, but you’re not transmitting any secrets, so I wouldn’t worry about it.)


Two on-time performance analyzers

This is actually a library that generates an HTML table showing minimum, maximum, median, mean and standard deviation of late times for particular trains at particular stations, or the likelihood of making connections between two trains.  (This is what finally goosed me to write the trivial statistics library that I mentioned in the previous post.)  The two programs I’m talking about here are extra added attractions.

The documentation is here.  If you’re a programmer who wants to play with the open-source code, there’s a link to a zip archive in the introduction.

Most of the documentation is geeky programming stuff; so if you just want to run the programs, go straight to “Two Programs that Use the Library” in the table of contents.  You’ll find links to the executables there.


A simple SQL database

Here are some musings about a possible design for an Amtrak-related database.  Although this is intended for testing the database access library that I’m working on, I’ll include it here because it’s about Amtrak.

My current design is here.

If anybody can think of anything else I should add to it, I’d love to hear about it; although it’s not about making reservations and shouldn’t have any PII in it.

Also, I currently have no clue where to get the data to load the consists table.  If anybody knows where I might find that on the Web, please let me know.  If it’s a secret that you don’t want to disclose in a comment, you can contact me privately at was@pobox.com.


A Trivial Statics Library

A while back I wrote that I’d have some posts about some C++ code that I was working on, but then cancer got in the way.

I’ll begin with an open-source library of abecedarian statistics functions, just the minimum, maximum, median, mean, variance and standard deviation of data points that are strongly ordered.  I started with just standard containers of built-in numeric types, but quickly went over the top trying to make the library as generic as possible while keeping it simple for the built-in types.  I was basically just having fun with that.

[user documentationdoc., code and license]

I’ll have the next couple of weeks free, so I’ll try to get more examples ready for posting.  I’ve written:

– A program for generating Amtrak timetables.

– A program for analyzing on-time performance of Amtrak trains.

– A program for guessing the likelihood of making connections between Amtrak trains.

And in support of a database access library that I’m writing:

– An unbounded integer type.

– A big decimal type.

– A preliminary design for an SQL database of Amtrak trains to test it.

The database access library is nowhere near being ready for prime time yet, but I have some preliminary user documentation for the current design.

If there’s any interest, I might stick it all out on github Real Soon Now.

On the Cancer Front

The only chemotherapy symptoms I’ve had are hair loss, but that’s ongoing for this old fart anyway, just happening a little quicker; and constipation, but that generally clears itself up in two or three days and so is just an annoyance.  One serious side effect that had no overt symptom associated with it was a dangerously low white blood cell count resulting in an increased danger of infection.  To guard against that, starting after the second round of three days of chemo, they stuck something on my abdomen called a “Neulasta”, a small boxy thing that gives me a very slow drip of some drug that gooses my bone marrow.  Blood work shows that the white cells are under control.

My last drip in the hospital was yesterday morning; I had a couple of pills to take at home after breakfast this morning; and I took the Neulasta off at 4:00 pm today as instructed.  I am now officially done with the chemo.

The next step, which will happen on the 12th of next month, is an MRI to see whether the cancer wants to reassert itself in my brain, and a head-to-hip CT scan to look for any other occurrances.  Depending on how the scans look, it’s possible that I’ll qualify for a study of whether the usual treatment of prophylactic low-level radiation to keep the cancer out of the brain is actually as effective as some 40-year-old study suggests.  IIUC, the radiation carries with it a small but non-negligible risk of a bit of short-term memory loss.  I hope I made it clear that I’ll happily accept the small risk in exchange for the opportunity to help increase human knowledge in my small way.

The new study, IIUC, is specifically about small-cell lung cancer caught early, which is rare so that, in the earlier study, n was small, and so the data wasn’t all that good for my particular disease.  The study will be randomized but not blind, so I’ll know whether I’m in the experimental group or the control group right from the get-go.  Double-blind would be better of course; but when I asked the radiation oncologist about that, he said that there would be no “sham radiation”; and that choice of words suggested to me that there might be some ethical limitation on that.  (He didn’t say that specifically, so the “ethical” bit is just a wild guess on my part.)

I’ll be meeting with both the chemo and radiation oncologists on the day after the scans when I’ll find out whether I qualify for the study.  If I do, I will definitely sign up.  (I’m guessing that both Utilitarians and Kantian ethicists would approve of that decision, so it’s an easy one that’s not at all confusing.)

<aside>
After I got home yesterday, I took a short nap and dreamt that the chemotherapy guy asked whether I’d like to switch to his next-door neighbor who just got her “chemo license” and was looking for “nice patients” to start out with.  I sometimes flatter myself in my dreams. ๐Ÿ˜Ž
</aside>

Could Trump Be Disqualified?

I’m on an e-mail list from Robert Reich, and I got an interesting message this evening that included:

On Friday, Denver District Judge Sarah B. Wallace ruled that Donald Trump “acted with the specific intent to disrupt the Electoral College certification of President Biden’s electoral victory through unlawful means; specifically, by using unlawful force and violence.”

She concluded with this finding of fact:  “Trump incited an insurrection on January 6, 2021 and therefore ‘engaged’ in insurrection.”

Bingo.

It’s the first official legal finding that Trump participated in an insurrection.

That would normally disqualify Trump from holding any public office in the U.S. under Section 3 of the 14th Amendment; but Reich reports that Wallace performed some legal “somersaults” in order to interpret the amendment in such a way that Trump could still be on the ballot because the 14th says that it applies to those who took an oath to “support” the Constitution, but the oath that Trump took was to “preserve, protect and defend” the Constitution.  (Yes, really.)  But Reich also writes “… appellate courts do not defer to district court interpretations of law or the Constitution.”

This will certainly go all the way to SCOTUS.  Stay tuned…

Kona Trip Report day 14

[day −1]
[days 0-2]
[day 3]
[day 4]
[day 5]
[days 6-9]
[day 10]
[days 11-12]
[day 13]

2023-11-15 05:00−6:

As is often the case these days, I woke up well before the sun showed its face.  After the breakfast buffet, which was mediocre, I wrote most of the day 13 report.

10:00:

I checked out of the hotel and got a taxi to Union Station.  I gave the driver a twenty in the hope that that would make up for the short fare.  He seemed pleased with that and understood my mobility issues.  Canal Street was blocked off, so we stopped at the corner of Canal and Jackson, and the driver was happy to take my bags to the elevator down to the concourse.

I checked one bag on the Texas Eagle to St. Louis, then checked in at the Met. Lounge where I put the final touches on the day 13 report and published it.

13:15:

We started boarding train 21.  A redcap showed up right away and drove me and another couple to the gate where we had to wait about ten minutes, I guess because the crew weren’t really ready for us yet.

I had room 2 in the sleeper, a “roomette”, a pair of facing seats that convert to upper and lower berths at night.  It’s not like the roomettes of old, but more like the old ”open sections” except with walls and a door instead of curtains.

It was a pretty sorry excuse for a long distance train:  one engine unit, a sleeper, a diner/lounge, a coach-baggage, and an accessible coach.  Some of us train-riding geeks are worried that Amtrak is actually trying to discourage overnight travel so that they can discontinue the long distance trains.

13:55:

We pulled from Union Station right on time and, as expected, had some slow going on the Canadian National tracks to Joliet where it seemed to me we had a rather long dwell time; but we departed Joliet only six minutes late.

17:00:

The LSA called for passengers in the sleeper to head to the diner/lounge.  She had taken our orders for dinner earlier; and when we got to the not-a-diner, we found all the food already set out for us (and getting cold).  The food offered on the “flexible dining menu” isn’t worth talking about.

ca. 18:55:

Aside for some pretty rough track between Springfield and Carlinville, the trip from Chicago to St. Louis was largely uneventful.  We were never more than ten minutes late departing any station along the way; and thanks to schedule padding, we arrived in St. Louis early only to stop for a while just short of the station.  The conductor announced on the PA that we had to “disconnect the cars” — I guess we droped off a third coach that I hadn’t noticed and that would be added to train 22 in the morning.  They do that sometimes when they have lots of coach passengers between Chicago and St. Louis.  We made our final stop at 18:59, twelve minutes early.  We had shoved back onto the usual track, but at the far end of the platform, so passengers had quite a hike to the station.

After claiming my check bag, I still had one concern:  the credit card I had lost in Hawaiʻi was the one that I had used to get into the long term parking lot two weeks ago.  The station agent assured me that all I had to do was push the intercom button at the lot exit and somebody would “work with me” to get me out.  I was expecting to give my name and the last four digits of the card number or something like that; but as soon as I said that the card had been lost, they opened the gate and I was on my way.

As usual after returning on Amtrak after not driving for a couple of weeks or more, I drove home on city streets instead of blasting down I-55 and got home safe and sound around 20:30 or thereabouts.

Actually, “sound” might be something of an overstatement because it was a bit of a struggle to lug my luggage up from the basement (where my garage is) to my second floor apartment.  I even had to stop about half way and sit on the steps for a bit to catch my breath.  That was new to me and makes me worry about how my lungs are doing.  I’ll ask the oncologist about that on Wednesday when I finish my last chemotherapy session.  I might have to rethink my travel to Wroclaw, Poland next October or November.  We’ll see …


Follow-up, Thursday the 16th:

I went to the bank to report the lost credit card.  The agent printed out the last few weeks of transactions, and there were no bogus charges, so that’s a relief.  She cancelled that card and ordered me a new one which I should get in the mail some day between now and December 4th, at which time I’ll need to change the card I use for all of my automatic bill payments.  That’ll be a hassle; but it’s only a storage space, Verizon, and three utilities; and I have no one but myself to blame for that.

Kona Trip Report day 13

[day −1]
[days 0-2]
[day 3]
[day 4]
[day 5]
[days 6-9]
[day 10]
[days 11-12]

2023-11-14 05:00−6:

I woke up for Omaha and had the usual breakfast at 06:30.

We were right on time until Burlington, IA where we had to wait for a while.  I gathered that the station track wouldn’t be available, so we had to wait for a westbound freight to get out of the way and a switch to get lined for an adjacent track.  IIRC, the train had to make some fairly precise spots to allow passengers to get to and from the station.  I didn’t record when we finally departed Burlington because I was in the diner for an early lunch, but we were out of the next stop at Galesburg, IL four minutes early.  (The eastbound Zephyr is discharge-only from Galesburg to Chicago and so doesn’t have to wait for advertised departure times.)

There are some pictures of my room on the train below the fold if anybody is interested.

14:25:

We arrived in Chicago 25 minutes early.  One couple and I had to wait a while for a redcap to show up, but we were eventually taken to the taxi stand.

I had made a reservation at the Hilton Garden Inn that’s just across the river and a couple of blocks further from Union Station.  I had expected to be able to walk to it, but I’ve become less mobile since then and so decided to take a taxi.

The driver didn’t know the address of the hotel and had to look it up on his cell phone.  We wound up going to a different Hilton Garden Inn that was a couple of miles away, which I knew was wrong almost as soon as we left the Union Station area; but the driver insisted.  It turns out that I should have asked for the “Hilton Garden Inn Chicago Central Loop”.  Oh, well.  I’m going to have to remember to write down hotel addresses for taxi drivers in the future.  This was the second time in a single trip that a taxi driver didn’t know how to get to a hotel from its name.  (The first was from SFO to the Hyatt House Emeryville.)

We finally got to the right place.  I had planned on giving the driver a twenty dollar bill to make up for the short fare; and so that’s what he got.  He seemed satisfied with that.

After checking in, I wrote the last three blog posts; and that was it for the day.

[Read more…]

Kona Trip Report–the COVID ain’t over edition

Shortly after my most recent posting, I read a message on one of the WG21 committee’s e-mail reflectors from a fellow who had attended the Kona meeting and thereafter tested positive for COVID.  Several of us thanked the writer for the warning; and several replied that they, too, have tested positive.

I successfully resisted the urge to say, “Told ya so!”; but I did add to my own reply:

There’s a big box hardware store (Home Depot) near me that sells N95s as protection against small airborne particles created when doing fine sanding or grinding.  You might find a place like that near you where you can buy good masks at reasonable prices.  I’m told that N95s are pretty good at protecting me from others, and very good at protecting others from me. ๐Ÿ˜Ž

I also resisted the urge to finish with something like, “That last bit is what the Ayn Randians don’t get.”

Kona Trip Report days 11-12

[day −1]
[days 0-2]
[day 3]
[day 4]
[day 5]
[days 6-9]
[day 10]

Today begins my trip home on Amtrak’s California Zephyr to Chicago, then the Texas Eagle to St. Louis.

2023-11-12 06:00−8:

I woke up after a really good sleep and had plenty of time to repack from flying to riding on a train:  basically just moving all the stuff that might have frightened the TSA folks — my scanner, a couple of power strips, various cables — from my checked bag to my carryon.

08:30:

After breakfast, I checked out of the hotel and walked the roughly two city blocks, mostly through a parking lot, to the pedestrian walkway over the tracks at the Amtrak station.  The elevators on both sides worked. ๐Ÿ˜Ž

When I got to the station, I found out that a BNSF train had several tank cars on the ground at Pinecliffe, CO blocking the Moffat Tunnel, and so my train would be bustituted* from Grand Junction to Denver.  That’s the really scenic part of the trip where I might have taken some pretty pictures.  The trip over the Sierra Nevada is scenic, too; but there are no stops where one can get off the train for a bit; and I couldn’t get any decent shots from the window of a moving train.

09:38:

We departed Emeryville about a quarter of an hour late but had picked up about half of that time by Roseville where I went to lunch in the diner.

They’re now letting coach passengers in the diner.  For a while after returning to “traditional dining”** on several of the western long-distance trains, the diner was for passengers in the sleepers only.  Passengers with coach tickets had to subsist with stuff from the snack bar on the lower level of the lounge car.

Shortly after Roseville, we stopped for quite a while.  I have no clue why, and there was no announcement on the PA explaining what the delay was all about.  We were about three quarters of an hour late out of Colfax.

I had dinner in the diner shortly after Reno and had the steak.  I had ordered it medium but got it rare.

We picked up a bit of time and were only about twenty minutes late out of Winnemucca where I went to bed.


2023-11-13 04:45−7:

I woke up in time for arrival in Salt Lake City which we departed just after 05:00, an hour and a half late.

The diner opened for breakfast at 06:30.  I had the french toast and pork sausage which was quite good.

We arrived in Grand Junction about 1:45 late, but ran right through it.  The plan was to wye the train east of the station to turn it to be train 5, the westbound Zephyr, and let the passengers off after that.  While wyeing the train, we had to stop and wait a while for each switch to be lined properly, as if nobody could anticipate that lining the switches would be required.  Go figure.  (That was Union Pacific’s silliness, not Amtrak’s.)

The diner had an early lunch for sleeper passengers only.  The coach passengers got box lunches that they could eat on the bus to Denver.

There were three busses, at least two of which went straight to Denver.  I guess one of them was for passengers bound for Glenwood Springs, Granby, and Fraser.

The bus ride on Interstate 70 was tedious but only lasted for about four and a half hours.  I did get a nice view in Glenwood Canyon of the track on the other bank of the Colorado River where I would have preferred to be. ๐Ÿ˜Ž

On arrival in Denver, a redcap drove me and some others straight to our sleeper cars and handled all the baggage for us.

This train, which had turned from train 5 earlier in the day, had the same crew that I’d had on my westbound trip a week earlier.  My TA, O. C. Smith, was very friendly and helpful; but he was looking forward to calling it quits.  This would be his antepenultimate trip before retiring.

The diner was open and serving dinner when we got to the train.  I had the pasta with the “plant-based meat sauce”, which was actually quite good; but I wasn’t really hungry and couldn’t finish it.

We departed Denver right on time; and I went to bed shortly after the first stop at Fort Morgan about quarter to nine.


*“Bustituted” is a term that some of us regular Amtrak riders use to mean that a bus is being used as a substitute for a train.  In my roughly three decades of riding Amtrak trains, I’ve been bustituted only twice before:  once from Seattle to Spokane where train 7 had turned to train 8 because 7 had gotten caught in a blizzard; and once from Pittsburgh to D.C. on what should have been the Capitol Limited, I don’t remember why.

**What Amtrak is advertising as “traditional dining” is nothing of the sort.  I can remember when at least four service attendants (SAs) would be waiting the tables along with the dining car steward, and there’d be a cook or two and a dishwasher downstairs (on double-decker Superliner diners) preparing freshly cooked food served on real, if thin, china.  These days, it’s a lead service attendant (LSA) and one SA waiting tables, and one cook preparing what, at least, isn’t the prepackaged, microwaved stuff that you still get on all the eastern trains, the Texas Eagle, and AFAIK the City of New Orleans.