Message Boards Message Boards

GROUPS:

Display polynomial retaining MonomialList[ ] order?

Posted 6 days ago
142 Views
|
4 Replies
|
1 Total Likes
|

MonomialList is a neat functions for rearranging a polynomial, but if you convert it back to a polynomial with Total[] or Plus[], the output reverts to the default lexicographic order, which sabotages the functionality of MonomialList[]. Is there a way to rearrange a polynomial according to MonomialList[] options? By that, I mean a way that's easier than editing the list back into a polynomial character by character?

For example: Say you have a polynomial like 4 x y^2 z + 4 z^2 - 5 x^3 + 7 x^2 z^2 and want to display it three different ways -- Lexicographic order, DegreeLexicographic order and NegativeDegreeLexicographic order.

4 Replies

Hi Jay,

Here is one way that I saw on MSE. I searched but cannot find it

ClearAll[x, y, x];
exp = 4 x y^2 z + 4 z^2 - 5 x^3 + 7 x^2 z^2

orders = MonomialList[exp, #] & /@ {"Lexicographic", "DegreeLexicographic", 
  "DegreeReverseLexicographic", "NegativeLexicographic", 
  "NegativeDegreeLexicographic", "NegativeDegreeReverseLexicographic"}
(* {{-5 x^3, 7 x^2 z^2, 4 x y^2 z, 4 z^2}, {7 x^2 z^2, 4 x y^2 z, -5 x^3,
   4 z^2}, {4 x y^2 z, 7 x^2 z^2, -5 x^3, 4 z^2}, {4 z^2, 4 x y^2 z, 
  7 x^2 z^2, -5 x^3}, {4 z^2, -5 x^3, 7 x^2 z^2, 
  4 x y^2 z}, {4 z^2, -5 x^3, 4 x y^2 z, 7 x^2 z^2}}  *)

Replace[orders, {x__} :> HoldForm[+x], 1]

enter image description here

Shown as an image since it is a held expression and releasing the hold will revert to lexicographic.

Thanks, Rohit. You are a genius. I just read the Replace[] documentation, and I still don't understand why this works. But it does. Thumbs up.

You are a genius

Ummm... no. Definitely not me. I searched again on MSE and found it.

You're too modest. I would not have recognized that MSE thread as an answer to my question had I seen it. In fact, I've seen it now, and I still don't recognize it as an answer to my question. Clarity is the ultimate genius. The guys who figured out what Gauss was saying were smarter than Gauss.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract