As for competition... I don't understand the dichotomy you're creating. That "vast amount" of simple code (the UI, etc), is protected by a different government-ranted monopoly: copyright. That's the only reason A can compete with B on that basis. But why is a large body of simple UI code worth copyright protection, while the small but complicated imaging algorithm isn't worth patent protection?
And your example doesn't address the specialization issue. Why do we want experts in ultrasonic imaging competing on UI and updates/support? Isn't it better for them to be able to focus on new imaging algorithms (their core competency), and sell those to someone who has an expertise in medical UIs?
I use this example a lot, but think about ARM. Aren't they a perfect example of the patent system working correctly? Isn't it great that they can sell their IP and let NVIDIA integrate it with a graphics core for consumer devices, etc, without forcing ARM to go into the business of manufacturing every type of microprocessor people might need?
I don't think it's obvious that they should naturally be allowed to prevent a clean-room reimplementation. The real innovative and creative work is in the designs that would be protected by copyright - the alleged "innovative circuits" subject to patent are really just being used as patent traps to prevent a clean-room reimplementation of the architecture - as anti-interoperability measures, in other words.
Imagine I'm the guy building the ultrasound machine. Company A comes to me with this new algorithm they've developed to do nifty processing of the data. Things I care about:
In any piece of data analysis code, the vast, vast majority of the actual code will go into stuff only orthogonal to your nifty algorithm. And the thing is, the stuff I'm really paying for is that vast majority. I want it to run on my systems, and not crash, and have a nice UI and...Even if Company B comes along with software that uses the same algorithm, or perhaps I decide to write my own software, I still need to rewrite this vast majority of code that is not the algorithm itself. And, as a hardware guy, I'll be bad at that. As Company A, you get to compete with Company B using that.