Tick marks on graphs

When you view the graph of a real-valued function of a real variable, you will view both major and minor tick marks on the axes. The major tick marks are associated with numbers, while minor tick marks are smaller and size and not associated with explicit values.

Now, it is reasonably straight-forward for a human to look at an axis and determine appropriate major and minor tick marks. For example, if asked to create major and minor tick marks for the interval $[1.12, 2.16]$, $[0.646, 1.729]$ and $[-11.36, 35.91]$, one may come up with the following solutions:

Algorithm X.1: Finding tick marks

Input: an interval $[a, b]$
Output: four or five points.

Come up with an algorithm that takes two end points of an interval $[a, b]$ and comes up with either four or five major tick marks with three or four minor tick marks between. You cannot expand or contract the interval. You may use the base-10 logarithm (or common logarithm) in your algorithm.

Your solution should, for example, be two lists:

$1.2, 1.4, 1.6, 1.8, 2.0$
$1.15, 1.25, 1.3, 1.35, 1.45, \ldots, 1.95, 2.05, 2.1, 2.15$

You may use the standard arithmetic operations as well as the floor and ceiling functions. Recall that the floor of a real number is the largest integer less than or equal to that real number, and the ceiling of a real number is the smallest integer greater than or equal to that real number.

Note, there is no perfect solution; however, some criteria that may be used to compare and contrast different solutions include that the numeric values of the tick marks should not have repeating decimal expansions and the fewer significant digits that appear in the numeric values associated with the tick marks, the better. For example, in the example above, a second solution for tick marks on the interval $[0.646, 1.729]$ could be found:

Indeed, this second solution may be slightly more pleasing than the first.

Algorithm X.2: Finding major and minor tick marks

Input: an interval $[a, b]$
Output: four or five major tick marks to be numbered, a list of major tick marks not to be numbered, and a list of minor tick marks.

You may only want four or five numbers appearing on the axis, but if you look at the solution for $[1.12, 2.16]$ and the second solution for $[0.646, 1.729]$, you will note that the values of the minor tick marks are $1.25$, $1.3$ and $1.35$ in the first case, and $0.85$, $0.9$ and $0.95$. It would make sense to have the tick marks $1.3$ and $0.9$, respectively, to have the same height as the major tick marks, just not numbered.

Thus, devise an algorithm that provides either two or three lists:

  • a list of numbered major tick marks,
  • a list of unnumbered major tick marks, and
  • a list of minor tick marks, and