Derivates some math expressions in prolog