Pennsylvania’s 46,000 square miles have never been so popular — and it’s all thanks to math.

Last year, a group of citizens and the League of Women Voters of Pennsylvania filed a lawsuit claiming the commonwealth’s congressional district map, adopted in 2011, gave an unfair advantage to Republicans. The Pa. Supreme Court agreed, and in January, declared the map unconstitutional, tossing it out and instituting a new one.

State and national GOP leaders have decried the Pa. court’s move as itself unconstitutional, and Republicans have asked the U.S. Supreme Court to intervene. Political scholars, PACs and other groups have flooded SCOTUS with arguments in support of one side or the other. The case is being watched by analysts across the country as a bellwether for 2018 elections.

The basic story is political. But the reason the controversy has gone as far as it has goes beyond politics. It comes down to mathematics.

After all, it was way back in 1986 that the U.S. Supreme Court officially declared extreme partisan gerrymandering unconstitutional. But without a reliable way to identify or prove when or where district lines were being manipulated, there were few successful lawsuits based on the ruling.

Until now. Recently, courts around the country have successfully challenged what they say are unfairly drawn district maps, using arguments based on statistical tools that rely on fast computing.

Counting ‘wasted votes’

Christopher Warshaw, a political scientist at George Washington University, measured the extent of partisanship of the Pennsylvania map by first calculating the number of what’s called “wasted votes” in each district.

Counting those wasted votes — how many votes a party received in districts it lost, plus how many extra votes a party received in districts it won — helps measure how the party in power “packs” voters for the opposing party into as few districts as possible, and “cracks” them to spread them out and prevent district-level majorities.

Warshaw’s numbers, which he used to calculate what’s known as the “efficiency gap,” showed that the 2011 map gave Republicans a significant advantage in the state. It also showed Pennsylvania’s map as being one of the most extreme partisan gerrymanders in the nation.

Indeed, since the 2011 map was adopted, Republicans have won 13 of 18 U.S. House seats up for grabs in Pennsylvania, despite approximately half the voters in the state being registered Democrats.

Markov chains

A group of mathematicians in Pittsburgh used a mathematical theorem called Markov chains to make a similar case.

You might have heard of Markov chains in relation to Twitter bots — they’re the math that powered the famous @horse_ebooks account, and many other non sequitur accounts that still tweet today.

What Markov chains do is generate random objects from a fixed object in a stepwise fashion by introducing small changes at each step. Using this method, the team — consisting of University of Pittsburgh professor Maria Chikina and Carnegie Mellon professors Alan Frieze and Wesley Pegden — introduced small changes to the actual Pa. district map to generate truly random districting maps.

These bot maps were generated under specific geometric constraints to ensure that they were plausible; i.e. that they followed the actual required criteria for districts to be contiguous, have similar population sizes and have reasonable shapes.

The team used this process to create one trillion slightly different randomly generated maps, then measured the partisan bias in each one.

Bias was measured via a popular method called the median vs. mean test. In a closely-divided state, the median (or middle) value is expected to be close to the mean (or average). A large gap between these two numbers indicates a partisan advantage.

And using this metric, the group found the 2011 map exhibited more partisan bias than 99.99% of the trillion randomly-generated maps — statistically significant proof that the 2011 map could not have been produced by a strictly nonpartisan process.

500 maps to prove a point

Independent of the Pittsburgh team, political scientist Jowei Chen used software to produce hundreds of random maps using traditional principles for redistricting, and came to the same conclusion as the Markov group.

His software generated 500 random maps, a majority of which gave Republicans nine seats in the House, well shy of the 13 GOP seats actually won. Only two percent of those random maps even gave Republicans 10 seats.

The court-drawn result

To generate its replacement map last month, Pa. Supreme Court it drew on proposals from both Republicans and Democrats, as well as other suggestions put forth.

One major feature: It is much more compact. One analysis found the court-drawn map eliminated over 1,100 miles of district borders from the 2011 map.

Overall, the new map released by the state Supreme Court creates two new districts that would favor Democrats, maintains the same number of closely-divided swing districts as before, and transforms one district from a heavily-favored Republican stronghold to a district that’s GOP-leaning.

In other words, it more closely matches the Pennsylvania electorate, which is about evenly divided between Democrats and Republicans — as evidenced by state and national elections.

Of course, there is no guarantee that the new redistricting map will hold. A federal panel refused to immediately block the new map, but a hearing is scheduled for March 9.