1
$\begingroup$

Is it possible to simplify the following expression? I feel like this can be simplified.

$$N = (7 - ((3X - C)\mod 7))\mod 7$$

$$A = \left\lfloor\frac{X + O}{7}\right\rfloor$$

I'll explain a bit for sake of completeness:

The formula is used to get key signature value, where:

  • $0\leq N \lt7$ starting from note C to B

  • $-7\leq X\leq 7$ number of sharps or flats. Negative value means flats and positive means sharps.

  • $C = 0$ for major scales, $C = 5$ for minor scales.

  • $-1\leq A\leq 1$ negative value indicates flat key, positive indicates sharp key.

  • $O = 1$ for major scales, $O = 4$ for minor scales.

I think It is possible to somehow simplify $\mod7 \mod7$ part. the formula I wrote is experimental but it works fine for defined ranges that I tested.

Example:

X = 4; // 4 sharps
C = 5; // minor scale
O = 4; // minor scale

$N = (7 - ((3\times 4 - 5)\mod 7))\mod 7\implies N = 0$ , therefore Note C

$A = \left\lfloor\frac{4+4}{7}\right\rfloor\implies A = 1 , A > 0$, therefore is sharp.

So key signature is C# minor

$\endgroup$
  • 1
    $\begingroup$ your example is wrong, you have X=4 $\endgroup$ – JMP May 13 '17 at 21:59
  • $\begingroup$ thanks for correction. yes c# minor has 4 sharps. 3 was typo @JonMarkPerry $\endgroup$ – M.kazem Akhgary May 14 '17 at 2:04
1
$\begingroup$

The first $7$ is redundant, you can use:

$$C-3X \pmod 7$$

instead.

$\endgroup$
  • $\begingroup$ this doesn't work for all cases. for example when X = 1 and C = 0 (G major) instead of giving N = 4 it gives N = -3. I'm not sure if I'm mistaken something? $\endgroup$ – M.kazem Akhgary May 14 '17 at 2:18
  • $\begingroup$ oh I see. the language I use is C# and the modulus operator in C# is not giving expected mathematic result for negative numbers. the function you give is correct by the way. stackoverflow.com/questions/1082917/… $\endgroup$ – M.kazem Akhgary May 14 '17 at 2:23
  • $\begingroup$ I was able to fix this issue by just adding 21 units to constants. C = 21 for major and C = 26 for minor scales. this will cause the result to be always positive. stackoverflow.com/a/16023027/4767498 $\endgroup$ – M.kazem Akhgary May 14 '17 at 5:22
  • $\begingroup$ some mod implementations do this automatically; in maths we write: $$-3\equiv 4 \pmod 7$$, you can also use, if (retValue<0) retvalue+=7; but I'm glad you've worked it out. $\endgroup$ – JMP May 14 '17 at 5:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.