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?













1












$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.










share|improve this question











$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 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$
    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















1












$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.










share|improve this question











$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 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$
    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













1












1








1





$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.










share|improve this question











$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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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$
    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$
    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$
    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










1 Answer
1






active

oldest

votes


















3












$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.






share|improve this answer









$endgroup$












  • $begingroup$
    Yes, that should work I think. Thank you!
    $endgroup$
    – AGML
    1 hour 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%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









3












$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.






share|improve this answer









$endgroup$












  • $begingroup$
    Yes, that should work I think. Thank you!
    $endgroup$
    – AGML
    1 hour ago















3












$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.






share|improve this answer









$endgroup$












  • $begingroup$
    Yes, that should work I think. Thank you!
    $endgroup$
    – AGML
    1 hour ago













3












3








3





$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.






share|improve this answer









$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.







share|improve this answer












share|improve this answer



share|improve this answer










answered 1 hour ago









SomosSomos

1,42519




1,42519











  • $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




$begingroup$
Yes, that should work I think. Thank you!
$endgroup$
– AGML
1 hour 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%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





















































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

Era Viking Índice Início da Era Viquingue | Cotidiano | Sociedade | Língua | Religião | A arte | As primeiras cidades | As viagens dos viquingues | Viquingues do Oeste e Leste | Fim da Era Viquingue | Fontes históricas | Referências Bibliografia | Ligações externas | Menu de navegação«Sverige då!»«Handel I vikingetid»«O que é Nórdico Antigo»Mito, magia e religião na volsunga saga Um olhar sobre a trajetória mítica do herói sigurd«Bonden var den verklige vikingen»«Vikingatiden»«Vikingatiden»«Vinland»«Guerreiras de Óðinn: As Valkyrjor na Mitologia Viking»1519-9053«Esculpindo símbolos e seres: A arte viking em pedras rúnicas»1679-9313Historia - Tema: VikingarnaAventura e Magia no Mundo das Sagas IslandesasEra Vikinge

What's the metal clinking sound at the end of credits in Avengers: Endgame?What makes Thanos so strong in Avengers: Endgame?Who is the character that appears at the end of Endgame?What happens to Mjolnir (Thor's hammer) at the end of Endgame?The People's Ages in Avengers: EndgameWhat did Nebula do in Avengers: Endgame?Messing with time in the Avengers: Endgame climaxAvengers: Endgame timelineWhat are the time-travel rules in Avengers Endgame?Why use this song in Avengers: Endgame Opening Logo Sequence?Peggy's age in Avengers Endgame

Are there legal definitions of ethnicities/races? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Legal definitions in the United StatesAre there truly legal limits on US interest rates?Are gender identity and sexual orientation federally protected?Why is there an apparent legal bias against digital services?What limits are there to the powers of individual judges in the United States legal system?Are women only scholarships legal under Irish / EU law?Is the term “race” defined by Public Law enacted by Congress of the United StatesIs there a legal definition of race in the US?Neighbors are spying for landlord on Renters is it legal?Are Protected Classes Bi-directional?