Skip to content

Commit 307fba1

Browse files
committed
added function that computes Newton polygons of L-polynomials
1 parent 1798763 commit 307fba1

File tree

3 files changed

+74
-5
lines changed

3 files changed

+74
-5
lines changed

src/DeRham.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ include("ExamplePolynomials.jl")
3030

3131
include("ZetaFunction.jl")
3232
include("PointCounts.jl")
33+
include("NewtonPolygon.jl")
3334

3435
# TODO: export Zeta Function functions
3536

src/NewtonPolygon.jl

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
vp(a, p)
3+
Returns the p-adic valuation of a
4+
5+
INPUTS:
6+
* "a" -- integer
7+
* "p" -- integer, a prime number
8+
"""
9+
function vp(a, p)
10+
@assert is_prime(p)
11+
if a == 0
12+
return Inf
13+
end
14+
15+
e = 0
16+
while mod(a, p) == 0
17+
a = div(a, p)
18+
e = e + 1
19+
end
20+
21+
return e
22+
end
23+
24+
"""
25+
newton_polygon(f, p)
26+
Returns the Newton polygon of f
27+
28+
INPUTS:
29+
* "f" -- list, coefficients of a polynomial, constant term first
30+
* "p" -- integer, a prime number
31+
"""
32+
function newton_polygon(f, p)
33+
@assert is_prime(p)
34+
35+
pts = []
36+
for (i, a) in enumerate(f)
37+
if a != 0
38+
push!(pts, (i-1, vp(a, p)))
39+
end
40+
end
41+
42+
# compute the lower convex hull of points
43+
hull = Tuple{Int64, Int64}[]
44+
for pt in pts
45+
while length(hull) >= 2
46+
(x1, y1) = hull[end-1]
47+
(x2, y2) = hull[end]
48+
(x3, y3) = pt
49+
# Compute cross product to decide whether pt is "below" the last segment.
50+
cp = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)
51+
if cp <= 0
52+
pop!(hull)
53+
else
54+
break
55+
end
56+
end
57+
push!(hull, pt)
58+
end
59+
return SlopesPolygon(hull)
60+
#return hull
61+
end
62+
63+
64+

src/SlopesPolygon.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,22 @@ end
103103
"""
104104
Given an array of vertices
105105
"""
106-
function SlopesPolygon(vertices::Array{Tuple{Int,Int}})
106+
#function SlopesPolygon(vertices::Array{Tuple{Int,Int}})
107+
function SlopesPolygon(vertices::Vector{Tuple{Int64, Int64}})
107108
#TODO implement
108109

109110
n = length(vertices)-1
110111
slopelengths = zeros(Int,n)
111112
slopes = zeros(Rational{Int},n)
112-
for i = 2:n
113+
for i = 2:n+1
113114
slopevec = vertices[i] .- vertices[i-1]
114-
push!(slopes, slopevec[2] // slopevec[1])
115-
push!(slopelengths,slopevec[2])
115+
#push!(slopes, slopevec[2] // slopevec[1])
116+
#push!(slopelengths,slopevec[2])
117+
slopes[i-1] = slopevec[2] // slopevec[1]
118+
slopelengths[i-1] = slopevec[2]
116119
end
117-
120+
println(slopelengths)
121+
println(slopes)
118122
SlopesPolygon(slopes,slopelengths,values(slopes,slopelengths)...)
119123
end
120124

0 commit comments

Comments
 (0)