So the reality is a bit more complicated than “big sparse country”. Freight railroads don’t really care about population density, just distance and operating margins. It comes down to who owns the rails and their motivations.
A big capital investment like electrification is actually extremely profitable long term. Over 30-40 years it would save a class 1 railroad about 25% of their operating expenses for fuel and maintenance (diesel-electric units are complex high maintenance systems compared to big-ass AC motors). Even when factoring in debt servicing over that period it’s still a large overall win.
The problem is that a big investment like that isn’t attractive to CN or CPKC, because they’re mainly concerned with positive quarterly reports. It’s the same reason our tracks are so shabby, it’s not that they can’t afford to it’s that their motivation is to move freight for the absolute lowest cost, speed and reliability be damned.
In Europe & Asia the infrastructure is commonly owned by a state corporation, and they’re generally more willing to take on big projects like that so they can get more revenue from the train operators themselves. More passengers and higher speed = more tax revenue. The incentives are just different in that situation
Another fun fact… if you were to add up the bonuses, dividends, buybacks, and dumb vanity projects (CN Tower) in the past half-century, they’ve already blown through more than double what it would cost to electrify and upgrade the most serviced trackage in the country. Instead we made some old guys obscenely wealthy.