Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Reversing a logical ( OR )

Reversing a logical ( OR )

Scheduled Pinned Locked Moved The Weird and The Wonderful
11 Posts 11 Posters 66 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    albert_redditt
    wrote on last edited by
    #1

    I was told that there's no way to undo an OR as it loses value in the output.. I fumbled upon a formula , to undo an OR v1 or or_val = ( v1 xor or_val ) + ( v1 and or_val ) 100 or 5 = ( (100 or 5) xor 5 ) + ( 100 and 5 ) 100 or 10 = ( (100 or 10) xor 10 ) + ( 100 and 10 ) 255 or 12 = ( (255 or 12) xor 12 ) + ( 255 and 12 )

    P J R J J 8 Replies Last reply
    0
    • A albert_redditt

      I was told that there's no way to undo an OR as it loses value in the output.. I fumbled upon a formula , to undo an OR v1 or or_val = ( v1 xor or_val ) + ( v1 and or_val ) 100 or 5 = ( (100 or 5) xor 5 ) + ( 100 and 5 ) 100 or 10 = ( (100 or 10) xor 10 ) + ( 100 and 10 ) 255 or 12 = ( (255 or 12) xor 12 ) + ( 255 and 12 )

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Maybe you should be more clear about what you are saying.

      1 Reply Last reply
      0
      • A albert_redditt

        I was told that there's no way to undo an OR as it loses value in the output.. I fumbled upon a formula , to undo an OR v1 or or_val = ( v1 xor or_val ) + ( v1 and or_val ) 100 or 5 = ( (100 or 5) xor 5 ) + ( 100 and 5 ) 100 or 10 = ( (100 or 10) xor 10 ) + ( 100 and 10 ) 255 or 12 = ( (255 or 12) xor 12 ) + ( 255 and 12 )

        J Offline
        J Offline
        Jon McKee
        wrote on last edited by
        #3

        If you already have both original values in order to "undo" the OR, you've already effectively undone the OR. Or am I missing something? :doh: Pretty sure this is an equivalency too, not an undo. If it was an undo it would generate two values from a single OR'd value, or generate a value given an OR'd value and one of the original values.

        M 1 Reply Last reply
        0
        • A albert_redditt

          I was told that there's no way to undo an OR as it loses value in the output.. I fumbled upon a formula , to undo an OR v1 or or_val = ( v1 xor or_val ) + ( v1 and or_val ) 100 or 5 = ( (100 or 5) xor 5 ) + ( 100 and 5 ) 100 or 10 = ( (100 or 10) xor 10 ) + ( 100 and 10 ) 255 or 12 = ( (255 or 12) xor 12 ) + ( 255 and 12 )

          R Offline
          R Offline
          Rick York
          wrote on last edited by
          #4

          To stay with binary logic operations, what your formula boils down to is (using C syntax) :

          A | B = ( A ^ B ) | ( A & B )

          That is not "undoing" the OR operation. That is a sequence of operations which arrive at the same result. To undo A | B = C you need to perform operations on C with B to give a result of A or operations on C with A that give B. I find it easier to do binary logic with hexadecimal numbers so with the first numbers,

          100 = 0x64
          5 = 0x05
          0x64 | 0x05 = 0x65

          To undo the OR what you need is

          0x65 ? 0x05 = 0x64

          or

          0x65 ? 0x64 = 0x05

          I don't know what that expression would be and I can see why you were told it is impossible.

          "They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"

          1 Reply Last reply
          0
          • A albert_redditt

            I was told that there's no way to undo an OR as it loses value in the output.. I fumbled upon a formula , to undo an OR v1 or or_val = ( v1 xor or_val ) + ( v1 and or_val ) 100 or 5 = ( (100 or 5) xor 5 ) + ( 100 and 5 ) 100 or 10 = ( (100 or 10) xor 10 ) + ( 100 and 10 ) 255 or 12 = ( (255 or 12) xor 12 ) + ( 255 and 12 )

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            albert_redditt wrote:

            I was told that there's no way to undo an OR as it loses value in the output..

            That is correct. Boolean algebra is implemented in programming languages but it still originates from that branch of mathematics. If you have a value '1' there is no way you will ever be able to tell which of the following statements it originated from.

            1 | 1
            1 | 0
            0 | 1

            Because of that you cannot do that you cannot, in a programming language, recover the original values from a value that was created by oring other values together.

            1 Reply Last reply
            0
            • A albert_redditt

              I was told that there's no way to undo an OR as it loses value in the output.. I fumbled upon a formula , to undo an OR v1 or or_val = ( v1 xor or_val ) + ( v1 and or_val ) 100 or 5 = ( (100 or 5) xor 5 ) + ( 100 and 5 ) 100 or 10 = ( (100 or 10) xor 10 ) + ( 100 and 10 ) 255 or 12 = ( (255 or 12) xor 12 ) + ( 255 and 12 )

              J Offline
              J Offline
              James Curran
              wrote on last edited by
              #6

              To reverse a OR operation, given on something like

              A | B = C

              solve for B knowing only A & C. For example:

              6 | B = 7

              Given that, B could be 1 or 3 or 5 or 7. Any of those would work in the equation, and there is no way to know which it was.

              Truth, James

              1 Reply Last reply
              0
              • A albert_redditt

                I was told that there's no way to undo an OR as it loses value in the output.. I fumbled upon a formula , to undo an OR v1 or or_val = ( v1 xor or_val ) + ( v1 and or_val ) 100 or 5 = ( (100 or 5) xor 5 ) + ( 100 and 5 ) 100 or 10 = ( (100 or 10) xor 10 ) + ( 100 and 10 ) 255 or 12 = ( (255 or 12) xor 12 ) + ( 255 and 12 )

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                The formula is correct (though as mentioned it doesn't "undo" the OR, it computes the OR in terms of other operations) and I'll prove it algebraically, starting at the end and deriving that it must be equal to `v1 | or_val`. ```text ( v1 ^ or_val ) + ( v1 & or_val ) = (the left and right operands do not "intersect", their bitwise AND is zero, in that case A + B == A | B) ( v1 ^ or_val ) | ( v1 & or_val ) = (OR distributes over AND) (v1 ^ or_val | v1) & (v1 ^ or_val | or_val) = (A ^ B | B == A | B) (or_val | v1) & (v1 | or_val) = (A AND A == A) v1 | or_val ```

                1 Reply Last reply
                0
                • A albert_redditt

                  I was told that there's no way to undo an OR as it loses value in the output.. I fumbled upon a formula , to undo an OR v1 or or_val = ( v1 xor or_val ) + ( v1 and or_val ) 100 or 5 = ( (100 or 5) xor 5 ) + ( 100 and 5 ) 100 or 10 = ( (100 or 10) xor 10 ) + ( 100 and 10 ) 255 or 12 = ( (255 or 12) xor 12 ) + ( 255 and 12 )

                  P Offline
                  P Offline
                  Phil Hodgkins
                  wrote on last edited by
                  #8

                  It uses the value you are trying to find to find the value you are trying to find. No point to it. E.g. for X OR 9 = 11, use it to find the value of X.

                  1 Reply Last reply
                  0
                  • A albert_redditt

                    I was told that there's no way to undo an OR as it loses value in the output.. I fumbled upon a formula , to undo an OR v1 or or_val = ( v1 xor or_val ) + ( v1 and or_val ) 100 or 5 = ( (100 or 5) xor 5 ) + ( 100 and 5 ) 100 or 10 = ( (100 or 10) xor 10 ) + ( 100 and 10 ) 255 or 12 = ( (255 or 12) xor 12 ) + ( 255 and 12 )

                    R Offline
                    R Offline
                    Rob Grainger
                    wrote on last edited by
                    #9

                    I suspect the person telling you that meant there is no mathematical inverse to the OR operator - which means that the input of a function (or operator) must be reconstructable from the input to that function. In this sense, OR definitely has no inverse.

                    "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                    Richard DeemingR 1 Reply Last reply
                    0
                    • R Rob Grainger

                      I suspect the person telling you that meant there is no mathematical inverse to the OR operator - which means that the input of a function (or operator) must be reconstructable from the input to that function. In this sense, OR definitely has no inverse.

                      "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                      Richard DeemingR Offline
                      Richard DeemingR Offline
                      Richard Deeming
                      wrote on last edited by
                      #10

                      Rob Grainger wrote:

                      the input of a function (or operator) must be reconstructable from the input to that function

                      That's trivial. It's reconstructing it from the output that's difficult. ;P


                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                      1 Reply Last reply
                      0
                      • J Jon McKee

                        If you already have both original values in order to "undo" the OR, you've already effectively undone the OR. Or am I missing something? :doh: Pretty sure this is an equivalency too, not an undo. If it was an undo it would generate two values from a single OR'd value, or generate a value given an OR'd value and one of the original values.

                        M Offline
                        M Offline
                        Matias Lopez
                        wrote on last edited by
                        #11

                        But, what's the utility of using this type of syntax to "exec-undo" "dual-values"? :confused:

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups