nt.number theory – Sum of inverse squares of numbers divisible only by primes in the kernel of a quadratic character

Let $chi$ be a primitive quadratic Dirichlet character of d modulus $m$, and consider the product
$$prod_{substack{p text{ prime} \ chi(p) = 1}} (1-p^{-2})^{-1}.$$

What can we say about the value of this product? Do we have good upper or lower bounds?

Some observations, ideas, and auxiliary questions

  • When $chi$ is trivial, it has value $zeta(2)$.
  • In general, since Chebotarev density theorem (CDT) tells us that $chi(p)$ is equidistributed in the limit, I would “want” the value to be something like

$$Big(zeta(2)prod_{p | m} (1-p^{-2})Big)^{frac{1}{2}}.$$

However, if I’m not mistaken, it seems that the error terms in effective forms of CDT may cause this to be very far from the truth. We can’t ignore what happens before we are close to equidistribution as the tail and the head are both $O(1)$. We can’t even control the error term well (without GRH) because of Siegel zeroes.

  • I don’t think we can appeal to Dirichlet density versions of CDT since those only tell us things in the limit as $s$ goes to $1$ and here $s = 2$.
  • Is there a way to “Dirichlet character”-ify a proof of $zeta(2) = pi^2/6$ to get a formula for this more general case? At least with Euler’s proof via Weierstrass factorization, it seems that we would need some holomorphic function which has zeroes whenever $chi(n) = 1$.

I had a few other ideas but they all seem to run into the same basic problem of “can’t ignore the stuff before the limit”… am I missing something?

dnd 5e – Does a reach weapon allow you to threaten squares 10 feet away or not?

The Following is an analysis based on a strict reading of the rules, and ignoring designer intent and their use of language. The lead designer for 5e, Jeremy Crawford, had this to say about Reach weapons:

Yan ᵔ.ᵔ‏ @Plaguescarred · 21 Aug 2014

@JeremyECrawford I notice people have different interpretation, does polearm increase reach always or only when attacking with it?

Jeremy Crawford‏ @JeremyECrawford · 21 Aug 2014

@Plaguescarred The reach property applies only when you attack with a weapon. Any use beyond that is up to the DM.

Rules for Opportunity attacks and Reach weapons don’t make (narrative?) sense, but they are consistent. Reach is always 5 feet when not actively making an attack, and not the weapon being used.

  • As you will see from the rules of the polearm master, the purpose of opportunity attacks is mainly to prevent people from running past you, and not to punish people who flee your engagement with them.

To understand how/why this is the case, we must first work with the assumption that it’s possible and logical that a person with a 10 foot reach weapon when they attack, is going to have a reach of 10 feet for the purpose of opportunity attacks.

Let’s first be clear about what an opportunity attack in 5e is. Normally, an opportunity attack is an attack you are able to make when a creature leaves the area you can reach. It’s a penalty for a creature leaving combat without first disengaging. It is not an attack which demonstrates what area you threaten. That is, if somebody enters your reach, or moves about within your reach, you do not threaten them. Opportunity attacks seem to serve two purposes:

  1. It creates a cost by way of the “disengage” action to leave melee combat with someone once it has been initiated. (This is based the application of the rules with 5 foot reach weapons, but not directly stated in the rules)
  2. It prevents enemies running right past you to engage with someone else you are defending/blocking. (Page 195 of the players handbook)

    You can rarely move heedlessly past your foes without putting your self in danger; doin g so provokes an opportunity attack.

However, when using reach weapons, this seemingly falls apart, no matter which way you interpret the rules.

Diagram showing 5-foot and 10-foot reach areas relative to an enemy 5 feet away and an ally 10 feet away

The blue square with an x is you. The purple square with an x is an ally, and the green square with an x is a medium creature with speed 30. The red square is your 5foot reach, the Orange square is your 10 foot reach.

Scenario 1: Reach for opportunity attacks is 5 feet.
In this scenario, you have just finished attacking the green monster. It is now the monster’s turn. You engaged them in melee combat, but he can now step away from you and go off and do something else without any penalty. Purpose 1 of opportunity attacks has been subverted. It’s arguable that this isn’t really the purpose of opportunity attacks, but I think it’s the basic assumption for most people, and it’s consistent with the rules for 5 foot reach weapons.

Scenario 2: Reach for opportunity attacks is 10 feet.
In this scenario, you have just finished attacking the green monster. The green monster now wants to go and attack the purple ally since he is an easier target than you to hit. The monster can smoothly walk right past you, without ever leaving your 10 foot reach. This means you can never do an opportunity attack against them. Purpose 2 of the opportunity attacks has been subverted, as directly stated by the rules.

That is the situation with your run of the mill opportunity attack. But now let’s include the polearm master feat. (Page 168 of the Players Handbook)

Polearm Master
You can keep your enemies at bay with reach weapons. You gain the following benefits:
• When you take the Attack action and attack with only a glaive, halberd, or quarterstaff, you can use a bonus action to make a melee attack with the opposite end of the weapon.
The weapon’s damage die for this attack is a d4, and the attack deals bludgeoning damage.
• While you are wielding a glaive, halberd, pike, or quarterstaff, other creatures provoke an opportunity attack from you when they enter your reach.

And now looks more closely at the wording of the opportunity attack rule.

Page 195 of the Players handbook
The attack interrupts the provoking creature’s
movement, occurring right before the creature leaves your reach.

If we edit the rule with polearm master in mind it would read as follows:

The attack interrupts the provoking creature’s
movement, occurring right before the creature leaves or enters your reach.

So now, with this wording, if your reach with the polearm is 10 feet, you can never actually reach the target which you are stopping. The creature will be 15 feet away from you when you interrupt it’s movement before it enters your reach. However, if your reach is 5 feet, then before it enters your reach the creature is 10 feet away from you. When you attack the creature, your reach now extends to 10 feet, and you and you can hit it. This would seem to strongly suggest that two important things.

  1. Reach for opportunity attacks is always 5 feet, and not your weapon or attack.
  2. The purpose of opportunity attacks is ONLY to prevent people from running past you, and not to prevent people from running away from you after being attacked.

The alternative is assuming that the rules are wrong and lots of errata is needed all over the place to “fix it”.

Something else to notice, is that none of the monsters in the DM Basic rules are listed as having a reach of 10, or anything other number. However, many attacks are listed as having a reach of 10. Such as the Adult dragons’ bite. (Though the claw attack is listed as having a reach of 5). In many cases, you can see one attack having a reach of X, while another attack has a reach of y. The section in the rules which discusses the reach of a creature extending beyond 5 feet is specifically in the “Melee Attacks” section, and not in the other sections which mention reach.

Most creatures have a 5-foot reach and can thus attack targets within 5 feet of them wh en making a melee attack. Certain creatures (typically those larger than Medium ) have melee attacks with a greater reach than 5 feet, as noted in their descriptions.

Of course, if your table decides to play things out differently, you may do so, but be consistent if you do.

All that being said, in the end, the intention of the rules is that an Opportunity Attack is an attack and so the reach property applies to the conditions that allow you to attack as well. As can be seen from this conversation on Twitter:

Yan ᵔ.ᵔ‏ @Plaguescarred · 22 Aug 2014

@JeremyECrawford Why distance discrepency OA provoke base on weapon? You said earlier reach weapon dont increase if not attacking? #Confuse

Jeremy Crawford‏ @JeremyECrawford · 22 Aug 2014

@Plaguescarred Yes, OA (an attack) is based on your reach with the weapon you’re using.

For creatures, you will see that different attacks have different reaches, and so an Ancient Red Dragon for example will have one reach domain for it’s claws and another for it’s bite, giving it a greater “threat area”.

Michael Amygdalidis‏ @maplealmond · 25 Aug 2014

@mikemearls So an Adult Red has claws (5ft) and bite (10ft) and tail (15ft.) If I run from adjacent, when does he get to OA?

Mike Mearls‏ @mikemearls · 25 Aug 2014

@maplealmond none – only if you move away, dragon picks which one to use. claws make most sense.

dnd 5e – Are the squares in my graph paper too small?

I’m starting my first campaign with so friends of mine, and I think my graph paper is too small.
I mean, 4 squares equals 1 inch so… Also the paper has 35 tiles in width.
I’m using regular office-store graph paper. Could you say if my graph paper is good enough?
Could you also recommend some more… friendly, graph paper for tabletop-roleplaying?

sums of squares – How can I calculate distance from two pixels HSV?

I want to look for a better way to calculate the distance between two pixels in the HSV color space. In my program I used Euclidean distance.
distance(p_1, p_2) = sqrt{(h_1 – h_2)^2 + (s_1 – s_2)^2 +(v_1 – v_2)^2}

$where ,, h_1, h_2, s_1, s_2, v_1, v_2 ,, are,, the,, components,, of,, the,, two,, pixels,, p_1,, and ,,p_2 ,,from,, HSV,, color ,,space. quad
p_1 = (h_1, s_1, v_1),,
p_2 =(h_2, s_2,v_2)

Using Euclidean distance is not a good approach because the hue value is expressed in degrees, $ hue in (0^{circ}, 360 ^{circ})$. How can I calculate this distance in another way? My proposal is to use polar coordinates to calculate the distance between two HSV pixels. But I don’t know how to express hue, saturation, value in cylindrical space. I think that the x axis is saturation, the value represents the y-axis and $theta$ is represented by hue value in degrees.

nt.number theory – Squares of the form $2^jcdot 3^k+1$

There are finitely many pairs $(j,k)$, and this follows from results on $S$-unit equations. Moreover, the solutions can be effectively determined. Here is a quick treatment going back to the classical work of Thue (1909).

Assume that $2^j3^k+1=n^2$ is a square. Then $n-1=2^a3^b$ and $n+1=2^c3^d$ for some $a,b,c,dinmathbb{N}$. Classifying the quadruple $(a,b,c,d)$ according to its residue modulo $3$, we are led to $81$ equations of the form $Ax^3-By^3=2$, where the coefficients $A$ and $B$ lie in ${2^p3^q:p,qin{0,1,2}}$. Each of them has finitely many solutions by a theorem of Thue (1909), so we are done. See also Thue equations.

c – Babbage Problem – squares ending in digits 269696

//the strategy of take the rest of division by 1e06 is
//to take the a number how 6 last digits are 269696
    while (((square=current*current) % 1000000 != 269696) && (square<INT_MAX)) {

This is part of the “C” example on rosettacode.org. The comments, and not only them, more belong to towerofbabel.disorg!

But rosettacode has a very nice presentation:

What is the smallest positive integer whose square ends in the digits 269,696?

…Babbage asked in a letter, to give an example of what his yet-to-build engine could be working on.

He thought the answer might be 99,736, whose square is 9,947,269,696;
but he couldn’t be certain.

I hope this is all true, because the story is almost too good: I really wonder how he got at this solution; it is correct, but there is a much smaller one.

It is suggested you write it as if for Mr. Babbage himself, who seems to have a clever pen-and-paper method, and who knows the basics (only the basics, but very well).

I found some rare programs that only check roots ending on 4 or 6, because the end of the 269696 ending is a 6. I extended this keenly to endings 64 and 36, which both only give squares ending on 96.

Here is my code. I turned it around and first calculate an approximate root for every number with that ending. At least I treat it as approximate.

My main Q is about the rounding and the way I assign and use babb and diff. Before I used round() it was not really working; now I removed all casts and it seems to work.

/* "Babbage Problem"
    = (Smallest) number whose square ends in ...269696 ? */
/* The root must end on 4 or 6 to give ending 6,
   but also on 36 or 64 to give ending 96 ?!? */

#include <stdio.h>
#include <math.h>

int main() {
    const int ENDING = 269696;
    const int EXPMAX = 38;
    const double mu = 0.001;

    long n,
         babb;       /* nearest integer to root */

    double root,     /* approximation, unless sqrt() is used */
           diff,     /* between root and babb */
           modroot;  /* root wuth last int digits only */

    for (n = ENDING; n < 1L<<EXPMAX; n += 1000*1000) {

        /* sqrt() is faster than exp(log()/2) and has no fraction/diff at all if really integer */
        root = exp(log(n)/2);
        //root = sqrt((double)n); 

        babb = round(root);
        diff = root - babb;
        /* mod 100 with 36 and 64, or mod 10 with 4 and 6 */
        modroot = babb % 100 + diff;
        if (fabs(36 - modroot) < mu ||
            fabs(64 - modroot) < mu   ) {

            /* Check with integer division */
            if (n % babb == 0)
                putchar(' ');

            printf("%16ld %20.12f %12ld %20.12fn", n, root, babb, diff);
    return 0;


*       638269696   25264.000000000004        25264       0.000000000004
*      9947269696   99735.999999999927        99736      -0.000000000073
*     22579269696  150263.999999999971       150264      -0.000000000029
*     50506269696  224735.999999999884       224736      -0.000000000116
      55020269696  234563.999147354130       234564      -0.000852645870
      70456269696  265435.999246522610       265436      -0.000753477390
*     75770269696  275263.999999999942       275264      -0.000000000058
*    122315269696  349736.000000000175       349736       0.000000000175
     129286269696  359563.999443770794       359564      -0.000556229206
     152440269696  390435.999487752211       390436      -0.000512247789
*    160211269696  400264.000000000058       400264       0.000000000058
*    225374269696  474735.999999999651       474736      -0.000000000349
     234802269696  484563.999587257451       484564      -0.000412742549
     265674269696  515435.999611978768       515436      -0.000388021232

So Babbage’s pen-and-paper 99736 is the second one, being at 9947 million. But the first one is after 638 iterations/millions. He came from somewhere else. This is with exp(log()).

The near misses (no stars) are also interesting. With a smaller mu, n up to 2^46 and sqrt() the last lines are:

    *  67646282269696 8224736.000000000000      8224736       0.000000000000
       67808044269696 8234563.999975712039      8234564      -0.000024287961
       68317432269696 8265435.999975803308      8265436      -0.000024196692
    *  68479994269696 8275264.000000000000      8275264       0.000000000000
    *  69718091269696 8349736.000000000000      8349736       0.000000000000
       69882310269696 8359563.999976075254      8359564      -0.000023924746

Does sqrt() always return .00000 ?

Is there something like exp(log()/2) but even simpler?

I only need 3 or 4 significant digits around the decimal point. An imprecise but specialized square root (or log) function. I don’t really understand that “binary estimation” for the seed value. How can I think about 2^n without log2()?

python – Determine whether a number and its square are both the sum of two squares

You can speed it up by saving the squares in a set. If you wrote a function to do this, you can give it a mutable default argument for it to save all the squares instead of having to calculate them repeatedly.

def sum_squares(n, saved_squares=set()):
    # check for sum while saving squares for future calls
    if int(n**(1/2)) > len(saved_squares):
        found_while_saving = False
        for num_to_save in range(len(saved_squares) + 1, int(n**(1/2) + 1)):
            square = num_to_save**2
            if n - square in saved_squares:
                found_while_saving = True
        return found_while_saving
    # check for sum in set of already calculated squares
    for square in saved_squares:
        if n - square in saved_squares:
            return True
        if square >= n:
    return False

With the numbers 5881, 2048, 2670, and 3482, it will only have to calculate any squares for the first call with the number 5881. On the other three calls it can skip to checking the set of all the already calculated squares.

lo.logic – Defining squares in integer linear programming

  1. Is the following definition of squares allowed (may not be know but wanted to know if it u not disallowed) in integer linear programming (Presburger)?

$${zinmathbb Z:exists x,x_1,dots,x_tinmathbb Zmbox{ such that } A(x,x_1,dots,x_t,z)’leq bwedge z=x^2}$$

where $t$ is a constant and $A$ is a fixed matrix with rational entries and of constant number of rows and columns and $b$ is a rational vector with constant number of rows.

  1. If not then to define all squares upto $2^r$ how many rows and columns you need in $A$?

number theory – Finding Pythagorean triple where the squares of sides are weighted

Suppose $a, b, c in mathbb{Z}_{>0}$. The following is a variation of a Pythagorean triple, but with weighted squares:

$$a^2 + 3 b^2 = 4 c^2$$

Can I find something like Euclid’s formula that can generate all solutions for this formula? I’m not sure how to approach this problem.

sum of squares of the coefficients of a monic polynomial

Consider the monic polynomial $$f: = X^n + a_1 X^{n-1} + cdots + a_n$$ over $mathbb Z$. Let $p_i$ be the $i$_th power sum ($1 le i le n$) of the roots of $f$ (in some extension of $mathbb Z$). What is the formula for ${a_1}^2 + {a_2}^2 + cdots + {a_n}^2$ in terms of the $p_i$ ($1 le i le n$).