NYCJUG/2017-07-11
Meeting Agenda for NYCJUG 20170711 ---------------------------------- 1. Beginner's regatta: see "Generating Excel Formulas" See also "Extracting and Using Formatted Data". 2. Show-and-tell: see "OpenWhisk Docker J image under Alpine" and "Complex Residue". 3. Advanced topics: see "Reading and Writing Images in J", and "J’s Startup Sequence". 4. Learning and teaching J: see "Learning J: Complex Number Problem". +.--------------------+. The course of a river is almost always disapproved of by its source. - Cocteau
Beginner's regatta
Generating Excel Formulas
Sometimes you will have a set of formulas in Excel that do not lend themselves well to copying even though there is a pattern to them. Say you want to move around cells in the following pattern:
The pattern shown here repeats, mapping a 10x6 table from the left to the linear pattern shown on the right. However, it doesn’t repeat in a fashion that Excel handles when you copy a row of formulas to the next row. One way to handle this is to create the first row on the right, then turn on formula display and copy this formula to be a template for the following rows. You might have something like this to be your template for the first row:
=CIQ_Export__05152017.csv!$A$2 =CIQ_Export__05152017.csv!$D$7 =CIQ_Export__05152017.csv!$E$7 =CIQ_Export__05152017.csv!$F$7 =CIQ_Export__05152017.csv!$D$2 =CIQ_Export__05152017.csv!$E$2 =CIQ_Export__05152017.csv!$F$2 =CIQ_Export__05152017.csv!$D$3 =CIQ_Export__05152017.csv!$E$3 =CIQ_Export__05152017.csv!$F$3 =CIQ_Export__05152017.csv!$D$4 =CIQ_Export__05152017.csv!$E$4 =CIQ_Export__05152017.csv!$F$4 =CIQ_Export__05152017.csv!$D$5 =CIQ_Export__05152017.csv!$E$5 =CIQ_Export__05152017.csv!$F$5 =CIQ_Export__05152017.csv!$D$6 =CIQ_Export__05152017.csv!$E$6 =CIQ_Export__05152017.csv!$F$6 =CIQ_Export__05152017.csv!$D$8 =CIQ_Export__05152017.csv!$E$8 =CIQ_Export__05152017.csv!$F$8 =CIQ_Export__05152017.csv!$D$9 =CIQ_Export__05152017.csv!$E$9 =CIQ_Export__05152017.csv!$F$9 =CIQ_Export__05152017.csv!$D$10 =CIQ_Export__05152017.csv!$E$10 =CIQ_Export__05152017.csv!$F$10 =CIQ_Export__05152017.csv!$D$11 =CIQ_Export__05152017.csv!$E$11 =CIQ_Export__05152017.csv!$F$11
Where the above is on a single line.
To generate the formulas for the following lines of our target, we extract the numeric portion of the cell addresses, giving us something like this:
$nums=. 2 7 7 7 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 8 8 8 9 9 9 10 10 10 11 11 11 31
We then set up our base line of formulas – our template – as a boxed array of cells like this:
$base=. <;._1 TAB,'=CIQ_Export__05152017.csv!$A$2 =CIQ_Export__05152017.csv!$D$7 =CIQ_Export__05152017.csv!$E$7 =CIQ_Export__05152017.csv!$F$7 =CIQ_Export__05152017.csv!$D$2 =CIQ_Export__05152017.csv!$E$2 =CIQ_Export__05152017.csv!$F$2 =CIQ_Export__05152017.csv!$D$3 =CIQ_Export__05152017.csv!$E$3 =CIQ_Export__05152017.csv!$F$3 =CIQ_Export__05152017.csv!$D$4 =CIQ_Export__05152017.csv!$E$4 =CIQ_Export__05152017.csv!$F$4 =CIQ_Export__05152017.csv!$D$5 =CIQ_Export__05152017.csv!$E$5 =CIQ_Export__05152017.csv!$F$5 =CIQ_Export__05152017.csv!$D$6 =CIQ_Export__05152017.csv!$E$6 =CIQ_Export__05152017.csv!$F$6 =CIQ_Export__05152017.csv!$D$8 =CIQ_Export__05152017.csv!$E$8 =CIQ_Export__05152017.csv!$F$8 =CIQ_Export__05152017.csv!$D$9 =CIQ_Export__05152017.csv!$E$9 =CIQ_Export__05152017.csv!$F$9 =CIQ_Export__05152017.csv!$D$10 =CIQ_Export__05152017.csv!$E$10 =CIQ_Export__05152017.csv!$F$10 =CIQ_Export__05152017.csv!$D$11 =CIQ_Export__05152017.csv!$E$11 =CIQ_Export__05152017.csv!$F$11' 31
We then drop off the final number in each cell address:
base=. base {.~&.>>:base i:&>'$'
Check that we can reconstruct the original:
base,&.>":&.>nums +------------------------------+------------------------------+------------------------------+---------... |=CIQ_Export__05152017.csv!$A$2|=CIQ_Export__05152017.csv!$D$7|=CIQ_Export__05152017.csv!$E$7|=CIQ_Expo... +------------------------------+------------------------------+------------------------------+---------...
Since our source data is in blocks of 10 lines, we want to add multiples of 10 to our numbers:
4 5{.|:nums +/0 10 20 30 2 7 7 7 2 12 17 17 17 12 22 27 27 27 22 32 37 37 37 32 $":&.>|:nums +/0 10 20 30 4 31
Finally, we write the correct number of rows to our formulas file:
$formulas=. ;LF,~&.>}:&.>;&.>TAB,~&.>&.>(<base),&.>&.><"1 ":&.>|:nums +/10*i.134 137813 formulas fwrite 'formulas.txt' 137813
Extracting and Using Formatted Data
Here we see text that we get in a loosely formatted form. We want to extract the relevant numbers from this to calculate the total cost per share of a position bought in lots with differing prices.
egtrds=. <;._1&>TAB,&.><;._2 ] LF (] , [ #~ [ ~: [: {: ]) CR-.~0 : 0 DSM DREYFUS STRATEGIC MUNICI Get a Quote Action Quantity Price Timing Time & Date (ET) Sell 5,800 Shares Market Day Only 9:44 AM 04/11/2017 Sold 5,200 $8.4733 Settles 04/17/2017 9:44 AM 04/11/2017 Sold 100 $8.475 Settles 04/17/2017 9:44 AM 04/11/2017 Sold 300 $8.4725 Settles 04/17/2017 9:44 AM 04/11/2017 Sold 100 $8.475 Settles 04/17/2017 9:44 AM 04/11/2017 Sold 100 $8.4733 Settles 04/17/2017 9:44 AM 04/11/2017 CLOSED Filled Cost Basis Method*: View/Edit Order #: 23066735 ) $egtrds 10 5 egtrds +--------------------------------------------------------------+------------+-------+---... |DSM DREYFUS STRATEGIC MUNICI | | | ... +--------------------------------------------------------------+------------+-------+---... |Get a Quote | | | ... +--------------------------------------------------------------+------------+-------+---... |Action |Quantity |Price |Tim... +--------------------------------------------------------------+------------+-------+---... |Sell |5,800 Shares|Market |Day... +--------------------------------------------------------------+------------+-------+---... |Sold |5,200 |$8.4733|Set... +--------------------------------------------------------------+------------+-------+---... |Sold |100 |$8.475 |Set... +--------------------------------------------------------------+------------+-------+---... |Sold |300 |$8.4725|Set... +--------------------------------------------------------------+------------+-------+---... |Sold |100 |$8.475 |Set... +--------------------------------------------------------------+------------+-------+---... |Sold |100 |$8.4733|Set... +--------------------------------------------------------------+------------+-------+---... |CLOSED Filled Cost Basis Method*: View/Edit Order #: 23066735| | | ... +--------------------------------------------------------------+------------+-------+---...
We locate the lines with a “Sold” or “Bought” (for generality) information:
]whtrds=. (0{"1 egtrds) e. 'Sold';'Bought' 0 0 0 0 1 1 1 1 1 0
We extract the title line to make the following code more robust to small changes in the input:
]tit=. egtrds{~(0{"1 egtrds) i. <'Action' +------+--------+-----+------+----------------+ |Action|Quantity|Price|Timing|Time & Date (ET)| +------+--------+-----+------+----------------+ ]qtypx=. (tit i. 'Quantity';'Price'){"1 whtrds#egtrds +-----+-------+ |5,200|$8.4733| +-----+-------+ |100 |$8.475 | +-----+-------+ |300 |$8.4725| +-----+-------+ |100 |$8.475 | +-----+-------+ |100 |$8.4733| +-----+-------+
Here we have the share and dollar amounts, each with a little non-numeric bit we need to remove before turning them from text into numbers:
]qtypx=. ".&>qtypx-.&.><'$,' 5200 8.4733 100 8.475 300 8.4725 100 8.475 100 8.4733
We multiply the columns to get the total amount per lot:
*/"1 qtypx 44061.2 847.5 2541.75 847.5 847.33
Finally we divide the total number of shares by this total amount to get the price per share:
(+/0{"1 qtypx)%~+/*/"1 qtypx 8.47332 NB. Total price 8.47332*5800 49145.3
Show-and-tell
OpenWhisk Docker J image under Alpine
From: Thomas McGuire <tmcguirefl@gmail.com>
Date: Tue, Jun 20, 2017 at 11:17 PM
Subject: [Jprogramming] OpenWhisk Docker J image under Alpine.
To: Programming forum <programming@jsoftware.com>
Joe Bogner Posted a Docker image for running J on a tiny core docker image on JChat forum.
http://www.jsoftware.com/pipermail/chat/2016-November/007158.html <http://www.jsoftware.com/pipermail/chat/2016-November/007158.html>
I happened across the post doing a search on the Forums. It gave me a chance to come up to speed on Docker and ultimately I took a stab at creating an image to create a Docker container that would run J under the openwhisk/dockerskeleton distribution and have been able to set up an OpenWhisk action on my IBM Bluemix account that calls a jconsole script via the python open whisk miniderver installed in the open whisk/dockerskeleton distro.
To do this I borrowed from Joe Bogner’s Dockerfile and set up the Linux J distribution for 805. However, under Alpine this does not work because of some low level functions that are in glibc but are not in the musl c distribution that is standard with Alpine. Luckily J is not the only program that relies on these functions and by borrowing the commands to set up glibc under this docker/image I was able to create an Alpine Docker image that will run jconsole scripts using #!/home/j805/bin/jconsole
The docker images can be found at:
https://cloud.docker.com/swarm/porteverglades/repository/docker/porteverglades/alpine-j-whisk/general <https://cloud.docker.com/swarm/porteverglades/repository/docker/porteverglades/alpine-j-whisk/general>
And the source files at
https://github.com/tmcguirefl/alpine-j-whisk <https://github.com/tmcguirefl/alpine-j-whisk>
The pertinent files are action.sh:
#!/home/j805/bin/jconsole load '~addons/convert/json/json.ijs' load '~addons/convert/misc/base64.ijs' load '~temp/main.ijs' echo main ARGV exit ''And main.ijs (which is where most of the action logic is accomplished):
NB. main.ijs - J OpenWhisk script NB. expects JSON in arg2 of boxed ARGV input NB. returns JSON output main =: 3 : 0 outstr =. '{ "result" : { ' for_i. y do. if. '"' e. ;i do. outstr =. outstr, '"arg',(": i_index),'" : "',(('"';'\"') stringreplace ;i),'", ' else. outstr =. outstr, '"arg',(": i_index),'" : "',(;i),'", ' end. end. outstr, '"msg":"that''s all folks!"}}’ )TODO:
action.sh should convert arg2 (the JSON payload) into boxed format using ‘convert/JSON’
Main.ijs currently expects an ARGV style parameter and just echos it back using a string representation for JSON. But really it should expect a JSON value that has already been converted into J boxed JSON form by ‘convert/json’ and return the same.
The J addons needed must be downloaded manually to the image build directory. This should probably be changed to a ‘wget' in the Docker file so the compressed files can be downloaded directly from the JSoftware site thereby obtaining the most up to date add-on available.
Complex Residue
From: Louis de Forcrand <olius@bluewin.ch>
Date: Thu, Jun 22, 2017 at 4:53 PM
Subject: [Jprogramming] Complex residue
To: programming@jsoftware.com
Hi,
There's been recent discussion on the GNU APL forums about how to define the residue function on complex arguments. I wondered how it was specified in J, but the dictionnary page seems kind of vague.
Nuvoc says that
(x|y)=y-x*<.y%x+0=xfor all scalars x and y (including complex numbers). However, this is untrue for
'x y'=: 1j1 3j4(tested on the old J for iOS)
While it would seem like a logical extension, the dictionary only says that this is true for rational numbers.
So how is the residue of two complex numbers defined in J?
Thanks, Louis
From: Henry Rich <henryhrich@gmail.com>
Date: Thu, Jun 22, 2017 at 5:53 PM
What it actually is (when x and y are not infinite and x is not 0) is
d =. |x ab =. (+x) * y q =. <.@(0.5&+)&.+. ab%d y - x * qIf my algebra is right, this is equivalent to
(x|y)=y-x* <.@(0.5&+)&.+.y%x+0=xIn other words, the Dictionary description incorrectly says that the complex quotient will be rounded using complex floor, while in reality each component of the quotient is (tolerantly) rounded independently.
Henry Rich
From: Raul Miller <rauldmiller@gmail.com>
Date: Thu, Jun 22, 2017 at 5:58 PM
Since the dictionary defines the language, I think a better way of stating the issue is that the implementation incorrectly does something different?
Thanks, -- Raul
From: Henry Rich <henryhrich@gmail.com>
Date: Thu, Jun 22, 2017 at 6:21 PM
I don't know which one is wrong. The Dictionary has errors and omissions, and the implementation is what it is. I agree that they should be made consistent. That's a work in progress.
From: Raul Miller <rauldmiller@gmail.com>
Date: Thu, Jun 22, 2017 at 6:49 PM
Yeah... over time, I've probably argued at least three sides of this issue... -- Raul
From: Don Kelly <dhky@shaw.ca>
Date: Thu, Jun 22, 2017 at 6:54 PM
This is from NuVoc (for 806)
1. For finite x, x | y is extended to negative numbers by the definition x|y ==> y-x*<. y % x+0=x and to complex <http://code.jsoftware.com/wiki/Vocabulary/Glossary#Complex> numbers by the definition x|y ==> y-x* <.@(0.5&+)&.+. y % x+0=x .
which agrees with your algebra.
The Vocabulary uses
y-x*<. y % x+0=x extends the residue to a zero left argument, and to negative and fractional finite arguments.
but says that the dyad | extends to complex numbers
In either case the result appears to be different from the Complex Residue
In mathematics, more specifically *complex* analysis, the *residue* is a *complex number* proportional to the contour integral of a meromorphic function along a path enclosing one of its singularities. Don Kelly
Residue (complex analysis) - Wikipedia <https://www.google.ca/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=0ahUKEwjwqYKwxNLUAhUJ8WMKHVhgCQsQFggoMAE&url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FResidue_%28complex_analysis%29&usg=AFQjCNGJ2qCb-juMCMekL7Vd4znD0H9xnA>
https://en.wikipedia.org/wiki/Residue_(complex_analysis)
- SO why do we **attempt to use the "common residue" for a complex number- does it have meaning?
Don Kelly
From: Henry Rich <henryhrich@gmail.com>
Date: Thu, Jun 22, 2017 at 9:32 PM
I admit that the definition as it is implemented is less pretty than the one in Ye Dic. It would be easy to change the code to match the Dictionary definition - I just don't know if that would break existing code. Is that something we could thrash out here?
Does anyone use complex residue? Would they care if we changed the code to match the Dictionary definition?
Henry Rich
From: Henry Rich <henryhrich@gmail.com>
Date: Fri, Jun 23, 2017 at 8:25 AM
After reflection it seems clear that this is a bug in the implementation, so I have fixed it for the next release, to match the Dictionary.
Henry Rich
From: Louis de Forcrand <olius@bluewin.ch>
Date: Fri, Jun 23, 2017 at 10:06 AM
Thanks for the quick answers (and quick bug-fixing for that matter).
Louis
From: Don Kelly <dhky@shaw.ca>
Date: Fri, Jun 23, 2017 at 9:47 PM
the floor and related residue operations in the dictionary are related to the paper. The dictionary residue is as in the dictionary but the floor definition for complex numbers is apparently as in this paper. However the question as to whether floor, ceiling and residue of complex numbers are of any use-fairly esoteric and not related to the pole oriented mathematical complex integrals.
http://www.jsoftware.com/papers/eem/complexfloor.htm <cid:part1.7E9EFC8E.956DF47D@shaw.ca>
Don Kelly
Advanced topics
We look at an email thread on how to write images to file in J.
Reading and Writing Images in J
From: Devon McCormick <devonmcc@gmail.com>
Date: Sun, Mar 12, 2017 at 5:09 AM
Subject: Location of "readimg"
To: J-programming forum <programming@jsoftware.com>
I used to find code to read and write .JPGs in the jqtide namespace but this seems to have disappeared in recent versions of J - I'm on J 8.05.
Did this migrate somewhere? Is here another image reader/writer that people use? It seems I have to re-ask this question every couple of years because this keeps changing.
Regards,
Devon
From: Devon McCormick <devonmcc@gmail.com>
Date: Sun, Mar 12, 2017 at 5:37 AM
It looks like the problem is that I work under emacs using jconsole, and there's a switch using "IFQT" that avoids load qtlib for me.
From: Devon McCormick <devonmcc@gmail.com>
Date: Sun, Mar 12, 2017 at 5:44 AM
Yes - that's it. I just have to "require 'ide/qt/qtlib'" to get the fns I used to get.
Thanks.
From: bill lam <bbill.lam@gmail.com>
Date: Sun, Mar 12, 2017 at 5:49 AM
If you are not running jqt, loading all jqt definitions can cause conflicts and be harmful. If you know what you are doing, you can run load 'ide/qt/qtlib' which enable some qt facilities for non-Qt platforms.
Sorry for inconvenience, the changes should have happened in j806 beta.
From: Devon McCormick <devonmcc@gmail.com>
Date: Tue, May 9, 2017 at 4:17 PM
Now the mystery deepens: despairing of figuring out what I'd done previously to "fix" J (allow it to load the JQt image libraries even when running from jconsole), I installed J 8.04 on my new machine in preparation of diff'ing it against my customized version but, to my surprise, the image library works fine under jconsole in 8.04 without me changing anything. It still fails under J 8.05.
This was a fresh install, downloaded from Jsoftware.com, so the only customization remaining would be in my own startup scripts, the same ones that run under J 8.05.
In any case, I can continue my work under J 8.04.
On Mon, Mar 13, 2017 at 2:31 AM, Devon McCormick <devonmcc@gmail.com> wrote:
OK - I'm using Windows 7 on AMD on this new machine - it may be something to do with this configuration.
From: Ric Sherlock <tikkanz@gmail.com>
Date: Tue, May 9, 2017 at 10:33 PM
Hi Bill, I have the same versions of all packages as you on both Linux and Windows. On Linux I can successfully read and write jpg and png. On Windows I can read and write png, but not jpg.
readimg_jqtide_ 'toucan.png' NB. works fine on Windows & Linux readimg_jqtide_ 'toucan.jpg' NB. works on Linux but not Windows 'writetoucan.png' writeimg_jqtide_~ readimg_jqtide_ 'toucan.png' NB. works fine on Windows & Linux 'writetoucan.jpg' writeimg_jqtide_~ readimg_jqtide_ 'toucan.png' NB. works fine on Linux but not Windows
From: bill lam <bbill.lam@gmail.com>
Date: Thu, Jun 15, 2017 at 12:49 AM
I had tried again and might had found a solution. Apparently just loading qtlib under jconsole failed to locate the qt plugin folder. It needs to set env QT_PLUGIN_PATH to the path of J bin directory where contains the Qt dll files. This can be automated by adding a line into jconsole.cmd
@rem load J console @rem run from the J install directory @cd /d %~dp0 @set QT_PLUGIN_PATH=%~dp0bin @bin\jconsole.exethen click on jconsole.cmd to launch
2!:5'QT_PLUGIN_PATH' D:\j805\bin load'ide/qt/qtlib' $readimg_jqtide_ jpath '~temp/toucan.png' 144 200 $readimg_jqtide_ jpath '~temp/toucan.jpg' 144 200J’s Startup Sequence
We look at what J does when it starts up.
Configuration
The Edit|Configure menu allows you to change the interpreter's settings. Look through the tabs to see what is available. Note especially the Folders tab, which lets you specify the folders Project Manager and Find In Files will use to organize your work.
In addition to the configuration variables, you can have startup commands executed whenever J starts, or you can specify a script in the command line that will run after J has been initialized. The startup sequence is described in detail here. If you just want to run some startup commands, jump to the section describing the user startup file.
Startup Sequence
[This sequence is generally correct but some of the command line parameters have changed. The current startup information is here. ]
- The command line is parsed into words. The words are assigned to the variable ARGV_z_. The first word is the name of the J executable. The subsequent words, the parameters, tell J what to do. The first parameter that is not a switch is the name of the command script which is the J script you want to execute.
- If the first parameter is the -jijx switch, the normal J IDE window, where you type commands and see them executed, will not be created. You must have a fully standalone application. Except for creating the IDE window, the J startup sequence will be followed as described below, and the -jprofile switch will be honored.
- If the command line contains the -jprofile switch, you are taking full control of J's startup. Your command script will be executed instead of J's normal start sequence. Make sure you get it right! If the command script is omitted, J will skip the startup sequence entirely.
- If you don't specify the -jprofile switch, you get J's normal startup sequence which winds up by executing the command script. The normal startup sequence is contained in the script ~bin\profile.ijs, which goes through the following steps:
- The variable SystemFolders_j_ is created, containing the paths J uses to get to your home directory, the system, etc. You can look at this variable after J has started to see what folders are defined. If you want to change these directories, you do so by creating the script ~bin\profilex.ijs. Use ~bin\profilex_template.ijs as the template for creating your custom script.
- Any missing directories referred to in SystemFolders_j_ are created.
- Normal startup continues by running ~system\util\boot.ijs. This file loads the J system files stdlib.ijs, scripts.ijs, regex.ijs, task.ijs, configure.ijs, ctag.ijs, jadetag.ijs, and (if appropriate), 'qt.ijs'. Use 4!:3 to see all the scripts that are loaded at startup.
- Next, if the J executable was Jconsole, the console window is created and the console startup file ~config/startup_console.ijs is executed. User customization is not performed.
- If the J executable was not Jconsole, the user customization steps are performed:
- The J IDE is loaded and the configuration files are executed:
- the user configuration from the Edit|Configure menu
- the addons configuration file ~addons\config\config.ijs.
- After configuration, the user startup script is executed. This script is contained in the Edit|Configure|Startup Script menu. This script is where you put the definitions that you want executed every time J starts. It is executed in the base locale.
- Finally, the command script is loaded if there is one. Normally this is a file, but if the inline script indicator -js is given in place of the name of the command script, the words of ARGV_z_ following the -jsare taken to be lines of J code, and they are put into the verb ARGVVERB which is used as the command script. The command script is executed in the base locale. If the command script is omitted, nothing is run.
- When the startup sequence finishes, J may wait for user input. This input may come from a form, or, if -jijx was not specified, from the IDE window; but if neither of these sources of input exists, the interpreter will exit with no prompt. If your program expects input from another source, such as a timer or socket interrupt, you need to display a dummy form to keep J from terminating.
Public Names
The noun Public_j_ defines short names and the corresponding full form. The short names may be used in open or load verbs. Items of Public_j_ are lines of a table:
2 {. Public_j_ +--------+-----------------------------------+ |afm |~system\classes\plot\afm.ijs | +--------+-----------------------------------+ |bigfiles|~system\packages\files\bigfiles.ijs| +--------+-----------------------------------+If you want to define your own names, you may add them to Public_j_ in your startup file. The easiest way to do this is to use the buildpublic_j_ verb:
buildpublic_j_ 0 : 0 langexten C:\myfiles\langexten utils C:\myfiles\utils )After executing the lines above, I can open one of my files simply by typing
open 'langexten'Seeing What Scripts Have Run
The foreign 4!:3 tells what scripts have been loaded. You can execute this just after startup to see the sequence of startup scripts.
See Also: Configuring JQt, User Manual - Starting J - Details, User Manual - Starting J - Profile Errors, User Manual - Command Line Parameters
Learning and Teaching J
Learning J: Complex Number Problem
From: Lawrence Wickert <skippy_lou@hotmail.com>
Date: Fri, Jun 30, 2017 at 11:14 PM
Subject: [Jprogramming] Complex Number Problems
To: "programming@jsoftware.com" <programming@jsoftware.com>
Hello, I am a old EE still trying to learn. I am a real beginner having no end of problems with specifying complex numbers. I am using j64-804 on ubuntu 12.04. I am either doing something really stupid or I need to update to 806. Updating anything gives me heartburn or worse so I hope it is just my misunderstanding of basic principles. Although I have a bad habit of RTFM as a last resort I have tried the Dictionary to no avail. I appreciate any guidance.
0j(2^0.5)%2 |ill-formed number 0j((2^0.5)%2) |ill-formed number j.(2^0.5)%2 0j0.707107 NB. Eureaka, OK, I get it! NB. But wait, not so fast: 1j.(2^0.5)%2 |ill-formed number NB. No 1j(2^0.5)%2 |ill-formed number NB. Still No 1+j.(2^0.5)%2 1j0.707107 NB. This works!Let's try to do something with it:
k=:(0 1+j.(2^0.5)%2 3 4 0 5) |length error | k=:(0 1 +j.(2^0.5)%2 3 4 0 5) NB. Maybe parantheses will help: k=:(0 (1+j.(2^0.5)%2) 3 4 0 5) |syntax error | k=:( 0(1+j.(2^0.5)%2)3 4 0 5) NB. This one has to work: k=:(0 1j0.7071 3 4 0 5) k 0 1j0.7071 3 4 0 5 NB. It does but it can't be the only way to do it. NB. One last rry: g=: 1+j.(2^0.5)%2 g 1j0.707107 NB. That's nice. k=:(0 g 3 4 0 5) |syntax error | k=:( 0 g 3 4 0 5) NB. This isn't nice.Lost in the high desert of New Mexico, Larry Wickert
From: Martin Kreuzer <info@airkreuzer.com>
Date: Sat, Jul 1, 2017 at 1:46 PM
Raul -
- Many thanks for pointing out the difference between (.) the character and (.) the conjunction; has made it very clear.
- Powers of 10 -- the Dictionary says under /Constants that "The form of a numeric constant ... is elaborated by the use of further letters, as in 2r3 for two-thirds, 2p1 for two [pi], and 2e3p1 for 2000 [pi]."
Here we have the exception to the rule formulated; (e) seems -by implementation- to be the "weakest" of these elements, "dominated" by r, p (and x), as a result of accepting only integer (not real) exponents:
1e1r2 NB. 10/2, instead of sqrt(10) 5 1e1p1 NB. 10*pi, instead of 10^3.14... 31.4159 1e1x1 NB. 10*en, instead of 10^2.71... 27.1828-M
From: HenryRich <henryhrich@gmail.com>
Date: Sat, Jul 1, 2017 at 2:12 PM
To summarize:
A word is numeric if and only if it begins with 0-9 or _
Within a numeric word, zero is not required before a decimal point.
1e.4 is not allowed because the exponent must be an integer.
Henry Rich
From: Jose Mario Quintana <jose.mario.quintana@gmail.com>
Date: Sun, Jul 2, 2017 at 10:35 AM
Thinking that all these years (decades?) I could have written _.5 instead of _0.5! I was wondering if anyone had used that form before in actual code and I searched the forum posts; apparently, although there are plenty of instances of _0.5 nobody has used _.5 in actual code, at least in the forums, with one possible exception.
Learning J is akin to reading an interesting book which it seems it never ends. I learned something useful today.
From: Lawrence Wickert <skippy_lou@hotmail.com>
Date: Sat, Jul 1, 2017 at 12:10 PM
The fog is lifting. I realize that trying to learn J the way I learned Fortran, PL/I and C is not the right way to go. J is truly special. The Dissect tool is great. I also realized that paying attention to the colors of the tokens in the jqt editor eliminates many stupid errors. Many thanks for all the very informative responses.
Larry
Materials
Double brackets allow abbreviated (local) links but require a pipe to separate the associated text, like this: Building a GUI in J
- Attachment: * attachment:
- Link: [https:]
- Picture:
the monadic verb +x actually produces the complex conjugate of x.