Ask Your Question

Is it possible to change the default ordering of added terms?

asked 2023-09-20 10:12:33 +0200

Smrz gravatar image

sage seems to have a default ordering for terms added together in an expression. E.g. if I enter


it will be displayed as

-(b -1)

I.e. the variable is always first and the number always second. While -(b - 1) is correct, in some contexts (1-b) is clearer and more conventional. Is there anyway to change the ordering of terms so that entering (1-b) displays as (1-b)?


edit retag flag offensive close merge delete


How b is defined?

Max Alekseyev gravatar imageMax Alekseyev ( 2023-09-20 15:45:01 +0200 )edit

b = var("b")

Smrz gravatar imageSmrz ( 2023-09-21 03:24:24 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2023-09-28 07:45:15 +0200

Emmanuel Charpentier gravatar image

updated 2023-09-28 07:47:00 +0200

(Answer added to make it easier to find it while perusing this site)

Is there anyway to change the ordering of terms so that entering (1-b) displays as (1-b)?


Sage insists on displaying symbolic expressions in its "preferred order" :

sage: foo=1-x ; foo
-x + 1

This Very Frequently Asked Question has already caused much tears, wails and teeth gnashing ; the examples quoted by Max Alexeyev are but a small sample... As pointed out in one of these, acting on this defaul format woul require deep surgery in ginac code, which is a minefield (with rusty, unstable mines...).

Since the problem is stricly cosmetic, this difficult task is deemed low priority...


edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2023-09-20 10:12:33 +0200

Seen: 160 times

Last updated: Sep 28 '23