Author Topic: Boolean memory  (Read 9520 times)

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Re: Boolean memory
« Reply #15 on: January 21, 2012, 09:09:30 PM »
I'm not necessarily against it, but when would that be useful?  I can't think of any use cases where you'd need to do that except for storing true/false flags to memory, and then you could do something like:

1 custommemoryloc store not 0 custommemoryloc store

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
Re: Boolean memory
« Reply #16 on: January 23, 2012, 05:12:38 PM »
I was hoping you'll ask:

I recently did an AI project for school myself. It has no real Boolean logic, example:
Code: [Select]
IF True THEN Sin 29 * CALC Memory(121) OUT Do_Nothing TYPE action DIRECTION clone_up
IF True THEN 250 7 216 * CALC Memory(170) OUT Do_Nothing TYPE action DIRECTION clone_down
IF True THEN Sin 29 * CALC Memory(121) OUT Do_Nothing TYPE action DIRECTION clone_up
IF True THEN Sin 29 * CALC Memory(121) OUT Do_Nothing TYPE action DIRECTION clone_up
IF Memory(167) < Memory(36) THEN 142 0 CALC Memory(99) OUT Do_Nothing TYPE data DIRECTION clone_up
IF True THEN 29 * CALC Memory(197) OUT Do_Nothing TYPE action DIRECTION clone_up
IF Memory(234) = Memory(211) THEN 206 * CALC Memory(178) OUT Do_Nothing TYPE action DIRECTION clone_up
IF True THEN 351.508334281997 1 Cos 39.1118722540835 Cos CALC Memory(76) OUT Do_Nothing TYPE data DIRECTION clone_up
IF False THEN 202 * 217 * CALC Memory(7) OUT Gear2_Reverse TYPE data DIRECTION clone_up
IF True THEN Distance 161 0 * * Sin * 241 * CALC Memory(174) OUT Do_Nothing TYPE data DIRECTION clone_up
IF False THEN 34.3416983468838 202 * 217 * CALC Memory(7) OUT Gear2_Reverse TYPE data DIRECTION clone_up
IF Memory(133) != Memory(213) THEN * 61 * CALC Memory(110) OUT Do_Nothing TYPE data DIRECTION clone_up

After CALC is the destination of the data (math)  result

One of the operators I have is called "Angle_Compare" (btw: I am considering this for DB as well) It compares two angles using this algorithm:

Code: [Select]
                                        hold1 = popstack(a) '100
                                        hold2 = popstack(a) '99
                                        calc = IIf(angle_compare(hold1, hold2), 2, -2)
                                        If MD_state = 5 And a = cntrl_math Then debug_print.Text = debug_print.Text & vbNewLine & hold1 'debug
                                        If MD_state = 5 And a = cntrl_math Then debug_print.Text = debug_print.Text & vbNewLine & hold2 'debug
                                        If MD_state = 5 And a = cntrl_math Then debug_print.Text = debug_print.Text & vbNewLine & "DIR:" & calc 'debug
                                        pushstack(a, calc)

    Private Function angle_compare(ByVal ang1 As Single, ByVal ang2 As Single) As Boolean
        Dim data2 As Integer = ang2
        Dim data1 As Integer = ang1
        Dim out As Boolean
        Dim sp As Boolean = False
        If data1 > 180 Then
            sp = True
            data2 = 360 - data2
            data1 = 360 - data1
        End If
        If (data2 > data1) And (data2 < (data1 + 180)) Then out = True Else out = False
        If sp Then angle_compare = IIf(out, True, False) Else angle_compare = IIf(out, False, True)
    End Function

As you can see since there is no real Boolean stack; The functions result is always stored as Integer (2 , -2) and then can be stored into a memory location. Then the system can always compare the result > v. zero. This kind of model worked pretty good for me.

The button line is it will add flexibility of using a Boolean operator as a data operator and vise-versa.
Think about "angle_compare": In DB it will take two Integers and return an Integer (2  or -2) , but it will be cool to turn it into a Boolean right away.



You may catch me here on the fact that I am making an imaginary concept (intotobool) on concept that's imaginary as well (angle_compare) but I hope it'll be alright.
« Last Edit: January 23, 2012, 05:35:18 PM by Botsareus »

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
Re: Boolean memory
« Reply #17 on: January 27, 2012, 03:26:06 PM »
lol, Numsgil did that post actually made sense since you are slow to reply?  :D

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Re: Boolean memory
« Reply #18 on: January 27, 2012, 07:58:51 PM »
Sorry, I got distracted trying to figure out what your angle_compare was trying to do.

I think it's probably something you can do using a dot product or 2D cross product.  Usually when you have to break something out in terms of angles it's a sign you're doing it wrong (at least in terms of programming).

That is:

A dot B = |A| * |B| * cos(angle between them)

So:

(A dot B ) / (|A| * |B|) = cos(angle between them)

And for the 2D cross product:

(A cross B ) \ (|A| * |B|) = sin(angle between them)

Using those two identities you can often get rid of all the trig, which is better computationally and more elegant from a computation standpoint.
« Last Edit: January 28, 2012, 05:53:12 PM by Numsgil »

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
Re: Boolean memory
« Reply #19 on: January 28, 2012, 10:32:41 AM »
Ouch, that math looks heavy...

I am guessing (angle between them) is: ang1 - ang2
Right?
I also have to assume that A and B are vectors relative to zero
Right?

What values does that formula return?
« Last Edit: January 28, 2012, 12:40:11 PM by Botsareus »

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Re: Boolean memory
« Reply #20 on: January 28, 2012, 05:55:39 PM »
Yeah, angle between them is the difference in their relative angles.

And yes, it only really makes sense if A and B are directional vectors and not points.

The dot product is just:

A.x * B.x + A.y * B.y

Cross product is:

+/- (A.x * B.y - A.y * B.x)

(+/- depending on what "handedness" you're using).

Offline ikke

  • Bot Destroyer
  • ***
  • Posts: 300
    • View Profile
Re: Boolean memory
« Reply #21 on: January 29, 2012, 04:26:38 AM »
I remember learning this at Delft university. This has confronted me with the knowledge that I can no longer reproduce this on my own. Knowledge has a half life...

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
Re: Boolean memory
« Reply #22 on: January 31, 2012, 05:19:55 PM »
Wow, this formula is awesome. Thx for teaching me that Numsgil. , I did some basic tests on it, I will do rigorous testing on it when I get a chance.
« Last Edit: January 31, 2012, 06:13:19 PM by Botsareus »

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
Re: Boolean memory
« Reply #23 on: February 01, 2012, 04:32:17 PM »
I just realized I don't need to divide by (|A| * |B|) because all it does is rescale the triangle.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Re: Boolean memory
« Reply #24 on: February 01, 2012, 04:37:42 PM »
if A and B are unit length, you don't need to.  Or if they cancel out in some way later in the problem, you don't need to.