Is there an "easy" formula for calculating the species and quality of the musical interval between two notes? Let's number the scale steps of the major scale $1,2,\ldots 7$, i.e., label them from the tonic upward mod $7$ and then add $1$. With that numbering scheme, let the lowest note of a given diatonic interval be $x$ and the highest note $y$. 
Is there an "easy" or at least "manageable" formula/algorithm for the function $I(x,y)$, where $I$ takes values $1,2,\ldots,7$ according as the interval between $x$ and $y$ is a unison, second, third, etc.?
For example, $I(6,4)=6$. 
As a further question, could we then modify the formula for $I(x,y)$ into one for $J(x,y)$, where $J(x,y)=(I(x,y),Q)$, with $Q$ the quality (major, minor, perfect, augmented, diminished) of the interval according to some convenient numerical labeling? 
 A: For the intervals part, I think that by definition the number-name of the interval is simply the distance, the difference $\;y-x\;$, between scale steps $\;x\;$ and $\;y\;$.
Only with two complications: Intervals are numbered starting from $1$, not $0$; and sometimes one doesn't want to distinguish between a sixth, a 13th, or an inverted third.
That leads to the $\;+1\;$ and the $\;\text{ mod }7\;$ in the formula from the earlier answer $$
I(x,y) \;=\; (y-x)\text{ mod }7 + 1
$$
Now for the quality, I have found the following.
First, we calculate the number of fifths in the interval, which is $\;F(y) - F(x)\;$, where $$
F(x) = 2m - \left\lfloor (m+4)/7 \right\rfloor\times7 - \left\lfloor m/7 \right\rfloor\times7 \text{, where } m = x-1
$$ is the number of fifths (modulo octaves) from the tonic to $\;x\;$. (Note that $\;\left\lfloor \dots/7 \right\rfloor\times7\;$ rounds down to the nearest multiple of $7$.)
Then the quality is $$
Q(x,y) = h(k) - h(-k) \text{,}
\\
\text{where } k = F(y) - F(x)
\\
\text{ and } h(k) = \max(0, \left\lfloor (k+8)/7 \right\rfloor)
$$ where the quality is encoded as




Q(x,y)
quality name




...
...


$-3$
doubly diminished


$-2$
diminished


$-1$
minor


$ 0$
perfect


$ 1$
major


$ 2$
augmented


$ 3$
doubly augmented


...
...




There is more behind this, but I cannot expand on that now.  For now, suffice it to say that $\;h(k)\;$ indicates how 'major' the $\;k\;$-fifths interval is; and a perfect interval is, in some sense, one that is both major and minor.
A: Although you don't say explicitly what $\ I(x,y)\ $ means when $\ x>y\ $(i.e. the index of the lower note is greater than the index of the higher note) , I assume from your example that it is the degree of the interval from the note represented by $\ x\ $ to the one an octave higher than that represented by $\ y\ $. In that case, if
$$
I(x,y)\stackrel{\text{def}}{=} y-x\hspace{-0.5em} \pmod{7}+1
$$
then the interval between $\ x\ $ and $\ y\ $ will be a unison if $\ I(x,y)=1\ $, and an $\ n$-th if  $\ I(x,y)=n\ $ with $\ n=2,3,\dots,7\ $.
For the qualities, I doubt if there's any simpler way to represent them than in a table something like the following:
$$
\begin{matrix}
\,_{\large x}\backslash^{\large y}&1&2&3&4&5&6&7\\
1&u&2&3&p4&p5&6&7\\
2&m7&u&2&m3&p4&p5&6\\
3&m6&m7&u&m2&m3&p4&p5\\
4&p5&6&7&u&2&3&a4\\
5&p4&p5&6&m7&u&2&3\\
6&m3&p4&p5&m6&m7&u&2\\
7&m2&m3&p4&d5&m6&m7&u
\end{matrix}
$$
in which the numbers unaccompanied by a letter represent major intervals. While you could no doubt concoct some sort of numerical formula to represent the same information that's contained in this table, I doubt if it could be made any more succinct.
A: (For the record, total musical noob also trying to make convinient formulas to avoid remembering stuff - this is for intervals within an octave)
(given x is the lower/root pitch note wise, regardlesss of letter)
Example:
f(x,y) = 
    if Y>X
        return dist(X,Y) + 1 # +1 is to handle starting at 1 (A=1)
    else 
        return 8 - dist(X,Y)

    f(C,F) -> Y>X -> dist(X,Y) + 1-> Y - X + 1 -> 6-3+1 = 4th Interval
    f(F,C) -> X>Y -> 8 - dist(X,Y) -> 8 - (6-3) -> 8 - 3 -> 5th interval

    If Y>X but x is of lower letters, say A-D you can use 

    f(B,G) --> (A = B - 1 -> G - 1 = 6th, less hassle)
    Any bigger X just count it, its max 3 steps if Y>X    
    

    
    **Note sum is always 9 together.** 

For X>Y,
We can internalize this table to calculate more easly:




dist(x,y) + 1
Quantity




2
7


3
6


4
5


5
4


6
2


7
2





*

*2<->7

*3<->6

*4<->5

Example:
F(G, D) -> dist(G,D) -> (7-4+1) = 4 --> pair of 4<->5 [Always equal 9 together] --> 5th Interval

Not sure this is easier at all, but I learned it quiet thoroughly ^ _ ^
Interval Quality:
I don't have a convinient formula for the quality but I use this:
Major Second: Accidental matches, except root E/B where it’s raised one
Major Third: Accidental raised one, except root F/C/G where it matches
Perfect Fourth: Accidental matches, except root F where it’s lowered one
Perfect Fifth: Accidental matches, except root B where it’s raised one
Major Sixth: Accidental matches, except for root A/E/B where it’s raised one
Major Seventh: Accidental raised one except for root F/C where it matches

Always calculate the major/perfect interval and then apply any minor/aug/etc, super efficient :)
(source: https://www.musical-u.com/learn/spell-intervals-fast-tips-tricks/)
