## Problem plotting finite sum involving HurwitzZeta function

I’m not sure if the definitions you posted are different from the ones used in your plot, or you have lingering definitions that are interfering, but the plot I get from your code is slightly different than the one you show.

``````Z1D((Beta)_, (Xi)_, (Theta)_) = (1/(Xi) (2/(Beta)^2 -
1) + (((Theta) Exp(-(Beta)))/2 - 1/2) +
Sum(((-(Beta))^n (Xi)^(n/2))/n! HurwitzZeta(-(n/2),
1 + 1/(Xi)), {n, 1, 80}));

Cv0((Beta)_, (Xi)_) = (Beta)^2 D(
Log(Z1D((Beta), (Xi), 1)), {(Beta), 2});

CSS((Beta)_, a_) =
Cv0((Beta), 18) +
a/2 (Beta)^2 D((Beta)^2/Z1D((Beta), 18, 1) D(
Z1D((Beta), 18, 1), {(Beta), 2}) -
Log(Z1D((Beta), 18, 1))^2, {(Beta), 2});
Quiet@Plot({
CSS((Beta), 0),
CSS((Beta), 5/100),
CSS((Beta), 1/10),
CSS((Beta), 5/10)
},
{(Beta), 0, 5},
WorkingPrecision -> 50,
PlotPoints -> 100,
MaxRecursion -> 3,
PlotLegends -> "Expressions"
)
``````

I think that setting `MaxRecursion` artificially low (to 1) might be responsible for the gaps you see in your plot. I have it set to 3 here. J.M.’s suggestion of `Exclusions -> None` also works even with `MaxRecursion -> 1`.

Also, I don’t know enough about the Mathematics of your functions to know for sure, but it sure looks like the result is complex beyond about 4.5 depending on the exact function.

``````Block({\$MaxExtraPrecision = 500},
N({CSS(9/2, 0), CSS(9/2, 5/100), CSS(9/2, 1/10), CSS(9/2, 5/10)}, 50)
)
``````

$$-79699.364150898969209802685927039062671148814585580$$

$$8.35688067895158097516109070604051 17173041706645372times 10^7+12519.146845612096555038077041258063228049288586 i$$

$$1.6721731294318251847243161680673727340875456210533times 10^8+25038.29369122419311007615408251612645609857717 i$$

$$8.3640536217251618823899729477739452329445740578499times 10^8+125191.46845612096555038077041258063228049288586 i$$

I’m using `Block({\$MaxExtraPrecision = 500}, ...)` to tell Mathematica that it can use a precision up to 550 while evaluating the numbers in order to ensure that it returns numbers with a precision of at least 50. Without the `Block`, I run into a warning that says `\$MaxExtraPrecision = 50 reach while evaluating`. Fortunately, even without the `Block` the numbers are basically the same, but they’re nowhere near a precision of 50. In fact, their precision is around 10.

For small values of $$beta$$, the precision remains high. But as the value of $$beta$$ increases, it seems like the precision diminishes rapidly unless you allow Mathematica to use extra precision. This doesn’t seem to affect the plot, but I thought it was interesting so I wanted to mention it. It also leads me to believe that Mathematica isn’t mistaken when it says those high $$beta$$ functions are complex.

## oc.optimization and control – Does the plane clustered to minimize sum distances^2 to clusters centers ( inertia / “K-means”) produce hexagonal clusters / hexagonal lattice?

“K-means” is the most simple and famous clustering algorithm, which has numerous applications.
For a given as an input number of clusters it segments set of points in R^n to that given number of clusters.
It minimizes the so-called “inertia” i.e. sum distances^2 to clusters centers = $$sum_{i ~ – ~ cluster~ number} sum_{X – points~ in ~i-th ~ cluster} |X_{in ~ i-th ~ cluster} – center_{i-th~ cluster} |^2$$

By some reasons let me ask, what happens for the plane i.e. there is no any natural clusters, but still we can pose minimization task and it will produce something. Let us look on the example:

So, most clusters look like hexagons. Especially the most central one which is colored in red.
Well, boundary spoils things, also may be not enough sample size/iteration number – simulation is not a perfect thing – but I made many and pictures are similar…
Hexagonal lattice appears in many somewhat related topics, so it might be that some reason exists.

Question 0 What is known on “inertia” minimization on the plane/torus ? (torus – to avoid boundary effects.) (Any references/ideas are welcome). Do hexagons arise as generic clusters ?

Question 1 Consider a torus of sizes R1,R2 , consider the number of clusters to be mn ,
is it true that hexagonal lattice will provide the global minima for “inertia” ? (At least for consistent values of R1, R2, m,n (R1=a
m, R2 = a*n) ).

(Instead of finite number of points we can consider the continuous case and substitute summation over points by the integral. Or we can sample large enough uniform datacloud – as done in simulation).

Let me mention beautiful survey by Henry Cohn at ICM2010, where lots of optimization problems of somewhat related spirit are discussed and which sound simple, but remain unsolved for years (see also MO78900). That question is not discussed there unfortunately.

The Python code for the simulation above. One can use colab.research.google.com – to run it – no need to install anything – can use google’s powers for free.

``````from sklearn.cluster import  KMeans
import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial.distance import cdist
import time
#import datetime

t0 = time.time()
N = 10**5 # Number of uniformly scattered point
d = 2 # dimension of space
X = np.random.rand(N,d) # Generate random uniform N poins on (0,1)^d
n_clusters = 225 # Number of clusters for Kmeans
clustering = KMeans(n_clusters=n_clusters,
init='k-means++', n_init=10, max_iter=600, # max_iter increased twice from default
tol=0.0001,  random_state=None,  algorithm= 'full' ).fit(X) # Run K-means with default params
# https://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html#sklearn.cluster.KMeans

print(time.time() - t0, ' secs passed' ) # Print time passed

cluster_centers_ = clustering.cluster_centers_ #
predicted_clusters = clustering.labels_ #

####################################################################
# Choose the most central classter - hope boundary effect on it would be negligble
central_point = 0.5 * np.ones(d)  # Choose central pint
idx_most_central_cluster  = np.argmin( cdist( central_point.reshape(1,-1), cluster_centers_ ) ) # Find cluster most close to central point
coords_most_central_cluster_center = cluster_centers_(idx_most_central_cluster,: )
Xm = X(mask,: ) # Select only points from the most central cluster

#######################################################################
# Plotting
fig = plt.figure( figsize= (20,10 ) ) # 20 - horizontal size, 6 - vertical size
plt.scatter( X(:,0), X(:,1), c = predicted_clusters )  # scatter plot all the points  colored according to different clusters
plt.scatter( cluster_centers_(:,0),  cluster_centers_(:,1), c = 'blue' ) # Mark centers of the clusters
plt.scatter( Xm(:,0), Xm(:,1), c = 'red' ) # Color by red most central cluster
plt.title('n_sample = '+str(N) + ' n_cluster = ' + str(n_clusters))
plt.show()
``````

## nt.number theory – Number of distinct sum of two and four squares under sum condition

Given $$0leq mleq n$$ and $$x_1+dots+x_4=n$$ holds what is the

1. distribution of

2. maximum

number of distinct values of the sum of squares function $$x_1^2+dots+x_4^2$$ on conditions

a. $$0=x_1=x_2leq x_3,x_4leq m$$

b. $$0leq x_1,x_2,x_3,x_4leq m$$ holds?

(Note we do not force order).

## geometry – How to determine the minimum value of the weighted sum of the distances from two points to a point on a circumference

In a two-dimensional Cartesian coordinate system,
there are two points $$A(2, 0)$$ and $$B(2, 2)$$
and a circle $$c$$ with radius $$1$$ centered at the origin $$O(0, 0)$$,
as shown in the figure below.

If $$P$$ is a point on the circle $$c$$,
then what is the minimum value of

$$f = 2sqrt{2}lvert{PA}rvert + lvert{PB}rvert?$$

From my experience,
the solutions to such problems do not seem to be available under elementary form in general,
as indicated by answers to the question Minimize the sum of distances between two point and a circle.
However, when I studied this problem on GeoGebra,
it seems that minimum value is exactly $$5$$ in this specific situation,
with $$P$$ located at roughly the position shown below:

I tried to verify my hypothesis as follows.
Since $$P$$ is located inside $$angle AOB$$,
we set its location to $$(x, sqrt{1 – x^2})$$ (where $$sqrt{2}/2 < x < 1$$).
Therefore,
begin{align*} lvert{PA}rvert &= sqrt{(2 – x)^2 + (1 – x^2)} \ &= sqrt{5 – 4x}, \ lvert{PB}rvert &= sqrt{(2 – x)^2 + (2 – sqrt{1 – x^2})^2} \ &= sqrt{-4sqrt{1 – x^2} – 4x + 9}, \ f &= 2sqrt{2} lvert{PA}rvert + lvert{PB}rvert \ &= 2sqrt{2} sqrt{5 – 4x} + sqrt{-4sqrt{1 – x^2} – 4x + 9}. \ end{align*}

I asked GeoGebra again to plot $$f(x)$$:

and it seems to confirm my conjecture that
$$min_{sqrt{2}/2 < x < 1} f(x) = 5$$

Is my hypothesis correct?
If so, is there a proof of this hypothesis that can be relatively easily by hand
(preferably avoiding, say, the evaluation of $$f'(x)$$)?
Geometric proofs will be especially appreciated.

## plotting – Problem with a finite sum involving HurwitzZeta Function

I’m trying to reproduce some plots from the analytical expression:

$$f(xi)=left(frac{2}{beta^2}-1right)+left(frac{theta,e^{-beta}}{2}-frac{1}{2}right)xi+sum_{n=1}^{60}left(frac{(-beta)^n}{n!}xi^{1+n/2}zeta_Hleft(-frac{n}{2},1+frac{1}{xi}right)right)$$.

I need to plot $$f(-4x)$$ for several values of $$beta$$ and with $$theta=0$$ and $$theta=1$$. In the attached picture, the left panel is what I have to get (ignore the blue curves), but Mathematica gives me a lot of noise.

My code is:

``````f((Beta)_, (Xi)_,M_, (Theta)_) := ((2/(Beta)^2 -1) + (((Theta) Exp(-(Beta)))/2 - 1/2) (Xi) + Sum(((-(Beta))^n (Xi)^(1 + n/2))/n! HurwitzZeta(-(n/2), 1 + 1/(Xi)), {n, 1, M}));

Plot({f(0.5, -4 x, 60, 1), f(0.5, 4 x, 60, 0),
f(0.8, -4 x, 60, 1), f(0.8, 4 x, 60, 0), f(1.1, -4 x, 60, 1),
f(1.1, 4 x, 60, 0)}, {x, -6, 6}, AxesOrigin -> {0, 0},
PlotStyle -> {Green, Green, Red, Red, Black, Black},
PlotRange -> {0, 8})
``````

Do you have an idea of what is going on?

Thanks!

## Python sum of duplicate elements from list of dictionary

How to make sum of duplicate elements from a list of dictionary.

sample list ==>

``````data = [
[
{'user': 1, 'rating': 0},
{'user': 2, 'rating': 10},
{'user': 1, 'rating': 20},
{'user': 3, 'rating': 10}
],
[
{'user': 4, 'rating': 4},
{'user': 2, 'rating': 80},
{'user': 1, 'rating': 20},
{'user': 1, 'rating': 10}
],
]
``````

expected_op ==>

``````op = [
[
{'user': 1, 'rating': 20},
{'user': 2, 'rating': 10},
{'user': 3, 'rating': 10}
],
[
{'user': 4, 'rating': 4},
{'user': 2, 'rating': 80},
{'user': 1, 'rating': 30},
],
]
``````

my code :

``````data = [
[
{'user': 1, 'rating': 0},
{'user': 2, 'rating': 10},
{'user': 1, 'rating': 20},
{'user': 3, 'rating': 10}
],
[
{'user': 4, 'rating': 4},
{'user': 2, 'rating': 80},
{'user': 1, 'rating': 20},
{'user': 1, 'rating': 10}
],
]

for d in data:
lambda sum: sum + d['rating'] if d['user'] == d
``````

## Each of eight, consecutive, three digit numbers is divisble by its last digit. What is the sum of digits of the smallest number?

Each of eight, consecutive, three digit numbers is divisble by its last digit. What is the sum of digits of the smallest number?

### My approach:

Each number we can denote like that:

$$overline{abc}, overline{abc}+1, …, overline{abc}+7quad$$
,where$$overline{abc} ;$$is the smallest.

Sum of these numbers: $$8(a+b+c)+27$$

Also each number has the same second from the last digit, because there is no number divisble by $$0$$. That means sequance starts with number ending with digit $$1,$$ or $$2$$.

This question is from this year’s Kangaroo competition.

## maximum of a sum

Let $$q$$ be an integer $$ge2$$, $$k$$ and $$f$$ be two positives integers.
I try to find
$$max{sum_{l_1+cdots+l_f=k}l_iq^{l_i}mid (l_1,cdots,l_f)in(mathbb N_0)^f}$$
I think it is $$kq^k$$, but no way to prove it.
Does anyone have a proof of that?

## algorithms – Maximum sum path in a matrix

As Pal have commented, this is a question in dynamic programming. I will now propose the solution using dynamic programming to the question, but I highly recommend trying it on your own first, and checking this later.

The algorithm:

1. Create a new empty matrix $$V$$ of size N by N
2. for $$1 le i le N:$$
1. for $$1 le j le N:$$
1. Set $$V(i, j) = M(i,j) + max(V(i-1, j), V(i, j-1))$$ (note that $$V(-1,j) = V(i,-1) = 0$$)
3. Find $$m = max_i,_j(V(i,j))$$
4. Count the number of times we see $$m$$ in $$V$$
5. You can return the maximum sum $$m$$ and the number of times it occurs (as you have counted it)

Complexity:

The algorithm takes $$O(N^2)$$ time (which is $$O(k)$$ if we let $$k$$ be the input size) since it calculates a new matrix of size N by N, doing $$O(1)$$ operations per cell in it.

Notive that the algorithm’s space complexity is also $$O(N^2)$$ as we were required to create a whole new matrix.

## Replace a family of coefficients by a function in a sum

I would like to do something very simple, i.e. replace the coefficients in a sum by a function:

``````c(1) + c(2) + c(3) /. {c(s) -> (s + 1)/(2 (2 s + 1))}
``````

Unfortunately, this does not work. Any suggestion for something handy that would do the job?