Sunday, September 30, 2018

Driving in New Zealand

My wife and I recently traveled to New Zealand. It had been a bucket list place to visit. We had a great time visiting the Coromandel Peninsula and greater Rotorua on the North Island.

New Zealand is a country where you drive on the left. Nothing new here. The national speed limit is 100 kph, unless otherwise posted, which is a lot, mainly for towns, but also during construction.

The unusual driving item are the rural one lane bridges. A sign as you approach indicates which travel direction has the right-of-way. Sometimes it is a challenge to see to the end of the bridge to see if anyone is coming. Didn't meet anyone on the middle of a bridge, but I'm sure it happens.

Details from New Zealand government are here.

When using a navigation system in New Zealand the estimated travel time requires adjustment, especially on rural roads and unsealed roads. [Unsealed road means dirt roads where I come from.] As stated, the national speed limit is 100 kph. If the distance to travel is 50 kilometers, the navigation system will report a time of 30 minutes. Not!

The rural roads in New Zealand can be twisty and hilly. The speed at turns can drop to 55 kph, then 45 kph, even 25 kph. Even if the navigation system knows the speed and distance of turns, it assumes you can go 100 kph between them. This is not possible. Add 25-50% to the estimated time and "She'll be right."

Thursday, July 19, 2018

Primes and Sines

Primes and Sines

Prime numbers are a fascinating set of numbers. A prime is a number divisible by only one and itself. 11 is prime. 6 is not prime.

Primes are a subset of the counting numbers, 1, 2, 3, 4,...  Prime numbers are never negative. The first few primes are 2,3,5,7,11.

1 is not considered a prime. 2 is sometimes not considered a prime. Math papers on primes might start 'Consider the set of primes starting at 3...'.

When a number is not prime it has a list of prime factors. This is part of the Fundamental Theorem of Arthimetic. The non-prime number is created by multiplying all the prime factors together. A prime factor may repeat. 18 has 2, 3, and 3 as prime factors (2*3*3=18).

Any even number is a multiple of 2. All primes numbers are odd, except 2. This is why 2 is sometimes left off the list of primes numbers.


To determine if a number, N, is prime, a simple sequence of steps can be followed.

1 - Find the list of all primes less than the square root of the number N.

2 - For each prime, p[i], in the list of primes, N/p[i].
2a - If there is no remainder from the division of any p[i], then N is not prime.

Given 21, the square root of 21 is 4. The list of prime numbers less than or equal to 4 is 2 and 3. 21/2 = 10, with 1 remainder. 21/3 = 7, with no remainder. 21 is not prime.

To create a list of primes, one follows a sequence called a prime number sieve.

First select a maximum number to be examined, say 1000.

2 is given as a prime (or ignored).

Create a list of 1000 numbers, mark all numbers as prime.

Starting with 3, add 3 to 3. In the list, at 6, mark 6 as not prime. Continue adding 3 to obtain the next multiple of 3 marking that entry in the list as not prime until the maximum number is reached, 1000.

Repeat for all odd numbers.

Examine each odd number in the list. Those entries still marked prime is the list of prime numbers less than 1000.

This is prime number sieve is very easy to write in computer code. There are various methods of optimizing the method. One such method is found in GMP. The GMP prime number sieve finds all the primes in the first ten million digits is much less than one second (running on a recent laptop).

The basic process is 1) create a list, assume a numbers are prime, 2) mark those numbers not prime, 3) examine the resulting list looking for prime numbers.

Sines

A sine wave is a periodic wave. It repeats as much as desired.

y = sin(x) [1]

generates a periodic wave, starting at 0,0, with four points being (π/2, 1), (π, 0), (3π/2, -1) and (2π, 0). The sine wave cross y=0 at π intervals.

y = sin(x)

If the equation is changed to

y = sin(π/2 * x)  [2]

Equation [2], starting at 0,0 has the following four points (1,1), (2,0), (3,-1), (4,0).

y = sin(π/2 * x)

For equation [2] the value of y is 0 at every multiple of 2. Equation [2] can be viewed as marking all those numbers that are multiples of 2 and thus not prime.

y = sin(π/3 * x)  [3]

y = sin(π/3 * x)
For equation [3] the value of y is 0 at every multiple of 3. Again all those numbers that are multiples of three have y=0 and visually mark the number as not prime.

Now if equations [2] and [3] are shown together.
y = sin(π/2 * x) and y = sin(π/3 * x)

Any odd number not crossed by equation [2] or [3] is prime. 5, 7, and 11 are the next 3 prime numbers.

Any point where y=0 for either equation [2] or [3] represents a number that is not prime.

This is true for all primes up to 24. Why 24?

Any odd number less than 24 has at least 2 or 3 as a prime factor. 25 is the first number without 2 or 3 as prime number, 5 * 5.

The list of prime numbers after 3 and before 24 is 5, 7, 11, 13, 17, 19, and 23. Using just 2 prime numbers we find an additional 7 prime numbers.

y = sin(π/2 * x) and y = sin(π/3 * x)

If we add a new equation

y = sin(π/5 * x)  [4]

y = sin(π/2 * x), y = sin(π/3 * x), and y = sin(π/5 * x)

It is a bit more difficult to see those numbers that are prime. 29, 31, 37, etc. are prime.

This is a graphical representation of the prime number sieve.

Take the absolute value of [2].

y = | sin(π/2 * x) |  [5]



y = | sin(π/2 * x) | 

Repeat this process for equations [3] and [4].

y = | sin(π/3 * x) |  [6]
y = | sin(π/4 * x) |  [7]

Combine [5], [6], and [7].

y = | sin(π/2 * x) | , y = | sin(π/3 * x) | , and y = | sin(π/5 * x) | 

The numbers that are prime are now much easier to identify. The prime numbers are where the three equations lack a y=0 point.

Using [5], [6], and [7] will find the prime numbers up to 48, as 49 is 7*7. The first number without 2, 3, or 5 as a factor. The remaining primes are 7,11,13,17,19,23,29,31,37,41,43,47. With just 3 primes 12 additional primes are found.

This visualization of the prime number sieve uncovered an algorithm that seems more pleasing that the standard prime number sieve, at least to this author.


Modulo

The sine graphs are visual, but not practical. The curves are continuous. Only the values at odd numbers need to be calculated, but trigonometric functions are expensive to calculate.

It is only required to know if the sine curve is zero or not zero at the point N.

A way of determining if a number is prime is to use the same prime number list, but use modulo arithmetic instead of sines.

Modulo arithmetic was shown above for the number 21.

If a number, N, has a prime sine curve, p, passing through it (y=0) then the modulo of N of p is zero stating that N is not prime.

Given a list of primes, whose largest prime is P, for all odd numbers N from P+2 to (P+2)(P+2)-1, perform modulo arithmetic on N using the list of primes. If all modulo results are non-zero, the number is prime. Testing N can stop when one modulo result is zero.

The graphs above were created using Desmos. The link to the Desmos page with the graphs is here.

Modulo code is found on GitHub.


Saturday, April 28, 2018

Software, Insurance, and Underwriter's Laboratory

Jack Ganssle wrote this article entitled 'Fire Code for Software'.

http://www.ganssle.com/articles/FireCode.htm

"Fire code for Software?" is essentially saying why hasn't the software industry developed an Underwriter's Laboratory or an Insurance Institute for Highway Safety for software?

Both UL and IIHS are products of the insurance companies desire to improve human safety, lower claims, and manage insurance costs. UL has been around since 1894. Software has only be around for 50 or so years and only in the last 20 or so years has software been 'mainstream'.

Currently software is not insured. Problems with software are resolved after the fact, usually by litigation.

Regulators, such as the FDA, monitor software for medical devices. The NTSB can audit software when a 'recall' event occurs involving vehicle (car, train, plane) software. Several companies have gone bankrupt because of software mistakes that killed people, Therac-25, for example.

Self-driving cars may push the issue of software testing for insurance reasons.

When the cost of software mistakes are born by someone other than the software builder and the customer, this is insurance, and the insurance companies will protect their interests.

Friday, January 26, 2018

Speculations of an Autonomous Vehicle World

Autonomous vehicles are just around the corner. Tesla has semi-autonomous vehicles for sale today. Waymo, Google, and Uber are all working on fully autonomous vehicles. Delphi, a supplier of auto parts, is selling the sensors necessary for autonomous vehicles to know about their environment.

What will happen to society, jobs, work, travel, and the environment as the autonomous vehicle becomes the norm? This is a speculation on a new world with autonomous vehicles.

In the beginning of the autonomous vehicle world only those early adopters will experience a new life style. Sitting in an autonomous vehicle will be like being in an airplane on the ground. The passenger doesn't care where the vehicle is going, just the vehicle gets to the destination safely and on time.

The world will not have 100% autonomous vehicles soon. It will start slow and build. As it builds, changes will occur in transportation, jobs, and leisure.

The first adoption of autonomous vehicles will be where the most savings of money and labor can be realized.  There will also be adoption by those that can afford new technology, but that will be as a status symbol, a toy. The initial commercial impact will be in long haul trucks, street sweepers, garbage trucks, snowplows, delivery vehicles, pizza delivery, and package delivery.

Already long haul trucks have been driven coast to coast autonomously. [ref] Volvo is advertising a self driving garbage truck. Self driving street sweeper is a direct spin off. Snowplows may be more difficult given the size of the blade and parked cars, but on limited access highways a distinct possibility. Pizza delivery can be by drone, but can also be done by small, go cart like vehicles. Punch in a code to unlock door when vehicle arrives. UPS is looking at deploying autonomous carts from a vehicle to deliver more than one package at a time in a limited area. The UPS truck could drive itself to the deployment location.

Those that drive trucks, short haul and long haul, delivery trucks, garbage trucks, street sweepers, snow plows, or other municipal vehicles will be the first to feel the job stress from autonomous vehicles. Drivers of taxis and buses will be affected as well.

Cities and towns will definitely do a cost analysis of employing autonomous vehicles to reduce costs. When current vehicles have reached their useful life, autonomous vehicles will be available for purchase. Unions will push back. It may take decades to change the union contracts or wait for existing employees to retire. Removing the toll booth operators around NYC was technically feasible when the first FastPass was installed. It wasn't until 2017 that all human operator toll booths were removed.

When an autonomous delivery vehicle arrives with goods for a customer, does the customer unload the vehicle? Does the vehicle unload itself? Is there still a person with the delivery vehicle to unload the goods?

Vacation travel will change. RVs will now be a living room on wheels. One will get to a destination in half the time. The vehicle drives 24 hours a day. Fueling a vehicle will need some thought. A robot gas station perhaps? How will humans tell the autonomous vehicle to pull over for a bathroom break or stop for lunch? Yes, RVs and buses have toilets, but not sedans.

How many less cars will on the road? Will there be less congestion? Will autonomous vehicles drive better resulting in less rush hour delays?

Who will benefit? Fleet owners of autonomous vehicles, body shops that customize interiors, software programmers, advanced auto mechanics, and training schools.

Who will lose? Truck drivers, taxi cab drivers, delivery drivers, public works employees, parking lot owners, parking lot attendees, automobile assembly line workers, car dealerships, auto mechanics, the Teamsters Union. Municipalities will have less revenue because there will be less cars to tax, less parking, so less parking meter fees. The parking meter fees represent a significant percentage of some cities revenues. A law was proposed in Massachusetts that will tax autonomous vehicles for 'cruising' around without parking. The law essentially taxes the vehicle at different rates, with passengers, without passengers, etc. This is an attempt to recapture the lost taxes from less cars.

Ford, GM, and others are looking into subscription service for vehicles, not ownership. Cadillacs are already offers normal cars on a subscription basis. Subscription service is going to be required by the auto manufacturers to make up for lost revenue as the number of cars required drops, by some estimates as much as 75%. [ref].

Everyone will pay a monthly fee to be able to 'hail' an autonomous vehicle. What sort of premium services will be available? Will there be 'congestion' pricing, 'time of day' pricing?

Enter into your 'hail a ride' app how far you want to walk from your home, how far to want to walk to work, when you want to leave and arrive at your destination. A vehicle shows up as requested. It may have no passengers, it may be a van pool, it may be a bus. It all depends on your choices and level of service.

Will there be a bus as we know it? Buses run on fixed routes at fixed times to be predictable. It is used, mainly, by those that don't have vehicles today. Buses won't have to run on fixed routes, if they are autonomous. There may be fixed pick up and drop off points, but the buses don't have to follow a fixed route to get to each point. Either a kiosk or a phone app will be used to say which destination you want to go to and from which location you want to be picked up. Routes will be created dynamically based on the real time demand. Less total buses will be needed and can run 24 hours a day.

The displacement of workers due to work sent overseas took decades and affected mainly manufacturing. Autonomous vehicles will affect the entire transportation infrastructure and all the people that work in it and will be rolled out in less than a decade.

Houses will be built without garages. Housing density go up as off street parking will not be required. What other planning and zoning changes will occur? Will there be a surge in customization of vehicles? Boutique fleet owners will provide unusual, exotic rides for special occasions. The living room sofa ride will now be a reality. Will traveling in luxury take on a new meaning? A TV, Internet, lounger, mini-bar, microwave, refrigerator are all items that can be found in a vehicle today. What will be found in the luxury autonomous car of tomorrow? Multiple day rides in an autonomous vehicles will include a bed. Autonomous vehicles may be fueled or charged while they roll, just like midair refueling of military aircraft. Definitely a time saver.

Will there be an entire generation that doesn't know how to drive? The department of motor vehicles will have less cars to register. You will go to DMV to get a state identification card, not a driver's license.

The autonomous vehicle will be a boon to those who are blind and handicapped, or those who cannot drive for some reason. The mobility of seniors will greatly increase.

The challenges today for autonomous vehicles is snow obscures visibility, snow covers the painted lines. Heavy rain and glare are also an issue. Northern climate residents may see a slower roll out of the autonomous vehicle.

The autonomous vehicle will be assisted by other vehicles and by road side devices to help with navigation. Auto manufactures are designing the communication and devices for a smart highway. The smart highway will help to define the autonomous experience. States may have to do a better job with road line painting for the autonomous vehicle fleet. What happens after a road is paved? There are no lines on the road immediately after paving. Will line painting be autonomous too?

What about computer hacking? Vehicles have already been shown to be hackable. Will a terrorist be able to cause death and mayhem on the road?

What about the classic car owners? How will older cars fit into the world of autonomous vehicles? Will they have to be fitted with special sensors?

The decrease in the number of cars will free up resources for other purposes. Commodity prices will fall as demand for iron and copper to build cars go down. Yes, there will be less cars on the road, but will there be more or less miles traveled? Ride sharing would decrease traveled miles, but those that didn't drive will be more mobile. Does oil demand go down or up?

How will criminals use autonomous vehicles?

The Chinese character for crisis, 危機, combines glyphs from danger, 危險, and opportunity, 機會. The world of autonomous vehicles will be different than today, danger for those supporting the non-autonomous world and opportunity for those that embrace the autonomous world. Will there be room for everyone?