Issue with Upvalues
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
I want to introduce two variables (I call them EXt and EXtC, where "C" stands for complex conjugate) which would mimic the behavior of a phase of a complex number. For that, I use the following tags:
EXt /: EXt EXtC := 1;
EXtC /: EXtC EXt := 1;
EXt /: EXt EXtC^n_ := EXtC^(n - 1);
EXtC /: EXtC EXt^n_ := EXt^(n - 1);
EXt /: EXt^(n_?Negative) := EXtC^(-n);
EXtC /: EXtC^(n_?Negative) := EXt^(-n);
EXt /: Conjugate[EXt] := EXtC;
EXtC /: Conjugate[EXtC] := EXt;
With that, I can simplify expressions like
EXt^2 EXt^2
i.e. when both of the variables have the same power (and this power is a number)
However, I am not able to simplify the expressions in which the powers are different. For example, I cannot simplify (i.e. make it equal to EXtC in this case),
EXt^2 EXtC^3
even with the use of FullSimplify
. I tried to introduce the following tag
EXt /: EXt^n_ EXtC^m_ := EXtC^(m - n)
but soon learned (for example, from here) that the upvalue mechanism can only scan one level deep, so I expectedly get the error message
TagSetDelayed::tagpos: Tag EXt in EXt^n_ EXtC^m_ is too deep for an assigned rule to be found. >>
Any ideas on how to circumvent this restriction and implement this property?
simplifying-expressions symbolic upvalues
New contributor
add a comment |Â
up vote
4
down vote
favorite
I want to introduce two variables (I call them EXt and EXtC, where "C" stands for complex conjugate) which would mimic the behavior of a phase of a complex number. For that, I use the following tags:
EXt /: EXt EXtC := 1;
EXtC /: EXtC EXt := 1;
EXt /: EXt EXtC^n_ := EXtC^(n - 1);
EXtC /: EXtC EXt^n_ := EXt^(n - 1);
EXt /: EXt^(n_?Negative) := EXtC^(-n);
EXtC /: EXtC^(n_?Negative) := EXt^(-n);
EXt /: Conjugate[EXt] := EXtC;
EXtC /: Conjugate[EXtC] := EXt;
With that, I can simplify expressions like
EXt^2 EXt^2
i.e. when both of the variables have the same power (and this power is a number)
However, I am not able to simplify the expressions in which the powers are different. For example, I cannot simplify (i.e. make it equal to EXtC in this case),
EXt^2 EXtC^3
even with the use of FullSimplify
. I tried to introduce the following tag
EXt /: EXt^n_ EXtC^m_ := EXtC^(m - n)
but soon learned (for example, from here) that the upvalue mechanism can only scan one level deep, so I expectedly get the error message
TagSetDelayed::tagpos: Tag EXt in EXt^n_ EXtC^m_ is too deep for an assigned rule to be found. >>
Any ideas on how to circumvent this restriction and implement this property?
simplifying-expressions symbolic upvalues
New contributor
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I want to introduce two variables (I call them EXt and EXtC, where "C" stands for complex conjugate) which would mimic the behavior of a phase of a complex number. For that, I use the following tags:
EXt /: EXt EXtC := 1;
EXtC /: EXtC EXt := 1;
EXt /: EXt EXtC^n_ := EXtC^(n - 1);
EXtC /: EXtC EXt^n_ := EXt^(n - 1);
EXt /: EXt^(n_?Negative) := EXtC^(-n);
EXtC /: EXtC^(n_?Negative) := EXt^(-n);
EXt /: Conjugate[EXt] := EXtC;
EXtC /: Conjugate[EXtC] := EXt;
With that, I can simplify expressions like
EXt^2 EXt^2
i.e. when both of the variables have the same power (and this power is a number)
However, I am not able to simplify the expressions in which the powers are different. For example, I cannot simplify (i.e. make it equal to EXtC in this case),
EXt^2 EXtC^3
even with the use of FullSimplify
. I tried to introduce the following tag
EXt /: EXt^n_ EXtC^m_ := EXtC^(m - n)
but soon learned (for example, from here) that the upvalue mechanism can only scan one level deep, so I expectedly get the error message
TagSetDelayed::tagpos: Tag EXt in EXt^n_ EXtC^m_ is too deep for an assigned rule to be found. >>
Any ideas on how to circumvent this restriction and implement this property?
simplifying-expressions symbolic upvalues
New contributor
I want to introduce two variables (I call them EXt and EXtC, where "C" stands for complex conjugate) which would mimic the behavior of a phase of a complex number. For that, I use the following tags:
EXt /: EXt EXtC := 1;
EXtC /: EXtC EXt := 1;
EXt /: EXt EXtC^n_ := EXtC^(n - 1);
EXtC /: EXtC EXt^n_ := EXt^(n - 1);
EXt /: EXt^(n_?Negative) := EXtC^(-n);
EXtC /: EXtC^(n_?Negative) := EXt^(-n);
EXt /: Conjugate[EXt] := EXtC;
EXtC /: Conjugate[EXtC] := EXt;
With that, I can simplify expressions like
EXt^2 EXt^2
i.e. when both of the variables have the same power (and this power is a number)
However, I am not able to simplify the expressions in which the powers are different. For example, I cannot simplify (i.e. make it equal to EXtC in this case),
EXt^2 EXtC^3
even with the use of FullSimplify
. I tried to introduce the following tag
EXt /: EXt^n_ EXtC^m_ := EXtC^(m - n)
but soon learned (for example, from here) that the upvalue mechanism can only scan one level deep, so I expectedly get the error message
TagSetDelayed::tagpos: Tag EXt in EXt^n_ EXtC^m_ is too deep for an assigned rule to be found. >>
Any ideas on how to circumvent this restriction and implement this property?
simplifying-expressions symbolic upvalues
simplifying-expressions symbolic upvalues
New contributor
New contributor
New contributor
asked 2 hours ago
user43283
1211
1211
New contributor
New contributor
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
How about the following?:
Clear[ext, extc]
ext /: ext[n_] extc[m_] := extc[m - n]
ext /: ext[n_] ext[m_] := ext[m + n]
extc /: extc[n_] extc[m_] := extc[m + n]
ext /: Conjugate@ext[n_] := extc[n]
extc /: Conjugate@extc[n_] := ext[n]
extc[n_?Negative] := ext[-n]
ext[n_?Negative] := extc[-n]
extc[0] = 1;
The compromises are:
EXt^n
andEXtC^n
are expressed asext[n]
andextc[n]
.Single
EXt
andEXtC
must be expressed asext[1]
andextc[1]
.
Example:
ext@2 extc@3
(* extc[1] *)
ext@1 extc@n // Conjugate
(* ext[-1 + n] *)
add a comment |Â
up vote
2
down vote
Here's a variation of @xzczd's idea, using only a single symbol and adding formatting:
Clear[ext]
ext[n_] ext[m_] ^:= ext[n+m]
ext[n_]^m_ ^:= ext[n m]
Conjugate[ext[n_]] ^:= ext[-n]
ext[0] = 1;
MakeBoxes[ext[n_],StandardForm]:=Switch[n,
0, "1",
1, MakeBoxes[EXt],
-1, MakeBoxes[EXtC],
_Integer?Negative, With[s=-n, MakeBoxes[EXtC^s]],
_, MakeBoxes[EXt^n]
]
For example:
EXt = ext[1]
EXtC = ext[-1]
EXt
EXtC
And:
EXt^2 EXtC^2
EXt^2 EXtC^3
EXt EXtC^n //Conjugate
1
EXtC
EXt^(-1 + n)
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
How about the following?:
Clear[ext, extc]
ext /: ext[n_] extc[m_] := extc[m - n]
ext /: ext[n_] ext[m_] := ext[m + n]
extc /: extc[n_] extc[m_] := extc[m + n]
ext /: Conjugate@ext[n_] := extc[n]
extc /: Conjugate@extc[n_] := ext[n]
extc[n_?Negative] := ext[-n]
ext[n_?Negative] := extc[-n]
extc[0] = 1;
The compromises are:
EXt^n
andEXtC^n
are expressed asext[n]
andextc[n]
.Single
EXt
andEXtC
must be expressed asext[1]
andextc[1]
.
Example:
ext@2 extc@3
(* extc[1] *)
ext@1 extc@n // Conjugate
(* ext[-1 + n] *)
add a comment |Â
up vote
2
down vote
How about the following?:
Clear[ext, extc]
ext /: ext[n_] extc[m_] := extc[m - n]
ext /: ext[n_] ext[m_] := ext[m + n]
extc /: extc[n_] extc[m_] := extc[m + n]
ext /: Conjugate@ext[n_] := extc[n]
extc /: Conjugate@extc[n_] := ext[n]
extc[n_?Negative] := ext[-n]
ext[n_?Negative] := extc[-n]
extc[0] = 1;
The compromises are:
EXt^n
andEXtC^n
are expressed asext[n]
andextc[n]
.Single
EXt
andEXtC
must be expressed asext[1]
andextc[1]
.
Example:
ext@2 extc@3
(* extc[1] *)
ext@1 extc@n // Conjugate
(* ext[-1 + n] *)
add a comment |Â
up vote
2
down vote
up vote
2
down vote
How about the following?:
Clear[ext, extc]
ext /: ext[n_] extc[m_] := extc[m - n]
ext /: ext[n_] ext[m_] := ext[m + n]
extc /: extc[n_] extc[m_] := extc[m + n]
ext /: Conjugate@ext[n_] := extc[n]
extc /: Conjugate@extc[n_] := ext[n]
extc[n_?Negative] := ext[-n]
ext[n_?Negative] := extc[-n]
extc[0] = 1;
The compromises are:
EXt^n
andEXtC^n
are expressed asext[n]
andextc[n]
.Single
EXt
andEXtC
must be expressed asext[1]
andextc[1]
.
Example:
ext@2 extc@3
(* extc[1] *)
ext@1 extc@n // Conjugate
(* ext[-1 + n] *)
How about the following?:
Clear[ext, extc]
ext /: ext[n_] extc[m_] := extc[m - n]
ext /: ext[n_] ext[m_] := ext[m + n]
extc /: extc[n_] extc[m_] := extc[m + n]
ext /: Conjugate@ext[n_] := extc[n]
extc /: Conjugate@extc[n_] := ext[n]
extc[n_?Negative] := ext[-n]
ext[n_?Negative] := extc[-n]
extc[0] = 1;
The compromises are:
EXt^n
andEXtC^n
are expressed asext[n]
andextc[n]
.Single
EXt
andEXtC
must be expressed asext[1]
andextc[1]
.
Example:
ext@2 extc@3
(* extc[1] *)
ext@1 extc@n // Conjugate
(* ext[-1 + n] *)
answered 1 hour ago
xzczd
25k467236
25k467236
add a comment |Â
add a comment |Â
up vote
2
down vote
Here's a variation of @xzczd's idea, using only a single symbol and adding formatting:
Clear[ext]
ext[n_] ext[m_] ^:= ext[n+m]
ext[n_]^m_ ^:= ext[n m]
Conjugate[ext[n_]] ^:= ext[-n]
ext[0] = 1;
MakeBoxes[ext[n_],StandardForm]:=Switch[n,
0, "1",
1, MakeBoxes[EXt],
-1, MakeBoxes[EXtC],
_Integer?Negative, With[s=-n, MakeBoxes[EXtC^s]],
_, MakeBoxes[EXt^n]
]
For example:
EXt = ext[1]
EXtC = ext[-1]
EXt
EXtC
And:
EXt^2 EXtC^2
EXt^2 EXtC^3
EXt EXtC^n //Conjugate
1
EXtC
EXt^(-1 + n)
add a comment |Â
up vote
2
down vote
Here's a variation of @xzczd's idea, using only a single symbol and adding formatting:
Clear[ext]
ext[n_] ext[m_] ^:= ext[n+m]
ext[n_]^m_ ^:= ext[n m]
Conjugate[ext[n_]] ^:= ext[-n]
ext[0] = 1;
MakeBoxes[ext[n_],StandardForm]:=Switch[n,
0, "1",
1, MakeBoxes[EXt],
-1, MakeBoxes[EXtC],
_Integer?Negative, With[s=-n, MakeBoxes[EXtC^s]],
_, MakeBoxes[EXt^n]
]
For example:
EXt = ext[1]
EXtC = ext[-1]
EXt
EXtC
And:
EXt^2 EXtC^2
EXt^2 EXtC^3
EXt EXtC^n //Conjugate
1
EXtC
EXt^(-1 + n)
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Here's a variation of @xzczd's idea, using only a single symbol and adding formatting:
Clear[ext]
ext[n_] ext[m_] ^:= ext[n+m]
ext[n_]^m_ ^:= ext[n m]
Conjugate[ext[n_]] ^:= ext[-n]
ext[0] = 1;
MakeBoxes[ext[n_],StandardForm]:=Switch[n,
0, "1",
1, MakeBoxes[EXt],
-1, MakeBoxes[EXtC],
_Integer?Negative, With[s=-n, MakeBoxes[EXtC^s]],
_, MakeBoxes[EXt^n]
]
For example:
EXt = ext[1]
EXtC = ext[-1]
EXt
EXtC
And:
EXt^2 EXtC^2
EXt^2 EXtC^3
EXt EXtC^n //Conjugate
1
EXtC
EXt^(-1 + n)
Here's a variation of @xzczd's idea, using only a single symbol and adding formatting:
Clear[ext]
ext[n_] ext[m_] ^:= ext[n+m]
ext[n_]^m_ ^:= ext[n m]
Conjugate[ext[n_]] ^:= ext[-n]
ext[0] = 1;
MakeBoxes[ext[n_],StandardForm]:=Switch[n,
0, "1",
1, MakeBoxes[EXt],
-1, MakeBoxes[EXtC],
_Integer?Negative, With[s=-n, MakeBoxes[EXtC^s]],
_, MakeBoxes[EXt^n]
]
For example:
EXt = ext[1]
EXtC = ext[-1]
EXt
EXtC
And:
EXt^2 EXtC^2
EXt^2 EXtC^3
EXt EXtC^n //Conjugate
1
EXtC
EXt^(-1 + n)
edited 13 mins ago
answered 19 mins ago
Carl Woll
61.8k280158
61.8k280158
add a comment |Â
add a comment |Â
user43283 is a new contributor. Be nice, and check out our Code of Conduct.
user43283 is a new contributor. Be nice, and check out our Code of Conduct.
user43283 is a new contributor. Be nice, and check out our Code of Conduct.
user43283 is a new contributor. Be nice, and check out our Code of Conduct.
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184467%2fissue-with-upvalues%23new-answer', 'question_page');
);
Post as a guest
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
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
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