Why is expression not evaluated completely?












3












$begingroup$


I have a simple sum of complex numbers. In my example their sum is zero.



sum = Total[{1 , E^(2*I/3*Pi) , E^((4*I)/3*Pi)}]
Print[sum]


Try it online!



When computing this sum, I just get back this "symbolic" expression:



1 + E^((-2*I)/3*Pi) + E^((2*I)/3*Pi)


(I already learned that this can be reduced to a single number using Simplify to get the result I expect.)



But when I replace this list of complex numbers with e.g. a list of integers {1,2,3} it does get evaluated to a single number.



I didn't understand why these two cases behave differently, so can you explain why I get an expression back for the first case and a fully simplified number in the second case?










share|improve this question









$endgroup$












  • $begingroup$
    Is there some reason to expect any result other than the one indicates? Stated differently, what result is expected from 1+ E^((-2*I)/3*Pi)+E^((2*I)/3*Pi)? Or, for that matter, from just adding the last two terms: E^((-2*I)/3*Pi)+E^((2*I)/3*Pi)?
    $endgroup$
    – Daniel Lichtblau
    14 hours ago












  • $begingroup$
    @DanielLichtblau As there exists a much simpler representation I expected Mathematica to find that, just as it finds the most "simple" representation of a fraction or a sum. (I mean it would not return a fraction like 4/10 or a sum like 1+2+3.) Of course such simple sums might be easier to compute, but the original sum that I was referring to was also just an algebraic expression which are computationally not too difficult to simplify.
    $endgroup$
    – flawr
    14 hours ago








  • 2




    $begingroup$
    Arithmetic involves basic evaluation so for example entering 1+2+3 will give 6. But finding "simplest" forms in general is outside the scope of the core evaluator. Functions such as Simplify can be used for this purpose.
    $endgroup$
    – Daniel Lichtblau
    14 hours ago
















3












$begingroup$


I have a simple sum of complex numbers. In my example their sum is zero.



sum = Total[{1 , E^(2*I/3*Pi) , E^((4*I)/3*Pi)}]
Print[sum]


Try it online!



When computing this sum, I just get back this "symbolic" expression:



1 + E^((-2*I)/3*Pi) + E^((2*I)/3*Pi)


(I already learned that this can be reduced to a single number using Simplify to get the result I expect.)



But when I replace this list of complex numbers with e.g. a list of integers {1,2,3} it does get evaluated to a single number.



I didn't understand why these two cases behave differently, so can you explain why I get an expression back for the first case and a fully simplified number in the second case?










share|improve this question









$endgroup$












  • $begingroup$
    Is there some reason to expect any result other than the one indicates? Stated differently, what result is expected from 1+ E^((-2*I)/3*Pi)+E^((2*I)/3*Pi)? Or, for that matter, from just adding the last two terms: E^((-2*I)/3*Pi)+E^((2*I)/3*Pi)?
    $endgroup$
    – Daniel Lichtblau
    14 hours ago












  • $begingroup$
    @DanielLichtblau As there exists a much simpler representation I expected Mathematica to find that, just as it finds the most "simple" representation of a fraction or a sum. (I mean it would not return a fraction like 4/10 or a sum like 1+2+3.) Of course such simple sums might be easier to compute, but the original sum that I was referring to was also just an algebraic expression which are computationally not too difficult to simplify.
    $endgroup$
    – flawr
    14 hours ago








  • 2




    $begingroup$
    Arithmetic involves basic evaluation so for example entering 1+2+3 will give 6. But finding "simplest" forms in general is outside the scope of the core evaluator. Functions such as Simplify can be used for this purpose.
    $endgroup$
    – Daniel Lichtblau
    14 hours ago














3












3








3


1



$begingroup$


I have a simple sum of complex numbers. In my example their sum is zero.



sum = Total[{1 , E^(2*I/3*Pi) , E^((4*I)/3*Pi)}]
Print[sum]


Try it online!



When computing this sum, I just get back this "symbolic" expression:



1 + E^((-2*I)/3*Pi) + E^((2*I)/3*Pi)


(I already learned that this can be reduced to a single number using Simplify to get the result I expect.)



But when I replace this list of complex numbers with e.g. a list of integers {1,2,3} it does get evaluated to a single number.



I didn't understand why these two cases behave differently, so can you explain why I get an expression back for the first case and a fully simplified number in the second case?










share|improve this question









$endgroup$




I have a simple sum of complex numbers. In my example their sum is zero.



sum = Total[{1 , E^(2*I/3*Pi) , E^((4*I)/3*Pi)}]
Print[sum]


Try it online!



When computing this sum, I just get back this "symbolic" expression:



1 + E^((-2*I)/3*Pi) + E^((2*I)/3*Pi)


(I already learned that this can be reduced to a single number using Simplify to get the result I expect.)



But when I replace this list of complex numbers with e.g. a list of integers {1,2,3} it does get evaluated to a single number.



I didn't understand why these two cases behave differently, so can you explain why I get an expression back for the first case and a fully simplified number in the second case?







simplifying-expressions evaluation






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









flawrflawr

1205




1205












  • $begingroup$
    Is there some reason to expect any result other than the one indicates? Stated differently, what result is expected from 1+ E^((-2*I)/3*Pi)+E^((2*I)/3*Pi)? Or, for that matter, from just adding the last two terms: E^((-2*I)/3*Pi)+E^((2*I)/3*Pi)?
    $endgroup$
    – Daniel Lichtblau
    14 hours ago












  • $begingroup$
    @DanielLichtblau As there exists a much simpler representation I expected Mathematica to find that, just as it finds the most "simple" representation of a fraction or a sum. (I mean it would not return a fraction like 4/10 or a sum like 1+2+3.) Of course such simple sums might be easier to compute, but the original sum that I was referring to was also just an algebraic expression which are computationally not too difficult to simplify.
    $endgroup$
    – flawr
    14 hours ago








  • 2




    $begingroup$
    Arithmetic involves basic evaluation so for example entering 1+2+3 will give 6. But finding "simplest" forms in general is outside the scope of the core evaluator. Functions such as Simplify can be used for this purpose.
    $endgroup$
    – Daniel Lichtblau
    14 hours ago


















  • $begingroup$
    Is there some reason to expect any result other than the one indicates? Stated differently, what result is expected from 1+ E^((-2*I)/3*Pi)+E^((2*I)/3*Pi)? Or, for that matter, from just adding the last two terms: E^((-2*I)/3*Pi)+E^((2*I)/3*Pi)?
    $endgroup$
    – Daniel Lichtblau
    14 hours ago












  • $begingroup$
    @DanielLichtblau As there exists a much simpler representation I expected Mathematica to find that, just as it finds the most "simple" representation of a fraction or a sum. (I mean it would not return a fraction like 4/10 or a sum like 1+2+3.) Of course such simple sums might be easier to compute, but the original sum that I was referring to was also just an algebraic expression which are computationally not too difficult to simplify.
    $endgroup$
    – flawr
    14 hours ago








  • 2




    $begingroup$
    Arithmetic involves basic evaluation so for example entering 1+2+3 will give 6. But finding "simplest" forms in general is outside the scope of the core evaluator. Functions such as Simplify can be used for this purpose.
    $endgroup$
    – Daniel Lichtblau
    14 hours ago
















$begingroup$
Is there some reason to expect any result other than the one indicates? Stated differently, what result is expected from 1+ E^((-2*I)/3*Pi)+E^((2*I)/3*Pi)? Or, for that matter, from just adding the last two terms: E^((-2*I)/3*Pi)+E^((2*I)/3*Pi)?
$endgroup$
– Daniel Lichtblau
14 hours ago






$begingroup$
Is there some reason to expect any result other than the one indicates? Stated differently, what result is expected from 1+ E^((-2*I)/3*Pi)+E^((2*I)/3*Pi)? Or, for that matter, from just adding the last two terms: E^((-2*I)/3*Pi)+E^((2*I)/3*Pi)?
$endgroup$
– Daniel Lichtblau
14 hours ago














$begingroup$
@DanielLichtblau As there exists a much simpler representation I expected Mathematica to find that, just as it finds the most "simple" representation of a fraction or a sum. (I mean it would not return a fraction like 4/10 or a sum like 1+2+3.) Of course such simple sums might be easier to compute, but the original sum that I was referring to was also just an algebraic expression which are computationally not too difficult to simplify.
$endgroup$
– flawr
14 hours ago






$begingroup$
@DanielLichtblau As there exists a much simpler representation I expected Mathematica to find that, just as it finds the most "simple" representation of a fraction or a sum. (I mean it would not return a fraction like 4/10 or a sum like 1+2+3.) Of course such simple sums might be easier to compute, but the original sum that I was referring to was also just an algebraic expression which are computationally not too difficult to simplify.
$endgroup$
– flawr
14 hours ago






2




2




$begingroup$
Arithmetic involves basic evaluation so for example entering 1+2+3 will give 6. But finding "simplest" forms in general is outside the scope of the core evaluator. Functions such as Simplify can be used for this purpose.
$endgroup$
– Daniel Lichtblau
14 hours ago




$begingroup$
Arithmetic involves basic evaluation so for example entering 1+2+3 will give 6. But finding "simplest" forms in general is outside the scope of the core evaluator. Functions such as Simplify can be used for this purpose.
$endgroup$
– Daniel Lichtblau
14 hours ago










3 Answers
3






active

oldest

votes


















7












$begingroup$

Exact numeric expressions are treated symbolically, and there are a very limited number of transformations that will be applied automatically. Adding "actual numbers" (see NumberQ) is one such transformation that occurs. But E^((-2*I)/3*Pi) is not converted to a number, unless such a transformation is explicitly requested (as is done by Simplify, ComplexExpand, and so forth). A similar thing happens with the following:



Total@ArcTan@Range@3
(* π/4 + ArcTan[2] + ArcTan[3] *)

FullSimplify[%]
(* π *)





share|improve this answer











$endgroup$





















    4












    $begingroup$

    sum = Total[{1, E^(2*I/3*Pi), E^((4*I)/3*Pi)}]

    (* 1+E^(-((2 I π)/3))+E^((2 I π)/3) *)


    Using machine precision, the sum is not identically zero



    sum // N

    (* 4.44089*10^-16+0. I *)


    In fact, basic symbolic and numerical methods used internally do not show that sum has value zero



    sum // PossibleZeroQ

    (* PossibleZeroQ::ztest1: Unable to decide whether numeric quantity
    1-(-1)^(1/3)+(-1)^(2/3) is equal to zero. Assuming it is.

    True *)


    Consequently, sum does not automatically evaluate to zero. More robust methods are required such as



    #@sum& /@ {Simplify, ComplexExpand, RootReduce}

    (* {0,0,0} *)





    share|improve this answer









    $endgroup$





















      1












      $begingroup$

      Try



      sum = Total[{1, E^(2*I/3*Pi), E^((4*I)/3*Pi)}] // ExpToTrig
      (*0*)





      share|improve this answer









      $endgroup$













        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%2f190740%2fwhy-is-expression-not-evaluated-completely%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        7












        $begingroup$

        Exact numeric expressions are treated symbolically, and there are a very limited number of transformations that will be applied automatically. Adding "actual numbers" (see NumberQ) is one such transformation that occurs. But E^((-2*I)/3*Pi) is not converted to a number, unless such a transformation is explicitly requested (as is done by Simplify, ComplexExpand, and so forth). A similar thing happens with the following:



        Total@ArcTan@Range@3
        (* π/4 + ArcTan[2] + ArcTan[3] *)

        FullSimplify[%]
        (* π *)





        share|improve this answer











        $endgroup$


















          7












          $begingroup$

          Exact numeric expressions are treated symbolically, and there are a very limited number of transformations that will be applied automatically. Adding "actual numbers" (see NumberQ) is one such transformation that occurs. But E^((-2*I)/3*Pi) is not converted to a number, unless such a transformation is explicitly requested (as is done by Simplify, ComplexExpand, and so forth). A similar thing happens with the following:



          Total@ArcTan@Range@3
          (* π/4 + ArcTan[2] + ArcTan[3] *)

          FullSimplify[%]
          (* π *)





          share|improve this answer











          $endgroup$
















            7












            7








            7





            $begingroup$

            Exact numeric expressions are treated symbolically, and there are a very limited number of transformations that will be applied automatically. Adding "actual numbers" (see NumberQ) is one such transformation that occurs. But E^((-2*I)/3*Pi) is not converted to a number, unless such a transformation is explicitly requested (as is done by Simplify, ComplexExpand, and so forth). A similar thing happens with the following:



            Total@ArcTan@Range@3
            (* π/4 + ArcTan[2] + ArcTan[3] *)

            FullSimplify[%]
            (* π *)





            share|improve this answer











            $endgroup$



            Exact numeric expressions are treated symbolically, and there are a very limited number of transformations that will be applied automatically. Adding "actual numbers" (see NumberQ) is one such transformation that occurs. But E^((-2*I)/3*Pi) is not converted to a number, unless such a transformation is explicitly requested (as is done by Simplify, ComplexExpand, and so forth). A similar thing happens with the following:



            Total@ArcTan@Range@3
            (* π/4 + ArcTan[2] + ArcTan[3] *)

            FullSimplify[%]
            (* π *)






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited yesterday

























            answered yesterday









            Michael E2Michael E2

            147k12197470




            147k12197470























                4












                $begingroup$

                sum = Total[{1, E^(2*I/3*Pi), E^((4*I)/3*Pi)}]

                (* 1+E^(-((2 I π)/3))+E^((2 I π)/3) *)


                Using machine precision, the sum is not identically zero



                sum // N

                (* 4.44089*10^-16+0. I *)


                In fact, basic symbolic and numerical methods used internally do not show that sum has value zero



                sum // PossibleZeroQ

                (* PossibleZeroQ::ztest1: Unable to decide whether numeric quantity
                1-(-1)^(1/3)+(-1)^(2/3) is equal to zero. Assuming it is.

                True *)


                Consequently, sum does not automatically evaluate to zero. More robust methods are required such as



                #@sum& /@ {Simplify, ComplexExpand, RootReduce}

                (* {0,0,0} *)





                share|improve this answer









                $endgroup$


















                  4












                  $begingroup$

                  sum = Total[{1, E^(2*I/3*Pi), E^((4*I)/3*Pi)}]

                  (* 1+E^(-((2 I π)/3))+E^((2 I π)/3) *)


                  Using machine precision, the sum is not identically zero



                  sum // N

                  (* 4.44089*10^-16+0. I *)


                  In fact, basic symbolic and numerical methods used internally do not show that sum has value zero



                  sum // PossibleZeroQ

                  (* PossibleZeroQ::ztest1: Unable to decide whether numeric quantity
                  1-(-1)^(1/3)+(-1)^(2/3) is equal to zero. Assuming it is.

                  True *)


                  Consequently, sum does not automatically evaluate to zero. More robust methods are required such as



                  #@sum& /@ {Simplify, ComplexExpand, RootReduce}

                  (* {0,0,0} *)





                  share|improve this answer









                  $endgroup$
















                    4












                    4








                    4





                    $begingroup$

                    sum = Total[{1, E^(2*I/3*Pi), E^((4*I)/3*Pi)}]

                    (* 1+E^(-((2 I π)/3))+E^((2 I π)/3) *)


                    Using machine precision, the sum is not identically zero



                    sum // N

                    (* 4.44089*10^-16+0. I *)


                    In fact, basic symbolic and numerical methods used internally do not show that sum has value zero



                    sum // PossibleZeroQ

                    (* PossibleZeroQ::ztest1: Unable to decide whether numeric quantity
                    1-(-1)^(1/3)+(-1)^(2/3) is equal to zero. Assuming it is.

                    True *)


                    Consequently, sum does not automatically evaluate to zero. More robust methods are required such as



                    #@sum& /@ {Simplify, ComplexExpand, RootReduce}

                    (* {0,0,0} *)





                    share|improve this answer









                    $endgroup$



                    sum = Total[{1, E^(2*I/3*Pi), E^((4*I)/3*Pi)}]

                    (* 1+E^(-((2 I π)/3))+E^((2 I π)/3) *)


                    Using machine precision, the sum is not identically zero



                    sum // N

                    (* 4.44089*10^-16+0. I *)


                    In fact, basic symbolic and numerical methods used internally do not show that sum has value zero



                    sum // PossibleZeroQ

                    (* PossibleZeroQ::ztest1: Unable to decide whether numeric quantity
                    1-(-1)^(1/3)+(-1)^(2/3) is equal to zero. Assuming it is.

                    True *)


                    Consequently, sum does not automatically evaluate to zero. More robust methods are required such as



                    #@sum& /@ {Simplify, ComplexExpand, RootReduce}

                    (* {0,0,0} *)






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered yesterday









                    Bob HanlonBob Hanlon

                    59.8k33596




                    59.8k33596























                        1












                        $begingroup$

                        Try



                        sum = Total[{1, E^(2*I/3*Pi), E^((4*I)/3*Pi)}] // ExpToTrig
                        (*0*)





                        share|improve this answer









                        $endgroup$


















                          1












                          $begingroup$

                          Try



                          sum = Total[{1, E^(2*I/3*Pi), E^((4*I)/3*Pi)}] // ExpToTrig
                          (*0*)





                          share|improve this answer









                          $endgroup$
















                            1












                            1








                            1





                            $begingroup$

                            Try



                            sum = Total[{1, E^(2*I/3*Pi), E^((4*I)/3*Pi)}] // ExpToTrig
                            (*0*)





                            share|improve this answer









                            $endgroup$



                            Try



                            sum = Total[{1, E^(2*I/3*Pi), E^((4*I)/3*Pi)}] // ExpToTrig
                            (*0*)






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 13 hours ago









                            Ulrich NeumannUlrich Neumann

                            8,487516




                            8,487516






























                                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%2f190740%2fwhy-is-expression-not-evaluated-completely%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

                                If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                                Alcedinidae

                                Can an atomic nucleus contain both particles and antiparticles? [duplicate]