logic_utils module¶
Python infrastructure for the Mathematical Logic through Programming book.
-
@
logic_utils.
frozen
(cls)¶ A class decorator that disallows assignment to instance variables after construction.
-
class
logic_utils.
frozendict
(*args, **kwargs)¶ Bases:
dict
,typing.Generic
An immutable variant of the built-in
dict
class.
-
@
logic_utils.
memoized_parameterless_method
(method)¶ A method decorator for parameterless methods of immutable classes that memoizes the return value to avoid recalculation.
- Parameters
method (
Callable
[[~T], ~S]) – method to modify.- Return type
Callable
[[~T], ~S]- Returns
The given method, modified so that after its first execution, its functionality is replaced with simply returning the value calculated by its first execution. If the value calculated by the given method has a
copy
()
method, then instead of returning this value, each execution of the returned method, including the first one, makes a fresh call to thiscopy
()
method and returns the result.
-
logic_utils.
fresh_variable_name_generator
¶ A generator for fresh variable names. The first call to
next
(
fresh_variable_name_generator
)
will return'z1'
, the second call tonext
(
fresh_variable_name_generator
)
will return'z2'
, and so on.
-
logic_utils.
fresh_constant_name_generator
¶ A generator for fresh constant names. The first call to
next
(
fresh_constant_name_generator
)
will return'e1'
, the second call tonext
(
fresh_constant_name_generator
)
will return'e2'
, and so on.