1
$\begingroup$

I know it's a silly scenario but I wolud like to know if it's relevant and maybe there are some sort of theory/studies on it or it's merely a non-sense situation.

Immagine a language much close to a Turing machine that is compiled in an higher language (let's say C). This language can accept an integer as input, but using his syntax i don't have any access to his internal rappresentation of this integer, that is the integer wolud be located in one single cell and the only operation I can do on a cell are:

 +1, -1, copy/paste from a register, set to 0, chek if it's non-zero.

Now if I want to output the sign of the integer I would create a copy of it so that in one cell the value gets incremented and in the other gets decremented. Until I reach 0 and then I would stop and correctly tell the sign.

The interesting part is that under the hood, this program would surely use the information of the sign of the integer to execute +1 and -1 correctlty...

So I'm using operations that would use information x to obtain information x... Normally I would have access to the rappresentation of the integers and to check the sign consists in looking at one particular bit. But in this case some information is hidden from me.

It reminds me of solving the limit sin(x)/x as x goes to 0 by de l'Hopital rule... It's a logical fallacy because that limit is required in order to differentiate sin(x)

Could there be situations when this is not generated explicitly by us and it's inevitable? Has it more profound consequences?

$\endgroup$

1 Answer 1

2
$\begingroup$

There's plenty of precedent for this in real programming languages. One obvious example is pointers/references, which are internally just an address (probably). The language/runtime must know this, but in managed languages you don't have access to that.

One of my favourite examples of "useful information that must be there but is hidden" is in C++. You can allocate an array of objects using the new[] operator and deallocate them with delete[]:

Object* objs = new Object[25];
// do stuff to objs
delete[] objs;

C++ does not provide a way to obtain the number of elements in array. However, the delete[] operator must have access to this information, because it needs to execute the destructors of those elements.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.