Testing the divisibility of $\sum_{k=0}^{m-1} (n+k) $ by $m$ when $m$ is odd

52 Views Asked by At

The theorem I am attempting to test is

$$ \forall m, n \in \mathbb{Z}, n > 0, m \space odd \space \Rightarrow m | \sum \limits _{k=0}^{m-1} (n+k) $$

Please note: The object of this code is to help me to determine if I should attempt to prove or disprove a theory.

The code I wrote is below is in c++

bool __theorem__1();    

mpz_class is_odd ( mpz_class input );
mpz_class const RANGEMAX = 10;    

int main ( int argc, const char * argv[] )
{
    __theorem__1();
    return 0;
}    

mpz_class is_odd ( mpz_class input )
{
    return input % 2;
}    

bool __theorem__1()
{
    // set result to 0
    mpz_class result = 0;
    // for all m
    for ( mpz_class m = 0 ; m < RANGEMAX; m++ )
    {
        // if m is odd
        if ( is_odd ( m ) )
        {
            // set k to 0, and n to 1,
            // increment loop until k is greater or equal to m-1
            mpz_class k = 0 , n = 1;
            for ( ; k >= m - 1; k++, n++ )
            {
                result += ( n + k );
            }
            // if m does not a multiple of m then print counter example. 
            if ( ( result % m ) != 0 )
            {
                cout << "found counter example with k = : " << k << "and n " << n << endl;
            }
            else
            {
                cout << "No counter example found " << endl;
            }
        }
    }
    // this is just here for now. I will update bool logic later. 
    return  true;
}

I am posting this topic to see if someone can review my work and let me know if I made any mistakes so I can attempt to understand what I am doing / reading wrong.

1

There are 1 best solutions below

0
On

This is not a code-review site. However, here is a proof of the statement you're interested in: $$\begin{align*} \sum_{k=0}^{m-1}(n+k)&=\left(\sum_{k=0}^{m-1}n\right)+\left(\sum_{k=0}^{m-1}k\right)\\\\ &=\left(\underbrace{n+n+\cdots+n}_{m\text{ times}}\right)+\sum_{k=0}^{m-1}k\\\\ &=mn+\frac{m(m-1)}{2} \end{align*}$$ which, when $m$ is odd, is clearly a multiple of $m$: $$m\left(n+\frac{m-1}{2}\right)$$ By the way, the word theorem refers to something that has been proven already. It does not quite make sense to "test" a theorem to determine its validity since (if one's argument is correct) to do so is unnecessary. A more appropriate word you could have used in your post would be "conjecture" or "hypothesis".