Planet b is an inner planet (an inferior planet relative to planet a
in ancient astro jargon)
and planet a is an outer planet (a superior planet relative to planet b
in ancient astro jargon).
Now planet b because it is inferior has a greater angular velocity about
the Sun than planet a. Thus planet b will lap planet a eventually:
i.e., planet b will travel from one point of alignment with planet a
and the Sun (the vertical alignment in the diagram) and come into
a new alignment (the oblique alignment in the diagram) after traveling
more than 360 degrees.
The time it takes to lap is the synodic period itself.
If we measure angle from the vertical, then we have the following relations
where \theta is the angle of the second alignment, r_a is the angular speed of planet a, r_b is the angular speed of planet b, and t is the synodic period, our unknown. Now we solve for t eliminating \theta (which is an unknown that can stay unknown):360+\theta=r_a*t and \theta=r_b*t
where p_a is the sidereal period of planet a and p_b is the sidereal period of planet b. Now in fact the synodic period of planet b relative to planet a is the same as that of planet a relative to planet b. Thus if we use absolute value signs, we need make no distinction in the formula between superior and inferior planets:360+r_b*t=r_a*t, t=360/(r_a-r_b), and thus t=p_b*p_a/(p_b-p_a),
If we assume p_a is constant, then we can see how t varies as p_b grows from 0 to p_a to infinity.t=p_b*p_a/|p_b-p_a|.