4

I fully expect downvotes, but this got me really curious, and I hope at least someone can answer. Our discrete mathematics professor really likes old languages for the plethora of bitwise operators they provide. Now, he gave us a homework which was to determine the output of the following BASIC statement:

PRINT (NOT (15 OR 51) EQV 85) IMP (15 AND 51)

I've solved it and I'm pretty much sure it's supposed to output -105, but I wanted to compile it just to make sure. Then I figured out I was facing a problem. I have no idea what kind of BASIC is this! A compiler for the original BASIC language failed to compile it. A QBasic compiler failed to compile it. a VB.NET compiler failed to compile it, even after I modified it to what I think should be VB.NET's syntax like this:

Console.WriteLine((NOT (15 OR 51) EQV 85) IMP (15 AND 51))

The question is: is there even a sort or dialect of BASIC in which a program with this statement can compile? And if yes, which?

eoredson
  • 1,167
  • 2
  • 14
  • 29
  • As far as I can tell EQV() is equal to NOT(XOR()) and IMP(X,Y) is equal to 0 if X is true and Y is false. – eoredson Jul 08 '18 at 04:26

6 Answers6

3

This works in the "original" Microsoft Visual Basic. The VB.NET version isn't exactly fully compatible.

The easiest way you can try this is by using Visual Basic for Applications, which you can find in Microsoft Office. Indeed, the expression evaluates to -105. I've used Excel with this code:

Cells(1, 1).Value = (Not (15 Or 51) Eqv 85) Imp (15 And 51)

There's also probably other Basic dialects that wil work fine - PowerBASIC might be one of them, but I can't really check :)

Identifying the exact dialect is tricky without knowing your teacher's background - there's a lot of those, and many are very similar.

Luaan
  • 62,244
  • 7
  • 97
  • 116
1

It seems to be a VBA syntax for me.

May be you can try it out in MS-Excel Macros.

Sub VBA_Function()
    Dim x
    x = (Not (15 Or 51) Eqv 85) Imp (15 And 51)
    Range("A1").Value = x
End Sub
1

Perhaps your professor provided the question specifically in this form as a challenge to solve it analytically and not by entering the code into a compiler. It's not a complicated expression.

Neither EQV nor IMP are supported BASIC functions anymore (so much for MS being always backwardly compatible!).

To validate your answer, you should be using the function definitions and solving it manually.

Failing that, it is, interestingly, still supported in VBA. You can find VBA buried within most of the MS Office suite apps.

Community
  • 1
  • 1
Ian W
  • 4,559
  • 2
  • 18
  • 37
0

Examples of BASIC boolean truth tables:

X EQV Y  Computes not xor
X IMP Y  Computes not(x and not y)

  Boolean truth tables:

      X | Not               X |  Y  |  Or         X |  Y  |  And
  -----------           -----------------     ------------------
      1 |  0                1 |  1  |  1          1 |  1  |   1
      0 |  1                1 |  0  |  1          1 |  0  |   0
                            0 |  1  |  1          0 |  1  |   0
                            0 |  0  |  0          0 |  0  |   0

      X |  Y  |  Xor        X |  Y  |  Imp        X |  Y  |  Eqv
  ------------------    ------------------    ------------------
      1 |  1  |   0         1 |  1  |   1         1 |  1  |   1
      1 |  0  |   1         1 |  0  |   0         1 |  0  |   0
      0 |  1  |   1         0 |  1  |   1         0 |  1  |   0
      0 |  0  |   0         0 |  0  |   1         0 |  0  |   1
eoredson
  • 1,167
  • 2
  • 14
  • 29
0

Additional boolean truth tables:

Where NOR is NOT OR, NON is NOT IMP, XAN is NOT AND

      X |  Y  |  Nor        X |  Y  |  Non        X |  Y  |  Xan
  ------------------    ------------------    ------------------
     -1 | -1  |   0        -1 | -1  |   0        -1 | -1  |   0
     -1 |  0  |   0        -1 |  0  |  -1        -1 |  0  |  -1
      0 | -1  |   0         0 | -1  |   0         0 | -1  |  -1
      0 |  0  |  -1         0 |  0  |   0         0 |  0  |  -1
eoredson
  • 1,167
  • 2
  • 14
  • 29
0

So, removing EQV and IMP from your equation, and building it back to:

REM modify boolean values:

PRINT (NOT (15 OR 51) EQV 85) IMP (15 AND 51)

REM removing EQV and IMP:

PRINT NOT (NOT (NOT (15 OR 51) XOR 85) AND NOT (15 AND 51))

solves your question.

eoredson
  • 1,167
  • 2
  • 14
  • 29