<commit_before>/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/* linbox/field/hom.h
 * Written by <NAME>
 * See COPYING for license information.
 */

#ifndef __HOM_H
#define __HOM_H

// including specialization to modular
#include "linbox/field/modular.h"

namespace LinBox {
/** 
 * An instance of Hom is a homomorphism from a ring of type Source
 * to a ring (usually field) of type Target.  The intended use is that
 * it will be a natural mapping.  For instance: 
 * 
 * Hom<Integers, Modular<integer> >(Z, Zp) nat; // is the mod p mapping.
 *
 * Hom<Unparametric<NTL_ZZp, Modular<integer> >(Zp, Mp) nat; 
 *
 * // is an isomorphism, provided the Zp and Mp have same characteristic.
 * Hom<Unparametric<NTL_ZZp, Unparameteric<NTL_ZZpEx> >(Z3, Z27) nat; 
 * // is the embedding of the prime field in the extension.
 */
template< class Source, class Target > 
class Hom 
{   public:
	typedef typename Source::Element SrcElt;
	typedef typename Target::Element Elt;

	Hom(){}
	/**
	 * Construct a homomorphism from a specific source ring S and target 
	 * field T with Hom(S, T).  The default behaviour is error.  
	 * Specializations define all actual homomorphisms.
	 */
	Hom(Source& S, Target& T){ throw NoHomError(); }

	/** 
	 * image(t, s) implements the homomorphism, assigning the 
	 * t the value of the image of s under the mapping.
	 *
	 * The default behaviour is a no-op.
	 */
	Elt& image(Elt& t, const SrcElt& s) {}

	/** If possible, preimage(s,t) assigns a value to s such that 
	 * the image of s is t.  Otherwise behaviour is unspecified.
	 * An error may be thrown, a conventional value may be set, or
	 * an arb value set.
	 *
	 * The default behaviour is a no-op.
	 */
	SrcElt& preimage(SrcElt& s, const Elt& t) {}
	const Source& source() { return _source;}
	const Target& target() { return _target;}

	private:
	Source _source;
	Target _target;
}; // end Hom 

/// Error object for attempt to establish a Hom that cannot exist.
class NoHomError{};

/// Specialization to Modular<uint16> --> Modular<uint_32>.
// Just a trial.  delete this when better examples exist.
template<> Hom<Modular<uint16>, Modular<uint32> >::
	Hom(Modular<uint16>& S, Modular<uint32>& T ): _source(S),_target(T)
	{
			integer ps, pt;
			if (S.characteristic(ps) != T.characteristic(pt)) throw NoHomError();
	}

template<> Modular<uint32>::Element& Hom<Modular<uint16>, Modular<uint32> >::
image(Modular<uint32>::Element& t, const Modular<uint16>::Element& s) { return t = s; }

// assumes t normalized.
template<> Modular<uint16>::Element& Hom<Modular<uint16>, Modular<uint32> >::
preimage(Modular<uint16>::Element& s, const Modular<uint32>::Element& t) { return s = t; }

}// namespace LinBox
#endif // __HOM_H<commit_msg>Add some special case<commit_after>/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/* linbox/field/hom.h
 * Written by <NAME>
 * See COPYING for license information.
 */

#ifndef __HOM_H
#define __HOM_H


namespace LinBox {
/** 
 * An instance of Hom is a homomorphism from a ring of type Source
 * to a ring (usually field) of type Target.  The intended use is that
 * it will be a natural mapping.  For instance: 
 * 
 * Hom<Unparametric<Integers>, Modular<integer> >(Z, Zp) nat; // is the mod p mapping.
 *
 * Hom<<NTL_ZZp, Modular<integer> >(Zp, Mp) nat; 
 *
 * // is an isomorphism, provided the Zp and Mp have same characteristic.
 * Hom<Unparametric<NTL_ZZp, Unparameteric<NTL_ZZpEx> >(Z3, Z27) nat; 
 * // is the embedding of the prime field in the extension.
 */

/// Error object for attempt to establish a Hom that cannot exist.
class NoHomError{};

template< class Source, class Target > 
class Hom 
{   public:
	typedef typename Source::Element SrcElt;
	typedef typename Target::Element Elt;

	//Hom(){}
	/**
	 * Construct a homomorphism from a specific source ring S and target 
	 * field T with Hom(S, T).  The default behaviour is error.  
	 * Specializations define all actual homomorphisms.
	 */
	Hom(const Source& S, const Target& T){ throw NoHomError(); }

	/** 
	 * image(t, s) implements the homomorphism, assigning the 
	 * t the value of the image of s under the mapping.
	 *
	 * The default behaviour is a no-op.
	 */
	Elt& image(Elt& t, const SrcElt& s) {return t;}

	/** If possible, preimage(s,t) assigns a value to s such that 
	 * the image of s is t.  Otherwise behaviour is unspecified.
	 * An error may be thrown, a conventional value may be set, or
	 * an arb value set.
	 *
	 * The default behaviour is a no-op.
	 */
	SrcElt& preimage(SrcElt& s, const Elt& t) {return s;}
	const Source& source() { return _source;}
	const Target& target() { return _target;}

	private:
	Source _source;
	Target _target;
}; // end Hom 


}

#ifdef __FIELD_MODULAR_H
// including specialization to modular
//#include "linbox/field/modular.h"
/// Specialization to Modular<uint16> --> Modular<uint_32>.
// Just a trial.  delete this when better examples exist.
namespace LinBox {
template<> Hom<Modular<uint16>, Modular<uint32> >::
	Hom(const Modular<uint16>& S, const Modular<uint32>& T ): _source(S),_target(T)
	{
			integer ps, pt;
			if (S.characteristic(ps) != T.characteristic(pt)) throw NoHomError();
	}

template<> Modular<uint32>::Element& Hom<Modular<uint16>, Modular<uint32> >::
image(Modular<uint32>::Element& t, const Modular<uint16>::Element& s) { return t = s; }

// assumes t normalized.
template<> Modular<uint16>::Element& Hom<Modular<uint16>, Modular<uint32> >::
preimage(Modular<uint16>::Element& s, const Modular<uint32>::Element& t) { return s = t; }

}// namespace LinBox
#endif

#ifdef __FIELD_UNPARAMETRIC_H
namespace LinBox{
template<class _Target>
class Hom<UnparametricField<integer>, _Target> {

public:
	typedef UnparametricField<integer> Source;
	typedef _Target Target;
	typedef typename Source::Element SrcElt;
	typedef typename Target::Element Elt;
	
	Hom(const Source& S, const Target& T) : _source (S), _target (T) {}
	inline Elt& image(Elt& t, const SrcElt& s) {
		_target. init (t, s);
		return t;
	}
	inline SrcElt& preimage(SrcElt& s, const Elt& t) {
		_target. convert (s, t);
		return s;
	}
	const Source& source() { return _source;}
	const Target& target() { return _target;}

protected:
	Source _source;
	Target _target;
}; // end Hom 
}
#endif

#ifdef __LINBOX_NTL_ZZ_H__

namespace LinBox {

template<class _Target > 
class Hom <NTL_ZZ , _Target> {

public:
	typedef NTL_ZZ Source;
	typedef _Target Target;
	typedef typename Source::Element SrcElt;
	typedef typename Target::Element Elt;
	
	Hom(const Source& S, const Target& T) : _source(S), _target(T){}
	inline Elt& image(Elt& t, const SrcElt& s) {
		_source. convert (tmp, s);
		_target. init (t, tmp);
		return t;
	}
	inline SrcElt& preimage(SrcElt& s, const Elt& t) {
		_target. convert (tmp, t);
		_source. init (s, tmp);
		return s;
	}
	const Source& source() { return _source;}
	const Target& target() { return _target;}

protected:
	integer tmp;
	Source _source;
	Target _target;
}; // end Hom 
}
#endif

#ifdef __FIELD_GMP_RATIONAL_H
namespace LinBox {
template <class _Target>
class Hom<GMPRationalField, _Target> {

public:
	typedef GMPRationalField Source;
	typedef _Target Target;
	typedef typename Source::Element SrcElt;
	typedef typename Target::Element Elt;
	
	Hom(const Source& S, const Target& T) : _source (S), _target(T){}
	Elt& image(Elt& t, const SrcElt& s) {
		_source. get_num (num, s);
		_source. get_den (den, s);
		_target. init (tmp, den);
		_target. init (t, num);
		_target. divin (t, tmp);
		return t;
	}
	SrcElt& preimage(SrcElt& s, const Elt& t) {
		_target. convert (num, t);
		_source. init (s, num);
		return s;
	}
	const Source& source() { return _source;}
	const Target& target() { return _target;}

protected:
	integer num, den;
	Elt tmp;
	Source _source;
	Target _target;
}; // end Hom 

template <>
class Hom<GMPRationalField, GMPRationalField> {

public:
	typedef GMPRationalField Source;
	typedef GMPRationalField Target;
	typedef Source::Element SrcElt;
	typedef Target::Element Elt;
	
	Hom(const Source& S, const Target& T) : _source (S), _target(T){}
	Elt& image(Elt& t, const SrcElt& s) {
		_source. assign (t, s);
		return t;
	}
	SrcElt& preimage(SrcElt& s, const Elt& t) {
		_source. assign (s, t);
		return s;
	}
	const Source& source() { return _source;}
	const Target& target() { return _target;}

protected:
	Source _source;
	Target _target;
}; // end Hom 

}
#endif

#endif // __HOM_H
{'fraction_non_alphanumeric': 0.1290896159317212, 'fraction_numerical': 0.008771929824561403, 'mean_word_length': 3.954198473282443, 'pattern_counts': {'":': 0, '<': 78, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2851712', 'n_tokens_mistral': 3094, 'n_tokens_neox': 2851, 'n_words': 994}