Apple is nearing a historic $4 trillion stock market valuation, fueled by a rally in its shares and investor enthusiasm about the company's artificial intelligence (AI) efforts.