sequence function: consume-reaction

    description:
        consume-reaction(sp, sp, sp)
        process a chemical reaction that consumes the reactants
        eg: 2 H_2 + O_2 -> 2 H_2 0
        is represented by: 
            consume-reaction(input-sp, 2|H2> + |O2>, 2|H2O>)
        which is equivalent to:
            input-sp - (2|H2> + |O2>) + 2|H2O>
      
        if input-sp doesn't contain the necessary reactants, then it is returned unchanged
        
        an alternate definition:
        consume-reaction (*,*,*) #=> if(is-subset(|_self2>, |_self1>), |_self1> - |_self2> + |_self3>, |_self1>)
      
    examples:
        -- learn some knowledge:
        current |state> => words-to-list |can opener, closed can and hungry>
        learn-state (*) #=> learn(|op: current>, |state>, |_self>)
        use |can opener> #=> learn-state consume-reaction(current |state>, |can opener> + |closed can>, |can opener> + |open can>)
        eat-from |can> #=> learn-state consume-reaction(current |state>, |open can> + |hungry>, |empty can> + |not hungry>)
      
        -- what is our starting state?
        current |state>
            |can opener> + |closed can> + |hungry>
      
        -- what is the state after using the can-opener?
        use |can opener>
            |can opener> + |hungry> + |open can>
      
        -- what is the state after we eat-from the can?
        eat-from |can>
            |can opener> + |empty can> + |not hungry>

    
        -- next, see: shopping.sw
        -- learn the prices for some items:
        the-price-for |apple> => 0.6|dollar>
        the-price-for |orange> => 0.8|dollar>
        the-price-for |milk> => 2.3|dollar>
        the-price-for |coffee> => 5.5|dollar>
        the-price-for |steak> => 9|dollar>
        
        -- learn our shopping list:
        the |shopping list> => |orange> + 4|apple> + |milk> + |coffee> + |steak>
        
        -- check if we know the price for an item:       
        price-is-defined |*> #=> do-you-know the-price-for |_self>
        
        -- filter our shopping list down to available items:
        the-list-of |available items> #=> such-that[price-is-defined] the |shopping list>
        
        -- define our buy operator:
        buy (*,*) #=> consume-reaction( |_self2>, the-price-for |_self1>, |_self1>)
        
        -- ask, what are the available items?
        the-list-of |available items>
            |orange> + 4|apple> + |milk> + |coffee> + |steak>
        
        -- now ask, what is the price for the available items?
        the-price-for the-list-of |available items>
            20|dollar>
                    
        -- now go shopping with $30:
        buy(the-list-of |available items>, 30 |dollar>)
            10|dollar> + |orange> + 4|apple> + |milk> + |coffee> + |steak>
            
        -- convert superposition result to English:
        plural |*> #=> |_self> _ |s>
        list-to-words int-coeffs-to-word buy(the-list-of |available items>, 30 |dollar>)
            |10 dollars, 1 orange, 4 apples, 1 milk, 1 coffee and 1 steak>

    see also:
        catalytic-reaction, eat-from-can, fission-uranium

Home