Skip to main content
added 267 characters in body
Source Link

I ran into a problem with CoefficientRules behaving differently with exact and numerical coefficients, where in the numerical case it behaves as if the entire expression had an N[...] around it, numericizing all numbers, including indices and subscripts.

E.g.,

CoefficientRules[A[0] x + A[1] y + 1, {x, y}]

works as intended, but

CoefficientRules[A[0] x + A[1] y + 1., {x, y}]

does not, as it has A[0.] and A[1.] in the result.

Is there an easy way to stop this from happening or to convert back the wrong results to their correct form?

Edit: one general workaround I found is to use subscripts such as Subscript[A,0] instead of expressions that could be interpreted as function evaluations. That also works with multiple indices and non-integer parameters, for which some of the other suggested workarounds do not.

I ran into a problem with CoefficientRules behaving differently with exact and numerical coefficients, where in the numerical case it behaves as if the entire expression had an N[...] around it, numericizing all numbers, including indices and subscripts.

E.g.,

CoefficientRules[A[0] x + A[1] y + 1, {x, y}]

works as intended, but

CoefficientRules[A[0] x + A[1] y + 1., {x, y}]

does not, as it has A[0.] and A[1.] in the result.

Is there an easy way to stop this from happening or to convert back the wrong results to their correct form?

I ran into a problem with CoefficientRules behaving differently with exact and numerical coefficients, where in the numerical case it behaves as if the entire expression had an N[...] around it, numericizing all numbers, including indices.

E.g.,

CoefficientRules[A[0] x + A[1] y + 1, {x, y}]

works as intended, but

CoefficientRules[A[0] x + A[1] y + 1., {x, y}]

does not, as it has A[0.] and A[1.] in the result.

Is there an easy way to stop this from happening or to convert back the wrong results to their correct form?

Edit: one general workaround I found is to use subscripts such as Subscript[A,0] instead of expressions that could be interpreted as function evaluations. That also works with multiple indices and non-integer parameters, for which some of the other suggested workarounds do not.

Source Link

CoefficientRules numericizing parameters

I ran into a problem with CoefficientRules behaving differently with exact and numerical coefficients, where in the numerical case it behaves as if the entire expression had an N[...] around it, numericizing all numbers, including indices and subscripts.

E.g.,

CoefficientRules[A[0] x + A[1] y + 1, {x, y}]

works as intended, but

CoefficientRules[A[0] x + A[1] y + 1., {x, y}]

does not, as it has A[0.] and A[1.] in the result.

Is there an easy way to stop this from happening or to convert back the wrong results to their correct form?