真話騙子 2.2

這段改編自 2021 年 12 月 17 日的對話。

.

……

現在集中討論第一點:

即使是所謂的「善意」的假話或隱瞞,也應盡量避免講,因為結果為何,不是你或者任何人,可以控制到。

審判過程中翁靜晶丈夫劉家良在書面口供表示,兩夫婦曾因翁靜晶與林競業的緋聞陷入離婚邊緣,而且翁靜晶為了避免事情鬧大,阻延報警求救最少二十分鐘。靜晶則供稱當日劉家良突然到訪寓所,當時在翁寓所內的林競業為避免遭到劉誤會他與翁偷情,主動爬出窗外,卻失足飛墮平台。

— 維基百科

不必要的隱瞞,後果可以那麼嚴重。

.

那個處境的正確做法是:

1. 其實應該在事先,就避免那個情境的發生——不是情侶的異性,就不要獨處。瓜田李下也。

2. 如果是必須,例如工作需要的話,二人也應該各自,事先通知自己的另一半。

3. 如果不幸地,沒有跟隨這兩個要點,導致遇到例子中情形的話,就要如實反映。講了實話後,別人信不信,並不是重點。

即使伴侶不信任,而導致離婚,也已是兩害取其輕。

— Me@2024-12-18 10:56:12 AM

.

.

2025.01.15 Wednesday (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

Panjandrum

大架子

.

On the day when the Nobel Prize was announced, Louise gave me some very wise advice: “Now you have to write some unimportant papers.” I knew what she meant.

Even when scientists who receive the Nobel Prize resist the temptation to become panjandrums like Heisenberg, by issuing judgments about what others should be doing, there is a tendency for laureates to feel that one should stop doing the ordinary hard work of science, and instead go only for the next Big Thing.

I take pride in the fact that I have continued working hard on minor problems and have written a large number—literally hundreds—of unimportant papers, both before and after the Nobel Prize. Whatever other physicists may have learned from these papers, I have learned a lot. And at least I have escaped panjandrum-itis.

— Steven Weinberg: A Life in Physics

.

.

2025.01.09 Thursday (c) All rights reserved by ACHK

Where are you? 2.7

Utopia | 何有之鄉, 2.7

.

不可能遷就到,而為了保命,必須立刻超光速逃離,或者𣊬間轉移的例子有:

……

五、 不可信:

……

大漏洞是,要永久不被發現,你的心神就要,永久經營那些大話,心情永久不能放鬆。

記住,維持誠信有如保持健康,主要是為了自己而做的;他人知不知道,沒有關係。

以下是例外情形,可能有必要講假話。

1. 有時,講真話會危害性命,你就嘗試不答話。仍然不行的話,為了保護自己或他人的人身安全,唯有說假話。

2. 有些近似謊言,會立刻極速自我實現,就叫「自證預言」。如果對人對己極為有利,「自證預言」可以說。

例如,如果有位正常智力的學生問你,他夠不夠聰明,應付公開考試。只要你大力宣稱他夠聰明,而他又相信的話,他就自然會有心機,用心溫習。他在公開試奪取佳績的機會,就會大大提升,應驗了你「他夠聰明」的宣稱。

留意,如果自我實現不是立刻極速,那就有違道義,不可算是「自證預言」。

其他情形下,謊言假話,幾乎一概不可接受。

……

— Me@2024-09-05 03:33:08 PM

.

.

2025.01.07 Tuesday (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

Why Yg = g(Yg) Enables Recursion, 2

In essence, Yg = g(Yg) allows for recursion by providing a mechanism where a function can reference itself through another function’s application, without needing to explicitly name itself, thus bypassing the need for direct recursion support in the language. This approach is particularly useful in theoretical computer science, lambda calculus, and in functional programming languages or environments where direct recursion might be restricted or not available.

— Based on Grok 2

— Edited by Me@2024-12-19 11:26:25 AM

.

.

2024.12.30 Monday (c) All rights reserved by ACHK

好為人師 3.2

這段改編自 2023 年 6 月 23 日的對話。

.

…… 原因是,雙方也會出於禮貌,即使在不同意對方時,也不會直斥其非、議事論事。既然不是開心見誠,無所顧忌,而是有所隱瞞,那就會導致誤會,日久累積加深。這情況在本人身上,發生不少次。有時是與學生反面,有時則是和教授,不相往來。

例子一:

我在大學做研究助理時,有次遇到一位舊生甲。他在中學時,我有教過他。我們在校內餐廳,傾談了一個小時多,十分投契。他鄉遇故知,格外開心。

不料,不久之後,甲跟他的舊同學,講了一些批評我的說話。批評本身不是問題。但是甲的批評方法,有兩大問題:

一、為何不當面提及?(因為我是師輩,當面批評,可能有失禮貌。)

當面提及的話,大家可以討論和爭拗,從而誤會最小化。

二、甲想像了一些從沒發生,甚至與實情相反的事件;又引述了一些,我從來未說過的話,或者我從來未有過的立場。當面提及的話,我可以當面釐清。又或者,我其實真的有失言,只是忘記了;他又可以立刻指正之。

我不介意被誤會,但介意因為被騙,誤以為對方想跟我聊天,而導致浪費了,一個小時多。

再後來,他邀請我參加他的婚宴時,我婉拒了,因為我不好意思去。我不知道,他真的想見我,還是客氣而已。

— Me@2024-12-28 07:02:54 PM

.

.

2024.12.28 Saturday (c) All rights reserved by ACHK

Euler problem 25.2.1

import System.CPUTime
import Text.Printf (printf)

-- | Times the execution of a pure function and prints the result.
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

fibs :: [Integer]
fibs = 0:1:zipWith (+) fibs (tail fibs)

t :: Integer
t = 10^999
 
p25 :: Int
p25 = length w
    where
      w = takeWhile (< t) fibs

λ> time p25
Result: 4782
 Time taken: 0.000496 seconds
4782
λ> 
λ> time p25
Result: 4782
 Time taken: 0.002918 seconds
4782
λ> 

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

.

.

2024.12.26 Thursday (c) All rights reserved by ACHK

SageMath for Ubuntu 24.04

0. In this tutorial, you will need to go to the official website of NixOS. Make sure that its website is the real, official one. Any instructions from an imposter website can get your machine infected with malware.

1. Assuming your computer’s OS is Ubuntu 24.04 or above, go to the NixOS official website. Follow the instructions to install the Nix package manager (not the NixOS operating system) onto your OS. Choose the “single-user installation” method.

.

2. Run this command to install SageMath:

nix-env -iA nixpkgs.sage

3. Run this to open:

sage --notebook=jupyterlab

— Me@2024-11-27 12:28:48 AM

.

.

2024.12.24 Tuesday (c) All rights reserved by ACHK

Y combinator

Why Yg = g(Yg) Enables Recursion

.

The following calculation verifies that Yg is indeed a fixed point of the function g:

\begin{aligned}  Y g &= (\lambda f.(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x)))\ g \\      &= (\lambda x.g\ (x\ x))\ (\lambda x.g\ (x\ x)) \\      &= g\ ((\lambda x.g\ (x\ x))\ (\lambda x.g\ (x\ x))) \\      &= g\ (Y\ g)  \end{aligned}

The lambda term g\ (Y\ g) may not, in general, \beta-reduce to the term Y\ g . However, both terms \beta-reduce to the same term, as shown.

— Wikipedia on Fixed-point combinator

.

\begin{aligned}  Y g &= (\lambda f.(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x)))\ g \\      &= (\lambda f.(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x)))\ (f := g) \\      &= (\lambda x.g\ (x\ x))\ (\lambda x.g\ (x\ x)) \\      &= (\lambda x.g\ (x\ x))\ (\lambda y.g\ (y\ y)) \\  &= (\lambda x.g\ (x\ x))\ (x := (\lambda y.g\ (y\ y))) \\      &= g\ ((\lambda y.g\ (y\ y))\ (\lambda y.g\ (y\ y))) \\      &= g\ (Y\ g)  \end{aligned}

— Me@2024-12-22 11:53:21 PM

.

.

2024.12.22 Sunday (c) All rights reserved by ACHK

真話騙子 2

這段改編自 2021 年 12 月 17 日的對話。

.

有誠信的人,會盡量不講假話;但是要留意,「誠信」並不只是,「講不講真話」的問題,因為,如果有心傷害人,只講真話也可以做到。

大方向是:

1. 不要在毋須講假話時,講假話。

2. 不要公開一些,毋須公開的真話。這就是「個人私隱」的意思。只有公職事務,你才有責任公開。

這兩點可統一為:

0. 不要在毋須說話時說話。

.

現在集中討論第一點:

即使是所謂的「善意」假話或隱瞞,也應盡量避免,因為結果為何,不是你,或者任何人,可以控制到。

……

— Me@2024-12-20 12:01:28 PM

.

.

2024.12.20 Friday (c) All rights reserved by ACHK

Euler problem 25.1.2

(defun matrix-multiply (a b)
  (destructuring-bind ((a11 a12) (a21 a22)) a
    (destructuring-bind ((b11 b12) (b21 b22)) b
      (list (list (+ (* a11 b11) (* a12 b21))
                  (+ (* a11 b12) (* a12 b22)))
            (list (+ (* a21 b11) (* a22 b21))
                  (+ (* a21 b12) (* a22 b22)))))))

(defun matrix-power (m n)
  (declare (type fixnum n))
  (cond ((= n 1) m)
        (t (let* ((half (matrix-power m (floor n 2)))
                  (squared (matrix-multiply half half)))
             (if (oddp n)
                 (matrix-multiply squared m)
                 squared)))))

(defun digits-in-number (n)
  "Count the number of digits in a number."
  (length (write-to-string n)))

(defun fib-nth (n)
  (declare (type fixnum n))
  (if (<= n 2)
      1
      (destructuring-bind ((result b)
                           (c d))
          (matrix-power '((1 1) (1 0)) (- n 1))
        (declare (ignore b c d))
        result)))

(defun fib-upper-bound (digit-count)
  "Calculate an upper bound for the index where Fibonacci has at least digit-count digits."
  (let* ((phi (float 1.618033988749895))
         (log-phi (log phi 10))
         (log-5 (log 5 10)))
    (ceiling (/ (+ digit-count (- 1 (/ log-5 2))) log-phi))))

(defun binary-search-fib-index (digit-count)
  "Find the index of the first Fibonacci number with the specified number of digits using binary search."
  (labels ((binary-search (left right)
             (when (<= left right)
               (let* ((mid (+ left (floor
                                    (/ (- right left) 2))))
                      (mid-fib (fib-nth mid))
                      (mid-digits (digits-in-number mid-fib)))
                 (cond ((= mid-digits digit-count) 
                        (let* ((prev-fib (fib-nth (1- mid)))
                               (prev-digits (digits-in-number
                                             prev-fib)))
                          (if (< prev-digits digit-count)
                              mid
                              (binary-search left (1- mid)))))
                       ((< mid-digits digit-count) 
                        (binary-search (1+ mid) right))
                       (t 
                        (binary-search left (1- mid))))))))
    (let* ((upper-bound (fib-upper-bound digit-count))
           (result (binary-search 1 upper-bound)))
      (or result (cons :upper-bound upper-bound)))))

; SLIME 2.28
CL-USER> (time (binary-search-fib-index 1000))
Evaluation took:
  0.001 seconds of real time
  
4782
CL-USER> 

— Me@2024-12-10 07:23:47 PM

.

.

2024.12.16 Monday (c) All rights reserved by ACHK

Ex 3.3: Hill Climbing, 2

Functional Differential Geometry

.

b. Write this as a computational expression.

~~~

\begin{aligned}   P &= mg \frac{d h}{d t} \\   &= mg \left( \frac{\partial h}{\partial x} \frac{dx}{dt} + \frac{\partial h}{\partial y} \frac{dy}{dt} \right) \\   &= mg \begin{bmatrix}   \frac{\partial h}{\partial x} & \frac{\partial h}{\partial y} \end{bmatrix} \begin{bmatrix} \frac{dx}{dt} \\ \frac{dy}{dt} \end{bmatrix} \\  &= mg (\nabla h) \cdot \mathbf{v} \\  &= mg (D f(\chi(\mathbf{m})) b(\chi{(\mathbf{m}})) \\   \end{aligned}

(define (components->vector-field components coordsys)
  (define (v f)
    (compose (* (D (compose f (point coordsys)))
                components)
             (chart coordsys)))
  (procedure->vector-field v))

(define R2->R (-> (UP Real Real) Real))

(define v
  (components->vector-field
   (up (literal-function 'v_x R2->R)
       (literal-function 'v_y R2->R))
   R2-rect))

(define R2-rect-chi-inverse
  (point R2-rect))

(define R2-rect-point
  (R2-rect-chi-inverse (up 'x_0 'y_0)))

(show-expression
 ((v (literal-manifold-function
      'h R2-rect)) R2-rect-point))

\left(      \left(v_x \left(\begin{pmatrix} x_0 \\ y_0 \end{pmatrix}\right) \cdot \left(\partial_0 h \right)\right|_{\begin{pmatrix} x_0 \\ y_0 \end{pmatrix}} +      \left(v_y \left(\begin{pmatrix} x_0 \\ y_0 \end{pmatrix}\right) \cdot \left(\partial_1 h \right) \right|_{\begin{pmatrix} x_0 \\ y_0 \end{pmatrix}}  \right)

— Me@2024-11-22 04:05:26 PM

.

.

2024.12.15 Sunday (c) All rights reserved by ACHK

Posted in FDG

Equality Predicates, 3.1

Here are mnemonic “formulae” to help remember the relationship between eq, eql, equal, equalp, and = in Common Lisp:

  • eq:

    eq: Exact same object in memory

    Think “Exact” for eq.

  • eql:

    eql: eq + little more (for numbers and characters)

    Think “Little more” for eql.

  • equal:

    equal: eql + structural comparison for lists, strings, etc.

    Think “All” for equal – checks all structural elements.

  • equalp:

    equalp: equal + case-insensitive + number type agnostic

    Think “P for Practical” – it’s practical because it ignores case and number types.

  • =:

    =: Numbers are equal regardless of type (float vs. integer)

    Think “= for Numbers” – only used for numeric comparison.

These mnemonics aim to encapsulate the essence of each function:

  • eq is about memory identity.
  • eql extends eq slightly for direct value comparison in some cases.
  • equal checks for structural equivalence beyond what eql does.
  • equalp adds case insensitivity and type flexibility to equal.
  • = is strictly for numeric equality, ignoring type differences.

— Me@2024-12-14 10:57:53 AM

.

.

2024.12.14 Saturday (c) All rights reserved by ACHK