3 * $Id: pfilt.h,v 1.4 2004/04/08 01:36:15 mdw Exp $
5 * Finding and testing prime numbers
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 #ifndef CATACOMB_PFILT_H
31 #define CATACOMB_PFILT_H
37 /*----- Header files ------------------------------------------------------*/
43 #ifndef CATACOMB_PRIMETAB_H
44 # include "primetab.h"
47 /*----- Data structures ---------------------------------------------------*/
49 typedef struct pfilt {
54 /*----- Functions provided ------------------------------------------------*/
56 /* --- @pfilt_smallfactor@ --- *
58 * Arguments: @mp *m@ = integer to test
60 * Returns: One of the @PGEN@ result codes.
62 * Use: Tests a number by dividing by a number of small primes. This
63 * is a useful first step if you're testing random primes; for
64 * sequential searches, @pfilt_create@ works better.
67 extern int pfilt_smallfactor(mp */*m*/);
69 /* --- @pfilt_create@ --- *
71 * Arguments: @pfilt *p@ = pointer to prime filtering context
72 * @mp *m@ = pointer to initial number to test
74 * Returns: A @PGEN@ result code.
76 * Use: Tests an initial number for primality by computing its
77 * residue modulo various small prime numbers. This is fairly
78 * quick, but not particularly certain. If a @PGEN_TRY@
79 * result is returned, perform Rabin-Miller tests to confirm.
82 extern int pfilt_create(pfilt */*p*/, mp */*m*/);
84 /* --- @pfilt_destroy@ --- *
86 * Arguments: @pfilt *p@ = pointer to prime filtering context
90 * Use: Discards a context and all the resources it holds.
93 extern void pfilt_destroy(pfilt */*p*/);
95 /* --- @pfilt_step@ --- *
97 * Arguments: @pfilt *p@ = pointer to prime filtering context
98 * @mpw step@ = how much to step the number
100 * Returns: One of the @PGEN@ result codes.
102 * Use: Steps a number by a small amount. Stepping is much faster
103 * than initializing with a new number. The test performed is
104 * the same simple one used by @primetab_create@, so @PGEN_TRY@
105 * results should be followed up by a Rabin-Miller test.
108 extern int pfilt_step(pfilt */*p*/, mpw /*step*/);
110 /* --- @pfilt_muladd@ --- *
112 * Arguments: @pfilt *p@ = destination prime filtering context
113 * @const pfilt *q@ = source prime filtering context
114 * @mpw m@ = number to multiply by
115 * @mpw a@ = number to add
117 * Returns: One of the @PGEN@ result codes.
119 * Use: Multiplies the number in a prime filtering context by a
120 * small value and then adds a small value. The destination
121 * should either be uninitialized or the same as the source.
123 * Common things to do include multiplying by 2 and adding 0 to
124 * turn a prime into a jump for finding other primes with @q@ as
125 * a factor of @p - 1@, or multiplying by 2 and adding 1.
128 extern int pfilt_muladd(pfilt */*p*/, const pfilt */*q*/,
129 mpw /*m*/, mpw /*a*/);
131 /* --- @pfilt_jump@ --- *
133 * Arguments: @pfilt *p@ = pointer to prime filtering context
134 * @const pfilt *j@ = pointer to another filtering context
136 * Returns: One of the @PGEN@ result codes.
138 * Use: Steps a number by a large amount. Even so, jumping is much
139 * faster than initializing a new number. The test peformed is
140 * the same simple one used by @primetab_create@, so @PGEN_TRY@
141 * results should be followed up by a Rabin-Miller test.
143 * Note that the number stored in the @j@ context is probably
144 * better off being even than prime. The important thing is
145 * that all of the residues for the number have already been
149 extern int pfilt_jump(pfilt */*p*/, const pfilt */*j*/);
151 /*----- That's all, folks -------------------------------------------------*/