# 搜神記 4

.

— 搜神記

— 林夕

.

.

— Me@2022-12-09 12:19:31 PM

— Me@2022-12-27 12:14:50 PM

.

Nobody is coming to save you. Get up. Be your own hero.

— Wealth Director

.

Doctors won’t make you healthy. Teachers won’t make you smart.

Ultimately, you have to take responsibility. Save yourself.

— @naval

.

.

# cmu-infix

is

a library for writing infix mathematical notation in Common Lisp. To install it:

1. In the Bash terminal, get Quicklisp by the following command:

sudo apt-get install cl-quicklisp


The file quicklisp.lisp will be created at

/usr/share/common-lisp/source/quicklisp/quicklisp.lisp


.

2. Run the command

sbcl --load /usr/share/common-lisp/source/quicklisp/quicklisp.lisp

(quicklisp-quickstart:install)



.

4. To enable the library, in the Common Lisp REPL, run the code:

(ql:quickload :cmu-infix)

5. And then run:

(named-readtables:in-readtable cmu-infix:syntax)

.

6. To test the library, run:

(defmacro add (x y)
(let ((a ,x)
(b ,y))
#I(a+b)))

(macroexpand-1 '#I(1+2-3*5^^6))

(eval (macroexpand-1 '#I(1+2-3*5^^6))) — Me@2022-12-25 10:13:04 AM

.

.

# Euler problem 11.4


recursive function max_e11(a2d, i, j, acc) result(a)

integer, dimension(20, 20) :: a2d
integer :: i, j, acc, a, accm = 0
integer :: dia_l = 0, dia_r = 0, hori = 0, vert = 0
integer :: k = 0, x = 1, y = 1
integer :: lenx = 20, leny = 20

if (i <= (lenx - 3)) then
hori = 1
do k = 0, 3
hori = hori*a2d(i+k, j)
end do
end if

if (j <= (leny - 3)) then
vert = 1
do k = 0, 3
vert = vert*a2d(i, j+k)
end do
end if

if ((i <= (lenx - 3)) .and. (j <= (leny - 3))) then
dia_r = 1
do k = 0, 3
dia_r = dia_r*a2d(i+k, j+k)
end do
end if

if ((i >= 4) .and. (j <= (leny - 3))) then
dia_l = 1
do k = 0, 3
dia_l = dia_l*a2d(i-k, j+k)
end do
end if

if ((i == lenx) .and. (j == leny)) then
a = acc
else
accm = max(acc, hori, vert, dia_l, dia_r)

if (i == lenx) then
x = 1
y = j + 1
else
x = i + 1
y = j
end if

a = max_e11(a2d, x, y, accm)
end if
end function max_e11

program main

implicit none

integer :: p_max, p_count, i, j
integer(kind = 16) :: p_sum
logical, ALLOCATABLE, DIMENSION(:) :: is_prime
character(len=128) :: currentDir
integer, dimension(20, 20) :: D, M
integer :: max_e11

call GET_ENVIRONMENT_VARIABLE('PWD', currentDir)

print *, "dir == ", trim(currentDir)

open(1, file = "t.txt", status = "old")
close(1)

M = transpose(D)

write(*, *) M(1, 1)
write(*, *) max_e11(M, 1, 1, 0)
write(*, *) M(1, 1)

end program main


— Me@2022-12-24 11:50:15 AM

.

.

# Feynman looking

NickRandom 3 days ago | next [–]

I have been in true ‘life or death’ situations (in other words, I’m alive because others were slower or less able to draw their weapons and fire).

In those sorts of situations time truly does slow down. I replay those times endlessly in my dreams/nightmares but either way it seemed like both at the time and in my mental replaying of the events that time slowed down to a crawl.

During endless sessions with various mental health professionals it seems that people involved in car crashes have the same slowing down of time. Based on what I’ve learnt, the time differential boils down to muscle memory (much like a batter hits a fast ball) that can and does initiate a response before the brain processes the event and that the mind catches up afterwards and is able to replay the events in a somewhat coherent way.

retrac 3 days ago | parent | next [–]

I once found a loved one in grave condition, without a pulse. What followed was like a surreal movie that has its frames out of order. I remember a thought of surprise at basically flinging furniture out of the way. Very much a passenger in my body at that point. I began CPR. Muscle memory is right. I was not really conscious throughout most of it.

One of the few things that resembles a thought during the entire episode is something like “you cannot think about this right now if you do you will collapse”. A jumble of eternal instants. It dragged on. And on. And on. Eventually, very eventually, the paramedics arrived. I had another thing resembling a thought. I can collapse now. I can look away now. I have no basically no memory until the next day when I saw her, awake, in the hospital.

I know the day and time it happened. I checked the logs after. The paramedics took less than 5 minutes to arrive. But it was outside the normal linearity of my experience. It doesn’t fit between the day before and the day after. For a while, the jumbled movie would play in my head, involuntarily. I think I was trying to make sense of it, fit it in, when it really doesn’t fit. Experiences and memories I couldn’t easily process because I didn’t really experience them consciously when they occurred? Maybe something like that. It went away with time, and does not bother me these days, but descriptions of PTSD do make a lot more sense to me now.

— Richard Feynman on looking at the world from another point of view (1973)

— Hacker News

.

.

2022.12.22 Thursday ACHK

# Chasing

Dear men,

Don’t be afraid to lose a girl.

Be afraid of losing yourself while chasing her.

— Lovers’ Guide

— guideforlovers

.

.

2022.12.21 Wednesday ACHK

.

.

.

# Ex 2.1-1 Particle in a Box

Remove["Global*"]

hbar := \[HBar]

H[V_] @ psi_  := -hbar^2/(2m) D[psi,{x,2}] + V psi

SchD[V_] @  psi_ := H[V] @ psi - En psi

SchD[V[x]] @ psi[x] == 0 // TeXForm $\displaystyle{-\text{En} \psi (x)-\frac{\hbar ^2 \psi ''(x)}{2 m}+\psi (x) V(x)=0}$

phi[n_, x_] := Cn Sin[n Pi x/L]

SchD @ phi[n,x] == 0 // ExpandAll

SchD @ phi[n,x] / phi[n,x] == 0 // Simplify // TeXForm $\displaystyle{2 \text{En} L=\frac{\pi ^2 n^2 \hbar ^2}{L m}}$

Starting with a linear superposition A E^(Ikx) + B E^(-Ikx) of independent plane waves, where A and B are constants, verify the box eigen-functions and eigen-energies given above.

Thus, show that this superposition is a solution of the Schrodinger equation and, by invoking the boundary condition, that k -> n Pi/L.

— Quantum Methods with Mathematica

phi[k_, x_] := A E^(I k x) + B E^(- I k x)

eq1 := SchD @ phi[k,x]/phi[k,x] == 0 // Simplify

Ek[k_] := En /. Solve[eq1, En] []

Ek[k] // TeXForm $\displaystyle{\frac{k^2 \hbar ^2}{2 m}}$

.

The boundary conditions are $\displaystyle{\phi_{x=0} = \phi_{x=L} = 0}$. \displaystyle{ \begin{aligned} A+B&=0 \\ A e^{i k L}+B e^{-i k L}&=0 \\ \end{aligned}}

So \displaystyle{ \begin{aligned} e^{i k L} - e^{-i k L}&=0 \\ \end{aligned}}

Solve[E^(I k L) - E^(-I k L) == 0, k] // Simplify $\displaystyle{ \left\{k\to -\frac{2 \pi c_1}{L}\text{ if }c_1\in \mathbb{Z}, ~~~k\to -\frac{2 \pi c_1+\pi }{L}\text{ if }c_1\in \mathbb{Z} \right\}}$ $\displaystyle{ =\left\{k\to \frac{n \pi }{L}\text{ if }n \in \mathbb{Z}\right\}}$

.

phi[n_, x_] := Cn Sin[n Pi x/L]

norm[n_] = Cn /.
Solve[
Integrate[ phi[n,x]^2, {x,0,L}] == 1 /.
Sin[m_Integer n Pi] -> 0,
Cn
] [] // TeXForm $\displaystyle{ -\frac{\sqrt{2}}{\sqrt{L}} }$

It’s interesting to note in passing that the 1D box eigenfunctions are also classically the eigenfunctions of a taut string. However, whereas the quantum mechanical energies scale as n^2, the classical eigenfrequencies of the string’s normal modes are linear in n. This is a consequence of the classical wave equation being second order in time in contrast to the quantum wave equation being first order.

— Quantum Methods with Mathematica

— Me@2022-12-16 10:23:45 AM

.

.

# Euler problem 11.5

A project created by using Lazarus on one platform can be compiled on any other one which Free Pascal compiler supports. For desktop applications a single source can target macOS, Linux, and Windows, with little or no modification. An example is the Lazarus IDE itself, created from a single code base and available on all major platforms including the Raspberry Pi.

— Wikipedia on Lazarus (software)

. .

What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?

program e11;

uses
SysUtils, math;

type
T2d_int_array = array of array of integer;

const
filename = 't.txt';

var
current_dir: string;
ptext: TextFile;

line_string: string;
s: string = '';
lines: array of string;
array_string_2d: array of array of string;
array_int_2d: T2d_int_array;

isbegin: boolean = true;
i: integer;
j: integer;
lenx: integer = 0;
leny: integer = 0;
c: integer = 0;

function max4_iter(a2d: T2d_int_array;
i, j: integer;
acc: longint): integer;
var
dia_l: longint = 0;
dia_r: longint = 0;
hori: longint = 0;
vert: longint = 0;
k: integer = 0;
accm: longint = 0;
x: integer = 0;
y: integer = 0;

begin
if i <= (lenx - 4) then begin
hori := 1;
for k := 0 to 3 do begin
hori := hori*a2d[i+k, j];
end;
end;

if j <= (leny - 4) then begin
vert := 1;
for k := 0 to 3 do begin
vert := vert*a2d[i, j+k];
end;
end;

if (i <= (lenx - 4)) and (j <= (leny - 4)) then
begin
dia_r := 1;
for k := 0 to 3 do begin
dia_r := dia_r*a2d[i+k, j+k];
end;
end;

if (i >= 3) and (j <= (leny - 4)) then begin
dia_l := 1;
for k := 0 to 3 do begin
dia_l := dia_l*a2d[i-k, j+k];
end;
end;

if (i = (lenx - 1)) and (j = (leny - 1)) then
begin
max4_iter := acc;
end else begin
accm := max(acc,
max(hori,
max(vert,
max(dia_l, dia_r))));

if i = lenx - 1 then begin
x := 0;
y := j + 1;
end else begin
x := i + 1;
y := j;
end;
max4_iter := max4_iter(a2d, x, y, accm);
end;
end;

begin

current_dir := GetCurrentDir;

writeln(filename, ':');
writeln('==================================');

if not FileExists(filename) then begin
writeln(filename, ' does not exist.');
exit;
end;

assign(ptext, filename);
reset(ptext);

setLength(lines, 0);
s := '';
isbegin := true;
while not eof(ptext) do begin
if isbegin then begin
s := s + line_string;
isbegin := false;
end else begin
s := s + LineEnding + line_string;
end;
end;
close(ptext);

lines := s.split(LineEnding);
lenx := length(lines);
setLength(array_string_2d, lenx);

for i := 0 to (lenx - 1) do begin
array_string_2d[i] := lines[i].split(' ');
end;
leny := length(array_string_2d);

setLength(array_int_2d, lenx);
for i := 0 to (lenx - 1) do begin
setLength(array_int_2d[i], leny);
end;

for i := 0 to (lenx - 1) do begin
for j := 0 to (leny - 1) do begin
val(array_string_2d[i][j],
array_int_2d[i][j],
c);
end;
end;

writeln(max4_iter(array_int_2d, 0, 0, 0));
writeln('==================================');
end.



— Me@2022-12-14 03:56:23 PM

.

.

# Light-like

Spacetime interval, 3 | How far away is tomorrow?, 2

.

Any two events in a spacelike region are not causally related.

Any two events in a timelike region can be causally related.

How about two events on the boundary (light-like)?

— Me@2016-06-30 06:38:06 PM

.

Their spacetime distance is zero, meaning that the communication signals/particles between the two events would have to travel at the speed of light.

In other words, the two events can only be marginally causally related.

— Me@2022-12-14 10:55:20 AM

.

.

philip1209 on June 30, 2018

One of my favorite classes in college was a physics course taught in this way:

1. Before class, we were assigned to read a chapter from the textbook, understand the material, and complete two or three homework problems from the material we had just self-learned.

2. After submitting homework, lectures focused on discussing the concepts more in-depth. Everybody already had a baseline knowledge, so the professor would highlight the important takeaways, applications, live demonstrations of concepts, etc. I found these lectures engaging because I had already learned the material – and the lectures focused on mastering it.

3. Sometimes there would be follow-up homework problems focusing on advanced applications or derivations. These advanced problems were closest to exam questions.

Some takeaways for me:

• If we didn’t have homework to do before class, I doubt I would have consistently learned the material before lecture.

• Lectures taught us more than the “what” – it taught us the “why” and how these concepts related to other areas.

• Lectures focused on answering questions, exploring curiosities (like “what if” questions), demonstrations/experiments, and mastery. The professor added value beyond the written material!

I hope this helps OP because it sounds like they have material prepared beforehand, which means that the lectures could go beyond the material.

— Hacker News

.

.

2022.12.13 Tuesday ACHK

# 人生 Presentation, 2.1

.

（安：雖然我不是從事教學工作，但是，在公司解釋東西給上司時，其實很多時也需要使用到，所謂的「教學技巧」。

.

（安：但是，除了這一點外，你應該還有其他技巧，因為，我覺得你很多時也會，在適當時候，講適當的東西。）

.

「在適當時候，講適當的東西」這個講法好得意，因為，你可以反問：

.

— Me@2022-12-12 02:40:07 PM

.

.

# Direct from Dell

Euler problem 9.2

. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.

g p =
[ [a, b, c]
| m <- [2 .. limit],
n <- [1 .. (m - 1)],
let a = m ^ 2 - n ^ 2,
let b = 2 * m * n,
let c = m ^ 2 + n ^ 2,
a + b + c == p
]
where
limit = floor . sqrt . fromIntegral \$ p


.

Euclid’s formula is a fundamental formula for generating Pythagorean triples given an arbitrary pair of integers $m$ and $n$ with $m > n > 0$. The formula states that the integers $\displaystyle{ a=m^{2}-n^{2},\ \,b=2mn,\ \,c=m^{2}+n^{2}}$

form a Pythagorean triple. The triple generated by Euclid’s formula is primitive if and only if $m$ and $n$ are coprime and one of them is even. When both $m$ and $n$ are odd, then $a$, $b$, and $c$ will be even, and the triple will not be primitive; however, dividing $a$, $b$, and $c$ by 2 will yield a primitive triple when $m$ and $n$ are coprime.

Every primitive triple arises (after the exchange of $a$ and $b$, if $a$ is even) from a unique pair of coprime numbers $m$, $n$, one of which is even.

— Wikipedia on Pythagorean triple — Me@2022-12-10 09:57:27 PM

.

.

# Ex 2.1 Curves

Functional Differential Geometry

.

a. The rectangular coordinate equation for the Lemniscate of Bernoulli is $\displaystyle{(x^2 + y^2)^2 = 2 a^2 (x^2 - y^2)}$.

Find the expression in polar coordinates.

b. Describe a helix space curve in both rectangular and cylindrical coordinates.

~~~

(define-coordinates (up x y) R2-rect)

(define-coordinates (up r theta) R2-polar)

;

(define R2-rect-chi (chart R2-rect))

; R2-rect-chi
;     generates the rectangle coordinates of a point.

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

; R2-rect-chi-inverse
;     gets the abstract representation.

(x (R2-rect-chi-inverse (up 'x0 'y0)))

; Function x
;     gets the x coordinate
;          of an (abstract-represented) point.

;

(define R2-polar-chi (chart R2-polar))

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

(x (R2-polar-chi-inverse (up 'r0 'theta0)))

(r (R2-polar-chi-inverse (up 'r0 'theta0)))

(r (R2-rect-chi-inverse (up 'x0 'y0)))

(theta (R2-rect-chi-inverse (up 'x0 'y0)))

;

(define h (+ (* x (square r)) (cube y)))

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

(show-expression
(h R2-rect-point))

(show-expression
(h (R2-polar-chi-inverse (up 'r_0 'theta_0))))  (show-expression
((- r (* 2 'a (+ 1 (cos theta))))
((point R2-rect) (up 'x 'y)))) ; Ex 2.1 a

(show-expression
((- (square (+ (square x) (square y)))
(* 2 (square 'a) (- (square x) (square y))))
((point R2-rect) (up 'x 'y))))

(show-expression
((- (square (+ (square x) (square y)))
(* 2 (square 'a) (- (square x) (square y))))
((point R2-polar) (up 'r 'theta))))  ; Ex 2.1 b

(define-coordinates (up r theta z) R3-cyl)

(define-coordinates (up x y z) R3-rect)

(show-expression
((- (up r z) (up 'R (* 'a theta)))
((point R3-cyl) (up 'r 'theta 'z))))

(show-expression
((- (up r z) (up 'R (* 'a theta)))
((point R3-rect) (up 'x 'y 'z))))  — Me@2022-12-10 10:29:59 AM

.

.

Posted in FDG

# Why does the universe exist? 7.0

ParEdit, 2

.

What is there before the beginning of the universe?

What does the universe change from?

— Me@2016-07-20 06:16:34 AM

.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

"paredit" "Turn on pseudo-structural editing." t)

;;;;;;;;;;;

(mapc (lambda (hook)
hooks))

'emacs-lisp-mode-hook
'eval-expression-minibuffer-setup-hook
'ielm-mode-hook
'lisp-mode-hook
'lisp-interaction-mode-hook
'scheme-mode-hook)

#'enable-paredit-mode)

;;;;;;;;;;;

(lambda () (paredit-mode +1)))

(defun override-slime-repl-bindings-with-paredit ()
(define-key slime-repl-mode-map

'override-slime-repl-bindings-with-paredit)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


— Me@2022-12-09 01:24:55 PM

.

.

# Computing Note, 3


Summer 2002

1. Perhaps the Encyclopedia Britannica
Research Assistant
is written by[in] Java.

2. Work Hard Play Hard
Live your life with[in] all [its] fullness.

3. H(Learning): HyperLearning 真切學習:
[]
Be a professional professional: 比專業還專業 .

To edit Lazarus code in Emacs:

1. Open Emacs’ initialization file, whose location should be

~/.emacs


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defmacro compile-with (command-string)

(progn

(save-buffer)

(unless visual-line-mode
(visual-line-mode 1))

(universal-argument)

(compile ,command-string)))

(defmacro defcomp (fn command-string kbd-string)

(progn

(defun ,fn ()

(interactive)

(compile-with ,command-string))

(global-set-key (kbd ,kbd-string) ',fn)))

;;;;;;;;;;;;;;;;;;;;;

(defcomp g-la-com

(concat
"lazbuild "
(replace-regexp-in-string
"pas" "lpi" buffer-file-name))

"C-x C-p")

;;;;;;;;;;;;;;;;;;;;;

(defcomp g-la-run

(replace-regexp-in-string
".pas" "" buffer-file-name)

"C-x C-[")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


3. Close Emacs.

4. Use the Lazarus IDE to create a console project named p11.

5. Close Lazarus.

6. Use Emacs to open the file p11.pas.

— Me@2022-12-07 08:35:48 PM

.

.

# Combinatorial proof

.

— Me@2022-12-06 09:58:50 AM

.

.

# Pier, 2.2

Euler problem 9.1

. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.

(defun e9c ()
(loop :for a :from 1 :to 1000 :do
(loop :for b :from 1 :to a :do
(let ((c (- 1000 (+ a b))))
(if (= (+ (* a a) (* b b)) (* c c))
(return-from e9c
(list a b c (* a b c)))))))) — colorized by palette fm

— Me@2022-12-05 05:59:49 PM

.

.

# Fortran Package Manager

.

The goal of this blog post is to set up an integrated programming environment for Fortran.

.

3. Install the package manager Anaconda.

4. Use Anaconda to install the Fortran Package Manager (fpm), by following the fpm installation guide.

4.1. Add the additional channel mentioned in the fpm installation guide.

4.2. Install the fpm itself:

conda create -n fpm_env fpm

conda activate fpm_env

5. Install the Fortran language server:

conda install fortls

6. Install the Emacs plugin:

sudo apt-get install elpa-pyvenv


7. Open Emacs’ initialization file, whose location should be

~/.emacs


8. Add the following code to the file.


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun gfortran-run ()

(interactive)

(save-buffer)

(unless visual-line-mode
(visual-line-mode 1))

(universal-argument)

(compile "fpm run"))

(global-set-key (kbd "C-x C-r") 'gfortran-run)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(setenv "WORKON_HOME" "~/anaconda3/envs")

(pyvenv-mode 1)

(pyvenv-workon "fpm_env")

;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

— Me@2022-12-01 09:18:59 AM

.

.

# Why does the universe exist? 7.3

Euler problem 10.4

.

program main

implicit none

integer :: p_max, p_count, i, j
integer(kind = 16) :: p_sum
logical, ALLOCATABLE, DIMENSION(:) :: is_prime

p_max = 2000000

ALLOCATE(is_prime(p_max))

is_prime = .true.

is_prime(1) = .false.

do i = 2, ceiling(sqrt(real(p_max)))
if (is_prime(i)) then
do j = i*i, p_max, i
is_prime(j) = .false.
end do
end if
end do

p_count = 0
p_sum = 0
do i = 1, p_max
if (is_prime(i)) then
p_count = p_count + 1
p_sum = p_sum + i
end if
end do

print *, "p_count == ", p_count
print *, "p_sum == ", p_sum

DEALLOCATE(is_prime)

end program main


For a universe part, which is partial in space or in time, you can ask for its cause.

But for the universe as a whole, you cannot.

If the big bang is the first cause, you cannot ask for the cause of its existence.

Asking for the cause of the existence of the universe is the same as asking for the cause of the first cause.

— Me@2012-10-15 08:33:01 AM

— Me@2022-11-27 09:09:53 PM

.

.

# Hacking Reality

Good marriage is better than no marriage.

No marriage is better than bad marriage.

— John T Reed

.

Your wife should be the exception of the (brutal) reality of this world.

If someone is just another reality, better not to marry her.

— Me@2022-11-10 01:21:15 AM

.

.