# Path: support/types.py
# def template( *parameters ):
#     """
#     Factory function to create template meta-classes.  The function arguments
#     are the names of the template parameters.  After specialization, the bound
#     parameters are available as class attributes of the given names.
#     
#     Usage example:
#     @code
#     # Create a class template C with parameters "a" and "b"
#     class C( metaclass=template("a", "b") ):
#         pass
#     
#     # Instantiate the template with values 23 and 42; Cp is a class object.
#     Cp = C(23, 42)
#     isinstance(Cp, type) == True   # This holds
#     Cp.a == 23
#     Cp.b == 42
#     
#     # Construct Cp objects
#     x = Cp()
#     type(x) is Cp                  # This also holds
#     @endcode
#     
#     @see TypeTemplate
#     """
#     template_name = "TypeTemplate<{0}>".format( ", ".join( parameters ) )
#     template_bases = tuple( [ TypeTemplate ] )
#     template_dict = {   "__parameters__": parameters,
#                         "__unbound_parameters__": parameters,
#                         "__parameter_map__": {}
#                      }
#     return type( template_name, template_bases, template_dict )
# 
# Path: support/profiling.py
# def profiling_name(name):
#     """
#     A class decorator that sets the @p name that will show up in profiles
#     generated with the @c cProfile module.
#     
#     Usage example:
#     @code
#     @local_method_names
#     @profiling_name( "GF<{_size}>" )
#     class FiniteField( Field, metaclass=template( "_size" ) ):
#         ...
#     @endcode
#     
#     @param name    A string that contains the class name (which is usually
#                    shorter than the original name).  For template classes, the
#                    string may contain format-string variables for the
#                    parameters.
#     
#     @note  The function requires the @c local_method_name() decorator to show
#            an effect. 
#     
#     @see   The sources of rings.quotients.naive.QuotientRing for a usage
#            example and support.types.template() for information about template
#            classes.
#     """
#     def class_wrapper(cls):
#         setattr(cls, "__profiling_name__", name)
#         return cls
#     return class_wrapper
# 
# def local_method_names(cls):
#     """
#     A class decorator that makes the function names used by the @c cProfile
#     module local to the class of use (rather than the class of definition).
#     
#     The @c cProfile module uses the name of a function's code object as the
#     profile name.  Therefore, calls to methods in subclasses that do not
#     re-implement the method are counted as calls to the parent class.  In
#     template classes, this makes the call profile too coarse.
#     
#     Use profiling_name() to get shorter class names.
# 
#     @note  The decorator copies the code objects; it "flattens" the class.
#            Therefore, re-assigning methods will annihilate the decorator
#            effects for the method.
# 
#     @see   The sources of rings.quotients.naive.QuotientRing for a usage
#            example and support.types.template() for information about template
#            classes.
#     """
#     if getattr( cls.__class__, "__operation_renaming__", False ):
#         return cls
# 
#     original_new = cls.__class__.__new__
# 
#     def prefixing_new(meta_class, class_name, bases, class_dict, **kw_arguments):
#         class_object = original_new( meta_class, class_name, bases, class_dict, **kw_arguments )
# 
#         if is_incomplete( class_object ):
#             return class_object
# 
#         if "__operation_renaming__" in class_object.__dict__:
#             return class_object
# 
#         profiling_name = __profiling_str( class_object )
#         __localize_method_names(
#                     class_object.__class__,
#                     [ "__new__", "__call__" ],
#                     "{cls}::<meta>{{meth}}".format( cls = profiling_name )
#                 )
#         
#         __flatten_methods( class_object )
#         __localize_method_names(
#                     class_object,
#                     __method_names( class_object ),
#                     "{cls}::{{meth}}".format( cls = profiling_name )
#                 )
#         
#             
#         setattr( class_object, "__operation_renaming__", True )
#         return class_object
#     
#     cls.__class__.__new__ = prefixing_new
#     setattr( cls.__class__, "__operation_renaming__", True )
#     
#     return cls


from support.types import template
from support.profiling import profiling_name, local_method_names
# -*- coding: utf-8 -*-
# Copyright (c) 2010--2012  Peter Dinges <pdinges@acm.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


"""
A naive implementation of an elliptic curve with points
using Cartesian coordinates as representation.

@package   elliptic_curves.naive
@author    Peter Dinges <pdinges@acm.org>
"""


@local_method_names

# Path: support/types.py
# def template( *parameters ):
#     """
#     Factory function to create template meta-classes.  The function arguments
#     are the names of the template parameters.  After specialization, the bound
#     parameters are available as class attributes of the given names.
#     
#     Usage example:
#     @code
#     # Create a class template C with parameters "a" and "b"
#     class C( metaclass=template("a", "b") ):
#         pass
#     
#     # Instantiate the template with values 23 and 42; Cp is a class object.
#     Cp = C(23, 42)
#     isinstance(Cp, type) == True   # This holds
#     Cp.a == 23
#     Cp.b == 42
#     
#     # Construct Cp objects
#     x = Cp()
#     type(x) is Cp                  # This also holds
#     @endcode
#     
#     @see TypeTemplate
#     """
#     template_name = "TypeTemplate<{0}>".format( ", ".join( parameters ) )
#     template_bases = tuple( [ TypeTemplate ] )
#     template_dict = {   "__parameters__": parameters,
#                         "__unbound_parameters__": parameters,
#                         "__parameter_map__": {}
#                      }
#     return type( template_name, template_bases, template_dict )
# 
# Path: support/profiling.py
# def profiling_name(name):
#     """
#     A class decorator that sets the @p name that will show up in profiles
#     generated with the @c cProfile module.
#     
#     Usage example:
#     @code
#     @local_method_names
#     @profiling_name( "GF<{_size}>" )
#     class FiniteField( Field, metaclass=template( "_size" ) ):
#         ...
#     @endcode
#     
#     @param name    A string that contains the class name (which is usually
#                    shorter than the original name).  For template classes, the
#                    string may contain format-string variables for the
#                    parameters.
#     
#     @note  The function requires the @c local_method_name() decorator to show
#            an effect. 
#     
#     @see   The sources of rings.quotients.naive.QuotientRing for a usage
#            example and support.types.template() for information about template
#            classes.
#     """
#     def class_wrapper(cls):
#         setattr(cls, "__profiling_name__", name)
#         return cls
#     return class_wrapper
# 
# def local_method_names(cls):
#     """
#     A class decorator that makes the function names used by the @c cProfile
#     module local to the class of use (rather than the class of definition).
#     
#     The @c cProfile module uses the name of a function's code object as the
#     profile name.  Therefore, calls to methods in subclasses that do not
#     re-implement the method are counted as calls to the parent class.  In
#     template classes, this makes the call profile too coarse.
#     
#     Use profiling_name() to get shorter class names.
# 
#     @note  The decorator copies the code objects; it "flattens" the class.
#            Therefore, re-assigning methods will annihilate the decorator
#            effects for the method.
# 
#     @see   The sources of rings.quotients.naive.QuotientRing for a usage
#            example and support.types.template() for information about template
#            classes.
#     """
#     if getattr( cls.__class__, "__operation_renaming__", False ):
#         return cls
# 
#     original_new = cls.__class__.__new__
# 
#     def prefixing_new(meta_class, class_name, bases, class_dict, **kw_arguments):
#         class_object = original_new( meta_class, class_name, bases, class_dict, **kw_arguments )
# 
#         if is_incomplete( class_object ):
#             return class_object
# 
#         if "__operation_renaming__" in class_object.__dict__:
#             return class_object
# 
#         profiling_name = __profiling_str( class_object )
#         __localize_method_names(
#                     class_object.__class__,
#                     [ "__new__", "__call__" ],
#                     "{cls}::<meta>{{meth}}".format( cls = profiling_name )
#                 )
#         
#         __flatten_methods( class_object )
#         __localize_method_names(
#                     class_object,
#                     __method_names( class_object ),
#                     "{cls}::{{meth}}".format( cls = profiling_name )
#                 )
#         
#             
#         setattr( class_object, "__operation_renaming__", True )
#         return class_object
#     
#     cls.__class__.__new__ = prefixing_new
#     setattr( cls.__class__, "__operation_renaming__", True )
#     
#     return cls


# Path: elliptic_curves/naive.py
from support.types import template
from support.profiling import profiling_name, local_method_names

# -*- coding: utf-8 -*-
# Copyright (c) 2010--2012  Peter Dinges <pdinges@acm.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


"""
A naive implementation of an elliptic curve with points
using Cartesian coordinates as representation.

@package   elliptic_curves.naive
@author    Peter Dinges <pdinges@acm.org>
"""


@local_method_names

@profiling_name( "E<{_field}>" )