5
$\begingroup$

For inexact coefficients MonomialList seems to apply N. How to avoid this?

expr = 1.0c[1] x ;
MonomialList[expr, {x}]
(* {1. x c[1.]}  *)

It is possible to:

SetAttributes[c, NHoldAll] ;
expr =1.0c[1] x ;
MonomialList[expr, {x}]
(* {1. x c[1]}  *)

But this fails in the following case:

SetAttributes[c, NHoldAll] ;
expr =1.0c[1] [1]x ;
MonomialList[expr, {x}]
{1. x c[1][1.]} 

It is possible to use ReplaceAll and Rationalizeto post-process the result, but this is some extra work I want to avoid.

$\endgroup$
5
  • 5
    $\begingroup$ I consider it to be a bug. There is no reason why the function should do anything to the coefficients except collecting them. $\endgroup$ Commented Sep 28, 2025 at 9:56
  • 1
    $\begingroup$ @azerbajdzan Seems like it, I've filed a bug report, will update based on their response $\endgroup$ Commented Sep 28, 2025 at 10:49
  • 1
    $\begingroup$ (1) The behavior of MonomialList[] aside, note that attributes do not apply to sub-value expressions. So NHoldHall protects the argument 1 of c in the expression N[c[1]] but not the argument 2 of c[1] in N[c[1][2]]. (2) As for MonomialList[], it explicitly sets the precision of the result to the precision of the input. So it seems intentional, but I don't know the reason why. $\endgroup$ Commented Sep 28, 2025 at 13:30
  • 2
    $\begingroup$ I’ll go with the “it’s a bug” view. $\endgroup$ Commented Sep 28, 2025 at 16:39
  • 1
    $\begingroup$ As a workaround, I would write 1.0 c[1, 1] x instead of 1.0 c[1][1] x. $\endgroup$ Commented Sep 29, 2025 at 2:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.