Message Boards Message Boards

0
|
4121 Views
|
9 Replies
|
7 Total Likes
View groups...
Share
Share this post:

Display polynomial retaining MonomialList[ ] order?

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.

POSTED BY: Jay Gourley
9 Replies

Thanks. J.M. I didn't know about Inactive.

POSTED BY: Jay Gourley
Posted 2 years ago

Another possibility is to just use an inactivated version of Plus:

expr = 4 x y^2 z + 4 z^2 - 5 x^3 + 7 x^2 z^2;
ordList = {"Lexicographic", "DegreeLexicographic", "DegreeReverseLexicographic",
           "NegativeLexicographic", "NegativeDegreeLexicographic",
           "NegativeDegreeReverseLexicographic"};

Apply[Inactive[Plus], MonomialList[expr, #]] & /@ ordList

and one can easily get back the original polynomial using Activate[]; e.g.

Activate[Last[%]]
POSTED BY: J. M.

Yes, Rohit. It appears to be the same issue. I think I misunderstood the "orders = ..." line in your previous post. Today I found the tutorial on patterns. I'm going through it now.

POSTED BY: Jay Gourley
Posted 2 years ago

Hi Jay,

Isn't this the same issue that was solved using the Injector Pattern earlier in this post?

MonomialList[a x^2 + b x y + c y^2, {y, x}] // Replace[#, {x__} :> HoldForm[+x]] &
(* c y^2 + b x y + a x^2 *)

If you evaluate it, it will of course revert to lexicographic.

POSTED BY: Rohit Namjoshi

Rohit Namjoshi solution works for standard order, but I'm having trouble generalizing this other variable orders. For example,...

POSTED BY: Jay Gourley

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.

POSTED BY: Jay Gourley
Posted 2 years ago

You are a genius

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

POSTED BY: Rohit Namjoshi

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.

POSTED BY: Jay Gourley
Posted 2 years ago

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.

POSTED BY: Rohit Namjoshi
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