unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#55744: infinite loop
@ 2022-05-31 19:49 Daniel R. Grayson
  2022-05-31 20:12 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 13+ messages in thread
From: Daniel R. Grayson @ 2022-05-31 19:49 UTC (permalink / raw)
  To: 55744


[-- Attachment #1.1: Type: text/plain, Size: 5535 bytes --]

The attached file contains the string "end--" in two places.  When
searching for that string with M-x isearch-forward (C-s) in that file,
just after opening the file, starting from the top of the file, it often
happens, that after positioning the cursor at the first "end" in the file,
it displays "end-" on the mode line and then goes into an infinite loop,
not responding to further input or making any further
progress on the search.




In GNU Emacs 28.1 (build 1, x86_64-apple-darwin18.7.0, NS appkit-1671.60
Version 10.14.6 (Build 18G95))
 of 2022-04-22 built on builder10-14.lan
Windowing system distributor 'Apple', version 10.3.2113
System Description:  macOS 12.3

Configured using:
 'configure --with-ns '--enable-locallisppath=/Library/Application
 Support/Emacs/${version}/site-lisp:/Library/Application
 Support/Emacs/site-lisp' --with-modules'

Configured features:
ACL GMP GNUTLS JSON LIBXML2 MODULES NOTIFY KQUEUE NS PDUMPER THREADS
TOOLKIT_SCROLL_BARS ZLIB

Important settings:
  value of $EMACSLOADPATH:
/Applications/LilyPond.app/Contents/Resources/share/emacs/site-lisp:/Users/dan/local/share/emacs/site-lisp:/usr/local/share/emacs/site-lisp:
  value of $LC_ALL: en_US.UTF-8
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Info

Minor modes in effect:
  global-edit-server-edit-mode: t
  icomplete-mode: t
  global-auto-revert-mode: t
  auto-image-file-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  temp-buffer-resize-mode: t
  buffer-read-only: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
/Users/dan/src/M2/M2.git/M2/Macaulay2/editors/emacs/M2-symbols hides
/Applications/Macaulay2-1.20/share/emacs/site-lisp/macaulay2/M2-symbols
/Users/dan/src/M2/M2.git/M2/Macaulay2/editors/emacs/M2 hides
/Applications/Macaulay2-1.20/share/emacs/site-lisp/macaulay2/M2
/Users/dan/src/M2/M2.git/M2/Macaulay2/editors/emacs/M2-init hides
/Applications/Macaulay2-1.20/share/emacs/site-lisp/macaulay2/M2-init
/Users/dan/src/M2/M2.git/M2/Macaulay2/editors/emacs/M2-mode hides
/Applications/Macaulay2-1.20/share/emacs/site-lisp/macaulay2/M2-mode
/Users/dan/emacs/gedcom hides /Users/dan/home/emacs/gedcom
/Users/dan/src/M2/M2.git/M2/Macaulay2/editors/emacs/M2-symbols hides
/usr/local/share/emacs/site-lisp/macaulay2/M2-symbols
/Users/dan/src/M2/M2.git/M2/Macaulay2/editors/emacs/M2 hides
/usr/local/share/emacs/site-lisp/macaulay2/M2
/Users/dan/src/M2/M2.git/M2/Macaulay2/editors/emacs/M2-init hides
/usr/local/share/emacs/site-lisp/macaulay2/M2-init
/Users/dan/src/M2/M2.git/M2/Macaulay2/editors/emacs/M2-mode hides
/usr/local/share/emacs/site-lisp/macaulay2/M2-mode
/Users/dan/emacs/rmail hides
/Applications/Emacs.app/Contents/Resources/lisp/mail/rmail
/Users/dan/home/emacs/longlines hides
/Applications/Emacs.app/Contents/Resources/lisp/obsolete/longlines

Features:
(shadow sort mail-extr warnings emacsbug message rmc puny rfc822 mml
mml-sec epa epg rfc6068 epg-config gnus-util rmail mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail
rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils thai-util
thai-word lao-util enriched facemenu view vc-git diff-mode vc-dispatcher
M2 M2-symbols rx jka-compr dired-aux dired dired-loaddefs misearch
multi-isearch eieio-opt cl-extra speedbar ezimage dframe find-func
shortdoc thingatpt help-fns radix-tree tabify imenu man agda2-mode pcase
derived agda2-queue agda2-abbrevs skeleton agda2-highlight agda2
annotation eri time-date pp agda-input quail help-mode edit-server
easy-mmode edmacro kmacro server generic disp-table cc-styles cc-align
cc-engine cc-vars cc-defs icomplete grep compile text-property-search
comint ansi-color ring autorevert filenotify image-file image-converter
cus-load info proof-site proof-autoloads package browse-url url
url-proxy url-privacy url-expand url-methods url-history url-cookie
url-domsuf url-util mailcap url-handlers url-parse auth-source cl-seq
eieio eieio-core cl-macs eieio-loaddefs password-cache json subr-x map
url-vars seq byte-opt gv bytecomp byte-compile cconv cl-loaddefs cl-lib
iso-transl tooltip eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/ns-win ns-win ucs-normalize
mule-util term/common-win tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice button
loaddefs faces cus-face macroexp files window text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote threads kqueue cocoa ns multi-tty
make-network-process emacs)

Memory information:
((conses 16 299140 12614)
 (symbols 48 14179 3)
 (strings 32 50438 2510)
 (string-bytes 1 1513842)
 (vectors 16 26190)
 (vector-slots 8 305278 27939)
 (floats 8 93 32)
 (intervals 56 7639 129)
 (buffers 992 27))

[-- Attachment #1.2: Type: text/html, Size: 6045 bytes --]

[-- Attachment #2: Topcom.m2 --]
[-- Type: application/octet-stream, Size: 30752 bytes --]

-- TODO:
--   1. how to check if a triangulation is correct?
--   2. generate the (oriented) circuits of a point set
--   3. Perhaps: add in a type "Chirotope" to facilitate the computation of circuits
--   4. find the lower hull of a polytope (maybe in Polyhedra? Where?)
--   5. check that going from a regular fine triangulation to a regular star fine triangulation 
--       (in the reflexive case) works.
--   6. generate (parts of) the flip graph, at least for regular triangulations.
--   7. topcom uses symmetry, place that into the interface here too
-- possible bugs:
--   why are the regular triangulation weights sometimes coming out negative?
--   need to be able to check that weights are correct.
newPackage(
        "Topcom",
        Version => "0.5", 
        Date => "6 May 2018",
        Authors => {{
                Name => "Mike Stillman", 
                Email => "mike@math.cornell.edu", 
                HomePage=>"http://www.math.cornell.edu/~mike"
                }},
        Headline => "interface to a small part of topcom",
	Keywords => {"Interfaces"},
        Configuration => {
            "path" => ""
            },
        PackageImports => {"FourierMotzkin"}
        )

export {
    "allTriangulations",
    "chirotope",
    "fineStarTriangulation",
    "flips",
    "isRegularTriangulation",
    "naiveChirotope",
    "naiveIsTriangulation",
    "numFlips",
    "numTriangulations",
    "orientedCircuits",
    "orientedCocircuits",
    "regularFineTriangulation",
    "regularFineStarTriangulation",
    "regularTriangulationWeights",
    "ConnectedToRegular",
    "Homogenize",
    "RegularOnly",
    "Fine",
    "topcomIsTriangulation"
    }

-- for backward compatibility
if not programPaths#?"topcom" and Topcom#Options#Configuration#"path" != ""
    then programPaths#"topcom" = Topcom#Options#Configuration#"path"

topcomProgram = null

augment = (A) -> (
    -- A is a matrix over ZZ
    -- add in a last row of 1's.
    n := numColumns A;
    ones := matrix {{n : 1}};
    A || ones
    )

topcomPoints = method(Options=>{Homogenize=>true})
topcomPoints Matrix := opts -> (A) -> (
    A1 := if opts.Homogenize then augment A else A;
    new Array from for a in entries transpose A1 list new Array from a
    )

-- Workhorse function for calling topcom.
-- command: one of the commands of topcom, with command line arguments included.
-- inputs: a list of objects that are in the format for topcom to understand.
-- output: 2 file names, one for the stdout, one for stderr.
-- If the executable fails, what happens?
-- debugLevel: set to 0 - 7 for varying verbose output
callTopcom = method()
callTopcom(String, List) := (command, inputs) -> (
    if topcomProgram === null then
	topcomProgram = findProgram("topcom","cube 3", Prefix => {
	    (".*", "topcom-"), -- debian
	    ("^(cross|cube|cyclic|hypersimplex|lattice)$", "TOPCOM-"), --fedora
	    ("^cube$", "topcom_")}); --gentoo
    filename := temporaryFileName();
    infile := filename|".in";
    -- now create the output file
    F := openOut(infile);
    for f in inputs do (
        F << toString f << endl;
    );
    F << close;

    -- setting RaiseError to false because we sometimes get nonzero return
    -- values, e.g., the calls to topcomIsTriangulation in the
    -- "bad triangulations of the square" tests below
    retval := runProgram(topcomProgram, command, " < " | infile,
	KeepFiles => true, RaiseError => false);

    if debugLevel >= 1 then (
        << "-- calling topcom" << endl;
        << "-- " << command << ": using temporary file prefix " << filename << endl;
        );
    if debugLevel >= 7 then << "-- " << command << ": input = " << net get infile << endl;
    if debugLevel >= 2 then << "-- " << command << ": executing " << retval#"command" << endl;

    --if 0 =!= retval then error ("error running topcom:"| net get errfile);

    if debugLevel >= 5 then << "-- " << command << ": output = " << net retval#"output" << endl;
    if debugLevel >= 6 then << "-- " << command << ": stderr = " << net retval#"error" << endl;

    (retval#"output file", retval#"error file")
    )

isRegularTriangulation = method(Options=>{Homogenize=>true})
isRegularTriangulation(Matrix, List) := opts -> (A, tri) -> (
    -- now create the output file
    (outfile, errfile) := callTopcom("checkregularity --checktriang -v", {topcomPoints(A, opts), [], tri });
    match("Checked 1 triangulations, 0 non-regular so far", get errfile)
    )

regularTriangulationWeights = method(Options => options isRegularTriangulation)
regularTriangulationWeights(Matrix, List) := opts -> (A, tri) -> (
    -- returns null if the triangulation is not regular.
    -- otherwise returns a list of rational numbers which are the 
    -- heights that result in the triangulation.
    (outfile, errfile) := callTopcom("checkregularity --heights", {topcomPoints(A, opts), [], tri });
    output := get outfile;
    if match("non-regular", output) then return null;
    result := value first lines output;
    return if instance(result, Number) then {result} else toList result
    )

regularFineTriangulation = method(Options => options isRegularTriangulation)
regularFineTriangulation Matrix := opts -> (A) -> (
    (outfile,errfile) := callTopcom("points2finetriang --regular", {topcomPoints(A, opts)});
    value get outfile
    )

chirotope = method(Options => options isRegularTriangulation)
chirotope Matrix := opts -> A -> (
    (outfile,errfile) := callTopcom("points2chiro", {topcomPoints(A, opts)});
    get outfile
    )

naiveChirotope = method(Options => options chirotope)
naiveChirotope Matrix := opts -> A -> (
    A1 := if opts.Homogenize then augment A else A;
    n := numColumns A1;
    d := numRows A1;
    chiroHeader := (toString n) | "," | (toString d) | ":\n";
    subs := sort subsets(n,d);
    subs1 := pack(subs, 100);
    chiroHeader | concatenate for s in subs1 list (
        concatenate (for s1 in s list (
                d := det A1_s1;
                if d > 0 then "+" else if d == 0 then "0" else "-"
                )) | "\n"
        )
    )

orientedCircuits = method(Options => {Homogenize=>true})
orientedCircuits String := opts -> (chiro) -> (
    (outfile,errfile) := callTopcom("chiro2circuits", {chiro});
    s := lines get outfile;
    -- remove first 2 lines, and last line:
    s = drop(drop(s, 2), -1);
    circs := s/(x -> toList value x);
    -- now sort it all
    circs/sort//sort
    )
orientedCircuits Matrix := opts -> A -> orientedCircuits chirotope(A, opts)

orientedCocircuits = method(Options => {Homogenize=>true})
orientedCocircuits String := opts -> (chiro) -> (
    (outfile,errfile) := callTopcom("chiro2cocircuits", {chiro});
    s := lines get outfile;
    s = drop(drop(s, 2), -1);
    s/(x -> toList value x)
    )
orientedCocircuits Matrix := opts -> A -> orientedCocircuits chirotope(A, opts)

allTriangsExecutable = hashTable {
    -- Fine?, COnnectedToRegular?
    (true, true) => "points2finetriangs",
    (true, false) => "points2allfinetriangs",
    (false, true) => "points2triangs",
    (false, false) => "points2alltriangs"
    }
numTriangsExecutable = hashTable {
    -- Fine?, COnnectedToRegular?
    (true, true) => "points2nfinetriangs",
    (true, false) => "points2nallfinetriangs",
    (false, true) => "points2ntriangs",
    (false, false) => "points2nalltriangs"
    }

allTriangulations = method(Options => {Homogenize=>true, RegularOnly => true, Fine => false, ConnectedToRegular => true})
allTriangulations Matrix := opts -> (A) -> (
    if not opts.ConnectedToRegular and opts.RegularOnly then error "cannot have both RegularOnly=>true and ConnectedToRegular=>false";
    executable := allTriangsExecutable#(opts.Fine, opts.ConnectedToRegular);
    args := if opts.RegularOnly then " --regular" else "";
    (outfile, errfile) := callTopcom(executable | args, {topcomPoints(A, Homogenize=>opts.Homogenize)});
    tris := lines get outfile;
    -- if ConnectToRegular is true, then the output is different, and needs to be parsed.
    -- in the other case, we can avoid the first 2 lines but they don't do anything either.
    for t in tris list (
        t1 := replace(///T\[[0-9]+\]:=\[.*:///, "", t);
        t2 := replace(///\];///, "", t1);
        t3 := sort value t2
        )
    )

numTriangulations = method(Options => {Homogenize=>true, RegularOnly => true, Fine => false, ConnectedToRegular => true})
numTriangulations Matrix := opts -> (A) -> (
    if not opts.ConnectedToRegular and opts.RegularOnly then error "cannot have both RegularOnly=>true and ConnectedToRegular=>false";
    executable := numTriangsExecutable#(opts.Fine, opts.ConnectedToRegular);
    args := if opts.RegularOnly then " --regular" else "";
    (outfile, errfile) := callTopcom(executable | args, {topcomPoints(A, Homogenize=>opts.Homogenize)});
    value get outfile
    )

numFlips = method(Options => {Homogenize=>true, RegularOnly =>true})
numFlips(Matrix, List) := opts -> (A, tri) -> (
    executable := "points2nflips";
    args := if opts.RegularOnly then " --regular" else "";
    (outfile, errfile) := callTopcom(executable | args, {topcomPoints(A, Homogenize=>opts.Homogenize)});
    (get outfile, get errfile)
    )

flips = method(Options => {Homogenize=>true, RegularOnly =>true})
flips(Matrix, List) := opts -> (A, tri) -> (
    executable := "points2flips";
    args := if opts.RegularOnly then " --regular" else "";
    (outfile, errfile) := callTopcom(executable | args, {topcomPoints(A, Homogenize=>opts.Homogenize)});
    (get outfile, get errfile)
    )

fineStarTriangulation = method()
fineStarTriangulation(Matrix, List) := (A, tri) -> (
    aA := augment A;
    -- H := first halfspaces convexHull aA;
    H := transpose(-(first fourierMotzkin aA));
    myfacets := for e in entries H list (
        positions(flatten entries(matrix {e} * aA), x -> x == 0)
        );
    sort unique flatten for f in tri list for g in myfacets list (
        a := toList(set g * set f); 
        if #a < numRows A then 
        continue 
        else sort a
        )
    -- newtri = for f in newtri list append(f, numColumns A)
    )

regularFineStarTriangulation = method()
regularFineStarTriangulation Matrix := (A) -> fineStarTriangulation(A, regularFineTriangulation A)

naiveIsTriangulation = method()
naiveIsTriangulation(Matrix, List, List) := (A, circuits, tri) -> (
    aA := augment A;
    -- H := first halfspaces convexHull aA;
    H := transpose(-(first fourierMotzkin aA));
    myfacets := for e in entries H list (
        positions(flatten entries(matrix {e} * aA), x -> x == 0)
        );
    -- test 1: each wall should be in a facet of the convex hull, or occur exactly twice.
    walls := tally flatten for t in tri list subsets(t,#t-1);
    test1 := for k in keys walls list (
        if any(myfacets, f -> isSubset(k,f)) then 
          walls#k == 1
        else
          walls#k == 2
        );
    if any(test1, x -> not x) then return false;
    -- test 2: for each oriented circuit Z = (Z+, Z-)
    test2 := for z in circuits list (
      # select(tri, t -> isSubset(z_0, t)),
      # select(tri, t -> isSubset(z_1, t))
      );
    all(test2, x -> x#0 == 0 or x#1 == 0)
    )
naiveIsTriangulation(Matrix, List) := (A, tri) -> naiveIsTriangulation(A, orientedCircuits A, tri)


topcomIsTriangulation = method();
topcomIsTriangulation(Matrix, List) := (Vin, T) -> (
   -- Topcom does not check whether the sets in T actually form simplices. In
   -- that case it throws an error instead of giving an answer.  -- So we do it
   -- manually:
   V := promote(augment Vin, QQ);
   d := numRows V;
   if not all(T, t-> #t == d) then (
      << "Index sets do not correspond to full-dimensional simplices" << endl;
      return false;
   );
   simplices := apply(T, t -> V_t);
   if not all(simplices, s->d==rank s) then (
      << "Index sets do not correspond to full-dimensional simplices" << endl;
      return false;
   );
   (outfile, errfile) := callTopcom("points2nflips --checktriang -v", {topcomPoints(V, Homogenize=>false), [], T });
   not match("not valid", get errfile)
)


beginDocumentation()

doc ///
Key
  Topcom
Headline
  interface to selected functions from topcom package
Description
  Text
    Topcom @HREF{"http://www.rambau.wm.uni-bayreuth.de/TOPCOM/"}@ is mathematical software written by Jorg Rambau for 
    computing and manipulating triangulations of polytopes and chirotopes.
    
    This package implements two key functions from the topcom package
    @TO "isRegularTriangulation"@  checks whether a triangulation of a point set is a regular triangulation,
    and @TO "regularFineTriangulation"@ computes a triangulation which involves all lattice points of a polytope.
Caveat
  There are many other functions available in Topcom.  If you wish any of these implemented, or you would like to contribute
  such an implementation, please contact the author.
SeeAlso
  "CohomCalg::CohomCalg"
  "ReflexivePolytopesDB::ReflexivePolytopesDB"
///

doc ///
Key
  isRegularTriangulation
  (isRegularTriangulation,Matrix,List)
Headline
  determine if a given triangulation is a regular triangulation
Usage
  isRegularTriangulation(C, tri)
Inputs
  C:Matrix
    A matrix over ZZ.  Each column represents one of the points
    which can be used in a triangulation
  tri:List
    A triangulation of the point set C
Outputs
  :Boolean
    whether the given triangulation is regular
Description
  Text
    The following example is one of the simplest examples of a non-regular
    triangulation.  Notice that {\tt tri} is a triangulation of the 
    polytope which is the convex hull of the columns of $A$, which are 
    the only points allowed in the triangulation.
  Example
    A = transpose matrix {{0,3},{0,1},{-1,-1},{1,-1},{-4,-2},{4,-2}}
    tri = {{0,1,2}, {1,3,5}, {2,3,4}, {0,1,5}, 
        {0,2,4}, {3,4,5}, {1,2,3}}
    isRegularTriangulation(A,tri)
  Text
    Setting debugLevel to either 1,2, or 5 will give more detail about
    what files are written to Topcom, and what the executable is.
    Setting debugLevel to 0 means that the function will run silently.
Caveat
  Do we check that the triangulation is actually welll defined?
SeeAlso
  regularFineTriangulation  
///

TEST ///
-*
  restart
  debug needsPackage "Topcom"
*-
  -- test of isRegularTriangulation
  A = transpose matrix {{-1,-1,1},{-1,1,1},{1,-1,1},{1,1,1},{0,0,1}}
  regularFineTriangulation(A, Homogenize=>false)
  tri = {{0, 2, 4}, {2, 3, 4}, {0, 1, 4}, {1, 3, 4}}
  assert isRegularTriangulation(A,tri)
  assert(regularTriangulationWeights(A,tri,Homogenize=>false) == {1,1,0,0,0})
///

TEST ///
  needsPackage "Topcom"
  -- test of isRegularTriangulation
  A = transpose matrix {{0,3},{0,1},{-1,-1},{1,-1},{-4,-2},{4,-2}}
  tri = {{0,1,2}, {1,3,5}, {2,3,4},
         {0,1,5}, {0,2,4}, {3,4,5},
         {1,2,3}}
  assert not isRegularTriangulation(A,tri)
  assert(null === regularTriangulationWeights(A,tri))
  numTriangulations A
  allTriangulations A  
  allTriangulations(A, Fine=>true)
  allTriangulations(A, Fine=>true, RegularOnly=>false)
  A = transpose matrix {{0,3},{0,1},{-1,-1},{1,-1},{-4,-2},{7,-2}}
  tri = {{0,1,2}, {1,3,5}, {2,3,4},
         {0,1,5}, {0,2,4}, {3,4,5},
         {1,2,3}}
  assert isRegularTriangulation(A,tri)
  regularTriangulationWeights(A,tri) -- Question: how to test that this is correct
    -- TODO: need a function which takes a point set, weights, and creates the lift (easy)
    --       compute the lower hull of this polytope.

  assert(chirotope A == naiveChirotope A)
  orientedCircuits A
  orientedCocircuits A
  A = transpose matrix {{1,0},{0,1}}
  tri = {{0,1}}
  assert isRegularTriangulation(A,tri)
  regularTriangulationWeights(A,tri) == {0,1} -- TODO: check that this is the correct answer
  
  A = transpose matrix {{0}}
  tri = {{0}}
  assert isRegularTriangulation(A,tri)
  regularTriangulationWeights(A,tri) == {1}
///

///
-- TODO: This test needs to be made to assert correct statements
-- How to test that triangulations are correct?  What I thought worked does not.
  needsPackage "Topcom"
  A = transpose matrix{{-1,-1},{-1,1},{1,-1},{1,1},{0,0}}
  regularFineTriangulation A  
  tri = {{0, 2, 4}, {2, 3, 4}, {0, 1, 4}, {1, 3, 4}}
  tri = {{0, 2, 4}, {2, 3, 4}, {0, 1, 4}, {1, 2, 3}}
  isRegularTriangulation(A, tri) -- Wrong!!

  badtri = {{0, 2, 4}, {2, 3, 4}, {0, 1, 4}, {1, 2, 3}}
  debugLevel = 6
  isRegularTriangulation(A,badtri) -- this should fail! But it doesn't seem to do so. BUG in something!!!
  debugLevel = 0
  -- hmmm, we can make non-sensical triangulations, without it noticing.
  -- this should be a bug?  
  A = transpose matrix {{0,0},{0,1},{1,0},{1,1}}
  tri = {{0,1,2},{0,2,3}}
  assert isRegularTriangulation(A,tri)  
  tri = {{0,1,2},{1,2,3}}
  assert isRegularTriangulation(A,tri) 
///

TEST ///  
  needsPackage "Topcom"
  needsPackage "Polyhedra"
  
  A = transpose matrix {{-1,-1,2},{-1,0,1},{-1,1,1},{0,-1,2},{0,1,1},{1,-1,3},{1,0,-1},{1,1,-2}}
  debugLevel = 0
  tri = regularFineTriangulation A
  assert isRegularTriangulation(A, tri)
  assert(regularTriangulationWeights(A, tri) =!= null)

  A = transpose matrix {{-1, 0, -1, -1}, {-1, 0, 0, -1}, {-1, 1, 2, -1}, {-1, 1, 2, 0}, {1, -1, -1, -1}, {1, -1, -1, 1}, {1, 0, -1, 2}, {1, 0, 1, 2}}
  P2 = polar convexHull A
  C = matrix {latticePoints P2}
  tri = regularFineTriangulation C
  assert isRegularTriangulation(C, tri)
  regularTriangulationWeights(C, tri) -- is this correct?  Some weights have negative values??
///


TEST ///
-- simple example of chirotope
-*
  restart
  debug needsPackage "Topcom"
*-
  A = transpose matrix {{-1,-1},{-1,1},{1,-1},{1,1},{0,0}}
  tri = {{0, 2, 4}, {2, 3, 4}, {0, 1, 4}, {1, 3, 4}}
  ch1 = chirotope A
  ch2 = naiveChirotope A
  assert(ch1 == ch2)
///

TEST ///
-- Bad triangulations of the square
V = transpose matrix {{0,0},{1,0},{0,1},{1,1}}
T1 = {{0,1,2}}
T2 = {{0,1,2},{0,1,3}}
T3 = {{0,1,2,3}}
assert(not naiveIsTriangulation(V, T1))
assert(not naiveIsTriangulation(V, T2))
assert(not naiveIsTriangulation(V, T3))
-- assert(not topcomIsTriangulation(V, T1)) -- topcom signals an error here
-- assert(not topcomIsTriangulation(V, T2)) -- topcom signals an error here
assert(not topcomIsTriangulation(V, T3))
///

-- This example is a good one, but takes too long to be run automatically
///
restart
  needsPackage "Topcom"  
  needsPackage "Polyhedra"
  pts =  {{-1,0,0,-1},{-1,0,1,-1},{-1,0,1,0},{-1,1,0,-1},{-1,1,0,0},{-1,1,1,2},{1,-1,0,-1},{1,0,-1,1},{1,-1,-1,-1},{0,0,0,-1}}
  A = transpose matrix pts 
  -- debugLevel = 7

  elapsedTime n1 = numTriangulations(A, Fine=>true, ConnectedToRegular=>true) -- 6.9 sec, 408 of these CORRECT
  elapsedTime n2 = numTriangulations(A, Fine=>true, ConnectedToRegular=>false) -- 116 sec, 448 of these WRONG
  elapsedTime n3 = numTriangulations(A, Fine=>false, ConnectedToRegular=>true)  -- 8 sec, 520 of these CORRECT
  elapsedTime n4 = numTriangulations(A, Fine=>false, ConnectedToRegular=>false) -- 115 sec, 564 of these WRONG

  elapsedTime n5 = numTriangulations(A, Fine=>true, ConnectedToRegular=>true, RegularOnly=>false) -- .09 sec, 448 of these
  elapsedTime n6 = numTriangulations(A, Fine=>true, ConnectedToRegular=>false, RegularOnly=>false) -- 115.5 sec, 448 of these
  elapsedTime n7 = numTriangulations(A, Fine=>false, ConnectedToRegular=>true, RegularOnly=>false)  -- .11 sec, 564 of these
  elapsedTime n8 = numTriangulations(A, Fine=>false, ConnectedToRegular=>false, RegularOnly=>false) -- 116 sec, 564 of these

  elapsedTime set1 = allTriangulations(A, Fine=>true, ConnectedToRegular=>true); -- 6.9 sec, 408  CORRECT
  elapsedTime set2 = allTriangulations(A, Fine=>true, ConnectedToRegular=>false); -- 118 sec, 448 WRONG
  elapsedTime set3 = allTriangulations(A, Fine=>false, ConnectedToRegular=>true); -- 8.1 sec, 520 CORRECT
  elapsedTime set4 = allTriangulations(A, Fine=>false, ConnectedToRegular=>false); -- 116 sec.  564 of these. WRONG

  elapsedTime set5 = allTriangulations(A, Fine=>true, ConnectedToRegular=>true, RegularOnly=>false); -- .15 sec, 448 of these
  elapsedTime set6 = allTriangulations(A, Fine=>true, ConnectedToRegular=>false, RegularOnly=>false); -- 116 sec, 448 of these
  elapsedTime set7 = allTriangulations(A, Fine=>false, ConnectedToRegular=>true, RegularOnly=>false); -- .22 sec, 564 of these
  elapsedTime set8 = allTriangulations(A, Fine=>false, ConnectedToRegular=>false, RegularOnly=>false); -- 117 sec, 564 of these

  assert((n1,n2,n3,n4,n5,n6,n7,n8) == (#set1, #set2, #set3, #set4, #set5, #set6, #set7, #set8))
  fineTris = select(set8, x -> # unique flatten x == numColumns A);
  regularFineTris = select(fineTris, x -> isRegularTriangulation(A, x));
  regularTris = select(set8, x -> isRegularTriangulation(A, x));

  assert(#regularFineTris == 408)
  assert(#fineTris == 448)
  assert(#regularTris == 520)  

  assert(set set5 === set set6) -- in general, this doesn't need to hold, but it is rare for this to be the case
  assert(set set7 === set set8) -- same: rare for this to not hold
  assert(set set4 === set set8) -- this one should not be true?  
  assert(set select(set7, x -> isRegularTriangulation(A, x)) === set set3)
  assert(set select(set5, x -> isRegularTriangulation(A, x)) === set set1)

  set5_0
  for tri in set5 list naiveIsTriangulation(A, tri)

  numFlips(A, set5_0)  
  flips(A, set5_0)
  -- now let's see about the naive way of getting regular star triangulations 
  -- i.e. we add in the origin
  
  pts1 =  {{-1,0,0,-1},{-1,0,1,-1},{-1,0,1,0},{-1,1,0,-1},{-1,1,0,0},{-1,1,1,2},{1,-1,0,-1},{1,0,-1,1},{1,-1,-1,-1},{0,0,0,-1},{0,0,0,0}}
  A1 = transpose matrix pts1
  --elapsedTime tris1 = allTriangulations(A1, Fine=>true, ConnectedToRegular=>true, RegularOnly=>false); -- 
  elapsedTime tris1 = allTriangulations(A1, Fine=>false, ConnectedToRegular=>true, RegularOnly=>false); -- 
  fineTris1 = select(tris1, x -> # unique flatten x == numColumns A1);
  regTris1 = select(tris1, x -> isRegularTriangulation(A1, x));  
  fineRegTris1 = select(regTris1, x -> # unique flatten x == numColumns A1);
  stars1 = select(tris1, x -> all(x, x1 -> member(10, x1))); -- 100 here
  starsFine1 = select(stars1, x -> # unique flatten x == numColumns A1);
  RST = select(stars1, x -> isRegularTriangulation(A1,x)); -- 80 here...
  FSRT = select(starsFine1, x -> isRegularTriangulation(A1,x)); -- 48 here...!


  unique for tri in set5 list (
      tri1 := fineStarTriangulation(A, tri);
      newtri := for t in tri1 list append(t, 10);
      newtri
      );
  select(oo, tri -> isRegularTriangulation(A1, tri))  

  -- let's test this one for being a triangulation:
  oA = orientedCircuits A
  tri = set5_3
  tally flatten for t in tri list subsets(t,4)
  for z in oA list (
      # select(tri, t -> isSubset(z_0, t)),
      # select(tri, t -> isSubset(z_1, t))
      )
  -- todo:
  -- 1. routine to check that a triangulation is a triangulation
  -- 2. routine to turn a regular, fine triangulation, into a star (fine, regular) triangulation. How general is this? DONE, I think.
  -- 3. perform bistellar flips to get new triangulations.
///

///
  restart
  needsPackage "ReflexivePolytopesDB"
  needsPackage "Topcom"  
  needsPackage "Polyhedra"
 str = "4 18  M:53 18 N:11 10 H:6,45 [-78]
        1   0   0  -2   0   2   1   3  -2   2  -2   2   3  -1   0  -2   0  -1
        0   1   0   2   0   0   1  -2   1  -2   0   0  -1   0  -2   0  -2  -1
        0   0   1   1   0  -1  -1  -2   2  -2   0  -2  -2   2  -1   2   1   2
        0   0   0   0   1  -1  -1   0  -1   1   1  -1  -1  -1   2  -1   0  -1"
 str = "4 12  M:50 12 N:11 9 H:6,44 [-76]
        1   1   1  -1  -1   0   2  -3  -2   3  -5   1
        0   2   0  -2   0   0   1  -3  -2   4  -5   4
        0   0   2   0  -2   0   2  -3   0   2  -3   0
        0   0   0   0   0   1  -1   1   1  -2   1  -2"
 A = matrixFromString last first parseKS str
 A = matrix first kreuzerSkarke str
 P = convexHull A
 P2 = polar P
 A1 = vertices P2
 LP = matrix{select(latticePoints P2, x -> x != 0)}
 numTriangulations(LP, Fine => true)
 allTriangulations(LP, Fine=>true);
 numTriangulations(LP)
 allTriangulations(LP);

///

end----------------------------------------------------

restart
uninstallPackage "Topcom"
restart
check "Topcom"
restart
installPackage "Topcom"
needsPackage "Topcom"


TEST /// 
  -- points2chiro
  toppath = "/Users/mike/src/M2-master/M2/BUILD/dan/builds.tmp/as-mth-indigo.local-master/libraries/topcom/build/topcom-0.17.8/src/"
  A = transpose matrix {{-1,-1,1},{-1,1,1},{1,-1,1},{1,1,1},{0,0,1}}
  tri = {{0, 2, 4}, {2, 3, 4}, {0, 1, 4}, {1, 3, 4}}
  run (toppath|"/points2chiro"|" -h")
  "topcomfoo.in" << topcomPoints(A, Homogenize=>false) << endl << close;
  chiro = get ("!"|toppath|"/points2chiro"|" <topcomfoo.in")
  #chiro
  chiro2 = "5,3:\n" | (concatenate for s in sort subsets(5,3) list (
      d := det A_s;
      if d > 0 then "+" else if d == 0 then "0" else "-"
      )) | "\n"
  chiro == chiro2
  -- notes: a chirotope for topcom:
  --  5,3:  (number of vertices, dim)
  --  a string of "-","+","0", maybe cut over a number of lines.
  -- should we make a type out of this (so we can read and write it to a file)

  -- chiro2circuits
  "topcomfoo.in" << chiro << endl << [] << endl << close;
  circs = get ("!"|toppath|"/chiro2circuits"|"  <topcomfoo.in")
  cocircs = get ("!"|toppath|"/chiro2cocircuits"|"  <topcomfoo.in")
  drop(drop(circs, 2), -1)
  oo/value

chiro = "5, 3:"

r12'chiro = "12, 4:
-+--+++---++---++-+---++-+++-----++--++-++++--++---+++-+++--+---++---++--++-++++
--+---++-+++--+++--++--+----+-+++--+++--++--+----+---++--++-++++-++--+-----+----
-++---++---+++-+++--+---++---++--++-++++--+---++-+++--+++--++--+----+-+++--+++--
++--+----+---++--++-++++---++-+++++-+++++--++++---++-+++--+++--++--+----+-+++--+
++--++--+----+---++--++-++++---++-+++++-+++++--+++---++---++--++-++++-+++--++--+
----+++--+-----+-----++--+++--++--+----+++--+-----+-----++----++-+++++-+++++--++
--------++--++-
"
  chiro = r12'chiro
  -- chiro2alltriangs, chiro2nalltriangs
  "topcomfoo.in" << "5, 3:" << endl << chiro << endl << [] << endl << close;
  "topcomfoo.in" << chiro << [] << endl << close;
  get ("!"|toppath|"/chiro2placingtriang"|" -v <topcomfoo.in")
  get ("!"|toppath|"/chiro2circuits"|" <topcomfoo.in")
  get ("!"|toppath|"/chiro2cocircuits"|" <topcomfoo.in")
  get ("!"|toppath|"/chiro2alltriangs"|" <topcomfoo.in")
  get ("!"|toppath|"/chiro2ntriangs"|" <topcomfoo.in")
  get ("!"|toppath|"/chiro2finetriang"|" <topcomfoo.in")
  get ("!"|toppath|"/chiro2finetriangs"|" <topcomfoo.in") -- what is the format of the output here??
  get ("!"|toppath|"/chiro2nfinetriangs"|" -v <topcomfoo.in")
  
///

TEST ///
  restart
  debug needsPackage "Topcom"
  needsPackage "ReflexivePolytopesDB"
  needsPackage "StringTorics"
  polytopes = kreuzerSkarke(50, Limit=>10);
  tope = polytopes_5
  A = matrix tope
  P = convexHull A
  P2 = polar P
  A = matrix{latticePoints P2}

  LP = drop(latticePointList P2, -1);
  A = transpose matrix LP;
  debugLevel = 6
  elapsedTime tri = regularFineTriangulation A;
  
  -- XXX
  augment A
  "topcomfoo.in" << topcomPoints(augment A, Homogenize=>false) << endl << close;
  chiro = get ("!"|toppath|"/points2chiro"|" <topcomfoo.in")

  "topcomfoo.in" << chiro << "[]" << endl << close;
  get ("!"|toppath|"/chiro2circuits"|" <topcomfoo.in")
  get ("!"|toppath|"/chiro2ntriangs"|" <topcomfoo.in")
  --get ("!"|toppath|"/chiro2alltriangs"|"  <topcomfoo.in")
  get ("!"|toppath|"/chiro2cocircuits"|" <topcomfoo.in")    
///

TEST ///
-- how to check a triangulation?  I don't think that Topcom has this implemented for general use.
-*
  restart
  debug needsPackage "Topcom"
*-
  -- test of isRegularTriangulation
  toppath = "/Users/mike/src/M2-master/M2/BUILD/dan/builds.tmp/as-mth-indigo.local-master/libraries/topcom/build/topcom-0.17.8/src/"
  A = transpose matrix {{-1,-1,1},{-1,1,1},{1,-1,1},{1,1,1},{0,0,1}}
  badtri = {{0, 2, 4}, {2, 3, 4}, {0, 1, 4}, {1, 2}}
  debugLevel = 6

  -- a regular triangulation
  A = transpose matrix {{0,3},{0,1},{-1,-1},{1,-1},{-4,-2},{7,-2}}
  tri = {{0,1,2}, {1,3,5}, {2,3,4},
         {0,1,5}, {0,2,4}, {3,4,5},
         {1,2,3}}
  "topcomfoo.in" << topcomPoints(A, Homogenize=>true) << endl << "[]" << endl << tri << endl << close;
  run (topcompath|"checkregularity"|" --heights <topcomfoo.in >topcomfoo.out")  

  -- points2chiro
  "topcomfoo.in" << topcomPoints(A, Homogenize=>false) << endl << "[]" << endl << badtri << endl << close;
  print (toppath|"/points2alltriangs"|" --checktriang -v <topcomfoo.in") 


  A = transpose matrix {{0,3},{0,1},{-1,-1},{1,-1},{-4,-2},{4,-2}}
  tri = {{0,1,2}, {1,3,5}, {2,3,4},
         {0,1,5}, {0,2,4}, {3,4,5},
         {1,2,3}}
  "topcomfoo.in" << topcomPoints(A, Homogenize=>true) << endl << "[]" << endl << tri << endl << close;
  run (topcompath|"checkregularity"|" --heights <topcomfoo.in >topcomfoo.out")
  assert not isRegularTriangulation(A,tri)

///


end--

restart
uninstallPackage "Topcom"
restart
needsPackage "Topcom"
installPackage "Topcom"
restart
check "Topcom"
viewHelp

///
-- generate examples to use for this package
-- from reflexive polytopes of dim 4
  restart
  needsPackage "StringTorics"

  str = getKreuzerSkarke(10, Limit=>5)
  str = getKreuzerSkarke(20, Limit=>5)
  str = getKreuzerSkarke(30, Limit=>5)
  polytopes = parseKS str
  tope = polytopes_4_1
  A = matrixFromString tope
  P = convexHull A
  P2 = polar P
  LP = drop(latticePointList P2, -1)
  A1 = transpose matrix LP
  A2 = transpose matrix latticePointList P2
  tri = regularFineTriangulation A1
  tri2 = regularFineTriangulation A2
  #tri
  #tri2
  elapsedTime chiro1 = chirotope A1;
  elapsedTime chiro2 = chirotope A2;
  elapsedTime # orientedCircuits chiro1
  elapsedTime # orientedCircuits chiro2
  elapsedTime # orientedCocircuits chiro1
  elapsedTime # orientedCocircuits chiro2
  (select(orientedCocircuits A2, f -> #f#0 == 0 or #f#1 == 0))/first
  netList annotatedFaces P2  
  tri2
  -- fine:
  assert(sort unique flatten tri2 == toList (0..14))
  walls = tri2/(x -> subsets(x, #x-1))//flatten
  nfacets = tally walls
  facs = (select((annotatedFaces P2), x -> x_0 == 3))/(x -> x#2)
  walls = partition(k -> nfacets#k, keys nfacets)
  for w in walls#1 list (
      # select(facs, f -> isSubset(w, f))
      )
  for w in walls#2 list (
      # select(facs, f -> isSubset(w, f))
      )
  -- check overlaps of elements of tri2:
  C = orientedCircuits A2;
  elapsedTime for c in C list (
      val1 := select(tri2, x -> isSubset(c_0, x));
      val2 := select(tri2, x -> isSubset(c_1, x));
      if #val1 > 0 and #val2 > 0 then print (c, val1, val2);
      (c, #val1, #val2));
  
  tri_0
  
///
  
doc ///
Key
Headline
Usage
Inputs
Outputs
Consequences
Description
  Text
  Example
  Code
  Pre
Caveat
SeeAlso
///


^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#55744: infinite loop
  2022-05-31 19:49 bug#55744: infinite loop Daniel R. Grayson
@ 2022-05-31 20:12 ` Lars Ingebrigtsen
  2022-05-31 20:26   ` Daniel R. Grayson
  0 siblings, 1 reply; 13+ messages in thread
From: Lars Ingebrigtsen @ 2022-05-31 20:12 UTC (permalink / raw)
  To: Daniel R. Grayson; +Cc: 55744

"Daniel R. Grayson" <danielrichardgrayson@gmail.com> writes:

> The attached file contains the string "end--" in two places.  When
> searching for that string with M-x isearch-forward (C-s) in that file,
> just after opening the file, starting from the top of the file, it
> often happens, that after positioning the cursor at the first "end" in
> the file, it displays "end-" on the mode line and then goes into an
> infinite loop, not responding to further input or making any further
> progress on the search.

I'm unable to reproduce this in Emacs 28.1 (on Debian/bookworm).  Is
this with "emacs -Q"?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#55744: infinite loop
  2022-05-31 20:12 ` Lars Ingebrigtsen
@ 2022-05-31 20:26   ` Daniel R. Grayson
  2022-05-31 20:28     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 13+ messages in thread
From: Daniel R. Grayson @ 2022-05-31 20:26 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 55744

[-- Attachment #1: Type: text/plain, Size: 846 bytes --]

Nope, no command line options.

On Tue, May 31, 2022 at 1:12 PM Lars Ingebrigtsen <larsi@gnus.org> wrote:

> "Daniel R. Grayson" <danielrichardgrayson@gmail.com> writes:
>
> > The attached file contains the string "end--" in two places.  When
> > searching for that string with M-x isearch-forward (C-s) in that file,
> > just after opening the file, starting from the top of the file, it
> > often happens, that after positioning the cursor at the first "end" in
> > the file, it displays "end-" on the mode line and then goes into an
> > infinite loop, not responding to further input or making any further
> > progress on the search.
>
> I'm unable to reproduce this in Emacs 28.1 (on Debian/bookworm).  Is
> this with "emacs -Q"?
>
> --
> (domestic pets only, the antidote for overdose, milk.)
>    bloggy blog: http://lars.ingebrigtsen.no
>

[-- Attachment #2: Type: text/html, Size: 1398 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#55744: infinite loop
  2022-05-31 20:26   ` Daniel R. Grayson
@ 2022-05-31 20:28     ` Lars Ingebrigtsen
  2022-05-31 20:42       ` Daniel R. Grayson
  0 siblings, 1 reply; 13+ messages in thread
From: Lars Ingebrigtsen @ 2022-05-31 20:28 UTC (permalink / raw)
  To: Daniel R. Grayson; +Cc: 55744

"Daniel R. Grayson" <danielrichardgrayson@gmail.com> writes:

> Nope, no command line options.

I mean, can you reproduce this problem with "emacs -Q" (which makes
Emacs start up without reading your init files)?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#55744: infinite loop
  2022-05-31 20:28     ` Lars Ingebrigtsen
@ 2022-05-31 20:42       ` Daniel R. Grayson
  2022-06-01  2:29         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 13+ messages in thread
From: Daniel R. Grayson @ 2022-05-31 20:42 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 55744


[-- Attachment #1.1: Type: text/plain, Size: 105 bytes --]

Ah, indeed, the bug doesn't seem to be reproducible with "-Q".  I attach my
.emacs and .emacs-Macaulay2.

[-- Attachment #1.2: Type: text/html, Size: 172 bytes --]

[-- Attachment #2: .emacs --]
[-- Type: application/octet-stream, Size: 66412 bytes --]

[-- Attachment #3: .emacs-Macaulay2 --]
[-- Type: application/octet-stream, Size: 1179 bytes --]

;-*-emacs-lisp-*-

;; add "/Applications/Macaulay2-1.20/share/emacs/site-lisp/macaulay2" to load-path if it isn't there
(add-to-list 'load-path "/Applications/Macaulay2-1.20/share/emacs/site-lisp/macaulay2")

;; add "/Applications/Macaulay2-1.20/share/info" to Info-default-directory-list if it isn't there
(add-to-list 'Info-default-directory-list "/Applications/Macaulay2-1.20/share/info")

;; add "/Applications/Macaulay2-1.20/bin" to PATH if it isn't there
(if (not (string-match "/Applications/Macaulay2-1.20/bin" (getenv "PATH")))
     (setenv "PATH" "/Applications/Macaulay2-1.20/bin:$PATH" t))

;; this version will give an error if M2-init.el is not found:
(load "M2-init")

;; this version will not give an error if M2-init.el is not found:
;(load "M2-init" t)

; You may comment out the following line with an initial semicolon if you 
; want to use your f12 key for something else.  However, this action
; will be undone the next time you run setup() or setupEmacs().
(global-set-key [ f12 ] 'M2)

; Prevent Emacs from inserting a superfluous "See" or "see" in front
; of the hyperlinks when reading documentation in Info mode.
(setq Info-hide-note-references 'hide)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#55744: infinite loop
  2022-05-31 20:42       ` Daniel R. Grayson
@ 2022-06-01  2:29         ` Lars Ingebrigtsen
  2022-06-01 14:27           ` Daniel R. Grayson
  0 siblings, 1 reply; 13+ messages in thread
From: Lars Ingebrigtsen @ 2022-06-01  2:29 UTC (permalink / raw)
  To: Daniel R. Grayson; +Cc: 55744

"Daniel R. Grayson" <danielrichardgrayson@gmail.com> writes:

> Ah, indeed, the bug doesn't seem to be reproducible with "-Q".  I
> attach my .emacs and .emacs-Macaulay2.

Try removing things from those to determine what triggers the problem.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#55744: infinite loop
  2022-06-01  2:29         ` Lars Ingebrigtsen
@ 2022-06-01 14:27           ` Daniel R. Grayson
  2022-06-01 15:35             ` Lars Ingebrigtsen
  0 siblings, 1 reply; 13+ messages in thread
From: Daniel R. Grayson @ 2022-06-01 14:27 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 55744

[-- Attachment #1: Type: text/plain, Size: 332 bytes --]

Okay, I did that, and it seems to be this:

(defconst M2-mode-font-lock-keywords ' (
"///\\(/?/?[^/]\\|\\(//\\)*////[^/]\\)*\\(//\\)*///" .
'font-lock-string-face) )
(define-derived-mode M2-mode prog-mode "Macaulay2" (setq font-lock-defaults
'( M2-mode-font-lock-keywords )) )
(add-to-list 'auto-mode-alist '("\\.m2\\'" . M2-mode))

[-- Attachment #2: Type: text/html, Size: 442 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#55744: infinite loop
  2022-06-01 14:27           ` Daniel R. Grayson
@ 2022-06-01 15:35             ` Lars Ingebrigtsen
  2022-06-01 15:47               ` Daniel R. Grayson
  2022-06-06 22:15               ` Richard Stallman
  0 siblings, 2 replies; 13+ messages in thread
From: Lars Ingebrigtsen @ 2022-06-01 15:35 UTC (permalink / raw)
  To: Daniel R. Grayson; +Cc: 55744

"Daniel R. Grayson" <danielrichardgrayson@gmail.com> writes:

> Okay, I did that, and it seems to be this:
>
> (defconst M2-mode-font-lock-keywords
>           '("///\\(/?/?[^/]\\|\\(//\\)*////[^/]\\)*\\(//\\)*///" .
> 'font-lock-string-face) )

That's a regexp with a lot of backtracking, I think (i.e., elements that
can be matched both by the ?'s as well as the two *'s).  So matching
this will be slow, which results in the hangs you're seeing when Emacs
is trying to match that to the text in the buffer.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#55744: infinite loop
  2022-06-01 15:35             ` Lars Ingebrigtsen
@ 2022-06-01 15:47               ` Daniel R. Grayson
  2022-06-01 15:48                 ` Lars Ingebrigtsen
  2022-06-06 22:15               ` Richard Stallman
  1 sibling, 1 reply; 13+ messages in thread
From: Daniel R. Grayson @ 2022-06-01 15:47 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 55744

[-- Attachment #1: Type: text/plain, Size: 1106 bytes --]

Ah, you're right -- if I wait 45 seconds or so, it finally finishes and
moves on,
and that file has strings that should have matched it.  And it needs to
match all the text
from the start of the file, since string starts and string ends look the
same.  And the result is the same
if I search for any other string that first occurs deep into the file.

Thanks, it's not a bug in emacs!



On Wed, Jun 1, 2022 at 8:35 AM Lars Ingebrigtsen <larsi@gnus.org> wrote:

> "Daniel R. Grayson" <danielrichardgrayson@gmail.com> writes:
>
> > Okay, I did that, and it seems to be this:
> >
> > (defconst M2-mode-font-lock-keywords
> >           '("///\\(/?/?[^/]\\|\\(//\\)*////[^/]\\)*\\(//\\)*///" .
> > 'font-lock-string-face) )
>
> That's a regexp with a lot of backtracking, I think (i.e., elements that
> can be matched both by the ?'s as well as the two *'s).  So matching
> this will be slow, which results in the hangs you're seeing when Emacs
> is trying to match that to the text in the buffer.
>
> --
> (domestic pets only, the antidote for overdose, milk.)
>    bloggy blog: http://lars.ingebrigtsen.no
>

[-- Attachment #2: Type: text/html, Size: 1739 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#55744: infinite loop
  2022-06-01 15:47               ` Daniel R. Grayson
@ 2022-06-01 15:48                 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 13+ messages in thread
From: Lars Ingebrigtsen @ 2022-06-01 15:48 UTC (permalink / raw)
  To: Daniel R. Grayson; +Cc: 55744

"Daniel R. Grayson" <danielrichardgrayson@gmail.com> writes:

> Thanks, it's not a bug in emacs!

Thanks; I'm closing this bug report, then.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#55744: infinite loop
  2022-06-01 15:35             ` Lars Ingebrigtsen
  2022-06-01 15:47               ` Daniel R. Grayson
@ 2022-06-06 22:15               ` Richard Stallman
  2022-06-06 22:46                 ` Daniel R. Grayson
  2022-06-07  2:28                 ` Eli Zaretskii
  1 sibling, 2 replies; 13+ messages in thread
From: Richard Stallman @ 2022-06-06 22:15 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: danielrichardgrayson, 55744

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > That's a regexp with a lot of backtracking, I think (i.e., elements that
  > can be matched both by the ?'s as well as the two *'s).  So matching
  > this will be slow, which results in the hangs you're seeing when Emacs
  > is trying to match that to the text in the buffer.

Would it make sense to say more about this point in the Emacs Lisp Manual
where it describes regexps?

-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)







^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#55744: infinite loop
  2022-06-06 22:15               ` Richard Stallman
@ 2022-06-06 22:46                 ` Daniel R. Grayson
  2022-06-07  2:28                 ` Eli Zaretskii
  1 sibling, 0 replies; 13+ messages in thread
From: Daniel R. Grayson @ 2022-06-06 22:46 UTC (permalink / raw)
  To: rms; +Cc: Lars Ingebrigtsen, 55744

[-- Attachment #1: Type: text/plain, Size: 1015 bytes --]

Conceivably, although I wasn't referring to the manual, even after I
isolated the offending
regexp.

On Mon, Jun 6, 2022 at 3:15 PM Richard Stallman <rms@gnu.org> wrote:

> [[[ To any NSA and FBI agents reading my email: please consider    ]]]
> [[[ whether defending the US Constitution against all enemies,     ]]]
> [[[ foreign or domestic, requires you to follow Snowden's example. ]]]
>
>   > That's a regexp with a lot of backtracking, I think (i.e., elements
> that
>   > can be matched both by the ?'s as well as the two *'s).  So matching
>   > this will be slow, which results in the hangs you're seeing when Emacs
>   > is trying to match that to the text in the buffer.
>
> Would it make sense to say more about this point in the Emacs Lisp Manual
> where it describes regexps?
>
> --
> Dr Richard Stallman (https://stallman.org)
> Chief GNUisance of the GNU Project (https://gnu.org)
> Founder, Free Software Foundation (https://fsf.org)
> Internet Hall-of-Famer (https://internethalloffame.org)
>
>
>

[-- Attachment #2: Type: text/html, Size: 1677 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#55744: infinite loop
  2022-06-06 22:15               ` Richard Stallman
  2022-06-06 22:46                 ` Daniel R. Grayson
@ 2022-06-07  2:28                 ` Eli Zaretskii
  1 sibling, 0 replies; 13+ messages in thread
From: Eli Zaretskii @ 2022-06-07  2:28 UTC (permalink / raw)
  To: rms; +Cc: larsi, danielrichardgrayson, 55744

> Cc: danielrichardgrayson@gmail.com, 55744@debbugs.gnu.org
> From: Richard Stallman <rms@gnu.org>
> Date: Mon, 06 Jun 2022 18:15:06 -0400
> 
>   > That's a regexp with a lot of backtracking, I think (i.e., elements that
>   > can be matched both by the ?'s as well as the two *'s).  So matching
>   > this will be slow, which results in the hangs you're seeing when Emacs
>   > is trying to match that to the text in the buffer.
> 
> Would it make sense to say more about this point in the Emacs Lisp Manual
> where it describes regexps?

I think we already do, see the node "Regexp Problems" there.





^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-06-07  2:28 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-31 19:49 bug#55744: infinite loop Daniel R. Grayson
2022-05-31 20:12 ` Lars Ingebrigtsen
2022-05-31 20:26   ` Daniel R. Grayson
2022-05-31 20:28     ` Lars Ingebrigtsen
2022-05-31 20:42       ` Daniel R. Grayson
2022-06-01  2:29         ` Lars Ingebrigtsen
2022-06-01 14:27           ` Daniel R. Grayson
2022-06-01 15:35             ` Lars Ingebrigtsen
2022-06-01 15:47               ` Daniel R. Grayson
2022-06-01 15:48                 ` Lars Ingebrigtsen
2022-06-06 22:15               ` Richard Stallman
2022-06-06 22:46                 ` Daniel R. Grayson
2022-06-07  2:28                 ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).