Wrestling with substitution rules
up vote
2
down vote
favorite
Summary
I am struggling with substitution rules.
Example
Here are several cases which are problematic:
Clear[a,α];
{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a + b -> α}
Actual result:
{1 + a + 2 b, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}
Desired result:
{1 + α + b, -α, 2 α, α^2}
Question
Currently, the rule is permuted for every case, e.g.
2 a + 2 b -> 2α
Can the alpha substitution rule be generalized That, is there a single rule to handle all cases?
replacement rule
add a comment |
up vote
2
down vote
favorite
Summary
I am struggling with substitution rules.
Example
Here are several cases which are problematic:
Clear[a,α];
{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a + b -> α}
Actual result:
{1 + a + 2 b, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}
Desired result:
{1 + α + b, -α, 2 α, α^2}
Question
Currently, the rule is permuted for every case, e.g.
2 a + 2 b -> 2α
Can the alpha substitution rule be generalized That, is there a single rule to handle all cases?
replacement rule
2
You mean: "One to rule them all"? ;)
– Henrik Schumacher
Nov 4 at 18:38
1
UsePolynomialReduce
to obtain algebraic "substitutions".In[208]:= PolynomialReduce[{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}, a + b - alpha, {a, b}][[All, 2]] Out[208]= {1 + alpha + b, -alpha, 2 alpha, alpha^2}
– Daniel Lichtblau
Nov 4 at 19:14
1
Generally, to apply a relationship broadly, write the corresponding rule such that the LHS of the rule is as simple as possible, e.g., solution posted by @HenrikSchumacher. Since rules are applied to the structure of the internal (FullForm) representation, this will result in the highest number of matches with the LHS.
– Bob Hanlon
Nov 4 at 19:38
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Summary
I am struggling with substitution rules.
Example
Here are several cases which are problematic:
Clear[a,α];
{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a + b -> α}
Actual result:
{1 + a + 2 b, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}
Desired result:
{1 + α + b, -α, 2 α, α^2}
Question
Currently, the rule is permuted for every case, e.g.
2 a + 2 b -> 2α
Can the alpha substitution rule be generalized That, is there a single rule to handle all cases?
replacement rule
Summary
I am struggling with substitution rules.
Example
Here are several cases which are problematic:
Clear[a,α];
{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a + b -> α}
Actual result:
{1 + a + 2 b, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}
Desired result:
{1 + α + b, -α, 2 α, α^2}
Question
Currently, the rule is permuted for every case, e.g.
2 a + 2 b -> 2α
Can the alpha substitution rule be generalized That, is there a single rule to handle all cases?
replacement rule
replacement rule
edited Nov 4 at 18:35
Henrik Schumacher
44.1k263129
44.1k263129
asked Nov 4 at 18:34
dantopa
47428
47428
2
You mean: "One to rule them all"? ;)
– Henrik Schumacher
Nov 4 at 18:38
1
UsePolynomialReduce
to obtain algebraic "substitutions".In[208]:= PolynomialReduce[{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}, a + b - alpha, {a, b}][[All, 2]] Out[208]= {1 + alpha + b, -alpha, 2 alpha, alpha^2}
– Daniel Lichtblau
Nov 4 at 19:14
1
Generally, to apply a relationship broadly, write the corresponding rule such that the LHS of the rule is as simple as possible, e.g., solution posted by @HenrikSchumacher. Since rules are applied to the structure of the internal (FullForm) representation, this will result in the highest number of matches with the LHS.
– Bob Hanlon
Nov 4 at 19:38
add a comment |
2
You mean: "One to rule them all"? ;)
– Henrik Schumacher
Nov 4 at 18:38
1
UsePolynomialReduce
to obtain algebraic "substitutions".In[208]:= PolynomialReduce[{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}, a + b - alpha, {a, b}][[All, 2]] Out[208]= {1 + alpha + b, -alpha, 2 alpha, alpha^2}
– Daniel Lichtblau
Nov 4 at 19:14
1
Generally, to apply a relationship broadly, write the corresponding rule such that the LHS of the rule is as simple as possible, e.g., solution posted by @HenrikSchumacher. Since rules are applied to the structure of the internal (FullForm) representation, this will result in the highest number of matches with the LHS.
– Bob Hanlon
Nov 4 at 19:38
2
2
You mean: "One to rule them all"? ;)
– Henrik Schumacher
Nov 4 at 18:38
You mean: "One to rule them all"? ;)
– Henrik Schumacher
Nov 4 at 18:38
1
1
Use
PolynomialReduce
to obtain algebraic "substitutions". In[208]:= PolynomialReduce[{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}, a + b - alpha, {a, b}][[All, 2]] Out[208]= {1 + alpha + b, -alpha, 2 alpha, alpha^2}
– Daniel Lichtblau
Nov 4 at 19:14
Use
PolynomialReduce
to obtain algebraic "substitutions". In[208]:= PolynomialReduce[{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}, a + b - alpha, {a, b}][[All, 2]] Out[208]= {1 + alpha + b, -alpha, 2 alpha, alpha^2}
– Daniel Lichtblau
Nov 4 at 19:14
1
1
Generally, to apply a relationship broadly, write the corresponding rule such that the LHS of the rule is as simple as possible, e.g., solution posted by @HenrikSchumacher. Since rules are applied to the structure of the internal (FullForm) representation, this will result in the highest number of matches with the LHS.
– Bob Hanlon
Nov 4 at 19:38
Generally, to apply a relationship broadly, write the corresponding rule such that the LHS of the rule is as simple as possible, e.g., solution posted by @HenrikSchumacher. Since rules are applied to the structure of the internal (FullForm) representation, this will result in the highest number of matches with the LHS.
– Bob Hanlon
Nov 4 at 19:38
add a comment |
2 Answers
2
active
oldest
votes
up vote
6
down vote
{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a -> α - b} // Simplify
{1 + b + α, -α, 2 α, α^2}
add a comment |
up vote
5
down vote
Also
Simplify[{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}, {a + b == α}]
{1 + b + α, -α, 2 α, α^2}
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a -> α - b} // Simplify
{1 + b + α, -α, 2 α, α^2}
add a comment |
up vote
6
down vote
{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a -> α - b} // Simplify
{1 + b + α, -α, 2 α, α^2}
add a comment |
up vote
6
down vote
up vote
6
down vote
{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a -> α - b} // Simplify
{1 + b + α, -α, 2 α, α^2}
{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a -> α - b} // Simplify
{1 + b + α, -α, 2 α, α^2}
answered Nov 4 at 18:37
Henrik Schumacher
44.1k263129
44.1k263129
add a comment |
add a comment |
up vote
5
down vote
Also
Simplify[{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}, {a + b == α}]
{1 + b + α, -α, 2 α, α^2}
add a comment |
up vote
5
down vote
Also
Simplify[{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}, {a + b == α}]
{1 + b + α, -α, 2 α, α^2}
add a comment |
up vote
5
down vote
up vote
5
down vote
Also
Simplify[{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}, {a + b == α}]
{1 + b + α, -α, 2 α, α^2}
Also
Simplify[{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}, {a + b == α}]
{1 + b + α, -α, 2 α, α^2}
answered Nov 4 at 19:18
kglr
170k8193396
170k8193396
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f185287%2fwrestling-with-substitution-rules%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
You mean: "One to rule them all"? ;)
– Henrik Schumacher
Nov 4 at 18:38
1
Use
PolynomialReduce
to obtain algebraic "substitutions".In[208]:= PolynomialReduce[{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}, a + b - alpha, {a, b}][[All, 2]] Out[208]= {1 + alpha + b, -alpha, 2 alpha, alpha^2}
– Daniel Lichtblau
Nov 4 at 19:14
1
Generally, to apply a relationship broadly, write the corresponding rule such that the LHS of the rule is as simple as possible, e.g., solution posted by @HenrikSchumacher. Since rules are applied to the structure of the internal (FullForm) representation, this will result in the highest number of matches with the LHS.
– Bob Hanlon
Nov 4 at 19:38