SlideShare a Scribd company logo
1 of 1
Given vectors u = (u_1, u_2,..., u_n) and v = (v_1, v_2,,..., v_n), the inner product of u and v is
defined to be u_1*v_1 + u_2*v_2 + ... + u_n*v_n. Write a curried F# function inner that takes
two vectors represented as int lists and returns their inner product (assuming the two lists are of
equal length): > inner [1;2;3] [4;5;6];; val it: int = 32
Solution
Answer:)
let rec inner xs ys =
match (xs, ys) with
| ([],[]) -> 0
| ([],ys) -> failwith "Vector dimensions inconsistent"
| (xs,[]) -> failwith "Vector dimensions inconsistent"
| (x::xs, y::ys) -> x*y + inner xs ys
inner [1;2;3] [4;5;6]

More Related Content

More from rtodd588

More from rtodd588 (8)

Graphite bonds in flat sheets with only London forces to hold the shee.docx
Graphite bonds in flat sheets with only London forces to hold the shee.docxGraphite bonds in flat sheets with only London forces to hold the shee.docx
Graphite bonds in flat sheets with only London forces to hold the shee.docx
 
Given this information about activity 3-4- ES - 10- EF - 15- LS - 16-.docx
Given this information about activity 3-4- ES - 10- EF - 15- LS - 16-.docxGiven this information about activity 3-4- ES - 10- EF - 15- LS - 16-.docx
Given this information about activity 3-4- ES - 10- EF - 15- LS - 16-.docx
 
Growing active lifestyle apparel segment Wholesale distribution mix De.docx
Growing active lifestyle apparel segment Wholesale distribution mix De.docxGrowing active lifestyle apparel segment Wholesale distribution mix De.docx
Growing active lifestyle apparel segment Wholesale distribution mix De.docx
 
Group Policy is one of the most useful features of Windows Server 2008.docx
Group Policy is one of the most useful features of Windows Server 2008.docxGroup Policy is one of the most useful features of Windows Server 2008.docx
Group Policy is one of the most useful features of Windows Server 2008.docx
 
how can I better understand how to do the reverse in factoring polynom.docx
how can I better understand how to do the reverse in factoring polynom.docxhow can I better understand how to do the reverse in factoring polynom.docx
how can I better understand how to do the reverse in factoring polynom.docx
 
Holly inherited $10-000 of City of Atlanta bonds in February- In March.docx
Holly inherited $10-000 of City of Atlanta bonds in February- In March.docxHolly inherited $10-000 of City of Atlanta bonds in February- In March.docx
Holly inherited $10-000 of City of Atlanta bonds in February- In March.docx
 
Hi- Please- need help- and step by step- More detail- I need to unders.docx
Hi- Please- need help- and step by step- More detail- I need to unders.docxHi- Please- need help- and step by step- More detail- I need to unders.docx
Hi- Please- need help- and step by step- More detail- I need to unders.docx
 
hich is most solo ble ethane - ethamol2 butane ar butanal2 SolutionAlk.docx
hich is most solo ble ethane - ethamol2 butane ar butanal2 SolutionAlk.docxhich is most solo ble ethane - ethamol2 butane ar butanal2 SolutionAlk.docx
hich is most solo ble ethane - ethamol2 butane ar butanal2 SolutionAlk.docx
 

Recently uploaded

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 

Recently uploaded (20)

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

Given vectors u - (u_1- u_2----- u_n) and v - (v_1- v_2------ v_n)- th.docx

  • 1. Given vectors u = (u_1, u_2,..., u_n) and v = (v_1, v_2,,..., v_n), the inner product of u and v is defined to be u_1*v_1 + u_2*v_2 + ... + u_n*v_n. Write a curried F# function inner that takes two vectors represented as int lists and returns their inner product (assuming the two lists are of equal length): > inner [1;2;3] [4;5;6];; val it: int = 32 Solution Answer:) let rec inner xs ys = match (xs, ys) with | ([],[]) -> 0 | ([],ys) -> failwith "Vector dimensions inconsistent" | (xs,[]) -> failwith "Vector dimensions inconsistent" | (x::xs, y::ys) -> x*y + inner xs ys inner [1;2;3] [4;5;6]