mm-699 === Subject: Re: Output display of exponential function in Mathematica >Use the correct syntax :-) The natural logarithm of the number a, say, >is written Log[a]. Check Agreed. Back and forth I go because in class and with our instructor it's LN. Sorry for the inconvenience. >Now, the base of the natural logarithm is written E (capital e). Beg to differ here. The BasicInput.nb palette uses the small 'e' that is kind of double-struck. === >> Try running klipper or some similar utility. By habit, I use the middle >> mouse button to paste, and so had never encountered what you'd >> described. I was able to reproduce the hang using the key strokes as you >> detail. Running klipper solves it. Tested on fvwm, GNOME and KDE. > I was running klipper, but I had not fiddled with the settings. After your > suggestion I made a few changes, and now I can paste using the key combos. > I can't say exactly what I changed, because I can't seem to get it back to > the errant configuration. At least not without restarting X. There are various ways to stop klipper. 1. Find the klipper icon, right click and Quit. ps -aux |grep klipper # take note of the pid then; kill -9 klipper pid top -u $USER k Enter klipper pid 9 and all the other variants to command line constructs that could be combined into a script. > I've been having another problem since I changed the klipper settings. Now > when I paste, I often lose focus in the notebook, and the only thing I have > found that gives it back is to click with the mouse. That was the whole > reason for my not using button 2 in the first place. I don't like taking > my hands of the keyboard. If I could find a way to code button 2 into a > key chord, I would be quite happy. OK, so it sounds like you don't want to use the mouse at all. Try Alt + F11. It should allow you to cycle through open windows. You can also use your number key pad to move the mouse pointer around. Of those buttons on the Num keypad, I think that the 5, / and . keys correspond to mouse buttons Left, Middle, and Right, respectively. > I tried it under fvwm and the same thing happens. I copy some text out > of the > notebook, Ctrl+F, Shift+Insert, and it locks up. When I did a RMC, the > pointer became confined to the notebook rectangle, and I lost all other > HID access to the machine. >> Yes, its odd. I assume its related to the Find form not knowing what >> Shift+Insert means. > Strange that Klipper fixes that - I think; sort of. Perhaps it has to do > with what is in the buffer Shift+Insert is pulling from? > I've been told by WRI techsupport that new and wonderful things are in the > works regarding the FrontEnd. No one is saying much more. Let me guess - Because WRI has a product that boasts cross platform independence from the point of view that Mathematica is available for almost all OS's in popular use today, they can only aim to make the FrontEnd behaviour more cross platform independent. My guess is that the template for such a FrontEnd was seeded at about the same time that JLink was introduced. My guess is that all graphics will now appear as a separate or FrontEnd embedded window where mouse clicks will allow the user to directly manipulate graphics directives and to a certain degree, graphics primitives. My guess is that there will be color syntax highlighting. My guess is that 3D graphics will somehow be tied with the Java 3D API. My guess is that new packages will allow direct connection and communication with peripheral devices such as DAQ's etc via, USB, ethernet or SCSI interfaces (maybe I'm dreaming). My guess is that there will be press button functionality for Import etc. I could keep on guessing, but I think I'll just wait. In the meantime there are workarounds to almost all inconveniences introduced by the different OS's and environments. It is however, valuable to have stable siftware programs running on stable OS's. In any case, I reckon, it'll be all good. Yas > -- > The Mathematica Wiki: http://www.mathematica-users.org/ > Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html > Math for the WWW: http://www.w3.org/Math/ === Subject: Re: How would you evaluate this limit in Mathmatica David, I _have_ taught, extensively, and the model you explemplify with your reply is precisely the process that every decent teacher would wish his/her students would follow. I guess I am also an impractical idealist. Our educational system does not encourage students to follow such a model - it in fact discourages such explorations. My two decades outside academia only increases my discomfort with the way we teach our children. Our system generates many degree-holders with deficient insight, limited curiousity, and a low level of competence. I would very much like to change this situation, but the problem seems to be much larger than my ability to effect change. Still, I work at it. I hope others will as well. I agree with you that Mathematica provides many opportunities to learn mathematics. Specific examples appear prolifically on this listserv. -GRB- ----- Start Original Message ----- === Subject: How would you evaluate this limit in Mathmatica > I would like to take a different tack from Andrzej on this. > I think Mathematica is great for tackling and learning mathematical subjects > just as this and maybe almost any mathematical subject. I don't believe at > all in the 'set Mathematica aside when the real math comes in' school. The > problem is to be able to take the time to explore a subject. Unfortunately, > students are seldom given the time or the tools. > I'm not an expert on analysis but the problem looked interesting and > possibly instructive so I tried it and replied to Robert privately because I > was using an attachment. I got the limit of zero from Mathematica > immediately but when I plotted the function over a wider range of x I saw > some spikes that made me suspcious. I then remembered from MathGroup that > Andrzej, or was it Paul Abbott, was always bringing in Series expansions to > augment limit problems. So I did a series expansion and saw the problem at a > == E. Then I decided to look at it as a complex function with z == = x + I a > and made a domain coloring plot. That showed that a curving infinite modulus > line crossed a zero modulus line at x == 0, a == E. By taking a l= arger view > it appeared that was the only singular point on the x == 0 line. (But there > was lots of interesting structure elsewhere that might be fun to explore.) > I then used Mathematica to take the limit specifically when a == E and got > 6. But I was doubtful if that was correct. It looked to me that the limit > might be undefined there (and maybe it is as a two dimensional problem - I > don't know yet.) Then I cracked open a handbook (Mathematics Handbook for > Science and Engineering 4th Edition by Lennart Rade & Bertil Westergren - > the best darn small mathematics handbook I have ever seen) and reviewed > l'Hopital's rule and the 'sandwich theorem'. Then using a series on the > numerator I found two simpler functions that sandwiched Robert's function > and had the limit of 6 at a = E. So I became convinced that Mathematica was > right. > But I would never have gotten the answer without Mathematica. Nor would I > have spent the time. > I can see how one could make a nice notebook on Robert's problem that would > teach a lot about limits and mathematics. > The problem is not with Mathematica or CASs in general. The problem is with > a mode of instruction where the student reads the book, is lectured to, > works exercises and then demonstrates his knowledge on formal tests. Far > better if the student has the time and tools to explore interesting and real > problems, and a professor that acts more as a tutor, guide and codiscoverer > than a remote expert. > But then, I've never taught so am probably an impractical idealist. > David Park > djmp@earthlink.net > http://home.earthlink.net/~djmp/ > I am afraid I have no good ideas for tackling this without using the > Taylor series. However, in any case, I think to deal with this type > of situation students need to understand not only the mathematics > behind it but the limitations of computer software. I find that > students are at the beginning quite surprised that such an advanced > and expensive program as mathematica is can't deal with such problems > by itself, but (if I have time for this sort of thing, which I > usually do not) I try to make them think themselves of how to design > a algorithm or a method that would deal with such problems without > human intervention. I think this approach is very enlightening but it > requires that the mathematics should already be well understood. It's > because of problem like this that I do not think that CAS systems are > suitable for developing understanding of mathematics. I think they > are good for illustrating mathematical ideas, particularly by means > of graphics, and for performing tedious computations and > manipulations once one has a good understanding of the mathematical > concepts involved. I would be very weary, however, about suggesting > progrms like Matheamtica as a good mean sof undestanding limits, > derivatives and integrals. A good text book is a far more reliable > tool for this. > Andrzej Kozlowski > The series expansion does indeed show there is a problem when Log > [a] = 1, > i.e. when a = E and then > Series[ > ((1 + 4 x^2)^(1/4) - (1 + 5 x^2)^(1/5))/ > (E^(-x^2/2) - Cos[x]), {x, 0, 4}] > will show the answer in that special case. Indeed Mathematica does > give 6 for > Limit[ > ((1 + 4 x^2)^(1/4) - (1 + 5 x^2)^(1/5))/ > (E^(-x^2/2) - Cos[x]), x->0] > as well. > -- Bob > -- > Robert L. Knighten > Robert@Knighten.org ----- End Original Message ----- === Subject: Turning on numerical computation Mathematica outputs answers in symbolic form as the exact answer. I can force numeric output by N or using a decimal. Can I make numeric answers the default until I want to go back to symbolic. In other words, can I turn numeric on and off as my default output? === Subject: How to draw elliptical curve y^2=x^3+x+1 in screen with Mathematica4, and I have tried ellipticExp and EllipticLog but in vain. Could anyone tell me in detail how to draw === Subject: Re: How to draw elliptical curve Hi Berlid, why not solve the equation for x or y? e.g. solving for y: Plot[{Sqrt[x^3 + x + 1], -Sqrt[x^3 + x + 1]}, {x, -.6823, 1}] or solving for x: res = Solve[y^2 == x^3 + x + 1, x][[1]]; Plot[x /. res, {y, -2, 2}] Daniel > y^2=x^3+x+1 in screen with Mathematica4, and I have tried ellipticExp > and EllipticLog but in vain. Could anyone tell me in detail how to draw === Subject: Sending again: Symbolizing subscripts Sorry if I am sending this twice, but the first one doesn't seem to have worked: It looks like there aren't any ideas for solving my original problem (included below), so I'll widen my search a bit. I want any expression of the form Subscript[a, b] to be interpreted as a symbol. I can achieve this easily using the Notation package, by the following: Utilities`Notation`Symbolize[NotationBoxTag[SubscriptBox[_, _]]] I also want to run my code in batch mode (without a front end). However, [it appears that] the Notation package cannot be used in batch mode. Given that I can't easily make the Notation package work in batch mode, I now ask: does anyone know another way (not using the Notation package) to make all subscripts behave as symbols? -Andrew > I have some code that includes (and relies upon) a call to > Utilities`Notation`Symbolize[...]. I would like to run the code in batch > mode (without a front end), but the Notation package generates many error > messages when being loaded without a front end, and subsequent calls to > Symbolize[...] result in the Mathematica kernel hanging. > Does anyone know of any way to use the notation package in batch mode, or > does anyone have any ideas for other ways to run my code automatically from > the (linux) shell? > -Andrew === Subject: Re: Sending again: Symbolizing subscripts I saw your question the first time. One of my packages is also suffering from a similar problem. Maybe you could try emailing the guy email is written in the package documentation (assumedly so you know which expert at WRI to ask). If there is no solution forthcoming that uses the notation package and assuming you are trying to introduce a new input notation, then you should look into the the various functions that handle transforming box expressions into mathematical expressions (eg, superscript into power) and add your definition there. For output, you need to do the inverse. You could try looking at the source code of the error propagation package on Math Source, it introduces a simple notation. Please post back to the list with the information you obtain. Sorry I'm not of more help to you, -- http://chrischiasson.com/contact/chris_chiasson === Subject: Re: Sending again: Symbolizing subscripts in batch mode you will see nothing, especial you will never see the special formatis for subscripts .. it is nonsens to set up a special notation for things that you can't see -- work with x1,x2 or x$1,x$2 Jens Andrew Moylan schrieb | Sorry if I am sending this twice, but the first one doesn't seem to have | worked: | | | It looks like there aren't any ideas for solving my original problem | (included below), so I'll widen my search a bit. | | I want any expression of the form Subscript[a, b] to be interpreted as a | symbol. I can achieve this easily using the Notation package, by the | following: | Utilities`Notation`Symbolize[NotationBoxTag[SubscriptBox[_, _]]] | | I also want to run my code in batch mode (without a front end). However, | [it appears that] the Notation package cannot be used in batch mode. | Given that I can't easily make the Notation package work in batch mode, | I now ask: does anyone know another way (not using the Notation package) | to make all subscripts behave as symbols? | | -Andrew | | > I have some code that includes (and relies upon) a call to | > Utilities`Notation`Symbolize[...]. I would like to run the code in batch | > mode (without a front end), but the Notation package generates many error | > messages when being loaded without a front end, and subsequent calls to | > Symbolize[...] result in the Mathematica kernel hanging. | > Does anyone know of any way to use the notation package in batch mode, or | > does anyone have any ideas for other ways to run my code automatically from | > the (linux) shell? | > -Andrew | === Subject: Re: Sending again: Symbolizing subscripts Hi Andrew, if you do not mind if your output looks a bit funny, you may replace any subscripted variable by a symbol whose name is constructed by the original name and the index. E.g. Unprotect[Subscript]; Subscript[x1_,x2_]:=Symbol[ToString[x1]<>sub<>ToString[x2]] This will change any subcsripted variable into a symbol with name ...sub... Daniel > Sorry if I am sending this twice, but the first one doesn't seem to have > worked: > It looks like there aren't any ideas for solving my original problem > (included below), so I'll widen my search a bit. > I want any expression of the form Subscript[a, b] to be interpreted as a > symbol. I can achieve this easily using the Notation package, by the > following: > Utilities`Notation`Symbolize[NotationBoxTag[SubscriptBox[_, _]]] > I also want to run my code in batch mode (without a front end). However, > [it appears that] the Notation package cannot be used in batch mode. > Given that I can't easily make the Notation package work in batch mode, > I now ask: does anyone know another way (not using the Notation package) > to make all subscripts behave as symbols? > -Andrew > > I have some code that includes (and relies upon) a call to > > Utilities`Notation`Symbolize[...]. I would like to run the code in batch > > mode (without a front end), but the Notation package generates many error > > messages when being loaded without a front end, and subsequent calls to > > Symbolize[...] result in the Mathematica kernel hanging. > > Does anyone know of any way to use the notation package in batch mode, or > > does anyone have any ideas for other ways to run my code automatically from > > the (linux) shell? > > -Andrew > > === Subject: Re: How prove an inequality? > It's easy to argue that: Log[2] > 1/2 > One argument goes as follows: Consider > f[x_] := Log[x] > on the interval from 1 to 2. Then by the Mean Value Theorem, > (f[2] - f[1])/(2 - 1) = f'[c] for some c with 1 < c < 2. > On the one hand: > (f[2] - f[1])/(2 - 1) > Log[2] > On the other hand, > f'[c] > 1/c > and obviously 1/c > 1/2 when 1 < c < 2. > Is there some simple and direct way to express the on the other hand > part in Mathematica? > Of course one could evaluate: > Minimize[{f'[c], 1 <= c <= 2} , c] > But that does not quite express what was said above. Surely there's > some way to do it using Simplify or Resolve or some such function. > How? > -- > Murray Eisenberg murray@math.umass.edu > Mathematics & Statistics Dept. > Lederle Graduate Research Tower phone 413 549-1020 (H) > University of Massachusetts 413 545-2859 (W) > 710 North Pleasant Street fax 413 545-1801 > Amherst, MA 01003-9305 How about this: f[x_] := Log[x] Resolve[ForAll[c,11/2]] True Andrzej Kozlowski === Subject: How prove an inequality? It's easy to argue that: Log[2] > 1/2 One argument goes as follows: Consider f[x_] := Log[x] on the interval from 1 to 2. Then by the Mean Value Theorem, (f[2] - f[1])/(2 - 1) = f'[c] for some c with 1 < c < 2. On the one hand: (f[2] - f[1])/(2 - 1) Log[2] On the other hand, f'[c] 1/c and obviously 1/c > 1/2 when 1 < c < 2. Is there some simple and direct way to express the on the other hand part in Mathematica? Of course one could evaluate: Minimize[{f'[c], 1 <= c <= 2} , c] But that does not quite express what was said above. Surely there's some way to do it using Simplify or Resolve or some such function. How? -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: How prove an inequality? Maybe f'[Interval[{1, 2}]] or Reduce[{f'[x] == k, 1 < x < 2}, {k, x}, Reals] give what you require? Daniel === Subject: Re: Turning on numerical computation Default behavior is exact {E,Pi,GoldenRatio} {[ExponentialE], ?, ?} %//N {2.71828, 3.14159, 1.61803} ?$Post $Post is a global variable whose value, if set, is applied to every output expression. $Post=N; {E, Pi, GoldenRatio} {2.71828, 3.14159, 1.61803} Restore default behavior to exact using $Post=. {E, Pi, GoldenRatio} {[ExponentialE], ?, ?} %//N {2.71828, 3.14159, 1.61803} Bob Hanlon === > Subject: Turning on numerical computation > Mathematica outputs answers in symbolic form as the exact answer. > I can force numeric output by N or using a decimal. > Can I make numeric answers the default until I want to go back to > symbolic. In other words, can I turn numeric on and off as my default > output? === Subject: Re: How to draw elliptical curve eqn=(y^2==x^3+x+1); Plot[Evaluate[y/.Solve[eqn, y]], {x, Root[#1^3+#1+1&,1], 2}]; ImplicitPlot[eqn,{x, -1, 2}, AspectRatio->1/GoldenRatio, ImageSize->288]; Bob Hanlon === > Subject: How to draw elliptical curve > y^2=x^3+x+1 in screen with Mathematica4, and I have tried ellipticExp > and EllipticLog but in vain. Could anyone tell me in detail how to draw === Subject: Re: Re: Output display of exponential function in Mathematica To get the 'double struck small e' type esc e e esc, or click it off the palette. In any case, it is not the Latin small case e. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ >Now, the base of the natural logarithm is written E (capital e). Beg to differ here. The BasicInput.nb palette uses the small 'e' that is kind of double-struck. Bookreader === Subject: Re: How to draw elliptical curve Needs[Graphics`ImplicitPlot`] ImplicitPlot[y^2 == x^3 + x + 1, {x, -2, 8}, {y, -10, 10}, PlotPoints -> 40]; Or we can make a parametric plot if we get the minimum value for x. xmin = x /. First@Solve[x^3 + x + 1 == 0] -(2/(3*(-9 + Sqrt[93])))^(1/3) + ((1/2)*(-9 + Sqrt[93]))^(1/3)/3^(2/3) ParametricPlot[ {{x, Sqrt[x^3 + x + 1]}, {x, -Sqrt[x^3 + x + 1]}}, {x, xmin, 6}, Frame -> True, Axes -> False] David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ y^2=x^3+x+1 in screen with Mathematica4, and I have tried ellipticExp and EllipticLog but in vain. Could anyone tell me in detail how to draw === Subject: Re: How to draw elliptical curve Why not simply: xmin = x /. First@Solve[x^3 + x + 1 == 0] Plot[{Sqrt[x^3 + x + 1], -Sqrt[x^3 + x + 1]}, {x, xmin, 6}, Frame -> True, Axes -> False] === Subject: Re: Output display of exponential function in Mathematica >>Now, the base of the natural logarithm is written E (capital e). >Beg to differ here. The BasicInput.nb palette uses the small 'e' >that is kind of double-struck. The BasicInput palette displays the constants Pi and E in TraditionalForm. If you type E//TraditionalForm into an empty cell, the corresponding output cell will be the same character you get after clicking the entry button on the BasicInput pallete. The point is, to enter the constant E from the keyboard, you enter it as a capital E. -- To reply via email subtract one hundred and four === Subject: Re: Turning on numerical computation >Can I make numeric answers the default until I want to go back to >symbolic. In other words, can I turn numeric on and off as my >default output? Yes. If you set the value of $Post to N, the all subsequent numeric output will be machine precision numbers. To get the normal default behaviour back, simply clear $Post. -- To reply via email subtract one hundred and four === Subject: Re: How to draw elliptical curve >like y^2=x^3+x+1 in screen with Mathematica4, and I have tried >ellipticExp and EllipticLog but in vain. Could anyone tell me in One way to do this would be to use ImplicitPlot, i.e., <1/GoldenRatio]; -- To reply via email subtract one hundred and four === Subject: Re: How would you evaluate this limit in Mathmatica Yeah, I actually think this is a lovely example of how teaching using a CAS can potentially work really *well*. If the CAS is used as a supposedly infallible, oracular source of correct answers, than obviously there's a problem. So let's not use Mathematica like that! We shouldn't be using it like that anyway. That's what the back of textbooks is for. Instead, how about a sequence of activities that, for example, asks students to use Mathematica to evaluate the generic limit and then the exceptional case, and then invites them to comment on any discrepancy, investigate and try to work out what's going on, using whatever techniques and resources they like (graph plotting, series expansion, L'Hopital's Rule, etc). That's potentially a really nice open-ended problem that could even form the basis of a mini-project. And if one of the things that comes out of it is that software isn't infallible, so much the better. Indeed, the question why this is a hard problem to solve using generic algorithms is itself quite rich and interesting, don't you feel? Link to the forum page for this post: http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=Speci al:Forum_ViewTopic&pid=6624#p6624 === Subject: Re: How would you evaluate this limit in Mathematica > There has recently been an off-topic discussion on the category theory > mailing list of the assertion that computer algebra systems are tricky to > use correctly. The starting point was the question of evaluating the > (parametric) limit: > Lim ((1 + 4 x^2)^(1/4) - (1 + 5 x^2)^(1/5)) > x->0 --------------------------------------- > (a^(-x^2/2) - Cos[x]) > So I am interested in getting comments about doing this in Mathematica. I'm > also interested in how one would teach solving limits using Mathematica. > The reason this is an interesting question is because the limit is indeed 0 > EXCEPT for the one exceptional case when a = E where the limit is 6. The > problem was originally given to students in a mathematical analysis course as > part of the early discussion of limits, and was then taken by one of the > students as a test case to another class where they were being introduced to > CAS. [I'm just an interested bystander in all of this.] > So Mathematica gives 0 for > Limit[ > ((1 + 4 x^2)^(1/4) - (1 + 5 x^2)^(1/5))/ > (a^(-x^2/2) - Cos[x]), x->0] > but does indeed give 6 for > Limit[ > ((1 + 4 x^2)^(1/4) - (1 + 5 x^2)^(1/5))/ > (E^(-x^2/2) - Cos[x]), x->0] > but how is a Mathematica user supposed to learn that? > This limit is a 0/0 case, so one can use L'Hospital's rule > Limit[D[((1 + 4 x^2)^(1/4) - (1 + 5 x^2)^(1/5)),x]/D[(a^(-x^2/2) - > Cos[x]),x],x->0] > which again gives 0. A good student will remember to check and will find that > Limit[D[((1 + 4 x^2)^(1/4) - (1 + 5 x^2)^(1/5)),x], x->0] is 0 > and > Limit[D[(a^(-x^2/2) - Cos[x]),x],x->0], x->0] is 0 as well. > Iterating L'Hospital's Rule doesn't help -- the answer is still 0, but the > limit of the second derivative of the denominator is 1 - Log[a] which should > give a hint that the special case where 1 - Log[a] = 0 needs to be > investigated. > An easier method is to look at > Series[((1 + 4 x^2)^(1/4) - (1 + 5 x^2)^(1/5))/ > (a^(-x^2/2) - Cos[x]), {x, 0, 3}] > which gives > x^2/(1 - Log[a]) + O[x]^4 > and shows there is a problem when Log[a] = 1, i.e. when a = E, and then > Series[((1 + 4 x^2)^(1/4) - (1 + 5 x^2)^(1/5))/ > (E^(-x^2/2) - Cos[x]), {x, 0, 3}] > gives > 6 - 143x^2/5 + O[x]^4 > which shows the answer in that special case, but this is certainly what I > *would* call tricky. And this is long before a discussion of Taylor series. > -- Bob > -- > Robert L. Knighten > Robert@Knighten.org Probably all the more time before discussion of points of indeterminacy (most students will not encounter that concept unless and until taking a course in several complex variables). You have a meromorphic function in {a,x} in a neighborhood of {E,0}. At that particular point the limiting value will be path dependent. For example, func[a_, x_] := ((1 + 4x^2)^(1/4) - (1 + 5* x^2)^(1/5)) /(a^(-x^2/2) - Cos[x]) In[26]:=Limit[func[E+m*t^2,t],t->0] Out[27]=(6*E)/(E - 6*m) We can thus attain any nonzero limit by judicious selection of m, if we have the second variable approach 0 linearly and the first approach E quadratically. I don't particularly disagree with sentiments expressed in several responses, regarding how to use or not use symbolic computation in education. But if one point stands out from an example such as this one, it is that there can be subtleties both to the math and the interaction with symbolic algebra. I do not think this necessarily indicates a deficiency in how we teach, or how we use symbolic programs (in and out of the classroom), or in how such programs work. Which is not to say that other reasons do not exist to indicate flaws in these various areas. Daniel Lichtblau Wolfram Research === Subject: Re: How would you evaluate this limit in Mathematica I lack the ability to give insight into these types of problems, but maybe asking for it will motivate others to drop some knowledge: Can someone provide code to graphically illustrate how the limit is path dependant near a->E and x->0? Is this problem really a double limit? Can it be converted into a different coordinate system where it is then a single variable limit? -- http://chrischiasson.com/contact/chris_chiasson === Subject: Re: Something wrong about PolynomialGCD Why not do thelist = Get[element3.m]; result = PolynomialGCD@@thelist; ? It's hard to tell what the problem is without looking at element3.m. Bhuvanesh, Wolfram Research. === Subject: Re: Mathematica SingularValueDecomposition failure Is the bug present in Netlib's svdpack? === Subject: Re: Mathematica SingularValueDecomposition failure I'm curious if your bug involves complex numbers. I ran into a problem with the Fortran version of SVD some years ago for a problem involving complex numbers. The answer looked reasonable (no errors or out-of-range numbers), but it was demonstrably wrong. I ended up recasting my problem to reals. Unfortunately, I no longer have my notes on the problem. And I can't be sure if I was using LINPACK (which became LAPACK) or IMSL at the time. Gerry F. >It is now six weeks since my request [TS 28968] asked for help >regarding outright failures in SingularValueDecomposition[] >and routines deriving from it. >Although Wolfram Research always replies promptly, politely, >and respectfully to my emails, the amount of actual support >received to date continues to be zero. >After six weeks with no reply, I am sure you can appreciate >my apprehension that this issue is steadily slipping lower and >lower on Wolfram's internal priority list, such that the waiting >time is asymptotically tending to .... [Infinity]. Yikes !! >My original questions were: > (a) Has Wolfram Research reproduced the SVD bug? > (b) Do you know a workaround at present? > (c) If no workaround is known, when will one be available? >After conversations with colleagues, there is a new question: > (d) If the bug turns out to be in LAPACK and/or BLAS > (as several of my colleagues now suspect) and Wolfram > Research finds and fixes it, is it then Wolfram Research > policy to post a correction to the public-domain code? >This is a serious bug that is obstructing a large research >program. And due to the ubiquity of SVD calculations, it >impacts a considerable portion of Mathematica's customers. > John Sidles, Professor > UW School of Medicine > UW Quantum System Engineering Group > ( http://www.mrfm.org ) === Subject: How to set up a diff equation for circuit with a diode? I'm kind of curious how to set up a nonlinear differential equation and then solve it using NDSolve in case of the following setup: Battery V in series with a diode, R and L. To simplify, we may assume that diode is a pure conducting device in forward direction and pure blocking device in the reverse direction. Now how to set up a differential equation for the current I(t), that is solvable using NDSolve? Mike === Subject: Re: How to set up a diff equation for circuit with a diode? > I'm kind of curious how to set up a nonlinear differential equation and > then solve it using NDSolve in case of the following setup: > Battery V in series with a diode, R and L. What you mean like this? http://documents.wolfram.com/mathematica/Demos/Notebooks/ChaoticCircuit.html where it is shown (using a real diode not an ideal one) that chaotic behaviour is possible. -- Dave K http://www.southminster-branch-line.org.uk/ Please note my email address changes periodically to avoid spam. It is always of the form: month-year@domain. Hitting reply will work for a couple of months only. Later set it manually. The month is always written in 3 letters (e.g. Jan, not January etc) === Subject: Re: How to set up a diff equation for circuit with a diode? Does anyone know, offhand, how they obtained that model for the diode (or just what model of a diode that is)? -- http://chrischiasson.com/contact/chris_chiasson === Subject: Re: How to set up a diff equation for circuit with a diode? I figured out this. Please comment: During forward bias, voltage across diode = 0.026 ln [10^12 I + 1] <- from diode equation During reverse bias, diode can be modelled as a large resistor, eg 10^12 ohms. voltage = I * R_Large So the differential equation looks like: V = IR + LI' + 0.026 ln[ 10^12 Abs[I] + 1] * U[I] + I * R_Large U[-I] where U is the Unit Step function (can be modelled as a continuous function using tanh). L and R are inductance and resistance in series with a source V(t) I modelled U as U[I] = (1+ Tanh[IB])/2 where B is a very large number, eg 10^12 Works great in mathematica using NDSolve. Mike > I'm kind of curious how to set up a nonlinear differential equation and > then solve it using NDSolve in case of the following setup: > Battery V in series with a diode, R and L. > To simplify, we may assume that diode is a pure conducting device in > forward direction and pure blocking device in the reverse direction. > Now how to set up a differential equation for the current I(t), that is > solvable using NDSolve? > Mike === Subject: Re: How to set up a diff equation for circuit with a diode? your question mnust be rephrased. The diode either has no effect or blocks all current. If the diode has no effect, the initial current of I0 changes with time exponentially to V/R. For this case we have (I call the current C because I already has a meaning): L C'[t] + R C[t] -V == 0 the analytic solution to this is (in its full glory): !(([ExponentialE]^(-((R t)/L)) ((C0 R + (((-1) + [ExponentialE]^((R t)/L))) V)))/R) Using NDSolve, you will first have to give numerical values to the constants and then you would write: rep = {R -> 1, L -> 1, V -> 1, C0 -> 2}; NDSolve[{L C'[t] + R C[t] - V == 0, C[0] == C0} /. rep, C, {t, 0, 2}] this gives an InterpolatingFunction that can be plottedt e.g. by: Plot[(C /. res[[1]])[t], {t, 0, 2}] Daniel > I'm kind of curious how to set up a nonlinear differential equation and > then solve it using NDSolve in case of the following setup: > Battery V in series with a diode, R and L. > To simplify, we may assume that diode is a pure conducting device in > forward direction and pure blocking device in the reverse direction. > Now how to set up a differential equation for the current I(t), that is > solvable using NDSolve? > Mike === Subject: Re: How to set up a diff equation for circuit with a diode? > I'm kind of curious how to set up a nonlinear differential equation and > then solve it using NDSolve in case of the following setup: > Battery V in series with a diode, R and L. > To simplify, we may assume that diode is a pure conducting device in > forward direction and pure blocking device in the reverse direction. > Now how to set up a differential equation for the current I(t), that is > solvable using NDSolve? Actually, this is an example in the built-in documentation. Evaluate FrontEndExecute[FrontEnd`HelpBrowserLookup[ DemosLink, Chaotic Circuit]] and click on the Demos link. 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 === Subject: Re: How to set up a diff equation for circuit with a diode? your unrealistic assumption | To simplify, we may assume that diode is a pure conducting device in | forward direction and pure blocking device in the reverse direction. will hinder NDSolve[] to work properly because the error term will infinte large when the current change the sign. A Laplace Transform may help you but that's not NDSolve[] Jens siliconmike schrieb im | I'm kind of curious how to set up a nonlinear differential equation and | then solve it using NDSolve in case of the following setup: | | Battery V in series with a diode, R and L. | | To simplify, we may assume that diode is a pure conducting device in | forward direction and pure blocking device in the reverse direction. | | Now how to set up a differential equation for the current I(t), that is | solvable using NDSolve? | | Mike | === Subject: FixedPoint stops when elements no longer change? This is the example in The Mathematica Book for FixedPointList: FixedPointList[Cos, 1.0] {1., 0.540302, 0.857553, 0.65429, 0.79348, 0.701369, 0.76396, 0.722102, 0.750418, 0.731404, 0.744237, 0.735605, 0.741425, 0.737507, 0.740147, 0.738369, 0.739567, 0.73876, 0.739304, 0.738938, 0.739184, 0.739018, 0.73913, 0.739055, 0.739106, 0.739071, 0.739094, 0.739079, 0.739089, 0.739082, 0.739087, 0.739084, 0.739086, 0.739085, 0.739086, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085} A bit of poking around showed me that this is using SameQ for SameTest. SameQ requires exact correspondence between expressions, except that it considers Real numbers equal if their difference is less than the uncertainty of either of them. I guess I'm not seeing all the decimal places used to generate to list above. How would I determine the precision used to determine two successive values are unchanged? I tried FixedPointList[N[Cos[#], 2] &, 1.0], but that changed neither the display, nor the result. -- The Mathematica Wiki: http://www.mathematica-users.org/ Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html Math for the WWW: http://www.w3.org/Math/ === Subject: Re: FixedPoint stops when elements no longer change? Hi Steven, It seems that the answered you got directed you how to represent the results with desired accuracy but in order to use desired accuracy in FixedPoint[] you need to set this in the SameTest option. Try the following FixedPointList[Cos, 1.0, SameTest -> (Abs[#1 - #2] < 0.01 &)] yehuda > This is the example in The Mathematica Book for FixedPointList: > FixedPointList[Cos, 1.0] > {1., 0.540302, 0.857553, 0.65429, 0.79348, 0.701369, 0.76396, 0.722102, > 0.750418, 0.731404, 0.744237, 0.735605, 0.741425, 0.737507, 0.740147, > 0.738369, 0.739567, 0.73876, 0.739304, 0.738938, 0.739184, 0.739018, > 0.73913, > 0.739055, 0.739106, 0.739071, 0.739094, 0.739079, 0.739089, 0.739082, > 0.739087, 0.739084, 0.739086, 0.739085, 0.739086, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085} > A bit of poking around showed me that this is using SameQ for SameTest. > SameQ requires exact correspondence between expressions, except that it > considers Real numbers equal if their difference is less than the > uncertainty of either of them. > I guess I'm not seeing all the decimal places used to generate to list > above. How would I determine the precision used to determine two > successive values are unchanged? > I tried FixedPointList[N[Cos[#], 2] &, 1.0], but that changed neither the > display, nor the result. > -- > The Mathematica Wiki: http://www.mathematica-users.org/ > Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html > Math for the WWW: http://www.w3.org/Math/ === Subject: Re: FixedPoint stops when elements no longer change? > This is the example in The Mathematica Book for FixedPointList: > FixedPointList[Cos, 1.0] > {1., 0.540302, 0.857553, 0.65429, 0.79348, 0.701369, 0.76396, 0.722102, > 0.750418, 0.731404, 0.744237, 0.735605, 0.741425, 0.737507, 0.740147, > 0.738369, 0.739567, 0.73876, 0.739304, 0.738938, 0.739184, 0.739018, > 0.73913, > 0.739055, 0.739106, 0.739071, 0.739094, 0.739079, 0.739089, 0.739082, > 0.739087, 0.739084, 0.739086, 0.739085, 0.739086, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085} > A bit of poking around showed me that this is using SameQ for SameTest. > SameQ requires exact correspondence between expressions, except that it > considers Real numbers equal if their difference is less than the > uncertainty of either of them. > I guess I'm not seeing all the decimal places used to generate to list > above. How would I determine the precision used to determine two > successive values are unchanged? > I tried FixedPointList[N[Cos[#], 2] &, 1.0], but that changed neither the > display, nor the result. Hi Steven, Try the following: In[16]:= l = FixedPointList[Cos, 1.]; In[17]:= NumberForm[l, Floor[$MachinePrecision] + 1] Out[17]//NumberForm= {1.,0.5403023058681398,0.857553215846393,0.6542897904977791,0. 7934803587425656,0.7013687736227565,0.7639596829006542,0.7221024250267077,0. 7504177617637605,0.7314040424225098,0.7442373549005569,0.7356047404363474,0. 7414250866101092,0.7375068905132428,0.7401473355678757,0.7383692041223232,0. 7395672022122561,0.7387603198742113,0.7393038923969058,0.7389377567153445,0. 7391843997714936,0.7390182624274122,0.7391301765296711,0.7390547907469173,0. 7391055719265363,0.7390713652989449,0.7390944073790912,0.7390788859949921,0. 7390893414033926,0.7390822985224023,0.7390870426953322,0.7390838469650002,0. 7390859996481299,0.7390845495752126,0.7390855263619245,0.7390848683867142,0. 7390853116067619,0.7390850130484203,0.7390852141609171,0.739085078689123,0. 7390851699445545,0.7390851084737987,0.7390851498812394,0.7390851219886894,0. 7390851407774467,0.7390851281211138,0.7390851366465718,0.7390851309037208,0. 7390851347721744,0.7390851321663375,0.7390851339216606,0.7390851327392538,0. 7390851335357373,0.7390851329992164,0.7390851333606233,0.7390851331171753,0. 7390851332811648,0.7390851331706995,0.7390851332451103,0.7390851331949863,0. 7390851332287504,0.7390851332060064,0.7390851332213271,0.7390851332110069,0. 7390851332179587,0.7390851332132758,0.7390851332164302,0.7390851332143055,0. 7390851332157366,0.7390851332147727,0.739085133215422,0.7390851332149846,0. 7390851332152792,0.7390851332150808,0.7390851332152145,0.7390851332151244,0. 739085133215185,0.7390851332151441,0.7390851332151717,0.7390851332151531,0. 7390851332151657,0.7390851332151573,0.7390851332151628,0.7390851332151591,0. 7390851332151617,0.7390851332151599,0.7390851332151611,0.7390851332151604,0. 7390851332151609,0.7390851332151605,0.7390851332151608,0.7390851332151605,0. 7390851332151607} In[9]:= l[[-1]] - l[[-2]] Out[9]= 1.1102230246251565*^-16 $MachineEpsilon gives the smallest machine-precision number which can be added to 1.0 to give a result that is distinguishable from 1.0. In[11]:= $MachineEpsilon Out[11]= 2.220446049250313*^-16 In[12]:= l[[-1]] - l[[-2]] < $MachineEpsilon Out[12]= True In[18]:= $Version Out[18]= 5.2 for Microsoft Windows (June 20, 2005) /J.M === Subject: Re: FixedPoint stops when elements no longer change? Hi Steven, to see all decimal places you could say: NumberForm[#, 17] & /@ FixedPointList[Cos, 1.0] Daniel > This is the example in The Mathematica Book for FixedPointList: > FixedPointList[Cos, 1.0] > {1., 0.540302, 0.857553, 0.65429, 0.79348, 0.701369, 0.76396, 0.722102, > 0.750418, 0.731404, 0.744237, 0.735605, 0.741425, 0.737507, 0.740147, > 0.738369, 0.739567, 0.73876, 0.739304, 0.738938, 0.739184, 0.739018, > 0.73913, > 0.739055, 0.739106, 0.739071, 0.739094, 0.739079, 0.739089, 0.739082, > 0.739087, 0.739084, 0.739086, 0.739085, 0.739086, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, > 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085, 0.739085} > A bit of poking around showed me that this is using SameQ for SameTest. > SameQ requires exact correspondence between expressions, except that it > considers Real numbers equal if their difference is less than the > uncertainty of either of them. > I guess I'm not seeing all the decimal places used to generate to list > above. How would I determine the precision used to determine two > successive values are unchanged? > I tried FixedPointList[N[Cos[#], 2] &, 1.0], but that changed neither the > display, nor the result. === Subject: Re: How to draw elliptical curve you can use ImplicitPlot but i don't know wether it is in mathematica4. i use mathematica5 << Graphics`ImplicitPlot` n = 3; ImplicitPlot[y^2 == x^3 + x + 1, {x, -n, n}] === Subject: Fedora 3 segmentation fault I'm using Fedora3 (on a Pentium3) and Mathematica 4.1. I'm getting lots of segmenations faults from the Kernel. Has anyone had a similar problem? Any suggestions on how to fix it? === Subject: Re: Fedora 3 segmentation fault http://support.wolfram.com/mathematica/systems/linux/general/selinux.html may help you. Jens cgi-bin schrieb | I'm using Fedora3 (on a Pentium3) and Mathematica 4.1. | I'm getting lots of segmenations faults from the Kernel. | | Has anyone had a similar problem? | Any suggestions on how to fix it? | === Subject: Convert to hypergeometric function How do you express the following function functions in terms of the hypergeometric function ? ExponentialIntegral Ei(x) LogarithmicIntegral Li(x) Trigonometric functions: sin(x) arcsin(x) cos(x) arccos(x) tan(x) arctan(x) cot(x) arccot(x) sec(x) arcsec(x) cosec(x) arccosec(x) Similarly the hyperbolic functions : sinh(x) cosh(x) tanh(x) ;;; arcsinh(x) arccosh(x) arctanh(x) The logarithmic function: log(1+x) or log(x) the gamma function : gamma(n) the lambert function : lambertW(n,x) PLEASE provide the solutions for all the above cases (if possible) === Subject: Re: Convert to hypergeometric function > How do you express the following function functions in terms of > the hypergeometric function ? > ExponentialIntegral Ei(x) Go to http://functions.wolfram.com/GammaBetaErf/ExpIntegralEi/ and click on the Representations through more general functions link. There you will find that a number of possible representations including ExpIntegralEi[z] == z HypergeometricPFQ[{1, 1}, {2, 2}, z] + (1/2) (Log[z] - Log[1/z]) + EulerGamma > LogarithmicIntegral Li(x) At http://functions.wolfram.com/06.36.26.0001.01 you will find that LogIntegral[z] == Log[z] HypergeometricPFQ[{1, 1}, {2, 2}, Log[z]] + (1/2) (Log[Log[z]] - Log[1/Log[z]]) + EulerGamma > Trigonometric functions: > sin(x) arcsin(x) > cos(x) arccos(x) > tan(x) arctan(x) > cot(x) arccot(x) > sec(x) arcsec(x) > cosec(x) arccosec(x) Similar answers for all these case. E.g., at http://functions.wolfram.com/01.10.26.0001.01 you will find that Csc[z] == 1/(z HypergeometricPFQ[{}, {3/2}, -(z^2/4)]) > Similarly the hyperbolic functions : sinh(x) cosh(x) tanh(x) ;;; > arcsinh(x) arccosh(x) arctanh(x) > The logarithmic function: log(1+x) or log(x) > the gamma function : gamma(n) > the lambert function : lambertW(n,x) > PLEASE provide the solutions for all the above cases (if possible) I expect that I don't need to go into details here ... 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 === Subject: Re: Convert to hypergeometric function sounds like a home work. Try it by your self, may be that http://functions.wolfram.com/ helps. Jens bd satish schrieb im | | How do you express the following function functions in terms of | the hypergeometric function ? | | ExponentialIntegral Ei(x) | LogarithmicIntegral Li(x) | | Trigonometric functions: | sin(x) arcsin(x) | cos(x) arccos(x) | tan(x) arctan(x) | cot(x) arccot(x) | sec(x) arcsec(x) | cosec(x) arccosec(x) | | Similarly the hyperbolic functions : sinh(x) cosh(x) tanh(x) ;;; | arcsinh(x) arccosh(x) arctanh(x) | | The logarithmic function: log(1+x) or log(x) | the gamma function : gamma(n) | the lambert function : lambertW(n,x) | | PLEASE provide the solutions for all the above cases (if possible) | | === Subject: Re: Rendering goes into infinite loop the graphics has several polygons that overlap complete. This cause Mathematicas painter algoritm to hang up because it can't split the polygons into non-overalping pices. Jens Steven T. Hatton schrieb im Newsbeitrag | The following is an example from _The Mathematica GuideBook for | Programming_, chapter 6. I made a few minor modification. For | one, I set the DisplayFunction->Identity. I also changed the | ViewPoint->{1.300, -2.400, 2.000}. It was originally | ViewPoint->{1, 1, 1}. With that value, I found the kernel | went into what appeared to be an infinite loop. I could kill | the kernel and get the front end back, but while the kernel ran, | I could not interact with the front end at all. I suspect this | is Linux specific. Could I get some people to test this to see | if there is a problem on other systems? | | I'm running SuSE 10 on a P4. The display manager doesn't seem to | be the problem. I tried different DMs and windown managers. | | In[1]:= GluedPolygons[n_Integer?(# >= 3&), | iter__Integer?(# >= 0&), faceShape:(Polygon | Line), | opts___Rule] := | Module[{c = N[Cos[[Alpha]]], s = N[Sin[[Alpha]]], myUnion, [ScriptR], [ScriptCapitalR], allm, argch, | makeHole, makeLine, [ScriptN] = #/Sqrt[#.#]&, [CurlyEpsilon] = 10^-6}, | myUnion[l_] := Union[l, SameTest -> ((Plus @@ (#.#& /@ (#1 - #2))) < [CurlyEpsilon]&)]; | | [ScriptR][point_, rotPoint_, {dir1_, dir2_, dir3_}] := | Module[{[Delta] = point - rotPoint, parallel, normal}, | parallel = [Delta].dir1 dir1; | normal = Sqrt[#.#]&[[Delta] - parallel]; | rotPoint + c normal dir2 + s normal dir3 + parallel]; | | [ScriptCapitalR][l_] := Module[{dir1, dir2, dir3}, | (* three orthogonal directions *) | dir1 = [ScriptN][Subtract @@ Take[l, 2]]; | dir2 = [ScriptN][(Plus @@ l)/Length[l] - (Plus @@ Take[l, 2])/2]; | dir3 = -Cross[dir1, dir2]; | Map[N[[ScriptR][#, l[[1]], {dir1, dir2, dir3}]]&, l, {-2}]]; | | allm[l_] := Table[RotateLeft[l, i], {i, Length[l] - 1}]; | argch[l_] := Join[Reverse[Take[l, 2]], Reverse[Drop[l, 2]]]; | | makeHole[l_] := | With[{mp = (Plus @@ l)/Length[l], h = Append[#, First[#]]&[l]}, | MapThread[Polygon[Join[#1, Reverse[#2]]]&, | {Partition[h, 2, 1], Partition[mp + 0.8(# - mp)& /@ h, 2, 1]}]]; | | makeLine[l_] := Line[Append[l, First[l]]]; | makeHole[#], makeLine[#]]& /@ | Join[{Table[N[{Cos[[CurlyPhi]], Sin[[CurlyPhi]], 0}], {[CurlyPhi], 0, 2Pi - 2Pi/n, 2Pi/n}]}, | | If[iter > 0, Flatten[NestList[myUnion[argch /@ ([ScriptCapitalR] /@ | Flatten[Join[allm /@ #], 1])]&, Join[argch /@ ([ScriptCapitalR] /@ #)]&[ | Table[Table[N[{Cos[[CurlyPhi]], Sin[[CurlyPhi]], 0}], | {[CurlyPhi], [CurlyPhi]0, [CurlyPhi]0 + 2Pi - 2Pi/n, 2Pi/n}], | {[CurlyPhi]0, 0, 2Pi - 2Pi/n, 2Pi/n}]], iter - 1], 1], {}]]], opts]] | | In[2]:= g = GluedPolygons[3, 0.729729, 4, Polygon, | Boxed -> False, | SphericalRegion -> True, | ViewPoint->{1.300, -2.400, 2.000}, | DisplayFunction -> Identity]; | | In[3]:= Show[g, DisplayFunction -> $DisplayFunction] | | -- | The Mathematica Wiki: http://www.mathematica-users.org/ | Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html | Math for the WWW: http://www.w3.org/Math/ | === Subject: Re: Rendering goes into infinite loop Same thing happens here. Yas > The following is an example from _The Mathematica GuideBook for > Programming_, chapter 6. I made a few minor modification. For > one, I set the DisplayFunction->Identity. I also changed the > ViewPoint->{1.300, -2.400, 2.000}. It was originally > ViewPoint->{1, 1, 1}. With that value, I found the kernel > went into what appeared to be an infinite loop. I could kill > the kernel and get the front end back, but while the kernel ran, > I could not interact with the front end at all. I suspect this > is Linux specific. Could I get some people to test this to see > if there is a problem on other systems? > I'm running SuSE 10 on a P4. The display manager doesn't seem to > be the problem. I tried different DMs and windown managers. > iter__Integer?(# >= 0&), faceShape:(Polygon | Line), > opts___Rule] := > Module[{c = N[Cos[[Alpha]]], s = N[Sin[[Alpha]]], myUnion, [ScriptR], [ScriptCapitalR], allm, argch, > makeHole, makeLine, [ScriptN] = #/Sqrt[#.#]&, [CurlyEpsilon] = 10^-6}, > myUnion[l_] := Union[l, SameTest -> ((Plus @@ (#.#& /@ (#1 - #2))) < [CurlyEpsilon]&)]; > [ScriptR][point_, rotPoint_, {dir1_, dir2_, dir3_}] := > Module[{[Delta] = point - rotPoint, parallel, normal}, > parallel = [Delta].dir1 dir1; > normal = Sqrt[#.#]&[[Delta] - parallel]; > rotPoint + c normal dir2 + s normal dir3 + parallel]; > [ScriptCapitalR][l_] := Module[{dir1, dir2, dir3}, > (* three orthogonal directions *) > dir1 = [ScriptN][Subtract @@ Take[l, 2]]; > dir2 = [ScriptN][(Plus @@ l)/Length[l] - (Plus @@ Take[l, 2])/2]; > dir3 = -Cross[dir1, dir2]; > Map[N[[ScriptR][#, l[[1]], {dir1, dir2, dir3}]]&, l, {-2}]]; > allm[l_] := Table[RotateLeft[l, i], {i, Length[l] - 1}]; > argch[l_] := Join[Reverse[Take[l, 2]], Reverse[Drop[l, 2]]]; > makeHole[l_] := > With[{mp = (Plus @@ l)/Length[l], h = Append[#, First[#]]&[l]}, > MapThread[Polygon[Join[#1, Reverse[#2]]]&, > {Partition[h, 2, 1], Partition[mp + 0.8(# - mp)& /@ h, 2, 1]}]]; > makeLine[l_] := Line[Append[l, First[l]]]; > Join[{Table[N[{Cos[[CurlyPhi]], Sin[[CurlyPhi]], 0}], {[CurlyPhi], 0, 2Pi - 2Pi/n, 2Pi/n}]}, > If[iter > 0, Flatten[NestList[myUnion[argch /@ ([ScriptCapitalR] /@ > Flatten[Join[allm /@ #], 1])]&, Join[argch /@ ([ScriptCapitalR] /@ #)]&[ > Table[Table[N[{Cos[[CurlyPhi]], Sin[[CurlyPhi]], 0}], > {[CurlyPhi], [CurlyPhi]0, [CurlyPhi]0 + 2Pi - 2Pi/n, 2Pi/n}], > {[CurlyPhi]0, 0, 2Pi - 2Pi/n, 2Pi/n}]], iter - 1], 1], {}]]], opts]] > In[2]:= g = GluedPolygons[3, 0.729729, 4, Polygon, > Boxed -> False, > SphericalRegion -> True, > ViewPoint->{1.300, -2.400, 2.000}, > DisplayFunction -> Identity]; > In[3]:= Show[g, DisplayFunction -> $DisplayFunction] > -- > The Mathematica Wiki: http://www.mathematica-users.org/ > Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html > Math for the WWW: http://www.w3.org/Math/ === Subject: Re: Re: Types in Mathematica I started this reply before seeing your conversations with Kris Carlson, he seems to have better elucidated the points I was trying to make. >> An example of a strong and >> dynamic language is LISP, and this is one respect in which >> Mathematica >> differs from LISP. > (setq f 1) > (setq g 2.2) > (setq h (+ f g)) > (print h) > =>3.2 It's been a while since I used LISP, fair enough. Whatever the case with respect to strong typing LISP is generally considered strong among computer scientists as far as I can tell. >> C is of course weak and static, Java is strong and >> static and that covers the four possibilities. > Java certainly supports primitive type conversion, so I don't > understand your > statement. Allowing type conversion isn't the issue (and real + int is a poor example) but we both agree it's a difficult concept to define unambiguously. It also seems it's aside from the general discussion, this thread does not appear to be about whether Mathematica is strong or weakly typed but about what a type is exactly in Mathematica. >> A List is most certainly not a Symbol, nor is it Complex, Integer, >> Real >> etc. A List is an expression whose Head is a Symbol with value List >> applied to zero or more arguments. Hence the idea that everything in >> Mathematica is an expression, that's really the only type that exists >> (and paradoxically in that sense Mathematica is strongly typed, >> but in >> a universe with only one type it is impossible to distinguish between >> strong and weak typing). > I don't agree with this. Fair enough but Head[{1,2,3}] is not Symbol. > One can say that 1 is an expression with head > Integer, but to say that expression is a data type is not much > different than > saying everything in C++ is a statement. There are different kinds of statements in C++ of which expressions are but one class (http://cpp.comsci.us/syntax/). There are no different kinds of expressions in Mathematica all have the same structure Head[Arguments...]. >> f[g[x_]] can be considered to be a function that acts on objects of >> type g. Since Mathematica is not strongly typed to ensure that we >> know >> the pattern x_ is to be considered of type g we have to explicitly >> include the information somewhere, and in Mathematica a convenient >> location is the head of an expression. It's not necessary to do it >> that way f[{g,x_}] also works and now the type g is represented as a >> list whose first element indicates its type. > How does that have superficial resemblance to the use of a type > system in > another language? Because there is no intrinsic type system to which I've added g in the sense that declaring a class in C++ adds an explicit new type to C ++ along with int, double etc. > What confusion? The confusion over exactly what constitutes a type in Mathematica. I will go out on a limb here and say there are two definitions of type in Mathematica. One is of what type entities (the word objects has too many connotations to use in this context) in Mathematica are, to which the answer is everything is an expression. The other definition is of how one defines a type hierarchy in Mathematica which defines objects and operations thereon, and the answer is there are multiple ways but the generally preferred way is to use the head of expressions to establish membership in the hierarchy. > What is the difference between associating a function with an > operator in C++ > and in Mathematica? You can't inspect the structure of the function in C++ because it's a function definition and there is no facility for programmatically inspecting the contents of a definition in C++. In Mathematica the contents are stored as an expression in the DownValues which can be modified as any other expression in Mathematica sans restrictions. >> Because C++ has well defined constructs called, statements, functions >> (or operators) and a host of types and a lot of rules explaining how >> they all interact. Mathematica has none of these. > You are making assertions which are contrary to the terminology > used to > discuss Mathematica. For the sake of brevity and in the correct context clarity, it helps to refer to things like Plus[a_,b_] as a function or operator and For [...] as a statement but the truth is in Mathematica they are both expressions and equivalent in that sense. Making the distinction may be useful to thinking about problems from the programmer's perspective but there is nothing within Mathematica itself that forces that distinction unlike in C++ where function+(a,b) and for (...){} are different. I suppose though that this discussion thread would be helped by examples of where some particular definition of type is both useful to the programmer and difficult to implement in Mathematica. Personally I have found that objects which require complicated state information are not trivial to use in Mathematica but I have usually found that using a different perspective often obviates the need for state in the first place. With respect to GUI like programs that don't lend themselves to the Notebook interface, this is not generally the case and as has been said many times on this list Mathematica is not suited to the writing of such programs. Ssezi === Subject: Re: Types in Mathematica > In[10]:= x_[s] ^:= Sin[x] > In[11]:= Pi[s] > Out[11]= 0 > Try defining an argument that operates on its function in any other > language. Of course few Mathematica programmers would do anything this > silly, and the Mathematica kernel contains many built in functions > that conform to the functional convention. Nevertheless, you can go off > the functional/procedural path in all sorts of interesting ways in > Mathematica, and these ways really don't have close analogs in other > languages. In OCaml, that could be written: let rewrite = function Apply(x, [Symbol s]) -> Apply(Sin, [x]) The difference is only that the underlying representation of an expression is exposed: f[x] is: Apply(Symbol f, [Symbol x]) -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html === Subject: Re: Re: Types in Mathematica > It also seems it's aside from the general discussion, > this thread does not appear to be about whether Mathematica is strong > or weakly typed but about what a type is exactly in Mathematica. Lets just say Mathematica is loosely typed, and leave that term loosely defined. > A List is most certainly not a Symbol, nor is it Complex, Integer, > Real > etc. A List is an expression whose Head is a Symbol with value List > applied to zero or more arguments. Hence the idea that everything in > Mathematica is an expression, that's really the only type that exists > (and paradoxically in that sense Mathematica is strongly typed, > but in > a universe with only one type it is impossible to distinguish between > strong and weak typing). >> I don't agree with this. > Fair enough but Head[{1,2,3}] is not Symbol. I would say that we have to be clear about what we mean by Head[{1,2,3}]. At one level, it is nothing but a sequence of characters. When Head[{1,2,3}] is evaluated, a downvalue is added to In In[1]:= Head[{1,2,3}] Out[1]= List In[2]:= DownValues[In] Out[2]= {HoldPattern[In[1]] :> Head[{1, 2, 3}], HoldPattern[In[2]] :> DownValues[In]} It *could* be that the character sequence Head[{1, 2, 3}] is stored in the symbol table entry for In with some mechanism used to indicate the things that really exist in Mathematica are symbols. A.9.2 in the 5.2 Mathematica Book says A Mathematica expression internally consists of a contiguous array of pointers, the first to the head, and the rest to its successive elements. I find that statement very incomplete. When I am finished typing Head[{1,2,3}], and before I evaluate it, it certainly does not have any internal representation in the kernel. The kernel need not be running at that point. After the input is evaluated, is there still an internal representation of the expression? Perhaps I am wrong about how the DownValues of In are stored. They may actually be expressions as described in the appendix. In any case, (I believe) the leaves of an expression will be atoms of one kind or another. The atoms are (AFAIK) the only entities in Mathematica which hold data. The only way to access an expression is through some symbol. Expressions are composite data structures which form trees whose subtrees are expressions, and whose leaves are atoms. Now, by definition an Atom is an expression, so you can say everything is an expression, but there are clearly different types of atomic expressions. >> One can say that 1 is an expression with head >> Integer, but to say that expression is a data type is not much >> different than >> saying everything in C++ is a statement. > There are different kinds of statements in C++ of which expressions > are but one class (http://cpp.comsci.us/syntax/). There are no > different kinds of expressions in Mathematica all have the same > structure Head[Arguments...]. How is that different from saying there are atomic expressions and composite expressions in Mathematica? Is 1 of the form Head[Arguments...]? You may be able to show that it is by playing with the definition for [Arguments...], but to my way of thingking, 1 just /is/. > f[g[x_]] can be considered to be a function that acts on objects of > type g. Since Mathematica is not strongly typed to ensure that we > know > the pattern x_ is to be considered of type g we have to explicitly > include the information somewhere, and in Mathematica a convenient > location is the head of an expression. It's not necessary to do it > that way f[{g,x_}] also works and now the type g is represented as a > list whose first element indicates its type. >> How does that have superficial resemblance to the use of a type >> system in >> another language? > Because there is no intrinsic type system to which I've added g in > the sense that declaring a class in C++ adds an explicit new type to C > ++ along with int, double etc. But that only says that whatever you did is not like C++ in so much as C++ has a formal definition of type, and Mathematica does not. It still doesn't tell me how it has any resemblance to a type in C++. I can create a pseudo type system in C++. It is not uncommon to find code that uses such a mechanism, rather than using the builtin type mechanism. >> What confusion? > The confusion over exactly what constitutes a type in Mathematica. Since there is no formal definition, it is strictly a matter of opinion, and/or convention. Since there seems to be little in the way of commonly agreed upon convention, we are stuck with relying on opinion. >> What is the difference between associating a function with an >> operator in C++ >> and in Mathematica? > You can't inspect the structure of the function in C++ because it's a > function definition and there is no facility for programmatically > inspecting the contents of a definition in C++. In Mathematica the > contents are stored as an expression in the DownValues which can be > modified as any other expression in Mathematica sans restrictions. But that really seems to rely on the fact that C++ is a compiled language, whereas Mathematica is interpreted. That is certainly an important distinction. I'm not sure why that distinction would be any more significant when dealing with operators than in any other context. I believe there are important distinction between the way C++ and Mathematica support operator overloading. > Because C++ has well defined constructs called, statements, functions > (or operators) and a host of types and a lot of rules explaining how > they all interact. Mathematica has none of these. >> You are making assertions which are contrary to the terminology >> used to >> discuss Mathematica. > For the sake of brevity and in the correct context clarity, it helps > to refer to things like Plus[a_,b_] as a function or operator and For > [...] as a statement but the truth is in Mathematica they are both > expressions and equivalent in that sense. Making the distinction may > be useful to thinking about problems from the programmer's > perspective but there is nothing within Mathematica itself that > forces that distinction unlike in C++ where function+(a,b) and for > (...){} are different. I don't follow. I can write a function Vector3f plus(const Vecotr3f& v1, const Vecotr3f& v1) { return Vector3f(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z); } and Vector3f operaotr+(const Vecotr3f& v1, const Vecotr3f& v1) { return plus(v1,v2); } Then write va + vb to add two Vector3f objects. How does that compare to overloading + in Mathematica? > I suppose though that this discussion thread would be helped by > examples of where some particular definition of type is both useful > to the programmer and difficult to implement in Mathematica. > Personally I have found that objects which require complicated state > information are not trivial to use in Mathematica but I have usually > found that using a different perspective often obviates the need for > state in the first place. With respect to GUI like programs that > don't lend themselves to the Notebook interface, this is not > generally the case and as has been said many times on this list > Mathematica is not suited to the writing of such programs. When trying to represent an ensamble of interacting physical objects, I find it useful to be able to maintain state. In OOP that is fairly straightforward. This is why I like development libraries such as OpenSceneGraph. I've done similar things with Mathematica, but it has not been quite as easy. Part of the problem is that I really didn't understand Mathematica well when I started using things such as Dr. Maeder's Classes package. -- The Mathematica Wiki: http://www.mathematica-users.org/ Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html Math for the WWW: http://www.w3.org/Math/ === Subject: inequations Can somebody help me with this Inequation? (( 2*Sin [a] ) / (3*Pi / 4 ) -a ) +1 -d >= 0 I need solve for a, but i can't found any function or easy form for solve. === Subject: Re: inequations > Can somebody help me with this Inequation? > (( 2*Sin [a] ) / (3*Pi / 4 ) -a ) +1 -d >= 0 > I need solve for a, but i can't found any function or easy form for solve. An obvious choice would be the function *Reduce*, unfortunately it fails to solve the inequality: In[1]:= expr = ((2*Sin[a])/(3*(Pi/4)) - a) + 1 - d; In[2]:= Reduce[expr >= 0, a] Reduce::nsmet: This system cannot be solved with the methods available to Reduce. More... Out[2]= Reduce[1 - a - d + (8*Sin[a])/(3*Pi) >= 0, a] Therefore, you might be on your own to find a general formula. Studying some particular cases by giving some values to the parameter d and plating the graph of the functions f(a) = 1 - a - d + (8*Sin[a])/(3*Pi) and y = d should help visualizing what's going on (f{a} is decreasing on R and we are interested in the intersection point of f(a) and the horizontal straight line y = d. Then, the required value of a are on the left of the graph). You could try In[3]:= Plot[{expr /. d -> 1, 1}, {a, -10, 10}]; or the following one that gives a family of intersecting curves and their intersection points: In[4]:= Needs[Graphics`Graphics`] Plot[Evaluate[Table[{expr /. d -> n, n}, {n, -5, 5}]], {a, -10, 10}, PlotStyle -> {{Red}, {Blue, Dashing[{0.015}]}}, ImageSize -> 500, Frame -> True, FrameTicks -> {UnitScale[-3*Pi, 3*Pi, 8/(3*Pi)], Automatic, None, None}, Axes -> None, Epilog -> {PointSize[0.015], Point /@ Table[{a /. FindRoot[expr == n /. d -> n, {a, -n}], n}, {n, -5, 5}]}]; Hope this helps, /J.M. === Subject: Re: A question about algebraic numbers using Mathematica >>What about the following (I have thought more about the question)? >>Since in my case of interest the quartic q(x) and 2-x are irreducible >>over Q we must have that GCD[q(x),2-x] = 1 so there exist >>polynomials u >>and v such that u q + v (2-x) = 1. >>Since u is constant (the degree of u < the degree 2-x) and q(r) = 0 we >>have that v(2-r) = 1, so >>v is the inverse of 2-r in Q[r]. Is this an easier way of determing >>the >>inverse of 2-r? >>By the way, could you provide me with the inverse of 2c-r? > Yes, you are right of course, but I think you would want Mathematica > do this for you? Mathematica has a function PolynomialExtendedGCD in > the package Algebra`PolynomialExtendedGCD` and this function will do > exactly what you need when a,b and c are integers but will not work > with symbols. So although mathematically your argument is correct, I > do not think Mathematica can be of help in this. This will work after the next release. < As for your last question, I think it can be done in the same way. > Here are all the steps again: > First define the polynomial: > In[1]:= > poly = r^4 - 2*c*r^3 + (c^2 - 2*a^2)*r^2 + 2*a^2*c*r - > a^2*c^2; > Next find the polynomial poly1 satisfied by (2c -r): > In[2]:= > poly1 = First[GroebnerBasis[{poly, v - (2*c - r)}, > {a, b, c, v}, {r}]] > Out[2]= > 4*c^4 - 12*v*c^3 - 5*a^2*c^2 + 13*v^2*c^2 - 6*v^3*c + > 6*a^2*v*c + v^4 - 2*a^2*v^2 > Next find the part free of v: > In[3]:= > free = poly1 /. v -> 0 > Out[3]= > 4*c^4 - 5*a^2*c^2 > The polynomial q below is our inverse: > In[4]:= > poly2 = Cancel[(poly1 - free)/v] > Out[4]= > -12*c^3 + 13*v*c^2 + 6*a^2*c - 6*v^2*c + v^3 - 2*a^2*v > In[5]:= > q = Expand[poly2 /. v -> 2*c - r]/free > Out[5]= > (-2*c^3 - r*c^2 + 2*a^2*c - r^3 + 2*a^2*r)/ > (4*c^4 - 5*a^2*c^2) > Finally, we check that it really is the inverse, that is, that q*(2c - > r) gives remainder 1 on division by poly: > In[6]:= > FullSimplify[PolynomialReduce[q*(2*c - r), poly, r]] > Out[6]= > {{1/(c^2*(4*c^2 - 5*a^2))}, -1} > Somehow I got -1 so the inverse is actually -q. (However as it is > already after midnight here I shall leave it at that). > Andrzej Kozlowski > [...] The GroebnerBasis approach is a bit easier if one works with v*(2*c-r)-1 as a generator. In[12]:= InputForm[v2 = vv /. First[Solve[GroebnerBasis[{poly, vv*(2*c - r)-1}, {vv,r}, CoefficientDomain->RationalFunctions][[2]]==0, vv]]] Out[12]//InputForm= -((2*a^2*c - 2*c^3 + 2*a^2*r - c^2*r - r^3)/(c^2*(-5*a^2 + 4*c^2))) We check that this agrees with our previous result. In[13]:= Together[v2-v] Out[13]= 0 This method is basically how the Algebra` add-on function PolynomialPowerMod does negative powers. Daniel Lichtblau Wolfram Research === Subject: Re: A question about algebraic numbers using Mathematica >>I want to find the inverse of 2 - r in Q[r] where r is a root of the equation >>x^4 - 2c x^3 + (c^2 - 2a^2) x^2 + 2a^2 c x - a^2 c^2 = 0 for a, b and c integers. >>Can this be done for general a, b and c? (I know how to do it for specific given numerical values of a, b and c.) >>Kent Holing > < InputForm[PolynomialPowerMod[2 - x, -1, x, > {x^4 - 2*c*x^3 + (c^2-2*a^2)*x^2 + 2*a^2*c*x - a^2*c^2, 0}]] > Out[5]//InputForm= > PolynomialPowerMod[2 - x, -1, x, > {-(a^2*c^2) + 2*a^2*c*x + (-2*a^2 + c^2)*x^2 - 2*c*x^3 + x^4, 0}] > Daniel Lichtblau > Wolfram Research Let me try that again. In[7]:= InputForm[inv = PolynomialPowerMod[2 - x, -1, x, {x^4 - 2*c*x^3 + (c^2-2*a^2)*x^2 + 2*a^2*c*x - a^2*c^2, 0}]] Out[7]//InputForm= (-8 + 4*a^2 + 8*c - 2*a^2*c - 2*c^2 - 4*x + 2*a^2*x + 4*c*x - c^2*x - 2*x^2 + 2*c*x^2 - x^3)/ (-16 + 8*a^2 + 16*c - 4*a^2*c - 4*c^2 + a^2*c^2) Let's check the result this time. In[9]:= PolynomialMod[inv*(2-x), x^4 - 2*c*x^3 + (c^2-2*a^2)*x^2 + 2*a^2*c*x - a^2*c^2] Out[9]= 1 Daniel Lichtblau Wolfram Research === Subject: Re: A question about algebraic numbers using Mathematica > I want to find the inverse of 2 - r in Q[r] where r is a root of the equation > x^4 - 2c x^3 + (c^2 - 2a^2) x^2 + 2a^2 c x - a^2 c^2 = 0 for a, b and c integers. > Can this be done for general a, b and c? (I know how to do it for specific given numerical values of a, b and c.) > Kent Holing < What about the following (I have thought more about the question)? > Since in my case of interest the quartic q(x) and 2-x are irreducible > over Q we must have that GCD[q(x),2-x] = 1 so there exist > polynomials u > and v such that u q + v (2-x) = 1. > Since u is constant (the degree of u < the degree 2-x) and q(r) = 0 we > have that v(2-r) = 1, so > v is the inverse of 2-r in Q[r]. Is this an easier way of determing > the > inverse of 2-r? > By the way, could you provide me with the inverse of 2c-r? Yes, you are right of course, but I think you would want Mathematica do this for you? Mathematica has a function PolynomialExtendedGCD in the package Algebra`PolynomialExtendedGCD` and this function will do exactly what you need when a,b and c are integers but will not work with symbols. So although mathematically your argument is correct, I do not think Mathematica can be of help in this. As for your last question, I think it can be done in the same way. Here are all the steps again: First define the polynomial: In[1]:= poly = r^4 - 2*c*r^3 + (c^2 - 2*a^2)*r^2 + 2*a^2*c*r - a^2*c^2; Next find the polynomial poly1 satisfied by (2c -r): In[2]:= poly1 = First[GroebnerBasis[{poly, v - (2*c - r)}, {a, b, c, v}, {r}]] Out[2]= 4*c^4 - 12*v*c^3 - 5*a^2*c^2 + 13*v^2*c^2 - 6*v^3*c + 6*a^2*v*c + v^4 - 2*a^2*v^2 Next find the part free of v: In[3]:= free = poly1 /. v -> 0 Out[3]= 4*c^4 - 5*a^2*c^2 The polynomial q below is our inverse: In[4]:= poly2 = Cancel[(poly1 - free)/v] Out[4]= -12*c^3 + 13*v*c^2 + 6*a^2*c - 6*v^2*c + v^3 - 2*a^2*v In[5]:= q = Expand[poly2 /. v -> 2*c - r]/free Out[5]= (-2*c^3 - r*c^2 + 2*a^2*c - r^3 + 2*a^2*r)/ (4*c^4 - 5*a^2*c^2) Finally, we check that it really is the inverse, that is, that q*(2c - r) gives remainder 1 on division by poly: In[6]:= FullSimplify[PolynomialReduce[q*(2*c - r), poly, r]] Out[6]= {{1/(c^2*(4*c^2 - 5*a^2))}, -1} Somehow I got -1 so the inverse is actually -q. (However as it is already after midnight here I shall leave it at that). Andrzej Kozlowski > -----Original Message----- === > Subject: Re: A question about algebraic numbers using > Mathematica >> I want to find the inverse of 2 - r in Q[r] where r is a root of the >> equation >> x^4 - 2c x^3 + (c^2 - 2a^2) x^2 + 2a^2 c x - a^2 c^2 = 0 for a, b and >> c integers. >> Can this be done for general a, b and c? (I know how to do it for >> specific given numerical values of a, b and c.) >> Kent Holing > I think this can be done using Groebner basis. Suppose r satisfies the > above equation and let v be 2-r. Let us first find the algebraic > equation satisfied by v. > In[1]:= > poly1 = First[GroebnerBasis[{r^4 - 2*c*r^3 + (c^2 - 2*a^2)*r^2 + > 2*a^2*c*r - a^2*c^2, v - (2 - r)}, {a, b, c, v}, > {r}]] > Out[1]= > v^4 + 2*c*v^3 - 8*v^3 - 2*a^2*v^2 + c^2*v^2 - 12*c*v^2 + 24*v^2 + > 8*a^2*v - 4*c^2*v - 2*a^2*c*v + 24*c*v - 32*v - > 8*a^2 - a^2*c^2 + 4*c^2 + 4*a^2*c - 16*c + 16 > polynomial in > v with rational coefficients, and by substituting 2-r for v we can > also > get a polynomial in r. We proceed as follows. First we find the free > term (not involving v) in poly1: > In[2]:= > free = poly1 /. v -> 0 > Out[2]= > (-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16 > Next we subtract the free term from poly1 and divide by v: > In[3]:= > poly2 = Cancel[(poly1 - free)/v] > Out[3]= > v^3 + 2*c*v^2 - 8*v^2 - 2*a^2*v + c^2*v - 12*c*v + 24*v + 8*a^2 - > 4*c^2 - 2*a^2*c + 24*c - 32 > Now substitute 2-r for v: > In[4]:= > q = Expand[poly2 /. v -> 2 - r] > Out[4]= > -r^3 + 2*c*r^2 - 2*r^2 + 2*a^2*r - c^2*r + 4*c*r - 4*r + 4*a^2 - > 2*c^2 - 2*a^2*c + 8*c - 8 > The inverse ought to be the polynomial poly3 given by: > In[5]:= > poly3 = Expand[(q/free)*(r - 2)] > Out[5]= > -(r^4/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16)) + > (2*c*r^3)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) + > (2*a^2*r^2)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) - > (c^2*r^2)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) - > (2*a^2*c*r)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) - > (8*a^2)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) + > (4*c^2)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) + > (4*a^2*c)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) - > (16*c)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) + 16/((- > c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) > Finally we check that this is indeed the inverse of r-2 modulo the > original polynomial p: > In[6]:= > FullSimplify[PolynomialReduce[poly3, r^4 - 2*c*r^3 + (c^2 - 2*a^2) > *r^2 + 2*a^2*c*r - a^2*c^2, r]] > Out[6]= > {{1/(a^2*((c - 4)*c + 8) - 4*(c - 2)^2)}, 1} > We get the remainder 1, as we should. > Andrzej Kozlowski > ------------------------------------------------------------------- > The information contained in this message may be CONFIDENTIAL and is > intended for the addressee only. Any unauthorised use, > dissemination of the > information or copying of this message is prohibited. If you are > not the > addressee, please notify the sender immediately by return e-mail > and delete > this message. === Subject: Re: A question about algebraic numbers using Mathematica >> I want to find the inverse of 2 - r in Q[r] where r is a root of >> the equation >> x^4 - 2c x^3 + (c^2 - 2a^2) x^2 + 2a^2 c x - a^2 c^2 = 0 for a, b >> and c integers. >> Can this be done for general a, b and c? (I know how to do it for >> specific given numerical values of a, b and c.) >> Kent Holing > I think this can be done using Groebner basis. Suppose r satisfies > the above equation and let v be 2-r. Let us first find the > algebraic equation satisfied by v. > In[1]:= > poly1 = First[GroebnerBasis[{r^4 - 2*c*r^3 + (c^2 - 2*a^2)*r^2 + > 2*a^2*c*r - a^2*c^2, v - (2 - r)}, {a, b, c, v}, > {r}]] > Out[1]= > v^4 + 2*c*v^3 - 8*v^3 - 2*a^2*v^2 + c^2*v^2 - 12*c*v^2 + 24*v^2 + > 8*a^2*v - 4*c^2*v - 2*a^2*c*v + 24*c*v - 32*v - > 8*a^2 - a^2*c^2 + 4*c^2 + 4*a^2*c - 16*c + 16 > polynomial in v with rational coefficients, and by substituting 2-r > for v we can also get a polynomial in r. We proceed as follows. > First we find the free term (not involving v) in poly1: > In[2]:= > free = poly1 /. v -> 0 > Out[2]= > (-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16 > Next we subtract the free term from poly1 and divide by v: > In[3]:= > poly2 = Cancel[(poly1 - free)/v] > Out[3]= > v^3 + 2*c*v^2 - 8*v^2 - 2*a^2*v + c^2*v - 12*c*v + 24*v + 8*a^2 - > 4*c^2 - 2*a^2*c + 24*c - 32 > Now substitute 2-r for v: > In[4]:= > q = Expand[poly2 /. v -> 2 - r] > Out[4]= > -r^3 + 2*c*r^2 - 2*r^2 + 2*a^2*r - c^2*r + 4*c*r - 4*r + 4*a^2 - > 2*c^2 - 2*a^2*c + 8*c - 8 > The inverse ought to be the polynomial poly3 given by: > In[5]:= > poly3 = Expand[(q/free)*(r - 2)] > Out[5]= > -(r^4/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16)) + > (2*c*r^3)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) + > (2*a^2*r^2)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) - > (c^2*r^2)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) - > (2*a^2*c*r)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) - > (8*a^2)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) + > (4*c^2)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) + > (4*a^2*c)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) - > (16*c)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) + 16/((- > c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) > Finally we check that this is indeed the inverse of r-2 modulo the > original polynomial p: > In[6]:= > FullSimplify[PolynomialReduce[poly3, r^4 - 2*c*r^3 + (c^2 - 2*a^2) > *r^2 + 2*a^2*c*r - a^2*c^2, r]] > Out[6]= > {{1/(a^2*((c - 4)*c + 8) - 4*(c - 2)^2)}, 1} > We get the remainder 1, as we should. > Andrzej Kozlowski Sorry, I got confused near the end. The inverse of (r-2) is of course the polynomial inv=q/free above. The last part of the argument shows that this polynomial ( inv) is the inverse of (r-2) modulo the original polynomial in r. === Subject: Re: A question about algebraic numbers using Mathematica > I want to find the inverse of 2 - r in Q[r] where r is a root of > the equation > x^4 - 2c x^3 + (c^2 - 2a^2) x^2 + 2a^2 c x - a^2 c^2 = 0 for a, b > and c integers. > Can this be done for general a, b and c? (I know how to do it for > specific given numerical values of a, b and c.) > Kent Holing I think this can be done using Groebner basis. Suppose r satisfies the above equation and let v be 2-r. Let us first find the algebraic equation satisfied by v. In[1]:= poly1 = First[GroebnerBasis[{r^4 - 2*c*r^3 + (c^2 - 2*a^2)*r^2 + 2*a^2*c*r - a^2*c^2, v - (2 - r)}, {a, b, c, v}, {r}]] Out[1]= v^4 + 2*c*v^3 - 8*v^3 - 2*a^2*v^2 + c^2*v^2 - 12*c*v^2 + 24*v^2 + 8*a^2*v - 4*c^2*v - 2*a^2*c*v + 24*c*v - 32*v - 8*a^2 - a^2*c^2 + 4*c^2 + 4*a^2*c - 16*c + 16 in v with rational coefficients, and by substituting 2-r for v we can also get a polynomial in r. We proceed as follows. First we find the free term (not involving v) in poly1: In[2]:= free = poly1 /. v -> 0 Out[2]= (-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16 Next we subtract the free term from poly1 and divide by v: In[3]:= poly2 = Cancel[(poly1 - free)/v] Out[3]= v^3 + 2*c*v^2 - 8*v^2 - 2*a^2*v + c^2*v - 12*c*v + 24*v + 8*a^2 - 4*c^2 - 2*a^2*c + 24*c - 32 Now substitute 2-r for v: In[4]:= q = Expand[poly2 /. v -> 2 - r] Out[4]= -r^3 + 2*c*r^2 - 2*r^2 + 2*a^2*r - c^2*r + 4*c*r - 4*r + 4*a^2 - 2*c^2 - 2*a^2*c + 8*c - 8 The inverse ought to be the polynomial poly3 given by: In[5]:= poly3 = Expand[(q/free)*(r - 2)] Out[5]= -(r^4/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16)) + (2*c*r^3)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) + (2*a^2*r^2)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) - (c^2*r^2)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) - (2*a^2*c*r)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) - (8*a^2)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) + (4*c^2)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) + (4*a^2*c)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) - (16*c)/((-c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) + 16/((- c^2)*a^2 + 4*c*a^2 - 8*a^2 + 4*c^2 - 16*c + 16) Finally we check that this is indeed the inverse of r-2 modulo the original polynomial p: In[6]:= FullSimplify[PolynomialReduce[poly3, r^4 - 2*c*r^3 + (c^2 - 2*a^2) *r^2 + 2*a^2*c*r - a^2*c^2, r]] Out[6]= {{1/(a^2*((c - 4)*c + 8) - 4*(c - 2)^2)}, 1} We get the remainder 1, as we should. Andrzej Kozlowski === Subject: A question about algebraic numbers using Mathematica I want to find the inverse of 2 - r in Q[r] where r is a root of the equation x^4 - 2c x^3 + (c^2 - 2a^2) x^2 + 2a^2 c x - a^2 c^2 = 0 for a, b and c integers. Can this be done for general a, b and c? (I know how to do it for specific given numerical values of a, b and c.) Kent Holing === Subject: Re: A question about algebraic numbers using Mathematica Hi Kent, I assume by Q[r] you mean the field extension of the rationals by r. Because of the extension field minimal polynomial p[x]: x^4 - 2c x^3 + (c^2 - 2a^2) x^2 + 2a^2 c x - a^2 c^2 p[r]==0 r^4 can be written as r^4== -(- 2c x^3 + (c^2 - 2a^2) x^2 + 2a^2 c x - a^2 c^2) This shows that all numbers can be written as polynomials in r with dgeree <=3. Therefore, to get the inverse of 2-r we need to determine a number y: y= y0 + y1 r + y2 r^2 + y3 r^3 so that y (2-r) ==1 or y(2-r)-1 ==0 Towards this aim, we multiply and expand y(2-r)-1, then replace r^4 by lower powers and finally collect coefficients of factors of r: y= y0 + y1 r + y2 r^2 + y3 r^3; rep= r^4-> -(- 2c r^3 + (c^2 - 2a^2) r^2 + 2a^2 c r - a^2 c^2); res1= CoefficientList[Expand[y (2-r)-1] /. rep ,r] Now, because of y(2-r)-1 ==0, all these coefficients must er zero: Solve[ Thread[res1=={0,0,0,0}], {y0,y1,y2,y3} ] this gives the inverse of 2-r Daniel > I want to find the inverse of 2 - r in Q[r] where r is a root of the equation > x^4 - 2c x^3 + (c^2 - 2a^2) x^2 + 2a^2 c x - a^2 c^2 = 0 for a, b and c integers. > Can this be done for general a, b and c? (I know how to do it for specific given numerical values of a, b and c.) > Kent Holing === Subject: Re: Types in Mathematica, a practical example I like to use Array when I want a variable to be treated as a matrix. [[Expression:||| Array[x,{2,2}] |||]] This is probably not what you want since the output is a nested list. This is not the same as declaring a variable as a matrix. But now, this approach works: [[Expression:||| a={{1,2},{3,4}}|||]] [[Expression:||| Array[x,{2,2}] - a /. x[k__]:>a[[k]] |||]] Link to the forum page for this post: http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=Speci al:Forum_ViewTopic&pid=6675#p6675 === Subject: Re: Extracting just the value of the variable from the result of Solve/NDSolve Pradeep, Try First. eqn = {F == 2*T}; T = 300; sol = First@Solve[eqn, F]; F /. sol 600 David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Hi all, i am facing a peculiar problem with the curly brackets of the output of Solve and NDsolve commands....the result of Solve/NSolve/DSolve/NDSolve all are in the form of {{y->a}} format and at best by doing a y/.soln, i can get it to {a}, but for my purposes of passing this result to JAVA(using J/Link), i need the value of the variable as just 'a' and not '{a}'(i hope i am making myself clear). E.g. eqn={F==2*T}; T = 300; sol = Solve[eqn, F] F /. sol gives me {600}, as i said earlier i need the answer 600(which is different in datatype compared to {600} even though for all practical purposes {600} is the same as 600). When i use J/link to extract value, the {600} is not considered an integer/string/double/function,...so i cannnot use getInteger,getString etc. Can someone plz suggest a solution this problem, however triveal as it may sound, it is an important problem in using J/Link to talk with Mathematica. Pradeep === Subject: Re: Threading 'Append' What about... MapThread[Join[#1, {#2}] &, {{{1, 2}, {3, 4}, {5, 6}}, {a, b, c}}] {{1, 2, a}, {3, 4, b}, {5, 6, c}} David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ If I run Thread[Append[{{1,2},{3,4},{5,6}},{a,b,c}]] I would expect to get {{1,2,a},{3,4,b},{5,6,c}} but in fact I get an 'Objects of unequal length' error. On the other hand, Thread[foo[{{1,2},{3,4},{5,6}},{a,b,c}]] %/.foo->Append gives what I wanted. Can someone explain what's going on? === Subject: Re: Threading 'Append' Thread doesn't hold its arguments, and Append gives: In[1]:= Append[{{1,2},{3,4},{5,6}},{a,b,c}] Out[1]= {{1, 2}, {3, 4}, {5, 6}, {a, b, c}} One way to do what you want is: In[2]:= list1 = {{1,2},{3,4},{5,6}}; In[3]:= list2 = {a,b,c}; In[4]:= Transpose[Append[Transpose[list1],list2]] Out[4]= {{1, 2, a}, {3, 4, b}, {5, 6, c}} Bhuvanesh, Wolfram Research. === Subject: Re: Types in Mathematica > I believe most people here will agree that Mathematica is not a strongly > typed programming language. Actually, one can productively say that Mathematica is a strongly typed language because it has only one type (expr). Indeed, this is an important observation about Mathematica and separates it from many other languages. > What would a type system in Mathematica be? Anything you want. > What might be gained by having a type system in Mathematica? Performance, correctness. > What might be lost? Simplicity, brevity, clarity. > To what extent /does/ Mathematica have a type system? Results of the Compile function do some run-time type checking (e.g. for machine-size real input). Many other built-in functions check the types of their arguments but that is slightly different to conventional dynamic type checking. > To what extent can a type system be implemented within Mathematica without > modifying the language? Entirely. Because Mathematica is a rewrite system, it is comparatively easy to write interpreters and compilers in it (compared to C, for example). As a type system and, more importantly, a type checker is part of a compiler/interpreter, these can be written in Mathematica. > How would a type system in Mathematica be similar to one in another > language? You could write a type checking function to type check Mathematica programs. This could mimic an ML-like type system, for example. > How would a type system in Mathematica differ from one in another > language? It would be optional because it is not fundamental to the language. To improve performance, the use of a more refined type system could be entirely automated and invisible to the user. To improve correctness, the type system must be exposed to the user in the form of static type errors. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html === Subject: Re: Types in Mathematica >> I believe most people here will agree that Mathematica is not a strongly >> typed programming language. > Actually, one can productively say that Mathematica is a strongly typed > language because it has only one type (expr). Is that assertion really meaningful or useful? >> What would a type system in Mathematica be? > Anything you want. What would a _useful_ type system in Mathematica be? >> What might be gained by having a type system in Mathematica? > Performance, correctness. >> What might be lost? > Simplicity, brevity, clarity. It might be argued that these could be increased in some circumstance by having a type system. Likewise, performance might take a hit from extensive typechecking. >> To what extent /does/ Mathematica have a type system? > Results of the Compile function do some run-time type checking (e.g. for > machine-size real input). Many other built-in functions check the types > of their arguments but that is slightly different to conventional dynamic > type checking. When I think about dynamic type checking, I think about determining the actual type of an object referred to by a variable referring to a basetype of multiple derived types. I can imagine circumstances where such a feature might be useful in Mathematica. The example of testing to determine if some object represents a real number was intended to suggest this. An integer is a real number, as is a rational number. That is an is a relation in OOP terminology, and thus implies an inheritance hierarchy. >> To what extent can a type system be implemented within Mathematica >> without modifying the language? > Entirely. > Because Mathematica is a rewrite system, it is comparatively easy to write > interpreters and compilers in it (compared to C, for example). I can certainly imagine writing a C++ parser in Mathematica, but that makes assumptions about the input. In particular, that it is written in C++ which already has a type system defined. > As a type > system and, more importantly, a type checker is part of a > compiler/interpreter, these can be written in Mathematica. Yes, but see my previous comment. You would need a means of expressing types in Mathematica in order to check them. >> How would a type system in Mathematica be similar to one in another >> language? > You could write a type checking function to type check Mathematica > programs. This could mimic an ML-like type system, for example. I have wanted to study ML for a long time, but I have to plead virtual ignorance here. >> How would a type system in Mathematica differ from one in another >> language? > It would be optional because it is not fundamental to the language. > To improve performance, the use of a more refined type system could be > entirely automated and invisible to the user. One aspect of comparing Mathematica to compiled languages in the area of type checking is that compiled languages typically do their type checking at compile time. Yes, dynamic type checking can happen at runtime, but that already assumes certain compile time checking has been performed. Furthermore, dynamic type checking usually incurs a performance hit. If there were typechecking in Mathematica, that could mean a test is perfromed for every parameter each time a function is evaluated. Ironically, in C++, it appears that functional programming constructs tend to be slower than procedural ones. In Mathematica, the opposite appears to be the case. The same may be true of type checking. > To improve correctness, the type system must be exposed to the user in the > form of static type errors. One thing I've noticed about Mathematica regarding errors is that, for the most part, errors do not halt evaluation. In compiled languages, a type checking error will halt compilation. There are such constructs as Throw and Catch in Mathematica, but I'm not convinced of their usefulness. -- The Mathematica Wiki: http://www.mathematica-users.org/ Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html Math for the WWW: http://www.w3.org/Math/ === Subject: Re: Re: Types in Mathematica > 5. If I am extending built-in or user-defined functions (like Plus), > should I restrict users to using a constructor to do that, or extend > the existing function in the context of my data type with an upvalue? I'm not sure what you mean here. Can you provide examples? > it as extending Part with an upvalue to extract the numerator or > denominator of a rational number (created as a new datatype as an > exercise from M220 the programming course), I can see the other point > of view--not allowing Part to do this. > .... > The datatype is rational[n_Integer, d_Integer] with n and d > type-checked as integers .... > makeRational[n_Integer, 0] := > Print[This rational is undefined.] (* better than just getting > input back as output *) > conversion; for a negative denominator, it calls the function again > and just reverses the signs of the numerator and denominator; that way > negative rationals are always in the format rational[-n, d] *) > makeRational[n_Integer, d_Integer?Negative] := makeRational[-n, d] > ... > denominator::denominator will extract the denominator of the > rational. You can also use Part[ rational ] , which has been modified > to work correctly in the context of this package. > ... > rational /: (r_rational)[[1]] := numerator[r]; (* numerator is the > constructor *) > rational /: (r_rational)[[2]] := denominator[r]; (* denominator is the > constructor *) expressions? -- The Mathematica Wiki: http://www.mathematica-users.org/ Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html Math for the WWW: http://www.w3.org/Math/ === Subject: Re: Re: Types in Mathematica encountered the result of my doing something something foolish. I had updated several of the packages in the prerelease KDE I run, and didn't bother to restart X when I finished. X locked up, and I lost the message. What's below is quite different from the original message. [snip, ain't gonna touch that] > When considering data typing in Mathematica, the thought process > should go something like this: > 1. What is my purpose in typing? It would be interesting to enumerate the reasons for using data types in various languages. Here are a few uses of data types off the top of my head; mostly in terms of C++. 1) A self-commenting code. 2) Validity checking. 3) Control over lowlevel performance issues. 4) Representing abstract structures. (user defined types, i.e., classes) 5) Representing specific types of real world objects. (also classes) 6) Statefull functions. (Function objects) 8) Function overloading. 9)... I'm sure there is a lot that can be said about all of the above, and I am also sure it is not exhaustive. > 2. Are there built-in types or type filters or converters that I can > use? (There are a bunch) We do have something of a problem determining what we mean by built-in types, etc. Since Mathematica does not have a formal specification, much less a formal definition of what a type is, it really reduces to a matter of opinion as to what is, or is not a type. > 3. Should I create my own data type? (Easy to do) I'm still uncommitted regarding how easy it is to create data types with associated operations in such a way as to be less trouble than they are worth. Some of this certainly depends on the kind of application you are working on. It makes little sense to create an intricate data type which will only be used once or twice. > 4. Should I create an automatic type converter using pattern matching > and rules? (A little more complicated to get the syntax to work, but > still eminently doable and eminently flexible) I have come to realize that there are (or appear to be) certain limitations as to what can be done with type conversions in comparison to how they are used in C++. For example, in C++ it is possible to create type conversion operators which will be invoked according to the parameters accepted by a function. For example, you might have some kind of counter object which automatically converts to an integer when passed as a variable of integer type. I don't believe I could do something similar with Mathematica. For instance, if I have a type Vector3D[x,y,z], I don't see a way of getting that to convert to a List[x,y,z] when passed to an arbitrary function taking a List as an argument. > Or should I default to > Mathematica's implicit error message of getting back my input > unaltered? Or should I add an error message? I believe it would be possible to have a catchall signature that generates a message if none of the intended patterns (signatures) are matched. > 5. If I am extending built-in or user-defined functions (like Plus), > should I restrict users to using a constructor to do that, or extend > the existing function in the context of my data type with an upvalue? I'm not sure what you mean by restrict users to using a constructor to do that. Care you explain? [Note: I read what follows, and I'm still a bit unsure what is meant.] > This last is a philosophical discussion; harry calkins of the > Education Group believes we should always use constructors. I believe, > following the same design principle of Mathematica's built-in > converters, which in turn follow the UI design principle of just get > the job done without involving the user's valuable time unnecessarily, > to consider extending existing functions with upvalues. I can't comment on that until I have a better understanding of what is meant by constructors in this context. > it as extending Part with an upvalue to extract the numerator or > denominator of a rational number (created as a new datatype as an > exercise from M220 the programming course), I can see the other point > of view--not allowing Part to do this. > .... > The datatype is rational[n_Integer, d_Integer] with n and d > type-checked as integers .... > makeRational[n_Integer, 0] := > Print[This rational is undefined.] (* better than just getting > input back as output *) > conversion; for a negative denominator, it calls the function again > and just reverses the signs of the numerator and denominator; that way > negative rationals are always in the format rational[-n, d] *) > makeRational[n_Integer, d_Integer?Negative] := makeRational[-n, d] The above are what I would call /constructors/. They are something like simple a factory design pattern. > ... > denominator::denominator will extract the denominator of the > rational. You can also use Part[ rational ] , which has been modified > to work correctly in the context of this package. Using an upvalue? > ... > rational /: (r_rational)[[1]] := numerator[r]; (* numerator is the > constructor *) I believe Dr. Maeder would use the term selector instead of constructor in this context. -- The Mathematica Wiki: http://www.mathematica-users.org/ Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html Math for the WWW: http://www.w3.org/Math/ === Subject: Re: Re: Types in Mathematica > I have to say that my definition > of /strongly typed/ involves compile-time type checking which is not > something applicable to Mathematica. > You are correct that strongly typed is ill defined, however the > distinction between compile and run time type checking is not between > strong and weak typing but between dynamic and static typing. > Generally a strongly typed language disallows the following operation > + left and reals on the right. That is not a definition I have used. I recently encountered that definition, but it is not a definition typically used by programmers I know. > Mathematica of course allows addition of > two expressions with head Integer and Real respectively and it is that > fact which makes Mathematica weakly typed. An example of a strong and > dynamic language is LISP, and this is one respect in which Mathematica > differs from LISP. (setq f 1) (setq g 2.2) (setq h (+ f g)) (print h) =>3.2 > C is of course weak and static, Java is strong and > static and that covers the four possibilities. Java certainly supports primitive type conversion, so I don't understand your statement. > There are Integer, Real, > Complex, Rational, String and Symbol atomic types. Everything else > in > Mathematica is constructed of these basic types. > A List is most certainly not a Symbol, nor is it Complex, Integer, Real > etc. A List is an expression whose Head is a Symbol with value List > applied to zero or more arguments. Hence the idea that everything in > Mathematica is an expression, that's really the only type that exists > (and paradoxically in that sense Mathematica is strongly typed, but in > a universe with only one type it is impossible to distinguish between > strong and weak typing). I don't agree with this. One can say that 1 is an expression with head Integer, but to say that expression is a data type is not much different than saying everything in C++ is a statement. > One can simulate a type system by treating the values of the Heads > differently but that's a simulation and not intrinsic to Mathematica > itself. I'm not sure what you mean. Mathematica treats 1 + 1.5 differently than it treats 1 + some string. That is intrinsic to the language as it is presented to the user. Without a formal language specification, I know of no other means of determining what is, or is not intrinsic than to examine how Mathematica works out of the box. >> You may make arbitrary inquires about the structure of expressions. >> This >> is far more flexible and general than any type system, but in simple >> cases may superfically resemble one. > Can you give an example? > f[g[x_]] can be considered to be a function that acts on objects of > type g. Since Mathematica is not strongly typed to ensure that we know > the pattern x_ is to be considered of type g we have to explicitly > include the information somewhere, and in Mathematica a convenient > location is the head of an expression. It's not necessary to do it > that way f[{g,x_}] also works and now the type g is represented as a > list whose first element indicates its type. How does that have superficial resemblance to the use of a type system in another language? > What about predicates which test for types? > An alternative way of thinking about the predicates which would avoid > confusion about the idea of typing is to imagine them as functions over > the space of all possible expressions mapping a subset to the value > True which subset we then can treat as a type. What confusion? > Can you explain this in terms of operator overloading in Mathematica > and > C++? > Operator overloading is a restricted version of pattern matching which > is useful in a statically typed environment. Both C++ and Mathematica support operator overloading. Are both of these statically typed languages? Neither of these languages satisfy the criteria you have given for classification as strongly typed. > How is C++ operator overloading similar to that in Mathematica? > There are no operators in Mathematica so the idea of operator > overloading is not defined. That is simply not correct. > Of course just as with types, operators can be simulated in Mathematica. What is the difference between associating a function with an operator in C++ and in Mathematica? > Why > is that similarity superficial? > Because C++ has well defined constructs called, statements, functions > (or operators) and a host of types and a lot of rules explaining how > they all interact. Mathematica has none of these. You are making assertions which are contrary to the terminology used to discuss Mathematica. > How does it differ from generic programming in C++? > One can actually get C++ templates to behave like Mathematica, that's > how Blitz++(http://www.oonumerics.org/blitz/) Blitz++ actually uses a good deal of CPP code in its implementation. === Subject: Re: Re: Types in Mathematica > I have to say that my definition > of /strongly typed/ involves compile-time type checking which is not > something applicable to Mathematica. You are correct that strongly typed is ill defined, however the distinction between compile and run time type checking is not between strong and weak typing but between dynamic and static typing. Generally a strongly typed language disallows the following operation + unless the user explicitly creates a + operator for integers on the left and reals on the right. Mathematica of course allows addition of two expressions with head Integer and Real respectively and it is that fact which makes Mathematica weakly typed. An example of a strong and dynamic language is LISP, and this is one respect in which Mathematica differs from LISP. C is of course weak and static, Java is strong and static and that covers the four possibilities. > There are Integer, Real, > Complex, Rational, String and Symbol atomic types. Everything else > in > Mathematica is constructed of these basic types. A List is most certainly not a Symbol, nor is it Complex, Integer, Real etc. A List is an expression whose Head is a Symbol with value List applied to zero or more arguments. Hence the idea that everything in Mathematica is an expression, that's really the only type that exists (and paradoxically in that sense Mathematica is strongly typed, but in a universe with only one type it is impossible to distinguish between strong and weak typing). One can simulate a type system by treating the values of the Heads differently but that's a simulation and not intrinsic to Mathematica itself. >> You may make arbitrary inquires about the structure of expressions. >> This >> is far more flexible and general than any type system, but in simple >> cases may superfically resemble one. > Can you give an example? f[g[x_]] can be considered to be a function that acts on objects of type g. Since Mathematica is not strongly typed to ensure that we know the pattern x_ is to be considered of type g we have to explicitly include the information somewhere, and in Mathematica a convenient location is the head of an expression. It's not necessary to do it that way f[{g,x_}] also works and now the type g is represented as a list whose first element indicates its type. > What about predicates which test for types? An alternative way of thinking about the predicates which would avoid confusion about the idea of typing is to imagine them as functions over the space of all possible expressions mapping a subset to the value True which subset we then can treat as a type. Thus with respect to the type defined in this fashion Mathematica is weakly typed (resolving the ambiguity mentioned before) so 5.+5 maps into a well defined type (with respect to the predefined predicates) in Mathematica. Unfortunately by default 5.+5 does not (it maps a Real and a String to an expression of type Plus[x_Real,y_String] which has no definition with respect to the predefined predicates) and it's that issue which has in my experience driven language designers away from weak typing. The ever contrarian Larry Wall of course decided that Perl, the sin qua non of weak typing, would attempt to resolve that ambiguity. The low regard with which Perl programmers are generally held in the Computer Science community, a special circle of hell previously reserved for Visual Basic users, is a by product of that fact. > How does structural pattern > matching differ form concept checking in C++ template metaprogramming? It actually very similar, but syntactically far more elegant. > Can you explain this in terms of operator overloading in Mathematica > and > C++? Operator overloading is a restricted version of pattern matching which is useful in a statically typed environment. > How is C++ operator overloading similar to that in Mathematica? There are no operators in Mathematica so the idea of operator overloading is not defined. There are expressions and a facility for relating expressions to each other based on the structure of the expression (aka pattern matching) and that's pretty much all there is. Of course just as with types, operators can be simulated in Mathematica. > Why > is that similarity superficial? Because C++ has well defined constructs called, statements, functions (or operators) and a host of types and a lot of rules explaining how they all interact. Mathematica has none of these. > How does it differ from generic programming in C++? One can actually get C++ templates to behave like Mathematica, that's how Blitz++(http://www.oonumerics.org/blitz/) works: by taking advantage of the implementation of the template parsers of most C++ compilers to allow C++ expressions to be treated as abstract syntax trees and optimized at compilation time. Ssezi === Subject: Re: Re: Types in Mathematica > The ever contrarian Larry Wall of course decided that Perl, the > sin qua non of weak typing, would attempt to resolve that ambiguity. > The low regard with which Perl programmers are generally held in the > Computer Science community, a special circle of hell previously reserved > for Visual Basic users, is a by product of that fact. That 'special circle of hell' that you speak of is news to me. I've never heard of it; I know that perl has its detractors, but for every detractor, there's a fervent supporter on communities like slashdot (http://www.slashdot.org) and digg (http://www.digg.org). As for an impression of mathematica users, I've never seen one (positive or negative). Mathematica seems to be off this particular map. As for weak typing, its not necessarily a bad thing - its a damn *productive* thing in the case of perl. That being said, optional, strong(er) typing wouldn't be that bad an item to have. Perl6 is adding this, but its a long, slow slog; perl6 isn't expected to be out for a couple of years, at the minimum. Ed === Subject: Re: Types in Mathematica > The ever contrarian Larry Wall of course decided that Perl, the > sin qua non of weak typing, would attempt to resolve that ambiguity. > The low regard with which Perl programmers are generally held in the > Computer Science community, a special circle of hell previously reserved > for Visual Basic users, is a by product of that fact. A nice quote. I wonder where Mathematica programmers rank in the Computer Science community? 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 === Subject: [JLINK] passing a function reference Frequently when writing program in mathematica, I find it useful to have one function take function as one of its parameters, e.g. F[f_]:=f[2] I would like to duplicate this functionality for some installable java code I am writing so that class`F[f] passes some reference to java so that I can evaluate the function on the java side, calling back to mathematica appropriately, so it seems like I can either pass a symbol represting the function name, build up a packet manually to evaluate it and send that off, or possibly pass a pure function and do something similar, what seems like a robust solution to you, I'd (ideally) like this to be as transparent to the end user as possible, and to incoporate any optimization (MethodFunction for example), thats probably asking alot, but I'm just interested to hearing what you think is a good overall solution Jonathan Katz === Subject: Re: Types in Mathematica >I have come to realize that there are (or appear to be) certain >limitations as to what can be done with type conversions in >comparison to how they are used in C++. For example, in C++ it is >possible to create type conversion operators which will be invoked >according to the parameters accepted by a function. For example, >you might have some kind of counter object which automatically >converts to an integer when passed as a variable of integer type. >I don't believe I could do something similar with Mathematica. For >instance, if I have a type Vector3D[x,y,z], I don't see a way of >getting that to convert to a List[x,y,z] when passed to an >arbitrary function taking a List as an argument. I don't understand your comment here. I can easily do the following: In[3]:= a = Vector3D[x, y, z]; b = List @@ a; Head[b] Out[5]=List Given this, why shouldn't Apply (@@) be considered a type conversion in this context? -- To reply via email subtract one hundred and four === Subject: Re: Types in Mathematica thread >>4. There are other built in type tests that rely on other tests >>than Head: NumberQ, NumericQ, IntegerQ, EvenQ, OddQ, PrimeQ; >>ArrayQ, VectorQ, MatrixQ (for these there are nice element tests, >>too), PolynomialQ (element tests). There are built in structural >>tests, and I mention these for the reason mentioned next: SameQ, >>UnsameQ, OrderedQ, MemberQ, FreeQ, MatchQ, ValueQ, AtomQ. With >>these, argument-testing syntax is f[x_?testQ]. q.v. Section 2.3.5. >RealQ? Ironically that one seems to be missing. Probably an >intentional ommission. Perhaps. But it is easily added should you want a test for reals using the same syntax, e.g., RealQ[x_]:=Element[x,Reals] will do the trick quite nicely. -- To reply via email subtract one hundred and four === Subject: Re: Types in Mathematica thread > But it is easily added should you want a test for reals using the > same syntax, e.g., > RealQ[x_]:=Element[x,Reals] > will do the trick quite nicely. You may also want: to guarantee a boolean result, or: RealQ[_Real] := True RealQ[_] := False for equivalence with the Head test _Real, rather than the mathematical concept of a real number. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html === Subject: Re: Extracting just the value of the variable from the result of Solve/NDSolve > Hi all, > i am facing a peculiar problem with the curly brackets of the output of > Solve and NDsolve commands....the result of Solve/NSolve/DSolve/NDSolve > all are in the form of {{y->a}} format and at best by doing a y/.soln, i > can get it to {a}, but for my purposes of passing this result to > JAVA(using J/Link), i need the value of the variable as just 'a' and not > '{a}'(i hope i am making myself clear). > E.g. > eqn={F==2*T}; > T = 300; > sol = Solve[eqn, F] > F /. sol > gives me {600}, as i said earlier i need the answer 600(which is > different in datatype compared to {600} even though for all practical > purposes {600} is the same as 600). When i use J/link to extract value, > the {600} is not considered an integer/string/double/function,...so i > cannnot use getInteger,getString etc. > Can someone plz suggest a solution this problem, however triveal as it > may sound, it is an important problem in using J/Link to talk with > Mathematica. This works in the Mathematica front-end, don't know about J/Link: eqn={F==2*T}; T = 300; sol = Solve[eqn, F] F /. sol[[1]] In[1]:= eqn = {F==2*T}; In[2]:= T=300; In[3]:= sol = Solve[eqn,F] Out[3]= {{F -> 600}} In[4]:= F/.sol[[1]] Out[4]= 600 Obviously, this technique blows up if there are multiple solutions to the equation. -- MSN: wizard_of_yendor@hotmail.com Orkut: http://www.orkut.com/Profile.aspx?uid=2202360379963855296 === Subject: Extracting just the value of the variable from the result of Solve/NDSolve Hi all, i am facing a peculiar problem with the curly brackets of the output of Solve and NDsolve commands....the result of Solve/NSolve/DSolve/NDSolve all are in the form of {{y->a}} format and at best by doing a y/.soln, i can get it to {a}, but for my purposes of passing this result to JAVA(using J/Link), i need the value of the variable as just 'a' and not '{a}'(i hope i am making myself clear). E.g. eqn={F==2*T}; T = 300; sol = Solve[eqn, F] F /. sol gives me {600}, as i said earlier i need the answer 600(which is different in datatype compared to {600} even though for all practical purposes {600} is the same as 600). When i use J/link to extract value, the {600} is not considered an integer/string/double/function,...so i cannnot use getInteger,getString etc. Can someone plz suggest a solution this problem, however triveal as it may sound, it is an important problem in using J/Link to talk with Mathematica. Pradeep === Subject: Re: Extracting just the value of the variable from the result of Solve/NDSolve > Hi all, > i am facing a peculiar problem with the curly brackets of the output of > Solve and NDsolve commands....the result of Solve/NSolve/DSolve/NDSolve > all are in the form of {{y->a}} format and at best by doing a y/.soln, i > can get it to {a}, but for my purposes of passing this result to > JAVA(using J/Link), i need the value of the variable as just 'a' and not > '{a}'(i hope i am making myself clear). > E.g. > eqn={F==2*T}; > T = 300; > sol = Solve[eqn, F] > F /. sol > gives me {600}, as i said earlier i need the answer 600(which is > different in datatype compared to {600} even though for all practical > purposes {600} is the same as 600). When i use J/link to extract value, > the {600} is not considered an integer/string/double/function,...so i > cannnot use getInteger,getString etc. > Can someone plz suggest a solution this problem, however triveal as it > may sound, it is an important problem in using J/Link to talk with > Mathematica. > Pradeep Hi Pradeep, Add a part specification to the the list of solutions {sol[[1]] in this case): In[1]:= eqn = F == 2*T; sol = Solve[eqn /. T -> 300, F]; F /. sol[[1]] Out[3]= 600 === Subject: Re: Threading 'Append' >If I run >Thread[Append[{{1,2},{3,4},{5,6}},{a,b,c}]] >I would expect to get >{{1,2,a},{3,4,b},{5,6,c}} >but in fact I get an 'Objects of unequal length' error. Try either In[8]:= Thread[Append[Transpose@{{1, 2}, {3, 4}, {5, 6}}, {a, b, c}]] Out[8]= {{1, 2, a}, {3, 4, b}, {5, 6, c}} or In[14]:= MapThread[Append, {{{1, 2}, {3, 4}, {5, 6}}, {a, b, c}}] Out[14]= {{1, 2, a}, {3, 4, b}, {5, 6, c}} -- To reply via email subtract one hundred and four === Subject: Re: Re: Types in Mathematica thread > I can't think of why there is no RealQ predicate, but there is > _Real, a pattern test via the head. >> Maybe because it is called InexactNumberQ. > That clearly would not be the equivalent of RealQ since > InexactNumberQ[Pi] correctly returns False when RealQ[Pi] would > return True if it existed. > -- The discussion was not about testing whether something is a real number or not (in the mathematical sense). This you test with Element [something, Reals]. The discussion was about types. Please note the title of the thread to which you have just contributed, or even better rerad the thread. Well, the type of objects with head Real in Mathematica is exactly what InexactNumberQ tests for. A mathematica _Real is not a real number in the sense of mathematics but precisely an inexact number. (Actually, I myself do not agree that that there are types in Mathematica and that these functions test for types. But even if it were not a discussion of types in any case your answer would be quite wrong, since NumberQ[Pi] also gives False, and surely Pi is a number? ) Andrzej Kozlowski === Subject: Re: Re: Types in Mathematica thread > The discussion was not about testing whether something is a real > number or not (in the mathematical sense). This you test with Element > [something, Reals]. The discussion was about types. Please note the > title of the thread to which you have just contributed, or even > better rerad the thread. Well, the type of objects with head Real > in Mathematica is exactly what InexactNumberQ tests for. A > mathematica _Real is not a real number in the sense of mathematics > but precisely an inexact number. Basically I agree with your answer, but what about: In[10]:= InexactNumberQ[0.5 I] Out[10]= True albert === Subject: Re: Types in Mathematica thread >>I can't think of why there is no RealQ predicate, but there is >>_Real, a pattern test via the head. >Maybe because it is called InexactNumberQ. That clearly would not be the equivalent of RealQ since InexactNumberQ[Pi] correctly returns False when RealQ[Pi] would return True if it existed. -- To reply via email subtract one hundred and four === Subject: Re: Threading 'Append' >>If I run >>Thread[Append[{{1,2},{3,4},{5,6}},{a,b,c}]] >>I would expect to get >>{{1,2,a},{3,4,b},{5,6,c}} >>but in fact I get an 'Objects of unequal length' error. >>On the other hand, >>Thread[foo[{{1,2},{3,4},{5,6}},{a,b,c}]] >>%/.foo->Append >>gives what I wanted. Can someone explain what's going on? >> >All you need to do is: >In[9]:= >Thread[Unevaluated[Append[{{1, 2}, {3, 4}, {5, 6}}, > {a, b, c}]]] >Out[9]= >{{1, 2, a}, {3, 4, b}, {5, 6, c}} >The name of the function Unevaluated should make it self evident >what happened here (I hope). Actually it is not. Can you please elaborate Pratik >Andrzej Kozlowski === Subject: Re: Threading 'Append' You probably mean to use MapThread MapThread[Append, {{{1, 2}, {3, 4}, {5, 6}}, {a, b, c}}] returns {{1, 2, a}, {3, 4, b}, {5, 6, c}} look at the help to see the difference between Thread and MapThread yehua > If I run > Thread[Append[{{1,2},{3,4},{5,6}},{a,b,c}]] > I would expect to get > {{1,2,a},{3,4,b},{5,6,c}} > but in fact I get an 'Objects of unequal length' error. > On the other hand, > Thread[foo[{{1,2},{3,4},{5,6}},{a,b,c}]] > %/.foo->Append > gives what I wanted. Can someone explain what's going on? === Subject: Re: Threading 'Append' > If I run > Thread[Append[{{1,2},{3,4},{5,6}},{a,b,c}]] > I would expect to get > {{1,2,a},{3,4,b},{5,6,c}} > but in fact I get an 'Objects of unequal length' error. > On the other hand, > Thread[foo[{{1,2},{3,4},{5,6}},{a,b,c}]] > %/.foo->Append > gives what I wanted. Can someone explain what's going on? All you need to do is: In[9]:= Thread[Unevaluated[Append[{{1, 2}, {3, 4}, {5, 6}}, {a, b, c}]]] Out[9]= {{1, 2, a}, {3, 4, b}, {5, 6, c}} The name of the function Unevaluated should make it self evident what happened here (I hope). Andrzej Kozlowski === Subject: Re: Threading 'Append' > If I run > Thread[Append[{{1,2},{3,4},{5,6}},{a,b,c}]] > I would expect to get > {{1,2,a},{3,4,b},{5,6,c}} > but in fact I get an 'Objects of unequal length' error. > On the other hand, > Thread[foo[{{1,2},{3,4},{5,6}},{a,b,c}]] > %/.foo->Append > gives what I wanted. Can someone explain what's going on? It's an evaluation order problem Thread[Unevaluated[Append[{{1, 2}, {3, 4}, {5, 6}}, {a, b, c}]]] works. I've run into this problem before, it's even worse if you try to do l1 = {{1, 2}, {3, 4}, {5, 6}}; l2 = {a, b, c}; Thread[Unevaluated[Append[l1, l2]]] Most of the time I just work around it with MapThread which evaluates the expressions in the order one would prefer. Ssezi === Subject: Threading 'Append' If I run Thread[Append[{{1,2},{3,4},{5,6}},{a,b,c}]] I would expect to get {{1,2,a},{3,4,b},{5,6,c}} but in fact I get an 'Objects of unequal length' error. On the other hand, Thread[foo[{{1,2},{3,4},{5,6}},{a,b,c}]] %/.foo->Append gives what I wanted. Can someone explain what's going on? === Subject: Re: Threading 'Append' Mathematica evaluate an expression from the inner parts to the outer parts. Since Append[{{1,2},{3,4},{5,6}},{a,b,c}] is evaluated to {{1,2},{3,4},{5,6},{a,b,c}} the later evaluation of Thread[] does not find a Append that it can thread .. Thread[Hold[Append][{{1, 2}, {3, 4}, {5, 6}}, {a, b, c}]] // ReleaseHold or MapThread[Append, {{{1, 2}, {3, 4}, {5, 6}}, {a, b, c}}] may help. Jens J Siehler schrieb im | If I run | | Thread[Append[{{1,2},{3,4},{5,6}},{a,b,c}]] | | I would expect to get | | {{1,2,a},{3,4,b},{5,6,c}} | | but in fact I get an 'Objects of unequal length' error. | | On the other hand, | | Thread[foo[{{1,2},{3,4},{5,6}},{a,b,c}]] | %/.foo->Append | | gives what I wanted. Can someone explain what's going on? | === Subject: Re: Can you solve my gravity-maths problem in Mathematica? > atoms have a minimum electron shell distance caused by the quantisation > of the electromagnetic force my approximation for the average distance > model, becomes : > Find r at the maximum value of: > f(r) = exp( m*r ) * integrate( exp(-2*m*r)/r^2 , r ) > (r>0) You really need to distinguish between r the integration variable, and r the argument to f. Also, if the r^2 in the denominator is the integration variable, then the integral over r>0 does not converge. So, change the name of the integration variable, and spell out the limits of the integration. Then, maybe someone can help you. Carl Woll Wolfram Research > Where we use constants such that c=h=G=1. In this system for example > electron mass is something like 10^(-23) I believe. (The graviational > bond enegy in this model becomes m^5 in my units.) > So I need to find f'(r)=0. > Can anyone find a good way to solve this for r, maybe as a series in > terms of m? Also, I would be interested in seeing a graph of f(r). === Subject: Can you solve my gravity-maths problem in Mathematica? atoms have a minimum electron shell distance caused by the quantisation of the electromagnetic force my approximation for the average distance model, becomes : Find r at the maximum value of: f(r) = exp( m*r ) * integrate( exp(-2*m*r)/r^2 , r ) (r>0) Where we use constants such that c=h=G=1. In this system for example electron mass is something like 10^(-23) I believe. (The graviational bond enegy in this model becomes m^5 in my units.) So I need to find f'(r)=0. Can anyone find a good way to solve this for r, maybe as a series in terms of m? Also, I would be interested in seeing a graph of f(r). === Subject: Re: Can you solve my gravity-maths problem in Mathematica? Hi Paul, your function does not have a minimal value for r>0. To show this, we first simplify your function by defining a new variable x= m r and we use a definite integral from zero: f[r] == F[x] == m Exp[x] Integrate[Exp[-2x1]/x1^2,{0,x}] We may drop m as it does not change the position of a minimum. If this function would have a minimum, a x0 would exists so that F'[x0] = Exp[x0] Integrate[Exp[-2x1]/x1^2,{0,x0}] +Exp[x0] Exp[-2x0]/x0^2== 0 from this we get: Integrate[Exp[-2x1]/x1^2,{0,x0}] = - Exp[-2x0]/x0^2 For positive x0 the left side is positive (positive integrand), but the right side is negative. Therefore, no x0 exists. Daniel > atoms have a minimum electron shell distance caused by the quantisation > of the electromagnetic force my approximation for the average distance > model, becomes : > Find r at the maximum value of: > f(r) = exp( m*r ) * integrate( exp(-2*m*r)/r^2 , r ) > (r>0) > Where we use constants such that c=h=G=1. In this system for example > electron mass is something like 10^(-23) I believe. (The graviational > bond enegy in this model becomes m^5 in my units.) > So I need to find f'(r)=0. > Can anyone find a good way to solve this for r, maybe as a series in > terms of m? Also, I would be interested in seeing a graph of f(r). === Subject: Roman Maeder's Classes.m Does anybody know where I can find an explanation of how Roman Maeder's Classes.m works? The notebook advertised at the following link seems to be some kind of binary file insted of a Mathematica notebook: http://www.mathconsult.ch/math/stuff/ It may be described in _The Mathematica Programmer_, but that book is unfortunately out of print. I can read the code, and understand most of it. That does not, however, communicate the conceptual framework he used to create the package. -- The Mathematica Wiki: http://www.mathematica-users.org/ Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html Math for the WWW: http://www.w3.org/Math/ === Subject: Bug in Graphics output of Circle primitive? I stumbled upon a strange (and suspicious) graphics output when displaying arcs with small angular length. If I evaluate the following lines: r = 10000; gx = Circle[{r, 0}, r, {179¡, 180¡}]; Show[Graphics[{gx, Point[{0, 0}]}], Axes -> True, PlotRange -> {Automatic, Automatic}, AxesOrigin -> {0, 0}]; (or the same in plain text format...) r=10000; gx=Circle[{r,0},r,{179[Degree],180[Degree]}]; Show[Graphics[{gx,Point[{0,0}]}],Axes[Rule]True, PlotRange[Rule]{Automatic,Automatic},AxesOrigin[Rule]{0,0}]; I get the point as specified at the origin {0,0}. The arc though does not intersect at the origin as it should IMHO, but somewhat left of it. Same thing occurs for arbitrary values of r. There might be some precision problem of the postscript output concerning the Circle primitive when very different axes scaling is used, but any enlightment would be appreciated. I am using V5.2 on windows. Any hints or tips to get rid of this faulty output would be very welcome, Yves Klett === Subject: Re: Types in Mathematica, a practical example > It seems to me that you are looking here at Mathematica from the > wrong view point. Although Mathematica is not a strict functional > language, it is functional at least in the sense that it is > functions and not objects that play the central role (I am being > deliberately vague here but I have run out of patience with long > discussions of programming languages and general design issues.). Amen, but apparently I have a masochistic streak that makes me persevere in this sisyphean discussion. At any rate I thought about the problem a bit further, I am not sure why, and your point above is related to my thoughts. If one insists on seeing all programming in an object oriented manner there is an argument that could be made for understanding how to make a Symbol x have some desired properties corresponding to behavior according to a type. The first thing one must do is forget the Java/C++ model of objects, where objects are defined as record structures which can contain associated methods. Instead the appropriate model is Smalltalk, where the definition of a method on a variable defines the behaviors of the class to which that variable belongs. > In > this case the issue is with the function Plus and not with the nature > or type of x etc. Plus has the attribute Listable, which is > responsible for the behaviour you see Agreed, so the object oriented approach would be to redefine the Plus method on x to get the behavior we desire. We can consider the regular Plus method to be inherited from the type which roots the Mathematica type system: expression. The larger problem is the evaluator; the Listable attribute gets applied before any definitions of Plus are used and removing the Listable attribute would apply to all definitions of Plus not just the Plus for x. Having spent too much time thinking about this already I'm not really sure how to work around that problem, it seems to me one would need to redefine Plus in such a way that all instances of Plus not involving x behave as a Listable expression which is a nontrivial task. A simpler alternative is to create your own method not named Plus with the properties you desire: objects of type undefined2DArray should return as a symbol and other objects should be evaluated. There are still some issues with the evaluator but mySubtract[undefined2DArray[x_], a_] := HoldForm[mySubtract[x, a]] mySubtract[x_, a_] := x - a mySubtract[undefined2DArray[x], a] ReleaseHold[mySubtract[undefined2DArray[x], a] /. x -> a] gets most of the way there but is admittedly unwieldy to use because of the Holds. > the natural way to deal with your problem is by > temporarily blocking the Listable attribute like this: > In[10]:= > a = {{1, 2}, {3, 4}}; > In[11]:= > Block[{Plus}, x - a /. x -> a] > Out[11]= > {{0, 0}, {0, 0}} Of course, but I think the idea in this thread is to deal with the idea of types and their implementation in Mathematica. The evaluator does not easily fit into a model of types. I think what should be clear though is that unless there is a very good argument for developing the infrastructure necessary to redefine the behavior of Mathematica expressions globally, development of a type system infrastructure is probably far more work than it's worth. Ssezi === Subject: Re: Types in Mathematica, a practical example > To MathGroup, > I am not an advocate for strong typing in Mathematica, but consider the > following simple example: I want to see if two matrices are equal. > One of > them was the result from some equation, and is given inside a rule. > Then I > write some code similar to this: > a = {{1, 2}, {3, 4}}; > x - a /. {x -> a} > I of course hope to get a matrix filled by zeroes, but if x is > undefined, > the following is returned: > {{{{0, 1}, {2, 3}}, {{-1, 0}, {1, 2}}}, {{{-2, -1}, {0, 1}}, {{-3, > -2}, {-1, > 0}}}} > First x was assumed to be a number, and (x - a) was evaluated. Then > x was > substituted by the matrix a. No bug in Mathematica, but it was not > what I > wanted as user. It is easy to make such a mistake in the > programming. Of > course there are many ways to get around this problem, but is there any > reasonably simple way to type x to be a list of lists without > specifying > the elements, in such a way that the above example works? > I could do > ReleaseHold[Hold[x - a] /. {x -> a}] > but then we are not in the typing business any longer. > I think this question illuminates one aspect of the typing issue in > Mathematica. I remember that I as a newbie looked for ways to declare > matrices, in such a way that I later could specify matrix elements > one-by-one, without initializing them first. I soon learned that > there are > other ways to achieve similar results, but still I do not see any good > reason why I cannot force Mathematica to give the following response > from > x-a, if x in some way is declared to be a 2x2 list of lists: > {{x[[1,1]] - 1, x[[1,2]] - 2},{x[[2,1]] - 3, x[[2,2]] - 4}} > I am not allowed to Unset or Clear any part of a list either. Why not? > Ingolf Dahl > Sweden > >> Hi Ingolf >> Perhaps I am missing the point, and after reading some of the posts >> in this thread I am not really sure what type actually means. >> Nevertheless based on the definition >> http://mathworld.wolfram.com/MatrixEquality.html >> Why not write a function such as this?? > Whoops, that will not work for obvious reasons > s1 = {{1, 2, 3}, {4, 5, 6}} > s2 = {{1, 2}, {3, 4}, {5, 6}} > MatEQ[s1,s2] >>True > :-[ But this might MatEQ[m_?MatrixQ, n_?MatrixQ] := ( s1 = {{1, 2, 3}, {4, 5, 6}} s2 = {{1, 2}, {3, 4}, {5, 6}} s3 = {{1, 2, 3}, {4, 5, 6}} MatEQ[s1,s2] >>False MatEQ[s1,s3] >>True === Subject: Re: Types in Mathematica, a practical example >> To MathGroup, >> I am not an advocate for strong typing in Mathematica, but consider the >> following simple example: I want to see if two matrices are equal. >> One of >> them was the result from some equation, and is given inside a rule. >> Then I >> write some code similar to this: >> a = {{1, 2}, {3, 4}}; >> x - a /. {x -> a} >> I of course hope to get a matrix filled by zeroes, but if x is >> undefined, >> the following is returned: >> {{{{0, 1}, {2, 3}}, {{-1, 0}, {1, 2}}}, {{{-2, -1}, {0, 1}}, {{-3, >> -2}, {-1, >> 0}}}} >> First x was assumed to be a number, and (x - a) was evaluated. Then x >> was >> substituted by the matrix a. No bug in Mathematica, but it was not >> what I >> wanted as user. It is easy to make such a mistake in the programming. Of >> course there are many ways to get around this problem, but is there any >> reasonably simple way to type x to be a list of lists without >> specifying >> the elements, in such a way that the above example works? >> I could do >> ReleaseHold[Hold[x - a] /. {x -> a}] >> but then we are not in the typing business any longer. >> I think this question illuminates one aspect of the typing issue in >> Mathematica. I remember that I as a newbie looked for ways to declare >> matrices, in such a way that I later could specify matrix elements >> one-by-one, without initializing them first. I soon learned that >> there are >> other ways to achieve similar results, but still I do not see any good >> reason why I cannot force Mathematica to give the following response >> from >> x-a, if x in some way is declared to be a 2x2 list of lists: >> {{x[[1,1]] - 1, x[[1,2]] - 2},{x[[2,1]] - 3, x[[2,2]] - 4}} >> I am not allowed to Unset or Clear any part of a list either. Why not? >> Ingolf Dahl >> Sweden >> > Hi Ingolf > Perhaps I am missing the point, and after reading some of the posts in > this thread I am not really sure what type actually means. > Nevertheless based on the definition > http://mathworld.wolfram.com/MatrixEquality.html > Why not write a function such as this?? Whoops, that will not work for obvious reasons s1 = {{1, 2, 3}, {4, 5, 6}} s2 = {{1, 2}, {3, 4}, {5, 6}} MatEQ[s1,s2] >>True :-[ === Subject: Re: Types in Mathematica, a practical example It seems to me that you are looking here at Mathematica from the wrong view point. Although Mathematica is not a strict functional language, it is functional at least in the sense that it is functions and not objects that play the central role (I am being deliberately vague here but I have run out of patience with long discussions of programming languages and general design issues.). In this case the issue is with the function Plus and not with the nature or type of x etc. Plus has the attribute Listable, which is responsible for the behaviour you see (and it does really matter if Mathematica assumes that x is a number or not, for the same thing will happen, for example, if you use the string x instead of the symbol x). Hence the natural way to deal with your problem is by temporarily blocking the Listable attribute like this: In[10]:= a = {{1, 2}, {3, 4}}; In[11]:= Block[{Plus}, x - a /. x -> a] Out[11]= {{0, 0}, {0, 0}} As far as I am concerned this works just as I would wish and I see no benefit in adding any kind of types to deal with this sort of problems. Andrzej Kozlowski > To MathGroup, > I am not an advocate for strong typing in Mathematica, but consider > the > following simple example: I want to see if two matrices are equal. > One of > them was the result from some equation, and is given inside a rule. > Then I > write some code similar to this: > a = {{1, 2}, {3, 4}}; > x - a /. {x -> a} > I of course hope to get a matrix filled by zeroes, but if x is > undefined, > the following is returned: > {{{{0, 1}, {2, 3}}, {{-1, 0}, {1, 2}}}, {{{-2, -1}, {0, 1}}, {{-3, > -2}, {-1, > 0}}}} > First x was assumed to be a number, and (x - a) was evaluated. Then > x was > substituted by the matrix a. No bug in Mathematica, but it was not > what I > wanted as user. It is easy to make such a mistake in the > programming. Of > course there are many ways to get around this problem, but is there > any > reasonably simple way to type x to be a list of lists without > specifying > the elements, in such a way that the above example works? > I could do > ReleaseHold[Hold[x - a] /. {x -> a}] > but then we are not in the typing business any longer. > I think this question illuminates one aspect of the typing issue in > Mathematica. I remember that I as a newbie looked for ways to declare > matrices, in such a way that I later could specify matrix elements > one-by-one, without initializing them first. I soon learned that > there are > other ways to achieve similar results, but still I do not see any good > reason why I cannot force Mathematica to give the following > response from > x-a, if x in some way is declared to be a 2x2 list of lists: > {{x[[1,1]] - 1, x[[1,2]] - 2},{x[[2,1]] - 3, x[[2,2]] - 4}} > I am not allowed to Unset or Clear any part of a list either. Why not? > Ingolf Dahl > Sweden === Subject: Re: Types in Mathematica, a practical example I'm still working on my first pot of coffee, so I can claim full mental acuity. Nonetheless, I will offer my observations. > It seems to me that you are looking here at Mathematica from the > wrong view point. Although Mathematica is not a strict functional > language, it is functional at least in the sense that it is > functions and not objects that play the central role (I am being > deliberately vague here but I have run out of patience with long > discussions of programming languages and general design issues.). You aren't obligated to participate in this discussion, as I'm sure you know. I will acknowledge that discussing Mathematica in terms of a programming language can be a bit frustrating. Part of that is due to the inexact way in which it is documented at the fundamental level. > In > this case the issue is with the function Plus and not with the nature > or type of x etc. Plus has the attribute Listable, which is > responsible for the behaviour you see (and it does [not?] really matter if > Mathematica assumes that x is a number or not, for the same thing > will happen, for example, if you use the string x instead of the > symbol x). Hence the natural way to deal with your problem is by > temporarily blocking the Listable attribute Here I will say that Plus could be viewed as an instance of a class Symbol with a member variable Listable. I would probably implement attributes as a single bit field. [10101110], or whatever, where one means the attribute is set. > like this: > In[10]:= > a = {{1, 2}, {3, 4}}; > In[11]:= > Block[{Plus}, x - a /. x -> a] That is certainly an interesting trick. If I understand correctly, you have basically shadowed the definition of Plus, and within the context of the Block, Plus is just a vacant symbol. > Out[11]= > {{0, 0}, {0, 0}} > As far as I am concerned this works just as I would wish and I see no > benefit in adding any kind of types to deal with this sort of > problems. This really is the kind of answer I was trying to get at by bringing up the topic of typing. That is to say, in other languages we expect certain kinds of behavior. Some of these behaviors are based on a type system in the other language. What we have here is a person who came to Mathematica with certain expectations of behavior which seem type related. Your suggestions seems like an insightfull means of accomplishing the original objective of Ingolf's example. As for adding any kind of type system to Mathematica, that could mean different things. It could mean modifying the core Mathematica language to add a type system. That is not something I expect to happen in the next few thousand years, at least not in the sense of types in C++, etc. It could also mean implementing a type system using the current Mathematica language. That is something which people (e.g., Roman Maeder) have done, by their own definition of types. It also seems to be something WRI is promoting in their training courses. -- The Mathematica Wiki: http://www.mathematica-users.org/ Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html Math for the WWW: http://www.w3.org/Math/ === Subject: Re: Types in Mathematica, a practical example >To MathGroup, >I am not an advocate for strong typing in Mathematica, but consider the >following simple example: I want to see if two matrices are equal. One of >them was the result from some equation, and is given inside a rule. Then I >write some code similar to this: >a = {{1, 2}, {3, 4}}; >x - a /. {x -> a} >I of course hope to get a matrix filled by zeroes, but if x is undefined, >the following is returned: >{{{{0, 1}, {2, 3}}, {{-1, 0}, {1, 2}}}, {{{-2, -1}, {0, 1}}, {{-3, -2}, {-1, >0}}}} >First x was assumed to be a number, and (x - a) was evaluated. Then x was >substituted by the matrix a. No bug in Mathematica, but it was not what I >wanted as user. It is easy to make such a mistake in the programming. Of >course there are many ways to get around this problem, but is there any >reasonably simple way to type x to be a list of lists without specifying >the elements, in such a way that the above example works? >I could do >ReleaseHold[Hold[x - a] /. {x -> a}] >but then we are not in the typing business any longer. >I think this question illuminates one aspect of the typing issue in >Mathematica. I remember that I as a newbie looked for ways to declare >matrices, in such a way that I later could specify matrix elements >one-by-one, without initializing them first. I soon learned that there are >other ways to achieve similar results, but still I do not see any good >reason why I cannot force Mathematica to give the following response from >x-a, if x in some way is declared to be a 2x2 list of lists: >{{x[[1,1]] - 1, x[[1,2]] - 2},{x[[2,1]] - 3, x[[2,2]] - 4}} >I am not allowed to Unset or Clear any part of a list either. Why not? >Ingolf Dahl >Sweden Hi Ingolf Perhaps I am missing the point, and after reading some of the posts in this thread I am not really sure what type actually means. Nevertheless based on the definition http://mathworld.wolfram.com/MatrixEquality.html Why not write a function such as this?? === Subject: Re: Types in Mathematica, a practical example Ingolf, How about, on an initialized one per your spec: In[11]:= Table[ Table[0, {2}], {2}] Out[11]= {{0,0},{0,0}} In[12]:= MatrixQ[Out[11]] Out[12]= True on yours, or an arbitrary one, for which you have to adjust the Depth argument: In[19]:= idlist = {{{{0, 1}, {2, 3}}, {{-1, 0}, {1, 2}}}, {{{-2, -1}, {0, 1}}, {{-3, -2}, {-1, 0}}}}; ArrayQ[idlist, 4] Out[20]= True Note you can also initialize via indexed arrays (See Array in Help), and then replace by index (eg f[1,1] = 2) or by MapAt. You can also query some of the qualities of each array element; qv Help 2.3.5, middle section. Kris > To MathGroup, > I am not an advocate for strong typing in Mathematica, but consider the > following simple example: I want to see if two matrices are equal. One of > them was the result from some equation, and is given inside a rule. Then I > write some code similar to this: > a = {{1, 2}, {3, 4}}; > x - a /. {x -> a} > I of course hope to get a matrix filled by zeroes, but if x is undefined, > the following is returned: > {{{{0, 1}, {2, 3}}, {{-1, 0}, {1, 2}}}, {{{-2, -1}, {0, 1}}, {{-3, -2}, {-1, > 0}}}} > First x was assumed to be a number, and (x - a) was evaluated. Then x was > substituted by the matrix a. No bug in Mathematica, but it was not what I > wanted as user. It is easy to make such a mistake in the programming. Of > course there are many ways to get around this problem, but is there any > reasonably simple way to type x to be a list of lists without specifying > the elements, in such a way that the above example works? > I could do > ReleaseHold[Hold[x - a] /. {x -> a}] > but then we are not in the typing business any longer. > I think this question illuminates one aspect of the typing issue in > Mathematica. I remember that I as a newbie looked for ways to declare > matrices, in such a way that I later could specify matrix elements > one-by-one, without initializing them first. I soon learned that there are > other ways to achieve similar results, but still I do not see any good > reason why I cannot force Mathematica to give the following response from > x-a, if x in some way is declared to be a 2x2 list of lists: > {{x[[1,1]] - 1, x[[1,2]] - 2},{x[[2,1]] - 3, x[[2,2]] - 4}} > I am not allowed to Unset or Clear any part of a list either. Why not? > Ingolf Dahl > Sweden === Subject: Re: Types in Mathematica, a practical example > To MathGroup, > I am not an advocate for strong typing in Mathematica, but consider > the > following simple example: I want to see if two matrices are equal. > One of > them was the result from some equation, and is given inside a rule. > Then I > write some code similar to this: > a = {{1, 2}, {3, 4}}; > x - a /. {x -> a} > I of course hope to get a matrix filled by zeroes, but if x is > undefined, > the following is returned: > {{{{0, 1}, {2, 3}}, {{-1, 0}, {1, 2}}}, {{{-2, -1}, {0, 1}}, {{-3, > -2}, {-1, > 0}}}} > First x was assumed to be a number, and (x - a) was evaluated. x was not assumed to be a number, x is a Symbol and without any definitions for x, x-a is {{-1 + x, -2 + x}, {-3 + x, -4 + x}} as expected. > Then x was > substituted by the matrix a. Actually first 1 is substituted for x then 2 etc. The result is what happens when you evaluate the expression for x-a above for each of those values of x. > is there any > reasonably simple way to type x to be a list of lists without > specifying > the elements, in such a way that the above example works? The unbound symbol x has a value (x) and given the rules for Subtract and lists and the value of a the rest of the results follow. If you want to treat x as having some other value (such as a list of lists) you have to assign that value to it, since the values of the elements in your case are unimportant(although in this case they actually are as you say below) then x=Table[y, Evaluate[Sequence @@ Transpose[{Dimensions[a]}]]] should suffice, but this is an unwieldy structure to work with, especially for the problem at hand. > I remember that I as a newbie looked for ways to declare > matrices, in such a way that I later could specify matrix elements > one-by-one, without initializing them first. Define expressions which returns the desired values when x is supplied with arguments: x[a_,b_] := a[[a,b]] in this case. The problem is then you have to cognizant of what x in x-a means because of the rules around lists. > if x in some way is declared to be a 2x2 list of lists: > {{x[[1,1]] - 1, x[[1,2]] - 2},{x[[2,1]] - 3, x[[2,2]] - 4}} This specification makes clear that you are actually interested in the values of the elements of x, they are supposed to be equivalent to some unspecified matrix. x=Table[y[i,j],{i,Length[a]},{j,Length[a[[1]]]}] is such a structure and you can use appropriate substitutions for y [i,j]. This is not an easy exercise because if a is larger than 2x2 there's a lot of bookkeeping to do, and you have to remember to leave y defined as a Symbol. This is also using the facilities of Mathematica in a rather perverse way, it is possible. As always until the advent of natural language understanding AIs with reasoning ability programming will remain a task of clearly specifying what is meant and expressing it unambiguously. > I am not allowed to Unset or Clear any part of a list either. Why not? What would clearing part of a list mean? Similarly for Unset. If you have a good idea of what such an expression should evaluate to you can use UpValues and Unprotect to make it happen. Ssezi === Subject: Types in Mathematica, a practical example To MathGroup, I am not an advocate for strong typing in Mathematica, but consider the following simple example: I want to see if two matrices are equal. One of them was the result from some equation, and is given inside a rule. Then I write some code similar to this: a = {{1, 2}, {3, 4}}; x - a /. {x -> a} I of course hope to get a matrix filled by zeroes, but if x is undefined, the following is returned: {{{{0, 1}, {2, 3}}, {{-1, 0}, {1, 2}}}, {{{-2, -1}, {0, 1}}, {{-3, -2}, {-1, 0}}}} First x was assumed to be a number, and (x - a) was evaluated. Then x was substituted by the matrix a. No bug in Mathematica, but it was not what I wanted as user. It is easy to make such a mistake in the programming. Of course there are many ways to get around this problem, but is there any reasonably simple way to type x to be a list of lists without specifying the elements, in such a way that the above example works? I could do ReleaseHold[Hold[x - a] /. {x -> a}] but then we are not in the typing business any longer. I think this question illuminates one aspect of the typing issue in Mathematica. I remember that I as a newbie looked for ways to declare matrices, in such a way that I later could specify matrix elements one-by-one, without initializing them first. I soon learned that there are other ways to achieve similar results, but still I do not see any good reason why I cannot force Mathematica to give the following response from {{x[[1,1]] - 1, x[[1,2]] - 2},{x[[2,1]] - 3, x[[2,2]] - 4}} I am not allowed to Unset or Clear any part of a list either. Why not? Ingolf Dahl Sweden === Subject: Re: Types in Mathematica, a practical example > I am not allowed to Unset or Clear any part of a list either. Why not? I should probably look into this more carefully before commenting, but, at the risk of making an incorrect statement, I will say this. Lists and other entities in Mathematica are rewritten upon each evaluation. You never really modify an existing expression. Instead, you modify a copy, and assign the result to the original symbol. My explanation is almost certainly an oversimplification in need of refinement, but I believe it addresses the essence of your question. -- The Mathematica Wiki: http://www.mathematica-users.org/ Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html Math for the WWW: http://www.w3.org/Math/ === Subject: Re: Zero or one > Matching zero or one of something is helpful sometimes. String > patterns have the usual ? regex, but _, __ and ___ aren't quite the > same for function definitions and MatchQ[ ]. For these occasions, > there's the following bit of syntactic sugar. > The pattern > ___ ? (Length[{#}] == 0&) > is one way to say zero of something. Wrapped into a function, we get > something like > optional[expr_] := expr | ___ ? (Length[{#}] == 0&); > as a way of saying zero or one of expr. Examples: > MatchQ[{1,3}, {1, optional[2], 3}] > True > MatchQ[{1,2, 3}, {1, optional[2], 3}] > True > MatchQ[{1, 2, 2, 3}, {1, optional[2], 3}] > False > MatchQ[{1, foo, 3}, {1, optional[_String | _Integer], 3}] > True > MatchQ[{1, foo, bar, 3}, {1, optional[_String | _Integer], 3}] > False > Generalizations over a sequence of expressions, or to count between > exactly m and n repetitions of an expression, are also possible. > Trevor. A nice idea. It may be a little more direct to define optional by: optional[expr_] := expr | ___? (#==Null&); Andrzej Kozlowski === Subject: Zero or one Matching zero or one of something is helpful sometimes. String patterns have the usual ? regex, but _, __ and ___ aren't quite the same for function definitions and MatchQ[ ]. For these occasions, there's the following bit of syntactic sugar. The pattern ___ ? (Length[{#}] == 0&) is one way to say zero of something. Wrapped into a function, we get something like optional[expr_] := expr | ___ ? (Length[{#}] == 0&); as a way of saying zero or one of expr. Examples: MatchQ[{1,3}, {1, optional[2], 3}] True MatchQ[{1,2, 3}, {1, optional[2], 3}] True MatchQ[{1, 2, 2, 3}, {1, optional[2], 3}] False MatchQ[{1, foo, 3}, {1, optional[_String | _Integer], 3}] True MatchQ[{1, foo, bar, 3}, {1, optional[_String | _Integer], 3}] False Generalizations over a sequence of expressions, or to count between exactly m and n repetitions of an expression, are also possible. Trevor. === Subject: Re: Re: Types in Mathematica, a practical example Please, could you explain better? If I try to copy-and-paste your expressions into Mathematica, I cannot get it to work. I get the following error message: Syntax::sntxb: Expression cannot begin with [[Expression:||| Array[x,{2,2}] |||]]. More... or Syntax::tsntxi : !([(([((Expression : ((|| ((| ((Array[x, {2, 2}] ||)) |))))))]))]) is incomplete; more input is needed.() (ButtonBox[More[Ellipsis], Rule[ButtonStyle, RefGuideLinkText], Rule[ButtonFrame, None], RuleDelayed[ButtonData, General::tsntxi]]) Expression is not very well explained in the help, and how should I interpret the three vertical bars? The notation does not look like anything I am used to. Ingolf Dahl Sweden -----Original Message----- === Subject: Re: Types in Mathematica, a practical example I like to use Array when I want a variable to be treated as a matrix. [[Expression:||| Array[x,{2,2}] |||]] This is probably not what you want since the output is a nested list. This is not the same as declaring a variable as a matrix. But now, this approach works: [[Expression:||| a={{1,2},{3,4}}|||]] [[Expression:||| Array[x,{2,2}] - a /. x[k__]:>a[[k]] |||]] Link to the forum page for this post: http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=Speci al:Forum_ViewTopic&pid=6675#p6675 === Subject: Re: Importing tab-delimited data files? This may have posted but This is a Tabular separated values with empty fields. So use Import[yourfilehere,TSV, ConversionOptions -> {EmptyField -> } ] No tab or newline options needed. >I create a text file filedata with the following content using a text > editor, with tabs between each number or string (5 tabs per line), and > no content -- not even a space, just successive adjacent tabs -- in the > empty slots. > (The columns should line up if your reader uses monospaced type.) > 11 aaa 22 bbb 33 ccc > 22 bbb 33 ccc > 33 ccc > Opening Mathematica and using !!filedata reproduces exactly same thing: > 11 aaa 22 bbb 33 ccc > 22 bbb 33 ccc > 33 ccc > Trying to follow this with > fileDataAsViewed = !!fildata > or > fileDataAsViewed = % > doesn't work, however. > Using the Mathematica expression > Import[datafile, Table, > ConversionOptions->{TableSeparators->{{r,n},{t}}}] > gives: > 11 aaa 22 bbb 33 ccc > 22 bbb 33 ccc > 33 ccc > Recreating the text file with a space between the tabs in the empty > slots and applying the same Import[ ] expression, however, gives the > right answer: > 11 aaa 22 bbb 33 ccc > 22 bbb 33 ccc > 33 ccc > I suppose this is not exactly unexpected. The problem is, the app that > creates the (much larger) tab-delimited filedata text file I really want > to load into a Mathematica Table creates numerous blank cells, i.e. > adjacent and unspaced tabs. I guess I'll just have to go at it with a > smart text editor and separate adjacent tabs before trying to load it. === Subject: Questions on Apply function Please look at the following code. I'm wondering the output 1 doesn't give me the right answer. 6435-4545 should be 1890. Is there anything wrong with input 1? It seems that it is correct, because input 3 works well. Peng In[1]:= Apply[(#+{-6750,6435})&,{{6945,-4545},{6945, -4545}},{1}] Out[1]= {{195,13380},{195, 13380}} In[2]:= {-6750,6435}+{6945,-4545} Out[2]= {195,1890} In[3]:= Apply[(#+{a,b})&,{{a1,b1},{a2,b2},{a3,b3}},{1}] Out[3]= {{a+a1,a1+b},{a+a2,a2+b},{a+a3,a3+b}} === Subject: Access control on webMathematica I want to restrict access to webMathematica (2.1) on a Sun running Solaris 10, Mathematica (5.2), Apache (2.0.52) and Tomcat (5.5.12). Apache has access controls (various forms of authentication) so I think if I start Tomcat from Apache, I can control access to webMathematica. The problem is I don't know how to start Tomcat from Apache and even if I did, I have not found enough information to describe how to proceed from there. The Tomcat distribution, which I downloaded from the site suggested in the webMathematica documentation http://jakarta.apache.org/ has no tomcat.conf file, yet the Apache configuration file (httpd.conf) has a line (that is commented out) that includes tomcat.conf Any pointers appreciated. -- Dave K http://www.southminster-branch-line.org.uk/ Please note my email address changes periodically to avoid spam. It is always of the form: month-year@domain. Hitting reply will work for a couple of months only. Later set it manually. The month is always written in 3 letters (e.g. Jan, not January etc) === Subject: Re: Types in Mathematica thread This is fascinating but due to relevancy we can't pursue more here; Root objects are the way that Mathematica represents algebraic numbers. Algebraic numbers have the property that when you perform algebraic operations on them, you always get a single algebraic number as the result. 3.4.3 Algebraic numbers are defined to be numbers that solve polynomial equations with rational coefficients. x (* is an element of *) Algebraics evaluates immediately only for quantities x that are explicitly constructed from rational numbers, radicals and Root objects, or are known to be transcendental. (* from the Built-in Function definition of Algebraics *) So what does it do, try to solve the expression with Simplify, Root, RootReduce, & other functions, and then, if those functions don't work, check a look up table for known transcendentals? But is it reliable--if it can't solve it, how does it know it's transcendental? Interestingly: In[91]:= Not[Element[2^(1/3)+Sqrt[3],Algebraics]] Out[91]= False How does it know that it's not a transcendental when it can't solve for roots? The following is from Help 3.4.3 about the expression just tested: Even though a simple form in terms of radicals does exist, ToRadicals does not find it. How does it know, then? However, you should realize that there are some special cases in which a reduction to radicals is in principle possible, but Mathematica cannot find it. Lastly: any recommended math user groups? Kris > You had me going there, I did look for it :-) > Maybe. Another possibility is the ambiguity; an integer, a negative > number, a rational, a prime, are all reals. > Yes, but obviously if the discussion is about types in the sense that > computer scientists (not me!) use the term, then the type of objects > with Head Real in Mathematica is exactly what is known as inexact > numbers, or floating point number or floats etc.. > Andrzej, why there isn't a test for transcendentals--TranscendentalQ. > That's a joke but I always wanted to see how pi and E were proved to > be transcendental. I wonder if there is an algorithm to capture some > of them, classes of them or something. Those proofs, since they are > finite, must capture some commonality. > Well, actually the proofs for E and Pi are quite different. The proof > of the transcendentality of E was given by Hermite and that of Pi by > Lindemann about a decade later (both in the 19th century). Actually, > it is quite easy to prove that E is transcendental (a simple proof > was given by Hilbert). Hilbert also gave a proof of the fact that Pi > is transcendental, which is simpler than Lindemann's original one, > but still much harder than the proof for Pi. Many years ago as an > undergraduate student I saw Hilbert's proof of the trancendentality > of E done in a number theory class but all I remember now is that you > start by assuming that there is a polynomial with integer > coefficients whose root is E, and than you use properties of some > infinite integrals involving E to prove that this is impossible. I > have no idea how one proves that Pi is transcendental, but I suppose > the general scheme must be similar. It is much easier to prove that > there are transcendental numbers (actually, if you accept Cantor's > diagonal argument - Kronecker did not - then it is almost trivial). > In fact one can also construct explicit numbers for which it is easy > to prove that they are transcendental: the first one was constructed > by Liouville. This number, the Liouville constant, is > Sum[10^(-k!),{k,1,Infinity}] > Mathematica does not know it but correctly computes its numerical > approximation: > NSum[10^(-k!), {k, 1, Infinity}] > 0.110001 > But in any case, all this has nothing to do with types in the sense > of computer science. > Andrzej Kozlowski > Kris > I can't think of why there is no RealQ predicate, but there is > _Real, > a pattern test via the head. > Maybe because it is called InexactNumberQ. >> Andrzej Kozlowski >> === Subject: Re: Re: Types in Mathematica thread > [...] >>5. Mathematica excels in pattern-matching, > Mathematica certainly provides a lot of functionality in its pattern matcher > but pattern matchers in other languages provide many benefits not found in > Mathematica: > 1. Exhaustiveness checking > 2. Redundancy checking > 3. Well-defined performance > For example, the conventional implementation of a function to compute the > length of a list has quadratic complexity in Mathematica: > f[{}] := 0 > f[{h_, t___}] := 1 + f[{t}] This is exactly is it should be. The pattern is reforming a List of length one less at every step of the match. > However, this may get fixed in the future. My colleagues often pleasantly surprise me, but I rather doubt the complexity of this can be improved. When you note conventional implementation you may have in mind complexity that would apply if the inderlying structure were a Lisp-like linked list. But a Mathematica List is more akin to what traditionally is viewed as an array or vector or table, that is, something with a fixed number of contiguous elements (which may or may not actually map to contiguous entities in storage). > The fact that Mathematica distinguishes between up- and down-values is > really incidental (a historical artefact). So I think you're over-analysing > it. I don't see this as artifact. It is important that UpValues behave differently in various aspects from DownValues. Maybe I'm misunderstanding what you mean by an incidental distinction. Daniel Lichtblau Wolfram Research === Subject: Re: Types in Mathematica thread >> You had me going there, I did look for it :-) >> Maybe. Another possibility is the ambiguity; an integer, a negative >> number, a rational, a prime, are all reals. > Yes, but obviously if the discussion is about types in the sense that > computer scientists (not me!) use the term, then the type of objects > with Head Real in Mathematica is exactly what is known as inexact > numbers, or floating point number or floats etc.. As a programmer, not a professional computer scientist, and someone who works with a lot of numeric data I must say I have never seen a type hierarchy of numerics in a programming language that made mathematics easy. It seems to me that if one wanted a type hierarchy then the root would actually be what is informally considered the most complex type (for example complex numbers, but why stop there why not quaternions and octonions? And what about such oddities as Chatin's constant and Aleph numbers?) and the descendants would be reals, integers etc. This is almost exactly the reverse of how the type hierarchy for numerics is usually defined (in fact it's rarely a singly rooted tree but a collection of trees typically rooted at real and integer) and still be unwieldy. For example it would be nice to have a class of imaginaries as a descendent of complex values, but that cannot be the same as the real class which is a superset of the integers and thus in most languages it would be very difficult if not impossible to write functions that took integers as arguments and returned imaginaries since typically one can return parent or child types but not cousin types which require breadth first traversal of the type hierarchy. I suppose you could use some sort of set theoretic expression for numbers to resolve this problem but I can't imagine that would perform acceptably on any physically realizable computer. Ssezi === Subject: Re: Types in Mathematica thread >> Andrzej, why there isn't a test for transcendentals--Transcendental. > TranscendentalNumber.html>: > A number can then be tested to see if it is transcendental using > the Mathematica command Not[Element[x, Algebraics]]. In fact Mathematica knows quite a lot about transcendental numbers: Not[Element[E^Pi, Algebraics]] True Not[Element[Sqrt[2]^Sqrt[2], Algebraics]] True Not[Element[E^Pi+Sqrt[2], Algebraics]] True Of course it won't tell you anything about the numbers that are not known to be transcendental (even though almost certainly are): Element[Pi^E ,Algebraics] Element[Pi^E,Algebraics] (note that Pi is much harder than E, for example we do not know if Element[Pi^Sqrt[2],Algebraics] For E this is well known. Everything in the case of Pi is much harder than in the case of E. Of course all of this is subject to the usual limitations: Element[Exp[Pi*I*(Cos[Pi/27]^2 + Sin[Pi/27]^2)], Algebraics] Element[Exp[Pi*I*(Cos[Pi/27]^2 + Sin[Pi/27]^2)], Algebraics] even though Simplify[Exp[Pi*I*(Cos[Pi/27]^2+Sin[Pi/27]^2)]] -1 If we then use this on an expression that Mathematica can't explicitly simplify to something it knows about you won't get any answer. Thus you certainly you are unlikely discover any new transcendental numbers in this way. Andrzej Kozlowski === Subject: Re: Types in Mathematica thread > Andrzej, why there isn't a test for transcendentals--TranscendentalQ. A number can then be tested to see if it is transcendental using the Mathematica command Not[Element[x, Algebraics]]. === Subject: Re: Types in Mathematica thread > You had me going there, I did look for it :-) > Maybe. Another possibility is the ambiguity; an integer, a negative > number, a rational, a prime, are all reals. Yes, but obviously if the discussion is about types in the sense that computer scientists (not me!) use the term, then the type of objects with Head Real in Mathematica is exactly what is known as inexact numbers, or floating point number or floats etc.. > Andrzej, why there isn't a test for transcendentals--TranscendentalQ. > That's a joke but I always wanted to see how pi and E were proved to > be transcendental. I wonder if there is an algorithm to capture some > of them, classes of them or something. Those proofs, since they are > finite, must capture some commonality. Well, actually the proofs for E and Pi are quite different. The proof of the transcendentality of E was given by Hermite and that of Pi by Lindemann about a decade later (both in the 19th century). Actually, it is quite easy to prove that E is transcendental (a simple proof was given by Hilbert). Hilbert also gave a proof of the fact that Pi is transcendental, which is simpler than Lindemann's original one, but still much harder than the proof for Pi. Many years ago as an undergraduate student I saw Hilbert's proof of the trancendentality of E done in a number theory class but all I remember now is that you start by assuming that there is a polynomial with integer coefficients whose root is E, and than you use properties of some infinite integrals involving E to prove that this is impossible. I have no idea how one proves that Pi is transcendental, but I suppose the general scheme must be similar. It is much easier to prove that there are transcendental numbers (actually, if you accept Cantor's diagonal argument - Kronecker did not - then it is almost trivial). In fact one can also construct explicit numbers for which it is easy to prove that they are transcendental: the first one was constructed by Liouville. This number, the Liouville constant, is Sum[10^(-k!),{k,1,Infinity}] Mathematica does not know it but correctly computes its numerical approximation: NSum[10^(-k!), {k, 1, Infinity}] 0.110001 But in any case, all this has nothing to do with types in the sense of computer science. Andrzej Kozlowski > Kris > I can't think of why there is no RealQ predicate, but there is > _Real, > a pattern test via the head. >> Maybe because it is called InexactNumberQ. >> Andrzej Kozlowski === Subject: Re: Types in Mathematica thread > There is no known algorithm that can determine if a given > algebraic number is real or not. I meant non-algebraic number. Andrzej Kozlowski === Subject: Re: Types in Mathematica thread >> Well, actually the proofs for E and Pi are quite different. > I believe you can derive Pi from E, so it should be possible to > prove the > former from the latter. I have decided to give up discussing computer science issues (see last remark at the bottom) but this is a different matter. Derive Pi form E? What on earth can you mean? Are you by any chance referring to something like the Euler formula: Exp[I Pi]==-1. In that case would you say that you can also derive I form Pi and E? What do you mean by deriving a number from another number? Every real number is some power of E: are they all transcendental? You assert that It should be possible to derive the transcendence of the Pi from the transcendence of E. Well, mathematics is not a subject in which such vague claims have any place. Logically one can also make the claim that it should be possible to derive any true statement from any other true statement since in Logic True implies True. But having what would be considered by most mathematicians as a valid mathematical proof is quite another matter. Please note that Lindemann proved the transcendence of Pi ten years after Hermite proved the transcendence of E. I would speculate that all the analysis you are familiar with was already familiar to Lindemann and yet he, a really great mathematician, could not simply deduce the transcendence of Pi form that of E. Moreover, Lindemann's proof is still considered one of the major achievements in mathematics. Now you come along w assert that it should be possible. Don't you think it is a little bit funny? >> But in any case, all this has nothing to do with types in the sense >> of computer science. > I don't agree. I believe what we are dealing with here fits into > the notion > of inheritance hierarchies as are found in OOP. There are cases > when one > creates an inheritance hierarchy simply for the purpose of grouping > objects > conceptually. The objects of the distinct classes may verywell have > identical implementations. The class of the object is merely a > means of > tagging it. > Since we really don't have a way of modifying the implementation of > such > objects as Pi and E, we may accomplish the same functionality, at > least on > a limited scale, using predicates, and explicitly adding those > items or > features we are interested in to the predicate tests. Thus RealQ > might > test for everything that is a number, and not Complex. Hm. Are you aware of the following: 1. There is no known algorithm that can determine if a given algebraic number is real or not. 2. Consider these simple examples: IntegerQ[Cos[Pi/7]^2+Sin[Pi/7]^2] False and also try this: Element[1 + I*(Cos[Pi/7]^2 + Sin[Pi/7]^2 - 1), Reals] Do you still claim that > Thus RealQ might > test for everything that is a number, and not Complex. As for the difference between the concept of _Real and Reals I think I will simply refer to much bigger authority than myself, namely the professor of computer science at Berkley, R.J. Fateman, who once quite mistakenly accused me on this list of not being aware of this difference . If he is reading this perhaps he might like to take up this debate. I think I will stick to my own area which is mathematics. Andrzej Kozlowski === Subject: Re: Types in Mathematica thread > Yes, but obviously if the discussion is about types in the sense that > computer scientists (not me!) use the term, then the type of objects > with Head Real in Mathematica is exactly what is known as inexact > numbers, or floating point number or floats etc. or intervals. As I've said, using Head is not a generally useful definition of type in the context of Mathematica code: In[1]:= Head[Sqrt[2]] Out[2]= Power > Mathematica does not know it but correctly computes its numerical > approximation: > NSum[10^(-k!), {k, 1, Infinity}] > 0.110001 > But in any case, all this has nothing to do with types in the sense > of computer science. The word type means different things to different people even within computer science. Some type systems provide numerics in the type system, even if it is accidental (e.g. church numerals encoded in C++ templates). -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html === Subject: Re: Types in Mathematica thread You had me going there, I did look for it :-) >> Maybe. Another possibility is the ambiguity; an integer, a negative >> number, a rational, a prime, are all reals. > Yes, but obviously if the discussion is about types in the sense that > computer scientists (not me!) use the term, then the type of objects > with Head Real in Mathematica is exactly what is known as inexact > numbers, or floating point number or floats etc.. Well, not really. A float type is typically a specific kind of storage. In C++, it is implementation defined as to the exact nature of the type, but that implementation-provided definition will never have the features that a Mathematica Real has. But the use of types in computer science is much broader than what we find in the limited and archaic example of C/C++ numeric types. It is also the case that computer scientists will use terms in context specific ways such that the intended concepts are not transferable without modification to a different context. For example, the term instantiation applied to templates means something very different from what it means for classes. >> Andrzej, why there isn't a test for transcendentals--TranscendentalQ. >> That's a joke but I always wanted to see how pi and E were proved to >> be transcendental. I wonder if there is an algorithm to capture some >> of them, classes of them or something. Those proofs, since they are >> finite, must capture some commonality. > Well, actually the proofs for E and Pi are quite different. I believe you can derive Pi from E, so it should be possible to prove the former from the latter. > But in any case, all this has nothing to do with types in the sense > of computer science. I don't agree. I believe what we are dealing with here fits into the notion of inheritance hierarchies as are found in OOP. There are cases when one creates an inheritance hierarchy simply for the purpose of grouping objects conceptually. The objects of the distinct classes may verywell have identical implementations. The class of the object is merely a means of tagging it. Since we really don't have a way of modifying the implementation of such objects as Pi and E, we may accomplish the same functionality, at least on a limited scale, using predicates, and explicitly adding those items or features we are interested in to the predicate tests. Thus RealQ might test for everything that is a number, and not Complex. -- The Mathematica Wiki: http://www.mathematica-users.org/ Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html Math for the WWW: http://www.w3.org/Math/ === Subject: Re: Types in Mathematica thread > 1. Everything is an expression, which is wonderful in its simplicity. Thus > since everything is of the form head[body], everything is typed in at > least one way via the head, and everything can be tested for its type, eg, > with Head[expr]. Trying to define the type of a Mathematica expression as the result returned by Head is not a great idea because the result of Head is itself an arbitrary expression. For example, this definition of type becomes useless in the presence of currying. > ... > 5. Mathematica excels in pattern-matching, Mathematica certainly provides a lot of functionality in its pattern matcher but pattern matchers in other languages provide many benefits not found in Mathematica: 1. Exhaustiveness checking 2. Redundancy checking 3. Well-defined performance For example, the conventional implementation of a function to compute the length of a list has quadratic complexity in Mathematica: f[{}] := 0 f[{h_, t___}] := 1 + f[{t}] However, this may get fixed in the future. > 7. Downvalues are default function structures, or common functions, or > built-in function structures, or broadest class functions. Upvalues > are special case functions, or user-defined functions / modifications > of built-in or default functions, or narrow-case functions, or > context-dependent functions. (This latter is especially important for AI > and for a general understanding of the universe.) The fact that Mathematica distinguishes between up- and down-values is really incidental (a historical artefact). So I think you're over-analysing it. > What is overloading? Mathematica does not provide functions such as > plusII[ i1_Integer, i2_Integer], plusRR[ r1_Real, r2_Real ], plusRI[ > r_Real, i_Integer }, and so forth. You would not be using it if it did > [because it would be a big pain in the rear like we find in other > strongly typed languages--KWC]. Some strongly typed languages, yes. I still use other languages that do separate ints and floats into separate types. > The standard arithmetic operations are overloaded: they work with data of > many different types and perform conversions as necessary. Without a definition of type, such statements have no value. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html === Subject: Re: Types in Mathematica thread You had me going there, I did look for it :-) Maybe. Another possibility is the ambiguity; an integer, a negative number, a rational, a prime, are all reals. Maybe the designers left Help 3.1.1: One way to find out the type of a number in Mathematica is just to pick out its head using Head[expr]. For many purposes, however, it is better to use functions like IntegerQ which explicitly test for particular types. Functions like this are set up to return True if their argument is manifestly of the required type, and to return False otherwise. As a result, IntegerQ[x] will give False, unless x has an explicit integer value. I wonder what pattern test those Q tests actually translate into. Probably simple, but still helpful in designing our own. Andrzej, why there isn't a test for transcendentals--TranscendentalQ. That's a joke but I always wanted to see how pi and E were proved to be transcendental. I wonder if there is an algorithm to capture some of them, classes of them or something. Those proofs, since they are finite, must capture some commonality. Kris > I can't think of why there is no RealQ predicate, but there is _Real, > a pattern test via the head. > Maybe because it is called InexactNumberQ. > Andrzej Kozlowski === Subject: Re: Types in Mathematica thread > I can't think of why there is no RealQ predicate, but there is _Real, > a pattern test via the head. Maybe because it is called InexactNumberQ. Andrzej Kozlowski === Subject: Re: Types in Mathematica thread > something to be said for not using pre-release software for /everything/. > :( And I'm getting used to Google Gmail and sent the last post to you directly, and in rich text format :( > Unfortunately, the latest (at your own peril) bits for my usenet client > seem to be a bit buggy, thus I have lost my previous posts. > My message: > Hmmm, most of you know more than I do about Mathematica and programming > but it seems this thread missed some of the mark. I'm harking to Murray's > email because he gave the best answer. > Do you have a usenet message ID for that? Here is his post, which was in response to yours: Every function you write can be made to type its variables. E.g., f[x_?NumberQ] := x^2 g[lis_List] := Most[lis] normalize[v_ /; VectorQ[v, NumberQ]] := v/Norm[v] use: the built-in NumberQ function to test a property of the input x, and the pattern test for having a head of List, respectively. Sections 2.3.4 and 2.3.5 of The Mathematica Book are two places to find this subject discussed. I don't understand why you don't have access to search in your Linux installation: Whenever I've installed in Linux and selected to install the documentation, the usual HelpBrowser becomes available, including its search capability. The difficulty is, of course, in figuring out what to search for. To find section 2.3.4, I searched for Types in the MasterIndex of the HelpBrowser; the relevant entry was for Types, using patterns to constrain. To find section 2.3.5, I looked for Constraints; the relevant entry was for Constraints, on transformation rules, Condition. - Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 > 1. Everything is an expression, which is wonderful in its simplicity. Thus > since everything is of the form head[body], everything is typed in at > least one way via the head, and everything can be tested for its type, eg, > with Head[expr]. > How does that differ from type checking in such languages as C++? I don't know C++; guessing: not as universal? Not as easy to check? Not as flexible? Not as easy to convert via Apply[newhead, expr]? But see comment at the bottom; we are not railing against C++, or stressing the utility of Mathematica outside of the context of doing mathematical science. > 4. There are other built in type tests that rely on other tests than Head: > NumberQ, NumericQ, IntegerQ, EvenQ, OddQ, PrimeQ; ArrayQ, VectorQ, MatrixQ > (for these there are nice element tests, too), PolynomialQ (element > tests). There are built in structural tests, and I mention these for the > reason mentioned next: SameQ, UnsameQ, OrderedQ, MemberQ, FreeQ, MatchQ, > ValueQ, AtomQ. With these, argument-testing syntax is f[x_?testQ]. q.v. > Section 2.3.5. > RealQ? Ironically that one seems to be missing. Probably an intentional > ommission. Interesting question; here is relevant Helptext: _Real can be used to stand for a real number in a pattern. One way to find out the type of a number in Mathematica is just to pick out its head using Head[expr]. For many purposes, however, it is better to use functions like IntegerQ which explicitly test for particular types. Functions like this are set up to return True if their argument is manifestly of the required type, and to return False otherwise. As a result, IntegerQ[x] will give False, unless x has an explicit integer value. & I tried: In[2]:= RealQ[123] Out[2]= RealQ[123] Nobody home. In[3]:= IntegerQ[123] Out[3]= True In[4]:= IntegerQ[123.] Out[4]= False I can't think of why there is no RealQ predicate, but there is _Real, a pattern test via the head. > 5. Mathematica excels in pattern-matching, which in one form or another > (little pun there), is what all these other tests do. There are many > built-in high level pattern matching functions and devices. Since we can > write our own pattern tests, data typing is limited only by our own > ingenuity. Thus, overall, the type-testing and automatic conversion > facility in Mathematica exceeds what I have seen rigidly implemented in > other languages (I hasten to say I am not broadly educated in other > languages.) > What distinguishes Mathematica from compiled languages is largely that these > mechanism are selfinflicted. That is, Mathematica applies its pattern > matching to Mathematica code as it is evaluated. In C++ the only places > where such a thing is applicable are in the CPP (the root of all C++ evil), > and templates, but only at (pre)compile time. > In a sense, Mathematica is like a scripting language along the lines of > bash, JavaScript, Perl, etc. All of these languages can generate and or > modify code as they interpret code. They all have pattern matching and > substitution rules of one form or another. And of course, Lisp must be > mentioned in this context, though it is not generally considered a > scripting language. > 6. Taking a statement from Maeder a bit out of context, In general, such > [devices] are powerful tools for proving the correctness of an > implementation. He said it in regard to constructors and selectors acting > on datatypes. (M220 v1.1, Datatypes) > Can you clarify what you mean by M220 v1.1, Datatypes? I assume that > relates to the Mathematica training course. Are you referring to text > distributed with the course? Sorry, yes. Incidentally, the new Mathematica Indexer should imho also return text from these courses' manuals & exercises; just a page or two. Then that's informative and advertises the value of the courses. > 7. Downvalues are default function structures, or common functions, or > built-in function structures, or broadest class functions. Upvalues > are special case functions, or user-defined functions / modifications > of built-in or default functions, or narrow-case functions, or > context-dependent functions. (This latter is especially important for AI > and for a general understanding of the universe.) > Upvalues are evaluated when the associated symbol is encountered as an > argument. This precedes the evaluation of downvalues of the function in > which the argument appears. I am not sure of upvalues are ordered according > to specificity in the way downvalues are. I would expect them to be, but I > really don't recall having read that they are. To be clearer: Mathematica evaluates user-defined functions before built-ins, on the principle / assumption that the built-ins are more As discussed in Section 2.5.10, you can associate definitions with symbols either as upvalues or downvalues. Mathematica always tries upvalue definitions before downvalue ones. But we can order upvalues and downvalues to be applied in the order we believe efficacious (qv 2.5.13) > What is overloading? Mathematica does not provide functions such as > plusII[ i1_Integer, i2_Integer], plusRR[ r1_Real, r2_Real ], plusRI[ > r_Real, i_Integer }, and so forth. You would not be using it if it did > [because it would be a big pain in the rear like we find in other > strongly typed languages--KWC]. You simply write > C++ has a very powerful function and operator overloading mechanism. You > certainly can overload, say, + for vectors. You can overload it using > templates which makes the overload definition apply to any abstraction > which matches the template structure. Maybe Maeder got the idea from what he saw in C++. > In[1]:= 1.1 + 2/3 > Out[1]= 1.76667 > and expect it to work. > It depends what exactly you expect. C++ can be fairly tricky regarding > numerical type conversions. But so can Mathematica. There are situations > where you have to treat results as complex numbers, for example, when all > your inputs are real, and typical usage in math would suggest a real > value result. > For automatic type conversion, use definitions like > h /: x_h + i_Integer := plusHI[ x, i ] > or reuse existing code, > h /: x_h + i_Integer := x + makeH[ i ] > where makeH[ i ] is a constructor (type converter) that turns in integer i > into a h data element. > One thing you can't do (AFAIK) is type conversion based on accepted > parameter types in a function call. For example, in C++, you could create > function taking an argument of type string. Took a shot in my previous post at something like this you said. I think this is exactly what Maeder is getting at. Maybe this, as a constructor? makeString[arg1, arg2, datefunction[x_Integer, y_Integer, z_Integer]] := makeString[arg1, arg2, Map[ToString, List @@ dateFunction[x, y, z]] > 8. All the above being said, my conclusion is that Mathematica is a > superior language designed and implemented by superior intellects. As > Andrzej just said, post a problem to MathGroup before assuming Mathematica > can't do something. > You really have to put that in perspective. Almost every program I use, to > include Mathematica is written in either C or C++. Some have a > considerable amount of additional code written in some form of an > interpreted language. For example Mozilla has a lot of JavaScript built > in. Emacs is largely implemented in Lisp, but the Lisp interpreter itself > is written in C. Even Java is written in C and C++. Mathematica is very > specialized, and is not well suited to creating such facilities as user > interfaces. In many ways its graphics support is fairly limited in > comparison to development environments such as OpenSceneGraph. OK, I agree; overall; but I don't think people come to Mathematica to do the type of GUI-driven Rapid Application Development that I did in VB. ****Within the context of _doing mathematical science_ Mathematica is open-ended and very high-level compared to any other language/environment I've seen.**** A superior language, like C++. Agree on the graphics capabilities; they are superb in one respect but you're right, very specialized, and limited in others. > In the C++ Standard Library there are 57 (IIRC) generic algorithms for > operating on generic collections. Many of these have direct parallels in > Mathematica. Also have a look at section 5.2.1 of > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf > As I've said, Mathematica is a very specialized language. To compare it to > C++ in terms of superiority would not make sense. If every program written > in C++ failed to function at the same time, the entire technological > infrastructure of the planet would come to a screeching halt. The same > cannot be said of Mathematica. OTOH, if I want to solve differential > equations using familiar symbols and relatively easy to use constructs, I > would not turn to C++. If I wanted to write a program to do that, I most > certainly /would/ use C++. Meant Mathematica? I hope nothing I said sounded like disparaging the C family. Civ would come to a halt without it or something like it. And mathematical science is pretty important, too. RED--Rapid Experiment Design--in mathematical science is what Mathematica is designed for. And having spent some hours the last few days attempting to parse the Lisp code of a world leader in classifier systems (AI) (thankfully with his help), this opinion is fresh in my mind. Before we assume Mathematica can't do something _in that context_, I think we should let MathGroup take a shot at it. Onward and upward, Kris > -- > The Mathematica Wiki: http://www.mathematica-users.org/ > Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html > Math for the WWW: http://www.w3.org/Math/ === Subject: Re: Types in Mathematica thread OK, this is my third attempt to write a reply to this message. There is something to be said for not using pre-release software for /everything/. :( Unfortunately, the latest (at your own peril) bits for my usenet client seem to be a bit buggy, thus I have lost my previous posts. > My message: > Hmmm, most of you know more than I do about Mathematica and programming > but it seems this thread missed some of the mark. I'm harking to Murray's > email because he gave the best answer. Do you have a usenet message ID for that? > 1. Everything is an expression, which is wonderful in its simplicity. Thus > since everything is of the form head[body], everything is typed in at > least one way via the head, and everything can be tested for its type, eg, > with Head[expr]. How does that differ from type checking in such languages as C++? > 4. There are other built in type tests that rely on other tests than Head: > NumberQ, NumericQ, IntegerQ, EvenQ, OddQ, PrimeQ; ArrayQ, VectorQ, MatrixQ > (for these there are nice element tests, too), PolynomialQ (element > tests). There are built in structural tests, and I mention these for the > reason mentioned next: SameQ, UnsameQ, OrderedQ, MemberQ, FreeQ, MatchQ, > ValueQ, AtomQ. With these, argument-testing syntax is f[x_?testQ]. q.v. > Section 2.3.5. RealQ? Ironically that one seems to be missing. Probably an intentional ommission. > 5. Mathematica excels in pattern-matching, which in one form or another > (little pun there), is what all these other tests do. There are many > built-in high level pattern matching functions and devices. Since we can > write our own pattern tests, data typing is limited only by our own > ingenuity. Thus, overall, the type-testing and automatic conversion > facility in Mathematica exceeds what I have seen rigidly implemented in > other languages (I hasten to say I am not broadly educated in other > languages.) What distinguishes Mathematica from compiled languages is largely that these mechanism are selfinflicted. That is, Mathematica applies its pattern matching to Mathematica code as it is evaluated. In C++ the only places where such a thing is applicable are in the CPP (the root of all C++ evil), and templates, but only at (pre)compile time. In a sense, Mathematica is like a scripting language along the lines of bash, JavaScript, Perl, etc. All of these languages can generate and or modify code as they interpret code. They all have pattern matching and substitution rules of one form or another. And of course, Lisp must be mentioned in this context, though it is not generally considered a scripting language. > 6. Taking a statement from Maeder a bit out of context, In general, such > [devices] are powerful tools for proving the correctness of an > implementation. He said it in regard to constructors and selectors acting > on datatypes. (M220 v1.1, Datatypes) Can you clarify what you mean by M220 v1.1, Datatypes? I assume that relates to the Mathematica training course. Are you referring to text distributed with the course? > 7. Downvalues are default function structures, or common functions, or > built-in function structures, or broadest class functions. Upvalues > are special case functions, or user-defined functions / modifications > of built-in or default functions, or narrow-case functions, or > context-dependent functions. (This latter is especially important for AI > and for a general understanding of the universe.) Upvalues are evaluated when the associated symbol is encountered as an argument. This precedes the evaluation of downvalues of the function in which the argument appears. I am not sure of upvalues are ordered according to specificity in the way downvalues are. I would expect them to be, but I really don't recall having read that they are. > What is overloading? Mathematica does not provide functions such as > plusII[ i1_Integer, i2_Integer], plusRR[ r1_Real, r2_Real ], plusRI[ > r_Real, i_Integer }, and so forth. You would not be using it if it did > [because it would be a big pain in the rear like we find in other > strongly typed languages--KWC]. You simply write C++ has a very powerful function and operator overloading mechanism. You certainly can overload, say, + for vectors. You can overload it using templates which makes the overload definition apply to any abstraction which matches the template structure. > In[1]:= 1.1 + 2/3 > Out[1]= 1.76667 > and expect it to work. It depends what exactly you expect. C++ can be fairly tricky regarding numerical type conversions. But so can Mathematica. There are situations where you have to treat results as complex numbers, for example, when all your inputs are real, and typical usage in math would suggest a real value result. > For automatic type conversion, use definitions like > h /: x_h + i_Integer := plusHI[ x, i ] > or reuse existing code, > h /: x_h + i_Integer := x + makeH[ i ] > where makeH[ i ] is a constructor (type converter) that turns in integer i > into a h data element. One thing you can't do (AFAIK) is type conversion based on accepted parameter types in a function call. For example, in C++, you could create function taking an argument of type string. > 8. All the above being said, my conclusion is that Mathematica is a > superior language designed and implemented by superior intellects. As > Andrzej just said, post a problem to MathGroup before assuming Mathematica > can't do something. You really have to put that in perspective. Almost every program I use, to include Mathematica is written in either C or C++. Some have a considerable amount of additional code written in some form of an interpreted language. For example Mozilla has a lot of JavaScript built in. Emacs is largely implemented in Lisp, but the Lisp interpreter itself is written in C. Even Java is written in C and C++. Mathematica is very specialized, and is not well suited to creating such facilities as user interfaces. In many ways its graphics support is fairly limited in comparison to development environments such as OpenSceneGraph. In the C++ Standard Library there are 57 (IIRC) generic algorithms for operating on generic collections. Many of these have direct parallels in Mathematica. Also have a look at section 5.2.1 of http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf As I've said, Mathematica is a very specialized language. To compare it to C++ in terms of superiority would not make sense. If every program written in C++ failed to function at the same time, the entire technological infrastructure of the planet would come to a screeching halt. The same cannot be said of Mathematica. OTOH, if I want to solve differential equations using familiar symbols and relatively easy to use constructs, I would not turn to C++. If I wanted to write a program to do that, I most certainly /would/ use C++. -- The Mathematica Wiki: http://www.mathematica-users.org/ Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html Math for the WWW: http://www.w3.org/Math/ === Subject: Re: How would you evaluate this limit in Mathmatica David Park was kind enough to send me his notebook on this problem and gant permission for me to publish this post. His notebook contains a lot of explanation and visualizations created using the (commercially available) Cardano 3 package. Based off of his work, both in the notebook and in the Cardano 3 package, I have created four plots that (somewhat) illustrate why one must take care in evaluating the limit posed in this thread. Here is the code to create the plots: f[a_][x_]=((1+4*x^2)^(1/4)-(1+5*x^2)^(1/5))/(a^(-(x^2/2))-Cos[x]) SetOptions[DensityPlot,Mesh[Rule]False,PlotPoints[Rule]400, ColorFunctionScaling[Rule]False, ColorFunction[Rule] Function[RGBColor[Min[Max[0,Re[#]]^(1/1.5),1],Min[Abs[Im[#]]^(1/30),1], Min[Abs[Min[0,Re[#]]]^(1/1.5),1]]],FrameLabel[Rule]{x,a}]; SetOptions[Plot3D,PlotPoints[Rule]400,ViewPoint[Rule]{0,0,3}, Mesh[Rule]False,AxesLabel[Rule]{x,a,f}]; DensityPlot[f[a][x],{x,-10,10},{a,-10,10}]; Plot3D[f[a][x],{x,-10,10},{a,0,10}]; DensityPlot[f[a][x],{x,-.01 E,.01 E},{a,.99 E,1.01 E}]; Plot3D[f[a][x],{x,-.01 E,.01 E},{a,.99 E,1.01 E}]; For the density plots, I have spliced the positive real parts of the function into the red channel, the negative real parts of the function into the blue channel, and the absolute value of the imaginary part of the function into the green channel. Black just indicates the function is close to zero. You can clearly see the discontinuity and the zero David mentioned passing straight through {0,E}. Finding the limit at the confluence of these features looks to be a risky venture at best. So, one of the questions still on my mind is: Does Mathematica make an error in the following evaluation: In[74]:= Limit[f[a][x],x[Rule]0] Out[74]= 0 P.S. The exponents in the color function allow one to amplify the color scaling, which I have specifically used to make sure the function isn't complex for positive a. -- http://chrischiasson.com/contact/chris_chiasson === Subject: Re: How would you evaluate this limit in Mathmatica > ..I am interested in getting comments about doing this in > Mathematica. > I'm also interested in how one would teach solving limits using Mathematica. Hi. Just something different.. equ = ((1 + 4*x^2)^(1/4) - (1 + 5*x^2)^(1/5))/(a^(-x^2/2) - Cos[x]) ContourPlot[equ, {x, -1, 1}, {a, 2, 4}, Contours -> 20, PlotPoints -> 300]; This picture suggest a limit at x=0, with a special case of 'a' being near 2.7 (ie E) The White/Black band suggests a discontinuity jump from high to low. Interchanging the option to the following suggests that the limit is zero. (Adjust as desired..) Contours -> {0, .01} Contours -> {0, -.01} Contours -> {-.01,0, .01} Other options w/ Mathematica... a = E; Needs[NumericalMath`NLimit`] Numerically, NLimit isn't so hot on the answer being 6 6 - NLimit[equ, x -> 0, Terms -> 13, WorkingPrecision -> 50] 0. * 10^-4 But the option SequenceLimit worked harder in convincing us the answer is 6. 6 - NLimit[equ, x -> 0, Terms -> 13, WorkingPrecision -> 50, Method -> SequenceLimit] 3. * 10^-23 Again, just some more options. (I Think David's comments are excellent !!) -- Dana DeLouis === Subject: Types in Mathematica >> I believe most people here will agree that Mathematica is not a >> strongly typed programming language. > Actually, one can productively say that Mathematica is a strongly typed > language because it has only one type (expr). > Is that assertion really meaningful or useful? Yes. It is a direct result of Mathematica being a rewrite language. >> What would a type system in Mathematica be? > Anything you want. > What would a _useful_ type system in Mathematica be? I think there are many possible answers. However, I am not sure of their utility. Perhaps it would be nice if you could write conventional code in Mathematica and have it run as fast and be as statically checked as it would be in other languages. >> What might be lost? > Simplicity, brevity, clarity. > It might be argued that these could be increased in some circumstance by > having a type system. Yes. > Likewise, performance might take a hit from extensive typechecking. If your type checker is very slow (e.g. if it were written in Mathematica) and your program was doing large amounts of type-checked run-time code generation and the resulting programs were trivial then yes. However, that is unlikely. > When I think about dynamic type checking, I think about determining the > actual type of an object referred to by a variable referring to a basetype > of multiple derived types. I can imagine circumstances where such a > feature might be useful in Mathematica. The example of testing to > determine if some object represents a real number was intended to > suggest this. Yes. > An integer is a real number, as is a rational number. In mathematics, yes. > That is an > is a relation in OOP terminology, and thus implies an inheritance > hierarchy. Maybe. I don't think that OOP is relevant to this discussion. > Because Mathematica is a rewrite system, it is comparatively easy to > write interpreters and compilers in it (compared to C, for example). > I can certainly imagine writing a C++ parser in Mathematica, but that > makes > assumptions about the input. In particular, that it is written in C++ > which already has a type system defined. You could define a new language that is a subset of Mathematica's existing language that is designed to be type checked. You could run programs in this language either without type checking in the current Mathematica, or run them through a form of compiler to have them type checked. I think this is clearly preferable to incorporating a completely different language into Mathematica. > As a type > system and, more importantly, a type checker is part of a > compiler/interpreter, these can be written in Mathematica. > Yes, but see my previous comment. You would need a means of expressing > types in Mathematica in order to check them. Not necessarily. A type system could be implemented inside the Mathematica kernel and the user need not know. This could be used to improve performance under the hood. > You could write a type checking function to type check Mathematica > programs. This could mimic an ML-like type system, for example. > I have wanted to study ML for a long time, but I have to plead virtual > ignorance here. There are many such languages (e.g. SML, OCaml, Haskell) that are much better representations of modern type systems than C++, Java etc. > To improve performance, the use of a more refined type system could be > entirely automated and invisible to the user. > One aspect of comparing Mathematica to compiled languages in the area of > type checking is that compiled languages typically do their type checking > at compile time. Yes. In the context of type checking in Mathematica, static vs dynamic type checking really refers to whether or not the checking can be hoisted from the algorithm that is being evaluated. > Yes, dynamic type checking can happen at runtime, but > that already assumes certain compile time checking has been performed. What compile-time checking is required by dynamic type checking? > Furthermore, dynamic type checking usually incurs a performance hit. Yes. > If > there were typechecking in Mathematica, that could mean a test is > perfromed for every parameter each time a function is evaluated. Optimising those tests away is premature. > Ironically, in C++, it appears that functional programming constructs tend > to be slower than procedural ones. In Mathematica, the opposite appears > to be the case. The same may be true of type checking. Do you mean that static type checking might slow Mathematica down? -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html === Subject: Re: Package development I felt exactly the same way until Chris French recently introduced me to AutoIndent -> False as available in the option inspector. AutoIndent is set to Automatic by default; set AutoIndent to False and suddenly you can format your code again, all in the notebook FrontEnd. (That said, I agree with David that the real problem is the instability of comments.) Trevor. === Subject: Re: Formatting GridBox with ColumnAlignments > r3 = DisplayForm[GridBox[{{r1}, {r2}}, ColumnAlignments -> Center]] > will do the trick ??? Try evaluating r3 with Using ColumnAlignments -> Center and we find * nothing above the 1 in r2; * the 1 in r1 above the 2 in r2; * the 2 in r1 above the 3 in r2; * the 3 in r1 above the 4 in r2; * nothing above the 5 in r2. In other words, ColumnAlignments -> Center causes r1 and r2 to be *centered*, as we would expect. The challenge is to (more-or-less) left-align r1 over r2, such that: * the 1 in r1 will be above the 1 in r2. (Think of r1 and r2 as two different lines of symbolic material to be left-aligned in r3, under the condition that the leftmost numbers in each should align exactly, ignoring the start-parenthesis in r1 and the overbracket in r2.) Is this possible? Trevor. === Subject: Re: Formatting GridBox with ColumnAlignments r3 = DisplayForm[GridBox[{{r1}, {r2}}, ColumnAlignments -> Center]] will do the trick yehuda > A formatting question: > If we let > r1 = DisplayForm[RowBox[{(, 1, 2, 3, )}]] > and > r2 = DisplayForm[Overscript[RowBox[{1, 2, 3, 4, 5}], [OverBracket]]] > and then put r1 and r2 together in > r3 = DisplayForm[GridBox[{{r1}, {r2}}, ColumnAlignments -> Left]] > then we get something that's not very aligned at all. (Evaluating r3 > shows quit a bit of whitespace prior to the open parenthesis in r2, > making the two rows in the grid look somewhat messy). > Question: is it possible to make the 1s align exactly in r3? > (ColumnAlignments -> 1 isn't doing the trick.) > Trevor. === Subject: Mathematica and Transcendental Numbers Mathematica's treatment of transcendental numbers is quite sophisticated . Consider these two contrasting cases: Element[E^(Cos[(231/3577)*Pi]^2 + Sin[(231/3577)*Pi]^2),Algebraics] False Element[Pi^(Cos[(231/3577)*Pi]^2 + Sin[(231/3577)*Pi]^2),Algebraics] Element[Pi^(Cos[(231/3577)*Pi]^2 + Sin[(231/3577)*Pi]^2),Algebraics] Actually, both answers should be False, since Cos[(231/3577)*Pi]^2 + Sin[(231/3577)*Pi]^2) ==1 and both Pi and E are transcendental. It is of course not surprising that Mathematica can't get the second problem right since trigonometric simplifications are not performed automatically by the evaluator unless Simplify is used. But to deal with the first input correctly Mathematica makes use of some fairly advanced mathematical knowledge. First of all it knows that numbers like Cos[(231/3577)*Pi] and Sin[(231/3577)*Pi] are algebraic without evaluating them. Then of course it makes use of the fact that algebraic functions of algebraic numbers are themselves algebraic. And finally, having determined that the exponent is an algebraic number, Mathematica makes use of the fact that E^a, where a is an algebraic number is transcendental. For Pi the analogous result is unproved so the second input is returned unevaluated. Usually, much less is known in this context about Pi then E; however, there is one exception, which Mathematica also knows: Element[E^Pi,Algebraics] False while Element[E^E, Algebraics] Element[E^E, Algebraics] is not known. In addition to the numbers that are known to be algebraic and the ones known to be transcendental there is a large number of those about which we do not know if they are algebraic or not. Since the problem of deciding if a number is algebraic or not is, if I remember correctly, undecidable in general, I tend to refer to all numbers that are not known to be algebraic (such as Pi^Pi) as non-algebraic. Transcendental means something that has been proved to be non-algebraic. Andrzej Kozlowski