Eliminating linear combinations from lists
Suppose I have a list of simple expressions, something like:
list = a-b-2c-d+e+2f,-a-2b-c+d+2e+f,-2a-b+c+2d+e-f,x-y-z,-x+y-z,-x-y+z;
These expressions are going to become elements in a linear combination. But notice that the third element in this list is itself already a linear combination of the first two. Therefore, my "basis" really should be this list without one of the first three elements (it doesn't matter which one goes away, but for consistency I would like to remove the third of them). Is there an automated way in Mathematica to search a list of expressions like this, identify when elements are linear combinations of others, and then remove the extraneous elements?
list-manipulation linear-algebra
add a comment |
Suppose I have a list of simple expressions, something like:
list = a-b-2c-d+e+2f,-a-2b-c+d+2e+f,-2a-b+c+2d+e-f,x-y-z,-x+y-z,-x-y+z;
These expressions are going to become elements in a linear combination. But notice that the third element in this list is itself already a linear combination of the first two. Therefore, my "basis" really should be this list without one of the first three elements (it doesn't matter which one goes away, but for consistency I would like to remove the third of them). Is there an automated way in Mathematica to search a list of expressions like this, identify when elements are linear combinations of others, and then remove the extraneous elements?
list-manipulation linear-algebra
2
"But notice that the third element in this list is itself already a linear combination of the first two." Nope. Check it (especially $e$).
– David G. Stork
Nov 12 at 5:49
Yeah, typo. Fixed now. Thank you for pointing it out!
– Kevin Ausman
Nov 13 at 19:53
add a comment |
Suppose I have a list of simple expressions, something like:
list = a-b-2c-d+e+2f,-a-2b-c+d+2e+f,-2a-b+c+2d+e-f,x-y-z,-x+y-z,-x-y+z;
These expressions are going to become elements in a linear combination. But notice that the third element in this list is itself already a linear combination of the first two. Therefore, my "basis" really should be this list without one of the first three elements (it doesn't matter which one goes away, but for consistency I would like to remove the third of them). Is there an automated way in Mathematica to search a list of expressions like this, identify when elements are linear combinations of others, and then remove the extraneous elements?
list-manipulation linear-algebra
Suppose I have a list of simple expressions, something like:
list = a-b-2c-d+e+2f,-a-2b-c+d+2e+f,-2a-b+c+2d+e-f,x-y-z,-x+y-z,-x-y+z;
These expressions are going to become elements in a linear combination. But notice that the third element in this list is itself already a linear combination of the first two. Therefore, my "basis" really should be this list without one of the first three elements (it doesn't matter which one goes away, but for consistency I would like to remove the third of them). Is there an automated way in Mathematica to search a list of expressions like this, identify when elements are linear combinations of others, and then remove the extraneous elements?
list-manipulation linear-algebra
list-manipulation linear-algebra
edited Nov 13 at 19:53
asked Nov 12 at 5:26
Kevin Ausman
1637
1637
2
"But notice that the third element in this list is itself already a linear combination of the first two." Nope. Check it (especially $e$).
– David G. Stork
Nov 12 at 5:49
Yeah, typo. Fixed now. Thank you for pointing it out!
– Kevin Ausman
Nov 13 at 19:53
add a comment |
2
"But notice that the third element in this list is itself already a linear combination of the first two." Nope. Check it (especially $e$).
– David G. Stork
Nov 12 at 5:49
Yeah, typo. Fixed now. Thank you for pointing it out!
– Kevin Ausman
Nov 13 at 19:53
2
2
"But notice that the third element in this list is itself already a linear combination of the first two." Nope. Check it (especially $e$).
– David G. Stork
Nov 12 at 5:49
"But notice that the third element in this list is itself already a linear combination of the first two." Nope. Check it (especially $e$).
– David G. Stork
Nov 12 at 5:49
Yeah, typo. Fixed now. Thank you for pointing it out!
– Kevin Ausman
Nov 13 at 19:53
Yeah, typo. Fixed now. Thank you for pointing it out!
– Kevin Ausman
Nov 13 at 19:53
add a comment |
3 Answers
3
active
oldest
votes
Take your list and fix it so that the 3rd element dependent on the first two:
list[[3]] = (list[[2]] + list[[1]])/3 // Expand;
list
(*
2a + b - c - 2d - e + f, a + 2b + c - d - 2 e - f, -a + b + 2c + d - e - 2f,
x - y - z, -x + y - z, -x - y + z
*)
Convert system of linear functions to a matrix:
vars = Variables@list;
linsys = CoefficientArrays[Flatten@list, vars][[2]];
Extract linearly independent elements of list
:
Extract[list,
FirstPosition[#, 1, Nothing] & /@ RowReduce[Transpose@linsys]]
(*
a - b - 2 c - d + e + 2 f, -a - 2 b - c + d + 2 e + f,
x - y - z, -x + y - z, -x - y + z
*)
Or row reduce to get an equivalent basis:
RowReduce[linsys].vars // DeleteCases[0]
(* a - c - d + f, b + c - e - f, x, y, z *)
The example I started with does have the third entry dependent on the first two (element 2 minus element 1 is element 3). But regardless, your approach worked perfectly! Thank you!
– Kevin Ausman
Nov 12 at 19:13
@KevinAusman You're welcome. (Maybe there's a typo in the question because elt. 2 minus elt. 1 should have a+ e
in the expression, but there are noe
.)
– Michael E2
Nov 12 at 19:40
Huh. You are obviously correct about the typo. Thank you! Fixing it now.
– Kevin Ausman
Nov 13 at 19:47
And I accidentally, in trying to fix the problem, tried to edit your response! So sorry... I don't know how to withdraw my suggested edit. Clearly I didn't get enough sleep last nigh.
– Kevin Ausman
Nov 13 at 19:51
@KevinAusman No problem. New users' edits of other posts go through a queue for approval. Those who review it might reject it, if they spot the error. If it does go through, it can be rolled back. Hopefully they will see your comment and reject it.
– Michael E2
Nov 13 at 19:55
add a comment |
What I would do is replace symbols by numeric vectors with a function like
ClearAll[toNumbers];
toNumbers[list_, vars_] :=
list /. Thread[vars -> IdentityMatrix[Length[vars]]];
toNumbers[a, b, a + b, a, b]
(*1, 0, 0, 1, 1, 1*)
then perform some linear algebra and convert the result back into symbols with something like
ClearAll[fromNumbers];
fromNumbers[list_, vars_] := Replace[
list,
x_ :> x.vars,
1
];
fromNumbers[1, 0, 0, 1, 1, 1, a, b]
(*a, b, a + b*)
The linear algebra logic can be something like Fold
which checks a vector and appends it to a list if it is linear independent form the vectors in the list:
Fold[
f,
,
1, 1, 0, 0, 1, 0, 1, 1, 1
]
where
ClearAll[f];
f[vecs_, vec_] := With[
vecs2 = Append[vecs, vec]
,
vecs2 /; MatrixRank[vecs2] == Length[vecs2]
];
f[vecs_, vec_] := vecs;
Gathering all together (except f
):
ClearAll[leaveLinearIndependent];
leaveLinearIndependent[list_, vars_] := Replace[
Fold[
f,
,
list /. Thread[vars -> IdentityMatrix[Length[vars]]]
],
x_ :> x.vars,
1
];
leaveLinearIndependent[a, a + b, b, c, a, b, c]
(*a, a + b, c*)
add a comment |
list = a-b-2c-d+e+2f,-a-2b-c+d+2e+f,
-2a-b+c+2d+e-f,x-y-z,-x+y-z,-x-y+z;
First extract coefficient arrays.
coeffArrays = Normal[CoefficientArrays[list]][[2,All,1]]
(* ut[29]= 1, -1, -2, -1, 1, 2, 0, 0, 0,
-1, -2, -1, 1, 2, 1, 0, 0, 0,
-2, -1, 1, 2, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1,
0, 0, 0, 0, 0, 0, -1, 1, -1, 0, 0, 0, 0, 0, 0, -1, -1, 1 *)
Find null vectors of the transpose.
nulls = NullSpace[Transpose@dd]
(* Out[30]= 1, -1, 1, 0, 0, 0 *)
We want to remove vectors in positions of last nonzero value in each null vector (of which there is but one, in this case). We can automate the task of finding the list to remove as below.
Flatten[Length[nulls[[1]]] + 1 -
Map[FirstPosition[#,Except[0],Heads->False]&,
Map[Reverse,nulls]]]
(* Out[41]= 3 *)
add a comment |
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
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f185825%2feliminating-linear-combinations-from-lists%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Take your list and fix it so that the 3rd element dependent on the first two:
list[[3]] = (list[[2]] + list[[1]])/3 // Expand;
list
(*
2a + b - c - 2d - e + f, a + 2b + c - d - 2 e - f, -a + b + 2c + d - e - 2f,
x - y - z, -x + y - z, -x - y + z
*)
Convert system of linear functions to a matrix:
vars = Variables@list;
linsys = CoefficientArrays[Flatten@list, vars][[2]];
Extract linearly independent elements of list
:
Extract[list,
FirstPosition[#, 1, Nothing] & /@ RowReduce[Transpose@linsys]]
(*
a - b - 2 c - d + e + 2 f, -a - 2 b - c + d + 2 e + f,
x - y - z, -x + y - z, -x - y + z
*)
Or row reduce to get an equivalent basis:
RowReduce[linsys].vars // DeleteCases[0]
(* a - c - d + f, b + c - e - f, x, y, z *)
The example I started with does have the third entry dependent on the first two (element 2 minus element 1 is element 3). But regardless, your approach worked perfectly! Thank you!
– Kevin Ausman
Nov 12 at 19:13
@KevinAusman You're welcome. (Maybe there's a typo in the question because elt. 2 minus elt. 1 should have a+ e
in the expression, but there are noe
.)
– Michael E2
Nov 12 at 19:40
Huh. You are obviously correct about the typo. Thank you! Fixing it now.
– Kevin Ausman
Nov 13 at 19:47
And I accidentally, in trying to fix the problem, tried to edit your response! So sorry... I don't know how to withdraw my suggested edit. Clearly I didn't get enough sleep last nigh.
– Kevin Ausman
Nov 13 at 19:51
@KevinAusman No problem. New users' edits of other posts go through a queue for approval. Those who review it might reject it, if they spot the error. If it does go through, it can be rolled back. Hopefully they will see your comment and reject it.
– Michael E2
Nov 13 at 19:55
add a comment |
Take your list and fix it so that the 3rd element dependent on the first two:
list[[3]] = (list[[2]] + list[[1]])/3 // Expand;
list
(*
2a + b - c - 2d - e + f, a + 2b + c - d - 2 e - f, -a + b + 2c + d - e - 2f,
x - y - z, -x + y - z, -x - y + z
*)
Convert system of linear functions to a matrix:
vars = Variables@list;
linsys = CoefficientArrays[Flatten@list, vars][[2]];
Extract linearly independent elements of list
:
Extract[list,
FirstPosition[#, 1, Nothing] & /@ RowReduce[Transpose@linsys]]
(*
a - b - 2 c - d + e + 2 f, -a - 2 b - c + d + 2 e + f,
x - y - z, -x + y - z, -x - y + z
*)
Or row reduce to get an equivalent basis:
RowReduce[linsys].vars // DeleteCases[0]
(* a - c - d + f, b + c - e - f, x, y, z *)
The example I started with does have the third entry dependent on the first two (element 2 minus element 1 is element 3). But regardless, your approach worked perfectly! Thank you!
– Kevin Ausman
Nov 12 at 19:13
@KevinAusman You're welcome. (Maybe there's a typo in the question because elt. 2 minus elt. 1 should have a+ e
in the expression, but there are noe
.)
– Michael E2
Nov 12 at 19:40
Huh. You are obviously correct about the typo. Thank you! Fixing it now.
– Kevin Ausman
Nov 13 at 19:47
And I accidentally, in trying to fix the problem, tried to edit your response! So sorry... I don't know how to withdraw my suggested edit. Clearly I didn't get enough sleep last nigh.
– Kevin Ausman
Nov 13 at 19:51
@KevinAusman No problem. New users' edits of other posts go through a queue for approval. Those who review it might reject it, if they spot the error. If it does go through, it can be rolled back. Hopefully they will see your comment and reject it.
– Michael E2
Nov 13 at 19:55
add a comment |
Take your list and fix it so that the 3rd element dependent on the first two:
list[[3]] = (list[[2]] + list[[1]])/3 // Expand;
list
(*
2a + b - c - 2d - e + f, a + 2b + c - d - 2 e - f, -a + b + 2c + d - e - 2f,
x - y - z, -x + y - z, -x - y + z
*)
Convert system of linear functions to a matrix:
vars = Variables@list;
linsys = CoefficientArrays[Flatten@list, vars][[2]];
Extract linearly independent elements of list
:
Extract[list,
FirstPosition[#, 1, Nothing] & /@ RowReduce[Transpose@linsys]]
(*
a - b - 2 c - d + e + 2 f, -a - 2 b - c + d + 2 e + f,
x - y - z, -x + y - z, -x - y + z
*)
Or row reduce to get an equivalent basis:
RowReduce[linsys].vars // DeleteCases[0]
(* a - c - d + f, b + c - e - f, x, y, z *)
Take your list and fix it so that the 3rd element dependent on the first two:
list[[3]] = (list[[2]] + list[[1]])/3 // Expand;
list
(*
2a + b - c - 2d - e + f, a + 2b + c - d - 2 e - f, -a + b + 2c + d - e - 2f,
x - y - z, -x + y - z, -x - y + z
*)
Convert system of linear functions to a matrix:
vars = Variables@list;
linsys = CoefficientArrays[Flatten@list, vars][[2]];
Extract linearly independent elements of list
:
Extract[list,
FirstPosition[#, 1, Nothing] & /@ RowReduce[Transpose@linsys]]
(*
a - b - 2 c - d + e + 2 f, -a - 2 b - c + d + 2 e + f,
x - y - z, -x + y - z, -x - y + z
*)
Or row reduce to get an equivalent basis:
RowReduce[linsys].vars // DeleteCases[0]
(* a - c - d + f, b + c - e - f, x, y, z *)
edited Nov 14 at 0:02
Kevin Ausman
1637
1637
answered Nov 12 at 11:32
Michael E2
145k11194464
145k11194464
The example I started with does have the third entry dependent on the first two (element 2 minus element 1 is element 3). But regardless, your approach worked perfectly! Thank you!
– Kevin Ausman
Nov 12 at 19:13
@KevinAusman You're welcome. (Maybe there's a typo in the question because elt. 2 minus elt. 1 should have a+ e
in the expression, but there are noe
.)
– Michael E2
Nov 12 at 19:40
Huh. You are obviously correct about the typo. Thank you! Fixing it now.
– Kevin Ausman
Nov 13 at 19:47
And I accidentally, in trying to fix the problem, tried to edit your response! So sorry... I don't know how to withdraw my suggested edit. Clearly I didn't get enough sleep last nigh.
– Kevin Ausman
Nov 13 at 19:51
@KevinAusman No problem. New users' edits of other posts go through a queue for approval. Those who review it might reject it, if they spot the error. If it does go through, it can be rolled back. Hopefully they will see your comment and reject it.
– Michael E2
Nov 13 at 19:55
add a comment |
The example I started with does have the third entry dependent on the first two (element 2 minus element 1 is element 3). But regardless, your approach worked perfectly! Thank you!
– Kevin Ausman
Nov 12 at 19:13
@KevinAusman You're welcome. (Maybe there's a typo in the question because elt. 2 minus elt. 1 should have a+ e
in the expression, but there are noe
.)
– Michael E2
Nov 12 at 19:40
Huh. You are obviously correct about the typo. Thank you! Fixing it now.
– Kevin Ausman
Nov 13 at 19:47
And I accidentally, in trying to fix the problem, tried to edit your response! So sorry... I don't know how to withdraw my suggested edit. Clearly I didn't get enough sleep last nigh.
– Kevin Ausman
Nov 13 at 19:51
@KevinAusman No problem. New users' edits of other posts go through a queue for approval. Those who review it might reject it, if they spot the error. If it does go through, it can be rolled back. Hopefully they will see your comment and reject it.
– Michael E2
Nov 13 at 19:55
The example I started with does have the third entry dependent on the first two (element 2 minus element 1 is element 3). But regardless, your approach worked perfectly! Thank you!
– Kevin Ausman
Nov 12 at 19:13
The example I started with does have the third entry dependent on the first two (element 2 minus element 1 is element 3). But regardless, your approach worked perfectly! Thank you!
– Kevin Ausman
Nov 12 at 19:13
@KevinAusman You're welcome. (Maybe there's a typo in the question because elt. 2 minus elt. 1 should have a
+ e
in the expression, but there are no e
.)– Michael E2
Nov 12 at 19:40
@KevinAusman You're welcome. (Maybe there's a typo in the question because elt. 2 minus elt. 1 should have a
+ e
in the expression, but there are no e
.)– Michael E2
Nov 12 at 19:40
Huh. You are obviously correct about the typo. Thank you! Fixing it now.
– Kevin Ausman
Nov 13 at 19:47
Huh. You are obviously correct about the typo. Thank you! Fixing it now.
– Kevin Ausman
Nov 13 at 19:47
And I accidentally, in trying to fix the problem, tried to edit your response! So sorry... I don't know how to withdraw my suggested edit. Clearly I didn't get enough sleep last nigh.
– Kevin Ausman
Nov 13 at 19:51
And I accidentally, in trying to fix the problem, tried to edit your response! So sorry... I don't know how to withdraw my suggested edit. Clearly I didn't get enough sleep last nigh.
– Kevin Ausman
Nov 13 at 19:51
@KevinAusman No problem. New users' edits of other posts go through a queue for approval. Those who review it might reject it, if they spot the error. If it does go through, it can be rolled back. Hopefully they will see your comment and reject it.
– Michael E2
Nov 13 at 19:55
@KevinAusman No problem. New users' edits of other posts go through a queue for approval. Those who review it might reject it, if they spot the error. If it does go through, it can be rolled back. Hopefully they will see your comment and reject it.
– Michael E2
Nov 13 at 19:55
add a comment |
What I would do is replace symbols by numeric vectors with a function like
ClearAll[toNumbers];
toNumbers[list_, vars_] :=
list /. Thread[vars -> IdentityMatrix[Length[vars]]];
toNumbers[a, b, a + b, a, b]
(*1, 0, 0, 1, 1, 1*)
then perform some linear algebra and convert the result back into symbols with something like
ClearAll[fromNumbers];
fromNumbers[list_, vars_] := Replace[
list,
x_ :> x.vars,
1
];
fromNumbers[1, 0, 0, 1, 1, 1, a, b]
(*a, b, a + b*)
The linear algebra logic can be something like Fold
which checks a vector and appends it to a list if it is linear independent form the vectors in the list:
Fold[
f,
,
1, 1, 0, 0, 1, 0, 1, 1, 1
]
where
ClearAll[f];
f[vecs_, vec_] := With[
vecs2 = Append[vecs, vec]
,
vecs2 /; MatrixRank[vecs2] == Length[vecs2]
];
f[vecs_, vec_] := vecs;
Gathering all together (except f
):
ClearAll[leaveLinearIndependent];
leaveLinearIndependent[list_, vars_] := Replace[
Fold[
f,
,
list /. Thread[vars -> IdentityMatrix[Length[vars]]]
],
x_ :> x.vars,
1
];
leaveLinearIndependent[a, a + b, b, c, a, b, c]
(*a, a + b, c*)
add a comment |
What I would do is replace symbols by numeric vectors with a function like
ClearAll[toNumbers];
toNumbers[list_, vars_] :=
list /. Thread[vars -> IdentityMatrix[Length[vars]]];
toNumbers[a, b, a + b, a, b]
(*1, 0, 0, 1, 1, 1*)
then perform some linear algebra and convert the result back into symbols with something like
ClearAll[fromNumbers];
fromNumbers[list_, vars_] := Replace[
list,
x_ :> x.vars,
1
];
fromNumbers[1, 0, 0, 1, 1, 1, a, b]
(*a, b, a + b*)
The linear algebra logic can be something like Fold
which checks a vector and appends it to a list if it is linear independent form the vectors in the list:
Fold[
f,
,
1, 1, 0, 0, 1, 0, 1, 1, 1
]
where
ClearAll[f];
f[vecs_, vec_] := With[
vecs2 = Append[vecs, vec]
,
vecs2 /; MatrixRank[vecs2] == Length[vecs2]
];
f[vecs_, vec_] := vecs;
Gathering all together (except f
):
ClearAll[leaveLinearIndependent];
leaveLinearIndependent[list_, vars_] := Replace[
Fold[
f,
,
list /. Thread[vars -> IdentityMatrix[Length[vars]]]
],
x_ :> x.vars,
1
];
leaveLinearIndependent[a, a + b, b, c, a, b, c]
(*a, a + b, c*)
add a comment |
What I would do is replace symbols by numeric vectors with a function like
ClearAll[toNumbers];
toNumbers[list_, vars_] :=
list /. Thread[vars -> IdentityMatrix[Length[vars]]];
toNumbers[a, b, a + b, a, b]
(*1, 0, 0, 1, 1, 1*)
then perform some linear algebra and convert the result back into symbols with something like
ClearAll[fromNumbers];
fromNumbers[list_, vars_] := Replace[
list,
x_ :> x.vars,
1
];
fromNumbers[1, 0, 0, 1, 1, 1, a, b]
(*a, b, a + b*)
The linear algebra logic can be something like Fold
which checks a vector and appends it to a list if it is linear independent form the vectors in the list:
Fold[
f,
,
1, 1, 0, 0, 1, 0, 1, 1, 1
]
where
ClearAll[f];
f[vecs_, vec_] := With[
vecs2 = Append[vecs, vec]
,
vecs2 /; MatrixRank[vecs2] == Length[vecs2]
];
f[vecs_, vec_] := vecs;
Gathering all together (except f
):
ClearAll[leaveLinearIndependent];
leaveLinearIndependent[list_, vars_] := Replace[
Fold[
f,
,
list /. Thread[vars -> IdentityMatrix[Length[vars]]]
],
x_ :> x.vars,
1
];
leaveLinearIndependent[a, a + b, b, c, a, b, c]
(*a, a + b, c*)
What I would do is replace symbols by numeric vectors with a function like
ClearAll[toNumbers];
toNumbers[list_, vars_] :=
list /. Thread[vars -> IdentityMatrix[Length[vars]]];
toNumbers[a, b, a + b, a, b]
(*1, 0, 0, 1, 1, 1*)
then perform some linear algebra and convert the result back into symbols with something like
ClearAll[fromNumbers];
fromNumbers[list_, vars_] := Replace[
list,
x_ :> x.vars,
1
];
fromNumbers[1, 0, 0, 1, 1, 1, a, b]
(*a, b, a + b*)
The linear algebra logic can be something like Fold
which checks a vector and appends it to a list if it is linear independent form the vectors in the list:
Fold[
f,
,
1, 1, 0, 0, 1, 0, 1, 1, 1
]
where
ClearAll[f];
f[vecs_, vec_] := With[
vecs2 = Append[vecs, vec]
,
vecs2 /; MatrixRank[vecs2] == Length[vecs2]
];
f[vecs_, vec_] := vecs;
Gathering all together (except f
):
ClearAll[leaveLinearIndependent];
leaveLinearIndependent[list_, vars_] := Replace[
Fold[
f,
,
list /. Thread[vars -> IdentityMatrix[Length[vars]]]
],
x_ :> x.vars,
1
];
leaveLinearIndependent[a, a + b, b, c, a, b, c]
(*a, a + b, c*)
answered Nov 12 at 8:28
Anton.Sakovich
45628
45628
add a comment |
add a comment |
list = a-b-2c-d+e+2f,-a-2b-c+d+2e+f,
-2a-b+c+2d+e-f,x-y-z,-x+y-z,-x-y+z;
First extract coefficient arrays.
coeffArrays = Normal[CoefficientArrays[list]][[2,All,1]]
(* ut[29]= 1, -1, -2, -1, 1, 2, 0, 0, 0,
-1, -2, -1, 1, 2, 1, 0, 0, 0,
-2, -1, 1, 2, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1,
0, 0, 0, 0, 0, 0, -1, 1, -1, 0, 0, 0, 0, 0, 0, -1, -1, 1 *)
Find null vectors of the transpose.
nulls = NullSpace[Transpose@dd]
(* Out[30]= 1, -1, 1, 0, 0, 0 *)
We want to remove vectors in positions of last nonzero value in each null vector (of which there is but one, in this case). We can automate the task of finding the list to remove as below.
Flatten[Length[nulls[[1]]] + 1 -
Map[FirstPosition[#,Except[0],Heads->False]&,
Map[Reverse,nulls]]]
(* Out[41]= 3 *)
add a comment |
list = a-b-2c-d+e+2f,-a-2b-c+d+2e+f,
-2a-b+c+2d+e-f,x-y-z,-x+y-z,-x-y+z;
First extract coefficient arrays.
coeffArrays = Normal[CoefficientArrays[list]][[2,All,1]]
(* ut[29]= 1, -1, -2, -1, 1, 2, 0, 0, 0,
-1, -2, -1, 1, 2, 1, 0, 0, 0,
-2, -1, 1, 2, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1,
0, 0, 0, 0, 0, 0, -1, 1, -1, 0, 0, 0, 0, 0, 0, -1, -1, 1 *)
Find null vectors of the transpose.
nulls = NullSpace[Transpose@dd]
(* Out[30]= 1, -1, 1, 0, 0, 0 *)
We want to remove vectors in positions of last nonzero value in each null vector (of which there is but one, in this case). We can automate the task of finding the list to remove as below.
Flatten[Length[nulls[[1]]] + 1 -
Map[FirstPosition[#,Except[0],Heads->False]&,
Map[Reverse,nulls]]]
(* Out[41]= 3 *)
add a comment |
list = a-b-2c-d+e+2f,-a-2b-c+d+2e+f,
-2a-b+c+2d+e-f,x-y-z,-x+y-z,-x-y+z;
First extract coefficient arrays.
coeffArrays = Normal[CoefficientArrays[list]][[2,All,1]]
(* ut[29]= 1, -1, -2, -1, 1, 2, 0, 0, 0,
-1, -2, -1, 1, 2, 1, 0, 0, 0,
-2, -1, 1, 2, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1,
0, 0, 0, 0, 0, 0, -1, 1, -1, 0, 0, 0, 0, 0, 0, -1, -1, 1 *)
Find null vectors of the transpose.
nulls = NullSpace[Transpose@dd]
(* Out[30]= 1, -1, 1, 0, 0, 0 *)
We want to remove vectors in positions of last nonzero value in each null vector (of which there is but one, in this case). We can automate the task of finding the list to remove as below.
Flatten[Length[nulls[[1]]] + 1 -
Map[FirstPosition[#,Except[0],Heads->False]&,
Map[Reverse,nulls]]]
(* Out[41]= 3 *)
list = a-b-2c-d+e+2f,-a-2b-c+d+2e+f,
-2a-b+c+2d+e-f,x-y-z,-x+y-z,-x-y+z;
First extract coefficient arrays.
coeffArrays = Normal[CoefficientArrays[list]][[2,All,1]]
(* ut[29]= 1, -1, -2, -1, 1, 2, 0, 0, 0,
-1, -2, -1, 1, 2, 1, 0, 0, 0,
-2, -1, 1, 2, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1,
0, 0, 0, 0, 0, 0, -1, 1, -1, 0, 0, 0, 0, 0, 0, -1, -1, 1 *)
Find null vectors of the transpose.
nulls = NullSpace[Transpose@dd]
(* Out[30]= 1, -1, 1, 0, 0, 0 *)
We want to remove vectors in positions of last nonzero value in each null vector (of which there is but one, in this case). We can automate the task of finding the list to remove as below.
Flatten[Length[nulls[[1]]] + 1 -
Map[FirstPosition[#,Except[0],Heads->False]&,
Map[Reverse,nulls]]]
(* Out[41]= 3 *)
answered Nov 14 at 15:11
Daniel Lichtblau
46.4k275162
46.4k275162
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f185825%2feliminating-linear-combinations-from-lists%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
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
2
"But notice that the third element in this list is itself already a linear combination of the first two." Nope. Check it (especially $e$).
– David G. Stork
Nov 12 at 5:49
Yeah, typo. Fixed now. Thank you for pointing it out!
– Kevin Ausman
Nov 13 at 19:53