Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 184633
1
/* Generated by Cython 0.25.2 */
2
3
/* BEGIN: Cython Metadata
4
{
5
"distutils": {
6
"depends": []
7
},
8
"module_name": "code.psage.number_fields.sqrt5.prime"
9
}
10
END: Cython Metadata */
11
12
#define PY_SSIZE_T_CLEAN
13
#include "Python.h"
14
#ifndef Py_PYTHON_H
15
#error Python headers needed to compile C extensions, please install development version of Python.
16
#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000)
17
#error Cython requires Python 2.6+ or Python 3.2+.
18
#else
19
#define CYTHON_ABI "0_25_2"
20
#include <stddef.h>
21
#ifndef offsetof
22
#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
23
#endif
24
#if !defined(WIN32) && !defined(MS_WINDOWS)
25
#ifndef __stdcall
26
#define __stdcall
27
#endif
28
#ifndef __cdecl
29
#define __cdecl
30
#endif
31
#ifndef __fastcall
32
#define __fastcall
33
#endif
34
#endif
35
#ifndef DL_IMPORT
36
#define DL_IMPORT(t) t
37
#endif
38
#ifndef DL_EXPORT
39
#define DL_EXPORT(t) t
40
#endif
41
#ifndef HAVE_LONG_LONG
42
#if PY_VERSION_HEX >= 0x03030000 || (PY_MAJOR_VERSION == 2 && PY_VERSION_HEX >= 0x02070000)
43
#define HAVE_LONG_LONG
44
#endif
45
#endif
46
#ifndef PY_LONG_LONG
47
#define PY_LONG_LONG LONG_LONG
48
#endif
49
#ifndef Py_HUGE_VAL
50
#define Py_HUGE_VAL HUGE_VAL
51
#endif
52
#ifdef PYPY_VERSION
53
#define CYTHON_COMPILING_IN_PYPY 1
54
#define CYTHON_COMPILING_IN_PYSTON 0
55
#define CYTHON_COMPILING_IN_CPYTHON 0
56
#undef CYTHON_USE_TYPE_SLOTS
57
#define CYTHON_USE_TYPE_SLOTS 0
58
#undef CYTHON_USE_ASYNC_SLOTS
59
#define CYTHON_USE_ASYNC_SLOTS 0
60
#undef CYTHON_USE_PYLIST_INTERNALS
61
#define CYTHON_USE_PYLIST_INTERNALS 0
62
#undef CYTHON_USE_UNICODE_INTERNALS
63
#define CYTHON_USE_UNICODE_INTERNALS 0
64
#undef CYTHON_USE_UNICODE_WRITER
65
#define CYTHON_USE_UNICODE_WRITER 0
66
#undef CYTHON_USE_PYLONG_INTERNALS
67
#define CYTHON_USE_PYLONG_INTERNALS 0
68
#undef CYTHON_AVOID_BORROWED_REFS
69
#define CYTHON_AVOID_BORROWED_REFS 1
70
#undef CYTHON_ASSUME_SAFE_MACROS
71
#define CYTHON_ASSUME_SAFE_MACROS 0
72
#undef CYTHON_UNPACK_METHODS
73
#define CYTHON_UNPACK_METHODS 0
74
#undef CYTHON_FAST_THREAD_STATE
75
#define CYTHON_FAST_THREAD_STATE 0
76
#undef CYTHON_FAST_PYCALL
77
#define CYTHON_FAST_PYCALL 0
78
#elif defined(PYSTON_VERSION)
79
#define CYTHON_COMPILING_IN_PYPY 0
80
#define CYTHON_COMPILING_IN_PYSTON 1
81
#define CYTHON_COMPILING_IN_CPYTHON 0
82
#ifndef CYTHON_USE_TYPE_SLOTS
83
#define CYTHON_USE_TYPE_SLOTS 1
84
#endif
85
#undef CYTHON_USE_ASYNC_SLOTS
86
#define CYTHON_USE_ASYNC_SLOTS 0
87
#undef CYTHON_USE_PYLIST_INTERNALS
88
#define CYTHON_USE_PYLIST_INTERNALS 0
89
#ifndef CYTHON_USE_UNICODE_INTERNALS
90
#define CYTHON_USE_UNICODE_INTERNALS 1
91
#endif
92
#undef CYTHON_USE_UNICODE_WRITER
93
#define CYTHON_USE_UNICODE_WRITER 0
94
#undef CYTHON_USE_PYLONG_INTERNALS
95
#define CYTHON_USE_PYLONG_INTERNALS 0
96
#ifndef CYTHON_AVOID_BORROWED_REFS
97
#define CYTHON_AVOID_BORROWED_REFS 0
98
#endif
99
#ifndef CYTHON_ASSUME_SAFE_MACROS
100
#define CYTHON_ASSUME_SAFE_MACROS 1
101
#endif
102
#ifndef CYTHON_UNPACK_METHODS
103
#define CYTHON_UNPACK_METHODS 1
104
#endif
105
#undef CYTHON_FAST_THREAD_STATE
106
#define CYTHON_FAST_THREAD_STATE 0
107
#undef CYTHON_FAST_PYCALL
108
#define CYTHON_FAST_PYCALL 0
109
#else
110
#define CYTHON_COMPILING_IN_PYPY 0
111
#define CYTHON_COMPILING_IN_PYSTON 0
112
#define CYTHON_COMPILING_IN_CPYTHON 1
113
#ifndef CYTHON_USE_TYPE_SLOTS
114
#define CYTHON_USE_TYPE_SLOTS 1
115
#endif
116
#if PY_MAJOR_VERSION < 3
117
#undef CYTHON_USE_ASYNC_SLOTS
118
#define CYTHON_USE_ASYNC_SLOTS 0
119
#elif !defined(CYTHON_USE_ASYNC_SLOTS)
120
#define CYTHON_USE_ASYNC_SLOTS 1
121
#endif
122
#if PY_VERSION_HEX < 0x02070000
123
#undef CYTHON_USE_PYLONG_INTERNALS
124
#define CYTHON_USE_PYLONG_INTERNALS 0
125
#elif !defined(CYTHON_USE_PYLONG_INTERNALS)
126
#define CYTHON_USE_PYLONG_INTERNALS 1
127
#endif
128
#ifndef CYTHON_USE_PYLIST_INTERNALS
129
#define CYTHON_USE_PYLIST_INTERNALS 1
130
#endif
131
#ifndef CYTHON_USE_UNICODE_INTERNALS
132
#define CYTHON_USE_UNICODE_INTERNALS 1
133
#endif
134
#if PY_VERSION_HEX < 0x030300F0
135
#undef CYTHON_USE_UNICODE_WRITER
136
#define CYTHON_USE_UNICODE_WRITER 0
137
#elif !defined(CYTHON_USE_UNICODE_WRITER)
138
#define CYTHON_USE_UNICODE_WRITER 1
139
#endif
140
#ifndef CYTHON_AVOID_BORROWED_REFS
141
#define CYTHON_AVOID_BORROWED_REFS 0
142
#endif
143
#ifndef CYTHON_ASSUME_SAFE_MACROS
144
#define CYTHON_ASSUME_SAFE_MACROS 1
145
#endif
146
#ifndef CYTHON_UNPACK_METHODS
147
#define CYTHON_UNPACK_METHODS 1
148
#endif
149
#ifndef CYTHON_FAST_THREAD_STATE
150
#define CYTHON_FAST_THREAD_STATE 1
151
#endif
152
#ifndef CYTHON_FAST_PYCALL
153
#define CYTHON_FAST_PYCALL 1
154
#endif
155
#endif
156
#if !defined(CYTHON_FAST_PYCCALL)
157
#define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
158
#endif
159
#if CYTHON_USE_PYLONG_INTERNALS
160
#include "longintrepr.h"
161
#undef SHIFT
162
#undef BASE
163
#undef MASK
164
#endif
165
#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
166
#define Py_OptimizeFlag 0
167
#endif
168
#define __PYX_BUILD_PY_SSIZE_T "n"
169
#define CYTHON_FORMAT_SSIZE_T "z"
170
#if PY_MAJOR_VERSION < 3
171
#define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
172
#define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
173
PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
174
#define __Pyx_DefaultClassType PyClass_Type
175
#else
176
#define __Pyx_BUILTIN_MODULE_NAME "builtins"
177
#define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
178
PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
179
#define __Pyx_DefaultClassType PyType_Type
180
#endif
181
#ifndef Py_TPFLAGS_CHECKTYPES
182
#define Py_TPFLAGS_CHECKTYPES 0
183
#endif
184
#ifndef Py_TPFLAGS_HAVE_INDEX
185
#define Py_TPFLAGS_HAVE_INDEX 0
186
#endif
187
#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
188
#define Py_TPFLAGS_HAVE_NEWBUFFER 0
189
#endif
190
#ifndef Py_TPFLAGS_HAVE_FINALIZE
191
#define Py_TPFLAGS_HAVE_FINALIZE 0
192
#endif
193
#ifndef METH_FASTCALL
194
#define METH_FASTCALL 0x80
195
typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject **args,
196
Py_ssize_t nargs, PyObject *kwnames);
197
#else
198
#define __Pyx_PyCFunctionFast _PyCFunctionFast
199
#endif
200
#if CYTHON_FAST_PYCCALL
201
#define __Pyx_PyFastCFunction_Check(func)\
202
((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)))))
203
#else
204
#define __Pyx_PyFastCFunction_Check(func) 0
205
#endif
206
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
207
#define CYTHON_PEP393_ENABLED 1
208
#define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\
209
0 : _PyUnicode_Ready((PyObject *)(op)))
210
#define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
211
#define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
212
#define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u)
213
#define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u)
214
#define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u)
215
#define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i)
216
#define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch)
217
#define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
218
#else
219
#define CYTHON_PEP393_ENABLED 0
220
#define PyUnicode_1BYTE_KIND 1
221
#define PyUnicode_2BYTE_KIND 2
222
#define PyUnicode_4BYTE_KIND 4
223
#define __Pyx_PyUnicode_READY(op) (0)
224
#define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
225
#define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
226
#define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
227
#define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE))
228
#define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u))
229
#define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
230
#define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
231
#define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u))
232
#endif
233
#if CYTHON_COMPILING_IN_PYPY
234
#define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b)
235
#define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b)
236
#else
237
#define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b)
238
#define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
239
PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
240
#endif
241
#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
242
#define PyUnicode_Contains(u, s) PySequence_Contains(u, s)
243
#endif
244
#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
245
#define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type)
246
#endif
247
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
248
#define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt)
249
#endif
250
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
251
#define PyObject_Malloc(s) PyMem_Malloc(s)
252
#define PyObject_Free(p) PyMem_Free(p)
253
#define PyObject_Realloc(p) PyMem_Realloc(p)
254
#endif
255
#if CYTHON_COMPILING_IN_PYSTON
256
#define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co)
257
#define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
258
#else
259
#define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0)
260
#define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno)
261
#endif
262
#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
263
#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
264
#if PY_MAJOR_VERSION >= 3
265
#define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b)
266
#else
267
#define __Pyx_PyString_Format(a, b) PyString_Format(a, b)
268
#endif
269
#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
270
#define PyObject_ASCII(o) PyObject_Repr(o)
271
#endif
272
#if PY_MAJOR_VERSION >= 3
273
#define PyBaseString_Type PyUnicode_Type
274
#define PyStringObject PyUnicodeObject
275
#define PyString_Type PyUnicode_Type
276
#define PyString_Check PyUnicode_Check
277
#define PyString_CheckExact PyUnicode_CheckExact
278
#endif
279
#if PY_MAJOR_VERSION >= 3
280
#define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
281
#define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
282
#else
283
#define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
284
#define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
285
#endif
286
#ifndef PySet_CheckExact
287
#define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
288
#endif
289
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
290
#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
291
#if PY_MAJOR_VERSION >= 3
292
#define PyIntObject PyLongObject
293
#define PyInt_Type PyLong_Type
294
#define PyInt_Check(op) PyLong_Check(op)
295
#define PyInt_CheckExact(op) PyLong_CheckExact(op)
296
#define PyInt_FromString PyLong_FromString
297
#define PyInt_FromUnicode PyLong_FromUnicode
298
#define PyInt_FromLong PyLong_FromLong
299
#define PyInt_FromSize_t PyLong_FromSize_t
300
#define PyInt_FromSsize_t PyLong_FromSsize_t
301
#define PyInt_AsLong PyLong_AsLong
302
#define PyInt_AS_LONG PyLong_AS_LONG
303
#define PyInt_AsSsize_t PyLong_AsSsize_t
304
#define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
305
#define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
306
#define PyNumber_Int PyNumber_Long
307
#endif
308
#if PY_MAJOR_VERSION >= 3
309
#define PyBoolObject PyLongObject
310
#endif
311
#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
312
#ifndef PyUnicode_InternFromString
313
#define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
314
#endif
315
#endif
316
#if PY_VERSION_HEX < 0x030200A4
317
typedef long Py_hash_t;
318
#define __Pyx_PyInt_FromHash_t PyInt_FromLong
319
#define __Pyx_PyInt_AsHash_t PyInt_AsLong
320
#else
321
#define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
322
#define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
323
#endif
324
#if PY_MAJOR_VERSION >= 3
325
#define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
326
#else
327
#define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
328
#endif
329
#if CYTHON_USE_ASYNC_SLOTS
330
#if PY_VERSION_HEX >= 0x030500B1
331
#define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
332
#define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
333
#else
334
typedef struct {
335
unaryfunc am_await;
336
unaryfunc am_aiter;
337
unaryfunc am_anext;
338
} __Pyx_PyAsyncMethodsStruct;
339
#define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
340
#endif
341
#else
342
#define __Pyx_PyType_AsAsync(obj) NULL
343
#endif
344
#ifndef CYTHON_RESTRICT
345
#if defined(__GNUC__)
346
#define CYTHON_RESTRICT __restrict__
347
#elif defined(_MSC_VER) && _MSC_VER >= 1400
348
#define CYTHON_RESTRICT __restrict
349
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
350
#define CYTHON_RESTRICT restrict
351
#else
352
#define CYTHON_RESTRICT
353
#endif
354
#endif
355
#ifndef CYTHON_UNUSED
356
# if defined(__GNUC__)
357
# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
358
# define CYTHON_UNUSED __attribute__ ((__unused__))
359
# else
360
# define CYTHON_UNUSED
361
# endif
362
# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
363
# define CYTHON_UNUSED __attribute__ ((__unused__))
364
# else
365
# define CYTHON_UNUSED
366
# endif
367
#endif
368
#ifndef CYTHON_MAYBE_UNUSED_VAR
369
# if defined(__cplusplus)
370
template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
371
# else
372
# define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
373
# endif
374
#endif
375
#ifndef CYTHON_NCP_UNUSED
376
# if CYTHON_COMPILING_IN_CPYTHON
377
# define CYTHON_NCP_UNUSED
378
# else
379
# define CYTHON_NCP_UNUSED CYTHON_UNUSED
380
# endif
381
#endif
382
#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
383
384
#ifndef CYTHON_INLINE
385
#if defined(__clang__)
386
#define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
387
#elif defined(__GNUC__)
388
#define CYTHON_INLINE __inline__
389
#elif defined(_MSC_VER)
390
#define CYTHON_INLINE __inline
391
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
392
#define CYTHON_INLINE inline
393
#else
394
#define CYTHON_INLINE
395
#endif
396
#endif
397
398
#if defined(WIN32) || defined(MS_WINDOWS)
399
#define _USE_MATH_DEFINES
400
#endif
401
#include <math.h>
402
#ifdef NAN
403
#define __PYX_NAN() ((float) NAN)
404
#else
405
static CYTHON_INLINE float __PYX_NAN() {
406
float value;
407
memset(&value, 0xFF, sizeof(value));
408
return value;
409
}
410
#endif
411
#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
412
#define __Pyx_truncl trunc
413
#else
414
#define __Pyx_truncl truncl
415
#endif
416
417
418
#define __PYX_ERR(f_index, lineno, Ln_error) \
419
{ \
420
__pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \
421
}
422
423
#if PY_MAJOR_VERSION >= 3
424
#define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
425
#define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
426
#else
427
#define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
428
#define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
429
#endif
430
431
#ifndef __PYX_EXTERN_C
432
#ifdef __cplusplus
433
#define __PYX_EXTERN_C extern "C"
434
#else
435
#define __PYX_EXTERN_C extern
436
#endif
437
#endif
438
439
#define __PYX_HAVE__code__psage__number_fields__sqrt5__prime
440
#define __PYX_HAVE_API__code__psage__number_fields__sqrt5__prime
441
#include <string.h>
442
#include <stdio.h>
443
#include "pari/pari.h"
444
#ifdef _OPENMP
445
#include <omp.h>
446
#endif /* _OPENMP */
447
448
#ifdef PYREX_WITHOUT_ASSERTIONS
449
#define CYTHON_WITHOUT_ASSERTIONS
450
#endif
451
452
typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
453
const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;
454
455
#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
456
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0
457
#define __PYX_DEFAULT_STRING_ENCODING ""
458
#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
459
#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
460
#define __Pyx_uchar_cast(c) ((unsigned char)c)
461
#define __Pyx_long_cast(x) ((long)x)
462
#define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\
463
(sizeof(type) < sizeof(Py_ssize_t)) ||\
464
(sizeof(type) > sizeof(Py_ssize_t) &&\
465
likely(v < (type)PY_SSIZE_T_MAX ||\
466
v == (type)PY_SSIZE_T_MAX) &&\
467
(!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
468
v == (type)PY_SSIZE_T_MIN))) ||\
469
(sizeof(type) == sizeof(Py_ssize_t) &&\
470
(is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
471
v == (type)PY_SSIZE_T_MAX))) )
472
#if defined (__cplusplus) && __cplusplus >= 201103L
473
#include <cstdlib>
474
#define __Pyx_sst_abs(value) std::abs(value)
475
#elif SIZEOF_INT >= SIZEOF_SIZE_T
476
#define __Pyx_sst_abs(value) abs(value)
477
#elif SIZEOF_LONG >= SIZEOF_SIZE_T
478
#define __Pyx_sst_abs(value) labs(value)
479
#elif defined (_MSC_VER) && defined (_M_X64)
480
#define __Pyx_sst_abs(value) _abs64(value)
481
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
482
#define __Pyx_sst_abs(value) llabs(value)
483
#elif defined (__GNUC__)
484
#define __Pyx_sst_abs(value) __builtin_llabs(value)
485
#else
486
#define __Pyx_sst_abs(value) ((value<0) ? -value : value)
487
#endif
488
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*);
489
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
490
#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
491
#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
492
#define __Pyx_PyBytes_FromString PyBytes_FromString
493
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
494
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
495
#if PY_MAJOR_VERSION < 3
496
#define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString
497
#define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
498
#else
499
#define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString
500
#define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
501
#endif
502
#define __Pyx_PyObject_AsSString(s) ((signed char*) __Pyx_PyObject_AsString(s))
503
#define __Pyx_PyObject_AsUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s))
504
#define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s)
505
#define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s)
506
#define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s)
507
#define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s)
508
#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
509
#if PY_MAJOR_VERSION < 3
510
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
511
{
512
const Py_UNICODE *u_end = u;
513
while (*u_end++) ;
514
return (size_t)(u_end - u - 1);
515
}
516
#else
517
#define __Pyx_Py_UNICODE_strlen Py_UNICODE_strlen
518
#endif
519
#define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
520
#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
521
#define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode
522
#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
523
#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
524
#define __Pyx_PyBool_FromLong(b) ((b) ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False))
525
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
526
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
527
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
528
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
529
#if CYTHON_ASSUME_SAFE_MACROS
530
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
531
#else
532
#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
533
#endif
534
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
535
#if PY_MAJOR_VERSION >= 3
536
#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
537
#else
538
#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
539
#endif
540
#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
541
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
542
static int __Pyx_sys_getdefaultencoding_not_ascii;
543
static int __Pyx_init_sys_getdefaultencoding_params(void) {
544
PyObject* sys;
545
PyObject* default_encoding = NULL;
546
PyObject* ascii_chars_u = NULL;
547
PyObject* ascii_chars_b = NULL;
548
const char* default_encoding_c;
549
sys = PyImport_ImportModule("sys");
550
if (!sys) goto bad;
551
default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
552
Py_DECREF(sys);
553
if (!default_encoding) goto bad;
554
default_encoding_c = PyBytes_AsString(default_encoding);
555
if (!default_encoding_c) goto bad;
556
if (strcmp(default_encoding_c, "ascii") == 0) {
557
__Pyx_sys_getdefaultencoding_not_ascii = 0;
558
} else {
559
char ascii_chars[128];
560
int c;
561
for (c = 0; c < 128; c++) {
562
ascii_chars[c] = c;
563
}
564
__Pyx_sys_getdefaultencoding_not_ascii = 1;
565
ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
566
if (!ascii_chars_u) goto bad;
567
ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
568
if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
569
PyErr_Format(
570
PyExc_ValueError,
571
"This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
572
default_encoding_c);
573
goto bad;
574
}
575
Py_DECREF(ascii_chars_u);
576
Py_DECREF(ascii_chars_b);
577
}
578
Py_DECREF(default_encoding);
579
return 0;
580
bad:
581
Py_XDECREF(default_encoding);
582
Py_XDECREF(ascii_chars_u);
583
Py_XDECREF(ascii_chars_b);
584
return -1;
585
}
586
#endif
587
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
588
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
589
#else
590
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
591
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
592
static char* __PYX_DEFAULT_STRING_ENCODING;
593
static int __Pyx_init_sys_getdefaultencoding_params(void) {
594
PyObject* sys;
595
PyObject* default_encoding = NULL;
596
char* default_encoding_c;
597
sys = PyImport_ImportModule("sys");
598
if (!sys) goto bad;
599
default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
600
Py_DECREF(sys);
601
if (!default_encoding) goto bad;
602
default_encoding_c = PyBytes_AsString(default_encoding);
603
if (!default_encoding_c) goto bad;
604
__PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c));
605
if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
606
strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
607
Py_DECREF(default_encoding);
608
return 0;
609
bad:
610
Py_XDECREF(default_encoding);
611
return -1;
612
}
613
#endif
614
#endif
615
616
617
/* Test for GCC > 2.95 */
618
#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
619
#define likely(x) __builtin_expect(!!(x), 1)
620
#define unlikely(x) __builtin_expect(!!(x), 0)
621
#else /* !__GNUC__ or GCC < 2.95 */
622
#define likely(x) (x)
623
#define unlikely(x) (x)
624
#endif /* __GNUC__ */
625
626
static PyObject *__pyx_m;
627
static PyObject *__pyx_d;
628
static PyObject *__pyx_b;
629
static PyObject *__pyx_empty_tuple;
630
static PyObject *__pyx_empty_bytes;
631
static PyObject *__pyx_empty_unicode;
632
static int __pyx_lineno;
633
static int __pyx_clineno = 0;
634
static const char * __pyx_cfilenm= __FILE__;
635
static const char *__pyx_filename;
636
637
638
static const char *__pyx_f[] = {
639
"code/psage/number_fields/sqrt5/prime.pyx",
640
"code/psage/number_fields/sqrt5/prime.pxd",
641
"type.pxd",
642
};
643
644
/*--- Type declarations ---*/
645
struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime;
646
647
/* "code/psage/number_fields/sqrt5/prime.pxd":22
648
* #################################################################################
649
*
650
* cdef class Prime: # <<<<<<<<<<<<<<
651
* cdef public long p, r
652
* cdef bint first
653
*/
654
struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime {
655
PyObject_HEAD
656
struct __pyx_vtabstruct_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_vtab;
657
long p;
658
long r;
659
int first;
660
};
661
662
663
664
/* "code/psage/number_fields/sqrt5/prime.pyx":83
665
* from sage.rings.number_field.number_field_ideal import NumberFieldFractionalIdeal
666
*
667
* cdef class Prime: # <<<<<<<<<<<<<<
668
* """
669
* Nonzero prime ideal of the ring of integers of Q(sqrt(5)). This
670
*/
671
672
struct __pyx_vtabstruct_4code_5psage_13number_fields_5sqrt5_5prime_Prime {
673
long (*norm)(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *, int __pyx_skip_dispatch);
674
int (*is_split)(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *, int __pyx_skip_dispatch);
675
int (*is_inert)(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *, int __pyx_skip_dispatch);
676
int (*is_ramified)(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *, int __pyx_skip_dispatch);
677
};
678
static struct __pyx_vtabstruct_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_vtabptr_4code_5psage_13number_fields_5sqrt5_5prime_Prime;
679
680
/* --- Runtime support code (head) --- */
681
/* Refnanny.proto */
682
#ifndef CYTHON_REFNANNY
683
#define CYTHON_REFNANNY 0
684
#endif
685
#if CYTHON_REFNANNY
686
typedef struct {
687
void (*INCREF)(void*, PyObject*, int);
688
void (*DECREF)(void*, PyObject*, int);
689
void (*GOTREF)(void*, PyObject*, int);
690
void (*GIVEREF)(void*, PyObject*, int);
691
void* (*SetupContext)(const char*, int, const char*);
692
void (*FinishContext)(void**);
693
} __Pyx_RefNannyAPIStruct;
694
static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
695
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
696
#define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
697
#ifdef WITH_THREAD
698
#define __Pyx_RefNannySetupContext(name, acquire_gil)\
699
if (acquire_gil) {\
700
PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
701
__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
702
PyGILState_Release(__pyx_gilstate_save);\
703
} else {\
704
__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
705
}
706
#else
707
#define __Pyx_RefNannySetupContext(name, acquire_gil)\
708
__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
709
#endif
710
#define __Pyx_RefNannyFinishContext()\
711
__Pyx_RefNanny->FinishContext(&__pyx_refnanny)
712
#define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
713
#define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
714
#define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
715
#define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
716
#define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
717
#define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
718
#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
719
#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
720
#else
721
#define __Pyx_RefNannyDeclarations
722
#define __Pyx_RefNannySetupContext(name, acquire_gil)
723
#define __Pyx_RefNannyFinishContext()
724
#define __Pyx_INCREF(r) Py_INCREF(r)
725
#define __Pyx_DECREF(r) Py_DECREF(r)
726
#define __Pyx_GOTREF(r)
727
#define __Pyx_GIVEREF(r)
728
#define __Pyx_XINCREF(r) Py_XINCREF(r)
729
#define __Pyx_XDECREF(r) Py_XDECREF(r)
730
#define __Pyx_XGOTREF(r)
731
#define __Pyx_XGIVEREF(r)
732
#endif
733
#define __Pyx_XDECREF_SET(r, v) do {\
734
PyObject *tmp = (PyObject *) r;\
735
r = v; __Pyx_XDECREF(tmp);\
736
} while (0)
737
#define __Pyx_DECREF_SET(r, v) do {\
738
PyObject *tmp = (PyObject *) r;\
739
r = v; __Pyx_DECREF(tmp);\
740
} while (0)
741
#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
742
#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
743
744
/* PyObjectGetAttrStr.proto */
745
#if CYTHON_USE_TYPE_SLOTS
746
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
747
PyTypeObject* tp = Py_TYPE(obj);
748
if (likely(tp->tp_getattro))
749
return tp->tp_getattro(obj, attr_name);
750
#if PY_MAJOR_VERSION < 3
751
if (likely(tp->tp_getattr))
752
return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
753
#endif
754
return PyObject_GetAttr(obj, attr_name);
755
}
756
#else
757
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
758
#endif
759
760
/* GetBuiltinName.proto */
761
static PyObject *__Pyx_GetBuiltinName(PyObject *name);
762
763
/* RaiseDoubleKeywords.proto */
764
static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);
765
766
/* ParseKeywords.proto */
767
static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
768
PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
769
const char* function_name);
770
771
/* RaiseArgTupleInvalid.proto */
772
static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
773
Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);
774
775
/* GetModuleGlobalName.proto */
776
static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name);
777
778
/* PyCFunctionFastCall.proto */
779
#if CYTHON_FAST_PYCCALL
780
static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
781
#else
782
#define __Pyx_PyCFunction_FastCall(func, args, nargs) (assert(0), NULL)
783
#endif
784
785
/* PyFunctionFastCall.proto */
786
#if CYTHON_FAST_PYCALL
787
#define __Pyx_PyFunction_FastCall(func, args, nargs)\
788
__Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
789
#if 1 || PY_VERSION_HEX < 0x030600B1
790
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs);
791
#else
792
#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
793
#endif
794
#endif
795
796
/* PyObjectCall.proto */
797
#if CYTHON_COMPILING_IN_CPYTHON
798
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
799
#else
800
#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
801
#endif
802
803
/* PyObjectCallMethO.proto */
804
#if CYTHON_COMPILING_IN_CPYTHON
805
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
806
#endif
807
808
/* PyObjectCallOneArg.proto */
809
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);
810
811
/* PyObjectCallNoArg.proto */
812
#if CYTHON_COMPILING_IN_CPYTHON
813
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
814
#else
815
#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
816
#endif
817
818
/* None.proto */
819
static CYTHON_INLINE long __Pyx_mod_long(long, long);
820
821
/* PyThreadStateGet.proto */
822
#if CYTHON_FAST_THREAD_STATE
823
#define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate;
824
#define __Pyx_PyThreadState_assign __pyx_tstate = PyThreadState_GET();
825
#else
826
#define __Pyx_PyThreadState_declare
827
#define __Pyx_PyThreadState_assign
828
#endif
829
830
/* PyErrFetchRestore.proto */
831
#if CYTHON_FAST_THREAD_STATE
832
#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
833
#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
834
#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
835
#define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
836
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
837
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
838
#else
839
#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb)
840
#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb)
841
#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb)
842
#define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb)
843
#endif
844
845
/* WriteUnraisableException.proto */
846
static void __Pyx_WriteUnraisable(const char *name, int clineno,
847
int lineno, const char *filename,
848
int full_traceback, int nogil);
849
850
/* ArgTypeTest.proto */
851
static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
852
const char *name, int exact);
853
854
/* Import.proto */
855
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);
856
857
/* ImportFrom.proto */
858
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);
859
860
/* RaiseException.proto */
861
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);
862
863
/* ExtTypeTest.proto */
864
static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type);
865
866
/* ListAppend.proto */
867
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
868
static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
869
PyListObject* L = (PyListObject*) list;
870
Py_ssize_t len = Py_SIZE(list);
871
if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) {
872
Py_INCREF(x);
873
PyList_SET_ITEM(list, len, x);
874
Py_SIZE(list) = len+1;
875
return 0;
876
}
877
return PyList_Append(list, x);
878
}
879
#else
880
#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
881
#endif
882
883
/* SetVTable.proto */
884
static int __Pyx_SetVtable(PyObject *dict, void *vtable);
885
886
/* CodeObjectCache.proto */
887
typedef struct {
888
PyCodeObject* code_object;
889
int code_line;
890
} __Pyx_CodeObjectCacheEntry;
891
struct __Pyx_CodeObjectCache {
892
int count;
893
int max_count;
894
__Pyx_CodeObjectCacheEntry* entries;
895
};
896
static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
897
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
898
static PyCodeObject *__pyx_find_code_object(int code_line);
899
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
900
901
/* AddTraceback.proto */
902
static void __Pyx_AddTraceback(const char *funcname, int c_line,
903
int py_line, const char *filename);
904
905
/* CIntToPy.proto */
906
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
907
908
/* CIntFromPy.proto */
909
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
910
911
/* CIntFromPy.proto */
912
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
913
914
/* CheckBinaryVersion.proto */
915
static int __Pyx_check_binary_version(void);
916
917
/* PyIdentifierFromString.proto */
918
#if !defined(__Pyx_PyIdentifier_FromString)
919
#if PY_MAJOR_VERSION < 3
920
#define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
921
#else
922
#define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
923
#endif
924
#endif
925
926
/* ModuleImport.proto */
927
static PyObject *__Pyx_ImportModule(const char *name);
928
929
/* TypeImport.proto */
930
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict);
931
932
/* InitStrings.proto */
933
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
934
935
static int __pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_is_split(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/
936
static int __pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_is_inert(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/
937
static int __pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_is_ramified(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/
938
static long __pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_norm(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/
939
940
/* Module declarations from 'libc.string' */
941
942
/* Module declarations from 'libc.stdio' */
943
944
/* Module declarations from '__builtin__' */
945
946
/* Module declarations from 'cpython.type' */
947
static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0;
948
949
/* Module declarations from 'cpython' */
950
951
/* Module declarations from 'cpython.object' */
952
953
/* Module declarations from 'code.psage.number_fields.sqrt5.prime' */
954
static PyTypeObject *__pyx_ptype_4code_5psage_13number_fields_5sqrt5_5prime_Prime = 0;
955
static CYTHON_INLINE PyObject *__pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_PY_NEW(PyTypeObject *); /*proto*/
956
#define __Pyx_MODULE_NAME "code.psage.number_fields.sqrt5.prime"
957
int __pyx_module_is_main_code__psage__number_fields__sqrt5__prime = 0;
958
959
/* Implementation of 'code.psage.number_fields.sqrt5.prime' */
960
static PyObject *__pyx_builtin_ValueError;
961
static const char __pyx_k_F[] = "F";
962
static const char __pyx_k_P[] = "P";
963
static const char __pyx_k_a[] = "a";
964
static const char __pyx_k_b[] = "b";
965
static const char __pyx_k_p[] = "p";
966
static const char __pyx_k_r[] = "r";
967
static const char __pyx_k_s[] = "%s";
968
static const char __pyx_k_t[] = "t";
969
static const char __pyx_k_v[] = "v";
970
static const char __pyx_k_p2[] = "p2";
971
static const char __pyx_k_r0[] = "r0";
972
static const char __pyx_k_r1[] = "r1";
973
static const char __pyx_k_sr[] = "sr";
974
static const char __pyx_k_gen[] = "gen";
975
static const char __pyx_k_s_s[] = "%s%s";
976
static const char __pyx_k_main[] = "__main__";
977
static const char __pyx_k_misc[] = "misc";
978
static const char __pyx_k_norm[] = "norm";
979
static const char __pyx_k_repr[] = "__repr__";
980
static const char __pyx_k_stop[] = "stop";
981
static const char __pyx_k_test[] = "__test__";
982
static const char __pyx_k_bound[] = "bound";
983
static const char __pyx_k_check[] = "check";
984
static const char __pyx_k_first[] = "first";
985
static const char __pyx_k_ideal[] = "ideal";
986
static const char __pyx_k_start[] = "start";
987
static const char __pyx_k_import[] = "__import__";
988
static const char __pyx_k_Integer[] = "Integer";
989
static const char __pyx_k_py_ints[] = "py_ints";
990
static const char __pyx_k_is_inert[] = "is_inert";
991
static const char __pyx_k_is_split[] = "is_split";
992
static const char __pyx_k_pari_hnf[] = "pari_hnf";
993
static const char __pyx_k_sage_all[] = "sage.all";
994
static const char __pyx_k_ValueError[] = "ValueError";
995
static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
996
static const char __pyx_k_is_ramified[] = "is_ramified";
997
static const char __pyx_k_prime_range[] = "prime_range";
998
static const char __pyx_k_primes_above[] = "primes_above";
999
static const char __pyx_k_is_pseudoprime[] = "is_pseudoprime";
1000
static const char __pyx_k_prime_range_ZZ[] = "prime_range_ZZ";
1001
static const char __pyx_k_p_must_be_a_prime[] = "p must be a prime";
1002
static const char __pyx_k_sage_rings_integer[] = "sage.rings.integer";
1003
static const char __pyx_k_primes_of_bounded_norm[] = "primes_of_bounded_norm";
1004
static const char __pyx_k_NumberFieldFractionalIdeal[] = "NumberFieldFractionalIdeal";
1005
static const char __pyx_k_bound_must_be_less_than_2_31[] = "bound must be less than 2^31";
1006
static const char __pyx_k_Fast_prime_ideals_of_the_ring_R[] = "\nFast prime ideals of the ring R of integers of Q(sqrt(5)).\n\nThis module implements Cython classes for prime ideals of R, and their\nenumeration. The main entry function is primes_of_bounded_norm::\n\n sage: from psage.number_fields.sqrt5 import primes_of_bounded_norm\n sage: v = primes_of_bounded_norm(50); v\n [2, 5a, 3, 11a, 11b, 19a, 19b, 29a, 29b, 31a, 31b, 41a, 41b, 7]\n\nNote that the output of primes_of_bounded_norm is a list. Each entry\nis a prime ideal, which prints using a simple label consisting of the\ncharacteristic of the prime then \"a\" or \"b\", where \"b\" only appears for\nthe second split prime.::\n\n sage: type(v[8])\n <type 'psage.number_fields.sqrt5.prime.Prime'>\n sage: v[8].sage_ideal()\n Fractional ideal (a + 5)\n\nAUTHOR:\n - William Stein \n";
1007
static const char __pyx_k_projects_68c8b2b8_03ba_44d4_a0d[] = "/projects/68c8b2b8-03ba-44d4-a0d1-5d771c8cb465/code/psage/number_fields/sqrt5/prime.pyx";
1008
static const char __pyx_k_code_psage_number_fields_sqrt5_p[] = "code.psage.number_fields.sqrt5.prime";
1009
static const char __pyx_k_sage_rings_number_field_number_f[] = "sage.rings.number_field.number_field_ideal";
1010
static PyObject *__pyx_n_s_F;
1011
static PyObject *__pyx_n_s_Integer;
1012
static PyObject *__pyx_n_s_NumberFieldFractionalIdeal;
1013
static PyObject *__pyx_n_s_P;
1014
static PyObject *__pyx_n_s_ValueError;
1015
static PyObject *__pyx_n_s_a;
1016
static PyObject *__pyx_n_s_b;
1017
static PyObject *__pyx_n_s_bound;
1018
static PyObject *__pyx_kp_s_bound_must_be_less_than_2_31;
1019
static PyObject *__pyx_n_s_check;
1020
static PyObject *__pyx_n_s_code_psage_number_fields_sqrt5_p;
1021
static PyObject *__pyx_n_s_first;
1022
static PyObject *__pyx_n_s_gen;
1023
static PyObject *__pyx_n_s_ideal;
1024
static PyObject *__pyx_n_s_import;
1025
static PyObject *__pyx_n_s_is_inert;
1026
static PyObject *__pyx_n_s_is_pseudoprime;
1027
static PyObject *__pyx_n_s_is_ramified;
1028
static PyObject *__pyx_n_s_is_split;
1029
static PyObject *__pyx_n_s_main;
1030
static PyObject *__pyx_n_s_misc;
1031
static PyObject *__pyx_n_s_norm;
1032
static PyObject *__pyx_n_s_p;
1033
static PyObject *__pyx_n_s_p2;
1034
static PyObject *__pyx_kp_s_p_must_be_a_prime;
1035
static PyObject *__pyx_n_s_pari_hnf;
1036
static PyObject *__pyx_n_s_prime_range;
1037
static PyObject *__pyx_n_s_prime_range_ZZ;
1038
static PyObject *__pyx_n_s_primes_above;
1039
static PyObject *__pyx_n_s_primes_of_bounded_norm;
1040
static PyObject *__pyx_kp_s_projects_68c8b2b8_03ba_44d4_a0d;
1041
static PyObject *__pyx_n_s_py_ints;
1042
static PyObject *__pyx_n_s_pyx_vtable;
1043
static PyObject *__pyx_n_s_r;
1044
static PyObject *__pyx_n_s_r0;
1045
static PyObject *__pyx_n_s_r1;
1046
static PyObject *__pyx_n_s_repr;
1047
static PyObject *__pyx_kp_s_s;
1048
static PyObject *__pyx_kp_s_s_s;
1049
static PyObject *__pyx_n_s_sage_all;
1050
static PyObject *__pyx_n_s_sage_rings_integer;
1051
static PyObject *__pyx_n_s_sage_rings_number_field_number_f;
1052
static PyObject *__pyx_n_s_sr;
1053
static PyObject *__pyx_n_s_start;
1054
static PyObject *__pyx_n_s_stop;
1055
static PyObject *__pyx_n_s_t;
1056
static PyObject *__pyx_n_s_test;
1057
static PyObject *__pyx_n_s_v;
1058
static int __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime___init__(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self, PyObject *__pyx_v_p, long __pyx_v_r, int __pyx_v_first); /* proto */
1059
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_2__repr__(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self); /* proto */
1060
static Py_hash_t __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_4__hash__(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self); /* proto */
1061
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_6_latex_(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self); /* proto */
1062
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_8is_split(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self); /* proto */
1063
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_10is_inert(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self); /* proto */
1064
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_12is_ramified(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self); /* proto */
1065
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_14norm(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self); /* proto */
1066
#if PY_MAJOR_VERSION < 3
1067
static int __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_16__cmp__(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self, struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_right); /* proto */
1068
#endif
1069
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_18sage_ideal(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self); /* proto */
1070
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1p___get__(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self); /* proto */
1071
static int __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1p_2__set__(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
1072
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1r___get__(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self); /* proto */
1073
static int __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1r_2__set__(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
1074
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_primes_above(CYTHON_UNUSED PyObject *__pyx_self, long __pyx_v_p, int __pyx_v_check); /* proto */
1075
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_2primes_of_bounded_norm(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_bound); /* proto */
1076
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_4prime_range(CYTHON_UNUSED PyObject *__pyx_self, long __pyx_v_start, PyObject *__pyx_v_stop); /* proto */
1077
static PyObject *__pyx_tp_new_4code_5psage_13number_fields_5sqrt5_5prime_Prime(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
1078
static PyObject *__pyx_int_0;
1079
static PyObject *__pyx_int_1;
1080
static PyObject *__pyx_int_3;
1081
static PyObject *__pyx_int_2147483648;
1082
static PyObject *__pyx_tuple_;
1083
static PyObject *__pyx_tuple__2;
1084
static PyObject *__pyx_tuple__3;
1085
static PyObject *__pyx_tuple__5;
1086
static PyObject *__pyx_tuple__7;
1087
static PyObject *__pyx_codeobj__4;
1088
static PyObject *__pyx_codeobj__6;
1089
static PyObject *__pyx_codeobj__8;
1090
1091
/* "code/psage/number_fields/sqrt5/prime.pyx":53
1092
*
1093
*
1094
* cdef inline PY_NEW(type t): # <<<<<<<<<<<<<<
1095
* """
1096
* Return ``t.__new__(t)``. This works even for types like
1097
*/
1098
1099
static CYTHON_INLINE PyObject *__pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_PY_NEW(PyTypeObject *__pyx_v_t) {
1100
PyObject *__pyx_r = NULL;
1101
__Pyx_RefNannyDeclarations
1102
PyObject *__pyx_t_1 = NULL;
1103
__Pyx_RefNannySetupContext("PY_NEW", 0);
1104
1105
/* "code/psage/number_fields/sqrt5/prime.pyx":59
1106
* optimizations assume that ``tp_new`` doesn't change).
1107
* """
1108
* return (<PyTypeObject*>t).tp_new(t, <object>NULL, <object>NULL) # <<<<<<<<<<<<<<
1109
*
1110
*
1111
*/
1112
__Pyx_XDECREF(__pyx_r);
1113
__pyx_t_1 = ((PyTypeObject *)__pyx_v_t)->tp_new(((PyTypeObject *)__pyx_v_t), ((PyObject *)NULL), ((PyObject *)NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error)
1114
__Pyx_GOTREF(__pyx_t_1);
1115
__pyx_r = __pyx_t_1;
1116
__pyx_t_1 = 0;
1117
goto __pyx_L0;
1118
1119
/* "code/psage/number_fields/sqrt5/prime.pyx":53
1120
*
1121
*
1122
* cdef inline PY_NEW(type t): # <<<<<<<<<<<<<<
1123
* """
1124
* Return ``t.__new__(t)``. This works even for types like
1125
*/
1126
1127
/* function exit code */
1128
__pyx_L1_error:;
1129
__Pyx_XDECREF(__pyx_t_1);
1130
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.PY_NEW", __pyx_clineno, __pyx_lineno, __pyx_filename);
1131
__pyx_r = 0;
1132
__pyx_L0:;
1133
__Pyx_XGIVEREF(__pyx_r);
1134
__Pyx_RefNannyFinishContext();
1135
return __pyx_r;
1136
}
1137
1138
/* "code/psage/number_fields/sqrt5/prime.pyx":62
1139
*
1140
*
1141
* cdef inline void PY_SET_TP_NEW(type dst, type src): # <<<<<<<<<<<<<<
1142
* """
1143
* Manually set ``dst.__new__`` to ``src.__new__``. This is used to
1144
*/
1145
1146
static CYTHON_INLINE void __pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_PY_SET_TP_NEW(PyTypeObject *__pyx_v_dst, PyTypeObject *__pyx_v_src) {
1147
__Pyx_RefNannyDeclarations
1148
newfunc __pyx_t_1;
1149
__Pyx_RefNannySetupContext("PY_SET_TP_NEW", 0);
1150
1151
/* "code/psage/number_fields/sqrt5/prime.pyx":68
1152
* irrelevant base class ``tp_new`` methods.
1153
* """
1154
* (<PyTypeObject*>dst).tp_new = (<PyTypeObject*>src).tp_new # <<<<<<<<<<<<<<
1155
*
1156
*
1157
*/
1158
__pyx_t_1 = ((PyTypeObject *)__pyx_v_src)->tp_new;
1159
((PyTypeObject *)__pyx_v_dst)->tp_new = __pyx_t_1;
1160
1161
/* "code/psage/number_fields/sqrt5/prime.pyx":62
1162
*
1163
*
1164
* cdef inline void PY_SET_TP_NEW(type dst, type src): # <<<<<<<<<<<<<<
1165
* """
1166
* Manually set ``dst.__new__`` to ``src.__new__``. This is used to
1167
*/
1168
1169
/* function exit code */
1170
__Pyx_RefNannyFinishContext();
1171
}
1172
1173
/* "code/psage/number_fields/sqrt5/prime.pyx":71
1174
*
1175
*
1176
* cdef inline bint HAS_DICTIONARY(obj): # <<<<<<<<<<<<<<
1177
* """
1178
* Test whether the given object has a Python dictionary.
1179
*/
1180
1181
static CYTHON_INLINE int __pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_HAS_DICTIONARY(PyObject *__pyx_v_obj) {
1182
int __pyx_r;
1183
__Pyx_RefNannyDeclarations
1184
__Pyx_RefNannySetupContext("HAS_DICTIONARY", 0);
1185
1186
/* "code/psage/number_fields/sqrt5/prime.pyx":75
1187
* Test whether the given object has a Python dictionary.
1188
* """
1189
* return Py_TYPE(obj).tp_dictoffset != 0 # <<<<<<<<<<<<<<
1190
*
1191
* cdef extern from "pari/pari.h":
1192
*/
1193
__pyx_r = (Py_TYPE(__pyx_v_obj)->tp_dictoffset != 0);
1194
goto __pyx_L0;
1195
1196
/* "code/psage/number_fields/sqrt5/prime.pyx":71
1197
*
1198
*
1199
* cdef inline bint HAS_DICTIONARY(obj): # <<<<<<<<<<<<<<
1200
* """
1201
* Test whether the given object has a Python dictionary.
1202
*/
1203
1204
/* function exit code */
1205
__pyx_L0:;
1206
__Pyx_RefNannyFinishContext();
1207
return __pyx_r;
1208
}
1209
1210
/* "code/psage/number_fields/sqrt5/prime.pyx":95
1211
* # cpdef bint is_inert(self)
1212
* # cpdef bint is_ramified(self)
1213
* def __init__(self, p, long r=0, bint first=True): # <<<<<<<<<<<<<<
1214
* """
1215
* Create Prime ideal with given residue characteristic, root,
1216
*/
1217
1218
/* Python wrapper */
1219
static int __pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
1220
static char __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_5Prime___init__[] = "\n Create Prime ideal with given residue characteristic, root,\n and first or not with that characterstic.\n\n INPUT form 1:\n - `p` -- prime\n - `r` -- root (or 0)\n - ``first`` -- boolean: True if first prime over p\n\n INPUT form 2:\n - p -- prime ideal of integers of Q(sqrt(5)); validity of the\n input is not checked in any way!\n\n NOTE: No checking is done to verify that the input is valid.\n \n EXAMPLES::\n\n sage: from psage.number_fields.sqrt5.prime import Prime\n sage: P = Prime(2,0,True); P\n 2\n sage: type(P)\n <type 'psage.number_fields.sqrt5.prime.Prime'>\n sage: P = Prime(5,3,True); P\n 5a\n sage: P = Prime(11,8,True); P\n 11a\n sage: P = Prime(11,4,False); P\n 11b\n\n We can also set P using a prime ideal of the ring of integers::\n\n sage: from psage.number_fields.sqrt5.prime import Prime; K.<a> = NumberField(x^2-x-1)\n sage: P1 = Prime(K.primes_above(11)[0]); P2 = Prime(K.primes_above(11)[1]); P1, P2\n (11b, 11a)\n sage: P1 > P2\n True\n sage: Prime(K.prime_above(2))\n 2\n sage: P = Prime(K.prime_above(5)); P, P.r\n (5a, 3)\n sage: Prime(K.prime_above(3))\n 3\n\n Test that conversion both ways works for primes up to norm `10^5`::\n \n sage: from psage.number_fields.sqrt5.prime import primes_of_bounded_norm, Prime\n sage: v = primes_of_bounded_norm(10^5)\n sage: w = [Prime(z.sage_ideal()) for z in v]\n sage: v == w\n True\n ";
1221
#if CYTHON_COMPILING_IN_CPYTHON
1222
struct wrapperbase __pyx_wrapperbase_4code_5psage_13number_fields_5sqrt5_5prime_5Prime___init__;
1223
#endif
1224
static int __pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
1225
PyObject *__pyx_v_p = 0;
1226
long __pyx_v_r;
1227
int __pyx_v_first;
1228
int __pyx_r;
1229
__Pyx_RefNannyDeclarations
1230
__Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
1231
{
1232
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_p,&__pyx_n_s_r,&__pyx_n_s_first,0};
1233
PyObject* values[3] = {0,0,0};
1234
if (unlikely(__pyx_kwds)) {
1235
Py_ssize_t kw_args;
1236
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
1237
switch (pos_args) {
1238
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
1239
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
1240
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
1241
case 0: break;
1242
default: goto __pyx_L5_argtuple_error;
1243
}
1244
kw_args = PyDict_Size(__pyx_kwds);
1245
switch (pos_args) {
1246
case 0:
1247
if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_p)) != 0)) kw_args--;
1248
else goto __pyx_L5_argtuple_error;
1249
case 1:
1250
if (kw_args > 0) {
1251
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_r);
1252
if (value) { values[1] = value; kw_args--; }
1253
}
1254
case 2:
1255
if (kw_args > 0) {
1256
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_first);
1257
if (value) { values[2] = value; kw_args--; }
1258
}
1259
}
1260
if (unlikely(kw_args > 0)) {
1261
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 95, __pyx_L3_error)
1262
}
1263
} else {
1264
switch (PyTuple_GET_SIZE(__pyx_args)) {
1265
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
1266
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
1267
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
1268
break;
1269
default: goto __pyx_L5_argtuple_error;
1270
}
1271
}
1272
__pyx_v_p = values[0];
1273
if (values[1]) {
1274
__pyx_v_r = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v_r == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 95, __pyx_L3_error)
1275
} else {
1276
__pyx_v_r = ((long)0);
1277
}
1278
if (values[2]) {
1279
__pyx_v_first = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_first == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 95, __pyx_L3_error)
1280
} else {
1281
__pyx_v_first = ((int)1);
1282
}
1283
}
1284
goto __pyx_L4_argument_unpacking_done;
1285
__pyx_L5_argtuple_error:;
1286
__Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 95, __pyx_L3_error)
1287
__pyx_L3_error:;
1288
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.Prime.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
1289
__Pyx_RefNannyFinishContext();
1290
return -1;
1291
__pyx_L4_argument_unpacking_done:;
1292
__pyx_r = __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime___init__(((struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_v_self), __pyx_v_p, __pyx_v_r, __pyx_v_first);
1293
1294
/* function exit code */
1295
__Pyx_RefNannyFinishContext();
1296
return __pyx_r;
1297
}
1298
1299
static int __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime___init__(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self, PyObject *__pyx_v_p, long __pyx_v_r, int __pyx_v_first) {
1300
long __pyx_v_t;
1301
long __pyx_v_r1;
1302
PyObject *__pyx_v_H = NULL;
1303
int __pyx_r;
1304
__Pyx_RefNannyDeclarations
1305
PyObject *__pyx_t_1 = NULL;
1306
int __pyx_t_2;
1307
int __pyx_t_3;
1308
PyObject *__pyx_t_4 = NULL;
1309
PyObject *__pyx_t_5 = NULL;
1310
long __pyx_t_6;
1311
__Pyx_RefNannySetupContext("__init__", 0);
1312
1313
/* "code/psage/number_fields/sqrt5/prime.pyx":148
1314
* """
1315
* cdef long t, r1
1316
* if isinstance(p, NumberFieldFractionalIdeal): # <<<<<<<<<<<<<<
1317
* # Set self using a prime ideal of Q(sqrt(5)).
1318
* H = p.pari_hnf()
1319
*/
1320
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_NumberFieldFractionalIdeal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error)
1321
__Pyx_GOTREF(__pyx_t_1);
1322
__pyx_t_2 = PyObject_IsInstance(__pyx_v_p, __pyx_t_1); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(0, 148, __pyx_L1_error)
1323
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1324
__pyx_t_3 = (__pyx_t_2 != 0);
1325
if (__pyx_t_3) {
1326
1327
/* "code/psage/number_fields/sqrt5/prime.pyx":150
1328
* if isinstance(p, NumberFieldFractionalIdeal):
1329
* # Set self using a prime ideal of Q(sqrt(5)).
1330
* H = p.pari_hnf() # <<<<<<<<<<<<<<
1331
* self.p = H[0,0]
1332
* self.first = True
1333
*/
1334
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_p, __pyx_n_s_pari_hnf); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 150, __pyx_L1_error)
1335
__Pyx_GOTREF(__pyx_t_4);
1336
__pyx_t_5 = NULL;
1337
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
1338
__pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
1339
if (likely(__pyx_t_5)) {
1340
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
1341
__Pyx_INCREF(__pyx_t_5);
1342
__Pyx_INCREF(function);
1343
__Pyx_DECREF_SET(__pyx_t_4, function);
1344
}
1345
}
1346
if (__pyx_t_5) {
1347
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 150, __pyx_L1_error)
1348
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
1349
} else {
1350
__pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 150, __pyx_L1_error)
1351
}
1352
__Pyx_GOTREF(__pyx_t_1);
1353
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
1354
__pyx_v_H = __pyx_t_1;
1355
__pyx_t_1 = 0;
1356
1357
/* "code/psage/number_fields/sqrt5/prime.pyx":151
1358
* # Set self using a prime ideal of Q(sqrt(5)).
1359
* H = p.pari_hnf()
1360
* self.p = H[0,0] # <<<<<<<<<<<<<<
1361
* self.first = True
1362
* t = self.p % 5
1363
*/
1364
__pyx_t_1 = PyObject_GetItem(__pyx_v_H, __pyx_tuple_); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 151, __pyx_L1_error)
1365
__Pyx_GOTREF(__pyx_t_1);
1366
__pyx_t_6 = __Pyx_PyInt_As_long(__pyx_t_1); if (unlikely((__pyx_t_6 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 151, __pyx_L1_error)
1367
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1368
__pyx_v_self->p = __pyx_t_6;
1369
1370
/* "code/psage/number_fields/sqrt5/prime.pyx":152
1371
* H = p.pari_hnf()
1372
* self.p = H[0,0]
1373
* self.first = True # <<<<<<<<<<<<<<
1374
* t = self.p % 5
1375
* if t == 1 or t == 4:
1376
*/
1377
__pyx_v_self->first = 1;
1378
1379
/* "code/psage/number_fields/sqrt5/prime.pyx":153
1380
* self.p = H[0,0]
1381
* self.first = True
1382
* t = self.p % 5 # <<<<<<<<<<<<<<
1383
* if t == 1 or t == 4:
1384
* self.r = self.p - H[0,1]
1385
*/
1386
__pyx_v_t = __Pyx_mod_long(__pyx_v_self->p, 5);
1387
1388
/* "code/psage/number_fields/sqrt5/prime.pyx":154
1389
* self.first = True
1390
* t = self.p % 5
1391
* if t == 1 or t == 4: # <<<<<<<<<<<<<<
1392
* self.r = self.p - H[0,1]
1393
* r1 = self.p + 1 - self.r
1394
*/
1395
switch (__pyx_v_t) {
1396
case 1:
1397
case 4:
1398
1399
/* "code/psage/number_fields/sqrt5/prime.pyx":155
1400
* t = self.p % 5
1401
* if t == 1 or t == 4:
1402
* self.r = self.p - H[0,1] # <<<<<<<<<<<<<<
1403
* r1 = self.p + 1 - self.r
1404
* if self.r > r1:
1405
*/
1406
__pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_self->p); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 155, __pyx_L1_error)
1407
__Pyx_GOTREF(__pyx_t_1);
1408
__pyx_t_4 = PyObject_GetItem(__pyx_v_H, __pyx_tuple__2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 155, __pyx_L1_error)
1409
__Pyx_GOTREF(__pyx_t_4);
1410
__pyx_t_5 = PyNumber_Subtract(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 155, __pyx_L1_error)
1411
__Pyx_GOTREF(__pyx_t_5);
1412
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1413
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
1414
__pyx_t_6 = __Pyx_PyInt_As_long(__pyx_t_5); if (unlikely((__pyx_t_6 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 155, __pyx_L1_error)
1415
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
1416
__pyx_v_self->r = __pyx_t_6;
1417
1418
/* "code/psage/number_fields/sqrt5/prime.pyx":156
1419
* if t == 1 or t == 4:
1420
* self.r = self.p - H[0,1]
1421
* r1 = self.p + 1 - self.r # <<<<<<<<<<<<<<
1422
* if self.r > r1:
1423
* self.first = False
1424
*/
1425
__pyx_v_r1 = ((__pyx_v_self->p + 1) - __pyx_v_self->r);
1426
1427
/* "code/psage/number_fields/sqrt5/prime.pyx":157
1428
* self.r = self.p - H[0,1]
1429
* r1 = self.p + 1 - self.r
1430
* if self.r > r1: # <<<<<<<<<<<<<<
1431
* self.first = False
1432
* elif t == 0:
1433
*/
1434
__pyx_t_3 = ((__pyx_v_self->r > __pyx_v_r1) != 0);
1435
if (__pyx_t_3) {
1436
1437
/* "code/psage/number_fields/sqrt5/prime.pyx":158
1438
* r1 = self.p + 1 - self.r
1439
* if self.r > r1:
1440
* self.first = False # <<<<<<<<<<<<<<
1441
* elif t == 0:
1442
* self.r = 3
1443
*/
1444
__pyx_v_self->first = 0;
1445
1446
/* "code/psage/number_fields/sqrt5/prime.pyx":157
1447
* self.r = self.p - H[0,1]
1448
* r1 = self.p + 1 - self.r
1449
* if self.r > r1: # <<<<<<<<<<<<<<
1450
* self.first = False
1451
* elif t == 0:
1452
*/
1453
}
1454
1455
/* "code/psage/number_fields/sqrt5/prime.pyx":154
1456
* self.first = True
1457
* t = self.p % 5
1458
* if t == 1 or t == 4: # <<<<<<<<<<<<<<
1459
* self.r = self.p - H[0,1]
1460
* r1 = self.p + 1 - self.r
1461
*/
1462
break;
1463
1464
/* "code/psage/number_fields/sqrt5/prime.pyx":159
1465
* if self.r > r1:
1466
* self.first = False
1467
* elif t == 0: # <<<<<<<<<<<<<<
1468
* self.r = 3
1469
* else:
1470
*/
1471
case 0:
1472
1473
/* "code/psage/number_fields/sqrt5/prime.pyx":160
1474
* self.first = False
1475
* elif t == 0:
1476
* self.r = 3 # <<<<<<<<<<<<<<
1477
* else:
1478
* self.r = 0
1479
*/
1480
__pyx_v_self->r = 3;
1481
1482
/* "code/psage/number_fields/sqrt5/prime.pyx":159
1483
* if self.r > r1:
1484
* self.first = False
1485
* elif t == 0: # <<<<<<<<<<<<<<
1486
* self.r = 3
1487
* else:
1488
*/
1489
break;
1490
default:
1491
1492
/* "code/psage/number_fields/sqrt5/prime.pyx":162
1493
* self.r = 3
1494
* else:
1495
* self.r = 0 # <<<<<<<<<<<<<<
1496
* else:
1497
* self.p = p
1498
*/
1499
__pyx_v_self->r = 0;
1500
break;
1501
}
1502
1503
/* "code/psage/number_fields/sqrt5/prime.pyx":148
1504
* """
1505
* cdef long t, r1
1506
* if isinstance(p, NumberFieldFractionalIdeal): # <<<<<<<<<<<<<<
1507
* # Set self using a prime ideal of Q(sqrt(5)).
1508
* H = p.pari_hnf()
1509
*/
1510
goto __pyx_L3;
1511
}
1512
1513
/* "code/psage/number_fields/sqrt5/prime.pyx":164
1514
* self.r = 0
1515
* else:
1516
* self.p = p # <<<<<<<<<<<<<<
1517
* self.r = r
1518
* self.first = first
1519
*/
1520
/*else*/ {
1521
__pyx_t_6 = __Pyx_PyInt_As_long(__pyx_v_p); if (unlikely((__pyx_t_6 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 164, __pyx_L1_error)
1522
__pyx_v_self->p = __pyx_t_6;
1523
1524
/* "code/psage/number_fields/sqrt5/prime.pyx":165
1525
* else:
1526
* self.p = p
1527
* self.r = r # <<<<<<<<<<<<<<
1528
* self.first = first
1529
*
1530
*/
1531
__pyx_v_self->r = __pyx_v_r;
1532
1533
/* "code/psage/number_fields/sqrt5/prime.pyx":166
1534
* self.p = p
1535
* self.r = r
1536
* self.first = first # <<<<<<<<<<<<<<
1537
*
1538
* def __repr__(self):
1539
*/
1540
__pyx_v_self->first = __pyx_v_first;
1541
}
1542
__pyx_L3:;
1543
1544
/* "code/psage/number_fields/sqrt5/prime.pyx":95
1545
* # cpdef bint is_inert(self)
1546
* # cpdef bint is_ramified(self)
1547
* def __init__(self, p, long r=0, bint first=True): # <<<<<<<<<<<<<<
1548
* """
1549
* Create Prime ideal with given residue characteristic, root,
1550
*/
1551
1552
/* function exit code */
1553
__pyx_r = 0;
1554
goto __pyx_L0;
1555
__pyx_L1_error:;
1556
__Pyx_XDECREF(__pyx_t_1);
1557
__Pyx_XDECREF(__pyx_t_4);
1558
__Pyx_XDECREF(__pyx_t_5);
1559
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.Prime.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
1560
__pyx_r = -1;
1561
__pyx_L0:;
1562
__Pyx_XDECREF(__pyx_v_H);
1563
__Pyx_RefNannyFinishContext();
1564
return __pyx_r;
1565
}
1566
1567
/* "code/psage/number_fields/sqrt5/prime.pyx":168
1568
* self.first = first
1569
*
1570
* def __repr__(self): # <<<<<<<<<<<<<<
1571
* """
1572
* EXAMPLES::
1573
*/
1574
1575
/* Python wrapper */
1576
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_3__repr__(PyObject *__pyx_v_self); /*proto*/
1577
static char __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_2__repr__[] = "\n EXAMPLES::\n \n sage: from psage.number_fields.sqrt5.prime import Prime\n sage: Prime(11,4,False).__repr__()\n '11b'\n sage: Prime(11,4,True).__repr__()\n '11a'\n sage: Prime(7,0,True).__repr__()\n '7'\n ";
1578
#if CYTHON_COMPILING_IN_CPYTHON
1579
struct wrapperbase __pyx_wrapperbase_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_2__repr__;
1580
#endif
1581
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_3__repr__(PyObject *__pyx_v_self) {
1582
PyObject *__pyx_r = 0;
1583
__Pyx_RefNannyDeclarations
1584
__Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
1585
__pyx_r = __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_2__repr__(((struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_v_self));
1586
1587
/* function exit code */
1588
__Pyx_RefNannyFinishContext();
1589
return __pyx_r;
1590
}
1591
1592
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_2__repr__(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self) {
1593
PyObject *__pyx_r = NULL;
1594
__Pyx_RefNannyDeclarations
1595
int __pyx_t_1;
1596
PyObject *__pyx_t_2 = NULL;
1597
PyObject *__pyx_t_3 = NULL;
1598
PyObject *__pyx_t_4 = NULL;
1599
__Pyx_RefNannySetupContext("__repr__", 0);
1600
1601
/* "code/psage/number_fields/sqrt5/prime.pyx":180
1602
* '7'
1603
* """
1604
* if self.r: # <<<<<<<<<<<<<<
1605
* return '%s%s'%(self.p, 'a' if self.first else 'b')
1606
* return '%s'%self.p
1607
*/
1608
__pyx_t_1 = (__pyx_v_self->r != 0);
1609
if (__pyx_t_1) {
1610
1611
/* "code/psage/number_fields/sqrt5/prime.pyx":181
1612
* """
1613
* if self.r:
1614
* return '%s%s'%(self.p, 'a' if self.first else 'b') # <<<<<<<<<<<<<<
1615
* return '%s'%self.p
1616
*
1617
*/
1618
__Pyx_XDECREF(__pyx_r);
1619
__pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_self->p); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 181, __pyx_L1_error)
1620
__Pyx_GOTREF(__pyx_t_2);
1621
if ((__pyx_v_self->first != 0)) {
1622
__Pyx_INCREF(__pyx_n_s_a);
1623
__pyx_t_3 = __pyx_n_s_a;
1624
} else {
1625
__Pyx_INCREF(__pyx_n_s_b);
1626
__pyx_t_3 = __pyx_n_s_b;
1627
}
1628
__pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 181, __pyx_L1_error)
1629
__Pyx_GOTREF(__pyx_t_4);
1630
__Pyx_GIVEREF(__pyx_t_2);
1631
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
1632
__Pyx_GIVEREF(__pyx_t_3);
1633
PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
1634
__pyx_t_2 = 0;
1635
__pyx_t_3 = 0;
1636
__pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 181, __pyx_L1_error)
1637
__Pyx_GOTREF(__pyx_t_3);
1638
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
1639
__pyx_r = __pyx_t_3;
1640
__pyx_t_3 = 0;
1641
goto __pyx_L0;
1642
1643
/* "code/psage/number_fields/sqrt5/prime.pyx":180
1644
* '7'
1645
* """
1646
* if self.r: # <<<<<<<<<<<<<<
1647
* return '%s%s'%(self.p, 'a' if self.first else 'b')
1648
* return '%s'%self.p
1649
*/
1650
}
1651
1652
/* "code/psage/number_fields/sqrt5/prime.pyx":182
1653
* if self.r:
1654
* return '%s%s'%(self.p, 'a' if self.first else 'b')
1655
* return '%s'%self.p # <<<<<<<<<<<<<<
1656
*
1657
* def __hash__(self):
1658
*/
1659
__Pyx_XDECREF(__pyx_r);
1660
__pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_self->p); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 182, __pyx_L1_error)
1661
__Pyx_GOTREF(__pyx_t_3);
1662
__pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_s, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 182, __pyx_L1_error)
1663
__Pyx_GOTREF(__pyx_t_4);
1664
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1665
__pyx_r = __pyx_t_4;
1666
__pyx_t_4 = 0;
1667
goto __pyx_L0;
1668
1669
/* "code/psage/number_fields/sqrt5/prime.pyx":168
1670
* self.first = first
1671
*
1672
* def __repr__(self): # <<<<<<<<<<<<<<
1673
* """
1674
* EXAMPLES::
1675
*/
1676
1677
/* function exit code */
1678
__pyx_L1_error:;
1679
__Pyx_XDECREF(__pyx_t_2);
1680
__Pyx_XDECREF(__pyx_t_3);
1681
__Pyx_XDECREF(__pyx_t_4);
1682
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.Prime.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
1683
__pyx_r = NULL;
1684
__pyx_L0:;
1685
__Pyx_XGIVEREF(__pyx_r);
1686
__Pyx_RefNannyFinishContext();
1687
return __pyx_r;
1688
}
1689
1690
/* "code/psage/number_fields/sqrt5/prime.pyx":184
1691
* return '%s'%self.p
1692
*
1693
* def __hash__(self): # <<<<<<<<<<<<<<
1694
* return self.p*(self.r+1) + int(self.first)
1695
*
1696
*/
1697
1698
/* Python wrapper */
1699
static Py_hash_t __pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_5__hash__(PyObject *__pyx_v_self); /*proto*/
1700
static Py_hash_t __pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_5__hash__(PyObject *__pyx_v_self) {
1701
Py_hash_t __pyx_r;
1702
__Pyx_RefNannyDeclarations
1703
__Pyx_RefNannySetupContext("__hash__ (wrapper)", 0);
1704
__pyx_r = __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_4__hash__(((struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_v_self));
1705
1706
/* function exit code */
1707
__Pyx_RefNannyFinishContext();
1708
return __pyx_r;
1709
}
1710
1711
static Py_hash_t __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_4__hash__(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self) {
1712
Py_hash_t __pyx_r;
1713
__Pyx_RefNannyDeclarations
1714
PyObject *__pyx_t_1 = NULL;
1715
PyObject *__pyx_t_2 = NULL;
1716
PyObject *__pyx_t_3 = NULL;
1717
Py_hash_t __pyx_t_4;
1718
__Pyx_RefNannySetupContext("__hash__", 0);
1719
1720
/* "code/psage/number_fields/sqrt5/prime.pyx":185
1721
*
1722
* def __hash__(self):
1723
* return self.p*(self.r+1) + int(self.first) # <<<<<<<<<<<<<<
1724
*
1725
* def _latex_(self):
1726
*/
1727
__pyx_t_1 = __Pyx_PyInt_From_long((__pyx_v_self->p * (__pyx_v_self->r + 1))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 185, __pyx_L1_error)
1728
__Pyx_GOTREF(__pyx_t_1);
1729
__pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_self->first); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 185, __pyx_L1_error)
1730
__Pyx_GOTREF(__pyx_t_2);
1731
__pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 185, __pyx_L1_error)
1732
__Pyx_GOTREF(__pyx_t_3);
1733
__Pyx_GIVEREF(__pyx_t_2);
1734
PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
1735
__pyx_t_2 = 0;
1736
__pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)(&PyInt_Type)), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 185, __pyx_L1_error)
1737
__Pyx_GOTREF(__pyx_t_2);
1738
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1739
__pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 185, __pyx_L1_error)
1740
__Pyx_GOTREF(__pyx_t_3);
1741
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1742
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
1743
__pyx_t_4 = __Pyx_PyInt_AsHash_t(__pyx_t_3); if (unlikely((__pyx_t_4 == (Py_hash_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 185, __pyx_L1_error)
1744
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1745
__pyx_r = __pyx_t_4;
1746
goto __pyx_L0;
1747
1748
/* "code/psage/number_fields/sqrt5/prime.pyx":184
1749
* return '%s'%self.p
1750
*
1751
* def __hash__(self): # <<<<<<<<<<<<<<
1752
* return self.p*(self.r+1) + int(self.first)
1753
*
1754
*/
1755
1756
/* function exit code */
1757
__pyx_L1_error:;
1758
__Pyx_XDECREF(__pyx_t_1);
1759
__Pyx_XDECREF(__pyx_t_2);
1760
__Pyx_XDECREF(__pyx_t_3);
1761
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.Prime.__hash__", __pyx_clineno, __pyx_lineno, __pyx_filename);
1762
__pyx_r = -1;
1763
__pyx_L0:;
1764
if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2;
1765
__Pyx_RefNannyFinishContext();
1766
return __pyx_r;
1767
}
1768
1769
/* "code/psage/number_fields/sqrt5/prime.pyx":187
1770
* return self.p*(self.r+1) + int(self.first)
1771
*
1772
* def _latex_(self): # <<<<<<<<<<<<<<
1773
* """
1774
* EXAMPLES::
1775
*/
1776
1777
/* Python wrapper */
1778
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_7_latex_(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
1779
static char __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_6_latex_[] = "\n EXAMPLES::\n\n sage: from psage.number_fields.sqrt5.prime import Prime\n sage: Prime(11,8,True)._latex_()\n '11a'\n sage: Prime(11,4,False)._latex_()\n '11b'\n ";
1780
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_7_latex_(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
1781
PyObject *__pyx_r = 0;
1782
__Pyx_RefNannyDeclarations
1783
__Pyx_RefNannySetupContext("_latex_ (wrapper)", 0);
1784
__pyx_r = __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_6_latex_(((struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_v_self));
1785
1786
/* function exit code */
1787
__Pyx_RefNannyFinishContext();
1788
return __pyx_r;
1789
}
1790
1791
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_6_latex_(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self) {
1792
PyObject *__pyx_r = NULL;
1793
__Pyx_RefNannyDeclarations
1794
PyObject *__pyx_t_1 = NULL;
1795
PyObject *__pyx_t_2 = NULL;
1796
PyObject *__pyx_t_3 = NULL;
1797
__Pyx_RefNannySetupContext("_latex_", 0);
1798
1799
/* "code/psage/number_fields/sqrt5/prime.pyx":197
1800
* '11b'
1801
* """
1802
* return self.__repr__() # <<<<<<<<<<<<<<
1803
*
1804
* cpdef bint is_split(self):
1805
*/
1806
__Pyx_XDECREF(__pyx_r);
1807
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_repr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 197, __pyx_L1_error)
1808
__Pyx_GOTREF(__pyx_t_2);
1809
__pyx_t_3 = NULL;
1810
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
1811
__pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
1812
if (likely(__pyx_t_3)) {
1813
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
1814
__Pyx_INCREF(__pyx_t_3);
1815
__Pyx_INCREF(function);
1816
__Pyx_DECREF_SET(__pyx_t_2, function);
1817
}
1818
}
1819
if (__pyx_t_3) {
1820
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 197, __pyx_L1_error)
1821
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1822
} else {
1823
__pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 197, __pyx_L1_error)
1824
}
1825
__Pyx_GOTREF(__pyx_t_1);
1826
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
1827
__pyx_r = __pyx_t_1;
1828
__pyx_t_1 = 0;
1829
goto __pyx_L0;
1830
1831
/* "code/psage/number_fields/sqrt5/prime.pyx":187
1832
* return self.p*(self.r+1) + int(self.first)
1833
*
1834
* def _latex_(self): # <<<<<<<<<<<<<<
1835
* """
1836
* EXAMPLES::
1837
*/
1838
1839
/* function exit code */
1840
__pyx_L1_error:;
1841
__Pyx_XDECREF(__pyx_t_1);
1842
__Pyx_XDECREF(__pyx_t_2);
1843
__Pyx_XDECREF(__pyx_t_3);
1844
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.Prime._latex_", __pyx_clineno, __pyx_lineno, __pyx_filename);
1845
__pyx_r = NULL;
1846
__pyx_L0:;
1847
__Pyx_XGIVEREF(__pyx_r);
1848
__Pyx_RefNannyFinishContext();
1849
return __pyx_r;
1850
}
1851
1852
/* "code/psage/number_fields/sqrt5/prime.pyx":199
1853
* return self.__repr__()
1854
*
1855
* cpdef bint is_split(self): # <<<<<<<<<<<<<<
1856
* """
1857
* Return True if this prime is split (and not ramified).
1858
*/
1859
1860
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_9is_split(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
1861
static int __pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_is_split(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self, int __pyx_skip_dispatch) {
1862
int __pyx_r;
1863
__Pyx_RefNannyDeclarations
1864
PyObject *__pyx_t_1 = NULL;
1865
PyObject *__pyx_t_2 = NULL;
1866
PyObject *__pyx_t_3 = NULL;
1867
PyObject *__pyx_t_4 = NULL;
1868
int __pyx_t_5;
1869
int __pyx_t_6;
1870
__Pyx_RefNannySetupContext("is_split", 0);
1871
/* Check if called by wrapper */
1872
if (unlikely(__pyx_skip_dispatch)) ;
1873
/* Check if overridden in Python */
1874
else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
1875
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_split); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 199, __pyx_L1_error)
1876
__Pyx_GOTREF(__pyx_t_1);
1877
if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_9is_split)) {
1878
__Pyx_INCREF(__pyx_t_1);
1879
__pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
1880
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
1881
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
1882
if (likely(__pyx_t_4)) {
1883
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
1884
__Pyx_INCREF(__pyx_t_4);
1885
__Pyx_INCREF(function);
1886
__Pyx_DECREF_SET(__pyx_t_3, function);
1887
}
1888
}
1889
if (__pyx_t_4) {
1890
__pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 199, __pyx_L1_error)
1891
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
1892
} else {
1893
__pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 199, __pyx_L1_error)
1894
}
1895
__Pyx_GOTREF(__pyx_t_2);
1896
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1897
__pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 199, __pyx_L1_error)
1898
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
1899
__pyx_r = __pyx_t_5;
1900
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1901
goto __pyx_L0;
1902
}
1903
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
1904
}
1905
1906
/* "code/psage/number_fields/sqrt5/prime.pyx":213
1907
* False
1908
* """
1909
* return self.r != 0 and self.p != 5 # <<<<<<<<<<<<<<
1910
*
1911
* cpdef bint is_inert(self):
1912
*/
1913
__pyx_t_6 = ((__pyx_v_self->r != 0) != 0);
1914
if (__pyx_t_6) {
1915
} else {
1916
__pyx_t_5 = __pyx_t_6;
1917
goto __pyx_L3_bool_binop_done;
1918
}
1919
__pyx_t_6 = ((__pyx_v_self->p != 5) != 0);
1920
__pyx_t_5 = __pyx_t_6;
1921
__pyx_L3_bool_binop_done:;
1922
__pyx_r = __pyx_t_5;
1923
goto __pyx_L0;
1924
1925
/* "code/psage/number_fields/sqrt5/prime.pyx":199
1926
* return self.__repr__()
1927
*
1928
* cpdef bint is_split(self): # <<<<<<<<<<<<<<
1929
* """
1930
* Return True if this prime is split (and not ramified).
1931
*/
1932
1933
/* function exit code */
1934
__pyx_L1_error:;
1935
__Pyx_XDECREF(__pyx_t_1);
1936
__Pyx_XDECREF(__pyx_t_2);
1937
__Pyx_XDECREF(__pyx_t_3);
1938
__Pyx_XDECREF(__pyx_t_4);
1939
__Pyx_WriteUnraisable("code.psage.number_fields.sqrt5.prime.Prime.is_split", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
1940
__pyx_r = 0;
1941
__pyx_L0:;
1942
__Pyx_RefNannyFinishContext();
1943
return __pyx_r;
1944
}
1945
1946
/* Python wrapper */
1947
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_9is_split(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
1948
static char __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_8is_split[] = "\n Return True if this prime is split (and not ramified).\n \n EXAMPLES::\n\n sage: from psage.number_fields.sqrt5.prime import Prime\n sage: Prime(11,8,True).is_split()\n True\n sage: Prime(3,0,True).is_split()\n False\n sage: Prime(5,3,True).is_split()\n False\n ";
1949
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_9is_split(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
1950
PyObject *__pyx_r = 0;
1951
__Pyx_RefNannyDeclarations
1952
__Pyx_RefNannySetupContext("is_split (wrapper)", 0);
1953
__pyx_r = __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_8is_split(((struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_v_self));
1954
1955
/* function exit code */
1956
__Pyx_RefNannyFinishContext();
1957
return __pyx_r;
1958
}
1959
1960
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_8is_split(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self) {
1961
PyObject *__pyx_r = NULL;
1962
__Pyx_RefNannyDeclarations
1963
PyObject *__pyx_t_1 = NULL;
1964
__Pyx_RefNannySetupContext("is_split", 0);
1965
__Pyx_XDECREF(__pyx_r);
1966
__pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_is_split(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 199, __pyx_L1_error)
1967
__Pyx_GOTREF(__pyx_t_1);
1968
__pyx_r = __pyx_t_1;
1969
__pyx_t_1 = 0;
1970
goto __pyx_L0;
1971
1972
/* function exit code */
1973
__pyx_L1_error:;
1974
__Pyx_XDECREF(__pyx_t_1);
1975
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.Prime.is_split", __pyx_clineno, __pyx_lineno, __pyx_filename);
1976
__pyx_r = NULL;
1977
__pyx_L0:;
1978
__Pyx_XGIVEREF(__pyx_r);
1979
__Pyx_RefNannyFinishContext();
1980
return __pyx_r;
1981
}
1982
1983
/* "code/psage/number_fields/sqrt5/prime.pyx":215
1984
* return self.r != 0 and self.p != 5
1985
*
1986
* cpdef bint is_inert(self): # <<<<<<<<<<<<<<
1987
* """
1988
* Return True if this prime is inert.
1989
*/
1990
1991
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_11is_inert(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
1992
static int __pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_is_inert(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self, int __pyx_skip_dispatch) {
1993
int __pyx_r;
1994
__Pyx_RefNannyDeclarations
1995
PyObject *__pyx_t_1 = NULL;
1996
PyObject *__pyx_t_2 = NULL;
1997
PyObject *__pyx_t_3 = NULL;
1998
PyObject *__pyx_t_4 = NULL;
1999
int __pyx_t_5;
2000
__Pyx_RefNannySetupContext("is_inert", 0);
2001
/* Check if called by wrapper */
2002
if (unlikely(__pyx_skip_dispatch)) ;
2003
/* Check if overridden in Python */
2004
else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
2005
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_inert); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 215, __pyx_L1_error)
2006
__Pyx_GOTREF(__pyx_t_1);
2007
if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_11is_inert)) {
2008
__Pyx_INCREF(__pyx_t_1);
2009
__pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
2010
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
2011
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
2012
if (likely(__pyx_t_4)) {
2013
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
2014
__Pyx_INCREF(__pyx_t_4);
2015
__Pyx_INCREF(function);
2016
__Pyx_DECREF_SET(__pyx_t_3, function);
2017
}
2018
}
2019
if (__pyx_t_4) {
2020
__pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 215, __pyx_L1_error)
2021
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
2022
} else {
2023
__pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 215, __pyx_L1_error)
2024
}
2025
__Pyx_GOTREF(__pyx_t_2);
2026
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2027
__pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 215, __pyx_L1_error)
2028
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2029
__pyx_r = __pyx_t_5;
2030
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2031
goto __pyx_L0;
2032
}
2033
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2034
}
2035
2036
/* "code/psage/number_fields/sqrt5/prime.pyx":229
2037
* False
2038
* """
2039
* return self.r == 0 # <<<<<<<<<<<<<<
2040
*
2041
* cpdef bint is_ramified(self):
2042
*/
2043
__pyx_r = (__pyx_v_self->r == 0);
2044
goto __pyx_L0;
2045
2046
/* "code/psage/number_fields/sqrt5/prime.pyx":215
2047
* return self.r != 0 and self.p != 5
2048
*
2049
* cpdef bint is_inert(self): # <<<<<<<<<<<<<<
2050
* """
2051
* Return True if this prime is inert.
2052
*/
2053
2054
/* function exit code */
2055
__pyx_L1_error:;
2056
__Pyx_XDECREF(__pyx_t_1);
2057
__Pyx_XDECREF(__pyx_t_2);
2058
__Pyx_XDECREF(__pyx_t_3);
2059
__Pyx_XDECREF(__pyx_t_4);
2060
__Pyx_WriteUnraisable("code.psage.number_fields.sqrt5.prime.Prime.is_inert", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
2061
__pyx_r = 0;
2062
__pyx_L0:;
2063
__Pyx_RefNannyFinishContext();
2064
return __pyx_r;
2065
}
2066
2067
/* Python wrapper */
2068
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_11is_inert(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
2069
static char __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_10is_inert[] = "\n Return True if this prime is inert. \n\n EXAMPLES::\n\n sage: from psage.number_fields.sqrt5.prime import Prime\n sage: Prime(11,8,True).is_inert()\n False\n sage: Prime(3,0,True).is_inert()\n True\n sage: Prime(5,3,True).is_inert()\n False\n ";
2070
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_11is_inert(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
2071
PyObject *__pyx_r = 0;
2072
__Pyx_RefNannyDeclarations
2073
__Pyx_RefNannySetupContext("is_inert (wrapper)", 0);
2074
__pyx_r = __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_10is_inert(((struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_v_self));
2075
2076
/* function exit code */
2077
__Pyx_RefNannyFinishContext();
2078
return __pyx_r;
2079
}
2080
2081
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_10is_inert(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self) {
2082
PyObject *__pyx_r = NULL;
2083
__Pyx_RefNannyDeclarations
2084
PyObject *__pyx_t_1 = NULL;
2085
__Pyx_RefNannySetupContext("is_inert", 0);
2086
__Pyx_XDECREF(__pyx_r);
2087
__pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_is_inert(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 215, __pyx_L1_error)
2088
__Pyx_GOTREF(__pyx_t_1);
2089
__pyx_r = __pyx_t_1;
2090
__pyx_t_1 = 0;
2091
goto __pyx_L0;
2092
2093
/* function exit code */
2094
__pyx_L1_error:;
2095
__Pyx_XDECREF(__pyx_t_1);
2096
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.Prime.is_inert", __pyx_clineno, __pyx_lineno, __pyx_filename);
2097
__pyx_r = NULL;
2098
__pyx_L0:;
2099
__Pyx_XGIVEREF(__pyx_r);
2100
__Pyx_RefNannyFinishContext();
2101
return __pyx_r;
2102
}
2103
2104
/* "code/psage/number_fields/sqrt5/prime.pyx":231
2105
* return self.r == 0
2106
*
2107
* cpdef bint is_ramified(self): # <<<<<<<<<<<<<<
2108
* """
2109
* Return True if this prime is ramified (i.e., the prime over 5).
2110
*/
2111
2112
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_13is_ramified(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
2113
static int __pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_is_ramified(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self, int __pyx_skip_dispatch) {
2114
int __pyx_r;
2115
__Pyx_RefNannyDeclarations
2116
PyObject *__pyx_t_1 = NULL;
2117
PyObject *__pyx_t_2 = NULL;
2118
PyObject *__pyx_t_3 = NULL;
2119
PyObject *__pyx_t_4 = NULL;
2120
int __pyx_t_5;
2121
__Pyx_RefNannySetupContext("is_ramified", 0);
2122
/* Check if called by wrapper */
2123
if (unlikely(__pyx_skip_dispatch)) ;
2124
/* Check if overridden in Python */
2125
else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
2126
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_ramified); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 231, __pyx_L1_error)
2127
__Pyx_GOTREF(__pyx_t_1);
2128
if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_13is_ramified)) {
2129
__Pyx_INCREF(__pyx_t_1);
2130
__pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
2131
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
2132
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
2133
if (likely(__pyx_t_4)) {
2134
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
2135
__Pyx_INCREF(__pyx_t_4);
2136
__Pyx_INCREF(function);
2137
__Pyx_DECREF_SET(__pyx_t_3, function);
2138
}
2139
}
2140
if (__pyx_t_4) {
2141
__pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 231, __pyx_L1_error)
2142
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
2143
} else {
2144
__pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 231, __pyx_L1_error)
2145
}
2146
__Pyx_GOTREF(__pyx_t_2);
2147
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2148
__pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 231, __pyx_L1_error)
2149
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2150
__pyx_r = __pyx_t_5;
2151
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2152
goto __pyx_L0;
2153
}
2154
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2155
}
2156
2157
/* "code/psage/number_fields/sqrt5/prime.pyx":245
2158
* True
2159
* """
2160
* return self.p == 5 # <<<<<<<<<<<<<<
2161
*
2162
* cpdef long norm(self):
2163
*/
2164
__pyx_r = (__pyx_v_self->p == 5);
2165
goto __pyx_L0;
2166
2167
/* "code/psage/number_fields/sqrt5/prime.pyx":231
2168
* return self.r == 0
2169
*
2170
* cpdef bint is_ramified(self): # <<<<<<<<<<<<<<
2171
* """
2172
* Return True if this prime is ramified (i.e., the prime over 5).
2173
*/
2174
2175
/* function exit code */
2176
__pyx_L1_error:;
2177
__Pyx_XDECREF(__pyx_t_1);
2178
__Pyx_XDECREF(__pyx_t_2);
2179
__Pyx_XDECREF(__pyx_t_3);
2180
__Pyx_XDECREF(__pyx_t_4);
2181
__Pyx_WriteUnraisable("code.psage.number_fields.sqrt5.prime.Prime.is_ramified", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
2182
__pyx_r = 0;
2183
__pyx_L0:;
2184
__Pyx_RefNannyFinishContext();
2185
return __pyx_r;
2186
}
2187
2188
/* Python wrapper */
2189
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_13is_ramified(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
2190
static char __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_12is_ramified[] = "\n Return True if this prime is ramified (i.e., the prime over 5).\n \n EXAMPLES::\n\n sage: from psage.number_fields.sqrt5.prime import Prime\n sage: Prime(11,8,True).is_ramified()\n False\n sage: Prime(3,0,True).is_ramified()\n False\n sage: Prime(5,3,True).is_ramified()\n True\n ";
2191
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_13is_ramified(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
2192
PyObject *__pyx_r = 0;
2193
__Pyx_RefNannyDeclarations
2194
__Pyx_RefNannySetupContext("is_ramified (wrapper)", 0);
2195
__pyx_r = __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_12is_ramified(((struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_v_self));
2196
2197
/* function exit code */
2198
__Pyx_RefNannyFinishContext();
2199
return __pyx_r;
2200
}
2201
2202
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_12is_ramified(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self) {
2203
PyObject *__pyx_r = NULL;
2204
__Pyx_RefNannyDeclarations
2205
PyObject *__pyx_t_1 = NULL;
2206
__Pyx_RefNannySetupContext("is_ramified", 0);
2207
__Pyx_XDECREF(__pyx_r);
2208
__pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_is_ramified(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 231, __pyx_L1_error)
2209
__Pyx_GOTREF(__pyx_t_1);
2210
__pyx_r = __pyx_t_1;
2211
__pyx_t_1 = 0;
2212
goto __pyx_L0;
2213
2214
/* function exit code */
2215
__pyx_L1_error:;
2216
__Pyx_XDECREF(__pyx_t_1);
2217
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.Prime.is_ramified", __pyx_clineno, __pyx_lineno, __pyx_filename);
2218
__pyx_r = NULL;
2219
__pyx_L0:;
2220
__Pyx_XGIVEREF(__pyx_r);
2221
__Pyx_RefNannyFinishContext();
2222
return __pyx_r;
2223
}
2224
2225
/* "code/psage/number_fields/sqrt5/prime.pyx":247
2226
* return self.p == 5
2227
*
2228
* cpdef long norm(self): # <<<<<<<<<<<<<<
2229
* """
2230
* Return the norm of this ideal.
2231
*/
2232
2233
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_15norm(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
2234
static long __pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_norm(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self, int __pyx_skip_dispatch) {
2235
long __pyx_r;
2236
__Pyx_RefNannyDeclarations
2237
PyObject *__pyx_t_1 = NULL;
2238
PyObject *__pyx_t_2 = NULL;
2239
PyObject *__pyx_t_3 = NULL;
2240
PyObject *__pyx_t_4 = NULL;
2241
long __pyx_t_5;
2242
__Pyx_RefNannySetupContext("norm", 0);
2243
/* Check if called by wrapper */
2244
if (unlikely(__pyx_skip_dispatch)) ;
2245
/* Check if overridden in Python */
2246
else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
2247
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_norm); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 247, __pyx_L1_error)
2248
__Pyx_GOTREF(__pyx_t_1);
2249
if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_15norm)) {
2250
__Pyx_INCREF(__pyx_t_1);
2251
__pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
2252
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
2253
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
2254
if (likely(__pyx_t_4)) {
2255
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
2256
__Pyx_INCREF(__pyx_t_4);
2257
__Pyx_INCREF(function);
2258
__Pyx_DECREF_SET(__pyx_t_3, function);
2259
}
2260
}
2261
if (__pyx_t_4) {
2262
__pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 247, __pyx_L1_error)
2263
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
2264
} else {
2265
__pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 247, __pyx_L1_error)
2266
}
2267
__Pyx_GOTREF(__pyx_t_2);
2268
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2269
__pyx_t_5 = __Pyx_PyInt_As_long(__pyx_t_2); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 247, __pyx_L1_error)
2270
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2271
__pyx_r = __pyx_t_5;
2272
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2273
goto __pyx_L0;
2274
}
2275
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2276
}
2277
2278
/* "code/psage/number_fields/sqrt5/prime.pyx":259
2279
* 49
2280
* """
2281
* return self.p if self.r else self.p*self.p # <<<<<<<<<<<<<<
2282
*
2283
* def __cmp__(self, Prime right):
2284
*/
2285
if ((__pyx_v_self->r != 0)) {
2286
__pyx_t_5 = __pyx_v_self->p;
2287
} else {
2288
__pyx_t_5 = (__pyx_v_self->p * __pyx_v_self->p);
2289
}
2290
__pyx_r = __pyx_t_5;
2291
goto __pyx_L0;
2292
2293
/* "code/psage/number_fields/sqrt5/prime.pyx":247
2294
* return self.p == 5
2295
*
2296
* cpdef long norm(self): # <<<<<<<<<<<<<<
2297
* """
2298
* Return the norm of this ideal.
2299
*/
2300
2301
/* function exit code */
2302
__pyx_L1_error:;
2303
__Pyx_XDECREF(__pyx_t_1);
2304
__Pyx_XDECREF(__pyx_t_2);
2305
__Pyx_XDECREF(__pyx_t_3);
2306
__Pyx_XDECREF(__pyx_t_4);
2307
__Pyx_WriteUnraisable("code.psage.number_fields.sqrt5.prime.Prime.norm", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
2308
__pyx_r = 0;
2309
__pyx_L0:;
2310
__Pyx_RefNannyFinishContext();
2311
return __pyx_r;
2312
}
2313
2314
/* Python wrapper */
2315
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_15norm(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
2316
static char __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_14norm[] = "\n Return the norm of this ideal.\n\n EXAMPLES::\n\n sage: from psage.number_fields.sqrt5.prime import Prime\n sage: Prime(11,4,True).norm()\n 11\n sage: Prime(7,0,True).norm()\n 49\n ";
2317
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_15norm(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
2318
PyObject *__pyx_r = 0;
2319
__Pyx_RefNannyDeclarations
2320
__Pyx_RefNannySetupContext("norm (wrapper)", 0);
2321
__pyx_r = __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_14norm(((struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_v_self));
2322
2323
/* function exit code */
2324
__Pyx_RefNannyFinishContext();
2325
return __pyx_r;
2326
}
2327
2328
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_14norm(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self) {
2329
PyObject *__pyx_r = NULL;
2330
__Pyx_RefNannyDeclarations
2331
PyObject *__pyx_t_1 = NULL;
2332
__Pyx_RefNannySetupContext("norm", 0);
2333
__Pyx_XDECREF(__pyx_r);
2334
__pyx_t_1 = __Pyx_PyInt_From_long(__pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_norm(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 247, __pyx_L1_error)
2335
__Pyx_GOTREF(__pyx_t_1);
2336
__pyx_r = __pyx_t_1;
2337
__pyx_t_1 = 0;
2338
goto __pyx_L0;
2339
2340
/* function exit code */
2341
__pyx_L1_error:;
2342
__Pyx_XDECREF(__pyx_t_1);
2343
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.Prime.norm", __pyx_clineno, __pyx_lineno, __pyx_filename);
2344
__pyx_r = NULL;
2345
__pyx_L0:;
2346
__Pyx_XGIVEREF(__pyx_r);
2347
__Pyx_RefNannyFinishContext();
2348
return __pyx_r;
2349
}
2350
2351
/* "code/psage/number_fields/sqrt5/prime.pyx":261
2352
* return self.p if self.r else self.p*self.p
2353
*
2354
* def __cmp__(self, Prime right): # <<<<<<<<<<<<<<
2355
* """
2356
* Compare two prime ideals. First sort by the norm, then in the
2357
*/
2358
2359
/* Python wrapper */
2360
#if PY_MAJOR_VERSION < 3
2361
static int __pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_17__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_right); /*proto*/
2362
static char __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_16__cmp__[] = "\n Compare two prime ideals. First sort by the norm, then in the\n (only remaining) split case if the norms are the same, compare\n the residue of (1+sqrt(5))/2 in the interval [0,p).\n\n WARNING: The ordering is NOT the same as the ordering of\n fractional ideals in Sage.\n\n EXAMPLES::\n\n sage: from psage.number_fields.sqrt5 import primes_of_bounded_norm\n sage: v = primes_of_bounded_norm(50); v\n [2, 5a, 3, 11a, 11b, 19a, 19b, 29a, 29b, 31a, 31b, 41a, 41b, 7]\n sage: v[3], v[4]\n (11a, 11b)\n sage: v[3] < v[4]\n True\n sage: v[4] > v[3]\n True\n\n We test the ordering a bit by sorting::\n \n sage: v.sort(); v\n [2, 5a, 3, 11a, 11b, 19a, 19b, 29a, 29b, 31a, 31b, 41a, 41b, 7]\n sage: v = list(reversed(v)); v\n [7, 41b, 41a, 31b, 31a, 29b, 29a, 19b, 19a, 11b, 11a, 3, 5a, 2]\n sage: v.sort(); v\n [2, 5a, 3, 11a, 11b, 19a, 19b, 29a, 29b, 31a, 31b, 41a, 41b, 7]\n\n A bigger test::\n\n sage: v = primes_of_bounded_norm(10^7)\n sage: w = list(reversed(v)); w.sort()\n sage: v == w\n True\n ";
2363
#if CYTHON_COMPILING_IN_CPYTHON
2364
struct wrapperbase __pyx_wrapperbase_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_16__cmp__;
2365
#endif
2366
static int __pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_17__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_right) {
2367
int __pyx_r;
2368
__Pyx_RefNannyDeclarations
2369
__Pyx_RefNannySetupContext("__cmp__ (wrapper)", 0);
2370
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_right), __pyx_ptype_4code_5psage_13number_fields_5sqrt5_5prime_Prime, 1, "right", 0))) __PYX_ERR(0, 261, __pyx_L1_error)
2371
__pyx_r = __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_16__cmp__(((struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_v_self), ((struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_v_right));
2372
2373
/* function exit code */
2374
goto __pyx_L0;
2375
__pyx_L1_error:;
2376
__pyx_r = -1;
2377
__pyx_L0:;
2378
__Pyx_RefNannyFinishContext();
2379
return __pyx_r;
2380
}
2381
#endif /*!(#if PY_MAJOR_VERSION < 3)*/
2382
2383
#if PY_MAJOR_VERSION < 3
2384
static int __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_16__cmp__(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self, struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_right) {
2385
long __pyx_v_selfn;
2386
long __pyx_v_rightn;
2387
int __pyx_r;
2388
__Pyx_RefNannyDeclarations
2389
int __pyx_t_1;
2390
__Pyx_RefNannySetupContext("__cmp__", 0);
2391
2392
/* "code/psage/number_fields/sqrt5/prime.pyx":298
2393
* True
2394
* """
2395
* cdef long selfn = self.norm(), rightn = right.norm() # <<<<<<<<<<<<<<
2396
* if selfn > rightn: return 1
2397
* elif rightn > selfn: return -1
2398
*/
2399
__pyx_v_selfn = ((struct __pyx_vtabstruct_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_v_self->__pyx_vtab)->norm(__pyx_v_self, 0);
2400
__pyx_v_rightn = ((struct __pyx_vtabstruct_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_v_right->__pyx_vtab)->norm(__pyx_v_right, 0);
2401
2402
/* "code/psage/number_fields/sqrt5/prime.pyx":299
2403
* """
2404
* cdef long selfn = self.norm(), rightn = right.norm()
2405
* if selfn > rightn: return 1 # <<<<<<<<<<<<<<
2406
* elif rightn > selfn: return -1
2407
* elif self.r > right.r: return 1
2408
*/
2409
__pyx_t_1 = ((__pyx_v_selfn > __pyx_v_rightn) != 0);
2410
if (__pyx_t_1) {
2411
__pyx_r = 1;
2412
goto __pyx_L0;
2413
}
2414
2415
/* "code/psage/number_fields/sqrt5/prime.pyx":300
2416
* cdef long selfn = self.norm(), rightn = right.norm()
2417
* if selfn > rightn: return 1
2418
* elif rightn > selfn: return -1 # <<<<<<<<<<<<<<
2419
* elif self.r > right.r: return 1
2420
* elif right.r > self.r: return -1
2421
*/
2422
__pyx_t_1 = ((__pyx_v_rightn > __pyx_v_selfn) != 0);
2423
if (__pyx_t_1) {
2424
__pyx_r = -1;
2425
goto __pyx_L0;
2426
}
2427
2428
/* "code/psage/number_fields/sqrt5/prime.pyx":301
2429
* if selfn > rightn: return 1
2430
* elif rightn > selfn: return -1
2431
* elif self.r > right.r: return 1 # <<<<<<<<<<<<<<
2432
* elif right.r > self.r: return -1
2433
* else: return 0
2434
*/
2435
__pyx_t_1 = ((__pyx_v_self->r > __pyx_v_right->r) != 0);
2436
if (__pyx_t_1) {
2437
__pyx_r = 1;
2438
goto __pyx_L0;
2439
}
2440
2441
/* "code/psage/number_fields/sqrt5/prime.pyx":302
2442
* elif rightn > selfn: return -1
2443
* elif self.r > right.r: return 1
2444
* elif right.r > self.r: return -1 # <<<<<<<<<<<<<<
2445
* else: return 0
2446
*
2447
*/
2448
__pyx_t_1 = ((__pyx_v_right->r > __pyx_v_self->r) != 0);
2449
if (__pyx_t_1) {
2450
__pyx_r = -1;
2451
goto __pyx_L0;
2452
}
2453
2454
/* "code/psage/number_fields/sqrt5/prime.pyx":303
2455
* elif self.r > right.r: return 1
2456
* elif right.r > self.r: return -1
2457
* else: return 0 # <<<<<<<<<<<<<<
2458
*
2459
* def sage_ideal(self):
2460
*/
2461
/*else*/ {
2462
__pyx_r = 0;
2463
goto __pyx_L0;
2464
}
2465
2466
/* "code/psage/number_fields/sqrt5/prime.pyx":261
2467
* return self.p if self.r else self.p*self.p
2468
*
2469
* def __cmp__(self, Prime right): # <<<<<<<<<<<<<<
2470
* """
2471
* Compare two prime ideals. First sort by the norm, then in the
2472
*/
2473
2474
/* function exit code */
2475
__pyx_L0:;
2476
__Pyx_RefNannyFinishContext();
2477
return __pyx_r;
2478
}
2479
#endif /*!(#if PY_MAJOR_VERSION < 3)*/
2480
2481
/* "code/psage/number_fields/sqrt5/prime.pyx":305
2482
* else: return 0
2483
*
2484
* def sage_ideal(self): # <<<<<<<<<<<<<<
2485
* """
2486
* Return the usual prime fractional ideal associated to this
2487
*/
2488
2489
/* Python wrapper */
2490
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_19sage_ideal(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
2491
static char __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_18sage_ideal[] = "\n Return the usual prime fractional ideal associated to this\n prime. This is slow, but provides substantial additional\n functionality.\n\n EXAMPLES::\n\n sage: from psage.number_fields.sqrt5 import primes_of_bounded_norm\n sage: v = primes_of_bounded_norm(20)\n sage: v[1].sage_ideal()\n Fractional ideal (2*a - 1)\n sage: [P.sage_ideal() for P in v]\n [Fractional ideal (2), Fractional ideal (2*a - 1), Fractional ideal (3), Fractional ideal (3*a - 1), Fractional ideal (3*a - 2), Fractional ideal (-4*a + 1), Fractional ideal (-4*a + 3)]\n ";
2492
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_19sage_ideal(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
2493
PyObject *__pyx_r = 0;
2494
__Pyx_RefNannyDeclarations
2495
__Pyx_RefNannySetupContext("sage_ideal (wrapper)", 0);
2496
__pyx_r = __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_18sage_ideal(((struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_v_self));
2497
2498
/* function exit code */
2499
__Pyx_RefNannyFinishContext();
2500
return __pyx_r;
2501
}
2502
2503
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_18sage_ideal(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self) {
2504
PyObject *__pyx_v_F = NULL;
2505
long __pyx_v_p;
2506
long __pyx_v_r;
2507
PyObject *__pyx_r = NULL;
2508
__Pyx_RefNannyDeclarations
2509
PyObject *__pyx_t_1 = NULL;
2510
PyObject *__pyx_t_2 = NULL;
2511
long __pyx_t_3;
2512
int __pyx_t_4;
2513
PyObject *__pyx_t_5 = NULL;
2514
PyObject *__pyx_t_6 = NULL;
2515
PyObject *__pyx_t_7 = NULL;
2516
PyObject *__pyx_t_8 = NULL;
2517
int __pyx_t_9;
2518
__Pyx_RefNannySetupContext("sage_ideal", 0);
2519
2520
/* "code/psage/number_fields/sqrt5/prime.pyx":320
2521
* [Fractional ideal (2), Fractional ideal (2*a - 1), Fractional ideal (3), Fractional ideal (3*a - 1), Fractional ideal (3*a - 2), Fractional ideal (-4*a + 1), Fractional ideal (-4*a + 3)]
2522
* """
2523
* from misc import F # <<<<<<<<<<<<<<
2524
* cdef long p=self.p, r=self.r
2525
* if r: # split and ramified cases
2526
*/
2527
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 320, __pyx_L1_error)
2528
__Pyx_GOTREF(__pyx_t_1);
2529
__Pyx_INCREF(__pyx_n_s_F);
2530
__Pyx_GIVEREF(__pyx_n_s_F);
2531
PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_F);
2532
__pyx_t_2 = __Pyx_Import(__pyx_n_s_misc, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 320, __pyx_L1_error)
2533
__Pyx_GOTREF(__pyx_t_2);
2534
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2535
__pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_F); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 320, __pyx_L1_error)
2536
__Pyx_GOTREF(__pyx_t_1);
2537
__Pyx_INCREF(__pyx_t_1);
2538
__pyx_v_F = __pyx_t_1;
2539
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2540
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2541
2542
/* "code/psage/number_fields/sqrt5/prime.pyx":321
2543
* """
2544
* from misc import F
2545
* cdef long p=self.p, r=self.r # <<<<<<<<<<<<<<
2546
* if r: # split and ramified cases
2547
* return F.ideal(p, F.gen()-r)
2548
*/
2549
__pyx_t_3 = __pyx_v_self->p;
2550
__pyx_v_p = __pyx_t_3;
2551
__pyx_t_3 = __pyx_v_self->r;
2552
__pyx_v_r = __pyx_t_3;
2553
2554
/* "code/psage/number_fields/sqrt5/prime.pyx":322
2555
* from misc import F
2556
* cdef long p=self.p, r=self.r
2557
* if r: # split and ramified cases # <<<<<<<<<<<<<<
2558
* return F.ideal(p, F.gen()-r)
2559
* else: # inert case
2560
*/
2561
__pyx_t_4 = (__pyx_v_r != 0);
2562
if (__pyx_t_4) {
2563
2564
/* "code/psage/number_fields/sqrt5/prime.pyx":323
2565
* cdef long p=self.p, r=self.r
2566
* if r: # split and ramified cases
2567
* return F.ideal(p, F.gen()-r) # <<<<<<<<<<<<<<
2568
* else: # inert case
2569
* return F.ideal(p)
2570
*/
2571
__Pyx_XDECREF(__pyx_r);
2572
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_F, __pyx_n_s_ideal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 323, __pyx_L1_error)
2573
__Pyx_GOTREF(__pyx_t_1);
2574
__pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_p); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 323, __pyx_L1_error)
2575
__Pyx_GOTREF(__pyx_t_5);
2576
__pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_F, __pyx_n_s_gen); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 323, __pyx_L1_error)
2577
__Pyx_GOTREF(__pyx_t_7);
2578
__pyx_t_8 = NULL;
2579
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
2580
__pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
2581
if (likely(__pyx_t_8)) {
2582
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
2583
__Pyx_INCREF(__pyx_t_8);
2584
__Pyx_INCREF(function);
2585
__Pyx_DECREF_SET(__pyx_t_7, function);
2586
}
2587
}
2588
if (__pyx_t_8) {
2589
__pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 323, __pyx_L1_error)
2590
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
2591
} else {
2592
__pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 323, __pyx_L1_error)
2593
}
2594
__Pyx_GOTREF(__pyx_t_6);
2595
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
2596
__pyx_t_7 = __Pyx_PyInt_From_long(__pyx_v_r); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 323, __pyx_L1_error)
2597
__Pyx_GOTREF(__pyx_t_7);
2598
__pyx_t_8 = PyNumber_Subtract(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 323, __pyx_L1_error)
2599
__Pyx_GOTREF(__pyx_t_8);
2600
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2601
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
2602
__pyx_t_7 = NULL;
2603
__pyx_t_9 = 0;
2604
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
2605
__pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1);
2606
if (likely(__pyx_t_7)) {
2607
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
2608
__Pyx_INCREF(__pyx_t_7);
2609
__Pyx_INCREF(function);
2610
__Pyx_DECREF_SET(__pyx_t_1, function);
2611
__pyx_t_9 = 1;
2612
}
2613
}
2614
#if CYTHON_FAST_PYCALL
2615
if (PyFunction_Check(__pyx_t_1)) {
2616
PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_5, __pyx_t_8};
2617
__pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 323, __pyx_L1_error)
2618
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
2619
__Pyx_GOTREF(__pyx_t_2);
2620
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
2621
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
2622
} else
2623
#endif
2624
#if CYTHON_FAST_PYCCALL
2625
if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
2626
PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_5, __pyx_t_8};
2627
__pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 323, __pyx_L1_error)
2628
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
2629
__Pyx_GOTREF(__pyx_t_2);
2630
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
2631
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
2632
} else
2633
#endif
2634
{
2635
__pyx_t_6 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 323, __pyx_L1_error)
2636
__Pyx_GOTREF(__pyx_t_6);
2637
if (__pyx_t_7) {
2638
__Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); __pyx_t_7 = NULL;
2639
}
2640
__Pyx_GIVEREF(__pyx_t_5);
2641
PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_9, __pyx_t_5);
2642
__Pyx_GIVEREF(__pyx_t_8);
2643
PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_9, __pyx_t_8);
2644
__pyx_t_5 = 0;
2645
__pyx_t_8 = 0;
2646
__pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 323, __pyx_L1_error)
2647
__Pyx_GOTREF(__pyx_t_2);
2648
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2649
}
2650
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2651
__pyx_r = __pyx_t_2;
2652
__pyx_t_2 = 0;
2653
goto __pyx_L0;
2654
2655
/* "code/psage/number_fields/sqrt5/prime.pyx":322
2656
* from misc import F
2657
* cdef long p=self.p, r=self.r
2658
* if r: # split and ramified cases # <<<<<<<<<<<<<<
2659
* return F.ideal(p, F.gen()-r)
2660
* else: # inert case
2661
*/
2662
}
2663
2664
/* "code/psage/number_fields/sqrt5/prime.pyx":325
2665
* return F.ideal(p, F.gen()-r)
2666
* else: # inert case
2667
* return F.ideal(p) # <<<<<<<<<<<<<<
2668
*
2669
* from sage.rings.integer import Integer
2670
*/
2671
/*else*/ {
2672
__Pyx_XDECREF(__pyx_r);
2673
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_F, __pyx_n_s_ideal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 325, __pyx_L1_error)
2674
__Pyx_GOTREF(__pyx_t_1);
2675
__pyx_t_6 = __Pyx_PyInt_From_long(__pyx_v_p); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 325, __pyx_L1_error)
2676
__Pyx_GOTREF(__pyx_t_6);
2677
__pyx_t_8 = NULL;
2678
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
2679
__pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
2680
if (likely(__pyx_t_8)) {
2681
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
2682
__Pyx_INCREF(__pyx_t_8);
2683
__Pyx_INCREF(function);
2684
__Pyx_DECREF_SET(__pyx_t_1, function);
2685
}
2686
}
2687
if (!__pyx_t_8) {
2688
__pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 325, __pyx_L1_error)
2689
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2690
__Pyx_GOTREF(__pyx_t_2);
2691
} else {
2692
#if CYTHON_FAST_PYCALL
2693
if (PyFunction_Check(__pyx_t_1)) {
2694
PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6};
2695
__pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 325, __pyx_L1_error)
2696
__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
2697
__Pyx_GOTREF(__pyx_t_2);
2698
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2699
} else
2700
#endif
2701
#if CYTHON_FAST_PYCCALL
2702
if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
2703
PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6};
2704
__pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 325, __pyx_L1_error)
2705
__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
2706
__Pyx_GOTREF(__pyx_t_2);
2707
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2708
} else
2709
#endif
2710
{
2711
__pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 325, __pyx_L1_error)
2712
__Pyx_GOTREF(__pyx_t_5);
2713
__Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_8); __pyx_t_8 = NULL;
2714
__Pyx_GIVEREF(__pyx_t_6);
2715
PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_6);
2716
__pyx_t_6 = 0;
2717
__pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 325, __pyx_L1_error)
2718
__Pyx_GOTREF(__pyx_t_2);
2719
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
2720
}
2721
}
2722
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2723
__pyx_r = __pyx_t_2;
2724
__pyx_t_2 = 0;
2725
goto __pyx_L0;
2726
}
2727
2728
/* "code/psage/number_fields/sqrt5/prime.pyx":305
2729
* else: return 0
2730
*
2731
* def sage_ideal(self): # <<<<<<<<<<<<<<
2732
* """
2733
* Return the usual prime fractional ideal associated to this
2734
*/
2735
2736
/* function exit code */
2737
__pyx_L1_error:;
2738
__Pyx_XDECREF(__pyx_t_1);
2739
__Pyx_XDECREF(__pyx_t_2);
2740
__Pyx_XDECREF(__pyx_t_5);
2741
__Pyx_XDECREF(__pyx_t_6);
2742
__Pyx_XDECREF(__pyx_t_7);
2743
__Pyx_XDECREF(__pyx_t_8);
2744
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.Prime.sage_ideal", __pyx_clineno, __pyx_lineno, __pyx_filename);
2745
__pyx_r = NULL;
2746
__pyx_L0:;
2747
__Pyx_XDECREF(__pyx_v_F);
2748
__Pyx_XGIVEREF(__pyx_r);
2749
__Pyx_RefNannyFinishContext();
2750
return __pyx_r;
2751
}
2752
2753
/* "code/psage/number_fields/sqrt5/prime.pxd":23
2754
*
2755
* cdef class Prime:
2756
* cdef public long p, r # <<<<<<<<<<<<<<
2757
* cdef bint first
2758
* cpdef long norm(self)
2759
*/
2760
2761
/* Python wrapper */
2762
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1p_1__get__(PyObject *__pyx_v_self); /*proto*/
2763
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1p_1__get__(PyObject *__pyx_v_self) {
2764
PyObject *__pyx_r = 0;
2765
__Pyx_RefNannyDeclarations
2766
__Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
2767
__pyx_r = __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1p___get__(((struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_v_self));
2768
2769
/* function exit code */
2770
__Pyx_RefNannyFinishContext();
2771
return __pyx_r;
2772
}
2773
2774
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1p___get__(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self) {
2775
PyObject *__pyx_r = NULL;
2776
__Pyx_RefNannyDeclarations
2777
PyObject *__pyx_t_1 = NULL;
2778
__Pyx_RefNannySetupContext("__get__", 0);
2779
__Pyx_XDECREF(__pyx_r);
2780
__pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_self->p); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 23, __pyx_L1_error)
2781
__Pyx_GOTREF(__pyx_t_1);
2782
__pyx_r = __pyx_t_1;
2783
__pyx_t_1 = 0;
2784
goto __pyx_L0;
2785
2786
/* function exit code */
2787
__pyx_L1_error:;
2788
__Pyx_XDECREF(__pyx_t_1);
2789
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.Prime.p.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
2790
__pyx_r = NULL;
2791
__pyx_L0:;
2792
__Pyx_XGIVEREF(__pyx_r);
2793
__Pyx_RefNannyFinishContext();
2794
return __pyx_r;
2795
}
2796
2797
/* Python wrapper */
2798
static int __pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1p_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
2799
static int __pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1p_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
2800
int __pyx_r;
2801
__Pyx_RefNannyDeclarations
2802
__Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
2803
__pyx_r = __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1p_2__set__(((struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_v_self), ((PyObject *)__pyx_v_value));
2804
2805
/* function exit code */
2806
__Pyx_RefNannyFinishContext();
2807
return __pyx_r;
2808
}
2809
2810
static int __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1p_2__set__(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self, PyObject *__pyx_v_value) {
2811
int __pyx_r;
2812
__Pyx_RefNannyDeclarations
2813
long __pyx_t_1;
2814
__Pyx_RefNannySetupContext("__set__", 0);
2815
__pyx_t_1 = __Pyx_PyInt_As_long(__pyx_v_value); if (unlikely((__pyx_t_1 == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 23, __pyx_L1_error)
2816
__pyx_v_self->p = __pyx_t_1;
2817
2818
/* function exit code */
2819
__pyx_r = 0;
2820
goto __pyx_L0;
2821
__pyx_L1_error:;
2822
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.Prime.p.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
2823
__pyx_r = -1;
2824
__pyx_L0:;
2825
__Pyx_RefNannyFinishContext();
2826
return __pyx_r;
2827
}
2828
2829
/* Python wrapper */
2830
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1r_1__get__(PyObject *__pyx_v_self); /*proto*/
2831
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1r_1__get__(PyObject *__pyx_v_self) {
2832
PyObject *__pyx_r = 0;
2833
__Pyx_RefNannyDeclarations
2834
__Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
2835
__pyx_r = __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1r___get__(((struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_v_self));
2836
2837
/* function exit code */
2838
__Pyx_RefNannyFinishContext();
2839
return __pyx_r;
2840
}
2841
2842
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1r___get__(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self) {
2843
PyObject *__pyx_r = NULL;
2844
__Pyx_RefNannyDeclarations
2845
PyObject *__pyx_t_1 = NULL;
2846
__Pyx_RefNannySetupContext("__get__", 0);
2847
__Pyx_XDECREF(__pyx_r);
2848
__pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_self->r); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 23, __pyx_L1_error)
2849
__Pyx_GOTREF(__pyx_t_1);
2850
__pyx_r = __pyx_t_1;
2851
__pyx_t_1 = 0;
2852
goto __pyx_L0;
2853
2854
/* function exit code */
2855
__pyx_L1_error:;
2856
__Pyx_XDECREF(__pyx_t_1);
2857
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.Prime.r.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
2858
__pyx_r = NULL;
2859
__pyx_L0:;
2860
__Pyx_XGIVEREF(__pyx_r);
2861
__Pyx_RefNannyFinishContext();
2862
return __pyx_r;
2863
}
2864
2865
/* Python wrapper */
2866
static int __pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1r_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
2867
static int __pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1r_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
2868
int __pyx_r;
2869
__Pyx_RefNannyDeclarations
2870
__Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
2871
__pyx_r = __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1r_2__set__(((struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_v_self), ((PyObject *)__pyx_v_value));
2872
2873
/* function exit code */
2874
__Pyx_RefNannyFinishContext();
2875
return __pyx_r;
2876
}
2877
2878
static int __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1r_2__set__(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_self, PyObject *__pyx_v_value) {
2879
int __pyx_r;
2880
__Pyx_RefNannyDeclarations
2881
long __pyx_t_1;
2882
__Pyx_RefNannySetupContext("__set__", 0);
2883
__pyx_t_1 = __Pyx_PyInt_As_long(__pyx_v_value); if (unlikely((__pyx_t_1 == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 23, __pyx_L1_error)
2884
__pyx_v_self->r = __pyx_t_1;
2885
2886
/* function exit code */
2887
__pyx_r = 0;
2888
goto __pyx_L0;
2889
__pyx_L1_error:;
2890
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.Prime.r.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
2891
__pyx_r = -1;
2892
__pyx_L0:;
2893
__Pyx_RefNannyFinishContext();
2894
return __pyx_r;
2895
}
2896
2897
/* "code/psage/number_fields/sqrt5/prime.pyx":329
2898
* from sage.rings.integer import Integer
2899
*
2900
* def primes_above(long p, bint check=True): # <<<<<<<<<<<<<<
2901
* """
2902
* Return ordered list of all primes above p in the ring of integers
2903
*/
2904
2905
/* Python wrapper */
2906
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_1primes_above(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
2907
static char __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_primes_above[] = "\n Return ordered list of all primes above p in the ring of integers\n of Q(sqrt(5)). See the docstring for primes_of_bounded_norm.\n\n INPUT:\n - p -- prime number in integers ZZ (less than `2^{31}`)\n - check -- bool (default: True); if True, check that p is prime\n OUTPUT:\n - list of 1 or 2 Prime objects\n\n EXAMPLES::\n\n sage: from psage.number_fields.sqrt5.prime import primes_above\n sage: primes_above(2)\n [2]\n sage: primes_above(3)\n [3]\n sage: primes_above(5)\n [5a]\n sage: primes_above(11)\n [11a, 11b]\n sage: primes_above(13)\n [13]\n sage: primes_above(17)\n [17]\n sage: primes_above(4)\n Traceback (most recent call last):\n ...\n ValueError: p must be a prime\n sage: primes_above(4, check=False)\n [2]\n ";
2908
static PyMethodDef __pyx_mdef_4code_5psage_13number_fields_5sqrt5_5prime_1primes_above = {"primes_above", (PyCFunction)__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_1primes_above, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_primes_above};
2909
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_1primes_above(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
2910
long __pyx_v_p;
2911
int __pyx_v_check;
2912
PyObject *__pyx_r = 0;
2913
__Pyx_RefNannyDeclarations
2914
__Pyx_RefNannySetupContext("primes_above (wrapper)", 0);
2915
{
2916
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_p,&__pyx_n_s_check,0};
2917
PyObject* values[2] = {0,0};
2918
if (unlikely(__pyx_kwds)) {
2919
Py_ssize_t kw_args;
2920
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
2921
switch (pos_args) {
2922
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
2923
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
2924
case 0: break;
2925
default: goto __pyx_L5_argtuple_error;
2926
}
2927
kw_args = PyDict_Size(__pyx_kwds);
2928
switch (pos_args) {
2929
case 0:
2930
if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_p)) != 0)) kw_args--;
2931
else goto __pyx_L5_argtuple_error;
2932
case 1:
2933
if (kw_args > 0) {
2934
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_check);
2935
if (value) { values[1] = value; kw_args--; }
2936
}
2937
}
2938
if (unlikely(kw_args > 0)) {
2939
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "primes_above") < 0)) __PYX_ERR(0, 329, __pyx_L3_error)
2940
}
2941
} else {
2942
switch (PyTuple_GET_SIZE(__pyx_args)) {
2943
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
2944
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
2945
break;
2946
default: goto __pyx_L5_argtuple_error;
2947
}
2948
}
2949
__pyx_v_p = __Pyx_PyInt_As_long(values[0]); if (unlikely((__pyx_v_p == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 329, __pyx_L3_error)
2950
if (values[1]) {
2951
__pyx_v_check = __Pyx_PyObject_IsTrue(values[1]); if (unlikely((__pyx_v_check == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 329, __pyx_L3_error)
2952
} else {
2953
__pyx_v_check = ((int)1);
2954
}
2955
}
2956
goto __pyx_L4_argument_unpacking_done;
2957
__pyx_L5_argtuple_error:;
2958
__Pyx_RaiseArgtupleInvalid("primes_above", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 329, __pyx_L3_error)
2959
__pyx_L3_error:;
2960
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.primes_above", __pyx_clineno, __pyx_lineno, __pyx_filename);
2961
__Pyx_RefNannyFinishContext();
2962
return NULL;
2963
__pyx_L4_argument_unpacking_done:;
2964
__pyx_r = __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_primes_above(__pyx_self, __pyx_v_p, __pyx_v_check);
2965
2966
/* function exit code */
2967
__Pyx_RefNannyFinishContext();
2968
return __pyx_r;
2969
}
2970
2971
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_primes_above(CYTHON_UNUSED PyObject *__pyx_self, long __pyx_v_p, int __pyx_v_check) {
2972
long __pyx_v_t;
2973
PyObject *__pyx_r = NULL;
2974
__Pyx_RefNannyDeclarations
2975
int __pyx_t_1;
2976
int __pyx_t_2;
2977
PyObject *__pyx_t_3 = NULL;
2978
PyObject *__pyx_t_4 = NULL;
2979
PyObject *__pyx_t_5 = NULL;
2980
PyObject *__pyx_t_6 = NULL;
2981
PyObject *__pyx_t_7 = NULL;
2982
PyObject *__pyx_t_8 = NULL;
2983
int __pyx_t_9;
2984
int __pyx_t_10;
2985
__Pyx_RefNannySetupContext("primes_above", 0);
2986
2987
/* "code/psage/number_fields/sqrt5/prime.pyx":362
2988
* [2]
2989
* """
2990
* if check and not Integer(p).is_pseudoprime(): # <<<<<<<<<<<<<<
2991
* raise ValueError, "p must be a prime"
2992
* cdef long t = p%5
2993
*/
2994
__pyx_t_2 = (__pyx_v_check != 0);
2995
if (__pyx_t_2) {
2996
} else {
2997
__pyx_t_1 = __pyx_t_2;
2998
goto __pyx_L4_bool_binop_done;
2999
}
3000
__pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_Integer); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 362, __pyx_L1_error)
3001
__Pyx_GOTREF(__pyx_t_5);
3002
__pyx_t_6 = __Pyx_PyInt_From_long(__pyx_v_p); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 362, __pyx_L1_error)
3003
__Pyx_GOTREF(__pyx_t_6);
3004
__pyx_t_7 = NULL;
3005
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
3006
__pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
3007
if (likely(__pyx_t_7)) {
3008
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
3009
__Pyx_INCREF(__pyx_t_7);
3010
__Pyx_INCREF(function);
3011
__Pyx_DECREF_SET(__pyx_t_5, function);
3012
}
3013
}
3014
if (!__pyx_t_7) {
3015
__pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 362, __pyx_L1_error)
3016
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
3017
__Pyx_GOTREF(__pyx_t_4);
3018
} else {
3019
#if CYTHON_FAST_PYCALL
3020
if (PyFunction_Check(__pyx_t_5)) {
3021
PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_6};
3022
__pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 362, __pyx_L1_error)
3023
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
3024
__Pyx_GOTREF(__pyx_t_4);
3025
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
3026
} else
3027
#endif
3028
#if CYTHON_FAST_PYCCALL
3029
if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
3030
PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_6};
3031
__pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 362, __pyx_L1_error)
3032
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
3033
__Pyx_GOTREF(__pyx_t_4);
3034
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
3035
} else
3036
#endif
3037
{
3038
__pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 362, __pyx_L1_error)
3039
__Pyx_GOTREF(__pyx_t_8);
3040
__Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL;
3041
__Pyx_GIVEREF(__pyx_t_6);
3042
PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_6);
3043
__pyx_t_6 = 0;
3044
__pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 362, __pyx_L1_error)
3045
__Pyx_GOTREF(__pyx_t_4);
3046
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
3047
}
3048
}
3049
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
3050
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_is_pseudoprime); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 362, __pyx_L1_error)
3051
__Pyx_GOTREF(__pyx_t_5);
3052
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
3053
__pyx_t_4 = NULL;
3054
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
3055
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
3056
if (likely(__pyx_t_4)) {
3057
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
3058
__Pyx_INCREF(__pyx_t_4);
3059
__Pyx_INCREF(function);
3060
__Pyx_DECREF_SET(__pyx_t_5, function);
3061
}
3062
}
3063
if (__pyx_t_4) {
3064
__pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 362, __pyx_L1_error)
3065
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
3066
} else {
3067
__pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 362, __pyx_L1_error)
3068
}
3069
__Pyx_GOTREF(__pyx_t_3);
3070
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
3071
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 362, __pyx_L1_error)
3072
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
3073
__pyx_t_9 = ((!__pyx_t_2) != 0);
3074
__pyx_t_1 = __pyx_t_9;
3075
__pyx_L4_bool_binop_done:;
3076
if (__pyx_t_1) {
3077
3078
/* "code/psage/number_fields/sqrt5/prime.pyx":363
3079
* """
3080
* if check and not Integer(p).is_pseudoprime():
3081
* raise ValueError, "p must be a prime" # <<<<<<<<<<<<<<
3082
* cdef long t = p%5
3083
* if t == 1 or t == 4 or t == 0:
3084
*/
3085
__Pyx_Raise(__pyx_builtin_ValueError, __pyx_kp_s_p_must_be_a_prime, 0, 0);
3086
__PYX_ERR(0, 363, __pyx_L1_error)
3087
3088
/* "code/psage/number_fields/sqrt5/prime.pyx":362
3089
* [2]
3090
* """
3091
* if check and not Integer(p).is_pseudoprime(): # <<<<<<<<<<<<<<
3092
* raise ValueError, "p must be a prime"
3093
* cdef long t = p%5
3094
*/
3095
}
3096
3097
/* "code/psage/number_fields/sqrt5/prime.pyx":364
3098
* if check and not Integer(p).is_pseudoprime():
3099
* raise ValueError, "p must be a prime"
3100
* cdef long t = p%5 # <<<<<<<<<<<<<<
3101
* if t == 1 or t == 4 or t == 0:
3102
* return prime_range(p, p+1)
3103
*/
3104
__pyx_v_t = __Pyx_mod_long(__pyx_v_p, 5);
3105
3106
/* "code/psage/number_fields/sqrt5/prime.pyx":365
3107
* raise ValueError, "p must be a prime"
3108
* cdef long t = p%5
3109
* if t == 1 or t == 4 or t == 0: # <<<<<<<<<<<<<<
3110
* return prime_range(p, p+1)
3111
* else: # inert
3112
*/
3113
switch (__pyx_v_t) {
3114
case 1:
3115
case 4:
3116
case 0:
3117
3118
/* "code/psage/number_fields/sqrt5/prime.pyx":366
3119
* cdef long t = p%5
3120
* if t == 1 or t == 4 or t == 0:
3121
* return prime_range(p, p+1) # <<<<<<<<<<<<<<
3122
* else: # inert
3123
* return [Prime(p, 0, True)]
3124
*/
3125
__Pyx_XDECREF(__pyx_r);
3126
__pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_prime_range); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 366, __pyx_L1_error)
3127
__Pyx_GOTREF(__pyx_t_5);
3128
__pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_p); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 366, __pyx_L1_error)
3129
__Pyx_GOTREF(__pyx_t_4);
3130
__pyx_t_8 = __Pyx_PyInt_From_long((__pyx_v_p + 1)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 366, __pyx_L1_error)
3131
__Pyx_GOTREF(__pyx_t_8);
3132
__pyx_t_6 = NULL;
3133
__pyx_t_10 = 0;
3134
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
3135
__pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
3136
if (likely(__pyx_t_6)) {
3137
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
3138
__Pyx_INCREF(__pyx_t_6);
3139
__Pyx_INCREF(function);
3140
__Pyx_DECREF_SET(__pyx_t_5, function);
3141
__pyx_t_10 = 1;
3142
}
3143
}
3144
#if CYTHON_FAST_PYCALL
3145
if (PyFunction_Check(__pyx_t_5)) {
3146
PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_4, __pyx_t_8};
3147
__pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 366, __pyx_L1_error)
3148
__Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
3149
__Pyx_GOTREF(__pyx_t_3);
3150
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
3151
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
3152
} else
3153
#endif
3154
#if CYTHON_FAST_PYCCALL
3155
if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
3156
PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_4, __pyx_t_8};
3157
__pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 366, __pyx_L1_error)
3158
__Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
3159
__Pyx_GOTREF(__pyx_t_3);
3160
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
3161
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
3162
} else
3163
#endif
3164
{
3165
__pyx_t_7 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 366, __pyx_L1_error)
3166
__Pyx_GOTREF(__pyx_t_7);
3167
if (__pyx_t_6) {
3168
__Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL;
3169
}
3170
__Pyx_GIVEREF(__pyx_t_4);
3171
PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_10, __pyx_t_4);
3172
__Pyx_GIVEREF(__pyx_t_8);
3173
PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_10, __pyx_t_8);
3174
__pyx_t_4 = 0;
3175
__pyx_t_8 = 0;
3176
__pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 366, __pyx_L1_error)
3177
__Pyx_GOTREF(__pyx_t_3);
3178
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
3179
}
3180
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
3181
__pyx_r = __pyx_t_3;
3182
__pyx_t_3 = 0;
3183
goto __pyx_L0;
3184
3185
/* "code/psage/number_fields/sqrt5/prime.pyx":365
3186
* raise ValueError, "p must be a prime"
3187
* cdef long t = p%5
3188
* if t == 1 or t == 4 or t == 0: # <<<<<<<<<<<<<<
3189
* return prime_range(p, p+1)
3190
* else: # inert
3191
*/
3192
break;
3193
default:
3194
3195
/* "code/psage/number_fields/sqrt5/prime.pyx":368
3196
* return prime_range(p, p+1)
3197
* else: # inert
3198
* return [Prime(p, 0, True)] # <<<<<<<<<<<<<<
3199
*
3200
* def primes_of_bounded_norm(bound):
3201
*/
3202
__Pyx_XDECREF(__pyx_r);
3203
__pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v_p); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 368, __pyx_L1_error)
3204
__Pyx_GOTREF(__pyx_t_3);
3205
__pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 368, __pyx_L1_error)
3206
__Pyx_GOTREF(__pyx_t_5);
3207
__Pyx_GIVEREF(__pyx_t_3);
3208
PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
3209
__Pyx_INCREF(__pyx_int_0);
3210
__Pyx_GIVEREF(__pyx_int_0);
3211
PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_int_0);
3212
__Pyx_INCREF(Py_True);
3213
__Pyx_GIVEREF(Py_True);
3214
PyTuple_SET_ITEM(__pyx_t_5, 2, Py_True);
3215
__pyx_t_3 = 0;
3216
__pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_4code_5psage_13number_fields_5sqrt5_5prime_Prime), __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 368, __pyx_L1_error)
3217
__Pyx_GOTREF(__pyx_t_3);
3218
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
3219
__pyx_t_5 = PyList_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 368, __pyx_L1_error)
3220
__Pyx_GOTREF(__pyx_t_5);
3221
__Pyx_GIVEREF(__pyx_t_3);
3222
PyList_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
3223
__pyx_t_3 = 0;
3224
__pyx_r = __pyx_t_5;
3225
__pyx_t_5 = 0;
3226
goto __pyx_L0;
3227
break;
3228
}
3229
3230
/* "code/psage/number_fields/sqrt5/prime.pyx":329
3231
* from sage.rings.integer import Integer
3232
*
3233
* def primes_above(long p, bint check=True): # <<<<<<<<<<<<<<
3234
* """
3235
* Return ordered list of all primes above p in the ring of integers
3236
*/
3237
3238
/* function exit code */
3239
__pyx_L1_error:;
3240
__Pyx_XDECREF(__pyx_t_3);
3241
__Pyx_XDECREF(__pyx_t_4);
3242
__Pyx_XDECREF(__pyx_t_5);
3243
__Pyx_XDECREF(__pyx_t_6);
3244
__Pyx_XDECREF(__pyx_t_7);
3245
__Pyx_XDECREF(__pyx_t_8);
3246
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.primes_above", __pyx_clineno, __pyx_lineno, __pyx_filename);
3247
__pyx_r = NULL;
3248
__pyx_L0:;
3249
__Pyx_XGIVEREF(__pyx_r);
3250
__Pyx_RefNannyFinishContext();
3251
return __pyx_r;
3252
}
3253
3254
/* "code/psage/number_fields/sqrt5/prime.pyx":370
3255
* return [Prime(p, 0, True)]
3256
*
3257
* def primes_of_bounded_norm(bound): # <<<<<<<<<<<<<<
3258
* """
3259
* Return ordered list of all prime ideals of the ring of integers of
3260
*/
3261
3262
/* Python wrapper */
3263
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_3primes_of_bounded_norm(PyObject *__pyx_self, PyObject *__pyx_v_bound); /*proto*/
3264
static char __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_2primes_of_bounded_norm[] = "\n Return ordered list of all prime ideals of the ring of integers of\n Q(sqrt(5)) of norm less than bound.\n\n The primes are instances of a special fast Primes class (they are\n *not* usual Sage prime ideals -- use the sage_ideal() method to\n get those). They are sorted first by norm, then in the remaining\n split case by the integer in the interval [0,p) congruent to\n (1+sqrt(5))/2. \n\n INPUT:\n - ``bound`` -- nonnegative integer, less than `2^{31}`\n\n WARNING: The ordering is NOT the same as the ordering of primes by\n Sage. Even if you order first by norm, then use Sage's ordering\n for primes of the same norm, then the orderings do not agree.::\n\n EXAMPLES::\n\n sage: from psage.number_fields.sqrt5 import primes_of_bounded_norm\n sage: primes_of_bounded_norm(0)\n []\n sage: primes_of_bounded_norm(10)\n [2, 5a, 3]\n sage: primes_of_bounded_norm(50)\n [2, 5a, 3, 11a, 11b, 19a, 19b, 29a, 29b, 31a, 31b, 41a, 41b, 7]\n sage: len(primes_of_bounded_norm(10^6))\n 78510\n\n We grab one of the primes::\n \n sage: v = primes_of_bounded_norm(100)\n sage: P = v[3]; type(P)\n <type 'psage.number_fields.sqrt5.prime.Prime'>\n\n It prints with a nice label::\n \n sage: P\n 11a\n\n You can get the corresponding fractional ideal as a normal Sage ideal::\n \n sage: P.sage_ideal()\n Fractional ideal (3*a - 1)\n\n You can also get the underlying residue characteristic::\n \n sage: P.p\n 11\n\n And, the image of (1+sqrt(5))/2 modulo the prime (or 0 in the inert case)::\n \n sage: P.r\n 4\n sage: z = P.sage_ideal(); z.residue_field()(z.number_field().gen())\n 4\n\n Prime enumeration is reasonable fast, even when the input is\n relatively large (going up to `10^8` takes a few seconds, and up\n to `10^9` takes a few minutes), and the following s""hould take less\n than a second::\n\n sage: len(primes_of_bounded_norm(10^7)) # less than a second\n 664500\n\n One limitation is that the bound must be less than `2^{31}`::\n\n sage: primes_of_bounded_norm(2^31)\n Traceback (most recent call last):\n ...\n ValueError: bound must be less than 2^31\n ";
3265
static PyMethodDef __pyx_mdef_4code_5psage_13number_fields_5sqrt5_5prime_3primes_of_bounded_norm = {"primes_of_bounded_norm", (PyCFunction)__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_3primes_of_bounded_norm, METH_O, __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_2primes_of_bounded_norm};
3266
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_3primes_of_bounded_norm(PyObject *__pyx_self, PyObject *__pyx_v_bound) {
3267
PyObject *__pyx_r = 0;
3268
__Pyx_RefNannyDeclarations
3269
__Pyx_RefNannySetupContext("primes_of_bounded_norm (wrapper)", 0);
3270
__pyx_r = __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_2primes_of_bounded_norm(__pyx_self, ((PyObject *)__pyx_v_bound));
3271
3272
/* function exit code */
3273
__Pyx_RefNannyFinishContext();
3274
return __pyx_r;
3275
}
3276
3277
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_2primes_of_bounded_norm(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_bound) {
3278
PyObject *__pyx_r = NULL;
3279
__Pyx_RefNannyDeclarations
3280
PyObject *__pyx_t_1 = NULL;
3281
PyObject *__pyx_t_2 = NULL;
3282
PyObject *__pyx_t_3 = NULL;
3283
PyObject *__pyx_t_4 = NULL;
3284
__Pyx_RefNannySetupContext("primes_of_bounded_norm", 0);
3285
3286
/* "code/psage/number_fields/sqrt5/prime.pyx":443
3287
* ValueError: bound must be less than 2^31
3288
* """
3289
* return prime_range(bound) # <<<<<<<<<<<<<<
3290
*
3291
* def prime_range(long start, stop=None):
3292
*/
3293
__Pyx_XDECREF(__pyx_r);
3294
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_prime_range); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 443, __pyx_L1_error)
3295
__Pyx_GOTREF(__pyx_t_2);
3296
__pyx_t_3 = NULL;
3297
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
3298
__pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
3299
if (likely(__pyx_t_3)) {
3300
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
3301
__Pyx_INCREF(__pyx_t_3);
3302
__Pyx_INCREF(function);
3303
__Pyx_DECREF_SET(__pyx_t_2, function);
3304
}
3305
}
3306
if (!__pyx_t_3) {
3307
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_bound); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 443, __pyx_L1_error)
3308
__Pyx_GOTREF(__pyx_t_1);
3309
} else {
3310
#if CYTHON_FAST_PYCALL
3311
if (PyFunction_Check(__pyx_t_2)) {
3312
PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_bound};
3313
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 443, __pyx_L1_error)
3314
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
3315
__Pyx_GOTREF(__pyx_t_1);
3316
} else
3317
#endif
3318
#if CYTHON_FAST_PYCCALL
3319
if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
3320
PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_bound};
3321
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 443, __pyx_L1_error)
3322
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
3323
__Pyx_GOTREF(__pyx_t_1);
3324
} else
3325
#endif
3326
{
3327
__pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 443, __pyx_L1_error)
3328
__Pyx_GOTREF(__pyx_t_4);
3329
__Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL;
3330
__Pyx_INCREF(__pyx_v_bound);
3331
__Pyx_GIVEREF(__pyx_v_bound);
3332
PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_bound);
3333
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 443, __pyx_L1_error)
3334
__Pyx_GOTREF(__pyx_t_1);
3335
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
3336
}
3337
}
3338
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3339
__pyx_r = __pyx_t_1;
3340
__pyx_t_1 = 0;
3341
goto __pyx_L0;
3342
3343
/* "code/psage/number_fields/sqrt5/prime.pyx":370
3344
* return [Prime(p, 0, True)]
3345
*
3346
* def primes_of_bounded_norm(bound): # <<<<<<<<<<<<<<
3347
* """
3348
* Return ordered list of all prime ideals of the ring of integers of
3349
*/
3350
3351
/* function exit code */
3352
__pyx_L1_error:;
3353
__Pyx_XDECREF(__pyx_t_1);
3354
__Pyx_XDECREF(__pyx_t_2);
3355
__Pyx_XDECREF(__pyx_t_3);
3356
__Pyx_XDECREF(__pyx_t_4);
3357
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.primes_of_bounded_norm", __pyx_clineno, __pyx_lineno, __pyx_filename);
3358
__pyx_r = NULL;
3359
__pyx_L0:;
3360
__Pyx_XGIVEREF(__pyx_r);
3361
__Pyx_RefNannyFinishContext();
3362
return __pyx_r;
3363
}
3364
3365
/* "code/psage/number_fields/sqrt5/prime.pyx":445
3366
* return prime_range(bound)
3367
*
3368
* def prime_range(long start, stop=None): # <<<<<<<<<<<<<<
3369
* """
3370
* Return ordered list of all prime ideals of the ring of integers of
3371
*/
3372
3373
/* Python wrapper */
3374
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5prime_range(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
3375
static char __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_4prime_range[] = "\n Return ordered list of all prime ideals of the ring of integers of\n Q(sqrt(5)) of norm at least start and less than stop. If only\n start is given then return primes with norm less than start.\n\n The primes are instances of a special fast Primes class (they are\n *not* usual Sage prime ideals -- use the sage_ideal() method to\n get those). They are sorted first by norm, then in the remaining\n split case by the integer in the interval [0,p) congruent to\n (1+sqrt(5))/2. For optimal speed you can use the Prime objects\n directly from Cython, which provides direct C-level access to the\n underlying data structure.\n\n INPUT:\n - ``start`` -- nonnegative integer, less than `2^{31}`\n - ``stop`` -- None or nonnegative integer, less than `2^{31}`\n\n EXAMPLES::\n\n sage: from psage.number_fields.sqrt5.prime import prime_range\n sage: prime_range(10, 60)\n [11a, 11b, 19a, 19b, 29a, 29b, 31a, 31b, 41a, 41b, 7, 59a, 59b]\n sage: prime_range(2, 11)\n [2, 5a, 3]\n sage: prime_range(2, 12)\n [2, 5a, 3, 11a, 11b]\n sage: prime_range(3, 12)\n [2, 5a, 3, 11a, 11b]\n sage: prime_range(9, 12)\n [3, 11a, 11b]\n sage: prime_range(5, 12)\n [5a, 3, 11a, 11b]\n ";
3376
static PyMethodDef __pyx_mdef_4code_5psage_13number_fields_5sqrt5_5prime_5prime_range = {"prime_range", (PyCFunction)__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5prime_range, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_4prime_range};
3377
static PyObject *__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5prime_range(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
3378
long __pyx_v_start;
3379
PyObject *__pyx_v_stop = 0;
3380
PyObject *__pyx_r = 0;
3381
__Pyx_RefNannyDeclarations
3382
__Pyx_RefNannySetupContext("prime_range (wrapper)", 0);
3383
{
3384
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_start,&__pyx_n_s_stop,0};
3385
PyObject* values[2] = {0,0};
3386
values[1] = ((PyObject *)Py_None);
3387
if (unlikely(__pyx_kwds)) {
3388
Py_ssize_t kw_args;
3389
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
3390
switch (pos_args) {
3391
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
3392
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
3393
case 0: break;
3394
default: goto __pyx_L5_argtuple_error;
3395
}
3396
kw_args = PyDict_Size(__pyx_kwds);
3397
switch (pos_args) {
3398
case 0:
3399
if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start)) != 0)) kw_args--;
3400
else goto __pyx_L5_argtuple_error;
3401
case 1:
3402
if (kw_args > 0) {
3403
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_stop);
3404
if (value) { values[1] = value; kw_args--; }
3405
}
3406
}
3407
if (unlikely(kw_args > 0)) {
3408
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "prime_range") < 0)) __PYX_ERR(0, 445, __pyx_L3_error)
3409
}
3410
} else {
3411
switch (PyTuple_GET_SIZE(__pyx_args)) {
3412
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
3413
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
3414
break;
3415
default: goto __pyx_L5_argtuple_error;
3416
}
3417
}
3418
__pyx_v_start = __Pyx_PyInt_As_long(values[0]); if (unlikely((__pyx_v_start == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 445, __pyx_L3_error)
3419
__pyx_v_stop = values[1];
3420
}
3421
goto __pyx_L4_argument_unpacking_done;
3422
__pyx_L5_argtuple_error:;
3423
__Pyx_RaiseArgtupleInvalid("prime_range", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 445, __pyx_L3_error)
3424
__pyx_L3_error:;
3425
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.prime_range", __pyx_clineno, __pyx_lineno, __pyx_filename);
3426
__Pyx_RefNannyFinishContext();
3427
return NULL;
3428
__pyx_L4_argument_unpacking_done:;
3429
__pyx_r = __pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_4prime_range(__pyx_self, __pyx_v_start, __pyx_v_stop);
3430
3431
/* function exit code */
3432
__Pyx_RefNannyFinishContext();
3433
return __pyx_r;
3434
}
3435
3436
static PyObject *__pyx_pf_4code_5psage_13number_fields_5sqrt5_5prime_4prime_range(CYTHON_UNUSED PyObject *__pyx_self, long __pyx_v_start, PyObject *__pyx_v_stop) {
3437
long __pyx_v_p;
3438
long __pyx_v_p2;
3439
long __pyx_v_r0;
3440
long __pyx_v_r1;
3441
long __pyx_v_t;
3442
long __pyx_v_bound;
3443
struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *__pyx_v_P = 0;
3444
PyObject *__pyx_v_v = 0;
3445
PyObject *__pyx_v_prime_range_ZZ = NULL;
3446
PyObject *__pyx_r = NULL;
3447
__Pyx_RefNannyDeclarations
3448
int __pyx_t_1;
3449
PyObject *__pyx_t_2 = NULL;
3450
PyObject *__pyx_t_3 = NULL;
3451
int __pyx_t_4;
3452
long __pyx_t_5;
3453
PyObject *__pyx_t_6 = NULL;
3454
Py_ssize_t __pyx_t_7;
3455
PyObject *(*__pyx_t_8)(PyObject *);
3456
long __pyx_t_9;
3457
int __pyx_t_10;
3458
__Pyx_RefNannySetupContext("prime_range", 0);
3459
3460
/* "code/psage/number_fields/sqrt5/prime.pyx":479
3461
* [5a, 3, 11a, 11b]
3462
* """
3463
* if start >= 2**31 or (stop and stop >= 2**31): # <<<<<<<<<<<<<<
3464
* raise ValueError, "bound must be less than 2^31"
3465
*
3466
*/
3467
__pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_start); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 479, __pyx_L1_error)
3468
__Pyx_GOTREF(__pyx_t_2);
3469
__pyx_t_3 = PyObject_RichCompare(__pyx_t_2, __pyx_int_2147483648, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 479, __pyx_L1_error)
3470
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3471
__pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 479, __pyx_L1_error)
3472
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
3473
if (!__pyx_t_4) {
3474
} else {
3475
__pyx_t_1 = __pyx_t_4;
3476
goto __pyx_L4_bool_binop_done;
3477
}
3478
__pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_stop); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 479, __pyx_L1_error)
3479
if (__pyx_t_4) {
3480
} else {
3481
__pyx_t_1 = __pyx_t_4;
3482
goto __pyx_L4_bool_binop_done;
3483
}
3484
__pyx_t_3 = PyObject_RichCompare(__pyx_v_stop, __pyx_int_2147483648, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 479, __pyx_L1_error)
3485
__pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 479, __pyx_L1_error)
3486
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
3487
__pyx_t_1 = __pyx_t_4;
3488
__pyx_L4_bool_binop_done:;
3489
if (__pyx_t_1) {
3490
3491
/* "code/psage/number_fields/sqrt5/prime.pyx":480
3492
* """
3493
* if start >= 2**31 or (stop and stop >= 2**31):
3494
* raise ValueError, "bound must be less than 2^31" # <<<<<<<<<<<<<<
3495
*
3496
* cdef long p, p2, sr, r0, r1, t, bound
3497
*/
3498
__Pyx_Raise(__pyx_builtin_ValueError, __pyx_kp_s_bound_must_be_less_than_2_31, 0, 0);
3499
__PYX_ERR(0, 480, __pyx_L1_error)
3500
3501
/* "code/psage/number_fields/sqrt5/prime.pyx":479
3502
* [5a, 3, 11a, 11b]
3503
* """
3504
* if start >= 2**31 or (stop and stop >= 2**31): # <<<<<<<<<<<<<<
3505
* raise ValueError, "bound must be less than 2^31"
3506
*
3507
*/
3508
}
3509
3510
/* "code/psage/number_fields/sqrt5/prime.pyx":484
3511
* cdef long p, p2, sr, r0, r1, t, bound
3512
* cdef Prime P
3513
* cdef list v = [] # <<<<<<<<<<<<<<
3514
*
3515
* if stop is None:
3516
*/
3517
__pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 484, __pyx_L1_error)
3518
__Pyx_GOTREF(__pyx_t_3);
3519
__pyx_v_v = ((PyObject*)__pyx_t_3);
3520
__pyx_t_3 = 0;
3521
3522
/* "code/psage/number_fields/sqrt5/prime.pyx":486
3523
* cdef list v = []
3524
*
3525
* if stop is None: # <<<<<<<<<<<<<<
3526
* bound = start
3527
* start = 2
3528
*/
3529
__pyx_t_1 = (__pyx_v_stop == Py_None);
3530
__pyx_t_4 = (__pyx_t_1 != 0);
3531
if (__pyx_t_4) {
3532
3533
/* "code/psage/number_fields/sqrt5/prime.pyx":487
3534
*
3535
* if stop is None:
3536
* bound = start # <<<<<<<<<<<<<<
3537
* start = 2
3538
* else:
3539
*/
3540
__pyx_v_bound = __pyx_v_start;
3541
3542
/* "code/psage/number_fields/sqrt5/prime.pyx":488
3543
* if stop is None:
3544
* bound = start
3545
* start = 2 # <<<<<<<<<<<<<<
3546
* else:
3547
* bound = stop
3548
*/
3549
__pyx_v_start = 2;
3550
3551
/* "code/psage/number_fields/sqrt5/prime.pyx":486
3552
* cdef list v = []
3553
*
3554
* if stop is None: # <<<<<<<<<<<<<<
3555
* bound = start
3556
* start = 2
3557
*/
3558
goto __pyx_L7;
3559
}
3560
3561
/* "code/psage/number_fields/sqrt5/prime.pyx":490
3562
* start = 2
3563
* else:
3564
* bound = stop # <<<<<<<<<<<<<<
3565
*
3566
* from sage.all import prime_range as prime_range_ZZ
3567
*/
3568
/*else*/ {
3569
__pyx_t_5 = __Pyx_PyInt_As_long(__pyx_v_stop); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 490, __pyx_L1_error)
3570
__pyx_v_bound = __pyx_t_5;
3571
}
3572
__pyx_L7:;
3573
3574
/* "code/psage/number_fields/sqrt5/prime.pyx":492
3575
* bound = stop
3576
*
3577
* from sage.all import prime_range as prime_range_ZZ # <<<<<<<<<<<<<<
3578
*
3579
* for p in prime_range_ZZ(bound, py_ints=True):
3580
*/
3581
__pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 492, __pyx_L1_error)
3582
__Pyx_GOTREF(__pyx_t_3);
3583
__Pyx_INCREF(__pyx_n_s_prime_range);
3584
__Pyx_GIVEREF(__pyx_n_s_prime_range);
3585
PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_prime_range);
3586
__pyx_t_2 = __Pyx_Import(__pyx_n_s_sage_all, __pyx_t_3, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 492, __pyx_L1_error)
3587
__Pyx_GOTREF(__pyx_t_2);
3588
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
3589
__pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_prime_range); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 492, __pyx_L1_error)
3590
__Pyx_GOTREF(__pyx_t_3);
3591
__Pyx_INCREF(__pyx_t_3);
3592
__pyx_v_prime_range_ZZ = __pyx_t_3;
3593
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
3594
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3595
3596
/* "code/psage/number_fields/sqrt5/prime.pyx":494
3597
* from sage.all import prime_range as prime_range_ZZ
3598
*
3599
* for p in prime_range_ZZ(bound, py_ints=True): # <<<<<<<<<<<<<<
3600
* t = p % 5
3601
* if t == 1 or t == 4: # split
3602
*/
3603
__pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_bound); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 494, __pyx_L1_error)
3604
__Pyx_GOTREF(__pyx_t_2);
3605
__pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 494, __pyx_L1_error)
3606
__Pyx_GOTREF(__pyx_t_3);
3607
__Pyx_GIVEREF(__pyx_t_2);
3608
PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
3609
__pyx_t_2 = 0;
3610
__pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 494, __pyx_L1_error)
3611
__Pyx_GOTREF(__pyx_t_2);
3612
if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_py_ints, Py_True) < 0) __PYX_ERR(0, 494, __pyx_L1_error)
3613
__pyx_t_6 = __Pyx_PyObject_Call(__pyx_v_prime_range_ZZ, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 494, __pyx_L1_error)
3614
__Pyx_GOTREF(__pyx_t_6);
3615
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
3616
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3617
if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) {
3618
__pyx_t_2 = __pyx_t_6; __Pyx_INCREF(__pyx_t_2); __pyx_t_7 = 0;
3619
__pyx_t_8 = NULL;
3620
} else {
3621
__pyx_t_7 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 494, __pyx_L1_error)
3622
__Pyx_GOTREF(__pyx_t_2);
3623
__pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 494, __pyx_L1_error)
3624
}
3625
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
3626
for (;;) {
3627
if (likely(!__pyx_t_8)) {
3628
if (likely(PyList_CheckExact(__pyx_t_2))) {
3629
if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_2)) break;
3630
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
3631
__pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_6); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 494, __pyx_L1_error)
3632
#else
3633
__pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 494, __pyx_L1_error)
3634
__Pyx_GOTREF(__pyx_t_6);
3635
#endif
3636
} else {
3637
if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
3638
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
3639
__pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_6); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 494, __pyx_L1_error)
3640
#else
3641
__pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 494, __pyx_L1_error)
3642
__Pyx_GOTREF(__pyx_t_6);
3643
#endif
3644
}
3645
} else {
3646
__pyx_t_6 = __pyx_t_8(__pyx_t_2);
3647
if (unlikely(!__pyx_t_6)) {
3648
PyObject* exc_type = PyErr_Occurred();
3649
if (exc_type) {
3650
if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
3651
else __PYX_ERR(0, 494, __pyx_L1_error)
3652
}
3653
break;
3654
}
3655
__Pyx_GOTREF(__pyx_t_6);
3656
}
3657
__pyx_t_5 = __Pyx_PyInt_As_long(__pyx_t_6); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 494, __pyx_L1_error)
3658
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
3659
__pyx_v_p = __pyx_t_5;
3660
3661
/* "code/psage/number_fields/sqrt5/prime.pyx":495
3662
*
3663
* for p in prime_range_ZZ(bound, py_ints=True):
3664
* t = p % 5 # <<<<<<<<<<<<<<
3665
* if t == 1 or t == 4: # split
3666
* if p >= start:
3667
*/
3668
__pyx_v_t = __Pyx_mod_long(__pyx_v_p, 5);
3669
3670
/* "code/psage/number_fields/sqrt5/prime.pyx":496
3671
* for p in prime_range_ZZ(bound, py_ints=True):
3672
* t = p % 5
3673
* if t == 1 or t == 4: # split # <<<<<<<<<<<<<<
3674
* if p >= start:
3675
* # Compute a square root of 5 modulo p.
3676
*/
3677
switch (__pyx_v_t) {
3678
case 1:
3679
case 4:
3680
__pyx_t_4 = 1;
3681
break;
3682
default:
3683
__pyx_t_4 = 0;
3684
break;
3685
}
3686
if (__pyx_t_4) {
3687
3688
/* "code/psage/number_fields/sqrt5/prime.pyx":497
3689
* t = p % 5
3690
* if t == 1 or t == 4: # split
3691
* if p >= start: # <<<<<<<<<<<<<<
3692
* # Compute a square root of 5 modulo p.
3693
* #sr = Fl_sqrt(5, p)
3694
*/
3695
__pyx_t_4 = ((__pyx_v_p >= __pyx_v_start) != 0);
3696
if (__pyx_t_4) {
3697
3698
/* "code/psage/number_fields/sqrt5/prime.pyx":503
3699
* #r0 = Fl_div(1+sr, 2, p)
3700
* # TODO fix
3701
* r1 = p+1-r0 # <<<<<<<<<<<<<<
3702
* # Sort
3703
* if r0 > r1: r0, r1 = r1, r0
3704
*/
3705
__pyx_v_r1 = ((__pyx_v_p + 1) - __pyx_v_r0);
3706
3707
/* "code/psage/number_fields/sqrt5/prime.pyx":505
3708
* r1 = p+1-r0
3709
* # Sort
3710
* if r0 > r1: r0, r1 = r1, r0 # <<<<<<<<<<<<<<
3711
* # Append each prime to the list
3712
* P = PY_NEW(Prime); P.p = p; P.r = r0; P.first = True; v.append(P)
3713
*/
3714
__pyx_t_4 = ((__pyx_v_r0 > __pyx_v_r1) != 0);
3715
if (__pyx_t_4) {
3716
__pyx_t_5 = __pyx_v_r1;
3717
__pyx_t_9 = __pyx_v_r0;
3718
__pyx_v_r0 = __pyx_t_5;
3719
__pyx_v_r1 = __pyx_t_9;
3720
}
3721
3722
/* "code/psage/number_fields/sqrt5/prime.pyx":507
3723
* if r0 > r1: r0, r1 = r1, r0
3724
* # Append each prime to the list
3725
* P = PY_NEW(Prime); P.p = p; P.r = r0; P.first = True; v.append(P) # <<<<<<<<<<<<<<
3726
* P = PY_NEW(Prime); P.p = p; P.r = r1; P.first = False; v.append(P)
3727
* elif p == 5: # ramified
3728
*/
3729
__pyx_t_6 = __pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_PY_NEW(__pyx_ptype_4code_5psage_13number_fields_5sqrt5_5prime_Prime); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 507, __pyx_L1_error)
3730
__Pyx_GOTREF(__pyx_t_6);
3731
if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_4code_5psage_13number_fields_5sqrt5_5prime_Prime))))) __PYX_ERR(0, 507, __pyx_L1_error)
3732
__Pyx_XDECREF_SET(__pyx_v_P, ((struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_t_6));
3733
__pyx_t_6 = 0;
3734
__pyx_v_P->p = __pyx_v_p;
3735
__pyx_v_P->r = __pyx_v_r0;
3736
__pyx_v_P->first = 1;
3737
__pyx_t_10 = __Pyx_PyList_Append(__pyx_v_v, ((PyObject *)__pyx_v_P)); if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 507, __pyx_L1_error)
3738
3739
/* "code/psage/number_fields/sqrt5/prime.pyx":508
3740
* # Append each prime to the list
3741
* P = PY_NEW(Prime); P.p = p; P.r = r0; P.first = True; v.append(P)
3742
* P = PY_NEW(Prime); P.p = p; P.r = r1; P.first = False; v.append(P) # <<<<<<<<<<<<<<
3743
* elif p == 5: # ramified
3744
* if p >= start:
3745
*/
3746
__pyx_t_6 = __pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_PY_NEW(__pyx_ptype_4code_5psage_13number_fields_5sqrt5_5prime_Prime); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 508, __pyx_L1_error)
3747
__Pyx_GOTREF(__pyx_t_6);
3748
if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_4code_5psage_13number_fields_5sqrt5_5prime_Prime))))) __PYX_ERR(0, 508, __pyx_L1_error)
3749
__Pyx_DECREF_SET(__pyx_v_P, ((struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)__pyx_t_6));
3750
__pyx_t_6 = 0;
3751
__pyx_v_P->p = __pyx_v_p;
3752
__pyx_v_P->r = __pyx_v_r1;
3753
__pyx_v_P->first = 0;
3754
__pyx_t_10 = __Pyx_PyList_Append(__pyx_v_v, ((PyObject *)__pyx_v_P)); if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 508, __pyx_L1_error)
3755
3756
/* "code/psage/number_fields/sqrt5/prime.pyx":497
3757
* t = p % 5
3758
* if t == 1 or t == 4: # split
3759
* if p >= start: # <<<<<<<<<<<<<<
3760
* # Compute a square root of 5 modulo p.
3761
* #sr = Fl_sqrt(5, p)
3762
*/
3763
}
3764
3765
/* "code/psage/number_fields/sqrt5/prime.pyx":496
3766
* for p in prime_range_ZZ(bound, py_ints=True):
3767
* t = p % 5
3768
* if t == 1 or t == 4: # split # <<<<<<<<<<<<<<
3769
* if p >= start:
3770
* # Compute a square root of 5 modulo p.
3771
*/
3772
goto __pyx_L10;
3773
}
3774
3775
/* "code/psage/number_fields/sqrt5/prime.pyx":509
3776
* P = PY_NEW(Prime); P.p = p; P.r = r0; P.first = True; v.append(P)
3777
* P = PY_NEW(Prime); P.p = p; P.r = r1; P.first = False; v.append(P)
3778
* elif p == 5: # ramified # <<<<<<<<<<<<<<
3779
* if p >= start:
3780
* v.append(Prime(p, 3, True))
3781
*/
3782
__pyx_t_4 = ((__pyx_v_p == 5) != 0);
3783
if (__pyx_t_4) {
3784
3785
/* "code/psage/number_fields/sqrt5/prime.pyx":510
3786
* P = PY_NEW(Prime); P.p = p; P.r = r1; P.first = False; v.append(P)
3787
* elif p == 5: # ramified
3788
* if p >= start: # <<<<<<<<<<<<<<
3789
* v.append(Prime(p, 3, True))
3790
* else:
3791
*/
3792
__pyx_t_4 = ((__pyx_v_p >= __pyx_v_start) != 0);
3793
if (__pyx_t_4) {
3794
3795
/* "code/psage/number_fields/sqrt5/prime.pyx":511
3796
* elif p == 5: # ramified
3797
* if p >= start:
3798
* v.append(Prime(p, 3, True)) # <<<<<<<<<<<<<<
3799
* else:
3800
* p2 = p*p
3801
*/
3802
__pyx_t_6 = __Pyx_PyInt_From_long(__pyx_v_p); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 511, __pyx_L1_error)
3803
__Pyx_GOTREF(__pyx_t_6);
3804
__pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 511, __pyx_L1_error)
3805
__Pyx_GOTREF(__pyx_t_3);
3806
__Pyx_GIVEREF(__pyx_t_6);
3807
PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
3808
__Pyx_INCREF(__pyx_int_3);
3809
__Pyx_GIVEREF(__pyx_int_3);
3810
PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_3);
3811
__Pyx_INCREF(Py_True);
3812
__Pyx_GIVEREF(Py_True);
3813
PyTuple_SET_ITEM(__pyx_t_3, 2, Py_True);
3814
__pyx_t_6 = 0;
3815
__pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_4code_5psage_13number_fields_5sqrt5_5prime_Prime), __pyx_t_3, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 511, __pyx_L1_error)
3816
__Pyx_GOTREF(__pyx_t_6);
3817
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
3818
__pyx_t_10 = __Pyx_PyList_Append(__pyx_v_v, __pyx_t_6); if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 511, __pyx_L1_error)
3819
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
3820
3821
/* "code/psage/number_fields/sqrt5/prime.pyx":510
3822
* P = PY_NEW(Prime); P.p = p; P.r = r1; P.first = False; v.append(P)
3823
* elif p == 5: # ramified
3824
* if p >= start: # <<<<<<<<<<<<<<
3825
* v.append(Prime(p, 3, True))
3826
* else:
3827
*/
3828
}
3829
3830
/* "code/psage/number_fields/sqrt5/prime.pyx":509
3831
* P = PY_NEW(Prime); P.p = p; P.r = r0; P.first = True; v.append(P)
3832
* P = PY_NEW(Prime); P.p = p; P.r = r1; P.first = False; v.append(P)
3833
* elif p == 5: # ramified # <<<<<<<<<<<<<<
3834
* if p >= start:
3835
* v.append(Prime(p, 3, True))
3836
*/
3837
goto __pyx_L10;
3838
}
3839
3840
/* "code/psage/number_fields/sqrt5/prime.pyx":513
3841
* v.append(Prime(p, 3, True))
3842
* else:
3843
* p2 = p*p # <<<<<<<<<<<<<<
3844
* if p2 < bound and p2 >= start:
3845
* v.append(Prime(p, 0, True))
3846
*/
3847
/*else*/ {
3848
__pyx_v_p2 = (__pyx_v_p * __pyx_v_p);
3849
3850
/* "code/psage/number_fields/sqrt5/prime.pyx":514
3851
* else:
3852
* p2 = p*p
3853
* if p2 < bound and p2 >= start: # <<<<<<<<<<<<<<
3854
* v.append(Prime(p, 0, True))
3855
*
3856
*/
3857
__pyx_t_1 = ((__pyx_v_p2 < __pyx_v_bound) != 0);
3858
if (__pyx_t_1) {
3859
} else {
3860
__pyx_t_4 = __pyx_t_1;
3861
goto __pyx_L15_bool_binop_done;
3862
}
3863
__pyx_t_1 = ((__pyx_v_p2 >= __pyx_v_start) != 0);
3864
__pyx_t_4 = __pyx_t_1;
3865
__pyx_L15_bool_binop_done:;
3866
if (__pyx_t_4) {
3867
3868
/* "code/psage/number_fields/sqrt5/prime.pyx":515
3869
* p2 = p*p
3870
* if p2 < bound and p2 >= start:
3871
* v.append(Prime(p, 0, True)) # <<<<<<<<<<<<<<
3872
*
3873
* v.sort()
3874
*/
3875
__pyx_t_6 = __Pyx_PyInt_From_long(__pyx_v_p); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 515, __pyx_L1_error)
3876
__Pyx_GOTREF(__pyx_t_6);
3877
__pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 515, __pyx_L1_error)
3878
__Pyx_GOTREF(__pyx_t_3);
3879
__Pyx_GIVEREF(__pyx_t_6);
3880
PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
3881
__Pyx_INCREF(__pyx_int_0);
3882
__Pyx_GIVEREF(__pyx_int_0);
3883
PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
3884
__Pyx_INCREF(Py_True);
3885
__Pyx_GIVEREF(Py_True);
3886
PyTuple_SET_ITEM(__pyx_t_3, 2, Py_True);
3887
__pyx_t_6 = 0;
3888
__pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_4code_5psage_13number_fields_5sqrt5_5prime_Prime), __pyx_t_3, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 515, __pyx_L1_error)
3889
__Pyx_GOTREF(__pyx_t_6);
3890
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
3891
__pyx_t_10 = __Pyx_PyList_Append(__pyx_v_v, __pyx_t_6); if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 515, __pyx_L1_error)
3892
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
3893
3894
/* "code/psage/number_fields/sqrt5/prime.pyx":514
3895
* else:
3896
* p2 = p*p
3897
* if p2 < bound and p2 >= start: # <<<<<<<<<<<<<<
3898
* v.append(Prime(p, 0, True))
3899
*
3900
*/
3901
}
3902
}
3903
__pyx_L10:;
3904
3905
/* "code/psage/number_fields/sqrt5/prime.pyx":494
3906
* from sage.all import prime_range as prime_range_ZZ
3907
*
3908
* for p in prime_range_ZZ(bound, py_ints=True): # <<<<<<<<<<<<<<
3909
* t = p % 5
3910
* if t == 1 or t == 4: # split
3911
*/
3912
}
3913
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3914
3915
/* "code/psage/number_fields/sqrt5/prime.pyx":517
3916
* v.append(Prime(p, 0, True))
3917
*
3918
* v.sort() # <<<<<<<<<<<<<<
3919
* return v
3920
*
3921
*/
3922
__pyx_t_10 = PyList_Sort(__pyx_v_v); if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 517, __pyx_L1_error)
3923
3924
/* "code/psage/number_fields/sqrt5/prime.pyx":518
3925
*
3926
* v.sort()
3927
* return v # <<<<<<<<<<<<<<
3928
*
3929
*
3930
*/
3931
__Pyx_XDECREF(__pyx_r);
3932
__Pyx_INCREF(__pyx_v_v);
3933
__pyx_r = __pyx_v_v;
3934
goto __pyx_L0;
3935
3936
/* "code/psage/number_fields/sqrt5/prime.pyx":445
3937
* return prime_range(bound)
3938
*
3939
* def prime_range(long start, stop=None): # <<<<<<<<<<<<<<
3940
* """
3941
* Return ordered list of all prime ideals of the ring of integers of
3942
*/
3943
3944
/* function exit code */
3945
__pyx_L1_error:;
3946
__Pyx_XDECREF(__pyx_t_2);
3947
__Pyx_XDECREF(__pyx_t_3);
3948
__Pyx_XDECREF(__pyx_t_6);
3949
__Pyx_AddTraceback("code.psage.number_fields.sqrt5.prime.prime_range", __pyx_clineno, __pyx_lineno, __pyx_filename);
3950
__pyx_r = NULL;
3951
__pyx_L0:;
3952
__Pyx_XDECREF((PyObject *)__pyx_v_P);
3953
__Pyx_XDECREF(__pyx_v_v);
3954
__Pyx_XDECREF(__pyx_v_prime_range_ZZ);
3955
__Pyx_XGIVEREF(__pyx_r);
3956
__Pyx_RefNannyFinishContext();
3957
return __pyx_r;
3958
}
3959
static struct __pyx_vtabstruct_4code_5psage_13number_fields_5sqrt5_5prime_Prime __pyx_vtable_4code_5psage_13number_fields_5sqrt5_5prime_Prime;
3960
3961
static PyObject *__pyx_tp_new_4code_5psage_13number_fields_5sqrt5_5prime_Prime(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
3962
struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *p;
3963
PyObject *o;
3964
if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
3965
o = (*t->tp_alloc)(t, 0);
3966
} else {
3967
o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
3968
}
3969
if (unlikely(!o)) return 0;
3970
p = ((struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *)o);
3971
p->__pyx_vtab = __pyx_vtabptr_4code_5psage_13number_fields_5sqrt5_5prime_Prime;
3972
return o;
3973
}
3974
3975
static void __pyx_tp_dealloc_4code_5psage_13number_fields_5sqrt5_5prime_Prime(PyObject *o) {
3976
#if PY_VERSION_HEX >= 0x030400a1
3977
if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
3978
if (PyObject_CallFinalizerFromDealloc(o)) return;
3979
}
3980
#endif
3981
(*Py_TYPE(o)->tp_free)(o);
3982
}
3983
3984
static PyObject *__pyx_getprop_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_p(PyObject *o, CYTHON_UNUSED void *x) {
3985
return __pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1p_1__get__(o);
3986
}
3987
3988
static int __pyx_setprop_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_p(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
3989
if (v) {
3990
return __pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1p_3__set__(o, v);
3991
}
3992
else {
3993
PyErr_SetString(PyExc_NotImplementedError, "__del__");
3994
return -1;
3995
}
3996
}
3997
3998
static PyObject *__pyx_getprop_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_r(PyObject *o, CYTHON_UNUSED void *x) {
3999
return __pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1r_1__get__(o);
4000
}
4001
4002
static int __pyx_setprop_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_r(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
4003
if (v) {
4004
return __pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1r_3__set__(o, v);
4005
}
4006
else {
4007
PyErr_SetString(PyExc_NotImplementedError, "__del__");
4008
return -1;
4009
}
4010
}
4011
4012
static PyMethodDef __pyx_methods_4code_5psage_13number_fields_5sqrt5_5prime_Prime[] = {
4013
{"_latex_", (PyCFunction)__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_7_latex_, METH_NOARGS, __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_6_latex_},
4014
{"is_split", (PyCFunction)__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_9is_split, METH_NOARGS, __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_8is_split},
4015
{"is_inert", (PyCFunction)__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_11is_inert, METH_NOARGS, __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_10is_inert},
4016
{"is_ramified", (PyCFunction)__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_13is_ramified, METH_NOARGS, __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_12is_ramified},
4017
{"norm", (PyCFunction)__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_15norm, METH_NOARGS, __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_14norm},
4018
{"sage_ideal", (PyCFunction)__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_19sage_ideal, METH_NOARGS, __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_18sage_ideal},
4019
{0, 0, 0, 0}
4020
};
4021
4022
static struct PyGetSetDef __pyx_getsets_4code_5psage_13number_fields_5sqrt5_5prime_Prime[] = {
4023
{(char *)"p", __pyx_getprop_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_p, __pyx_setprop_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_p, (char *)0, 0},
4024
{(char *)"r", __pyx_getprop_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_r, __pyx_setprop_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_r, (char *)0, 0},
4025
{0, 0, 0, 0, 0}
4026
};
4027
4028
static PyTypeObject __pyx_type_4code_5psage_13number_fields_5sqrt5_5prime_Prime = {
4029
PyVarObject_HEAD_INIT(0, 0)
4030
"code.psage.number_fields.sqrt5.prime.Prime", /*tp_name*/
4031
sizeof(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime), /*tp_basicsize*/
4032
0, /*tp_itemsize*/
4033
__pyx_tp_dealloc_4code_5psage_13number_fields_5sqrt5_5prime_Prime, /*tp_dealloc*/
4034
0, /*tp_print*/
4035
0, /*tp_getattr*/
4036
0, /*tp_setattr*/
4037
#if PY_MAJOR_VERSION < 3
4038
__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_17__cmp__, /*tp_compare*/
4039
#endif
4040
#if PY_MAJOR_VERSION >= 3
4041
0, /*tp_as_async*/
4042
#endif
4043
__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_3__repr__, /*tp_repr*/
4044
0, /*tp_as_number*/
4045
0, /*tp_as_sequence*/
4046
0, /*tp_as_mapping*/
4047
__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_5__hash__, /*tp_hash*/
4048
0, /*tp_call*/
4049
0, /*tp_str*/
4050
0, /*tp_getattro*/
4051
0, /*tp_setattro*/
4052
0, /*tp_as_buffer*/
4053
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
4054
"\n Nonzero prime ideal of the ring of integers of Q(sqrt(5)). This\n is a fast customized Cython class; to get at the corresponding\n Sage prime ideal use the sage_ideal method.\n ", /*tp_doc*/
4055
0, /*tp_traverse*/
4056
0, /*tp_clear*/
4057
0, /*tp_richcompare*/
4058
0, /*tp_weaklistoffset*/
4059
0, /*tp_iter*/
4060
0, /*tp_iternext*/
4061
__pyx_methods_4code_5psage_13number_fields_5sqrt5_5prime_Prime, /*tp_methods*/
4062
0, /*tp_members*/
4063
__pyx_getsets_4code_5psage_13number_fields_5sqrt5_5prime_Prime, /*tp_getset*/
4064
0, /*tp_base*/
4065
0, /*tp_dict*/
4066
0, /*tp_descr_get*/
4067
0, /*tp_descr_set*/
4068
0, /*tp_dictoffset*/
4069
__pyx_pw_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_1__init__, /*tp_init*/
4070
0, /*tp_alloc*/
4071
__pyx_tp_new_4code_5psage_13number_fields_5sqrt5_5prime_Prime, /*tp_new*/
4072
0, /*tp_free*/
4073
0, /*tp_is_gc*/
4074
0, /*tp_bases*/
4075
0, /*tp_mro*/
4076
0, /*tp_cache*/
4077
0, /*tp_subclasses*/
4078
0, /*tp_weaklist*/
4079
0, /*tp_del*/
4080
0, /*tp_version_tag*/
4081
#if PY_VERSION_HEX >= 0x030400a1
4082
0, /*tp_finalize*/
4083
#endif
4084
};
4085
4086
static PyMethodDef __pyx_methods[] = {
4087
{0, 0, 0, 0}
4088
};
4089
4090
#if PY_MAJOR_VERSION >= 3
4091
static struct PyModuleDef __pyx_moduledef = {
4092
#if PY_VERSION_HEX < 0x03020000
4093
{ PyObject_HEAD_INIT(NULL) NULL, 0, NULL },
4094
#else
4095
PyModuleDef_HEAD_INIT,
4096
#endif
4097
"prime",
4098
__pyx_k_Fast_prime_ideals_of_the_ring_R, /* m_doc */
4099
-1, /* m_size */
4100
__pyx_methods /* m_methods */,
4101
NULL, /* m_reload */
4102
NULL, /* m_traverse */
4103
NULL, /* m_clear */
4104
NULL /* m_free */
4105
};
4106
#endif
4107
4108
static __Pyx_StringTabEntry __pyx_string_tab[] = {
4109
{&__pyx_n_s_F, __pyx_k_F, sizeof(__pyx_k_F), 0, 0, 1, 1},
4110
{&__pyx_n_s_Integer, __pyx_k_Integer, sizeof(__pyx_k_Integer), 0, 0, 1, 1},
4111
{&__pyx_n_s_NumberFieldFractionalIdeal, __pyx_k_NumberFieldFractionalIdeal, sizeof(__pyx_k_NumberFieldFractionalIdeal), 0, 0, 1, 1},
4112
{&__pyx_n_s_P, __pyx_k_P, sizeof(__pyx_k_P), 0, 0, 1, 1},
4113
{&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
4114
{&__pyx_n_s_a, __pyx_k_a, sizeof(__pyx_k_a), 0, 0, 1, 1},
4115
{&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1},
4116
{&__pyx_n_s_bound, __pyx_k_bound, sizeof(__pyx_k_bound), 0, 0, 1, 1},
4117
{&__pyx_kp_s_bound_must_be_less_than_2_31, __pyx_k_bound_must_be_less_than_2_31, sizeof(__pyx_k_bound_must_be_less_than_2_31), 0, 0, 1, 0},
4118
{&__pyx_n_s_check, __pyx_k_check, sizeof(__pyx_k_check), 0, 0, 1, 1},
4119
{&__pyx_n_s_code_psage_number_fields_sqrt5_p, __pyx_k_code_psage_number_fields_sqrt5_p, sizeof(__pyx_k_code_psage_number_fields_sqrt5_p), 0, 0, 1, 1},
4120
{&__pyx_n_s_first, __pyx_k_first, sizeof(__pyx_k_first), 0, 0, 1, 1},
4121
{&__pyx_n_s_gen, __pyx_k_gen, sizeof(__pyx_k_gen), 0, 0, 1, 1},
4122
{&__pyx_n_s_ideal, __pyx_k_ideal, sizeof(__pyx_k_ideal), 0, 0, 1, 1},
4123
{&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
4124
{&__pyx_n_s_is_inert, __pyx_k_is_inert, sizeof(__pyx_k_is_inert), 0, 0, 1, 1},
4125
{&__pyx_n_s_is_pseudoprime, __pyx_k_is_pseudoprime, sizeof(__pyx_k_is_pseudoprime), 0, 0, 1, 1},
4126
{&__pyx_n_s_is_ramified, __pyx_k_is_ramified, sizeof(__pyx_k_is_ramified), 0, 0, 1, 1},
4127
{&__pyx_n_s_is_split, __pyx_k_is_split, sizeof(__pyx_k_is_split), 0, 0, 1, 1},
4128
{&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
4129
{&__pyx_n_s_misc, __pyx_k_misc, sizeof(__pyx_k_misc), 0, 0, 1, 1},
4130
{&__pyx_n_s_norm, __pyx_k_norm, sizeof(__pyx_k_norm), 0, 0, 1, 1},
4131
{&__pyx_n_s_p, __pyx_k_p, sizeof(__pyx_k_p), 0, 0, 1, 1},
4132
{&__pyx_n_s_p2, __pyx_k_p2, sizeof(__pyx_k_p2), 0, 0, 1, 1},
4133
{&__pyx_kp_s_p_must_be_a_prime, __pyx_k_p_must_be_a_prime, sizeof(__pyx_k_p_must_be_a_prime), 0, 0, 1, 0},
4134
{&__pyx_n_s_pari_hnf, __pyx_k_pari_hnf, sizeof(__pyx_k_pari_hnf), 0, 0, 1, 1},
4135
{&__pyx_n_s_prime_range, __pyx_k_prime_range, sizeof(__pyx_k_prime_range), 0, 0, 1, 1},
4136
{&__pyx_n_s_prime_range_ZZ, __pyx_k_prime_range_ZZ, sizeof(__pyx_k_prime_range_ZZ), 0, 0, 1, 1},
4137
{&__pyx_n_s_primes_above, __pyx_k_primes_above, sizeof(__pyx_k_primes_above), 0, 0, 1, 1},
4138
{&__pyx_n_s_primes_of_bounded_norm, __pyx_k_primes_of_bounded_norm, sizeof(__pyx_k_primes_of_bounded_norm), 0, 0, 1, 1},
4139
{&__pyx_kp_s_projects_68c8b2b8_03ba_44d4_a0d, __pyx_k_projects_68c8b2b8_03ba_44d4_a0d, sizeof(__pyx_k_projects_68c8b2b8_03ba_44d4_a0d), 0, 0, 1, 0},
4140
{&__pyx_n_s_py_ints, __pyx_k_py_ints, sizeof(__pyx_k_py_ints), 0, 0, 1, 1},
4141
{&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1},
4142
{&__pyx_n_s_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 0, 1, 1},
4143
{&__pyx_n_s_r0, __pyx_k_r0, sizeof(__pyx_k_r0), 0, 0, 1, 1},
4144
{&__pyx_n_s_r1, __pyx_k_r1, sizeof(__pyx_k_r1), 0, 0, 1, 1},
4145
{&__pyx_n_s_repr, __pyx_k_repr, sizeof(__pyx_k_repr), 0, 0, 1, 1},
4146
{&__pyx_kp_s_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 0, 1, 0},
4147
{&__pyx_kp_s_s_s, __pyx_k_s_s, sizeof(__pyx_k_s_s), 0, 0, 1, 0},
4148
{&__pyx_n_s_sage_all, __pyx_k_sage_all, sizeof(__pyx_k_sage_all), 0, 0, 1, 1},
4149
{&__pyx_n_s_sage_rings_integer, __pyx_k_sage_rings_integer, sizeof(__pyx_k_sage_rings_integer), 0, 0, 1, 1},
4150
{&__pyx_n_s_sage_rings_number_field_number_f, __pyx_k_sage_rings_number_field_number_f, sizeof(__pyx_k_sage_rings_number_field_number_f), 0, 0, 1, 1},
4151
{&__pyx_n_s_sr, __pyx_k_sr, sizeof(__pyx_k_sr), 0, 0, 1, 1},
4152
{&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1},
4153
{&__pyx_n_s_stop, __pyx_k_stop, sizeof(__pyx_k_stop), 0, 0, 1, 1},
4154
{&__pyx_n_s_t, __pyx_k_t, sizeof(__pyx_k_t), 0, 0, 1, 1},
4155
{&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
4156
{&__pyx_n_s_v, __pyx_k_v, sizeof(__pyx_k_v), 0, 0, 1, 1},
4157
{0, 0, 0, 0, 0, 0, 0}
4158
};
4159
static int __Pyx_InitCachedBuiltins(void) {
4160
__pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 363, __pyx_L1_error)
4161
return 0;
4162
__pyx_L1_error:;
4163
return -1;
4164
}
4165
4166
static int __Pyx_InitCachedConstants(void) {
4167
__Pyx_RefNannyDeclarations
4168
__Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
4169
4170
/* "code/psage/number_fields/sqrt5/prime.pyx":151
4171
* # Set self using a prime ideal of Q(sqrt(5)).
4172
* H = p.pari_hnf()
4173
* self.p = H[0,0] # <<<<<<<<<<<<<<
4174
* self.first = True
4175
* t = self.p % 5
4176
*/
4177
__pyx_tuple_ = PyTuple_Pack(2, __pyx_int_0, __pyx_int_0); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 151, __pyx_L1_error)
4178
__Pyx_GOTREF(__pyx_tuple_);
4179
__Pyx_GIVEREF(__pyx_tuple_);
4180
4181
/* "code/psage/number_fields/sqrt5/prime.pyx":155
4182
* t = self.p % 5
4183
* if t == 1 or t == 4:
4184
* self.r = self.p - H[0,1] # <<<<<<<<<<<<<<
4185
* r1 = self.p + 1 - self.r
4186
* if self.r > r1:
4187
*/
4188
__pyx_tuple__2 = PyTuple_Pack(2, __pyx_int_0, __pyx_int_1); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 155, __pyx_L1_error)
4189
__Pyx_GOTREF(__pyx_tuple__2);
4190
__Pyx_GIVEREF(__pyx_tuple__2);
4191
4192
/* "code/psage/number_fields/sqrt5/prime.pyx":329
4193
* from sage.rings.integer import Integer
4194
*
4195
* def primes_above(long p, bint check=True): # <<<<<<<<<<<<<<
4196
* """
4197
* Return ordered list of all primes above p in the ring of integers
4198
*/
4199
__pyx_tuple__3 = PyTuple_Pack(3, __pyx_n_s_p, __pyx_n_s_check, __pyx_n_s_t); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 329, __pyx_L1_error)
4200
__Pyx_GOTREF(__pyx_tuple__3);
4201
__Pyx_GIVEREF(__pyx_tuple__3);
4202
__pyx_codeobj__4 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__3, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_projects_68c8b2b8_03ba_44d4_a0d, __pyx_n_s_primes_above, 329, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__4)) __PYX_ERR(0, 329, __pyx_L1_error)
4203
4204
/* "code/psage/number_fields/sqrt5/prime.pyx":370
4205
* return [Prime(p, 0, True)]
4206
*
4207
* def primes_of_bounded_norm(bound): # <<<<<<<<<<<<<<
4208
* """
4209
* Return ordered list of all prime ideals of the ring of integers of
4210
*/
4211
__pyx_tuple__5 = PyTuple_Pack(1, __pyx_n_s_bound); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 370, __pyx_L1_error)
4212
__Pyx_GOTREF(__pyx_tuple__5);
4213
__Pyx_GIVEREF(__pyx_tuple__5);
4214
__pyx_codeobj__6 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__5, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_projects_68c8b2b8_03ba_44d4_a0d, __pyx_n_s_primes_of_bounded_norm, 370, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__6)) __PYX_ERR(0, 370, __pyx_L1_error)
4215
4216
/* "code/psage/number_fields/sqrt5/prime.pyx":445
4217
* return prime_range(bound)
4218
*
4219
* def prime_range(long start, stop=None): # <<<<<<<<<<<<<<
4220
* """
4221
* Return ordered list of all prime ideals of the ring of integers of
4222
*/
4223
__pyx_tuple__7 = PyTuple_Pack(12, __pyx_n_s_start, __pyx_n_s_stop, __pyx_n_s_p, __pyx_n_s_p2, __pyx_n_s_sr, __pyx_n_s_r0, __pyx_n_s_r1, __pyx_n_s_t, __pyx_n_s_bound, __pyx_n_s_P, __pyx_n_s_v, __pyx_n_s_prime_range_ZZ); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 445, __pyx_L1_error)
4224
__Pyx_GOTREF(__pyx_tuple__7);
4225
__Pyx_GIVEREF(__pyx_tuple__7);
4226
__pyx_codeobj__8 = (PyObject*)__Pyx_PyCode_New(2, 0, 12, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__7, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_projects_68c8b2b8_03ba_44d4_a0d, __pyx_n_s_prime_range, 445, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__8)) __PYX_ERR(0, 445, __pyx_L1_error)
4227
__Pyx_RefNannyFinishContext();
4228
return 0;
4229
__pyx_L1_error:;
4230
__Pyx_RefNannyFinishContext();
4231
return -1;
4232
}
4233
4234
static int __Pyx_InitGlobals(void) {
4235
if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
4236
__pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
4237
__pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
4238
__pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) __PYX_ERR(0, 1, __pyx_L1_error)
4239
__pyx_int_2147483648 = PyInt_FromString((char *)"2147483648", 0, 0); if (unlikely(!__pyx_int_2147483648)) __PYX_ERR(0, 1, __pyx_L1_error)
4240
return 0;
4241
__pyx_L1_error:;
4242
return -1;
4243
}
4244
4245
#if PY_MAJOR_VERSION < 3
4246
PyMODINIT_FUNC initprime(void); /*proto*/
4247
PyMODINIT_FUNC initprime(void)
4248
#else
4249
PyMODINIT_FUNC PyInit_prime(void); /*proto*/
4250
PyMODINIT_FUNC PyInit_prime(void)
4251
#endif
4252
{
4253
PyObject *__pyx_t_1 = NULL;
4254
PyObject *__pyx_t_2 = NULL;
4255
__Pyx_RefNannyDeclarations
4256
#if CYTHON_REFNANNY
4257
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
4258
if (!__Pyx_RefNanny) {
4259
PyErr_Clear();
4260
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
4261
if (!__Pyx_RefNanny)
4262
Py_FatalError("failed to import 'refnanny' module");
4263
}
4264
#endif
4265
__Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_prime(void)", 0);
4266
if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4267
__pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
4268
__pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
4269
__pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
4270
#ifdef __Pyx_CyFunction_USED
4271
if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4272
#endif
4273
#ifdef __Pyx_FusedFunction_USED
4274
if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4275
#endif
4276
#ifdef __Pyx_Coroutine_USED
4277
if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4278
#endif
4279
#ifdef __Pyx_Generator_USED
4280
if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4281
#endif
4282
#ifdef __Pyx_StopAsyncIteration_USED
4283
if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4284
#endif
4285
/*--- Library function declarations ---*/
4286
/*--- Threads initialization code ---*/
4287
#if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
4288
#ifdef WITH_THREAD /* Python build with threading support? */
4289
PyEval_InitThreads();
4290
#endif
4291
#endif
4292
/*--- Module creation code ---*/
4293
#if PY_MAJOR_VERSION < 3
4294
__pyx_m = Py_InitModule4("prime", __pyx_methods, __pyx_k_Fast_prime_ideals_of_the_ring_R, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
4295
#else
4296
__pyx_m = PyModule_Create(&__pyx_moduledef);
4297
#endif
4298
if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
4299
__pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
4300
Py_INCREF(__pyx_d);
4301
__pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
4302
#if CYTHON_COMPILING_IN_PYPY
4303
Py_INCREF(__pyx_b);
4304
#endif
4305
if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
4306
/*--- Initialize various global constants etc. ---*/
4307
if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4308
#if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
4309
if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4310
#endif
4311
if (__pyx_module_is_main_code__psage__number_fields__sqrt5__prime) {
4312
if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4313
}
4314
#if PY_MAJOR_VERSION >= 3
4315
{
4316
PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
4317
if (!PyDict_GetItemString(modules, "code.psage.number_fields.sqrt5.prime")) {
4318
if (unlikely(PyDict_SetItemString(modules, "code.psage.number_fields.sqrt5.prime", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
4319
}
4320
}
4321
#endif
4322
/*--- Builtin init code ---*/
4323
if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4324
/*--- Constants init code ---*/
4325
if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4326
/*--- Global init code ---*/
4327
/*--- Variable export code ---*/
4328
/*--- Function export code ---*/
4329
/*--- Type init code ---*/
4330
__pyx_vtabptr_4code_5psage_13number_fields_5sqrt5_5prime_Prime = &__pyx_vtable_4code_5psage_13number_fields_5sqrt5_5prime_Prime;
4331
__pyx_vtable_4code_5psage_13number_fields_5sqrt5_5prime_Prime.norm = (long (*)(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *, int __pyx_skip_dispatch))__pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_norm;
4332
__pyx_vtable_4code_5psage_13number_fields_5sqrt5_5prime_Prime.is_split = (int (*)(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *, int __pyx_skip_dispatch))__pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_is_split;
4333
__pyx_vtable_4code_5psage_13number_fields_5sqrt5_5prime_Prime.is_inert = (int (*)(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *, int __pyx_skip_dispatch))__pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_is_inert;
4334
__pyx_vtable_4code_5psage_13number_fields_5sqrt5_5prime_Prime.is_ramified = (int (*)(struct __pyx_obj_4code_5psage_13number_fields_5sqrt5_5prime_Prime *, int __pyx_skip_dispatch))__pyx_f_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_is_ramified;
4335
if (PyType_Ready(&__pyx_type_4code_5psage_13number_fields_5sqrt5_5prime_Prime) < 0) __PYX_ERR(0, 83, __pyx_L1_error)
4336
__pyx_type_4code_5psage_13number_fields_5sqrt5_5prime_Prime.tp_print = 0;
4337
#if CYTHON_COMPILING_IN_CPYTHON
4338
{
4339
PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_4code_5psage_13number_fields_5sqrt5_5prime_Prime, "__init__"); if (unlikely(!wrapper)) __PYX_ERR(0, 83, __pyx_L1_error)
4340
if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
4341
__pyx_wrapperbase_4code_5psage_13number_fields_5sqrt5_5prime_5Prime___init__ = *((PyWrapperDescrObject *)wrapper)->d_base;
4342
__pyx_wrapperbase_4code_5psage_13number_fields_5sqrt5_5prime_5Prime___init__.doc = __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_5Prime___init__;
4343
((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_4code_5psage_13number_fields_5sqrt5_5prime_5Prime___init__;
4344
}
4345
}
4346
#endif
4347
#if CYTHON_COMPILING_IN_CPYTHON
4348
{
4349
PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_4code_5psage_13number_fields_5sqrt5_5prime_Prime, "__repr__"); if (unlikely(!wrapper)) __PYX_ERR(0, 83, __pyx_L1_error)
4350
if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
4351
__pyx_wrapperbase_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_2__repr__ = *((PyWrapperDescrObject *)wrapper)->d_base;
4352
__pyx_wrapperbase_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_2__repr__.doc = __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_2__repr__;
4353
((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_2__repr__;
4354
}
4355
}
4356
#endif
4357
#if PY_MAJOR_VERSION < 3
4358
#if CYTHON_COMPILING_IN_CPYTHON
4359
{
4360
PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_4code_5psage_13number_fields_5sqrt5_5prime_Prime, "__cmp__"); if (unlikely(!wrapper)) __PYX_ERR(0, 83, __pyx_L1_error)
4361
if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
4362
__pyx_wrapperbase_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_16__cmp__ = *((PyWrapperDescrObject *)wrapper)->d_base;
4363
__pyx_wrapperbase_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_16__cmp__.doc = __pyx_doc_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_16__cmp__;
4364
((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_4code_5psage_13number_fields_5sqrt5_5prime_5Prime_16__cmp__;
4365
}
4366
}
4367
#endif
4368
#endif
4369
if (__Pyx_SetVtable(__pyx_type_4code_5psage_13number_fields_5sqrt5_5prime_Prime.tp_dict, __pyx_vtabptr_4code_5psage_13number_fields_5sqrt5_5prime_Prime) < 0) __PYX_ERR(0, 83, __pyx_L1_error)
4370
if (PyObject_SetAttrString(__pyx_m, "Prime", (PyObject *)&__pyx_type_4code_5psage_13number_fields_5sqrt5_5prime_Prime) < 0) __PYX_ERR(0, 83, __pyx_L1_error)
4371
__pyx_ptype_4code_5psage_13number_fields_5sqrt5_5prime_Prime = &__pyx_type_4code_5psage_13number_fields_5sqrt5_5prime_Prime;
4372
/*--- Type import code ---*/
4373
__pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type",
4374
#if CYTHON_COMPILING_IN_PYPY
4375
sizeof(PyTypeObject),
4376
#else
4377
sizeof(PyHeapTypeObject),
4378
#endif
4379
0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) __PYX_ERR(2, 9, __pyx_L1_error)
4380
/*--- Variable import code ---*/
4381
/*--- Function import code ---*/
4382
/*--- Execution code ---*/
4383
#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
4384
if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4385
#endif
4386
4387
/* "code/psage/number_fields/sqrt5/prime.pyx":81
4388
* unsigned long Fl_div(unsigned long, unsigned long, unsigned long)
4389
*
4390
* from sage.rings.number_field.number_field_ideal import NumberFieldFractionalIdeal # <<<<<<<<<<<<<<
4391
*
4392
* cdef class Prime:
4393
*/
4394
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 81, __pyx_L1_error)
4395
__Pyx_GOTREF(__pyx_t_1);
4396
__Pyx_INCREF(__pyx_n_s_NumberFieldFractionalIdeal);
4397
__Pyx_GIVEREF(__pyx_n_s_NumberFieldFractionalIdeal);
4398
PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_NumberFieldFractionalIdeal);
4399
__pyx_t_2 = __Pyx_Import(__pyx_n_s_sage_rings_number_field_number_f, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 81, __pyx_L1_error)
4400
__Pyx_GOTREF(__pyx_t_2);
4401
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4402
__pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_NumberFieldFractionalIdeal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 81, __pyx_L1_error)
4403
__Pyx_GOTREF(__pyx_t_1);
4404
if (PyDict_SetItem(__pyx_d, __pyx_n_s_NumberFieldFractionalIdeal, __pyx_t_1) < 0) __PYX_ERR(0, 81, __pyx_L1_error)
4405
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4406
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4407
4408
/* "code/psage/number_fields/sqrt5/prime.pyx":327
4409
* return F.ideal(p)
4410
*
4411
* from sage.rings.integer import Integer # <<<<<<<<<<<<<<
4412
*
4413
* def primes_above(long p, bint check=True):
4414
*/
4415
__pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 327, __pyx_L1_error)
4416
__Pyx_GOTREF(__pyx_t_2);
4417
__Pyx_INCREF(__pyx_n_s_Integer);
4418
__Pyx_GIVEREF(__pyx_n_s_Integer);
4419
PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_Integer);
4420
__pyx_t_1 = __Pyx_Import(__pyx_n_s_sage_rings_integer, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 327, __pyx_L1_error)
4421
__Pyx_GOTREF(__pyx_t_1);
4422
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4423
__pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_Integer); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 327, __pyx_L1_error)
4424
__Pyx_GOTREF(__pyx_t_2);
4425
if (PyDict_SetItem(__pyx_d, __pyx_n_s_Integer, __pyx_t_2) < 0) __PYX_ERR(0, 327, __pyx_L1_error)
4426
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4427
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4428
4429
/* "code/psage/number_fields/sqrt5/prime.pyx":329
4430
* from sage.rings.integer import Integer
4431
*
4432
* def primes_above(long p, bint check=True): # <<<<<<<<<<<<<<
4433
* """
4434
* Return ordered list of all primes above p in the ring of integers
4435
*/
4436
__pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4code_5psage_13number_fields_5sqrt5_5prime_1primes_above, NULL, __pyx_n_s_code_psage_number_fields_sqrt5_p); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 329, __pyx_L1_error)
4437
__Pyx_GOTREF(__pyx_t_1);
4438
if (PyDict_SetItem(__pyx_d, __pyx_n_s_primes_above, __pyx_t_1) < 0) __PYX_ERR(0, 329, __pyx_L1_error)
4439
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4440
4441
/* "code/psage/number_fields/sqrt5/prime.pyx":370
4442
* return [Prime(p, 0, True)]
4443
*
4444
* def primes_of_bounded_norm(bound): # <<<<<<<<<<<<<<
4445
* """
4446
* Return ordered list of all prime ideals of the ring of integers of
4447
*/
4448
__pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4code_5psage_13number_fields_5sqrt5_5prime_3primes_of_bounded_norm, NULL, __pyx_n_s_code_psage_number_fields_sqrt5_p); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 370, __pyx_L1_error)
4449
__Pyx_GOTREF(__pyx_t_1);
4450
if (PyDict_SetItem(__pyx_d, __pyx_n_s_primes_of_bounded_norm, __pyx_t_1) < 0) __PYX_ERR(0, 370, __pyx_L1_error)
4451
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4452
4453
/* "code/psage/number_fields/sqrt5/prime.pyx":445
4454
* return prime_range(bound)
4455
*
4456
* def prime_range(long start, stop=None): # <<<<<<<<<<<<<<
4457
* """
4458
* Return ordered list of all prime ideals of the ring of integers of
4459
*/
4460
__pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4code_5psage_13number_fields_5sqrt5_5prime_5prime_range, NULL, __pyx_n_s_code_psage_number_fields_sqrt5_p); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 445, __pyx_L1_error)
4461
__Pyx_GOTREF(__pyx_t_1);
4462
if (PyDict_SetItem(__pyx_d, __pyx_n_s_prime_range, __pyx_t_1) < 0) __PYX_ERR(0, 445, __pyx_L1_error)
4463
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4464
4465
/* "code/psage/number_fields/sqrt5/prime.pyx":1
4466
* ################################################################################# # <<<<<<<<<<<<<<
4467
* #
4468
* # (c) Copyright 2011 William Stein
4469
*/
4470
__pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
4471
__Pyx_GOTREF(__pyx_t_1);
4472
if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
4473
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4474
4475
/*--- Wrapped vars code ---*/
4476
4477
goto __pyx_L0;
4478
__pyx_L1_error:;
4479
__Pyx_XDECREF(__pyx_t_1);
4480
__Pyx_XDECREF(__pyx_t_2);
4481
if (__pyx_m) {
4482
if (__pyx_d) {
4483
__Pyx_AddTraceback("init code.psage.number_fields.sqrt5.prime", __pyx_clineno, __pyx_lineno, __pyx_filename);
4484
}
4485
Py_DECREF(__pyx_m); __pyx_m = 0;
4486
} else if (!PyErr_Occurred()) {
4487
PyErr_SetString(PyExc_ImportError, "init code.psage.number_fields.sqrt5.prime");
4488
}
4489
__pyx_L0:;
4490
__Pyx_RefNannyFinishContext();
4491
#if PY_MAJOR_VERSION < 3
4492
return;
4493
#else
4494
return __pyx_m;
4495
#endif
4496
}
4497
4498
/* --- Runtime support code --- */
4499
/* Refnanny */
4500
#if CYTHON_REFNANNY
4501
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
4502
PyObject *m = NULL, *p = NULL;
4503
void *r = NULL;
4504
m = PyImport_ImportModule((char *)modname);
4505
if (!m) goto end;
4506
p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
4507
if (!p) goto end;
4508
r = PyLong_AsVoidPtr(p);
4509
end:
4510
Py_XDECREF(p);
4511
Py_XDECREF(m);
4512
return (__Pyx_RefNannyAPIStruct *)r;
4513
}
4514
#endif
4515
4516
/* GetBuiltinName */
4517
static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
4518
PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
4519
if (unlikely(!result)) {
4520
PyErr_Format(PyExc_NameError,
4521
#if PY_MAJOR_VERSION >= 3
4522
"name '%U' is not defined", name);
4523
#else
4524
"name '%.200s' is not defined", PyString_AS_STRING(name));
4525
#endif
4526
}
4527
return result;
4528
}
4529
4530
/* RaiseDoubleKeywords */
4531
static void __Pyx_RaiseDoubleKeywordsError(
4532
const char* func_name,
4533
PyObject* kw_name)
4534
{
4535
PyErr_Format(PyExc_TypeError,
4536
#if PY_MAJOR_VERSION >= 3
4537
"%s() got multiple values for keyword argument '%U'", func_name, kw_name);
4538
#else
4539
"%s() got multiple values for keyword argument '%s'", func_name,
4540
PyString_AsString(kw_name));
4541
#endif
4542
}
4543
4544
/* ParseKeywords */
4545
static int __Pyx_ParseOptionalKeywords(
4546
PyObject *kwds,
4547
PyObject **argnames[],
4548
PyObject *kwds2,
4549
PyObject *values[],
4550
Py_ssize_t num_pos_args,
4551
const char* function_name)
4552
{
4553
PyObject *key = 0, *value = 0;
4554
Py_ssize_t pos = 0;
4555
PyObject*** name;
4556
PyObject*** first_kw_arg = argnames + num_pos_args;
4557
while (PyDict_Next(kwds, &pos, &key, &value)) {
4558
name = first_kw_arg;
4559
while (*name && (**name != key)) name++;
4560
if (*name) {
4561
values[name-argnames] = value;
4562
continue;
4563
}
4564
name = first_kw_arg;
4565
#if PY_MAJOR_VERSION < 3
4566
if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
4567
while (*name) {
4568
if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
4569
&& _PyString_Eq(**name, key)) {
4570
values[name-argnames] = value;
4571
break;
4572
}
4573
name++;
4574
}
4575
if (*name) continue;
4576
else {
4577
PyObject*** argname = argnames;
4578
while (argname != first_kw_arg) {
4579
if ((**argname == key) || (
4580
(CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
4581
&& _PyString_Eq(**argname, key))) {
4582
goto arg_passed_twice;
4583
}
4584
argname++;
4585
}
4586
}
4587
} else
4588
#endif
4589
if (likely(PyUnicode_Check(key))) {
4590
while (*name) {
4591
int cmp = (**name == key) ? 0 :
4592
#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
4593
(PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
4594
#endif
4595
PyUnicode_Compare(**name, key);
4596
if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
4597
if (cmp == 0) {
4598
values[name-argnames] = value;
4599
break;
4600
}
4601
name++;
4602
}
4603
if (*name) continue;
4604
else {
4605
PyObject*** argname = argnames;
4606
while (argname != first_kw_arg) {
4607
int cmp = (**argname == key) ? 0 :
4608
#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
4609
(PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
4610
#endif
4611
PyUnicode_Compare(**argname, key);
4612
if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
4613
if (cmp == 0) goto arg_passed_twice;
4614
argname++;
4615
}
4616
}
4617
} else
4618
goto invalid_keyword_type;
4619
if (kwds2) {
4620
if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
4621
} else {
4622
goto invalid_keyword;
4623
}
4624
}
4625
return 0;
4626
arg_passed_twice:
4627
__Pyx_RaiseDoubleKeywordsError(function_name, key);
4628
goto bad;
4629
invalid_keyword_type:
4630
PyErr_Format(PyExc_TypeError,
4631
"%.200s() keywords must be strings", function_name);
4632
goto bad;
4633
invalid_keyword:
4634
PyErr_Format(PyExc_TypeError,
4635
#if PY_MAJOR_VERSION < 3
4636
"%.200s() got an unexpected keyword argument '%.200s'",
4637
function_name, PyString_AsString(key));
4638
#else
4639
"%s() got an unexpected keyword argument '%U'",
4640
function_name, key);
4641
#endif
4642
bad:
4643
return -1;
4644
}
4645
4646
/* RaiseArgTupleInvalid */
4647
static void __Pyx_RaiseArgtupleInvalid(
4648
const char* func_name,
4649
int exact,
4650
Py_ssize_t num_min,
4651
Py_ssize_t num_max,
4652
Py_ssize_t num_found)
4653
{
4654
Py_ssize_t num_expected;
4655
const char *more_or_less;
4656
if (num_found < num_min) {
4657
num_expected = num_min;
4658
more_or_less = "at least";
4659
} else {
4660
num_expected = num_max;
4661
more_or_less = "at most";
4662
}
4663
if (exact) {
4664
more_or_less = "exactly";
4665
}
4666
PyErr_Format(PyExc_TypeError,
4667
"%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
4668
func_name, more_or_less, num_expected,
4669
(num_expected == 1) ? "" : "s", num_found);
4670
}
4671
4672
/* GetModuleGlobalName */
4673
static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
4674
PyObject *result;
4675
#if !CYTHON_AVOID_BORROWED_REFS
4676
result = PyDict_GetItem(__pyx_d, name);
4677
if (likely(result)) {
4678
Py_INCREF(result);
4679
} else {
4680
#else
4681
result = PyObject_GetItem(__pyx_d, name);
4682
if (!result) {
4683
PyErr_Clear();
4684
#endif
4685
result = __Pyx_GetBuiltinName(name);
4686
}
4687
return result;
4688
}
4689
4690
/* PyCFunctionFastCall */
4691
#if CYTHON_FAST_PYCCALL
4692
static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
4693
PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
4694
PyCFunction meth = PyCFunction_GET_FUNCTION(func);
4695
PyObject *self = PyCFunction_GET_SELF(func);
4696
assert(PyCFunction_Check(func));
4697
assert(METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)));
4698
assert(nargs >= 0);
4699
assert(nargs == 0 || args != NULL);
4700
/* _PyCFunction_FastCallDict() must not be called with an exception set,
4701
because it may clear it (directly or indirectly) and so the
4702
caller loses its exception */
4703
assert(!PyErr_Occurred());
4704
return (*((__Pyx_PyCFunctionFast)meth)) (self, args, nargs, NULL);
4705
}
4706
#endif // CYTHON_FAST_PYCCALL
4707
4708
/* PyFunctionFastCall */
4709
#if CYTHON_FAST_PYCALL
4710
#include "frameobject.h"
4711
static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
4712
PyObject *globals) {
4713
PyFrameObject *f;
4714
PyThreadState *tstate = PyThreadState_GET();
4715
PyObject **fastlocals;
4716
Py_ssize_t i;
4717
PyObject *result;
4718
assert(globals != NULL);
4719
/* XXX Perhaps we should create a specialized
4720
PyFrame_New() that doesn't take locals, but does
4721
take builtins without sanity checking them.
4722
*/
4723
assert(tstate != NULL);
4724
f = PyFrame_New(tstate, co, globals, NULL);
4725
if (f == NULL) {
4726
return NULL;
4727
}
4728
fastlocals = f->f_localsplus;
4729
for (i = 0; i < na; i++) {
4730
Py_INCREF(*args);
4731
fastlocals[i] = *args++;
4732
}
4733
result = PyEval_EvalFrameEx(f,0);
4734
++tstate->recursion_depth;
4735
Py_DECREF(f);
4736
--tstate->recursion_depth;
4737
return result;
4738
}
4739
#if 1 || PY_VERSION_HEX < 0x030600B1
4740
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) {
4741
PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
4742
PyObject *globals = PyFunction_GET_GLOBALS(func);
4743
PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
4744
PyObject *closure;
4745
#if PY_MAJOR_VERSION >= 3
4746
PyObject *kwdefs;
4747
#endif
4748
PyObject *kwtuple, **k;
4749
PyObject **d;
4750
Py_ssize_t nd;
4751
Py_ssize_t nk;
4752
PyObject *result;
4753
assert(kwargs == NULL || PyDict_Check(kwargs));
4754
nk = kwargs ? PyDict_Size(kwargs) : 0;
4755
if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
4756
return NULL;
4757
}
4758
if (
4759
#if PY_MAJOR_VERSION >= 3
4760
co->co_kwonlyargcount == 0 &&
4761
#endif
4762
likely(kwargs == NULL || nk == 0) &&
4763
co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
4764
if (argdefs == NULL && co->co_argcount == nargs) {
4765
result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
4766
goto done;
4767
}
4768
else if (nargs == 0 && argdefs != NULL
4769
&& co->co_argcount == Py_SIZE(argdefs)) {
4770
/* function called with no arguments, but all parameters have
4771
a default value: use default values as arguments .*/
4772
args = &PyTuple_GET_ITEM(argdefs, 0);
4773
result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
4774
goto done;
4775
}
4776
}
4777
if (kwargs != NULL) {
4778
Py_ssize_t pos, i;
4779
kwtuple = PyTuple_New(2 * nk);
4780
if (kwtuple == NULL) {
4781
result = NULL;
4782
goto done;
4783
}
4784
k = &PyTuple_GET_ITEM(kwtuple, 0);
4785
pos = i = 0;
4786
while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
4787
Py_INCREF(k[i]);
4788
Py_INCREF(k[i+1]);
4789
i += 2;
4790
}
4791
nk = i / 2;
4792
}
4793
else {
4794
kwtuple = NULL;
4795
k = NULL;
4796
}
4797
closure = PyFunction_GET_CLOSURE(func);
4798
#if PY_MAJOR_VERSION >= 3
4799
kwdefs = PyFunction_GET_KW_DEFAULTS(func);
4800
#endif
4801
if (argdefs != NULL) {
4802
d = &PyTuple_GET_ITEM(argdefs, 0);
4803
nd = Py_SIZE(argdefs);
4804
}
4805
else {
4806
d = NULL;
4807
nd = 0;
4808
}
4809
#if PY_MAJOR_VERSION >= 3
4810
result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
4811
args, nargs,
4812
k, (int)nk,
4813
d, (int)nd, kwdefs, closure);
4814
#else
4815
result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
4816
args, nargs,
4817
k, (int)nk,
4818
d, (int)nd, closure);
4819
#endif
4820
Py_XDECREF(kwtuple);
4821
done:
4822
Py_LeaveRecursiveCall();
4823
return result;
4824
}
4825
#endif // CPython < 3.6
4826
#endif // CYTHON_FAST_PYCALL
4827
4828
/* PyObjectCall */
4829
#if CYTHON_COMPILING_IN_CPYTHON
4830
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
4831
PyObject *result;
4832
ternaryfunc call = func->ob_type->tp_call;
4833
if (unlikely(!call))
4834
return PyObject_Call(func, arg, kw);
4835
if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
4836
return NULL;
4837
result = (*call)(func, arg, kw);
4838
Py_LeaveRecursiveCall();
4839
if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
4840
PyErr_SetString(
4841
PyExc_SystemError,
4842
"NULL result without error in PyObject_Call");
4843
}
4844
return result;
4845
}
4846
#endif
4847
4848
/* PyObjectCallMethO */
4849
#if CYTHON_COMPILING_IN_CPYTHON
4850
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
4851
PyObject *self, *result;
4852
PyCFunction cfunc;
4853
cfunc = PyCFunction_GET_FUNCTION(func);
4854
self = PyCFunction_GET_SELF(func);
4855
if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
4856
return NULL;
4857
result = cfunc(self, arg);
4858
Py_LeaveRecursiveCall();
4859
if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
4860
PyErr_SetString(
4861
PyExc_SystemError,
4862
"NULL result without error in PyObject_Call");
4863
}
4864
return result;
4865
}
4866
#endif
4867
4868
/* PyObjectCallOneArg */
4869
#if CYTHON_COMPILING_IN_CPYTHON
4870
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
4871
PyObject *result;
4872
PyObject *args = PyTuple_New(1);
4873
if (unlikely(!args)) return NULL;
4874
Py_INCREF(arg);
4875
PyTuple_SET_ITEM(args, 0, arg);
4876
result = __Pyx_PyObject_Call(func, args, NULL);
4877
Py_DECREF(args);
4878
return result;
4879
}
4880
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
4881
#if CYTHON_FAST_PYCALL
4882
if (PyFunction_Check(func)) {
4883
return __Pyx_PyFunction_FastCall(func, &arg, 1);
4884
}
4885
#endif
4886
#ifdef __Pyx_CyFunction_USED
4887
if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
4888
#else
4889
if (likely(PyCFunction_Check(func))) {
4890
#endif
4891
if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
4892
return __Pyx_PyObject_CallMethO(func, arg);
4893
#if CYTHON_FAST_PYCCALL
4894
} else if (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) {
4895
return __Pyx_PyCFunction_FastCall(func, &arg, 1);
4896
#endif
4897
}
4898
}
4899
return __Pyx__PyObject_CallOneArg(func, arg);
4900
}
4901
#else
4902
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
4903
PyObject *result;
4904
PyObject *args = PyTuple_Pack(1, arg);
4905
if (unlikely(!args)) return NULL;
4906
result = __Pyx_PyObject_Call(func, args, NULL);
4907
Py_DECREF(args);
4908
return result;
4909
}
4910
#endif
4911
4912
/* PyObjectCallNoArg */
4913
#if CYTHON_COMPILING_IN_CPYTHON
4914
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
4915
#if CYTHON_FAST_PYCALL
4916
if (PyFunction_Check(func)) {
4917
return __Pyx_PyFunction_FastCall(func, NULL, 0);
4918
}
4919
#endif
4920
#ifdef __Pyx_CyFunction_USED
4921
if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
4922
#else
4923
if (likely(PyCFunction_Check(func))) {
4924
#endif
4925
if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
4926
return __Pyx_PyObject_CallMethO(func, NULL);
4927
}
4928
}
4929
return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
4930
}
4931
#endif
4932
4933
/* None */
4934
static CYTHON_INLINE long __Pyx_mod_long(long a, long b) {
4935
long r = a % b;
4936
r += ((r != 0) & ((r ^ b) < 0)) * b;
4937
return r;
4938
}
4939
4940
/* PyErrFetchRestore */
4941
#if CYTHON_FAST_THREAD_STATE
4942
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
4943
PyObject *tmp_type, *tmp_value, *tmp_tb;
4944
tmp_type = tstate->curexc_type;
4945
tmp_value = tstate->curexc_value;
4946
tmp_tb = tstate->curexc_traceback;
4947
tstate->curexc_type = type;
4948
tstate->curexc_value = value;
4949
tstate->curexc_traceback = tb;
4950
Py_XDECREF(tmp_type);
4951
Py_XDECREF(tmp_value);
4952
Py_XDECREF(tmp_tb);
4953
}
4954
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
4955
*type = tstate->curexc_type;
4956
*value = tstate->curexc_value;
4957
*tb = tstate->curexc_traceback;
4958
tstate->curexc_type = 0;
4959
tstate->curexc_value = 0;
4960
tstate->curexc_traceback = 0;
4961
}
4962
#endif
4963
4964
/* WriteUnraisableException */
4965
static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
4966
CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
4967
int full_traceback, CYTHON_UNUSED int nogil) {
4968
PyObject *old_exc, *old_val, *old_tb;
4969
PyObject *ctx;
4970
__Pyx_PyThreadState_declare
4971
#ifdef WITH_THREAD
4972
PyGILState_STATE state;
4973
if (nogil)
4974
state = PyGILState_Ensure();
4975
#ifdef _MSC_VER
4976
else state = (PyGILState_STATE)-1;
4977
#endif
4978
#endif
4979
__Pyx_PyThreadState_assign
4980
__Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
4981
if (full_traceback) {
4982
Py_XINCREF(old_exc);
4983
Py_XINCREF(old_val);
4984
Py_XINCREF(old_tb);
4985
__Pyx_ErrRestore(old_exc, old_val, old_tb);
4986
PyErr_PrintEx(1);
4987
}
4988
#if PY_MAJOR_VERSION < 3
4989
ctx = PyString_FromString(name);
4990
#else
4991
ctx = PyUnicode_FromString(name);
4992
#endif
4993
__Pyx_ErrRestore(old_exc, old_val, old_tb);
4994
if (!ctx) {
4995
PyErr_WriteUnraisable(Py_None);
4996
} else {
4997
PyErr_WriteUnraisable(ctx);
4998
Py_DECREF(ctx);
4999
}
5000
#ifdef WITH_THREAD
5001
if (nogil)
5002
PyGILState_Release(state);
5003
#endif
5004
}
5005
5006
/* ArgTypeTest */
5007
static void __Pyx_RaiseArgumentTypeInvalid(const char* name, PyObject *obj, PyTypeObject *type) {
5008
PyErr_Format(PyExc_TypeError,
5009
"Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
5010
name, type->tp_name, Py_TYPE(obj)->tp_name);
5011
}
5012
static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
5013
const char *name, int exact)
5014
{
5015
if (unlikely(!type)) {
5016
PyErr_SetString(PyExc_SystemError, "Missing type object");
5017
return 0;
5018
}
5019
if (none_allowed && obj == Py_None) return 1;
5020
else if (exact) {
5021
if (likely(Py_TYPE(obj) == type)) return 1;
5022
#if PY_MAJOR_VERSION == 2
5023
else if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
5024
#endif
5025
}
5026
else {
5027
if (likely(PyObject_TypeCheck(obj, type))) return 1;
5028
}
5029
__Pyx_RaiseArgumentTypeInvalid(name, obj, type);
5030
return 0;
5031
}
5032
5033
/* Import */
5034
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
5035
PyObject *empty_list = 0;
5036
PyObject *module = 0;
5037
PyObject *global_dict = 0;
5038
PyObject *empty_dict = 0;
5039
PyObject *list;
5040
#if PY_VERSION_HEX < 0x03030000
5041
PyObject *py_import;
5042
py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
5043
if (!py_import)
5044
goto bad;
5045
#endif
5046
if (from_list)
5047
list = from_list;
5048
else {
5049
empty_list = PyList_New(0);
5050
if (!empty_list)
5051
goto bad;
5052
list = empty_list;
5053
}
5054
global_dict = PyModule_GetDict(__pyx_m);
5055
if (!global_dict)
5056
goto bad;
5057
empty_dict = PyDict_New();
5058
if (!empty_dict)
5059
goto bad;
5060
{
5061
#if PY_MAJOR_VERSION >= 3
5062
if (level == -1) {
5063
if (strchr(__Pyx_MODULE_NAME, '.')) {
5064
#if PY_VERSION_HEX < 0x03030000
5065
PyObject *py_level = PyInt_FromLong(1);
5066
if (!py_level)
5067
goto bad;
5068
module = PyObject_CallFunctionObjArgs(py_import,
5069
name, global_dict, empty_dict, list, py_level, NULL);
5070
Py_DECREF(py_level);
5071
#else
5072
module = PyImport_ImportModuleLevelObject(
5073
name, global_dict, empty_dict, list, 1);
5074
#endif
5075
if (!module) {
5076
if (!PyErr_ExceptionMatches(PyExc_ImportError))
5077
goto bad;
5078
PyErr_Clear();
5079
}
5080
}
5081
level = 0;
5082
}
5083
#endif
5084
if (!module) {
5085
#if PY_VERSION_HEX < 0x03030000
5086
PyObject *py_level = PyInt_FromLong(level);
5087
if (!py_level)
5088
goto bad;
5089
module = PyObject_CallFunctionObjArgs(py_import,
5090
name, global_dict, empty_dict, list, py_level, NULL);
5091
Py_DECREF(py_level);
5092
#else
5093
module = PyImport_ImportModuleLevelObject(
5094
name, global_dict, empty_dict, list, level);
5095
#endif
5096
}
5097
}
5098
bad:
5099
#if PY_VERSION_HEX < 0x03030000
5100
Py_XDECREF(py_import);
5101
#endif
5102
Py_XDECREF(empty_list);
5103
Py_XDECREF(empty_dict);
5104
return module;
5105
}
5106
5107
/* ImportFrom */
5108
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
5109
PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
5110
if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
5111
PyErr_Format(PyExc_ImportError,
5112
#if PY_MAJOR_VERSION < 3
5113
"cannot import name %.230s", PyString_AS_STRING(name));
5114
#else
5115
"cannot import name %S", name);
5116
#endif
5117
}
5118
return value;
5119
}
5120
5121
/* RaiseException */
5122
#if PY_MAJOR_VERSION < 3
5123
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
5124
CYTHON_UNUSED PyObject *cause) {
5125
__Pyx_PyThreadState_declare
5126
Py_XINCREF(type);
5127
if (!value || value == Py_None)
5128
value = NULL;
5129
else
5130
Py_INCREF(value);
5131
if (!tb || tb == Py_None)
5132
tb = NULL;
5133
else {
5134
Py_INCREF(tb);
5135
if (!PyTraceBack_Check(tb)) {
5136
PyErr_SetString(PyExc_TypeError,
5137
"raise: arg 3 must be a traceback or None");
5138
goto raise_error;
5139
}
5140
}
5141
if (PyType_Check(type)) {
5142
#if CYTHON_COMPILING_IN_PYPY
5143
if (!value) {
5144
Py_INCREF(Py_None);
5145
value = Py_None;
5146
}
5147
#endif
5148
PyErr_NormalizeException(&type, &value, &tb);
5149
} else {
5150
if (value) {
5151
PyErr_SetString(PyExc_TypeError,
5152
"instance exception may not have a separate value");
5153
goto raise_error;
5154
}
5155
value = type;
5156
type = (PyObject*) Py_TYPE(type);
5157
Py_INCREF(type);
5158
if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
5159
PyErr_SetString(PyExc_TypeError,
5160
"raise: exception class must be a subclass of BaseException");
5161
goto raise_error;
5162
}
5163
}
5164
__Pyx_PyThreadState_assign
5165
__Pyx_ErrRestore(type, value, tb);
5166
return;
5167
raise_error:
5168
Py_XDECREF(value);
5169
Py_XDECREF(type);
5170
Py_XDECREF(tb);
5171
return;
5172
}
5173
#else
5174
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
5175
PyObject* owned_instance = NULL;
5176
if (tb == Py_None) {
5177
tb = 0;
5178
} else if (tb && !PyTraceBack_Check(tb)) {
5179
PyErr_SetString(PyExc_TypeError,
5180
"raise: arg 3 must be a traceback or None");
5181
goto bad;
5182
}
5183
if (value == Py_None)
5184
value = 0;
5185
if (PyExceptionInstance_Check(type)) {
5186
if (value) {
5187
PyErr_SetString(PyExc_TypeError,
5188
"instance exception may not have a separate value");
5189
goto bad;
5190
}
5191
value = type;
5192
type = (PyObject*) Py_TYPE(value);
5193
} else if (PyExceptionClass_Check(type)) {
5194
PyObject *instance_class = NULL;
5195
if (value && PyExceptionInstance_Check(value)) {
5196
instance_class = (PyObject*) Py_TYPE(value);
5197
if (instance_class != type) {
5198
int is_subclass = PyObject_IsSubclass(instance_class, type);
5199
if (!is_subclass) {
5200
instance_class = NULL;
5201
} else if (unlikely(is_subclass == -1)) {
5202
goto bad;
5203
} else {
5204
type = instance_class;
5205
}
5206
}
5207
}
5208
if (!instance_class) {
5209
PyObject *args;
5210
if (!value)
5211
args = PyTuple_New(0);
5212
else if (PyTuple_Check(value)) {
5213
Py_INCREF(value);
5214
args = value;
5215
} else
5216
args = PyTuple_Pack(1, value);
5217
if (!args)
5218
goto bad;
5219
owned_instance = PyObject_Call(type, args, NULL);
5220
Py_DECREF(args);
5221
if (!owned_instance)
5222
goto bad;
5223
value = owned_instance;
5224
if (!PyExceptionInstance_Check(value)) {
5225
PyErr_Format(PyExc_TypeError,
5226
"calling %R should have returned an instance of "
5227
"BaseException, not %R",
5228
type, Py_TYPE(value));
5229
goto bad;
5230
}
5231
}
5232
} else {
5233
PyErr_SetString(PyExc_TypeError,
5234
"raise: exception class must be a subclass of BaseException");
5235
goto bad;
5236
}
5237
#if PY_VERSION_HEX >= 0x03030000
5238
if (cause) {
5239
#else
5240
if (cause && cause != Py_None) {
5241
#endif
5242
PyObject *fixed_cause;
5243
if (cause == Py_None) {
5244
fixed_cause = NULL;
5245
} else if (PyExceptionClass_Check(cause)) {
5246
fixed_cause = PyObject_CallObject(cause, NULL);
5247
if (fixed_cause == NULL)
5248
goto bad;
5249
} else if (PyExceptionInstance_Check(cause)) {
5250
fixed_cause = cause;
5251
Py_INCREF(fixed_cause);
5252
} else {
5253
PyErr_SetString(PyExc_TypeError,
5254
"exception causes must derive from "
5255
"BaseException");
5256
goto bad;
5257
}
5258
PyException_SetCause(value, fixed_cause);
5259
}
5260
PyErr_SetObject(type, value);
5261
if (tb) {
5262
#if CYTHON_COMPILING_IN_PYPY
5263
PyObject *tmp_type, *tmp_value, *tmp_tb;
5264
PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
5265
Py_INCREF(tb);
5266
PyErr_Restore(tmp_type, tmp_value, tb);
5267
Py_XDECREF(tmp_tb);
5268
#else
5269
PyThreadState *tstate = PyThreadState_GET();
5270
PyObject* tmp_tb = tstate->curexc_traceback;
5271
if (tb != tmp_tb) {
5272
Py_INCREF(tb);
5273
tstate->curexc_traceback = tb;
5274
Py_XDECREF(tmp_tb);
5275
}
5276
#endif
5277
}
5278
bad:
5279
Py_XDECREF(owned_instance);
5280
return;
5281
}
5282
#endif
5283
5284
/* ExtTypeTest */
5285
static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
5286
if (unlikely(!type)) {
5287
PyErr_SetString(PyExc_SystemError, "Missing type object");
5288
return 0;
5289
}
5290
if (likely(PyObject_TypeCheck(obj, type)))
5291
return 1;
5292
PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
5293
Py_TYPE(obj)->tp_name, type->tp_name);
5294
return 0;
5295
}
5296
5297
/* SetVTable */
5298
static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
5299
#if PY_VERSION_HEX >= 0x02070000
5300
PyObject *ob = PyCapsule_New(vtable, 0, 0);
5301
#else
5302
PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
5303
#endif
5304
if (!ob)
5305
goto bad;
5306
if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0)
5307
goto bad;
5308
Py_DECREF(ob);
5309
return 0;
5310
bad:
5311
Py_XDECREF(ob);
5312
return -1;
5313
}
5314
5315
/* CodeObjectCache */
5316
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
5317
int start = 0, mid = 0, end = count - 1;
5318
if (end >= 0 && code_line > entries[end].code_line) {
5319
return count;
5320
}
5321
while (start < end) {
5322
mid = start + (end - start) / 2;
5323
if (code_line < entries[mid].code_line) {
5324
end = mid;
5325
} else if (code_line > entries[mid].code_line) {
5326
start = mid + 1;
5327
} else {
5328
return mid;
5329
}
5330
}
5331
if (code_line <= entries[mid].code_line) {
5332
return mid;
5333
} else {
5334
return mid + 1;
5335
}
5336
}
5337
static PyCodeObject *__pyx_find_code_object(int code_line) {
5338
PyCodeObject* code_object;
5339
int pos;
5340
if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
5341
return NULL;
5342
}
5343
pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
5344
if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
5345
return NULL;
5346
}
5347
code_object = __pyx_code_cache.entries[pos].code_object;
5348
Py_INCREF(code_object);
5349
return code_object;
5350
}
5351
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
5352
int pos, i;
5353
__Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
5354
if (unlikely(!code_line)) {
5355
return;
5356
}
5357
if (unlikely(!entries)) {
5358
entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
5359
if (likely(entries)) {
5360
__pyx_code_cache.entries = entries;
5361
__pyx_code_cache.max_count = 64;
5362
__pyx_code_cache.count = 1;
5363
entries[0].code_line = code_line;
5364
entries[0].code_object = code_object;
5365
Py_INCREF(code_object);
5366
}
5367
return;
5368
}
5369
pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
5370
if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
5371
PyCodeObject* tmp = entries[pos].code_object;
5372
entries[pos].code_object = code_object;
5373
Py_DECREF(tmp);
5374
return;
5375
}
5376
if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
5377
int new_max = __pyx_code_cache.max_count + 64;
5378
entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
5379
__pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry));
5380
if (unlikely(!entries)) {
5381
return;
5382
}
5383
__pyx_code_cache.entries = entries;
5384
__pyx_code_cache.max_count = new_max;
5385
}
5386
for (i=__pyx_code_cache.count; i>pos; i--) {
5387
entries[i] = entries[i-1];
5388
}
5389
entries[pos].code_line = code_line;
5390
entries[pos].code_object = code_object;
5391
__pyx_code_cache.count++;
5392
Py_INCREF(code_object);
5393
}
5394
5395
/* AddTraceback */
5396
#include "compile.h"
5397
#include "frameobject.h"
5398
#include "traceback.h"
5399
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
5400
const char *funcname, int c_line,
5401
int py_line, const char *filename) {
5402
PyCodeObject *py_code = 0;
5403
PyObject *py_srcfile = 0;
5404
PyObject *py_funcname = 0;
5405
#if PY_MAJOR_VERSION < 3
5406
py_srcfile = PyString_FromString(filename);
5407
#else
5408
py_srcfile = PyUnicode_FromString(filename);
5409
#endif
5410
if (!py_srcfile) goto bad;
5411
if (c_line) {
5412
#if PY_MAJOR_VERSION < 3
5413
py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
5414
#else
5415
py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
5416
#endif
5417
}
5418
else {
5419
#if PY_MAJOR_VERSION < 3
5420
py_funcname = PyString_FromString(funcname);
5421
#else
5422
py_funcname = PyUnicode_FromString(funcname);
5423
#endif
5424
}
5425
if (!py_funcname) goto bad;
5426
py_code = __Pyx_PyCode_New(
5427
0,
5428
0,
5429
0,
5430
0,
5431
0,
5432
__pyx_empty_bytes, /*PyObject *code,*/
5433
__pyx_empty_tuple, /*PyObject *consts,*/
5434
__pyx_empty_tuple, /*PyObject *names,*/
5435
__pyx_empty_tuple, /*PyObject *varnames,*/
5436
__pyx_empty_tuple, /*PyObject *freevars,*/
5437
__pyx_empty_tuple, /*PyObject *cellvars,*/
5438
py_srcfile, /*PyObject *filename,*/
5439
py_funcname, /*PyObject *name,*/
5440
py_line,
5441
__pyx_empty_bytes /*PyObject *lnotab*/
5442
);
5443
Py_DECREF(py_srcfile);
5444
Py_DECREF(py_funcname);
5445
return py_code;
5446
bad:
5447
Py_XDECREF(py_srcfile);
5448
Py_XDECREF(py_funcname);
5449
return NULL;
5450
}
5451
static void __Pyx_AddTraceback(const char *funcname, int c_line,
5452
int py_line, const char *filename) {
5453
PyCodeObject *py_code = 0;
5454
PyFrameObject *py_frame = 0;
5455
py_code = __pyx_find_code_object(c_line ? c_line : py_line);
5456
if (!py_code) {
5457
py_code = __Pyx_CreateCodeObjectForTraceback(
5458
funcname, c_line, py_line, filename);
5459
if (!py_code) goto bad;
5460
__pyx_insert_code_object(c_line ? c_line : py_line, py_code);
5461
}
5462
py_frame = PyFrame_New(
5463
PyThreadState_GET(), /*PyThreadState *tstate,*/
5464
py_code, /*PyCodeObject *code,*/
5465
__pyx_d, /*PyObject *globals,*/
5466
0 /*PyObject *locals*/
5467
);
5468
if (!py_frame) goto bad;
5469
__Pyx_PyFrame_SetLineNumber(py_frame, py_line);
5470
PyTraceBack_Here(py_frame);
5471
bad:
5472
Py_XDECREF(py_code);
5473
Py_XDECREF(py_frame);
5474
}
5475
5476
/* CIntFromPyVerify */
5477
#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
5478
__PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
5479
#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
5480
__PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
5481
#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
5482
{\
5483
func_type value = func_value;\
5484
if (sizeof(target_type) < sizeof(func_type)) {\
5485
if (unlikely(value != (func_type) (target_type) value)) {\
5486
func_type zero = 0;\
5487
if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
5488
return (target_type) -1;\
5489
if (is_unsigned && unlikely(value < zero))\
5490
goto raise_neg_overflow;\
5491
else\
5492
goto raise_overflow;\
5493
}\
5494
}\
5495
return (target_type) value;\
5496
}
5497
5498
/* CIntToPy */
5499
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
5500
const long neg_one = (long) -1, const_zero = (long) 0;
5501
const int is_unsigned = neg_one > const_zero;
5502
if (is_unsigned) {
5503
if (sizeof(long) < sizeof(long)) {
5504
return PyInt_FromLong((long) value);
5505
} else if (sizeof(long) <= sizeof(unsigned long)) {
5506
return PyLong_FromUnsignedLong((unsigned long) value);
5507
#ifdef HAVE_LONG_LONG
5508
} else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
5509
return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
5510
#endif
5511
}
5512
} else {
5513
if (sizeof(long) <= sizeof(long)) {
5514
return PyInt_FromLong((long) value);
5515
#ifdef HAVE_LONG_LONG
5516
} else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
5517
return PyLong_FromLongLong((PY_LONG_LONG) value);
5518
#endif
5519
}
5520
}
5521
{
5522
int one = 1; int little = (int)*(unsigned char *)&one;
5523
unsigned char *bytes = (unsigned char *)&value;
5524
return _PyLong_FromByteArray(bytes, sizeof(long),
5525
little, !is_unsigned);
5526
}
5527
}
5528
5529
/* CIntFromPy */
5530
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
5531
const long neg_one = (long) -1, const_zero = (long) 0;
5532
const int is_unsigned = neg_one > const_zero;
5533
#if PY_MAJOR_VERSION < 3
5534
if (likely(PyInt_Check(x))) {
5535
if (sizeof(long) < sizeof(long)) {
5536
__PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
5537
} else {
5538
long val = PyInt_AS_LONG(x);
5539
if (is_unsigned && unlikely(val < 0)) {
5540
goto raise_neg_overflow;
5541
}
5542
return (long) val;
5543
}
5544
} else
5545
#endif
5546
if (likely(PyLong_Check(x))) {
5547
if (is_unsigned) {
5548
#if CYTHON_USE_PYLONG_INTERNALS
5549
const digit* digits = ((PyLongObject*)x)->ob_digit;
5550
switch (Py_SIZE(x)) {
5551
case 0: return (long) 0;
5552
case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
5553
case 2:
5554
if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
5555
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
5556
__PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5557
} else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
5558
return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
5559
}
5560
}
5561
break;
5562
case 3:
5563
if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
5564
if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
5565
__PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5566
} else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
5567
return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
5568
}
5569
}
5570
break;
5571
case 4:
5572
if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
5573
if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
5574
__PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5575
} else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
5576
return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
5577
}
5578
}
5579
break;
5580
}
5581
#endif
5582
#if CYTHON_COMPILING_IN_CPYTHON
5583
if (unlikely(Py_SIZE(x) < 0)) {
5584
goto raise_neg_overflow;
5585
}
5586
#else
5587
{
5588
int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
5589
if (unlikely(result < 0))
5590
return (long) -1;
5591
if (unlikely(result == 1))
5592
goto raise_neg_overflow;
5593
}
5594
#endif
5595
if (sizeof(long) <= sizeof(unsigned long)) {
5596
__PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
5597
#ifdef HAVE_LONG_LONG
5598
} else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
5599
__PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
5600
#endif
5601
}
5602
} else {
5603
#if CYTHON_USE_PYLONG_INTERNALS
5604
const digit* digits = ((PyLongObject*)x)->ob_digit;
5605
switch (Py_SIZE(x)) {
5606
case 0: return (long) 0;
5607
case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
5608
case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0])
5609
case -2:
5610
if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
5611
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
5612
__PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5613
} else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
5614
return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
5615
}
5616
}
5617
break;
5618
case 2:
5619
if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
5620
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
5621
__PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5622
} else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
5623
return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
5624
}
5625
}
5626
break;
5627
case -3:
5628
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
5629
if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
5630
__PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5631
} else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
5632
return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
5633
}
5634
}
5635
break;
5636
case 3:
5637
if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
5638
if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
5639
__PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5640
} else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
5641
return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
5642
}
5643
}
5644
break;
5645
case -4:
5646
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
5647
if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
5648
__PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5649
} else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
5650
return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
5651
}
5652
}
5653
break;
5654
case 4:
5655
if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
5656
if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
5657
__PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5658
} else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
5659
return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
5660
}
5661
}
5662
break;
5663
}
5664
#endif
5665
if (sizeof(long) <= sizeof(long)) {
5666
__PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
5667
#ifdef HAVE_LONG_LONG
5668
} else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
5669
__PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
5670
#endif
5671
}
5672
}
5673
{
5674
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
5675
PyErr_SetString(PyExc_RuntimeError,
5676
"_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
5677
#else
5678
long val;
5679
PyObject *v = __Pyx_PyNumber_IntOrLong(x);
5680
#if PY_MAJOR_VERSION < 3
5681
if (likely(v) && !PyLong_Check(v)) {
5682
PyObject *tmp = v;
5683
v = PyNumber_Long(tmp);
5684
Py_DECREF(tmp);
5685
}
5686
#endif
5687
if (likely(v)) {
5688
int one = 1; int is_little = (int)*(unsigned char *)&one;
5689
unsigned char *bytes = (unsigned char *)&val;
5690
int ret = _PyLong_AsByteArray((PyLongObject *)v,
5691
bytes, sizeof(val),
5692
is_little, !is_unsigned);
5693
Py_DECREF(v);
5694
if (likely(!ret))
5695
return val;
5696
}
5697
#endif
5698
return (long) -1;
5699
}
5700
} else {
5701
long val;
5702
PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
5703
if (!tmp) return (long) -1;
5704
val = __Pyx_PyInt_As_long(tmp);
5705
Py_DECREF(tmp);
5706
return val;
5707
}
5708
raise_overflow:
5709
PyErr_SetString(PyExc_OverflowError,
5710
"value too large to convert to long");
5711
return (long) -1;
5712
raise_neg_overflow:
5713
PyErr_SetString(PyExc_OverflowError,
5714
"can't convert negative value to long");
5715
return (long) -1;
5716
}
5717
5718
/* CIntFromPy */
5719
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
5720
const int neg_one = (int) -1, const_zero = (int) 0;
5721
const int is_unsigned = neg_one > const_zero;
5722
#if PY_MAJOR_VERSION < 3
5723
if (likely(PyInt_Check(x))) {
5724
if (sizeof(int) < sizeof(long)) {
5725
__PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
5726
} else {
5727
long val = PyInt_AS_LONG(x);
5728
if (is_unsigned && unlikely(val < 0)) {
5729
goto raise_neg_overflow;
5730
}
5731
return (int) val;
5732
}
5733
} else
5734
#endif
5735
if (likely(PyLong_Check(x))) {
5736
if (is_unsigned) {
5737
#if CYTHON_USE_PYLONG_INTERNALS
5738
const digit* digits = ((PyLongObject*)x)->ob_digit;
5739
switch (Py_SIZE(x)) {
5740
case 0: return (int) 0;
5741
case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
5742
case 2:
5743
if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
5744
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
5745
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5746
} else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
5747
return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
5748
}
5749
}
5750
break;
5751
case 3:
5752
if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
5753
if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
5754
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5755
} else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
5756
return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
5757
}
5758
}
5759
break;
5760
case 4:
5761
if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
5762
if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
5763
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5764
} else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
5765
return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
5766
}
5767
}
5768
break;
5769
}
5770
#endif
5771
#if CYTHON_COMPILING_IN_CPYTHON
5772
if (unlikely(Py_SIZE(x) < 0)) {
5773
goto raise_neg_overflow;
5774
}
5775
#else
5776
{
5777
int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
5778
if (unlikely(result < 0))
5779
return (int) -1;
5780
if (unlikely(result == 1))
5781
goto raise_neg_overflow;
5782
}
5783
#endif
5784
if (sizeof(int) <= sizeof(unsigned long)) {
5785
__PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
5786
#ifdef HAVE_LONG_LONG
5787
} else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
5788
__PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
5789
#endif
5790
}
5791
} else {
5792
#if CYTHON_USE_PYLONG_INTERNALS
5793
const digit* digits = ((PyLongObject*)x)->ob_digit;
5794
switch (Py_SIZE(x)) {
5795
case 0: return (int) 0;
5796
case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
5797
case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0])
5798
case -2:
5799
if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
5800
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
5801
__PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5802
} else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
5803
return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
5804
}
5805
}
5806
break;
5807
case 2:
5808
if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
5809
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
5810
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5811
} else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
5812
return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
5813
}
5814
}
5815
break;
5816
case -3:
5817
if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
5818
if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
5819
__PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5820
} else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
5821
return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
5822
}
5823
}
5824
break;
5825
case 3:
5826
if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
5827
if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
5828
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5829
} else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
5830
return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
5831
}
5832
}
5833
break;
5834
case -4:
5835
if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
5836
if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
5837
__PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5838
} else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
5839
return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
5840
}
5841
}
5842
break;
5843
case 4:
5844
if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
5845
if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
5846
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
5847
} else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
5848
return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
5849
}
5850
}
5851
break;
5852
}
5853
#endif
5854
if (sizeof(int) <= sizeof(long)) {
5855
__PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
5856
#ifdef HAVE_LONG_LONG
5857
} else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
5858
__PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
5859
#endif
5860
}
5861
}
5862
{
5863
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
5864
PyErr_SetString(PyExc_RuntimeError,
5865
"_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
5866
#else
5867
int val;
5868
PyObject *v = __Pyx_PyNumber_IntOrLong(x);
5869
#if PY_MAJOR_VERSION < 3
5870
if (likely(v) && !PyLong_Check(v)) {
5871
PyObject *tmp = v;
5872
v = PyNumber_Long(tmp);
5873
Py_DECREF(tmp);
5874
}
5875
#endif
5876
if (likely(v)) {
5877
int one = 1; int is_little = (int)*(unsigned char *)&one;
5878
unsigned char *bytes = (unsigned char *)&val;
5879
int ret = _PyLong_AsByteArray((PyLongObject *)v,
5880
bytes, sizeof(val),
5881
is_little, !is_unsigned);
5882
Py_DECREF(v);
5883
if (likely(!ret))
5884
return val;
5885
}
5886
#endif
5887
return (int) -1;
5888
}
5889
} else {
5890
int val;
5891
PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
5892
if (!tmp) return (int) -1;
5893
val = __Pyx_PyInt_As_int(tmp);
5894
Py_DECREF(tmp);
5895
return val;
5896
}
5897
raise_overflow:
5898
PyErr_SetString(PyExc_OverflowError,
5899
"value too large to convert to int");
5900
return (int) -1;
5901
raise_neg_overflow:
5902
PyErr_SetString(PyExc_OverflowError,
5903
"can't convert negative value to int");
5904
return (int) -1;
5905
}
5906
5907
/* CheckBinaryVersion */
5908
static int __Pyx_check_binary_version(void) {
5909
char ctversion[4], rtversion[4];
5910
PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
5911
PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
5912
if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
5913
char message[200];
5914
PyOS_snprintf(message, sizeof(message),
5915
"compiletime version %s of module '%.100s' "
5916
"does not match runtime version %s",
5917
ctversion, __Pyx_MODULE_NAME, rtversion);
5918
return PyErr_WarnEx(NULL, message, 1);
5919
}
5920
return 0;
5921
}
5922
5923
/* ModuleImport */
5924
#ifndef __PYX_HAVE_RT_ImportModule
5925
#define __PYX_HAVE_RT_ImportModule
5926
static PyObject *__Pyx_ImportModule(const char *name) {
5927
PyObject *py_name = 0;
5928
PyObject *py_module = 0;
5929
py_name = __Pyx_PyIdentifier_FromString(name);
5930
if (!py_name)
5931
goto bad;
5932
py_module = PyImport_Import(py_name);
5933
Py_DECREF(py_name);
5934
return py_module;
5935
bad:
5936
Py_XDECREF(py_name);
5937
return 0;
5938
}
5939
#endif
5940
5941
/* TypeImport */
5942
#ifndef __PYX_HAVE_RT_ImportType
5943
#define __PYX_HAVE_RT_ImportType
5944
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
5945
size_t size, int strict)
5946
{
5947
PyObject *py_module = 0;
5948
PyObject *result = 0;
5949
PyObject *py_name = 0;
5950
char warning[200];
5951
Py_ssize_t basicsize;
5952
#ifdef Py_LIMITED_API
5953
PyObject *py_basicsize;
5954
#endif
5955
py_module = __Pyx_ImportModule(module_name);
5956
if (!py_module)
5957
goto bad;
5958
py_name = __Pyx_PyIdentifier_FromString(class_name);
5959
if (!py_name)
5960
goto bad;
5961
result = PyObject_GetAttr(py_module, py_name);
5962
Py_DECREF(py_name);
5963
py_name = 0;
5964
Py_DECREF(py_module);
5965
py_module = 0;
5966
if (!result)
5967
goto bad;
5968
if (!PyType_Check(result)) {
5969
PyErr_Format(PyExc_TypeError,
5970
"%.200s.%.200s is not a type object",
5971
module_name, class_name);
5972
goto bad;
5973
}
5974
#ifndef Py_LIMITED_API
5975
basicsize = ((PyTypeObject *)result)->tp_basicsize;
5976
#else
5977
py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
5978
if (!py_basicsize)
5979
goto bad;
5980
basicsize = PyLong_AsSsize_t(py_basicsize);
5981
Py_DECREF(py_basicsize);
5982
py_basicsize = 0;
5983
if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
5984
goto bad;
5985
#endif
5986
if (!strict && (size_t)basicsize > size) {
5987
PyOS_snprintf(warning, sizeof(warning),
5988
"%s.%s size changed, may indicate binary incompatibility. Expected %zd, got %zd",
5989
module_name, class_name, basicsize, size);
5990
if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
5991
}
5992
else if ((size_t)basicsize != size) {
5993
PyErr_Format(PyExc_ValueError,
5994
"%.200s.%.200s has the wrong size, try recompiling. Expected %zd, got %zd",
5995
module_name, class_name, basicsize, size);
5996
goto bad;
5997
}
5998
return (PyTypeObject *)result;
5999
bad:
6000
Py_XDECREF(py_module);
6001
Py_XDECREF(result);
6002
return NULL;
6003
}
6004
#endif
6005
6006
/* InitStrings */
6007
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
6008
while (t->p) {
6009
#if PY_MAJOR_VERSION < 3
6010
if (t->is_unicode) {
6011
*t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
6012
} else if (t->intern) {
6013
*t->p = PyString_InternFromString(t->s);
6014
} else {
6015
*t->p = PyString_FromStringAndSize(t->s, t->n - 1);
6016
}
6017
#else
6018
if (t->is_unicode | t->is_str) {
6019
if (t->intern) {
6020
*t->p = PyUnicode_InternFromString(t->s);
6021
} else if (t->encoding) {
6022
*t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
6023
} else {
6024
*t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
6025
}
6026
} else {
6027
*t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
6028
}
6029
#endif
6030
if (!*t->p)
6031
return -1;
6032
++t;
6033
}
6034
return 0;
6035
}
6036
6037
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
6038
return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
6039
}
6040
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
6041
Py_ssize_t ignore;
6042
return __Pyx_PyObject_AsStringAndSize(o, &ignore);
6043
}
6044
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
6045
#if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
6046
if (
6047
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
6048
__Pyx_sys_getdefaultencoding_not_ascii &&
6049
#endif
6050
PyUnicode_Check(o)) {
6051
#if PY_VERSION_HEX < 0x03030000
6052
char* defenc_c;
6053
PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
6054
if (!defenc) return NULL;
6055
defenc_c = PyBytes_AS_STRING(defenc);
6056
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
6057
{
6058
char* end = defenc_c + PyBytes_GET_SIZE(defenc);
6059
char* c;
6060
for (c = defenc_c; c < end; c++) {
6061
if ((unsigned char) (*c) >= 128) {
6062
PyUnicode_AsASCIIString(o);
6063
return NULL;
6064
}
6065
}
6066
}
6067
#endif
6068
*length = PyBytes_GET_SIZE(defenc);
6069
return defenc_c;
6070
#else
6071
if (__Pyx_PyUnicode_READY(o) == -1) return NULL;
6072
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
6073
if (PyUnicode_IS_ASCII(o)) {
6074
*length = PyUnicode_GET_LENGTH(o);
6075
return PyUnicode_AsUTF8(o);
6076
} else {
6077
PyUnicode_AsASCIIString(o);
6078
return NULL;
6079
}
6080
#else
6081
return PyUnicode_AsUTF8AndSize(o, length);
6082
#endif
6083
#endif
6084
} else
6085
#endif
6086
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
6087
if (PyByteArray_Check(o)) {
6088
*length = PyByteArray_GET_SIZE(o);
6089
return PyByteArray_AS_STRING(o);
6090
} else
6091
#endif
6092
{
6093
char* result;
6094
int r = PyBytes_AsStringAndSize(o, &result, length);
6095
if (unlikely(r < 0)) {
6096
return NULL;
6097
} else {
6098
return result;
6099
}
6100
}
6101
}
6102
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
6103
int is_true = x == Py_True;
6104
if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
6105
else return PyObject_IsTrue(x);
6106
}
6107
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
6108
#if CYTHON_USE_TYPE_SLOTS
6109
PyNumberMethods *m;
6110
#endif
6111
const char *name = NULL;
6112
PyObject *res = NULL;
6113
#if PY_MAJOR_VERSION < 3
6114
if (PyInt_Check(x) || PyLong_Check(x))
6115
#else
6116
if (PyLong_Check(x))
6117
#endif
6118
return __Pyx_NewRef(x);
6119
#if CYTHON_USE_TYPE_SLOTS
6120
m = Py_TYPE(x)->tp_as_number;
6121
#if PY_MAJOR_VERSION < 3
6122
if (m && m->nb_int) {
6123
name = "int";
6124
res = PyNumber_Int(x);
6125
}
6126
else if (m && m->nb_long) {
6127
name = "long";
6128
res = PyNumber_Long(x);
6129
}
6130
#else
6131
if (m && m->nb_int) {
6132
name = "int";
6133
res = PyNumber_Long(x);
6134
}
6135
#endif
6136
#else
6137
res = PyNumber_Int(x);
6138
#endif
6139
if (res) {
6140
#if PY_MAJOR_VERSION < 3
6141
if (!PyInt_Check(res) && !PyLong_Check(res)) {
6142
#else
6143
if (!PyLong_Check(res)) {
6144
#endif
6145
PyErr_Format(PyExc_TypeError,
6146
"__%.4s__ returned non-%.4s (type %.200s)",
6147
name, name, Py_TYPE(res)->tp_name);
6148
Py_DECREF(res);
6149
return NULL;
6150
}
6151
}
6152
else if (!PyErr_Occurred()) {
6153
PyErr_SetString(PyExc_TypeError,
6154
"an integer is required");
6155
}
6156
return res;
6157
}
6158
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
6159
Py_ssize_t ival;
6160
PyObject *x;
6161
#if PY_MAJOR_VERSION < 3
6162
if (likely(PyInt_CheckExact(b))) {
6163
if (sizeof(Py_ssize_t) >= sizeof(long))
6164
return PyInt_AS_LONG(b);
6165
else
6166
return PyInt_AsSsize_t(x);
6167
}
6168
#endif
6169
if (likely(PyLong_CheckExact(b))) {
6170
#if CYTHON_USE_PYLONG_INTERNALS
6171
const digit* digits = ((PyLongObject*)b)->ob_digit;
6172
const Py_ssize_t size = Py_SIZE(b);
6173
if (likely(__Pyx_sst_abs(size) <= 1)) {
6174
ival = likely(size) ? digits[0] : 0;
6175
if (size == -1) ival = -ival;
6176
return ival;
6177
} else {
6178
switch (size) {
6179
case 2:
6180
if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
6181
return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
6182
}
6183
break;
6184
case -2:
6185
if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
6186
return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
6187
}
6188
break;
6189
case 3:
6190
if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
6191
return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
6192
}
6193
break;
6194
case -3:
6195
if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
6196
return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
6197
}
6198
break;
6199
case 4:
6200
if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
6201
return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
6202
}
6203
break;
6204
case -4:
6205
if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
6206
return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
6207
}
6208
break;
6209
}
6210
}
6211
#endif
6212
return PyLong_AsSsize_t(b);
6213
}
6214
x = PyNumber_Index(b);
6215
if (!x) return -1;
6216
ival = PyInt_AsSsize_t(x);
6217
Py_DECREF(x);
6218
return ival;
6219
}
6220
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
6221
return PyInt_FromSize_t(ival);
6222
}
6223
6224
6225
#endif /* Py_PYTHON_H */
6226
6227