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

rename variables by default to avoid execute() clashes in linked libs #672

Closed
wants to merge 10 commits into from
56 changes: 28 additions & 28 deletions docs/src/alghom.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ julia> L = FiniteField(3, 2, "a")

julia> R, (x, y, z, w) = polynomial_ring(L[1], ["x", "y", "z", "w"];
ordering=:negdegrevlex)
(Singular Polynomial Ring (9,a),(x,y,z,w),(ds(4),C), spoly{n_GF}[x, y, z, w])
(Singular Polynomial Ring (9,@OSCAR@a@1),(@OSCAR@x@1,@OSCAR@y@1,@OSCAR@z@1,@OSCAR@w@1),(ds(4),C), spoly{n_GF}[x, y, z, w])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should update the variable names here. Instead I would perform this kind of renaming in Oscar.jl

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here in the docstring? Or altogether?

Copy link
Author

@mjrodgers mjrodgers Jun 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I at least agree that if I am renaming the variables in Singular.jl, then prepending @OSCAR@ is not the right approach. I went with this because Singular.jl already had a helper function to rename "bad" variable names. I can create one in Oscar.jl, but when to call it becomes an issue. Because this issue is not just with computing primary decomposition from Singular, we could potentially run into these name clashes any time we call the Singular library.

Unrelated, at the moment this renaming is causing a segfault in the tests, during one of the calls to libSingular.algExt_GetMinpoly, trying to figure out what is going on with that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into this more, the renaming is sort of a fundamental part of Singular.jl. The type constructors convert to a "good" list of variable names and write them to the Singular objects that they wrap, while maintaining a vector of the corresponding symbols used for the variable names in Julia. I think it would probably break some things to remove this from Singular.jl, and would require some type piracy to handle all of this from the Oscar.jl side.

I think Hans has helped identify the source of the segfault, but regardless, I would honestly vote for just considering every variable name bad, and replace it by def*<number> where def is the (already implemented) default taken by rename_symbol. The reasons being,

  1. it's infeasible to predict all of the possible identifiers that will create a clash in the Singular library and
  2. from the Julia side, we shouldn't care what Singular is calling these variables internally.

There are only 3 times when we might see these Singular variable names, and it will always be I think an issue that should be fixed:

  1. We have Singular actually printing the output for some reason.
  2. We have a badly defined print routine for an object that is pulling the variable names from the wrapped Singular object instead of from the list of julia symbols the object is using.
  3. We for some reason are creating a julia object directly from a pointer to a Singular object, in this case it reads the variable names from Singular.

Related to 2. above, the Singular.jl polynomial rings have a bad print routine that shows the wrapped variable names (and is in general unintelligeable):

julia> using Singular;
julia> F, (a,) = FunctionField(QQ,["a"]);
julia> K, a = AlgebraicExtensionField(F, a^2 + 1);
julia> R, (x, y, z) = polynomial_ring(K, ["x", "y", "z"])
(Singular Polynomial Ring (0,a_1),(x_1,y_1,z_1),(dp(3),C), spoly{n_algExt}[x, y, z])

julia> R.S
3-element Vector{Symbol}:
 :x
 :y
 :z

This is in my version that renames all variables, though this occured previously whenever a variable was renamed; we see that the original symbols are properly saved, but the print routine gives us... I'm not even sure what. (But this occurs in Singular.jl, Oscar.jl does not have this problem).


julia> S, (a, b, c) = polynomial_ring(L[1], ["a", "b", "c"];
ordering=:degrevlex)
(Singular Polynomial Ring (9,a),(a@1,b,c),(dp(3),C), spoly{n_GF}[a, b, c])
(Singular Polynomial Ring (9,@OSCAR@a@1),(@OSCAR@a@2,@OSCAR@b@1,@OSCAR@c@1),(dp(3),C), spoly{n_GF}[a, b, c])

julia> V = [a, a + b^2, b - c, c + b]
4-element Vector{spoly{n_GF}}:
Expand All @@ -55,9 +55,9 @@ julia> V = [a, a + b^2, b - c, c + b]
julia> f = AlgebraHomomorphism(R, S, V)
Algebra Homomorphism with

Domain: Singular Polynomial Ring (9,a),(x,y,z,w),(ds(4),C)
Domain: Singular Polynomial Ring (9,@OSCAR@a@1),(@OSCAR@x@1,@OSCAR@y@1,@OSCAR@z@1,@OSCAR@w@1),(ds(4),C)

Codomain: Singular Polynomial Ring (9,a),(a@1,b,c),(dp(3),C)
Codomain: Singular Polynomial Ring (9,@OSCAR@a@1),(@OSCAR@a@2,@OSCAR@b@1,@OSCAR@c@1),(dp(3),C)

Defining Equations: spoly{n_GF}[a, b^2 + a, b + a^4*c, b + c]

Expand Down Expand Up @@ -106,11 +106,11 @@ A short command for the composition of $f$ and $g$ is `f*g`, which is the same a
```jldoctest
julia> R, (x, y, z, w) = polynomial_ring(QQ, ["x", "y", "z", "w"];
ordering=:negdegrevlex)
(Singular Polynomial Ring (QQ),(x,y,z,w),(ds(4),C), spoly{n_Q}[x, y, z, w])
(Singular Polynomial Ring (QQ),(@OSCAR@x@1,@OSCAR@y@1,@OSCAR@z@1,@OSCAR@w@1),(ds(4),C), spoly{n_Q}[x, y, z, w])

julia> S, (a, b, c) = polynomial_ring(QQ, ["a", "b", "c"];
ordering=:degrevlex)
(Singular Polynomial Ring (QQ),(a,b,c),(dp(3),C), spoly{n_Q}[a, b, c])
(Singular Polynomial Ring (QQ),(@OSCAR@a@1,@OSCAR@b@1,@OSCAR@c@1),(dp(3),C), spoly{n_Q}[a, b, c])

julia> V = [a, a + b^2, b - c, c + b]
4-element Vector{spoly{n_Q}}:
Expand All @@ -128,65 +128,65 @@ julia> W = [x^2, x + y + z, z*y]
julia> f = AlgebraHomomorphism(R, S, V)
Algebra Homomorphism with

Domain: Singular Polynomial Ring (QQ),(x,y,z,w),(ds(4),C)
Domain: Singular Polynomial Ring (QQ),(@OSCAR@x@1,@OSCAR@y@1,@OSCAR@z@1,@OSCAR@w@1),(ds(4),C)

Codomain: Singular Polynomial Ring (QQ),(a,b,c),(dp(3),C)
Codomain: Singular Polynomial Ring (QQ),(@OSCAR@a@1,@OSCAR@b@1,@OSCAR@c@1),(dp(3),C)

Defining Equations: spoly{n_Q}[a, b^2 + a, b - c, b + c]


julia> g = AlgebraHomomorphism(S, R, W)
Algebra Homomorphism with

Domain: Singular Polynomial Ring (QQ),(a,b,c),(dp(3),C)
Domain: Singular Polynomial Ring (QQ),(@OSCAR@a@1,@OSCAR@b@1,@OSCAR@c@1),(dp(3),C)

Codomain: Singular Polynomial Ring (QQ),(x,y,z,w),(ds(4),C)
Codomain: Singular Polynomial Ring (QQ),(@OSCAR@x@1,@OSCAR@y@1,@OSCAR@z@1,@OSCAR@w@1),(ds(4),C)

Defining Equations: spoly{n_Q}[x^2, x + y + z, y*z]


julia> idR = IdentityAlgebraHomomorphism(R)
Identity Algebra Homomorphism with

Domain: Singular Polynomial Ring (QQ),(x,y,z,w),(ds(4),C)
Domain: Singular Polynomial Ring (QQ),(@OSCAR@x@1,@OSCAR@y@1,@OSCAR@z@1,@OSCAR@w@1),(ds(4),C)

Defining Equations: spoly{n_Q}[x, y, z, w]


julia> h1 = f*g
Algebra Homomorphism with

Domain: Singular Polynomial Ring (QQ),(x,y,z,w),(ds(4),C)
Domain: Singular Polynomial Ring (QQ),(@OSCAR@x@1,@OSCAR@y@1,@OSCAR@z@1,@OSCAR@w@1),(ds(4),C)

Codomain: Singular Polynomial Ring (QQ),(x,y,z,w),(ds(4),C)
Codomain: Singular Polynomial Ring (QQ),(@OSCAR@x@1,@OSCAR@y@1,@OSCAR@z@1,@OSCAR@w@1),(ds(4),C)

Defining Equations: spoly[x^2, 2*x^2 + 2*x*y + y^2 + 2*x*z + 2*y*z + z^2, x + y + z - y*z, x + y + z + y*z]


julia> h2 = idR*f
Algebra Homomorphism with

Domain: Singular Polynomial Ring (QQ),(x,y,z,w),(ds(4),C)
Domain: Singular Polynomial Ring (QQ),(@OSCAR@x@1,@OSCAR@y@1,@OSCAR@z@1,@OSCAR@w@1),(ds(4),C)

Codomain: Singular Polynomial Ring (QQ),(a,b,c),(dp(3),C)
Codomain: Singular Polynomial Ring (QQ),(@OSCAR@a@1,@OSCAR@b@1,@OSCAR@c@1),(dp(3),C)

Defining Equations: spoly{n_Q}[a, b^2 + a, b - c, b + c]


julia> h3 = g*idR
Algebra Homomorphism with

Domain: Singular Polynomial Ring (QQ),(a,b,c),(dp(3),C)
Domain: Singular Polynomial Ring (QQ),(@OSCAR@a@1,@OSCAR@b@1,@OSCAR@c@1),(dp(3),C)

Codomain: Singular Polynomial Ring (QQ),(x,y,z,w),(ds(4),C)
Codomain: Singular Polynomial Ring (QQ),(@OSCAR@x@1,@OSCAR@y@1,@OSCAR@z@1,@OSCAR@w@1),(ds(4),C)

Defining Equations: spoly{n_Q}[x^2, x + y + z, y*z]


julia> h4 = idR*idR
Identity Algebra Homomorphism with

Domain: Singular Polynomial Ring (QQ),(x,y,z,w),(ds(4),C)
Domain: Singular Polynomial Ring (QQ),(@OSCAR@x@1,@OSCAR@y@1,@OSCAR@z@1,@OSCAR@w@1),(ds(4),C)

Defining Equations: spoly{n_Q}[x, y, z, w]
```
Expand Down Expand Up @@ -214,43 +214,43 @@ kernel(f::SAlgHom)
```jldoctest
julia> R, (x, y, z, w) = polynomial_ring(QQ, ["x", "y", "z", "w"];
ordering=:negdegrevlex)
(Singular Polynomial Ring (QQ),(x,y,z,w),(ds(4),C), spoly{n_Q}[x, y, z, w])
(Singular Polynomial Ring (QQ),(@OSCAR@x@1,@OSCAR@y@1,@OSCAR@z@1,@OSCAR@w@1),(ds(4),C), spoly{n_Q}[x, y, z, w])

julia> S, (a, b, c) = polynomial_ring(QQ, ["a", "b", "c"];
ordering=:degrevlex)
(Singular Polynomial Ring (QQ),(a,b,c),(dp(3),C), spoly{n_Q}[a, b, c])
(Singular Polynomial Ring (QQ),(@OSCAR@a@1,@OSCAR@b@1,@OSCAR@c@1),(dp(3),C), spoly{n_Q}[a, b, c])

julia> I = Ideal(S, [a, a + b^2, b - c, c + b])
Singular ideal over Singular Polynomial Ring (QQ),(a,b,c),(dp(3),C) with generators (a, b^2 + a, b - c, b + c)
Singular ideal over Singular Polynomial Ring (QQ),(@OSCAR@a@1,@OSCAR@b@1,@OSCAR@c@1),(dp(3),C) with generators (a, b^2 + a, b - c, b + c)

julia> f = AlgebraHomomorphism(R, S, gens(I))
Algebra Homomorphism with

Domain: Singular Polynomial Ring (QQ),(x,y,z,w),(ds(4),C)
Domain: Singular Polynomial Ring (QQ),(@OSCAR@x@1,@OSCAR@y@1,@OSCAR@z@1,@OSCAR@w@1),(ds(4),C)

Codomain: Singular Polynomial Ring (QQ),(a,b,c),(dp(3),C)
Codomain: Singular Polynomial Ring (QQ),(@OSCAR@a@1,@OSCAR@b@1,@OSCAR@c@1),(dp(3),C)

Defining Equations: spoly{n_Q}[a, b^2 + a, b - c, b + c]


julia> idS = IdentityAlgebraHomomorphism(S)
Identity Algebra Homomorphism with

Domain: Singular Polynomial Ring (QQ),(a,b,c),(dp(3),C)
Domain: Singular Polynomial Ring (QQ),(@OSCAR@a@1,@OSCAR@b@1,@OSCAR@c@1),(dp(3),C)

Defining Equations: spoly{n_Q}[a, b, c]


julia> P1 = preimage(f, I)
Singular ideal over Singular Polynomial Ring (QQ),(x,y,z,w),(ds(4),C) with generators (x, y, z, w)
Singular ideal over Singular Polynomial Ring (QQ),(@OSCAR@x@1,@OSCAR@y@1,@OSCAR@z@1,@OSCAR@w@1),(ds(4),C) with generators (x, y, z, w)

julia> P2 = preimage(idS, I)
Singular ideal over Singular Polynomial Ring (QQ),(a,b,c),(dp(3),C) with generators (a, b^2 + a, b - c, b + c)
Singular ideal over Singular Polynomial Ring (QQ),(@OSCAR@a@1,@OSCAR@b@1,@OSCAR@c@1),(dp(3),C) with generators (a, b^2 + a, b - c, b + c)

julia> K1 = kernel(f)
Singular ideal over Singular Polynomial Ring (QQ),(x,y,z,w),(ds(4),C) with generators (4*x - 4*y + z^2 + 2*z*w + w^2)
Singular ideal over Singular Polynomial Ring (QQ),(@OSCAR@x@1,@OSCAR@y@1,@OSCAR@z@1,@OSCAR@w@1),(ds(4),C) with generators (4*x - 4*y + z^2 + 2*z*w + w^2)

julia> K2 = kernel(idS)
Singular ideal over Singular Polynomial Ring (QQ),(a,b,c),(dp(3),C) with generators (0)
Singular ideal over Singular Polynomial Ring (QQ),(@OSCAR@a@1,@OSCAR@b@1,@OSCAR@c@1),(dp(3),C) with generators (0)
```

6 changes: 3 additions & 3 deletions docs/src/caller.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ julia> Singular.LibNctools.isCentral(x) # base ring A is inferred from x
0

julia> Singular.LibCentral.center(A, 3) # base ring cannot be inferred from the plain Int 3
Singular ideal over Singular G-Algebra (QQ),(x,y,z,t),(dp(4),C) with generators (t, 4*x*y + z^2 - 2*z)
Singular ideal over Singular G-Algebra (QQ),(@OSCAR@x@1,@OSCAR@y@1,@OSCAR@z@1,@OSCAR@t@1),(dp(4),C) with generators (t, 4*x*y + z^2 - 2*z)
```

## Global Interpreter Variables
Expand Down Expand Up @@ -147,10 +147,10 @@ julia> gens(with_degBound(5) do; return std(i); end)
z^6 + x^7 + y^7

julia> R, (x, y) = polynomial_ring(QQ, ["x", "y"])
(Singular Polynomial Ring (QQ),(x,y),(dp(2),C), spoly{n_Q}[x, y])
(Singular Polynomial Ring (QQ),(@OSCAR@x@1,@OSCAR@y@1),(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
[4294967295: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)
Singular ideal over Singular Polynomial Ring (QQ),(@OSCAR@x@1,@OSCAR@y@1),(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)
```
Loading