replaced speedometer driven gear with recommended 40 tooth and still not accurate...

Just think about this: 3mph at what mph? 40 tooth to 41 tooth is around 2.5%. It slows the speedometer 2.5%. So 5mph = 4.9mph, 40mph = 39mph, 60mph = 58.5mph, etc... The math here is extremely simple.
Math has never been simple to me (lol) but I get what you're saying. What would you do? The speedometer was working correctly before the engine/rear end swap and the shop that replaced the rear end gears swears it's a 3.91