Derivation of Magic Sets by Compilation