Skip to content

Commit

Permalink
Drop dependency on Graphs package
Browse files Browse the repository at this point in the history
This also avoids a bunch of inefficiencies.
  • Loading branch information
fingolfin committed Feb 1, 2024
1 parent 3f513aa commit b53e377
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 40 deletions.
1 change: 0 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ version = "0.1.1"
[deps]
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
Nemo = "2edaba10-b0f1-5616-af89-8c11ac63239a"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2 changes: 0 additions & 2 deletions src/GromovWitten.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import Combinatorics: permutations, with_replacement_combinations

import StatsBase: countmap

import Graphs: nv, ne, Edge, dst, src, DiGraph

export cache_integral_result
export coefterm
export constterm
Expand Down
12 changes: 6 additions & 6 deletions src/coefterm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#Where I(q) is the Feynman Integral and P(x,q) the Propagator.
#=function coefterm(x::Vector,q::Vector,G::FeynmanGraph ,p::QQMPolyRingElem,d::Integer;l=zeros(Int,nv(G)))
#here l is leak vector of the graph G.
ee=Edge.(G.edge)
G=DiGraph(Edge.(G.edge)) # convert from graph to Graph (so we can use nv(G))
ee=edges(G)
G=DiGraph(edges(G)) # convert from graph to Graph (so we can use nv(G))
L=zeros(Int,nv(G)) # define zeros Vector of length nv(G)
for ev in ee
if src(ev) == dst(ev) #checking for loop term.
Expand Down Expand Up @@ -94,7 +94,7 @@ Let Ω=[x1,...,xn] be a given Order and $a$ a branche type,flip_signature r
It will return -2 in case the Graph G has a loop.
"""
function flip_signature(G::FeynmanGraph ,p::Vector{Int64},a::Vector{Int64}) #graph G, list p, branch type a
ee=Edge.(G.edge)
ee=edges(G)
b=zeros(Int,length(a))
for (i, (ai, ev)) in enumerate(zip(a, ee))
if ai == 0 && src(ev) != dst(ev)
Expand Down Expand Up @@ -137,7 +137,7 @@ julia> signature_and_multiplicities(G,a)
```
"""
function signature_and_multiplicities(G::FeynmanGraph, a::Vector{Int64})
ee = Edge.(G.edge)
ee = edges(G)
p = Vector{Int64}()
b = Vector{Tuple{Int64, Vector{Int64}}}()
l = zeros(Int, nv(G))
Expand Down Expand Up @@ -208,8 +208,8 @@ function signature_and_multiplicities(G::FeynmanGraph, a::Vector{Int64})
end


function find_equal_pairs(ve::Vector{Tuple{Int64, Int64}})
equal_pairs = Dict{Tuple{Int, Int}, Vector{Int}}()
function find_equal_pairs(ve::Vector{Edge})
equal_pairs = Dict{Edge, Vector{Int}}()
for (i, pair) in enumerate(ve)
if haskey(equal_pairs, pair)
push!(equal_pairs[pair], i)
Expand Down
8 changes: 4 additions & 4 deletions src/coeftermV.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ end
return hp
end
function coeftermX( x::Vector, q::Vector,z::Vector,G::graph ,p::QQMPolyRingElem,d::Integer;l=zeros(Int,nv(G)))
ee=Edge.(G.edge)
G=DiGraph(Edge.(G.edge))
ee=edges(G)
G=DiGraph(edges(G))
L=zeros(Int,nv(G))
for ev in ee
if src(ev) == dst(ev)
Expand All @@ -122,8 +122,8 @@ function coeftermX( x::Vector, q::Vector,z::Vector,G::graph ,p::QQMPolyRingElem,
return p
end =#
function lis(G::FeynmanGraph,d::Int64,l::Vector{Int64})
ee = Edge.(G.edge)
#G=DiGraph(Edge.(G.edge))
ee = edges(G)
#G=DiGraph(edges(G))
L=zeros(Int,nv(G))
@inbounds for ev in ee
if src(ev) != dst(ev)
Expand Down
36 changes: 16 additions & 20 deletions src/feynmanIntegral.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ julia> feynman_integral_branch_type(F,a,g)
```
"""
function feynman_integral_branch_type(F::FeynmanIntegral, a::Vector{Int64}; l=zeros(Int, nv(F.G)))
ee = Edge.(F.G.edge)
ee = edges(F.G)
N = sum(a)
f = signature_and_multiplicities(F.G, a)
p = 0
Expand All @@ -62,7 +62,7 @@ function feynman_integral_branch_type(F::FeynmanIntegral, a::Vector{Int64}; l=ze
return p
end
function feynman_integral_branch_type(F::FeynmanIntegral, a::Vector{Int64},g::Vector{Int64}; aa=1,l=zeros(Int,nv(F.G)))
ee = Edge.(F.G.edge)
ee = edges(F.G)
N = sum(a)
f = signature_and_multiplicities(F.G, a)
p = 0
Expand Down Expand Up @@ -142,7 +142,7 @@ julia> feynman_integral_branch_type_order(F,a,Ω,g)
```
"""
function feynman_integral_branch_type_order(F::FeynmanIntegral, a::Vector{Int64}, o::Vector{Int64}; l=zeros(Int, nv(F.G)))
ee = Edge.(F.G.edge)
ee = edges(F.G)
N = sum(a)
f = signature_and_multiplicities_order(F.G, a,o)
p = 0
Expand Down Expand Up @@ -172,7 +172,7 @@ function feynman_integral_branch_type_order(F::FeynmanIntegral, a::Vector{Int64}
return p
end
function feynman_integral_branch_type_order(F::FeynmanIntegral, a::Vector{Int64}, o::Vector{Int64}, g::Vector{Int64}; aa=1,l=zeros(Int,nv(F.G)))
ee = Edge.(F.G.edge)
ee = edges(F.G)
N = sum(a)
f = signature_and_multiplicities_order(F.G, a,o)
p = 0
Expand Down Expand Up @@ -253,12 +253,11 @@ julia> feynman_integral_degree_order(F,Ω,3,g)
```
"""
function feynman_integral_degree_order( F::FeynmanIntegral,o::Vector{Int64},d::Integer,;l=zeros(Int,nv(F.G)) )
# ve==F.G.edge
indices = find_equal_pairs(F.G.edge)
indices = find_equal_pairs(edges(F.G))
if isempty(indices)
return feynman_integral_deg_order(F,o,d;l)
else
ee=Edge.(F.G.edge)
ee=edges(F.G)

re = Vector{Vector{Any}}()
res = []
Expand Down Expand Up @@ -301,12 +300,11 @@ function feynman_integral_degree_order( F::FeynmanIntegral,o::Vector{Int64},d::I
end
end
function feynman_integral_degree_order( F::FeynmanIntegral,o::Vector{Int64},d::Integer,g::Vector{Int} ;aa=1,l=zeros(Int,nv(F.G)) )
# ve==F.G.edge
indices = find_equal_pairs(F.G.edge)
indices = find_equal_pairs(edges(F.G))
if isempty(indices)
return feynman_integral_deg_order(F,o,d,g;aa,l)
else
ee=Edge.(F.G.edge)
ee=edges(F.G)

re = Vector{Vector{Any}}()
res = []
Expand Down Expand Up @@ -349,7 +347,7 @@ function feynman_integral_degree_order( F::FeynmanIntegral,o::Vector{Int64},d::I
end
end
function feynman_integral_deg_order(F::FeynmanIntegral,o::Vector{Int64},d::Integer;l=zeros(Int,nv(F.G)))
ee=Edge.(F.G.edge)
ee=edges(F.G)
a=partition(length(ee),d)
sum=0
for ai in a
Expand All @@ -358,7 +356,7 @@ function feynman_integral_deg_order(F::FeynmanIntegral,o::Vector{Int64},d::Integ
return sum
end
function feynman_integral_deg_order(F::FeynmanIntegral,o::Vector{Int64},d::Integer,g;aa=1,l=zeros(Int,nv(F.G)))
ee=Edge.(F.G.edge)
ee=edges(F.G)
a=partition(length(ee),d)
sum=0
for ai in a
Expand Down Expand Up @@ -403,12 +401,11 @@ julia> feynman_integral_degree(F,3,g)
```
"""
function feynman_integral_degree(F::FeynmanIntegral, d::Int64 ; l=zeros(Int, nv(F.G)) )
# ve==F.G.edge
indices = find_equal_pairs(F.G.edge)
indices = find_equal_pairs(edges(F.G))
if isempty(indices)
return feynman_integral_deg(F,d;l)
else
ee=Edge.(F.G.edge)
ee=edges(F.G)

re = Vector{Vector{Any}}()
res = []
Expand Down Expand Up @@ -448,12 +445,11 @@ julia> feynman_integral_degree(F,3,g)
end
end
function feynman_integral_degree( F::FeynmanIntegral,d::Integer,g::Vector{Int} ;aa=1,l=zeros(Int,nv(F.G)) )
# ve==F.G.edge
indices = find_equal_pairs(F.G.edge)
indices = find_equal_pairs(edges(F.G))
if isempty(indices)
return feynman_integral_deg(F,d,g;aa,l)
else
ee=Edge.(F.G.edge)
ee=edges(F.G)

re = Vector{Vector{Any}}()
res = []
Expand Down Expand Up @@ -493,7 +489,7 @@ julia> feynman_integral_degree(F,3,g)
end
end
function feynman_integral_deg( F::FeynmanIntegral,d::Integer ;l=zeros(Int,nv(F.G)))
ee=Edge.(F.G.edge)
ee=edges(F.G)
a=partition(length(ee),d)
sum=0
for ai in a
Expand All @@ -502,7 +498,7 @@ julia> feynman_integral_degree(F,3,g)
return sum
end
function feynman_integral_deg( F::FeynmanIntegral,d::Integer,g ;aa=1,l=zeros(Int,nv(F.G)))
ee=Edge.(F.G.edge)
ee=edges(F.G)
a=partition(length(ee),d)
sum=0
for ai in a
Expand Down
27 changes: 20 additions & 7 deletions src/graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,40 @@
# graph.jl : define graph and Polynomial Ring. #
# #
###############################################################################
struct Edge
src::Int
dst::Int
end
Edge(e::Tuple{Int, Int}) = Edge(e[1], e[2])
src(e::Edge) = e.src
dst(e::Edge) = e.dst

Base.show(io::IO, e::Edge) = show(io, (src(e), dst(e)))

Check warning on line 14 in src/graph.jl

View check run for this annotation

Codecov / codecov/patch

src/graph.jl#L14

Added line #L14 was not covered by tests

struct FeynmanGraph
edge::Vector
_edges::Vector{Edge}
end
# edge(G::FeynmanGraph) = Edge.(G.edge)
nv(G::FeynmanGraph) = nv(DiGraph(Edge.(G.edge)))
ne(G::FeynmanGraph) = length(Edge.(G.edge))
FeynmanGraph(edges::Vector{Tuple{Int, Int}}) = FeynmanGraph(Edge.(edges))

edges(G::FeynmanGraph) = G._edges
nv(G::FeynmanGraph) = length(union([e.src for e in G._edges], [e.dst for e in G._edges]))
ne(G::FeynmanGraph) = length(G._edges)

Base.show(io::IO, G::FeynmanGraph) = print(io, "FeynmanGraph(", [ (src(e), dst(e)) for e in edges(G) ], ")")

Check warning on line 25 in src/graph.jl

View check run for this annotation

Codecov / codecov/patch

src/graph.jl#L25

Added line #L25 was not covered by tests

function feynman_graph(edges::Vector{Tuple{Int, Int}})
return FeynmanGraph(edges)
end
#=function polynomial_ring(G::FeynmanGraph, x::String, q::String, z::String)
ee=Edge.(G.edge)
ee=edges(G)
if length(ee)==0
throw(DomainError(G,"G must be non empty graph"))
else
return @polynomial_ring(QQ, x[1:nv(G)], q[1:ne(G)], z[1:nv(G)])
end
end
function polynomial_ring(G::FeynmanGraph, x::String, q::String)
ee=Edge.(G.edge)
ee=edges(G)
if length(ee)==0
throw(DomainError(G,"G must be non empty graph"))
else
Expand Down Expand Up @@ -55,4 +69,3 @@ end
function feynman_integral(G::FeynmanGraph)
return FeynmanIntegral(G)
end
edge(F::FeynmanIntegral) = Edge.(F.G.edge)

0 comments on commit b53e377

Please sign in to comment.