not easily reproducible QQbar bug

40 views
Skip to first unread message

Martin R

unread,
Jan 13, 2022, 9:05:41 AM1/13/22
to sage-devel
I have some very strange behaviour of a substitution, which I don't know how to reproduce, but it happens from time to time, and is REALLY disturbing.  I don't even know what to write into a ticket, so I'm asking here first.  The definition of CSP is at the end of the mail.

sage:     R.<q> = ZZ[]
sage: p = q^21 + q^20 + q^19 + q^18 + q^17 + q^16 + q^15 + q^14 + q^13 + q^12 + q^11 + 2*q^10 + 2*q^9 + 2*q^8 + 2*q^7 + 2*q^6 + 2*q^5 + 2*q^4 + 2*q^3 + 2*q^2 + 3*q + 4
sage: p == CSP(22)
True
sage: CSP(22).subs({q:QQbar.zeta(2)})
-28
sage: CSP(22).subs({q:QQbar.zeta(2)})
2
sage: CSP(22).parent()
Univariate Polynomial Ring in q over Integer Ring

Sometimes I also get a complex number.

Martin

###################
def cycle_power(g, e):
    """
    Return k such that g^k = e
    """
    if e.is_one():
        return 0
    k = 1
    p = g
    while True:
        if e == p:
            return k
        p *= g
        k += 1

@cached_function
def CSP(n):
    C = groups.permutation.Cyclic(n)
    g = C.gen()
    R.<q> = ZZ[]
    return sum(q^min(cycle_power(g, e) for e in coset) for H in C.subgroups() for coset in C.cosets(H))

Vincent Delecroix

unread,
Jan 13, 2022, 9:09:57 AM1/13/22
to sage-...@googlegroups.com
Could you be more specific : Which sage version ? which setup ?

Vincent

Martin R

unread,
Jan 13, 2022, 9:16:31 AM1/13/22
to sage-devel
ubuntu 21.04
'SageMath version 9.5.beta7, Release Date: 2021-11-18'

John Cremona

unread,
Jan 13, 2022, 9:34:02 AM1/13/22
to SAGE devel
1. You could be using discrete_log() or one of its variants instead of
your cycle_power() function.

2. In CSP() would it not be faster to work out for each power h=g^k,
how many times h will arise and hence the coefficient of q^k? The
pattern in your example is fairly simple to see.

I know that neither of these points answers your actual question...

John

> @cached_function
> def CSP(n):
> C = groups.permutation.Cyclic(n)
> g = C.gen()
> R.<q> = ZZ[]
> return sum(q^min(cycle_power(g, e) for e in coset) for H in C.subgroups() for coset in C.cosets(H))
>
> --
> You received this message because you are subscribed to the Google Groups "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/a013e022-a007-4748-9a67-ae1e45f3e825n%40googlegroups.com.

Martin R

unread,
Jan 13, 2022, 9:41:51 AM1/13/22
to sage-devel
I agree to all of your 3 points :-)

Vincent Delecroix

unread,
Jan 13, 2022, 11:49:18 AM1/13/22
to sage-...@googlegroups.com
I am not able to reproduce. I ran 1000 times the same code snippet
you provided on all the sage that I have around me. Do you have the
bug in a fresh session or after some hours of other unrelated
computations? In the first case, you can try to reproduce with

1. In an instance where you have the bug (at the start of a
fresh session), get the initial random seed with initial_seed()

2. Start a fresh session, set the initial seed with
set_random_seed(value_from_point_1_above) and rerun
the code snippet

Best
Vincent
Reply all
Reply to author
Forward
0 new messages