-- Some possibly good test examples for integralClosure of ideals.
-- MES: Also: some bugs/unpleasant-isms DE found while playing with this

end
restart
load "integralClosureIdeal.m2"

kk=ZZ/101
S=kk[a,b]
integralClosure(ideal(a^3,b^7),2)
i=ideal"a4,a3b,ab3,b4"
integralClosure i
integralClosure (i^2) == i^2 -- i^2 is already integrally closed
  -- this line above doesn't seem to finish in small time

-- the timings here refer to some older version of integral closure.
S=kk[a,b,c]
integralClosure ideal(a^2,b^3,c^3) -- OLD: 4th rad takes 45 sec. Then done.
time integralClosure ideal(a^3,b^3,c^3) 
-- OLD 4th rad takes 70 sec, 5th rad much longer.
-- NEW 4th rad takes 1 sec, 5th rad 23 sec
time integralClosure(ideal(a^3,b^4,c^5),1) 
-- OLD: third (?) rad comp 60 sec. 4th much longer.
-- NEW: fourth rad comp 1 sec. 5th takes 439 sec. 

---------------
--Huneke's question (related to "evolutions"):
--If f has isolated singularity, is
--f \in mm*integralClosureIdeal(J(f)) 
--where mm is the maximal ideal and J(f) is the
--ideal generated by the partial derivatives of f?
--This is known to be true in 2 variables, and
--it's also known if f is quasi-homogeneous.
--Further, it's known that 
--f \in integralClosureIdeal(mm*J(f)) 

restart
kk=ZZ/32003
S=kk[a,b,c]
mm=ideal vars S
--S=QQ[x,y]
f=ideal(matrix{{a^3}}+random(S^1, S^{-4})) -- smallest non-qhom ex we could find in 3 vars.
toString f
ideal(-2136*a^4+9349*a^3*b-5609*a^2*b^2-15802*a*b^3-11250*b^4+8735*a^3*c-9489*a^2*b*c-371*a*b^2*c-14212*b
     ^3*c+13529*a^2*c^2-545*a*b*c^2-1270*b^2*c^2-2519*a*c^3-1415*b*c^3+626*c^4+a^3)

f= ideal (y^4-2*x^3*y^2-4*x^5*y+x^6-x^7)
f = trim ideal( random(S^1, S^{-3})+random(S^1, S^{-5}))

f = ideal (a^2+a^3+b^2+c^2) -- this is an example
f = ideal (a^2+a^3+b^2+a*b*c+c^2) -- this is an example

J = ideal jacobian f
substitute(J:f, kk) -- check local quasi-homogeneity!


ReesJ=(flattenRing reesAlgebra(J))_0
P=ideal oo
betti res P
Q=trim(P+ minors (2,jacobian P))
codim Q
betti Q


Q1=trim(P+ideal randomMinors(1,2,jacobian P))
betti Q1
time decompose Q1
--radical Q1

vasconcelos (ideal(a,b,c),a)
R1=ringFromFractions(oo, Variable=>z)
R1ring = target (R1_0)
P1=trim ideal R1ring

codim P1
Q2=trim(P1+ideal randomMinors(1,3,jacobian P1))
codim Q2
betti Q1

time decompose Q2
--radical Q1

vasconcelos (ideal(a,b,c),a)
R1=ringFromFractions(oo, Variable=>z)
R1ring = target (R1_0)
P1=trim ideal R1ring



JJ = J -- in the integral closed case
--gens f%J -- f is not in J, so not quasi-homogeneous THIS IS WRONG -- NEED TO LOOK AT IT LOCALLY
JJ=integralClosureOfIdeal J

Slocal = (coefficientRing S){gens S}
fl=substitute(f,Slocal)
JJl=substitute(JJ,Slocal)
mml=substitute(mm,Slocal)
Jl=substitute(J,Slocal)
(gens fl) % (mml*JJl)
(gens fl) % JJl

J:f;


--integralClosureOfIdeal(mm*J)--can't compute this -- just finding the minors the first time is 
--very slow (9 variables, codim 5, the 5 x 5's of a 9 x ?? matrix...)
betti res (mm*J)

R4 = kk[a..d]
F = ((super basis(5,ideal(a,b,c))) * random(R4^55, R4^1))_(0,0)
R = kk[a,b,c]
f = sub(F,{d=>1})
f = sub(f,R)
f = ideal f
-------------
restart

--Some bugs:

viewHelp random  -- documentation for "random" is peculiar

--truncate(3,Rbar^1)
--viewHelp truncate
--DOCUMENTATION OF "TRUNCATE" CLAIMS THERE'S A BUG

--BASIS problems:

restart
kk=ZZ/101
S=kk[a,b]
R=kk[c,d]
f=map(R,S,{c,d^2})
P=R^1/(ideal vars R)^3
--M=map(P,S^1,{{1_R}}) -- gives error
--M.RingMap=f
B=basis(P)

B=basis(P,SourceRing => S)
keys B -- "RingMap" is a key
B.RingMap => f --returns f, does NOT set the key
B.RingMap -- thinks the map of rings is 0.
kernel B

matrix"c,d3"
keys oo

source B
coimage B

--N=coker matrix{{a*b}}
--map(P,N,{{1_R}}) -- gives error
