Do not display this message again
Close window
Application Center - Maplesoft
Contact Maplesoft
Request Quote
Products
Maple
Powerful math software that is easy to use
• Maple for Academics
• Maple for Students
• Maple Learn
• Maple Calculator App
• Maple for Industry and Government
• Maple for Individuals
Maple Add-Ons
• E-Books & Study Guides for Students
• Maple Toolboxes
• MapleNet
• Free Maple Player
Math Success Platform
Improving Retention Rates
Maple Flow
Engineering calculations & documentation
• Maple Flow
• Maple Flow Migration Assistant
MapleSim
Advanced System Level Modeling
• MapleSim
• MapleSim for Web Converting Systems
• MapleSim for Digital Twins
• MapleSim for Education
• Add-on Libraries and Connectors
• MapleSim Insight
Consulting Services
• Engineering Services
• Training
• Turnkey Solutions
Maple T.A. and Möbius
Looking for Maple T.A. or Möbius?
DigitalEd, a Maplesoft technology partner, now offers these products. Learn more.
Solutions
Education
• Mathematics Education
• Engineering Education
• High Schools & Two-Year Colleges
• Students
• Remote Learning Resources
Industries
Automotive and Aerospace
• Electric & Hybrid-Electric Vehicles
• Powertrain
• Vehicle Dynamics
• Heavy Mobile Machinery
• Aircraft Systems
• Space Systems
Robotics
• Robotics Research
• Motion Control/Mechatronics
Machine Design & Industrial Automation
• Machine Design
• Manufacturing
• Mining & Oil Production Equipment
• Web Handling
Other
• Power Industries
• Finance
• Medical Devices
• Life Sciences
Application Areas
• Power Systems Engineering
• Electrical Engineering Calculations
• Mechanical Engineering Calculations
• System Simulation & Analysis
• Virtual Commissioning
• Battery Modeling and Design
• Heat Transfer Modeling
• Dynamic Analysis of Mechanisms
• Calculation Management
• Model development for HIL
• Vibration Analysis & Attenuation
Purchase
Product Pricing
• Maple
• Maple Flow
• MapleSim
• Add-Ons and Connectors
• Request a Quote
Purchasing
• Purchase & Download Immediately
• Upgrade to the Latest Version
• Contact Sales
Institutional Student Licensing
• Virtualization
• Student Licensing & Distribution Options
Maplesoft Elite Maintenance (EMP)
• EMP Overview
• EMP FAQ
Support & Resources
Support
• Tech Support & Customer Service
• Frequently Asked Questions
• Product Documentation
• Download Product Updates
Product Training
• Student Help Center
• Online Product Training
• On-Site Training
Online Product Help
• Maple Online Help
• MapleSim Online Help
Webinars & Events
• Live Webinars
• Recorded Webinars
• Upcoming Events
Publications
• Technical Whitepapers
• E-Mail Newsletters
• Maple Books
• Math Matters
Content Hubs
• Teacher Resource Center
• Student Help Center
• Remote Learning Resources
Examples & Applications
• Maple Application Center
• MapleSim Model Gallery
• User Case Studies
• Exploring Engineering Fundamentals
• Teaching Concepts with Maple
Community
• MaplePrimes
• MapleCloud
• Maple Conference
Company
About Maplesoft
• Company Overview
• Management
• Customers
• Partnerships and OEM Opportunities
Media Center
• Media Releases
• User Case Studies
• Media Coverage
User Community
• MaplePrimes
• Maple Ambassador Program
• Maple Conference
Contact
• Global Contact Details
• Careers
Home
Products
Maple
Maple Add-Ons
Maple Learn
Maple Calculator App
Maple Flow
MapleSim
MapleSim Add-Ons
Consulting Services
Online Education Products
Solutions
Education
Industries
Application Areas
Purchase
Product Pricing
Purchasing
Institutional Student Licensing
Maplesoft Elite Maintenance (EMP)
Support & Resources
Support
Product Training
Online Product Help
Webinars & Events
Publications
Content Hubs
Examples & Applications
Community
Company
About Maplesoft
Media Center
User Community
Contact
Toggle navigation
Sign in
Register
Submit your work
Application Center
Applications
Wallace Tree Decoder
Preview
App Preview:
Wallace Tree Decoder
You can switch back to the summary page by clicking
here.
Learn about Maple
Download Application
Wallace Tree Decoder
Ron Dotson, (c) May 23, 2003
>
with (Logic):
Environment(2):
# 3-bit Decoder (3 inputs, 2 outputs)
# Out1:= &xor(i1,i2,i3); # LSB
# Out2:= &or(&and(i1,i2),&and(i1,i3),&and(i2,i3)); # MSB
# ______________________________________________________
# 'decode' Creates subsequent stages of a Wallace Tree Decoder
# from elements in the input list, and returns either a single
# element, or a two element nested list in which the first list
# element is the LSB (2^0) bit of the decoded count, and the
# second list element is itself a list of the carries generated
# for bit position 2^1. The last element of the input list 'inL'
# must itself be a list of prior carries into the MSB position of
# the two bits being output, which will be appended to by 'decoder'.
# Called by: decoder
#
decode:= proc(inL::list)::list; # LSB = inL[1]
local N::integer, n::integer, i::integer:
global S, Cy;
use Logic in
S:=[];
Cy:=[];
n:= nops(inL)-1; # ignore the sublist on the MSB end
#print(`dec
ode: n=`,n);
#print(`decode: inL=`,inL);
ASSERT(n>0,`Error(decode): Parameter list empty`);
if n<=3 then
if n=1 then # one LSB (nothing to decode)
return inL;
elif n=2 then # two LSBs
return [&xor(inL[1],inL[2]),[&and(inL[1],inL[2]),op(inL[3])]];
else # three LSBs
return [&xor(inL[1],inL[2],inL[3]),[&or(&and(inL[1],inL[2]),&and(inL[1],inL[3]),&and(inL[2],inL[3])),op(inL[4])]];
fi;
fi;
for i from 1 by 3 while n>3 do
S:= [op(S),&xor(inL[i],inL[i+1],inL[i+2])]; # LSB
Cy:= [op(Cy),&or(&and(inL[i],inL[i+1]),&and(inL[i],inL[i+2]),&and(inL[i+1],inL[i+2]))]; # MSB
n:= n - 3;
od;
if n=1 then # one remaining LSB
ASSERT(i+1 = nops(inL),`Error(decode): i+1 = nops(inL) FAILED`);
S:= [op(S),inL[i]];
Cy:= [op(Cy),false];
elif n=2 then # two LSBs
ASSERT(i+2 = nops(inL),`Error(decode): i+2 = nops(inL) FAILED`);
S:= [op(S),&xor(inL[i],inL[i+1])];
Cy:= [op(Cy),&and(inL[i],inL[i+1])];
else # three LSBs
ASSERT(i+3 = nops(inL),`Error(decode): i+3 = nops(inL) FAILED`);
S:= [op(S),&xor(inL[i],inL[i+1],inL[i+2])];
Cy:= [op(Cy),&or(&and(inL[i],inL[i+1]),&and(inL[i],inL[i+2]),&and(inL[i+1],inL[i+2]))];
fi;
return decode([op(S),[op(Cy),op(inL[nops(inL)])]]);
end use;
end proc: # decode
# ______________________________________________________
# 'decoder' Creates the first stage of a Wallace Tree Decoder from
# elements in the input list, and returns either a single element, or
# a two element nested list in which the first list element is the
# LSB (2^0) bit of the decoded count, and the second list element
# is itself a list of the carries generated for bit position 2^1.
# Calls: decode
#
decoder:= proc(inL::list)::list; # LSB = inL[1]
local N::integer, n::integer, i::integer, j::integer, car;
global S, Cy, U;
use Logic in
S:=[];
Cy:=[];
n:= nops(inL);
#print(`decoder: n=`,n);
#print(`decoder: inL=`,inL);
ASSERT(n>0,`Error(decoder): Parameter list empty`);
if n<=3 then
if n=1 then
return inL;
elif n=2 then
ASSERT(nops(&and(inL[1],inL[2]))=2,`Error(decoder): nops(&and(inL[1],inL[2]))=2 FAILED`);
return [&xor(inL[1],inL[2]),[&and(inL[1],inL[2])]];
else # n=3
car:= &or(&and(inL[1],inL[2]),&and(inL[1],inL[3]),&and(inL[2],inL[3])); # MSB
return [&xor(inL[1],inL[2],inL[3]),[car]];
fi;
fi;
for i from 1 by 3 while n>3 do
S:= [op(S),&xor(inL[i],inL[i+1],inL[i+2])]; # LSB
Cy:= [op(Cy),&or(&and(inL[i],inL[i+1]),&and(inL[i],inL[i+2]),&and(inL[i+1],inL[i+2]))]; # MSB
n:= n - 3;
od;
if n=1 then # one remaining LSB
S:= [op(S),inL[i]];
Cy:= [op(Cy),false];
elif n=2 then # two LSBs
S:= [op(S),&xor(inL[i],inL[i+1])];
Cy:= [op(Cy),&and(inL[i],inL[i+1])];
else # three LSBs
S:= [op(S),&xor(inL[i],inL[i+1],inL[i+2])];
Cy:= [op(Cy),&or(&and(inL[i],inL[i+1]),&and(inL[i],inL[i+2]),&and(inL[i+1],inL[i+2]))];
fi;
U:= decode([op(S),Cy]); # Cy is already a list
ASSERT(nops(U)<=2);
if nops(U)=1 then
return [U[1]];
else # nops(U)=2
if type(U[2],list) then
return [U[1],op(decode(U[2]))]; # decode sublist and return w/o sublist
else
return [op(decoder([U[1],U[2]]))]; # else NO sublist
fi;
fi;
end use;
end proc: # decoder
# ______________________________________________________
wallace:= proc(inL::list)::list; # LSB = inL[1]
local R::list, r;
use Logic in
R:= decoder(inL);
r:= R[nops(R)];
if type(r,list) then
R:= subsop(nops(R)=seq(r[i],i=1..nops(r)),R)
fi;
return R;
end use;
end proc: # wallace
>
Result1:= wallace([a1,b1]);
>
Result2:= wallace([true,true,false,true,false,true,true,false,true]); # count number of one bits in parameter list
>
Result3:= wallace([m,n,o,p,q,r]);
>