Define different actions for the same operator depending on the nature of its argumentsHow to define the tangent gradient operator?How can I make threading more flexible?How to construct custom operators with precedence?Construct a function whose definition depends on the values of its argumentsDefine an operator with the distributive propertyReplacing multiplication of matrix elements by application of these elements as functionsDefining a matrix with elements acting as operatorsDefine an operator for FileNameJoinUsing Two Arguments on the Same FunctionHow to define custom differential operator using the arguments of the expression?
/bin/ls output does not match manpage
Help interpret cancellation charges for hotel booking
No, nay, never, no more
Happy pi day, everyone!
Is having access to past exams cheating and, if yes, could it be proven just by a good grade?
Employee lack of ownership
What has been your most complicated TikZ drawing?
At what level can a dragon innately cast its spells?
MSTP and Rapid-PVST+
If Invisibility ends because the original caster casts a non-concentration spell, does Invisibility also end on other targets of the original casting?
Co-worker team leader wants to inject his friend's awful software into our development. What should I say to our common boss?
Word for a person who has no opinion about whether god exists
Why would a flight no longer considered airworthy be redirected like this?
How to simplify this time periods definition interface?
Plot a function of two variables equal 0
How could a female member of a species produce eggs unto death?
Provisioning profile doesn't include the application-identifier and keychain-access-groups entitlements
What is a good source for large tables on the properties of water?
Why do passenger jet manufacturers design their planes with stall prevention systems?
Meaning of "SEVERA INDEOVI VAS" from 3rd Century slab
Professor being mistaken for a grad student
Russian cases: A few examples, I'm really confused
How many of these lines lie entirely in the interior of the original cube?
About parabolic Kazhdan Lusztig polynomials
Define different actions for the same operator depending on the nature of its arguments
How to define the tangent gradient operator?How can I make threading more flexible?How to construct custom operators with precedence?Construct a function whose definition depends on the values of its argumentsDefine an operator with the distributive propertyReplacing multiplication of matrix elements by application of these elements as functionsDefining a matrix with elements acting as operatorsDefine an operator for FileNameJoinUsing Two Arguments on the Same FunctionHow to define custom differential operator using the arguments of the expression?
$begingroup$
I am working with terms of the form
A**B1**B2
where A, B1, and B2 are at this point abstract operators and ** means NonCommutativeMultiply.
I'd like to manipulate these expressions at an abstract level, and then only later substitute explicit matrix operations. Specifically, $A$ will be a square matrix, while $B1$ and $B2$ will be commensurate vectors.
The trick is that at this point the specific meanings of the two occurrences of ** will change. Specifically, A ** B1 will become a matrix multiplication, and B1 ** B2 will become an outer product.
I'm using a package (NCAlgebra) to simplify the expressions at an abstract level, and I want the special handling of NonCommutativeMultiply to apply then. So it would be good if there were some way to create an operation that behaves in all respects as NonCommutativeMultiply (so that the package still recognizes it as such), except in a certain function of my design (so that it gets substituted for the correct explicit operation).
Is there a way I can accomplish this?
Edit: A perhaps-important complication is that in the general case, once made explicit the matrix dimensions will be such that the matrix multiplication A ** B1 will not be defined until the outer product B1 ** B2 has been performed.
function-construction operators argument-patterns
$endgroup$
add a comment |
$begingroup$
I am working with terms of the form
A**B1**B2
where A, B1, and B2 are at this point abstract operators and ** means NonCommutativeMultiply.
I'd like to manipulate these expressions at an abstract level, and then only later substitute explicit matrix operations. Specifically, $A$ will be a square matrix, while $B1$ and $B2$ will be commensurate vectors.
The trick is that at this point the specific meanings of the two occurrences of ** will change. Specifically, A ** B1 will become a matrix multiplication, and B1 ** B2 will become an outer product.
I'm using a package (NCAlgebra) to simplify the expressions at an abstract level, and I want the special handling of NonCommutativeMultiply to apply then. So it would be good if there were some way to create an operation that behaves in all respects as NonCommutativeMultiply (so that the package still recognizes it as such), except in a certain function of my design (so that it gets substituted for the correct explicit operation).
Is there a way I can accomplish this?
Edit: A perhaps-important complication is that in the general case, once made explicit the matrix dimensions will be such that the matrix multiplication A ** B1 will not be defined until the outer product B1 ** B2 has been performed.
function-construction operators argument-patterns
$endgroup$
$begingroup$
How are we supposed to distinguish between matrix multiplication and outer product? It looks the same to me.
$endgroup$
– Somos
1 hour ago
$begingroup$
Do you mean mathematically or in the code? Mathematically the two vectors are mapped by the outer product to a square matrix. In the code we would need to create a new function for at least one. I would like that function to behave as NonCommutativeMultiply, except when otherwise specified.
$endgroup$
– AGML
1 hour ago
$begingroup$
All I see isA**B1**B2and the two**look the same to me. How are we supposed to know that they are supposed to be different?
$endgroup$
– Somos
1 hour ago
$begingroup$
We of course cannot, at present. To solve the problem one of the two ** needs to be replaced by a new function. I have used ** in both cases because I want the new function to match the same existing patterns as ** would.
$endgroup$
– AGML
1 hour ago
$begingroup$
Alternatively, ** could be used in both cases, but the replacement rule could e.g. substitute an outer product only when the inner product is not defined, or something along those lines.
$endgroup$
– AGML
1 hour ago
add a comment |
$begingroup$
I am working with terms of the form
A**B1**B2
where A, B1, and B2 are at this point abstract operators and ** means NonCommutativeMultiply.
I'd like to manipulate these expressions at an abstract level, and then only later substitute explicit matrix operations. Specifically, $A$ will be a square matrix, while $B1$ and $B2$ will be commensurate vectors.
The trick is that at this point the specific meanings of the two occurrences of ** will change. Specifically, A ** B1 will become a matrix multiplication, and B1 ** B2 will become an outer product.
I'm using a package (NCAlgebra) to simplify the expressions at an abstract level, and I want the special handling of NonCommutativeMultiply to apply then. So it would be good if there were some way to create an operation that behaves in all respects as NonCommutativeMultiply (so that the package still recognizes it as such), except in a certain function of my design (so that it gets substituted for the correct explicit operation).
Is there a way I can accomplish this?
Edit: A perhaps-important complication is that in the general case, once made explicit the matrix dimensions will be such that the matrix multiplication A ** B1 will not be defined until the outer product B1 ** B2 has been performed.
function-construction operators argument-patterns
$endgroup$
I am working with terms of the form
A**B1**B2
where A, B1, and B2 are at this point abstract operators and ** means NonCommutativeMultiply.
I'd like to manipulate these expressions at an abstract level, and then only later substitute explicit matrix operations. Specifically, $A$ will be a square matrix, while $B1$ and $B2$ will be commensurate vectors.
The trick is that at this point the specific meanings of the two occurrences of ** will change. Specifically, A ** B1 will become a matrix multiplication, and B1 ** B2 will become an outer product.
I'm using a package (NCAlgebra) to simplify the expressions at an abstract level, and I want the special handling of NonCommutativeMultiply to apply then. So it would be good if there were some way to create an operation that behaves in all respects as NonCommutativeMultiply (so that the package still recognizes it as such), except in a certain function of my design (so that it gets substituted for the correct explicit operation).
Is there a way I can accomplish this?
Edit: A perhaps-important complication is that in the general case, once made explicit the matrix dimensions will be such that the matrix multiplication A ** B1 will not be defined until the outer product B1 ** B2 has been performed.
function-construction operators argument-patterns
function-construction operators argument-patterns
edited 2 hours ago
AGML
asked 2 hours ago
AGMLAGML
1557
1557
$begingroup$
How are we supposed to distinguish between matrix multiplication and outer product? It looks the same to me.
$endgroup$
– Somos
1 hour ago
$begingroup$
Do you mean mathematically or in the code? Mathematically the two vectors are mapped by the outer product to a square matrix. In the code we would need to create a new function for at least one. I would like that function to behave as NonCommutativeMultiply, except when otherwise specified.
$endgroup$
– AGML
1 hour ago
$begingroup$
All I see isA**B1**B2and the two**look the same to me. How are we supposed to know that they are supposed to be different?
$endgroup$
– Somos
1 hour ago
$begingroup$
We of course cannot, at present. To solve the problem one of the two ** needs to be replaced by a new function. I have used ** in both cases because I want the new function to match the same existing patterns as ** would.
$endgroup$
– AGML
1 hour ago
$begingroup$
Alternatively, ** could be used in both cases, but the replacement rule could e.g. substitute an outer product only when the inner product is not defined, or something along those lines.
$endgroup$
– AGML
1 hour ago
add a comment |
$begingroup$
How are we supposed to distinguish between matrix multiplication and outer product? It looks the same to me.
$endgroup$
– Somos
1 hour ago
$begingroup$
Do you mean mathematically or in the code? Mathematically the two vectors are mapped by the outer product to a square matrix. In the code we would need to create a new function for at least one. I would like that function to behave as NonCommutativeMultiply, except when otherwise specified.
$endgroup$
– AGML
1 hour ago
$begingroup$
All I see isA**B1**B2and the two**look the same to me. How are we supposed to know that they are supposed to be different?
$endgroup$
– Somos
1 hour ago
$begingroup$
We of course cannot, at present. To solve the problem one of the two ** needs to be replaced by a new function. I have used ** in both cases because I want the new function to match the same existing patterns as ** would.
$endgroup$
– AGML
1 hour ago
$begingroup$
Alternatively, ** could be used in both cases, but the replacement rule could e.g. substitute an outer product only when the inner product is not defined, or something along those lines.
$endgroup$
– AGML
1 hour ago
$begingroup$
How are we supposed to distinguish between matrix multiplication and outer product? It looks the same to me.
$endgroup$
– Somos
1 hour ago
$begingroup$
How are we supposed to distinguish between matrix multiplication and outer product? It looks the same to me.
$endgroup$
– Somos
1 hour ago
$begingroup$
Do you mean mathematically or in the code? Mathematically the two vectors are mapped by the outer product to a square matrix. In the code we would need to create a new function for at least one. I would like that function to behave as NonCommutativeMultiply, except when otherwise specified.
$endgroup$
– AGML
1 hour ago
$begingroup$
Do you mean mathematically or in the code? Mathematically the two vectors are mapped by the outer product to a square matrix. In the code we would need to create a new function for at least one. I would like that function to behave as NonCommutativeMultiply, except when otherwise specified.
$endgroup$
– AGML
1 hour ago
$begingroup$
All I see is
A**B1**B2 and the two ** look the same to me. How are we supposed to know that they are supposed to be different?$endgroup$
– Somos
1 hour ago
$begingroup$
All I see is
A**B1**B2 and the two ** look the same to me. How are we supposed to know that they are supposed to be different?$endgroup$
– Somos
1 hour ago
$begingroup$
We of course cannot, at present. To solve the problem one of the two ** needs to be replaced by a new function. I have used ** in both cases because I want the new function to match the same existing patterns as ** would.
$endgroup$
– AGML
1 hour ago
$begingroup$
We of course cannot, at present. To solve the problem one of the two ** needs to be replaced by a new function. I have used ** in both cases because I want the new function to match the same existing patterns as ** would.
$endgroup$
– AGML
1 hour ago
$begingroup$
Alternatively, ** could be used in both cases, but the replacement rule could e.g. substitute an outer product only when the inner product is not defined, or something along those lines.
$endgroup$
– AGML
1 hour ago
$begingroup$
Alternatively, ** could be used in both cases, but the replacement rule could e.g. substitute an outer product only when the inner product is not defined, or something along those lines.
$endgroup$
– AGML
1 hour ago
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
If I understand your question correctly, then the ** can be given a definition to do what you want. This code may work for you
Unprotect[NonCommutativeMultiply];
ClearAll[NonCommutativeMultiply];
NonCommutativeMultiply[x_?NumericQ, y_?NumericQ] := x * y;
NonCommutativeMultiply[x_?MatrixQ, y_?MatrixQ] := x . y;
NonCommutativeMultiply[x_?ListQ, y_?ListQ] := Outer[Times, x, y];
You can add more checking in the code as you need to.
$endgroup$
$begingroup$
Yes, that should work I think. Thank you!
$endgroup$
– AGML
1 hour ago
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%2f193255%2fdefine-different-actions-for-the-same-operator-depending-on-the-nature-of-its-ar%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
$begingroup$
If I understand your question correctly, then the ** can be given a definition to do what you want. This code may work for you
Unprotect[NonCommutativeMultiply];
ClearAll[NonCommutativeMultiply];
NonCommutativeMultiply[x_?NumericQ, y_?NumericQ] := x * y;
NonCommutativeMultiply[x_?MatrixQ, y_?MatrixQ] := x . y;
NonCommutativeMultiply[x_?ListQ, y_?ListQ] := Outer[Times, x, y];
You can add more checking in the code as you need to.
$endgroup$
$begingroup$
Yes, that should work I think. Thank you!
$endgroup$
– AGML
1 hour ago
add a comment |
$begingroup$
If I understand your question correctly, then the ** can be given a definition to do what you want. This code may work for you
Unprotect[NonCommutativeMultiply];
ClearAll[NonCommutativeMultiply];
NonCommutativeMultiply[x_?NumericQ, y_?NumericQ] := x * y;
NonCommutativeMultiply[x_?MatrixQ, y_?MatrixQ] := x . y;
NonCommutativeMultiply[x_?ListQ, y_?ListQ] := Outer[Times, x, y];
You can add more checking in the code as you need to.
$endgroup$
$begingroup$
Yes, that should work I think. Thank you!
$endgroup$
– AGML
1 hour ago
add a comment |
$begingroup$
If I understand your question correctly, then the ** can be given a definition to do what you want. This code may work for you
Unprotect[NonCommutativeMultiply];
ClearAll[NonCommutativeMultiply];
NonCommutativeMultiply[x_?NumericQ, y_?NumericQ] := x * y;
NonCommutativeMultiply[x_?MatrixQ, y_?MatrixQ] := x . y;
NonCommutativeMultiply[x_?ListQ, y_?ListQ] := Outer[Times, x, y];
You can add more checking in the code as you need to.
$endgroup$
If I understand your question correctly, then the ** can be given a definition to do what you want. This code may work for you
Unprotect[NonCommutativeMultiply];
ClearAll[NonCommutativeMultiply];
NonCommutativeMultiply[x_?NumericQ, y_?NumericQ] := x * y;
NonCommutativeMultiply[x_?MatrixQ, y_?MatrixQ] := x . y;
NonCommutativeMultiply[x_?ListQ, y_?ListQ] := Outer[Times, x, y];
You can add more checking in the code as you need to.
answered 1 hour ago
SomosSomos
1,42519
1,42519
$begingroup$
Yes, that should work I think. Thank you!
$endgroup$
– AGML
1 hour ago
add a comment |
$begingroup$
Yes, that should work I think. Thank you!
$endgroup$
– AGML
1 hour ago
$begingroup$
Yes, that should work I think. Thank you!
$endgroup$
– AGML
1 hour ago
$begingroup$
Yes, that should work I think. Thank you!
$endgroup$
– AGML
1 hour ago
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.
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%2f193255%2fdefine-different-actions-for-the-same-operator-depending-on-the-nature-of-its-ar%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
$begingroup$
How are we supposed to distinguish between matrix multiplication and outer product? It looks the same to me.
$endgroup$
– Somos
1 hour ago
$begingroup$
Do you mean mathematically or in the code? Mathematically the two vectors are mapped by the outer product to a square matrix. In the code we would need to create a new function for at least one. I would like that function to behave as NonCommutativeMultiply, except when otherwise specified.
$endgroup$
– AGML
1 hour ago
$begingroup$
All I see is
A**B1**B2and the two**look the same to me. How are we supposed to know that they are supposed to be different?$endgroup$
– Somos
1 hour ago
$begingroup$
We of course cannot, at present. To solve the problem one of the two ** needs to be replaced by a new function. I have used ** in both cases because I want the new function to match the same existing patterns as ** would.
$endgroup$
– AGML
1 hour ago
$begingroup$
Alternatively, ** could be used in both cases, but the replacement rule could e.g. substitute an outer product only when the inner product is not defined, or something along those lines.
$endgroup$
– AGML
1 hour ago