@@ -691,7 +691,7 @@ cdef class fmpq_mpoly(flint_mpoly):
691
691
692
692
def subs (self , dict_args ) -> fmpq_mpoly:
693
693
"""
694
- Partial evaluate this polynomial with select constants. Keys must be generator names ,
694
+ Partial evaluate this polynomial with select constants. Keys must be generator names or generator indices ,
695
695
all values must be fmpq.
696
696
697
697
>>> from flint import Ordering
@@ -703,26 +703,18 @@ cdef class fmpq_mpoly(flint_mpoly):
703
703
"""
704
704
cdef:
705
705
fmpq_mpoly res
706
- slong i , nargs
707
-
708
- args = tuple ((i, dict_args[x]) for i, x in enumerate (self .ctx.names()) if x in dict_args)
709
- nargs = len (args)
710
-
711
- # If we've been provided with an invalid generator name then the length of our filter
712
- # args will be less than what we've been provided with.
713
- if nargs < len(dict_args ):
714
- raise ValueError (" unknown generator name provided" )
706
+ slong i
715
707
716
- args_fmpq = tuple (any_as_fmpq(v) for _ , v in args )
717
- for arg in args_fmpq :
718
- if arg is NotImplemented :
719
- raise TypeError (f" cannot coerce argument ('{arg }') to fmpq" )
708
+ args = tuple (( self .ctx.variable_to_index(k), any_as_fmpq(v)) for k , v in dict_args.items() )
709
+ for _ , v in args :
710
+ if v is NotImplemented:
711
+ raise TypeError(f"cannot coerce argument ('{v }') to fmpq")
720
712
721
713
# Partial application with args in Q. We evaluate the polynomial one variable at a time
722
714
res = create_fmpq_mpoly(self .ctx)
723
715
724
716
fmpq_mpoly_set(res.val , self.val , self.ctx.val )
725
- for ( i, _), arg in zip ( args, args_fmpq) :
717
+ for i , arg in args:
726
718
if fmpq_mpoly_evaluate_one_fmpq(res.val , res.val , i , (<fmpq>arg ).val , self.ctx.val ) == 0:
727
719
raise ValueError("unreasonably large polynomial") # pragma: no cover
728
720
return res
0 commit comments