Error Message when nothing should be evaluatedWhy is the first argument of the SetDelayed evaluated?MapThread...

A file manager to open a zip file like opening a folder, instead of extract it by using a archive manager

Is differentiation as a map discontinuous?

What are the consequences of high orphan block rate?

What secular civic space would pioneers build for small frontier towns?

Is it a good idea to leave minor world details to the reader's imagination?

Pi Zero Work With Embedded WIFI And Cellular USB Modem

Clear text passwords in Unix

How can an attacker use robots.txt?

Fuel sender works when outside of tank, but not when in tank

Why did UK NHS pay for homeopathic treatments?

Error Message when nothing should be evaluated

Aesthetic proofs that involve Field Theory / Galois Theory

OSM Thunderforest API keys in QGIS3

Is there something that can completely prevent the effects of the Hold Person spell?

Is it impolite to ask for halal food when traveling to and in Thailand?

I am 15 years old and do not go to a Yeshiva but would like to learn Talmud. A few rabbis near me said they could teach me. How should I start

Why are there two fundamental laws of logic?

Reorder a matrix, twice

Is the use of language other than English 'Reasonable Suspicion' for detention?

Why does my browser attempt to download pages from http://clhs.lisp.se instead of viewing them normally?

What would influence an alien race to map their planet in a way other than the traditional map of the Earth

Co-supervisor comes to the office to help her students, which distracts me

How 象【しょう】 ( ≈かたち、 すがた、ようす) and 象【ぞう】 (どうぶつ) got to be written with the same kanji?

Why does C++ have 'Undefined Behaviour' and other languages like C# or Java don't?



Error Message when nothing should be evaluated


Why is the first argument of the SetDelayed evaluated?MapThread gives different results from ToExpression when trying to assign variables from a listHow to ignore list elements when extracting with pattern matchingWhy is the first argument of the SetDelayed evaluated?How can I get the minimum error term when manipulating Taylor series?Error in Assignment






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







5












$begingroup$


When I try to define this simple function



getCoeff[SeriesData[_, _, coeff_, _, _, _]] := coeff[[2]]


I get an error:



SeriesData: Coefficient specification coeff_ in SeriesData[_,_,coeff_,_,_,_] is not a list.


Can someone explain what's wrong with this? My understanding was that SetDelayed shouldn't complain about such things because until I actually evaluate an expression containing getCoeff it shouldn't try to evaluate Part[coeff,2].



There is no error thrown for the similar function



f[g[_, _, x_, _, _, _]] := x[[2]]


and furthermore getCoeff works as expected:



getCoeff@Series[E^([Pi] x), {x, 0, 3}]


outputs $pi$.



I know the "right" way to manipulate SeriesData, I'd just like to understand this case for its own sake.










share|improve this question









$endgroup$










  • 1




    $begingroup$
    Use unevaluated: getCoeff[Unevaluated[SeriesData[_, _, coeff_, _, _, _]]] := coeff[[2]]; Then getCoeff@Series[E^([Pi] x), {x, 0, 3}] = [Pi].
    $endgroup$
    – Shredderroy
    8 hours ago


















5












$begingroup$


When I try to define this simple function



getCoeff[SeriesData[_, _, coeff_, _, _, _]] := coeff[[2]]


I get an error:



SeriesData: Coefficient specification coeff_ in SeriesData[_,_,coeff_,_,_,_] is not a list.


Can someone explain what's wrong with this? My understanding was that SetDelayed shouldn't complain about such things because until I actually evaluate an expression containing getCoeff it shouldn't try to evaluate Part[coeff,2].



There is no error thrown for the similar function



f[g[_, _, x_, _, _, _]] := x[[2]]


and furthermore getCoeff works as expected:



getCoeff@Series[E^([Pi] x), {x, 0, 3}]


outputs $pi$.



I know the "right" way to manipulate SeriesData, I'd just like to understand this case for its own sake.










share|improve this question









$endgroup$










  • 1




    $begingroup$
    Use unevaluated: getCoeff[Unevaluated[SeriesData[_, _, coeff_, _, _, _]]] := coeff[[2]]; Then getCoeff@Series[E^([Pi] x), {x, 0, 3}] = [Pi].
    $endgroup$
    – Shredderroy
    8 hours ago














5












5








5


1



$begingroup$


When I try to define this simple function



getCoeff[SeriesData[_, _, coeff_, _, _, _]] := coeff[[2]]


I get an error:



SeriesData: Coefficient specification coeff_ in SeriesData[_,_,coeff_,_,_,_] is not a list.


Can someone explain what's wrong with this? My understanding was that SetDelayed shouldn't complain about such things because until I actually evaluate an expression containing getCoeff it shouldn't try to evaluate Part[coeff,2].



There is no error thrown for the similar function



f[g[_, _, x_, _, _, _]] := x[[2]]


and furthermore getCoeff works as expected:



getCoeff@Series[E^([Pi] x), {x, 0, 3}]


outputs $pi$.



I know the "right" way to manipulate SeriesData, I'd just like to understand this case for its own sake.










share|improve this question









$endgroup$




When I try to define this simple function



getCoeff[SeriesData[_, _, coeff_, _, _, _]] := coeff[[2]]


I get an error:



SeriesData: Coefficient specification coeff_ in SeriesData[_,_,coeff_,_,_,_] is not a list.


Can someone explain what's wrong with this? My understanding was that SetDelayed shouldn't complain about such things because until I actually evaluate an expression containing getCoeff it shouldn't try to evaluate Part[coeff,2].



There is no error thrown for the similar function



f[g[_, _, x_, _, _, _]] := x[[2]]


and furthermore getCoeff works as expected:



getCoeff@Series[E^([Pi] x), {x, 0, 3}]


outputs $pi$.



I know the "right" way to manipulate SeriesData, I'd just like to understand this case for its own sake.







series-expansion assignment






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 8 hours ago









DiffycueDiffycue

2811 silver badge6 bronze badges




2811 silver badge6 bronze badges











  • 1




    $begingroup$
    Use unevaluated: getCoeff[Unevaluated[SeriesData[_, _, coeff_, _, _, _]]] := coeff[[2]]; Then getCoeff@Series[E^([Pi] x), {x, 0, 3}] = [Pi].
    $endgroup$
    – Shredderroy
    8 hours ago














  • 1




    $begingroup$
    Use unevaluated: getCoeff[Unevaluated[SeriesData[_, _, coeff_, _, _, _]]] := coeff[[2]]; Then getCoeff@Series[E^([Pi] x), {x, 0, 3}] = [Pi].
    $endgroup$
    – Shredderroy
    8 hours ago








1




1




$begingroup$
Use unevaluated: getCoeff[Unevaluated[SeriesData[_, _, coeff_, _, _, _]]] := coeff[[2]]; Then getCoeff@Series[E^([Pi] x), {x, 0, 3}] = [Pi].
$endgroup$
– Shredderroy
8 hours ago




$begingroup$
Use unevaluated: getCoeff[Unevaluated[SeriesData[_, _, coeff_, _, _, _]]] := coeff[[2]]; Then getCoeff@Series[E^([Pi] x), {x, 0, 3}] = [Pi].
$endgroup$
– Shredderroy
8 hours ago










1 Answer
1






active

oldest

votes


















5














$begingroup$

This is due to the special behavior of SetDelayed (:=) with regards to the first argument (see e.g. this question): The arguments of the l.h.s. are evaluated by SetDelayed, which causes the error you are seeing - after all, SeriesData[_, _, coeff_, _, _, _] is not a valid SeriesData construct. This is what HoldPattern is designed for: It prevents evaluation of its argument (like Hold), but is invisible to the pattern matcher. The solution is therefore simply:



(* prevent the l.h.s. from being evaluated *)
HoldPattern@getCoeff[SeriesData[_, _, coeff_, _, _, _]] := coeff[[2]]

getCoeff@Series[E^(π x), {x, 0, 3}]
(* π *)

(* prevent only evaluation of the first argument (equivalent in this case) *)
getCoeff[HoldPattern@SeriesData[_, _, coeff_, _, _, _]] := coeff[[2]]

getCoeff@Series[E^(π x), {x, 0, 3}]
(* π *)





share|improve this answer









$endgroup$


















    Your Answer








    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/4.0/"u003ecc by-sa 4.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%2f206614%2ferror-message-when-nothing-should-be-evaluated%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









    5














    $begingroup$

    This is due to the special behavior of SetDelayed (:=) with regards to the first argument (see e.g. this question): The arguments of the l.h.s. are evaluated by SetDelayed, which causes the error you are seeing - after all, SeriesData[_, _, coeff_, _, _, _] is not a valid SeriesData construct. This is what HoldPattern is designed for: It prevents evaluation of its argument (like Hold), but is invisible to the pattern matcher. The solution is therefore simply:



    (* prevent the l.h.s. from being evaluated *)
    HoldPattern@getCoeff[SeriesData[_, _, coeff_, _, _, _]] := coeff[[2]]

    getCoeff@Series[E^(π x), {x, 0, 3}]
    (* π *)

    (* prevent only evaluation of the first argument (equivalent in this case) *)
    getCoeff[HoldPattern@SeriesData[_, _, coeff_, _, _, _]] := coeff[[2]]

    getCoeff@Series[E^(π x), {x, 0, 3}]
    (* π *)





    share|improve this answer









    $endgroup$




















      5














      $begingroup$

      This is due to the special behavior of SetDelayed (:=) with regards to the first argument (see e.g. this question): The arguments of the l.h.s. are evaluated by SetDelayed, which causes the error you are seeing - after all, SeriesData[_, _, coeff_, _, _, _] is not a valid SeriesData construct. This is what HoldPattern is designed for: It prevents evaluation of its argument (like Hold), but is invisible to the pattern matcher. The solution is therefore simply:



      (* prevent the l.h.s. from being evaluated *)
      HoldPattern@getCoeff[SeriesData[_, _, coeff_, _, _, _]] := coeff[[2]]

      getCoeff@Series[E^(π x), {x, 0, 3}]
      (* π *)

      (* prevent only evaluation of the first argument (equivalent in this case) *)
      getCoeff[HoldPattern@SeriesData[_, _, coeff_, _, _, _]] := coeff[[2]]

      getCoeff@Series[E^(π x), {x, 0, 3}]
      (* π *)





      share|improve this answer









      $endgroup$


















        5














        5










        5







        $begingroup$

        This is due to the special behavior of SetDelayed (:=) with regards to the first argument (see e.g. this question): The arguments of the l.h.s. are evaluated by SetDelayed, which causes the error you are seeing - after all, SeriesData[_, _, coeff_, _, _, _] is not a valid SeriesData construct. This is what HoldPattern is designed for: It prevents evaluation of its argument (like Hold), but is invisible to the pattern matcher. The solution is therefore simply:



        (* prevent the l.h.s. from being evaluated *)
        HoldPattern@getCoeff[SeriesData[_, _, coeff_, _, _, _]] := coeff[[2]]

        getCoeff@Series[E^(π x), {x, 0, 3}]
        (* π *)

        (* prevent only evaluation of the first argument (equivalent in this case) *)
        getCoeff[HoldPattern@SeriesData[_, _, coeff_, _, _, _]] := coeff[[2]]

        getCoeff@Series[E^(π x), {x, 0, 3}]
        (* π *)





        share|improve this answer









        $endgroup$



        This is due to the special behavior of SetDelayed (:=) with regards to the first argument (see e.g. this question): The arguments of the l.h.s. are evaluated by SetDelayed, which causes the error you are seeing - after all, SeriesData[_, _, coeff_, _, _, _] is not a valid SeriesData construct. This is what HoldPattern is designed for: It prevents evaluation of its argument (like Hold), but is invisible to the pattern matcher. The solution is therefore simply:



        (* prevent the l.h.s. from being evaluated *)
        HoldPattern@getCoeff[SeriesData[_, _, coeff_, _, _, _]] := coeff[[2]]

        getCoeff@Series[E^(π x), {x, 0, 3}]
        (* π *)

        (* prevent only evaluation of the first argument (equivalent in this case) *)
        getCoeff[HoldPattern@SeriesData[_, _, coeff_, _, _, _]] := coeff[[2]]

        getCoeff@Series[E^(π x), {x, 0, 3}]
        (* π *)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 7 hours ago









        Lukas LangLukas Lang

        9,8291 gold badge13 silver badges36 bronze badges




        9,8291 gold badge13 silver badges36 bronze badges


































            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%2f206614%2ferror-message-when-nothing-should-be-evaluated%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

            Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

            Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

            Ciclooctatetraenă Vezi și | Bibliografie | Meniu de navigare637866text4148569-500570979m