@@ -691,7 +691,7 @@ cdef class fmpq_mpoly(flint_mpoly):
691691
692692 def subs (self , dict_args ) -> fmpq_mpoly:
693693 """
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 ,
695695 all values must be fmpq.
696696
697697 >>> from flint import Ordering
@@ -703,26 +703,18 @@ cdef class fmpq_mpoly(flint_mpoly):
703703 """
704704 cdef:
705705 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
715707
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")
720712
721713 # Partial application with args in Q. We evaluate the polynomial one variable at a time
722714 res = create_fmpq_mpoly(self .ctx)
723715
724716 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:
726718 if fmpq_mpoly_evaluate_one_fmpq(res.val , res.val , i , (<fmpq>arg ).val , self.ctx.val ) == 0:
727719 raise ValueError("unreasonably large polynomial") # pragma: no cover
728720 return res
0 commit comments