From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: Complex numbers Date: Fri, 15 Apr 2011 09:50:23 -0600 Message-ID: <87lizba3d9.fsf@gmail.com> References: <87tye24xlf.fsf@gmail.com> <87aafum7nq.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([140.186.70.92]:43374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QAlqT-0001PQ-BD for emacs-orgmode@gnu.org; Fri, 15 Apr 2011 12:26:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QAlqP-0006pA-BQ for emacs-orgmode@gnu.org; Fri, 15 Apr 2011 12:26:09 -0400 Received: from mail-px0-f179.google.com ([209.85.212.179]:50245) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QAlqP-0006p3-2B for emacs-orgmode@gnu.org; Fri, 15 Apr 2011 12:26:05 -0400 Received: by pxi2 with SMTP id 2so1623434pxi.38 for ; Fri, 15 Apr 2011 09:26:04 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Renier Marchand Cc: emacs-orgmode@gnu.org Renier Marchand writes: > It is a cool idea yes, but I quickly learned that it also have its > problems, i.e. you cant really create nice column formulas because the > reference is not aware of "the current row" etc. > > The biggest problem as I see it is that emacs-lisp does not support > the complex data type as lisp (natively) do. I am going to look into a > way of representing it.. maybe a two element lisp list (re im). I am > not really versed in lisp so it is a bit of a problem to modify code, > but I am looking into it. > > One problem that I have encountered is that when a two element list is > referenced in the following scenario > > | (1 2) | #ERROR | > #+TBLFM: $2=3D'(sbe "myfunc" (data $1)) > > an error is caused because lisp is trying to execute this list > appearing struct, but when I do > > | (1 2) | > | (2 3) | > | resul | > #+TBLFM: $1@3=3D'(sbe "myfunc" (data @1$1..@2$1)) > > no error is reported because it is assumed to be a list of data for my > python code. i.e. it is sent as [[1,2],[2,3]] which is what I want. Is > there a way to get more consistent behavior? > If you represent the complex number as a vector instead of a list, then elisp will not assume that the first element is a function and try to evaluate the data, e.g. | [1 2] | |------------------| | real:1 complex:2 | #+TBLFM: @2$1=3D'(sbe real (it @1$1)) #+source: real(it=3D'()) #+begin_src emacs-lisp (format "real:%d complex:%d" (aref it 0) (aref it 1)) #+end_src also, a quoted list '(1 2) would work... Best -- Eric > > Thank you. > Renier > > On Wed, Apr 13, 2011 at 6:35 PM, Eric Schulte wr= ote: >> Renier Marchand writes: >> >>> I have found the following way to reference my data correctly without >>> having to quote it or have data rewritten. >>> >>> I do: >>> >>> =C2=A0 =C2=A0 =C2=A0 #+tblname: my-data >>> =C2=A0 =C2=A0 =C2=A0 | hmin | >>> =C2=A0 =C2=A0 =C2=A0 |------| >>> =C2=A0 =C2=A0 =C2=A0 | =C2=A0 =C2=A0 =C2=A0| >>> =C2=A0 =C2=A0 =C2=A0 | 0.05 | >>> =C2=A0 =C2=A0 =C2=A0 | =C2=A00.2 | >>> =C2=A0 =C2=A0 =C2=A0 | =C2=A00.2 | >>> =C2=A0 =C2=A0 =C2=A0 #+TBLFM: @5$1=3D'(sbe "myfunc" (data "my-data[3:4,= 0]")) >>> >>> This also works for complex data as you suggested. >>> >> >> Very cool, I would never have thought to use a reference within a table >> formula. >> >>> >>> But is there a way to refer in the formula to the current table >>> instead of a specific table? Because this would obviously not work for >>> multiple tables with the same name. (i.e. copy and paste for another >>> dataset) >>> >> >> No, there is no support for that sort of usage, and adding such a >> position dependent reference would be a fairly large change from the >> existing reference resolution mechanisms. >> >> Best -- Eric >> >>> >>> Regards, >>> >>> Renier >>> >>> On Wed, Apr 13, 2011 at 5:52 AM, Eric Schulte = wrote: >>>> Hi Renier, >>>> >>>> The Org-mode table machinery is interpreting the values of your table >>>> cells as emacs lisp (given that the table formula is an elisp, rather >>>> than a calc formula). =C2=A0Due to the "," the result is a weird neste= d list >>>> which confuses your python code block. =C2=A0Some options here include= ... >>>> >>>> 1. wrapping these cells in quotes so that they are passed to the python >>>> =C2=A0 block as strings... >>>> >>>> =C2=A0 #+source: parameter-variation(data=3D0) >>>> =C2=A0 #+begin_src python :result values >>>> =C2=A0 =C2=A0 return 'text' >>>> =C2=A0 #+end_src >>>> >>>> =C2=A0 |---------------------------------------| >>>> =C2=A0 | "(0.0331901438056,0.000535222885197)" | >>>> =C2=A0 | "(0.0333434157791,0.000537930174356)" | >>>> =C2=A0 | "(0.0345727512157,0.000559346040457)" | >>>> =C2=A0 | "(0.0353146483908,0.000571501584524)" | >>>> =C2=A0 | "(0.0355522909393,0.000574387067408)" | >>>> =C2=A0 | "(0.0356575682336,0.000574851263615)" | >>>> =C2=A0 | "(0.0357806926897,0.000575051685084)" | >>>> =C2=A0 |---------------------------------------| >>>> =C2=A0 | text =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| >>>> =C2=A0 #+TBLFM: @8$1=3D'(sbe parameter-variation (nums @1$1..@7$1)) >>>> >>>> 2. referencing the table from an external code block, rather than insi= de >>>> =C2=A0 of a table formula. =C2=A0This is probably the easier solution,= but it >>>> =C2=A0 doesn't insert the result into your table, unless you do someth= ing >>>> =C2=A0 tricky like give the code block and the table the same name so = that >>>> =C2=A0 the results of the code block replace the table... >>>> >>>> =C2=A0 #+results: complex-data >>>> =C2=A0 |-------------------------------------| >>>> =C2=A0 | (0.0331901438056,0.000535222885197) | >>>> =C2=A0 | (0.0333434157791,0.000537930174356) | >>>> =C2=A0 | (0.0345727512157,0.000559346040457) | >>>> =C2=A0 | (0.0353146483908,0.000571501584524) | >>>> =C2=A0 | (0.0355522909393,0.000574387067408) | >>>> =C2=A0 | (0.0356575682336,0.000574851263615) | >>>> =C2=A0 | (0.0357806926897,0.000575051685084) | >>>> =C2=A0 #+TBLFM: @8$1=3D'(sbe parameter-variation (nums @1$1..@7$1)) >>>> >>>> =C2=A0 #+begin_src python :var data=3Dcomplex-data >>>> =C2=A0 =C2=A0 return data >>>> =C2=A0 #+end_src >>>> >>>> Hope this helps -- Eric >>>> >>>> Renier Marchand writes: >>>> >>>>> Hi. >>>>> >>>>> I have been playing around with complex data that has been returned >>>>> from Python. This is obviously not in calc.el format but if I change >>>>> them to the correct format I can manipulate them using calc. >>>>> >>>>> but >>>>> >>>>> When I want to pass the complex numbers (python format) to python I >>>>> get an error. If I pass real number everything works as expected >>>>> >>>>> For example: >>>>> >>>>> =C2=A0 =C2=A0 =C2=A0 #+source: parameter-variation(data=3D0) >>>>> =C2=A0 =C2=A0 =C2=A0 #+begin_src python :result values >>>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 return 'text' >>>>> =C2=A0 =C2=A0 =C2=A0 #+end_src >>>>> >>>>> >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 |=C2=A0 hmin | =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 | >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |---+-------+-------------------------= ------------| >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 | =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= | >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 |=C2=A0 0.05 | (0.033190= 1438056,0.000535222885197) | >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 |=C2=A0=C2=A0 0.1 | (0.0= 333434157791,0.000537930174356) | >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 |=C2=A0=C2=A0 0.3 | (0.0= 345727512157,0.000559346040457) | >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 |=C2=A0=C2=A0 0.6 | (0.0= 353146483908,0.000571501584524) | >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 |=C2=A0=C2=A0 0.9 | (0.0= 355522909393,0.000574387067408) | >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 |=C2=A0=C2=A0 1.2 | (0.0= 356575682336,0.000574851263615) | >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 |=C2=A0 10.0 | (0.035780= 6926897,0.000575051685084) | >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | $ | x=3D0.1 | y=3D0.1=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 | >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 |=C2=A0 text | =C2=A0 = =C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 #+TBLFM: @11$2=3D'(sbe "parameter-vari= ation" (data >>>>> @3$2..@9$2))::@11$3=3D'(sbe "parameter-variation" (data @3$3..@9$3)) >>>>> >>>>> i.e. I get the word 'text' returned for column 2 where there are real >>>>> numbers but I don't get anything returned where there are complex >>>>> numbers. As you can see, there are no actual calculation performed on >>>>> the data I am just returning 'text' so I am expecting it to work in >>>>> both instances. >>>>> >>>>> The debug sessions show the following for the real column: >>>>> >>>>> Substitution history of formula >>>>> Orig: =C2=A0 '(sbe "parameter-variation" (data @3$2..@9$2)) >>>>> $xyz-> =C2=A0'(sbe "parameter-variation" (data @3$2..@9$2)) >>>>> @r$c-> =C2=A0'(sbe "parameter-variation" (data #("0.05" 0 4 (fontifie= d t >>>>> face org-table)) #("0.1" 0 3 (fontified t face org-table)) #("0.3" 0 3 >>>>> (fontified t face org-table)) #("0.6" 0 3 (fontified t face >>>>> org-table)) #("0.9" 0 3 (fontified t face org-table)) #("1.2" 0 3 >>>>> (fontified t face org-table)) #("10.0" 0 4 (fontified t face >>>>> org-table)))) >>>>> $1-> =C2=A0 =C2=A0'(sbe "parameter-variation" (data #("0.05" 0 4 (fon= tified t >>>>> face org-table)) #("0.1" 0 3 (fontified t face org-table)) #("0.3" 0 3 >>>>> (fontified t face org-table)) #("0.6" 0 3 (fontified t face >>>>> org-table)) #("0.9" 0 3 (fontified t face org-table)) #("1.2" 0 3 >>>>> (fontified t face org-table)) #("10.0" 0 4 (fontified t face >>>>> org-table)))) >>>>> Result: text >>>>> Format: NONE >>>>> Final: =C2=A0text >>>>> >>>>> and for the complex column: >>>>> >>>>> Substitution history of formula >>>>> Orig: =C2=A0 '(sbe "parameter-variation" (data @3$3..@9$3)) >>>>> $xyz-> =C2=A0'(sbe "parameter-variation" (data @3$3..@9$3)) >>>>> @r$c-> =C2=A0'(sbe "parameter-variation" (data >>>>> #("(0.0331901438056,0.000535222885197)" 0 35 (fontified t face >>>>> org-table)) #("(0.0333434157791,0.000537930174356)" 0 35 (fontified t >>>>> face org-table)) #("(0.0345727512157,0.000559346040457)" 0 35 >>>>> (fontified t face org-table)) #("(0.0353146483908,0.000571501584524)" >>>>> 0 35 (fontified t face org-table)) >>>>> #("(0.0355522909393,0.000574387067408)" 0 35 (fontified t face >>>>> org-table)) #("(0.0356575682336,0.000574851263615)" 0 35 (fontified t >>>>> face org-table)) #("(0.0357806926897,0.000575051685084)" 0 35 >>>>> (fontified t face org-table)))) >>>>> $1-> =C2=A0 =C2=A0'(sbe "parameter-variation" (data >>>>> #("(0.0331901438056,0.000535222885197)" 0 35 (fontified t face >>>>> org-table)) #("(0.0333434157791,0.000537930174356)" 0 35 (fontified t >>>>> face org-table)) #("(0.0345727512157,0.000559346040457)" 0 35 >>>>> (fontified t face org-table)) #("(0.0353146483908,0.000571501584524)" >>>>> 0 35 (fontified t face org-table)) >>>>> #("(0.0355522909393,0.000574387067408)" 0 35 (fontified t face >>>>> org-table)) #("(0.0356575682336,0.000574851263615)" 0 35 (fontified t >>>>> face org-table)) #("(0.0357806926897,0.000575051685084)" 0 35 >>>>> (fontified t face org-table)))) >>>>> Result: >>>>> Format: NONE >>>>> Final: >>>>> >>>>> >>>>> Thank you very much for your help. >>>>> >>>>> Renier >>>>> >>>>> >>>> >>>> -- >>>> Eric Schulte >>>> http://cs.unm.edu/~eschulte/ >>>> >>> >> >> -- >> Eric Schulte >> http://cs.unm.edu/~eschulte/ >> > --=20 Eric Schulte http://cs.unm.edu/~eschulte/