function 2: transform
transform:
description:
transform(sp1, sp2) input-sp
transform the ingredients in sp1 into those in sp2, providing there are enough ingredients in the input superposition
eg, process a chemical reaction, or a nuclear reaction, or a trade, etc
if there are not enough ingredients in input-sp then return it unchanged
examples:
-- the first example is make water from hydrogen and oxygen gas:
make-water (*) #=> transform( 2|H2> + |O2>, 2|H2O> ) |__self>
-- first try to make water with just hydrogen gas:
-- and we see the reaction did not proceed:
make-water 10|H2>
10|H2>
-- now try to make 40 molecules of water from 10 molecules of hydrogen gas and 10 of oxygen gas:
-- and we see we only have enough ingredients to successfully apply the make-water operator 5 times:
-- ie, 10 molecules of water
make-water^20 (10|H2> + 10|O2>)
0|H2> + 5|O2> + 10|H2O>
-- the next example is going shopping, ie a trade of cash for goods:
-- first define the shopping list:
the |shopping list> => 5|apple> + 7|orange> + |milk> + |steak> + |coffee> + |bread>
-- now define their prices:
-- note that if an item on your shopping list does not have a defined price, you get it for free
-- though we can change that behaviour by defining a general rule:
-- price |*> => |item not for sale>
-- then if any items do not have a specific price, the shopping will fail
-- because |item not for sale> is not in the input superposition for the transform operator
price |apple> => 0.4|dollar>
price |orange> => 0.6|dollar>
price |milk> => 2|dollar>
price |steak> => 9|dollar>
price |coffee> => 4.5|dollar>
price |bread> => 2.6|dollar>
-- now let's define the buy-shopping operator:
buy-shopping (*) #=> transform(price the |shopping list>, the |shopping list>) |__self>
-- now let's try to buy our shopping starting with 10 dollars:
-- and the trade/purchase fails because we don't have enough money:
buy-shopping 10|dollar>
10|dollar>
-- now try again, but this time with 100 dollars:
buy-shopping 100|dollar>
75.700000|dollar> + 5|apple> + 7|orange> + |milk> + |steak> + |coffee> + |bread>
-- of course, we could have saved ourselves trouble, by calculating the cost of our shopping list
-- before trying to buy it with only 10 dollars:
price the |shopping list>
24.300000|dollar>
-- now let's consider the toy example of fissioning U235:
-- first, learn some of the possible reactions:
-- NB: a realistic example would include |MeV> too
fission-channel-1 |U: 235> => |Ba: 141> + |Kr: 92> + 3|n>
fission-channel-2 |U: 235> => |Xe: 140> + |Sr: 94> + 2|n>
fission-channel-3 |U: 235> => |La: 143> + |Br: 90> + 3|n>
fission-channel-4 |U: 235> => |Cs: 137> + |Rb: 96> + 3|n>
fission-channel-5 |U: 235> => |I: 131> + |Y: 89> + 16|n>
-- now learn their operators:
-- NB: a realistic example would also include their respective probabilities, as coefficients of each of the channels
list-of-fission-channels |U: 235> => |op: fission-channel-1> + |op: fission-channel-2> + |op: fission-channel-3> + |op: fission-channel-4> + |op: fission-channel-5>
-- now define a single fission event operator:
fission |*> #=> apply(weighted-pick-elt list-of-fission-channels |_self>, |_self>)
-- now let's try out our new fission operator a couple of times:
fission |U: 235>
|La: 143> + |Br: 90> + 3|n>
fission |U: 235>
|Ba: 141> + |Kr: 92> + 3|n>
fission |U: 235>
|Xe: 140> + |Sr: 94> + 2|n>
-- now, let's define an operator that transforms one neutron and one U235 into fission decay products:
fission-uranium-235 (*) #=> transform(|n> + |U: 235>, fission |U: 235>) |__self>
-- let's apply it once to one neutron and 10 U235 atoms:
fission-uranium-235 (|n> + 10|U: 235>)
2|n> + 9|U: 235> + |Xe: 140> + |Sr: 94>
-- let's apply it 50 times to one neutron and 100 U235 atoms:
fission-uranium-235^50 (|n> + 100|U: 235>)
173|n> + 50|U: 235> + 10|Cs: 137> + 10|Rb: 96> + 12|La: 143> + 12|Br: 90> + 10|Ba: 141> + 10|Kr: 92> + 7|Xe: 140> + 7|Sr: 94> + 7|I: 131> + 7|Y: 89>
-- finally, let's define some operators to change a person's state:
-- open-can, eat-food, go-to-sleep:
open-can (*) #=> drop transform(|closed can>, |open can>) |__self>
eat-food (*) #=> drop transform(|open can> + |hungry>, |empty can> + |not hungry>) |__self>
go-to-sleep (*) #=> drop transform(|tired>, |asleep>) |__self>
-- now define my current state:
current-state |me> => |closed can> + |hungry> + |tired>
-- now let's use them step by step:
open-can current-state |me>
|hungry> + |tired> + |open can>
eat-food open-can current-state |me>
|tired> + |empty can> + |not hungry>
go-to-sleep eat-food open-can current-state |me>
|empty can> + |not hungry> + |asleep>
-- note that you can't successfully eat-food before you open-can:
eat-food current-state |me>
|closed can> + |hungry> + |tired>
see also:
Home