Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5976051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:10:23+00:00 2026-05-22T21:10:23+00:00

How do I tell mathematica to do this replacement smartly? (or how do I

  • 0

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 /. a + b :> 1

Out = 2 a + b + c d + ec

I expect the answer to be a + cd + ec + 1. And before someone suggests, I don’t want to do a :> 1 - b, because for aesthetic purposes, I’d like to have both a and b in my equation as long as the a+b = 1 simplification cannot be made.


In addition, how do I get it to replace all instances of 1-b, -b+1 or -1+b, b-1 with a or -a respectively and vice versa?

Here’s an example for this part:

expr = b + c (1 - a) + (-1 + b)(a - 1) + (1 -a -b) d + 2 a
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:10:24+00:00Added an answer on May 22, 2026 at 9:10 pm

    You can use a customised version of FullSimplify by supplying your own transformations to FullSimplify and let it figure out the details:

    In[1]:= MySimplify[expr_,equivs_]:= FullSimplify[expr,
              TransformationFunctions ->
                Prepend[
                  Function[x,x-#]&/@Flatten@Map[{#,-#}&,equivs/.Equal->Subtract],
                  Automatic
                ]
            ]
    In[2]:= MySimplify[2a+b+c*d+e*c, {a+b==1}]
    Out[2]= a + c(d + e) + 1
    

    equivs/.Equal->Subtract turns given equations into expressions equal to zero (e.g. a+b==1 -> a+b-1). Flatten@Map[{#,-#}&, ] then constructs also negated versions and flattens them into a single list. Function[x,x-#]& /@ turns the zero expressions into functions, which subtract the zero expressions (the #) from what is later given to them (x) by FullSimplify.

    It may be necessary to specify your own ComplexityFunction for FullSimplify, too, if your idea of simple differs from FullSimplify‘s default ComplexityFunction (which is roughly equivalent to LeafCount), e.g.:

    MySimplify[expr_, equivs_] := FullSimplify[expr,
      TransformationFunctions ->
        Prepend[
          Function[x,x-#]&/@Flatten@Map[{#,-#}&,equivs/.Equal->Subtract],
          Automatic
        ],
      ComplexityFunction -> (
        1000 LeafCount[#] + 
        Composition[
          Total,Flatten,Map[ArrayDepth[#]#&,#]&,CoefficientArrays
        ][#] &
      )
    ]
    

    In your example case, the default ComplexityFunction works fine, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement this in Mathematica: I realize I can use ParametricPlot to
This is another simple 'matrix' question in Mathematica. I want to show how I
please tell me how to get and bind data to UltraGrid dynamically on each
The sha1 hash of abc is a9993e364706816aba3e25717850c26c9cd0d89d The only way to get Mathematica to
Could someone please help and tell me how to include IEEE mathematical functions in
please tell me theres a way around this... $my_var = 'hello'; class Test{ private
How can we tell Mathematica to gives us a set of non-intersecting lines? In
I found this open-source library that I want to use in my Java application.
Please tell me if this is correct. In my error handler, I need to
Please tell me whats wrong with this c# code.. public bool CloseCOMPort() { try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.