Any clue as to the input to summary, or what you're summarising?
Sorry if it's obvious!
Note these (display ?) errors:
pol =. _1 [space] x: ...
hp =. x [space] :: ] ...
Cheers,
Mike
On 21/08/2020 15:41, 'Bo Jacoby' via Programming wrote:
tomb=.(^/i.@>:)~ NB. tombola lottery powers
hist=.({."1~>:)~(*[:^/~i.@#@,)NB. histogram powers
s=.(*#)@ (}.%{.) @ (+/) NB. summation
f1=.$~2# # NB. n*n matrix
f2=.>:@i.@#, }: NB. insert S0, remove Sn
f3=.*_1^i.@# NB. change sign
f4=.|:|.!.0"01~-@i.@# NB. shift zeroes in
m=.|:@f4@(f3"1@f2@|:@f1) NB. matrix
e=.1,(%.m) NB. solve linear equations
pol=._1x: -@|.@>@{:@p.@|. NB.solve alg.eqn.
hp=.x::: ] NB. high precision
summary=.pol@e@s@hp f. NB. complete program
sorry for the still missing carriage returns.
Den fredag den 21. august 2020 16.37.19 CEST skrev Bo Jacoby
<[email protected]>:
tomb=.(^/i.@>:)~ NB. tombola lottery powershist=.({."1~>:)~(*[:^/~i.@#@,)NB. histogram powerss=.(*#)@ (}.%{.) @ (+/) NB. summationf1=.$~2# # NB. n*n matrixf2=.>:@i.@#, }: NB. insert S0, remove Snf3=.*_1^i.@# NB. change signf4=.|:|.!.0"01~-@i.@# NB. shift zeroes inm=.|:@f4@(f3"1@f2@|:@f1) NB. matrixe=.1,(%.m) NB. solve linear equationspol=._1x: -@|.@>@{:@p.@|. NB.solve alg.eqn.hp=.x::: ] NB. high precisionsummary=.pol@e@s@hp f. NB. complete program
This should be better. Sorry.
Bo. Den fredag den 21. august 2020 16.29.35 CEST skrev 'Bo Jacoby' via Programming
<[email protected]>:
Thank you!
I was trying to accomplish this
tomb=.(^/i.@>:)~ NB. tombola lottery powershist=.({."1~>:)~(*[:^/~i.@#@,)NB. histogram
powerss=.(*#)@ (}.%{.) @ (+/) NB. summationf1=.$~2# # NB. n*n matrixf2=.>:@i.@#, }: NB. indsæt S0,
fjern Snf3=.*_1^i.@# NB. change signf4=.|:|.!.0"01~-@i.@# NB. shift zeroes
inm=.|:@f4@(f3"1@f2@|:@f1) NB. matrixe=.1,(%.m) NB. solve linear equationspol=._1x:
-@|.@>@{:@p.@|. NB.solve alg.eqn.hp=.x::: ] NB. high precisionsummary=.pol@e@s@hpf. NB. complete program
1&(summary@tomb) computes the mean value of a dataset.
1 summary@tomb i.11
5
The mean value of 99 zeroes and 1 one is
1 summary@hist 99 1
0.01
The mean value plus/minus the standard deviation is computed like this
2 summary@tomb i.11
1.83772 8.16228
2 summary@hist 99 1
_0.0894987 0.109499
Of course these two numbers have the correct mean value
1 summary@tomb 2 summary@tomb i.11
5
1 summary@tomb 2 summary@hist 99 1
0.01
The computation is generalized to 3 numbers
3 summary@tomb i.11
1.12702 5 8.87298
3 summary@hist 99 1
_0.108204j0.16452 _0.108204j_0.16452 0.246409
having the correct mean values and standarddeviations.
2 summary@tomb 3 summary@tomb i.11
1.83772 8.16228
2 summary@tomb 3 summary@hist 99 1
_0.0894987 0.109499
Thus complicated probability distributions functions are summarized by a few
numbers. That is what I accomplished!
Thanks!
Bo.
Den fredag den 21. august 2020 15.33.50 CEST skrev ethiejiesa via Programming
<[email protected]>:
Bo Jacoby <[email protected]> wrote:
How to de-smell this:
3([* i.@#@,@[ ^/ i.@>:@])~ 0 0 1 1 1
3 (]* ((^/&i. >:)~ #)) 0 0 1 1 1
Maybe? That comes from just a little mechanical algebra:
3([* i.@#@,@[ ^/ i.@>:@])~ 0 0 1 1 1
First notice the repeated (i.) on either argument of (^/). There is a general
pattern, (f@u v f@w <--> u v&f w), which in this case specializes to
3([* #@,@[ ^/&i. >:@])~ 0 0 1 1 1
Then, at least in this example the (@,) is superfluous, so we elide it:
3([* #@[ ^/&i. >:@])~ 0 0 1 1 1
Finally, here is an idiom: ( (u@[ v w@]) <--> ((v w)~ u)~ ), and since
(x v~~ y <--> x v y), we have
3 (]* ((^/&i. >:)~ #)) 0 0 1 1 1
The last idiom is really a matter of preference. I like the bare verbs, but
code golf-wise it doesn't win.
More importantly, however, I really have no idea what you are trying to
accomplish. The above just performs some J syntax manipulations; however, this
doesn't at all demonstrate the main point of avoiding code smell as I see it,
which is more about finding places to improve the *algorithm* rather than only
cleaning up the syntax.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm