{'fraction_non_alphanumeric': 0.047428189712758854, 'fraction_numerical': 0.01879950376944365, 'mean_word_length': 3.938737040527804, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
A modern solution to the Gion shrine problem

We give a new solution to the famous Gion shrine geometry problem from eighteenth-century Japan. Like the classical Japanese solution, ours is given in the form of a degree ten equation. However, our polynomial has the advantage of being much easier to write down. We also provide some additional analysis, including a discussion of existence and uniqueness.


Introduction.
If you had visited Kyoto's Gion shrine 1 around the middle of the eighteenth century, you might have noticed a wooden tablet, inscribed with geometric figures, hanging from one of the eaves. This may not have been a great surprise, since such sangaku (literally "mathematical tablets") were commonplace in temples and shrines throughout Japan at the time. However, this particular tablet happened to hold a problem that would rise to great fame among a generation of Japanese mathematicians. The algebraic particulars of this challenge might strike modern mathematicians as odd, but it has roots in a fascinating niche of mathematical history.

Background
Eighteenth-century Japan, unified under the Tokugawa shogunate, was a relatively peaceful place where artistic recreation flourished. Those with leisure time indulged in the emerging arts of kabuki and bunraku theater, haiku poetry, ukiyo-e woodblock printing, origamiand a homegrown style of mathematics called wasan. Practitioners of wasan tended to gravitate toward the aesthetics of geometry, and proved wonderful (though esoteric) results about packings of circles, polygons, and ellipses, as well as analogous problems in three dimensions. When a collection of theorems was deemed especially beautiful, it would be inscribed on a sangaku and hung in a Buddhist temple or Shinto shrine, both as an offering to the gods and as a challenge to other worshippers.
At the same time, the shogunate's policy of sakoku ("closed country") kept Japan intellectually distant from the scientific revolution of the West. The result was an insulated discipline that relied heavily on two sources of established knowledge: the planar geometry results of the Greeks, and the rich body of mathematics imported from China, both of which had long been present in Japanese mathematics. Sangi computing rods, a notable Chinese technology, allowed for the numerical computation of roots of polynomials, and were used extensively in Japan. For more about traditional Japanese mathematics, see [1] and [2].
The Gion shrine problem exhibits both geometrical aesthetics and an opportunity to harness the computational power of sangi. Tsuda Nobuhisa solved the problem first by deriving a 1024th degree polynomial from whose roots one could derive the result; his solution appeared on a sangaku hung from the Gion shrine in 1749. Subsequent progress was made by a mathematician named Nakata, who was able to reduce the necessary polynomial degree to 46. However, a celebrated breakthrough was made by Ajima Naonobu, who in a 1774 handwritten manuscript entitled Kyoto Gion Gaku Toujyutsu 2 presented a degree ten polynomial solution. Ajima's derivation was first published in 1966 [3], and has since received a modern analysis that has been translated into English [4].
Strikingly, Ajima's approach uses no geometric techniques more sophisticated than the Pythagorean theorem. With a great deal of algebraic persistence, he is able to manipulate a few basic geometric relations into a system of high degree equations in a and d. A clever substitution yields four, third degree equations in a single variable X = 0 whose coefficients are given in terms of a, p, and q. This can be viewed as a homogeneous linear system with nontrivial solution (X 3 , X 2 , X, 1); any such system must have determinant zero. Ajima then uses a technique equivalent to Laplace's method of cofactor expansion (c. 1776) to arrive at a degree ten polynomial equation in a, which requires nearly a full page to write out completely. It should be noted that, because of sakoku, Ajima (1732-1798) may not have even heard of Laplace (1749-1827), and likely was unaware of his results.
The solution given in this paper also has the form of a tenth degree polynomial. In contrast to Ajima's, ours uses the formalism of trigonometry extensively, though it should be noted that these techniques 3 would likely have been available to eighteenth century Japanese mathematicians, as well. An upside to this approach is as that it allows for greater geometrical insight-and it results in a polynomial that can comfortably be written in two lines.
We also show existence and uniqueness 4 of solutions, and that, in general, for rational p and q, the numbers a, m, s and d are contained in an extension of Q of degree 20.

Solution.
In contrast to Ajima's solution, given in the form of a polynomial in a, ours uses a new variable t. While t arises somewhat mysteriously from a series of ad-hoc substitutions, ultimately we shall see that in fact t = d/a.

Solution.
We start by fixing the constants and Given p and q, with 2 < q ≤ q 0 , we first find the unique solution t ∈ (0, t 0 ] of the equation Then, using t, we compute the quantities and put p = a + m + s + d . Finally, the desired quantities will be Proof. From the definitions of p and q, one immediately sees that scaling all lengths by λ changes p to λp but leaves q invariant. As such, the problem is, for all practical purposes, independent of the overall scale. For convenience, let's start by looking for a solution in which the radius of the circular arc is 1. Observe that the angle ϕ determines the circular segment and, as we shall see, the solution. But for the problem to have a solution, the angle ϕ is limited to the interval 0 < ϕ ≤ ϕ 0 := π 2 + arctan 1/2 ≈ 117 • . If ϕ > ϕ 0 , the square will fail to fit inside the segment. Figure 3 shows the limiting case in which ϕ = ϕ 0 . Not surprisingly, the given value of q completely determines ϕ. We shall see this correspondence shortly (Figure 4).
Our first goal will be to express each of the quantities d, m, a, and s in terms of a single variable; the quantity r = d/2, the radius of the small circle, happens to be a convenient choice. From  From (2), we find that cos θ = cos ϕ + sin θ. Thus cos 2 θ = cos 2 ϕ + 2 cos ϕ sin θ + sin 2 θ, and finally 2 sin 2 θ + 2 cos ϕ sin θ − sin 2 ϕ = 0. This equation, quadratic in sin θ, has two solutions whose product is negative. Since in our case sin θ > 0, we must take the greater of the two solutions, where 0 < r < 1/2. It follows that We also have that m = 1 − cos ϕ, from which it follows that Taking a brief digression, we can use (1), (2), (3), and (5) to write q in terms of ϕ. A plot of the implicit function ϕ(q) is given in Figure 4.  Figure 4. A given q determines the angle ϕ, in degrees.
Since 0 < ϕ ≤ ϕ 0 we have 1 > cos ϕ ≥ −1/ √ 5 = cos ϕ 0 . Then (5) implies that 0 < r ≤ r 0 := −1 Equation (5) also tells us that which, when combined with (3) and (5), yields Bringing together our results from (1), (2), (4), (6), and (7), we now have the problem's four desired quantities in terms of r: At this stage, we could write down a polynomial equation relating q and r, plug in the given value of q and solve for r ∈ (0, r 0 ] (using sangi, or Mathematica), and use this value to recover the quantities d, m, a, and s. However, there are lots of radicals running around in (8), forcing any such polynomial equation to have a large degree. Instead, let's proceed with a sequence of variable changes that will help to eliminate some of these radicals. First, define x > 0 by 1 − 2r = x 2 . The inequality 0 < r ≤ r 0 < 1/2 guarantees that 1 > x ≥ x 0 := √ 1 − 2r 0 ≈ 0.0514622. We can write the above equations (8) in terms of x: The situation is better now, but radicals in both a and s would still result in a polynomial degree that's too big. The next natural choice of substitution might be to try a new variable y 2 = 3 − 2x − x 2 . On its own, such a substitution would create more radicals than it eliminated. However, recognizing that y 2 = 3 − 2x − x 2 gives the equation of a circle, we can find a rational circle parametrization in the variable t as below: This gives us t 2 = (1−x)/(3+x), and it is easy to see that when x ∈ [x 0 , 1) we get t 2 ∈ (0, t 2 0 ). Thus we'll need to restrict t as follows: In terms of the new variable t the equations (9) become We can simplify these expressions further by changing the overall scale of the problem: let's choose the radius of the circular arc to be 2(1 + t 2 ) 2 instead of 1. In this case, our four quantities can be written Observe that the new variable t = 2r/a.
So, given p and q we first solve for t in P (t, q) = 0, choosing a root t ∈ (0, t 0 ]. Then, equations (12) will recover quantities a , m , s , and d that correspond to q. To get the correct p we need only to rescale the solution by the reciprocal of p = a + m + s + d . This is precisely the procedure indicated in Solution 3.
Not all values of p and q are allowed. We can plot q in terms of t as given by equation (13); see Figure 5. We see that q varies on the interval 2 < q ≤ q 0 where (14) If q is not in the interval (2, q 0 ], it cannot correspond to an allowable value of t; in this case there is no solution to the problem. On the other hand, q(t) is an increasing function on the interval [0, t 0 ]. To show this, we compute and rationalize q (t). The inequality q (t) > 0 is equivalent to one of the form u(t) > 0 for a polynomial u(t); the latter inequality is easy to check. Therefore, for each 2 < q ≤ q 0 there is a unique 0 < t ≤ t 0 with P (q, t) = 0.
To summarize, given a pair of positive real numbers p and q: • if q ≤ 2 or q > q 0 , there will be no solution to the Gion shrine problem; • if 2 < q ≤ q 0 , there will be exactly one solution. For many values of q ∈ Q, the polynomial P (q, t) is irreducible. For example, this happens with q = 9/4. In such a case, the corresponding t generates a field Q(t) that is an extension of degree 10. Here the numbers a , m , s and d are contained in Q(t) or an extension of degree 2 of Q(t). If we choose p to be rational, the same occurs with the final numbers a, m, s, and d. These numbers could be contained in some subfield. But since t = 2r/a, this subfield can be only Q(t) or an extension of degree 2 of this. Thus, the solutions generate a field extension of degree 10 (or possibly 20). We conclude with a question: Is there some case in which a, m, s, d are all rational numbers?