j

How to call J (ijconsole) with a script automatically

邮差的信 提交于 2021-01-27 13:40:12
问题 I'm using the J programming language in Ubuntu, and I'd like to call a script automatically from the command line. I think this should be possible using the ijconsole command, but I don't know how to pass it a set of functions. For instance, in perl, one would type: perl -e 'print "Hello";' Is there an equivalent method for J, using the ijconsole program? For instance: ijconsole -e 'load "script.ijs"' Thank you! 回答1: Assuming ijconsole is in your path, you can run a script from the terminal

How to plot with no default x-axes in J?

。_饼干妹妹 提交于 2021-01-27 11:58:20
问题 I want to plot in J with 2 list of data: data1 and data2 as y-axes and x_axes. I want to know how to define the x-axes but not use the default i.($y). 回答1: You can create a scatter plot giving both the x-axis and y-axis coordinates as follows: load 'plot' ]data1=: 20 ?@$ 500 282 212 154 130 84 355 35 307 108 123 266 460 299 462 93 91 435 341 27 437 ]data2=: 20 ?@$ 100 73 3 7 10 93 32 25 48 45 11 21 95 84 63 33 6 84 9 93 65 plot data1;data2 However the default plot is a line so this may not

J: Tacit adverb of Newton's method

感情迁移 提交于 2020-01-03 09:10:10
问题 I've found in 'addons/math/misc/brent.ijs' implementation of Brent's method as an adverb. I would like to build a Newton's method as an adverb too but it's much harder than building tacit verbs. Here is a explicit version of Newton's iteration: newton_i =: 1 : '] - u % u d.1' With such usage: 2&o. newton_i^:_ (1) NB. (-: 1p1) must be found 1.5708 2 o. 1.5708 NB. after substitution we get almost 0 _3.67321e_6 And of course, for convenience: newton =: 1 : 'u newton_i^:_' What's a tacit

How to list the code of a verb in J

ぃ、小莉子 提交于 2019-12-30 06:55:09
问题 In the console, typing a single verb without parameters will print its content: tolower 3 : 0 x=. I. 26 > n=. ((65+i.26){a.) i. t=. ,y ($y) $ ((x{n) { (97+i.26){a.) x}t ) That's nice for development, but unexploitable during execution. Is there a way to do that dynamically? Is there a verb that can return the contents of another verb? For example: showverb 'tolower' or showverb tolower 回答1: You can use its representation. For example the boxed representation ( 5!:2 ) of tolower is: (5!:2) <

How to list the code of a verb in J

南楼画角 提交于 2019-12-30 06:54:25
问题 In the console, typing a single verb without parameters will print its content: tolower 3 : 0 x=. I. 26 > n=. ((65+i.26){a.) i. t=. ,y ($y) $ ((x{n) { (97+i.26){a.) x}t ) That's nice for development, but unexploitable during execution. Is there a way to do that dynamically? Is there a verb that can return the contents of another verb? For example: showverb 'tolower' or showverb tolower 回答1: You can use its representation. For example the boxed representation ( 5!:2 ) of tolower is: (5!:2) <

How to refactor this in J?

不想你离开。 提交于 2019-12-24 20:32:47
问题 Here is a different approach for the Project Euler #1 solution: +/~.(3*i.>.1000%3),5*i.>.1000%5 How to refactor it? 回答1: [:+/@~.@,3 5([*i.@>.@%~)] usage example: f =: [:+/@~.@,3 5([*i.@>.@%~)] f 1000 or +/~.,3 5([*i.@>.@%~)1000 %~ = 4 : 'y % x' i.@>.@%~ = 4 : 'i. >. y % x' [*i.@>.@%~ = 4 : 'x * i. >. y % x' 3 5([*i.@>.@%~)] = 3 : '3 5 * i. >. y % 3 5' [:+/@~.@,3 5([*i.@>.@%~)] = 3 : '+/ ~. , 3 5 * i. >. y % 3 5' 回答2: +/(#~ ( (0= 3| ]) +. (0 = 5 |]) )) 1+i.999 0 = ( 3 | ]) uses (twice) the

Installing JQt IDE for the J language, getting error

≡放荡痞女 提交于 2019-12-24 05:08:09
问题 I've been following the instructions here: http://code.jsoftware.com/wiki/System/Installation/Linux to install J on an Ubuntu, new computer with everything updated. I have managed to follow all of the instructions up to the point where I install a JQt IDE http://code.jsoftware.com/wiki/Guides/Qt_IDE/Install When I search the various file paths listed at the first like, like /usr/bin , I don't see any jqt.sh nor do I know which one is "the J install directory" since I only downloaded the .deb

List a number's digits in J

断了今生、忘了曾经 提交于 2019-12-24 00:52:32
问题 I use the programming language: J. I want to put all of the digit of a number in a list. From: 12345 to: 1 2 3 4 5 What can I do? 回答1: Another approach: intToList =: 3 : '((>. 10 ^. y)#10) #: y' This doesn't convert to string and back, which can be potentially costly, but counts the digits with a base-10 log, then uses anti-base ( #: ) to get each digit. EDIT: Better, safer version based on Dan Bron's comment: intToList =: 3 : '10 #.^:_1 y' 回答2: The way I'd write this is 10&#.^:_1 which we

Arbitrary precision number is clipped

痴心易碎 提交于 2019-12-23 21:26:19
问题 J clips the big integer number in the terminal (note the ellipsis in the output). How can this be prevented? Code !333x Output 1033446543458805915609396553829751655062226004168206282343290246978318859791427656855270019484987792989437595025257047708041835273259765874566592560470466922713372647724385431783663513069412389371163853300198049622987566547659856882180617030376554048981440... 回答1: You can use the Files foreign to output to stdout like so: (":!333x) (1!:2) 4 Or you can use the Output

Square of the sum minus sum of the squares in J (or how to take the train?)

半城伤御伤魂 提交于 2019-12-23 01:16:04
问题 Still in the learning process of J... The problem to solve is now to express the square of the sum minus the sum of the squares of natural integers. The naive solution is (*:+/>:i.100) - (+/*:>:i.100) Now, I want to use a fork to be able to write the list >:i.100 only one time. My fork should like to: h / \ f g | | x x where f is the square of the sum, g is the sum of the squares, and h is minus. So, naively, I wrote: ((*:+/) - (+/*:)) >:i.100 but it gives me a domain error. Why? I also tried