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

/* linbox/field/givaro-gfq.h
 * Copyright (C) 2002 <NAME>
 *
 * Written by <NAME> <<EMAIL>>
 * JGD 12.06.2002 : -- I don't see the need of *(new in convert
 * JGD 19.09.2003 : added isZero
 * WJT 24.06.2005 : Removed using declarations
 *
 * ------------------------------------
 *
 * See COPYING for license information.
 */

/* WARNING this wrapper works only with an improved version of Givaro.
 * This version of givaro won't be available for public yet.
 * But it is available on my web page.
 * You can send me a mail to get it or for others details.
 */

#ifndef __FIELD_GIVARO_GFQ
#define __FIELD_GIVARO_GFQ


#include <linbox/integer.h>
#include <linbox/field/field-traits.h>
#include <linbox/field/field-interface.h>
#include <linbox/util/debug.h>
#include <linbox/field/hom.h>
#include "linbox/linbox-config.h"


//------------------------------------
// Files of Givaro library


#include <givaro/givgfq.h>
#include <givaro/giv_randiter.h>
#include <givaro/givpoly1factor.h>
//------------------------------------

// Namespace in which all LinBox code resides
namespace LinBox 
{ 

	template <class Ring>
	struct ClassifyRing;

	class GivaroGfq;

	template<>
	struct ClassifyRing<GivaroGfq> {
		typedef RingCategories::ModularTag categoryTag;
        };


	class GivaroGfq;
	
	template<>
	integer& FieldTraits<GivaroGfq>::maxModulus( integer& i )
		{ return i = integer( 32749 ); } // prevprime( 2^15 )

	template<>
	bool FieldTraits<GivaroGfq>::goodModulus( const integer& i ) {
		integer max;
		if( i < 2 || i > FieldTraits<GivaroGfq>::maxModulus(max) )
			return false;
		return probab_prime( i, 10 );
	}

	template<>
	integer& FieldTraits<GivaroGfq>::maxExponent( integer& i )
		{ return i = 20; } // Cardinality must be <= 2^20


  /** wrapper of Givaro's GFqDom<int32>  class 
  \ingroup field

   *  This class allows to construct only extension fields with a prime characteristic.
   */   
 class GivaroGfq : public GFqDom<int32>, public FieldInterface
  {
 
  public:

    /** Element type.
     *  This type is inherited from the Givaro class GFqDom<int32>
     */
    typedef  GFqDom<int32>::Rep Element;
    
    /** RandIter type
     *  This type is inherited from the Givaro class GFqDom<TAG>
     */	
    typedef GIV_randIter< GFqDom<int32>, LinBox::integer >  RandIter;

    /** Constructor from an integer
     *  this constructor use the ZpzDom<TAG> constructor
     */
    GivaroGfq(const integer& p, const integer& k=1) :
      GFqDom<int32>(static_cast<UTT>(int32(p)), static_cast<UTT>(int32(k))) {
	//enforce that the cardinality must be <2^16, for givaro-gfq
	int32 pl=p;
	for(int32 i=1;i<k;++i) pl*=(int32)p;
	if(!FieldTraits<GivaroGfq>::goodModulus(p)) 
		throw PreconditionFailed(__FUNCTION__,__LINE__,"modulus be between 2 and 2^15 and prime");
	else if(pl>(1<<20)) throw PreconditionFailed(__FUNCTION__,__LINE__,"cardinality must be < 2^20");

	}

    // <NAME> 6-15-04
    // This constructor takes a vector of ints that represent the polynomial
    // to use (for modular arithmetic on the extension field).
    // Mostly copied from givaro/givgfq.inl
    GivaroGfq(const integer& p, const integer& k, const std::vector<integer>& modPoly)<commit_msg>added empty cstor<commit_after>/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/* linbox/field/givaro-gfq.h
 * Copyright (C) 2002 <NAME>
 *
 * Written by <NAME> <<EMAIL>>
 * JGD 12.06.2002 : -- I don't see the need of *(new in convert
 * JGD 19.09.2003 : added isZero
 * WJT 24.06.2005 : Removed using declarations
 *
 * ------------------------------------
 *
 * See COPYING for license information.
 */

/* WARNING this wrapper works only with an improved version of Givaro.
 * This version of givaro won't be available for public yet.
 * But it is available on my web page.
 * You can send me a mail to get it or for others details.
 */

#ifndef __FIELD_GIVARO_GFQ
#define __FIELD_GIVARO_GFQ


#include <linbox/integer.h>
#include <linbox/field/field-traits.h>
#include <linbox/field/field-interface.h>
#include <linbox/util/debug.h>
#include <linbox/field/hom.h>
#include "linbox/linbox-config.h"


//------------------------------------
// Files of Givaro library


#include <givaro/givgfq.h>
#include <givaro/giv_randiter.h>
#include <givaro/givpoly1factor.h>
//------------------------------------

// Namespace in which all LinBox code resides
namespace LinBox 
{ 

	template <class Ring>
	struct ClassifyRing;

	class GivaroGfq;

	template<>
	struct ClassifyRing<GivaroGfq> {
		typedef RingCategories::ModularTag categoryTag;
        };


	class GivaroGfq;
	
	template<>
	integer& FieldTraits<GivaroGfq>::maxModulus( integer& i )
		{ return i = integer( 32749 ); } // prevprime( 2^15 )

	template<>
	bool FieldTraits<GivaroGfq>::goodModulus( const integer& i ) {
		integer max;
		if( i < 2 || i > FieldTraits<GivaroGfq>::maxModulus(max) )
			return false;
		return probab_prime( i, 10 );
	}

	template<>
	integer& FieldTraits<GivaroGfq>::maxExponent( integer& i )
		{ return i = 20; } // Cardinality must be <= 2^20


  /** wrapper of Givaro's GFqDom<int32>  class 
  \ingroup field

   *  This class allows to construct only extension fields with a prime characteristic.
   */   
 class GivaroGfq : public GFqDom<int32>, public FieldInterface
  {
 
  public:

    /** Element type.
     *  This type is inherited from the Givaro class GFqDom<int32>
     */
    typedef  GFqDom<int32>::Rep Element;
    
    /** RandIter type
     *  This type is inherited from the Givaro class GFqDom<TAG>
     */	
    typedef GIV_randIter< GFqDom<int32>, LinBox::integer >  RandIter;

    /** Empty Constructor 
     */
    GivaroGfq() : GFqDom<int32>() { }

    /** Constructor from an integer
     *  this constructor use the ZpzDom<TAG> constructor
     */
    GivaroGfq(const integer& p, const integer& k=1) :
      GFqDom<int32>(static_cast<UTT>(int32(p)), static_cast<UTT>(int32(k))) {
	//enforce that the cardinality must be <2^16, for givaro-gfq
	int32 pl=p;
	for(int32 i=1;i<k;++i) pl*=(int32)p;
	if(!FieldTraits<GivaroGfq>::goodModulus(p)) 
		throw PreconditionFailed(__FUNCTION__,__LINE__,"modulus be between 2 and 2^15 and prime");
	else if(pl>(1<<20)) throw PreconditionFailed(__FUNCTION__,__LINE__,"cardinality must be < 2^20");

	}

    // <NAME> 6-15-04
    // This constructor takes a vector of ints that represent the polynomial
    // to use (for modular arithmetic on the extension field).
    // Mostly copied from givaro/givgfq.inl
    GivaroGfq(const integer& p, const integer& k, const std::vector<integer>& modPoly)
{'fraction_non_alphanumeric': 0.15238954012623984, 'fraction_numerical': 0.027051397655545536, 'mean_word_length': 3.0953846153846154, 'pattern_counts': {'":': 0, '<': 90, '<?xml version=': 0, '>': 80, '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': '1342478', 'n_tokens_mistral': 2493, 'n_tokens_neox': 2261, 'n_words': 639}