I was at a friend's house for dinner and they suggested the idea of a "Prime-factor vector space". In this space the positive integers are expressed as a vector such that the nth element in the vector is the number of times the nth prime divides the number. (Note that this means that our vectors have an infinite number of terms.) For example 20 is
2 0 1 0 0 0 ...
Because its prime factorization is 2 * 2 * 5.
Since prime factorization is unique each number corresponds to one vector.
We can add vectors by pairwise adding their entries. This is the same as multiplying the numbers they are associated with. We can also do scalar multiplication, which is akin to raising the associated number to a power.
The problem is that this space is not in fact a vector space because there are no inverses. If we go ahead and add the inverses and close the vector space we now have a way of expressing every positive rational number as a vector. If we keep the fact that vector addition represents multiplication. Then the inverse of a natural number is its reciprocal.
For example the number 20 had the vector
2 0 1 0 0 0 ...
So the fraction 1/20 is its inverse
-2 0 -1 0 0 0 ...
If we wanted to find the vector associated with a fraction like 14/15 we would find 14
1 0 0 1 0 0 ...
and 1/15
0 -1 -1 0 0 0 ...
and multiply them by performing vector addition
1 -1 -1 1 0 0 ...
Now that we have a vector space we can modify it to form an inner product space by giving it an inner product. To do this we steal the inner product that vector spaces are given classically. The inner product of two vectors is defined as the sum of the pairwise multiplication of their terms. For example 20 · 14/15 would be calculated as follows
20 = 2 0 1 0 0 0 ...
14/15 = 1 -1 -1 1 0 0 ...
2 0 -1 0 0 0 ... -> 1
As another example the product 2/19 · 4/19
2/19 = 1 0 0 0 0 0 0 -1 0 0 0 ...
4/19 = 2 0 0 0 0 0 0 -1 0 0 0 ...
2 0 0 0 0 0 0 1 0 0 0 ... -> 3
Your task is to implement a program that performs this dot product. It should take two positive rational numbers via either a pair of positive integers (numerator and denominator) or a rational type (floats are not allowed, because they cause problems with precision and divisibility) and should output a integer representing the dot product of the two inputs.
This is code-golf so answers will be scored in bytes with fewer bytes being better.
Test Cases
4 · 4 = 4
8 · 8 = 9
10 · 10 = 2
12 · 12 = 5
4 · 1/4 = -4
20 · 14/15 = 1
2/19 · 4/19 = 3