Popular recipes tagged "lazy_evaluation"http://code.activestate.com/recipes/tags/lazy_evaluation/2010-01-15T06:08:56-08:00ActiveState Code Recipeslazy property (Python) 2009-04-26T18:10:55-07:00Sridhar Ratnakumarhttp://code.activestate.com/recipes/users/4169511/http://code.activestate.com/recipes/576720-lazy-property/ <p style="color: grey"> Python recipe 576720 by <a href="/recipes/users/4169511/">Sridhar Ratnakumar</a> (<a href="/recipes/tags/evaluation/">evaluation</a>, <a href="/recipes/tags/lazy/">lazy</a>, <a href="/recipes/tags/lazy_evaluation/">lazy_evaluation</a>). Revision 6. </p> <p>Python does not have lazy evaluation syntax features built-in, but fortunately decorators can be used with new-style classes to emulate such a feature. There are cases where one wants <code>foo.property</code> to return the actual property whose calculation takes significant amount of time.</p> <p>This recipe adapts the existing <code>property</code> to provide a <code>lazypropery</code> decorator that does this.</p> <p>See the first comment below for an example usage.</p> <p>Also see: <a href="http://en.wikipedia.org/wiki/Lazy_initialization">lazy initialization</a></p> Calculations with error propagation, and semi-formal expressions (Python) 2010-01-15T06:08:56-08:00Eric-Olivier LE BIGOThttp://code.activestate.com/recipes/users/2672032/http://code.activestate.com/recipes/576721-calculations-with-error-propagation-and-semi-forma/ <p style="color: grey"> Python recipe 576721 by <a href="/recipes/users/2672032/">Eric-Olivier LE BIGOT</a> (<a href="/recipes/tags/calculus/">calculus</a>, <a href="/recipes/tags/error_propagation/">error_propagation</a>, <a href="/recipes/tags/expressions/">expressions</a>, <a href="/recipes/tags/formal_calculations/">formal_calculations</a>, <a href="/recipes/tags/lazy_evaluation/">lazy_evaluation</a>, <a href="/recipes/tags/uncertainties/">uncertainties</a>). Revision 22. </p> <p><strong>Do not use this module</strong>, but use instead the more powerful <a href="http://pypi.python.org/pypi/uncertainties/">uncertainties.py module</a>.</p> <p>Module for performing calculations with error propagation, such as (1 +- 0.1) * 2 = 2 +- 0.2. Mathematical operations (addition, etc.), operations defined in the math module (sin, atan,...) and logical operations (&lt;, &gt;, etc.) can be used.</p> <p>Correlations between parts of an expression are correctly taken into account (for instance, the error on "x-x" is strictly zero).</p> <p>Code written for floats should directly work with the numbers with uncertainty defined here, without much need for modifications.</p> <p>The module also contains a class that represents non-evaluated mathematical expressions. This class is used for performing the differentiation required by the error propagation calculation, but can be used on its own, for manipulating "semi-formal" expressions whose variables can be accessed.</p> Lazy, recursive generator function (Python) 2008-12-14T10:04:29-08:00Don Sawatzkyhttp://code.activestate.com/recipes/users/4168423/http://code.activestate.com/recipes/576585-lazy-recursive-generator-function/ <p style="color: grey"> Python recipe 576585 by <a href="/recipes/users/4168423/">Don Sawatzky</a> (<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/lazy_evaluation/">lazy_evaluation</a>, <a href="/recipes/tags/recursion/">recursion</a>). Revision 4. </p> <p>This procedure was proposed as a challenge to Python and other languages as the most concise coding. See Icon programming on the web. This is a lazy, recursive generator. It can be implemented several ways in Python with lists, iteration, and recursion. However, the lists increase in size exponentially with each iteration and recursion plus they are saved in every recursion. This recipe develops a lazy generator function.</p>