Ask Your Question

Jaakko Seppälä's profile - activity

2023-03-03 19:45:15 +0100 received badge  Famous Question (source)
2022-02-22 13:27:49 +0100 received badge  Notable Question (source)
2022-01-31 14:36:52 +0100 received badge  Popular Question (source)
2022-01-27 20:14:38 +0100 received badge  Popular Question (source)
2021-11-23 23:19:02 +0100 received badge  Notable Question (source)
2021-03-13 15:24:28 +0100 received badge  Popular Question (source)
2021-02-25 00:11:26 +0100 received badge  Nice Question (source)
2021-02-24 15:17:19 +0100 asked a question How one can find a matrix with given condition?

I found the following recreational mathematics problem too hard for me. Can anyone give me hints how to find a solution?

Consider a $4\times 4$ matrix with integer coefficients. Let its elements be $a_{i,j}$ for $1\leq i,j\leq 4$. Now form four sets $A_1$, $A_2$, $A_3$, $A_4$. Say that $A_1$ is the set of elements $a_{i,j}$. Also, $A_2$ is the set of elements $a_{i,j}+a_{i+1,j}+a_{i,j+1}+a_{i+1,j+1}$ i.e. the set of sums of elements of $2\times 2$-subsquares of the matrix. Similarly, denote by $A_3$ the set of sums of $3\times 3$-submatrices and $A_4$ the set containing the sum of all elements of the given $4\times 4$-matrix.

Now, I heard a rumor that one can give an example of 16 integers $a_{i,j}$ such that all integers from 1 to 25 belong to $A_1 \cup A_2 \cup A_3 \cup A_4$. How can one find such an example? It is easy to see that at least some of the elements $a_{i,j}$ must satisfy $1\leq a_{i,j}\leq 25$ but there are still so many elements that finding such a matrix by brute force seems impossible. I was wondering if genetic algorithms or simulated annealing work for such a problem but I don't have enough experience to implement that.

The best I know is that getting all integers from 1 to 24 is possible, for instance using the matrix:

-42  22  23   7
 13  11 -32  14
-23  16  15   8
 19   9 -22   1
2020-05-17 18:49:47 +0100 received badge  Popular Question (source)
2019-11-13 18:44:45 +0100 commented question How to collect number with minimal number of rounds?

Yes. My efforts are in https://stackoverflow.com/questions/5... . It looks they takes too much memory or time.

2019-11-11 22:05:03 +0100 asked a question How to collect number with minimal number of rounds?

Has someone an idea how to solve the following problem?

Take the numbers 1,...,100000 and permute them in some way. At first you can make a swap of two numbers. Then you have to compute how many rounds it would take to collect numbers in ascending order. You have to collect numbers by every round by going left to right. In how many ways you can swap two numbers at the beginning to collect numbers in ascending order with minimum number of rounds?

For example, if numbers are from one to five and those at the beginning in order 3, 1, 5, 4, 2, then you can collect them in three rounds: On first round you collect 1, 2, on the second round 3, 4 and finally 5. But you can do one swap in three different ways to collect numbers in two rounds, namely

3, 4, 5, 1, 2
3, 1, 4, 5, 2
3, 1, 2, 4, 5

Five number sequence can be solved easily by brute force and I found an algorithm to collect 1000 numbers, but 100000 numbers needs maybe some kind of trick to compute fast how a specific swap at the beginning affects how many rounds it takes to collect numbers.

2019-08-08 15:48:23 +0100 asked a question The shortest string containing all given substrings

I found a problem from https://www.ohjelmointiputka.net/post... . An English translation goes like this:

A person wants to learn playing tuba. His neigbours get angry for the noise so he tries to find a song that contains as few tunes as possible that he is able to play all four or less tune combinations. The tunes are c, d, e, f, g, a, and h. Output the minimal song.

I tried a code from https://artofproblemsolving.com/commu... .

def de_bruijn(k, n):
    """
    de Bruijn sequence for alphabet k
    and subsequences of length n.
    """
    alphabet = k
    k = len(k)

    a = [0] * k * n
    sequence = []

    def db(t, p):
        if t > n:
            if n % p == 0:
                sequence.extend(a[1:p + 1])
        else:
            a[t] = a[t - p]
            db(t + 1, p)
            for j in range(a[t - p] + 1, k):
                a[t] = j
                db(t + 1, t)
    db(1, 1)
    return "".join(alphabet[i] for i in sequence)

seq = de_bruijn("cdefgah", 4)
print(seq)

But the validator on the site says that hccc is missing.

So, how can I use Sagemath to solve the problem that if a set contains letters a, c, d, e, f, g, h, how to find the shortest string containing all one to four letter long substrings?

2019-05-14 20:26:16 +0100 commented question A goat in a tether

Actually it was not homework. I just wanted to learn Sagemath to do numerical integration.

2019-05-01 09:21:40 +0100 asked a question A goat in a tether

I would like to solve the following goat problem in sage.

A goat is on the tether on the boundary of the circle with radius 10. What is the radius of the tether is the goat manages to eat half of the grass?

I managed to solve it by Python when I derived the equation.

import numpy
import scipy
import scipy.optimize
def f(x):
    y=400*x*numpy.cos(x)**2-100*numpy.sin(2*x)-200*x+50*numpy.pi
    return y

angle = scipy.optimize.newton(f, 1)
print(20*numpy.cos(angle))

But I was wondering if this can be solved by sage such that I make equations for circle with center (0,0) and radius 10 and circle with center (0,1) and radius x_1, compute the intersections numerically, find the area between curves numerically and iterate this for different radius x_n until the suitable accuracy is found.

The problem, I found is that I don't know how to fund numerically the coordinates of the intersections of two circles and pass them to the numerical integrator.

2019-04-23 00:08:51 +0100 received badge  Famous Question (source)
2018-12-14 19:49:22 +0100 received badge  Famous Question (source)
2018-03-27 10:47:55 +0100 received badge  Notable Question (source)
2018-03-27 10:47:55 +0100 received badge  Popular Question (source)
2017-01-23 23:45:40 +0100 received badge  Famous Question (source)
2017-01-09 16:49:07 +0100 received badge  Notable Question (source)
2016-10-24 14:35:26 +0100 received badge  Popular Question (source)
2016-10-22 04:59:14 +0100 received badge  Nice Question (source)
2016-10-11 10:09:00 +0100 asked a question How to find a polynomial identity to evaluate sum of fifth powers?

I saw the following problem on a book of mine:

Let $a,b,c\in \mathbb C$ satisfies $a+b+c=3,a^2+b^2+c^2=5, a^3+b^3+c^3=7$. Compute $a^5+b^5+c^5$.

How one can do it by Sage? I found a mathematician who was able to find the identity that solves the problem.

sage: a = var('a')
sage: b = var('b')
sage: c = var('c')
sage: x = a+b+c
sage: y = a^2+b^2+c^2
sage: z = a^3+b^3+c^3
sage: expand((x^5-5*x^3*y+5*x^2*z+5*y*z)/6)
a^5 + b^5 + c^5
sage: expand((3^5-5*3^3*5+5*3^2*7+5*5*7)/6)
29/3

But can I use Sage to find the correct identity?

2016-02-21 03:17:04 +0100 received badge  Notable Question (source)
2015-03-27 04:12:26 +0100 marked best answer Can I parse CSV data separated by \t to vectors

I have a CSV data as follows:

pcb138  pcb180  pcb52   pcb118  pcb
1.46    0.738   0.532   0.72    19.9959
0.64    0.664   0.03    0.236   6.0996
3.29    1.15    0.134   1.54    24.9655
3.94    1.33    0.466   1.94    37.4436
3.18    2.14    0.243   1.47    30.183
2.43    1.3     0.137   1.31    20.8036
3.94    3.49    0.208   0.876   41.3818
3.38    1.04    0.477   2.46    29.478
2.21    0.966   0.457   1.14    24.2387
2.49    1.59    0.298   1.18    26.3198
0.86    0.395   0.02    0.406   8.591
3.38    1.85    0.539   1.5     36.4229
7.39    4.42    0.707   3.55    66.4108

Is it possible to read that to vectors? I tried the following:

sage: import csv                           
sage: file='/home/jaakko/Downloads/pcb.dat'
sage: reader=csv.reader(open(file))        
sage: L=[]                                 
sage: for row in reader:^J    L.append(row)
....:     
sage: L[0][0]
'pcb138\tpcb180\tpcb52\tpcb118\tpcb'
sage: L[1][0]
'1'
sage: L[1][1]
'46\t'

What I would like to have is vectors of the form

pcb138=vector([1.46,0.64,...,7.39])

without those tabulators.

2015-03-27 04:12:21 +0100 marked best answer Polynomials as a sum of squares

Is it possible find a decomposition of a polynomial as a sum of squares in Sage if such representation is possible? For example, if I want to prove that $x^6 - x^5 + x^4 - x^3 + x^2 - x + 2/5>0$ for all $x\in\mathbb{R}$ then Sage would return for example

$$\left (x^2\left (x - \frac{1}{2}\right)\right )^2+\left (\frac{\sqrt{3}x}{2}\left (x - \frac{2}{3}\right)\right )^2+\left (\sqrt{\frac{2}{3}}\left(x - \frac{3}{4}\right )\right )^2+\sqrt{\frac{1}{40}}^2$$

2015-03-27 04:09:09 +0100 marked best answer Computing permutations

Is there a way to solve the following question is Sage? I have symmetric group $S_8$ and its elements $a=(x_1 x_2)(x_3 x_4),b=(x_5 x_6), c=(x_7 x_8)(x_9 x_{10})(x_{11} x_{12})(x_{13} x_{14})$ Here of course we might have $x_i=x_j$ if $i\ne j$. Is some given $(y_1 y_2)\in \langle a,b,c\rangle$?

2015-03-27 04:08:56 +0100 marked best answer Reading a table to vectors

I have a csv-file and I have read this in R code read.delim("file:///home/jaakko/Downloads/pcb.dat",header=T , dec = "," , sep = "\t")

This outputs the data like

      A     B      C      D        E
1    11    22.33 21.3   23.23  23.43
2    34     64   664    0.340  0.236   
3    3.29  1.150 0.134  1.540  24.9655
...
69   34     123   23     12     23.344

Is there an easy way to split that data to vectors? Like A <- c(11, 34, 3.29, ..., 34), B <- c(22.33, 64, 1.150, ..., 123),...,E <- c(23.43, 0.236, 24.9655, ..., 23.344)

I'm not sure if R-code output can be used as sage-code input, do formatting by Python and then convert code back to R.

Edit. Sorry, I forgot to say that I read the data as in R-mode.

2015-03-27 04:08:54 +0100 marked best answer Numerical and graphical summaries of data

I have been given the following data:

  pcb138 pcb180 pcb52 pcb118      pcb
1    1.46  0.738 0.532  0.720  19.9959
2    0.64  0.664 0.030  0.236   6.0996
3    3.29  1.150 0.134  1.540  24.9655
4    3.94  1.330 0.466  1.940  37.4436
5    3.18  2.140 0.243  1.470  30.1830
6    2.43  1.300 0.137  1.310  20.8036
7    3.94  3.490 0.208  0.876  41.3818
8    3.38  1.040 0.477  2.460  29.4780
9    2.21  0.966 0.457  1.140  24.2387
10   2.49  1.590 0.298  1.180  26.3198
11   0.86  0.395 0.020  0.406   8.5910
12   3.38  1.850 0.539  1.500  36.4229
13   7.39  4.420 0.707  3.550  66.4108
14   2.74  0.595 0.893  1.980  30.5757
15   2.58  1.780 0.112  1.520  25.4771
16   7.28  3.490 1.440  4.000  68.5567
17   2.29  2.100 0.124  0.981  23.1381
18   5.35  5.370 0.154  0.737  43.0451
19   4.62  2.690 0.319  1.490  39.5300
20   3.54  1.140 0.536  1.890  36.5013
21   1.98  1.040 0.718  0.889  26.5255
22   2.01  1.040 0.173  1.500  22.1370
23   2.22  0.897 0.228  1.070  19.1992
24   3.50  2.330 0.456  1.520  32.9518
25   0.86  0.474 0.152  0.393   9.0893
26   4.92  3.650 0.181  1.790  42.0037
27   2.76  0.868 1.780  2.140  48.7727
28   5.18  3.610 0.843  2.390  55.8940
29   2.60  1.240 0.482  1.600  31.8021
30   4.95  2.740 1.290  2.350  60.1485
31  10.80  8.820 0.067  3.550  97.2793
32   2.02  1.390 0.311  1.310  18.3945
33   3.24  2.600 0.117  1.740  27.5003
34   8.22  7.070 0.531  2.560  79.0347
35   9.50  9.470 0.752  2.420  97.8119
36   4.88  2.690 0.304  2.600  44.8870
37   5.75  3.100 0.595  1.850  58.2125
38   5.48  5.460 0.352  1.540  57.4186
39   8.08  3.370 0.065  3.580  57.4938
40   3.29  2.370 0.340  1.350  33.5817
41   3.73  1.020 5.860  3.890 115.7361
42   1.36  0.624 0.269  0.508  14.8479
43   9.92  2.810 1.260  4.770  91.6305
44   8.65  6.210 0.428  3.680  92.1625
45   4.56  1 ...
(more)
2015-03-27 04:08:47 +0100 marked best answer Pearson correlation

Is there a method in Sage to compute Pearson correlation of a finite set? I have data points $(x_1,y_1),\ldots,(x_6,y_6)$ and wondering if there is a shorter way to do it than just write one long expression.

2015-03-16 23:50:10 +0100 received badge  Notable Question (source)
2015-03-16 23:50:10 +0100 received badge  Popular Question (source)
2015-03-16 23:49:20 +0100 received badge  Popular Question (source)
2015-02-01 16:31:43 +0100 received badge  Notable Question (source)