Issue with Upvalues

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite
1












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?










share|improve this question







New contributor




user43283 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    4
    down vote

    favorite
    1












    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?










    share|improve this question







    New contributor




    user43283 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      4
      down vote

      favorite
      1









      up vote
      4
      down vote

      favorite
      1






      1





      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?










      share|improve this question







      New contributor




      user43283 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      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






      share|improve this question







      New contributor




      user43283 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      user43283 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      user43283 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 hours ago









      user43283

      1211




      1211




      New contributor




      user43283 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      user43283 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      user43283 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          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:



          1. EXt^n and EXtC^n are expressed as ext[n] and extc[n].


          2. Single EXt and EXtC must be expressed as ext[1] and extc[1].


          Example:



          ext@2 extc@3
          (* extc[1] *)

          ext@1 extc@n // Conjugate
          (* ext[-1 + n] *)





          share|improve this answer



























            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)







            share|improve this answer






















              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',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );






              user43283 is a new contributor. Be nice, and check out our Code of Conduct.









               

              draft saved


              draft discarded


















              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






























              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:



              1. EXt^n and EXtC^n are expressed as ext[n] and extc[n].


              2. Single EXt and EXtC must be expressed as ext[1] and extc[1].


              Example:



              ext@2 extc@3
              (* extc[1] *)

              ext@1 extc@n // Conjugate
              (* ext[-1 + n] *)





              share|improve this answer
























                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:



                1. EXt^n and EXtC^n are expressed as ext[n] and extc[n].


                2. Single EXt and EXtC must be expressed as ext[1] and extc[1].


                Example:



                ext@2 extc@3
                (* extc[1] *)

                ext@1 extc@n // Conjugate
                (* ext[-1 + n] *)





                share|improve this answer






















                  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:



                  1. EXt^n and EXtC^n are expressed as ext[n] and extc[n].


                  2. Single EXt and EXtC must be expressed as ext[1] and extc[1].


                  Example:



                  ext@2 extc@3
                  (* extc[1] *)

                  ext@1 extc@n // Conjugate
                  (* ext[-1 + n] *)





                  share|improve this answer












                  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:



                  1. EXt^n and EXtC^n are expressed as ext[n] and extc[n].


                  2. Single EXt and EXtC must be expressed as ext[1] and extc[1].


                  Example:



                  ext@2 extc@3
                  (* extc[1] *)

                  ext@1 extc@n // Conjugate
                  (* ext[-1 + n] *)






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 1 hour ago









                  xzczd

                  25k467236




                  25k467236




















                      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)







                      share|improve this answer


























                        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)







                        share|improve this answer
























                          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)







                          share|improve this answer














                          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)








                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited 13 mins ago

























                          answered 19 mins ago









                          Carl Woll

                          61.8k280158




                          61.8k280158




















                              user43283 is a new contributor. Be nice, and check out our Code of Conduct.









                               

                              draft saved


                              draft discarded


















                              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.













                               


                              draft saved


                              draft discarded














                              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













































































                              Comments

                              Popular posts from this blog

                              Long meetings (6-7 hours a day): Being “babysat” by supervisor

                              Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                              Confectionery