How to get an expression in the form (n+1)/(n−k+1) instead of -(n+1)/(k−n−1)?

29 views
Skip to first unread message

lv航宇

unread,
Jul 16, 2025, 2:09:01 AMJul 16
to sage-support
我想知道为什么下面的代码以 -(n + 1)/(k - n - 1) 的形式计算结果。有没有办法让它返回类似于 (n + 1)/(n - k + 1) 的形式?
'''python
_ = var('k n')
假设 (n > k)
假设 (n - k + 1 > 0)
结果 = (n + 1)/(n - k + 1)
结果
```
提前感谢您的帮助!

Nils Bruin

unread,
Jul 16, 2025, 2:13:48 AMJul 16
to sage-support
Assuming you are asking the question in the title (and assuming that you can somehow use this answer written in english):

I suspect the issue here is that the engine responsible for simplifying symbolic expressions prefers the denominator to be "monic" and that it orders the variables alphabetically. Hence, it wants the coefficient in front of "k" to be 1 in the denominator and not the one in front of "n". If you change your example to
```
var("n,p")
-(n+1)/(p-n-1)
```
you see that it rewrites it in the form you desire (albeit with a p in the place of k).
Reply all
Reply to author
Forward
0 new messages