What is the version of the following sentence with correct punctuation?

If the sequences ended then the sum could defined in terms of starting with the rightmost digits and expressing the sum in terms of the carry operation
If the sequences ended then the sum could defined in terms of starting with the right-most digits and expressing the sum in terms of the carry operation.