Ask Your Question
0

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

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

Smrz gravatar image

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

(1-b)

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)?

thanks

edit retag flag offensive close merge delete

Comments

How b is defined?

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

b = var("b")

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

1 Answer

Sort by ยป oldest newest most voted
1

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

Emmanuel Charpentier gravatar image

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

(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)?

Nope.

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...

HTH,

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

Stats

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

Seen: 230 times

Last updated: Sep 28 '23