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.

Parameters

cls (Type[~T]) – class to modify.

Return type

Type[~T]

Returns

The given class, modified so that assignment to instance variable is disallowed after construction.

@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 this copy() method and returns the result.

class logic_utils.frozendict(*args, **kwargs)

Bases: dict, typing.Generic

An immutable variant of the built-in dict class.

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 to next(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 'c1', the second call to next(fresh_constant_name_generator) will return 'c2', and so on.