It's called exhaust theory.
The length of the pipe needed for optimum performance depends on several different factors. As the exhaust pulse, (sound wave) a positive pressure wave, reaches the end of the pipe and expands into the atmosphere, it creates a negative pressure wave in the opposite direction. If that negative pressure wave arrives at the engine while the exhaust valve is still open, it will lower the pressure in the cylinder and allow more intake charge to enter the cylinder. The speed of that pressure wave (sound) is very dependent on the temperature in the exhaust pipe. It will increase, or decrease, at about 1.5 ft./s per degree. The fact that the exhaust valve and the intake valve are both open for such a short period of time limits the effects of the four stroke exhaust system as far as increases in performance are concerned. In a two cycle, the exhaust ports and transfer ports are both open, together, for a significant period of time. A well tuned exhaust system for a two stroke can increase the horsepower by 50% or more, versus a muffler.
There are a huge number of variables at work. If you know the exhaust temperature (EGT) you might be able to calculate, as a working hypothesis, the length of the pipe needed. Still, you must realize, the temperature of the exhaust gas drops very rapidly as the exhaust flows out the pipe. The temperature at the port, and the temperature at the exhaust pipe end, are very different. This effects the timing of the negative pressure waves arrival at the exhaust port.
As the length, and the diameter, change, it affects the speed of that pressure wave. I doubt there's any formula that can give you a specific wave speed without extensive testing and measuring. As others have already told you, it's mostly a cut and try procedure.
In any case, you're only going to get a small boost from the four cycle exhaust, and the timing of where you get that boost is going to happen only in a narrow rpm range.
I'm sorry if this is a very vague explanation, but it's a very complicated subject. As far as performance increases are concerned, the four cycle exhaust cannot be compared to a two cycle exhaust system. They are worlds apart.