Skip to content

Commit

Permalink
Merge pull request oscar-system#527 from tthsqe12/global_variables
Browse files Browse the repository at this point in the history
interface to degBound and multBound
  • Loading branch information
tthsqe12 authored Jan 31, 2022
2 parents 5a2367c + 85923ed commit 6d41657
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 2 deletions.
73 changes: 72 additions & 1 deletion docs/src/caller.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
CurrentModule = Singular
```

# Library Procedures
# Interpreter Functionality

Singular.jl provides limited access to the functionality of the Singular
interpreter and its associated standard library procedures. The following
Expand Down Expand Up @@ -70,3 +70,74 @@ julia> Singular.LibCentral.center(A, 3) # base ring cannot be infered from the
Singular ideal over Singular G-Algebra (QQ),(x,y,z,t),(dp(4),C) with generators (t, 4*x*y + z^2 - 2*z)
```

## Global variables

The global variables `degBound` and `multBound` can be used in a local fashion.
As with any global variable, their usage should be accompanied with caution.

```@docs
with_degBound(f, degb::Integer)
```

```@docs
with_multBound(f, degb::Integer)
```

The following [options](https://www.singular.uni-kl.de/Manual/4-3-0/sing_318.htm#SEC358)
are available. The usage of, say, the option `infRefTail`
would be as `with_infRefTail(f, flag::Bool)` where the same do-block syntax
can be used as with the degree bounds.

```
fastHC, infRedTail, lazy, length, notBuckets, prot, qringNF, redTail, redThrough
```

**Examples**

```julia
julia> r, (x,y,z) = PolynomialRing(QQ, ["x", "y", "z"], ordering=ordering_ds());

julia> i = Ideal(r, [x^7+y^7+z^6,x^6+y^8+z^7,x^7+y^5+z^8,x^2*y^3+y^2*z^3+x^3*z^2,x^3*y^2+y^3*z^2+x^2*z^3]);

julia> degree(std(i)) # default behaviour of no multiplicity bound
(0, 86)

julia> with_multBound(100) do
# run with a multiplicity bound of 100
return degree(std(i))
end
(0, 98)

julia> degree(std(i)) # back to default behaviour
(0, 86)

julia> gens(std(i))
11-element Vector{spoly{n_Q}}:
x^3*y^2 + y^3*z^2 + x^2*z^3
x^2*y^3 + x^3*z^2 + y^2*z^3
y^5 + x^7 + z^8
x^6 + z^7 + y^8
x^4*z^2 - y^4*z^2 - x^2*y*z^3 + x*y^2*z^3
z^6 + x^7 + y^7
y^4*z^3 - y^3*z^4 - x^2*z^5 - x^9
x^3*y*z^4 - x^2*y^2*z^4 + x*y^3*z^4 - y^4*z^4 + x^3*z^5 - x^2*y*z^5
x^3*z^5
x^2*y*z^5 + y^3*z^5 + x^2*z^6
x*y^3*z^5

julia> gens(with_degBound(5) do; return std(i); end)
5-element Vector{spoly{n_Q}}:
x^3*y^2 + y^3*z^2 + x^2*z^3
x^2*y^3 + x^3*z^2 + y^2*z^3
y^5 + x^7 + z^8
x^6 + z^7 + y^8
z^6 + x^7 + y^7

julia> R, (x, y) = PolynomialRing(QQ, ["x", "y"])
(Singular Polynomial Ring (QQ),(x,y),(dp(2),C), spoly{n_Q}[x, y])

julia> with_prot(true) do; return std(Ideal(R, x^5 - y*x + 1, y^6*x + x^2 + y^3)); end
[65535:2]5s7s11s1214-s15
product criterion:1 chain criterion:1
Singular ideal over Singular Polynomial Ring (QQ),(x,y),(dp(2),C) with generators (x^5 - x*y + 1, x*y^6 + y^3 + x^2, x^4*y^3 - y^6 - y^4 - x, y^9 + y^7 + x^3*y^3 + x*y^3 + x*y - 1)
```
2 changes: 1 addition & 1 deletion docs/src/noncommutative.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ julia> y*x
2*x*y + x
```

Associativity can be checked via [Library Proceedures](@ref).
Associativity can be checked via [Interpreter Functionality](@ref).

```
julia> iszero(Singular.LibNctools.ndcond(G))
Expand Down
71 changes: 71 additions & 0 deletions src/MessyHacks.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,74 @@
#=
messy hack #0: (not really that messy)
provide wrappers for working with Singular's global variables
=#

export with_degBound, with_multBound

@doc Markdown.doc"""
with_degBound(f, degb::Integer)
Evaluate and return `f()` with the Singular global setting `degBound = degb`. The
value of `degBound` is automatically restored upon return; the effect is only a
local one on `f()`. The value `degBound = 0` corresponds to no degree bound in
Singular and this is the starting value.
"""
function with_degBound(f, degb::Integer)
old_degb = libSingular.set_degBound(Cint(degb))
local g = nothing
try
g = f()
finally
libSingular.set_degBound(old_degb)
end
return g
end

@doc Markdown.doc"""
with_multBound(f, mu::Integer)
Evaluate and return `f()` with the Singular global setting `multBound = mu`. The
value of `multBound` is automatically restored upon return; the effect is only a
local one on `f()`. The value `multBound = 0` corresponds to no multiplicity
bound in Singular and this is the starting value.
"""
function with_multBound(f, mu::Integer)
old_mu = libSingular.set_multBound(Cint(mu))
local g = nothing
try
g = f()
finally
libSingular.set_multBound(old_mu)
end
return g
end

for (name, str) in [(:with_fastHC, "OPT_FASTHC")
(:with_infRedTail, "OPT_INFREDTAIL")
(:with_lazy, "OPT_OLDSTD")
(:with_length, "V_LENGTH")
(:with_notBuckets, "OPT_NOT_BUCKETS")
(:with_prot, "OPT_PROT")
(:with_qringNF, "V_QRING")
(:with_redTail, "OPT_REDTAIL")
(:with_redThrough, "OPT_REDTHROUGH")]
@eval begin
function ($name)(f, flag::Bool)
old_flag = libSingular.set_option($str, flag)
local g = nothing
try
g = f()
finally
libSingular.set_option($str, old_flag)
end
return g
end

export $name
end
end

#=
messy hack #1:
Expand Down
11 changes: 11 additions & 0 deletions src/Singular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ function __init__()
# silence printlevel-based printing
libSingular.set_printlevel(-100)

# At this point we have Kstd1_mu = 2^31-1 and OPT_MULTBOUND unset, which is
# a slightly inconsistent state. The singular intepreter variable "multBound"
# simply reads Kstd1_mu and assigning to "multBound" assigns to Kstd1_mu
# and sets OPT_MULTBOUND if it is nonzero, and unsets OPT_MULTBOUND if it is
# zero. Since we want to be able to easily restore the multBound to a
# consistent state, we set Kstd1_mu to zero here, which also leaves
# OPT_MULTBOUND unset.
Singular.libSingular.set_multBound(0)
# ditto
Singular.libSingular.set_degBound(0)

# set up Singular parents (we cannot do this before Singular is initialised)

global ZZ = Integers()
Expand Down

0 comments on commit 6d41657

Please sign in to comment.