Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

#***************************************************************************** 

# Copyright (C) 2005 William Stein <wstein@gmail.com> 

# 

# Distributed under the terms of the GNU General Public License (GPL) 

# 

# This code is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 

# General Public License for more details. 

# 

# The full text of the GPL is available at: 

# 

# http://www.gnu.org/licenses/ 

#***************************************************************************** 

  

include 'misc.pxi' 

include 'decl.pxi' 

  

ZZ_pEContextDict = {} 

  

from sage.libs.ntl.ntl_ZZ_pX cimport ntl_ZZ_pX 

from sage.libs.ntl.ntl_ZZ_pContext import ntl_ZZ_pContext 

from sage.libs.ntl.ntl_ZZ cimport ntl_ZZ 

  

cdef class ntl_ZZ_pEContext_class(object): 

def __init__(self, ntl_ZZ_pX f): 

""" 

EXAMPLES: 

# You can construct contexts manually. 

sage: c=ntl.ZZ_pEContext(ntl.ZZ_pX([4,1,6],25)) 

sage: n1=c.ZZ_pE([10,17,12]) 

sage: n1 

[2 15] 

  

# or You can construct contexts implicitly. 

sage: n2=ntl.ZZ_pE(12, ntl.ZZ_pX([1,1,1],7)) 

sage: n2 

[5] 

sage: n2+n1 # Mismatched moduli: It will go BOOM! 

Traceback (most recent call last): 

... 

ValueError: You can not perform arithmetic with elements of different moduli. 

""" 

pass 

  

def __cinit__(self, ntl_ZZ_pX f): 

self.pc = f.c 

self.pc.restore_c() 

self.x = ZZ_pEContext_c(f.x) 

ZZ_pEContextDict[(repr(f),repr(f.c.p))] = self 

self.f = f 

self.ptrs.zzpc = &(self.pc.x) 

self.ptrs.zzpec = &(self.x) 

  

def __reduce__(self): 

""" 

sage: c=ntl.ZZ_pEContext(ntl.ZZ_pX([1,1,1],7)) 

sage: loads(dumps(c)) is c 

True 

""" 

return ntl_ZZ_pEContext, (self.f,) 

  

def __repr__(self): 

""" 

Returns a string representation of self. 

  

EXAMPLES: 

sage: c = ntl.ZZ_pEContext(ntl.ZZ_pX([1,1,1], 7)); c 

NTL modulus [1 1 1] (mod 7) 

""" 

return "NTL modulus %s (mod %s)"%(self.f, self.pc.p) 

  

def get_pc(self): 

""" 

Returns the ZZ_pContext contained within self. 

  

EXAMPLES: 

sage: c = ntl.ZZ_pEContext(ntl.ZZ_pX([1,1,1], 7)); c 

NTL modulus [1 1 1] (mod 7) 

sage: c.get_pc() 

NTL modulus 7 

""" 

return self.pc 

  

def polynomial(self): 

""" 

Returns the ZZ_pX polynomial defining self. 

  

EXAMPLES: 

sage: c = ntl.ZZ_pEContext(ntl.ZZ_pX([1,1,1], 7)) 

sage: c.polynomial() 

[1 1 1] 

""" 

return self.f 

  

def restore(self): 

""" 

Manually sets the global NTL modulus to be self. 

  

This should be done automatically by all of the NTL wrapper classes. 

  

CRUCIAL: If you are writing your own classes that use ZZ_p_c, ZZ_pX_c, ZZ_pE_c, ZZ_pEX_c 

then you MUST restore the context before calling off to NTL for anything. If the context has been 

switched by other code then behavior of operations is undefined. See the NTL documentation for 

more details (or the wrappers in sage.libs.ntl) 

""" 

self.restore_c() 

  

cdef void restore_c(self): 

""" 

Sets the global NTL modulus to be self. 

  

CRUCIAL: If you are writing your own classes that use ZZ_p_c, ZZ_pX_c, ZZ_pE_c, ZZ_pEX_c 

then you MUST restore the context before calling off to NTL for anything. If the context has been 

switched by other code then behavior of operations is undefined. See the NTL documentation for 

more details (or the wrappers in sage.libs.ntl) 

""" 

self.pc.restore_c() 

self.x.restore() 

  

#def ZZ_pX(self,v = None): 

# from ntl_ZZ_pX import ntl_ZZ_pX 

# return ntl_ZZ_pX(v,modulus=self) 

  

def ZZ_pE(self,v = None): 

""" 

Returns a ZZ_pE object with modulus self out of the data v. 

  

EXAMPLES: 

sage: c = ntl.ZZ_pEContext(ntl.ZZ_pX([1,1,1], 7)) 

sage: c.ZZ_pE([4,3]) 

[4 3] 

""" 

from .ntl_ZZ_pE import ntl_ZZ_pE 

return ntl_ZZ_pE(v,modulus=self) 

  

def ZZ_pEX(self, v = None): 

""" 

Returns a ZZ_pE object with modulus self out of the data v. 

  

EXAMPLES: 

sage: c = ntl.ZZ_pEContext(ntl.ZZ_pX([1,1,1], 7)) 

sage: c.ZZ_pEX([4,3]) 

[[4] [3]] 

""" 

from .ntl_ZZ_pEX import ntl_ZZ_pEX 

return ntl_ZZ_pEX(v, modulus=self) 

  

def ntl_ZZ_pEContext( ntl_ZZ_pX f): 

""" 

Creates an ntl_ZZ_pEContext. 

  

Such an object must be created before any ZZ_pE or ZZ_pEX objects can be used. 

  

The context handling should be taken care of by the wrapper classes. 

EXAMPLES: 

sage: c = ntl.ZZ_pEContext(ntl.ZZ_pX([1,1,1], 7)); c 

NTL modulus [1 1 1] (mod 7) 

""" 

try: 

return ZZ_pEContextDict[repr(f), repr(f.c.p)] 

except KeyError: 

# Creating the following object caches it. 

return ntl_ZZ_pEContext_class(f)