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
The first $7$ is redundant, you can use:
$$C-3X \pmod 7$$
instead.