Page 1 of 1

Data representation

Posted: Thu Jan 06, 2011 11:50 am
by giangiquario
I'd appreciate to understand the following different results (version 12.1):

Code: Select all

      ⎕dr 1
83
      ⎕dr 1⍴1
83
      ⎕dr 2⍴1
11

and

Code: Select all

      ⎕dr 1↑1 1
11
      ⎕dr 1↑2⍴1
83
      ⎕dr 1↑2⍴1 1
11

Re: Data representation

Posted: Thu Jan 06, 2011 1:40 pm
by PhilGray
Strange , in your second example, I get this :

Code: Select all

  ⎕dr 1↑2⍴1
11


.. as opposed to the '83' result that your example shows .


Classic Version: 12.1.1.6592
Created: Sep 28 2010 at 21:12:05
Build ID: 8c8ab56b

Re: Data representation

Posted: Thu Jan 06, 2011 4:53 pm
by alexbalako
In 12.1.0

Code: Select all

      ⎕dr 1
83
      ⎕dr 1⍴1
11
      ⎕dr 2⍴1
11
      ⎕dr 1↑1 1
11
      ⎕dr 1↑2⍴1
11
      ⎕dr 1↑2⍴1 1
11

Re: Data representation

Posted: Fri Jan 07, 2011 8:58 am
by giangiquario
My version is:
Classic Version: 12.1.1.5252
Created: May 5 2010 at 21:26:48
Build ID: ffa69d95

Re: Data representation

Posted: Fri Jan 07, 2011 9:13 am
by JohnS|Dyalog
⎕DR was introduced to Dyalog after many years. By this time, we had established the principle of representing numbers internally in the "most efficient" (in terms of space and time) form. In the classic APL language, a number is a number is a number ...

We found by experiment that maintaining the scalar literal values 0 and 1 as bytes, rather than as bits, made applications run slightly faster. These values occur very frequently and not having to mask out bits each time they were accessed gave us a small but measurable performance improvement.

This is what I expect to see:

Code: Select all

Dyalog APL/W Version 12.1.1
Serial No : 000000
Unicode Edition
DEBUG Build
Fri Jan 07 09:06:34 2011
clear ws
      ⎕dr 1
83
      ⎕dr 1⍴1
11
      ⎕dr 2⍴1
11
      ⎕dr 1↑1 1
11
      ⎕dr 1↑2⍴1
11
      ⎕dr 1↑2⍴1 1
11

Re: Data representation

Posted: Tue Jan 11, 2011 10:54 am
by Richard|Dyalog
I have looked more at why:

Code: Select all

      ⎕dr 1⍴1
      ⎕dr 1↑2⍴1

generally give 11 (1-bit boolean) but sometimes 83 (8-bit integer). That it is not 11 might suggest that the array doesn't contain just the values 0 and 1; that it can give two different values might also suggest a problem. Be assured that neither is the case; in both cases the array being examined is a length 1 vector containing the numeric value 1. The internal representation may indeed vary but that is only visible to you when you call ⎕dr; it is different because the best optimisation technique is sometimes a close call and subtle differences in the environment etc affect the choices the interpreter makes.

In a clear workspace you will see the following:

Code: Select all

      ⎕dr 1⍴1                                                                   
11                                                                             
      ⎕dr 1⍴2-1                                                                 
83

The first example can also give 83 depending on what else is in the workspace, which is what has happened in the reported case.