Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Untitled #1

Open
wants to merge 71 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
5c93138
graph: added functions to generate all subsequencies with fixed length
yanok Nov 11, 2010
bae501b
graph: add function to count number of cycles inside a given subgraph
yanok Nov 11, 2010
69c0e85
theory: add stub module to define theory-specific values
yanok Nov 12, 2010
723347c
graph: change signSubgraphs to take numbers of tails from theory
yanok Nov 12, 2010
ccf70f7
graph: add functions to compute int/ext cycles for subgraph
yanok Nov 13, 2010
d7e2336
graph: change edges cycle representation
yanok Nov 13, 2010
a5a7cee
graph: add function to test if cycle set covers all edges in graph
yanok Nov 13, 2010
1acec80
graph: use dual cycles representation in most places
yanok Nov 15, 2010
67c14ce
graph: fix cycleLiesIn function
yanok Nov 15, 2010
a8add98
graph: add optimal cycles calculation
yanok Nov 15, 2010
707166f
theory: add stub for phi4 theory
yanok Nov 15, 2010
54554c7
moment: very simple type to store and display moment's values
yanok Nov 16, 2010
6e986b9
graph: make Graph a module and rename file to Graph.hs
yanok Nov 18, 2010
57cbb94
graph: stupid implementation of nickel calculation
yanok Nov 18, 2010
5ac0a2c
graph: use Moment type to tag elements
yanok Nov 20, 2010
fc70244
graph: add function to add moments to diagram
yanok Nov 20, 2010
630e6c2
gitignore: add it
yanok Nov 20, 2010
6da1e08
graph: change DElemType to be ADT not string
yanok Nov 20, 2010
5cf39fd
theory: added two more fields to theory type
yanok Nov 24, 2010
fe88aad
graph: simple function to compute diagram divergence index
yanok Nov 24, 2010
9797678
graph: added function to place vertex on a line and function to compu…
yanok Nov 24, 2010
2db78ed
graph: add functions to squash a subgraph and to calculate a finite p…
yanok Nov 25, 2010
fe8e837
graph: drop CDiagram type (confuses compiler)
yanok Nov 25, 2010
c9e5e5f
phi3: temporary add diagrams for G2 and G3 (up to 4 loops)
yanok Nov 25, 2010
4152ef9
phi3: fix type for phi3G3_! to help compiler
yanok Nov 25, 2010
5c58a05
graph: add functions to compute J' and NG1*NG2 for Green functions
yanok Nov 25, 2010
85cbcd1
graph: fix diagramAddVertex function
yanok Nov 25, 2010
4635b9a
graph: add functions to test equality we expect to find
yanok Nov 25, 2010
3bed9d2
phi3: remove duplicate diagrams
yanok Dec 7, 2010
0f580b5
graph: add functions to strecth moments inside subgraphs
yanok Dec 13, 2010
ad9a54b
angles: some simple functions to compute angle between pair of vectors
yanok Dec 14, 2010
cb2d019
lincomb: simple monad to handle linear combinations
yanok Dec 17, 2010
a86a333
gitignore: ignore backup files
yanok Dec 17, 2010
2ddcfc3
graph: add 'deriving (Eq)' for graph label types
yanok Dec 17, 2010
eb9eb84
graph: graphMap implementation (incorrect, wIP)
yanok Dec 20, 2010
c5220a1
diagram: top-level diagram handling
yanok Dec 20, 2010
8f512ab
lincomb: fixed map functions to handle zeroes properly
yanok Dec 20, 2010
eca51ab
moment: (incomplete) Num instance (useful just for negation)
yanok Dec 21, 2010
06cc486
graph: fix graphMap implementation
yanok Dec 21, 2010
21ac106
cosmetic newline fix to make git happy
yanok Dec 21, 2010
92c8216
diagram: dP operation to put differentiation by external moment on el…
yanok Dec 21, 2010
ebccc6e
diagram: add differentiation by parameter function
yanok Dec 21, 2010
512280a
graph,phi3: fix diagramDivIndex to account modifiers
yanok Dec 21, 2010
f8745ff
moments: add function to make symbollic representation for squared mo…
yanok Dec 21, 2010
dadeddd
graph: function to make symbollic representation for a graph
yanok Dec 22, 2010
4d02e3a
diagram: function to diff diagram by ext moments and then put it to 0
yanok Dec 22, 2010
78a1ab6
graph: fix bug in diagramStretchMoments
yanok Dec 23, 2010
5bb236d
graph: fix double symbolizing of diagram lines
yanok Dec 23, 2010
70fb0c1
diagram: add function to take signature and return symbolic value
yanok Dec 23, 2010
056b1c6
diagram: remove diagramStrProcess and add diagramPutDots instead
yanok Dec 28, 2010
ebb9322
main: ugly interface to print some intermediate results
yanok Dec 28, 2010
5b89c81
angles: add function to get Jacobian
Jan 9, 2011
6f73776
main: function to print Jacobian
Jan 9, 2011
afaa7b1
diagram: add function to expand differentations by a_n parameters
Jan 9, 2011
9d96bd4
main: expand a-diffs inside expandS and expandD
Jan 9, 2011
8f3ebe7
moment: show empty moments as "0"
Jan 9, 2011
2263091
graph: symbolize modifiers as functions
Jan 9, 2011
771581f
main: renamed to Result
Jan 9, 2011
e6313ed
expand: simple stand-alone program that just does expandS on it's fir…
Jan 9, 2011
32f5a8b
expand.sh: script to handle function convversion with cpp
Jan 9, 2011
fff90a1
result: add new expandS' function which adds coefs and (1-a^2) terms
yanok Jan 12, 2011
ff87a9b
moment,angles: use ** instead of ^ to denote power
yanok Jan 12, 2011
a45ee77
expand: use expandS' instead of expandS
yanok Jan 12, 2011
be9c4af
expand.py: simple sympy evaluator to get rid of diff's
yanok Jan 12, 2011
3fbdcec
jacobian: calculate and Jacobian
yanok Jan 12, 2011
1a22ac4
graph: use phi3-specific nrLoops
yanok Jan 12, 2011
6134a01
angles: fix 1-loop jacobian printing
yanok Jan 13, 2011
38082ba
angles: use x_i and y_i to denote cos(theta_i) and sin(theta_i)
yanok Jan 15, 2011
0e57b01
makec.py: simple script to make C files for results
yanok Jan 15, 2011
9ca9944
makec.sh: shell script to do all the work
yanok Jan 15, 2011
d1f1f4c
angles,jacobian.py: fix final Jacobian expression
yanok Jan 24, 2011
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.hi
*.o
*~
99 changes: 99 additions & 0 deletions Angles.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
module Angles where

import Data.List
import Data.Maybe
import Data.Function (on)

data (Ord a) => Pair a = Pair a a

makePair x y | x<y = Pair x y
| otherwise = Pair y x
makePairL [x,y] = makePair x y

getPair (Pair x y) = [x,y]

instance (Show a,Ord a) => Show (Pair a) where
show (Pair x y) = show (x,y)

instance (Ord a,Eq a) => Eq (Pair a) where
(Pair x1 y1) == (Pair x2 y2) =
((x1==x2) && (y1==y2)) || ((x1==y2) && (y1==x2))

pairs l = map makePairL [x | x <- subsequences l, length x == 2]

pairsMany ls = foldl1 union $ map pairs ls

layerPairs order pairs = reverse res where
(res,_) = foldl filterPairsWith ([],pairs) order
filterPairsWith (lps,ps) e = (lps',ps') where
lps' = newLayer:lps
(newLayer,ps') = partition ((elem e).getPair) ps

layerPairs' order = (convertLayers order) . (layerPairs order)

convertLayers order layers =
map (\(x,ps) -> (x,[y | p <- ps, y <- getPair p, y/=x])) $ zip order layers

convertLayers' layers' = (order,layers) where
(order,_) = unzip layers'
layers = map (\(e,l) -> map (makePair e) l) layers'

closeLayers' ls = res where
(res,_) = foldl closeLayer ([],[]) $ reverse ls where
closeLayer (clsdLs,fromPrev) (n,ps) =
((n,ps'):clsdLs,fromCur) where
ps' = union ps fromPrev
fromCur | null ps' = []
| otherwise = n:ps'

closeLayers order layers =
snd $ convertLayers' $ closeLayers' $ convertLayers order layers

scoreOrder order pairs =
sum $ map (\(x,y) -> x^p*y) $ zip [0..] $ map length layrs where
layrs = layerPairs order pairs
p = length order

anglesOrder order pairs =
sum $ map length $ closeLayers order $ layerPairs order pairs

optimalOrder n pairs = (m,angleMin) where
m = minimumBy (compare `on` (\(x,_,_) -> x)) scoredOrders
scoredOrders = zip3 scores orders angles
scores = map (flip scoreOrder pairs) orders
angles = map (flip anglesOrder pairs) orders
orders = permutations [1..n]
angleMin = minimum angles

layer (Pair x y) order =
(min `on` fromJust) (elemIndex x order) (elemIndex y order)

cosP p@(Pair x y) n pairs =
(i,prjs) where
Just i = lookup p thetas
thetas = zip (concat clsdLayers) [1..]
clsdLayers = closeLayers order $ layerPairs order pairs
((_,order,_),_) = optimalOrder n pairs
prjs = map (\e -> (fromJust $ lookup (Pair e x) thetas,
fromJust $ lookup (Pair e y) thetas)) upperLs
upperLs = take (layer p order) order

strCos i = "x_" ++ show i
strSin i = "y_" ++ show i

stringifyCos (i,prjs) =
(concatMap strOnePrj prjs) ++ strCos i ++ closingBrcts where
strOnePrj (x,y) = strCos x ++ "*" ++ strCos y ++ "+" ++
strSin x ++ "*" ++ strSin y ++ "*("
closingBrcts = replicate (length prjs) ')'

-- Jacobian for coordinate transformation
jacobian n pairs = zip [1..] ls where
ls = concatMap (\(n,l) -> replicate (length l) n) nmbrdLayers
nmbrdLayers = zip [0..] clsdLayers
clsdLayers = closeLayers order $ layerPairs order pairs
((_,order,_),_) = optimalOrder n pairs

stringifyJ [] = "1"
stringifyJ as = intercalate "*" $ map strOne as where
strOne (a,n) = "y_" ++ show a ++ "**(d-" ++ show (n+2) ++ ")"
85 changes: 85 additions & 0 deletions Diagram.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
module Diagram where

import Data.Graph.Inductive
import Control.Monad

import Graph hiding (dMuSquare)
import LinComb
import Theory
import Theory.Phi3
import Moment
import Angles

data DExp = Diagram Diagram
| DElement DElement deriving (Show)

getDElement (DElement e) = e
actOnElement f = (fmap getDElement) . f . DElement

dMu2 :: DExp -> LinComb Rational DExp
dMu2 (Diagram d) = fmap Diagram $ graphMap mapChain (actOnElement dMu2) d
dMu2 (DElement ((DVertex,_),_)) = LC [] -- FIXME! I'd like to use 0 or mzero here
dMu2 (DElement (p@(DProp,_),mods)) = return $ DElement (p,"dMu2":mods)

dP :: DExp -> LinComb Rational DExp
dP (Diagram d) = fmap Diagram $ graphMap mapChain (actOnElement dP) d
dP (DElement ((t,m),mods)) | m `hasMoment` 0 = return $ DElement ((t,m),"dP":mods)
| otherwise = LC []

dAn :: Int -> DExp -> LinComb Rational DExp
dAn n (Diagram d) = fmap Diagram $ graphMap mapChain (actOnElement $ dAn n) d
dAn n (DElement ((t,m),mods)) | m `isStretchedBy` n = return $ DElement ((t,m),("dA_" ++ show n):mods)
| otherwise = LC []

zeroP :: DExp -> LinComb Rational DExp
zeroP (Diagram d) = fmap Diagram $ graphMap mapAll (actOnElement zeroP) d
zeroP (DElement ((t,m),mods)) | "dP" `elem` mods = return $ DElement ((t,m),"zeroP":mods)
| otherwise = return $ DElement ((t,m `removeMoment` 0),mods)

unStretch :: Int -> DExp -> LinComb Rational DExp
unStretch n (Diagram d) = fmap Diagram $ graphMap mapAll (actOnElement $ unStretch n) d
unStretch n (DElement ((t,m),mods)) = return $ DElement ((t,m `momentUnStretch` n),mods)

-- power for functions. TODO: Find correct place for me
power f 0 = id
power f n = foldl1 (.) $ replicate n f

-- and monadic version
powerM f 0 = return
powerM f n = foldl1 (>=>) $ replicate n f

diagramHandleExtMoment th d = return d >>= (powerM dP n) >>= zeroP where
n = -diagramDivIndex th d'
Diagram d' = d

diagramAllMomentPairs d = pairsMany ls where
ls = map (filter (/=0)) ls' -- we will handle ext moment separately
ls' = map ((\(_,x,_) -> x).unzip3.moments) ms
ms = (map (\(_,INode ((_,m),_)) -> m) $ labNodes d') ++
(map (\(_,_,((_,m),_)) -> m) $ labEdges d')
d' = delNode 0 d

diagramSignSubgraphsDivIndices th d =
zip [1..] (map (diagramDivIndex th) (signSubgraphs th d))

diagramUnStretchUnneeded th d = unStretchOp d where
unStretchOp = foldl (>=>) return $ map unStretch idxs
idxs = [x | (x,i) <- diagramSignSubgraphsDivIndices th d', i<0]
Diagram d' = d

diagramAOps th d =
[(x,i) | (x,i) <- diagramSignSubgraphsDivIndices th d', i>=0] where
Diagram d' = d

diagramSymbolize d n pairs = graphSymbolize d' n pairs where
Diagram d' = d

diagramPutDots th d =
(diagramHandleExtMoment th $ Diagram d') >>= dMu2 >>= (diagramUnStretchUnneeded th) where
n = nrLoops d
pairs = diagramAllMomentPairs d'
d' = diagramStretchMoments th $ diagramAddMoments th d

diagramExpandADiffs th d = aDiffs (diagramAOps th d) d where
aDiffs [] = return
aDiffs ops = foldl1 (>=>) $ map (\(n,k) -> powerM (dAn n) (k+1)) ops
Loading