Advertisement
Guest User

Untitled

a guest
Dec 26th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Oz 1.70 KB | None | 0 0
  1. fun {AndG X Y}
  2.     case X#Y of (H|T)#(I|V)
  3.     then H*I|{AndG T V}
  4.     [] nil#nil then nil
  5.     else X*Y
  6.     end
  7. end
  8. fun {OrG X Y}
  9.     case X#Y of (H|T)#(I|V)
  10.     then H+I-(H*I)|{OrG T V}
  11.     [] nil#nil then nil
  12.     else X+Y-(X*Y)
  13.     end
  14. end
  15. fun {XorG X Y}
  16.     case X#Y of (H|T)#(I|V)
  17.     then H+I-2*H*I|{OrG T V}
  18.     [] nil#nil then nil
  19.     else X+Y-2*Y*X
  20.     end
  21. end
  22. proc {FullAdder X Y Z C S}
  23.     local
  24.         A
  25.         B
  26.         D
  27.         E
  28.         F
  29.     in
  30.         A={AndG X Y}
  31.         B={AndG Y Z}
  32.         D={AndG X Z}
  33.         E={XorG X Y}
  34.         F={OrG B D}
  35.         C={OrG A F}
  36.          S={XorG Z E}
  37.     end
  38. end
  39. fun {NFullAdder S1 S2}
  40.     local
  41.         fun{Reverse L Acc}
  42.             case L of H|T then
  43.                 if Acc==nil then {Reverse T H|nil}
  44.                 else {Reverse T H|Acc}
  45.                 end
  46.             else Acc
  47.             end
  48.         end
  49.         fun{Listo L1 L2 Prev LSol}
  50.             local
  51.                 X
  52.                 Y
  53.             in
  54.                 case L1#L2 of (I|T)#(J|V) then
  55.                     {FullAdder I J Prev X Y}
  56.                     {Listo T V X Y|LSol}
  57.                 else LSol#Prev
  58.                 end
  59.             end
  60.         end
  61.         fun{NListo L1 L2}
  62.                 case L1#L2 of (H|T)#(I|V) then
  63.                     {Listo {Reverse H nil} {Reverse I nil} 0 nil}|{NListo T V}
  64.                 else nil
  65.                 end
  66.         end
  67.     in
  68.         {NListo S1 S2}
  69.     end
  70. end
  71. SA SB S5 S6 SC
  72.     S1 = [1 1 1 1 1]|[0 0 0 0 0]|[1 1 1 1 0]|S5
  73.     S2 = [1 1 1 1 1]|[0 0 0 0 0]|[0 0 0 0 1]|S6
  74.     thread SA=S1 end
  75.     thread SB=S2 end
  76.     thread SC = {NFullAdder SA SB} end
  77.     thread {Browse SC} end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement