A65 ==== Subject: Re: Periodic function Roots This is also a good example for using Ted Ersek's RootSearch package on MathSource. I believe he has just updated it, or is about to update it. The advantage is that it will find all the roots in a domain with a single command. Needs[Ersek`RootSearch`] f[x_] := Cos[x] + .5 Cos[2x] + .25 Cos[3x] + 2.5 Cos[4x] RootSearch[f[x] == 0, {x, 0, 2[Pi]}] {{x -> 0.51129}, {x -> 1.20136}, {x -> 1.91222}, {x -> 2.81887}, {x -> 3.46432}, {x -> 4.37096}, {x -> 5.08183}, {x -> 5.7719}} David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ (Style ACos(x)+BCos(2x)+...==K). Mathematica can't let me us 'Solve' function, so it gives me the error: Solve::tdep: The equations appear to involve the variables to be solved for in an essentially non-algebraic way. To arrange this, i'm making a little program involving FindRoot function to find at least two roots from the ecuation in the first period. But I would like to know if there are some other method to do this more easily. F. Bellas ==== Subject: Controlling inverses of functions I've got some functions (Tensor's actually) which aren't trivially inverted and I want to either control their inverse form, or prevent mathematica from inverting them altogether, so that I can use Solve in safety on expressions containing them. Is there anyway of doing that? For example: In: F[a] == F[b] F[c] In: Solve[%, F[b]] Out: {F[b] -> F[a] / F[c]} This is incorrect because 1 / F[c] is an invalid statement (as the inverse isn't defined). The correct answer is that an answer can't be derived. Any help on this would be wonderful. Joe -- Josef Karthauser (joe@tao.org.uk) http://www.josef-k.net/ FreeBSD (cvs meister, admin and hacker) http://www.uk.FreeBSD.org/ ==== Subject: Re: Integrate and Boole problems > I'm using Mathematica 5.1 and I'm getting some inconsistent results > when integrating the Boole function. For example: Integrate[Boole[((x - 1)^2 + y^2 + z^2 - 3^2)*((x + 1)^2 + y^2 + z^2 - > 3^2) = 0], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}, {z, > -Infinity, Infinity}]; > N[%] 50.2654821239234 + 3.829918318813164*^-9*I > NIntegrate[Boole[((x - 1)^2 + y^2 + z^2 - 3^2)*((x + 1)^2 + y^2 + z^2 > -3^2) = 0], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}, {z, > -Infinity, Infinity}] 108.90854533339399 - 2.749275252793041*^-29*I Am I doing something wrong or is this just a limit of the Integrate > function? > Hi Chris, I am confused by -- or just do not understand -- what you attempt to do since the *Boole* function only returns 0 or 1 depending whether the expression given to *Boole* is true. Furthermore, your expression does not work at all as entered: you must use a double = (==) to test equality (a single = is the assignment operator). In[1]:= Integrate[Boole[((x - 1)^2 + y^2 + z^2 - 3^2)* ((x + 1)^2 + y^2 + z^2 - 3^2) = 0], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}, {z, -Infinity, Infinity}] !(Set::write ((:)( )) Tag Times in !((((-9) + (((-1) + x))^2 + y^2 + z^2)) (((-9) + ((1 + x))^2 + y^2 + z^2))) is Protected.) Integrate::idiv: Integral of Boole[0] does not converge on {-.89Ì.9b, .89Ì.9b}. Out[1]= Integrate[Boole[0], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}, {z, -Infinity, Infinity}] In[2]:= Integrate[Boole[((x - 1)^2 + y^2 + z^2 - 3^2)* ((x + 1)^2 + y^2 + z^2 - 3^2) == 0], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}, {z, -Infinity, Infinity}] Out[2]= 0 In[3]:= NIntegrate[Boole[((x - 1)^2 + y^2 + z^2 - 3^2)* ((x + 1)^2 + y^2 + z^2 - 3^2) == 0], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}, {z, -Infinity, Infinity}] Out[3]= 0 (Tested on a Pentium IV 2.6GHz 512Mo Physical Ram, Windows XP SP2, Mathematica 5.1.) /J.M. P.S. You should use the _InputForm_ when copying an expression from a Mathematica notebook to your email client: in Mathematica, select the cell(s) you want to include in your email, then within the *Cell* menu select either *Convert To* or *Display As* and choose *InputForm*. Finally, copy and paste as usual into your email. ==== Subject: Re: Periodic function Roots > An example of what i do in such a case: In[1]:=f[x_]:=Cos[x]+.5 Cos[2x]+.25 Cos[3x]+2.5 Cos[4x] In[2]:=t=Table[FindRoot[f[x] == 0,{x,u}],{u,0.1,2Pi,0.1}]; In[3]:=Union[t,SameTest -> (Abs[(x/.#2)-(x/.#1)]<10^-5&)] Out[3]= > {{x -> -0.51129},{x -> 0.51129},{x -> 1.20136}, > {x -> 1.91222},{x -> 2.81887},{x -> 3.46432}, > {x -> 4.37096},{x -> 5.08183},{x -> 5.7719}} > v.a. > Drawing on the work of Valeri, here is another approach using *Reduce* and several other command depending of you intend to do with the solutions retuned by *Reduce*. In[1]:= f[x_] := Cos[x] + (1/2)*Cos[2*x] + (1/4)*Cos[3*x] + (5/5)*Cos[4*x] In[2]:= Reduce[f[x] == 0, x] Out[2]= C[1] .89ÌÌ Integers && (x == -2*ArcTan[Sqrt[Root[11 - 126*#1 + 260*#1^2 - 114*#1^3 + #1^4 & , 1]]] + 2*Pi*C[1] || x == 2*ArcTan[Sqrt[Root[11 - 126*#1 + 260*#1^2 - 114*#1^3 + #1^4 & , 1]]] + 2*Pi*C[1] || x == -2*ArcTan[Sqrt[Root[11 - 126*#1 + 260*#1^2 - 114*#1^3 + #1^4 & , 2]]] + 2*Pi*C[1] || x == 2*ArcTan[Sqrt[Root[11 - 126*#1 + 260*#1^2 - 114*#1^3 + #1^4 & , 2]]] + 2*Pi*C[1] || x == -2*ArcTan[Sqrt[Root[11 - 126*#1 + 260*#1^2 - 114*#1^3 + #1^4 & , 3]]] + 2*Pi*C[1] || x == 2*ArcTan[Sqrt[Root[11 - 126*#1 + 260*#1^2 - 114*#1^3 + #1^4 & , 3]]] + 2*Pi*C[1] || x == -2*ArcTan[Sqrt[Root[11 - 126*#1 + 260*#1^2 - 114*#1^3 + #1^4 & , 4]]] + 2*Pi*C[1] || x == 2*ArcTan[Sqrt[Root[11 - 126*#1 + 260*#1^2 - 114*#1^3 + #1^4 & , 4]]] + 2*Pi*C[1]) In[3]:= sols = N[%] Out[3]= C[1] .89ÌÌ Integers && (x == -0.6455013610404079 + 6.283185307179586* C[1] || x == 0.6455013610404079 + 6.283185307179586*C[1] || x == -1.2524776552773014 + 6.283185307179586* C[1] || x == 1.2524776552773014 + 6.283185307179586*C[1] || x == -1.828145008678062 + 6.283185307179586*C[1] || x == 1.828145008678062 + 6.283185307179586*C[1] || x == -2.9529034404768435 + 6.283185307179586* C[1] || x == 2.9529034404768435 + 6.283185307179586*C[1]) In[4]:= sols /. C[1] -> 0 Out[4]= x == -0.6455013610404079 || x == 0.6455013610404079 || x == -1.2524776552773014 || x == 1.2524776552773014 || x == -1.828145008678062 || x == 1.828145008678062 || x == -2.9529034404768435 || x == 2.9529034404768435 In[5]:= ToRules[%] Out[5]= Sequence[{x -> -0.6455013610404079}, {x -> 0.6455013610404079}, {x -> -1.2524776552773014}, {x -> 1.2524776552773014}, {x -> -1.828145008678062}, {x -> 1.828145008678062}, {x -> -2.9529034404768435}, {x -> 2.9529034404768435}] /J.M. ==== Subject: Re: Periodic function Roots do I understand your question right? You want to get expansion coefficients A,B,.. in a cosine expansion of the periodic function K. Toward this aim, there is: Calculus`FourierTransform`FourierCosCoefficient here is an example: Let K= Mod[t^2,2 Pi] then we get the n-th expansion coefficient by: FourierCosCoefficient[Mod[t^2, 2Pi], t, n] the first few are: {1/12, -Pi^(-2), 1/(4*Pi^2), -1/(9*Pi^2)} sincerely, Daniel > (Style ACos(x)+BCos(2x)+...==K). Mathematica can't let me us 'Solve' > function, so it gives me the error: > Solve::tdep: The equations appear to involve the variables to be solved for in an essentially non-algebraic way. To arrange this, i'm making a little program involving FindRoot function to > find at least two roots from the ecuation in the first period. But I would > like to know if there are some other method to do this more easily. > F. Bellas ==== Subject: Explicit solution to Root[] Here is the code: !((Root[(-2) #1^3 + 2 #1^4 - #1 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1] - 6 #1^2 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1] + 6 #1^3 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1] - 5 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1]^2 - 6 #1 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1]^2 + 6 #1^2 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1]^2 - 2 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1] ^3 + 2 #1 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1]^3 &, 2];)) I would guess it is a number. I applied RootReduce, ToRadicals, N or combinations of thereof, however, nothing seem to convert the above expression into an explicit number. What command or sequence of Mukhtar Bekkali ==== Subject: Re: Exporting mathematica equations into MathType i found latex2word and it seems to work better than latex2rft ==== Subject: Can't assign value to symbols Situation: I have a table that contains parameters and sets of values that I want to assign to the parameters for the purposes of running a simulation. - parameters = {{a,b,c},{1,2,3},{4,5,6},{7,8,9}} - want to assign values in a given row to the symbols listed in the first row. - tried using: MapThread[ #1 = #2 &, {parameters[[1]], parameters[[3]]} ] - fails with error Tag Slot in #1 is Protected - tried adding Unprotect[#1] and a variety of other attemps, but can't get it to work. Anyone know how might accomplish this? Lee ==== Subject: Re: poly question >> I have a polynom called ftlmat >> (Dialog) In[187]:= >> ftlmat >> (Dialog) Out[187]= >> 2*a^2*b^2*c + 2*a*b^2*c*d - >> 2*b^2*c^2*d + b^2*c^2*d^2 + >> 4*a^2*b*c*e - 2*a^2*c^2*e + >> 2*a*b*c^2*e + 4*a*b*c*d*e - >> 4*a*c^2*d*e - 2*b*c^2*d*e - >> 2*c^2*d^2*e + 2*b*c^2*d^2* >> e + 2*a^2*c*e^2 + >> 2*a*c^2*e^2 + 2*a*c*d*e^2 + >> c^2*d^2*e^2 + 2*a^2*b*c*f - >> 2*a*b^2*d*f + 4*a*b*c*d*f - >> 4*b^2*c*d*f - 2*b^2*d^2*f + >> 2*b*c*d^2*f + 2*b^2*c*d^2* >> f - 2*a^2*c*e*f + >> 4*a*b*c*e*f - 4*a*b*d*e*f - >> 4*a*c*d*e*f - 4*b*c*d*e*f - >> 4*b*d^2*e*f - 2*c*d^2*e*f + >> 4*b*c*d^2*e*f + 4*a*c*e^2* >> f - 2*a*d*e^2*f - >> 2*d^2*e^2*f + 2*c*d^2*e^2* >> f + 2*a^2*b*f^2 + >> 4*a*b*d*f^2 - 2*b^2*d*f^2 + >> 2*b*d^2*f^2 + b^2*d^2*f^2 + >> 2*a*b*e*f^2 - 2*b*d*e*f^2 + >> 2*b*d^2*e*f^2 + >> 2*a*e^2*f^2 + d^2*e^2*f^2 >> If I do a PolynomialReduce of it the following way, I get: >> In[170]:= >> PolynomialReduce[ftlmat, >> {a*b*c, a*b*f, a*c*e, >> a*e*f, b*c*d, b*d*f, >> c*d*e, d*e*f}, {a, b, c, >> d, e, f}] >> Out[170]= >> {{2*a*b + 2*b*d + 4*a*e + >> 2*c*e + 4*d*e + 2*a*f + >> 4*d*f + 4*e*f, >> -2*b*d - 4*d*e + 2*a*f + >> 4*d*f + 2*e*f, >> -2*a*c - 4*c*d + 2*a*e + >> 2*c*e + 2*d*e - 2*a*f - >> 4*d*f + 4*e*f, >> -2*d*e + 2*e*f, >> -2*b*c + b*c*d - 2*c*e + >> 2*c*d*e - 4*b*f + 2*d*f + >> 2*b*d*f - 4*e*f + >> 4*d*e*f, -2*b*d - 4*d*e - >> 2*b*f + 2*d*f + b*d*f - >> 2*e*f + 2*d*e*f, >> -2*c*d + c*d*e - 2*d*f + >> 2*d*e*f, -2*d*e + d*e*f}, >> 0} >> The result show that the first poly I got - related to a*b*c - has >> all 6 variables, the next has 5 and the rest goes like 5,3,5,4,4,3. >> If I total them it is 35. My question is what series of polynomials >> should I use in PolymonialReduce to get results which contain the >> least amount of variables each - that is the total of the number of >> variables in each resulting polynom should be minimal, and on the >> same time the number of selected polynoms should be also minimal and >> their construction is simple - not necessary the same length as in >> my case - and I should not get any reminder in the result of >> PolynominalReduce. >> If I look PolynomialReduce as giving a vectorization of the polynom >> regarding to the selected {poly1,poly2,...} base, then the components >> of the result are the polynomial projections to the individual base >> polynoms. I would like to select a base where the resulting >> components have the minimum number of variables per component and I >> want this base to be as simple as possible, that is they also should >> have minimum number of variables in them. I am sure algebra has some >> theory for it, but my brain is just not recalling it right now. >> Any good tip, >> J.87nos > > I am not sure I really understand your question. You seem to want > to reduce your polynomial with respect to a family of polynomials > with reminder 0. That means you are reducing the polynomial with > respect to an ideal that contains the polynomial. Obviously you > will get the simplest representation in your sense (or at least > in the sense in which I understand what you are saying) if you > simply take the ideal generated by the polynomial, and as its basis > the polynomial itself. > PolynomialReduce[ftlmat,ftlmat] {{1},0} Nothing could be simpler than this but somehow I don't think that > is quite what you wanted? Perhaps you may be better satisifed by reducing with respect to a > GroebnerBasis of the ideal generated by the monomials of your > polynomial ftlmat? That will certainly contain your polynomial so > you will get remainder 0. The number of polynomials in the > GroebnerBasis will not be normally be small but the coefficients > can be made simple according to various criteria. For example > here are a couple of examples: > First[PolynomialReduce[ftlmat,GroebnerBasis[List@@ftlmat,Variables > [ftlmat]]]] > {2 c+f-2,4 b-2,2 b+e-2,2 d-2,b+2,-4,-4,2 b > +2,-2,-2,-2,-4,d-2,2,-2,4,-4,2,2,-4, > 2,4,-4,4,4,4,2,-2,2,-2,2,-2,2,2,4,2} v = First[PolynomialReduce[ftlmat, gr = GroebnerBasis[List @@ > ftlmat, Reverse[Variables[ftlmat]], > MonomialOrder -> EliminationOrder]]] > {2, 4, 2, 2, -2, 2, -2, 2, -2, 2, 4, 4, 4, -4, 4, 2, -4, 2, 2, -4, > 4, -2, 2, d - 2, 2*d - 4, f - 2, -2, > 2*d - 2, 4*e + 2, -4, 2*f - 4, 2, -2, e - 2, 2*e - 2, f - 2} You could try different orderings of the variables and different > monomial orders to see what gives you the simplest representation. Andrzej Kozlowski Chiba, Japan I am looking for an Aristotelian golden middle between your first and second recommendation. Let me reformulate my poly question in a general sense. I refer to the Help on PolynomialReduce for the explanation of symbols. Let say I have a polynomial poly and applying PolynomialReduce with polynomials {poly1,poly2,...,polym} with variables {x1,x2,...,xn} I get a result in the form {{roly1,roly2,...rolym} ,0} without any remainder. How should I select {poly1,poly2,...,polym} to get {roly1,roly2,...rolym} such as that Variables[roly1]+Variables[roly2]+....+Variables[rolyk] be minimal, but every one of these rolyis still should have minimum one variable? The individual rolys can be any length - obviously less than the length of poly. In my example I selected a subset of the 3-variable permutations of the variables for {poly1,poly2,...,polym} , where the guidance for my selection was that they should have had minimum common elements pairwise - like bcd and acf have just one common element. I do not want {poly1,poly2,...,polym} to be too long and probably all of them should be terms. Optimally {roly1,roly2,...rolym} should have elements that Variables[rolyi]+Variables[polyi]<=n. J.87nos ==== Subject: Re: poly question > I have a polynom called ftlmat (Dialog) In[187]:= > ftlmat > (Dialog) Out[187]= > 2*a^2*b^2*c + 2*a*b^2*c*d - > 2*b^2*c^2*d + b^2*c^2*d^2 + > 4*a^2*b*c*e - 2*a^2*c^2*e + > 2*a*b*c^2*e + 4*a*b*c*d*e - > 4*a*c^2*d*e - 2*b*c^2*d*e - > 2*c^2*d^2*e + 2*b*c^2*d^2* > e + 2*a^2*c*e^2 + > 2*a*c^2*e^2 + 2*a*c*d*e^2 + > c^2*d^2*e^2 + 2*a^2*b*c*f - > 2*a*b^2*d*f + 4*a*b*c*d*f - > 4*b^2*c*d*f - 2*b^2*d^2*f + > 2*b*c*d^2*f + 2*b^2*c*d^2* > f - 2*a^2*c*e*f + > 4*a*b*c*e*f - 4*a*b*d*e*f - > 4*a*c*d*e*f - 4*b*c*d*e*f - > 4*b*d^2*e*f - 2*c*d^2*e*f + > 4*b*c*d^2*e*f + 4*a*c*e^2* > f - 2*a*d*e^2*f - > 2*d^2*e^2*f + 2*c*d^2*e^2* > f + 2*a^2*b*f^2 + > 4*a*b*d*f^2 - 2*b^2*d*f^2 + > 2*b*d^2*f^2 + b^2*d^2*f^2 + > 2*a*b*e*f^2 - 2*b*d*e*f^2 + > 2*b*d^2*e*f^2 + > 2*a*e^2*f^2 + d^2*e^2*f^2 If I do a PolynomialReduce of it the following way, I get: In[170]:= > PolynomialReduce[ftlmat, > {a*b*c, a*b*f, a*c*e, > a*e*f, b*c*d, b*d*f, > c*d*e, d*e*f}, {a, b, c, > d, e, f}] > Out[170]= > {{2*a*b + 2*b*d + 4*a*e + > 2*c*e + 4*d*e + 2*a*f + > 4*d*f + 4*e*f, > -2*b*d - 4*d*e + 2*a*f + > 4*d*f + 2*e*f, > -2*a*c - 4*c*d + 2*a*e + > 2*c*e + 2*d*e - 2*a*f - > 4*d*f + 4*e*f, > -2*d*e + 2*e*f, > -2*b*c + b*c*d - 2*c*e + > 2*c*d*e - 4*b*f + 2*d*f + > 2*b*d*f - 4*e*f + > 4*d*e*f, -2*b*d - 4*d*e - > 2*b*f + 2*d*f + b*d*f - > 2*e*f + 2*d*e*f, > -2*c*d + c*d*e - 2*d*f + > 2*d*e*f, -2*d*e + d*e*f}, > 0} The result show that the first poly I got - related to a*b*c - has > all 6 variables, the next has 5 and the rest goes like 5,3,5,4,4,3. > If I total them it is 35. My question is what series of polynomials > should I use in PolymonialReduce to get results which contain the > least amount of variables each - that is the total of the number of > variables in each resulting polynom should be minimal, and on the > same time the number of selected polynoms should be also minimal and > their construction is simple - not necessary the same length as in > my case - and I should not get any reminder in the result of > PolynominalReduce. If I look PolynomialReduce as giving a vectorization of the polynom > regarding to the selected {poly1,poly2,...} base, then the components > of the result are the polynomial projections to the individual base > polynoms. I would like to select a base where the resulting > components have the minimum number of variables per component and I > want this base to be as simple as possible, that is they also should > have minimum number of variables in them. I am sure algebra has some > theory for it, but my brain is just not recalling it right now. > Any good tip, J.87nos I am not sure I really understand your question. You seem to want to reduce your polynomial with respect to a family of polynomials with reminder 0. That means you are reducing the polynomial with respect to an ideal that contains the polynomial. Obviously you will get the simplest representation in your sense (or at least in the sense in which I understand what you are saying) if you simply take the ideal generated by the polynomial, and as its basis the polynomial itself. PolynomialReduce[ftlmat,ftlmat] {{1},0} Nothing could be simpler than this but somehow I don't think that is quite what you wanted? Perhaps you may be better satisifed by reducing with respect to a GroebnerBasis of the ideal generated by the monomials of your polynomial ftlmat? That will certainly contain your polynomial so you will get remainder 0. The number of polynomials in the GroebnerBasis will not be normally be small but the coefficients can be made simple according to various criteria. For example here are a couple of examples: First[PolynomialReduce[ftlmat,GroebnerBasis[List@@ftlmat,Variables [ftlmat]]]] {2 c+f-2,4 b-2,2 b+e-2,2 d-2,b+2,-4,-4,2 b +2,-2,-2,-2,-4,d-2,2,-2,4,-4,2,2,-4, 2,4,-4,4,4,4,2,-2,2,-2,2,-2,2,2,4,2} v = First[PolynomialReduce[ftlmat, gr = GroebnerBasis[List @@ ftlmat, Reverse[Variables[ftlmat]], MonomialOrder -> EliminationOrder]]] {2, 4, 2, 2, -2, 2, -2, 2, -2, 2, 4, 4, 4, -4, 4, 2, -4, 2, 2, -4, 4, -2, 2, d - 2, 2*d - 4, f - 2, -2, 2*d - 2, 4*e + 2, -4, 2*f - 4, 2, -2, e - 2, 2*e - 2, f - 2} You could try different orderings of the variables and different monomial orders to see what gives you the simplest representation. Andrzej Kozlowski Chiba, Japan ==== Subject: a question about the UnitStep function I want to let Mathematica compute the convolution of two sqare waves. I did as follows f[x_]:=(UnitStep[x+1]-UnitStep[x-1])/2; integrand=f[z] f[x-z]; Assuming[Element[x, Reals], Integrate[integrand, {z, -Infinity, Infinity}]] Mathematica gave me the result as follows, ((-1 + x) UnitStep[-1 + x] - x UnitStep[x] + (2 + x) UnitStep[2 + x])/4 I plot the result to check Plot[%,{x,-10,10}, PlotRange->All]; It is clear wrong since the convolution of two square waves should be convergent. Can anyone give me some help with the subtlties about the UnitStep function? Any thoughts are appriciable. ==== Subject: Re: Weird behavior of SparseArray >I don't understand what is going on with SparseArray >If I write this: >cp1 = SparseArray[{i_, j_} -> 0, {4, 2}]; >cp1[[Range[4], 1]] = cp1[[Range[4], 1]] + {1, 1, 1, 1}; >cp1 // MatrixForm >I get cp1 with all entries equal to zero That's not what I see. I see In[6]:= cp1 = SparseArray[{i_, j_} -> 0, {4, 2}]; cp1[[Range[4],1]] = cp1[[Range[4],1]] + {1, 1, 1, 1}; Normal[cp1] $Version Out[8]= {{1, 0}, {1, 0}, {1, 0}, {1, 0}} Out[9]= 5.1 for Mac OS X (January 27, 2005) as I would expect -- To reply via email subtract one hundred and four ==== Subject: Re: Sudoku puzzle > A short solution, which I placed on Mathsource last week, applies two > basic rules before resorting to backtracking. The rules are sufficient > to find the 1 at {5,5} in this example. http://library.wolfram.com/infocenter/MathSource/5690/ Very nice. One thing that would make it more visual is to have an option Showing the solution a step at a time would be particularly useful if you are solving the puzzle by hand, get stuck, and want a hint. Since there are many people out there solving Sudoku puzzles, perhaps a webMathematica page using your solver would be a nice hook for webMathematica and Mathematica? > The solutions by Fred Simons and Andrzej Kozlowski (previously posted to > MathGroup) involving backtracking work fine (I did not select their > solutions for TMJ because it did not show progress towards the solution) > -- but I wonder if for the sudoku puzzles whether backtracking is ever > required? I think that any general solver must implement backtracking to deal > with under-specified problems, where there are multiple solutions, such > as the one shown above. There is insufficent information to proceed > once the {5,5} position is found, so a guess must be made for one of > the remaining positions. You can only know whether that guess is consistant with solution by > atempting to solve it and back tracking on a contradiction. If that > wasn't true then you would have been able to proceed. I would guess that puzzles with a single unique solution can all be > solved without backtracking, but the two rules that I implemented are > insufficent on the more difficult problems. That is essentially my question. All the puzzles published in newspapers, even the Very Hard ones, have a unique solution and, rejecting full enumeration as a way to avoid backtracking, I suspect as you do that backtracking is not required, and that at each stage of the solution, at least one entry can be filled in. Indeed, for all the newspaper examples I've tried with your package, setting ShowSteps -> True generates no intermediate output. Paul -- Paul Abbott Phone: +61 8 6488 2734 School of Physics, M013 Fax: +61 8 6488 1014 The University of Western Australia (CRICOS Provider No 00126G) AUSTRALIA http://physics.uwa.edu.au/~paul http://InternationalMathematicaSymposium.org/IMS2005/ ==== Subject: Re: Sudoku puzzle post. Also I hadn't made the connection between Paul Abbotts in flight puzzle and sudoku. There seems to be a few Mathematica solvers out there but no sudoku makers(???). both a sudoku maker and a sudoku solver. Mike > See, for example: http://library.wolfram.com/infocenter/MathSource/5690/ Michal >> Many readers would be aware that Sudoku is a puzzle (craze) that has >> recently appeared in many major newspapers around the world as a regular >> puzzle. >> (See http://www.sudoku.com and http://www.sudokufun.com/ >> An open source sudoku project exists with a Java applet available at >> sourceforge: http://sudoku.sourceforge.net/) >> Mathematica in Education and Research would like to issue a challenge to >> the >> Mathematica community to create a Mathematica version of Sudoku: a package >> that both creates Sudoku puzzles and solves them (either totally within a >> notebook or via the GUI interface). >> Education >> and Research describing the code and the (presumed?) challenges faced and >> overcome in writing the code. >> Michael Honeychurch >> Mathematica in Education and Research >> http://www.ijournals.net