Kevin Acres on Fri, 09 Feb 2024 13:02:22 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Rational exponent


I've added a small example for an exponent of -1. Ideally I need to accept any rational exponent here without SER/POL clashes.

Kevin.

On 2024-01-31 23:59, Kevin Acres wrote:
I have a function that I would like to use with rational exponents.
Currently it only works with integral exponents.

I'm struggling a little and any help is welcomed.

Kevin.

/*
 * z : Integer input 0..2^n-1
 * p : irreducible polynomial of degree n
 * n : output is in binary format 0..2^n-1
 * e : exponent
*/
fn2(z,p,n,e) = {
    my(s,t=vector(n)~,k,a);

    if(z==0, return(t~););
    k = Pol(binary(z))^e;
    a = lift(Mod(k, p));
    s=Vecrev(a);
    s *= denominator(s);
    s %= 2;
    for(i=1,#s,
        t[i]=s[i];
    );
    t~;
};

A short example for an exponent of -1. Ideally I need to be able to use rational exponents instead of -1.

    for(i = 1, 10,
        r = fn2(i-1, poly, e, -1);
        print([i, poly, e, -1, r]);
    );

[1, x^6 + x^4 + x^3 + 1, 6, -1, [0, 0, 0, 0, 0, 0]]
[2, x^6 + x^4 + x^3 + 1, 6, -1, [1, 0, 0, 0, 0, 0]]
[3, x^6 + x^4 + x^3 + 1, 6, -1, [0, 0, 1, 1, 0, 1]]
[4, x^6 + x^4 + x^3 + 1, 6, -1, [1, 1, 1, 0, 1, 1]]
[5, x^6 + x^4 + x^3 + 1, 6, -1, [0, 1, 1, 0, 1, 0]]
[6, x^6 + x^4 + x^3 + 1, 6, -1, [1, 1, 1, 0, 1, 1]]
[7, x^6 + x^4 + x^3 + 1, 6, -1, [1, 1, 1, 0, 1, 1]]
[8, x^6 + x^4 + x^3 + 1, 6, -1, [1, 0, 1, 1, 1, 1]]
[9, x^6 + x^4 + x^3 + 1, 6, -1, [1, 1, 0, 1, 0, 0]]
[10, x^6 + x^4 + x^3 + 1, 6, -1, [1, 1, 1, 0, 1, 1]]