Hi sage devs,

I am proposing contribution to sage.
Attaching https://j.ludost.net/code/algdep_numeric.py.txt

>From the comments:

    Given a list F of numeric lists F_{i,1},F_{i,2},...F_{i,k}
    Finds a list of polynomials G_i, such that G_i(F_j)=0
    Examples:

    F=[ [ZZ(fibonacci(2*i)),fibonacci(2*i+1)] for i in range(2,50)]
    ag=algdepanalytic(F,D=2,check=1);ag
    [x0^2 + x0*x1 - x1^2 + 1]

    The X coordinate of an Elliptic Curve over finite field:
    F=[ X(n*P),X((n+1)*P)]

    p=next_prime(10**3);K=GF(p)
    E=EllipticCurve(GF(p),[0,2]);P=E.gens()[0]
    def X_n(P,n):  return (n*P).xy()[0]
    F=[ [X_n(P,2*i),X_n(P,2*i+1)] for i in range(2,47)]
    ag=algdepanalytic(F,D=4,check=1);ag
[126*x0^2*x1^2 - 97*x0^2*x1 - 97*x0*x1^2 + 353*x0^2 + 303*x0*x1 +
353*x1^2 + x0 + x1 - 388]

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/CAGUWgD8s3QX5AVJ1Pfx%3D-PnopjKNTg93o51Fa_t5vQ1%3D5WezZA%40mail.gmail.com.
def algdepanalytic(F,D=4,check=False,K=None):
    """
    sage code for algebraic dependendecy of numerical data
    Author:  Georgi Guninski, ggunin...@gmail.com, gunin...@guninski.com
    Version:  2.0, Mon 06 Feb 2023
    Project page:  https://j.ludost.net/code
    Given a list F of numeric lists F_{i,1},F_{i,2},...F_{i,k}
    Finds a list of polynomials G_i, such that G_i(F_j)=0
    Examples:
    
    FI=[fibonacci(2*i),fibonacci(2*i+1)]
    def FI(n):  return fibonacci(n)
    F=[ [ZZ(fibonacci(2*i)),fibonacci(2*i+1)] for i in range(2,50)]
    ag=algdepanalytic(F,D=2,check=1);ag
    [x0^2 + x0*x1 - x1^2 + 1]

    The X coordinate of an Elliptic Curve over finite field:
    F=[ X(n*P),X((n+1)*P)]

    p=next_prime(10**3);K=GF(p)
    E=EllipticCurve(GF(p),[0,2]);P=E.gens()[0]
    def X_n(P,n):  return (n*P).xy()[0]
    F=[ [X_n(P,2*i),X_n(P,2*i+1)] for i in range(2,47)]
    ag=algdepanalytic(F,D=4,check=1);ag
[126*x0^2*x1^2 - 97*x0^2*x1 - 97*x0*x1^2 + 353*x0^2 + 303*x0*x1 + 353*x1^2 + x0 + x1 - 388]


    """
    n=len(F[0])
    if K is None:  K=F[0][0].base_ring()
    Kx=PolynomialRing(K,x,n)
    ge=Kx.gens()
    mo=prod(ge)**D
    mo=Kx.monomial_all_divisors(mo)
    mo=[i for i in mo if i.degree()<=D]
    mo += [Kx(1)]
    if len(F)<len(mo) and check:  
        print("underdetermined")
        raise Exception(f"underdetermined and check=True need={len(mo)}")
    J=[]
    for P in F:
        l=[i(P) for i in mo]
        J.append(l)
    M=Matrix(K,J)
    ke=list(M.right_kernel().basis())
    res=[]
    for k in ke:
        S=sum(i*j for i,j in zip(k,mo))
        res += [S]
    return res

Reply via email to