We develop a numerical model using both artificial and empirical inputs to analyze taxi dynamics in an urban setting. More specifically, we quantify how the supply and demand for taxi services, the underlying road network, and the public acceptance of taxi ridesharing (TRS) affect the optimal number of taxis for a particular city, as well as commuters' average waiting time and trip time. Results reveal certain universal features of the taxi dynamics with real-time taxi-booking—that there is a well-defined transition between the oversaturated phase when demand exceeds supply, and the undersaturated phase when supply exceeds demand. The boundary between the two phases gives the optimal number of taxis a city should accommodate, given the specific demand, road network and commuter habits. Adding or removing taxis may affect commuter experience very differently in the two phases revealed. In the oversaturated phase the average waiting time is affected exponentially, while in the undersaturated phase it is affected sub-linearly. We analyze various factors that can shift the phase boundary, and show that an increased level of acceptance for TRS universally shifts the phase boundary by reducing the number of taxis needed. We discuss some of the useful insights on the benefits and costs of TRS, especially how under certain situations TRS will not only have economic benefits for commuters, but can also save the overall travel time for the shared parties, by significantly reducing the time commuters spend on waiting for taxis. Our simulations also suggest that simple artificial taxi systems can capture most of the universal features of the taxi dynamics. The relevance of the assumptions and the overall methodology are also illustrated using the empirical road network and taxi demand in Singapore.