Removing fractions without a particular variableFilter out all terms not involving a given variableAdd...

How do you funnel food off a cutting board?

Program that converts a number to a letter of the alphabet

How to remove trailing forward slash

Implicit conversion and operator overload

Cryptic with missing capitals

What makes the Forgotten Realms "forgotten"?

Is there a rule for the nth root of a radical?

Can we use the stored gravitational potential energy of a building to produce power?

Why would the Pakistan airspace closure cancel flights not headed to Pakistan itself?

Is a debit card dangerous for an account with low balance and no overdraft protection?

Can a person refuse a presidential pardon?

Why don't American passenger airlines operate dedicated cargo flights any more?

Would a National Army of mercenaries be a feasible idea?

Why did the villain in the first Men in Black movie care about Earth's Cockroaches?

Reference on complex cobordism

It took me a lot of time to make this, pls like. (YouTube Comments #1)

Quenching swords in dragon blood; why?

Can you earn endless XP using a Flameskull and its self-revival feature?

Why do members of Congress in committee hearings ask witnesses the same question multiple times?

Can pricing be copyrighted?

How to acknowledge an embarrassing job interview, now that I work directly with the interviewer?

Checking for the existence of multiple directories

Why is "points exist" not an axiom in geometry?

Explain the objections to these measures against human trafficking



Removing fractions without a particular variable


Filter out all terms not involving a given variableAdd Pattern to List Removing DuplicatesHow to make this particular replacement involving expAutomatic substitution of fractionsHow to select the value of a substitution rule for a particular variable?Why is `Block` significantly faster than `ReplaceAll` for inputting variable valuesApply tranformation to particular list elementsMake substitutions without specifying the objectHow to replace Variable With Variableusing DeleteCases to delete vectors with particular index as 0Relative Chop for Fractions with Trigonometric Terms













2












$begingroup$


As a very minimal example, consider a sum of fractions such as:



$A=frac{a}{s_{123}bc}+frac{d}{e}$



In practice, I have many hundreds of thousands of these fractions generated from a recursion relation. My desired result comes around from the prescription in my theory, where I am required to multiply through by $s_{123}$ and then take $s_{123}to 0$. Upon replicating in MMA, I use a code similar to:



A*s[1,2,3]//Expand
%/.{s[1,2,3]->0}


This Expand is necessary since by simply multiplying A by the relevant factor, MMA will first interpret it as $s_{123} big (frac{a}{s_{123}bc}+frac{d}{e}big)$. I think this is what is slowing my code down substantially, and crashes MMA due to a lack of memory.



To get around this, I have had a few ideas;




  1. Use something like DeleteCase as a simple method (or something perhaps similar to Filter out all terms not involving a given variable which might be a bit overkill for my needs) to delete all terms not involving $s_{123}$, and then set the remaining factors of it in the leftover terms to 1.

  2. Instead of using Expand, define a new function which brings common factors inside to each fraction.


Which of these, alongside any other methods, would you suggest? How could I go about implementing them? I think 2 would be easier to do, but at this point, I am needing efficiency in my code on such a large scale.










share|improve this question











$endgroup$












  • $begingroup$
    You might find that working with a List of terms is better (e.g. effectively List@@A) than working with a sum of terms. Presumably Expand is comparing a large number of terms, looking for common subexpressions.
    $endgroup$
    – mikado
    3 hours ago
















2












$begingroup$


As a very minimal example, consider a sum of fractions such as:



$A=frac{a}{s_{123}bc}+frac{d}{e}$



In practice, I have many hundreds of thousands of these fractions generated from a recursion relation. My desired result comes around from the prescription in my theory, where I am required to multiply through by $s_{123}$ and then take $s_{123}to 0$. Upon replicating in MMA, I use a code similar to:



A*s[1,2,3]//Expand
%/.{s[1,2,3]->0}


This Expand is necessary since by simply multiplying A by the relevant factor, MMA will first interpret it as $s_{123} big (frac{a}{s_{123}bc}+frac{d}{e}big)$. I think this is what is slowing my code down substantially, and crashes MMA due to a lack of memory.



To get around this, I have had a few ideas;




  1. Use something like DeleteCase as a simple method (or something perhaps similar to Filter out all terms not involving a given variable which might be a bit overkill for my needs) to delete all terms not involving $s_{123}$, and then set the remaining factors of it in the leftover terms to 1.

  2. Instead of using Expand, define a new function which brings common factors inside to each fraction.


Which of these, alongside any other methods, would you suggest? How could I go about implementing them? I think 2 would be easier to do, but at this point, I am needing efficiency in my code on such a large scale.










share|improve this question











$endgroup$












  • $begingroup$
    You might find that working with a List of terms is better (e.g. effectively List@@A) than working with a sum of terms. Presumably Expand is comparing a large number of terms, looking for common subexpressions.
    $endgroup$
    – mikado
    3 hours ago














2












2








2





$begingroup$


As a very minimal example, consider a sum of fractions such as:



$A=frac{a}{s_{123}bc}+frac{d}{e}$



In practice, I have many hundreds of thousands of these fractions generated from a recursion relation. My desired result comes around from the prescription in my theory, where I am required to multiply through by $s_{123}$ and then take $s_{123}to 0$. Upon replicating in MMA, I use a code similar to:



A*s[1,2,3]//Expand
%/.{s[1,2,3]->0}


This Expand is necessary since by simply multiplying A by the relevant factor, MMA will first interpret it as $s_{123} big (frac{a}{s_{123}bc}+frac{d}{e}big)$. I think this is what is slowing my code down substantially, and crashes MMA due to a lack of memory.



To get around this, I have had a few ideas;




  1. Use something like DeleteCase as a simple method (or something perhaps similar to Filter out all terms not involving a given variable which might be a bit overkill for my needs) to delete all terms not involving $s_{123}$, and then set the remaining factors of it in the leftover terms to 1.

  2. Instead of using Expand, define a new function which brings common factors inside to each fraction.


Which of these, alongside any other methods, would you suggest? How could I go about implementing them? I think 2 would be easier to do, but at this point, I am needing efficiency in my code on such a large scale.










share|improve this question











$endgroup$




As a very minimal example, consider a sum of fractions such as:



$A=frac{a}{s_{123}bc}+frac{d}{e}$



In practice, I have many hundreds of thousands of these fractions generated from a recursion relation. My desired result comes around from the prescription in my theory, where I am required to multiply through by $s_{123}$ and then take $s_{123}to 0$. Upon replicating in MMA, I use a code similar to:



A*s[1,2,3]//Expand
%/.{s[1,2,3]->0}


This Expand is necessary since by simply multiplying A by the relevant factor, MMA will first interpret it as $s_{123} big (frac{a}{s_{123}bc}+frac{d}{e}big)$. I think this is what is slowing my code down substantially, and crashes MMA due to a lack of memory.



To get around this, I have had a few ideas;




  1. Use something like DeleteCase as a simple method (or something perhaps similar to Filter out all terms not involving a given variable which might be a bit overkill for my needs) to delete all terms not involving $s_{123}$, and then set the remaining factors of it in the leftover terms to 1.

  2. Instead of using Expand, define a new function which brings common factors inside to each fraction.


Which of these, alongside any other methods, would you suggest? How could I go about implementing them? I think 2 would be easier to do, but at this point, I am needing efficiency in my code on such a large scale.







performance-tuning replacement deletecases






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 4 hours ago







Brad

















asked 6 hours ago









BradBrad

497




497












  • $begingroup$
    You might find that working with a List of terms is better (e.g. effectively List@@A) than working with a sum of terms. Presumably Expand is comparing a large number of terms, looking for common subexpressions.
    $endgroup$
    – mikado
    3 hours ago


















  • $begingroup$
    You might find that working with a List of terms is better (e.g. effectively List@@A) than working with a sum of terms. Presumably Expand is comparing a large number of terms, looking for common subexpressions.
    $endgroup$
    – mikado
    3 hours ago
















$begingroup$
You might find that working with a List of terms is better (e.g. effectively List@@A) than working with a sum of terms. Presumably Expand is comparing a large number of terms, looking for common subexpressions.
$endgroup$
– mikado
3 hours ago




$begingroup$
You might find that working with a List of terms is better (e.g. effectively List@@A) than working with a sum of terms. Presumably Expand is comparing a large number of terms, looking for common subexpressions.
$endgroup$
– mikado
3 hours ago










1 Answer
1






active

oldest

votes


















3












$begingroup$

Pick out only those terms in A that contain exactly one s123 in the denominator:



A = a/(s123 b c) + d/e;

Select[A, Exponent[#, s123] == -1 &] /. s123 -> 1



a/(b c)




or with pattern matching:



Total[Cases[A, _/s123 | 1/s123, {1}]] /. s123 -> 1



a/(b c)




You'll have to check what's fastest in your case. Also, for added speed you may leave out the special pattern 1/s123 (*) in the second solution if you're sure it never occurs.





(*) We need a special pattern for 1/s123 because it does not match the pattern _/s123. Why not? The full form of x/s123 (with anything for x) has head Times:



x/s123 //FullForm
(* Times[Power[s123, -1], x] *)


The full form of 1/s123, on the other hand, has head Power:



1/s123 //FullForm
(* Power[s123, -1] *)





share|improve this answer











$endgroup$













  • $begingroup$
    Thank you for your very helpful and informative comment. Only off the top of your head, can you think of any other alternative methods that may be faster which I have not considered before?
    $endgroup$
    – Brad
    44 mins ago











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192458%2fremoving-fractions-without-a-particular-variable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3












$begingroup$

Pick out only those terms in A that contain exactly one s123 in the denominator:



A = a/(s123 b c) + d/e;

Select[A, Exponent[#, s123] == -1 &] /. s123 -> 1



a/(b c)




or with pattern matching:



Total[Cases[A, _/s123 | 1/s123, {1}]] /. s123 -> 1



a/(b c)




You'll have to check what's fastest in your case. Also, for added speed you may leave out the special pattern 1/s123 (*) in the second solution if you're sure it never occurs.





(*) We need a special pattern for 1/s123 because it does not match the pattern _/s123. Why not? The full form of x/s123 (with anything for x) has head Times:



x/s123 //FullForm
(* Times[Power[s123, -1], x] *)


The full form of 1/s123, on the other hand, has head Power:



1/s123 //FullForm
(* Power[s123, -1] *)





share|improve this answer











$endgroup$













  • $begingroup$
    Thank you for your very helpful and informative comment. Only off the top of your head, can you think of any other alternative methods that may be faster which I have not considered before?
    $endgroup$
    – Brad
    44 mins ago
















3












$begingroup$

Pick out only those terms in A that contain exactly one s123 in the denominator:



A = a/(s123 b c) + d/e;

Select[A, Exponent[#, s123] == -1 &] /. s123 -> 1



a/(b c)




or with pattern matching:



Total[Cases[A, _/s123 | 1/s123, {1}]] /. s123 -> 1



a/(b c)




You'll have to check what's fastest in your case. Also, for added speed you may leave out the special pattern 1/s123 (*) in the second solution if you're sure it never occurs.





(*) We need a special pattern for 1/s123 because it does not match the pattern _/s123. Why not? The full form of x/s123 (with anything for x) has head Times:



x/s123 //FullForm
(* Times[Power[s123, -1], x] *)


The full form of 1/s123, on the other hand, has head Power:



1/s123 //FullForm
(* Power[s123, -1] *)





share|improve this answer











$endgroup$













  • $begingroup$
    Thank you for your very helpful and informative comment. Only off the top of your head, can you think of any other alternative methods that may be faster which I have not considered before?
    $endgroup$
    – Brad
    44 mins ago














3












3








3





$begingroup$

Pick out only those terms in A that contain exactly one s123 in the denominator:



A = a/(s123 b c) + d/e;

Select[A, Exponent[#, s123] == -1 &] /. s123 -> 1



a/(b c)




or with pattern matching:



Total[Cases[A, _/s123 | 1/s123, {1}]] /. s123 -> 1



a/(b c)




You'll have to check what's fastest in your case. Also, for added speed you may leave out the special pattern 1/s123 (*) in the second solution if you're sure it never occurs.





(*) We need a special pattern for 1/s123 because it does not match the pattern _/s123. Why not? The full form of x/s123 (with anything for x) has head Times:



x/s123 //FullForm
(* Times[Power[s123, -1], x] *)


The full form of 1/s123, on the other hand, has head Power:



1/s123 //FullForm
(* Power[s123, -1] *)





share|improve this answer











$endgroup$



Pick out only those terms in A that contain exactly one s123 in the denominator:



A = a/(s123 b c) + d/e;

Select[A, Exponent[#, s123] == -1 &] /. s123 -> 1



a/(b c)




or with pattern matching:



Total[Cases[A, _/s123 | 1/s123, {1}]] /. s123 -> 1



a/(b c)




You'll have to check what's fastest in your case. Also, for added speed you may leave out the special pattern 1/s123 (*) in the second solution if you're sure it never occurs.





(*) We need a special pattern for 1/s123 because it does not match the pattern _/s123. Why not? The full form of x/s123 (with anything for x) has head Times:



x/s123 //FullForm
(* Times[Power[s123, -1], x] *)


The full form of 1/s123, on the other hand, has head Power:



1/s123 //FullForm
(* Power[s123, -1] *)






share|improve this answer














share|improve this answer



share|improve this answer








edited 49 mins ago

























answered 2 hours ago









RomanRoman

2,249716




2,249716












  • $begingroup$
    Thank you for your very helpful and informative comment. Only off the top of your head, can you think of any other alternative methods that may be faster which I have not considered before?
    $endgroup$
    – Brad
    44 mins ago


















  • $begingroup$
    Thank you for your very helpful and informative comment. Only off the top of your head, can you think of any other alternative methods that may be faster which I have not considered before?
    $endgroup$
    – Brad
    44 mins ago
















$begingroup$
Thank you for your very helpful and informative comment. Only off the top of your head, can you think of any other alternative methods that may be faster which I have not considered before?
$endgroup$
– Brad
44 mins ago




$begingroup$
Thank you for your very helpful and informative comment. Only off the top of your head, can you think of any other alternative methods that may be faster which I have not considered before?
$endgroup$
– Brad
44 mins ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematica Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192458%2fremoving-fractions-without-a-particular-variable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Webac Holding Inhaltsverzeichnis Geschichte | Organisationsstruktur | Tochterfirmen |...

What's the meaning of a knight fighting a snail in medieval book illustrations?What is the meaning of a glove...

Salamanca Inhaltsverzeichnis Lage und Klima | Bevölkerungsentwicklung | Geschichte | Kultur und...