Question on “smart” replacing in mathematica

后端 未结 2 1812
[愿得一人]
[愿得一人] 2020-12-30 13:27

How do I tell mathematica to do this replacement smartly? (or how do I get smarter at telling mathematica to do what i want)

expr = b + c d + ec + 2 a;
expr          


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-30 14:21

    For the first case, you might consider:

    expr = b + c d + ec + 2 a
    
    PolynomialReduce[expr, {a + b - 1}, {b, a}][[2]]
    

    For the second case, consider:

    expr = b + c (1 - a) + (-1 + b) (a - 1) + (1 - a - b) d + 2 a;
    
    PolynomialReduce[expr, {x + b - 1}][[2]]
    
    (% /. x -> 1 - b) == expr // Simplify
    

    and:

    PolynomialReduce[expr, {a + b - 1}][[2]]
    
    Simplify[% == expr /. a -> 1 - b]
    

提交回复
热议问题