Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

I need to combine data structures in operations analogous to addition, subtraction, multiplication and division (and more). I need more than one operation of each type, i.e. more than one method of addition, subtraction, etc. I have made some progress. Using the Notation palette, i can for example define !/! and %/% as different operators for division. But how can I set precedence? My impression is that this is not possible. I have explored the existing symbols without in-built meanings, such as CirclePlus and CircleMinus. These symbols without in-built meanings have precedence while allowing the meaning to be defined by the user. But I can't find enough of them to meet my needs. For example, there is no "CircleDivide".

Might it be possible to use subscripts and have $/_a$ and $/_b$ for different types of division while retaining the precedence of the division operator? If I could do it for division, then I could do it for the other operators of interest too.

ADDENDUM: I've made some progress following the cluethe clue provided by Mr.WizardMr.Wizard. The following code creates subscripted operators for operations analogous to +,-,*,/. The conv functions are highly simplified for test purposes and in the actual application would perform operations on data structures.

In[1]:= conv[x_, y_, op_ /; op == "+" || op == "-"] := Module[{}, If[op == "-", Return[conv[x, -y, "+"]]]; x + y] conv[x_, y_, op_ /; op == "*" || op == "/"] := Module[{}, If[op == "/", Return[conv[x, 1/y, "*"]]]; x y] MakeExpression[RowBox[{x_, SubscriptBox["+", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"+\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["-", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"-\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["*", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"*\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["/", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"/\"", "]"}], StandardForm] 

Testing the code, it works at least up to a point and the subscripted operators appear to have the same precedence as the parent operators (+,*, etc.):

test 1

However, if I remove the parentheses from the second test expression, I get an error message. Why is that occurring and how do I fix it?

test 2

I need to combine data structures in operations analogous to addition, subtraction, multiplication and division (and more). I need more than one operation of each type, i.e. more than one method of addition, subtraction, etc. I have made some progress. Using the Notation palette, i can for example define !/! and %/% as different operators for division. But how can I set precedence? My impression is that this is not possible. I have explored the existing symbols without in-built meanings, such as CirclePlus and CircleMinus. These symbols without in-built meanings have precedence while allowing the meaning to be defined by the user. But I can't find enough of them to meet my needs. For example, there is no "CircleDivide".

Might it be possible to use subscripts and have $/_a$ and $/_b$ for different types of division while retaining the precedence of the division operator? If I could do it for division, then I could do it for the other operators of interest too.

ADDENDUM: I've made some progress following the clue provided by Mr.Wizard. The following code creates subscripted operators for operations analogous to +,-,*,/. The conv functions are highly simplified for test purposes and in the actual application would perform operations on data structures.

In[1]:= conv[x_, y_, op_ /; op == "+" || op == "-"] := Module[{}, If[op == "-", Return[conv[x, -y, "+"]]]; x + y] conv[x_, y_, op_ /; op == "*" || op == "/"] := Module[{}, If[op == "/", Return[conv[x, 1/y, "*"]]]; x y] MakeExpression[RowBox[{x_, SubscriptBox["+", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"+\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["-", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"-\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["*", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"*\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["/", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"/\"", "]"}], StandardForm] 

Testing the code, it works at least up to a point and the subscripted operators appear to have the same precedence as the parent operators (+,*, etc.):

test 1

However, if I remove the parentheses from the second test expression, I get an error message. Why is that occurring and how do I fix it?

test 2

I need to combine data structures in operations analogous to addition, subtraction, multiplication and division (and more). I need more than one operation of each type, i.e. more than one method of addition, subtraction, etc. I have made some progress. Using the Notation palette, i can for example define !/! and %/% as different operators for division. But how can I set precedence? My impression is that this is not possible. I have explored the existing symbols without in-built meanings, such as CirclePlus and CircleMinus. These symbols without in-built meanings have precedence while allowing the meaning to be defined by the user. But I can't find enough of them to meet my needs. For example, there is no "CircleDivide".

Might it be possible to use subscripts and have $/_a$ and $/_b$ for different types of division while retaining the precedence of the division operator? If I could do it for division, then I could do it for the other operators of interest too.

ADDENDUM: I've made some progress following the clue provided by Mr.Wizard. The following code creates subscripted operators for operations analogous to +,-,*,/. The conv functions are highly simplified for test purposes and in the actual application would perform operations on data structures.

In[1]:= conv[x_, y_, op_ /; op == "+" || op == "-"] := Module[{}, If[op == "-", Return[conv[x, -y, "+"]]]; x + y] conv[x_, y_, op_ /; op == "*" || op == "/"] := Module[{}, If[op == "/", Return[conv[x, 1/y, "*"]]]; x y] MakeExpression[RowBox[{x_, SubscriptBox["+", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"+\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["-", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"-\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["*", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"*\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["/", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"/\"", "]"}], StandardForm] 

Testing the code, it works at least up to a point and the subscripted operators appear to have the same precedence as the parent operators (+,*, etc.):

test 1

However, if I remove the parentheses from the second test expression, I get an error message. Why is that occurring and how do I fix it?

test 2

added 213 characters in body; edited tags
Source Link
Karsten7
  • 27.7k
  • 5
  • 76
  • 138

I need to combine data structures in operations analogous to addition, subtraction, multiplication and division (and more). I need more than one operation of each type, i.e. more than one method of addition, subtraction, etc. I have made some progress. Using the Notation palette, i can for example define !/!!/! and %/%%/% as different operators for division. But how can I set precedence? My impression is that this is not possible. I have explored the existing symbols without in-built meanings, such as CirclePlusCirclePlus and CircleMinusCircleMinus. These symbols without in-built meanings have precedence while allowing the meaning to be defined by the user. But I can't find enough of them to meet my needs. For example, there is no "CircleDivide""CircleDivide".

Might it be possible to use subscripts and have $/_a$ and $/_b$ for different types of division while retaining the precedence of the division operator? If I could do it for division, then I could do it for the other operators of interest too.

ADDENDUM: I've made some progress following the cluethe clue provided by @Mr.WizardMr.Wizard. The following code creates subscripted operators for operations analogous to ++,--,**,//. The 'conv'conv functions are highly simplified for test purposes and in the actual application would perform operations on data structures.

In[1]:= conv[x_, y_, op_ /; op == "+" || op == "-"] := Module[{}, If[op == "-", Return[conv[x, -y, "+"]]]; x + y] conv[x_, y_, op_ /; op == "*" || op == "/"] := Module[{}, If[op == "/", Return[conv[x, 1/y, "*"]]]; x y] MakeExpression[RowBox[{x_, SubscriptBox["+", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"+\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["-", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"-\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["*", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"*\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["/", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"/\"", "]"}], StandardForm] 

Testing the code, it works at least up to a point and the subscripted operators appear to have the same precedence as the parent operators (++,**, etc.):

test 1

However, if I remove the parentheses from the second test expression, I get an error message. Why is that occurring and how do I fix it?

test 2

I need to combine data structures in operations analogous to addition, subtraction, multiplication and division (and more). I need more than one operation of each type, i.e. more than one method of addition, subtraction, etc. I have made some progress. Using the Notation palette, i can for example define !/! and %/% as different operators for division. But how can I set precedence? My impression is that this is not possible. I have explored the existing symbols without in-built meanings, such as CirclePlus and CircleMinus. These symbols without in-built meanings have precedence while allowing the meaning to be defined by the user. But I can't find enough of them to meet my needs. For example, there is no "CircleDivide".

Might it be possible to use subscripts and have $/_a$ and $/_b$ for different types of division while retaining the precedence of the division operator? If I could do it for division, then I could do it for the other operators of interest too.

ADDENDUM: I've made some progress following the clue provided by @Mr.Wizard. The following code creates subscripted operators for operations analogous to +,-,*,/. The 'conv' functions are highly simplified for test purposes and in the actual application would perform operations on data structures.

In[1]:= conv[x_, y_, op_ /; op == "+" || op == "-"] := Module[{}, If[op == "-", Return[conv[x, -y, "+"]]]; x + y] conv[x_, y_, op_ /; op == "*" || op == "/"] := Module[{}, If[op == "/", Return[conv[x, 1/y, "*"]]]; x y] MakeExpression[RowBox[{x_, SubscriptBox["+", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"+\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["-", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"-\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["*", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"*\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["/", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"/\"", "]"}], StandardForm] 

Testing the code, it works at least up to a point and the subscripted operators appear to have the same precedence as the parent operators (+,*, etc.):

test 1

However, if I remove the parentheses from the second test expression, I get an error message. Why is that occurring and how do I fix it?

test 2

I need to combine data structures in operations analogous to addition, subtraction, multiplication and division (and more). I need more than one operation of each type, i.e. more than one method of addition, subtraction, etc. I have made some progress. Using the Notation palette, i can for example define !/! and %/% as different operators for division. But how can I set precedence? My impression is that this is not possible. I have explored the existing symbols without in-built meanings, such as CirclePlus and CircleMinus. These symbols without in-built meanings have precedence while allowing the meaning to be defined by the user. But I can't find enough of them to meet my needs. For example, there is no "CircleDivide".

Might it be possible to use subscripts and have $/_a$ and $/_b$ for different types of division while retaining the precedence of the division operator? If I could do it for division, then I could do it for the other operators of interest too.

ADDENDUM: I've made some progress following the clue provided by Mr.Wizard. The following code creates subscripted operators for operations analogous to +,-,*,/. The conv functions are highly simplified for test purposes and in the actual application would perform operations on data structures.

In[1]:= conv[x_, y_, op_ /; op == "+" || op == "-"] := Module[{}, If[op == "-", Return[conv[x, -y, "+"]]]; x + y] conv[x_, y_, op_ /; op == "*" || op == "/"] := Module[{}, If[op == "/", Return[conv[x, 1/y, "*"]]]; x y] MakeExpression[RowBox[{x_, SubscriptBox["+", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"+\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["-", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"-\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["*", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"*\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["/", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"/\"", "]"}], StandardForm] 

Testing the code, it works at least up to a point and the subscripted operators appear to have the same precedence as the parent operators (+,*, etc.):

test 1

However, if I remove the parentheses from the second test expression, I get an error message. Why is that occurring and how do I fix it?

test 2

added 24 characters in body
Source Link
Duns
  • 275
  • 1
  • 5

I need to combine data structures in operations analogous to addition, subtraction, multiplication and division (and more). I need more than one operation of each type, i.e. more than one method of addition, subtraction, etc. I have made some progress. Using the Notation palette, i can for example define !/! and %/% as different operators for division. But how can I set precedence? My impression is that this is not possible. I have explored the existing symbols without in-built meanings, such as CirclePlus and CircleMinus. These symbols without in-built meanings have precedence while allowing the meaning to be defined by the user. But I can't find enough of them to meet my needs. For example, there is no "CircleDivide".

Might it be possible to use subscripts and have $/_a$ and $/_b$ for different types of division while retaining the precedence of the division operator? If I could do it for division, then I could do it for the other operators of interest too.

ADDENDUM: I've made some progress following the clue provided by @Mr.Wizard. The following code creates subscripted operators for operations analogous to +,-,*,/. The 'conv' functions are highly simplified for test purposes and in the actual application would perform operations on data structures.

In[1]:= conv[x_, y_, op_ /; op == "+" || op == "-"] := Module[{}, If[op == "-", Return[conv[x, -y, "+"]]]; x + y] conv[x_, y_, op_ /; op == "*" || op == "/"] := Module[{}, If[op == "/", Return[conv[x, 1/y, "*"]]]; x y] MakeExpression[RowBox[{x_, SubscriptBox["+", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"+\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["-", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"-\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["*", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"*\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["/", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"/\"", "]"}], StandardForm] 

Testing the code, it works at least up to a point and the subscripted operators appear to have the same precedence as the parent operators (+,*, etc.):

test 1

However, if I remove the parentheses from the second test expression, I get an error message. HowWhy is that occurring and how do I fix thatit?

test 2

I need to combine data structures in operations analogous to addition, subtraction, multiplication and division (and more). I need more than one operation of each type, i.e. more than one method of addition, subtraction, etc. I have made some progress. Using the Notation palette, i can for example define !/! and %/% as different operators for division. But how can I set precedence? My impression is that this is not possible. I have explored the existing symbols without in-built meanings, such as CirclePlus and CircleMinus. These symbols without in-built meanings have precedence while allowing the meaning to be defined by the user. But I can't find enough of them to meet my needs. For example, there is no "CircleDivide".

Might it be possible to use subscripts and have $/_a$ and $/_b$ for different types of division while retaining the precedence of the division operator? If I could do it for division, then I could do it for the other operators of interest too.

ADDENDUM: I've made some progress following the clue provided by @Mr.Wizard. The following code creates subscripted operators for operations analogous to +,-,*,/. The 'conv' functions are highly simplified for test purposes and in the actual application would perform operations on data structures.

In[1]:= conv[x_, y_, op_ /; op == "+" || op == "-"] := Module[{}, If[op == "-", Return[conv[x, -y, "+"]]]; x + y] conv[x_, y_, op_ /; op == "*" || op == "/"] := Module[{}, If[op == "/", Return[conv[x, 1/y, "*"]]]; x y] MakeExpression[RowBox[{x_, SubscriptBox["+", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"+\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["-", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"-\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["*", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"*\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["/", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"/\"", "]"}], StandardForm] 

Testing the code, it works at least up to a point and the subscripted operators appear to have the same precedence as the parent operators (+,*, etc.):

test 1

However, if I remove the parentheses from the second test expression, I get an error message. How do I fix that?

test 2

I need to combine data structures in operations analogous to addition, subtraction, multiplication and division (and more). I need more than one operation of each type, i.e. more than one method of addition, subtraction, etc. I have made some progress. Using the Notation palette, i can for example define !/! and %/% as different operators for division. But how can I set precedence? My impression is that this is not possible. I have explored the existing symbols without in-built meanings, such as CirclePlus and CircleMinus. These symbols without in-built meanings have precedence while allowing the meaning to be defined by the user. But I can't find enough of them to meet my needs. For example, there is no "CircleDivide".

Might it be possible to use subscripts and have $/_a$ and $/_b$ for different types of division while retaining the precedence of the division operator? If I could do it for division, then I could do it for the other operators of interest too.

ADDENDUM: I've made some progress following the clue provided by @Mr.Wizard. The following code creates subscripted operators for operations analogous to +,-,*,/. The 'conv' functions are highly simplified for test purposes and in the actual application would perform operations on data structures.

In[1]:= conv[x_, y_, op_ /; op == "+" || op == "-"] := Module[{}, If[op == "-", Return[conv[x, -y, "+"]]]; x + y] conv[x_, y_, op_ /; op == "*" || op == "/"] := Module[{}, If[op == "/", Return[conv[x, 1/y, "*"]]]; x y] MakeExpression[RowBox[{x_, SubscriptBox["+", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"+\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["-", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"-\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["*", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"*\"", "]"}], StandardForm] MakeExpression[RowBox[{x_, SubscriptBox["/", "i"], y_}], StandardForm] := MakeExpression[RowBox[{"conv", "[", x, ",", y, ",", "\"/\"", "]"}], StandardForm] 

Testing the code, it works at least up to a point and the subscripted operators appear to have the same precedence as the parent operators (+,*, etc.):

test 1

However, if I remove the parentheses from the second test expression, I get an error message. Why is that occurring and how do I fix it?

test 2

added 10 characters in body
Source Link
Duns
  • 275
  • 1
  • 5
Loading
Addendum to report some progress.
Source Link
Duns
  • 275
  • 1
  • 5
Loading
Addendum to report some progress.
Source Link
Duns
  • 275
  • 1
  • 5
Loading
Tweeted twitter.com/#!/StackMma/status/567010295735132160
added 98 characters in body
Source Link
Duns
  • 275
  • 1
  • 5
Loading
Source Link
Duns
  • 275
  • 1
  • 5
Loading