[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

685.0. "How many colors, ignoring intensity?" by CLT::GILBERT (eager like a child) Sun Mar 29 1987 16:05

Suppose you have a color graphics terminal using the standard RBG pixel
idea.  The color of each pixel is determined by setting the three colors
red, blue and green to a value from 0 to n.  Ignoring intensity how many
different colors are there?  Note that 10,10,10 is the same color as
20,20,20 just dimmer.

Here, it may be best to ignore (0,0,0) as a color.  Letting P(n) be the
number of different colors, we see that

	P(1) = 2^3 - 1 = 7
		(all 2^3 possibilities except (0,0,0))

	P(2) = 3^3 - 1 - P(1) = 19
		(we drop (0,0,0), and the triples that can be divided
		 by 2, of which there are P(1))

	P(3) = 4^3 - 1 - P(1) - P(1) = 49
		(P(1) are multiples of 2, and P(1) are multiples of 3)


This problem is making the rounds on the usenet, and is attributed to
Mark Biggar ([email protected]).
T.RTitleUserPersonal
Name
DateLines
685.1more definition neededVIDEO::OSMANtype video::user$7:[osman]eric.sixMon Mar 30 1987 17:2525
    I think more definition is needed.
    
    Suppose (2,4,6) is a color.  Is this the same color as ADDING a
    constant to each, i.e. (7,9,11) ?  Or must we multiply, for
    instance (10,20,30) ?
    
    And why did you suggest omitting (0,0,0) ?  Perhaps we should
    omit (0,0,1) too ?  What's the rule here ?
    
    Also, I'm having trouble seeing why you calculate P(2) by subtracting
    P(1) from it.  What does that have to do with anything ?
    
    I'd count P(2) as

    000,001,002,010,011,012,020,021,022,100,101,102,110,111,112,120,121,122,
    200,201,202,210,211,212,220,221,222.
    
    Then, I would think 111 and 222 are "the same" because they both
    represent even RBG's.  So, 000 is probably the same too, although
    that gets a bit philisophical, since it's black.  (kind of like,
    when bear shits in woods with no one else there, does it stink?)
    
    I'm not sure I could eliminate anything else though.
    
    /Eric
685.2BEING::POSTPISCHILAlways mount a scratch monkey.Mon Mar 30 1987 17:5114
    Re .1:
    
    Two colors, a and b, are the same iff a = kb or ka = b for some k.
    
    Here, the individual components of the triple tell how much red light,
    green light, or blue light to emit.  Changing the intensity of the
    light ("multiplying the triple by a number") changes only the total
    amount of light emitted and not the proportions of it.  So (2,2,2) is
    the same _color_ as (1,1,1), although they are different intensities of
    that color, and (0,0,0) is, in a degenerate sense, the same color.  And
    (2,2,0) is the same as (1,1,0). 
    
    
    				-- edp 
685.3CLT::GILBERTeager like a childMon Mar 30 1987 18:0123
    The colors (a,b,c) and (k*a,k*b,k*c) are considered the same,
    for k > 1.  If k = 1, they *are* the same.

    I'd count P(2) as

        001,    010,011,012,    021,    
    100,101,102,110,111,112,120,121,122,
        201,    210,211,212,    221.

    so P(2) = 19.

    I'd count P(3) as

        001,        010,011,012,013,    021,    023,    031,032,   
    100,101,102,103,110,111,112,113,120,121,122,123,130,131,132,133,
        201,    203,210,211,212,213,    221,    223,230,231,232,233,
        301,302,    310,311,312,313,320,321,322,323,    331,332.   

    so P(3) = 49.

>   And why did you suggest omitting (0,0,0) ?

    Because it makes the above 'chart' for P(2) look symmetric.
685.4GCDTAV02::NITSANDuvdevani, DEC IsraelTue Mar 31 1987 08:5215
If you forget the "0" for a moment, then you are looking for all (x,y,z)
such that gcd(x,y,z) = 1. There is a total of 10^3 (x,y,z)'s. From this
you have to subtract:
 * The amount of (x,y,z)'s such that gcd(x,y,z)=2
 * The amount of (x,y,z)'s such that gcd(x,y,z)=3
 * The amount of (x,y,z)'s such that gcd(x,y,z)=4
 * The amount of (x,y,z)'s such that gcd(x,y,z)=5
    .  .  .
Each line by itself is easier to figure out - only beware of not subtracting
the same thing twice (for example, the "=2" and the "=4" triplets).

As for the "0", for (x,y,0) it's the same story, only with gcd(x,y) and so on.

Note: this is not a complete solution - just an idea.
Nitsan
685.5CLT::GILBERTeager like a childWed Apr 01 1987 12:3296
Let's look at this algorithmically.

    For n <- 1 to 100 do

	! Determine the number T of triples (x,y,z) with 0 <= x,y,z <= n
	! such that gcd(x,y,z) = 1, and (x,y,z) not equal to (0,0,0).

	T <- (n+1)**3 - 1		! This is our initial estimate

	For m <- 2 to n do

	    ! Subtract triples that have gcd(x,y,z) = m

	    ! Consider the prime factorization of m.

	    ! Have we already subtracted the triples with gcd(x,y,z) = m?
	    ! We have, only if the exponents in the factorization all equal 1.

	    If m is square-free
	    Then
		! We've already subtracted these triples

	    ! Perhaps we've subtracted these more than once already.
	    ! This can happen, for example, if m = 10 -- we subtracted
	    ! these once for gcd(x,y,z) = 2, and once for gcd(x,y,z) = 5.

	    Else
		T <- T + ( [n/m]**3 - 1 ) * d(m) 	! [x] is the floor of x
		! where d(m) = 1 - 2*(k mod 2), and m has k prime factors

To show that this is correct, we'd like to show that triples with
gcd(x,y,z) = m are subtracted from T exactly once.  Redefining d(m)
slightly, let

		-1 if m is square-free with an odd number of prime factors
	d(m) =   0 if m is not square-free
		+1 if m is square-free with an even number of prime factors
		      (thus d(1) = +1)

We need to show that

	Sum d(r) = 0

where the sum is over all (possibly non-prime) factors of m, including 1 and m.
(note that we chose to include d(1) = 1 in this summation -- that's why the
sum is not -1).

          q1    q2          qk
Letting p1  * p2  * ... * pk   be the prime factorization of m, this sum is:

	        i1    i2          ik
	Sum d(p1  * p2  * ... * pk  )
	0 <= i1 <= q1
	0 <= i2 <= q2
	    ...
	0 <= ik <= qk

But d(...) is zero if any of the exponents is 2 or greater.  So the sum is:

	        i1    i2          ik
	Sum d(p1  * p2  * ... * pk  )
	0 <= i1 <= 1
	0 <= i2 <= 1
	    ...
	0 <= ik <= 1

This is clearly true for k = 1, since d(1) + d(p1) = +1 + -1 = 0.  Note
that by our definition, d(...) only depends on the parity of i1+i2+...+ik.
So the sum equals

	    Sum      e(i1+i2+...+ik)
	0 <= i1 <= 1
	0 <= i2 <= 1
	    ...
	0 <= ik <= 1

where e(s) = 1 if s is even, and e(s) = -1 if s is odd.

                    a!{Letting C(a,b) = --------, we see that there are C(k,s) elements in the above
                 b!(a-b)!
sum having i1+i2+...+ik = s.  Thus, we can rewrite the sum as:

	Sum C(k,s) * e(s) = Sum C(k,s) * (-1)^s
	0 <= s <= k         0 <= s <= k

A simple application of the binomial theorem shows the sum does indeed equal 0.

In summary,
	        n
	T(n) = Sum ( [n/m]**3 - 1 ) * d(m)
	       m=1
where
		-1 if m is square-free with an odd number of prime factors
	d(m) =   0 if m is not square-free
		+1 if m is square-free with an even number of prime factors
		      (thus d(1) = +1)
685.6Colors in the real worldDENTON::AMARTINAlan H. MartinThu Apr 02 1987 19:098
Folks may find the discussion of colors, color systems and color
VAXstations in topic 854 of BULOVA::VWS (q.v.) of interest.

Note also, that while the stated problem is of mathematical interest,
it is not a good model of the real world.  I can assure you that the
RGB settings 10/20/40 and 20/40/80 are quite distinct colors, at least
on my VAXstation.
				/AHM
685.7CLT::GILBERTeager like a childThu Apr 02 1987 22:451
    Is there some better way to evaluate the T(n) given in 685.5?
685.8CLT::GILBERTeager like a childSun Apr 12 1987 12:525
I noticed a problem with a noisy line in 685.5.  By the bottom, it should read:

		    a!
Letting C(a,b) = --------, we see that there are C(k,s) elements in the above
                 b!(a-b)!
685.9CLT::GILBERTeager like a childTue May 05 1987 01:191
    The d(m) in .5 is often called mu(m).