MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: sparsearray bug?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101633] Re: [mg101477] sparsearray bug?
  • From: W.P.Bergsma at lse.ac.uk
  • Date: Sun, 12 Jul 2009 05:48:46 -0400 (EDT)
  • References: <200907081111.HAA12330@smc.vnet.net> <34c814850907080635r67ea3bd1x650995f410324b1b@mail.gmail.com>

Thanks,thisindeedseemstoexplainit.AworkaroundI=
foundis:

Withxandyvectors,use

SparseArray[x]*SparseArray[1/y]

insteadof

SparseArray[x]/SparseArray[y]

Regards,Wicher


-----OriginalMessage-----
From:LeonidShifrin[mailto:lshifr at gmail.com]
Sent:Wed8-7-200914:35
To:Bergsma,WP;mathgroup at smc.vnet.net
Subject:Re:[mg101477]sparsearraybug?

Hi,

Thisseemsindeedtobeabug.HereiswhatIthink=
isthereason.

In[1]=SparseArray[{1}]//FullForm


Out[1]=SparseArray[Automatic,List[1],0,List[1,List[List[0,1],List[=
List[1]]],List[1]]]

Lookatthethirdelement(zero).Thisisadefaultel=
ement,whichisfilledforanypositionmissedinexplic=
itrules(whenSparseArrayisdefinedfrom
asetofrulesposition->value).

Now,inthatlattercase(whenatleastonedefaultel=
ementispresent),
itmakessensetoapplywhateverListableoperationisa=
ppliedtoanentirearray(Power[x,-1]inthiscase)als=
otothedefaultelement-butthisshould
notbedoneincaseswhenallelementsareindicatede=
xplicitly(andsothedefaultelementsubstitutiondoes=
notactuallytakeplace).Letuschangeadefaultelemen=
tto1intheFullForm:


In[2]=SparseArray[Automatic,List[1],1,List[1,List[List[0,1],List[L=
ist[1]]],List[1]]]

Out[2]=SparseArray[<1>,{1},1]

Inthiscase,noerrormessage:

In[3]=1/SparseArray[Automatic,List[1],1,List[1,List[List[0,1],List=
[List[1]]],List[1]]]

Out[3]=SparseArray[<1>,{1},1]

In[4]=Normal[%]

Out[4]={1}

Now,wecanconvinceourselvesthatthebugisindeed=
relatedtoapplying
aninverse(inthiscase,butthismaybeamoregen=
eralproblem)tothedefaultelement:

In[5]:=Normal[1/SparseArray[{1->1,2->2,4->5}]]

DuringevaluationofIn[5]:=Power::infy:Infiniteexpressio=
n1/0encountered.>>

Out[5]={1,1/2,ComplexInfinity,1/5}

Herethebehaviorwascorrect,sincethedefaultispres=
ent.However,Iwouldbetthattheactualplacewhere=
thismessagewasgeneratedisn'tcorrect-Iamalmost=
certainthatitwasgeneratedbeforedefaultelementsubst=
itutionactuallytookplace(butthisonlyWRIcouldcon=
firm).Now:

In[6]:=Normal[1/SparseArray[{1->1,2->2,3->4,4->5}]]

DuringevaluationofIn[6]:=Power::infy:Infiniteexpressio=
n1/0encountered.>>

Out[6]={1,1/2,1/4,1/5}

Hereitwasincorrect(intermsoferrormessagegenerat=
ionatleast),sincethedefaultwasn'teverused.

Nowwechangethedefaultto1:

In[7]:=Normal[1/SparseArray[{1->1,2->2,3->4,4->5,{_}->1}]]

Out[7]={1,1/2,1/4,1/5}

andgetnoerrormessage.Herealsothedefaultwasn't=
actuallyused.
Thisseemstosupportmyconjecture.


Hopethishelps.

Regards,
Leonid




OnWed,Jul8,2009at4:11AM,wpb<w.p.bergsma at lse.ac.=
uk>wrote:


=09In[494]:=SparseArray[{1}]/SparseArray[{1}]
=09
=09DuringevaluationofIn[494]:=Power::infy:Infiniteexpr=
ession1/0encountered.>>
=09DuringevaluationofIn[494]:=\[Infinity]::indet:Indeterm=
inateexpression0ComplexInfinityencountered.>>
=09
=09Out[494]=SparseArray[<1>,{1},Indeterminate]
=09
=09




Pleaseaccesstheattachedhyperlinkforanimportantelec=
troniccommunicationsdisclaimer:http://www.lse.ac.uk/collections/s=
ecretariat/legal/disclaimer.htm


  • Prev by Date: four parametric projection ifs types
  • Next by Date: ColorFunction and question about how to use it
  • Previous by thread: Re: sparsearray bug?
  • Next by thread: Re: sparsearray bug?