Move the SMA implementation from examples/err.myc and examples/sma.myc to a new dedicated file in lib/. This change also cleans up unused code and improves the SMA logic.