Denominator and implicit orderings

Ewan Delanoy <[email protected]> Sun, 08 Feb 2026 14:43:50 +0100
Newsgroups gmane.comp.mathematics.pari.user
Message-ID <[email protected]>
The PARI-GP user manual (version 2.17.2) opines pessimistically that "Unfortunately, in some functions like content and denominator, there is no way to set explicitly a main variable like in divrem and remove the dependence on implicit orderings."



I'm in a slightly different situation, I have no interest in setting the main variable or modifying the variable

ordering. I just want to have a function



order_independent_denominator(rational_expr,list_of_vars)



such that



order_independent_denominator(v1/(v2^2+1),[v1,v2]) returns  v2^2+1,

order_independent_denominator(v2/(v1^2+1),[v1,v2]) returns  v1^2+1



Here is my take on it :



order_independent_denominator(rational_expr,list_of_vars)={

    my(n,var,modified);

    n=length(list_of_vars);

    for(k=1,n,

    var=list_of_vars[k];

    modified=subst(rational_expr,var,'x);

    if(type(modified)=="t_RFRAC",return(subst(denominator(modified),'x,var)););

    );

    return(1);

}



I'm not sure if the above might fail when 'x is among list_of_vars ?