Ask Your Question

wisher's profile - activity

2020-12-24 15:53:25 +0200 received badge  Notable Question (source)
2020-12-24 15:53:25 +0200 received badge  Popular Question (source)
2020-12-16 09:43:45 +0200 received badge  Popular Question (source)
2020-12-15 23:42:31 +0200 commented answer Square, cube, octahedron, equations

Thank you for your reply. She made me understand that I have math gaps. I'm going to check out math sites to try and figure out what L-infinity norm is. I have cut out!

2020-12-15 11:00:00 +0200 asked a question Square, cube, octahedron, equations

We know that $|x| + |y| - 1 = 0$ is the equation of a square having its vertices on the axes.

I asked to represent the equation $|x| + |y| + |z| - 1 - 0$, believing to obtain a cube in space.

But I obtain an octahedron. Why? And how do you get a cube?

# with SageMath 7.3
var('x, y, z')
f = abs(x) + abs(y) + abs(z) - 1
implicit_plot3d(f, (x, -1, 1), (y, -1, 1), (z, -1, 1), color='aquamarine ')
2020-08-26 15:54:33 +0200 received badge  Teacher (source)
2020-08-26 15:54:33 +0200 received badge  Necromancer (source)
2020-08-26 10:18:15 +0200 answered a question output.txt not updated

This problem has already made me bitch a few times until I found a solution: I copy the script to a new cell, make the modifications and there I get a new "full_output.txt file" which takes into account my modifications. One response says: "But reloading should get you what you want." I have found that this is not true! the old "full_output.txt file" is still present. (sorry for my bad english, i use google translator)

2019-01-24 16:28:04 +0200 commented question Problem with boring message

Excuse me for the delay in answering you. I did a restoration of my previous work to the problem caused by the use of LaTeX, which I do not need, and everything is back to normal. Sorry for your lost time.

2019-01-19 23:12:50 +0200 commented question Problem with boring message

Good evening, I do not use Latex.After being seen on the site ctan.org I decided that I did not need Latex. I also tried bits of codes like

var ('z ')
print latex (z ^ 12)

to see what that gave. As said in my request I always get the following message.

Error: PDFLaTeX does not seem to be installed. Download it from ctan.org and try again. None

What is serious now is that if I activate cells that already contain code that worked I still get this message and nothing else.

2019-01-19 17:45:55 +0200 asked a question Problem with boring message

In one of my worksheets I wanted to test Latex. I was directed to ctan.org After reading a bit about it, I decided that I did not need it. But since this test, whenever one of my exercises launches I get the following message and nothing else. How to get rid of this? Thanks in advance for your time.

Error: PDFLaTeX does not seem to be installed. Download it from ctan.org and try again. None

2018-12-06 09:43:04 +0200 commented answer Speed a function with hex grid and primes numbers

I did two more tests, here is the result:

lim       DP3           time in s
60001     1057          18 440
90001     1454          37 690  !
100001  -> the Sage software stops after a few seconds without an error.

I think the matrix has become too big. We must find another method of resolution, either mathematical or computer. I'll think about it. Anyway thank Mr. Lelièvre you for your help that allowed me to learn new concepts about prime numbers.

2018-12-05 10:52:19 +0200 commented answer Speed a function with hex grid and primes numbers

I'm going to run the program for more value from "lim" quite to running my computer all night. I will provide the results later.

2018-12-05 10:47:09 +0200 commented answer Speed a function with hex grid and primes numbers

I tested your second idea in more depth. As soon as we increase the value of "lim" it is your second idea that is the most powerful.

lim         DP3      time in s
1001      78           4.6
2001      119        17.5
3001      152          38
4001      180          69
5001      208        108
6001      240        157
8001      288        282
16001    433       1151
30001    644       4077

The curve that adjusts the pairs of points (DP3, time) seems parabolic or exponential. So it's not pleasant since you have to reach a DP3 = 2016. Rather than the brute force of the computer, there must be a simpler mathematical process that goes beyond me. It is simply frustrating to feel incapable of not knowing the right simplification techniques. Thank you

2018-12-04 00:10:08 +0200 commented answer Speed a function with hex grid and primes numbers

Thanks for your answer but your idea is slower. I have made a little try.

  • with my code: dp = len( [t for t in d if is_prime(abs(n-t))] ) I found an answer after 7.8 s

  • with your code: dp = len( [t for t in d if (n-t).abs().is_pseudoprime()] ) I found an answer after 10.4 s

2018-11-30 17:31:22 +0200 asked a question Speed a function with hex grid and primes numbers

Hello, I am trying to solve the question 175 of the Turing Challenge. We create a network of hexagonal tiles containing the following integers 1, 2, 3, 4, ... I represent this network in a square matrix by placing the number 1 in the center of the matrix. We must calculate the difference between each tile numbered n and each of its six neighbors, we will call DP (n) the number of these differences # which are a prime number. My problem is this: I have to calculate a lot of times the function below. We save in DP3 the n which are surrounded by exactly 3 prime numbers. Here is all my script. My idea is this: every time I have completed a turn I can calculate the DP3 of the previous turn. The program stops when len (DP3) = 2016. As the spirals become bigger and bigger you have to make more and more calls to the DP3 () search function. My question is: is it possible to speed up this function?

PS: I'm sorry for my bad english. I also note that I am a beginner in programming.

# TURING 175 - Tuiles hexagonales (essai VII)  DERNIER 26/11/18   OK ma!s trop lent
# Une tuile hexagonale portant le numéro 1 est entourée d'un anneau de six tuiles numérotées de 2 à 7, la première tuile de l'anneau étant # posée à midi et en tournant dans le sens inverse des aiguilles d'une montre. 
# De nouveaux anneaux sont ajoutés de la même façon, les anneaux suivants étant numérotés 8 à 19, de 20 à 37, de 38 à 61, et ainsi de 
# suite. Le diagramme ci-contre montre les trois premiers anneaux. 

# En calculant la différence entre la tuile numérotée n et chacune de ses six voisines, nous appellerons DP(n) le nombre de ces différences # qui sont un nombre premier. 
# Par exemple, autour de la tuile numéro 8, les différences sont 12, 29, 11, 6, 1 et 13. Donc DP(8)=3. 
# De la même manière, autour de la tuile numéro 17, les différences sont 1, 17, 16, 1, 11 et 10, d'où DP(17)=2. 
# On peut montrer que la valeur maximale de DP(n) est 3. 
# Quand toutes les tuiles pour lesquelles DP(n)=3 sont énumérées dans l'ordre croissant pour former une suite, la 10ème tuile
# porte le numéro 271. 
# Trouver le numéro de la 2016ème tuile de cette suite.

temps = walltime()

var('n,x,y')

def rechercheDP3(n,x,y):
    n = M[x, y]
    d = [ M[x-1, y], M[x, y+1], M[x+1, y+1], M[x+1, y], M[x, y-1], M[x-1, y-1] ]    # les 6 cases qui entourent n
    dp = len( [t for t in d if is_prime(abs(n-t))] )
    if dp == 3:
        DP3.append(n)
    return

lim  = 17                  # Attention, il faut que lim soit impair
M = matrix(ZZ, lim, lim)     # création matrice nulle M    ATTENTION:  X est vertical vers le bas &  Y est horizontal vers la droite 
x, y = lim//2, lim//2        # centre de M on compte à partir de 0 
print "Centre:", x, y
M[x, y]     = 1              # le nombre 1 est placé au centre puis le 1er tour (2,3,4,5,6,7)
M[x-1, y]   = 2
M[x-1, y-1] = 3
M[x, y-1]   = 4 
M[x+1, y]   = 5
M[x+1, y+1] = 6
M[x, y+1]   = 7
n = 7
x_debut_prec, y_debut_prec = x-1, y

DP3 = [1]
maxtour = lim//2
tour = 1                    # on a déjà placé le 1er tour 2...7
grandeur_deplact = 1        # plus la spirale est extérieure plus le déplacement est grand  
print "maxtour = ", maxtour 
print "*",walltime(temps) 
#print M        # valable si n est petit
#print

# on remplit la table en spirale
while tour < maxtour and len(DP3)<2016:        # 2016 est la valeur demandée dans l'énoncé
    tour += 1
    grandeur_deplact +=1
    # on se place au-dessus de la case de départ (2,8,20,...) -> 6 trajets de 1 au 1er tour, de 2 au 2d tour, de 3 au 3e tour, ....
    x = x_debut_prec - 1
    n += 1                   #n = dernier_terme_tour + 1

    M[x, y] = n
    x_debut_suivant, y_debut_suivant = x, y     # coord case départ tour suivant

    for i in xrange(grandeur_deplact):     # trajet 1 horizontal gauche
        y = y-1
        n += 1
        M[x, y] = n

    for i in xrange(grandeur_deplact):     # trajet 2 vertical bas
        x = x+1
        n += 1
        M[x, y] = n

    for i in xrange(grandeur_deplact):     # trajet 3 oblique bas droit     
        x = x+1  
        y = y+1        
        n += 1
        M[x, y] = n

    for i in xrange(grandeur_deplact):     # trajet 4 horizontal droite       
        y = y+1
        n += 1
        M[x, y] = n        

    for i in xrange(grandeur_deplact):     # trajet 5 vertical haut        
        x = x-1        
        n += 1
        M[x, y] = n  

    for i in xrange(grandeur_deplact-1):     # trajet 6 oblique haut gauche -1 car on retombe sur le 1er -> le tour est fini
        x = x-1 
        y = y-1       
        n += 1
        M[x, y] = n          

    dernier_tour_n = n                        # on mémorise le tour qu'on vient de faire
    xfin_tour = x
    yfin_tour = y   


    # recherche les dp3 -> on recommence le tour précédent et on cherche ses DP3
    grandeur_deplact -= 1       
    # on se place au-début du tour précédent (2,8,20,38,62,92,...)
    x,y = x_debut_prec, y_debut_prec
    np = M[x,y]    # np comme cela on ne touche pas à n
    rechercheDP3(np,x,y)

    for i in xrange(grandeur_deplact):     # trajet 1 horizontal gauche
        y = y-1
        np += 1
        rechercheDP3(np,x,y)

    for i in xrange(grandeur_deplact):     # trajet 2 vertical bas
        x = x+1
        np += 1
        rechercheDP3(np,x,y)

    for i in xrange(grandeur_deplact):     # trajet 3 oblique bas droit     
        x = x+1  
        y = y+1        
        np += 1
        rechercheDP3(np,x,y)

    for i in xrange(grandeur_deplact):     # trajet 4 horizontal droite       
        y = y+1
        np += 1
        rechercheDP3(np,x,y)       

    for i in xrange(grandeur_deplact):     # trajet 5 vertical haut        
        x = x-1        
        np += 1
        rechercheDP3(np,x,y)

    for i in xrange(grandeur_deplact-1):     # trajet 6 oblique haut gauche
        x = x-1 
        y = y-1       
        np += 1
        rechercheDP3(np,x,y)

    # retour aux bonnes valeurs 
    grandeur_deplact += 1   # on revient à la valeur exacte pour le tour suivant
    x = x_debut_suivant  
    y = y_debut_suivant
    x_debut_prec, y_debut_prec = x_debut_suivant, y_debut_suivant

if len(DP3) >= 2016:
    print DP3(2015)
else:
    print "len(DP3) = ", len(DP3)

print "Durée = ", walltime(temps)
2018-10-27 10:43:32 +0200 received badge  Supporter (source)
2018-10-27 10:21:52 +0200 commented answer Strange factoring in e = (x+1)^3*(x+2)^3*(x+3)^3*(x+4)^3

Thank you very much for your answer. I think I understand it and do exercises on this subject. Actually print q in my code would have put me on the path. But I also believe that I still have a lot of work to do in the field of SAGE. I have downloaded the free book "Calcul Mathématique avec Sage- Alexandre Casamayou Nathann Cohen ....) and I will study particularly the chapters 11 and 7 that will be very useful, I think, to understand your explanation. Not a problem because I'm retired - I'm 78 years old - and I enjoy solving the little problems that I encounter on the internet (like Euler Project, Turing Challenge, ...) Again thank you for your answer. Excuse me for my Google translation.

2018-10-24 14:48:08 +0200 received badge  Editor (source)
2018-10-24 14:44:40 +0200 asked a question Strange factoring in e = (x+1)^3*(x+2)^3*(x+3)^3*(x+4)^3

After reading a question about QUORA I had fun with Sage to test expressions factoring. If I ask to factorize e = (x+1)^3(x+2)^3(x+3)^3 everything is ok. But when I ask to factorize e = (x+1)^3(x+2)^3(x+3)^3*(x+4)^3 the result surprises me and I do not understand why! Here is my script and the results.

var('q')
e = (x+1)^3*(x+2)^3*(x+3)^3
print e
print "solve: ", solve(e,x)
#
R = ComplexField(16)['x']       # 16 donne 3 décimales et 32 donne 8 décimales   
q = R(e)
print "factor: ", factor(q)
print 

e = (x+1)^3*(x+2)^3*(x+3)^3*(x+4)^3
print e
print "solve: ", solve(e,x)
#
R = ComplexField(16)['x']       # 16 donne 3 décimales   
q = R(e)
print factor(q)
print
#
R = ComplexField(32)['x']       # 32 donne 8 décimales   
q = R(e)
print factor(q)

Now the results

(x + 3)^3*(x + 2)^3*(x + 1)^3
solve:  [
x == -3,
x == -2,
x == -1
]
factor:  (x + 1.000)^3 * (x + 2.000)^3 * (x + 3.000)^3

(x + 4)^3*(x + 3)^3*(x + 2)^3*(x + 1)^3
solve:  [
x == -4,
x == -3,
x == -2,
x == -1
]
(x + 0.8452 - 0.1196*I) * (x + 0.8452 + 0.1196*I) * (x + 1.115 - 0.4330*I) * (x + 1.115 + 0.4330*I) * (x
+ 1.764 - 1.048*I) * (x + 1.764 + 1.048*I) * (x + 2.528) * (x + 2.988 - 1.554*I) * (x + 2.988 + 1.554*I)
* (x + 4.457 - 1.231*I) * (x + 4.457 + 1.231*I) * (x + 5.134)

(x + 1.00000000)^3 * (x + 2.00000000)^3 * (x + 3.00000000)^3 * (x + 4.00000000)^3

As you can see when I the use of ComplexField(16) give me 12 roots (10 complex ans 2 false reals for me).This is totally different of ComplexField(32) which give the right answer. Why? Thank you in advance for enlightening my lantern.

2018-10-24 12:01:52 +0200 commented question drawing the function y = |log x|

Thank you very much for the answers. They show me that I still have to study a lot Sage.

2018-10-24 12:01:52 +0200 received badge  Commentator
2018-10-19 13:51:12 +0200 asked a question drawing the function y = |log x|

When drawing the function y = |log x|, I know that x must be positive but I have varied x from -5 to 5 by habit. I had no error message and a graph having a part in the box x<0. I would have liked to attach the graphic but that is denied me.

    def y(x):
        return abs(log(x))

    G = plot(y, (-5,5), color='blue')
    G.show(aspect_ratio=1, axes = True, gridlines=True, ymin = -1, ymax = 6)
2017-09-18 01:58:32 +0200 received badge  Student (source)
2017-07-31 00:24:54 +0200 commented answer how find quickly the order of a long prime ?

thank you for your explanations. I see that I still have a lot to learn. It's frustrating to be stuck in solving a problem because I do not know all the tricks that make a program much more effective. Where can I find answers? Which book or site or ...?

2017-07-31 00:15:17 +0200 commented answer how accelerate this simple program

thank you for your explanations. I see that I still have a lot to learn. It's frustrating to be stuck in solving a problem because I do not know all the tricks that make a program much more effective. Where can I find answers? Which book or site or ...?

2017-07-29 00:14:16 +0200 commented answer how accelerate this simple program

Good evening. A very big thank you for your long explanation that I find extraordinary. I would never have thought of doing that. I read and reread your text several times and I think I understood the principle. The result is found in just over a second! It's awesome

2017-07-28 23:41:36 +0200 commented answer how accelerate this simple program

Indeed your code works more than 100 times faster. I do not understand why RR (math.sqrt (n)) is 100 times faster than N (sqrt (n)). Where can I find an explanation (as simple as possible)?

I tried your cython code and I get the following error.

compilation terminated. error: command 'gcc' failed with exit status 1

Is not Sagemat already written in cython?

2017-07-28 23:24:49 +0200 commented answer how find quickly the order of a long prime ?

Thank you for your feedback. They remind me of my early years (I am 77 years old) when I tried to understand and assimilate the theorems of Fermat and Wilson. At the time I found it very difficult. Now, with a computer, as it is possible to experiment I try to solve problems (found on Euler and Turing project sites). If you could advise me a book or documents dealing with the simplest way possible by examples I will be grateful.

2017-07-28 00:37:44 +0200 asked a question how accelerate this simple program

Hello everybody. Here is my question We seek integers of which the decimal part of their square root begin by 2017. Sample: sqrt(10858) = 104.201727.... Here is my program:

for n in range (1, 10^5):
    if int(  N(sqrt(n)).frac() * 10000 )  == 2017:
        cpt += 1

the problem is it takes too much time. For the bound 10^5 it takes about 55 sec on my iMac, for 10^6 it takes 620 sec, for 10^7 it takes almost 6000 sec ... The question is to obtain the result for the bound 10^10 !

2017-07-27 18:49:25 +0200 marked best answer how find quickly the order of a long prime ?

Is it a quicker way for finding the order of a long prime without the inner loop for? I know that a prime number p is long iif is order is order is p-1

  for n in range(6, 50):
    if is_prime(n):
        for i in range(1, n):
            m = 10^i % n
            if m==1:
                print n, "ordre=", i
                #if i == n-1: print "-> premier long",
                #print
                break