Skip to content

Commit

Permalink
Add Roune-Stillman exs.; do more NewIJCs
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveBarton committed Nov 6, 2023
1 parent 78204a0 commit e28463a
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 22 deletions.
58 changes: 54 additions & 4 deletions src/Math/Algebra/Commutative/GBDemo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ showUsage = mapM_ putStrLn [
" --ts show details relating to selection strategy",
" --tt show total times of some algorithm parts",
"",
"examples: simpleDemo buchberger87 gerdt93 katsura5 katsura6 katsura7 katsura8 katsura10",
" hCyclic4 cyclic4 hCyclic5 cyclic5 hCyclic6 cyclic6 hCyclic7 cyclic7 hCyclic8 cyclic8",
" schransTroost jason210 yang cyclic8big logic3s logic3r logic3n;",
"examples: simpleDemo buchberger87 gerdt93",
" katsura5 katsura6 katsura7 katsura8 katsura10 katsura11",
" hCyclic4 cyclic4 hCyclic5 cyclic5 hCyclic6 cyclic6 hCyclic7 cyclic7 hcyclic8 cyclic8",
" schransTroost joswig101 jason210 yang mayr42 cyclic8big logic3s logic3r logic3n;",
" if none are listed then katsura8 cyclic7 jason210",
"",
"+RTS options set the number of cores used, heap nursery size, etc., and are described at",
Expand Down Expand Up @@ -239,6 +240,21 @@ x^5t^2 - z^2t^5] (z^2t^5 ≡ y^2z^3t^2)
"b^2+2bd-2ce+2df+4bg+4cg+4dg+2eg-47fg-20g^2+50eh-46fh+13gh-41h^2-4ci+50di-48ei+9fi+21gi-22hi+46i^2+50cj-48dj+9ej+19fj-18gj-7hj-43ij+39j^2+37b+48c+32d-10e +22f+27g+7h-40i-13j"
],

GBEx "katsura11" 101 ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"]
[
"a+2b+2c+2d+2e+2f+2g+2h+2i+2j+2k-1",
"fg-23g^2+eh-46fh-40gh-41h^2+di-46ei-40fi+19gi+30hi+47i^2+cj-46dj-40ej+19fj+30gj-7hj+9ij+39j^2+bk-46ck-40dk+19ek+30fk-7gk+9hk-23ik-2jk+36k^2+12b+48c+7d-10e-3f+28g-18h-40i-38j-12k",
"f^2+2eg+47g^2+2dh-7fh-19gh-18h^2+2ci-7ei-19fi-36gi+43hi+8i^2+2bj-7dj-19ej-36fj+43gj+16hj-16ij+24j^2-4bk-11ck-23dk-40ek+39fk+12gk-20hk+44ik+2jk+26k^2-24b+5c-14d+20e+6f+45g+36h-21i-25j+25k",
"ef+dg+ch+bi-2bj-2cj-2dj-2ej-2fj-2gj-2hj-2ij-2j^2+bk-2jk-50j",
"e^2+2df+2cg+2bh-4bi-4ci-4di-4ei-4fi-4gi-4hi-4i^2+2bj-4ij+2ck-4ik+i",
"de+cf+bg-2bh-2ch-2dh-2eh-2fh-2gh-2h^2+bi-2hi+cj-2hj+dk-2hk-50h",
"d^2+2ce+2bf-4bg-4cg-4dg-4eg+5g^2+2bh+4eh+18fh+38gh+38h^2+2ci+4di+18ei+42fi-29gi+19hi-14i^2+4cj+20dj+42ej-25fj+15gj-28hj+36ij-46j^2+4bk+18ck+42dk-23ek+19fk-32gk+36hk+9ik-8jk+43k^2+48b-10c+28d-40e-12f+12g+29h+42i+50j-48k",
"cd+be-2bf-2cf-2df+bg+2dg+4eg+48g^2+3ch+4dh+2eh-7fh-17gh-17h^2+2bi+4ci+3di-5ei-19fi-34gi+45hi+9i^2-2cj-9dj-20ej-40fj+41gj+14hj-18ij+21j^2-4bk-13ck-25dk-42ek+36fk+10gk-22hk+42ik-4jk+23k^2-24b+5c-14d+20e-44f+45g+36h-21i-24j+26k",
"c^2+2bd-4be-4ce+2bf+4cf+8df+4bg+10cg+4dg-4eg-4ch-6dh-12eh-8fh-8gh-8h^2-8bi-16ci-16di-18ei-16fi-16gi-24hi-16i^2-4cj-8dj-12ej-6fj-8gj-16hj-24ij-8j^2+4bk+8ck+4dk-4ek+2gk-8hk-16ik-8jk+e+2h+4i+2j",
"bc-2bd+3be+4ce-cf-6df-4bg-8cg-5dg+5g^2+2ch+2dh+9eh+18fh+38gh+38h^2+6bi+12ci+12di+26ei+47fi-25gi+23hi-10i^2+6cj+20dj+44ej-29fj+12gj-32hj+36ij-50j^2+10ck+34dk-29ek+9fk-44gk+25hk+ik-24jk+31k^2+48b-10c-22d-40e-11f+13g+30h+42i-49j-44k",
"b^2+2bd-2ce+2df+4bg+4cg+4dg+2eg+10g^2-4eh+14fh-49gh-49h^2-4ci-4di+12ei+48fi+5gi-26hi+33i^2-4cj+12dj+48ej+3fj-22gj-33hj-24ij-47j^2+16ck-49dk+3ek-22fk-27gk-20hk+9ik-43jk+14k^2-5b-19c-43d+25e-18f+30g-31h-i+19j+29k"
],

GBEx "hCyclic4" 7583 ["a", "b", "c", "d", "e"]
[
"a+b+c+d",
Expand Down Expand Up @@ -314,7 +330,7 @@ x^5t^2 - z^2t^5] (z^2t^5 ≡ y^2z^3t^2)
"abcdef+abcdeg+abcdfg+abcefg+abdefg+acdefg+bcdefg",
"abcdefg-1"
],

{-
GBEx "hCyclic8" 7583 ["a", "b", "c", "d", "e", "f", "g", "h", "i"]
[
"a+b+c+d+e+f+g+h",
Expand All @@ -326,6 +342,18 @@ x^5t^2 - z^2t^5] (z^2t^5 ≡ y^2z^3t^2)
"abcdefg+bcdefgh+cdefgha+defghab+efghabc+fghabcd+ghabcde+habcdef",
"abcdefgh-i^8"
],
-}
GBEx "hcyclic8" 101 ["a", "b", "c", "d", "e", "f", "g", "h", "i"]
[
"a+b+c+d+e+f+g+h",
"ab+bc+cd+de+ef+fg+gh+ha",
"abc+bcd+cde+def+efg+fgh+gha+hab",
"abcd+bcde+cdef+defg+efgh+fgha+ghab+habc",
"abcde+bcdef+cdefg+defgh+efgha+fghab+ghabc+habcd",
"abcdef+bcdefg+cdefgh+defgha+efghab+fghabc+ghabcd+habcde",
"abcdefg+bcdefgh+cdefgha+defghab+efghabc+fghabcd+ghabcde+habcdef",
"abcdefgh-i^8"
],

GBEx "cyclic8" 7583 ["a", "b", "c", "d", "e", "f", "g", "h"]
[
Expand Down Expand Up @@ -385,6 +413,15 @@ x^5t^2 - z^2t^5] (z^2t^5 ≡ y^2z^3t^2)
"-6de - 6fg + 6dh + 6eh + 6fh + 6gh + 8h^2 - ht"
],

GBEx "joswig101" 101 ["a", "b", "c", "d", "e"]
[
"ade^11+abe^10+c",
"bcde^8+ace^19+d",
"abce^18-bce^8+c^2e^8-bde^2-1",
"ab^2e^18-bce^14+c^2e^14+bce^8-bde^8-cde^4-b-e^6",
"b^2ce^20+b^2de^14+be^12-a"
],

GBEx "jason210" 32003 ["a", "b", "c", "d", "e", "f", "g", "h"]
[
"a^2c^4+b^2d^4+abc^2e^2+abd^2f^2+abcdeg+abcdfh",
Expand Down Expand Up @@ -432,6 +469,19 @@ x^5t^2 - z^2t^5] (z^2t^5 ≡ y^2z^3t^2)
"JMPS-INPS-JLQS+HNQS+ILRS-HMRS-JMOT+INOT+JKQT-GNQT-IKRT+GMRT+JLOU-HNOU-JKPU+GNPU+HKRU-GLRU-ILOV+HMOV+IKPV-GMPV-HKQV+GLQV"
],

GBEx "mayr42" 101 (map (: []) (['a' .. 'z'] ++ ['A' .. 'Y']))
[
"dW-jY", "cV-iY", "bU-hY", "aT-gY", "dR-iW", "cQ-hV", "bP-gU", "aO-fT", "dM-iW",
"cL-hV", "bK-gU", "aJ-fT", "iH-iW", "dH-eY", "hG-hV", "cG-dY", "gF-gU", "bF-cY",
"fE-fT", "aE-bY",
"inM-iCR", "hmL-hBQ", "glK-gAP", "fkJ-fzO",
"fz^2T-gY^3", "fk^2T-bY^3", "fu^2O-fTY^2", "fp^2J-fTY^2",
"ixDMX-iCRXY", "hwCLW-hBQWY", "gvBKV-gAPVY", "fuAJU-fzOUY", "ixyMS-iCRSY",
"hwxLR-hBQRY", "gvwKQ-gAPQY", "fuvJP-fzOPY", "itxMN-iCNRY", "hswLM-hBMQY",
"ioxIM-iCIRY", "grvKL-gALPY", "hnwHL-hBHQY", "fquJK-fzKOY", "gmvGK-gAGPY",
"fluFJ-fzFOY"
],

GBEx "cyclic8big" 7583 ["a", "b", "c", "d", "e", "f", "g", "h"]
[
"a+b+c+d+e+f+g+h",
Expand Down
41 changes: 23 additions & 18 deletions src/Math/Algebra/Commutative/GroebnerBasis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Control.Monad (unless, void, when)
import Control.Monad.Extra (ifM, orM, whenM)
import Data.Foldable (find, minimumBy, toList)
import Data.Int (Int64)
import Data.List (elemIndex, findIndices, groupBy, sortBy)
import Data.List (elemIndex, findIndices, groupBy, intercalate, sortBy)
import Data.List.Extra (chunksOf)
import Data.Maybe (catMaybes, fromJust, isJust, listToMaybe, mapMaybe)
import qualified Data.RRBVector as GBV
Expand Down Expand Up @@ -50,7 +50,7 @@ import Debug.Trace.String (traceEvent, traceEventIO)
import GHC.Stats (RTSStats, getRTSStats, getRTSStatsEnabled, mutator_cpu_ns, mutator_elapsed_ns)
import System.CPUTime (getCPUTime)
import System.IO (hPutStr, stderr)
-- import System.IO (hFlush, stdout)
import System.IO (hFlush, stdout)
-- import System.Process (callCommand)


Expand All @@ -68,6 +68,12 @@ fromGens :: SubmoduleOps r m sm -> Int -> [m] -> sm
fromGens smA gbTrace = smA.plusGens gbTrace smA.zeroMd


showBigN :: Int -> String
showBigN n = if n < 0 then '-' : go (- n) else go n
where
go m = intercalate "," $ reverse $ map reverse $ chunksOf 3 $ reverse (show m)


inc :: IORef Int -> Int -> IO ()
inc ref n = when (n /= 0) $ atomicModifyIORef'_ ref (+ n)

Expand Down Expand Up @@ -314,7 +320,7 @@ gkgsEmpty nEvGroups = SL.singleton (G1KGs 0 (kgsEmpty nEvGroups))
{-# SCC kgsFindReducer #-}
kgsFindReducer :: GBPoly ev term p => (ev -> [Word]) -> p -> KerGens p -> Maybe p
-- returns the best (shortest) top-reducer, if any
kgsFindReducer evGroup p kgs = TS.measurePure "kgsFindReducer" $
kgsFindReducer evGroup p kgs =
if pIsZero p then Nothing else
let nVars = Seq.length kgs
pEv = leadEvNZ p
Expand Down Expand Up @@ -404,11 +410,12 @@ kgsOps (GBPolyOps { .. }) = KGsOps { .. }
-- kgsReplace p p' kgs = kgsInsert p' (kgsDelete p kgs)

gkgsReplace :: EPolyHDeg p -> EPolyHDeg p -> Op1 (GapsKerGens p)
gkgsReplace ph ph' gkgs = gkgsInsert ph' (gkgsDelete ph gkgs)
gkgsReplace ph ph' gkgs = TS.measurePure "gkgsReplace" gkgsInsert ph' (gkgsDelete ph gkgs)

gkgsFindReducer :: p -> GapsKerGens p -> Maybe (EPolyHDeg p)
-- returns the best (least sugar gap, then shortest) top-reducer, if any
gkgsFindReducer p gkgs = listToMaybe (mapMaybe find1 (toList gkgs))
gkgsFindReducer p gkgs = {- @@ slow on 60 cores: TS.measurePure "gkgsFindReducer" $ -}
listToMaybe (mapMaybe find1 (toList gkgs))
where
find1 (G1KGs gap kgs) = -- if not useSugar.b, then h can be wrong:
fmap (\g -> EPolyHDeg g (evTotDeg (leadEvNZ g) + gap))
Expand Down Expand Up @@ -740,31 +747,28 @@ groebnerBasis gbpA@(GBPolyOps { .. }) gbTrace gbi0 newGens = TS.scope $ do
show (Set.size ijcs) ++ " pairs" ++
if numSleeping > 0 then ", " ++ show numSleeping ++ " sleeping" else ""
pure False
checkQueues nCores t = orM (tasks ++ [logSleep])
checkQueues _nCores t = orM (tasks ++ [logSleep])
where
logSleep = do
traceEventIO (" sleep " ++ show t)
when (gbTrace .&. gbTQueues /= 0) $ putChar 's'
pure False
tasks1
| t == 0 = [newIJCs, checkRgs1, doSP]
| 3 * t < nCores {- @@ tune -} = [newIJCs, doSP]
| otherwise = [doSP, newIJCs]
tasks = [traceTime | t == 0 && gbTrace /= 0] ++ [checkRgs1 | t == 1] ++ tasks1
tasks = [traceTime | t == 0 && gbTrace /= 0] ++ [checkRgs1 | t == 1]
++ [newIJCs] ++ [checkRgs1 | t == 0] ++ [doSP]
parNonBlocking wakeAllThreads numSleepingVar checkQueues
when (gbTrace .&. (gbTQueues .|. gbTProgressChars) /= 0) $ putS "\n"
when (gbTrace .&. gbTSummary /= 0) $ do
t <- cpuElapsedStr cpuTime0 sysTime0 mRTSStats0
putStrLn $ "Groebner Basis CPU/Elapsed Times: " ++ t
nSPairsRed <- atomicReadInt nSPairsRedRef
putStrLn $ "# SPairs reduced = " ++ show nSPairsRed
putStrLn $ "# SPairs reduced = " ++ showBigN nSPairsRed
nRedSteps <- atomicReadInt nRedStepsRef
putStrLn $ "# reduction steps (quotient terms) = " ++ show nRedSteps
putStrLn $ "# reduction steps (quotient terms) = " ++ showBigN nRedSteps
-- Macaulay just counts top-reduced
ghs <- readTVarIO genHsRef
let ndhs = [(numTerms g, evTotDeg (leadEvNZ g), h) | EPolyHDeg g h <- toList ghs]
putStrLn $ "generated (redundant) basis has " ++ show (length ghs) ++
" elements with " ++ show (sum (map fst3 ndhs)) ++ " monomials"
putStrLn $ "generated (redundant) basis has " ++ showBigN (length ghs) ++
" elements with " ++ showBigN (sum (map fst3 ndhs)) ++ " monomials"
when (gbTrace .&. gbTProgressDetails /= 0) $ do
putStrLn "(whether used & head degree + sugar, # monomials):"
let show4 (n, d, h) m =
Expand All @@ -782,15 +786,16 @@ groebnerBasis gbpA@(GBPolyOps { .. }) gbTrace gbi0 newGens = TS.scope $ do
putStrLn (s ++ ":")
mapM_ (putStrLn . pShow) gbGens
else when (gbTrace .&. gbTSummary /= 0) $ putStrLn s
{- when (gbTrace .&. gbTQueues /= 0) $ do
hFlush stdout
callCommand "echo; ps -v" -}
WithNGens gkgs _kN <- readTVarIO gkgsRef
let fullReduce2NZ p = fst (gkgsReduce gkgs (IsDeep True) (SL.singleton cd) t)
where
(!cd, !t) = unconsNZ p
~redGbGens = if not useSugar.b then gbGens else
rrbMapParChunk 16 fullReduce2NZ gbGens
{- when (gbTrace .&. gbTQueues /= 0) $ do
hFlush stdout
callCommand "echo; ps -v" -}
when (gbTrace /= 0) $ hFlush stdout -- e.g. for TS.scope
pure $ GroebnerIdeal { gkgs, gbGhs, gbGens, redGbGens }
where
evShow = evShowPrec 0
Expand Down

0 comments on commit e28463a

Please sign in to comment.