How To Calculate Fibonacci Extensions using Lisp?

by lucas.hilpert , in category: Technical Analysis , 4 months ago

How To Calculate Fibonacci Extensions using Lisp?

Facebook Twitter LinkedIn Whatsapp

2 answers

by norberto_waelchi , 4 months ago

@lucas.hilpert 

To calculate Fibonacci extensions in Lisp, you can use the following code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
(defun fibonacci (n)
  (cond
    ((= n 0) 0)
    ((= n 1) 1)
    (t (+ (fibonacci (- n 1)) (fibonacci (- n 2))))
  ))

(defun fibonacci-extensions (n)
  (let* ((fib-n (fibonacci n))
         (fib-n-1 (fibonacci (- n 1)))
         (fib-n-2 (fibonacci (- n 2)))
         (fib-extensions (+ fib-n fib-n-1 fib-n-2))
         (extension-n-127 (/ (* 127 fib-extensions) 100)))
    (list fib-n fib-n-1 fib-n-2 extension-n-127)
  ))

; Calculate Fibonacci extensions for n=10
(fibonacci-extensions 10)


In this code, the fibonacci function calculates the n-th Fibonacci number recursively. The fibonacci-extensions function then calculates the Fibonacci extensions for a given Fibonacci number n by adding the n-th, (n-1)-th, and (n-2)-th Fibonacci numbers, and then multiplying the sum by 127 and dividing by 100.


You can call the fibonacci-extensions function with the desired Fibonacci number n to calculate its extensions.

by ray.hilll , 2 months ago

@lucas.hilpert 

Here is an example of how you can use the code provided to calculate Fibonacci extensions in Lisp:

  1. Copy and paste the code snippet provided into your Lisp environment or editor.
  2. Evaluate the code.
  3. To calculate Fibonacci extensions for a specific value of n, call the fibonacci-extensions function and pass the desired Fibonacci number as an argument. For example, to calculate Fibonacci extensions for n = 10, you can evaluate (fibonacci-extensions 10).
  4. The function will return a list containing the n-th, (n-1)-th, and (n-2)-th Fibonacci numbers, as well as the Fibonacci extension calculated using the formula provided in the code.
  5. You can modify the code or experiment with different values of n to calculate Fibonacci extensions for other Fibonacci numbers.


Feel free to ask if you have any questions or need further clarification on how to use the code to calculate Fibonacci extensions in Lisp.