Search code examples
wolfram-mathematicalazy-evaluation

Does Mathematica 7 support lazy evaluation?


Suppose I have a list of Matrices saved in the variable G and apply the following operations:

top[g_] = Minors[g]
Diagonal[top /@ G] 

Minorsreturns a matrix where each element is the determinant with the (i,j) row/col deleted, and Diagonal returns a list of the diagonal elements of a matrix.

My question is on the evaluation of these commands - clearly I do not want all entries evaluated. Is Mathematica lazy in the sense that Diagonal is parsed first which only extracts the elements needed from Minors or is the minor matrix constructed and then its diagonal elements are pulled out?

This is a general question for lazy evaluation, however being new to Mathematica I would appreciate any tips on how to improve the syntax for the specific problem.


Solution

  • It's late so only a short answer: investigate Hold[] and its relatives. With them you can implement lazy evaluating functions. Most intrinsic Mathematica functions are not lazy, a few are. In general, as a beginner, you should avoid modifying the behaviour of Mathematica's intrinsic functions, though it is very good fun to do so and can very easily make the entire system unusable.