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?
Theorems like the Lovász Local Lemma?
2D counterpart of std::array in C++17
Fill color and outline color with the same value
Be in awe of my brilliance!
Informing my boss about remarks from a nasty colleague
Why must traveling waves have the same amplitude to form a standing wave?
My adviser wants to be the first author
Bash: What does "masking return values" mean?
Make a transparent 448*448 image
Where is the 1/8 CR apprentice in Volo's Guide to Monsters?
I need to drive a 7/16" nut but am unsure how to use the socket I bought for my screwdriver
Russian cases: A few examples, I'm really confused
How to deal with taxi scam when on vacation?
Is a lawful good "antagonist" effective?
Why did it take so long to abandon sail after steamships were demonstrated?
Counting certain elements in lists
RegionDifference for Cylinder and Cuboid
Can elves maintain concentration in a trance?
Do I need life insurance if I can cover my own funeral costs?
Brexit - No Deal Rejection
Why is stat::st_size 0 for devices but at the same time lseek defines the device size correctly?
How to simplify this time periods definition interface?
Can the damage from a Talisman of Pure Good (or Ultimate Evil) be non-lethal?
Replacing Windows 7 security updates with anti-virus?
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
4 hours 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
4 hours ago
$begingroup$
All I see isA**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
4 hours 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
4 hours 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
4 hours 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 5 hours ago
AGML
asked 5 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
4 hours 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
4 hours ago
$begingroup$
All I see isA**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
4 hours 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
4 hours 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
4 hours 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
4 hours 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
4 hours ago
$begingroup$
All I see isA**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
4 hours 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
4 hours 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
4 hours ago
$begingroup$
How are we supposed to distinguish between matrix multiplication and outer product? It looks the same to me.
$endgroup$
– Somos
4 hours ago
$begingroup$
How are we supposed to distinguish between matrix multiplication and outer product? It looks the same to me.
$endgroup$
– Somos
4 hours 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
4 hours 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
4 hours 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
4 hours 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
4 hours 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
4 hours 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
4 hours 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
4 hours 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
4 hours 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
4 hours 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
4 hours 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
4 hours 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 4 hours ago
SomosSomos
1,42519
1,42519
$begingroup$
Yes, that should work I think. Thank you!
$endgroup$
– AGML
4 hours ago
add a comment |
$begingroup$
Yes, that should work I think. Thank you!
$endgroup$
– AGML
4 hours ago
$begingroup$
Yes, that should work I think. Thank you!
$endgroup$
– AGML
4 hours ago
$begingroup$
Yes, that should work I think. Thank you!
$endgroup$
– AGML
4 hours 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
4 hours 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
4 hours 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
4 hours 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
4 hours 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
4 hours ago