# 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

.

.

# 大恩養仇人

.

no good deed goes unpunished

Beneficial actions often go unappreciated or are met with outright hostility.

— Wiktionary

.

.

1. 那是你自己的能力範圍以內。

2. 當事人有明確要求，或者情境預設，例如，當事人已昏迷，需立刻送院。

.

「幫助別人」就有如「責備別人」，雖然有時必須，但是越小越好，越少越好。

「幫助別人」就有如「服用藥物」，雖然有時必須，但是越小越好，越少越好。

.

— Me@2022-12-02 04:34:36 PM

.

.

# ParEdit .

(autoload 'enable-paredit-mode
"paredit" "Turn on pseudo-structural editing." t)

#'enable-paredit-mode)

#'enable-paredit-mode)

#'enable-paredit-mode)

#'enable-paredit-mode)

#'enable-paredit-mode)

#'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-11-29 10:03:49 PM

.

.

# Ex 1.2-1 Stationary States

Quantum Methods with Mathematica

.

Assume a wavefunction of the form psi[x, t] == f[t] psi[x] and perform a separation of variables on the wave equation.

Show that f[t] = E^(-I w t) where h w is the separation constant. Try the built-in function DSolve.

Equate h w to the Energy by evaluating the [expected] value of hamiltonian[V] in the state psi[x, t].

~~~

Remove["Global*"]

hbar := \[HBar]

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

psi[x_,t_] := f[t] psi[x]

I hbar D [psi[x,t],t] == H[V] @ psi[x, t]

I hbar D [psi[x,t],t] / psi[x,t] == H[V] @ psi[x,t] / psi[x,t] $\displaystyle{i \hbar \psi (x) f'(t)=V f(t) \psi (x)-\frac{\hbar ^2 f(t) \psi ''(x)}{2 m}}$ $\displaystyle{\frac{i \hbar f'(t)}{f(t)}=\frac{V f(t) \psi (x)-\frac{\hbar ^2 f(t) \psi ''(x)}{2 m}}{f(t) \psi (x)}}$

E1 := I hbar D [psi[x,t],t] / psi[x,t] == H[V] @ psi[x,t] / psi[x,t]

Simplify[E1] $\displaystyle{\frac{1}{2} \hbar \left(\frac{\hbar \psi ''(x)}{m \psi (x)}+\frac{2 i f'(t)}{f(t)}\right)=V}$

E2 := - 1/2 hbar hbar (D[D[psi[x],x],x]/(m psi[x])) == hbar omega

DSolve[E2, psi[x], x]

E3 := 1/2 hbar 2 i D[f[t],t] / f[t] == hbar omega

DSolve[E3, f[t], t] $\displaystyle{\left\{\left\{\psi (x)\to c_1 \cos \left(\frac{\sqrt{2} \sqrt{m} \sqrt{\omega } x}{\sqrt{\hbar }}\right)+c_2 \sin \left(\frac{\sqrt{2} \sqrt{m} \sqrt{\omega } x}{\sqrt{\hbar }}\right)\right\}\right\}}$ $\displaystyle{\left\{\left\{f(t)\to c_1 e^{\frac{\omega t}{i}}\right\}\right\}}$


k

psi[x_] := c E^(I k x)

psi[x]

f[t_] := E^(-I omega t)

f[t]

psi[x_,t_] := f[t] psi[x]

psi[x,t] $\displaystyle{ \left\{k,c e^{i k x},e^{-i \omega t},c e^{i k x-i \omega t}\right\} }$

E4 := Conjugate[psi[x,t]] H @ psi[x,t]

E4

E5 := Simplify[E4]

E5

k := Sqrt[2 m omega / hbar]

Refine[E5, {Element[{c, omega, m, t, hbar, k, x}, Reals]}] $\displaystyle{ \frac{c k^2 \hbar ^2 c^* \exp \left(-i \left(-(\omega t-k x)^*-k x+\omega t\right)\right)}{2 m} }$ $\displaystyle{ = c^2 \omega \hbar }$

E6 := Conjugate[psi[x,t]] psi[x,t]

Simplify[E6] $\displaystyle{ c c^* \exp \left(-i \left(-(\omega t-k x)^*-k x+\omega t\right)\right) }$ $\displaystyle{ = c^2 }$

. \displaystyle{\begin{aligned} \langle E \rangle &= \frac{\int_{-\infty}^{\infty} \psi^* H_{V=0} \psi dx}{\int_{-\infty}^{\infty} \psi^* \psi dx} \\ \\ &= \frac{c^2 \omega \hbar \int_{-\infty}^{\infty} dx}{c^2 \int_{-\infty}^{\infty} dx} \\ \\ &= \omega \hbar \\ \end{aligned}}

.

— Me@2022-11-26 07:17:29 PM

.

.

# Why does the universe exist? 7.2

“There is nothing in that region of space”

and

“there is nothing outside the universe”

have different meanings.

.

there is nothing except quantum fluctuations in that region of space

= the best detector detects nothing but quantum fluctuations

.

there is nothing outside the universe

= whatever detected, label the whole collection as “the universe”

.

“There is nothing outside the universe” does not (!!!) mean that “we go outside the universe to keep searching, but find nothing”.

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

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

.

.