SlideShare a Scribd company logo
1 of 10
Download to read offline
吳 哲 綱
2015.3.17
Fast doubling Fibonacci : arm
assembly實作
 複雜度𝑂(log 𝑛)
 不需要floating point運算
公式
 矩陣表示式
1 1
1 0
𝑛
=
𝐹(𝑛 + 1) 𝐹(𝑛)
𝐹 𝑛 𝐹(𝑛 − 1)
 Fast doubling
𝐹 2𝑘 = 𝐹(𝑘)[2𝐹(𝑘 + 1) − 𝐹(𝑘)]
𝐹(2𝑘 + 1) = 𝐹(𝑘 + 1)2
+ 𝐹(𝑘)2
證明-矩陣表示式
 以數學歸納法證明:
1 𝑛 = 1;
1 1
1 0
1
=
𝐹(2) 𝐹(1)
𝐹(1) 𝐹(0)
2 設
1 1
1 0
𝑛
=
𝐹(𝑛 + 1) 𝐹(𝑛)
𝐹 𝑛 𝐹(𝑛 − 1)
成立
⇒
1 1
1 0
𝑛+1
=
𝐹(𝑛 + 1) 𝐹(𝑛)
𝐹 𝑛 𝐹(𝑛 − 1)
1 1
1 0
=
𝐹 𝑛 + 1 + 𝐹 𝑛 𝐹 𝑛 + 1
𝐹 𝑛 + 𝐹 𝑛 − 1 𝐹 𝑛
=
𝐹 𝑛 + 2 𝐹 𝑛 + 1
𝐹 𝑛 + 1 𝐹 𝑛
證明-fast doubling
由矩陣表示式可知
𝐹 2𝑛 + 1 𝐹 2𝑛
𝐹 2𝑛 𝐹 2𝑛 − 1
=
1 1
1 0
2𝑛
=
1 1
1 0
𝑛 2
=
𝐹(𝑛 + 1) 𝐹(𝑛)
𝐹 𝑛 𝐹(𝑛 − 1)
2
=
𝐹(𝑛 + 1)2 + 𝐹(𝑛)2 𝐹(𝑛 + 1)𝐹(𝑛) + 𝐹(𝑛)𝐹(𝑛 − 1)
𝐹(𝑛)𝐹(𝑛 + 1) + 𝐹(𝑛 − 1)𝐹(𝑛) 𝐹(𝑛)2 + 𝐹(𝑛 − 1)2
比較前後式可得:
1 𝐹 2𝑛 + 1 = 𝐹(𝑛 + 1)2 + 𝐹(𝑛)2
2 𝐹 2𝑛 = 𝐹 𝑛 𝐹 𝑛 + 1 + 𝐹 𝑛 − 1
= 𝐹 𝑛 𝐹 𝑛 + 1 + 𝐹 𝑛 + 1 − 𝐹 𝑛
= 𝐹(𝑛)[2𝐹(𝑛 + 1) − 𝐹(𝑛)]
演算法
Fast_Fib(n)
a = 0; b = 1; //m=0
for i = (number of binary digit in n) to 1
t1 = a*(2*b-a);
t2 = b^2 + a^2;
a = t1; b = t2; //m*=2
if(current binary digit == 1)
t1=a+b; //m++
a = b; b = t1;
return a;
例: n = 10 = 10102
i start 4 3 2 1 result
n 1010
^
1010
^
1010
^
1010
^
F(m) F(0) F(0*2+1) F(1*2) F(2*2+1) F(5*2) F(10)
a 0 1 1 5 55 55
b 1 1 2 8 89
Assembly實作
 省略 F(0),從F(1)開始
 clz:計算leading zeros以求位數
 cbz:if(Ra==0) goto label
 利用rsb (reverse subtract) + barrel shifter
參考資料
 ARM instruction quick reference --
http://users.ece.utexas.edu/~valvano/Volume1/QuickRefe
renceCard.pdf
 Project Nayuki : Fast Fibonacci algorithms --
http://www.nayuki.io/page/fast-fibonacci-algorithms
 Wiki : Fibonacci number --
https://en.wikipedia.org/wiki/Fibonacci_number
 The first 300 Fibonacci numbers --
http://www.maths.surrey.ac.uk/hosted-
sites/R.Knott/Fibonacci/fibtable.html

More Related Content

What's hot

Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Pramit Kumar
 
Bicubic interpolation codes
Bicubic interpolation codesBicubic interpolation codes
Bicubic interpolation codesmmjalbiaty
 
딥러닝 교육 자료 #2
딥러닝 교육 자료 #2딥러닝 교육 자료 #2
딥러닝 교육 자료 #2Ashal aka JOKER
 
Logsexponents
LogsexponentsLogsexponents
Logsexponentsr0xee
 
1 fichas refuerzo operaciones combinadas numeros
1 fichas refuerzo operaciones combinadas numeros1 fichas refuerzo operaciones combinadas numeros
1 fichas refuerzo operaciones combinadas numerosBea Marfer
 
Waldie pd2
Waldie pd2Waldie pd2
Waldie pd2guero456
 
Ds0601 stack
Ds0601 stackDs0601 stack
Ds0601 stackvirajrana
 
Matrix Manipulation in Matlab
Matrix Manipulation in MatlabMatrix Manipulation in Matlab
Matrix Manipulation in MatlabMohamed Loey
 
More multiplication properties of exponents
More multiplication properties of exponents More multiplication properties of exponents
More multiplication properties of exponents chrystal_brinson
 
PC Test 2 study guide 2011
PC Test 2 study guide 2011PC Test 2 study guide 2011
PC Test 2 study guide 2011vhiggins1
 
Quadratic functions
Quadratic functionsQuadratic functions
Quadratic functionsIvy Estrella
 
Exercise 2
Exercise 2Exercise 2
Exercise 2math126
 
Cambio Climatico CO2 y la Diferencial de una funcion
Cambio Climatico CO2 y la Diferencial de una funcionCambio Climatico CO2 y la Diferencial de una funcion
Cambio Climatico CO2 y la Diferencial de una funcionJudith Medina Vela
 

What's hot (18)

Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)
 
Conformal mapping
Conformal mappingConformal mapping
Conformal mapping
 
Bicubic interpolation codes
Bicubic interpolation codesBicubic interpolation codes
Bicubic interpolation codes
 
딥러닝 교육 자료 #2
딥러닝 교육 자료 #2딥러닝 교육 자료 #2
딥러닝 교육 자료 #2
 
Logsexponents
LogsexponentsLogsexponents
Logsexponents
 
1 fichas refuerzo operaciones combinadas numeros
1 fichas refuerzo operaciones combinadas numeros1 fichas refuerzo operaciones combinadas numeros
1 fichas refuerzo operaciones combinadas numeros
 
Mc
McMc
Mc
 
Waldie pd2
Waldie pd2Waldie pd2
Waldie pd2
 
Ds0601 stack
Ds0601 stackDs0601 stack
Ds0601 stack
 
Matrix Manipulation in Matlab
Matrix Manipulation in MatlabMatrix Manipulation in Matlab
Matrix Manipulation in Matlab
 
More multiplication properties of exponents
More multiplication properties of exponents More multiplication properties of exponents
More multiplication properties of exponents
 
PC Test 2 study guide 2011
PC Test 2 study guide 2011PC Test 2 study guide 2011
PC Test 2 study guide 2011
 
Quadratic functions
Quadratic functionsQuadratic functions
Quadratic functions
 
Exercise 2
Exercise 2Exercise 2
Exercise 2
 
Module 6.7
Module 6.7Module 6.7
Module 6.7
 
Cambio Climatico CO2 y la Diferencial de una funcion
Cambio Climatico CO2 y la Diferencial de una funcionCambio Climatico CO2 y la Diferencial de una funcion
Cambio Climatico CO2 y la Diferencial de una funcion
 
Hprec7.1
Hprec7.1Hprec7.1
Hprec7.1
 
AP Calculus 1984 FRQs
AP Calculus 1984 FRQsAP Calculus 1984 FRQs
AP Calculus 1984 FRQs
 

Similar to Fast doubling Fibonacci in ARM assembly

Hermite integrators and Riordan arrays
Hermite integrators and Riordan arraysHermite integrators and Riordan arrays
Hermite integrators and Riordan arraysKeigo Nitadori
 
Speed of Light
Speed of LightSpeed of Light
Speed of LightMarc King
 
Exponent & Logarithm
Exponent &  LogarithmExponent &  Logarithm
Exponent & Logarithmguest0ffcb4
 
Formulario oficial-calculo
Formulario oficial-calculoFormulario oficial-calculo
Formulario oficial-calculoFavian Flores
 
differential-calculus-1-23.pdf
differential-calculus-1-23.pdfdifferential-calculus-1-23.pdf
differential-calculus-1-23.pdfIILSASTOWER
 
Daa divide-n-conquer
Daa divide-n-conquerDaa divide-n-conquer
Daa divide-n-conquersankara_rao
 
Hermite integrators and 2-parameter subgroup of Riordan group
Hermite integrators and 2-parameter subgroup of Riordan groupHermite integrators and 2-parameter subgroup of Riordan group
Hermite integrators and 2-parameter subgroup of Riordan groupKeigo Nitadori
 
Ejercicio de fasores
Ejercicio de fasoresEjercicio de fasores
Ejercicio de fasoresdpancheins
 
Numerical Algorithm for a few Special Functions
Numerical Algorithm for a few Special FunctionsNumerical Algorithm for a few Special Functions
Numerical Algorithm for a few Special FunctionsAmos Tsai
 
ملزمة الرياضيات للصف السادس التطبيقي الفصل الاول الاعداد المركبة 2022
 ملزمة الرياضيات للصف السادس التطبيقي الفصل الاول الاعداد المركبة 2022 ملزمة الرياضيات للصف السادس التطبيقي الفصل الاول الاعداد المركبة 2022
ملزمة الرياضيات للصف السادس التطبيقي الفصل الاول الاعداد المركبة 2022anasKhalaf4
 
Chapter 3 - Inverse Functions.pdf
Chapter 3 - Inverse Functions.pdfChapter 3 - Inverse Functions.pdf
Chapter 3 - Inverse Functions.pdfManarKareem1
 
pot fracciones log etc.pdf
pot fracciones log etc.pdfpot fracciones log etc.pdf
pot fracciones log etc.pdfadelaleston
 
Solucao_Marion_Thornton_Dinamica_Classic (1).pdf
Solucao_Marion_Thornton_Dinamica_Classic (1).pdfSolucao_Marion_Thornton_Dinamica_Classic (1).pdf
Solucao_Marion_Thornton_Dinamica_Classic (1).pdfFranciscoJavierCaedo
 
Calculus 10th edition anton solutions manual
Calculus 10th edition anton solutions manualCalculus 10th edition anton solutions manual
Calculus 10th edition anton solutions manualReece1334
 

Similar to Fast doubling Fibonacci in ARM assembly (20)

Hermite integrators and Riordan arrays
Hermite integrators and Riordan arraysHermite integrators and Riordan arrays
Hermite integrators and Riordan arrays
 
Speed of Light
Speed of LightSpeed of Light
Speed of Light
 
Chapter001
Chapter001Chapter001
Chapter001
 
Exponent & Logarithm
Exponent &  LogarithmExponent &  Logarithm
Exponent & Logarithm
 
Tables
TablesTables
Tables
 
Formulario oficial-calculo
Formulario oficial-calculoFormulario oficial-calculo
Formulario oficial-calculo
 
differential-calculus-1-23.pdf
differential-calculus-1-23.pdfdifferential-calculus-1-23.pdf
differential-calculus-1-23.pdf
 
Daa divide-n-conquer
Daa divide-n-conquerDaa divide-n-conquer
Daa divide-n-conquer
 
Algorithm.ppt
Algorithm.pptAlgorithm.ppt
Algorithm.ppt
 
Hermite integrators and 2-parameter subgroup of Riordan group
Hermite integrators and 2-parameter subgroup of Riordan groupHermite integrators and 2-parameter subgroup of Riordan group
Hermite integrators and 2-parameter subgroup of Riordan group
 
Ejercicio de fasores
Ejercicio de fasoresEjercicio de fasores
Ejercicio de fasores
 
Numerical Algorithm for a few Special Functions
Numerical Algorithm for a few Special FunctionsNumerical Algorithm for a few Special Functions
Numerical Algorithm for a few Special Functions
 
Calculo
CalculoCalculo
Calculo
 
ملزمة الرياضيات للصف السادس التطبيقي الفصل الاول الاعداد المركبة 2022
 ملزمة الرياضيات للصف السادس التطبيقي الفصل الاول الاعداد المركبة 2022 ملزمة الرياضيات للصف السادس التطبيقي الفصل الاول الاعداد المركبة 2022
ملزمة الرياضيات للصف السادس التطبيقي الفصل الاول الاعداد المركبة 2022
 
Chapter 3 - Inverse Functions.pdf
Chapter 3 - Inverse Functions.pdfChapter 3 - Inverse Functions.pdf
Chapter 3 - Inverse Functions.pdf
 
pot fracciones log etc.pdf
pot fracciones log etc.pdfpot fracciones log etc.pdf
pot fracciones log etc.pdf
 
Maths ms
Maths msMaths ms
Maths ms
 
Solucao_Marion_Thornton_Dinamica_Classic (1).pdf
Solucao_Marion_Thornton_Dinamica_Classic (1).pdfSolucao_Marion_Thornton_Dinamica_Classic (1).pdf
Solucao_Marion_Thornton_Dinamica_Classic (1).pdf
 
Calculus 10th edition anton solutions manual
Calculus 10th edition anton solutions manualCalculus 10th edition anton solutions manual
Calculus 10th edition anton solutions manual
 
Merge Sort
Merge SortMerge Sort
Merge Sort
 

Recently uploaded

The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 

Recently uploaded (20)

The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 

Fast doubling Fibonacci in ARM assembly

  • 1. 吳 哲 綱 2015.3.17 Fast doubling Fibonacci : arm assembly實作
  • 2.  複雜度𝑂(log 𝑛)  不需要floating point運算
  • 3. 公式  矩陣表示式 1 1 1 0 𝑛 = 𝐹(𝑛 + 1) 𝐹(𝑛) 𝐹 𝑛 𝐹(𝑛 − 1)  Fast doubling 𝐹 2𝑘 = 𝐹(𝑘)[2𝐹(𝑘 + 1) − 𝐹(𝑘)] 𝐹(2𝑘 + 1) = 𝐹(𝑘 + 1)2 + 𝐹(𝑘)2
  • 4. 證明-矩陣表示式  以數學歸納法證明: 1 𝑛 = 1; 1 1 1 0 1 = 𝐹(2) 𝐹(1) 𝐹(1) 𝐹(0) 2 設 1 1 1 0 𝑛 = 𝐹(𝑛 + 1) 𝐹(𝑛) 𝐹 𝑛 𝐹(𝑛 − 1) 成立 ⇒ 1 1 1 0 𝑛+1 = 𝐹(𝑛 + 1) 𝐹(𝑛) 𝐹 𝑛 𝐹(𝑛 − 1) 1 1 1 0 = 𝐹 𝑛 + 1 + 𝐹 𝑛 𝐹 𝑛 + 1 𝐹 𝑛 + 𝐹 𝑛 − 1 𝐹 𝑛 = 𝐹 𝑛 + 2 𝐹 𝑛 + 1 𝐹 𝑛 + 1 𝐹 𝑛
  • 5. 證明-fast doubling 由矩陣表示式可知 𝐹 2𝑛 + 1 𝐹 2𝑛 𝐹 2𝑛 𝐹 2𝑛 − 1 = 1 1 1 0 2𝑛 = 1 1 1 0 𝑛 2 = 𝐹(𝑛 + 1) 𝐹(𝑛) 𝐹 𝑛 𝐹(𝑛 − 1) 2 = 𝐹(𝑛 + 1)2 + 𝐹(𝑛)2 𝐹(𝑛 + 1)𝐹(𝑛) + 𝐹(𝑛)𝐹(𝑛 − 1) 𝐹(𝑛)𝐹(𝑛 + 1) + 𝐹(𝑛 − 1)𝐹(𝑛) 𝐹(𝑛)2 + 𝐹(𝑛 − 1)2 比較前後式可得: 1 𝐹 2𝑛 + 1 = 𝐹(𝑛 + 1)2 + 𝐹(𝑛)2 2 𝐹 2𝑛 = 𝐹 𝑛 𝐹 𝑛 + 1 + 𝐹 𝑛 − 1 = 𝐹 𝑛 𝐹 𝑛 + 1 + 𝐹 𝑛 + 1 − 𝐹 𝑛 = 𝐹(𝑛)[2𝐹(𝑛 + 1) − 𝐹(𝑛)]
  • 6. 演算法 Fast_Fib(n) a = 0; b = 1; //m=0 for i = (number of binary digit in n) to 1 t1 = a*(2*b-a); t2 = b^2 + a^2; a = t1; b = t2; //m*=2 if(current binary digit == 1) t1=a+b; //m++ a = b; b = t1; return a;
  • 7. 例: n = 10 = 10102 i start 4 3 2 1 result n 1010 ^ 1010 ^ 1010 ^ 1010 ^ F(m) F(0) F(0*2+1) F(1*2) F(2*2+1) F(5*2) F(10) a 0 1 1 5 55 55 b 1 1 2 8 89
  • 8. Assembly實作  省略 F(0),從F(1)開始  clz:計算leading zeros以求位數  cbz:if(Ra==0) goto label  利用rsb (reverse subtract) + barrel shifter
  • 9.
  • 10. 參考資料  ARM instruction quick reference -- http://users.ece.utexas.edu/~valvano/Volume1/QuickRefe renceCard.pdf  Project Nayuki : Fast Fibonacci algorithms -- http://www.nayuki.io/page/fast-fibonacci-algorithms  Wiki : Fibonacci number -- https://en.wikipedia.org/wiki/Fibonacci_number  The first 300 Fibonacci numbers -- http://www.maths.surrey.ac.uk/hosted- sites/R.Knott/Fibonacci/fibtable.html