Strange behaviour of Check












8












$begingroup$


Reap @ 
Quiet @
Do[
(On[Inverse::sing]; Sow @ Check[Inverse[({{1, 2},{1, 2}})]; 2 + 2, 3 + 3]),
{i, 10}];
(* {Null, {{6, 4, 4, 4, 4, 4, 4, 4, 4, 4}}} *)


The above code evaluates correctly in the first iteration to 6 since the matrix is singular. On successive iterations thereafter it yields 4.



Reap @ 
Quiet @
Do[Sow@Check[Assert[Inverse[({{1, 2},{1, 2}})]]; 2 + 2, 3 + 3], {i, 10}]
(* {Null, {{6, 6, 6, 6, 6, 6, 6, 6, 6, 6}}} *)


The problem can be avoided by using Assert. My question is why Check is ignoring the singularity of the matrix even though I am forcing the message to be on. Is it a bug? If it is, then it is a serious one.










share|improve this question











$endgroup$












  • $begingroup$
    In version 10.1 I get {Null, {{6, 4, 4, 4, 4, 4, 4, 4, 4, 4}}} every time.
    $endgroup$
    – Mr.Wizard
    yesterday
















8












$begingroup$


Reap @ 
Quiet @
Do[
(On[Inverse::sing]; Sow @ Check[Inverse[({{1, 2},{1, 2}})]; 2 + 2, 3 + 3]),
{i, 10}];
(* {Null, {{6, 4, 4, 4, 4, 4, 4, 4, 4, 4}}} *)


The above code evaluates correctly in the first iteration to 6 since the matrix is singular. On successive iterations thereafter it yields 4.



Reap @ 
Quiet @
Do[Sow@Check[Assert[Inverse[({{1, 2},{1, 2}})]]; 2 + 2, 3 + 3], {i, 10}]
(* {Null, {{6, 6, 6, 6, 6, 6, 6, 6, 6, 6}}} *)


The problem can be avoided by using Assert. My question is why Check is ignoring the singularity of the matrix even though I am forcing the message to be on. Is it a bug? If it is, then it is a serious one.










share|improve this question











$endgroup$












  • $begingroup$
    In version 10.1 I get {Null, {{6, 4, 4, 4, 4, 4, 4, 4, 4, 4}}} every time.
    $endgroup$
    – Mr.Wizard
    yesterday














8












8








8


2



$begingroup$


Reap @ 
Quiet @
Do[
(On[Inverse::sing]; Sow @ Check[Inverse[({{1, 2},{1, 2}})]; 2 + 2, 3 + 3]),
{i, 10}];
(* {Null, {{6, 4, 4, 4, 4, 4, 4, 4, 4, 4}}} *)


The above code evaluates correctly in the first iteration to 6 since the matrix is singular. On successive iterations thereafter it yields 4.



Reap @ 
Quiet @
Do[Sow@Check[Assert[Inverse[({{1, 2},{1, 2}})]]; 2 + 2, 3 + 3], {i, 10}]
(* {Null, {{6, 6, 6, 6, 6, 6, 6, 6, 6, 6}}} *)


The problem can be avoided by using Assert. My question is why Check is ignoring the singularity of the matrix even though I am forcing the message to be on. Is it a bug? If it is, then it is a serious one.










share|improve this question











$endgroup$




Reap @ 
Quiet @
Do[
(On[Inverse::sing]; Sow @ Check[Inverse[({{1, 2},{1, 2}})]; 2 + 2, 3 + 3]),
{i, 10}];
(* {Null, {{6, 4, 4, 4, 4, 4, 4, 4, 4, 4}}} *)


The above code evaluates correctly in the first iteration to 6 since the matrix is singular. On successive iterations thereafter it yields 4.



Reap @ 
Quiet @
Do[Sow@Check[Assert[Inverse[({{1, 2},{1, 2}})]]; 2 + 2, 3 + 3], {i, 10}]
(* {Null, {{6, 6, 6, 6, 6, 6, 6, 6, 6, 6}}} *)


The problem can be avoided by using Assert. My question is why Check is ignoring the singularity of the matrix even though I am forcing the message to be on. Is it a bug? If it is, then it is a serious one.







functions function-construction error-trapping






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









m_goldberg

88.7k873200




88.7k873200










asked yesterday









Ali HashmiAli Hashmi

5,77931433




5,77931433












  • $begingroup$
    In version 10.1 I get {Null, {{6, 4, 4, 4, 4, 4, 4, 4, 4, 4}}} every time.
    $endgroup$
    – Mr.Wizard
    yesterday


















  • $begingroup$
    In version 10.1 I get {Null, {{6, 4, 4, 4, 4, 4, 4, 4, 4, 4}}} every time.
    $endgroup$
    – Mr.Wizard
    yesterday
















$begingroup$
In version 10.1 I get {Null, {{6, 4, 4, 4, 4, 4, 4, 4, 4, 4}}} every time.
$endgroup$
– Mr.Wizard
yesterday




$begingroup$
In version 10.1 I get {Null, {{6, 4, 4, 4, 4, 4, 4, 4, 4, 4}}} every time.
$endgroup$
– Mr.Wizard
yesterday










2 Answers
2






active

oldest

votes


















10












$begingroup$

The behaviour we see is due to an optimization that is being applied by the evaluator. Once the evaluator sees that an expression is inert, it assumes that for the remainder of the evaluation the same expression need not be evaluated again. In the case at hand, Inverse[{{1, 2}, {1, 2}}] is inert since the definitions of Inverse have determined that the matrix is singular and have declined to transform the expression.



We can use Update to force the evaluator to avoid the optimization:



Do[Print@Check[Inverse[({{1,2},{1,2}})]; "wrong", "right"], {i,2}];
(*
Inverse::sing: Matrix {{1,2},{1,2}} is singular.
right
wrong
*)

Do[Print@Check[Update; Inverse[({{1,2},{1,2}})]; "wrong", "right"], {i,2}];
(*
Inverse::sing: Matrix {{1,2},{1,2}} is singular.
right
Inverse::sing: Matrix {{1,2},{1,2}} is singular.
right
*)


Analysis (current as of version 11.3.0)



An expression is called "inert" when there are no applicable definitions which transform it. The key word here is applicable. Definitions can exist, but as long as they are not applicable the expression is treated as inert. In this case of a singular matrix, there does exist at least one definition of Inverse that is evaluated -- but that definition has a condition that detects the singularity, issues an error message, and then indicates that the definition is not applicable. The optimization is insensitive to whether or not the definition condition has any side-effects (in this case, the issuance of a message).



We can emulate this behaviour of Inverse ourselves with a simpler example:



f[x_] := 10 x /; If[x >= 0, True, Message[f::ltzero]; False]

f::ltzero = "less than zero!";


We have defined a function which takes a value and multiplies it by ten, but only under the condition that the value is not less than zero. Otherwise, the condition issues an error message and returns False indicating that the definition does not apply. So:



f[1]
(* 10 *)

f[-1]
(*
>>f::ltzero: less than zero!
f[-1]
*)


With this in place, we can see the action of the optimization:



Table[f[-1], {2}]
(*
>>f::ltzero: less than zero!
{f[-1], f[-1]}
*)


Note how the message is issued only once even though we tried to evaluate f[-1] twice.



We can use Update tell the evaluator to make no optimizing assumptions about inert expressions:



Table[Update; f[-1], {2}]
Table[f[-1], {2}]
(*
>>f::ltzero: less than zero!
>>f::ltzero: less than zero!
{f[-1], f[-1]}
*)


Now, the expression is evaluated twice and the condition message appears twice.



What About Assert?



The question observes that wrapping Assert around the call to Inverse causes it to behave "correctly". Actually, the call to Assert is failing because the argument is expected to be True or False -- not Inverse[...]. Assert issues a message in that case and it is that message that causes Check to return its second argument. All of this can be seen if we remove Quiet from the expression:



Reap @ Do[Sow@Check[Assert[Inverse[({{1,2},{1,2}})]];2+2,3+3],{i,2}]
(*
>>Inverse::sing: Matrix {{1,2},{1,2}} is singular.
>>Assert::asrttf: Assertion test Inverse[{{1,2},{1,2}}] evaluated to Inverse[{{1,2},{1,2}}] that is neither True nor False.
>>Assert::asrttf: Assertion test Inverse[{{1,2},{1,2}}] evaluated to Inverse[{{1,2},{1,2}}] that is neither True nor False.
{Null,{{6,6}}}
*)


Notice how the Inverse::sing message was still only issued once whereas the Assert-related messages were shown multiple times.






share|improve this answer











$endgroup$





















    4












    $begingroup$

    The hard-coded singular matrix only causes Inverse to generate a message (triggering Check) in the first iteration of table (or Do). This doesn't happen with all message generating expressions, e.g. Check[0/0, 3 + 3] generates a message every iteration.



    On[Inverse::sing]

    f := Quiet[Check[Inverse[{{1, 2}, {1, 2}}], 3 + 3]]

    Table[f, 2]



    {6, Inverse[{{1, 2}, {1, 2}}]}




    With the matrix as a variable a singular matrix message is generated with every evaluation.



    m = {{1, 2}, {1, 2}};

    f := Quiet[Check[Inverse[m], 3 + 3]]

    Table[f, 2]



    {6, 6}







    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/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%2f195181%2fstrange-behaviour-of-check%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      10












      $begingroup$

      The behaviour we see is due to an optimization that is being applied by the evaluator. Once the evaluator sees that an expression is inert, it assumes that for the remainder of the evaluation the same expression need not be evaluated again. In the case at hand, Inverse[{{1, 2}, {1, 2}}] is inert since the definitions of Inverse have determined that the matrix is singular and have declined to transform the expression.



      We can use Update to force the evaluator to avoid the optimization:



      Do[Print@Check[Inverse[({{1,2},{1,2}})]; "wrong", "right"], {i,2}];
      (*
      Inverse::sing: Matrix {{1,2},{1,2}} is singular.
      right
      wrong
      *)

      Do[Print@Check[Update; Inverse[({{1,2},{1,2}})]; "wrong", "right"], {i,2}];
      (*
      Inverse::sing: Matrix {{1,2},{1,2}} is singular.
      right
      Inverse::sing: Matrix {{1,2},{1,2}} is singular.
      right
      *)


      Analysis (current as of version 11.3.0)



      An expression is called "inert" when there are no applicable definitions which transform it. The key word here is applicable. Definitions can exist, but as long as they are not applicable the expression is treated as inert. In this case of a singular matrix, there does exist at least one definition of Inverse that is evaluated -- but that definition has a condition that detects the singularity, issues an error message, and then indicates that the definition is not applicable. The optimization is insensitive to whether or not the definition condition has any side-effects (in this case, the issuance of a message).



      We can emulate this behaviour of Inverse ourselves with a simpler example:



      f[x_] := 10 x /; If[x >= 0, True, Message[f::ltzero]; False]

      f::ltzero = "less than zero!";


      We have defined a function which takes a value and multiplies it by ten, but only under the condition that the value is not less than zero. Otherwise, the condition issues an error message and returns False indicating that the definition does not apply. So:



      f[1]
      (* 10 *)

      f[-1]
      (*
      >>f::ltzero: less than zero!
      f[-1]
      *)


      With this in place, we can see the action of the optimization:



      Table[f[-1], {2}]
      (*
      >>f::ltzero: less than zero!
      {f[-1], f[-1]}
      *)


      Note how the message is issued only once even though we tried to evaluate f[-1] twice.



      We can use Update tell the evaluator to make no optimizing assumptions about inert expressions:



      Table[Update; f[-1], {2}]
      Table[f[-1], {2}]
      (*
      >>f::ltzero: less than zero!
      >>f::ltzero: less than zero!
      {f[-1], f[-1]}
      *)


      Now, the expression is evaluated twice and the condition message appears twice.



      What About Assert?



      The question observes that wrapping Assert around the call to Inverse causes it to behave "correctly". Actually, the call to Assert is failing because the argument is expected to be True or False -- not Inverse[...]. Assert issues a message in that case and it is that message that causes Check to return its second argument. All of this can be seen if we remove Quiet from the expression:



      Reap @ Do[Sow@Check[Assert[Inverse[({{1,2},{1,2}})]];2+2,3+3],{i,2}]
      (*
      >>Inverse::sing: Matrix {{1,2},{1,2}} is singular.
      >>Assert::asrttf: Assertion test Inverse[{{1,2},{1,2}}] evaluated to Inverse[{{1,2},{1,2}}] that is neither True nor False.
      >>Assert::asrttf: Assertion test Inverse[{{1,2},{1,2}}] evaluated to Inverse[{{1,2},{1,2}}] that is neither True nor False.
      {Null,{{6,6}}}
      *)


      Notice how the Inverse::sing message was still only issued once whereas the Assert-related messages were shown multiple times.






      share|improve this answer











      $endgroup$


















        10












        $begingroup$

        The behaviour we see is due to an optimization that is being applied by the evaluator. Once the evaluator sees that an expression is inert, it assumes that for the remainder of the evaluation the same expression need not be evaluated again. In the case at hand, Inverse[{{1, 2}, {1, 2}}] is inert since the definitions of Inverse have determined that the matrix is singular and have declined to transform the expression.



        We can use Update to force the evaluator to avoid the optimization:



        Do[Print@Check[Inverse[({{1,2},{1,2}})]; "wrong", "right"], {i,2}];
        (*
        Inverse::sing: Matrix {{1,2},{1,2}} is singular.
        right
        wrong
        *)

        Do[Print@Check[Update; Inverse[({{1,2},{1,2}})]; "wrong", "right"], {i,2}];
        (*
        Inverse::sing: Matrix {{1,2},{1,2}} is singular.
        right
        Inverse::sing: Matrix {{1,2},{1,2}} is singular.
        right
        *)


        Analysis (current as of version 11.3.0)



        An expression is called "inert" when there are no applicable definitions which transform it. The key word here is applicable. Definitions can exist, but as long as they are not applicable the expression is treated as inert. In this case of a singular matrix, there does exist at least one definition of Inverse that is evaluated -- but that definition has a condition that detects the singularity, issues an error message, and then indicates that the definition is not applicable. The optimization is insensitive to whether or not the definition condition has any side-effects (in this case, the issuance of a message).



        We can emulate this behaviour of Inverse ourselves with a simpler example:



        f[x_] := 10 x /; If[x >= 0, True, Message[f::ltzero]; False]

        f::ltzero = "less than zero!";


        We have defined a function which takes a value and multiplies it by ten, but only under the condition that the value is not less than zero. Otherwise, the condition issues an error message and returns False indicating that the definition does not apply. So:



        f[1]
        (* 10 *)

        f[-1]
        (*
        >>f::ltzero: less than zero!
        f[-1]
        *)


        With this in place, we can see the action of the optimization:



        Table[f[-1], {2}]
        (*
        >>f::ltzero: less than zero!
        {f[-1], f[-1]}
        *)


        Note how the message is issued only once even though we tried to evaluate f[-1] twice.



        We can use Update tell the evaluator to make no optimizing assumptions about inert expressions:



        Table[Update; f[-1], {2}]
        Table[f[-1], {2}]
        (*
        >>f::ltzero: less than zero!
        >>f::ltzero: less than zero!
        {f[-1], f[-1]}
        *)


        Now, the expression is evaluated twice and the condition message appears twice.



        What About Assert?



        The question observes that wrapping Assert around the call to Inverse causes it to behave "correctly". Actually, the call to Assert is failing because the argument is expected to be True or False -- not Inverse[...]. Assert issues a message in that case and it is that message that causes Check to return its second argument. All of this can be seen if we remove Quiet from the expression:



        Reap @ Do[Sow@Check[Assert[Inverse[({{1,2},{1,2}})]];2+2,3+3],{i,2}]
        (*
        >>Inverse::sing: Matrix {{1,2},{1,2}} is singular.
        >>Assert::asrttf: Assertion test Inverse[{{1,2},{1,2}}] evaluated to Inverse[{{1,2},{1,2}}] that is neither True nor False.
        >>Assert::asrttf: Assertion test Inverse[{{1,2},{1,2}}] evaluated to Inverse[{{1,2},{1,2}}] that is neither True nor False.
        {Null,{{6,6}}}
        *)


        Notice how the Inverse::sing message was still only issued once whereas the Assert-related messages were shown multiple times.






        share|improve this answer











        $endgroup$
















          10












          10








          10





          $begingroup$

          The behaviour we see is due to an optimization that is being applied by the evaluator. Once the evaluator sees that an expression is inert, it assumes that for the remainder of the evaluation the same expression need not be evaluated again. In the case at hand, Inverse[{{1, 2}, {1, 2}}] is inert since the definitions of Inverse have determined that the matrix is singular and have declined to transform the expression.



          We can use Update to force the evaluator to avoid the optimization:



          Do[Print@Check[Inverse[({{1,2},{1,2}})]; "wrong", "right"], {i,2}];
          (*
          Inverse::sing: Matrix {{1,2},{1,2}} is singular.
          right
          wrong
          *)

          Do[Print@Check[Update; Inverse[({{1,2},{1,2}})]; "wrong", "right"], {i,2}];
          (*
          Inverse::sing: Matrix {{1,2},{1,2}} is singular.
          right
          Inverse::sing: Matrix {{1,2},{1,2}} is singular.
          right
          *)


          Analysis (current as of version 11.3.0)



          An expression is called "inert" when there are no applicable definitions which transform it. The key word here is applicable. Definitions can exist, but as long as they are not applicable the expression is treated as inert. In this case of a singular matrix, there does exist at least one definition of Inverse that is evaluated -- but that definition has a condition that detects the singularity, issues an error message, and then indicates that the definition is not applicable. The optimization is insensitive to whether or not the definition condition has any side-effects (in this case, the issuance of a message).



          We can emulate this behaviour of Inverse ourselves with a simpler example:



          f[x_] := 10 x /; If[x >= 0, True, Message[f::ltzero]; False]

          f::ltzero = "less than zero!";


          We have defined a function which takes a value and multiplies it by ten, but only under the condition that the value is not less than zero. Otherwise, the condition issues an error message and returns False indicating that the definition does not apply. So:



          f[1]
          (* 10 *)

          f[-1]
          (*
          >>f::ltzero: less than zero!
          f[-1]
          *)


          With this in place, we can see the action of the optimization:



          Table[f[-1], {2}]
          (*
          >>f::ltzero: less than zero!
          {f[-1], f[-1]}
          *)


          Note how the message is issued only once even though we tried to evaluate f[-1] twice.



          We can use Update tell the evaluator to make no optimizing assumptions about inert expressions:



          Table[Update; f[-1], {2}]
          Table[f[-1], {2}]
          (*
          >>f::ltzero: less than zero!
          >>f::ltzero: less than zero!
          {f[-1], f[-1]}
          *)


          Now, the expression is evaluated twice and the condition message appears twice.



          What About Assert?



          The question observes that wrapping Assert around the call to Inverse causes it to behave "correctly". Actually, the call to Assert is failing because the argument is expected to be True or False -- not Inverse[...]. Assert issues a message in that case and it is that message that causes Check to return its second argument. All of this can be seen if we remove Quiet from the expression:



          Reap @ Do[Sow@Check[Assert[Inverse[({{1,2},{1,2}})]];2+2,3+3],{i,2}]
          (*
          >>Inverse::sing: Matrix {{1,2},{1,2}} is singular.
          >>Assert::asrttf: Assertion test Inverse[{{1,2},{1,2}}] evaluated to Inverse[{{1,2},{1,2}}] that is neither True nor False.
          >>Assert::asrttf: Assertion test Inverse[{{1,2},{1,2}}] evaluated to Inverse[{{1,2},{1,2}}] that is neither True nor False.
          {Null,{{6,6}}}
          *)


          Notice how the Inverse::sing message was still only issued once whereas the Assert-related messages were shown multiple times.






          share|improve this answer











          $endgroup$



          The behaviour we see is due to an optimization that is being applied by the evaluator. Once the evaluator sees that an expression is inert, it assumes that for the remainder of the evaluation the same expression need not be evaluated again. In the case at hand, Inverse[{{1, 2}, {1, 2}}] is inert since the definitions of Inverse have determined that the matrix is singular and have declined to transform the expression.



          We can use Update to force the evaluator to avoid the optimization:



          Do[Print@Check[Inverse[({{1,2},{1,2}})]; "wrong", "right"], {i,2}];
          (*
          Inverse::sing: Matrix {{1,2},{1,2}} is singular.
          right
          wrong
          *)

          Do[Print@Check[Update; Inverse[({{1,2},{1,2}})]; "wrong", "right"], {i,2}];
          (*
          Inverse::sing: Matrix {{1,2},{1,2}} is singular.
          right
          Inverse::sing: Matrix {{1,2},{1,2}} is singular.
          right
          *)


          Analysis (current as of version 11.3.0)



          An expression is called "inert" when there are no applicable definitions which transform it. The key word here is applicable. Definitions can exist, but as long as they are not applicable the expression is treated as inert. In this case of a singular matrix, there does exist at least one definition of Inverse that is evaluated -- but that definition has a condition that detects the singularity, issues an error message, and then indicates that the definition is not applicable. The optimization is insensitive to whether or not the definition condition has any side-effects (in this case, the issuance of a message).



          We can emulate this behaviour of Inverse ourselves with a simpler example:



          f[x_] := 10 x /; If[x >= 0, True, Message[f::ltzero]; False]

          f::ltzero = "less than zero!";


          We have defined a function which takes a value and multiplies it by ten, but only under the condition that the value is not less than zero. Otherwise, the condition issues an error message and returns False indicating that the definition does not apply. So:



          f[1]
          (* 10 *)

          f[-1]
          (*
          >>f::ltzero: less than zero!
          f[-1]
          *)


          With this in place, we can see the action of the optimization:



          Table[f[-1], {2}]
          (*
          >>f::ltzero: less than zero!
          {f[-1], f[-1]}
          *)


          Note how the message is issued only once even though we tried to evaluate f[-1] twice.



          We can use Update tell the evaluator to make no optimizing assumptions about inert expressions:



          Table[Update; f[-1], {2}]
          Table[f[-1], {2}]
          (*
          >>f::ltzero: less than zero!
          >>f::ltzero: less than zero!
          {f[-1], f[-1]}
          *)


          Now, the expression is evaluated twice and the condition message appears twice.



          What About Assert?



          The question observes that wrapping Assert around the call to Inverse causes it to behave "correctly". Actually, the call to Assert is failing because the argument is expected to be True or False -- not Inverse[...]. Assert issues a message in that case and it is that message that causes Check to return its second argument. All of this can be seen if we remove Quiet from the expression:



          Reap @ Do[Sow@Check[Assert[Inverse[({{1,2},{1,2}})]];2+2,3+3],{i,2}]
          (*
          >>Inverse::sing: Matrix {{1,2},{1,2}} is singular.
          >>Assert::asrttf: Assertion test Inverse[{{1,2},{1,2}}] evaluated to Inverse[{{1,2},{1,2}}] that is neither True nor False.
          >>Assert::asrttf: Assertion test Inverse[{{1,2},{1,2}}] evaluated to Inverse[{{1,2},{1,2}}] that is neither True nor False.
          {Null,{{6,6}}}
          *)


          Notice how the Inverse::sing message was still only issued once whereas the Assert-related messages were shown multiple times.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered yesterday









          WReachWReach

          53.6k2115215




          53.6k2115215























              4












              $begingroup$

              The hard-coded singular matrix only causes Inverse to generate a message (triggering Check) in the first iteration of table (or Do). This doesn't happen with all message generating expressions, e.g. Check[0/0, 3 + 3] generates a message every iteration.



              On[Inverse::sing]

              f := Quiet[Check[Inverse[{{1, 2}, {1, 2}}], 3 + 3]]

              Table[f, 2]



              {6, Inverse[{{1, 2}, {1, 2}}]}




              With the matrix as a variable a singular matrix message is generated with every evaluation.



              m = {{1, 2}, {1, 2}};

              f := Quiet[Check[Inverse[m], 3 + 3]]

              Table[f, 2]



              {6, 6}







              share|improve this answer











              $endgroup$


















                4












                $begingroup$

                The hard-coded singular matrix only causes Inverse to generate a message (triggering Check) in the first iteration of table (or Do). This doesn't happen with all message generating expressions, e.g. Check[0/0, 3 + 3] generates a message every iteration.



                On[Inverse::sing]

                f := Quiet[Check[Inverse[{{1, 2}, {1, 2}}], 3 + 3]]

                Table[f, 2]



                {6, Inverse[{{1, 2}, {1, 2}}]}




                With the matrix as a variable a singular matrix message is generated with every evaluation.



                m = {{1, 2}, {1, 2}};

                f := Quiet[Check[Inverse[m], 3 + 3]]

                Table[f, 2]



                {6, 6}







                share|improve this answer











                $endgroup$
















                  4












                  4








                  4





                  $begingroup$

                  The hard-coded singular matrix only causes Inverse to generate a message (triggering Check) in the first iteration of table (or Do). This doesn't happen with all message generating expressions, e.g. Check[0/0, 3 + 3] generates a message every iteration.



                  On[Inverse::sing]

                  f := Quiet[Check[Inverse[{{1, 2}, {1, 2}}], 3 + 3]]

                  Table[f, 2]



                  {6, Inverse[{{1, 2}, {1, 2}}]}




                  With the matrix as a variable a singular matrix message is generated with every evaluation.



                  m = {{1, 2}, {1, 2}};

                  f := Quiet[Check[Inverse[m], 3 + 3]]

                  Table[f, 2]



                  {6, 6}







                  share|improve this answer











                  $endgroup$



                  The hard-coded singular matrix only causes Inverse to generate a message (triggering Check) in the first iteration of table (or Do). This doesn't happen with all message generating expressions, e.g. Check[0/0, 3 + 3] generates a message every iteration.



                  On[Inverse::sing]

                  f := Quiet[Check[Inverse[{{1, 2}, {1, 2}}], 3 + 3]]

                  Table[f, 2]



                  {6, Inverse[{{1, 2}, {1, 2}}]}




                  With the matrix as a variable a singular matrix message is generated with every evaluation.



                  m = {{1, 2}, {1, 2}};

                  f := Quiet[Check[Inverse[m], 3 + 3]]

                  Table[f, 2]



                  {6, 6}








                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited yesterday

























                  answered yesterday









                  Chris DegnenChris Degnen

                  22.1k23787




                  22.1k23787






























                      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%2f195181%2fstrange-behaviour-of-check%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

                      How did Captain America manage to do this?

                      迪纳利

                      南乌拉尔铁路局