From 05f5c46c37ff4e93708a57ae751ab697f72a1b1d Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Tue, 6 Aug 2024 14:58:34 -0400 Subject: [PATCH 1/5] Simplify toExternalString for mutable types The error message was essentially the same for mutable lists and mutable hash tables, so we combine them. We also drop toExternalString(Type), since Type is a subclass of MutableHashTable, and we can just use inheritance. --- M2/Macaulay2/m2/nets.m2 | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/M2/Macaulay2/m2/nets.m2 b/M2/Macaulay2/m2/nets.m2 index 2fbf64e9d5..dada7f59f0 100644 --- a/M2/Macaulay2/m2/nets.m2 +++ b/M2/Macaulay2/m2/nets.m2 @@ -69,14 +69,13 @@ toExternalString Net := x -> if height x + depth x == 0 then concatenate("(horizontalJoin())", "^", toString height x) else concatenate(format toString x, "^", toString(height x - 1)) -toExternalString MutableHashTable := s -> ( - if hasAttribute(s,ReverseDictionary) then return toString getAttribute(s,ReverseDictionary); - error "anonymous mutable hash table cannot be converted to external string"; - ) -toExternalString Type := s -> ( - if hasAttribute(s,ReverseDictionary) then return toString getAttribute(s,ReverseDictionary); - error "anonymous type cannot be converted to external string"; - ) +toExternalString MutableHashTable := +toExternalString MutableList := s -> ( + if hasAttribute(s,ReverseDictionary) + then toString getAttribute(s,ReverseDictionary) + else error("anonymous ", synonym class s, + " cannot be converted to external string")) + toExternalString HashTable := s -> ( concatenate ( "new ", toExternalString class s, @@ -86,10 +85,6 @@ toExternalString HashTable := s -> ( then demark(", ", apply(pairs s, (k,v) -> toExternalString k | " => " | toExternalString v) ) else "", "}")) -toExternalString MutableList := s -> ( - error "anonymous mutable list cannot be converted to external string"; - -- concatenate("new ",toExternalString class s, " from {...", toString(#s), "...}" ) - ) mid := s -> ( if #s === 1 then toExternalString s#0 else between(",",apply(toSequence s,x -> if x === null then "" else toExternalString x)) From e82f71d174886c7106ce9ea3ee32f07fac365bed Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Tue, 6 Aug 2024 15:00:00 -0400 Subject: [PATCH 2/5] Add toExternalString(MutableMatrix) We just use the same method as we use for mutable lists and hash tables. --- M2/Macaulay2/m2/mutablemat.m2 | 1 + 1 file changed, 1 insertion(+) diff --git a/M2/Macaulay2/m2/mutablemat.m2 b/M2/Macaulay2/m2/mutablemat.m2 index ab0f0169c5..29fa740483 100644 --- a/M2/Macaulay2/m2/mutablemat.m2 +++ b/M2/Macaulay2/m2/mutablemat.m2 @@ -16,6 +16,7 @@ precision MutableMatrix := precision @@ ring expression MutableMatrix := m -> MatrixExpression append(applyTable(entries m, expression), symbol MutableMatrix => true) texMath MutableMatrix := m -> texMath expression m net MutableMatrix := m -> net expression m +toExternalString MutableMatrix := lookup(toExternalString, MutableHashTable) map(Ring,RawMutableMatrix) := opts -> (R,m) -> ( new MutableMatrix from { From bde39932347cb27907f9cbb4525e35620c0a5b9a Mon Sep 17 00:00:00 2001 From: Mahrud Sayrafi Date: Wed, 7 Aug 2024 08:43:17 +0200 Subject: [PATCH 3/5] removed unnecessary toExternalString methods --- M2/Macaulay2/m2/enginering.m2 | 7 ++++--- M2/Macaulay2/m2/galois.m2 | 3 --- M2/Macaulay2/m2/polyrings.m2 | 2 -- M2/Macaulay2/m2/quotring.m2 | 1 - M2/Macaulay2/m2/rings.m2 | 7 +++++++ 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/M2/Macaulay2/m2/enginering.m2 b/M2/Macaulay2/m2/enginering.m2 index 9759f629e9..62133d97f2 100644 --- a/M2/Macaulay2/m2/enginering.m2 +++ b/M2/Macaulay2/m2/enginering.m2 @@ -237,10 +237,12 @@ reduce := (r,s) -> ( ); (a,b)) +-- printing expression EngineRing := R -> if hasAttribute(R,ReverseDictionary) then expression getAttribute(R,ReverseDictionary) else expression toString R.RawRing -- should never be used -texMath EngineRing := R -> texMath expression R + toString EngineRing := toString @@ expression -net EngineRing := net @@ expression +net EngineRing := net @@ expression +texMath EngineRing := texMath @@ expression ZZ _ EngineRing := RR _ EngineRing := @@ -279,7 +281,6 @@ coefficientRing FractionField := F -> coefficientRing last F.baseRings dim FractionField := F -> 0 expression FractionField := F -> if hasAttribute(F,ReverseDictionary) then expression getAttribute(F,ReverseDictionary) else (expression frac) (expression last F.baseRings) describe FractionField := F -> Describe (expression frac) (describe last F.baseRings) - toExternalString FractionField := F -> toString describe F -- freduce := (f) -> (numerator f)/(denominator f) diff --git a/M2/Macaulay2/m2/galois.m2 b/M2/Macaulay2/m2/galois.m2 index fab401aef3..b92bf30487 100644 --- a/M2/Macaulay2/m2/galois.m2 +++ b/M2/Macaulay2/m2/galois.m2 @@ -7,9 +7,6 @@ needs "polyrings.m2" GaloisField = new Type of EngineRing GaloisField.synonym = "Galois field" -toExternalString GaloisField := k -> toString describe k -toString GaloisField := toString @@ expression -net GaloisField := net @@ expression expression GaloisField := F -> if hasAttribute(F,ReverseDictionary) then expression getAttribute(F,ReverseDictionary) else (expression GF) (expression F.order) describe GaloisField := F -> Describe (expression GF) (expression F.order) diff --git a/M2/Macaulay2/m2/polyrings.m2 b/M2/Macaulay2/m2/polyrings.m2 index 7123fd9a31..5c2f3a749b 100644 --- a/M2/Macaulay2/m2/polyrings.m2 +++ b/M2/Macaulay2/m2/polyrings.m2 @@ -64,8 +64,6 @@ expression PolynomialRing := R -> ( if hasAttribute(R, ReverseDictionary) then expression getAttribute(R, ReverseDictionary) else(expression last R.baseRings) expressionPolynomialRing R) - -toExternalString PolynomialRing := toString @@ describe -- the rest are inherited from EngineRing ----------------------------------------------------------------------------- diff --git a/M2/Macaulay2/m2/quotring.m2 b/M2/Macaulay2/m2/quotring.m2 index 7619f1b2d3..ec946cd15e 100644 --- a/M2/Macaulay2/m2/quotring.m2 +++ b/M2/Macaulay2/m2/quotring.m2 @@ -55,7 +55,6 @@ expression QuotientRing := S -> ( if hasAttribute(S, ReverseDictionary) then expression getAttribute(S, ReverseDictionary) else new Divide from { unhold expression ambient S, unhold expression printRels S }) -toExternalString QuotientRing := toString @@ describe -- TODO: add AfterPrint for QuotientRing ----------------------------------------------------------------------------- diff --git a/M2/Macaulay2/m2/rings.m2 b/M2/Macaulay2/m2/rings.m2 index 043c1ca2c2..5c79e2d681 100644 --- a/M2/Macaulay2/m2/rings.m2 +++ b/M2/Macaulay2/m2/rings.m2 @@ -79,6 +79,13 @@ isHomogeneous Ring := R -> ( degreeLength R == 0 ) +-- printing +-- technically this should not be allowed, since rings are mutable +-- and therefore "R === value toExternalString R" will always be false, +-- however, this is good enough to serialize a ring for another session. +toExternalString Ring := toString @@ describe +-- the rest of the printing methods will inherit from methods on Type + ----------------------------------------------------------------------------- -- promote, lift, liftable, and isConstant ----------------------------------------------------------------------------- From 3775fb0d2d936b85edc84089c7bde3a601c5c826 Mon Sep 17 00:00:00 2001 From: Mahrud Sayrafi Date: Wed, 7 Aug 2024 08:35:52 +0200 Subject: [PATCH 4/5] fixed expression for LocalRing --- M2/Macaulay2/packages/LocalRings/doc.m2 | 2 +- M2/Macaulay2/packages/LocalRings/localring.m2 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/M2/Macaulay2/packages/LocalRings/doc.m2 b/M2/Macaulay2/packages/LocalRings/doc.m2 index e822837445..e9bd11394c 100644 --- a/M2/Macaulay2/packages/LocalRings/doc.m2 +++ b/M2/Macaulay2/packages/LocalRings/doc.m2 @@ -373,7 +373,7 @@ importFrom_Core { "headline" } scan({ baseRing, char, coefficientRing, degreeLength, degrees, dim, frac, generators, isCommutative, numgens }, m -> document { Key => (m, LocalRing), Headline => headline makeDocumentTag (m, Ring), PARA {"See ", TO (m, Ring)} }) -undocumented apply({describe, expression, precision, presentation, toExternalString}, m -> (m, LocalRing)) +undocumented apply({describe, expression, precision, presentation}, m -> (m, LocalRing)) end-- diff --git a/M2/Macaulay2/packages/LocalRings/localring.m2 b/M2/Macaulay2/packages/LocalRings/localring.m2 index 0a26be1aaa..334df75e5d 100644 --- a/M2/Macaulay2/packages/LocalRings/localring.m2 +++ b/M2/Macaulay2/packages/LocalRings/localring.m2 @@ -22,6 +22,7 @@ --------------------------------------------------------------------------- importFrom_Core { + "unhold", "getAttribute", "hasAttribute", "ReverseDictionary", "indexStrings", "indexSymbols", "generatorExpressions", "generatorSymbols", "commonEngineRingInitializations", "rawFraction", "rawNumerator", "rawDenominator", "rawIsLocalUnit", "rawLocalRing" } @@ -36,8 +37,7 @@ LocalRing#{Standard,AfterPrint} = RP -> ( localRing = method(TypicalValue => LocalRing) describe LocalRing := RP -> Describe (expression localRing) (expression last RP.baseRings, expression RP.maxIdeal) - expression LocalRing := RP -> if hasAttribute(RP, ReverseDictionary) then expression getAttribute(RP, ReverseDictionary) else describe RP -toExternalString LocalRing:= RP -> toString describe RP + expression LocalRing := RP -> if hasAttribute(RP, ReverseDictionary) then expression getAttribute(RP, ReverseDictionary) else new FunctionApplication from unhold describe RP coefficientRing LocalRing := RP -> coefficientRing ring RP.maxIdeal isWellDefined LocalRing := RP -> isPrime RP.maxIdeal isCommutative LocalRing := RP -> isCommutative ring RP.maxIdeal -- FIXME make sure this is correct From 02997ee9dde4cfb13482f52de397a3d5cbf6d092 Mon Sep 17 00:00:00 2001 From: Mahrud Sayrafi Date: Wed, 7 Aug 2024 08:36:17 +0200 Subject: [PATCH 5/5] simplified printing methods for SchurRing --- M2/Macaulay2/packages/SchurRings.m2 | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/M2/Macaulay2/packages/SchurRings.m2 b/M2/Macaulay2/packages/SchurRings.m2 index 7ef4c691dd..1710eccce7 100644 --- a/M2/Macaulay2/packages/SchurRings.m2 +++ b/M2/Macaulay2/packages/SchurRings.m2 @@ -69,21 +69,14 @@ SchurRing.synonym = "Schur ring" ClassFunction = new Type of HashTable ClassFunction.synonym = "Class function" -expression SchurRing := S -> new FunctionApplication from { schurRing, (expression last S.baseRings, S.Symbol, S.numgens ) } -undocumented (expression, SchurRing) - -toExternalString SchurRing := R -> toString expression R -undocumented (toExternalString, SchurRing), +describe SchurRing := S -> Describe (expression schurRing) (expression last S.baseRings, S.Symbol, S.numgens) +undocumented (describe, SchurRing) -toString SchurRing := R -> ( - if hasAttribute(R,ReverseDictionary) then toString getAttribute(R,ReverseDictionary) - else toString expression R) -undocumented (toString, SchurRing) - -net SchurRing := R -> ( - if hasAttribute(R,ReverseDictionary) then toString getAttribute(R,ReverseDictionary) - else net expression R) -undocumented (net, SchurRing) +expression SchurRing := S -> ( + if hasAttribute(S, ReverseDictionary) + then toString getAttribute(S, ReverseDictionary) + else new FunctionApplication from unhold describe S) +undocumented (expression, SchurRing) rawmonom2partition = (m) -> ( reverse splice apply(rawSparseListFormMonomial m, (x,e) -> e:x)