Re: [Jprogramming] Complex puzzle WAS: Better way to locate coomplex or real numbers in an array

2014-11-30 Thread Linda Alvord
What is a ?

Linda

-Original Message-
From: programming-boun...@forums.jsoftware.com
[mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Henry Rich
Sent: Saturday, November 29, 2014 11:23 PM
To: programm...@jsoftware.com
Subject: [Jprogramming] Complex puzzle WAS: Better way to locate coomplex or
real numbers in an array

Two ways of detecting complex numbers have been suggested:

iscomplex =. 0 ~: 11&o.
isnotreal =. ~:~ +

They are not equivalent.
iscomplex a
1
isnotreal a
0

What is an example for the finite number a?

Henry Rich

On 11/29/2014 10:20 PM, Linda Alvord wrote:
> \Very nice.  Or, if it has a different conjugate it must be complex.  
> Linda
>
> -Original Message-
> From: programming-boun...@forums.jsoftware.com
> [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Lippu 
> Esa
> Sent: Saturday, November 29, 2014 4:37 PM
> To: 'programm...@jsoftware.com'
> Subject: Re: [Jprogramming] Better way to locate coomplex or real 
> numbers in an array
>
> A real number equals its conjugate, so (~:+) works too:
>
>  ]A=:(i:2)j./i:2
> _2j_2 _2j_1 _2 _2j1 _2j2
> _1j_2 _1j_1 _1 _1j1 _1j2
>0j_2  0j_1  0  0j1  0j2
>1j_2  1j_1  1  1j1  1j2
>2j_2  2j_1  2  2j1  2j2
>  (~:+) A
> 1 1 0 1 1
> 1 1 0 1 1
> 1 1 0 1 1
> 1 1 0 1 1
> 1 1 0 1 1
>
> Esa
> -Original Message-
> From: programming-boun...@forums.jsoftware.com
> [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Henry 
> Rich
> Sent: 29. marraskuuta 2014 05:34
> To: programm...@jsoftware.com
> Subject: Re: [Jprogramming] Better way to locate coomplex or real 
> numbers in an array
>
>  ]A=:(i:2)j./i:2
> _2j_2 _2j_1 _2 _2j1 _2j2
> _1j_2 _1j_1 _1 _1j1 _1j2
>0j_2  0j_1  0  0j1  0j2
>1j_2  1j_1  1  1j1  1j2
>2j_2  2j_1  2  2j1  2j2
>  (0 ~: 11&o.) A
> 1 1 0 1 1
> 1 1 0 1 1
> 1 1 0 1 1
> 1 1 0 1 1
> 1 1 0 1 1
>
> Henry Rich
>
> On 11/28/2014 10:27 PM, Linda Alvord wrote:
>> A is an array of real and complex numbers.  Is there an easier way to 
>> locate all the complex numbers.  Signum locates each numbers 
>> intersection with a line from it to the origin and the circle.
>>
>>
>>
>>  ]A=:(i:2)j./i:2
>>
>> _2j_2 _2j_1 _2 _2j1 _2j2
>>
>> _1j_2 _1j_1 _1 _1j1 _1j2
>>
>> 0j_2 0j_1 0 0j1 0j2
>>
>> 1j_2 1j_1 1 1j1 1j2
>>
>> 2j_2 2j_1 2 2j1 2j2
>>
>>
>>
>>  *A
>>
>> _0.707107j_0.707107 _0.894427j_0.447214 _1 _0.894427j0.447214
>> _0.707107j0.707107
>>
>> _0.447214j_0.894427 _0.707107j_0.707107 _1 _0.707107j0.707107
>> _0.447214j0.894427
>>
>> 0j_1 0j_1 0 0j1 0j1
>>
>> 0.447214j_0.894427 0.707107j_0.707107 1 0.707107j0.707107
>> 0.447214j0.894427
>>
>> 0.707107j_0.707107 0.894427j_0.447214 1 0.894427j0.447214
>> 0.707107j0.707107
>>
>>
>>
>>  -.(*A)e. _1 0 1
>>
>> 1 1 0 1 1
>>
>> 1 1 0 1 1
>>
>> 1 1 0 1 1
>>
>> 1 1 0 1 1
>>
>> 1 1 0 1 1
>>
>>
>>
>> I am looking for the best way to locate all the complex numbers.
>>
>>
>>
>> Linda
>>
>> -
>> - 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
>
> --
> 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


Re: [Jprogramming] Complex puzzle WAS: Better way to locate coomplex or real numbers in an array

2014-11-30 Thread Linda Alvord
Henry

 

 isnotreal =. ~:~ +

 

This is not the definition that Lippu used.  It was:

 

   (~:+) A=:(i:2)j./i:2

 

I also used  A ~:+ A

 

Can they be considered a test for whether the numbers are complex?

 

Linda

 

-Original Message-
From: programming-boun...@forums.jsoftware.com
[mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Henry Rich
Sent: Saturday, November 29, 2014 11:23 PM
To: programm...@jsoftware.com
Subject: [Jprogramming] Complex puzzle WAS: Better way to locate coomplex or
real numbers in an array

 

Two ways of detecting complex numbers have been suggested:

 

iscomplex =. 0 ~: 11&o.

isnotreal =. ~:~ +

 

They are not equivalent.

iscomplex a

1

isnotreal a

0

 

What is an example for the finite number a?

 

Henry Rich

 

On 11/29/2014 10:20 PM, Linda Alvord wrote:

> \Very nice.  Or, if it has a different conjugate it must be complex.  

> Linda

> 

> -Original Message-

> From:  
programming-boun...@forums.jsoftware.com

> [ 
mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Lippu 

> Esa

> Sent: Saturday, November 29, 2014 4:37 PM

> To: 'programm...@jsoftware.com'

> Subject: Re: [Jprogramming] Better way to locate coomplex or real 

> numbers in an array

> 

> A real number equals its conjugate, so (~:+) works too:

> 

>  ]A=:(i:2)j./i:2

> _2j_2 _2j_1 _2 _2j1 _2j2

> _1j_2 _1j_1 _1 _1j1 _1j2

>0j_2  0j_1  0  0j1  0j2

>1j_2  1j_1  1  1j1  1j2

>2j_2  2j_1  2  2j1  2j2

>  (~:+) A

> 1 1 0 1 1

> 1 1 0 1 1

> 1 1 0 1 1

> 1 1 0 1 1

> 1 1 0 1 1

> 

> Esa

> -Original Message-

> From:  
programming-boun...@forums.jsoftware.com

> [ 
mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Henry 

> Rich

> Sent: 29. marraskuuta 2014 05:34

> To:   programm...@jsoftware.com

> Subject: Re: [Jprogramming] Better way to locate coomplex or real 

> numbers in an array

> 

>  ]A=:(i:2)j./i:2

> _2j_2 _2j_1 _2 _2j1 _2j2

> _1j_2 _1j_1 _1 _1j1 _1j2

>0j_2  0j_1  0  0j1  0j2

>1j_2  1j_1  1  1j1  1j2

>2j_2  2j_1  2  2j1  2j2

>  (0 ~: 11&o.) A

> 1 1 0 1 1

> 1 1 0 1 1

> 1 1 0 1 1

> 1 1 0 1 1

> 1 1 0 1 1

> 

> Henry Rich

> 

> On 11/28/2014 10:27 PM, Linda Alvord wrote:

>> A is an array of real and complex numbers.  Is there an easier way to 

>> locate all the complex numbers.  Signum locates each numbers 

>> intersection with a line from it to the origin and the circle.

>> 

>> 

>> 

>>  ]A=:(i:2)j./i:2

>> 

>> _2j_2 _2j_1 _2 _2j1 _2j2

>> 

>> _1j_2 _1j_1 _1 _1j1 _1j2

>> 

>> 0j_2 0j_1 0 0j1 0j2

>> 

>> 1j_2 1j_1 1 1j1 1j2

>> 

>> 2j_2 2j_1 2 2j1 2j2

>> 

>> 

>> 

>>  *A

>> 

>> _0.707107j_0.707107 _0.894427j_0.447214 _1 _0.894427j0.447214

>> _0.707107j0.707107

>> 

>> _0.447214j_0.894427 _0.707107j_0.707107 _1 _0.707107j0.707107

>> _0.447214j0.894427

>> 

>> 0j_1 0j_1 0 0j1 0j1

>> 

>> 0.447214j_0.894427 0.707107j_0.707107 1 0.707107j0.707107

>> 0.447214j0.894427

>> 

>> 0.707107j_0.707107 0.894427j_0.447214 1 0.894427j0.447214

>> 0.707107j0.707107

>> 

>> 

>> 

>>  -.(*A)e. _1 0 1

>> 

>> 1 1 0 1 1

>> 

>> 1 1 0 1 1

>> 

>> 1 1 0 1 1

>> 

>> 1 1 0 1 1

>> 

>> 1 1 0 1 1

>> 

>> 

>> 

>> I am looking for the best way to locate all the complex numbers.

>> 

>> 

>> 

>> Linda

>> 

>> -

>> - 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

> 

> --

> 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


[Jprogramming] Flatten a boxed array

2014-11-30 Thread Jon Hough
What is the best way to flatten a box array of arbitrary depth?

e.g. if I have


arr =: (< 3 4) ; (3; <'HELLO'; << 'HI'); 'WORLD' NB. just random boxes


┌─┬┬─┐
│┌───┐│┌─┬┐│WORLD│
││3 4│││3│┌─┬┐││ │
│└───┘││ ││HELLO│┌──┐│││ │
│ ││ ││ ││HI │
│ ││ ││ │└──┘│││ │
│ ││ │└─┴┘││ │
│ │└─┴┘│ │
└─┴┴─┘
and I want to make


┌───┬─┬─┬──┬─┐
│3 4│3│HELLO│HI│WORLD│
└───┴─┴─┴──┴─┘
 That is, all boxed items are moved to the top.



  
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Flatten a boxed array

2014-11-30 Thread Raul Miller
   arr =: (< 3 4) ; (3; <'HELLO'; << 'HI'); 'WORLD' NB. just random boxes
   http://rosettacode.org/wiki/Flatten_a_list#J
http://rosettacode.org/wiki/Tree_traversal#J

Thanks,

-- 
Raul


On Sun, Nov 30, 2014 at 9:34 AM, Jon Hough  wrote:
> What is the best way to flatten a box array of arbitrary depth?
>
> e.g. if I have
>
>
> arr =: (< 3 4) ; (3; <'HELLO'; << 'HI'); 'WORLD' NB. just random boxes
>
>
> ┌─┬┬─┐
> │┌───┐│┌─┬┐│WORLD│
> ││3 4│││3│┌─┬┐││ │
> │└───┘││ ││HELLO│┌──┐│││ │
> │ ││ ││ ││HI │
> │ ││ ││ │└──┘│││ │
> │ ││ │└─┴┘││ │
> │ │└─┴┘│ │
> └─┴┴─┘
> and I want to make
>
>
> ┌───┬─┬─┬──┬─┐
> │3 4│3│HELLO│HI│WORLD│
> └───┴─┴─┴──┴─┘
>  That is, all boxed items are moved to the top.
>
>
>
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

[Jprogramming] current best 3d rendering mechanism(s)?

2014-11-30 Thread Raul Miller
The Catmull-Clark surface subdivision algorithm is a fun little algorithm:

http://rosettacode.org/wiki/Catmull%E2%80%93Clark_subdivision_surface
http://rosettacode.org/wiki/Catmull%E2%80%93Clark_subdivision_surface#J

But there are other approaches to this task, and some of them require
very different sorts of abstractions.

But testing the result - especially when the result is not exactly
equivalent but only visually similar - requires a way of visualizing
the results. Basically, you need a decent rendering system (one that
gives lighting effects to represent the orientation of surfaces).

Meanwhile, I've not been spending much time with all of the
possibilities we have here.

What are some of the current best 3d rendering systems we have in J?
(Bonus question: what does the data structure for a medium-grey or
green cube look like, for each such system?)

Thanks,

-- 
Raul
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Complex puzzle WAS: Better way to locate coomplex or real numbers in an array

2014-11-30 Thread Henry Rich

Bob: there is a primitive for tolerant comparison against 0:

   * 1e_45
0


Linda: the ~ was superfluous but immaterial.  As for how to test for 
complex numbers, that is for the user to decide: do you want a number 
whose complex angle is close to 0/pi, or do you want to insist on 
exactly 0/pi?


Henry Rich

On 11/30/2014 5:08 AM, Linda Alvord wrote:

Henry



  isnotreal =. ~:~ +



This is not the definition that Lippu used.  It was:



(~:+) A=:(i:2)j./i:2



I also used  A ~:+ A



Can they be considered a test for whether the numbers are complex?



Linda



-Original Message-
From: programming-boun...@forums.jsoftware.com
[mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Henry Rich
Sent: Saturday, November 29, 2014 11:23 PM
To: programm...@jsoftware.com
Subject: [Jprogramming] Complex puzzle WAS: Better way to locate coomplex or
real numbers in an array



Two ways of detecting complex numbers have been suggested:



 iscomplex =. 0 ~: 11&o.

 isnotreal =. ~:~ +



They are not equivalent.

 iscomplex a

1

 isnotreal a

0



What is an example for the finite number a?



Henry Rich



On 11/29/2014 10:20 PM, Linda Alvord wrote:


\Very nice.  Or, if it has a different conjugate it must be complex.



Linda







-Original Message-



From:  

programming-boun...@forums.jsoftware.com


[ 

mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Lippu


Esa



Sent: Saturday, November 29, 2014 4:37 PM



To: 'programm...@jsoftware.com'



Subject: Re: [Jprogramming] Better way to locate coomplex or real



numbers in an array







A real number equals its conjugate, so (~:+) works too:







  ]A=:(i:2)j./i:2



_2j_2 _2j_1 _2 _2j1 _2j2



_1j_2 _1j_1 _1 _1j1 _1j2



0j_2  0j_1  0  0j1  0j2



1j_2  1j_1  1  1j1  1j2



2j_2  2j_1  2  2j1  2j2



  (~:+) A



1 1 0 1 1



1 1 0 1 1



1 1 0 1 1



1 1 0 1 1



1 1 0 1 1







Esa



-Original Message-



From:  

programming-boun...@forums.jsoftware.com


[ 

mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Henry


Rich



Sent: 29. marraskuuta 2014 05:34



To:   programm...@jsoftware.com



Subject: Re: [Jprogramming] Better way to locate coomplex or real



numbers in an array







  ]A=:(i:2)j./i:2



_2j_2 _2j_1 _2 _2j1 _2j2



_1j_2 _1j_1 _1 _1j1 _1j2



0j_2  0j_1  0  0j1  0j2



1j_2  1j_1  1  1j1  1j2



2j_2  2j_1  2  2j1  2j2



  (0 ~: 11&o.) A



1 1 0 1 1



1 1 0 1 1



1 1 0 1 1



1 1 0 1 1



1 1 0 1 1







Henry Rich







On 11/28/2014 10:27 PM, Linda Alvord wrote:



A is an array of real and complex numbers.  Is there an easier way to



locate all the complex numbers.  Signum locates each numbers



intersection with a line from it to the origin and the circle.















  ]A=:(i:2)j./i:2







_2j_2 _2j_1 _2 _2j1 _2j2







_1j_2 _1j_1 _1 _1j1 _1j2







0j_2 0j_1 0 0j1 0j2







1j_2 1j_1 1 1j1 1j2







2j_2 2j_1 2 2j1 2j2















  *A







_0.707107j_0.707107 _0.894427j_0.447214 _1 _0.894427j0.447214



_0.707107j0.707107







_0.447214j_0.894427 _0.707107j_0.707107 _1 _0.707107j0.707107



_0.447214j0.894427







0j_1 0j_1 0 0j1 0j1







0.447214j_0.894427 0.707107j_0.707107 1 0.707107j0.707107



0.447214j0.894427







0.707107j_0.707107 0.894427j_0.447214 1 0.894427j0.447214



0.707107j0.707107















  -.(*A)e. _1 0 1







1 1 0 1 1







1 1 0 1 1







1 1 0 1 1







1 1 0 1 1







1 1 0 1 1















I am looking for the best way to locate all the complex numbers.















Linda







-



- 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






--



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



[Jprogramming] Dumb ffi question

2014-11-30 Thread Scott Locklin
So, I have this pile of C code that uses rank-2 arrays as double**, then 
subsets them with loops like "array[i][j]." I'm so used to the J FFI 
working flawlessly on C code (most of which sensibly uses double*), I 
forgot that a J-array doesn't work like that, and was kind of shocked 
when the code dumped core on me.


Is there any magic J incantation I can do to my arrays so that C can 
more easily digest them, or should I just write a C macro to dereference 
the double pointer?


This is for hierarchical clustering, if anyone is interested in that 
sort of thing (a most un-J like algorithm, sadly). Maybe 2-d wavelets as 
well.


-SL
--
For information about J forums see http://www.jsoftware.com/forums.htm