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?













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















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













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
















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















$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










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
    4 hours 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
    4 hours 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
    4 hours 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 4 hours ago









SomosSomos

1,42519




1,42519











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




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

Masuk log Menu navigasi

Identifying “long and narrow” polygons in with PostGISlength and width of polygonWhy postgis st_overlaps reports Qgis' “avoid intersections” generated polygon as overlapping with others?Adjusting polygons to boundary and filling holesDrawing polygons with fixed area?How to remove spikes in Polygons with PostGISDeleting sliver polygons after difference operation in QGIS?Snapping boundaries in PostGISSplit polygon into parts adding attributes based on underlying polygon in QGISSplitting overlap between polygons and assign to nearest polygon using PostGIS?Expanding polygons and clipping at midpoint?Removing Intersection of Buffers in Same Layers

Старые Смолеговицы Содержание История | География | Демография | Достопримечательности | Примечания | НавигацияHGЯOLHGЯOL41 206 832 01641 606 406 141Административно-территориальное деление Ленинградской области«Переписная оброчная книга Водской пятины 1500 года», С. 793«Карта Ингерманландии: Ивангорода, Яма, Копорья, Нотеборга», по материалам 1676 г.«Генеральная карта провинции Ингерманландии» Э. Белинга и А. Андерсина, 1704 г., составлена по материалам 1678 г.«Географический чертёж над Ижорскою землей со своими городами» Адриана Шонбека 1705 г.Новая и достоверная всей Ингерманландии ланткарта. Грав. А. Ростовцев. СПб., 1727 г.Топографическая карта Санкт-Петербургской губернии. 5-и верстка. Шуберт. 1834 г.Описание Санкт-Петербургской губернии по уездам и станамСпецкарта западной части России Ф. Ф. Шуберта. 1844 г.Алфавитный список селений по уездам и станам С.-Петербургской губернииСписки населённых мест Российской Империи, составленные и издаваемые центральным статистическим комитетом министерства внутренних дел. XXXVII. Санкт-Петербургская губерния. По состоянию на 1862 год. СПб. 1864. С. 203Материалы по статистике народного хозяйства в С.-Петербургской губернии. Вып. IX. Частновладельческое хозяйство в Ямбургском уезде. СПб, 1888, С. 146, С. 2, 7, 54Положение о гербе муниципального образования Курское сельское поселениеСправочник истории административно-территориального деления Ленинградской области.Топографическая карта Ленинградской области, квадрат О-35-23-В (Хотыницы), 1930 г.АрхивированоАдминистративно-территориальное деление Ленинградской области. — Л., 1933, С. 27, 198АрхивированоАдминистративно-экономический справочник по Ленинградской области. — Л., 1936, с. 219АрхивированоАдминистративно-территориальное деление Ленинградской области. — Л., 1966, с. 175АрхивированоАдминистративно-территориальное деление Ленинградской области. — Лениздат, 1973, С. 180АрхивированоАдминистративно-территориальное деление Ленинградской области. — Лениздат, 1990, ISBN 5-289-00612-5, С. 38АрхивированоАдминистративно-территориальное деление Ленинградской области. — СПб., 2007, с. 60АрхивированоКоряков Юрий База данных «Этно-языковой состав населённых пунктов России». Ленинградская область.Административно-территориальное деление Ленинградской области. — СПб, 1997, ISBN 5-86153-055-6, С. 41АрхивированоКультовый комплекс Старые Смолеговицы // Электронная энциклопедия ЭрмитажаПроблемы выявления, изучения и сохранения культовых комплексов с каменными крестами: по материалам работ 2016-2017 гг. в Ленинградской области