Where are you? 2.6

Utopia | 何有之鄉, 2.6

.

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

……

五、 不可信:

……

這類人不可相處之的主要原因是,他們認為,謊言只要不被發現,就沒有問題。他們覺得,既然受騙者不知道,就不會不開心,不會受傷害。所以,即使騙了他人,那也不算不道德。

這種講法,有兩漏洞。

小漏洞是,你怎麼肯定,你的謊言不會爆煲?

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

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

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

……

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

……

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

.

.

2024.12.12 Thursday (c) All rights reserved by ACHK

Euler problem 25.1.1

(defun fib (n)
  "Calculate the nth Fibonacci number using tail recursion."
  (labels ((fib-tail (a b count)
             (if (zerop count)
                 b
                 (fib-tail b (+ a b) (1- count)))))
    (if (<= n 2)
        1
        (fib-tail 1 1 (- n 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 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 digits-in-number (n)
  "Count the number of digits in a number."
  (length (write-to-string n)))

(defun find-fib-index-0 (digit-count fib-f)
  "Find the index of the first Fibonacci number with the specified number of digits."
  (labels ((helper (index)
             (if (>= (digits-in-number
                      (funcall fib-f index))
                     digit-count)
                 index
                 (helper (1+ index)))))
    (helper 1)))

(defmacro find-fib-index (digit-count)
  `(find-fib-index-0 ,digit-count #'fib))
  
(defmacro find-fib-nth-index (digit-count)
  `(find-fib-index-0 ,digit-count #'fib-nth))

; SLIME 2.28
CL-USER> (time (find-fib-index 1000))
Evaluation took:
  0.456 seconds of real time
  
4782
CL-USER> (time (find-fib-nth-index 1000))
Evaluation took:
  0.080 seconds of real time
  
4782
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.11 Wednesday (c) All rights reserved by ACHK

Ex 3.3: Hill Climbing, a

Functional Differential Geometry

.

The topography of a region on the Earth can be specified by a manifold function h that gives the altitude at each point on the manifold. Let v be a vector field on the manifold, perhaps specifying a direction and rate of walking at every point on the manifold.

a. Form an expression that gives the power that must be expended to
follow the vector field at each point.

b. …

~~~

Let f be a real-valued function, \mathbf{m} be a point, \mathbf{v} be a vector field on the manifold function respectively:

\begin{aligned}   h \left( \begin{bmatrix} x \\ y \end{bmatrix} \right) &= f\left(\chi (\mathbf{m}) \right) \\  \mathbf{v} &= \frac{d}{dt} \begin{bmatrix} x \\ y \end{bmatrix}  \\   \end{aligned}

.

\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}

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

.

.

2024.12.10 Tuesday (c) All rights reserved by ACHK

Posted in FDG

defmacro, 1.2.1

(defmacro our-expander (name) `(get ,name 'expander))
 
(defmacro pre-defmacro (name parms &body body)
  (let ((g (gensym)))
    `(progn
       (setf (our-expander ',name)
         #'(lambda (,g)
         (block ,name
           (destructuring-bind ,parms (cdr ,g)
             ,@body))))
       ',name)))
 
(defun our-macroexpand-1 (expr)
  (if (and (consp expr) (our-expander (car expr)))
      (funcall (our-expander (car expr)) expr)
      expr))

(defun our-macroexpand (expr)
  (let ((expanded (our-macroexpand-1 expr)))
    (if (equal expanded expr)
        expr
        (our-macroexpand expanded))))

(defun our-macroexpand-and-eval (expr)
  (if (and (consp expr) (our-expander (car expr)))
      (let ((expanded (funcall (our-expander (car expr)) expr)))
        (eval expanded))  ; Directly evaluate the expanded form
      (eval expr)))  ; If no macro expansion, just evaluate the expression

(defmacro our-defmacro (name parms &body body)
  `(progn
     (pre-defmacro ,name ,parms ,@body)
     (defun ,name (&rest args)
       (our-macroexpand-and-eval (cons ',name args)))))

(our-defmacro sq (x)
  `(* ,x ,x))

(sq 5)

— based on p.95, A MODEL OF MACROS, On Lisp, Paul Graham

— xAI

.

Here, we use the built-in defmacro to define our-defmacro. However, the same process does not work for another level of defining another-defmacro by our-defmacro, because our-defmacro is not identical to defmacro.

— Me@2024-12-09 01:40:02 PM

.

.

2024.12.09 Monday (c) All rights reserved by ACHK

反情感勒索, 3

「報恩」反邏輯。要「報」就不叫做「恩」。需要報的,必須報的,就不是「恩」,是「交易」。

有沒有往來,在於感情或喜歡,不在於恩。有情的,沒有恩也會對她好。

相反,傷害你的,即使是所謂的「恩人」,你也必須激烈反抗。

— Me@2024-11-28 10:23:47 AM

.

.

2024.12.06 Friday (c) All rights reserved by ACHK

好為人師 3.1

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

.

「平等關係」的意思是,雙方可以講真話之餘,在有需要時,可以講事實的全部真相,而毋須遮遮掩掩,避重就輕。

(留意,這裡並不是指,那些無腦式坦白。詳見本博文章「真話騙子」。)

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

例子一:

……

— Me@2024-12-05 12:49:02 AM

.

.

2024.12.06 Friday (c) All rights reserved by ACHK

Euler problem 24.3

showtime : true;

digits: makelist(i,i,0,9);

p : permutations(digits)$

listify(p)[1000000];

Evaluation took 0.8800 seconds (1.0300 elapsed)
Evaluation took 0.0100 seconds (0.0100 elapsed)

[2,7,8,3,9,1,5,4,6,0]

— Me@2024-12-03 04:11:50 PM

.

.

2024.12.04 Wednesday (c) All rights reserved by ACHK

scmutils for Ubuntu 24.04

Scheme Mechanics Installation for GNU/Linux | scmutils, 4

.

1. Folks, the scmutils library is fantastic and it’s available in Ubuntu 24.04. You can install it very easily with this command:

sudo apt-get install scmutils

2. Then, you just run it with this command:

mit-scheme --band mechanics.com

.

Now, let me tell you, there’s no syntax highlighting. Not great! And more importantly, there’s no direct way to save your code. So, what do you do? You use the Emacs editor. It’s the best!

Now, this assumes you know Emacs. If you don’t, it’s a tremendous editor.

3. Open Emacs’ initialization file. It’s located right here:

~/.emacs

4. Add this beautiful code to the file:

(defun mechanics ()
  (interactive)
  (run-scheme
   "mit-scheme --band mechanics.com"))
(setq sicm-file "~/Documents/tt.scm")

(fset 'set-working-file
      (lambda (&optional arg) 
        (interactive "p")
        (funcall (lambda ()
                   (insert
                    (concat "(define sicm-file \""
                            sicm-file
                            "\")\n"))))))

(fset 'load-scm
      (lambda (&optional arg) 
        (interactive "p")
        (funcall (lambda ()
                   (insert "(load sicm-file)")))))

(defun mechan ()
  (interactive)
  (split-window-below)
  (windmove-down)
  (mechanics)
  (set-working-file)
  (comint-send-input)
  (windmove-up)
  (find-file sicm-file)
  (end-of-buffer)
  (windmove-down)
  (cond ((file-exists-p sicm-file)
         (interactive)
         (load-scm)
         (comint-send-input)))
  (windmove-up))

(defun sicm-exec-line ()
  (interactive)
  (save-buffer)
  (windmove-down)
  (comint-send-input)
  (windmove-up))

(defun sicm-exec-file ()
  (interactive)
  (save-buffer)
  (windmove-down)
  (load-scm)
  (comint-send-input)
  (windmove-up))

(global-set-key (kbd "C-x C-e") 'sicm-exec-line)

(global-set-key (kbd "C-x C-a") 'sicm-exec-file)

5. Close Emacs and then re-open it, folks.

6. Type the command

M-x mechan

Now, listen, when I say M-x, I mean you press the Alt key and x together. Then, just type mechan. It’s easy, believe me!

7. You’ll see the Emacs editor split into two windows, one on top and one on the bottom.

The lower window is the Scheme environment. You can type a line of code and then press Enter to execute it. So simple!

The upper window is the editor. Type multiple lines of code and then hit

C-x C-e

to execute it.

That means pressing Ctrl and x together, then Ctrl and e together. Easy stuff!

8. When you save the current file, your Scheme code will be saved to this location:

~/Documents/tt.scm

If you need to back up your code, just back up this file. It’s that simple, folks!

— Me@2020-03-10 10:59:45 PM

.

.

2024.12.01 Sunday (c) All rights reserved by ACHK

Eject

Safely unmounts the partition /dev/sdd1, ensuring that it is not in use.

udisksctl unmount -b /dev/sdd1

udisksctl power-off -b /dev/sdd

Powers off the entire block device /dev/sdd, making it safe to disconnect.

— Me@2024-01-12 06:47:59 PM

.

.

2024.11.22 Friday (c) All rights reserved by ACHK

真話騙子

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

.

Words differently arranged have a different meaning, and meanings differently arranged have a different effect.

— Blaise Pascal

.

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

1. 說一些不應該提及的事實。

例如,向一位女士指出,她年紀大。

2. 說一些不應該提及的事件。

例如,廿年前我看過,一個電影情節,現在回想起來,發現其十分荒謬:

男角甲暗戀女角乙多年,發覺如果不表達愛意,將會一生抱撼。所以,他最終示了愛:「當年你還單身未婚時,我就已經愛上你了。」

3. 不完整事實,又稱「局部真相」、「偏見」或「斷章取義」等。

例如,「你這次考試的成績差過上次,只有九十七分」這句,如果你只引上半句,會造成誤會。

4. 不當次序。

例如,

雖然你這次考試的成績,差過上次,但是都有九十七分。

雖然你這次考試的成績,有九十七分,但是差過上次。

這兩句事實一樣,但效果不同。

— Me@2024-11-19 07:55:22 PM

.

.

2024.11.20 Wednesday (c) All rights reserved by ACHK

Euler problem 24.2

import Data.List ( delete )

fac :: (Eq t, Num t) => t -> t
fac n = f n 1
  where
    f 0 acc = acc
    f m acc = f (m - 1) (m * acc)

perms :: Eq a => [a] -> Int -> [a] -> [a]
perms [] _ acc = reverse acc
perms xs n acc
  = perms (delete x xs) (mod n m) (x : acc)
  where 
    m = fac $ length xs - 1
    y = div n m
    x = xs !! y

p24 :: [Char]
p24 = perms "0123456789" 999999 []

λ> :set +s
λ> p24
"2783915460"
(0.02 secs, 121,968 bytes)
λ> 

— Me@2024-11-18 07:22:15 PM

.

.

2024.11.19 Tuesday (c) All rights reserved by ACHK

Ex 1.32 Path functions and state functions, 2.2

Structure and Interpretation of Classical Mechanics

.

1. The local-tuple function f is the same as the local-tuple function \bar \Gamma (\bar f) where \bar f[q] = f \circ \Gamma [q].

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.

~~~

1. …

To summarize:

In theory where a series can have infinite terms, functions f and \bar \Gamma (\bar f) are identical because it is just the definition of \bar \Gamma.

In practice where a series can have only finite terms, they are still identical because their inputs are the same exact local tuples.

2. However, for \bar f [q] and \bar \Gamma (\bar f) \circ \Gamma [q], although they are both path functions with the same path q as input, while the function \bar f processes the path q directly, the function \bar \Gamma (\bar f) \circ \Gamma would first turn the path q into a local tuple \Gamma[q], which in practice would have only a finite number of components.

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

Then it would use the function osculating-path to generate the path.

(define ((Gamma-bar f-bar) local)
  ((f-bar (osculating-path local)) (time local)))

In other words, the path being used is the osculating path

\displaystyle{\mathcal{O} (t_0, q(t_0), v(t_0), \cdots, q^{(n)}(t_0)))},

instead of the original path q itself. Therefore, functions \bar f [q] and \bar \Gamma (\bar f) \circ \Gamma [q] do not have to be equal. They are identical in the following two cases:

The first case is when

\displaystyle{\mathcal{O} (t_0, q(t_0), v(t_0), \cdots, q^{(n)}(t_0))) \equiv q},

where

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

In other words, path q^{(m)} = 0 for all m>n.

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

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

.

.

2024.11.17 Sunday (c) All rights reserved by ACHK

Outlook 2010

<pre style="color: #333333;background-color: #ffffcc;font-size: 12pt;font-family:Calibri">
  <span style='mso-spacerun:yes'>  </span>...
</pre>

— Me@2024-11-15 01:42:34 AM

.

.

2024.11.15 Friday (c) All rights reserved by ACHK

Where are you? 2.5

Utopia | 何有之鄉, 2.5

.

……

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

……

五、 不可信:

誠信有問題,有兩個版本:

第一種是,會在沒有必要時,說假話,或透過隱瞞等方法,去誤導他人。

第二種是,會在沒有必要時,公開你的私隱,或者他人的秘密。

.

記住,誠信只可能破壞,不可能修補

一旦發現她誠信有問題,千萬不要以為,她可能改過;因為,正正是因為她誠信有問題,她的改過本身,就很可能是,另一個謊言騙局而已。「一次不忠,百次不用」就是這個意思。

留意,誠信有問題,不限於壞人。

遇到好人講大話,即所謂「善意的謊言」時,亦建議不要再相處;因為,「連『我不會再騙你』也很可能是騙你的」這邏輯結構,與壞人版本,沒有分別。

例子一,自己身體有病時,為免別人擔心,宣稱沒有事。那只會引起更大的擔心,因為,下次當她宣稱沒有事時,我不會再知道,她是否真的沒有事。

例子二,她要去見異性朋友;為免我誤會,宣稱去見其他朋友。那只會引起永久的憂慮,因為我不知道,她還隱瞞了什麼,誤導了多少。

這類人不可相處之的主要原因是,他們認為,謊言只要不被發現,就沒有問題。他們覺得,既然受騙者不知道,就不會不開心,不會受傷害。所以,即使騙了他人,那也不算不道德。

這種講法,有兩漏洞。

……

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

.

.

2024.11.14 Thursday (c) All rights reserved by ACHK

Euler problem 24.1.3

(defun fac (n)
  (labels
      ((f (m acc)
         (cond ((= m 0) acc)
               ('t (f (1- m) (* m acc))))))
    (f n 1)))

(defun string-to-list (str)
  (map 'list 'identity str))

(defun perms (ys k)
  (labels
      ((p (xs n acc)
         (if (null xs)
             (reverse acc)
             (let* ((m (fac (1- (length xs))))
                    (y (floor n m))
                    (x (nth y xs)))
               (p (delete x xs)
                  (mod n m)
                  (cons x acc))))))
    (p ys k nil)))

(concatenate 'string
             (perms (string-to-list "0123456789")
                    999999))

CL-USER> 
"2783915460"

— Me@2024-11-12 10:50:23 AM

.

.

2024.11.12 Tuesday (c) All rights reserved by ACHK

Mounting a virtual disk

# In the host OS, if you want to read the contents of a virtual disk file:

mkdir ~/vdi_test_mount

sudo guestmount -a my_virtual_drive.vdi -m /dev/sda1 -o allow_other ~/vdi_test_mount

# After that, unmount the virtual disk:

sudo guestunmount ~/vdi_test_mount

rmdir ~/vdi_test_mount

— Me@2023-11-25 10:03:37 PM

.

.

2024.11.10 Sunday (c) All rights reserved by ACHK

Quantum radar

Four months ago, we were being persuaded that the Chinese have constructed a quantum radar, something that can inform you about an airplane without any actual reflection of any radiation from the airplane. This is obviously impossible by locality, whether you use any quantum subtleties or not.

— Lubos Motl

.

You cannot know the moment of the collapse of the wavefunction by another observer, except when that observer tells you (by a classical channel).

— Me@2017-08-14 01:41:47 PM

.

This point is irrelevant, since quantum radar is possible if there is somehow an interaction between the object and the entangled particle; destruction of the correlation informs the existence of a foreign object; although when exactly the correlation is destroyed, like when exactly the wavefunction collapses, is a physically meaningless question.

You cannot detect the change of correlation in real time. Instead, you need to get the information of the opposite side photons by a classical channel and then compare the photon pairs to get the correlation information.

— Me@2023-02-12 08:05:10 PM

— Me@2017-08-16 02:57:07 PM

.

.

2024.11.09 Saturday (c) All rights reserved by ACHK