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 6917089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:41:11+00:00 2026-05-27T09:41:11+00:00

I have this expression in Mathematica: (a^2 (alpha + beta)^2)/(b^2 + c^2) + (a

  • 0

I have this expression in Mathematica:

(a^2 (alpha + beta)^2)/(b^2 + c^2) + (a (alpha + beta))/(b^2 + c^2) + 1  

As you can see, the expression has a couple of subexpressions that repeat throughout it.

I want to be able to replace a/(b^2+c^2) with d and alpha+beta with gamma.

The final expression should then be:

1+d*gamma+a*d*gamma^2

I have much more complicated expressions where being able to do this would greatly simplify my work.

I have tried Googling this question, and I only find answers that use FactorTerms and ReplaceRepeated, but do not work consistently and for a more complicated expression like this one. I am hoping that someone here has the answer.

  • 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-27T09:41:11+00:00Added an answer on May 27, 2026 at 9:41 am

    The hard part for the case at hand is the rule for d. Perhaps, there are simpler ways to do it, but one way is to expand the powers to products, to make it work. Let’s say this is your expression:

    expr  = (a^2 (alpha + beta)^2)/(b^2 + c^2) + (a (alpha + beta))/(b^2 + c^2) + 1
    

    and these are the rules one would naively write:

    rules = {a/(b^2 + c^2) -> d, alpha + beta -> gamma}
    

    What we would like to do now is to expand powers to products, in both expr and rules. The problem is that even if we do, they will auto-evaluate back to powers. To prevent that, we’ll need to wrap them into, for example, Hold. Here is a function which will help us:

    Clear[withExpandedPowers];
    withExpandedPowers[expr_, f_: Hold] :=
      Module[{times},
        Apply[f,
           Hold[expr] /. x_^(n_Integer?Positive) :>
              With[{eval = times @@ Table[x, {n}]}, eval /; True] /.
           times -> Times //.
           HoldPattern[Times[left___, Times[middle__], right___]] :>
              Times[left, middle, right]]];
    

    For example:

    In[39]:= withExpandedPowers[expr]
    Out[39]= Hold[1+(a (alpha+beta))/(b b+c c)+((alpha+beta) (alpha+beta) a a)/(b b+c c)]
    

    The following will then do the job:

    In[40]:= 
    ReleaseHold[
       withExpandedPowers[expr] //. 
          withExpandedPowers[Map[MapAt[HoldPattern, #, 1] &, rules], Identity]]
    
    Out[40]= 1 + d gamma + a d gamma^2
    

    We had to additionally wrap the l.h.s. of rules in HoldPattern, to prevent products from collapsing back to powers there.

    This is just one case where we had to fight the auto-simplification mechanism of Mathematica, but for this sort of problems this will be the main obstacle. I can’t assess how robust this will be for larger and more complex expressions.

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

Sidebar

Related Questions

I have this Regular Expression that matches the following strings: <!-- 09-02-2009 ---> <!--
Right now I have something like this in NHibernate: Expression.Like(property, value, MatchMode.Anywhere) and that
I have a data that looks like this 1:SRX000566 Submitter: WoldLab Study: RNASeq expression
I have a large mathematical expression that has to be created dynamically. For example,
I have a very complicated mathematica expression that I'd like to simplify by using
I want to validate number in range of 0-255 I have this expression '/^([0-1]?[0-9]?[0-9])|([2][0-4][0-9])|(25[0-5])$/'
I have this regular expression: ^\$?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$ however it is failing when i have an
I am very confused. I have this lambda expression: tvPatientPrecriptionsEntities.Sort((p1, p2) => p1.MedicationStartDate .Value
The following code fails in 'Evaluate' with: This expression was expected to have type
I have a this line of code: var predicate = Expression.Lambda<Func<TEntityType, bool>>(body, param); where

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.