Classic Editor

If WordPress keeps opening the block editor instead of the Classic Editor, simply add

&classic-editor

to any edit URL such as

post.php?post=123&action=edit&classic-editor

and hit Enter to instantly open the Classic Editor.

— Me@2025-12-06 07:59:41 AM

.

.

2025.12.06 Saturday (c) All rights reserved by ACHK

Posted in CSS

Euler problem 28.2

e28a :: Integer
e28a = 1 + sum [4*(n-2)^2 + 10*(n-1)
               | n <- [3, 5 .. 1001]]


e28b :: Integer
e28b = let n = 500
           sumSquares = n*(n+1)*(2*n+1) `div` 6
           sumLinear = n*(n+1) `div` 2
       in 16*sumSquares + 4*sumLinear + 4*n + 1
λ> :set +s
λ> e28a
669171001
(0.00 secs, 617,688 bytes)

λ> e28b
669171001
(0.00 secs, 82,400 bytes)
λ> 

— Me@2025-11-17 12:00:22 AM

.

.

2025.11.17 Monday (c) All rights reserved by ACHK

Euler problem 28.1

(defun e-28 ()
  (+ 1 (loop :for n :from 3 :to 1001 :by 2
             :sum (+ (* 4 (expt (- n 2) 2))
                     (* 10 (- n 1))))))

CL-USER> (e-28)
669171001

— Me@2025-06-13 11:01:45 PM

.

.

2025.06.15 Sunday (c) All rights reserved by ACHK

Ex 1.33 Properties of E

Understanding the Euler-Lagrange Operator

.

Let \displaystyle{F} and \displaystyle{G} be two Lagrangian-like functions of a local tuple, \displaystyle{C} be a local-tuple transformation function, and \displaystyle{c} a constant.

Demonstrate the following properties:

a. \displaystyle{E[F + G] = E[F] + E[G]}

d. \displaystyle{\mathcal{E}[F \circ C] = D_t (DF \circ C) \partial_2 C + DF \circ C \mathcal{E}[C]}

~~~

Eq. (1.167):

\displaystyle{\bar \Gamma (\bar f) (t, q, v, \dots) = \bar f [\mathcal{O} (t,q,v, \dots)](t)}

Eq. (1.174):

\displaystyle{E[L] = D_t \partial_2 L - \partial_1 L}

.

\displaystyle{  \begin{aligned}  E[L] &= D_t \partial_2 L - \partial_1 L \\   E[F+G] &= D_t \left( \partial_2 (F+G) \right) - \partial_1 (F+G) \\   &= D_t \left( \partial_2 F+\partial_2 G \right) - (\partial_1 F+ \partial_1 G) \\   &= D_t \partial_2 F+D_t \partial_2 G - (\partial_1 F+ \partial_1 G) \\  &= D_t \partial_2 F- \partial_1 F +D_t \partial_2 G - \partial_1 G \\   &= E[F] + E[G] \\  \end{aligned}  }

— Me@2025-05-30 03:40:41 PM

.

The Problem

\displaystyle{  \begin{aligned}  &E[F \circ C] (t,q,v,\dots) \\   &= (D_t \partial_2 (F \circ C) - \partial_1 (F \circ C)) (t,q,v,\dots)\\     &= (D_t \partial_2 (F (C(t,q,v,\dots))) - \partial_1 (F(C(t,q,v,\dots)))) \\     \end{aligned}  }

Prove that

\displaystyle{\mathcal{E}[F \circ C] = D_t (DF \circ C) \partial_2 C + DF \circ C \mathcal{E}[C]}


Key Terms Explained

  • Local Tuple: Think of this as a snapshot of a system’s state along a path. It includes:
    • \displaystyle{ t }: time,
    • \displaystyle{ q }: generalized coordinate (e.g., position),
    • \displaystyle{ v = \frac{dq}{dt} }: velocity,
    • and possibly higher derivatives like acceleration. We’ll use \displaystyle{ \eta = (t, q, v) } for simplicity.
  • Lagrangian-like Function \displaystyle{ F }: A scalar function of the local tuple, such as \displaystyle{ F(t, q, v) }, akin to a Lagrangian in mechanics.
  • Local-Tuple Transformation \displaystyle{ C }: A function that maps one local tuple to another. For example, \displaystyle{ C(\eta) = (t, C_q(t, q, v), C_v(t, q, v)) }, where \displaystyle{ C_q } and \displaystyle{ C_v } transform the coordinate and velocity.
  • Composition \displaystyle{ F \circ C }: This is \displaystyle{ F } evaluated at the transformed tuple: \displaystyle{ (F \circ C)(\eta) = F(t, C_q(t, q, v), C_v(t, q, v)) }.
  • Euler-Lagrange Operator \displaystyle{ E }: For a function \displaystyle{ G(t, q, v) }, it’s defined as:
    \displaystyle{ E[G] = \frac{\partial G}{\partial q} - D_t \left( \frac{\partial G}{\partial v} \right) }
    This operator extracts the equations of motion when applied to a Lagrangian.
  • Total Time Derivative \displaystyle{ D_t }: This accounts for how a function changes over time, considering all variables. For \displaystyle{ h(t, q, v) }:
    \displaystyle{ D_t h = \frac{\partial h}{\partial t} + v \frac{\partial h}{\partial q} + a \frac{\partial h}{\partial v} }
    where \displaystyle{ a = \frac{dv}{dt} } is acceleration.
  • Derivative \displaystyle{ DF }: The derivative of \displaystyle{ F } with respect to its spatial arguments, typically \displaystyle{ DF = \left( \frac{\partial F}{\partial q}, \frac{\partial F}{\partial v} \right) }.

— Me@2025-05-31 01:32:05 PM

.

.

2025.06.03 Tuesday (c) All rights reserved by ACHK

xrandr, 2

xrandr -q

xrandr --output DisplayPort-3 --auto --primary --output HDMI-A-4 --auto --left-of DisplayPort-3

xrandr --output DisplayPort-3 --auto --primary --output HDMI-A-4 --off

— Me@2025-04-20 02:19:35 PM

.

.

2025.04.20 Sunday (c) All rights reserved by ACHK

Euler problem 27.2.2

p_27 = -(2 * a - 1) * (a ^ 2 - a + 41)
  where
    n = 1000
    m = head $ filter (\x -> x ^ 2 - x + 41 > n) [1 ..]
    a = m - 1

Euler Problem 27 asks us to find a quadratic equation of the form (n^2 + a \cdot n + b) that generates the most consecutive prime numbers starting from n = 0, with the constraints |a| < 1000 and |b| \leq 1000. The final answer is the product a \cdot b for the winning pair. The “official” Haskell solution looks cryptic, but there’s a clever trick behind it. Let’s break it down step-by-step in a way that’s easier to follow.

A Handy Math Trick: Shifting the Quadratic

Imagine we tweak our quadratic (n^2 + a \cdot n + b) by replacing n with n - x. When we expand it out, we get:

(n - x)^2 + a(n - x) + b = n^2 + (a - 2x)n + (x^2 - ax + b)

This is still a quadratic in n, but now the coefficients are:

  • a_{\text{new}} = a - 2x
  • b_{\text{new}} = x^2 - ax + b

By choosing the right x, we can transform any quadratic into a simpler form, like n^2 + d or n^2 + n + d. This is our starting point.

Which Form Works Best?

  • Form 1: n^2 + d
    This one’s a dud. Plug in n = 0, 1, 2, 3, and you’ll see every other number is even (e.g., d, d+1, d+4, d+9). With so many evens, it can’t produce a long run of primes—primes are mostly odd (except 2).
  • Form 2: n^2 + n + d
    This is more promising. A mathematician named Rabinowitz proved that for this form to generate the longest sequence of primes, 4d - 1 must be a special number called a Heegner number. There are only six possibilities, and after testing, n^2 + n + 41 comes out on top. It spits out 40 primes from n = 0 to n = 39. The runner-up, n^2 + n + 17, doesn’t do as well.

So, n^2 + n + 41 is our golden ticket. But there’s more to it.

The Symmetry Bonus

Here’s a cool trick with n^2 + n + 41:

(-1 - n)^2 + (-1 - n) + 41 = n^2 + n + 41

This means if n = 2 gives a prime (like 47), then n = -3 (i.e., -1 - 2) does too (also 47). The sequence works both ways—positive and negative n. Starting at n = 0, we get 40 primes up to n = 39, but we can also count backward with negative n. Our goal is to shift this quadratic so we capture more of these primes from n = 0 onward, while keeping a and b within the problem’s limits.

Fitting It Into the Rules

Let’s start with n^2 + n + 41 (where a = 1, b = 41) and shift it using our trick:

  • New quadratic: n^2 + (1 - 2x)n + (x^2 - x + 41)
  • New a = 1 - 2x
  • New b = x^2 - x + 41

The problem says |a| < 1000 and |b| \leq 1000, so:

  • |1 - 2x| < 1000
  • |x^2 - x + 41| \leq 1000

The second condition is trickier because x^2 grows fast. We need the biggest x where x^2 - x + 41 \leq 1000.

Crunching the Numbers

Let’s test some x values:

  • x = 31: 31^2 - 31 + 41 = 961 - 31 + 41 = 971 (under 1000)
  • x = 32: 32^2 - 32 + 41 = 1024 - 32 + 41 = 1033 (over 1000)

So, x = 31 is the largest value that works. Now calculate:

  • a = 1 - 2 \cdot 31 = 1 - 62 = -61
  • b = 971 (from above)

Check the constraints:

  • |a| = |-61| = 61 < 1000
  • |b| = 971 \leq 1000

The Haskell Code Explained

That’s where this funky code comes in:

n = 1000
m = head $ filter (\x -> x ^ 2 - x + 41 > n) [1 ..]
a = m - 1

It finds m = 32 (first x where x^2 - x + 41 > 1000). Then x = m - 1 = 31.

The final line:

p_27 = -(2 * a - 1) * (a ^ 2 - a + 41)

This is a bit off. It uses a = 31, but we need a = 1 - 2x = -61. The correct product should be:

  • a = -61
  • b = 971
  • a \cdot b = -61 \cdot 971 = -59231

The code’s formula seems to be a typo or a leftover from a different derivation. It should just compute (1 - 2x) \cdot (x^2 - x + 41).

Why It Works

With a = -61, b = 971, the quadratic n^2 - 61n + 971 generates 71 primes from n = 0 to n = 70. This shift captures more of the n^2 + n + 41 sequence’s primes in the positive direction, thanks to the negative a. The product -59231 is the answer.

Wrapping Up

This solution is sneaky—it starts with a prime-generating champ, shifts it just right, and fits the problem’s rules. It’s not the brute-force way (testing every a and b), but a math shortcut that lands on the perfect answer. Pretty cool, right?

— Me@2025-03-24 12:25:20 PM

.

.

2025.03.30 Sunday (c) All rights reserved by ACHK

LISP, Y Combinator, and the Fixed Point of Startup Innovation

According to Harold Abelson, one of the authors of “Structure and Interpretation of Computer Programs” (SICP), LISP can be seen as the fixed point of the process of defining a programming language, where the language itself can be used to define itself. This concept is analogous to the Y combinator in lambda calculus, which finds the fixed point of a function.

Drawing from this analogy, if LISP is considered the fixed point of the process of defining a programming language:

    • Paul Graham’s Y Combinator (the company) could be seen as the fixed point of the process of startup creation and growth. Here’s how:
      • Startup Ecosystem: Just as LISP recursively defines its own structure and operations, Y Combinator as a company recursively supports, nurtures, and grows startups. Each startup that Y Combinator backs can be seen as an iteration or instance of this process, much like how LISP functions or programs are instances of the language’s self-definition.
      • Self-Replication: Similar to how the Y combinator in lambda calculus allows functions to call themselves without explicit recursion, Y Combinator as a business model “replicates” itself through each cohort of startups it invests in. Each startup, in turn, might use the methodologies, culture, and network provided by Y Combinator to further innovate or even spawn more startups.
      • Cultural and Intellectual Capital: Y Combinator also serves as a hub for knowledge transfer, where the “fixed point” isn’t just the company but the collective wisdom, culture, and network that grows with each new company. This knowledge and network then feed back into the system, enhancing future iterations.

Therefore, according to the conceptual framework laid out by the authors of SICP, Paul Graham’s Y Combinator could be seen as the fixed point of the entrepreneurial process, where the methodology, culture, and success of one startup generation informs and shapes the next, creating a self-sustaining cycle of innovation and growth. This interpretation is not explicitly stated by Abelson or Sussman but is a logical extension of their ideas applied to business and innovation ecosystems.

— Me@2024-12-30 07:37:41 PM

.

.

2025.03.14 Friday (c) All rights reserved by ACHK

Euler problem 27.1

(defparameter *primes-up-to-1000*
  (let ((sieve (make-array 1001
                           :element-type 'bit
                           :initial-element 0)))
    (loop for i from 2 to 1000
          when (zerop (sbit sieve i))
            do (loop for j from (* i i) to 1000 by i
                     do (setf (sbit sieve j) 1)))
    (loop for i from 2 to 1000
          when (zerop (sbit sieve i))
            collect i)))

(defun primep (n)
  (cond ((<= n 1) nil)
        ((<= n 1000) (member n *primes-up-to-1000*))
        (t (loop for p in *primes-up-to-1000*
                 while (<= (* p p) n)
                 never (zerop (mod n p))))))

(defun prime-sequence-length (a b)
  (loop for n from 0
        while (primep (+ (* n n) (* a n) b))
        count t))

(defun find-best-quadratic-coefficients
    (&optional (max-a 1000) (max-b 1000))
  (loop with best-length = 0
        with best-a = 0
        with best-b = 0
        for a from (- max-a) to max-a
        do (loop for b in *primes-up-to-1000*
                 when (> b max-b) do (loop-finish)
                   do (let ((len (prime-sequence-length
                                  a
                                  b)))
                        (when (> len best-length)
                          (setf best-length len
                                best-a a
                                best-b b))))
        finally (return (list best-length
                              best-a best-b))))

(defun euler-27 ()
  (destructuring-bind (len a b)
      (find-best-quadratic-coefficients)
    (format t
            "Sequence length: ~d, a: ~d, b: ~d~%"
            len a b)
    (* a b)))

(defun main ()
  (time (format t "Answer: ~d~%" (euler-27))))

; SLIME 2.28
CL-USER> (main)
Sequence length: 71, a: -61, b: 971
Answer: -59231
Evaluation took:
  0.103 seconds of real time
  0.103747 seconds of total run time (0.103637 user, 0.000110 system)
  100.97% CPU
  258,919,169 processor cycles
  0 bytes consed
  
NIL
CL-USER> 

— Me@2025-02-23 03:48:23 PM

.

.

2025.02.23 Sunday (c) All rights reserved by ACHK

Ex 1.32 Path functions and state functions, 2.4

Structure and Interpretation of Classical Mechanics

.

2. On the other hand, the path function \bar f[q] and the path function \bar \Gamma (\bar f) \circ \Gamma [q] are not necessarily the same. Explain.

4. Write programs to illustrate the behavior.

~~~

(pp Gamma)

(define ((f-bar q) t)
  (f ((Gamma q) t)))
 
(define ((Gamma-bar h-bar) local)
  ((h-bar (osculating-path local)) (time local)))

(define (q t)
  (sin t))

(define (f-bar q)
  (D q))

(define p
  (literal-function 'q))

(show-expression
 ((f-bar p) 't))

Dq(t)

(show-expression
 ((osculating-path ((Gamma p) 't_0)) 't))

q(t_0) + (t - t_0)Dq(t_0)

(show-expression
 ((Gamma-bar f-bar) ((Gamma p) 't)))

Dq(t)

(define ((GammaBar-fBar-o-Gamma f-bar) q)
  (compose (Gamma-bar f-bar) (Gamma q)))

(show-expression
 (((GammaBar-fBar-o-Gamma f-bar) p) 't))

Two paths that have the same local description up to the n-th derivative are said to osculate with order-n contact. For example, a path and the truncated power series representation of the path up to order n have order-n contact; if fewer than n derivatives are needed by a local-tuple function, the path and the truncated power series representation are equivalent.

(define (g-bar q)
  ((expt D 3) q))

(show-expression
 ((Gamma p) 't))

\left(  \begin{array}{c}  t \\  q(t) \\  Dq(t)  \end{array}  \right)

(show-expression
 ((g-bar p) 't))

((D^3 q)(t))

(show-expression
 ((osculating-path ((Gamma p) 't_0)) 't))

q(t_0) + (t - t_0)Dq(t_0)

(show-expression
 (((GammaBar-fBar-o-Gamma g-bar) p) 't))

0

— Me@2024-10-16 10:34:35 AM

.

.

2025.02.16 Sunday (c) All rights reserved by ACHK

Lisp as a Y combinator

Lisp = Process(Lisp), 1.3

.

YCombinator = a fixed point of
Lisp = Process(Lisp)

So

Lisp = Y(Process)

— Me@2025-01-09 01:09:57 PM

.

Actually, it is

Lisp_n = Process(Lisp_(n-1))

— Me@2024-12-30 10:43:36 AM

.

.

2025.02.13 Thursday (c) All rights reserved by ACHK

Euler problem 26.2.2

import Data.List (elemIndex, maximumBy) 
import Data.Ord (comparing)
import Data.Maybe (fromJust)

recurringCycle :: Int -> Int
recurringCycle d = remainders 1 []
  where
    remainders r rs
      | r == 0          = 0
      | s `elem` rs     = 1 + fromJust (elemIndex s rs)
      | otherwise       = remainders ((r * 10) `mod` d) (s : rs)
      where s = r `mod` d

p26 :: Int
p26 = fst $ maximumBy (comparing snd) [(n, recurringCycle n) | n <- [1,3..999], n `mod` 5 /= 0]

λ> :set +s
λ> p26
983
(0.11 secs, 29,770,480 bytes)
λ> 

— Me@2025-02-06 08:29:54 AM

.

.

2025.02.06 Thursday (c) All rights reserved by ACHK

Euler problem 26.1

(defun recurring-cycle (d)
  "Calculate the length of the recurring cycle for 1/d."
  (labels ((remainders (d r rs)
             (if (eql r 0)
                 0               
                 (let ((s (mod r d)))
                   (if (member s rs)
                       (1+ (position s rs))
                       (remainders d (* 10 s) (cons s rs)))))))
    (remainders d 1 nil)))

(defun p26 ()
  "Find the number below 1000 with the longest recurring cycle in its decimal representation."
  (let* ((results (loop :for n :from 1 :to 999 
                        collect (cons n (recurring-cycle n))))
         (max-pair (reduce #'(lambda (a b)
                               (if (> (cdr a) (cdr b))
                                   a
                                   b))
                           results)))
    (car max-pair)))

; SLIME 2.28
CL-USER> (p26)
983
CL-USER> 

— Me@2025-01-20 03:57:23 PM

.

.

2025.01.20 Monday (c) All rights reserved by ACHK

Lisp = Process(Lisp), 1.2

Lisp as a Y combinator

.

This concept ties into:

  • Metacircular Evaluators: In SICP, they introduce the concept of a metacircular evaluator, which is an interpreter for Lisp written in Lisp itself. This is a direct example of “Lisp = Process(Lisp)”, where the “Process” is the act of interpretation or implementation.

Sussman’s statement is both a philosophical and practical insight into the nature of Lisp, highlighting its self-referential capabilities and the elegance of its design in terms of theoretical computer science concepts like fixed points.

— Me@2024-12-30 10:45:35 AM

.

.

2025.01.17 Friday (c) All rights reserved by ACHK

Euler problem 25.3

showtime : false$
t0 : elapsed_real_time()$

t: 10^999$

j : 1$
while fib(j) < t do (
    j: j + 1
)$

j;

t1: elapsed_real_time()$

time_taken: t1-t0$

print("Time taken:", float(time_taken), "seconds");

4782

"Time taken:"0.4299999999999997"seconds"

— Me@2025-01-13 08:11:23 AM

.

.

2025.01.13 Monday (c) All rights reserved by ACHK

Ex 1.32 Path functions and state functions, 2.3

Structure and Interpretation of Classical Mechanics

.

2. On the other hand, the path function \bar f[q] and the path function \bar \Gamma (\bar f) \circ \Gamma [q] are not necessarily the same. Explain.

3. Give examples where they are the same and where they are not the same.

~~~

In other words, path q^{(m)} = 0 for all m>n. Or put it simply, q(t) is a polynomial.

.

The second case is when the path function \bar f [q] requires no derivatives of q with order higher than n. For example:

Assume that the path is \displaystyle{q = \sin(t)}, the osculating path is

\displaystyle{\begin{aligned}     &\mathcal{O} (t_0, q(t_0), v(t_0), a(t_0)))(t) \\     &= q_0 + v_0 (t-t_0) + \frac{1}{2} a_0 (t-t_0)^2 \\        \end{aligned}}

and \displaystyle{\bar f [q] = Dq}.

Then \displaystyle{\bar f [q](t = t_0) = \cos (t_0)}; and

\displaystyle{\begin{aligned}    & \left. \bar \Gamma (\bar f) \circ \Gamma [q] \right|_{t_0} \\  &= \left. \bar \Gamma (\bar f) \circ \Gamma[\mathcal{O} (t,q,v,a)](t)\right|_{t_0} \\  &= \left. \bar \Gamma (\bar f) (t, q, v, a)\right|_{t_0} \\  &= \left[ v_0 + a_0 (t-t_0) \right]_{t_0} \\  &= \cos (t_0) \\   \end{aligned}}

.

\displaystyle{\mathcal{O} (t,q,v, \cdots, q^{(n)})} == a taylor series with finite length

.

However, if a path function \bar g requires a higher derivative which is not provided by \Gamma:

\displaystyle{q = \sin(t)}

\displaystyle{\begin{aligned}     &\mathcal{O} (t_0, q(t_0), v(t_0), a(t_0)))(t) \\     &= q_0 + v_0 (t-t_0) + \frac{1}{2} a_0 (t-t_0)^2 \\     &= \sin t_0 + ( \cos t_0 ) (t-t_0) - \frac{1}{2} \sin t_0 (t-t_0)^2 \\        \end{aligned}}

\displaystyle{\bar g [q] = D^3q},

then \displaystyle{\bar g [q](t = t_0) = - \cos (t_0)}; and

\displaystyle{\begin{aligned}    & \left. \bar \Gamma (\bar g) \circ \Gamma [q] \right|_{t_0} \\  &= \left. \bar \Gamma (\bar g) \circ \Gamma[\mathcal{O} (t,q,v,a)](t)\right|_{t_0} \\  &= \left. \bar \Gamma (\bar g) (t, q, v, a)\right|_{t_0} \\  &= \left[ 0 \right]_{t_0} \\  &= 0 \\   \end{aligned}}

— Me@2025-01-12 06:43:55 AM

.

.

2025.01.12 Sunday (c) All rights reserved by ACHK

Lisp = Process(Lisp)

Lisp as a Y combinator

.

Lisp is the fixed point of the process which says, if I know what Lisp was and substituted it in for eval and apply and so on, on the right-hand sides of all those recursion equations, then if it was a real good Lisp, is a real one then the left-hand side would also be Lisp.

— Gerald Jay Sussman

.

Process: This refers to the act of defining or implementing Lisp. Specifically, it’s about defining Lisp’s core functions like eval and apply which are crucial for interpreting and executing Lisp code.

— Me@2024-12-30 10:45:35 AM

.

.

2025.01.10 Friday (c) All rights reserved by ACHK

Euler problem 25.2.2

import System.CPUTime
import Text.Printf (printf)
import Data.List (findIndex)

time :: (Show a) => a -> IO a
time result = do
    start <- getCPUTime
    let computed = result
    end <- computed `seq` getCPUTime
    let diff = (fromIntegral (end - start)::Float)/(10^12)
    printf "Result: %s\n Time taken: %.6f seconds\n" (show computed) diff
    return computed
    
matrixMultiply :: Num a => [(a, a)] -> [(a, a)] -> [(a, a)]
matrixMultiply [(a11, a12), (a21, a22)] [(b11, b12), (b21, b22)] =
  [ (a11*b11 + a12*b21, a11*b12 + a12*b22)
  , (a21*b11 + a22*b21, a21*b12 + a22*b22) ]
 
matrixPower :: Num a => [(a, a)] -> Int -> [(a, a)]
matrixPower m 1 = m
matrixPower m n =
  let half = matrixPower m (n `div` 2)
      squared = matrixMultiply half half
  in if odd n then matrixMultiply squared m else squared
 
digitsInNumber :: (Show a, Integral a) => a -> Int
digitsInNumber = length . show
 
fibNth :: Integral a => a -> a
fibNth n 
  | n <= 2    = 1
  | otherwise = fst $ head $ matrixPower [(1, 1), (1, 0)] (fromIntegral (n - 1))
 
fibUpperBound :: Int -> Integer
fibUpperBound digitCount =
  let phi = 1.618033988749895
      logPhi = logBase 10 phi
      log5 = logBase 10 5
  in ceiling $ (fromIntegral digitCount - 1 + (log5 / 2)) / logPhi
 
binarySearchFibIndex :: Int -> Maybe Integer
binarySearchFibIndex digitCount =
  let upperBound = fibUpperBound digitCount
      binarySearch left right 
        | left > right = Nothing
        | otherwise =
            let mid = left + (right - left) `div` 2
                midFib = fibNth mid
                midDigits = digitsInNumber midFib
            in case compare midDigits digitCount of
                 EQ ->
                   let prevDigits = digitsInNumber $ fibNth (mid - 1)
                   in if prevDigits < digitCount then Just mid else binarySearch left (mid - 1)
                 LT -> binarySearch (mid + 1) right
                 GT -> binarySearch left (mid - 1)
  in binarySearch 1 upperBound

λ> time $ binarySearchFibIndex 1000
Result: Just 4782
 Time taken: 0.000852 seconds
Just 4782
λ> 
λ> time $ binarySearchFibIndex 1000
Result: Just 4782
 Time taken: 0.006747 seconds
Just 4782
λ> 

— Me@2024-12-25 07:00:13 AM

.

.

2025.01.01 Wednesday (c) All rights reserved by ACHK

Problem 14.5d1.2.3

A First Course in String Theory

.

The generating function is an infinite product:

\displaystyle{ \begin{aligned} \alpha' M_L^2: \end{aligned}}

\displaystyle{\begin{aligned} &f_{L, NS+}(x) \\ &= a_{NS+} (r) x^r \\ &= \frac{1}{x} \prod_{r=1}^\infty \frac{(1 + x^{r-\frac{1}{2}})^{32}}{(1 - x^r)^8} \\ \end{aligned}}

.

To evaluate the infinite product, you can use wxMaxima. However, it does not provide \LaTeX rendering of answers yet. Instead, you can call Maxima‘s code in SageMath, if you use Jupyter Notebook to access SageMath.

reset()

%display latex

maxima('taylor((1/x)*product((1 + x^(r - 1/2))^32 / (1 - x^r)^8, r, 1, oo), x, 0, 6)')

\displaystyle {{1}\over{x}}+{{32}\over{\sqrt{x}}}+504+5248\,\sqrt{x}+40996\,x+  258624\,x^{{{3}\over{2}}}+1384320\,x^2+6512384\,x^{{{5}\over{2}}}+  27623826\,x^3+107640288\,x^{{{7}\over{2}}}+390667136\,x^4+1334500992  \,x^{{{9}\over{2}}}+4325559288\,x^5+13390178752\,x^{{{11}\over{2}}}+  39794729472\,x^6+\cdots

— Me@2024-12-02 06:33:46 AM

.

.

2024.12.31 Tuesday (c) All rights reserved by ACHK