// ---------------------------------------------------------------------------
// - Libmth.cpp                                                              -
// - afnix:mth module - declaration & implementation                         -
// ---------------------------------------------------------------------------
// - This program is free software;  you can redistribute it  and/or  modify -
// - it provided that this copyright notice is kept intact.                  -
// -                                                                         -
// - 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.  In no event shall -
// - the copyright holder be liable for any  direct, indirect, incidental or -
// - special damages arising in any way out of the use of this software.     -
// ---------------------------------------------------------------------------
// - copyright (c) 1999-2009 amaury darsch                                   -
// ---------------------------------------------------------------------------

#include "Meta.hpp"
#include "Mpia.hpp"
#include "Random.hpp"
#include "Libmth.hpp"
#include "Function.hpp"
#include "Primality.hpp"

namespace afnix {

  // initialize the afnix:mth module

  Object* init_afnix_mth (Interp* interp, Vector* argv) {
    // make sure we are not called from something crazy
    if (interp == nilp) return nilp;

    // create the afnix:mth nameset
    Nameset* aset = interp->mknset ("afnix");
    Nameset* nset = aset->mknset   ("mth");

    // bind all mth calls in the afnix:mth nameset
    nset->symcst ("gcd",                new Function (mth_gcd));
    nset->symcst ("lcm",                new Function (mth_lcm));
    nset->symcst ("mmi",                new Function (mth_mmi));
    
    nset->symcst ("get-random-integer", new Function (mth_longrnd));
    nset->symcst ("get-random-real",    new Function (mth_realrnd));
    nset->symcst ("get-random-relatif", new Function (mth_relnrnd));
    nset->symcst ("get-random-prime",   new Function (mth_primrnd));

    nset->symcst ("fermat-p",           new Function (mth_frmtp));
    nset->symcst ("miller-rabin-p",     new Function (mth_mrptp));
    nset->symcst ("prime-probable-p",   new Function (mth_ppntp));

    // not used but needed
    return nilp;
  }
}

extern "C" {
  afnix::Object* dli_afnix_mth (afnix::Interp* interp, afnix::Vector* argv) {
    return init_afnix_mth (interp, argv);
  }
}
