Data representation

General APL language issues

Data representation

Postby giangiquario on Thu Jan 06, 2011 11:50 am

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
User avatar
giangiquario
 
Posts: 46
Joined: Thu Nov 26, 2009 8:55 am
Location: Milano, Italia

Re: Data representation

Postby PhilGray on Thu Jan 06, 2011 1:40 pm

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
PhilGray
 
Posts: 50
Joined: Sat Mar 13, 2010 7:55 pm

Re: Data representation

Postby alexbalako on Thu Jan 06, 2011 4:53 pm

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
alexbalako
 
Posts: 16
Joined: Mon Nov 30, 2009 8:58 pm

Re: Data representation

Postby giangiquario on Fri Jan 07, 2011 8:58 am

My version is:
Classic Version: 12.1.1.5252
Created: May 5 2010 at 21:26:48
Build ID: ffa69d95
User avatar
giangiquario
 
Posts: 46
Joined: Thu Nov 26, 2009 8:55 am
Location: Milano, Italia

Re: Data representation

Postby JohnS|Dyalog on Fri Jan 07, 2011 9:13 am

⎕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
JohnS|Dyalog
 

Re: Data representation

Postby Richard|Dyalog on Tue Jan 11, 2011 10:54 am

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.
User avatar
Richard|Dyalog
 
Posts: 44
Joined: Thu Oct 02, 2008 11:11 am


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest